@ttoss/forms 0.3.6 → 0.5.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/dist/forms.esm.js DELETED
@@ -1,1295 +0,0 @@
1
- import { createElement, Fragment, Children, forwardRef, useRef, useState } from 'react';
2
- import { ErrorMessage as ErrorMessage$1 } from '@hookform/error-message';
3
- import get from 'lodash-es/get';
4
- import { FormProvider, useFormContext, useFieldArray } from 'react-hook-form';
5
- import { Box, Text, Label, Input } from 'theme-ui';
6
- import { format, parse } from 'date-fns';
7
- import IMask from 'imask';
8
-
9
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
- try {
11
- var info = gen[key](arg);
12
- var value = info.value;
13
- } catch (error) {
14
- reject(error);
15
- return;
16
- }
17
-
18
- if (info.done) {
19
- resolve(value);
20
- } else {
21
- Promise.resolve(value).then(_next, _throw);
22
- }
23
- }
24
-
25
- function _asyncToGenerator(fn) {
26
- return function () {
27
- var self = this,
28
- args = arguments;
29
- return new Promise(function (resolve, reject) {
30
- var gen = fn.apply(self, args);
31
-
32
- function _next(value) {
33
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
34
- }
35
-
36
- function _throw(err) {
37
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
38
- }
39
-
40
- _next(undefined);
41
- });
42
- };
43
- }
44
-
45
- function _extends() {
46
- _extends = Object.assign || function (target) {
47
- for (var i = 1; i < arguments.length; i++) {
48
- var source = arguments[i];
49
-
50
- for (var key in source) {
51
- if (Object.prototype.hasOwnProperty.call(source, key)) {
52
- target[key] = source[key];
53
- }
54
- }
55
- }
56
-
57
- return target;
58
- };
59
-
60
- return _extends.apply(this, arguments);
61
- }
62
-
63
- function _objectWithoutPropertiesLoose(source, excluded) {
64
- if (source == null) return {};
65
- var target = {};
66
- var sourceKeys = Object.keys(source);
67
- var key, i;
68
-
69
- for (i = 0; i < sourceKeys.length; i++) {
70
- key = sourceKeys[i];
71
- if (excluded.indexOf(key) >= 0) continue;
72
- target[key] = source[key];
73
- }
74
-
75
- return target;
76
- }
77
-
78
- var Form = function Form(_ref) {
79
- var children = _ref.children,
80
- methods = _ref.methods,
81
- boxProps = _objectWithoutPropertiesLoose(_ref, ["children", "methods"]);
82
-
83
- return createElement(FormProvider, Object.assign({}, methods), createElement(Box, Object.assign({
84
- as: "form",
85
- variant: "forms.form"
86
- }, boxProps), children));
87
- };
88
-
89
- var ErrorMessage = function ErrorMessage(_ref2) {
90
- var name = _ref2.name;
91
-
92
- var _useFormContext = useFormContext(),
93
- errors = _useFormContext.errors;
94
-
95
- return createElement(ErrorMessage$1, {
96
- errors: errors,
97
- name: name,
98
- render: function render(_ref3) {
99
- var message = _ref3.message,
100
- messages = _ref3.messages;
101
-
102
- if (messages) {
103
- return createElement(Fragment, null, Object.entries(messages).map(function (_ref4) {
104
- var type = _ref4[0],
105
- message = _ref4[1];
106
- return createElement(Text, {
107
- variant: "text.error",
108
- role: "alert",
109
- key: type
110
- }, message);
111
- }));
112
- }
113
-
114
- return createElement(Text, {
115
- variant: "text.error",
116
- role: "alert"
117
- }, message);
118
- }
119
- });
120
- };
121
-
122
- var Field = function Field(_ref5) {
123
- var name = _ref5.name,
124
- children = _ref5.children,
125
- label = _ref5.label,
126
- inputProps = _objectWithoutPropertiesLoose(_ref5, ["name", "children", "label", "ref"]);
127
-
128
- var _useFormContext2 = useFormContext(),
129
- errors = _useFormContext2.errors,
130
- register = _useFormContext2.register;
131
-
132
- var error = get(errors, name);
133
- var commonProps = {
134
- name: name,
135
- key: name,
136
- id: name,
137
- 'aria-invalid': error ? 'true' : 'false'
138
- };
139
- return createElement(Box, {
140
- variant: "forms.field"
141
- }, label && createElement(Label, {
142
- htmlFor: name
143
- }, label), children ? Children.map(children, function (child) {
144
- return createElement(child.type, _extends({
145
- ref: register()
146
- }, commonProps, child.props));
147
- }) : createElement(Input, Object.assign({
148
- ref: register()
149
- }, commonProps, inputProps)), createElement(ErrorMessage, {
150
- name: name
151
- }));
152
- };
153
-
154
- Form.ErrorMessage = ErrorMessage;
155
- Form.Field = Field;
156
-
157
- function createCommonjsModule(fn, module) {
158
- return module = { exports: {} }, fn(module, module.exports), module.exports;
159
- }
160
-
161
- var runtime_1 = createCommonjsModule(function (module) {
162
- /**
163
- * Copyright (c) 2014-present, Facebook, Inc.
164
- *
165
- * This source code is licensed under the MIT license found in the
166
- * LICENSE file in the root directory of this source tree.
167
- */
168
-
169
- var runtime = (function (exports) {
170
-
171
- var Op = Object.prototype;
172
- var hasOwn = Op.hasOwnProperty;
173
- var undefined$1; // More compressible than void 0.
174
- var $Symbol = typeof Symbol === "function" ? Symbol : {};
175
- var iteratorSymbol = $Symbol.iterator || "@@iterator";
176
- var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
177
- var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
178
-
179
- function define(obj, key, value) {
180
- Object.defineProperty(obj, key, {
181
- value: value,
182
- enumerable: true,
183
- configurable: true,
184
- writable: true
185
- });
186
- return obj[key];
187
- }
188
- try {
189
- // IE 8 has a broken Object.defineProperty that only works on DOM objects.
190
- define({}, "");
191
- } catch (err) {
192
- define = function(obj, key, value) {
193
- return obj[key] = value;
194
- };
195
- }
196
-
197
- function wrap(innerFn, outerFn, self, tryLocsList) {
198
- // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
199
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
200
- var generator = Object.create(protoGenerator.prototype);
201
- var context = new Context(tryLocsList || []);
202
-
203
- // The ._invoke method unifies the implementations of the .next,
204
- // .throw, and .return methods.
205
- generator._invoke = makeInvokeMethod(innerFn, self, context);
206
-
207
- return generator;
208
- }
209
- exports.wrap = wrap;
210
-
211
- // Try/catch helper to minimize deoptimizations. Returns a completion
212
- // record like context.tryEntries[i].completion. This interface could
213
- // have been (and was previously) designed to take a closure to be
214
- // invoked without arguments, but in all the cases we care about we
215
- // already have an existing method we want to call, so there's no need
216
- // to create a new function object. We can even get away with assuming
217
- // the method takes exactly one argument, since that happens to be true
218
- // in every case, so we don't have to touch the arguments object. The
219
- // only additional allocation required is the completion record, which
220
- // has a stable shape and so hopefully should be cheap to allocate.
221
- function tryCatch(fn, obj, arg) {
222
- try {
223
- return { type: "normal", arg: fn.call(obj, arg) };
224
- } catch (err) {
225
- return { type: "throw", arg: err };
226
- }
227
- }
228
-
229
- var GenStateSuspendedStart = "suspendedStart";
230
- var GenStateSuspendedYield = "suspendedYield";
231
- var GenStateExecuting = "executing";
232
- var GenStateCompleted = "completed";
233
-
234
- // Returning this object from the innerFn has the same effect as
235
- // breaking out of the dispatch switch statement.
236
- var ContinueSentinel = {};
237
-
238
- // Dummy constructor functions that we use as the .constructor and
239
- // .constructor.prototype properties for functions that return Generator
240
- // objects. For full spec compliance, you may wish to configure your
241
- // minifier not to mangle the names of these two functions.
242
- function Generator() {}
243
- function GeneratorFunction() {}
244
- function GeneratorFunctionPrototype() {}
245
-
246
- // This is a polyfill for %IteratorPrototype% for environments that
247
- // don't natively support it.
248
- var IteratorPrototype = {};
249
- IteratorPrototype[iteratorSymbol] = function () {
250
- return this;
251
- };
252
-
253
- var getProto = Object.getPrototypeOf;
254
- var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
255
- if (NativeIteratorPrototype &&
256
- NativeIteratorPrototype !== Op &&
257
- hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
258
- // This environment has a native %IteratorPrototype%; use it instead
259
- // of the polyfill.
260
- IteratorPrototype = NativeIteratorPrototype;
261
- }
262
-
263
- var Gp = GeneratorFunctionPrototype.prototype =
264
- Generator.prototype = Object.create(IteratorPrototype);
265
- GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
266
- GeneratorFunctionPrototype.constructor = GeneratorFunction;
267
- GeneratorFunction.displayName = define(
268
- GeneratorFunctionPrototype,
269
- toStringTagSymbol,
270
- "GeneratorFunction"
271
- );
272
-
273
- // Helper for defining the .next, .throw, and .return methods of the
274
- // Iterator interface in terms of a single ._invoke method.
275
- function defineIteratorMethods(prototype) {
276
- ["next", "throw", "return"].forEach(function(method) {
277
- define(prototype, method, function(arg) {
278
- return this._invoke(method, arg);
279
- });
280
- });
281
- }
282
-
283
- exports.isGeneratorFunction = function(genFun) {
284
- var ctor = typeof genFun === "function" && genFun.constructor;
285
- return ctor
286
- ? ctor === GeneratorFunction ||
287
- // For the native GeneratorFunction constructor, the best we can
288
- // do is to check its .name property.
289
- (ctor.displayName || ctor.name) === "GeneratorFunction"
290
- : false;
291
- };
292
-
293
- exports.mark = function(genFun) {
294
- if (Object.setPrototypeOf) {
295
- Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
296
- } else {
297
- genFun.__proto__ = GeneratorFunctionPrototype;
298
- define(genFun, toStringTagSymbol, "GeneratorFunction");
299
- }
300
- genFun.prototype = Object.create(Gp);
301
- return genFun;
302
- };
303
-
304
- // Within the body of any async function, `await x` is transformed to
305
- // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
306
- // `hasOwn.call(value, "__await")` to determine if the yielded value is
307
- // meant to be awaited.
308
- exports.awrap = function(arg) {
309
- return { __await: arg };
310
- };
311
-
312
- function AsyncIterator(generator, PromiseImpl) {
313
- function invoke(method, arg, resolve, reject) {
314
- var record = tryCatch(generator[method], generator, arg);
315
- if (record.type === "throw") {
316
- reject(record.arg);
317
- } else {
318
- var result = record.arg;
319
- var value = result.value;
320
- if (value &&
321
- typeof value === "object" &&
322
- hasOwn.call(value, "__await")) {
323
- return PromiseImpl.resolve(value.__await).then(function(value) {
324
- invoke("next", value, resolve, reject);
325
- }, function(err) {
326
- invoke("throw", err, resolve, reject);
327
- });
328
- }
329
-
330
- return PromiseImpl.resolve(value).then(function(unwrapped) {
331
- // When a yielded Promise is resolved, its final value becomes
332
- // the .value of the Promise<{value,done}> result for the
333
- // current iteration.
334
- result.value = unwrapped;
335
- resolve(result);
336
- }, function(error) {
337
- // If a rejected Promise was yielded, throw the rejection back
338
- // into the async generator function so it can be handled there.
339
- return invoke("throw", error, resolve, reject);
340
- });
341
- }
342
- }
343
-
344
- var previousPromise;
345
-
346
- function enqueue(method, arg) {
347
- function callInvokeWithMethodAndArg() {
348
- return new PromiseImpl(function(resolve, reject) {
349
- invoke(method, arg, resolve, reject);
350
- });
351
- }
352
-
353
- return previousPromise =
354
- // If enqueue has been called before, then we want to wait until
355
- // all previous Promises have been resolved before calling invoke,
356
- // so that results are always delivered in the correct order. If
357
- // enqueue has not been called before, then it is important to
358
- // call invoke immediately, without waiting on a callback to fire,
359
- // so that the async generator function has the opportunity to do
360
- // any necessary setup in a predictable way. This predictability
361
- // is why the Promise constructor synchronously invokes its
362
- // executor callback, and why async functions synchronously
363
- // execute code before the first await. Since we implement simple
364
- // async functions in terms of async generators, it is especially
365
- // important to get this right, even though it requires care.
366
- previousPromise ? previousPromise.then(
367
- callInvokeWithMethodAndArg,
368
- // Avoid propagating failures to Promises returned by later
369
- // invocations of the iterator.
370
- callInvokeWithMethodAndArg
371
- ) : callInvokeWithMethodAndArg();
372
- }
373
-
374
- // Define the unified helper method that is used to implement .next,
375
- // .throw, and .return (see defineIteratorMethods).
376
- this._invoke = enqueue;
377
- }
378
-
379
- defineIteratorMethods(AsyncIterator.prototype);
380
- AsyncIterator.prototype[asyncIteratorSymbol] = function () {
381
- return this;
382
- };
383
- exports.AsyncIterator = AsyncIterator;
384
-
385
- // Note that simple async functions are implemented on top of
386
- // AsyncIterator objects; they just return a Promise for the value of
387
- // the final result produced by the iterator.
388
- exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
389
- if (PromiseImpl === void 0) PromiseImpl = Promise;
390
-
391
- var iter = new AsyncIterator(
392
- wrap(innerFn, outerFn, self, tryLocsList),
393
- PromiseImpl
394
- );
395
-
396
- return exports.isGeneratorFunction(outerFn)
397
- ? iter // If outerFn is a generator, return the full iterator.
398
- : iter.next().then(function(result) {
399
- return result.done ? result.value : iter.next();
400
- });
401
- };
402
-
403
- function makeInvokeMethod(innerFn, self, context) {
404
- var state = GenStateSuspendedStart;
405
-
406
- return function invoke(method, arg) {
407
- if (state === GenStateExecuting) {
408
- throw new Error("Generator is already running");
409
- }
410
-
411
- if (state === GenStateCompleted) {
412
- if (method === "throw") {
413
- throw arg;
414
- }
415
-
416
- // Be forgiving, per 25.3.3.3.3 of the spec:
417
- // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
418
- return doneResult();
419
- }
420
-
421
- context.method = method;
422
- context.arg = arg;
423
-
424
- while (true) {
425
- var delegate = context.delegate;
426
- if (delegate) {
427
- var delegateResult = maybeInvokeDelegate(delegate, context);
428
- if (delegateResult) {
429
- if (delegateResult === ContinueSentinel) continue;
430
- return delegateResult;
431
- }
432
- }
433
-
434
- if (context.method === "next") {
435
- // Setting context._sent for legacy support of Babel's
436
- // function.sent implementation.
437
- context.sent = context._sent = context.arg;
438
-
439
- } else if (context.method === "throw") {
440
- if (state === GenStateSuspendedStart) {
441
- state = GenStateCompleted;
442
- throw context.arg;
443
- }
444
-
445
- context.dispatchException(context.arg);
446
-
447
- } else if (context.method === "return") {
448
- context.abrupt("return", context.arg);
449
- }
450
-
451
- state = GenStateExecuting;
452
-
453
- var record = tryCatch(innerFn, self, context);
454
- if (record.type === "normal") {
455
- // If an exception is thrown from innerFn, we leave state ===
456
- // GenStateExecuting and loop back for another invocation.
457
- state = context.done
458
- ? GenStateCompleted
459
- : GenStateSuspendedYield;
460
-
461
- if (record.arg === ContinueSentinel) {
462
- continue;
463
- }
464
-
465
- return {
466
- value: record.arg,
467
- done: context.done
468
- };
469
-
470
- } else if (record.type === "throw") {
471
- state = GenStateCompleted;
472
- // Dispatch the exception by looping back around to the
473
- // context.dispatchException(context.arg) call above.
474
- context.method = "throw";
475
- context.arg = record.arg;
476
- }
477
- }
478
- };
479
- }
480
-
481
- // Call delegate.iterator[context.method](context.arg) and handle the
482
- // result, either by returning a { value, done } result from the
483
- // delegate iterator, or by modifying context.method and context.arg,
484
- // setting context.delegate to null, and returning the ContinueSentinel.
485
- function maybeInvokeDelegate(delegate, context) {
486
- var method = delegate.iterator[context.method];
487
- if (method === undefined$1) {
488
- // A .throw or .return when the delegate iterator has no .throw
489
- // method always terminates the yield* loop.
490
- context.delegate = null;
491
-
492
- if (context.method === "throw") {
493
- // Note: ["return"] must be used for ES3 parsing compatibility.
494
- if (delegate.iterator["return"]) {
495
- // If the delegate iterator has a return method, give it a
496
- // chance to clean up.
497
- context.method = "return";
498
- context.arg = undefined$1;
499
- maybeInvokeDelegate(delegate, context);
500
-
501
- if (context.method === "throw") {
502
- // If maybeInvokeDelegate(context) changed context.method from
503
- // "return" to "throw", let that override the TypeError below.
504
- return ContinueSentinel;
505
- }
506
- }
507
-
508
- context.method = "throw";
509
- context.arg = new TypeError(
510
- "The iterator does not provide a 'throw' method");
511
- }
512
-
513
- return ContinueSentinel;
514
- }
515
-
516
- var record = tryCatch(method, delegate.iterator, context.arg);
517
-
518
- if (record.type === "throw") {
519
- context.method = "throw";
520
- context.arg = record.arg;
521
- context.delegate = null;
522
- return ContinueSentinel;
523
- }
524
-
525
- var info = record.arg;
526
-
527
- if (! info) {
528
- context.method = "throw";
529
- context.arg = new TypeError("iterator result is not an object");
530
- context.delegate = null;
531
- return ContinueSentinel;
532
- }
533
-
534
- if (info.done) {
535
- // Assign the result of the finished delegate to the temporary
536
- // variable specified by delegate.resultName (see delegateYield).
537
- context[delegate.resultName] = info.value;
538
-
539
- // Resume execution at the desired location (see delegateYield).
540
- context.next = delegate.nextLoc;
541
-
542
- // If context.method was "throw" but the delegate handled the
543
- // exception, let the outer generator proceed normally. If
544
- // context.method was "next", forget context.arg since it has been
545
- // "consumed" by the delegate iterator. If context.method was
546
- // "return", allow the original .return call to continue in the
547
- // outer generator.
548
- if (context.method !== "return") {
549
- context.method = "next";
550
- context.arg = undefined$1;
551
- }
552
-
553
- } else {
554
- // Re-yield the result returned by the delegate method.
555
- return info;
556
- }
557
-
558
- // The delegate iterator is finished, so forget it and continue with
559
- // the outer generator.
560
- context.delegate = null;
561
- return ContinueSentinel;
562
- }
563
-
564
- // Define Generator.prototype.{next,throw,return} in terms of the
565
- // unified ._invoke helper method.
566
- defineIteratorMethods(Gp);
567
-
568
- define(Gp, toStringTagSymbol, "Generator");
569
-
570
- // A Generator should always return itself as the iterator object when the
571
- // @@iterator function is called on it. Some browsers' implementations of the
572
- // iterator prototype chain incorrectly implement this, causing the Generator
573
- // object to not be returned from this call. This ensures that doesn't happen.
574
- // See https://github.com/facebook/regenerator/issues/274 for more details.
575
- Gp[iteratorSymbol] = function() {
576
- return this;
577
- };
578
-
579
- Gp.toString = function() {
580
- return "[object Generator]";
581
- };
582
-
583
- function pushTryEntry(locs) {
584
- var entry = { tryLoc: locs[0] };
585
-
586
- if (1 in locs) {
587
- entry.catchLoc = locs[1];
588
- }
589
-
590
- if (2 in locs) {
591
- entry.finallyLoc = locs[2];
592
- entry.afterLoc = locs[3];
593
- }
594
-
595
- this.tryEntries.push(entry);
596
- }
597
-
598
- function resetTryEntry(entry) {
599
- var record = entry.completion || {};
600
- record.type = "normal";
601
- delete record.arg;
602
- entry.completion = record;
603
- }
604
-
605
- function Context(tryLocsList) {
606
- // The root entry object (effectively a try statement without a catch
607
- // or a finally block) gives us a place to store values thrown from
608
- // locations where there is no enclosing try statement.
609
- this.tryEntries = [{ tryLoc: "root" }];
610
- tryLocsList.forEach(pushTryEntry, this);
611
- this.reset(true);
612
- }
613
-
614
- exports.keys = function(object) {
615
- var keys = [];
616
- for (var key in object) {
617
- keys.push(key);
618
- }
619
- keys.reverse();
620
-
621
- // Rather than returning an object with a next method, we keep
622
- // things simple and return the next function itself.
623
- return function next() {
624
- while (keys.length) {
625
- var key = keys.pop();
626
- if (key in object) {
627
- next.value = key;
628
- next.done = false;
629
- return next;
630
- }
631
- }
632
-
633
- // To avoid creating an additional object, we just hang the .value
634
- // and .done properties off the next function object itself. This
635
- // also ensures that the minifier will not anonymize the function.
636
- next.done = true;
637
- return next;
638
- };
639
- };
640
-
641
- function values(iterable) {
642
- if (iterable) {
643
- var iteratorMethod = iterable[iteratorSymbol];
644
- if (iteratorMethod) {
645
- return iteratorMethod.call(iterable);
646
- }
647
-
648
- if (typeof iterable.next === "function") {
649
- return iterable;
650
- }
651
-
652
- if (!isNaN(iterable.length)) {
653
- var i = -1, next = function next() {
654
- while (++i < iterable.length) {
655
- if (hasOwn.call(iterable, i)) {
656
- next.value = iterable[i];
657
- next.done = false;
658
- return next;
659
- }
660
- }
661
-
662
- next.value = undefined$1;
663
- next.done = true;
664
-
665
- return next;
666
- };
667
-
668
- return next.next = next;
669
- }
670
- }
671
-
672
- // Return an iterator with no values.
673
- return { next: doneResult };
674
- }
675
- exports.values = values;
676
-
677
- function doneResult() {
678
- return { value: undefined$1, done: true };
679
- }
680
-
681
- Context.prototype = {
682
- constructor: Context,
683
-
684
- reset: function(skipTempReset) {
685
- this.prev = 0;
686
- this.next = 0;
687
- // Resetting context._sent for legacy support of Babel's
688
- // function.sent implementation.
689
- this.sent = this._sent = undefined$1;
690
- this.done = false;
691
- this.delegate = null;
692
-
693
- this.method = "next";
694
- this.arg = undefined$1;
695
-
696
- this.tryEntries.forEach(resetTryEntry);
697
-
698
- if (!skipTempReset) {
699
- for (var name in this) {
700
- // Not sure about the optimal order of these conditions:
701
- if (name.charAt(0) === "t" &&
702
- hasOwn.call(this, name) &&
703
- !isNaN(+name.slice(1))) {
704
- this[name] = undefined$1;
705
- }
706
- }
707
- }
708
- },
709
-
710
- stop: function() {
711
- this.done = true;
712
-
713
- var rootEntry = this.tryEntries[0];
714
- var rootRecord = rootEntry.completion;
715
- if (rootRecord.type === "throw") {
716
- throw rootRecord.arg;
717
- }
718
-
719
- return this.rval;
720
- },
721
-
722
- dispatchException: function(exception) {
723
- if (this.done) {
724
- throw exception;
725
- }
726
-
727
- var context = this;
728
- function handle(loc, caught) {
729
- record.type = "throw";
730
- record.arg = exception;
731
- context.next = loc;
732
-
733
- if (caught) {
734
- // If the dispatched exception was caught by a catch block,
735
- // then let that catch block handle the exception normally.
736
- context.method = "next";
737
- context.arg = undefined$1;
738
- }
739
-
740
- return !! caught;
741
- }
742
-
743
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
744
- var entry = this.tryEntries[i];
745
- var record = entry.completion;
746
-
747
- if (entry.tryLoc === "root") {
748
- // Exception thrown outside of any try block that could handle
749
- // it, so set the completion value of the entire function to
750
- // throw the exception.
751
- return handle("end");
752
- }
753
-
754
- if (entry.tryLoc <= this.prev) {
755
- var hasCatch = hasOwn.call(entry, "catchLoc");
756
- var hasFinally = hasOwn.call(entry, "finallyLoc");
757
-
758
- if (hasCatch && hasFinally) {
759
- if (this.prev < entry.catchLoc) {
760
- return handle(entry.catchLoc, true);
761
- } else if (this.prev < entry.finallyLoc) {
762
- return handle(entry.finallyLoc);
763
- }
764
-
765
- } else if (hasCatch) {
766
- if (this.prev < entry.catchLoc) {
767
- return handle(entry.catchLoc, true);
768
- }
769
-
770
- } else if (hasFinally) {
771
- if (this.prev < entry.finallyLoc) {
772
- return handle(entry.finallyLoc);
773
- }
774
-
775
- } else {
776
- throw new Error("try statement without catch or finally");
777
- }
778
- }
779
- }
780
- },
781
-
782
- abrupt: function(type, arg) {
783
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
784
- var entry = this.tryEntries[i];
785
- if (entry.tryLoc <= this.prev &&
786
- hasOwn.call(entry, "finallyLoc") &&
787
- this.prev < entry.finallyLoc) {
788
- var finallyEntry = entry;
789
- break;
790
- }
791
- }
792
-
793
- if (finallyEntry &&
794
- (type === "break" ||
795
- type === "continue") &&
796
- finallyEntry.tryLoc <= arg &&
797
- arg <= finallyEntry.finallyLoc) {
798
- // Ignore the finally entry if control is not jumping to a
799
- // location outside the try/catch block.
800
- finallyEntry = null;
801
- }
802
-
803
- var record = finallyEntry ? finallyEntry.completion : {};
804
- record.type = type;
805
- record.arg = arg;
806
-
807
- if (finallyEntry) {
808
- this.method = "next";
809
- this.next = finallyEntry.finallyLoc;
810
- return ContinueSentinel;
811
- }
812
-
813
- return this.complete(record);
814
- },
815
-
816
- complete: function(record, afterLoc) {
817
- if (record.type === "throw") {
818
- throw record.arg;
819
- }
820
-
821
- if (record.type === "break" ||
822
- record.type === "continue") {
823
- this.next = record.arg;
824
- } else if (record.type === "return") {
825
- this.rval = this.arg = record.arg;
826
- this.method = "return";
827
- this.next = "end";
828
- } else if (record.type === "normal" && afterLoc) {
829
- this.next = afterLoc;
830
- }
831
-
832
- return ContinueSentinel;
833
- },
834
-
835
- finish: function(finallyLoc) {
836
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
837
- var entry = this.tryEntries[i];
838
- if (entry.finallyLoc === finallyLoc) {
839
- this.complete(entry.completion, entry.afterLoc);
840
- resetTryEntry(entry);
841
- return ContinueSentinel;
842
- }
843
- }
844
- },
845
-
846
- "catch": function(tryLoc) {
847
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
848
- var entry = this.tryEntries[i];
849
- if (entry.tryLoc === tryLoc) {
850
- var record = entry.completion;
851
- if (record.type === "throw") {
852
- var thrown = record.arg;
853
- resetTryEntry(entry);
854
- }
855
- return thrown;
856
- }
857
- }
858
-
859
- // The context.catch method must only be called with a location
860
- // argument that corresponds to a known catch block.
861
- throw new Error("illegal catch attempt");
862
- },
863
-
864
- delegateYield: function(iterable, resultName, nextLoc) {
865
- this.delegate = {
866
- iterator: values(iterable),
867
- resultName: resultName,
868
- nextLoc: nextLoc
869
- };
870
-
871
- if (this.method === "next") {
872
- // Deliberately forget the last sent value so that we don't
873
- // accidentally pass it on to the delegate.
874
- this.arg = undefined$1;
875
- }
876
-
877
- return ContinueSentinel;
878
- }
879
- };
880
-
881
- // Regardless of whether this script is executing as a CommonJS module
882
- // or not, return the runtime object so that we can declare the variable
883
- // regeneratorRuntime in the outer scope, which allows this module to be
884
- // injected easily by `bin/regenerator --include-runtime script.js`.
885
- return exports;
886
-
887
- }(
888
- // If this script is executing as a CommonJS module, use module.exports
889
- // as the regeneratorRuntime namespace. Otherwise create a new empty
890
- // object. Either way, the resulting object will be used to initialize
891
- // the regeneratorRuntime variable at the top of this file.
892
- module.exports
893
- ));
894
-
895
- try {
896
- regeneratorRuntime = runtime;
897
- } catch (accidentalStrictMode) {
898
- // This module should not be running in strict mode, so the above
899
- // assignment should always work unless something is misconfigured. Just
900
- // in case runtime.js accidentally runs in strict mode, we can escape
901
- // strict mode using a global Function call. This could conceivably fail
902
- // if a Content Security Policy forbids using Function, but in that case
903
- // the proper solution is to fix the accidental strict mode problem. If
904
- // you've misconfigured your bundler to force strict mode and applied a
905
- // CSP to forbid Function, and you're not willing to fix either of those
906
- // problems, please detail your unique predicament in a GitHub issue.
907
- Function("r", "regeneratorRuntime = r")(runtime);
908
- }
909
- });
910
-
911
- var S3 = /*#__PURE__*/forwardRef(function (_ref, ref) {
912
- var getS3Key = _ref.getS3Key,
913
- getPutObjectSignedUrl = _ref.getPutObjectSignedUrl,
914
- renderUploadStatus = _ref.renderUploadStatus,
915
- inputProps = _objectWithoutPropertiesLoose(_ref, ["getS3Key", "getPutObjectSignedUrl", "renderUploadStatus", "ref"]);
916
-
917
- var multiple = inputProps.multiple,
918
- _inputProps$name = inputProps.name,
919
- name = _inputProps$name === void 0 ? '' : _inputProps$name;
920
- var fileInputRef = useRef(null);
921
-
922
- var _useFormContext = useFormContext(),
923
- clearErrors = _useFormContext.clearErrors,
924
- control = _useFormContext.control,
925
- register = _useFormContext.register,
926
- setError = _useFormContext.setError,
927
- watch = _useFormContext.watch;
928
-
929
- var _useFieldArray = useFieldArray({
930
- control: control,
931
- name: name
932
- }),
933
- append = _useFieldArray.append,
934
- fields = _useFieldArray.fields,
935
- remove = _useFieldArray.remove;
936
-
937
- var _React$useState = useState(),
938
- failed = _React$useState[0],
939
- setFailed = _React$useState[1];
940
-
941
- var success = watch(name);
942
-
943
- var onChange = /*#__PURE__*/function () {
944
- var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(event) {
945
- return runtime_1.wrap(function _callee2$(_context2) {
946
- while (1) {
947
- switch (_context2.prev = _context2.next) {
948
- case 0:
949
- if (event.target.files) {
950
- _context2.next = 2;
951
- break;
952
- }
953
-
954
- return _context2.abrupt("return");
955
-
956
- case 2:
957
- clearErrors(name);
958
- _context2.prev = 3;
959
- _context2.next = 6;
960
- return Promise.all(Array.from(event.target.files).map( /*#__PURE__*/function () {
961
- var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(file) {
962
- var filename, type, key, s3File, signedUrl, _yield$fetch, status;
963
-
964
- return runtime_1.wrap(function _callee$(_context) {
965
- while (1) {
966
- switch (_context.prev = _context.next) {
967
- case 0:
968
- filename = file.name;
969
- type = file.type;
970
- key = getS3Key({
971
- name: name,
972
- filename: filename
973
- });
974
- s3File = {
975
- key: key,
976
- filename: filename,
977
- type: type
978
- };
979
- _context.prev = 4;
980
- _context.next = 7;
981
- return getPutObjectSignedUrl({
982
- key: key,
983
- type: type
984
- });
985
-
986
- case 7:
987
- signedUrl = _context.sent;
988
-
989
- if (signedUrl) {
990
- _context.next = 10;
991
- break;
992
- }
993
-
994
- throw new Error();
995
-
996
- case 10:
997
- _context.t0 = fetch;
998
- _context.t1 = signedUrl;
999
- _context.t2 = {
1000
- 'Content-Type': type
1001
- };
1002
- _context.next = 15;
1003
- return file.arrayBuffer();
1004
-
1005
- case 15:
1006
- _context.t3 = _context.sent;
1007
- _context.t4 = {
1008
- method: 'PUT',
1009
- headers: _context.t2,
1010
- body: _context.t3
1011
- };
1012
- _context.next = 19;
1013
- return (0, _context.t0)(_context.t1, _context.t4);
1014
-
1015
- case 19:
1016
- _yield$fetch = _context.sent;
1017
- status = _yield$fetch.status;
1018
-
1019
- if (!(status !== 200)) {
1020
- _context.next = 23;
1021
- break;
1022
- }
1023
-
1024
- throw new Error();
1025
-
1026
- case 23:
1027
- if (!multiple) {
1028
- remove();
1029
- }
1030
-
1031
- append(s3File);
1032
- _context.next = 30;
1033
- break;
1034
-
1035
- case 27:
1036
- _context.prev = 27;
1037
- _context.t5 = _context["catch"](4);
1038
- setFailed(function (f) {
1039
- return [s3File].concat(f || []);
1040
- });
1041
-
1042
- case 30:
1043
- case "end":
1044
- return _context.stop();
1045
- }
1046
- }
1047
- }, _callee, null, [[4, 27]]);
1048
- }));
1049
-
1050
- return function (_x2) {
1051
- return _ref3.apply(this, arguments);
1052
- };
1053
- }()));
1054
-
1055
- case 6:
1056
- _context2.next = 11;
1057
- break;
1058
-
1059
- case 8:
1060
- _context2.prev = 8;
1061
- _context2.t0 = _context2["catch"](3);
1062
- setError(name, {
1063
- message: _context2.t0.message
1064
- });
1065
-
1066
- case 11:
1067
- case "end":
1068
- return _context2.stop();
1069
- }
1070
- }
1071
- }, _callee2, null, [[3, 8]]);
1072
- }));
1073
-
1074
- return function onChange(_x) {
1075
- return _ref2.apply(this, arguments);
1076
- };
1077
- }();
1078
-
1079
- return createElement(Fragment, null, createElement("input", {
1080
- type: "file",
1081
- style: {
1082
- display: 'none'
1083
- },
1084
- ref: fileInputRef,
1085
- onChange: onChange,
1086
- multiple: multiple
1087
- }), createElement(Input, Object.assign({}, inputProps, {
1088
- ref: ref || register(),
1089
- onClick: function onClick() {
1090
- var _fileInputRef$current;
1091
-
1092
- (_fileInputRef$current = fileInputRef.current) == null ? void 0 : _fileInputRef$current.click();
1093
- }
1094
- })), fields.map(function (_ref4, index) {
1095
- var id = _ref4.id,
1096
- key = _ref4.key,
1097
- filename = _ref4.filename,
1098
- type = _ref4.type;
1099
- return createElement(Fragment, {
1100
- key: id
1101
- }, createElement("input", {
1102
- type: "hidden",
1103
- ref: ref || register(),
1104
- name: name + "[" + index + "].key",
1105
- defaultValue: key
1106
- }), createElement(ErrorMessage, {
1107
- name: name + "[" + index + "].key"
1108
- }), createElement("input", {
1109
- type: "hidden",
1110
- ref: ref || register(),
1111
- name: name + "[" + index + "].filename",
1112
- defaultValue: filename
1113
- }), createElement(ErrorMessage, {
1114
- name: name + "[" + index + "].filename"
1115
- }), createElement("input", {
1116
- type: "hidden",
1117
- ref: ref || register(),
1118
- name: name + "[" + index + "].type",
1119
- defaultValue: type
1120
- }), createElement(ErrorMessage, {
1121
- name: name + "[" + index + "].type"
1122
- }));
1123
- }), renderUploadStatus == null ? void 0 : renderUploadStatus({
1124
- success: success,
1125
- failed: failed
1126
- }));
1127
- });
1128
-
1129
- /**
1130
- * https://stackoverflow.com/a/10452789/8786986
1131
- * @param args
1132
- */
1133
-
1134
- var masker = function masker(_ref) {
1135
- var masked = _ref.masked,
1136
- transform = _ref.transform,
1137
- maskDefault = _ref.maskDefault;
1138
- return function () {
1139
- var mask = IMask.createPipe(masked, IMask.PIPE_TYPE.UNMASKED, IMask.PIPE_TYPE.MASKED);
1140
- var unmask = IMask.createPipe(masked, IMask.PIPE_TYPE.MASKED, IMask.PIPE_TYPE.UNMASKED);
1141
-
1142
- var onChange = function onChange(e) {
1143
- var unmasked = unmask(e.target.value);
1144
- var newValue = mask(unmasked);
1145
- e.target.value = newValue;
1146
- };
1147
-
1148
- return {
1149
- mask: mask,
1150
- onChange: onChange,
1151
- transform: transform || unmask,
1152
- unmask: unmask,
1153
- maskDefault: maskDefault || mask
1154
- };
1155
- }();
1156
- };
1157
- var dateFormatClient = 'dd/MM/yyyy';
1158
- var dateFormatApi = 'yyyy-MM-dd';
1159
- var dateMask = /*#__PURE__*/masker({
1160
- masked: {
1161
- mask: Date,
1162
- pattern: dateFormatClient,
1163
- blocks: {
1164
- dd: {
1165
- mask: IMask.MaskedRange,
1166
- from: 1,
1167
- to: 31,
1168
- maxLength: 2
1169
- },
1170
- MM: {
1171
- mask: IMask.MaskedRange,
1172
- from: 1,
1173
- to: 12,
1174
- maxLength: 2
1175
- },
1176
- yyyy: {
1177
- mask: IMask.MaskedRange,
1178
- from: 1900,
1179
- to: 9999
1180
- }
1181
- },
1182
- format: function format$1(date) {
1183
- return format(date, dateFormatClient);
1184
- },
1185
- parse: function parse$1(dateStr) {
1186
- return parse(dateStr, dateFormatClient, new Date());
1187
- }
1188
- },
1189
- transform: function transform(value) {
1190
- if (!value) {
1191
- return value;
1192
- }
1193
-
1194
- var date = parse(value, dateFormatClient, new Date());
1195
- return format(date, dateFormatApi);
1196
- },
1197
- maskDefault: function maskDefault(value) {
1198
- return format(parse(value, dateFormatApi, new Date()), dateFormatClient);
1199
- }
1200
- });
1201
- var cpfOrCnpjMask = /*#__PURE__*/masker({
1202
- masked: {
1203
- mask: [{
1204
- mask: '000.000.000-00',
1205
- type: 'CPF'
1206
- }, {
1207
- mask: '00.000.000/0000-00',
1208
- type: 'CNPJ'
1209
- }],
1210
- dispatch: function dispatch(appended, dynamicMasked) {
1211
- var cpfMask = dynamicMasked.compiledMasks.find(function (_ref2) {
1212
- var type = _ref2.type;
1213
- return type === 'CPF';
1214
- });
1215
- var cnpjMask = dynamicMasked.compiledMasks.find(function (_ref3) {
1216
- var type = _ref3.type;
1217
- return type === 'CNPJ';
1218
- });
1219
-
1220
- if (("" + dynamicMasked.value + appended).length > cpfMask.mask.length) {
1221
- return cnpjMask;
1222
- }
1223
-
1224
- return cpfMask;
1225
- }
1226
- }
1227
- });
1228
- var phoneMask = /*#__PURE__*/masker({
1229
- masked: {
1230
- mask: [{
1231
- mask: '+55 00 0000-0000',
1232
- phone: 'landline'
1233
- }, {
1234
- mask: '+55 00 00000-0000',
1235
- phone: 'mobile'
1236
- }],
1237
- dispatch: function dispatch(appended, dynamicMasked) {
1238
- var landlineMask = dynamicMasked.compiledMasks.find(function (_ref4) {
1239
- var phone = _ref4.phone;
1240
- return phone === 'landline';
1241
- });
1242
- var mobileMask = dynamicMasked.compiledMasks.find(function (_ref5) {
1243
- var phone = _ref5.phone;
1244
- return phone === 'mobile';
1245
- });
1246
-
1247
- if (("" + dynamicMasked.value + appended).length > landlineMask.mask.length) {
1248
- return mobileMask;
1249
- }
1250
-
1251
- return landlineMask;
1252
- }
1253
- }
1254
- });
1255
- var brlCurrencyMask = /*#__PURE__*/masker({
1256
- masked: {
1257
- mask: 'R$ num{,}cents',
1258
- blocks: {
1259
- num: {
1260
- mask: Number,
1261
- signed: true,
1262
- thousandsSeparator: '.',
1263
- mapToRadix: [''],
1264
- scale: 0
1265
- },
1266
- cents: {
1267
- mask: '00',
1268
- normalizeZeros: true,
1269
- padFractionalZeros: true
1270
- }
1271
- }
1272
- },
1273
- transform: function transform(value, originalValue) {
1274
- try {
1275
- return Number(brlCurrencyMask.unmask(value || originalValue || 0).replace(',', '.'));
1276
- } catch (_unused) {
1277
- return 0;
1278
- }
1279
- },
1280
- maskDefault: function maskDefault(value) {
1281
- return value ? brlCurrencyMask.mask(value.toFixed(2).replace('.', ',')) : '';
1282
- }
1283
- });
1284
-
1285
- var masks = {
1286
- __proto__: null,
1287
- masker: masker,
1288
- dateMask: dateMask,
1289
- cpfOrCnpjMask: cpfOrCnpjMask,
1290
- phoneMask: phoneMask,
1291
- brlCurrencyMask: brlCurrencyMask
1292
- };
1293
-
1294
- export { ErrorMessage, Form, S3, masks };
1295
- //# sourceMappingURL=forms.esm.js.map