relay-forms-nodeps 2.0.0 → 2.2.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.
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @generated SignedSource<<d21170d0feb748c6558c5e5dbb4425c4>>
5
+ * @lightSyntaxTransform
6
+ * @nogrep
7
+ */
8
+ Object.defineProperty(exports, "__esModule", {
9
+ value: true
10
+ });
11
+ var node = {
12
+ "argumentDefinitions": [],
13
+ "kind": "Fragment",
14
+ "metadata": null,
15
+ "name": "queryFieldFragment",
16
+ "selections": [{
17
+ "alias": null,
18
+ "args": null,
19
+ "kind": "ScalarField",
20
+ "name": "id",
21
+ "storageKey": null
22
+ }, {
23
+ "alias": null,
24
+ "args": null,
25
+ "kind": "ScalarField",
26
+ "name": "check",
27
+ "storageKey": null
28
+ }],
29
+ "type": "Entry",
30
+ "abstractKey": null
31
+ };
32
+ node.hash = "d5b0953bdeb412925ee13444a6be6082";
33
+ exports.default = node;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @generated SignedSource<<6f460eca2a43fd75eab202937349c693>>
3
+ * @relayHash 0b493a6f66e132f2693f91a5da941414
4
+ * @lightSyntaxTransform
5
+ * @nogrep
6
+ */
7
+ import { ConcreteRequest } from 'relay-runtime';
8
+ export declare type queryFieldQuery$variables = Record<PropertyKey, never>;
9
+ export declare type queryFieldQuery$data = {
10
+ readonly form: {
11
+ readonly entries: ReadonlyArray<{
12
+ readonly check: number | null | undefined;
13
+ readonly error: string | null | undefined;
14
+ readonly id: string;
15
+ readonly key: string;
16
+ readonly value: string | null | undefined;
17
+ } | null | undefined> | null | undefined;
18
+ } | null | undefined;
19
+ };
20
+ export declare type queryFieldQuery = {
21
+ response: queryFieldQuery$data;
22
+ variables: queryFieldQuery$variables;
23
+ };
24
+ declare const node: ConcreteRequest;
25
+ export default node;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @generated SignedSource<<6f460eca2a43fd75eab202937349c693>>
5
+ * @relayHash 0b493a6f66e132f2693f91a5da941414
6
+ * @lightSyntaxTransform
7
+ * @nogrep
8
+ */
9
+ Object.defineProperty(exports, "__esModule", {
10
+ value: true
11
+ });
12
+ var node = function () {
13
+ var v0 = [{
14
+ "alias": null,
15
+ "args": null,
16
+ "concreteType": "EntryForm",
17
+ "kind": "LinkedField",
18
+ "name": "form",
19
+ "plural": false,
20
+ "selections": [{
21
+ "alias": null,
22
+ "args": null,
23
+ "concreteType": "Entry",
24
+ "kind": "LinkedField",
25
+ "name": "entries",
26
+ "plural": true,
27
+ "selections": [{
28
+ "alias": null,
29
+ "args": null,
30
+ "kind": "ScalarField",
31
+ "name": "id",
32
+ "storageKey": null
33
+ }, {
34
+ "alias": null,
35
+ "args": null,
36
+ "kind": "ScalarField",
37
+ "name": "key",
38
+ "storageKey": null
39
+ }, {
40
+ "alias": null,
41
+ "args": null,
42
+ "kind": "ScalarField",
43
+ "name": "value",
44
+ "storageKey": null
45
+ }, {
46
+ "alias": null,
47
+ "args": null,
48
+ "kind": "ScalarField",
49
+ "name": "check",
50
+ "storageKey": null
51
+ }, {
52
+ "alias": null,
53
+ "args": null,
54
+ "kind": "ScalarField",
55
+ "name": "error",
56
+ "storageKey": null
57
+ }],
58
+ "storageKey": null
59
+ }],
60
+ "storageKey": null
61
+ }];
62
+ return {
63
+ "fragment": {
64
+ "argumentDefinitions": [],
65
+ "kind": "Fragment",
66
+ "metadata": null,
67
+ "name": "queryFieldQuery",
68
+ "selections": v0 /*: any*/,
69
+ "type": "Query",
70
+ "abstractKey": null
71
+ },
72
+ "kind": "Request",
73
+ "operation": {
74
+ "argumentDefinitions": [],
75
+ "kind": "Operation",
76
+ "name": "queryFieldQuery",
77
+ "selections": v0 /*: any*/
78
+ },
79
+
80
+ "params": {
81
+ "id": "0b493a6f66e132f2693f91a5da941414\r",
82
+ "metadata": {},
83
+ "name": "queryFieldQuery",
84
+ "operationKind": "query",
85
+ "text": null
86
+ }
87
+ };
88
+ }();
89
+ node.hash = "f9fd20a80a839dfb51206c305cbb1657";
90
+ exports.default = node;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @generated SignedSource<<432c971608826457e61804e44aeb7a64>>
3
+ * @lightSyntaxTransform
4
+ * @nogrep
5
+ */
6
+ import { ReaderFragment } from 'relay-runtime';
7
+ import { FragmentRefs } from "relay-runtime";
8
+ export declare type queryValueFieldFragment$data = {
9
+ readonly error: string | null | undefined;
10
+ readonly id: string;
11
+ readonly label: string | null | undefined;
12
+ readonly value: string | null | undefined;
13
+ readonly " $fragmentType": "queryValueFieldFragment";
14
+ };
15
+ export declare type queryValueFieldFragment$key = {
16
+ readonly " $data"?: queryValueFieldFragment$data;
17
+ readonly " $fragmentSpreads": FragmentRefs<"queryValueFieldFragment">;
18
+ };
19
+ declare const node: ReaderFragment;
20
+ export default node;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @generated SignedSource<<432c971608826457e61804e44aeb7a64>>
5
+ * @lightSyntaxTransform
6
+ * @nogrep
7
+ */
8
+ Object.defineProperty(exports, "__esModule", {
9
+ value: true
10
+ });
11
+ var node = {
12
+ "argumentDefinitions": [],
13
+ "kind": "Fragment",
14
+ "metadata": null,
15
+ "name": "queryValueFieldFragment",
16
+ "selections": [{
17
+ "alias": null,
18
+ "args": null,
19
+ "kind": "ScalarField",
20
+ "name": "id",
21
+ "storageKey": null
22
+ }, {
23
+ "alias": null,
24
+ "args": null,
25
+ "kind": "ScalarField",
26
+ "name": "value",
27
+ "storageKey": null
28
+ }, {
29
+ "alias": null,
30
+ "args": null,
31
+ "kind": "ScalarField",
32
+ "name": "label",
33
+ "storageKey": null
34
+ }, {
35
+ "alias": null,
36
+ "args": null,
37
+ "kind": "ScalarField",
38
+ "name": "error",
39
+ "storageKey": null
40
+ }],
41
+ "type": "Entry",
42
+ "abstractKey": null
43
+ };
44
+ node.hash = "364beea31c4e318a5241f2bd7d96fbd8";
45
+ exports.default = node;
@@ -364,6 +364,100 @@ var useFormState = function () {
364
364
  return data;
365
365
  };
366
366
 
367
+ /*! *****************************************************************************
368
+ Copyright (c) Microsoft Corporation.
369
+
370
+ Permission to use, copy, modify, and/or distribute this software for any
371
+ purpose with or without fee is hereby granted.
372
+
373
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
374
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
375
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
376
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
377
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
378
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
379
+ PERFORMANCE OF THIS SOFTWARE.
380
+ ***************************************************************************** */
381
+
382
+ var __assign = function() {
383
+ __assign = Object.assign || function __assign(t) {
384
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
385
+ s = arguments[i];
386
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
387
+ }
388
+ return t;
389
+ };
390
+ return __assign.apply(this, arguments);
391
+ };
392
+
393
+ function __generator(thisArg, body) {
394
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
395
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
396
+ function verb(n) { return function (v) { return step([n, v]); }; }
397
+ function step(op) {
398
+ if (f) throw new TypeError("Generator is already executing.");
399
+ while (_) try {
400
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
401
+ if (y = 0, t) op = [op[0] & 2, t.value];
402
+ switch (op[0]) {
403
+ case 0: case 1: t = op; break;
404
+ case 4: _.label++; return { value: op[1], done: false };
405
+ case 5: _.label++; y = op[1]; op = [0]; continue;
406
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
407
+ default:
408
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
409
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
410
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
411
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
412
+ if (t[2]) _.ops.pop();
413
+ _.trys.pop(); continue;
414
+ }
415
+ op = body.call(thisArg, _);
416
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
417
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
418
+ }
419
+ }
420
+
421
+ /**
422
+ * @generated SignedSource<<432c971608826457e61804e44aeb7a64>>
423
+ * @lightSyntaxTransform
424
+ * @nogrep
425
+ */
426
+ var node = {
427
+ "argumentDefinitions": [],
428
+ "kind": "Fragment",
429
+ "metadata": null,
430
+ "name": "queryValueFieldFragment",
431
+ "selections": [{
432
+ "alias": null,
433
+ "args": null,
434
+ "kind": "ScalarField",
435
+ "name": "id",
436
+ "storageKey": null
437
+ }, {
438
+ "alias": null,
439
+ "args": null,
440
+ "kind": "ScalarField",
441
+ "name": "value",
442
+ "storageKey": null
443
+ }, {
444
+ "alias": null,
445
+ "args": null,
446
+ "kind": "ScalarField",
447
+ "name": "label",
448
+ "storageKey": null
449
+ }, {
450
+ "alias": null,
451
+ "args": null,
452
+ "kind": "ScalarField",
453
+ "name": "error",
454
+ "storageKey": null
455
+ }],
456
+ "type": "Entry",
457
+ "abstractKey": null
458
+ };
459
+ node.hash = "364beea31c4e318a5241f2bd7d96fbd8";
460
+
367
461
  function useForceUpdate() {
368
462
  var _a = React.useReducer(function (x) {
369
463
  return x + 1;
@@ -390,10 +484,15 @@ function logicSetValue(params) {
390
484
  initialValue = params.initialValue,
391
485
  forceUpdate = params.forceUpdate,
392
486
  validateOnChange = params.validateOnChange,
393
- label = params.label;
487
+ label = params.label,
488
+ dependsOn = params.dependsOn;
394
489
  var validate = undefined;
395
490
  var firstSet = true;
491
+ var deps = {};
396
492
  var localId = getFieldId(key);
493
+ function getDeps() {
494
+ return deps;
495
+ }
397
496
  function getValidate() {
398
497
  return validate;
399
498
  }
@@ -468,13 +567,14 @@ function logicSetValue(params) {
468
567
  }
469
568
  commitField(false);
470
569
  }
471
- function internalValidate(value, validateFunction) {
570
+ function internalValidate(value, validateFunction, depsValidation) {
472
571
  ref.isChecking = true;
473
- var result = validateFunction(value);
572
+ var result = validateFunction(value, deps);
474
573
  function internalFinalize(error) {
475
574
  var validate = getValidate();
476
- if (value !== dataResult.value || validate !== validateFunction) {
477
- internalValidate(dataResult.value, validate);
575
+ var deps = getDeps();
576
+ if (value !== dataResult.value || validate !== validateFunction || deps !== depsValidation) {
577
+ internalValidate(dataResult.value, validate, deps);
478
578
  return;
479
579
  }
480
580
  finalizeCheck(error);
@@ -498,9 +598,23 @@ function logicSetValue(params) {
498
598
  ref.check = getInitCheck(validate);
499
599
  setValueInternal(initialValue);
500
600
  } else if (isValidating && !ref.isChecking) {
501
- internalValidate(dataResult.value, validate);
601
+ internalValidate(dataResult.value, validate, deps);
502
602
  }
503
603
  }).dispose;
604
+ if (dependsOn != null) {
605
+ dependsOn.forEach(function (depKey) {
606
+ var snapshot = getSnapshot(environment, node, depKey);
607
+ environment.subscribe(snapshot, function (s) {
608
+ var _a;
609
+ var data = s.data;
610
+ deps = __assign(__assign({}, deps), (_a = {}, _a[depKey] = data, _a));
611
+ if (ref.check == DONEVALIDATED && !ref.isChecking) {
612
+ ref.check = VALIDATING;
613
+ commitField(false);
614
+ }
615
+ }).dispose;
616
+ });
617
+ }
504
618
  var dispose = function () {
505
619
  disposeSubscrition();
506
620
  commit(environment, function (store, form) {
@@ -513,7 +627,7 @@ function logicSetValue(params) {
513
627
  });
514
628
  };
515
629
  if (validateOnChange) {
516
- internalValidate(initialValue, getValidate());
630
+ internalValidate(initialValue, getValidate(), deps);
517
631
  }
518
632
  return dispose;
519
633
  }
@@ -529,7 +643,8 @@ function useFormField(_a) {
529
643
  initialValue = _a.initialValue,
530
644
  validate = _a.validate,
531
645
  validateOnChange = _a.validateOnChange,
532
- label = _a.label;
646
+ label = _a.label,
647
+ dependsOn = _a.dependsOn;
533
648
  var forceUpdate = useForceUpdate();
534
649
  var environment = useStore();
535
650
  var resolver = React__default["default"].useMemo(function () {
@@ -539,9 +654,10 @@ function useFormField(_a) {
539
654
  label: label,
540
655
  initialValue: initialValue,
541
656
  forceUpdate: forceUpdate,
542
- validateOnChange: validateOnChange
657
+ validateOnChange: validateOnChange,
658
+ dependsOn: dependsOn
543
659
  });
544
- }, [environment, key, initialValue, forceUpdate, validateOnChange, label]);
660
+ }, [environment, key, initialValue, forceUpdate, validateOnChange, label, dependsOn]);
545
661
  resolver.setValidate(validate);
546
662
  React__default["default"].useEffect(function () {
547
663
  return resolver.subscribe();
@@ -681,60 +797,6 @@ function useFormValue(key) {
681
797
  return data;
682
798
  }
683
799
 
684
- /*! *****************************************************************************
685
- Copyright (c) Microsoft Corporation.
686
-
687
- Permission to use, copy, modify, and/or distribute this software for any
688
- purpose with or without fee is hereby granted.
689
-
690
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
691
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
692
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
693
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
694
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
695
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
696
- PERFORMANCE OF THIS SOFTWARE.
697
- ***************************************************************************** */
698
-
699
- var __assign = function() {
700
- __assign = Object.assign || function __assign(t) {
701
- for (var s, i = 1, n = arguments.length; i < n; i++) {
702
- s = arguments[i];
703
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
704
- }
705
- return t;
706
- };
707
- return __assign.apply(this, arguments);
708
- };
709
-
710
- function __generator(thisArg, body) {
711
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
712
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
713
- function verb(n) { return function (v) { return step([n, v]); }; }
714
- function step(op) {
715
- if (f) throw new TypeError("Generator is already executing.");
716
- while (_) try {
717
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
718
- if (y = 0, t) op = [op[0] & 2, t.value];
719
- switch (op[0]) {
720
- case 0: case 1: t = op; break;
721
- case 4: _.label++; return { value: op[1], done: false };
722
- case 5: _.label++; y = op[1]; op = [0]; continue;
723
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
724
- default:
725
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
726
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
727
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
728
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
729
- if (t[2]) _.ops.pop();
730
- _.trys.pop(); continue;
731
- }
732
- op = body.call(thisArg, _);
733
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
734
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
735
- }
736
- }
737
-
738
800
  var ID_KEY = RelayStoreUtils.ID_KEY,
739
801
  REF_KEY = RelayStoreUtils.REF_KEY,
740
802
  REFS_KEY = RelayStoreUtils.REFS_KEY;