@nokecy/qc-ui 0.1.53 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/array-table/arrayAddBtn.d.ts +3 -0
- package/dist/cjs/array-table/arrayAddBtn.js +82 -0
- package/dist/cjs/array-table/arrayBase.d.ts +1 -1
- package/dist/cjs/array-table/arrayBase.js +22 -81
- package/dist/cjs/array-table/index.js +30 -24
- package/dist/cjs/editable/index.js +3 -1
- package/dist/esm/array-table/arrayAddBtn.d.ts +3 -0
- package/dist/esm/array-table/arrayAddBtn.js +66 -0
- package/dist/esm/array-table/arrayBase.d.ts +1 -1
- package/dist/esm/array-table/arrayBase.js +24 -83
- package/dist/esm/array-table/index.js +31 -27
- package/dist/esm/editable/index.js +2 -1
- package/dist/umd/qc-ui.min.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _react2 = require("@formily/react");
|
|
11
|
+
|
|
12
|
+
var _antd = require("antd");
|
|
13
|
+
|
|
14
|
+
var _builtins__ = require("@formily/antd-v5/lib/__builtins__");
|
|
15
|
+
|
|
16
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
17
|
+
|
|
18
|
+
var _icons = require("@ant-design/icons");
|
|
19
|
+
|
|
20
|
+
var _shared = require("@formily/shared");
|
|
21
|
+
|
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
+
|
|
24
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
25
|
+
|
|
26
|
+
var getSchemaDefaultValue = function getSchemaDefaultValue(schema) {
|
|
27
|
+
if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'array') return [];
|
|
28
|
+
if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'object') return {};
|
|
29
|
+
|
|
30
|
+
if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'void') {
|
|
31
|
+
for (var key in schema.properties) {
|
|
32
|
+
var value = getSchemaDefaultValue(schema.properties[key]);
|
|
33
|
+
if ((0, _shared.isValid)(value)) return value;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
var getDefaultValue = function getDefaultValue(defaultValue, schema) {
|
|
39
|
+
if ((0, _shared.isValid)(defaultValue)) return (0, _shared.clone)(defaultValue);
|
|
40
|
+
if (Array.isArray(schema === null || schema === void 0 ? void 0 : schema.items)) return getSchemaDefaultValue(schema === null || schema === void 0 ? void 0 : schema.items[0]);
|
|
41
|
+
return getSchemaDefaultValue(schema === null || schema === void 0 ? void 0 : schema.items);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
var ArrayAddBtn = function ArrayAddBtn(props) {
|
|
45
|
+
var self = (0, _react2.useField)();
|
|
46
|
+
var arrayField = props.arrayField,
|
|
47
|
+
schema = props.schema;
|
|
48
|
+
var prefixCls = (0, _builtins__.usePrefixCls)("formily-array-base");
|
|
49
|
+
if (!arrayField) return null;
|
|
50
|
+
if (arrayField.pattern !== "editable" && arrayField.pattern !== "disabled") return null;
|
|
51
|
+
return /*#__PURE__*/_react.default.createElement(_antd.Button, _extends({
|
|
52
|
+
type: "primary"
|
|
53
|
+
}, props, {
|
|
54
|
+
disabled: self === null || self === void 0 ? void 0 : self.disabled,
|
|
55
|
+
className: (0, _classnames.default)("".concat(prefixCls, "-addition"), props.className),
|
|
56
|
+
onClick: function onClick(e) {
|
|
57
|
+
if (arrayField !== null && arrayField !== void 0 && arrayField.disabled) return;
|
|
58
|
+
var defaultValue = getDefaultValue(props.defaultValue, schema);
|
|
59
|
+
|
|
60
|
+
if (props.method === "unshift") {
|
|
61
|
+
var _arrayField$unshift, _props$onAdd;
|
|
62
|
+
|
|
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);
|
|
65
|
+
} else {
|
|
66
|
+
var _arrayField$push, _props$onAdd2, _arrayField$value;
|
|
67
|
+
|
|
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);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (props.onClick) {
|
|
73
|
+
//@ts-ignore
|
|
74
|
+
props.onClick(e);
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
icon: (0, _shared.isUndef)(props.icon) ? /*#__PURE__*/_react.default.createElement(_icons.PlusOutlined, null) : props.icon
|
|
78
|
+
}), props.title || self.title);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
var _default = ArrayAddBtn;
|
|
82
|
+
exports.default = _default;
|
|
@@ -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
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
161
|
-
var value = (0, _shared.clone)(array === null || array === void 0 ? void 0 : (_array$
|
|
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$
|
|
164
|
-
(_array$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
195
|
-
(_array$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
226
|
-
(_array$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
257
|
-
array === null || array === void 0 ? void 0 : (_array$
|
|
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
|
|
@@ -21,20 +21,16 @@ var _utils = require("./utils");
|
|
|
21
21
|
|
|
22
22
|
var _arrayBase = _interopRequireDefault(require("./arrayBase"));
|
|
23
23
|
|
|
24
|
+
var _arrayAddBtn = _interopRequireDefault(require("./arrayAddBtn"));
|
|
25
|
+
|
|
26
|
+
var _antd = require("antd");
|
|
27
|
+
|
|
24
28
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
25
29
|
|
|
26
30
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
27
31
|
|
|
28
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
33
|
|
|
30
|
-
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
31
|
-
|
|
32
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
33
|
-
|
|
34
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
35
|
-
|
|
36
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
37
|
-
|
|
38
34
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
39
35
|
|
|
40
36
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -62,13 +58,28 @@ var ArrayTable = (0, _react2.observer)(function (props) {
|
|
|
62
58
|
var dataSource = Array.isArray(field.value) ? field.value.slice() : [];
|
|
63
59
|
var sources = (0, _utils.useArrayTableSources)();
|
|
64
60
|
var columns = (0, _utils.useArrayTableColumns)(dataSource, field, sources);
|
|
65
|
-
var
|
|
61
|
+
var schema = (0, _react2.useFieldSchema)();
|
|
66
62
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
67
63
|
ref: ref,
|
|
68
64
|
style: {
|
|
69
65
|
height: height ? height : 400
|
|
70
66
|
}
|
|
71
|
-
}, /*#__PURE__*/_react.default.createElement(_arrayBase.default, null, /*#__PURE__*/_react.default.createElement(
|
|
67
|
+
}, /*#__PURE__*/_react.default.createElement(_arrayBase.default, null, /*#__PURE__*/_react.default.createElement(_antd.Space, {
|
|
68
|
+
style: {
|
|
69
|
+
marginBottom: 5
|
|
70
|
+
}
|
|
71
|
+
}, /*#__PURE__*/_react.default.createElement(_arrayAddBtn.default, {
|
|
72
|
+
arrayField: field,
|
|
73
|
+
schema: schema,
|
|
74
|
+
defaultValue: {
|
|
75
|
+
_id: (0, _uniqueId.default)(),
|
|
76
|
+
_isNew: true
|
|
77
|
+
},
|
|
78
|
+
title: "新增",
|
|
79
|
+
onAdd: function onAdd() {
|
|
80
|
+
setIsAdd(true);
|
|
81
|
+
}
|
|
82
|
+
})), /*#__PURE__*/_react.default.createElement(_agGridReact.AgGridReact, {
|
|
72
83
|
onGridReady: function onGridReady(params) {
|
|
73
84
|
apiRef.current = params.api;
|
|
74
85
|
},
|
|
@@ -81,6 +92,15 @@ var ArrayTable = (0, _react2.observer)(function (props) {
|
|
|
81
92
|
}
|
|
82
93
|
},
|
|
83
94
|
className: "ag-theme-alpine",
|
|
95
|
+
defaultColDef: {
|
|
96
|
+
resizable: true,
|
|
97
|
+
headerComponentParams: {
|
|
98
|
+
template: '<div class="ag-cell-label-container" role="presentation">' + // ' <span ref="eMenu" class="ag-header-icon ag-header-cell-menu-button" aria-hidden="true"></span>' +
|
|
99
|
+
' <div ref="eLabel" class="ag-header-cell-label" role="presentation">' + ' <span ref="eText" class="ag-header-cell-text"></span>' + // ' <span ref="eFilter" class="ag-header-icon ag-filter-icon"></span>' +
|
|
100
|
+
// ' <span ref="eSortOrder" class="ag-header-icon ag-sort-order"></span>' +
|
|
101
|
+
' <span ref="eSortAsc" class="ag-header-icon ag-sort-ascending-icon"></span>' + ' <span ref="eSortDesc" class="ag-header-icon ag-sort-descending-icon"></span>' + ' <span ref="eSortNone" class="ag-header-icon ag-sort-none-icon"></span>' + ' </div>' + '</div>'
|
|
102
|
+
}
|
|
103
|
+
},
|
|
84
104
|
getRowId: function getRowId(_ref) {
|
|
85
105
|
var data = _ref.data;
|
|
86
106
|
return data._id || data.id;
|
|
@@ -127,19 +147,5 @@ ArrayTable.Column = function () {
|
|
|
127
147
|
|
|
128
148
|
_arrayBase.default.mixin(ArrayTable);
|
|
129
149
|
|
|
130
|
-
var Addition = function Addition(props) {
|
|
131
|
-
return /*#__PURE__*/_react.default.createElement(_arrayBase.default.Addition, _extends({
|
|
132
|
-
type: "primary",
|
|
133
|
-
children: "新增行"
|
|
134
|
-
}, props, {
|
|
135
|
-
block: false,
|
|
136
|
-
defaultValue: _objectSpread(_objectSpread({}, props.defaultValue), {}, {
|
|
137
|
-
_id: (0, _uniqueId.default)(),
|
|
138
|
-
_isNew: true
|
|
139
|
-
})
|
|
140
|
-
}));
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
ArrayTable.Addition = Addition;
|
|
144
150
|
var _default = ArrayTable;
|
|
145
151
|
exports.default = _default;
|
|
@@ -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 =
|
|
66
|
+
var record = _arrayBase.ArrayBase.useRecord();
|
|
65
67
|
|
|
66
68
|
var field = (0, _react.useField)(); // useLayoutEffect(() => {
|
|
67
69
|
// if (pattern === 'editable') {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { useField } from "@formily/react";
|
|
5
|
+
import { Button } from "antd";
|
|
6
|
+
import { usePrefixCls } from "@formily/antd-v5/lib/__builtins__";
|
|
7
|
+
import cls from 'classnames';
|
|
8
|
+
import { PlusOutlined } from "@ant-design/icons";
|
|
9
|
+
import { isValid, clone, isUndef } from '@formily/shared';
|
|
10
|
+
|
|
11
|
+
var getSchemaDefaultValue = function getSchemaDefaultValue(schema) {
|
|
12
|
+
if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'array') return [];
|
|
13
|
+
if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'object') return {};
|
|
14
|
+
|
|
15
|
+
if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'void') {
|
|
16
|
+
for (var key in schema.properties) {
|
|
17
|
+
var value = getSchemaDefaultValue(schema.properties[key]);
|
|
18
|
+
if (isValid(value)) return value;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
var getDefaultValue = function getDefaultValue(defaultValue, schema) {
|
|
24
|
+
if (isValid(defaultValue)) return clone(defaultValue);
|
|
25
|
+
if (Array.isArray(schema === null || schema === void 0 ? void 0 : schema.items)) return getSchemaDefaultValue(schema === null || schema === void 0 ? void 0 : schema.items[0]);
|
|
26
|
+
return getSchemaDefaultValue(schema === null || schema === void 0 ? void 0 : schema.items);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
var ArrayAddBtn = function ArrayAddBtn(props) {
|
|
30
|
+
var self = useField();
|
|
31
|
+
var arrayField = props.arrayField,
|
|
32
|
+
schema = props.schema;
|
|
33
|
+
var prefixCls = usePrefixCls("formily-array-base");
|
|
34
|
+
if (!arrayField) return null;
|
|
35
|
+
if (arrayField.pattern !== "editable" && arrayField.pattern !== "disabled") return null;
|
|
36
|
+
return /*#__PURE__*/React.createElement(Button, _extends({
|
|
37
|
+
type: "primary"
|
|
38
|
+
}, props, {
|
|
39
|
+
disabled: self === null || self === void 0 ? void 0 : self.disabled,
|
|
40
|
+
className: cls("".concat(prefixCls, "-addition"), props.className),
|
|
41
|
+
onClick: function onClick(e) {
|
|
42
|
+
if (arrayField !== null && arrayField !== void 0 && arrayField.disabled) return;
|
|
43
|
+
var defaultValue = getDefaultValue(props.defaultValue, schema);
|
|
44
|
+
|
|
45
|
+
if (props.method === "unshift") {
|
|
46
|
+
var _arrayField$unshift, _props$onAdd;
|
|
47
|
+
|
|
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);
|
|
50
|
+
} else {
|
|
51
|
+
var _arrayField$push, _props$onAdd2, _arrayField$value;
|
|
52
|
+
|
|
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);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (props.onClick) {
|
|
58
|
+
//@ts-ignore
|
|
59
|
+
props.onClick(e);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
icon: isUndef(props.icon) ? /*#__PURE__*/React.createElement(PlusOutlined, null) : props.icon
|
|
63
|
+
}), props.title || self.title);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export default ArrayAddBtn;
|
|
@@ -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
|
|
47
|
+
useRecord: (record?: number) => any;
|
|
48
48
|
};
|
|
49
49
|
export interface IArrayBaseProps {
|
|
50
50
|
disabled?: boolean;
|