This commit is contained in:
2025-09-19 14:25:20 +08:00
parent 269893a435
commit fbf3f77229
24949 changed files with 2839404 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
export * from './use-form-common-props';
export * from './use-form-item';

View File

@@ -0,0 +1,3 @@
export { useDisabled, useFormDisabled, useFormSize, useSize } from './use-form-common-props.mjs';
export { useFormItem, useFormItemInputId } from './use-form-item.mjs';
//# sourceMappingURL=index.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}

View File

@@ -0,0 +1,6 @@
import type { ComponentSize } from 'element-plus/es/constants';
import type { MaybeRef } from '@vueuse/core';
export declare const useFormSize: (fallback?: MaybeRef<ComponentSize | undefined>, ignore?: Partial<Record<"prop" | "form" | "formItem" | "global", boolean>>) => import("vue").ComputedRef<"" | "small" | "default" | "large">;
export declare const useFormDisabled: (fallback?: MaybeRef<boolean | undefined>) => import("vue").ComputedRef<boolean>;
export declare const useSize: (fallback?: MaybeRef<ComponentSize | undefined>, ignore?: Partial<Record<"prop" | "form" | "formItem" | "global", boolean>>) => import("vue").ComputedRef<"" | "small" | "default" | "large">;
export declare const useDisabled: (fallback?: MaybeRef<boolean | undefined>) => import("vue").ComputedRef<boolean>;

View File

@@ -0,0 +1,23 @@
import { computed, unref, ref, inject } from 'vue';
import { useGlobalSize } from '../../../../hooks/use-size/index.mjs';
import { useProp } from '../../../../hooks/use-prop/index.mjs';
import { formContextKey, formItemContextKey } from '../constants.mjs';
const useFormSize = (fallback, ignore = {}) => {
const emptyRef = ref(void 0);
const size = ignore.prop ? emptyRef : useProp("size");
const globalConfig = ignore.global ? emptyRef : useGlobalSize();
const form = ignore.form ? { size: void 0 } : inject(formContextKey, void 0);
const formItem = ignore.formItem ? { size: void 0 } : inject(formItemContextKey, void 0);
return computed(() => size.value || unref(fallback) || (formItem == null ? void 0 : formItem.size) || (form == null ? void 0 : form.size) || globalConfig.value || "");
};
const useFormDisabled = (fallback) => {
const disabled = useProp("disabled");
const form = inject(formContextKey, void 0);
return computed(() => disabled.value || unref(fallback) || (form == null ? void 0 : form.disabled) || false);
};
const useSize = useFormSize;
const useDisabled = useFormDisabled;
export { useDisabled, useFormDisabled, useFormSize, useSize };
//# sourceMappingURL=use-form-common-props.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"use-form-common-props.mjs","sources":["../../../../../../../packages/components/form/src/hooks/use-form-common-props.ts"],"sourcesContent":["import { computed, inject, ref, unref } from 'vue'\nimport { useGlobalSize } from '@element-plus/hooks/use-size'\nimport { useProp } from '@element-plus/hooks/use-prop'\nimport { formContextKey, formItemContextKey } from '../constants'\n\nimport type { ComponentSize } from '@element-plus/constants'\nimport type { MaybeRef } from '@vueuse/core'\n\nexport const useFormSize = (\n fallback?: MaybeRef<ComponentSize | undefined>,\n ignore: Partial<Record<'prop' | 'form' | 'formItem' | 'global', boolean>> = {}\n) => {\n const emptyRef = ref(undefined)\n\n const size = ignore.prop ? emptyRef : useProp<ComponentSize>('size')\n const globalConfig = ignore.global ? emptyRef : useGlobalSize()\n const form = ignore.form\n ? { size: undefined }\n : inject(formContextKey, undefined)\n const formItem = ignore.formItem\n ? { size: undefined }\n : inject(formItemContextKey, undefined)\n\n return computed(\n (): ComponentSize =>\n size.value ||\n unref(fallback) ||\n formItem?.size ||\n form?.size ||\n globalConfig.value ||\n ''\n )\n}\n\nexport const useFormDisabled = (fallback?: MaybeRef<boolean | undefined>) => {\n const disabled = useProp<boolean>('disabled')\n const form = inject(formContextKey, undefined)\n return computed(\n () => disabled.value || unref(fallback) || form?.disabled || false\n )\n}\n\n// These exports are used for preventing breaking changes\nexport const useSize = useFormSize\nexport const useDisabled = useFormDisabled\n"],"names":[],"mappings":";;;;;AAIY,MAAC,WAAW,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,EAAE,KAAK;AACtD,EAAE,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AAC/B,EAAE,MAAM,IAAI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from 'vue';
import type { FormItemContext } from '../types';
export declare const useFormItem: () => {
form: import("../types").FormContext | undefined;
formItem: FormItemContext | undefined;
};
export type IUseFormItemInputCommonProps = {
id?: string;
label?: string | number | boolean | Record<string, any>;
ariaLabel?: string | number | boolean | Record<string, any>;
};
export declare const useFormItemInputId: (props: Partial<IUseFormItemInputCommonProps>, { formItemContext, disableIdGeneration, disableIdManagement, }: {
formItemContext?: FormItemContext;
disableIdGeneration?: ComputedRef<boolean> | Ref<boolean>;
disableIdManagement?: ComputedRef<boolean> | Ref<boolean>;
}) => {
isLabeledByFormItem: ComputedRef<boolean>;
inputId: Ref<string | undefined>;
};

View File

@@ -0,0 +1,71 @@
import { inject, ref, getCurrentInstance, computed, onMounted, watch, toRef, onUnmounted } from 'vue';
import { useId } from '../../../../hooks/use-id/index.mjs';
import { formContextKey, formItemContextKey } from '../constants.mjs';
const useFormItem = () => {
const form = inject(formContextKey, void 0);
const formItem = inject(formItemContextKey, void 0);
return {
form,
formItem
};
};
const useFormItemInputId = (props, {
formItemContext,
disableIdGeneration,
disableIdManagement
}) => {
if (!disableIdGeneration) {
disableIdGeneration = ref(false);
}
if (!disableIdManagement) {
disableIdManagement = ref(false);
}
const instance = getCurrentInstance();
const inLabel = () => {
let parent = instance == null ? void 0 : instance.parent;
while (parent) {
if (parent.type.name === "ElFormItem") {
return false;
}
if (parent.type.name === "ElLabelWrap") {
return true;
}
parent = parent.parent;
}
return false;
};
const inputId = ref();
let idUnwatch = void 0;
const isLabeledByFormItem = computed(() => {
var _a;
return !!(!(props.label || props.ariaLabel) && formItemContext && formItemContext.inputIds && ((_a = formItemContext.inputIds) == null ? void 0 : _a.length) <= 1);
});
onMounted(() => {
idUnwatch = watch([toRef(props, "id"), disableIdGeneration], ([id, disableIdGeneration2]) => {
const newId = id != null ? id : !disableIdGeneration2 ? useId().value : void 0;
if (newId !== inputId.value) {
if ((formItemContext == null ? void 0 : formItemContext.removeInputId) && !inLabel()) {
inputId.value && formItemContext.removeInputId(inputId.value);
if (!(disableIdManagement == null ? void 0 : disableIdManagement.value) && !disableIdGeneration2 && newId) {
formItemContext.addInputId(newId);
}
}
inputId.value = newId;
}
}, { immediate: true });
});
onUnmounted(() => {
idUnwatch && idUnwatch();
if (formItemContext == null ? void 0 : formItemContext.removeInputId) {
inputId.value && formItemContext.removeInputId(inputId.value);
}
});
return {
isLabeledByFormItem,
inputId
};
};
export { useFormItem, useFormItemInputId };
//# sourceMappingURL=use-form-item.mjs.map

File diff suppressed because one or more lines are too long