@visualli/core 0.1.2 → 0.1.4
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/index.cjs +7 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -10
- package/dist/index.d.ts +4 -10
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/parser/visualliConverter.ts +3 -3
- package/src/parser/visualliParser.ts +1 -6
- package/src/types/index.ts +0 -1
- package/src/types/schema.ts +2 -2
- package/src/utils/navigation.ts +12 -8
package/package.json
CHANGED
|
@@ -193,14 +193,14 @@ function convertLayerWithContainers(
|
|
|
193
193
|
);
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
const byId = new Map(flatNodes.map(n => [n.id, n]));
|
|
196
|
+
const byId = new Map(flatNodes.map((n: FlatNode) => [n.id, n]));
|
|
197
197
|
const containerNodeIds = new Set<string>();
|
|
198
198
|
const containerGroups = new Map<string, FlatNode[]>();
|
|
199
199
|
|
|
200
200
|
for (const container of layer.containers) {
|
|
201
|
-
const group = container.nodes.map(id => byId.get(id)).filter((n): n is FlatNode => !!n);
|
|
201
|
+
const group = container.nodes.map((id: string) => byId.get(id)).filter((n: FlatNode | undefined): n is FlatNode => !!n);
|
|
202
202
|
if (!group.length) continue;
|
|
203
|
-
container.nodes.forEach(id => containerNodeIds.add(id));
|
|
203
|
+
container.nodes.forEach((id: string) => containerNodeIds.add(id));
|
|
204
204
|
const formation = ((container.data as unknown as Record<string, unknown> | undefined)?.['formation'] as string | undefined) ?? 'radial';
|
|
205
205
|
applyFormation(group, formation);
|
|
206
206
|
containerGroups.set(container.id, group);
|
|
@@ -104,12 +104,7 @@ export function parseVisualliFile(content: string): VisualliDocument {
|
|
|
104
104
|
return doc;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
|
|
108
|
-
* Fetch and parse a .visualli file from a URL.
|
|
109
|
-
*
|
|
110
|
-
* @throws VisualliParseError | Error
|
|
111
|
-
*/
|
|
112
|
-
export async function loadVisualliFile(url: string): Promise<VisualliDocument> {
|
|
107
|
+
export async function fetchAndParseVisualli(url: string): Promise<VisualliDocument> {
|
|
113
108
|
const response = await fetch(url);
|
|
114
109
|
if (!response.ok) {
|
|
115
110
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
package/src/types/index.ts
CHANGED
package/src/types/schema.ts
CHANGED
|
@@ -16,12 +16,12 @@ import type {
|
|
|
16
16
|
Container,
|
|
17
17
|
Layer,
|
|
18
18
|
Extension,
|
|
19
|
-
|
|
19
|
+
VisualliSpec,
|
|
20
20
|
} from '@visualli/bindings';
|
|
21
21
|
|
|
22
22
|
// ─── Re-exports ────────────────────────────────────────────────────────────────
|
|
23
23
|
// Export the generated types from bindings
|
|
24
|
-
export type { Meta, Node, Connection, Container, Layer, Extension,
|
|
24
|
+
export type { Meta, Node, Connection, Container, Layer, Extension, VisualliSpec };
|
|
25
25
|
|
|
26
26
|
// Union type for JSONL fragments
|
|
27
27
|
export type VisualliFragment = Meta | Layer;
|
package/src/utils/navigation.ts
CHANGED
|
@@ -32,17 +32,16 @@ export function getChildLayerForNode(
|
|
|
32
32
|
currentLayerId: string,
|
|
33
33
|
): VisualliLayer | null {
|
|
34
34
|
// Walk all layers looking for one whose `parentNodeId` matches
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
for (const [, layer] of doc.layers) {
|
|
36
|
+
if (layer.parentLayerId === currentLayerId && layer.parentNodeId === nodeId) {
|
|
37
|
+
return layer;
|
|
38
|
+
}
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
-
return null;
|
|
40
|
+
return null;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
45
|
-
* Returns null when the node has no child layer.
|
|
44
|
+
*
|
|
46
45
|
*/
|
|
47
46
|
export function getLayerForNavigation(
|
|
48
47
|
doc: VisualliDocument,
|
|
@@ -141,7 +140,12 @@ export function getContainersForLayer(
|
|
|
141
140
|
): ContainerGroupInfo[] {
|
|
142
141
|
const layer = doc.layers.get(layerId);
|
|
143
142
|
if (!layer) return [];
|
|
144
|
-
|
|
143
|
+
|
|
144
|
+
// Defensive: ensure containers is an array
|
|
145
|
+
const containers = layer.containers ?? [];
|
|
146
|
+
if (!Array.isArray(containers)) return [];
|
|
147
|
+
|
|
148
|
+
return containers.map(c => {
|
|
145
149
|
// Schema Container has nested data.label structure
|
|
146
150
|
const label = c.data?.label ?? c.id;
|
|
147
151
|
return { id: c.id, label, nodeIds: c.nodes, level: layer.level };
|