@inditextech/weave-sdk 5.1.1 → 5.1.2

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,11 @@ 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
+ }
4916
4921
  }
4917
4922
  if (metaPressed && isSelected) {
4918
4923
  const nodes = tr.nodes().slice();
@@ -5010,6 +5015,7 @@ function handlePointerDown(ctx, e) {
5010
5015
  if (e.target.getClassName().includes("custom-snap-guide")) return;
5011
5016
  ctx.setClickOrTapHandled(false);
5012
5017
  ctx.registerPointer(e.evt.pointerId, e.evt);
5018
+ ctx.clearArmedDrag();
5013
5019
  if (e.evt.pointerType === "touch" && ctx.getPointerCount() > 1) return;
5014
5020
  if (e.evt.pointerType === "mouse" && e.evt?.button !== 0) return;
5015
5021
  if (e.evt.pointerType === "pen" && e.evt?.pressure <= .05) return;
@@ -5103,6 +5109,7 @@ function handlePointerUp(ctx, e) {
5103
5109
  ctx.getGesture().checkDoubleTap(e.evt.clientX, e.evt.clientY);
5104
5110
  ctx.unregisterPointer(e.evt.pointerId);
5105
5111
  ctx.getGesture().commitTap();
5112
+ ctx.clearArmedDrag();
5106
5113
  if (stage.mode() !== WEAVE_STAGE_DEFAULT_MODE) return;
5107
5114
  const contextMenuPlugin = ctx.getContextMenuPlugin();
5108
5115
  if (!ctx.isInitialized()) {
@@ -5193,6 +5200,35 @@ function handlePointerUp(ctx, e) {
5193
5200
  ctx.triggerSelectedNodesEvent();
5194
5201
  }
5195
5202
 
5203
+ //#endregion
5204
+ //#region src/plugins/nodes-selection/events/armed-drag.ts
5205
+ /**
5206
+ * Handles the stage `pointermove` for single-gesture select+drag. When a node
5207
+ * has been "armed" by a fresh single-selection click (see click-tap.ts), this
5208
+ * starts the drag on the same gesture as soon as the pointer moves past the
5209
+ * move threshold, so the user does not need a second press to begin moving.
5210
+ *
5211
+ * A plain click (no movement) never reaches the threshold, so it only selects.
5212
+ * Uses the public Konva `startDrag` API — the node's own `dragstart` handler
5213
+ * and the transformer's drag proxy take over from there.
5214
+ *
5215
+ * Wired un-throttled (separate from the throttled selection pointermove) to
5216
+ * keep drag initiation responsive.
5217
+ */
5218
+ function handleArmedDrag(ctx, e) {
5219
+ const node = ctx.getArmedDragNode();
5220
+ if (!node || !e?.evt) return;
5221
+ if (e.evt.buttons === 0) {
5222
+ ctx.clearArmedDrag();
5223
+ return;
5224
+ }
5225
+ if (e.evt.pointerId !== ctx.getArmedDragPointerId()) return;
5226
+ if (!ctx.getGesture().checkMoved(e.evt.clientX, e.evt.clientY)) return;
5227
+ if (node.isDragging()) return;
5228
+ ctx.clearArmedDrag();
5229
+ node.startDrag(e.evt);
5230
+ }
5231
+
5196
5232
  //#endregion
5197
5233
  //#region src/plugins/nodes-selection/nodes-selection.ts
5198
5234
  var WeaveNodesSelectionPlugin = class extends WeavePlugin {
@@ -5200,6 +5236,8 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
5200
5236
  _handledClickOrTap = false;
5201
5237
  dragSelectedNodes = [];
5202
5238
  _activeGroupContext = null;
5239
+ _armedDragNode = null;
5240
+ _armedDragPointerId = null;
5203
5241
  onRender = void 0;
5204
5242
  constructor(params) {
5205
5243
  super();
@@ -5227,6 +5265,8 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
5227
5265
  this.dragSelectedNodes = [];
5228
5266
  this._handledClickOrTap = false;
5229
5267
  this._activeGroupContext = null;
5268
+ this._armedDragNode = null;
5269
+ this._armedDragPointerId = null;
5230
5270
  }
5231
5271
  getName() {
5232
5272
  return WEAVE_NODES_SELECTION_KEY;
@@ -5285,6 +5325,20 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
5285
5325
  setAreaSelecting(val) {
5286
5326
  this.selecting = val;
5287
5327
  }
5328
+ armDrag(node, pointerId) {
5329
+ this._armedDragNode = node;
5330
+ this._armedDragPointerId = pointerId;
5331
+ }
5332
+ getArmedDragNode() {
5333
+ return this._armedDragNode;
5334
+ }
5335
+ getArmedDragPointerId() {
5336
+ return this._armedDragPointerId;
5337
+ }
5338
+ clearArmedDrag() {
5339
+ this._armedDragNode = null;
5340
+ this._armedDragPointerId = null;
5341
+ }
5288
5342
  initLayer() {
5289
5343
  const stage = this.instance.getStage();
5290
5344
  const layer = new Konva.Layer({ id: this.getLayerName() });
@@ -5427,6 +5481,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
5427
5481
  registerKeyboardHandlers(this);
5428
5482
  stage.on("pointerdown", (e) => handlePointerDown(this, e));
5429
5483
  stage.on("pointermove", (0, import_throttle.default)((e) => handlePointerMove(this, e), DEFAULT_THROTTLE_MS));
5484
+ stage.on("pointermove", (e) => handleArmedDrag(this, e));
5430
5485
  stage.on("pointerup", (e) => handlePointerUp(this, e));
5431
5486
  this.instance.addEventListener("onStateChange", () => {
5432
5487
  requestAnimationFrame(() => {
@@ -9701,7 +9756,7 @@ var WeaveRegisterManager = class {
9701
9756
 
9702
9757
  //#endregion
9703
9758
  //#region package.json
9704
- var version = "5.1.1";
9759
+ var version = "5.1.2";
9705
9760
 
9706
9761
  //#endregion
9707
9762
  //#region src/managers/setup.ts
@@ -13756,6 +13811,8 @@ var WeaveTextNode = class extends WeaveNode {
13756
13811
  this.textAreaContainer = null;
13757
13812
  this.textArea = null;
13758
13813
  this.editing = false;
13814
+ this.editingNodeId = null;
13815
+ this.nodeRenderedAddedRegistered = false;
13759
13816
  this.textArea = null;
13760
13817
  }
13761
13818
  updateNode(nodeInstance) {
@@ -13771,9 +13828,9 @@ var WeaveTextNode = class extends WeaveNode {
13771
13828
  this.instance.addNode(serializedNode, actualContainer?.getAttrs().id);
13772
13829
  } else if (this.createNode && actNode.getAttrs().text === "") actNode.destroy();
13773
13830
  else this.instance.updateNode(this.serialize(clonedText));
13774
- this.createNode = false;
13775
13831
  clonedText.destroy();
13776
13832
  }
13833
+ this.createNode = false;
13777
13834
  }
13778
13835
  handleKeyPress = (e) => {
13779
13836
  if (e.code === "Enter" && this.instance.getActiveAction() === SELECTION_TOOL_ACTION_NAME && !this.editing && e.target !== this.textArea) {
@@ -13943,9 +14000,12 @@ var WeaveTextNode = class extends WeaveNode {
13943
14000
  text.on("transformend", () => {
13944
14001
  handleTransformEnd();
13945
14002
  });
13946
- this.instance.addEventListener("onNodeRenderedAdded", (node) => {
13947
- if (node.id() === text.id() && node.getParent() !== text.getParent() && this.editing) text.getAttr("cancelEditMode")?.();
13948
- });
14003
+ if (!this.nodeRenderedAddedRegistered) {
14004
+ this.instance.addEventListener("onNodeRenderedAdded", (node) => {
14005
+ if (this.editing && this.editingNodeId !== null && node.id() === this.editingNodeId && node.getAttr("cancelEditMode")) node.getAttr("cancelEditMode")?.();
14006
+ });
14007
+ this.nodeRenderedAddedRegistered = true;
14008
+ }
13949
14009
  if (!this.instance.isServerSide() && !this.keyPressHandler) {
13950
14010
  this.keyPressHandler = this.handleKeyPress.bind(this);
13951
14011
  window.addEventListener("keypress", this.keyPressHandler, { signal: this.instance.getEventsController().signal });
@@ -13981,7 +14041,7 @@ var WeaveTextNode = class extends WeaveNode {
13981
14041
  width,
13982
14042
  height
13983
14043
  });
13984
- if (this.editing) this.updateTextAreaDOM(nodeInstance);
14044
+ if (this.editing && this.editingNodeId === nodeInstance.id()) this.updateTextAreaDOM(nodeInstance);
13985
14045
  if (!this.editing) {
13986
14046
  const nodesSelectionPlugin = this.instance.getPlugin("nodesSelection");
13987
14047
  if (nodesSelectionPlugin) {
@@ -14325,27 +14385,29 @@ var WeaveTextNode = class extends WeaveNode {
14325
14385
  this.instance.disablePlugin("nodesSelection");
14326
14386
  tr.hide();
14327
14387
  }
14328
- if (this.editing) textNode.visible(false);
14388
+ if (this.editing && this.editingNodeId === textNode.id()) textNode.visible(false);
14329
14389
  else textNode.visible(true);
14330
14390
  }
14331
14391
  removeTextAreaDOM(textNode) {
14332
14392
  this.instance.releaseMutexLock();
14333
14393
  this.instance.getStage().mode(WEAVE_STAGE_DEFAULT_MODE);
14334
14394
  this.editing = false;
14395
+ this.editingNodeId = null;
14335
14396
  const stage = this.instance.getStage();
14336
14397
  if (this.textAreaSuperContainer) this.textAreaSuperContainer.remove();
14337
14398
  textNode.visible(true);
14338
14399
  this.updateNode(textNode);
14400
+ const liveNode = stage.findOne(`#${textNode.id()}`) ?? textNode;
14339
14401
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
14340
14402
  if (selectionPlugin) {
14341
14403
  this.instance.enablePlugin("nodesSelection");
14342
- selectionPlugin.setSelectedNodes([textNode]);
14404
+ selectionPlugin.setSelectedNodes([liveNode]);
14343
14405
  this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
14344
14406
  }
14345
14407
  stage.container().tabIndex = 1;
14346
14408
  stage.container().click();
14347
14409
  stage.container().focus();
14348
- this.instance.emitEvent("onExitTextNodeEditMode", { node: textNode });
14410
+ this.instance.emitEvent("onExitTextNodeEditMode", { node: liveNode });
14349
14411
  }
14350
14412
  triggerEditMode(textNode, create = false) {
14351
14413
  if (create) this.createNode = true;
@@ -14355,6 +14417,7 @@ var WeaveTextNode = class extends WeaveNode {
14355
14417
  });
14356
14418
  if (!lockAcquired) return;
14357
14419
  this.editing = true;
14420
+ this.editingNodeId = textNode.id();
14358
14421
  textNode.visible(false);
14359
14422
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
14360
14423
  if (selectionPlugin) {
@@ -24844,14 +24907,18 @@ var WeaveTextToolAction = class extends WeaveAction {
24844
24907
  cleanup() {
24845
24908
  const stage = this.instance.getStage();
24846
24909
  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);
24910
+ const placedId = this.textId;
24911
+ const justAdded = this.state === TEXT_TOOL_STATE.FINISHED && !!placedId;
24912
+ if (justAdded) {
24913
+ const selectionPlugin = this.instance.getPlugin("nodesSelection");
24914
+ if (selectionPlugin) {
24915
+ const node = stage.findOne(`#${placedId}`);
24916
+ if (node) selectionPlugin.setSelectedNodes([node]);
24917
+ this.instance.triggerAction(SELECTION_TOOL_ACTION_NAME);
24918
+ }
24919
+ const textGroup = stage.findOne(`#${placedId}`);
24920
+ if (textGroup) textGroup.getAttr("triggerEditMode")?.(textGroup, true);
24852
24921
  }
24853
- const textGroup = stage.findOne(`#${this.textId}`);
24854
- if (textGroup) textGroup.getAttr("triggerEditMode")(textGroup, true);
24855
24922
  this.initialCursor = null;
24856
24923
  this.textId = null;
24857
24924
  this.container = void 0;