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