slate-angular 17.4.2 → 17.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.
@@ -816,15 +816,6 @@ const AngularEditor = {
816
816
  if (anchorNode == null || focusNode == null || anchorOffset == null || focusOffset == null) {
817
817
  throw new Error(`Cannot resolve a Slate range from DOM range: ${domRange}`);
818
818
  }
819
- // COMPAT: Triple-clicking a word in chrome will sometimes place the focus
820
- // inside a `contenteditable="false"` DOM node following the word, which
821
- // will cause `toSlatePoint` to throw an error. (2023/03/07)
822
- if ('getAttribute' in focusNode &&
823
- focusNode.getAttribute('contenteditable') === 'false' &&
824
- focusNode.getAttribute('data-slate-void') !== 'true') {
825
- focusNode = anchorNode;
826
- focusOffset = anchorNode.textContent?.length || 0;
827
- }
828
819
  const anchor = AngularEditor.toSlatePoint(editor, [anchorNode, anchorOffset], { suppressThrow, exactMatch });
829
820
  if (!anchor) {
830
821
  return null;
@@ -1055,6 +1046,48 @@ const createThrottleRAF = () => {
1055
1046
  return throttleRAF;
1056
1047
  };
1057
1048
 
1049
+ const isClipboardReadSupported = () => {
1050
+ return 'clipboard' in navigator && 'read' in navigator.clipboard;
1051
+ };
1052
+ const isClipboardWriteSupported = () => {
1053
+ return 'clipboard' in navigator && 'write' in navigator.clipboard;
1054
+ };
1055
+ const isClipboardWriteTextSupported = () => {
1056
+ return 'clipboard' in navigator && 'writeText' in navigator.clipboard;
1057
+ };
1058
+ const isClipboardFile = (item) => {
1059
+ return item.types.find(i => i.match(/^image\//));
1060
+ };
1061
+ const isInvalidTable = (nodes = []) => {
1062
+ return nodes.some(node => node.tagName.toLowerCase() === 'tr');
1063
+ };
1064
+ const stripHtml = (html) => {
1065
+ // See <https://github.com/developit/preact-markup/blob/4788b8d61b4e24f83688710746ee36e7464f7bbc/src/parse-markup.js#L60-L69>
1066
+ const doc = document.implementation.createHTMLDocument('');
1067
+ doc.documentElement.innerHTML = html.trim();
1068
+ return doc.body.textContent || doc.body.innerText || '';
1069
+ };
1070
+ const blobAsString = (blob) => {
1071
+ return new Promise((resolve, reject) => {
1072
+ const reader = new FileReader();
1073
+ reader.addEventListener('loadend', () => {
1074
+ const text = reader.result;
1075
+ resolve(text);
1076
+ });
1077
+ reader.addEventListener('error', () => {
1078
+ reject(reader.error);
1079
+ });
1080
+ reader.readAsText(blob);
1081
+ });
1082
+ };
1083
+ const completeTable = (fragment) => {
1084
+ const result = document.createDocumentFragment();
1085
+ const table = document.createElement('table');
1086
+ result.appendChild(table);
1087
+ table.appendChild(fragment);
1088
+ return result;
1089
+ };
1090
+
1058
1091
  const setDataTransferClipboard = (dataTransfer, htmlText) => {
1059
1092
  dataTransfer?.setData(`text/html`, htmlText);
1060
1093
  };
@@ -1098,38 +1131,6 @@ const getDataTransferClipboardText = (data) => {
1098
1131
  return { text };
1099
1132
  };
1100
1133
 
1101
- const isClipboardReadSupported = () => {
1102
- return 'clipboard' in navigator && 'read' in navigator.clipboard;
1103
- };
1104
- const isClipboardWriteSupported = () => {
1105
- return 'clipboard' in navigator && 'write' in navigator.clipboard;
1106
- };
1107
- const isClipboardWriteTextSupported = () => {
1108
- return 'clipboard' in navigator && 'writeText' in navigator.clipboard;
1109
- };
1110
- const isClipboardFile = (item) => {
1111
- return item.types.find(i => i.match(/^image\//));
1112
- };
1113
- const stripHtml = (html) => {
1114
- // See <https://github.com/developit/preact-markup/blob/4788b8d61b4e24f83688710746ee36e7464f7bbc/src/parse-markup.js#L60-L69>
1115
- const doc = document.implementation.createHTMLDocument('');
1116
- doc.documentElement.innerHTML = html.trim();
1117
- return doc.body.textContent || doc.body.innerText || '';
1118
- };
1119
- const blobAsString = (blob) => {
1120
- return new Promise((resolve, reject) => {
1121
- const reader = new FileReader();
1122
- reader.addEventListener('loadend', () => {
1123
- const text = reader.result;
1124
- resolve(text);
1125
- });
1126
- reader.addEventListener('error', () => {
1127
- reject(reader.error);
1128
- });
1129
- reader.readAsText(blob);
1130
- });
1131
- };
1132
-
1133
1134
  const setNavigatorClipboard = async (htmlText, data, text = '') => {
1134
1135
  let textClipboard = text;
1135
1136
  if (isClipboardWriteSupported()) {
@@ -1444,10 +1445,16 @@ const withAngular = (editor, clipboardFormatKey = 'x-slate-fragment') => {
1444
1445
  const fragment = e.getFragment();
1445
1446
  // Add the content to a <div> so that we can get its inner HTML.
1446
1447
  const div = contents.ownerDocument.createElement('div');
1448
+ const attachWrapper = document.createElement('div');
1449
+ const elements = Array.from(contents.children);
1450
+ if (isInvalidTable(elements)) {
1451
+ contents = completeTable(contents.cloneNode(true));
1452
+ }
1453
+ attachWrapper.appendChild(attach);
1447
1454
  div.appendChild(contents);
1448
1455
  div.setAttribute('hidden', 'true');
1449
1456
  contents.ownerDocument.body.appendChild(div);
1450
- setClipboardData({ text: getPlainText(div), elements: fragment }, div, attach, dataTransfer);
1457
+ setClipboardData({ text: getPlainText(div), elements: fragment }, div, attachWrapper, dataTransfer);
1451
1458
  contents.ownerDocument.body.removeChild(div);
1452
1459
  };
1453
1460
  e.deleteCutData = () => {
@@ -3548,15 +3555,17 @@ class SlateEditable {
3548
3555
  }
3549
3556
  // try to get the selection directly, because some terrible case can be normalize for normalizeDOMPoint
3550
3557
  // for example, double-click the last cell of the table to select a non-editable DOM
3551
- const range = AngularEditor.toSlateRange(this.editor, domSelection);
3552
- if (this.editor.selection && Range.equals(range, this.editor.selection) && !hasStringTarget(domSelection)) {
3553
- if (!isTargetInsideVoid(this.editor, activeElement)) {
3554
- // force adjust DOMSelection
3555
- this.toNativeSelection();
3558
+ const range = AngularEditor.toSlateRange(this.editor, domSelection, { exactMatch: false, suppressThrow: true });
3559
+ if (range) {
3560
+ if (this.editor.selection && Range.equals(range, this.editor.selection) && !hasStringTarget(domSelection)) {
3561
+ if (!isTargetInsideVoid(this.editor, activeElement)) {
3562
+ // force adjust DOMSelection
3563
+ this.toNativeSelection();
3564
+ }
3565
+ }
3566
+ else {
3567
+ Transforms.select(this.editor, range);
3556
3568
  }
3557
- }
3558
- else {
3559
- Transforms.select(this.editor, range);
3560
3569
  }
3561
3570
  }
3562
3571
  catch (error) {
@@ -4496,5 +4505,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.4", ngImpor
4496
4505
  * Generated bundle index. Do not edit.
4497
4506
  */
4498
4507
 
4499
- export { AngularEditor, BaseComponent, BaseElementComponent, BaseLeafComponent, BaseTextComponent, DOMComment, DOMElement, DOMNode, DOMRange, DOMSelection, DOMStaticRange, DOMText, EDITOR_TO_AFTER_VIEW_INIT_QUEUE, EDITOR_TO_ELEMENT, EDITOR_TO_ON_CHANGE, EDITOR_TO_PLACEHOLDER, EDITOR_TO_WINDOW, ELEMENT_TO_COMPONENT, ELEMENT_TO_NODE, FAKE_LEFT_BLOCK_CARD_OFFSET, FAKE_RIGHT_BLOCK_CARD_OFFSET, HAS_BEFORE_INPUT_SUPPORT, IS_ANDROID, IS_APPLE, IS_CHROME, IS_CHROME_LEGACY, IS_CLICKING, IS_DRAGGING, IS_EDGE_LEGACY, IS_FIREFOX, IS_FIREFOX_LEGACY, IS_FOCUSED, IS_IOS, IS_QQBROWSER, IS_READONLY, IS_SAFARI, IS_UC_MOBILE, IS_WECHATBROWSER, KEY_TO_ELEMENT, Key, NODE_TO_ELEMENT, NODE_TO_INDEX, NODE_TO_KEY, NODE_TO_PARENT, PLACEHOLDER_SYMBOL, SlateChildren, SlateChildrenOutlet, SlateDefaultString, SlateEditable, SlateElement, SlateErrorCode, SlateFragmentAttributeKey, SlateLeaves, SlateModule, SlateString, blobAsString, buildHTMLText, check, createClipboardData, createThrottleRAF, defaultScrollSelectionIntoView, getCardTargetAttribute, getClipboardData, getClipboardFromHTMLText, getDataTransferClipboard, getDataTransferClipboardText, getDefaultView, getEditableChild, getEditableChildAndIndex, getNavigatorClipboard, getPlainText, getSlateFragmentAttribute, hasAfterContextChange, hasBeforeContextChange, hasBlockCard, hasBlockCardWithNode, hasEditableTarget, hasShadowRoot, hotkeys, isCardCenterByTargetAttr, isCardLeft, isCardLeftByTargetAttr, isCardRightByTargetAttr, isClipboardFile, isClipboardReadSupported, isClipboardWriteSupported, isClipboardWriteTextSupported, isComponentType, isDOMComment, isDOMElement, isDOMNode, isDOMSelection, isDOMText, isDecoratorRangeListEqual, isEmpty, isPlainTextOnlyPaste, isTemplateRef, isValid, normalize, normalizeDOMPoint, setClipboardData, setDataTransferClipboard, setDataTransferClipboardText, setNavigatorClipboard, shallowCompare, stripHtml, withAngular };
4508
+ export { AngularEditor, BaseComponent, BaseElementComponent, BaseLeafComponent, BaseTextComponent, DOMComment, DOMElement, DOMNode, DOMRange, DOMSelection, DOMStaticRange, DOMText, EDITOR_TO_AFTER_VIEW_INIT_QUEUE, EDITOR_TO_ELEMENT, EDITOR_TO_ON_CHANGE, EDITOR_TO_PLACEHOLDER, EDITOR_TO_WINDOW, ELEMENT_TO_COMPONENT, ELEMENT_TO_NODE, FAKE_LEFT_BLOCK_CARD_OFFSET, FAKE_RIGHT_BLOCK_CARD_OFFSET, HAS_BEFORE_INPUT_SUPPORT, IS_ANDROID, IS_APPLE, IS_CHROME, IS_CHROME_LEGACY, IS_CLICKING, IS_DRAGGING, IS_EDGE_LEGACY, IS_FIREFOX, IS_FIREFOX_LEGACY, IS_FOCUSED, IS_IOS, IS_QQBROWSER, IS_READONLY, IS_SAFARI, IS_UC_MOBILE, IS_WECHATBROWSER, KEY_TO_ELEMENT, Key, NODE_TO_ELEMENT, NODE_TO_INDEX, NODE_TO_KEY, NODE_TO_PARENT, PLACEHOLDER_SYMBOL, SlateChildren, SlateChildrenOutlet, SlateDefaultString, SlateEditable, SlateElement, SlateErrorCode, SlateFragmentAttributeKey, SlateLeaves, SlateModule, SlateString, blobAsString, buildHTMLText, check, completeTable, createClipboardData, createThrottleRAF, defaultScrollSelectionIntoView, getCardTargetAttribute, getClipboardData, getClipboardFromHTMLText, getDataTransferClipboard, getDataTransferClipboardText, getDefaultView, getEditableChild, getEditableChildAndIndex, getNavigatorClipboard, getPlainText, getSlateFragmentAttribute, hasAfterContextChange, hasBeforeContextChange, hasBlockCard, hasBlockCardWithNode, hasEditableTarget, hasShadowRoot, hotkeys, isCardCenterByTargetAttr, isCardLeft, isCardLeftByTargetAttr, isCardRightByTargetAttr, isClipboardFile, isClipboardReadSupported, isClipboardWriteSupported, isClipboardWriteTextSupported, isComponentType, isDOMComment, isDOMElement, isDOMNode, isDOMSelection, isDOMText, isDecoratorRangeListEqual, isEmpty, isInvalidTable, isPlainTextOnlyPaste, isTemplateRef, isValid, normalize, normalizeDOMPoint, setClipboardData, setDataTransferClipboard, setDataTransferClipboardText, setNavigatorClipboard, shallowCompare, stripHtml, withAngular };
4500
4509
  //# sourceMappingURL=slate-angular.mjs.map