@maif/react-forms 1.0.60 → 1.1.2
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/README.md +21 -0
- package/lib/esm/index.js +1290 -2772
- package/lib/index.d.ts +364 -0
- package/lib/index.js +1304 -2786
- package/package.json +23 -15
package/lib/index.js
CHANGED
|
@@ -11,7 +11,7 @@ var reactFeather = require('react-feather');
|
|
|
11
11
|
var reactHookForm = require('react-hook-form');
|
|
12
12
|
var reactRainbowComponents = require('react-rainbow-components');
|
|
13
13
|
var ReactToolTip = require('react-tooltip');
|
|
14
|
-
var uuid = require('uuid');
|
|
14
|
+
var uuid$1 = require('uuid');
|
|
15
15
|
var CreatableSelect = require('react-select/creatable');
|
|
16
16
|
var Select = require('react-select');
|
|
17
17
|
var hash$1 = require('object-hash');
|
|
@@ -23,25 +23,26 @@ var hljs = require('highlight.js');
|
|
|
23
23
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
24
24
|
|
|
25
25
|
function _interopNamespace(e) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
if (e && e.__esModule) return e;
|
|
27
|
+
var n = Object.create(null);
|
|
28
|
+
if (e) {
|
|
29
|
+
Object.keys(e).forEach(function (k) {
|
|
30
|
+
if (k !== 'default') {
|
|
31
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
32
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () { return e[k]; }
|
|
35
|
+
});
|
|
36
|
+
}
|
|
35
37
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
n["default"] = e;
|
|
40
|
-
return Object.freeze(n);
|
|
38
|
+
}
|
|
39
|
+
n["default"] = e;
|
|
40
|
+
return Object.freeze(n);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
var yup__namespace = /*#__PURE__*/_interopNamespace(yup);
|
|
44
44
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
45
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
45
46
|
var classNames__default = /*#__PURE__*/_interopDefaultLegacy(classNames);
|
|
46
47
|
var deepEqual__default = /*#__PURE__*/_interopDefaultLegacy(deepEqual);
|
|
47
48
|
var ReactToolTip__default = /*#__PURE__*/_interopDefaultLegacy(ReactToolTip);
|
|
@@ -51,1124 +52,483 @@ var hash__default = /*#__PURE__*/_interopDefaultLegacy(hash$1);
|
|
|
51
52
|
var showdown__default = /*#__PURE__*/_interopDefaultLegacy(showdown);
|
|
52
53
|
var hljs__default = /*#__PURE__*/_interopDefaultLegacy(hljs);
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
var format = {
|
|
65
|
-
array: 'array',
|
|
66
|
-
select: 'select',
|
|
67
|
-
code: 'code',
|
|
68
|
-
markdown: 'markdown',
|
|
69
|
-
text: 'textarea',
|
|
70
|
-
textarea: 'textarea',
|
|
71
|
-
email: 'email',
|
|
72
|
-
password: 'password',
|
|
73
|
-
hidden: 'hidden',
|
|
74
|
-
form: 'form',
|
|
75
|
-
buttonsSelect: 'buttons',
|
|
76
|
-
singleLineCode: 'singleLineCode'
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
var _required = function required() {
|
|
80
|
-
var message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "Value required";
|
|
81
|
-
return function (r) {
|
|
82
|
-
return r.required(message);
|
|
83
|
-
};
|
|
84
|
-
}; //string
|
|
85
|
-
|
|
86
|
-
var _url = function url() {
|
|
87
|
-
var message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "That is not a valid url";
|
|
88
|
-
return function (r) {
|
|
89
|
-
return r.url(message);
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
var _email = function email() {
|
|
94
|
-
var message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "That is not a valid email";
|
|
95
|
-
return function (r) {
|
|
96
|
-
return r.email(message);
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
var _uuid = function uuid() {
|
|
101
|
-
var message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "That is not a valid uuid";
|
|
102
|
-
return function (r) {
|
|
103
|
-
return r.uuid(message);
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
var _matches = function matches() {
|
|
108
|
-
var regexp = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : /.*/;
|
|
109
|
-
var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "This field does not match the pattern";
|
|
110
|
-
return function (r) {
|
|
111
|
-
return r.matches(regexp, {
|
|
112
|
-
message: message,
|
|
113
|
-
excludeEmptyString: true
|
|
114
|
-
});
|
|
115
|
-
};
|
|
116
|
-
}; //string & number
|
|
117
|
-
|
|
118
|
-
var _min = function min(ref) {
|
|
119
|
-
var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "Min value is required";
|
|
120
|
-
return function (r) {
|
|
121
|
-
return r.min(maybeRef(ref), message);
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
var _max = function max(ref) {
|
|
126
|
-
var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "Max value is required";
|
|
127
|
-
return function (r) {
|
|
128
|
-
return r.max(maybeRef(ref), message);
|
|
129
|
-
};
|
|
130
|
-
}; //number
|
|
131
|
-
|
|
132
|
-
var _positive = function positive() {
|
|
133
|
-
var message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "Positive value is required";
|
|
134
|
-
return function (r) {
|
|
135
|
-
return r.positive(message);
|
|
136
|
-
};
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
var _negative = function negative() {
|
|
140
|
-
var message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "Negative value is required";
|
|
141
|
-
return function (r) {
|
|
142
|
-
return r.negative(message);
|
|
143
|
-
};
|
|
55
|
+
const type = {
|
|
56
|
+
string: "string",
|
|
57
|
+
number: "number",
|
|
58
|
+
bool: "bool",
|
|
59
|
+
date: "date",
|
|
60
|
+
object: "object",
|
|
61
|
+
file: "file",
|
|
62
|
+
json: "json"
|
|
144
63
|
};
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
64
|
+
function stringTuple$1(...data) {
|
|
65
|
+
return data;
|
|
66
|
+
}
|
|
67
|
+
stringTuple$1(...Object.values(type));
|
|
68
|
+
|
|
69
|
+
const format = {
|
|
70
|
+
array: "array",
|
|
71
|
+
select: "select",
|
|
72
|
+
code: "code",
|
|
73
|
+
markdown: "markdown",
|
|
74
|
+
text: "textarea",
|
|
75
|
+
textarea: "textarea",
|
|
76
|
+
email: "email",
|
|
77
|
+
password: "password",
|
|
78
|
+
hidden: "hidden",
|
|
79
|
+
form: "form",
|
|
80
|
+
buttonsSelect: "buttons",
|
|
81
|
+
singleLineCode: "singleLineCode"
|
|
151
82
|
};
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
83
|
+
function stringTuple(...data) {
|
|
84
|
+
return data;
|
|
85
|
+
}
|
|
86
|
+
stringTuple(...Object.values(format));
|
|
87
|
+
|
|
88
|
+
const required = (message = "Value required") => (r) => r.required(message);
|
|
89
|
+
//string
|
|
90
|
+
const url = (message = "That is not a valid url") => (r) => r.url(message);
|
|
91
|
+
const email = (message = "That is not a valid email") => (r) => r.email(message);
|
|
92
|
+
const uuid = (message = "That is not a valid uuid") => (r) => r.uuid(message);
|
|
93
|
+
const matches = (regexp = /.*/, message = "This field does not match the pattern") => (r) => r.matches(regexp, { message, excludeEmptyString: true });
|
|
94
|
+
//string & number
|
|
95
|
+
const min = (ref, message = "Min value is required") => (r) => r.min(maybeRef(ref), message);
|
|
96
|
+
const max = (ref, message = "Max value is required") => (r) => r.max(maybeRef(ref), message);
|
|
97
|
+
//number
|
|
98
|
+
const positive = (message = "Positive value is required") => (r) => r.positive(message);
|
|
99
|
+
const negative = (message = "Negative value is required") => (r) => r.negative(message);
|
|
100
|
+
const integer = (message = "an integer please") => (r) => r.integer(message);
|
|
101
|
+
const lessThan$1 = (ref, message = `This field must be less than ${ref}`) => (r, key /* FIXME */, dependencies) => {
|
|
156
102
|
if (typeof ref !== 'number') {
|
|
157
|
-
|
|
103
|
+
dependencies.push([key, ref]);
|
|
158
104
|
}
|
|
159
|
-
|
|
160
105
|
return r.lessThan(maybeRef(ref), message);
|
|
161
|
-
};
|
|
162
106
|
};
|
|
163
|
-
|
|
164
|
-
var _moreThan = function moreThan(ref) {
|
|
165
|
-
var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "This field must be more than ".concat(ref);
|
|
166
|
-
return function (r, key, dependencies) {
|
|
107
|
+
const moreThan = (ref, message = `This field must be more than ${ref}`) => (r, key, dependencies) => {
|
|
167
108
|
if (typeof ref !== 'number') {
|
|
168
|
-
|
|
109
|
+
dependencies.push([key, ref]);
|
|
169
110
|
}
|
|
170
|
-
|
|
171
111
|
return r.moreThan(maybeRef(ref), message);
|
|
172
|
-
};
|
|
173
|
-
}; //array
|
|
174
|
-
|
|
175
|
-
var _length = function length(ref) {
|
|
176
|
-
var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "The size of this collection must be ".concat(ref);
|
|
177
|
-
return function (r) {
|
|
178
|
-
return r.length(maybeRef(ref), message);
|
|
179
|
-
};
|
|
180
|
-
}; //file
|
|
181
|
-
|
|
182
|
-
var _supportedFormat = function supportedFormat(arrayOfValues) {
|
|
183
|
-
var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Unsupported File Format';
|
|
184
|
-
return function (r) {
|
|
185
|
-
var SUPPORTED_FORMATS = arrayOfValues.map(function (f) {
|
|
186
|
-
return f.toLowerCase();
|
|
187
|
-
});
|
|
188
|
-
return r.test('supportedFormat', message, function (value) {
|
|
189
|
-
if (!value.length) return true;
|
|
190
|
-
return SUPPORTED_FORMATS.some(function (format) {
|
|
191
|
-
return value[0].type.toLowerCase().includes(format);
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
};
|
|
195
112
|
};
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
113
|
+
//array
|
|
114
|
+
const length = (ref, message = `The size of this collection must be ${ref}`) => (r) => r.length(maybeRef(ref), message);
|
|
115
|
+
//file
|
|
116
|
+
const supportedFormat = (arrayOfValues, message = 'Unsupported File Format') => (r /* TODO check */) => {
|
|
117
|
+
const SUPPORTED_FORMATS = arrayOfValues.map(f => f.toLowerCase());
|
|
118
|
+
return r.test('supportedFormat', message, (value) => {
|
|
119
|
+
if (!value.length)
|
|
120
|
+
return true;
|
|
121
|
+
return SUPPORTED_FORMATS.some(format => value[0].type.toLowerCase().includes(format));
|
|
202
122
|
});
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
123
|
+
};
|
|
124
|
+
const unsupportedFormat = (arrayOfValues, message = 'Unsupported File Format') => (r) => {
|
|
125
|
+
const UNSUPPORTED_FORMATS = arrayOfValues.map(f => f.toLowerCase());
|
|
126
|
+
return r.test('unsupportedFormat', message, (value) => {
|
|
127
|
+
if (!value.length)
|
|
128
|
+
return true;
|
|
129
|
+
return UNSUPPORTED_FORMATS.some(format => value[0].type.toLowerCase().includes(format));
|
|
208
130
|
});
|
|
209
|
-
};
|
|
210
131
|
};
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
if (!value.length) return true;
|
|
217
|
-
return value[0].size <= maybeRef(ref);
|
|
132
|
+
const maxSize = (ref, message = `size is excedeed ${ref}`) => (r) => {
|
|
133
|
+
return r.test('fileSize', message, (value) => {
|
|
134
|
+
if (!value.length)
|
|
135
|
+
return true;
|
|
136
|
+
return value[0].size <= maybeRef(ref);
|
|
218
137
|
});
|
|
219
|
-
};
|
|
220
|
-
}; //mixed
|
|
221
|
-
|
|
222
|
-
var _test = function test(name) {
|
|
223
|
-
var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Test failed';
|
|
224
|
-
var test = arguments.length > 2 ? arguments[2] : undefined;
|
|
225
|
-
return function (r) {
|
|
226
|
-
return r.test(name, message, test);
|
|
227
|
-
};
|
|
228
138
|
};
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
var otherwise = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
233
|
-
return function (r, key, dependencies) {
|
|
139
|
+
//mixed
|
|
140
|
+
const test = (name, message = 'Test failed', test) => (r) => r.test(name, message, test);
|
|
141
|
+
const when = (ref, test, then = [], otherwise = []) => (r, key, dependencies) => {
|
|
234
142
|
// dependencies.push([key, ref])
|
|
235
|
-
|
|
236
|
-
|
|
143
|
+
const thenReducer = then.reduce((resolver, constraint) => {
|
|
144
|
+
return constraint(resolver, key, dependencies);
|
|
237
145
|
}, r);
|
|
238
|
-
|
|
239
|
-
|
|
146
|
+
const otherWiseReducer = otherwise.reduce((resolver, constraint) => {
|
|
147
|
+
return constraint(resolver, key, dependencies);
|
|
240
148
|
}, r);
|
|
241
|
-
return r.when(ref, {
|
|
242
|
-
is: test,
|
|
243
|
-
then: thenReducer,
|
|
244
|
-
otherwise: otherWiseReducer
|
|
245
|
-
});
|
|
246
|
-
};
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
var _oneOf = function oneOf(arrayOfValues) {
|
|
250
|
-
var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "This value must be one of ".concat(arrayOfValues.join(', '));
|
|
251
|
-
return function (r) {
|
|
252
|
-
return r.oneOf(arrayOfValues.map(maybeRef), message);
|
|
253
|
-
};
|
|
254
|
-
}; //todo: rename by notOneOf
|
|
255
|
-
|
|
256
|
-
var _blacklist = function blacklist(arrayOfValues) {
|
|
257
|
-
var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "This value can't include the following values ".concat(arrayOfValues.join(', '));
|
|
258
|
-
return function (r) {
|
|
259
|
-
return r.test('blacklist', message, function (value) {
|
|
260
|
-
return !arrayOfValues.some(function (f) {
|
|
261
|
-
return (value || '').includes(f);
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
};
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
var _ref21 = function ref(_ref) {
|
|
268
|
-
return yup__namespace.ref(_ref);
|
|
149
|
+
return r.when(ref, { is: test, then: thenReducer, otherwise: otherWiseReducer });
|
|
269
150
|
};
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
_ref6$message = _ref6.message,
|
|
301
|
-
message = _ref6$message === void 0 ? "This field does not match the pattern" : _ref6$message;
|
|
302
|
-
return _matches(regexp, message);
|
|
303
|
-
},
|
|
304
|
-
min: function min(_ref7) {
|
|
305
|
-
var ref = _ref7.ref,
|
|
306
|
-
_ref7$message = _ref7.message,
|
|
307
|
-
message = _ref7$message === void 0 ? "Min value is required" : _ref7$message;
|
|
308
|
-
return _min(ref, message);
|
|
309
|
-
},
|
|
310
|
-
max: function max(_ref8) {
|
|
311
|
-
var ref = _ref8.ref,
|
|
312
|
-
_ref8$message = _ref8.message,
|
|
313
|
-
message = _ref8$message === void 0 ? "Max value is required" : _ref8$message;
|
|
314
|
-
return _max(ref, message);
|
|
315
|
-
},
|
|
316
|
-
positive: function positive(_ref9) {
|
|
317
|
-
var _ref9$message = _ref9.message,
|
|
318
|
-
message = _ref9$message === void 0 ? "Positive value is required" : _ref9$message;
|
|
319
|
-
return _positive(message);
|
|
320
|
-
},
|
|
321
|
-
negative: function negative(_ref10) {
|
|
322
|
-
var _ref10$message = _ref10.message,
|
|
323
|
-
message = _ref10$message === void 0 ? "Negative value is required" : _ref10$message;
|
|
324
|
-
return _negative(message);
|
|
325
|
-
},
|
|
326
|
-
integer: function integer(_ref11) {
|
|
327
|
-
var _ref11$message = _ref11.message,
|
|
328
|
-
message = _ref11$message === void 0 ? "an integer please" : _ref11$message;
|
|
329
|
-
return _integer(message);
|
|
330
|
-
},
|
|
331
|
-
lessThan: function lessThan(_ref12) {
|
|
332
|
-
var ref = _ref12.ref,
|
|
333
|
-
_ref12$message = _ref12.message,
|
|
334
|
-
message = _ref12$message === void 0 ? "This field must be less than ".concat(ref) : _ref12$message;
|
|
335
|
-
return _lessThan(ref, message);
|
|
336
|
-
},
|
|
337
|
-
moreThan: function moreThan(_ref13) {
|
|
338
|
-
var ref = _ref13.ref,
|
|
339
|
-
_ref13$message = _ref13.message,
|
|
340
|
-
message = _ref13$message === void 0 ? "This field must be more than ".concat(ref) : _ref13$message;
|
|
341
|
-
return _moreThan(ref, message);
|
|
342
|
-
},
|
|
343
|
-
length: function length(_ref14) {
|
|
344
|
-
var ref = _ref14.ref,
|
|
345
|
-
_ref14$message = _ref14.message,
|
|
346
|
-
message = _ref14$message === void 0 ? "The size of this collection must be ".concat(ref) : _ref14$message;
|
|
347
|
-
return _length(ref, message);
|
|
348
|
-
},
|
|
349
|
-
supportedFormat: function supportedFormat(_ref15) {
|
|
350
|
-
var arrayOfValues = _ref15.arrayOfValues,
|
|
351
|
-
_ref15$message = _ref15.message,
|
|
352
|
-
message = _ref15$message === void 0 ? 'Unsupported File Format' : _ref15$message;
|
|
353
|
-
return _supportedFormat(arrayOfValues, message);
|
|
354
|
-
},
|
|
355
|
-
unsupportedFormat: function unsupportedFormat(_ref16) {
|
|
356
|
-
var arrayOfValues = _ref16.arrayOfValues,
|
|
357
|
-
_ref16$message = _ref16.message,
|
|
358
|
-
message = _ref16$message === void 0 ? 'Unsupported File Format' : _ref16$message;
|
|
359
|
-
return _unsupportedFormat(arrayOfValues, message);
|
|
360
|
-
},
|
|
361
|
-
maxSize: function maxSize(_ref17) {
|
|
362
|
-
var ref = _ref17.ref,
|
|
363
|
-
_ref17$message = _ref17.message,
|
|
364
|
-
message = _ref17$message === void 0 ? "size is excedeed ".concat(ref) : _ref17$message;
|
|
365
|
-
return _maxSize(ref, message);
|
|
366
|
-
},
|
|
367
|
-
test: function test(c) {
|
|
368
|
-
return _test(c.name, c.message, c.test);
|
|
369
|
-
},
|
|
370
|
-
when: function when(_ref18) {
|
|
371
|
-
var ref = _ref18.ref,
|
|
372
|
-
test = _ref18.test,
|
|
373
|
-
_ref18$then = _ref18.then,
|
|
374
|
-
then = _ref18$then === void 0 ? [] : _ref18$then,
|
|
375
|
-
_ref18$otherwise = _ref18.otherwise,
|
|
376
|
-
otherwise = _ref18$otherwise === void 0 ? [] : _ref18$otherwise;
|
|
377
|
-
return _when(ref, test, then, otherwise);
|
|
378
|
-
},
|
|
379
|
-
oneOf: function oneOf(_ref19) {
|
|
380
|
-
var arrayOfValues = _ref19.arrayOfValues,
|
|
381
|
-
_ref19$message = _ref19.message,
|
|
382
|
-
message = _ref19$message === void 0 ? "This value must be one of ".concat(arrayOfValues.join(', ')) : _ref19$message;
|
|
383
|
-
return _oneOf(arrayOfValues, message);
|
|
384
|
-
},
|
|
385
|
-
blacklist: function blacklist(_ref20) {
|
|
386
|
-
var arrayOfValues = _ref20.arrayOfValues,
|
|
387
|
-
_ref20$message = _ref20.message,
|
|
388
|
-
message = _ref20$message === void 0 ? "This value can't include the following values ".concat(arrayOfValues.join(', ')) : _ref20$message;
|
|
389
|
-
return _blacklist(arrayOfValues, message);
|
|
390
|
-
},
|
|
391
|
-
ref: function ref(val) {
|
|
392
|
-
return _ref21(val.ref);
|
|
393
|
-
}
|
|
151
|
+
const oneOf = (arrayOfValues, message = `This value must be one of ${arrayOfValues.join(', ')}`) => (r) => r.oneOf(arrayOfValues.map(maybeRef), message);
|
|
152
|
+
//todo: rename by notOneOf
|
|
153
|
+
const blacklist = (arrayOfValues, message = `This value can't include the following values ${arrayOfValues.join(', ')}`) => (r) => r.test('blacklist', message, value => {
|
|
154
|
+
return !arrayOfValues.some(f => (value || '').includes(f));
|
|
155
|
+
});
|
|
156
|
+
const ref = (ref) => yup__namespace.ref(ref);
|
|
157
|
+
const maybeRef = (x) => (x === null || x === void 0 ? void 0 : x.ref) ? ref(x.ref) : x;
|
|
158
|
+
//### JSON method ###
|
|
159
|
+
const jsonConstraints = {
|
|
160
|
+
required: ({ message = "Value required" }) => required(message),
|
|
161
|
+
url: ({ message = "That is not a valid url" }) => url(message),
|
|
162
|
+
email: ({ message = "That is not a valid email" }) => email(message),
|
|
163
|
+
uuid: ({ message = "That is not a valid uuid" }) => uuid(message),
|
|
164
|
+
matches: ({ regexp = /.*/, message = "This field does not match the pattern" }) => matches(regexp, message),
|
|
165
|
+
min: ({ ref, message = "Min value is required" }) => min(ref, message),
|
|
166
|
+
max: ({ ref, message = "Max value is required" }) => max(ref, message),
|
|
167
|
+
positive: ({ message = "Positive value is required" }) => positive(message),
|
|
168
|
+
negative: ({ message = "Negative value is required" }) => negative(message),
|
|
169
|
+
integer: ({ message = "an integer please" }) => integer(message),
|
|
170
|
+
lessThan: ({ ref, message = `This field must be less than ${ref}` }) => lessThan$1(ref, message),
|
|
171
|
+
moreThan: ({ ref, message = `This field must be more than ${ref}` }) => moreThan(ref, message),
|
|
172
|
+
length: ({ ref, message = `The size of this collection must be ${ref}` }) => length(ref, message),
|
|
173
|
+
supportedFormat: ({ arrayOfValues, message = 'Unsupported File Format' }) => supportedFormat(arrayOfValues, message),
|
|
174
|
+
unsupportedFormat: ({ arrayOfValues, message = 'Unsupported File Format' }) => unsupportedFormat(arrayOfValues, message),
|
|
175
|
+
maxSize: ({ ref, message = `size is excedeed ${ref}` }) => maxSize(ref, message),
|
|
176
|
+
test: (c) => test(c.name, c.message, c.test),
|
|
177
|
+
when: ({ ref, test, then = [], otherwise = [] }) => when(ref, test, then, otherwise),
|
|
178
|
+
oneOf: ({ arrayOfValues, message = `This value must be one of ${arrayOfValues.join(', ')}` }) => oneOf(arrayOfValues, message),
|
|
179
|
+
blacklist: ({ arrayOfValues, message = `This value can't include the following values ${arrayOfValues.join(', ')}` }) => blacklist(arrayOfValues, message),
|
|
180
|
+
ref: (val) => ref(val.ref)
|
|
394
181
|
};
|
|
395
182
|
|
|
396
183
|
var constraints = /*#__PURE__*/Object.freeze({
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
184
|
+
__proto__: null,
|
|
185
|
+
required: required,
|
|
186
|
+
url: url,
|
|
187
|
+
email: email,
|
|
188
|
+
uuid: uuid,
|
|
189
|
+
matches: matches,
|
|
190
|
+
min: min,
|
|
191
|
+
max: max,
|
|
192
|
+
positive: positive,
|
|
193
|
+
negative: negative,
|
|
194
|
+
integer: integer,
|
|
195
|
+
lessThan: lessThan$1,
|
|
196
|
+
moreThan: moreThan,
|
|
197
|
+
length: length,
|
|
198
|
+
supportedFormat: supportedFormat,
|
|
199
|
+
unsupportedFormat: unsupportedFormat,
|
|
200
|
+
maxSize: maxSize,
|
|
201
|
+
test: test,
|
|
202
|
+
when: when,
|
|
203
|
+
oneOf: oneOf,
|
|
204
|
+
blacklist: blacklist,
|
|
205
|
+
ref: ref,
|
|
206
|
+
jsonConstraints: jsonConstraints
|
|
420
207
|
});
|
|
421
208
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
427
|
-
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
428
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
429
|
-
})), keys.push.apply(keys, symbols);
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
return keys;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
function _objectSpread2$1(target) {
|
|
436
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
437
|
-
var source = null != arguments[i] ? arguments[i] : {};
|
|
438
|
-
i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) {
|
|
439
|
-
_defineProperty$1(target, key, source[key]);
|
|
440
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) {
|
|
441
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
return target;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
function _typeof$1(obj) {
|
|
449
|
-
"@babel/helpers - typeof";
|
|
450
|
-
|
|
451
|
-
return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
452
|
-
return typeof obj;
|
|
453
|
-
} : function (obj) {
|
|
454
|
-
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
455
|
-
}, _typeof$1(obj);
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
function _defineProperty$1(obj, key, value) {
|
|
459
|
-
if (key in obj) {
|
|
460
|
-
Object.defineProperty(obj, key, {
|
|
461
|
-
value: value,
|
|
462
|
-
enumerable: true,
|
|
463
|
-
configurable: true,
|
|
464
|
-
writable: true
|
|
465
|
-
});
|
|
466
|
-
} else {
|
|
467
|
-
obj[key] = value;
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
return obj;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
function _extends() {
|
|
474
|
-
_extends = Object.assign || function (target) {
|
|
475
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
476
|
-
var source = arguments[i];
|
|
477
|
-
|
|
478
|
-
for (var key in source) {
|
|
479
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
480
|
-
target[key] = source[key];
|
|
209
|
+
const BooleanInput = React__default["default"].forwardRef(({ onChange, value, readOnly }, ref) => {
|
|
210
|
+
const handleClick = (value) => {
|
|
211
|
+
if (!readOnly) {
|
|
212
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(value);
|
|
481
213
|
}
|
|
482
|
-
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
function _readOnlyError(name) {
|
|
492
|
-
throw new TypeError("\"" + name + "\" is read-only");
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
function _slicedToArray(arr, i) {
|
|
496
|
-
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray$1(arr, i) || _nonIterableRest();
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
function _toConsumableArray$1(arr) {
|
|
500
|
-
return _arrayWithoutHoles$1(arr) || _iterableToArray$1(arr) || _unsupportedIterableToArray$1(arr) || _nonIterableSpread$1();
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
function _arrayWithoutHoles$1(arr) {
|
|
504
|
-
if (Array.isArray(arr)) return _arrayLikeToArray$1(arr);
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
function _arrayWithHoles(arr) {
|
|
508
|
-
if (Array.isArray(arr)) return arr;
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
function _iterableToArray$1(iter) {
|
|
512
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
function _iterableToArrayLimit(arr, i) {
|
|
516
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
517
|
-
|
|
518
|
-
if (_i == null) return;
|
|
519
|
-
var _arr = [];
|
|
520
|
-
var _n = true;
|
|
521
|
-
var _d = false;
|
|
522
|
-
|
|
523
|
-
var _s, _e;
|
|
524
|
-
|
|
525
|
-
try {
|
|
526
|
-
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
527
|
-
_arr.push(_s.value);
|
|
528
|
-
|
|
529
|
-
if (i && _arr.length === i) break;
|
|
530
|
-
}
|
|
531
|
-
} catch (err) {
|
|
532
|
-
_d = true;
|
|
533
|
-
_e = err;
|
|
534
|
-
} finally {
|
|
535
|
-
try {
|
|
536
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
537
|
-
} finally {
|
|
538
|
-
if (_d) throw _e;
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
return _arr;
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
function _unsupportedIterableToArray$1(o, minLen) {
|
|
546
|
-
if (!o) return;
|
|
547
|
-
if (typeof o === "string") return _arrayLikeToArray$1(o, minLen);
|
|
548
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
549
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
550
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
551
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen);
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
function _arrayLikeToArray$1(arr, len) {
|
|
555
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
556
|
-
|
|
557
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
558
|
-
|
|
559
|
-
return arr2;
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
function _nonIterableSpread$1() {
|
|
563
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
function _nonIterableRest() {
|
|
567
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
var BooleanInput = /*#__PURE__*/React__default["default"].forwardRef(function (_ref, ref) {
|
|
571
|
-
var _classNames;
|
|
572
|
-
|
|
573
|
-
var onChange = _ref.onChange,
|
|
574
|
-
value = _ref.value,
|
|
575
|
-
readOnly = _ref.readOnly;
|
|
576
|
-
|
|
577
|
-
var handleClick = function handleClick(value) {
|
|
578
|
-
if (!readOnly) {
|
|
579
|
-
onChange(value);
|
|
580
|
-
}
|
|
581
|
-
};
|
|
582
|
-
|
|
583
|
-
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
584
|
-
className: classNames__default["default"]((_classNames = {}, _defineProperty$1(_classNames, 'mrf-cursor_pointer', !readOnly), _defineProperty$1(_classNames, 'mrf-cursor_not_allowed', readOnly), _classNames))
|
|
585
|
-
}, !!value && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
586
|
-
className: classNames__default["default"]('mrf-content_switch_button_on'),
|
|
587
|
-
onClick: function onClick() {
|
|
588
|
-
return handleClick(false);
|
|
589
|
-
}
|
|
590
|
-
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
591
|
-
className: classNames__default["default"]('mrf-switch_button_on')
|
|
592
|
-
})), !value && value !== null && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
593
|
-
className: classNames__default["default"]('mrf-content_switch_button_off'),
|
|
594
|
-
onClick: function onClick() {
|
|
595
|
-
return handleClick(true);
|
|
596
|
-
}
|
|
597
|
-
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
598
|
-
className: classNames__default["default"]('mrf-switch_button_off')
|
|
599
|
-
})), value === null && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
600
|
-
className: classNames__default["default"]('mrf-content_switch_button_null'),
|
|
601
|
-
onClick: function onClick() {
|
|
602
|
-
return handleClick(true);
|
|
603
|
-
}
|
|
604
|
-
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
605
|
-
className: classNames__default["default"]('mrf-switch_button_null')
|
|
606
|
-
})));
|
|
214
|
+
};
|
|
215
|
+
return (React__default["default"].createElement("div", { className: classNames__default["default"]({ ['mrf-cursor_pointer']: !readOnly, ['mrf-cursor_not_allowed']: readOnly }) },
|
|
216
|
+
!!value && React__default["default"].createElement("div", { className: classNames__default["default"]('mrf-content_switch_button_on'), onClick: () => handleClick(false) },
|
|
217
|
+
React__default["default"].createElement("div", { className: classNames__default["default"]('mrf-switch_button_on') })),
|
|
218
|
+
!value && value !== null && React__default["default"].createElement("div", { className: classNames__default["default"]('mrf-content_switch_button_off'), onClick: () => handleClick(true) },
|
|
219
|
+
React__default["default"].createElement("div", { className: classNames__default["default"]('mrf-switch_button_off') })),
|
|
220
|
+
value === null && React__default["default"].createElement("div", { className: classNames__default["default"]('mrf-content_switch_button_null'), onClick: () => handleClick(true) },
|
|
221
|
+
React__default["default"].createElement("div", { className: classNames__default["default"]('mrf-switch_button_null') }))));
|
|
607
222
|
});
|
|
608
223
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
}, props.label), /*#__PURE__*/React__default["default"].createElement("button", {
|
|
630
|
-
type: "button",
|
|
631
|
-
className: classNames__default["default"]('mrf-btn', 'mrf-btn_sm', 'mrf-ml_5', _defineProperty$1({}, 'mrf-collapse_error', props.errored)),
|
|
632
|
-
onClick: toggle
|
|
633
|
-
}, !!collapsed && /*#__PURE__*/React__default["default"].createElement(reactFeather.Eye, {
|
|
634
|
-
size: 16
|
|
635
|
-
}), !collapsed && /*#__PURE__*/React__default["default"].createElement(reactFeather.EyeOff, {
|
|
636
|
-
size: 16
|
|
637
|
-
}))), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
638
|
-
className: classNames__default["default"]('mrf-ml_10', (_classNames4 = {}, _defineProperty$1(_classNames4, 'mrf-display__none', !!collapsed), _defineProperty$1(_classNames4, 'mrf-flex', !!props.inline), _defineProperty$1(_classNames4, 'mrf-collapse__inline', !!props.inline), _classNames4))
|
|
639
|
-
}, props.children), props.lineEnd && /*#__PURE__*/React__default["default"].createElement("hr", null));
|
|
224
|
+
const Collapse = (props) => {
|
|
225
|
+
const [collapsed, setCollapsed] = React.useState(props.initCollapsed || props.collapsed);
|
|
226
|
+
const toggle = (e) => {
|
|
227
|
+
if (e)
|
|
228
|
+
e.stopPropagation();
|
|
229
|
+
setCollapsed(!collapsed);
|
|
230
|
+
};
|
|
231
|
+
return (React__default["default"].createElement("div", null,
|
|
232
|
+
React__default["default"].createElement("hr", { className: classNames__default["default"]({ ['mrf-collapse_error']: props.errored }) }),
|
|
233
|
+
React__default["default"].createElement("div", { className: 'mrf-cursor_pointer mrf-flex mrf-jc_between', onClick: toggle },
|
|
234
|
+
React__default["default"].createElement("span", { className: classNames__default["default"]('mrf-collapse_label', { ['mrf-collapse_error']: props.errored }) }, props.label),
|
|
235
|
+
React__default["default"].createElement("button", { type: "button", className: classNames__default["default"]('mrf-btn', 'mrf-btn_sm', 'mrf-ml_5', { ['mrf-collapse_error']: props.errored }), onClick: toggle },
|
|
236
|
+
!!collapsed && React__default["default"].createElement(reactFeather.Eye, { size: 16 }),
|
|
237
|
+
!collapsed && React__default["default"].createElement(reactFeather.EyeOff, { size: 16 }))),
|
|
238
|
+
React__default["default"].createElement("div", { className: classNames__default["default"]('mrf-ml_10', {
|
|
239
|
+
['mrf-display__none']: !!collapsed,
|
|
240
|
+
['mrf-flex']: !!props.inline,
|
|
241
|
+
['mrf-collapse__inline']: !!props.inline,
|
|
242
|
+
}) }, props.children),
|
|
243
|
+
props.lineEnd && React__default["default"].createElement("hr", null)));
|
|
640
244
|
};
|
|
641
245
|
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
}
|
|
656
|
-
orElse: function orElse() {
|
|
657
|
-
return option(x);
|
|
658
|
-
},
|
|
659
|
-
getOrElse: function getOrElse() {
|
|
660
|
-
return x;
|
|
661
|
-
},
|
|
662
|
-
getOrNull: function getOrNull() {
|
|
663
|
-
return x;
|
|
664
|
-
},
|
|
665
|
-
isDefined: true,
|
|
666
|
-
exists: function exists(f) {
|
|
667
|
-
return option(f(x)).isDefined;
|
|
668
|
-
}
|
|
669
|
-
};
|
|
670
|
-
};
|
|
671
|
-
var None = {
|
|
672
|
-
map: function map() {
|
|
673
|
-
return None;
|
|
674
|
-
},
|
|
675
|
-
flatMap: function flatMap() {
|
|
676
|
-
return None;
|
|
677
|
-
},
|
|
678
|
-
fold: function fold(ifEmpty, _f) {
|
|
679
|
-
return ifEmpty();
|
|
680
|
-
},
|
|
681
|
-
orElse: function orElse(x) {
|
|
682
|
-
return option(x);
|
|
683
|
-
},
|
|
684
|
-
getOrElse: function getOrElse(ifEmpty) {
|
|
685
|
-
return ifEmpty;
|
|
686
|
-
},
|
|
687
|
-
getOrNull: function getOrNull() {
|
|
688
|
-
return undefined;
|
|
689
|
-
},
|
|
690
|
-
isDefined: false,
|
|
691
|
-
exists: function exists() {
|
|
692
|
-
return false;
|
|
693
|
-
}
|
|
246
|
+
function option(x) {
|
|
247
|
+
return (x === undefined || x === null ? None : Some(x));
|
|
248
|
+
}
|
|
249
|
+
const Some = (x) => {
|
|
250
|
+
return {
|
|
251
|
+
map: (f) => option(f(x)),
|
|
252
|
+
flatMap: (f) => option(f(x)).getOrElse(None),
|
|
253
|
+
fold: (_ifEmpty, f) => f(x),
|
|
254
|
+
orElse: () => option(x),
|
|
255
|
+
getOrElse: () => x,
|
|
256
|
+
getOrNull: () => x,
|
|
257
|
+
isDefined: () => true,
|
|
258
|
+
exists: (f) => option(f(x)).isDefined(),
|
|
259
|
+
};
|
|
694
260
|
};
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
261
|
+
const None = {
|
|
262
|
+
map: () => None,
|
|
263
|
+
flatMap: () => None,
|
|
264
|
+
fold: (ifEmpty) => ifEmpty(),
|
|
265
|
+
orElse: (x) => option(x),
|
|
266
|
+
getOrElse: (ifEmpty) => ifEmpty,
|
|
267
|
+
getOrNull: () => undefined,
|
|
268
|
+
isDefined: () => false,
|
|
269
|
+
exists: () => false,
|
|
698
270
|
};
|
|
699
|
-
var arrayFlatten = function arrayFlatten(array) {
|
|
700
|
-
if (array.some(Array.isArray)) {
|
|
701
|
-
return arrayFlatten(array.flat());
|
|
702
|
-
}
|
|
703
271
|
|
|
704
|
-
|
|
272
|
+
const isPromise = (value) => {
|
|
273
|
+
return Boolean(value && typeof value.then === 'function');
|
|
705
274
|
};
|
|
706
|
-
|
|
707
|
-
|
|
275
|
+
const arrayFlatten = (array) => {
|
|
276
|
+
if (array.some(Array.isArray)) {
|
|
277
|
+
return arrayFlatten(array.flat());
|
|
278
|
+
}
|
|
279
|
+
return array;
|
|
708
280
|
};
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
if (
|
|
714
|
-
|
|
715
|
-
isFirst.current = false;
|
|
716
|
-
return;
|
|
281
|
+
function isDefined(value) {
|
|
282
|
+
return value !== null && value !== undefined;
|
|
283
|
+
}
|
|
284
|
+
const cleanPromise = (obj) => {
|
|
285
|
+
if (!!obj && Array.isArray(obj)) {
|
|
286
|
+
return obj.map(cleanPromise);
|
|
717
287
|
}
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
288
|
+
else if (!!obj && typeof obj === 'object') {
|
|
289
|
+
return Object.fromEntries(Object.entries(obj).map(([k, v]) => {
|
|
290
|
+
if (isPromise(v)) {
|
|
291
|
+
return [k, `promise-${k}`];
|
|
292
|
+
}
|
|
293
|
+
else if (typeof v === "object") {
|
|
294
|
+
return [k, cleanPromise(v)];
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
return [k, v];
|
|
298
|
+
}
|
|
299
|
+
}));
|
|
725
300
|
}
|
|
726
|
-
|
|
301
|
+
return obj;
|
|
727
302
|
};
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
if (
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
}).getOrElse([]);
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
var maybeValue = option(possibleValues.find(function (v) {
|
|
749
|
-
return deepEqual__default["default"](v.value, value);
|
|
750
|
-
}));
|
|
751
|
-
return maybeValue.getOrElse({
|
|
752
|
-
label: maybeValue.map(function (v) {
|
|
753
|
-
return v.label;
|
|
754
|
-
}).getOrElse((value === null || value === void 0 ? void 0 : value.label) || (_typeof$1(value) === 'object' ? JSON.stringify(value) : value)),
|
|
755
|
-
value: maybeValue.map(function (v) {
|
|
756
|
-
return v.value;
|
|
757
|
-
}).getOrElse((value === null || value === void 0 ? void 0 : value.value) || value)
|
|
758
|
-
});
|
|
303
|
+
const cleanHash = (item) => hash__default["default"](cleanPromise(item));
|
|
304
|
+
const useHashEffect = (func, deps) => {
|
|
305
|
+
const isFirst = React.useRef(true);
|
|
306
|
+
const prevDeps = React.useRef(deps);
|
|
307
|
+
React.useEffect(() => {
|
|
308
|
+
if (isFirst.current) {
|
|
309
|
+
func();
|
|
310
|
+
isFirst.current = false;
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const depsHash = cleanHash(deps);
|
|
314
|
+
const prevDepsHash = cleanHash(prevDeps.current);
|
|
315
|
+
if (depsHash !== prevDepsHash) {
|
|
316
|
+
prevDeps.current = deps;
|
|
317
|
+
func();
|
|
318
|
+
}
|
|
319
|
+
}, deps); /* FIXME deps or [deps] ? */
|
|
759
320
|
};
|
|
760
321
|
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
if (props.optionsFrom) {
|
|
797
|
-
var cond = option(props.fetchCondition).map(function (cond) {
|
|
798
|
-
return cond();
|
|
799
|
-
}).getOrElse(true);
|
|
800
|
-
|
|
801
|
-
if (cond) {
|
|
802
|
-
setLoading(true);
|
|
803
|
-
var promise;
|
|
804
|
-
|
|
805
|
-
if (isPromise(props.optionsFrom)) {
|
|
806
|
-
promise = props.optionsFrom;
|
|
807
|
-
} else if (typeof props.optionsFrom === 'function') {
|
|
808
|
-
var result = props.optionsFrom({
|
|
809
|
-
rawValues: getValues(),
|
|
810
|
-
value: getValues(props.id)
|
|
811
|
-
});
|
|
812
|
-
promise = isPromise(result) ? result : props.httpClient(result, 'GET').then(function (r) {
|
|
813
|
-
return r.json();
|
|
814
|
-
});
|
|
815
|
-
} else {
|
|
816
|
-
promise = props.httpClient(props.optionsFrom, 'GET').then(function (r) {
|
|
817
|
-
return r.json();
|
|
818
|
-
});
|
|
322
|
+
const valueToSelectOption = (value, possibleValues = [], isMulti = false) => {
|
|
323
|
+
if (value === null || !value) {
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
if (isMulti) {
|
|
327
|
+
return option(value)
|
|
328
|
+
.map(v => {
|
|
329
|
+
return (() => {
|
|
330
|
+
if (Array.isArray(v))
|
|
331
|
+
return (v || []);
|
|
332
|
+
else if (typeof v === 'object')
|
|
333
|
+
return Object.values(v);
|
|
334
|
+
return v;
|
|
335
|
+
})().map((x) => valueToSelectOption(x, possibleValues, false));
|
|
336
|
+
})
|
|
337
|
+
.getOrElse([]);
|
|
338
|
+
}
|
|
339
|
+
const maybeValue = option(possibleValues.find(v => deepEqual__default["default"](v.value, value)));
|
|
340
|
+
return maybeValue
|
|
341
|
+
.getOrElse({
|
|
342
|
+
label: maybeValue.map(v => v.label).getOrElse((value === null || value === void 0 ? void 0 : value.label) || (typeof value === 'object' ? JSON.stringify(value) : value)),
|
|
343
|
+
value: maybeValue.map(v => v.value).getOrElse((value === null || value === void 0 ? void 0 : value.value) || value),
|
|
344
|
+
});
|
|
345
|
+
};
|
|
346
|
+
const SelectInput = (props) => {
|
|
347
|
+
const { getValues } = reactHookForm.useFormContext();
|
|
348
|
+
function transform(v) {
|
|
349
|
+
if (!props.transformer) {
|
|
350
|
+
return None;
|
|
351
|
+
}
|
|
352
|
+
if (typeof props.transformer === 'function') {
|
|
353
|
+
return option(props.transformer(v));
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
return Some({ label: v[props.transformer.label], value: v[props.transformer.value] });
|
|
819
357
|
}
|
|
820
|
-
|
|
821
|
-
promise.then(function (values) {
|
|
822
|
-
return values.map(function (x) {
|
|
823
|
-
return props.transformer ? props.transformer(x) : valueToSelectOption(x, values, props.isMulti, props.transformer);
|
|
824
|
-
});
|
|
825
|
-
}).then(function (values) {
|
|
826
|
-
setValues(values);
|
|
827
|
-
setValue(values.find(function (item) {
|
|
828
|
-
return item.value === (value ? value.value : value);
|
|
829
|
-
}) || null);
|
|
830
|
-
setLoading(false);
|
|
831
|
-
});
|
|
832
|
-
}
|
|
833
358
|
}
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
props.onChange(changes === null || changes === void 0 ? void 0 : changes.value);
|
|
359
|
+
function transformOption(v) {
|
|
360
|
+
const maybeSelectOption = props.transformer ?
|
|
361
|
+
(typeof props.transformer === 'function' ?
|
|
362
|
+
props.transformer(v) :
|
|
363
|
+
({ label: v[props.transformer.label], value: v[props.transformer.value] }))
|
|
364
|
+
: v;
|
|
365
|
+
return {
|
|
366
|
+
label: (maybeSelectOption === null || maybeSelectOption === void 0 ? void 0 : maybeSelectOption.label) || (typeof maybeSelectOption === 'object' ? JSON.stringify(maybeSelectOption) : maybeSelectOption),
|
|
367
|
+
value: (maybeSelectOption === null || maybeSelectOption === void 0 ? void 0 : maybeSelectOption.value) || v
|
|
368
|
+
};
|
|
845
369
|
}
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
370
|
+
const possibleValues = (props.possibleValues || [])
|
|
371
|
+
.map(v => transformOption(v));
|
|
372
|
+
const [loading, setLoading] = React.useState(false);
|
|
373
|
+
const [values, setValues] = React.useState(possibleValues);
|
|
374
|
+
const [value, setValue] = React.useState(valueToSelectOption(props.value || props.defaultValue, possibleValues, props.isMulti));
|
|
375
|
+
React.useEffect(() => {
|
|
376
|
+
setValue(valueToSelectOption(props.value, values, props.isMulti));
|
|
377
|
+
}, [props.value, values]);
|
|
378
|
+
React.useEffect(() => {
|
|
379
|
+
if (props.optionsFrom) {
|
|
380
|
+
const cond = option(props.fetchCondition)
|
|
381
|
+
.map(cond => cond())
|
|
382
|
+
.getOrElse(true);
|
|
383
|
+
if (cond) {
|
|
384
|
+
setLoading(true);
|
|
385
|
+
let promise;
|
|
386
|
+
if (isPromise(props.optionsFrom)) { /* FIXME undocumented behaviour ? */
|
|
387
|
+
promise = props.optionsFrom;
|
|
388
|
+
}
|
|
389
|
+
else if (typeof props.optionsFrom === 'function') { /* FIXME undocumented behaviour ? */
|
|
390
|
+
const result = props.optionsFrom({ rawValues: getValues(), value: getValues(props.id) });
|
|
391
|
+
promise = isPromise(result) ? result : props.httpClient(result, 'GET').then(r => r.json());
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
promise = props.httpClient(props.optionsFrom, 'GET').then(r => r.json());
|
|
395
|
+
}
|
|
396
|
+
promise
|
|
397
|
+
.then((values) => {
|
|
398
|
+
return values.map(x => transformOption(x));
|
|
399
|
+
})
|
|
400
|
+
.then((values) => {
|
|
401
|
+
setValues(values);
|
|
402
|
+
setValue(values.find((item) => {
|
|
403
|
+
if (Array.isArray(value)) {
|
|
404
|
+
return value.find(opt => opt.value === item.value);
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
return item.value === (value ? value.value : value);
|
|
408
|
+
}
|
|
409
|
+
}) || null);
|
|
410
|
+
setLoading(false);
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
setValues((props.possibleValues || [])
|
|
416
|
+
.map(v => transformOption(v)));
|
|
417
|
+
}
|
|
418
|
+
}, [props.optionsFrom, props.possibleValues]);
|
|
419
|
+
const onChange = (changes) => {
|
|
420
|
+
var _a, _b;
|
|
421
|
+
setValue(changes);
|
|
422
|
+
if (props.isMulti) {
|
|
423
|
+
(_a = props === null || props === void 0 ? void 0 : props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, changes.map(x => x.value));
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
(_b = props === null || props === void 0 ? void 0 : props.onChange) === null || _b === void 0 ? void 0 : _b.call(props, changes === null || changes === void 0 ? void 0 : changes.value);
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
const handleCreate = (label, fn) => {
|
|
430
|
+
const createdValue = option(fn)
|
|
431
|
+
.map(func => func(label))
|
|
432
|
+
.flatMap(createdOpt => transform(createdOpt))
|
|
433
|
+
.getOrElse(valueToSelectOption(label, values));
|
|
434
|
+
setValues([...values, createdValue]);
|
|
435
|
+
if (props.isMulti) {
|
|
436
|
+
onChange([...value, createdValue]);
|
|
437
|
+
}
|
|
438
|
+
else {
|
|
439
|
+
onChange(createdValue);
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
const handleSelectButtonClick = (v) => {
|
|
443
|
+
if (props.isMulti) {
|
|
444
|
+
const vs = value;
|
|
445
|
+
if (vs.includes(v)) { /* FIXME could be a different object ref but the same SelectOption, perhaps it would be better to compare label/values ? */
|
|
446
|
+
return onChange(vs.filter(val => val.value !== v.value));
|
|
447
|
+
}
|
|
448
|
+
else {
|
|
449
|
+
return onChange([...vs, v]);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
return onChange(v);
|
|
453
|
+
};
|
|
454
|
+
if (props.buttons) {
|
|
455
|
+
return (React__default["default"].createElement("div", { style: { display: 'flex' } }, values.map((v, idx) => {
|
|
456
|
+
const active = !!value && (props.isMulti ? value.includes(v) : v.value === value.value);
|
|
457
|
+
return (React__default["default"].createElement("button", { key: idx, type: "button", disabled: props.disabled, className: classNames__default["default"](props.className, 'mrf-btn mrf-btn_grey mrf-ml_5', { active }), onClick: () => handleSelectButtonClick(v) }, v.label));
|
|
458
|
+
})));
|
|
862
459
|
}
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
var handleSelectButtonClick = function handleSelectButtonClick(v) {
|
|
866
|
-
if (props.isMulti) {
|
|
867
|
-
if (value.includes(v)) {
|
|
868
|
-
return onChange(value.filter(function (val) {
|
|
869
|
-
return val.value !== v.value;
|
|
870
|
-
}));
|
|
871
|
-
} else {
|
|
872
|
-
return onChange([].concat(_toConsumableArray$1(value), [v]));
|
|
873
|
-
}
|
|
460
|
+
if (props.createOption) {
|
|
461
|
+
return (React__default["default"].createElement(CreatableSelect__default["default"], Object.assign({}, props, { name: `${props.label}-search`, isLoading: loading, value: value, isDisabled: props.disabled, placeholder: props.placeholder, onChange: onChange, options: values, onCreateOption: option => handleCreate(option, props.onCreateOption), classNamePrefix: "react-form-select", className: props.className })));
|
|
874
462
|
}
|
|
463
|
+
else {
|
|
464
|
+
return (React__default["default"].createElement(Select__default["default"], Object.assign({}, props, { name: `${props.label}-search`, isLoading: loading, value: value, defaultValue: value, isDisabled: props.disabled, placeholder: props.placeholder, options: values, onChange: onChange, classNamePrefix: "react-form-select", className: props.className })));
|
|
465
|
+
}
|
|
466
|
+
};
|
|
875
467
|
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
return handleSelectButtonClick(v);
|
|
468
|
+
const ObjectInput = (props) => {
|
|
469
|
+
const [internalState, setInternalState] = React.useState({});
|
|
470
|
+
React.useEffect(() => {
|
|
471
|
+
setInternalState(Object.fromEntries(Object.entries(props.value || {})
|
|
472
|
+
.map(([key, value], idx) => [Date.now() + idx, { key, value }])));
|
|
473
|
+
}, []);
|
|
474
|
+
React.useEffect(() => {
|
|
475
|
+
if (props.value) {
|
|
476
|
+
const newState = props.value || {};
|
|
477
|
+
const previousState = Object.entries(internalState || {})
|
|
478
|
+
.reduce((acc, [_, item]) => {
|
|
479
|
+
if (item.key)
|
|
480
|
+
return (Object.assign(Object.assign({}, acc), { [item.key]: item.value }));
|
|
481
|
+
return acc;
|
|
482
|
+
}, {});
|
|
483
|
+
if (!deepEqual__default["default"](newState, previousState))
|
|
484
|
+
setInternalState(Object.fromEntries(Object.entries(props.value || {})
|
|
485
|
+
.map(([key, value], idx) => [Date.now() + idx, { key, value }])));
|
|
895
486
|
}
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
if (props.createOption) {
|
|
901
|
-
return /*#__PURE__*/React__default["default"].createElement(CreatableSelect__default["default"], _extends({}, props, {
|
|
902
|
-
name: "".concat(props.label, "-search"),
|
|
903
|
-
isLoading: loading,
|
|
904
|
-
value: value,
|
|
905
|
-
isDisabled: props.disabled,
|
|
906
|
-
placeholder: props.placeholder,
|
|
907
|
-
onChange: onChange,
|
|
908
|
-
options: values,
|
|
909
|
-
onCreateOption: function onCreateOption(option) {
|
|
910
|
-
return handleCreate(option, props.onCreateOption);
|
|
911
|
-
},
|
|
912
|
-
classNamePrefix: "react-form-select",
|
|
913
|
-
className: props.className,
|
|
914
|
-
readOnly: props.disabled ? 'readOnly' : null
|
|
915
|
-
}));
|
|
916
|
-
} else {
|
|
917
|
-
return /*#__PURE__*/React__default["default"].createElement(Select__default["default"], _extends({}, props, {
|
|
918
|
-
name: "".concat(props.label, "-search"),
|
|
919
|
-
isLoading: loading,
|
|
920
|
-
value: value,
|
|
921
|
-
defaultValue: value,
|
|
922
|
-
isDisabled: props.disabled,
|
|
923
|
-
placeholder: props.placeholder,
|
|
924
|
-
options: values,
|
|
925
|
-
onChange: onChange,
|
|
926
|
-
classNamePrefix: "react-form-select",
|
|
927
|
-
className: props.className,
|
|
928
|
-
readOnly: props.disabled ? 'readOnly' : null
|
|
929
|
-
}));
|
|
930
|
-
}
|
|
931
|
-
});
|
|
932
|
-
|
|
933
|
-
var ObjectInput = function ObjectInput(props) {
|
|
934
|
-
var _useState = React.useState(),
|
|
935
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
936
|
-
internalState = _useState2[0],
|
|
937
|
-
setInternalState = _useState2[1];
|
|
938
|
-
|
|
939
|
-
React.useEffect(function () {
|
|
940
|
-
setInternalState(Object.fromEntries(Object.entries(props.value || {}).map(function (_ref, idx) {
|
|
941
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
942
|
-
key = _ref2[0],
|
|
943
|
-
value = _ref2[1];
|
|
944
|
-
|
|
945
|
-
return [Date.now() + idx, {
|
|
946
|
-
key: key,
|
|
947
|
-
value: value
|
|
948
|
-
}];
|
|
949
|
-
})));
|
|
950
|
-
}, []);
|
|
951
|
-
React.useEffect(function () {
|
|
952
|
-
if (props.value) {
|
|
953
|
-
var newState = props.value || {};
|
|
954
|
-
var previousState = Object.entries(internalState || {}).reduce(function (acc, _ref3) {
|
|
955
|
-
var _ref4 = _slicedToArray(_ref3, 2);
|
|
956
|
-
_ref4[0];
|
|
957
|
-
var item = _ref4[1];
|
|
958
|
-
|
|
959
|
-
if (item.key) return _objectSpread2$1(_objectSpread2$1({}, acc), {}, _defineProperty$1({}, item.key, item.value));
|
|
960
|
-
return acc;
|
|
961
|
-
}, {});
|
|
962
|
-
if (!deepEqual__default["default"](newState, previousState)) setInternalState(Object.fromEntries(Object.entries(props.value || {}).map(function (_ref5, idx) {
|
|
963
|
-
var _ref6 = _slicedToArray(_ref5, 2),
|
|
964
|
-
key = _ref6[0],
|
|
965
|
-
value = _ref6[1];
|
|
966
|
-
|
|
967
|
-
return [Date.now() + idx, {
|
|
968
|
-
key: key,
|
|
969
|
-
value: value
|
|
970
|
-
}];
|
|
971
|
-
})));
|
|
972
|
-
}
|
|
973
|
-
}, [props.value]);
|
|
974
|
-
|
|
975
|
-
var onChange = function onChange(state) {
|
|
976
|
-
props.onChange(Object.values(state).reduce(function (acc, c) {
|
|
977
|
-
return _objectSpread2$1(_objectSpread2$1({}, acc), {}, _defineProperty$1({}, c.key, c.value));
|
|
978
|
-
}, {}));
|
|
979
|
-
};
|
|
980
|
-
|
|
981
|
-
var changeValue = function changeValue(id, newValue) {
|
|
982
|
-
var newState = _objectSpread2$1(_objectSpread2$1({}, internalState), {}, _defineProperty$1({}, id, {
|
|
983
|
-
key: internalState[id].key,
|
|
984
|
-
value: newValue
|
|
985
|
-
}));
|
|
986
|
-
|
|
987
|
-
setInternalState(newState);
|
|
988
|
-
onChange(newState);
|
|
989
|
-
};
|
|
990
|
-
|
|
991
|
-
var changeKey = function changeKey(id, newValue) {
|
|
992
|
-
var newState = _objectSpread2$1(_objectSpread2$1({}, internalState), {}, _defineProperty$1({}, id, {
|
|
993
|
-
key: newValue,
|
|
994
|
-
value: internalState[id].value
|
|
995
|
-
}));
|
|
996
|
-
|
|
997
|
-
setInternalState(newState);
|
|
998
|
-
onChange(newState);
|
|
999
|
-
};
|
|
1000
|
-
|
|
1001
|
-
var addFirst = function addFirst() {
|
|
1002
|
-
if (!internalState || Object.keys(internalState).length === 0) {
|
|
1003
|
-
var newState = _objectSpread2$1(_objectSpread2$1({}, internalState), {}, _defineProperty$1({}, Date.now(), props.defaultKeyValue || {
|
|
1004
|
-
key: '',
|
|
1005
|
-
value: ''
|
|
1006
|
-
}));
|
|
1007
|
-
|
|
1008
|
-
setInternalState(newState);
|
|
1009
|
-
onChange(newState);
|
|
1010
|
-
}
|
|
1011
|
-
};
|
|
1012
|
-
|
|
1013
|
-
var addNext = function addNext() {
|
|
1014
|
-
var newItem = props.defaultKeyValue || {
|
|
1015
|
-
key: '',
|
|
1016
|
-
value: ''
|
|
487
|
+
}, [props.value]);
|
|
488
|
+
const onChange = (state) => {
|
|
489
|
+
var _a;
|
|
490
|
+
(_a = props === null || props === void 0 ? void 0 : props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, Object.values(state).reduce((acc, c) => (Object.assign(Object.assign({}, acc), { [c.key]: c.value })), {}));
|
|
1017
491
|
};
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
value
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
type: "text",
|
|
1057
|
-
className: "mrf-w_50 mrf-input",
|
|
1058
|
-
placeholder: props.placeholderKey,
|
|
1059
|
-
value: key,
|
|
1060
|
-
onChange: function onChange(e) {
|
|
1061
|
-
return changeKey(id, e.target.value);
|
|
1062
|
-
}
|
|
1063
|
-
}), /*#__PURE__*/React__default["default"].createElement("input", {
|
|
1064
|
-
disabled: props.disabled,
|
|
1065
|
-
type: "text",
|
|
1066
|
-
className: "mrf-w_50 mrf-input",
|
|
1067
|
-
placeholder: props.placeholderValue,
|
|
1068
|
-
value: value,
|
|
1069
|
-
onChange: function onChange(e) {
|
|
1070
|
-
return changeValue(id, e.target.value);
|
|
1071
|
-
}
|
|
1072
|
-
}), /*#__PURE__*/React__default["default"].createElement("button", {
|
|
1073
|
-
disabled: props.disabled,
|
|
1074
|
-
type: "button",
|
|
1075
|
-
className: "mrf-flex mrf-btn mrf-btn_red mrf-btn_sm mrf-ml_10",
|
|
1076
|
-
onClick: function onClick() {
|
|
1077
|
-
return remove(id);
|
|
1078
|
-
}
|
|
1079
|
-
}, /*#__PURE__*/React__default["default"].createElement(reactFeather.MinusCircle, null)), idx === Object.keys(internalState).length - 1 && /*#__PURE__*/React__default["default"].createElement("button", {
|
|
1080
|
-
disabled: props.disabled,
|
|
1081
|
-
type: "button",
|
|
1082
|
-
className: "mrf-flex mrf-btn mrf-btn_blue mrf-btn_sm mrf-ml_5",
|
|
1083
|
-
onClick: addNext
|
|
1084
|
-
}, /*#__PURE__*/React__default["default"].createElement(reactFeather.PlusCircle, null)));
|
|
1085
|
-
}));
|
|
492
|
+
const changeValue = (id, newValue) => {
|
|
493
|
+
const newState = Object.assign(Object.assign({}, internalState), { [id]: { key: internalState[id].key, value: newValue } });
|
|
494
|
+
setInternalState(newState);
|
|
495
|
+
onChange(newState);
|
|
496
|
+
};
|
|
497
|
+
const changeKey = (id, newValue) => {
|
|
498
|
+
const newState = Object.assign(Object.assign({}, internalState), { [id]: { key: newValue, value: internalState[id].value } });
|
|
499
|
+
setInternalState(newState);
|
|
500
|
+
onChange(newState);
|
|
501
|
+
};
|
|
502
|
+
const addFirst = () => {
|
|
503
|
+
if (!internalState || Object.keys(internalState).length === 0) {
|
|
504
|
+
const newState = Object.assign(Object.assign({}, internalState), { [Date.now()]: props.defaultKeyValue || { key: '', value: '' } });
|
|
505
|
+
setInternalState(newState);
|
|
506
|
+
onChange(newState);
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
const addNext = () => {
|
|
510
|
+
const newItem = props.defaultKeyValue || { key: '', value: '' };
|
|
511
|
+
const newState = Object.assign(Object.assign({}, internalState), { [Date.now()]: newItem });
|
|
512
|
+
setInternalState(newState);
|
|
513
|
+
onChange(newState);
|
|
514
|
+
};
|
|
515
|
+
const remove = (removedId) => {
|
|
516
|
+
const newState = Object.fromEntries(Object.entries(internalState).filter(([id, _]) => id !== removedId));
|
|
517
|
+
setInternalState(newState);
|
|
518
|
+
onChange(newState);
|
|
519
|
+
};
|
|
520
|
+
return (React__namespace.createElement("div", { className: props.className },
|
|
521
|
+
Object.keys(internalState || {}).length === 0 && (React__namespace.createElement("button", { disabled: props.disabled, type: "button", className: 'mrf-flex mrf-btn mrf-btn_blue mrf-btn_sm', onClick: addFirst },
|
|
522
|
+
React__namespace.createElement(reactFeather.PlusCircle, null))),
|
|
523
|
+
Object.entries(internalState || {}).map(([id, { key, value }], idx) => (React__namespace.createElement("div", { className: 'mrf-flex mrf-mt_5', key: idx },
|
|
524
|
+
React__namespace.createElement("input", { disabled: props.disabled, type: "text", className: 'mrf-w_50 mrf-input', placeholder: props.placeholderKey, value: key, onChange: e => changeKey(id, e.target.value) }),
|
|
525
|
+
React__namespace.createElement("input", { disabled: props.disabled, type: "text", className: 'mrf-w_50 mrf-input', placeholder: props.placeholderValue, value: value, onChange: e => changeValue(id, e.target.value) }),
|
|
526
|
+
React__namespace.createElement("button", { disabled: props.disabled, type: "button", className: 'mrf-flex mrf-btn mrf-btn_red mrf-btn_sm mrf-ml_10', onClick: () => remove(id) },
|
|
527
|
+
React__namespace.createElement(reactFeather.MinusCircle, null)),
|
|
528
|
+
idx === Object.keys(internalState).length - 1 && (React__namespace.createElement("button", { disabled: props.disabled, type: "button", className: 'mrf-flex mrf-btn mrf-btn_blue mrf-btn_sm mrf-ml_5', onClick: addNext },
|
|
529
|
+
React__namespace.createElement(reactFeather.PlusCircle, null))))))));
|
|
1086
530
|
};
|
|
1087
531
|
|
|
1088
|
-
function ownKeys(object, enumerableOnly) {
|
|
1089
|
-
var keys = Object.keys(object);
|
|
1090
|
-
|
|
1091
|
-
if (Object.getOwnPropertySymbols) {
|
|
1092
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
1093
|
-
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
1094
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
1095
|
-
})), keys.push.apply(keys, symbols);
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
return keys;
|
|
1099
|
-
}
|
|
1100
|
-
|
|
1101
|
-
function _objectSpread2(target) {
|
|
1102
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
1103
|
-
var source = null != arguments[i] ? arguments[i] : {};
|
|
1104
|
-
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
1105
|
-
_defineProperty(target, key, source[key]);
|
|
1106
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
1107
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
1108
|
-
});
|
|
1109
|
-
}
|
|
1110
|
-
|
|
1111
|
-
return target;
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
function _typeof(obj) {
|
|
1115
|
-
"@babel/helpers - typeof";
|
|
1116
|
-
|
|
1117
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
1118
|
-
return typeof obj;
|
|
1119
|
-
} : function (obj) {
|
|
1120
|
-
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
1121
|
-
}, _typeof(obj);
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
|
-
function _defineProperty(obj, key, value) {
|
|
1125
|
-
if (key in obj) {
|
|
1126
|
-
Object.defineProperty(obj, key, {
|
|
1127
|
-
value: value,
|
|
1128
|
-
enumerable: true,
|
|
1129
|
-
configurable: true,
|
|
1130
|
-
writable: true
|
|
1131
|
-
});
|
|
1132
|
-
} else {
|
|
1133
|
-
obj[key] = value;
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
return obj;
|
|
1137
|
-
}
|
|
1138
|
-
|
|
1139
|
-
function _toConsumableArray(arr) {
|
|
1140
|
-
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
function _arrayWithoutHoles(arr) {
|
|
1144
|
-
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
|
-
function _iterableToArray(iter) {
|
|
1148
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
1149
|
-
}
|
|
1150
|
-
|
|
1151
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
1152
|
-
if (!o) return;
|
|
1153
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
1154
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
1155
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
1156
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
1157
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
function _arrayLikeToArray(arr, len) {
|
|
1161
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
1162
|
-
|
|
1163
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
1164
|
-
|
|
1165
|
-
return arr2;
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
function _nonIterableSpread() {
|
|
1169
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
532
|
// Compressed representation of the Grapheme_Cluster_Break=Extend
|
|
1173
533
|
// information from
|
|
1174
534
|
// http://www.unicode.org/Public/13.0.0/ucd/auxiliary/GraphemeBreakProperty.txt.
|
|
@@ -28226,1765 +27586,923 @@ the highlight style).
|
|
|
28226
27586
|
*/
|
|
28227
27587
|
const oneDark = [oneDarkTheme, oneDarkHighlightStyle];
|
|
28228
27588
|
|
|
28229
|
-
|
|
28230
|
-
|
|
28231
|
-
|
|
28232
|
-
|
|
28233
|
-
|
|
28234
|
-
|
|
27589
|
+
/*global event*/
|
|
27590
|
+
const languages = {
|
|
27591
|
+
javascript,
|
|
27592
|
+
css,
|
|
27593
|
+
json,
|
|
27594
|
+
html,
|
|
27595
|
+
markdown
|
|
28235
27596
|
};
|
|
28236
|
-
function Editor(parent, mode, onChange, value
|
|
28237
|
-
var tabSize = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
|
|
28238
|
-
var readOnly = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
28239
|
-
var showLinesNumber = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : true;
|
|
28240
|
-
var highlightLine = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : false;
|
|
28241
|
-
var themeStyle = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : {
|
|
27597
|
+
function Editor(parent, mode, onChange, value, tabSize = 1, readOnly = false, showLinesNumber = true, highlightLine = false, themeStyle = {
|
|
28242
27598
|
height: '-1',
|
|
28243
27599
|
minHeight: '300px',
|
|
28244
27600
|
maxHeight: '-1',
|
|
28245
27601
|
width: '-1',
|
|
28246
27602
|
minWidth: '-1',
|
|
28247
|
-
maxWidth: '-1'
|
|
28248
|
-
|
|
28249
|
-
|
|
28250
|
-
|
|
28251
|
-
|
|
28252
|
-
|
|
28253
|
-
|
|
28254
|
-
|
|
28255
|
-
|
|
28256
|
-
|
|
28257
|
-
|
|
28258
|
-
|
|
28259
|
-
|
|
28260
|
-
|
|
28261
|
-
|
|
28262
|
-
|
|
28263
|
-
|
|
28264
|
-
|
|
28265
|
-
|
|
28266
|
-
|
|
28267
|
-
|
|
28268
|
-
|
|
28269
|
-
|
|
28270
|
-
|
|
28271
|
-
|
|
27603
|
+
maxWidth: '-1',
|
|
27604
|
+
}) {
|
|
27605
|
+
const theme = EditorView.theme({
|
|
27606
|
+
'&': Object.assign({}, themeStyle),
|
|
27607
|
+
});
|
|
27608
|
+
const setup = [
|
|
27609
|
+
showLinesNumber ? lineNumbers() : lineNumbers({ formatNumber: () => "" }),
|
|
27610
|
+
highlightActiveLineGutter(),
|
|
27611
|
+
highlightSpecialChars(),
|
|
27612
|
+
history(),
|
|
27613
|
+
languages[mode](),
|
|
27614
|
+
foldGutter(),
|
|
27615
|
+
drawSelection(),
|
|
27616
|
+
dropCursor(),
|
|
27617
|
+
EditorState.allowMultipleSelections.of(true),
|
|
27618
|
+
defaultHighlightStyle.fallback,
|
|
27619
|
+
bracketMatching(),
|
|
27620
|
+
closeBrackets(),
|
|
27621
|
+
autocompletion(),
|
|
27622
|
+
rectangularSelection(),
|
|
27623
|
+
highlightLine ? highlightActiveLine() : undefined,
|
|
27624
|
+
highlightSelectionMatches(),
|
|
27625
|
+
keymap.of([
|
|
27626
|
+
...closeBracketsKeymap,
|
|
27627
|
+
...defaultKeymap,
|
|
27628
|
+
...searchKeymap,
|
|
27629
|
+
...historyKeymap,
|
|
27630
|
+
...foldKeymap,
|
|
27631
|
+
...commentKeymap,
|
|
27632
|
+
...completionKeymap,
|
|
27633
|
+
...lintKeymap,
|
|
27634
|
+
indentWithTab
|
|
27635
|
+
]),
|
|
27636
|
+
oneDark,
|
|
27637
|
+
theme,
|
|
27638
|
+
EditorState.tabSize.of(tabSize), indentUnit.of(" ".repeat(tabSize))
|
|
27639
|
+
].filter((f) => !!f);
|
|
27640
|
+
const state = EditorState.create({
|
|
27641
|
+
extensions: [
|
|
27642
|
+
...setup,
|
|
27643
|
+
EditorView.updateListener.of(vu => {
|
|
27644
|
+
try {
|
|
27645
|
+
if (vu.docChanged) {
|
|
27646
|
+
const doc = vu.state.doc.toString();
|
|
27647
|
+
onChange(doc);
|
|
27648
|
+
}
|
|
27649
|
+
}
|
|
27650
|
+
catch (_) {
|
|
27651
|
+
}
|
|
27652
|
+
}),
|
|
27653
|
+
EditorView.editable.of(!readOnly)
|
|
27654
|
+
],
|
|
27655
|
+
doc: (value === null || value === undefined) ? '' : (typeof value === 'object' ? value.value : value),
|
|
27656
|
+
});
|
|
27657
|
+
return new EditorView({
|
|
27658
|
+
state,
|
|
27659
|
+
parent
|
|
27660
|
+
});
|
|
28272
27661
|
}
|
|
28273
27662
|
|
|
28274
|
-
function CodeInput(
|
|
28275
|
-
var onChange = _ref.onChange,
|
|
28276
|
-
value = _ref.value,
|
|
28277
|
-
_ref$mode = _ref.mode,
|
|
28278
|
-
mode = _ref$mode === void 0 ? 'javascript' : _ref$mode,
|
|
28279
|
-
_ref$tabSize = _ref.tabSize,
|
|
28280
|
-
tabSize = _ref$tabSize === void 0 ? 2 : _ref$tabSize,
|
|
28281
|
-
_ref$readOnly = _ref.readOnly,
|
|
28282
|
-
readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
|
|
28283
|
-
_ref$showLinesNumber = _ref.showLinesNumber,
|
|
28284
|
-
showLinesNumber = _ref$showLinesNumber === void 0 ? true : _ref$showLinesNumber,
|
|
28285
|
-
_ref$highlightLine = _ref.highlightLine,
|
|
28286
|
-
highlightLine = _ref$highlightLine === void 0 ? false : _ref$highlightLine,
|
|
28287
|
-
_ref$themeStyle = _ref.themeStyle,
|
|
28288
|
-
themeStyle = _ref$themeStyle === void 0 ? {
|
|
27663
|
+
function CodeInput({ onChange, value, mode = 'javascript', tabSize = 2, readOnly = false, showLinesNumber = true, highlightLine = false, themeStyle = {
|
|
28289
27664
|
height: '-1',
|
|
28290
27665
|
minHeight: '300px',
|
|
28291
27666
|
maxHeight: '-1',
|
|
28292
27667
|
width: '-1',
|
|
28293
27668
|
minWidth: '-1',
|
|
28294
|
-
maxWidth: '-1'
|
|
28295
|
-
|
|
28296
|
-
|
|
28297
|
-
|
|
28298
|
-
|
|
28299
|
-
|
|
28300
|
-
|
|
28301
|
-
|
|
28302
|
-
|
|
28303
|
-
|
|
28304
|
-
|
|
28305
|
-
|
|
28306
|
-
ref.current.addEventListener("keydown", function (e) {
|
|
28307
|
-
e.stopImmediatePropagation();
|
|
28308
|
-
});
|
|
28309
|
-
if (setRef) setRef(e);
|
|
28310
|
-
e.dispatch({
|
|
28311
|
-
changes: {
|
|
28312
|
-
from: 0,
|
|
28313
|
-
to: e.state.doc.length,
|
|
28314
|
-
insert: value === null || value === undefined ? '' : _typeof$1(value) === 'object' ? JSON.stringify(value, null, 2) : value
|
|
28315
|
-
}
|
|
28316
|
-
});
|
|
28317
|
-
setEditor(e);
|
|
28318
|
-
}, []);
|
|
28319
|
-
React.useEffect(function () {
|
|
28320
|
-
if (editor && (_typeof$1(value) === 'object' ? JSON.stringify(value, null, 2) : value) !== editor.state.doc.toString()) {
|
|
28321
|
-
editor.dispatch({
|
|
28322
|
-
changes: {
|
|
28323
|
-
from: 0,
|
|
28324
|
-
to: editor.state.doc.length,
|
|
28325
|
-
insert: value === null || value === undefined ? '' : _typeof$1(value) === 'object' ? JSON.stringify(value, null, 2) : value
|
|
28326
|
-
}
|
|
28327
|
-
});
|
|
28328
|
-
}
|
|
28329
|
-
}, [value]);
|
|
28330
|
-
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
28331
|
-
ref: ref
|
|
28332
|
-
});
|
|
28333
|
-
}
|
|
28334
|
-
|
|
28335
|
-
var converter = new showdown__default["default"].Converter({
|
|
28336
|
-
omitExtraWLInCodeBlocks: true,
|
|
28337
|
-
ghCompatibleHeaderId: true,
|
|
28338
|
-
parseImgDimensions: true,
|
|
28339
|
-
simplifiedAutoLink: true,
|
|
28340
|
-
tables: true,
|
|
28341
|
-
tasklists: true,
|
|
28342
|
-
requireSpaceBeforeHeadingText: true,
|
|
28343
|
-
ghMentions: true,
|
|
28344
|
-
emoji: true,
|
|
28345
|
-
ghMentionsLink: '/{u}'
|
|
28346
|
-
});
|
|
28347
|
-
var MarkdownInput = function MarkdownInput(props) {
|
|
28348
|
-
var _useState = React.useState(props.preview),
|
|
28349
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
28350
|
-
preview = _useState2[0],
|
|
28351
|
-
setPreview = _useState2[1];
|
|
28352
|
-
|
|
28353
|
-
var ref = React.useRef();
|
|
28354
|
-
React.useEffect(function () {
|
|
28355
|
-
if (preview) {
|
|
28356
|
-
showPreview();
|
|
28357
|
-
}
|
|
28358
|
-
}, [preview, props.value]);
|
|
28359
|
-
var commands = [{
|
|
28360
|
-
name: 'Add header',
|
|
28361
|
-
icon: 'heading',
|
|
28362
|
-
inject: function inject(range) {
|
|
28363
|
-
return !range ? '#' : [{
|
|
28364
|
-
from: range.from,
|
|
28365
|
-
insert: "# "
|
|
28366
|
-
}];
|
|
28367
|
-
}
|
|
28368
|
-
}, {
|
|
28369
|
-
name: 'Add bold text',
|
|
28370
|
-
icon: 'bold',
|
|
28371
|
-
inject: function inject(range) {
|
|
28372
|
-
return !range ? '** **' : [{
|
|
28373
|
-
from: range.from,
|
|
28374
|
-
insert: "**"
|
|
28375
|
-
}, {
|
|
28376
|
-
from: range.to,
|
|
28377
|
-
insert: '**'
|
|
28378
|
-
}];
|
|
28379
|
-
}
|
|
28380
|
-
}, {
|
|
28381
|
-
name: 'Add italic text',
|
|
28382
|
-
icon: 'italic',
|
|
28383
|
-
inject: function inject(range) {
|
|
28384
|
-
return !range ? '* *' : [{
|
|
28385
|
-
from: range.from,
|
|
28386
|
-
insert: '*'
|
|
28387
|
-
}, {
|
|
28388
|
-
from: range.to,
|
|
28389
|
-
insert: '*'
|
|
28390
|
-
}];
|
|
28391
|
-
}
|
|
28392
|
-
}, {
|
|
28393
|
-
name: 'Add strikethrough text',
|
|
28394
|
-
icon: 'strikethrough',
|
|
28395
|
-
inject: function inject(range) {
|
|
28396
|
-
return !range ? '~~ ~~' : [{
|
|
28397
|
-
from: range.from,
|
|
28398
|
-
insert: '~~'
|
|
28399
|
-
}, {
|
|
28400
|
-
from: range.to,
|
|
28401
|
-
insert: '~~'
|
|
28402
|
-
}];
|
|
28403
|
-
}
|
|
28404
|
-
}, {
|
|
28405
|
-
name: 'Add link',
|
|
28406
|
-
icon: 'link',
|
|
28407
|
-
inject: function inject(range) {
|
|
28408
|
-
return !range ? '[ ](url)' : [{
|
|
28409
|
-
from: range.from,
|
|
28410
|
-
insert: '['
|
|
28411
|
-
}, {
|
|
28412
|
-
from: range.to,
|
|
28413
|
-
insert: '](url)'
|
|
28414
|
-
}];
|
|
28415
|
-
}
|
|
28416
|
-
}, {
|
|
28417
|
-
name: 'Add code',
|
|
28418
|
-
icon: 'code',
|
|
28419
|
-
inject: function inject(range) {
|
|
28420
|
-
return !range ? '```\n\n```\n' : [{
|
|
28421
|
-
from: range.from,
|
|
28422
|
-
insert: '```\n'
|
|
28423
|
-
}, {
|
|
28424
|
-
from: range.to,
|
|
28425
|
-
insert: '\n```\n'
|
|
28426
|
-
}];
|
|
28427
|
-
}
|
|
28428
|
-
}, {
|
|
28429
|
-
name: 'Add quotes',
|
|
28430
|
-
icon: 'quote-right',
|
|
28431
|
-
inject: function inject(range) {
|
|
28432
|
-
return !range ? '> ' : [{
|
|
28433
|
-
from: range.from,
|
|
28434
|
-
insert: '> '
|
|
28435
|
-
}];
|
|
28436
|
-
}
|
|
28437
|
-
}, {
|
|
28438
|
-
name: 'Add image',
|
|
28439
|
-
icon: 'image',
|
|
28440
|
-
inject: function inject(range) {
|
|
28441
|
-
return !range ? '' : [{
|
|
28442
|
-
from: range.from,
|
|
28443
|
-
insert: ''
|
|
28447
|
-
}];
|
|
28448
|
-
}
|
|
28449
|
-
}, {
|
|
28450
|
-
name: 'Add unordered list',
|
|
28451
|
-
icon: 'list-ul',
|
|
28452
|
-
inject: function inject(range) {
|
|
28453
|
-
return !range ? '* ' : [{
|
|
28454
|
-
from: range.from,
|
|
28455
|
-
insert: '* '
|
|
28456
|
-
}];
|
|
28457
|
-
}
|
|
28458
|
-
}, {
|
|
28459
|
-
name: 'Add ordered list',
|
|
28460
|
-
icon: 'list-ol',
|
|
28461
|
-
inject: function inject(range) {
|
|
28462
|
-
return !range ? '1. ' : [{
|
|
28463
|
-
from: range.from,
|
|
28464
|
-
insert: '1. '
|
|
28465
|
-
}];
|
|
28466
|
-
}
|
|
28467
|
-
}, {
|
|
28468
|
-
name: 'Add check list',
|
|
28469
|
-
icon: 'tasks',
|
|
28470
|
-
inject: function inject(range) {
|
|
28471
|
-
return !range ? '* [ ] ' : [{
|
|
28472
|
-
from: range.from,
|
|
28473
|
-
insert: '* [ ] '
|
|
28474
|
-
}];
|
|
28475
|
-
}
|
|
28476
|
-
}];
|
|
28477
|
-
|
|
28478
|
-
var showPreview = function showPreview() {
|
|
28479
|
-
var parent = _toConsumableArray$1(document.getElementsByClassName('mrf-preview'));
|
|
28480
|
-
|
|
28481
|
-
if (parent.length > 0) _toConsumableArray$1(parent[0].querySelectorAll('pre code')).forEach(function (block) {
|
|
28482
|
-
return hljs__default["default"].highlightElement(block);
|
|
28483
|
-
});
|
|
28484
|
-
};
|
|
28485
|
-
|
|
28486
|
-
var injectButtons = function injectButtons() {
|
|
28487
|
-
return commands.map(function (command, idx) {
|
|
28488
|
-
if (command.component) {
|
|
28489
|
-
return command.component(idx);
|
|
28490
|
-
}
|
|
28491
|
-
|
|
28492
|
-
return /*#__PURE__*/React__default["default"].createElement("button", {
|
|
28493
|
-
type: "button",
|
|
28494
|
-
className: classNames__default["default"]('mrf-btn_for_descriptionToolbar'),
|
|
28495
|
-
"aria-label": command.name,
|
|
28496
|
-
title: command.name,
|
|
28497
|
-
key: "toolbar-btn-".concat(idx),
|
|
28498
|
-
onClick: function onClick() {
|
|
28499
|
-
var editor = ref.current;
|
|
28500
|
-
var selections = editor.state.selection.ranges;
|
|
28501
|
-
if (selections.length === 1 && selections[0].from === selections[0].to) editor.dispatch({
|
|
27669
|
+
maxWidth: '-1',
|
|
27670
|
+
}, setRef }) {
|
|
27671
|
+
const ref = React.useRef();
|
|
27672
|
+
const [editor, setEditor] = React.useState();
|
|
27673
|
+
React.useEffect(() => {
|
|
27674
|
+
const e = Editor(ref.current, mode, onChange, value, tabSize, readOnly, showLinesNumber, highlightLine, themeStyle);
|
|
27675
|
+
ref.current.addEventListener("keydown", (e) => {
|
|
27676
|
+
e.stopImmediatePropagation();
|
|
27677
|
+
});
|
|
27678
|
+
if (setRef)
|
|
27679
|
+
setRef(e);
|
|
27680
|
+
e.dispatch({
|
|
28502
27681
|
changes: {
|
|
28503
|
-
|
|
28504
|
-
|
|
28505
|
-
|
|
28506
|
-
}
|
|
28507
|
-
|
|
28508
|
-
|
|
28509
|
-
|
|
28510
|
-
|
|
28511
|
-
|
|
28512
|
-
|
|
28513
|
-
|
|
28514
|
-
|
|
27682
|
+
from: 0,
|
|
27683
|
+
to: e.state.doc.length,
|
|
27684
|
+
insert: (value === null || value === undefined) ? '' : (typeof value === 'object' ? JSON.stringify(value, null, 2) : value)
|
|
27685
|
+
}
|
|
27686
|
+
});
|
|
27687
|
+
setEditor(e);
|
|
27688
|
+
}, []);
|
|
27689
|
+
React.useEffect(() => {
|
|
27690
|
+
if (editor && (typeof value === 'object' ? JSON.stringify(value, null, 2) : value) !== editor.state.doc.toString()) {
|
|
27691
|
+
editor.dispatch({
|
|
27692
|
+
changes: {
|
|
27693
|
+
from: 0,
|
|
27694
|
+
to: editor.state.doc.length,
|
|
27695
|
+
insert: (value === null || value === undefined) ? '' : (typeof value === 'object' ? JSON.stringify(value, null, 2) : value)
|
|
27696
|
+
}
|
|
27697
|
+
});
|
|
28515
27698
|
}
|
|
28516
|
-
|
|
28517
|
-
|
|
28518
|
-
|
|
28519
|
-
|
|
28520
|
-
|
|
28521
|
-
|
|
28522
|
-
|
|
28523
|
-
|
|
28524
|
-
|
|
28525
|
-
|
|
28526
|
-
|
|
28527
|
-
|
|
28528
|
-
|
|
28529
|
-
|
|
28530
|
-
|
|
28531
|
-
|
|
28532
|
-
|
|
28533
|
-
|
|
28534
|
-
|
|
28535
|
-
|
|
28536
|
-
|
|
28537
|
-
|
|
28538
|
-
|
|
28539
|
-
|
|
28540
|
-
|
|
28541
|
-
|
|
28542
|
-
|
|
28543
|
-
|
|
28544
|
-
|
|
28545
|
-
|
|
28546
|
-
|
|
28547
|
-
|
|
28548
|
-
|
|
28549
|
-
|
|
28550
|
-
|
|
28551
|
-
|
|
28552
|
-
|
|
28553
|
-
|
|
28554
|
-
|
|
28555
|
-
|
|
28556
|
-
|
|
28557
|
-
|
|
28558
|
-
|
|
28559
|
-
|
|
27699
|
+
}, [value]);
|
|
27700
|
+
return React__default["default"].createElement("div", { ref: ref });
|
|
27701
|
+
}
|
|
27702
|
+
|
|
27703
|
+
const converter = new showdown__default["default"].Converter({
|
|
27704
|
+
omitExtraWLInCodeBlocks: true,
|
|
27705
|
+
ghCompatibleHeaderId: true,
|
|
27706
|
+
parseImgDimensions: true,
|
|
27707
|
+
simplifiedAutoLink: true,
|
|
27708
|
+
tables: true,
|
|
27709
|
+
tasklists: true,
|
|
27710
|
+
requireSpaceBeforeHeadingText: true,
|
|
27711
|
+
ghMentions: true,
|
|
27712
|
+
emoji: true,
|
|
27713
|
+
ghMentionsLink: '/{u}'
|
|
27714
|
+
});
|
|
27715
|
+
const MarkdownInput = (props) => {
|
|
27716
|
+
const [preview, setPreview] = React.useState(props.preview || false);
|
|
27717
|
+
const ref = React.useRef();
|
|
27718
|
+
React.useEffect(() => {
|
|
27719
|
+
if (preview) {
|
|
27720
|
+
showPreview();
|
|
27721
|
+
}
|
|
27722
|
+
}, [preview, props.value]);
|
|
27723
|
+
const commands = [
|
|
27724
|
+
{
|
|
27725
|
+
name: 'Add header',
|
|
27726
|
+
icon: 'heading',
|
|
27727
|
+
inject: (range) => !range ? '#' : [{ from: range.from, insert: "# " }]
|
|
27728
|
+
},
|
|
27729
|
+
{
|
|
27730
|
+
name: 'Add bold text',
|
|
27731
|
+
icon: 'bold',
|
|
27732
|
+
inject: (range) => !range ? '** **' : [{ from: range.from, insert: "**" }, { from: range.to, insert: '**' }]
|
|
27733
|
+
},
|
|
27734
|
+
{
|
|
27735
|
+
name: 'Add italic text',
|
|
27736
|
+
icon: 'italic',
|
|
27737
|
+
inject: (range) => !range ? '* *' : [{ from: range.from, insert: '*' }, { from: range.to, insert: '*' }]
|
|
27738
|
+
},
|
|
27739
|
+
{
|
|
27740
|
+
name: 'Add strikethrough text',
|
|
27741
|
+
icon: 'strikethrough',
|
|
27742
|
+
inject: (range) => !range ? '~~ ~~' : [{ from: range.from, insert: '~~' }, { from: range.to, insert: '~~' }]
|
|
27743
|
+
},
|
|
27744
|
+
{
|
|
27745
|
+
name: 'Add link',
|
|
27746
|
+
icon: 'link',
|
|
27747
|
+
inject: (range) => !range ? '[ ](url)' : [{ from: range.from, insert: '[' }, { from: range.to, insert: '](url)' }]
|
|
27748
|
+
},
|
|
27749
|
+
{
|
|
27750
|
+
name: 'Add code',
|
|
27751
|
+
icon: 'code',
|
|
27752
|
+
inject: (range) => !range ? '```\n\n```\n' : [{ from: range.from, insert: '```\n' }, { from: range.to, insert: '\n```\n' }]
|
|
27753
|
+
},
|
|
27754
|
+
{
|
|
27755
|
+
name: 'Add quotes',
|
|
27756
|
+
icon: 'quote-right',
|
|
27757
|
+
inject: (range) => !range ? '> ' : [{ from: range.from, insert: '> ' }]
|
|
27758
|
+
},
|
|
27759
|
+
{
|
|
27760
|
+
name: 'Add image',
|
|
27761
|
+
icon: 'image',
|
|
27762
|
+
inject: (range) => !range ? '' : [{ from: range.from, insert: '' }]
|
|
27763
|
+
},
|
|
27764
|
+
{
|
|
27765
|
+
name: 'Add unordered list',
|
|
27766
|
+
icon: 'list-ul',
|
|
27767
|
+
inject: (range) => !range ? '* ' : [{ from: range.from, insert: '* ' }]
|
|
27768
|
+
},
|
|
27769
|
+
{
|
|
27770
|
+
name: 'Add ordered list',
|
|
27771
|
+
icon: 'list-ol',
|
|
27772
|
+
inject: (range) => !range ? '1. ' : [{ from: range.from, insert: '1. ' }]
|
|
27773
|
+
},
|
|
27774
|
+
{
|
|
27775
|
+
name: 'Add check list',
|
|
27776
|
+
icon: 'tasks',
|
|
27777
|
+
inject: (range) => !range ? '* [ ] ' : [{ from: range.from, insert: '* [ ] ' }]
|
|
27778
|
+
}
|
|
27779
|
+
];
|
|
27780
|
+
const showPreview = () => {
|
|
27781
|
+
const parent = [...document.getElementsByClassName('mrf-preview')];
|
|
27782
|
+
if (parent.length > 0)
|
|
27783
|
+
[...parent[0].querySelectorAll('pre code')]
|
|
27784
|
+
.forEach(block => hljs__default["default"].highlightElement(block));
|
|
27785
|
+
};
|
|
27786
|
+
const injectButtons = () => {
|
|
27787
|
+
return commands.map((command, idx) => {
|
|
27788
|
+
return (React__default["default"].createElement("button", { type: "button", className: classNames__default["default"]('mrf-btn_for_descriptionToolbar'), "aria-label": command.name, title: command.name, key: `toolbar-btn-${idx}`, onClick: () => {
|
|
27789
|
+
const editor = ref.current;
|
|
27790
|
+
const selections = editor.state.selection.ranges;
|
|
27791
|
+
if (selections.length === 1 && selections[0].from === selections[0].to)
|
|
27792
|
+
editor.dispatch({
|
|
27793
|
+
changes: {
|
|
27794
|
+
from: 0,
|
|
27795
|
+
to: editor.state.doc.length,
|
|
27796
|
+
insert: editor.state.doc.toString() + command.inject()
|
|
27797
|
+
}
|
|
27798
|
+
});
|
|
27799
|
+
else {
|
|
27800
|
+
editor.dispatch(editor.state.changeByRange((range) => ({
|
|
27801
|
+
changes: command.inject(range),
|
|
27802
|
+
range
|
|
27803
|
+
})));
|
|
27804
|
+
}
|
|
27805
|
+
} },
|
|
27806
|
+
React__default["default"].createElement("i", { className: `fas fa-${command.icon}` })));
|
|
27807
|
+
});
|
|
27808
|
+
};
|
|
27809
|
+
return React__default["default"].createElement("div", { className: classNames__default["default"](props.className) },
|
|
27810
|
+
!props.readOnly && React__default["default"].createElement("div", { style: {
|
|
27811
|
+
marginBottom: 10,
|
|
27812
|
+
} },
|
|
27813
|
+
React__default["default"].createElement("div", null,
|
|
27814
|
+
React__default["default"].createElement("div", null,
|
|
27815
|
+
React__default["default"].createElement("button", { type: "button", className: 'mrf-btn mrf-btn_sm', style: { color: !preview ? '#7f96af' : 'white', backgroundColor: preview ? '#7f96af' : 'white' }, onClick: () => setPreview(false) }, "Write"),
|
|
27816
|
+
React__default["default"].createElement("button", { type: "button", className: 'mrf-btn mrf-btn_sm mrf-ml_5', style: { color: preview ? '#7f96af' : 'white', backgroundColor: preview ? 'white' : '#7f96af' }, onClick: () => setPreview(true) }, "Preview"))),
|
|
27817
|
+
React__default["default"].createElement("div", { className: 'mrf-flex mrf-flexWrap' }, injectButtons())),
|
|
27818
|
+
!preview && (React__default["default"].createElement(CodeInput, Object.assign({}, props, { setRef: e => ref.current = e }))),
|
|
27819
|
+
preview && (React__default["default"].createElement("div", { className: "mrf-preview", dangerouslySetInnerHTML: { __html: converter.makeHtml(props.value || "") } })));
|
|
28560
27820
|
};
|
|
28561
27821
|
|
|
28562
|
-
function SingleLineCode(
|
|
28563
|
-
var onChange = _ref.onChange,
|
|
28564
|
-
value = _ref.value,
|
|
28565
|
-
_ref$mode = _ref.mode,
|
|
28566
|
-
mode = _ref$mode === void 0 ? 'javascript' : _ref$mode,
|
|
28567
|
-
_ref$tabSize = _ref.tabSize,
|
|
28568
|
-
tabSize = _ref$tabSize === void 0 ? 2 : _ref$tabSize,
|
|
28569
|
-
_ref$readOnly = _ref.readOnly,
|
|
28570
|
-
readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
|
|
28571
|
-
_ref$showLinesNumber = _ref.showLinesNumber,
|
|
28572
|
-
showLinesNumber = _ref$showLinesNumber === void 0 ? true : _ref$showLinesNumber,
|
|
28573
|
-
_ref$highlightLine = _ref.highlightLine,
|
|
28574
|
-
highlightLine = _ref$highlightLine === void 0 ? false : _ref$highlightLine,
|
|
28575
|
-
_ref$themeStyle = _ref.themeStyle,
|
|
28576
|
-
themeStyle = _ref$themeStyle === void 0 ? {
|
|
27822
|
+
function SingleLineCode({ onChange, value, mode = 'javascript', tabSize = 2, readOnly = false, showLinesNumber = true, highlightLine = false, themeStyle = {
|
|
28577
27823
|
height: '-1',
|
|
28578
27824
|
minHeight: '-1',
|
|
28579
27825
|
maxHeight: '-1',
|
|
28580
27826
|
width: '-1',
|
|
28581
27827
|
minWidth: '-1',
|
|
28582
|
-
maxWidth: '-1'
|
|
28583
|
-
|
|
28584
|
-
|
|
28585
|
-
|
|
28586
|
-
|
|
28587
|
-
|
|
28588
|
-
|
|
28589
|
-
|
|
28590
|
-
|
|
28591
|
-
|
|
28592
|
-
|
|
28593
|
-
|
|
28594
|
-
|
|
28595
|
-
|
|
28596
|
-
flex: 1,
|
|
28597
|
-
overflow: 'hidden'
|
|
28598
|
-
}
|
|
28599
|
-
});
|
|
27828
|
+
maxWidth: '-1',
|
|
27829
|
+
} }) {
|
|
27830
|
+
const ref = React.useRef();
|
|
27831
|
+
React.useEffect(() => {
|
|
27832
|
+
Editor(ref.current, mode, (v) => {
|
|
27833
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(v.replace(/\n/g, ""));
|
|
27834
|
+
}, value, tabSize, readOnly, showLinesNumber, highlightLine, themeStyle);
|
|
27835
|
+
ref.current.addEventListener("keydown", (e) => {
|
|
27836
|
+
e.stopImmediatePropagation();
|
|
27837
|
+
});
|
|
27838
|
+
}, []);
|
|
27839
|
+
return React__default["default"].createElement("div", { ref: ref, style: {
|
|
27840
|
+
flex: 1, overflow: 'hidden'
|
|
27841
|
+
} });
|
|
28600
27842
|
}
|
|
28601
27843
|
|
|
28602
|
-
|
|
28603
|
-
|
|
28604
|
-
|
|
28605
|
-
|
|
28606
|
-
|
|
28607
|
-
|
|
28608
|
-
|
|
28609
|
-
|
|
28610
|
-
|
|
28611
|
-
|
|
28612
|
-
|
|
28613
|
-
|
|
28614
|
-
|
|
28615
|
-
|
|
28616
|
-
|
|
28617
|
-
|
|
28618
|
-
|
|
28619
|
-
|
|
28620
|
-
|
|
28621
|
-
|
|
28622
|
-
|
|
28623
|
-
|
|
28624
|
-
|
|
28625
|
-
|
|
28626
|
-
|
|
28627
|
-
|
|
28628
|
-
|
|
28629
|
-
|
|
28630
|
-
|
|
28631
|
-
|
|
28632
|
-
|
|
28633
|
-
|
|
28634
|
-
|
|
28635
|
-
|
|
28636
|
-
|
|
27844
|
+
const resolvers = {
|
|
27845
|
+
[type.string]: (typeErrorMessage) => yup__namespace.string().nullable().optional().typeError(typeErrorMessage || 'Value must be a string'),
|
|
27846
|
+
[type.number]: (typeErrorMessage) => yup__namespace.number().nullable().optional()
|
|
27847
|
+
.transform(v => { return isNaN(v) ? null : v; })
|
|
27848
|
+
.typeError(typeErrorMessage || 'Value must be a number'),
|
|
27849
|
+
[type.bool]: () => yup__namespace.bool().nullable().optional(),
|
|
27850
|
+
[type.object]: () => yup__namespace.object().nullable().optional(),
|
|
27851
|
+
[type.date]: (typeErrorMessage) => yup__namespace.date().nullable().optional().typeError(typeErrorMessage || 'Value must be a date'),
|
|
27852
|
+
[type.file]: () => yup__namespace.mixed(),
|
|
27853
|
+
[type.json]: () => yup__namespace.mixed()
|
|
27854
|
+
};
|
|
27855
|
+
const buildSubResolver = (props, key, dependencies, rawValues) => {
|
|
27856
|
+
const { constraints = [] } = props;
|
|
27857
|
+
if (props.array || props.isMulti) {
|
|
27858
|
+
let subResolver;
|
|
27859
|
+
let arrayResolver = yup__namespace.array();
|
|
27860
|
+
if (props.schema) {
|
|
27861
|
+
const deps = [];
|
|
27862
|
+
subResolver = yup__namespace.object().shape(getShapeAndDependencies(props.flow || Object.keys(props.schema), props.schema, deps, rawValues).shape, deps);
|
|
27863
|
+
arrayResolver = arrayResolver.of(yup__namespace.object().shape({ value: subResolver }));
|
|
27864
|
+
}
|
|
27865
|
+
return constraints.reduce((resolver, constraint) => {
|
|
27866
|
+
return jsonOrFunctionConstraint(constraint, resolver, key, dependencies);
|
|
27867
|
+
}, arrayResolver);
|
|
27868
|
+
}
|
|
27869
|
+
else if (props.type === type.object && props.schema) {
|
|
27870
|
+
if (!Object.keys(props.schema).length) {
|
|
27871
|
+
return yup__namespace.object();
|
|
27872
|
+
}
|
|
27873
|
+
const subResolver = getShapeAndDependencies(props.flow || Object.keys(props.schema), props.schema, dependencies, rawValues);
|
|
27874
|
+
return constraints.reduce((resolver, constraint) => {
|
|
27875
|
+
return jsonOrFunctionConstraint(constraint, resolver, key, dependencies);
|
|
27876
|
+
}, yup__namespace.object().shape(subResolver.shape, dependencies));
|
|
27877
|
+
}
|
|
27878
|
+
else if (props.type === type.object && props.conditionalSchema) {
|
|
27879
|
+
const { schema, flow } = option(props.conditionalSchema)
|
|
27880
|
+
.map(condiSchema => {
|
|
27881
|
+
const ref = option(condiSchema.ref).map(ref => rawValues[ref]).getOrNull();
|
|
27882
|
+
const filterSwitch = condiSchema.switch.find(s => {
|
|
27883
|
+
if (typeof s.condition === 'function') {
|
|
27884
|
+
return s.condition({ rawValues, ref }); /* FIXME rawData vs rowValue */
|
|
27885
|
+
}
|
|
27886
|
+
else {
|
|
27887
|
+
return s.condition === ref;
|
|
27888
|
+
}
|
|
27889
|
+
});
|
|
27890
|
+
return option(filterSwitch)
|
|
27891
|
+
.orElse(condiSchema.switch.find(s => s.default))
|
|
27892
|
+
.getOrElse({ schema: {}, flow: [] });
|
|
27893
|
+
})
|
|
27894
|
+
.getOrElse({ schema: {}, flow: [] });
|
|
27895
|
+
const subResolver = getShapeAndDependencies(flow || Object.keys(schema), schema, dependencies, rawValues);
|
|
27896
|
+
return constraints.reduce((resolver, constraint) => {
|
|
27897
|
+
return jsonOrFunctionConstraint(constraint, resolver, key, dependencies);
|
|
27898
|
+
}, yup__namespace.object().shape(subResolver.shape, dependencies));
|
|
28637
27899
|
}
|
|
28638
|
-
|
|
28639
|
-
|
|
28640
|
-
|
|
28641
|
-
|
|
28642
|
-
} else if (props.type === type.object && props.schema) {
|
|
28643
|
-
if (!Object.keys(props.schema).length) {
|
|
28644
|
-
return yup__namespace.object();
|
|
27900
|
+
else {
|
|
27901
|
+
return constraints.reduce((resolver, constraint) => {
|
|
27902
|
+
return jsonOrFunctionConstraint(constraint, resolver, key, dependencies);
|
|
27903
|
+
}, resolvers[props.type]());
|
|
28645
27904
|
}
|
|
28646
|
-
|
|
28647
|
-
|
|
28648
|
-
|
|
28649
|
-
|
|
28650
|
-
|
|
28651
|
-
|
|
28652
|
-
|
|
28653
|
-
|
|
28654
|
-
var ref = option(condiSchema.ref).map(function (ref) {
|
|
28655
|
-
return rawData[ref];
|
|
28656
|
-
}).getOrNull();
|
|
28657
|
-
var filterSwitch = condiSchema["switch"].find(function (s) {
|
|
28658
|
-
if (typeof s.condition === 'function') {
|
|
28659
|
-
return s.condition({
|
|
28660
|
-
rawData: rawData,
|
|
28661
|
-
ref: ref
|
|
28662
|
-
});
|
|
28663
|
-
} else {
|
|
28664
|
-
return s.condition === ref;
|
|
28665
|
-
}
|
|
28666
|
-
});
|
|
28667
|
-
return option(filterSwitch).orElse(condiSchema["switch"].find(function (s) {
|
|
28668
|
-
return s["default"];
|
|
28669
|
-
})).getOrElse({
|
|
28670
|
-
schema: {},
|
|
28671
|
-
flow: []
|
|
28672
|
-
});
|
|
28673
|
-
}).getOrElse({
|
|
28674
|
-
schema: {},
|
|
28675
|
-
flow: []
|
|
28676
|
-
}),
|
|
28677
|
-
schema = _option$map$getOrElse.schema,
|
|
28678
|
-
flow = _option$map$getOrElse.flow;
|
|
28679
|
-
|
|
28680
|
-
var realFlow = flow || Object.keys(schema);
|
|
28681
|
-
|
|
28682
|
-
if (realFlow.length) {
|
|
28683
|
-
var _subResolver2 = getShapeAndDependencies(flow || Object.keys(schema), schema, dependencies, rawData);
|
|
28684
|
-
|
|
28685
|
-
return constraints.reduce(function (resolver, constraint) {
|
|
28686
|
-
return jsonOrFunctionConstraint(constraint, resolver, key, dependencies);
|
|
28687
|
-
}, yup__namespace.object().shape(_subResolver2.shape, dependencies));
|
|
27905
|
+
};
|
|
27906
|
+
const jsonOrFunctionConstraint = (constraint, resolver, key, dependencies) => {
|
|
27907
|
+
if (typeof constraint === 'function') {
|
|
27908
|
+
return constraint(resolver, key, dependencies);
|
|
27909
|
+
}
|
|
27910
|
+
else {
|
|
27911
|
+
// TODO
|
|
27912
|
+
return (jsonConstraints[constraint.type])(constraint)(resolver, key, dependencies);
|
|
28688
27913
|
}
|
|
28689
|
-
} else {
|
|
28690
|
-
return constraints.reduce(function (resolver, constraint) {
|
|
28691
|
-
return jsonOrFunctionConstraint(constraint, resolver, key, dependencies);
|
|
28692
|
-
}, resolvers[props.type]());
|
|
28693
|
-
}
|
|
28694
27914
|
};
|
|
28695
|
-
|
|
28696
|
-
|
|
28697
|
-
|
|
28698
|
-
|
|
28699
|
-
|
|
28700
|
-
|
|
28701
|
-
|
|
27915
|
+
const getShapeAndDependencies = (flow, schema, dependencies = [], rawData = {}) => {
|
|
27916
|
+
if (!Object.keys(schema).length) {
|
|
27917
|
+
return { shape: {}, dependencies };
|
|
27918
|
+
}
|
|
27919
|
+
const shape = (flow || Object.keys(schema))
|
|
27920
|
+
.reduce((resolvers, key) => {
|
|
27921
|
+
if (typeof key === 'object') {
|
|
27922
|
+
return Object.assign(Object.assign({}, resolvers), getShapeAndDependencies(key.flow, schema, dependencies, rawData).shape);
|
|
27923
|
+
}
|
|
27924
|
+
if (!schema[key]) {
|
|
27925
|
+
return resolvers;
|
|
27926
|
+
}
|
|
27927
|
+
const resolver = buildSubResolver(schema[key], key, dependencies, rawData);
|
|
27928
|
+
return Object.assign(Object.assign({}, resolvers), { [key]: resolver });
|
|
27929
|
+
}, {});
|
|
27930
|
+
return { shape, dependencies };
|
|
28702
27931
|
};
|
|
28703
27932
|
|
|
28704
|
-
|
|
28705
|
-
|
|
28706
|
-
|
|
28707
|
-
|
|
28708
|
-
if (!Object.keys(schema).length) {
|
|
28709
|
-
return {
|
|
28710
|
-
shape: yup__namespace.object().shape({}),
|
|
28711
|
-
dependencies: dependencies
|
|
28712
|
-
};
|
|
28713
|
-
}
|
|
28714
|
-
|
|
28715
|
-
var shape = (flow || Object.keys(schema)).reduce(function (resolvers, key) {
|
|
28716
|
-
if (_typeof$1(key) === 'object') {
|
|
28717
|
-
return _objectSpread2$1(_objectSpread2$1({}, resolvers), getShapeAndDependencies(key.flow, schema, dependencies, rawData).shape);
|
|
27933
|
+
const CustomizableInput$1 = React__namespace.memo((props) => {
|
|
27934
|
+
if (props.render) {
|
|
27935
|
+
return (props.render(Object.assign(Object.assign({}, props.field), { error: props.error })));
|
|
28718
27936
|
}
|
|
28719
|
-
|
|
28720
|
-
|
|
28721
|
-
|
|
27937
|
+
return props.children;
|
|
27938
|
+
}, (prev, next) => {
|
|
27939
|
+
if (next.render || next.conditionalSchema) {
|
|
27940
|
+
return false;
|
|
28722
27941
|
}
|
|
28723
|
-
|
|
28724
|
-
var resolver = buildSubResolver(schema[key], key, dependencies, rawData);
|
|
28725
|
-
return _objectSpread2$1(_objectSpread2$1({}, resolvers), {}, _defineProperty$1({}, key, resolver));
|
|
28726
|
-
}, {});
|
|
28727
|
-
return {
|
|
28728
|
-
shape: shape,
|
|
28729
|
-
dependencies: dependencies
|
|
28730
|
-
};
|
|
28731
|
-
};
|
|
28732
|
-
|
|
28733
|
-
var CustomizableInput$1 = /*#__PURE__*/React__default["default"].memo(function (props) {
|
|
28734
|
-
if (props.render) {
|
|
28735
|
-
return props.render(_objectSpread2$1(_objectSpread2$1({}, props.field), {}, {
|
|
28736
|
-
error: props.error
|
|
28737
|
-
}));
|
|
28738
|
-
}
|
|
28739
|
-
|
|
28740
|
-
return props.children;
|
|
28741
|
-
}, function (prev, next) {
|
|
28742
|
-
if (next.render || next.conditionalSchema) {
|
|
28743
|
-
return false;
|
|
28744
|
-
}
|
|
28745
|
-
|
|
28746
|
-
return prev.field.value === next.field.value && next.errorDisplayed === prev.errorDisplayed;
|
|
27942
|
+
return (prev.field.value === next.field.value && next.errorDisplayed === prev.errorDisplayed && cleanHash(next.step) === cleanHash(prev.step));
|
|
28747
27943
|
});
|
|
28748
|
-
|
|
28749
|
-
|
|
28750
|
-
|
|
28751
|
-
|
|
28752
|
-
|
|
28753
|
-
errorDisplayed = _ref.errorDisplayed;
|
|
28754
|
-
|
|
28755
|
-
var _useController = reactHookForm.useController({
|
|
28756
|
-
defaultValue: isDefined(step.defaultValue) ? step.defaultValue : null,
|
|
28757
|
-
name: entry
|
|
28758
|
-
}),
|
|
28759
|
-
field = _useController.field;
|
|
28760
|
-
|
|
28761
|
-
var _useFormContext = reactHookForm.useFormContext(),
|
|
28762
|
-
getValues = _useFormContext.getValues,
|
|
28763
|
-
_setValue = _useFormContext.setValue,
|
|
28764
|
-
errors = _useFormContext.formState.errors;
|
|
28765
|
-
|
|
28766
|
-
var functionalProperty = function functionalProperty(entry, prop) {
|
|
28767
|
-
if (typeof prop === 'function') {
|
|
28768
|
-
return prop({
|
|
28769
|
-
rawValues: getValues(),
|
|
28770
|
-
value: getValues(entry)
|
|
28771
|
-
});
|
|
28772
|
-
} else {
|
|
28773
|
-
return prop;
|
|
28774
|
-
}
|
|
28775
|
-
};
|
|
28776
|
-
|
|
28777
|
-
var props = _objectSpread2$1(_objectSpread2$1(_objectSpread2$1({}, field), step.props), {}, {
|
|
28778
|
-
id: entry,
|
|
28779
|
-
readOnly: functionalProperty(entry, step.disabled) ? 'readOnly' : null,
|
|
28780
|
-
placeholder: step.placeholder,
|
|
28781
|
-
onChange: function onChange(e) {
|
|
28782
|
-
var value = function () {
|
|
28783
|
-
if (!e) {
|
|
28784
|
-
if (step.type === type.bool || step.type === type.number && field.value === 0) {
|
|
28785
|
-
return e;
|
|
28786
|
-
} else {
|
|
28787
|
-
return null;
|
|
28788
|
-
}
|
|
28789
|
-
} else if (e.target) {
|
|
28790
|
-
return e.target.value || null;
|
|
28791
|
-
} else {
|
|
28792
|
-
return e;
|
|
28793
|
-
}
|
|
28794
|
-
}();
|
|
28795
|
-
|
|
28796
|
-
field.onChange(value);
|
|
28797
|
-
option(step.onChange).map(function (onChange) {
|
|
28798
|
-
return onChange({
|
|
28799
|
-
rawValues: getValues(),
|
|
28800
|
-
value: value,
|
|
28801
|
-
setValue: _setValue
|
|
28802
|
-
});
|
|
28803
|
-
});
|
|
28804
|
-
},
|
|
28805
|
-
value: field.value
|
|
28806
|
-
});
|
|
28807
|
-
|
|
28808
|
-
var error = entry.split('.').reduce(function (acc, curr) {
|
|
28809
|
-
return acc && acc[curr];
|
|
28810
|
-
}, errors);
|
|
28811
|
-
return /*#__PURE__*/React__default["default"].createElement(CustomizableInput$1, {
|
|
28812
|
-
render: step.render,
|
|
28813
|
-
field: _objectSpread2$1({
|
|
28814
|
-
parent: parent,
|
|
28815
|
-
setValue: function setValue(key, value) {
|
|
28816
|
-
return _setValue(key, value);
|
|
28817
|
-
},
|
|
28818
|
-
rawValues: getValues()
|
|
28819
|
-
}, field),
|
|
28820
|
-
error: error,
|
|
28821
|
-
errorDisplayed: errorDisplayed
|
|
28822
|
-
}, component ? component(field, props) : /*#__PURE__*/React__default["default"].cloneElement(children, _objectSpread2$1({}, props)));
|
|
28823
|
-
};
|
|
28824
|
-
|
|
28825
|
-
var usePrevious = function usePrevious(value) {
|
|
28826
|
-
// The ref object is a generic container whose current property is mutable ...
|
|
28827
|
-
// ... and can hold any value, similar to an instance property on a class
|
|
28828
|
-
var ref = React.useRef(); // Store current value in ref
|
|
28829
|
-
|
|
28830
|
-
React.useEffect(function () {
|
|
28831
|
-
ref.current = value;
|
|
28832
|
-
}, [value]); // Only re-run if value changes
|
|
28833
|
-
// Return previous value (happens before update in useEffect above)
|
|
28834
|
-
|
|
28835
|
-
return ref.current;
|
|
28836
|
-
};
|
|
28837
|
-
|
|
28838
|
-
var BasicWrapper = function BasicWrapper(_ref) {
|
|
28839
|
-
var entry = _ref.entry;
|
|
28840
|
-
_ref.className;
|
|
28841
|
-
var label = _ref.label,
|
|
28842
|
-
help = _ref.help,
|
|
28843
|
-
children = _ref.children,
|
|
28844
|
-
render = _ref.render;
|
|
28845
|
-
|
|
28846
|
-
if (_typeof$1(entry) === 'object') {
|
|
28847
|
-
return children;
|
|
28848
|
-
}
|
|
28849
|
-
|
|
28850
|
-
var id = uuid.v4();
|
|
28851
|
-
|
|
28852
|
-
var _useFormContext = reactHookForm.useFormContext(),
|
|
28853
|
-
formState = _useFormContext.formState;
|
|
28854
|
-
|
|
28855
|
-
var error = entry.split('.').reduce(function (acc, curr) {
|
|
28856
|
-
return acc && acc[curr];
|
|
28857
|
-
}, formState.errors);
|
|
28858
|
-
var isDirty = entry.split('.').reduce(function (acc, curr) {
|
|
28859
|
-
return acc && acc[curr];
|
|
28860
|
-
}, formState.dirtyFields);
|
|
28861
|
-
var isTouched = entry.split('.').reduce(function (acc, curr) {
|
|
28862
|
-
return acc && acc[curr];
|
|
28863
|
-
}, formState.touchedFields);
|
|
28864
|
-
var errorDisplayed = formState.isSubmitted || isDirty || isTouched;
|
|
28865
|
-
|
|
28866
|
-
if (render) {
|
|
28867
|
-
return render({
|
|
28868
|
-
entry: entry,
|
|
28869
|
-
label: label,
|
|
28870
|
-
error: error,
|
|
28871
|
-
help: help,
|
|
28872
|
-
children: children
|
|
27944
|
+
const ControlledInput = (inputProps) => {
|
|
27945
|
+
const { step, entry, children, component, errorDisplayed = false } = inputProps;
|
|
27946
|
+
const { field } = reactHookForm.useController({
|
|
27947
|
+
defaultValue: isDefined(step.defaultValue) ? step.defaultValue : null,
|
|
27948
|
+
name: entry
|
|
28873
27949
|
});
|
|
28874
|
-
|
|
28875
|
-
|
|
28876
|
-
|
|
28877
|
-
|
|
28878
|
-
|
|
28879
|
-
|
|
28880
|
-
|
|
28881
|
-
|
|
28882
|
-
|
|
28883
|
-
|
|
28884
|
-
|
|
28885
|
-
|
|
28886
|
-
|
|
28887
|
-
|
|
28888
|
-
|
|
28889
|
-
|
|
28890
|
-
|
|
28891
|
-
|
|
28892
|
-
|
|
28893
|
-
|
|
28894
|
-
|
|
28895
|
-
|
|
28896
|
-
|
|
28897
|
-
|
|
28898
|
-
|
|
28899
|
-
|
|
28900
|
-
|
|
28901
|
-
|
|
28902
|
-
|
|
28903
|
-
};
|
|
28904
|
-
|
|
28905
|
-
|
|
28906
|
-
|
|
28907
|
-
return props.render(_objectSpread2$1(_objectSpread2$1({}, props.field), {}, {
|
|
28908
|
-
error: props.error
|
|
28909
|
-
}));
|
|
28910
|
-
}
|
|
28911
|
-
|
|
28912
|
-
return props.children;
|
|
27950
|
+
const { getValues, setValue, formState: { errors } } = reactHookForm.useFormContext();
|
|
27951
|
+
const functionalProperty = (entry, prop) => {
|
|
27952
|
+
if (typeof prop === 'function') {
|
|
27953
|
+
return prop({ rawValues: getValues(), value: getValues(entry) });
|
|
27954
|
+
}
|
|
27955
|
+
else {
|
|
27956
|
+
return prop;
|
|
27957
|
+
}
|
|
27958
|
+
};
|
|
27959
|
+
const props = Object.assign(Object.assign({ name: field.name }, step.props), { id: entry, readOnly: functionalProperty(entry, step.disabled) ? 'readOnly' : null, placeholder: step.placeholder, onChange: (e) => {
|
|
27960
|
+
const value = (() => {
|
|
27961
|
+
if (!e) {
|
|
27962
|
+
if (step.type === type.bool ||
|
|
27963
|
+
(step.type === type.number && field.value === 0)) {
|
|
27964
|
+
return e;
|
|
27965
|
+
}
|
|
27966
|
+
else {
|
|
27967
|
+
return null;
|
|
27968
|
+
}
|
|
27969
|
+
}
|
|
27970
|
+
else if (e.target) {
|
|
27971
|
+
return e.target.value || null;
|
|
27972
|
+
}
|
|
27973
|
+
else {
|
|
27974
|
+
return e;
|
|
27975
|
+
}
|
|
27976
|
+
})();
|
|
27977
|
+
field.onChange(value);
|
|
27978
|
+
option(step.onChange)
|
|
27979
|
+
.map(onChange => onChange({ rawValues: getValues(), value, setValue }));
|
|
27980
|
+
}, value: field.value });
|
|
27981
|
+
const error = entry.split('.').reduce((acc, curr) => acc && acc[curr], errors);
|
|
27982
|
+
return React__namespace.createElement(CustomizableInput$1, { render: step.render, step: step, field: Object.assign({ parent, setValue: (key, value) => setValue(key, value), rawValues: getValues() }, field), error: error, errorDisplayed: errorDisplayed }, component ? component(field, props) : React__namespace.cloneElement(children, Object.assign({}, props)));
|
|
28913
27983
|
};
|
|
28914
27984
|
|
|
28915
|
-
|
|
28916
|
-
|
|
28917
|
-
|
|
28918
|
-
|
|
27985
|
+
const usePrevious = (value) => {
|
|
27986
|
+
// The ref object is a generic container whose current property is mutable ...
|
|
27987
|
+
// ... and can hold any value, similar to an instance property on a class
|
|
27988
|
+
const ref = React.useRef();
|
|
27989
|
+
// Store current value in ref
|
|
27990
|
+
React.useEffect(() => {
|
|
27991
|
+
ref.current = value;
|
|
27992
|
+
}, [value]); // Only re-run if value changes
|
|
27993
|
+
// Return previous value (happens before update in useEffect above)
|
|
27994
|
+
return ref.current;
|
|
28919
27995
|
};
|
|
28920
|
-
|
|
28921
|
-
|
|
28922
|
-
|
|
28923
|
-
|
|
28924
|
-
|
|
28925
|
-
|
|
28926
|
-
|
|
28927
|
-
|
|
28928
|
-
|
|
28929
|
-
|
|
28930
|
-
|
|
27996
|
+
const BasicWrapper = ({ entry, children, render, functionalProperty, step }) => {
|
|
27997
|
+
const { formState, watch } = reactHookForm.useFormContext();
|
|
27998
|
+
if (typeof entry === 'object') {
|
|
27999
|
+
return children;
|
|
28000
|
+
}
|
|
28001
|
+
const visibleStep = option(step)
|
|
28002
|
+
.map(s => s.visible)
|
|
28003
|
+
.map(visible => {
|
|
28004
|
+
let value;
|
|
28005
|
+
switch (typeof visible) {
|
|
28006
|
+
case 'object':
|
|
28007
|
+
value = watch(visible.ref);
|
|
28008
|
+
return option(visible.test).map(test => test(value)).getOrElse(value);
|
|
28009
|
+
case 'boolean':
|
|
28010
|
+
return visible;
|
|
28011
|
+
default:
|
|
28012
|
+
return true;
|
|
28013
|
+
}
|
|
28014
|
+
})
|
|
28015
|
+
.getOrElse(true);
|
|
28016
|
+
if (!visibleStep) {
|
|
28017
|
+
return null;
|
|
28931
28018
|
}
|
|
28932
|
-
|
|
28933
|
-
|
|
28934
|
-
|
|
28019
|
+
const computedLabel = functionalProperty(entry, (step === null || step === void 0 ? void 0 : step.label) === null ? null : (step === null || step === void 0 ? void 0 : step.label) || entry);
|
|
28020
|
+
const id = uuid$1.v4();
|
|
28021
|
+
// FIXME not sure it works as intended with more two or more parts
|
|
28022
|
+
const error = entry.split('.').reduce((acc, curr) => acc && acc[curr], formState.errors);
|
|
28023
|
+
const isDirty = entry.split('.').reduce((acc, curr) => acc && acc[curr], formState.dirtyFields);
|
|
28024
|
+
const isTouched = entry.split('.').reduce((acc, curr) => acc && acc[curr], formState.touchedFields);
|
|
28025
|
+
const errorDisplayed = formState.isSubmitted || isDirty || isTouched;
|
|
28026
|
+
if (render) {
|
|
28027
|
+
return render({ entry, label: computedLabel, error, help: step === null || step === void 0 ? void 0 : step.help, children });
|
|
28028
|
+
}
|
|
28029
|
+
return (React__default["default"].createElement("div", { className: 'mrf-mt_10', style: { position: 'relative' } },
|
|
28030
|
+
computedLabel && React__default["default"].createElement("label", { className: 'mrf-flex mrf-ai_center mrf-mb_5', htmlFor: entry },
|
|
28031
|
+
React__default["default"].createElement("span", null, computedLabel),
|
|
28032
|
+
(step === null || step === void 0 ? void 0 : step.help) && React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
28033
|
+
React__default["default"].createElement(ReactToolTip__default["default"], { html: true, place: 'bottom', id: id }),
|
|
28034
|
+
React__default["default"].createElement("span", { className: 'mrf-flex mrf-ai_center', "data-html": true, "data-tip": step === null || step === void 0 ? void 0 : step.help, "data-for": id },
|
|
28035
|
+
React__default["default"].createElement(reactFeather.HelpCircle, { style: { color: 'gray', width: 17, marginLeft: '.5rem', cursor: 'help' } })))),
|
|
28036
|
+
children,
|
|
28037
|
+
error && React__default["default"].createElement("div", { className: classNames__default["default"]('mrf-feedback', { ['mrf-txt_red']: !!errorDisplayed }) }, error.message)));
|
|
28935
28038
|
};
|
|
28936
|
-
|
|
28937
|
-
|
|
28938
|
-
|
|
28939
|
-
return f.map(function (v) {
|
|
28940
|
-
return v.flow || v;
|
|
28941
|
-
});
|
|
28942
|
-
}).map(arrayFlatten).getOrElse(Object.keys(subSchema || {}));
|
|
28943
|
-
return Object.entries(subSchema || {}).filter(function (_ref2) {
|
|
28944
|
-
var _ref3 = _slicedToArray(_ref2, 1),
|
|
28945
|
-
key = _ref3[0];
|
|
28946
|
-
|
|
28947
|
-
return realFlow.includes(key);
|
|
28948
|
-
}).reduce(function (acc, _ref4) {
|
|
28949
|
-
var _ref5 = _slicedToArray(_ref4, 2),
|
|
28950
|
-
key = _ref5[0],
|
|
28951
|
-
step = _ref5[1];
|
|
28952
|
-
|
|
28953
|
-
var v = null;
|
|
28954
|
-
|
|
28955
|
-
if (obj) {
|
|
28956
|
-
v = obj[key];
|
|
28039
|
+
const CustomizableInput = (props) => {
|
|
28040
|
+
if (props.render) {
|
|
28041
|
+
return (props.render(Object.assign(Object.assign({}, props.field), { error: props.error })));
|
|
28957
28042
|
}
|
|
28958
|
-
|
|
28959
|
-
var maybeDefaultValue = defaultValues[key];
|
|
28960
|
-
|
|
28961
|
-
if (!v && isDefined(maybeDefaultValue)) {
|
|
28962
|
-
v = maybeDefaultValue;
|
|
28963
|
-
}
|
|
28964
|
-
|
|
28965
|
-
if (step.array && !step.render) {
|
|
28966
|
-
return _objectSpread2$1(_objectSpread2$1({}, acc), {}, _defineProperty$1({}, key, (v || []).map(function (value) {
|
|
28967
|
-
var _subSchema$key, _subSchema$key2;
|
|
28968
|
-
|
|
28969
|
-
return {
|
|
28970
|
-
value: _typeof$1(value) === 'object' && !(value instanceof Date) && !Array.isArray(value) ? cleanInputArray(value, defaultValues, (_subSchema$key = subSchema[key]) === null || _subSchema$key === void 0 ? void 0 : _subSchema$key.flow, ((_subSchema$key2 = subSchema[key]) === null || _subSchema$key2 === void 0 ? void 0 : _subSchema$key2.schema) || {}) : value
|
|
28971
|
-
};
|
|
28972
|
-
})));
|
|
28973
|
-
} else if (_typeof$1(v) === 'object' && !(v instanceof Date) && !Array.isArray(v)) {
|
|
28974
|
-
var _subSchema$key3, _subSchema$key4;
|
|
28975
|
-
|
|
28976
|
-
return _objectSpread2$1(_objectSpread2$1({}, acc), {}, _defineProperty$1({}, key, cleanInputArray(v, defaultValues, (_subSchema$key3 = subSchema[key]) === null || _subSchema$key3 === void 0 ? void 0 : _subSchema$key3.flow, ((_subSchema$key4 = subSchema[key]) === null || _subSchema$key4 === void 0 ? void 0 : _subSchema$key4.schema) || {})));
|
|
28977
|
-
} else {
|
|
28978
|
-
return _objectSpread2$1(_objectSpread2$1({}, acc), {}, _defineProperty$1({}, key, v === undefined ? Array.isArray(v) ? [] : step.type === type.object ? {} : null : v));
|
|
28979
|
-
}
|
|
28980
|
-
}, obj);
|
|
28043
|
+
return props.children;
|
|
28981
28044
|
};
|
|
28982
|
-
|
|
28983
|
-
|
|
28984
|
-
|
|
28985
|
-
|
|
28986
|
-
|
|
28987
|
-
|
|
28988
|
-
|
|
28989
|
-
|
|
28990
|
-
|
|
28991
|
-
|
|
28992
|
-
|
|
28993
|
-
|
|
28994
|
-
|
|
28995
|
-
|
|
28996
|
-
|
|
28997
|
-
|
|
28998
|
-
return
|
|
28999
|
-
|
|
29000
|
-
|
|
29001
|
-
|
|
29002
|
-
|
|
29003
|
-
|
|
29004
|
-
|
|
29005
|
-
|
|
29006
|
-
|
|
29007
|
-
|
|
29008
|
-
|
|
29009
|
-
|
|
29010
|
-
|
|
29011
|
-
|
|
29012
|
-
|
|
29013
|
-
|
|
29014
|
-
|
|
29015
|
-
|
|
29016
|
-
|
|
29017
|
-
}
|
|
29018
|
-
|
|
28045
|
+
const defaultVal = (value, array, defaultValue, type) => {
|
|
28046
|
+
if (isDefined(defaultValue))
|
|
28047
|
+
return defaultValue;
|
|
28048
|
+
if (array)
|
|
28049
|
+
return [];
|
|
28050
|
+
return value;
|
|
28051
|
+
};
|
|
28052
|
+
function getDefaultValues(flow, schema, value) {
|
|
28053
|
+
return (flow || []).reduce((acc, key) => {
|
|
28054
|
+
if (typeof key === 'object') {
|
|
28055
|
+
return Object.assign(Object.assign({}, acc), getDefaultValues(key.flow, schema, value));
|
|
28056
|
+
}
|
|
28057
|
+
const entry = schema[key];
|
|
28058
|
+
if (!entry) {
|
|
28059
|
+
return acc;
|
|
28060
|
+
}
|
|
28061
|
+
return Object.assign(Object.assign({}, acc), { [key]: defaultVal(value ? value[key] : null, entry.array || entry.isMulti || false, entry.defaultValue) });
|
|
28062
|
+
}, {});
|
|
28063
|
+
}
|
|
28064
|
+
const cleanInputArray = (obj = {}, defaultValues = {}, flow, subSchema) => {
|
|
28065
|
+
const realFlow = option(flow)
|
|
28066
|
+
.map(f => f.map(v => typeof v === 'object' ? v.flow : v))
|
|
28067
|
+
.map(arrayFlatten)
|
|
28068
|
+
.getOrElse(Object.keys(subSchema || {}));
|
|
28069
|
+
return Object.entries(subSchema || {})
|
|
28070
|
+
.filter(([key]) => realFlow.includes(key))
|
|
28071
|
+
.reduce((acc, [key, step]) => {
|
|
28072
|
+
var _a, _b;
|
|
28073
|
+
let v = null;
|
|
28074
|
+
if (obj) {
|
|
28075
|
+
v = obj[key];
|
|
28076
|
+
}
|
|
28077
|
+
const maybeDefaultValue = defaultValues[key];
|
|
28078
|
+
if (!v && isDefined(maybeDefaultValue)) {
|
|
28079
|
+
v = maybeDefaultValue;
|
|
28080
|
+
}
|
|
28081
|
+
if (step.array && !step.render) {
|
|
28082
|
+
return Object.assign(Object.assign({}, acc), { [key]: (v || []).map((value) => {
|
|
28083
|
+
var _a, _b;
|
|
28084
|
+
return ({
|
|
28085
|
+
value: typeof value === 'object' && !(value instanceof Date) && !Array.isArray(value) ?
|
|
28086
|
+
cleanInputArray(value, defaultValues, (_a = subSchema === null || subSchema === void 0 ? void 0 : subSchema[key]) === null || _a === void 0 ? void 0 : _a.flow, ((_b = subSchema === null || subSchema === void 0 ? void 0 : subSchema[key]) === null || _b === void 0 ? void 0 : _b.schema) || {}) : value
|
|
28087
|
+
});
|
|
28088
|
+
}) });
|
|
29019
28089
|
}
|
|
29020
|
-
|
|
29021
|
-
|
|
29022
|
-
|
|
29023
|
-
|
|
29024
|
-
|
|
28090
|
+
else if (typeof v === 'object' && !(v instanceof Date) && !Array.isArray(v)) {
|
|
28091
|
+
return Object.assign(Object.assign({}, acc), { [key]: cleanInputArray(v, defaultValues, (_a = subSchema === null || subSchema === void 0 ? void 0 : subSchema[key]) === null || _a === void 0 ? void 0 : _a.flow, ((_b = subSchema === null || subSchema === void 0 ? void 0 : subSchema[key]) === null || _b === void 0 ? void 0 : _b.schema) || {}) });
|
|
28092
|
+
}
|
|
28093
|
+
else {
|
|
28094
|
+
return Object.assign(Object.assign({}, acc), { [key]: v === undefined ? (Array.isArray(v) ? [] : step.type === type.object ? {} : null) : v });
|
|
28095
|
+
}
|
|
28096
|
+
}, obj);
|
|
29025
28097
|
};
|
|
29026
|
-
|
|
29027
|
-
|
|
29028
|
-
|
|
29029
|
-
|
|
29030
|
-
|
|
29031
|
-
|
|
29032
|
-
|
|
29033
|
-
|
|
29034
|
-
|
|
29035
|
-
|
|
29036
|
-
|
|
28098
|
+
const cleanOutputArray = (obj, subSchema) => {
|
|
28099
|
+
return Object.entries(obj).reduce((acc, curr) => {
|
|
28100
|
+
var _a, _b;
|
|
28101
|
+
const [key, v] = curr;
|
|
28102
|
+
if (Array.isArray(v)) {
|
|
28103
|
+
const isArray = option(subSchema)
|
|
28104
|
+
// .orElse(schema) TODO : schema is undefined
|
|
28105
|
+
.map(s => s[key])
|
|
28106
|
+
.map(entry => !!entry.array && !entry.render)
|
|
28107
|
+
.getOrElse(false);
|
|
28108
|
+
if (isArray) {
|
|
28109
|
+
return Object.assign(Object.assign({}, acc), { [key]: v.map(step => {
|
|
28110
|
+
var _a;
|
|
28111
|
+
if (!!step.value && typeof step.value === 'object' && !(step.value instanceof (Date) && !Array.isArray(step.value)))
|
|
28112
|
+
return cleanOutputArray(step.value, ((_a = subSchema[key]) === null || _a === void 0 ? void 0 : _a.schema) || {});
|
|
28113
|
+
return step.value;
|
|
28114
|
+
}) });
|
|
28115
|
+
}
|
|
28116
|
+
return Object.assign(Object.assign({}, acc), { [key]: v });
|
|
28117
|
+
}
|
|
28118
|
+
else if (!!v && typeof v === 'object' && !(v instanceof (Date) && !Array.isArray(v))) {
|
|
28119
|
+
return Object.assign(Object.assign({}, acc), { [key]: cleanOutputArray(v, ((_a = subSchema[key]) === null || _a === void 0 ? void 0 : _a.schema) || {}) });
|
|
28120
|
+
}
|
|
28121
|
+
else {
|
|
28122
|
+
if (((_b = subSchema[key]) === null || _b === void 0 ? void 0 : _b.type) === 'json') {
|
|
28123
|
+
try {
|
|
28124
|
+
return Object.assign(Object.assign({}, acc), { [key]: JSON.parse(v) });
|
|
28125
|
+
}
|
|
28126
|
+
catch (err) {
|
|
28127
|
+
return Object.assign(Object.assign({}, acc), { [key]: v });
|
|
28128
|
+
}
|
|
28129
|
+
}
|
|
28130
|
+
else {
|
|
28131
|
+
return Object.assign(Object.assign({}, acc), { [key]: v });
|
|
28132
|
+
}
|
|
28133
|
+
}
|
|
28134
|
+
}, {});
|
|
29037
28135
|
};
|
|
29038
|
-
|
|
29039
|
-
|
|
29040
|
-
|
|
29041
|
-
|
|
29042
|
-
|
|
29043
|
-
|
|
29044
|
-
|
|
29045
|
-
|
|
29046
|
-
control: control
|
|
29047
|
-
});
|
|
29048
|
-
useHashEffect(function () {
|
|
29049
|
-
if (!!options.autosubmit) {
|
|
29050
|
-
handleSubmit(function () {
|
|
29051
|
-
onSubmit(cleanOutputArray(data, schema));
|
|
29052
|
-
})();
|
|
29053
|
-
}
|
|
29054
|
-
}, [data]);
|
|
29055
|
-
|
|
29056
|
-
if (options.watch) {
|
|
29057
|
-
if (typeof options.watch === 'function') {
|
|
29058
|
-
options.watch(cleanOutputArray(data, schema));
|
|
29059
|
-
} else {
|
|
29060
|
-
console.group('react-form watch');
|
|
29061
|
-
console.log(cleanOutputArray(data, schema));
|
|
29062
|
-
console.groupEnd();
|
|
29063
|
-
}
|
|
29064
|
-
}
|
|
29065
|
-
|
|
29066
|
-
return null;
|
|
28136
|
+
const validate = (flow, schema, value) => {
|
|
28137
|
+
const formFlow = flow || Object.keys(schema);
|
|
28138
|
+
const { shape, dependencies } = getShapeAndDependencies(formFlow, schema);
|
|
28139
|
+
return yup__namespace.object()
|
|
28140
|
+
.shape(shape, dependencies)
|
|
28141
|
+
.validate(value, {
|
|
28142
|
+
abortEarly: false
|
|
28143
|
+
});
|
|
29067
28144
|
};
|
|
29068
|
-
|
|
29069
|
-
|
|
29070
|
-
|
|
29071
|
-
|
|
29072
|
-
|
|
29073
|
-
|
|
29074
|
-
|
|
29075
|
-
|
|
29076
|
-
|
|
29077
|
-
|
|
29078
|
-
|
|
29079
|
-
|
|
29080
|
-
|
|
29081
|
-
|
|
29082
|
-
|
|
29083
|
-
|
|
29084
|
-
|
|
29085
|
-
|
|
29086
|
-
//todo: if present props.resolve()
|
|
29087
|
-
if (options.httpClient) {
|
|
29088
|
-
return options.httpClient(url, method);
|
|
28145
|
+
const Watcher = ({ options, control, schema, onSubmit, handleSubmit }) => {
|
|
28146
|
+
const data = reactHookForm.useWatch({ control });
|
|
28147
|
+
useHashEffect(() => {
|
|
28148
|
+
if (options.autosubmit) {
|
|
28149
|
+
handleSubmit(() => {
|
|
28150
|
+
onSubmit(cleanOutputArray(data, schema));
|
|
28151
|
+
})();
|
|
28152
|
+
}
|
|
28153
|
+
}, [data]);
|
|
28154
|
+
if (options.watch) {
|
|
28155
|
+
if (typeof options.watch === 'function') {
|
|
28156
|
+
options.watch(cleanOutputArray(data, schema));
|
|
28157
|
+
}
|
|
28158
|
+
else {
|
|
28159
|
+
console.group('react-form watch');
|
|
28160
|
+
console.log(cleanOutputArray(data, schema));
|
|
28161
|
+
console.groupEnd();
|
|
28162
|
+
}
|
|
29089
28163
|
}
|
|
29090
|
-
|
|
29091
|
-
|
|
29092
|
-
|
|
29093
|
-
|
|
29094
|
-
|
|
29095
|
-
|
|
29096
|
-
|
|
28164
|
+
return null;
|
|
28165
|
+
};
|
|
28166
|
+
const Form = React__default["default"].forwardRef(function Form({ schema, flow, value, inputWrapper, onSubmit, onError = () => { }, footer, style = {}, className, options = {}, nostyle }, ref) {
|
|
28167
|
+
const formFlow = flow || Object.keys(schema);
|
|
28168
|
+
const maybeCustomHttpClient = (url, method) => {
|
|
28169
|
+
//todo: if present props.resolve()
|
|
28170
|
+
if (options.httpClient) {
|
|
28171
|
+
return options.httpClient(url, method);
|
|
28172
|
+
}
|
|
28173
|
+
return fetch(url, {
|
|
28174
|
+
method,
|
|
28175
|
+
headers: {
|
|
28176
|
+
Accept: 'application/json',
|
|
28177
|
+
'Content-Type': 'application/json'
|
|
28178
|
+
},
|
|
28179
|
+
});
|
|
28180
|
+
};
|
|
28181
|
+
const defaultValues = getDefaultValues(formFlow, schema, value);
|
|
28182
|
+
//FIXME: get real schema through the switch
|
|
28183
|
+
const resolver = (rawData) => {
|
|
28184
|
+
const { shape, dependencies } = getShapeAndDependencies(formFlow, schema, [], rawData);
|
|
28185
|
+
const resolver = yup__namespace.object().shape(shape, dependencies);
|
|
28186
|
+
return resolver;
|
|
28187
|
+
};
|
|
28188
|
+
const methods = reactHookForm.useForm({
|
|
28189
|
+
resolver: (data, context, options) => yup$1.yupResolver(resolver(data))(data, context, options),
|
|
28190
|
+
shouldFocusError: false,
|
|
28191
|
+
mode: 'onChange'
|
|
29097
28192
|
});
|
|
29098
|
-
|
|
29099
|
-
|
|
29100
|
-
|
|
29101
|
-
|
|
29102
|
-
|
|
29103
|
-
|
|
29104
|
-
|
|
29105
|
-
|
|
29106
|
-
|
|
29107
|
-
|
|
29108
|
-
|
|
29109
|
-
|
|
29110
|
-
|
|
29111
|
-
|
|
29112
|
-
|
|
29113
|
-
|
|
29114
|
-
|
|
29115
|
-
|
|
29116
|
-
|
|
29117
|
-
|
|
29118
|
-
|
|
29119
|
-
var _useState = React.useState(false),
|
|
29120
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
29121
|
-
initialReseted = _useState2[0];
|
|
29122
|
-
_useState2[1]; // useEffect(() => {
|
|
29123
|
-
// reset(cleanInputArray(value, defaultValues, flow, schema))
|
|
29124
|
-
// setReset(true)
|
|
29125
|
-
// }, [reset])
|
|
29126
|
-
|
|
29127
|
-
|
|
29128
|
-
React.useEffect(function () {
|
|
29129
|
-
trigger();
|
|
29130
|
-
}, [trigger, initialReseted]);
|
|
29131
|
-
var _handleSubmit = methods.handleSubmit,
|
|
29132
|
-
_methods$formState = methods.formState;
|
|
29133
|
-
_methods$formState.errors;
|
|
29134
|
-
var dirtyFields = _methods$formState.dirtyFields,
|
|
29135
|
-
_reset = methods.reset,
|
|
29136
|
-
trigger = methods.trigger,
|
|
29137
|
-
getValues = methods.getValues,
|
|
29138
|
-
watch = methods.watch;
|
|
29139
|
-
useHashEffect(function () {
|
|
29140
|
-
_reset(_objectSpread2$1({}, cleanInputArray(value, defaultValues, flow, schema)));
|
|
29141
|
-
}, [value, schema]);
|
|
29142
|
-
|
|
29143
|
-
var functionalProperty = function functionalProperty(entry, prop) {
|
|
29144
|
-
if (typeof prop === 'function') {
|
|
29145
|
-
return prop({
|
|
29146
|
-
rawValues: getValues(),
|
|
29147
|
-
value: getValues(entry)
|
|
29148
|
-
});
|
|
29149
|
-
} else {
|
|
29150
|
-
return prop;
|
|
29151
|
-
}
|
|
29152
|
-
};
|
|
29153
|
-
|
|
29154
|
-
React.useImperativeHandle(ref, function () {
|
|
29155
|
-
return {
|
|
29156
|
-
handleSubmit: function handleSubmit() {
|
|
29157
|
-
return _handleSubmit(function (data) {
|
|
29158
|
-
var clean = cleanOutputArray(data, schema);
|
|
29159
|
-
onSubmit(clean);
|
|
29160
|
-
}, onError)();
|
|
29161
|
-
},
|
|
29162
|
-
trigger: trigger,
|
|
29163
|
-
methods: _objectSpread2$1(_objectSpread2$1({}, methods), {}, {
|
|
29164
|
-
data: function data() {
|
|
29165
|
-
return cleanOutputArray(getValues(), schema);
|
|
29166
|
-
}
|
|
29167
|
-
})
|
|
28193
|
+
const [initialReseted, setReset] = React.useState(false);
|
|
28194
|
+
// useEffect(() => {
|
|
28195
|
+
// reset(cleanInputArray(value, defaultValues, flow, schema))
|
|
28196
|
+
// setReset(true)
|
|
28197
|
+
// }, [reset])
|
|
28198
|
+
const { handleSubmit, formState: { errors, dirtyFields }, reset, trigger, getValues, watch } = methods;
|
|
28199
|
+
React.useEffect(() => {
|
|
28200
|
+
if (!!options.showErrorsOnStart) {
|
|
28201
|
+
trigger();
|
|
28202
|
+
}
|
|
28203
|
+
}, [trigger, initialReseted]);
|
|
28204
|
+
useHashEffect(() => {
|
|
28205
|
+
reset(Object.assign({}, cleanInputArray(value, defaultValues, flow, schema)));
|
|
28206
|
+
}, [value, schema]);
|
|
28207
|
+
const functionalProperty = (entry, prop) => {
|
|
28208
|
+
if (typeof prop === 'function') {
|
|
28209
|
+
return prop({ rawValues: getValues(), value: getValues(entry) }); // FIXME why ???
|
|
28210
|
+
}
|
|
28211
|
+
else {
|
|
28212
|
+
return prop;
|
|
28213
|
+
}
|
|
29168
28214
|
};
|
|
29169
|
-
|
|
29170
|
-
|
|
29171
|
-
|
|
29172
|
-
|
|
29173
|
-
|
|
29174
|
-
|
|
29175
|
-
|
|
29176
|
-
watch: methods.watch
|
|
29177
|
-
}), /*#__PURE__*/React__default["default"].createElement("form", {
|
|
29178
|
-
className: className || "mrf-pr_15 mrf-w_100",
|
|
29179
|
-
onSubmit: _handleSubmit(function (data) {
|
|
29180
|
-
var clean = cleanOutputArray(data, schema);
|
|
29181
|
-
onSubmit(clean);
|
|
29182
|
-
}, onError)
|
|
29183
|
-
}, formFlow.map(function (entry, idx) {
|
|
29184
|
-
var step = schema[entry];
|
|
29185
|
-
|
|
29186
|
-
if (!step && typeof entry === 'string') {
|
|
29187
|
-
console.error("no step found for the entry \"".concat(entry, "\" in the given schema. Your form might not work properly. Please fix it"));
|
|
29188
|
-
return null;
|
|
29189
|
-
}
|
|
29190
|
-
|
|
29191
|
-
var visibleStep = option(step).map(function (s) {
|
|
29192
|
-
return s.visible;
|
|
29193
|
-
}).map(function (visible) {
|
|
29194
|
-
switch (_typeof$1(visible)) {
|
|
29195
|
-
case 'object':
|
|
29196
|
-
var _value = watch(step.visible.ref);
|
|
29197
|
-
|
|
29198
|
-
return option(step.visible.test).map(function (test) {
|
|
29199
|
-
return test(_value, idx);
|
|
29200
|
-
}).getOrElse(_value);
|
|
29201
|
-
|
|
29202
|
-
case 'boolean':
|
|
29203
|
-
return visible;
|
|
29204
|
-
|
|
29205
|
-
default:
|
|
29206
|
-
return true;
|
|
29207
|
-
}
|
|
29208
|
-
}).getOrElse(true);
|
|
29209
|
-
|
|
29210
|
-
if (!visibleStep) {
|
|
29211
|
-
return null;
|
|
29212
|
-
}
|
|
29213
|
-
|
|
29214
|
-
return /*#__PURE__*/React__default["default"].createElement(BasicWrapper, {
|
|
29215
|
-
key: "".concat(entry, "-").concat(idx),
|
|
29216
|
-
entry: entry,
|
|
29217
|
-
dirtyFields: dirtyFields,
|
|
29218
|
-
label: functionalProperty(entry, (step === null || step === void 0 ? void 0 : step.label) === null ? null : (step === null || step === void 0 ? void 0 : step.label) || entry),
|
|
29219
|
-
help: step === null || step === void 0 ? void 0 : step.help,
|
|
29220
|
-
render: inputWrapper
|
|
29221
|
-
}, /*#__PURE__*/React__default["default"].createElement(Step, {
|
|
29222
|
-
key: idx,
|
|
29223
|
-
entry: entry,
|
|
29224
|
-
step: step,
|
|
29225
|
-
schema: schema,
|
|
29226
|
-
inputWrapper: inputWrapper,
|
|
29227
|
-
httpClient: maybeCustomHttpClient,
|
|
29228
|
-
functionalProperty: functionalProperty
|
|
28215
|
+
React.useImperativeHandle(ref, () => ({
|
|
28216
|
+
handleSubmit: () => handleSubmit(data => {
|
|
28217
|
+
const clean = cleanOutputArray(data, schema);
|
|
28218
|
+
onSubmit(clean);
|
|
28219
|
+
}, onError)(),
|
|
28220
|
+
trigger,
|
|
28221
|
+
methods: Object.assign(Object.assign({}, methods), { data: () => cleanOutputArray(getValues(), schema) })
|
|
29229
28222
|
}));
|
|
29230
|
-
|
|
29231
|
-
|
|
29232
|
-
|
|
29233
|
-
|
|
29234
|
-
|
|
29235
|
-
|
|
29236
|
-
|
|
29237
|
-
|
|
29238
|
-
|
|
29239
|
-
|
|
28223
|
+
return (React__default["default"].createElement(reactHookForm.FormProvider, Object.assign({}, methods),
|
|
28224
|
+
React__default["default"].createElement(Watcher, { options: options, control: methods.control, schema: schema, onSubmit: onSubmit, handleSubmit: handleSubmit }),
|
|
28225
|
+
React__default["default"].createElement("form", { className: className || `mrf-pr_15 mrf-w_100`, onSubmit: handleSubmit(data => {
|
|
28226
|
+
const clean = cleanOutputArray(data, schema);
|
|
28227
|
+
onSubmit(clean);
|
|
28228
|
+
}, onError) },
|
|
28229
|
+
formFlow.map((entry, idx) => {
|
|
28230
|
+
const step = typeof entry === "object" ? undefined : schema[entry];
|
|
28231
|
+
if (!step && typeof entry === 'string') {
|
|
28232
|
+
console.error(`no step found for the entry "${entry}" in the given schema. Your form might not work properly. Please fix it`);
|
|
28233
|
+
return null;
|
|
28234
|
+
}
|
|
28235
|
+
return (React__default["default"].createElement(BasicWrapper, { key: `${entry}-${idx}`, entry: entry, functionalProperty: functionalProperty, render: inputWrapper, step: step },
|
|
28236
|
+
React__default["default"].createElement(Step, { key: idx, entry: entry, step: step, schema: schema, inputWrapper: inputWrapper, httpClient: maybeCustomHttpClient, functionalProperty: functionalProperty })));
|
|
28237
|
+
}),
|
|
28238
|
+
React__default["default"].createElement(Footer, { render: footer, reset: () => reset(defaultValues), valid: handleSubmit(data => onSubmit(cleanOutputArray(data, schema)), onError), actions: options.actions }))));
|
|
29240
28239
|
});
|
|
29241
|
-
|
|
29242
|
-
var
|
|
29243
|
-
|
|
29244
|
-
|
|
29245
|
-
|
|
29246
|
-
|
|
29247
|
-
|
|
29248
|
-
|
|
29249
|
-
|
|
29250
|
-
|
|
29251
|
-
|
|
29252
|
-
var isSubmitDisplayed = ((_props$actions = props.actions) === null || _props$actions === void 0 ? void 0 : (_props$actions$submit = _props$actions.submit) === null || _props$actions$submit === void 0 ? void 0 : _props$actions$submit.display) === undefined ? true : !!((_props$actions2 = props.actions) !== null && _props$actions2 !== void 0 && (_props$actions2$submi = _props$actions2.submit) !== null && _props$actions2$submi !== void 0 && _props$actions2$submi.display);
|
|
29253
|
-
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
29254
|
-
className: "mrf-flex mrf-jc_end mrf-mt_5"
|
|
29255
|
-
}, ((_props$actions3 = props.actions) === null || _props$actions3 === void 0 ? void 0 : (_props$actions3$cance = _props$actions3.cancel) === null || _props$actions3$cance === void 0 ? void 0 : _props$actions3$cance.display) && /*#__PURE__*/React__default["default"].createElement("button", {
|
|
29256
|
-
className: "mrf-btn mrf-btn_red",
|
|
29257
|
-
type: "button",
|
|
29258
|
-
onClick: function onClick() {
|
|
29259
|
-
var _props$actions4;
|
|
29260
|
-
|
|
29261
|
-
return (_props$actions4 = props.actions) === null || _props$actions4 === void 0 ? void 0 : _props$actions4.cancel.action();
|
|
29262
|
-
}
|
|
29263
|
-
}, ((_props$actions5 = props.actions) === null || _props$actions5 === void 0 ? void 0 : (_props$actions5$cance = _props$actions5.cancel) === null || _props$actions5$cance === void 0 ? void 0 : _props$actions5$cance.label) || 'Cancel'), ((_props$actions6 = props.actions) === null || _props$actions6 === void 0 ? void 0 : (_props$actions6$reset = _props$actions6.reset) === null || _props$actions6$reset === void 0 ? void 0 : _props$actions6$reset.display) && /*#__PURE__*/React__default["default"].createElement("button", {
|
|
29264
|
-
className: "mrf-btn mrf-btn_red",
|
|
29265
|
-
type: "button",
|
|
29266
|
-
onClick: props.reset
|
|
29267
|
-
}, ((_props$actions7 = props.actions) === null || _props$actions7 === void 0 ? void 0 : (_props$actions7$reset = _props$actions7.reset) === null || _props$actions7$reset === void 0 ? void 0 : _props$actions7$reset.label) || 'Reset'), isSubmitDisplayed && /*#__PURE__*/React__default["default"].createElement("button", {
|
|
29268
|
-
className: "mrf-btn mrf-btn_green mrf-ml_10",
|
|
29269
|
-
type: "submit"
|
|
29270
|
-
}, ((_props$actions8 = props.actions) === null || _props$actions8 === void 0 ? void 0 : (_props$actions8$submi = _props$actions8.submit) === null || _props$actions8$submi === void 0 ? void 0 : _props$actions8$submi.label) || 'Save'));
|
|
28240
|
+
const Footer = (props) => {
|
|
28241
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
28242
|
+
if (props.render) {
|
|
28243
|
+
return props.render({ reset: props.reset, valid: props.valid });
|
|
28244
|
+
}
|
|
28245
|
+
const isSubmitDisplayed = ((_b = (_a = props.actions) === null || _a === void 0 ? void 0 : _a.submit) === null || _b === void 0 ? void 0 : _b.display) === undefined ? true : !!((_d = (_c = props.actions) === null || _c === void 0 ? void 0 : _c.submit) === null || _d === void 0 ? void 0 : _d.display);
|
|
28246
|
+
return (React__default["default"].createElement("div", { className: 'mrf-flex mrf-jc_end mrf-mt_5' },
|
|
28247
|
+
((_f = (_e = props.actions) === null || _e === void 0 ? void 0 : _e.cancel) === null || _f === void 0 ? void 0 : _f.display) && React__default["default"].createElement("button", { className: 'mrf-btn mrf-btn_red', type: "button", onClick: () => { var _a, _b; return (_b = (_a = props.actions) === null || _a === void 0 ? void 0 : _a.cancel) === null || _b === void 0 ? void 0 : _b.action(); } }, ((_h = (_g = props.actions) === null || _g === void 0 ? void 0 : _g.cancel) === null || _h === void 0 ? void 0 : _h.label) || 'Cancel'),
|
|
28248
|
+
((_k = (_j = props.actions) === null || _j === void 0 ? void 0 : _j.reset) === null || _k === void 0 ? void 0 : _k.display) && React__default["default"].createElement("button", { className: 'mrf-btn mrf-btn_red', type: "button", onClick: props.reset }, ((_m = (_l = props.actions) === null || _l === void 0 ? void 0 : _l.reset) === null || _m === void 0 ? void 0 : _m.label) || 'Reset'),
|
|
28249
|
+
isSubmitDisplayed && React__default["default"].createElement("button", { className: 'mrf-btn mrf-btn_green mrf-ml_10', type: "submit" }, ((_p = (_o = props.actions) === null || _o === void 0 ? void 0 : _o.submit) === null || _p === void 0 ? void 0 : _p.label) || 'Save')));
|
|
29271
28250
|
};
|
|
29272
|
-
|
|
29273
|
-
|
|
29274
|
-
|
|
29275
|
-
|
|
29276
|
-
|
|
29277
|
-
|
|
29278
|
-
|
|
29279
|
-
|
|
29280
|
-
|
|
29281
|
-
|
|
29282
|
-
functionalProperty = _ref8.functionalProperty,
|
|
29283
|
-
parent = _ref8.parent,
|
|
29284
|
-
onAfterChange = _ref8.onAfterChange;
|
|
29285
|
-
|
|
29286
|
-
var _useFormContext2 = reactHookForm.useFormContext(),
|
|
29287
|
-
_useFormContext2$form = _useFormContext2.formState,
|
|
29288
|
-
errors = _useFormContext2$form.errors,
|
|
29289
|
-
dirtyFields = _useFormContext2$form.dirtyFields,
|
|
29290
|
-
touchedFields = _useFormContext2$form.touchedFields,
|
|
29291
|
-
isSubmitted = _useFormContext2$form.isSubmitted,
|
|
29292
|
-
control = _useFormContext2.control;
|
|
29293
|
-
_useFormContext2.trigger;
|
|
29294
|
-
var getValues = _useFormContext2.getValues,
|
|
29295
|
-
_setValue = _useFormContext2.setValue,
|
|
29296
|
-
watch = _useFormContext2.watch;
|
|
29297
|
-
_useFormContext2.register;
|
|
29298
|
-
|
|
29299
|
-
if (entry && _typeof$1(entry) === 'object') {
|
|
29300
|
-
var errored = entry.flow.some(function (step) {
|
|
29301
|
-
return !!errors[step] && (dirtyFields[step] || touchedFields[step]);
|
|
29302
|
-
});
|
|
29303
|
-
return /*#__PURE__*/React__default["default"].createElement(Collapse, _extends({}, entry, {
|
|
29304
|
-
errored: errored
|
|
29305
|
-
}), entry.flow.map(function (en, entryIdx) {
|
|
29306
|
-
var stp = schema[en];
|
|
29307
|
-
_typeof$1(en) === 'object' ? undefined : en.split('.').reduce(function (object, key) {
|
|
29308
|
-
return object && object[key];
|
|
29309
|
-
}, errors);
|
|
29310
|
-
|
|
29311
|
-
if (!stp && typeof en === 'string') {
|
|
29312
|
-
console.error("no step found for the entry \"".concat(en, "\" in the given schema. Your form might not work properly. Please fix it"));
|
|
29313
|
-
return null;
|
|
29314
|
-
}
|
|
29315
|
-
|
|
29316
|
-
var visibleStep = option(stp).map(function (s) {
|
|
29317
|
-
return s.visible;
|
|
29318
|
-
}).map(function (visible) {
|
|
29319
|
-
switch (_typeof$1(visible)) {
|
|
29320
|
-
case 'object':
|
|
29321
|
-
var value = watch(visible.ref);
|
|
29322
|
-
return option(visible.test).map(function (test) {
|
|
29323
|
-
return test(value, index);
|
|
29324
|
-
}).getOrElse(value);
|
|
29325
|
-
|
|
29326
|
-
case 'boolean':
|
|
29327
|
-
return visible;
|
|
29328
|
-
|
|
29329
|
-
default:
|
|
29330
|
-
return true;
|
|
29331
|
-
}
|
|
29332
|
-
}).getOrElse(true);
|
|
29333
|
-
|
|
29334
|
-
if (!visibleStep) {
|
|
29335
|
-
return null;
|
|
29336
|
-
}
|
|
29337
|
-
|
|
29338
|
-
return /*#__PURE__*/React__default["default"].createElement(BasicWrapper, {
|
|
29339
|
-
key: "collapse-".concat(en, "-").concat(entryIdx),
|
|
29340
|
-
entry: en,
|
|
29341
|
-
label: functionalProperty(en, (stp === null || stp === void 0 ? void 0 : stp.label) === null ? null : (stp === null || stp === void 0 ? void 0 : stp.label) || en),
|
|
29342
|
-
help: stp === null || stp === void 0 ? void 0 : stp.help,
|
|
29343
|
-
render: inputWrapper
|
|
29344
|
-
}, /*#__PURE__*/React__default["default"].createElement(Step, {
|
|
29345
|
-
entry: en,
|
|
29346
|
-
step: stp,
|
|
29347
|
-
schema: schema,
|
|
29348
|
-
inputWrapper: inputWrapper,
|
|
29349
|
-
httpClient: httpClient,
|
|
29350
|
-
defaultValue: stp === null || stp === void 0 ? void 0 : stp.defaultValue,
|
|
29351
|
-
functionalProperty: functionalProperty
|
|
29352
|
-
}));
|
|
29353
|
-
}));
|
|
29354
|
-
}
|
|
29355
|
-
|
|
29356
|
-
var error = entry.split('.').reduce(function (acc, curr) {
|
|
29357
|
-
return acc && acc[curr];
|
|
29358
|
-
}, errors);
|
|
29359
|
-
var isDirty = entry.split('.').reduce(function (acc, curr) {
|
|
29360
|
-
return acc && acc[curr];
|
|
29361
|
-
}, dirtyFields);
|
|
29362
|
-
var isTouched = entry.split('.').reduce(function (acc, curr) {
|
|
29363
|
-
return acc && acc[curr];
|
|
29364
|
-
}, touchedFields);
|
|
29365
|
-
var errorDisplayed = !!error && (isSubmitted || isDirty || isTouched);
|
|
29366
|
-
var onAfterChangeFunc = onAfterChange || step.onAfterChange || step.on_after_change;
|
|
29367
|
-
|
|
29368
|
-
if (onAfterChangeFunc) {
|
|
29369
|
-
var data = watch();
|
|
29370
|
-
var d = entry.replace('[', '.').replace(']', '').split('.').reduce(function (acc, curr) {
|
|
29371
|
-
return acc && acc[curr];
|
|
29372
|
-
}, data) || {};
|
|
29373
|
-
var currentData = usePrevious(cleanOutputArray(d, schema));
|
|
29374
|
-
var newData = cleanOutputArray(d, schema);
|
|
29375
|
-
if (!deepEqual__default["default"](newData, currentData) || newData !== undefined && currentData === undefined) onAfterChangeFunc({
|
|
29376
|
-
entry: entry,
|
|
29377
|
-
value: getValues(entry),
|
|
29378
|
-
rawValues: newData,
|
|
29379
|
-
previousValue: currentData,
|
|
29380
|
-
getValue: function getValue(e) {
|
|
29381
|
-
return getValues(e);
|
|
29382
|
-
},
|
|
29383
|
-
setValue: _setValue,
|
|
29384
|
-
onChange: function onChange(v) {
|
|
29385
|
-
return _setValue(entry, v);
|
|
29386
|
-
}
|
|
29387
|
-
});
|
|
29388
|
-
}
|
|
29389
|
-
|
|
29390
|
-
if (step.array) {
|
|
29391
|
-
return /*#__PURE__*/React__default["default"].createElement(CustomizableInput, {
|
|
29392
|
-
render: step.render,
|
|
29393
|
-
field: {
|
|
29394
|
-
setValue: function setValue(key, value) {
|
|
29395
|
-
return _setValue(key, value);
|
|
29396
|
-
},
|
|
29397
|
-
rawValues: getValues(),
|
|
29398
|
-
value: getValues(entry),
|
|
29399
|
-
onChange: function onChange(v) {
|
|
29400
|
-
return _setValue(entry, v);
|
|
29401
|
-
}
|
|
29402
|
-
},
|
|
29403
|
-
error: error
|
|
29404
|
-
}, /*#__PURE__*/React__default["default"].createElement(ArrayStep, {
|
|
29405
|
-
entry: entry,
|
|
29406
|
-
step: step,
|
|
29407
|
-
disabled: functionalProperty(entry, step.disabled),
|
|
29408
|
-
component: function component(props, idx) {
|
|
29409
|
-
var _props$defaultValue;
|
|
29410
|
-
|
|
29411
|
-
return /*#__PURE__*/React__default["default"].createElement(Step, {
|
|
29412
|
-
entry: "".concat(entry, ".").concat(idx, ".value"),
|
|
29413
|
-
onAfterChange: step.onAfterChange || step.on_after_change,
|
|
29414
|
-
step: _objectSpread2$1(_objectSpread2$1({}, schema[realEntry || entry]), {}, {
|
|
29415
|
-
render: step.itemRender,
|
|
29416
|
-
onChange: undefined,
|
|
29417
|
-
array: false
|
|
29418
|
-
}),
|
|
29419
|
-
schema: schema,
|
|
29420
|
-
inputWrapper: inputWrapper,
|
|
29421
|
-
httpClient: httpClient,
|
|
29422
|
-
defaultValue: (_props$defaultValue = props.defaultValue) === null || _props$defaultValue === void 0 ? void 0 : _props$defaultValue.value,
|
|
29423
|
-
value: props.value,
|
|
29424
|
-
index: idx,
|
|
29425
|
-
functionalProperty: functionalProperty
|
|
29426
|
-
});
|
|
29427
|
-
}
|
|
29428
|
-
}));
|
|
29429
|
-
}
|
|
29430
|
-
|
|
29431
|
-
switch (step.type) {
|
|
29432
|
-
case type.string:
|
|
29433
|
-
switch (step.format) {
|
|
29434
|
-
case format.text:
|
|
29435
|
-
return /*#__PURE__*/React__default["default"].createElement(ControlledInput, {
|
|
29436
|
-
defaultValue: defaultValue,
|
|
29437
|
-
step: step,
|
|
29438
|
-
entry: entry,
|
|
29439
|
-
errorDisplayed: errorDisplayed
|
|
29440
|
-
}, /*#__PURE__*/React__default["default"].createElement("textarea", {
|
|
29441
|
-
type: "text",
|
|
29442
|
-
className: classNames__default["default"]('mrf-input', step.className, _defineProperty$1({}, 'mrf-mrf-input__invalid', errorDisplayed))
|
|
29443
|
-
}));
|
|
29444
|
-
|
|
29445
|
-
case format.code:
|
|
29446
|
-
case format.singleLineCode:
|
|
29447
|
-
var Component = step.format === format.code ? CodeInput : SingleLineCode;
|
|
29448
|
-
return /*#__PURE__*/React__default["default"].createElement(ControlledInput, {
|
|
29449
|
-
defaultValue: defaultValue,
|
|
29450
|
-
step: step,
|
|
29451
|
-
entry: entry,
|
|
29452
|
-
errorDisplayed: errorDisplayed
|
|
29453
|
-
}, /*#__PURE__*/React__default["default"].createElement(Component, {
|
|
29454
|
-
className: classNames__default["default"](step.className, _defineProperty$1({}, 'mrf-input__invalid', errorDisplayed))
|
|
29455
|
-
}));
|
|
29456
|
-
|
|
29457
|
-
case format.markdown:
|
|
29458
|
-
return /*#__PURE__*/React__default["default"].createElement(ControlledInput, {
|
|
29459
|
-
defaultValue: defaultValue,
|
|
29460
|
-
step: step,
|
|
29461
|
-
entry: entry,
|
|
29462
|
-
errorDisplayed: errorDisplayed
|
|
29463
|
-
}, /*#__PURE__*/React__default["default"].createElement(MarkdownInput, {
|
|
29464
|
-
className: classNames__default["default"](step.className, _defineProperty$1({}, 'mrf-input__invalid', errorDisplayed))
|
|
29465
|
-
}));
|
|
29466
|
-
|
|
29467
|
-
case format.buttonsSelect:
|
|
29468
|
-
case format.select:
|
|
29469
|
-
{
|
|
29470
|
-
return /*#__PURE__*/React__default["default"].createElement(ControlledInput, {
|
|
29471
|
-
defaultValue: defaultValue,
|
|
29472
|
-
step: step,
|
|
29473
|
-
entry: entry,
|
|
29474
|
-
errorDisplayed: errorDisplayed
|
|
29475
|
-
}, /*#__PURE__*/React__default["default"].createElement(SelectInput, _extends({
|
|
29476
|
-
className: classNames__default["default"]('mrf-flex_grow_1', step.className, _defineProperty$1({}, 'mrf-input__invalid', errorDisplayed)),
|
|
29477
|
-
disabled: functionalProperty(entry, step.disabled)
|
|
29478
|
-
}, step.props, {
|
|
29479
|
-
possibleValues: step.options,
|
|
29480
|
-
httpClient: httpClient,
|
|
29481
|
-
isMulti: step.isMulti,
|
|
29482
|
-
createOption: step.createOption,
|
|
29483
|
-
transformer: step.transformer,
|
|
29484
|
-
buttons: step.format === format.buttonsSelect,
|
|
29485
|
-
optionsFrom: step.optionsFrom
|
|
29486
|
-
})));
|
|
29487
|
-
}
|
|
29488
|
-
|
|
29489
|
-
default:
|
|
29490
|
-
return /*#__PURE__*/React__default["default"].createElement(ControlledInput, {
|
|
29491
|
-
defaultValue: defaultValue,
|
|
29492
|
-
step: step,
|
|
29493
|
-
entry: entry,
|
|
29494
|
-
errorDisplayed: errorDisplayed
|
|
29495
|
-
}, /*#__PURE__*/React__default["default"].createElement("input", {
|
|
29496
|
-
type: step.format || 'text',
|
|
29497
|
-
className: classNames__default["default"]('mrf-input', step.className, _defineProperty$1({}, 'mrf-input__invalid', errorDisplayed))
|
|
29498
|
-
}));
|
|
29499
|
-
}
|
|
29500
|
-
|
|
29501
|
-
case type.number:
|
|
29502
|
-
switch (step.format) {
|
|
29503
|
-
case format.buttonsSelect:
|
|
29504
|
-
case format.select:
|
|
29505
|
-
return /*#__PURE__*/React__default["default"].createElement(ControlledInput, {
|
|
29506
|
-
defaultValue: defaultValue,
|
|
29507
|
-
step: step,
|
|
29508
|
-
entry: entry,
|
|
29509
|
-
errorDisplayed: errorDisplayed
|
|
29510
|
-
}, /*#__PURE__*/React__default["default"].createElement(SelectInput, _extends({
|
|
29511
|
-
className: classNames__default["default"]('mrf-content', step.className, _defineProperty$1({}, 'mrf-input__invalid', errorDisplayed))
|
|
29512
|
-
}, step.props, {
|
|
29513
|
-
possibleValues: step.options,
|
|
29514
|
-
httpClient: httpClient,
|
|
29515
|
-
isMulti: step.isMulti,
|
|
29516
|
-
createOption: step.createOption,
|
|
29517
|
-
onCreateOption: step.onCreateOption,
|
|
29518
|
-
transformer: step.transformer,
|
|
29519
|
-
buttons: step.format === format.buttonsSelect,
|
|
29520
|
-
optionsFrom: step.optionsFrom
|
|
29521
|
-
})));
|
|
29522
|
-
|
|
29523
|
-
default:
|
|
29524
|
-
return /*#__PURE__*/React__default["default"].createElement(ControlledInput, {
|
|
29525
|
-
defaultValue: defaultValue,
|
|
29526
|
-
step: step,
|
|
29527
|
-
entry: entry,
|
|
29528
|
-
errorDisplayed: errorDisplayed
|
|
29529
|
-
}, /*#__PURE__*/React__default["default"].createElement("input", {
|
|
29530
|
-
type: step.format || 'number',
|
|
29531
|
-
className: classNames__default["default"]('mrf-input', step.className, _defineProperty$1({}, 'mrf-input__invalid', errorDisplayed))
|
|
29532
|
-
}));
|
|
29533
|
-
}
|
|
29534
|
-
|
|
29535
|
-
case type.bool:
|
|
29536
|
-
return /*#__PURE__*/React__default["default"].createElement(ControlledInput, {
|
|
29537
|
-
step: step,
|
|
29538
|
-
entry: entry,
|
|
29539
|
-
errorDisplayed: errorDisplayed
|
|
29540
|
-
}, /*#__PURE__*/React__default["default"].createElement(BooleanInput, {
|
|
29541
|
-
className: classNames__default["default"](step.className, _defineProperty$1({}, 'mrf-input__invalid', errorDisplayed))
|
|
29542
|
-
}));
|
|
29543
|
-
|
|
29544
|
-
case type.object:
|
|
29545
|
-
switch (step.format) {
|
|
29546
|
-
case format.buttonsSelect:
|
|
29547
|
-
case format.select:
|
|
29548
|
-
return /*#__PURE__*/React__default["default"].createElement(ControlledInput, {
|
|
29549
|
-
defaultValue: defaultValue,
|
|
29550
|
-
step: step,
|
|
29551
|
-
entry: entry,
|
|
29552
|
-
errorDisplayed: errorDisplayed
|
|
29553
|
-
}, /*#__PURE__*/React__default["default"].createElement(SelectInput, _extends({
|
|
29554
|
-
className: classNames__default["default"]('mrf-flex_grow_1', step.className, _defineProperty$1({}, 'mrf-input__invalid', errorDisplayed))
|
|
29555
|
-
}, step.props, {
|
|
29556
|
-
possibleValues: step.options,
|
|
29557
|
-
httpClient: httpClient,
|
|
29558
|
-
isMulti: step.isMulti,
|
|
29559
|
-
createOption: step.createOption,
|
|
29560
|
-
onCreateOption: step.onCreateOption,
|
|
29561
|
-
transformer: step.transformer,
|
|
29562
|
-
buttons: step.format === format.buttonsSelect,
|
|
29563
|
-
optionsFrom: step.optionsFrom
|
|
29564
|
-
})));
|
|
29565
|
-
|
|
29566
|
-
case format.form:
|
|
29567
|
-
//todo: disabled ?
|
|
29568
|
-
var flow = option(step.flow).getOrElse(option(step.schema).map(function (s) {
|
|
29569
|
-
return Object.keys(s);
|
|
29570
|
-
}).getOrNull());
|
|
29571
|
-
return /*#__PURE__*/React__default["default"].createElement(CustomizableInput, {
|
|
29572
|
-
render: step.render,
|
|
29573
|
-
field: {
|
|
29574
|
-
parent: parent,
|
|
29575
|
-
setValue: function setValue(key, value) {
|
|
29576
|
-
return _setValue(key, value);
|
|
29577
|
-
},
|
|
29578
|
-
rawValues: getValues(),
|
|
29579
|
-
value: getValues(entry),
|
|
29580
|
-
onChange: function onChange(v) {
|
|
29581
|
-
return _setValue(entry, v, {
|
|
29582
|
-
shouldValidate: true
|
|
29583
|
-
});
|
|
29584
|
-
}
|
|
29585
|
-
}
|
|
29586
|
-
}, /*#__PURE__*/React__default["default"].createElement(NestedForm, {
|
|
29587
|
-
schema: step.schema,
|
|
29588
|
-
flow: flow,
|
|
29589
|
-
step: step,
|
|
29590
|
-
parent: entry,
|
|
29591
|
-
inputWrapper: inputWrapper,
|
|
29592
|
-
maybeCustomHttpClient: httpClient,
|
|
29593
|
-
value: getValues(entry) || defaultValue,
|
|
29594
|
-
index: index,
|
|
29595
|
-
functionalProperty: functionalProperty,
|
|
29596
|
-
errorDisplayed: errorDisplayed
|
|
29597
|
-
}));
|
|
29598
|
-
|
|
29599
|
-
case format.code:
|
|
29600
|
-
return /*#__PURE__*/React__default["default"].createElement(ControlledInput, {
|
|
29601
|
-
defaultValue: defaultValue,
|
|
29602
|
-
step: step,
|
|
29603
|
-
entry: entry,
|
|
29604
|
-
errorDisplayed: errorDisplayed,
|
|
29605
|
-
component: function component(field, props) {
|
|
29606
|
-
return /*#__PURE__*/React__default["default"].createElement(CodeInput, _extends({}, props, {
|
|
29607
|
-
className: classNames__default["default"](step.className, _defineProperty$1({}, 'mrf-input__invalid', error)),
|
|
29608
|
-
onChange: function onChange(e) {
|
|
29609
|
-
_readOnlyError("errorDisplayed");
|
|
29610
|
-
var v;
|
|
29611
|
-
|
|
29612
|
-
try {
|
|
29613
|
-
v = JSON.parse(e);
|
|
29614
|
-
} catch (err) {
|
|
29615
|
-
v = e;
|
|
29616
|
-
}
|
|
29617
|
-
|
|
29618
|
-
field.onChange(v);
|
|
29619
|
-
option(step.onChange).map(function (onChange) {
|
|
29620
|
-
return onChange({
|
|
29621
|
-
rawValues: getValues(),
|
|
29622
|
-
value: v,
|
|
29623
|
-
setValue: _setValue
|
|
29624
|
-
});
|
|
29625
|
-
});
|
|
29626
|
-
},
|
|
29627
|
-
value: field.value === null ? null : _typeof$1(field.value) === 'object' ? JSON.stringify(field.value, null, 2) : field.value
|
|
29628
|
-
}));
|
|
28251
|
+
const Step = (props) => {
|
|
28252
|
+
let { entry, realEntry, step, schema, inputWrapper, httpClient, defaultValue, index, functionalProperty, parent, parentInformations } = props;
|
|
28253
|
+
const { formState: { errors, dirtyFields, touchedFields, isSubmitted }, control, getValues, setValue, watch } = reactHookForm.useFormContext();
|
|
28254
|
+
if (entry && typeof entry === 'object') {
|
|
28255
|
+
const errored = extractFlowString(entry).some(step => !!errors[step] && (dirtyFields[step] || touchedFields[step]));
|
|
28256
|
+
return (React__default["default"].createElement(Collapse, Object.assign({}, entry, { errored: errored }), entry.flow.map((en, entryIdx) => {
|
|
28257
|
+
const stp = typeof en === "object" ? undefined : schema[en]; // TODO Factorise this logic
|
|
28258
|
+
if (!stp && typeof en === 'string') {
|
|
28259
|
+
console.error(`no step found for the entry "${en}" in the given schema. Your form might not work properly. Please fix it`);
|
|
28260
|
+
return null;
|
|
29629
28261
|
}
|
|
29630
|
-
|
|
29631
|
-
|
|
28262
|
+
return (React__default["default"].createElement(BasicWrapper, { key: `collapse-${en}-${entryIdx}`, entry: en, functionalProperty: functionalProperty, step: stp, render: inputWrapper },
|
|
28263
|
+
React__default["default"].createElement(Step, { entry: en, step: stp, schema: schema, inputWrapper: inputWrapper, httpClient: httpClient, defaultValue: stp === null || stp === void 0 ? void 0 : stp.defaultValue, functionalProperty: functionalProperty, parentInformations: parentInformations })));
|
|
28264
|
+
})));
|
|
28265
|
+
}
|
|
28266
|
+
const error = entry.split('.').reduce((acc, curr) => acc && acc[curr], errors);
|
|
28267
|
+
const isDirty = entry.split('.').reduce((acc, curr) => acc && acc[curr], dirtyFields);
|
|
28268
|
+
const isTouched = entry.split('.').reduce((acc, curr) => acc && acc[curr], touchedFields);
|
|
28269
|
+
const errorDisplayed = (!!error && (isSubmitted || isDirty || isTouched));
|
|
28270
|
+
const informations = { path: entry, parent: parentInformations, index };
|
|
28271
|
+
step = step;
|
|
28272
|
+
if (step.onAfterChange) {
|
|
28273
|
+
const data = watch();
|
|
28274
|
+
const d = entry
|
|
28275
|
+
.replace('[', '.').replace(']', '')
|
|
28276
|
+
.split('.')
|
|
28277
|
+
.reduce((acc, curr) => acc && acc[curr], data) || {};
|
|
28278
|
+
const currentData = usePrevious(cleanOutputArray(d, schema));
|
|
28279
|
+
const newData = cleanOutputArray(d, schema);
|
|
28280
|
+
if (!deepEqual__default["default"](newData, currentData) || (newData !== undefined && currentData === undefined))
|
|
28281
|
+
step.onAfterChange({
|
|
28282
|
+
entry,
|
|
28283
|
+
value: getValues(entry),
|
|
28284
|
+
rawValues: getValues(),
|
|
28285
|
+
previousValue: currentData,
|
|
28286
|
+
getValue: (e) => getValues(e),
|
|
28287
|
+
setValue,
|
|
28288
|
+
onChange: (v) => setValue(entry, v),
|
|
28289
|
+
informations
|
|
28290
|
+
});
|
|
28291
|
+
}
|
|
28292
|
+
if (step.array) {
|
|
28293
|
+
return (React__default["default"].createElement(CustomizableInput, { render: step.render, field: {
|
|
28294
|
+
setValue: (key, value) => setValue(key, value), rawValues: getValues(), value: getValues(entry), onChange: (v) => setValue(entry, v)
|
|
28295
|
+
}, error: !!error },
|
|
28296
|
+
React__default["default"].createElement(ArrayStep, { entry: entry, step: step, disabled: functionalProperty(entry, step.disabled || false), component: ((props, idx) => {
|
|
28297
|
+
var _a;
|
|
28298
|
+
return (React__default["default"].createElement(Step, { entry: `${entry}.${idx}.value`, step: Object.assign(Object.assign({}, (schema[realEntry || entry])), { render: step.itemRender, onChange: undefined, array: false, onAfterChange: step.onAfterChange }), schema: schema, inputWrapper: inputWrapper, httpClient: httpClient, defaultValue: (_a = props.defaultValue) === null || _a === void 0 ? void 0 : _a.value, index: idx, functionalProperty: functionalProperty, parentInformations: informations }));
|
|
28299
|
+
}) })));
|
|
28300
|
+
}
|
|
28301
|
+
switch (step.type) {
|
|
28302
|
+
case type.string:
|
|
28303
|
+
switch (step.format) {
|
|
28304
|
+
case format.text:
|
|
28305
|
+
return (React__default["default"].createElement(ControlledInput, { step: step, entry: entry, errorDisplayed: errorDisplayed },
|
|
28306
|
+
React__default["default"].createElement("textarea", { className: classNames__default["default"]('mrf-input', step.className, { 'mrf-mrf-input__invalid': !!errorDisplayed }) })));
|
|
28307
|
+
case format.code:
|
|
28308
|
+
case format.singleLineCode:
|
|
28309
|
+
const Component = step.format === format.code ? CodeInput : SingleLineCode;
|
|
28310
|
+
return (React__default["default"].createElement(ControlledInput, { step: step, entry: entry, errorDisplayed: errorDisplayed },
|
|
28311
|
+
React__default["default"].createElement(Component /*TODO try to pass className down OR use built in mechanism to display error classNames(step.className, { 'mrf-input__invalid': !!errorDisplayed })}*/, null)));
|
|
28312
|
+
case format.markdown:
|
|
28313
|
+
return (React__default["default"].createElement(ControlledInput, { step: step, entry: entry, errorDisplayed: errorDisplayed },
|
|
28314
|
+
React__default["default"].createElement(MarkdownInput, { className: classNames__default["default"](step.className, { 'mrf-input__invalid': !!errorDisplayed }) })));
|
|
28315
|
+
case format.buttonsSelect:
|
|
28316
|
+
case format.select: {
|
|
28317
|
+
return (React__default["default"].createElement(ControlledInput, { step: step, entry: entry, errorDisplayed: errorDisplayed },
|
|
28318
|
+
React__default["default"].createElement(SelectInput, Object.assign({ className: classNames__default["default"]('mrf-flex_grow_1', step.className, { 'mrf-input__invalid': !!errorDisplayed }), disabled: functionalProperty(entry, step.disabled || false) }, step.props, { possibleValues: step.options, httpClient: httpClient, isMulti: step.isMulti, createOption: step.createOption, onCreateOption: step.onCreateOption, transformer: step.transformer, buttons: step.format === format.buttonsSelect, optionsFrom: step.optionsFrom }))));
|
|
28319
|
+
}
|
|
28320
|
+
default:
|
|
28321
|
+
return (React__default["default"].createElement(ControlledInput, { step: step, entry: entry, errorDisplayed: errorDisplayed },
|
|
28322
|
+
React__default["default"].createElement("input", { type: step.format || 'text', className: classNames__default["default"]('mrf-input', step.className, { 'mrf-input__invalid': !!errorDisplayed }) })));
|
|
28323
|
+
}
|
|
28324
|
+
case type.number:
|
|
28325
|
+
switch (step.format) {
|
|
28326
|
+
case format.buttonsSelect:
|
|
28327
|
+
case format.select:
|
|
28328
|
+
return (React__default["default"].createElement(ControlledInput, { step: step, entry: entry, errorDisplayed: errorDisplayed },
|
|
28329
|
+
React__default["default"].createElement(SelectInput, Object.assign({ className: classNames__default["default"]('mrf-content', step.className, { 'mrf-input__invalid': !!errorDisplayed }) }, step.props, { possibleValues: step.options, httpClient: httpClient, isMulti: step.isMulti, createOption: step.createOption, onCreateOption: step.onCreateOption, transformer: step.transformer, buttons: step.format === format.buttonsSelect, optionsFrom: step.optionsFrom }))));
|
|
28330
|
+
default:
|
|
28331
|
+
return React__default["default"].createElement(ControlledInput, { step: step, entry: entry, errorDisplayed: errorDisplayed },
|
|
28332
|
+
React__default["default"].createElement("input", { type: step.format || 'number', className: classNames__default["default"]('mrf-input', step.className, { 'mrf-input__invalid': !!errorDisplayed }) }));
|
|
28333
|
+
}
|
|
28334
|
+
case type.bool:
|
|
28335
|
+
return (React__default["default"].createElement(ControlledInput, { step: step, entry: entry, errorDisplayed: errorDisplayed },
|
|
28336
|
+
React__default["default"].createElement(BooleanInput /* TODO see how to pass error down className={classNames(step.className, { 'mrf-input__invalid': !!errorDisplayed })}*/, null)));
|
|
28337
|
+
case type.object:
|
|
28338
|
+
switch (step.format) {
|
|
28339
|
+
case format.buttonsSelect:
|
|
28340
|
+
case format.select:
|
|
28341
|
+
return (React__default["default"].createElement(ControlledInput, { step: step, entry: entry, errorDisplayed: errorDisplayed },
|
|
28342
|
+
React__default["default"].createElement(SelectInput, Object.assign({ className: classNames__default["default"]('mrf-flex_grow_1', step.className, { 'mrf-input__invalid': !!errorDisplayed }) }, step.props, { possibleValues: step.options, httpClient: httpClient, isMulti: step.isMulti, createOption: step.createOption, onCreateOption: step.onCreateOption, transformer: step.transformer, buttons: step.format === format.buttonsSelect, optionsFrom: step.optionsFrom }))));
|
|
28343
|
+
case format.form: //todo: disabled ?
|
|
28344
|
+
const flow = option(step.flow).getOrElse(option(step.schema).map(s => Object.keys(s)).getOrElse([]));
|
|
28345
|
+
return (React__default["default"].createElement(CustomizableInput, { render: step.render, field: { parent, setValue: (key, value) => setValue(key, value), rawValues: getValues(), value: getValues(entry), onChange: (v) => setValue(entry, v, { shouldValidate: true }) } },
|
|
28346
|
+
React__default["default"].createElement(NestedForm, { schema: step.schema, flow: flow, step: step, parent: entry, inputWrapper: inputWrapper, maybeCustomHttpClient: httpClient, value: getValues(entry) || defaultValue, functionalProperty: functionalProperty, errorDisplayed: errorDisplayed, informations: informations })));
|
|
28347
|
+
case format.code:
|
|
28348
|
+
return (React__default["default"].createElement(ControlledInput, { step: step, entry: entry, errorDisplayed: errorDisplayed, component: (field, props) => (React__default["default"].createElement(CodeInput, Object.assign({}, props, {
|
|
28349
|
+
/* TODO className={classNames(step.className, { 'mrf-input__invalid': !!error })}*/
|
|
28350
|
+
onChange: (e) => {
|
|
28351
|
+
let v;
|
|
28352
|
+
try {
|
|
28353
|
+
v = JSON.parse(e);
|
|
28354
|
+
}
|
|
28355
|
+
catch (err) {
|
|
28356
|
+
v = e;
|
|
28357
|
+
}
|
|
28358
|
+
field.onChange(v);
|
|
28359
|
+
option(step === null || step === void 0 ? void 0 : step.onChange)
|
|
28360
|
+
.map(onChange => onChange({ rawValues: getValues(), value: v, setValue }));
|
|
28361
|
+
}, value: field.value === null ? null : ((typeof field.value === 'object') ? JSON.stringify(field.value, null, 2) : field.value) }))) }));
|
|
28362
|
+
default:
|
|
28363
|
+
return (React__default["default"].createElement(ControlledInput, { step: step, entry: entry, errorDisplayed: errorDisplayed },
|
|
28364
|
+
React__default["default"].createElement(ObjectInput, { className: classNames__default["default"](step.className, { 'mrf-input__invalid': !!errorDisplayed }) })));
|
|
28365
|
+
}
|
|
28366
|
+
case type.date:
|
|
28367
|
+
return (React__default["default"].createElement(ControlledInput, { step: step, entry: entry, errorDisplayed: errorDisplayed },
|
|
28368
|
+
React__default["default"].createElement(reactRainbowComponents.DatePicker, { className: classNames__default["default"]('mrf-datepicker', step.className, { 'mrf-input__invalid': !!errorDisplayed }), formatStyle: "large" })));
|
|
28369
|
+
case type.file:
|
|
28370
|
+
return (React__default["default"].createElement(reactHookForm.Controller, { name: entry, control: control, render: ({ field }) => {
|
|
28371
|
+
const FileInput = ({ onChange }) => {
|
|
28372
|
+
const [uploading, setUploading] = React.useState(false);
|
|
28373
|
+
const [input, setInput] = React.useState(undefined);
|
|
28374
|
+
const setFiles = (e) => {
|
|
28375
|
+
const files = e.target.files;
|
|
28376
|
+
setUploading(true);
|
|
28377
|
+
onChange && onChange(files ? [...files] : []);
|
|
28378
|
+
setUploading(false);
|
|
28379
|
+
};
|
|
28380
|
+
const trigger = () => {
|
|
28381
|
+
input === null || input === void 0 ? void 0 : input.click();
|
|
28382
|
+
};
|
|
28383
|
+
const files = field.value || [];
|
|
28384
|
+
return (React__default["default"].createElement("div", { className: classNames__default["default"]('mrf-flex', 'mrf-ai_center', step === null || step === void 0 ? void 0 : step.className, { 'mrf-input__invalid': !!error }) },
|
|
28385
|
+
React__default["default"].createElement("input", { ref: (r) => setInput(r), type: "file", multiple: true, className: 'mrf-d_none', onChange: setFiles }),
|
|
28386
|
+
React__default["default"].createElement("button", { type: "button", className: 'mrf-btn mrf-btn_sm mrf-flex mrf-ai_center', disabled: uploading || functionalProperty(entry, (step === null || step === void 0 ? void 0 : step.disabled) || false), onClick: trigger },
|
|
28387
|
+
uploading && React__default["default"].createElement(reactFeather.Loader, null),
|
|
28388
|
+
!uploading && React__default["default"].createElement(reactFeather.Upload, null),
|
|
28389
|
+
React__default["default"].createElement("span", { className: 'mrf-ml_5' }, "Select file(s)")),
|
|
28390
|
+
React__default["default"].createElement("span", { className: 'mrf-ml_5' }, files.length <= 0 ? 'No files selected' : files.map(r => r.name).join(" , "))));
|
|
28391
|
+
};
|
|
28392
|
+
return (React__default["default"].createElement(ControlledInput, { step: step, entry: entry, errorDisplayed: errorDisplayed },
|
|
28393
|
+
React__default["default"].createElement(FileInput, null)));
|
|
28394
|
+
} }));
|
|
28395
|
+
case type.json:
|
|
28396
|
+
return (React__default["default"].createElement(ControlledInput, { step: step, entry: entry, component: (field, props) => (React__default["default"].createElement(CodeInput, Object.assign({}, props, {
|
|
28397
|
+
/* TODO className={classNames({ 'mrf-input__invalid': !!error })} */
|
|
28398
|
+
onChange: (v) => {
|
|
28399
|
+
field.onChange(v);
|
|
28400
|
+
option(step === null || step === void 0 ? void 0 : step.onChange)
|
|
28401
|
+
.map(onChange => onChange({ rawValues: getValues(), value: v, setValue }));
|
|
28402
|
+
}, value: field.value }))) }));
|
|
29632
28403
|
default:
|
|
29633
|
-
|
|
29634
|
-
|
|
29635
|
-
step: step,
|
|
29636
|
-
entry: entry,
|
|
29637
|
-
errorDisplayed: errorDisplayed
|
|
29638
|
-
}, /*#__PURE__*/React__default["default"].createElement(ObjectInput, {
|
|
29639
|
-
className: classNames__default["default"](step.className, _defineProperty$1({}, 'mrf-input__invalid', errorDisplayed))
|
|
29640
|
-
}));
|
|
29641
|
-
}
|
|
29642
|
-
|
|
29643
|
-
case type.date:
|
|
29644
|
-
return /*#__PURE__*/React__default["default"].createElement(ControlledInput, {
|
|
29645
|
-
defaultValue: defaultValue,
|
|
29646
|
-
step: step,
|
|
29647
|
-
entry: entry,
|
|
29648
|
-
errorDisplayed: errorDisplayed
|
|
29649
|
-
}, /*#__PURE__*/React__default["default"].createElement(reactRainbowComponents.DatePicker, {
|
|
29650
|
-
className: classNames__default["default"]('mrf-datepicker', step.className, _defineProperty$1({}, 'mrf-input__invalid', errorDisplayed)),
|
|
29651
|
-
formatStyle: "large"
|
|
29652
|
-
}));
|
|
29653
|
-
|
|
29654
|
-
case type.file:
|
|
29655
|
-
return /*#__PURE__*/React__default["default"].createElement(reactHookForm.Controller, {
|
|
29656
|
-
name: entry,
|
|
29657
|
-
control: control,
|
|
29658
|
-
render: function render(_ref9) {
|
|
29659
|
-
var field = _ref9.field;
|
|
29660
|
-
|
|
29661
|
-
var FileInput = function FileInput(_ref10) {
|
|
29662
|
-
var onChange = _ref10.onChange;
|
|
29663
|
-
|
|
29664
|
-
var _useState3 = React.useState(false),
|
|
29665
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
29666
|
-
uploading = _useState4[0],
|
|
29667
|
-
setUploading = _useState4[1];
|
|
29668
|
-
|
|
29669
|
-
var _useState5 = React.useState(undefined),
|
|
29670
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
29671
|
-
input = _useState6[0],
|
|
29672
|
-
setInput = _useState6[1];
|
|
29673
|
-
|
|
29674
|
-
var setFiles = function setFiles(e) {
|
|
29675
|
-
var files = e.target.files;
|
|
29676
|
-
setUploading(true);
|
|
29677
|
-
onChange(_toConsumableArray$1(files));
|
|
29678
|
-
setUploading(false);
|
|
29679
|
-
};
|
|
29680
|
-
|
|
29681
|
-
var trigger = function trigger() {
|
|
29682
|
-
input.click();
|
|
29683
|
-
};
|
|
29684
|
-
|
|
29685
|
-
var files = field.value || [];
|
|
29686
|
-
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
29687
|
-
className: classNames__default["default"]('mrf-flex', 'mrf-ai_center', step.className, _defineProperty$1({}, 'mrf-input__invalid', error))
|
|
29688
|
-
}, /*#__PURE__*/React__default["default"].createElement("input", {
|
|
29689
|
-
ref: function ref(r) {
|
|
29690
|
-
return setInput(r);
|
|
29691
|
-
},
|
|
29692
|
-
type: "file",
|
|
29693
|
-
multiple: true,
|
|
29694
|
-
className: "mrf-d_none",
|
|
29695
|
-
onChange: setFiles
|
|
29696
|
-
}), /*#__PURE__*/React__default["default"].createElement("button", {
|
|
29697
|
-
type: "button",
|
|
29698
|
-
className: "mrf-btn mrf-btn_sm mrf-flex mrf-ai_center",
|
|
29699
|
-
disabled: uploading || functionalProperty(entry, step.disabled),
|
|
29700
|
-
onClick: trigger
|
|
29701
|
-
}, uploading && /*#__PURE__*/React__default["default"].createElement(reactFeather.Loader, null), !uploading && /*#__PURE__*/React__default["default"].createElement(reactFeather.Upload, null), /*#__PURE__*/React__default["default"].createElement("span", {
|
|
29702
|
-
className: "mrf-ml_5"
|
|
29703
|
-
}, "Select file(s)")), /*#__PURE__*/React__default["default"].createElement("span", {
|
|
29704
|
-
className: "mrf-ml_5"
|
|
29705
|
-
}, files.length <= 0 ? 'No files selected' : files.map(function (r) {
|
|
29706
|
-
return r.name;
|
|
29707
|
-
}).join(" , ")));
|
|
29708
|
-
};
|
|
29709
|
-
|
|
29710
|
-
return /*#__PURE__*/React__default["default"].createElement(ControlledInput, {
|
|
29711
|
-
defaultValue: defaultValue,
|
|
29712
|
-
step: step,
|
|
29713
|
-
entry: entry,
|
|
29714
|
-
errorDisplayed: errorDisplayed
|
|
29715
|
-
}, /*#__PURE__*/React__default["default"].createElement(FileInput, null));
|
|
29716
|
-
}
|
|
29717
|
-
});
|
|
29718
|
-
|
|
29719
|
-
case type.json:
|
|
29720
|
-
return /*#__PURE__*/React__default["default"].createElement(ControlledInput, {
|
|
29721
|
-
defaultValue: defaultValue,
|
|
29722
|
-
step: step,
|
|
29723
|
-
entry: entry,
|
|
29724
|
-
component: function component(field, props) {
|
|
29725
|
-
return /*#__PURE__*/React__default["default"].createElement(CodeInput, _extends({}, props, {
|
|
29726
|
-
className: classNames__default["default"](_defineProperty$1({}, 'mrf-input__invalid', error)),
|
|
29727
|
-
onChange: function onChange(v) {
|
|
29728
|
-
field.onChange(v);
|
|
29729
|
-
option(step.onChange).map(function (onChange) {
|
|
29730
|
-
return onChange({
|
|
29731
|
-
rawValues: getValues(),
|
|
29732
|
-
value: v,
|
|
29733
|
-
setValue: _setValue
|
|
29734
|
-
});
|
|
29735
|
-
});
|
|
29736
|
-
},
|
|
29737
|
-
value: field.value
|
|
29738
|
-
}));
|
|
29739
|
-
}
|
|
29740
|
-
});
|
|
29741
|
-
|
|
29742
|
-
default:
|
|
29743
|
-
return null;
|
|
29744
|
-
}
|
|
28404
|
+
return null;
|
|
28405
|
+
}
|
|
29745
28406
|
};
|
|
29746
|
-
|
|
29747
|
-
|
|
29748
|
-
|
|
29749
|
-
|
|
29750
|
-
|
|
29751
|
-
|
|
29752
|
-
|
|
29753
|
-
|
|
29754
|
-
|
|
29755
|
-
|
|
29756
|
-
|
|
29757
|
-
|
|
29758
|
-
|
|
29759
|
-
|
|
29760
|
-
|
|
29761
|
-
|
|
29762
|
-
|
|
29763
|
-
|
|
29764
|
-
|
|
29765
|
-
|
|
29766
|
-
|
|
29767
|
-
|
|
29768
|
-
|
|
29769
|
-
|
|
29770
|
-
|
|
29771
|
-
|
|
29772
|
-
|
|
29773
|
-
|
|
29774
|
-
|
|
29775
|
-
}),
|
|
29776
|
-
fields = _useFieldArray.fields,
|
|
29777
|
-
append = _useFieldArray.append,
|
|
29778
|
-
remove = _useFieldArray.remove;
|
|
29779
|
-
|
|
29780
|
-
return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, fields.map(function (field, idx) {
|
|
29781
|
-
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
29782
|
-
key: field.id
|
|
29783
|
-
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
29784
|
-
className: "mrf-ai_center mrf-mt_5",
|
|
29785
|
-
style: {
|
|
29786
|
-
position: 'relative'
|
|
29787
|
-
}
|
|
29788
|
-
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
29789
|
-
style: {
|
|
29790
|
-
width: '95%'
|
|
29791
|
-
}
|
|
29792
|
-
}, component(_objectSpread2$1(_objectSpread2$1({
|
|
29793
|
-
key: field.id
|
|
29794
|
-
}, field), {}, {
|
|
29795
|
-
defaultValue: values[idx]
|
|
29796
|
-
}), idx)), /*#__PURE__*/React__default["default"].createElement("button", {
|
|
29797
|
-
type: "button",
|
|
29798
|
-
style: {
|
|
29799
|
-
position: 'absolute',
|
|
29800
|
-
top: '2px',
|
|
29801
|
-
right: 0
|
|
29802
|
-
},
|
|
29803
|
-
className: "mrf-btn mrf-btn_red mrf-btn_sm mrf-ml_5",
|
|
29804
|
-
disabled: disabled,
|
|
29805
|
-
onClick: function onClick() {
|
|
29806
|
-
remove(idx);
|
|
29807
|
-
trigger(entry);
|
|
29808
|
-
}
|
|
29809
|
-
}, /*#__PURE__*/React__default["default"].createElement(reactFeather.Trash2, {
|
|
29810
|
-
size: 16
|
|
29811
|
-
}))));
|
|
29812
|
-
}), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
29813
|
-
className: "mrf-flex mrf-jc_flex_end"
|
|
29814
|
-
}, /*#__PURE__*/React__default["default"].createElement("button", {
|
|
29815
|
-
type: "button",
|
|
29816
|
-
className: classNames__default["default"]('mrf-btn', 'mrf-btn_blue', 'mrf-btn_sm', 'mrf-mt_5', _defineProperty$1({}, 'mrf-input__invalid', errorDisplayed)),
|
|
29817
|
-
onClick: function onClick() {
|
|
29818
|
-
var newValue = cleanInputArray({}, getValues(entry), step.flow, step.schema);
|
|
29819
|
-
append({
|
|
29820
|
-
value: step.addableDefaultValue || (step.type === type.object && newValue ? newValue : defaultVal())
|
|
29821
|
-
}); // trigger(entry);
|
|
29822
|
-
|
|
29823
|
-
option(step.onChange).map(function (onChange) {
|
|
29824
|
-
return onChange({
|
|
29825
|
-
rawValues: getValues(),
|
|
29826
|
-
value: getValues(entry),
|
|
29827
|
-
setValue: setValue
|
|
29828
|
-
});
|
|
29829
|
-
});
|
|
29830
|
-
},
|
|
29831
|
-
disabled: disabled
|
|
29832
|
-
}, "Add"), error && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
29833
|
-
className: "mrf-invalid-feedback"
|
|
29834
|
-
}, error.message)));
|
|
28407
|
+
const ArrayStep = ({ entry, step, component, disabled }) => {
|
|
28408
|
+
const { getValues, setValue, control, trigger, formState } = reactHookForm.useFormContext();
|
|
28409
|
+
const values = getValues(entry);
|
|
28410
|
+
const error = entry.split('.').reduce((acc, curr) => acc && acc[curr], formState.errors);
|
|
28411
|
+
const isDirty = entry.split('.').reduce((acc, curr) => acc && acc[curr], formState.dirtyFields);
|
|
28412
|
+
const isTouched = entry.split('.').reduce((acc, curr) => acc && acc[curr], formState.touchedFields);
|
|
28413
|
+
const errorDisplayed = !!error && (formState.isSubmitted || isDirty || isTouched);
|
|
28414
|
+
const { fields, append, remove } = reactHookForm.useFieldArray({ control, name: entry });
|
|
28415
|
+
return (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
28416
|
+
fields
|
|
28417
|
+
.map((field, idx) => {
|
|
28418
|
+
return (React__default["default"].createElement("div", { key: field.id },
|
|
28419
|
+
React__default["default"].createElement("div", { className: 'mrf-ai_center mrf-mt_5', style: { position: 'relative' } },
|
|
28420
|
+
React__default["default"].createElement("div", { style: { width: '95%' } }, component(Object.assign(Object.assign({ key: field.id }, field), { defaultValue: values[idx] }), idx)),
|
|
28421
|
+
React__default["default"].createElement("button", { type: "button", style: { position: 'absolute', top: '2px', right: 0 }, className: 'mrf-btn mrf-btn_red mrf-btn_sm mrf-ml_5', disabled: disabled, onClick: () => {
|
|
28422
|
+
remove(idx);
|
|
28423
|
+
trigger(entry);
|
|
28424
|
+
} },
|
|
28425
|
+
React__default["default"].createElement(reactFeather.Trash2, { size: 16 })))));
|
|
28426
|
+
}),
|
|
28427
|
+
React__default["default"].createElement("div", { className: 'mrf-flex mrf-jc_flex_end' },
|
|
28428
|
+
React__default["default"].createElement("button", { type: "button", className: classNames__default["default"]('mrf-btn', 'mrf-btn_blue', 'mrf-btn_sm', 'mrf-mt_5', { ['mrf-input__invalid']: !!errorDisplayed }), onClick: () => {
|
|
28429
|
+
const newValue = cleanInputArray({}, getValues(entry), step.flow, step.schema);
|
|
28430
|
+
append({ value: step.addableDefaultValue || ((step.type === type.object && newValue) ? newValue : defaultVal()) });
|
|
28431
|
+
// trigger(entry);
|
|
28432
|
+
option(step.onChange)
|
|
28433
|
+
.map(onChange => onChange({ rawValues: getValues(), value: getValues(entry), setValue }));
|
|
28434
|
+
}, disabled: disabled }, "Add"),
|
|
28435
|
+
error && React__default["default"].createElement("div", { className: "mrf-invalid-feedback" }, error.message))));
|
|
29835
28436
|
};
|
|
29836
|
-
|
|
29837
|
-
var
|
|
29838
|
-
|
|
29839
|
-
|
|
29840
|
-
|
|
29841
|
-
|
|
29842
|
-
|
|
29843
|
-
|
|
29844
|
-
|
|
29845
|
-
|
|
29846
|
-
|
|
29847
|
-
|
|
29848
|
-
|
|
29849
|
-
|
|
29850
|
-
|
|
29851
|
-
|
|
29852
|
-
getValues = _useFormContext4.getValues,
|
|
29853
|
-
setValue = _useFormContext4.setValue,
|
|
29854
|
-
watch = _useFormContext4.watch;
|
|
29855
|
-
|
|
29856
|
-
var _useState7 = React.useState(!!step.collapsed),
|
|
29857
|
-
_useState8 = _slicedToArray(_useState7, 2),
|
|
29858
|
-
collapsed = _useState8[0],
|
|
29859
|
-
setCollapsed = _useState8[1];
|
|
29860
|
-
|
|
29861
|
-
reactHookForm.useWatch(step === null || step === void 0 ? void 0 : (_step$conditionalSche = step.conditionalSchema) === null || _step$conditionalSche === void 0 ? void 0 : _step$conditionalSche.ref);
|
|
29862
|
-
var schemaAndFlow = option(step.conditionalSchema).map(function (condiSchema) {
|
|
29863
|
-
var ref = option(condiSchema.ref).map(function (ref) {
|
|
29864
|
-
return getValues(ref);
|
|
29865
|
-
}).getOrNull();
|
|
29866
|
-
var rawValues = getValues();
|
|
29867
|
-
var filterSwitch = condiSchema["switch"].find(function (s) {
|
|
29868
|
-
if (typeof s.condition === 'function') {
|
|
29869
|
-
return s.condition({
|
|
29870
|
-
rawValues: rawValues,
|
|
29871
|
-
ref: ref
|
|
28437
|
+
const NestedForm = ({ schema, flow, parent, inputWrapper, maybeCustomHttpClient, errorDisplayed, value, step, functionalProperty, informations }) => {
|
|
28438
|
+
var _a;
|
|
28439
|
+
const { getValues, setValue, control, formState: { errors, dirtyFields, touchedFields } } = reactHookForm.useFormContext();
|
|
28440
|
+
const [collapsed, setCollapsed] = React.useState(!!step.collapsed);
|
|
28441
|
+
reactHookForm.useWatch({ name: ((_a = step === null || step === void 0 ? void 0 : step.conditionalSchema) === null || _a === void 0 ? void 0 : _a.ref) || "", control });
|
|
28442
|
+
const schemaAndFlow = option(step.conditionalSchema)
|
|
28443
|
+
.map(condiSchema => {
|
|
28444
|
+
const ref = option(condiSchema.ref).map(ref => getValues(ref)).getOrNull();
|
|
28445
|
+
const rawValues = getValues();
|
|
28446
|
+
const filterSwitch = condiSchema.switch.find(s => {
|
|
28447
|
+
if (typeof s.condition === 'function') {
|
|
28448
|
+
return s.condition({ rawValues, ref });
|
|
28449
|
+
}
|
|
28450
|
+
else {
|
|
28451
|
+
return s.condition === ref;
|
|
28452
|
+
}
|
|
29872
28453
|
});
|
|
29873
|
-
|
|
29874
|
-
|
|
29875
|
-
|
|
29876
|
-
|
|
29877
|
-
|
|
29878
|
-
|
|
29879
|
-
|
|
29880
|
-
|
|
29881
|
-
|
|
29882
|
-
});
|
|
29883
|
-
|
|
29884
|
-
|
|
29885
|
-
|
|
29886
|
-
};
|
|
29887
|
-
|
|
29888
|
-
|
|
29889
|
-
|
|
29890
|
-
|
|
29891
|
-
|
|
29892
|
-
|
|
29893
|
-
|
|
29894
|
-
|
|
29895
|
-
|
|
29896
|
-
|
|
29897
|
-
|
|
29898
|
-
|
|
29899
|
-
|
|
29900
|
-
|
|
29901
|
-
|
|
29902
|
-
|
|
29903
|
-
|
|
29904
|
-
|
|
29905
|
-
|
|
29906
|
-
|
|
29907
|
-
|
|
29908
|
-
|
|
29909
|
-
|
|
29910
|
-
|
|
29911
|
-
|
|
29912
|
-
|
|
29913
|
-
|
|
29914
|
-
return true;
|
|
29915
|
-
}
|
|
29916
|
-
}).getOrElse(true);
|
|
29917
|
-
return [].concat(_toConsumableArray$1(acc), [{
|
|
29918
|
-
step: step,
|
|
29919
|
-
visibleStep: visibleStep,
|
|
29920
|
-
entry: entry
|
|
29921
|
-
}]);
|
|
29922
|
-
}, []);
|
|
29923
|
-
var bordered = computedSandF.filter(function (x) {
|
|
29924
|
-
return x.visibleStep;
|
|
29925
|
-
}).length >= 1 && step.label !== null;
|
|
29926
|
-
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
29927
|
-
className: classNames__default["default"]((_classNames17 = {}, _defineProperty$1(_classNames17, 'mrf-nestedform__border', bordered), _defineProperty$1(_classNames17, 'mrf-border__error', !!errorDisplayed), _classNames17)),
|
|
29928
|
-
style: {
|
|
29929
|
-
position: 'relative'
|
|
29930
|
-
}
|
|
29931
|
-
}, !!step.collapsable && schemaAndFlow.flow.length > 1 && collapsed && /*#__PURE__*/React__default["default"].createElement(reactFeather.ChevronDown, {
|
|
29932
|
-
size: 30,
|
|
29933
|
-
className: "mrf-cursor_pointer",
|
|
29934
|
-
style: {
|
|
29935
|
-
position: 'absolute',
|
|
29936
|
-
top: -35,
|
|
29937
|
-
right: 0,
|
|
29938
|
-
zIndex: 100
|
|
29939
|
-
},
|
|
29940
|
-
strokeWidth: "2",
|
|
29941
|
-
onClick: function onClick() {
|
|
29942
|
-
return setCollapsed(!collapsed);
|
|
29943
|
-
}
|
|
29944
|
-
}), !!step.collapsable && schemaAndFlow.flow.length > 1 && !collapsed && /*#__PURE__*/React__default["default"].createElement(reactFeather.ChevronUp, {
|
|
29945
|
-
size: 30,
|
|
29946
|
-
className: "mrf-cursor_pointer",
|
|
29947
|
-
style: {
|
|
29948
|
-
position: 'absolute',
|
|
29949
|
-
top: -35,
|
|
29950
|
-
right: 0,
|
|
29951
|
-
zIndex: 100
|
|
29952
|
-
},
|
|
29953
|
-
strokeWidth: "2",
|
|
29954
|
-
onClick: function onClick() {
|
|
29955
|
-
return setCollapsed(!collapsed);
|
|
29956
|
-
}
|
|
29957
|
-
}), computedSandF.map(function (_ref13, idx) {
|
|
29958
|
-
var step = _ref13.step,
|
|
29959
|
-
visibleStep = _ref13.visibleStep,
|
|
29960
|
-
entry = _ref13.entry;
|
|
29961
|
-
|
|
29962
|
-
if (!step && typeof entry === 'string') {
|
|
29963
|
-
console.error("no step found for the entry \"".concat(entry, "\" in the given schema. Your form might not work properly. Please fix it"));
|
|
29964
|
-
return null;
|
|
29965
|
-
}
|
|
29966
|
-
|
|
29967
|
-
return /*#__PURE__*/React__default["default"].createElement(BasicWrapper, {
|
|
29968
|
-
key: "".concat(entry, ".").concat(idx),
|
|
29969
|
-
className: classNames__default["default"](_defineProperty$1({}, 'mrf-display__none', collapsed && !step.visibleOnCollapse || !visibleStep)),
|
|
29970
|
-
entry: "".concat(parent, ".").concat(entry),
|
|
29971
|
-
label: functionalProperty(entry, (step === null || step === void 0 ? void 0 : step.label) === null ? null : (step === null || step === void 0 ? void 0 : step.label) || entry),
|
|
29972
|
-
help: step.help,
|
|
29973
|
-
render: inputWrapper
|
|
29974
|
-
}, /*#__PURE__*/React__default["default"].createElement(Step, {
|
|
29975
|
-
key: "step.".concat(entry, ".").concat(idx),
|
|
29976
|
-
entry: "".concat(parent, ".").concat(entry),
|
|
29977
|
-
realEntry: entry,
|
|
29978
|
-
step: schemaAndFlow.schema[entry],
|
|
29979
|
-
parent: parent,
|
|
29980
|
-
schema: schemaAndFlow.schema,
|
|
29981
|
-
inputWrapper: inputWrapper,
|
|
29982
|
-
httpClient: maybeCustomHttpClient,
|
|
29983
|
-
defaultValue: value && value[entry],
|
|
29984
|
-
functionalProperty: functionalProperty
|
|
29985
|
-
}));
|
|
29986
|
-
}));
|
|
28454
|
+
const schemaAndFlow = option(filterSwitch)
|
|
28455
|
+
.orElse(condiSchema.switch.find(s => s.default))
|
|
28456
|
+
.getOrElse({ schema: {}, flow: [] });
|
|
28457
|
+
return { schema: schemaAndFlow.schema, flow: schemaAndFlow.flow || Object.keys(schemaAndFlow.schema) };
|
|
28458
|
+
})
|
|
28459
|
+
.getOrElse({ schema, flow });
|
|
28460
|
+
useHashEffect(() => {
|
|
28461
|
+
const def = getDefaultValues(schemaAndFlow.flow, schemaAndFlow.schema, getValues(parent));
|
|
28462
|
+
setValue(parent, def, { shouldValidate: false });
|
|
28463
|
+
}, [schemaAndFlow.schema]);
|
|
28464
|
+
const computedSandF = schemaAndFlow.flow.reduce((acc, entry) => {
|
|
28465
|
+
const step = (typeof entry === "string") ? schemaAndFlow.schema[entry] : schemaAndFlow.schema[entry.label];
|
|
28466
|
+
return [...acc, { step, entry }];
|
|
28467
|
+
}, []);
|
|
28468
|
+
const bordered = computedSandF.length >= 1 && step.label !== null;
|
|
28469
|
+
return (React__default["default"].createElement("div", { className: classNames__default["default"]({ ['mrf-nestedform__border']: bordered, ['mrf-border__error']: !!errorDisplayed }), style: { position: 'relative' } },
|
|
28470
|
+
!!step.collapsable && schemaAndFlow.flow.length > 1 && collapsed &&
|
|
28471
|
+
React__default["default"].createElement(reactFeather.ChevronDown, { size: 30, className: 'mrf-cursor_pointer', style: { position: 'absolute', top: -35, right: 0, zIndex: 100 }, strokeWidth: "2", onClick: () => setCollapsed(!collapsed) }),
|
|
28472
|
+
!!step.collapsable && schemaAndFlow.flow.length > 1 && !collapsed &&
|
|
28473
|
+
React__default["default"].createElement(reactFeather.ChevronUp, { size: 30, className: 'mrf-cursor_pointer', style: { position: 'absolute', top: -35, right: 0, zIndex: 100 }, strokeWidth: "2", onClick: () => setCollapsed(!collapsed) }),
|
|
28474
|
+
computedSandF.map(({ step, entry }, idx) => {
|
|
28475
|
+
if (!step && typeof entry === 'string') {
|
|
28476
|
+
console.error(`no step found for the entry "${entry}" in the given schema. Your form might not work properly. Please fix it`);
|
|
28477
|
+
return null;
|
|
28478
|
+
}
|
|
28479
|
+
if (typeof entry === "object") {
|
|
28480
|
+
const errored = extractFlowString(entry).some(step => !!errors[step] && (dirtyFields[step] || touchedFields[step])); /* FIXME does it works in case of Flow object ? Need to do a "flatMap" to retrieve all leafs string of flows objects */
|
|
28481
|
+
return React__default["default"].createElement(Collapse, Object.assign({}, entry, { errored: errored }), entry.flow.map((en, entryIdx) => {
|
|
28482
|
+
const stp = typeof en === "object" ? undefined : schema[en];
|
|
28483
|
+
if (!stp && typeof en === 'string') {
|
|
28484
|
+
console.error(`no step found for the entry "${en}" in the given schema. Your form might not work properly. Please fix it`);
|
|
28485
|
+
return null;
|
|
28486
|
+
}
|
|
28487
|
+
return (React__default["default"].createElement(BasicWrapper, { key: `collapse-${en}-${entryIdx}`, entry: en, functionalProperty: functionalProperty, step: stp, render: inputWrapper },
|
|
28488
|
+
React__default["default"].createElement(Step, { entry: en, step: stp, schema: schema, inputWrapper: inputWrapper, httpClient: maybeCustomHttpClient, defaultValue: stp === null || stp === void 0 ? void 0 : stp.defaultValue, functionalProperty: functionalProperty })));
|
|
28489
|
+
}));
|
|
28490
|
+
// TODO return collapse, then entry will always be a string in below return
|
|
28491
|
+
}
|
|
28492
|
+
return (React__default["default"].createElement(BasicWrapper, { key: `${entry}.${idx}`, className: classNames__default["default"]({ ['mrf-display__none']: (collapsed && !step.visibleOnCollapse) }), entry: `${parent}.${entry}`, functionalProperty: functionalProperty, step: step, render: inputWrapper },
|
|
28493
|
+
React__default["default"].createElement(Step, { key: `step.${entry}.${idx}`, entry: `${parent}.${entry}`, realEntry: entry, step: schemaAndFlow.schema[entry], parent: parent, schema: schemaAndFlow.schema, inputWrapper: inputWrapper, httpClient: maybeCustomHttpClient, defaultValue: value && value[entry], functionalProperty: functionalProperty, parentInformations: informations })));
|
|
28494
|
+
})));
|
|
29987
28495
|
};
|
|
28496
|
+
function extractFlowString(entry) {
|
|
28497
|
+
return entry.flow.map(eitherStringOrObject => {
|
|
28498
|
+
if (typeof eitherStringOrObject === "string") {
|
|
28499
|
+
return eitherStringOrObject;
|
|
28500
|
+
}
|
|
28501
|
+
else {
|
|
28502
|
+
return extractFlowString(eitherStringOrObject);
|
|
28503
|
+
}
|
|
28504
|
+
}).flat();
|
|
28505
|
+
}
|
|
29988
28506
|
|
|
29989
28507
|
exports.BooleanInput = BooleanInput;
|
|
29990
28508
|
exports.CodeInput = CodeInput;
|