@dazhicheng/ui 1.6.19 → 1.6.21

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.
Files changed (49) hide show
  1. package/dist/components/tt-form/index.d.ts +2 -2
  2. package/dist/components/tt-form/src/formApi.d.ts +11 -2
  3. package/dist/components/tt-form/src/group-form/LazyFormField.vue.js +162 -114
  4. package/dist/components/tt-form/src/group-form/groupFormApi.js +0 -6
  5. package/dist/components/tt-form/src/group-form/lazyContext.d.ts +18 -0
  6. package/dist/components/tt-form/src/group-form/lazyContext.js +64 -36
  7. package/dist/components/tt-form/src/group-form/types.d.ts +39 -6
  8. package/dist/components/tt-form/src/group-form/useGroupForm.d.ts +7 -5
  9. package/dist/components/tt-form/src/types.d.ts +58 -26
  10. package/dist/components/tt-form/src/useForm.d.ts +1 -1
  11. package/dist/components/tt-form/src/useForm.js +5 -5
  12. package/dist/components/tt-modal/index.d.ts +1 -0
  13. package/dist/components/tt-modal/index.js +8 -3
  14. package/dist/components/tt-modal/src/RenderModal.vue.js +224 -210
  15. package/dist/components/tt-modal/src/hooks/useModalRender.js +66 -67
  16. package/dist/components/tt-modal/src/index.js +9 -7
  17. package/dist/components/tt-modal/src/utils/modal-api.d.ts +9 -3
  18. package/dist/components/tt-modal/src/utils/modal-api.js +42 -36
  19. package/dist/components/tt-modal/src/utils/modal-close-transition.d.ts +13 -0
  20. package/dist/components/tt-modal/src/utils/modal-close-transition.js +13 -0
  21. package/dist/components/tt-modal/src/utils/modal-host-app.d.ts +5 -0
  22. package/dist/components/tt-modal/src/utils/modal-host-app.js +12 -0
  23. package/dist/components/tt-modal/src/utils/modal-scope.d.ts +21 -0
  24. package/dist/components/tt-modal/src/utils/modal-scope.js +20 -0
  25. package/dist/components/tt-modal/src/utils/modal-service.d.ts +23 -0
  26. package/dist/components/tt-modal/src/utils/modal-service.js +51 -0
  27. package/dist/components/tt-modal/src/utils/modal-stack.d.ts +14 -13
  28. package/dist/components/tt-modal/src/utils/modal-stack.js +20 -9
  29. package/dist/components/tt-modal/src/utils/modal-z-index.d.ts +15 -0
  30. package/dist/components/tt-modal/src/utils/modal-z-index.js +24 -0
  31. package/dist/components/tt-modal/src/utils/resolve-modal-target.d.ts +14 -0
  32. package/dist/components/tt-modal/src/utils/resolve-modal-target.js +83 -47
  33. package/dist/components/tt-modal-form/props.d.ts +9 -4
  34. package/dist/components/tt-modal-form/useModalForm.d.ts +1 -1
  35. package/dist/components/tt-table/index.d.ts +15 -0
  36. package/dist/components/tt-table/src/Table.vue.d.ts +9 -0
  37. package/dist/components/tt-table/src/Table.vue.js +240 -242
  38. package/dist/components/tt-table/src/TableForm.vue.d.ts +7 -5
  39. package/dist/components/tt-table/src/TableForm.vue.js +199 -180
  40. package/dist/components/tt-table/src/hooks/usePagination.d.ts +1 -1
  41. package/dist/components/tt-table/src/hooks/usePagination.js +38 -24
  42. package/dist/components/tt-table/src/hooks/useTableRender.d.ts +4 -4
  43. package/dist/components/tt-table/src/props.d.ts +6 -0
  44. package/dist/components/tt-table/src/props.js +5 -0
  45. package/dist/components/tt-table/src/types/table.d.ts +8 -0
  46. package/dist/components/tt-table/src/types/tableForm.d.ts +29 -14
  47. package/dist/components/tt-table/src/utils/table-form-api.d.ts +11 -11
  48. package/dist/index.js +132 -127
  49. package/package.json +1 -1
@@ -134,12 +134,19 @@ export interface ArraySchemaContext {
134
134
  export type FormActions = FormContext<GenericObject> & {
135
135
  arrayAction?: FormArrayActions;
136
136
  };
137
+ /**
138
+ * 表单值写入入参。
139
+ *
140
+ * 已声明的字段按 `TValues` 校验类型,同时允许写入嵌套数组路径(如 `list.0.name`)这类
141
+ * 不在 `TValues` 里的键,与 `setValues` 的运行时口径一致。
142
+ */
143
+ export type FormValuesInput<TValues extends Record<string, any> = Record<string, any>> = Partial<TValues> & Record<string, unknown>;
137
144
  /** 表单 schema 回调的公共参数类型 */
138
- export type CustomRenderType<TValues extends Record<string, any> = Record<string, any>> = ((value: TValues, formApi: FormApi) => Component | VNodeChild) | string;
145
+ export type CustomRenderType<TValues extends Record<string, any> = Record<string, any>> = ((value: TValues, formApi: ExtendedFormApi<TValues>) => Component | VNodeChild) | string;
139
146
  export type FormSchemaRuleType = "required" | "selectRequired" | null | (Record<never, never> & string) | ZodTypeAny;
140
- export type FormItemDependenciesCondition<TResult = boolean | PromiseLike<boolean>, TValues extends Record<string, any> = Record<string, any>> = (value: TValues, formApi: FormApi) => TResult;
141
- export type FormItemDependenciesConditionWithRules<TValues extends Record<string, any> = Record<string, any>> = (value: TValues, formApi: FormApi) => FormSchemaRuleType | PromiseLike<FormSchemaRuleType>;
142
- export type FormItemDependenciesConditionWithProps<TValues extends Record<string, any> = Record<string, any>> = (value: TValues, formApi: FormApi) => MaybeComponentProps | PromiseLike<MaybeComponentProps>;
147
+ export type FormItemDependenciesCondition<TResult = boolean | PromiseLike<boolean>, TValues extends Record<string, any> = Record<string, any>> = (value: TValues, formApi: ExtendedFormApi<TValues>) => TResult;
148
+ export type FormItemDependenciesConditionWithRules<TValues extends Record<string, any> = Record<string, any>> = (value: TValues, formApi: ExtendedFormApi<TValues>) => FormSchemaRuleType | PromiseLike<FormSchemaRuleType>;
149
+ export type FormItemDependenciesConditionWithProps<TValues extends Record<string, any> = Record<string, any>> = (value: TValues, formApi: ExtendedFormApi<TValues>) => MaybeComponentProps | PromiseLike<MaybeComponentProps>;
143
150
  export interface FormItemDependencies<TValues extends Record<string, any> = Record<string, any>> {
144
151
  /**
145
152
  * 组件参数
@@ -190,7 +197,7 @@ export interface FormItemDependencies<TValues extends Record<string, any> = Reco
190
197
  * - 允许声明 `triggerFields` 作为依赖触发源
191
198
  */
192
199
  export type ArrayRegisterDependencies<TValues extends Record<string, any> = Record<string, any>> = Pick<FormItemDependencies<TValues>, "if" | "show" | "rules" | "disabled" | "triggerFields">;
193
- export type ComponentProps<TValues extends Record<string, any> = Record<string, any>> = ((value: TValues, formApi: FormApi) => MaybeComponentProps) | MaybeComponentProps;
200
+ export type ComponentProps<TValues extends Record<string, any> = Record<string, any>> = ((value: TValues, formApi: ExtendedFormApi<TValues>) => MaybeComponentProps) | MaybeComponentProps;
194
201
  export interface FormCommonConfig<TValues extends Record<string, any> = Record<string, any>> {
195
202
  /**
196
203
  * 在Label后显示一个冒号
@@ -262,9 +269,9 @@ export interface FormCommonConfig<TValues extends Record<string, any> = Record<s
262
269
  */
263
270
  wrapperClass?: string;
264
271
  }
265
- export type RenderComponentContentType<TValues extends Record<string, any> = Record<string, any>> = (value: TValues, formApi: FormApi) => Record<string, any>;
266
- export type HandleSubmitFn = (values: Record<string, any>) => Promise<void> | void;
267
- export type HandleResetFn = (values: Record<string, any>) => Promise<void> | void;
272
+ export type RenderComponentContentType<TValues extends Record<string, any> = Record<string, any>> = (value: TValues, formApi: ExtendedFormApi<TValues>) => Record<string, any>;
273
+ export type HandleSubmitFn<TValues extends Record<string, any> = Record<string, any>> = (values: TValues) => Promise<void> | void;
274
+ export type HandleResetFn<TValues extends Record<string, any> = Record<string, any>> = (values: TValues) => Promise<void> | void;
268
275
  export type FieldMappingTime = [
269
276
  string,
270
277
  [
@@ -486,15 +493,15 @@ export interface TtFormProps<TValues extends Record<string, any> = Record<string
486
493
  /**
487
494
  * 表单重置回调
488
495
  */
489
- handleReset?: HandleResetFn;
496
+ handleReset?: HandleResetFn<TValues>;
490
497
  /**
491
498
  * 表单提交回调
492
499
  */
493
- handleSubmit?: HandleSubmitFn;
500
+ handleSubmit?: HandleSubmitFn<TValues>;
494
501
  /**
495
502
  * 表单值变化回调
496
503
  */
497
- handleValuesChange?: (values: Record<string, any>, fieldsChanged: string[]) => void;
504
+ handleValuesChange?: (values: TValues, fieldsChanged: string[]) => void;
498
505
  /**
499
506
  * 重置按钮参数
500
507
  */
@@ -524,38 +531,63 @@ export interface TtFormProps<TValues extends Record<string, any> = Record<string
524
531
  */
525
532
  submitOnEnter?: boolean;
526
533
  }
527
- export type ExtendedFormApi = Omit<FormApi, "getValues" | "validate" | "setState"> & {
534
+ /**
535
+ * 表单 api 对外类型。
536
+ *
537
+ * `FormApi` 类本身不带泛型(内部按 `Record<string, any>` 处理),泛型只在这一层对外收窄:
538
+ * 凡是吃/吐表单值与 schema 的方法都按 `TValues` 重新声明,其余方法沿用类的签名。
539
+ * 这样 `useForm<Data>()` 之后再调 `setState({ schema })` / `updateSchema` / `appendFields`,
540
+ * schema 里的 `dependencies` 回调依旧能推断出 `Data`。
541
+ *
542
+ * 这里保持 `Omit<类, ...>` 的写法(与改动前一致):`Omit` 会抹掉类的私有成员,所以本类型
543
+ * 不能反向赋给 `FormApi`,但改动前就是这样,业务受影响面没变;换成与类交叉虽然能反向赋值,
544
+ * 代价是同名方法变成重载对、收窄签名匹配失败时静默退回类的宽松签名,
545
+ * `setValues({ age: "1" })` 这种字段类型写错就查不出来了。
546
+ * 分组表单那侧因为改动前直接暴露的是类本身,必须用交叉,见 `ExtendedGroupFormApi`。
547
+ */
548
+ export type ExtendedFormApi<TValues extends Record<string, any> = Record<string, any>> = Omit<FormApi, "appendFields" | "getState" | "getValues" | "setValues" | "setState" | "updateSchema" | "validate"> & {
528
549
  /**
529
550
  * @description 设置表单状态,支持扩展字段(如 navAnchorProps、groupSchema 等)
530
- * @param {Partial<TtFormProps & Record<string, any>> | ((prev: TtFormProps & Record<string, any>) => Partial<TtFormProps & Record<string, any>>)} stateOrFn - 新状态或更新函数
551
+ * @param stateOrFn - 新状态或更新函数
552
+ */
553
+ setState: (stateOrFn: ((prev: TtFormProps<TValues> & Record<string, any>) => Partial<TtFormProps<TValues> & Record<string, any>>) | Partial<TtFormProps<TValues> & Record<string, any>>) => void;
554
+ /**
555
+ * @description 读取当前表单状态
556
+ */
557
+ getState: () => null | TtFormProps<TValues>;
558
+ /**
559
+ * @description 写入表单值,已声明字段按 `TValues` 校验类型
560
+ */
561
+ setValues: (fields: FormValuesInput<TValues>, filterFields?: boolean, shouldValidate?: boolean) => Promise<void>;
562
+ /**
563
+ * @description 按 fieldName 局部更新 schema
531
564
  */
532
- setState: (stateOrFn: ((prev: TtFormProps & Record<string, any>) => Partial<TtFormProps & Record<string, any>>) | Partial<TtFormProps & Record<string, any>>) => void;
565
+ updateSchema: (schema: Partial<FormSchema<TValues>>[]) => void;
533
566
  /**
534
567
  * 校验表单,支持通过第二个参数控制是否滚动到第一个错误分组
568
+ *
569
+ * 返回类型直接取 `FormApi.validate`,与运行时实际返回保持一致(`errors` 的值可能是 undefined)。
535
570
  * @param {any} [opts] - 原始 validate 选项
536
571
  * @param {boolean} [scrollToError] - 是否滚动到第一个错误分组,不传时使用全局配置 scrollToFirstError
537
572
  */
538
- validate: (opts?: any, scrollToError?: boolean) => Promise<{
539
- valid: boolean;
540
- errors: Record<string, string>;
541
- results?: any;
542
- }>;
573
+ validate: (opts?: any, scrollToError?: boolean) => ReturnType<FormApi["validate"]>;
543
574
  /**
544
575
  * 获取表单值
545
576
  * @param {boolean} [isGroup] - 为 true 时返回按分组 key 嵌套的对象,默认 false 返回扁平值
546
577
  * @returns {Promise<T>} 表单值
547
578
  */
548
- getValues: <T = Record<string, any>>(isGroup?: boolean) => Promise<T>;
549
- useStore: <T = NoInfer<TtFormProps>>(selector?: (state: NoInfer<TtFormProps>) => T) => Readonly<Ref<T>>;
579
+ getValues: <T = TValues>(isGroup?: boolean) => Promise<T>;
580
+ useStore: <T = NoInfer<TtFormProps<TValues>>>(selector?: (state: NoInfer<TtFormProps<TValues>>) => T) => Readonly<Ref<T>>;
550
581
  /** 滚动到指定分组(仅 useGroupForm 场景下可用) */
551
582
  scrollToGroup?: (key: string) => void;
552
583
  /**
553
- * 在指定分组中增量插入字段,无需全量重建 schema
554
- * @param {string} groupKey - 目标分组的 key
555
- * @param {any[]} fields - 要插入的字段或子结构(实际类型为 GroupFormSchema[])
556
- * @param {InsertPosition} [position] - 插入位置:before/after 匹配 fieldName、slot content 或 group key;省略则追加到末尾
584
+ * 增量插入字段,无需全量重建 schema
585
+ *
586
+ * `useGroupForm` 下由 `GroupFormApi` 覆盖,接收的是分组 schema 树节点。
587
+ * @param fields - 要插入的字段或子结构
588
+ * @param position - 插入位置:before/after 匹配 fieldName、slot content 或 group key;省略则追加到末尾
557
589
  */
558
- appendFields?: (groupKey: string, fields: any[], position?: {
590
+ appendFields: (fields: FormSchema<TValues>[], position?: {
559
591
  before?: string;
560
592
  after?: string;
561
593
  }) => void;
@@ -1,2 +1,2 @@
1
1
  import { ExtendedFormApi, TtFormProps } from './types';
2
- export declare function useForm<TValues extends Record<string, any> = Record<string, any>>(options: TtFormProps<TValues>): readonly [import('vue').DefineSetupFnComponent<TtFormProps<TValues>, {}, {}, TtFormProps<TValues> & {}, import('vue').PublicProps>, ExtendedFormApi];
2
+ export declare function useForm<TValues extends Record<string, any> = Record<string, any>>(options: TtFormProps<TValues>): readonly [import('vue').DefineSetupFnComponent<TtFormProps<TValues>, {}, {}, TtFormProps<TValues> & {}, import('vue').PublicProps>, ExtendedFormApi<TValues>];
@@ -4,12 +4,12 @@ import { FormApi as A } from "./formApi.js";
4
4
  import S from "./index.vue2.js";
5
5
  /* empty css */
6
6
  function C(t) {
7
- const n = a(t), e = new A(t), m = e;
8
- m.useStore = (r) => p(e.store, r);
7
+ const n = a(t), e = new A(t), r = e;
8
+ r.useStore = (m) => p(e.store, m);
9
9
  const i = c(
10
- (r, { attrs: o, slots: s }) => (f(() => {
10
+ (m, { attrs: o, slots: s }) => (f(() => {
11
11
  e.unmount();
12
- }), e.setState({ ...r, ...o }), () => u(S, { ...r, ...o, formApi: m }, s)),
12
+ }), e.setState({ ...m, ...o }), () => u(S, { ...m, ...o, formApi: r }, s)),
13
13
  {
14
14
  name: "TtForm",
15
15
  inheritAttrs: !1
@@ -21,7 +21,7 @@ function C(t) {
21
21
  e.setState({ schema: t.schema });
22
22
  },
23
23
  { immediate: !0 }
24
- ), [i, m];
24
+ ), [i, r];
25
25
  }
26
26
  export {
27
27
  C as useForm
@@ -914,6 +914,7 @@ export declare const RenderModal: import('../../../../utils/src').SFCWithInstall
914
914
  })> & Record<string, any>;
915
915
  export { useModalRender, showTtModal } from './src/hooks/useModalRender';
916
916
  export { setupModal, useShowModal } from './src';
917
+ export { ttModal, openTtModal, closeTtModal, closeAllTtModal, type OpenTtModalOptions, } from './src/utils/modal-service';
917
918
  export * from './src/typing';
918
919
  export declare const TtModal: import('../../../../utils/src').SFCWithInstall<{
919
920
  new (...args: any[]): import('vue').CreateComponentPublicInstanceWithMixins<Readonly<import('vue').ExtractPropTypes<{
@@ -18,9 +18,14 @@ import t from "./src/RenderModal.vue.js";
18
18
  import "@tanstack/vue-store";
19
19
  import "vue-router";
20
20
  import "@vueuse/core";
21
- const r = o(t), b = r;
21
+ import { closeAllTtModal as j, closeTtModal as k, openTtModal as q, ttModal as v } from "./src/utils/modal-service.js";
22
+ const r = o(t), R = r;
22
23
  export {
23
24
  r as RenderModal,
24
- b as TtModal,
25
- r as default
25
+ R as TtModal,
26
+ j as closeAllTtModal,
27
+ k as closeTtModal,
28
+ r as default,
29
+ q as openTtModal,
30
+ v as ttModal
26
31
  };