@3plate/graph-react 0.1.5 → 0.1.7

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.mts CHANGED
@@ -1,2 +1,33 @@
1
+ import React from 'react';
2
+ import { Update, APIArguments, PlaygroundOptions } from '@3plate/graph-core';
1
3
 
2
- export { }
4
+ type GraphProps<N, E> = {
5
+ /** Initial nodes */
6
+ nodes?: N[];
7
+ /** Initial edges */
8
+ edges?: E[];
9
+ /** Initial history */
10
+ history?: Update<N, E>[];
11
+ /** Options */
12
+ options?: APIArguments<N, E>['options'];
13
+ /** Events */
14
+ events?: APIArguments<N, E>['events'];
15
+ };
16
+ /**
17
+ * Graph component - renders a graph visualization
18
+ * Intelligently handles prop changes by diffing nodes, edges, and history
19
+ */
20
+ declare function Graph<N, E>(props: GraphProps<N, E>): React.JSX.Element;
21
+
22
+ type PlaygroundProps = {
23
+ /** Examples to display */
24
+ examples: PlaygroundOptions['examples'];
25
+ /** Default example key */
26
+ defaultExample?: string;
27
+ };
28
+ /**
29
+ * Playground component - renders the interactive playground with examples
30
+ */
31
+ declare function Playground(props: PlaygroundProps): React.JSX.Element;
32
+
33
+ export { Graph, type GraphProps, Playground, type PlaygroundProps };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,33 @@
1
+ import React from 'react';
2
+ import { Update, APIArguments, PlaygroundOptions } from '@3plate/graph-core';
1
3
 
2
- export { }
4
+ type GraphProps<N, E> = {
5
+ /** Initial nodes */
6
+ nodes?: N[];
7
+ /** Initial edges */
8
+ edges?: E[];
9
+ /** Initial history */
10
+ history?: Update<N, E>[];
11
+ /** Options */
12
+ options?: APIArguments<N, E>['options'];
13
+ /** Events */
14
+ events?: APIArguments<N, E>['events'];
15
+ };
16
+ /**
17
+ * Graph component - renders a graph visualization
18
+ * Intelligently handles prop changes by diffing nodes, edges, and history
19
+ */
20
+ declare function Graph<N, E>(props: GraphProps<N, E>): React.JSX.Element;
21
+
22
+ type PlaygroundProps = {
23
+ /** Examples to display */
24
+ examples: PlaygroundOptions['examples'];
25
+ /** Default example key */
26
+ defaultExample?: string;
27
+ };
28
+ /**
29
+ * Playground component - renders the interactive playground with examples
30
+ */
31
+ declare function Playground(props: PlaygroundProps): React.JSX.Element;
32
+
33
+ export { Graph, type GraphProps, Playground, type PlaygroundProps };
package/dist/index.js CHANGED
@@ -1 +1,271 @@
1
1
  "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ Graph: () => Graph,
34
+ Playground: () => Playground
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+
38
+ // src/Graph.tsx
39
+ var import_react = __toESM(require("react"));
40
+ var import_graph_core = require("@3plate/graph-core");
41
+ function Graph(props) {
42
+ const rootRef = (0, import_react.useRef)(null);
43
+ const apiRef = (0, import_react.useRef)(null);
44
+ const rootIdRef = (0, import_react.useRef)(`graph-${Math.random().toString(36).slice(2, 11)}`);
45
+ const prevPropsRef = (0, import_react.useRef)({});
46
+ (0, import_react.useEffect)(() => {
47
+ if (!rootRef.current || apiRef.current) return;
48
+ rootRef.current.id = rootIdRef.current;
49
+ prevPropsRef.current = {
50
+ nodes: props.nodes,
51
+ edges: props.edges,
52
+ history: props.history,
53
+ options: props.options
54
+ };
55
+ (0, import_graph_core.graph)({
56
+ root: rootIdRef.current,
57
+ nodes: props.nodes,
58
+ edges: props.edges,
59
+ history: props.history,
60
+ options: props.options,
61
+ events: props.events
62
+ }).then((api) => {
63
+ apiRef.current = api;
64
+ });
65
+ return () => {
66
+ if (apiRef.current) {
67
+ apiRef.current.destroy();
68
+ apiRef.current = null;
69
+ }
70
+ if (rootRef.current) {
71
+ const canvas = rootRef.current.querySelector("canvas, svg");
72
+ if (canvas) {
73
+ canvas.remove();
74
+ }
75
+ }
76
+ };
77
+ }, []);
78
+ (0, import_react.useEffect)(() => {
79
+ if (!apiRef.current) return;
80
+ const api = apiRef.current;
81
+ const prev = prevPropsRef.current;
82
+ const nodesChanged = !shallowEqual(props.nodes, prev.nodes);
83
+ const edgesChanged = !shallowEqual(props.edges, prev.edges);
84
+ if (nodesChanged || edgesChanged) {
85
+ if (props.nodes) {
86
+ api.replaceSnapshot(props.nodes, props.edges || [], void 0);
87
+ }
88
+ prevPropsRef.current = { ...prevPropsRef.current, nodes: props.nodes, edges: props.edges };
89
+ return;
90
+ }
91
+ if (props.history !== prev.history) {
92
+ if (props.history === void 0) {
93
+ if (props.nodes) {
94
+ api.replaceSnapshot(props.nodes, props.edges || [], void 0);
95
+ }
96
+ prevPropsRef.current = { ...prevPropsRef.current, history: props.history };
97
+ return;
98
+ }
99
+ if (prev.history && isHistoryAppended(prev.history, props.history)) {
100
+ const prevLength = prev.history.length;
101
+ const newFrames = props.history.slice(prevLength);
102
+ for (const frame of newFrames) {
103
+ api.update((u) => {
104
+ if (frame.addNodes) u.addNodes(...frame.addNodes);
105
+ if (frame.removeNodes) u.deleteNodes(...frame.removeNodes);
106
+ if (frame.updateNodes) u.updateNodes(...frame.updateNodes);
107
+ if (frame.addEdges) u.addEdges(...frame.addEdges);
108
+ if (frame.removeEdges) u.deleteEdges(...frame.removeEdges);
109
+ if (frame.updateEdges) u.updateEdges(...frame.updateEdges);
110
+ if (frame.description) u.describe(frame.description);
111
+ });
112
+ }
113
+ } else {
114
+ api.replaceHistory(props.history);
115
+ }
116
+ prevPropsRef.current = { ...prevPropsRef.current, history: props.history };
117
+ }
118
+ }, [props.nodes, props.edges, props.history]);
119
+ (0, import_react.useEffect)(() => {
120
+ if (!apiRef.current) return;
121
+ const api = apiRef.current;
122
+ const prev = prevPropsRef.current.options;
123
+ const curr = props.options;
124
+ const prevCanvas = prev?.canvas;
125
+ const currCanvas = curr?.canvas;
126
+ const colorModeChanged = prevCanvas?.colorMode !== currCanvas?.colorMode;
127
+ if (colorModeChanged && currCanvas?.colorMode) {
128
+ api.setColorMode(currCanvas.colorMode);
129
+ }
130
+ const themeChanged = prevCanvas?.theme !== currCanvas?.theme;
131
+ const nodeTypesChanged = prevCanvas?.nodeTypes !== currCanvas?.nodeTypes;
132
+ const edgeTypesChanged = prevCanvas?.edgeTypes !== currCanvas?.edgeTypes;
133
+ if (themeChanged || nodeTypesChanged || edgeTypesChanged) {
134
+ api.updateStyles({
135
+ theme: currCanvas?.theme,
136
+ nodeTypes: currCanvas?.nodeTypes,
137
+ edgeTypes: currCanvas?.edgeTypes
138
+ });
139
+ }
140
+ prevPropsRef.current = { ...prevPropsRef.current, options: props.options };
141
+ }, [props.options]);
142
+ return /* @__PURE__ */ import_react.default.createElement("div", { ref: rootRef, style: { width: "100%", height: "100%" } });
143
+ }
144
+ function shallowEqual(a, b) {
145
+ if (a === b) return true;
146
+ if (!a || !b) return false;
147
+ if (a.length !== b.length) return false;
148
+ for (let i = 0; i < a.length; i++) {
149
+ if (a[i] !== b[i]) {
150
+ if (typeof a[i] === "object" && a[i] !== null && typeof b[i] === "object" && b[i] !== null) {
151
+ const aObj = a[i];
152
+ const bObj = b[i];
153
+ const aKeys = Object.keys(aObj);
154
+ const bKeys = Object.keys(bObj);
155
+ if (aKeys.length !== bKeys.length) return false;
156
+ for (const key of aKeys) {
157
+ if (aObj[key] !== bObj[key]) return false;
158
+ }
159
+ } else {
160
+ return false;
161
+ }
162
+ }
163
+ }
164
+ return true;
165
+ }
166
+ function isHistoryAppended(oldHistory, newHistory) {
167
+ if (newHistory.length < oldHistory.length) return false;
168
+ for (let i = 0; i < oldHistory.length; i++) {
169
+ if (!shallowEqualUpdates(oldHistory[i], newHistory[i])) {
170
+ return false;
171
+ }
172
+ }
173
+ return true;
174
+ }
175
+ function shallowEqualUpdates(a, b) {
176
+ if (a === b) return true;
177
+ if (a.description !== b.description) return false;
178
+ if (!shallowEqual(a.addNodes, b.addNodes)) return false;
179
+ if (!shallowEqual(a.removeNodes, b.removeNodes)) return false;
180
+ if (!shallowEqual(a.updateNodes, b.updateNodes)) return false;
181
+ if (!shallowEqual(a.addEdges, b.addEdges)) return false;
182
+ if (!shallowEqual(a.removeEdges, b.removeEdges)) return false;
183
+ if (!shallowEqual(a.updateEdges, b.updateEdges)) return false;
184
+ return true;
185
+ }
186
+
187
+ // src/Playground.tsx
188
+ var import_react2 = __toESM(require("react"));
189
+ var import_graph_core2 = require("@3plate/graph-core");
190
+ function Playground(props) {
191
+ const rootRef = (0, import_react2.useRef)(null);
192
+ const playgroundRef = (0, import_react2.useRef)(null);
193
+ const rootIdRef = (0, import_react2.useRef)(`playground-${Math.random().toString(36).slice(2, 11)}`);
194
+ const prevExamplesRef = (0, import_react2.useRef)({});
195
+ (0, import_react2.useEffect)(() => {
196
+ if (!rootRef.current || playgroundRef.current) return;
197
+ rootRef.current.id = rootIdRef.current;
198
+ const playground = new import_graph_core2.Playground({
199
+ root: rootIdRef.current,
200
+ examples: props.examples,
201
+ defaultExample: props.defaultExample
202
+ });
203
+ playgroundRef.current = playground;
204
+ prevExamplesRef.current = { ...props.examples };
205
+ playground.init();
206
+ return () => {
207
+ playgroundRef.current = null;
208
+ };
209
+ }, []);
210
+ (0, import_react2.useEffect)(() => {
211
+ if (!playgroundRef.current) return;
212
+ const playground = playgroundRef.current;
213
+ const prev = prevExamplesRef.current;
214
+ const current = props.examples;
215
+ const allKeys = /* @__PURE__ */ new Set([...Object.keys(prev), ...Object.keys(current)]);
216
+ for (const key of allKeys) {
217
+ const prevExample = prev[key];
218
+ const currentExample = current[key];
219
+ if (!prevExample && currentExample) {
220
+ playground.addExample(key, currentExample);
221
+ } else if (prevExample && !currentExample) {
222
+ playground.removeExample(key);
223
+ } else if (prevExample && currentExample && !shallowEqualExample(prevExample, currentExample)) {
224
+ playground.addExample(key, currentExample);
225
+ }
226
+ }
227
+ prevExamplesRef.current = { ...current };
228
+ }, [props.examples]);
229
+ return /* @__PURE__ */ import_react2.default.createElement("div", { ref: rootRef, style: { width: "100%", height: "100%" } });
230
+ }
231
+ function shallowEqualExample(a, b) {
232
+ if (a === b) return true;
233
+ if (a.name !== b.name) return false;
234
+ if (a.description !== b.description) return false;
235
+ if (!shallowEqualArray(a.nodes, b.nodes)) return false;
236
+ if (!shallowEqualArray(a.edges, b.edges)) return false;
237
+ if (!shallowEqualOptions(a.options, b.options)) return false;
238
+ if (!shallowEqualSource(a.source, b.source)) return false;
239
+ return true;
240
+ }
241
+ function shallowEqualArray(a, b) {
242
+ if (a === b) return true;
243
+ if (!a || !b) return false;
244
+ if (a.length !== b.length) return false;
245
+ for (let i = 0; i < a.length; i++) {
246
+ if (a[i] !== b[i]) return false;
247
+ }
248
+ return true;
249
+ }
250
+ function shallowEqualOptions(a, b) {
251
+ if (a === b) return true;
252
+ if (!a || !b) return false;
253
+ return a === b;
254
+ }
255
+ function shallowEqualSource(a, b) {
256
+ if (a === b) return true;
257
+ if (!a || !b) return false;
258
+ if (a.type !== b.type) return false;
259
+ if (a.type === "file" && b.type === "file") {
260
+ return a.path === b.path;
261
+ }
262
+ if (a.type === "websocket" && b.type === "websocket") {
263
+ return a.url === b.url;
264
+ }
265
+ return false;
266
+ }
267
+ // Annotate the CommonJS export names for ESM import in node:
268
+ 0 && (module.exports = {
269
+ Graph,
270
+ Playground
271
+ });
package/dist/index.mjs CHANGED
@@ -0,0 +1,233 @@
1
+ // src/Graph.tsx
2
+ import React, { useEffect, useRef } from "react";
3
+ import { graph } from "@3plate/graph-core";
4
+ function Graph(props) {
5
+ const rootRef = useRef(null);
6
+ const apiRef = useRef(null);
7
+ const rootIdRef = useRef(`graph-${Math.random().toString(36).slice(2, 11)}`);
8
+ const prevPropsRef = useRef({});
9
+ useEffect(() => {
10
+ if (!rootRef.current || apiRef.current) return;
11
+ rootRef.current.id = rootIdRef.current;
12
+ prevPropsRef.current = {
13
+ nodes: props.nodes,
14
+ edges: props.edges,
15
+ history: props.history,
16
+ options: props.options
17
+ };
18
+ graph({
19
+ root: rootIdRef.current,
20
+ nodes: props.nodes,
21
+ edges: props.edges,
22
+ history: props.history,
23
+ options: props.options,
24
+ events: props.events
25
+ }).then((api) => {
26
+ apiRef.current = api;
27
+ });
28
+ return () => {
29
+ if (apiRef.current) {
30
+ apiRef.current.destroy();
31
+ apiRef.current = null;
32
+ }
33
+ if (rootRef.current) {
34
+ const canvas = rootRef.current.querySelector("canvas, svg");
35
+ if (canvas) {
36
+ canvas.remove();
37
+ }
38
+ }
39
+ };
40
+ }, []);
41
+ useEffect(() => {
42
+ if (!apiRef.current) return;
43
+ const api = apiRef.current;
44
+ const prev = prevPropsRef.current;
45
+ const nodesChanged = !shallowEqual(props.nodes, prev.nodes);
46
+ const edgesChanged = !shallowEqual(props.edges, prev.edges);
47
+ if (nodesChanged || edgesChanged) {
48
+ if (props.nodes) {
49
+ api.replaceSnapshot(props.nodes, props.edges || [], void 0);
50
+ }
51
+ prevPropsRef.current = { ...prevPropsRef.current, nodes: props.nodes, edges: props.edges };
52
+ return;
53
+ }
54
+ if (props.history !== prev.history) {
55
+ if (props.history === void 0) {
56
+ if (props.nodes) {
57
+ api.replaceSnapshot(props.nodes, props.edges || [], void 0);
58
+ }
59
+ prevPropsRef.current = { ...prevPropsRef.current, history: props.history };
60
+ return;
61
+ }
62
+ if (prev.history && isHistoryAppended(prev.history, props.history)) {
63
+ const prevLength = prev.history.length;
64
+ const newFrames = props.history.slice(prevLength);
65
+ for (const frame of newFrames) {
66
+ api.update((u) => {
67
+ if (frame.addNodes) u.addNodes(...frame.addNodes);
68
+ if (frame.removeNodes) u.deleteNodes(...frame.removeNodes);
69
+ if (frame.updateNodes) u.updateNodes(...frame.updateNodes);
70
+ if (frame.addEdges) u.addEdges(...frame.addEdges);
71
+ if (frame.removeEdges) u.deleteEdges(...frame.removeEdges);
72
+ if (frame.updateEdges) u.updateEdges(...frame.updateEdges);
73
+ if (frame.description) u.describe(frame.description);
74
+ });
75
+ }
76
+ } else {
77
+ api.replaceHistory(props.history);
78
+ }
79
+ prevPropsRef.current = { ...prevPropsRef.current, history: props.history };
80
+ }
81
+ }, [props.nodes, props.edges, props.history]);
82
+ useEffect(() => {
83
+ if (!apiRef.current) return;
84
+ const api = apiRef.current;
85
+ const prev = prevPropsRef.current.options;
86
+ const curr = props.options;
87
+ const prevCanvas = prev?.canvas;
88
+ const currCanvas = curr?.canvas;
89
+ const colorModeChanged = prevCanvas?.colorMode !== currCanvas?.colorMode;
90
+ if (colorModeChanged && currCanvas?.colorMode) {
91
+ api.setColorMode(currCanvas.colorMode);
92
+ }
93
+ const themeChanged = prevCanvas?.theme !== currCanvas?.theme;
94
+ const nodeTypesChanged = prevCanvas?.nodeTypes !== currCanvas?.nodeTypes;
95
+ const edgeTypesChanged = prevCanvas?.edgeTypes !== currCanvas?.edgeTypes;
96
+ if (themeChanged || nodeTypesChanged || edgeTypesChanged) {
97
+ api.updateStyles({
98
+ theme: currCanvas?.theme,
99
+ nodeTypes: currCanvas?.nodeTypes,
100
+ edgeTypes: currCanvas?.edgeTypes
101
+ });
102
+ }
103
+ prevPropsRef.current = { ...prevPropsRef.current, options: props.options };
104
+ }, [props.options]);
105
+ return /* @__PURE__ */ React.createElement("div", { ref: rootRef, style: { width: "100%", height: "100%" } });
106
+ }
107
+ function shallowEqual(a, b) {
108
+ if (a === b) return true;
109
+ if (!a || !b) return false;
110
+ if (a.length !== b.length) return false;
111
+ for (let i = 0; i < a.length; i++) {
112
+ if (a[i] !== b[i]) {
113
+ if (typeof a[i] === "object" && a[i] !== null && typeof b[i] === "object" && b[i] !== null) {
114
+ const aObj = a[i];
115
+ const bObj = b[i];
116
+ const aKeys = Object.keys(aObj);
117
+ const bKeys = Object.keys(bObj);
118
+ if (aKeys.length !== bKeys.length) return false;
119
+ for (const key of aKeys) {
120
+ if (aObj[key] !== bObj[key]) return false;
121
+ }
122
+ } else {
123
+ return false;
124
+ }
125
+ }
126
+ }
127
+ return true;
128
+ }
129
+ function isHistoryAppended(oldHistory, newHistory) {
130
+ if (newHistory.length < oldHistory.length) return false;
131
+ for (let i = 0; i < oldHistory.length; i++) {
132
+ if (!shallowEqualUpdates(oldHistory[i], newHistory[i])) {
133
+ return false;
134
+ }
135
+ }
136
+ return true;
137
+ }
138
+ function shallowEqualUpdates(a, b) {
139
+ if (a === b) return true;
140
+ if (a.description !== b.description) return false;
141
+ if (!shallowEqual(a.addNodes, b.addNodes)) return false;
142
+ if (!shallowEqual(a.removeNodes, b.removeNodes)) return false;
143
+ if (!shallowEqual(a.updateNodes, b.updateNodes)) return false;
144
+ if (!shallowEqual(a.addEdges, b.addEdges)) return false;
145
+ if (!shallowEqual(a.removeEdges, b.removeEdges)) return false;
146
+ if (!shallowEqual(a.updateEdges, b.updateEdges)) return false;
147
+ return true;
148
+ }
149
+
150
+ // src/Playground.tsx
151
+ import React2, { useEffect as useEffect2, useRef as useRef2 } from "react";
152
+ import { Playground as PlaygroundClass } from "@3plate/graph-core";
153
+ function Playground(props) {
154
+ const rootRef = useRef2(null);
155
+ const playgroundRef = useRef2(null);
156
+ const rootIdRef = useRef2(`playground-${Math.random().toString(36).slice(2, 11)}`);
157
+ const prevExamplesRef = useRef2({});
158
+ useEffect2(() => {
159
+ if (!rootRef.current || playgroundRef.current) return;
160
+ rootRef.current.id = rootIdRef.current;
161
+ const playground = new PlaygroundClass({
162
+ root: rootIdRef.current,
163
+ examples: props.examples,
164
+ defaultExample: props.defaultExample
165
+ });
166
+ playgroundRef.current = playground;
167
+ prevExamplesRef.current = { ...props.examples };
168
+ playground.init();
169
+ return () => {
170
+ playgroundRef.current = null;
171
+ };
172
+ }, []);
173
+ useEffect2(() => {
174
+ if (!playgroundRef.current) return;
175
+ const playground = playgroundRef.current;
176
+ const prev = prevExamplesRef.current;
177
+ const current = props.examples;
178
+ const allKeys = /* @__PURE__ */ new Set([...Object.keys(prev), ...Object.keys(current)]);
179
+ for (const key of allKeys) {
180
+ const prevExample = prev[key];
181
+ const currentExample = current[key];
182
+ if (!prevExample && currentExample) {
183
+ playground.addExample(key, currentExample);
184
+ } else if (prevExample && !currentExample) {
185
+ playground.removeExample(key);
186
+ } else if (prevExample && currentExample && !shallowEqualExample(prevExample, currentExample)) {
187
+ playground.addExample(key, currentExample);
188
+ }
189
+ }
190
+ prevExamplesRef.current = { ...current };
191
+ }, [props.examples]);
192
+ return /* @__PURE__ */ React2.createElement("div", { ref: rootRef, style: { width: "100%", height: "100%" } });
193
+ }
194
+ function shallowEqualExample(a, b) {
195
+ if (a === b) return true;
196
+ if (a.name !== b.name) return false;
197
+ if (a.description !== b.description) return false;
198
+ if (!shallowEqualArray(a.nodes, b.nodes)) return false;
199
+ if (!shallowEqualArray(a.edges, b.edges)) return false;
200
+ if (!shallowEqualOptions(a.options, b.options)) return false;
201
+ if (!shallowEqualSource(a.source, b.source)) return false;
202
+ return true;
203
+ }
204
+ function shallowEqualArray(a, b) {
205
+ if (a === b) return true;
206
+ if (!a || !b) return false;
207
+ if (a.length !== b.length) return false;
208
+ for (let i = 0; i < a.length; i++) {
209
+ if (a[i] !== b[i]) return false;
210
+ }
211
+ return true;
212
+ }
213
+ function shallowEqualOptions(a, b) {
214
+ if (a === b) return true;
215
+ if (!a || !b) return false;
216
+ return a === b;
217
+ }
218
+ function shallowEqualSource(a, b) {
219
+ if (a === b) return true;
220
+ if (!a || !b) return false;
221
+ if (a.type !== b.type) return false;
222
+ if (a.type === "file" && b.type === "file") {
223
+ return a.path === b.path;
224
+ }
225
+ if (a.type === "websocket" && b.type === "websocket") {
226
+ return a.url === b.url;
227
+ }
228
+ return false;
229
+ }
230
+ export {
231
+ Graph,
232
+ Playground
233
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@3plate/graph-react",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "license": "GPL-3.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,16 +21,23 @@
21
21
  "react-dom": "^18.0.0 || ^19.0.0"
22
22
  },
23
23
  "dependencies": {
24
- "@3plate/graph-core": "0.1.5"
24
+ "@3plate/graph-core": "0.1.7"
25
25
  },
26
26
  "devDependencies": {
27
+ "@testing-library/jest-dom": "^6.6.3",
28
+ "@testing-library/react": "^16.1.0",
29
+ "@testing-library/user-event": "^14.5.2",
27
30
  "@types/react": "^19.2.7",
28
31
  "@types/react-dom": "^19.2.3",
32
+ "jsdom": "^25.0.1",
29
33
  "tsup": "^8.5.1",
30
- "typescript": "^5.9.3"
34
+ "typescript": "^5.9.3",
35
+ "vitest": "^2.1.8"
31
36
  },
32
37
  "scripts": {
33
38
  "build": "tsup src/index.ts --format cjs,esm --dts --external react --external react-dom",
34
- "dev": "tsup src/index.ts --format cjs,esm --dts --watch --external react --external react-dom"
39
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch --external react --external react-dom",
40
+ "test": "vitest run",
41
+ "test:watch": "vitest"
35
42
  }
36
43
  }