@flozy/editor 10.5.8 → 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.
- package/dist/Editor/utils/accordion.js +38 -64
- package/package.json +1 -1
@@ -1,6 +1,5 @@
|
|
1
|
-
import { Editor,
|
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, {
|
@@ -8,77 +7,52 @@ const focusAccordion = (editor, upPath) => {
|
|
8
7
|
offset: 0
|
9
8
|
});
|
10
9
|
};
|
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
|
-
}
|
18
10
|
export const insertAccordion = (editor, path) => {
|
19
11
|
try {
|
20
12
|
const {
|
21
13
|
selection
|
22
14
|
} = editor;
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
+
}));
|
26
21
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
if (isSingleNodeSelected) {
|
31
|
-
const currentNodeText = selectedText ? getCurrentNodeText(editor) : "";
|
32
|
-
fullySelected = selectedText?.length && currentNodeText.length === selectedText?.length;
|
33
|
-
}
|
34
|
-
const accordion = {
|
35
|
-
type: "accordion",
|
36
|
-
children: [{
|
37
|
-
type: "accordion-summary",
|
38
|
-
children: [{
|
39
|
-
type: "paragraph",
|
40
|
-
children: [{
|
41
|
-
text: selectedText || ""
|
42
|
-
}]
|
43
|
-
}]
|
44
|
-
}, {
|
45
|
-
type: "accordion-details",
|
46
|
-
children: [{
|
47
|
-
type: "paragraph",
|
22
|
+
for (const [node, path] of selectedNodes) {
|
23
|
+
const accordion = {
|
24
|
+
type: "accordion",
|
48
25
|
children: [{
|
49
|
-
|
26
|
+
type: "accordion-summary",
|
27
|
+
children: [node]
|
28
|
+
}, {
|
29
|
+
type: "accordion-details",
|
30
|
+
children: [{
|
31
|
+
type: "paragraph",
|
32
|
+
children: [{
|
33
|
+
text: ""
|
34
|
+
}]
|
35
|
+
}]
|
50
36
|
}]
|
51
|
-
}
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
const
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
const upPath = [...curPath];
|
70
|
-
// get title index
|
71
|
-
const summaryIndex = upPath.length - 3;
|
72
|
-
upPath[summaryIndex] = upPath[summaryIndex] === 0 ? 0 : upPath[summaryIndex] - 1;
|
73
|
-
|
74
|
-
// select accordion title by default
|
75
|
-
if (isMobileWindow()) {
|
76
|
-
// timeout to resolve focus issue in mobile
|
77
|
-
setTimeout(() => focusAccordion(editor, upPath), 0);
|
78
|
-
} else {
|
79
|
-
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);
|
80
55
|
}
|
81
|
-
insertNewLine(editor);
|
82
56
|
} catch (err) {
|
83
57
|
console.log(err);
|
84
58
|
}
|