@visualli/core 0.1.2 → 0.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visualli/core",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Framework-agnostic core logic, types, and engines for Visualli",
5
5
  "repository": {
6
6
  "type": "git",
@@ -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}`);
@@ -12,6 +12,5 @@ export {
12
12
  type Layer,
13
13
  type Connection,
14
14
  type Extension,
15
- type VisualliSpec011,
16
15
  type VisualliFragment,
17
16
  } from './schema.js';
@@ -16,12 +16,12 @@ import type {
16
16
  Container,
17
17
  Layer,
18
18
  Extension,
19
- VisualliSpec011,
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, VisualliSpec011 };
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;
@@ -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
- for (const [, layer] of doc.layers) {
36
- if (layer.parentLayerId === currentLayerId && layer.parentNodeId === nodeId) {
37
- return layer;
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
- * Returns the layer to navigate INTO when double-clicking `nodeId` in `currentLayerId`.
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
- return layer.containers.map(c => {
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 };