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