@flozy/editor 10.6.7 → 10.6.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,6 @@
1
1
  import { Editor, Element, Path, Transforms } from "slate";
2
2
  import insertNewLine from "./insertNewLine";
3
- import { ALLOWED_TEXT_NODES, getNode, getNodeText, getNodeWithType } from "./helper";
3
+ import { ALLOWED_TEXT_NODES, getNode, getNodeText, getNodeWithType, getSelectedText } from "./helper";
4
4
  import { isMobileWindow } from "../helper";
5
5
  import { removeAccordion } from "./events";
6
6
  import { ReactEditor } from "slate-react";
@@ -12,50 +12,48 @@ const focusAccordion = (editor, upPath) => {
12
12
  };
13
13
  export const insertAccordion = (editor, path) => {
14
14
  try {
15
- const {
16
- selection
17
- } = editor;
18
- if (selection) {
19
- const selectedNodes = Array.from(Editor.nodes(editor, {
20
- at: selection,
21
- match: n => Element.isElement(n),
22
- mode: "lowest" // use 'lowest' to get individual blocks
23
- }));
24
-
25
- for (const [node, path] of selectedNodes) {
26
- const accordion = {
27
- type: "accordion",
15
+ const selectedText = getSelectedText(editor);
16
+ const accordion = {
17
+ type: "accordion",
18
+ children: [{
19
+ type: "accordion-summary",
20
+ children: [{
21
+ type: "paragraph",
28
22
  children: [{
29
- type: "accordion-summary",
30
- children: [node]
31
- }, {
32
- type: "accordion-details",
33
- children: [{
34
- type: "paragraph",
35
- children: [{
36
- text: ""
37
- }]
38
- }]
23
+ text: selectedText || ""
39
24
  }]
40
- };
41
- Transforms.removeNodes(editor, {
42
- at: path
43
- });
44
- Transforms.insertNodes(editor, accordion, {
45
- at: path
46
- });
47
- }
48
- const lastNode = selectedNodes[selectedNodes.length - 1];
49
- const lastNodePath = lastNode[1];
50
- const accordionPath = [...lastNodePath, 0, 0, 0];
51
- if (isMobileWindow()) {
52
- // timeout to resolve focus issue in mobile
53
- setTimeout(() => focusAccordion(editor, accordionPath), 0);
54
- } else {
55
- focusAccordion(editor, accordionPath);
56
- }
57
- insertNewLine(editor);
25
+ }]
26
+ }, {
27
+ type: "accordion-details",
28
+ children: [{
29
+ type: "paragraph",
30
+ children: [{
31
+ text: ""
32
+ }]
33
+ }]
34
+ }]
35
+ };
36
+ const props = path ? {
37
+ at: path,
38
+ select: true
39
+ } : {
40
+ select: true
41
+ };
42
+ Transforms.insertNodes(editor, accordion, props);
43
+ const curPath = [...editor?.selection?.anchor?.path];
44
+ const upPath = [...curPath];
45
+ // get title index
46
+ const summaryIndex = upPath.length - 3;
47
+ upPath[summaryIndex] = upPath[summaryIndex] === 0 ? 0 : upPath[summaryIndex] - 1;
48
+
49
+ // select accordion title by default
50
+ if (isMobileWindow()) {
51
+ // timeout to resolve focus issue in mobile
52
+ setTimeout(() => focusAccordion(editor, upPath), 0);
53
+ } else {
54
+ focusAccordion(editor, upPath);
58
55
  }
56
+ insertNewLine(editor);
59
57
  } catch (err) {
60
58
  console.log(err);
61
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "10.6.7",
3
+ "version": "10.6.9",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"