@fxhash/open-form-graph 0.0.2 → 0.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.
@@ -0,0 +1,313 @@
1
+ import { ColorTransform, Focus, HighlightStyle, MouseListener, Point, RGB, RawGraphData, RootNodeImageSources, SimNode, ThemeMode, Transform, TransformListener } from "./_types-CjgCTzqc.js";
2
+ import { Dispatch, MutableRefObject, ReactNode } from "react";
3
+ import * as react_jsx_runtime1 from "react/jsx-runtime";
4
+ import * as d3_scale2 from "d3-scale";
5
+ import { EventEmitter } from "@fxhash/utils";
6
+
7
+ //#region src/_interfaces.d.ts
8
+ interface GraphConfig {
9
+ debug: false;
10
+ nodeSize: number;
11
+ minClusterSize: number;
12
+ maxClusterSize: number;
13
+ minZoom: number;
14
+ maxZoom: number;
15
+ theme: {
16
+ dark: [number, number, number];
17
+ light: [number, number, number];
18
+ };
19
+ }
20
+ //#endregion
21
+ //#region src/util/color.d.ts
22
+ interface ColorHandler {
23
+ (arg?: number): string;
24
+ (arg: ColorTransform): ColorHandler;
25
+ rgb: RGB;
26
+ }
27
+ /**
28
+ * Some utility functions to handle colors
29
+ */
30
+ declare function color(rgb: RGB): ColorHandler;
31
+ /**
32
+ * Dims a color to white or black
33
+ * @param color An array of 3 numbers representing RGB values (0-255)
34
+ * @param dimFactor A value between 0 and 1 where 0 is completely black and 1 is the original color
35
+ * @returns A new array with the dimmed RGB values
36
+ */
37
+ declare function dim(factor?: number, white?: boolean): ColorTransform;
38
+ //#endregion
39
+ //#region src/sim/TransformCanvas.d.ts
40
+ declare class TransformCanvas {
41
+ private canvas;
42
+ private transform;
43
+ private targetTransform;
44
+ private isAnimating;
45
+ private animationFrame;
46
+ private focus;
47
+ private offset;
48
+ private isDragging;
49
+ private dragStart;
50
+ private hasMoved;
51
+ private lastPointerPos;
52
+ private lastMovePos;
53
+ private velocity;
54
+ private lastDragTime;
55
+ private momentumFrame;
56
+ private touchStart;
57
+ private pinchStartDist;
58
+ private pinchStartScale;
59
+ private noInteraction;
60
+ private dpr;
61
+ private resizeObserver;
62
+ private mediaQueryList;
63
+ onUpdate?: TransformListener;
64
+ onClick?: MouseListener;
65
+ onMove?: MouseListener;
66
+ constructor(canvas: HTMLCanvasElement, options?: {
67
+ onUpdate?: TransformListener;
68
+ onClick?: MouseListener;
69
+ onMove?: MouseListener;
70
+ offset?: Point;
71
+ });
72
+ private bindEventHandlers;
73
+ private attachEventListeners;
74
+ private setupDPRMonitoring;
75
+ private updateDPR;
76
+ toCanvasCoords(clientX: number, clientY: number): Point;
77
+ private toCSSCoords;
78
+ private startMomentum;
79
+ private applyMomentum;
80
+ private lerp;
81
+ private animateTransform;
82
+ private startAnimation;
83
+ private stopAnimation;
84
+ private interruptAnimation;
85
+ private handleWheel;
86
+ private handleMouseDown;
87
+ private handleMouseMove;
88
+ private handleMouseUp;
89
+ private handleCanvasClick;
90
+ private handleTouchStart;
91
+ private handleTouchMove;
92
+ private handleTouchEnd;
93
+ resetZoom(): void;
94
+ transformTo(update: Partial<Transform>): void;
95
+ getTransformationFromWorld(worldX: number, worldY: number, newScale?: number): {
96
+ x: number;
97
+ y: number;
98
+ scale: number;
99
+ };
100
+ transformToWorld(worldX: number, worldY: number, newScale?: number): void;
101
+ trackCursor(): void;
102
+ setNoInteraction(noInteraction: boolean): void;
103
+ focusOn(focus: Focus | null): void;
104
+ resetFocus(): void;
105
+ destroy(): void;
106
+ getTransform(): Readonly<Transform>;
107
+ getTargetTransform(): Readonly<Transform>;
108
+ getFocus(): Readonly<Focus | null>;
109
+ setOffset(offset: Point): void;
110
+ }
111
+ //#endregion
112
+ //#region src/sim/_interfaces.d.ts
113
+ interface IOpenGraphSimulation {
114
+ width: number;
115
+ height: number;
116
+ config: GraphConfig;
117
+ rootImageSources: RootNodeImageSources;
118
+ canvas: HTMLCanvasElement;
119
+ theme: ThemeMode;
120
+ emitter: OpenGraphEventEmitter;
121
+ selectedNode: SimNode | null;
122
+ hoveredNode: SimNode | null;
123
+ highlights: HighlightStyle[];
124
+ transformCanvas: TransformCanvas;
125
+ initialize(data: RawGraphData, rootId: string): void;
126
+ restart(): void;
127
+ resize(width: number, height: number): void;
128
+ setTheme(theme: ThemeMode): void;
129
+ setHideThumbnails(hide: boolean): void;
130
+ setSelectedNode(node: SimNode | null): void;
131
+ setHighlights(highlights: HighlightStyle[]): void;
132
+ setNoInteraction(noInteraction: boolean): void;
133
+ getNodeById(nodeId: string): SimNode | null;
134
+ getNodeScreenPosition(node: SimNode): {
135
+ x: number;
136
+ y: number;
137
+ };
138
+ getNodeSize(nodeId: string): number;
139
+ destroy(): void;
140
+ }
141
+ type OpenGraphEventsTypemap = {
142
+ "transform-changed": Transform;
143
+ "hovered-node-changed": SimNode | null;
144
+ "selected-node-changed": SimNode | null;
145
+ draw: IOpenGraphSimulation;
146
+ };
147
+ declare class OpenGraphEventEmitter extends EventEmitter<OpenGraphEventsTypemap> {}
148
+ //#endregion
149
+ //#region src/sim/OpenGraphSimulation.d.ts
150
+ interface OpenGraphSimulationProps {
151
+ width: number;
152
+ height: number;
153
+ config?: GraphConfig;
154
+ rootImageSources?: RootNodeImageSources;
155
+ canvas: HTMLCanvasElement;
156
+ theme?: ThemeMode;
157
+ loadNodeImage?: (node: SimNode) => Promise<string | undefined>;
158
+ translate?: {
159
+ x: number;
160
+ y: number;
161
+ };
162
+ lockedNodeId?: string;
163
+ highlights?: HighlightStyle[];
164
+ }
165
+ declare class OpenGraphSimulation implements IOpenGraphSimulation {
166
+ width: number;
167
+ height: number;
168
+ config: GraphConfig;
169
+ rootImageSources: RootNodeImageSources;
170
+ canvas: HTMLCanvasElement;
171
+ transformCanvas: TransformCanvas;
172
+ theme: ThemeMode;
173
+ private rawData?;
174
+ emitter: OpenGraphEventEmitter;
175
+ private translate;
176
+ private data;
177
+ private prunedData;
178
+ private subGraph;
179
+ private rootId;
180
+ private simulation;
181
+ private clusterSizeRange;
182
+ private maxDepth;
183
+ private isTicking;
184
+ private tickCount;
185
+ private loadNodeImage?;
186
+ private imageCache;
187
+ private rootImages;
188
+ private hideThumbnails;
189
+ private noInteraction;
190
+ lockedNodeId?: string;
191
+ selectedNode: SimNode | null;
192
+ hoveredNode: SimNode | null;
193
+ highlights: HighlightStyle[];
194
+ private renderLayers;
195
+ constructor(props: OpenGraphSimulationProps);
196
+ private get center();
197
+ private get origin();
198
+ private getNodeAtPosition;
199
+ getNodeScreenPosition: (node: SimNode) => {
200
+ x: number;
201
+ y: number;
202
+ };
203
+ getNodeCanvasPosition: (node: SimNode) => {
204
+ x: number;
205
+ y: number;
206
+ };
207
+ screenToWorld(_x: number, _y: number): {
208
+ x: number;
209
+ y: number;
210
+ };
211
+ worldToScreen(worldX: number, worldY: number): {
212
+ x: number;
213
+ y: number;
214
+ };
215
+ handleClick: (x: number, y: number) => void;
216
+ handleClickNode: (node: SimNode | null, options?: {
217
+ noToggle?: boolean;
218
+ triggerFocus?: boolean;
219
+ }) => void;
220
+ updateScene: () => void;
221
+ handleMove: (x: number, y: number) => void;
222
+ handleTransform: (t: Transform) => void;
223
+ updateHighlights: () => void;
224
+ initialize: (data: RawGraphData, rootId: string) => void;
225
+ get lockedNode(): SimNode | null;
226
+ triggerSelected: (triggerFocus?: boolean) => void;
227
+ restart: (alpha?: number) => void;
228
+ get rootNode(): SimNode | null;
229
+ handleTick: () => void;
230
+ setTranslate({
231
+ x,
232
+ y
233
+ }: {
234
+ x: number;
235
+ y: number;
236
+ }): void;
237
+ get visiblityScale(): d3_scale2.ScaleLogarithmic<number, number, never>;
238
+ get color(): ColorHandler;
239
+ get colorContrast(): ColorHandler;
240
+ getNodeSize: (nodeId: string) => number;
241
+ private updateRenderLayers;
242
+ private renderLink;
243
+ private renderNode;
244
+ private renderSessionNode;
245
+ private renderRootNode;
246
+ private renderCollapsedNode;
247
+ private renderExpandedNode;
248
+ onDraw: () => void;
249
+ private drawDebug;
250
+ private drawDebugDepthCircles;
251
+ private onEnd;
252
+ private loadNodeImages;
253
+ destroy: () => void;
254
+ resize: (width: number, height: number) => void;
255
+ setTheme: (theme: ThemeMode) => void;
256
+ setHideThumbnails: (hide: boolean) => void;
257
+ setSelectedNode: (node: SimNode | null) => void;
258
+ private _highlightHash?;
259
+ setHighlights: (highlights: HighlightStyle[]) => void;
260
+ setNoInteraction: (noInteraction: boolean) => void;
261
+ getNodeById: (nodeId: string) => SimNode | null;
262
+ setLockedNodeId: (nodeId?: string | null) => void;
263
+ handleClickDebug: (x: number, y: number) => void;
264
+ circles: Array<Point>;
265
+ onDrawDebug: () => void;
266
+ }
267
+ //#endregion
268
+ //#region src/context/provider.d.ts
269
+ interface OpenFormGraphProviderProps {
270
+ rootId: string;
271
+ rootImageSources: RootNodeImageSources;
272
+ theme: ThemeMode;
273
+ children: ReactNode;
274
+ config?: GraphConfig;
275
+ data: RawGraphData;
276
+ onSelectedNodeChange?: (node: SimNode | null) => void;
277
+ onHoveredNodeChange?: (node: SimNode | null) => void;
278
+ lockedNodeId?: string;
279
+ }
280
+ interface OpenFormGraphApi {
281
+ rootId: string;
282
+ rootImageSources: RootNodeImageSources;
283
+ setSelectedNode: Dispatch<SimNode | null>;
284
+ setHoveredNode: Dispatch<SimNode | null>;
285
+ theme: ThemeMode;
286
+ hideThumbnails: boolean;
287
+ setHideThumbnails: Dispatch<boolean>;
288
+ config: GraphConfig;
289
+ data: RawGraphData;
290
+ simulation: MutableRefObject<OpenGraphSimulation | null>;
291
+ selectedNode: SimNode | null;
292
+ hoveredNode: SimNode | null;
293
+ setSelectedNodeById: (nodeId: string) => void;
294
+ lockedNodeId?: string;
295
+ }
296
+ declare function OpenFormGraphProvider({
297
+ theme,
298
+ rootId,
299
+ children,
300
+ rootImageSources,
301
+ config,
302
+ data,
303
+ lockedNodeId
304
+ }: OpenFormGraphProviderProps): react_jsx_runtime1.JSX.Element;
305
+ declare function useOpenFormGraph(): OpenFormGraphApi;
306
+ //#endregion
307
+ //#region src/context/constants.d.ts
308
+ declare const VOID_ROOT_ID = "void-root";
309
+ declare const VOID_DETACH_ID = "void-detach";
310
+ declare const DEFAULT_GRAPH_CONFIG: GraphConfig;
311
+ //#endregion
312
+ export { ColorHandler, DEFAULT_GRAPH_CONFIG as DEFAULT_GRAPH_CONFIG$1, GraphConfig, IOpenGraphSimulation, OpenFormGraphApi, OpenFormGraphProvider as OpenFormGraphProvider$1, OpenGraphEventEmitter as OpenGraphEventEmitter$1, OpenGraphEventsTypemap, OpenGraphSimulation as OpenGraphSimulation$1, TransformCanvas as TransformCanvas$1, VOID_DETACH_ID as VOID_DETACH_ID$1, VOID_ROOT_ID as VOID_ROOT_ID$1, color as color$1, dim as dim$1, useOpenFormGraph as useOpenFormGraph$1 };
313
+ //# sourceMappingURL=constants-BNPHdbBA.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { OpenFormGraph$1 as OpenFormGraph } from "./OpenFormGraph-0EqYrhjv.js";
2
- import { ColorHandler, ColorTransform, DEFAULT_GRAPH_CONFIG$1 as DEFAULT_GRAPH_CONFIG, GraphConfig, GraphData, Link, NestedRawNode, Node, NodeState, OpenFormGraphApi, OpenFormGraphProvider$1 as OpenFormGraphProvider, RGB, RawGraphData, RawLink, RawNode, RootNodeImageSources, SimLink, SimNode, ThemeMode, VOID_ROOT_ID$1 as VOID_ROOT_ID, color$1 as color, dim$1 as dim, useOpenFormGraph$1 as useOpenFormGraph } from "./constants-DU_wYtaU.js";
3
- import * as d3_force2 from "d3-force";
1
+ import { ColorTransform, CustomHighlight, Focus, GraphData, HighlightStyle, Link, MouseListener, NestedRawNode, Node, NodeState, Point, RGB, RawGraphData, RawLink, RawNode, RootNodeImageSources, SimLink, SimNode, SimpleHighlight, ThemeMode, Transform, TransformListener } from "./_types-CjgCTzqc.js";
2
+ import { OpenFormGraph$1 as OpenFormGraph } from "./OpenFormGraph-CdcWNN86.js";
3
+ import { ColorHandler, DEFAULT_GRAPH_CONFIG$1 as DEFAULT_GRAPH_CONFIG, GraphConfig, IOpenGraphSimulation, OpenFormGraphApi, OpenFormGraphProvider$1 as OpenFormGraphProvider, OpenGraphEventEmitter$1 as OpenGraphEventEmitter, OpenGraphEventsTypemap, OpenGraphSimulation$1 as OpenGraphSimulation, TransformCanvas$1 as TransformCanvas, VOID_DETACH_ID$1 as VOID_DETACH_ID, VOID_ROOT_ID$1 as VOID_ROOT_ID, color$1 as color, dim$1 as dim, useOpenFormGraph$1 as useOpenFormGraph } from "./constants-BNPHdbBA.js";
4
+ import * as d3_force5 from "d3-force";
4
5
 
5
6
  //#region src/util/canvas.d.ts
6
7
 
@@ -75,9 +76,9 @@ declare function hexagon(ctx: CanvasRenderingContext2D, x: number, y: number, ra
75
76
  //#endregion
76
77
  //#region src/util/data.d.ts
77
78
  declare function generateTree(maxNodes: number, maxChildren: number): RawGraphData;
78
- declare function getPrunedData(startId: string, nodes: SimNode[], links: SimLink[]): {
79
+ declare function getPrunedData(startId: string, nodes: SimNode[], links: SimLink[], highlights?: HighlightStyle[]): {
79
80
  nodes: SimNode[];
80
- links: d3_force2.SimulationLinkDatum<SimNode>[];
81
+ links: d3_force5.SimulationLinkDatum<SimNode>[];
81
82
  };
82
83
  /**
83
84
  * Automatically identifies root nodes and builds a nested structure
@@ -98,8 +99,11 @@ declare function searchParents(nodeHash: string, nodes: RawNode[], links: RawLin
98
99
  //#region src/util/graph.d.ts
99
100
  declare function getNodeId(n: any): any;
100
101
  declare function getParents(id: string, links: SimLink[]): string[];
102
+ declare function getAllParentsUntil(nodeId: string, links: SimLink[], stopAtId: string): string[];
101
103
  declare function getChildren(id: string, links: SimLink[]): string[];
102
104
  declare function getClusterSize(id: string, links: RawLink[]): number;
105
+ declare function getNodeDepth(id: string, links: RawLink[]): number;
106
+ declare function getRootParent(id: string, links: RawLink[], stop?: string): string | null;
103
107
  declare function hasOnlyLeafs(id: string, links: RawLink[]): boolean;
104
108
  declare function getNodeSubgraph(nodeId: string, nodes: SimNode[], links: SimLink[], rootId: string): {
105
109
  nodes: SimNode[];
@@ -107,11 +111,21 @@ declare function getNodeSubgraph(nodeId: string, nodes: SimNode[], links: SimLin
107
111
  };
108
112
  //#endregion
109
113
  //#region src/util/img.d.ts
110
- declare function loadImage(src: string): Promise<HTMLImageElement>;
114
+ declare function loadHTMLImageElement(src: string): Promise<HTMLImageElement>;
115
+ //#endregion
116
+ //#region src/util/highlights.d.ts
117
+ declare const red: RGB;
118
+ declare class Highlight {
119
+ static owner: (id: string) => CustomHighlight;
120
+ static primary: (id: string) => CustomHighlight;
121
+ static evolved: (id: string) => CustomHighlight;
122
+ static minted: (id: string) => CustomHighlight;
123
+ }
111
124
  //#endregion
112
125
  //#region src/util/types.d.ts
113
126
  declare function isSimNode(node: SimNode | string | number): node is SimNode;
114
127
  declare function isSimLink(link: SimLink): link is SimLink;
128
+ declare function isCustomHighlight(highlight: CustomHighlight | SimpleHighlight): highlight is CustomHighlight;
115
129
  //#endregion
116
- export { ColorHandler, ColorTransform, DEFAULT_GRAPH_CONFIG, GraphConfig, GraphData, Link, NestedRawNode, Node, NodeState, OpenFormGraph, OpenFormGraphApi, OpenFormGraphProvider, RGB, RawGraphData, RawLink, RawNode, RootNodeImageSources, SimLink, SimNode, ThemeMode, VOID_ROOT_ID, buildTreeFromGraphData, circle, color, dim, generateTree, getChildren, getClusterSize, getNodeId, getNodeSubgraph, getParents, getPrunedData, hasOnlyLeafs, hexagon, img, isSimLink, isSimNode, loadImage, rect, searchParents, useOpenFormGraph };
130
+ export { ColorHandler, ColorTransform, CustomHighlight, DEFAULT_GRAPH_CONFIG, Focus, GraphConfig, GraphData, Highlight, HighlightStyle, IOpenGraphSimulation, Link, MouseListener, NestedRawNode, Node, NodeState, OpenFormGraph, OpenFormGraphApi, OpenFormGraphProvider, OpenGraphEventEmitter, OpenGraphEventsTypemap, OpenGraphSimulation, Point, RGB, RawGraphData, RawLink, RawNode, RootNodeImageSources, SimLink, SimNode, SimpleHighlight, ThemeMode, Transform, TransformCanvas, TransformListener, VOID_DETACH_ID, VOID_ROOT_ID, buildTreeFromGraphData, circle, color, dim, generateTree, getAllParentsUntil, getChildren, getClusterSize, getNodeDepth, getNodeId, getNodeSubgraph, getParents, getPrunedData, getRootParent, hasOnlyLeafs, hexagon, img, isCustomHighlight, isSimLink, isSimNode, loadHTMLImageElement, rect, red, searchParents, useOpenFormGraph };
117
131
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { DEFAULT_GRAPH_CONFIG, OpenFormGraphProvider, VOID_ROOT_ID, useOpenFormGraph } from "./provider-CTDz6ZQd.js";
2
- import { OpenFormGraph, buildTreeFromGraphData, circle, color, dim, generateTree, getChildren, getClusterSize, getNodeId, getNodeSubgraph, getParents, getPrunedData, hasOnlyLeafs, hexagon, img, isSimLink, isSimNode, loadImage, rect, searchParents } from "./OpenFormGraph-wo_Y20C6.js";
1
+ import { DEFAULT_GRAPH_CONFIG, OpenFormGraphProvider, VOID_DETACH_ID, VOID_ROOT_ID, useOpenFormGraph } from "./provider-PqOen2FE.js";
2
+ import { Highlight, OpenFormGraph, OpenGraphEventEmitter, OpenGraphSimulation, TransformCanvas, buildTreeFromGraphData, circle, color, dim, generateTree, getAllParentsUntil, getChildren, getClusterSize, getNodeDepth, getNodeId, getNodeSubgraph, getParents, getPrunedData, getRootParent, hasOnlyLeafs, hexagon, img, isCustomHighlight, isSimLink, isSimNode, loadHTMLImageElement, rect, red, searchParents } from "./OpenFormGraph-i8VSTamk.js";
3
3
 
4
- export { DEFAULT_GRAPH_CONFIG, OpenFormGraph, OpenFormGraphProvider, VOID_ROOT_ID, buildTreeFromGraphData, circle, color, dim, generateTree, getChildren, getClusterSize, getNodeId, getNodeSubgraph, getParents, getPrunedData, hasOnlyLeafs, hexagon, img, isSimLink, isSimNode, loadImage, rect, searchParents, useOpenFormGraph };
4
+ export { DEFAULT_GRAPH_CONFIG, Highlight, OpenFormGraph, OpenFormGraphProvider, OpenGraphEventEmitter, OpenGraphSimulation, TransformCanvas, VOID_DETACH_ID, VOID_ROOT_ID, buildTreeFromGraphData, circle, color, dim, generateTree, getAllParentsUntil, getChildren, getClusterSize, getNodeDepth, getNodeId, getNodeSubgraph, getParents, getPrunedData, getRootParent, hasOnlyLeafs, hexagon, img, isCustomHighlight, isSimLink, isSimNode, loadHTMLImageElement, rect, red, searchParents, useOpenFormGraph };
@@ -3,9 +3,10 @@ import { jsx } from "react/jsx-runtime";
3
3
 
4
4
  //#region src/context/constants.ts
5
5
  const VOID_ROOT_ID = "void-root";
6
+ const VOID_DETACH_ID = "void-detach";
6
7
  const DEFAULT_GRAPH_CONFIG = {
7
8
  debug: false,
8
- nodeSize: 15,
9
+ nodeSize: 20,
9
10
  minClusterSize: 10,
10
11
  maxClusterSize: 20,
11
12
  minZoom: .1,
@@ -44,7 +45,7 @@ const OpenFormGraphContext = createContext({
44
45
  simulation: { current: null },
45
46
  setSelectedNodeById: () => {}
46
47
  });
47
- function OpenFormGraphProvider({ theme = "light", rootId, children, rootImageSources = [], config = DEFAULT_GRAPH_CONFIG, data }) {
48
+ function OpenFormGraphProvider({ theme = "light", rootId, children, rootImageSources = [], config = DEFAULT_GRAPH_CONFIG, data, lockedNodeId }) {
48
49
  const simulation = useRef(null);
49
50
  const [selectedNode, _setSelectedNode] = useState(null);
50
51
  const [hoveredNode, setHoveredNode] = useState(null);
@@ -71,7 +72,8 @@ function OpenFormGraphProvider({ theme = "light", rootId, children, rootImageSou
71
72
  theme,
72
73
  config,
73
74
  data,
74
- simulation
75
+ simulation,
76
+ lockedNodeId
75
77
  };
76
78
  }, [
77
79
  rootId,
@@ -85,7 +87,8 @@ function OpenFormGraphProvider({ theme = "light", rootId, children, rootImageSou
85
87
  rootImageSources,
86
88
  config,
87
89
  data,
88
- simulation
90
+ simulation,
91
+ lockedNodeId
89
92
  ]);
90
93
  return /* @__PURE__ */ jsx(OpenFormGraphContext.Provider, {
91
94
  value: contextValue,
@@ -99,5 +102,5 @@ function useOpenFormGraph() {
99
102
  }
100
103
 
101
104
  //#endregion
102
- export { DEFAULT_GRAPH_CONFIG, OpenFormGraphProvider, VOID_ROOT_ID, useOpenFormGraph };
103
- //# sourceMappingURL=provider-CTDz6ZQd.js.map
105
+ export { DEFAULT_GRAPH_CONFIG, OpenFormGraphProvider, VOID_DETACH_ID, VOID_ROOT_ID, useOpenFormGraph };
106
+ //# sourceMappingURL=provider-PqOen2FE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-PqOen2FE.js","names":["DEFAULT_GRAPH_CONFIG: GraphConfig","node: SimNode | null","nodeId: string","contextValue: OpenFormGraphApi"],"sources":["../src/context/constants.ts","../src/context/provider.tsx"],"sourcesContent":["import { GraphConfig } from \"@/_interfaces\"\n\nexport const VOID_ROOT_ID = \"void-root\"\nexport const VOID_DETACH_ID = \"void-detach\"\n\nexport const DEFAULT_GRAPH_CONFIG: GraphConfig = {\n debug: false,\n nodeSize: 20,\n minClusterSize: 10,\n maxClusterSize: 20,\n minZoom: 0.1,\n maxZoom: 10,\n theme: {\n light: [255, 255, 255],\n dark: [0, 0, 0],\n },\n}\n","import {\n createContext,\n useContext,\n useState,\n ReactNode,\n Dispatch,\n useMemo,\n useRef,\n MutableRefObject,\n useCallback,\n} from \"react\"\nimport {\n RawGraphData,\n RootNodeImageSources,\n SimNode,\n ThemeMode,\n} from \"@/_types\"\nimport { GraphConfig } from \"@/_interfaces\"\nimport { DEFAULT_GRAPH_CONFIG } from \"./constants\"\nimport { OpenGraphSimulation } from \"@/sim/OpenGraphSimulation\"\n\ninterface OpenFormGraphProviderProps {\n rootId: string\n rootImageSources: RootNodeImageSources\n theme: ThemeMode\n children: ReactNode\n config?: GraphConfig\n data: RawGraphData\n onSelectedNodeChange?: (node: SimNode | null) => void\n onHoveredNodeChange?: (node: SimNode | null) => void\n lockedNodeId?: string\n}\n\nexport interface OpenFormGraphApi {\n rootId: string\n rootImageSources: RootNodeImageSources\n setSelectedNode: Dispatch<SimNode | null>\n setHoveredNode: Dispatch<SimNode | null>\n theme: ThemeMode\n hideThumbnails: boolean\n setHideThumbnails: Dispatch<boolean>\n config: GraphConfig\n data: RawGraphData\n simulation: MutableRefObject<OpenGraphSimulation | null>\n selectedNode: SimNode | null\n hoveredNode: SimNode | null\n setSelectedNodeById: (nodeId: string) => void\n lockedNodeId?: string\n}\n\nconst OpenFormGraphContext = createContext<OpenFormGraphApi>({\n rootId: \"\",\n rootImageSources: [],\n setSelectedNode: () => {},\n setHoveredNode: () => {},\n theme: \"light\",\n hideThumbnails: false,\n setHideThumbnails: () => {},\n config: DEFAULT_GRAPH_CONFIG,\n data: { nodes: [], links: [] },\n selectedNode: null,\n hoveredNode: null,\n simulation: { current: null },\n setSelectedNodeById: () => {},\n})\n\nexport function OpenFormGraphProvider({\n theme = \"light\",\n rootId,\n children,\n rootImageSources = [],\n config = DEFAULT_GRAPH_CONFIG,\n data,\n lockedNodeId,\n}: OpenFormGraphProviderProps) {\n const simulation = useRef<OpenGraphSimulation | null>(null)\n const [selectedNode, _setSelectedNode] = useState<SimNode | null>(null)\n const [hoveredNode, setHoveredNode] = useState<SimNode | null>(null)\n const [hideThumbnails, setHideThumbnails] = useState(false)\n\n const setSelectedNode = useCallback(\n (node: SimNode | null) => {\n _setSelectedNode(node)\n simulation.current?.setSelectedNode(node)\n },\n [_setSelectedNode]\n )\n\n const setSelectedNodeById = useCallback(\n (nodeId: string) => {\n const node = simulation.current?.getNodeById(nodeId)\n if (node) {\n simulation.current?.handleClickNode(node)\n }\n },\n [setSelectedNode]\n )\n\n const contextValue: OpenFormGraphApi = useMemo(() => {\n return {\n rootId,\n selectedNode,\n setSelectedNode,\n setSelectedNodeById,\n hoveredNode,\n setHoveredNode,\n hideThumbnails,\n setHideThumbnails,\n rootImageSources,\n theme,\n config,\n data,\n simulation,\n lockedNodeId,\n }\n }, [\n rootId,\n selectedNode,\n setSelectedNode,\n setSelectedNodeById,\n hoveredNode,\n setHoveredNode,\n hideThumbnails,\n setHideThumbnails,\n rootImageSources,\n config,\n data,\n simulation,\n lockedNodeId,\n ])\n\n return (\n <OpenFormGraphContext.Provider value={contextValue}>\n {children}\n </OpenFormGraphContext.Provider>\n )\n}\n\nexport function useOpenFormGraph(): OpenFormGraphApi {\n const context = useContext(OpenFormGraphContext)\n if (!context) {\n throw new Error(\n \"useOpenFormGraph must be used within a OpenFormGraphProvider\"\n )\n }\n return context\n}\n"],"mappings":";;;;AAEA,MAAa,eAAe;AAC5B,MAAa,iBAAiB;AAE9B,MAAaA,uBAAoC;CAC/C,OAAO;CACP,UAAU;CACV,gBAAgB;CAChB,gBAAgB;CAChB,SAAS;CACT,SAAS;CACT,OAAO;EACL,OAAO;GAAC;GAAK;GAAK;EAAI;EACtB,MAAM;GAAC;GAAG;GAAG;EAAE;CAChB;AACF;;;;ACkCD,MAAM,uBAAuB,cAAgC;CAC3D,QAAQ;CACR,kBAAkB,CAAE;CACpB,iBAAiB,MAAM,CAAE;CACzB,gBAAgB,MAAM,CAAE;CACxB,OAAO;CACP,gBAAgB;CAChB,mBAAmB,MAAM,CAAE;CAC3B,QAAQ;CACR,MAAM;EAAE,OAAO,CAAE;EAAE,OAAO,CAAE;CAAE;CAC9B,cAAc;CACd,aAAa;CACb,YAAY,EAAE,SAAS,KAAM;CAC7B,qBAAqB,MAAM,CAAE;AAC9B,EAAC;AAEF,SAAgB,sBAAsB,EACpC,QAAQ,SACR,QACA,UACA,mBAAmB,CAAE,GACrB,SAAS,sBACT,MACA,cAC2B,EAAE;CAC7B,MAAM,aAAa,OAAmC,KAAK;CAC3D,MAAM,CAAC,cAAc,iBAAiB,GAAG,SAAyB,KAAK;CACvE,MAAM,CAAC,aAAa,eAAe,GAAG,SAAyB,KAAK;CACpE,MAAM,CAAC,gBAAgB,kBAAkB,GAAG,SAAS,MAAM;CAE3D,MAAM,kBAAkB,YACtB,CAACC,SAAyB;AACxB,mBAAiB,KAAK;AACtB,aAAW,SAAS,gBAAgB,KAAK;CAC1C,GACD,CAAC,gBAAiB,EACnB;CAED,MAAM,sBAAsB,YAC1B,CAACC,WAAmB;EAClB,MAAM,OAAO,WAAW,SAAS,YAAY,OAAO;AACpD,MAAI,KACF,YAAW,SAAS,gBAAgB,KAAK;CAE5C,GACD,CAAC,eAAgB,EAClB;CAED,MAAMC,eAAiC,QAAQ,MAAM;AACnD,SAAO;GACL;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACD;CACF,GAAE;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD,EAAC;AAEF,wBACE,IAAC,qBAAqB;EAAS,OAAO;EACnC;GAC6B;AAEnC;AAED,SAAgB,mBAAqC;CACnD,MAAM,UAAU,WAAW,qBAAqB;AAChD,MAAK,QACH,OAAM,IAAI,MACR;AAGJ,QAAO;AACR"}
@@ -1,2 +1,3 @@
1
- import { DEFAULT_GRAPH_CONFIG$1 as DEFAULT_GRAPH_CONFIG, OpenFormGraphApi, OpenFormGraphProvider$1 as OpenFormGraphProvider, VOID_ROOT_ID$1 as VOID_ROOT_ID, useOpenFormGraph$1 as useOpenFormGraph } from "./constants-DU_wYtaU.js";
2
- export { DEFAULT_GRAPH_CONFIG, OpenFormGraphApi, OpenFormGraphProvider, VOID_ROOT_ID, useOpenFormGraph };
1
+ import "./_types-CjgCTzqc.js";
2
+ import { DEFAULT_GRAPH_CONFIG$1 as DEFAULT_GRAPH_CONFIG, OpenFormGraphApi, OpenFormGraphProvider$1 as OpenFormGraphProvider, VOID_DETACH_ID$1 as VOID_DETACH_ID, VOID_ROOT_ID$1 as VOID_ROOT_ID, useOpenFormGraph$1 as useOpenFormGraph } from "./constants-BNPHdbBA.js";
3
+ export { DEFAULT_GRAPH_CONFIG, OpenFormGraphApi, OpenFormGraphProvider, VOID_DETACH_ID, VOID_ROOT_ID, useOpenFormGraph };
package/dist/provider.js CHANGED
@@ -1,3 +1,3 @@
1
- import { DEFAULT_GRAPH_CONFIG, OpenFormGraphProvider, VOID_ROOT_ID, useOpenFormGraph } from "./provider-CTDz6ZQd.js";
1
+ import { DEFAULT_GRAPH_CONFIG, OpenFormGraphProvider, VOID_DETACH_ID, VOID_ROOT_ID, useOpenFormGraph } from "./provider-PqOen2FE.js";
2
2
 
3
- export { DEFAULT_GRAPH_CONFIG, OpenFormGraphProvider, VOID_ROOT_ID, useOpenFormGraph };
3
+ export { DEFAULT_GRAPH_CONFIG, OpenFormGraphProvider, VOID_DETACH_ID, VOID_ROOT_ID, useOpenFormGraph };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fxhash/open-form-graph",
3
3
  "description": "A react-force-graph visualizer for open form collections",
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "author": "fxhash",
6
6
  "dependencies": {
7
7
  "d3-force": "3.0.0",
@@ -9,8 +9,7 @@
9
9
  "d3-scale-chromatic": "3.1.0",
10
10
  "lodash.debounce": "4.0.8",
11
11
  "lodash.throttle": "4.1.1",
12
- "three": "0.176.0",
13
- "three-spritetext": "1.9.6"
12
+ "@fxhash/utils": "0.0.5"
14
13
  },
15
14
  "devDependencies": {
16
15
  "@types/d3-force": "3.0.10",
@@ -21,10 +20,9 @@
21
20
  "@types/react": "18.3.12",
22
21
  "@types/react-dom": "18.3.1",
23
22
  "@types/three": "0.176.0",
24
- "esbuild-css-modules-plugin": "2.7.1",
25
23
  "tsdown": "0.12.2",
26
24
  "typescript": "5.8.2",
27
- "@fxhash/tsconfig": "0.0.2"
25
+ "@fxhash/tsconfig": "0.0.3"
28
26
  },
29
27
  "exports": {
30
28
  ".": {
@@ -1,17 +0,0 @@
1
- import { MouseEventHandler } from "react";
2
- import * as react_jsx_runtime1 from "react/jsx-runtime";
3
-
4
- //#region src/components/OpenFormGraph.d.ts
5
- interface OpenFormGraphProps {
6
- width: number;
7
- height: number;
8
- highlights?: string[];
9
- className?: string;
10
- noInteraction?: boolean;
11
- onMouseEnter?: MouseEventHandler;
12
- onMouseLeave?: MouseEventHandler;
13
- }
14
- declare function OpenFormGraph(props: OpenFormGraphProps): react_jsx_runtime1.JSX.Element;
15
- //#endregion
16
- export { OpenFormGraph as OpenFormGraph$1 };
17
- //# sourceMappingURL=OpenFormGraph-0EqYrhjv.d.ts.map