{"version":3,"file":"context.mjs","sources":["../../../../../../packages/components/form/src/context.ts"],"sourcesContent":["import type { ValidateMessages } from '@antdv/locale';\nimport type { ValidateStatus } from '@antdv/types';\nimport type { ComputedRef, InjectionKey } from 'vue';\nimport type { ColProps } from '../../grid';\nimport type { FieldExpose, FormLabelAlign, RequiredMark, Rule } from './interface';\nimport { computed, inject, provide } from 'vue';\nimport { defaultValidateMessages } from './utils/messages';\n\nexport const FormContextKey: InjectionKey<FormContextProps> = Symbol('formContextKey');\n\nexport interface FormContextProps {\n  model?: ComputedRef<any>\n  vertical: ComputedRef<boolean>\n  name?: ComputedRef<string>\n  colon?: ComputedRef<boolean>\n  labelAlign?: ComputedRef<FormLabelAlign>\n  labelWrap?: ComputedRef<boolean>\n  labelCol?: ComputedRef<ColProps>\n  wrapperCol?: ComputedRef<ColProps>\n  requiredMark?: ComputedRef<RequiredMark>\n  // itemRef: (name: (string | number)[]) => (node: React.ReactElement) => void;\n  addField: (eventKey: string, field: FieldExpose) => void\n  removeField: (eventKey: string) => void\n  validateTrigger?: ComputedRef<string | string[]>\n  rules?: ComputedRef<{ [k: string]: Rule[] | Rule }>\n  onValidate: (\n    name: string | number | Array<string | number>,\n    status: boolean,\n    errors: string[] | null,\n  ) => void\n  validateMessages: ComputedRef<ValidateMessages>\n}\n\nexport function useProvideForm(state: FormContextProps) {\n  provide(FormContextKey, state);\n}\n\nexport function useInjectForm() {\n  return inject(FormContextKey, {\n    name: computed(() => undefined),\n    labelAlign: computed(() => 'right' as FormLabelAlign),\n    vertical: computed(() => false),\n\n    addField: (_eventKey: string, _field: FieldExpose) => {},\n\n    removeField: (_eventKey: string) => {},\n    model: computed(() => undefined),\n    rules: computed(() => undefined),\n    colon: computed(() => undefined),\n    labelWrap: computed(() => undefined),\n    labelCol: computed(() => undefined),\n    requiredMark: computed(() => false),\n    validateTrigger: computed(() => undefined),\n    onValidate: () => {},\n    validateMessages: computed(() => defaultValidateMessages),\n  } as FormContextProps);\n}\n\n/** Used for ErrorList only */\nexport interface FormItemPrefixContextProps {\n  prefixCls: ComputedRef<string>\n  status?: ComputedRef<ValidateStatus>\n}\n\nexport const FormItemPrefixContextKey: InjectionKey<FormItemPrefixContextProps> = Symbol(\n  'formItemPrefixContextKey',\n);\n\nexport function useProvideFormItemPrefix(state: FormItemPrefixContextProps) {\n  provide(FormItemPrefixContextKey, state);\n}\n\nexport function useInjectFormItemPrefix() {\n  return inject(FormItemPrefixContextKey, {\n    prefixCls: computed(() => ''),\n  });\n}\n"],"names":[],"mappings":";;;AAQa,MAAA,cAAA,GAAiD,OAAO,gBAAgB,EAAA;AAyB9E,SAAS,eAAe,KAAyB,EAAA;AACtD,EAAA,OAAA,CAAQ,gBAAgB,KAAK,CAAA,CAAA;AAC/B,CAAA;AAEO,SAAS,aAAgB,GAAA;AAC9B,EAAA,OAAO,OAAO,cAAgB,EAAA;AAAA,IAC5B,IAAA,EAAM,QAAS,CAAA,MAAM,KAAS,CAAA,CAAA;AAAA,IAC9B,UAAA,EAAY,QAAS,CAAA,MAAM,OAAyB,CAAA;AAAA,IACpD,QAAA,EAAU,QAAS,CAAA,MAAM,KAAK,CAAA;AAAA,IAE9B,QAAA,EAAU,CAAC,SAAA,EAAmB,MAAwB,KAAA;AAAA,KAAC;AAAA,IAEvD,WAAA,EAAa,CAAC,SAAsB,KAAA;AAAA,KAAC;AAAA,IACrC,KAAA,EAAO,QAAS,CAAA,MAAM,KAAS,CAAA,CAAA;AAAA,IAC/B,KAAA,EAAO,QAAS,CAAA,MAAM,KAAS,CAAA,CAAA;AAAA,IAC/B,KAAA,EAAO,QAAS,CAAA,MAAM,KAAS,CAAA,CAAA;AAAA,IAC/B,SAAA,EAAW,QAAS,CAAA,MAAM,KAAS,CAAA,CAAA;AAAA,IACnC,QAAA,EAAU,QAAS,CAAA,MAAM,KAAS,CAAA,CAAA;AAAA,IAClC,YAAA,EAAc,QAAS,CAAA,MAAM,KAAK,CAAA;AAAA,IAClC,eAAA,EAAiB,QAAS,CAAA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