@nexiq/extension-sdk 1.0.2 → 1.0.3
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.
|
@@ -6,22 +6,74 @@ export const componentTask = {
|
|
|
6
6
|
const nodes = [...result.nodes];
|
|
7
7
|
const edges = [...result.edges];
|
|
8
8
|
const typeData = { ...result.typeData };
|
|
9
|
-
const entities = batch?.entities || data.entities || [];
|
|
10
9
|
const scopes = batch?.scopes || data.scopes || [];
|
|
11
10
|
const symbols = batch?.symbols || data.symbols || [];
|
|
12
11
|
const relations = batch?.relations || data.relations || [];
|
|
13
12
|
const renders = batch?.renders || data.renders || [];
|
|
14
13
|
const files = data.files || [];
|
|
15
14
|
const fileMap = new Map(files.map((f) => [f.id, f.path]));
|
|
15
|
+
// Identify automatic JSX symbols and their entities to skip them and their scopes
|
|
16
|
+
const automaticJsxEntities = new Set();
|
|
17
|
+
for (const symbol of symbols) {
|
|
18
|
+
if (symbol.name.startsWith("jsx@")) {
|
|
19
|
+
automaticJsxEntities.add(symbol.entity_id);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// Build Export Map: Map<filePath, Map<exportName, symbolId>>
|
|
23
|
+
const exportMap = new Map();
|
|
24
|
+
for (const exp of data.exports) {
|
|
25
|
+
const scope = data.scopes.find((s) => s.id === exp.scope_id);
|
|
26
|
+
if (!scope)
|
|
27
|
+
continue;
|
|
28
|
+
const filePath = fileMap.get(scope.file_id);
|
|
29
|
+
if (!filePath)
|
|
30
|
+
continue;
|
|
31
|
+
if (!exportMap.has(filePath)) {
|
|
32
|
+
exportMap.set(filePath, new Map());
|
|
33
|
+
}
|
|
34
|
+
if (exp.symbol_id) {
|
|
35
|
+
exportMap
|
|
36
|
+
.get(filePath)
|
|
37
|
+
.set(exp.is_default ? "default" : exp.name, exp.symbol_id);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Build Redirection Map: Map<importSymbolId, actualSymbolId>
|
|
41
|
+
const redirectionMap = new Map();
|
|
42
|
+
for (const symbol of data.symbols) {
|
|
43
|
+
const entity = data.entities.find((e) => e.id === symbol.entity_id);
|
|
44
|
+
if (entity?.kind === "import" && entity.data_json) {
|
|
45
|
+
try {
|
|
46
|
+
const impData = JSON.parse(entity.data_json);
|
|
47
|
+
const sourcePath = impData.source;
|
|
48
|
+
const importedName = impData.type === "default" ? "default" : impData.importedName;
|
|
49
|
+
const targetSymbolId = exportMap.get(sourcePath)?.get(importedName);
|
|
50
|
+
if (targetSymbolId) {
|
|
51
|
+
redirectionMap.set(symbol.id, targetSymbolId);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// ignore
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
16
59
|
// 1. Map Scopes to Combos
|
|
17
60
|
for (const scope of scopes) {
|
|
61
|
+
if (scope.kind === "module")
|
|
62
|
+
continue;
|
|
18
63
|
if (combos.some((c) => c.id === scope.id))
|
|
19
64
|
continue;
|
|
65
|
+
// Skip scopes belonging to automatic JSX elements
|
|
66
|
+
if (scope.entity_id && automaticJsxEntities.has(scope.entity_id))
|
|
67
|
+
continue;
|
|
68
|
+
const parentScope = data.scopes.find((s) => s.id === scope.parent_id);
|
|
69
|
+
const parentComboId = parentScope && parentScope.kind !== "module"
|
|
70
|
+
? scope.parent_id
|
|
71
|
+
: undefined;
|
|
20
72
|
combos.push({
|
|
21
73
|
id: scope.id,
|
|
22
74
|
name: scope.kind,
|
|
23
75
|
label: { text: scope.kind },
|
|
24
|
-
combo:
|
|
76
|
+
combo: parentComboId || undefined,
|
|
25
77
|
type: "scope",
|
|
26
78
|
collapsed: true,
|
|
27
79
|
});
|
|
@@ -31,13 +83,33 @@ export const componentTask = {
|
|
|
31
83
|
if (nodes.some((n) => n.id === symbol.id) ||
|
|
32
84
|
combos.some((c) => c.id === symbol.id))
|
|
33
85
|
continue;
|
|
86
|
+
// Skip automatic JSX symbols to avoid clutter
|
|
87
|
+
if (symbol.name.startsWith("jsx@"))
|
|
88
|
+
continue;
|
|
34
89
|
const entity = data.entities.find((e) => e.id === symbol.entity_id);
|
|
35
90
|
if (!entity)
|
|
36
91
|
continue;
|
|
92
|
+
// Skip imports
|
|
93
|
+
if (entity.kind === "import")
|
|
94
|
+
continue;
|
|
95
|
+
// Skip state setters (index 1 of the state array) to avoid showing both state and setter as separate nodes
|
|
96
|
+
if (entity.kind === "state" && symbol.path) {
|
|
97
|
+
try {
|
|
98
|
+
const pathArr = JSON.parse(symbol.path);
|
|
99
|
+
if (Array.isArray(pathArr) &&
|
|
100
|
+
pathArr.length > 0 &&
|
|
101
|
+
pathArr[0] !== "0") {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
// ignore
|
|
107
|
+
}
|
|
108
|
+
}
|
|
37
109
|
const scope = data.scopes.find((s) => s.id === symbol.scope_id);
|
|
38
110
|
const file = scope ? fileMap.get(scope.file_id) : undefined;
|
|
39
|
-
// Check if this symbol's entity has an associated
|
|
40
|
-
const blockScope = data.scopes.find((s) => s.entity_id === entity.id
|
|
111
|
+
// Check if this symbol's entity has an associated scope (e.g. the body)
|
|
112
|
+
const blockScope = data.scopes.find((s) => s.entity_id === entity.id);
|
|
41
113
|
if (blockScope) {
|
|
42
114
|
// This symbol represents a scope (e.g. function body)
|
|
43
115
|
// We update the combo created for this scope
|
|
@@ -48,20 +120,133 @@ export const componentTask = {
|
|
|
48
120
|
combo.type = entity.kind;
|
|
49
121
|
combo.fileName = file;
|
|
50
122
|
combo.loc = { line: entity.line || 0, column: entity.column || 0 };
|
|
123
|
+
// Handle effects for this component/hook
|
|
124
|
+
if (entity.data_json) {
|
|
125
|
+
try {
|
|
126
|
+
const metadata = JSON.parse(entity.data_json);
|
|
127
|
+
if (metadata.effects) {
|
|
128
|
+
for (const effect of Object.values(metadata.effects)) {
|
|
129
|
+
const effectName = effect.name || "useEffect";
|
|
130
|
+
nodes.push({
|
|
131
|
+
id: effect.id,
|
|
132
|
+
name: effectName,
|
|
133
|
+
label: { text: effectName },
|
|
134
|
+
combo: blockScope.id,
|
|
135
|
+
type: "effect",
|
|
136
|
+
fileName: file,
|
|
137
|
+
loc: { line: effect.loc.line, column: effect.loc.column },
|
|
138
|
+
displayName: effectName,
|
|
139
|
+
});
|
|
140
|
+
if (effect.reactDeps) {
|
|
141
|
+
for (const dep of effect.reactDeps) {
|
|
142
|
+
const targetId = redirectionMap.get(dep.id) || dep.id;
|
|
143
|
+
if (targetId) {
|
|
144
|
+
edges.push({
|
|
145
|
+
id: `${targetId}-${effect.id}-effect-dep`,
|
|
146
|
+
source: targetId,
|
|
147
|
+
target: effect.id,
|
|
148
|
+
label: "dependency",
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
// ignore
|
|
158
|
+
}
|
|
159
|
+
}
|
|
51
160
|
}
|
|
52
161
|
}
|
|
53
162
|
else {
|
|
54
|
-
//
|
|
163
|
+
// Handle destructuring paths to group variables and reduce clutter
|
|
164
|
+
let parentComboId = scope && scope.kind !== "module" ? symbol.scope_id : undefined;
|
|
165
|
+
if (symbol.path && entity.kind !== "state") {
|
|
166
|
+
try {
|
|
167
|
+
const pathArr = JSON.parse(symbol.path);
|
|
168
|
+
if (Array.isArray(pathArr) && pathArr.length >= 1) {
|
|
169
|
+
// 1. Create a "source" combo for the entity (e.g., the hook call or variable)
|
|
170
|
+
const sourceComboId = `${symbol.scope_id}:source:${symbol.entity_id}`;
|
|
171
|
+
if (!combos.some((c) => c.id === sourceComboId)) {
|
|
172
|
+
let sourceLabel = entity.name || entity.kind;
|
|
173
|
+
if (entity.kind === "hook" && entity.data_json) {
|
|
174
|
+
try {
|
|
175
|
+
const meta = JSON.parse(entity.data_json);
|
|
176
|
+
if (meta.call?.name)
|
|
177
|
+
sourceLabel = meta.call.name;
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
// ignore
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
combos.push({
|
|
184
|
+
id: sourceComboId,
|
|
185
|
+
name: sourceLabel,
|
|
186
|
+
label: { text: sourceLabel },
|
|
187
|
+
combo: parentComboId,
|
|
188
|
+
type: "source-group",
|
|
189
|
+
collapsed: true,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
parentComboId = sourceComboId;
|
|
193
|
+
// 2. Create intermediate combos for each segment of the path except the last one
|
|
194
|
+
for (let i = 0; i < pathArr.length - 1; i++) {
|
|
195
|
+
const segment = pathArr[i];
|
|
196
|
+
// Use a stable ID for the path combo nested under the source combo
|
|
197
|
+
const segmentId = `${sourceComboId}:path:${pathArr
|
|
198
|
+
.slice(0, i + 1)
|
|
199
|
+
.join("/")}`;
|
|
200
|
+
if (!combos.some((c) => c.id === segmentId)) {
|
|
201
|
+
combos.push({
|
|
202
|
+
id: segmentId,
|
|
203
|
+
name: segment.toString(),
|
|
204
|
+
label: { text: segment.toString() },
|
|
205
|
+
combo: parentComboId,
|
|
206
|
+
type: "path-group",
|
|
207
|
+
collapsed: true,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
parentComboId = segmentId;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
// ignore invalid path JSON
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const labelText = symbol.name;
|
|
219
|
+
// Handle reactDeps and special labeling for hooks
|
|
220
|
+
if (entity.data_json) {
|
|
221
|
+
try {
|
|
222
|
+
const metadata = JSON.parse(entity.data_json);
|
|
223
|
+
if (metadata.reactDeps) {
|
|
224
|
+
for (const dep of metadata.reactDeps) {
|
|
225
|
+
const targetId = redirectionMap.get(dep.id) || dep.id;
|
|
226
|
+
if (targetId) {
|
|
227
|
+
edges.push({
|
|
228
|
+
id: `${targetId}-${symbol.id}-react-dep`,
|
|
229
|
+
source: targetId,
|
|
230
|
+
target: symbol.id,
|
|
231
|
+
label: "dependency",
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
// ignore
|
|
239
|
+
}
|
|
240
|
+
}
|
|
55
241
|
nodes.push({
|
|
56
242
|
id: symbol.id,
|
|
57
243
|
name: symbol.name,
|
|
58
|
-
label: { text:
|
|
59
|
-
combo:
|
|
244
|
+
label: { text: labelText },
|
|
245
|
+
combo: parentComboId,
|
|
60
246
|
type: entity.kind,
|
|
61
247
|
fileName: file,
|
|
62
248
|
loc: { line: entity.line || 0, column: entity.column || 0 },
|
|
63
249
|
displayName: symbol.name,
|
|
64
|
-
radius: 10,
|
|
65
250
|
});
|
|
66
251
|
}
|
|
67
252
|
}
|
|
@@ -71,50 +256,68 @@ export const componentTask = {
|
|
|
71
256
|
combos.some((c) => c.id === render.id))
|
|
72
257
|
continue;
|
|
73
258
|
const file = fileMap.get(render.file_id);
|
|
74
|
-
const
|
|
75
|
-
|
|
259
|
+
const parentScope = data.scopes.find((s) => s.entity_id === render.parent_entity_id);
|
|
260
|
+
const parentCombo = parentScope?.id;
|
|
261
|
+
// Create a "render" group combo within the parent combo if not exists
|
|
262
|
+
let finalParentCombo = render.parent_render_id ?? parentCombo;
|
|
263
|
+
if (parentCombo && !render.parent_render_id) {
|
|
264
|
+
const renderGroupId = `render-group-${parentCombo}`;
|
|
265
|
+
if (!combos.some((c) => c.id === renderGroupId)) {
|
|
266
|
+
combos.push({
|
|
267
|
+
id: renderGroupId,
|
|
268
|
+
name: "render",
|
|
269
|
+
label: { text: "render" },
|
|
270
|
+
combo: parentCombo,
|
|
271
|
+
type: "render-group",
|
|
272
|
+
collapsed: true,
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
finalParentCombo = renderGroupId;
|
|
276
|
+
}
|
|
277
|
+
const labelText = render.tag;
|
|
76
278
|
const commonData = {
|
|
77
279
|
id: render.id,
|
|
78
280
|
name: render.tag,
|
|
79
|
-
label: { text:
|
|
80
|
-
combo:
|
|
281
|
+
label: { text: labelText },
|
|
282
|
+
combo: finalParentCombo,
|
|
81
283
|
type: "render",
|
|
82
284
|
fileName: file,
|
|
83
285
|
loc: { line: render.line || 0, column: render.column || 0 },
|
|
84
286
|
displayName: render.tag,
|
|
85
287
|
};
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
288
|
+
// Renders are now nodes that stack within the component combo
|
|
289
|
+
combos.push(commonData);
|
|
290
|
+
// Add edge for JSX hierarchy
|
|
291
|
+
// if (render.parent_render_id) {
|
|
292
|
+
// edges.push({
|
|
293
|
+
// id: `${render.parent_render_id}-${render.id}-nesting`,
|
|
294
|
+
// source: render.parent_render_id,
|
|
295
|
+
// target: render.id,
|
|
296
|
+
// label: "nesting",
|
|
297
|
+
// });
|
|
298
|
+
// }
|
|
299
|
+
// if (render.symbol_id) {
|
|
300
|
+
// const targetId =
|
|
301
|
+
// redirectionMap.get(render.symbol_id) || render.symbol_id;
|
|
302
|
+
// edges.push({
|
|
303
|
+
// id: `${render.id}-${targetId}`,
|
|
304
|
+
// source: render.id,
|
|
305
|
+
// target: targetId,
|
|
306
|
+
// label: "reference",
|
|
307
|
+
// });
|
|
308
|
+
// }
|
|
108
309
|
}
|
|
109
310
|
// 4. Handle Relations (Edges)
|
|
110
311
|
for (const rel of relations) {
|
|
111
|
-
const
|
|
312
|
+
const sourceId = redirectionMap.get(rel.from_id) || rel.from_id;
|
|
313
|
+
const targetId = redirectionMap.get(rel.to_id) || rel.to_id;
|
|
314
|
+
const edgeId = `${sourceId}-${targetId}-${rel.kind}`;
|
|
112
315
|
if (edges.some((e) => e.id === edgeId))
|
|
113
316
|
continue;
|
|
114
317
|
edges.push({
|
|
115
318
|
id: edgeId,
|
|
116
|
-
source:
|
|
117
|
-
target:
|
|
319
|
+
source: sourceId,
|
|
320
|
+
target: targetId,
|
|
118
321
|
label: rel.kind,
|
|
119
322
|
});
|
|
120
323
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|