@itcase/forms 1.0.36 → 1.0.38
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/dist/css/form/Field/Input/Input.css +1 -1
- package/dist/css/form/FormField/FormField.css +2 -3
- package/dist/itcase-forms.cjs.js +971 -1511
- package/dist/itcase-forms.esm.js +971 -1511
- package/package.json +23 -26
package/dist/itcase-forms.esm.js
CHANGED
|
@@ -32,28 +32,25 @@ import { Group as Group$1 } from '@itcase/ui/components/Group';
|
|
|
32
32
|
import { NotificationItem } from '@itcase/ui/components/Notification';
|
|
33
33
|
import createDecorator from 'final-form-focus';
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
const phoneValidation = (value, context) => {
|
|
36
36
|
if (!value) {
|
|
37
37
|
return true;
|
|
38
38
|
}
|
|
39
39
|
return isPossiblePhoneNumber(value, 'RU');
|
|
40
40
|
};
|
|
41
|
-
|
|
41
|
+
const emailValidation = (value, context) => {
|
|
42
42
|
// from https://emailregex.com/
|
|
43
43
|
if (!value) {
|
|
44
44
|
return true;
|
|
45
45
|
}
|
|
46
46
|
// eslint-disable-next-line
|
|
47
|
-
|
|
47
|
+
const regexp = /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]{2,}(?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/;
|
|
48
48
|
return regexp.test(String(value).toLowerCase());
|
|
49
49
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
schema.requiredFields = fields.reduce(
|
|
53
|
-
|
|
54
|
-
var fieldName = _ref[0],
|
|
55
|
-
validationProps = _ref[1];
|
|
56
|
-
if ((_validationProps$excl = validationProps.exclusiveTests) != null && _validationProps$excl.required) {
|
|
50
|
+
const addRequiredFieldsParamToSchema = schema => {
|
|
51
|
+
const fields = Object.entries(schema.fields);
|
|
52
|
+
schema.requiredFields = fields.reduce((list, [fieldName, validationProps]) => {
|
|
53
|
+
if (validationProps.exclusiveTests?.required) {
|
|
57
54
|
list.push(fieldName);
|
|
58
55
|
}
|
|
59
56
|
return list;
|
|
@@ -61,382 +58,6 @@ var addRequiredFieldsParamToSchema = function addRequiredFieldsParamToSchema(sch
|
|
|
61
58
|
return schema;
|
|
62
59
|
};
|
|
63
60
|
|
|
64
|
-
function _asyncIterator(r) {
|
|
65
|
-
var n,
|
|
66
|
-
t,
|
|
67
|
-
o,
|
|
68
|
-
e = 2;
|
|
69
|
-
for ("undefined" != typeof Symbol && (t = Symbol.asyncIterator, o = Symbol.iterator); e--;) {
|
|
70
|
-
if (t && null != (n = r[t])) return n.call(r);
|
|
71
|
-
if (o && null != (n = r[o])) return new AsyncFromSyncIterator(n.call(r));
|
|
72
|
-
t = "@@asyncIterator", o = "@@iterator";
|
|
73
|
-
}
|
|
74
|
-
throw new TypeError("Object is not async iterable");
|
|
75
|
-
}
|
|
76
|
-
function AsyncFromSyncIterator(r) {
|
|
77
|
-
function AsyncFromSyncIteratorContinuation(r) {
|
|
78
|
-
if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object."));
|
|
79
|
-
var n = r.done;
|
|
80
|
-
return Promise.resolve(r.value).then(function (r) {
|
|
81
|
-
return {
|
|
82
|
-
value: r,
|
|
83
|
-
done: n
|
|
84
|
-
};
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
return AsyncFromSyncIterator = function (r) {
|
|
88
|
-
this.s = r, this.n = r.next;
|
|
89
|
-
}, AsyncFromSyncIterator.prototype = {
|
|
90
|
-
s: null,
|
|
91
|
-
n: null,
|
|
92
|
-
next: function () {
|
|
93
|
-
return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
|
|
94
|
-
},
|
|
95
|
-
return: function (r) {
|
|
96
|
-
var n = this.s.return;
|
|
97
|
-
return void 0 === n ? Promise.resolve({
|
|
98
|
-
value: r,
|
|
99
|
-
done: !0
|
|
100
|
-
}) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
|
101
|
-
},
|
|
102
|
-
throw: function (r) {
|
|
103
|
-
var n = this.s.return;
|
|
104
|
-
return void 0 === n ? Promise.reject(r) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
|
105
|
-
}
|
|
106
|
-
}, new AsyncFromSyncIterator(r);
|
|
107
|
-
}
|
|
108
|
-
function _regeneratorRuntime() {
|
|
109
|
-
_regeneratorRuntime = function () {
|
|
110
|
-
return e;
|
|
111
|
-
};
|
|
112
|
-
var t,
|
|
113
|
-
e = {},
|
|
114
|
-
r = Object.prototype,
|
|
115
|
-
n = r.hasOwnProperty,
|
|
116
|
-
o = Object.defineProperty || function (t, e, r) {
|
|
117
|
-
t[e] = r.value;
|
|
118
|
-
},
|
|
119
|
-
i = "function" == typeof Symbol ? Symbol : {},
|
|
120
|
-
a = i.iterator || "@@iterator",
|
|
121
|
-
c = i.asyncIterator || "@@asyncIterator",
|
|
122
|
-
u = i.toStringTag || "@@toStringTag";
|
|
123
|
-
function define(t, e, r) {
|
|
124
|
-
return Object.defineProperty(t, e, {
|
|
125
|
-
value: r,
|
|
126
|
-
enumerable: !0,
|
|
127
|
-
configurable: !0,
|
|
128
|
-
writable: !0
|
|
129
|
-
}), t[e];
|
|
130
|
-
}
|
|
131
|
-
try {
|
|
132
|
-
define({}, "");
|
|
133
|
-
} catch (t) {
|
|
134
|
-
define = function (t, e, r) {
|
|
135
|
-
return t[e] = r;
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
function wrap(t, e, r, n) {
|
|
139
|
-
var i = e && e.prototype instanceof Generator ? e : Generator,
|
|
140
|
-
a = Object.create(i.prototype),
|
|
141
|
-
c = new Context(n || []);
|
|
142
|
-
return o(a, "_invoke", {
|
|
143
|
-
value: makeInvokeMethod(t, r, c)
|
|
144
|
-
}), a;
|
|
145
|
-
}
|
|
146
|
-
function tryCatch(t, e, r) {
|
|
147
|
-
try {
|
|
148
|
-
return {
|
|
149
|
-
type: "normal",
|
|
150
|
-
arg: t.call(e, r)
|
|
151
|
-
};
|
|
152
|
-
} catch (t) {
|
|
153
|
-
return {
|
|
154
|
-
type: "throw",
|
|
155
|
-
arg: t
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
e.wrap = wrap;
|
|
160
|
-
var h = "suspendedStart",
|
|
161
|
-
l = "suspendedYield",
|
|
162
|
-
f = "executing",
|
|
163
|
-
s = "completed",
|
|
164
|
-
y = {};
|
|
165
|
-
function Generator() {}
|
|
166
|
-
function GeneratorFunction() {}
|
|
167
|
-
function GeneratorFunctionPrototype() {}
|
|
168
|
-
var p = {};
|
|
169
|
-
define(p, a, function () {
|
|
170
|
-
return this;
|
|
171
|
-
});
|
|
172
|
-
var d = Object.getPrototypeOf,
|
|
173
|
-
v = d && d(d(values([])));
|
|
174
|
-
v && v !== r && n.call(v, a) && (p = v);
|
|
175
|
-
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
|
176
|
-
function defineIteratorMethods(t) {
|
|
177
|
-
["next", "throw", "return"].forEach(function (e) {
|
|
178
|
-
define(t, e, function (t) {
|
|
179
|
-
return this._invoke(e, t);
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
function AsyncIterator(t, e) {
|
|
184
|
-
function invoke(r, o, i, a) {
|
|
185
|
-
var c = tryCatch(t[r], t, o);
|
|
186
|
-
if ("throw" !== c.type) {
|
|
187
|
-
var u = c.arg,
|
|
188
|
-
h = u.value;
|
|
189
|
-
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
|
190
|
-
invoke("next", t, i, a);
|
|
191
|
-
}, function (t) {
|
|
192
|
-
invoke("throw", t, i, a);
|
|
193
|
-
}) : e.resolve(h).then(function (t) {
|
|
194
|
-
u.value = t, i(u);
|
|
195
|
-
}, function (t) {
|
|
196
|
-
return invoke("throw", t, i, a);
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
a(c.arg);
|
|
200
|
-
}
|
|
201
|
-
var r;
|
|
202
|
-
o(this, "_invoke", {
|
|
203
|
-
value: function (t, n) {
|
|
204
|
-
function callInvokeWithMethodAndArg() {
|
|
205
|
-
return new e(function (e, r) {
|
|
206
|
-
invoke(t, n, e, r);
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
function makeInvokeMethod(e, r, n) {
|
|
214
|
-
var o = h;
|
|
215
|
-
return function (i, a) {
|
|
216
|
-
if (o === f) throw new Error("Generator is already running");
|
|
217
|
-
if (o === s) {
|
|
218
|
-
if ("throw" === i) throw a;
|
|
219
|
-
return {
|
|
220
|
-
value: t,
|
|
221
|
-
done: !0
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
for (n.method = i, n.arg = a;;) {
|
|
225
|
-
var c = n.delegate;
|
|
226
|
-
if (c) {
|
|
227
|
-
var u = maybeInvokeDelegate(c, n);
|
|
228
|
-
if (u) {
|
|
229
|
-
if (u === y) continue;
|
|
230
|
-
return u;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
|
234
|
-
if (o === h) throw o = s, n.arg;
|
|
235
|
-
n.dispatchException(n.arg);
|
|
236
|
-
} else "return" === n.method && n.abrupt("return", n.arg);
|
|
237
|
-
o = f;
|
|
238
|
-
var p = tryCatch(e, r, n);
|
|
239
|
-
if ("normal" === p.type) {
|
|
240
|
-
if (o = n.done ? s : l, p.arg === y) continue;
|
|
241
|
-
return {
|
|
242
|
-
value: p.arg,
|
|
243
|
-
done: n.done
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
function maybeInvokeDelegate(e, r) {
|
|
251
|
-
var n = r.method,
|
|
252
|
-
o = e.iterator[n];
|
|
253
|
-
if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
|
|
254
|
-
var i = tryCatch(o, e.iterator, r.arg);
|
|
255
|
-
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
|
256
|
-
var a = i.arg;
|
|
257
|
-
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
|
|
258
|
-
}
|
|
259
|
-
function pushTryEntry(t) {
|
|
260
|
-
var e = {
|
|
261
|
-
tryLoc: t[0]
|
|
262
|
-
};
|
|
263
|
-
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
|
264
|
-
}
|
|
265
|
-
function resetTryEntry(t) {
|
|
266
|
-
var e = t.completion || {};
|
|
267
|
-
e.type = "normal", delete e.arg, t.completion = e;
|
|
268
|
-
}
|
|
269
|
-
function Context(t) {
|
|
270
|
-
this.tryEntries = [{
|
|
271
|
-
tryLoc: "root"
|
|
272
|
-
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
|
273
|
-
}
|
|
274
|
-
function values(e) {
|
|
275
|
-
if (e || "" === e) {
|
|
276
|
-
var r = e[a];
|
|
277
|
-
if (r) return r.call(e);
|
|
278
|
-
if ("function" == typeof e.next) return e;
|
|
279
|
-
if (!isNaN(e.length)) {
|
|
280
|
-
var o = -1,
|
|
281
|
-
i = function next() {
|
|
282
|
-
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
|
283
|
-
return next.value = t, next.done = !0, next;
|
|
284
|
-
};
|
|
285
|
-
return i.next = i;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
throw new TypeError(typeof e + " is not iterable");
|
|
289
|
-
}
|
|
290
|
-
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
|
|
291
|
-
value: GeneratorFunctionPrototype,
|
|
292
|
-
configurable: !0
|
|
293
|
-
}), o(GeneratorFunctionPrototype, "constructor", {
|
|
294
|
-
value: GeneratorFunction,
|
|
295
|
-
configurable: !0
|
|
296
|
-
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
|
|
297
|
-
var e = "function" == typeof t && t.constructor;
|
|
298
|
-
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
|
|
299
|
-
}, e.mark = function (t) {
|
|
300
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
|
|
301
|
-
}, e.awrap = function (t) {
|
|
302
|
-
return {
|
|
303
|
-
__await: t
|
|
304
|
-
};
|
|
305
|
-
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
|
306
|
-
return this;
|
|
307
|
-
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
|
308
|
-
void 0 === i && (i = Promise);
|
|
309
|
-
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
|
310
|
-
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
|
311
|
-
return t.done ? t.value : a.next();
|
|
312
|
-
});
|
|
313
|
-
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
|
314
|
-
return this;
|
|
315
|
-
}), define(g, "toString", function () {
|
|
316
|
-
return "[object Generator]";
|
|
317
|
-
}), e.keys = function (t) {
|
|
318
|
-
var e = Object(t),
|
|
319
|
-
r = [];
|
|
320
|
-
for (var n in e) r.push(n);
|
|
321
|
-
return r.reverse(), function next() {
|
|
322
|
-
for (; r.length;) {
|
|
323
|
-
var t = r.pop();
|
|
324
|
-
if (t in e) return next.value = t, next.done = !1, next;
|
|
325
|
-
}
|
|
326
|
-
return next.done = !0, next;
|
|
327
|
-
};
|
|
328
|
-
}, e.values = values, Context.prototype = {
|
|
329
|
-
constructor: Context,
|
|
330
|
-
reset: function (e) {
|
|
331
|
-
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
|
|
332
|
-
},
|
|
333
|
-
stop: function () {
|
|
334
|
-
this.done = !0;
|
|
335
|
-
var t = this.tryEntries[0].completion;
|
|
336
|
-
if ("throw" === t.type) throw t.arg;
|
|
337
|
-
return this.rval;
|
|
338
|
-
},
|
|
339
|
-
dispatchException: function (e) {
|
|
340
|
-
if (this.done) throw e;
|
|
341
|
-
var r = this;
|
|
342
|
-
function handle(n, o) {
|
|
343
|
-
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
|
344
|
-
}
|
|
345
|
-
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
|
346
|
-
var i = this.tryEntries[o],
|
|
347
|
-
a = i.completion;
|
|
348
|
-
if ("root" === i.tryLoc) return handle("end");
|
|
349
|
-
if (i.tryLoc <= this.prev) {
|
|
350
|
-
var c = n.call(i, "catchLoc"),
|
|
351
|
-
u = n.call(i, "finallyLoc");
|
|
352
|
-
if (c && u) {
|
|
353
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
354
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
355
|
-
} else if (c) {
|
|
356
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
357
|
-
} else {
|
|
358
|
-
if (!u) throw new Error("try statement without catch or finally");
|
|
359
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
},
|
|
364
|
-
abrupt: function (t, e) {
|
|
365
|
-
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
|
366
|
-
var o = this.tryEntries[r];
|
|
367
|
-
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
|
368
|
-
var i = o;
|
|
369
|
-
break;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
|
373
|
-
var a = i ? i.completion : {};
|
|
374
|
-
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
|
375
|
-
},
|
|
376
|
-
complete: function (t, e) {
|
|
377
|
-
if ("throw" === t.type) throw t.arg;
|
|
378
|
-
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
|
|
379
|
-
},
|
|
380
|
-
finish: function (t) {
|
|
381
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
382
|
-
var r = this.tryEntries[e];
|
|
383
|
-
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
|
384
|
-
}
|
|
385
|
-
},
|
|
386
|
-
catch: function (t) {
|
|
387
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
388
|
-
var r = this.tryEntries[e];
|
|
389
|
-
if (r.tryLoc === t) {
|
|
390
|
-
var n = r.completion;
|
|
391
|
-
if ("throw" === n.type) {
|
|
392
|
-
var o = n.arg;
|
|
393
|
-
resetTryEntry(r);
|
|
394
|
-
}
|
|
395
|
-
return o;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
throw new Error("illegal catch attempt");
|
|
399
|
-
},
|
|
400
|
-
delegateYield: function (e, r, n) {
|
|
401
|
-
return this.delegate = {
|
|
402
|
-
iterator: values(e),
|
|
403
|
-
resultName: r,
|
|
404
|
-
nextLoc: n
|
|
405
|
-
}, "next" === this.method && (this.arg = t), y;
|
|
406
|
-
}
|
|
407
|
-
}, e;
|
|
408
|
-
}
|
|
409
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
410
|
-
try {
|
|
411
|
-
var info = gen[key](arg);
|
|
412
|
-
var value = info.value;
|
|
413
|
-
} catch (error) {
|
|
414
|
-
reject(error);
|
|
415
|
-
return;
|
|
416
|
-
}
|
|
417
|
-
if (info.done) {
|
|
418
|
-
resolve(value);
|
|
419
|
-
} else {
|
|
420
|
-
Promise.resolve(value).then(_next, _throw);
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
function _asyncToGenerator(fn) {
|
|
424
|
-
return function () {
|
|
425
|
-
var self = this,
|
|
426
|
-
args = arguments;
|
|
427
|
-
return new Promise(function (resolve, reject) {
|
|
428
|
-
var gen = fn.apply(self, args);
|
|
429
|
-
function _next(value) {
|
|
430
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
431
|
-
}
|
|
432
|
-
function _throw(err) {
|
|
433
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
434
|
-
}
|
|
435
|
-
_next(undefined);
|
|
436
|
-
});
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
|
|
440
61
|
/**
|
|
441
62
|
* Sets the `innerError.message` in an `errors` object at the key
|
|
442
63
|
* defined by `innerError.path`.
|
|
@@ -444,7 +65,7 @@ function _asyncToGenerator(fn) {
|
|
|
444
65
|
* @param {{ path: string, message: string }} innerError A `yup` field error.
|
|
445
66
|
* @returns {Object} The result of setting the new error message onto `errors`.
|
|
446
67
|
*/
|
|
447
|
-
|
|
68
|
+
const setInError = (errors, innerError) => {
|
|
448
69
|
return setIn(errors, innerError.path, innerError.message);
|
|
449
70
|
};
|
|
450
71
|
|
|
@@ -453,7 +74,7 @@ var setInError = function setInError(errors, innerError) {
|
|
|
453
74
|
* value for reducing the `err.inner` array of errors
|
|
454
75
|
* from a `yup~ValidationError`.
|
|
455
76
|
*/
|
|
456
|
-
|
|
77
|
+
const emptyObj = Object.create(null);
|
|
457
78
|
|
|
458
79
|
/**
|
|
459
80
|
* Takes a `yup` validation schema and returns a function that expects
|
|
@@ -465,146 +86,122 @@ var emptyObj = Object.create(null);
|
|
|
465
86
|
* and resolves to either `undefined` or a map of field names to error messages.
|
|
466
87
|
*/
|
|
467
88
|
|
|
468
|
-
|
|
469
|
-
return
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
_context.next = 12;
|
|
481
|
-
break;
|
|
482
|
-
case 5:
|
|
483
|
-
_context.prev = 5;
|
|
484
|
-
_context.t0 = _context["catch"](0);
|
|
485
|
-
if (!_context.t0.inner) {
|
|
486
|
-
_context.next = 11;
|
|
487
|
-
break;
|
|
488
|
-
}
|
|
489
|
-
return _context.abrupt("return", _context.t0.inner.reduce(setInError, emptyObj));
|
|
490
|
-
case 11:
|
|
491
|
-
console.warn('itcase-forms schema.validate error: An error not related to the form occurred during validation. Validation ignored.');
|
|
492
|
-
case 12:
|
|
493
|
-
case "end":
|
|
494
|
-
return _context.stop();
|
|
495
|
-
}
|
|
496
|
-
}, _callee, null, [[0, 5]]);
|
|
497
|
-
}));
|
|
498
|
-
function validate(_x) {
|
|
499
|
-
return _validate.apply(this, arguments);
|
|
89
|
+
const makeValidate = schema => {
|
|
90
|
+
return async function validate(values) {
|
|
91
|
+
try {
|
|
92
|
+
await schema.validate(values, {
|
|
93
|
+
abortEarly: false
|
|
94
|
+
});
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if (error.inner) {
|
|
97
|
+
return error.inner.reduce(setInError, emptyObj);
|
|
98
|
+
} else {
|
|
99
|
+
console.warn('itcase-forms schema.validate error: An error not related to the form occurred during validation. Validation ignored.');
|
|
100
|
+
}
|
|
500
101
|
}
|
|
501
|
-
|
|
502
|
-
}();
|
|
102
|
+
};
|
|
503
103
|
};
|
|
504
104
|
function useYupValidationSchema(schema, language) {
|
|
505
|
-
|
|
506
|
-
return schema && makeValidate(schema);
|
|
507
|
-
}, [schema, language]);
|
|
105
|
+
const validate = useMemo(() => schema && makeValidate(schema), [schema, language]);
|
|
508
106
|
return validate;
|
|
509
107
|
}
|
|
510
108
|
|
|
511
109
|
function FieldWrapperBase(props) {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
110
|
+
const {
|
|
111
|
+
after,
|
|
112
|
+
afterItem,
|
|
113
|
+
before,
|
|
114
|
+
beforeItem,
|
|
115
|
+
children,
|
|
116
|
+
className,
|
|
117
|
+
desc,
|
|
118
|
+
descTextSize,
|
|
119
|
+
descTextColor,
|
|
120
|
+
descTextWidth,
|
|
121
|
+
divider,
|
|
122
|
+
dividerDirection,
|
|
123
|
+
dividerFill,
|
|
124
|
+
dividerSize,
|
|
125
|
+
dividerWidth,
|
|
126
|
+
fieldClassName,
|
|
127
|
+
id,
|
|
128
|
+
inputName,
|
|
129
|
+
inputValue,
|
|
130
|
+
isRequired,
|
|
131
|
+
label,
|
|
132
|
+
labelTextSize,
|
|
133
|
+
labelTextColor,
|
|
134
|
+
labelTextWidth,
|
|
135
|
+
errorMessageTextSize,
|
|
136
|
+
errorMessageTextWeight,
|
|
137
|
+
errorMessageTextColor,
|
|
138
|
+
message,
|
|
139
|
+
messageTextSize,
|
|
140
|
+
messageTextColor,
|
|
141
|
+
messageTextWeight,
|
|
142
|
+
metaActive,
|
|
143
|
+
metaError,
|
|
144
|
+
metaModifiedSinceLastSubmit,
|
|
145
|
+
metaSubmitError,
|
|
146
|
+
metaSubmitFailed,
|
|
147
|
+
metaTouched,
|
|
148
|
+
metaValid,
|
|
149
|
+
set,
|
|
150
|
+
type,
|
|
151
|
+
hideMessage,
|
|
152
|
+
isHidden,
|
|
153
|
+
tag: Tag,
|
|
154
|
+
dataTour,
|
|
155
|
+
showErrorsOnSubmit
|
|
156
|
+
} = props;
|
|
157
|
+
const error = metaError || !metaModifiedSinceLastSubmit && metaSubmitError || false;
|
|
158
|
+
const showError = useMemo(() => {
|
|
559
159
|
if (showErrorsOnSubmit) {
|
|
560
160
|
return metaSubmitFailed && metaTouched && error;
|
|
561
161
|
} else {
|
|
562
162
|
return metaTouched && error;
|
|
563
163
|
}
|
|
564
164
|
}, [showErrorsOnSubmit, metaSubmitFailed, metaTouched, error]);
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
165
|
+
const showValid = useMemo(() => {
|
|
166
|
+
const hasValue = Array.isArray(inputValue) ? inputValue.length : inputValue;
|
|
167
|
+
const isModifiedAfterSubmit = !metaError && metaSubmitError && metaModifiedSinceLastSubmit;
|
|
568
168
|
return hasValue && (metaValid || isModifiedAfterSubmit);
|
|
569
169
|
}, [inputValue, metaValid, metaError, metaSubmitError, metaModifiedSinceLastSubmit]);
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
var fieldClass = useMemo(function () {
|
|
574
|
-
return clsx(fieldClassName, showError && fieldClassName + "_state_error", showValid && fieldClassName + "_state_success", metaActive && fieldClassName + "_state_focus", inputValue && fieldClassName + "_state_filled");
|
|
575
|
-
}, [fieldClassName, showError, showValid, metaActive, inputValue]);
|
|
576
|
-
var sizeClass = useDeviceTargetClass(props, {
|
|
170
|
+
const formFieldClass = useMemo(() => clsx(className, showError && 'form__item_state_error', showValid && 'form__item_state_success', isRequired && 'form__item_state_required', metaActive && 'form__item_state_focus', inputValue && 'form__item_state_filled'), [className, showError, showValid, isRequired, metaActive, inputValue]);
|
|
171
|
+
const fieldClass = useMemo(() => clsx(fieldClassName, showError && `${fieldClassName}_state_error`, showValid && `${fieldClassName}_state_success`, metaActive && `${fieldClassName}_state_focus`, inputValue && `${fieldClassName}_state_filled`), [fieldClassName, showError, showValid, metaActive, inputValue]);
|
|
172
|
+
const sizeClass = useDeviceTargetClass(props, {
|
|
577
173
|
prefix: 'form-field_size_',
|
|
578
174
|
propsKey: 'size'
|
|
579
175
|
});
|
|
580
|
-
|
|
176
|
+
const fillClass = useDeviceTargetClass(props, {
|
|
581
177
|
prefix: 'fill_',
|
|
582
178
|
propsKey: 'fill'
|
|
583
179
|
});
|
|
584
|
-
|
|
180
|
+
const inputFillClass = useDeviceTargetClass(props, {
|
|
585
181
|
prefix: 'fill_',
|
|
586
182
|
propsKey: 'inputFill'
|
|
587
183
|
});
|
|
588
|
-
|
|
184
|
+
const shapeClass = useDeviceTargetClass(props, {
|
|
589
185
|
prefix: 'form-field_shape_',
|
|
590
186
|
propsKey: 'shape'
|
|
591
187
|
});
|
|
592
|
-
|
|
188
|
+
const inputShapeClass = useDeviceTargetClass(props, {
|
|
593
189
|
prefix: 'form-field__item-value_shape_',
|
|
594
190
|
propsKey: 'inputShape'
|
|
595
191
|
});
|
|
596
|
-
|
|
192
|
+
const directionClass = useDeviceTargetClass(props, {
|
|
597
193
|
prefix: 'direction_',
|
|
598
194
|
propsKey: 'direction'
|
|
599
195
|
});
|
|
600
|
-
|
|
196
|
+
const widthClass = useDeviceTargetClass(props, {
|
|
601
197
|
prefix: 'width_',
|
|
602
198
|
propsKey: 'width'
|
|
603
199
|
});
|
|
604
|
-
|
|
605
|
-
formFieldStyles
|
|
200
|
+
const {
|
|
201
|
+
styles: formFieldStyles
|
|
202
|
+
} = useStyles(props);
|
|
606
203
|
return /*#__PURE__*/React.createElement(Tag, {
|
|
607
|
-
className: clsx(formFieldClass, 'form__item', 'form-field', type &&
|
|
204
|
+
className: clsx(formFieldClass, 'form__item', 'form-field', type && `form-field_type_${type}`, set && `form-field_set_${set}`, sizeClass, fillClass, shapeClass, isHidden && `form-field_state_hidden`, directionClass, widthClass),
|
|
608
205
|
"data-tour": dataTour,
|
|
609
206
|
style: formFieldStyles
|
|
610
207
|
}, before, label && /*#__PURE__*/React.createElement("div", {
|
|
@@ -637,7 +234,7 @@ function FieldWrapperBase(props) {
|
|
|
637
234
|
size: errorMessageTextSize,
|
|
638
235
|
textWeight: errorMessageTextWeight,
|
|
639
236
|
textColor: errorMessageTextColor,
|
|
640
|
-
id: inputName
|
|
237
|
+
id: `${inputName}-error`
|
|
641
238
|
}, error), Boolean(message) && !showError && /*#__PURE__*/React.createElement(Text, {
|
|
642
239
|
className: "form-field__message-item form-field__message-item_type_message",
|
|
643
240
|
size: messageTextSize,
|
|
@@ -646,7 +243,7 @@ function FieldWrapperBase(props) {
|
|
|
646
243
|
}, message), Boolean(!showError) && Boolean(!message) && /*#__PURE__*/React.createElement(Text, {
|
|
647
244
|
className: "form-field__message-item form-field__message-item_type_message",
|
|
648
245
|
size: messageTextSize
|
|
649
|
-
},
|
|
246
|
+
}, '\u00A0')), after);
|
|
650
247
|
}
|
|
651
248
|
FieldWrapperBase.defaultProps = {
|
|
652
249
|
tag: 'div',
|
|
@@ -702,12 +299,15 @@ FieldWrapperBase.propTypes = {
|
|
|
702
299
|
type: PropTypes.string
|
|
703
300
|
};
|
|
704
301
|
function FieldWrapper(props) {
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
302
|
+
const {
|
|
303
|
+
inputName
|
|
304
|
+
} = props;
|
|
305
|
+
const {
|
|
306
|
+
change
|
|
307
|
+
} = useForm(); // , mutators
|
|
708
308
|
|
|
709
|
-
useEffect(
|
|
710
|
-
return
|
|
309
|
+
useEffect(() => {
|
|
310
|
+
return () => {
|
|
711
311
|
change(inputName, undefined);
|
|
712
312
|
};
|
|
713
313
|
}, []);
|
|
@@ -737,21 +337,24 @@ FieldWrapper.propTypes = {
|
|
|
737
337
|
showErrorsOnSubmit: PropTypes.bool
|
|
738
338
|
};
|
|
739
339
|
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
340
|
+
const CheckboxField = /*#__PURE__*/React.memo(function CheckboxField(props) {
|
|
341
|
+
const {
|
|
342
|
+
name,
|
|
343
|
+
isRequired,
|
|
344
|
+
onChange,
|
|
345
|
+
fieldProps,
|
|
346
|
+
inputProps,
|
|
347
|
+
classNameGroupItem,
|
|
348
|
+
hideMessage
|
|
349
|
+
} = props;
|
|
748
350
|
return /*#__PURE__*/React.createElement(Field, {
|
|
749
351
|
name: name,
|
|
750
352
|
type: "checkbox"
|
|
751
|
-
},
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
353
|
+
}, ({
|
|
354
|
+
input,
|
|
355
|
+
meta
|
|
356
|
+
}) => {
|
|
357
|
+
const onChangeField = useCallback(event => {
|
|
755
358
|
input.onChange(event);
|
|
756
359
|
if (onChange) {
|
|
757
360
|
onChange(event.target.checked, input.name);
|
|
@@ -795,41 +398,43 @@ CheckboxField.propTypes = {
|
|
|
795
398
|
onChange: PropTypes.func
|
|
796
399
|
};
|
|
797
400
|
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
401
|
+
const ChoiceField = /*#__PURE__*/React.memo(function ChoiceField(props) {
|
|
402
|
+
const {
|
|
403
|
+
options,
|
|
404
|
+
classNameGroupItem,
|
|
405
|
+
fieldProps,
|
|
406
|
+
inputProps,
|
|
407
|
+
isMultiple,
|
|
408
|
+
isRequired,
|
|
409
|
+
initialValue,
|
|
410
|
+
label,
|
|
411
|
+
name,
|
|
412
|
+
messageType,
|
|
413
|
+
hideMessage,
|
|
414
|
+
placeholder
|
|
415
|
+
} = props;
|
|
416
|
+
const {
|
|
417
|
+
change
|
|
418
|
+
} = useForm();
|
|
813
419
|
return /*#__PURE__*/React.createElement(Field, {
|
|
814
420
|
name: name,
|
|
815
421
|
initialValue: initialValue
|
|
816
|
-
},
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
422
|
+
}, ({
|
|
423
|
+
input,
|
|
424
|
+
meta
|
|
425
|
+
}) => {
|
|
426
|
+
const activeOption = useMemo(() => {
|
|
427
|
+
const emptyOption = {
|
|
821
428
|
value: null,
|
|
822
429
|
label: null
|
|
823
430
|
};
|
|
824
431
|
if (input.value) {
|
|
825
|
-
|
|
826
|
-
return option.value === input.value;
|
|
827
|
-
});
|
|
432
|
+
const currentOption = options.find(option => option.value === input.value);
|
|
828
433
|
return currentOption || emptyOption;
|
|
829
434
|
}
|
|
830
435
|
return emptyOption;
|
|
831
436
|
}, [input.value]);
|
|
832
|
-
|
|
437
|
+
const setActiveSegment = useCallback(option => {
|
|
833
438
|
change(name, option.value);
|
|
834
439
|
}, [change]);
|
|
835
440
|
return /*#__PURE__*/React.createElement(FieldWrapper, Object.assign({
|
|
@@ -872,37 +477,38 @@ ChoiceField.propTypes = {
|
|
|
872
477
|
placeholder: PropTypes.string
|
|
873
478
|
};
|
|
874
479
|
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
480
|
+
const CustomField = /*#__PURE__*/React.memo(function CustomField(props) {
|
|
481
|
+
const {
|
|
482
|
+
Component,
|
|
483
|
+
isRequired,
|
|
484
|
+
name,
|
|
485
|
+
fieldProps,
|
|
486
|
+
classNameGroupItem,
|
|
487
|
+
hideMessage
|
|
488
|
+
} = props;
|
|
882
489
|
return /*#__PURE__*/React.createElement(Field, {
|
|
883
490
|
name: name
|
|
884
|
-
},
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
});
|
|
491
|
+
}, ({
|
|
492
|
+
input,
|
|
493
|
+
meta
|
|
494
|
+
}) => /*#__PURE__*/React.createElement(FieldWrapper, Object.assign({
|
|
495
|
+
className: clsx('form-field_type_custom', 'form__item_type_custom', classNameGroupItem),
|
|
496
|
+
fieldClassName: 'form-custom',
|
|
497
|
+
inputName: input.name,
|
|
498
|
+
inputValue: input.value,
|
|
499
|
+
isRequired: isRequired,
|
|
500
|
+
metaActive: meta.active,
|
|
501
|
+
metaError: meta.error,
|
|
502
|
+
metaModifiedSinceLastSubmit: meta.modifiedSinceLastSubmit,
|
|
503
|
+
metaSubmitError: meta.submitError,
|
|
504
|
+
metaSubmitFailed: meta.submitFailed,
|
|
505
|
+
metaTouched: meta.touched,
|
|
506
|
+
metaValid: meta.valid,
|
|
507
|
+
hideMessage: hideMessage
|
|
508
|
+
}, fieldProps), /*#__PURE__*/React.createElement(Component, Object.assign({}, props, {
|
|
509
|
+
input: input,
|
|
510
|
+
meta: meta
|
|
511
|
+
}))));
|
|
906
512
|
});
|
|
907
513
|
CustomField.defaultProps = {
|
|
908
514
|
inputProps: {},
|
|
@@ -915,41 +521,42 @@ CustomField.propTypes = {
|
|
|
915
521
|
inputProps: PropTypes.object
|
|
916
522
|
};
|
|
917
523
|
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
524
|
+
const CodeField = /*#__PURE__*/React.memo(function CodeField(props) {
|
|
525
|
+
const {
|
|
526
|
+
isRequired,
|
|
527
|
+
name,
|
|
528
|
+
fieldProps,
|
|
529
|
+
inputProps,
|
|
530
|
+
classNameGroupItem,
|
|
531
|
+
hideMessage
|
|
532
|
+
} = props;
|
|
925
533
|
return /*#__PURE__*/React.createElement(Field, {
|
|
926
534
|
name: name
|
|
927
|
-
},
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
});
|
|
535
|
+
}, ({
|
|
536
|
+
input,
|
|
537
|
+
meta
|
|
538
|
+
}) => /*#__PURE__*/React.createElement(FieldWrapper, Object.assign({
|
|
539
|
+
className: clsx('form-field_type_code', 'form__item_type_code', classNameGroupItem),
|
|
540
|
+
fieldClassName: 'form-code',
|
|
541
|
+
inputName: input.name,
|
|
542
|
+
inputValue: input.value,
|
|
543
|
+
isRequired: isRequired,
|
|
544
|
+
metaActive: meta.active,
|
|
545
|
+
metaError: meta.error,
|
|
546
|
+
metaModifiedSinceLastSubmit: meta.modifiedSinceLastSubmit,
|
|
547
|
+
metaSubmitError: meta.submitError,
|
|
548
|
+
metaSubmitFailed: meta.submitFailed,
|
|
549
|
+
metaTouched: meta.touched,
|
|
550
|
+
metaValid: meta.valid,
|
|
551
|
+
hideMessage: hideMessage
|
|
552
|
+
}, fieldProps), /*#__PURE__*/React.createElement(Code, Object.assign({
|
|
553
|
+
autoComplete: "nope",
|
|
554
|
+
name: input.name,
|
|
555
|
+
value: input.value,
|
|
556
|
+
onBlur: input.onBlur,
|
|
557
|
+
onChange: input.onChange,
|
|
558
|
+
onFocus: input.onFocus
|
|
559
|
+
}, inputProps))));
|
|
953
560
|
});
|
|
954
561
|
CodeField.defaultProps = {
|
|
955
562
|
inputProps: {},
|
|
@@ -963,28 +570,31 @@ CodeField.propTypes = {
|
|
|
963
570
|
};
|
|
964
571
|
|
|
965
572
|
function DatePickerField(props) {
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
573
|
+
const {
|
|
574
|
+
isRequired,
|
|
575
|
+
fieldProps,
|
|
576
|
+
inputProps,
|
|
577
|
+
datePickerProps,
|
|
578
|
+
name,
|
|
579
|
+
iconSize,
|
|
580
|
+
iconBorder,
|
|
581
|
+
iconBorderHover,
|
|
582
|
+
iconFill,
|
|
583
|
+
iconFillHover,
|
|
584
|
+
iconRevealableShow,
|
|
585
|
+
iconRevealableHide,
|
|
586
|
+
iconShape,
|
|
587
|
+
hideMessage,
|
|
588
|
+
onChange,
|
|
589
|
+
classNameGroupItem
|
|
590
|
+
} = props;
|
|
982
591
|
return /*#__PURE__*/React.createElement(Field, {
|
|
983
592
|
name: name
|
|
984
|
-
},
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
593
|
+
}, ({
|
|
594
|
+
input,
|
|
595
|
+
meta
|
|
596
|
+
}) => {
|
|
597
|
+
const onChangeField = useCallback(value => {
|
|
988
598
|
input.onChange(value);
|
|
989
599
|
if (onChange) {
|
|
990
600
|
onChange(value, input.name);
|
|
@@ -1027,161 +637,78 @@ DatePickerField.propTypes = {
|
|
|
1027
637
|
onChange: PropTypes.func
|
|
1028
638
|
};
|
|
1029
639
|
|
|
1030
|
-
function getFileByURL(
|
|
1031
|
-
|
|
640
|
+
async function getFileByURL(url) {
|
|
641
|
+
try {
|
|
642
|
+
const response = await axios({
|
|
643
|
+
url: `/api/${url}/`,
|
|
644
|
+
responseType: 'blob'
|
|
645
|
+
});
|
|
646
|
+
const blobObject = response.data;
|
|
647
|
+
const dirtyFilename = response.headers['content-disposition']?.split('filename=')[1];
|
|
648
|
+
// Remove double quotes
|
|
649
|
+
let filename = dirtyFilename?.substring(1).slice(0, -1);
|
|
650
|
+
if (!filename) {
|
|
651
|
+
const typeParts = blobObject.type.split('/');
|
|
652
|
+
const fileType = typeParts[typeParts.length - 1];
|
|
653
|
+
filename = `${new Date().getTime()}.${fileType}`;
|
|
654
|
+
}
|
|
655
|
+
return new File([blobObject], filename, {
|
|
656
|
+
type: blobObject.type
|
|
657
|
+
});
|
|
658
|
+
} catch (error) {
|
|
659
|
+
console.log('error: ', error);
|
|
660
|
+
return null;
|
|
661
|
+
}
|
|
1032
662
|
}
|
|
1033
|
-
function
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
});
|
|
1045
|
-
case 3:
|
|
1046
|
-
response = _context3.sent;
|
|
1047
|
-
blobObject = response.data;
|
|
1048
|
-
dirtyFilename = (_response$headers$con = response.headers['content-disposition']) == null ? void 0 : _response$headers$con.split('filename=')[1]; // Remove double quotes
|
|
1049
|
-
filename = dirtyFilename == null ? void 0 : dirtyFilename.substring(1).slice(0, -1);
|
|
1050
|
-
if (!filename) {
|
|
1051
|
-
typeParts = blobObject.type.split('/');
|
|
1052
|
-
fileType = typeParts[typeParts.length - 1];
|
|
1053
|
-
filename = new Date().getTime() + "." + fileType;
|
|
1054
|
-
}
|
|
1055
|
-
return _context3.abrupt("return", new File([blobObject], filename, {
|
|
1056
|
-
type: blobObject.type
|
|
1057
|
-
}));
|
|
1058
|
-
case 11:
|
|
1059
|
-
_context3.prev = 11;
|
|
1060
|
-
_context3.t0 = _context3["catch"](0);
|
|
1061
|
-
console.log('error: ', _context3.t0);
|
|
1062
|
-
return _context3.abrupt("return", null);
|
|
1063
|
-
case 15:
|
|
1064
|
-
case "end":
|
|
1065
|
-
return _context3.stop();
|
|
663
|
+
async function convertToFiles(inputValue, isPreviews) {
|
|
664
|
+
const newFiles = [];
|
|
665
|
+
for await (const value of castArray(inputValue)) {
|
|
666
|
+
let newFile = null;
|
|
667
|
+
|
|
668
|
+
// Download image by url and save as File instance
|
|
669
|
+
const isURL = typeof value === 'string' && value.includes('/');
|
|
670
|
+
if (value.image || isURL) {
|
|
671
|
+
newFile = await getFileByURL(value.image || value);
|
|
672
|
+
if (newFile) {
|
|
673
|
+
setFileDataURL(newFile);
|
|
1066
674
|
}
|
|
1067
|
-
}
|
|
1068
|
-
}));
|
|
1069
|
-
return _getFileByURL.apply(this, arguments);
|
|
1070
|
-
}
|
|
1071
|
-
function convertToFiles(_x2, _x3) {
|
|
1072
|
-
return _convertToFiles.apply(this, arguments);
|
|
1073
|
-
}
|
|
1074
|
-
function _convertToFiles() {
|
|
1075
|
-
_convertToFiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(inputValue, isPreviews) {
|
|
1076
|
-
var newFiles, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, value, newFile, isURL;
|
|
1077
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
1078
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
1079
|
-
case 0:
|
|
1080
|
-
newFiles = [];
|
|
1081
|
-
_iteratorAbruptCompletion = false;
|
|
1082
|
-
_didIteratorError = false;
|
|
1083
|
-
_context4.prev = 3;
|
|
1084
|
-
_iterator = _asyncIterator(castArray(inputValue));
|
|
1085
|
-
case 5:
|
|
1086
|
-
_context4.next = 7;
|
|
1087
|
-
return _iterator.next();
|
|
1088
|
-
case 7:
|
|
1089
|
-
if (!(_iteratorAbruptCompletion = !(_step = _context4.sent).done)) {
|
|
1090
|
-
_context4.next = 21;
|
|
1091
|
-
break;
|
|
1092
|
-
}
|
|
1093
|
-
value = _step.value;
|
|
1094
|
-
newFile = null; // Download image by url and save as File instance
|
|
1095
|
-
isURL = typeof value === 'string' && value.includes('/');
|
|
1096
|
-
if (!(value.image || isURL)) {
|
|
1097
|
-
_context4.next = 16;
|
|
1098
|
-
break;
|
|
1099
|
-
}
|
|
1100
|
-
_context4.next = 14;
|
|
1101
|
-
return getFileByURL(value.image || value);
|
|
1102
|
-
case 14:
|
|
1103
|
-
newFile = _context4.sent;
|
|
1104
|
-
if (newFile) {
|
|
1105
|
-
setFileDataURL(newFile);
|
|
1106
|
-
}
|
|
1107
|
-
case 16:
|
|
1108
|
-
// Convert dataURL to File instance
|
|
1109
|
-
if (value.dataURL) {
|
|
1110
|
-
newFile = createFileFromDataURL(value.name || value.path, value.dataURL);
|
|
1111
|
-
newFile.dataURL = value.dataURL;
|
|
1112
|
-
}
|
|
675
|
+
}
|
|
1113
676
|
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
}
|
|
1120
|
-
newFiles.push(newFile);
|
|
1121
|
-
}
|
|
677
|
+
// Convert dataURL to File instance
|
|
678
|
+
if (value.dataURL) {
|
|
679
|
+
newFile = createFileFromDataURL(value.name || value.path, value.dataURL);
|
|
680
|
+
newFile.dataURL = value.dataURL;
|
|
681
|
+
}
|
|
1122
682
|
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
// }
|
|
1129
|
-
case 18:
|
|
1130
|
-
_iteratorAbruptCompletion = false;
|
|
1131
|
-
_context4.next = 5;
|
|
1132
|
-
break;
|
|
1133
|
-
case 21:
|
|
1134
|
-
_context4.next = 27;
|
|
1135
|
-
break;
|
|
1136
|
-
case 23:
|
|
1137
|
-
_context4.prev = 23;
|
|
1138
|
-
_context4.t0 = _context4["catch"](3);
|
|
1139
|
-
_didIteratorError = true;
|
|
1140
|
-
_iteratorError = _context4.t0;
|
|
1141
|
-
case 27:
|
|
1142
|
-
_context4.prev = 27;
|
|
1143
|
-
_context4.prev = 28;
|
|
1144
|
-
if (!(_iteratorAbruptCompletion && _iterator["return"] != null)) {
|
|
1145
|
-
_context4.next = 32;
|
|
1146
|
-
break;
|
|
1147
|
-
}
|
|
1148
|
-
_context4.next = 32;
|
|
1149
|
-
return _iterator["return"]();
|
|
1150
|
-
case 32:
|
|
1151
|
-
_context4.prev = 32;
|
|
1152
|
-
if (!_didIteratorError) {
|
|
1153
|
-
_context4.next = 35;
|
|
1154
|
-
break;
|
|
1155
|
-
}
|
|
1156
|
-
throw _iteratorError;
|
|
1157
|
-
case 35:
|
|
1158
|
-
return _context4.finish(32);
|
|
1159
|
-
case 36:
|
|
1160
|
-
return _context4.finish(27);
|
|
1161
|
-
case 37:
|
|
1162
|
-
return _context4.abrupt("return", newFiles);
|
|
1163
|
-
case 38:
|
|
1164
|
-
case "end":
|
|
1165
|
-
return _context4.stop();
|
|
683
|
+
// Save new File to state
|
|
684
|
+
if (newFile) {
|
|
685
|
+
newFile.id = value.id;
|
|
686
|
+
if (isPreviews) {
|
|
687
|
+
newFile.preview = URL.createObjectURL(newFile);
|
|
1166
688
|
}
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
689
|
+
newFiles.push(newFile);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// else if (value) {
|
|
693
|
+
// newFiles.push({
|
|
694
|
+
// name: value,
|
|
695
|
+
// error: 'File is unavailable',
|
|
696
|
+
// })
|
|
697
|
+
// }
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
return newFiles;
|
|
1170
701
|
}
|
|
1171
702
|
function setFileDataURL(file, resolve) {
|
|
1172
|
-
resolve = resolve ||
|
|
703
|
+
resolve = resolve || (() => {});
|
|
1173
704
|
// Init reader and save his file
|
|
1174
|
-
|
|
705
|
+
const reader = new FileReader();
|
|
1175
706
|
reader._readedFile = file;
|
|
1176
707
|
|
|
1177
708
|
// Set handlers
|
|
1178
|
-
reader.onabort =
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
reader.onerror = function () {
|
|
1182
|
-
return resolve();
|
|
1183
|
-
};
|
|
1184
|
-
reader.onload = function (event) {
|
|
709
|
+
reader.onabort = () => resolve();
|
|
710
|
+
reader.onerror = () => resolve();
|
|
711
|
+
reader.onload = event => {
|
|
1185
712
|
event.target._readedFile.dataURL = reader.result;
|
|
1186
713
|
resolve();
|
|
1187
714
|
};
|
|
@@ -1192,146 +719,122 @@ function setFileDataURL(file, resolve) {
|
|
|
1192
719
|
resolve();
|
|
1193
720
|
}
|
|
1194
721
|
}
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
dropzoneProps =
|
|
1231
|
-
onAddFiles
|
|
1232
|
-
onDeleteFile
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
var _useState2 = useState(false),
|
|
1237
|
-
fileIsLoading = _useState2[0],
|
|
1238
|
-
setFileIsLoading = _useState2[1];
|
|
722
|
+
const FileInputDropzone = /*#__PURE__*/React.memo(function FileInputDropzone(props) {
|
|
723
|
+
const {
|
|
724
|
+
inputName,
|
|
725
|
+
size,
|
|
726
|
+
className,
|
|
727
|
+
fileErrorText,
|
|
728
|
+
hintTitleTextSize,
|
|
729
|
+
removeThumbTextSize,
|
|
730
|
+
removeThumbTextColor,
|
|
731
|
+
removeThumbTextWeight,
|
|
732
|
+
thumbNameTextSize,
|
|
733
|
+
thumbNameTextColor,
|
|
734
|
+
removeThumbTextHoverColor,
|
|
735
|
+
thumbNameTextWrap,
|
|
736
|
+
thumbNameTextWeight,
|
|
737
|
+
hintTitleTextColor,
|
|
738
|
+
hintTitleTextWrap,
|
|
739
|
+
thumbColumn,
|
|
740
|
+
hintTitleTextWeight,
|
|
741
|
+
hintDescriptionTextSize,
|
|
742
|
+
hintDescriptionTextColor,
|
|
743
|
+
hintDescriptionTextWrap,
|
|
744
|
+
hintDescriptionTextWeight,
|
|
745
|
+
errorMessageTextSize,
|
|
746
|
+
errorMessageTextWeight,
|
|
747
|
+
errorMessageTextColor,
|
|
748
|
+
inputValue,
|
|
749
|
+
maxFiles,
|
|
750
|
+
maxSize,
|
|
751
|
+
removeThumbText,
|
|
752
|
+
hintTitle,
|
|
753
|
+
hintDescription,
|
|
754
|
+
isShowFilename,
|
|
755
|
+
isPreviews,
|
|
756
|
+
loadingText,
|
|
757
|
+
dropzoneProps = {},
|
|
758
|
+
onAddFiles,
|
|
759
|
+
onDeleteFile
|
|
760
|
+
} = props;
|
|
761
|
+
const [fileError, setFileError] = useState('');
|
|
762
|
+
const [fileIsLoading, setFileIsLoading] = useState(false);
|
|
1239
763
|
// State with instances of "File" type
|
|
1240
|
-
|
|
1241
|
-
files = _useState3[0],
|
|
1242
|
-
setFiles = _useState3[1];
|
|
764
|
+
const [files, setFiles] = useState(inputValue ? castArray(inputValue) : []);
|
|
1243
765
|
|
|
1244
766
|
// Save to mobx state
|
|
1245
|
-
|
|
1246
|
-
change
|
|
1247
|
-
|
|
767
|
+
const {
|
|
768
|
+
change
|
|
769
|
+
} = useForm();
|
|
770
|
+
const changeFormState = useCallback(newFiles => {
|
|
1248
771
|
// If max files in dropzone is 1 - return file as it self, else as array of files
|
|
1249
772
|
// ps: for old projects compatibility
|
|
1250
|
-
|
|
773
|
+
const toSave = dropzoneProps.maxFiles == 1 ? newFiles[0] : newFiles;
|
|
1251
774
|
change(inputName, toSave);
|
|
1252
775
|
return toSave;
|
|
1253
776
|
}, [dropzoneProps, change]);
|
|
1254
777
|
|
|
1255
778
|
// Create dropzone options
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
}
|
|
1279
|
-
}, _callee);
|
|
1280
|
-
}));
|
|
1281
|
-
function getFilesFromEvent(_x4) {
|
|
1282
|
-
return _getFilesFromEvent.apply(this, arguments);
|
|
1283
|
-
}
|
|
1284
|
-
return getFilesFromEvent;
|
|
1285
|
-
}(),
|
|
1286
|
-
onDropAccepted: function onDropAccepted(acceptedFiles, event) {
|
|
1287
|
-
// If dropped files has accepted and we need a previews
|
|
1288
|
-
if (isPreviews) {
|
|
1289
|
-
// Add preview to every file
|
|
1290
|
-
acceptedFiles.forEach(function (file) {
|
|
1291
|
-
if (!file.error) {
|
|
1292
|
-
file.preview = URL.createObjectURL(file);
|
|
1293
|
-
}
|
|
1294
|
-
});
|
|
1295
|
-
}
|
|
1296
|
-
// Save to form data (including empty when files are not valid)
|
|
1297
|
-
setFiles(acceptedFiles);
|
|
1298
|
-
setFileError('');
|
|
1299
|
-
|
|
1300
|
-
// Save DataURL for all files
|
|
1301
|
-
var readerPromisesList = acceptedFiles.map(function (file) {
|
|
1302
|
-
return new Promise(function (resolve) {
|
|
1303
|
-
return setFileDataURL(file, resolve);
|
|
1304
|
-
});
|
|
1305
|
-
});
|
|
1306
|
-
// Save files to form values
|
|
1307
|
-
Promise.all(readerPromisesList).then(function () {
|
|
1308
|
-
var filesToSave = changeFormState(acceptedFiles);
|
|
1309
|
-
if (onAddFiles) {
|
|
1310
|
-
onAddFiles(filesToSave, inputName);
|
|
779
|
+
const {
|
|
780
|
+
getRootProps,
|
|
781
|
+
getInputProps
|
|
782
|
+
} = useDropzone({
|
|
783
|
+
maxSize: maxSize || 10485760,
|
|
784
|
+
// 10mb
|
|
785
|
+
maxFiles: maxFiles || 5,
|
|
786
|
+
// accept: { 'image/*': [] },
|
|
787
|
+
...dropzoneProps,
|
|
788
|
+
getFilesFromEvent: async event => {
|
|
789
|
+
const result = await fromEvent(event);
|
|
790
|
+
const newFiles = result.filter(item => item instanceof File);
|
|
791
|
+
// Add exists and new files to accepted(or rejected)
|
|
792
|
+
return [...files, ...newFiles];
|
|
793
|
+
},
|
|
794
|
+
onDropAccepted: (acceptedFiles, event) => {
|
|
795
|
+
// If dropped files has accepted and we need a previews
|
|
796
|
+
if (isPreviews) {
|
|
797
|
+
// Add preview to every file
|
|
798
|
+
acceptedFiles.forEach(file => {
|
|
799
|
+
if (!file.error) {
|
|
800
|
+
file.preview = URL.createObjectURL(file);
|
|
1311
801
|
}
|
|
1312
802
|
});
|
|
1313
|
-
}
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
803
|
+
}
|
|
804
|
+
// Save to form data (including empty when files are not valid)
|
|
805
|
+
setFiles(acceptedFiles);
|
|
806
|
+
setFileError('');
|
|
807
|
+
|
|
808
|
+
// Save DataURL for all files
|
|
809
|
+
const readerPromisesList = acceptedFiles.map(file => {
|
|
810
|
+
return new Promise(resolve => setFileDataURL(file, resolve));
|
|
811
|
+
});
|
|
812
|
+
// Save files to form values
|
|
813
|
+
Promise.all(readerPromisesList).then(() => {
|
|
814
|
+
const filesToSave = changeFormState(acceptedFiles);
|
|
815
|
+
if (onAddFiles) {
|
|
816
|
+
onAddFiles(filesToSave, inputName);
|
|
1324
817
|
}
|
|
818
|
+
});
|
|
819
|
+
},
|
|
820
|
+
onDropRejected: (rejectedFiles, event) => {
|
|
821
|
+
// If dropped files has rejected
|
|
822
|
+
if (rejectedFiles.length) {
|
|
823
|
+
const firstFileError = rejectedFiles[0].errors[0]?.message;
|
|
824
|
+
// Show error
|
|
825
|
+
setFileError(firstFileError || 'Error on adding file');
|
|
826
|
+
} else {
|
|
827
|
+
// Else clean error
|
|
828
|
+
setFileError('');
|
|
1325
829
|
}
|
|
1326
|
-
}
|
|
1327
|
-
|
|
1328
|
-
getInputProps = _useDropzone.getInputProps;
|
|
830
|
+
}
|
|
831
|
+
});
|
|
1329
832
|
|
|
1330
833
|
// Delete file from dropzone
|
|
1331
|
-
|
|
834
|
+
const removeFile = useCallback((event, index) => {
|
|
1332
835
|
event.stopPropagation();
|
|
1333
836
|
event.preventDefault();
|
|
1334
|
-
|
|
837
|
+
const newFiles = [...files];
|
|
1335
838
|
newFiles.splice(index, 1);
|
|
1336
839
|
if (onDeleteFile) {
|
|
1337
840
|
onDeleteFile(files[index], inputName);
|
|
@@ -1340,38 +843,19 @@ var FileInputDropzone = /*#__PURE__*/React.memo(function FileInputDropzone(props
|
|
|
1340
843
|
}, [files, changeFormState, onDeleteFile]);
|
|
1341
844
|
|
|
1342
845
|
//
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
return convertToFiles(newInputValue, isPreviews);
|
|
1352
|
-
case 3:
|
|
1353
|
-
newFiles = _context2.sent;
|
|
1354
|
-
setFileIsLoading(false);
|
|
1355
|
-
setFiles(newFiles);
|
|
1356
|
-
return _context2.abrupt("return", newFiles);
|
|
1357
|
-
case 7:
|
|
1358
|
-
case "end":
|
|
1359
|
-
return _context2.stop();
|
|
1360
|
-
}
|
|
1361
|
-
}, _callee2);
|
|
1362
|
-
}));
|
|
1363
|
-
return function (_x5) {
|
|
1364
|
-
return _ref.apply(this, arguments);
|
|
1365
|
-
};
|
|
1366
|
-
}(), [isPreviews]);
|
|
1367
|
-
useEffect(function () {
|
|
846
|
+
const convertFiledValueAndSaveAsFiles = useCallback(async newInputValue => {
|
|
847
|
+
setFileIsLoading(true);
|
|
848
|
+
const newFiles = await convertToFiles(newInputValue, isPreviews);
|
|
849
|
+
setFileIsLoading(false);
|
|
850
|
+
setFiles(newFiles);
|
|
851
|
+
return newFiles;
|
|
852
|
+
}, [isPreviews]);
|
|
853
|
+
useEffect(() => {
|
|
1368
854
|
// First time convert value to Files and save to local and form state
|
|
1369
|
-
convertFiledValueAndSaveAsFiles(inputValue).then(
|
|
1370
|
-
return changeFormState(newFiles);
|
|
1371
|
-
});
|
|
855
|
+
convertFiledValueAndSaveAsFiles(inputValue).then(newFiles => changeFormState(newFiles));
|
|
1372
856
|
}, []); // eslint-disable-line
|
|
1373
857
|
|
|
1374
|
-
useEffect(
|
|
858
|
+
useEffect(() => {
|
|
1375
859
|
// Everytime convert value to Files and save to local state
|
|
1376
860
|
if (!inputValue) {
|
|
1377
861
|
setFiles([]);
|
|
@@ -1381,116 +865,108 @@ var FileInputDropzone = /*#__PURE__*/React.memo(function FileInputDropzone(props
|
|
|
1381
865
|
// only "inputValue"
|
|
1382
866
|
}, [inputValue]); // eslint-disable-line
|
|
1383
867
|
|
|
1384
|
-
useEffect(
|
|
868
|
+
useEffect(() => {
|
|
1385
869
|
// Make sure to revoke the data uris to avoid memory leaks, will run on unmount
|
|
1386
|
-
return
|
|
1387
|
-
return files.forEach(function (file) {
|
|
1388
|
-
return URL.revokeObjectURL(file == null ? void 0 : file.preview);
|
|
1389
|
-
});
|
|
1390
|
-
};
|
|
870
|
+
return () => files.forEach(file => URL.revokeObjectURL(file?.preview));
|
|
1391
871
|
}, []); // eslint-disable-line
|
|
1392
872
|
|
|
1393
|
-
|
|
873
|
+
const fillClass = useDeviceTargetClass(props, {
|
|
1394
874
|
prefix: 'fill_',
|
|
1395
875
|
propsKey: 'fill'
|
|
1396
876
|
});
|
|
1397
|
-
|
|
877
|
+
const fillHoverClass = useDeviceTargetClass(props, {
|
|
1398
878
|
prefix: 'fill_hover_',
|
|
1399
879
|
propsKey: 'fillHover'
|
|
1400
880
|
});
|
|
1401
|
-
|
|
881
|
+
const borderWidthClass = useDeviceTargetClass(props, {
|
|
1402
882
|
prefix: 'border-width_',
|
|
1403
883
|
propsKey: 'borderWidth'
|
|
1404
884
|
});
|
|
1405
|
-
|
|
885
|
+
const borderColorClass = useDeviceTargetClass(props, {
|
|
1406
886
|
prefix: 'border-color_',
|
|
1407
887
|
propsKey: 'borderColor'
|
|
1408
888
|
});
|
|
1409
|
-
|
|
889
|
+
const borderColorHoverClass = useDeviceTargetClass(props, {
|
|
1410
890
|
prefix: 'border-color_hover_',
|
|
1411
891
|
propsKey: 'borderColorHover'
|
|
1412
892
|
});
|
|
1413
|
-
|
|
893
|
+
const borderTypeClass = useDeviceTargetClass(props, {
|
|
1414
894
|
prefix: 'border_type_',
|
|
1415
895
|
propsKey: 'borderType'
|
|
1416
896
|
});
|
|
1417
|
-
|
|
897
|
+
const shapeClass = useDeviceTargetClass(props, {
|
|
1418
898
|
prefix: 'form-dropzone_shape_',
|
|
1419
899
|
propsKey: 'shape'
|
|
1420
900
|
});
|
|
1421
|
-
|
|
901
|
+
const thumbBorderWidthClass = useDeviceTargetClass(props, {
|
|
1422
902
|
prefix: 'border-width_',
|
|
1423
903
|
propsKey: 'thumbBorderWidth'
|
|
1424
904
|
});
|
|
1425
|
-
|
|
905
|
+
const thumbDirectionClass = useDeviceTargetClass(props, {
|
|
1426
906
|
prefix: 'form-dropzone__thumb_direction_',
|
|
1427
907
|
propsKey: 'thumbDirection'
|
|
1428
908
|
});
|
|
1429
|
-
|
|
909
|
+
const thumbBorderColorClass = useDeviceTargetClass(props, {
|
|
1430
910
|
prefix: 'border-color_',
|
|
1431
911
|
propsKey: 'thumbBorderColor'
|
|
1432
912
|
});
|
|
1433
|
-
|
|
913
|
+
const thumbBorderColorHoverClass = useDeviceTargetClass(props, {
|
|
1434
914
|
prefix: 'border-color_hover_',
|
|
1435
915
|
propsKey: 'thumbBorderColorHover'
|
|
1436
916
|
});
|
|
1437
|
-
|
|
917
|
+
const thumbBorderTypeClass = useDeviceTargetClass(props, {
|
|
1438
918
|
prefix: 'border_type_',
|
|
1439
919
|
propsKey: 'thumbBorderType'
|
|
1440
920
|
});
|
|
1441
921
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", getRootProps({
|
|
1442
|
-
className:
|
|
922
|
+
className: `form-dropzone__dropzone dropzone ${className} thumbColumn form-dropzone__dropzone_size_${size} ${shapeClass}`
|
|
1443
923
|
}), /*#__PURE__*/React.createElement("input", Object.assign({}, getInputProps(), {
|
|
1444
924
|
name: inputName
|
|
1445
925
|
})), /*#__PURE__*/React.createElement("div", {
|
|
1446
|
-
className: clsx('form-dropzone__dropzone-wrapper', thumbColumn &&
|
|
1447
|
-
}, files.map(
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
textColorHover: removeThumbTextHoverColor,
|
|
1491
|
-
className: "form-dropzone__thumb-remove-text"
|
|
1492
|
-
}, removeThumbText || 'Remove')));
|
|
1493
|
-
}), !files.length ? /*#__PURE__*/React.createElement("div", {
|
|
926
|
+
className: clsx('form-dropzone__dropzone-wrapper', thumbColumn && `form-dropzone__dropzone-wrapper_column_${thumbColumn}`, fillClass, fillHoverClass, borderWidthClass, borderColorClass, borderColorHoverClass, borderTypeClass)
|
|
927
|
+
}, files.map((file, i) => /*#__PURE__*/React.createElement("aside", {
|
|
928
|
+
className: clsx('form-dropzone__thumb', fillClass, thumbDirectionClass, thumbBorderWidthClass, thumbBorderColorClass, thumbBorderColorHoverClass, thumbBorderTypeClass),
|
|
929
|
+
key: `${file.id || `${file.name}_${i}` || 'i' + i}`
|
|
930
|
+
}, isPreviews && !file.error && /*#__PURE__*/React.createElement("div", {
|
|
931
|
+
className: "form-dropzone__thumb-image"
|
|
932
|
+
}, /*#__PURE__*/React.createElement("img", {
|
|
933
|
+
className: "form-dropzone__thumb-image-inner",
|
|
934
|
+
src: file.preview || file.image,
|
|
935
|
+
onLoad: () => {
|
|
936
|
+
// Revoke data uri after image is loaded
|
|
937
|
+
URL.revokeObjectURL(file.preview);
|
|
938
|
+
}
|
|
939
|
+
})), file.error && /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Text, {
|
|
940
|
+
size: thumbNameTextSize,
|
|
941
|
+
textColor: thumbNameTextColor,
|
|
942
|
+
textWrap: thumbNameTextWrap,
|
|
943
|
+
textWeight: thumbNameTextWeight
|
|
944
|
+
}, fileErrorText || file.error)), isShowFilename && /*#__PURE__*/React.createElement("div", {
|
|
945
|
+
className: "form-dropzone__thumb-name"
|
|
946
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
947
|
+
size: thumbNameTextSize,
|
|
948
|
+
textColor: thumbNameTextColor,
|
|
949
|
+
textWrap: thumbNameTextWrap,
|
|
950
|
+
textWeight: thumbNameTextWeight,
|
|
951
|
+
className: "form-dropzone__thumb-name-inner"
|
|
952
|
+
}, file.name)), fileIsLoading && /*#__PURE__*/React.createElement("div", {
|
|
953
|
+
className: "form-dropzone__thumb-loader"
|
|
954
|
+
}, /*#__PURE__*/React.createElement(Loader, {
|
|
955
|
+
fill: "surfacePrimary",
|
|
956
|
+
height: "fill",
|
|
957
|
+
itemFill: "surfaceItemAccent",
|
|
958
|
+
set: "simple",
|
|
959
|
+
width: "fill"
|
|
960
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
961
|
+
className: "form-dropzone__thumb-remove",
|
|
962
|
+
onClick: event => removeFile(event, i)
|
|
963
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
964
|
+
size: removeThumbTextSize,
|
|
965
|
+
textColor: removeThumbTextColor,
|
|
966
|
+
textWeight: removeThumbTextWeight,
|
|
967
|
+
textColorHover: removeThumbTextHoverColor,
|
|
968
|
+
className: "form-dropzone__thumb-remove-text"
|
|
969
|
+
}, removeThumbText || 'Remove')))), !files.length ? /*#__PURE__*/React.createElement("div", {
|
|
1494
970
|
className: "form-dropzone__hint"
|
|
1495
971
|
}, /*#__PURE__*/React.createElement(Text, {
|
|
1496
972
|
size: hintTitleTextSize,
|
|
@@ -1543,132 +1019,133 @@ FileInputDropzone.propTypes = {
|
|
|
1543
1019
|
onDeleteFile: PropTypes.func
|
|
1544
1020
|
};
|
|
1545
1021
|
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1022
|
+
const FileInput = /*#__PURE__*/React.memo(function FileInput(props) {
|
|
1023
|
+
const {
|
|
1024
|
+
name,
|
|
1025
|
+
shape,
|
|
1026
|
+
size,
|
|
1027
|
+
borderWidth,
|
|
1028
|
+
borderColor,
|
|
1029
|
+
borderColorHover,
|
|
1030
|
+
borderType,
|
|
1031
|
+
label,
|
|
1032
|
+
thumbBorderWidth,
|
|
1033
|
+
thumbBorderColor,
|
|
1034
|
+
thumbBorderColorHover,
|
|
1035
|
+
thumbBorderType,
|
|
1036
|
+
removeThumbTextHoverColor,
|
|
1037
|
+
labelTextColor,
|
|
1038
|
+
fill,
|
|
1039
|
+
fillHover,
|
|
1040
|
+
className,
|
|
1041
|
+
removeThumbText,
|
|
1042
|
+
thumbNameTextSize,
|
|
1043
|
+
thumbNameTextColor,
|
|
1044
|
+
thumbNameTextWrap,
|
|
1045
|
+
thumbNameTextWeight,
|
|
1046
|
+
removeThumbTextSize,
|
|
1047
|
+
removeThumbTextColor,
|
|
1048
|
+
removeThumbTextWeight,
|
|
1049
|
+
hintTitle,
|
|
1050
|
+
errorMessageTextSize,
|
|
1051
|
+
errorMessageTextWeight,
|
|
1052
|
+
errorMessageTextColor,
|
|
1053
|
+
fieldProps,
|
|
1054
|
+
hintTitleTextSize,
|
|
1055
|
+
hintTitleTextColor,
|
|
1056
|
+
hintTitleTextWrap,
|
|
1057
|
+
hintTitleTextWeight,
|
|
1058
|
+
hintDescriptionTextSize,
|
|
1059
|
+
hintDescriptionTextColor,
|
|
1060
|
+
hintDescriptionTextWrap,
|
|
1061
|
+
hintDescriptionTextWeight,
|
|
1062
|
+
hideMessage,
|
|
1063
|
+
thumbDirection,
|
|
1064
|
+
hintDescription,
|
|
1065
|
+
isShowFilename,
|
|
1066
|
+
fileErrorText,
|
|
1067
|
+
dropzoneProps,
|
|
1068
|
+
maxFiles,
|
|
1069
|
+
maxSize,
|
|
1070
|
+
thumbColumn,
|
|
1071
|
+
isRequired,
|
|
1072
|
+
isPreviews,
|
|
1073
|
+
onAddFiles,
|
|
1074
|
+
onDeleteFile,
|
|
1075
|
+
classNameGroupItem
|
|
1076
|
+
} = props;
|
|
1599
1077
|
return /*#__PURE__*/React.createElement(Field, {
|
|
1600
1078
|
name: name
|
|
1601
|
-
},
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
});
|
|
1079
|
+
}, ({
|
|
1080
|
+
input,
|
|
1081
|
+
meta
|
|
1082
|
+
}) => /*#__PURE__*/React.createElement(FieldWrapper, Object.assign({
|
|
1083
|
+
className: clsx('form-field_type_dropzone', 'form__item_type_dropzone', classNameGroupItem),
|
|
1084
|
+
fieldClassName: "form-dropzone",
|
|
1085
|
+
inputName: input.name,
|
|
1086
|
+
inputValue: input.value,
|
|
1087
|
+
isRequired: isRequired,
|
|
1088
|
+
label: label,
|
|
1089
|
+
labelTextColor: labelTextColor,
|
|
1090
|
+
metaActive: meta.active,
|
|
1091
|
+
metaError: meta.error,
|
|
1092
|
+
metaModifiedSinceLastSubmit: meta.modifiedSinceLastSubmit,
|
|
1093
|
+
metaSubmitError: meta.submitError,
|
|
1094
|
+
metaSubmitFailed: meta.submitFailed,
|
|
1095
|
+
metaTouched: meta.touched,
|
|
1096
|
+
metaValid: meta.valid,
|
|
1097
|
+
hideMessage: hideMessage
|
|
1098
|
+
}, fieldProps), /*#__PURE__*/React.createElement(FileInputDropzone, {
|
|
1099
|
+
dropzoneProps: dropzoneProps,
|
|
1100
|
+
hintDescription: hintDescription,
|
|
1101
|
+
hintTitle: hintTitle,
|
|
1102
|
+
borderWidth: borderWidth,
|
|
1103
|
+
borderColor: borderColor,
|
|
1104
|
+
borderColorHover: borderColorHover,
|
|
1105
|
+
borderType: borderType,
|
|
1106
|
+
thumbBorderWidth: thumbBorderWidth,
|
|
1107
|
+
thumbBorderColor: thumbBorderColor,
|
|
1108
|
+
thumbBorderColorHover: thumbBorderColorHover,
|
|
1109
|
+
thumbBorderType: thumbBorderType,
|
|
1110
|
+
fileErrorText: fileErrorText,
|
|
1111
|
+
fill: fill,
|
|
1112
|
+
size: size,
|
|
1113
|
+
maxFiles: maxFiles,
|
|
1114
|
+
maxSize: maxSize,
|
|
1115
|
+
removeThumbTextHoverColor: removeThumbTextHoverColor,
|
|
1116
|
+
fillHover: fillHover,
|
|
1117
|
+
className: className,
|
|
1118
|
+
thumbColumn: thumbColumn,
|
|
1119
|
+
thumbDirection: thumbDirection,
|
|
1120
|
+
inputName: input.name,
|
|
1121
|
+
inputValue: input.value,
|
|
1122
|
+
thumbNameTextSize: thumbNameTextSize,
|
|
1123
|
+
thumbNameTextColor: thumbNameTextColor,
|
|
1124
|
+
thumbNameTextWrap: thumbNameTextWrap,
|
|
1125
|
+
thumbNameTextWeight: thumbNameTextWeight,
|
|
1126
|
+
hintTitleTextSize: hintTitleTextSize,
|
|
1127
|
+
hintTitleTextColor: hintTitleTextColor,
|
|
1128
|
+
hintTitleTextWrap: hintTitleTextWrap,
|
|
1129
|
+
hintTitleTextWeight: hintTitleTextWeight,
|
|
1130
|
+
removeThumbTextSize: removeThumbTextSize,
|
|
1131
|
+
removeThumbTextColor: removeThumbTextColor,
|
|
1132
|
+
removeThumbTextWeight: removeThumbTextWeight,
|
|
1133
|
+
hintDescriptionTextSize: hintDescriptionTextSize,
|
|
1134
|
+
hintDescriptionTextColor: hintDescriptionTextColor,
|
|
1135
|
+
hintDescriptionTextWrap: hintDescriptionTextWrap,
|
|
1136
|
+
hintDescriptionTextWeight: hintDescriptionTextWeight,
|
|
1137
|
+
errorMessageTextSize: errorMessageTextSize,
|
|
1138
|
+
errorMessageWeight: errorMessageTextWeight,
|
|
1139
|
+
errorMessageTextColor: errorMessageTextColor,
|
|
1140
|
+
isPreviews: isPreviews,
|
|
1141
|
+
shape: shape,
|
|
1142
|
+
isShowFilename: isShowFilename,
|
|
1143
|
+
metaError: meta.error,
|
|
1144
|
+
metaTouched: meta.touched,
|
|
1145
|
+
removeThumbText: removeThumbText,
|
|
1146
|
+
onAddFiles: onAddFiles,
|
|
1147
|
+
onDeleteFile: onDeleteFile
|
|
1148
|
+
})));
|
|
1672
1149
|
});
|
|
1673
1150
|
FileInput.defaultProps = {
|
|
1674
1151
|
errorMessageTextSize: 's',
|
|
@@ -1695,33 +1172,36 @@ FileInput.propTypes = {
|
|
|
1695
1172
|
onDeleteFile: PropTypes.func
|
|
1696
1173
|
};
|
|
1697
1174
|
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1175
|
+
const Group = /*#__PURE__*/React.memo(function Group(props) {
|
|
1176
|
+
const {
|
|
1177
|
+
after,
|
|
1178
|
+
before,
|
|
1179
|
+
className,
|
|
1180
|
+
label,
|
|
1181
|
+
labelTextColor,
|
|
1182
|
+
labelTextSize,
|
|
1183
|
+
labelTextWeight,
|
|
1184
|
+
message,
|
|
1185
|
+
errorMessageTextSize,
|
|
1186
|
+
errorMessageTextWeight,
|
|
1187
|
+
errorMessageTextColor,
|
|
1188
|
+
messageTextSize,
|
|
1189
|
+
messageTextWeight,
|
|
1190
|
+
messageTextColor,
|
|
1191
|
+
children,
|
|
1192
|
+
dataTour,
|
|
1193
|
+
hideMessage,
|
|
1194
|
+
name,
|
|
1195
|
+
showErrorsOnSubmit
|
|
1196
|
+
} = props;
|
|
1718
1197
|
return /*#__PURE__*/React.createElement(Field, {
|
|
1719
1198
|
name: name
|
|
1720
|
-
},
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1199
|
+
}, ({
|
|
1200
|
+
input,
|
|
1201
|
+
meta
|
|
1202
|
+
}) => {
|
|
1203
|
+
const error = meta.error || !meta.modifiedSinceLastSubmit && meta.submitError || false;
|
|
1204
|
+
const showError = useMemo(() => {
|
|
1725
1205
|
if (showErrorsOnSubmit) {
|
|
1726
1206
|
return meta.submitFailed && meta.touched && error;
|
|
1727
1207
|
} else {
|
|
@@ -1746,7 +1226,7 @@ var Group = /*#__PURE__*/React.memo(function Group(props) {
|
|
|
1746
1226
|
size: errorMessageTextSize,
|
|
1747
1227
|
textWeight: errorMessageTextWeight,
|
|
1748
1228
|
textColor: errorMessageTextColor,
|
|
1749
|
-
id: name
|
|
1229
|
+
id: `${name}-error`
|
|
1750
1230
|
}, error), Boolean(message) && !showError && /*#__PURE__*/React.createElement(Text, {
|
|
1751
1231
|
className: "form__group-message",
|
|
1752
1232
|
size: messageTextSize,
|
|
@@ -1755,7 +1235,7 @@ var Group = /*#__PURE__*/React.memo(function Group(props) {
|
|
|
1755
1235
|
}, message), Boolean(!showError) && Boolean(!message) && /*#__PURE__*/React.createElement(Text, {
|
|
1756
1236
|
className: "form__group-message",
|
|
1757
1237
|
size: messageTextSize
|
|
1758
|
-
},
|
|
1238
|
+
}, '\u00A0')));
|
|
1759
1239
|
});
|
|
1760
1240
|
});
|
|
1761
1241
|
Group.defaultProps = {
|
|
@@ -1774,48 +1254,47 @@ Group.propTypes = {
|
|
|
1774
1254
|
inputProps: PropTypes.object
|
|
1775
1255
|
};
|
|
1776
1256
|
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1257
|
+
const InputField = /*#__PURE__*/React.memo(function InputField(props) {
|
|
1258
|
+
const {
|
|
1259
|
+
isPassword,
|
|
1260
|
+
isRequired,
|
|
1261
|
+
fieldProps,
|
|
1262
|
+
inputProps,
|
|
1263
|
+
isRevealable,
|
|
1264
|
+
name,
|
|
1265
|
+
parse,
|
|
1266
|
+
iconSize,
|
|
1267
|
+
iconBorder,
|
|
1268
|
+
iconBorderHover,
|
|
1269
|
+
iconFill,
|
|
1270
|
+
iconFillHover,
|
|
1271
|
+
iconRevealableShow,
|
|
1272
|
+
iconRevealableHide,
|
|
1273
|
+
iconShape,
|
|
1274
|
+
hideMessage,
|
|
1275
|
+
onChange,
|
|
1276
|
+
classNameGroupItem
|
|
1277
|
+
} = props;
|
|
1278
|
+
const [isRevealed, setIsRevealed] = useState(false);
|
|
1279
|
+
const inputType = useMemo(() => {
|
|
1800
1280
|
if (isPassword) {
|
|
1801
1281
|
return isRevealed ? 'text' : 'password';
|
|
1802
1282
|
} else {
|
|
1803
1283
|
return 'text';
|
|
1804
1284
|
}
|
|
1805
1285
|
}, [isRevealed, isPassword]);
|
|
1806
|
-
|
|
1286
|
+
const revealeHandler = useCallback(e => {
|
|
1807
1287
|
e.preventDefault();
|
|
1808
|
-
setIsRevealed(
|
|
1809
|
-
return !prev;
|
|
1810
|
-
});
|
|
1288
|
+
setIsRevealed(prev => !prev);
|
|
1811
1289
|
}, [setIsRevealed]);
|
|
1812
1290
|
return /*#__PURE__*/React.createElement(Field, {
|
|
1813
1291
|
name: name,
|
|
1814
1292
|
parse: parse
|
|
1815
|
-
},
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1293
|
+
}, ({
|
|
1294
|
+
input,
|
|
1295
|
+
meta
|
|
1296
|
+
}) => {
|
|
1297
|
+
const onChangeField = useCallback(event => {
|
|
1819
1298
|
input.onChange(event);
|
|
1820
1299
|
if (onChange) {
|
|
1821
1300
|
onChange(event.target.value, input.name);
|
|
@@ -1871,11 +1350,13 @@ InputField.propTypes = {
|
|
|
1871
1350
|
};
|
|
1872
1351
|
|
|
1873
1352
|
function RadioGroupItem(props) {
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1353
|
+
const {
|
|
1354
|
+
input,
|
|
1355
|
+
option,
|
|
1356
|
+
onChange,
|
|
1357
|
+
inputProps
|
|
1358
|
+
} = props;
|
|
1359
|
+
const onChangeField = useCallback(event => {
|
|
1879
1360
|
if (event.target.checked) {
|
|
1880
1361
|
onChange(option.value);
|
|
1881
1362
|
}
|
|
@@ -1909,12 +1390,12 @@ RadioGroupItem.propTypes = {
|
|
|
1909
1390
|
};
|
|
1910
1391
|
|
|
1911
1392
|
function RadioGroupInput(props) {
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1393
|
+
const {
|
|
1394
|
+
input,
|
|
1395
|
+
value,
|
|
1396
|
+
onChange
|
|
1397
|
+
} = props;
|
|
1398
|
+
const onChangeField = useCallback(event => onChange(event.target.value), [onChange]);
|
|
1918
1399
|
return /*#__PURE__*/React.createElement(Input, Object.assign({
|
|
1919
1400
|
autoComplete: "nope",
|
|
1920
1401
|
name: input.name,
|
|
@@ -1932,29 +1413,25 @@ RadioGroupInput.propTypes = {
|
|
|
1932
1413
|
};
|
|
1933
1414
|
|
|
1934
1415
|
function RadioGroupList(props) {
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
setEditableValue = _useState[1];
|
|
1951
|
-
useEffect(function () {
|
|
1416
|
+
const {
|
|
1417
|
+
input,
|
|
1418
|
+
options,
|
|
1419
|
+
editableProps,
|
|
1420
|
+
onChange,
|
|
1421
|
+
inputProps
|
|
1422
|
+
} = props;
|
|
1423
|
+
const [editableValue, setEditableValue] = useState(() => {
|
|
1424
|
+
const isRadioValue = options.find(option => option.value === input.value);
|
|
1425
|
+
if (!isRadioValue) {
|
|
1426
|
+
return input.value;
|
|
1427
|
+
}
|
|
1428
|
+
return '';
|
|
1429
|
+
});
|
|
1430
|
+
useEffect(() => {
|
|
1952
1431
|
// When a new value from outside enters the form
|
|
1953
1432
|
if (input.value) {
|
|
1954
1433
|
// Check value for radio type
|
|
1955
|
-
|
|
1956
|
-
return option.value === input.value && !option.editable;
|
|
1957
|
-
});
|
|
1434
|
+
const isRadioValue = options.find(option => option.value === input.value && !option.editable);
|
|
1958
1435
|
// If new value not in radio list - set to editable input
|
|
1959
1436
|
setEditableValue(isRadioValue ? '' : input.value);
|
|
1960
1437
|
} else {
|
|
@@ -1964,7 +1441,7 @@ function RadioGroupList(props) {
|
|
|
1964
1441
|
}, [input.value]);
|
|
1965
1442
|
|
|
1966
1443
|
// Callback for value changes
|
|
1967
|
-
|
|
1444
|
+
const onChangeSomeInput = useCallback(value => {
|
|
1968
1445
|
// Save to form values
|
|
1969
1446
|
input.onChange(value);
|
|
1970
1447
|
if (onChange) {
|
|
@@ -1974,33 +1451,31 @@ function RadioGroupList(props) {
|
|
|
1974
1451
|
}, [input, onChange]);
|
|
1975
1452
|
|
|
1976
1453
|
// Handle for radio inputs
|
|
1977
|
-
|
|
1454
|
+
const onChangeRadio = useCallback(value => {
|
|
1978
1455
|
setEditableValue('');
|
|
1979
1456
|
onChangeSomeInput(value);
|
|
1980
1457
|
}, [onChangeSomeInput]);
|
|
1981
1458
|
|
|
1982
1459
|
// Handle for text input
|
|
1983
|
-
|
|
1460
|
+
const onChangeEditable = useCallback(value => {
|
|
1984
1461
|
setEditableValue(value);
|
|
1985
1462
|
onChangeSomeInput(value);
|
|
1986
1463
|
}, [onChangeSomeInput]);
|
|
1987
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, options.map(
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
});
|
|
2003
|
-
}));
|
|
1464
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, options.map(option => option.editable ? /*#__PURE__*/React.createElement(RadioGroupInput, {
|
|
1465
|
+
key: option.label,
|
|
1466
|
+
input: input,
|
|
1467
|
+
value: editableValue,
|
|
1468
|
+
option: option,
|
|
1469
|
+
onChange: onChangeEditable,
|
|
1470
|
+
editableProps: editableProps,
|
|
1471
|
+
inputProps: inputProps
|
|
1472
|
+
}) : /*#__PURE__*/React.createElement(RadioGroupItem, {
|
|
1473
|
+
key: option.value,
|
|
1474
|
+
input: input,
|
|
1475
|
+
option: option,
|
|
1476
|
+
onChange: onChangeRadio,
|
|
1477
|
+
inputProps: inputProps
|
|
1478
|
+
})));
|
|
2004
1479
|
}
|
|
2005
1480
|
RadioGroupList.propTypes = {
|
|
2006
1481
|
editableProps: PropTypes.object,
|
|
@@ -2010,42 +1485,43 @@ RadioGroupList.propTypes = {
|
|
|
2010
1485
|
options: PropTypes.object
|
|
2011
1486
|
};
|
|
2012
1487
|
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
1488
|
+
const RadioGroup = /*#__PURE__*/React.memo(function RadioGroup(props) {
|
|
1489
|
+
const {
|
|
1490
|
+
isRequired,
|
|
1491
|
+
name,
|
|
1492
|
+
options,
|
|
1493
|
+
fieldProps,
|
|
1494
|
+
editableProps,
|
|
1495
|
+
inputProps,
|
|
1496
|
+
onChange,
|
|
1497
|
+
hideMessage
|
|
1498
|
+
} = props;
|
|
2022
1499
|
return /*#__PURE__*/React.createElement(Field, {
|
|
2023
1500
|
name: name
|
|
2024
|
-
},
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
});
|
|
1501
|
+
}, ({
|
|
1502
|
+
input,
|
|
1503
|
+
meta
|
|
1504
|
+
}) => /*#__PURE__*/React.createElement(FieldWrapper, Object.assign({
|
|
1505
|
+
className: "form__item_type_radio",
|
|
1506
|
+
fieldClassName: 'form-radio',
|
|
1507
|
+
inputName: input.name,
|
|
1508
|
+
inputValue: input.value || '',
|
|
1509
|
+
isRequired: isRequired,
|
|
1510
|
+
metaActive: meta.active,
|
|
1511
|
+
metaError: meta.error,
|
|
1512
|
+
metaModifiedSinceLastSubmit: meta.modifiedSinceLastSubmit,
|
|
1513
|
+
metaSubmitError: meta.submitError,
|
|
1514
|
+
metaSubmitFailed: meta.submitFailed,
|
|
1515
|
+
metaTouched: meta.touched,
|
|
1516
|
+
metaValid: meta.valid,
|
|
1517
|
+
hideMessage: hideMessage
|
|
1518
|
+
}, fieldProps), /*#__PURE__*/React.createElement(RadioGroupList, {
|
|
1519
|
+
input: input,
|
|
1520
|
+
options: options,
|
|
1521
|
+
onChange: onChange,
|
|
1522
|
+
editableProps: editableProps,
|
|
1523
|
+
inputProps: inputProps
|
|
1524
|
+
})));
|
|
2049
1525
|
});
|
|
2050
1526
|
RadioGroup.defaultProps = {
|
|
2051
1527
|
fieldProps: {},
|
|
@@ -2065,33 +1541,35 @@ RadioGroup.propTypes = {
|
|
|
2065
1541
|
|
|
2066
1542
|
// const SegmentedField = React.memo(
|
|
2067
1543
|
function SegmentedField(props) {
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
1544
|
+
const {
|
|
1545
|
+
options,
|
|
1546
|
+
isRequired,
|
|
1547
|
+
name,
|
|
1548
|
+
fieldProps,
|
|
1549
|
+
inputProps,
|
|
1550
|
+
hideMessage
|
|
1551
|
+
} = props;
|
|
1552
|
+
const {
|
|
1553
|
+
change
|
|
1554
|
+
} = useForm();
|
|
2076
1555
|
return /*#__PURE__*/React.createElement(Field, {
|
|
2077
1556
|
name: name
|
|
2078
|
-
},
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
1557
|
+
}, ({
|
|
1558
|
+
input,
|
|
1559
|
+
meta
|
|
1560
|
+
}) => {
|
|
1561
|
+
const activeOption = useMemo(() => {
|
|
1562
|
+
const emptyOption = {
|
|
2083
1563
|
value: null,
|
|
2084
1564
|
label: null
|
|
2085
1565
|
};
|
|
2086
1566
|
if (input.value) {
|
|
2087
|
-
|
|
2088
|
-
return option.value === input.value;
|
|
2089
|
-
});
|
|
1567
|
+
const currentOption = options.find(option => option.value === input.value);
|
|
2090
1568
|
return currentOption || emptyOption;
|
|
2091
1569
|
}
|
|
2092
1570
|
return emptyOption;
|
|
2093
1571
|
}, [input.value]);
|
|
2094
|
-
|
|
1572
|
+
const setActiveSegment = useCallback(option => {
|
|
2095
1573
|
change(name, option.value);
|
|
2096
1574
|
}, [change]);
|
|
2097
1575
|
return /*#__PURE__*/React.createElement(FieldWrapper, Object.assign({
|
|
@@ -2130,12 +1608,12 @@ SegmentedField.propTypes = {
|
|
|
2130
1608
|
};
|
|
2131
1609
|
|
|
2132
1610
|
function getDefaultValue(options, selectValue) {
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
options.forEach(
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
1611
|
+
const selectValues = Array.isArray(selectValue) ? selectValue : [selectValue];
|
|
1612
|
+
let result = [];
|
|
1613
|
+
options.forEach(item => {
|
|
1614
|
+
const isValue = selectValues.includes(item.value);
|
|
1615
|
+
const isLabel = selectValues.includes(item.label);
|
|
1616
|
+
let childOptions = [];
|
|
2139
1617
|
if (item.options) {
|
|
2140
1618
|
childOptions = getDefaultValue(item.options, selectValue);
|
|
2141
1619
|
}
|
|
@@ -2147,35 +1625,35 @@ function getDefaultValue(options, selectValue) {
|
|
|
2147
1625
|
});
|
|
2148
1626
|
return result;
|
|
2149
1627
|
}
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
1628
|
+
const SelectField = /*#__PURE__*/React.memo(function SelectField(props) {
|
|
1629
|
+
const {
|
|
1630
|
+
isRequired,
|
|
1631
|
+
key,
|
|
1632
|
+
name,
|
|
1633
|
+
options,
|
|
1634
|
+
fieldProps,
|
|
1635
|
+
selectProps,
|
|
1636
|
+
selectRef,
|
|
1637
|
+
onChange,
|
|
1638
|
+
classNameGroupItem,
|
|
1639
|
+
hideMessage
|
|
1640
|
+
} = props;
|
|
2161
1641
|
return /*#__PURE__*/React.createElement(Field, {
|
|
2162
1642
|
name: name
|
|
2163
|
-
},
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
1643
|
+
}, ({
|
|
1644
|
+
input,
|
|
1645
|
+
meta
|
|
1646
|
+
}) => {
|
|
1647
|
+
const onChangeField = useCallback(value => {
|
|
2167
1648
|
input.onChange(value);
|
|
2168
1649
|
if (onChange) {
|
|
2169
1650
|
onChange(value, input.name);
|
|
2170
1651
|
}
|
|
2171
1652
|
}, [onChange]);
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
var _input$value;
|
|
2177
|
-
var optionsValues = getDefaultValue(options, input.value);
|
|
2178
|
-
if (!optionsValues.length && (_input$value = input.value) != null && _input$value.length) {
|
|
1653
|
+
const [selectedOptions, setSelectedOptions] = useState(null);
|
|
1654
|
+
const defaultValue = useMemo(() => {
|
|
1655
|
+
const optionsValues = getDefaultValue(options, input.value);
|
|
1656
|
+
if (!optionsValues.length && input.value?.length) {
|
|
2179
1657
|
optionsValues.push({
|
|
2180
1658
|
value: input.value,
|
|
2181
1659
|
label: input.value
|
|
@@ -2183,13 +1661,9 @@ var SelectField = /*#__PURE__*/React.memo(function SelectField(props) {
|
|
|
2183
1661
|
}
|
|
2184
1662
|
return optionsValues;
|
|
2185
1663
|
}, [input.value]);
|
|
2186
|
-
useEffect(
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
var onChangeValue = useCallback(function (option, actionMeta) {
|
|
2190
|
-
var value = Array.isArray(option) ? option.map(function (o) {
|
|
2191
|
-
return o.value;
|
|
2192
|
-
}) : (option == null ? void 0 : option.value) || null;
|
|
1664
|
+
useEffect(() => setSelectedOptions(defaultValue), [defaultValue]);
|
|
1665
|
+
const onChangeValue = useCallback((option, actionMeta) => {
|
|
1666
|
+
const value = Array.isArray(option) ? option.map(o => o.value) : option?.value || null;
|
|
2193
1667
|
setSelectedOptions(option);
|
|
2194
1668
|
onChangeField(value);
|
|
2195
1669
|
}, [onChangeField]);
|
|
@@ -2209,7 +1683,7 @@ var SelectField = /*#__PURE__*/React.memo(function SelectField(props) {
|
|
|
2209
1683
|
hideMessage: hideMessage
|
|
2210
1684
|
}, fieldProps), /*#__PURE__*/React.createElement(Select, Object.assign({
|
|
2211
1685
|
className: "form-select-item",
|
|
2212
|
-
instanceId:
|
|
1686
|
+
instanceId: `id_${input.name}`,
|
|
2213
1687
|
value: selectedOptions,
|
|
2214
1688
|
onChange: onChangeValue,
|
|
2215
1689
|
options: options,
|
|
@@ -2228,21 +1702,24 @@ SelectField.propTypes = {
|
|
|
2228
1702
|
onChange: PropTypes.func
|
|
2229
1703
|
};
|
|
2230
1704
|
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
1705
|
+
const SwitchField = /*#__PURE__*/React.memo(function SwitchField(props) {
|
|
1706
|
+
const {
|
|
1707
|
+
name,
|
|
1708
|
+
isRequired,
|
|
1709
|
+
onChange,
|
|
1710
|
+
fieldProps,
|
|
1711
|
+
inputProps,
|
|
1712
|
+
classNameGroupItem,
|
|
1713
|
+
hideMessage
|
|
1714
|
+
} = props;
|
|
2239
1715
|
return /*#__PURE__*/React.createElement(Field, {
|
|
2240
1716
|
name: name,
|
|
2241
1717
|
type: "checkbox"
|
|
2242
|
-
},
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
1718
|
+
}, ({
|
|
1719
|
+
input,
|
|
1720
|
+
meta
|
|
1721
|
+
}) => {
|
|
1722
|
+
const onChangeField = useCallback(event => {
|
|
2246
1723
|
input.onChange(event);
|
|
2247
1724
|
if (onChange) {
|
|
2248
1725
|
onChange(event.target.checked, input.name);
|
|
@@ -2286,41 +1763,42 @@ SwitchField.propTypes = {
|
|
|
2286
1763
|
onChange: PropTypes.func
|
|
2287
1764
|
};
|
|
2288
1765
|
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
1766
|
+
const TextareaField = /*#__PURE__*/React.memo(function TextareaField(props) {
|
|
1767
|
+
const {
|
|
1768
|
+
isRequired,
|
|
1769
|
+
name,
|
|
1770
|
+
fieldProps,
|
|
1771
|
+
inputProps,
|
|
1772
|
+
classNameGroupItem,
|
|
1773
|
+
hideMessage
|
|
1774
|
+
} = props;
|
|
2296
1775
|
return /*#__PURE__*/React.createElement(Field, {
|
|
2297
1776
|
name: name
|
|
2298
|
-
},
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
});
|
|
1777
|
+
}, ({
|
|
1778
|
+
input,
|
|
1779
|
+
meta
|
|
1780
|
+
}) => /*#__PURE__*/React.createElement(FieldWrapper, Object.assign({
|
|
1781
|
+
className: clsx('form-field_type_textarea', 'form__item_type_textarea', classNameGroupItem),
|
|
1782
|
+
fieldClassName: 'form-textarea',
|
|
1783
|
+
inputName: input.name,
|
|
1784
|
+
inputValue: input.value,
|
|
1785
|
+
isRequired: isRequired,
|
|
1786
|
+
metaActive: meta.active,
|
|
1787
|
+
metaError: meta.error,
|
|
1788
|
+
metaModifiedSinceLastSubmit: meta.modifiedSinceLastSubmit,
|
|
1789
|
+
metaSubmitError: meta.submitError,
|
|
1790
|
+
metaSubmitFailed: meta.submitFailed,
|
|
1791
|
+
metaTouched: meta.touched,
|
|
1792
|
+
metaValid: meta.valid,
|
|
1793
|
+
hideMessage: hideMessage
|
|
1794
|
+
}, fieldProps), /*#__PURE__*/React.createElement(Textarea, Object.assign({
|
|
1795
|
+
autoComplete: "nope",
|
|
1796
|
+
name: input.name,
|
|
1797
|
+
value: input.value,
|
|
1798
|
+
onBlur: input.onBlur,
|
|
1799
|
+
onChange: input.onChange,
|
|
1800
|
+
onFocus: input.onFocus
|
|
1801
|
+
}, inputProps))));
|
|
2324
1802
|
});
|
|
2325
1803
|
TextareaField.defaultProps = {
|
|
2326
1804
|
inputProps: {},
|
|
@@ -2333,32 +1811,32 @@ TextareaField.propTypes = {
|
|
|
2333
1811
|
inputProps: PropTypes.object
|
|
2334
1812
|
};
|
|
2335
1813
|
|
|
2336
|
-
|
|
2337
|
-
|
|
1814
|
+
const focusOnError = (formElementsList, errors) => {
|
|
1815
|
+
const selectsIds = Object.keys(errors).map(fieldName => {
|
|
2338
1816
|
if (fieldName === FORM_ERROR) {
|
|
2339
1817
|
// TODO: get from somewhere
|
|
2340
1818
|
return 'notification__item_status_error';
|
|
2341
1819
|
}
|
|
2342
|
-
return
|
|
1820
|
+
return `react-select-id_${fieldName}-input`;
|
|
2343
1821
|
});
|
|
2344
|
-
|
|
1822
|
+
const errorFieldElement = formElementsList.find(element => {
|
|
2345
1823
|
if (element.name) {
|
|
2346
1824
|
return getIn(errors, element.name);
|
|
2347
1825
|
} else {
|
|
2348
1826
|
return selectsIds.includes(element.id);
|
|
2349
1827
|
}
|
|
2350
1828
|
});
|
|
2351
|
-
|
|
1829
|
+
const errorsList = Object.keys(errors);
|
|
2352
1830
|
if (!errorFieldElement && errorsList.length) {
|
|
2353
|
-
|
|
1831
|
+
let errorElement;
|
|
2354
1832
|
try {
|
|
2355
|
-
|
|
1833
|
+
const fieldName = errorsList[0];
|
|
2356
1834
|
if (fieldName === FORM_ERROR) {
|
|
2357
1835
|
errorElement = document.querySelector('notification__item_status_error');
|
|
2358
1836
|
} else {
|
|
2359
|
-
errorElement = document.querySelector(
|
|
1837
|
+
errorElement = document.querySelector(`#${fieldName}-error`);
|
|
2360
1838
|
if (!errorElement) {
|
|
2361
|
-
errorElement = document.querySelector(
|
|
1839
|
+
errorElement = document.querySelector(`#id_${fieldName}`);
|
|
2362
1840
|
}
|
|
2363
1841
|
}
|
|
2364
1842
|
} catch (err) {
|
|
@@ -2380,12 +1858,11 @@ var focusOnError = function focusOnError(formElementsList, errors) {
|
|
|
2380
1858
|
}
|
|
2381
1859
|
return null;
|
|
2382
1860
|
};
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
var fieldError = data.error;
|
|
1861
|
+
const focusOnErrorDecorator = createDecorator(null, focusOnError);
|
|
1862
|
+
const setErrorsMutator = (args, state) => {
|
|
1863
|
+
const [fieldName, data] = args;
|
|
1864
|
+
const submitError = data.submitError;
|
|
1865
|
+
const fieldError = data.error;
|
|
2389
1866
|
if (fieldName === 'non_field_errors') {
|
|
2390
1867
|
// state.formState.invalid = true
|
|
2391
1868
|
// state.formState.valid = false
|
|
@@ -2393,15 +1870,17 @@ var setErrorsMutator = function setErrorsMutator(args, state) {
|
|
|
2393
1870
|
state.formState.submitError = submitError;
|
|
2394
1871
|
} else if (fieldName in state.fields) {
|
|
2395
1872
|
if (fieldError) {
|
|
2396
|
-
|
|
2397
|
-
|
|
1873
|
+
const errorsState = Object.assign({}, state.formState.errors, {
|
|
1874
|
+
[fieldName]: fieldError
|
|
1875
|
+
});
|
|
2398
1876
|
state.fields[fieldName].touched = true;
|
|
2399
1877
|
state.fields[fieldName].error = fieldError;
|
|
2400
1878
|
state.formState.errors = errorsState;
|
|
2401
1879
|
}
|
|
2402
1880
|
if (submitError) {
|
|
2403
|
-
|
|
2404
|
-
|
|
1881
|
+
const submitErrorsState = Object.assign({}, state.formState.submitErrors, {
|
|
1882
|
+
[fieldName]: submitError
|
|
1883
|
+
});
|
|
2405
1884
|
|
|
2406
1885
|
// state.fields[fieldName].submitFailed = true
|
|
2407
1886
|
// state.fields[fieldName].submitSucceeded = false
|
|
@@ -2413,56 +1892,36 @@ var setErrorsMutator = function setErrorsMutator(args, state) {
|
|
|
2413
1892
|
}
|
|
2414
1893
|
}
|
|
2415
1894
|
};
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
var fieldName = _ref2[0],
|
|
2445
|
-
errorsList = _ref2[1];
|
|
2446
|
-
formErrors[fieldName] = errorsList[0];
|
|
2447
|
-
});
|
|
2448
|
-
}
|
|
2449
|
-
return _context.abrupt("return", {
|
|
2450
|
-
success: false,
|
|
2451
|
-
formErrors: formErrors,
|
|
2452
|
-
error: _context.t0
|
|
2453
|
-
});
|
|
2454
|
-
case 13:
|
|
2455
|
-
case "end":
|
|
2456
|
-
return _context.stop();
|
|
2457
|
-
}
|
|
2458
|
-
}, _callee, null, [[0, 7]]);
|
|
2459
|
-
}));
|
|
2460
|
-
return function sendFormDataToServer(_x, _x2) {
|
|
2461
|
-
return _ref.apply(this, arguments);
|
|
2462
|
-
};
|
|
2463
|
-
}();
|
|
1895
|
+
const sendFormDataToServer = async (url, data) => {
|
|
1896
|
+
try {
|
|
1897
|
+
const response = await axios({
|
|
1898
|
+
url: url,
|
|
1899
|
+
method: 'POST',
|
|
1900
|
+
data: data
|
|
1901
|
+
});
|
|
1902
|
+
return {
|
|
1903
|
+
success: true,
|
|
1904
|
+
response
|
|
1905
|
+
};
|
|
1906
|
+
} catch (error) {
|
|
1907
|
+
const formErrors = {};
|
|
1908
|
+
if (typeof error.response?.data === 'string') {
|
|
1909
|
+
formErrors[FORM_ERROR] = 'Something went wrong';
|
|
1910
|
+
}
|
|
1911
|
+
if (typeof error.response?.data === 'object') {
|
|
1912
|
+
Object.entries(error.response.data).forEach(([fieldName, errorsList]) => {
|
|
1913
|
+
formErrors[fieldName] = errorsList[0];
|
|
1914
|
+
});
|
|
1915
|
+
}
|
|
1916
|
+
return {
|
|
1917
|
+
success: false,
|
|
1918
|
+
formErrors,
|
|
1919
|
+
error
|
|
1920
|
+
};
|
|
1921
|
+
}
|
|
1922
|
+
};
|
|
2464
1923
|
|
|
2465
|
-
|
|
1924
|
+
const formTypes = {
|
|
2466
1925
|
checkbox: 'checkbox',
|
|
2467
1926
|
custom: 'custom',
|
|
2468
1927
|
choice: 'choice',
|
|
@@ -2474,7 +1933,7 @@ var formTypes = {
|
|
|
2474
1933
|
radioGroup: 'radioGroup',
|
|
2475
1934
|
segmented: 'segmented',
|
|
2476
1935
|
select: 'select',
|
|
2477
|
-
|
|
1936
|
+
switch: 'switch',
|
|
2478
1937
|
text: 'text',
|
|
2479
1938
|
textarea: 'textarea'
|
|
2480
1939
|
};
|
|
@@ -2498,7 +1957,7 @@ function generateField(field, config, props) {
|
|
|
2498
1957
|
key: config.key
|
|
2499
1958
|
}, field, props));
|
|
2500
1959
|
}
|
|
2501
|
-
case formTypes
|
|
1960
|
+
case formTypes.switch:
|
|
2502
1961
|
{
|
|
2503
1962
|
return /*#__PURE__*/React.createElement(SwitchField, Object.assign({
|
|
2504
1963
|
key: config.key
|
|
@@ -2556,13 +2015,12 @@ function generateField(field, config, props) {
|
|
|
2556
2015
|
{
|
|
2557
2016
|
return /*#__PURE__*/React.createElement(Group, Object.assign({
|
|
2558
2017
|
key: config.key
|
|
2559
|
-
}, field, props), Object.entries(field.group).map(
|
|
2560
|
-
|
|
2561
|
-
value
|
|
2562
|
-
var groupProps = Object.assign({}, value, {
|
|
2018
|
+
}, field, props), Object.entries(field.group).map(([key, value]) => {
|
|
2019
|
+
const groupProps = {
|
|
2020
|
+
...value,
|
|
2563
2021
|
hideMessage: field.hideMessage,
|
|
2564
2022
|
classNameGroupItem: value.classNameGroupItem || 'form__group-item'
|
|
2565
|
-
}
|
|
2023
|
+
};
|
|
2566
2024
|
return generateField(groupProps, {
|
|
2567
2025
|
key: key + '_form_group'
|
|
2568
2026
|
}, props);
|
|
@@ -2571,118 +2029,121 @@ function generateField(field, config, props) {
|
|
|
2571
2029
|
}
|
|
2572
2030
|
}
|
|
2573
2031
|
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2032
|
+
const FinalForm = /*#__PURE__*/React.forwardRef(function FinalForm(props, ref) {
|
|
2033
|
+
const {
|
|
2034
|
+
additionalProps,
|
|
2035
|
+
after,
|
|
2036
|
+
before,
|
|
2037
|
+
buttonDirection,
|
|
2038
|
+
buttonGap,
|
|
2039
|
+
buttonPadding,
|
|
2040
|
+
groupGap,
|
|
2041
|
+
className,
|
|
2042
|
+
config,
|
|
2043
|
+
description,
|
|
2044
|
+
descriptionSize,
|
|
2045
|
+
descriptionTextColor,
|
|
2046
|
+
descriptionTextWeight,
|
|
2047
|
+
disableFieldsAutoComplete,
|
|
2048
|
+
fieldsGap,
|
|
2049
|
+
formName,
|
|
2050
|
+
initialValues,
|
|
2051
|
+
initialValuesEqual,
|
|
2052
|
+
isLoading,
|
|
2053
|
+
loader,
|
|
2054
|
+
loaderSet,
|
|
2055
|
+
loaderFill,
|
|
2056
|
+
loaderItemFill,
|
|
2057
|
+
loaderText,
|
|
2058
|
+
language,
|
|
2059
|
+
mutators,
|
|
2060
|
+
onChangeFormValues,
|
|
2061
|
+
onClickSecondaryButton,
|
|
2062
|
+
onClickTertiaryButton,
|
|
2063
|
+
onSubmit,
|
|
2064
|
+
primaryButton,
|
|
2065
|
+
primaryButtonLabel,
|
|
2066
|
+
secondaryButton,
|
|
2067
|
+
secondaryButtonLabel,
|
|
2068
|
+
primaryButtonFill,
|
|
2069
|
+
primaryButtonFillHover,
|
|
2070
|
+
secondaryButtonFill,
|
|
2071
|
+
secondaryButtonFillHover,
|
|
2072
|
+
primaryButtonSize,
|
|
2073
|
+
primaryButtonLabelTextColor,
|
|
2074
|
+
primaryButtonLabelSize,
|
|
2075
|
+
primaryButtonLabelTextWeight,
|
|
2076
|
+
secondaryButtonSize,
|
|
2077
|
+
secondaryButtonLabelTextColor,
|
|
2078
|
+
secondaryButtonLabelSize,
|
|
2079
|
+
secondaryButtonLabelTextWeight,
|
|
2080
|
+
tertiaryButton,
|
|
2081
|
+
tertiaryButtonFill,
|
|
2082
|
+
tertiaryButtonFillHover,
|
|
2083
|
+
tertiaryButtonSize,
|
|
2084
|
+
tertiaryButtonLabelTextColor,
|
|
2085
|
+
tertiaryButtonLabelSize,
|
|
2086
|
+
tertiaryButtonLabelTextWeight,
|
|
2087
|
+
tertiaryButtonLabel,
|
|
2088
|
+
set,
|
|
2089
|
+
type,
|
|
2090
|
+
buttonJustifyContent,
|
|
2091
|
+
title,
|
|
2092
|
+
notificationType,
|
|
2093
|
+
notificationClose,
|
|
2094
|
+
buttonFill,
|
|
2095
|
+
titleTextSize,
|
|
2096
|
+
titleTextColor,
|
|
2097
|
+
titleTextWeight,
|
|
2098
|
+
validationSchema,
|
|
2099
|
+
dataTour,
|
|
2100
|
+
dataTourButtons,
|
|
2101
|
+
dataTourPrimaryButton,
|
|
2102
|
+
dataTourSecondaryButton,
|
|
2103
|
+
dataTourTertiaryButton
|
|
2104
|
+
} = props;
|
|
2105
|
+
const validate = useYupValidationSchema(validationSchema, language);
|
|
2106
|
+
const onRefFormInstance = useCallback(formInstance => {
|
|
2646
2107
|
if (ref) {
|
|
2647
2108
|
ref.current = formInstance;
|
|
2648
2109
|
}
|
|
2649
2110
|
}, [ref]);
|
|
2650
|
-
|
|
2111
|
+
const fillClass = useDeviceTargetClass(props, {
|
|
2651
2112
|
prefix: 'fill_',
|
|
2652
2113
|
propsKey: 'fill'
|
|
2653
2114
|
});
|
|
2654
|
-
|
|
2115
|
+
const directionClass = useDeviceTargetClass(props, {
|
|
2655
2116
|
prefix: 'direction_',
|
|
2656
2117
|
propsKey: 'direction'
|
|
2657
2118
|
});
|
|
2658
|
-
|
|
2119
|
+
const shapeClass = useDeviceTargetClass(props, {
|
|
2659
2120
|
prefix: 'shape_',
|
|
2660
2121
|
propsKey: 'shape'
|
|
2661
2122
|
});
|
|
2662
|
-
|
|
2123
|
+
const elevationClass = useDeviceTargetClass(props, {
|
|
2663
2124
|
prefix: 'elevation_',
|
|
2664
2125
|
propsKey: 'elevation'
|
|
2665
2126
|
});
|
|
2666
|
-
|
|
2667
|
-
formStyles
|
|
2127
|
+
const {
|
|
2128
|
+
styles: formStyles
|
|
2129
|
+
} = useStyles(props);
|
|
2668
2130
|
return /*#__PURE__*/React.createElement(Form, {
|
|
2669
2131
|
decorators: [focusOnErrorDecorator],
|
|
2670
2132
|
initialValues: initialValues,
|
|
2671
2133
|
initialValuesEqual: initialValuesEqual,
|
|
2672
2134
|
mutators: mutators,
|
|
2673
|
-
render:
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2135
|
+
render: ({
|
|
2136
|
+
handleSubmit,
|
|
2137
|
+
submitError,
|
|
2138
|
+
modifiedSinceLastSubmit,
|
|
2139
|
+
form
|
|
2140
|
+
}) => {
|
|
2678
2141
|
return /*#__PURE__*/React.createElement("form", {
|
|
2679
2142
|
style: formStyles,
|
|
2680
|
-
className: clsx(className, 'form', set &&
|
|
2143
|
+
className: clsx(className, 'form', set && `form_set_${set}`, type && `form_type_${type}`, directionClass, fillClass, shapeClass, elevationClass),
|
|
2681
2144
|
name: formName,
|
|
2682
2145
|
"data-tour": dataTour,
|
|
2683
|
-
ref:
|
|
2684
|
-
return onRefFormInstance(form);
|
|
2685
|
-
},
|
|
2146
|
+
ref: () => onRefFormInstance(form),
|
|
2686
2147
|
onSubmit: handleSubmit,
|
|
2687
2148
|
autoComplete: disableFieldsAutoComplete ? 'off' : undefined,
|
|
2688
2149
|
autoCorrect: disableFieldsAutoComplete ? 'off' : undefined,
|
|
@@ -2699,10 +2160,11 @@ var FinalForm = /*#__PURE__*/React.forwardRef(function FinalForm(props, ref) {
|
|
|
2699
2160
|
textColor: descriptionTextColor,
|
|
2700
2161
|
textWeight: descriptionTextWeight
|
|
2701
2162
|
}, description), submitError && !modifiedSinceLastSubmit && /*#__PURE__*/React.createElement("div", {
|
|
2702
|
-
className: clsx('notification', 'form-notification', notificationType ?
|
|
2163
|
+
className: clsx('notification', 'form-notification', notificationType ? `form-notification_type_${notificationType}` : 'form-notification_type_global')
|
|
2703
2164
|
}, /*#__PURE__*/React.createElement(NotificationItem, {
|
|
2704
2165
|
className: "form-notification__item",
|
|
2705
2166
|
titleTextSize: "h6",
|
|
2167
|
+
notificationClose: notificationClose,
|
|
2706
2168
|
title: form.getState().submitError,
|
|
2707
2169
|
set: "form",
|
|
2708
2170
|
status: "error"
|
|
@@ -2715,11 +2177,9 @@ var FinalForm = /*#__PURE__*/React.forwardRef(function FinalForm(props, ref) {
|
|
|
2715
2177
|
direction: "vertical",
|
|
2716
2178
|
gap: fieldsGap || groupGap,
|
|
2717
2179
|
className: "form__wrapper"
|
|
2718
|
-
}, Object.keys(config).map(
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
}, additionalProps[config[key].name]);
|
|
2722
|
-
}), isLoading && (loader || /*#__PURE__*/React.createElement(Loader, {
|
|
2180
|
+
}, Object.keys(config).map(key => generateField(config[key], {
|
|
2181
|
+
key
|
|
2182
|
+
}, additionalProps[config[key].name])), isLoading && (loader || /*#__PURE__*/React.createElement(Loader, {
|
|
2723
2183
|
className: "form__loader",
|
|
2724
2184
|
set: loaderSet,
|
|
2725
2185
|
fill: loaderFill,
|