slate-angular 19.1.1 → 19.2.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.
@@ -882,12 +882,42 @@ const setClipboardData = async (clipboardData, wrapper, attach, dataTransfer) =>
882
882
  setDataTransferClipboardText(dataTransfer, text);
883
883
  return;
884
884
  }
885
+ const htmlText = buildHTMLText(wrapper, attach, elements);
885
886
  // Compatible with situations where navigator.clipboard.write is not supported and dataTransfer is empty
886
887
  // Such as contextmenu copy in Firefox.
887
888
  if (isClipboardWriteTextSupported()) {
888
- const htmlText = buildHTMLText(wrapper, attach, elements);
889
889
  return await navigator.clipboard.writeText(htmlText);
890
890
  }
891
+ else {
892
+ return await fallbackCopyText(htmlText);
893
+ }
894
+ };
895
+ const fallbackCopyText = async (text) => {
896
+ return new Promise((resolve, reject) => {
897
+ const textArea = document.createElement('textarea');
898
+ textArea.value = text;
899
+ textArea.style.position = 'fixed';
900
+ textArea.style.left = '-999999px';
901
+ textArea.style.top = '-999999px';
902
+ textArea.style.opacity = '0';
903
+ document.body.appendChild(textArea);
904
+ textArea.focus();
905
+ textArea.select();
906
+ try {
907
+ const successful = document.execCommand('copy');
908
+ document.body.removeChild(textArea);
909
+ if (successful) {
910
+ resolve();
911
+ }
912
+ else {
913
+ reject(new Error('execCommand error'));
914
+ }
915
+ }
916
+ catch (err) {
917
+ document.body.removeChild(textArea);
918
+ reject(err);
919
+ }
920
+ });
891
921
  };
892
922
 
893
923
  const withAngular = (editor, clipboardFormatKey = 'x-slate-fragment') => {
@@ -3852,6 +3882,17 @@ const defaultScrollSelectionIntoView = (editor, domRange) => {
3852
3882
  // so enabled only if the selection has been collapsed.
3853
3883
  if (domRange.getBoundingClientRect && (!editor.selection || (editor.selection && Range.isCollapsed(editor.selection)))) {
3854
3884
  const leafEl = domRange.startContainer.parentElement;
3885
+ // COMPAT: In Chrome, domRange.getBoundingClientRect() can return zero dimensions for valid ranges (e.g. line breaks).
3886
+ // When this happens, do not scroll like most editors do.
3887
+ const domRect = domRange.getBoundingClientRect();
3888
+ const isZeroDimensionRect = domRect.width === 0 && domRect.height === 0 && domRect.x === 0 && domRect.y === 0;
3889
+ if (isZeroDimensionRect) {
3890
+ const leafRect = leafEl.getBoundingClientRect();
3891
+ const leafHasDimensions = leafRect.width > 0 || leafRect.height > 0;
3892
+ if (leafHasDimensions) {
3893
+ return;
3894
+ }
3895
+ }
3855
3896
  leafEl.getBoundingClientRect = domRange.getBoundingClientRect.bind(domRange);
3856
3897
  scrollIntoView(leafEl, {
3857
3898
  scrollMode: 'if-needed'
@@ -4028,5 +4069,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImpo
4028
4069
  * Generated bundle index. Do not edit.
4029
4070
  */
4030
4071
 
4031
- 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 };
4072
+ 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, 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 };
4032
4073
  //# sourceMappingURL=slate-angular.mjs.map