@formhaus/core 0.13.1 → 0.14.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 (63) hide show
  1. package/dist/{check-definition-DuLExofm.d.ts → check-definition-DyiWqhEV.d.ts} +3 -3
  2. package/dist/chunk-5WADJMJJ.js +2 -0
  3. package/dist/chunk-5WADJMJJ.js.map +1 -0
  4. package/dist/chunk-5YPOS62Y.js +3 -0
  5. package/dist/chunk-5YPOS62Y.js.map +1 -0
  6. package/dist/chunk-CW5ZWCSD.js +2 -0
  7. package/dist/chunk-CW5ZWCSD.js.map +1 -0
  8. package/dist/chunk-QMT7RJ4T.js +3 -0
  9. package/dist/chunk-QMT7RJ4T.js.map +1 -0
  10. package/dist/chunk-QVA6DLYS.js +2 -0
  11. package/dist/chunk-QVA6DLYS.js.map +1 -0
  12. package/dist/chunk-REIX6ART.js +2 -0
  13. package/dist/chunk-REIX6ART.js.map +1 -0
  14. package/dist/chunk-TMO47L42.js +5 -0
  15. package/dist/chunk-TMO47L42.js.map +1 -0
  16. package/dist/cloud.d.ts +3 -3
  17. package/dist/cloud.js +1 -1
  18. package/dist/{controller-Ds_kbXSU.d.ts → controller-BJVYkMHT.d.ts} +1 -1
  19. package/dist/default-messages-E-nZe4Tc.d.ts +10 -0
  20. package/dist/{definition-B4OIy_wH.d.ts → definition-o4Y0OY6y.d.ts} +53 -6
  21. package/dist/fix.d.ts +38 -0
  22. package/dist/fix.js +3 -0
  23. package/dist/fix.js.map +1 -0
  24. package/dist/i18n.d.ts +4 -3
  25. package/dist/i18n.js +1 -1
  26. package/dist/i18n.js.map +1 -1
  27. package/dist/{runtime-BN2PuKD7.d.ts → index-BNGgMIbC.d.ts} +20 -6
  28. package/dist/index.d.ts +67 -11
  29. package/dist/index.js +1 -1
  30. package/dist/internal.d.ts +28 -8
  31. package/dist/internal.js +1 -1
  32. package/dist/internal.js.map +1 -1
  33. package/dist/issues-Dua58e1J.d.ts +14 -0
  34. package/dist/server.d.ts +5 -5
  35. package/dist/server.iife.js +3 -3
  36. package/dist/server.iife.js.map +1 -1
  37. package/dist/server.js +1 -1
  38. package/dist/server.js.map +1 -1
  39. package/dist/{validate-field-ND_UxoJU.d.ts → validate-field-CRR6GQBA.d.ts} +2 -2
  40. package/fixtures/submissions/choices.json +6 -26
  41. package/fixtures/submissions/groups.json +649 -0
  42. package/fixtures/submissions/messages.json +4 -16
  43. package/fixtures/submissions/show-conditions.json +2 -7
  44. package/fixtures/submissions/skip-routes.json +1 -3
  45. package/fixtures/submissions/skip.json +3 -9
  46. package/fixtures/submissions/special-types.json +2 -6
  47. package/package.json +10 -6
  48. package/schema/form-definition.schema.json +380 -19
  49. package/schema/form-translation.schema.json +79 -1
  50. package/style.css +103 -82
  51. package/dist/chunk-35SAVPYL.js +0 -2
  52. package/dist/chunk-35SAVPYL.js.map +0 -1
  53. package/dist/chunk-76YV4J3Q.js +0 -3
  54. package/dist/chunk-76YV4J3Q.js.map +0 -1
  55. package/dist/chunk-PBTYUSZR.js +0 -2
  56. package/dist/chunk-PBTYUSZR.js.map +0 -1
  57. package/dist/chunk-PZEBYRGE.js +0 -2
  58. package/dist/chunk-PZEBYRGE.js.map +0 -1
  59. package/dist/chunk-RN5GQHKN.js +0 -5
  60. package/dist/chunk-RN5GQHKN.js.map +0 -1
  61. package/dist/chunk-YTUVSJUF.js +0 -3
  62. package/dist/chunk-YTUVSJUF.js.map +0 -1
  63. package/dist/default-messages-yS4QtrYi.d.ts +0 -23
@@ -163,9 +163,7 @@
163
163
  "bonusCode": "B1",
164
164
  "terms": true
165
165
  },
166
- "skippedSteps": [
167
- "extras"
168
- ]
166
+ "skippedSteps": ["extras"]
169
167
  },
170
168
  "expected": {
171
169
  "values": {
@@ -101,9 +101,7 @@
101
101
  "perk": "Lounge",
102
102
  "terms": true
103
103
  },
104
- "skippedSteps": [
105
- "extras"
106
- ]
104
+ "skippedSteps": ["extras"]
107
105
  },
108
106
  "expected": {
109
107
  "values": {
@@ -120,9 +118,7 @@
120
118
  "tier": "basic",
121
119
  "terms": true
122
120
  },
123
- "skippedSteps": [
124
- "profile"
125
- ]
121
+ "skippedSteps": ["profile"]
126
122
  },
127
123
  "expected": {
128
124
  "values": {
@@ -143,9 +139,7 @@
143
139
  "phone": "+1",
144
140
  "terms": false
145
141
  },
146
- "skippedSteps": [
147
- "nope"
148
- ]
142
+ "skippedSteps": ["nope"]
149
143
  },
150
144
  "expected": {
151
145
  "values": {
@@ -102,9 +102,7 @@
102
102
  "rating": {
103
103
  "$gt": 0
104
104
  },
105
- "color": [
106
- 1
107
- ]
105
+ "color": [1]
108
106
  },
109
107
  "skippedSteps": []
110
108
  },
@@ -116,9 +114,7 @@
116
114
  "rating": {
117
115
  "$gt": 0
118
116
  },
119
- "color": [
120
- 1
121
- ]
117
+ "color": [1]
122
118
  },
123
119
  "errors": {
124
120
  "avatar": "Must be a file reference",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formhaus/core",
3
- "version": "0.13.1",
3
+ "version": "0.14.0",
4
4
  "description": "JSON form definition engine: validation, conditional visibility, multi-step and branching routes. Zero dependencies, works in React, Vue, Svelte or vanilla.",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -13,23 +13,27 @@
13
13
  "exports": {
14
14
  ".": {
15
15
  "types": "./dist/index.d.ts",
16
- "import": "./dist/index.js"
16
+ "default": "./dist/index.js"
17
17
  },
18
18
  "./cloud": {
19
19
  "types": "./dist/cloud.d.ts",
20
- "import": "./dist/cloud.js"
20
+ "default": "./dist/cloud.js"
21
21
  },
22
22
  "./server": {
23
23
  "types": "./dist/server.d.ts",
24
- "import": "./dist/server.js"
24
+ "default": "./dist/server.js"
25
25
  },
26
26
  "./internal": {
27
27
  "types": "./dist/internal.d.ts",
28
- "import": "./dist/internal.js"
28
+ "default": "./dist/internal.js"
29
29
  },
30
30
  "./i18n": {
31
31
  "types": "./dist/i18n.d.ts",
32
- "import": "./dist/i18n.js"
32
+ "default": "./dist/i18n.js"
33
+ },
34
+ "./fix": {
35
+ "types": "./dist/fix.d.ts",
36
+ "import": "./dist/fix.js"
33
37
  },
34
38
  "./server.iife.js": "./dist/server.iife.js",
35
39
  "./style.css": "./style.css",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "formatVersion": {
11
11
  "type": "string",
12
- "description": "Format version of the definition, such as \"1.0\". Core rejects a newer major version.",
12
+ "description": "Format version of the definition, such as \"1.1\". Core rejects a newer major version. Sections and groups need \"1.1\".",
13
13
  "pattern": "^[1-9]\\d*(\\.\\d+)?$"
14
14
  },
15
15
  "id": {
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "labels": {
37
37
  "$ref": "#/definitions/LabelCatalog",
38
- "description": "Renderer label templates: continue, back, stepOf ({current}, {total}) and errorSummary."
38
+ "description": "Renderer label templates: continue, back, stepOf ({current}, {total}), errorSummary, addItem, removeItem, itemLabel ({label}, {index}), itemAdded, itemRemoved, removeItemPrompt and removeItemBody ({item}), removeItemNamed ({label}, {item}) and cancel."
39
39
  },
40
40
  "i18n": {
41
41
  "$ref": "#/definitions/FormI18n",
@@ -52,7 +52,7 @@
52
52
  "fields": {
53
53
  "type": "array",
54
54
  "items": {
55
- "$ref": "#/definitions/FormField"
55
+ "$ref": "#/definitions/FormNode"
56
56
  },
57
57
  "description": "Fields of a single-step form."
58
58
  },
@@ -127,6 +127,10 @@
127
127
  "type": "string",
128
128
  "minLength": 1
129
129
  },
130
+ "time": {
131
+ "type": "string",
132
+ "minLength": 1
133
+ },
130
134
  "option": {
131
135
  "type": "string",
132
136
  "minLength": 1
@@ -150,6 +154,10 @@
150
154
  "value": {
151
155
  "type": "string",
152
156
  "minLength": 1
157
+ },
158
+ "hidden": {
159
+ "type": "string",
160
+ "minLength": 1
153
161
  }
154
162
  },
155
163
  "additionalProperties": false
@@ -172,6 +180,42 @@
172
180
  "errorSummary": {
173
181
  "type": "string",
174
182
  "minLength": 1
183
+ },
184
+ "addItem": {
185
+ "type": "string",
186
+ "minLength": 1
187
+ },
188
+ "removeItem": {
189
+ "type": "string",
190
+ "minLength": 1
191
+ },
192
+ "itemLabel": {
193
+ "type": "string",
194
+ "minLength": 1
195
+ },
196
+ "itemAdded": {
197
+ "type": "string",
198
+ "minLength": 1
199
+ },
200
+ "itemRemoved": {
201
+ "type": "string",
202
+ "minLength": 1
203
+ },
204
+ "removeItemNamed": {
205
+ "type": "string",
206
+ "minLength": 1
207
+ },
208
+ "removeItemPrompt": {
209
+ "type": "string",
210
+ "minLength": 1
211
+ },
212
+ "removeItemBody": {
213
+ "type": "string",
214
+ "minLength": 1
215
+ },
216
+ "cancel": {
217
+ "type": "string",
218
+ "minLength": 1
175
219
  }
176
220
  },
177
221
  "additionalProperties": false
@@ -308,6 +352,39 @@
308
352
  },
309
353
  "additionalProperties": false
310
354
  },
355
+ "FormNode": {
356
+ "if": {
357
+ "properties": {
358
+ "type": {
359
+ "const": "section"
360
+ }
361
+ },
362
+ "required": [
363
+ "type"
364
+ ]
365
+ },
366
+ "then": {
367
+ "$ref": "#/definitions/FormSection"
368
+ },
369
+ "else": {
370
+ "if": {
371
+ "properties": {
372
+ "type": {
373
+ "const": "group"
374
+ }
375
+ },
376
+ "required": [
377
+ "type"
378
+ ]
379
+ },
380
+ "then": {
381
+ "$ref": "#/definitions/FormGroup"
382
+ },
383
+ "else": {
384
+ "$ref": "#/definitions/FormField"
385
+ }
386
+ }
387
+ },
311
388
  "FormField": {
312
389
  "type": "object",
313
390
  "properties": {
@@ -354,6 +431,10 @@
354
431
  "defaultValue": {
355
432
  "description": "Initial value. Also the value restored on reset or skip."
356
433
  },
434
+ "source": {
435
+ "$ref": "#/definitions/FieldSource",
436
+ "description": "Fills a hidden field in the browser at mount: a URL parameter ({ \"query\": \"utm_source\" }), the referrer, the page URL without query and hash, the page title, the browser language, the time zone or the device class. country is filled by the server. defaultValue is the fallback and initialValues win."
437
+ },
357
438
  "show": {
358
439
  "type": "array",
359
440
  "items": {
@@ -457,7 +538,41 @@
457
538
  "file",
458
539
  "date",
459
540
  "datetime",
460
- "textarea"
541
+ "time",
542
+ "textarea",
543
+ "hidden"
544
+ ]
545
+ },
546
+ "FieldSource": {
547
+ "anyOf": [
548
+ {
549
+ "$ref": "#/definitions/FieldSourceName"
550
+ },
551
+ {
552
+ "type": "object",
553
+ "properties": {
554
+ "query": {
555
+ "type": "string",
556
+ "minLength": 1
557
+ }
558
+ },
559
+ "required": [
560
+ "query"
561
+ ],
562
+ "additionalProperties": false
563
+ }
564
+ ]
565
+ },
566
+ "FieldSourceName": {
567
+ "type": "string",
568
+ "enum": [
569
+ "referrer",
570
+ "page",
571
+ "pageTitle",
572
+ "language",
573
+ "timezone",
574
+ "device",
575
+ "country"
461
576
  ]
462
577
  },
463
578
  "FieldValidation": {
@@ -588,6 +703,266 @@
588
703
  },
589
704
  "additionalProperties": false
590
705
  },
706
+ "FormSection": {
707
+ "type": "object",
708
+ "properties": {
709
+ "key": {
710
+ "type": "string",
711
+ "description": "Section identifier for translations, DOM ids and editors. Unique among field keys. Conditions cannot test it.",
712
+ "not": {
713
+ "enum": [
714
+ "__defineGetter__",
715
+ "__defineSetter__",
716
+ "__lookupGetter__",
717
+ "__lookupSetter__",
718
+ "__proto__",
719
+ "constructor",
720
+ "hasOwnProperty",
721
+ "isPrototypeOf",
722
+ "propertyIsEnumerable",
723
+ "prototype",
724
+ "toLocaleString",
725
+ "toString",
726
+ "valueOf"
727
+ ]
728
+ }
729
+ },
730
+ "type": {
731
+ "type": "string",
732
+ "const": "section"
733
+ },
734
+ "title": {
735
+ "type": "string",
736
+ "description": "Section heading."
737
+ },
738
+ "description": {
739
+ "type": "string",
740
+ "description": "Text below the section heading."
741
+ },
742
+ "show": {
743
+ "type": "array",
744
+ "items": {
745
+ "$ref": "#/definitions/ShowCondition"
746
+ },
747
+ "description": "Section and its fields are visible only when all conditions match. Hidden fields are cleared."
748
+ },
749
+ "showAny": {
750
+ "type": "array",
751
+ "items": {
752
+ "$ref": "#/definitions/ShowCondition"
753
+ },
754
+ "description": "Section is visible when any condition matches."
755
+ },
756
+ "fields": {
757
+ "type": "array",
758
+ "items": {
759
+ "if": {
760
+ "properties": {
761
+ "type": {
762
+ "const": "group"
763
+ }
764
+ },
765
+ "required": [
766
+ "type"
767
+ ]
768
+ },
769
+ "then": {
770
+ "$ref": "#/definitions/FormGroup"
771
+ },
772
+ "else": {
773
+ "$ref": "#/definitions/FormField"
774
+ }
775
+ },
776
+ "description": "Fields and groups of the section. Sections do not nest."
777
+ },
778
+ "i18n": {
779
+ "$ref": "#/definitions/StepI18n",
780
+ "description": "Translation keys for the section title and description."
781
+ }
782
+ },
783
+ "required": [
784
+ "key",
785
+ "type",
786
+ "title",
787
+ "fields"
788
+ ],
789
+ "additionalProperties": false,
790
+ "description": "A titled block of fields with shared show conditions. Its fields keep their own keys in the submitted values."
791
+ },
792
+ "FormGroup": {
793
+ "type": "object",
794
+ "properties": {
795
+ "key": {
796
+ "type": "string",
797
+ "description": "Key of the item array in the submitted values. No other field key may start with this key and a dot.",
798
+ "not": {
799
+ "enum": [
800
+ "__defineGetter__",
801
+ "__defineSetter__",
802
+ "__lookupGetter__",
803
+ "__lookupSetter__",
804
+ "__proto__",
805
+ "constructor",
806
+ "hasOwnProperty",
807
+ "isPrototypeOf",
808
+ "propertyIsEnumerable",
809
+ "prototype",
810
+ "toLocaleString",
811
+ "toString",
812
+ "valueOf"
813
+ ]
814
+ }
815
+ },
816
+ "type": {
817
+ "type": "string",
818
+ "const": "group"
819
+ },
820
+ "label": {
821
+ "type": "string",
822
+ "description": "Group heading."
823
+ },
824
+ "helperText": {
825
+ "type": "string",
826
+ "description": "Hint text below the group heading."
827
+ },
828
+ "itemLabel": {
829
+ "type": "string",
830
+ "description": "Item heading. {index} is the 1-based item number, {label} the group label."
831
+ },
832
+ "addLabel": {
833
+ "type": "string",
834
+ "description": "Text of the button that adds an item."
835
+ },
836
+ "removeLabel": {
837
+ "type": "string",
838
+ "description": "Text of the button that removes an item."
839
+ },
840
+ "defaultItems": {
841
+ "type": "integer",
842
+ "description": "Number of empty items the group starts with.",
843
+ "minimum": 0
844
+ },
845
+ "show": {
846
+ "type": "array",
847
+ "items": {
848
+ "$ref": "#/definitions/ShowCondition"
849
+ },
850
+ "description": "Group is visible only when all conditions match. A hidden group is cleared."
851
+ },
852
+ "showAny": {
853
+ "type": "array",
854
+ "items": {
855
+ "$ref": "#/definitions/ShowCondition"
856
+ },
857
+ "description": "Group is visible when any condition matches."
858
+ },
859
+ "validation": {
860
+ "$ref": "#/definitions/GroupValidation",
861
+ "description": "Item count rules. required means at least one item; minLength and maxLength count items."
862
+ },
863
+ "fields": {
864
+ "type": "array",
865
+ "items": {
866
+ "$ref": "#/definitions/FormField"
867
+ },
868
+ "description": "Fields of one item. Their keys are unique in the item and do not repeat a key outside the group. Their conditions can test fields of the same item and fields outside the group."
869
+ },
870
+ "i18n": {
871
+ "$ref": "#/definitions/GroupI18n",
872
+ "description": "Translation keys for the group texts."
873
+ }
874
+ },
875
+ "required": [
876
+ "key",
877
+ "type",
878
+ "label",
879
+ "fields"
880
+ ],
881
+ "additionalProperties": false,
882
+ "description": "A repeatable group. Its value is an array of item objects keyed by the keys of its fields."
883
+ },
884
+ "GroupValidation": {
885
+ "type": "object",
886
+ "properties": {
887
+ "required": {
888
+ "type": [
889
+ "boolean",
890
+ "string"
891
+ ]
892
+ },
893
+ "minLength": {
894
+ "type": "number"
895
+ },
896
+ "minLengthMessage": {
897
+ "type": "string"
898
+ },
899
+ "maxLength": {
900
+ "type": "number"
901
+ },
902
+ "maxLengthMessage": {
903
+ "type": "string"
904
+ },
905
+ "validator": {
906
+ "type": "string"
907
+ },
908
+ "i18n": {
909
+ "type": "object",
910
+ "properties": {
911
+ "required": {
912
+ "type": "string"
913
+ },
914
+ "minLength": {
915
+ "type": "string"
916
+ },
917
+ "maxLength": {
918
+ "type": "string"
919
+ }
920
+ },
921
+ "additionalProperties": false
922
+ }
923
+ },
924
+ "additionalProperties": false
925
+ },
926
+ "GroupI18n": {
927
+ "type": "object",
928
+ "properties": {
929
+ "label": {
930
+ "type": "string",
931
+ "minLength": 1
932
+ },
933
+ "helperText": {
934
+ "type": "string",
935
+ "minLength": 1
936
+ },
937
+ "itemLabel": {
938
+ "type": "string",
939
+ "minLength": 1
940
+ },
941
+ "addLabel": {
942
+ "type": "string",
943
+ "minLength": 1
944
+ },
945
+ "removeLabel": {
946
+ "type": "string",
947
+ "minLength": 1
948
+ }
949
+ },
950
+ "additionalProperties": false
951
+ },
952
+ "StepI18n": {
953
+ "type": "object",
954
+ "properties": {
955
+ "title": {
956
+ "type": "string",
957
+ "minLength": 1
958
+ },
959
+ "description": {
960
+ "type": "string",
961
+ "minLength": 1
962
+ }
963
+ },
964
+ "additionalProperties": false
965
+ },
591
966
  "FormStep": {
592
967
  "type": "object",
593
968
  "properties": {
@@ -611,7 +986,7 @@
611
986
  "fields": {
612
987
  "type": "array",
613
988
  "items": {
614
- "$ref": "#/definitions/FormField"
989
+ "$ref": "#/definitions/FormNode"
615
990
  }
616
991
  },
617
992
  "show": {
@@ -698,20 +1073,6 @@
698
1073
  ],
699
1074
  "additionalProperties": false,
700
1075
  "description": "A forward destination for a step."
701
- },
702
- "StepI18n": {
703
- "type": "object",
704
- "properties": {
705
- "title": {
706
- "type": "string",
707
- "minLength": 1
708
- },
709
- "description": {
710
- "type": "string",
711
- "minLength": 1
712
- }
713
- },
714
- "additionalProperties": false
715
1076
  }
716
1077
  }
717
1078
  }