iglooform 2.5.45 → 2.5.47
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/es/form/element/index.js +16 -2
- package/es/form/element/style/index.less +8 -0
- package/es/form/hsteps/index.js +61 -26
- package/es/form/index.js +56 -11
- package/es/form/steps/index.js +62 -24
- package/es/form-context.d.ts +1 -0
- package/es/free-form/element/index.js +16 -2
- package/es/free-form/element/style/index.less +8 -0
- package/es/free-form/index.js +62 -13
- package/es/free-form/step/index.d.ts +1 -0
- package/es/free-form/step/index.js +60 -23
- package/es/types.d.ts +3 -0
- package/es/utils/form-utils.d.ts +1 -0
- package/es/utils/form-utils.js +74 -1
- package/es/utils/option-utils.d.ts +1 -0
- package/es/utils/option-utils.js +21 -13
- package/lib/form/element/index.js +17 -2
- package/lib/form/element/style/index.less +8 -0
- package/lib/form/hsteps/index.js +60 -25
- package/lib/form/index.js +57 -10
- package/lib/form/steps/index.js +62 -23
- package/lib/form-context.d.ts +1 -0
- package/lib/free-form/element/index.js +17 -2
- package/lib/free-form/element/style/index.less +8 -0
- package/lib/free-form/index.js +64 -12
- package/lib/free-form/step/index.d.ts +1 -0
- package/lib/free-form/step/index.js +60 -22
- package/lib/types.d.ts +3 -0
- package/lib/utils/form-utils.d.ts +1 -0
- package/lib/utils/form-utils.js +78 -2
- package/lib/utils/option-utils.d.ts +1 -0
- package/lib/utils/option-utils.js +21 -13
- package/package.json +1 -1
|
@@ -33,6 +33,8 @@ var _formUtils = require("../../utils/form-utils");
|
|
|
33
33
|
|
|
34
34
|
var _formContext = _interopRequireDefault(require("../../form-context"));
|
|
35
35
|
|
|
36
|
+
var _invariant = _interopRequireDefault(require("invariant"));
|
|
37
|
+
|
|
36
38
|
require("./style/index.less");
|
|
37
39
|
|
|
38
40
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -84,10 +86,12 @@ var Step = function Step(_ref) {
|
|
|
84
86
|
children = _ref.children,
|
|
85
87
|
shouldRender = _ref.shouldRender,
|
|
86
88
|
subscribedFields = _ref.subscribedFields,
|
|
87
|
-
buttonText = _ref.buttonText
|
|
89
|
+
buttonText = _ref.buttonText,
|
|
90
|
+
validationRule = _ref.validationRule;
|
|
88
91
|
|
|
89
92
|
var _useContext = (0, _react.useContext)(_locale.LocaleContext),
|
|
90
|
-
formatMessage = _useContext.formatMessage
|
|
93
|
+
formatMessage = _useContext.formatMessage,
|
|
94
|
+
currentLang = _useContext.currentLang;
|
|
91
95
|
|
|
92
96
|
var _useContext2 = (0, _react.useContext)(_formContext.default),
|
|
93
97
|
continueText = _useContext2.continueText,
|
|
@@ -95,6 +99,7 @@ var Step = function Step(_ref) {
|
|
|
95
99
|
submitting = _useContext2.submitting,
|
|
96
100
|
form = _useContext2.form,
|
|
97
101
|
showSubmitButton = _useContext2.showSubmitButton,
|
|
102
|
+
getRuleValidationApi = _useContext2.getRuleValidationApi,
|
|
98
103
|
getScrollContainer = _useContext2.getScrollContainer,
|
|
99
104
|
registerDependencies = _useContext2.registerDependencies;
|
|
100
105
|
|
|
@@ -112,6 +117,7 @@ var Step = function Step(_ref) {
|
|
|
112
117
|
_ = _useReducer2[0],
|
|
113
118
|
dispatch = _useReducer2[1];
|
|
114
119
|
|
|
120
|
+
(0, _invariant.default)(!validationRule || getRuleValidationApi, 'Please provide getRuleValidationApi in Form props');
|
|
115
121
|
(0, _react.useEffect)(function () {
|
|
116
122
|
if (shouldRender || getButtonDisabledState) {
|
|
117
123
|
registerDependencies(Array.isArray(subscribedFields) ? subscribedFields : 'SUBSCRIBE_ALL', dispatch);
|
|
@@ -171,12 +177,13 @@ var Step = function Step(_ref) {
|
|
|
171
177
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
172
178
|
var _allFields$filter;
|
|
173
179
|
|
|
174
|
-
var allFields, fields, errors;
|
|
180
|
+
var allFields, allValues, fields, res, errors;
|
|
175
181
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
176
182
|
while (1) {
|
|
177
183
|
switch (_context.prev = _context.next) {
|
|
178
184
|
case 0:
|
|
179
185
|
allFields = (form === null || form === void 0 ? void 0 : form.getFieldsError()) || [];
|
|
186
|
+
allValues = form === null || form === void 0 ? void 0 : form.getFieldsValue(true);
|
|
180
187
|
fields = allFields === null || allFields === void 0 ? void 0 : (_allFields$filter = allFields.filter(function (_ref3) {
|
|
181
188
|
var name = _ref3.name;
|
|
182
189
|
return name.join().startsWith(pName === null || pName === void 0 ? void 0 : pName.join());
|
|
@@ -184,54 +191,85 @@ var Step = function Step(_ref) {
|
|
|
184
191
|
var name = _ref4.name;
|
|
185
192
|
return name;
|
|
186
193
|
});
|
|
187
|
-
_context.prev =
|
|
188
|
-
_context.next =
|
|
194
|
+
_context.prev = 3;
|
|
195
|
+
_context.next = 6;
|
|
189
196
|
return form === null || form === void 0 ? void 0 : form.validateFields(fields);
|
|
190
197
|
|
|
191
|
-
case
|
|
192
|
-
_context.next =
|
|
198
|
+
case 6:
|
|
199
|
+
_context.next = 12;
|
|
193
200
|
break;
|
|
194
201
|
|
|
195
|
-
case
|
|
196
|
-
_context.prev =
|
|
197
|
-
_context.t0 = _context["catch"](
|
|
202
|
+
case 8:
|
|
203
|
+
_context.prev = 8;
|
|
204
|
+
_context.t0 = _context["catch"](3);
|
|
198
205
|
form === null || form === void 0 ? void 0 : form.scrollToField(_context.t0.errorFields[0].name);
|
|
199
206
|
return _context.abrupt("return");
|
|
200
207
|
|
|
201
|
-
case
|
|
208
|
+
case 12:
|
|
209
|
+
if (!(validationRule && getRuleValidationApi)) {
|
|
210
|
+
_context.next = 26;
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
_context.prev = 13;
|
|
215
|
+
_context.next = 16;
|
|
216
|
+
return (0, _formUtils.getRuleValidation)(getRuleValidationApi, validationRule, allValues, currentLang);
|
|
217
|
+
|
|
218
|
+
case 16:
|
|
219
|
+
res = _context.sent;
|
|
220
|
+
|
|
221
|
+
if (!(Array.isArray(res) && res.length)) {
|
|
222
|
+
_context.next = 21;
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
form === null || form === void 0 ? void 0 : form.setFields(res);
|
|
227
|
+
form === null || form === void 0 ? void 0 : form.scrollToField(res[0].name);
|
|
228
|
+
return _context.abrupt("return");
|
|
229
|
+
|
|
230
|
+
case 21:
|
|
231
|
+
_context.next = 26;
|
|
232
|
+
break;
|
|
233
|
+
|
|
234
|
+
case 23:
|
|
235
|
+
_context.prev = 23;
|
|
236
|
+
_context.t1 = _context["catch"](13);
|
|
237
|
+
return _context.abrupt("return");
|
|
238
|
+
|
|
239
|
+
case 26:
|
|
202
240
|
if (!(typeof handleNextProp === 'function')) {
|
|
203
|
-
_context.next =
|
|
241
|
+
_context.next = 37;
|
|
204
242
|
break;
|
|
205
243
|
}
|
|
206
244
|
|
|
207
|
-
_context.prev =
|
|
208
|
-
_context.next =
|
|
245
|
+
_context.prev = 27;
|
|
246
|
+
_context.next = 30;
|
|
209
247
|
return handleNextProp(form === null || form === void 0 ? void 0 : form.getFieldsValue(fields));
|
|
210
248
|
|
|
211
|
-
case
|
|
249
|
+
case 30:
|
|
212
250
|
errors = _context.sent;
|
|
213
251
|
|
|
214
252
|
if (Array.isArray(errors)) {
|
|
215
253
|
form === null || form === void 0 ? void 0 : form.setFields(errors);
|
|
216
254
|
}
|
|
217
255
|
|
|
218
|
-
_context.next =
|
|
256
|
+
_context.next = 37;
|
|
219
257
|
break;
|
|
220
258
|
|
|
221
|
-
case
|
|
222
|
-
_context.prev =
|
|
223
|
-
_context.
|
|
259
|
+
case 34:
|
|
260
|
+
_context.prev = 34;
|
|
261
|
+
_context.t2 = _context["catch"](27);
|
|
224
262
|
return _context.abrupt("return");
|
|
225
263
|
|
|
226
|
-
case
|
|
264
|
+
case 37:
|
|
227
265
|
handleNextStep && handleNextStep(fields);
|
|
228
266
|
|
|
229
|
-
case
|
|
267
|
+
case 38:
|
|
230
268
|
case "end":
|
|
231
269
|
return _context.stop();
|
|
232
270
|
}
|
|
233
271
|
}
|
|
234
|
-
}, _callee, null, [[
|
|
272
|
+
}, _callee, null, [[3, 8], [13, 23], [27, 34]]);
|
|
235
273
|
}));
|
|
236
274
|
|
|
237
275
|
return function handleNext() {
|
package/lib/types.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ export interface FormBasicConfig {
|
|
|
28
28
|
onFirstModified?: () => any;
|
|
29
29
|
uploadApi?: string;
|
|
30
30
|
selectDatasourceApi?: string;
|
|
31
|
+
validationRule?: string;
|
|
32
|
+
getRuleValidationApi?: string;
|
|
31
33
|
stepDirection?: 'vertical' | 'horizontal';
|
|
32
34
|
}
|
|
33
35
|
export declare type FormItemAssert = {
|
|
@@ -120,6 +122,7 @@ export interface FormItemExtraConfig extends FormItemProps {
|
|
|
120
122
|
minLength?: number;
|
|
121
123
|
maxLength?: number;
|
|
122
124
|
idType?: 'KTP' | 'NIK';
|
|
125
|
+
validationRule?: string;
|
|
123
126
|
[key: string]: any;
|
|
124
127
|
}
|
|
125
128
|
export interface FormItemConfig extends FormItemExtraConfig {
|
|
@@ -73,3 +73,4 @@ export declare const calcSelectValue: (selectValue?: FormItemSelectValue[] | und
|
|
|
73
73
|
disabled: boolean | undefined;
|
|
74
74
|
};
|
|
75
75
|
export declare const calcShouldRender: (dependencies?: NamePath[], asserts?: FormItemAssert[], shouldRender?: ((form?: FormInstance<any> | undefined) => boolean) | undefined, form?: FormInstance<any> | undefined) => boolean;
|
|
76
|
+
export declare const getRuleValidation: (url: string, rule: string | string[], values?: any, lang?: string | undefined) => Promise<any>;
|
package/lib/utils/form-utils.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.testAssert = exports.calcShouldRender = exports.calcSelectValue = exports.calcNamePath = exports.calcFormItemProps = exports.calcDisabled = exports.calcCopyValue = void 0;
|
|
6
|
+
exports.testAssert = exports.getRuleValidation = exports.calcShouldRender = exports.calcSelectValue = exports.calcNamePath = exports.calcFormItemProps = exports.calcDisabled = exports.calcCopyValue = void 0;
|
|
7
7
|
|
|
8
8
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
9
9
|
|
|
@@ -20,6 +20,10 @@ var _excluded = ["type", "name", "required", "requiredAsserts", "showOptional",
|
|
|
20
20
|
|
|
21
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
22
|
|
|
23
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
24
|
+
|
|
25
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
26
|
+
|
|
23
27
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
24
28
|
|
|
25
29
|
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; }
|
|
@@ -543,4 +547,76 @@ var calcShouldRender = function calcShouldRender() {
|
|
|
543
547
|
return true;
|
|
544
548
|
};
|
|
545
549
|
|
|
546
|
-
exports.calcShouldRender = calcShouldRender;
|
|
550
|
+
exports.calcShouldRender = calcShouldRender;
|
|
551
|
+
|
|
552
|
+
var getRuleValidation = /*#__PURE__*/function () {
|
|
553
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(url, rule, values, lang) {
|
|
554
|
+
var _lang, _lang$split;
|
|
555
|
+
|
|
556
|
+
var res, json, _ref4, conclusion, details;
|
|
557
|
+
|
|
558
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
559
|
+
while (1) {
|
|
560
|
+
switch (_context.prev = _context.next) {
|
|
561
|
+
case 0:
|
|
562
|
+
lang = ((_lang = lang) === null || _lang === void 0 ? void 0 : (_lang$split = _lang.split('-')) === null || _lang$split === void 0 ? void 0 : _lang$split[0]) || 'en';
|
|
563
|
+
_context.next = 3;
|
|
564
|
+
return fetch("".concat(url, "?lang=").concat(lang), {
|
|
565
|
+
method: 'post',
|
|
566
|
+
headers: {
|
|
567
|
+
'Content-Type': 'application/json; charset=utf-8'
|
|
568
|
+
},
|
|
569
|
+
body: JSON.stringify({
|
|
570
|
+
form: values || {},
|
|
571
|
+
rules: Array.isArray(rule) ? rule : [rule]
|
|
572
|
+
})
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
case 3:
|
|
576
|
+
res = _context.sent;
|
|
577
|
+
_context.next = 6;
|
|
578
|
+
return res.json();
|
|
579
|
+
|
|
580
|
+
case 6:
|
|
581
|
+
json = _context.sent;
|
|
582
|
+
_ref4 = json || {}, conclusion = _ref4.conclusion, details = _ref4.details;
|
|
583
|
+
|
|
584
|
+
if (!conclusion) {
|
|
585
|
+
_context.next = 10;
|
|
586
|
+
break;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
return _context.abrupt("return");
|
|
590
|
+
|
|
591
|
+
case 10:
|
|
592
|
+
if (!(conclusion === false)) {
|
|
593
|
+
_context.next = 12;
|
|
594
|
+
break;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
return _context.abrupt("return", details === null || details === void 0 ? void 0 : details.map(function (_ref5) {
|
|
598
|
+
var err_message = _ref5.err_message,
|
|
599
|
+
path = _ref5.path;
|
|
600
|
+
return {
|
|
601
|
+
name: path.split('.'),
|
|
602
|
+
errors: [err_message]
|
|
603
|
+
};
|
|
604
|
+
}));
|
|
605
|
+
|
|
606
|
+
case 12:
|
|
607
|
+
return _context.abrupt("return", Promise.reject(json.message));
|
|
608
|
+
|
|
609
|
+
case 13:
|
|
610
|
+
case "end":
|
|
611
|
+
return _context.stop();
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
}, _callee);
|
|
615
|
+
}));
|
|
616
|
+
|
|
617
|
+
return function getRuleValidation(_x, _x2, _x3, _x4) {
|
|
618
|
+
return _ref3.apply(this, arguments);
|
|
619
|
+
};
|
|
620
|
+
}();
|
|
621
|
+
|
|
622
|
+
exports.getRuleValidation = getRuleValidation;
|
|
@@ -15,7 +15,7 @@ var _formContext = _interopRequireDefault(require("../form-context"));
|
|
|
15
15
|
|
|
16
16
|
var _invariant = _interopRequireDefault(require("invariant"));
|
|
17
17
|
|
|
18
|
-
var _excluded = ["options", "optionGroups", "getOptions", "datasourceKey", "dependField", "children", "onSearch"];
|
|
18
|
+
var _excluded = ["options", "optionGroups", "getOptions", "datasourceFilters", "datasourceKey", "dependField", "children", "onSearch"];
|
|
19
19
|
|
|
20
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
21
|
|
|
@@ -107,6 +107,7 @@ function optionsHOC(Component) {
|
|
|
107
107
|
var options = props.options,
|
|
108
108
|
optionGroups = props.optionGroups,
|
|
109
109
|
getOptions = props.getOptions,
|
|
110
|
+
datasourceFilters = props.datasourceFilters,
|
|
110
111
|
datasourceKey = props.datasourceKey,
|
|
111
112
|
dependField = props.dependField,
|
|
112
113
|
children = props.children,
|
|
@@ -148,6 +149,7 @@ function optionsHOC(Component) {
|
|
|
148
149
|
}
|
|
149
150
|
}, [optionsFromGetOptions]);
|
|
150
151
|
(0, _invariant.default)(datasourceKey && selectDatasourceApi || !datasourceKey, 'Please provide selectDatasourceApi in Form props');
|
|
152
|
+
(0, _invariant.default)(datasourceFilters && datasourceKey && selectDatasourceApi || !datasourceFilters, 'Please provide selectDatasourceApi in Form props');
|
|
151
153
|
(0, _react.useEffect)(function () {
|
|
152
154
|
if (Array.isArray(optionsFromGetOptions)) {
|
|
153
155
|
return;
|
|
@@ -211,7 +213,7 @@ function optionsHOC(Component) {
|
|
|
211
213
|
|
|
212
214
|
case 9:
|
|
213
215
|
if (!(selectDatasourceApi && datasourceKey)) {
|
|
214
|
-
_context.next =
|
|
216
|
+
_context.next = 28;
|
|
215
217
|
break;
|
|
216
218
|
}
|
|
217
219
|
|
|
@@ -223,35 +225,41 @@ function optionsHOC(Component) {
|
|
|
223
225
|
query += "&search_keyword=".concat(searchKey);
|
|
224
226
|
}
|
|
225
227
|
|
|
228
|
+
if (datasourceFilters) {
|
|
229
|
+
query += datasourceFilters.map(function (f) {
|
|
230
|
+
return "filter=".concat(f);
|
|
231
|
+
}).join('&');
|
|
232
|
+
}
|
|
233
|
+
|
|
226
234
|
api = "".concat(selectDatasourceApi, "/").concat(datasourceKey);
|
|
227
|
-
_context.prev =
|
|
228
|
-
_context.next =
|
|
235
|
+
_context.prev = 14;
|
|
236
|
+
_context.next = 17;
|
|
229
237
|
return fetch(query ? "".concat(api, "?").concat(query) : api);
|
|
230
238
|
|
|
231
|
-
case
|
|
239
|
+
case 17:
|
|
232
240
|
rst = _context.sent;
|
|
233
|
-
_context.next =
|
|
241
|
+
_context.next = 20;
|
|
234
242
|
return rst.json();
|
|
235
243
|
|
|
236
|
-
case
|
|
244
|
+
case 20:
|
|
237
245
|
_yield$rst$json = _context.sent;
|
|
238
246
|
data = _yield$rst$json.data;
|
|
239
247
|
return _context.abrupt("return", data || []);
|
|
240
248
|
|
|
241
|
-
case
|
|
242
|
-
_context.prev =
|
|
243
|
-
_context.t0 = _context["catch"](
|
|
249
|
+
case 25:
|
|
250
|
+
_context.prev = 25;
|
|
251
|
+
_context.t0 = _context["catch"](14);
|
|
244
252
|
return _context.abrupt("return", []);
|
|
245
253
|
|
|
246
|
-
case
|
|
254
|
+
case 28:
|
|
247
255
|
return _context.abrupt("return", []);
|
|
248
256
|
|
|
249
|
-
case
|
|
257
|
+
case 29:
|
|
250
258
|
case "end":
|
|
251
259
|
return _context.stop();
|
|
252
260
|
}
|
|
253
261
|
}
|
|
254
|
-
}, _callee, null, [[
|
|
262
|
+
}, _callee, null, [[14, 25]]);
|
|
255
263
|
}));
|
|
256
264
|
|
|
257
265
|
return function calcOptions() {
|