@flozy/editor 5.3.8 → 5.4.0

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.
Files changed (192) hide show
  1. package/dist/Editor/ChatEditor.js +25 -34
  2. package/dist/Editor/CommonEditor.js +29 -15
  3. package/dist/Editor/Editor.css +100 -18
  4. package/dist/Editor/Elements/AI/AIInput.js +0 -1
  5. package/dist/Editor/Elements/AI/CustomSelect.js +19 -11
  6. package/dist/Editor/Elements/AI/PopoverAIInput.js +58 -52
  7. package/dist/Editor/Elements/AI/Styles.js +24 -6
  8. package/dist/Editor/Elements/Accordion/Accordion.js +8 -1
  9. package/dist/Editor/Elements/AppHeader/AppHeader.js +6 -6
  10. package/dist/Editor/Elements/Button/EditorButton.js +9 -2
  11. package/dist/Editor/Elements/Carousel/CarouselItem.js +11 -3
  12. package/dist/Editor/Elements/Color Picker/ColorButtons.js +7 -5
  13. package/dist/Editor/Elements/Color Picker/Styles.js +7 -3
  14. package/dist/Editor/Elements/Color Picker/defaultColors.js +2 -2
  15. package/dist/Editor/Elements/DataView/DataView.js +124 -0
  16. package/dist/Editor/Elements/DataView/DataViewButton.js +23 -0
  17. package/dist/Editor/Elements/DataView/Layouts/ColumnView.js +67 -0
  18. package/dist/Editor/Elements/DataView/Layouts/DataTypes/CheckType.js +33 -0
  19. package/dist/Editor/Elements/DataView/Layouts/DataTypes/Components/Select.js +162 -0
  20. package/dist/Editor/Elements/DataView/Layouts/DataTypes/Components/SimpleSelect.js +40 -0
  21. package/dist/Editor/Elements/DataView/Layouts/DataTypes/Components/styles.js +67 -0
  22. package/dist/Editor/Elements/DataView/Layouts/DataTypes/DateType.js +35 -0
  23. package/dist/Editor/Elements/DataView/Layouts/DataTypes/MultiSelectType.js +39 -0
  24. package/dist/Editor/Elements/DataView/Layouts/DataTypes/NumberType.js +30 -0
  25. package/dist/Editor/Elements/DataView/Layouts/DataTypes/PersonType.js +30 -0
  26. package/dist/Editor/Elements/DataView/Layouts/DataTypes/SelectType.js +35 -0
  27. package/dist/Editor/Elements/DataView/Layouts/DataTypes/TextType.js +36 -0
  28. package/dist/Editor/Elements/DataView/Layouts/DataTypes/index.js +17 -0
  29. package/dist/Editor/Elements/DataView/Layouts/FilterSort/SortOptions/ChooseField.js +29 -0
  30. package/dist/Editor/Elements/DataView/Layouts/FilterSort/SortOptions/ChooseSort.js +38 -0
  31. package/dist/Editor/Elements/DataView/Layouts/FilterSort/SortOptions/index.js +74 -0
  32. package/dist/Editor/Elements/DataView/Layouts/FilterSort/index.js +64 -0
  33. package/dist/Editor/Elements/DataView/Layouts/FilterSort/styles.js +106 -0
  34. package/dist/Editor/Elements/DataView/Layouts/FilterView.js +174 -0
  35. package/dist/Editor/Elements/DataView/Layouts/Formula.js +29 -0
  36. package/dist/Editor/Elements/DataView/Layouts/Options/AddOptions.js +113 -0
  37. package/dist/Editor/Elements/DataView/Layouts/Options/AddProperty.js +37 -0
  38. package/dist/Editor/Elements/DataView/Layouts/Options/AllProperties.js +111 -0
  39. package/dist/Editor/Elements/DataView/Layouts/Options/ChangeProperty.js +60 -0
  40. package/dist/Editor/Elements/DataView/Layouts/Options/ColumnsList.js +36 -0
  41. package/dist/Editor/Elements/DataView/Layouts/Options/Constants.js +101 -0
  42. package/dist/Editor/Elements/DataView/Layouts/Options/EditOption.js +160 -0
  43. package/dist/Editor/Elements/DataView/Layouts/Options/EditProperty.js +190 -0
  44. package/dist/Editor/Elements/DataView/Layouts/Options/FilterProperty.js +42 -0
  45. package/dist/Editor/Elements/DataView/Layouts/Options/PropertyList.js +30 -0
  46. package/dist/Editor/Elements/DataView/Layouts/Options/index.js +110 -0
  47. package/dist/Editor/Elements/DataView/Layouts/Options/styles.js +179 -0
  48. package/dist/Editor/Elements/DataView/Layouts/TableStyles.js +112 -0
  49. package/dist/Editor/Elements/DataView/Layouts/TableView.js +227 -0
  50. package/dist/Editor/Elements/DataView/Layouts/ViewData.js +80 -0
  51. package/dist/Editor/Elements/DataView/Layouts/colStyles.js +10 -0
  52. package/dist/Editor/Elements/DataView/Layouts/index.js +25 -0
  53. package/dist/Editor/Elements/DataView/Providers/DataViewProvider.js +281 -0
  54. package/dist/Editor/Elements/DataView/Utils/globalSearch.js +15 -0
  55. package/dist/Editor/Elements/DataView/Utils/multiSortRows.js +74 -0
  56. package/dist/Editor/Elements/DataView/styles.js +154 -0
  57. package/dist/Editor/Elements/Divider/Divider.js +36 -20
  58. package/dist/Editor/Elements/Embed/Image.js +51 -16
  59. package/dist/Editor/Elements/Embed/Video.js +26 -3
  60. package/dist/Editor/Elements/Form/Form.js +39 -2
  61. package/dist/Editor/Elements/Form/FormElements/FormCheckbox.js +7 -1
  62. package/dist/Editor/Elements/Form/FormElements/FormDate.js +7 -1
  63. package/dist/Editor/Elements/Form/FormElements/FormEmail.js +7 -1
  64. package/dist/Editor/Elements/Form/FormElements/FormNumbers.js +7 -1
  65. package/dist/Editor/Elements/Form/FormElements/FormRadioButton.js +7 -1
  66. package/dist/Editor/Elements/Form/FormElements/FormText.js +7 -1
  67. package/dist/Editor/Elements/Form/FormElements/FormTextArea.js +6 -1
  68. package/dist/Editor/Elements/Form/FormPopup.js +12 -9
  69. package/dist/Editor/Elements/FreeGrid/FreeGrid.js +1 -1
  70. package/dist/Editor/Elements/FreeGrid/FreeGridItem.js +20 -1
  71. package/dist/Editor/Elements/FreeGrid/breakpointConstants.js +4 -4
  72. package/dist/Editor/Elements/FreeGrid/styles.js +2 -1
  73. package/dist/Editor/Elements/Grid/GridButton.js +2 -2
  74. package/dist/Editor/Elements/Grid/GridItem.js +47 -36
  75. package/dist/Editor/Elements/Grid/Styles.js +50 -0
  76. package/dist/Editor/Elements/Link/LinkButton.js +1 -1
  77. package/dist/Editor/Elements/List/CheckList.js +2 -1
  78. package/dist/Editor/Elements/Search/SearchAttachment.js +1 -0
  79. package/dist/Editor/Elements/Search/SearchButton.js +1 -0
  80. package/dist/Editor/Elements/Signature/Signature.css +1 -1
  81. package/dist/Editor/Elements/Signature/SignatureOptions/TypeSignature.js +2 -2
  82. package/dist/Editor/Elements/Signature/SignaturePopup.js +17 -52
  83. package/dist/Editor/Elements/SimpleText/index.js +8 -1
  84. package/dist/Editor/Elements/SimpleText/style.js +20 -1
  85. package/dist/Editor/Elements/Table/AddRowCol.js +77 -0
  86. package/dist/Editor/Elements/Table/DragButton.js +142 -0
  87. package/dist/Editor/Elements/Table/DragStyles.js +70 -0
  88. package/dist/Editor/Elements/Table/Draggable.js +25 -0
  89. package/dist/Editor/Elements/Table/Droppable.js +53 -0
  90. package/dist/Editor/Elements/Table/Styles.js +82 -79
  91. package/dist/Editor/Elements/Table/Table.js +258 -140
  92. package/dist/Editor/Elements/Table/TableCell.js +365 -111
  93. package/dist/Editor/Elements/Table/TablePopup.js +9 -3
  94. package/dist/Editor/Elements/Table/TableRow.js +10 -2
  95. package/dist/Editor/Elements/Table/TableTool.js +101 -0
  96. package/dist/Editor/Elements/Table/tableHelper.js +71 -0
  97. package/dist/Editor/Elements/TopBanner/TopBanner.js +2 -1
  98. package/dist/Editor/MiniEditor.js +15 -1
  99. package/dist/Editor/Styles/EditorStyles.js +13 -4
  100. package/dist/Editor/Toolbar/FormatTools/BlockButton.js +10 -0
  101. package/dist/Editor/Toolbar/FormatTools/Dropdown.js +7 -12
  102. package/dist/Editor/Toolbar/FormatTools/FontFamilyAutocomplete.js +26 -4
  103. package/dist/Editor/Toolbar/FormatTools/MarkButton.js +3 -0
  104. package/dist/Editor/Toolbar/FormatTools/TextSize.js +5 -5
  105. package/dist/Editor/Toolbar/Mini/MiniToolbar.js +3 -6
  106. package/dist/Editor/Toolbar/Mini/Styles.js +4 -1
  107. package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/InfinityAITool.js +7 -3
  108. package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/index.js +6 -4
  109. package/dist/Editor/Toolbar/PopupTool/PopperHeader.js +19 -15
  110. package/dist/Editor/Toolbar/PopupTool/PopupToolStyle.js +555 -57
  111. package/dist/Editor/Toolbar/PopupTool/TextFormat.js +73 -16
  112. package/dist/Editor/Toolbar/PopupTool/index.js +3 -5
  113. package/dist/Editor/Toolbar/Toolbar.js +6 -0
  114. package/dist/Editor/Toolbar/toolbarGroups.js +4 -0
  115. package/dist/Editor/assets/svg/BrainIcon.js +2 -2
  116. package/dist/Editor/assets/svg/SettingsIcon.js +4 -4
  117. package/dist/Editor/assets/svg/TableIcons.js +220 -0
  118. package/dist/Editor/common/ColorPickerButton.js +85 -45
  119. package/dist/Editor/common/DnD/Draggable.js +2 -1
  120. package/dist/Editor/common/FontLoader/FontLoader.js +4 -4
  121. package/dist/Editor/common/Icon.js +23 -20
  122. package/dist/Editor/common/ImageSelector/Options/Upload.js +2 -1
  123. package/dist/Editor/common/ImageSelector/Styles.js +47 -6
  124. package/dist/Editor/common/ImageSelector/UploadStyles.js +18 -6
  125. package/dist/Editor/common/LinkSettings/NavComponents.js +2 -1
  126. package/dist/Editor/common/LinkSettings/index.js +2 -1
  127. package/dist/Editor/common/MentionsPopup/Styles.js +143 -8
  128. package/dist/Editor/common/MentionsPopup/index.js +1 -1
  129. package/dist/Editor/common/RnD/ElementSettings/Settings/FormSettings.js +108 -12
  130. package/dist/Editor/common/RnD/GuideLines/styles.js +3 -3
  131. package/dist/Editor/common/RnD/ShadowElement.js +1 -1
  132. package/dist/Editor/common/RnD/SwitchViewport/SwitchViewport.js +14 -2
  133. package/dist/Editor/common/RnD/Utils/gridDropItem.js +9 -6
  134. package/dist/Editor/common/RnD/VirtualElement/index.js +5 -1
  135. package/dist/Editor/common/RnD/index.js +3 -2
  136. package/dist/Editor/common/Section/index.js +3 -3
  137. package/dist/Editor/common/Section/styles.js +5 -1
  138. package/dist/Editor/common/Select/index.js +20 -0
  139. package/dist/Editor/common/Select/styles.js +17 -0
  140. package/dist/Editor/common/Shorthands/elements.js +13 -1
  141. package/dist/Editor/common/StyleBuilder/fieldStyle.js +2 -1
  142. package/dist/Editor/common/StyleBuilder/fieldTypes/backgroundImage.js +9 -3
  143. package/dist/Editor/common/StyleBuilder/fieldTypes/bannerSpacing.js +35 -7
  144. package/dist/Editor/common/StyleBuilder/fieldTypes/borderRadius.js +15 -2
  145. package/dist/Editor/common/StyleBuilder/fieldTypes/card.js +10 -2
  146. package/dist/Editor/common/StyleBuilder/fieldTypes/color.js +2 -1
  147. package/dist/Editor/common/StyleBuilder/fieldTypes/fontSize.js +1 -1
  148. package/dist/Editor/common/StyleBuilder/fieldTypes/icons.js +2 -0
  149. package/dist/Editor/common/StyleBuilder/fieldTypes/index.js +3 -1
  150. package/dist/Editor/common/StyleBuilder/fieldTypes/lineSpacing.js +79 -0
  151. package/dist/Editor/common/StyleBuilder/fieldTypes/radiusStyle.js +11 -11
  152. package/dist/Editor/common/StyleBuilder/fieldTypes/saveAsTemplate.js +22 -6
  153. package/dist/Editor/common/StyleBuilder/fieldTypes/selectBox.js +21 -2
  154. package/dist/Editor/common/StyleBuilder/fieldTypes/text.js +20 -4
  155. package/dist/Editor/common/StyleBuilder/fieldTypes/textOptions.js +12 -2
  156. package/dist/Editor/common/StyleBuilder/formStyle.js +268 -149
  157. package/dist/Editor/common/StyleBuilder/index.js +101 -20
  158. package/dist/Editor/common/StyleBuilder/pageSettingsStyle.js +4 -0
  159. package/dist/Editor/common/StyleBuilder/tableStyle.js +69 -25
  160. package/dist/Editor/common/SwipeableDrawer/style.js +15 -4
  161. package/dist/Editor/common/ToolbarIcon.js +1 -1
  162. package/dist/Editor/common/Uploader.js +46 -36
  163. package/dist/Editor/common/iconListV2.js +616 -60
  164. package/dist/Editor/common/iconslist.js +23 -17
  165. package/dist/Editor/commonStyle.js +417 -11
  166. package/dist/Editor/helper/deserialize/index.js +19 -7
  167. package/dist/Editor/helper/enforceDateFormat.js +41 -0
  168. package/dist/Editor/helper/index.js +17 -4
  169. package/dist/Editor/helper/theme.js +24 -1
  170. package/dist/Editor/hooks/useMouseMove.js +5 -2
  171. package/dist/Editor/hooks/useTable.js +210 -0
  172. package/dist/Editor/plugins/withCustomDeleteBackward.js +36 -4
  173. package/dist/Editor/plugins/withEmbeds.js +30 -26
  174. package/dist/Editor/plugins/withHTML.js +61 -10
  175. package/dist/Editor/plugins/withLayout.js +1 -0
  176. package/dist/Editor/utils/SlateUtilityFunctions.js +39 -12
  177. package/dist/Editor/utils/brains.js +1 -1
  178. package/dist/Editor/utils/button.js +4 -4
  179. package/dist/Editor/utils/chatEditor/SlateUtilityFunctions.js +26 -1
  180. package/dist/Editor/utils/customHooks/useResize.js +7 -4
  181. package/dist/Editor/utils/customHooks/useTableResize.js +6 -2
  182. package/dist/Editor/utils/dataView.js +43 -0
  183. package/dist/Editor/utils/embed.js +2 -1
  184. package/dist/Editor/utils/events.js +0 -1
  185. package/dist/Editor/utils/font.js +11 -4
  186. package/dist/Editor/utils/formfield.js +8 -4
  187. package/dist/Editor/utils/helper.js +103 -2
  188. package/dist/Editor/utils/insertNewLine.js +19 -1
  189. package/dist/Editor/utils/pageSettings.js +14 -2
  190. package/dist/Editor/utils/serializeToText.js +2 -0
  191. package/dist/Editor/utils/table.js +228 -24
  192. package/package.json +2 -2
@@ -0,0 +1,41 @@
1
+ function enforceDateFormat(inputElement) {
2
+ inputElement.addEventListener("input", event => {
3
+ const input = event.target;
4
+ let value = input.value;
5
+
6
+ // Allow only numbers and forward slashes
7
+ value = value.replace(/[^\d/]/g, "");
8
+
9
+ // Enforce MM/DD/YYYY structure
10
+ if (value.length > 10) {
11
+ value = value.slice(0, 10);
12
+ }
13
+ const parts = value.split("/");
14
+ if (parts.length > 1) {
15
+ parts[0] = parts[0].slice(0, 2); // Limit MM to 2 digits
16
+ if (parts[0] > 12) parts[0] = "12"; // Max month value
17
+ }
18
+
19
+ if (parts.length > 2) {
20
+ parts[1] = parts[1].slice(0, 2); // Limit DD to 2 digits
21
+ if (parts[1] > 31) parts[1] = "31"; // Max day value
22
+ }
23
+
24
+ if (parts.length > 3) {
25
+ parts[2] = parts[2].slice(0, 4); // Limit YYYY to 4 digits
26
+ }
27
+
28
+ input.value = parts.join("/");
29
+
30
+ // Optionally, validate the full date
31
+ if (input.value.length === 10) {
32
+ const [month, day, year] = input.value.split("/").map(Number);
33
+ const isValidDate = !isNaN(Date.parse(`${year}-${month}-${day}`));
34
+ if (!isValidDate) {
35
+ input.value = ""; // Clear input if invalid
36
+ alert("Invalid date format. Please enter a valid MM/DD/YYYY date.");
37
+ }
38
+ }
39
+ });
40
+ }
41
+ export default enforceDateFormat;
@@ -308,7 +308,13 @@ export const getTextColor = (color = "") => {
308
308
  color: "transparent !important",
309
309
  caretColor: "black",
310
310
  "& span": {
311
- color: "transparent !important"
311
+ color: "transparent !important",
312
+ "& ::selection": {
313
+ color: "#000 !important"
314
+ }
315
+ },
316
+ "& ::selection": {
317
+ color: "#000 !important"
312
318
  }
313
319
  } : {
314
320
  color
@@ -331,14 +337,14 @@ export const isCarouselSelected = editor => {
331
337
  return false;
332
338
  }
333
339
  const [nodeEntry] = Editor.nodes(editor, {
334
- match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === 'carousel'
340
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "carousel"
335
341
  });
336
342
  if (!nodeEntry) {
337
343
  return false;
338
344
  }
339
345
  const [node] = nodeEntry;
340
346
  const carouselDom = ReactEditor.toDOMNode(editor, node);
341
- const isEdit = carouselDom.classList.contains('carousel_slider_edit');
347
+ const isEdit = carouselDom.classList.contains("carousel_slider_edit");
342
348
  return !isEdit;
343
349
  } catch (err) {
344
350
  console.log(err);
@@ -352,7 +358,7 @@ export const clearBrainText = editor => {
352
358
  } = editor;
353
359
  if (selection) {
354
360
  const [currentNode, currentPath] = Editor.node(editor, selection);
355
- const cleanedText = Node.string(currentNode).replace(/\/b(?:rain|rai|ra|r)?/g, "").trim();
361
+ const cleanedText = Node.string(currentNode).replace(/\/(?:b(?:rain|rai|ra|r)?)?/g, "").trim();
356
362
  Transforms.insertText(editor, cleanedText, {
357
363
  at: currentPath
358
364
  });
@@ -360,4 +366,11 @@ export const clearBrainText = editor => {
360
366
  } catch (err) {
361
367
  console.log(err);
362
368
  }
369
+ };
370
+ export const clearSelectionOnly = editor => {
371
+ try {
372
+ Transforms.deselect(editor);
373
+ } catch (err) {
374
+ console.log(err);
375
+ }
363
376
  };
@@ -147,4 +147,27 @@ export const groupByBreakpoint = (styleProps, theme) => {
147
147
  }
148
148
  };
149
149
  };
150
- export const getCustomizationValue = value => isNaN(parseInt(value)) ? null : parseInt(value);
150
+ export const getCustomizationValue = value => isNaN(parseInt(value)) ? null : parseInt(value);
151
+ export const getBreakpointLineSpacing = (value, breakpoint) => {
152
+ try {
153
+ const values = getBreakPointsValue(value, breakpoint);
154
+ const cssVal = BREAKPOINTS_DEVICES.reduce((a, b) => {
155
+ if (values[b] || values["lg"]) {
156
+ const value = values[b] || values["lg"];
157
+ return {
158
+ ...a,
159
+ [b]: value
160
+ };
161
+ } else {
162
+ return a;
163
+ }
164
+ }, {});
165
+ if (breakpoint) {
166
+ return value[breakpoint] || value["lg"] || value;
167
+ } else {
168
+ return cssVal["lg"];
169
+ }
170
+ } catch (err) {
171
+ // console.log(err);
172
+ }
173
+ };
@@ -35,6 +35,7 @@ export const EditorProvider = ({
35
35
  path: null
36
36
  });
37
37
  const [fontFamilies, setFontFamilies] = useState({});
38
+ const [activeBreakPoint, setActiveBreakPoint] = useState("");
38
39
  useEffect(() => {
39
40
  window.updateSelectedItem = d => {
40
41
  setSelectedElement(d);
@@ -97,8 +98,10 @@ export const EditorProvider = ({
97
98
  setOpenAI,
98
99
  updateDragging,
99
100
  fontFamilies,
100
- setFontFamilies
101
- }), [path, editor?.selection, selectedPath, selectedElement, contextMenu, openAI, popupType, drop]);
101
+ setFontFamilies,
102
+ activeBreakPoint,
103
+ setActiveBreakPoint
104
+ }), [path, editor?.selection, selectedPath, selectedElement, contextMenu, openAI, popupType, drop, activeBreakPoint]);
102
105
  return /*#__PURE__*/_jsx(EditorContext.Provider, {
103
106
  value: otherValues,
104
107
  children: children
@@ -0,0 +1,210 @@
1
+ import { ClickAwayListener } from "@mui/material";
2
+ import { createContext, useContext, useEffect, useMemo, useState } from "react";
3
+ import { clearCellText } from "../utils/table";
4
+ import { Editor, Element, Transforms } from "slate";
5
+ import { DndContext, DragOverlay, PointerSensor, useSensor, useSensors } from "@dnd-kit/core";
6
+ import { encodeToBase64, isHavingSelection } from "../utils/helper";
7
+ import { serializeToText } from "../utils/serializeToText";
8
+ import { createCopiedTableStructure, getRectangleBounds, tableNodeToDom } from "../Elements/Table/tableHelper";
9
+
10
+ // const selectFirstCell = (tablePath, editor, updateTableSelection) => {
11
+ // const firstCell = [...tablePath, 0, 0];
12
+
13
+ // const end = Editor.end(editor, firstCell);
14
+
15
+ // Transforms.select(editor, {
16
+ // anchor: end,
17
+ // focus: end,
18
+ // });
19
+
20
+ // updateTableSelection({
21
+ // startCellPath: firstCell,
22
+ // endCellPath: [],
23
+ // isDragging: false,
24
+ // });
25
+ // };
26
+ import { jsx as _jsx } from "react/jsx-runtime";
27
+ import { jsxs as _jsxs } from "react/jsx-runtime";
28
+ const handleDragEnd = (dragData, editor, resetAll) => {
29
+ const {
30
+ active,
31
+ over
32
+ } = dragData;
33
+ if (over) {
34
+ const {
35
+ dragType,
36
+ path: startCellPath
37
+ } = active?.data?.current || {};
38
+ const {
39
+ path: overCellPath
40
+ } = over?.data?.current || {};
41
+ if (startCellPath?.length) {
42
+ if (dragType === "row") {
43
+ const startRowPath = startCellPath.slice(0, -1);
44
+ const overRowPath = overCellPath.slice(0, -1);
45
+ Transforms.moveNodes(editor, {
46
+ at: startRowPath,
47
+ to: overRowPath
48
+ });
49
+ } else {
50
+ const [startCol] = startCellPath.slice(-1);
51
+ const [overCol] = overCellPath.slice(-1);
52
+ const [tableData] = Editor.nodes(editor, {
53
+ at: startCellPath,
54
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
55
+ });
56
+ const [tableNode, tablePath] = tableData;
57
+ const rows = tableNode?.rows || 0;
58
+ for (let row = 0; row < rows; row++) {
59
+ const startColPath = [...tablePath, row, startCol];
60
+ const overColPath = [...tablePath, row, overCol];
61
+ Transforms.moveNodes(editor, {
62
+ at: startColPath,
63
+ to: overColPath
64
+ });
65
+ }
66
+ }
67
+ resetAll();
68
+ }
69
+ }
70
+ };
71
+ const TableContext = /*#__PURE__*/createContext();
72
+ export function getDefaultTableSelection() {
73
+ return {
74
+ startCellPath: [],
75
+ endCellPath: [],
76
+ isDragging: false
77
+ };
78
+ }
79
+ export const TableProvider = ({
80
+ editor,
81
+ children,
82
+ otherProps = {}
83
+ }) => {
84
+ const [hoverPath, setHoverPath] = useState(null);
85
+ const [tableSelection, setTableSelection] = useState(getDefaultTableSelection());
86
+ const [tableResizing, setTableResizing] = useState(null);
87
+
88
+ // for the button events (like onclick,...etc) inside draggable component to work correctly
89
+ const sensors = useSensors(useSensor(PointerSensor, {
90
+ activationConstraint: {
91
+ delay: 250,
92
+ distance: 0 // throws exceeded distance error
93
+ }
94
+ }));
95
+
96
+ const getSelectedCells = () => {
97
+ return getRectangleBounds(tableSelection);
98
+ };
99
+ const updateTableSelection = update => {
100
+ setTableSelection(prev => ({
101
+ ...prev,
102
+ ...update
103
+ }));
104
+ };
105
+ const resetAll = () => {
106
+ setTableSelection(getDefaultTableSelection());
107
+ Transforms.deselect(editor);
108
+
109
+ // hide drag icons after drag completion
110
+ setTimeout(() => setHoverPath(null), 200);
111
+ };
112
+ const values = useMemo(() => {
113
+ return {
114
+ hoverPath,
115
+ setHoverPath,
116
+ editor,
117
+ getSelectedCells,
118
+ updateTableSelection,
119
+ tableSelection,
120
+ tableResizing,
121
+ setTableResizing,
122
+ otherProps,
123
+ resetAll
124
+ };
125
+ }, [hoverPath, editor?.selection, tableSelection, tableResizing]);
126
+ useEffect(() => {
127
+ let isTextSelected;
128
+ const handleKeyDown = event => {
129
+ const isCutKey = (event.ctrlKey || event.metaKey) && event.key === "x";
130
+ if (isCutKey) {
131
+ isTextSelected = isHavingSelection(editor);
132
+ } else if (event.key === "Backspace") {
133
+ const selectedCells = getSelectedCells();
134
+ if (selectedCells?.length > 1) {
135
+ selectedCells.forEach(currentCellPath => {
136
+ clearCellText(editor, currentCellPath);
137
+ });
138
+ }
139
+ }
140
+ };
141
+ const handleCopy = (event, isCut) => {
142
+ try {
143
+ const isTextSelected = isHavingSelection(editor);
144
+ const {
145
+ startCellPath
146
+ } = tableSelection || {};
147
+ const customCopy = startCellPath?.length;
148
+ if (customCopy && !isTextSelected) {
149
+ event.preventDefault(); // Prevent default copy behavior
150
+
151
+ const {
152
+ tablePath
153
+ } = otherProps;
154
+ const [node] = Editor.node(editor, tablePath);
155
+ const copiedTableNode = createCopiedTableStructure(editor, tableSelection, node, tablePath);
156
+ const tableNode = [copiedTableNode];
157
+ const encodedTableNode = encodeToBase64(tableNode);
158
+ event.clipboardData.setData("application/x-slate-fragment", encodedTableNode);
159
+ const textData = serializeToText(tableNode);
160
+ event.clipboardData.setData("text/plain", textData);
161
+ const tableDom = tableNodeToDom(copiedTableNode);
162
+ event.clipboardData.setData("text/html", tableDom?.outerHTML);
163
+ if (isCut) {
164
+ clearCellText(editor, startCellPath);
165
+ }
166
+ }
167
+ } catch (err) {
168
+ console.log(err);
169
+ }
170
+ };
171
+ const handleCut = e => {
172
+ // unable to find the text selected or not here, that why handling it on handleKeyDown
173
+
174
+ if (!isTextSelected) {
175
+ e.preventDefault();
176
+ handleCopy(e, true);
177
+ }
178
+ };
179
+ window.addEventListener("keydown", handleKeyDown);
180
+ window.addEventListener("copy", handleCopy);
181
+ window.addEventListener("cut", handleCut);
182
+ return () => {
183
+ window.removeEventListener("keydown", handleKeyDown);
184
+ window.removeEventListener("copy", handleCopy);
185
+ window.removeEventListener("cut", handleCut);
186
+ };
187
+ }, [tableSelection, editor, tableSelection]);
188
+
189
+ // useEffect(() => {
190
+ // selectFirstCell(tablePath, editor, updateTableSelection);
191
+ // }, []);
192
+
193
+ return /*#__PURE__*/_jsx(TableContext.Provider, {
194
+ value: values,
195
+ children: /*#__PURE__*/_jsxs(DndContext, {
196
+ sensors: sensors,
197
+ onDragEnd: data => handleDragEnd(data, editor, resetAll),
198
+ children: [/*#__PURE__*/_jsx(ClickAwayListener, {
199
+ onClickAway: () => setTableSelection(getDefaultTableSelection()),
200
+ children: /*#__PURE__*/_jsx("div", {
201
+ children: children
202
+ })
203
+ }), /*#__PURE__*/_jsx(DragOverlay, {})]
204
+ })
205
+ });
206
+ };
207
+ function useTable() {
208
+ return useContext(TableContext);
209
+ }
210
+ export default useTable;
@@ -1,5 +1,6 @@
1
- import { Editor, Node, Path, Point, Transforms } from "slate";
2
- import { getNextNode } from "../utils/helper";
1
+ import { Editor, Node, Path, Point, Range, Transforms } from "slate";
2
+ import { containsSurrogatePair, getNextNode } from "../utils/helper";
3
+ const BACKWARD_BLOCKS = ["list-item", "signature"];
3
4
  const isNodeTextEmpty = node => {
4
5
  const nodeText = Node.string(node);
5
6
  return nodeText.trim() === "";
@@ -28,10 +29,41 @@ const withCustomDeleteBackward = editor => {
28
29
  return;
29
30
  }
30
31
  }
32
+ if (selection && Range.isCollapsed(selection)) {
33
+ const [currentNode, path] = Editor.node(editor, selection);
34
+ if (currentNode && typeof currentNode.text === 'string') {
35
+ const text = currentNode.text;
36
+ if (containsSurrogatePair(text)) {
37
+ // Check if the cursor is at the end of a surrogate pair
38
+ const {
39
+ offset
40
+ } = selection.anchor;
41
+ const beforeCursor = text.slice(0, offset);
42
+ const afterCursor = text.slice(offset);
43
+ if (containsSurrogatePair(beforeCursor) || containsSurrogatePair(afterCursor)) {
44
+ // Delete the entire surrogate pair
45
+ Transforms.delete(editor, {
46
+ at: {
47
+ anchor: {
48
+ path,
49
+ offset: offset - 2
50
+ },
51
+ // Move back 2 for surrogate pair
52
+ focus: {
53
+ path,
54
+ offset
55
+ }
56
+ }
57
+ });
58
+ return;
59
+ }
60
+ }
61
+ }
62
+ }
31
63
 
32
- // Check if current node is a list item and is the last one
64
+ // Check if current node is a list item and is the last one, signature node
33
65
  const [node] = Editor.nodes(editor, {
34
- match: n => n.type === "list-item" // Adjust based on your list item type
66
+ match: n => BACKWARD_BLOCKS.includes(n.type) // Adjust based on your list item type
35
67
  });
36
68
 
37
69
  if (node) {
@@ -40,32 +40,36 @@ const withEmbeds = editor => {
40
40
  }
41
41
  };
42
42
  editor.insertBreak = (...args) => {
43
- const parentPath = Path.parent(editor.selection.focus.path);
44
- const parentNode = Node.get(editor, parentPath);
45
- if (editor.isVoid(parentNode)) {
46
- const nextPath = Path.next(parentPath);
47
- Transforms.insertNodes(editor, {
48
- type: "paragraph",
49
- children: [{
50
- text: ""
51
- }]
52
- }, {
53
- at: nextPath,
54
- select: true // Focus on this node once inserted
55
- });
56
- } else if (AvoidCopying.indexOf(parentNode?.type) >= 0) {
57
- const nextPath = Path.next(parentPath);
58
- Transforms.insertNodes(editor, {
59
- type: "paragraph",
60
- children: [{
61
- text: ""
62
- }]
63
- }, {
64
- at: nextPath,
65
- select: true // Focus on this node once inserted
66
- });
67
- } else {
68
- insertBreak(...args);
43
+ try {
44
+ const parentPath = Path.parent(editor.selection.focus.path);
45
+ const parentNode = Node.get(editor, parentPath);
46
+ if (editor.isVoid(parentNode)) {
47
+ const nextPath = Path.next(parentPath);
48
+ Transforms.insertNodes(editor, {
49
+ type: "paragraph",
50
+ children: [{
51
+ text: ""
52
+ }]
53
+ }, {
54
+ at: nextPath,
55
+ select: true // Focus on this node once inserted
56
+ });
57
+ } else if (AvoidCopying.indexOf(parentNode?.type) >= 0) {
58
+ const nextPath = Path.next(parentPath);
59
+ Transforms.insertNodes(editor, {
60
+ type: "paragraph",
61
+ children: [{
62
+ text: ""
63
+ }]
64
+ }, {
65
+ at: nextPath,
66
+ select: true // Focus on this node once inserted
67
+ });
68
+ } else {
69
+ insertBreak(...args);
70
+ }
71
+ } catch (err) {
72
+ console.log(err);
69
73
  }
70
74
  };
71
75
  return editor;
@@ -2,6 +2,8 @@ import { Transforms, Editor, Element, Node, Path } from "slate";
2
2
  import deserialize from "../helper/deserialize";
3
3
  import { decodeAndParseBase64 } from "../utils/helper";
4
4
  const avoidDefaultInsert = ["table", "grid"];
5
+ const NON_TEXT_TAGS = ["ol", "ul", "img", "table", "video", "a", "button", "GOOGLE-SHEETS-HTML-ORIGIN"];
6
+ const ALLOWED_TEXT_NODES = ["paragraph", "title", "headingOne", "headingTwo", "headingThree"];
5
7
  const loopChildren = (children = [], defaultInsert) => {
6
8
  if (!children?.length) {
7
9
  return defaultInsert;
@@ -61,12 +63,23 @@ const insertAtNextNode = (editor, formattedFragment) => {
61
63
  console.log(err);
62
64
  }
63
65
  };
64
- const handleInsert = (editor, defaultInsert, fragment = []) => {
65
- if (getCurrentElementText(editor) && fragment.some(f => f.type === "table")) {
66
- insertAtNextNode(editor, fragment);
67
- } else {
68
- defaultInsert();
69
- }
66
+
67
+ // const handleInsert = (editor, defaultInsert, fragment = []) => {
68
+ // if (
69
+ // getCurrentElementText(editor) &&
70
+ // fragment.some((f) => f.type === "table")
71
+ // ) {
72
+ // insertAtNextNode(editor, fragment);
73
+ // } else {
74
+ // defaultInsert();
75
+ // }
76
+ // };
77
+
78
+ const getTableCellChild = (fragment = []) => {
79
+ const table = fragment.find(node => node.type === "table");
80
+ const row = table?.children?.find(node => node.type === "table-row");
81
+ const cell = row?.children?.find(node => node.type === "table-cell");
82
+ return cell?.children || [];
70
83
  };
71
84
  const formatFragment = {
72
85
  "list-item": fragment => {
@@ -115,8 +128,21 @@ const withHtml = editor => {
115
128
  const html = data?.getData("text/html");
116
129
  const currentEl = getCurrentElement(editor);
117
130
  const eltype = currentEl?.type;
131
+ const firstNode = editor?.children?.[0];
132
+ const titlePath = firstNode?.type === "topbanner" ? 1 : 0;
133
+ const isTitlePath = editor.needLayout && editor?.selection?.anchor?.path[0] === titlePath;
118
134
  if (slateHTML && !formatFragment[eltype]) {
135
+ const [tableCellNode] = Editor.nodes(editor, {
136
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table-cell"
137
+ });
119
138
  const decoded = decodeAndParseBase64(slateHTML);
139
+ if (tableCellNode) {
140
+ const tableCellChild = getTableCellChild(decoded);
141
+ if (tableCellChild?.length) {
142
+ Transforms.insertFragment(editor, tableCellChild);
143
+ return;
144
+ }
145
+ }
120
146
  const tableNode = getFocusedNode(editor, "table");
121
147
  const onlyTextNode = getFocusedNode(editor, "freegrid");
122
148
 
@@ -154,22 +180,38 @@ const withHtml = editor => {
154
180
  Transforms.insertText(editor, text);
155
181
  }
156
182
  } else {
157
- handleInsert(editor, () => insertData(data), decoded);
183
+ const isTextNode = ALLOWED_TEXT_NODES.includes(decoded?.[0]?.type);
184
+ if (isTitlePath && !isTextNode) {
185
+ insertAtNextNode(editor, decoded);
186
+ return;
187
+ }
188
+ const currentText = getCurrentElementText(editor);
189
+ if (currentText && !isTextNode) {
190
+ insertAtNextNode(editor, decoded);
191
+ return;
192
+ }
193
+ insertData(data);
158
194
  }
159
195
  } else if (html) {
160
196
  const parsed = new DOMParser().parseFromString(html, "text/html");
197
+ const rootElement = parsed.body || parsed.documentElement;
198
+ const isNonText = rootElement ? rootElement?.querySelector(NON_TEXT_TAGS.toString()) : false;
161
199
  const isGoogleSheet = parsed.body.querySelector("google-sheets-html-origin");
162
200
  if (isGoogleSheet) {
163
201
  if (editor.isChatEditor) {
164
202
  return;
165
203
  }
166
- const table = parsed.body.querySelector("table");
204
+ const table = rootElement.querySelector("table");
167
205
  const colGrp = table.querySelector("colgroup");
168
206
  if (colGrp) {
169
207
  colGrp.remove();
170
208
  }
171
209
  const fragment = deserialize(table);
172
- Transforms.insertFragment(editor, [fragment]);
210
+ if (isTitlePath) {
211
+ insertAtNextNode(editor, [fragment]);
212
+ } else {
213
+ Transforms.insertFragment(editor, [fragment]);
214
+ }
173
215
  return;
174
216
  }
175
217
  const fragment = deserialize(parsed.body);
@@ -183,7 +225,16 @@ const withHtml = editor => {
183
225
  if (editor.isChatEditor && is_img_table) {
184
226
  return;
185
227
  }
186
- handleInsert(editor, () => Transforms.insertFragment(editor, formattedFragment), formattedFragment);
228
+ if (isTitlePath && isNonText) {
229
+ insertAtNextNode(editor, formattedFragment);
230
+ return;
231
+ }
232
+ const currentText = getCurrentElementText(editor);
233
+ if (currentText && isNonText) {
234
+ insertAtNextNode(editor, formattedFragment);
235
+ return;
236
+ }
237
+ Transforms.insertFragment(editor, formattedFragment);
187
238
  return;
188
239
  } else {
189
240
  insertData(data);
@@ -58,6 +58,7 @@ const withLayout = editor => {
58
58
  Transforms.insertNodes(editor, paragraph, {
59
59
  at: path.concat(1)
60
60
  });
61
+ return;
61
62
  }
62
63
  ORDERS_LAYOUT.forEach((enforce, index) => {
63
64
  if (index < editor.children.length) {