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