@es-joy/jsoe 0.2.0 → 0.4.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/.eslintignore +3 -0
- package/.eslintrc.cjs +2 -0
- package/.ncurc.cjs +9 -0
- package/CHANGES.md +9 -0
- package/README.md +2 -2
- package/demo/index.html +8 -0
- package/demo/index.js +1 -1
- package/dist/formatAndTypeChoices.d.ts +56 -0
- package/dist/formatAndTypeChoices.d.ts.map +1 -0
- package/dist/formats/indexedDBKey.d.ts +4 -0
- package/dist/formats/indexedDBKey.d.ts.map +1 -0
- package/dist/formats/json.d.ts +4 -0
- package/dist/formats/json.d.ts.map +1 -0
- package/dist/formats/schemaAndArbitrary.d.ts +6 -0
- package/dist/formats/schemaAndArbitrary.d.ts.map +1 -0
- package/dist/formats/schemaOnly.d.ts +6 -0
- package/dist/formats/schemaOnly.d.ts.map +1 -0
- package/dist/formats/structuredCloning.d.ts +20 -0
- package/dist/formats/structuredCloning.d.ts.map +1 -0
- package/dist/formats.d.ts +26 -0
- package/dist/formats.d.ts.map +1 -0
- package/dist/fundamentalTypes/BooleanObjectType.d.ts +8 -0
- package/dist/fundamentalTypes/BooleanObjectType.d.ts.map +1 -0
- package/dist/fundamentalTypes/NumberObjectType.d.ts +6 -0
- package/dist/fundamentalTypes/NumberObjectType.d.ts.map +1 -0
- package/dist/fundamentalTypes/StringObjectType.d.ts +6 -0
- package/dist/fundamentalTypes/StringObjectType.d.ts.map +1 -0
- package/dist/fundamentalTypes/arrayReferenceType.d.ts +8 -0
- package/dist/fundamentalTypes/arrayReferenceType.d.ts.map +1 -0
- package/dist/fundamentalTypes/arrayType.d.ts +60 -0
- package/dist/fundamentalTypes/arrayType.d.ts.map +1 -0
- package/dist/fundamentalTypes/bigintType.d.ts +6 -0
- package/dist/fundamentalTypes/bigintType.d.ts.map +1 -0
- package/dist/fundamentalTypes/dateType.d.ts +26 -0
- package/dist/fundamentalTypes/dateType.d.ts.map +1 -0
- package/dist/fundamentalTypes/nullType.d.ts +6 -0
- package/dist/fundamentalTypes/nullType.d.ts.map +1 -0
- package/dist/fundamentalTypes/numberType.d.ts +6 -0
- package/dist/fundamentalTypes/numberType.d.ts.map +1 -0
- package/dist/fundamentalTypes/objectReferenceType.d.ts +8 -0
- package/dist/fundamentalTypes/objectReferenceType.d.ts.map +1 -0
- package/dist/fundamentalTypes/objectType.d.ts +6 -0
- package/dist/fundamentalTypes/objectType.d.ts.map +1 -0
- package/dist/fundamentalTypes/regexpType.d.ts +8 -0
- package/dist/fundamentalTypes/regexpType.d.ts.map +1 -0
- package/dist/fundamentalTypes/sparseUndefinedType.d.ts +6 -0
- package/dist/fundamentalTypes/sparseUndefinedType.d.ts.map +1 -0
- package/dist/fundamentalTypes/stringType.d.ts +6 -0
- package/dist/fundamentalTypes/stringType.d.ts.map +1 -0
- package/dist/fundamentalTypes/undefinedType.d.ts +6 -0
- package/dist/fundamentalTypes/undefinedType.d.ts.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/src/deepEqual.d.ts +3 -0
- package/dist/src/deepEqual.d.ts.map +1 -0
- package/dist/src/formatAndTypeChoices.d.ts +47 -0
- package/dist/src/formatAndTypeChoices.d.ts.map +1 -0
- package/dist/src/formats/indexedDBKey.d.ts +9 -0
- package/dist/src/formats/indexedDBKey.d.ts.map +1 -0
- package/dist/src/formats/json.d.ts +9 -0
- package/dist/src/formats/json.d.ts.map +1 -0
- package/dist/src/formats/schemaAndArbitrary.d.ts +6 -0
- package/dist/src/formats/schemaAndArbitrary.d.ts.map +1 -0
- package/dist/src/formats/schemaOnly.d.ts +6 -0
- package/dist/src/formats/schemaOnly.d.ts.map +1 -0
- package/dist/src/formats/structuredCloning.d.ts +15 -0
- package/dist/src/formats/structuredCloning.d.ts.map +1 -0
- package/dist/src/formats.d.ts +18 -0
- package/dist/src/formats.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/BooleanObjectType.d.ts +6 -0
- package/dist/src/fundamentalTypes/BooleanObjectType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/NumberObjectType.d.ts +6 -0
- package/dist/src/fundamentalTypes/NumberObjectType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/StringObjectType.d.ts +6 -0
- package/dist/src/fundamentalTypes/StringObjectType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/arrayReferenceType.d.ts +6 -0
- package/dist/src/fundamentalTypes/arrayReferenceType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/arrayType.d.ts +6 -0
- package/dist/src/fundamentalTypes/arrayType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/bigintType.d.ts +6 -0
- package/dist/src/fundamentalTypes/bigintType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/dateType.d.ts +6 -0
- package/dist/src/fundamentalTypes/dateType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/nullType.d.ts +6 -0
- package/dist/src/fundamentalTypes/nullType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/numberType.d.ts +6 -0
- package/dist/src/fundamentalTypes/numberType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/objectReferenceType.d.ts +6 -0
- package/dist/src/fundamentalTypes/objectReferenceType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/objectType.d.ts +6 -0
- package/dist/src/fundamentalTypes/objectType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/regexpType.d.ts +6 -0
- package/dist/src/fundamentalTypes/regexpType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/sparseUndefinedType.d.ts +6 -0
- package/dist/src/fundamentalTypes/sparseUndefinedType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/stringType.d.ts +6 -0
- package/dist/src/fundamentalTypes/stringType.d.ts.map +1 -0
- package/dist/src/fundamentalTypes/undefinedType.d.ts +6 -0
- package/dist/src/fundamentalTypes/undefinedType.d.ts.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/subTypes/blobHTMLType.d.ts +26 -0
- package/dist/src/subTypes/blobHTMLType.d.ts.map +1 -0
- package/dist/src/subTypes/falseType.d.ts +6 -0
- package/dist/src/subTypes/falseType.d.ts.map +1 -0
- package/dist/src/subTypes/trueType.d.ts +6 -0
- package/dist/src/subTypes/trueType.d.ts.map +1 -0
- package/dist/src/superTypes/SpecialNumberSuperType.d.ts +11 -0
- package/dist/src/superTypes/SpecialNumberSuperType.d.ts.map +1 -0
- package/dist/src/superTypes/SpecialRealNumberSuperType.d.ts +6 -0
- package/dist/src/superTypes/SpecialRealNumberSuperType.d.ts.map +1 -0
- package/dist/src/typeChoices.d.ts +30 -0
- package/dist/src/typeChoices.d.ts.map +1 -0
- package/dist/src/types.d.ts +333 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/utils/dialogs.d.ts +29 -0
- package/dist/src/utils/dialogs.d.ts.map +1 -0
- package/dist/src/utils/jsonPointer.d.ts +42 -0
- package/dist/src/utils/jsonPointer.d.ts.map +1 -0
- package/dist/src/utils/templateUtils.d.ts +59 -0
- package/dist/src/utils/templateUtils.d.ts.map +1 -0
- package/dist/src/utils/types.d.ts +2 -0
- package/dist/src/utils/types.d.ts.map +1 -0
- package/dist/subTypes/blobHTMLType.d.ts +14 -0
- package/dist/subTypes/blobHTMLType.d.ts.map +1 -0
- package/dist/subTypes/falseType.d.ts +8 -0
- package/dist/subTypes/falseType.d.ts.map +1 -0
- package/dist/subTypes/trueType.d.ts +8 -0
- package/dist/subTypes/trueType.d.ts.map +1 -0
- package/dist/superTypes/SpecialNumberSuperType.d.ts +14 -0
- package/dist/superTypes/SpecialNumberSuperType.d.ts.map +1 -0
- package/dist/superTypes/SpecialRealNumberSuperType.d.ts +6 -0
- package/dist/superTypes/SpecialRealNumberSuperType.d.ts.map +1 -0
- package/dist/typeChoices.d.ts +103 -0
- package/dist/typeChoices.d.ts.map +1 -0
- package/dist/types.d.ts +523 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/dialogs.d.ts +109 -0
- package/dist/utils/dialogs.d.ts.map +1 -0
- package/dist/utils/jsonPointer.d.ts +46 -0
- package/dist/utils/jsonPointer.d.ts.map +1 -0
- package/dist/utils/templateUtils.d.ts +59 -0
- package/dist/utils/templateUtils.d.ts.map +1 -0
- package/dist/utils/types.d.ts +2 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/vendor/jamilih/dist/jml-es.d.ts +436 -0
- package/dist/vendor/jamilih/dist/jml-es.d.ts.map +1 -0
- package/dist/vendor/typeson-registry/dist/index.d.ts +400 -0
- package/dist/vendor/typeson-registry/dist/index.d.ts.map +1 -0
- package/dist/vendor-imports.d.ts +3 -0
- package/dist/vendor-imports.d.ts.map +1 -0
- package/package.json +19 -14
- package/postorder-traversal.js +58 -0
- package/src/formatAndTypeChoices.js +95 -50
- package/src/formats/indexedDBKey.js +49 -56
- package/src/formats/json.js +47 -56
- package/src/formats/schemaOnly.js +12 -2
- package/src/formats/structuredCloning.js +162 -105
- package/src/formats.js +38 -10
- package/src/fundamentalTypes/BooleanObjectType.js +6 -4
- package/src/fundamentalTypes/NumberObjectType.js +5 -3
- package/src/fundamentalTypes/StringObjectType.js +1 -1
- package/src/fundamentalTypes/arrayReferenceType.js +29 -14
- package/src/fundamentalTypes/arrayType.js +789 -278
- package/src/fundamentalTypes/bigintType.js +2 -2
- package/src/fundamentalTypes/dateType.js +42 -14
- package/src/fundamentalTypes/nullType.js +1 -1
- package/src/fundamentalTypes/numberType.js +2 -2
- package/src/fundamentalTypes/objectReferenceType.js +7 -5
- package/src/fundamentalTypes/regexpType.js +45 -24
- package/src/fundamentalTypes/sparseUndefinedType.js +7 -1
- package/src/fundamentalTypes/stringType.js +1 -1
- package/src/fundamentalTypes/undefinedType.js +2 -2
- package/src/jsoe.css +1 -1
- package/src/subTypes/blobHTMLType.js +42 -22
- package/src/subTypes/falseType.js +2 -2
- package/src/subTypes/trueType.js +2 -2
- package/src/superTypes/SpecialNumberSuperType.js +30 -16
- package/src/superTypes/SpecialRealNumberSuperType.js +62 -0
- package/src/typeChoices.js +137 -55
- package/src/types.js +312 -148
- package/src/utils/dialogs.js +98 -29
- package/src/utils/jsonPointer.js +4 -0
- package/src/utils/templateUtils.js +27 -12
- package/src/vendor-imports.js +8 -0
- package/tsconfig.json +18 -0
- package/typings/sceditor.d.ts +20 -0
- package/vendor/jamilih/dist/jml-es.js +1019 -389
- package/vendor/jamilih/dist/jml.d.ts +436 -0
- package/vendor/jamilih/package.json +136 -0
- package/vendor/typeson-registry/dist/index.js +382 -84
- package/src/superTypes/InfinitiesSuperType.js +0 -49
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {$e} from '../utils/templateUtils.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @type {import('./SpecialNumberSuperType.js').SuperTypeObject}
|
|
5
|
+
*/
|
|
6
|
+
const SpecialRealNumberSuperType = {
|
|
7
|
+
option: ['Special Real Number', {title: '`Infinity`, `-Infinity`, `-0`'}],
|
|
8
|
+
childTypes: ['infinity', 'negativeInfinity', 'negativeZero'],
|
|
9
|
+
stringRegex: /^(?:-?Infinity|-0)$/u,
|
|
10
|
+
toValue (s) {
|
|
11
|
+
return {
|
|
12
|
+
value: s === '-0'
|
|
13
|
+
? -0
|
|
14
|
+
: s === 'Infinity'
|
|
15
|
+
? Number.POSITIVE_INFINITY
|
|
16
|
+
: Number.NEGATIVE_INFINITY
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
getSelect ({root}) {
|
|
20
|
+
return /** @type {HTMLSelectElement} */ ($e(root, 'select'));
|
|
21
|
+
},
|
|
22
|
+
getValue ({root}) {
|
|
23
|
+
return this.toValue(
|
|
24
|
+
/** @type {Required<import('../types.js').TypeObject>} */ (
|
|
25
|
+
this
|
|
26
|
+
).getSelect({root}).value
|
|
27
|
+
).value;
|
|
28
|
+
},
|
|
29
|
+
setValue ({root, value}) {
|
|
30
|
+
/** @type {Required<import('../types.js').TypeObject>} */ (
|
|
31
|
+
this
|
|
32
|
+
).getSelect({root}).value = String(value);
|
|
33
|
+
},
|
|
34
|
+
viewUI ({value}) {
|
|
35
|
+
return ['i', {dataset: {type: 'SpecialRealNumber'}}, [
|
|
36
|
+
Object.is(value, -0) ? '-0' : String(value)
|
|
37
|
+
]];
|
|
38
|
+
},
|
|
39
|
+
getInput ({root}) {
|
|
40
|
+
return /** @type {HTMLSelectElement} */ ($e(root, 'select'));
|
|
41
|
+
},
|
|
42
|
+
editUI ({typeNamespace, value = Number.POSITIVE_INFINITY}) {
|
|
43
|
+
return ['div', {dataset: {type: 'SpecialRealNumber'}}, [
|
|
44
|
+
['label', [
|
|
45
|
+
'Special Real Number: ',
|
|
46
|
+
['select', {name: `${typeNamespace}-SpecialRealNumber`}, [
|
|
47
|
+
['option', {
|
|
48
|
+
value: 'Infinity', selected: value === Number.POSITIVE_INFINITY
|
|
49
|
+
}, ['Infinity']],
|
|
50
|
+
['option', {
|
|
51
|
+
value: '-Infinity', selected: value === Number.NEGATIVE_INFINITY
|
|
52
|
+
}, ['-Infinity']],
|
|
53
|
+
['option', {
|
|
54
|
+
value: '-0', selected: Object.is(value, -0)
|
|
55
|
+
}, ['-0']]
|
|
56
|
+
]]
|
|
57
|
+
]]
|
|
58
|
+
]];
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default SpecialRealNumberSuperType;
|
package/src/typeChoices.js
CHANGED
|
@@ -1,30 +1,79 @@
|
|
|
1
|
+
import {jml} from './vendor-imports.js';
|
|
1
2
|
import Formats, {getControlsForFormatAndValue} from './formats.js';
|
|
2
3
|
import Types from './types.js';
|
|
3
|
-
import {jml} from '../vendor/jamilih/dist/jml-es.js';
|
|
4
4
|
|
|
5
5
|
import {$e, DOM} from './utils/templateUtils.js';
|
|
6
6
|
import dialogs from './utils/dialogs.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
|
|
9
|
+
* @typedef {(info: {type: string, editUI: Element}) => void} AddTypeAndEditUI
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {(info?: {
|
|
14
|
+
* baseValue?: import('./formats.js').StructuredCloneValue,
|
|
15
|
+
* bringIntoFocus?: boolean
|
|
16
|
+
* }) => void} AddAndValidateEditUI
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {() => void} SetStyles
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @typedef {Element & {
|
|
25
|
+
* $addAndValidateEditUI: AddAndValidateEditUI,
|
|
26
|
+
* $setStyles: SetStyles
|
|
27
|
+
* }} TypeChoicesElementAPI
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @callback GetValue
|
|
32
|
+
* @param {import('./types.js').StateObject} [stateObj] Will
|
|
33
|
+
* auto-set `typeNamespace` and `format`
|
|
34
|
+
* @param {string} [currentPath]
|
|
35
|
+
* @returns {import('./formats.js').StructuredCloneValue}
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @callback GetType
|
|
40
|
+
* @returns {string|null|undefined}
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @callback ValidValuesSet
|
|
45
|
+
* @returns {boolean}
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @callback SetValue
|
|
50
|
+
* @param {import('./formats.js').StructuredCloneValue} value
|
|
51
|
+
* @param {import('./types.js').StateObject} stateObj
|
|
52
|
+
* @returns {Promise<void>}
|
|
11
53
|
*/
|
|
12
54
|
|
|
13
55
|
/**
|
|
14
56
|
* @callback BuildTypeChoices
|
|
15
|
-
* @param {
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
57
|
+
* @param {{
|
|
58
|
+
* format: import('./formats.js').AvailableFormat,
|
|
59
|
+
* typeNamespace?: string,
|
|
60
|
+
* value?: import('./formats.js').StructuredCloneValue,
|
|
61
|
+
* setValue?: boolean,
|
|
62
|
+
* state?: string,
|
|
63
|
+
* keySelectClass?: string,
|
|
64
|
+
* requireObject?: boolean,
|
|
65
|
+
* objectHasValue?: boolean,
|
|
66
|
+
* topRoot: import('./types.js').RootElement,
|
|
67
|
+
* schema?: string,
|
|
68
|
+
* schemaContent?: object,
|
|
69
|
+
* }} cfg
|
|
70
|
+
* @returns {{
|
|
71
|
+
* domArray: [select: Element, typeContainer: Element],
|
|
72
|
+
* getValue: GetValue,
|
|
73
|
+
* getType: GetType,
|
|
74
|
+
* validValuesSet: ValidValuesSet,
|
|
75
|
+
* setValue: SetValue
|
|
76
|
+
* }}
|
|
28
77
|
*/
|
|
29
78
|
|
|
30
79
|
/**
|
|
@@ -50,7 +99,7 @@ export const buildTypeChoices = ({
|
|
|
50
99
|
: Types.getTypeOptionsForFormatAndState(format, state);
|
|
51
100
|
|
|
52
101
|
let editUI;
|
|
53
|
-
const sel = jml('select', {
|
|
102
|
+
const sel = /** @type {HTMLSelectElement} */ (jml('select', {
|
|
54
103
|
hidden: requireObject,
|
|
55
104
|
class: `typeChoices-${typeNamespace}${keySelectClass
|
|
56
105
|
? ' ' + keySelectClass
|
|
@@ -58,15 +107,27 @@ export const buildTypeChoices = ({
|
|
|
58
107
|
}`,
|
|
59
108
|
// is: 'type-choices',
|
|
60
109
|
$custom: {
|
|
110
|
+
/**
|
|
111
|
+
* @param {object} cfg
|
|
112
|
+
* @param {string} cfg.type
|
|
113
|
+
* @param {import('./formats.js').StructuredCloneValue} cfg.baseValue
|
|
114
|
+
* @param {boolean} cfg.bringIntoFocus
|
|
115
|
+
* @returns {void}
|
|
116
|
+
*/
|
|
61
117
|
$setType ({type, baseValue, bringIntoFocus}) {
|
|
62
118
|
this.value = type;
|
|
63
119
|
this.$setStyles();
|
|
64
120
|
this.$addAndValidateEditUI({baseValue, bringIntoFocus});
|
|
65
121
|
},
|
|
122
|
+
/**
|
|
123
|
+
* @type {(info: {type: string}) => void} cfg
|
|
124
|
+
*/
|
|
66
125
|
$setTypeNoEditUI ({type}) {
|
|
67
126
|
this.value = type;
|
|
68
127
|
this.$setStyles();
|
|
69
128
|
},
|
|
129
|
+
|
|
130
|
+
/** @type {SetStyles} */
|
|
70
131
|
$setStyles () {
|
|
71
132
|
const {value: type} = this;
|
|
72
133
|
this.dataset.type = type; // Used for styling
|
|
@@ -74,7 +135,7 @@ export const buildTypeChoices = ({
|
|
|
74
135
|
if (parEl.nodeName.toLowerCase() === 'fieldset') {
|
|
75
136
|
parEl.dataset.type = type;
|
|
76
137
|
DOM.filterChildElements(parEl, 'legend').forEach((legend) => {
|
|
77
|
-
legend.dataset.type = type;
|
|
138
|
+
/** @type {HTMLElement} */ (legend).dataset.type = type;
|
|
78
139
|
});
|
|
79
140
|
}
|
|
80
141
|
},
|
|
@@ -86,6 +147,8 @@ export const buildTypeChoices = ({
|
|
|
86
147
|
}
|
|
87
148
|
return $e(container, 'div[data-type]');
|
|
88
149
|
},
|
|
150
|
+
|
|
151
|
+
/** @type {AddAndValidateEditUI} */
|
|
89
152
|
$addAndValidateEditUI ({baseValue, bringIntoFocus} = {}) {
|
|
90
153
|
const {value: type} = this;
|
|
91
154
|
|
|
@@ -113,10 +176,15 @@ export const buildTypeChoices = ({
|
|
|
113
176
|
// Needed; Array/object ref somewhere could now be valid or invalid
|
|
114
177
|
Types.validateAllReferences({topRoot});
|
|
115
178
|
},
|
|
179
|
+
|
|
180
|
+
/** @type {AddTypeAndEditUI} */
|
|
116
181
|
$addTypeAndEditUI ({type, editUI}) {
|
|
117
182
|
this.$setTypeNoEditUI({type});
|
|
118
183
|
this.$addEditUI({editUI});
|
|
119
184
|
},
|
|
185
|
+
/**
|
|
186
|
+
* @type {(info: {editUI: Element}) => void}
|
|
187
|
+
*/
|
|
120
188
|
$addEditUI ({editUI}) {
|
|
121
189
|
const container = this.$getContainer();
|
|
122
190
|
DOM.removeChildren(container);
|
|
@@ -128,6 +196,9 @@ export const buildTypeChoices = ({
|
|
|
128
196
|
$getTopRoot () {
|
|
129
197
|
return topRoot || this.$getTypeRoot();
|
|
130
198
|
},
|
|
199
|
+
/**
|
|
200
|
+
* @returns {boolean}
|
|
201
|
+
*/
|
|
131
202
|
$validate () {
|
|
132
203
|
const {value: type} = this;
|
|
133
204
|
const container = this.$getContainer();
|
|
@@ -143,14 +214,16 @@ export const buildTypeChoices = ({
|
|
|
143
214
|
$on: {change (e) {
|
|
144
215
|
// We don't want form `onchange` to run `$checkForKeyDuplicates`
|
|
145
216
|
// again (through `addAndValidateEditUI`->`validateAllReferences`)
|
|
146
|
-
e
|
|
147
|
-
this.$addAndValidateEditUI();
|
|
148
|
-
this.$setStyles();
|
|
217
|
+
e?.stopPropagation();
|
|
218
|
+
/** @type {TypeChoicesElementAPI} */ (this).$addAndValidateEditUI();
|
|
219
|
+
/** @type {TypeChoicesElementAPI} */ (this).$setStyles();
|
|
149
220
|
}}
|
|
150
221
|
}, [
|
|
151
222
|
['option', {value: ''}, [
|
|
152
223
|
'(Choose a type)'
|
|
153
224
|
]],
|
|
225
|
+
// [string, {value: AvailableType; title?: string | undefined;}]
|
|
226
|
+
// @ts-ignore Apparent TS bug
|
|
154
227
|
...typeOptions.map(
|
|
155
228
|
([optText, optAtts]) => [
|
|
156
229
|
'option',
|
|
@@ -160,7 +233,7 @@ export const buildTypeChoices = ({
|
|
|
160
233
|
[optText]
|
|
161
234
|
]
|
|
162
235
|
)
|
|
163
|
-
]);
|
|
236
|
+
]));
|
|
164
237
|
if (setValue || (requireObject && !objectHasValue)) {
|
|
165
238
|
setTimeout(async () => {
|
|
166
239
|
if (!setValue) { // if (requireObject && !objectHasValue) {
|
|
@@ -179,8 +252,15 @@ export const buildTypeChoices = ({
|
|
|
179
252
|
schemaContent
|
|
180
253
|
}
|
|
181
254
|
);
|
|
182
|
-
const type =
|
|
183
|
-
|
|
255
|
+
const type = /** @type {string} */ (
|
|
256
|
+
Types.getTypeForRoot(/** @type {HTMLDivElement} */ (
|
|
257
|
+
rootEditUI
|
|
258
|
+
))
|
|
259
|
+
);
|
|
260
|
+
// eslint-disable-next-line max-len -- Long
|
|
261
|
+
/** @type {HTMLSelectElement & {$addTypeAndEditUI: AddTypeAndEditUI}} */ (
|
|
262
|
+
sel
|
|
263
|
+
).$addTypeAndEditUI({type, editUI: rootEditUI});
|
|
184
264
|
} catch (err) {
|
|
185
265
|
/* istanbul ignore next -- At least some errors handled earlier */
|
|
186
266
|
dialogs.alert({
|
|
@@ -193,7 +273,9 @@ export const buildTypeChoices = ({
|
|
|
193
273
|
});
|
|
194
274
|
}
|
|
195
275
|
|
|
196
|
-
const typeContainer =
|
|
276
|
+
const typeContainer = /** @type {HTMLDivElement} */ (
|
|
277
|
+
jml('div', {class: 'typeContainer'})
|
|
278
|
+
);
|
|
197
279
|
|
|
198
280
|
return {
|
|
199
281
|
domArray: [
|
|
@@ -201,49 +283,49 @@ export const buildTypeChoices = ({
|
|
|
201
283
|
typeContainer
|
|
202
284
|
],
|
|
203
285
|
|
|
204
|
-
/**
|
|
205
|
-
* @param {import('./types.js').StateObject} [stateObj] Will
|
|
206
|
-
* auto-set `typeNamespace` and `format`
|
|
207
|
-
* @param {string} [currentPath]
|
|
208
|
-
* @returns {StructuredCloneValue}
|
|
209
|
-
*/
|
|
286
|
+
/** @type {GetValue} */
|
|
210
287
|
getValue (stateObj, currentPath) {
|
|
211
|
-
const root =
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
288
|
+
const root = /** @type {HTMLDivElement} */ (
|
|
289
|
+
$e(typeContainer, 'div[data-type]')
|
|
290
|
+
);
|
|
291
|
+
return Types.getValueForRoot(
|
|
292
|
+
root,
|
|
293
|
+
/** @type {import('./types.js').StateObject} */ ({
|
|
294
|
+
typeNamespace,
|
|
295
|
+
format,
|
|
296
|
+
...stateObj
|
|
297
|
+
}), currentPath
|
|
298
|
+
);
|
|
217
299
|
},
|
|
218
300
|
|
|
219
|
-
/**
|
|
220
|
-
* @returns {string|undefined}
|
|
221
|
-
*/
|
|
301
|
+
/** @type {GetType} */
|
|
222
302
|
getType () {
|
|
223
|
-
const root =
|
|
303
|
+
const root = /** @type {HTMLDivElement} */ (
|
|
304
|
+
$e(typeContainer, 'div[data-type]')
|
|
305
|
+
);
|
|
224
306
|
return Types.getTypeForRoot(root);
|
|
225
307
|
},
|
|
226
308
|
|
|
227
|
-
/**
|
|
228
|
-
* @returns {boolean}
|
|
229
|
-
*/
|
|
309
|
+
/** @type {ValidValuesSet} */
|
|
230
310
|
validValuesSet () {
|
|
231
|
-
const root =
|
|
232
|
-
|
|
311
|
+
const root = /** @type {HTMLDivElement} */ (
|
|
312
|
+
$e(typeContainer, 'div[data-type]')
|
|
313
|
+
);
|
|
314
|
+
const form = /** @type {HTMLFormElement} */ (root.closest('form'));
|
|
233
315
|
return Types.validValuesSet({form, typeNamespace});
|
|
234
316
|
},
|
|
235
317
|
|
|
236
|
-
/**
|
|
237
|
-
* @param {StructuredCloneValue} value
|
|
238
|
-
* @param {import('./types.js').StateObject} stateObj
|
|
239
|
-
* @returns {Promise<void>}
|
|
240
|
-
*/
|
|
318
|
+
/** @type {SetValue} */
|
|
241
319
|
async setValue (value, stateObj) {
|
|
242
|
-
const rootEditUI =
|
|
243
|
-
|
|
320
|
+
const rootEditUI = /** @type {HTMLDivElement} */ (
|
|
321
|
+
await getControlsForFormatAndValue(
|
|
322
|
+
format, value, stateObj
|
|
323
|
+
)
|
|
244
324
|
);
|
|
245
|
-
const type = Types.getTypeForRoot(rootEditUI);
|
|
246
|
-
|
|
325
|
+
const type = /** @type {string} */ (Types.getTypeForRoot(rootEditUI));
|
|
326
|
+
/** @type {HTMLSelectElement & {$addTypeAndEditUI: AddTypeAndEditUI}} */ (
|
|
327
|
+
sel
|
|
328
|
+
).$addTypeAndEditUI({type, editUI: rootEditUI});
|
|
247
329
|
}
|
|
248
330
|
};
|
|
249
331
|
};
|