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.
@@ -1242,6 +1242,18 @@ function computeCurvedCacheBounds(element) {
1242
1242
  height: declaredHeight + maxSagitta * 2
1243
1243
  };
1244
1244
  }
1245
+
1246
+ // Sync a newly measured/computed height onto the element while keeping its
1247
+ // vertical center fixed — grows/shrinks equally above and below the original
1248
+ // position, instead of anchoring the top edge and only ever expanding downward.
1249
+ function syncHeightKeepingCenter(element, newHeight) {
1250
+ if (Math.abs(newHeight - element.height) <= 1) return;
1251
+ var deltaY = (newHeight - element.height) / 2;
1252
+ element.set({
1253
+ height: newHeight,
1254
+ y: element.y - deltaY
1255
+ });
1256
+ }
1245
1257
  var TextElementComponent = mobxReactLite.observer(function (_ref) {
1246
1258
  var _element$backgroundOp;
1247
1259
  var element = _ref.element;
@@ -1252,6 +1264,7 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
1252
1264
  groupChild = _ref.groupChild;
1253
1265
  var groupRef = React.useRef(null);
1254
1266
  var textRef = React.useRef(null);
1267
+ var textareaRef = React.useRef(null);
1255
1268
  var _useState = React.useState(element.height || 50),
1256
1269
  _useState2 = _slicedToArray(_useState, 2),
1257
1270
  textHeight = _useState2[0],
@@ -1280,9 +1293,7 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
1280
1293
  var h = node.height();
1281
1294
  if (h > 0) {
1282
1295
  setTextHeight(h);
1283
- if (Math.abs(h - element.height) > 1) element.set({
1284
- height: h
1285
- });
1296
+ syncHeightKeepingCenter(element, h);
1286
1297
  }
1287
1298
  // Re-cache if blur is active
1288
1299
  if (element.blurEnabled && node) {
@@ -1307,9 +1318,7 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
1307
1318
  var h = node.height();
1308
1319
  if (h > 0) {
1309
1320
  setTextHeight(h);
1310
- if (Math.abs(h - element.height) > 1) element.set({
1311
- height: h
1312
- });
1321
+ syncHeightKeepingCenter(element, h);
1313
1322
  }
1314
1323
  });
1315
1324
  return function () {
@@ -1325,11 +1334,24 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
1325
1334
  var lineHeightMultiplier = typeof element.lineHeight === 'number' ? element.lineHeight : parseFloat(element.lineHeight) || 1.2;
1326
1335
  var h = lineCount * element.fontSize * lineHeightMultiplier;
1327
1336
  setTextHeight(h);
1328
- if (Math.abs(h - element.height) > 1) element.set({
1329
- height: h
1330
- });
1337
+ syncHeightKeepingCenter(element, h);
1331
1338
  }, [element.text, element.placeholder, element.fontSize, element.lineHeight, element.curveEnabled, element.curvePower]);
1332
1339
 
1340
+ // While the live-typing textarea overlay is open, keep it aligned with the
1341
+ // Konva text node as syncHeightKeepingCenter adjusts element.y/height during
1342
+ // auto-grow — otherwise the invisible textarea (and its caret) stays at its
1343
+ // original position while the visible Konva text re-centers around it.
1344
+ React.useEffect(function () {
1345
+ if (!element._editModeEnabled) return;
1346
+ var node = textRef.current;
1347
+ var textarea = textareaRef.current;
1348
+ if (!node || !textarea) return;
1349
+ var pos = node.absolutePosition();
1350
+ var scaleY = node.getAbsoluteScale().y;
1351
+ textarea.style.top = "".concat(pos.y, "px");
1352
+ textarea.style.height = "".concat(element.height * scaleY, "px");
1353
+ }, [element._editModeEnabled, element.y, element.height]);
1354
+
1333
1355
  // Apply blur filter: cache the text node when blur is enabled
1334
1356
  React.useEffect(function () {
1335
1357
  var _node$getLayer3;
@@ -1449,6 +1471,7 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
1449
1471
  textarea.style.minHeight = '0';
1450
1472
  textarea.style.minWidth = '0';
1451
1473
  stageContainer.appendChild(textarea);
1474
+ textareaRef.current = textarea;
1452
1475
  textarea.focus();
1453
1476
  var caretPos = textarea.value.length;
1454
1477
  textarea.setSelectionRange(caretPos, caretPos);
@@ -1466,6 +1489,7 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
1466
1489
  text: cancel ? originalText : textarea.value
1467
1490
  });
1468
1491
  element.toggleEditMode(false);
1492
+ if (textareaRef.current === textarea) textareaRef.current = null;
1469
1493
  if (textarea.parentNode) {
1470
1494
  textarea.parentNode.removeChild(textarea);
1471
1495
  }