labellife-design-tool 2.4.2 → 2.4.4

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.
@@ -1365,13 +1365,8 @@ var TextElementComponent = observer(function (_ref) {
1365
1365
  element.toggleEditMode(true);
1366
1366
  var textNode = textRef.current;
1367
1367
  if (!textNode) return;
1368
- var grp = groupRef.current;
1369
1368
  var stage = textNode.getStage();
1370
1369
  if (!stage) return;
1371
-
1372
- // Hide the group so the textarea appears as in-place editing
1373
- if (grp) grp.hide();
1374
- stage.batchDraw();
1375
1370
  var stageContainer = stage.container();
1376
1371
  var textPosition = textNode.absolutePosition();
1377
1372
  var absScale = textNode.getAbsoluteScale();
@@ -1380,9 +1375,17 @@ var TextElementComponent = observer(function (_ref) {
1380
1375
  var cssFontStyle = element.fontStyle === 'italic' ? 'italic' : 'normal';
1381
1376
  var cssFontWeight = String(element.fontWeight || 'normal');
1382
1377
  var originalText = element.text;
1378
+
1379
+ // The Group stays visible and mirrors the textarea's value live (via the
1380
+ // 'input' listener below), so what's on screen while typing is the real
1381
+ // Konva render — stroke, shadow, background, curve all included — not a
1382
+ // CSS approximation of it (CSS can't reproduce Canvas 2D's stroke/shadow
1383
+ // rendering faithfully; see e.g. -webkit-text-stroke looking bolder and
1384
+ // "welding" adjacent glyphs together vs. Canvas's per-glyph vector stroke).
1385
+ // The textarea itself is fully transparent — it only captures input and
1386
+ // shows a caret positioned over the real text.
1383
1387
  var textarea = document.createElement('textarea');
1384
- textarea.value = '';
1385
- textarea.placeholder = originalText;
1388
+ textarea.value = originalText;
1386
1389
  textarea.style.position = 'absolute';
1387
1390
  textarea.style.top = "".concat(textPosition.y, "px");
1388
1391
  textarea.style.left = "".concat(textPosition.x, "px");
@@ -1393,7 +1396,8 @@ var TextElementComponent = observer(function (_ref) {
1393
1396
  textarea.style.fontStyle = cssFontStyle;
1394
1397
  textarea.style.fontWeight = cssFontWeight;
1395
1398
  textarea.style.textAlign = element.align;
1396
- textarea.style.color = element.fill;
1399
+ textarea.style.color = 'transparent';
1400
+ textarea.style.caretColor = element.stroke || element.fill || '#000000';
1397
1401
  textarea.style.border = '0';
1398
1402
  textarea.style.borderWidth = '0';
1399
1403
  textarea.style.padding = '0';
@@ -1415,31 +1419,27 @@ var TextElementComponent = observer(function (_ref) {
1415
1419
  textarea.style.wordBreak = 'break-word';
1416
1420
  textarea.style.minHeight = '0';
1417
1421
  textarea.style.minWidth = '0';
1418
-
1419
- // Placeholder inherits the element's text color at 40% opacity
1420
- var placeholderStyle = document.createElement('style');
1421
- placeholderStyle.textContent = "\n textarea:placeholder-shown { opacity: 1; }\n textarea::placeholder { color: ".concat(element.fill, "; opacity: 0.4; }\n ");
1422
- stageContainer.appendChild(placeholderStyle);
1423
1422
  stageContainer.appendChild(textarea);
1424
1423
  textarea.focus();
1424
+ var caretPos = textarea.value.length;
1425
+ textarea.setSelectionRange(caretPos, caretPos);
1426
+ textarea.addEventListener('input', function () {
1427
+ element.set({
1428
+ text: textarea.value
1429
+ });
1430
+ });
1425
1431
  var removed = false;
1426
1432
  var removeTextarea = function removeTextarea() {
1427
1433
  var cancel = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
1428
1434
  if (removed) return;
1429
1435
  removed = true;
1430
- var newText = !cancel && textarea.value.length > 0 ? textarea.value : originalText;
1431
1436
  element.set({
1432
- text: newText
1437
+ text: cancel ? originalText : textarea.value
1433
1438
  });
1434
1439
  element.toggleEditMode(false);
1435
- if (grp) grp.show();
1436
- stage.batchDraw();
1437
1440
  if (textarea.parentNode) {
1438
1441
  textarea.parentNode.removeChild(textarea);
1439
1442
  }
1440
- if (placeholderStyle.parentNode) {
1441
- placeholderStyle.parentNode.removeChild(placeholderStyle);
1442
- }
1443
1443
  };
1444
1444
  textarea.addEventListener('blur', function () {
1445
1445
  return removeTextarea(false);