labellife-design-tool 2.2.8 → 2.2.9

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.
@@ -971,8 +971,10 @@ var TextElementComponent = observer(function (_ref) {
971
971
  var scaleY = absScale.y;
972
972
  var cssFontStyle = element.fontStyle === 'italic' ? 'italic' : 'normal';
973
973
  var cssFontWeight = String(element.fontWeight || 'normal');
974
+ var originalText = element.text;
974
975
  var textarea = document.createElement('textarea');
975
- textarea.value = element.text;
976
+ textarea.value = '';
977
+ textarea.placeholder = originalText;
976
978
  textarea.style.position = 'absolute';
977
979
  textarea.style.top = "".concat(textPosition.y, "px");
978
980
  textarea.style.left = "".concat(textPosition.x, "px");
@@ -1005,15 +1007,21 @@ var TextElementComponent = observer(function (_ref) {
1005
1007
  textarea.style.wordBreak = 'break-word';
1006
1008
  textarea.style.minHeight = '0';
1007
1009
  textarea.style.minWidth = '0';
1010
+
1011
+ // Placeholder inherits the element's text color at 40% opacity
1012
+ var placeholderStyle = document.createElement('style');
1013
+ placeholderStyle.textContent = "\n textarea:placeholder-shown { opacity: 1; }\n textarea::placeholder { color: ".concat(element.fill, "; opacity: 0.4; }\n ");
1014
+ stageContainer.appendChild(placeholderStyle);
1008
1015
  stageContainer.appendChild(textarea);
1009
1016
  textarea.focus();
1010
- textarea.select();
1011
1017
  var removed = false;
1012
1018
  var removeTextarea = function removeTextarea() {
1019
+ var cancel = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
1013
1020
  if (removed) return;
1014
1021
  removed = true;
1022
+ var newText = !cancel && textarea.value.length > 0 ? textarea.value : originalText;
1015
1023
  element.set({
1016
- text: textarea.value
1024
+ text: newText
1017
1025
  });
1018
1026
  element.toggleEditMode(false);
1019
1027
  if (grp) grp.show();
@@ -1021,12 +1029,15 @@ var TextElementComponent = observer(function (_ref) {
1021
1029
  if (textarea.parentNode) {
1022
1030
  textarea.parentNode.removeChild(textarea);
1023
1031
  }
1032
+ if (placeholderStyle.parentNode) {
1033
+ placeholderStyle.parentNode.removeChild(placeholderStyle);
1034
+ }
1024
1035
  };
1025
- textarea.addEventListener('blur', removeTextarea);
1036
+ textarea.addEventListener('blur', function () {
1037
+ return removeTextarea(false);
1038
+ });
1026
1039
  textarea.addEventListener('keydown', function (e) {
1027
- if (e.key === 'Escape') {
1028
- removeTextarea();
1029
- }
1040
+ if (e.key === 'Escape') removeTextarea(true);
1030
1041
  });
1031
1042
  };
1032
1043