UNPKG

vuestic-ui

Version:
1 lines 1.59 kB
{"version":3,"file":"useFormChild.mjs","sources":["../../../../../src/composables/useForm/useFormChild.ts"],"sourcesContent":["import { inject, ref, computed, onMounted, onBeforeUnmount } from 'vue'\nimport { useComponentUuid } from '../useComponentUuid'\nimport { FormServiceKey } from './consts'\nimport { type FormFiled } from './types'\nimport { type FormContext } from './formContext'\n\nexport const useFormChild = (context: FormFiled) => {\n const formContext = inject(FormServiceKey, null)\n\n if (!formContext) {\n return {\n forceDirty: ref(false),\n forceHideErrorMessages: ref(false),\n forceHideErrors: ref(false),\n forceHideLoading: ref(false),\n fields: computed(() => []),\n registerField: () => {},\n unregisterField: () => {},\n immediate: computed(() => false),\n } as FormContext\n }\n\n const uid = useComponentUuid()\n\n onMounted(() => {\n formContext.registerField(uid, context)\n })\n\n onBeforeUnmount(() => {\n formContext.unregisterField(uid)\n })\n\n return formContext\n}\n"],"names":[],"mappings":";;;AAMa,MAAA,eAAe,CAAC,YAAuB;AAC5C,QAAA,cAAc,OAAO,gBAAgB,IAAI;AAE/C,MAAI,CAAC,aAAa;AACT,WAAA;AAAA,MACL,YAAY,IAAI,KAAK;AAAA,MACrB,wBAAwB,IAAI,KAAK;AAAA,MACjC,iBAAiB,IAAI,KAAK;AAAA,MAC1B,kBAAkB,IAAI,KAAK;AAAA,MAC3B,QAAQ,SAAS,MAAM,EAAE;AAAA,MACzB,eAAe,MAAM;AAAA,MAAC;AAAA,MACtB,iBAAiB,MAAM;AAAA,MAAC;AAAA,MACxB,WAAW,SAAS,MAAM,KAAK;AAAA,IAAA;AAAA,EAEnC;AAEA,QAAM,MAAM;AAEZ,YAAU,MAAM;AACF,gBAAA,cAAc,KAAK,OAAO;AAAA,EAAA,CACvC;AAED,kBAAgB,MAAM;AACpB,gBAAY,gBAAgB,GAAG;AAAA,EAAA,CAChC;AAEM,SAAA;AACT;"}