@inditextech/weave-sdk 5.1.1 → 5.1.3

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/types.js CHANGED
@@ -4913,6 +4913,12 @@ function handleClickOrTap(ctx, e) {
4913
4913
  tr.nodes([nodeTargeted]);
4914
4914
  tr.show();
4915
4915
  areNodesSelected = true;
4916
+ const canMove = typeof nodeTargeted.canDrag === "function" ? nodeTargeted.canDrag() : false;
4917
+ if (canMove && e.evt) {
4918
+ nodeTargeted.draggable(true);
4919
+ ctx.armDrag(nodeTargeted, e.evt.pointerId);
4920
+ return;
4921
+ }
4916
4922
  }
4917
4923
  if (metaPressed && isSelected) {
4918
4924
  const nodes = tr.nodes().slice();
@@ -5010,6 +5016,7 @@ function handlePointerDown(ctx, e) {
5010
5016
  if (e.target.getClassName().includes("custom-snap-guide")) return;
5011
5017
  ctx.setClickOrTapHandled(false);
5012
5018
  ctx.registerPointer(e.evt.pointerId, e.evt);
5019
+ ctx.clearArmedDrag();
5013
5020
  if (e.evt.pointerType === "touch" && ctx.getPointerCount() > 1) return;
5014
5021
  if (e.evt.pointerType === "mouse" && e.evt?.button !== 0) return;
5015
5022
  if (e.evt.pointerType === "pen" && e.evt?.pressure <= .05) return;
@@ -5022,6 +5029,25 @@ function handlePointerDown(ctx, e) {
5022
5029
  ctx.setAreaSelecting(false);
5023
5030
  ctx.getEdgePanning().stop();
5024
5031
  ctx.getAreaSelector().hide();
5032
+ const weave = ctx.getWeaveInstance();
5033
+ const realNode = weave.getRealSelectedNode(selectedGroup);
5034
+ const tr = ctx.getTransformerController().getTransformer();
5035
+ const selectedIds = new Set(tr.nodes().map((node) => node.getAttrs().id));
5036
+ let isWithinSelection = false;
5037
+ for (let cur = realNode; cur; cur = cur.getParent()) {
5038
+ if (typeof cur.getAttrs !== "function") break;
5039
+ if (selectedIds.has(cur.getAttrs().id)) {
5040
+ isWithinSelection = true;
5041
+ break;
5042
+ }
5043
+ }
5044
+ if (!isWithinSelection && realNode.getAttrs().nodeType) {
5045
+ Konva.DD._dragElements.forEach((elem, key) => {
5046
+ if (elem.dragStatus === "ready") Konva.DD._dragElements.delete(key);
5047
+ });
5048
+ tr.setAttrs({ listening: false });
5049
+ handleClickOrTap(ctx, e);
5050
+ }
5025
5051
  return;
5026
5052
  }
5027
5053
  const isStage = e.target instanceof Konva.Stage;
@@ -5103,6 +5129,7 @@ function handlePointerUp(ctx, e) {
5103
5129
  ctx.getGesture().checkDoubleTap(e.evt.clientX, e.evt.clientY);
5104
5130
  ctx.unregisterPointer(e.evt.pointerId);
5105
5131
  ctx.getGesture().commitTap();
5132
+ ctx.clearArmedDrag();
5106
5133
  if (stage.mode() !== WEAVE_STAGE_DEFAULT_MODE) return;
5107
5134
  const contextMenuPlugin = ctx.getContextMenuPlugin();
5108
5135
  if (!ctx.isInitialized()) {
@@ -5193,6 +5220,35 @@ function handlePointerUp(ctx, e) {
5193
5220
  ctx.triggerSelectedNodesEvent();
5194
5221
  }
5195
5222
 
5223
+ //#endregion
5224
+ //#region src/plugins/nodes-selection/events/armed-drag.ts
5225
+ /**
5226
+ * Handles the stage `pointermove` for single-gesture select+drag. When a node
5227
+ * has been "armed" by a fresh single-selection click (see click-tap.ts), this
5228
+ * starts the drag on the same gesture as soon as the pointer moves past the
5229
+ * move threshold, so the user does not need a second press to begin moving.
5230
+ *
5231
+ * A plain click (no movement) never reaches the threshold, so it only selects.
5232
+ * Uses the public Konva `startDrag` API — the node's own `dragstart` handler
5233
+ * and the transformer's drag proxy take over from there.
5234
+ *
5235
+ * Wired un-throttled (separate from the throttled selection pointermove) to
5236
+ * keep drag initiation responsive.
5237
+ */
5238
+ function handleArmedDrag(ctx, e) {
5239
+ const node = ctx.getArmedDragNode();
5240
+ if (!node || !e?.evt) return;
5241
+ if (e.evt.buttons === 0) {
5242
+ ctx.clearArmedDrag();
5243
+ return;
5244
+ }
5245
+ if (e.evt.pointerId !== ctx.getArmedDragPointerId()) return;
5246
+ if (!ctx.getGesture().checkMoved(e.evt.clientX, e.evt.clientY)) return;
5247
+ if (node.isDragging()) return;
5248
+ ctx.clearArmedDrag();
5249
+ node.startDrag({ evt: e.evt });
5250
+ }
5251
+
5196
5252
  //#endregion
5197
5253
  //#region src/plugins/nodes-selection/nodes-selection.ts
5198
5254
  var WeaveNodesSelectionPlugin = class extends WeavePlugin {
@@ -5200,6 +5256,8 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
5200
5256
  _handledClickOrTap = false;
5201
5257
  dragSelectedNodes = [];
5202
5258
  _activeGroupContext = null;
5259
+ _armedDragNode = null;
5260
+ _armedDragPointerId = null;
5203
5261
  onRender = void 0;
5204
5262
  constructor(params) {
5205
5263
  super();
@@ -5227,6 +5285,8 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
5227
5285
  this.dragSelectedNodes = [];
5228
5286
  this._handledClickOrTap = false;
5229
5287
  this._activeGroupContext = null;
5288
+ this._armedDragNode = null;
5289
+ this._armedDragPointerId = null;
5230
5290
  }
5231
5291
  getName() {
5232
5292
  return WEAVE_NODES_SELECTION_KEY;
@@ -5285,6 +5345,20 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
5285
5345
  setAreaSelecting(val) {
5286
5346
  this.selecting = val;
5287
5347
  }
5348
+ armDrag(node, pointerId) {
5349
+ this._armedDragNode = node;
5350
+ this._armedDragPointerId = pointerId;
5351
+ }
5352
+ getArmedDragNode() {
5353
+ return this._armedDragNode;
5354
+ }
5355
+ getArmedDragPointerId() {
5356
+ return this._armedDragPointerId;
5357
+ }
5358
+ clearArmedDrag() {
5359
+ this._armedDragNode = null;
5360
+ this._armedDragPointerId = null;
5361
+ }
5288
5362
  initLayer() {
5289
5363
  const stage = this.instance.getStage();
5290
5364
  const layer = new Konva.Layer({ id: this.getLayerName() });
@@ -5427,6 +5501,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
5427
5501
  registerKeyboardHandlers(this);
5428
5502
  stage.on("pointerdown", (e) => handlePointerDown(this, e));
5429
5503
  stage.on("pointermove", (0, import_throttle.default)((e) => handlePointerMove(this, e), DEFAULT_THROTTLE_MS));
5504
+ stage.on("pointermove", (e) => handleArmedDrag(this, e));
5430
5505
  stage.on("pointerup", (e) => handlePointerUp(this, e));
5431
5506
  this.instance.addEventListener("onStateChange", () => {
5432
5507
  requestAnimationFrame(() => {
@@ -5507,6 +5582,8 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
5507
5582
  }
5508
5583
  setSelectedNodes(nodes) {
5509
5584
  const tr = this.transformerCtrl.getTransformer();
5585
+ const previousNodes = tr.getNodes();
5586
+ for (const previousNode of previousNodes) if (!nodes.includes(previousNode) && typeof previousNode.draggable === "function") previousNode.draggable(false);
5510
5587
  tr.setNodes(nodes);
5511
5588
  this.handleBehaviors();
5512
5589
  if (nodes.length === 0) this.getNodesSelectionFeedbackPlugin()?.cleanupSelectedHalos();
@@ -6461,7 +6538,7 @@ var WeaveNode = class {
6461
6538
  if (e.evt?.button === 1) isWheelMousePressed = true;
6462
6539
  this.getNodesSelectionFeedbackPlugin()?.hideSelectionHalo(nodeTarget);
6463
6540
  const canMove = typeof nodeTarget?.canDrag === "function" ? nodeTarget.canDrag() : false;
6464
- if (!canMove) {
6541
+ if (!canMove || !this.isSelecting()) {
6465
6542
  nodeTarget.stopDrag();
6466
6543
  return;
6467
6544
  }
@@ -9701,7 +9778,7 @@ var WeaveRegisterManager = class {
9701
9778
 
9702
9779
  //#endregion
9703
9780
  //#region package.json
9704
- var version = "5.1.1";
9781
+ var version = "5.1.3";
9705
9782
 
9706
9783
  //#endregion
9707
9784
  //#region src/managers/setup.ts
@@ -13756,6 +13833,8 @@ var WeaveTextNode = class extends WeaveNode {
13756
13833
  this.textAreaContainer = null;
13757
13834
  this.textArea = null;
13758
13835
  this.editing = false;
13836
+ this.editingNodeId = null;
13837
+ this.nodeRenderedAddedRegistered = false;
13759
13838
  this.textArea = null;
13760
13839
  }
13761
13840
  updateNode(nodeInstance) {
@@ -13771,9 +13850,9 @@ var WeaveTextNode = class extends WeaveNode {
13771
13850
  this.instance.addNode(serializedNode, actualContainer?.getAttrs().id);
13772
13851
  } else if (this.createNode && actNode.getAttrs().text === "") actNode.destroy();
13773
13852
  else this.instance.updateNode(this.serialize(clonedText));
13774
- this.createNode = false;
13775
13853
  clonedText.destroy();
13776
13854
  }
13855
+ this.createNode = false;
13777
13856
  }
13778
13857
  handleKeyPress = (e) => {
13779
13858
  if (e.code === "Enter" && this.instance.getActiveAction() === SELECTION_TOOL_ACTION_NAME && !this.editing && e.target !== this.textArea) {
@@ -13943,9 +14022,12 @@ var WeaveTextNode = class extends WeaveNode {
13943
14022
  text.on("transformend", () => {
13944
14023
  handleTransformEnd();
13945
14024
  });
13946
- this.instance.addEventListener("onNodeRenderedAdded", (node) => {
13947
- if (node.id() === text.id() && node.getParent() !== text.getParent() && this.editing) text.getAttr("cancelEditMode")?.();
13948
- });
14025
+ if (!this.nodeRenderedAddedRegistered) {
14026
+ this.instance.addEventListener("onNodeRenderedAdded", (node) => {
14027
+ if (this.editing && this.editingNodeId !== null && node.id() === this.editingNodeId && node.getAttr("cancelEditMode")) node.getAttr("cancelEditMode")?.();
14028
+ });
14029
+ this.nodeRenderedAddedRegistered = true;
14030
+ }
13949
14031
  if (!this.instance.isServerSide() && !this.keyPressHandler) {
13950
14032
  this.keyPressHandler = this.handleKeyPress.bind(this);
13951
14033
  window.addEventListener("keypress", this.keyPressHandler, { signal: this.instance.getEventsController().signal });
@@ -13981,7 +14063,7 @@ var WeaveTextNode = class extends WeaveNode {
13981
14063
  width,
13982
14064
  height
13983
14065
  });
13984
- if (this.editing) this.updateTextAreaDOM(nodeInstance);
14066
+ if (this.editing && this.editingNodeId === nodeInstance.id()) this.updateTextAreaDOM(nodeInstance);
13985
14067
  if (!this.editing) {
13986
14068
  const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
13987
14069
  if (nodesSelectionPlugin) {
@@ -14325,27 +14407,29 @@ var WeaveTextNode = class extends WeaveNode {
14325
14407
  this.instance.disablePlugin("nodesSelection");
14326
14408
  tr.hide();
14327
14409
  }
14328
- if (this.editing) textNode.visible(false);
14410
+ if (this.editing && this.editingNodeId === textNode.id()) textNode.visible(false);
14329
14411
  else textNode.visible(true);
14330
14412
  }
14331
14413
  removeTextAreaDOM(textNode) {
14332
14414
  this.instance.releaseMutexLock();
14333
14415
  this.instance.getStage().mode(WEAVE_STAGE_DEFAULT_MODE);
14334
14416
  this.editing = false;
14417
+ this.editingNodeId = null;
14335
14418
  const stage = this.instance.getStage();
14336
14419
  if (this.textAreaSuperContainer) this.textAreaSuperContainer.remove();
14337
14420
  textNode.visible(true);
14338
14421
  this.updateNode(textNode);
14422
+ const liveNode = stage.findOne(`#${textNode.id()}`) ?? textNode;
14339
14423
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
14340
14424
  if (selectionPlugin) {
14341
14425
  this.instance.enablePlugin("nodesSelection");
14342
- selectionPlugin.setSelectedNodes([textNode]);
14426
+ selectionPlugin.setSelectedNodes([liveNode]);
14343
14427
  this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
14344
14428
  }
14345
14429
  stage.container().tabIndex = 1;
14346
14430
  stage.container().click();
14347
14431
  stage.container().focus();
14348
- this.instance.emitEvent("onExitTextNodeEditMode", { node: textNode });
14432
+ this.instance.emitEvent("onExitTextNodeEditMode", { node: liveNode });
14349
14433
  }
14350
14434
  triggerEditMode(textNode, create = false) {
14351
14435
  if (create) this.createNode = true;
@@ -14355,6 +14439,7 @@ var WeaveTextNode = class extends WeaveNode {
14355
14439
  });
14356
14440
  if (!lockAcquired) return;
14357
14441
  this.editing = true;
14442
+ this.editingNodeId = textNode.id();
14358
14443
  textNode.visible(false);
14359
14444
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
14360
14445
  if (selectionPlugin) {
@@ -24844,14 +24929,18 @@ var WeaveTextToolAction = class extends WeaveAction {
24844
24929
  cleanup() {
24845
24930
  const stage = this.instance.getStage();
24846
24931
  stage.container().style.cursor = "default";
24847
- const selectionPlugin = this.instance.getPlugin("nodesSelection");
24848
- if (selectionPlugin) {
24849
- const node = stage.findOne(`#${this.textId}`);
24850
- if (node) selectionPlugin.setSelectedNodes([node]);
24851
- this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
24932
+ const placedId = this.textId;
24933
+ const justAdded = this.state === TEXT_TOOL_STATE.FINISHED && !!placedId;
24934
+ if (justAdded) {
24935
+ const selectionPlugin = this.instance.getPlugin("nodesSelection");
24936
+ if (selectionPlugin) {
24937
+ const node = stage.findOne(`#${placedId}`);
24938
+ if (node) selectionPlugin.setSelectedNodes([node]);
24939
+ this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
24940
+ }
24941
+ const textGroup = stage.findOne(`#${placedId}`);
24942
+ if (textGroup) textGroup.getAttr("triggerEditMode")?.(textGroup, true);
24852
24943
  }
24853
- const textGroup = stage.findOne(`#${this.textId}`);
24854
- if (textGroup) textGroup.getAttr("triggerEditMode")(textGroup, true);
24855
24944
  this.initialCursor = null;
24856
24945
  this.textId = null;
24857
24946
  this.container = void 0;