slate-angular 19.1.2 → 19.3.0

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.
@@ -815,6 +815,27 @@ const getSelection = (root) => {
815
815
  }
816
816
  return document.getSelection();
817
817
  };
818
+ const getContentHeight = (element) => {
819
+ if (!element)
820
+ return 0;
821
+ const style = window.getComputedStyle(element);
822
+ const boxSizing = style.boxSizing;
823
+ const height = parseFloat(style.height) || 0;
824
+ const paddingTop = parseFloat(style.paddingTop) || 0;
825
+ const paddingBottom = parseFloat(style.paddingBottom) || 0;
826
+ const totalPadding = paddingTop + paddingBottom;
827
+ const borderTop = parseFloat(style.borderTopWidth) || 0;
828
+ const borderBottom = parseFloat(style.borderBottomWidth) || 0;
829
+ const totalBorder = borderTop + borderBottom;
830
+ let contentHeight;
831
+ if (boxSizing === 'border-box') {
832
+ contentHeight = height - totalPadding - totalBorder;
833
+ }
834
+ else {
835
+ contentHeight = height;
836
+ }
837
+ return Math.max(contentHeight, 0);
838
+ };
818
839
 
819
840
  const buildHTMLText = (wrapper, attach, data) => {
820
841
  const stringObj = JSON.stringify(data);
@@ -882,12 +903,42 @@ const setClipboardData = async (clipboardData, wrapper, attach, dataTransfer) =>
882
903
  setDataTransferClipboardText(dataTransfer, text);
883
904
  return;
884
905
  }
906
+ const htmlText = buildHTMLText(wrapper, attach, elements);
885
907
  // Compatible with situations where navigator.clipboard.write is not supported and dataTransfer is empty
886
908
  // Such as contextmenu copy in Firefox.
887
909
  if (isClipboardWriteTextSupported()) {
888
- const htmlText = buildHTMLText(wrapper, attach, elements);
889
910
  return await navigator.clipboard.writeText(htmlText);
890
911
  }
912
+ else {
913
+ return await fallbackCopyText(htmlText);
914
+ }
915
+ };
916
+ const fallbackCopyText = async (text) => {
917
+ return new Promise((resolve, reject) => {
918
+ const textArea = document.createElement('textarea');
919
+ textArea.value = text;
920
+ textArea.style.position = 'fixed';
921
+ textArea.style.left = '-999999px';
922
+ textArea.style.top = '-999999px';
923
+ textArea.style.opacity = '0';
924
+ document.body.appendChild(textArea);
925
+ textArea.focus();
926
+ textArea.select();
927
+ try {
928
+ const successful = document.execCommand('copy');
929
+ document.body.removeChild(textArea);
930
+ if (successful) {
931
+ resolve();
932
+ }
933
+ else {
934
+ reject(new Error('execCommand error'));
935
+ }
936
+ }
937
+ catch (err) {
938
+ document.body.removeChild(textArea);
939
+ reject(err);
940
+ }
941
+ });
891
942
  };
892
943
 
893
944
  const withAngular = (editor, clipboardFormatKey = 'x-slate-fragment') => {
@@ -2134,6 +2185,14 @@ class BaseLeafComponent extends BaseComponent {
2134
2185
  this.placeholderElement = placeholderElement;
2135
2186
  this.nativeElement.classList.add('leaf-with-placeholder');
2136
2187
  this.nativeElement.appendChild(placeholderElement);
2188
+ setTimeout(() => {
2189
+ const editorElement = this.nativeElement.closest('.the-editor-typo');
2190
+ const editorContentHeight = getContentHeight(editorElement);
2191
+ // Not supported webkitLineClamp exceeds height hiding
2192
+ placeholderElement.style.maxHeight = `${editorContentHeight}px`;
2193
+ const lineClamp = Math.floor(editorContentHeight / this.nativeElement.offsetHeight);
2194
+ placeholderElement.style.webkitLineClamp = `${lineClamp}`;
2195
+ });
2137
2196
  }
2138
2197
  updatePlaceholder() {
2139
2198
  if (this.placeholderElement.innerText !== this.context.leaf['placeholder']) {
@@ -4039,5 +4098,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImpo
4039
4098
  * Generated bundle index. Do not edit.
4040
4099
  */
4041
4100
 
4042
- export { AngularEditor, BaseComponent, BaseElementComponent, BaseLeafComponent, BaseTextComponent, EDITOR_TO_AFTER_VIEW_INIT_QUEUE, ELEMENT_TO_COMPONENT, FAKE_LEFT_BLOCK_CARD_OFFSET, FAKE_RIGHT_BLOCK_CARD_OFFSET, HAS_BEFORE_INPUT_SUPPORT, IS_ANDROID, IS_APPLE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_FIREFOX, IS_FIREFOX_LEGACY, IS_IOS, IS_QQBROWSER, IS_SAFARI, IS_UC_MOBILE, IS_WECHATBROWSER, PLACEHOLDER_SYMBOL, SlateChildren, SlateChildrenOutlet, SlateDefaultString, SlateEditable, SlateElement, SlateErrorCode, SlateFragmentAttributeKey, SlateLeaves, SlateModule, SlateString, blobAsString, buildHTMLText, check, completeTable, createClipboardData, createThrottleRAF, defaultScrollSelectionIntoView, getCardTargetAttribute, getClipboardData, getClipboardFromHTMLText, getDataTransferClipboard, getDataTransferClipboardText, getNavigatorClipboard, getPlainText, getSelection, getSlateFragmentAttribute, hasAfterContextChange, hasBeforeContextChange, hasBlockCard, hasBlockCardWithNode, hotkeys, isCardCenterByTargetAttr, isCardLeft, isCardLeftByTargetAttr, isCardRightByTargetAttr, isClipboardFile, isClipboardReadSupported, isClipboardWriteSupported, isClipboardWriteTextSupported, isComponentType, isDOMText, isDecoratorRangeListEqual, isEmpty, isInvalidTable, isTemplateRef, isValid, normalize, setClipboardData, setDataTransferClipboard, setDataTransferClipboardText, setNavigatorClipboard, shallowCompare, stripHtml, withAngular };
4101
+ export { AngularEditor, BaseComponent, BaseElementComponent, BaseLeafComponent, BaseTextComponent, EDITOR_TO_AFTER_VIEW_INIT_QUEUE, ELEMENT_TO_COMPONENT, FAKE_LEFT_BLOCK_CARD_OFFSET, FAKE_RIGHT_BLOCK_CARD_OFFSET, HAS_BEFORE_INPUT_SUPPORT, IS_ANDROID, IS_APPLE, IS_CHROME, IS_CHROME_LEGACY, IS_EDGE_LEGACY, IS_FIREFOX, IS_FIREFOX_LEGACY, IS_IOS, IS_QQBROWSER, IS_SAFARI, IS_UC_MOBILE, IS_WECHATBROWSER, PLACEHOLDER_SYMBOL, SlateChildren, SlateChildrenOutlet, SlateDefaultString, SlateEditable, SlateElement, SlateErrorCode, SlateFragmentAttributeKey, SlateLeaves, SlateModule, SlateString, blobAsString, buildHTMLText, check, completeTable, createClipboardData, createThrottleRAF, defaultScrollSelectionIntoView, fallbackCopyText, getCardTargetAttribute, getClipboardData, getClipboardFromHTMLText, getContentHeight, getDataTransferClipboard, getDataTransferClipboardText, getNavigatorClipboard, getPlainText, getSelection, getSlateFragmentAttribute, hasAfterContextChange, hasBeforeContextChange, hasBlockCard, hasBlockCardWithNode, hotkeys, isCardCenterByTargetAttr, isCardLeft, isCardLeftByTargetAttr, isCardRightByTargetAttr, isClipboardFile, isClipboardReadSupported, isClipboardWriteSupported, isClipboardWriteTextSupported, isComponentType, isDOMText, isDecoratorRangeListEqual, isEmpty, isInvalidTable, isTemplateRef, isValid, normalize, setClipboardData, setDataTransferClipboard, setDataTransferClipboardText, setNavigatorClipboard, shallowCompare, stripHtml, withAngular };
4043
4102
  //# sourceMappingURL=slate-angular.mjs.map