@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.
- package/.gitignore +10 -0
- package/.npmignore +9 -0
- package/CHANGES.md +76 -0
- package/README.md +6 -4
- package/badges/coverage-badge.svg +1 -1
- package/badges/tests-badge.svg +1 -0
- package/dist/formats/schema.d.ts +11 -0
- package/dist/formats/schema.d.ts.map +1 -1
- package/dist/formats/structuredCloning.d.ts.map +1 -1
- package/dist/fundamentalTypes/arrayType.d.ts.map +1 -1
- package/dist/fundamentalTypes/stringType.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/typeChoices.d.ts +32 -2
- package/dist/typeChoices.d.ts.map +1 -1
- package/dist/types.d.ts +8 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/rawTypesonEditor.d.ts +110 -0
- package/dist/utils/rawTypesonEditor.d.ts.map +1 -0
- package/dist/vendor-imports.d.ts +4 -0
- package/docs/proposals/raw-typeson-edit-view.md +575 -0
- package/eslint.config.js +36 -27
- package/mmr.json +6 -0
- package/package.json +22 -12
- package/pnpm-workspace.yaml +4 -2
- package/src/formats/schema.js +38 -7
- package/src/formats/structuredCloning.js +24 -17
- package/src/fundamentalTypes/arrayType.js +135 -7
- package/src/fundamentalTypes/stringType.js +5 -0
- package/src/jsoe.css +12 -0
- package/src/typeChoices.js +39 -8
- package/src/types.js +20 -2
- package/src/utils/rawTypesonEditor.js +669 -0
- package/src/vendor-imports.js +12 -0
- package/tsconfig.json +1 -1
- package/typings/json-6.d.ts +12 -0
- package/vendor/@codemirror/autocomplete/dist/index.js +2125 -0
- package/vendor/@codemirror/commands/dist/index.js +1826 -0
- package/vendor/@codemirror/lang-javascript/dist/index.js +513 -0
- package/vendor/@codemirror/language/dist/index.js +2693 -0
- package/vendor/@codemirror/lint/dist/index.js +956 -0
- package/vendor/@codemirror/search/dist/index.js +1238 -0
- package/vendor/@codemirror/state/dist/index.js +3947 -0
- package/vendor/@codemirror/view/dist/index.js +11867 -0
- package/vendor/@lezer/common/dist/index.js +2202 -0
- package/vendor/@lezer/highlight/dist/index.js +927 -0
- package/vendor/@lezer/javascript/dist/index.js +192 -0
- package/vendor/@lezer/lr/dist/index.js +1889 -0
- package/vendor/@marijn/find-cluster-break/src/index.js +87 -0
- package/vendor/codemirror/dist/index.js +96 -0
- package/vendor/crelt/index.js +28 -0
- package/vendor/json-6/dist/index.mjs +1783 -0
- package/vendor/style-mod/src/style-mod.js +172 -0
- package/vendor/typeson-registry/dist/index.js +83 -10
- package/vendor/w3c-keyname/index.js +119 -0
- package/vendor/zod/classic/checks.d.ts +1 -1
- package/vendor/zod/classic/checks.js +1 -1
- package/vendor/zod/classic/external.d.ts +1 -1
- package/vendor/zod/classic/external.js +1 -1
- package/vendor/zod/classic/from-json-schema.js +245 -24
- package/vendor/zod/classic/schemas.d.ts +17 -1
- package/vendor/zod/classic/schemas.js +77 -29
- package/vendor/zod/core/api.d.ts +6 -4
- package/vendor/zod/core/api.js +17 -2
- package/vendor/zod/core/checks.d.ts +1 -1
- package/vendor/zod/core/checks.js +0 -96
- package/vendor/zod/core/compile.d.ts +18 -4
- package/vendor/zod/core/compile.js +146 -67
- package/vendor/zod/core/doc.js +7 -2
- package/vendor/zod/core/errors.js +2 -5
- package/vendor/zod/core/json-schema-generator.js +2 -2
- package/vendor/zod/core/json-schema-processors.d.ts +17 -0
- package/vendor/zod/core/json-schema-processors.js +195 -64
- package/vendor/zod/core/memoizer.js +72 -23
- package/vendor/zod/core/parse.js +37 -16
- package/vendor/zod/core/regexes.d.ts +2 -0
- package/vendor/zod/core/regexes.js +8 -4
- package/vendor/zod/core/schemas.d.ts +42 -7
- package/vendor/zod/core/schemas.js +301 -94
- package/vendor/zod/core/to-json-schema.d.ts +7 -3
- package/vendor/zod/core/to-json-schema.js +8 -7
- package/vendor/zod/core/util.d.ts +25 -4
- package/vendor/zod/core/util.js +160 -143
- package/vendor/zod/core/versions.d.ts +1 -1
- package/vendor/zod/core/versions.js +2 -2
- package/vendor/zod/core/visit.js +12 -0
- package/vendor/zod/locales/ar.js +1 -0
- package/vendor/zod/locales/az.js +1 -0
- package/vendor/zod/locales/be.js +1 -0
- package/vendor/zod/locales/bg.js +1 -0
- package/vendor/zod/locales/bn.js +1 -0
- package/vendor/zod/locales/ca.js +1 -0
- package/vendor/zod/locales/ckb.js +1 -0
- package/vendor/zod/locales/cs.js +1 -0
- package/vendor/zod/locales/da.js +1 -0
- package/vendor/zod/locales/de.js +1 -0
- package/vendor/zod/locales/el.js +1 -0
- package/vendor/zod/locales/en.js +1 -0
- package/vendor/zod/locales/eo.js +1 -0
- package/vendor/zod/locales/es.js +1 -0
- package/vendor/zod/locales/fa.js +1 -0
- package/vendor/zod/locales/fi.js +1 -0
- package/vendor/zod/locales/fr-CA.js +1 -0
- package/vendor/zod/locales/fr.js +1 -0
- package/vendor/zod/locales/gu.js +1 -0
- package/vendor/zod/locales/he.js +1 -0
- package/vendor/zod/locales/hi.js +1 -0
- package/vendor/zod/locales/hr.js +1 -0
- package/vendor/zod/locales/hu.js +1 -0
- package/vendor/zod/locales/hy.js +1 -0
- package/vendor/zod/locales/id.js +1 -0
- package/vendor/zod/locales/index.d.ts +1 -0
- package/vendor/zod/locales/index.js +1 -0
- package/vendor/zod/locales/is.js +1 -0
- package/vendor/zod/locales/it.js +1 -0
- package/vendor/zod/locales/ja.js +1 -0
- package/vendor/zod/locales/ka.js +1 -0
- package/vendor/zod/locales/km.js +1 -0
- package/vendor/zod/locales/kn.js +1 -0
- package/vendor/zod/locales/ko.js +1 -0
- package/vendor/zod/locales/lt.js +1 -0
- package/vendor/zod/locales/mk.js +1 -0
- package/vendor/zod/locales/ms.js +1 -0
- package/vendor/zod/locales/ne.js +1 -0
- package/vendor/zod/locales/nl.js +1 -0
- package/vendor/zod/locales/nn.js +1 -0
- package/vendor/zod/locales/no.js +1 -0
- package/vendor/zod/locales/ota.js +1 -0
- package/vendor/zod/locales/pl.js +1 -0
- package/vendor/zod/locales/ps.js +1 -0
- package/vendor/zod/locales/pt-BR.js +1 -0
- package/vendor/zod/locales/pt.js +1 -0
- package/vendor/zod/locales/ro.js +1 -0
- package/vendor/zod/locales/ru.js +1 -0
- package/vendor/zod/locales/sk.js +1 -0
- package/vendor/zod/locales/sl.js +1 -0
- package/vendor/zod/locales/sv.js +1 -0
- package/vendor/zod/locales/ta.js +1 -0
- package/vendor/zod/locales/tg.d.ts +4 -0
- package/vendor/zod/locales/tg.js +116 -0
- package/vendor/zod/locales/th.js +1 -0
- package/vendor/zod/locales/tk.js +1 -0
- package/vendor/zod/locales/tr.js +1 -0
- package/vendor/zod/locales/uk.js +1 -0
- package/vendor/zod/locales/ur.js +1 -0
- package/vendor/zod/locales/uz.js +1 -0
- package/vendor/zod/locales/vi.js +1 -0
- package/vendor/zod/locales/yo.js +1 -0
- package/vendor/zod/locales/zh-CN.js +1 -0
- package/vendor/zod/locales/zh-TW.js +1 -0
- package/vendor/zod/mini/checks.d.ts +1 -1
- package/vendor/zod/mini/checks.js +1 -1
- package/vendor/zod/mini/external.d.ts +1 -1
- package/vendor/zod/mini/external.js +1 -1
- package/vendor/zod/mini/schemas.d.ts +8 -0
- package/vendor/zod/mini/schemas.js +19 -2
- package/vendor/zodexy/dist/esm/index.js +34 -1
- package/vendor/zodexy/dist/schema.zodexy.json +18 -0
package/src/typeChoices.js
CHANGED
|
@@ -66,17 +66,44 @@ import deepEqual from 'fast-deep-equal/es6/index.js';
|
|
|
66
66
|
*/
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
|
-
*
|
|
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
|
-
* }}
|
|
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:
|
|
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 &&
|
|
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:
|
|
230
|
+
* selectEl: TypeChoicesElementAPI
|
|
202
231
|
* }} cfg
|
|
203
|
-
* @returns {
|
|
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 {
|
|
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 {
|
|
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})`;
|