@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.
@@ -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,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 currentNodeText = selectedText ? getCurrentNodeText(editor) : "";
19
- const fullySelected = selectedText?.length && currentNodeText.length === selectedText?.length;
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
- Transforms.removeNodes(editor, props);
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];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "10.5.7",
3
+ "version": "10.5.8",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"