@radicalbit/formbit 1.0.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.
Files changed (35) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1180 -0
  3. package/dist/__tests__/check.test.d.ts +1 -0
  4. package/dist/__tests__/error.test.d.ts +1 -0
  5. package/dist/__tests__/initialize.test.d.ts +1 -0
  6. package/dist/__tests__/is-form-invalid.test.d.ts +1 -0
  7. package/dist/__tests__/is-form-valid.test.d.ts +1 -0
  8. package/dist/__tests__/live-validation.test.d.ts +1 -0
  9. package/dist/__tests__/remove.test.d.ts +1 -0
  10. package/dist/__tests__/reset-form.test.d.ts +1 -0
  11. package/dist/__tests__/set-error.test.d.ts +1 -0
  12. package/dist/__tests__/set-schema.test.d.ts +1 -0
  13. package/dist/__tests__/submit-form.test.d.ts +1 -0
  14. package/dist/__tests__/use-execute-callbacks.test.d.ts +1 -0
  15. package/dist/__tests__/use-formbit-context.test.d.ts +1 -0
  16. package/dist/__tests__/validate-all.test.d.ts +1 -0
  17. package/dist/__tests__/validate-form.test.d.ts +1 -0
  18. package/dist/__tests__/validate-sync-all.test.d.ts +1 -0
  19. package/dist/__tests__/validate.test.d.ts +1 -0
  20. package/dist/__tests__/write-all.test.d.ts +1 -0
  21. package/dist/__tests__/write.test.d.ts +1 -0
  22. package/dist/formbit-context.d.ts +9 -0
  23. package/dist/helpers/constants.d.ts +9 -0
  24. package/dist/helpers/obj-leaves.d.ts +3 -0
  25. package/dist/index.d.ts +4 -0
  26. package/dist/index.js +658 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/index.modern.js +654 -0
  29. package/dist/index.modern.js.map +1 -0
  30. package/dist/types/helpers.d.ts +2 -0
  31. package/dist/types/index.d.ts +418 -0
  32. package/dist/use-execute-callbacks.d.ts +11 -0
  33. package/dist/use-formbit.d.ts +7 -0
  34. package/dist/validate-sync-all.d.ts +2 -0
  35. package/package.json +90 -0
@@ -0,0 +1,654 @@
1
+ import React, { useRef, useEffect, useCallback, useState, createContext, useContext } from 'react';
2
+ import { isEmpty, set, cloneDeep, omit, get, once } from 'lodash';
3
+ import { object } from 'yup';
4
+
5
+ function _extends() {
6
+ _extends = Object.assign || function (target) {
7
+ for (var i = 1; i < arguments.length; i++) {
8
+ var source = arguments[i];
9
+
10
+ for (var key in source) {
11
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
12
+ target[key] = source[key];
13
+ }
14
+ }
15
+ }
16
+
17
+ return target;
18
+ };
19
+
20
+ return _extends.apply(this, arguments);
21
+ }
22
+
23
+ function _objectWithoutPropertiesLoose(source, excluded) {
24
+ if (source == null) return {};
25
+ var target = {};
26
+ var sourceKeys = Object.keys(source);
27
+ var key, i;
28
+
29
+ for (i = 0; i < sourceKeys.length; i++) {
30
+ key = sourceKeys[i];
31
+ if (excluded.indexOf(key) >= 0) continue;
32
+ target[key] = source[key];
33
+ }
34
+
35
+ return target;
36
+ }
37
+
38
+ function _unsupportedIterableToArray(o, minLen) {
39
+ if (!o) return;
40
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
41
+ var n = Object.prototype.toString.call(o).slice(8, -1);
42
+ if (n === "Object" && o.constructor) n = o.constructor.name;
43
+ if (n === "Map" || n === "Set") return Array.from(o);
44
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
45
+ }
46
+
47
+ function _arrayLikeToArray(arr, len) {
48
+ if (len == null || len > arr.length) len = arr.length;
49
+
50
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
51
+
52
+ return arr2;
53
+ }
54
+
55
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
56
+ var it;
57
+
58
+ if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
59
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
60
+ if (it) o = it;
61
+ var i = 0;
62
+ return function () {
63
+ if (i >= o.length) return {
64
+ done: true
65
+ };
66
+ return {
67
+ done: false,
68
+ value: o[i++]
69
+ };
70
+ };
71
+ }
72
+
73
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
74
+ }
75
+
76
+ it = o[Symbol.iterator]();
77
+ return it.next.bind(it);
78
+ }
79
+
80
+ function isObject(val) {
81
+ return val != null && typeof val === 'object' && Array.isArray(val) === false;
82
+ }
83
+
84
+ var objLeaves = function objLeaves(obj, acc) {
85
+ if (acc === void 0) {
86
+ acc = [];
87
+ }
88
+
89
+ var fn = function fn(o, s) {
90
+ if (Array.isArray(o)) {
91
+ return Object.keys(o).forEach(function (k) {
92
+ var path = s ? s + "[" + k + "]" : k;
93
+ var isLeaf = fn(o[+k], path) === false;
94
+
95
+ if (isLeaf) {
96
+ acc.push(path);
97
+ }
98
+ });
99
+ }
100
+
101
+ if (isObject(o)) {
102
+ return Object.keys(o).forEach(function (k) {
103
+ var path = s ? s + "." + k : k;
104
+ var isLeaf = fn(o[k], path) === false;
105
+
106
+ if (isLeaf) {
107
+ acc.push(path);
108
+ }
109
+ });
110
+ }
111
+
112
+ return false;
113
+ };
114
+
115
+ fn(obj);
116
+ return acc;
117
+ };
118
+
119
+ var ACTIONS;
120
+
121
+ (function (ACTIONS) {
122
+ ACTIONS["write"] = "write";
123
+ ACTIONS["remove"] = "remove";
124
+ })(ACTIONS || (ACTIONS = {}));
125
+
126
+ var MISSING_CONTEXT_ERROR = 'No FormbitContext.Provider found, useFormbitContext can only be called inside proper context';
127
+
128
+ var isValidationError = function isValidationError(error) {
129
+ if (error && typeof error === 'object' && 'message' in error && 'path' in error && 'inner' in error) {
130
+ var path = error.path,
131
+ message = error.message,
132
+ inner = error.inner;
133
+ return (typeof path === 'string' || path === undefined) && (typeof message === 'string' || path === undefined) && Array.isArray(inner);
134
+ }
135
+
136
+ return false;
137
+ };
138
+
139
+ var validateSyncAll = function validateSyncAll(paths, schema, form, options) {
140
+ if (options === void 0) {
141
+ options = {};
142
+ }
143
+
144
+ var errors = [];
145
+
146
+ if (isEmpty(paths)) {
147
+ return errors;
148
+ }
149
+
150
+ for (var _iterator = _createForOfIteratorHelperLoose(paths), _step; !(_step = _iterator()).done;) {
151
+ var pathToValidate = _step.value;
152
+
153
+ try {
154
+ schema.validateSyncAt(pathToValidate, form, options);
155
+ } catch (e) {
156
+ var _options;
157
+
158
+ if (isValidationError(e)) {
159
+ var message = e.message,
160
+ path = e.path;
161
+ errors = errors.concat({
162
+ message: message,
163
+ path: path
164
+ });
165
+ }
166
+
167
+ if ((_options = options) !== null && _options !== void 0 && _options.abortEarly) {
168
+ break;
169
+ }
170
+ }
171
+ }
172
+
173
+ return errors;
174
+ };
175
+
176
+ var useExecuteCallbacks = (function (writer, setError) {
177
+ var callbacksStore = useRef([]);
178
+ useEffect(function () {
179
+ if (callbacksStore.current.length) {
180
+ callbacksStore.current.forEach(function (cb) {
181
+ if (cb) {
182
+ cb(writer, setError);
183
+ }
184
+ });
185
+ callbacksStore.current = [];
186
+ }
187
+ }, [setError, writer]);
188
+ return useCallback(function (cb) {
189
+ if (cb) {
190
+ callbacksStore.current.push(cb);
191
+ }
192
+ }, []);
193
+ });
194
+
195
+ var useFormbit = (function (_ref) {
196
+ var _ref$initialValues = _ref.initialValues,
197
+ initialValues = _ref$initialValues === void 0 ? {} : _ref$initialValues,
198
+ schema = _ref.yup;
199
+ var schemaRef = useRef(schema);
200
+
201
+ var _useState = useState({
202
+ form: initialValues,
203
+ initialValues: initialValues,
204
+ errors: {},
205
+ liveValidation: {},
206
+ isDirty: false
207
+ }),
208
+ writer = _useState[0],
209
+ setWriter = _useState[1];
210
+
211
+ var initialize = useCallback(function (values) {
212
+ setWriter(function (w) {
213
+ return _extends({}, w, {
214
+ initialValues: values,
215
+ form: values,
216
+ errors: {},
217
+ liveValidation: {},
218
+ isDirty: false
219
+ });
220
+ });
221
+ }, []);
222
+ var setSchema = useCallback(function (newSchema) {
223
+ schemaRef.current = newSchema;
224
+ }, []);
225
+ var setError = useCallback(function (path, value) {
226
+ setWriter(function (w) {
227
+ var errors = set(cloneDeep(w.errors), path, value);
228
+ return _extends({}, w, {
229
+ errors: errors
230
+ });
231
+ });
232
+ }, []);
233
+ var executeCb = useExecuteCallbacks(writer, setError);
234
+ var writeOrRemove = useCallback(function (path, value, _temp, action) {
235
+ var _ref2 = _temp === void 0 ? {} : _temp,
236
+ _ref2$noLiveValidatio = _ref2.noLiveValidation,
237
+ noLiveValidation = _ref2$noLiveValidatio === void 0 ? false : _ref2$noLiveValidatio,
238
+ _ref2$pathsToValidate = _ref2.pathsToValidate,
239
+ pathsToValidate = _ref2$pathsToValidate === void 0 ? [] : _ref2$pathsToValidate,
240
+ successCallback = _ref2.successCallback,
241
+ errorCallback = _ref2.errorCallback,
242
+ _ref2$options = _ref2.options,
243
+ options = _ref2$options === void 0 ? {} : _ref2$options;
244
+
245
+ setWriter(function (w) {
246
+ var liveValidationPaths = noLiveValidation ? [] : Object.keys(w.liveValidation);
247
+ var paths = pathsToValidate.concat(liveValidationPaths);
248
+
249
+ var form = function execute() {
250
+ switch (action) {
251
+ case ACTIONS.write:
252
+ return set(cloneDeep(w.form), path, value);
253
+
254
+ case ACTIONS.remove:
255
+ return omit(cloneDeep(w.form), path);
256
+
257
+ default:
258
+ return cloneDeep(w.form);
259
+ }
260
+ }();
261
+
262
+ var newWriter = _extends({}, w, {
263
+ form: form,
264
+ isDirty: true
265
+ });
266
+
267
+ if (paths.length === 0) {
268
+ executeCb(successCallback);
269
+ return newWriter;
270
+ }
271
+
272
+ var cleanErrors = paths.reduce(function (acc, key) {
273
+ return set(acc, key, undefined);
274
+ }, cloneDeep(newWriter.errors));
275
+ var inner = validateSyncAll(paths, schemaRef.current, newWriter.form, options);
276
+
277
+ if (isEmpty(inner)) {
278
+ var _neww = _extends({}, newWriter, {
279
+ errors: cleanErrors
280
+ });
281
+
282
+ executeCb(successCallback);
283
+ return _neww;
284
+ }
285
+
286
+ var errors = inner.reduce(function (acc, _ref3) {
287
+ var innerPath = _ref3.path,
288
+ message = _ref3.message;
289
+ return innerPath ? set(acc, innerPath, message) : acc;
290
+ }, cleanErrors);
291
+ var liveValidation = inner.reduce(function (acc, _ref4) {
292
+ var _extends2;
293
+
294
+ var innerPath = _ref4.path;
295
+ return innerPath ? _extends({}, acc, (_extends2 = {}, _extends2[innerPath] = true, _extends2)) : acc;
296
+ }, newWriter.liveValidation);
297
+
298
+ var neww = _extends({}, newWriter, {
299
+ errors: errors,
300
+ liveValidation: liveValidation
301
+ });
302
+
303
+ executeCb(errorCallback);
304
+ return neww;
305
+ });
306
+ }, [executeCb]);
307
+ var write = useCallback(function (path, value, options) {
308
+ return writeOrRemove(path, value, options, ACTIONS.write);
309
+ }, [writeOrRemove]);
310
+ var remove = useCallback(function (path, options) {
311
+ return writeOrRemove(path, undefined, options, ACTIONS.remove);
312
+ }, [writeOrRemove]);
313
+ var writeAll = useCallback(function (arr, _temp2) {
314
+ var _ref5 = _temp2 === void 0 ? {} : _temp2,
315
+ _ref5$noLiveValidatio = _ref5.noLiveValidation,
316
+ noLiveValidation = _ref5$noLiveValidatio === void 0 ? false : _ref5$noLiveValidatio,
317
+ _ref5$pathsToValidate = _ref5.pathsToValidate,
318
+ pathsToValidate = _ref5$pathsToValidate === void 0 ? [] : _ref5$pathsToValidate,
319
+ successCallback = _ref5.successCallback,
320
+ errorCallback = _ref5.errorCallback,
321
+ _ref5$options = _ref5.options,
322
+ options = _ref5$options === void 0 ? {} : _ref5$options;
323
+
324
+ setWriter(function (w) {
325
+ var liveValidationPaths = noLiveValidation ? [] : Object.keys(w.liveValidation);
326
+ var paths = pathsToValidate.concat(liveValidationPaths);
327
+ var form = arr.reduce(function (acc, _ref6) {
328
+ var key = _ref6[0],
329
+ val = _ref6[1];
330
+ return set(acc, key, val);
331
+ }, cloneDeep(w.form));
332
+
333
+ var newWriter = _extends({}, w, {
334
+ form: form,
335
+ isDirty: true
336
+ });
337
+
338
+ if (paths.length === 0) {
339
+ executeCb(successCallback);
340
+ return newWriter;
341
+ }
342
+
343
+ var cleanErrors = paths.reduce(function (acc, key) {
344
+ return set(acc, key, undefined);
345
+ }, cloneDeep(newWriter.errors));
346
+ var inner = validateSyncAll(paths, schemaRef.current, newWriter.form, options);
347
+
348
+ if (isEmpty(inner)) {
349
+ var _neww2 = _extends({}, newWriter, {
350
+ errors: cleanErrors
351
+ });
352
+
353
+ executeCb(successCallback);
354
+ return _neww2;
355
+ }
356
+
357
+ var errors = inner.reduce(function (acc, _ref7) {
358
+ var _ref7$path = _ref7.path,
359
+ path = _ref7$path === void 0 ? '' : _ref7$path,
360
+ message = _ref7.message;
361
+ return set(acc, path, message);
362
+ }, cleanErrors);
363
+ var liveValidation = inner.reduce(function (acc, _ref8) {
364
+ var _extends3;
365
+
366
+ var _ref8$path = _ref8.path,
367
+ path = _ref8$path === void 0 ? '' : _ref8$path;
368
+ return _extends({}, acc, (_extends3 = {}, _extends3[path] = true, _extends3));
369
+ }, newWriter.liveValidation);
370
+
371
+ var neww = _extends({}, newWriter, {
372
+ errors: errors,
373
+ liveValidation: liveValidation
374
+ });
375
+
376
+ executeCb(errorCallback);
377
+ return neww;
378
+ });
379
+ }, [executeCb]);
380
+ var validate = useCallback(function (path, _temp3) {
381
+ var _ref9 = _temp3 === void 0 ? {} : _temp3,
382
+ successCallback = _ref9.successCallback,
383
+ errorCallback = _ref9.errorCallback,
384
+ options = _ref9.options;
385
+
386
+ setWriter(function (w) {
387
+ var cleanErrors = set(cloneDeep(w.errors), path, undefined);
388
+ var inner = validateSyncAll([path], schemaRef.current, w.form, options);
389
+
390
+ if (isEmpty(inner)) {
391
+ var _neww3 = _extends({}, w, {
392
+ errors: cleanErrors
393
+ });
394
+
395
+ executeCb(successCallback);
396
+ return _neww3;
397
+ }
398
+
399
+ var errors = inner.reduce(function (acc, _ref10) {
400
+ var _ref10$path = _ref10.path,
401
+ errorPath = _ref10$path === void 0 ? '' : _ref10$path,
402
+ message = _ref10.message;
403
+ return set(acc, errorPath, message);
404
+ }, cleanErrors);
405
+ var liveValidation = inner.reduce(function (acc, _ref11) {
406
+ var _extends4;
407
+
408
+ var _ref11$path = _ref11.path,
409
+ errorPath = _ref11$path === void 0 ? '' : _ref11$path;
410
+ return _extends({}, acc, (_extends4 = {}, _extends4[errorPath] = true, _extends4));
411
+ }, w.liveValidation);
412
+
413
+ var neww = _extends({}, w, {
414
+ errors: errors,
415
+ liveValidation: liveValidation
416
+ });
417
+
418
+ executeCb(errorCallback);
419
+ return neww;
420
+ });
421
+ }, [executeCb]);
422
+ var validateAll = useCallback(function (paths, _temp4) {
423
+ var _ref12 = _temp4 === void 0 ? {} : _temp4,
424
+ successCallback = _ref12.successCallback,
425
+ errorCallback = _ref12.errorCallback,
426
+ options = _ref12.options;
427
+
428
+ setWriter(function (w) {
429
+ var cleanErrors = paths.reduce(function (acc, path) {
430
+ return set(acc, path, undefined);
431
+ }, cloneDeep(w.errors));
432
+ var inner = validateSyncAll(paths, schemaRef.current, w.form, options);
433
+
434
+ if (isEmpty(inner)) {
435
+ var _neww4 = _extends({}, w, {
436
+ errors: cleanErrors
437
+ });
438
+
439
+ executeCb(successCallback);
440
+ return _neww4;
441
+ }
442
+
443
+ var errors = inner.reduce(function (acc, _ref13) {
444
+ var _ref13$path = _ref13.path,
445
+ path = _ref13$path === void 0 ? '' : _ref13$path,
446
+ message = _ref13.message;
447
+ return set(acc, path, message);
448
+ }, cleanErrors);
449
+ var liveValidation = inner.reduce(function (acc, _ref14) {
450
+ var _extends5;
451
+
452
+ var _ref14$path = _ref14.path,
453
+ path = _ref14$path === void 0 ? '' : _ref14$path;
454
+ return _extends({}, acc, (_extends5 = {}, _extends5[path] = true, _extends5));
455
+ }, w.liveValidation);
456
+
457
+ var neww = _extends({}, w, {
458
+ errors: errors,
459
+ liveValidation: liveValidation
460
+ });
461
+
462
+ executeCb(errorCallback);
463
+ return neww;
464
+ });
465
+ }, [executeCb]);
466
+ var check = useCallback(function (json, _temp5) {
467
+ var _ref15 = _temp5 === void 0 ? {} : _temp5,
468
+ successCallback = _ref15.successCallback,
469
+ errorCallback = _ref15.errorCallback,
470
+ options = _ref15.options;
471
+
472
+ try {
473
+ schema.validateSync(json, _extends({
474
+ abortEarly: false
475
+ }, options));
476
+ successCallback === null || successCallback === void 0 ? void 0 : successCallback(json, writer, setError);
477
+ return undefined;
478
+ } catch (e) {
479
+ if (isValidationError(e)) {
480
+ var inner = e.inner;
481
+ errorCallback === null || errorCallback === void 0 ? void 0 : errorCallback(json, inner, writer, setError);
482
+ return inner;
483
+ }
484
+
485
+ return undefined;
486
+ }
487
+ }, [schema, setError, writer]);
488
+ var privateValidateForm = useCallback(function (successCallback, errorCallback, _temp6) {
489
+ var _ref16 = _temp6 === void 0 ? {} : _temp6,
490
+ options = _ref16.options;
491
+
492
+ setWriter(function (w) {
493
+ try {
494
+ schemaRef.current.validateSync(w.form, _extends({
495
+ abortEarly: false
496
+ }, options));
497
+ executeCb(successCallback);
498
+ return _extends({}, w, {
499
+ errors: {}
500
+ });
501
+ } catch (e) {
502
+ if (!isValidationError(e)) {
503
+ console.error(e);
504
+ return w;
505
+ }
506
+
507
+ var inner = e.inner;
508
+ var errors = inner.reduce(function (acc, _ref17) {
509
+ var message = _ref17.message,
510
+ _ref17$path = _ref17.path,
511
+ path = _ref17$path === void 0 ? '' : _ref17$path;
512
+ return set(acc, path, message);
513
+ }, {});
514
+
515
+ var _liveValidation = inner.reduce(function (acc, _ref18) {
516
+ var _extends6;
517
+
518
+ var _ref18$path = _ref18.path,
519
+ path = _ref18$path === void 0 ? '' : _ref18$path;
520
+ return _extends({}, acc, (_extends6 = {}, _extends6[path] = true, _extends6));
521
+ }, w.liveValidation);
522
+
523
+ var newWriter = _extends({}, w, {
524
+ errors: errors,
525
+ liveValidation: _liveValidation
526
+ });
527
+
528
+ executeCb(errorCallback);
529
+ return newWriter;
530
+ }
531
+ });
532
+ }, [executeCb]);
533
+ var validateForm = useCallback(function (successCallback, errorCallback, options) {
534
+ if (options === void 0) {
535
+ options = {};
536
+ }
537
+
538
+ return privateValidateForm(successCallback, errorCallback, {
539
+ options: options
540
+ });
541
+ }, [privateValidateForm]);
542
+ var submitForm = useCallback(function (successCallback, errorCallback, options) {
543
+ if (options === void 0) {
544
+ options = {};
545
+ }
546
+
547
+ var fn = function fn() {
548
+ return setWriter(function (w) {
549
+ return _extends({}, w, {
550
+ isDirty: false
551
+ });
552
+ });
553
+ };
554
+
555
+ var successCallbackAndClearIsDirty = function successCallbackAndClearIsDirty(a, b) {
556
+ var writer = a;
557
+
558
+ var _writer$form = writer.form,
559
+ form = _objectWithoutPropertiesLoose(_writer$form, ["__metadata"]);
560
+
561
+ return successCallback(_extends({}, writer, {
562
+ form: form
563
+ }), b, fn);
564
+ };
565
+
566
+ return privateValidateForm(successCallbackAndClearIsDirty, errorCallback, {
567
+ options: options
568
+ });
569
+ }, [privateValidateForm]);
570
+ var resetForm = useCallback(function () {
571
+ setWriter(function (w) {
572
+ return _extends({}, w, {
573
+ form: w.initialValues,
574
+ errors: {},
575
+ isDirty: false,
576
+ liveValidation: {}
577
+ });
578
+ });
579
+ }, []);
580
+ var isFormValid = useCallback(function () {
581
+ var _writer$errors = writer.errors,
582
+ e = _objectWithoutPropertiesLoose(_writer$errors, ["silent"]);
583
+
584
+ return objLeaves(e).every(function (leaf) {
585
+ return !get(e, leaf);
586
+ });
587
+ }, [writer.errors]);
588
+ var isFormInvalid = useCallback(function () {
589
+ var _writer$errors2 = writer.errors,
590
+ e = _objectWithoutPropertiesLoose(_writer$errors2, ["silent"]);
591
+
592
+ return objLeaves(e).some(function (leaf) {
593
+ return get(e, leaf);
594
+ });
595
+ }, [writer.errors]);
596
+ var error = useCallback(function (path) {
597
+ return get(writer.errors, path, undefined);
598
+ }, [writer.errors]);
599
+ var liveValidation = useCallback(function (path) {
600
+ return get(writer.liveValidation, path, undefined);
601
+ }, [writer.liveValidation]);
602
+ return {
603
+ check: check,
604
+ error: error,
605
+ errors: writer.errors,
606
+ form: writer.form,
607
+ initialize: initialize,
608
+ isDirty: writer.isDirty,
609
+ isFormInvalid: isFormInvalid,
610
+ isFormValid: isFormValid,
611
+ liveValidation: liveValidation,
612
+ remove: remove,
613
+ resetForm: resetForm,
614
+ setError: setError,
615
+ setSchema: setSchema,
616
+ submitForm: submitForm,
617
+ validate: validate,
618
+ validateAll: validateAll,
619
+ validateForm: validateForm,
620
+ write: write,
621
+ writeAll: writeAll
622
+ };
623
+ });
624
+
625
+ var createFormbitContext = once(function () {
626
+ return createContext(undefined);
627
+ });
628
+ function FormbitContextProvider(_ref) {
629
+ var _ref$initialValues = _ref.initialValues,
630
+ initialValues = _ref$initialValues === void 0 ? {} : _ref$initialValues,
631
+ schema = _ref.schema,
632
+ children = _ref.children;
633
+ var FormbitContext = createFormbitContext();
634
+ var value = useFormbit({
635
+ initialValues: initialValues,
636
+ yup: schema || object()
637
+ });
638
+ return /*#__PURE__*/React.createElement(FormbitContext.Provider, {
639
+ value: value
640
+ }, children);
641
+ }
642
+ var useFormbitContext = function useFormbitContext() {
643
+ var context = useContext(createFormbitContext());
644
+
645
+ if (!context) {
646
+ throw new Error(MISSING_CONTEXT_ERROR);
647
+ }
648
+
649
+ return context;
650
+ };
651
+
652
+ export default useFormbit;
653
+ export { FormbitContextProvider, useFormbitContext };
654
+ //# sourceMappingURL=index.modern.js.map