@3plate/graph-core 0.1.15 → 0.1.17

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.d.cts CHANGED
@@ -213,6 +213,12 @@ type EventsOptions<N, E> = {
213
213
  };
214
214
  /** Function to render a node */
215
215
  type RenderNode<N> = (node: N, props?: NodeProps<N>) => HTMLElement;
216
+ /**
217
+ * Function called after a node element has been mounted to the DOM.
218
+ * Use this to integrate framework-specific rendering (e.g. React, Vue) into node content.
219
+ * The returned function, if any, is called when the node is removed.
220
+ */
221
+ type MountNode<N> = (node: N, element: HTMLElement) => (() => void) | void;
216
222
  /** Color mode */
217
223
  type ColorMode = 'light' | 'dark' | 'system';
218
224
  /** Canvas background and general colors */
@@ -265,6 +271,12 @@ type CanvasOptions<N> = {
265
271
  panZoom?: boolean;
266
272
  /** Function to render a node */
267
273
  renderNode?: RenderNode<N>;
274
+ /**
275
+ * Called after a node element is mounted to the DOM.
276
+ * Use this to integrate framework renderers (React, Vue, etc.) into node content.
277
+ * Return a cleanup function to be called when the node is removed.
278
+ */
279
+ mountNode?: MountNode<N>;
268
280
  /** Color mode */
269
281
  colorMode?: ColorMode;
270
282
  /** Theme */
@@ -718,4 +730,4 @@ declare class Playground {
718
730
 
719
731
  declare function graph<N, E>(args?: APIArguments<N, E>): Promise<API<N, E>>;
720
732
 
721
- export { API, type APIArguments, type APIOptions, type CanvasTheme, type ColorMode, type EdgeProps, type EdgeTheme, type EventsOptions, type Example, type ExampleEdge, type ExampleNode, type ExampleOptions, FileSource, type FileSourceArgs, type FileStatus, type FileStatusListener, FileSystemSource, type FileSystemSourceArgs, type HistoryMessage, Ingest, type IngestMessage, type IngestionConfig, type NewEdge, type NewNode, type NodeAlign, type NodeProps, type NodeTheme, type Orientation, Playground, type PlaygroundOptions, type PortProps, type PortStyle, type PortTheme, type RenderNode, type SnapshotMessage, type ThemeVars, type Update, type UpdateMessage, Updater, WebSocketSource, type WebSocketSourceArgs, type WebSocketStatus, type WebSocketStatusListener, graph as default, graph };
733
+ export { API, type APIArguments, type APIOptions, type CanvasOptions, type CanvasTheme, type ColorMode, type EdgeProps, type EdgeTheme, type EventsOptions, type Example, type ExampleEdge, type ExampleNode, type ExampleOptions, FileSource, type FileSourceArgs, type FileStatus, type FileStatusListener, FileSystemSource, type FileSystemSourceArgs, type HistoryMessage, Ingest, type IngestMessage, type IngestionConfig, type MountNode, type NewEdge, type NewNode, type NodeAlign, type NodeProps, type NodeTheme, type Orientation, Playground, type PlaygroundOptions, type PortProps, type PortStyle, type PortTheme, type RenderNode, type SnapshotMessage, type ThemeVars, type Update, type UpdateMessage, Updater, WebSocketSource, type WebSocketSourceArgs, type WebSocketStatus, type WebSocketStatusListener, graph as default, graph };
package/dist/index.d.ts CHANGED
@@ -213,6 +213,12 @@ type EventsOptions<N, E> = {
213
213
  };
214
214
  /** Function to render a node */
215
215
  type RenderNode<N> = (node: N, props?: NodeProps<N>) => HTMLElement;
216
+ /**
217
+ * Function called after a node element has been mounted to the DOM.
218
+ * Use this to integrate framework-specific rendering (e.g. React, Vue) into node content.
219
+ * The returned function, if any, is called when the node is removed.
220
+ */
221
+ type MountNode<N> = (node: N, element: HTMLElement) => (() => void) | void;
216
222
  /** Color mode */
217
223
  type ColorMode = 'light' | 'dark' | 'system';
218
224
  /** Canvas background and general colors */
@@ -265,6 +271,12 @@ type CanvasOptions<N> = {
265
271
  panZoom?: boolean;
266
272
  /** Function to render a node */
267
273
  renderNode?: RenderNode<N>;
274
+ /**
275
+ * Called after a node element is mounted to the DOM.
276
+ * Use this to integrate framework renderers (React, Vue, etc.) into node content.
277
+ * Return a cleanup function to be called when the node is removed.
278
+ */
279
+ mountNode?: MountNode<N>;
268
280
  /** Color mode */
269
281
  colorMode?: ColorMode;
270
282
  /** Theme */
@@ -718,4 +730,4 @@ declare class Playground {
718
730
 
719
731
  declare function graph<N, E>(args?: APIArguments<N, E>): Promise<API<N, E>>;
720
732
 
721
- export { API, type APIArguments, type APIOptions, type CanvasTheme, type ColorMode, type EdgeProps, type EdgeTheme, type EventsOptions, type Example, type ExampleEdge, type ExampleNode, type ExampleOptions, FileSource, type FileSourceArgs, type FileStatus, type FileStatusListener, FileSystemSource, type FileSystemSourceArgs, type HistoryMessage, Ingest, type IngestMessage, type IngestionConfig, type NewEdge, type NewNode, type NodeAlign, type NodeProps, type NodeTheme, type Orientation, Playground, type PlaygroundOptions, type PortProps, type PortStyle, type PortTheme, type RenderNode, type SnapshotMessage, type ThemeVars, type Update, type UpdateMessage, Updater, WebSocketSource, type WebSocketSourceArgs, type WebSocketStatus, type WebSocketStatusListener, graph as default, graph };
733
+ export { API, type APIArguments, type APIOptions, type CanvasOptions, type CanvasTheme, type ColorMode, type EdgeProps, type EdgeTheme, type EventsOptions, type Example, type ExampleEdge, type ExampleNode, type ExampleOptions, FileSource, type FileSourceArgs, type FileStatus, type FileStatusListener, FileSystemSource, type FileSystemSourceArgs, type HistoryMessage, Ingest, type IngestMessage, type IngestionConfig, type MountNode, type NewEdge, type NewNode, type NodeAlign, type NodeProps, type NodeTheme, type Orientation, Playground, type PlaygroundOptions, type PortProps, type PortStyle, type PortTheme, type RenderNode, type SnapshotMessage, type ThemeVars, type Update, type UpdateMessage, Updater, WebSocketSource, type WebSocketSourceArgs, type WebSocketStatus, type WebSocketStatusListener, graph as default, graph };
package/dist/index.js CHANGED
@@ -1971,6 +1971,8 @@ var Node2 = class {
1971
1971
  hovered;
1972
1972
  container;
1973
1973
  content;
1974
+ innerContent;
1975
+ cleanup;
1974
1976
  canvas;
1975
1977
  data;
1976
1978
  isDummy;
@@ -1985,10 +1987,13 @@ var Node2 = class {
1985
1987
  const size = canvas.dummyNodeSize;
1986
1988
  } else {
1987
1989
  const render = data.render ?? canvas.renderNode;
1988
- this.content = this.renderContent(render(data.data, data));
1990
+ const innerEl = render(data.data, data);
1991
+ this.innerContent = innerEl;
1992
+ this.content = this.renderContent(innerEl);
1989
1993
  }
1990
1994
  }
1991
1995
  remove() {
1996
+ this.cleanup?.();
1992
1997
  this.container.remove();
1993
1998
  }
1994
1999
  append() {
@@ -2929,7 +2934,24 @@ var Canvas = class {
2929
2934
  newNodes.set(data.data, node);
2930
2935
  this.measurement.appendChild(node.content);
2931
2936
  }
2932
- await new Promise(requestAnimationFrame);
2937
+ if (this.mountNode) {
2938
+ for (const node of newNodes.values()) {
2939
+ if (node.innerContent) {
2940
+ node.cleanup = this.mountNode(node.data.data, node.innerContent) ?? void 0;
2941
+ }
2942
+ }
2943
+ }
2944
+ await new Promise((resolve) => {
2945
+ let resolved = false;
2946
+ const done = () => {
2947
+ if (!resolved) {
2948
+ resolved = true;
2949
+ resolve();
2950
+ }
2951
+ };
2952
+ requestAnimationFrame(done);
2953
+ setTimeout(done, 50);
2954
+ });
2933
2955
  const isVertical = this.orientation === "TB" || this.orientation === "BT";
2934
2956
  for (const node of newNodes.values()) {
2935
2957
  node.measure(isVertical);