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