@flozy/editor 10.5.7 → 10.5.8
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.
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Range, Transforms } from "slate";
|
1
|
+
import { Editor, Range, Transforms } from "slate";
|
2
2
|
import insertNewLine from "./insertNewLine";
|
3
3
|
import { getCurrentNodeText, getSelectedText } from "./helper";
|
4
4
|
import { isMobileWindow } from "../helper";
|
@@ -8,6 +8,13 @@ const focusAccordion = (editor, upPath) => {
|
|
8
8
|
offset: 0
|
9
9
|
});
|
10
10
|
};
|
11
|
+
function isSelectionInSingleNode(editor) {
|
12
|
+
const {
|
13
|
+
anchor,
|
14
|
+
focus
|
15
|
+
} = editor.selection;
|
16
|
+
return Editor.path(editor, anchor).toString() === Editor.path(editor, focus).toString();
|
17
|
+
}
|
11
18
|
export const insertAccordion = (editor, path) => {
|
12
19
|
try {
|
13
20
|
const {
|
@@ -15,8 +22,15 @@ export const insertAccordion = (editor, path) => {
|
|
15
22
|
} = editor;
|
16
23
|
const isHavingSelection = selection && !Range.isCollapsed(selection);
|
17
24
|
const selectedText = isHavingSelection ? getSelectedText(editor) : "";
|
18
|
-
const
|
19
|
-
|
25
|
+
const isSingleNodeSelected = isHavingSelection && isSelectionInSingleNode(editor);
|
26
|
+
|
27
|
+
// Fully select the heading text and convert it to an accordion.
|
28
|
+
// An empty heading is inserted just before the newly created accordion.
|
29
|
+
let fullySelected = false;
|
30
|
+
if (isSingleNodeSelected) {
|
31
|
+
const currentNodeText = selectedText ? getCurrentNodeText(editor) : "";
|
32
|
+
fullySelected = selectedText?.length && currentNodeText.length === selectedText?.length;
|
33
|
+
}
|
20
34
|
const accordion = {
|
21
35
|
type: "accordion",
|
22
36
|
children: [{
|
@@ -44,7 +58,11 @@ export const insertAccordion = (editor, path) => {
|
|
44
58
|
select: true
|
45
59
|
};
|
46
60
|
if (fullySelected) {
|
47
|
-
|
61
|
+
const insertPath = editor.selection.anchor.path;
|
62
|
+
Transforms.removeNodes(editor, {
|
63
|
+
at: insertPath
|
64
|
+
});
|
65
|
+
props.at = insertPath;
|
48
66
|
}
|
49
67
|
Transforms.insertNodes(editor, accordion, props);
|
50
68
|
const curPath = [...editor?.selection?.anchor?.path];
|