@flozy/editor 1.5.9 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. package/dist/Editor/CommonEditor.js +195 -94
  2. package/dist/Editor/DialogWrapper.js +3 -0
  3. package/dist/Editor/Editor.css +211 -50
  4. package/dist/Editor/Elements/Accordion/Accordion.js +0 -1
  5. package/dist/Editor/Elements/Accordion/AccordionButton.js +13 -12
  6. package/dist/Editor/Elements/Accordion/AccordionSummary.js +0 -1
  7. package/dist/Editor/Elements/AppHeader/AppHeader.js +136 -133
  8. package/dist/Editor/Elements/AppHeader/AppHeaderPopup.js +4 -2
  9. package/dist/Editor/Elements/Button/ButtonToolIcon.js +10 -9
  10. package/dist/Editor/Elements/Button/EditorButton.js +8 -24
  11. package/dist/Editor/Elements/Carousel/Carousel.js +47 -28
  12. package/dist/Editor/Elements/Carousel/CarouselButton.js +7 -8
  13. package/dist/Editor/Elements/Color Picker/ColorButtons.js +133 -0
  14. package/dist/Editor/Elements/Color Picker/ColorPicker.js +49 -58
  15. package/dist/Editor/Elements/Color Picker/Styles.js +51 -0
  16. package/dist/Editor/Elements/Color Picker/defaultColors.js +1 -1
  17. package/dist/Editor/Elements/Embed/Embed.js +35 -126
  18. package/dist/Editor/Elements/Embed/Image.js +24 -7
  19. package/dist/Editor/Elements/Embed/Video.js +21 -6
  20. package/dist/Editor/Elements/Emoji/EmojiButton.js +73 -0
  21. package/dist/Editor/Elements/Emoji/EmojiPicker.js +0 -0
  22. package/dist/Editor/Elements/Form/Form.js +24 -13
  23. package/dist/Editor/Elements/Form/FormButton.js +11 -9
  24. package/dist/Editor/Elements/Form/FormElements/FormText.js +4 -2
  25. package/dist/Editor/Elements/Form/FormElements/FormTextArea.js +3 -2
  26. package/dist/Editor/Elements/Form/FormField.js +7 -1
  27. package/dist/Editor/Elements/Grid/Grid.js +143 -47
  28. package/dist/Editor/Elements/Grid/GridButton.js +52 -29
  29. package/dist/Editor/Elements/Grid/GridItem.js +32 -21
  30. package/dist/Editor/Elements/Grid/Styles.js +11 -0
  31. package/dist/Editor/Elements/InlineIcon/InlineIcon.js +0 -1
  32. package/dist/Editor/Elements/List/CheckList.js +57 -0
  33. package/dist/Editor/Elements/List/CheckListButton.js +24 -0
  34. package/dist/Editor/Elements/NewLine/NewLineButton.js +14 -14
  35. package/dist/Editor/Elements/PageSettings/PageSettings.js +4 -2
  36. package/dist/Editor/Elements/PageSettings/PageSettingsButton.js +17 -62
  37. package/dist/Editor/Elements/PageSettings/PageSettingsPopup.js +1 -1
  38. package/dist/Editor/Elements/Signature/Signature.js +9 -3
  39. package/dist/Editor/Elements/Signature/SignatureButton.js +10 -9
  40. package/dist/Editor/Elements/Signature/SignaturePopup.js +42 -6
  41. package/dist/Editor/Elements/SimpleText.js +62 -0
  42. package/dist/Editor/Elements/Table/Styles.js +66 -0
  43. package/dist/Editor/Elements/Table/Table.js +33 -16
  44. package/dist/Editor/Elements/Table/TableCell.js +54 -24
  45. package/dist/Editor/Elements/Table/TableSelector.js +13 -15
  46. package/dist/Editor/Elements/Table/table.css +0 -10
  47. package/dist/Editor/Elements/TopBanner/Styles.js +33 -0
  48. package/dist/Editor/Elements/TopBanner/TopBanner.js +106 -0
  49. package/dist/Editor/Elements/TopBanner/TopBannerButton.js +47 -0
  50. package/dist/Editor/Styles/EditorStyles.js +50 -0
  51. package/dist/Editor/Toolbar/FormatTools/Autocomplete.js +0 -2
  52. package/dist/Editor/Toolbar/FormatTools/Dropdown.js +8 -3
  53. package/dist/Editor/Toolbar/FormatTools/FontFamilyDropdown.js +63 -0
  54. package/dist/Editor/Toolbar/FormatTools/FontSize.js +112 -0
  55. package/dist/Editor/Toolbar/FormatTools/TextSize.js +13 -3
  56. package/dist/Editor/Toolbar/FormatTools/index.js +4 -1
  57. package/dist/Editor/Toolbar/Mini/MiniToolbar.js +101 -0
  58. package/dist/Editor/Toolbar/Mini/Options/Options.js +17 -0
  59. package/dist/Editor/Toolbar/Mini/Styles.js +30 -0
  60. package/dist/Editor/Toolbar/PopupTool/AddElements.js +32 -0
  61. package/dist/Editor/Toolbar/PopupTool/AddTemplates.js +115 -0
  62. package/dist/Editor/Toolbar/PopupTool/PopperHeader.js +65 -0
  63. package/dist/Editor/Toolbar/PopupTool/PopupToolStyle.js +160 -6
  64. package/dist/Editor/Toolbar/PopupTool/TextFormat.js +263 -80
  65. package/dist/Editor/Toolbar/PopupTool/index.js +50 -85
  66. package/dist/Editor/Toolbar/Toolbar.js +189 -129
  67. package/dist/Editor/Toolbar/styles.css +136 -18
  68. package/dist/Editor/Toolbar/toolbarGroups.js +94 -34
  69. package/dist/Editor/assets/svg/AddElementIcon.js +29 -0
  70. package/dist/Editor/assets/svg/AddTemplateIcon.js +29 -0
  71. package/dist/Editor/assets/svg/TextIcon.js +29 -0
  72. package/dist/Editor/common/Icon.js +54 -5
  73. package/dist/Editor/common/ImageList.js +75 -0
  74. package/dist/Editor/common/ImageSelector/ImageSelector.js +117 -0
  75. package/dist/Editor/common/ImageSelector/Options/AddLink.js +44 -0
  76. package/dist/Editor/common/ImageSelector/Options/ChooseAssets.js +39 -0
  77. package/dist/Editor/common/ImageSelector/Options/Upload.js +30 -0
  78. package/dist/Editor/common/ImageSelector/Styles.js +41 -0
  79. package/dist/Editor/common/ImageUploader.js +94 -0
  80. package/dist/Editor/common/MentionsPopup/ElementsListCard.js +66 -0
  81. package/dist/Editor/common/MentionsPopup/MentionsListCard.js +70 -0
  82. package/dist/Editor/common/MentionsPopup/Styles.js +68 -0
  83. package/dist/Editor/common/MentionsPopup/index.js +129 -0
  84. package/dist/Editor/common/Shorthands/elements.js +191 -0
  85. package/dist/Editor/common/Shorthands/index.js +7 -0
  86. package/dist/Editor/common/Shorthands/mentions.js +8 -0
  87. package/dist/Editor/common/StyleBuilder/appHeaderStyle.js +5 -5
  88. package/dist/Editor/common/StyleBuilder/buttonStyle.js +1 -1
  89. package/dist/Editor/common/StyleBuilder/embedImageStyle.js +15 -2
  90. package/dist/Editor/common/StyleBuilder/embedVideoStyle.js +8 -0
  91. package/dist/Editor/common/StyleBuilder/fieldTypes/alignment.js +2 -3
  92. package/dist/Editor/common/StyleBuilder/fieldTypes/backgroundImage.js +23 -35
  93. package/dist/Editor/common/StyleBuilder/fieldTypes/buttonLink.js +3 -20
  94. package/dist/Editor/common/StyleBuilder/fieldTypes/fontSize.js +95 -0
  95. package/dist/Editor/common/StyleBuilder/fieldTypes/icons.js +14 -2
  96. package/dist/Editor/common/StyleBuilder/fieldTypes/index.js +3 -1
  97. package/dist/Editor/common/StyleBuilder/fieldTypes/menusArray.js +0 -1
  98. package/dist/Editor/common/StyleBuilder/fieldTypes/textOptions.js +3 -2
  99. package/dist/Editor/common/StyleBuilder/index.js +0 -1
  100. package/dist/Editor/common/StyleBuilder/tableStyle.js +9 -5
  101. package/dist/Editor/common/ToolbarIcon.js +43 -0
  102. package/dist/Editor/common/Uploader.js +35 -61
  103. package/dist/Editor/common/iconslist.js +46 -1
  104. package/dist/Editor/helper/index.js +0 -1
  105. package/dist/Editor/hooks/useDrag.js +2 -2
  106. package/dist/Editor/hooks/useMentions.js +104 -17
  107. package/dist/Editor/hooks/useMouseMove.js +53 -0
  108. package/dist/Editor/hooks/useScroll.js +26 -0
  109. package/dist/Editor/plugins/withEmbeds.js +12 -0
  110. package/dist/Editor/service/fileupload.js +2 -2
  111. package/dist/Editor/utils/SlateUtilityFunctions.js +61 -9
  112. package/dist/Editor/utils/button.js +2 -1
  113. package/dist/Editor/utils/carousel.js +5 -2
  114. package/dist/Editor/utils/carouselItem.js +2 -2
  115. package/dist/Editor/utils/customHooks/useResize.js +2 -3
  116. package/dist/Editor/utils/customHooks/useTableResize.js +2 -1
  117. package/dist/Editor/utils/embed.js +25 -8
  118. package/dist/Editor/utils/emoji.js +8 -0
  119. package/dist/Editor/utils/events.js +49 -12
  120. package/dist/Editor/utils/form.js +3 -9
  121. package/dist/Editor/utils/formfield.js +2 -1
  122. package/dist/Editor/utils/grid.js +44 -8
  123. package/dist/Editor/utils/gridItem.js +4 -3
  124. package/dist/Editor/utils/insertNewLine.js +12 -0
  125. package/dist/Editor/utils/mentions.js +14 -10
  126. package/dist/Editor/utils/pageSettings.js +67 -0
  127. package/dist/Editor/utils/signature.js +6 -8
  128. package/dist/Editor/utils/table.js +79 -18
  129. package/dist/Editor/utils/topBanner.js +58 -0
  130. package/package.json +6 -2
  131. package/dist/Editor/common/MentionsPopup.js +0 -56
@@ -1,5 +1,5 @@
1
- import { Transforms, Editor } from "slate";
2
- import { insertMention } from "./mentions";
1
+ import { Editor, Transforms, Element, Node, Path } from "slate";
2
+ import { toggleBlock } from "./SlateUtilityFunctions";
3
3
  const HOTKEYS = {
4
4
  b: "bold",
5
5
  i: "italic",
@@ -11,11 +11,10 @@ export const mentionsEvent = props => {
11
11
  mentions,
12
12
  setMentions,
13
13
  chars,
14
- editor
14
+ mentionsRef
15
15
  } = props;
16
16
  const {
17
- index,
18
- target
17
+ index
19
18
  } = mentions;
20
19
  switch (event.key) {
21
20
  case "ArrowDown":
@@ -37,18 +36,16 @@ export const mentionsEvent = props => {
37
36
  case "Tab":
38
37
  case "Enter":
39
38
  event.preventDefault();
40
- Transforms.select(editor, target);
41
- insertMention(editor, chars[index]);
42
- setMentions({
43
- ...mentions,
44
- target: null
45
- });
39
+ if (mentionsRef && mentionsRef?.current) {
40
+ mentionsRef?.current?.handleOnSelect(chars[index]);
41
+ }
46
42
  break;
47
43
  case "Escape":
48
44
  event.preventDefault();
49
45
  setMentions({
50
46
  ...mentions,
51
- target: null
47
+ target: null,
48
+ type: null
52
49
  });
53
50
  break;
54
51
  default:
@@ -73,4 +70,44 @@ export const commands = props => {
73
70
  Editor.addMark(editor, HOTKEYS[event.key], true);
74
71
  }
75
72
  }
73
+ };
74
+ export const indentation = props => {
75
+ const {
76
+ editor
77
+ } = props;
78
+ const {
79
+ selection
80
+ } = editor;
81
+ if (selection) {
82
+ const [listItemNode] = Editor.nodes(editor, {
83
+ match: n => n.type === "list-item"
84
+ });
85
+ if (listItemNode) {
86
+ const [, listItemPath] = listItemNode;
87
+ const [parentNode] = Editor.parent(editor, listItemPath);
88
+ const type = parentNode.type;
89
+ Transforms.wrapNodes(editor, {
90
+ type,
91
+ children: []
92
+ }, {
93
+ at: listItemPath
94
+ });
95
+ }
96
+ }
97
+ };
98
+ export const escapeEvent = props => {
99
+ const {
100
+ editor
101
+ } = props;
102
+ const list_types = ["orderedList", "unorderedList", "checkList"];
103
+ const parentPath = Path.ancestors(editor.selection.anchor.path);
104
+ const parentNodes = parentPath.filter(m => m.length).map(m => Node.get(editor, m));
105
+ if (parentNodes.length === 2 && parentNodes[1]?.type === "list-item") {
106
+ toggleBlock(editor, "list-item", editor.selection);
107
+ } else {
108
+ Transforms.unwrapNodes(editor, {
109
+ match: n => list_types.includes(!Editor.isEditor(n) && Element.isElement(n) && n.type),
110
+ split: true
111
+ });
112
+ }
76
113
  };
@@ -1,5 +1,6 @@
1
1
  import { Transforms } from "slate";
2
2
  import { formField } from "./formfield";
3
+ import insertNewLine from "./insertNewLine";
3
4
  export const insertForm = (editor, item) => {
4
5
  const grid = !item ? {
5
6
  type: "form",
@@ -18,15 +19,8 @@ export const insertForm = (editor, item) => {
18
19
  },
19
20
  children: [{
20
21
  ...formField()
21
- }, {
22
- text: ""
23
22
  }]
24
23
  } : item;
25
- const {
26
- selection
27
- } = editor;
28
- Transforms.insertNodes(editor, grid, {
29
- at: selection.focus.path
30
- });
31
- Transforms.move(editor);
24
+ Transforms.insertNodes(editor, grid);
25
+ insertNewLine(editor);
32
26
  };
@@ -9,7 +9,8 @@ export const formField = () => {
9
9
  children: [{
10
10
  text: ""
11
11
  }],
12
- bgColor: "rgba(255, 255, 255, 0)",
12
+ bgColor: "rgba(255, 255, 255, 1)",
13
+ borderColor: "#ccc",
13
14
  bannerSpacing: {
14
15
  left: 16,
15
16
  right: 16,
@@ -1,12 +1,48 @@
1
1
  import { Transforms } from "slate";
2
2
  import default_grid from "../Elements/Grid/templates/default_grid";
3
+ import insertNewLine from "./insertNewLine";
4
+ import { gridItem } from "./gridItem";
5
+ export const insertPlainGrid = count => {
6
+ const size = 12 / count;
7
+ const items = Array.from(Array(count).keys()).map(() => gridItem({
8
+ grid: size,
9
+ borderColor: "#ccc",
10
+ lockSpacing: true,
11
+ bannerSpacing: {
12
+ top: "16",
13
+ left: "16",
14
+ right: "16",
15
+ bottom: "16"
16
+ }
17
+ }));
18
+ return {
19
+ type: "grid",
20
+ grid: "container",
21
+ children: [...items],
22
+ alignment: {
23
+ flexDirection: "row"
24
+ },
25
+ lockSpacing: true,
26
+ bannerSpacing: {
27
+ top: "16",
28
+ left: "16",
29
+ right: "16",
30
+ bottom: "16"
31
+ }
32
+ };
33
+ };
3
34
  export const insertGrid = (editor, item, path) => {
4
- const grid = !item ? JSON.parse(default_grid) : item;
5
- const {
6
- selection
7
- } = editor;
8
- Transforms.insertNodes(editor, grid, {
9
- at: path || selection.focus.path,
10
- select: true
11
- });
35
+ try {
36
+ const grid = !item ? JSON.parse(default_grid) : item;
37
+ const {
38
+ selection
39
+ } = editor;
40
+ Transforms.insertNodes(editor, grid, {
41
+ at: path || selection.focus.path,
42
+ select: true
43
+ });
44
+ insertNewLine(editor);
45
+ } catch (err) {
46
+ console.log(err);
47
+ }
12
48
  };
@@ -1,15 +1,16 @@
1
1
  import { Transforms } from "slate";
2
- export const gridItem = () => {
2
+ export const gridItem = (props = {}) => {
3
3
  return {
4
4
  type: "grid-item",
5
5
  grid: 6,
6
6
  children: [{
7
7
  type: "paragraph",
8
8
  children: [{
9
- text: `About Us`
9
+ text: " "
10
10
  }]
11
11
  }],
12
- bgColor: "rgba(255, 255, 255, 0)"
12
+ bgColor: "rgba(255, 255, 255, 0)",
13
+ ...(props || {})
13
14
  };
14
15
  };
15
16
  export const insertGridItem = editor => {
@@ -0,0 +1,12 @@
1
+ import { Transforms } from "slate";
2
+ const insertNewLine = editor => {
3
+ Transforms.insertNodes(editor, {
4
+ type: "paragraph",
5
+ children: [{
6
+ text: ""
7
+ }]
8
+ }, {
9
+ at: [editor.children.length]
10
+ });
11
+ };
12
+ export default insertNewLine;
@@ -1,12 +1,16 @@
1
1
  import { Transforms } from "slate";
2
- export const insertMention = (editor, character) => {
3
- const mention = {
4
- type: "mention",
5
- character,
6
- children: [{
7
- text: ""
8
- }]
9
- };
10
- Transforms.insertNodes(editor, mention);
11
- Transforms.move(editor);
2
+ export const insertMention = (editor, character, type) => {
3
+ if (type === "mentions") {
4
+ const mention = {
5
+ type: "mention",
6
+ character,
7
+ children: [{
8
+ text: ""
9
+ }]
10
+ };
11
+ Transforms.insertNodes(editor, mention);
12
+ Transforms.move(editor);
13
+ } else if (type === "elements" && character && character.onInsert) {
14
+ character.onInsert(editor);
15
+ }
12
16
  };
@@ -0,0 +1,67 @@
1
+ import { Editor, Transforms, Element } from "slate";
2
+ export const getPageSettings = editor => {
3
+ try {
4
+ const [pageSettingsNode] = Editor.nodes(editor, {
5
+ at: [],
6
+ match: n => {
7
+ return !Editor.isEditor(n) && Element.isElement(n) && n.type === "page-settings";
8
+ }
9
+ });
10
+ if (pageSettingsNode && pageSettingsNode[0] && pageSettingsNode[1]) {
11
+ const [element, path] = pageSettingsNode;
12
+ return {
13
+ path,
14
+ element
15
+ };
16
+ } else {
17
+ return {
18
+ path: null,
19
+ element: {
20
+ pageProps: {
21
+ pageWidth: "fixed"
22
+ }
23
+ }
24
+ };
25
+ }
26
+ } catch (err) {
27
+ console.log(err);
28
+ return {
29
+ path: null,
30
+ element: {}
31
+ };
32
+ }
33
+ };
34
+ export const insertPageSettings = (editor, pageProps = {}) => {
35
+ Transforms.insertNodes(editor, [{
36
+ type: "page-settings",
37
+ pageProps: {
38
+ ...pageProps,
39
+ pageWidth: "fixed"
40
+ },
41
+ children: [{
42
+ text: ""
43
+ }]
44
+ }], {
45
+ at: [editor.children.length]
46
+ });
47
+ };
48
+ export const updatePageSettings = (editor, pageProps = {}) => {
49
+ try {
50
+ const {
51
+ path
52
+ } = getPageSettings(editor);
53
+ if (path) {
54
+ Transforms.setNodes(editor, {
55
+ pageProps: {
56
+ ...pageProps
57
+ }
58
+ }, {
59
+ at: path
60
+ });
61
+ } else {
62
+ insertPageSettings(editor, pageProps);
63
+ }
64
+ } catch (err) {
65
+ console.log(err);
66
+ }
67
+ };
@@ -1,4 +1,5 @@
1
1
  import { Transforms } from "slate";
2
+ import insertNewLine from "./insertNewLine";
2
3
  export const insertSignature = editor => {
3
4
  const signature = {
4
5
  type: "signature",
@@ -9,15 +10,12 @@ export const insertSignature = editor => {
9
10
  date: "" // YYYY-MM-DD
10
11
  },
11
12
 
12
- size: {
13
- height: 535,
14
- widthInPercent: 99.75490196078437,
15
- width: 1628.000000000001
16
- },
17
13
  children: [{
18
- text: ""
14
+ text: " "
19
15
  }]
20
16
  };
21
- Transforms.insertNodes(editor, signature);
22
- Transforms.move(editor);
17
+ Transforms.insertNodes(editor, signature, {
18
+ at: editor.selection.anchor.path
19
+ });
20
+ insertNewLine(editor);
23
21
  };
@@ -1,5 +1,6 @@
1
1
  import { Transforms, Editor, Range, Element, Path, Node } from "slate";
2
2
  import { ReactEditor } from "slate-react";
3
+ import insertNewLine from "./insertNewLine";
3
4
  const prefixKey = (obj, pk = "") => {
4
5
  return Object.keys(obj).reduce((a, b) => {
5
6
  a[`${pk}${b}`] = obj[b];
@@ -36,18 +37,11 @@ export class TableUtil {
36
37
  }, () => ""));
37
38
  const newTable = createTableNode(cellText, rows, columns);
38
39
  Transforms.insertNodes(this.editor, newTable, {
39
- // mode: "highest",
40
+ // to insert in current line
41
+ // at: this.editor.selection.anchor.path,
40
42
  });
41
- Transforms.insertNodes(this.editor, {
42
- type: "paragraph",
43
- children: [{
44
- text: ""
45
- }]
46
- }
47
- // { mode: "highest" }
48
- );
43
+ insertNewLine(this.editor);
49
44
  };
50
-
51
45
  removeTable = () => {
52
46
  Transforms.removeNodes(this.editor, {
53
47
  match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
@@ -64,7 +58,7 @@ export class TableUtil {
64
58
  const tableDOM = ReactEditor.toDOMNode(this.editor, tableNode[0]);
65
59
  return tableDOM;
66
60
  } catch (err) {
67
- console.log(err);
61
+ // console.log(err);
68
62
  }
69
63
  };
70
64
  getTotalWidth = (path, colCount = 0) => {
@@ -223,6 +217,21 @@ export class TableUtil {
223
217
  }, {
224
218
  at: currentCellPath
225
219
  });
220
+
221
+ // cell bg entire
222
+ if (cellProps?.entireBgColor) {
223
+ const {
224
+ rows
225
+ } = tableProps;
226
+ for (let r = 0; r < rows; r++) {
227
+ Transforms.setNodes(this.editor, {
228
+ ...cellProps,
229
+ entireBgColor: cellProps?.entireBgColor
230
+ }, {
231
+ at: [currentCellPath[0], r, currentCellPath[2]]
232
+ });
233
+ }
234
+ }
226
235
  }
227
236
  } catch (err) {
228
237
  console.log(err);
@@ -290,6 +299,61 @@ export class TableUtil {
290
299
  return null;
291
300
  }
292
301
  };
302
+ isCellSelected = selection => {
303
+ try {
304
+ if (!selection || Range.isCollapsed(selection) || Editor.string(this.editor, selection) === "") {
305
+ return false;
306
+ }
307
+ const [tableNode] = Editor.nodes(this.editor, {
308
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
309
+ });
310
+ const [, tableCellPath] = Editor.nodes(this.editor, {
311
+ at: selection,
312
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table-cell"
313
+ });
314
+ const {
315
+ anchor,
316
+ focus
317
+ } = this.editor.selection || {};
318
+ if (tableNode && tableNode[0] && tableCellPath && tableCellPath[1] && focus?.path) {
319
+ let startCell = anchor?.path;
320
+ let endCell = focus?.path;
321
+
322
+ // swap for reverse selection
323
+ if (startCell[1] > endCell[1]) {
324
+ startCell = focus?.path;
325
+ endCell = anchor?.path;
326
+ } else if (startCell[2] > endCell[2]) {
327
+ startCell = focus?.path;
328
+ endCell = anchor?.path;
329
+ }
330
+ const {
331
+ columns
332
+ } = tableNode[0];
333
+ const startPath = startCell[0];
334
+ const startRow = startCell[1];
335
+ let startCol = startCell[2];
336
+ const endRow = endCell[1];
337
+ const endCol = endCell[2];
338
+ const selectedCellsPath = [];
339
+ let uptoCol = startRow !== endRow ? columns - 1 : endCol;
340
+ for (let row = startRow; row <= endRow; row++) {
341
+ for (let col = startCol; col <= uptoCol; col++) {
342
+ let nextPath = [startPath, row, col];
343
+ selectedCellsPath.push(nextPath);
344
+ }
345
+ startCol = 0;
346
+ uptoCol = endCol;
347
+ }
348
+ return selectedCellsPath;
349
+ } else {
350
+ return false;
351
+ }
352
+ } catch (err) {
353
+ console.log(err);
354
+ return false;
355
+ }
356
+ };
293
357
  }
294
358
  const createRow = cellText => {
295
359
  const newRow = Array.from(cellText, value => createTableCell(value));
@@ -312,13 +376,10 @@ export const createTableCell = text => {
312
376
  const createTableNode = (cellText, rows, columns) => {
313
377
  const tableChildren = Array.from(cellText, value => createRow(value));
314
378
  let tableNode = {
315
- type: "paragraph",
316
- children: [{
317
- type: "table",
318
- children: tableChildren,
319
- rows,
320
- columns
321
- }]
379
+ type: "table",
380
+ children: tableChildren,
381
+ rows,
382
+ columns
322
383
  };
323
384
  return tableNode;
324
385
  };
@@ -0,0 +1,58 @@
1
+ import { Transforms } from "slate";
2
+ import insertNewLine from "./insertNewLine";
3
+ export const createTopBannerNode = ({
4
+ url,
5
+ alt
6
+ }) => ({
7
+ type: "topbanner",
8
+ alt,
9
+ url,
10
+ children: [{
11
+ text: " "
12
+ }],
13
+ size: {
14
+ widthInPercent: "100%",
15
+ height: "auto"
16
+ }
17
+ });
18
+ export const insertTopBanner = (editor, embedData) => {
19
+ try {
20
+ const {
21
+ url
22
+ } = embedData;
23
+ if (!url) return;
24
+ const embed = createTopBannerNode(embedData);
25
+ Transforms.insertNodes(editor, embed, {
26
+ at: [0]
27
+ });
28
+ insertNewLine(editor);
29
+ } catch (err) {
30
+ console.log(err);
31
+ }
32
+ };
33
+ export const removeTopBanner = editor => {
34
+ try {
35
+ const isTopBanner = editor?.children[0]?.type === "topbanner";
36
+ if (isTopBanner) {
37
+ Transforms.removeNodes(editor, {
38
+ at: [0]
39
+ });
40
+ }
41
+ } catch (err) {
42
+ console.log(err);
43
+ }
44
+ };
45
+ export const updateTopBanner = (editor, attr = {}) => {
46
+ try {
47
+ const isTopBanner = editor?.children[0]?.type === "topbanner";
48
+ if (isTopBanner) {
49
+ Transforms.setNodes(editor, {
50
+ ...attr
51
+ }, {
52
+ at: [0]
53
+ });
54
+ }
55
+ } catch (err) {
56
+ console.log(err);
57
+ }
58
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "1.5.9",
3
+ "version": "1.6.1",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"
@@ -9,6 +9,8 @@
9
9
  "dependencies": {
10
10
  "@dnd-kit/core": "^6.1.0",
11
11
  "@dnd-kit/sortable": "^8.0.0",
12
+ "@emoji-mart/data": "^1.1.2",
13
+ "@emoji-mart/react": "^1.1.1",
12
14
  "@emotion/react": "^11.11.1",
13
15
  "@emotion/styled": "^11.11.0",
14
16
  "@hocuspocus/provider": "^2.5.0",
@@ -20,6 +22,7 @@
20
22
  "@testing-library/jest-dom": "^5.16.5",
21
23
  "@testing-library/react": "^13.4.0",
22
24
  "@testing-library/user-event": "^13.5.0",
25
+ "emoji-mart": "^5.5.2",
23
26
  "html2canvas": "^1.4.1",
24
27
  "husky": "^8.0.3",
25
28
  "interweave": "^13.1.0",
@@ -55,7 +58,8 @@
55
58
  "eject": "react-scripts eject",
56
59
  "storybook": "storybook dev -p 6006",
57
60
  "build-storybook": "storybook build",
58
- "publish:npm": "rm -rf dist && mkdir dist && babel src/components -d dist --copy-files"
61
+ "publish:npm": "rm -rf dist && mkdir dist && babel src/components -d dist --copy-files",
62
+ "publish:local": "rm -rf dist && mkdir dist && babel src/components -d dist --copy-files && rm -rf /Users/dineshkumar/Desktop/devop/sweetpsocial-2.0/client/node_modules/@flozy/editor/dist && babel dist -d /Users/dineshkumar/Desktop/devop/sweetpsocial-2.0/client/node_modules/@flozy/editor/dist --copy-files"
59
63
  },
60
64
  "eslintConfig": {
61
65
  "extends": [
@@ -1,56 +0,0 @@
1
- import React, { useRef, useEffect } from "react";
2
- import { Transforms } from "slate";
3
- import { ReactEditor } from "slate-react";
4
- import { insertMention } from "../utils/mentions";
5
- import { jsx as _jsx } from "react/jsx-runtime";
6
- const MentionsPopup = props => {
7
- const {
8
- editor,
9
- index,
10
- target,
11
- chars,
12
- mentions,
13
- setMentions
14
- } = props;
15
- const ref = useRef(null);
16
- useEffect(() => {
17
- if (target && chars.length > 0) {
18
- const el = ref.current;
19
- const domRange = ReactEditor.toDOMRange(editor, target);
20
- const rect = domRange.getBoundingClientRect();
21
- el.style.top = `${rect.top + window.scrollY + 24}px`;
22
- el.style.left = `${rect.left + window.scrollX}px`;
23
- }
24
- }, [chars.length, editor, index, target]);
25
- return target && chars.length > 0 ? /*#__PURE__*/_jsx("div", {
26
- ref: ref,
27
- style: {
28
- top: "-9999px",
29
- left: "-9999px",
30
- position: "absolute",
31
- zIndex: 1,
32
- padding: "3px",
33
- background: "white",
34
- borderRadius: "4px",
35
- boxShadow: "0 1px 5px rgba(0,0,0,.2)"
36
- },
37
- "data-cy": "mentions-portal",
38
- children: chars.map((char, i) => /*#__PURE__*/_jsx("div", {
39
- onClick: () => {
40
- Transforms.select(editor, target);
41
- insertMention(editor, char);
42
- setMentions({
43
- ...mentions,
44
- target: null
45
- });
46
- },
47
- style: {
48
- padding: "1px 3px",
49
- borderRadius: "3px",
50
- background: i === index ? "#B4D5FF" : "transparent"
51
- },
52
- children: char.name
53
- }, char))
54
- }) : null;
55
- };
56
- export default MentionsPopup;