@hzab/form-render 1.6.18 → 1.6.19

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 (59) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +239 -239
  3. package/package.json +57 -57
  4. package/src/common/formily-utils.ts +125 -125
  5. package/src/common/schema-handler.ts +253 -253
  6. package/src/common/schema-merge.ts +68 -68
  7. package/src/components/ArrayBase/index.tsx +349 -349
  8. package/src/components/ArrayBase/style.less +90 -90
  9. package/src/components/ArrayBase/style.ts +2 -2
  10. package/src/components/ArrayCards/index.tsx +149 -149
  11. package/src/components/ArrayCards/style.less +14 -14
  12. package/src/components/ArrayCards/style.ts +4 -4
  13. package/src/components/ArrayTable/index.tsx +411 -411
  14. package/src/components/ArrayTable/style.less +52 -52
  15. package/src/components/ArrayTable/style.ts +7 -7
  16. package/src/components/DatePicker/index.tsx +108 -108
  17. package/src/components/LocationListPicker/assets/icon.js +1 -1
  18. package/src/components/LocationListPicker/components/AddrList/index.less +55 -55
  19. package/src/components/LocationListPicker/components/AddrList/index.tsx +75 -75
  20. package/src/components/LocationListPicker/components/Popup/address.schema.json +21 -21
  21. package/src/components/LocationListPicker/components/Popup/index.less +22 -22
  22. package/src/components/LocationListPicker/components/Popup/index.tsx +92 -92
  23. package/src/components/LocationListPicker/index.less +34 -34
  24. package/src/components/LocationListPicker/index.tsx +521 -520
  25. package/src/components/LocationPicker/Map/AMap/common/loader.ts +58 -58
  26. package/src/components/LocationPicker/Map/AMap/common/utils.ts +431 -431
  27. package/src/components/LocationPicker/Map/AMap/index.jsx +51 -51
  28. package/src/components/LocationPicker/README.md +44 -44
  29. package/src/components/LocationPicker/common/utils.ts +30 -30
  30. package/src/components/LocationPicker/components/ModalContent/index.tsx +387 -387
  31. package/src/components/LocationPicker/components/PickerInfo/index.tsx +109 -109
  32. package/src/components/LocationPicker/components/ResInfo/index.less +38 -38
  33. package/src/components/LocationPicker/components/ResInfo/index.tsx +65 -65
  34. package/src/components/LocationPicker/index.tsx +197 -197
  35. package/src/components/PersonnelSelect/index.less +21 -21
  36. package/src/components/PersonnelSelect/index.module.less +33 -33
  37. package/src/components/PersonnelSelect/type.ts +92 -92
  38. package/src/components/RichEditor/index.less +38 -38
  39. package/src/components/RichEditor/index.tsx +238 -238
  40. package/src/components/TreeCheckbox/components/CheckboxTable/index.tsx +55 -55
  41. package/src/components/TreeCheckbox/components/TabsRender/index.tsx +58 -58
  42. package/src/components/TreeCheckbox/index.less +12 -12
  43. package/src/components/TreeCheckbox/index.tsx +63 -63
  44. package/src/components/Upload/README.md +64 -64
  45. package/src/components/Upload/common/OfflineUpload.ts +339 -339
  46. package/src/components/Upload/common/customRequest.ts +81 -81
  47. package/src/components/Upload/common/fileName.ts +142 -142
  48. package/src/components/Upload/common/handleIOFileList.ts +393 -393
  49. package/src/components/Upload/common/nanoid.ts +7 -7
  50. package/src/components/Upload/common/ossUpload.js +159 -159
  51. package/src/components/Upload/common/utils.js +194 -194
  52. package/src/components/Upload/components/ItemList/index.tsx +52 -52
  53. package/src/components/Upload/components/PreviewModal/previewRender.tsx +80 -80
  54. package/src/components/Upload/index.tsx +17 -17
  55. package/src/components/Upload/uploader-input.jsx +187 -187
  56. package/src/components/Upload/uploader.jsx +316 -316
  57. package/src/components/UserSelect/index.tsx +123 -123
  58. package/src/components/index.tsx +17 -17
  59. package/src/index.tsx +198 -198
@@ -1,349 +1,349 @@
1
- import { CopyOutlined, DeleteOutlined, DownOutlined, MenuOutlined, PlusOutlined, UpOutlined } from "@ant-design/icons";
2
- import { ArrayField } from "@formily/core";
3
- import { JSXComponent, Schema, useField, useFieldSchema } from "@formily/react";
4
- import { clone, isUndef, isValid } from "@formily/shared";
5
- import { Button, Popconfirm } from "antd";
6
- import { ButtonProps } from "antd/lib/button";
7
- import cls from "classnames";
8
- import React, { createContext, ReactNode, useContext } from "react";
9
- import { SortableHandle, usePrefixCls } from "c-formily-antd/lib/__builtins__";
10
-
11
- export interface IArrayBaseAdditionProps extends ButtonProps {
12
- title?: string;
13
- method?: "push" | "unshift";
14
- defaultValue?: any;
15
- }
16
- export interface IArrayBaseOperationProps extends ButtonProps {
17
- title?: string;
18
- index?: number;
19
- ref?: React.Ref<HTMLElement>;
20
- }
21
-
22
- export interface IArrayBaseContext {
23
- props: IArrayBaseProps;
24
- field: ArrayField;
25
- schema: Schema;
26
- }
27
-
28
- export interface IArrayBaseItemProps {
29
- index: number;
30
- record: ((index: number) => Record<string, any>) | Record<string, any>;
31
- }
32
-
33
- export type ArrayBaseMixins = {
34
- Addition?: React.FC<React.PropsWithChildren<IArrayBaseAdditionProps>>;
35
- Copy?: React.FC<React.PropsWithChildren<IArrayBaseOperationProps & { index?: number }>>;
36
- Remove?: React.FC<React.PropsWithChildren<IArrayBaseOperationProps & { index?: number }>>;
37
- MoveUp?: React.FC<React.PropsWithChildren<IArrayBaseOperationProps & { index?: number }>>;
38
- MoveDown?: React.FC<React.PropsWithChildren<IArrayBaseOperationProps & { index?: number }>>;
39
- SortHandle?: React.FC<React.PropsWithChildren<IArrayBaseOperationProps & { index?: number }>>;
40
- Index?: React.FC;
41
- useArray?: () => IArrayBaseContext;
42
- useIndex?: (index?: number) => number;
43
- useRecord?: (record?: number) => any;
44
- deletePopconfirmTitle?: ReactNode;
45
- deletePopconfirm?: boolean;
46
- };
47
-
48
- export interface IArrayBaseProps {
49
- disabled?: boolean;
50
- onAdd?: (index: number) => void;
51
- onCopy?: (index: number) => void;
52
- onRemove?: (index: number) => void;
53
- onMoveDown?: (index: number) => void;
54
- onMoveUp?: (index: number) => void;
55
- deletePopconfirmTitle?: () => ReactNode;
56
- deletePopconfirm?: boolean;
57
- }
58
-
59
- type ComposedArrayBase = React.FC<React.PropsWithChildren<IArrayBaseProps>> &
60
- ArrayBaseMixins & {
61
- Item?: React.FC<React.PropsWithChildren<IArrayBaseItemProps>>;
62
- mixin?: <T extends JSXComponent>(target: T) => T & ArrayBaseMixins;
63
- };
64
-
65
- const ArrayBaseContext = createContext<IArrayBaseContext>(null);
66
-
67
- const ItemContext = createContext<IArrayBaseItemProps>(null);
68
-
69
- const takeRecord = (val: any, index?: number) => (typeof val === "function" ? val(index) : val);
70
-
71
- const useArray = () => {
72
- return useContext(ArrayBaseContext);
73
- };
74
-
75
- const useIndex = (index?: number) => {
76
- const ctx = useContext(ItemContext);
77
- return ctx ? ctx.index : index;
78
- };
79
-
80
- const useRecord = (record?: number) => {
81
- const ctx = useContext(ItemContext);
82
- return takeRecord(ctx ? ctx.record : record, ctx?.index);
83
- };
84
-
85
- const getSchemaDefaultValue = (schema: Schema) => {
86
- if (schema?.type === "array") return [];
87
- if (schema?.type === "object") return {};
88
- if (schema?.type === "void") {
89
- for (let key in schema.properties) {
90
- const value = getSchemaDefaultValue(schema.properties[key]);
91
- if (isValid(value)) return value;
92
- }
93
- }
94
- };
95
-
96
- const getDefaultValue = (defaultValue: any, schema: Schema) => {
97
- if (isValid(defaultValue)) return clone(defaultValue);
98
- if (Array.isArray(schema?.items)) return getSchemaDefaultValue(schema?.items[0]);
99
- return getSchemaDefaultValue(schema?.items);
100
- };
101
-
102
- export const ArrayBase: ComposedArrayBase = (props: any) => {
103
- const field = useField<ArrayField>();
104
- const schema = useFieldSchema();
105
- return <ArrayBaseContext.Provider value={{ field, schema, props }}>{props.children}</ArrayBaseContext.Provider>;
106
- };
107
-
108
- ArrayBase.Item = ({ children, ...props }) => {
109
- return <ItemContext.Provider value={props}>{children}</ItemContext.Provider>;
110
- };
111
-
112
- const SortHandle = SortableHandle((props: any) => {
113
- const prefixCls = usePrefixCls("formily-array-base");
114
- return (
115
- <MenuOutlined {...props} className={cls(`${prefixCls}-sort-handle`, props.className)} style={{ ...props.style }} />
116
- );
117
- }) as any;
118
-
119
- ArrayBase.SortHandle = (props) => {
120
- const array = useArray();
121
- if (!array) return null;
122
- if (array.field?.pattern !== "editable") return null;
123
- return <SortHandle {...props} />;
124
- };
125
-
126
- ArrayBase.Index = (props) => {
127
- const index = useIndex();
128
- const prefixCls = usePrefixCls("formily-array-base");
129
- return (
130
- <span {...props} className={`${prefixCls}-index`}>
131
- #{index + 1}.
132
- </span>
133
- );
134
- };
135
-
136
- ArrayBase.Addition = (props) => {
137
- const self = useField();
138
- const array = useArray();
139
- const prefixCls = usePrefixCls("formily-array-base");
140
- if (!array) return null;
141
- if (array.field?.pattern !== "editable" && array.field?.pattern !== "disabled") return null;
142
- return (
143
- <Button
144
- type="dashed"
145
- block
146
- {...props}
147
- disabled={self?.disabled}
148
- className={cls(`${prefixCls}-addition`, props.className)}
149
- onClick={(e) => {
150
- if (array.props?.disabled) return;
151
- if (props.onClick) {
152
- props.onClick(e);
153
- if (e.defaultPrevented) return;
154
- }
155
- const defaultValue = getDefaultValue(props.defaultValue, array.schema);
156
- if (props.method === "unshift") {
157
- array.field?.unshift?.(defaultValue);
158
- array.props?.onAdd?.(0);
159
- } else {
160
- array.field?.push?.(defaultValue);
161
- array.props?.onAdd?.(array?.field?.value?.length - 1);
162
- }
163
- }}
164
- icon={isUndef(props.icon) ? <PlusOutlined /> : props.icon}
165
- >
166
- {props.title || self.title}
167
- </Button>
168
- );
169
- };
170
-
171
- ArrayBase.Copy = React.forwardRef((props, ref) => {
172
- const self = useField();
173
- const array = useArray();
174
- const index = useIndex(props.index);
175
- const prefixCls = usePrefixCls("formily-array-base");
176
- if (!array) return null;
177
- if (array.field?.pattern !== "editable") return null;
178
- return (
179
- <Button
180
- type="text"
181
- {...props}
182
- disabled={self?.disabled}
183
- className={cls(`${prefixCls}-copy`, self?.disabled ? `${prefixCls}-copy-disabled` : "", props.className)}
184
- ref={ref}
185
- onClick={(e) => {
186
- if (self?.disabled) return;
187
- e.stopPropagation();
188
- if (array.props?.disabled) return;
189
- if (props.onClick) {
190
- props.onClick(e);
191
- if (e.defaultPrevented) return;
192
- }
193
- const value = clone(array?.field?.value[index]);
194
- const distIndex = index + 1;
195
- array.field?.insert?.(distIndex, value);
196
- array.props?.onCopy?.(distIndex);
197
- }}
198
- icon={isUndef(props.icon) ? <CopyOutlined /> : props.icon}
199
- >
200
- {props.title || self.title}
201
- </Button>
202
- );
203
- });
204
-
205
- ArrayBase.Remove = React.forwardRef((props, ref) => {
206
- const index = useIndex(props.index);
207
- const self = useField();
208
- const array = useArray();
209
- const prefixCls = usePrefixCls("formily-array-base");
210
- if (!array) return null;
211
- if (array.field?.pattern !== "editable") return null;
212
-
213
- return (
214
- <>
215
- {array.props?.deletePopconfirm && !self?.disabled ? (
216
- <Popconfirm
217
- {...array.props}
218
- title={array.props?.deletePopconfirmTitle() || null}
219
- onConfirm={() => {
220
- if (self?.disabled) return;
221
- array.field?.remove?.(index);
222
- array.props?.onRemove?.(index);
223
- }}
224
- >
225
- <Button
226
- type="text"
227
- {...props}
228
- disabled={self?.disabled}
229
- className={cls(
230
- `${prefixCls}-remove`,
231
- self?.disabled ? `${prefixCls}-remove-disabled` : "",
232
- props.className,
233
- )}
234
- ref={ref}
235
- icon={isUndef(props.icon) ? <DeleteOutlined /> : props.icon}
236
- >
237
- {props.title || self.title}
238
- </Button>
239
- </Popconfirm>
240
- ) : (
241
- <Button
242
- type="text"
243
- {...props}
244
- disabled={self?.disabled}
245
- className={cls(`${prefixCls}-remove`, self?.disabled ? `${prefixCls}-remove-disabled` : "", props.className)}
246
- ref={ref}
247
- onClick={(e) => {
248
- if (self?.disabled) return;
249
- e.stopPropagation();
250
- if (props.onClick) {
251
- props.onClick(e);
252
- if (e.defaultPrevented) return;
253
- }
254
- array.field?.remove?.(index);
255
- array.props?.onRemove?.(index);
256
- }}
257
- icon={isUndef(props.icon) ? <DeleteOutlined /> : props.icon}
258
- >
259
- {props.title || self.title}
260
- </Button>
261
- )}
262
- </>
263
- );
264
- });
265
-
266
- ArrayBase.MoveDown = React.forwardRef((props, ref) => {
267
- const index = useIndex(props.index);
268
- const self = useField();
269
- const array = useArray();
270
- const prefixCls = usePrefixCls("formily-array-base");
271
- if (!array) return null;
272
- if (array.field?.pattern !== "editable") return null;
273
- return (
274
- <Button
275
- type="text"
276
- {...props}
277
- disabled={self?.disabled}
278
- className={cls(
279
- `${prefixCls}-move-down`,
280
- self?.disabled ? `${prefixCls}-move-down-disabled` : "",
281
- props.className,
282
- )}
283
- ref={ref}
284
- onClick={(e) => {
285
- if (self?.disabled) return;
286
- e.stopPropagation();
287
- if (props.onClick) {
288
- props.onClick(e);
289
- if (e.defaultPrevented) return;
290
- }
291
- array.field?.moveDown?.(index);
292
- array.props?.onMoveDown?.(index);
293
- }}
294
- icon={isUndef(props.icon) ? <DownOutlined /> : props.icon}
295
- >
296
- {props.title || self.title}
297
- </Button>
298
- );
299
- });
300
-
301
- ArrayBase.MoveUp = React.forwardRef((props, ref) => {
302
- const index = useIndex(props.index);
303
- const self = useField();
304
- const array = useArray();
305
- const prefixCls = usePrefixCls("formily-array-base");
306
- if (!array) return null;
307
- if (array.field?.pattern !== "editable") return null;
308
- return (
309
- <Button
310
- type="text"
311
- {...props}
312
- disabled={self?.disabled}
313
- className={cls(`${prefixCls}-move-up`, self?.disabled ? `${prefixCls}-move-up-disabled` : "", props.className)}
314
- ref={ref}
315
- onClick={(e) => {
316
- if (self?.disabled) return;
317
- e.stopPropagation();
318
- if (props.onClick) {
319
- props.onClick(e);
320
- if (e.defaultPrevented) return;
321
- }
322
- array?.field?.moveUp(index);
323
- array?.props?.onMoveUp?.(index);
324
- }}
325
- icon={isUndef(props.icon) ? <UpOutlined /> : props.icon}
326
- >
327
- {props.title || self.title}
328
- </Button>
329
- );
330
- });
331
-
332
- ArrayBase.useArray = useArray;
333
- ArrayBase.useIndex = useIndex;
334
- ArrayBase.useRecord = useRecord;
335
- ArrayBase.mixin = (target: any) => {
336
- target.Index = ArrayBase.Index;
337
- target.SortHandle = ArrayBase.SortHandle;
338
- target.Addition = ArrayBase.Addition;
339
- target.Copy = ArrayBase.Copy;
340
- target.Remove = ArrayBase.Remove;
341
- target.MoveDown = ArrayBase.MoveDown;
342
- target.MoveUp = ArrayBase.MoveUp;
343
- target.useArray = ArrayBase.useArray;
344
- target.useIndex = ArrayBase.useIndex;
345
- target.useRecord = ArrayBase.useRecord;
346
- return target;
347
- };
348
-
349
- export default ArrayBase;
1
+ import { CopyOutlined, DeleteOutlined, DownOutlined, MenuOutlined, PlusOutlined, UpOutlined } from "@ant-design/icons";
2
+ import { ArrayField } from "@formily/core";
3
+ import { JSXComponent, Schema, useField, useFieldSchema } from "@formily/react";
4
+ import { clone, isUndef, isValid } from "@formily/shared";
5
+ import { Button, Popconfirm } from "antd";
6
+ import { ButtonProps } from "antd/lib/button";
7
+ import cls from "classnames";
8
+ import React, { createContext, ReactNode, useContext } from "react";
9
+ import { SortableHandle, usePrefixCls } from "c-formily-antd/lib/__builtins__";
10
+
11
+ export interface IArrayBaseAdditionProps extends ButtonProps {
12
+ title?: string;
13
+ method?: "push" | "unshift";
14
+ defaultValue?: any;
15
+ }
16
+ export interface IArrayBaseOperationProps extends ButtonProps {
17
+ title?: string;
18
+ index?: number;
19
+ ref?: React.Ref<HTMLElement>;
20
+ }
21
+
22
+ export interface IArrayBaseContext {
23
+ props: IArrayBaseProps;
24
+ field: ArrayField;
25
+ schema: Schema;
26
+ }
27
+
28
+ export interface IArrayBaseItemProps {
29
+ index: number;
30
+ record: ((index: number) => Record<string, any>) | Record<string, any>;
31
+ }
32
+
33
+ export type ArrayBaseMixins = {
34
+ Addition?: React.FC<React.PropsWithChildren<IArrayBaseAdditionProps>>;
35
+ Copy?: React.FC<React.PropsWithChildren<IArrayBaseOperationProps & { index?: number }>>;
36
+ Remove?: React.FC<React.PropsWithChildren<IArrayBaseOperationProps & { index?: number }>>;
37
+ MoveUp?: React.FC<React.PropsWithChildren<IArrayBaseOperationProps & { index?: number }>>;
38
+ MoveDown?: React.FC<React.PropsWithChildren<IArrayBaseOperationProps & { index?: number }>>;
39
+ SortHandle?: React.FC<React.PropsWithChildren<IArrayBaseOperationProps & { index?: number }>>;
40
+ Index?: React.FC;
41
+ useArray?: () => IArrayBaseContext;
42
+ useIndex?: (index?: number) => number;
43
+ useRecord?: (record?: number) => any;
44
+ deletePopconfirmTitle?: ReactNode;
45
+ deletePopconfirm?: boolean;
46
+ };
47
+
48
+ export interface IArrayBaseProps {
49
+ disabled?: boolean;
50
+ onAdd?: (index: number) => void;
51
+ onCopy?: (index: number) => void;
52
+ onRemove?: (index: number) => void;
53
+ onMoveDown?: (index: number) => void;
54
+ onMoveUp?: (index: number) => void;
55
+ deletePopconfirmTitle?: () => ReactNode;
56
+ deletePopconfirm?: boolean;
57
+ }
58
+
59
+ type ComposedArrayBase = React.FC<React.PropsWithChildren<IArrayBaseProps>> &
60
+ ArrayBaseMixins & {
61
+ Item?: React.FC<React.PropsWithChildren<IArrayBaseItemProps>>;
62
+ mixin?: <T extends JSXComponent>(target: T) => T & ArrayBaseMixins;
63
+ };
64
+
65
+ const ArrayBaseContext = createContext<IArrayBaseContext>(null);
66
+
67
+ const ItemContext = createContext<IArrayBaseItemProps>(null);
68
+
69
+ const takeRecord = (val: any, index?: number) => (typeof val === "function" ? val(index) : val);
70
+
71
+ const useArray = () => {
72
+ return useContext(ArrayBaseContext);
73
+ };
74
+
75
+ const useIndex = (index?: number) => {
76
+ const ctx = useContext(ItemContext);
77
+ return ctx ? ctx.index : index;
78
+ };
79
+
80
+ const useRecord = (record?: number) => {
81
+ const ctx = useContext(ItemContext);
82
+ return takeRecord(ctx ? ctx.record : record, ctx?.index);
83
+ };
84
+
85
+ const getSchemaDefaultValue = (schema: Schema) => {
86
+ if (schema?.type === "array") return [];
87
+ if (schema?.type === "object") return {};
88
+ if (schema?.type === "void") {
89
+ for (let key in schema.properties) {
90
+ const value = getSchemaDefaultValue(schema.properties[key]);
91
+ if (isValid(value)) return value;
92
+ }
93
+ }
94
+ };
95
+
96
+ const getDefaultValue = (defaultValue: any, schema: Schema) => {
97
+ if (isValid(defaultValue)) return clone(defaultValue);
98
+ if (Array.isArray(schema?.items)) return getSchemaDefaultValue(schema?.items[0]);
99
+ return getSchemaDefaultValue(schema?.items);
100
+ };
101
+
102
+ export const ArrayBase: ComposedArrayBase = (props: any) => {
103
+ const field = useField<ArrayField>();
104
+ const schema = useFieldSchema();
105
+ return <ArrayBaseContext.Provider value={{ field, schema, props }}>{props.children}</ArrayBaseContext.Provider>;
106
+ };
107
+
108
+ ArrayBase.Item = ({ children, ...props }) => {
109
+ return <ItemContext.Provider value={props}>{children}</ItemContext.Provider>;
110
+ };
111
+
112
+ const SortHandle = SortableHandle((props: any) => {
113
+ const prefixCls = usePrefixCls("formily-array-base");
114
+ return (
115
+ <MenuOutlined {...props} className={cls(`${prefixCls}-sort-handle`, props.className)} style={{ ...props.style }} />
116
+ );
117
+ }) as any;
118
+
119
+ ArrayBase.SortHandle = (props) => {
120
+ const array = useArray();
121
+ if (!array) return null;
122
+ if (array.field?.pattern !== "editable") return null;
123
+ return <SortHandle {...props} />;
124
+ };
125
+
126
+ ArrayBase.Index = (props) => {
127
+ const index = useIndex();
128
+ const prefixCls = usePrefixCls("formily-array-base");
129
+ return (
130
+ <span {...props} className={`${prefixCls}-index`}>
131
+ #{index + 1}.
132
+ </span>
133
+ );
134
+ };
135
+
136
+ ArrayBase.Addition = (props) => {
137
+ const self = useField();
138
+ const array = useArray();
139
+ const prefixCls = usePrefixCls("formily-array-base");
140
+ if (!array) return null;
141
+ if (array.field?.pattern !== "editable" && array.field?.pattern !== "disabled") return null;
142
+ return (
143
+ <Button
144
+ type="dashed"
145
+ block
146
+ {...props}
147
+ disabled={self?.disabled}
148
+ className={cls(`${prefixCls}-addition`, props.className)}
149
+ onClick={(e) => {
150
+ if (array.props?.disabled) return;
151
+ if (props.onClick) {
152
+ props.onClick(e);
153
+ if (e.defaultPrevented) return;
154
+ }
155
+ const defaultValue = getDefaultValue(props.defaultValue, array.schema);
156
+ if (props.method === "unshift") {
157
+ array.field?.unshift?.(defaultValue);
158
+ array.props?.onAdd?.(0);
159
+ } else {
160
+ array.field?.push?.(defaultValue);
161
+ array.props?.onAdd?.(array?.field?.value?.length - 1);
162
+ }
163
+ }}
164
+ icon={isUndef(props.icon) ? <PlusOutlined /> : props.icon}
165
+ >
166
+ {props.title || self.title}
167
+ </Button>
168
+ );
169
+ };
170
+
171
+ ArrayBase.Copy = React.forwardRef((props, ref) => {
172
+ const self = useField();
173
+ const array = useArray();
174
+ const index = useIndex(props.index);
175
+ const prefixCls = usePrefixCls("formily-array-base");
176
+ if (!array) return null;
177
+ if (array.field?.pattern !== "editable") return null;
178
+ return (
179
+ <Button
180
+ type="text"
181
+ {...props}
182
+ disabled={self?.disabled}
183
+ className={cls(`${prefixCls}-copy`, self?.disabled ? `${prefixCls}-copy-disabled` : "", props.className)}
184
+ ref={ref}
185
+ onClick={(e) => {
186
+ if (self?.disabled) return;
187
+ e.stopPropagation();
188
+ if (array.props?.disabled) return;
189
+ if (props.onClick) {
190
+ props.onClick(e);
191
+ if (e.defaultPrevented) return;
192
+ }
193
+ const value = clone(array?.field?.value[index]);
194
+ const distIndex = index + 1;
195
+ array.field?.insert?.(distIndex, value);
196
+ array.props?.onCopy?.(distIndex);
197
+ }}
198
+ icon={isUndef(props.icon) ? <CopyOutlined /> : props.icon}
199
+ >
200
+ {props.title || self.title}
201
+ </Button>
202
+ );
203
+ });
204
+
205
+ ArrayBase.Remove = React.forwardRef((props, ref) => {
206
+ const index = useIndex(props.index);
207
+ const self = useField();
208
+ const array = useArray();
209
+ const prefixCls = usePrefixCls("formily-array-base");
210
+ if (!array) return null;
211
+ if (array.field?.pattern !== "editable") return null;
212
+
213
+ return (
214
+ <>
215
+ {array.props?.deletePopconfirm && !self?.disabled ? (
216
+ <Popconfirm
217
+ {...array.props}
218
+ title={array.props?.deletePopconfirmTitle() || null}
219
+ onConfirm={() => {
220
+ if (self?.disabled) return;
221
+ array.field?.remove?.(index);
222
+ array.props?.onRemove?.(index);
223
+ }}
224
+ >
225
+ <Button
226
+ type="text"
227
+ {...props}
228
+ disabled={self?.disabled}
229
+ className={cls(
230
+ `${prefixCls}-remove`,
231
+ self?.disabled ? `${prefixCls}-remove-disabled` : "",
232
+ props.className,
233
+ )}
234
+ ref={ref}
235
+ icon={isUndef(props.icon) ? <DeleteOutlined /> : props.icon}
236
+ >
237
+ {props.title || self.title}
238
+ </Button>
239
+ </Popconfirm>
240
+ ) : (
241
+ <Button
242
+ type="text"
243
+ {...props}
244
+ disabled={self?.disabled}
245
+ className={cls(`${prefixCls}-remove`, self?.disabled ? `${prefixCls}-remove-disabled` : "", props.className)}
246
+ ref={ref}
247
+ onClick={(e) => {
248
+ if (self?.disabled) return;
249
+ e.stopPropagation();
250
+ if (props.onClick) {
251
+ props.onClick(e);
252
+ if (e.defaultPrevented) return;
253
+ }
254
+ array.field?.remove?.(index);
255
+ array.props?.onRemove?.(index);
256
+ }}
257
+ icon={isUndef(props.icon) ? <DeleteOutlined /> : props.icon}
258
+ >
259
+ {props.title || self.title}
260
+ </Button>
261
+ )}
262
+ </>
263
+ );
264
+ });
265
+
266
+ ArrayBase.MoveDown = React.forwardRef((props, ref) => {
267
+ const index = useIndex(props.index);
268
+ const self = useField();
269
+ const array = useArray();
270
+ const prefixCls = usePrefixCls("formily-array-base");
271
+ if (!array) return null;
272
+ if (array.field?.pattern !== "editable") return null;
273
+ return (
274
+ <Button
275
+ type="text"
276
+ {...props}
277
+ disabled={self?.disabled}
278
+ className={cls(
279
+ `${prefixCls}-move-down`,
280
+ self?.disabled ? `${prefixCls}-move-down-disabled` : "",
281
+ props.className,
282
+ )}
283
+ ref={ref}
284
+ onClick={(e) => {
285
+ if (self?.disabled) return;
286
+ e.stopPropagation();
287
+ if (props.onClick) {
288
+ props.onClick(e);
289
+ if (e.defaultPrevented) return;
290
+ }
291
+ array.field?.moveDown?.(index);
292
+ array.props?.onMoveDown?.(index);
293
+ }}
294
+ icon={isUndef(props.icon) ? <DownOutlined /> : props.icon}
295
+ >
296
+ {props.title || self.title}
297
+ </Button>
298
+ );
299
+ });
300
+
301
+ ArrayBase.MoveUp = React.forwardRef((props, ref) => {
302
+ const index = useIndex(props.index);
303
+ const self = useField();
304
+ const array = useArray();
305
+ const prefixCls = usePrefixCls("formily-array-base");
306
+ if (!array) return null;
307
+ if (array.field?.pattern !== "editable") return null;
308
+ return (
309
+ <Button
310
+ type="text"
311
+ {...props}
312
+ disabled={self?.disabled}
313
+ className={cls(`${prefixCls}-move-up`, self?.disabled ? `${prefixCls}-move-up-disabled` : "", props.className)}
314
+ ref={ref}
315
+ onClick={(e) => {
316
+ if (self?.disabled) return;
317
+ e.stopPropagation();
318
+ if (props.onClick) {
319
+ props.onClick(e);
320
+ if (e.defaultPrevented) return;
321
+ }
322
+ array?.field?.moveUp(index);
323
+ array?.props?.onMoveUp?.(index);
324
+ }}
325
+ icon={isUndef(props.icon) ? <UpOutlined /> : props.icon}
326
+ >
327
+ {props.title || self.title}
328
+ </Button>
329
+ );
330
+ });
331
+
332
+ ArrayBase.useArray = useArray;
333
+ ArrayBase.useIndex = useIndex;
334
+ ArrayBase.useRecord = useRecord;
335
+ ArrayBase.mixin = (target: any) => {
336
+ target.Index = ArrayBase.Index;
337
+ target.SortHandle = ArrayBase.SortHandle;
338
+ target.Addition = ArrayBase.Addition;
339
+ target.Copy = ArrayBase.Copy;
340
+ target.Remove = ArrayBase.Remove;
341
+ target.MoveDown = ArrayBase.MoveDown;
342
+ target.MoveUp = ArrayBase.MoveUp;
343
+ target.useArray = ArrayBase.useArray;
344
+ target.useIndex = ArrayBase.useIndex;
345
+ target.useRecord = ArrayBase.useRecord;
346
+ return target;
347
+ };
348
+
349
+ export default ArrayBase;