labellife-design-tool 2.4.5 → 2.4.6

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/cjs/index.js CHANGED
@@ -11324,6 +11324,18 @@ function computeCurvedCacheBounds(element) {
11324
11324
  height: declaredHeight + maxSagitta * 2
11325
11325
  };
11326
11326
  }
11327
+
11328
+ // Sync a newly measured/computed height onto the element while keeping its
11329
+ // vertical center fixed — grows/shrinks equally above and below the original
11330
+ // position, instead of anchoring the top edge and only ever expanding downward.
11331
+ function syncHeightKeepingCenter(element, newHeight) {
11332
+ if (Math.abs(newHeight - element.height) <= 1) return;
11333
+ var deltaY = (newHeight - element.height) / 2;
11334
+ element.set({
11335
+ height: newHeight,
11336
+ y: element.y - deltaY
11337
+ });
11338
+ }
11327
11339
  var TextElementComponent = mobxReactLite.observer(function (_ref) {
11328
11340
  var _element$backgroundOp;
11329
11341
  var element = _ref.element;
@@ -11334,6 +11346,7 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
11334
11346
  groupChild = _ref.groupChild;
11335
11347
  var groupRef = React.useRef(null);
11336
11348
  var textRef = React.useRef(null);
11349
+ var textareaRef = React.useRef(null);
11337
11350
  var _useState = React.useState(element.height || 50),
11338
11351
  _useState2 = _slicedToArray(_useState, 2),
11339
11352
  textHeight = _useState2[0],
@@ -11362,9 +11375,7 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
11362
11375
  var h = node.height();
11363
11376
  if (h > 0) {
11364
11377
  setTextHeight(h);
11365
- if (Math.abs(h - element.height) > 1) element.set({
11366
- height: h
11367
- });
11378
+ syncHeightKeepingCenter(element, h);
11368
11379
  }
11369
11380
  // Re-cache if blur is active
11370
11381
  if (element.blurEnabled && node) {
@@ -11389,9 +11400,7 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
11389
11400
  var h = node.height();
11390
11401
  if (h > 0) {
11391
11402
  setTextHeight(h);
11392
- if (Math.abs(h - element.height) > 1) element.set({
11393
- height: h
11394
- });
11403
+ syncHeightKeepingCenter(element, h);
11395
11404
  }
11396
11405
  });
11397
11406
  return function () {
@@ -11407,11 +11416,24 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
11407
11416
  var lineHeightMultiplier = typeof element.lineHeight === 'number' ? element.lineHeight : parseFloat(element.lineHeight) || 1.2;
11408
11417
  var h = lineCount * element.fontSize * lineHeightMultiplier;
11409
11418
  setTextHeight(h);
11410
- if (Math.abs(h - element.height) > 1) element.set({
11411
- height: h
11412
- });
11419
+ syncHeightKeepingCenter(element, h);
11413
11420
  }, [element.text, element.placeholder, element.fontSize, element.lineHeight, element.curveEnabled, element.curvePower]);
11414
11421
 
11422
+ // While the live-typing textarea overlay is open, keep it aligned with the
11423
+ // Konva text node as syncHeightKeepingCenter adjusts element.y/height during
11424
+ // auto-grow — otherwise the invisible textarea (and its caret) stays at its
11425
+ // original position while the visible Konva text re-centers around it.
11426
+ React.useEffect(function () {
11427
+ if (!element._editModeEnabled) return;
11428
+ var node = textRef.current;
11429
+ var textarea = textareaRef.current;
11430
+ if (!node || !textarea) return;
11431
+ var pos = node.absolutePosition();
11432
+ var scaleY = node.getAbsoluteScale().y;
11433
+ textarea.style.top = "".concat(pos.y, "px");
11434
+ textarea.style.height = "".concat(element.height * scaleY, "px");
11435
+ }, [element._editModeEnabled, element.y, element.height]);
11436
+
11415
11437
  // Apply blur filter: cache the text node when blur is enabled
11416
11438
  React.useEffect(function () {
11417
11439
  var _node$getLayer3;
@@ -11531,6 +11553,7 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
11531
11553
  textarea.style.minHeight = '0';
11532
11554
  textarea.style.minWidth = '0';
11533
11555
  stageContainer.appendChild(textarea);
11556
+ textareaRef.current = textarea;
11534
11557
  textarea.focus();
11535
11558
  var caretPos = textarea.value.length;
11536
11559
  textarea.setSelectionRange(caretPos, caretPos);
@@ -11548,6 +11571,7 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
11548
11571
  text: cancel ? originalText : textarea.value
11549
11572
  });
11550
11573
  element.toggleEditMode(false);
11574
+ if (textareaRef.current === textarea) textareaRef.current = null;
11551
11575
  if (textarea.parentNode) {
11552
11576
  textarea.parentNode.removeChild(textarea);
11553
11577
  }