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