@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.node.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
  }
@@ -21527,27 +21589,23 @@ var WeaveStateManager = class {
21527
21589
  }, msg);
21528
21590
  return;
21529
21591
  }
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);
21592
+ if (!parent.props.children) parent.props.children = [];
21593
+ if (index) {
21594
+ parent.props.children.splice(index, 0, node);
21595
+ for (let i = 0; i < parent.props.children.length; i++) parent.props.children[i].props.zIndex = i;
21596
+ }
21597
+ if (!index) {
21598
+ const childrenAmount = parent.props.children.length;
21599
+ const nodeToAdd = {
21600
+ ...node,
21601
+ props: {
21602
+ ...node.props,
21603
+ zIndex: childrenAmount
21604
+ }
21605
+ };
21606
+ parent.props.children.push(nodeToAdd);
21607
+ }
21608
+ this.instance.emitEvent("onNodeAdded", node);
21551
21609
  }
21552
21610
  deepSyncSyncedStore(target, source) {
21553
21611
  for (const key in target) if (!(key in source)) delete target[key];
@@ -21584,12 +21642,19 @@ var WeaveStateManager = class {
21584
21642
  this.logger.warn({ node }, msg);
21585
21643
  return;
21586
21644
  }
21645
+ this.deepSyncSyncedStore(nodeState.props, node.props);
21646
+ this.instance.emitEvent("onNodeUpdated", node);
21647
+ }
21648
+ updateNodes(nodes) {
21649
+ for (const node of nodes) this.updateNode(node);
21650
+ }
21651
+ stateTransactional(callback) {
21652
+ const state = this.instance.getStore().getState();
21587
21653
  const doc = getYjsDoc(state);
21588
21654
  const userId = this.instance.getStore().getUser().id;
21589
21655
  doc.transact(() => {
21590
- this.deepSyncSyncedStore(nodeState.props, node.props);
21656
+ callback();
21591
21657
  }, userId);
21592
- this.instance.emitEvent("onNodeUpdated", node);
21593
21658
  }
21594
21659
  removeNode(node) {
21595
21660
  const state = this.instance.getStore().getState();
@@ -21609,21 +21674,14 @@ var WeaveStateManager = class {
21609
21674
  this.logger.warn({ node }, msg);
21610
21675
  return;
21611
21676
  }
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);
21677
+ if (parent.props.children) {
21678
+ for (let i = parent.props.children.length - 1; i >= 0; i--) if (parent.props.children[i].key === node.key) {
21679
+ parent.props.children.splice(i, 1);
21680
+ break;
21622
21681
  }
21623
- }, userId);
21624
- }
21625
- removeNodes(nodes) {
21626
- for (const node of nodes) this.removeNode(node);
21682
+ for (let i = 0; i < parent.props.children.length; i++) parent.props.children[i].props.zIndex = i;
21683
+ this.instance.emitEvent("onNodeRemoved", node);
21684
+ }
21627
21685
  }
21628
21686
  moveNode(node, position) {
21629
21687
  const state = this.instance.getStore().getState();
@@ -21651,19 +21709,15 @@ var WeaveStateManager = class {
21651
21709
  this.logger.warn({ node }, msg);
21652
21710
  return;
21653
21711
  }
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);
21712
+ if (parent.props.children) {
21713
+ const item = JSON.parse(JSON.stringify(parent.props.children[nodeIndex]));
21714
+ parent.props.children.splice(nodeIndex, 1);
21715
+ if (item && position === WEAVE_NODE_POSITION.UP) parent.props.children.splice(nodeIndex + 1, 0, item);
21716
+ if (item && position === WEAVE_NODE_POSITION.DOWN) parent.props.children.splice(nodeIndex - 1, 0, item);
21717
+ if (item && position === WEAVE_NODE_POSITION.FRONT) parent.props.children.splice(childrenAmount - 1, 0, item);
21718
+ if (item && position === WEAVE_NODE_POSITION.BACK) parent.props.children.splice(0, 0, item);
21719
+ for (let i = 0; i < parent.props.children.length; i++) parent.props.children[i].props.zIndex = i;
21720
+ }
21667
21721
  }
21668
21722
  }
21669
21723
  getElementsTree() {
@@ -21749,7 +21803,7 @@ var WeaveRegisterManager = class {
21749
21803
 
21750
21804
  //#endregion
21751
21805
  //#region package.json
21752
- var version = "2.1.1";
21806
+ var version = "2.3.0";
21753
21807
 
21754
21808
  //#endregion
21755
21809
  //#region src/managers/setup.ts
@@ -22536,25 +22590,59 @@ var Weave = class {
22536
22590
  return this.stateManager.getNode(nodeKey);
22537
22591
  }
22538
22592
  addNode(node, parentId = "mainLayer", index = void 0) {
22593
+ this.stateTransactional(() => {
22594
+ this.stateManager.addNode(node, parentId, index);
22595
+ });
22596
+ }
22597
+ addNodeNT(node, parentId = "mainLayer", index = void 0) {
22539
22598
  this.stateManager.addNode(node, parentId, index);
22540
22599
  }
22541
22600
  updateNode(node) {
22601
+ this.stateTransactional(() => {
22602
+ this.stateManager.updateNode(node);
22603
+ });
22604
+ }
22605
+ updateNodeNT(node) {
22542
22606
  this.stateManager.updateNode(node);
22543
22607
  }
22544
22608
  updateNodes(nodes) {
22545
- for (const node of nodes) this.updateNode(node);
22609
+ this.stateTransactional(() => {
22610
+ this.stateManager.updateNodes(nodes);
22611
+ });
22612
+ }
22613
+ updateNodesNT(nodes) {
22614
+ this.stateManager.updateNodes(nodes);
22546
22615
  }
22547
22616
  removeNode(node) {
22617
+ this.stateTransactional(() => {
22618
+ this.stateManager.removeNode(node);
22619
+ const selectionPlugin = this.getPlugin("nodesSelection");
22620
+ if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
22621
+ });
22622
+ }
22623
+ removeNodeNT(node) {
22548
22624
  this.stateManager.removeNode(node);
22549
22625
  const selectionPlugin = this.getPlugin("nodesSelection");
22550
22626
  if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
22551
22627
  }
22552
22628
  removeNodes(nodes) {
22553
- for (const node of nodes) this.removeNode(node);
22629
+ this.stateTransactional(() => {
22630
+ for (const node of nodes) this.removeNodeNT(node);
22631
+ const selectionPlugin = this.getPlugin("nodesSelection");
22632
+ if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
22633
+ });
22634
+ }
22635
+ removeNodesNT(nodes) {
22636
+ for (const node of nodes) this.removeNodeNT(node);
22554
22637
  const selectionPlugin = this.getPlugin("nodesSelection");
22555
22638
  if (selectionPlugin) selectionPlugin.setSelectedNodes([]);
22556
22639
  }
22557
22640
  moveNode(node, position) {
22641
+ this.stateTransactional(() => {
22642
+ this.stateManager.moveNode(node, position);
22643
+ });
22644
+ }
22645
+ moveNodeNT(node, position) {
22558
22646
  this.stateManager.moveNode(node, position);
22559
22647
  }
22560
22648
  getElementsTree() {
@@ -22584,6 +22672,9 @@ var Weave = class {
22584
22672
  getBoundingBox(nodes, config) {
22585
22673
  return getBoundingBox(nodes, config);
22586
22674
  }
22675
+ stateTransactional(callback) {
22676
+ this.stateManager.stateTransactional(callback);
22677
+ }
22587
22678
  moveUp(node) {
22588
22679
  this.zIndexManager.moveUp(node);
22589
22680
  }
@@ -22863,6 +22954,9 @@ var WeaveLayerNode = class extends WeaveNode {
22863
22954
  nodeType = WEAVE_LAYER_NODE_TYPE;
22864
22955
  onRender(props) {
22865
22956
  const layer = new Konva.Layer({ ...props });
22957
+ layer.canMoveToContainer = function() {
22958
+ return true;
22959
+ };
22866
22960
  return layer;
22867
22961
  }
22868
22962
  onUpdate(nodeInstance, nextProps) {
@@ -24946,6 +25040,9 @@ var WeaveFrameNode = class extends WeaveNode {
24946
25040
  fill: onTargetEnterFill
24947
25041
  });
24948
25042
  });
25043
+ frame.canMoveToContainer = function() {
25044
+ return true;
25045
+ };
24949
25046
  return frame;
24950
25047
  }
24951
25048
  onUpdate(nodeInstance, nextProps) {
@@ -29320,6 +29417,7 @@ const FRAME_TOOL_STATE = {
29320
29417
  //#region src/actions/frame-tool/frame-tool.ts
29321
29418
  var WeaveFrameToolAction = class extends WeaveAction {
29322
29419
  initialized = false;
29420
+ templateId = null;
29323
29421
  onPropsChange = void 0;
29324
29422
  onInit = void 0;
29325
29423
  constructor() {
@@ -29341,6 +29439,9 @@ var WeaveFrameToolAction = class extends WeaveAction {
29341
29439
  opacity: 1
29342
29440
  };
29343
29441
  }
29442
+ setTemplateToUse(templateId) {
29443
+ this.templateId = templateId;
29444
+ }
29344
29445
  setupEvents() {
29345
29446
  const stage = this.instance.getStage();
29346
29447
  window.addEventListener("keydown", (e) => {
@@ -29355,7 +29456,7 @@ var WeaveFrameToolAction = class extends WeaveAction {
29355
29456
  });
29356
29457
  stage.on("pointerclick", () => {
29357
29458
  if (this.state === FRAME_TOOL_STATE.IDLE) return;
29358
- if (this.state === FRAME_TOOL_STATE.ADDING) {
29459
+ if (this.state === FRAME_TOOL_STATE.ADDING && this.templateId === null) {
29359
29460
  this.handleAdding();
29360
29461
  return;
29361
29462
  }
@@ -29369,6 +29470,7 @@ var WeaveFrameToolAction = class extends WeaveAction {
29369
29470
  this.setCursor();
29370
29471
  this.setFocusStage();
29371
29472
  this.instance.emitEvent("onAddingFrame");
29473
+ this.templateId = null;
29372
29474
  this.frameId = null;
29373
29475
  this.clickPoint = null;
29374
29476
  this.setState(FRAME_TOOL_STATE.ADDING);
@@ -29418,6 +29520,7 @@ var WeaveFrameToolAction = class extends WeaveAction {
29418
29520
  this.frameId = null;
29419
29521
  this.container = void 0;
29420
29522
  this.clickPoint = null;
29523
+ this.templateId = null;
29421
29524
  this.setState(FRAME_TOOL_STATE.IDLE);
29422
29525
  }
29423
29526
  setCursor() {
@@ -32619,5 +32722,5 @@ if (typeof window === "undefined") {
32619
32722
  }
32620
32723
 
32621
32724
  //#endregion
32622
- 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, setupCanvasBackend, setupSkiaBackend };
32725
+ 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, setupCanvasBackend, setupSkiaBackend };
32623
32726
  //# sourceMappingURL=sdk.node.js.map