@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {jml} from '
|
|
1
|
+
import {jml} from './vendor-imports.js';
|
|
2
2
|
import {buildTypeChoices} from './typeChoices.js';
|
|
3
3
|
import Types from './types.js';
|
|
4
4
|
import {getControlsForFormatAndValue} from './formats.js';
|
|
@@ -16,7 +16,8 @@ import {$e, DOM} from './utils/templateUtils.js';
|
|
|
16
16
|
*/
|
|
17
17
|
export const getFormatAndSchemaChoices = ({schema, hasKeyPath} = {}) => {
|
|
18
18
|
const hasSchema = typeof schema === 'string';
|
|
19
|
-
|
|
19
|
+
// eslint-disable-next-line max-len -- Long
|
|
20
|
+
return /** @type {[optText: string, opts: {value: string, selected?: boolean}][]} */ ([
|
|
20
21
|
['JSON only', {value: 'json'}],
|
|
21
22
|
...(hasKeyPath
|
|
22
23
|
? []
|
|
@@ -48,14 +49,26 @@ export const getFormatAndSchemaChoices = ({schema, hasKeyPath} = {}) => {
|
|
|
48
49
|
'for structured cloning'
|
|
49
50
|
}]
|
|
50
51
|
*/
|
|
51
|
-
].map(([optText, optAtts]) => {
|
|
52
|
-
return
|
|
53
|
-
|
|
52
|
+
]).map(([optText, optAtts]) => {
|
|
53
|
+
return /** @type {HTMLOptionElement} */ (
|
|
54
|
+
jml('option', optAtts, [optText])
|
|
55
|
+
);
|
|
56
|
+
}).reduce((
|
|
57
|
+
frag,
|
|
58
|
+
option
|
|
59
|
+
) => {
|
|
54
60
|
frag.append(option);
|
|
55
61
|
return frag;
|
|
56
62
|
}, document.createDocumentFragment());
|
|
57
63
|
};
|
|
58
64
|
|
|
65
|
+
/**
|
|
66
|
+
* @callback SetValue
|
|
67
|
+
* @param {import('./formats.js').StructuredCloneValue} value
|
|
68
|
+
* @param {import('./types.js').StateObject} stateObj
|
|
69
|
+
* @returns {Promise<void>}
|
|
70
|
+
*/
|
|
71
|
+
|
|
59
72
|
/**
|
|
60
73
|
* Builds a selector and container for types.
|
|
61
74
|
* @param {object} cfg
|
|
@@ -77,9 +90,10 @@ export const getFormatAndSchemaChoices = ({schema, hasKeyPath} = {}) => {
|
|
|
77
90
|
* typesHolder: TypesHolder,
|
|
78
91
|
* domArray: [formatChoices: FormatChoices, typesHolder: TypesHolder],
|
|
79
92
|
* getValue: (stateObj: import('./types.js').StateObject,
|
|
80
|
-
* currentPath: string) => StructuredCloneValue,
|
|
81
|
-
* getType: () => string|undefined,
|
|
82
|
-
* validValuesSet: () => boolean
|
|
93
|
+
* currentPath: string) => import('./formats.js').StructuredCloneValue,
|
|
94
|
+
* getType: () => string|null|undefined,
|
|
95
|
+
* validValuesSet: () => boolean,
|
|
96
|
+
* setValue: SetValue
|
|
83
97
|
* }} The selector for types and the container for them. Both should be
|
|
84
98
|
* added to the page.
|
|
85
99
|
*/
|
|
@@ -92,7 +106,7 @@ export function formatAndTypeChoices ({
|
|
|
92
106
|
typeNamespace
|
|
93
107
|
}) {
|
|
94
108
|
const format = 'structuredCloning';
|
|
95
|
-
const formatChoices = jml('select', {
|
|
109
|
+
const formatChoices = /** @type {HTMLSelectElement} */ (jml('select', {
|
|
96
110
|
class: 'formatChoices',
|
|
97
111
|
hidden: singleValue,
|
|
98
112
|
// is: 'main-type-choices',
|
|
@@ -130,8 +144,10 @@ export function formatAndTypeChoices ({
|
|
|
130
144
|
$buildTypeChoices () {
|
|
131
145
|
DOM.removeChildren(typesHolder);
|
|
132
146
|
jml({'#': buildTypeChoices({
|
|
133
|
-
topRoot:
|
|
134
|
-
|
|
147
|
+
topRoot: /** @type {HTMLDivElement} */ (
|
|
148
|
+
$e(typesHolder, 'div[data-type]')
|
|
149
|
+
),
|
|
150
|
+
// resultType: 'both',
|
|
135
151
|
format: this.value,
|
|
136
152
|
typeNamespace,
|
|
137
153
|
requireObject: hasKeyPath,
|
|
@@ -142,18 +158,20 @@ export function formatAndTypeChoices ({
|
|
|
142
158
|
}
|
|
143
159
|
},
|
|
144
160
|
$on: {change () {
|
|
145
|
-
|
|
161
|
+
/** @type {Element & {$buildTypeChoices: TypeChoiceBuilder}} */ (
|
|
162
|
+
this
|
|
163
|
+
).$buildTypeChoices();
|
|
146
164
|
}}
|
|
147
|
-
}, [getFormatAndSchemaChoices({schema, hasKeyPath})]);
|
|
165
|
+
}, [getFormatAndSchemaChoices({schema, hasKeyPath})]));
|
|
148
166
|
|
|
149
167
|
/**
|
|
150
168
|
* @callback TypeRootGetter
|
|
151
|
-
* @returns {
|
|
169
|
+
* @returns {Element|null}
|
|
152
170
|
*/
|
|
153
171
|
|
|
154
172
|
/**
|
|
155
173
|
* @callback TypeSelectGetter
|
|
156
|
-
* @returns {
|
|
174
|
+
* @returns {HTMLSelectElement|null}
|
|
157
175
|
*/
|
|
158
176
|
|
|
159
177
|
/**
|
|
@@ -162,24 +180,30 @@ export function formatAndTypeChoices ({
|
|
|
162
180
|
* @property {TypeSelectGetter} $getTypeSelect
|
|
163
181
|
*/
|
|
164
182
|
|
|
165
|
-
const typesHolder =
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
183
|
+
const typesHolder = /** @type {HTMLDivElement} */ (
|
|
184
|
+
jml('div', {class: 'typesHolder', $custom: {
|
|
185
|
+
/**
|
|
186
|
+
* @type {TypeRootGetter}
|
|
187
|
+
* @this {Element}
|
|
188
|
+
*/
|
|
189
|
+
$getTypeRoot () {
|
|
190
|
+
return $e(this, 'div[data-type]');
|
|
191
|
+
},
|
|
192
|
+
/**
|
|
193
|
+
* @type {TypeSelectGetter}
|
|
194
|
+
* @this {HTMLSelectElement}
|
|
195
|
+
*/
|
|
196
|
+
$getTypeSelect () {
|
|
197
|
+
return /** @type {HTMLSelectElement} */ (
|
|
198
|
+
$e(this, `.typeChoices-${typeNamespace}`)
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
}})
|
|
202
|
+
);
|
|
179
203
|
|
|
180
204
|
jml({'#': buildTypeChoices({
|
|
181
|
-
resultType: 'both',
|
|
182
|
-
topRoot: $e(typesHolder, 'div[data-type]'),
|
|
205
|
+
// resultType: 'both',
|
|
206
|
+
topRoot: /** @type {HTMLDivElement} */ ($e(typesHolder, 'div[data-type]')),
|
|
183
207
|
format,
|
|
184
208
|
typeNamespace,
|
|
185
209
|
requireObject: hasKeyPath,
|
|
@@ -200,46 +224,67 @@ export function formatAndTypeChoices ({
|
|
|
200
224
|
* @param {import('./types.js').StateObject} [stateObj] Will
|
|
201
225
|
* auto-set `typeNamespace` and `format`
|
|
202
226
|
* @param {string} [currentPath]
|
|
203
|
-
* @returns {StructuredCloneValue}
|
|
227
|
+
* @returns {import('./formats.js').StructuredCloneValue}
|
|
204
228
|
*/
|
|
205
229
|
getValue (stateObj, currentPath) {
|
|
206
|
-
|
|
207
|
-
|
|
230
|
+
// eslint-disable-next-line max-len -- Long
|
|
231
|
+
const root = /** @type {HTMLDivElement & {$getTypeRoot: TypeRootGetter}} */ (
|
|
232
|
+
typesHolder
|
|
233
|
+
).$getTypeRoot();
|
|
234
|
+
return Types.getValueForRoot(/** @type {HTMLDivElement} */ (root), {
|
|
208
235
|
typeNamespace,
|
|
209
|
-
format:
|
|
236
|
+
format: /** @type {import('./formats.js').AvailableFormat} */ (
|
|
237
|
+
formatChoices.value
|
|
238
|
+
),
|
|
210
239
|
...stateObj
|
|
211
240
|
}, currentPath);
|
|
212
241
|
},
|
|
213
242
|
|
|
214
243
|
/**
|
|
215
|
-
* @returns {string|undefined}
|
|
244
|
+
* @returns {string|null|undefined}
|
|
216
245
|
*/
|
|
217
246
|
getType () {
|
|
218
|
-
|
|
219
|
-
|
|
247
|
+
// eslint-disable-next-line max-len -- Long
|
|
248
|
+
const root = /** @type {HTMLDivElement & {$getTypeRoot: TypeRootGetter}} */ (
|
|
249
|
+
typesHolder
|
|
250
|
+
).$getTypeRoot();
|
|
251
|
+
return Types.getTypeForRoot(/** @type {HTMLDivElement} */ (root));
|
|
220
252
|
},
|
|
221
253
|
|
|
222
254
|
/**
|
|
223
255
|
* @returns {boolean}
|
|
224
256
|
*/
|
|
225
257
|
validValuesSet () {
|
|
226
|
-
|
|
227
|
-
const
|
|
258
|
+
// eslint-disable-next-line max-len -- Long
|
|
259
|
+
const root = /** @type {HTMLDivElement & {$getTypeRoot: TypeRootGetter}} */ (
|
|
260
|
+
typesHolder
|
|
261
|
+
).$getTypeRoot();
|
|
262
|
+
const form = /** @type {HTMLFormElement} */ (
|
|
263
|
+
/** @type {Element} */ (root).closest('form')
|
|
264
|
+
);
|
|
228
265
|
return Types.validValuesSet({form, typeNamespace});
|
|
229
266
|
},
|
|
230
267
|
|
|
231
|
-
/**
|
|
232
|
-
* @param {StructuredCloneValue} value
|
|
233
|
-
* @param {import('./types.js').StateObject} stateObj
|
|
234
|
-
* @returns {Promise<void>}
|
|
235
|
-
*/
|
|
268
|
+
/** @type {SetValue} */
|
|
236
269
|
async setValue (value, stateObj) {
|
|
237
|
-
const rootEditUI =
|
|
238
|
-
|
|
270
|
+
const rootEditUI = /** @type {HTMLDivElement} */ (
|
|
271
|
+
await getControlsForFormatAndValue(
|
|
272
|
+
/** @type {import('./formats.js').AvailableFormat} */ (
|
|
273
|
+
formatChoices.value
|
|
274
|
+
),
|
|
275
|
+
value,
|
|
276
|
+
stateObj
|
|
277
|
+
)
|
|
239
278
|
);
|
|
240
|
-
const type = Types.getTypeForRoot(rootEditUI);
|
|
241
|
-
|
|
242
|
-
sel
|
|
279
|
+
const type = /** @type {string} */ (Types.getTypeForRoot(rootEditUI));
|
|
280
|
+
// eslint-disable-next-line max-len -- Long
|
|
281
|
+
const sel = /** @type {HTMLDivElement & {$getTypeSelect: TypeSelectGetter}} */ (
|
|
282
|
+
typesHolder
|
|
283
|
+
).$getTypeSelect();
|
|
284
|
+
// eslint-disable-next-line max-len -- Long
|
|
285
|
+
/** @type {HTMLSelectElement & {$addTypeAndEditUI: import('./typeChoices.js').AddTypeAndEditUI}} */ (
|
|
286
|
+
sel
|
|
287
|
+
).$addTypeAndEditUI({type, editUI: rootEditUI});
|
|
243
288
|
}
|
|
244
289
|
};
|
|
245
290
|
}
|
|
@@ -1,66 +1,59 @@
|
|
|
1
|
-
import
|
|
1
|
+
import structuredCloning from './structuredCloning.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// A hack until we simply pass in our own types or do own parsing
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @param {string} newType
|
|
15
|
-
* @param {Date|GenericArray} value
|
|
16
|
-
* @returns {boolean}
|
|
17
|
-
*/
|
|
18
|
-
export const testInvalid = (newType, value) => {
|
|
19
|
-
switch (newType) {
|
|
20
|
-
/* istanbul ignore next -- Shouldn't occur as it is a preset */
|
|
21
|
-
case 'Infinities':
|
|
3
|
+
/** @type {import('../formats.js').Format} */
|
|
4
|
+
const indexedDBKey = {
|
|
5
|
+
types: () => [
|
|
6
|
+
'number', 'SpecialRealNumber', 'string', 'ValidDate', 'array'
|
|
7
|
+
],
|
|
8
|
+
// A hack until we simply pass in our own types or do own parsing
|
|
9
|
+
testInvalid (newType, value) {
|
|
10
|
+
switch (newType) {
|
|
22
11
|
/* istanbul ignore next -- Shouldn't occur as it is a preset */
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
12
|
+
case 'SpecialRealNumber':
|
|
13
|
+
/* istanbul ignore next -- Shouldn't occur as it is a preset */
|
|
14
|
+
return Number.isNaN(value);
|
|
15
|
+
case 'ValidDate':
|
|
16
|
+
return Number.isNaN(/** @type {Date} */ (value).getTime());
|
|
17
|
+
case 'array':
|
|
18
|
+
return Object.keys(value).length !==
|
|
19
|
+
/** @type {Array<import('../formats.js').StructuredCloneValue>} */ (
|
|
20
|
+
value
|
|
21
|
+
).length;
|
|
30
22
|
/* istanbul ignore next -- Shouldn't occur */
|
|
23
|
+
default:
|
|
24
|
+
/* istanbul ignore next -- Shouldn't occur */
|
|
25
|
+
return false; // Todo: Should this throw?
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
convertFromTypeson (typesonType) {
|
|
29
|
+
return typesonToIndexedDBKey.get(typesonType);
|
|
30
|
+
},
|
|
31
|
+
iterate (records, stateObj) {
|
|
32
|
+
stateObj.format = 'indexedDBKey';
|
|
33
|
+
return structuredCloning.iterate(records, stateObj);
|
|
34
|
+
},
|
|
35
|
+
getTypesForState (state) {
|
|
36
|
+
if (!state || ['array'].includes(state)) {
|
|
37
|
+
return this.types();
|
|
38
|
+
}
|
|
39
|
+
/* istanbul ignore next -- Can't be object, so shouldn't reach here */
|
|
31
40
|
return undefined; // Todo: Should this throw?
|
|
32
41
|
}
|
|
33
42
|
};
|
|
34
43
|
|
|
35
|
-
|
|
36
|
-
* @param {string} typesonType
|
|
37
|
-
* @returns {string}
|
|
38
|
-
*/
|
|
39
|
-
export const convertFromTypeson = (typesonType) => {
|
|
40
|
-
return {
|
|
41
|
-
SpecialNumber: 'Infinities', // This shouldn't occur as it is a preset
|
|
42
|
-
date: 'ValidDate',
|
|
43
|
-
// sparseArrays: 'array',
|
|
44
|
-
arrayNonindexKeys: 'array'
|
|
45
|
-
}[typesonType];
|
|
46
|
-
};
|
|
44
|
+
// Todo (low): Support ArrayBuffer
|
|
47
45
|
|
|
48
46
|
/**
|
|
49
|
-
* @type {import('
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
* @type {Map<import('../types.js').AvailableType,
|
|
48
|
+
* import('../types.js').AvailableType>
|
|
49
|
+
* }
|
|
50
|
+
*/
|
|
51
|
+
const typesonToIndexedDBKey = new Map([
|
|
52
|
+
// This shouldn't occur as it is a preset
|
|
53
|
+
['SpecialNumber', 'SpecialRealNumber'],
|
|
54
|
+
['date', 'ValidDate'],
|
|
55
|
+
// 'sparseArrays', 'array',
|
|
56
|
+
['arrayNonindexKeys', 'array']
|
|
57
|
+
]);
|
|
55
58
|
|
|
56
|
-
|
|
57
|
-
* @param {"array"|undefined} state
|
|
58
|
-
* @returns {undefined|string[]}
|
|
59
|
-
*/
|
|
60
|
-
export const getTypesForState = function (state) {
|
|
61
|
-
if (!state || ['array'].includes(state)) {
|
|
62
|
-
return this.types();
|
|
63
|
-
}
|
|
64
|
-
/* istanbul ignore next -- Can't be object, so shouldn't reach here */
|
|
65
|
-
return undefined; // Todo: Should this throw?
|
|
66
|
-
};
|
|
59
|
+
export default indexedDBKey;
|
package/src/formats/json.js
CHANGED
|
@@ -1,64 +1,55 @@
|
|
|
1
|
-
import
|
|
1
|
+
import structuredCloning from './structuredCloning.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @
|
|
4
|
+
* @type {Map<import('../types.js').AvailableType,
|
|
5
|
+
* import('../types.js').AvailableType>
|
|
6
|
+
* }
|
|
5
7
|
*/
|
|
6
|
-
|
|
7
|
-
'
|
|
8
|
-
];
|
|
8
|
+
const typesonToJson = new Map([
|
|
9
|
+
['arrayNonindexKeys', 'array']
|
|
10
|
+
]);
|
|
9
11
|
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @param {string} newType
|
|
38
|
-
* @param {GenericArray} value
|
|
39
|
-
* @returns {boolean|undefined}
|
|
40
|
-
*/
|
|
41
|
-
export const testInvalid = (newType, value) => {
|
|
42
|
-
switch (newType) {
|
|
43
|
-
case 'array':
|
|
44
|
-
return Object.keys(value).length !== value.length;
|
|
45
|
-
/* istanbul ignore next -- Shouldn't occur */
|
|
46
|
-
default:
|
|
12
|
+
/** @type {import('../formats.js').Format} */
|
|
13
|
+
const json = {
|
|
14
|
+
types: () => [
|
|
15
|
+
'null', 'true', 'false', 'number', 'string', 'array', 'object'
|
|
16
|
+
],
|
|
17
|
+
iterate (records, stateObj) {
|
|
18
|
+
// Todo (low): Add a more optimal (`JSON.stringify`-based iterator)
|
|
19
|
+
const recs = records;
|
|
20
|
+
// I believe this escaping should be by Typeson itself
|
|
21
|
+
// if (records && typeof records === 'object' && records.$types) {
|
|
22
|
+
// recs = {$: records, $types: true};
|
|
23
|
+
// }
|
|
24
|
+
stateObj.format = 'json';
|
|
25
|
+
return structuredCloning.iterate(recs, stateObj);
|
|
26
|
+
},
|
|
27
|
+
// A hack until we simply pass in our own types or do own parsing
|
|
28
|
+
convertFromTypeson (typesonType) {
|
|
29
|
+
return typesonToJson.get(typesonType);
|
|
30
|
+
},
|
|
31
|
+
testInvalid (newType, value) {
|
|
32
|
+
switch (newType) {
|
|
33
|
+
case 'array':
|
|
34
|
+
return Object.keys(value).length !==
|
|
35
|
+
/** @type {Array<import('../formats.js').StructuredCloneValue>} */ (
|
|
36
|
+
value
|
|
37
|
+
).length;
|
|
47
38
|
/* istanbul ignore next -- Shouldn't occur */
|
|
48
|
-
|
|
39
|
+
default:
|
|
40
|
+
/* istanbul ignore next -- Shouldn't occur */
|
|
41
|
+
return undefined; // Todo: Fix?
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
getTypesForState (state) {
|
|
45
|
+
/* istanbul ignore else -- No other states apparently */
|
|
46
|
+
if (!state || ['array', 'object'].includes(state)) {
|
|
47
|
+
return this.types();
|
|
48
|
+
}
|
|
49
|
+
// Todo: Should this throw?
|
|
50
|
+
/* istanbul ignore next -- No other states apparently */
|
|
51
|
+
return undefined;
|
|
49
52
|
}
|
|
50
53
|
};
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
* @param {string} state
|
|
54
|
-
* @returns {string[]|undefined}
|
|
55
|
-
*/
|
|
56
|
-
export const getTypesForState = function (state) {
|
|
57
|
-
/* istanbul ignore else -- No other states apparently */
|
|
58
|
-
if (!state || ['array', 'object'].includes(state)) {
|
|
59
|
-
return this.types();
|
|
60
|
-
}
|
|
61
|
-
// Todo: Should this throw?
|
|
62
|
-
/* istanbul ignore next -- No other states apparently */
|
|
63
|
-
return undefined;
|
|
64
|
-
};
|
|
55
|
+
export default json;
|
|
@@ -3,10 +3,13 @@
|
|
|
3
3
|
sonarjs/no-empty-collection,
|
|
4
4
|
sonarjs/no-identical-conditions,
|
|
5
5
|
no-constant-binary-expression -- Just debugging */
|
|
6
|
-
import
|
|
6
|
+
import {getTypeForFormatStateAndValue} from '../formats.js';
|
|
7
7
|
import * as structuredCloning from './structuredCloning.js';
|
|
8
8
|
import deepEqual from '../deepEqual.js';
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {import('./formats.js').StructuredCloneValue} StructuredCloneValue
|
|
12
|
+
*/
|
|
10
13
|
/**
|
|
11
14
|
* @type {import('./structuredCloning.js').FormatIterator}
|
|
12
15
|
*/
|
|
@@ -31,11 +34,18 @@ export const iterate = (records, stateObj) => {
|
|
|
31
34
|
const resolveRef = (/* {schema, possibleSchemaObject} */) => {
|
|
32
35
|
// Todo?
|
|
33
36
|
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param {object} cfg
|
|
40
|
+
* @param {StructuredCloneValue[]} cfg.list
|
|
41
|
+
* @param {StructuredCloneValue} cfg.value
|
|
42
|
+
* @returns {boolean}
|
|
43
|
+
*/
|
|
34
44
|
const valueInEnumList = ({list, value}) => {
|
|
35
45
|
return list.some((en) => deepEqual(en, value));
|
|
36
46
|
};
|
|
37
47
|
const getTypesForValues = ({enumList}) => enumList.map(
|
|
38
|
-
(value) =>
|
|
48
|
+
(value) => getTypeForFormatStateAndValue({
|
|
39
49
|
value,
|
|
40
50
|
format: 'structuredCloning',
|
|
41
51
|
state: 'arrayNonindexKeys'
|