@bolttech/form-engine 3.1.0-beta.9 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.esm.js CHANGED
@@ -1,1644 +1,40 @@
1
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
- import { createContext, useContext, useRef, useEffect, useState, useMemo, useCallback, Suspense } from 'react';
3
- import { FormGroup, FormCore, FormField } from '@bolttech/form-engine-core';
1
+ 'use client';
2
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
3
+ import { createContext, useContext, useRef, useEffect, useMemo, useState, useCallback, Suspense } from 'react';
4
+ import { FormGroup, FormField } from '@bolttech/form-engine-core';
4
5
 
5
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
6
-
7
- var fails$b = function (exec) {
8
- try {
9
- return !!exec();
10
- } catch (error) {
11
- return true;
12
- }
13
- };
14
-
15
- var fails$a = fails$b;
16
-
17
- var functionBindNative = !fails$a(function () {
18
- // eslint-disable-next-line es/no-function-prototype-bind -- safe
19
- var test = (function () { /* empty */ }).bind();
20
- // eslint-disable-next-line no-prototype-builtins -- safe
21
- return typeof test != 'function' || test.hasOwnProperty('prototype');
22
- });
23
-
24
- var NATIVE_BIND$1 = functionBindNative;
25
-
26
- var FunctionPrototype$1 = Function.prototype;
27
- var call$6 = FunctionPrototype$1.call;
28
- var uncurryThisWithBind = NATIVE_BIND$1 && FunctionPrototype$1.bind.bind(call$6, call$6);
29
-
30
- var functionUncurryThis = NATIVE_BIND$1 ? uncurryThisWithBind : function (fn) {
31
- return function () {
32
- return call$6.apply(fn, arguments);
33
- };
34
- };
35
-
36
- var uncurryThis$a = functionUncurryThis;
37
-
38
- var toString$1 = uncurryThis$a({}.toString);
39
- var stringSlice$1 = uncurryThis$a(''.slice);
40
-
41
- var classofRaw = function (it) {
42
- return stringSlice$1(toString$1(it), 8, -1);
43
- };
44
-
45
- var uncurryThis$9 = functionUncurryThis;
46
- var fails$9 = fails$b;
47
- var classof = classofRaw;
48
-
49
- var $Object$3 = Object;
50
- var split = uncurryThis$9(''.split);
51
-
52
- // fallback for non-array-like ES3 and non-enumerable old V8 strings
53
- var indexedObject = fails$9(function () {
54
- // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346
55
- // eslint-disable-next-line no-prototype-builtins -- safe
56
- return !$Object$3('z').propertyIsEnumerable(0);
57
- }) ? function (it) {
58
- return classof(it) === 'String' ? split(it, '') : $Object$3(it);
59
- } : $Object$3;
60
-
61
- // we can't use just `it == null` since of `document.all` special case
62
- // https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot-aec
63
- var isNullOrUndefined$2 = function (it) {
64
- return it === null || it === undefined;
65
- };
66
-
67
- var isNullOrUndefined$1 = isNullOrUndefined$2;
68
-
69
- var $TypeError$6 = TypeError;
70
-
71
- // `RequireObjectCoercible` abstract operation
72
- // https://tc39.es/ecma262/#sec-requireobjectcoercible
73
- var requireObjectCoercible$3 = function (it) {
74
- if (isNullOrUndefined$1(it)) throw new $TypeError$6("Can't call method on " + it);
75
- return it;
76
- };
77
-
78
- // toObject with fallback for non-array-like ES3 strings
79
- var IndexedObject$1 = indexedObject;
80
- var requireObjectCoercible$2 = requireObjectCoercible$3;
81
-
82
- var toIndexedObject$5 = function (it) {
83
- return IndexedObject$1(requireObjectCoercible$2(it));
84
- };
85
-
86
- var check = function (it) {
87
- return it && it.Math === Math && it;
88
- };
89
-
90
- // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
91
- var global$b =
92
- // eslint-disable-next-line es/no-global-this -- safe
93
- check(typeof globalThis == 'object' && globalThis) ||
94
- check(typeof window == 'object' && window) ||
95
- // eslint-disable-next-line no-restricted-globals -- safe
96
- check(typeof self == 'object' && self) ||
97
- check(typeof commonjsGlobal == 'object' && commonjsGlobal) ||
98
- check(typeof commonjsGlobal == 'object' && commonjsGlobal) ||
99
- // eslint-disable-next-line no-new-func -- fallback
100
- (function () { return this; })() || Function('return this')();
101
-
102
- var sharedStore = {exports: {}};
103
-
104
- var global$a = global$b;
105
-
106
- // eslint-disable-next-line es/no-object-defineproperty -- safe
107
- var defineProperty$5 = Object.defineProperty;
108
-
109
- var defineGlobalProperty$3 = function (key, value) {
110
- try {
111
- defineProperty$5(global$a, key, { value: value, configurable: true, writable: true });
112
- } catch (error) {
113
- global$a[key] = value;
114
- } return value;
115
- };
116
-
117
- var globalThis$1 = global$b;
118
- var defineGlobalProperty$2 = defineGlobalProperty$3;
119
-
120
- var SHARED = '__core-js_shared__';
121
- var store$3 = sharedStore.exports = globalThis$1[SHARED] || defineGlobalProperty$2(SHARED, {});
122
-
123
- (store$3.versions || (store$3.versions = [])).push({
124
- version: '3.37.1',
125
- mode: 'global',
126
- copyright: '© 2014-2024 Denis Pushkarev (zloirock.ru)',
127
- license: 'https://github.com/zloirock/core-js/blob/v3.37.1/LICENSE',
128
- source: 'https://github.com/zloirock/core-js'
129
- });
130
-
131
- var store$2 = sharedStore.exports;
132
-
133
- var shared$3 = function (key, value) {
134
- return store$2[key] || (store$2[key] = value || {});
135
- };
136
-
137
- var requireObjectCoercible$1 = requireObjectCoercible$3;
138
-
139
- var $Object$2 = Object;
140
-
141
- // `ToObject` abstract operation
142
- // https://tc39.es/ecma262/#sec-toobject
143
- var toObject$3 = function (argument) {
144
- return $Object$2(requireObjectCoercible$1(argument));
145
- };
146
-
147
- var uncurryThis$8 = functionUncurryThis;
148
- var toObject$2 = toObject$3;
149
-
150
- var hasOwnProperty = uncurryThis$8({}.hasOwnProperty);
151
-
152
- // `HasOwnProperty` abstract operation
153
- // https://tc39.es/ecma262/#sec-hasownproperty
154
- // eslint-disable-next-line es/no-object-hasown -- safe
155
- var hasOwnProperty_1 = Object.hasOwn || function hasOwn(it, key) {
156
- return hasOwnProperty(toObject$2(it), key);
157
- };
158
-
159
- var uncurryThis$7 = functionUncurryThis;
160
-
161
- var id = 0;
162
- var postfix = Math.random();
163
- var toString = uncurryThis$7(1.0.toString);
164
-
165
- var uid$2 = function (key) {
166
- return 'Symbol(' + (key === undefined ? '' : key) + ')_' + toString(++id + postfix, 36);
167
- };
168
-
169
- var engineUserAgent = typeof navigator != 'undefined' && String(navigator.userAgent) || '';
170
-
171
- var global$9 = global$b;
172
- var userAgent = engineUserAgent;
173
-
174
- var process = global$9.process;
175
- var Deno = global$9.Deno;
176
- var versions = process && process.versions || Deno && Deno.version;
177
- var v8 = versions && versions.v8;
178
- var match, version;
179
-
180
- if (v8) {
181
- match = v8.split('.');
182
- // in old Chrome, versions of V8 isn't V8 = Chrome / 10
183
- // but their correct versions are not interesting for us
184
- version = match[0] > 0 && match[0] < 4 ? 1 : +(match[0] + match[1]);
185
- }
186
-
187
- // BrowserFS NodeJS `process` polyfill incorrectly set `.v8` to `0.0`
188
- // so check `userAgent` even if `.v8` exists, but 0
189
- if (!version && userAgent) {
190
- match = userAgent.match(/Edge\/(\d+)/);
191
- if (!match || match[1] >= 74) {
192
- match = userAgent.match(/Chrome\/(\d+)/);
193
- if (match) version = +match[1];
194
- }
195
- }
196
-
197
- var engineV8Version = version;
198
-
199
- /* eslint-disable es/no-symbol -- required for testing */
200
- var V8_VERSION = engineV8Version;
201
- var fails$8 = fails$b;
202
- var global$8 = global$b;
203
-
204
- var $String$4 = global$8.String;
205
-
206
- // eslint-disable-next-line es/no-object-getownpropertysymbols -- required for testing
207
- var symbolConstructorDetection = !!Object.getOwnPropertySymbols && !fails$8(function () {
208
- var symbol = Symbol('symbol detection');
209
- // Chrome 38 Symbol has incorrect toString conversion
210
- // `get-own-property-symbols` polyfill symbols converted to object are not Symbol instances
211
- // nb: Do not call `String` directly to avoid this being optimized out to `symbol+''` which will,
212
- // of course, fail.
213
- return !$String$4(symbol) || !(Object(symbol) instanceof Symbol) ||
214
- // Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances
215
- !Symbol.sham && V8_VERSION && V8_VERSION < 41;
216
- });
217
-
218
- /* eslint-disable es/no-symbol -- required for testing */
219
- var NATIVE_SYMBOL$1 = symbolConstructorDetection;
220
-
221
- var useSymbolAsUid = NATIVE_SYMBOL$1
222
- && !Symbol.sham
223
- && typeof Symbol.iterator == 'symbol';
224
-
225
- var global$7 = global$b;
226
- var shared$2 = shared$3;
227
- var hasOwn$8 = hasOwnProperty_1;
228
- var uid$1 = uid$2;
229
- var NATIVE_SYMBOL = symbolConstructorDetection;
230
- var USE_SYMBOL_AS_UID$1 = useSymbolAsUid;
231
-
232
- var Symbol$1 = global$7.Symbol;
233
- var WellKnownSymbolsStore = shared$2('wks');
234
- var createWellKnownSymbol = USE_SYMBOL_AS_UID$1 ? Symbol$1['for'] || Symbol$1 : Symbol$1 && Symbol$1.withoutSetter || uid$1;
235
-
236
- var wellKnownSymbol$6 = function (name) {
237
- if (!hasOwn$8(WellKnownSymbolsStore, name)) {
238
- WellKnownSymbolsStore[name] = NATIVE_SYMBOL && hasOwn$8(Symbol$1, name)
239
- ? Symbol$1[name]
240
- : createWellKnownSymbol('Symbol.' + name);
241
- } return WellKnownSymbolsStore[name];
242
- };
243
-
244
- // https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot
245
- var documentAll = typeof document == 'object' && document.all;
246
-
247
- // `IsCallable` abstract operation
248
- // https://tc39.es/ecma262/#sec-iscallable
249
- // eslint-disable-next-line unicorn/no-typeof-undefined -- required for testing
250
- var isCallable$d = typeof documentAll == 'undefined' && documentAll !== undefined ? function (argument) {
251
- return typeof argument == 'function' || argument === documentAll;
252
- } : function (argument) {
253
- return typeof argument == 'function';
254
- };
255
-
256
- var isCallable$c = isCallable$d;
257
-
258
- var isObject$8 = function (it) {
259
- return typeof it == 'object' ? it !== null : isCallable$c(it);
260
- };
261
-
262
- var isObject$7 = isObject$8;
263
-
264
- var $String$3 = String;
265
- var $TypeError$5 = TypeError;
266
-
267
- // `Assert: Type(argument) is Object`
268
- var anObject$4 = function (argument) {
269
- if (isObject$7(argument)) return argument;
270
- throw new $TypeError$5($String$3(argument) + ' is not an object');
271
- };
272
-
273
- var objectDefineProperties = {};
274
-
275
- var fails$7 = fails$b;
276
-
277
- // Detect IE8's incomplete defineProperty implementation
278
- var descriptors = !fails$7(function () {
279
- // eslint-disable-next-line es/no-object-defineproperty -- required for testing
280
- return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] !== 7;
281
- });
282
-
283
- var DESCRIPTORS$9 = descriptors;
284
- var fails$6 = fails$b;
285
-
286
- // V8 ~ Chrome 36-
287
- // https://bugs.chromium.org/p/v8/issues/detail?id=3334
288
- var v8PrototypeDefineBug = DESCRIPTORS$9 && fails$6(function () {
289
- // eslint-disable-next-line es/no-object-defineproperty -- required for testing
290
- return Object.defineProperty(function () { /* empty */ }, 'prototype', {
291
- value: 42,
292
- writable: false
293
- }).prototype !== 42;
294
- });
295
-
296
- var objectDefineProperty = {};
297
-
298
- var global$6 = global$b;
299
- var isObject$6 = isObject$8;
300
-
301
- var document$1 = global$6.document;
302
- // typeof document.createElement is 'object' in old IE
303
- var EXISTS$1 = isObject$6(document$1) && isObject$6(document$1.createElement);
304
-
305
- var documentCreateElement$2 = function (it) {
306
- return EXISTS$1 ? document$1.createElement(it) : {};
307
- };
308
-
309
- var DESCRIPTORS$8 = descriptors;
310
- var fails$5 = fails$b;
311
- var createElement = documentCreateElement$2;
312
-
313
- // Thanks to IE8 for its funny defineProperty
314
- var ie8DomDefine = !DESCRIPTORS$8 && !fails$5(function () {
315
- // eslint-disable-next-line es/no-object-defineproperty -- required for testing
316
- return Object.defineProperty(createElement('div'), 'a', {
317
- get: function () { return 7; }
318
- }).a !== 7;
319
- });
320
-
321
- var NATIVE_BIND = functionBindNative;
322
-
323
- var call$5 = Function.prototype.call;
324
-
325
- var functionCall = NATIVE_BIND ? call$5.bind(call$5) : function () {
326
- return call$5.apply(call$5, arguments);
327
- };
328
-
329
- var global$5 = global$b;
330
- var isCallable$b = isCallable$d;
331
-
332
- var aFunction = function (argument) {
333
- return isCallable$b(argument) ? argument : undefined;
334
- };
335
-
336
- var getBuiltIn$3 = function (namespace, method) {
337
- return arguments.length < 2 ? aFunction(global$5[namespace]) : global$5[namespace] && global$5[namespace][method];
338
- };
339
-
340
- var uncurryThis$6 = functionUncurryThis;
341
-
342
- var objectIsPrototypeOf = uncurryThis$6({}.isPrototypeOf);
343
-
344
- var getBuiltIn$2 = getBuiltIn$3;
345
- var isCallable$a = isCallable$d;
346
- var isPrototypeOf = objectIsPrototypeOf;
347
- var USE_SYMBOL_AS_UID = useSymbolAsUid;
348
-
349
- var $Object$1 = Object;
350
-
351
- var isSymbol$2 = USE_SYMBOL_AS_UID ? function (it) {
352
- return typeof it == 'symbol';
353
- } : function (it) {
354
- var $Symbol = getBuiltIn$2('Symbol');
355
- return isCallable$a($Symbol) && isPrototypeOf($Symbol.prototype, $Object$1(it));
356
- };
357
-
358
- var $String$2 = String;
359
-
360
- var tryToString$1 = function (argument) {
361
- try {
362
- return $String$2(argument);
363
- } catch (error) {
364
- return 'Object';
365
- }
366
- };
367
-
368
- var isCallable$9 = isCallable$d;
369
- var tryToString = tryToString$1;
370
-
371
- var $TypeError$4 = TypeError;
372
-
373
- // `Assert: IsCallable(argument) is true`
374
- var aCallable$2 = function (argument) {
375
- if (isCallable$9(argument)) return argument;
376
- throw new $TypeError$4(tryToString(argument) + ' is not a function');
377
- };
378
-
379
- var aCallable$1 = aCallable$2;
380
- var isNullOrUndefined = isNullOrUndefined$2;
381
-
382
- // `GetMethod` abstract operation
383
- // https://tc39.es/ecma262/#sec-getmethod
384
- var getMethod$1 = function (V, P) {
385
- var func = V[P];
386
- return isNullOrUndefined(func) ? undefined : aCallable$1(func);
387
- };
388
-
389
- var call$4 = functionCall;
390
- var isCallable$8 = isCallable$d;
391
- var isObject$5 = isObject$8;
392
-
393
- var $TypeError$3 = TypeError;
394
-
395
- // `OrdinaryToPrimitive` abstract operation
396
- // https://tc39.es/ecma262/#sec-ordinarytoprimitive
397
- var ordinaryToPrimitive$1 = function (input, pref) {
398
- var fn, val;
399
- if (pref === 'string' && isCallable$8(fn = input.toString) && !isObject$5(val = call$4(fn, input))) return val;
400
- if (isCallable$8(fn = input.valueOf) && !isObject$5(val = call$4(fn, input))) return val;
401
- if (pref !== 'string' && isCallable$8(fn = input.toString) && !isObject$5(val = call$4(fn, input))) return val;
402
- throw new $TypeError$3("Can't convert object to primitive value");
403
- };
404
-
405
- var call$3 = functionCall;
406
- var isObject$4 = isObject$8;
407
- var isSymbol$1 = isSymbol$2;
408
- var getMethod = getMethod$1;
409
- var ordinaryToPrimitive = ordinaryToPrimitive$1;
410
- var wellKnownSymbol$5 = wellKnownSymbol$6;
411
-
412
- var $TypeError$2 = TypeError;
413
- var TO_PRIMITIVE = wellKnownSymbol$5('toPrimitive');
414
-
415
- // `ToPrimitive` abstract operation
416
- // https://tc39.es/ecma262/#sec-toprimitive
417
- var toPrimitive$1 = function (input, pref) {
418
- if (!isObject$4(input) || isSymbol$1(input)) return input;
419
- var exoticToPrim = getMethod(input, TO_PRIMITIVE);
420
- var result;
421
- if (exoticToPrim) {
422
- if (pref === undefined) pref = 'default';
423
- result = call$3(exoticToPrim, input, pref);
424
- if (!isObject$4(result) || isSymbol$1(result)) return result;
425
- throw new $TypeError$2("Can't convert object to primitive value");
426
- }
427
- if (pref === undefined) pref = 'number';
428
- return ordinaryToPrimitive(input, pref);
429
- };
430
-
431
- var toPrimitive = toPrimitive$1;
432
- var isSymbol = isSymbol$2;
433
-
434
- // `ToPropertyKey` abstract operation
435
- // https://tc39.es/ecma262/#sec-topropertykey
436
- var toPropertyKey$2 = function (argument) {
437
- var key = toPrimitive(argument, 'string');
438
- return isSymbol(key) ? key : key + '';
439
- };
440
-
441
- var DESCRIPTORS$7 = descriptors;
442
- var IE8_DOM_DEFINE$1 = ie8DomDefine;
443
- var V8_PROTOTYPE_DEFINE_BUG$1 = v8PrototypeDefineBug;
444
- var anObject$3 = anObject$4;
445
- var toPropertyKey$1 = toPropertyKey$2;
446
-
447
- var $TypeError$1 = TypeError;
448
- // eslint-disable-next-line es/no-object-defineproperty -- safe
449
- var $defineProperty = Object.defineProperty;
450
- // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
451
- var $getOwnPropertyDescriptor$1 = Object.getOwnPropertyDescriptor;
452
- var ENUMERABLE = 'enumerable';
453
- var CONFIGURABLE$1 = 'configurable';
454
- var WRITABLE = 'writable';
455
-
456
- // `Object.defineProperty` method
457
- // https://tc39.es/ecma262/#sec-object.defineproperty
458
- objectDefineProperty.f = DESCRIPTORS$7 ? V8_PROTOTYPE_DEFINE_BUG$1 ? function defineProperty(O, P, Attributes) {
459
- anObject$3(O);
460
- P = toPropertyKey$1(P);
461
- anObject$3(Attributes);
462
- if (typeof O === 'function' && P === 'prototype' && 'value' in Attributes && WRITABLE in Attributes && !Attributes[WRITABLE]) {
463
- var current = $getOwnPropertyDescriptor$1(O, P);
464
- if (current && current[WRITABLE]) {
465
- O[P] = Attributes.value;
466
- Attributes = {
467
- configurable: CONFIGURABLE$1 in Attributes ? Attributes[CONFIGURABLE$1] : current[CONFIGURABLE$1],
468
- enumerable: ENUMERABLE in Attributes ? Attributes[ENUMERABLE] : current[ENUMERABLE],
469
- writable: false
470
- };
471
- }
472
- } return $defineProperty(O, P, Attributes);
473
- } : $defineProperty : function defineProperty(O, P, Attributes) {
474
- anObject$3(O);
475
- P = toPropertyKey$1(P);
476
- anObject$3(Attributes);
477
- if (IE8_DOM_DEFINE$1) try {
478
- return $defineProperty(O, P, Attributes);
479
- } catch (error) { /* empty */ }
480
- if ('get' in Attributes || 'set' in Attributes) throw new $TypeError$1('Accessors not supported');
481
- if ('value' in Attributes) O[P] = Attributes.value;
482
- return O;
483
- };
484
-
485
- var ceil = Math.ceil;
486
- var floor = Math.floor;
487
-
488
- // `Math.trunc` method
489
- // https://tc39.es/ecma262/#sec-math.trunc
490
- // eslint-disable-next-line es/no-math-trunc -- safe
491
- var mathTrunc = Math.trunc || function trunc(x) {
492
- var n = +x;
493
- return (n > 0 ? floor : ceil)(n);
494
- };
495
-
496
- var trunc = mathTrunc;
497
-
498
- // `ToIntegerOrInfinity` abstract operation
499
- // https://tc39.es/ecma262/#sec-tointegerorinfinity
500
- var toIntegerOrInfinity$2 = function (argument) {
501
- var number = +argument;
502
- // eslint-disable-next-line no-self-compare -- NaN check
503
- return number !== number || number === 0 ? 0 : trunc(number);
504
- };
505
-
506
- var toIntegerOrInfinity$1 = toIntegerOrInfinity$2;
507
-
508
- var max = Math.max;
509
- var min$1 = Math.min;
510
-
511
- // Helper for a popular repeating case of the spec:
512
- // Let integer be ? ToInteger(index).
513
- // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length).
514
- var toAbsoluteIndex$1 = function (index, length) {
515
- var integer = toIntegerOrInfinity$1(index);
516
- return integer < 0 ? max(integer + length, 0) : min$1(integer, length);
517
- };
518
-
519
- var toIntegerOrInfinity = toIntegerOrInfinity$2;
520
-
521
- var min = Math.min;
522
-
523
- // `ToLength` abstract operation
524
- // https://tc39.es/ecma262/#sec-tolength
525
- var toLength$1 = function (argument) {
526
- var len = toIntegerOrInfinity(argument);
527
- return len > 0 ? min(len, 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991
528
- };
529
-
530
- var toLength = toLength$1;
531
-
532
- // `LengthOfArrayLike` abstract operation
533
- // https://tc39.es/ecma262/#sec-lengthofarraylike
534
- var lengthOfArrayLike$1 = function (obj) {
535
- return toLength(obj.length);
536
- };
537
-
538
- var toIndexedObject$4 = toIndexedObject$5;
539
- var toAbsoluteIndex = toAbsoluteIndex$1;
540
- var lengthOfArrayLike = lengthOfArrayLike$1;
541
-
542
- // `Array.prototype.{ indexOf, includes }` methods implementation
543
- var createMethod = function (IS_INCLUDES) {
544
- return function ($this, el, fromIndex) {
545
- var O = toIndexedObject$4($this);
546
- var length = lengthOfArrayLike(O);
547
- if (length === 0) return !IS_INCLUDES && -1;
548
- var index = toAbsoluteIndex(fromIndex, length);
549
- var value;
550
- // Array#includes uses SameValueZero equality algorithm
551
- // eslint-disable-next-line no-self-compare -- NaN check
552
- if (IS_INCLUDES && el !== el) while (length > index) {
553
- value = O[index++];
554
- // eslint-disable-next-line no-self-compare -- NaN check
555
- if (value !== value) return true;
556
- // Array#indexOf ignores holes, Array#includes - not
557
- } else for (;length > index; index++) {
558
- if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0;
559
- } return !IS_INCLUDES && -1;
560
- };
561
- };
562
-
563
- var arrayIncludes = {
564
- // `Array.prototype.includes` method
565
- // https://tc39.es/ecma262/#sec-array.prototype.includes
566
- includes: createMethod(true),
567
- // `Array.prototype.indexOf` method
568
- // https://tc39.es/ecma262/#sec-array.prototype.indexof
569
- indexOf: createMethod(false)
570
- };
571
-
572
- var hiddenKeys$4 = {};
573
-
574
- var uncurryThis$5 = functionUncurryThis;
575
- var hasOwn$7 = hasOwnProperty_1;
576
- var toIndexedObject$3 = toIndexedObject$5;
577
- var indexOf = arrayIncludes.indexOf;
578
- var hiddenKeys$3 = hiddenKeys$4;
579
-
580
- var push = uncurryThis$5([].push);
581
-
582
- var objectKeysInternal = function (object, names) {
583
- var O = toIndexedObject$3(object);
584
- var i = 0;
585
- var result = [];
586
- var key;
587
- for (key in O) !hasOwn$7(hiddenKeys$3, key) && hasOwn$7(O, key) && push(result, key);
588
- // Don't enum bug & hidden keys
589
- while (names.length > i) if (hasOwn$7(O, key = names[i++])) {
590
- ~indexOf(result, key) || push(result, key);
591
- }
592
- return result;
593
- };
594
-
595
- // IE8- don't enum bug keys
596
- var enumBugKeys$3 = [
597
- 'constructor',
598
- 'hasOwnProperty',
599
- 'isPrototypeOf',
600
- 'propertyIsEnumerable',
601
- 'toLocaleString',
602
- 'toString',
603
- 'valueOf'
604
- ];
605
-
606
- var internalObjectKeys$1 = objectKeysInternal;
607
- var enumBugKeys$2 = enumBugKeys$3;
608
-
609
- // `Object.keys` method
610
- // https://tc39.es/ecma262/#sec-object.keys
611
- // eslint-disable-next-line es/no-object-keys -- safe
612
- var objectKeys$2 = Object.keys || function keys(O) {
613
- return internalObjectKeys$1(O, enumBugKeys$2);
614
- };
615
-
616
- var DESCRIPTORS$6 = descriptors;
617
- var V8_PROTOTYPE_DEFINE_BUG = v8PrototypeDefineBug;
618
- var definePropertyModule$3 = objectDefineProperty;
619
- var anObject$2 = anObject$4;
620
- var toIndexedObject$2 = toIndexedObject$5;
621
- var objectKeys$1 = objectKeys$2;
622
-
623
- // `Object.defineProperties` method
624
- // https://tc39.es/ecma262/#sec-object.defineproperties
625
- // eslint-disable-next-line es/no-object-defineproperties -- safe
626
- objectDefineProperties.f = DESCRIPTORS$6 && !V8_PROTOTYPE_DEFINE_BUG ? Object.defineProperties : function defineProperties(O, Properties) {
627
- anObject$2(O);
628
- var props = toIndexedObject$2(Properties);
629
- var keys = objectKeys$1(Properties);
630
- var length = keys.length;
631
- var index = 0;
632
- var key;
633
- while (length > index) definePropertyModule$3.f(O, key = keys[index++], props[key]);
634
- return O;
635
- };
636
-
637
- var getBuiltIn$1 = getBuiltIn$3;
638
-
639
- var html$1 = getBuiltIn$1('document', 'documentElement');
640
-
641
- var shared$1 = shared$3;
642
- var uid = uid$2;
643
-
644
- var keys = shared$1('keys');
645
-
646
- var sharedKey$3 = function (key) {
647
- return keys[key] || (keys[key] = uid(key));
648
- };
649
-
650
- /* global ActiveXObject -- old IE, WSH */
651
- var anObject$1 = anObject$4;
652
- var definePropertiesModule = objectDefineProperties;
653
- var enumBugKeys$1 = enumBugKeys$3;
654
- var hiddenKeys$2 = hiddenKeys$4;
655
- var html = html$1;
656
- var documentCreateElement$1 = documentCreateElement$2;
657
- var sharedKey$2 = sharedKey$3;
658
-
659
- var GT = '>';
660
- var LT = '<';
661
- var PROTOTYPE = 'prototype';
662
- var SCRIPT = 'script';
663
- var IE_PROTO$1 = sharedKey$2('IE_PROTO');
664
-
665
- var EmptyConstructor = function () { /* empty */ };
666
-
667
- var scriptTag = function (content) {
668
- return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT;
669
- };
670
-
671
- // Create object with fake `null` prototype: use ActiveX Object with cleared prototype
672
- var NullProtoObjectViaActiveX = function (activeXDocument) {
673
- activeXDocument.write(scriptTag(''));
674
- activeXDocument.close();
675
- var temp = activeXDocument.parentWindow.Object;
676
- activeXDocument = null; // avoid memory leak
677
- return temp;
678
- };
679
-
680
- // Create object with fake `null` prototype: use iframe Object with cleared prototype
681
- var NullProtoObjectViaIFrame = function () {
682
- // Thrash, waste and sodomy: IE GC bug
683
- var iframe = documentCreateElement$1('iframe');
684
- var JS = 'java' + SCRIPT + ':';
685
- var iframeDocument;
686
- iframe.style.display = 'none';
687
- html.appendChild(iframe);
688
- // https://github.com/zloirock/core-js/issues/475
689
- iframe.src = String(JS);
690
- iframeDocument = iframe.contentWindow.document;
691
- iframeDocument.open();
692
- iframeDocument.write(scriptTag('document.F=Object'));
693
- iframeDocument.close();
694
- return iframeDocument.F;
695
- };
696
-
697
- // Check for document.domain and active x support
698
- // No need to use active x approach when document.domain is not set
699
- // see https://github.com/es-shims/es5-shim/issues/150
700
- // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
701
- // avoid IE GC bug
702
- var activeXDocument;
703
- var NullProtoObject = function () {
704
- try {
705
- activeXDocument = new ActiveXObject('htmlfile');
706
- } catch (error) { /* ignore */ }
707
- NullProtoObject = typeof document != 'undefined'
708
- ? document.domain && activeXDocument
709
- ? NullProtoObjectViaActiveX(activeXDocument) // old IE
710
- : NullProtoObjectViaIFrame()
711
- : NullProtoObjectViaActiveX(activeXDocument); // WSH
712
- var length = enumBugKeys$1.length;
713
- while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys$1[length]];
714
- return NullProtoObject();
715
- };
716
-
717
- hiddenKeys$2[IE_PROTO$1] = true;
718
-
719
- // `Object.create` method
720
- // https://tc39.es/ecma262/#sec-object.create
721
- // eslint-disable-next-line es/no-object-create -- safe
722
- var objectCreate = Object.create || function create(O, Properties) {
723
- var result;
724
- if (O !== null) {
725
- EmptyConstructor[PROTOTYPE] = anObject$1(O);
726
- result = new EmptyConstructor();
727
- EmptyConstructor[PROTOTYPE] = null;
728
- // add "__proto__" for Object.getPrototypeOf polyfill
729
- result[IE_PROTO$1] = O;
730
- } else result = NullProtoObject();
731
- return Properties === undefined ? result : definePropertiesModule.f(result, Properties);
732
- };
733
-
734
- var wellKnownSymbol$4 = wellKnownSymbol$6;
735
- var create$1 = objectCreate;
736
- var defineProperty$4 = objectDefineProperty.f;
737
-
738
- var UNSCOPABLES = wellKnownSymbol$4('unscopables');
739
- var ArrayPrototype = Array.prototype;
740
-
741
- // Array.prototype[@@unscopables]
742
- // https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
743
- if (ArrayPrototype[UNSCOPABLES] === undefined) {
744
- defineProperty$4(ArrayPrototype, UNSCOPABLES, {
745
- configurable: true,
746
- value: create$1(null)
747
- });
748
- }
749
-
750
- // add a key to Array.prototype[@@unscopables]
751
- var addToUnscopables$1 = function (key) {
752
- ArrayPrototype[UNSCOPABLES][key] = true;
753
- };
754
-
755
- var iterators = {};
756
-
757
- var global$4 = global$b;
758
- var isCallable$7 = isCallable$d;
759
-
760
- var WeakMap$1 = global$4.WeakMap;
761
-
762
- var weakMapBasicDetection = isCallable$7(WeakMap$1) && /native code/.test(String(WeakMap$1));
763
-
764
- var createPropertyDescriptor$3 = function (bitmap, value) {
765
- return {
766
- enumerable: !(bitmap & 1),
767
- configurable: !(bitmap & 2),
768
- writable: !(bitmap & 4),
769
- value: value
770
- };
771
- };
772
-
773
- var DESCRIPTORS$5 = descriptors;
774
- var definePropertyModule$2 = objectDefineProperty;
775
- var createPropertyDescriptor$2 = createPropertyDescriptor$3;
776
-
777
- var createNonEnumerableProperty$4 = DESCRIPTORS$5 ? function (object, key, value) {
778
- return definePropertyModule$2.f(object, key, createPropertyDescriptor$2(1, value));
779
- } : function (object, key, value) {
780
- object[key] = value;
781
- return object;
782
- };
783
-
784
- var NATIVE_WEAK_MAP = weakMapBasicDetection;
785
- var global$3 = global$b;
786
- var isObject$3 = isObject$8;
787
- var createNonEnumerableProperty$3 = createNonEnumerableProperty$4;
788
- var hasOwn$6 = hasOwnProperty_1;
789
- var shared = sharedStore.exports;
790
- var sharedKey$1 = sharedKey$3;
791
- var hiddenKeys$1 = hiddenKeys$4;
792
-
793
- var OBJECT_ALREADY_INITIALIZED = 'Object already initialized';
794
- var TypeError$1 = global$3.TypeError;
795
- var WeakMap = global$3.WeakMap;
796
- var set, get, has;
797
-
798
- var enforce = function (it) {
799
- return has(it) ? get(it) : set(it, {});
800
- };
801
-
802
- var getterFor = function (TYPE) {
803
- return function (it) {
804
- var state;
805
- if (!isObject$3(it) || (state = get(it)).type !== TYPE) {
806
- throw new TypeError$1('Incompatible receiver, ' + TYPE + ' required');
807
- } return state;
808
- };
809
- };
810
-
811
- if (NATIVE_WEAK_MAP || shared.state) {
812
- var store$1 = shared.state || (shared.state = new WeakMap());
813
- /* eslint-disable no-self-assign -- prototype methods protection */
814
- store$1.get = store$1.get;
815
- store$1.has = store$1.has;
816
- store$1.set = store$1.set;
817
- /* eslint-enable no-self-assign -- prototype methods protection */
818
- set = function (it, metadata) {
819
- if (store$1.has(it)) throw new TypeError$1(OBJECT_ALREADY_INITIALIZED);
820
- metadata.facade = it;
821
- store$1.set(it, metadata);
822
- return metadata;
823
- };
824
- get = function (it) {
825
- return store$1.get(it) || {};
826
- };
827
- has = function (it) {
828
- return store$1.has(it);
829
- };
830
- } else {
831
- var STATE = sharedKey$1('state');
832
- hiddenKeys$1[STATE] = true;
833
- set = function (it, metadata) {
834
- if (hasOwn$6(it, STATE)) throw new TypeError$1(OBJECT_ALREADY_INITIALIZED);
835
- metadata.facade = it;
836
- createNonEnumerableProperty$3(it, STATE, metadata);
837
- return metadata;
838
- };
839
- get = function (it) {
840
- return hasOwn$6(it, STATE) ? it[STATE] : {};
841
- };
842
- has = function (it) {
843
- return hasOwn$6(it, STATE);
844
- };
845
- }
846
-
847
- var internalState = {
848
- set: set,
849
- get: get,
850
- has: has,
851
- enforce: enforce,
852
- getterFor: getterFor
853
- };
854
-
855
- var objectGetOwnPropertyDescriptor = {};
856
-
857
- var objectPropertyIsEnumerable = {};
858
-
859
- var $propertyIsEnumerable = {}.propertyIsEnumerable;
860
- // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
861
- var getOwnPropertyDescriptor$1 = Object.getOwnPropertyDescriptor;
862
-
863
- // Nashorn ~ JDK8 bug
864
- var NASHORN_BUG = getOwnPropertyDescriptor$1 && !$propertyIsEnumerable.call({ 1: 2 }, 1);
865
-
866
- // `Object.prototype.propertyIsEnumerable` method implementation
867
- // https://tc39.es/ecma262/#sec-object.prototype.propertyisenumerable
868
- objectPropertyIsEnumerable.f = NASHORN_BUG ? function propertyIsEnumerable(V) {
869
- var descriptor = getOwnPropertyDescriptor$1(this, V);
870
- return !!descriptor && descriptor.enumerable;
871
- } : $propertyIsEnumerable;
872
-
873
- var DESCRIPTORS$4 = descriptors;
874
- var call$2 = functionCall;
875
- var propertyIsEnumerableModule$1 = objectPropertyIsEnumerable;
876
- var createPropertyDescriptor$1 = createPropertyDescriptor$3;
877
- var toIndexedObject$1 = toIndexedObject$5;
878
- var toPropertyKey = toPropertyKey$2;
879
- var hasOwn$5 = hasOwnProperty_1;
880
- var IE8_DOM_DEFINE = ie8DomDefine;
881
-
882
- // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
883
- var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
884
-
885
- // `Object.getOwnPropertyDescriptor` method
886
- // https://tc39.es/ecma262/#sec-object.getownpropertydescriptor
887
- objectGetOwnPropertyDescriptor.f = DESCRIPTORS$4 ? $getOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) {
888
- O = toIndexedObject$1(O);
889
- P = toPropertyKey(P);
890
- if (IE8_DOM_DEFINE) try {
891
- return $getOwnPropertyDescriptor(O, P);
892
- } catch (error) { /* empty */ }
893
- if (hasOwn$5(O, P)) return createPropertyDescriptor$1(!call$2(propertyIsEnumerableModule$1.f, O, P), O[P]);
894
- };
895
-
896
- var makeBuiltIn$2 = {exports: {}};
897
-
898
- var DESCRIPTORS$3 = descriptors;
899
- var hasOwn$4 = hasOwnProperty_1;
900
-
901
- var FunctionPrototype = Function.prototype;
902
- // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
903
- var getDescriptor = DESCRIPTORS$3 && Object.getOwnPropertyDescriptor;
904
-
905
- var EXISTS = hasOwn$4(FunctionPrototype, 'name');
906
- // additional protection from minified / mangled / dropped function names
907
- var PROPER = EXISTS && (function something() { /* empty */ }).name === 'something';
908
- var CONFIGURABLE = EXISTS && (!DESCRIPTORS$3 || (DESCRIPTORS$3 && getDescriptor(FunctionPrototype, 'name').configurable));
909
-
910
- var functionName = {
911
- EXISTS: EXISTS,
912
- PROPER: PROPER,
913
- CONFIGURABLE: CONFIGURABLE
914
- };
915
-
916
- var uncurryThis$4 = functionUncurryThis;
917
- var isCallable$6 = isCallable$d;
918
- var store = sharedStore.exports;
919
-
920
- var functionToString = uncurryThis$4(Function.toString);
921
-
922
- // this helper broken in `core-js@3.4.1-3.4.4`, so we can't use `shared` helper
923
- if (!isCallable$6(store.inspectSource)) {
924
- store.inspectSource = function (it) {
925
- return functionToString(it);
926
- };
927
- }
928
-
929
- var inspectSource$1 = store.inspectSource;
930
-
931
- var uncurryThis$3 = functionUncurryThis;
932
- var fails$4 = fails$b;
933
- var isCallable$5 = isCallable$d;
934
- var hasOwn$3 = hasOwnProperty_1;
935
- var DESCRIPTORS$2 = descriptors;
936
- var CONFIGURABLE_FUNCTION_NAME$1 = functionName.CONFIGURABLE;
937
- var inspectSource = inspectSource$1;
938
- var InternalStateModule$1 = internalState;
939
-
940
- var enforceInternalState = InternalStateModule$1.enforce;
941
- var getInternalState$1 = InternalStateModule$1.get;
942
- var $String$1 = String;
943
- // eslint-disable-next-line es/no-object-defineproperty -- safe
944
- var defineProperty$3 = Object.defineProperty;
945
- var stringSlice = uncurryThis$3(''.slice);
946
- var replace = uncurryThis$3(''.replace);
947
- var join = uncurryThis$3([].join);
948
-
949
- var CONFIGURABLE_LENGTH = DESCRIPTORS$2 && !fails$4(function () {
950
- return defineProperty$3(function () { /* empty */ }, 'length', { value: 8 }).length !== 8;
951
- });
952
-
953
- var TEMPLATE = String(String).split('String');
954
-
955
- var makeBuiltIn$1 = makeBuiltIn$2.exports = function (value, name, options) {
956
- if (stringSlice($String$1(name), 0, 7) === 'Symbol(') {
957
- name = '[' + replace($String$1(name), /^Symbol\(([^)]*)\).*$/, '$1') + ']';
958
- }
959
- if (options && options.getter) name = 'get ' + name;
960
- if (options && options.setter) name = 'set ' + name;
961
- if (!hasOwn$3(value, 'name') || (CONFIGURABLE_FUNCTION_NAME$1 && value.name !== name)) {
962
- if (DESCRIPTORS$2) defineProperty$3(value, 'name', { value: name, configurable: true });
963
- else value.name = name;
964
- }
965
- if (CONFIGURABLE_LENGTH && options && hasOwn$3(options, 'arity') && value.length !== options.arity) {
966
- defineProperty$3(value, 'length', { value: options.arity });
967
- }
968
- try {
969
- if (options && hasOwn$3(options, 'constructor') && options.constructor) {
970
- if (DESCRIPTORS$2) defineProperty$3(value, 'prototype', { writable: false });
971
- // in V8 ~ Chrome 53, prototypes of some methods, like `Array.prototype.values`, are non-writable
972
- } else if (value.prototype) value.prototype = undefined;
973
- } catch (error) { /* empty */ }
974
- var state = enforceInternalState(value);
975
- if (!hasOwn$3(state, 'source')) {
976
- state.source = join(TEMPLATE, typeof name == 'string' ? name : '');
977
- } return value;
978
- };
979
-
980
- // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
981
- // eslint-disable-next-line no-extend-native -- required
982
- Function.prototype.toString = makeBuiltIn$1(function toString() {
983
- return isCallable$5(this) && getInternalState$1(this).source || inspectSource(this);
984
- }, 'toString');
985
-
986
- var isCallable$4 = isCallable$d;
987
- var definePropertyModule$1 = objectDefineProperty;
988
- var makeBuiltIn = makeBuiltIn$2.exports;
989
- var defineGlobalProperty$1 = defineGlobalProperty$3;
990
-
991
- var defineBuiltIn$3 = function (O, key, value, options) {
992
- if (!options) options = {};
993
- var simple = options.enumerable;
994
- var name = options.name !== undefined ? options.name : key;
995
- if (isCallable$4(value)) makeBuiltIn(value, name, options);
996
- if (options.global) {
997
- if (simple) O[key] = value;
998
- else defineGlobalProperty$1(key, value);
999
- } else {
1000
- try {
1001
- if (!options.unsafe) delete O[key];
1002
- else if (O[key]) simple = true;
1003
- } catch (error) { /* empty */ }
1004
- if (simple) O[key] = value;
1005
- else definePropertyModule$1.f(O, key, {
1006
- value: value,
1007
- enumerable: false,
1008
- configurable: !options.nonConfigurable,
1009
- writable: !options.nonWritable
1010
- });
1011
- } return O;
1012
- };
1013
-
1014
- var objectGetOwnPropertyNames = {};
1015
-
1016
- var internalObjectKeys = objectKeysInternal;
1017
- var enumBugKeys = enumBugKeys$3;
1018
-
1019
- var hiddenKeys = enumBugKeys.concat('length', 'prototype');
1020
-
1021
- // `Object.getOwnPropertyNames` method
1022
- // https://tc39.es/ecma262/#sec-object.getownpropertynames
1023
- // eslint-disable-next-line es/no-object-getownpropertynames -- safe
1024
- objectGetOwnPropertyNames.f = Object.getOwnPropertyNames || function getOwnPropertyNames(O) {
1025
- return internalObjectKeys(O, hiddenKeys);
1026
- };
1027
-
1028
- var objectGetOwnPropertySymbols = {};
1029
-
1030
- // eslint-disable-next-line es/no-object-getownpropertysymbols -- safe
1031
- objectGetOwnPropertySymbols.f = Object.getOwnPropertySymbols;
1032
-
1033
- var getBuiltIn = getBuiltIn$3;
1034
- var uncurryThis$2 = functionUncurryThis;
1035
- var getOwnPropertyNamesModule = objectGetOwnPropertyNames;
1036
- var getOwnPropertySymbolsModule$1 = objectGetOwnPropertySymbols;
1037
- var anObject = anObject$4;
1038
-
1039
- var concat$1 = uncurryThis$2([].concat);
1040
-
1041
- // all object keys, includes non-enumerable and symbols
1042
- var ownKeys$1 = getBuiltIn('Reflect', 'ownKeys') || function ownKeys(it) {
1043
- var keys = getOwnPropertyNamesModule.f(anObject(it));
1044
- var getOwnPropertySymbols = getOwnPropertySymbolsModule$1.f;
1045
- return getOwnPropertySymbols ? concat$1(keys, getOwnPropertySymbols(it)) : keys;
1046
- };
1047
-
1048
- var hasOwn$2 = hasOwnProperty_1;
1049
- var ownKeys = ownKeys$1;
1050
- var getOwnPropertyDescriptorModule = objectGetOwnPropertyDescriptor;
1051
- var definePropertyModule = objectDefineProperty;
1052
-
1053
- var copyConstructorProperties$1 = function (target, source, exceptions) {
1054
- var keys = ownKeys(source);
1055
- var defineProperty = definePropertyModule.f;
1056
- var getOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;
1057
- for (var i = 0; i < keys.length; i++) {
1058
- var key = keys[i];
1059
- if (!hasOwn$2(target, key) && !(exceptions && hasOwn$2(exceptions, key))) {
1060
- defineProperty(target, key, getOwnPropertyDescriptor(source, key));
1061
- }
1062
- }
1063
- };
1064
-
1065
- var fails$3 = fails$b;
1066
- var isCallable$3 = isCallable$d;
1067
-
1068
- var replacement = /#|\.prototype\./;
1069
-
1070
- var isForced$1 = function (feature, detection) {
1071
- var value = data[normalize(feature)];
1072
- return value === POLYFILL ? true
1073
- : value === NATIVE ? false
1074
- : isCallable$3(detection) ? fails$3(detection)
1075
- : !!detection;
1076
- };
1077
-
1078
- var normalize = isForced$1.normalize = function (string) {
1079
- return String(string).replace(replacement, '.').toLowerCase();
1080
- };
1081
-
1082
- var data = isForced$1.data = {};
1083
- var NATIVE = isForced$1.NATIVE = 'N';
1084
- var POLYFILL = isForced$1.POLYFILL = 'P';
1085
-
1086
- var isForced_1 = isForced$1;
1087
-
1088
- var global$2 = global$b;
1089
- var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f;
1090
- var createNonEnumerableProperty$2 = createNonEnumerableProperty$4;
1091
- var defineBuiltIn$2 = defineBuiltIn$3;
1092
- var defineGlobalProperty = defineGlobalProperty$3;
1093
- var copyConstructorProperties = copyConstructorProperties$1;
1094
- var isForced = isForced_1;
1095
-
1096
- /*
1097
- options.target - name of the target object
1098
- options.global - target is the global object
1099
- options.stat - export as static methods of target
1100
- options.proto - export as prototype methods of target
1101
- options.real - real prototype method for the `pure` version
1102
- options.forced - export even if the native feature is available
1103
- options.bind - bind methods to the target, required for the `pure` version
1104
- options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
1105
- options.unsafe - use the simple assignment of property instead of delete + defineProperty
1106
- options.sham - add a flag to not completely full polyfills
1107
- options.enumerable - export as enumerable property
1108
- options.dontCallGetSet - prevent calling a getter on target
1109
- options.name - the .name of the function if it does not match the key
1110
- */
1111
- var _export = function (options, source) {
1112
- var TARGET = options.target;
1113
- var GLOBAL = options.global;
1114
- var STATIC = options.stat;
1115
- var FORCED, target, key, targetProperty, sourceProperty, descriptor;
1116
- if (GLOBAL) {
1117
- target = global$2;
1118
- } else if (STATIC) {
1119
- target = global$2[TARGET] || defineGlobalProperty(TARGET, {});
1120
- } else {
1121
- target = global$2[TARGET] && global$2[TARGET].prototype;
1122
- }
1123
- if (target) for (key in source) {
1124
- sourceProperty = source[key];
1125
- if (options.dontCallGetSet) {
1126
- descriptor = getOwnPropertyDescriptor(target, key);
1127
- targetProperty = descriptor && descriptor.value;
1128
- } else targetProperty = target[key];
1129
- FORCED = isForced(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced);
1130
- // contained in target
1131
- if (!FORCED && targetProperty !== undefined) {
1132
- if (typeof sourceProperty == typeof targetProperty) continue;
1133
- copyConstructorProperties(sourceProperty, targetProperty);
1134
- }
1135
- // add a flag to not completely full polyfills
1136
- if (options.sham || (targetProperty && targetProperty.sham)) {
1137
- createNonEnumerableProperty$2(sourceProperty, 'sham', true);
1138
- }
1139
- defineBuiltIn$2(target, key, sourceProperty, options);
1140
- }
1141
- };
1142
-
1143
- var fails$2 = fails$b;
1144
-
1145
- var correctPrototypeGetter = !fails$2(function () {
1146
- function F() { /* empty */ }
1147
- F.prototype.constructor = null;
1148
- // eslint-disable-next-line es/no-object-getprototypeof -- required for testing
1149
- return Object.getPrototypeOf(new F()) !== F.prototype;
1150
- });
1151
-
1152
- var hasOwn$1 = hasOwnProperty_1;
1153
- var isCallable$2 = isCallable$d;
1154
- var toObject$1 = toObject$3;
1155
- var sharedKey = sharedKey$3;
1156
- var CORRECT_PROTOTYPE_GETTER = correctPrototypeGetter;
1157
-
1158
- var IE_PROTO = sharedKey('IE_PROTO');
1159
- var $Object = Object;
1160
- var ObjectPrototype = $Object.prototype;
1161
-
1162
- // `Object.getPrototypeOf` method
1163
- // https://tc39.es/ecma262/#sec-object.getprototypeof
1164
- // eslint-disable-next-line es/no-object-getprototypeof -- safe
1165
- var objectGetPrototypeOf = CORRECT_PROTOTYPE_GETTER ? $Object.getPrototypeOf : function (O) {
1166
- var object = toObject$1(O);
1167
- if (hasOwn$1(object, IE_PROTO)) return object[IE_PROTO];
1168
- var constructor = object.constructor;
1169
- if (isCallable$2(constructor) && object instanceof constructor) {
1170
- return constructor.prototype;
1171
- } return object instanceof $Object ? ObjectPrototype : null;
1172
- };
1173
-
1174
- var fails$1 = fails$b;
1175
- var isCallable$1 = isCallable$d;
1176
- var isObject$2 = isObject$8;
1177
- var getPrototypeOf$1 = objectGetPrototypeOf;
1178
- var defineBuiltIn$1 = defineBuiltIn$3;
1179
- var wellKnownSymbol$3 = wellKnownSymbol$6;
1180
-
1181
- var ITERATOR$2 = wellKnownSymbol$3('iterator');
1182
- var BUGGY_SAFARI_ITERATORS$1 = false;
1183
-
1184
- // `%IteratorPrototype%` object
1185
- // https://tc39.es/ecma262/#sec-%iteratorprototype%-object
1186
- var IteratorPrototype$2, PrototypeOfArrayIteratorPrototype, arrayIterator;
1187
-
1188
- /* eslint-disable es/no-array-prototype-keys -- safe */
1189
- if ([].keys) {
1190
- arrayIterator = [].keys();
1191
- // Safari 8 has buggy iterators w/o `next`
1192
- if (!('next' in arrayIterator)) BUGGY_SAFARI_ITERATORS$1 = true;
1193
- else {
1194
- PrototypeOfArrayIteratorPrototype = getPrototypeOf$1(getPrototypeOf$1(arrayIterator));
1195
- if (PrototypeOfArrayIteratorPrototype !== Object.prototype) IteratorPrototype$2 = PrototypeOfArrayIteratorPrototype;
1196
- }
1197
- }
1198
-
1199
- var NEW_ITERATOR_PROTOTYPE = !isObject$2(IteratorPrototype$2) || fails$1(function () {
1200
- var test = {};
1201
- // FF44- legacy iterators case
1202
- return IteratorPrototype$2[ITERATOR$2].call(test) !== test;
1203
- });
1204
-
1205
- if (NEW_ITERATOR_PROTOTYPE) IteratorPrototype$2 = {};
1206
-
1207
- // `%IteratorPrototype%[@@iterator]()` method
1208
- // https://tc39.es/ecma262/#sec-%iteratorprototype%-@@iterator
1209
- if (!isCallable$1(IteratorPrototype$2[ITERATOR$2])) {
1210
- defineBuiltIn$1(IteratorPrototype$2, ITERATOR$2, function () {
1211
- return this;
1212
- });
1213
- }
1214
-
1215
- var iteratorsCore = {
1216
- IteratorPrototype: IteratorPrototype$2,
1217
- BUGGY_SAFARI_ITERATORS: BUGGY_SAFARI_ITERATORS$1
1218
- };
1219
-
1220
- var defineProperty$2 = objectDefineProperty.f;
1221
- var hasOwn = hasOwnProperty_1;
1222
- var wellKnownSymbol$2 = wellKnownSymbol$6;
1223
-
1224
- var TO_STRING_TAG = wellKnownSymbol$2('toStringTag');
1225
-
1226
- var setToStringTag$3 = function (target, TAG, STATIC) {
1227
- if (target && !STATIC) target = target.prototype;
1228
- if (target && !hasOwn(target, TO_STRING_TAG)) {
1229
- defineProperty$2(target, TO_STRING_TAG, { configurable: true, value: TAG });
1230
- }
1231
- };
1232
-
1233
- var IteratorPrototype$1 = iteratorsCore.IteratorPrototype;
1234
- var create = objectCreate;
1235
- var createPropertyDescriptor = createPropertyDescriptor$3;
1236
- var setToStringTag$2 = setToStringTag$3;
1237
- var Iterators$2 = iterators;
1238
-
1239
- var returnThis$1 = function () { return this; };
1240
-
1241
- var iteratorCreateConstructor = function (IteratorConstructor, NAME, next, ENUMERABLE_NEXT) {
1242
- var TO_STRING_TAG = NAME + ' Iterator';
1243
- IteratorConstructor.prototype = create(IteratorPrototype$1, { next: createPropertyDescriptor(+!ENUMERABLE_NEXT, next) });
1244
- setToStringTag$2(IteratorConstructor, TO_STRING_TAG, false);
1245
- Iterators$2[TO_STRING_TAG] = returnThis$1;
1246
- return IteratorConstructor;
1247
- };
1248
-
1249
- var uncurryThis$1 = functionUncurryThis;
1250
- var aCallable = aCallable$2;
1251
-
1252
- var functionUncurryThisAccessor = function (object, key, method) {
1253
- try {
1254
- // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
1255
- return uncurryThis$1(aCallable(Object.getOwnPropertyDescriptor(object, key)[method]));
1256
- } catch (error) { /* empty */ }
1257
- };
1258
-
1259
- var isObject$1 = isObject$8;
1260
-
1261
- var isPossiblePrototype$1 = function (argument) {
1262
- return isObject$1(argument) || argument === null;
1263
- };
1264
-
1265
- var isPossiblePrototype = isPossiblePrototype$1;
1266
-
1267
- var $String = String;
1268
- var $TypeError = TypeError;
1269
-
1270
- var aPossiblePrototype$1 = function (argument) {
1271
- if (isPossiblePrototype(argument)) return argument;
1272
- throw new $TypeError("Can't set " + $String(argument) + ' as a prototype');
1273
- };
1274
-
1275
- /* eslint-disable no-proto -- safe */
1276
- var uncurryThisAccessor = functionUncurryThisAccessor;
1277
- var isObject = isObject$8;
1278
- var requireObjectCoercible = requireObjectCoercible$3;
1279
- var aPossiblePrototype = aPossiblePrototype$1;
1280
-
1281
- // `Object.setPrototypeOf` method
1282
- // https://tc39.es/ecma262/#sec-object.setprototypeof
1283
- // Works with __proto__ only. Old v8 can't work with null proto objects.
1284
- // eslint-disable-next-line es/no-object-setprototypeof -- safe
1285
- var objectSetPrototypeOf = Object.setPrototypeOf || ('__proto__' in {} ? function () {
1286
- var CORRECT_SETTER = false;
1287
- var test = {};
1288
- var setter;
1289
- try {
1290
- setter = uncurryThisAccessor(Object.prototype, '__proto__', 'set');
1291
- setter(test, []);
1292
- CORRECT_SETTER = test instanceof Array;
1293
- } catch (error) { /* empty */ }
1294
- return function setPrototypeOf(O, proto) {
1295
- requireObjectCoercible(O);
1296
- aPossiblePrototype(proto);
1297
- if (!isObject(O)) return O;
1298
- if (CORRECT_SETTER) setter(O, proto);
1299
- else O.__proto__ = proto;
1300
- return O;
1301
- };
1302
- }() : undefined);
1303
-
1304
- var $$1 = _export;
1305
- var call$1 = functionCall;
1306
- var FunctionName = functionName;
1307
- var isCallable = isCallable$d;
1308
- var createIteratorConstructor = iteratorCreateConstructor;
1309
- var getPrototypeOf = objectGetPrototypeOf;
1310
- var setPrototypeOf = objectSetPrototypeOf;
1311
- var setToStringTag$1 = setToStringTag$3;
1312
- var createNonEnumerableProperty$1 = createNonEnumerableProperty$4;
1313
- var defineBuiltIn = defineBuiltIn$3;
1314
- var wellKnownSymbol$1 = wellKnownSymbol$6;
1315
- var Iterators$1 = iterators;
1316
- var IteratorsCore = iteratorsCore;
1317
-
1318
- var PROPER_FUNCTION_NAME = FunctionName.PROPER;
1319
- var CONFIGURABLE_FUNCTION_NAME = FunctionName.CONFIGURABLE;
1320
- var IteratorPrototype = IteratorsCore.IteratorPrototype;
1321
- var BUGGY_SAFARI_ITERATORS = IteratorsCore.BUGGY_SAFARI_ITERATORS;
1322
- var ITERATOR$1 = wellKnownSymbol$1('iterator');
1323
- var KEYS = 'keys';
1324
- var VALUES = 'values';
1325
- var ENTRIES = 'entries';
1326
-
1327
- var returnThis = function () { return this; };
1328
-
1329
- var iteratorDefine = function (Iterable, NAME, IteratorConstructor, next, DEFAULT, IS_SET, FORCED) {
1330
- createIteratorConstructor(IteratorConstructor, NAME, next);
1331
-
1332
- var getIterationMethod = function (KIND) {
1333
- if (KIND === DEFAULT && defaultIterator) return defaultIterator;
1334
- if (!BUGGY_SAFARI_ITERATORS && KIND && KIND in IterablePrototype) return IterablePrototype[KIND];
1335
-
1336
- switch (KIND) {
1337
- case KEYS: return function keys() { return new IteratorConstructor(this, KIND); };
1338
- case VALUES: return function values() { return new IteratorConstructor(this, KIND); };
1339
- case ENTRIES: return function entries() { return new IteratorConstructor(this, KIND); };
1340
- }
1341
-
1342
- return function () { return new IteratorConstructor(this); };
1343
- };
1344
-
1345
- var TO_STRING_TAG = NAME + ' Iterator';
1346
- var INCORRECT_VALUES_NAME = false;
1347
- var IterablePrototype = Iterable.prototype;
1348
- var nativeIterator = IterablePrototype[ITERATOR$1]
1349
- || IterablePrototype['@@iterator']
1350
- || DEFAULT && IterablePrototype[DEFAULT];
1351
- var defaultIterator = !BUGGY_SAFARI_ITERATORS && nativeIterator || getIterationMethod(DEFAULT);
1352
- var anyNativeIterator = NAME === 'Array' ? IterablePrototype.entries || nativeIterator : nativeIterator;
1353
- var CurrentIteratorPrototype, methods, KEY;
1354
-
1355
- // fix native
1356
- if (anyNativeIterator) {
1357
- CurrentIteratorPrototype = getPrototypeOf(anyNativeIterator.call(new Iterable()));
1358
- if (CurrentIteratorPrototype !== Object.prototype && CurrentIteratorPrototype.next) {
1359
- if (getPrototypeOf(CurrentIteratorPrototype) !== IteratorPrototype) {
1360
- if (setPrototypeOf) {
1361
- setPrototypeOf(CurrentIteratorPrototype, IteratorPrototype);
1362
- } else if (!isCallable(CurrentIteratorPrototype[ITERATOR$1])) {
1363
- defineBuiltIn(CurrentIteratorPrototype, ITERATOR$1, returnThis);
1364
- }
1365
- }
1366
- // Set @@toStringTag to native iterators
1367
- setToStringTag$1(CurrentIteratorPrototype, TO_STRING_TAG, true);
1368
- }
1369
- }
1370
-
1371
- // fix Array.prototype.{ values, @@iterator }.name in V8 / FF
1372
- if (PROPER_FUNCTION_NAME && DEFAULT === VALUES && nativeIterator && nativeIterator.name !== VALUES) {
1373
- if (CONFIGURABLE_FUNCTION_NAME) {
1374
- createNonEnumerableProperty$1(IterablePrototype, 'name', VALUES);
1375
- } else {
1376
- INCORRECT_VALUES_NAME = true;
1377
- defaultIterator = function values() { return call$1(nativeIterator, this); };
1378
- }
1379
- }
1380
-
1381
- // export additional methods
1382
- if (DEFAULT) {
1383
- methods = {
1384
- values: getIterationMethod(VALUES),
1385
- keys: IS_SET ? defaultIterator : getIterationMethod(KEYS),
1386
- entries: getIterationMethod(ENTRIES)
1387
- };
1388
- if (FORCED) for (KEY in methods) {
1389
- if (BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME || !(KEY in IterablePrototype)) {
1390
- defineBuiltIn(IterablePrototype, KEY, methods[KEY]);
1391
- }
1392
- } else $$1({ target: NAME, proto: true, forced: BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME }, methods);
1393
- }
1394
-
1395
- // define iterator
1396
- if (IterablePrototype[ITERATOR$1] !== defaultIterator) {
1397
- defineBuiltIn(IterablePrototype, ITERATOR$1, defaultIterator, { name: DEFAULT });
1398
- }
1399
- Iterators$1[NAME] = defaultIterator;
1400
-
1401
- return methods;
1402
- };
1403
-
1404
- // `CreateIterResultObject` abstract operation
1405
- // https://tc39.es/ecma262/#sec-createiterresultobject
1406
- var createIterResultObject$1 = function (value, done) {
1407
- return { value: value, done: done };
1408
- };
1409
-
1410
- var toIndexedObject = toIndexedObject$5;
1411
- var addToUnscopables = addToUnscopables$1;
1412
- var Iterators = iterators;
1413
- var InternalStateModule = internalState;
1414
- var defineProperty$1 = objectDefineProperty.f;
1415
- var defineIterator = iteratorDefine;
1416
- var createIterResultObject = createIterResultObject$1;
1417
- var DESCRIPTORS$1 = descriptors;
1418
-
1419
- var ARRAY_ITERATOR = 'Array Iterator';
1420
- var setInternalState = InternalStateModule.set;
1421
- var getInternalState = InternalStateModule.getterFor(ARRAY_ITERATOR);
1422
-
1423
- // `Array.prototype.entries` method
1424
- // https://tc39.es/ecma262/#sec-array.prototype.entries
1425
- // `Array.prototype.keys` method
1426
- // https://tc39.es/ecma262/#sec-array.prototype.keys
1427
- // `Array.prototype.values` method
1428
- // https://tc39.es/ecma262/#sec-array.prototype.values
1429
- // `Array.prototype[@@iterator]` method
1430
- // https://tc39.es/ecma262/#sec-array.prototype-@@iterator
1431
- // `CreateArrayIterator` internal method
1432
- // https://tc39.es/ecma262/#sec-createarrayiterator
1433
- var es_array_iterator = defineIterator(Array, 'Array', function (iterated, kind) {
1434
- setInternalState(this, {
1435
- type: ARRAY_ITERATOR,
1436
- target: toIndexedObject(iterated), // target
1437
- index: 0, // next index
1438
- kind: kind // kind
1439
- });
1440
- // `%ArrayIteratorPrototype%.next` method
1441
- // https://tc39.es/ecma262/#sec-%arrayiteratorprototype%.next
1442
- }, function () {
1443
- var state = getInternalState(this);
1444
- var target = state.target;
1445
- var index = state.index++;
1446
- if (!target || index >= target.length) {
1447
- state.target = undefined;
1448
- return createIterResultObject(undefined, true);
1449
- }
1450
- switch (state.kind) {
1451
- case 'keys': return createIterResultObject(index, false);
1452
- case 'values': return createIterResultObject(target[index], false);
1453
- } return createIterResultObject([index, target[index]], false);
1454
- }, 'values');
1455
-
1456
- // argumentsList[@@iterator] is %ArrayProto_values%
1457
- // https://tc39.es/ecma262/#sec-createunmappedargumentsobject
1458
- // https://tc39.es/ecma262/#sec-createmappedargumentsobject
1459
- var values = Iterators.Arguments = Iterators.Array;
1460
-
1461
- // https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
1462
- addToUnscopables('keys');
1463
- addToUnscopables('values');
1464
- addToUnscopables('entries');
1465
-
1466
- // V8 ~ Chrome 45- bug
1467
- if (DESCRIPTORS$1 && values.name !== 'values') try {
1468
- defineProperty$1(values, 'name', { value: 'values' });
1469
- } catch (error) { /* empty */ }
1470
-
1471
- // iterable DOM collections
1472
- // flag - `iterable` interface - 'entries', 'keys', 'values', 'forEach' methods
1473
- var domIterables = {
1474
- CSSRuleList: 0,
1475
- CSSStyleDeclaration: 0,
1476
- CSSValueList: 0,
1477
- ClientRectList: 0,
1478
- DOMRectList: 0,
1479
- DOMStringList: 0,
1480
- DOMTokenList: 1,
1481
- DataTransferItemList: 0,
1482
- FileList: 0,
1483
- HTMLAllCollection: 0,
1484
- HTMLCollection: 0,
1485
- HTMLFormElement: 0,
1486
- HTMLSelectElement: 0,
1487
- MediaList: 0,
1488
- MimeTypeArray: 0,
1489
- NamedNodeMap: 0,
1490
- NodeList: 1,
1491
- PaintRequestList: 0,
1492
- Plugin: 0,
1493
- PluginArray: 0,
1494
- SVGLengthList: 0,
1495
- SVGNumberList: 0,
1496
- SVGPathSegList: 0,
1497
- SVGPointList: 0,
1498
- SVGStringList: 0,
1499
- SVGTransformList: 0,
1500
- SourceBufferList: 0,
1501
- StyleSheetList: 0,
1502
- TextTrackCueList: 0,
1503
- TextTrackList: 0,
1504
- TouchList: 0
1505
- };
1506
-
1507
- // in old WebKit versions, `element.classList` is not an instance of global `DOMTokenList`
1508
- var documentCreateElement = documentCreateElement$2;
1509
-
1510
- var classList = documentCreateElement('span').classList;
1511
- var DOMTokenListPrototype$1 = classList && classList.constructor && classList.constructor.prototype;
1512
-
1513
- var domTokenListPrototype = DOMTokenListPrototype$1 === Object.prototype ? undefined : DOMTokenListPrototype$1;
1514
-
1515
- var global$1 = global$b;
1516
- var DOMIterables = domIterables;
1517
- var DOMTokenListPrototype = domTokenListPrototype;
1518
- var ArrayIteratorMethods = es_array_iterator;
1519
- var createNonEnumerableProperty = createNonEnumerableProperty$4;
1520
- var setToStringTag = setToStringTag$3;
1521
- var wellKnownSymbol = wellKnownSymbol$6;
1522
-
1523
- var ITERATOR = wellKnownSymbol('iterator');
1524
- var ArrayValues = ArrayIteratorMethods.values;
1525
-
1526
- var handlePrototype = function (CollectionPrototype, COLLECTION_NAME) {
1527
- if (CollectionPrototype) {
1528
- // some Chrome versions have non-configurable methods on DOMTokenList
1529
- if (CollectionPrototype[ITERATOR] !== ArrayValues) try {
1530
- createNonEnumerableProperty(CollectionPrototype, ITERATOR, ArrayValues);
1531
- } catch (error) {
1532
- CollectionPrototype[ITERATOR] = ArrayValues;
1533
- }
1534
- setToStringTag(CollectionPrototype, COLLECTION_NAME, true);
1535
- if (DOMIterables[COLLECTION_NAME]) for (var METHOD_NAME in ArrayIteratorMethods) {
1536
- // some Chrome versions have non-configurable methods on DOMTokenList
1537
- if (CollectionPrototype[METHOD_NAME] !== ArrayIteratorMethods[METHOD_NAME]) try {
1538
- createNonEnumerableProperty(CollectionPrototype, METHOD_NAME, ArrayIteratorMethods[METHOD_NAME]);
1539
- } catch (error) {
1540
- CollectionPrototype[METHOD_NAME] = ArrayIteratorMethods[METHOD_NAME];
1541
- }
1542
- }
1543
- }
1544
- };
1545
-
1546
- for (var COLLECTION_NAME in DOMIterables) {
1547
- handlePrototype(global$1[COLLECTION_NAME] && global$1[COLLECTION_NAME].prototype, COLLECTION_NAME);
1548
- }
1549
-
1550
- handlePrototype(DOMTokenListPrototype, 'DOMTokenList');
1551
-
1552
- var DESCRIPTORS = descriptors;
1553
- var uncurryThis = functionUncurryThis;
1554
- var call = functionCall;
1555
- var fails = fails$b;
1556
- var objectKeys = objectKeys$2;
1557
- var getOwnPropertySymbolsModule = objectGetOwnPropertySymbols;
1558
- var propertyIsEnumerableModule = objectPropertyIsEnumerable;
1559
- var toObject = toObject$3;
1560
- var IndexedObject = indexedObject;
1561
-
1562
- // eslint-disable-next-line es/no-object-assign -- safe
1563
- var $assign = Object.assign;
1564
- // eslint-disable-next-line es/no-object-defineproperty -- required for testing
1565
- var defineProperty = Object.defineProperty;
1566
- var concat = uncurryThis([].concat);
1567
-
1568
- // `Object.assign` method
1569
- // https://tc39.es/ecma262/#sec-object.assign
1570
- var objectAssign = !$assign || fails(function () {
1571
- // should have correct order of operations (Edge bug)
1572
- if (DESCRIPTORS && $assign({ b: 1 }, $assign(defineProperty({}, 'a', {
1573
- enumerable: true,
1574
- get: function () {
1575
- defineProperty(this, 'b', {
1576
- value: 3,
1577
- enumerable: false
1578
- });
1579
- }
1580
- }), { b: 2 })).b !== 1) return true;
1581
- // should work with symbols and should have deterministic property order (V8 bug)
1582
- var A = {};
1583
- var B = {};
1584
- // eslint-disable-next-line es/no-symbol -- safe
1585
- var symbol = Symbol('assign detection');
1586
- var alphabet = 'abcdefghijklmnopqrst';
1587
- A[symbol] = 7;
1588
- alphabet.split('').forEach(function (chr) { B[chr] = chr; });
1589
- return $assign({}, A)[symbol] !== 7 || objectKeys($assign({}, B)).join('') !== alphabet;
1590
- }) ? function assign(target, source) { // eslint-disable-line no-unused-vars -- required for `.length`
1591
- var T = toObject(target);
1592
- var argumentsLength = arguments.length;
1593
- var index = 1;
1594
- var getOwnPropertySymbols = getOwnPropertySymbolsModule.f;
1595
- var propertyIsEnumerable = propertyIsEnumerableModule.f;
1596
- while (argumentsLength > index) {
1597
- var S = IndexedObject(arguments[index++]);
1598
- var keys = getOwnPropertySymbols ? concat(objectKeys(S), getOwnPropertySymbols(S)) : objectKeys(S);
1599
- var length = keys.length;
1600
- var j = 0;
1601
- var key;
1602
- while (length > j) {
1603
- key = keys[j++];
1604
- if (!DESCRIPTORS || call(propertyIsEnumerable, S, key)) T[key] = S[key];
1605
- }
1606
- } return T;
1607
- } : $assign;
1608
-
1609
- var $ = _export;
1610
- var assign = objectAssign;
1611
-
1612
- // `Object.assign` method
1613
- // https://tc39.es/ecma262/#sec-object.assign
1614
- // eslint-disable-next-line es/no-object-assign -- required for testing
1615
- $({ target: 'Object', stat: true, arity: 2, forced: Object.assign !== assign }, {
1616
- assign: assign
1617
- });
1618
-
1619
- const BuildSchemaAsFields = ({
1620
- components,
1621
- mappers,
1622
- formIndex,
1623
- mountedForm
1624
- }) => {
1625
- return components && components.map(component => {
1626
- const mapper = mappers === null || mappers === void 0 ? void 0 : mappers.find(el => el.componentName === component.component);
1627
- return mapper ? jsx(AsFormFieldBuilder, Object.assign({
1628
- formIndex: formIndex,
1629
- mapper: mapper,
1630
- formMounted: mountedForm
1631
- }, component, {
1632
- children: component.children && component.children.length > 0 && jsx(BuildSchemaAsFields, {
1633
- formIndex: formIndex,
1634
- mappers: mappers,
1635
- components: component.children,
1636
- mountedForm: mountedForm
1637
- })
1638
- }), component.name) : jsx("div", {
1639
- children: `component mapper not found for ${component.component} from field name ${component.name} on form ${formIndex}`
1640
- }, component.name);
1641
- });
6
+ /******************************************************************************
7
+ Copyright (c) Microsoft Corporation.
8
+
9
+ Permission to use, copy, modify, and/or distribute this software for any
10
+ purpose with or without fee is hereby granted.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
13
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
15
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
17
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18
+ PERFORMANCE OF THIS SOFTWARE.
19
+ ***************************************************************************** */
20
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
21
+
22
+
23
+ function __rest(s, e) {
24
+ var t = {};
25
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
26
+ t[p] = s[p];
27
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
28
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
29
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
30
+ t[p[i]] = s[p[i]];
31
+ }
32
+ return t;
33
+ }
34
+
35
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
36
+ var e = new Error(message);
37
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1642
38
  };
1643
39
 
1644
40
  const FormGroupContext = /*#__PURE__*/createContext({});
@@ -1654,8 +50,10 @@ const IsolatedContext = ({
1654
50
  config
1655
51
  }) => {
1656
52
  const formGroupInstance = useRef(new FormGroup({
1657
- config
53
+ config,
54
+ mappers
1658
55
  }));
56
+ const formGroupContextMountRef = useRef(false);
1659
57
  const addFormWithIndex = index => {
1660
58
  formGroupInstance.current.createFormWithIndex({
1661
59
  index,
@@ -1664,11 +62,11 @@ const IsolatedContext = ({
1664
62
  };
1665
63
  const addForm = ({
1666
64
  key,
1667
- formInstance
65
+ params
1668
66
  }) => {
1669
67
  formGroupInstance.current.addForm({
1670
68
  key,
1671
- formInstance
69
+ params
1672
70
  });
1673
71
  };
1674
72
  const removeForm = ({
@@ -1686,9 +84,23 @@ const IsolatedContext = ({
1686
84
  const printFormGroupInstance = () => {
1687
85
  console.log(formGroupInstance.current.printFormGroupInstance());
1688
86
  };
1689
- function submitMultipleFormsByIndex(indexes) {
1690
- return formGroupInstance.current.submitMultipleFormsByIndex(indexes);
87
+ function submitMultipleFormsByIndex(indexes, callback) {
88
+ return formGroupInstance.current.submitMultipleFormsByIndex(indexes, callback);
1691
89
  }
90
+ useEffect(() => {
91
+ return () => {
92
+ if (formGroupContextMountRef.current) {
93
+ // strictMode made me do this, Beato Carlo Acutis please forgive me
94
+ // eslint-disable-next-line react-hooks/exhaustive-deps
95
+ formGroupInstance.current.destroy();
96
+ }
97
+ };
98
+ }, []);
99
+ useEffect(() => {
100
+ return () => {
101
+ formGroupContextMountRef.current = true;
102
+ };
103
+ }, []);
1692
104
  return {
1693
105
  addFormWithIndex,
1694
106
  addForm,
@@ -1703,82 +115,338 @@ const IsolatedContext = ({
1703
115
  };
1704
116
  };
1705
117
  /**
1706
- * context provider to wrap form-engine adapter elements
118
+ * context provider to wrap form-engine adapter elements
119
+ *
120
+ * @param {PropsWithChildren<TFormContextProvider>} param context parameters
121
+ * @returns {ReactElement}
122
+ */
123
+ const FormGroupContextProvider = ({
124
+ children,
125
+ mappers,
126
+ debugMode: _debugMode2 = false,
127
+ config
128
+ }) => {
129
+ const contextValue = IsolatedContext({
130
+ mappers,
131
+ debugMode: _debugMode2,
132
+ config
133
+ });
134
+ contextValue.debugMode = _debugMode2;
135
+ contextValue.active = true;
136
+ contextValue.config = config;
137
+ return jsxs(FormGroupContext.Provider, {
138
+ value: contextValue,
139
+ children: [_debugMode2 && jsxs(Fragment, {
140
+ children: [jsx("button", {
141
+ onClick: () => console.log(contextValue.formGroupInstance),
142
+ children: "printGroupInstance"
143
+ }), jsx("br", {}), jsx("hr", {})]
144
+ }), children]
145
+ });
146
+ };
147
+ /**
148
+ * FormGroup context hook to handle context or isolated context implementations
149
+ *
150
+ * @param {TFormContextProvider} props form group context parameters
151
+ * @returns {TFormContext}
152
+ */
153
+ const useFormGroupContext = props => {
154
+ const context = useContext(FormGroupContext);
155
+ if (Object.keys(context).length === 0 && props) {
156
+ return IsolatedContext({
157
+ debugMode: props.debugMode,
158
+ mappers: props.mappers
159
+ });
160
+ }
161
+ return context;
162
+ };
163
+
164
+ /**
165
+ * Renders the React element defined on the mappers configuration
166
+ *
167
+ * @param param component props, field instance and children to render
168
+ * @returns
169
+ */
170
+ const FieldWrapperComponentRender = ({
171
+ props,
172
+ fieldInstance,
173
+ children,
174
+ mapper
175
+ }) => {
176
+ var _a, _b, _c;
177
+ const Component = (mapper === null || mapper === void 0 ? void 0 : mapper.component) || ((_a = fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.mapper) === null || _a === void 0 ? void 0 : _a.component);
178
+ const Asynccomponent = (mapper === null || mapper === void 0 ? void 0 : mapper.asynccomponent) || ((_b = fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.mapper) === null || _b === void 0 ? void 0 : _b.asynccomponent);
179
+ if (Component) return jsx(Component, Object.assign({}, props, {
180
+ children: children && children
181
+ }));
182
+ if (Asynccomponent) return jsx(Suspense, {
183
+ children: jsx(Asynccomponent, Object.assign({}, props, {
184
+ children: children && children
185
+ }))
186
+ });
187
+ return jsx("div", {
188
+ children: `failed to render field ${fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.name} with componentName:${(_c = fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.mapper) === null || _c === void 0 ? void 0 : _c.componentName}, please check mappers`
189
+ });
190
+ };
191
+ /**
192
+ * Base field Wrapper to render the component with the necessary configurations from the schema
193
+ * and mapper configuration
1707
194
  *
1708
- * @param {PropsWithChildren<TFormContextProvider>} param context parameters
195
+ * @param {TFieldWrapperProps} param FieldWrapper params
1709
196
  * @returns {ReactElement}
1710
197
  */
1711
- const FormGroupContextProvider = ({
198
+ const FieldWrapper = ({
199
+ name,
200
+ formIndex,
1712
201
  children,
1713
- mappers,
1714
- debugMode: _debugMode2 = false,
1715
- config
202
+ props,
203
+ context,
204
+ mounted,
205
+ mapper,
206
+ visibility,
207
+ component
1716
208
  }) => {
1717
- const contextValue = IsolatedContext({
1718
- mappers,
1719
- debugMode: _debugMode2,
1720
- config
209
+ var _a, _b, _c;
210
+ const localContext = useFormGroupContext({});
211
+ const fieldMapper = mapper || ((_a = localContext.mappers) === null || _a === void 0 ? void 0 : _a.find(mapper => mapper.componentName === component));
212
+ /**
213
+ * picks the right context prioritizing the context passed as prop
214
+ */
215
+ const {
216
+ formGroupInstance,
217
+ debugMode
218
+ } = useMemo(() => context ? context : localContext, [context, localContext]);
219
+ /**
220
+ * retrieves the field instance when it's mounted
221
+ */
222
+ const fieldInstance = useMemo(() => {
223
+ var _a;
224
+ return (_a = formGroupInstance.getForm({
225
+ key: formIndex
226
+ })) === null || _a === void 0 ? void 0 : _a.getField({
227
+ key: name
228
+ });
229
+ }, [mounted]);
230
+ /**
231
+ * props with templates stripped until the field isn't ready on the instance
232
+ */
233
+ const filteredProps = useMemo(() => {
234
+ return FormField.filterProps(props);
235
+ }, []);
236
+ /**
237
+ * sends props changed on the adapter for comparison to effectively change props for the instance
238
+ */
239
+ useEffect(() => {
240
+ if (fieldInstance && props) fieldInstance.adapterProps = props;
241
+ }, [props]);
242
+ const [valueState, setValueState] = useState((fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.stateValue) || {
243
+ [((_b = fieldMapper === null || fieldMapper === void 0 ? void 0 : fieldMapper.events) === null || _b === void 0 ? void 0 : _b.setValue) || 'value']: ''
1721
244
  });
1722
- contextValue.debugMode = _debugMode2;
1723
- contextValue.active = true;
1724
- contextValue.config = config;
1725
- return jsxs(FormGroupContext.Provider, {
1726
- value: contextValue,
1727
- children: [_debugMode2 && jsxs(Fragment, {
1728
- children: [jsx("button", {
1729
- onClick: () => console.log(contextValue.formGroupInstance),
1730
- children: "printGroupInstance"
1731
- }), jsx("br", {}), jsx("hr", {})]
1732
- }), children]
245
+ const [state, setState] = useState({
246
+ visibility: typeof visibility === 'boolean' ? visibility : true,
247
+ props: filteredProps
1733
248
  });
249
+ /**
250
+ * handles the mounting and unmounting logic onto the field instance
251
+ */
252
+ useEffect(() => {
253
+ if (!fieldInstance || (fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.mounted)) return;
254
+ fieldInstance.mountField({
255
+ valueSubscription: value => {
256
+ setValueState(value);
257
+ },
258
+ propsSubscription: ({
259
+ visibility,
260
+ props,
261
+ errors
262
+ }) => {
263
+ setState(prev => Object.assign(Object.assign({}, prev), {
264
+ visibility,
265
+ props,
266
+ errors
267
+ }));
268
+ }
269
+ });
270
+ }, [fieldInstance]);
271
+ /**
272
+ * recycle effect to remove the field Subscriptions due to memory leaks
273
+ */
274
+ useEffect(() => {
275
+ return () => {
276
+ (fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.mounted) && (fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.destroyField());
277
+ };
278
+ }, []);
279
+ /**
280
+ * handles the value change onto the field instance
281
+ */
282
+ const handleChange = useCallback(event => {
283
+ if (!mounted) return;
284
+ fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.emitValue({
285
+ value: event,
286
+ event: 'ON_FIELD_CHANGE'
287
+ });
288
+ }, [mounted]);
289
+ /**
290
+ * handles the event emission onto the field instance
291
+ */
292
+ const handleEvent = useCallback(event => {
293
+ if (!mounted) return;
294
+ fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.emitEvents({
295
+ event
296
+ });
297
+ }, [mounted]);
298
+ /**
299
+ * handles the mappers configuration to bind the event submission callback
300
+ * to the corresponding prop defined on the mappers
301
+ */
302
+ const mapProps = useMemo(() => {
303
+ const events = fieldMapper === null || fieldMapper === void 0 ? void 0 : fieldMapper.events;
304
+ const props = {};
305
+ if (events === null || events === void 0 ? void 0 : events.onBlur) props[events.onBlur] = () => handleEvent('ON_FIELD_BLUR');
306
+ if (events === null || events === void 0 ? void 0 : events.getValue) props[events.getValue] = handleChange;
307
+ if (events === null || events === void 0 ? void 0 : events.onFocus) props[events.onFocus] = () => handleEvent('ON_FIELD_FOCUS');
308
+ if (events === null || events === void 0 ? void 0 : events.onClick) props[events.onClick] = () => handleEvent('ON_FIELD_CLICK');
309
+ if (events === null || events === void 0 ? void 0 : events.onSubmit) props[events.onSubmit] = () => handleEvent('ON_FORM_SUBMIT');
310
+ if (events === null || events === void 0 ? void 0 : events.onKeyUp) props[events.onKeyUp] = () => handleEvent('ON_FIELD_KEYUP');
311
+ if (events === null || events === void 0 ? void 0 : events.onKeyDown) props[events.onKeyDown] = () => handleEvent('ON_FIELD_KEYDOWN');
312
+ return props;
313
+ }, [mounted]);
314
+ return state.visibility ? jsxs(Fragment, {
315
+ children: [debugMode && jsxs("div", {
316
+ style: {
317
+ width: '100%',
318
+ display: 'flex',
319
+ flexDirection: 'column'
320
+ },
321
+ children: [jsxs("b", {
322
+ style: {
323
+ padding: '0px',
324
+ margin: '0px'
325
+ },
326
+ children: ["name:", name]
327
+ }), jsx("br", {}), jsx("hr", {})]
328
+ }), jsx(FieldWrapperComponentRender, {
329
+ props: Object.assign(Object.assign(Object.assign(Object.assign({}, mapProps), state.props), state.errors), valueState),
330
+ fieldInstance: fieldInstance,
331
+ mapper: fieldMapper,
332
+ children: children ? children : ((_c = state === null || state === void 0 ? void 0 : state.props) === null || _c === void 0 ? void 0 : _c.children) ? state === null || state === void 0 ? void 0 : state.props.children : null
333
+ })]
334
+ }) : jsx(Fragment, {});
1734
335
  };
336
+
1735
337
  /**
1736
- * FormGroup context hook to handle context or isolated context implementations
338
+ * Component Wrapper to render form fields without the Form component, gets additional formId and mapper since
339
+ * it won't rely on them and needs to be manually declared
1737
340
  *
1738
- * @param {TFormContextProvider} props form group context parameters
1739
- * @returns {TFormContext}
341
+ * @param {TAsFormFieldBuilderProps} props JSON schema props along with FieldWrapper props and mapper props
342
+ * @returns {ReactElement}
1740
343
  */
1741
- const useFormGroupContext = props => {
1742
- const context = useContext(FormGroupContext);
1743
- if (Object.keys(context).length === 0 && props) {
1744
- return IsolatedContext({
1745
- debugMode: props.debugMode,
1746
- mappers: props.mappers
344
+ const AsFormFieldBuilder = props => {
345
+ const context = useFormGroupContext({});
346
+ /**
347
+ * state to track the field instance mounting (client-side reactivity activation)
348
+ */
349
+ const [mounted, setMounted] = useState(false);
350
+ const mountedRef = useRef(false);
351
+ /**
352
+ * initializer to create or add a form instance to the formGroup by it's formId
353
+ * and add the field to the form instance
354
+ */
355
+ useEffect(() => {
356
+ var _a, _b;
357
+ if (mountedRef.current) return;
358
+ if (typeof props.formMounted === 'undefined' && !((_a = context.formGroupInstance) === null || _a === void 0 ? void 0 : _a.forms.has(props.formIndex))) {
359
+ context.addFormWithIndex(props.formIndex);
360
+ }
361
+ if (props.formMounted || typeof props.formMounted === 'undefined') {
362
+ const formInstance = context.formGroupInstance.forms.get(props.formIndex);
363
+ if (formInstance && !formInstance.fields.has(props.name)) {
364
+ const fieldSchema = Object.assign(Object.assign({}, props), {
365
+ component: ((_b = props.mapper) === null || _b === void 0 ? void 0 : _b.componentName) || props.component,
366
+ children: undefined
367
+ });
368
+ formInstance.addField({
369
+ fieldSchema,
370
+ mapperElement: props.mapper
371
+ });
372
+ }
373
+ setMounted(true);
374
+ mountedRef.current = true;
375
+ }
376
+ }, [props.formMounted]);
377
+ /**
378
+ * recycle effect to remove the field from the form instance when the field leaves the vDOM
379
+ * and the subscriptions
380
+ */
381
+ useEffect(() => {
382
+ return () => {
383
+ var _a, _b;
384
+ if ((_b = (_a = context.getForm({
385
+ key: props.formIndex
386
+ })) === null || _a === void 0 ? void 0 : _a.getField({
387
+ key: props.name
388
+ })) === null || _b === void 0 ? void 0 : _b.mounted) context.formGroupInstance.removeField({
389
+ formIndex: props.formIndex,
390
+ fieldIndex: props.name
391
+ });
392
+ };
393
+ }, []);
394
+ /**
395
+ * allows to control field selected value on each event
396
+ */
397
+ useEffect(() => {
398
+ var _a;
399
+ if (!props.onSelected) return;
400
+ const callback = payload => {
401
+ if (props.onSelected) {
402
+ props.onSelected(payload);
403
+ }
404
+ };
405
+ const sub = (_a = context.formGroupInstance.forms.get(props.formIndex)) === null || _a === void 0 ? void 0 : _a.subscribeFieldEvent({
406
+ callback
1747
407
  });
1748
- }
1749
- return context;
408
+ return () => sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
409
+ }, [props.onSelected]);
410
+ return jsx(FieldWrapper, {
411
+ formIndex: props.formIndex,
412
+ name: props.name,
413
+ props: props.props,
414
+ context: !context.active ? context : null,
415
+ mounted: mounted,
416
+ mapper: props.mapper,
417
+ visibility: props.visibility,
418
+ component: props.component,
419
+ children: props.children && props.children
420
+ });
1750
421
  };
1751
422
 
1752
- /******************************************************************************
1753
- Copyright (c) Microsoft Corporation.
1754
-
1755
- Permission to use, copy, modify, and/or distribute this software for any
1756
- purpose with or without fee is hereby granted.
1757
-
1758
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1759
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1760
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1761
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1762
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1763
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1764
- PERFORMANCE OF THIS SOFTWARE.
1765
- ***************************************************************************** */
1766
-
1767
- function __rest(s, e) {
1768
- var t = {};
1769
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
1770
- t[p] = s[p];
1771
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
1772
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
1773
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
1774
- t[p[i]] = s[p[i]];
1775
- }
1776
- return t;
1777
- }
1778
-
1779
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1780
- var e = new Error(message);
1781
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
423
+ const BuildSchemaAsFields = ({
424
+ components,
425
+ mappers,
426
+ formIndex,
427
+ mountedForm
428
+ }) => {
429
+ return components && components.map(_a => {
430
+ var {
431
+ component
432
+ } = _a,
433
+ componentEl = __rest(_a, ["component"]);
434
+ const mapper = mappers === null || mappers === void 0 ? void 0 : mappers.find(el => el.componentName === component);
435
+ return mapper ? jsx(AsFormFieldBuilder, Object.assign({
436
+ formIndex: formIndex,
437
+ mapper: mapper,
438
+ formMounted: mountedForm
439
+ }, componentEl, {
440
+ children: componentEl.children && componentEl.children.length > 0 && jsx(BuildSchemaAsFields, {
441
+ formIndex: formIndex,
442
+ mappers: mappers,
443
+ components: componentEl.children,
444
+ mountedForm: mountedForm
445
+ })
446
+ }), componentEl.name) : jsx("div", {
447
+ children: `component mapper not found for ${component} from field name ${componentEl.name} on form ${formIndex}`
448
+ }, componentEl.name);
449
+ });
1782
450
  };
1783
451
 
1784
452
  /**
@@ -1791,8 +459,20 @@ const eventsMapping = {
1791
459
  ON_FIELD_KEYDOWN: 'onKeyDown',
1792
460
  ON_FIELD_KEYUP: 'onKeyUp',
1793
461
  ON_FIELD_MOUNT: 'onMount',
462
+ ON_API_FIELD_REQUEST: 'onApiRequest',
1794
463
  ON_API_FIELD_RESPONSE: 'onApiResponse',
1795
- ON_FIELD_CLICK: 'onClick'
464
+ ON_FIELD_CLICK: 'onClick',
465
+ ON_FIELD_CLEARED: 'onCleared',
466
+ ON_FIELD_UNMOUNT: 'onUnmount'
467
+ };
468
+ const uniqueIdGen = () => {
469
+ const timestamp = +new Date();
470
+ const rand = Math.random() * 1e5;
471
+ const finalNumb = timestamp * rand;
472
+ const string = (Math.random() + 1).toString(36).substring(7);
473
+ const mixedID = finalNumb + string + '-';
474
+ const shuffle = str => [...str].sort(() => Math.random() - 0.5).join('');
475
+ return shuffle(mixedID);
1796
476
  };
1797
477
 
1798
478
  /**
@@ -1801,15 +481,56 @@ const eventsMapping = {
1801
481
  function useForm(_a, deps) {
1802
482
  var {
1803
483
  id,
484
+ index,
1804
485
  onData,
1805
486
  onSubmit,
1806
487
  onFormMount,
1807
- onValid
488
+ onValid,
489
+ iVars,
490
+ initialValues,
491
+ stopEventsOnSubmit
1808
492
  } = _a,
1809
- rest = __rest(_a, ["id", "onData", "onSubmit", "onFormMount", "onValid"]);
493
+ rest = __rest(_a, ["id", "index", "onData", "onSubmit", "onFormMount", "onValid", "iVars", "initialValues", "stopEventsOnSubmit"]);
1810
494
  const {
1811
495
  formGroupInstance
1812
496
  } = useFormGroupContext({});
497
+ const useFormIndex = index || id;
498
+ if (!useFormIndex) {
499
+ throw new Error('useForm hook must have an id or an index');
500
+ }
501
+ useEffect(() => {
502
+ if (!formGroupInstance.forms.has(useFormIndex)) {
503
+ console.log('failed to set stopEventsOnSubmit due to no form instance');
504
+ return;
505
+ }
506
+ if (typeof stopEventsOnSubmit === 'boolean') {
507
+ formGroupInstance.getForm({
508
+ key: useFormIndex
509
+ }).stopEventsOnSubmit = stopEventsOnSubmit;
510
+ }
511
+ }, []);
512
+ /**
513
+ * iVars change tracker to update iVars onto form instance
514
+ */
515
+ useEffect(() => {
516
+ if (!formGroupInstance.forms.has(useFormIndex)) {
517
+ console.log('failed to add iVars due to no form instance');
518
+ return;
519
+ }
520
+ if (iVars) formGroupInstance.forms.get(useFormIndex).iVars = iVars;
521
+ // if (iVars) formInstance.current.iVars = iVars;
522
+ }, [iVars]);
523
+ /**
524
+ * initialValues setter for async initialValues
525
+ */
526
+ useEffect(() => {
527
+ if (!formGroupInstance.forms.has(useFormIndex)) {
528
+ console.log('failed to add initialValues due to no form instance');
529
+ return;
530
+ }
531
+ if (initialValues) formGroupInstance.forms.get(useFormIndex).initialValues = initialValues;
532
+ // if (initialValues) formInstance.current.initialValues = initialValues;
533
+ }, [initialValues]);
1813
534
  /**
1814
535
  * reference to store all updated callback functions rerendered by props change
1815
536
  */
@@ -1846,7 +567,7 @@ function useForm(_a, deps) {
1846
567
  }
1847
568
  };
1848
569
  const sub = (_a = formGroupInstance.getForm({
1849
- key: id
570
+ key: useFormIndex
1850
571
  })) === null || _a === void 0 ? void 0 : _a.subscribeFieldEvent({
1851
572
  callback
1852
573
  });
@@ -1857,7 +578,7 @@ function useForm(_a, deps) {
1857
578
  }
1858
579
  };
1859
580
  const mountSub = (_b = formGroupInstance.getForm({
1860
- key: id
581
+ key: useFormIndex
1861
582
  })) === null || _b === void 0 ? void 0 : _b.subscribeOnMount(mountCallback);
1862
583
  const dataCallback = payload => {
1863
584
  var _a, _b;
@@ -1866,7 +587,7 @@ function useForm(_a, deps) {
1866
587
  }
1867
588
  };
1868
589
  const dataSub = (_c = formGroupInstance.getForm({
1869
- key: id
590
+ key: useFormIndex
1870
591
  })) === null || _c === void 0 ? void 0 : _c.subscribeData(dataCallback);
1871
592
  const validationCallback = payload => {
1872
593
  if (formValuesCallbackRefs.current.onValid) {
@@ -1874,7 +595,7 @@ function useForm(_a, deps) {
1874
595
  }
1875
596
  };
1876
597
  const validSub = (_d = formGroupInstance.getForm({
1877
- key: id
598
+ key: useFormIndex
1878
599
  })) === null || _d === void 0 ? void 0 : _d.subscribeFormValidation(validationCallback);
1879
600
  const submitCallback = payload => {
1880
601
  var _a, _b;
@@ -1883,7 +604,7 @@ function useForm(_a, deps) {
1883
604
  }
1884
605
  };
1885
606
  const submitSub = (_e = formGroupInstance.getForm({
1886
- key: id
607
+ key: useFormIndex
1887
608
  })) === null || _e === void 0 ? void 0 : _e.subscribeOnSubmit(submitCallback);
1888
609
  return () => {
1889
610
  sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
@@ -1909,6 +630,7 @@ function Form({
1909
630
  action,
1910
631
  method,
1911
632
  config,
633
+ prefetchedData,
1912
634
  onSubmit,
1913
635
  onFormMount,
1914
636
  onData,
@@ -1921,411 +643,145 @@ function Form({
1921
643
  onKeyUp,
1922
644
  onMount,
1923
645
  onValid,
646
+ stopEventsOnSubmit,
1924
647
  children
1925
- }) {
1926
- const {
1927
- getForm,
1928
- mappers,
1929
- debugMode,
1930
- formGroupInstance
1931
- } = useFormGroupContext({});
1932
- const schemaIndex = useRef(index || (schema === null || schema === void 0 ? void 0 : schema.index) || 'defaultChange').current;
1933
- const [mounted, setMounted] = useState(false);
1934
- const mountedRef = useRef(false);
1935
- /**
1936
- * effect to create the form instance and notify the recursive generated fields of it's mounted status
1937
- */
1938
- useEffect(() => {
1939
- if (mountedRef.current) return;
1940
- formGroupInstance.addForm({
1941
- key: schemaIndex,
1942
- formInstance: new FormCore({
1943
- schema,
1944
- initialValues: initialValues || (schema === null || schema === void 0 ? void 0 : schema.initialValues),
1945
- iVars: iVars || (schema === null || schema === void 0 ? void 0 : schema.iVars),
1946
- action: action || (schema === null || schema === void 0 ? void 0 : schema.action),
1947
- method: method || (schema === null || schema === void 0 ? void 0 : schema.method),
1948
- index: schemaIndex,
1949
- mappers,
1950
- config: config || formGroupInstance.config
1951
- })
1952
- });
1953
- setMounted(true);
1954
- mountedRef.current = true;
1955
- // }
1956
- }, []);
1957
- /**
1958
- * iVars change tracker to update iVars onto form instance
1959
- */
1960
- useEffect(() => {
1961
- if (!formGroupInstance.forms.has(schemaIndex)) {
1962
- console.log('failed to add iVars due to no form instance');
1963
- return;
1964
- }
1965
- if (iVars && mounted) formGroupInstance.forms.get(schemaIndex).iVars = iVars;
1966
- // if (iVars) formInstance.current.iVars = iVars;
1967
- }, [iVars, mounted]);
1968
- /**
1969
- * initialValues setter for async initialValues
1970
- */
1971
- useEffect(() => {
1972
- if (!formGroupInstance.forms.has(schemaIndex)) {
1973
- console.log('failed to add initialValues due to no form instance');
1974
- return;
1975
- }
1976
- if (initialValues && mounted) formGroupInstance.forms.get(schemaIndex).initialValues = initialValues;
1977
- // if (initialValues) formInstance.current.initialValues = initialValues;
1978
- }, [initialValues, mounted]);
1979
- /**
1980
- * hook usage to keep event bindings updated on callback functions passed as props
1981
- */
1982
- useForm({
1983
- id: schemaIndex,
1984
- onApiResponse,
1985
- onBlur,
1986
- onChange,
1987
- onClick,
1988
- onFocus,
1989
- onKeyDown,
1990
- onKeyUp,
1991
- onMount,
1992
- onSubmit,
1993
- onFormMount,
1994
- onData,
1995
- onValid
1996
- });
1997
- /*
1998
- @TODO move this logic inside form-core, add action and method onto form element,
1999
- might need a ref of the form to collect all the form parameters when there is a
2000
- normal form submition with redirect
2001
- */
2002
- const handleSubmit = event => {
2003
- const formElement = getForm({
2004
- key: schemaIndex
2005
- });
2006
- if (!(formElement === null || formElement === void 0 ? void 0 : formElement.action) && event) {
2007
- event.preventDefault();
2008
- }
2009
- formElement === null || formElement === void 0 ? void 0 : formElement.submit();
2010
- };
2011
- return jsxs(Fragment, {
2012
- children: [debugMode && jsxs(Fragment, {
2013
- children: [jsx("b", {
2014
- style: {
2015
- padding: '0px',
2016
- margin: '0px'
2017
- },
2018
- children: `form index: ${schemaIndex}`
2019
- }), jsx("button", {
2020
- onClick: () => console.log(getForm({
2021
- key: schemaIndex
2022
- })),
2023
- children: "print form instance"
2024
- }), jsx("button", {
2025
- onClick: () => {
2026
- var _a;
2027
- return console.log((_a = getForm({
2028
- key: schemaIndex
2029
- })) === null || _a === void 0 ? void 0 : _a.getFormValues());
2030
- },
2031
- children: "print form values"
2032
- }), jsx("button", {
2033
- onClick: () => {
2034
- var _a;
2035
- return (_a = getForm({
2036
- key: schemaIndex
2037
- })) === null || _a === void 0 ? void 0 : _a.submit();
2038
- },
2039
- children: "try submit"
2040
- }), jsx("br", {}), jsx("hr", {})]
2041
- }), jsx("form", {
2042
- onSubmit: handleSubmit,
2043
- children: jsx(BuildSchemaAsFields, {
2044
- formIndex: schemaIndex,
2045
- mappers: mappers,
2046
- components: schema === null || schema === void 0 ? void 0 : schema.components,
2047
- mountedForm: mounted
2048
- })
2049
- })]
2050
- });
2051
- }
2052
-
2053
- /**
2054
- * Component wrapper to aid building schemas with react without writting a JSON schema
2055
- * along with BuildAsFormFieldTree inside a Form component, FieldWrapper gets this props
2056
- * to build the component as it does with a JSON schema, this component only works inside
2057
- * the Form component
2058
- *
2059
- * @param {TAsFormFieldProps} props JSON schema props
2060
- * @returns {ReactNode}
2061
- */
2062
- const AsFormField = props => {
2063
- return props.children;
2064
- };
2065
-
2066
- /**
2067
- * Renders the React element defined on the mappers configuration
2068
- *
2069
- * @param param component props, field instance and children to render
2070
- * @returns
2071
- */
2072
- const FieldWrapperComponentRender = ({
2073
- props,
2074
- fieldInstance,
2075
- children,
2076
- mapper
2077
- }) => {
2078
- var _a, _b, _c;
2079
- const Component = (mapper === null || mapper === void 0 ? void 0 : mapper.component) || ((_a = fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.mapper) === null || _a === void 0 ? void 0 : _a.component);
2080
- const Asynccomponent = (mapper === null || mapper === void 0 ? void 0 : mapper.asynccomponent) || ((_b = fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.mapper) === null || _b === void 0 ? void 0 : _b.asynccomponent);
2081
- if (Component) return jsx(Component, Object.assign({}, props, {
2082
- children: children && children
2083
- }));
2084
- if (Asynccomponent) return jsx(Suspense, {
2085
- children: jsx(Asynccomponent, Object.assign({}, props, {
2086
- children: children && children
2087
- }))
2088
- });
2089
- return jsx("div", {
2090
- children: `failed to render field ${fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.name} with componentName:${(_c = fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.mapper) === null || _c === void 0 ? void 0 : _c.componentName}, please check mappers`
2091
- });
2092
- };
2093
- /**
2094
- * Base field Wrapper to render the component with the necessary configurations from the schema
2095
- * and mapper configuration
2096
- *
2097
- * @param {TFieldWrapperProps} param FieldWrapper params
2098
- * @returns {ReactElement}
2099
- */
2100
- const FieldWrapper = ({
2101
- name,
2102
- formIndex,
2103
- children,
2104
- props,
2105
- context,
2106
- mounted,
2107
- mapper,
2108
- visibility
2109
- }) => {
2110
- var _a, _b, _c;
2111
- const localContext = useFormGroupContext({});
2112
- /**
2113
- * picks the right context prioritizing the context passed as prop
2114
- */
2115
- const {
2116
- formGroupInstance,
2117
- debugMode
2118
- } = useMemo(() => context ? context : localContext, [context, localContext]);
2119
- const fieldInstance = useMemo(() => {
2120
- var _a;
2121
- return (_a = formGroupInstance.getForm({
2122
- key: formIndex
2123
- })) === null || _a === void 0 ? void 0 : _a.getField({
2124
- key: name
2125
- });
2126
- }, [mounted]);
2127
- /**
2128
- * props with templates stripped until the field ins't ready on the instance
2129
- */
2130
- const filteredProps = useMemo(() => {
2131
- let returnProps = {};
2132
- if (props) {
2133
- returnProps = FormField.filterProps(props);
2134
- }
2135
- if (fieldInstance) fieldInstance.props = returnProps;
2136
- return returnProps;
2137
- }, [props]);
2138
- const [valueState, setValueState] = useState((fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.stateValue) || {
2139
- [((_a = mapper === null || mapper === void 0 ? void 0 : mapper.events) === null || _a === void 0 ? void 0 : _a.setValue) || 'value']: ''
2140
- });
2141
- const [state, setState] = useState({
2142
- visibility: typeof visibility === 'boolean' ? visibility : true,
2143
- props: filteredProps
2144
- });
2145
- const mountedRef = useRef(false);
2146
- /**
2147
- * handles the mounting and unmounting logic onto the field instance
2148
- */
2149
- useEffect(() => {
2150
- if (!fieldInstance || mountedRef.current) return;
2151
- fieldInstance.mountField({
2152
- valueSubscription: value => {
2153
- setValueState(value);
2154
- },
2155
- propsSubscription: ({
2156
- visibility,
2157
- props,
2158
- errors
2159
- }) => {
2160
- setState(prev => Object.assign(Object.assign({}, prev), {
2161
- visibility,
2162
- props,
2163
- errors
2164
- }));
648
+ }) {
649
+ const {
650
+ getForm,
651
+ mappers,
652
+ debugMode,
653
+ formGroupInstance
654
+ } = useFormGroupContext({});
655
+ const schemaIndex = useRef(index || (schema === null || schema === void 0 ? void 0 : schema.index) || 'defaultChange').current;
656
+ const [mounted, setMounted] = useState(false);
657
+ const mountedRef = useRef(false);
658
+ /**
659
+ * Synchronously ensures the form instance exists during render.
660
+ * This allows the component tree to render meaningful HTML during SSR.
661
+ * Subscriptions and reactivity are still deferred to useEffect (client-only).
662
+ *
663
+ * Note: iVars and initialValues are also set in useForm hook (via useEffect),
664
+ * but they need to be here as well so the FormCore constructor has them available
665
+ * during the synchronous render phase for SSR template resolution.
666
+ */
667
+ useMemo(() => {
668
+ if (formGroupInstance.getForm({
669
+ key: schemaIndex
670
+ })) return;
671
+ const schemaWithPrefetch = prefetchedData && schema ? Object.assign(Object.assign({}, schema), {
672
+ prefetchedData
673
+ }) : schema;
674
+ formGroupInstance.addForm({
675
+ key: schemaIndex,
676
+ params: {
677
+ schema: schemaWithPrefetch,
678
+ action: action || (schema === null || schema === void 0 ? void 0 : schema.action),
679
+ method: method || (schema === null || schema === void 0 ? void 0 : schema.method),
680
+ index: schemaIndex,
681
+ mappers,
682
+ iVars: iVars || (schema === null || schema === void 0 ? void 0 : schema.iVars),
683
+ initialValues: initialValues || (schema === null || schema === void 0 ? void 0 : schema.initialValues),
684
+ config: config || formGroupInstance.config
2165
685
  }
2166
686
  });
2167
- mountedRef.current = true;
2168
- }, [fieldInstance]);
687
+ }, []);
2169
688
  /**
2170
- * recycle effect to remove the field Subscriptions due to memory leaks
689
+ * effect to notify the recursive generated fields of the form's mounted status
690
+ * and activate client-side reactivity (subscriptions, events, etc.)
2171
691
  */
2172
692
  useEffect(() => {
2173
- return () => {
2174
- mountedRef.current && (fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.destroyField());
2175
- };
693
+ if (mountedRef.current) return;
694
+ setMounted(true);
695
+ mountedRef.current = true;
2176
696
  }, []);
2177
697
  /**
2178
- * handles the value change onto the field instance
2179
- */
2180
- const handleChange = useCallback(event => {
2181
- if (!mounted) return;
2182
- fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.emitValue({
2183
- value: event,
2184
- event: 'ON_FIELD_CHANGE'
2185
- });
2186
- }, [mounted]);
2187
- /**
2188
- * handles the event emission onto the field instance
698
+ * hook usage to keep event bindings updated on callback functions passed as props
2189
699
  */
2190
- const handleEvent = useCallback(event => {
2191
- if (!mounted) return;
2192
- fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.emitEvents({
2193
- event
700
+ useForm({
701
+ index: schemaIndex,
702
+ initialValues,
703
+ iVars,
704
+ stopEventsOnSubmit,
705
+ onApiResponse,
706
+ onBlur,
707
+ onChange,
708
+ onClick,
709
+ onFocus,
710
+ onKeyDown,
711
+ onKeyUp,
712
+ onMount,
713
+ onSubmit,
714
+ onFormMount,
715
+ onData,
716
+ onValid
717
+ });
718
+ /*
719
+ @TODO move this logic inside form-core, add action and method onto form element,
720
+ might need a ref of the form to collect all the form parameters when there is a
721
+ normal form submition with redirect
722
+ */
723
+ const handleSubmit = event => {
724
+ const formElement = getForm({
725
+ key: schemaIndex
2194
726
  });
2195
- }, [mounted]);
2196
- /**
2197
- * handles the mappers configuration to bind the event submission callback
2198
- * to the corresponding prop defined on the mappers
2199
- */
2200
- const mapProps = useMemo(() => {
2201
- const events = mapper === null || mapper === void 0 ? void 0 : mapper.events;
2202
- const props = {};
2203
- if (events === null || events === void 0 ? void 0 : events.onBlur) props[events.onBlur] = () => handleEvent('ON_FIELD_BLUR');
2204
- if (events === null || events === void 0 ? void 0 : events.getValue) props[events.getValue] = handleChange;
2205
- if (events === null || events === void 0 ? void 0 : events.onFocus) props[events.onFocus] = () => handleEvent('ON_FIELD_FOCUS');
2206
- if (events === null || events === void 0 ? void 0 : events.onClick) props[events.onClick] = () => handleEvent('ON_FIELD_CLICK');
2207
- if (events === null || events === void 0 ? void 0 : events.onSubmit) props[events.onSubmit] = () => handleEvent('ON_FORM_SUBMIT');
2208
- if (events === null || events === void 0 ? void 0 : events.onKeyUp) props[events.onKeyUp] = () => handleEvent('ON_FIELD_KEYUP');
2209
- if (events === null || events === void 0 ? void 0 : events.onKeyDown) props[events.onKeyDown] = () => handleEvent('ON_FIELD_KEYDOWN');
2210
- return props;
2211
- }, [mounted]);
2212
- return state.visibility ? jsxs(Fragment, {
2213
- children: [debugMode && jsxs("div", {
2214
- style: {
2215
- width: '100%',
2216
- display: 'flex',
2217
- flexDirection: 'column'
2218
- },
2219
- children: [jsxs("b", {
727
+ if (!(formElement === null || formElement === void 0 ? void 0 : formElement.action) && event) {
728
+ event.preventDefault();
729
+ }
730
+ formElement === null || formElement === void 0 ? void 0 : formElement.submit();
731
+ };
732
+ return jsxs(Fragment, {
733
+ children: [debugMode && jsxs(Fragment, {
734
+ children: [jsx("b", {
2220
735
  style: {
2221
736
  padding: '0px',
2222
737
  margin: '0px'
2223
738
  },
2224
- children: ["name:", name]
2225
- }), jsxs("b", {
2226
- style: {
2227
- padding: '0px',
2228
- margin: '0px'
739
+ children: `form index: ${schemaIndex}`
740
+ }), jsx("button", {
741
+ onClick: () => console.log(getForm({
742
+ key: schemaIndex
743
+ })),
744
+ children: "print form instance"
745
+ }), jsx("button", {
746
+ onClick: () => {
747
+ var _a;
748
+ return console.log((_a = getForm({
749
+ key: schemaIndex
750
+ })) === null || _a === void 0 ? void 0 : _a.getFormValues());
2229
751
  },
2230
- children: ["order:", (_b = fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.originalSchema) === null || _b === void 0 ? void 0 : _b.order]
2231
- }), jsxs("b", {
2232
- style: {
2233
- padding: '0px',
2234
- margin: '0px'
752
+ children: "print form values"
753
+ }), jsx("button", {
754
+ onClick: () => {
755
+ var _a;
756
+ return (_a = getForm({
757
+ key: schemaIndex
758
+ })) === null || _a === void 0 ? void 0 : _a.submit();
2235
759
  },
2236
- children: ["path:", fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.path]
760
+ children: "try submit"
2237
761
  }), jsx("br", {}), jsx("hr", {})]
2238
- }), jsx(FieldWrapperComponentRender, {
2239
- props: Object.assign(Object.assign(Object.assign(Object.assign({}, mapProps), state.props), state.errors), valueState),
2240
- fieldInstance: fieldInstance,
2241
- mapper: mapper,
2242
- children: children ? children : ((_c = state === null || state === void 0 ? void 0 : state.props) === null || _c === void 0 ? void 0 : _c.children) ? state === null || state === void 0 ? void 0 : state.props.children : null
762
+ }), jsxs("form", {
763
+ onSubmit: handleSubmit,
764
+ children: [jsx(BuildSchemaAsFields, {
765
+ formIndex: schemaIndex,
766
+ mappers: mappers,
767
+ components: schema === null || schema === void 0 ? void 0 : schema.components,
768
+ mountedForm: mounted
769
+ }), children]
2243
770
  })]
2244
- }) : jsx(Fragment, {});
2245
- };
771
+ });
772
+ }
2246
773
 
2247
774
  /**
2248
- * Component Wrapper to render form fields without the Form component, gets additional formId and mapper since
2249
- * it won't rely on them and needs to be manually declared
775
+ * Component wrapper to aid building schemas with react without writting a JSON schema
776
+ * along with BuildAsFormFieldTree inside a Form component, FieldWrapper gets this props
777
+ * to build the component as it does with a JSON schema, this component only works inside
778
+ * the Form component
2250
779
  *
2251
- * @param {TAsFormFieldBuilderProps} props JSON schema props along with FieldWrapper props and mapper props
2252
- * @returns {ReactElement}
780
+ * @param {TAsFormFieldProps} props JSON schema props
781
+ * @returns {ReactNode}
2253
782
  */
2254
- const AsFormFieldBuilder = props => {
2255
- const context = useFormGroupContext({});
2256
- /**
2257
- * state to track the field instance creation process
2258
- */
2259
- const [mounted, setMounted] = useState(false);
2260
- const mountedRef = useRef(false);
2261
- /**
2262
- * initializer to create or add a form instance to the formGroup by it's formId
2263
- * and add the field to the form instance
2264
- * Also has the logic to remove it once this element is removed
2265
- */
2266
- useEffect(() => {
2267
- var _a;
2268
- if (mountedRef.current) return;
2269
- if (typeof props.formMounted === 'undefined' && !((_a = context.formGroupInstance) === null || _a === void 0 ? void 0 : _a.forms.has(props.formIndex))) {
2270
- context.addFormWithIndex(props.formIndex);
2271
- }
2272
- if (props.formMounted || typeof props.formMounted === 'undefined') {
2273
- const fieldSchema = Object.assign(Object.assign({}, props), {
2274
- component: props.mapper.componentName,
2275
- children: undefined
2276
- });
2277
- const formInstance = context.formGroupInstance.forms.get(props.formIndex);
2278
- formInstance === null || formInstance === void 0 ? void 0 : formInstance.addField({
2279
- fieldSchema,
2280
- mapperElement: props.mapper
2281
- });
2282
- setMounted(true);
2283
- mountedRef.current = true;
2284
- }
2285
- }, [props.formMounted]);
2286
- /**
2287
- * recycle effect to remove the field from the form instance when the field leaves the vDOM
2288
- * and the subscriptions
2289
- */
2290
- useEffect(() => {
2291
- return () => {
2292
- var _a, _b;
2293
- if ((_b = (_a = context.getForm({
2294
- key: props.formIndex
2295
- })) === null || _a === void 0 ? void 0 : _a.getField({
2296
- key: props.name
2297
- })) === null || _b === void 0 ? void 0 : _b.mounted) context.formGroupInstance.removeField({
2298
- formIndex: props.formIndex,
2299
- fieldIndex: props.name
2300
- });
2301
- };
2302
- }, []);
2303
- /**
2304
- * allows to control field selected value on each event
2305
- */
2306
- useEffect(() => {
2307
- var _a;
2308
- if (!props.onSelected) return;
2309
- const callback = payload => {
2310
- if (props.onSelected) {
2311
- props.onSelected(payload);
2312
- }
2313
- };
2314
- const sub = (_a = context.formGroupInstance.forms.get(props.formIndex)) === null || _a === void 0 ? void 0 : _a.subscribeFieldEvent({
2315
- callback
2316
- });
2317
- return () => sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
2318
- }, [props.onSelected]);
2319
- return jsx(FieldWrapper, {
2320
- formIndex: props.formIndex,
2321
- name: props.name,
2322
- props: props.props,
2323
- context: !context.active ? context : null,
2324
- mounted: mounted,
2325
- mapper: props.mapper,
2326
- visibility: props.visibility,
2327
- children: props.children && props.children
2328
- });
783
+ const AsFormField = props => {
784
+ return props.children;
2329
785
  };
2330
786
 
2331
787
  function useFormGroup({
@@ -2388,6 +844,124 @@ function useFormGroup({
2388
844
  return;
2389
845
  }
2390
846
 
847
+ /**
848
+ * Adapter do manage repeated list elements on form
849
+ *
850
+ * @param {TAsFormFieldRepeaterProps} props Repeater properties to configure the elements repeater
851
+ * @returns {ReactElement}
852
+ */
853
+ const AsFormFieldRepeater = ({
854
+ RepeaterComponent,
855
+ addFieldName,
856
+ removeFieldName,
857
+ existingElements,
858
+ initialElements,
859
+ stateUpdater,
860
+ formPrefix,
861
+ RepeaterFooter
862
+ }) => {
863
+ const {
864
+ getForm,
865
+ formGroupInstance
866
+ } = useFormGroupContext();
867
+ const [elements, setElements] = useState(typeof existingElements === 'object' && existingElements !== null ? Object.keys(existingElements).map(() => uniqueIdGen()) : typeof initialElements === 'number' ? Array.from(Array(initialElements), () => uniqueIdGen()) : []);
868
+ const mountedRef = useRef(false);
869
+ const prevElements = useRef(0);
870
+ const REPEATER_FOOTER_ID = useMemo(() => uniqueIdGen(), []);
871
+ const listeningElements = useMemo(() => {
872
+ return [...elements, REPEATER_FOOTER_ID];
873
+ }, [elements]);
874
+ useFormGroup({
875
+ ids: listeningElements,
876
+ onData: payload => {
877
+ if (stateUpdater) {
878
+ if (formPrefix) {
879
+ stateUpdater(elements.reduce((acc, curr, index) => {
880
+ const value = payload[curr];
881
+ acc[`${formPrefix}${index + 1}`] = value;
882
+ return acc;
883
+ }, {}));
884
+ return;
885
+ }
886
+ stateUpdater(payload);
887
+ }
888
+ }
889
+ }, [listeningElements]);
890
+ useEffect(() => {
891
+ // @TODO: refactor, quick workarount to emit data when removing a form from the list
892
+ if (prevElements.current > elements.length) {
893
+ formGroupInstance.dataSubject$.next({
894
+ event: 'ON_FIELD_UNMOUNT',
895
+ fieldIndex: 'unmounted_repeater_form',
896
+ formIndex: elements[0]
897
+ });
898
+ }
899
+ if (!mountedRef.current) {
900
+ elements.forEach((key, index) => {
901
+ const form = getForm({
902
+ key
903
+ });
904
+ if (form && (existingElements === null || existingElements === void 0 ? void 0 : existingElements[index])) {
905
+ form.initialValues = existingElements[index];
906
+ }
907
+ });
908
+ }
909
+ const subs = listeningElements.map(key => {
910
+ var _a;
911
+ return (_a = getForm({
912
+ key
913
+ })) === null || _a === void 0 ? void 0 : _a.subscribeFieldEvent({
914
+ callback({
915
+ event,
916
+ fieldName,
917
+ fieldInstance
918
+ }) {
919
+ if (fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.formIndex) {
920
+ if (event === 'ON_FIELD_CLICK' && fieldInstance.formIndex === REPEATER_FOOTER_ID) {
921
+ setElements(prev => {
922
+ prev.push(uniqueIdGen());
923
+ return [...prev];
924
+ });
925
+ return;
926
+ }
927
+ if (event === 'ON_FIELD_CLICK' && fieldName === addFieldName) {
928
+ setElements(prev => {
929
+ const index = prev.indexOf(fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.formIndex);
930
+ prev.splice(index + 1, 0, uniqueIdGen());
931
+ return [...prev];
932
+ });
933
+ }
934
+ if (event === 'ON_FIELD_CLICK' && fieldName === removeFieldName) {
935
+ if ((fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.formIndex) && elements.length > 0) setElements(prev => {
936
+ const index = prev.indexOf(fieldInstance === null || fieldInstance === void 0 ? void 0 : fieldInstance.formIndex);
937
+ prev.splice(index, 1);
938
+ return [...prev];
939
+ });
940
+ }
941
+ }
942
+ }
943
+ });
944
+ });
945
+ mountedRef.current = true;
946
+ prevElements.current = elements.length;
947
+ return () => {
948
+ subs.map(sub => sub === null || sub === void 0 ? void 0 : sub.unsubscribe());
949
+ };
950
+ }, [elements]);
951
+ return jsxs("div", {
952
+ style: {
953
+ display: 'flex',
954
+ flexDirection: 'column'
955
+ },
956
+ children: [elements.map((el, index) => jsx(RepeaterComponent, {
957
+ formIndex: el,
958
+ index: index
959
+ }, el)), RepeaterFooter && jsx(RepeaterFooter, {
960
+ formIndex: REPEATER_FOOTER_ID
961
+ })]
962
+ });
963
+ };
964
+
2391
965
  const defaultChangeEvent = event => {
2392
966
  return event.currentTarget.value;
2393
967
  };
@@ -2397,6 +971,11 @@ const checkedChangeEvent = event => {
2397
971
  const valueChangeEvent = event => {
2398
972
  return event.target.value;
2399
973
  };
974
+ const numberInputChangeEvent = number => {
975
+ if (number) {
976
+ return Number(number);
977
+ }
978
+ };
2400
979
  const datepickerChangeEvent = event => event;
2401
980
  const dropdownChangeEvent = (event, opts) => {
2402
981
  if (typeof event === 'object' && event !== null && 'value' in event && 'id' in event) {
@@ -2404,7 +983,7 @@ const dropdownChangeEvent = (event, opts) => {
2404
983
  _value: event === null || event === void 0 ? void 0 : event.id,
2405
984
  _metadata: event
2406
985
  };
2407
- } else if (typeof event === 'string' && typeof opts === 'object' && 'props' in opts && typeof opts.props === 'object' && 'optionList' in opts.props && Array.isArray(opts.props.optionList)) {
986
+ } else if ((typeof event === 'string' || typeof event === 'number') && typeof opts === 'object' && 'props' in opts && typeof opts.props === 'object' && 'optionList' in opts.props && Array.isArray(opts.props.optionList)) {
2408
987
  const option = opts.props.optionList.find(el => el.value === event);
2409
988
  if (option) {
2410
989
  return {
@@ -2417,7 +996,12 @@ const dropdownChangeEvent = (event, opts) => {
2417
996
  _metadata: event
2418
997
  };
2419
998
  }
999
+ } else {
1000
+ return {
1001
+ _value: event,
1002
+ _metadata: event
1003
+ };
2420
1004
  }
2421
1005
  };
2422
1006
 
2423
- export { AsFormField, AsFormFieldBuilder, Form, FormGroupContext, FormGroupContextProvider, checkedChangeEvent, datepickerChangeEvent, defaultChangeEvent, dropdownChangeEvent, useForm, useFormGroup, useFormGroupContext, valueChangeEvent };
1007
+ export { AsFormField, AsFormFieldBuilder, AsFormFieldRepeater, Form, FormGroupContext, FormGroupContextProvider, checkedChangeEvent, datepickerChangeEvent, defaultChangeEvent, dropdownChangeEvent, numberInputChangeEvent, useForm, useFormGroup, useFormGroupContext, valueChangeEvent };