@inditextech/weave-sdk 2.1.1 → 2.3.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.js CHANGED
@@ -17616,7 +17616,7 @@ function resetScale(node) {
17616
17616
  }
17617
17617
  function clearContainerTargets(instance) {
17618
17618
  const containers = instance.getContainerNodes();
17619
- for (const container of containers) container.fire(WEAVE_NODE_CUSTOM_EVENTS.onTargetLeave, { bubbles: true });
17619
+ for (const container of containers) container.fire(WEAVE_NODE_CUSTOM_EVENTS.onTargetLeave, { node: void 0 });
17620
17620
  }
17621
17621
  function containerOverCursor(instance, ignoreNodes, definedCursorPosition) {
17622
17622
  Konva.hitOnDragEnabled = true;
@@ -17642,6 +17642,8 @@ function moveNodeToContainer(instance, node, containerToMove, invalidOriginsType
17642
17642
  const stage = instance.getStage();
17643
17643
  const isLocked = instance.allNodesLocked([node]);
17644
17644
  if (isLocked) return false;
17645
+ const canMoveToLayer = containerToMove.canMoveToContainer(node);
17646
+ if (!canMoveToLayer) return false;
17645
17647
  let nodeActualContainer = node.getParent();
17646
17648
  if (nodeActualContainer.getAttrs().nodeId) {
17647
17649
  const realParent = stage.findOne(`#${nodeActualContainer.getAttrs().nodeId}`);
@@ -17661,6 +17663,10 @@ function moveNodeToContainer(instance, node, containerToMove, invalidOriginsType
17661
17663
  node.x(node.x() - (layerToMoveAttrs.containerOffsetX ?? 0));
17662
17664
  node.y(node.y() - (layerToMoveAttrs.containerOffsetY ?? 0));
17663
17665
  node.movedToContainer(layerToMove);
17666
+ instance.emitEvent("onNodeMovedToContainer", {
17667
+ node: node.clone(),
17668
+ container: layerToMove
17669
+ });
17664
17670
  const nodeHandler = instance.getNodeHandler(node.getAttrs().nodeType);
17665
17671
  if (nodeHandler) {
17666
17672
  const actualNode = nodeHandler.serialize(node);
@@ -17902,6 +17908,16 @@ function mergeExceptArrays(object, source) {
17902
17908
  return void 0;
17903
17909
  });
17904
17910
  }
17911
+ function getStageClickPoint(instance, pointerPos) {
17912
+ const stage = instance.getStage();
17913
+ const scale = stage.scale();
17914
+ const position = stage.position();
17915
+ const stageClickPoint = {
17916
+ x: (pointerPos.x - position.x) / scale.x,
17917
+ y: (pointerPos.y - position.y) / scale.y
17918
+ };
17919
+ return stageClickPoint;
17920
+ }
17905
17921
 
17906
17922
  //#endregion
17907
17923
  //#region src/actions/selection-tool/constants.ts
@@ -18719,6 +18735,8 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
18719
18735
  this.triggerSelectedNodesEvent();
18720
18736
  });
18721
18737
  let initialPos = null;
18738
+ const originalNodeOpacity = {};
18739
+ const DRAG_OPACITY = .75;
18722
18740
  tr.on("dragstart", (e) => {
18723
18741
  initialPos = {
18724
18742
  x: e.target.x(),
@@ -18731,6 +18749,11 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
18731
18749
  e.target.stopDrag();
18732
18750
  return;
18733
18751
  }
18752
+ const nodes = tr.nodes();
18753
+ if (nodes.length > 1) for (const node of nodes) {
18754
+ originalNodeOpacity[node.getAttrs().id ?? ""] = node.opacity();
18755
+ node.opacity(DRAG_OPACITY);
18756
+ }
18734
18757
  e.cancelBubble = true;
18735
18758
  tr.forceUpdate();
18736
18759
  });
@@ -18761,7 +18784,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
18761
18784
  if (this.isSelecting() && selectedNodes.length > 1) {
18762
18785
  clearContainerTargets(this.instance);
18763
18786
  const layerToMove = containerOverCursor(this.instance, selectedNodes);
18764
- if (layerToMove && !selectionContainsFrames) layerToMove.fire(WEAVE_NODE_CUSTOM_EVENTS.onTargetEnter, { bubbles: true });
18787
+ if (layerToMove && !selectionContainsFrames) layerToMove.fire(WEAVE_NODE_CUSTOM_EVENTS.onTargetEnter, { node: void 0 });
18765
18788
  }
18766
18789
  tr.forceUpdate();
18767
18790
  };
@@ -18778,6 +18801,11 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
18778
18801
  selectionContainsFrames = selectionContainsFrames || hasFrames(node);
18779
18802
  node.updatePosition(node.getAbsolutePosition());
18780
18803
  }
18804
+ const nodes = tr.nodes();
18805
+ if (nodes.length > 1) for (const node of nodes) {
18806
+ node.opacity(originalNodeOpacity[node.getAttrs().id ?? ""]);
18807
+ delete originalNodeOpacity[node.getAttrs().id ?? ""];
18808
+ }
18781
18809
  if (this.isSelecting() && tr.nodes().length > 1) {
18782
18810
  const actualCursor = stage.container().style.cursor;
18783
18811
  stage.container().style.cursor = "wait";
@@ -18788,6 +18816,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
18788
18816
  const nodeUpdatePromise = (node) => {
18789
18817
  return new Promise((resolve) => {
18790
18818
  setTimeout(() => {
18819
+ if (node.getAttrs().lockToContainer === void 0 || !node.getAttrs().lockToContainer) return resolve();
18791
18820
  clearContainerTargets(this.instance);
18792
18821
  const nodeHandler = this.instance.getNodeHandler(node.getAttrs().nodeType);
18793
18822
  if (nodeHandler) this.instance.updateNode(nodeHandler.serialize(node));
@@ -18795,7 +18824,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
18795
18824
  if (layerToMove) containerToMove = layerToMove;
18796
18825
  let moved = false;
18797
18826
  if (containerToMove && !selectionContainsFrames) moved = moveNodeToContainer(this.instance, node, containerToMove);
18798
- if (containerToMove) containerToMove.fire(WEAVE_NODE_CUSTOM_EVENTS.onTargetLeave, { bubbles: true });
18827
+ if (containerToMove) containerToMove.fire(WEAVE_NODE_CUSTOM_EVENTS.onTargetLeave, { node: void 0 });
18799
18828
  if (!nodeHandler) return resolve();
18800
18829
  toSelect.push(node.getAttrs().id ?? "");
18801
18830
  if (!moved) toUpdate.push(nodeHandler.serialize(node));
@@ -19347,11 +19376,11 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
19347
19376
  }
19348
19377
  if (nodesSelected === 1) {
19349
19378
  transformerAttrs = mergeExceptArrays(transformerAttrs, nodes[0].getTransformerProperties());
19350
- transformerAttrs.enabledAnchors = nodes[0].allowedAnchors();
19379
+ transformerAttrs.enabledAnchors = nodes[0]?.allowedAnchors() ?? [];
19351
19380
  }
19352
19381
  if (nodesSelected > 1) {
19353
19382
  const anchorsArrays = [];
19354
- for (const node of nodes) anchorsArrays.push(node.allowedAnchors());
19383
+ for (const node of nodes) anchorsArrays.push(node?.allowedAnchors() ?? []);
19355
19384
  transformerAttrs.enabledAnchors = intersectArrays(anchorsArrays);
19356
19385
  }
19357
19386
  if (this.tr && this.tr.nodes().length > 0) {
@@ -19923,6 +19952,9 @@ var WeaveNode = class {
19923
19952
  node.handleMouseout = function() {};
19924
19953
  node.handleSelectNode = function() {};
19925
19954
  node.handleDeselectNode = function() {};
19955
+ node.canMoveToContainer = function() {
19956
+ return true;
19957
+ };
19926
19958
  }
19927
19959
  isNodeSelected(ele) {
19928
19960
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
@@ -19941,7 +19973,7 @@ var WeaveNode = class {
19941
19973
  setHoverState(node) {
19942
19974
  const selectionPlugin = this.getSelectionPlugin();
19943
19975
  if (!selectionPlugin) return;
19944
- if (selectionPlugin.isAreaSelecting()) {
19976
+ if (selectionPlugin.getSelectedNodes().length === 1 && node === selectionPlugin.getSelectedNodes()[0] || selectionPlugin.isAreaSelecting()) {
19945
19977
  this.hideHoverState();
19946
19978
  return;
19947
19979
  }
@@ -20011,6 +20043,8 @@ var WeaveNode = class {
20011
20043
  const nodeTarget = e.target;
20012
20044
  originalPosition = nodeTarget.getAbsolutePosition();
20013
20045
  });
20046
+ let originalOpacity = void 0;
20047
+ const DRAG_OPACITY = .75;
20014
20048
  node.on("dragstart", (e) => {
20015
20049
  const nodeTarget = e.target;
20016
20050
  this.getNodesSelectionFeedbackPlugin()?.hideSelectionHalo(nodeTarget);
@@ -20031,6 +20065,8 @@ var WeaveNode = class {
20031
20065
  }
20032
20066
  const realNodeTarget = this.getRealSelectedNode(nodeTarget);
20033
20067
  if (realNodeTarget.getAttrs().isCloned) return;
20068
+ originalOpacity = realNodeTarget.opacity();
20069
+ realNodeTarget.opacity(DRAG_OPACITY);
20034
20070
  if (e.evt?.altKey) {
20035
20071
  nodeTarget.setAttrs({ isCloneOrigin: true });
20036
20072
  nodeTarget.setAttrs({ isCloned: false });
@@ -20074,7 +20110,7 @@ var WeaveNode = class {
20074
20110
  if (this.isSelecting() && this.getSelectionPlugin()?.getSelectedNodes().length === 1) {
20075
20111
  clearContainerTargets(this.instance);
20076
20112
  const layerToMove = containerOverCursor(this.instance, [realNodeTarget]);
20077
- if (layerToMove && !hasFrames(realNodeTarget) && realNodeTarget.isDragging()) layerToMove.fire(WEAVE_NODE_CUSTOM_EVENTS.onTargetEnter, { bubbles: true });
20113
+ if (layerToMove && !hasFrames(realNodeTarget) && realNodeTarget.isDragging() && !realNodeTarget.getAttrs().lockToContainer) layerToMove.fire(WEAVE_NODE_CUSTOM_EVENTS.onTargetEnter, { node: realNodeTarget });
20078
20114
  }
20079
20115
  };
20080
20116
  node.on("dragmove", (0, import_lodash.throttle)(handleDragMove, 100));
@@ -20097,7 +20133,9 @@ var WeaveNode = class {
20097
20133
  }
20098
20134
  this.instance.emitEvent("onDrag", null);
20099
20135
  const realNodeTarget = this.getRealSelectedNode(nodeTarget);
20100
- if (this.isSelecting() && this.getSelectionPlugin()?.getSelectedNodes().length === 1) {
20136
+ realNodeTarget.setAttrs({ opacity: originalOpacity });
20137
+ originalOpacity = void 0;
20138
+ if (this.isSelecting() && this.getSelectionPlugin()?.getSelectedNodes().length === 1 && (realNodeTarget.getAttrs().lockToContainer === void 0 || !realNodeTarget.getAttrs().lockToContainer)) {
20101
20139
  clearContainerTargets(this.instance);
20102
20140
  const nodesEdgeSnappingPlugin = this.getNodesEdgeSnappingPlugin();
20103
20141
  const nodesDistanceSnappingPlugin = this.getNodesDistanceSnappingPlugin();
@@ -20109,9 +20147,17 @@ var WeaveNode = class {
20109
20147
  let moved = false;
20110
20148
  if (containerToMove && !hasFrames(node)) moved = moveNodeToContainer(this.instance, realNodeTarget, containerToMove);
20111
20149
  if (realNodeTarget.getAttrs().isCloned) this.instance.getCloningManager().removeClone(realNodeTarget);
20112
- if (containerToMove) containerToMove.fire(WEAVE_NODE_CUSTOM_EVENTS.onTargetLeave, { bubbles: true });
20150
+ if (containerToMove) containerToMove.fire(WEAVE_NODE_CUSTOM_EVENTS.onTargetLeave, { node: realNodeTarget });
20113
20151
  if (!moved) this.instance.updateNode(this.serialize(realNodeTarget));
20114
20152
  }
20153
+ if (this.isSelecting() && this.getSelectionPlugin()?.getSelectedNodes().length === 1 && realNodeTarget.getAttrs().lockToContainer) {
20154
+ clearContainerTargets(this.instance);
20155
+ const nodesEdgeSnappingPlugin = this.getNodesEdgeSnappingPlugin();
20156
+ const nodesDistanceSnappingPlugin = this.getNodesDistanceSnappingPlugin();
20157
+ if (nodesEdgeSnappingPlugin) nodesEdgeSnappingPlugin.cleanupGuidelines();
20158
+ if (nodesDistanceSnappingPlugin) nodesDistanceSnappingPlugin.cleanupGuidelines();
20159
+ this.instance.updateNode(this.serialize(realNodeTarget));
20160
+ }
20115
20161
  nodeTarget.setAttrs({ isCloned: void 0 });
20116
20162
  nodeTarget.setAttrs({ isCloneOrigin: void 0 });
20117
20163
  realNodeTarget.setAttrs({ isCloned: void 0 });
@@ -20394,29 +20440,50 @@ var WeaveReconciler = class {
20394
20440
  const type = child.getAttrs().nodeType;
20395
20441
  const handler = this.instance.getNodeHandler(type);
20396
20442
  if (!handler) return;
20443
+ let nodeAdded = false;
20397
20444
  if (parentInstance instanceof Konva.Stage && child instanceof Konva.Layer) {
20398
20445
  parentInstance.add(child);
20399
20446
  handler.onAdd?.(child);
20447
+ nodeAdded = true;
20400
20448
  }
20401
20449
  if (parentInstance instanceof Konva.Layer) {
20402
20450
  parentInstance.add(child);
20403
20451
  handler.onAdd?.(child);
20452
+ nodeAdded = true;
20404
20453
  }
20405
20454
  if (parentInstance instanceof Konva.Group && typeof parentAttrs.containerId !== "undefined") {
20406
20455
  const realParent = parentInstance.findOne(`#${parentAttrs.containerId}`);
20407
20456
  realParent?.add(child);
20408
20457
  handler.onAdd?.(child);
20458
+ nodeAdded = true;
20409
20459
  }
20410
20460
  if (parentInstance instanceof Konva.Group && typeof parentAttrs.containerId === "undefined") {
20411
20461
  parentInstance.add(child);
20412
20462
  handler.onAdd?.(child);
20463
+ nodeAdded = true;
20413
20464
  }
20414
20465
  if (childInitialZIndex) child.zIndex(childInitialZIndex);
20466
+ if (nodeAdded) this.instance.emitEvent("onNodeRenderedAdded", child);
20467
+ }
20468
+ updateNode(instance, type, prevProps, nextProps) {
20469
+ if (!(0, import_lodash.isEqual)(prevProps, nextProps)) {
20470
+ const handler = this.instance.getNodeHandler(type);
20471
+ if (!handler) return;
20472
+ handler.onUpdate(instance, nextProps);
20473
+ const childZIndex = nextProps.zIndex;
20474
+ if (childZIndex) instance.zIndex(childZIndex);
20475
+ this.instance.emitEvent("onNodeRenderedUpdated", instance);
20476
+ }
20477
+ }
20478
+ removeNode(node) {
20479
+ this.instance.emitEvent("onNodeRenderedRemoved", node);
20415
20480
  }
20416
20481
  getConfig() {
20417
20482
  const weaveInstance = this.instance;
20418
20483
  const logger = this.logger;
20419
20484
  const addNode = this.addNode.bind(this);
20485
+ const updateNode = this.updateNode.bind(this);
20486
+ const removeNode = this.removeNode.bind(this);
20420
20487
  return {
20421
20488
  noTimeout: -1,
20422
20489
  isPrimaryRenderer: true,
@@ -20610,13 +20677,7 @@ var WeaveReconciler = class {
20610
20677
  nextProps
20611
20678
  }, "commitUpdate");
20612
20679
  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
- }
20680
+ updateNode(instance, type, prevProps, nextProps);
20620
20681
  },
20621
20682
  removeChildFromContainer() {
20622
20683
  logger.debug("removeChildFromContainer");
@@ -20627,6 +20688,7 @@ var WeaveReconciler = class {
20627
20688
  const handler = weaveInstance.getNodeHandler(type);
20628
20689
  if (!handler) return;
20629
20690
  handler.onDestroy(child);
20691
+ removeNode(child);
20630
20692
  }
20631
20693
  };
20632
20694
  }
@@ -20791,6 +20853,9 @@ var WeaveLayerNode = class extends WeaveNode {
20791
20853
  nodeType = WEAVE_LAYER_NODE_TYPE;
20792
20854
  onRender(props) {
20793
20855
  const layer = new Konva.Layer({ ...props });
20856
+ layer.canMoveToContainer = function() {
20857
+ return true;
20858
+ };
20794
20859
  return layer;
20795
20860
  }
20796
20861
  onUpdate(nodeInstance, nextProps) {
@@ -22874,6 +22939,9 @@ var WeaveFrameNode = class extends WeaveNode {
22874
22939
  fill: onTargetEnterFill
22875
22940
  });
22876
22941
  });
22942
+ frame.canMoveToContainer = function() {
22943
+ return true;
22944
+ };
22877
22945
  return frame;
22878
22946
  }
22879
22947
  onUpdate(nodeInstance, nextProps) {
@@ -27248,6 +27316,7 @@ const FRAME_TOOL_STATE = {
27248
27316
  //#region src/actions/frame-tool/frame-tool.ts
27249
27317
  var WeaveFrameToolAction = class extends WeaveAction {
27250
27318
  initialized = false;
27319
+ templateId = null;
27251
27320
  onPropsChange = void 0;
27252
27321
  onInit = void 0;
27253
27322
  constructor() {
@@ -27269,6 +27338,9 @@ var WeaveFrameToolAction = class extends WeaveAction {
27269
27338
  opacity: 1
27270
27339
  };
27271
27340
  }
27341
+ setTemplateToUse(templateId) {
27342
+ this.templateId = templateId;
27343
+ }
27272
27344
  setupEvents() {
27273
27345
  const stage = this.instance.getStage();
27274
27346
  window.addEventListener("keydown", (e) => {
@@ -27283,7 +27355,7 @@ var WeaveFrameToolAction = class extends WeaveAction {
27283
27355
  });
27284
27356
  stage.on("pointerclick", () => {
27285
27357
  if (this.state === FRAME_TOOL_STATE.IDLE) return;
27286
- if (this.state === FRAME_TOOL_STATE.ADDING) {
27358
+ if (this.state === FRAME_TOOL_STATE.ADDING && this.templateId === null) {
27287
27359
  this.handleAdding();
27288
27360
  return;
27289
27361
  }
@@ -27297,6 +27369,7 @@ var WeaveFrameToolAction = class extends WeaveAction {
27297
27369
  this.setCursor();
27298
27370
  this.setFocusStage();
27299
27371
  this.instance.emitEvent("onAddingFrame");
27372
+ this.templateId = null;
27300
27373
  this.frameId = null;
27301
27374
  this.clickPoint = null;
27302
27375
  this.setState(FRAME_TOOL_STATE.ADDING);
@@ -27346,6 +27419,7 @@ var WeaveFrameToolAction = class extends WeaveAction {
27346
27419
  this.frameId = null;
27347
27420
  this.container = void 0;
27348
27421
  this.clickPoint = null;
27422
+ this.templateId = null;
27349
27423
  this.setState(FRAME_TOOL_STATE.IDLE);
27350
27424
  }
27351
27425
  setCursor() {
@@ -31377,27 +31451,23 @@ var WeaveStateManager = class {
31377
31451
  }, msg);
31378
31452
  return;
31379
31453
  }
31380
- const doc = getYjsDoc(state);
31381
- const userId = this.instance.getStore().getUser().id;
31382
- doc.transact(() => {
31383
- if (!parent.props.children) parent.props.children = [];
31384
- if (index) {
31385
- parent.props.children.splice(index, 0, node);
31386
- for (let i = 0; i < parent.props.children.length; i++) parent.props.children[i].props.zIndex = i;
31387
- }
31388
- if (!index) {
31389
- const childrenAmount = parent.props.children.length;
31390
- const nodeToAdd = {
31391
- ...node,
31392
- props: {
31393
- ...node.props,
31394
- zIndex: childrenAmount
31395
- }
31396
- };
31397
- parent.props.children.push(nodeToAdd);
31398
- }
31399
- this.instance.emitEvent("onNodeAdded", node);
31400
- }, userId);
31454
+ if (!parent.props.children) parent.props.children = [];
31455
+ if (index) {
31456
+ parent.props.children.splice(index, 0, node);
31457
+ for (let i = 0; i < parent.props.children.length; i++) parent.props.children[i].props.zIndex = i;
31458
+ }
31459
+ if (!index) {
31460
+ const childrenAmount = parent.props.children.length;
31461
+ const nodeToAdd = {
31462
+ ...node,
31463
+ props: {
31464
+ ...node.props,
31465
+ zIndex: childrenAmount
31466
+ }
31467
+ };
31468
+ parent.props.children.push(nodeToAdd);
31469
+ }
31470
+ this.instance.emitEvent("onNodeAdded", node);
31401
31471
  }
31402
31472
  deepSyncSyncedStore(target, source) {
31403
31473
  for (const key in target) if (!(key in source)) delete target[key];
@@ -31434,12 +31504,19 @@ var WeaveStateManager = class {
31434
31504
  this.logger.warn({ node }, msg);
31435
31505
  return;
31436
31506
  }
31507
+ this.deepSyncSyncedStore(nodeState.props, node.props);
31508
+ this.instance.emitEvent("onNodeUpdated", node);
31509
+ }
31510
+ updateNodes(nodes) {
31511
+ for (const node of nodes) this.updateNode(node);
31512
+ }
31513
+ stateTransactional(callback) {
31514
+ const state = this.instance.getStore().getState();
31437
31515
  const doc = getYjsDoc(state);
31438
31516
  const userId = this.instance.getStore().getUser().id;
31439
31517
  doc.transact(() => {
31440
- this.deepSyncSyncedStore(nodeState.props, node.props);
31518
+ callback();
31441
31519
  }, userId);
31442
- this.instance.emitEvent("onNodeUpdated", node);
31443
31520
  }
31444
31521
  removeNode(node) {
31445
31522
  const state = this.instance.getStore().getState();
@@ -31459,21 +31536,14 @@ var WeaveStateManager = class {
31459
31536
  this.logger.warn({ node }, msg);
31460
31537
  return;
31461
31538
  }
31462
- const doc = getYjsDoc(state);
31463
- const userId = this.instance.getStore().getUser().id;
31464
- doc.transact(() => {
31465
- if (parent.props.children) {
31466
- for (let i = parent.props.children.length - 1; i >= 0; i--) if (parent.props.children[i].key === node.key) {
31467
- parent.props.children.splice(i, 1);
31468
- break;
31469
- }
31470
- for (let i = 0; i < parent.props.children.length; i++) parent.props.children[i].props.zIndex = i;
31471
- this.instance.emitEvent("onNodeRemoved", node);
31539
+ if (parent.props.children) {
31540
+ for (let i = parent.props.children.length - 1; i >= 0; i--) if (parent.props.children[i].key === node.key) {
31541
+ parent.props.children.splice(i, 1);
31542
+ break;
31472
31543
  }
31473
- }, userId);
31474
- }
31475
- removeNodes(nodes) {
31476
- for (const node of nodes) this.removeNode(node);
31544
+ for (let i = 0; i < parent.props.children.length; i++) parent.props.children[i].props.zIndex = i;
31545
+ this.instance.emitEvent("onNodeRemoved", node);
31546
+ }
31477
31547
  }
31478
31548
  moveNode(node, position) {
31479
31549
  const state = this.instance.getStore().getState();
@@ -31501,19 +31571,15 @@ var WeaveStateManager = class {
31501
31571
  this.logger.warn({ node }, msg);
31502
31572
  return;
31503
31573
  }
31504
- const doc = getYjsDoc(state);
31505
- const userId = this.instance.getStore().getUser().id;
31506
- doc.transact(() => {
31507
- if (parent.props.children) {
31508
- const item = JSON.parse(JSON.stringify(parent.props.children[nodeIndex]));
31509
- parent.props.children.splice(nodeIndex, 1);
31510
- if (item && position === WEAVE_NODE_POSITION.UP) parent.props.children.splice(nodeIndex + 1, 0, item);
31511
- if (item && position === WEAVE_NODE_POSITION.DOWN) parent.props.children.splice(nodeIndex - 1, 0, item);
31512
- if (item && position === WEAVE_NODE_POSITION.FRONT) parent.props.children.splice(childrenAmount - 1, 0, item);
31513
- if (item && position === WEAVE_NODE_POSITION.BACK) parent.props.children.splice(0, 0, item);
31514
- for (let i = 0; i < parent.props.children.length; i++) parent.props.children[i].props.zIndex = i;
31515
- }
31516
- }, userId);
31574
+ if (parent.props.children) {
31575
+ const item = JSON.parse(JSON.stringify(parent.props.children[nodeIndex]));
31576
+ parent.props.children.splice(nodeIndex, 1);
31577
+ if (item && position === WEAVE_NODE_POSITION.UP) parent.props.children.splice(nodeIndex + 1, 0, item);
31578
+ if (item && position === WEAVE_NODE_POSITION.DOWN) parent.props.children.splice(nodeIndex - 1, 0, item);
31579
+ if (item && position === WEAVE_NODE_POSITION.FRONT) parent.props.children.splice(childrenAmount - 1, 0, item);
31580
+ if (item && position === WEAVE_NODE_POSITION.BACK) parent.props.children.splice(0, 0, item);
31581
+ for (let i = 0; i < parent.props.children.length; i++) parent.props.children[i].props.zIndex = i;
31582
+ }
31517
31583
  }
31518
31584
  }
31519
31585
  getElementsTree() {
@@ -31599,7 +31665,7 @@ var WeaveRegisterManager = class {
31599
31665
 
31600
31666
  //#endregion
31601
31667
  //#region package.json
31602
- var version = "2.1.1";
31668
+ var version = "2.3.0";
31603
31669
 
31604
31670
  //#endregion
31605
31671
  //#region src/managers/setup.ts
@@ -32381,25 +32447,59 @@ var Weave = class {
32381
32447
  return this.stateManager.getNode(nodeKey);
32382
32448
  }
32383
32449
  addNode(node, parentId = "mainLayer", index = void 0) {
32450
+ this.stateTransactional(() => {
32451
+ this.stateManager.addNode(node, parentId, index);
32452
+ });
32453
+ }
32454
+ addNodeNT(node, parentId = "mainLayer", index = void 0) {
32384
32455
  this.stateManager.addNode(node, parentId, index);
32385
32456
  }
32386
32457
  updateNode(node) {
32458
+ this.stateTransactional(() => {
32459
+ this.stateManager.updateNode(node);
32460
+ });
32461
+ }
32462
+ updateNodeNT(node) {
32387
32463
  this.stateManager.updateNode(node);
32388
32464
  }
32389
32465
  updateNodes(nodes) {
32390
- for (const node of nodes) this.updateNode(node);
32466
+ this.stateTransactional(() => {
32467
+ this.stateManager.updateNodes(nodes);
32468
+ });
32469
+ }
32470
+ updateNodesNT(nodes) {
32471
+ this.stateManager.updateNodes(nodes);
32391
32472
  }
32392
32473
  removeNode(node) {
32474
+ this.stateTransactional(() => {
32475
+ this.stateManager.removeNode(node);
32476
+ const selectionPlugin = this.getPlugin("nodesSelection");
32477
+ if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
32478
+ });
32479
+ }
32480
+ removeNodeNT(node) {
32393
32481
  this.stateManager.removeNode(node);
32394
32482
  const selectionPlugin = this.getPlugin("nodesSelection");
32395
32483
  if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
32396
32484
  }
32397
32485
  removeNodes(nodes) {
32398
- for (const node of nodes) this.removeNode(node);
32486
+ this.stateTransactional(() => {
32487
+ for (const node of nodes) this.removeNodeNT(node);
32488
+ const selectionPlugin = this.getPlugin("nodesSelection");
32489
+ if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
32490
+ });
32491
+ }
32492
+ removeNodesNT(nodes) {
32493
+ for (const node of nodes) this.removeNodeNT(node);
32399
32494
  const selectionPlugin = this.getPlugin("nodesSelection");
32400
32495
  if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
32401
32496
  }
32402
32497
  moveNode(node, position) {
32498
+ this.stateTransactional(() => {
32499
+ this.stateManager.moveNode(node, position);
32500
+ });
32501
+ }
32502
+ moveNodeNT(node, position) {
32403
32503
  this.stateManager.moveNode(node, position);
32404
32504
  }
32405
32505
  getElementsTree() {
@@ -32429,6 +32529,9 @@ var Weave = class {
32429
32529
  getBoundingBox(nodes, config) {
32430
32530
  return getBoundingBox(nodes, config);
32431
32531
  }
32532
+ stateTransactional(callback) {
32533
+ this.stateManager.stateTransactional(callback);
32534
+ }
32432
32535
  moveUp(node) {
32433
32536
  this.zIndexManager.moveUp(node);
32434
32537
  }
@@ -32613,5 +32716,5 @@ window._weave_isServerSide = false;
32613
32716
  window._weave_serverSideBackend = void 0;
32614
32717
 
32615
32718
  //#endregion
32616
- export { ALIGN_NODES_ALIGN_TO, ALIGN_NODES_TOOL_ACTION_NAME, ALIGN_NODES_TOOL_STATE, ARROW_TOOL_ACTION_NAME, ARROW_TOOL_STATE, BRUSH_TOOL_ACTION_NAME, BRUSH_TOOL_DEFAULT_CONFIG, BRUSH_TOOL_STATE, COPY_PASTE_NODES_PLUGIN_STATE, ELLIPSE_TOOL_ACTION_NAME, ELLIPSE_TOOL_STATE, ERASER_TOOL_ACTION_NAME, ERASER_TOOL_STATE, FRAME_TOOL_ACTION_NAME, FRAME_TOOL_STATE, GUIDE_DISTANCE_LINE_DEFAULT_CONFIG, GUIDE_ENTER_SNAPPING_TOLERANCE, GUIDE_EXIT_SNAPPING_TOLERANCE, GUIDE_HORIZONTAL_LINE_NAME, GUIDE_LINE_DEFAULT_CONFIG, GUIDE_LINE_DRAG_SNAPPING_THRESHOLD, GUIDE_LINE_NAME, GUIDE_LINE_TRANSFORM_SNAPPING_THRESHOLD, GUIDE_ORIENTATION, GUIDE_VERTICAL_LINE_NAME, IMAGE_TOOL_ACTION_NAME, IMAGE_TOOL_STATE, MOVE_TOOL_ACTION_NAME, MOVE_TOOL_STATE, NODE_SNAP, NODE_SNAP_HORIZONTAL, NODE_SNAP_VERTICAL, PEN_TOOL_ACTION_NAME, PEN_TOOL_STATE, RECTANGLE_TOOL_ACTION_NAME, RECTANGLE_TOOL_STATE, REGULAR_POLYGON_TOOL_ACTION_NAME, REGULAR_POLYGON_TOOL_STATE, SELECTION_TOOL_ACTION_NAME, SELECTION_TOOL_STATE, STAGE_MINIMAP_DEFAULT_CONFIG, STAR_TOOL_ACTION_NAME, STAR_TOOL_STATE, TEXT_LAYOUT, TEXT_TOOL_ACTION_NAME, TEXT_TOOL_STATE, VIDEO_TOOL_ACTION_NAME, VIDEO_TOOL_STATE, WEAVE_ARROW_NODE_TYPE, WEAVE_COMMENTS_RENDERER_KEY, WEAVE_COMMENTS_TOOL_LAYER_ID, WEAVE_COMMENT_CREATE_ACTION, WEAVE_COMMENT_NODE_ACTION, WEAVE_COMMENT_NODE_DEFAULTS, WEAVE_COMMENT_NODE_TYPE, WEAVE_COMMENT_STATUS, WEAVE_COMMENT_TOOL_ACTION_NAME, WEAVE_COMMENT_TOOL_DEFAULT_CONFIG, WEAVE_COMMENT_TOOL_STATE, WEAVE_COMMENT_VIEW_ACTION, WEAVE_COPY_PASTE_CONFIG_DEFAULT, WEAVE_COPY_PASTE_NODES_KEY, WEAVE_COPY_PASTE_PASTE_CATCHER_ID, WEAVE_COPY_PASTE_PASTE_MODES, WEAVE_DEFAULT_USER_INFO_FUNCTION, WEAVE_ELLIPSE_NODE_TYPE, WEAVE_FRAME_DEFAULT_BACKGROUND_COLOR, WEAVE_FRAME_NODE_DEFAULT_CONFIG, WEAVE_FRAME_NODE_DEFAULT_PROPS, WEAVE_FRAME_NODE_TYPE, WEAVE_GRID_DEFAULT_COLOR, WEAVE_GRID_DEFAULT_DOT_MAX_DOTS_PER_AXIS, WEAVE_GRID_DEFAULT_MAJOR_DOT_RATIO, WEAVE_GRID_DEFAULT_MAJOR_EVERY, WEAVE_GRID_DEFAULT_MAJOR_LINE_RATIO, WEAVE_GRID_DEFAULT_ORIGIN_COLOR, WEAVE_GRID_DEFAULT_RADIUS, WEAVE_GRID_DEFAULT_SIZE, WEAVE_GRID_DEFAULT_STROKE, WEAVE_GRID_DEFAULT_TYPE, WEAVE_GRID_LAYER_ID, WEAVE_GRID_TYPES, WEAVE_GROUP_NODE_TYPE, WEAVE_IMAGE_CROP_END_TYPE, WEAVE_IMAGE_DEFAULT_CONFIG, WEAVE_IMAGE_NODE_TYPE, WEAVE_LAYER_NODE_TYPE, WEAVE_LINE_NODE_TYPE, WEAVE_NODES_DISTANCE_SNAPPING_PLUGIN_KEY, WEAVE_NODES_EDGE_SNAPPING_PLUGIN_KEY, WEAVE_NODES_MULTI_SELECTION_FEEDBACK_PLUGIN_DEFAULT_CONFIG, WEAVE_NODES_MULTI_SELECTION_FEEDBACK_PLUGIN_KEY, WEAVE_NODES_MULTI_SELECTION_FEEDBACK_PLUGIN_LAYER_ID, WEAVE_NODES_SELECTION_DEFAULT_CONFIG, WEAVE_NODES_SELECTION_KEY, WEAVE_NODES_SELECTION_LAYER_ID, WEAVE_RECTANGLE_NODE_TYPE, WEAVE_REGULAR_POLYGON_NODE_TYPE, WEAVE_STAGE_DEFAULT_MODE, WEAVE_STAGE_GRID_PLUGIN_KEY, WEAVE_STAGE_KEYBOARD_MOVE_DEFAULT_CONFIG, WEAVE_STAGE_KEYBOARD_MOVE_KEY, WEAVE_STAGE_MINIMAP_KEY, WEAVE_STAGE_NODE_TYPE, WEAVE_STAGE_PANNING_DEFAULT_CONFIG, WEAVE_STAGE_PANNING_KEY, WEAVE_STAR_NODE_TYPE, WEAVE_STROKE_NODE_DEFAULT_CONFIG, WEAVE_STROKE_NODE_TYPE, WEAVE_TEXT_NODE_TYPE, WEAVE_USERS_POINTERS_CONFIG_DEFAULT_PROPS, WEAVE_USERS_POINTERS_KEY, WEAVE_USERS_SELECTION_KEY, WEAVE_USER_POINTER_KEY, WEAVE_USER_SELECTION_KEY, WEAVE_VIDEO_DEFAULT_CONFIG, WEAVE_VIDEO_NODE_TYPE, Weave, WeaveAction, WeaveAlignNodesToolAction, WeaveArrowNode, WeaveArrowToolAction, WeaveBrushToolAction, WeaveCommentNode, WeaveCommentToolAction, WeaveCommentsRendererPlugin, WeaveConnectedUsersPlugin, WeaveContextMenuPlugin, WeaveCopyPasteNodesPlugin, WeaveEllipseNode, WeaveEllipseToolAction, WeaveEraserToolAction, WeaveExportNodesToolAction, WeaveExportStageToolAction, WeaveFitToScreenToolAction, WeaveFitToSelectionToolAction, WeaveFrameNode, WeaveFrameToolAction, WeaveGroupNode, WeaveImageNode, WeaveImageToolAction, WeaveLayerNode, WeaveLineNode, WeaveMoveToolAction, WeaveNode, WeaveNodesDistanceSnappingPlugin, WeaveNodesEdgeSnappingPlugin, WeaveNodesMultiSelectionFeedbackPlugin, WeaveNodesSelectionPlugin, WeavePenToolAction, WeavePlugin, WeaveRectangleNode, WeaveRectangleToolAction, WeaveRegularPolygonNode, WeaveRegularPolygonToolAction, WeaveSelectionToolAction, WeaveStageDropAreaPlugin, WeaveStageGridPlugin, WeaveStageKeyboardMovePlugin, WeaveStageMinimapPlugin, WeaveStageNode, WeaveStagePanningPlugin, WeaveStageResizePlugin, WeaveStageZoomPlugin, WeaveStarNode, WeaveStarToolAction, WeaveStore, WeaveStrokeNode, WeaveTextNode, WeaveTextToolAction, WeaveUsersPointersPlugin, WeaveUsersSelectionPlugin, WeaveVideoNode, WeaveVideoToolAction, WeaveZoomInToolAction, WeaveZoomOutToolAction, canComposite, clearContainerTargets, containerOverCursor, containsNodeDeep, defaultInitialState, getBoundingBox, getExportBoundingBox, getPositionRelativeToContainerOnPosition, getSelectedNodesMetadata, getTargetAndSkipNodes, getTargetedNode, getTopmostShadowHost, getVisibleNodes, getVisibleNodesInViewport, hasFrames, hasImages, intersectArrays, isIOS, isInShadowDOM, isNodeInSelection, isServer, memoize, mergeExceptArrays, moveNodeToContainer, resetScale };
32719
+ export { ALIGN_NODES_ALIGN_TO, ALIGN_NODES_TOOL_ACTION_NAME, ALIGN_NODES_TOOL_STATE, ARROW_TOOL_ACTION_NAME, ARROW_TOOL_STATE, BRUSH_TOOL_ACTION_NAME, BRUSH_TOOL_DEFAULT_CONFIG, BRUSH_TOOL_STATE, COPY_PASTE_NODES_PLUGIN_STATE, ELLIPSE_TOOL_ACTION_NAME, ELLIPSE_TOOL_STATE, ERASER_TOOL_ACTION_NAME, ERASER_TOOL_STATE, FRAME_TOOL_ACTION_NAME, FRAME_TOOL_STATE, GUIDE_DISTANCE_LINE_DEFAULT_CONFIG, GUIDE_ENTER_SNAPPING_TOLERANCE, GUIDE_EXIT_SNAPPING_TOLERANCE, GUIDE_HORIZONTAL_LINE_NAME, GUIDE_LINE_DEFAULT_CONFIG, GUIDE_LINE_DRAG_SNAPPING_THRESHOLD, GUIDE_LINE_NAME, GUIDE_LINE_TRANSFORM_SNAPPING_THRESHOLD, GUIDE_ORIENTATION, GUIDE_VERTICAL_LINE_NAME, IMAGE_TOOL_ACTION_NAME, IMAGE_TOOL_STATE, MOVE_TOOL_ACTION_NAME, MOVE_TOOL_STATE, NODE_SNAP, NODE_SNAP_HORIZONTAL, NODE_SNAP_VERTICAL, PEN_TOOL_ACTION_NAME, PEN_TOOL_STATE, RECTANGLE_TOOL_ACTION_NAME, RECTANGLE_TOOL_STATE, REGULAR_POLYGON_TOOL_ACTION_NAME, REGULAR_POLYGON_TOOL_STATE, SELECTION_TOOL_ACTION_NAME, SELECTION_TOOL_STATE, STAGE_MINIMAP_DEFAULT_CONFIG, STAR_TOOL_ACTION_NAME, STAR_TOOL_STATE, TEXT_LAYOUT, TEXT_TOOL_ACTION_NAME, TEXT_TOOL_STATE, VIDEO_TOOL_ACTION_NAME, VIDEO_TOOL_STATE, WEAVE_ARROW_NODE_TYPE, WEAVE_COMMENTS_RENDERER_KEY, WEAVE_COMMENTS_TOOL_LAYER_ID, WEAVE_COMMENT_CREATE_ACTION, WEAVE_COMMENT_NODE_ACTION, WEAVE_COMMENT_NODE_DEFAULTS, WEAVE_COMMENT_NODE_TYPE, WEAVE_COMMENT_STATUS, WEAVE_COMMENT_TOOL_ACTION_NAME, WEAVE_COMMENT_TOOL_DEFAULT_CONFIG, WEAVE_COMMENT_TOOL_STATE, WEAVE_COMMENT_VIEW_ACTION, WEAVE_COPY_PASTE_CONFIG_DEFAULT, WEAVE_COPY_PASTE_NODES_KEY, WEAVE_COPY_PASTE_PASTE_CATCHER_ID, WEAVE_COPY_PASTE_PASTE_MODES, WEAVE_DEFAULT_USER_INFO_FUNCTION, WEAVE_ELLIPSE_NODE_TYPE, WEAVE_FRAME_DEFAULT_BACKGROUND_COLOR, WEAVE_FRAME_NODE_DEFAULT_CONFIG, WEAVE_FRAME_NODE_DEFAULT_PROPS, WEAVE_FRAME_NODE_TYPE, WEAVE_GRID_DEFAULT_COLOR, WEAVE_GRID_DEFAULT_DOT_MAX_DOTS_PER_AXIS, WEAVE_GRID_DEFAULT_MAJOR_DOT_RATIO, WEAVE_GRID_DEFAULT_MAJOR_EVERY, WEAVE_GRID_DEFAULT_MAJOR_LINE_RATIO, WEAVE_GRID_DEFAULT_ORIGIN_COLOR, WEAVE_GRID_DEFAULT_RADIUS, WEAVE_GRID_DEFAULT_SIZE, WEAVE_GRID_DEFAULT_STROKE, WEAVE_GRID_DEFAULT_TYPE, WEAVE_GRID_LAYER_ID, WEAVE_GRID_TYPES, WEAVE_GROUP_NODE_TYPE, WEAVE_IMAGE_CROP_END_TYPE, WEAVE_IMAGE_DEFAULT_CONFIG, WEAVE_IMAGE_NODE_TYPE, WEAVE_LAYER_NODE_TYPE, WEAVE_LINE_NODE_TYPE, WEAVE_NODES_DISTANCE_SNAPPING_PLUGIN_KEY, WEAVE_NODES_EDGE_SNAPPING_PLUGIN_KEY, WEAVE_NODES_MULTI_SELECTION_FEEDBACK_PLUGIN_DEFAULT_CONFIG, WEAVE_NODES_MULTI_SELECTION_FEEDBACK_PLUGIN_KEY, WEAVE_NODES_MULTI_SELECTION_FEEDBACK_PLUGIN_LAYER_ID, WEAVE_NODES_SELECTION_DEFAULT_CONFIG, WEAVE_NODES_SELECTION_KEY, WEAVE_NODES_SELECTION_LAYER_ID, WEAVE_RECTANGLE_NODE_TYPE, WEAVE_REGULAR_POLYGON_NODE_TYPE, WEAVE_STAGE_DEFAULT_MODE, WEAVE_STAGE_GRID_PLUGIN_KEY, WEAVE_STAGE_KEYBOARD_MOVE_DEFAULT_CONFIG, WEAVE_STAGE_KEYBOARD_MOVE_KEY, WEAVE_STAGE_MINIMAP_KEY, WEAVE_STAGE_NODE_TYPE, WEAVE_STAGE_PANNING_DEFAULT_CONFIG, WEAVE_STAGE_PANNING_KEY, WEAVE_STAR_NODE_TYPE, WEAVE_STROKE_NODE_DEFAULT_CONFIG, WEAVE_STROKE_NODE_TYPE, WEAVE_TEXT_NODE_TYPE, WEAVE_USERS_POINTERS_CONFIG_DEFAULT_PROPS, WEAVE_USERS_POINTERS_KEY, WEAVE_USERS_SELECTION_KEY, WEAVE_USER_POINTER_KEY, WEAVE_USER_SELECTION_KEY, WEAVE_VIDEO_DEFAULT_CONFIG, WEAVE_VIDEO_NODE_TYPE, Weave, WeaveAction, WeaveAlignNodesToolAction, WeaveArrowNode, WeaveArrowToolAction, WeaveBrushToolAction, WeaveCommentNode, WeaveCommentToolAction, WeaveCommentsRendererPlugin, WeaveConnectedUsersPlugin, WeaveContextMenuPlugin, WeaveCopyPasteNodesPlugin, WeaveEllipseNode, WeaveEllipseToolAction, WeaveEraserToolAction, WeaveExportNodesToolAction, WeaveExportStageToolAction, WeaveFitToScreenToolAction, WeaveFitToSelectionToolAction, WeaveFrameNode, WeaveFrameToolAction, WeaveGroupNode, WeaveImageNode, WeaveImageToolAction, WeaveLayerNode, WeaveLineNode, WeaveMoveToolAction, WeaveNode, WeaveNodesDistanceSnappingPlugin, WeaveNodesEdgeSnappingPlugin, WeaveNodesMultiSelectionFeedbackPlugin, WeaveNodesSelectionPlugin, WeavePenToolAction, WeavePlugin, WeaveRectangleNode, WeaveRectangleToolAction, WeaveRegularPolygonNode, WeaveRegularPolygonToolAction, WeaveSelectionToolAction, WeaveStageDropAreaPlugin, WeaveStageGridPlugin, WeaveStageKeyboardMovePlugin, WeaveStageMinimapPlugin, WeaveStageNode, WeaveStagePanningPlugin, WeaveStageResizePlugin, WeaveStageZoomPlugin, WeaveStarNode, WeaveStarToolAction, WeaveStore, WeaveStrokeNode, WeaveTextNode, WeaveTextToolAction, WeaveUsersPointersPlugin, WeaveUsersSelectionPlugin, WeaveVideoNode, WeaveVideoToolAction, WeaveZoomInToolAction, WeaveZoomOutToolAction, canComposite, clearContainerTargets, containerOverCursor, containsNodeDeep, defaultInitialState, getBoundingBox, getExportBoundingBox, getPositionRelativeToContainerOnPosition, getSelectedNodesMetadata, getStageClickPoint, getTargetAndSkipNodes, getTargetedNode, getTopmostShadowHost, getVisibleNodes, getVisibleNodesInViewport, hasFrames, hasImages, intersectArrays, isIOS, isInShadowDOM, isNodeInSelection, isServer, memoize, mergeExceptArrays, moveNodeToContainer, resetScale };
32617
32720
  //# sourceMappingURL=sdk.js.map