@fxhash/open-form-graph 0.0.1 → 0.0.2

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,103 @@
1
+ import { createContext, useCallback, useContext, useMemo, useRef, useState } from "react";
2
+ import { jsx } from "react/jsx-runtime";
3
+
4
+ //#region src/context/constants.ts
5
+ const VOID_ROOT_ID = "void-root";
6
+ const DEFAULT_GRAPH_CONFIG = {
7
+ debug: false,
8
+ nodeSize: 15,
9
+ minClusterSize: 10,
10
+ maxClusterSize: 20,
11
+ minZoom: .1,
12
+ maxZoom: 10,
13
+ theme: {
14
+ light: [
15
+ 255,
16
+ 255,
17
+ 255
18
+ ],
19
+ dark: [
20
+ 0,
21
+ 0,
22
+ 0
23
+ ]
24
+ }
25
+ };
26
+
27
+ //#endregion
28
+ //#region src/context/provider.tsx
29
+ const OpenFormGraphContext = createContext({
30
+ rootId: "",
31
+ rootImageSources: [],
32
+ setSelectedNode: () => {},
33
+ setHoveredNode: () => {},
34
+ theme: "light",
35
+ hideThumbnails: false,
36
+ setHideThumbnails: () => {},
37
+ config: DEFAULT_GRAPH_CONFIG,
38
+ data: {
39
+ nodes: [],
40
+ links: []
41
+ },
42
+ selectedNode: null,
43
+ hoveredNode: null,
44
+ simulation: { current: null },
45
+ setSelectedNodeById: () => {}
46
+ });
47
+ function OpenFormGraphProvider({ theme = "light", rootId, children, rootImageSources = [], config = DEFAULT_GRAPH_CONFIG, data }) {
48
+ const simulation = useRef(null);
49
+ const [selectedNode, _setSelectedNode] = useState(null);
50
+ const [hoveredNode, setHoveredNode] = useState(null);
51
+ const [hideThumbnails, setHideThumbnails] = useState(false);
52
+ const setSelectedNode = useCallback((node) => {
53
+ _setSelectedNode(node);
54
+ simulation.current?.setSelectedNode(node);
55
+ }, [_setSelectedNode]);
56
+ const setSelectedNodeById = useCallback((nodeId) => {
57
+ const node = simulation.current?.getNodeById(nodeId);
58
+ if (node) simulation.current?.handleClickNode(node);
59
+ }, [setSelectedNode]);
60
+ const contextValue = useMemo(() => {
61
+ return {
62
+ rootId,
63
+ selectedNode,
64
+ setSelectedNode,
65
+ setSelectedNodeById,
66
+ hoveredNode,
67
+ setHoveredNode,
68
+ hideThumbnails,
69
+ setHideThumbnails,
70
+ rootImageSources,
71
+ theme,
72
+ config,
73
+ data,
74
+ simulation
75
+ };
76
+ }, [
77
+ rootId,
78
+ selectedNode,
79
+ setSelectedNode,
80
+ setSelectedNodeById,
81
+ hoveredNode,
82
+ setHoveredNode,
83
+ hideThumbnails,
84
+ setHideThumbnails,
85
+ rootImageSources,
86
+ config,
87
+ data,
88
+ simulation
89
+ ]);
90
+ return /* @__PURE__ */ jsx(OpenFormGraphContext.Provider, {
91
+ value: contextValue,
92
+ children
93
+ });
94
+ }
95
+ function useOpenFormGraph() {
96
+ const context = useContext(OpenFormGraphContext);
97
+ if (!context) throw new Error("useOpenFormGraph must be used within a OpenFormGraphProvider");
98
+ return context;
99
+ }
100
+
101
+ //#endregion
102
+ export { DEFAULT_GRAPH_CONFIG, OpenFormGraphProvider, VOID_ROOT_ID, useOpenFormGraph };
103
+ //# sourceMappingURL=provider-CTDz6ZQd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-CTDz6ZQd.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\"\n\nexport const DEFAULT_GRAPH_CONFIG: GraphConfig = {\n debug: false,\n nodeSize: 15,\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}\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}\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}: 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 }\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 ])\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;AAE5B,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;;;;ACiCD,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,MAC2B,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;EACD;CACF,GAAE;EACD;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"}
@@ -0,0 +1,2 @@
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 };
@@ -0,0 +1,3 @@
1
+ import { DEFAULT_GRAPH_CONFIG, OpenFormGraphProvider, VOID_ROOT_ID, useOpenFormGraph } from "./provider-CTDz6ZQd.js";
2
+
3
+ export { DEFAULT_GRAPH_CONFIG, OpenFormGraphProvider, 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.1",
4
+ "version": "0.0.2",
5
5
  "author": "fxhash",
6
6
  "dependencies": {
7
7
  "d3-force": "3.0.0",
@@ -9,8 +9,6 @@
9
9
  "d3-scale-chromatic": "3.1.0",
10
10
  "lodash.debounce": "4.0.8",
11
11
  "lodash.throttle": "4.1.1",
12
- "react-force-graph-2d": "1.27.1",
13
- "react-force-graph-3d": "1.26.1",
14
12
  "three": "0.176.0",
15
13
  "three-spritetext": "1.9.6"
16
14
  },
@@ -24,14 +22,22 @@
24
22
  "@types/react-dom": "18.3.1",
25
23
  "@types/three": "0.176.0",
26
24
  "esbuild-css-modules-plugin": "2.7.1",
27
- "tsup": "8.4.0",
25
+ "tsdown": "0.12.2",
28
26
  "typescript": "5.8.2",
29
- "@fxhash/tsconfig": "0.0.1"
27
+ "@fxhash/tsconfig": "0.0.2"
30
28
  },
31
29
  "exports": {
32
30
  ".": {
33
31
  "types": "./dist/index.d.ts",
34
32
  "default": "./dist/index.js"
33
+ },
34
+ "./provider": {
35
+ "types": "./dist/provider.d.ts",
36
+ "default": "./dist/provider.js"
37
+ },
38
+ "./components": {
39
+ "types": "./dist/components.d.ts",
40
+ "default": "./dist/components.js"
35
41
  }
36
42
  },
37
43
  "files": [
@@ -46,9 +52,10 @@
46
52
  "access": "public"
47
53
  },
48
54
  "repository": "fxhash/fxhash-package",
55
+ "sideEffects": false,
49
56
  "type": "module",
50
57
  "scripts": {
51
- "build": "tsup",
52
- "dev": "tsup --watch"
58
+ "build": "tsdown && tsc --noEmit",
59
+ "dev": "tsdown --watch"
53
60
  }
54
61
  }