@schemx/vue 0.1.21 → 0.1.22-alpha.20260701230808.331d3b2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -119,18 +119,18 @@ rendererRegistry.register("input", InputRenderer)
119
119
 
120
120
  ## Composition API
121
121
 
122
- | API | 说明 |
123
- | ------------------- | --------------------------------------------- |
124
- | `useForm()` | 创建表单实例,并通过 Vue context 提供给子组件 |
125
- | `useField()` | 获取字段级读写、校验和状态能力 |
126
- | `useWatch()` | 监听字段变化 |
127
- | `useWatchField()` | 监听单个字段 |
128
- | `useWatchFields()` | 监听多个字段 |
129
- | `useWatchAll()` | 监听整张表单 |
130
- | `useDictionary()` | 管理依赖字段的远程或本地选项 |
131
- | `useContext()` | 获取表单上下文 |
132
- | `useEffect()` | 创建字段依赖追踪 effect |
133
- | `useFieldContext()` | 获取当前字段上下文 |
122
+ | API | 说明 |
123
+ | -------------------- | --------------------------------------------- |
124
+ | `useForm()` | 创建表单实例,并通过 Vue context 提供给子组件 |
125
+ | `useField()` | 获取字段级读写、校验和状态能力 |
126
+ | `useWatch()` | 监听字段变化 |
127
+ | `useWatchField()` | 监听单个字段 |
128
+ | `useWatchFields()` | 监听多个字段 |
129
+ | `useWatchAll()` | 监听整张表单 |
130
+ | `useDictionary()` | 管理依赖字段的远程或本地选项 |
131
+ | `useConfigContext()` | 获取表单上下文 |
132
+ | `useEffect()` | 创建字段依赖追踪 effect |
133
+ | `useFieldContext()` | 获取当前字段上下文 |
134
134
 
135
135
  ## Adapter 边界
136
136
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/FormItem/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAsBH,OAAO,KAAK,EAOV,gBAAgB,EAChB,MAAM,EACP,MAAM,cAAc,CAAA;AAErB;;;;GAIG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACxD,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAA;CAC5B;AAED,QAAA,MAAM,QAAQ;;;;kCAwPb,CAAA;AAED,eAAe,QAAQ,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/FormItem/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAmBH,OAAO,KAAK,EAMV,gBAAgB,EAChB,MAAM,EACP,MAAM,cAAc,CAAA;AAErB;;;;GAIG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACxD,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAA;CAC5B;AAED,QAAA,MAAM,QAAQ;;;;kCAkOb,CAAA;AAED,eAAe,QAAQ,CAAA"}
@@ -6,5 +6,4 @@
6
6
  * @module hocs
7
7
  */
8
8
  export { WithRemoteOptions } from './withRemoteOptions';
9
- export type { SchemxDictionary, SchemxWithDictionary } from './withRemoteOptions';
10
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hocs/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAEvD,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hocs/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import { Component, PropType } from 'vue';
2
- import { NamePath, SchemxDictionary } from '@schemx/core';
2
+ import { SchemxDictionary } from '../types/dictionary';
3
+ import { NamePath } from '@schemx/core';
3
4
 
4
- export type { SchemxDictionary, SchemxWithDictionary } from '@schemx/core';
5
5
  /**
6
6
  * WithRemoteOptions 注入给被包装组件的额外 Props
7
7
  */
@@ -1 +1 @@
1
- {"version":3,"file":"withRemoteOptions.d.ts","sourceRoot":"","sources":["../../src/hocs/withRemoteOptions.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAgC,QAAQ,EAAgB,MAAM,KAAK,CAAA;AAIrF,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAE9D,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAE1E;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,cAAc;IACd,OAAO,EAAE,GAAG,EAAE,CAAA;IACd,WAAW;IACX,OAAO,EAAE,OAAO,CAAA;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,iBAAiB,CAAC,gBAAgB,EAAE,SAAS;;cAMrC,QAAQ,CAAC,gBAAgB,CAAC;;;;cAIjB,QAAQ,CAAC,QAAQ,CAAC;;;;;;;cAJ3B,QAAQ,CAAC,gBAAgB,CAAC;;;;cAIjB,QAAQ,CAAC,QAAQ,CAAC;;;;;;6EAoBlD;AAED,eAAe,iBAAiB,CAAA"}
1
+ {"version":3,"file":"withRemoteOptions.d.ts","sourceRoot":"","sources":["../../src/hocs/withRemoteOptions.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAgC,QAAQ,EAAgB,MAAM,KAAK,CAAA;AAErF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAI1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAG5C;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,cAAc;IACd,OAAO,EAAE,GAAG,EAAE,CAAA;IACd,WAAW;IACX,OAAO,EAAE,OAAO,CAAA;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,iBAAiB,CAAC,gBAAgB,EAAE,SAAS;;cAMrC,QAAQ,CAAC,gBAAgB,CAAC;;;;cAIjB,QAAQ,CAAC,QAAQ,CAAC;;;;;;;cAJ3B,QAAQ,CAAC,gBAAgB,CAAC;;;;cAIjB,QAAQ,CAAC,QAAQ,CAAC;;;;;;6EAoBlD;AAED,eAAe,iBAAiB,CAAA"}
@@ -4,21 +4,19 @@
4
4
  * @module hooks
5
5
  */
6
6
  /** useForm - 表单状态管理 */
7
- export { useForm } from './useForm';
7
+ export { useForm, useFormContext } from './useForm';
8
8
  /** useField - 单字段控制 */
9
- export { useField } from './useField';
9
+ export { useField, createFieldContext, useFieldContext } from './useField';
10
10
  /** useWatch - 字段变化监听 */
11
11
  export { useWatch, useWatchField, useWatchFields, useWatchAll } from './useWatch';
12
12
  /** useEffect - 通用 Signal effect */
13
13
  export { useEffect } from './useEffect';
14
14
  /** useDictionary - 字典选项加载 */
15
- export { useDictionary, type SchemxDictionary, type SchemxWithDictionary, type UseDictOptionsReturn, } from './useDictionary';
16
- /** useContext - 表单上下文注入与消费 */
17
- export { type FormContextProps, useContext } from './useContext';
15
+ export { useDictionary, type SchemxDictionary, type SchemxWithDictionary, type UseDictionaryReturn, } from './useDictionary';
16
+ /** useConfigContext - 表单上下文注入与消费 */
17
+ export { createConfigContext, useConfigContext, type FormContextProps, } from './useContext';
18
18
  /** useStableRef - 引用稳定化的 shallowRef */
19
19
  export { useStableRef } from './useStableRef';
20
20
  /** useViewSchemas - ViewSchemas Vue 桥接 */
21
21
  export { useViewSchemas } from './useViewSchemas';
22
- /** useFieldContext - 字段上下文注入与消费 */
23
- export { useFieldContext } from './useFieldContext';
24
22
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,uBAAuB;AACvB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,uBAAuB;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,wBAAwB;AACxB,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAEjF,mCAAmC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,6BAA6B;AAC7B,OAAO,EACL,aAAa,EACb,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,GAC1B,MAAM,iBAAiB,CAAA;AAExB,8BAA8B;AAC9B,OAAO,EAAE,KAAK,gBAAgB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEhE,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,0CAA0C;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD,mCAAmC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,uBAAuB;AACvB,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAEnD,uBAAuB;AACvB,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE1E,wBAAwB;AACxB,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAEjF,mCAAmC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,6BAA6B;AAC7B,OAAO,EACL,aAAa,EACb,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,GACzB,MAAM,iBAAiB,CAAA;AAExB,oCAAoC;AACpC,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,KAAK,gBAAgB,GACtB,MAAM,cAAc,CAAA;AAErB,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,0CAA0C;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA"}
@@ -20,6 +20,12 @@ export interface FormContextProps<T extends Values = Values> extends Omit<Schemx
20
20
  * @typeParam T - 表单值类型
21
21
  * @param props - 表单上下文属性
22
22
  */
23
+ export declare const createConfigContext: <T extends Values = Values>(props: FormContextProps<T>) => void;
24
+ /**
25
+ * @deprecated
26
+ *
27
+ * 已弃用,请使用 **createConfigContext**
28
+ */
23
29
  export declare const createContext: <T extends Values = Values>(props: FormContextProps<T>) => void;
24
30
  /**
25
31
  * 获取表单上下文配置
@@ -32,9 +38,15 @@ export declare const createContext: <T extends Values = Values>(props: FormConte
32
38
  *
33
39
  * @example
34
40
  * ```ts
35
- * const context = useContext()
41
+ * const context = useConfigContext()
36
42
  * console.log(context.readonly, context.disabled)
37
43
  * ```
38
44
  */
39
- export declare function useContext(): FormContextProps;
45
+ export declare function useConfigContext(): FormContextProps;
46
+ /**
47
+ * @deprecated
48
+ *
49
+ * 已弃用,请使用 **useConfigContext**
50
+ */
51
+ export declare const useContext: typeof useConfigContext;
40
52
  //# sourceMappingURL=useContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useContext.d.ts","sourceRoot":"","sources":["../../src/hooks/useContext.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAE1C,yBAAyB;AACzB,eAAO,MAAM,gBAAgB,eAAwB,CAAA;AAErD;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,IAAI,CACvE,eAAe,CAAC,CAAC,CAAC,EAChB,MAAM,GACN,YAAY,GACZ,kBAAkB,GAClB,qBAAqB,GACrB,gBAAgB,GAChB,UAAU,GACV,gBAAgB,GAChB,gBAAgB,GAChB,gBAAgB,CACnB;CAAG;AAEJ;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,OAAO,gBAAgB,CAAC,CAAC,CAAC,SAElF,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,IAAI,gBAAgB,CAQ7C"}
1
+ {"version":3,"file":"useContext.d.ts","sourceRoot":"","sources":["../../src/hooks/useContext.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAE1C,yBAAyB;AACzB,eAAO,MAAM,gBAAgB,eAAwB,CAAA;AAErD;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,IAAI,CACvE,eAAe,CAAC,CAAC,CAAC,EAChB,MAAM,GACN,YAAY,GACZ,kBAAkB,GAClB,qBAAqB,GACrB,gBAAgB,GAChB,UAAU,GACV,gBAAgB,GAChB,gBAAgB,GAChB,gBAAgB,CACnB;CAAG;AAEJ;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,MAAM,GAAG,MAAM,EAC3D,OAAO,gBAAgB,CAAC,CAAC,CAAC,SAG3B,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAXU,CAAC,SAAS,MAAM,kBAC3C,gBAAgB,CAAC,CAAC,CAAC,SAUoB,CAAA;AAEhD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,IAAI,gBAAgB,CAQnD;AAED;;;;GAIG;AACH,eAAO,MAAM,UAAU,yBAAmB,CAAA"}
@@ -1,11 +1,12 @@
1
1
  import { Ref } from 'vue';
2
- import { NamePath, SchemxDictionary, Values } from '@schemx/core';
2
+ import { SchemxDictionary } from '../types/dictionary';
3
+ import { NamePath, Values } from '@schemx/core';
3
4
 
4
- export type { SchemxDictionary, SchemxWithDictionary } from '@schemx/core';
5
+ export type { SchemxDictionary, SchemxWithDictionary } from '../types/dictionary';
5
6
  /**
6
7
  * useDictionary 返回值
7
8
  */
8
- export interface UseDictOptionsReturn {
9
+ export interface UseDictionaryReturn {
9
10
  /** 远程加载的字典选项列表(响应式) */
10
11
  list: Ref<any[]>;
11
12
  /** 请求加载状态(响应式) */
@@ -19,6 +20,12 @@ export interface UseDictOptionsReturn {
19
20
  /** 直接修改 list 的值,不触发 api 调用 */
20
21
  mutate: (data: any[]) => void;
21
22
  }
23
+ /**
24
+ * @deprecated
25
+ *
26
+ * 已弃用,请使用 **UseDictionaryReturn**
27
+ */
28
+ export type UseDictOptionsReturn = UseDictionaryReturn;
22
29
  /**
23
30
  * 将未知抛出值规范化为 `Error` 实例
24
31
  *
@@ -58,6 +65,6 @@ export declare function normalizeError(err: unknown): Error;
58
65
  * }, 'city')
59
66
  * ```
60
67
  */
61
- export declare const useDictionary: <TValues extends Values = Values, TName extends NamePath<TValues> = NamePath<TValues>>(options: SchemxDictionary<TValues>, fieldName?: TName) => UseDictOptionsReturn;
68
+ export declare const useDictionary: <TValues extends Values = Values, TName extends NamePath<TValues> = NamePath<TValues>>(options: SchemxDictionary<TValues>, fieldName?: TName) => UseDictionaryReturn;
62
69
  export default useDictionary;
63
70
  //# sourceMappingURL=useDictionary.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDictionary.d.ts","sourceRoot":"","sources":["../../src/hooks/useDictionary.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAa,GAAG,EAAO,MAAM,KAAK,CAAA;AAKzC,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAEtE,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAE1E;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,uBAAuB;IACvB,IAAI,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,CAAA;IAChB,kBAAkB;IAClB,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;IACrB,kBAAkB;IAClB,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,SAAS,CAAC,CAAA;IAC7B,eAAe;IACf,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7B,qBAAqB;IACrB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5B,8BAA8B;IAC9B,MAAM,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;CAC9B;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,KAAK,CAIlD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,aAAa,GACxB,OAAO,SAAS,MAAM,GAAG,MAAM,EAC/B,KAAK,SAAS,QAAQ,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,EAEnD,SAAS,gBAAgB,CAAC,OAAO,CAAC,EAClC,YAAY,KAAK,KAChB,oBAmIF,CAAA;AAED,eAAe,aAAa,CAAA"}
1
+ {"version":3,"file":"useDictionary.d.ts","sourceRoot":"","sources":["../../src/hooks/useDictionary.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAa,GAAG,EAAO,MAAM,KAAK,CAAA;AAEzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAK1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAGpD,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAEhF;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,uBAAuB;IACvB,IAAI,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,CAAA;IAChB,kBAAkB;IAClB,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;IACrB,kBAAkB;IAClB,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,SAAS,CAAC,CAAA;IAC7B,eAAe;IACf,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7B,qBAAqB;IACrB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5B,8BAA8B;IAC9B,MAAM,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;CAC9B;AAED;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,mBAAmB,CAAA;AAEtD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,KAAK,CAIlD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,aAAa,GACxB,OAAO,SAAS,MAAM,GAAG,MAAM,EAC/B,KAAK,SAAS,QAAQ,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,EAEnD,SAAS,gBAAgB,CAAC,OAAO,CAAC,EAClC,YAAY,KAAK,KAChB,mBAmIF,CAAA;AAED,eAAe,aAAa,CAAA"}
@@ -34,5 +34,36 @@ import { NamePath, Values } from '@schemx/core';
34
34
  * ```
35
35
  */
36
36
  export declare const useField: <TValues extends Values = Values>(name: NamePath<TValues>) => FieldInstance<TValues>;
37
+ /**
38
+ * 向子组件树注入当前字段上下文。
39
+ *
40
+ * 应在 FormItem(或任何创建了 useField 的组件)的 setup 中调用。
41
+ *
42
+ * @param field - useField 返回的字段实例
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * // FormItem 中
47
+ * const field = useField('date')
48
+ * createFieldContext(field)
49
+ *
50
+ * ```
51
+ */
52
+ export declare function createFieldContext<TValues extends Values = Values>(field: FieldInstance<TValues>): void;
53
+ /**
54
+ * 从最近的 FormItem 获取当前字段上下文。
55
+ *
56
+ * 必须在 FormItem 的组件子树内调用,否则抛出错误。
57
+ *
58
+ * @returns useField 返回的字段实例
59
+ *
60
+ * @throws 当不在 FormItem 子树内时抛出
61
+ *
62
+ * @example
63
+ * const field = useFieldContext()
64
+ * field.error.value // string[] | undefined
65
+ * field.getValue() // 当前字段值(Vue 响应式)
66
+ */
67
+ export declare function useFieldContext(): ReturnType<typeof useField>;
37
68
  export default useField;
38
69
  //# sourceMappingURL=useField.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useField.d.ts","sourceRoot":"","sources":["../../src/hooks/useField.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAMH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAI9C,OAAO,KAAK,EAAE,QAAQ,EAAkB,MAAM,EAAE,MAAM,cAAc,CAAA;AAoEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,SAAS,MAAM,GAAG,MAAM,EACtD,MAAM,QAAQ,CAAC,OAAO,CAAC,KACtB,aAAa,CAAC,OAAO,CAuCvB,CAAA;AAED,eAAe,QAAQ,CAAA"}
1
+ {"version":3,"file":"useField.d.ts","sourceRoot":"","sources":["../../src/hooks/useField.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAMH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAI9C,OAAO,KAAK,EAAE,QAAQ,EAAkB,MAAM,EAAE,MAAM,cAAc,CAAA;AAuEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,SAAS,MAAM,GAAG,MAAM,EACtD,MAAM,QAAQ,CAAC,OAAO,CAAC,KACtB,aAAa,CAAC,OAAO,CAuCvB,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,EAChE,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,GAC5B,IAAI,CAEN;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,IAAI,UAAU,CAAC,OAAO,QAAQ,CAAC,CAQ7D;AAED,eAAe,QAAQ,CAAA"}
@@ -37,7 +37,7 @@ export interface UseFormOptions<TValues extends Values> extends CreateFormOption
37
37
  * form.setFieldValue('name', 'John')
38
38
  * ```
39
39
  */
40
- export declare function useForm<TValues extends Values = Values>(options: UseFormOptions<TValues>): SchemxInstance<TValues>;
40
+ export declare function useForm<TValues extends Values = Values>(options?: UseFormOptions<TValues>): SchemxInstance<TValues>;
41
41
  /**
42
42
  * 获取表单实例
43
43
  *
@@ -51,9 +51,9 @@ export declare function useForm<TValues extends Values = Values>(options: UseFor
51
51
  *
52
52
  * @example
53
53
  * ```ts
54
- * const form = useFormInstance()
54
+ * const form = useFormContext()
55
55
  * form.setFieldValue('name', 'hello')
56
56
  * ```
57
57
  */
58
- export declare function useFormInstance<TValues extends Values = Values>(): SchemxInstance<TValues>;
58
+ export declare function useFormContext<TValues extends Values = Values>(): SchemxInstance<TValues>;
59
59
  //# sourceMappingURL=useForm.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../src/hooks/useForm.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAEvF,mDAAmD;AACnD,eAAO,MAAM,mBAAmB,eAA4B,CAAA;AAC5D,0DAA0D;AAC1D,eAAO,MAAM,iBAAiB,QAAsB,CAAA;AAEpD;;;;;;GAMG;AACH,MAAM,WAAW,cAAc,CAAC,OAAO,SAAS,MAAM,CAAE,SAAQ,iBAAiB,CAC/E,OAAO,EACP,QAAQ,CAAC,OAAO,CAAC,CAClB;CAAG;AAEJ;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,OAAO,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,EACrD,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC,GAC/B,cAAc,CAAC,OAAO,CAAC,CAkBzB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAC7B,OAAO,SAAS,MAAM,GAAG,MAAM,KAC5B,cAAc,CAAC,OAAO,CAAC,CAQ3B"}
1
+ {"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../src/hooks/useForm.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAEvF,mDAAmD;AACnD,eAAO,MAAM,mBAAmB,eAA4B,CAAA;AAE5D,0DAA0D;AAC1D,eAAO,MAAM,iBAAiB,QAAsB,CAAA;AAEpD;;;;;;GAMG;AACH,MAAM,WAAW,cAAc,CAAC,OAAO,SAAS,MAAM,CAAE,SAAQ,iBAAiB,CAC/E,OAAO,EACP,QAAQ,CAAC,OAAO,CAAC,CAClB;CAAG;AAEJ;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,OAAO,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,EACrD,OAAO,GAAE,cAAc,CAAC,OAAO,CAAM,GACpC,cAAc,CAAC,OAAO,CAAC,CAkBzB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,cAAc,CAC5B,OAAO,SAAS,MAAM,GAAG,MAAM,KAC5B,cAAc,CAAC,OAAO,CAAC,CAQ3B"}
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),t=require("classnames"),i=require("es-toolkit");var r=Object.defineProperty,n=(e,t,i)=>((e,t,i)=>t in e?r(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i)(e,"symbol"!=typeof t?t+"":t,i),s=Symbol.for("preact-signals");function o(){if(c>1)c--;else{var e,t=!1;for(!function(){var e=p;for(p=void 0;void 0!==e;)e.S.v===e.v&&(e.S.i=e.i),e=e.o}();void 0!==u;){var i=u;for(u=void 0,d++;void 0!==i;){var r=i.u;if(i.u=void 0,i.f&=-3,!(8&i.f)&&m(i))try{i.c()}catch(n){t||(e=n,t=!0)}i=r}}if(d=0,c--,t)throw e}}var l=void 0;function a(e){var t=l;l=void 0;try{return e()}finally{l=t}}var u=void 0,c=0,d=0,h=0,f=0,p=void 0,v=0;function y(e){if(void 0!==l){var t=e.n;if(void 0===t||t.t!==l)return t={i:0,S:e,p:l.s,n:void 0,t:l,e:void 0,x:void 0,r:t},void 0!==l.s&&(l.s.n=t),l.s=t,e.n=t,32&l.f&&e.S(t),t;if(-1===t.i)return t.i=0,void 0!==t.n&&(t.n.p=t.p,void 0!==t.p&&(t.p.n=t.n),t.p=l.s,t.n=void 0,l.s.n=t,l.s=t),t}}function g(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=null==t?void 0:t.watched,this.Z=null==t?void 0:t.unwatched,this.name=null==t?void 0:t.name}function m(e){for(var t=e.s;void 0!==t;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function b(e){for(var t=e.s;void 0!==t;t=t.n){var i=t.S.n;if(void 0!==i&&(t.r=i),t.S.n=t,t.i=-1,void 0===t.n){e.s=t;break}}}function F(e){for(var t=e.s,i=void 0;void 0!==t;){var r=t.p;-1===t.i?(t.S.U(t),void 0!==r&&(r.n=t.n),void 0!==t.n&&(t.n.p=r)):i=t,t.S.n=t.r,void 0!==t.r&&(t.r=void 0),t=r}e.s=i}function w(e,t){g.call(this,void 0),this.x=e,this.s=void 0,this.g=v-1,this.f=4,this.W=null==t?void 0:t.watched,this.Z=null==t?void 0:t.unwatched,this.name=null==t?void 0:t.name}function S(e){var t=e.m;if(e.m=void 0,"function"==typeof t){c++;var i=l;l=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,V(e),r}finally{l=i,o()}}}function V(e){for(var t=e.s;void 0!==t;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,S(e)}function k(e){if(l!==this)throw new Error("Out-of-order effect");F(this),l=e,this.f&=-2,8&this.f&&V(this),o()}function A(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=null==t?void 0:t.name}function x(e,t){var i=new A(e,t);try{i.c()}catch(n){throw i.d(),n}var r=i.d.bind(i);return r[Symbol.dispose]=r,r}function R(e,t){return new g(e,t)}g.prototype.brand=s,g.prototype.h=function(){return!0},g.prototype.S=function(e){var t=this,i=this.t;i!==e&&void 0===e.e&&(e.x=i,this.t=e,void 0!==i?i.e=e:a(function(){var e;null==(e=t.W)||e.call(t)}))},g.prototype.U=function(e){var t=this;if(void 0!==this.t){var i=e.e,r=e.x;void 0!==i&&(i.x=r,e.e=void 0),void 0!==r&&(r.e=i,e.x=void 0),e===this.t&&(this.t=r,void 0===r&&a(function(){var e;null==(e=t.Z)||e.call(t)}))}},g.prototype.subscribe=function(e){var t=this;return x(function(){var i=t.value,r=l;l=void 0;try{e(i)}finally{l=r}},{name:"sub"})},g.prototype.valueOf=function(){return this.value},g.prototype.toString=function(){return this.value+""},g.prototype.toJSON=function(){return this.value},g.prototype.peek=function(){var e=this;return a(function(){return e.value})},Object.defineProperty(g.prototype,"value",{get:function(){var e=y(this);return void 0!==e&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(d>100)throw new Error("Cycle detected");i=this,0!==c&&0===d&&i.l!==f&&(i.l=f,p={S:i,v:i.v,i:i.i,o:p}),this.v=e,this.i++,v++,c++;try{for(var t=this.t;void 0!==t;t=t.x)t.t.N()}finally{o()}}var i}}),w.prototype=new g,w.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if(32==(36&this.f))return!0;if(this.f&=-5,this.g===v)return!0;if(this.g=v,this.f|=1,this.i>0&&!m(this))return this.f&=-2,!0;var e=l;try{b(this),l=this;var t=this.x();(16&this.f||this.v!==t||0===this.i)&&(this.v=t,this.f&=-17,this.i++)}catch(i){this.v=i,this.f|=16,this.i++}return l=e,F(this),this.f&=-2,!0},w.prototype.S=function(e){if(void 0===this.t){this.f|=36;for(var t=this.s;void 0!==t;t=t.n)t.S.S(t)}g.prototype.S.call(this,e)},w.prototype.U=function(e){if(void 0!==this.t&&(g.prototype.U.call(this,e),void 0===this.t)){this.f&=-33;for(var t=this.s;void 0!==t;t=t.n)t.S.U(t)}},w.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;void 0!==e;e=e.x)e.t.N()}},Object.defineProperty(w.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=y(this);if(this.h(),void 0!==e&&(e.i=this.i),16&this.f)throw this.v;return this.v}}),A.prototype.c=function(){var e=this.S();try{if(8&this.f)return;if(void 0===this.x)return;var t=this.x();"function"==typeof t&&(this.m=t)}finally{e()}},A.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,S(this),b(this),c++;var e=l;return l=this,k.bind(this,e)},A.prototype.N=function(){2&this.f||(this.f|=2,this.u=u,u=this)},A.prototype.d=function(){this.f|=8,1&this.f||V(this)},A.prototype.dispose=function(){this.d()};const j="object"==typeof globalThis&&globalThis||"object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||function(){return this}();function O(e,t,{signal:i,edges:r}={}){let n,s=null;const o=null!=r&&r.includes("leading"),l=null==r||r.includes("trailing"),a=()=>{null!==s&&(e.apply(n,s),n=void 0,s=null)};let u=null;const c=()=>{null!=u&&clearTimeout(u),u=setTimeout(()=>{u=null,l&&a(),d()},t)},d=()=>{null!==u&&(clearTimeout(u),u=null),n=void 0,s=null},h=function(...e){if(null==i?void 0:i.aborted)return;n=this,s=e;const t=null==u;c(),o&&t&&a()};return h.schedule=c,h.cancel=d,h.flush=()=>{a()},null==i||i.addEventListener("abort",d,{once:!0}),h}function T(){}function C(e){return void 0!==j.Buffer&&j.Buffer.isBuffer(e)}function P(e){return Object.getOwnPropertySymbols(e).filter(t=>Object.prototype.propertyIsEnumerable.call(e,t))}function E(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":Object.prototype.toString.call(e)}const B="[object RegExp]",N="[object String]",M="[object Number]",I="[object Boolean]",$="[object Arguments]",D="[object Symbol]",U="[object Date]",_="[object Map]",q="[object Set]",z="[object Array]",W="[object ArrayBuffer]",L="[object Object]",G="[object DataView]",K="[object Uint8Array]",Z="[object Uint8ClampedArray]",H="[object Uint16Array]",X="[object Uint32Array]",J="[object Int8Array]",Q="[object Int16Array]",Y="[object Int32Array]",ee="[object Float32Array]",te="[object Float64Array]";function ie(e,t,i,r=new Map,n=void 0){const s=null==n?void 0:n(e,t,i,r);if(void 0!==s)return s;if(null==(o=e)||"object"!=typeof o&&"function"!=typeof o)return e;var o,l;if(r.has(e))return r.get(e);if(Array.isArray(e)){const t=new Array(e.length);r.set(e,t);for(let s=0;s<e.length;s++)t[s]=ie(e[s],s,i,r,n);return Object.hasOwn(e,"index")&&(t.index=e.index),Object.hasOwn(e,"input")&&(t.input=e.input),t}if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp){const t=new RegExp(e.source,e.flags);return t.lastIndex=e.lastIndex,t}if(e instanceof Map){const t=new Map;r.set(e,t);for(const[s,o]of e)t.set(s,ie(o,s,i,r,n));return t}if(e instanceof Set){const t=new Set;r.set(e,t);for(const s of e)t.add(ie(s,void 0,i,r,n));return t}if(C(e))return e.subarray();if(l=e,ArrayBuffer.isView(l)&&!(l instanceof DataView)){const t=new(Object.getPrototypeOf(e).constructor)(e.length);r.set(e,t);for(let s=0;s<e.length;s++)t[s]=ie(e[s],s,i,r,n);return t}if(e instanceof ArrayBuffer||"undefined"!=typeof SharedArrayBuffer&&e instanceof SharedArrayBuffer)return e.slice(0);if(e instanceof DataView){const t=new DataView(e.buffer.slice(0),e.byteOffset,e.byteLength);return r.set(e,t),re(t,e,i,r,n),t}if("undefined"!=typeof File&&e instanceof File){const t=new File([e],e.name,{type:e.type});return r.set(e,t),re(t,e,i,r,n),t}if("undefined"!=typeof Blob&&e instanceof Blob){const t=new Blob([e],{type:e.type});return r.set(e,t),re(t,e,i,r,n),t}if(e instanceof Error){const t=structuredClone(e);return r.set(e,t),t.message=e.message,t.name=e.name,t.stack=e.stack,t.cause=e.cause,t.constructor=e.constructor,re(t,e,i,r,n),t}if(e instanceof Boolean){const t=new Boolean(e.valueOf());return r.set(e,t),re(t,e,i,r,n),t}if(e instanceof Number){const t=new Number(e.valueOf());return r.set(e,t),re(t,e,i,r,n),t}if(e instanceof String){const t=new String(e.valueOf());return r.set(e,t),re(t,e,i,r,n),t}if("object"==typeof e&&function(e){switch(E(e)){case $:case z:case W:case G:case I:case U:case ee:case te:case J:case Q:case Y:case _:case M:case L:case B:case q:case N:case D:case K:case Z:case H:case X:return!0;default:return!1}}(e)){const t=Object.create(Object.getPrototypeOf(e));return r.set(e,t),re(t,e,i,r,n),t}return e}function re(e,t,i=e,r,n){const s=[...Object.keys(t),...P(t)];for(let o=0;o<s.length;o++){const l=s[o],a=Object.getOwnPropertyDescriptor(e,l);(null==a||a.writable)&&(e[l]=ie(t[l],l,i,r,n))}}function ne(e){return ie(e,void 0,e,new Map,void 0)}function se(e){if(!e||"object"!=typeof e)return!1;const t=Object.getPrototypeOf(e);return(null===t||t===Object.prototype||null===Object.getPrototypeOf(t))&&"[object Object]"===Object.prototype.toString.call(e)}function oe(e){return"__proto__"===e}function le(e,t){const i={};for(let r=0;r<t.length;r++){const n=t[r];Object.hasOwn(e,n)&&(i[n]=e[n])}return i}function ae(e,t){return e===t||Number.isNaN(e)&&Number.isNaN(t)}function ue(e,t,i,r,n,s,o){const l=o(e,t,i,r,n,s);if(void 0!==l)return l;if(typeof e==typeof t)switch(typeof e){case"bigint":case"string":case"boolean":case"symbol":case"undefined":case"function":return e===t;case"number":return e===t||Object.is(e,t);case"object":return ce(e,t,s,o)}return ce(e,t,s,o)}function ce(e,t,i,r){if(Object.is(e,t))return!0;let n=E(e),s=E(t);if("[object Arguments]"===n&&(n=L),"[object Arguments]"===s&&(s=L),n!==s)return!1;switch(n){case N:return e.toString()===t.toString();case M:return ae(e.valueOf(),t.valueOf());case I:case U:case D:return Object.is(e.valueOf(),t.valueOf());case B:return e.source===t.source&&e.flags===t.flags;case"[object Function]":return e===t}const o=(i=i??new Map).get(e),l=i.get(t);if(null!=o&&null!=l)return o===t;i.set(e,t),i.set(t,e);try{switch(n){case _:if(e.size!==t.size)return!1;for(const[n,s]of e.entries())if(!t.has(n)||!ue(s,t.get(n),n,e,t,i,r))return!1;return!0;case q:{if(e.size!==t.size)return!1;const n=Array.from(e.values()),s=Array.from(t.values());for(let o=0;o<n.length;o++){const l=n[o],a=s.findIndex(n=>ue(l,n,void 0,e,t,i,r));if(-1===a)return!1;s.splice(a,1)}return!0}case z:case K:case Z:case H:case X:case"[object BigUint64Array]":case J:case Q:case Y:case"[object BigInt64Array]":case ee:case te:if(C(e)!==C(t))return!1;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!ue(e[n],t[n],n,e,t,i,r))return!1;return!0;case W:return e.byteLength===t.byteLength&&ce(new Uint8Array(e),new Uint8Array(t),i,r);case G:return e.byteLength===t.byteLength&&e.byteOffset===t.byteOffset&&ce(new Uint8Array(e),new Uint8Array(t),i,r);case"[object Error]":return e.name===t.name&&e.message===t.message;case L:{if(!(ce(e.constructor,t.constructor,i,r)||se(e)&&se(t)))return!1;const n=[...Object.keys(e),...P(e)],s=[...Object.keys(t),...P(t)];if(n.length!==s.length)return!1;for(let o=0;o<n.length;o++){const s=n[o],l=e[s];if(!Object.hasOwn(t,s))return!1;if(!ue(l,t[s],s,e,t,i,r))return!1}return!0}default:return!1}}finally{i.delete(e),i.delete(t)}}function de(e,t){return function(e,t,i){return ue(e,t,void 0,void 0,void 0,void 0,i)}(e,t,T)}function he(e){const{value:t,initialValue:i,touched:r,pending:n}=e||{},s=R(void 0===t?void 0:ne(t)),o=R(void 0===i?void 0:ne(i)),l=R(r??!1),a=R(n??!1),u=R([]);return{value:s,initialValue:o,touched:l,pending:a,pendingMessage:u,setValue:e=>{s.value=e},setInitialValue:e=>{o.value=e},setTouched:e=>{l.value=e},setPending:(e,t)=>{a.value=e,e?t&&(u.value=Array.isArray(t)?t:[t]):u.value=[]},reset:(e=o.peek())=>{s.value=ne(e),l.value=!1,a.value=!1},peek:()=>({value:s.peek(),initialValue:o.peek(),touched:l.peek(),pending:a.peek(),pendingMessage:u.peek()})}}class fe{constructor(e={}){n(this,"records",new Map),n(this,"version",R(0)),n(this,"normalizeKey"),this.normalizeKey=e.normalizeKey??ve}getKey(e){return this.normalizeKey(e)}get(e){const t=this.records.get(this.getKey(e));if(t)return t.value;this.version.value}peek(e){var t;return null==(t=this.records.get(this.getKey(e)))?void 0:t.value}set(e,t){const i=this.getKey(e),r=this.records.has(i);return this.records.set(i,{key:e,value:t}),r||this.version.value++,this}has(e){return this.records.has(this.getKey(e))}delete(e){const t=this.getKey(e),i=this.records.get(t);return!!i&&(this.records.delete(t),pe(i.value),this.version.value++,!0)}clear(){if(0!==this.records.size){for(const e of this.records.values())pe(e.value);this.records.clear(),this.version.value++}}keys(){return this.version.value,Array.from(this.records.values(),e=>e.key).values()}values(){return this.version.value,Array.from(this.records.values(),e=>e.value).values()}entries(){return this.version.value,Array.from(this.records.values(),e=>[e.key,e.value]).values()}}function pe(e){e.value.value=void 0,e.initialValue.value=void 0,e.touched.value=!1,e.pending.value=!1}function ve(e){return Array.isArray(e)?e.map(e=>String(e)).join("."):String(e)}function ye(e){return x(e)}function ge(e){!function(e){if(c>0)return e();f=++h,c++;try{return e()}finally{o()}}(e)}class me{constructor(){n(this,"signals",new Map),n(this,"version",R(0))}get(e){const t=this.signals.get(e);if(t)return t.value;this.version.value}set(e,t){const i=this.signals.get(e);return i?i.value=t:(this.signals.set(e,R(t)),this.version.value++),this}peek(e){var t;return null==(t=this.signals.get(e))?void 0:t.peek()}has(e){return this.signals.has(e)}delete(e){const t=this.signals.get(e);return!!t&&(this.signals.delete(e),ge(()=>{t.value=void 0,this.version.value++}),!0)}clear(){if(0===this.signals.size)return;const e=[...this.signals.values()];this.signals.clear(),ge(()=>{for(const t of e)t.value=void 0;this.version.value++})}keys(){return this.version.value,this.signals.keys()}values(){return this.version.value,Array.from(this.signals.values(),e=>e.value).values()}entries(){return this.version.value,Array.from(this.signals.entries(),([e,t])=>[e,t.value]).values()}}function be(e){return!Fe(e)&&!we(e)}function Fe(e){return"group"===e.componentType}function we(e){return"dependency"===e.componentType}function Se(e){return"group"===e.componentType}const Ve=e=>Object.hasOwn(e,"componentType")&&"string"==typeof e.componentType;function ke(e){const t=[];return(e=>Object.hasOwn(e,"name")&&[null,void 0,""].every(t=>t!==e.name))(e)||t.push("name"),Ve(e)||t.push("componentType"),t}function Ae(e){const t=[];return Ve(e)||t.push("componentType"),Object.hasOwn(e,"children")&&Array.isArray(e.children)||t.push("children"),t}function xe(e){const t=[];return Ve(e)||t.push("componentType"),Object.hasOwn(e,"to")&&Array.isArray(e.to)||t.push("to"),"function"!=typeof e.renderer&&t.push("renderer"),t}function Re(e,t,i){const r="name"in t&&t.name||t.componentType||"unknown";return`[schemx] schemas[${e}] (${String(r)}) 缺少必填项: ${i.join(", ")},已被过滤`}function je(e){const t=[],i=[];for(let r=0;r<e.length;r++){const n=e[r];let s=[];if(Fe(n)){if(s=Ae(n),s.length>0){i.push(Re(r,n,s));continue}t.push({...n,children:je(n.children)})}else if(we(n)){if(s=xe(n),s.length>0){i.push(Re(r,n,s));continue}t.push(n)}else if(be(n)){if(s=ke(n),s.length>0){i.push(Re(r,n,s));continue}t.push(n)}}return i.length&&console.warn(i.join("\n")),t}function Oe(e){if(null==e)return"";if("string"==typeof e)return e;if(Array.isArray(e))return e.map(Oe).join(",");const t=String(e);return"0"===t&&Object.is(Number(e),-0)?"-0":t}function Te(e){var t;return"string"==typeof e||"symbol"==typeof e?e:Object.is(null==(t=null==e?void 0:e.valueOf)?void 0:t.call(e),-0)?"-0":String(e)}function Ce(e){if(Array.isArray(e))return e.map(Te);if("symbol"==typeof e)return[e];const t=[],i=(e=Oe(e)).length;if(0===i)return t;let r=0,n="",s="",o=!1;for(46===e.charCodeAt(0)&&(t.push(""),r++);r<i;){const l=e[r];s?"\\"===l&&r+1<i?(r++,n+=e[r]):l===s?s="":n+=l:o?'"'===l||"'"===l?s=l:"]"===l?(o=!1,t.push(n),n=""):n+=l:"["===l?(o=!0,n&&(t.push(n),n="")):"."===l?n&&(t.push(n),n=""):n+=l,r++}return n&&t.push(n),t}function Pe(e,t,i){if(null==e)return i;switch(typeof t){case"string":{if(oe(t))return i;const r=e[t];return void 0===r?function(e){switch(typeof e){case"number":case"symbol":return!1;case"string":return e.includes(".")||e.includes("[")||e.includes("]")}}(t)?Pe(e,Ce(t),i):i:r}case"number":case"symbol":{"number"==typeof t&&(t=Te(t));const r=e[t];return void 0===r?i:r}default:{if(Array.isArray(t))return function(e,t,i){if(0===t.length)return i;let r=e;for(let n=0;n<t.length;n++){if(null==r)return i;if(oe(t[n]))return i;r=r[t[n]]}return void 0===r?i:r}(e,t,i);if(oe(t=Object.is(null==t?void 0:t.valueOf(),-0)?"-0":String(t)))return i;const r=e[t];return void 0===r?i:r}}}function Ee(e){return null!==e&&("object"==typeof e||"function"==typeof e)}const Be=/^(?:0|[1-9]\d*)$/;function Ne(e,t=Number.MAX_SAFE_INTEGER){switch(typeof e){case"number":return Number.isInteger(e)&&e>=0&&e<t;case"symbol":return!1;case"string":return Be.test(e)}}const Me=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Ie=/^\w*$/;function $e(e,t){return!Array.isArray(e)&&(!("number"!=typeof e&&"boolean"!=typeof e&&null!=e&&!function(e){return"symbol"==typeof e||e instanceof Symbol}(e))||("string"==typeof e&&(Ie.test(e)||!Me.test(e))||null!=t&&Object.hasOwn(t,e)))}const De=(e,t,i)=>{const r=e[t];Object.hasOwn(e,t)&&ae(r,i)&&(void 0!==i||t in e)||(e[t]=i)};function Ue(e,t,i){return function(e,t,i,r){if(null==e&&!Ee(e))return e;let n;n=$e(t,e)?[t]:Array.isArray(t)?t:Ce(t);const s=i(Pe(e,n));let o=e;for(let l=0;l<n.length&&null!=o;l++){const t=Te(n[l]);if(oe(t))continue;let i;if(l===n.length-1)i=s;else{const s=o[t],a=null==r?void 0:r(s,t,e);i=void 0!==a?a:Ee(s)?s:Ne(n[l+1])?[]:{}}De(o,t,i),o=o[t]}return e}(e,t,()=>i,()=>{})}function _e(e,t){return""===t||Array.isArray(t)&&0===t.length?e:Pe(e,We(t))}function qe(e,t,i){null!=e&&Ue(e,We(t),i)}function ze(e,t=""){const i=[];for(const r of Object.keys(e)){const n=t?`${t}.${r}`:r,s=e[r];Array.isArray(s)?s.forEach((e,t)=>{const r=`${n}[${t}]`;null!==e&&"object"==typeof e?i.push(...ze(e,r)):i.push(r)}):null!==s&&"object"==typeof s?i.push(...ze(s,n)):i.push(n)}return i}const We=e=>Array.isArray(e)?e.map(e=>"number"==typeof e?e:String(e)):e;function Le(e){let t=null;return(...i)=>t||(t=e(...i).finally(()=>{t=null}),t)}function Ge(e,t){const i={};for(const r of Object.keys(e))de(e[r],t[r])||(i[r]=e[r]);return i}const Ke={required:!1,readonly:!1,disabled:!1,visible:!0,labelIcon:"",labelAlign:"left",labelPosition:"left",labelWidth:"auto",validationTrigger:"blur",colon:!0},Ze=Object.keys(Ke);class He{constructor(){n(this,"rules",new Map),n(this,"errors",new me)}register(e,t,i){const r=Array.isArray(t)?t:[t],n=this.rules.get(e);n?(n.schemas.push(...r),i&&(n.defaultMessage=i)):this.rules.set(e,{schemas:r,defaultMessage:i})}unregister(e){this.rules.delete(e),this.errors.delete(e)}getFieldError(e){return this.errors.get(e)}setFieldError(e,t){this.errors.set(e,t)}async validateField(e,t){const i=Array.isArray(e)?e:[e];this.reset(i);let r=!0;for(const n of i){(await this.validateSingleRule(n,t)).ok||(r=!1)}return this.buildResult(r,t)}async validate(e){let t=!0;this.reset();for(const i of this.rules.keys()){(await this.validateSingleRule(i,e)).ok||(t=!1)}return this.buildResult(t,e)}reset(e){ge(e?()=>{for(const t of e)this.errors.set(t,[])}:()=>{for(const e of this.rules.keys())this.errors.set(e,[]);for(const e of[...this.errors.keys()])this.rules.has(e)||this.errors.delete(e)})}buildResult(e,t){return e?{ok:!0,values:t}:{ok:!1,error:{errors:Array.from(this.errors.keys()).map(e=>({field:e,message:this.errors.peek(e)||[]})),values:t}}}failResult(e,t,i){return this.errors.set(e,t),{ok:!1,error:{errors:[{field:e,message:t}],values:i}}}async validateSingleRule(e,t){const i=this.rules.get(e);if(!i||0===i.schemas.length)return this.errors.delete(e),{ok:!0,values:t};const r=_e(t,e),n=[];null==r&&i.defaultMessage&&n.push(i.defaultMessage);for(const o of i.schemas)try{const e=await o["~standard"].validate(r);e.issues&&n.push(...e.issues.map(e=>e.message))}catch(s){console.warn(`[Validator] 校验字段 "${e}" 时发生错误:`,s),n.push("校验失败")}return n.length>0?this.failResult(e,n,t):(this.errors.delete(e),{ok:!0,values:t})}}function Xe(){return new He}function Je(e){return et(t=>{if(null==t||""===t){const t=(null==e?void 0:e.label)??"";return tt(t?`请输入${t}`:"此项为必填项")}return it(t)})}function Qe(e){return et(t=>{if(null==t||""===t||Array.isArray(t)&&0===t.length){const t=(null==e?void 0:e.label)??"";return tt(t?`请选择${t}`:"此项为必选项")}return it(t)})}function Ye(e){return et(t=>{if(null==t||Array.isArray(t)&&0===t.length){const t=(null==e?void 0:e.label)??"";return tt(t?`请上传${t}`:"此项为必传项")}return it(t)})}const et=e=>({"~standard":{version:1,vendor:"schemx",validate:e}}),tt=e=>({issues:[{message:e}]}),it=e=>({value:e});class rt{constructor(e){n(this,"renderers"),n(this,"defaultType"),this.renderers=new Map,this.defaultType=e}register(e,t,i){this.renderers.has(e)&&!1===(null==i?void 0:i.override)?console.warn(`[RendererRegistryType] RendererRegistry "${e}" already exists, skipping registration`):this.renderers.set(e,t)}registerAll(e){Object.entries(e).forEach(([e,t])=>{this.renderers.set(e,t)})}getRenderer(e){let t=this.renderers.get(e);return t||(console.warn(`[RendererRegistryType] RendererRegistry "${e}" not found, falling back to default "${this.defaultType}"`),this.defaultType&&(t=this.renderers.get(this.defaultType))),t}hasRenderer(e){return this.renderers.has(e)}unregister(e){const t=e===this.defaultType,i=this.renderers.delete(e);if(t&&i){const e=this.renderers.keys().next().value;e&&(console.warn("[RendererRegistryType] Default renderer was removed, Please reset the default renderer."),this.defaultType=e)}return i}getTypes(){return Array.from(this.renderers.keys())}setDefault(e){this.renderers.has(e)?this.defaultType=e:console.warn(`[RendererRegistryType] Cannot set default to "${e}": renderer not registered`)}getDefault(){return this.defaultType}clear(){this.renderers.clear()}size(){return this.renderers.size}}function nt(e){return new rt(e)}class st{constructor(){n(this,"validators"),this.validators=new Map}register(e,t,i){this.validators.has(e)&&!1===(null==i?void 0:i.override)?console.warn(`[ValidatorsRegistryType] Validators "${e}" 已存在,跳过注册`):this.validators.set(e,t)}registerAll(e){Object.entries(e).forEach(([e,t])=>{this.validators.set(e,t)})}get(e){return this.validators.get(e)}resolveValidatorsBySchema(e){const t=(null==e?void 0:e.rules)??[],i=Array.isArray(t)?t:[t],r=[];for(const n of i)if("string"==typeof n)if(this.validators.has(n)){const t=this.validators.get(n);t&&r.push("function"==typeof t?t(e):t)}else console.warn(`[schemx] 未找到名为 "${n}" 的校验规则`);else n&&r.push(n);return r}has(e){return this.validators.has(e)}unregister(e){return this.validators.delete(e)}getNames(){return Array.from(this.validators.keys())}clear(){this.validators.clear()}size(){return this.validators.size}}function ot(){return new st}function lt(e=[]){const t=R(e);return{signal:t,get value(){return t.value},peek:()=>t.peek(),set:e=>{t.value=e},update:e=>{t.value=e(t.peek())},subscribe:e=>{let i=!0;const r=t.subscribe(t=>{i?i=!1:e(t)});return()=>{r()}}}}function at(e){if(!e||Array.isArray(e))return!1;const t=e;return"function"==typeof t.peek&&"function"==typeof t.set&&"function"==typeof t.update&&"function"==typeof t.subscribe}class ut extends Error{constructor(e,t){super(e),n(this,"schemaKey"),n(this,"schemaName"),this.name="CompileError",t&&"name"in t&&(this.schemaName=t.name),t&&"key"in t&&t.key&&(this.schemaKey=t.key)}}const ct=ut;function dt(e,t={},i=""){const r=[],n=je(e);for(let s=0;s<n.length;s++){const e=n[s];let o;o=Fe(e)?ft(e,s,t,i):we(e)?pt(e,s,i):ht(e,s,t,i),r.push(o)}return r}function ht(e,t,i={},r=""){const n=e.key??(r?`field:${r}/${e.name}`:`field:${e.name}`),s=function(e,t={}){const{componentProps:i,visible:r,readonly:n,disabled:s,required:o,placeholder:l,rules:a,validationTrigger:u,dependencies:c,...d}=e,h=r??Ke.visible,f=n??t.readonly??Ke.readonly,p=s??t.disabled??Ke.disabled,v=f?"right":(null==i?void 0:i.align)??d.contentAlign,y=vt(e),g={...i,readonly:f,disabled:p,placeholder:y,align:v},m=(Array.isArray(a)?a:[a]).filter(Boolean),b=o??(m.length>0||Ke.required),F={...d??{},key:d.key,name:d.name,label:d.label,componentType:d.componentType,visible:h,readonly:f,disabled:p,required:b,placeholder:y,componentProps:g,labelIcon:d.labelIcon||Ke.labelIcon,labelAlign:d.labelAlign||Ke.labelAlign,labelPosition:d.labelPosition||Ke.labelPosition,labelWidth:d.labelWidth||Ke.labelWidth,colon:d.colon??Ke.colon,rules:a,validationTrigger:u||Ke.validationTrigger};Object.hasOwn(e,"initialValue")&&(F.initialValue=d.initialValue);f&&(F.contentAlign="right",F.labelPosition="left");return F}(e,i);return{type:"field",key:n,name:e.name,rendererType:e.componentType,schema:s,dependencies:e.dependencies}}function ft(e,t,i={},r=""){const n=e.key??(r?`group:${r}/${t}`:`group:${t}`),{children:s,...o}=e;return{type:"group",key:n,schema:{...o,key:n},children:dt(s,i,n)}}function pt(e,t,i=""){const r=e.key??(i?`dependency:${i}/${t}`:`dependency:${t}`);if(!e.to||0===e.to.length)throw new ct("Dependency schema must have non-empty trigger fields",e);return{type:"dependency",key:r,trigger:[...e.to],renderer:(t,i)=>{const r=t.getValues();return e.renderer(r,t,{abortSignal:i})}}}function vt(e){var t;const i=(null==(t=e.componentProps)?void 0:t.placeholder)??e.placeholder;return null==i?["input","text","textarea"].includes(e.componentType)?`请输入${e.label||e.name}`:`请选择${e.label||e.name}`:i}const yt=e=>"group"===e.type;function gt(e,t,i){const r=mt(t,i);var n,s;(n=e.snapshot.peek(),s=r,n.visible===s.visible&&n.disabled===s.disabled&&n.readonly===s.readonly&&n.required===s.required&&n.label===s.label&&function(e,t){return e===t||!(!Array.isArray(e)||!Array.isArray(t))&&(e.length===t.length&&e.every((e,i)=>e===t[i]))}(n.rules,s.rules)&&n.placeholder===s.placeholder&&function(e,t){if(e===t)return!0;const i=Object.keys(e),r=Object.keys(t),n=e,s=t;return i.length===r.length&&i.every(e=>n[e]===s[e])}(n.componentProps,s.componentProps))||(e.snapshot.value=r)}function mt(e,t){const i=e.schema;return{visible:(null==t?void 0:t.visible)??i.visible??Ke.visible,disabled:(null==t?void 0:t.disabled)??i.disabled??Ke.disabled,readonly:(null==t?void 0:t.readonly)??i.readonly??Ke.readonly,required:(null==t?void 0:t.required)??i.required??Ke.required,label:i.label||"",rules:((null==t?void 0:t.rules)??i.rules)||[],placeholder:(null==t?void 0:t.placeholder)??i.placeholder??vt(i),componentProps:((null==t?void 0:t.componentProps)??i.componentProps)||{}}}function bt(e){const{descriptor:t,fieldModel:i,context:r,scope:n}=e,s=t.schema,o=t.dependencies;if(null==o||null==o.triggerFields||0===o.triggerFields.length)return;let l=0;const a=ye(()=>{const e=++l;r.formApi.getValues(o.triggerFields),r.scheduler.track(async function(e,t,i){const r=i.getValues(),[n]=await Promise.all([wt(e,t,r,i),Ft(e,r,i)]);return n}(o,s,r.formApi).then(r=>{n.disposed||e!==l||gt(i,t,r)}))});n.add(()=>{l+=1,a()})}async function Ft(e,t,i){if(e.trigger)try{await e.trigger(t,i)}catch(r){console.error("[schemx] trigger 执行错误:",r)}}async function wt(e,t,i,r){const[n,s,o,l,a,u,c]=await Promise.all([St({condition:e.componentProps,values:i,formApi:r,defaultValue:t.componentProps}),St({condition:e.placeholder,values:i,formApi:r,defaultValue:t.placeholder}),St({condition:e.required,values:i,formApi:r,defaultValue:t.required}),St({condition:e.readonly,values:i,formApi:r,defaultValue:t.readonly}),St({condition:e.disabled,values:i,formApi:r,defaultValue:t.disabled}),St({condition:e.visible,values:i,formApi:r,defaultValue:t.visible}),St({condition:e.rules,values:i,formApi:r,defaultValue:t.rules})]);return{componentProps:n,placeholder:s,required:o,readonly:l,disabled:a,visible:u,rules:c}}async function St(e){const{condition:t,values:i,formApi:r,defaultValue:n}=e;return null==t?n:async function(e,t,i,r){try{return await t(i,e)??r}catch(n){return console.error("[schemx] 解析动态属性时发生错误:",n),r}}(r,t,i,n)}function Vt(e){var t;const{node:i,descriptor:r,context:n}=e,s=e.scope??i.scope.child();null==(t=i.dependencySlot)||t.dispose();const o={loading:R(!1),error:R(null),version:R(0),abortController:R(null),run:async()=>{},dispose:()=>{}};return i.dependencyResourceScope=s,o.run=()=>{var e;if(s.disposed)return Promise.resolve();const t=i.descriptor,r=o.version.value+1;o.version.value=r,null==(e=o.abortController.value)||e.abort();const l=new AbortController;return o.abortController.value=l,o.loading.value=!0,o.error.value=null,n.scheduler.track((async()=>{try{const e=await Promise.resolve(t.renderer(n.formApi,l.signal));if(s.disposed||l.signal.aborted||r!==o.version.value)return;const a=dt(e,n.defaultProps);n.commitChildren(i,a)}catch(e){if(s.disposed||l.signal.aborted||r!==o.version.value)return;o.error.value=function(e){return e instanceof Error?e:new Error(String(e))}(e)}finally{s.disposed||l.signal.aborted||r!==o.version.value||(o.loading.value=!1)}})())},o.dispose=()=>{var e;o.version.value+=1,null==(e=o.abortController.value)||e.abort(),s.dispose()},s.add(()=>{var e;null==(e=o.abortController.value)||e.abort(),o.abortController.value=null,i.dependencySlot===o&&(i.dependencySlot=null),i.dependencyResourceScope===s&&(i.dependencyResourceScope=null)}),r.trigger.length>0&&function(e,t,i,r){let n=!0,s=!1;const o=ye(()=>{t.getValues(e),n||s||(s=!0,queueMicrotask(()=>{s=!1,r.disposed||i().catch(e=>{console.error("DependencyEffectSlot trigger run error:",e)})})),n=!1});r.add(o)}(r.trigger,n.formApi,()=>o.run(),s),i.dependencySlot=o,o.run().catch(e=>{console.error("DependencyEffectSlot initial run error:",e)}),o}class kt{constructor(){n(this,"fields",new Map)}register(e){const t=e.name;this.fields.set(t,e)}unregister(e,t){const i=e,r=this.fields.get(i);t&&(null==r?void 0:r.node)!==t||this.fields.delete(i)}get(e){const t=e;return this.fields.get(t)}list(){return Array.from(this.fields.values())}}function At(e){const{name:t,fieldModel:i,scope:r,context:n}=e,s=n.scheduler,o=R(!1),l=R(!1);let a=0;const u=e=>{const i=++a;s.schedule({id:`validation:${String(t)}`,priority:"post",scope:r,run:()=>{r.disposed||i!==a||(e=>{const{visible:i,readonly:r,disabled:s,label:l,rules:a}=e;if(!i||r||s||!a)return n.instance.unregisterRules(t),n.instance.setFieldError(t,[]),void(o.value=!1);n.instance.registerRules(t,a,`${l}为必填项`),o.value=!0})(e)}})};r.add(()=>{a+=1,n.instance.unregisterRules(t),n.instance.setFieldError(t,[]),o.value=!1});const c=ye(()=>{u((()=>{const e=i.snapshot.value;return{visible:e.visible,readonly:e.readonly,disabled:e.disabled,label:e.label,rules:e.rules}})())});r.add(c);return{registered:o,validating:l,validate:async()=>{l.value=!0;try{return await n.instance.validateField(t)}finally{l.value=!1}},dispose:()=>{r.dispose()}}}function xt(e){const t=new Set;e&&t.add(e);const i=(e,...i)=>{for(const r of Array.from(t))e(r,...i)};return{on:e=>(t.add(e),()=>{t.delete(e)}),emitMount:e=>{i((e,t)=>{var i,r;null==(i=e.mount)||i.call(e,t),null==(r=e.mounted)||r.call(e,t)},e)},emitBeforeMount:e=>{i((e,t)=>{var i;null==(i=e.beforeMount)||i.call(e,t)},e)},emitUpdate:(e,t)=>{i((e,t,i)=>{var r;null==(r=e.update)||r.call(e,t,i)},e,t)},emitBeforeUpdate:(e,t)=>{i((e,t,i)=>{var r;null==(r=e.beforeUpdate)||r.call(e,t,i)},e,t)},emitUpdated:(e,t)=>{i((e,t,i)=>{var r;null==(r=e.updated)||r.call(e,t,i)},e,t)},emitBeforeUnmount:e=>{i((e,t)=>{var i;null==(i=e.beforeUnmount)||i.call(e,t)},e)},emitUnmount:e=>{i((e,t)=>{var i,r;null==(i=e.unmount)||i.call(e,t),null==(r=e.unmounted)||r.call(e,t)},e)},clear:()=>{t.clear()}}}const Rt=xt;function jt(e){return e.children}function Ot(e){return"root"!==e.type}function Tt(e){return"root"===e.type}function Ct(e){return"field"===(null==e?void 0:e.type)}function Pt(e){return"group"===(null==e?void 0:e.type)}function Et(e){return"dependency"===(null==e?void 0:e.type)}function Bt(e){return Tt(e)||Pt(e)?e.childNodes:Et(e)?e.dynamicChildNodes:[]}function Nt(e,t){Tt(e)||Pt(e)?e.childNodes=t:Et(e)&&(e.dynamicChildNodes=t)}function Mt(e,t){return function(e,t,i={}){const r=i.getChildren??jt,n=Array.isArray(e)?[...e]:[e];let s=0;for(;s<n.length;){const e=n[s];if(s++,t(e))return e;const i=r(e);(null==i?void 0:i.length)&&n.push(...i)}}(e,e=>Ct(e)&&e.descriptor.name===t,{getChildren:e=>Bt(e)})}class It{constructor(e){n(this,"runtimeNodeManager"),this.runtimeNodeManager=e}reconcileChildren(e,t){return this.reconcileChildrenTree(e,t)}reconcileChildrenTree(e,t){const i=new Map(Bt(e).map(e=>[e.key,e])),r=[],n=[];let s=!1;for(const o of t){const t=i.get(o.key);if(t&&t.type===o.type){i.delete(o.key),t.parent=e,this.runtimeNodeManager.update(t,o),r.push(t),yt(o)&&n.push({node:t,descriptor:o});continue}s=!0;const l=this.runtimeNodeManager.create(o,e);this.runtimeNodeManager.mount(l),r.push(l),yt(o)&&n.push({node:l,descriptor:o})}Nt(e,r);for(const{node:o,descriptor:l}of n)yt(l)&&this.reconcileChildrenTree(o,l.children)&&(s=!0);i.size>0&&(s=!0);for(const o of i.values())this.runtimeNodeManager.disposeTree(o);return s}}function $t(){let e=!1;const t=[],i=[];return{get disposed(){return e},add:i=>{if(e)return qt(i),Dt();const r={cleanup:i,disposed:!1};t.push(r);return{get disposed(){return r.disposed},dispose:()=>{r.disposed||(r.disposed=!0,_t(t,r),qt(r.cleanup))}}},child:()=>{const e=$t();return i.push(e),e.add(()=>{_t(i,e)}),e},dispose:()=>{if(!e){e=!0;for(const e of i.slice().reverse())e.dispose();i.length=0;for(const e of t.slice().reverse())e.disposed||(e.disposed=!0,qt(e.cleanup));t.length=0}}}}const Dt=()=>({disposed:!0,dispose:Ut}),Ut=()=>{},_t=(e,t)=>{const i=e.indexOf(t);i>=0&&e.splice(i,1)},qt=e=>{try{e()}catch(t){!function(e){console.error("[Scope] Cleanup error:",e)}(t)}};class zt{constructor(e){n(this,"nextId",1),n(this,"context"),n(this,"instance"),n(this,"fieldRegistry"),n(this,"lifecycleBus"),this.context=e,this.fieldRegistry=e.fieldRegistry,this.instance=e.instance,this.lifecycleBus=e.lifecycleBus}createRoot(){return{id:0,key:"schemx:root",type:"root",parent:null,scope:$t(),disposed:R(!1),mounted:R(!1),childNodes:[]}}create(e,t){return"field"===e.type?this.createField(e,t):"group"===e.type?this.createGroup(e,t):"dependency"===e.type?this.createDependency(e,t):void function(e){throw new Error(`unknown type: ${e.type??"unknown"}`)}(e)}mount(e){if(Ot(e)){switch(this.lifecycleBus.emitBeforeMount(e),e.type){case"field":this.mountField(e);break;case"group":this.mountGroup(e);break;case"dependency":this.mountDependency(e)}e.mounted.value=!0,this.lifecycleBus.emitMount(e)}}update(e,t){if(Ot(e))switch(e.type){case"field":{"field"!==t.type&&Lt(e,t);const i=Wt(e);this.lifecycleBus.emitBeforeUpdate(e,i),e.descriptor=t,this.updateField(e,i),this.lifecycleBus.emitUpdate(e,i),this.lifecycleBus.emitUpdated(e,i);break}case"group":{yt(t)||Lt(e,t);const i=Wt(e);this.lifecycleBus.emitBeforeUpdate(e,i),e.descriptor=t,this.updateGroup(e,t),this.lifecycleBus.emitUpdate(e,i),this.lifecycleBus.emitUpdated(e,i);break}case"dependency":{(e=>"dependency"===e.type)(t)||Lt(e,t);const i=Wt(e);this.lifecycleBus.emitBeforeUpdate(e,i),e.descriptor=t,this.updateDependency(e,i),this.lifecycleBus.emitUpdate(e,i),this.lifecycleBus.emitUpdated(e,i);break}}}unmount(e){if(Ot(e)){switch(e.type){case"field":this.unmountField(e);break;case"group":this.unmountGroup(e);break;case"dependency":this.unmountDependency(e)}e.mounted.value=!1}}disposeTree(e){if(!e.disposed.value){if("root"!==e.type&&this.lifecycleBus.emitBeforeUnmount(e),e.disposed.value=!0,function(e){return"root"===e.type||"group"===e.type||"dependency"===e.type}(e)){for(const t of Bt(e))this.disposeTree(t);Nt(e,[])}this.unmount(e),e.scope.dispose(),e.parent=null,"root"!==e.type&&this.lifecycleBus.emitUnmount(e)}}createField(e,t){const i=function(e){return{snapshot:R(mt(e))}}(e);return{id:this.nextId++,key:e.key,type:e.type,parent:t,scope:t.scope.child(),disposed:R(!1),mounted:R(!1),descriptor:e,fieldModel:i,fieldResourceScope:null,fieldDependenciesScope:null}}createGroup(e,t){return{id:this.nextId++,key:e.key,type:e.type,parent:t,scope:t.scope.child(),disposed:R(!1),mounted:R(!1),descriptor:e,childNodes:[]}}createDependency(e,t){return{id:this.nextId++,key:e.key,type:e.type,parent:t,scope:t.scope.child(),disposed:R(!1),mounted:R(!1),descriptor:e,dependencySlot:null,dependencyResourceScope:null,dynamicChildNodes:[]}}mountField(e){const t=e.scope.child(),i=e.fieldModel;i&&(this.initializeFieldValue(e),e.fieldResourceScope=t,this.fieldRegistry.register({name:e.descriptor.name,node:e,model:i}),t.add(()=>{this.fieldRegistry.unregister(e.descriptor.name,e),e.fieldResourceScope===t&&(e.fieldResourceScope=null)}),this.mountFieldValidation(e,i,t),this.mountOrRestartFieldDependencies(e,i))}initializeFieldValue(e){const{name:t,schema:i}=e.descriptor;if(!Object.hasOwn(i,"initialValue")||void 0!==this.instance.getFieldSnapshot(t))return;const r={};qe(r,t,i.initialValue),this.instance.setInitialValues(r),this.instance.setFieldValue(t,i.initialValue)}mountGroup(e){}mountDependency(e){Vt({node:e,descriptor:e.descriptor,context:this.context})}updateField(e,t){const i=e.fieldModel;if(i&&t&&t.descriptor.name===e.descriptor.name)return gt(i,e.descriptor),this.fieldRegistry.register({name:e.descriptor.name,node:e,model:i}),void this.mountOrRestartFieldDependencies(e,i);this.unmountField(e),this.mountField(e)}updateGroup(e,t){}updateDependency(e,t){e.dependencySlot&&t&&function(e,t){if(e.length!==t.length)return!1;return e.every((e,i)=>e===t[i])}(e.descriptor.trigger,null==t?void 0:t.descriptor.trigger)||(this.unmountDependency(e),this.mountDependency(e))}mountFieldValidation(e,t=e.fieldModel,i=e.fieldResourceScope){t&&i&&At({name:e.descriptor.name,fieldModel:t,context:this.context,scope:i})}mountOrRestartFieldDependencies(e,t=e.fieldModel){var i;if(null==(i=e.fieldDependenciesScope)||i.dispose(),!t||!e.descriptor.dependencies)return void(e.fieldDependenciesScope=null);const r=e.scope.child();e.fieldDependenciesScope=r,r.add(()=>{e.fieldDependenciesScope===r&&(e.fieldDependenciesScope=null)}),bt({descriptor:e.descriptor,fieldModel:t,context:this.context,scope:r})}unmountField(e){var t,i;null==(t=e.fieldDependenciesScope)||t.dispose(),e.fieldDependenciesScope=null,null==(i=e.fieldResourceScope)||i.dispose(),e.fieldResourceScope=null}unmountGroup(e){}unmountDependency(e){var t;null==(t=e.dependencyResourceScope)||t.dispose(),e.dependencyResourceScope=null,e.dependencySlot=null}}function Wt(e){return{...e}}function Lt(e,t){throw new Error(`unexpected descriptor type: node ${e.type} cannot update with ${t.type}`)}const Gt=["sync","pre","normal","post"];const Kt=e=>null!==e&&"object"==typeof e&&"then"in e&&"function"==typeof e.then;class Zt{constructor(e={}){n(this,"fieldSignals",function(e={}){return new fe(e)}()),n(this,"initialValues");const t=e.initialValues??{};this.initialValues=ne(t);const i=ze(t);for(const r of i){const e=_e(t,r);this.fieldSignals.set(r,he({value:e,initialValue:e}))}}getOrCreateFieldSignal(e){const t=_e(this.initialValues,e);let i=this.fieldSignals.peek(e);return i||(i=he({value:t,initialValue:t}),this.fieldSignals.set(e,i)),i}getFieldValue(e){const t=this.fieldSignals.get(e);return null==t?void 0:t.value.value}setFieldValue(e,t){const i=this.getOrCreateFieldSignal(e);i.setValue(t),i.setTouched(!de(t,i.initialValue.peek()))}getFieldsValue(e){const t={},i=e??this.fieldSignals.keys();for(const r of i)qe(t,r,this.getFieldValue(r));return t}setFieldsValue(e){const t=ze(e);ge(()=>{for(const i of t)this.setFieldValue(i,_e(e,i))})}getFieldSnapshot(e){const t=this.fieldSignals.peek(e);return null==t?void 0:t.value.peek()}getFieldsSnapshot(e){const t={},i=e??this.fieldSignals.keys();for(const r of i)qe(t,r,this.getFieldSnapshot(r));return t}getInitialValue(e){const t=this.fieldSignals.peek(e);return t?t.initialValue.peek():_e(this.initialValues,e)}getInitialValues(e){if(void 0===e)return ne(this.initialValues);const t={};for(const i of e)qe(t,i,_e(this.initialValues,i));return t}setInitialValue(e,t){qe(this.initialValues,e,t);const i=this.getOrCreateFieldSignal(e);i.setInitialValue(t),i.setTouched(!de(i.value.peek(),i.initialValue.peek()))}setInitialValues(e){const t=ze(e);t.length&&ge(()=>{for(const i of t){const t=_e(e,i);qe(this.initialValues,i,t);const r=this.getOrCreateFieldSignal(i);r.setInitialValue(t),r.setTouched(!de(r.value.peek(),r.initialValue.peek()))}})}isFieldTouched(e){var t;return(null==(t=this.fieldSignals.get(e))?void 0:t.touched.value)??!1}isFieldsTouched(e){const t=e??[...this.fieldSignals.keys()];return void 0===e?t.some(e=>this.isFieldTouched(e)):t.every(e=>this.isFieldTouched(e))}getTouchedFields(){const e=[];for(const[t,i]of this.fieldSignals.entries())i.touched.value&&e.push(t);return e}setFieldTouched(e,t){this.getOrCreateFieldSignal(e).setTouched(t)}setFieldsTouched(e,t=!0){ge(()=>{for(const i of e)this.setFieldTouched(i,t)})}isFieldPending(e){var t;return(null==(t=this.fieldSignals.get(e))?void 0:t.pending.value)??!1}isFieldsPending(e){return(e??[...this.fieldSignals.keys()]).every(e=>this.isFieldPending(e))}getPendingFields(){const e=[];for(const[t,i]of this.fieldSignals.entries())i.pending.value&&e.push({field:t,message:i.pendingMessage.peek()});return e}setFieldPending(e,t,i){this.getOrCreateFieldSignal(e).setPending(t,i)}setFieldsPending(e,t=!0,i){ge(()=>{for(const r of e)this.setFieldPending(r,t,i)})}resetField(e){this.getOrCreateFieldSignal(e).reset()}resetFields(e){ge(()=>{for(const t of e)this.getOrCreateFieldSignal(t).reset()})}reset(e){const t=ne(e??this.initialValues),i=ze(t),r=new Set(i);ge(()=>{for(const e of this.fieldSignals.keys())r.has(e)||this.fieldSignals.delete(e);for(const e of i){const i=_e(t,e);qe(this.initialValues,e,i);const r=this.fieldSignals.peek(e);r?(r.setInitialValue(i),r.reset(i)):this.fieldSignals.set(e,he({value:i,initialValue:i}))}})}destroy(){this.fieldSignals.clear()}}function Ht(e){return e?Xt(Bt(e),1):[]}function Xt(e,t){if(t>100)throw new RangeError(`buildViewSchemas: max depth 100 exceeded at depth ${t}`);const i=[];for(const r of e){const e=Jt(r,t);if(null!==e)if(Array.isArray(e))for(const t of e)i.push(t);else i.push(e)}return i}function Jt(e,t){return e.disposed.value?null:Pt(e)?function(e,t){const i=Xt(Bt(e),t+1),r=e.descriptor;return{...r.schema,key:e.key,children:i,debug:ti(e)}}(e,t):Et(e)?function(e,t){return Xt(Bt(e),t+1)}(e,t):Ct(e)?function(e){const t=e.descriptor,i=e.fieldModel;if(!i)return console.warn(`[buildViewSchemas] skipping field node "${e.key}": no FieldModel resource`),null;if("field"!==(null==t?void 0:t.type))return null;const r=t.schema,n=i.snapshot.value;return{...r,key:e.key,visible:n.visible,label:n.label,readonly:n.readonly,disabled:n.disabled,required:n.required,placeholder:Qt(n.placeholder),componentProps:Yt(n.componentProps??{}),rules:n.rules,validationTrigger:r.validationTrigger,debug:ti(e)}}(e):null}function Qt(e){return e.length>1e3?e.slice(0,1e3):e}function Yt(e,t=0){if(t>10)return{};const i={};for(const r of Object.keys(e)){if(!ei(r))continue;const n=e[r];null===n||"object"!=typeof n||Array.isArray(n)?i[r]=n:i[r]=Yt(n,t+1)}return i}function ei(e){return!!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(e)||!!/^[a-zA-Z0-9_-]+$/.test(e)}function ti(e){return{runtimeNodeId:e.id,runtimeNodeType:e.type,hasFieldModel:"field"===e.type&&void 0!==e.fieldModel,hasDependencySlot:"dependency"===e.type&&void 0!==e.dependencySlot}}function ii(e,t,i){let r=!1;const n=e.scope.add(()=>{r=!0}),s=function(e,t,i=16,r={}){const n=O(t,i,{edges:r.edges});let s=!1;const o=ye(()=>{const i=e();if(!s&&r.immediate)return s=!0,void t(i);s=!0,n(i)});return()=>{o(),n.cancel()}}(()=>(t.revision.value,r?[]:Ht(e)),e=>{try{i(e)}catch(t){console.error("[subscribeViewSchemas] onChange error:",t)}},16,{immediate:!0,edges:["leading","trailing"]});return()=>{s(),n.dispose(),r=!1}}class ri{constructor(e={}){var t,i;n(this,"context"),n(this,"callbacks"),n(this,"store"),n(this,"rendererRegistry"),n(this,"validatorRegistry"),n(this,"validator"),n(this,"root"),n(this,"scheduler"),n(this,"viewRevision"),n(this,"reconciler"),n(this,"runtimeNodeManager"),n(this,"fieldRegistry"),n(this,"scope",$t()),n(this,"schemas"),n(this,"disposed",!1),n(this,"lifecycleBus"),n(this,"getFormInstance",()=>({setFieldValue:this.store.setFieldValue.bind(this.store),setFieldsValue:this.store.setFieldsValue.bind(this.store),getFieldValue:this.store.getFieldValue.bind(this.store),getFieldsValue:this.store.getFieldsValue.bind(this.store),getFieldSnapshot:this.store.getFieldSnapshot.bind(this.store),getFieldsSnapshot:this.store.getFieldsSnapshot.bind(this.store),getInitialValue:this.store.getInitialValue.bind(this.store),getInitialValues:this.store.getInitialValues.bind(this.store),setInitialValues:this.store.setInitialValues.bind(this.store),isFieldTouched:this.store.isFieldTouched.bind(this.store),setFieldTouched:this.store.setFieldTouched.bind(this.store),getTouchedFields:this.store.getTouchedFields.bind(this.store),setFieldPending:this.store.setFieldPending.bind(this.store),isFieldPending:this.store.isFieldPending.bind(this.store),getPendingFields:this.store.getPendingFields.bind(this.store),validateField:this.validateField.bind(this),validate:this.validate.bind(this),getFieldError:this.validator.getFieldError.bind(this.validator),setFieldError:this.validator.setFieldError.bind(this.validator),resetFields:this.store.resetFields.bind(this.store),reset:this.reset.bind(this),submit:this.submit.bind(this),registerRules:this.register.bind(this),unregisterRules:this.validator.unregister.bind(this.validator),effect:this.effect.bind(this),batch:this.batch.bind(this),setSchemas:this.setSchemas.bind(this),updateSchemas:this.updateSchemas.bind(this),updateDefaultProps:this.updateDefaultProps.bind(this),getViewRevision:()=>this.viewRevision.revision.value,getViewSchemas:this.getViewSchemas.bind(this),subscribeViewSchemas:this.subscribeViewSchemas.bind(this),waitForDependencies:this.waitForIdle.bind(this),getRenderer:this.rendererRegistry.getRenderer.bind(this.rendererRegistry),registerRenderer:this.rendererRegistry.register.bind(this.rendererRegistry),hasRenderer:this.rendererRegistry.hasRenderer.bind(this.rendererRegistry),getValidator:this.validatorRegistry.get.bind(this.validatorRegistry),registerValidator:this.validatorRegistry.register.bind(this.validatorRegistry),hasValidator:this.validatorRegistry.has.bind(this.validatorRegistry),destroy:this.destroy.bind(this)})),n(this,"getFormApi",()=>({setValue:this.store.setFieldValue.bind(this.store),setValues:this.store.setFieldsValue.bind(this.store),getValue:this.store.getFieldValue.bind(this.store),getValues:this.store.getFieldsValue.bind(this.store),getSnapshots:this.store.getFieldsSnapshot.bind(this.store),setPending:this.store.setFieldPending.bind(this.store),isPending:this.store.isFieldPending.bind(this.store),setTouched:this.store.setFieldTouched.bind(this.store),isTouched:this.store.isFieldTouched.bind(this.store),getError:this.validator.getFieldError.bind(this.validator),setError:this.validator.setFieldError.bind(this.validator),resetFields:this.store.resetFields.bind(this.store),reset:this.reset.bind(this),validateField:this.validateField.bind(this),validate:this.validate.bind(this)})),n(this,"validate",Le(async()=>{const e=this.store.getPendingFields();if(e.length>0){const t=`存在正在操作中的字段: ${e.map(e=>e.field).join(", ")},请等待完成后再提交`;return console.warn(`[schemx] ${t}`),{ok:!1,error:{errors:e.map(({field:e,message:t})=>{const i=t.length?t:["字段正在处理中,请稍后重试"];return this.validator.setFieldError(e,i),{field:e,message:i}}),values:this.store.getFieldsSnapshot()}}}return await this.validator.validate(this.store.getFieldsValue())})),n(this,"submit",Le(async()=>{var e,t,i,r;if(!(await this.waitForIdle()))return;const n=await this.validate();n.ok?await(null==(t=(e=this.callbacks).onFinish)?void 0:t.call(e,n.values)):null==(r=(i=this.callbacks).onFinishFailed)||r.call(i,n.error)})),n(this,"commitChildren",(e,t)=>{this.reconciler.reconcileChildren(e,t)&&this.viewRevision.bump()});const{schemas:r,initialValues:s={},modelValue:o,rendererRegistry:l,defaultRendererType:a,validatorRegistry:u,...c}=e;var d,h;this.callbacks={onValuesChange:e.onValuesChange,onFinish:e.onFinish,onFinishFailed:e.onFinishFailed,onFieldsChange:e.onFieldsChange},this.rendererRegistry=l??nt(a),this.validatorRegistry=u??ot(),this.validator=Xe(),this.store=function(e={}){return new Zt(e)}({initialValues:{...s,...o??{}}}),this.validatorRegistry.registerAll({required:Je,selectRequired:Qe,uploadRequired:Ye}),this.lifecycleBus=xt(),this.scheduler=function(){const e=new Map(Gt.map(e=>[e,new Map])),t=new Set;let i=0,r=!1,n=null;const s=async()=>{if(!r)return n||(n=o().finally(()=>{n=null,d()}),n)},o=async()=>{var e,t;const i=l();for(const s of i)if(!r&&!(null==(e=s.scope)?void 0:e.disposed))try{const e=s.run();Kt(e)&&await a(e)}catch(n){null==(t=s.onError)||t.call(s,n)}},l=()=>{const t=[];for(const i of Gt){const r=e.get(i);r&&(t.push(...r.values()),r.clear())}return t},a=async e=>{i+=1;try{return await e}finally{i-=1,d()}},u=()=>!n&&0===i&&!c(),c=()=>Array.from(e.values()).some(e=>e.size>0),d=()=>{if(!u())return;const e=Array.from(t);t.clear(),e.forEach(e=>e(!0))};return{schedule:t=>{var i,n;r||(null==(i=t.scope)?void 0:i.disposed)||(null==(n=e.get(t.priority))||n.set(t.id,t),queueMicrotask(()=>{s()}))},flush:s,whenIdle:(e=1e4)=>u()?Promise.resolve(!0):new Promise(i=>{const r=globalThis.setTimeout(()=>{t.delete(i),i(!1)},e);t.add(e=>{globalThis.clearTimeout(r),i(e)})}),track:a,dispose:()=>{r=!0,e.forEach(e=>e.clear()),d()}}}(),this.viewRevision=function(){const e=R(0);return{revision:e,bump:()=>{e.value+=1}}}(),this.fieldRegistry=new kt,this.context={defaultProps:le(c,Ze),instance:this.getFormInstance(),formApi:this.getFormApi(),scheduler:this.scheduler,lifecycleBus:this.lifecycleBus,fieldRegistry:this.fieldRegistry,commitChildren:this.commitChildren},this.runtimeNodeManager=(d=this.context,new zt(d)),this.reconciler=(h=this.runtimeNodeManager,new It(h)),this.root=this.runtimeNodeManager.createRoot(),e.lifecycleHooks&&this.lifecycleBus.on(e.lifecycleHooks),this.schemas=at(r)?r:lt(r??[]),this.applySchemas(this.schemas.peek());const f=this.schemas.subscribe(e=>{this.applySchemas(e)});if(this.scope.add(f),(null==(t=this.callbacks)?void 0:t.onValuesChange)||(null==(i=this.callbacks)?void 0:i.onFieldsChange)){let e=this.store.getFieldsSnapshot();const t=ye(()=>{var t,i,r,n;const s=this.store.getFieldsValue(),o=this.store.getFieldsSnapshot(),l=Ge(o,e),a=ze(l);a.length>0&&(null==(i=(t=this.callbacks).onValuesChange)||i.call(t,l,o),null==(n=(r=this.callbacks).onFieldsChange)||n.call(r,a,ze(s))),e=o});this.scope.add(t)}}register(e,t,i){const r=[],n=Mt(this.root,e),s=null==n?void 0:n.descriptor.schema;this.validator.unregister(e);const o={...s,rules:t};r.push(...this.validatorRegistry.resolveValidatorsBySchema(o)),r.length>0&&this.validator.register(e,r,i)}async validateField(e){return await this.validator.validateField(e,this.store.getFieldsValue())}reset(){this.store.reset(),this.validator.reset()}effect(e){const t=ye(e),i=this.scope.add(t);return()=>{i.dispose()}}batch(e){ge(e)}setSchemas(e){this.disposed||this.schemas.set(e)}updateSchemas(e){this.disposed||this.schemas.update(e)}updateDefaultProps(e){this.disposed||(Object.assign(this.context.defaultProps,le(e,Ze)),this.applySchemas(this.schemas.peek()))}applySchemas(e){if(this.disposed)return;const t=this.viewRevision.revision.value,i=dt([...e],this.context.defaultProps);this.commitChildren(this.root,i),this.viewRevision.revision.value===t&&this.viewRevision.bump()}destroy(){this.disposed||(this.disposed=!0,this.scope.dispose(),this.runtimeNodeManager.disposeTree(this.root),this.scheduler.dispose(),this.store.destroy())}getViewSchemas(){return Ht(this.root)}subscribeViewSchemas(e){return ii(this.root,this.viewRevision,e)}waitForIdle(e=1e4){return this.scheduler.whenIdle(e)}}function ni(e={}){return new ri(e).getFormInstance()}function si(e,t){return{getValue:()=>e.getFieldValue(t),setValue:i=>{e.setFieldValue(t,i)},getInitialValue:()=>e.getInitialValue(t),setInitialValue:i=>{const r={};qe(r,t,i),e.setInitialValues(r)},getValues:()=>e.getFieldsValue(),getSnapshot:()=>e.getFieldsSnapshot(),validate:()=>e.validateField(t),getError:()=>e.getFieldError(t),setError:i=>{e.setFieldError(t,i)},clearError:()=>{e.setFieldError(t,[])},registerRules:(i,r)=>{e.registerRules(t,i,r)},unregisterRules:()=>{e.unregisterRules(t)},isTouched:()=>e.isFieldTouched(t)??!1,reset:()=>{e.resetFields([t])},setPending:(i,r)=>{e.setFieldPending(t,i,r)},isPending:()=>e.isFieldPending(t)??!1,effect:t=>e.effect(t)}}function oi(e){let t,i=!1;const r=ye(()=>{null==t||t(),t=void 0;const i=e();"function"==typeof i&&(t=i)});return()=>{i||(i=!0,r(),null==t||t(),t=void 0)}}const li=(e,t,i,r)=>{let n=e.getFieldSnapshot(t),s=!0;return e.effect(()=>{const o=e.getFieldValue(t),l=e.getFieldsSnapshot();if(s)return s=!1,r.immediate&&i({value:o,prevValue:void 0},l),void(n=o);r.inequality&&de(o,n)||(i({value:o,prevValue:n},l),n=o)})},ai=(e,t,i,r)=>{let n=e.getFieldsSnapshot(t),s=!0;return e.effect(()=>{const o=e.getFieldsValue(t),l=e.getFieldsSnapshot();if(s)return s=!1,r.immediate&&i({changedPaths:t,changedValues:o,prevValues:{}},l),void(n={...o});if(r.inequality&&de(o,n))return;const a=Ge(o,n),u=ze(a);i({changedPaths:u,changedValues:a,prevValues:n},l),n={...o}})},ui=(e,t,i)=>{let r=!0,n=e.getFieldsSnapshot();return e.effect(()=>{const s=e.getFieldsSnapshot();if(r)return r=!1,i.immediate&&t({changedPaths:[],changedValues:s,prevValues:{}},s),void(n={...s});if(i.inequality&&de(s,n))return;const o=Ge(s,n),l=ze(o);t({changedPaths:l,changedValues:o,prevValues:n},s),n={...s}})};function ci(e,t,i,r){return"function"==typeof t?ui(e,t,i||{}):"string"==typeof t||"number"==typeof t?li(e,t,i,r||{}):ai(e,t,i,r||{})}const di=nt("input"),hi=ot(),fi=Symbol("SCHEMX_INSTANCE");function pi(t){const{...i}=t,r={...i,rendererRegistry:i.rendererRegistry??di,validatorRegistry:i.validatorRegistry??hi},n=e.computed(()=>ni(r));return e.provide(fi,n.value),e.onUnmounted(()=>{n.value.destroy()}),n.value}function vi(){const t=e.inject(fi);if(!t)throw new Error("useFormInstance must be used within a Form");return t}const yi=new WeakMap;const gi=t=>{const i=vi(),r=t;let n=yi.get(i);n||(n=new Map,yi.set(i,n));const s=n.get(r);let o;if(s)s.refCount++,o=s;else{const{result:s,dispose:l}=function(t,i){const r=si(t,i),n=e.shallowRef(r.getValue()),s=e.shallowRef(r.getError()),o=e.shallowRef(r.isPending()),l=r.effect(()=>{n.value=r.getValue(),s.value=r.getError(),o.value=r.isPending()}),a=e.computed(()=>s.value),u=e.computed(()=>(n.value,r.isTouched())),c=e.computed(()=>o.value);return{result:{value:n,error:a,dirty:u,pending:c,...r,getValue:()=>n.value},dispose:l}}(i,t);o={refCount:1,result:s,dispose:l},n.set(r,o)}return e.onUnmounted(()=>{--o.refCount<=0&&(o.dispose(),n.delete(r))}),o.result};function mi(t,i,r){const n=ci(vi(),t,i,r);return e.onUnmounted(n),n}function bi(e,t,i){return mi(e,t,i)}function Fi(e){return e instanceof Error?e:new Error(String(e))}const wi=(t,i)=>{var r;const n=vi(),s=e.ref([]),o=e.ref(!1),l=e.ref(void 0);let a=0;const u=async()=>{try{const e=n.getFieldsValue();if("function"==typeof t.shouldFetch&&!t.shouldFetch(e))return s.value=[],void(o.value=!1);o.value=!0,l.value=void 0;const i=++a,r=await(async e=>{const i=t.retryCount??0,r=t.retryInterval??1e3;let s=new Error("Unknown error");for(let l=0;l<=i;l++)try{return await t.api(e,n)}catch(o){s=Fi(o),l<i&&await new Promise(e=>setTimeout(e,r))}throw s})(e);if(i!==a)return;const u=await(async e=>"function"==typeof(null==t?void 0:t.formatter)?await t.formatter(e,n):e)(r);if(i!==a)return;s.value=u,l.value=void 0,"function"==typeof t.onSuccess&&t.onSuccess(u,n),o.value=!1}catch(e){const i=Fi(e);l.value=i,s.value=[],o.value=!1,"function"==typeof t.onError&&t.onError(i,n)}};(null==(r=t.dependsOn)?void 0:r.length)&&bi(t.dependsOn,(e,r)=>{"function"==typeof t.onDepsChange&&t.onDepsChange(r,n),t.resetOnDepsChange&&i&&n.setFieldValue(i,void 0),u()});const c=t.immediate??!0;return e.onMounted(()=>{c&&u()}),{list:s,loading:o,error:l,loadDict:u,refresh:()=>u(),mutate:e=>{s.value=e}}},Si=Symbol("FormContext");function Vi(){const t=e.inject(Si);if(!t)throw new Error("useContext must be used within a Form");return t}function ki(t){const i=e.shallowRef({});return e.watchEffect(()=>{const e=t();((e,t)=>{const i=Object.keys(e),r=Object.keys(t);return i.length===r.length&&i.every(i=>e[i]===t[i])})(i.value,e)||(i.value=e)}),i}const Ai=Symbol("schemx:field");function xi(e){return void 0!==e&&(!Array.isArray(e)||0!==e.length)}function Ri(e,t){if(!t)return!1;return(Array.isArray(t)?t:[t]).some(t=>function(e){return{onBlur:"blur",onChange:"change",onSubmit:"submit",blur:"blur",change:"change",submit:"submit"}[e]??"submit"}(t)===e)}const ji=e=>/[A-Z]/.test(e),Oi=e=>e.includes("-"),Ti=e=>e.replace(/([A-Z])/g,"-$1").toLowerCase(),Ci=e=>e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase()),Pi=(e,t)=>{if(e[t])return e[t];const i=ji(t)?Ti(t):Oi(t)?Ci(t):void 0;return i&&e[i]?e[i]:void 0},Ei=(e,t)=>{const i={},r=(n=String(e),(Oi(n)?Ci(n):n)+":");var n;const s=(e=>ji(e)?Ti(e):e)(String(e))+":";for(const[o,l]of Object.entries(t))o.startsWith(r)?i[o.slice(r.length)]=l:o.startsWith(s)&&s!==r&&(i[o.slice(s.length)]=l);return i},Bi=e.defineComponent((i,{slots:r})=>{const n=e.ref(Boolean(i.schema.defaultCollapsed)),s=()=>{i.schema.collapsible&&(n.value=!n.value)};return()=>{const o=i.schema,l=Boolean(o.collapsible);return e.createVNode("div",{class:t("schemx-group",{"schemx-group--collapsed":n.value},o.class),"data-key":o.key},[o.label&&e.createVNode("div",{role:l?"button":void 0,tabindex:l?0:void 0,class:t("schemx-group__header",{"schemx-group__header--clickable":l}),onClick:s,onKeydown:e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),s())}},[e.createVNode("span",{class:"schemx-group__title"},[o.label]),l&&e.createVNode("span",{class:t("schemx-group__arrow",{"schemx-group__arrow--down":!n.value})},null)]),!n.value&&e.createVNode("div",{class:"schemx-group__body"},[o.children.map(t=>e.createVNode(Ni,{key:t.key,schema:t},r))])])}},{name:"SchemxGroup",props:{schema:{type:Object,required:!0}}}),Ni=e.defineComponent((r,{slots:n})=>{const s=e.toRef(r,"schema");if(Mi(s.value))return()=>e.h(Bi,{schema:s.value},n);const o=vi(),l=Vi(),a=()=>s.value,u=gi(a().name);!function(t){e.provide(Ai,t)}(u);const c=e.computed(()=>{return e=a().validationTrigger,t=l.validationTrigger,i="onChange",xi(e)?e:xi(t)?t:i;var e,t,i}),d=e.computed(()=>{const e=a().visible&&!a().readonly&&!a().disabled,t=a().rules,i=Array.isArray(t)?(null==t?void 0:t.length)>0:!!a().rules;return e&&i}),h=e=>{var t,i;u.setValue(e),null==(i=null==(t=a().componentProps)?void 0:t.onChange)||i.call(t,e),d.value&&Ri("change",c.value)&&u.validate()},f=()=>{d.value&&Ri("blur",c.value)&&u.validate()},p=e.computed(()=>({...i.omit(a(),["componentProps"]),name:a().name,componentType:a().componentType,class:t("schemx-item",a().class),required:a().required,readonly:a().readonly,disabled:a().disabled,visible:a().visible,placeholder:a().placeholder,validationTrigger:c.value})),v=ki(()=>({...a().componentProps,formItemProps:p.value,value:u.getValue(),readonly:a().readonly,disabled:a().disabled,placeholder:a().placeholder,onChange:h,onBlur:f,"onUpdate:value":e=>u.setValue(e)})),y=()=>{const t=Pi(n,`${a().name}Label`);if(t)return t(p.value);const i=a().labelAlign||l.labelAlign,r=a().labelWidth||l.labelWidth,s=a().colon??l.colon;return e.createVNode("label",{class:"schemx-item__label",style:{width:r,textAlign:i}},[!a().required||a().disabled||a().readonly?null:e.createVNode("span",{class:"schemx-item__required"},[e.createTextVNode("*")]),e.createVNode("span",{class:"schemx-item__label-text"},[a().label,s?":":""])])},g=()=>{const t=o.getRenderer(a().componentType);if(!t)throw new Error(`[schemx] Can not find component renderer of "${a().componentType}".`);const i=Ei(Ii(a().name),n),r=e.h(t,v.value,i),s=Pi(n,`${a().name}Content`);return s?s({...p.value,columnElement:r}):e.createVNode("div",{class:"schemx-item__control"},[r])},m=()=>{const t=Pi(n,`${a().name}Error`);return t?t({...p.value,errors:u.error.value}):Array.isArray(u.error.value)&&0!==u.error.value.length?e.createVNode("div",{class:"schemx-item__error"},[u.error.value[0]]):null};return()=>{if(!a().visible)return null;const i=Pi(n,Ii(a().name));if(i)return i(p.value);const r=a().labelPosition||l.labelPosition;return e.createVNode("div",{class:t("schemx-item-wrapper")},[e.createVNode("div",{class:t("schemx-item",`schemx-item--label-${r}`,a().class,{"is-readonly":a().readonly,"is-disabled":a().disabled}),style:{...a().style??{}}},[y(),e.createVNode("div",{class:"schemx-item__content"},[g(),m()])])])}},{name:"SchemxItem",props:{schema:{type:Object,required:!0}}}),Mi=e=>"group"===e.componentType,Ii=e=>Array.isArray(e)?e.map(e=>String(e)).join("."):String(e);function $i(e){return!(!e||"group"===e.componentType||"visible"in e&&!1===e.visible)}function Di(e,t,i){for(let r=t+i;r>=0&&r<e.length;r+=i)if($i(e[r]))return e[r]}const Ui=e.defineComponent({name:"SchemxForm",__name:"form",props:{class:{default:""},style:{default:()=>({})},required:{type:Boolean},readonly:{type:Boolean},disabled:{type:Boolean},visible:{type:Boolean},labelIcon:{},labelAlign:{},labelPosition:{},labelWidth:{},contentAlign:{},validationTrigger:{},colon:{type:Boolean},modelValue:{default:()=>({})},initialValues:{default:()=>({})},schemas:{default:()=>[]},form:{default:void 0},rendererRegistry:{default:void 0},defaultRendererType:{},validatorRegistry:{default:void 0},onFinish:{type:Function,default:void 0},onFinishFailed:{type:Function,default:void 0},onValuesChange:{type:Function,default:void 0},onFieldsChange:{type:Function,default:void 0}},emits:["update:modelValue"],setup(t,{expose:r,emit:n}){const s=t,o=n;(t=>{e.provide(Si,t)})(i.omit(s,["form","modelValue","rendererRegistry","defaultRendererType","validatorRegistry","onFinish","onFinishFailed","onValuesChange","onFieldsChange"]));const l=s.form?s.form:pi({schemas:s.schemas,initialValues:s.initialValues,rendererRegistry:s.rendererRegistry,defaultRendererType:s.defaultRendererType,validatorRegistry:s.validatorRegistry,readonly:s.readonly,disabled:s.disabled,onFinish:async e=>{var t;null==(t=s.onFinish)||t.call(s,e)},onFinishFailed:async e=>{var t;null==(t=s.onFinishFailed)||t.call(s,e)},onValuesChange:(e,t)=>{var i;o("update:modelValue",t),null==(i=s.onValuesChange)||i.call(s,e,t)},onFieldsChange:(e,t)=>{var i;null==(i=s.onFieldsChange)||i.call(s,e,t)}});e.watch(()=>s.schemas,e=>{l.setSchemas(e)},{deep:!1,immediate:!!s.form});const a=function(t){const i=e.shallowRef(t.getViewSchemas()),r=t.subscribeViewSchemas(e=>{i.value=e});return e.onScopeDispose(r),i}(l),u=e=>{const{isFirst:t,isLast:i}=function(e,t){const i=e.findIndex(e=>e.key===t);return-1===i?{found:!1,isFirst:!1,isLast:!1}:$i(e[i])?{found:!0,isFirst:!Di(e,i,-1),isLast:!Di(e,i,1)}:{found:!0,isFirst:!1,isLast:!1}}(a.value,e.key);return{"schemx-item-wrapper--first":t,"schemx-item-wrapper--last":i}};return e.watchEffect(()=>{l.updateDefaultProps(s)}),r({...l}),(t,i)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["schemx",s.class])},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(a),i=>(e.openBlock(),e.createBlock(e.unref(Ni),{key:i.key,schema:i,class:e.normalizeClass(u(i))},e.createSlots({_:2},[e.renderList(t.$slots,(i,r)=>({name:r,fn:e.withCtx(i=>[e.renderSlot(t.$slots,r,e.mergeProps({ref_for:!0},i??{}))])}))]),1032,["schema","class"]))),128))],2))}});const _i=(qi=Ui,zi={install(e,t){e.component("SchemxForm",Ui)},FormItem:Ni},Object.assign(qi,zi));var qi,zi;exports.FormGroup=Bi,exports.FormItem=Ni,exports.WithRemoteOptions=function(t){return e.defineComponent({name:`WithRemoteOptions(${t.name||"Anonymous"})`,inheritAttrs:!1,props:{dict:{type:Object,default:void 0},fieldName:{type:[String,Array],default:void 0}},setup(i,{attrs:r,slots:n}){const s=i.dict?wi(i.dict,i.fieldName):null,o=e.computed(()=>({...r,dict:i.dict,options:i.dict?null==s?void 0:s.list.value:r.options,loading:i.dict?null==s?void 0:s.loading.value:r.loading}));return()=>e.h(t,o.value,n)}})},exports.collectObjectPathsByLeaf=ze,exports.createEffect=oi,exports.createField=si,exports.createForm=ni,exports.createFormInstance=ni,exports.createLifecycle=Rt,exports.createLifecycleBus=xt,exports.createRendererRegistry=nt,exports.createSchemas=lt,exports.createValidator=Xe,exports.createValidatorsRegistry=ot,exports.createWatch=ci,exports.createWatchAll=ui,exports.createWatchField=li,exports.createWatchFields=ai,exports.default=_i,exports.getByPath=_e,exports.isBaseResolvedSchema=function(e){return!Se(e)&&!function(e){return"dependency"===e.componentType}(e)},exports.isBaseSchema=be,exports.isDependencySchema=we,exports.isGroupResolvedSchema=Se,exports.isGroupSchema=Fe,exports.isSchemxSchemas=at,exports.rendererRegistry=di,exports.schemxForm=_i,exports.setByPath=qe,exports.useContext=Vi,exports.useDictionary=wi,exports.useEffect=function(t){const i=oi(t);return e.onUnmounted(i),i},exports.useField=gi,exports.useFieldContext=function(){const t=e.inject(Ai);if(!t)throw new Error("[schemx] useFieldContext() must be used inside a FormItem tree");return t},exports.useForm=pi,exports.useWatch=mi,exports.useWatchAll=function(e,t){return mi(e,t)},exports.useWatchField=function(e,t,i){return mi(e,t,i)},exports.useWatchFields=bi,exports.validatorRegistry=hi;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),t=require("classnames"),r=require("@schemx/core"),n=require("es-toolkit"),o=r.createRendererRegistry("input"),s=r.createValidatorsRegistry(),a=Symbol("SCHEMX_INSTANCE");function l(t={}){const{...n}=t,l={...n,rendererRegistry:n.rendererRegistry??o,validatorRegistry:n.validatorRegistry??s},i=e.computed(()=>r.createForm(l));return e.provide(a,i.value),e.onUnmounted(()=>{i.value.destroy()}),i.value}function i(){const t=e.inject(a);if(!t)throw new Error("useFormContext must be used within a Form");return t}const u=Symbol("schemx:field"),c=new WeakMap;const d=t=>{const n=i(),o=t;let s=c.get(n);s||(s=new Map,c.set(n,s));const a=s.get(o);let l;if(a)a.refCount++,l=a;else{const{result:a,dispose:i}=function(t,n){const o=r.createField(t,n),s=e.shallowRef(o.getValue()),a=e.shallowRef(o.getError()),l=e.shallowRef(o.isPending()),i=o.effect(()=>{s.value=o.getValue(),a.value=o.getError(),l.value=o.isPending()}),u=e.computed(()=>a.value),c=e.computed(()=>(s.value,o.isTouched())),d=e.computed(()=>l.value);return{result:{value:s,error:u,dirty:c,pending:d,...o,getValue:()=>s.value},dispose:i}}(n,t);l={refCount:1,result:a,dispose:i},s.set(o,l)}return e.onUnmounted(()=>{--l.refCount<=0&&(l.dispose(),s.delete(o))}),l.result};function m(t,n,o){const s=i(),a=r.createWatch(s,t,n,o);return e.onUnmounted(a),a}function p(e,t,r){return m(e,t,r)}function f(e){return e instanceof Error?e:new Error(String(e))}const h=(t,r)=>{var n;const o=i(),s=e.ref([]),a=e.ref(!1),l=e.ref(void 0);let u=0;const c=async()=>{try{const e=o.getFieldsValue();if("function"==typeof t.shouldFetch&&!t.shouldFetch(e))return s.value=[],void(a.value=!1);a.value=!0,l.value=void 0;const r=++u,n=await(async e=>{const r=t.retryCount??0,n=t.retryInterval??1e3;let s=new Error("Unknown error");for(let l=0;l<=r;l++)try{return await t.api(e,o)}catch(a){s=f(a),l<r&&await new Promise(e=>setTimeout(e,n))}throw s})(e);if(r!==u)return;const i=await(async e=>"function"==typeof(null==t?void 0:t.formatter)?await t.formatter(e,o):e)(n);if(r!==u)return;s.value=i,l.value=void 0,"function"==typeof t.onSuccess&&t.onSuccess(i,o),a.value=!1}catch(e){const r=f(e);l.value=r,s.value=[],a.value=!1,"function"==typeof t.onError&&t.onError(r,o)}};(null==(n=t.dependsOn)?void 0:n.length)&&p(t.dependsOn,(e,n)=>{"function"==typeof t.onDepsChange&&t.onDepsChange(n,o),t.resetOnDepsChange&&r&&o.setFieldValue(r,void 0),c()});const d=t.immediate??!0;return e.onMounted(()=>{d&&c()}),{list:s,loading:a,error:l,loadDict:c,refresh:()=>c(),mutate:e=>{s.value=e}}},v=Symbol("FormContext");function y(){const t=e.inject(v);if(!t)throw new Error("useConfigContext must be used within a Form");return t}function g(t){const r=e.shallowRef({});return e.watchEffect(()=>{const e=t();((e,t)=>{const r=Object.keys(e),n=Object.keys(t);return r.length===n.length&&r.every(r=>e[r]===t[r])})(r.value,e)||(r.value=e)}),r}function b(e){return void 0!==e&&(!Array.isArray(e)||0!==e.length)}function x(e,t){if(!t)return!1;return(Array.isArray(t)?t:[t]).some(t=>function(e){return{onBlur:"blur",onChange:"change",onSubmit:"submit",blur:"blur",change:"change",submit:"submit"}[e]??"submit"}(t)===e)}const F=e=>/[A-Z]/.test(e),w=e=>e.includes("-"),C=e=>e.replace(/([A-Z])/g,"-$1").toLowerCase(),V=e=>e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase()),_=(e,t)=>{if(e[t])return e[t];const r=F(t)?C(t):w(t)?V(t):void 0;return r&&e[r]?e[r]:void 0},R=(e,t)=>{const r={},n=(o=String(e),(w(o)?V(o):o)+":");var o;const s=(e=>F(e)?C(e):e)(String(e))+":";for(const[a,l]of Object.entries(t))a.startsWith(n)?r[a.slice(n.length)]=l:a.startsWith(s)&&s!==n&&(r[a.slice(s.length)]=l);return r},S=e.defineComponent((r,{slots:n})=>{const o=e.ref(Boolean(r.schema.defaultCollapsed)),s=()=>{r.schema.collapsible&&(o.value=!o.value)};return()=>{const a=r.schema,l=Boolean(a.collapsible);return e.createVNode("div",{class:t("schemx-group",{"schemx-group--collapsed":o.value},a.class),"data-key":a.key},[a.label&&e.createVNode("div",{role:l?"button":void 0,tabindex:l?0:void 0,class:t("schemx-group__header",{"schemx-group__header--clickable":l}),onClick:s,onKeydown:e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),s())}},[e.createVNode("span",{class:"schemx-group__title"},[a.label]),l&&e.createVNode("span",{class:t("schemx-group__arrow",{"schemx-group__arrow--down":!o.value})},null)]),!o.value&&e.createVNode("div",{class:"schemx-group__body"},[a.children.map(t=>e.createVNode(k,{key:t.key,schema:t},n))])])}},{name:"SchemxGroup",props:{schema:{type:Object,required:!0}}}),k=e.defineComponent((r,{slots:n})=>{const o=e.toRef(r,"schema");if(E(o.value))return()=>e.h(S,{schema:o.value},n);const s=i(),a=y(),l=()=>o.value,c=d(l().name);!function(t){e.provide(u,t)}(c);const m=e.computed(()=>{return e=l().validationTrigger,t=a.validationTrigger,r="onChange",b(e)?e:b(t)?t:r;var e,t,r}),p=e.computed(()=>{const e=l().visible&&!l().readonly&&!l().disabled,t=l().rules,r=Array.isArray(t)?(null==t?void 0:t.length)>0:!!l().rules;return e&&r}),f=e=>{var t,r;c.setValue(e),null==(r=null==(t=l().componentProps)?void 0:t.onChange)||r.call(t,e),p.value&&x("change",m.value)&&c.validate()},h=()=>{p.value&&x("blur",m.value)&&c.validate()},v=g(()=>({...l().componentProps,value:c.getValue(),onChange:f,onBlur:h,"onUpdate:value":e=>c.setValue(e)})),F=()=>{const t=_(n,`${l().name}Label`);if(t)return t(l());const r=l().labelAlign||a.labelAlign,o=l().labelWidth||a.labelWidth,s=l().colon??a.colon;return e.createVNode("label",{class:"schemx-item__label",style:{width:o,textAlign:r}},[!l().required||l().disabled||l().readonly?null:e.createVNode("span",{class:"schemx-item__required"},[e.createTextVNode("*")]),e.createVNode("span",{class:"schemx-item__label-text"},[l().label,s?":":""])])},w=()=>{const t=s.getRenderer(l().componentType);if(!t)throw new Error(`[schemx] Can not find component renderer of "${l().componentType}".`);const r=R(A(l().name),n),o=e.h(t,v.value,r),a=_(n,`${l().name}Content`);return a?a({...l(),columnElement:o}):e.createVNode("div",{class:"schemx-item__control"},[o])},C=()=>{const t=_(n,`${l().name}Error`);return t?t({...l(),errors:c.error.value}):Array.isArray(c.error.value)&&0!==c.error.value.length?e.createVNode("div",{class:"schemx-item__error"},[c.error.value[0]]):null};return()=>{if(!l().visible)return null;const r=_(n,A(l().name));if(r)return r(l());const o=l().labelPosition||a.labelPosition;return e.createVNode("div",{class:t("schemx-item-wrapper")},[e.createVNode("div",{class:t("schemx-item",`schemx-item--label-${o}`,l().class,{"is-readonly":l().readonly,"is-disabled":l().disabled}),style:{...l().style??{}}},[F(),e.createVNode("div",{class:"schemx-item__content"},[w(),C()])])])}},{name:"SchemxItem",props:{schema:{type:Object,required:!0}}}),E=e=>"group"===e.componentType,A=e=>Array.isArray(e)?e.map(e=>String(e)).join("."):String(e);function N(e){return!(!e||"group"===e.componentType||"visible"in e&&!1===e.visible)}function O(e,t,r){for(let n=t+r;n>=0&&n<e.length;n+=r)if(N(e[n]))return e[n]}const T=e.defineComponent({name:"SchemxForm",__name:"form",props:{class:{default:""},style:{default:()=>({})},required:{type:Boolean},readonly:{type:Boolean},disabled:{type:Boolean},visible:{type:Boolean},labelIcon:{},labelAlign:{},labelPosition:{},labelWidth:{},contentAlign:{},validationTrigger:{},colon:{type:Boolean},modelValue:{default:()=>({})},initialValues:{default:()=>({})},schemas:{default:()=>[]},form:{default:void 0},rendererRegistry:{default:void 0},defaultRendererType:{},validatorRegistry:{default:void 0},onFinish:{type:Function,default:void 0},onFinishFailed:{type:Function,default:void 0},onValuesChange:{type:Function,default:void 0},onFieldsChange:{type:Function,default:void 0}},emits:["update:modelValue"],setup(t,{expose:r,emit:o}){const s=t,a=o;(t=>{e.provide(v,t)})(n.omit(s,["form","modelValue","rendererRegistry","defaultRendererType","validatorRegistry","onFinish","onFinishFailed","onValuesChange","onFieldsChange"]));const i=s.form?s.form:l({schemas:s.schemas,initialValues:s.initialValues,rendererRegistry:s.rendererRegistry,defaultRendererType:s.defaultRendererType,validatorRegistry:s.validatorRegistry,readonly:s.readonly,disabled:s.disabled,onFinish:async e=>{var t;null==(t=s.onFinish)||t.call(s,e)},onFinishFailed:async e=>{var t;null==(t=s.onFinishFailed)||t.call(s,e)},onValuesChange:(e,t)=>{var r;a("update:modelValue",t),null==(r=s.onValuesChange)||r.call(s,e,t)},onFieldsChange:(e,t)=>{var r;null==(r=s.onFieldsChange)||r.call(s,e,t)}});e.watch(()=>s.schemas,e=>{i.setSchemas(e)},{deep:!1,immediate:!!s.form});const u=function(t){const r=e.shallowRef(t.getViewSchemas()),n=t.subscribeViewSchemas(e=>{r.value=e});return e.onScopeDispose(n),r}(i),c=e=>{const{isFirst:t,isLast:r}=function(e,t){const r=e.findIndex(e=>e.key===t);return-1===r?{found:!1,isFirst:!1,isLast:!1}:N(e[r])?{found:!0,isFirst:!O(e,r,-1),isLast:!O(e,r,1)}:{found:!0,isFirst:!1,isLast:!1}}(u.value,e.key);return{"schemx-item-wrapper--first":t,"schemx-item-wrapper--last":r}};return e.watchEffect(()=>{i.updateDefaultProps(s)}),r({...i}),(t,r)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["schemx",s.class])},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(u),r=>(e.openBlock(),e.createBlock(e.unref(k),{key:r.key,schema:r,class:e.normalizeClass(c(r))},e.createSlots({_:2},[e.renderList(t.$slots,(r,n)=>({name:n,fn:e.withCtx(r=>[e.renderSlot(t.$slots,n,e.mergeProps({ref_for:!0},r??{}))])}))]),1032,["schema","class"]))),128))],2))}});const j=(B=T,P={install(e,t){e.component("SchemxForm",T)},FormItem:k},Object.assign(B,P));var B,P;exports.FormGroup=S,exports.FormItem=k,exports.WithRemoteOptions=function(t){return e.defineComponent({name:`WithRemoteOptions(${t.name||"Anonymous"})`,inheritAttrs:!1,props:{dict:{type:Object,default:void 0},fieldName:{type:[String,Array],default:void 0}},setup(r,{attrs:n,slots:o}){const s=r.dict?h(r.dict,r.fieldName):null,a=e.computed(()=>({...n,dict:r.dict,options:r.dict?null==s?void 0:s.list.value:n.options,loading:r.dict?null==s?void 0:s.loading.value:n.loading}));return()=>e.h(t,a.value,o)}})},exports.default=j,exports.rendererRegistry=o,exports.schemxForm=j,exports.useConfigContext=y,exports.useDictionary=h,exports.useEffect=function(t){const n=r.createEffect(t);return e.onUnmounted(n),n},exports.useField=d,exports.useFieldContext=function(){const t=e.inject(u);if(!t)throw new Error("[schemx] useFieldContext() must be used inside a FormItem tree");return t},exports.useForm=l,exports.useFormContext=i,exports.useWatch=m,exports.useWatchAll=function(e,t){return m(e,t)},exports.useWatchField=function(e,t,r){return m(e,t,r)},exports.useWatchFields=p,exports.validatorRegistry=s,Object.keys(r).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>r[e]})});
2
2
  //# sourceMappingURL=index.cjs.map