@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
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {$e} from '../utils/templateUtils.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @type {import('../types.js').TypeObject & {ct: number}}
|
|
5
|
+
*/
|
|
6
|
+
const booleanType = {
|
|
7
|
+
option: ['Boolean', {value: 'boolean'}],
|
|
8
|
+
stringRegex: /^(?:true|false)$/u,
|
|
9
|
+
valueMatch (x) {
|
|
10
|
+
return typeof x === 'boolean';
|
|
11
|
+
},
|
|
12
|
+
toValue: (s) => ({value: s === 'true'}),
|
|
13
|
+
getValue ({root}) {
|
|
14
|
+
return /** @type {HTMLInputElement} */ (this.getInput({root})).checked;
|
|
15
|
+
},
|
|
16
|
+
/* istanbul ignore next -- No dupe keys, array refs, or validation */
|
|
17
|
+
getInput ({root}) {
|
|
18
|
+
return /** @type {HTMLInputElement} */ ($e(root, 'input[value=true]'));
|
|
19
|
+
},
|
|
20
|
+
setValue ({root, value}) {
|
|
21
|
+
const input = value
|
|
22
|
+
? /** @type {HTMLInputElement} */ ($e(root, 'input[value=true]'))
|
|
23
|
+
: /** @type {HTMLInputElement} */ ($e(root, 'input[value=false]'));
|
|
24
|
+
input.checked = true;
|
|
25
|
+
},
|
|
26
|
+
viewUI ({value, specificSchemaObject}) {
|
|
27
|
+
return ['i', {
|
|
28
|
+
dataset: {type: 'boolean'},
|
|
29
|
+
title: specificSchemaObject?.description ?? '(a boolean)'
|
|
30
|
+
}, [value ? 'true' : 'false']];
|
|
31
|
+
},
|
|
32
|
+
ct: 0,
|
|
33
|
+
editUI ({typeNamespace, specificSchemaObject, value}) {
|
|
34
|
+
this.ct++;
|
|
35
|
+
const isLiteral = specificSchemaObject?.type === 'literal';
|
|
36
|
+
const val = isLiteral
|
|
37
|
+
? specificSchemaObject?.value
|
|
38
|
+
: (value ?? specificSchemaObject?.defaultValue);
|
|
39
|
+
return ['div', {
|
|
40
|
+
dataset: {type: 'boolean'},
|
|
41
|
+
title: specificSchemaObject?.description ?? 'Boolean'
|
|
42
|
+
}, [
|
|
43
|
+
['label', [
|
|
44
|
+
'True',
|
|
45
|
+
['input', {
|
|
46
|
+
disabled: isLiteral,
|
|
47
|
+
type: 'radio', name: `${typeNamespace}-boolean${this.ct}`,
|
|
48
|
+
value: 'true', checked: typeof val === 'boolean' ? val : true
|
|
49
|
+
}]
|
|
50
|
+
]],
|
|
51
|
+
['label', [
|
|
52
|
+
'False',
|
|
53
|
+
['input', {
|
|
54
|
+
disabled: isLiteral,
|
|
55
|
+
type: 'radio', name: `${typeNamespace}-boolean${this.ct}`,
|
|
56
|
+
value: 'false', checked: typeof val === 'boolean' ? !val : false
|
|
57
|
+
}]
|
|
58
|
+
]]
|
|
59
|
+
]];
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export default booleanType;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import {$e} from '../utils/templateUtils.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @type {import('../types.js').TypeObject}
|
|
5
|
+
*/
|
|
6
|
+
const catchType = {
|
|
7
|
+
option: ['Catch'],
|
|
8
|
+
stringRegex: /^catch\((.*)\)$/u,
|
|
9
|
+
valueMatch (x) {
|
|
10
|
+
// Todo: Should expand types here and in `toValue`
|
|
11
|
+
return ['number', 'string'].includes(typeof x);
|
|
12
|
+
},
|
|
13
|
+
toValue (s) {
|
|
14
|
+
const value = s.charAt(0) === '"' ? s.slice(1, -1) : Number(s);
|
|
15
|
+
return {value};
|
|
16
|
+
},
|
|
17
|
+
getInput ({root}) {
|
|
18
|
+
return /** @type {HTMLTextAreaElement} */ (
|
|
19
|
+
$e(root, 'input,textarea')
|
|
20
|
+
);
|
|
21
|
+
},
|
|
22
|
+
setValue ({root, value}) {
|
|
23
|
+
// input/textarea hasn't yet been added, so set timeout
|
|
24
|
+
setTimeout(() => {
|
|
25
|
+
this.getInput({root}).value = value;
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
getValue ({root}) {
|
|
29
|
+
return this.getInput({root}).value;
|
|
30
|
+
},
|
|
31
|
+
viewUI ({
|
|
32
|
+
specificSchemaObject, types,
|
|
33
|
+
resultType, typeNamespace, topRoot, format,
|
|
34
|
+
bringIntoFocus, buildTypeChoices, // schemaContent,
|
|
35
|
+
replaced, value
|
|
36
|
+
}) {
|
|
37
|
+
return ['span', {
|
|
38
|
+
dataset: {type: 'catch'},
|
|
39
|
+
title: specificSchemaObject?.description ?? '(a catch)'
|
|
40
|
+
}, [
|
|
41
|
+
['b', ['Catch']],
|
|
42
|
+
['br'],
|
|
43
|
+
'Default value',
|
|
44
|
+
['br'],
|
|
45
|
+
['div', {
|
|
46
|
+
class: 'defaultValue'
|
|
47
|
+
}, [
|
|
48
|
+
types.getUIForModeAndType({
|
|
49
|
+
readonly: true,
|
|
50
|
+
specificSchemaObject: /** @type {import('zodex').SzCatch} */ (
|
|
51
|
+
specificSchemaObject
|
|
52
|
+
)?.innerType,
|
|
53
|
+
hasValue: true,
|
|
54
|
+
value,
|
|
55
|
+
resultType, typeNamespace,
|
|
56
|
+
type: /** @type {import('../types.js').AvailableType} */ (
|
|
57
|
+
/** @type {import('zodex').SzCatch} */ (
|
|
58
|
+
specificSchemaObject
|
|
59
|
+
)?.innerType?.type
|
|
60
|
+
),
|
|
61
|
+
topRoot, bringIntoFocus,
|
|
62
|
+
buildTypeChoices, format,
|
|
63
|
+
// schemaContent,
|
|
64
|
+
replaced
|
|
65
|
+
})
|
|
66
|
+
]],
|
|
67
|
+
'Catch value',
|
|
68
|
+
['br'],
|
|
69
|
+
['div', {
|
|
70
|
+
class: 'catchValue'
|
|
71
|
+
}, [
|
|
72
|
+
types.getUIForModeAndType({
|
|
73
|
+
readonly: true,
|
|
74
|
+
specificSchemaObject: {
|
|
75
|
+
...(/** @type {import('zodex').SzCatch} */ (
|
|
76
|
+
specificSchemaObject
|
|
77
|
+
)?.innerType),
|
|
78
|
+
description: '(catch value)'
|
|
79
|
+
},
|
|
80
|
+
hasValue: true,
|
|
81
|
+
value: /** @type {import('zodex').SzCatch} */ (
|
|
82
|
+
specificSchemaObject
|
|
83
|
+
).value,
|
|
84
|
+
resultType, typeNamespace,
|
|
85
|
+
type: /** @type {import('../types.js').AvailableType} */ (
|
|
86
|
+
/** @type {import('zodex').SzCatch} */ (
|
|
87
|
+
specificSchemaObject
|
|
88
|
+
)?.innerType?.type
|
|
89
|
+
),
|
|
90
|
+
topRoot, bringIntoFocus,
|
|
91
|
+
buildTypeChoices, format,
|
|
92
|
+
// schemaContent,
|
|
93
|
+
replaced
|
|
94
|
+
})
|
|
95
|
+
]]
|
|
96
|
+
]];
|
|
97
|
+
},
|
|
98
|
+
editUI ({
|
|
99
|
+
format, type, buildTypeChoices, specificSchemaObject,
|
|
100
|
+
topRoot, schemaContent, typeNamespace, value
|
|
101
|
+
}) {
|
|
102
|
+
const schemaValue =
|
|
103
|
+
/** @type {import('zodex').SzCatch} */ (
|
|
104
|
+
specificSchemaObject
|
|
105
|
+
)?.value;
|
|
106
|
+
return ['div', {
|
|
107
|
+
dataset: {type: 'catch'},
|
|
108
|
+
title: specificSchemaObject?.description ?? '(a `catch`)'
|
|
109
|
+
}, [
|
|
110
|
+
['label', [
|
|
111
|
+
['b', {
|
|
112
|
+
title: String(schemaValue)
|
|
113
|
+
}, ['Value']],
|
|
114
|
+
' ',
|
|
115
|
+
...(/** @type {import('../typeChoices.js').BuildTypeChoices} */ (
|
|
116
|
+
buildTypeChoices
|
|
117
|
+
)({
|
|
118
|
+
// resultType,
|
|
119
|
+
// eslint-disable-next-line object-shorthand -- TS
|
|
120
|
+
topRoot: /** @type {HTMLDivElement} */ (topRoot),
|
|
121
|
+
// eslint-disable-next-line object-shorthand -- TS
|
|
122
|
+
format: /** @type {import('../formats.js').AvailableFormat} */ (
|
|
123
|
+
format
|
|
124
|
+
),
|
|
125
|
+
setValue: true,
|
|
126
|
+
value: value ?? schemaValue,
|
|
127
|
+
schemaOriginal: schemaContent,
|
|
128
|
+
schemaContent: /** @type {import('zodex').SzCatch} */ (
|
|
129
|
+
specificSchemaObject
|
|
130
|
+
)?.innerType,
|
|
131
|
+
state: type,
|
|
132
|
+
// itemIndex,
|
|
133
|
+
typeNamespace
|
|
134
|
+
}).domArray)
|
|
135
|
+
]]
|
|
136
|
+
]];
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export default catchType;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {jml} from '../vendor-imports.js';
|
|
1
|
+
import {jml, toStringTag} from '../vendor-imports.js';
|
|
2
2
|
import {$e} from '../utils/templateUtils.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @typedef {(
|
|
6
|
-
* legitimateInvalid?:
|
|
6
|
+
* legitimateInvalid?: boolean|undefined
|
|
7
7
|
* ) => void} SetValidity
|
|
8
8
|
*/
|
|
9
9
|
|
|
@@ -20,7 +20,9 @@ import {$e} from '../utils/templateUtils.js';
|
|
|
20
20
|
const dateType = {
|
|
21
21
|
option: ['Date'],
|
|
22
22
|
// ISO Date string
|
|
23
|
-
dateRegex: /^(?:\d{4}
|
|
23
|
+
dateRegex: /^(?:\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d)$/u, // ([+-][0-2]\d:[0-5]\d|Z)
|
|
24
|
+
// eslint-disable-next-line @stylistic/max-len -- Long
|
|
25
|
+
// /^(?:\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}\.\d{3}Z)?|(?:\+|-)\d{6}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)$/u,
|
|
24
26
|
stringRegex () {
|
|
25
27
|
const regex = this.dateRegex;
|
|
26
28
|
if (!this.valid) {
|
|
@@ -29,11 +31,16 @@ const dateType = {
|
|
|
29
31
|
}
|
|
30
32
|
return new RegExp(regex, 'u');
|
|
31
33
|
},
|
|
34
|
+
valueMatch (x) {
|
|
35
|
+
return toStringTag(x) === 'Date';
|
|
36
|
+
},
|
|
32
37
|
toValue (s) {
|
|
33
38
|
return {value: new Date(s)};
|
|
34
39
|
},
|
|
35
40
|
getInput ({root}) {
|
|
36
|
-
return /** @type {HTMLInputElement} */ (
|
|
41
|
+
return /** @type {HTMLInputElement} */ (
|
|
42
|
+
$e(root, 'input[type="datetime-local"]')
|
|
43
|
+
);
|
|
37
44
|
},
|
|
38
45
|
setValue ({root, value}) {
|
|
39
46
|
const notANum = value && Number.isNaN(value.getTime());
|
|
@@ -43,9 +50,10 @@ const dateType = {
|
|
|
43
50
|
).$setValidity(true);
|
|
44
51
|
return;
|
|
45
52
|
}
|
|
53
|
+
|
|
46
54
|
const dateStr = new Date(Date.parse(value)).toISOString();
|
|
47
55
|
this.getInput({root}).value = dateStr.length === 24
|
|
48
|
-
? dateStr.slice(0,
|
|
56
|
+
? dateStr.slice(0, -8)
|
|
49
57
|
// eslint-disable-next-line @stylistic/max-len -- Long
|
|
50
58
|
/* istanbul ignore next -- 6 digits year not reliable through `Date.parse` */
|
|
51
59
|
: dateStr.slice(3, 13); // Will cut off ten/hundred thousand years
|
|
@@ -63,6 +71,7 @@ const dateType = {
|
|
|
63
71
|
message: 'Must not be empty`'
|
|
64
72
|
};
|
|
65
73
|
}
|
|
74
|
+
|
|
66
75
|
return {
|
|
67
76
|
valid: new RegExp(this.dateRegex, 'u').test(val),
|
|
68
77
|
message: 'Must match a valid date'
|
|
@@ -86,22 +95,32 @@ const dateType = {
|
|
|
86
95
|
isValueInvalid (value) {
|
|
87
96
|
return value && Number.isNaN(value.getTime());
|
|
88
97
|
},
|
|
89
|
-
viewUI ({value}) {
|
|
98
|
+
viewUI ({value, specificSchemaObject}) {
|
|
90
99
|
return !this.valid && this.isValueInvalid(value)
|
|
91
100
|
? ['i', {
|
|
92
|
-
dataset: {type: 'date'}, class: 'InvalidDate'
|
|
101
|
+
dataset: {type: 'date'}, class: 'InvalidDate',
|
|
102
|
+
title: specificSchemaObject?.description ?? '(an InvalidDate)'
|
|
93
103
|
}, ['InvalidDate']]
|
|
94
|
-
: ['i', {
|
|
95
|
-
|
|
104
|
+
: ['i', {
|
|
105
|
+
dataset: {type: 'date'}, class: 'ValidDate',
|
|
106
|
+
title: specificSchemaObject?.description ?? '(a `Date`)'
|
|
107
|
+
}, [
|
|
108
|
+
value.toISOString().slice(0, -8)
|
|
96
109
|
]];
|
|
97
110
|
},
|
|
98
111
|
// Change to default to `new Date()` when can't be `NaN`
|
|
99
112
|
// value (keys)?
|
|
100
|
-
editUI ({typeNamespace, types, value
|
|
101
|
-
const
|
|
113
|
+
editUI ({typeNamespace, specificSchemaObject, types, value}) {
|
|
114
|
+
const dateSchemaObject = /** @type {import('zodex').SzDate} */ (
|
|
115
|
+
specificSchemaObject
|
|
116
|
+
);
|
|
117
|
+
const val = value ?? (specificSchemaObject?.defaultValue
|
|
118
|
+
? new Date(specificSchemaObject?.defaultValue)
|
|
119
|
+
: '');
|
|
120
|
+
const notANum = this.isValueInvalid(val);
|
|
102
121
|
const invalid = this.valid
|
|
103
122
|
? ''
|
|
104
|
-
:
|
|
123
|
+
: jml('div', [
|
|
105
124
|
['label', [
|
|
106
125
|
'Invalid date',
|
|
107
126
|
['input', {
|
|
@@ -116,7 +135,13 @@ const dateType = {
|
|
|
116
135
|
$setValidity (legitimateInvalid) {
|
|
117
136
|
// console.log('legitimateInvalid', legitimateInvalid);
|
|
118
137
|
if (legitimateInvalid === true) {
|
|
119
|
-
/**
|
|
138
|
+
/**
|
|
139
|
+
* @type {HTMLInputElement & {
|
|
140
|
+
* $setValidity: SetValidity
|
|
141
|
+
* }}
|
|
142
|
+
*/ (
|
|
143
|
+
this
|
|
144
|
+
).checked = true;
|
|
120
145
|
}
|
|
121
146
|
const label = /** @type {HTMLLabelElement} */ (
|
|
122
147
|
/** @type {HTMLDivElement} */ (
|
|
@@ -132,24 +157,37 @@ const dateType = {
|
|
|
132
157
|
},
|
|
133
158
|
$on: {
|
|
134
159
|
click (/* e */) {
|
|
135
|
-
/** @type {
|
|
160
|
+
/** @type {HTMLInputElement & {$setValidity: SetValidity}} */ (
|
|
161
|
+
this
|
|
162
|
+
).$setValidity(/** @type {HTMLInputElement} */ (
|
|
136
163
|
this
|
|
137
|
-
)
|
|
164
|
+
).checked);
|
|
138
165
|
}
|
|
139
166
|
}
|
|
140
167
|
}]
|
|
141
168
|
]]
|
|
142
|
-
])
|
|
143
|
-
return ['div', {
|
|
169
|
+
]);
|
|
170
|
+
return ['div', {
|
|
171
|
+
dataset: {type: this.valid ? 'ValidDate' : 'date'},
|
|
172
|
+
title: specificSchemaObject?.description ?? 'Date'
|
|
173
|
+
}, [
|
|
144
174
|
['label', {
|
|
145
175
|
hidden: notANum
|
|
146
176
|
}, [
|
|
147
177
|
'Date: ',
|
|
148
178
|
['input', {
|
|
149
179
|
name: `${typeNamespace}-date`,
|
|
150
|
-
type: '
|
|
180
|
+
type: 'datetime-local',
|
|
151
181
|
// Required yyyy-MM-dd format
|
|
152
|
-
value: !
|
|
182
|
+
value: !val || notANum
|
|
183
|
+
? ''
|
|
184
|
+
: val.toISOString().slice(0, -8),
|
|
185
|
+
min: dateSchemaObject?.min
|
|
186
|
+
? new Date(dateSchemaObject.min).toISOString().slice(0, -8)
|
|
187
|
+
: undefined,
|
|
188
|
+
max: dateSchemaObject?.max
|
|
189
|
+
? new Date(dateSchemaObject.max).toISOString().slice(0, -8)
|
|
190
|
+
: undefined
|
|
153
191
|
}]
|
|
154
192
|
]],
|
|
155
193
|
invalid
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
+
import {toStringTag} from '../vendor-imports.js';
|
|
1
2
|
import {$e} from '../utils/templateUtils.js';
|
|
2
3
|
|
|
4
|
+
let domExceptionNameId = 0;
|
|
5
|
+
|
|
3
6
|
/**
|
|
4
7
|
* @type {import('../types.js').TypeObject}
|
|
5
8
|
*/
|
|
6
9
|
const domexceptionType = {
|
|
7
10
|
option: ['DOMException'],
|
|
8
11
|
stringRegex: /^DOMException\((.*)\)$/u,
|
|
12
|
+
valueMatch (x) {
|
|
13
|
+
return toStringTag(x) === 'DOMException';
|
|
14
|
+
},
|
|
9
15
|
toValue (s) {
|
|
10
16
|
const {message, name} = JSON.parse(s);
|
|
11
17
|
return {value: new DOMException(message, name)};
|
|
@@ -30,8 +36,11 @@ const domexceptionType = {
|
|
|
30
36
|
).value;
|
|
31
37
|
return new DOMException(message, name);
|
|
32
38
|
},
|
|
33
|
-
viewUI ({value}) {
|
|
34
|
-
return ['div', {
|
|
39
|
+
viewUI ({value, specificSchemaObject}) {
|
|
40
|
+
return ['div', {
|
|
41
|
+
dataset: {type: 'domexception'},
|
|
42
|
+
title: specificSchemaObject?.description ?? '(a `DOMException`)'
|
|
43
|
+
}, [
|
|
35
44
|
['b', ['Message ']],
|
|
36
45
|
value.message,
|
|
37
46
|
['br'],
|
|
@@ -42,79 +51,68 @@ const domexceptionType = {
|
|
|
42
51
|
value.code
|
|
43
52
|
]];
|
|
44
53
|
},
|
|
45
|
-
editUI ({typeNamespace, value = ''}) {
|
|
46
|
-
|
|
47
|
-
return ['div', {
|
|
54
|
+
editUI ({typeNamespace, specificSchemaObject, value = ''}) {
|
|
55
|
+
domExceptionNameId++;
|
|
56
|
+
return ['div', {
|
|
57
|
+
dataset: {type: 'domexception'},
|
|
58
|
+
title: specificSchemaObject?.description ?? 'DOMException'
|
|
59
|
+
}, /** @type {import('jamilih').JamilihChildren} */ ([
|
|
48
60
|
['label', [
|
|
49
61
|
'Name: ',
|
|
50
62
|
['input', {
|
|
51
63
|
class: 'name',
|
|
52
|
-
|
|
64
|
+
list: `domExceptionNames-${domExceptionNameId}`,
|
|
65
|
+
name: `${typeNamespace}-domexception-name`,
|
|
66
|
+
value: value?.name ?? '',
|
|
67
|
+
size: 30,
|
|
68
|
+
placeholder: '(Optional predefined name)'
|
|
53
69
|
}]
|
|
54
70
|
]],
|
|
55
|
-
'
|
|
56
|
-
|
|
57
|
-
class: 'predefinedNames'
|
|
58
|
-
$on: {
|
|
59
|
-
/**
|
|
60
|
-
* @this {HTMLSelectElement}
|
|
61
|
-
*/
|
|
62
|
-
change () {
|
|
63
|
-
/** @type {HTMLInputElement} */
|
|
64
|
-
($e(
|
|
65
|
-
/** @type {HTMLLabelElement} */ (
|
|
66
|
-
this.previousElementSibling
|
|
67
|
-
),
|
|
68
|
-
'.name'
|
|
69
|
-
)).value = this.value;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
71
|
+
['datalist', {
|
|
72
|
+
id: `domExceptionNames-${domExceptionNameId}`,
|
|
73
|
+
class: 'predefinedNames'
|
|
72
74
|
}, [
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
'NotAllowedError'
|
|
108
|
-
].map((name) => {
|
|
109
|
-
return ['option', [name]];
|
|
110
|
-
})
|
|
111
|
-
]],
|
|
75
|
+
'IndexSizeError',
|
|
76
|
+
'HierarchyRequestError',
|
|
77
|
+
'WrongDocumentError',
|
|
78
|
+
'InvalidCharacterError',
|
|
79
|
+
'NoModificationAllowedError',
|
|
80
|
+
'NotFoundError',
|
|
81
|
+
'NotSupportedError',
|
|
82
|
+
'InvalidStateError',
|
|
83
|
+
'InUseAttributeError',
|
|
84
|
+
'SyntaxError',
|
|
85
|
+
'InvalidModificationError',
|
|
86
|
+
'NamespaceError',
|
|
87
|
+
'InvalidAccessError',
|
|
88
|
+
'TypeMismatchError',
|
|
89
|
+
'SecurityError',
|
|
90
|
+
'NetworkError',
|
|
91
|
+
'AbortError',
|
|
92
|
+
'URLMismatchError',
|
|
93
|
+
'QuotaExceededError',
|
|
94
|
+
'TimeoutError',
|
|
95
|
+
'InvalidNodeTypeError',
|
|
96
|
+
'DataCloneError',
|
|
97
|
+
'EncodingError',
|
|
98
|
+
'NotReadableError',
|
|
99
|
+
'UnknownError',
|
|
100
|
+
'ConstraintError',
|
|
101
|
+
'DataError',
|
|
102
|
+
'TransactionInactiveError',
|
|
103
|
+
'ReadOnlyErrorVersionError',
|
|
104
|
+
'OperationError',
|
|
105
|
+
'NotAllowedError'
|
|
106
|
+
].map((name) => {
|
|
107
|
+
return ['option', [name]];
|
|
108
|
+
})],
|
|
112
109
|
['br'],
|
|
113
110
|
['label', [
|
|
114
111
|
'Message: ',
|
|
115
112
|
['input', {
|
|
116
113
|
class: 'message',
|
|
117
|
-
name: `${typeNamespace}-domexception-message`,
|
|
114
|
+
name: `${typeNamespace}-domexception-message`,
|
|
115
|
+
value: value?.message ?? ''
|
|
118
116
|
}]
|
|
119
117
|
]]
|
|
120
118
|
])];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {$e} from '../utils/templateUtils.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @type {import('../types.js').TypeObject}
|
|
5
|
+
*/
|
|
6
|
+
const enumType = {
|
|
7
|
+
option: ['Enum'],
|
|
8
|
+
stringRegex: /^Enum\((.*)\)$/u,
|
|
9
|
+
valueMatch (x) {
|
|
10
|
+
return typeof x === 'string';
|
|
11
|
+
},
|
|
12
|
+
toValue (s) {
|
|
13
|
+
return {value: s.slice(1, -1)};
|
|
14
|
+
},
|
|
15
|
+
getInput ({root}) {
|
|
16
|
+
return /** @type {HTMLSelectElement} */ ($e(root, 'select'));
|
|
17
|
+
},
|
|
18
|
+
setValue ({root, value}) {
|
|
19
|
+
this.getInput({root}).value = value;
|
|
20
|
+
},
|
|
21
|
+
getValue ({root}) {
|
|
22
|
+
return this.getInput({root}).value;
|
|
23
|
+
},
|
|
24
|
+
viewUI ({value, specificSchemaObject}) {
|
|
25
|
+
return ['span', {
|
|
26
|
+
dataset: {type: 'enum'},
|
|
27
|
+
title: specificSchemaObject?.description ?? '(an enum)'
|
|
28
|
+
}, [
|
|
29
|
+
value
|
|
30
|
+
]];
|
|
31
|
+
},
|
|
32
|
+
editUI ({typeNamespace, specificSchemaObject, value = ''}) {
|
|
33
|
+
return ['div', {
|
|
34
|
+
dataset: {type: 'enum'},
|
|
35
|
+
title: specificSchemaObject?.description ?? 'Enum'
|
|
36
|
+
}, [
|
|
37
|
+
['select', {
|
|
38
|
+
name: `${typeNamespace}-enum`
|
|
39
|
+
}, /** @type {import('zodex').SzEnum} */ (
|
|
40
|
+
specificSchemaObject
|
|
41
|
+
)?.values.map((val) => {
|
|
42
|
+
return ['option', {
|
|
43
|
+
selected: value
|
|
44
|
+
? value === val
|
|
45
|
+
: specificSchemaObject?.defaultValue === val
|
|
46
|
+
}, [val]];
|
|
47
|
+
})]
|
|
48
|
+
]];
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default enumType;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {error as errorTypesonRegistry} from 'typeson-registry';
|
|
2
2
|
import {$e} from '../utils/templateUtils.js';
|
|
3
|
-
import {jml} from '../vendor-imports.js';
|
|
3
|
+
import {jml, toStringTag, hasConstructorOf} from '../vendor-imports.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @type {import('../types.js').TypeObject}
|
|
@@ -8,6 +8,11 @@ import {jml} from '../vendor-imports.js';
|
|
|
8
8
|
const errorType = {
|
|
9
9
|
option: ['Error'],
|
|
10
10
|
stringRegex: /^Error\((.*)\)$/u,
|
|
11
|
+
valueMatch (x) {
|
|
12
|
+
return toStringTag(x) === 'Error' &&
|
|
13
|
+
// Exclude special errors to let it be handled elsewhere
|
|
14
|
+
hasConstructorOf(x, Error);
|
|
15
|
+
},
|
|
11
16
|
toValue (s) {
|
|
12
17
|
const obj = JSON.parse(s);
|
|
13
18
|
const errObj = /** @type {{revive: import('typeson-registry').Reviver}} */ (
|
|
@@ -169,11 +174,16 @@ const errorType = {
|
|
|
169
174
|
return errObj;
|
|
170
175
|
},
|
|
171
176
|
viewUI (
|
|
172
|
-
{value: o, types, format}
|
|
177
|
+
{value: o, specificSchemaObject, types, format}
|
|
173
178
|
) {
|
|
174
179
|
return /** @type {import('jamilih').JamilihArray} */ ([
|
|
175
180
|
'div', {dataset: {type: 'error'}}, [
|
|
176
|
-
['b', {
|
|
181
|
+
['b', {
|
|
182
|
+
class: 'emphasis',
|
|
183
|
+
title: specificSchemaObject?.description ? '(an Error)' : undefined
|
|
184
|
+
}, [
|
|
185
|
+
specificSchemaObject?.description ?? 'Error'
|
|
186
|
+
]],
|
|
177
187
|
typeof o.message === 'string'
|
|
178
188
|
? ['div', [['b', ['Message: ']], ['span', [o.message]]]]
|
|
179
189
|
: [],
|
|
@@ -217,7 +227,7 @@ const errorType = {
|
|
|
217
227
|
]
|
|
218
228
|
]);
|
|
219
229
|
},
|
|
220
|
-
editUI ({typeNamespace, types, value = {
|
|
230
|
+
editUI ({typeNamespace, types, specificSchemaObject, value = {
|
|
221
231
|
message: '',
|
|
222
232
|
name: '',
|
|
223
233
|
fileName: '',
|
|
@@ -252,9 +262,12 @@ const errorType = {
|
|
|
252
262
|
});
|
|
253
263
|
}
|
|
254
264
|
|
|
255
|
-
const div =
|
|
265
|
+
const div = jml(
|
|
256
266
|
'div',
|
|
257
|
-
{
|
|
267
|
+
{
|
|
268
|
+
dataset: {type: 'error'},
|
|
269
|
+
title: specificSchemaObject?.description ?? 'Error'
|
|
270
|
+
},
|
|
258
271
|
/** @type {import('jamilih').JamilihChildren} */ ([
|
|
259
272
|
['div', [
|
|
260
273
|
['label', [
|
|
@@ -410,7 +423,7 @@ const errorType = {
|
|
|
410
423
|
['div', {class: 'causeContents'}]
|
|
411
424
|
]]
|
|
412
425
|
])
|
|
413
|
-
)
|
|
426
|
+
);
|
|
414
427
|
|
|
415
428
|
return [div];
|
|
416
429
|
}
|