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