@inditextech/weave-sdk 2.1.1 → 2.2.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/sdk.node.js CHANGED
@@ -15008,6 +15008,7 @@ var require_lodash = __commonJS({ "../../node_modules/lodash/lodash.js"(exports,
15008
15008
  } else root$8._ = _;
15009
15009
  }).call(exports);
15010
15010
  } });
15011
+ var import_lodash$1 = __toESM(require_lodash());
15011
15012
  var import_lodash = __toESM(require_lodash(), 1);
15012
15013
 
15013
15014
  //#endregion
@@ -15152,13 +15153,13 @@ var WeaveStore = class {
15152
15153
  node: JSON.parse(JSON.stringify(nodeInfo.node))
15153
15154
  });
15154
15155
  }
15155
- if (!this.isRoomLoaded && !(0, import_lodash.isEmpty)(this.state.weave)) {
15156
+ if (!this.isRoomLoaded && !(0, import_lodash$1.isEmpty)(this.state.weave)) {
15156
15157
  this.instance.setupRenderer();
15157
15158
  this.isRoomLoaded = true;
15158
15159
  this.emitOnRoomLoadedEvent();
15159
15160
  return;
15160
15161
  }
15161
- if (this.isRoomLoaded && !(0, import_lodash.isEmpty)(this.state.weave)) this.instance.render();
15162
+ if (this.isRoomLoaded && !(0, import_lodash$1.isEmpty)(this.state.weave)) this.instance.render();
15162
15163
  });
15163
15164
  }
15164
15165
  canUndoStateStep() {
@@ -17601,7 +17602,7 @@ var require_mergeWith = __commonJS({ "../../node_modules/lodash/mergeWith.js"(ex
17601
17602
  });
17602
17603
  module.exports = mergeWith;
17603
17604
  } });
17604
- var import_mergeWith = __toESM(require_mergeWith(), 1);
17605
+ var import_mergeWith = __toESM(require_mergeWith());
17605
17606
 
17606
17607
  //#endregion
17607
17608
  //#region src/utils.ts
@@ -18451,7 +18452,7 @@ var require_throttle = __commonJS({ "../../node_modules/lodash/throttle.js"(expo
18451
18452
  }
18452
18453
  module.exports = throttle;
18453
18454
  } });
18454
- var import_throttle = __toESM(require_throttle(), 1);
18455
+ var import_throttle = __toESM(require_throttle());
18455
18456
 
18456
18457
  //#endregion
18457
18458
  //#region src/nodes/stage/constants.ts
@@ -19347,11 +19348,11 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
19347
19348
  }
19348
19349
  if (nodesSelected === 1) {
19349
19350
  transformerAttrs = mergeExceptArrays(transformerAttrs, nodes[0].getTransformerProperties());
19350
- transformerAttrs.enabledAnchors = nodes[0].allowedAnchors();
19351
+ transformerAttrs.enabledAnchors = nodes[0]?.allowedAnchors() ?? [];
19351
19352
  }
19352
19353
  if (nodesSelected > 1) {
19353
19354
  const anchorsArrays = [];
19354
- for (const node of nodes) anchorsArrays.push(node.allowedAnchors());
19355
+ for (const node of nodes) anchorsArrays.push(node?.allowedAnchors() ?? []);
19355
19356
  transformerAttrs.enabledAnchors = intersectArrays(anchorsArrays);
19356
19357
  }
19357
19358
  if (this.tr && this.tr.nodes().length > 0) {
@@ -19985,7 +19986,7 @@ var WeaveNode = class {
19985
19986
  if (nodesSelectionPlugin && this.isSelecting() && this.isNodeSelected(node$1)) nodesSelectionPlugin.getTransformer().forceUpdate();
19986
19987
  if (nodesEdgeSnappingPlugin && transforming && this.isSelecting() && this.isNodeSelected(node$1)) nodesEdgeSnappingPlugin.evaluateGuidelines(e);
19987
19988
  };
19988
- node.on("transform", (0, import_lodash.throttle)(handleTransform, 100));
19989
+ node.on("transform", (0, import_lodash$1.throttle)(handleTransform, 100));
19989
19990
  node.on("transformend", (e) => {
19990
19991
  const node$1 = e.target;
19991
19992
  this.instance.emitEvent("onTransform", null);
@@ -20077,7 +20078,7 @@ var WeaveNode = class {
20077
20078
  if (layerToMove && !hasFrames(realNodeTarget) && realNodeTarget.isDragging()) layerToMove.fire(WEAVE_NODE_CUSTOM_EVENTS.onTargetEnter, { bubbles: true });
20078
20079
  }
20079
20080
  };
20080
- node.on("dragmove", (0, import_lodash.throttle)(handleDragMove, 100));
20081
+ node.on("dragmove", (0, import_lodash$1.throttle)(handleDragMove, 100));
20081
20082
  node.on("dragend", (e) => {
20082
20083
  const nodeTarget = e.target;
20083
20084
  this.getNodesSelectionFeedbackPlugin()?.hideSelectionHalo(nodeTarget);
@@ -20394,29 +20395,50 @@ var WeaveReconciler = class {
20394
20395
  const type = child.getAttrs().nodeType;
20395
20396
  const handler = this.instance.getNodeHandler(type);
20396
20397
  if (!handler) return;
20398
+ let nodeAdded = false;
20397
20399
  if (parentInstance instanceof Konva.Stage && child instanceof Konva.Layer) {
20398
20400
  parentInstance.add(child);
20399
20401
  handler.onAdd?.(child);
20402
+ nodeAdded = true;
20400
20403
  }
20401
20404
  if (parentInstance instanceof Konva.Layer) {
20402
20405
  parentInstance.add(child);
20403
20406
  handler.onAdd?.(child);
20407
+ nodeAdded = true;
20404
20408
  }
20405
20409
  if (parentInstance instanceof Konva.Group && typeof parentAttrs.containerId !== "undefined") {
20406
20410
  const realParent = parentInstance.findOne(`#${parentAttrs.containerId}`);
20407
20411
  realParent?.add(child);
20408
20412
  handler.onAdd?.(child);
20413
+ nodeAdded = true;
20409
20414
  }
20410
20415
  if (parentInstance instanceof Konva.Group && typeof parentAttrs.containerId === "undefined") {
20411
20416
  parentInstance.add(child);
20412
20417
  handler.onAdd?.(child);
20418
+ nodeAdded = true;
20413
20419
  }
20414
20420
  if (childInitialZIndex) child.zIndex(childInitialZIndex);
20421
+ if (nodeAdded) this.instance.emitEvent("onNodeRenderedAdded", child);
20422
+ }
20423
+ updateNode(instance, type, prevProps, nextProps) {
20424
+ if (!(0, import_lodash.isEqual)(prevProps, nextProps)) {
20425
+ const handler = this.instance.getNodeHandler(type);
20426
+ if (!handler) return;
20427
+ handler.onUpdate(instance, nextProps);
20428
+ const childZIndex = nextProps.zIndex;
20429
+ if (childZIndex) instance.zIndex(childZIndex);
20430
+ this.instance.emitEvent("onNodeRenderedUpdated", instance);
20431
+ }
20432
+ }
20433
+ removeNode(node) {
20434
+ this.instance.emitEvent("onNodeRenderedRemoved", node);
20415
20435
  }
20416
20436
  getConfig() {
20417
20437
  const weaveInstance = this.instance;
20418
20438
  const logger = this.logger;
20419
20439
  const addNode = this.addNode.bind(this);
20440
+ const updateNode = this.updateNode.bind(this);
20441
+ const removeNode = this.removeNode.bind(this);
20420
20442
  return {
20421
20443
  noTimeout: -1,
20422
20444
  isPrimaryRenderer: true,
@@ -20610,13 +20632,7 @@ var WeaveReconciler = class {
20610
20632
  nextProps
20611
20633
  }, "commitUpdate");
20612
20634
  if (instance instanceof Weave) return;
20613
- if (!(0, import_lodash.isEqual)(prevProps, nextProps)) {
20614
- const handler = weaveInstance.getNodeHandler(type);
20615
- if (!handler) return;
20616
- handler.onUpdate(instance, nextProps);
20617
- const childZIndex = nextProps.zIndex;
20618
- if (childZIndex) instance.zIndex(childZIndex);
20619
- }
20635
+ updateNode(instance, type, prevProps, nextProps);
20620
20636
  },
20621
20637
  removeChildFromContainer() {
20622
20638
  logger.debug("removeChildFromContainer");
@@ -20627,6 +20643,7 @@ var WeaveReconciler = class {
20627
20643
  const handler = weaveInstance.getNodeHandler(type);
20628
20644
  if (!handler) return;
20629
20645
  handler.onDestroy(child);
20646
+ removeNode(child);
20630
20647
  }
20631
20648
  };
20632
20649
  }
@@ -21527,27 +21544,23 @@ var WeaveStateManager = class {
21527
21544
  }, msg);
21528
21545
  return;
21529
21546
  }
21530
- const doc = getYjsDoc(state);
21531
- const userId = this.instance.getStore().getUser().id;
21532
- doc.transact(() => {
21533
- if (!parent.props.children) parent.props.children = [];
21534
- if (index) {
21535
- parent.props.children.splice(index, 0, node);
21536
- for (let i = 0; i < parent.props.children.length; i++) parent.props.children[i].props.zIndex = i;
21537
- }
21538
- if (!index) {
21539
- const childrenAmount = parent.props.children.length;
21540
- const nodeToAdd = {
21541
- ...node,
21542
- props: {
21543
- ...node.props,
21544
- zIndex: childrenAmount
21545
- }
21546
- };
21547
- parent.props.children.push(nodeToAdd);
21548
- }
21549
- this.instance.emitEvent("onNodeAdded", node);
21550
- }, userId);
21547
+ if (!parent.props.children) parent.props.children = [];
21548
+ if (index) {
21549
+ parent.props.children.splice(index, 0, node);
21550
+ for (let i = 0; i < parent.props.children.length; i++) parent.props.children[i].props.zIndex = i;
21551
+ }
21552
+ if (!index) {
21553
+ const childrenAmount = parent.props.children.length;
21554
+ const nodeToAdd = {
21555
+ ...node,
21556
+ props: {
21557
+ ...node.props,
21558
+ zIndex: childrenAmount
21559
+ }
21560
+ };
21561
+ parent.props.children.push(nodeToAdd);
21562
+ }
21563
+ this.instance.emitEvent("onNodeAdded", node);
21551
21564
  }
21552
21565
  deepSyncSyncedStore(target, source) {
21553
21566
  for (const key in target) if (!(key in source)) delete target[key];
@@ -21584,12 +21597,19 @@ var WeaveStateManager = class {
21584
21597
  this.logger.warn({ node }, msg);
21585
21598
  return;
21586
21599
  }
21600
+ this.deepSyncSyncedStore(nodeState.props, node.props);
21601
+ this.instance.emitEvent("onNodeUpdated", node);
21602
+ }
21603
+ updateNodes(nodes) {
21604
+ for (const node of nodes) this.updateNode(node);
21605
+ }
21606
+ stateTransactional(callback) {
21607
+ const state = this.instance.getStore().getState();
21587
21608
  const doc = getYjsDoc(state);
21588
21609
  const userId = this.instance.getStore().getUser().id;
21589
21610
  doc.transact(() => {
21590
- this.deepSyncSyncedStore(nodeState.props, node.props);
21611
+ callback();
21591
21612
  }, userId);
21592
- this.instance.emitEvent("onNodeUpdated", node);
21593
21613
  }
21594
21614
  removeNode(node) {
21595
21615
  const state = this.instance.getStore().getState();
@@ -21609,21 +21629,14 @@ var WeaveStateManager = class {
21609
21629
  this.logger.warn({ node }, msg);
21610
21630
  return;
21611
21631
  }
21612
- const doc = getYjsDoc(state);
21613
- const userId = this.instance.getStore().getUser().id;
21614
- doc.transact(() => {
21615
- if (parent.props.children) {
21616
- for (let i = parent.props.children.length - 1; i >= 0; i--) if (parent.props.children[i].key === node.key) {
21617
- parent.props.children.splice(i, 1);
21618
- break;
21619
- }
21620
- for (let i = 0; i < parent.props.children.length; i++) parent.props.children[i].props.zIndex = i;
21621
- this.instance.emitEvent("onNodeRemoved", node);
21632
+ if (parent.props.children) {
21633
+ for (let i = parent.props.children.length - 1; i >= 0; i--) if (parent.props.children[i].key === node.key) {
21634
+ parent.props.children.splice(i, 1);
21635
+ break;
21622
21636
  }
21623
- }, userId);
21624
- }
21625
- removeNodes(nodes) {
21626
- for (const node of nodes) this.removeNode(node);
21637
+ for (let i = 0; i < parent.props.children.length; i++) parent.props.children[i].props.zIndex = i;
21638
+ this.instance.emitEvent("onNodeRemoved", node);
21639
+ }
21627
21640
  }
21628
21641
  moveNode(node, position) {
21629
21642
  const state = this.instance.getStore().getState();
@@ -21651,19 +21664,15 @@ var WeaveStateManager = class {
21651
21664
  this.logger.warn({ node }, msg);
21652
21665
  return;
21653
21666
  }
21654
- const doc = getYjsDoc(state);
21655
- const userId = this.instance.getStore().getUser().id;
21656
- doc.transact(() => {
21657
- if (parent.props.children) {
21658
- const item = JSON.parse(JSON.stringify(parent.props.children[nodeIndex]));
21659
- parent.props.children.splice(nodeIndex, 1);
21660
- if (item && position === WEAVE_NODE_POSITION.UP) parent.props.children.splice(nodeIndex + 1, 0, item);
21661
- if (item && position === WEAVE_NODE_POSITION.DOWN) parent.props.children.splice(nodeIndex - 1, 0, item);
21662
- if (item && position === WEAVE_NODE_POSITION.FRONT) parent.props.children.splice(childrenAmount - 1, 0, item);
21663
- if (item && position === WEAVE_NODE_POSITION.BACK) parent.props.children.splice(0, 0, item);
21664
- for (let i = 0; i < parent.props.children.length; i++) parent.props.children[i].props.zIndex = i;
21665
- }
21666
- }, userId);
21667
+ if (parent.props.children) {
21668
+ const item = JSON.parse(JSON.stringify(parent.props.children[nodeIndex]));
21669
+ parent.props.children.splice(nodeIndex, 1);
21670
+ if (item && position === WEAVE_NODE_POSITION.UP) parent.props.children.splice(nodeIndex + 1, 0, item);
21671
+ if (item && position === WEAVE_NODE_POSITION.DOWN) parent.props.children.splice(nodeIndex - 1, 0, item);
21672
+ if (item && position === WEAVE_NODE_POSITION.FRONT) parent.props.children.splice(childrenAmount - 1, 0, item);
21673
+ if (item && position === WEAVE_NODE_POSITION.BACK) parent.props.children.splice(0, 0, item);
21674
+ for (let i = 0; i < parent.props.children.length; i++) parent.props.children[i].props.zIndex = i;
21675
+ }
21667
21676
  }
21668
21677
  }
21669
21678
  getElementsTree() {
@@ -21749,7 +21758,7 @@ var WeaveRegisterManager = class {
21749
21758
 
21750
21759
  //#endregion
21751
21760
  //#region package.json
21752
- var version = "2.1.1";
21761
+ var version = "2.2.0";
21753
21762
 
21754
21763
  //#endregion
21755
21764
  //#region src/managers/setup.ts
@@ -22536,25 +22545,59 @@ var Weave = class {
22536
22545
  return this.stateManager.getNode(nodeKey);
22537
22546
  }
22538
22547
  addNode(node, parentId = "mainLayer", index = void 0) {
22548
+ this.stateTransactional(() => {
22549
+ this.stateManager.addNode(node, parentId, index);
22550
+ });
22551
+ }
22552
+ addNodeNT(node, parentId = "mainLayer", index = void 0) {
22539
22553
  this.stateManager.addNode(node, parentId, index);
22540
22554
  }
22541
22555
  updateNode(node) {
22556
+ this.stateTransactional(() => {
22557
+ this.stateManager.updateNode(node);
22558
+ });
22559
+ }
22560
+ updateNodeNT(node) {
22542
22561
  this.stateManager.updateNode(node);
22543
22562
  }
22544
22563
  updateNodes(nodes) {
22545
- for (const node of nodes) this.updateNode(node);
22564
+ this.stateTransactional(() => {
22565
+ this.stateManager.updateNodes(nodes);
22566
+ });
22567
+ }
22568
+ updateNodesNT(nodes) {
22569
+ this.stateManager.updateNodes(nodes);
22546
22570
  }
22547
22571
  removeNode(node) {
22572
+ this.stateTransactional(() => {
22573
+ this.stateManager.removeNode(node);
22574
+ const selectionPlugin = this.getPlugin("nodesSelection");
22575
+ if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
22576
+ });
22577
+ }
22578
+ removeNodeNT(node) {
22548
22579
  this.stateManager.removeNode(node);
22549
22580
  const selectionPlugin = this.getPlugin("nodesSelection");
22550
22581
  if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
22551
22582
  }
22552
22583
  removeNodes(nodes) {
22553
- for (const node of nodes) this.removeNode(node);
22584
+ this.stateTransactional(() => {
22585
+ for (const node of nodes) this.removeNodeNT(node);
22586
+ const selectionPlugin = this.getPlugin("nodesSelection");
22587
+ if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
22588
+ });
22589
+ }
22590
+ removeNodesNT(nodes) {
22591
+ for (const node of nodes) this.removeNodeNT(node);
22554
22592
  const selectionPlugin = this.getPlugin("nodesSelection");
22555
22593
  if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
22556
22594
  }
22557
22595
  moveNode(node, position) {
22596
+ this.stateTransactional(() => {
22597
+ this.stateManager.moveNode(node, position);
22598
+ });
22599
+ }
22600
+ moveNodeNT(node, position) {
22558
22601
  this.stateManager.moveNode(node, position);
22559
22602
  }
22560
22603
  getElementsTree() {
@@ -22584,6 +22627,9 @@ var Weave = class {
22584
22627
  getBoundingBox(nodes, config) {
22585
22628
  return getBoundingBox(nodes, config);
22586
22629
  }
22630
+ stateTransactional(callback) {
22631
+ this.stateManager.stateTransactional(callback);
22632
+ }
22587
22633
  moveUp(node) {
22588
22634
  this.zIndexManager.moveUp(node);
22589
22635
  }
@@ -23258,7 +23304,7 @@ var WeaveTextNode = class extends WeaveNode {
23258
23304
  text.on("transformstart", (e) => {
23259
23305
  this.instance.emitEvent("onTransform", e.target);
23260
23306
  });
23261
- text.on("transform", (0, import_lodash.throttle)(handleTextTransform, 50));
23307
+ text.on("transform", (0, import_lodash$1.throttle)(handleTextTransform, 50));
23262
23308
  text.on("transformend", () => {
23263
23309
  this.instance.emitEvent("onTransform", null);
23264
23310
  });
@@ -26553,7 +26599,7 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
26553
26599
  this.config.zoomSteps = [minimumZoom, ...this.config.zoomSteps];
26554
26600
  }
26555
26601
  };
26556
- mainLayer?.on("draw", (0, import_lodash.throttle)(handleDraw, 50));
26602
+ mainLayer?.on("draw", (0, import_lodash$1.throttle)(handleDraw, 50));
26557
26603
  this.setZoom(this.config.zoomSteps[this.actualStep]);
26558
26604
  }
26559
26605
  setZoom(scale, centered = true, pointer) {
@@ -30271,7 +30317,7 @@ var WeaveStageGridPlugin = class extends WeavePlugin {
30271
30317
  if (!this.enabled || !(this.isSpaceKeyPressed || this.isMouseMiddleButtonPressed || this.moveToolActive)) return;
30272
30318
  this.onRender();
30273
30319
  };
30274
- stage.on("pointermove", (0, import_lodash.throttle)(handleMouseMove, 50));
30320
+ stage.on("pointermove", (0, import_lodash$1.throttle)(handleMouseMove, 50));
30275
30321
  stage.on("pointermove", () => {
30276
30322
  if (this.enabled) this.onRender();
30277
30323
  });
@@ -30580,7 +30626,7 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
30580
30626
  lastPos = pos;
30581
30627
  this.instance.emitEvent("onStageMove");
30582
30628
  };
30583
- stage.on("pointermove", (0, import_lodash.throttle)(handleMouseMove, 50));
30629
+ stage.on("pointermove", (0, import_lodash$1.throttle)(handleMouseMove, 50));
30584
30630
  stage.on("pointerup", (e) => {
30585
30631
  this.pointers.delete(e.evt.pointerId);
30586
30632
  this.isMouseLeftButtonPressed = false;
@@ -30844,7 +30890,7 @@ var WeaveStageMinimapPlugin = class extends WeavePlugin {
30844
30890
  this.setupMinimap();
30845
30891
  }
30846
30892
  onInit() {
30847
- const throttledUpdateMinimap = (0, import_lodash.throttle)(async () => {
30893
+ const throttledUpdateMinimap = (0, import_lodash$1.throttle)(async () => {
30848
30894
  await this.updateMinimapContent();
30849
30895
  this.updateMinimapViewportReference();
30850
30896
  }, 100);
@@ -31137,7 +31183,7 @@ var WeaveConnectedUsersPlugin = class extends WeavePlugin {
31137
31183
  newConnectedUsers[userInformation.id] = userInformation;
31138
31184
  }
31139
31185
  }
31140
- if (!(0, import_lodash.isEqual)(this.connectedUsers, newConnectedUsers)) this.instance.emitEvent("onConnectedUsersChange", newConnectedUsers);
31186
+ if (!(0, import_lodash$1.isEqual)(this.connectedUsers, newConnectedUsers)) this.instance.emitEvent("onConnectedUsersChange", newConnectedUsers);
31141
31187
  this.connectedUsers = newConnectedUsers;
31142
31188
  });
31143
31189
  }
@@ -31385,7 +31431,7 @@ var WeaveUsersPointersPlugin = class extends WeavePlugin {
31385
31431
  for (let i = 0; i < inactiveUsers.length; i++) delete this.usersPointers[inactiveUsers[i]];
31386
31432
  this.renderPointers();
31387
31433
  });
31388
- const sendAwarenessUpdateThrottled = (0, import_lodash.throttle)(this.sendAwarenessUpdate.bind(this), this.config.awarenessThrottleMs);
31434
+ const sendAwarenessUpdateThrottled = (0, import_lodash$1.throttle)(this.sendAwarenessUpdate.bind(this), this.config.awarenessThrottleMs);
31389
31435
  stage.on("dragmove", () => {
31390
31436
  const mousePos = stage.getRelativePointerPosition();
31391
31437
  if (mousePos) sendAwarenessUpdateThrottled(mousePos);