@es-joy/jsoe 0.3.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 +1 -0
- package/.ncurc.cjs +9 -0
- package/CHANGES.md +4 -0
- 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 +16 -11
- package/postorder-traversal.js +58 -0
- package/src/formatAndTypeChoices.js +95 -50
- package/src/formats/indexedDBKey.js +49 -57
- 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/subTypes/blobHTMLType.js +42 -22
- package/src/subTypes/falseType.js +2 -2
- package/src/subTypes/trueType.js +2 -2
- package/src/superTypes/SpecialNumberSuperType.js +13 -6
- package/src/superTypes/SpecialRealNumberSuperType.js +11 -5
- package/src/typeChoices.js +137 -55
- package/src/types.js +309 -146
- 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 +365 -83
package/src/types.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {jml} from '../vendor/jamilih/dist/jml-es.js';
|
|
2
1
|
import {
|
|
2
|
+
// jamilih
|
|
3
|
+
jml,
|
|
4
|
+
// typeson-registry
|
|
3
5
|
Typeson, getJSONType, structuredCloningThrowing
|
|
4
|
-
} from '
|
|
6
|
+
} from './vendor-imports.js';
|
|
5
7
|
|
|
6
8
|
import Formats from './formats.js';
|
|
7
9
|
|
|
@@ -36,64 +38,118 @@ import SpecialNumberSuperType from './superTypes/SpecialNumberSuperType.js';
|
|
|
36
38
|
*/
|
|
37
39
|
export const getPropertyValueFromLegend = (legend) => {
|
|
38
40
|
const propElem = $e(legend, '*[data-prop="true"]');
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
if (!propElem) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
'No property on the supplied legend element'
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
if (propElem.nodeName.toLowerCase() === 'input') {
|
|
47
|
+
return /** @type {HTMLInputElement} */ (propElem).value;
|
|
48
|
+
}
|
|
49
|
+
if (!propElem.textContent) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
'No property with text present on the supplied legend element'
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
// 1-based to 0-based
|
|
55
|
+
return String(Number.parseInt(propElem.textContent) - 1);
|
|
42
56
|
};
|
|
43
57
|
|
|
44
58
|
const Types = {};
|
|
45
59
|
|
|
60
|
+
/**
|
|
61
|
+
* @typedef {import('./formats.js').StructuredCloneValue} StructuredCloneValue
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @typedef {import('jamilih').JamilihArray} JamilihArray
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @typedef {{
|
|
70
|
+
* format: import('./formats.js').AvailableFormat,
|
|
71
|
+
* endMatchTypeObjs: TypeObject[],
|
|
72
|
+
* remnant: string,
|
|
73
|
+
* rootHolder: [
|
|
74
|
+
* type: string, parent: object, parentPath: string|number, path: string
|
|
75
|
+
* ][],
|
|
76
|
+
* parent: object,
|
|
77
|
+
* parentPath: string|number
|
|
78
|
+
* }} RootInfo
|
|
79
|
+
*/
|
|
80
|
+
|
|
46
81
|
/**
|
|
47
82
|
* @typedef {object} TypeObject
|
|
48
|
-
* @property {
|
|
49
|
-
*
|
|
83
|
+
* @property {[
|
|
84
|
+
* string, {value?: AvailableType, title?: string}?
|
|
85
|
+
* ]} option Creates the option HTML. May set an option `title` or `value`
|
|
50
86
|
* @property {boolean} [array] Private context variable. Whether or not
|
|
51
87
|
* it is an array. Do not use in other types.
|
|
52
88
|
* @property {string[]} [regexEndings] Used for string parsing.
|
|
53
|
-
* @property {RegExp} [stringRegex] Used
|
|
54
|
-
* present, use `stringRegexBegin` and
|
|
89
|
+
* @property {RegExp|((nonGrouping?: boolean) => RegExp)} [stringRegex] Used
|
|
90
|
+
* for string parsing. If not present, use `stringRegexBegin` and
|
|
91
|
+
* `stringRegexEnd`.
|
|
55
92
|
* @property {RegExp} [stringRegexBegin] Used for string parsing. If not
|
|
56
93
|
* present, use `stringRegex`
|
|
57
94
|
* @property {RegExp} [stringRegexEnd] Used for string parsing. If not
|
|
58
95
|
* present, use `stringRegex`
|
|
59
|
-
* @property {(
|
|
96
|
+
* @property {(v: StructuredCloneValue) => boolean} [valueMatch] Function to
|
|
60
97
|
* check whether this subtype matches
|
|
61
98
|
* @property {string} [superType] The greater fundamental type to which
|
|
62
99
|
* the type belongs
|
|
63
|
-
* @property {(
|
|
64
|
-
* string
|
|
65
|
-
*
|
|
66
|
-
*
|
|
100
|
+
* @property {(
|
|
101
|
+
* s: string, info?: RootInfo
|
|
102
|
+
* ) => StructuredCloneValue} toValue Converts from string to value. May use
|
|
103
|
+
* `stringRegex` to find components.
|
|
104
|
+
* @property {(info: {
|
|
105
|
+
* root: HTMLDivElement,
|
|
106
|
+
* stateObj?: StateObject,
|
|
107
|
+
* currentPath?: string
|
|
108
|
+
* }) =>
|
|
109
|
+
* StructuredCloneValue
|
|
67
110
|
* } getValue Gets the value for the type
|
|
68
|
-
* @property {(
|
|
69
|
-
*
|
|
111
|
+
* @property {(
|
|
112
|
+
* info: {
|
|
113
|
+
* root: HTMLDivElement,
|
|
114
|
+
* value: StructuredCloneValue
|
|
115
|
+
* }
|
|
116
|
+
* ) => void} [setValue] Should set the value of the form's `getInput` element
|
|
70
117
|
* @property {(info: {
|
|
71
|
-
* value?:
|
|
118
|
+
* value?: StructuredCloneValue,
|
|
72
119
|
* typeNamespace?: string,
|
|
73
|
-
* type?:
|
|
120
|
+
* type?: AvailableType,
|
|
74
121
|
* topRoot?: HTMLDivElement,
|
|
75
122
|
* resultType?: "keys"|"values"|"both",
|
|
76
|
-
* format
|
|
123
|
+
* format: import('./formats.js').AvailableFormat
|
|
77
124
|
* }) => JamilihArray} viewUI
|
|
78
125
|
* @property {(info: {
|
|
79
|
-
* value?:
|
|
126
|
+
* value?: StructuredCloneValue,
|
|
80
127
|
* typeNamespace?: string,
|
|
128
|
+
* bringIntoFocus?: boolean,
|
|
129
|
+
* format?: import('./formats.js').AvailableFormat,
|
|
130
|
+
* resultType?: "keys"|"values"|"both",
|
|
131
|
+
* type?: AvailableType,
|
|
132
|
+
* buildTypeChoices?: import('./typeChoices.js').BuildTypeChoices,
|
|
133
|
+
* topRoot?: HTMLDivElement
|
|
81
134
|
* }) => JamilihArray} editUI
|
|
82
135
|
* @property {(info: {root: HTMLDivElement}) =>
|
|
83
|
-
* HTMLInputElement|
|
|
84
|
-
* form control (with `value`)
|
|
85
|
-
* @property {(
|
|
86
|
-
*
|
|
87
|
-
*
|
|
136
|
+
* HTMLInputElement|HTMLTextAreaElement|HTMLSelectElement|
|
|
137
|
+
* HTMLButtonElement} getInput Gets the form control (with `value`)
|
|
138
|
+
* @property {(
|
|
139
|
+
* info: {root: HTMLDivElement}
|
|
140
|
+
* ) => HTMLSelectElement} [getSelect]
|
|
141
|
+
* @property {(path: string, value: StructuredCloneValue) =>
|
|
142
|
+
* StructuredCloneValue} [resolveReference] Gets the reference. For array
|
|
143
|
+
* and object references types only
|
|
88
144
|
* @property {(info: {root: HTMLDivElement, topRoot?: HTMLDivElement}) => {
|
|
89
|
-
* message
|
|
145
|
+
* message?: string,
|
|
90
146
|
* valid: boolean
|
|
91
147
|
* }} [validate] Message will be used if validity is false.
|
|
92
148
|
* @property {(info: {topRoot: HTMLDivElement}) => void} [validateAll] For
|
|
93
149
|
* validation of array and object references only.
|
|
94
150
|
* @property {{
|
|
95
151
|
* structuredCloning: {
|
|
96
|
-
* after:
|
|
152
|
+
* after: AvailableType,
|
|
97
153
|
* contexts: string[]
|
|
98
154
|
* }
|
|
99
155
|
* }} [stateDependent] The type after which it should be placed and its
|
|
@@ -201,62 +257,97 @@ Types.availableTypes = {
|
|
|
201
257
|
},
|
|
202
258
|
|
|
203
259
|
// We're catching this instead of using this
|
|
204
|
-
sparseUndefined: sparseUndefinedType
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
/*
|
|
210
|
-
|
|
260
|
+
sparseUndefined: sparseUndefinedType,
|
|
261
|
+
|
|
262
|
+
ValidDate: {
|
|
263
|
+
valid: true
|
|
264
|
+
},
|
|
265
|
+
/*
|
|
266
|
+
sparseArrays: {
|
|
267
|
+
sparse: true
|
|
268
|
+
},
|
|
269
|
+
*/
|
|
270
|
+
arrayNonindexKeys: {
|
|
211
271
|
sparse: true
|
|
272
|
+
}
|
|
212
273
|
};
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* @typedef {"null"|"true"|"false"|"number"|"bigint"|"string"|"arrayReference"|
|
|
277
|
+
* "objectReference"|"array"|"object"|"date"|"userObject"|"undef"|
|
|
278
|
+
* "SpecialRealNumber"|"SpecialNumber"|"regexp"|"BooleanObject"|
|
|
279
|
+
* "NumberObject"|"StringObject"|"map"|"set"|"file"|"filelist"|"blobHTML"|
|
|
280
|
+
* "arraybuffer"|"arraybufferview"|"dataview"|"imagedata"|"imagebitmap"|
|
|
281
|
+
* "int8array"|"uint8array"|"uint8clampedarray"|"int16array"|"uint16array"|
|
|
282
|
+
* "int32array"|"uint32array"|"float32array"|"float64array"|"IntlCollator"|
|
|
283
|
+
* "IntlDateTimeFormat"|"IntlNumberFormat"|"sparseUndefined"|"ValidDate"|
|
|
284
|
+
* "arrayNonindexKeys"} AvailableType
|
|
213
285
|
*/
|
|
214
|
-
Types.availableTypes.arrayNonindexKeys = {
|
|
215
|
-
sparse: true
|
|
216
|
-
};
|
|
217
286
|
|
|
218
287
|
/**
|
|
219
|
-
* @param {[
|
|
288
|
+
* @param {[
|
|
289
|
+
* copyFrom: AvailableType, copyTo: AvailableType
|
|
290
|
+
* ][]} replacements
|
|
220
291
|
* @returns {void}
|
|
221
292
|
*/
|
|
222
293
|
const copyTypeObjs = (replacements) => {
|
|
223
294
|
replacements.forEach(([copyFrom, copyTo]) => {
|
|
224
|
-
Object.assign(Types.availableTypes[
|
|
295
|
+
Object.assign(Types.availableTypes[
|
|
296
|
+
/** @type {AvailableType} */
|
|
297
|
+
(copyTo)
|
|
298
|
+
], Types.availableTypes[
|
|
299
|
+
/** @type {AvailableType} */
|
|
300
|
+
(copyFrom)
|
|
301
|
+
]);
|
|
225
302
|
});
|
|
226
303
|
};
|
|
227
|
-
|
|
228
|
-
|
|
304
|
+
|
|
305
|
+
copyTypeObjs(
|
|
229
306
|
[
|
|
230
|
-
|
|
231
|
-
|
|
307
|
+
/** @type {[AvailableType, AvailableType]} */ (
|
|
308
|
+
['date', 'ValidDate']
|
|
309
|
+
),
|
|
232
310
|
// 'sparseArrays'
|
|
311
|
+
/** @type {[AvailableType, AvailableType]} */ (
|
|
312
|
+
['array', 'arrayNonindexKeys']
|
|
313
|
+
)
|
|
233
314
|
]
|
|
234
|
-
|
|
315
|
+
);
|
|
235
316
|
|
|
236
317
|
/**
|
|
237
318
|
* Utility to retrieve the type out of a type root element.
|
|
238
319
|
* @public
|
|
239
320
|
* @param {?RootElement} root
|
|
240
|
-
* @returns {string|undefined} Why would it not exist?
|
|
321
|
+
* @returns {string|undefined|null} Why would it not exist?
|
|
241
322
|
*/
|
|
242
323
|
Types.getTypeForRoot = (root) => {
|
|
243
324
|
return root && root.dataset.type;
|
|
244
325
|
};
|
|
245
326
|
|
|
246
327
|
/**
|
|
247
|
-
* @typedef {
|
|
248
|
-
* typeNamespace: string,
|
|
249
|
-
* "readonly": boolean,
|
|
250
|
-
* format: string,
|
|
251
|
-
* error: Error,
|
|
252
|
-
* rootUI: Element,
|
|
253
|
-
* schemaContent: string,
|
|
254
|
-
* getPossibleSchemasForPathAndType: (
|
|
328
|
+
* @typedef {(
|
|
255
329
|
* keypath: string,
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
330
|
+
* parentPath: string,
|
|
331
|
+
* arrayOrObjectPropertyName: string,
|
|
332
|
+
* valueType: string
|
|
333
|
+
* ) => StateObject} GetPossibleSchemasForPathAndType
|
|
334
|
+
*/
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* @typedef {{
|
|
338
|
+
* typeNamespace?: string,
|
|
339
|
+
* "readonly"?: boolean,
|
|
340
|
+
* format?: import('./formats.js').AvailableFormat,
|
|
341
|
+
* error?: Error,
|
|
342
|
+
* rootUI?: Element,
|
|
343
|
+
* schema?: string,
|
|
344
|
+
* schemaContent?: object,
|
|
345
|
+
* getPossibleSchemasForPathAndType?: GetPossibleSchemasForPathAndType,
|
|
346
|
+
* paths?: {[currentPath: string]: {
|
|
347
|
+
* referentPath: string,
|
|
348
|
+
* expectArrayReferent: boolean
|
|
349
|
+
* }},
|
|
350
|
+
* handlingReference?: boolean
|
|
260
351
|
* }} StateObject
|
|
261
352
|
*/
|
|
262
353
|
|
|
@@ -271,7 +362,10 @@ Types.getTypeForRoot = (root) => {
|
|
|
271
362
|
*/
|
|
272
363
|
Types.getValueForRoot = (root, stateObj, currentPath) => {
|
|
273
364
|
const typeObject = /** @type {TypeObject} */ (
|
|
274
|
-
Types.availableTypes[
|
|
365
|
+
Types.availableTypes[
|
|
366
|
+
/** @type {AvailableType} */
|
|
367
|
+
(Types.getTypeForRoot(root))
|
|
368
|
+
]
|
|
275
369
|
);
|
|
276
370
|
return typeObject.getValue({
|
|
277
371
|
root, stateObj, currentPath
|
|
@@ -282,10 +376,14 @@ Types.getValueForRoot = (root, stateObj, currentPath) => {
|
|
|
282
376
|
* Utility to get the form control (e.g., input element) for a root.
|
|
283
377
|
* @public
|
|
284
378
|
* @param {RootElement} root
|
|
285
|
-
* @returns {null|
|
|
379
|
+
* @returns {null|
|
|
380
|
+
* HTMLInputElement|HTMLTextAreaElement|HTMLSelectElement|HTMLButtonElement}
|
|
286
381
|
*/
|
|
287
382
|
Types.getFormControlForRoot = (root) => {
|
|
288
|
-
const typeObj = Types.availableTypes[
|
|
383
|
+
const typeObj = /** @type {TypeObject} */ (Types.availableTypes[
|
|
384
|
+
/** @type {AvailableType} */
|
|
385
|
+
(Types.getTypeForRoot(root))
|
|
386
|
+
]);
|
|
289
387
|
/* istanbul ignore if -- All have except aliases */
|
|
290
388
|
if (!typeObj.getInput) {
|
|
291
389
|
return null;
|
|
@@ -301,16 +399,21 @@ Types.getFormControlForRoot = (root) => {
|
|
|
301
399
|
* @returns {StructuredCloneValue}
|
|
302
400
|
*/
|
|
303
401
|
Types.getValueFromRootAncestor = (selOrEl, stateObj) => {
|
|
304
|
-
return Types.getValueForRoot(
|
|
402
|
+
return Types.getValueForRoot(
|
|
403
|
+
/** @type {RootElement} */
|
|
404
|
+
($e(selOrEl, 'div[data-type]')),
|
|
405
|
+
stateObj
|
|
406
|
+
);
|
|
305
407
|
};
|
|
306
408
|
|
|
307
409
|
/**
|
|
308
410
|
* @public
|
|
309
411
|
* @param {string|Element} selOrEl
|
|
310
|
-
* @returns {null|HTMLInputElement
|
|
412
|
+
* @returns {null|HTMLInputElement|HTMLTextAreaElement|HTMLSelectElement|
|
|
413
|
+
* HTMLButtonElement}
|
|
311
414
|
*/
|
|
312
415
|
Types.getFormControlFromRootAncestor = (selOrEl) => {
|
|
313
|
-
const root = $e(selOrEl, 'div[data-type]');
|
|
416
|
+
const root = /** @type {RootElement} */ ($e(selOrEl, 'div[data-type]'));
|
|
314
417
|
if (!root) {
|
|
315
418
|
return null;
|
|
316
419
|
}
|
|
@@ -319,8 +422,8 @@ Types.getFormControlFromRootAncestor = (selOrEl) => {
|
|
|
319
422
|
|
|
320
423
|
/**
|
|
321
424
|
* @param {string} format
|
|
322
|
-
* @param {string} state
|
|
323
|
-
* @returns {
|
|
425
|
+
* @param {string} [state]
|
|
426
|
+
* @returns {AvailableType[]|undefined}
|
|
324
427
|
*/
|
|
325
428
|
Types.getTypesForFormatAndState = (
|
|
326
429
|
format, state
|
|
@@ -328,68 +431,85 @@ Types.getTypesForFormatAndState = (
|
|
|
328
431
|
|
|
329
432
|
/**
|
|
330
433
|
* @public
|
|
331
|
-
* @param {
|
|
332
|
-
* @returns {
|
|
434
|
+
* @param {AvailableType} type
|
|
435
|
+
* @returns {[string, {value: AvailableType, title?: string}]}
|
|
333
436
|
*/
|
|
334
437
|
Types.getOptionForType = (type) => {
|
|
335
|
-
|
|
336
|
-
optInfo
|
|
337
|
-
|
|
438
|
+
/** @type {[string, {value?: AvailableType, title?: string}?]} */
|
|
439
|
+
const optInfo = [
|
|
440
|
+
...(/** @type {TypeObject} */ (
|
|
441
|
+
Types.availableTypes[type]
|
|
442
|
+
)).option
|
|
443
|
+
];
|
|
444
|
+
optInfo[1] = {value: type, ...(optInfo[1])};
|
|
445
|
+
return /** @type {[string, {value: AvailableType, title?: string}]} */ (
|
|
446
|
+
optInfo
|
|
447
|
+
);
|
|
338
448
|
};
|
|
339
449
|
|
|
340
450
|
/**
|
|
341
451
|
* @public
|
|
342
452
|
* @param {string} format
|
|
343
|
-
* @param {string} parserState
|
|
344
|
-
* @returns {
|
|
453
|
+
* @param {string} [parserState]
|
|
454
|
+
* @returns {[string, {value: AvailableType, title?: string}][]}
|
|
345
455
|
*/
|
|
346
456
|
Types.getTypeOptionsForFormatAndState = (format, parserState) => {
|
|
347
457
|
const typesForFormatAndState = Types.getTypesForFormatAndState(
|
|
348
458
|
format, parserState
|
|
349
459
|
);
|
|
460
|
+
if (!typesForFormatAndState) {
|
|
461
|
+
throw new Error('Unexpected type for format and state');
|
|
462
|
+
}
|
|
350
463
|
return typesForFormatAndState.map((type) => {
|
|
351
464
|
return Types.getOptionForType(type);
|
|
352
465
|
});
|
|
353
466
|
};
|
|
354
467
|
|
|
468
|
+
/* eslint-disable jsdoc/valid-types -- readonly reserved */
|
|
355
469
|
/**
|
|
356
470
|
* @public
|
|
357
471
|
* @param {object} cfg
|
|
358
|
-
* @param {boolean} cfg.
|
|
359
|
-
* @param {"both"|"keys"|"values"} cfg.resultType
|
|
360
|
-
* @param {string} cfg.typeNamespace
|
|
361
|
-
* @param {
|
|
362
|
-
* @param {RootElement} cfg.topRoot
|
|
363
|
-
* @param {boolean} cfg.bringIntoFocus
|
|
364
|
-
* @param {BuildTypeChoices} cfg.buildTypeChoices
|
|
365
|
-
* @param {
|
|
366
|
-
* @param {
|
|
367
|
-
* @param {
|
|
368
|
-
*
|
|
472
|
+
* @param {boolean} [cfg.readonly]
|
|
473
|
+
* @param {"both"|"keys"|"values"} [cfg.resultType]
|
|
474
|
+
* @param {string} [cfg.typeNamespace]
|
|
475
|
+
* @param {AvailableType} cfg.type
|
|
476
|
+
* @param {RootElement} [cfg.topRoot]
|
|
477
|
+
* @param {boolean|undefined} cfg.bringIntoFocus
|
|
478
|
+
* @param {import('./typeChoices.js').BuildTypeChoices} [cfg.buildTypeChoices]
|
|
479
|
+
* @param {import('./formats.js').AvailableFormat} cfg.format
|
|
480
|
+
* @param {object} [cfg.schemaContent]
|
|
481
|
+
* @param {GetPossibleSchemasForPathAndType} [cfg.schemaState] Not currently
|
|
482
|
+
* in use
|
|
369
483
|
* @param {StructuredCloneValue} cfg.value
|
|
370
484
|
* @param {boolean} cfg.hasValue
|
|
485
|
+
* @param {StructuredCloneValue} [cfg.replaced]
|
|
371
486
|
* @returns {Element}
|
|
372
487
|
*/
|
|
373
488
|
Types.getUIForModeAndType = ({
|
|
374
489
|
readonly, resultType, typeNamespace, type, topRoot, bringIntoFocus,
|
|
375
|
-
buildTypeChoices, format, schemaContent, schemaState, value, hasValue
|
|
490
|
+
buildTypeChoices, format, schemaContent, schemaState, value, hasValue,
|
|
491
|
+
replaced
|
|
376
492
|
}) => {
|
|
377
|
-
|
|
378
|
-
const
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
493
|
+
/* eslint-enable jsdoc/valid-types -- readonly reserved */
|
|
494
|
+
const typeObj = /** @type {TypeObject} */ (Types.availableTypes[type]);
|
|
495
|
+
const arg = hasValue
|
|
496
|
+
? {
|
|
497
|
+
typeNamespace, type, buildTypeChoices,
|
|
498
|
+
format, schemaContent, schemaState,
|
|
499
|
+
resultType, topRoot, bringIntoFocus, value,
|
|
500
|
+
replaced
|
|
501
|
+
}
|
|
502
|
+
: {
|
|
503
|
+
typeNamespace, type, buildTypeChoices,
|
|
504
|
+
format, schemaContent, schemaState,
|
|
505
|
+
resultType, topRoot, bringIntoFocus,
|
|
506
|
+
replaced
|
|
507
|
+
};
|
|
508
|
+
const root = /** @type {HTMLDivElement} */ (jml(
|
|
509
|
+
...(readonly
|
|
510
|
+
? typeObj.viewUI(arg)
|
|
511
|
+
: typeObj.editUI(arg))
|
|
512
|
+
));
|
|
393
513
|
if (!readonly && typeObj.validate) {
|
|
394
514
|
const formControl = typeObj.getInput({root});
|
|
395
515
|
formControl.addEventListener('input', () => {
|
|
@@ -399,8 +519,17 @@ Types.getUIForModeAndType = ({
|
|
|
399
519
|
return root;
|
|
400
520
|
};
|
|
401
521
|
|
|
522
|
+
/**
|
|
523
|
+
* @type {{
|
|
524
|
+
* [key: string]: {
|
|
525
|
+
* [key: string]: {type: AvailableType, after: AvailableType}[]
|
|
526
|
+
* }
|
|
527
|
+
* }}
|
|
528
|
+
*/
|
|
402
529
|
Types.contexts = {};
|
|
403
|
-
Object.entries(Types.availableTypes).forEach(([
|
|
530
|
+
Object.entries(Types.availableTypes).forEach(([typ, typeObj]) => {
|
|
531
|
+
const type = /** @type {AvailableType} */ (typ);
|
|
532
|
+
const {stateDependent} = /** @type {TypeObject} */ (typeObj);
|
|
404
533
|
if (stateDependent) {
|
|
405
534
|
Object.entries(stateDependent).forEach(([format, formatStateDependent]) => {
|
|
406
535
|
if (!Types.contexts[format]) {
|
|
@@ -421,8 +550,8 @@ Object.entries(Types.availableTypes).forEach(([type, {stateDependent}]) => {
|
|
|
421
550
|
* @public
|
|
422
551
|
* @param {object} cfg
|
|
423
552
|
* @param {HTMLFormElement} cfg.form
|
|
424
|
-
* @param {string} cfg.typeNamespace
|
|
425
|
-
* @param {string} cfg.keySelectClass
|
|
553
|
+
* @param {string} [cfg.typeNamespace]
|
|
554
|
+
* @param {string} [cfg.keySelectClass]
|
|
426
555
|
* @returns {boolean}
|
|
427
556
|
*/
|
|
428
557
|
Types.validValuesSet = ({form, typeNamespace, keySelectClass}) => {
|
|
@@ -435,10 +564,13 @@ Types.validValuesSet = ({form, typeNamespace, keySelectClass}) => {
|
|
|
435
564
|
return false;
|
|
436
565
|
}
|
|
437
566
|
|
|
438
|
-
const typeChoices =
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
567
|
+
const typeChoices =
|
|
568
|
+
/** @type {(HTMLSelectElement & {$validate: () => boolean})[]} */ (
|
|
569
|
+
$$e(
|
|
570
|
+
form,
|
|
571
|
+
keySelectClass ? `.${keySelectClass}` : `.typeChoices-${typeNamespace}`
|
|
572
|
+
)
|
|
573
|
+
);
|
|
442
574
|
return (
|
|
443
575
|
// Specific value type set if present (any descendant, not
|
|
444
576
|
// only the first) chosen
|
|
@@ -475,7 +607,8 @@ Types.validateAllReferences = ({topRoot}) => {
|
|
|
475
607
|
|
|
476
608
|
// Could just hard-code arrayReference and objectReference,
|
|
477
609
|
// but we'll try to avoid depending on specific types
|
|
478
|
-
Object.values(Types.availableTypes).forEach((
|
|
610
|
+
Object.values(Types.availableTypes).forEach((typeObj) => {
|
|
611
|
+
const typeObject = /** @type {TypeObject} */ (typeObj);
|
|
479
612
|
if (typeObject.validateAll) {
|
|
480
613
|
typeObject.validateAll({topRoot});
|
|
481
614
|
}
|
|
@@ -486,16 +619,21 @@ Types.validateAllReferences = ({topRoot}) => {
|
|
|
486
619
|
}
|
|
487
620
|
};
|
|
488
621
|
|
|
622
|
+
/**
|
|
623
|
+
* @type {null|((info: {topRoot: HTMLDivElement}) => void)}
|
|
624
|
+
*/
|
|
625
|
+
Types.customValidateAllReferences = null;
|
|
626
|
+
|
|
489
627
|
/**
|
|
490
628
|
* @public
|
|
491
629
|
* @param {object} cfg
|
|
492
|
-
* @param {
|
|
630
|
+
* @param {AvailableType} cfg.type
|
|
493
631
|
* @param {RootElement} cfg.root
|
|
494
|
-
* @param {RootElement} cfg.topRoot
|
|
632
|
+
* @param {RootElement} [cfg.topRoot]
|
|
495
633
|
* @returns {boolean}
|
|
496
634
|
*/
|
|
497
635
|
Types.validate = ({type, root, topRoot}) => {
|
|
498
|
-
const typeObj = Types.availableTypes[type];
|
|
636
|
+
const typeObj = /** @type {TypeObject} */ (Types.availableTypes[type]);
|
|
499
637
|
// Todo (low): We limit for now to input boxes which have `validate`
|
|
500
638
|
if (typeObj.validate) {
|
|
501
639
|
const {valid, message} = typeObj.validate({root, topRoot});
|
|
@@ -514,13 +652,13 @@ Types.validate = ({type, root, topRoot}) => {
|
|
|
514
652
|
|
|
515
653
|
/**
|
|
516
654
|
* @param {object} cfg
|
|
517
|
-
* @param {
|
|
655
|
+
* @param {AvailableType} cfg.type
|
|
518
656
|
* @param {RootElement} cfg.root
|
|
519
657
|
* @param {StructuredCloneValue} cfg.value
|
|
520
658
|
* @returns {void}
|
|
521
659
|
*/
|
|
522
660
|
Types.setValue = ({type, root, value}) => {
|
|
523
|
-
const typeObj = Types.availableTypes[type];
|
|
661
|
+
const typeObj = /** @type {TypeObject} */ (Types.availableTypes[type]);
|
|
524
662
|
if (typeObj.setValue) {
|
|
525
663
|
typeObj.setValue({root, value});
|
|
526
664
|
}
|
|
@@ -549,68 +687,86 @@ function escapeRegex (str) {
|
|
|
549
687
|
* @public
|
|
550
688
|
* @param {string} s
|
|
551
689
|
* @param {object} cfg
|
|
552
|
-
* @param {
|
|
690
|
+
* @param {import('./formats.js').AvailableFormat} cfg.format
|
|
553
691
|
* @param {string} cfg.state
|
|
554
692
|
* @param {TypeObject[]} [cfg.endMatchTypeObjs=[]]
|
|
555
693
|
* @param {boolean} [cfg.firstRun=true]
|
|
556
|
-
* @param {
|
|
557
|
-
*
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
* }
|
|
564
|
-
* @
|
|
565
|
-
*
|
|
566
|
-
* @returns {{
|
|
567
|
-
* value: ArbitraryValue,
|
|
694
|
+
* @param {[
|
|
695
|
+
* type: string,
|
|
696
|
+
* parent: {[key: string]: any},
|
|
697
|
+
* parentPath: string|number,
|
|
698
|
+
* path: string
|
|
699
|
+
* ][]} [cfg.rootHolder=[]]
|
|
700
|
+
* @param {{[key: string]: any}} cfg.parent
|
|
701
|
+
* @param {string|number} cfg.parentPath
|
|
702
|
+
* @returns {[
|
|
703
|
+
* value: StructuredCloneValue,
|
|
568
704
|
* remnant: string,
|
|
569
705
|
* beginOnly: boolean,
|
|
570
706
|
* assign: boolean
|
|
571
|
-
* }
|
|
707
|
+
* ]}
|
|
572
708
|
*/
|
|
573
709
|
Types.getValueForString = (s, {
|
|
574
710
|
format, state, endMatchTypeObjs = [], firstRun = true,
|
|
575
711
|
rootHolder = [], parent, parentPath
|
|
576
712
|
}) => {
|
|
577
|
-
let assign = true;
|
|
578
|
-
let match;
|
|
579
713
|
const allowedTypes = Types.getTypesForFormatAndState(format, state);
|
|
714
|
+
if (!allowedTypes) {
|
|
715
|
+
throw new Error('Could not get types for format and state');
|
|
716
|
+
}
|
|
580
717
|
const allowedTypeObjs = Object.entries(
|
|
581
718
|
Types.availableTypes
|
|
582
|
-
).filter(([type]) =>
|
|
719
|
+
).filter(([type]) => {
|
|
720
|
+
return allowedTypes.includes(/** @type {AvailableType} */ (type));
|
|
721
|
+
});
|
|
583
722
|
const allowedTypeObjsVals = allowedTypeObjs.map(([, arr]) => arr);
|
|
584
723
|
|
|
585
|
-
const
|
|
724
|
+
const reduced = allowedTypeObjsVals.reduce((array, typObj) => {
|
|
725
|
+
const typeObj = /** @type {TypeObject} */ (typObj);
|
|
726
|
+
let arr = /** @type {string[]} */ (array);
|
|
586
727
|
if (typeObj.regexEndings) {
|
|
587
728
|
arr.push(...typeObj.regexEndings);
|
|
588
729
|
arr = [...new Set(arr)];
|
|
589
730
|
}
|
|
590
731
|
return arr;
|
|
591
|
-
}, [])
|
|
592
|
-
|
|
593
|
-
|
|
732
|
+
}, []);
|
|
733
|
+
const endings = '|' + /** @type {string[]} */ (
|
|
734
|
+
reduced
|
|
735
|
+
).map((str) => escapeRegex(str)).join('|');
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* @type {RegExpMatchArray|boolean|null}
|
|
739
|
+
*/
|
|
740
|
+
let match = null;
|
|
741
|
+
let found = allowedTypeObjs.find(([_type, typObj]) => {
|
|
742
|
+
const typeObj = /** @type {TypeObject} */ (typObj);
|
|
594
743
|
let {stringRegex} = typeObj;
|
|
595
|
-
if (typeof stringRegex === 'function') {
|
|
744
|
+
if (typeof typeObj.stringRegex === 'function') {
|
|
596
745
|
stringRegex = typeObj.stringRegex(true);
|
|
597
746
|
}
|
|
598
747
|
stringRegex = stringRegex
|
|
599
748
|
// Strip off terminal (dollar sign) when matching substrings
|
|
600
749
|
? new RegExp(
|
|
601
|
-
|
|
750
|
+
/** @type {RegExp} */ (
|
|
751
|
+
stringRegex
|
|
752
|
+
).source.slice(0, -1) + '(?=$' + endings + ')',
|
|
602
753
|
'u'
|
|
603
754
|
)
|
|
604
755
|
: stringRegex;
|
|
605
|
-
match = stringRegex && s && s.match(
|
|
756
|
+
match = Boolean(stringRegex && s) && s.match(
|
|
757
|
+
/** @type {RegExp} */ (stringRegex)
|
|
758
|
+
);
|
|
606
759
|
return match;
|
|
607
760
|
});
|
|
608
761
|
|
|
609
|
-
let beginOnly;
|
|
762
|
+
let beginOnly = false;
|
|
610
763
|
if (found === undefined) {
|
|
611
|
-
found = allowedTypeObjs.find(([_type,
|
|
764
|
+
found = allowedTypeObjs.find(([_type, typObj]) => {
|
|
765
|
+
const typeObj = /** @type {TypeObject} */ (typObj);
|
|
612
766
|
const {stringRegexBegin} = typeObj;
|
|
613
|
-
match = stringRegexBegin && s && s.match(
|
|
767
|
+
match = Boolean(stringRegexBegin && s) && s.match(
|
|
768
|
+
/** @type {RegExp} */ (stringRegexBegin)
|
|
769
|
+
);
|
|
614
770
|
if (match) {
|
|
615
771
|
beginOnly = true;
|
|
616
772
|
endMatchTypeObjs.push(typeObj);
|
|
@@ -618,13 +774,16 @@ Types.getValueForString = (s, {
|
|
|
618
774
|
return match;
|
|
619
775
|
});
|
|
620
776
|
}
|
|
777
|
+
let assign = true;
|
|
621
778
|
if (found !== undefined) {
|
|
622
|
-
|
|
623
|
-
|
|
779
|
+
// @ts-ignore The `found` is evaluated again, so sets `match` to non-null
|
|
780
|
+
const [content, innerContent] = /** @type {RegExpMatchArray} */ (match);
|
|
781
|
+
let remnant = s.slice(content.length);
|
|
782
|
+
s = s.slice(0, content.length);
|
|
624
783
|
// console.log('s0', s, '::', remnant, match);
|
|
625
784
|
let valObj;
|
|
626
785
|
try {
|
|
627
|
-
valObj = found[1].toValue(
|
|
786
|
+
valObj = /** @type {TypeObject} */ (found[1]).toValue(innerContent || s, {
|
|
628
787
|
format,
|
|
629
788
|
endMatchTypeObjs,
|
|
630
789
|
remnant,
|
|
@@ -646,7 +805,7 @@ Types.getValueForString = (s, {
|
|
|
646
805
|
|
|
647
806
|
if (beginOnly && endMatchTypeObjs.length) {
|
|
648
807
|
const endMatch = remnant.match(
|
|
649
|
-
endMatchTypeObjs.slice(-1)[0].stringRegexEnd
|
|
808
|
+
/** @type {RegExp} */ (endMatchTypeObjs.slice(-1)[0].stringRegexEnd)
|
|
650
809
|
);
|
|
651
810
|
if (endMatch) {
|
|
652
811
|
endMatchTypeObjs.pop(); // Safe now to extract
|
|
@@ -660,8 +819,12 @@ Types.getValueForString = (s, {
|
|
|
660
819
|
try {
|
|
661
820
|
const topRoot = typeson.revive(value);
|
|
662
821
|
rootHolder.forEach(([type, parent, parentPath, path]) => {
|
|
663
|
-
const
|
|
664
|
-
|
|
822
|
+
const typeObject = Types.availableTypes[
|
|
823
|
+
/** @type {AvailableType} */ (type + 'Reference')
|
|
824
|
+
];
|
|
825
|
+
|
|
826
|
+
// @ts-expect-error Reference method exists
|
|
827
|
+
const val = typeObject.resolveReference(path, topRoot);
|
|
665
828
|
const basicType = getJSONType(val);
|
|
666
829
|
// eslint-disable-next-line max-len -- Long
|
|
667
830
|
/* istanbul ignore else -- Successful reference always an object/array? */
|