@tiny-codes/react-easy 1.1.1 → 1.1.3

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 (129) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/es/components/BreakLines/index.d.ts +13 -19
  3. package/es/components/BreakLines/index.js +2 -3
  4. package/es/components/BreakLines/index.js.map +1 -1
  5. package/es/components/ConfigProvider/context.d.ts +20 -26
  6. package/es/components/ConfigProvider/context.js.map +1 -1
  7. package/es/components/ConfigProvider/index.d.ts +5 -7
  8. package/es/components/ConfigProvider/index.js +2 -3
  9. package/es/components/ConfigProvider/index.js.map +1 -1
  10. package/es/components/ConfirmAction/index.d.ts +58 -89
  11. package/es/components/ConfirmAction/index.js +12 -18
  12. package/es/components/ConfirmAction/index.js.map +1 -1
  13. package/es/components/DeleteConfirmAction/index.d.ts +2 -3
  14. package/es/components/DeleteConfirmAction/index.js +8 -12
  15. package/es/components/DeleteConfirmAction/index.js.map +1 -1
  16. package/es/components/EditableText/form.d.ts +144 -0
  17. package/es/components/EditableText/form.js +309 -0
  18. package/es/components/EditableText/form.js.map +1 -0
  19. package/es/components/EditableText/index.d.ts +138 -0
  20. package/es/components/EditableText/index.js +216 -0
  21. package/es/components/EditableText/index.js.map +1 -0
  22. package/es/components/EditableText/style/index.d.ts +3 -0
  23. package/es/components/EditableText/style/index.js +76 -0
  24. package/es/components/EditableText/style/index.js.map +1 -0
  25. package/es/components/FloatDrawer/index.d.ts +89 -86
  26. package/es/components/FloatDrawer/index.js +43 -20
  27. package/es/components/FloatDrawer/index.js.map +1 -1
  28. package/es/components/FloatDrawer/style/index.js +42 -23
  29. package/es/components/FloatDrawer/style/index.js.map +1 -1
  30. package/es/components/Loading/index.d.ts +66 -0
  31. package/es/components/Loading/index.js +97 -0
  32. package/es/components/Loading/index.js.map +1 -0
  33. package/es/components/Loading/style/index.d.ts +3 -0
  34. package/es/components/Loading/style/index.js +27 -0
  35. package/es/components/Loading/style/index.js.map +1 -0
  36. package/es/components/ModalAction/index.d.ts +98 -139
  37. package/es/components/ModalAction/index.js +25 -37
  38. package/es/components/ModalAction/index.js.map +1 -1
  39. package/es/components/OverflowTags/index.d.ts +30 -8
  40. package/es/components/OverflowTags/index.js +26 -7
  41. package/es/components/OverflowTags/index.js.map +1 -1
  42. package/es/components/OverflowTags/style/index.js +1 -3
  43. package/es/components/OverflowTags/style/index.js.map +1 -1
  44. package/es/components/index.d.ts +4 -0
  45. package/es/components/index.js +2 -0
  46. package/es/components/index.js.map +1 -1
  47. package/es/hooks/useRefFunction.d.ts +4 -5
  48. package/es/hooks/useRefFunction.js +6 -7
  49. package/es/hooks/useRefFunction.js.map +1 -1
  50. package/es/hooks/useRefValue.d.ts +2 -3
  51. package/es/hooks/useRefValue.js +2 -3
  52. package/es/hooks/useRefValue.js.map +1 -1
  53. package/es/hooks/useT.js +1 -2
  54. package/es/hooks/useT.js.map +1 -1
  55. package/es/hooks/useValidator.d.ts +2 -3
  56. package/es/hooks/useValidator.js +2 -3
  57. package/es/hooks/useValidator.js.map +1 -1
  58. package/es/hooks/useValidatorBuilder.d.ts +41 -61
  59. package/es/hooks/useValidatorBuilder.js +4 -6
  60. package/es/hooks/useValidatorBuilder.js.map +1 -1
  61. package/es/hooks/useValidators.d.ts +62 -83
  62. package/es/hooks/useValidators.js +3 -4
  63. package/es/hooks/useValidators.js.map +1 -1
  64. package/es/locales/index.d.ts +15 -0
  65. package/es/locales/langs/en-US.d.ts +5 -0
  66. package/es/locales/langs/en-US.js +5 -0
  67. package/es/locales/langs/en-US.js.map +1 -1
  68. package/es/locales/langs/zh-CN.d.ts +5 -0
  69. package/es/locales/langs/zh-CN.js +5 -0
  70. package/es/locales/langs/zh-CN.js.map +1 -1
  71. package/lib/components/BreakLines/index.d.ts +13 -19
  72. package/lib/components/BreakLines/index.js.map +2 -2
  73. package/lib/components/ConfigProvider/context.d.ts +20 -26
  74. package/lib/components/ConfigProvider/context.js.map +2 -2
  75. package/lib/components/ConfigProvider/index.d.ts +5 -7
  76. package/lib/components/ConfigProvider/index.js.map +2 -2
  77. package/lib/components/ConfirmAction/index.d.ts +58 -89
  78. package/lib/components/ConfirmAction/index.js.map +2 -2
  79. package/lib/components/DeleteConfirmAction/index.d.ts +2 -3
  80. package/lib/components/DeleteConfirmAction/index.js.map +2 -2
  81. package/lib/components/EditableText/form.d.ts +144 -0
  82. package/lib/components/EditableText/form.js +223 -0
  83. package/lib/components/EditableText/form.js.map +7 -0
  84. package/lib/components/EditableText/index.d.ts +138 -0
  85. package/lib/components/EditableText/index.js +174 -0
  86. package/lib/components/EditableText/index.js.map +7 -0
  87. package/lib/components/EditableText/style/index.d.ts +3 -0
  88. package/lib/components/EditableText/style/index.js +118 -0
  89. package/lib/components/EditableText/style/index.js.map +7 -0
  90. package/lib/components/FloatDrawer/index.d.ts +89 -86
  91. package/lib/components/FloatDrawer/index.js +64 -39
  92. package/lib/components/FloatDrawer/index.js.map +2 -2
  93. package/lib/components/FloatDrawer/style/index.js +60 -23
  94. package/lib/components/FloatDrawer/style/index.js.map +2 -2
  95. package/lib/components/Loading/index.d.ts +66 -0
  96. package/lib/components/Loading/index.js +81 -0
  97. package/lib/components/Loading/index.js.map +7 -0
  98. package/lib/components/Loading/style/index.d.ts +3 -0
  99. package/lib/components/Loading/style/index.js +50 -0
  100. package/lib/components/Loading/style/index.js.map +7 -0
  101. package/lib/components/ModalAction/index.d.ts +98 -139
  102. package/lib/components/ModalAction/index.js.map +2 -2
  103. package/lib/components/OverflowTags/index.d.ts +30 -8
  104. package/lib/components/OverflowTags/index.js +7 -5
  105. package/lib/components/OverflowTags/index.js.map +2 -2
  106. package/lib/components/OverflowTags/style/index.js +1 -1
  107. package/lib/components/OverflowTags/style/index.js.map +2 -2
  108. package/lib/components/index.d.ts +4 -0
  109. package/lib/components/index.js +6 -0
  110. package/lib/components/index.js.map +2 -2
  111. package/lib/hooks/useRefFunction.d.ts +4 -5
  112. package/lib/hooks/useRefFunction.js.map +2 -2
  113. package/lib/hooks/useRefValue.d.ts +2 -3
  114. package/lib/hooks/useRefValue.js.map +2 -2
  115. package/lib/hooks/useT.js.map +2 -2
  116. package/lib/hooks/useValidator.d.ts +2 -3
  117. package/lib/hooks/useValidator.js.map +2 -2
  118. package/lib/hooks/useValidatorBuilder.d.ts +41 -61
  119. package/lib/hooks/useValidatorBuilder.js.map +2 -2
  120. package/lib/hooks/useValidators.d.ts +62 -83
  121. package/lib/hooks/useValidators.js.map +2 -2
  122. package/lib/locales/index.d.ts +15 -0
  123. package/lib/locales/langs/en-US.d.ts +5 -0
  124. package/lib/locales/langs/en-US.js +5 -0
  125. package/lib/locales/langs/en-US.js.map +2 -2
  126. package/lib/locales/langs/zh-CN.d.ts +5 -0
  127. package/lib/locales/langs/zh-CN.js +5 -0
  128. package/lib/locales/langs/zh-CN.js.map +2 -2
  129. package/package.json +1 -1
@@ -2,123 +2,107 @@ import type { ComponentType, FC, ForwardedRef, ReactElement, ReactNode, RefAttri
2
2
  import type { ButtonProps, FormInstance, ModalProps, SwitchProps } from 'antd';
3
3
  import type { LinkProps } from 'antd/es/typography/Link';
4
4
  /**
5
- * **EN:** Symbol for not closing the dialog when submitting the form, which takes effect when
6
- * returning in the `onSave` event of the editing form component
7
- *
8
- * **CN:** 提交表单时不关闭弹框的Symbol,在编辑表单组件的`onSave`事件中返回时生效
5
+ * - **EN:** Symbol for not closing the dialog when submitting the form, which takes effect when
6
+ * returning in the `onSave` event of the editing form component
7
+ * - **CN:** 提交表单时不关闭弹框的Symbol,在编辑表单组件的`onSave`事件中返回时生效
9
8
  */
10
9
  export declare const SubmitWithoutClosingSymbol: unique symbol;
11
10
  export type ModalActionProps<FD extends object, CP extends FormCompPropsConstraint<FD>, TP extends object, E extends keyof TP, CRef extends object> = Omit<ModalProps, 'onOk'> & ModalActionTrigger<FD, CP, TP, E> & {
12
11
  /**
13
- * **EN:** Form editing component, do not use the Form component inside the component, the form
14
- * component and form instance are automatically created by the parent component
15
- *
16
- * **CN:** 表单编辑组件,组件内部不要使用Form组件,表单组件及表单实例由父组件自动创建
12
+ * - **EN:** Form editing component, do not use the Form component inside the component, the form
13
+ * component and form instance are automatically created by the parent component
14
+ * - **CN:** 表单编辑组件,组件内部不要使用Form组件,表单组件及表单实例由父组件自动创建
17
15
  */
18
16
  formComp: ComponentType<CP & RefAttributes<CRef>>;
19
17
  /**
20
- * **EN:** Props of the form editing component
21
- *
22
- * **CN:** 表单编辑组件的Props属性
18
+ * - **EN:** Props of the form editing component
19
+ * - **CN:** 表单编辑组件的Props属性
23
20
  */
24
21
  formProps?: Omit<CP, keyof FormCompPropsConstraint<FD>>;
25
22
  /**
26
- * **EN:** The callback when clicks the confirmation button, support asynchronous saving, return
27
- * `SubmitWithoutClosingSymbol` can prevent the dialog from closing, return other values will be
28
- * passed to the `afterOk` event, if any
29
- *
30
- * **CN:** 点击确认按钮的回调,支持异步保存,返回`SubmitWithoutClosingSymbol`可以阻止弹框关闭,返回其他值会传递给`afterOk`事件,如果有的话
23
+ * - **EN:** The callback when clicks the confirmation button, support asynchronous saving, return
24
+ * `SubmitWithoutClosingSymbol` can prevent the dialog from closing, return other values will
25
+ * be passed to the `afterOk` event, if any
26
+ * - **CN:** 点击确认按钮的回调,支持异步保存,返回`SubmitWithoutClosingSymbol`可以阻止弹框关闭,返回其他值会传递给`afterOk`事件,如果有的话
31
27
  */
32
28
  onOk?: (formData: FD, ...args: Parameters<TP[E]>) => unknown | Promise<unknown>;
33
29
  /**
34
- * **EN:** The callback after the confirmation event is completed, it will not be triggered when
35
- * it fails, the parameter is the return value of `onOk`
36
- *
37
- * **CN:** 确认事件完成后的回调,失败时不会触发,参数为`onOk`的返回值
30
+ * - **EN:** The callback after the confirmation event is completed, it will not be triggered when
31
+ * it fails, the parameter is the return value of `onOk`
32
+ * - **CN:** 确认事件完成后的回调,失败时不会触发,参数为`onOk`的返回值
38
33
  */
39
34
  afterOk?: (data?: any) => void;
40
35
  };
41
36
  export interface FormCompPropsConstraint<FD> {
42
37
  /**
43
- * **EN:** Automatically generated form instance, use this form instance in FormComp, do not
44
- * create a new instance
45
- *
46
- * **CN:** 自动生成的表单实例,编辑表单要使用这个表单实例,不要新创建实例
38
+ * - **EN:** Automatically generated form instance, use this form instance in FormComp, do not
39
+ * create a new instance
40
+ * - **CN:** 自动生成的表单实例,编辑表单要使用这个表单实例,不要新创建实例
47
41
  */
48
42
  form: FormInstance<FD>;
49
43
  /**
50
- * **EN:** Register the form save event, the callback function passed in will be called when the
51
- * confirm button is clicked, support asynchronous saving
52
- *
53
- * **CN:** 注册表单保存事件,传入的回调函数会在点击确认按钮时被调用,支持异步保存
44
+ * - **EN:** Register the form save event, the callback function passed in will be called when the
45
+ * confirm button is clicked, support asynchronous saving
46
+ * - **CN:** 注册表单保存事件,传入的回调函数会在点击确认按钮时被调用,支持异步保存
54
47
  *
55
48
  * @param handler Event handler | 事件处理函数
56
49
  */
57
50
  onSave: (handler: (
58
51
  /**
59
- * **EN:** Form data
60
- *
61
- * **CN:** 表单数据
52
+ * - **EN:** Form data
53
+ * - **CN:** 表单数据
62
54
  */
63
55
  formData: FD,
64
56
  /**
65
- * **EN:** Trigger click event data, for example, for the `Switch` type trigger, you can get
66
- * the value of the switch; for the `Button` type trigger, you can get the click event object
67
- * of the button
68
- *
69
- * **CN:** 触发器点击的事件数据,例如,对于`Switch`类型的触发器,可以获取点击开关的值;对于`Button`类型的触发器,可以获取按钮的点击事件对象
57
+ * - **EN:** Trigger click event data, for example, for the `Switch` type trigger, you can get
58
+ * the value of the switch; for the `Button` type trigger, you can get the click event
59
+ * object of the button
60
+ * - **CN:** 触发器点击的事件数据,例如,对于`Switch`类型的触发器,可以获取点击开关的值;对于`Button`类型的触发器,可以获取按钮的点击事件对象
70
61
  */
71
62
  ...triggerEventData: any[]) => unknown | Promise<unknown>) => void;
72
63
  /**
73
- * **EN:** Listen to the open and close status of the dialog. When `destroyOnHidden` is set to
74
- * false, the form component instance is cached, and the dialog can only be listened to in this
75
- * way
76
- *
77
- * **CN:** 监听弹框打开关闭状态。当`destroyOnHidden`设置为false时,表单组件实例被缓存,只能通过这种方式监听弹框
64
+ * - **EN:** Listen to the open and close status of the dialog. When `destroyOnHidden` is set to
65
+ * false, the form component instance is cached, and the dialog can only be listened to in this
66
+ * way
67
+ * - **CN:** 监听弹框打开关闭状态。当`destroyOnHidden`设置为false时,表单组件实例被缓存,只能通过这种方式监听弹框
78
68
  *
79
69
  * @param handler Event handler | 事件处理函数
80
70
  */
81
71
  onOpenChange: (handler: ModalProps['afterOpenChange']) => void;
82
72
  /**
83
- * **EN:** Set the dialog open status
84
- *
85
- * **CN:** 设置弹框打开状态
73
+ * - **EN:** Set the dialog open status
74
+ * - **CN:** 设置弹框打开状态
86
75
  *
87
76
  * @param open Whether is open or not | 弹窗是否打开
88
77
  */
89
78
  setOpen: (open: boolean) => void;
90
79
  /**
91
- * **EN:** Modify the properties of the dialog, such as title, width, button properties, etc.
92
- *
93
- * **CN:** 修改弹窗的属性,例如标题、宽度,按钮属性等
80
+ * - **EN:** Modify the properties of the dialog, such as title, width, button properties, etc.
81
+ * - **CN:** 修改弹窗的属性,例如标题、宽度,按钮属性等
94
82
  */
95
83
  updateModalProps: (props: Partial<ModalProps>) => void;
96
84
  /**
97
- * **EN:** Trigger click event data, for example, for the `Switch` type trigger, you can get the
98
- * value of the switch; for the `Button` type trigger, you can get the click event object of the
99
- * button
100
- *
101
- * **CN:** 触发器点击的事件数据,例如,对于`Switch`类型的触发器,可以获取点击开关的值,对于`Button`类型的触发器,可以获取按钮的点击事件对象
85
+ * - **EN:** Trigger click event data, for example, for the `Switch` type trigger, you can get the
86
+ * value of the switch; for the `Button` type trigger, you can get the click event object of the
87
+ * button
88
+ * - **CN:** 触发器点击的事件数据,例如,对于`Switch`类型的触发器,可以获取点击开关的值,对于`Button`类型的触发器,可以获取按钮的点击事件对象
102
89
  */
103
90
  triggerEventData?: any[];
104
91
  }
105
92
  export interface ModalActionTrigger<FD extends object, CP extends FormCompPropsConstraint<FD>, TP extends object, E extends keyof TP> {
106
93
  /**
107
- * **EN:** Trigger component, click to show the dialog
108
- *
109
- * **CN:** 弹窗触发器组件,点击触发显示弹框
94
+ * - **EN:** Trigger component, click to show the dialog
95
+ * - **CN:** 弹窗触发器组件,点击触发显示弹框
110
96
  */
111
97
  triggerComponent?: ComponentType<TP> | FC<TP>;
112
98
  /**
113
- * **EN:** Props of the trigger component
114
- *
115
- * **CN:** 触发器组件的Props属性
99
+ * - **EN:** Props of the trigger component
100
+ * - **CN:** 触发器组件的Props属性
116
101
  */
117
102
  triggerProps?: TP & {
118
103
  /**
119
- * **EN:** Set a custom function to determine whether to show the trigger button
120
- *
121
- * **CN:** 设置一个自定义函数,用于判断是否显示触发器按钮
104
+ * - **EN:** Set a custom function to determine whether to show the trigger button
105
+ * - **CN:** 设置一个自定义函数,用于判断是否显示触发器按钮
122
106
  *
123
107
  * @default true
124
108
  *
@@ -127,168 +111,143 @@ export interface ModalActionTrigger<FD extends object, CP extends FormCompPropsC
127
111
  show?: boolean | ((formProps?: Omit<CP, keyof FormCompPropsConstraint<FD>>) => boolean);
128
112
  };
129
113
  /**
130
- * **EN:** The event name that triggers the dialog
131
- *
132
- * **CN:** 触发弹窗的事件名称
133
- *
114
+ * - **EN:** The event name that triggers the dialog
115
+ * - **CN:** 触发弹窗的事件名称
134
116
  * - `Button`: 'onClick'
135
117
  * - `Switch`: 'onChange'
136
118
  * - `Link`: 'onClick'
137
119
  */
138
120
  triggerEvent?: E;
139
121
  /**
140
- * **EN:** Custom trigger content
141
- *
142
- * **CN:** 自定义触发器内容
122
+ * - **EN:** Custom trigger content
123
+ * - **CN:** 自定义触发器内容
143
124
  */
144
125
  children?: ReactNode;
145
126
  }
146
127
  export type ModalActionRef<R> = R & {
147
128
  /**
148
- * **EN:** Show the dialog
149
- *
150
- * **CN:** 显示弹框
129
+ * - **EN:** Show the dialog
130
+ * - **CN:** 显示弹框
151
131
  */
152
132
  show: () => void;
153
133
  };
154
134
  export declare const genModalActionRenderer: (defaultProps: Partial<ModalActionProps<any, any, any, never, never>>) => <FD extends object, CP extends FormCompPropsConstraint<FD>, TP extends object, E extends keyof TP, CRef extends object>(props: ModalActionProps<FD, CP, TP, E, CRef>, ref: ForwardedRef<ModalActionRef<CRef>>) => import("react/jsx-runtime").JSX.Element;
155
135
  /**
156
- * **EN:** Add default properties to the ModalAction component
157
- *
158
- * **CN:** 给ModalAction组件添加默认属性
136
+ * - **EN:** Add default properties to the ModalAction component
137
+ * - **CN:** 给ModalAction组件添加默认属性
159
138
  *
160
139
  * @param WrappedComponent ModalAction component | ModalAction组件
161
140
  * @param defaultProps Default properties | 默认属性
162
141
  */
163
142
  export declare const withDefaultModalActionProps: <FD extends object, CP extends FormCompPropsConstraint<FD>, TP extends object, E extends keyof TP, CRef extends object>(WrappedComponent: ComponentType<ModalActionProps<FD, CP, TP, E, CRef> & RefAttributes<ModalActionRef<CRef>>>, defaultProps?: Partial<ModalActionProps<FD, CP, TP, E, CRef>> | (() => Partial<ModalActionProps<FD, CP, TP, E, CRef>>)) => import("react").ForwardRefExoticComponent<Omit<ModalProps, "onOk"> & ModalActionTrigger<FD, CP, TP, E> & {
164
143
  /**
165
- * **EN:** Form editing component, do not use the Form component inside the component, the form
166
- * component and form instance are automatically created by the parent component
167
- *
168
- * **CN:** 表单编辑组件,组件内部不要使用Form组件,表单组件及表单实例由父组件自动创建
144
+ * - **EN:** Form editing component, do not use the Form component inside the component, the form
145
+ * component and form instance are automatically created by the parent component
146
+ * - **CN:** 表单编辑组件,组件内部不要使用Form组件,表单组件及表单实例由父组件自动创建
169
147
  */
170
148
  formComp: ComponentType<CP & RefAttributes<CRef>>;
171
149
  /**
172
- * **EN:** Props of the form editing component
173
- *
174
- * **CN:** 表单编辑组件的Props属性
150
+ * - **EN:** Props of the form editing component
151
+ * - **CN:** 表单编辑组件的Props属性
175
152
  */
176
153
  formProps?: Omit<CP, keyof FormCompPropsConstraint<FD_1>> | undefined;
177
154
  /**
178
- * **EN:** The callback when clicks the confirmation button, support asynchronous saving, return
179
- * `SubmitWithoutClosingSymbol` can prevent the dialog from closing, return other values will be
180
- * passed to the `afterOk` event, if any
181
- *
182
- * **CN:** 点击确认按钮的回调,支持异步保存,返回`SubmitWithoutClosingSymbol`可以阻止弹框关闭,返回其他值会传递给`afterOk`事件,如果有的话
155
+ * - **EN:** The callback when clicks the confirmation button, support asynchronous saving, return
156
+ * `SubmitWithoutClosingSymbol` can prevent the dialog from closing, return other values will
157
+ * be passed to the `afterOk` event, if any
158
+ * - **CN:** 点击确认按钮的回调,支持异步保存,返回`SubmitWithoutClosingSymbol`可以阻止弹框关闭,返回其他值会传递给`afterOk`事件,如果有的话
183
159
  */
184
160
  onOk?: ((formData: FD, ...args: Parameters<TP[E]>) => unknown | Promise<unknown>) | undefined;
185
161
  /**
186
- * **EN:** The callback after the confirmation event is completed, it will not be triggered when
187
- * it fails, the parameter is the return value of `onOk`
188
- *
189
- * **CN:** 确认事件完成后的回调,失败时不会触发,参数为`onOk`的返回值
162
+ * - **EN:** The callback after the confirmation event is completed, it will not be triggered when
163
+ * it fails, the parameter is the return value of `onOk`
164
+ * - **CN:** 确认事件完成后的回调,失败时不会触发,参数为`onOk`的返回值
190
165
  */
191
166
  afterOk?: ((data?: any) => void) | undefined;
192
167
  } & RefAttributes<ModalActionRef<CRef>>>;
193
168
  /**
194
- * **EN:** ModalAction component type
195
- *
196
- * **CN:** ModalAction组件的类型
169
+ * - **EN:** ModalAction component type
170
+ * - **CN:** ModalAction组件的类型
197
171
  */
198
172
  export type ModalActionInterface<FD extends object, CP extends FormCompPropsConstraint<FD>, TP extends object, E extends keyof TP, CRef extends object> = ComponentType<ModalActionProps<FD, CP, TP, E, CRef> & RefAttributes<ModalActionRef<CRef>>>;
199
173
  /**
200
- * **EN:** ModalAction component with generic type
201
- *
202
- * **CN:** ModalAction泛型组件的类型
174
+ * - **EN:** ModalAction component with generic type
175
+ * - **CN:** ModalAction泛型组件的类型
203
176
  */
204
177
  export type GenericModalActionInterface = <FD extends object, CP extends FormCompPropsConstraint<FD>, TP extends object, E extends keyof TP, CRef extends object>(props: ModalActionProps<FD, CP, TP, E, CRef> & RefAttributes<ModalActionRef<CRef>>) => ReactElement;
205
178
  /**
206
- * **EN:** ModalAction with specified trigger type (specified form component)
207
- *
208
- * **CN:** 已指定Trigger类型的ModalAction(并且已指定表单组件)
179
+ * - **EN:** ModalAction with specified trigger type (specified form component)
180
+ * - **CN:** 已指定Trigger类型的ModalAction(并且已指定表单组件)
209
181
  */
210
182
  type ModalActionWithTrigger<FD extends object, CP extends FormCompPropsConstraint<FD>, TP extends object, E extends keyof TP, CRef extends object, OMIT extends string = never> = ComponentType<Omit<ModalActionProps<FD, CP, TP, E, CRef>, 'triggerComponent' | 'triggerEvent' | OMIT> & RefAttributes<ModalActionRef<CRef>>>;
211
183
  /**
212
- * **EN:** ModalAction with specified trigger type (unspecified form component, keep generic)
213
- *
214
- * **CN:** 已指定Trigger类型的ModalAction(未指定表单组件,保持泛型)
184
+ * - **EN:** ModalAction with specified trigger type (unspecified form component, keep generic)
185
+ * - **CN:** 已指定Trigger类型的ModalAction(未指定表单组件,保持泛型)
215
186
  */
216
187
  type GenericModalActionWithTrigger<TP extends object, E extends keyof TP, OMIT extends string = never> = <FD extends object, CP extends FormCompPropsConstraint<FD>, CRef extends object>(props: Omit<ModalActionProps<FD, CP, TP, E, CRef>, 'triggerComponent' | 'triggerEvent' | OMIT> & RefAttributes<ModalActionRef<CRef>>) => ReactElement;
217
188
  /**
218
- * **EN:** Built-in trigger types (specified form components)
219
- *
220
- * **CN:** 内置的几种触发器类型(已指定表单组件)
189
+ * - **EN:** Built-in trigger types (specified form components)
190
+ * - **CN:** 内置的几种触发器类型(已指定表单组件)
221
191
  */
222
192
  interface TypedTriggers<FD extends object, CP extends FormCompPropsConstraint<FD>, CRef extends object, OMIT extends string = never> {
223
193
  /**
224
- * **EN:** Dialog with button type trigger
225
- *
226
- * **CN:** 按钮类型的弹窗
194
+ * - **EN:** Dialog with button type trigger
195
+ * - **CN:** 按钮类型的弹窗
227
196
  */
228
197
  Button: ModalActionWithTrigger<FD, CP, ButtonProps, 'onClick', CRef, 'triggerComponent' | 'triggerEvent' | OMIT>;
229
198
  /**
230
- * **EN:** Dialog with switch type trigger
231
- *
232
- * **CN:** 开关类型的弹窗
199
+ * - **EN:** Dialog with switch type trigger
200
+ * - **CN:** 开关类型的弹窗
233
201
  */
234
202
  Switch: ModalActionWithTrigger<FD, CP, SwitchProps, 'onChange', CRef, 'triggerComponent' | 'triggerEvent' | OMIT>;
235
203
  /**
236
- * **EN:** Dialog with link type trigger
237
- *
238
- * **CN:** 链接类型的弹窗
204
+ * - **EN:** Dialog with link type trigger
205
+ * - **CN:** 链接类型的弹窗
239
206
  */
240
207
  Link: ModalActionWithTrigger<FD, CP, LinkProps, 'onClick', CRef, 'triggerComponent' | 'triggerEvent' | OMIT>;
241
208
  }
242
209
  /**
243
- * **EN:** Built-in trigger types (generic types, unspecified form components)
244
- *
245
- * **CN:** 内置的几种触发器类型(泛型类型,未指定表单组件)
210
+ * - **EN:** Built-in trigger types (generic types, unspecified form components)
211
+ * - **CN:** 内置的几种触发器类型(泛型类型,未指定表单组件)
246
212
  */
247
213
  interface GenericTypedTriggers<OMIT extends string = never> {
248
214
  /**
249
- * **EN:** Dialog with button type trigger
250
- *
251
- * **CN:** 按钮类型的弹窗
215
+ * - **EN:** Dialog with button type trigger
216
+ * - **CN:** 按钮类型的弹窗
252
217
  */
253
218
  Button: GenericModalActionWithTrigger<ButtonProps, 'onClick', 'triggerComponent' | 'triggerEvent' | OMIT>;
254
219
  /**
255
- * **EN:** Dialog with switch type trigger
256
- *
257
- * **CN:** 开关类型的弹窗
220
+ * - **EN:** Dialog with switch type trigger
221
+ * - **CN:** 开关类型的弹窗
258
222
  */
259
223
  Switch: GenericModalActionWithTrigger<SwitchProps, 'onChange', 'triggerComponent' | 'triggerEvent' | OMIT>;
260
224
  /**
261
- * **EN:** Dialog with link type trigger
262
- *
263
- * **CN:** 链接类型的弹窗
225
+ * - **EN:** Dialog with link type trigger
226
+ * - **CN:** 链接类型的弹窗
264
227
  */
265
228
  Link: GenericModalActionWithTrigger<LinkProps, 'onClick', 'triggerComponent' | 'triggerEvent' | OMIT>;
266
229
  }
267
230
  type WithGenericTriggers<FD extends object, CP extends FormCompPropsConstraint<FD>, CRef extends object, OMIT extends string = never> = (<TP extends object, E extends keyof TP>(props: Omit<ModalActionProps<FD, CP, TP, E, CRef>, OMIT> & RefAttributes<ModalActionRef<CRef>>) => ReactElement) & (CP extends never ? GenericTypedTriggers<OMIT> : TypedTriggers<FD, CP, CRef, OMIT>);
268
231
  /**
269
- * **EN:** Dialog component with trigger
270
- *
271
- * **CN:** 带触发器的弹窗组件
232
+ * - **EN:** Dialog component with trigger
233
+ * - **CN:** 带触发器的弹窗组件
272
234
  */
273
235
  declare const ModalAction: WithGenericTriggers<object, FormCompPropsConstraint<object>, object, never>;
274
236
  /**
275
- * **EN:** Dialog component with trigger
276
- *
277
- * **CN:** 带触发器的弹窗组件
237
+ * - **EN:** Dialog component with trigger
238
+ * - **CN:** 带触发器的弹窗组件
278
239
  */
279
240
  export type ModalActionWithStatic = typeof ModalAction & {
280
241
  /**
281
- * **EN:** Symbol for not closing the dialog when submitting the form, which takes effect when
282
- * returning in the `onSave` event of the editing form component
283
- *
284
- * **CN:** 提交表单时不关闭弹框的Symbol,在编辑表单组件的`onSave`事件中返回时生效
242
+ * - **EN:** Symbol for not closing the dialog when submitting the form, which takes effect when
243
+ * returning in the `onSave` event of the editing form component
244
+ * - **CN:** 提交表单时不关闭弹框的Symbol,在编辑表单组件的`onSave`事件中返回时生效
285
245
  */
286
246
  SubmitWithoutClosing: symbol;
287
247
  };
288
248
  /**
289
- * **EN:** Generate a dialog component based on the editing form component
290
- *
291
- * **CN:** 基于编辑表单组件生成一个弹框组件
249
+ * - **EN:** Generate a dialog component based on the editing form component
250
+ * - **CN:** 基于编辑表单组件生成一个弹框组件
292
251
  *
293
252
  * @param formComp Component of dialog content | 弹窗内容组件
294
253
  * @param defaultProps Default properties of the dialog | 弹窗的默认属性
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/ModalAction/index.tsx"],
4
- "sourcesContent": ["import type { ComponentType, FC, ForwardedRef, ReactElement, ReactNode, RefAttributes } from 'react';\nimport { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';\nimport type { ButtonProps, FormInstance, ModalProps, SwitchProps } from 'antd';\nimport { Button, Form, Modal, Switch, Typography } from 'antd';\nimport type { LinkProps } from 'antd/es/typography/Link';\nimport { isForwardRef } from 'react-is';\nimport useContextValidator from '../../hooks/useContextValidator';\n\n/**\n * **EN:** Symbol for not closing the dialog when submitting the form, which takes effect when\n * returning in the `onSave` event of the editing form component\n *\n * **CN:** 提交表单时不关闭弹框的Symbol,在编辑表单组件的`onSave`事件中返回时生效\n */\nexport const SubmitWithoutClosingSymbol = Symbol('[SubmitWithoutClose]');\n\nexport type ModalActionProps<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n> = Omit<ModalProps, 'onOk'> &\n ModalActionTrigger<FD, CP, TP, E> & {\n /**\n * **EN:** Form editing component, do not use the Form component inside the component, the form\n * component and form instance are automatically created by the parent component\n *\n * **CN:** 表单编辑组件,组件内部不要使用Form组件,表单组件及表单实例由父组件自动创建\n */\n formComp: ComponentType<CP & RefAttributes<CRef>>;\n /**\n * **EN:** Props of the form editing component\n *\n * **CN:** 表单编辑组件的Props属性\n */\n formProps?: Omit<CP, keyof FormCompPropsConstraint<FD>>;\n /**\n * **EN:** The callback when clicks the confirmation button, support asynchronous saving, return\n * `SubmitWithoutClosingSymbol` can prevent the dialog from closing, return other values will be\n * passed to the `afterOk` event, if any\n *\n * **CN:** 点击确认按钮的回调,支持异步保存,返回`SubmitWithoutClosingSymbol`可以阻止弹框关闭,返回其他值会传递给`afterOk`事件,如果有的话\n */\n onOk?: (\n formData: FD,\n // @ts-expect-error: because TP[E] should be a function type\n ...args: Parameters<TP[E]>\n ) => unknown | Promise<unknown>;\n /**\n * **EN:** The callback after the confirmation event is completed, it will not be triggered when\n * it fails, the parameter is the return value of `onOk`\n *\n * **CN:** 确认事件完成后的回调,失败时不会触发,参数为`onOk`的返回值\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n afterOk?: (data?: any) => void;\n };\n\nexport interface FormCompPropsConstraint<FD> {\n /**\n * **EN:** Automatically generated form instance, use this form instance in FormComp, do not\n * create a new instance\n *\n * **CN:** 自动生成的表单实例,编辑表单要使用这个表单实例,不要新创建实例\n */\n form: FormInstance<FD>;\n /**\n * **EN:** Register the form save event, the callback function passed in will be called when the\n * confirm button is clicked, support asynchronous saving\n *\n * **CN:** 注册表单保存事件,传入的回调函数会在点击确认按钮时被调用,支持异步保存\n *\n * @param handler Event handler | 事件处理函数\n */\n onSave: (\n handler: (\n /**\n * **EN:** Form data\n *\n * **CN:** 表单数据\n */\n formData: FD,\n /**\n * **EN:** Trigger click event data, for example, for the `Switch` type trigger, you can get\n * the value of the switch; for the `Button` type trigger, you can get the click event object\n * of the button\n *\n * **CN:** 触发器点击的事件数据,例如,对于`Switch`类型的触发器,可以获取点击开关的值;对于`Button`类型的触发器,可以获取按钮的点击事件对象\n */\n ...triggerEventData: any[]\n ) => unknown | Promise<unknown>\n ) => void;\n /**\n * **EN:** Listen to the open and close status of the dialog. When `destroyOnHidden` is set to\n * false, the form component instance is cached, and the dialog can only be listened to in this\n * way\n *\n * **CN:** 监听弹框打开关闭状态。当`destroyOnHidden`设置为false时,表单组件实例被缓存,只能通过这种方式监听弹框\n *\n * @param handler Event handler | 事件处理函数\n */\n onOpenChange: (handler: ModalProps['afterOpenChange']) => void;\n /**\n * **EN:** Set the dialog open status\n *\n * **CN:** 设置弹框打开状态\n *\n * @param open Whether is open or not | 弹窗是否打开\n */\n setOpen: (open: boolean) => void;\n /**\n * **EN:** Modify the properties of the dialog, such as title, width, button properties, etc.\n *\n * **CN:** 修改弹窗的属性,例如标题、宽度,按钮属性等\n */\n updateModalProps: (props: Partial<ModalProps>) => void;\n /**\n * **EN:** Trigger click event data, for example, for the `Switch` type trigger, you can get the\n * value of the switch; for the `Button` type trigger, you can get the click event object of the\n * button\n *\n * **CN:** 触发器点击的事件数据,例如,对于`Switch`类型的触发器,可以获取点击开关的值,对于`Button`类型的触发器,可以获取按钮的点击事件对象\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n triggerEventData?: any[];\n}\n\nexport interface ModalActionTrigger<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n> {\n /**\n * **EN:** Trigger component, click to show the dialog\n *\n * **CN:** 弹窗触发器组件,点击触发显示弹框\n */\n triggerComponent?: ComponentType<TP> | FC<TP>;\n /**\n * **EN:** Props of the trigger component\n *\n * **CN:** 触发器组件的Props属性\n */\n triggerProps?: TP & {\n /**\n * **EN:** Set a custom function to determine whether to show the trigger button\n *\n * **CN:** 设置一个自定义函数,用于判断是否显示触发器按钮\n *\n * @default true\n *\n * @param formProps Form component props | 表单组件的props\n */\n show?: boolean | ((formProps?: Omit<CP, keyof FormCompPropsConstraint<FD>>) => boolean);\n };\n /**\n * **EN:** The event name that triggers the dialog\n *\n * **CN:** 触发弹窗的事件名称\n *\n * - `Button`: 'onClick'\n * - `Switch`: 'onChange'\n * - `Link`: 'onClick'\n */\n triggerEvent?: E;\n /**\n * **EN:** Custom trigger content\n *\n * **CN:** 自定义触发器内容\n */\n children?: ReactNode;\n}\nexport type ModalActionRef<R> = R & {\n /**\n * **EN:** Show the dialog\n *\n * **CN:** 显示弹框\n */\n show: () => void;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const genModalActionRenderer = (defaultProps: Partial<ModalActionProps<any, any, any, never, never>>) => {\n const ModalActionRenderer = <\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n >(\n props: ModalActionProps<FD, CP, TP, E, CRef>,\n ref: ForwardedRef<ModalActionRef<CRef>>\n ) => {\n const [userModalProps, setUserModalProps] = useState<Partial<ModalProps>>({});\n let mergedProps = mergeProps<FD, CP, TP, E, CRef>(defaultProps, props);\n mergedProps = mergeProps(mergedProps, userModalProps as typeof props);\n const {\n formComp,\n formProps,\n triggerComponent: Trigger = Button,\n triggerEvent = 'onClick' as E,\n triggerProps,\n open: openInProps,\n destroyOnClose = true,\n destroyOnHidden = true,\n maskClosable = false,\n okButtonProps,\n cancelButtonProps,\n onOk,\n afterOk,\n onCancel,\n afterClose,\n children,\n ...restProps\n } = mergedProps;\n useContextValidator();\n const FormComp = formComp as ComponentType<FormCompPropsConstraint<FD> & RefAttributes<CRef>>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const triggerEventArgsRef = useRef<any[]>(undefined);\n const [open, setOpen] = useState(false);\n const saveFuncRef = useRef<(formData: FD, ...args: any[]) => unknown>(undefined);\n const [isSaving, setIsSaving] = useState(false);\n const [formCompRef, setFormCompRef] = useState<CRef | null>(null);\n const [form, setForm] = useState<FormInstance<FD>>();\n const formRef = useRef<FormInstance<FD>>(form);\n formRef.current = form;\n const destroyOnCloseRef = useRef(destroyOnClose);\n destroyOnCloseRef.current = destroyOnClose || destroyOnHidden;\n const openListenerRef = useRef<ModalProps['afterOpenChange']>(undefined);\n\n // Listen to the open props changes\n useEffect(() => {\n if (openInProps) {\n setOpen(openInProps);\n }\n }, [openInProps]);\n\n // Reset the form after closed\n useEffect(() => {\n if (!destroyOnCloseRef.current && open && formRef.current) {\n formRef.current.resetFields();\n }\n }, [open]);\n\n // show trigger\n const showInProps = triggerProps?.show;\n const showTrigger = useMemo(() => {\n if (typeof showInProps === 'boolean') {\n return showInProps;\n } else if (typeof showInProps === 'function') {\n return showInProps(formProps);\n }\n return true;\n }, [showInProps, formProps]);\n\n // Show the dialog\n const showModal = useCallback(() => {\n setOpen(true);\n openListenerRef.current?.(true);\n }, []);\n // Hide the dialog\n const hideModal = useCallback(() => {\n setOpen(false);\n openListenerRef.current?.(false);\n }, []);\n // Set the dialog status listener\n const setOpenListener = useCallback(\n (listener: ModalProps['afterOpenChange']) => {\n openListenerRef.current = listener;\n // Call once when initialized\n openListenerRef.current?.(open);\n },\n [open]\n );\n // Receive the onSave callback method passed by the form component\n const setOnSaveHandler: FormCompPropsConstraint<FD>['onSave'] = useCallback((handler) => {\n saveFuncRef.current = handler;\n }, []);\n // Set the dialog status and trigger the onOpenChange event of the form component\n const handleSetOpen = useCallback((open: boolean) => {\n setOpen(open);\n openListenerRef.current?.(open);\n }, []);\n\n // Output ref\n useImperativeHandle(ref, () => ({ ...formCompRef, show: showModal }) as ModalActionRef<CRef>, [\n formCompRef,\n showModal,\n ]);\n\n // Render the trigger component\n return (\n <>\n {showTrigger && (\n <Trigger\n {...triggerProps}\n // Trigger event\n {...((triggerEvent\n ? {\n [triggerEvent]: (...args: any[]) => {\n triggerEventArgsRef.current = args;\n showModal();\n if (triggerProps && typeof triggerProps[triggerEvent] === 'function') {\n (triggerProps[triggerEvent] as (...args: any[]) => void)(...args);\n }\n },\n }\n : {}) as TP)}\n >\n {(triggerProps as { children?: ReactNode }).children ?? children}\n </Trigger>\n )}\n <Modal\n open={open}\n confirmLoading={isSaving}\n destroyOnClose={destroyOnClose}\n destroyOnHidden={destroyOnHidden}\n maskClosable={maskClosable}\n okButtonProps={{\n loading: isSaving,\n ...okButtonProps,\n }}\n cancelButtonProps={{\n disabled: isSaving,\n ...cancelButtonProps,\n }}\n onOk={async () => {\n let formData: FD;\n try {\n formData = (await form?.validateFields()) as FD;\n } catch (e) {\n // Validation error, should not throw error\n return;\n }\n if (Object.keys(formData).length === 0) {\n console.warn(\n 'form.getFieldsValue() is empty. Please use the form instance passed to formComp instead of creating the form instance yourself.'\n );\n }\n try {\n setIsSaving(true);\n // First call onSave of the form component\n let result = await saveFuncRef.current?.(formData, ...(triggerEventArgsRef.current ?? []));\n // The onSave of the form component has the ability to prevent the dialog from closing\n if (result === SubmitWithoutClosingSymbol) {\n throw new Error('SubmitWithoutClosing');\n }\n // Then call onOk of the dialog, support asynchronous, and will pass the return value of onSave, if any\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n result = await onOk?.((result as FD) ?? formData, ...((triggerEventArgsRef.current ?? []) as any));\n // onOk also has the ability to prevent the dialog from closing\n if (result === SubmitWithoutClosingSymbol) {\n throw new Error('SubmitWithoutClosing');\n }\n // If onOK is successful, close the dialog and trigger the afterOk event\n hideModal();\n afterOk?.(result);\n } catch (error) {\n console.error(error);\n } finally {\n setIsSaving(false);\n }\n }}\n onCancel={async (e) => {\n hideModal();\n onCancel?.(e);\n }}\n afterClose={() => {\n hideModal();\n afterClose?.();\n }}\n {...restProps}\n >\n <FormCreator<FD> onCreate={setForm} />\n {form && (\n <FormComp\n ref={isForwardRef(FormComp) ? setFormCompRef : undefined}\n {...formProps}\n form={form}\n onOpenChange={setOpenListener}\n onSave={setOnSaveHandler}\n triggerEventData={triggerEventArgsRef.current}\n setOpen={handleSetOpen}\n updateModalProps={setUserModalProps}\n />\n )}\n </Modal>\n </>\n );\n };\n return ModalActionRenderer;\n};\n\nfunction mergeProps<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n>(first?: Partial<ModalActionProps<FD, CP, TP, E, CRef>>, second?: Partial<ModalActionProps<FD, CP, TP, E, CRef>>) {\n return {\n ...first,\n ...second,\n okButtonProps: {\n ...first?.okButtonProps,\n ...second?.okButtonProps,\n },\n cancelButtonProps: {\n ...first?.cancelButtonProps,\n ...second?.cancelButtonProps,\n },\n bodyProps: {\n ...first?.bodyProps,\n ...second?.bodyProps,\n },\n maskProps: {\n ...first?.maskProps,\n ...second?.maskProps,\n },\n wrapProps: {\n ...first?.wrapProps,\n ...second?.wrapProps,\n },\n triggerProps: {\n ...first?.triggerProps,\n ...second?.triggerProps,\n style: {\n ...(first?.triggerProps && 'style' in first.triggerProps && typeof first.triggerProps.style === 'object'\n ? first.triggerProps.style\n : {}),\n ...(second?.triggerProps && 'style' in second.triggerProps && typeof second.triggerProps.style === 'object'\n ? second.triggerProps.style\n : {}),\n },\n },\n } as unknown as ModalActionProps<FD, CP, TP, E, CRef>;\n}\n\nfunction FormCreator<FD extends object>(props: { onCreate: (form: FormInstance<FD> | undefined) => void }) {\n const { onCreate } = props;\n const onCreateRef = useRef(onCreate);\n onCreateRef.current = onCreate;\n const [form] = Form.useForm<FD>();\n\n // output ref\n useEffect(() => {\n onCreateRef.current(form);\n return () => {\n onCreateRef.current(undefined);\n };\n }, [form]);\n\n return null;\n}\n\n/**\n * **EN:** Add default properties to the ModalAction component\n *\n * **CN:** 给ModalAction组件添加默认属性\n *\n * @param WrappedComponent ModalAction component | ModalAction组件\n * @param defaultProps Default properties | 默认属性\n */\nexport const withDefaultModalActionProps = <\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n>(\n WrappedComponent: ComponentType<ModalActionProps<FD, CP, TP, E, CRef> & RefAttributes<ModalActionRef<CRef>>>,\n defaultProps?: Partial<ModalActionProps<FD, CP, TP, E, CRef>> | (() => Partial<ModalActionProps<FD, CP, TP, E, CRef>>)\n) => {\n const WithDefaultProps = forwardRef<ModalActionRef<CRef>, ModalActionProps<FD, CP, TP, E, CRef>>((props, ref) => {\n const useDefaultProps = typeof defaultProps === 'function' ? defaultProps : () => defaultProps;\n const defaults = useDefaultProps();\n const mergedProps = mergeProps(defaults, props);\n WithDefaultProps.displayName = 'ForwardedRef(WithDefaultProps)';\n return <WrappedComponent ref={ref} {...mergedProps} />;\n });\n return WithDefaultProps;\n};\n\nconst renderModalAction = genModalActionRenderer({});\nconst forwardedModalAction = forwardRef(renderModalAction);\nforwardedModalAction.displayName = 'ForwardedRef(ModalAction)';\n/**\n * **EN:** ModalAction component type\n *\n * **CN:** ModalAction组件的类型\n */\nexport type ModalActionInterface<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n> = ComponentType<ModalActionProps<FD, CP, TP, E, CRef> & RefAttributes<ModalActionRef<CRef>>>;\n/**\n * **EN:** ModalAction component with generic type\n *\n * **CN:** ModalAction泛型组件的类型\n */\nexport type GenericModalActionInterface = <\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n>(\n props: ModalActionProps<FD, CP, TP, E, CRef> & RefAttributes<ModalActionRef<CRef>>\n) => ReactElement;\n/**\n * **EN:** ModalAction with specified trigger type (specified form component)\n *\n * **CN:** 已指定Trigger类型的ModalAction(并且已指定表单组件)\n */\ntype ModalActionWithTrigger<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n OMIT extends string = never,\n> = ComponentType<\n Omit<ModalActionProps<FD, CP, TP, E, CRef>, 'triggerComponent' | 'triggerEvent' | OMIT> &\n RefAttributes<ModalActionRef<CRef>>\n>;\n\n/**\n * **EN:** ModalAction with specified trigger type (unspecified form component, keep generic)\n *\n * **CN:** 已指定Trigger类型的ModalAction(未指定表单组件,保持泛型)\n */\ntype GenericModalActionWithTrigger<TP extends object, E extends keyof TP, OMIT extends string = never> = <\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n CRef extends object,\n>(\n props: Omit<ModalActionProps<FD, CP, TP, E, CRef>, 'triggerComponent' | 'triggerEvent' | OMIT> &\n RefAttributes<ModalActionRef<CRef>>\n) => ReactElement;\n\n/**\n * **EN:** Built-in trigger types (specified form components)\n *\n * **CN:** 内置的几种触发器类型(已指定表单组件)\n */\ninterface TypedTriggers<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n CRef extends object,\n OMIT extends string = never,\n> {\n /**\n * **EN:** Dialog with button type trigger\n *\n * **CN:** 按钮类型的弹窗\n */\n Button: ModalActionWithTrigger<FD, CP, ButtonProps, 'onClick', CRef, 'triggerComponent' | 'triggerEvent' | OMIT>;\n /**\n * **EN:** Dialog with switch type trigger\n *\n * **CN:** 开关类型的弹窗\n */\n Switch: ModalActionWithTrigger<FD, CP, SwitchProps, 'onChange', CRef, 'triggerComponent' | 'triggerEvent' | OMIT>;\n /**\n * **EN:** Dialog with link type trigger\n *\n * **CN:** 链接类型的弹窗\n */\n Link: ModalActionWithTrigger<FD, CP, LinkProps, 'onClick', CRef, 'triggerComponent' | 'triggerEvent' | OMIT>;\n}\n/**\n * **EN:** Built-in trigger types (generic types, unspecified form components)\n *\n * **CN:** 内置的几种触发器类型(泛型类型,未指定表单组件)\n */\ninterface GenericTypedTriggers<OMIT extends string = never> {\n /**\n * **EN:** Dialog with button type trigger\n *\n * **CN:** 按钮类型的弹窗\n */\n Button: GenericModalActionWithTrigger<ButtonProps, 'onClick', 'triggerComponent' | 'triggerEvent' | OMIT>;\n /**\n * **EN:** Dialog with switch type trigger\n *\n * **CN:** 开关类型的弹窗\n */\n Switch: GenericModalActionWithTrigger<SwitchProps, 'onChange', 'triggerComponent' | 'triggerEvent' | OMIT>;\n /**\n * **EN:** Dialog with link type trigger\n *\n * **CN:** 链接类型的弹窗\n */\n Link: GenericModalActionWithTrigger<LinkProps, 'onClick', 'triggerComponent' | 'triggerEvent' | OMIT>;\n}\ntype WithGenericTriggers<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n CRef extends object,\n OMIT extends string = never,\n> = (<TP extends object, E extends keyof TP>(\n props: Omit<ModalActionProps<FD, CP, TP, E, CRef>, OMIT> & RefAttributes<ModalActionRef<CRef>>\n) => ReactElement) &\n (CP extends never ? GenericTypedTriggers<OMIT> : TypedTriggers<FD, CP, CRef, OMIT>);\n\n/**\n * **EN:** Add trigger types to the ModalAction component\n *\n * **CN:** 给ModalAction组件添加子触发器类型\n */\nconst addTriggers = <\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n OuterTP extends object,\n OuterE extends keyof OuterTP,\n CRef extends object,\n OMIT extends string = never,\n>(\n comp: ComponentType<ModalActionProps<FD, CP, OuterTP, OuterE, CRef> & RefAttributes<ModalActionRef<CRef>>>\n) => {\n const patchedComp = comp as WithGenericTriggers<FD, CP, CRef, OMIT>;\n // Type of button trigger\n patchedComp.Button = withDefaultModalActionProps(comp as ModalActionInterface<FD, CP, ButtonProps, 'onClick', CRef>, {\n triggerComponent: Button,\n triggerEvent: 'onClick',\n triggerProps: {},\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n }) as any;\n // Type of switch trigger\n patchedComp.Switch = withDefaultModalActionProps(\n comp as ModalActionInterface<FD, CP, SwitchProps, 'onChange', CRef>,\n {\n triggerComponent: Switch,\n triggerEvent: 'onChange',\n triggerProps: {},\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) as any;\n // Type of link trigger\n patchedComp.Link = withDefaultModalActionProps(comp as ModalActionInterface<FD, CP, LinkProps, 'onClick', CRef>, {\n triggerComponent: Typography.Link,\n triggerEvent: 'onClick',\n triggerProps: {\n style: { whiteSpace: 'nowrap' },\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n }) as any;\n return patchedComp;\n};\n\n/**\n * **EN:** Dialog component with trigger\n *\n * **CN:** 带触发器的弹窗组件\n */\nconst ModalAction = addTriggers(forwardedModalAction);\n\n/**\n * **EN:** Dialog component with trigger\n *\n * **CN:** 带触发器的弹窗组件\n */\nexport type ModalActionWithStatic = typeof ModalAction & {\n /**\n * **EN:** Symbol for not closing the dialog when submitting the form, which takes effect when\n * returning in the `onSave` event of the editing form component\n *\n * **CN:** 提交表单时不关闭弹框的Symbol,在编辑表单组件的`onSave`事件中返回时生效\n */\n SubmitWithoutClosing: symbol;\n};\n(ModalAction as ModalActionWithStatic).SubmitWithoutClosing = SubmitWithoutClosingSymbol;\n\n/**\n * **EN:** Generate a dialog component based on the editing form component\n *\n * **CN:** 基于编辑表单组件生成一个弹框组件\n *\n * @param formComp Component of dialog content | 弹窗内容组件\n * @param defaultProps Default properties of the dialog | 弹窗的默认属性\n */\nexport function withModalAction<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n OuterTP extends object,\n OuterE extends keyof OuterTP,\n CRef extends object,\n>(\n formComp: ComponentType<CP & FormCompPropsConstraint<FD> & RefAttributes<CRef>>,\n defaultProps?:\n | Partial<ModalActionProps<FD, CP, OuterTP, OuterE, CRef>>\n | (() => Partial<ModalActionProps<FD, CP, OuterTP, OuterE, CRef>>)\n) {\n const withForm = withDefaultModalActionProps(\n forwardedModalAction as unknown as ModalActionInterface<FD, CP, OuterTP, OuterE, CRef>,\n () => {\n const useDefaultProps = typeof defaultProps === 'function' ? defaultProps : () => defaultProps;\n const defaults = useDefaultProps();\n return {\n formComp,\n ...defaults,\n };\n }\n ) as unknown as <TP extends object, E extends keyof TP>(\n props: Omit<ModalActionProps<FD, CP, TP, E, CRef>, 'formComp'> & RefAttributes<ModalActionRef<CRef>>\n ) => ReactElement;\n return addTriggers<FD, CP, OuterTP, OuterE, CRef, 'formComp'>(withForm);\n}\n\nexport default ModalAction as ModalActionWithStatic;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAmG;AAEnG,kBAAwD;AAExD,sBAA6B;AAC7B,iCAAgC;AAQzB,IAAM,6BAA6B,OAAO,sBAAsB;AA0KhE,IAAM,yBAAyB,CAAC,iBAAyE;AAC9G,QAAM,sBAAsB,CAO1B,OACA,QACG;AACH,UAAM,CAAC,gBAAgB,iBAAiB,QAAI,uBAA8B,CAAC,CAAC;AAC5E,QAAI,cAAc,WAAgC,cAAc,KAAK;AACrE,kBAAc,WAAW,aAAa,cAA8B;AACpE,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA,kBAAkB,UAAU;AAAA,MAC5B,eAAe;AAAA,MACf;AAAA,MACA,MAAM;AAAA,MACN,iBAAiB;AAAA,MACjB,kBAAkB;AAAA,MAClB,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AACnD,IAAM,2BAAuB,yBAAW,iBAAiB;AACzD,qBAAqB,cAAc;AAgInC,IAAM,cAAc,CAQlB,SACG;AACH,QAAM,cAAc;AAEpB,cAAY,SAAS,4BAA4B,MAAoE;AAAA,IACnH,kBAAkB;AAAA,IAClB,cAAc;AAAA,IACd,cAAc,CAAC;AAAA;AAAA,EAEjB,CAAC;AAED,cAAY,SAAS;AAAA,IACnB;AAAA,IACA;AAAA,MACE,kBAAkB;AAAA,MAClB,cAAc;AAAA,MACd,cAAc,CAAC;AAAA,IACjB;AAAA;AAAA,EAEF;AAEA,cAAY,OAAO,4BAA4B,MAAkE;AAAA,IAC/G,kBAAkB,uBAAW;AAAA,IAC7B,cAAc;AAAA,IACd,cAAc;AAAA,MACZ,OAAO,EAAE,YAAY,SAAS;AAAA,IAChC;AAAA;AAAA,EAEF,CAAC;AACD,SAAO;AACT;AAOA,IAAM,cAAc,YAAY,oBAAoB;AAgBnD,YAAsC,uBAAuB;AAUvD,SAAS,gBAOd,UACA,cAGA;AACA,QAAM,WAAW;AAAA,IACf;AAAA,IACA,MAAM;AACJ,YAAM,kBAAkB,OAAO,iBAAiB,aAAa,eAAe,MAAM;AAClF,YAAM,WAAW,gBAAgB;AACjC,aAAO;AAAA,QACL;AAAA,QACA,GAAG;AAAA,MACL;AAAA,IACF;AAAA,EACF;AAGA,SAAO,YAAuD,QAAQ;AACxE;AAEA,IAAO,sBAAQ;",
4
+ "sourcesContent": ["import type { ComponentType, FC, ForwardedRef, ReactElement, ReactNode, RefAttributes } from 'react';\nimport { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';\nimport type { ButtonProps, FormInstance, ModalProps, SwitchProps } from 'antd';\nimport { Button, Form, Modal, Switch, Typography } from 'antd';\nimport type { LinkProps } from 'antd/es/typography/Link';\nimport { isForwardRef } from 'react-is';\nimport useContextValidator from '../../hooks/useContextValidator';\n\n/**\n * - **EN:** Symbol for not closing the dialog when submitting the form, which takes effect when\n * returning in the `onSave` event of the editing form component\n * - **CN:** 提交表单时不关闭弹框的Symbol,在编辑表单组件的`onSave`事件中返回时生效\n */\nexport const SubmitWithoutClosingSymbol = Symbol('[SubmitWithoutClose]');\n\nexport type ModalActionProps<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n> = Omit<ModalProps, 'onOk'> &\n ModalActionTrigger<FD, CP, TP, E> & {\n /**\n * - **EN:** Form editing component, do not use the Form component inside the component, the form\n * component and form instance are automatically created by the parent component\n * - **CN:** 表单编辑组件,组件内部不要使用Form组件,表单组件及表单实例由父组件自动创建\n */\n formComp: ComponentType<CP & RefAttributes<CRef>>;\n /**\n * - **EN:** Props of the form editing component\n * - **CN:** 表单编辑组件的Props属性\n */\n formProps?: Omit<CP, keyof FormCompPropsConstraint<FD>>;\n /**\n * - **EN:** The callback when clicks the confirmation button, support asynchronous saving, return\n * `SubmitWithoutClosingSymbol` can prevent the dialog from closing, return other values will\n * be passed to the `afterOk` event, if any\n * - **CN:** 点击确认按钮的回调,支持异步保存,返回`SubmitWithoutClosingSymbol`可以阻止弹框关闭,返回其他值会传递给`afterOk`事件,如果有的话\n */\n onOk?: (\n formData: FD,\n // @ts-expect-error: because TP[E] should be a function type\n ...args: Parameters<TP[E]>\n ) => unknown | Promise<unknown>;\n /**\n * - **EN:** The callback after the confirmation event is completed, it will not be triggered when\n * it fails, the parameter is the return value of `onOk`\n * - **CN:** 确认事件完成后的回调,失败时不会触发,参数为`onOk`的返回值\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n afterOk?: (data?: any) => void;\n };\n\nexport interface FormCompPropsConstraint<FD> {\n /**\n * - **EN:** Automatically generated form instance, use this form instance in FormComp, do not\n * create a new instance\n * - **CN:** 自动生成的表单实例,编辑表单要使用这个表单实例,不要新创建实例\n */\n form: FormInstance<FD>;\n /**\n * - **EN:** Register the form save event, the callback function passed in will be called when the\n * confirm button is clicked, support asynchronous saving\n * - **CN:** 注册表单保存事件,传入的回调函数会在点击确认按钮时被调用,支持异步保存\n *\n * @param handler Event handler | 事件处理函数\n */\n onSave: (\n handler: (\n /**\n * - **EN:** Form data\n * - **CN:** 表单数据\n */\n formData: FD,\n /**\n * - **EN:** Trigger click event data, for example, for the `Switch` type trigger, you can get\n * the value of the switch; for the `Button` type trigger, you can get the click event\n * object of the button\n * - **CN:** 触发器点击的事件数据,例如,对于`Switch`类型的触发器,可以获取点击开关的值;对于`Button`类型的触发器,可以获取按钮的点击事件对象\n */\n ...triggerEventData: any[]\n ) => unknown | Promise<unknown>\n ) => void;\n /**\n * - **EN:** Listen to the open and close status of the dialog. When `destroyOnHidden` is set to\n * false, the form component instance is cached, and the dialog can only be listened to in this\n * way\n * - **CN:** 监听弹框打开关闭状态。当`destroyOnHidden`设置为false时,表单组件实例被缓存,只能通过这种方式监听弹框\n *\n * @param handler Event handler | 事件处理函数\n */\n onOpenChange: (handler: ModalProps['afterOpenChange']) => void;\n /**\n * - **EN:** Set the dialog open status\n * - **CN:** 设置弹框打开状态\n *\n * @param open Whether is open or not | 弹窗是否打开\n */\n setOpen: (open: boolean) => void;\n /**\n * - **EN:** Modify the properties of the dialog, such as title, width, button properties, etc.\n * - **CN:** 修改弹窗的属性,例如标题、宽度,按钮属性等\n */\n updateModalProps: (props: Partial<ModalProps>) => void;\n /**\n * - **EN:** Trigger click event data, for example, for the `Switch` type trigger, you can get the\n * value of the switch; for the `Button` type trigger, you can get the click event object of the\n * button\n * - **CN:** 触发器点击的事件数据,例如,对于`Switch`类型的触发器,可以获取点击开关的值,对于`Button`类型的触发器,可以获取按钮的点击事件对象\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n triggerEventData?: any[];\n}\n\nexport interface ModalActionTrigger<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n> {\n /**\n * - **EN:** Trigger component, click to show the dialog\n * - **CN:** 弹窗触发器组件,点击触发显示弹框\n */\n triggerComponent?: ComponentType<TP> | FC<TP>;\n /**\n * - **EN:** Props of the trigger component\n * - **CN:** 触发器组件的Props属性\n */\n triggerProps?: TP & {\n /**\n * - **EN:** Set a custom function to determine whether to show the trigger button\n * - **CN:** 设置一个自定义函数,用于判断是否显示触发器按钮\n *\n * @default true\n *\n * @param formProps Form component props | 表单组件的props\n */\n show?: boolean | ((formProps?: Omit<CP, keyof FormCompPropsConstraint<FD>>) => boolean);\n };\n /**\n * - **EN:** The event name that triggers the dialog\n * - **CN:** 触发弹窗的事件名称\n * - `Button`: 'onClick'\n * - `Switch`: 'onChange'\n * - `Link`: 'onClick'\n */\n triggerEvent?: E;\n /**\n * - **EN:** Custom trigger content\n * - **CN:** 自定义触发器内容\n */\n children?: ReactNode;\n}\nexport type ModalActionRef<R> = R & {\n /**\n * - **EN:** Show the dialog\n * - **CN:** 显示弹框\n */\n show: () => void;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const genModalActionRenderer = (defaultProps: Partial<ModalActionProps<any, any, any, never, never>>) => {\n const ModalActionRenderer = <\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n >(\n props: ModalActionProps<FD, CP, TP, E, CRef>,\n ref: ForwardedRef<ModalActionRef<CRef>>\n ) => {\n const [userModalProps, setUserModalProps] = useState<Partial<ModalProps>>({});\n let mergedProps = mergeProps<FD, CP, TP, E, CRef>(defaultProps, props);\n mergedProps = mergeProps(mergedProps, userModalProps as typeof props);\n const {\n formComp,\n formProps,\n triggerComponent: Trigger = Button,\n triggerEvent = 'onClick' as E,\n triggerProps,\n open: openInProps,\n destroyOnClose = true,\n destroyOnHidden = true,\n maskClosable = false,\n okButtonProps,\n cancelButtonProps,\n onOk,\n afterOk,\n onCancel,\n afterClose,\n children,\n ...restProps\n } = mergedProps;\n useContextValidator();\n const FormComp = formComp as ComponentType<FormCompPropsConstraint<FD> & RefAttributes<CRef>>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const triggerEventArgsRef = useRef<any[]>(undefined);\n const [open, setOpen] = useState(false);\n const saveFuncRef = useRef<(formData: FD, ...args: any[]) => unknown>(undefined);\n const [isSaving, setIsSaving] = useState(false);\n const [formCompRef, setFormCompRef] = useState<CRef | null>(null);\n const [form, setForm] = useState<FormInstance<FD>>();\n const formRef = useRef<FormInstance<FD>>(form);\n formRef.current = form;\n const destroyOnCloseRef = useRef(destroyOnClose);\n destroyOnCloseRef.current = destroyOnClose || destroyOnHidden;\n const openListenerRef = useRef<ModalProps['afterOpenChange']>(undefined);\n\n // Listen to the open props changes\n useEffect(() => {\n if (openInProps) {\n setOpen(openInProps);\n }\n }, [openInProps]);\n\n // Reset the form after closed\n useEffect(() => {\n if (!destroyOnCloseRef.current && open && formRef.current) {\n formRef.current.resetFields();\n }\n }, [open]);\n\n // show trigger\n const showInProps = triggerProps?.show;\n const showTrigger = useMemo(() => {\n if (typeof showInProps === 'boolean') {\n return showInProps;\n } else if (typeof showInProps === 'function') {\n return showInProps(formProps);\n }\n return true;\n }, [showInProps, formProps]);\n\n // Show the dialog\n const showModal = useCallback(() => {\n setOpen(true);\n openListenerRef.current?.(true);\n }, []);\n // Hide the dialog\n const hideModal = useCallback(() => {\n setOpen(false);\n openListenerRef.current?.(false);\n }, []);\n // Set the dialog status listener\n const setOpenListener = useCallback(\n (listener: ModalProps['afterOpenChange']) => {\n openListenerRef.current = listener;\n // Call once when initialized\n openListenerRef.current?.(open);\n },\n [open]\n );\n // Receive the onSave callback method passed by the form component\n const setOnSaveHandler: FormCompPropsConstraint<FD>['onSave'] = useCallback((handler) => {\n saveFuncRef.current = handler;\n }, []);\n // Set the dialog status and trigger the onOpenChange event of the form component\n const handleSetOpen = useCallback((open: boolean) => {\n setOpen(open);\n openListenerRef.current?.(open);\n }, []);\n\n // Output ref\n useImperativeHandle(ref, () => ({ ...formCompRef, show: showModal }) as ModalActionRef<CRef>, [\n formCompRef,\n showModal,\n ]);\n\n // Render the trigger component\n return (\n <>\n {showTrigger && (\n <Trigger\n {...triggerProps}\n // Trigger event\n {...((triggerEvent\n ? {\n [triggerEvent]: (...args: any[]) => {\n triggerEventArgsRef.current = args;\n showModal();\n if (triggerProps && typeof triggerProps[triggerEvent] === 'function') {\n (triggerProps[triggerEvent] as (...args: any[]) => void)(...args);\n }\n },\n }\n : {}) as TP)}\n >\n {(triggerProps as { children?: ReactNode }).children ?? children}\n </Trigger>\n )}\n <Modal\n open={open}\n confirmLoading={isSaving}\n destroyOnClose={destroyOnClose}\n destroyOnHidden={destroyOnHidden}\n maskClosable={maskClosable}\n okButtonProps={{\n loading: isSaving,\n ...okButtonProps,\n }}\n cancelButtonProps={{\n disabled: isSaving,\n ...cancelButtonProps,\n }}\n onOk={async () => {\n let formData: FD;\n try {\n formData = (await form?.validateFields()) as FD;\n } catch (e) {\n // Validation error, should not throw error\n return;\n }\n if (Object.keys(formData).length === 0) {\n console.warn(\n 'form.getFieldsValue() is empty. Please use the form instance passed to formComp instead of creating the form instance yourself.'\n );\n }\n try {\n setIsSaving(true);\n // First call onSave of the form component\n let result = await saveFuncRef.current?.(formData, ...(triggerEventArgsRef.current ?? []));\n // The onSave of the form component has the ability to prevent the dialog from closing\n if (result === SubmitWithoutClosingSymbol) {\n throw new Error('SubmitWithoutClosing');\n }\n // Then call onOk of the dialog, support asynchronous, and will pass the return value of onSave, if any\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n result = await onOk?.((result as FD) ?? formData, ...((triggerEventArgsRef.current ?? []) as any));\n // onOk also has the ability to prevent the dialog from closing\n if (result === SubmitWithoutClosingSymbol) {\n throw new Error('SubmitWithoutClosing');\n }\n // If onOK is successful, close the dialog and trigger the afterOk event\n hideModal();\n afterOk?.(result);\n } catch (error) {\n console.error(error);\n } finally {\n setIsSaving(false);\n }\n }}\n onCancel={async (e) => {\n hideModal();\n onCancel?.(e);\n }}\n afterClose={() => {\n hideModal();\n afterClose?.();\n }}\n {...restProps}\n >\n <FormCreator<FD> onCreate={setForm} />\n {form && (\n <FormComp\n ref={isForwardRef(FormComp) ? setFormCompRef : undefined}\n {...formProps}\n form={form}\n onOpenChange={setOpenListener}\n onSave={setOnSaveHandler}\n triggerEventData={triggerEventArgsRef.current}\n setOpen={handleSetOpen}\n updateModalProps={setUserModalProps}\n />\n )}\n </Modal>\n </>\n );\n };\n return ModalActionRenderer;\n};\n\nfunction mergeProps<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n>(first?: Partial<ModalActionProps<FD, CP, TP, E, CRef>>, second?: Partial<ModalActionProps<FD, CP, TP, E, CRef>>) {\n return {\n ...first,\n ...second,\n okButtonProps: {\n ...first?.okButtonProps,\n ...second?.okButtonProps,\n },\n cancelButtonProps: {\n ...first?.cancelButtonProps,\n ...second?.cancelButtonProps,\n },\n bodyProps: {\n ...first?.bodyProps,\n ...second?.bodyProps,\n },\n maskProps: {\n ...first?.maskProps,\n ...second?.maskProps,\n },\n wrapProps: {\n ...first?.wrapProps,\n ...second?.wrapProps,\n },\n triggerProps: {\n ...first?.triggerProps,\n ...second?.triggerProps,\n style: {\n ...(first?.triggerProps && 'style' in first.triggerProps && typeof first.triggerProps.style === 'object'\n ? first.triggerProps.style\n : {}),\n ...(second?.triggerProps && 'style' in second.triggerProps && typeof second.triggerProps.style === 'object'\n ? second.triggerProps.style\n : {}),\n },\n },\n } as unknown as ModalActionProps<FD, CP, TP, E, CRef>;\n}\n\nfunction FormCreator<FD extends object>(props: { onCreate: (form: FormInstance<FD> | undefined) => void }) {\n const { onCreate } = props;\n const onCreateRef = useRef(onCreate);\n onCreateRef.current = onCreate;\n const [form] = Form.useForm<FD>();\n\n // output ref\n useEffect(() => {\n onCreateRef.current(form);\n return () => {\n onCreateRef.current(undefined);\n };\n }, [form]);\n\n return null;\n}\n\n/**\n * - **EN:** Add default properties to the ModalAction component\n * - **CN:** 给ModalAction组件添加默认属性\n *\n * @param WrappedComponent ModalAction component | ModalAction组件\n * @param defaultProps Default properties | 默认属性\n */\nexport const withDefaultModalActionProps = <\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n>(\n WrappedComponent: ComponentType<ModalActionProps<FD, CP, TP, E, CRef> & RefAttributes<ModalActionRef<CRef>>>,\n defaultProps?: Partial<ModalActionProps<FD, CP, TP, E, CRef>> | (() => Partial<ModalActionProps<FD, CP, TP, E, CRef>>)\n) => {\n const WithDefaultProps = forwardRef<ModalActionRef<CRef>, ModalActionProps<FD, CP, TP, E, CRef>>((props, ref) => {\n const useDefaultProps = typeof defaultProps === 'function' ? defaultProps : () => defaultProps;\n const defaults = useDefaultProps();\n const mergedProps = mergeProps(defaults, props);\n WithDefaultProps.displayName = 'ForwardedRef(WithDefaultProps)';\n return <WrappedComponent ref={ref} {...mergedProps} />;\n });\n return WithDefaultProps;\n};\n\nconst renderModalAction = genModalActionRenderer({});\nconst forwardedModalAction = forwardRef(renderModalAction);\nforwardedModalAction.displayName = 'ForwardedRef(ModalAction)';\n/**\n * - **EN:** ModalAction component type\n * - **CN:** ModalAction组件的类型\n */\nexport type ModalActionInterface<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n> = ComponentType<ModalActionProps<FD, CP, TP, E, CRef> & RefAttributes<ModalActionRef<CRef>>>;\n/**\n * - **EN:** ModalAction component with generic type\n * - **CN:** ModalAction泛型组件的类型\n */\nexport type GenericModalActionInterface = <\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n>(\n props: ModalActionProps<FD, CP, TP, E, CRef> & RefAttributes<ModalActionRef<CRef>>\n) => ReactElement;\n/**\n * - **EN:** ModalAction with specified trigger type (specified form component)\n * - **CN:** 已指定Trigger类型的ModalAction(并且已指定表单组件)\n */\ntype ModalActionWithTrigger<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n TP extends object,\n E extends keyof TP,\n CRef extends object,\n OMIT extends string = never,\n> = ComponentType<\n Omit<ModalActionProps<FD, CP, TP, E, CRef>, 'triggerComponent' | 'triggerEvent' | OMIT> &\n RefAttributes<ModalActionRef<CRef>>\n>;\n\n/**\n * - **EN:** ModalAction with specified trigger type (unspecified form component, keep generic)\n * - **CN:** 已指定Trigger类型的ModalAction(未指定表单组件,保持泛型)\n */\ntype GenericModalActionWithTrigger<TP extends object, E extends keyof TP, OMIT extends string = never> = <\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n CRef extends object,\n>(\n props: Omit<ModalActionProps<FD, CP, TP, E, CRef>, 'triggerComponent' | 'triggerEvent' | OMIT> &\n RefAttributes<ModalActionRef<CRef>>\n) => ReactElement;\n\n/**\n * - **EN:** Built-in trigger types (specified form components)\n * - **CN:** 内置的几种触发器类型(已指定表单组件)\n */\ninterface TypedTriggers<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n CRef extends object,\n OMIT extends string = never,\n> {\n /**\n * - **EN:** Dialog with button type trigger\n * - **CN:** 按钮类型的弹窗\n */\n Button: ModalActionWithTrigger<FD, CP, ButtonProps, 'onClick', CRef, 'triggerComponent' | 'triggerEvent' | OMIT>;\n /**\n * - **EN:** Dialog with switch type trigger\n * - **CN:** 开关类型的弹窗\n */\n Switch: ModalActionWithTrigger<FD, CP, SwitchProps, 'onChange', CRef, 'triggerComponent' | 'triggerEvent' | OMIT>;\n /**\n * - **EN:** Dialog with link type trigger\n * - **CN:** 链接类型的弹窗\n */\n Link: ModalActionWithTrigger<FD, CP, LinkProps, 'onClick', CRef, 'triggerComponent' | 'triggerEvent' | OMIT>;\n}\n/**\n * - **EN:** Built-in trigger types (generic types, unspecified form components)\n * - **CN:** 内置的几种触发器类型(泛型类型,未指定表单组件)\n */\ninterface GenericTypedTriggers<OMIT extends string = never> {\n /**\n * - **EN:** Dialog with button type trigger\n * - **CN:** 按钮类型的弹窗\n */\n Button: GenericModalActionWithTrigger<ButtonProps, 'onClick', 'triggerComponent' | 'triggerEvent' | OMIT>;\n /**\n * - **EN:** Dialog with switch type trigger\n * - **CN:** 开关类型的弹窗\n */\n Switch: GenericModalActionWithTrigger<SwitchProps, 'onChange', 'triggerComponent' | 'triggerEvent' | OMIT>;\n /**\n * - **EN:** Dialog with link type trigger\n * - **CN:** 链接类型的弹窗\n */\n Link: GenericModalActionWithTrigger<LinkProps, 'onClick', 'triggerComponent' | 'triggerEvent' | OMIT>;\n}\ntype WithGenericTriggers<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n CRef extends object,\n OMIT extends string = never,\n> = (<TP extends object, E extends keyof TP>(\n props: Omit<ModalActionProps<FD, CP, TP, E, CRef>, OMIT> & RefAttributes<ModalActionRef<CRef>>\n) => ReactElement) &\n (CP extends never ? GenericTypedTriggers<OMIT> : TypedTriggers<FD, CP, CRef, OMIT>);\n\n/**\n * - **EN:** Add trigger types to the ModalAction component\n * - **CN:** 给ModalAction组件添加子触发器类型\n */\nconst addTriggers = <\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n OuterTP extends object,\n OuterE extends keyof OuterTP,\n CRef extends object,\n OMIT extends string = never,\n>(\n comp: ComponentType<ModalActionProps<FD, CP, OuterTP, OuterE, CRef> & RefAttributes<ModalActionRef<CRef>>>\n) => {\n const patchedComp = comp as WithGenericTriggers<FD, CP, CRef, OMIT>;\n // Type of button trigger\n patchedComp.Button = withDefaultModalActionProps(comp as ModalActionInterface<FD, CP, ButtonProps, 'onClick', CRef>, {\n triggerComponent: Button,\n triggerEvent: 'onClick',\n triggerProps: {},\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n }) as any;\n // Type of switch trigger\n patchedComp.Switch = withDefaultModalActionProps(\n comp as ModalActionInterface<FD, CP, SwitchProps, 'onChange', CRef>,\n {\n triggerComponent: Switch,\n triggerEvent: 'onChange',\n triggerProps: {},\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) as any;\n // Type of link trigger\n patchedComp.Link = withDefaultModalActionProps(comp as ModalActionInterface<FD, CP, LinkProps, 'onClick', CRef>, {\n triggerComponent: Typography.Link,\n triggerEvent: 'onClick',\n triggerProps: {\n style: { whiteSpace: 'nowrap' },\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n }) as any;\n return patchedComp;\n};\n\n/**\n * - **EN:** Dialog component with trigger\n * - **CN:** 带触发器的弹窗组件\n */\nconst ModalAction = addTriggers(forwardedModalAction);\n\n/**\n * - **EN:** Dialog component with trigger\n * - **CN:** 带触发器的弹窗组件\n */\nexport type ModalActionWithStatic = typeof ModalAction & {\n /**\n * - **EN:** Symbol for not closing the dialog when submitting the form, which takes effect when\n * returning in the `onSave` event of the editing form component\n * - **CN:** 提交表单时不关闭弹框的Symbol,在编辑表单组件的`onSave`事件中返回时生效\n */\n SubmitWithoutClosing: symbol;\n};\n(ModalAction as ModalActionWithStatic).SubmitWithoutClosing = SubmitWithoutClosingSymbol;\n\n/**\n * - **EN:** Generate a dialog component based on the editing form component\n * - **CN:** 基于编辑表单组件生成一个弹框组件\n *\n * @param formComp Component of dialog content | 弹窗内容组件\n * @param defaultProps Default properties of the dialog | 弹窗的默认属性\n */\nexport function withModalAction<\n FD extends object,\n CP extends FormCompPropsConstraint<FD>,\n OuterTP extends object,\n OuterE extends keyof OuterTP,\n CRef extends object,\n>(\n formComp: ComponentType<CP & FormCompPropsConstraint<FD> & RefAttributes<CRef>>,\n defaultProps?:\n | Partial<ModalActionProps<FD, CP, OuterTP, OuterE, CRef>>\n | (() => Partial<ModalActionProps<FD, CP, OuterTP, OuterE, CRef>>)\n) {\n const withForm = withDefaultModalActionProps(\n forwardedModalAction as unknown as ModalActionInterface<FD, CP, OuterTP, OuterE, CRef>,\n () => {\n const useDefaultProps = typeof defaultProps === 'function' ? defaultProps : () => defaultProps;\n const defaults = useDefaultProps();\n return {\n formComp,\n ...defaults,\n };\n }\n ) as unknown as <TP extends object, E extends keyof TP>(\n props: Omit<ModalActionProps<FD, CP, TP, E, CRef>, 'formComp'> & RefAttributes<ModalActionRef<CRef>>\n ) => ReactElement;\n return addTriggers<FD, CP, OuterTP, OuterE, CRef, 'formComp'>(withForm);\n}\n\nexport default ModalAction as ModalActionWithStatic;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAmG;AAEnG,kBAAwD;AAExD,sBAA6B;AAC7B,iCAAgC;AAOzB,IAAM,6BAA6B,OAAO,sBAAsB;AAuJhE,IAAM,yBAAyB,CAAC,iBAAyE;AAC9G,QAAM,sBAAsB,CAO1B,OACA,QACG;AACH,UAAM,CAAC,gBAAgB,iBAAiB,QAAI,uBAA8B,CAAC,CAAC;AAC5E,QAAI,cAAc,WAAgC,cAAc,KAAK;AACrE,kBAAc,WAAW,aAAa,cAA8B;AACpE,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA,kBAAkB,UAAU;AAAA,MAC5B,eAAe;AAAA,MACf;AAAA,MACA,MAAM;AAAA,MACN,iBAAiB;AAAA,MACjB,kBAAkB;AAAA,MAClB,eAAe;AAAA,MACf;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IACL,IAAI;AACJ,mCAAAA,SAAoB;AACpB,UAAM,WAAW;AAEjB,UAAM,0BAAsB,qBAAc,MAAS;AACnD,UAAM,CAAC,MAAM,OAAO,QAAI,uBAAS,KAAK;AACtC,UAAM,kBAAc,qBAAkD,MAAS;AAC/E,UAAM,CAAC,UAAU,WAAW,QAAI,uBAAS,KAAK;AAC9C,UAAM,CAAC,aAAa,cAAc,QAAI,uBAAsB,IAAI;AAChE,UAAM,CAAC,MAAM,OAAO,QAAI,uBAA2B;AACnD,UAAM,cAAU,qBAAyB,IAAI;AAC7C,YAAQ,UAAU;AAClB,UAAM,wBAAoB,qBAAO,cAAc;AAC/C,sBAAkB,UAAU,kBAAkB;AAC9C,UAAM,sBAA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Ac,YAAY,oBAAoB;AAcnD,YAAsC,uBAAuB;AASvD,SAAS,gBAOd,UACA,cAGA;AACA,QAAM,WAAW;AAAA,IACf;AAAA,IACA,MAAM;AACJ,YAAM,kBAAkB,OAAO,iBAAiB,aAAa,eAAe,MAAM;AAClF,YAAM,WAAW,gBAAgB;AACjC,aAAO;AAAA,QACL;AAAA,QACA,GAAG;AAAA,MACL;AAAA,IACF;AAAA,EACF;AAGA,SAAO,YAAuD,QAAQ;AACxE;AAEA,IAAO,sBAAQ;",
6
6
  "names": ["useContextValidator", "open"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  import type { ReactNode } from 'react';
2
2
  import type { TagProps } from 'antd';
3
3
  import type { OverflowProps } from 'rc-overflow';
4
- export interface OverflowTagsProps<T extends Record<string, unknown> = Record<string, unknown>> extends OverflowProps<T> {
4
+ export interface OverflowTagsProps<T extends Record<string, unknown> = Record<string, unknown>> extends Omit<OverflowProps<T>, 'renderItem'> {
5
5
  /**
6
6
  * **CN**: 标签集合的数据
7
7
  *
@@ -9,23 +9,29 @@ export interface OverflowTagsProps<T extends Record<string, unknown> = Record<st
9
9
  */
10
10
  tags: T[] | undefined;
11
11
  /**
12
- * **EN**: Function to get the tag name, default is `tag.name`
12
+ * **EN**: Function to get the tag name, default is `tag.label` or `tag.name`
13
13
  *
14
- * **CN**: 获取标签名称的函数,默认取`tag.name`
14
+ * **CN**: 获取标签名称的函数,默认取`tag.label`或`tag.name`
15
15
  */
16
16
  getTagName?: (tag: T) => ReactNode;
17
17
  /**
18
- * **EN**: Function to get the unique identifier of the tag, default is `tag.id`
18
+ * **EN**: Function to get the unique identifier of the tag, default is `tag.value` or `tag.id`
19
19
  *
20
- * **CN**: 获取标签唯一标识的函数,默认取`tag.id`
20
+ * **CN**: 获取标签唯一标识的函数,默认取`tag.value`或`tag.id`
21
21
  */
22
22
  getTagKey?: (tag: T) => React.Key;
23
23
  /**
24
- * **EN**: Function to render the tag, returns `TagProps`
24
+ * **EN**: Custom tag rendering function
25
25
  *
26
- * **CN**: 渲染标签的函数,返回`TagProps`
26
+ * **CN**: 标签渲染函数
27
27
  */
28
- renderTag?: (tag: T, tags: T[]) => TagProps;
28
+ renderTag?: OverflowProps<T>['renderItem'];
29
+ /**
30
+ * **EN**: Custom properties for the default tag rendering function, returning `TagProps`
31
+ *
32
+ * **CN**: 对于默认的标签渲染函数,自定义标签的属性,返回`TagProps`
33
+ */
34
+ getTagProps?: (tag: T, tags: T[]) => TagProps;
29
35
  /**
30
36
  * **EN**: Custom properties for the tag component, if `renderTag` is also specified, the latter
31
37
  * will override the former
@@ -48,5 +54,21 @@ export interface OverflowTagsProps<T extends Record<string, unknown> = Record<st
48
54
  */
49
55
  randomColors?: boolean;
50
56
  }
57
+ /**
58
+ * - **EN:** Overflow tags component, used to display a collection of tags that can overflow and be
59
+ * truncated. It supports displaying tags in a dropdown when the number of tags exceeds the
60
+ * maximum display count. It also supports custom tag rendering and properties.
61
+ * - **CN:** 溢出标签组件,用于显示一组可以溢出和截断的标签集合。当标签数量超过最大显示数量时,支持在下拉菜单中显示标签。还支持自定义标签渲染和属性。
62
+ *
63
+ * @example
64
+ * <OverflowTags
65
+ * tags={[
66
+ * { value: 1, label: 'Tag1', icon: <Icon1 /> },
67
+ * { value: 2, label: 'Tag2', icon: <Icon2 /> },
68
+ * ]}
69
+ * tagProps={{ color: 'blue' }}
70
+ * ellipsisTagProps={{ color: 'grey' }}
71
+ * />;
72
+ */
51
73
  declare const OverflowTags: <T extends Record<string, any>>(props: OverflowTagsProps<T>) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
52
74
  export default OverflowTags;