@flozy/editor 2.1.4 → 2.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. package/dist/Editor/CommonEditor.js +5 -8
  2. package/dist/Editor/Elements/AppHeader/AppHeader.js +0 -2
  3. package/dist/Editor/Elements/Carousel/Carousel.js +2 -2
  4. package/dist/Editor/Elements/Embed/Frames/DarkFrame.js +30 -9
  5. package/dist/Editor/Elements/Embed/Frames/ImageFrame.js +141 -0
  6. package/dist/Editor/Elements/Embed/Frames/InstaFrame.js +35 -10
  7. package/dist/Editor/Elements/Embed/Frames/InstaFrameDark.js +34 -10
  8. package/dist/Editor/Elements/Embed/Frames/LiteFrame.js +33 -9
  9. package/dist/Editor/Elements/Embed/Frames/RoundedDark.js +33 -9
  10. package/dist/Editor/Elements/Embed/Frames/RoundedLight.js +33 -9
  11. package/dist/Editor/Elements/Embed/Frames/RoundedLightB2.js +33 -9
  12. package/dist/Editor/Elements/Embed/Frames/Slider.js +40 -0
  13. package/dist/Editor/Elements/Embed/Image.js +15 -6
  14. package/dist/Editor/Elements/EmbedScript/Code.js +41 -0
  15. package/dist/Editor/Elements/EmbedScript/EmbedScript.js +65 -0
  16. package/dist/Editor/Elements/Form/FormElements/FormTextArea.js +2 -1
  17. package/dist/Editor/Elements/List/CheckList.js +43 -36
  18. package/dist/Editor/Styles/EditorStyles.js +4 -2
  19. package/dist/Editor/Toolbar/Mini/MiniToolbar.js +2 -4
  20. package/dist/Editor/Toolbar/PopupTool/AddElements.js +1 -1
  21. package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/SelectTypography.js +1 -0
  22. package/dist/Editor/Toolbar/PopupTool/PopperHeader.js +23 -10
  23. package/dist/Editor/Toolbar/PopupTool/PopupToolStyle.js +21 -6
  24. package/dist/Editor/Toolbar/PopupTool/TextFormat.js +5 -3
  25. package/dist/Editor/Toolbar/PopupTool/index.js +14 -14
  26. package/dist/Editor/Toolbar/Toolbar.js +9 -0
  27. package/dist/Editor/Toolbar/toolbarGroups.js +9 -1
  28. package/dist/Editor/common/Icon.js +12 -3
  29. package/dist/Editor/common/Shorthands/elements.js +0 -1
  30. package/dist/Editor/common/iconslist.js +72 -0
  31. package/dist/Editor/hooks/useDragDom.js +66 -0
  32. package/dist/Editor/hooks/useMouseMove.js +4 -1
  33. package/dist/Editor/utils/SlateUtilityFunctions.js +5 -5
  34. package/dist/Editor/utils/customHooks/useResize.js +2 -2
  35. package/dist/Editor/utils/embedScript.js +20 -0
  36. package/dist/Editor/utils/events.js +67 -14
  37. package/dist/Editor/utils/helper.js +8 -1
  38. package/package.json +1 -1
@@ -165,7 +165,15 @@ export const toolbarGroups = [[{
165
165
  format: "video",
166
166
  type: "embed",
167
167
  group: "elements"
168
- }, {
168
+ },
169
+ // {
170
+ // id: 49,
171
+ // lbT: "embedScript",
172
+ // format: "embedScript",
173
+ // type: "embedScript",
174
+ // group: "elements",
175
+ // },
176
+ {
169
177
  id: 45,
170
178
  format: "topbanner",
171
179
  type: "topbanner",
@@ -1,13 +1,13 @@
1
1
  import React from "react";
2
2
  import { MdFormatQuote, MdFormatAlignLeft, MdFormatAlignCenter, MdFormatAlignRight, MdFormatListNumbered, MdFormatListBulleted, MdAdd, MdArrowForward, MdEmojiEmotions, MdOutlinePermMedia } from "react-icons/md";
3
- import { BsTypeH1, BsTypeH2, BsTypeH3, BsCameraVideoFill, BsArrowBarRight, BsArrowBarLeft, BsFillMenuButtonWideFill } from "react-icons/bs";
3
+ import { BsTypeH1, BsTypeH2, BsTypeH3, BsCameraVideoFill, BsArrowBarRight, BsArrowBarLeft, BsFillMenuButtonWideFill, BsCodeSlash } from "react-icons/bs";
4
4
  import { FaSuperscript, FaSubscript } from "react-icons/fa";
5
5
  import { FcAddRow, FcAddColumn } from "react-icons/fc";
6
6
  import { AiFillEdit, AiOutlineInsertRowBelow, AiOutlineInsertRowRight, AiOutlineDelete, AiFillTag, AiOutlineUpload, AiOutlineArrowsAlt, AiOutlineInsertRowAbove, AiOutlineInsertRowLeft, AiFillHtml5 } from "react-icons/ai";
7
7
  import { SiLatex } from "react-icons/si";
8
8
  import { RiDeleteColumn, RiDeleteRow } from "react-icons/ri";
9
9
  import { IoIosImage } from "react-icons/io";
10
- import { GridIcon, AccordionIcon, SignatureIcon, ButtonIcon, Carousal, FormIcon, BoldIcon, FontFamilyIcon, FontSizeIcon, ImageIcon, ItalicIcon, LinkIcon, StrikethroughIcon, TableIcon, UnderLineIcon, VideoIcon, CheckboxIcon, AppHeader, MoreHorizontal, UploadImage, DocsUpload, LeftArrow, RightArrow, CheckListButton, CheckListButtonActive, ExcelIcon, CsvIcon, DividerIcon } from "./iconslist";
10
+ import { GridIcon, AccordionIcon, SignatureIcon, ButtonIcon, Carousal, FormIcon, BoldIcon, FontFamilyIcon, FontSizeIcon, ImageIcon, ItalicIcon, LinkIcon, StrikethroughIcon, TableIcon, UnderLineIcon, VideoIcon, CheckboxIcon, AppHeader, MoreHorizontal, UploadImage, DocsUpload, LeftArrow, RightArrow, CheckListButton, CheckListButtonActive, ExcelIcon, CsvIcon, DividerIcon, CloseIcon, SearchIcon, ExpandIcon } from "./iconslist";
11
11
  import ArrowRightIcon from "@mui/icons-material/ArrowRight";
12
12
  import ArrowDropDownIcon from "@mui/icons-material/ArrowDropDown";
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -202,7 +202,16 @@ const iconList = {
202
202
  checkListButtonActive: /*#__PURE__*/_jsx(CheckListButtonActive, {}),
203
203
  excelIcon: /*#__PURE__*/_jsx(ExcelIcon, {}),
204
204
  csvIcon: /*#__PURE__*/_jsx(CsvIcon, {}),
205
- divider: /*#__PURE__*/_jsx(DividerIcon, {})
205
+ divider: /*#__PURE__*/_jsx(DividerIcon, {}),
206
+ SearchIcon: /*#__PURE__*/_jsx(SearchIcon, {}),
207
+ expandIcon: /*#__PURE__*/_jsx(ExpandIcon, {}),
208
+ closeIcon: /*#__PURE__*/_jsx(CloseIcon, {}),
209
+ embedScript: /*#__PURE__*/_jsx(BsCodeSlash, {
210
+ size: 20,
211
+ style: {
212
+ fill: "#64748B"
213
+ }
214
+ })
206
215
  };
207
216
  const Icon = props => {
208
217
  const {
@@ -9,7 +9,6 @@ import { toggleBlock } from "../../utils/SlateUtilityFunctions";
9
9
  import { TableUtil } from "../../utils/table";
10
10
  import Icon from "../Icon";
11
11
  import EmojiButton from "../../Elements/Emoji/EmojiButton";
12
- import DividerButton from "../../Elements/Divider/DividerButton";
13
12
  import { insertDivider } from "../../utils/divider";
14
13
  import { jsx as _jsx } from "react/jsx-runtime";
15
14
  const ELEMENTS_LIST = [{
@@ -1673,4 +1673,76 @@ export const CsvIcon = () => /*#__PURE__*/_jsxs("svg", {
1673
1673
  d: "M10.1788 20.5847H10.9753C10.9475 20.8284 10.8559 21.0604 10.7098 21.2573C10.5697 21.4397 10.3875 21.5855 10.1788 21.6821C9.9552 21.7844 9.71217 21.8373 9.46631 21.837C9.23734 21.8459 9.00918 21.805 8.79756 21.7171C8.58593 21.6293 8.39588 21.4965 8.24052 21.3281C7.91249 20.9659 7.74073 20.4888 7.7626 20.0006C7.74301 19.5143 7.91093 19.039 8.23167 18.673C8.37983 18.5042 8.56321 18.37 8.76889 18.2797C8.97456 18.1895 9.19753 18.1455 9.42206 18.1508C9.64785 18.1457 9.87206 18.1898 10.0791 18.2799C10.2862 18.3701 10.4712 18.5042 10.6213 18.673C10.8099 18.8938 10.9313 19.1641 10.9709 19.4518H10.1788C10.1395 19.2957 10.0472 19.158 9.91768 19.0624C9.77323 18.9681 9.60336 18.9202 9.43091 18.9252C9.30533 18.9217 9.18061 18.9471 9.06632 18.9992C8.95203 19.0514 8.8512 19.129 8.77155 19.2261C8.59958 19.4467 8.51173 19.7212 8.52374 20.0006C8.51183 20.2814 8.60313 20.5569 8.7804 20.775C8.86139 20.8714 8.96321 20.9482 9.07819 20.9996C9.19317 21.0509 9.31832 21.0755 9.44418 21.0715C9.6028 21.0807 9.76013 21.0382 9.89257 20.9505C10.025 20.8627 10.1254 20.7344 10.1788 20.5847ZM11.6612 20.7174H12.3914C12.4223 20.8647 12.507 20.9953 12.6289 21.0836C12.7507 21.1719 12.9011 21.2118 13.0507 21.1954C13.1892 21.2025 13.3261 21.1636 13.4402 21.0847C13.4868 21.0509 13.5244 21.0062 13.5499 20.9546C13.5753 20.9029 13.5878 20.8458 13.5862 20.7882C13.5903 20.7117 13.5686 20.636 13.5244 20.5734C13.4803 20.5108 13.4163 20.4649 13.3428 20.4431C13.3103 20.4431 13.1628 20.3988 12.9003 20.3103C12.6226 20.2507 12.3565 20.146 12.1126 20.0006C11.9949 19.9147 11.9001 19.8011 11.8368 19.6699C11.7735 19.5387 11.7436 19.3938 11.7497 19.2483C11.7437 19.1007 11.7703 18.9535 11.8277 18.8174C11.8851 18.6812 11.9718 18.5594 12.0816 18.4606C12.3279 18.2522 12.6446 18.1461 12.9667 18.1641C13.2843 18.152 13.5966 18.2488 13.8517 18.4385C13.9632 18.52 14.0542 18.6265 14.1172 18.7494C14.1802 18.8724 14.2135 19.0083 14.2146 19.1465H13.4756C13.452 19.036 13.3871 18.9387 13.2941 18.8745C13.2012 18.8103 13.0872 18.7842 12.9755 18.8013C12.8543 18.7955 12.7346 18.8297 12.6348 18.8987C12.5939 18.9286 12.5609 18.968 12.5386 19.0135C12.5162 19.0589 12.5052 19.1091 12.5064 19.1598C12.5032 19.2161 12.5165 19.2721 12.5448 19.3209C12.5732 19.3697 12.6152 19.4091 12.6657 19.4341C12.8434 19.5084 13.029 19.5619 13.2189 19.5934C13.4646 19.6346 13.7013 19.7184 13.9181 19.8413C14.0591 19.9314 14.1741 20.0568 14.2517 20.205C14.3293 20.3533 14.3669 20.5192 14.3606 20.6865C14.3679 20.8731 14.3255 21.0584 14.2376 21.2233C14.1498 21.3881 14.0196 21.5266 13.8605 21.6246C13.61 21.7706 13.3227 21.8412 13.033 21.8282C12.8135 21.8476 12.5925 21.8121 12.3901 21.7248C12.1877 21.6375 12.0102 21.5012 11.8736 21.3281C11.7519 21.146 11.6787 20.9358 11.6612 20.7174ZM16.0466 21.7706L14.719 18.2305H15.5111L16.3741 20.6201L17.1131 18.2305H17.8875L16.7148 21.7706H16.0466Z",
1674
1674
  fill: "white"
1675
1675
  })]
1676
+ });
1677
+ export const CloseIcon = () => /*#__PURE__*/_jsxs("svg", {
1678
+ width: "20",
1679
+ height: "20",
1680
+ viewBox: "0 0 20 20",
1681
+ fill: "none",
1682
+ xmlns: "http://www.w3.org/2000/svg",
1683
+ children: [/*#__PURE__*/_jsx("path", {
1684
+ d: "M14.1245 5.875L5.87493 14.1246",
1685
+ stroke: "#64748B",
1686
+ strokeWidth: "1.5",
1687
+ strokeLinecap: "round",
1688
+ strokeLinejoin: "round"
1689
+ }), /*#__PURE__*/_jsx("path", {
1690
+ d: "M5.875 5.875L14.1246 14.1246",
1691
+ stroke: "#64748B",
1692
+ strokeWidth: "1.5",
1693
+ strokeLinecap: "round",
1694
+ strokeLinejoin: "round"
1695
+ })]
1696
+ });
1697
+ export const SearchIcon = () => /*#__PURE__*/_jsxs("svg", {
1698
+ width: "18",
1699
+ height: "18",
1700
+ viewBox: "0 0 18 18",
1701
+ fill: "none",
1702
+ xmlns: "http://www.w3.org/2000/svg",
1703
+ children: [/*#__PURE__*/_jsx("path", {
1704
+ d: "M7.95971 15.2213C11.8035 15.2213 14.9194 12.0377 14.9194 8.11065C14.9194 4.18355 11.8035 1 7.95971 1C4.11597 1 1 4.18355 1 8.11065C1 12.0377 4.11597 15.2213 7.95971 15.2213Z",
1705
+ stroke: "#64748B",
1706
+ strokeWidth: "1.5",
1707
+ strokeLinecap: "round",
1708
+ strokeLinejoin: "round"
1709
+ }), /*#__PURE__*/_jsx("path", {
1710
+ d: "M17.0004 17.0006L13.5205 13.4453",
1711
+ stroke: "#64748B",
1712
+ strokeWidth: "1.5",
1713
+ strokeLinecap: "round",
1714
+ strokeLinejoin: "round"
1715
+ })]
1716
+ });
1717
+ export const ExpandIcon = () => /*#__PURE__*/_jsxs("svg", {
1718
+ width: "16",
1719
+ height: "16",
1720
+ viewBox: "0 0 16 16",
1721
+ fill: "none",
1722
+ xmlns: "http://www.w3.org/2000/svg",
1723
+ children: [/*#__PURE__*/_jsx("path", {
1724
+ d: "M14 6V2H10",
1725
+ stroke: "#64748B",
1726
+ strokeWidth: "1.5",
1727
+ strokeLinecap: "round",
1728
+ strokeLinejoin: "round"
1729
+ }), /*#__PURE__*/_jsx("path", {
1730
+ d: "M2 10V14H6",
1731
+ stroke: "#64748B",
1732
+ strokeWidth: "1.5",
1733
+ strokeLinecap: "round",
1734
+ strokeLinejoin: "round"
1735
+ }), /*#__PURE__*/_jsx("path", {
1736
+ d: "M14 2L9 7",
1737
+ stroke: "#64748B",
1738
+ strokeWidth: "1.5",
1739
+ strokeLinecap: "round",
1740
+ strokeLinejoin: "round"
1741
+ }), /*#__PURE__*/_jsx("path", {
1742
+ d: "M7 9L2 14",
1743
+ stroke: "#64748B",
1744
+ strokeWidth: "1.5",
1745
+ strokeLinecap: "round",
1746
+ strokeLinejoin: "round"
1747
+ })]
1676
1748
  });
@@ -0,0 +1,66 @@
1
+ import { useEffect, useState } from "react";
2
+ const ePos = {
3
+ x: 0,
4
+ y: 0
5
+ };
6
+ const useDragDom = props => {
7
+ const {
8
+ refDom
9
+ } = props || {};
10
+ const [event, setEvent] = useState("");
11
+ const [delta, setDelta] = useState({
12
+ x: 0,
13
+ y: 0
14
+ });
15
+ useEffect(() => {
16
+ addListener();
17
+ return () => {
18
+ removeListener();
19
+ };
20
+ }, [refDom]);
21
+ const onMouseDown = e => {
22
+ ePos.x = e.x;
23
+ ePos.y = e.y;
24
+ setDelta({
25
+ x: 0,
26
+ y: 0
27
+ });
28
+ setEvent("start");
29
+ };
30
+ const onMouseMove = e => {
31
+ if (ePos.x) {
32
+ setDelta({
33
+ x: e.x - ePos.x,
34
+ y: e.y - ePos.y
35
+ });
36
+ }
37
+ };
38
+ const onMouseUp = e => {
39
+ setEvent("end");
40
+ ePos.x = 0;
41
+ ePos.y = 0;
42
+ if (event === "start") {
43
+ setDelta({
44
+ x: e.x - ePos.x,
45
+ y: e.y - ePos.y
46
+ });
47
+ }
48
+ };
49
+ const onClear = () => {
50
+ setDelta({
51
+ x: 0,
52
+ y: 0
53
+ });
54
+ };
55
+ const addListener = () => {
56
+ refDom?.addEventListener("pointerdown", onMouseDown);
57
+ refDom?.addEventListener("pointermove", onMouseMove);
58
+ document.addEventListener("pointerup", onMouseUp);
59
+ };
60
+ const removeListener = () => {
61
+ refDom?.removeEventListener("pointerdown", onMouseDown);
62
+ document.removeEventListener("pointerup", onMouseUp);
63
+ };
64
+ return [event, delta, onClear];
65
+ };
66
+ export default useDragDom;
@@ -24,6 +24,7 @@ export const EditorProvider = ({
24
24
  const [event] = useMouseMove();
25
25
  const [previous, setPrevious] = useState("");
26
26
  const [drop, setDrop] = useState(0);
27
+ const [selectedPath, setSelectedPath] = useState(null);
27
28
  const path = event?.target?.getAttribute("data-path");
28
29
  const onDrop = () => {
29
30
  setDrop(drop + 1);
@@ -45,7 +46,9 @@ export const EditorProvider = ({
45
46
  ...(value || {}),
46
47
  onDrop: onDrop,
47
48
  drop,
48
- theme: theme
49
+ theme: theme,
50
+ selectedPath: selectedPath,
51
+ setSelectedPath: setSelectedPath
49
52
  },
50
53
  children: children
51
54
  });
@@ -40,6 +40,7 @@ import Variables from "../Elements/Variables/Variable";
40
40
  import insertNewLine from "./insertNewLine";
41
41
  import Divider from "../Elements/Divider/Divider";
42
42
  import { getBorderColor } from "./helper";
43
+ import Code from "../Elements/EmbedScript/Code";
43
44
  import { jsx as _jsx } from "react/jsx-runtime";
44
45
  const alignment = ["alignLeft", "alignRight", "alignCenter"];
45
46
  const list_types = ["orderedList", "unorderedList"];
@@ -289,9 +290,6 @@ export const getBlock = props => {
289
290
  });
290
291
  case "alignLeft":
291
292
  return /*#__PURE__*/_jsx("div", {
292
- style: {
293
- listStylePosition: "inside"
294
- },
295
293
  ...attributes,
296
294
  ...element.attr,
297
295
  children: children
@@ -301,7 +299,6 @@ export const getBlock = props => {
301
299
  style: {
302
300
  display: "flex",
303
301
  alignItems: "center",
304
- listStylePosition: "inside",
305
302
  flexDirection: "column",
306
303
  textAlign: "center"
307
304
  },
@@ -314,7 +311,6 @@ export const getBlock = props => {
314
311
  style: {
315
312
  display: "flex",
316
313
  alignItems: "flex-end",
317
- listStylePosition: "inside",
318
314
  flexDirection: "column",
319
315
  textAlign: "right"
320
316
  },
@@ -498,6 +494,10 @@ export const getBlock = props => {
498
494
  return /*#__PURE__*/_jsx(Divider, {
499
495
  ...props
500
496
  });
497
+ case "embedScript":
498
+ return /*#__PURE__*/_jsx(Code, {
499
+ ...props
500
+ });
501
501
  default:
502
502
  return /*#__PURE__*/_jsx(SimpleText, {
503
503
  ...props,
@@ -26,8 +26,8 @@ const useResize = ({
26
26
  const onLoad = defaultSize => {
27
27
  setSize({
28
28
  widthInPercent: 100,
29
- height: isGrid ? height : 300,
30
- ...defaultSize
29
+ height: height,
30
+ ...defaultSize[device]
31
31
  });
32
32
  };
33
33
  const onMouseDown = () => {
@@ -0,0 +1,20 @@
1
+ import { Transforms } from "slate";
2
+ import insertNewLine from "./insertNewLine";
3
+ export const createEmbedScript = embedData => ({
4
+ type: "embedScript",
5
+ embedData: embedData,
6
+ children: [{
7
+ text: " "
8
+ }]
9
+ });
10
+ export const insertEmbedScript = (editor, embedData) => {
11
+ try {
12
+ const embed = createEmbedScript(embedData);
13
+ Transforms.insertNodes(editor, embed, {
14
+ at: editor.selection.anchor.path
15
+ });
16
+ insertNewLine(editor);
17
+ } catch (err) {
18
+ console.log(err);
19
+ }
20
+ };
@@ -2,6 +2,7 @@ import { Editor, Transforms, Element, Node, Path } from "slate";
2
2
  import { toggleBlock } from "./SlateUtilityFunctions";
3
3
  import insertNewLine from "./insertNewLine";
4
4
  import { insertAccordion } from "./accordion";
5
+ import { isListItem } from "./helper";
5
6
  const HOTKEYS = {
6
7
  b: "bold",
7
8
  i: "italic",
@@ -87,18 +88,27 @@ export const indentation = props => {
87
88
  } = editor;
88
89
  if (selection) {
89
90
  const [listItemNode] = Editor.nodes(editor, {
90
- match: n => n.type === "list-item"
91
+ match: n => n.type === "list-item" || n.type === "check-list-item"
91
92
  });
92
93
  if (listItemNode) {
93
- const [, listItemPath] = listItemNode;
94
- const [parentNode] = Editor.parent(editor, listItemPath);
95
- const type = parentNode.type;
96
- Transforms.wrapNodes(editor, {
97
- type,
98
- children: []
99
- }, {
100
- at: listItemPath
101
- });
94
+ const [listItem, listItemPath] = listItemNode;
95
+ if (listItem.type === "check-list-item") {
96
+ Transforms.wrapNodes(editor, {
97
+ type: listItem.type,
98
+ children: [{
99
+ text: ''
100
+ }]
101
+ });
102
+ } else {
103
+ const [parentNode] = Editor.parent(editor, listItemPath);
104
+ const type = parentNode.type;
105
+ Transforms.wrapNodes(editor, {
106
+ type,
107
+ children: []
108
+ }, {
109
+ at: listItemPath
110
+ });
111
+ }
102
112
  }
103
113
  }
104
114
  } catch (err) {
@@ -113,8 +123,12 @@ export const escapeEvent = props => {
113
123
  const list_types = ["orderedList", "unorderedList", "check-list-item"];
114
124
  const parentPath = Path.ancestors(editor.selection.anchor.path);
115
125
  const parentNodes = parentPath.filter(m => m.length).map(m => Node.get(editor, m));
126
+ const ele = isListItem(editor);
127
+ const eleType = ele[0]?.type;
116
128
  if (parentNodes.length === 2 && parentNodes[1]?.type === "list-item") {
117
129
  toggleBlock(editor, "list-item", editor.selection);
130
+ } else if (eleType === "check-list-item") {
131
+ checkListEnterEvent(editor, eleType);
118
132
  } else {
119
133
  Transforms.unwrapNodes(editor, {
120
134
  match: n => list_types.includes(!Editor.isEditor(n) && Element.isElement(n) && n.type),
@@ -125,8 +139,38 @@ export const escapeEvent = props => {
125
139
  console.log(err);
126
140
  }
127
141
  };
128
- export const enterEvent = (e, editor, ele) => {
142
+ const checkListEnterEvent = (editor, type) => {
143
+ const selectionPath = editor?.selection?.anchor?.path;
144
+ const ancestors = Path.ancestors(selectionPath);
145
+ const parentPath = ancestors[ancestors?.length - 2];
146
+ if (parentPath?.length) {
147
+ const lastPathIndex = parentPath.length - 1;
148
+ const otherPaths = parentPath.slice(0, lastPathIndex);
149
+ const nextChildrenPath = parentPath[lastPathIndex] + 1;
150
+ const newPath = [...otherPaths, nextChildrenPath];
151
+ Transforms.insertNodes(editor, {
152
+ type: "check-list-item",
153
+ children: [{
154
+ text: ''
155
+ }]
156
+ }, {
157
+ at: newPath
158
+ });
159
+ Transforms.removeNodes(editor);
160
+ // focus on the end of the line
161
+ Transforms.move(editor, {
162
+ distance: 1,
163
+ unit: 'line'
164
+ });
165
+ } else {
166
+ toggleBlock(editor, type);
167
+ insertNewLine(editor);
168
+ }
169
+ };
170
+ export const enterEvent = (e, editor) => {
129
171
  try {
172
+ const ele = isListItem(editor);
173
+
130
174
  // on shift enter break line in same node
131
175
  if (e.shiftKey) {
132
176
  e.preventDefault();
@@ -138,11 +182,20 @@ export const enterEvent = (e, editor, ele) => {
138
182
  const text = Node.string(ele[0]);
139
183
  switch (type) {
140
184
  case "list-item":
141
- case "check-list-item":
142
185
  if (!text) {
143
186
  e.preventDefault();
144
- toggleBlock(editor, type);
145
- insertNewLine(editor);
187
+ escapeEvent({
188
+ editor
189
+ });
190
+ }
191
+ break;
192
+ case "check-list-item":
193
+ const selectionPath = editor?.selection?.anchor?.path;
194
+ const currEle = Node.parent(editor, selectionPath);
195
+ const currEleText = Node.string(currEle);
196
+ if (!currEleText) {
197
+ e.preventDefault();
198
+ checkListEnterEvent(editor, type);
146
199
  }
147
200
  break;
148
201
  case "accordion-summary":
@@ -1,4 +1,4 @@
1
- import { Editor, Node, Transforms } from "slate";
1
+ import { Editor, Node, Transforms, Element } from "slate";
2
2
  import { ReactEditor } from "slate-react";
3
3
  export const windowVar = {};
4
4
  export const formatDate = (date, format = "MM/DD/YYYY") => {
@@ -142,4 +142,11 @@ export const handleInsertLastElement = (event, editor) => {
142
142
  }
143
143
  ReactEditor.focus(editor);
144
144
  }
145
+ };
146
+ export const isListItem = editor => {
147
+ const format = ["list-item", "check-list-item", "accordion-summary"];
148
+ const [node] = Editor.nodes(editor, {
149
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && format.indexOf(n.type) > -1
150
+ });
151
+ return node;
145
152
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "2.1.4",
3
+ "version": "2.1.6",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"