@inditextech/weave-react 0.14.3 → 0.16.0

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/react.cjs CHANGED
@@ -214,7 +214,7 @@ const useWeave = create()((set) => ({
214
214
 
215
215
  //#endregion
216
216
  //#region src/components/provider.tsx
217
- const WeaveProvider = ({ containerId, getUser, store, nodes = [], actions = [], plugins = [], customPlugins = [], fonts = [], callbacks = {}, children }) => {
217
+ const WeaveProvider = ({ containerId, getUser, store, nodes = [], actions = [], plugins = [], customPlugins = [], fonts = [], children }) => {
218
218
  const weaveInstanceRef = react.default.useRef(null);
219
219
  const selectedNodes = useWeave((state) => state.selection.nodes);
220
220
  const setInstance = useWeave((state) => state.setInstance);
@@ -224,19 +224,16 @@ const WeaveProvider = ({ containerId, getUser, store, nodes = [], actions = [],
224
224
  const setCanUndo = useWeave((state) => state.setCanUndo);
225
225
  const setCanRedo = useWeave((state) => state.setCanRedo);
226
226
  const setActualAction = useWeave((state) => state.setActualAction);
227
- const { onInstanceStatus, onRoomLoaded, onStateChange, onUndoManagerStatusChange, onActiveActionChange,...restCallbacks } = callbacks;
228
227
  const onInstanceStatusHandler = react.default.useCallback(
229
- (status$1) => {
230
- setStatus(status$1);
231
- onInstanceStatus?.(status$1);
228
+ (status) => {
229
+ setStatus(status);
232
230
  },
233
231
  // eslint-disable-next-line react-hooks/exhaustive-deps
234
232
  []
235
233
  );
236
234
  const onRoomLoadedHandler = react.default.useCallback(
237
- (status$1) => {
238
- setRoomLoaded(status$1);
239
- onRoomLoaded?.(status$1);
235
+ (status) => {
236
+ setRoomLoaded(status);
240
237
  },
241
238
  // eslint-disable-next-line react-hooks/exhaustive-deps
242
239
  []
@@ -244,7 +241,6 @@ const WeaveProvider = ({ containerId, getUser, store, nodes = [], actions = [],
244
241
  const onStateChangeHandler = react.default.useCallback(
245
242
  (state) => {
246
243
  setAppState(state);
247
- onStateChange?.(state);
248
244
  },
249
245
  // eslint-disable-next-line react-hooks/exhaustive-deps
250
246
  [selectedNodes]
@@ -254,7 +250,6 @@ const WeaveProvider = ({ containerId, getUser, store, nodes = [], actions = [],
254
250
  const { canUndo, canRedo } = undoManagerStatus;
255
251
  setCanUndo(canUndo);
256
252
  setCanRedo(canRedo);
257
- onUndoManagerStatusChange?.(undoManagerStatus);
258
253
  },
259
254
  // eslint-disable-next-line react-hooks/exhaustive-deps
260
255
  []
@@ -262,7 +257,6 @@ const WeaveProvider = ({ containerId, getUser, store, nodes = [], actions = [],
262
257
  const onActiveActionChangeHandler = react.default.useCallback(
263
258
  (actionName) => {
264
259
  setActualAction(actionName);
265
- onActiveActionChange?.(status);
266
260
  },
267
261
  // eslint-disable-next-line react-hooks/exhaustive-deps
268
262
  [selectedNodes]
@@ -289,6 +283,7 @@ const WeaveProvider = ({ containerId, getUser, store, nodes = [], actions = [],
289
283
  instancePlugins.push(new __inditextech_weave_sdk.WeaveCopyPasteNodesPlugin());
290
284
  instancePlugins.push(new __inditextech_weave_sdk.WeaveConnectedUsersPlugin({ config: { getUser } }));
291
285
  instancePlugins.push(new __inditextech_weave_sdk.WeaveUsersPointersPlugin({ config: { getUser } }));
286
+ instancePlugins.push(new __inditextech_weave_sdk.WeaveUsersSelectionPlugin({ config: { getUser } }));
292
287
  instancePlugins.push(new __inditextech_weave_sdk.WeaveContextMenuPlugin({ config: {
293
288
  xOffset: 10,
294
289
  yOffset: 10
@@ -300,25 +295,28 @@ const WeaveProvider = ({ containerId, getUser, store, nodes = [], actions = [],
300
295
  actions,
301
296
  plugins: [...instancePlugins, ...customPlugins],
302
297
  fonts,
303
- callbacks: {
304
- ...restCallbacks,
305
- onInstanceStatus: onInstanceStatusHandler,
306
- onRoomLoaded: onRoomLoadedHandler,
307
- onStateChange: onStateChangeHandler,
308
- onUndoManagerStatusChange: onUndoManagerStatusChangeHandler,
309
- onActiveActionChange: onActiveActionChangeHandler
310
- },
311
298
  logger: { level: "info" }
312
299
  }, {
313
300
  container: containerId,
314
301
  width: weaveEleClientRect?.width ?? 1920,
315
302
  height: weaveEleClientRect?.height ?? 1080
316
303
  });
304
+ weaveInstanceRef.current.addEventListener("onInstanceStatus", onInstanceStatusHandler);
305
+ weaveInstanceRef.current.addEventListener("onRoomLoaded", onRoomLoadedHandler);
306
+ weaveInstanceRef.current.addEventListener("onStateChange", onStateChangeHandler);
307
+ weaveInstanceRef.current.addEventListener("onUndoManagerStatusChange", onUndoManagerStatusChangeHandler);
308
+ weaveInstanceRef.current.addEventListener("onActiveActionChange", onActiveActionChangeHandler);
317
309
  setInstance(weaveInstanceRef.current);
318
310
  weaveInstanceRef.current.start();
319
311
  }
320
312
  }
313
+ setStatus(WEAVE_INSTANCE_STATUS.IDLE);
314
+ setRoomLoaded(false);
321
315
  initWeave();
316
+ return () => {
317
+ weaveInstanceRef.current?.destroy();
318
+ weaveInstanceRef.current = null;
319
+ };
322
320
  }, []);
323
321
  return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, children);
324
322
  };
package/dist/react.d.cts CHANGED
@@ -48,20 +48,6 @@ type WeaveUser = {
48
48
  type WeaveFont = {
49
49
  id: string;
50
50
  name: string;
51
- };
52
- type WeaveUndoRedoChange = {
53
- canRedo: boolean;
54
- canUndo: boolean;
55
- redoStackLength: number;
56
- undoStackLength: number;
57
- };
58
- type WeaveCallbacks = {
59
- onRender?: () => void;
60
- onRoomLoaded?: (loaded: boolean) => void;
61
- onInstanceStatus?: (status: WeaveStatus) => void;
62
- onActiveActionChange?: (actionName: string | undefined) => void;
63
- onStateChange?: (state: WeaveState) => void;
64
- onUndoManagerStatusChange?: (undoManagerStatus: WeaveUndoRedoChange) => void;
65
51
  }; //#endregion
66
52
  //#region src/components/provider.d.ts
67
53
  type WeaveProviderType = {
@@ -75,7 +61,6 @@ type WeaveProviderType = {
75
61
  customNodes?: WeaveNode[];
76
62
  customActions?: WeaveAction[];
77
63
  customPlugins?: WeavePlugin[];
78
- callbacks?: WeaveCallbacks;
79
64
  children: React.ReactNode;
80
65
  };
81
66
  declare const WeaveProvider: ({
@@ -87,7 +72,6 @@ declare const WeaveProvider: ({
87
72
  plugins,
88
73
  customPlugins,
89
74
  fonts,
90
- callbacks,
91
75
  children
92
76
  }: Readonly<WeaveProviderType>) => React.JSX.Element;
93
77
 
package/dist/react.d.ts CHANGED
@@ -48,20 +48,6 @@ type WeaveUser = {
48
48
  type WeaveFont = {
49
49
  id: string;
50
50
  name: string;
51
- };
52
- type WeaveUndoRedoChange = {
53
- canRedo: boolean;
54
- canUndo: boolean;
55
- redoStackLength: number;
56
- undoStackLength: number;
57
- };
58
- type WeaveCallbacks = {
59
- onRender?: () => void;
60
- onRoomLoaded?: (loaded: boolean) => void;
61
- onInstanceStatus?: (status: WeaveStatus) => void;
62
- onActiveActionChange?: (actionName: string | undefined) => void;
63
- onStateChange?: (state: WeaveState) => void;
64
- onUndoManagerStatusChange?: (undoManagerStatus: WeaveUndoRedoChange) => void;
65
51
  }; //#endregion
66
52
  //#region src/components/provider.d.ts
67
53
  type WeaveProviderType = {
@@ -75,7 +61,6 @@ type WeaveProviderType = {
75
61
  customNodes?: WeaveNode[];
76
62
  customActions?: WeaveAction[];
77
63
  customPlugins?: WeavePlugin[];
78
- callbacks?: WeaveCallbacks;
79
64
  children: React.ReactNode;
80
65
  };
81
66
  declare const WeaveProvider: ({
@@ -87,7 +72,6 @@ declare const WeaveProvider: ({
87
72
  plugins,
88
73
  customPlugins,
89
74
  fonts,
90
- callbacks,
91
75
  children
92
76
  }: Readonly<WeaveProviderType>) => React.JSX.Element;
93
77
 
package/dist/react.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { Weave, WeaveAction, WeaveConnectedUsersPlugin, WeaveContextMenuPlugin, WeaveCopyPasteNodesPlugin, WeaveNode, WeaveNodesSelectionPlugin, WeaveNodesSnappingPlugin, WeavePlugin, WeaveStageDropAreaPlugin, WeaveStageGridPlugin, WeaveStagePanningPlugin, WeaveStageResizePlugin, WeaveStageZoomPlugin, WeaveStore, WeaveUsersPointersPlugin } from "@inditextech/weave-sdk";
2
+ import { Weave, WeaveAction, WeaveConnectedUsersPlugin, WeaveContextMenuPlugin, WeaveCopyPasteNodesPlugin, WeaveNode, WeaveNodesSelectionPlugin, WeaveNodesSnappingPlugin, WeavePlugin, WeaveStageDropAreaPlugin, WeaveStageGridPlugin, WeaveStagePanningPlugin, WeaveStageResizePlugin, WeaveStageZoomPlugin, WeaveStore, WeaveUsersPointersPlugin, WeaveUsersSelectionPlugin } from "@inditextech/weave-sdk";
3
3
  import Konva from "konva";
4
4
  import "yjs";
5
5
 
@@ -190,7 +190,7 @@ const useWeave = create()((set) => ({
190
190
 
191
191
  //#endregion
192
192
  //#region src/components/provider.tsx
193
- const WeaveProvider = ({ containerId, getUser, store, nodes = [], actions = [], plugins = [], customPlugins = [], fonts = [], callbacks = {}, children }) => {
193
+ const WeaveProvider = ({ containerId, getUser, store, nodes = [], actions = [], plugins = [], customPlugins = [], fonts = [], children }) => {
194
194
  const weaveInstanceRef = React.useRef(null);
195
195
  const selectedNodes = useWeave((state) => state.selection.nodes);
196
196
  const setInstance = useWeave((state) => state.setInstance);
@@ -200,19 +200,16 @@ const WeaveProvider = ({ containerId, getUser, store, nodes = [], actions = [],
200
200
  const setCanUndo = useWeave((state) => state.setCanUndo);
201
201
  const setCanRedo = useWeave((state) => state.setCanRedo);
202
202
  const setActualAction = useWeave((state) => state.setActualAction);
203
- const { onInstanceStatus, onRoomLoaded, onStateChange, onUndoManagerStatusChange, onActiveActionChange,...restCallbacks } = callbacks;
204
203
  const onInstanceStatusHandler = React.useCallback(
205
- (status$1) => {
206
- setStatus(status$1);
207
- onInstanceStatus?.(status$1);
204
+ (status) => {
205
+ setStatus(status);
208
206
  },
209
207
  // eslint-disable-next-line react-hooks/exhaustive-deps
210
208
  []
211
209
  );
212
210
  const onRoomLoadedHandler = React.useCallback(
213
- (status$1) => {
214
- setRoomLoaded(status$1);
215
- onRoomLoaded?.(status$1);
211
+ (status) => {
212
+ setRoomLoaded(status);
216
213
  },
217
214
  // eslint-disable-next-line react-hooks/exhaustive-deps
218
215
  []
@@ -220,7 +217,6 @@ const WeaveProvider = ({ containerId, getUser, store, nodes = [], actions = [],
220
217
  const onStateChangeHandler = React.useCallback(
221
218
  (state) => {
222
219
  setAppState(state);
223
- onStateChange?.(state);
224
220
  },
225
221
  // eslint-disable-next-line react-hooks/exhaustive-deps
226
222
  [selectedNodes]
@@ -230,7 +226,6 @@ const WeaveProvider = ({ containerId, getUser, store, nodes = [], actions = [],
230
226
  const { canUndo, canRedo } = undoManagerStatus;
231
227
  setCanUndo(canUndo);
232
228
  setCanRedo(canRedo);
233
- onUndoManagerStatusChange?.(undoManagerStatus);
234
229
  },
235
230
  // eslint-disable-next-line react-hooks/exhaustive-deps
236
231
  []
@@ -238,7 +233,6 @@ const WeaveProvider = ({ containerId, getUser, store, nodes = [], actions = [],
238
233
  const onActiveActionChangeHandler = React.useCallback(
239
234
  (actionName) => {
240
235
  setActualAction(actionName);
241
- onActiveActionChange?.(status);
242
236
  },
243
237
  // eslint-disable-next-line react-hooks/exhaustive-deps
244
238
  [selectedNodes]
@@ -265,6 +259,7 @@ const WeaveProvider = ({ containerId, getUser, store, nodes = [], actions = [],
265
259
  instancePlugins.push(new WeaveCopyPasteNodesPlugin());
266
260
  instancePlugins.push(new WeaveConnectedUsersPlugin({ config: { getUser } }));
267
261
  instancePlugins.push(new WeaveUsersPointersPlugin({ config: { getUser } }));
262
+ instancePlugins.push(new WeaveUsersSelectionPlugin({ config: { getUser } }));
268
263
  instancePlugins.push(new WeaveContextMenuPlugin({ config: {
269
264
  xOffset: 10,
270
265
  yOffset: 10
@@ -276,25 +271,28 @@ const WeaveProvider = ({ containerId, getUser, store, nodes = [], actions = [],
276
271
  actions,
277
272
  plugins: [...instancePlugins, ...customPlugins],
278
273
  fonts,
279
- callbacks: {
280
- ...restCallbacks,
281
- onInstanceStatus: onInstanceStatusHandler,
282
- onRoomLoaded: onRoomLoadedHandler,
283
- onStateChange: onStateChangeHandler,
284
- onUndoManagerStatusChange: onUndoManagerStatusChangeHandler,
285
- onActiveActionChange: onActiveActionChangeHandler
286
- },
287
274
  logger: { level: "info" }
288
275
  }, {
289
276
  container: containerId,
290
277
  width: weaveEleClientRect?.width ?? 1920,
291
278
  height: weaveEleClientRect?.height ?? 1080
292
279
  });
280
+ weaveInstanceRef.current.addEventListener("onInstanceStatus", onInstanceStatusHandler);
281
+ weaveInstanceRef.current.addEventListener("onRoomLoaded", onRoomLoadedHandler);
282
+ weaveInstanceRef.current.addEventListener("onStateChange", onStateChangeHandler);
283
+ weaveInstanceRef.current.addEventListener("onUndoManagerStatusChange", onUndoManagerStatusChangeHandler);
284
+ weaveInstanceRef.current.addEventListener("onActiveActionChange", onActiveActionChangeHandler);
293
285
  setInstance(weaveInstanceRef.current);
294
286
  weaveInstanceRef.current.start();
295
287
  }
296
288
  }
289
+ setStatus(WEAVE_INSTANCE_STATUS.IDLE);
290
+ setRoomLoaded(false);
297
291
  initWeave();
292
+ return () => {
293
+ weaveInstanceRef.current?.destroy();
294
+ weaveInstanceRef.current = null;
295
+ };
298
296
  }, []);
299
297
  return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
300
298
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inditextech/weave-react",
3
- "version": "0.14.3",
3
+ "version": "0.16.0",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Jesus Manuel Piñeiro Cid <jesusmpc@inditex.com>",
@@ -48,7 +48,7 @@
48
48
  "yjs": "13.6.26"
49
49
  },
50
50
  "devDependencies": {
51
- "@inditextech/weave-sdk": "0.14.3",
51
+ "@inditextech/weave-sdk": "0.16.0",
52
52
  "@types/node": "^22.15.3",
53
53
  "@typescript-eslint/eslint-plugin": "8.26.0",
54
54
  "@typescript-eslint/parser": "8.26.0",