@uipath/apollo-wind 2.67.1 → 2.69.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/dist/components/forms/metadata-form.cjs +40 -44
- package/dist/components/forms/metadata-form.js +40 -44
- package/dist/components/ui/code-block.cjs +375 -0
- package/dist/components/ui/code-block.d.ts +38 -0
- package/dist/components/ui/code-block.js +307 -0
- package/dist/components/ui/index.cjs +268 -191
- package/dist/components/ui/index.d.ts +7 -0
- package/dist/components/ui/index.js +7 -0
- package/dist/components/ui/json-tree-view/JsonTree.cjs +2 -2
- package/dist/components/ui/json-tree-view/JsonTree.js +1 -1
- package/dist/components/ui/json-tree-view/JsonTree.types.d.ts +26 -0
- package/dist/components/ui/json-tree-view/JsonTreeRow.cjs +13 -10
- package/dist/components/ui/json-tree-view/JsonTreeRow.js +14 -11
- package/dist/components/ui/json-tree-view/JsonTreeToolbar.cjs +22 -11
- package/dist/components/ui/json-tree-view/JsonTreeToolbar.d.ts +6 -1
- package/dist/components/ui/json-tree-view/JsonTreeToolbar.js +22 -11
- package/dist/components/ui/json-tree-view/NodeKey.cjs +4 -0
- package/dist/components/ui/json-tree-view/NodeKey.js +4 -0
- package/dist/components/ui/json-tree-view/RowActions.cjs +23 -17
- package/dist/components/ui/json-tree-view/RowActions.d.ts +4 -1
- package/dist/components/ui/json-tree-view/RowActions.js +23 -17
- package/dist/components/ui/json-tree-view/buildJsonTree.cjs +99 -44
- package/dist/components/ui/json-tree-view/buildJsonTree.d.ts +15 -2
- package/dist/components/ui/json-tree-view/buildJsonTree.js +97 -45
- package/dist/components/ui/json-tree-view/index.cjs +26 -23
- package/dist/components/ui/json-tree-view/index.d.ts +2 -2
- package/dist/components/ui/json-tree-view/index.js +2 -2
- package/dist/components/ui/live-region.cjs +106 -0
- package/dist/components/ui/live-region.d.ts +31 -0
- package/dist/components/ui/live-region.js +72 -0
- package/dist/components/ui/loading-dots.cjs +95 -0
- package/dist/components/ui/loading-dots.d.ts +21 -0
- package/dist/components/ui/loading-dots.js +55 -0
- package/dist/components/ui/markdown.cjs +428 -0
- package/dist/components/ui/markdown.d.ts +55 -0
- package/dist/components/ui/markdown.js +378 -0
- package/dist/components/ui/panel-tabs.cjs +99 -0
- package/dist/components/ui/panel-tabs.d.ts +34 -0
- package/dist/components/ui/panel-tabs.js +53 -0
- package/dist/components/ui/thinking-indicator.cjs +146 -0
- package/dist/components/ui/thinking-indicator.d.ts +38 -0
- package/dist/components/ui/thinking-indicator.js +106 -0
- package/dist/components/ui/tool-call.cjs +359 -0
- package/dist/components/ui/tool-call.d.ts +75 -0
- package/dist/components/ui/tool-call.js +301 -0
- package/dist/index.cjs +334 -246
- package/dist/index.d.ts +15 -1
- package/dist/index.js +9 -2
- package/dist/styles.css +239 -0
- package/dist/tailwind.utilities.css +21 -0
- package/package.json +7 -1
- /package/dist/{components/ui/json-tree-view → lib}/clipboard.cjs +0 -0
- /package/dist/{components/ui/json-tree-view → lib}/clipboard.d.ts +0 -0
- /package/dist/{components/ui/json-tree-view → lib}/clipboard.js +0 -0
|
@@ -13,32 +13,38 @@ const ACTION_TONE_CLASS = {
|
|
|
13
13
|
warning: 'text-warning hover:text-warning',
|
|
14
14
|
error: 'text-error hover:text-error'
|
|
15
15
|
};
|
|
16
|
-
function RowActions({ node, actions, maxInline }) {
|
|
16
|
+
function RowActions({ node, actions, maxInline, meta }) {
|
|
17
17
|
const strings = useJsonTreeViewStrings();
|
|
18
18
|
const [menuOpen, setMenuOpen] = useState(false);
|
|
19
|
-
if (0 === actions.length) return null;
|
|
19
|
+
if (0 === actions.length && null == meta) return null;
|
|
20
20
|
const overflowing = actions.length > maxInline;
|
|
21
21
|
const inline = overflowing ? [] : actions;
|
|
22
22
|
const overflow = overflowing ? actions : [];
|
|
23
23
|
const moreLabel = strings.moreActions;
|
|
24
|
+
const renderInline = (action)=>/*#__PURE__*/ jsx(JsonTreeTooltip, {
|
|
25
|
+
content: action.tooltip ?? action.label,
|
|
26
|
+
placement: "top",
|
|
27
|
+
delay: true,
|
|
28
|
+
children: /*#__PURE__*/ jsx(Button, {
|
|
29
|
+
variant: "ghost",
|
|
30
|
+
size: "4xs",
|
|
31
|
+
icon: true,
|
|
32
|
+
disabled: action.disabled,
|
|
33
|
+
onClick: ()=>action.onSelect(node),
|
|
34
|
+
"aria-label": action.label,
|
|
35
|
+
className: cn(ACTION_BUTTON_CLASS, '[&_svg]:size-2.75', action.tone && ACTION_TONE_CLASS[action.tone], action.persistent && 'opacity-100', action.active && 'text-brand opacity-100 hover:text-brand'),
|
|
36
|
+
children: action.icon
|
|
37
|
+
})
|
|
38
|
+
}, action.id);
|
|
24
39
|
return /*#__PURE__*/ jsxs("span", {
|
|
25
40
|
className: "ml-auto flex shrink-0 items-center gap-0.5",
|
|
26
41
|
children: [
|
|
27
|
-
inline.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
size: "4xs",
|
|
34
|
-
icon: true,
|
|
35
|
-
disabled: action.disabled,
|
|
36
|
-
onClick: ()=>action.onSelect(node),
|
|
37
|
-
"aria-label": action.label,
|
|
38
|
-
className: cn(ACTION_BUTTON_CLASS, '[&_svg]:size-2.75', action.tone && ACTION_TONE_CLASS[action.tone], action.active && 'text-brand opacity-100 hover:text-brand'),
|
|
39
|
-
children: action.icon
|
|
40
|
-
})
|
|
41
|
-
}, action.id)),
|
|
42
|
+
inline.filter((action)=>'start' === action.placement).map(renderInline),
|
|
43
|
+
null != meta && /*#__PURE__*/ jsx("span", {
|
|
44
|
+
className: "mx-1.5 flex shrink-0 items-center",
|
|
45
|
+
children: meta
|
|
46
|
+
}),
|
|
47
|
+
inline.filter((action)=>'start' !== action.placement).map(renderInline),
|
|
42
48
|
overflow.length > 0 && /*#__PURE__*/ jsxs(DropdownMenu, {
|
|
43
49
|
open: menuOpen,
|
|
44
50
|
onOpenChange: setMenuOpen,
|
|
@@ -33,6 +33,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
33
33
|
inferValueType: ()=>inferValueType,
|
|
34
34
|
isArrayItemTemplateRoot: ()=>isArrayItemTemplateRoot,
|
|
35
35
|
isJsonObject: ()=>isJsonObject,
|
|
36
|
+
isPathCollapsed: ()=>isPathCollapsed,
|
|
36
37
|
removeValueAtPath: ()=>removeValueAtPath,
|
|
37
38
|
schemaDisplayType: ()=>schemaDisplayType,
|
|
38
39
|
setValueAtPath: ()=>setValueAtPath
|
|
@@ -41,6 +42,9 @@ const IDENTIFIER_RE = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
|
41
42
|
function hasOwn(object, key) {
|
|
42
43
|
return Object.prototype.hasOwnProperty.call(object, key);
|
|
43
44
|
}
|
|
45
|
+
function isPathCollapsed(collapsed, path) {
|
|
46
|
+
return hasOwn(collapsed, path) && !!collapsed[path];
|
|
47
|
+
}
|
|
44
48
|
function isJsonObject(value) {
|
|
45
49
|
return 'object' == typeof value && null !== value && !Array.isArray(value);
|
|
46
50
|
}
|
|
@@ -79,7 +83,29 @@ function schemaDisplayType(schema) {
|
|
|
79
83
|
if (void 0 !== enumSample) return inferValueType(enumSample);
|
|
80
84
|
return 'null';
|
|
81
85
|
}
|
|
82
|
-
function
|
|
86
|
+
function buildNodes(inputs) {
|
|
87
|
+
const roots = [];
|
|
88
|
+
const stack = [];
|
|
89
|
+
for(let index = inputs.length - 1; index >= 0; index -= 1)stack.push({
|
|
90
|
+
input: inputs[index],
|
|
91
|
+
siblings: roots
|
|
92
|
+
});
|
|
93
|
+
while(stack.length > 0){
|
|
94
|
+
const { input, siblings } = stack.pop();
|
|
95
|
+
const node = createNode(input);
|
|
96
|
+
siblings.push(node);
|
|
97
|
+
const childInputs = 'object' === node.type ? objectChildInputs(input.hasValue ? input.value : void 0, input.schema, input.segments, input.path, input.isTemplate) : 'array' === node.type ? arrayChildInputs(input.schema, input.value, input.hasValue, input.segments, input.path, input.isTemplate) : void 0;
|
|
98
|
+
if (!childInputs) continue;
|
|
99
|
+
const children = [];
|
|
100
|
+
node.children = children;
|
|
101
|
+
for(let index = childInputs.length - 1; index >= 0; index -= 1)stack.push({
|
|
102
|
+
input: childInputs[index],
|
|
103
|
+
siblings: children
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return roots;
|
|
107
|
+
}
|
|
108
|
+
function createNode(input) {
|
|
83
109
|
const type = input.hasValue ? inferValueType(input.value) : schemaDisplayType(input.schema);
|
|
84
110
|
const node = {
|
|
85
111
|
key: input.key,
|
|
@@ -91,13 +117,11 @@ function buildNode(input) {
|
|
|
91
117
|
};
|
|
92
118
|
if (input.hasValue) node.value = input.value;
|
|
93
119
|
if (input.isTemplate) node.isArrayItemTemplate = true;
|
|
94
|
-
if ('object' === type) node.children = buildObjectChildren(input.hasValue ? input.value : void 0, input.schema, input.segments, input.path, input.isTemplate);
|
|
95
|
-
else if ('array' === type) node.children = buildArrayChildren(input.schema, input.value, input.hasValue, input.segments, input.path, input.isTemplate);
|
|
96
120
|
return node;
|
|
97
121
|
}
|
|
98
|
-
function
|
|
122
|
+
function arrayChildInputs(schema, value, hasValue, segments, path, isTemplate) {
|
|
99
123
|
const items = hasValue && Array.isArray(value) ? value : [];
|
|
100
|
-
if (items.length > 0) return items.map((item, index)=>
|
|
124
|
+
if (items.length > 0) return items.map((item, index)=>({
|
|
101
125
|
key: String(index),
|
|
102
126
|
segments: [
|
|
103
127
|
...segments,
|
|
@@ -110,7 +134,7 @@ function buildArrayChildren(schema, value, hasValue, segments, path, isTemplate)
|
|
|
110
134
|
isTemplate
|
|
111
135
|
}));
|
|
112
136
|
if (schema?.items) return [
|
|
113
|
-
|
|
137
|
+
{
|
|
114
138
|
key: '0',
|
|
115
139
|
segments: [
|
|
116
140
|
...segments,
|
|
@@ -120,18 +144,18 @@ function buildArrayChildren(schema, value, hasValue, segments, path, isTemplate)
|
|
|
120
144
|
schema: schema.items,
|
|
121
145
|
hasValue: false,
|
|
122
146
|
isTemplate: true
|
|
123
|
-
}
|
|
147
|
+
}
|
|
124
148
|
];
|
|
125
149
|
return [];
|
|
126
150
|
}
|
|
127
|
-
function
|
|
151
|
+
function objectChildInputs(value, schema, segments, path, isTemplate) {
|
|
128
152
|
const properties = schema?.properties ?? {};
|
|
129
153
|
const required = new Set(schema?.required ?? []);
|
|
130
154
|
const additional = 'object' == typeof schema?.additionalProperties ? schema.additionalProperties : void 0;
|
|
131
155
|
const children = [];
|
|
132
156
|
for (const [key, childSchema] of Object.entries(properties)){
|
|
133
157
|
const hasValue = void 0 !== value && hasOwn(value, key);
|
|
134
|
-
children.push(
|
|
158
|
+
children.push({
|
|
135
159
|
key,
|
|
136
160
|
segments: [
|
|
137
161
|
...segments,
|
|
@@ -143,10 +167,10 @@ function buildObjectChildren(value, schema, segments, path, isTemplate) {
|
|
|
143
167
|
hasValue,
|
|
144
168
|
required: required.has(key),
|
|
145
169
|
isTemplate
|
|
146
|
-
})
|
|
170
|
+
});
|
|
147
171
|
}
|
|
148
172
|
if (void 0 !== value) {
|
|
149
|
-
for (const [key, childValue] of Object.entries(value))if (!hasOwn(properties, key)) children.push(
|
|
173
|
+
for (const [key, childValue] of Object.entries(value))if (!hasOwn(properties, key)) children.push({
|
|
150
174
|
key,
|
|
151
175
|
segments: [
|
|
152
176
|
...segments,
|
|
@@ -156,15 +180,15 @@ function buildObjectChildren(value, schema, segments, path, isTemplate) {
|
|
|
156
180
|
schema: additional,
|
|
157
181
|
value: childValue,
|
|
158
182
|
hasValue: true
|
|
159
|
-
})
|
|
183
|
+
});
|
|
160
184
|
}
|
|
161
185
|
return children;
|
|
162
186
|
}
|
|
163
187
|
function buildJsonTree(options) {
|
|
164
188
|
const { schema, value, basePath = '' } = options;
|
|
165
189
|
const rootIsArray = void 0 !== value ? Array.isArray(value) : !!schema && 'array' === schemaDisplayType(schema);
|
|
166
|
-
if (rootIsArray) return
|
|
167
|
-
return
|
|
190
|
+
if (rootIsArray) return buildNodes(arrayChildInputs(schema, value, void 0 !== value, [], basePath));
|
|
191
|
+
return buildNodes(objectChildInputs(isJsonObject(value) ? value : void 0, schema, [], basePath));
|
|
168
192
|
}
|
|
169
193
|
function isArrayItemTemplateRoot(node) {
|
|
170
194
|
return !!node.isArrayItemTemplate && 'number' == typeof node.segments[node.segments.length - 1];
|
|
@@ -176,47 +200,76 @@ function nodeSelfMatchesQuery(node, query, displayTexts) {
|
|
|
176
200
|
if (display?.sublabel?.toLowerCase().includes(query)) return true;
|
|
177
201
|
return void 0 !== node.value && null !== node.value && 'object' != typeof node.value && String(node.value).toLowerCase().includes(query);
|
|
178
202
|
}
|
|
179
|
-
function
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
203
|
+
function indexMatches(nodes, test) {
|
|
204
|
+
const self = new Set();
|
|
205
|
+
const below = new Set();
|
|
206
|
+
const order = [];
|
|
207
|
+
const stack = [
|
|
208
|
+
...nodes
|
|
209
|
+
];
|
|
210
|
+
while(stack.length > 0){
|
|
211
|
+
const node = stack.pop();
|
|
212
|
+
order.push(node);
|
|
213
|
+
if (node.children) for (const child of node.children)stack.push(child);
|
|
214
|
+
}
|
|
215
|
+
for(let index = order.length - 1; index >= 0; index -= 1){
|
|
216
|
+
const node = order[index];
|
|
217
|
+
if (test(node)) self.add(node);
|
|
218
|
+
if (node.children?.some((child)=>self.has(child) || below.has(child))) below.add(node);
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
self,
|
|
222
|
+
below
|
|
223
|
+
};
|
|
186
224
|
}
|
|
187
225
|
function flattenJsonTree(nodes, options = {}, depth = 0) {
|
|
188
|
-
const { collapsed = {},
|
|
189
|
-
const query = options.query?.trim().toLowerCase() ?? '';
|
|
226
|
+
const { collapsed = {}, displayTexts } = options;
|
|
190
227
|
const rows = [];
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
228
|
+
const stack = [];
|
|
229
|
+
const pushChildren = (children, childDepth, query, filterPredicate)=>{
|
|
230
|
+
for(let index = children.length - 1; index >= 0; index -= 1)stack.push({
|
|
231
|
+
node: children[index],
|
|
232
|
+
depth: childDepth,
|
|
233
|
+
query,
|
|
234
|
+
filterPredicate
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
const rootQuery = options.query?.trim().toLowerCase() ?? '';
|
|
238
|
+
pushChildren(nodes, depth, rootQuery, options.filterPredicate);
|
|
239
|
+
const queryMatches = rootQuery ? indexMatches(nodes, (node)=>nodeSelfMatchesQuery(node, rootQuery, displayTexts)) : void 0;
|
|
240
|
+
const predicateMatches = options.filterPredicate ? indexMatches(nodes, options.filterPredicate) : void 0;
|
|
241
|
+
while(stack.length > 0){
|
|
242
|
+
const { node, depth: nodeDepth, query, filterPredicate } = stack.pop();
|
|
243
|
+
const selfQueryMatch = !!query && !!queryMatches?.self.has(node);
|
|
244
|
+
if (query && !selfQueryMatch && !queryMatches?.below.has(node)) continue;
|
|
245
|
+
const selfPredicateMatch = !!filterPredicate && !!predicateMatches?.self.has(node);
|
|
246
|
+
if (filterPredicate && !selfPredicateMatch && !predicateMatches?.below.has(node)) continue;
|
|
247
|
+
rows.push({
|
|
248
|
+
node,
|
|
249
|
+
depth: nodeDepth
|
|
250
|
+
});
|
|
251
|
+
if (node.children && !isPathCollapsed(collapsed, node.path)) pushChildren(node.children, nodeDepth + 1, selfQueryMatch ? '' : query, selfPredicateMatch ? void 0 : filterPredicate);
|
|
209
252
|
}
|
|
210
253
|
return rows;
|
|
211
254
|
}
|
|
212
255
|
function collectContainerPaths(nodes, depth = 0) {
|
|
213
256
|
const paths = [];
|
|
214
|
-
|
|
257
|
+
const stack = [];
|
|
258
|
+
for(let index = nodes.length - 1; index >= 0; index -= 1)stack.push({
|
|
259
|
+
node: nodes[index],
|
|
260
|
+
depth
|
|
261
|
+
});
|
|
262
|
+
while(stack.length > 0){
|
|
263
|
+
const { node, depth: nodeDepth } = stack.pop();
|
|
264
|
+
if (!node.children) continue;
|
|
215
265
|
paths.push({
|
|
216
266
|
path: node.path,
|
|
217
|
-
depth
|
|
267
|
+
depth: nodeDepth
|
|
268
|
+
});
|
|
269
|
+
for(let index = node.children.length - 1; index >= 0; index -= 1)stack.push({
|
|
270
|
+
node: node.children[index],
|
|
271
|
+
depth: nodeDepth + 1
|
|
218
272
|
});
|
|
219
|
-
for (const child of collectContainerPaths(node.children, depth + 1))paths.push(child);
|
|
220
273
|
}
|
|
221
274
|
return paths;
|
|
222
275
|
}
|
|
@@ -302,6 +355,7 @@ exports.getValueAtPath = __webpack_exports__.getValueAtPath;
|
|
|
302
355
|
exports.inferValueType = __webpack_exports__.inferValueType;
|
|
303
356
|
exports.isArrayItemTemplateRoot = __webpack_exports__.isArrayItemTemplateRoot;
|
|
304
357
|
exports.isJsonObject = __webpack_exports__.isJsonObject;
|
|
358
|
+
exports.isPathCollapsed = __webpack_exports__.isPathCollapsed;
|
|
305
359
|
exports.removeValueAtPath = __webpack_exports__.removeValueAtPath;
|
|
306
360
|
exports.schemaDisplayType = __webpack_exports__.schemaDisplayType;
|
|
307
361
|
exports.setValueAtPath = __webpack_exports__.setValueAtPath;
|
|
@@ -315,6 +369,7 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
|
315
369
|
"inferValueType",
|
|
316
370
|
"isArrayItemTemplateRoot",
|
|
317
371
|
"isJsonObject",
|
|
372
|
+
"isPathCollapsed",
|
|
318
373
|
"removeValueAtPath",
|
|
319
374
|
"schemaDisplayType",
|
|
320
375
|
"setValueAtPath"
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import type { JsonContainer, JsonObject, JsonSchema, JsonTreeNode, JsonTreeNodeType, JsonValue, PathSegment } from './JsonTree.types';
|
|
2
|
+
/**
|
|
3
|
+
* Whether `path` is collapsed. Own keys only: paths are arbitrary JSON keys, and
|
|
4
|
+
* one named after an Object.prototype member (`constructor`, `toString`, …)
|
|
5
|
+
* would otherwise read the inherited function and stay collapsed.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isPathCollapsed(collapsed: Record<string, boolean>, path: string): boolean;
|
|
2
8
|
export declare function isJsonObject(value: JsonValue | undefined): value is JsonObject;
|
|
3
9
|
/** Appends a segment to an expression path (`a.b`, `a["x-y"]`, `a[0]`). */
|
|
4
10
|
export declare function appendPathSegment(path: string, segment: PathSegment): string;
|
|
@@ -48,13 +54,20 @@ export interface FlattenOptions {
|
|
|
48
54
|
/** Lets search also match consumer display labels (e.g. decoration labels). */
|
|
49
55
|
displayTexts?: NodeDisplayTexts;
|
|
50
56
|
}
|
|
51
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Flattens the tree to visible rows, honoring collapse state, search, and filter.
|
|
59
|
+
* Walks depth-first with an explicit stack rather than recursion, so a deeply
|
|
60
|
+
* nested tree can't overflow the call stack.
|
|
61
|
+
*/
|
|
52
62
|
export declare function flattenJsonTree(nodes: JsonTreeNode[], options?: FlattenOptions, depth?: number): FlatJsonTreeRow[];
|
|
53
63
|
export interface ContainerPath {
|
|
54
64
|
path: string;
|
|
55
65
|
depth: number;
|
|
56
66
|
}
|
|
57
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* All container (object/array) paths in the tree, with their depth, in tree
|
|
69
|
+
* order. Walks with an explicit stack, so deep trees can't overflow the call stack.
|
|
70
|
+
*/
|
|
58
71
|
export declare function collectContainerPaths(nodes: JsonTreeNode[], depth?: number): ContainerPath[];
|
|
59
72
|
export declare function getValueAtPath(root: JsonValue | undefined, segments: PathSegment[]): JsonValue | undefined;
|
|
60
73
|
/**
|
|
@@ -2,6 +2,9 @@ const IDENTIFIER_RE = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
|
2
2
|
function hasOwn(object, key) {
|
|
3
3
|
return Object.prototype.hasOwnProperty.call(object, key);
|
|
4
4
|
}
|
|
5
|
+
function isPathCollapsed(collapsed, path) {
|
|
6
|
+
return hasOwn(collapsed, path) && !!collapsed[path];
|
|
7
|
+
}
|
|
5
8
|
function isJsonObject(value) {
|
|
6
9
|
return 'object' == typeof value && null !== value && !Array.isArray(value);
|
|
7
10
|
}
|
|
@@ -40,7 +43,29 @@ function schemaDisplayType(schema) {
|
|
|
40
43
|
if (void 0 !== enumSample) return inferValueType(enumSample);
|
|
41
44
|
return 'null';
|
|
42
45
|
}
|
|
43
|
-
function
|
|
46
|
+
function buildNodes(inputs) {
|
|
47
|
+
const roots = [];
|
|
48
|
+
const stack = [];
|
|
49
|
+
for(let index = inputs.length - 1; index >= 0; index -= 1)stack.push({
|
|
50
|
+
input: inputs[index],
|
|
51
|
+
siblings: roots
|
|
52
|
+
});
|
|
53
|
+
while(stack.length > 0){
|
|
54
|
+
const { input, siblings } = stack.pop();
|
|
55
|
+
const node = createNode(input);
|
|
56
|
+
siblings.push(node);
|
|
57
|
+
const childInputs = 'object' === node.type ? objectChildInputs(input.hasValue ? input.value : void 0, input.schema, input.segments, input.path, input.isTemplate) : 'array' === node.type ? arrayChildInputs(input.schema, input.value, input.hasValue, input.segments, input.path, input.isTemplate) : void 0;
|
|
58
|
+
if (!childInputs) continue;
|
|
59
|
+
const children = [];
|
|
60
|
+
node.children = children;
|
|
61
|
+
for(let index = childInputs.length - 1; index >= 0; index -= 1)stack.push({
|
|
62
|
+
input: childInputs[index],
|
|
63
|
+
siblings: children
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return roots;
|
|
67
|
+
}
|
|
68
|
+
function createNode(input) {
|
|
44
69
|
const type = input.hasValue ? inferValueType(input.value) : schemaDisplayType(input.schema);
|
|
45
70
|
const node = {
|
|
46
71
|
key: input.key,
|
|
@@ -52,13 +77,11 @@ function buildNode(input) {
|
|
|
52
77
|
};
|
|
53
78
|
if (input.hasValue) node.value = input.value;
|
|
54
79
|
if (input.isTemplate) node.isArrayItemTemplate = true;
|
|
55
|
-
if ('object' === type) node.children = buildObjectChildren(input.hasValue ? input.value : void 0, input.schema, input.segments, input.path, input.isTemplate);
|
|
56
|
-
else if ('array' === type) node.children = buildArrayChildren(input.schema, input.value, input.hasValue, input.segments, input.path, input.isTemplate);
|
|
57
80
|
return node;
|
|
58
81
|
}
|
|
59
|
-
function
|
|
82
|
+
function arrayChildInputs(schema, value, hasValue, segments, path, isTemplate) {
|
|
60
83
|
const items = hasValue && Array.isArray(value) ? value : [];
|
|
61
|
-
if (items.length > 0) return items.map((item, index)=>
|
|
84
|
+
if (items.length > 0) return items.map((item, index)=>({
|
|
62
85
|
key: String(index),
|
|
63
86
|
segments: [
|
|
64
87
|
...segments,
|
|
@@ -71,7 +94,7 @@ function buildArrayChildren(schema, value, hasValue, segments, path, isTemplate)
|
|
|
71
94
|
isTemplate
|
|
72
95
|
}));
|
|
73
96
|
if (schema?.items) return [
|
|
74
|
-
|
|
97
|
+
{
|
|
75
98
|
key: '0',
|
|
76
99
|
segments: [
|
|
77
100
|
...segments,
|
|
@@ -81,18 +104,18 @@ function buildArrayChildren(schema, value, hasValue, segments, path, isTemplate)
|
|
|
81
104
|
schema: schema.items,
|
|
82
105
|
hasValue: false,
|
|
83
106
|
isTemplate: true
|
|
84
|
-
}
|
|
107
|
+
}
|
|
85
108
|
];
|
|
86
109
|
return [];
|
|
87
110
|
}
|
|
88
|
-
function
|
|
111
|
+
function objectChildInputs(value, schema, segments, path, isTemplate) {
|
|
89
112
|
const properties = schema?.properties ?? {};
|
|
90
113
|
const required = new Set(schema?.required ?? []);
|
|
91
114
|
const additional = 'object' == typeof schema?.additionalProperties ? schema.additionalProperties : void 0;
|
|
92
115
|
const children = [];
|
|
93
116
|
for (const [key, childSchema] of Object.entries(properties)){
|
|
94
117
|
const hasValue = void 0 !== value && hasOwn(value, key);
|
|
95
|
-
children.push(
|
|
118
|
+
children.push({
|
|
96
119
|
key,
|
|
97
120
|
segments: [
|
|
98
121
|
...segments,
|
|
@@ -104,10 +127,10 @@ function buildObjectChildren(value, schema, segments, path, isTemplate) {
|
|
|
104
127
|
hasValue,
|
|
105
128
|
required: required.has(key),
|
|
106
129
|
isTemplate
|
|
107
|
-
})
|
|
130
|
+
});
|
|
108
131
|
}
|
|
109
132
|
if (void 0 !== value) {
|
|
110
|
-
for (const [key, childValue] of Object.entries(value))if (!hasOwn(properties, key)) children.push(
|
|
133
|
+
for (const [key, childValue] of Object.entries(value))if (!hasOwn(properties, key)) children.push({
|
|
111
134
|
key,
|
|
112
135
|
segments: [
|
|
113
136
|
...segments,
|
|
@@ -117,15 +140,15 @@ function buildObjectChildren(value, schema, segments, path, isTemplate) {
|
|
|
117
140
|
schema: additional,
|
|
118
141
|
value: childValue,
|
|
119
142
|
hasValue: true
|
|
120
|
-
})
|
|
143
|
+
});
|
|
121
144
|
}
|
|
122
145
|
return children;
|
|
123
146
|
}
|
|
124
147
|
function buildJsonTree(options) {
|
|
125
148
|
const { schema, value, basePath = '' } = options;
|
|
126
149
|
const rootIsArray = void 0 !== value ? Array.isArray(value) : !!schema && 'array' === schemaDisplayType(schema);
|
|
127
|
-
if (rootIsArray) return
|
|
128
|
-
return
|
|
150
|
+
if (rootIsArray) return buildNodes(arrayChildInputs(schema, value, void 0 !== value, [], basePath));
|
|
151
|
+
return buildNodes(objectChildInputs(isJsonObject(value) ? value : void 0, schema, [], basePath));
|
|
129
152
|
}
|
|
130
153
|
function isArrayItemTemplateRoot(node) {
|
|
131
154
|
return !!node.isArrayItemTemplate && 'number' == typeof node.segments[node.segments.length - 1];
|
|
@@ -137,47 +160,76 @@ function nodeSelfMatchesQuery(node, query, displayTexts) {
|
|
|
137
160
|
if (display?.sublabel?.toLowerCase().includes(query)) return true;
|
|
138
161
|
return void 0 !== node.value && null !== node.value && 'object' != typeof node.value && String(node.value).toLowerCase().includes(query);
|
|
139
162
|
}
|
|
140
|
-
function
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
163
|
+
function indexMatches(nodes, test) {
|
|
164
|
+
const self = new Set();
|
|
165
|
+
const below = new Set();
|
|
166
|
+
const order = [];
|
|
167
|
+
const stack = [
|
|
168
|
+
...nodes
|
|
169
|
+
];
|
|
170
|
+
while(stack.length > 0){
|
|
171
|
+
const node = stack.pop();
|
|
172
|
+
order.push(node);
|
|
173
|
+
if (node.children) for (const child of node.children)stack.push(child);
|
|
174
|
+
}
|
|
175
|
+
for(let index = order.length - 1; index >= 0; index -= 1){
|
|
176
|
+
const node = order[index];
|
|
177
|
+
if (test(node)) self.add(node);
|
|
178
|
+
if (node.children?.some((child)=>self.has(child) || below.has(child))) below.add(node);
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
self,
|
|
182
|
+
below
|
|
183
|
+
};
|
|
147
184
|
}
|
|
148
185
|
function flattenJsonTree(nodes, options = {}, depth = 0) {
|
|
149
|
-
const { collapsed = {},
|
|
150
|
-
const query = options.query?.trim().toLowerCase() ?? '';
|
|
186
|
+
const { collapsed = {}, displayTexts } = options;
|
|
151
187
|
const rows = [];
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
188
|
+
const stack = [];
|
|
189
|
+
const pushChildren = (children, childDepth, query, filterPredicate)=>{
|
|
190
|
+
for(let index = children.length - 1; index >= 0; index -= 1)stack.push({
|
|
191
|
+
node: children[index],
|
|
192
|
+
depth: childDepth,
|
|
193
|
+
query,
|
|
194
|
+
filterPredicate
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
const rootQuery = options.query?.trim().toLowerCase() ?? '';
|
|
198
|
+
pushChildren(nodes, depth, rootQuery, options.filterPredicate);
|
|
199
|
+
const queryMatches = rootQuery ? indexMatches(nodes, (node)=>nodeSelfMatchesQuery(node, rootQuery, displayTexts)) : void 0;
|
|
200
|
+
const predicateMatches = options.filterPredicate ? indexMatches(nodes, options.filterPredicate) : void 0;
|
|
201
|
+
while(stack.length > 0){
|
|
202
|
+
const { node, depth: nodeDepth, query, filterPredicate } = stack.pop();
|
|
203
|
+
const selfQueryMatch = !!query && !!queryMatches?.self.has(node);
|
|
204
|
+
if (query && !selfQueryMatch && !queryMatches?.below.has(node)) continue;
|
|
205
|
+
const selfPredicateMatch = !!filterPredicate && !!predicateMatches?.self.has(node);
|
|
206
|
+
if (filterPredicate && !selfPredicateMatch && !predicateMatches?.below.has(node)) continue;
|
|
207
|
+
rows.push({
|
|
208
|
+
node,
|
|
209
|
+
depth: nodeDepth
|
|
210
|
+
});
|
|
211
|
+
if (node.children && !isPathCollapsed(collapsed, node.path)) pushChildren(node.children, nodeDepth + 1, selfQueryMatch ? '' : query, selfPredicateMatch ? void 0 : filterPredicate);
|
|
170
212
|
}
|
|
171
213
|
return rows;
|
|
172
214
|
}
|
|
173
215
|
function collectContainerPaths(nodes, depth = 0) {
|
|
174
216
|
const paths = [];
|
|
175
|
-
|
|
217
|
+
const stack = [];
|
|
218
|
+
for(let index = nodes.length - 1; index >= 0; index -= 1)stack.push({
|
|
219
|
+
node: nodes[index],
|
|
220
|
+
depth
|
|
221
|
+
});
|
|
222
|
+
while(stack.length > 0){
|
|
223
|
+
const { node, depth: nodeDepth } = stack.pop();
|
|
224
|
+
if (!node.children) continue;
|
|
176
225
|
paths.push({
|
|
177
226
|
path: node.path,
|
|
178
|
-
depth
|
|
227
|
+
depth: nodeDepth
|
|
228
|
+
});
|
|
229
|
+
for(let index = node.children.length - 1; index >= 0; index -= 1)stack.push({
|
|
230
|
+
node: node.children[index],
|
|
231
|
+
depth: nodeDepth + 1
|
|
179
232
|
});
|
|
180
|
-
for (const child of collectContainerPaths(node.children, depth + 1))paths.push(child);
|
|
181
233
|
}
|
|
182
234
|
return paths;
|
|
183
235
|
}
|
|
@@ -254,4 +306,4 @@ function formatLeafValue(type, value, options) {
|
|
|
254
306
|
if ('string' === type) return options?.preserveStringWhitespace ? `"${value}"` : JSON.stringify(value);
|
|
255
307
|
return String(value);
|
|
256
308
|
}
|
|
257
|
-
export { appendPathSegment, buildJsonTree, collectContainerPaths, flattenJsonTree, formatLeafValue, getValueAtPath, inferValueType, isArrayItemTemplateRoot, isJsonObject, removeValueAtPath, schemaDisplayType, setValueAtPath };
|
|
309
|
+
export { appendPathSegment, buildJsonTree, collectContainerPaths, flattenJsonTree, formatLeafValue, getValueAtPath, inferValueType, isArrayItemTemplateRoot, isJsonObject, isPathCollapsed, removeValueAtPath, schemaDisplayType, setValueAtPath };
|