@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.
@@ -145,6 +145,7 @@ const Styles = theme => ({
145
145
  "& .option-label": {
146
146
  display: "flex",
147
147
  alignItems: "center",
148
+ whiteSpace: 'nowrap',
148
149
  gap: "8px"
149
150
  },
150
151
  "&:hover": {
@@ -1,6 +1,5 @@
1
- import { Range, Transforms } from "slate";
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
- const isHavingSelection = selection && !Range.isCollapsed(selection);
17
- const selectedText = isHavingSelection ? getSelectedText(editor) : "";
18
- const currentNodeText = selectedText ? getCurrentNodeText(editor) : "";
19
- const fullySelected = selectedText?.length && currentNodeText.length === selectedText?.length;
20
- const accordion = {
21
- type: "accordion",
22
- children: [{
23
- type: "accordion-summary",
24
- children: [{
25
- type: "paragraph",
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
- text: ""
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
- const props = path ? {
41
- at: path,
42
- select: true
43
- } : {
44
- select: true
45
- };
46
- if (fullySelected) {
47
- Transforms.removeNodes(editor, props);
48
- }
49
- Transforms.insertNodes(editor, accordion, props);
50
- const curPath = [...editor?.selection?.anchor?.path];
51
- const upPath = [...curPath];
52
- // get title index
53
- const summaryIndex = upPath.length - 3;
54
- upPath[summaryIndex] = upPath[summaryIndex] === 0 ? 0 : upPath[summaryIndex] - 1;
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "10.5.7",
3
+ "version": "10.5.9",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"