122 lines
3.5 KiB
JavaScript
122 lines
3.5 KiB
JavaScript
import {
|
|
computedEager,
|
|
formContextKey,
|
|
formItemContextKey,
|
|
isClient
|
|
} from "./chunk-FYPMSKES.js";
|
|
import {
|
|
debugWarn
|
|
} from "./chunk-UFIWN4M6.js";
|
|
import {
|
|
useGetDerivedNamespace
|
|
} from "./chunk-R2OGZABH.js";
|
|
import {
|
|
computed,
|
|
getCurrentInstance,
|
|
inject,
|
|
onMounted,
|
|
onUnmounted,
|
|
ref,
|
|
toRef,
|
|
unref,
|
|
watch
|
|
} from "./chunk-AAHVYXXY.js";
|
|
|
|
// ../node_modules/.pnpm/element-plus@2.11.7_vue@3.5.24_typescript@5.9.3_/node_modules/element-plus/es/hooks/use-id/index.mjs
|
|
var defaultIdInjection = {
|
|
prefix: Math.floor(Math.random() * 1e4),
|
|
current: 0
|
|
};
|
|
var ID_INJECTION_KEY = Symbol("elIdInjection");
|
|
var useIdInjection = () => {
|
|
return getCurrentInstance() ? inject(ID_INJECTION_KEY, defaultIdInjection) : defaultIdInjection;
|
|
};
|
|
var useId = (deterministicId) => {
|
|
const idInjection = useIdInjection();
|
|
if (!isClient && idInjection === defaultIdInjection) {
|
|
debugWarn("IdInjection", `Looks like you are using server rendering, you must provide a id provider to ensure the hydration process to be succeed
|
|
usage: app.provide(ID_INJECTION_KEY, {
|
|
prefix: number,
|
|
current: number,
|
|
})`);
|
|
}
|
|
const namespace = useGetDerivedNamespace();
|
|
const idRef = computedEager(() => unref(deterministicId) || `${namespace.value}-id-${idInjection.prefix}-${idInjection.current++}`);
|
|
return idRef;
|
|
};
|
|
|
|
// ../node_modules/.pnpm/element-plus@2.11.7_vue@3.5.24_typescript@5.9.3_/node_modules/element-plus/es/components/form/src/hooks/use-form-item.mjs
|
|
var useFormItem = () => {
|
|
const form = inject(formContextKey, void 0);
|
|
const formItem = inject(formItemContextKey, void 0);
|
|
return {
|
|
form,
|
|
formItem
|
|
};
|
|
};
|
|
var 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 {
|
|
ID_INJECTION_KEY,
|
|
useIdInjection,
|
|
useId,
|
|
useFormItem,
|
|
useFormItemInputId
|
|
};
|
|
//# sourceMappingURL=chunk-DIGHH22S.js.map
|