slate-angular 17.2.2 → 17.4.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.
- package/esm2022/plugins/angular-editor.mjs +30 -30
- package/esm2022/utils/clipboard/clipboard.mjs +5 -4
- package/esm2022/utils/clipboard/navigator-clipboard.mjs +7 -4
- package/fesm2022/slate-angular.mjs +38 -34
- package/fesm2022/slate-angular.mjs.map +1 -1
- package/package.json +3 -3
- package/plugins/angular-editor.d.ts +3 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Editor, Range, Element, Transforms,
|
|
1
|
+
import { Editor, Range, Element, Transforms, Text as Text$1, Path, Node } from 'slate';
|
|
2
2
|
import { isKeyHotkey } from 'is-hotkey';
|
|
3
3
|
import * as i0 from '@angular/core';
|
|
4
4
|
import { TemplateRef, Component, ChangeDetectionStrategy, ViewChild, Directive, Input, InjectionToken, ComponentRef, IterableDiffers, HostBinding, inject, ViewContainerRef, forwardRef, ElementRef, Inject, NgModule } from '@angular/core';
|
|
@@ -515,20 +515,33 @@ const AngularEditor = {
|
|
|
515
515
|
/**
|
|
516
516
|
* Find a native DOM selection point from a Slate point.
|
|
517
517
|
*/
|
|
518
|
-
toDOMPoint(editor, point) {
|
|
518
|
+
toDOMPoint(editor, point, options) {
|
|
519
519
|
const [node] = Editor.node(editor, point.path);
|
|
520
520
|
const el = AngularEditor.toDOMNode(editor, node);
|
|
521
521
|
let domPoint;
|
|
522
522
|
// block card
|
|
523
|
-
const
|
|
524
|
-
if (
|
|
525
|
-
if (point.offset
|
|
526
|
-
|
|
527
|
-
|
|
523
|
+
const [parentNode] = Editor.parent(editor, point.path);
|
|
524
|
+
if (editor.isBlockCard(parentNode) || editor.isBlockCard(node)) {
|
|
525
|
+
if (point.offset < 0) {
|
|
526
|
+
if (point.offset === FAKE_LEFT_BLOCK_CARD_OFFSET) {
|
|
527
|
+
const cursorNode = AngularEditor.getCardCursorNode(editor, node, { direction: 'left' });
|
|
528
|
+
return [cursorNode, 1];
|
|
529
|
+
}
|
|
530
|
+
else {
|
|
531
|
+
const cursorNode = AngularEditor.getCardCursorNode(editor, node, { direction: 'right' });
|
|
532
|
+
return [cursorNode, 1];
|
|
533
|
+
}
|
|
528
534
|
}
|
|
529
|
-
|
|
530
|
-
const
|
|
531
|
-
|
|
535
|
+
if (Range.isExpanded(options.range)) {
|
|
536
|
+
const [start, end] = Range.edges(options.range);
|
|
537
|
+
if (start === point) {
|
|
538
|
+
const cursorNode = AngularEditor.getCardCursorNode(editor, parentNode, { direction: 'left' });
|
|
539
|
+
return [cursorNode, 1];
|
|
540
|
+
}
|
|
541
|
+
else {
|
|
542
|
+
const cursorNode = AngularEditor.getCardCursorNode(editor, parentNode, { direction: 'right' });
|
|
543
|
+
return [cursorNode, 1];
|
|
544
|
+
}
|
|
532
545
|
}
|
|
533
546
|
}
|
|
534
547
|
// If we're inside a void node, force the offset to 0, otherwise the zero
|
|
@@ -573,8 +586,8 @@ const AngularEditor = {
|
|
|
573
586
|
toDOMRange(editor, range) {
|
|
574
587
|
const { anchor, focus } = range;
|
|
575
588
|
const isBackward = Range.isBackward(range);
|
|
576
|
-
const domAnchor = AngularEditor.toDOMPoint(editor, anchor);
|
|
577
|
-
const domFocus = Range.isCollapsed(range) ? domAnchor : AngularEditor.toDOMPoint(editor, focus);
|
|
589
|
+
const domAnchor = AngularEditor.toDOMPoint(editor, anchor, { range });
|
|
590
|
+
const domFocus = Range.isCollapsed(range) ? domAnchor : AngularEditor.toDOMPoint(editor, focus, { range });
|
|
578
591
|
const window = AngularEditor.getWindow(editor);
|
|
579
592
|
const domRange = window.document.createRange();
|
|
580
593
|
const [startNode, startOffset] = isBackward ? domFocus : domAnchor;
|
|
@@ -694,25 +707,12 @@ const AngularEditor = {
|
|
|
694
707
|
return { path: blockPath, offset: -2 };
|
|
695
708
|
}
|
|
696
709
|
}
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
if (isCardLeftByTargetAttr(cardTargetAttr) && !isBackward) {
|
|
700
|
-
const endPath = blockPath[blockPath.length - 1] <= 0 ? blockPath : Path.previous(blockPath);
|
|
701
|
-
return Editor.end(editor, endPath);
|
|
710
|
+
if (isCardLeftByTargetAttr(cardTargetAttr)) {
|
|
711
|
+
return Editor.start(editor, blockPath);
|
|
702
712
|
}
|
|
703
|
-
|
|
704
|
-
if ((isCardCenterByTargetAttr(cardTargetAttr) || isCardRightByTargetAttr(cardTargetAttr)) && !isBackward) {
|
|
713
|
+
else {
|
|
705
714
|
return Editor.end(editor, blockPath);
|
|
706
715
|
}
|
|
707
|
-
// backward
|
|
708
|
-
// and to the start of next node
|
|
709
|
-
if (isCardRightByTargetAttr(cardTargetAttr) && isBackward) {
|
|
710
|
-
return Editor.start(editor, Path.next(blockPath));
|
|
711
|
-
}
|
|
712
|
-
// and to the start of current node
|
|
713
|
-
if ((isCardCenterByTargetAttr(cardTargetAttr) || isCardLeftByTargetAttr(cardTargetAttr)) && isBackward) {
|
|
714
|
-
return Editor.start(editor, blockPath);
|
|
715
|
-
}
|
|
716
716
|
}
|
|
717
717
|
if (parentNode) {
|
|
718
718
|
const voidNode = parentNode.closest('[data-slate-void="true"]');
|
|
@@ -1159,7 +1159,8 @@ const getNavigatorClipboard = async () => {
|
|
|
1159
1159
|
const blob = await (await fetch(url)).blob();
|
|
1160
1160
|
return new File([blob], 'file', { type: blob.type });
|
|
1161
1161
|
}));
|
|
1162
|
-
|
|
1162
|
+
clipboardData = {
|
|
1163
|
+
...clipboardData,
|
|
1163
1164
|
files
|
|
1164
1165
|
};
|
|
1165
1166
|
}
|
|
@@ -1167,15 +1168,17 @@ const getNavigatorClipboard = async () => {
|
|
|
1167
1168
|
const htmlContent = await blobAsString(await item.getType('text/html'));
|
|
1168
1169
|
const htmlClipboardData = getClipboardFromHTMLText(htmlContent);
|
|
1169
1170
|
if (htmlClipboardData) {
|
|
1170
|
-
|
|
1171
|
+
clipboardData = { ...clipboardData, ...htmlClipboardData };
|
|
1172
|
+
return clipboardData;
|
|
1171
1173
|
}
|
|
1172
1174
|
if (htmlContent && htmlContent.trim()) {
|
|
1173
|
-
clipboardData = { html: htmlContent };
|
|
1175
|
+
clipboardData = { ...clipboardData, html: htmlContent };
|
|
1174
1176
|
}
|
|
1175
1177
|
}
|
|
1176
1178
|
if (item.types.includes('text/plain')) {
|
|
1177
1179
|
const textContent = await blobAsString(await item.getType('text/plain'));
|
|
1178
1180
|
clipboardData = {
|
|
1181
|
+
...clipboardData,
|
|
1179
1182
|
text: stripHtml(textContent)
|
|
1180
1183
|
};
|
|
1181
1184
|
}
|
|
@@ -1216,11 +1219,12 @@ const createClipboardData = (html, elements, text, files) => {
|
|
|
1216
1219
|
const getClipboardData = async (dataTransfer) => {
|
|
1217
1220
|
let clipboardData = null;
|
|
1218
1221
|
if (dataTransfer) {
|
|
1222
|
+
let filesData = {};
|
|
1219
1223
|
if (dataTransfer.files.length) {
|
|
1220
|
-
|
|
1224
|
+
filesData = { ...filesData, files: Array.from(dataTransfer.files) };
|
|
1221
1225
|
}
|
|
1222
1226
|
clipboardData = getDataTransferClipboard(dataTransfer);
|
|
1223
|
-
return clipboardData;
|
|
1227
|
+
return { ...clipboardData, ...filesData };
|
|
1224
1228
|
}
|
|
1225
1229
|
if (isClipboardReadSupported()) {
|
|
1226
1230
|
return await getNavigatorClipboard();
|
|
@@ -1240,7 +1244,7 @@ const setClipboardData = async (clipboardData, wrapper, attach, dataTransfer) =>
|
|
|
1240
1244
|
if (isClipboardWriteSupported()) {
|
|
1241
1245
|
const htmlText = buildHTMLText(wrapper, attach, elements);
|
|
1242
1246
|
// TODO
|
|
1243
|
-
// maybe fail to write when copy some cell in table
|
|
1247
|
+
// maybe fail to write when copy some cell in table
|
|
1244
1248
|
return await setNavigatorClipboard(htmlText, elements, text);
|
|
1245
1249
|
}
|
|
1246
1250
|
if (dataTransfer) {
|