@es-joy/jsoe 0.16.0 → 0.17.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 (208) hide show
  1. package/.ncurc.cjs +4 -5
  2. package/CHANGES.md +4 -0
  3. package/README.md +27 -3
  4. package/badges/licenses-badge.svg +1 -0
  5. package/dist/formatAndTypeChoices.d.ts +39 -19
  6. package/dist/formatAndTypeChoices.d.ts.map +1 -1
  7. package/dist/formats/indexedDBKey.d.ts +1 -1
  8. package/dist/formats/indexedDBKey.d.ts.map +1 -1
  9. package/dist/formats/json.d.ts +1 -1
  10. package/dist/formats/json.d.ts.map +1 -1
  11. package/dist/formats/schema.d.ts +11 -0
  12. package/dist/formats/schema.d.ts.map +1 -0
  13. package/dist/formats/structuredCloning.d.ts +11 -13
  14. package/dist/formats/structuredCloning.d.ts.map +1 -1
  15. package/dist/formats.d.ts +86 -25
  16. package/dist/formats.d.ts.map +1 -1
  17. package/dist/fundamentalTypes/BooleanObjectType.d.ts +1 -1
  18. package/dist/fundamentalTypes/BooleanObjectType.d.ts.map +1 -1
  19. package/dist/fundamentalTypes/NumberObjectType.d.ts +1 -1
  20. package/dist/fundamentalTypes/NumberObjectType.d.ts.map +1 -1
  21. package/dist/fundamentalTypes/StringObjectType.d.ts +1 -1
  22. package/dist/fundamentalTypes/StringObjectType.d.ts.map +1 -1
  23. package/dist/fundamentalTypes/arrayReferenceType.d.ts +1 -1
  24. package/dist/fundamentalTypes/arrayType.d.ts +3 -3
  25. package/dist/fundamentalTypes/arrayType.d.ts.map +1 -1
  26. package/dist/fundamentalTypes/bigintObjectType.d.ts +6 -0
  27. package/dist/fundamentalTypes/bigintObjectType.d.ts.map +1 -0
  28. package/dist/fundamentalTypes/bigintType.d.ts +1 -1
  29. package/dist/fundamentalTypes/bigintType.d.ts.map +1 -1
  30. package/dist/fundamentalTypes/blobType.d.ts +1 -1
  31. package/dist/fundamentalTypes/blobType.d.ts.map +1 -1
  32. package/dist/fundamentalTypes/booleanType.d.ts +8 -0
  33. package/dist/fundamentalTypes/booleanType.d.ts.map +1 -0
  34. package/dist/fundamentalTypes/catchType.d.ts +6 -0
  35. package/dist/fundamentalTypes/catchType.d.ts.map +1 -0
  36. package/dist/fundamentalTypes/dateType.d.ts +4 -4
  37. package/dist/fundamentalTypes/dateType.d.ts.map +1 -1
  38. package/dist/fundamentalTypes/domexceptionType.d.ts +1 -1
  39. package/dist/fundamentalTypes/domexceptionType.d.ts.map +1 -1
  40. package/dist/fundamentalTypes/enumType.d.ts +6 -0
  41. package/dist/fundamentalTypes/enumType.d.ts.map +1 -0
  42. package/dist/fundamentalTypes/errorType.d.ts +1 -1
  43. package/dist/fundamentalTypes/errorType.d.ts.map +1 -1
  44. package/dist/fundamentalTypes/fileType.d.ts +1 -1
  45. package/dist/fundamentalTypes/fileType.d.ts.map +1 -1
  46. package/dist/fundamentalTypes/filelistType.d.ts +1 -1
  47. package/dist/fundamentalTypes/filelistType.d.ts.map +1 -1
  48. package/dist/fundamentalTypes/functionType.d.ts +6 -0
  49. package/dist/fundamentalTypes/functionType.d.ts.map +1 -0
  50. package/dist/fundamentalTypes/literalType.d.ts +6 -0
  51. package/dist/fundamentalTypes/literalType.d.ts.map +1 -0
  52. package/dist/fundamentalTypes/mapType.d.ts +1 -1
  53. package/dist/fundamentalTypes/mapType.d.ts.map +1 -1
  54. package/dist/fundamentalTypes/nanType.d.ts +6 -0
  55. package/dist/fundamentalTypes/nanType.d.ts.map +1 -0
  56. package/dist/fundamentalTypes/nativeEnumType.d.ts +6 -0
  57. package/dist/fundamentalTypes/nativeEnumType.d.ts.map +1 -0
  58. package/dist/fundamentalTypes/neverType.d.ts +6 -0
  59. package/dist/fundamentalTypes/neverType.d.ts.map +1 -0
  60. package/dist/fundamentalTypes/noneditableType.d.ts +1 -1
  61. package/dist/fundamentalTypes/noneditableType.d.ts.map +1 -1
  62. package/dist/fundamentalTypes/nullType.d.ts +1 -1
  63. package/dist/fundamentalTypes/nullType.d.ts.map +1 -1
  64. package/dist/fundamentalTypes/numberType.d.ts +1 -1
  65. package/dist/fundamentalTypes/numberType.d.ts.map +1 -1
  66. package/dist/fundamentalTypes/objectReferenceType.d.ts +1 -1
  67. package/dist/fundamentalTypes/objectType.d.ts +1 -1
  68. package/dist/fundamentalTypes/objectType.d.ts.map +1 -1
  69. package/dist/fundamentalTypes/promiseType.d.ts +6 -0
  70. package/dist/fundamentalTypes/promiseType.d.ts.map +1 -0
  71. package/dist/fundamentalTypes/recordType.d.ts +6 -0
  72. package/dist/fundamentalTypes/recordType.d.ts.map +1 -0
  73. package/dist/fundamentalTypes/regexpType.d.ts +1 -1
  74. package/dist/fundamentalTypes/regexpType.d.ts.map +1 -1
  75. package/dist/fundamentalTypes/setType.d.ts +1 -1
  76. package/dist/fundamentalTypes/setType.d.ts.map +1 -1
  77. package/dist/fundamentalTypes/sparseUndefinedType.d.ts +1 -1
  78. package/dist/fundamentalTypes/sparseUndefinedType.d.ts.map +1 -1
  79. package/dist/fundamentalTypes/stringType.d.ts +1 -1
  80. package/dist/fundamentalTypes/stringType.d.ts.map +1 -1
  81. package/dist/fundamentalTypes/symbolType.d.ts +8 -0
  82. package/dist/fundamentalTypes/symbolType.d.ts.map +1 -0
  83. package/dist/fundamentalTypes/tupleType.d.ts +6 -0
  84. package/dist/fundamentalTypes/tupleType.d.ts.map +1 -0
  85. package/dist/fundamentalTypes/undefinedType.d.ts +1 -1
  86. package/dist/fundamentalTypes/undefinedType.d.ts.map +1 -1
  87. package/dist/fundamentalTypes/voidType.d.ts +6 -0
  88. package/dist/fundamentalTypes/voidType.d.ts.map +1 -0
  89. package/dist/index.d.ts +2 -2
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/index.js +9660 -1586
  92. package/dist/subTypes/blobHTMLType.d.ts.map +1 -1
  93. package/dist/subTypes/falseType.d.ts +1 -1
  94. package/dist/subTypes/trueType.d.ts +1 -1
  95. package/dist/superTypes/SpecialNumberType.d.ts +1 -1
  96. package/dist/superTypes/SpecialRealNumberType.d.ts +1 -1
  97. package/dist/superTypes/SpecialRealNumberType.d.ts.map +1 -1
  98. package/dist/superTypes/buffersourceType.d.ts +1 -1
  99. package/dist/superTypes/buffersourceType.d.ts.map +1 -1
  100. package/dist/superTypes/dommatrixType.d.ts +1 -1
  101. package/dist/superTypes/dommatrixType.d.ts.map +1 -1
  102. package/dist/superTypes/dompointType.d.ts +1 -1
  103. package/dist/superTypes/dompointType.d.ts.map +1 -1
  104. package/dist/superTypes/domrectType.d.ts +1 -1
  105. package/dist/superTypes/domrectType.d.ts.map +1 -1
  106. package/dist/superTypes/errorsSpecialType.d.ts +1 -1
  107. package/dist/superTypes/errorsSpecialType.d.ts.map +1 -1
  108. package/dist/typeChoices.d.ts +33 -16
  109. package/dist/typeChoices.d.ts.map +1 -1
  110. package/dist/types.d.ts +161 -157
  111. package/dist/types.d.ts.map +1 -1
  112. package/dist/utils/dialogs.d.ts +3 -3
  113. package/dist/utils/dialogs.d.ts.map +1 -1
  114. package/dist/utils/jsonPointer.d.ts.map +1 -1
  115. package/dist/utils/media.d.ts.map +1 -1
  116. package/dist/utils/objects.d.ts +16 -0
  117. package/dist/utils/objects.d.ts.map +1 -0
  118. package/dist/utils/types.d.ts +1 -1
  119. package/dist/utils/types.d.ts.map +1 -1
  120. package/dist/vendor-imports.d.ts +1 -1
  121. package/eslint.config.js +74 -0
  122. package/licenseInfo.json +4 -0
  123. package/package.json +33 -42
  124. package/rollup.config.js +15 -0
  125. package/src/formatAndTypeChoices.js +68 -54
  126. package/src/formats/indexedDBKey.js +9 -4
  127. package/src/formats/json.js +7 -4
  128. package/src/formats/schema.js +772 -0
  129. package/src/formats/structuredCloning.js +187 -86
  130. package/src/formats.js +61 -26
  131. package/src/fundamentalTypes/BooleanObjectType.js +18 -6
  132. package/src/fundamentalTypes/NumberObjectType.js +18 -5
  133. package/src/fundamentalTypes/StringObjectType.js +20 -8
  134. package/src/fundamentalTypes/arrayType.js +1241 -533
  135. package/src/fundamentalTypes/bigintObjectType.js +64 -0
  136. package/src/fundamentalTypes/bigintType.js +31 -5
  137. package/src/fundamentalTypes/blobType.js +201 -190
  138. package/src/fundamentalTypes/booleanType.js +63 -0
  139. package/src/fundamentalTypes/catchType.js +140 -0
  140. package/src/fundamentalTypes/dateType.js +57 -19
  141. package/src/fundamentalTypes/domexceptionType.js +61 -63
  142. package/src/fundamentalTypes/enumType.js +52 -0
  143. package/src/fundamentalTypes/errorType.js +20 -7
  144. package/src/fundamentalTypes/fileType.js +195 -189
  145. package/src/fundamentalTypes/filelistType.js +4 -0
  146. package/src/fundamentalTypes/functionType.js +150 -0
  147. package/src/fundamentalTypes/literalType.js +81 -0
  148. package/src/fundamentalTypes/mapType.js +4 -0
  149. package/src/fundamentalTypes/nanType.js +41 -0
  150. package/src/fundamentalTypes/nativeEnumType.js +155 -0
  151. package/src/fundamentalTypes/neverType.js +44 -0
  152. package/src/fundamentalTypes/noneditableType.js +19 -5
  153. package/src/fundamentalTypes/nullType.js +16 -6
  154. package/src/fundamentalTypes/numberType.js +49 -6
  155. package/src/fundamentalTypes/objectType.js +10 -2
  156. package/src/fundamentalTypes/promiseType.js +60 -0
  157. package/src/fundamentalTypes/recordType.js +42 -0
  158. package/src/fundamentalTypes/regexpType.js +51 -33
  159. package/src/fundamentalTypes/setType.js +4 -0
  160. package/src/fundamentalTypes/sparseUndefinedType.js +3 -0
  161. package/src/fundamentalTypes/stringType.js +254 -6
  162. package/src/fundamentalTypes/symbolType.js +81 -0
  163. package/src/fundamentalTypes/tupleType.js +39 -0
  164. package/src/fundamentalTypes/undefinedType.js +14 -4
  165. package/src/fundamentalTypes/voidType.js +48 -0
  166. package/src/jsoe.css +37 -3
  167. package/src/subTypes/blobHTMLType.js +33 -24
  168. package/src/superTypes/SpecialRealNumberType.js +22 -6
  169. package/src/superTypes/buffersourceType.js +86 -30
  170. package/src/superTypes/dommatrixType.js +24 -7
  171. package/src/superTypes/dompointType.js +27 -7
  172. package/src/superTypes/domrectType.js +33 -7
  173. package/src/superTypes/errorsSpecialType.js +30 -14
  174. package/src/typeChoices.js +115 -44
  175. package/src/types.js +129 -45
  176. package/src/utils/FileList.js +3 -3
  177. package/src/utils/dialogs.js +6 -8
  178. package/src/utils/objects.js +22 -0
  179. package/src/vendor-imports.js +1 -1
  180. package/tsconfig.json +2 -2
  181. package/vendor/jamilih/dist/jml-es.js +23 -6
  182. package/vendor/typeson-registry/dist/index.js +77 -47
  183. package/vendor/zod/lib/index.mjs +4236 -0
  184. package/vendor/zodex/dist/esm/dezerialize.d.ts +26 -0
  185. package/vendor/zodex/dist/esm/dezerialize.js +393 -0
  186. package/vendor/zodex/dist/esm/index.d.ts +9 -0
  187. package/vendor/zodex/dist/esm/index.js +4 -0
  188. package/vendor/zodex/dist/esm/infer.d.ts +29 -0
  189. package/vendor/zodex/dist/esm/infer.js +1 -0
  190. package/vendor/zodex/dist/esm/package.json +1 -0
  191. package/vendor/zodex/dist/esm/types.d.ts +201 -0
  192. package/vendor/zodex/dist/esm/types.js +13 -0
  193. package/vendor/zodex/dist/esm/ui.d.ts +23 -0
  194. package/vendor/zodex/dist/esm/ui.js +10 -0
  195. package/vendor/zodex/dist/esm/zerialize.d.ts +50 -0
  196. package/vendor/zodex/dist/esm/zerialize.js +417 -0
  197. package/vendor/zodex/dist/esm/zod-types.d.ts +11 -0
  198. package/vendor/zodex/dist/esm/zod-types.js +1 -0
  199. package/.eslintignore +0 -13
  200. package/.eslintrc.cjs +0 -145
  201. package/.nyc_output/out.json +0 -117370
  202. package/cypress.config.ts +0 -15
  203. package/demo/index-instrumented.html +0 -29
  204. package/demo/index-instrumented.js +0 -644
  205. package/demo/index.html +0 -29
  206. package/demo/index.js +0 -215
  207. package/src/formats/schemaAndArbitrary.js +0 -20
  208. package/src/formats/schemaOnly.js +0 -539
@@ -10,6 +10,9 @@ const domrectType = {
10
10
  option: ['DOMRect'],
11
11
  childTypes: ['domrectreadonly'],
12
12
  stringRegex: /^(?<domRectClass>DOMRect|DOMRectReadOnly)\((?<innerContent>.*)\)$/u,
13
+ valueMatch (x) {
14
+ return ['DOMRect', 'DOMRectReadOnly'].includes(toStringTag(x));
15
+ },
13
16
  toValue (s, rootInfo) {
14
17
  const {groups: {
15
18
  domRectClass
@@ -24,7 +27,7 @@ const domrectType = {
24
27
  )(x, y, width, height)};
25
28
  },
26
29
  getInput ({root}) {
27
- return /** @type {HTMLInputElement} */ ($e(root, 'input:not([type])'));
30
+ return /** @type {HTMLInputElement} */ ($e(root, 'input'));
28
31
  },
29
32
  setValue ({root, value}) {
30
33
  /** @type {HTMLInputElement} */ (
@@ -69,10 +72,22 @@ const domrectType = {
69
72
  ).checked;
70
73
  return new (isReadWrite ? DOMRect : DOMRectReadOnly)(x, y, width, height);
71
74
  },
72
- viewUI ({value}) {
75
+ viewUI ({value, specificSchemaObject}) {
73
76
  const isReadWrite = toStringTag(value) === 'DOMRect';
74
- return ['div', {dataset: {type: 'domrect'}}, [
75
- ['b', {class: 'emphasis'}, [isReadWrite ? 'DOMRect' : 'DOMRectReadOnly']],
77
+ return ['div', {
78
+ dataset: {
79
+ type: 'domrect'
80
+ },
81
+ title: specificSchemaObject?.description
82
+ ? `(a \`${(isReadWrite ? 'DOMRect' : 'DOMRectReadOnly')}\`)`
83
+ : undefined
84
+ }, [
85
+ ['b', {
86
+ class: 'emphasis'
87
+ }, [
88
+ specificSchemaObject?.description ??
89
+ (isReadWrite ? 'DOMRect' : 'DOMRectReadOnly')
90
+ ]],
76
91
  ['br'],
77
92
  ['b', ['x ']],
78
93
  value.x,
@@ -87,15 +102,18 @@ const domrectType = {
87
102
  value.height
88
103
  ]];
89
104
  },
90
- editUI ({typeNamespace, value = {
105
+ editUI ({typeNamespace, specificSchemaObject, value = {
91
106
  x: '',
92
107
  y: '',
93
108
  width: '',
94
109
  height: ''
95
110
  }}) {
96
111
  idx++;
97
- // eslint-disable-next-line @stylistic/max-len -- Long
98
- return ['div', {dataset: {type: 'domrect'}}, /** @type {import('jamilih').JamilihChildren} */ ([
112
+ const step = 'any'; // Proper step?
113
+ return ['div', {
114
+ dataset: {type: 'domrect'},
115
+ title: specificSchemaObject?.description ?? 'DOMRect'
116
+ }, /** @type {import('jamilih').JamilihChildren} */ ([
99
117
  ['div', [
100
118
  ['label', [
101
119
  ['input', {
@@ -122,6 +140,8 @@ const domrectType = {
122
140
  ['label', [
123
141
  'x: ',
124
142
  ['input', {
143
+ type: 'number',
144
+ step,
125
145
  class: 'x',
126
146
  name: `${typeNamespace}-domrect-x`, value: value.x
127
147
  }]
@@ -130,6 +150,8 @@ const domrectType = {
130
150
  ['label', [
131
151
  'y: ',
132
152
  ['input', {
153
+ type: 'number',
154
+ step,
133
155
  class: 'y',
134
156
  name: `${typeNamespace}-domrect-y`, value: value.y
135
157
  }]
@@ -138,6 +160,8 @@ const domrectType = {
138
160
  ['label', [
139
161
  'width: ',
140
162
  ['input', {
163
+ type: 'number',
164
+ step,
141
165
  class: 'width',
142
166
  name: `${typeNamespace}-domrect-width`, value: value.width
143
167
  }]
@@ -146,6 +170,8 @@ const domrectType = {
146
170
  ['label', [
147
171
  'height: ',
148
172
  ['input', {
173
+ type: 'number',
174
+ step,
149
175
  class: 'height',
150
176
  name: `${typeNamespace}-domrect-height`, value: value.height
151
177
  }]
@@ -1,7 +1,7 @@
1
- /* globals InternalError */
1
+ /* globals InternalError -- Non-standard */
2
2
  import {errors as errorsTypesonRegistry} from 'typeson-registry';
3
3
  import {$e} from '../utils/templateUtils.js';
4
- import {jml} from '../vendor-imports.js';
4
+ import {jml, hasConstructorOf} from '../vendor-imports.js';
5
5
  import arrayType from '../fundamentalTypes/arrayType.js';
6
6
 
7
7
  /**
@@ -48,12 +48,19 @@ const specialErrors = [...specialErrorsMap.keys()];
48
48
  */
49
49
  const errorsSpecialType = {
50
50
  option: ['Special errors'],
51
+ valueMatch (x) {
52
+ return [
53
+ TypeError, RangeError, SyntaxError, ReferenceError,
54
+ EvalError, URIError,
55
+ AggregateError
56
+ ].some((Ctor) => hasConstructorOf(x, Ctor));
57
+ },
51
58
  childTypes: specialErrors.map((err) => {
52
59
  return err.toLowerCase();
53
60
  }),
54
61
  stringRegex: new RegExp(
55
62
  '^(?<errorClass>' + specialErrors.join('|') +
56
- ')\\((?<innerContent>.*)\\)$', 'u'
63
+ String.raw`)\((?<innerContent>.*)\)$`, 'u'
57
64
  ),
58
65
  toValue (s, rootInfo) {
59
66
  const {groups: {
@@ -288,14 +295,20 @@ const errorsSpecialType = {
288
295
  return errObj;
289
296
  },
290
297
  viewUI (
291
- {value: o, types, format, typeNamespace, resultType}
298
+ {value: o, types, format, specificSchemaObject, typeNamespace, resultType}
292
299
  ) {
293
300
  const constructor = getConstructor(o.constructor);
294
301
  return /** @type {import('jamilih').JamilihArray} */ ([
295
- 'div', {dataset: {type: 'errors'}}, [
296
- ['div', [['b', ['Error type: ']], ['span', [
297
- constructor
298
- ]]]],
302
+ 'div', {
303
+ dataset: {type: 'errors'},
304
+ title: specificSchemaObject?.description
305
+ ? `(an Error ${constructor})`
306
+ : undefined
307
+ }, [
308
+ specificSchemaObject?.description ??
309
+ ['div', [['b', ['Error type: ']], ['span', [
310
+ constructor
311
+ ]]]],
299
312
  typeof o.message === 'string'
300
313
  ? ['div', [['b', ['Message: ']], ['span', [o.message]]]]
301
314
  : [],
@@ -378,7 +391,6 @@ const errorsSpecialType = {
378
391
  : 'errors',
379
392
  value: error,
380
393
  bringIntoFocus: false
381
- // schemaContent, schemaState
382
394
  });
383
395
  });
384
396
  return div;
@@ -394,6 +406,7 @@ const errorsSpecialType = {
394
406
  },
395
407
  editUI ({
396
408
  typeNamespace,
409
+ specificSchemaObject,
397
410
  types,
398
411
 
399
412
  // Pass these to `errors` array
@@ -447,9 +460,12 @@ const errorsSpecialType = {
447
460
  });
448
461
  }
449
462
 
450
- const div = /** @type {HTMLDivElement} */ (jml(
463
+ const div = jml(
451
464
  'div',
452
- {dataset: {type: 'errors'}},
465
+ {
466
+ dataset: {type: 'errors'},
467
+ title: specificSchemaObject?.description ?? 'Special error'
468
+ },
453
469
  /** @type {import('jamilih').JamilihChildren} */ ([
454
470
  ['div', [
455
471
  ['label', [
@@ -622,6 +638,7 @@ const errorsSpecialType = {
622
638
  const causeContents = $e(causeHolder, '.causeContents');
623
639
  if (!causeContents?.children.length) {
624
640
  const editui = component.editUI({
641
+ buildTypeChoices,
625
642
  typeNamespace,
626
643
  types,
627
644
  value: value.cause
@@ -693,7 +710,7 @@ const errorsSpecialType = {
693
710
  typeNamespace, types, buildTypeChoices, format,
694
711
  type: 'array',
695
712
  topRoot, bringIntoFocus,
696
- arrayState: 'errorsArray',
713
+ forcedState: 'errorsArray',
697
714
  value: []
698
715
  });
699
716
 
@@ -713,7 +730,6 @@ const errorsSpecialType = {
713
730
  value: error,
714
731
  bringIntoFocus: false,
715
732
  setAValue: true
716
- // schemaContent, schemaState
717
733
  });
718
734
  });
719
735
 
@@ -766,7 +782,7 @@ const errorsSpecialType = {
766
782
  ['div', {class: 'aggregateErrorsContents'}]
767
783
  ]]
768
784
  ])
769
- ));
785
+ );
770
786
 
771
787
  return [div];
772
788
  }
@@ -11,18 +11,25 @@ import dialogs from './utils/dialogs.js';
11
11
  * @typedef {(cfg: {
12
12
  * type: string,
13
13
  * baseValue?: import('./formats.js').StructuredCloneValue,
14
- * bringIntoFocus?: boolean
14
+ * bringIntoFocus?: boolean,
15
+ * avoidReport?: boolean
15
16
  * }) => void} SetType
16
17
  */
17
18
 
18
19
  /**
19
- * @typedef {(info: {type: string, editUI: Element}) => void} AddTypeAndEditUI
20
+ * @typedef {(info: {
21
+ * type: string,
22
+ * editUI: Element,
23
+ * specificSchema?: import('zodex').SzType
24
+ * }) => void} AddTypeAndEditUI
20
25
  */
21
26
 
22
27
  /**
23
28
  * @typedef {(info?: {
24
29
  * baseValue?: import('./formats.js').StructuredCloneValue,
25
- * bringIntoFocus?: boolean
30
+ * bringIntoFocus?: boolean,
31
+ * schemaObject?: import('./formatAndTypeChoices.js').ZodexSchema,
32
+ * avoidReport?: boolean
26
33
  * }) => void} AddAndValidateEditUI
27
34
  */
28
35
 
@@ -65,12 +72,13 @@ import dialogs from './utils/dialogs.js';
65
72
  /**
66
73
  * @callback BuildTypeChoices
67
74
  * @param {{
75
+ * autoTrigger?: boolean,
68
76
  * format: import('./formats.js').AvailableFormat,
69
77
  * typeNamespace?: string,
70
78
  * value?: import('./formats.js').StructuredCloneValue,
71
79
  * setValue?: boolean,
72
80
  * state?: string,
73
- * arrayState?: string,
81
+ * forcedState?: string,
74
82
  * keySelectClass?: string,
75
83
  * requireObject?: boolean,
76
84
  * objectHasValue?: boolean,
@@ -78,7 +86,9 @@ import dialogs from './utils/dialogs.js';
78
86
  * formats?: import('./formats.js').default
79
87
  * types?: import('./types.js').default
80
88
  * schema?: string,
81
- * schemaContent?: object,
89
+ * schemaIdx?: number,
90
+ * schemaOriginal?: import('./formatAndTypeChoices.js').ZodexSchema,
91
+ * schemaContent?: import('./formatAndTypeChoices.js').ZodexSchema,
82
92
  * }} cfg
83
93
  * @returns {{
84
94
  * domArray: [select: HTMLElement, typeContainer: HTMLElement],
@@ -93,6 +103,7 @@ import dialogs from './utils/dialogs.js';
93
103
  * @type {BuildTypeChoices}
94
104
  */
95
105
  export const buildTypeChoices = ({
106
+ autoTrigger = true,
96
107
  format,
97
108
  typeNamespace,
98
109
  value,
@@ -106,12 +117,20 @@ export const buildTypeChoices = ({
106
117
  formats = new Formats(),
107
118
  types = new Types(),
108
119
  schema,
120
+ schemaIdx,
121
+ schemaOriginal,
109
122
  schemaContent
110
123
  }) => {
111
124
  // console.log('format', format, 'state', state, 'path', typeNamespace);
112
- const typeOptions = requireObject
113
- ? [types.getOptionForType('object')]
114
- : types.getTypeOptionsForFormatAndState(format, state);
125
+ const typeAndSchemaInfo = requireObject
126
+ ? {
127
+ typeOptions: [types.getOptionForType('object')], schemaObjects: undefined
128
+ }
129
+ : types.getTypeOptionsForFormatAndState(
130
+ format, state, schemaContent, schemaOriginal
131
+ );
132
+ const {typeOptions} = typeAndSchemaInfo;
133
+ const schemaObjs = typeAndSchemaInfo.schemaObjects;
115
134
 
116
135
  let editUI;
117
136
 
@@ -133,7 +152,7 @@ export const buildTypeChoices = ({
133
152
  );
134
153
  };
135
154
  const sel = /** @type {HTMLSelectElement} */ (jml('select', {
136
- hidden: requireObject,
155
+ hidden: requireObject || typeOptions.length === 1,
137
156
  class: `typeChoices-${typeNamespace}${keySelectClass
138
157
  ? ' ' + keySelectClass
139
158
  : ''
@@ -142,16 +161,24 @@ export const buildTypeChoices = ({
142
161
  $custom: {
143
162
  $getValue,
144
163
  /** @type {SetType} */
145
- $setType ({type, baseValue, bringIntoFocus}) {
164
+ $setType ({type, baseValue, bringIntoFocus, avoidReport}) {
146
165
  this.value = type;
147
166
  this.$setStyles();
148
- this.$addAndValidateEditUI({baseValue, bringIntoFocus});
167
+ this.$addAndValidateEditUI({baseValue, bringIntoFocus, avoidReport});
149
168
  },
150
169
  /**
151
- * @type {(info: {type: string}) => void} cfg
170
+ * @type {(info: {
171
+ * type: string,
172
+ * specificSchema?: import('zodex').SzType
173
+ * }) => void} cfg
152
174
  */
153
- $setTypeNoEditUI ({type}) {
154
- this.value = type;
175
+ $setTypeNoEditUI ({type, specificSchema}) {
176
+ if (schemaObjs && specificSchema) {
177
+ const idx = schemaObjs.indexOf(specificSchema);
178
+ this.selectedIndex = idx + 1;
179
+ } else {
180
+ this.value = type;
181
+ }
155
182
  this.$setStyles();
156
183
  },
157
184
 
@@ -159,11 +186,15 @@ export const buildTypeChoices = ({
159
186
  $setStyles () {
160
187
  const {value: type} = this;
161
188
  this.dataset.type = type; // Used for styling
162
- const parEl = this.parentElement;
163
- if (parEl.nodeName.toLowerCase() === 'fieldset') {
164
- parEl.dataset.type = type;
165
- DOM.filterChildElements(parEl, 'legend').forEach((legend) => {
166
- /** @type {HTMLElement} */ (legend).dataset.type = type;
189
+ let ancestorEl = this.parentElement;
190
+ if (ancestorEl.nodeName.toLowerCase() !== 'fieldset') {
191
+ // Grandparent check added for optional items placeholder
192
+ ancestorEl = this.parentElement.parentElement;
193
+ }
194
+ if (ancestorEl.nodeName.toLowerCase() === 'fieldset') {
195
+ ancestorEl.dataset.type = type;
196
+ DOM.filterChildElements(ancestorEl, 'legend').forEach((legend) => {
197
+ legend.dataset.type = type;
167
198
  });
168
199
  }
169
200
  },
@@ -177,7 +208,9 @@ export const buildTypeChoices = ({
177
208
  },
178
209
 
179
210
  /** @type {AddAndValidateEditUI} */
180
- $addAndValidateEditUI ({baseValue, bringIntoFocus} = {}) {
211
+ $addAndValidateEditUI ({
212
+ baseValue, bringIntoFocus, schemaObject, avoidReport
213
+ } = {}) {
181
214
  const {value: type} = this;
182
215
 
183
216
  if (!type) {
@@ -198,18 +231,34 @@ export const buildTypeChoices = ({
198
231
  value: baseValue,
199
232
  buildTypeChoices,
200
233
  format,
201
- topRoot
234
+ topRoot,
235
+ schemaContent: schemaOriginal ??
236
+ (schemaContent?.type === 'union' && schemaIdx !== undefined
237
+ ? schemaContent.options[schemaIdx]
238
+ : schemaContent),
239
+ // Added `schemaContent` as inner arrays were not getting their
240
+ // schema info; this apparently allows (actually requires)
241
+ // commenting out the auto-adding of object content at end of
242
+ // editUI in arrayType.js; we add `schemaFallingBack` to
243
+ // distinguish
244
+ specificSchemaObject: schemaObject ??
245
+ (schemaContent?.type === 'union' && schemaIdx !== undefined
246
+ ? schemaContent.options[schemaIdx]
247
+ : schemaContent),
248
+ schemaFallingBack: Boolean(!schemaObject && schemaContent)
202
249
  });
203
250
  this.$addEditUI({editUI});
204
- this.$validate();
251
+ this.$validate({
252
+ avoidReport
253
+ });
205
254
  topRoot = this.$getTopRoot(); // May be existing now
206
255
  // Needed; Array/object ref somewhere could now be valid or invalid
207
256
  types.validateAllReferences({topRoot});
208
257
  },
209
258
 
210
259
  /** @type {AddTypeAndEditUI} */
211
- $addTypeAndEditUI ({type, editUI}) {
212
- this.$setTypeNoEditUI({type});
260
+ $addTypeAndEditUI ({type, editUI, specificSchema}) {
261
+ this.$setTypeNoEditUI({type, specificSchema});
213
262
  this.$addEditUI({editUI});
214
263
  },
215
264
  /**
@@ -227,9 +276,10 @@ export const buildTypeChoices = ({
227
276
  return topRoot || this.$getTypeRoot();
228
277
  },
229
278
  /**
279
+ * @param {{avoidReport?: boolean}} cfg
230
280
  * @returns {boolean}
231
281
  */
232
- $validate () {
282
+ $validate ({avoidReport} = {}) {
233
283
  const {value: type} = this;
234
284
  const container = this.$getContainer();
235
285
  if (!container.firstElementChild) {
@@ -237,7 +287,8 @@ export const buildTypeChoices = ({
237
287
  }
238
288
  const editUI = container.firstElementChild;
239
289
  return types.validate({
240
- type, root: editUI, topRoot: this.$getTopRoot()
290
+ type, root: editUI, topRoot: this.$getTopRoot(),
291
+ avoidReport
241
292
  });
242
293
  }
243
294
  },
@@ -245,26 +296,41 @@ export const buildTypeChoices = ({
245
296
  // We don't want form `onchange` to run `$checkForKeyDuplicates`
246
297
  // again (through `addAndValidateEditUI`->`validateAllReferences`)
247
298
  e?.stopPropagation();
248
- /** @type {TypeChoicesElementAPI} */ (this).$addAndValidateEditUI();
299
+ /** @type {TypeChoicesElementAPI} */ (this).$addAndValidateEditUI({
300
+ schemaObject: schemaObjs
301
+ ? schemaObjs[Number(
302
+ /** @type {HTMLSelectElement} */
303
+ (e.target).selectedOptions[0].dataset.idx
304
+ )]
305
+ : undefined
306
+ });
249
307
  /** @type {TypeChoicesElementAPI} */ (this).$setStyles();
250
308
  }}
251
309
  }, [
252
310
  ['option', {value: ''}, [
253
311
  '(Choose a type)'
254
312
  ]],
255
- // [string, {value: AvailableType; title?: string | undefined;}]
256
- // @ts-ignore Apparent TS bug
313
+
314
+ // @ts-expect-error Apparent TS bug
257
315
  ...typeOptions.map(
258
- ([optText, optAtts]) => [
259
- 'option',
260
- optAtts ||
261
- /* istanbul ignore next -- Should always have atts */
262
- {},
263
- [optText]
264
- ]
316
+ ([optText, optAtts], idx) => {
317
+ return [
318
+ 'option',
319
+ {
320
+ ...optAtts,
321
+ dataset: schemaObjs ? {idx} : {}
322
+ },
323
+ [optText]
324
+ ];
325
+ }
265
326
  )
266
327
  ]));
267
- if (setValue || (requireObject && !objectHasValue)) {
328
+ if (autoTrigger && typeOptions.length === 1 && !setValue) {
329
+ setTimeout(() => {
330
+ sel.selectedIndex = 1;
331
+ sel.dispatchEvent(new Event('change'));
332
+ });
333
+ } else if (setValue || (requireObject && !objectHasValue)) {
268
334
  setTimeout(async () => {
269
335
  if (!setValue) { // if (requireObject && !objectHasValue) {
270
336
  // Todo (low): We could auto-populate keypath if has
@@ -273,7 +339,10 @@ export const buildTypeChoices = ({
273
339
  value = {};
274
340
  }
275
341
  try {
276
- const rootEditUI = await formats.getControlsForFormatAndValue(
342
+ const {
343
+ rootUI: rootEditUI,
344
+ specificSchemas
345
+ } = await formats.getControlsForFormatAndValue(
277
346
  types,
278
347
  format,
279
348
  value,
@@ -293,7 +362,11 @@ export const buildTypeChoices = ({
293
362
  // eslint-disable-next-line @stylistic/max-len -- Long
294
363
  /** @type {HTMLSelectElement & {$addTypeAndEditUI: AddTypeAndEditUI}} */ (
295
364
  sel
296
- ).$addTypeAndEditUI({type, editUI: rootEditUI});
365
+ ).$addTypeAndEditUI({
366
+ type, editUI: rootEditUI,
367
+ // We do actually want the first one
368
+ specificSchema: specificSchemas?.[0]
369
+ });
297
370
  } catch (err) {
298
371
  /* istanbul ignore next -- At least some errors handled earlier */
299
372
  dialogs.alert({
@@ -306,9 +379,7 @@ export const buildTypeChoices = ({
306
379
  });
307
380
  }
308
381
 
309
- const typeContainer = /** @type {HTMLDivElement} */ (
310
- jml('div', {class: 'typeContainer'})
311
- );
382
+ const typeContainer = jml('div', {class: 'typeContainer'});
312
383
 
313
384
  return {
314
385
  domArray: [
@@ -339,10 +410,10 @@ export const buildTypeChoices = ({
339
410
  /** @type {SetValue} */
340
411
  async setValue (value, stateObj) {
341
412
  const rootEditUI = /** @type {HTMLDivElement} */ (
342
- await formats.getControlsForFormatAndValue(
413
+ (await formats.getControlsForFormatAndValue(
343
414
  types,
344
415
  format, value, stateObj
345
- )
416
+ )).rootUI
346
417
  );
347
418
  const type = Types.getTypeForRoot(rootEditUI);
348
419
  /** @type {HTMLSelectElement & {$addTypeAndEditUI: AddTypeAndEditUI}} */ (