@es-joy/jsoe 0.5.0 → 0.6.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 +2 -0
- package/.eslintrc.cjs +2 -0
- package/.nyc_output/out.json +121296 -0
- package/CHANGES.md +10 -0
- package/README.md +47 -21
- package/cypress.config.ts +13 -0
- package/demo/index-instrumented.html +29 -0
- package/demo/index.html +10 -1
- package/demo/index.js +482 -126
- package/dist/formatAndTypeChoices.d.ts +10 -4
- package/dist/formatAndTypeChoices.d.ts.map +1 -1
- package/dist/formats/json.d.ts.map +1 -1
- package/dist/formats/structuredCloning.d.ts +2 -1
- package/dist/formats/structuredCloning.d.ts.map +1 -1
- package/dist/fundamentalTypes/arrayType.d.ts +6 -37
- package/dist/fundamentalTypes/arrayType.d.ts.map +1 -1
- package/dist/fundamentalTypes/dateType.d.ts.map +1 -1
- package/dist/fundamentalTypes/errorType.d.ts +6 -0
- package/dist/fundamentalTypes/errorType.d.ts.map +1 -0
- package/dist/fundamentalTypes/mapType.d.ts +6 -0
- package/dist/fundamentalTypes/mapType.d.ts.map +1 -0
- package/dist/fundamentalTypes/nullType.d.ts.map +1 -1
- package/dist/fundamentalTypes/objectReferenceType.d.ts.map +1 -1
- package/dist/fundamentalTypes/setType.d.ts +6 -0
- package/dist/fundamentalTypes/setType.d.ts.map +1 -0
- package/dist/fundamentalTypes/sparseUndefinedType.d.ts.map +1 -1
- package/dist/fundamentalTypes/undefinedType.d.ts.map +1 -1
- package/dist/subTypes/blobHTMLType.d.ts +12 -6
- package/dist/subTypes/blobHTMLType.d.ts.map +1 -1
- package/dist/superTypes/SpecialNumberType.d.ts +14 -0
- package/dist/superTypes/SpecialNumberType.d.ts.map +1 -0
- package/dist/superTypes/SpecialRealNumberType.d.ts +6 -0
- package/dist/superTypes/SpecialRealNumberType.d.ts.map +1 -0
- package/dist/superTypes/errorsSpecialType.d.ts +8 -0
- package/dist/superTypes/errorsSpecialType.d.ts.map +1 -0
- package/dist/typeChoices.d.ts +4 -2
- package/dist/typeChoices.d.ts.map +1 -1
- package/dist/types.d.ts +85 -233
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/dialogs.d.ts +22 -22
- package/dist/utils/dialogs.d.ts.map +1 -1
- package/dist/utils/templateUtils.d.ts +6 -6
- package/dist/utils/templateUtils.d.ts.map +1 -1
- package/dist/vendor-imports.d.ts +1 -1
- package/package.json +39 -34
- package/rollup.config.js +14 -2
- package/server.js +1 -1
- package/src/formatAndTypeChoices.js +14 -13
- package/src/formats/indexedDBKey.js +2 -2
- package/src/formats/json.js +1 -2
- package/src/formats/structuredCloning.js +104 -29
- package/src/formats.js +2 -2
- package/src/fundamentalTypes/arrayReferenceType.js +3 -3
- package/src/fundamentalTypes/arrayType.js +384 -79
- package/src/fundamentalTypes/dateType.js +4 -6
- package/src/fundamentalTypes/errorType.js +416 -0
- package/src/fundamentalTypes/mapType.js +34 -0
- package/src/fundamentalTypes/nullType.js +1 -2
- package/src/fundamentalTypes/objectReferenceType.js +2 -1
- package/src/fundamentalTypes/regexpType.js +2 -2
- package/src/fundamentalTypes/setType.js +34 -0
- package/src/fundamentalTypes/sparseUndefinedType.js +2 -3
- package/src/fundamentalTypes/undefinedType.js +2 -3
- package/src/jsoe.css +3 -0
- package/src/subTypes/blobHTMLType.js +37 -33
- package/src/subTypes/falseType.js +2 -2
- package/src/subTypes/trueType.js +2 -2
- package/src/superTypes/{SpecialNumberSuperType.js → SpecialNumberType.js} +1 -1
- package/src/superTypes/{SpecialRealNumberSuperType.js → SpecialRealNumberType.js} +3 -2
- package/src/superTypes/errorsSpecialType.js +768 -0
- package/src/typeChoices.js +27 -20
- package/src/types.js +72 -40
- package/src/utils/dialogs.js +11 -12
- package/src/utils/jsonPointer.js +3 -3
- package/src/utils/templateUtils.js +4 -4
- package/src/vendor-imports.js +2 -2
- package/tsconfig.json +1 -1
- package/typings/CypressPlugins.d.ts +10 -0
- package/vendor/jamilih/dist/jml-es.js +126 -106
- package/vendor/typeson-registry/dist/index.js +188 -44
package/demo/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {jml, body} from '../src/vendor-imports.js';
|
|
1
|
+
import {jml, body, $} from '../src/vendor-imports.js';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
typeChoices,
|
|
@@ -13,151 +13,507 @@ const keyPathNotExpectedTypeChoices = formatAndTypeChoices({
|
|
|
13
13
|
typeNamespace: 'demo-keypath-not-expected'
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
'
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
16
|
+
setTimeout(async function () {
|
|
17
|
+
jml('section', {role: 'main'}, [
|
|
18
|
+
['h1', [
|
|
19
|
+
'Jsoe testing'
|
|
20
|
+
]],
|
|
21
|
+
['h2', [
|
|
22
|
+
'Format and type choices: No key path expected (type can vary at root)'
|
|
23
|
+
]],
|
|
24
|
+
|
|
25
|
+
// Put inside form so can validate
|
|
26
|
+
['form', {id: 'formatAndTypeChoices'}, [
|
|
27
|
+
...keyPathNotExpectedTypeChoices.domArray
|
|
28
|
+
]],
|
|
29
|
+
|
|
30
|
+
['button', {
|
|
31
|
+
id: 'getType',
|
|
32
|
+
$on: {
|
|
33
|
+
click () {
|
|
34
|
+
// eslint-disable-next-line no-alert -- Simple demo
|
|
35
|
+
alert(keyPathNotExpectedTypeChoices.getType());
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}, ['Get type']],
|
|
39
|
+
|
|
40
|
+
['button', {
|
|
41
|
+
id: 'isValid',
|
|
42
|
+
$on: {
|
|
43
|
+
click () {
|
|
44
|
+
// eslint-disable-next-line no-alert -- Simple demo
|
|
45
|
+
alert(keyPathNotExpectedTypeChoices.validValuesSet());
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}, ['Is valid']],
|
|
49
|
+
|
|
50
|
+
['button', {
|
|
51
|
+
id: 'logValue',
|
|
52
|
+
$on: {
|
|
53
|
+
click () {
|
|
54
|
+
console.log(keyPathNotExpectedTypeChoices.getValue());
|
|
55
|
+
}
|
|
31
56
|
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
57
|
+
}, ['Log value']],
|
|
58
|
+
|
|
59
|
+
['button', {
|
|
60
|
+
id: 'viewUI',
|
|
61
|
+
$on: {
|
|
62
|
+
async click () {
|
|
63
|
+
const controls = await getControlsForFormatAndValue(
|
|
64
|
+
$('#useIndexedDBKey').checked
|
|
65
|
+
? 'indexedDBKey'
|
|
66
|
+
: 'structuredCloning',
|
|
67
|
+
keyPathNotExpectedTypeChoices.getValue(),
|
|
68
|
+
{
|
|
69
|
+
readonly: true
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
$('#viewUIResults').firstChild?.remove();
|
|
73
|
+
$('#viewUIResults').append(controls);
|
|
74
|
+
}
|
|
40
75
|
}
|
|
41
|
-
}
|
|
42
|
-
|
|
76
|
+
}, ['view UI']],
|
|
77
|
+
|
|
78
|
+
['div', {id: 'viewUIResults'}],
|
|
43
79
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
80
|
+
['button', {
|
|
81
|
+
id: 'initializeWithValue',
|
|
82
|
+
$on: {
|
|
83
|
+
async click () {
|
|
84
|
+
await keyPathNotExpectedTypeChoices.setValue(42);
|
|
85
|
+
}
|
|
48
86
|
}
|
|
49
|
-
}
|
|
50
|
-
}, ['Log value']],
|
|
87
|
+
}, ['Initialize with a value']],
|
|
51
88
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
89
|
+
['button', {
|
|
90
|
+
id: 'initializeWithComplexValue',
|
|
91
|
+
$on: {
|
|
92
|
+
async click () {
|
|
93
|
+
const a = {
|
|
94
|
+
bbb: {},
|
|
95
|
+
xxx: {yyy: []}
|
|
96
|
+
};
|
|
97
|
+
a.bbb.ccc = a;
|
|
98
|
+
a.zzz = a.xxx.yyy;
|
|
99
|
+
await keyPathNotExpectedTypeChoices.setValue(a);
|
|
100
|
+
}
|
|
56
101
|
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
'Format and type choices: Key path expected (object required at root)'
|
|
62
|
-
]],
|
|
63
|
-
...formatAndTypeChoices({
|
|
64
|
-
hasKeyPath: true,
|
|
65
|
-
typeNamespace: 'demo-keypath-expected'
|
|
66
|
-
}).domArray,
|
|
67
|
-
|
|
68
|
-
['h2', [
|
|
69
|
-
'Format choices without type selection ' +
|
|
70
|
-
'(might use as retrieval return format)'
|
|
71
|
-
]],
|
|
72
|
-
['select', [
|
|
73
|
-
getFormatAndSchemaChoices()
|
|
74
|
-
]],
|
|
75
|
-
|
|
76
|
-
['h2', [
|
|
77
|
-
'Type choices only'
|
|
78
|
-
]],
|
|
79
|
-
|
|
80
|
-
(() => {
|
|
81
|
-
const typeSelection = typeChoices({
|
|
82
|
-
format: 'structuredCloning',
|
|
83
|
-
typeNamespace: 'demo-type-choices-only'
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
return ['form', {
|
|
102
|
+
}, ['Initialize with a complex value']],
|
|
103
|
+
|
|
104
|
+
['button', {
|
|
105
|
+
id: 'programmaticallySetFormatToJSON',
|
|
87
106
|
$on: {
|
|
88
|
-
|
|
89
|
-
|
|
107
|
+
click () {
|
|
108
|
+
keyPathNotExpectedTypeChoices.formatChoices.$setFormat('json');
|
|
90
109
|
}
|
|
91
110
|
}
|
|
92
111
|
}, [
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
112
|
+
'Programmatically set format (to JSON)'
|
|
113
|
+
]],
|
|
114
|
+
|
|
115
|
+
['button', {
|
|
116
|
+
id: 'setCustomValidateAllReferences',
|
|
117
|
+
$on: {
|
|
118
|
+
click () {
|
|
119
|
+
Types.customValidateAllReferences = () => {
|
|
97
120
|
// eslint-disable-next-line no-alert -- Simple demo
|
|
98
|
-
alert(
|
|
99
|
-
}
|
|
121
|
+
alert('customValidateAllReferences set');
|
|
122
|
+
};
|
|
100
123
|
}
|
|
101
|
-
}
|
|
124
|
+
}
|
|
125
|
+
}, [
|
|
126
|
+
'Set custom all reference validation'
|
|
127
|
+
]],
|
|
128
|
+
|
|
129
|
+
['button', {
|
|
130
|
+
id: 'showRootFormControl',
|
|
131
|
+
$on: {
|
|
132
|
+
click () {
|
|
133
|
+
const root = $(
|
|
134
|
+
'#formatAndTypeChoices > .typesHolder > ' +
|
|
135
|
+
'.typeContainer > div[data-type]'
|
|
136
|
+
);
|
|
137
|
+
const formControl = Types.getFormControlForRoot(root);
|
|
138
|
+
formControl.style.backgroundColor = 'red';
|
|
139
|
+
setTimeout(() => {
|
|
140
|
+
formControl.style.backgroundColor = 'white';
|
|
141
|
+
}, 3000);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}, ['Show root form control']],
|
|
145
|
+
|
|
146
|
+
['button', {
|
|
147
|
+
id: 'getValueFromRootAncestor',
|
|
148
|
+
$on: {
|
|
149
|
+
click () {
|
|
150
|
+
const val = Types.getValueFromRootAncestor(
|
|
151
|
+
'#formatAndTypeChoices > .typesHolder > ' +
|
|
152
|
+
'.typeContainer'
|
|
153
|
+
);
|
|
154
|
+
console.log(val);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}, [
|
|
158
|
+
'Get value from root ancestor'
|
|
159
|
+
]],
|
|
160
|
+
|
|
161
|
+
['button', {
|
|
162
|
+
id: 'showFormControlFromRootAncestor',
|
|
163
|
+
$on: {
|
|
164
|
+
click () {
|
|
165
|
+
const formControl = Types.getFormControlFromRootAncestor(
|
|
166
|
+
'#formatAndTypeChoices > .typesHolder > ' +
|
|
167
|
+
'.typeContainer'
|
|
168
|
+
);
|
|
169
|
+
formControl.style.backgroundColor = 'red';
|
|
170
|
+
setTimeout(() => {
|
|
171
|
+
formControl.style.backgroundColor = 'initial';
|
|
172
|
+
}, 3000);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}, [
|
|
176
|
+
'Show form control from root ancestor'
|
|
177
|
+
]],
|
|
178
|
+
|
|
179
|
+
['h2', [
|
|
180
|
+
'Format and type choices: Key path expected (object required at root)'
|
|
181
|
+
]],
|
|
182
|
+
...formatAndTypeChoices({
|
|
183
|
+
hasKeyPath: true,
|
|
184
|
+
typeNamespace: 'demo-keypath-expected'
|
|
185
|
+
}).domArray,
|
|
186
|
+
|
|
187
|
+
['h2', [
|
|
188
|
+
'Format choices without type selection ' +
|
|
189
|
+
'(might use as retrieval return format)'
|
|
190
|
+
]],
|
|
191
|
+
['select', {id: 'formatAndSchemaChoices'}, [
|
|
192
|
+
getFormatAndSchemaChoices()
|
|
193
|
+
]],
|
|
102
194
|
|
|
103
|
-
|
|
195
|
+
['h2', [
|
|
196
|
+
'Type choices only'
|
|
197
|
+
]],
|
|
198
|
+
|
|
199
|
+
(() => {
|
|
200
|
+
const typeSelection = typeChoices({
|
|
201
|
+
format: 'structuredCloning',
|
|
202
|
+
typeNamespace: 'demo-type-choices-only'
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
return ['form', {
|
|
206
|
+
id: 'typeChoicesOnly',
|
|
104
207
|
$on: {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
alert(typeSelection.validValuesSet());
|
|
208
|
+
submit (e) {
|
|
209
|
+
e.preventDefault();
|
|
108
210
|
}
|
|
109
211
|
}
|
|
110
|
-
}, [
|
|
212
|
+
}, [
|
|
213
|
+
...typeSelection.domArray,
|
|
214
|
+
['button', {
|
|
215
|
+
id: 'typeChoicesOnly-getType',
|
|
216
|
+
$on: {
|
|
217
|
+
click () {
|
|
218
|
+
// eslint-disable-next-line no-alert -- Simple demo
|
|
219
|
+
alert(typeSelection.getType());
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}, ['Get type']],
|
|
111
223
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
224
|
+
['button', {
|
|
225
|
+
id: 'typeChoicesOnly-isValid',
|
|
226
|
+
$on: {
|
|
227
|
+
click () {
|
|
228
|
+
// eslint-disable-next-line no-alert -- Simple demo
|
|
229
|
+
alert(typeSelection.validValuesSet());
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}, ['Is valid']],
|
|
233
|
+
|
|
234
|
+
['button', {
|
|
235
|
+
id: 'validateInitialType',
|
|
236
|
+
$on: {
|
|
237
|
+
click () {
|
|
238
|
+
// eslint-disable-next-line no-alert -- Simple demo
|
|
239
|
+
alert(typeSelection.domArray[0].$validate());
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}, [
|
|
243
|
+
'Validate initial type'
|
|
244
|
+
]],
|
|
245
|
+
|
|
246
|
+
['button', {
|
|
247
|
+
id: 'typeChoicesOnly-logValue',
|
|
248
|
+
$on: {
|
|
249
|
+
click () {
|
|
250
|
+
console.log(typeSelection.getValue());
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}, ['Log value']],
|
|
254
|
+
|
|
255
|
+
['button', {
|
|
256
|
+
id: 'typeChoicesOnly-initializeWithValue',
|
|
257
|
+
$on: {
|
|
258
|
+
async click () {
|
|
259
|
+
await typeSelection.setValue(42);
|
|
260
|
+
}
|
|
116
261
|
}
|
|
262
|
+
}, ['Initialize with a value']]
|
|
263
|
+
]];
|
|
264
|
+
})(),
|
|
265
|
+
|
|
266
|
+
['h2', [
|
|
267
|
+
'Type choices with initial value set'
|
|
268
|
+
]],
|
|
269
|
+
|
|
270
|
+
(() => {
|
|
271
|
+
const badDate = new Date('Bad date');
|
|
272
|
+
const cause = new Error('some cause');
|
|
273
|
+
const error = new Error('msg');
|
|
274
|
+
error.cause = cause;
|
|
275
|
+
|
|
276
|
+
// eslint-disable-next-line unicorn/error-message -- Testing empty
|
|
277
|
+
const error2 = new Error();
|
|
278
|
+
error2.message = undefined; // Needed to force (at least in Chrome)
|
|
279
|
+
error2.fileName = 'abc';
|
|
280
|
+
error2.name = undefined;
|
|
281
|
+
error2.stack = undefined;
|
|
282
|
+
error2.lineNumber = 10;
|
|
283
|
+
error2.columnNumber = 20;
|
|
284
|
+
|
|
285
|
+
const typeError = new TypeError('msg');
|
|
286
|
+
const typeCause = new RangeError('some cause');
|
|
287
|
+
typeError.cause = typeCause;
|
|
288
|
+
|
|
289
|
+
// eslint-disable-next-line unicorn/error-message -- Testing empty
|
|
290
|
+
const error3 = new TypeError();
|
|
291
|
+
error3.message = undefined; // Needed to force (at least in Chrome)
|
|
292
|
+
error3.fileName = 'abc';
|
|
293
|
+
error3.name = undefined;
|
|
294
|
+
error3.stack = undefined;
|
|
295
|
+
error3.lineNumber = 10;
|
|
296
|
+
error3.columnNumber = 20;
|
|
297
|
+
|
|
298
|
+
const aggregate1 = new RangeError('agg err1');
|
|
299
|
+
const aggregate2 = new TypeError('agg err2');
|
|
300
|
+
const aggregate3 = new Error('agg err3');
|
|
301
|
+
const errAggregate = new AggregateError(
|
|
302
|
+
[aggregate1, aggregate2, aggregate3], 'agg msg'
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
const typeSelection = typeChoices({
|
|
306
|
+
format: 'structuredCloning',
|
|
307
|
+
setValue: true,
|
|
308
|
+
value: [
|
|
309
|
+
42, 123n, 'test123', new Date('1999-01-01'), badDate,
|
|
310
|
+
// eslint-disable-next-line require-unicode-regexp -- Testing
|
|
311
|
+
/.*?/,
|
|
312
|
+
// eslint-disable-next-line @stylistic/max-len -- Long
|
|
313
|
+
// eslint-disable-next-line no-new-wrappers, unicorn/new-for-builtins -- Testing
|
|
314
|
+
new Boolean(false),
|
|
315
|
+
// eslint-disable-next-line @stylistic/max-len -- Long
|
|
316
|
+
// eslint-disable-next-line no-new-wrappers, unicorn/new-for-builtins -- Testing
|
|
317
|
+
new Boolean(true),
|
|
318
|
+
// eslint-disable-next-line @stylistic/max-len -- Long
|
|
319
|
+
// eslint-disable-next-line no-new-wrappers, unicorn/new-for-builtins -- Testing
|
|
320
|
+
new Number(42),
|
|
321
|
+
// eslint-disable-next-line @stylistic/max-len -- Long
|
|
322
|
+
// eslint-disable-next-line no-new-wrappers, unicorn/new-for-builtins -- Testing
|
|
323
|
+
new String('test123'),
|
|
324
|
+
Number.NaN,
|
|
325
|
+
-0,
|
|
326
|
+
new Blob(['<b>Testing</b>'], {type: 'text/html'}),
|
|
327
|
+
new Map([
|
|
328
|
+
[null, 3],
|
|
329
|
+
[true, new Map([[false, 5]])],
|
|
330
|
+
[new Map([[6, 4]]), 7]
|
|
331
|
+
]),
|
|
332
|
+
error,
|
|
333
|
+
error2,
|
|
334
|
+
error3,
|
|
335
|
+
typeError,
|
|
336
|
+
errAggregate
|
|
337
|
+
],
|
|
338
|
+
typeNamespace: 'demo-type-choices-only-initial-value'
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
const typeSelectionBlob = typeChoices({
|
|
342
|
+
format: 'structuredCloning',
|
|
343
|
+
setValue: true,
|
|
344
|
+
value: new Blob(['<b>Testing</b>'], {type: 'text/html'}),
|
|
345
|
+
typeNamespace: 'demo-type-choices-only-initial-value'
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
const error4 = new Error('msg2');
|
|
349
|
+
const cause4 = new Error('some cause2');
|
|
350
|
+
error4.cause = cause4;
|
|
351
|
+
const typeSelectionErrorWithCause = typeChoices({
|
|
352
|
+
format: 'structuredCloning',
|
|
353
|
+
setValue: true,
|
|
354
|
+
value: error4,
|
|
355
|
+
typeNamespace: 'demo-type-choices-only-initial-value-ErrorCause'
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
const error5 = new TypeError('msg2');
|
|
359
|
+
const cause5 = new RangeError('some cause2');
|
|
360
|
+
error5.cause = cause5;
|
|
361
|
+
const typeSelectionTypeErrorWithCause = typeChoices({
|
|
362
|
+
format: 'structuredCloning',
|
|
363
|
+
setValue: true,
|
|
364
|
+
value: error5,
|
|
365
|
+
typeNamespace: 'demo-type-choices-only-initial-value-ErrorsCause'
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
const typeSelectionIndexedDBKey = typeChoices({
|
|
369
|
+
format: 'indexedDBKey',
|
|
370
|
+
setValue: true,
|
|
371
|
+
value: [-0, Number.NEGATIVE_INFINITY],
|
|
372
|
+
typeNamespace: 'demo-type-choices-only-initial-value',
|
|
373
|
+
keySelectClass: 'only-initial'
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
const agg1 = new RangeError('some err1');
|
|
377
|
+
const agg2 = new TypeError('some err2');
|
|
378
|
+
const agg3 = new Error('some err3');
|
|
379
|
+
const errorAggregate = new AggregateError([agg1, agg2, agg3], 'msg2');
|
|
380
|
+
errorAggregate.stack = undefined; // For coverage
|
|
381
|
+
const typeSelectionTypeErrorWithAggregate = typeChoices({
|
|
382
|
+
format: 'structuredCloning',
|
|
383
|
+
setValue: true,
|
|
384
|
+
value: errorAggregate,
|
|
385
|
+
typeNamespace: 'demo-type-choices-only-initial-value-ErrorsAggregate'
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
return ['form', [
|
|
389
|
+
...typeSelection.domArray,
|
|
390
|
+
...typeSelectionBlob.domArray,
|
|
391
|
+
...typeSelectionErrorWithCause.domArray,
|
|
392
|
+
...typeSelectionIndexedDBKey.domArray,
|
|
393
|
+
...typeSelectionTypeErrorWithCause.domArray,
|
|
394
|
+
...typeSelectionTypeErrorWithAggregate.domArray
|
|
395
|
+
]];
|
|
396
|
+
})(),
|
|
397
|
+
|
|
398
|
+
['button', {
|
|
399
|
+
id: 'validValuesSet',
|
|
400
|
+
$on: {
|
|
401
|
+
click () {
|
|
402
|
+
// eslint-disable-next-line no-alert -- Simple demo
|
|
403
|
+
alert(Types.validValuesSet({
|
|
404
|
+
form: this.previousElementSibling,
|
|
405
|
+
typeNamespace: 'demo-type-choices-only-initial-value',
|
|
406
|
+
keySelectClass: 'only-initial'
|
|
407
|
+
}));
|
|
117
408
|
}
|
|
118
|
-
}
|
|
409
|
+
}
|
|
410
|
+
}, [
|
|
411
|
+
'Valid values set?'
|
|
412
|
+
]],
|
|
413
|
+
|
|
414
|
+
['h2', [
|
|
415
|
+
'Convert arbitrary value to an editable menu'
|
|
416
|
+
]],
|
|
417
|
+
|
|
418
|
+
await getControlsForFormatAndValue(
|
|
419
|
+
'structuredCloning', new Date('1999-01-01')
|
|
420
|
+
),
|
|
119
421
|
|
|
120
|
-
|
|
422
|
+
['h2', [
|
|
423
|
+
'Convert arbitrary value to a readonly menu'
|
|
424
|
+
]],
|
|
425
|
+
|
|
426
|
+
await getControlsForFormatAndValue(
|
|
427
|
+
'structuredCloning',
|
|
428
|
+
new Date('1999-01-01'), {
|
|
429
|
+
readonly: true
|
|
430
|
+
}
|
|
431
|
+
),
|
|
432
|
+
|
|
433
|
+
['h2', [
|
|
434
|
+
'Convert structured cloning string representation to value and log'
|
|
435
|
+
]],
|
|
436
|
+
['input', {
|
|
437
|
+
id: 'getValueForString',
|
|
438
|
+
placeholder: 'e.g., ["abc", 17]',
|
|
439
|
+
$on: {
|
|
440
|
+
change () {
|
|
441
|
+
const value = Types.getValueForString(this.value, {
|
|
442
|
+
format: $('#useIndexedDBKey').checked
|
|
443
|
+
? 'indexedDBKey'
|
|
444
|
+
: 'structuredCloning'
|
|
445
|
+
})[0];
|
|
446
|
+
console.log(value);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}],
|
|
450
|
+
|
|
451
|
+
(() => {
|
|
452
|
+
return ['form', {
|
|
121
453
|
$on: {
|
|
122
|
-
|
|
123
|
-
|
|
454
|
+
submit (e) {
|
|
455
|
+
e.preventDefault();
|
|
124
456
|
}
|
|
125
457
|
}
|
|
126
|
-
}, [
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
458
|
+
}, [
|
|
459
|
+
['button', {
|
|
460
|
+
id: 'attemptBadIndexedDBKey',
|
|
461
|
+
$on: {
|
|
462
|
+
click () {
|
|
463
|
+
const badDate = new Date('Bad date');
|
|
464
|
+
typeChoices({
|
|
465
|
+
format: 'indexedDBKey',
|
|
466
|
+
setValue: true,
|
|
467
|
+
value: [badDate],
|
|
468
|
+
typeNamespace: 'demo-type-choices-only-initial-value'
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}, [
|
|
473
|
+
'Attempt bad indexedDBKey (invalid Date)'
|
|
474
|
+
]],
|
|
475
|
+
['button', {
|
|
476
|
+
id: 'attemptBadIndexedDBKeyStringObject',
|
|
477
|
+
$on: {
|
|
478
|
+
click () {
|
|
479
|
+
typeChoices({
|
|
480
|
+
format: 'indexedDBKey',
|
|
481
|
+
setValue: true,
|
|
482
|
+
// eslint-disable-next-line @stylistic/max-len -- Long
|
|
483
|
+
// eslint-disable-next-line no-new-wrappers, unicorn/new-for-builtins -- Testing
|
|
484
|
+
value: [new String('Bad value')],
|
|
485
|
+
typeNamespace: 'demo-type-choices-only-initial-value'
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}, [
|
|
490
|
+
'Attempt bad indexedDBKey (String object)'
|
|
491
|
+
]],
|
|
492
|
+
['button', {
|
|
493
|
+
id: 'attemptBadJSON',
|
|
494
|
+
$on: {
|
|
495
|
+
click () {
|
|
496
|
+
typeChoices({
|
|
497
|
+
format: 'json',
|
|
498
|
+
setValue: true,
|
|
499
|
+
// eslint-disable-next-line no-sparse-arrays -- Testing
|
|
500
|
+
value: [,],
|
|
501
|
+
typeNamespace: 'demo-type-choices-only-initial-value'
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}, [
|
|
506
|
+
'Attempt bad JSON (sparse array)'
|
|
507
|
+
]]
|
|
508
|
+
]];
|
|
509
|
+
})(),
|
|
510
|
+
|
|
511
|
+
['label', [
|
|
512
|
+
'Use indexedDBKey (valid dates only)',
|
|
513
|
+
['input', {
|
|
514
|
+
id: 'useIndexedDBKey',
|
|
515
|
+
type: 'checkbox'
|
|
516
|
+
}]
|
|
517
|
+
]]
|
|
518
|
+
], body);
|
|
519
|
+
}, 500);
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* domArray: [formatChoices: FormatChoices, typesHolder: TypesHolder],
|
|
27
27
|
* getValue: (stateObj: import('./types.js').StateObject,
|
|
28
28
|
* currentPath: string) => import('./formats.js').StructuredCloneValue,
|
|
29
|
-
* getType: () => string
|
|
29
|
+
* getType: () => string,
|
|
30
30
|
* validValuesSet: () => boolean,
|
|
31
31
|
* setValue: SetValue
|
|
32
32
|
* }} The selector for types and the container for them. Both should be
|
|
@@ -40,11 +40,17 @@ export function formatAndTypeChoices({ schema, schemaContent, hasValue, singleVa
|
|
|
40
40
|
hasKeyPath?: boolean | undefined;
|
|
41
41
|
typeNamespace?: string | undefined;
|
|
42
42
|
}): {
|
|
43
|
-
formatChoices: HTMLSelectElement
|
|
43
|
+
formatChoices: HTMLSelectElement & {
|
|
44
|
+
$setFormat: (valueFormat: string) => void;
|
|
45
|
+
$buildTypeChoices: () => void;
|
|
46
|
+
};
|
|
44
47
|
typesHolder: HTMLDivElement;
|
|
45
|
-
domArray: [formatChoices: HTMLSelectElement
|
|
48
|
+
domArray: [formatChoices: HTMLSelectElement & {
|
|
49
|
+
$setFormat: (valueFormat: string) => void;
|
|
50
|
+
$buildTypeChoices: () => void;
|
|
51
|
+
}, typesHolder: HTMLDivElement];
|
|
46
52
|
getValue: (stateObj: import('./types.js').StateObject, currentPath: string) => import('./formats.js').StructuredCloneValue;
|
|
47
|
-
getType: () => string
|
|
53
|
+
getType: () => string;
|
|
48
54
|
validValuesSet: () => boolean;
|
|
49
55
|
setValue: SetValue;
|
|
50
56
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatAndTypeChoices.d.ts","sourceRoot":"","sources":["../src/formatAndTypeChoices.js"],"names":[],"mappings":"AAqEA;;;;;GAKG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH;IAzBwB,MAAM;IACN,aAAa;IACZ,QAAQ;IAGR,WAAW;IACX,UAAU;IAKX,aAAa
|
|
1
|
+
{"version":3,"file":"formatAndTypeChoices.d.ts","sourceRoot":"","sources":["../src/formatAndTypeChoices.js"],"names":[],"mappings":"AAqEA;;;;;GAKG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH;IAzBwB,MAAM;IACN,aAAa;IACZ,QAAQ;IAGR,WAAW;IACX,UAAU;IAKX,aAAa;;;kCA+BpB,MAAM,KACJ,IAAI;iCAMJ,IAAI;;;;kCAPN,MAAM,KACJ,IAAI;iCAMJ,IAAI;;yBAhCG,OAAO,YAAY,EAAE,WAAW,eACtC,MAAM,KAAK,OAAO,cAAc,EAAE,oBAAoB;aAC5D,MAAM,MAAM;oBACL,MAAM,OAAO;cACnB,QAAQ;EA8LtB;AA7QM;IANiB,MAAM;IACL,UAAU;IAGtB,gBAAgB,CAgD5B;+BAIU,OAAO,cAAc,EAAE,oBAAoB,YAC3C,OAAO,YAAY,EAAE,WAAW,KAC9B,QAAQ,IAAI,CAAC;mCAjEb,cAAc,GAAC,IAAI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/formats/json.js"],"names":[],"mappings":";AAWA,6CAA6C;AAC7C,oBADW,OAAO,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/formats/json.js"],"names":[],"mappings":";AAWA,6CAA6C;AAC7C,oBADW,OAAO,eAAe,EAAE,MAAM,CAwCvC"}
|
|
@@ -4,9 +4,10 @@ export type AddAndSetArrayElement = (info: {
|
|
|
4
4
|
type: import('../types.js').AvailableType;
|
|
5
5
|
value: import('../formats.js').StructuredCloneValue;
|
|
6
6
|
bringIntoFocus?: boolean;
|
|
7
|
+
setAValue?: boolean;
|
|
7
8
|
schemaContent?: object;
|
|
8
9
|
schemaState?: import('../types.js').GetPossibleSchemasForPathAndType;
|
|
9
|
-
}) => HTMLElement;
|
|
10
|
+
}) => HTMLElement | null;
|
|
10
11
|
export type EncapsulateObserver = import('typeson-registry').EncapsulateObserver;
|
|
11
12
|
export type FormatIterator = (records: import('../formats.js').StructuredCloneValue, stateObj: import('../types.js').StateObject) => Promise<Element>;
|
|
12
13
|
/**
|