@es-joy/jsoe 0.15.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.
- package/.ncurc.cjs +4 -5
- package/CHANGES.md +9 -0
- package/README.md +28 -4
- package/badges/licenses-badge.svg +1 -0
- package/dist/formatAndTypeChoices.d.ts +39 -19
- package/dist/formatAndTypeChoices.d.ts.map +1 -1
- package/dist/formats/indexedDBKey.d.ts +1 -1
- package/dist/formats/indexedDBKey.d.ts.map +1 -1
- package/dist/formats/json.d.ts +1 -1
- package/dist/formats/json.d.ts.map +1 -1
- package/dist/formats/schema.d.ts +11 -0
- package/dist/formats/schema.d.ts.map +1 -0
- package/dist/formats/structuredCloning.d.ts +11 -13
- package/dist/formats/structuredCloning.d.ts.map +1 -1
- package/dist/formats.d.ts +86 -25
- package/dist/formats.d.ts.map +1 -1
- package/dist/fundamentalTypes/BooleanObjectType.d.ts +1 -1
- package/dist/fundamentalTypes/BooleanObjectType.d.ts.map +1 -1
- package/dist/fundamentalTypes/NumberObjectType.d.ts +1 -1
- package/dist/fundamentalTypes/NumberObjectType.d.ts.map +1 -1
- package/dist/fundamentalTypes/StringObjectType.d.ts +1 -1
- package/dist/fundamentalTypes/StringObjectType.d.ts.map +1 -1
- package/dist/fundamentalTypes/arrayReferenceType.d.ts +1 -1
- package/dist/fundamentalTypes/arrayType.d.ts +3 -3
- package/dist/fundamentalTypes/arrayType.d.ts.map +1 -1
- package/dist/fundamentalTypes/bigintObjectType.d.ts +6 -0
- package/dist/fundamentalTypes/bigintObjectType.d.ts.map +1 -0
- package/dist/fundamentalTypes/bigintType.d.ts +1 -1
- package/dist/fundamentalTypes/bigintType.d.ts.map +1 -1
- package/dist/fundamentalTypes/blobType.d.ts +1 -1
- package/dist/fundamentalTypes/blobType.d.ts.map +1 -1
- package/dist/fundamentalTypes/booleanType.d.ts +8 -0
- package/dist/fundamentalTypes/booleanType.d.ts.map +1 -0
- package/dist/fundamentalTypes/catchType.d.ts +6 -0
- package/dist/fundamentalTypes/catchType.d.ts.map +1 -0
- package/dist/fundamentalTypes/dateType.d.ts +4 -4
- package/dist/fundamentalTypes/dateType.d.ts.map +1 -1
- package/dist/fundamentalTypes/domexceptionType.d.ts +1 -1
- package/dist/fundamentalTypes/domexceptionType.d.ts.map +1 -1
- package/dist/fundamentalTypes/enumType.d.ts +6 -0
- package/dist/fundamentalTypes/enumType.d.ts.map +1 -0
- package/dist/fundamentalTypes/errorType.d.ts +1 -1
- package/dist/fundamentalTypes/errorType.d.ts.map +1 -1
- package/dist/fundamentalTypes/fileType.d.ts +1 -1
- package/dist/fundamentalTypes/fileType.d.ts.map +1 -1
- package/dist/fundamentalTypes/filelistType.d.ts +1 -1
- package/dist/fundamentalTypes/filelistType.d.ts.map +1 -1
- package/dist/fundamentalTypes/functionType.d.ts +6 -0
- package/dist/fundamentalTypes/functionType.d.ts.map +1 -0
- package/dist/fundamentalTypes/literalType.d.ts +6 -0
- package/dist/fundamentalTypes/literalType.d.ts.map +1 -0
- package/dist/fundamentalTypes/mapType.d.ts +1 -1
- package/dist/fundamentalTypes/mapType.d.ts.map +1 -1
- package/dist/fundamentalTypes/nanType.d.ts +6 -0
- package/dist/fundamentalTypes/nanType.d.ts.map +1 -0
- package/dist/fundamentalTypes/nativeEnumType.d.ts +6 -0
- package/dist/fundamentalTypes/nativeEnumType.d.ts.map +1 -0
- package/dist/fundamentalTypes/neverType.d.ts +6 -0
- package/dist/fundamentalTypes/neverType.d.ts.map +1 -0
- package/dist/fundamentalTypes/noneditableType.d.ts +1 -1
- package/dist/fundamentalTypes/noneditableType.d.ts.map +1 -1
- package/dist/fundamentalTypes/nullType.d.ts +1 -1
- package/dist/fundamentalTypes/nullType.d.ts.map +1 -1
- package/dist/fundamentalTypes/numberType.d.ts +1 -1
- package/dist/fundamentalTypes/numberType.d.ts.map +1 -1
- package/dist/fundamentalTypes/objectReferenceType.d.ts +1 -1
- package/dist/fundamentalTypes/objectType.d.ts +1 -1
- package/dist/fundamentalTypes/objectType.d.ts.map +1 -1
- package/dist/fundamentalTypes/promiseType.d.ts +6 -0
- package/dist/fundamentalTypes/promiseType.d.ts.map +1 -0
- package/dist/fundamentalTypes/recordType.d.ts +6 -0
- package/dist/fundamentalTypes/recordType.d.ts.map +1 -0
- package/dist/fundamentalTypes/regexpType.d.ts +1 -1
- package/dist/fundamentalTypes/regexpType.d.ts.map +1 -1
- package/dist/fundamentalTypes/setType.d.ts +1 -1
- package/dist/fundamentalTypes/setType.d.ts.map +1 -1
- package/dist/fundamentalTypes/sparseUndefinedType.d.ts +1 -1
- package/dist/fundamentalTypes/sparseUndefinedType.d.ts.map +1 -1
- package/dist/fundamentalTypes/stringType.d.ts +1 -1
- package/dist/fundamentalTypes/stringType.d.ts.map +1 -1
- package/dist/fundamentalTypes/symbolType.d.ts +8 -0
- package/dist/fundamentalTypes/symbolType.d.ts.map +1 -0
- package/dist/fundamentalTypes/tupleType.d.ts +6 -0
- package/dist/fundamentalTypes/tupleType.d.ts.map +1 -0
- package/dist/fundamentalTypes/undefinedType.d.ts +1 -1
- package/dist/fundamentalTypes/undefinedType.d.ts.map +1 -1
- package/dist/fundamentalTypes/voidType.d.ts +6 -0
- package/dist/fundamentalTypes/voidType.d.ts.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9661 -1587
- package/dist/subTypes/blobHTMLType.d.ts.map +1 -1
- package/dist/subTypes/falseType.d.ts +1 -1
- package/dist/subTypes/trueType.d.ts +1 -1
- package/dist/superTypes/SpecialNumberType.d.ts +1 -1
- package/dist/superTypes/SpecialRealNumberType.d.ts +1 -1
- package/dist/superTypes/SpecialRealNumberType.d.ts.map +1 -1
- package/dist/superTypes/buffersourceType.d.ts +1 -1
- package/dist/superTypes/buffersourceType.d.ts.map +1 -1
- package/dist/superTypes/dommatrixType.d.ts +1 -1
- package/dist/superTypes/dommatrixType.d.ts.map +1 -1
- package/dist/superTypes/dompointType.d.ts +1 -1
- package/dist/superTypes/dompointType.d.ts.map +1 -1
- package/dist/superTypes/domrectType.d.ts +1 -1
- package/dist/superTypes/domrectType.d.ts.map +1 -1
- package/dist/superTypes/errorsSpecialType.d.ts +1 -1
- package/dist/superTypes/errorsSpecialType.d.ts.map +1 -1
- package/dist/typeChoices.d.ts +33 -16
- package/dist/typeChoices.d.ts.map +1 -1
- package/dist/types.d.ts +161 -157
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/dialogs.d.ts +3 -3
- package/dist/utils/dialogs.d.ts.map +1 -1
- package/dist/utils/jsonPointer.d.ts.map +1 -1
- package/dist/utils/media.d.ts.map +1 -1
- package/dist/utils/objects.d.ts +16 -0
- package/dist/utils/objects.d.ts.map +1 -0
- package/dist/utils/types.d.ts +1 -1
- package/dist/utils/types.d.ts.map +1 -1
- package/dist/vendor-imports.d.ts +1 -1
- package/eslint.config.js +74 -0
- package/licenseInfo.json +4 -0
- package/package.json +59 -69
- package/rollup.config.js +16 -1
- package/src/formatAndTypeChoices.js +68 -54
- package/src/formats/indexedDBKey.js +9 -4
- package/src/formats/json.js +7 -4
- package/src/formats/schema.js +772 -0
- package/src/formats/structuredCloning.js +187 -86
- package/src/formats.js +61 -26
- package/src/fundamentalTypes/BooleanObjectType.js +18 -6
- package/src/fundamentalTypes/NumberObjectType.js +18 -5
- package/src/fundamentalTypes/StringObjectType.js +20 -8
- package/src/fundamentalTypes/arrayType.js +1241 -533
- package/src/fundamentalTypes/bigintObjectType.js +64 -0
- package/src/fundamentalTypes/bigintType.js +31 -5
- package/src/fundamentalTypes/blobType.js +201 -190
- package/src/fundamentalTypes/booleanType.js +63 -0
- package/src/fundamentalTypes/catchType.js +140 -0
- package/src/fundamentalTypes/dateType.js +57 -19
- package/src/fundamentalTypes/domexceptionType.js +61 -63
- package/src/fundamentalTypes/enumType.js +52 -0
- package/src/fundamentalTypes/errorType.js +20 -7
- package/src/fundamentalTypes/fileType.js +195 -189
- package/src/fundamentalTypes/filelistType.js +4 -0
- package/src/fundamentalTypes/functionType.js +150 -0
- package/src/fundamentalTypes/literalType.js +81 -0
- package/src/fundamentalTypes/mapType.js +4 -0
- package/src/fundamentalTypes/nanType.js +41 -0
- package/src/fundamentalTypes/nativeEnumType.js +155 -0
- package/src/fundamentalTypes/neverType.js +44 -0
- package/src/fundamentalTypes/noneditableType.js +19 -5
- package/src/fundamentalTypes/nullType.js +16 -6
- package/src/fundamentalTypes/numberType.js +49 -6
- package/src/fundamentalTypes/objectType.js +10 -2
- package/src/fundamentalTypes/promiseType.js +60 -0
- package/src/fundamentalTypes/recordType.js +42 -0
- package/src/fundamentalTypes/regexpType.js +52 -34
- package/src/fundamentalTypes/setType.js +4 -0
- package/src/fundamentalTypes/sparseUndefinedType.js +3 -0
- package/src/fundamentalTypes/stringType.js +254 -6
- package/src/fundamentalTypes/symbolType.js +81 -0
- package/src/fundamentalTypes/tupleType.js +39 -0
- package/src/fundamentalTypes/undefinedType.js +14 -4
- package/src/fundamentalTypes/voidType.js +48 -0
- package/src/jsoe.css +37 -3
- package/src/subTypes/blobHTMLType.js +33 -24
- package/src/superTypes/SpecialRealNumberType.js +22 -6
- package/src/superTypes/buffersourceType.js +86 -30
- package/src/superTypes/dommatrixType.js +24 -7
- package/src/superTypes/dompointType.js +27 -7
- package/src/superTypes/domrectType.js +33 -7
- package/src/superTypes/errorsSpecialType.js +30 -14
- package/src/typeChoices.js +115 -44
- package/src/types.js +129 -45
- package/src/utils/FileList.js +3 -3
- package/src/utils/dialogs.js +6 -8
- package/src/utils/objects.js +22 -0
- package/src/vendor-imports.js +1 -1
- package/tsconfig.json +2 -2
- package/vendor/jamilih/dist/jml-es.js +23 -6
- package/vendor/typeson-registry/dist/index.js +77 -47
- package/vendor/zod/lib/index.mjs +4236 -0
- package/vendor/zodex/dist/esm/dezerialize.d.ts +26 -0
- package/vendor/zodex/dist/esm/dezerialize.js +393 -0
- package/vendor/zodex/dist/esm/index.d.ts +9 -0
- package/vendor/zodex/dist/esm/index.js +4 -0
- package/vendor/zodex/dist/esm/infer.d.ts +29 -0
- package/vendor/zodex/dist/esm/infer.js +1 -0
- package/vendor/zodex/dist/esm/package.json +1 -0
- package/vendor/zodex/dist/esm/types.d.ts +201 -0
- package/vendor/zodex/dist/esm/types.js +13 -0
- package/vendor/zodex/dist/esm/ui.d.ts +23 -0
- package/vendor/zodex/dist/esm/ui.js +10 -0
- package/vendor/zodex/dist/esm/zerialize.d.ts +50 -0
- package/vendor/zodex/dist/esm/zerialize.js +417 -0
- package/vendor/zodex/dist/esm/zod-types.d.ts +11 -0
- package/vendor/zodex/dist/esm/zod-types.js +1 -0
- package/.eslintignore +0 -13
- package/.eslintrc.cjs +0 -145
- package/.nyc_output/out.json +0 -114984
- package/cypress.config.ts +0 -15
- package/demo/index-instrumented.html +0 -29
- package/demo/index.html +0 -29
- package/demo/index.js +0 -644
- package/src/formats/schemaAndArbitrary.js +0 -20
- 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
|
|
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', {
|
|
75
|
-
|
|
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
|
-
|
|
98
|
-
return ['div', {
|
|
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
|
-
|
|
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', {
|
|
296
|
-
|
|
297
|
-
|
|
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 =
|
|
463
|
+
const div = jml(
|
|
451
464
|
'div',
|
|
452
|
-
{
|
|
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
|
-
|
|
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
|
}
|
package/src/typeChoices.js
CHANGED
|
@@ -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: {
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
113
|
-
?
|
|
114
|
-
|
|
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: {
|
|
170
|
+
* @type {(info: {
|
|
171
|
+
* type: string,
|
|
172
|
+
* specificSchema?: import('zodex').SzType
|
|
173
|
+
* }) => void} cfg
|
|
152
174
|
*/
|
|
153
|
-
$setTypeNoEditUI ({type}) {
|
|
154
|
-
|
|
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
|
-
|
|
163
|
-
if (
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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 ({
|
|
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
|
-
|
|
256
|
-
// @ts-
|
|
313
|
+
|
|
314
|
+
// @ts-expect-error Apparent TS bug
|
|
257
315
|
...typeOptions.map(
|
|
258
|
-
([optText, optAtts]) =>
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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 (
|
|
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
|
|
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({
|
|
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 =
|
|
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}} */ (
|