@flozy/editor 10.5.7 → 10.5.9
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,6 +1,5 @@
|
|
1
|
-
import {
|
1
|
+
import { Editor, Element, Transforms } from "slate";
|
2
2
|
import insertNewLine from "./insertNewLine";
|
3
|
-
import { getCurrentNodeText, getSelectedText } from "./helper";
|
4
3
|
import { isMobileWindow } from "../helper";
|
5
4
|
const focusAccordion = (editor, upPath) => {
|
6
5
|
Transforms.select(editor, {
|
@@ -13,54 +12,47 @@ export const insertAccordion = (editor, path) => {
|
|
13
12
|
const {
|
14
13
|
selection
|
15
14
|
} = editor;
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
type: "
|
26
|
-
children: [{
|
27
|
-
text: selectedText || ""
|
28
|
-
}]
|
29
|
-
}]
|
30
|
-
}, {
|
31
|
-
type: "accordion-details",
|
32
|
-
children: [{
|
33
|
-
type: "paragraph",
|
15
|
+
if (selection) {
|
16
|
+
const selectedNodes = Array.from(Editor.nodes(editor, {
|
17
|
+
at: selection,
|
18
|
+
match: n => Element.isElement(n),
|
19
|
+
mode: "lowest" // use 'lowest' to get individual blocks
|
20
|
+
}));
|
21
|
+
|
22
|
+
for (const [node, path] of selectedNodes) {
|
23
|
+
const accordion = {
|
24
|
+
type: "accordion",
|
34
25
|
children: [{
|
35
|
-
|
26
|
+
type: "accordion-summary",
|
27
|
+
children: [node]
|
28
|
+
}, {
|
29
|
+
type: "accordion-details",
|
30
|
+
children: [{
|
31
|
+
type: "paragraph",
|
32
|
+
children: [{
|
33
|
+
text: ""
|
34
|
+
}]
|
35
|
+
}]
|
36
36
|
}]
|
37
|
-
}
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
// select accordion title by default
|
57
|
-
if (isMobileWindow()) {
|
58
|
-
// timeout to resolve focus issue in mobile
|
59
|
-
setTimeout(() => focusAccordion(editor, upPath), 0);
|
60
|
-
} else {
|
61
|
-
focusAccordion(editor, upPath);
|
37
|
+
};
|
38
|
+
Transforms.removeNodes(editor, {
|
39
|
+
at: path
|
40
|
+
});
|
41
|
+
Transforms.insertNodes(editor, accordion, {
|
42
|
+
at: path
|
43
|
+
});
|
44
|
+
}
|
45
|
+
const lastNode = selectedNodes[selectedNodes.length - 1];
|
46
|
+
const lastNodePath = lastNode[1];
|
47
|
+
const accordionPath = [...lastNodePath, 0, 0, 0];
|
48
|
+
if (isMobileWindow()) {
|
49
|
+
// timeout to resolve focus issue in mobile
|
50
|
+
setTimeout(() => focusAccordion(editor, accordionPath), 0);
|
51
|
+
} else {
|
52
|
+
focusAccordion(editor, accordionPath);
|
53
|
+
}
|
54
|
+
insertNewLine(editor);
|
62
55
|
}
|
63
|
-
insertNewLine(editor);
|
64
56
|
} catch (err) {
|
65
57
|
console.log(err);
|
66
58
|
}
|