iglooform 3.1.5 → 3.1.6
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/.dumi/tmp/core/defineApp.ts +1 -1
- package/.dumi/tmp/core/helmet.ts +1 -1
- package/.dumi/tmp/core/history.ts +1 -1
- package/.dumi/tmp/core/historyIntelli.ts +1 -1
- package/.dumi/tmp/core/plugin.ts +2 -2
- package/.dumi/tmp/core/polyfill.ts +197 -197
- package/.dumi/tmp/core/route.tsx +33 -33
- package/.dumi/tmp/dumi/exports.ts +1 -1
- package/.dumi/tmp/dumi/locales/runtime.tsx +2 -2
- package/.dumi/tmp/dumi/meta/index.ts +33 -33
- package/.dumi/tmp/dumi/meta/runtime.ts +1 -1
- package/.dumi/tmp/dumi/theme/ContextWrapper.tsx +2 -2
- package/.dumi/tmp/dumi/theme/builtins/API.ts +1 -1
- package/.dumi/tmp/dumi/theme/builtins/Badge.ts +1 -1
- package/.dumi/tmp/dumi/theme/builtins/Container.ts +1 -1
- package/.dumi/tmp/dumi/theme/builtins/Previewer.ts +1 -1
- package/.dumi/tmp/dumi/theme/builtins/SourceCode.ts +1 -1
- package/.dumi/tmp/dumi/theme/builtins/Table.ts +1 -1
- package/.dumi/tmp/dumi/theme/builtins/Tree.ts +1 -1
- package/.dumi/tmp/dumi/theme/layouts/DocLayout.ts +1 -1
- package/.dumi/tmp/dumi/theme/loading.tsx +1 -1
- package/.dumi/tmp/dumi/theme/slots/ColorSwitch.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/Content.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/ContentFooter.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/ContentTabs.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/Features.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/Footer.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/Header.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/HeaderExtra.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/Hero.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/HeroTitle.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/LangSwitch.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/Logo.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/Navbar.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/NavbarExtra.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/NotFound.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/PreviewerActions.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/PreviewerActionsExtra.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/RtlSwitch.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/SearchBar.ts +2 -2
- package/.dumi/tmp/dumi/theme/slots/SearchResult.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/Sidebar.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/SocialIcon.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/Toc.ts +1 -1
- package/.dumi/tmp/exports.ts +5 -5
- package/.dumi/tmp/testBrowser.tsx +3 -3
- package/.dumi/tmp/umi.ts +4 -4
- package/.idea/iglooform.iml +9 -0
- package/.idea/misc.xml +5 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/es/confirmation/style/index.d.ts +1 -0
- package/es/form/addable-section/index.js +18 -7
- package/es/form/element/index.d.ts +12 -0
- package/es/form/element/index.js +3 -2
- package/es/form/hsteps/index.js +4 -3
- package/es/form/steps/index.js +3 -2
- package/es/free-form/addable-section/index.js +33 -10
- package/es/free-form/element/index.js +4 -2
- package/es/free-form/step/index.js +1 -1
- package/es/media/file-icon.d.ts +9 -0
- package/es/ocr/micro-blink/style/index.d.ts +1 -0
- package/es/select/attached-select.d.ts +17 -0
- package/es/types.d.ts +1 -0
- package/es/utils/form-utils.d.ts +3 -2
- package/es/utils/form-utils.js +84 -16
- package/lib/confirmation/style/index.d.ts +1 -0
- package/lib/form/addable-section/index.js +18 -7
- package/lib/form/element/index.d.ts +12 -0
- package/lib/form/element/index.js +3 -2
- package/lib/form/hsteps/index.js +4 -3
- package/lib/form/steps/index.js +3 -2
- package/lib/free-form/addable-section/index.js +32 -9
- package/lib/free-form/element/index.js +4 -2
- package/lib/free-form/step/index.js +1 -1
- package/lib/media/file-icon.d.ts +9 -0
- package/lib/ocr/micro-blink/style/index.d.ts +1 -0
- package/lib/select/attached-select.d.ts +17 -0
- package/lib/types.d.ts +1 -0
- package/lib/utils/form-utils.d.ts +3 -2
- package/lib/utils/form-utils.js +86 -17
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { FormItemConfig, FormItemName } from '../../types';
|
|
3
|
+
import './style';
|
|
4
|
+
interface ElementProps {
|
|
5
|
+
config: FormItemConfig;
|
|
6
|
+
parentName?: FormItemName;
|
|
7
|
+
preview?: boolean;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
setShowStepButton?: (showButton: boolean) => void;
|
|
10
|
+
}
|
|
11
|
+
declare const Element: FC<ElementProps>;
|
|
12
|
+
export default Element;
|
|
@@ -74,7 +74,8 @@ var Element = function Element(_ref) {
|
|
|
74
74
|
disabled = config.disabled,
|
|
75
75
|
extraLabel = config.extraLabel,
|
|
76
76
|
requiredAsserts = config.requiredAsserts,
|
|
77
|
-
shouldRenderCode = config.shouldRenderCode
|
|
77
|
+
shouldRenderCode = config.shouldRenderCode,
|
|
78
|
+
disabledCode = config.disabledCode;
|
|
78
79
|
var dependentField = dependencies || [];
|
|
79
80
|
if (Array.isArray(subscribedFields)) {
|
|
80
81
|
dependentField.push.apply(dependentField, _toConsumableArray(subscribedFields));
|
|
@@ -100,7 +101,7 @@ var Element = function Element(_ref) {
|
|
|
100
101
|
return dependentField.push(assert.field);
|
|
101
102
|
});
|
|
102
103
|
}
|
|
103
|
-
if ((shouldRender || shouldRenderCode || getOptions || typeof extraLabel === 'function') && !Array.isArray(subscribedFields)) {
|
|
104
|
+
if ((shouldRender || shouldRenderCode || disabledCode || getOptions || typeof extraLabel === 'function') && !Array.isArray(subscribedFields)) {
|
|
104
105
|
dependentField.push('SUBSCRIBE_ALL');
|
|
105
106
|
}
|
|
106
107
|
if (dependField) {
|
package/lib/form/hsteps/index.js
CHANGED
|
@@ -83,6 +83,7 @@ var HSteps = function HSteps(_ref) {
|
|
|
83
83
|
var _useContext2 = (0, _react.useContext)(_locale.LocaleContext),
|
|
84
84
|
formatMessage = _useContext2.formatMessage,
|
|
85
85
|
currentLang = _useContext2.currentLang;
|
|
86
|
+
var _parentName = (0, _formUtils.calcNamePath)(parentName, name);
|
|
86
87
|
(0, _react.useEffect)(function () {
|
|
87
88
|
var subscribe = elements.some(function (_ref2) {
|
|
88
89
|
var shouldRender = _ref2.shouldRender,
|
|
@@ -118,7 +119,7 @@ var HSteps = function HSteps(_ref) {
|
|
|
118
119
|
shouldRenderCode = _ref5.shouldRenderCode;
|
|
119
120
|
(0, _invariant.default)(type === 'Step', 'Child of steps should be Step');
|
|
120
121
|
(0, _invariant.default)(!validationRule || getRuleValidationApi, 'Please provide getRuleValidationApi in Form props');
|
|
121
|
-
return (0, _formUtils.calcShouldRender)((0, _formUtils.calcNamePath)(
|
|
122
|
+
return (0, _formUtils.calcShouldRender)((0, _formUtils.calcNamePath)(_parentName, curName), _parentName, dependencies, asserts, shouldRender, shouldRenderCode, form);
|
|
122
123
|
});
|
|
123
124
|
var handleNext = /*#__PURE__*/function () {
|
|
124
125
|
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
@@ -277,7 +278,7 @@ var HSteps = function HSteps(_ref) {
|
|
|
277
278
|
},
|
|
278
279
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_hstep.default, {
|
|
279
280
|
config: renderElements[current],
|
|
280
|
-
parentName:
|
|
281
|
+
parentName: _parentName,
|
|
281
282
|
index: current,
|
|
282
283
|
total: withReview ? renderElements.length + 1 : renderElements.length,
|
|
283
284
|
preview: false,
|
|
@@ -307,7 +308,7 @@ var HSteps = function HSteps(_ref) {
|
|
|
307
308
|
}), renderElements.map(function (step, index) {
|
|
308
309
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_hstep.default, {
|
|
309
310
|
config: step,
|
|
310
|
-
parentName:
|
|
311
|
+
parentName: _parentName,
|
|
311
312
|
index: index,
|
|
312
313
|
total: withReview ? renderElements.length + 1 : renderElements.length,
|
|
313
314
|
preview: true,
|
package/lib/form/steps/index.js
CHANGED
|
@@ -62,6 +62,7 @@ var Steps = function Steps(_ref) {
|
|
|
62
62
|
registerDependencies = _useContext.registerDependencies;
|
|
63
63
|
var _useContext2 = (0, _react.useContext)(_locale.LocaleContext),
|
|
64
64
|
currentLang = _useContext2.currentLang;
|
|
65
|
+
var _parentName = (0, _formUtils.calcNamePath)(parentName, name);
|
|
65
66
|
(0, _react.useEffect)(function () {
|
|
66
67
|
var subscribe = elements.some(function (_ref2) {
|
|
67
68
|
var shouldRender = _ref2.shouldRender,
|
|
@@ -93,7 +94,7 @@ var Steps = function Steps(_ref) {
|
|
|
93
94
|
asserts = _ref5.asserts,
|
|
94
95
|
shouldRender = _ref5.shouldRender,
|
|
95
96
|
shouldRenderCode = _ref5.shouldRenderCode;
|
|
96
|
-
return (0, _formUtils.calcShouldRender)((0, _formUtils.calcNamePath)(
|
|
97
|
+
return (0, _formUtils.calcShouldRender)((0, _formUtils.calcNamePath)(_parentName, curName), _parentName, dependencies, asserts, shouldRender, shouldRenderCode, form);
|
|
97
98
|
});
|
|
98
99
|
var handleNext = /*#__PURE__*/function () {
|
|
99
100
|
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
@@ -206,7 +207,7 @@ var Steps = function Steps(_ref) {
|
|
|
206
207
|
},
|
|
207
208
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_step.default, {
|
|
208
209
|
config: child,
|
|
209
|
-
parentName:
|
|
210
|
+
parentName: _parentName,
|
|
210
211
|
index: index,
|
|
211
212
|
total: renderElements.length,
|
|
212
213
|
preview: current > index,
|
|
@@ -163,32 +163,44 @@ var AddableSection = function AddableSection(props) {
|
|
|
163
163
|
}]);
|
|
164
164
|
}
|
|
165
165
|
var transformChildren = function transformChildren(parentName) {
|
|
166
|
+
var index = parentName[parentName.length - 1];
|
|
166
167
|
if (Array.isArray(children)) {
|
|
167
|
-
return children.map(function (c,
|
|
168
|
+
return children.map(function (c, _index) {
|
|
168
169
|
var _c$type;
|
|
169
170
|
var _child = _objectSpread({}, c.props);
|
|
170
171
|
if (Array.isArray(_child.asserts)) {
|
|
171
172
|
_child.asserts = _child.asserts.map(function (assert) {
|
|
172
173
|
return _objectSpread(_objectSpread({}, assert), {}, {
|
|
173
|
-
field: (0, _formUtils.
|
|
174
|
+
field: (0, _formUtils.calcAddableSectionAssertField)(namePath, assert.field, index, children)
|
|
174
175
|
});
|
|
175
176
|
});
|
|
176
177
|
}
|
|
177
178
|
if (Array.isArray(_child.requiredAsserts)) {
|
|
178
179
|
_child.requiredAsserts = _child.requiredAsserts.map(function (assert) {
|
|
179
180
|
return _objectSpread(_objectSpread({}, assert), {}, {
|
|
180
|
-
field: (0, _formUtils.
|
|
181
|
+
field: (0, _formUtils.calcAddableSectionAssertField)(namePath, assert.field, index, children)
|
|
181
182
|
});
|
|
182
183
|
});
|
|
183
184
|
}
|
|
185
|
+
if (Array.isArray(_child.disabled)) {
|
|
186
|
+
_child.disabled = _child.disabled.map(function (assert) {
|
|
187
|
+
return _objectSpread(_objectSpread({}, assert), {}, {
|
|
188
|
+
field: (0, _formUtils.calcAddableSectionAssertField)(namePath, assert.field, index, children)
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
} else if (_typeof(_child.disabled) === 'object') {
|
|
192
|
+
_child.disabled = _objectSpread(_objectSpread({}, _child.disabled), {}, {
|
|
193
|
+
field: (0, _formUtils.calcAddableSectionAssertField)(namePath, _child.disabled.field, index, children)
|
|
194
|
+
});
|
|
195
|
+
}
|
|
184
196
|
if (Array.isArray(_child.dependencies)) {
|
|
185
197
|
_child.dependencies = _child.dependencies.map(function (path) {
|
|
186
|
-
return (0, _formUtils.
|
|
198
|
+
return (0, _formUtils.calcAddableSectionAssertField)(namePath, path, index, children);
|
|
187
199
|
});
|
|
188
200
|
}
|
|
189
201
|
if (['Igloo_Free_Form_Item', 'Igloo_Free_Form_Section', 'Igloo_Free_Form_AddableSection'].includes(c === null || c === void 0 ? void 0 : (_c$type = c.type) === null || _c$type === void 0 ? void 0 : _c$type.displayName)) {
|
|
190
202
|
return /*#__PURE__*/(0, _react.cloneElement)(c, _objectSpread(_objectSpread({
|
|
191
|
-
key:
|
|
203
|
+
key: _index
|
|
192
204
|
}, _child), {}, {
|
|
193
205
|
parentName: parentName,
|
|
194
206
|
setShowStepButton: setShowStepButton,
|
|
@@ -204,20 +216,31 @@ var AddableSection = function AddableSection(props) {
|
|
|
204
216
|
if (Array.isArray(_child.asserts)) {
|
|
205
217
|
_child.asserts = _child.asserts.map(function (assert) {
|
|
206
218
|
return _objectSpread(_objectSpread({}, assert), {}, {
|
|
207
|
-
field: (0, _formUtils.
|
|
219
|
+
field: (0, _formUtils.calcAddableSectionAssertField)(namePath, assert.field, index, [children])
|
|
208
220
|
});
|
|
209
221
|
});
|
|
210
222
|
}
|
|
211
223
|
if (Array.isArray(_child.requiredAsserts)) {
|
|
212
224
|
_child.requiredAsserts = _child.requiredAsserts.map(function (assert) {
|
|
213
225
|
return _objectSpread(_objectSpread({}, assert), {}, {
|
|
214
|
-
field: (0, _formUtils.
|
|
226
|
+
field: (0, _formUtils.calcAddableSectionAssertField)(namePath, assert.field, index, [children])
|
|
215
227
|
});
|
|
216
228
|
});
|
|
217
229
|
}
|
|
230
|
+
if (Array.isArray(_child.disabled)) {
|
|
231
|
+
_child.disabled = _child.disabled.map(function (assert) {
|
|
232
|
+
return _objectSpread(_objectSpread({}, assert), {}, {
|
|
233
|
+
field: (0, _formUtils.calcAddableSectionAssertField)(namePath, assert.field, index, [children])
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
} else if (_typeof(_child.disabled) === 'object') {
|
|
237
|
+
_child.disabled = _objectSpread(_objectSpread({}, _child.disabled), {}, {
|
|
238
|
+
field: (0, _formUtils.calcAddableSectionAssertField)(namePath, _child.disabled.field, index, [children])
|
|
239
|
+
});
|
|
240
|
+
}
|
|
218
241
|
if (Array.isArray(_child.dependencies)) {
|
|
219
242
|
_child.dependencies = _child.dependencies.map(function (path) {
|
|
220
|
-
return (0, _formUtils.
|
|
243
|
+
return (0, _formUtils.calcAddableSectionAssertField)(namePath, path, index, [children]);
|
|
221
244
|
});
|
|
222
245
|
}
|
|
223
246
|
return /*#__PURE__*/(0, _react.cloneElement)(children, _objectSpread(_objectSpread({}, _child), {}, {
|
|
@@ -273,7 +296,7 @@ var AddableSection = function AddableSection(props) {
|
|
|
273
296
|
children: transformChildren(parentName)
|
|
274
297
|
})
|
|
275
298
|
}))]
|
|
276
|
-
}, key);
|
|
299
|
+
}, key + index);
|
|
277
300
|
});
|
|
278
301
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
279
302
|
className: "igloo-addable-section-container",
|
|
@@ -67,7 +67,9 @@ var Element = function Element(props) {
|
|
|
67
67
|
subscribedFields = props.subscribedFields,
|
|
68
68
|
extraLabel = props.extraLabel,
|
|
69
69
|
disabled = props.disabled,
|
|
70
|
-
requiredAsserts = props.requiredAsserts
|
|
70
|
+
requiredAsserts = props.requiredAsserts,
|
|
71
|
+
shouldRenderCode = props.shouldRenderCode,
|
|
72
|
+
disabledCode = props.disabledCode;
|
|
71
73
|
var dependentField = dependencies || [];
|
|
72
74
|
if (Array.isArray(subscribedFields)) {
|
|
73
75
|
dependentField.push.apply(dependentField, _toConsumableArray(subscribedFields));
|
|
@@ -93,7 +95,7 @@ var Element = function Element(props) {
|
|
|
93
95
|
return dependentField.push(assert.field);
|
|
94
96
|
});
|
|
95
97
|
}
|
|
96
|
-
if ((shouldRender || getOptions || typeof extraLabel === 'function') && !Array.isArray(subscribedFields)) {
|
|
98
|
+
if ((shouldRender || shouldRenderCode || disabledCode || getOptions || typeof extraLabel === 'function') && !Array.isArray(subscribedFields)) {
|
|
97
99
|
dependentField.push('SUBSCRIBE_ALL');
|
|
98
100
|
}
|
|
99
101
|
if (dependField) {
|
|
@@ -216,7 +216,7 @@ var Step = function Step(_ref) {
|
|
|
216
216
|
return _ref3.apply(this, arguments);
|
|
217
217
|
};
|
|
218
218
|
}();
|
|
219
|
-
if (!(0, _formUtils.calcShouldRender)(pName, dependencies, asserts, shouldRender, shouldRenderCode, form)) {
|
|
219
|
+
if (!(0, _formUtils.calcShouldRender)(pName, parentName, dependencies, asserts, shouldRender, shouldRenderCode, form)) {
|
|
220
220
|
return null;
|
|
221
221
|
}
|
|
222
222
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './index.less';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Select } from 'antd';
|
|
2
|
+
import { SelectProps, SelectValue } from 'antd/es/select';
|
|
3
|
+
import { FC, IglooComponentProps } from '../types';
|
|
4
|
+
import './style';
|
|
5
|
+
import { ComponentProps } from '../utils/option-utils';
|
|
6
|
+
type Props = SelectProps<SelectValue> & IglooComponentProps & {
|
|
7
|
+
multiple?: boolean;
|
|
8
|
+
preview?: boolean;
|
|
9
|
+
} & ComponentProps;
|
|
10
|
+
type OptionType = typeof Select.Option;
|
|
11
|
+
type OptGroupType = typeof Select.OptGroup;
|
|
12
|
+
interface IglooSelectType extends FC<Props> {
|
|
13
|
+
Option: OptionType;
|
|
14
|
+
OptGroup: OptGroupType;
|
|
15
|
+
}
|
|
16
|
+
declare const AttachedSelect: IglooSelectType;
|
|
17
|
+
export default AttachedSelect;
|
package/lib/types.d.ts
CHANGED
|
@@ -146,6 +146,7 @@ export interface FormItemExtraConfig extends FormItemProps {
|
|
|
146
146
|
idType?: 'KTP' | 'NIK';
|
|
147
147
|
validationRule?: string;
|
|
148
148
|
shouldRenderCode?: string;
|
|
149
|
+
disabledCode?: string;
|
|
149
150
|
[key: string]: any;
|
|
150
151
|
}
|
|
151
152
|
export interface FormItemConfig extends FormItemExtraConfig {
|
|
@@ -54,7 +54,7 @@ export declare const calcFormItemProps: (config: FormItemConfig, extraProps: For
|
|
|
54
54
|
display: any;
|
|
55
55
|
previewFormater: ((value: any, form?: FormInstance<any> | undefined) => any) | undefined;
|
|
56
56
|
};
|
|
57
|
-
export declare const calcDisabled: (disabled?: boolean | FormItemAssert | FormItemAssert[], form?: FormInstance) =>
|
|
57
|
+
export declare const calcDisabled: (disabled?: boolean | FormItemAssert | FormItemAssert[], form?: FormInstance, disabledCode?: string, name?: FormItemName, parentName?: FormItemName) => any;
|
|
58
58
|
export declare const calcCopyValue: (copyValue?: FormItemCopyValue, form?: FormInstance) => {
|
|
59
59
|
copied: boolean;
|
|
60
60
|
value?: undefined;
|
|
@@ -73,5 +73,6 @@ export declare const calcSelectValue: (selectValue?: FormItemSelectValue[], form
|
|
|
73
73
|
value: any;
|
|
74
74
|
disabled: boolean | undefined;
|
|
75
75
|
};
|
|
76
|
-
export declare const calcShouldRender: (name: NamePath, dependencies?: NamePath[], asserts?: FormItemAssert[], shouldRender?: ((form?: FormInstance) => boolean) | undefined, shouldRenderCode?: string, form?: FormInstance) => any;
|
|
76
|
+
export declare const calcShouldRender: (name: NamePath, parentName: NamePath, dependencies?: NamePath[], asserts?: FormItemAssert[], shouldRender?: ((form?: FormInstance) => boolean) | undefined, shouldRenderCode?: string, form?: FormInstance) => any;
|
|
77
77
|
export declare const getRuleValidation: (url: string, rule: string | string[], values?: any, lang?: string) => Promise<any>;
|
|
78
|
+
export declare const calcAddableSectionAssertField: (name: any[], field: FormItemAssert['field'], index: number, elements: FormItemConfig[] | React.ReactElement[]) => any;
|
package/lib/utils/form-utils.js
CHANGED
|
@@ -4,14 +4,15 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.testAssert = exports.getRuleValidation = exports.calcShouldRender = exports.calcSelectValue = exports.calcNamePath = exports.calcFormItemProps = exports.calcDisabled = exports.calcCopyValue = void 0;
|
|
7
|
+
exports.testAssert = exports.getRuleValidation = exports.calcShouldRender = exports.calcSelectValue = exports.calcNamePath = exports.calcFormItemProps = exports.calcDisabled = exports.calcCopyValue = exports.calcAddableSectionAssertField = void 0;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
var _invariant = _interopRequireDefault(require("invariant"));
|
|
10
10
|
var _typography = _interopRequireDefault(require("../typography"));
|
|
11
11
|
var _formattedMessage = _interopRequireDefault(require("../locale/formatted-message"));
|
|
12
12
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
13
|
+
var _lodash = require("lodash");
|
|
13
14
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
|
-
var _excluded = ["type", "name", "required", "requiredAsserts", "showOptional", "rules", "initialValue", "normalize", "mergeRules", "getValueFromEvent", "getValueProps", "extra", "help", "label", "previewLabel", "extraLabel", "copyValue", "selectValue", "span", "halfRow", "fullRow", "valuePropName", "dependencies", "asserts", "messageVariables", "requiredMessage", "previewFormater", "disabled", "ignore", "shouldRender", "valueFormater", "antdDependencies", "dateLimitationType", "absoluteRangeEnd", "absoluteRangeStart", "relativeRangeStart", "relativeRangeEnd", "validationCode", "shouldRenderCode"],
|
|
15
|
+
var _excluded = ["type", "name", "required", "requiredAsserts", "showOptional", "rules", "initialValue", "normalize", "mergeRules", "getValueFromEvent", "getValueProps", "extra", "help", "label", "previewLabel", "extraLabel", "copyValue", "selectValue", "span", "halfRow", "fullRow", "valuePropName", "dependencies", "asserts", "messageVariables", "requiredMessage", "previewFormater", "disabled", "ignore", "shouldRender", "valueFormater", "antdDependencies", "dateLimitationType", "absoluteRangeEnd", "absoluteRangeStart", "relativeRangeStart", "relativeRangeEnd", "validationCode", "shouldRenderCode", "disabledCode"],
|
|
15
16
|
_excluded2 = ["initialValue", "normalize", "rules", "extra", "help", "getValueFromEvent", "span", "valuePropName", "fullRow", "halfRow", "messageVariables", "requiredMessage", "previewFormater", "valueFormater", "required", "requiredMark", "className"];
|
|
16
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
18
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
@@ -179,6 +180,7 @@ var calcFormItemProps = function calcFormItemProps(config, extraProps, form, par
|
|
|
179
180
|
_config$validationCod = config.validationCode,
|
|
180
181
|
validationCode = _config$validationCod === void 0 ? [] : _config$validationCod,
|
|
181
182
|
shouldRenderCode = config.shouldRenderCode,
|
|
183
|
+
disabledCode = config.disabledCode,
|
|
182
184
|
rest = _objectWithoutProperties(config, _excluded);
|
|
183
185
|
(0, _invariant.default)(nameProp !== undefined || type === 'Divider' || type === 'Section' || type === 'Typography' || type === 'OCR' || !type, "name property is required for form item config (type: ".concat(type, ")"));
|
|
184
186
|
(0, _invariant.default)(!previewFormater || typeof previewFormater === 'function', 'previewFormater property should be a function');
|
|
@@ -230,7 +232,7 @@ var calcFormItemProps = function calcFormItemProps(config, extraProps, form, par
|
|
|
230
232
|
Object.keys(_objectSpread(_objectSpread({}, extraRest), rest)).forEach(function (key) {
|
|
231
233
|
elementProps[key.replace('element-', '')] = rest[key];
|
|
232
234
|
});
|
|
233
|
-
elementProps.disabled = calcDisabled(disabled, form) || copiedValue.disabled || selectedValue.disabled;
|
|
235
|
+
elementProps.disabled = calcDisabled(disabled, form, disabledCode, name, parentName) || copiedValue.disabled || selectedValue.disabled;
|
|
234
236
|
if (dateLimitationType) {
|
|
235
237
|
var rangeStart;
|
|
236
238
|
var rangeEnd;
|
|
@@ -311,8 +313,12 @@ var calcFormItemProps = function calcFormItemProps(config, extraProps, form, par
|
|
|
311
313
|
var fn = eval(code);
|
|
312
314
|
var formValues = form === null || form === void 0 ? void 0 : form.getFieldsValue(true);
|
|
313
315
|
var _result2 = fn(value, formValues, {
|
|
314
|
-
moment: _dayjs.default
|
|
315
|
-
|
|
316
|
+
moment: _dayjs.default,
|
|
317
|
+
get: _lodash.get
|
|
318
|
+
}, _objectSpread({
|
|
319
|
+
name: name,
|
|
320
|
+
parentName: parentName
|
|
321
|
+
}, validationCodeExtraParams));
|
|
316
322
|
return _result2 ? Promise.resolve() : Promise.reject(errorMessage);
|
|
317
323
|
} catch (_unused) {
|
|
318
324
|
return Promise.reject(errorMessage);
|
|
@@ -374,13 +380,32 @@ var calcFormItemProps = function calcFormItemProps(config, extraProps, form, par
|
|
|
374
380
|
dependencies: antdDependencies
|
|
375
381
|
},
|
|
376
382
|
elementProps: elementProps,
|
|
377
|
-
display: !ignore && calcShouldRender(name, dependencies, asserts, shouldRender, shouldRenderCode, form),
|
|
383
|
+
display: !ignore && calcShouldRender(name, parentName, dependencies, asserts, shouldRender, shouldRenderCode, form),
|
|
378
384
|
previewFormater: previewFormater || extraPreviewFormater
|
|
379
385
|
};
|
|
380
386
|
};
|
|
381
387
|
exports.calcFormItemProps = calcFormItemProps;
|
|
382
|
-
var calcDisabled = function calcDisabled(disabled, form) {
|
|
383
|
-
if (!form
|
|
388
|
+
var calcDisabled = function calcDisabled(disabled, form, disabledCode, name, parentName) {
|
|
389
|
+
if (!form) return false;
|
|
390
|
+
if (disabledCode) {
|
|
391
|
+
var fn = eval(disabledCode);
|
|
392
|
+
if (typeof fn === 'function') {
|
|
393
|
+
try {
|
|
394
|
+
var value = form.getFieldValue(name);
|
|
395
|
+
var values = form.getFieldsValue(true);
|
|
396
|
+
return fn(value, values, {
|
|
397
|
+
moment: _dayjs.default,
|
|
398
|
+
get: _lodash.get
|
|
399
|
+
}, {
|
|
400
|
+
name: name,
|
|
401
|
+
parentName: parentName
|
|
402
|
+
});
|
|
403
|
+
} catch (_unused2) {
|
|
404
|
+
return false;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
if (!disabled) return false;
|
|
384
409
|
if (typeof disabled === 'boolean') return disabled;
|
|
385
410
|
if (Array.isArray(disabled)) {
|
|
386
411
|
var _iterator = _createForOfIteratorHelper(disabled),
|
|
@@ -455,12 +480,12 @@ var calcSelectValue = function calcSelectValue(selectValue, form) {
|
|
|
455
480
|
};
|
|
456
481
|
};
|
|
457
482
|
exports.calcSelectValue = calcSelectValue;
|
|
458
|
-
var calcShouldRender = function calcShouldRender(name) {
|
|
459
|
-
var dependencies = arguments.length >
|
|
460
|
-
var asserts = arguments.length >
|
|
461
|
-
var shouldRender = arguments.length >
|
|
462
|
-
var shouldRenderCode = arguments.length >
|
|
463
|
-
var form = arguments.length >
|
|
483
|
+
var calcShouldRender = function calcShouldRender(name, parentName) {
|
|
484
|
+
var dependencies = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
485
|
+
var asserts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
486
|
+
var shouldRender = arguments.length > 4 ? arguments[4] : undefined;
|
|
487
|
+
var shouldRenderCode = arguments.length > 5 ? arguments[5] : undefined;
|
|
488
|
+
var form = arguments.length > 6 ? arguments[6] : undefined;
|
|
464
489
|
if (!form) return true;
|
|
465
490
|
var _iterator3 = _createForOfIteratorHelper(dependencies),
|
|
466
491
|
_step3;
|
|
@@ -486,9 +511,13 @@ var calcShouldRender = function calcShouldRender(name) {
|
|
|
486
511
|
var value = form.getFieldValue(name);
|
|
487
512
|
var values = form.getFieldsValue(true);
|
|
488
513
|
return fn(value, values, {
|
|
489
|
-
moment: _dayjs.default
|
|
514
|
+
moment: _dayjs.default,
|
|
515
|
+
get: _lodash.get
|
|
516
|
+
}, {
|
|
517
|
+
name: name,
|
|
518
|
+
parentName: parentName
|
|
490
519
|
});
|
|
491
|
-
} catch (
|
|
520
|
+
} catch (_unused3) {
|
|
492
521
|
return false;
|
|
493
522
|
}
|
|
494
523
|
}
|
|
@@ -570,4 +599,44 @@ var getRuleValidation = /*#__PURE__*/function () {
|
|
|
570
599
|
return _ref3.apply(this, arguments);
|
|
571
600
|
};
|
|
572
601
|
}();
|
|
573
|
-
exports.getRuleValidation = getRuleValidation;
|
|
602
|
+
exports.getRuleValidation = getRuleValidation;
|
|
603
|
+
var isAddableSectionInnerField = function isAddableSectionInnerField(name, field, elements) {
|
|
604
|
+
var start = 0;
|
|
605
|
+
var hit = false;
|
|
606
|
+
while (start < name.length && start < field.length) {
|
|
607
|
+
if (name[start] === field[start]) {
|
|
608
|
+
hit = true;
|
|
609
|
+
start++;
|
|
610
|
+
} else {
|
|
611
|
+
if (hit) return false;
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
if (start === name.length) return true;
|
|
616
|
+
var restField = field.slice(start);
|
|
617
|
+
var _elements = elements;
|
|
618
|
+
var index = 0;
|
|
619
|
+
var isReactElement = elements.some(_react.default.isValidElement);
|
|
620
|
+
while (index < restField.length) {
|
|
621
|
+
var found = _elements.find(function (item) {
|
|
622
|
+
return (isReactElement ? item.props.name : item.name).toString() === restField[index];
|
|
623
|
+
});
|
|
624
|
+
if (!found) return false;
|
|
625
|
+
index++;
|
|
626
|
+
_elements = (isReactElement ? found.props.children : found.elements) || [];
|
|
627
|
+
}
|
|
628
|
+
return true;
|
|
629
|
+
};
|
|
630
|
+
|
|
631
|
+
// 暂时不考虑AddableSection嵌套的场景
|
|
632
|
+
var calcAddableSectionAssertField = function calcAddableSectionAssertField(name, field, index, elements) {
|
|
633
|
+
var _field = typeof field === 'string' ? field.split('.') : field;
|
|
634
|
+
if (!isAddableSectionInnerField(name, _field, elements)) return field;
|
|
635
|
+
if (!_field.join().startsWith(name.join())) return [].concat(_toConsumableArray(name), [index], _toConsumableArray(_field));
|
|
636
|
+
var _index = _field.findIndex(function (item) {
|
|
637
|
+
return item === name[name.length - 1];
|
|
638
|
+
});
|
|
639
|
+
if (_index === -1) return field;
|
|
640
|
+
return [].concat(_toConsumableArray(name), [index], _toConsumableArray(_field.slice(_index + 1)));
|
|
641
|
+
};
|
|
642
|
+
exports.calcAddableSectionAssertField = calcAddableSectionAssertField;
|