@es-joy/jsoe 0.26.1 → 0.28.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 (158) hide show
  1. package/.gitignore +10 -0
  2. package/.npmignore +9 -0
  3. package/CHANGES.md +76 -0
  4. package/README.md +6 -4
  5. package/badges/coverage-badge.svg +1 -1
  6. package/badges/tests-badge.svg +1 -0
  7. package/dist/formats/schema.d.ts +11 -0
  8. package/dist/formats/schema.d.ts.map +1 -1
  9. package/dist/formats/structuredCloning.d.ts.map +1 -1
  10. package/dist/fundamentalTypes/arrayType.d.ts.map +1 -1
  11. package/dist/fundamentalTypes/stringType.d.ts.map +1 -1
  12. package/dist/index.js +2 -2
  13. package/dist/index.js.map +1 -1
  14. package/dist/typeChoices.d.ts +32 -2
  15. package/dist/typeChoices.d.ts.map +1 -1
  16. package/dist/types.d.ts +8 -2
  17. package/dist/types.d.ts.map +1 -1
  18. package/dist/utils/rawTypesonEditor.d.ts +110 -0
  19. package/dist/utils/rawTypesonEditor.d.ts.map +1 -0
  20. package/dist/vendor-imports.d.ts +4 -0
  21. package/docs/proposals/raw-typeson-edit-view.md +575 -0
  22. package/eslint.config.js +36 -27
  23. package/mmr.json +6 -0
  24. package/package.json +22 -12
  25. package/pnpm-workspace.yaml +4 -2
  26. package/src/formats/schema.js +38 -7
  27. package/src/formats/structuredCloning.js +24 -17
  28. package/src/fundamentalTypes/arrayType.js +135 -7
  29. package/src/fundamentalTypes/stringType.js +5 -0
  30. package/src/jsoe.css +12 -0
  31. package/src/typeChoices.js +39 -8
  32. package/src/types.js +20 -2
  33. package/src/utils/rawTypesonEditor.js +669 -0
  34. package/src/vendor-imports.js +12 -0
  35. package/tsconfig.json +1 -1
  36. package/typings/json-6.d.ts +12 -0
  37. package/vendor/@codemirror/autocomplete/dist/index.js +2125 -0
  38. package/vendor/@codemirror/commands/dist/index.js +1826 -0
  39. package/vendor/@codemirror/lang-javascript/dist/index.js +513 -0
  40. package/vendor/@codemirror/language/dist/index.js +2693 -0
  41. package/vendor/@codemirror/lint/dist/index.js +956 -0
  42. package/vendor/@codemirror/search/dist/index.js +1238 -0
  43. package/vendor/@codemirror/state/dist/index.js +3947 -0
  44. package/vendor/@codemirror/view/dist/index.js +11867 -0
  45. package/vendor/@lezer/common/dist/index.js +2202 -0
  46. package/vendor/@lezer/highlight/dist/index.js +927 -0
  47. package/vendor/@lezer/javascript/dist/index.js +192 -0
  48. package/vendor/@lezer/lr/dist/index.js +1889 -0
  49. package/vendor/@marijn/find-cluster-break/src/index.js +87 -0
  50. package/vendor/codemirror/dist/index.js +96 -0
  51. package/vendor/crelt/index.js +28 -0
  52. package/vendor/json-6/dist/index.mjs +1783 -0
  53. package/vendor/style-mod/src/style-mod.js +172 -0
  54. package/vendor/typeson-registry/dist/index.js +83 -10
  55. package/vendor/w3c-keyname/index.js +119 -0
  56. package/vendor/zod/classic/checks.d.ts +1 -1
  57. package/vendor/zod/classic/checks.js +1 -1
  58. package/vendor/zod/classic/external.d.ts +1 -1
  59. package/vendor/zod/classic/external.js +1 -1
  60. package/vendor/zod/classic/from-json-schema.js +245 -24
  61. package/vendor/zod/classic/schemas.d.ts +17 -1
  62. package/vendor/zod/classic/schemas.js +77 -29
  63. package/vendor/zod/core/api.d.ts +6 -4
  64. package/vendor/zod/core/api.js +17 -2
  65. package/vendor/zod/core/checks.d.ts +1 -1
  66. package/vendor/zod/core/checks.js +0 -96
  67. package/vendor/zod/core/compile.d.ts +18 -4
  68. package/vendor/zod/core/compile.js +146 -67
  69. package/vendor/zod/core/doc.js +7 -2
  70. package/vendor/zod/core/errors.js +2 -5
  71. package/vendor/zod/core/json-schema-generator.js +2 -2
  72. package/vendor/zod/core/json-schema-processors.d.ts +17 -0
  73. package/vendor/zod/core/json-schema-processors.js +195 -64
  74. package/vendor/zod/core/memoizer.js +72 -23
  75. package/vendor/zod/core/parse.js +37 -16
  76. package/vendor/zod/core/regexes.d.ts +2 -0
  77. package/vendor/zod/core/regexes.js +8 -4
  78. package/vendor/zod/core/schemas.d.ts +42 -7
  79. package/vendor/zod/core/schemas.js +301 -94
  80. package/vendor/zod/core/to-json-schema.d.ts +7 -3
  81. package/vendor/zod/core/to-json-schema.js +8 -7
  82. package/vendor/zod/core/util.d.ts +25 -4
  83. package/vendor/zod/core/util.js +160 -143
  84. package/vendor/zod/core/versions.d.ts +1 -1
  85. package/vendor/zod/core/versions.js +2 -2
  86. package/vendor/zod/core/visit.js +12 -0
  87. package/vendor/zod/locales/ar.js +1 -0
  88. package/vendor/zod/locales/az.js +1 -0
  89. package/vendor/zod/locales/be.js +1 -0
  90. package/vendor/zod/locales/bg.js +1 -0
  91. package/vendor/zod/locales/bn.js +1 -0
  92. package/vendor/zod/locales/ca.js +1 -0
  93. package/vendor/zod/locales/ckb.js +1 -0
  94. package/vendor/zod/locales/cs.js +1 -0
  95. package/vendor/zod/locales/da.js +1 -0
  96. package/vendor/zod/locales/de.js +1 -0
  97. package/vendor/zod/locales/el.js +1 -0
  98. package/vendor/zod/locales/en.js +1 -0
  99. package/vendor/zod/locales/eo.js +1 -0
  100. package/vendor/zod/locales/es.js +1 -0
  101. package/vendor/zod/locales/fa.js +1 -0
  102. package/vendor/zod/locales/fi.js +1 -0
  103. package/vendor/zod/locales/fr-CA.js +1 -0
  104. package/vendor/zod/locales/fr.js +1 -0
  105. package/vendor/zod/locales/gu.js +1 -0
  106. package/vendor/zod/locales/he.js +1 -0
  107. package/vendor/zod/locales/hi.js +1 -0
  108. package/vendor/zod/locales/hr.js +1 -0
  109. package/vendor/zod/locales/hu.js +1 -0
  110. package/vendor/zod/locales/hy.js +1 -0
  111. package/vendor/zod/locales/id.js +1 -0
  112. package/vendor/zod/locales/index.d.ts +1 -0
  113. package/vendor/zod/locales/index.js +1 -0
  114. package/vendor/zod/locales/is.js +1 -0
  115. package/vendor/zod/locales/it.js +1 -0
  116. package/vendor/zod/locales/ja.js +1 -0
  117. package/vendor/zod/locales/ka.js +1 -0
  118. package/vendor/zod/locales/km.js +1 -0
  119. package/vendor/zod/locales/kn.js +1 -0
  120. package/vendor/zod/locales/ko.js +1 -0
  121. package/vendor/zod/locales/lt.js +1 -0
  122. package/vendor/zod/locales/mk.js +1 -0
  123. package/vendor/zod/locales/ms.js +1 -0
  124. package/vendor/zod/locales/ne.js +1 -0
  125. package/vendor/zod/locales/nl.js +1 -0
  126. package/vendor/zod/locales/nn.js +1 -0
  127. package/vendor/zod/locales/no.js +1 -0
  128. package/vendor/zod/locales/ota.js +1 -0
  129. package/vendor/zod/locales/pl.js +1 -0
  130. package/vendor/zod/locales/ps.js +1 -0
  131. package/vendor/zod/locales/pt-BR.js +1 -0
  132. package/vendor/zod/locales/pt.js +1 -0
  133. package/vendor/zod/locales/ro.js +1 -0
  134. package/vendor/zod/locales/ru.js +1 -0
  135. package/vendor/zod/locales/sk.js +1 -0
  136. package/vendor/zod/locales/sl.js +1 -0
  137. package/vendor/zod/locales/sv.js +1 -0
  138. package/vendor/zod/locales/ta.js +1 -0
  139. package/vendor/zod/locales/tg.d.ts +4 -0
  140. package/vendor/zod/locales/tg.js +116 -0
  141. package/vendor/zod/locales/th.js +1 -0
  142. package/vendor/zod/locales/tk.js +1 -0
  143. package/vendor/zod/locales/tr.js +1 -0
  144. package/vendor/zod/locales/uk.js +1 -0
  145. package/vendor/zod/locales/ur.js +1 -0
  146. package/vendor/zod/locales/uz.js +1 -0
  147. package/vendor/zod/locales/vi.js +1 -0
  148. package/vendor/zod/locales/yo.js +1 -0
  149. package/vendor/zod/locales/zh-CN.js +1 -0
  150. package/vendor/zod/locales/zh-TW.js +1 -0
  151. package/vendor/zod/mini/checks.d.ts +1 -1
  152. package/vendor/zod/mini/checks.js +1 -1
  153. package/vendor/zod/mini/external.d.ts +1 -1
  154. package/vendor/zod/mini/external.js +1 -1
  155. package/vendor/zod/mini/schemas.d.ts +8 -0
  156. package/vendor/zod/mini/schemas.js +19 -2
  157. package/vendor/zodexy/dist/esm/index.js +34 -1
  158. package/vendor/zodexy/dist/schema.zodexy.json +18 -0
@@ -66,17 +66,44 @@ import deepEqual from 'fast-deep-equal/es6/index.js';
66
66
  */
67
67
 
68
68
  /**
69
- * @typedef {HTMLSelectElement & {
69
+ * The `$`-methods every type-choices control exposes, whether it's a real
70
+ * `<select>` (`TypeChoicesElementAPI`) or the `xor` radio group's
71
+ * `<fieldset>` standing in for one (`TypeChoicesControl` — see its comment
72
+ * for why that one is *not* typed as `HTMLSelectElement`).
73
+ * @typedef {{
70
74
  * $addAndValidateEditUI: AddAndValidateEditUI,
75
+ * $addTypeAndEditUI: AddTypeAndEditUI,
71
76
  * $setStyles: SetStyles,
72
77
  * $getTypeRoot: GetTypeRoot,
73
78
  * $getContainer: () => HTMLElement,
74
79
  * $getTopRoot: () => HTMLDivElement,
75
80
  * $addEditUI: AddEditUI,
76
81
  * $validate: Validate,
82
+ * $setType: SetType,
77
83
  * $setTypeNoEditUI: SetTypeNoEditUI,
84
+ * $getValue: GetValue,
78
85
  * $whenReady: WhenReady
79
- * }} TypeChoicesElementAPI
86
+ * }} TypeChoicesAPIMethods
87
+ */
88
+
89
+ /**
90
+ * @typedef {HTMLSelectElement & TypeChoicesAPIMethods} TypeChoicesElementAPI
91
+ */
92
+
93
+ /**
94
+ * The type-choices control surface downstream code actually relies on:
95
+ * the `$`-methods, plus the `value`/`selectedIndex`/`selectedOptions`
96
+ * surface a real `<select>` provides natively. Deliberately *not* typed as
97
+ * `HTMLSelectElement`, because `buildXorTypeChoices` below returns a real
98
+ * `<fieldset>` with that surface shimmed on via `Object.defineProperties`
99
+ * (and the `$`-methods copied by reference from the parallel `<select>`)
100
+ * rather than an actual `<select>` — asserting `HTMLSelectElement` there
101
+ * would be a false claim, not just a loose one.
102
+ * @typedef {HTMLElement & TypeChoicesAPIMethods & {
103
+ * value: string,
104
+ * selectedIndex: number,
105
+ * selectedOptions: ArrayLike<{value: string, dataset?: {idx?: string}}>
106
+ * }} TypeChoicesControl
80
107
  */
81
108
 
82
109
  /**
@@ -126,7 +153,7 @@ import deepEqual from 'fast-deep-equal/es6/index.js';
126
153
  * schemaContent?: import('./formatAndTypeChoices.js').ZodexSchema,
127
154
  * }} cfg
128
155
  * @returns {{
129
- * domArray: [select: HTMLElement, typeContainer: HTMLElement],
156
+ * domArray: [select: TypeChoicesControl, typeContainer: HTMLElement],
130
157
  * getValue: GetValue,
131
158
  * getType: GetType,
132
159
  * validValuesSet: ValidValuesSet,
@@ -166,7 +193,9 @@ function deriveXorBranchLabel (schemaObj, optText, idx) {
166
193
  return String(values[0]);
167
194
  }
168
195
  }
169
- if (schemaObj && schemaObj.type === 'object') {
196
+ if (schemaObj &&
197
+ (schemaObj.type === 'object' || schemaObj.type === 'properties')
198
+ ) {
170
199
  const {properties} = /** @type {import('zodexy').SzObject} */ (schemaObj);
171
200
  const keys = properties && typeof properties === 'object'
172
201
  ? Object.keys(properties)
@@ -198,9 +227,9 @@ function deriveXorBranchLabel (schemaObj, optText, idx) {
198
227
  * types: InstanceType<typeof import('./types.js').default>,
199
228
  * typeContainer: HTMLElement,
200
229
  * xorSchema: import('zodexy').SzUnion|undefined,
201
- * selectEl: HTMLSelectElement
230
+ * selectEl: TypeChoicesElementAPI
202
231
  * }} cfg
203
- * @returns {HTMLSelectElement}
232
+ * @returns {TypeChoicesControl}
204
233
  */
205
234
  function buildXorTypeChoices ({
206
235
  typeNamespace, keySelectClass, typeOptions, schemaObjs, types,
@@ -357,7 +386,9 @@ function buildXorTypeChoices ({
357
386
  }
358
387
  });
359
388
 
360
- return /** @type {HTMLSelectElement} */ (/** @type {unknown} */ (fieldset));
389
+ return /** @type {TypeChoicesControl} */ (
390
+ /** @type {unknown} */ (fieldset)
391
+ );
361
392
  }
362
393
 
363
394
  /**
@@ -435,7 +466,7 @@ export const buildTypeChoices = ({
435
466
  // match indicator to value changes inside it
436
467
  const typeContainer = jml('div', {class: 'typeContainer'});
437
468
 
438
- const selectEl = /** @type {HTMLSelectElement} */ (jml('select', {
469
+ const selectEl = /** @type {TypeChoicesElementAPI} */ (jml('select', {
439
470
  hidden: requireObject || typeOptions.length === 1,
440
471
  class: `typeChoices-${typeNamespace}${keySelectClass
441
472
  ? ' ' + keySelectClass
package/src/types.js CHANGED
@@ -438,17 +438,28 @@ class Types {
438
438
  /**
439
439
  * @param {{
440
440
  * useZodexyErrorMessages?: boolean,
441
- * useZodexyErrorMessagesInTypes?: boolean
441
+ * useZodexyErrorMessagesInTypes?: boolean,
442
+ * allowUnsafeEval?: boolean,
443
+ * showRawTypesonControls?: boolean
442
444
  * }} [cfg]
443
445
  */
444
446
  constructor ({
445
447
  useZodexyErrorMessages = false,
446
- useZodexyErrorMessagesInTypes = false
448
+ useZodexyErrorMessagesInTypes = false,
449
+ allowUnsafeEval = false,
450
+ showRawTypesonControls = true
447
451
  } = {}) {
448
452
  this.formats = new Formats(); // Todo: Make customizable and test
449
453
 
450
454
  this.useZodexyErrorMessages = useZodexyErrorMessages;
451
455
  this.useZodexyErrorMessagesInTypes = useZodexyErrorMessagesInTypes;
456
+ // Gates the eval-mode sub-feature of the raw Typeson edit/view buttons
457
+ // (`src/utils/rawTypesonEditor.js`); disabled by default since eval'ing
458
+ // arbitrary user-supplied text is inherently unsafe.
459
+ this.allowUnsafeEval = allowUnsafeEval;
460
+ // Master on/off switch for the raw Typeson edit/view buttons themselves;
461
+ // when `false` neither button is rendered anywhere in the tree.
462
+ this.showRawTypesonControls = showRawTypesonControls;
452
463
  /** @type {WeakMap<RootElement, import('./formats/schema.js').ZodexSchema>} */
453
464
  this.schemasForRoots = new WeakMap();
454
465
 
@@ -721,6 +732,13 @@ class Types {
721
732
  // `record`/`tuple` are not shown as their own pull-down entries; they render
722
733
  // as `Object`/`Array` (their schema, incl. child descriptions, informs the
723
734
  // layout — see `arrayType.js`).
735
+ // `z.properties()` likewise renders through the `object` type/UI; when the
736
+ // schema supplies no label of its own, name it "Properties" so it is not
737
+ // shown as an indistinguishable "Object".
738
+ if (type === 'object' && schemaContent?.type === 'properties') {
739
+ optInfo[0] = 'Properties';
740
+ }
741
+
724
742
  const schemaContentLabel = resolveSchemaMeta(schemaContent).label;
725
743
  if (schemaContentLabel) {
726
744
  optInfo[0] = `${optInfo[0]} (${schemaContentLabel})`;