@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,81 @@
|
|
|
1
|
+
import {$e} from '../utils/templateUtils.js';
|
|
2
|
+
|
|
3
|
+
import booleanType from './booleanType.js';
|
|
4
|
+
import numberType from './numberType.js';
|
|
5
|
+
import stringType from './stringType.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @type {import('../types.js').TypeObject}
|
|
9
|
+
*/
|
|
10
|
+
const literalType = {
|
|
11
|
+
option: ['Literal'],
|
|
12
|
+
stringRegex: /^Literal\((.*)\)$/u,
|
|
13
|
+
valueMatch (x) {
|
|
14
|
+
// const schema =
|
|
15
|
+
// /** @type {import('zodex').SzLiteral<any>} */ (cfg?.schema);
|
|
16
|
+
return (typeof x === 'boolean' || typeof x === 'number' ||
|
|
17
|
+
typeof x === 'string'); // && (!schema || schema.value === x);
|
|
18
|
+
},
|
|
19
|
+
toValue (s) {
|
|
20
|
+
const value = s === 'true'
|
|
21
|
+
? true
|
|
22
|
+
: s === 'false'
|
|
23
|
+
? false
|
|
24
|
+
: s.charAt(0) === '"'
|
|
25
|
+
? s.slice(1, -1)
|
|
26
|
+
: Number(s);
|
|
27
|
+
return {value};
|
|
28
|
+
},
|
|
29
|
+
// Todo: Fix all the following methods up to `setValue` to work with children
|
|
30
|
+
getInput ({root}) {
|
|
31
|
+
return /** @type {HTMLTextAreaElement} */ ($e(root, 'input,textarea'));
|
|
32
|
+
},
|
|
33
|
+
setValue ({root, value}) {
|
|
34
|
+
this.getInput({root}).value = value;
|
|
35
|
+
},
|
|
36
|
+
getValue ({root, stateObj}) {
|
|
37
|
+
const innerTypeHolder = $e(root, '[data-type]');
|
|
38
|
+
const typeObject = stateObj?.types?.getTypeObject?.(
|
|
39
|
+
/** @type {import('../types.js').AvailableType} */ (
|
|
40
|
+
innerTypeHolder?.dataset.type
|
|
41
|
+
)
|
|
42
|
+
);
|
|
43
|
+
return /** @type {import('../types.js').TypeObject} */ (
|
|
44
|
+
typeObject
|
|
45
|
+
)?.getValue({root, stateObj});
|
|
46
|
+
},
|
|
47
|
+
viewUI ({value, specificSchemaObject}) {
|
|
48
|
+
return ['span', {
|
|
49
|
+
dataset: {type: 'literal'},
|
|
50
|
+
title: specificSchemaObject?.description ?? `(a literal ${typeof value})`
|
|
51
|
+
}, [`${value}`]];
|
|
52
|
+
},
|
|
53
|
+
editUI (arg) {
|
|
54
|
+
const {specificSchemaObject} = arg;
|
|
55
|
+
const {
|
|
56
|
+
value: val
|
|
57
|
+
} = /** @type {import('zodex').SzLiteral<any>} */ (specificSchemaObject);
|
|
58
|
+
|
|
59
|
+
let specificLiteralEditUI;
|
|
60
|
+
switch (typeof val) {
|
|
61
|
+
case 'boolean':
|
|
62
|
+
// arg.specificSchemaObject = {type: 'boolean'};
|
|
63
|
+
specificLiteralEditUI = booleanType.editUI(arg);
|
|
64
|
+
break;
|
|
65
|
+
case 'number':
|
|
66
|
+
// arg.specificSchemaObject = {type: 'number'};
|
|
67
|
+
specificLiteralEditUI = numberType.editUI(arg);
|
|
68
|
+
break;
|
|
69
|
+
case 'string': default:
|
|
70
|
+
// arg.specificSchemaObject = {type: 'string'};
|
|
71
|
+
specificLiteralEditUI = stringType.editUI(arg);
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return ['div', {dataset: {type: 'literal'}}, [
|
|
76
|
+
specificLiteralEditUI
|
|
77
|
+
]];
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export default literalType;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {toStringTag} from '../vendor-imports.js';
|
|
1
2
|
import arrayType from './arrayType.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -10,6 +11,9 @@ const mapType = {
|
|
|
10
11
|
regexEndings: [',', ')'],
|
|
11
12
|
stringRegexBegin: /^Map\(/u,
|
|
12
13
|
stringRegexEnd: /^\)/u,
|
|
14
|
+
valueMatch (x) {
|
|
15
|
+
return toStringTag(x) === 'Map';
|
|
16
|
+
},
|
|
13
17
|
toValue (...args) {
|
|
14
18
|
return /** @type {import('../types.js').ToValue} */ (
|
|
15
19
|
arrayType.toValue
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {$e} from '../utils/templateUtils.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @type {import('../types.js').TypeObject}
|
|
5
|
+
*/
|
|
6
|
+
const nanType = {
|
|
7
|
+
option: ['NaN'],
|
|
8
|
+
stringRegex: /^NaN$/u,
|
|
9
|
+
valueMatch (x) {
|
|
10
|
+
return Number.isNaN(x);
|
|
11
|
+
},
|
|
12
|
+
toValue: () => ({value: Number.NaN}),
|
|
13
|
+
getValue: () => Number.NaN,
|
|
14
|
+
/* istanbul ignore next -- No dupe keys, array refs, or validation */
|
|
15
|
+
getInput ({root}) {
|
|
16
|
+
return /** @type {HTMLInputElement} */ ($e(root, 'input'));
|
|
17
|
+
},
|
|
18
|
+
viewUI ({specificSchemaObject}) {
|
|
19
|
+
return ['i', {
|
|
20
|
+
dataset: {type: 'nan'},
|
|
21
|
+
title: specificSchemaObject?.description ?? '(a `NaN`)'
|
|
22
|
+
}, ['NaN']];
|
|
23
|
+
},
|
|
24
|
+
editUI ({typeNamespace, specificSchemaObject}) {
|
|
25
|
+
return ['div', {
|
|
26
|
+
dataset: {type: 'nan'},
|
|
27
|
+
title: specificSchemaObject?.description ?? 'NaN'
|
|
28
|
+
}, [
|
|
29
|
+
['label', [
|
|
30
|
+
'NaN',
|
|
31
|
+
['input', {
|
|
32
|
+
type: 'checkbox',
|
|
33
|
+
name: `${typeNamespace}-nan`,
|
|
34
|
+
checked: true
|
|
35
|
+
}]
|
|
36
|
+
]]
|
|
37
|
+
]];
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export default nanType;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import {$e} from '../utils/templateUtils.js';
|
|
2
|
+
import {escapeRegex} from '../types.js';
|
|
3
|
+
import {jml} from '../vendor-imports.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @type {import('../types.js').TypeObject}
|
|
7
|
+
*/
|
|
8
|
+
const nativeEnumType = {
|
|
9
|
+
option: ['Native enum'],
|
|
10
|
+
stringRegex: /^nativeEnum\((.*)\)$/u,
|
|
11
|
+
valueMatch (x) {
|
|
12
|
+
return ['number', 'string'].includes(typeof x);
|
|
13
|
+
},
|
|
14
|
+
toValue (s, rootInfo) {
|
|
15
|
+
const key = s.charAt(0) === '"' ? s.slice(1, -1) : Number(s);
|
|
16
|
+
|
|
17
|
+
let schema = rootInfo?.schemaObject;
|
|
18
|
+
/* istanbul ignore else -- Most likely is if */
|
|
19
|
+
if (rootInfo?.schemaObject?.type === 'union') {
|
|
20
|
+
const schemas = /** @type {import('zodex').SzUnion} */ (
|
|
21
|
+
rootInfo.schemaObject
|
|
22
|
+
).options.filter((option) => {
|
|
23
|
+
return option.type === 'nativeEnum';
|
|
24
|
+
});
|
|
25
|
+
schema = schemas.find((schema) => {
|
|
26
|
+
return key in schema.values;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const value = /** @type {import('zodex').SzNativeEnum} */ (schema)?.values[
|
|
30
|
+
key
|
|
31
|
+
];
|
|
32
|
+
return {value};
|
|
33
|
+
},
|
|
34
|
+
getInput ({root}) {
|
|
35
|
+
return /** @type {HTMLTextAreaElement} */ ($e(root, 'input'));
|
|
36
|
+
},
|
|
37
|
+
setValue ({root, value}) {
|
|
38
|
+
const input = /**
|
|
39
|
+
* @type {HTMLInputElement & {
|
|
40
|
+
* $schemaNativeEnumValues: import('zodex').SzNativeEnum['values']
|
|
41
|
+
* }}
|
|
42
|
+
*/ (this.getInput({root}));
|
|
43
|
+
input.value = Object.entries(
|
|
44
|
+
input.$schemaNativeEnumValues
|
|
45
|
+
).find(([, val]) => {
|
|
46
|
+
return val === value;
|
|
47
|
+
})?.[0] ?? '';
|
|
48
|
+
/** @type {HTMLSpanElement} */ (
|
|
49
|
+
$e(root, '.enumeratedValue')
|
|
50
|
+
).textContent = value;
|
|
51
|
+
},
|
|
52
|
+
getValue ({root}) {
|
|
53
|
+
const {value, $schemaNativeEnumValues} =
|
|
54
|
+
/**
|
|
55
|
+
* @type {HTMLInputElement & {
|
|
56
|
+
* $schemaNativeEnumValues: import('zodex').SzNativeEnum['values']
|
|
57
|
+
* }}
|
|
58
|
+
*/ (
|
|
59
|
+
this.getInput({root})
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
return $schemaNativeEnumValues[value];
|
|
63
|
+
},
|
|
64
|
+
viewUI ({value, specificSchemaObject}) {
|
|
65
|
+
return ['div', [
|
|
66
|
+
'Native enum: ',
|
|
67
|
+
['span', {
|
|
68
|
+
dataset: {type: 'nativeEnum'},
|
|
69
|
+
title: specificSchemaObject?.description ?? '(a native enum)'
|
|
70
|
+
}, [value]]
|
|
71
|
+
]];
|
|
72
|
+
},
|
|
73
|
+
editUI (info) {
|
|
74
|
+
const {
|
|
75
|
+
specificSchemaObject,
|
|
76
|
+
value
|
|
77
|
+
// typeNamespace
|
|
78
|
+
} = info;
|
|
79
|
+
const schemaNativeEnumValues = /** @type {import('zodex').SzNativeEnum} */ (
|
|
80
|
+
specificSchemaObject
|
|
81
|
+
)?.values;
|
|
82
|
+
const nativeEnumKeys = Object.keys(schemaNativeEnumValues);
|
|
83
|
+
|
|
84
|
+
let keyForValue;
|
|
85
|
+
if (schemaNativeEnumValues && 'value' in info) {
|
|
86
|
+
keyForValue = Object.entries(schemaNativeEnumValues).find(([, val]) => {
|
|
87
|
+
return val === value;
|
|
88
|
+
})?.[0];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const nativeEnumPattern = nativeEnumKeys.map((nativeEnumKey) => {
|
|
92
|
+
// Zod seems to prohibit numerically-indexed strings so we prevent here,
|
|
93
|
+
// but it seems the generated JavaScript allows them (?)
|
|
94
|
+
if (
|
|
95
|
+
(/^\d$/u).test(nativeEnumKey) &&
|
|
96
|
+
Object.values(schemaNativeEnumValues).includes(
|
|
97
|
+
Number.parseInt(nativeEnumKey)
|
|
98
|
+
)
|
|
99
|
+
) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
return escapeRegex(nativeEnumKey);
|
|
103
|
+
}).filter(Boolean).join('|');
|
|
104
|
+
|
|
105
|
+
const input =
|
|
106
|
+
/**
|
|
107
|
+
* @type {HTMLInputElement & {
|
|
108
|
+
* $schemaNativeEnumValues: import('zodex').SzNativeEnum['values']
|
|
109
|
+
* }}
|
|
110
|
+
*/ (jml(
|
|
111
|
+
'input',
|
|
112
|
+
/** @type {import('jamilih').JamilihAttributes} */ ({
|
|
113
|
+
class: 'nativeEnumKey',
|
|
114
|
+
placeholder: nativeEnumPattern,
|
|
115
|
+
title: nativeEnumPattern,
|
|
116
|
+
// Implicitly already wrapped by HTML in `^(?:...)$`
|
|
117
|
+
pattern: nativeEnumPattern,
|
|
118
|
+
value: keyForValue ?? '',
|
|
119
|
+
$on: {
|
|
120
|
+
input () {
|
|
121
|
+
const ev = /** @type {HTMLSpanElement} */ (
|
|
122
|
+
this.parentElement?.parentElement?.querySelector(
|
|
123
|
+
'.enumeratedValue'
|
|
124
|
+
)
|
|
125
|
+
);
|
|
126
|
+
ev.textContent = String(schemaNativeEnumValues[
|
|
127
|
+
/** @type {HTMLInputElement} */
|
|
128
|
+
(this).value
|
|
129
|
+
] ?? '');
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
));
|
|
134
|
+
input.$schemaNativeEnumValues = schemaNativeEnumValues;
|
|
135
|
+
|
|
136
|
+
return ['div', {
|
|
137
|
+
dataset: {type: 'nativeEnum'},
|
|
138
|
+
title: specificSchemaObject?.description ?? 'Native Enum'
|
|
139
|
+
}, [
|
|
140
|
+
['label', [
|
|
141
|
+
'Enumerated key ',
|
|
142
|
+
input
|
|
143
|
+
]],
|
|
144
|
+
['br'],
|
|
145
|
+
'Enumerated value: ',
|
|
146
|
+
['span', {
|
|
147
|
+
class: 'enumeratedValue'
|
|
148
|
+
}, [
|
|
149
|
+
value ?? ''
|
|
150
|
+
]]
|
|
151
|
+
]];
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export default nativeEnumType;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {$e} from '../utils/templateUtils.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @type {import('../types.js').TypeObject}
|
|
5
|
+
*/
|
|
6
|
+
const neverType = {
|
|
7
|
+
stringRegex: /^never$/u,
|
|
8
|
+
option: ['Never'],
|
|
9
|
+
valueMatch () {
|
|
10
|
+
return false;
|
|
11
|
+
},
|
|
12
|
+
toValue (/* _s */) {
|
|
13
|
+
throw new Error('Cannot convert to value');
|
|
14
|
+
},
|
|
15
|
+
getValue () {
|
|
16
|
+
return /** @type {import('../types.js').ToValue} */ (
|
|
17
|
+
this.toValue
|
|
18
|
+
)('');
|
|
19
|
+
},
|
|
20
|
+
viewUI ({specificSchemaObject}) {
|
|
21
|
+
return ['i', {
|
|
22
|
+
dataset: {type: 'never'},
|
|
23
|
+
title: specificSchemaObject?.description ?? '(a `never`)'
|
|
24
|
+
}, ['never']];
|
|
25
|
+
},
|
|
26
|
+
/* istanbul ignore next -- No dupe keys, array refs, or validation */
|
|
27
|
+
getInput ({root}) {
|
|
28
|
+
return /** @type {HTMLInputElement} */ ($e(root, 'input'));
|
|
29
|
+
},
|
|
30
|
+
editUI ({typeNamespace}) {
|
|
31
|
+
return ['div', {dataset: {type: 'never'}}, [
|
|
32
|
+
['label', [
|
|
33
|
+
'Never (no value present here)',
|
|
34
|
+
['input', {
|
|
35
|
+
type: 'checkbox',
|
|
36
|
+
name: `${typeNamespace}-never`,
|
|
37
|
+
hidden: true
|
|
38
|
+
}]
|
|
39
|
+
]]
|
|
40
|
+
]];
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export default neverType;
|
|
@@ -8,6 +8,9 @@ const noneditableType = {
|
|
|
8
8
|
// Ideally, we would remove the option,
|
|
9
9
|
// but edit forms currently need a pull-down option
|
|
10
10
|
option: ['Non-editable'],
|
|
11
|
+
valueMatch () {
|
|
12
|
+
return true;
|
|
13
|
+
},
|
|
11
14
|
getInput ({root}) {
|
|
12
15
|
return /** @type {HTMLButtonElement} */ ($e(root, 'button'));
|
|
13
16
|
},
|
|
@@ -36,19 +39,30 @@ const noneditableType = {
|
|
|
36
39
|
valid: val !== undefined
|
|
37
40
|
};
|
|
38
41
|
},
|
|
39
|
-
viewUI ({value}) {
|
|
42
|
+
viewUI ({value, specificSchemaObject}) {
|
|
43
|
+
const stringTag = toStringTag(value);
|
|
40
44
|
return ['div', {dataset: {type: 'resurrectable'}}, [
|
|
41
|
-
['b', {
|
|
45
|
+
['b', {
|
|
46
|
+
class: 'emphasis',
|
|
47
|
+
title: specificSchemaObject?.description
|
|
48
|
+
? `(a non-editable ${stringTag})`
|
|
49
|
+
: undefined
|
|
50
|
+
}, [
|
|
51
|
+
specificSchemaObject?.description ?? 'Non-editable'
|
|
52
|
+
]],
|
|
42
53
|
['span', {
|
|
43
54
|
title: 'There is no current support for editing this element\'s ' +
|
|
44
55
|
'type, but its contents will be passed on transparently.'
|
|
45
56
|
}, ['?']],
|
|
46
57
|
['b', ['String tag: ']],
|
|
47
|
-
|
|
58
|
+
stringTag
|
|
48
59
|
]];
|
|
49
60
|
},
|
|
50
|
-
editUI ({typeNamespace, value}) {
|
|
51
|
-
return ['div', {
|
|
61
|
+
editUI ({typeNamespace, specificSchemaObject, value}) {
|
|
62
|
+
return ['div', {
|
|
63
|
+
dataset: {type: 'resurrectable'},
|
|
64
|
+
title: specificSchemaObject?.description ?? 'Non-editable'
|
|
65
|
+
}, [
|
|
52
66
|
['a', {
|
|
53
67
|
// eslint-disable-next-line no-script-url -- Safe
|
|
54
68
|
href: 'javascript:void(0)',
|
|
@@ -6,23 +6,33 @@ import {$e} from '../utils/templateUtils.js';
|
|
|
6
6
|
const nullType = {
|
|
7
7
|
option: ['Null'],
|
|
8
8
|
stringRegex: /^null$/u,
|
|
9
|
+
valueMatch (x) {
|
|
10
|
+
return x === null;
|
|
11
|
+
},
|
|
9
12
|
toValue: () => ({value: null}),
|
|
10
13
|
getValue: () => null,
|
|
11
|
-
viewUI () {
|
|
12
|
-
return ['i', {dataset: {type: 'null'}}, ['null']];
|
|
13
|
-
},
|
|
14
14
|
/* istanbul ignore next -- No dupe keys, array refs, or validation */
|
|
15
15
|
getInput ({root}) {
|
|
16
16
|
return /** @type {HTMLInputElement} */ ($e(root, 'input'));
|
|
17
17
|
},
|
|
18
|
-
|
|
19
|
-
return ['
|
|
18
|
+
viewUI ({specificSchemaObject}) {
|
|
19
|
+
return ['i', {
|
|
20
|
+
dataset: {type: 'null'},
|
|
21
|
+
title: specificSchemaObject?.description ?? '(a `null`)'
|
|
22
|
+
}, ['null']];
|
|
23
|
+
},
|
|
24
|
+
editUI ({typeNamespace, specificSchemaObject}) {
|
|
25
|
+
return ['div', {
|
|
26
|
+
dataset: {type: 'null'},
|
|
27
|
+
title: specificSchemaObject?.description ?? 'Null'
|
|
28
|
+
}, [
|
|
20
29
|
['label', [
|
|
21
30
|
'Null',
|
|
22
31
|
['input', {
|
|
23
32
|
type: 'checkbox',
|
|
24
33
|
name: `${typeNamespace}-null`,
|
|
25
|
-
checked: true
|
|
34
|
+
checked: true,
|
|
35
|
+
disabled: true
|
|
26
36
|
}]
|
|
27
37
|
]]
|
|
28
38
|
]];
|
|
@@ -9,7 +9,7 @@ const numberType = {
|
|
|
9
9
|
'^' + // No leading content.
|
|
10
10
|
'[-+]?' + // Optional sign.
|
|
11
11
|
// Optionally 0-30 decimal digits of mantissa.
|
|
12
|
-
|
|
12
|
+
String.raw`(?:[0-9]{0,30}\.)?` +
|
|
13
13
|
// 1-30 decimal digits of integer or fraction.
|
|
14
14
|
'[0-9]{1,30}' +
|
|
15
15
|
// Optional exponent 0-29 for scientific notation.
|
|
@@ -17,6 +17,13 @@ const numberType = {
|
|
|
17
17
|
'$', // No trailing content.
|
|
18
18
|
'u'
|
|
19
19
|
),
|
|
20
|
+
valueMatch (x) {
|
|
21
|
+
return typeof x === 'number' &&
|
|
22
|
+
// Avoid special numbers:
|
|
23
|
+
!Number.isNaN(x) &&
|
|
24
|
+
x !== Number.POSITIVE_INFINITY && x !== Number.NEGATIVE_INFINITY &&
|
|
25
|
+
!Object.is(x, -0);
|
|
26
|
+
},
|
|
20
27
|
toValue (s) {
|
|
21
28
|
return {value: Number(s)};
|
|
22
29
|
},
|
|
@@ -41,13 +48,49 @@ const numberType = {
|
|
|
41
48
|
// Todo?
|
|
42
49
|
},
|
|
43
50
|
*/
|
|
44
|
-
viewUI ({value}) {
|
|
45
|
-
return ['i', {
|
|
51
|
+
viewUI ({value, specificSchemaObject}) {
|
|
52
|
+
return ['i', {
|
|
53
|
+
dataset: {type: 'number'},
|
|
54
|
+
title: specificSchemaObject?.description ?? '(a number)'
|
|
55
|
+
}, [
|
|
56
|
+
String(value)
|
|
57
|
+
]];
|
|
46
58
|
},
|
|
47
|
-
editUI ({typeNamespace, value
|
|
48
|
-
|
|
59
|
+
editUI ({typeNamespace, specificSchemaObject, value}) {
|
|
60
|
+
const isLiteral = specificSchemaObject?.type === 'literal';
|
|
61
|
+
const numberSchemaObject = /** @type {import('zodex').SzNumber} */ (
|
|
62
|
+
specificSchemaObject
|
|
63
|
+
);
|
|
64
|
+
// Seems to need a multiplier of around these sizes to have a noticeable
|
|
65
|
+
// effect on the inputs; shouldn't need any though
|
|
66
|
+
const epsilon = 150 * Number.EPSILON;
|
|
67
|
+
const maxEpsilon = 300 * Number.EPSILON;
|
|
68
|
+
|
|
69
|
+
return ['div', {
|
|
70
|
+
dataset: {type: 'number'},
|
|
71
|
+
title: specificSchemaObject?.description ?? 'Number'
|
|
72
|
+
}, [
|
|
49
73
|
['input', {
|
|
50
|
-
|
|
74
|
+
disabled: isLiteral,
|
|
75
|
+
name: `${typeNamespace}-number`,
|
|
76
|
+
type: 'number',
|
|
77
|
+
min: numberSchemaObject?.min
|
|
78
|
+
? numberSchemaObject?.minInclusive
|
|
79
|
+
? numberSchemaObject?.min
|
|
80
|
+
: numberSchemaObject?.min +
|
|
81
|
+
(numberSchemaObject?.int ? 1 : epsilon)
|
|
82
|
+
: undefined,
|
|
83
|
+
max: numberSchemaObject?.max
|
|
84
|
+
? numberSchemaObject?.maxInclusive
|
|
85
|
+
? numberSchemaObject?.max
|
|
86
|
+
: numberSchemaObject?.max -
|
|
87
|
+
(numberSchemaObject?.int ? 1 : maxEpsilon)
|
|
88
|
+
: undefined,
|
|
89
|
+
step: numberSchemaObject?.multipleOf ??
|
|
90
|
+
(numberSchemaObject?.int ? '1' : 'any'),
|
|
91
|
+
value: isLiteral
|
|
92
|
+
? specificSchemaObject?.value
|
|
93
|
+
: (value ?? specificSchemaObject?.defaultValue ?? '')
|
|
51
94
|
}]
|
|
52
95
|
]];
|
|
53
96
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {toStringTag} from '../vendor-imports.js';
|
|
1
2
|
import arrayType from './arrayType.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -8,6 +9,11 @@ const objectType = {
|
|
|
8
9
|
regexEndings: [',', '}'],
|
|
9
10
|
stringRegexBegin: /^\{/u,
|
|
10
11
|
stringRegexEnd: /^\}/u,
|
|
12
|
+
valueMatch (x) {
|
|
13
|
+
return x && typeof x === 'object' &&
|
|
14
|
+
// Exclude other special object types
|
|
15
|
+
toStringTag(x) === 'Object';
|
|
16
|
+
},
|
|
11
17
|
toValue (...args) {
|
|
12
18
|
return /** @type {import('../types.js').ToValue} */ (
|
|
13
19
|
arrayType.toValue
|
|
@@ -19,8 +25,10 @@ const objectType = {
|
|
|
19
25
|
getInput (...args) {
|
|
20
26
|
return arrayType.getInput.apply(this, args);
|
|
21
27
|
},
|
|
22
|
-
viewUI (...args) {
|
|
23
|
-
return arrayType.viewUI.
|
|
28
|
+
viewUI ({...args}) {
|
|
29
|
+
return arrayType.viewUI.call(this, {
|
|
30
|
+
...args, type: 'object'
|
|
31
|
+
});
|
|
24
32
|
},
|
|
25
33
|
editUI ({...args}) {
|
|
26
34
|
return arrayType.editUI.call(this, {
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {toStringTag} from '../vendor-imports.js';
|
|
2
|
+
import {$e} from '../utils/templateUtils.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @type {import('../types.js').TypeObject}
|
|
6
|
+
*/
|
|
7
|
+
const promiseType = {
|
|
8
|
+
option: ['Promise'],
|
|
9
|
+
stringRegex: /^Promise\((.*)\)$/u,
|
|
10
|
+
// Todo: Fix all the following methods up to `editUI` to work with children
|
|
11
|
+
valueMatch (x) {
|
|
12
|
+
return toStringTag(x) === 'Promise';
|
|
13
|
+
},
|
|
14
|
+
toValue (s) {
|
|
15
|
+
return {value: s.slice(8, -1)};
|
|
16
|
+
},
|
|
17
|
+
getInput ({root}) {
|
|
18
|
+
return /** @type {HTMLTextAreaElement} */ ($e(root, 'input'));
|
|
19
|
+
},
|
|
20
|
+
setValue ({root, value}) {
|
|
21
|
+
this.getInput({root}).value = value;
|
|
22
|
+
},
|
|
23
|
+
getValue ({root}) {
|
|
24
|
+
return this.getInput({root}).value;
|
|
25
|
+
},
|
|
26
|
+
viewUI ({specificSchemaObject}) {
|
|
27
|
+
return ['span', {
|
|
28
|
+
dataset: {type: 'promise'},
|
|
29
|
+
title: specificSchemaObject?.description
|
|
30
|
+
}, [
|
|
31
|
+
// We don't know what it resolves to without awaiting it
|
|
32
|
+
'A Promise'
|
|
33
|
+
]];
|
|
34
|
+
},
|
|
35
|
+
editUI ({
|
|
36
|
+
format, type, buildTypeChoices, specificSchemaObject,
|
|
37
|
+
topRoot, schemaContent, typeNamespace
|
|
38
|
+
}) {
|
|
39
|
+
return ['div', {dataset: {type: 'promise'}}, [
|
|
40
|
+
...(/** @type {import('../typeChoices.js').BuildTypeChoices} */ (
|
|
41
|
+
buildTypeChoices
|
|
42
|
+
)({
|
|
43
|
+
// resultType,
|
|
44
|
+
// eslint-disable-next-line object-shorthand -- TS
|
|
45
|
+
topRoot: /** @type {HTMLDivElement} */ (topRoot),
|
|
46
|
+
// eslint-disable-next-line object-shorthand -- TS
|
|
47
|
+
format: /** @type {import('../formats.js').AvailableFormat} */ (format),
|
|
48
|
+
schemaOriginal: schemaContent,
|
|
49
|
+
schemaContent: /** @type {import('zodex').SzPromise} */ (
|
|
50
|
+
specificSchemaObject
|
|
51
|
+
)?.value ?? {type: 'any'},
|
|
52
|
+
state: type,
|
|
53
|
+
// itemIndex,
|
|
54
|
+
typeNamespace
|
|
55
|
+
}).domArray)
|
|
56
|
+
]];
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export default promiseType;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {toStringTag} from '../vendor-imports.js';
|
|
2
|
+
import arrayType from './arrayType.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @type {import('../types.js').TypeObject}
|
|
6
|
+
*/
|
|
7
|
+
const recordType = {
|
|
8
|
+
option: ['Record'],
|
|
9
|
+
regexEndings: [',', '}'],
|
|
10
|
+
stringRegexBegin: /^Record\{/u,
|
|
11
|
+
stringRegexEnd: /^\}/u,
|
|
12
|
+
array: true,
|
|
13
|
+
record: true,
|
|
14
|
+
valueMatch (x) { // Like `object` type, can also match
|
|
15
|
+
return x && typeof x === 'object' &&
|
|
16
|
+
// Exclude other special object types
|
|
17
|
+
toStringTag(x) === 'Object';
|
|
18
|
+
},
|
|
19
|
+
toValue (...args) {
|
|
20
|
+
return /** @type {import('../types.js').ToValue} */ (
|
|
21
|
+
arrayType.toValue
|
|
22
|
+
).apply(this, args);
|
|
23
|
+
},
|
|
24
|
+
getValue (...args) {
|
|
25
|
+
return arrayType.getValue.apply(this, args);
|
|
26
|
+
},
|
|
27
|
+
getInput (...args) {
|
|
28
|
+
return arrayType.getInput.apply(this, args);
|
|
29
|
+
},
|
|
30
|
+
viewUI ({...args}) {
|
|
31
|
+
return arrayType.viewUI.call(this, {
|
|
32
|
+
...args, type: 'record'
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
editUI ({...args}) {
|
|
36
|
+
return arrayType.editUI.call(this, {
|
|
37
|
+
...args, type: 'record'
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default recordType;
|