@nokecy/qc-ui 0.1.54 → 0.2.1

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.
@@ -58,13 +58,15 @@ var ArrayAddBtn = function ArrayAddBtn(props) {
58
58
  var defaultValue = getDefaultValue(props.defaultValue, schema);
59
59
 
60
60
  if (props.method === "unshift") {
61
- var _arrayField$unshift;
61
+ var _arrayField$unshift, _props$onAdd;
62
62
 
63
- (_arrayField$unshift = arrayField.unshift) === null || _arrayField$unshift === void 0 ? void 0 : _arrayField$unshift.call(arrayField, defaultValue); // array.props?.onAdd?.(0);
63
+ (_arrayField$unshift = arrayField.unshift) === null || _arrayField$unshift === void 0 ? void 0 : _arrayField$unshift.call(arrayField, defaultValue);
64
+ props === null || props === void 0 ? void 0 : (_props$onAdd = props.onAdd) === null || _props$onAdd === void 0 ? void 0 : _props$onAdd.call(props, 0);
64
65
  } else {
65
- var _arrayField$push;
66
+ var _arrayField$push, _props$onAdd2, _arrayField$value;
66
67
 
67
- (_arrayField$push = arrayField.push) === null || _arrayField$push === void 0 ? void 0 : _arrayField$push.call(arrayField, defaultValue); // array.props?.onAdd?.(arrayField?.value?.length - 1);
68
+ (_arrayField$push = arrayField.push) === null || _arrayField$push === void 0 ? void 0 : _arrayField$push.call(arrayField, defaultValue);
69
+ props === null || props === void 0 ? void 0 : (_props$onAdd2 = props.onAdd) === null || _props$onAdd2 === void 0 ? void 0 : _props$onAdd2.call(props, (arrayField === null || arrayField === void 0 ? void 0 : (_arrayField$value = arrayField.value) === null || _arrayField$value === void 0 ? void 0 : _arrayField$value.length) - 1);
68
70
  }
69
71
 
70
72
  if (props.onClick) {
@@ -44,7 +44,7 @@ export declare type ArrayBaseMixins = {
44
44
  Index?: React.FC;
45
45
  useArray?: () => IArrayBaseContext;
46
46
  useIndex: (index?: number) => number;
47
- useRecord?: (record?: number) => any;
47
+ useRecord: (record?: number) => any;
48
48
  };
49
49
  export interface IArrayBaseProps {
50
50
  disabled?: boolean;
@@ -55,24 +55,6 @@ var useRecord = function useRecord(record) {
55
55
  return takeRecord(ctx ? ctx.record : record, ctx === null || ctx === void 0 ? void 0 : ctx.index);
56
56
  };
57
57
 
58
- var getSchemaDefaultValue = function getSchemaDefaultValue(schema) {
59
- if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'array') return [];
60
- if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'object') return {};
61
-
62
- if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'void') {
63
- for (var key in schema.properties) {
64
- var value = getSchemaDefaultValue(schema.properties[key]);
65
- if ((0, _shared.isValid)(value)) return value;
66
- }
67
- }
68
- };
69
-
70
- var getDefaultValue = function getDefaultValue(defaultValue, schema) {
71
- if ((0, _shared.isValid)(defaultValue)) return (0, _shared.clone)(defaultValue);
72
- if (Array.isArray(schema === null || schema === void 0 ? void 0 : schema.items)) return getSchemaDefaultValue(schema === null || schema === void 0 ? void 0 : schema.items[0]);
73
- return getSchemaDefaultValue(schema === null || schema === void 0 ? void 0 : schema.items);
74
- };
75
-
76
58
  var ArrayBase = function ArrayBase(props) {
77
59
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, props.children);
78
60
  };
@@ -96,56 +78,15 @@ ArrayBase.Index = function (props) {
96
78
  }), "#", (index ? index : 0) + 1, ".");
97
79
  };
98
80
 
99
- ArrayBase.Addition = function (props) {
100
- var _array$field, _array$field2;
101
-
102
- var self = (0, _react2.useField)();
103
- var array = useArray();
104
- var prefixCls = (0, _builtins__.usePrefixCls)('formily-array-base');
105
- if (!array) return null;
106
- if (((_array$field = array.field) === null || _array$field === void 0 ? void 0 : _array$field.pattern) !== 'editable' && ((_array$field2 = array.field) === null || _array$field2 === void 0 ? void 0 : _array$field2.pattern) !== 'disabled') return null;
107
- return /*#__PURE__*/_react.default.createElement(_antd.Button, _extends({
108
- type: "dashed",
109
- block: true
110
- }, props, {
111
- disabled: self === null || self === void 0 ? void 0 : self.disabled,
112
- className: (0, _classnames.default)("".concat(prefixCls, "-addition"), props.className),
113
- onClick: function onClick(e) {
114
- var _array$props;
115
-
116
- if ((_array$props = array.props) !== null && _array$props !== void 0 && _array$props.disabled) return;
117
- var defaultValue = getDefaultValue(props.defaultValue, array.schema);
118
-
119
- if (props.method === 'unshift') {
120
- var _array$field3, _array$field3$unshift, _array$props2, _array$props2$onAdd;
121
-
122
- (_array$field3 = array.field) === null || _array$field3 === void 0 ? void 0 : (_array$field3$unshift = _array$field3.unshift) === null || _array$field3$unshift === void 0 ? void 0 : _array$field3$unshift.call(_array$field3, defaultValue);
123
- (_array$props2 = array.props) === null || _array$props2 === void 0 ? void 0 : (_array$props2$onAdd = _array$props2.onAdd) === null || _array$props2$onAdd === void 0 ? void 0 : _array$props2$onAdd.call(_array$props2, 0);
124
- } else {
125
- var _array$field4, _array$field4$push, _array$props3, _array$props3$onAdd, _array$field5, _array$field5$value;
126
-
127
- (_array$field4 = array.field) === null || _array$field4 === void 0 ? void 0 : (_array$field4$push = _array$field4.push) === null || _array$field4$push === void 0 ? void 0 : _array$field4$push.call(_array$field4, defaultValue);
128
- (_array$props3 = array.props) === null || _array$props3 === void 0 ? void 0 : (_array$props3$onAdd = _array$props3.onAdd) === null || _array$props3$onAdd === void 0 ? void 0 : _array$props3$onAdd.call(_array$props3, (array === null || array === void 0 ? void 0 : (_array$field5 = array.field) === null || _array$field5 === void 0 ? void 0 : (_array$field5$value = _array$field5.value) === null || _array$field5$value === void 0 ? void 0 : _array$field5$value.length) - 1);
129
- }
130
-
131
- if (props.onClick) {
132
- //@ts-ignore
133
- props.onClick(e);
134
- }
135
- },
136
- icon: (0, _shared.isUndef)(props.icon) ? /*#__PURE__*/_react.default.createElement(_icons.PlusOutlined, null) : props.icon
137
- }), props.title || self.title);
138
- };
139
-
140
81
  ArrayBase.Copy = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
141
- var _array$field6;
82
+ var _array$field;
142
83
 
143
84
  var self = (0, _react2.useField)();
144
85
  var array = useArray();
145
86
  var index = useIndex(props.index);
146
87
  var prefixCls = (0, _builtins__.usePrefixCls)('formily-array-base');
147
88
  if (!array) return null;
148
- if (((_array$field6 = array.field) === null || _array$field6 === void 0 ? void 0 : _array$field6.pattern) !== 'editable') return null;
89
+ if (((_array$field = array.field) === null || _array$field === void 0 ? void 0 : _array$field.pattern) !== 'editable') return null;
149
90
  return /*#__PURE__*/_react.default.createElement(_antd.Button, _extends({
150
91
  type: "text"
151
92
  }, props, {
@@ -153,15 +94,15 @@ ArrayBase.Copy = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
153
94
  className: (0, _classnames.default)("".concat(prefixCls, "-copy"), self !== null && self !== void 0 && self.disabled ? "".concat(prefixCls, "-copy-disabled") : '', props.className),
154
95
  ref: ref,
155
96
  onClick: function onClick(e) {
156
- var _array$props4, _array$field7, _array$field8, _array$field8$insert, _array$props5, _array$props5$onCopy;
97
+ var _array$props, _array$field2, _array$field3, _array$field3$insert, _array$props2, _array$props2$onCopy;
157
98
 
158
99
  if (self !== null && self !== void 0 && self.disabled) return;
159
100
  e.stopPropagation();
160
- if ((_array$props4 = array.props) !== null && _array$props4 !== void 0 && _array$props4.disabled) return;
161
- var value = (0, _shared.clone)(array === null || array === void 0 ? void 0 : (_array$field7 = array.field) === null || _array$field7 === void 0 ? void 0 : _array$field7.value[index]);
101
+ if ((_array$props = array.props) !== null && _array$props !== void 0 && _array$props.disabled) return;
102
+ var value = (0, _shared.clone)(array === null || array === void 0 ? void 0 : (_array$field2 = array.field) === null || _array$field2 === void 0 ? void 0 : _array$field2.value[index]);
162
103
  var distIndex = index + 1;
163
- (_array$field8 = array.field) === null || _array$field8 === void 0 ? void 0 : (_array$field8$insert = _array$field8.insert) === null || _array$field8$insert === void 0 ? void 0 : _array$field8$insert.call(_array$field8, distIndex, value);
164
- (_array$props5 = array.props) === null || _array$props5 === void 0 ? void 0 : (_array$props5$onCopy = _array$props5.onCopy) === null || _array$props5$onCopy === void 0 ? void 0 : _array$props5$onCopy.call(_array$props5, distIndex);
104
+ (_array$field3 = array.field) === null || _array$field3 === void 0 ? void 0 : (_array$field3$insert = _array$field3.insert) === null || _array$field3$insert === void 0 ? void 0 : _array$field3$insert.call(_array$field3, distIndex, value);
105
+ (_array$props2 = array.props) === null || _array$props2 === void 0 ? void 0 : (_array$props2$onCopy = _array$props2.onCopy) === null || _array$props2$onCopy === void 0 ? void 0 : _array$props2$onCopy.call(_array$props2, distIndex);
165
106
 
166
107
  if (props.onClick) {
167
108
  //@ts-ignore
@@ -172,14 +113,14 @@ ArrayBase.Copy = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
172
113
  }), props.title || self.title);
173
114
  });
174
115
  ArrayBase.Remove = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
175
- var _array$field9;
116
+ var _array$field4;
176
117
 
177
118
  var index = useIndex(props.index);
178
119
  var self = (0, _react2.useField)();
179
120
  var array = useArray();
180
121
  var prefixCls = (0, _builtins__.usePrefixCls)('formily-array-base');
181
122
  if (!array) return null;
182
- if (((_array$field9 = array.field) === null || _array$field9 === void 0 ? void 0 : _array$field9.pattern) !== 'editable') return null;
123
+ if (((_array$field4 = array.field) === null || _array$field4 === void 0 ? void 0 : _array$field4.pattern) !== 'editable') return null;
183
124
  return /*#__PURE__*/_react.default.createElement(_antd.Button, _extends({
184
125
  type: "text"
185
126
  }, props, {
@@ -187,12 +128,12 @@ ArrayBase.Remove = /*#__PURE__*/_react.default.forwardRef(function (props, ref)
187
128
  className: (0, _classnames.default)("".concat(prefixCls, "-remove"), self !== null && self !== void 0 && self.disabled ? "".concat(prefixCls, "-remove-disabled") : '', props.className),
188
129
  ref: ref,
189
130
  onClick: function onClick(e) {
190
- var _array$field10, _array$field10$remove, _array$props6, _array$props6$onRemov;
131
+ var _array$field5, _array$field5$remove, _array$props3, _array$props3$onRemov;
191
132
 
192
133
  if (self !== null && self !== void 0 && self.disabled) return;
193
134
  e.stopPropagation();
194
- (_array$field10 = array.field) === null || _array$field10 === void 0 ? void 0 : (_array$field10$remove = _array$field10.remove) === null || _array$field10$remove === void 0 ? void 0 : _array$field10$remove.call(_array$field10, index);
195
- (_array$props6 = array.props) === null || _array$props6 === void 0 ? void 0 : (_array$props6$onRemov = _array$props6.onRemove) === null || _array$props6$onRemov === void 0 ? void 0 : _array$props6$onRemov.call(_array$props6, index);
135
+ (_array$field5 = array.field) === null || _array$field5 === void 0 ? void 0 : (_array$field5$remove = _array$field5.remove) === null || _array$field5$remove === void 0 ? void 0 : _array$field5$remove.call(_array$field5, index);
136
+ (_array$props3 = array.props) === null || _array$props3 === void 0 ? void 0 : (_array$props3$onRemov = _array$props3.onRemove) === null || _array$props3$onRemov === void 0 ? void 0 : _array$props3$onRemov.call(_array$props3, index);
196
137
 
197
138
  if (props.onClick) {
198
139
  //@ts-ignore
@@ -203,14 +144,14 @@ ArrayBase.Remove = /*#__PURE__*/_react.default.forwardRef(function (props, ref)
203
144
  }), props.title || self.title);
204
145
  });
205
146
  ArrayBase.MoveDown = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
206
- var _array$field11;
147
+ var _array$field6;
207
148
 
208
149
  var index = useIndex(props.index);
209
150
  var self = (0, _react2.useField)();
210
151
  var array = useArray();
211
152
  var prefixCls = (0, _builtins__.usePrefixCls)('formily-array-base');
212
153
  if (!array) return null;
213
- if (((_array$field11 = array.field) === null || _array$field11 === void 0 ? void 0 : _array$field11.pattern) !== 'editable') return null;
154
+ if (((_array$field6 = array.field) === null || _array$field6 === void 0 ? void 0 : _array$field6.pattern) !== 'editable') return null;
214
155
  return /*#__PURE__*/_react.default.createElement(_antd.Button, _extends({
215
156
  type: "text"
216
157
  }, props, {
@@ -218,12 +159,12 @@ ArrayBase.MoveDown = /*#__PURE__*/_react.default.forwardRef(function (props, ref
218
159
  className: (0, _classnames.default)("".concat(prefixCls, "-move-down"), self !== null && self !== void 0 && self.disabled ? "".concat(prefixCls, "-move-down-disabled") : '', props.className),
219
160
  ref: ref,
220
161
  onClick: function onClick(e) {
221
- var _array$field12, _array$field12$moveDo, _array$props7, _array$props7$onMoveD;
162
+ var _array$field7, _array$field7$moveDow, _array$props4, _array$props4$onMoveD;
222
163
 
223
164
  if (self !== null && self !== void 0 && self.disabled) return;
224
165
  e.stopPropagation();
225
- (_array$field12 = array.field) === null || _array$field12 === void 0 ? void 0 : (_array$field12$moveDo = _array$field12.moveDown) === null || _array$field12$moveDo === void 0 ? void 0 : _array$field12$moveDo.call(_array$field12, index);
226
- (_array$props7 = array.props) === null || _array$props7 === void 0 ? void 0 : (_array$props7$onMoveD = _array$props7.onMoveDown) === null || _array$props7$onMoveD === void 0 ? void 0 : _array$props7$onMoveD.call(_array$props7, index);
166
+ (_array$field7 = array.field) === null || _array$field7 === void 0 ? void 0 : (_array$field7$moveDow = _array$field7.moveDown) === null || _array$field7$moveDow === void 0 ? void 0 : _array$field7$moveDow.call(_array$field7, index);
167
+ (_array$props4 = array.props) === null || _array$props4 === void 0 ? void 0 : (_array$props4$onMoveD = _array$props4.onMoveDown) === null || _array$props4$onMoveD === void 0 ? void 0 : _array$props4$onMoveD.call(_array$props4, index);
227
168
 
228
169
  if (props.onClick) {
229
170
  //@ts-ignore
@@ -234,14 +175,14 @@ ArrayBase.MoveDown = /*#__PURE__*/_react.default.forwardRef(function (props, ref
234
175
  }), props.title || self.title);
235
176
  });
236
177
  ArrayBase.MoveUp = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
237
- var _array$field13;
178
+ var _array$field8;
238
179
 
239
180
  var index = useIndex(props.index);
240
181
  var self = (0, _react2.useField)();
241
182
  var array = useArray();
242
183
  var prefixCls = (0, _builtins__.usePrefixCls)('formily-array-base');
243
184
  if (!array) return null;
244
- if (((_array$field13 = array.field) === null || _array$field13 === void 0 ? void 0 : _array$field13.pattern) !== 'editable') return null;
185
+ if (((_array$field8 = array.field) === null || _array$field8 === void 0 ? void 0 : _array$field8.pattern) !== 'editable') return null;
245
186
  return /*#__PURE__*/_react.default.createElement(_antd.Button, _extends({
246
187
  type: "text"
247
188
  }, props, {
@@ -249,12 +190,12 @@ ArrayBase.MoveUp = /*#__PURE__*/_react.default.forwardRef(function (props, ref)
249
190
  className: (0, _classnames.default)("".concat(prefixCls, "-move-up"), self !== null && self !== void 0 && self.disabled ? "".concat(prefixCls, "-move-up-disabled") : '', props.className),
250
191
  ref: ref,
251
192
  onClick: function onClick(e) {
252
- var _array$field14, _array$props8, _array$props8$onMoveU;
193
+ var _array$field9, _array$props5, _array$props5$onMoveU;
253
194
 
254
195
  if (self !== null && self !== void 0 && self.disabled) return;
255
196
  e.stopPropagation();
256
- array === null || array === void 0 ? void 0 : (_array$field14 = array.field) === null || _array$field14 === void 0 ? void 0 : _array$field14.moveUp(index);
257
- array === null || array === void 0 ? void 0 : (_array$props8 = array.props) === null || _array$props8 === void 0 ? void 0 : (_array$props8$onMoveU = _array$props8.onMoveUp) === null || _array$props8$onMoveU === void 0 ? void 0 : _array$props8$onMoveU.call(_array$props8, index);
197
+ array === null || array === void 0 ? void 0 : (_array$field9 = array.field) === null || _array$field9 === void 0 ? void 0 : _array$field9.moveUp(index);
198
+ array === null || array === void 0 ? void 0 : (_array$props5 = array.props) === null || _array$props5 === void 0 ? void 0 : (_array$props5$onMoveU = _array$props5.onMoveUp) === null || _array$props5$onMoveU === void 0 ? void 0 : _array$props5$onMoveU.call(_array$props5, index);
258
199
 
259
200
  if (props.onClick) {
260
201
  //@ts-ignore
@@ -59,12 +59,7 @@ var ArrayTable = (0, _react2.observer)(function (props) {
59
59
  var sources = (0, _utils.useArrayTableSources)();
60
60
  var columns = (0, _utils.useArrayTableColumns)(dataSource, field, sources);
61
61
  var schema = (0, _react2.useFieldSchema)();
62
- return /*#__PURE__*/_react.default.createElement("div", {
63
- ref: ref,
64
- style: {
65
- height: height ? height : 400
66
- }
67
- }, /*#__PURE__*/_react.default.createElement(_arrayBase.default, null, /*#__PURE__*/_react.default.createElement(_antd.Space, {
62
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_antd.Space, {
68
63
  style: {
69
64
  marginBottom: 5
70
65
  }
@@ -75,8 +70,16 @@ var ArrayTable = (0, _react2.observer)(function (props) {
75
70
  _id: (0, _uniqueId.default)(),
76
71
  _isNew: true
77
72
  },
78
- title: "新增"
79
- })), /*#__PURE__*/_react.default.createElement(_agGridReact.AgGridReact, {
73
+ title: "新增",
74
+ onAdd: function onAdd() {
75
+ setIsAdd(true);
76
+ }
77
+ })), /*#__PURE__*/_react.default.createElement("div", {
78
+ ref: ref,
79
+ style: {
80
+ height: height ? height : 400
81
+ }
82
+ }, /*#__PURE__*/_react.default.createElement(_arrayBase.default, null, /*#__PURE__*/_react.default.createElement(_agGridReact.AgGridReact, {
80
83
  onGridReady: function onGridReady(params) {
81
84
  apiRef.current = params.api;
82
85
  },
@@ -133,7 +136,7 @@ var ArrayTable = (0, _react2.observer)(function (props) {
133
136
  onlyRenderSelf: true,
134
137
  key: key
135
138
  });
136
- })));
139
+ }))));
137
140
  });
138
141
  exports.ArrayTable = ArrayTable;
139
142
  ArrayTable.displayName = "ArrayTable";
@@ -19,6 +19,8 @@ var _classnames = _interopRequireDefault(require("classnames"));
19
19
 
20
20
  var _antdV = require("@formily/antd-v5");
21
21
 
22
+ var _arrayBase = require("../array-table/arrayBase");
23
+
22
24
  var _react2 = _interopRequireWildcard(require("react"));
23
25
 
24
26
  var _builtins__ = require("@formily/antd-v5/lib/__builtins__");
@@ -61,7 +63,7 @@ var useParentPattern = function useParentPattern() {
61
63
  var useEditable = function useEditable() {
62
64
  var pattern = useParentPattern();
63
65
 
64
- var record = _antdV.ArrayBase.useRecord();
66
+ var record = _arrayBase.ArrayBase.useRecord();
65
67
 
66
68
  var field = (0, _react.useField)(); // useLayoutEffect(() => {
67
69
  // if (pattern === 'editable') {
@@ -43,13 +43,15 @@ var ArrayAddBtn = function ArrayAddBtn(props) {
43
43
  var defaultValue = getDefaultValue(props.defaultValue, schema);
44
44
 
45
45
  if (props.method === "unshift") {
46
- var _arrayField$unshift;
46
+ var _arrayField$unshift, _props$onAdd;
47
47
 
48
- (_arrayField$unshift = arrayField.unshift) === null || _arrayField$unshift === void 0 ? void 0 : _arrayField$unshift.call(arrayField, defaultValue); // array.props?.onAdd?.(0);
48
+ (_arrayField$unshift = arrayField.unshift) === null || _arrayField$unshift === void 0 ? void 0 : _arrayField$unshift.call(arrayField, defaultValue);
49
+ props === null || props === void 0 ? void 0 : (_props$onAdd = props.onAdd) === null || _props$onAdd === void 0 ? void 0 : _props$onAdd.call(props, 0);
49
50
  } else {
50
- var _arrayField$push;
51
+ var _arrayField$push, _props$onAdd2, _arrayField$value;
51
52
 
52
- (_arrayField$push = arrayField.push) === null || _arrayField$push === void 0 ? void 0 : _arrayField$push.call(arrayField, defaultValue); // array.props?.onAdd?.(arrayField?.value?.length - 1);
53
+ (_arrayField$push = arrayField.push) === null || _arrayField$push === void 0 ? void 0 : _arrayField$push.call(arrayField, defaultValue);
54
+ props === null || props === void 0 ? void 0 : (_props$onAdd2 = props.onAdd) === null || _props$onAdd2 === void 0 ? void 0 : _props$onAdd2.call(props, (arrayField === null || arrayField === void 0 ? void 0 : (_arrayField$value = arrayField.value) === null || _arrayField$value === void 0 ? void 0 : _arrayField$value.length) - 1);
53
55
  }
54
56
 
55
57
  if (props.onClick) {
@@ -44,7 +44,7 @@ export declare type ArrayBaseMixins = {
44
44
  Index?: React.FC;
45
45
  useArray?: () => IArrayBaseContext;
46
46
  useIndex: (index?: number) => number;
47
- useRecord?: (record?: number) => any;
47
+ useRecord: (record?: number) => any;
48
48
  };
49
49
  export interface IArrayBaseProps {
50
50
  disabled?: boolean;
@@ -8,9 +8,9 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
8
8
 
9
9
  import React, { createContext, useContext } from 'react';
10
10
  import { Button } from 'antd';
11
- import { DeleteOutlined, DownOutlined, UpOutlined, PlusOutlined, CopyOutlined } from '@ant-design/icons';
11
+ import { DeleteOutlined, DownOutlined, UpOutlined, CopyOutlined } from '@ant-design/icons';
12
12
  import { useField } from '@formily/react';
13
- import { isValid, clone, isUndef } from '@formily/shared';
13
+ import { clone, isUndef } from '@formily/shared';
14
14
  import { usePrefixCls } from '@formily/antd-v5/lib/__builtins__';
15
15
  import cls from 'classnames';
16
16
  var ItemContext = /*#__PURE__*/createContext(null);
@@ -33,24 +33,6 @@ var useRecord = function useRecord(record) {
33
33
  return takeRecord(ctx ? ctx.record : record, ctx === null || ctx === void 0 ? void 0 : ctx.index);
34
34
  };
35
35
 
36
- var getSchemaDefaultValue = function getSchemaDefaultValue(schema) {
37
- if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'array') return [];
38
- if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'object') return {};
39
-
40
- if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'void') {
41
- for (var key in schema.properties) {
42
- var value = getSchemaDefaultValue(schema.properties[key]);
43
- if (isValid(value)) return value;
44
- }
45
- }
46
- };
47
-
48
- var getDefaultValue = function getDefaultValue(defaultValue, schema) {
49
- if (isValid(defaultValue)) return clone(defaultValue);
50
- if (Array.isArray(schema === null || schema === void 0 ? void 0 : schema.items)) return getSchemaDefaultValue(schema === null || schema === void 0 ? void 0 : schema.items[0]);
51
- return getSchemaDefaultValue(schema === null || schema === void 0 ? void 0 : schema.items);
52
- };
53
-
54
36
  export var ArrayBase = function ArrayBase(props) {
55
37
  return /*#__PURE__*/React.createElement(React.Fragment, null, props.children);
56
38
  };
@@ -72,56 +54,15 @@ ArrayBase.Index = function (props) {
72
54
  }), "#", (index ? index : 0) + 1, ".");
73
55
  };
74
56
 
75
- ArrayBase.Addition = function (props) {
76
- var _array$field, _array$field2;
77
-
78
- var self = useField();
79
- var array = useArray();
80
- var prefixCls = usePrefixCls('formily-array-base');
81
- if (!array) return null;
82
- if (((_array$field = array.field) === null || _array$field === void 0 ? void 0 : _array$field.pattern) !== 'editable' && ((_array$field2 = array.field) === null || _array$field2 === void 0 ? void 0 : _array$field2.pattern) !== 'disabled') return null;
83
- return /*#__PURE__*/React.createElement(Button, _extends({
84
- type: "dashed",
85
- block: true
86
- }, props, {
87
- disabled: self === null || self === void 0 ? void 0 : self.disabled,
88
- className: cls("".concat(prefixCls, "-addition"), props.className),
89
- onClick: function onClick(e) {
90
- var _array$props;
91
-
92
- if ((_array$props = array.props) !== null && _array$props !== void 0 && _array$props.disabled) return;
93
- var defaultValue = getDefaultValue(props.defaultValue, array.schema);
94
-
95
- if (props.method === 'unshift') {
96
- var _array$field3, _array$field3$unshift, _array$props2, _array$props2$onAdd;
97
-
98
- (_array$field3 = array.field) === null || _array$field3 === void 0 ? void 0 : (_array$field3$unshift = _array$field3.unshift) === null || _array$field3$unshift === void 0 ? void 0 : _array$field3$unshift.call(_array$field3, defaultValue);
99
- (_array$props2 = array.props) === null || _array$props2 === void 0 ? void 0 : (_array$props2$onAdd = _array$props2.onAdd) === null || _array$props2$onAdd === void 0 ? void 0 : _array$props2$onAdd.call(_array$props2, 0);
100
- } else {
101
- var _array$field4, _array$field4$push, _array$props3, _array$props3$onAdd, _array$field5, _array$field5$value;
102
-
103
- (_array$field4 = array.field) === null || _array$field4 === void 0 ? void 0 : (_array$field4$push = _array$field4.push) === null || _array$field4$push === void 0 ? void 0 : _array$field4$push.call(_array$field4, defaultValue);
104
- (_array$props3 = array.props) === null || _array$props3 === void 0 ? void 0 : (_array$props3$onAdd = _array$props3.onAdd) === null || _array$props3$onAdd === void 0 ? void 0 : _array$props3$onAdd.call(_array$props3, (array === null || array === void 0 ? void 0 : (_array$field5 = array.field) === null || _array$field5 === void 0 ? void 0 : (_array$field5$value = _array$field5.value) === null || _array$field5$value === void 0 ? void 0 : _array$field5$value.length) - 1);
105
- }
106
-
107
- if (props.onClick) {
108
- //@ts-ignore
109
- props.onClick(e);
110
- }
111
- },
112
- icon: isUndef(props.icon) ? /*#__PURE__*/React.createElement(PlusOutlined, null) : props.icon
113
- }), props.title || self.title);
114
- };
115
-
116
57
  ArrayBase.Copy = /*#__PURE__*/React.forwardRef(function (props, ref) {
117
- var _array$field6;
58
+ var _array$field;
118
59
 
119
60
  var self = useField();
120
61
  var array = useArray();
121
62
  var index = useIndex(props.index);
122
63
  var prefixCls = usePrefixCls('formily-array-base');
123
64
  if (!array) return null;
124
- if (((_array$field6 = array.field) === null || _array$field6 === void 0 ? void 0 : _array$field6.pattern) !== 'editable') return null;
65
+ if (((_array$field = array.field) === null || _array$field === void 0 ? void 0 : _array$field.pattern) !== 'editable') return null;
125
66
  return /*#__PURE__*/React.createElement(Button, _extends({
126
67
  type: "text"
127
68
  }, props, {
@@ -129,15 +70,15 @@ ArrayBase.Copy = /*#__PURE__*/React.forwardRef(function (props, ref) {
129
70
  className: cls("".concat(prefixCls, "-copy"), self !== null && self !== void 0 && self.disabled ? "".concat(prefixCls, "-copy-disabled") : '', props.className),
130
71
  ref: ref,
131
72
  onClick: function onClick(e) {
132
- var _array$props4, _array$field7, _array$field8, _array$field8$insert, _array$props5, _array$props5$onCopy;
73
+ var _array$props, _array$field2, _array$field3, _array$field3$insert, _array$props2, _array$props2$onCopy;
133
74
 
134
75
  if (self !== null && self !== void 0 && self.disabled) return;
135
76
  e.stopPropagation();
136
- if ((_array$props4 = array.props) !== null && _array$props4 !== void 0 && _array$props4.disabled) return;
137
- var value = clone(array === null || array === void 0 ? void 0 : (_array$field7 = array.field) === null || _array$field7 === void 0 ? void 0 : _array$field7.value[index]);
77
+ if ((_array$props = array.props) !== null && _array$props !== void 0 && _array$props.disabled) return;
78
+ var value = clone(array === null || array === void 0 ? void 0 : (_array$field2 = array.field) === null || _array$field2 === void 0 ? void 0 : _array$field2.value[index]);
138
79
  var distIndex = index + 1;
139
- (_array$field8 = array.field) === null || _array$field8 === void 0 ? void 0 : (_array$field8$insert = _array$field8.insert) === null || _array$field8$insert === void 0 ? void 0 : _array$field8$insert.call(_array$field8, distIndex, value);
140
- (_array$props5 = array.props) === null || _array$props5 === void 0 ? void 0 : (_array$props5$onCopy = _array$props5.onCopy) === null || _array$props5$onCopy === void 0 ? void 0 : _array$props5$onCopy.call(_array$props5, distIndex);
80
+ (_array$field3 = array.field) === null || _array$field3 === void 0 ? void 0 : (_array$field3$insert = _array$field3.insert) === null || _array$field3$insert === void 0 ? void 0 : _array$field3$insert.call(_array$field3, distIndex, value);
81
+ (_array$props2 = array.props) === null || _array$props2 === void 0 ? void 0 : (_array$props2$onCopy = _array$props2.onCopy) === null || _array$props2$onCopy === void 0 ? void 0 : _array$props2$onCopy.call(_array$props2, distIndex);
141
82
 
142
83
  if (props.onClick) {
143
84
  //@ts-ignore
@@ -148,14 +89,14 @@ ArrayBase.Copy = /*#__PURE__*/React.forwardRef(function (props, ref) {
148
89
  }), props.title || self.title);
149
90
  });
150
91
  ArrayBase.Remove = /*#__PURE__*/React.forwardRef(function (props, ref) {
151
- var _array$field9;
92
+ var _array$field4;
152
93
 
153
94
  var index = useIndex(props.index);
154
95
  var self = useField();
155
96
  var array = useArray();
156
97
  var prefixCls = usePrefixCls('formily-array-base');
157
98
  if (!array) return null;
158
- if (((_array$field9 = array.field) === null || _array$field9 === void 0 ? void 0 : _array$field9.pattern) !== 'editable') return null;
99
+ if (((_array$field4 = array.field) === null || _array$field4 === void 0 ? void 0 : _array$field4.pattern) !== 'editable') return null;
159
100
  return /*#__PURE__*/React.createElement(Button, _extends({
160
101
  type: "text"
161
102
  }, props, {
@@ -163,12 +104,12 @@ ArrayBase.Remove = /*#__PURE__*/React.forwardRef(function (props, ref) {
163
104
  className: cls("".concat(prefixCls, "-remove"), self !== null && self !== void 0 && self.disabled ? "".concat(prefixCls, "-remove-disabled") : '', props.className),
164
105
  ref: ref,
165
106
  onClick: function onClick(e) {
166
- var _array$field10, _array$field10$remove, _array$props6, _array$props6$onRemov;
107
+ var _array$field5, _array$field5$remove, _array$props3, _array$props3$onRemov;
167
108
 
168
109
  if (self !== null && self !== void 0 && self.disabled) return;
169
110
  e.stopPropagation();
170
- (_array$field10 = array.field) === null || _array$field10 === void 0 ? void 0 : (_array$field10$remove = _array$field10.remove) === null || _array$field10$remove === void 0 ? void 0 : _array$field10$remove.call(_array$field10, index);
171
- (_array$props6 = array.props) === null || _array$props6 === void 0 ? void 0 : (_array$props6$onRemov = _array$props6.onRemove) === null || _array$props6$onRemov === void 0 ? void 0 : _array$props6$onRemov.call(_array$props6, index);
111
+ (_array$field5 = array.field) === null || _array$field5 === void 0 ? void 0 : (_array$field5$remove = _array$field5.remove) === null || _array$field5$remove === void 0 ? void 0 : _array$field5$remove.call(_array$field5, index);
112
+ (_array$props3 = array.props) === null || _array$props3 === void 0 ? void 0 : (_array$props3$onRemov = _array$props3.onRemove) === null || _array$props3$onRemov === void 0 ? void 0 : _array$props3$onRemov.call(_array$props3, index);
172
113
 
173
114
  if (props.onClick) {
174
115
  //@ts-ignore
@@ -179,14 +120,14 @@ ArrayBase.Remove = /*#__PURE__*/React.forwardRef(function (props, ref) {
179
120
  }), props.title || self.title);
180
121
  });
181
122
  ArrayBase.MoveDown = /*#__PURE__*/React.forwardRef(function (props, ref) {
182
- var _array$field11;
123
+ var _array$field6;
183
124
 
184
125
  var index = useIndex(props.index);
185
126
  var self = useField();
186
127
  var array = useArray();
187
128
  var prefixCls = usePrefixCls('formily-array-base');
188
129
  if (!array) return null;
189
- if (((_array$field11 = array.field) === null || _array$field11 === void 0 ? void 0 : _array$field11.pattern) !== 'editable') return null;
130
+ if (((_array$field6 = array.field) === null || _array$field6 === void 0 ? void 0 : _array$field6.pattern) !== 'editable') return null;
190
131
  return /*#__PURE__*/React.createElement(Button, _extends({
191
132
  type: "text"
192
133
  }, props, {
@@ -194,12 +135,12 @@ ArrayBase.MoveDown = /*#__PURE__*/React.forwardRef(function (props, ref) {
194
135
  className: cls("".concat(prefixCls, "-move-down"), self !== null && self !== void 0 && self.disabled ? "".concat(prefixCls, "-move-down-disabled") : '', props.className),
195
136
  ref: ref,
196
137
  onClick: function onClick(e) {
197
- var _array$field12, _array$field12$moveDo, _array$props7, _array$props7$onMoveD;
138
+ var _array$field7, _array$field7$moveDow, _array$props4, _array$props4$onMoveD;
198
139
 
199
140
  if (self !== null && self !== void 0 && self.disabled) return;
200
141
  e.stopPropagation();
201
- (_array$field12 = array.field) === null || _array$field12 === void 0 ? void 0 : (_array$field12$moveDo = _array$field12.moveDown) === null || _array$field12$moveDo === void 0 ? void 0 : _array$field12$moveDo.call(_array$field12, index);
202
- (_array$props7 = array.props) === null || _array$props7 === void 0 ? void 0 : (_array$props7$onMoveD = _array$props7.onMoveDown) === null || _array$props7$onMoveD === void 0 ? void 0 : _array$props7$onMoveD.call(_array$props7, index);
142
+ (_array$field7 = array.field) === null || _array$field7 === void 0 ? void 0 : (_array$field7$moveDow = _array$field7.moveDown) === null || _array$field7$moveDow === void 0 ? void 0 : _array$field7$moveDow.call(_array$field7, index);
143
+ (_array$props4 = array.props) === null || _array$props4 === void 0 ? void 0 : (_array$props4$onMoveD = _array$props4.onMoveDown) === null || _array$props4$onMoveD === void 0 ? void 0 : _array$props4$onMoveD.call(_array$props4, index);
203
144
 
204
145
  if (props.onClick) {
205
146
  //@ts-ignore
@@ -210,14 +151,14 @@ ArrayBase.MoveDown = /*#__PURE__*/React.forwardRef(function (props, ref) {
210
151
  }), props.title || self.title);
211
152
  });
212
153
  ArrayBase.MoveUp = /*#__PURE__*/React.forwardRef(function (props, ref) {
213
- var _array$field13;
154
+ var _array$field8;
214
155
 
215
156
  var index = useIndex(props.index);
216
157
  var self = useField();
217
158
  var array = useArray();
218
159
  var prefixCls = usePrefixCls('formily-array-base');
219
160
  if (!array) return null;
220
- if (((_array$field13 = array.field) === null || _array$field13 === void 0 ? void 0 : _array$field13.pattern) !== 'editable') return null;
161
+ if (((_array$field8 = array.field) === null || _array$field8 === void 0 ? void 0 : _array$field8.pattern) !== 'editable') return null;
221
162
  return /*#__PURE__*/React.createElement(Button, _extends({
222
163
  type: "text"
223
164
  }, props, {
@@ -225,12 +166,12 @@ ArrayBase.MoveUp = /*#__PURE__*/React.forwardRef(function (props, ref) {
225
166
  className: cls("".concat(prefixCls, "-move-up"), self !== null && self !== void 0 && self.disabled ? "".concat(prefixCls, "-move-up-disabled") : '', props.className),
226
167
  ref: ref,
227
168
  onClick: function onClick(e) {
228
- var _array$field14, _array$props8, _array$props8$onMoveU;
169
+ var _array$field9, _array$props5, _array$props5$onMoveU;
229
170
 
230
171
  if (self !== null && self !== void 0 && self.disabled) return;
231
172
  e.stopPropagation();
232
- array === null || array === void 0 ? void 0 : (_array$field14 = array.field) === null || _array$field14 === void 0 ? void 0 : _array$field14.moveUp(index);
233
- array === null || array === void 0 ? void 0 : (_array$props8 = array.props) === null || _array$props8 === void 0 ? void 0 : (_array$props8$onMoveU = _array$props8.onMoveUp) === null || _array$props8$onMoveU === void 0 ? void 0 : _array$props8$onMoveU.call(_array$props8, index);
173
+ array === null || array === void 0 ? void 0 : (_array$field9 = array.field) === null || _array$field9 === void 0 ? void 0 : _array$field9.moveUp(index);
174
+ array === null || array === void 0 ? void 0 : (_array$props5 = array.props) === null || _array$props5 === void 0 ? void 0 : (_array$props5$onMoveU = _array$props5.onMoveUp) === null || _array$props5$onMoveU === void 0 ? void 0 : _array$props5$onMoveU.call(_array$props5, index);
234
175
 
235
176
  if (props.onClick) {
236
177
  //@ts-ignore
@@ -37,12 +37,7 @@ export var ArrayTable = observer(function (props) {
37
37
  var sources = useArrayTableSources();
38
38
  var columns = useArrayTableColumns(dataSource, field, sources);
39
39
  var schema = useFieldSchema();
40
- return /*#__PURE__*/React.createElement("div", {
41
- ref: ref,
42
- style: {
43
- height: height ? height : 400
44
- }
45
- }, /*#__PURE__*/React.createElement(ArrayBase, null, /*#__PURE__*/React.createElement(Space, {
40
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Space, {
46
41
  style: {
47
42
  marginBottom: 5
48
43
  }
@@ -53,8 +48,16 @@ export var ArrayTable = observer(function (props) {
53
48
  _id: uniqueId(),
54
49
  _isNew: true
55
50
  },
56
- title: "新增"
57
- })), /*#__PURE__*/React.createElement(AgGridReact, {
51
+ title: "新增",
52
+ onAdd: function onAdd() {
53
+ setIsAdd(true);
54
+ }
55
+ })), /*#__PURE__*/React.createElement("div", {
56
+ ref: ref,
57
+ style: {
58
+ height: height ? height : 400
59
+ }
60
+ }, /*#__PURE__*/React.createElement(ArrayBase, null, /*#__PURE__*/React.createElement(AgGridReact, {
58
61
  onGridReady: function onGridReady(params) {
59
62
  apiRef.current = params.api;
60
63
  },
@@ -111,7 +114,7 @@ export var ArrayTable = observer(function (props) {
111
114
  onlyRenderSelf: true,
112
115
  key: key
113
116
  });
114
- })));
117
+ }))));
115
118
  });
116
119
  ArrayTable.displayName = "ArrayTable";
117
120
 
@@ -25,7 +25,8 @@ import { isVoidField } from '@formily/core';
25
25
  import { observer, useField } from '@formily/react';
26
26
  import { Popover as AntdPopover } from 'antd';
27
27
  import cls from 'classnames';
28
- import { ArrayBase, FormItem } from '@formily/antd-v5';
28
+ import { FormItem } from '@formily/antd-v5';
29
+ import { ArrayBase } from "../array-table/arrayBase";
29
30
  import React, { useLayoutEffect, useRef, useState } from 'react';
30
31
  import { useClickAway, usePrefixCls } from '@formily/antd-v5/lib/__builtins__';
31
32
  import useStyle from "./style";