@es-joy/jsoe 0.31.0 → 0.32.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/CHANGES.md +4 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/search/fundamentalTypes/arraySearchType.d.ts.map +1 -1
- package/dist/search/fundamentalTypes/bigintSearchType.d.ts.map +1 -1
- package/dist/search/fundamentalTypes/blobSearchType.d.ts.map +1 -1
- package/dist/search/fundamentalTypes/booleanSearchType.d.ts.map +1 -1
- package/dist/search/fundamentalTypes/catchSearchType.d.ts.map +1 -1
- package/dist/search/fundamentalTypes/dateSearchType.d.ts.map +1 -1
- package/dist/search/fundamentalTypes/domexceptionSearchType.d.ts.map +1 -1
- package/dist/search/fundamentalTypes/enumSearchType.d.ts.map +1 -1
- package/dist/search/fundamentalTypes/fileSearchType.d.ts.map +1 -1
- package/dist/search/fundamentalTypes/filelistSearchType.d.ts.map +1 -1
- package/dist/search/fundamentalTypes/functionSearchType.d.ts.map +1 -1
- package/dist/search/fundamentalTypes/mapSearchType.d.ts.map +1 -1
- package/dist/search/fundamentalTypes/numberSearchType.d.ts.map +1 -1
- package/dist/search/fundamentalTypes/objectSearchType.d.ts.map +1 -1
- package/dist/search/fundamentalTypes/promiseSearchType.d.ts.map +1 -1
- package/dist/search/fundamentalTypes/regexpSearchType.d.ts.map +1 -1
- package/dist/search/fundamentalTypes/setSearchType.d.ts.map +1 -1
- package/dist/search/fundamentalTypes/stringSearchType.d.ts.map +1 -1
- package/dist/search/fundamentalTypes/symbolSearchType.d.ts.map +1 -1
- package/dist/search/index.d.ts +2 -0
- package/dist/search/index.d.ts.map +1 -1
- package/dist/search/searchDispatch.d.ts +11 -3
- package/dist/search/searchDispatch.d.ts.map +1 -1
- package/dist/search/searchElementUtils.d.ts +31 -1
- package/dist/search/searchElementUtils.d.ts.map +1 -1
- package/dist/search/searchUtils.d.ts +180 -0
- package/dist/search/searchUtils.d.ts.map +1 -1
- package/dist/search/subTypes/blobHTMLSearchType.d.ts.map +1 -1
- package/dist/search/subTypes/recordSearchType.d.ts.map +1 -1
- package/dist/search/subTypes/tupleSearchType.d.ts.map +1 -1
- package/dist/search/superTypes/SpecialRealNumberSearchType.d.ts.map +1 -1
- package/dist/search/superTypes/buffersourceSearchType.d.ts.map +1 -1
- package/dist/search/unions/unionFamilySearchType.d.ts.map +1 -1
- package/dist/utils/json6Stringify.d.ts +2 -0
- package/dist/utils/json6Stringify.d.ts.map +1 -0
- package/dist/utils/rawTypesonEditor.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/search/fundamentalTypes/arraySearchType.js +28 -5
- package/src/search/fundamentalTypes/bigintSearchType.js +14 -3
- package/src/search/fundamentalTypes/blobSearchType.js +21 -3
- package/src/search/fundamentalTypes/booleanSearchType.js +15 -3
- package/src/search/fundamentalTypes/catchSearchType.js +20 -3
- package/src/search/fundamentalTypes/dateSearchType.js +42 -3
- package/src/search/fundamentalTypes/domexceptionSearchType.js +18 -4
- package/src/search/fundamentalTypes/enumSearchType.js +15 -3
- package/src/search/fundamentalTypes/fileSearchType.js +15 -3
- package/src/search/fundamentalTypes/filelistSearchType.js +25 -5
- package/src/search/fundamentalTypes/functionSearchType.js +31 -4
- package/src/search/fundamentalTypes/mapSearchType.js +33 -5
- package/src/search/fundamentalTypes/numberSearchType.js +15 -3
- package/src/search/fundamentalTypes/objectSearchType.js +94 -5
- package/src/search/fundamentalTypes/promiseSearchType.js +20 -3
- package/src/search/fundamentalTypes/regexpSearchType.js +24 -4
- package/src/search/fundamentalTypes/setSearchType.js +25 -5
- package/src/search/fundamentalTypes/stringSearchType.js +25 -3
- package/src/search/fundamentalTypes/symbolSearchType.js +21 -3
- package/src/search/index.js +22 -0
- package/src/search/searchDispatch.js +14 -5
- package/src/search/searchElementUtils.js +98 -10
- package/src/search/searchUtils.js +368 -0
- package/src/search/subTypes/blobHTMLSearchType.js +43 -3
- package/src/search/subTypes/recordSearchType.js +30 -4
- package/src/search/subTypes/tupleSearchType.js +43 -5
- package/src/search/superTypes/SpecialRealNumberSearchType.js +15 -3
- package/src/search/superTypes/buffersourceSearchType.js +14 -3
- package/src/search/unions/unionFamilySearchType.js +45 -3
- package/src/utils/json6Stringify.js +50 -0
- package/src/utils/rawTypesonEditor.js +1 -51
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import {jml} from '../../vendor-imports.js';
|
|
2
|
-
import {buildPathLabel, findOwnControl} from '../searchUtils.js';
|
|
2
|
+
import {buildPathLabel, findOwnControl, extractLeafOfKind} from '../searchUtils.js';
|
|
3
3
|
import {makeTypeOfLeaf, combineAnd} from '../queryTreeBuilders.js';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
findSearchElement, getQueryViaElement, hasGetQuery,
|
|
6
|
+
applyQueryViaElement, hasApplyQuery
|
|
7
|
+
} from '../searchElementUtils.js';
|
|
5
8
|
import {getSearchSchemaType, buildSearchWidget} from '../searchDispatch.js';
|
|
6
9
|
|
|
7
10
|
/**
|
|
@@ -101,6 +104,44 @@ export function makeUnionFamilySearchType ({tagName, discriminated}) {
|
|
|
101
104
|
? branchEl.getQuery()
|
|
102
105
|
: undefined;
|
|
103
106
|
return combineAnd([typeOfLeaf, branchQuery]);
|
|
107
|
+
},
|
|
108
|
+
/**
|
|
109
|
+
* Drives the existing "Has type" `<select>`'s own `change`
|
|
110
|
+
* listener (defined below, per-instance and so already safe to
|
|
111
|
+
* close over `branches`) rather than reimplementing branch-DOM
|
|
112
|
+
* construction here - `$define` methods are installed once on the
|
|
113
|
+
* tag's shared prototype the first time it's defined (this
|
|
114
|
+
* function's own doc), so `applyQuery` can't close over
|
|
115
|
+
* `branches` itself, but dispatching a real `change` event lets
|
|
116
|
+
* the per-instance listener that *can* do the rebuild for us.
|
|
117
|
+
* @this {HTMLElement}
|
|
118
|
+
* @param {import('../queryTree.js').QueryNode|undefined} queryNode
|
|
119
|
+
* @returns {void}
|
|
120
|
+
*/
|
|
121
|
+
applyQuery (queryNode) {
|
|
122
|
+
const select = /** @type {HTMLSelectElement|undefined} */ (
|
|
123
|
+
findOwnControl(this, 'select.jsoeSearchTypeOf')
|
|
124
|
+
);
|
|
125
|
+
if (!select) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const {matched, rest} = extractLeafOfKind(queryNode, 'typeOf');
|
|
129
|
+
const optionMatch = matched && [...select.options].find((opt) => (
|
|
130
|
+
opt.dataset.searchType === matched.searchType &&
|
|
131
|
+
(opt.dataset.discriminatorValue === undefined
|
|
132
|
+
? matched.discriminatorValue === undefined
|
|
133
|
+
: JSON.parse(opt.dataset.discriminatorValue) === matched.discriminatorValue)
|
|
134
|
+
));
|
|
135
|
+
select.value = optionMatch ? optionMatch.value : '';
|
|
136
|
+
select.dispatchEvent(new Event('change'));
|
|
137
|
+
if (!optionMatch) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const searchPath = this.dataset.searchPath ?? '';
|
|
141
|
+
const branchEl = findSearchElement(this, searchPath);
|
|
142
|
+
if (branchEl && hasApplyQuery(branchEl)) {
|
|
143
|
+
branchEl.applyQuery(rest);
|
|
144
|
+
}
|
|
104
145
|
}
|
|
105
146
|
}
|
|
106
147
|
}, [
|
|
@@ -163,6 +204,7 @@ export function makeUnionFamilySearchType ({tagName, discriminated}) {
|
|
|
163
204
|
['div', {class: 'searchUnionBranch'}]
|
|
164
205
|
]];
|
|
165
206
|
},
|
|
166
|
-
getQuery: getQueryViaElement
|
|
207
|
+
getQuery: getQueryViaElement,
|
|
208
|
+
applyQuery: applyQueryViaElement
|
|
167
209
|
};
|
|
168
210
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const identifierKeyRegex = (/^[A-Za-z_$][\w$]*$/u);
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A minimal JSON6-*subset* stringifier: unquotes object keys that are valid
|
|
5
|
+
* identifiers (for the "simplified" display the JSON6 mode is meant to
|
|
6
|
+
* give), while always fully quoting string *values* via `JSON.stringify`.
|
|
7
|
+
*
|
|
8
|
+
* `JSON6.stringify` (from the `json-6` package) was tried first but has a
|
|
9
|
+
* real bug: it runs the same identifier-unquoting logic it uses for keys
|
|
10
|
+
* on string *values* too, so e.g. the value `"hello"` is emitted as the
|
|
11
|
+
* bare word `hello` — not valid JS/JSON6 syntax as a value, and not even
|
|
12
|
+
* re-parseable by the package's own `JSON6.parse`. Hand-rolling this
|
|
13
|
+
* avoids depending on that broken path while still using `JSON6.parse`
|
|
14
|
+
* (which is correct) to read the text back after editing.
|
|
15
|
+
* @param {unknown} value
|
|
16
|
+
* @param {string} indent
|
|
17
|
+
* @param {string} curIndent
|
|
18
|
+
* @returns {string}
|
|
19
|
+
*/
|
|
20
|
+
export const stringifyJSON6 = (value, indent, curIndent) => {
|
|
21
|
+
if (value === null || typeof value !== 'object') {
|
|
22
|
+
return JSON.stringify(value);
|
|
23
|
+
}
|
|
24
|
+
const nextIndent = curIndent + indent;
|
|
25
|
+
if (Array.isArray(value)) {
|
|
26
|
+
if (!value.length) {
|
|
27
|
+
return '[]';
|
|
28
|
+
}
|
|
29
|
+
const items = value.map((item) => {
|
|
30
|
+
return `${nextIndent}${stringifyJSON6(item, indent, nextIndent)}`;
|
|
31
|
+
});
|
|
32
|
+
return `[\n${items.join(',\n')}\n${curIndent}]`;
|
|
33
|
+
}
|
|
34
|
+
const keys = Object.keys(value);
|
|
35
|
+
if (!keys.length) {
|
|
36
|
+
return '{}';
|
|
37
|
+
}
|
|
38
|
+
const items = keys.map((key) => {
|
|
39
|
+
const keyText = identifierKeyRegex.test(key)
|
|
40
|
+
? key
|
|
41
|
+
: JSON.stringify(key);
|
|
42
|
+
return `${nextIndent}${keyText}: ${
|
|
43
|
+
stringifyJSON6(
|
|
44
|
+
/** @type {{[key: string]: unknown}} */ (value)[key], indent,
|
|
45
|
+
nextIndent
|
|
46
|
+
)
|
|
47
|
+
}`;
|
|
48
|
+
});
|
|
49
|
+
return `{\n${items.join(',\n')}\n${curIndent}}`;
|
|
50
|
+
};
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
} from '../vendor-imports.js';
|
|
7
7
|
import {structuredCloningJsoe} from '../formats/structuredCloning.js';
|
|
8
8
|
import {parseValue} from '../formats/schema.js';
|
|
9
|
+
import {stringifyJSON6} from './json6Stringify.js';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* @returns {import('typeson').Typeson}
|
|
@@ -14,8 +15,6 @@ const buildTypeson = () => {
|
|
|
14
15
|
return new Typeson().register(structuredCloningJsoe);
|
|
15
16
|
};
|
|
16
17
|
|
|
17
|
-
const identifierKeyRegex = (/^[A-Za-z_$][\w$]*$/u);
|
|
18
|
-
|
|
19
18
|
/** @type {ReadonlySet<string>} */
|
|
20
19
|
const typedArrayTagNames = new Set([
|
|
21
20
|
'Int8Array', 'Uint8Array', 'Uint8ClampedArray', 'Int16Array',
|
|
@@ -45,55 +44,6 @@ const bytesToBase64 = (bytes) => {
|
|
|
45
44
|
return btoa(binary);
|
|
46
45
|
};
|
|
47
46
|
|
|
48
|
-
/**
|
|
49
|
-
* A minimal JSON6-*subset* stringifier: unquotes object keys that are valid
|
|
50
|
-
* identifiers (for the "simplified" display the JSON6 mode is meant to
|
|
51
|
-
* give), while always fully quoting string *values* via `JSON.stringify`.
|
|
52
|
-
*
|
|
53
|
-
* `JSON6.stringify` (from the `json-6` package) was tried first but has a
|
|
54
|
-
* real bug: it runs the same identifier-unquoting logic it uses for keys
|
|
55
|
-
* on string *values* too, so e.g. the value `"hello"` is emitted as the
|
|
56
|
-
* bare word `hello` — not valid JS/JSON6 syntax as a value, and not even
|
|
57
|
-
* re-parseable by the package's own `JSON6.parse`. Hand-rolling this
|
|
58
|
-
* avoids depending on that broken path while still using `JSON6.parse`
|
|
59
|
-
* (which is correct) to read the text back after editing.
|
|
60
|
-
* @param {unknown} value
|
|
61
|
-
* @param {string} indent
|
|
62
|
-
* @param {string} curIndent
|
|
63
|
-
* @returns {string}
|
|
64
|
-
*/
|
|
65
|
-
const stringifyJSON6 = (value, indent, curIndent) => {
|
|
66
|
-
if (value === null || typeof value !== 'object') {
|
|
67
|
-
return JSON.stringify(value);
|
|
68
|
-
}
|
|
69
|
-
const nextIndent = curIndent + indent;
|
|
70
|
-
if (Array.isArray(value)) {
|
|
71
|
-
if (!value.length) {
|
|
72
|
-
return '[]';
|
|
73
|
-
}
|
|
74
|
-
const items = value.map((item) => {
|
|
75
|
-
return `${nextIndent}${stringifyJSON6(item, indent, nextIndent)}`;
|
|
76
|
-
});
|
|
77
|
-
return `[\n${items.join(',\n')}\n${curIndent}]`;
|
|
78
|
-
}
|
|
79
|
-
const keys = Object.keys(value);
|
|
80
|
-
if (!keys.length) {
|
|
81
|
-
return '{}';
|
|
82
|
-
}
|
|
83
|
-
const items = keys.map((key) => {
|
|
84
|
-
const keyText = identifierKeyRegex.test(key)
|
|
85
|
-
? key
|
|
86
|
-
: JSON.stringify(key);
|
|
87
|
-
return `${nextIndent}${keyText}: ${
|
|
88
|
-
stringifyJSON6(
|
|
89
|
-
/** @type {{[key: string]: unknown}} */ (value)[key], indent,
|
|
90
|
-
nextIndent
|
|
91
|
-
)
|
|
92
|
-
}`;
|
|
93
|
-
});
|
|
94
|
-
return `{\n${items.join(',\n')}\n${curIndent}}`;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
47
|
/**
|
|
98
48
|
* Builds the Typeson/JSON6 text shown by both the view-mode "View raw"
|
|
99
49
|
* button and, seeded, the edit-mode "Edit raw" button's Typeson mode.
|