@flozy/editor 5.5.8 → 5.6.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 (199) hide show
  1. package/dist/Editor/ChatEditor.js +25 -34
  2. package/dist/Editor/CommonEditor.js +26 -13
  3. package/dist/Editor/Editor.css +106 -20
  4. package/dist/Editor/Elements/AI/AIInput.js +0 -1
  5. package/dist/Editor/Elements/AI/CustomSelect.js +17 -10
  6. package/dist/Editor/Elements/AI/PopoverAIInput.js +59 -53
  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 +6 -1
  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 +8 -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 +83 -0
  18. package/dist/Editor/Elements/DataView/Layouts/DataTypes/CheckType.js +33 -0
  19. package/dist/Editor/Elements/DataView/Layouts/DataTypes/Components/Select.js +180 -0
  20. package/dist/Editor/Elements/DataView/Layouts/DataTypes/Components/SimpleSelect.js +62 -0
  21. package/dist/Editor/Elements/DataView/Layouts/DataTypes/Components/styles.js +68 -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 +86 -0
  32. package/dist/Editor/Elements/DataView/Layouts/FilterSort/index.js +71 -0
  33. package/dist/Editor/Elements/DataView/Layouts/FilterSort/styles.js +138 -0
  34. package/dist/Editor/Elements/DataView/Layouts/FilterView.js +213 -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 +44 -0
  38. package/dist/Editor/Elements/DataView/Layouts/Options/AllProperties.js +146 -0
  39. package/dist/Editor/Elements/DataView/Layouts/Options/ChangeProperty.js +79 -0
  40. package/dist/Editor/Elements/DataView/Layouts/Options/ColumnsList.js +57 -0
  41. package/dist/Editor/Elements/DataView/Layouts/Options/Constants.js +101 -0
  42. package/dist/Editor/Elements/DataView/Layouts/Options/EditOption.js +174 -0
  43. package/dist/Editor/Elements/DataView/Layouts/Options/EditProperty.js +241 -0
  44. package/dist/Editor/Elements/DataView/Layouts/Options/FilterProperty.js +45 -0
  45. package/dist/Editor/Elements/DataView/Layouts/Options/PropertyList.js +32 -0
  46. package/dist/Editor/Elements/DataView/Layouts/Options/index.js +110 -0
  47. package/dist/Editor/Elements/DataView/Layouts/Options/styles.js +217 -0
  48. package/dist/Editor/Elements/DataView/Layouts/TableStyles.js +131 -0
  49. package/dist/Editor/Elements/DataView/Layouts/TableView.js +253 -0
  50. package/dist/Editor/Elements/DataView/Layouts/ViewData.js +85 -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 +277 -0
  54. package/dist/Editor/Elements/DataView/Utils/globalSearch.js +15 -0
  55. package/dist/Editor/Elements/DataView/Utils/multiSortRows.js +88 -0
  56. package/dist/Editor/Elements/DataView/styles.js +169 -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 +38 -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/Form/Workflow/Styles.js +2 -0
  70. package/dist/Editor/Elements/FreeGrid/FreeGrid.js +1 -1
  71. package/dist/Editor/Elements/FreeGrid/FreeGridBox.js +4 -2
  72. package/dist/Editor/Elements/FreeGrid/FreeGridItem.js +20 -1
  73. package/dist/Editor/Elements/FreeGrid/breakpointConstants.js +4 -4
  74. package/dist/Editor/Elements/FreeGrid/styles.js +1 -1
  75. package/dist/Editor/Elements/Grid/GridButton.js +2 -2
  76. package/dist/Editor/Elements/Grid/GridItem.js +47 -36
  77. package/dist/Editor/Elements/Grid/Styles.js +50 -0
  78. package/dist/Editor/Elements/Link/LinkButton.js +1 -1
  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 +3 -2
  84. package/dist/Editor/Elements/SimpleText/style.js +15 -0
  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 +88 -78
  91. package/dist/Editor/Elements/Table/Table.js +263 -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 +21 -2
  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 +8 -8
  106. package/dist/Editor/Toolbar/Mini/Styles.js +9 -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 +547 -58
  111. package/dist/Editor/Toolbar/PopupTool/TextFormat.js +28 -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/ArrowDownIcon.js +25 -0
  116. package/dist/Editor/assets/svg/ArrowUpIcon.js +25 -0
  117. package/dist/Editor/assets/svg/BrainIcon.js +2 -2
  118. package/dist/Editor/assets/svg/CalenderIconTick.js +64 -0
  119. package/dist/Editor/assets/svg/ChervDown.js +18 -0
  120. package/dist/Editor/assets/svg/ChervUp.js +18 -0
  121. package/dist/Editor/assets/svg/DataTableIcon.js +50 -0
  122. package/dist/Editor/assets/svg/DuplicateIcon.js +23 -0
  123. package/dist/Editor/assets/svg/EyeIcon.js +23 -0
  124. package/dist/Editor/assets/svg/EyeSlash.js +43 -0
  125. package/dist/Editor/assets/svg/HashtagIcon.js +33 -0
  126. package/dist/Editor/assets/svg/PlusIcon.js +23 -0
  127. package/dist/Editor/assets/svg/SelectRoundedIcon.js +24 -0
  128. package/dist/Editor/assets/svg/SettingsIcon.js +4 -4
  129. package/dist/Editor/assets/svg/SortByIcon.js +33 -0
  130. package/dist/Editor/assets/svg/TableIcons.js +220 -0
  131. package/dist/Editor/assets/svg/TickOutlined.js +23 -0
  132. package/dist/Editor/assets/svg/TrashCanIcon.js +38 -0
  133. package/dist/Editor/common/ColorPickerButton.js +85 -45
  134. package/dist/Editor/common/DnD/Draggable.js +2 -1
  135. package/dist/Editor/common/FontLoader/FontLoader.js +2 -2
  136. package/dist/Editor/common/Icon.js +54 -21
  137. package/dist/Editor/common/ImageSelector/Options/Upload.js +2 -1
  138. package/dist/Editor/common/ImageSelector/Styles.js +47 -6
  139. package/dist/Editor/common/ImageSelector/UploadStyles.js +18 -6
  140. package/dist/Editor/common/LinkSettings/NavComponents.js +2 -1
  141. package/dist/Editor/common/LinkSettings/index.js +2 -1
  142. package/dist/Editor/common/MentionsPopup/Styles.js +142 -8
  143. package/dist/Editor/common/MentionsPopup/index.js +1 -1
  144. package/dist/Editor/common/RnD/ElementSettings/Settings/FormSettings.js +107 -12
  145. package/dist/Editor/common/RnD/GuideLines/styles.js +3 -3
  146. package/dist/Editor/common/RnD/ShadowElement.js +1 -1
  147. package/dist/Editor/common/RnD/VirtualElement/index.js +5 -1
  148. package/dist/Editor/common/RnD/index.js +4 -3
  149. package/dist/Editor/common/Section/index.js +3 -3
  150. package/dist/Editor/common/Section/styles.js +5 -1
  151. package/dist/Editor/common/Select/index.js +20 -0
  152. package/dist/Editor/common/Select/styles.js +17 -0
  153. package/dist/Editor/common/Shorthands/elements.js +13 -1
  154. package/dist/Editor/common/StyleBuilder/fieldStyle.js +2 -1
  155. package/dist/Editor/common/StyleBuilder/fieldTypes/backgroundImage.js +4 -3
  156. package/dist/Editor/common/StyleBuilder/fieldTypes/bannerSpacing.js +35 -7
  157. package/dist/Editor/common/StyleBuilder/fieldTypes/borderRadius.js +15 -2
  158. package/dist/Editor/common/StyleBuilder/fieldTypes/color.js +2 -1
  159. package/dist/Editor/common/StyleBuilder/fieldTypes/fontSize.js +1 -1
  160. package/dist/Editor/common/StyleBuilder/fieldTypes/icons.js +2 -0
  161. package/dist/Editor/common/StyleBuilder/fieldTypes/radiusStyle.js +11 -11
  162. package/dist/Editor/common/StyleBuilder/fieldTypes/saveAsTemplate.js +22 -6
  163. package/dist/Editor/common/StyleBuilder/fieldTypes/selectBox.js +21 -2
  164. package/dist/Editor/common/StyleBuilder/fieldTypes/text.js +20 -4
  165. package/dist/Editor/common/StyleBuilder/fieldTypes/textOptions.js +12 -2
  166. package/dist/Editor/common/StyleBuilder/formStyle.js +268 -149
  167. package/dist/Editor/common/StyleBuilder/index.js +101 -20
  168. package/dist/Editor/common/StyleBuilder/tableStyle.js +69 -25
  169. package/dist/Editor/common/SwipeableDrawer/style.js +15 -4
  170. package/dist/Editor/common/ToolbarIcon.js +1 -1
  171. package/dist/Editor/common/Uploader.js +39 -37
  172. package/dist/Editor/common/iconListV2.js +598 -74
  173. package/dist/Editor/common/iconslist.js +25 -19
  174. package/dist/Editor/commonStyle.js +421 -15
  175. package/dist/Editor/helper/deserialize/index.js +31 -2
  176. package/dist/Editor/helper/enforceDateFormat.js +41 -0
  177. package/dist/Editor/helper/index.js +15 -2
  178. package/dist/Editor/helper/theme.js +15 -1
  179. package/dist/Editor/hooks/useBreakpoints.js +1 -1
  180. package/dist/Editor/hooks/useTable.js +210 -0
  181. package/dist/Editor/plugins/withCustomDeleteBackward.js +1 -1
  182. package/dist/Editor/plugins/withEmbeds.js +30 -26
  183. package/dist/Editor/plugins/withHTML.js +100 -12
  184. package/dist/Editor/plugins/withLayout.js +1 -0
  185. package/dist/Editor/utils/SlateUtilityFunctions.js +31 -11
  186. package/dist/Editor/utils/brains.js +1 -1
  187. package/dist/Editor/utils/chatEditor/SlateUtilityFunctions.js +75 -6
  188. package/dist/Editor/utils/customHooks/useResize.js +7 -4
  189. package/dist/Editor/utils/customHooks/useTableResize.js +6 -2
  190. package/dist/Editor/utils/dataView.js +43 -0
  191. package/dist/Editor/utils/embed.js +2 -1
  192. package/dist/Editor/utils/events.js +0 -1
  193. package/dist/Editor/utils/font.js +11 -4
  194. package/dist/Editor/utils/formfield.js +8 -4
  195. package/dist/Editor/utils/helper.js +100 -2
  196. package/dist/Editor/utils/insertNewLine.js +19 -1
  197. package/dist/Editor/utils/serializeToText.js +2 -0
  198. package/dist/Editor/utils/table.js +228 -24
  199. package/package.json +2 -2
@@ -1,4 +1,26 @@
1
1
  import { jsx } from "slate-hyperscript";
2
+ const inlineStyles = [{
3
+ key: "bold",
4
+ getStyle: styles => styles.fontWeight === "bold" || parseInt(styles.fontWeight, 10) >= 700
5
+ }, {
6
+ key: "italic",
7
+ getStyle: styles => styles.fontStyle === "italic"
8
+ }, {
9
+ key: "underline",
10
+ getStyle: styles => styles.textDecoration.includes("underline")
11
+ }];
12
+ function getInlineTextStyles(element) {
13
+ if (!element || !element.style) return {};
14
+ const styles = element.style;
15
+ const elementStyles = inlineStyles.reduce((total, currVal) => {
16
+ const style = currVal.getStyle(styles);
17
+ if (style) {
18
+ total[currVal.key] = style;
19
+ }
20
+ return total;
21
+ }, {});
22
+ return elementStyles;
23
+ }
2
24
  const handleTableCell = (el, children) => {
3
25
  const wrapChild = children?.map(c => {
4
26
  if (typeof c === "string") {
@@ -14,7 +36,10 @@ const handleTableCell = (el, children) => {
14
36
  });
15
37
  return {
16
38
  type: "table-cell",
17
- overwriteChild: wrapChild
39
+ overwriteChild: wrapChild,
40
+ size: {
41
+ width: 120
42
+ }
18
43
  };
19
44
  };
20
45
  const INLINE_TAGS = ["A", "ABBR", "B", "BDO", "CITE", "CODE", "DATA", "DEL", "DFN", "IMG", "INS", "KBD", "LABEL", "MARK", "Q", "SAMP", "SMALL", "SPAN", "SUB", "SUP", "TIME", "VAR"];
@@ -135,9 +160,13 @@ const TEXT_TAGS = {
135
160
 
136
161
  const deserialize = el => {
137
162
  if (el.nodeType === 3) {
163
+ // if there is any line-breaks
138
164
  const match = /\r|\n/.exec(el.textContent);
139
165
  const text = el.textContent.replace(/\r|\n/g, "").trim();
140
- return match && !text ? null : el.textContent;
166
+ return match && !text ? null : {
167
+ text,
168
+ ...getInlineTextStyles(el.parentNode)
169
+ };
141
170
  } else if (el.nodeType !== 1) {
142
171
  return null;
143
172
  } else if (el.nodeName === "BR") {
@@ -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
@@ -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
  };
@@ -54,6 +54,20 @@ const overrides = {
54
54
  return `${val?.topLeft}px ${val?.topRight}px ${val?.bottomLeft}px ${val?.bottomRight}px`;
55
55
  }
56
56
  };
57
+ export const checkXS = (val = {}) => {
58
+ try {
59
+ if (typeof val === "object") {
60
+ if (val?.xs === undefined && val?.lg !== undefined) {
61
+ val.xs = val.lg;
62
+ }
63
+ return val;
64
+ }
65
+ return val;
66
+ } catch (err) {
67
+ console.log(err);
68
+ return val;
69
+ }
70
+ };
57
71
  export const getBreakPointsValue = (value, breakpoint, ot = null, ov = false) => {
58
72
  try {
59
73
  if (breakpoint) {
@@ -67,7 +81,7 @@ export const getBreakPointsValue = (value, breakpoint, ot = null, ov = false) =>
67
81
  return value ? value[breakpoint] || value["lg"] : value;
68
82
  }
69
83
  } else if (typeof value === "object") {
70
- return !breakpoint && value["lg"] ? !ov ? value : overrideValues(value, ot) : value[breakpoint] || copyAllLg(value, ot);
84
+ return !breakpoint && value["lg"] ? !ov ? value : checkXS(overrideValues(value, ot)) : value[breakpoint] || copyAllLg(value, ot);
71
85
  } else {
72
86
  // consider without breakpoints
73
87
  return copyAllLg(value, ot);
@@ -1,6 +1,6 @@
1
1
  import { useMediaQuery } from "@mui/material";
2
2
  export const STIMULATOR_MOCK = {
3
- xs: "@media (min-width: 1200px) and (max-width: 1980px)"
3
+ xs: "@media (min-width: 1200px) and (max-width: 10000px)"
4
4
  };
5
5
  export const isStimulator = () => {
6
6
  try {
@@ -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;
@@ -64,7 +64,7 @@ const withCustomDeleteBackward = editor => {
64
64
 
65
65
  // Check if current node is a list item and is the last one, signature node
66
66
  const [node] = Editor.nodes(editor, {
67
- match: n => BACKWARD_BLOCKS?.includes(n.type) // Adjust based on your list item type
67
+ match: n => BACKWARD_BLOCKS.includes(n.type) // Adjust based on your list item type
68
68
  });
69
69
 
70
70
  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,45 @@ 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"];
7
+ const parseCopiedHTML = html => {
8
+ const parsed = new DOMParser().parseFromString(html, "text/html");
9
+
10
+ // if ol, ul are inside li, remove and push ol,ul after that li to maintain format between our slate list and external source list's json
11
+ parsed.querySelectorAll("li > ul, li > ol").forEach(list => {
12
+ // Find the parent li
13
+ const parentLi = list.parentElement;
14
+
15
+ // Move the list after the parent li
16
+ parentLi.after(list);
17
+ });
18
+
19
+ // to handle google docs list
20
+ parsed.querySelectorAll("li p, li div").forEach(element => {
21
+ const parent = element.parentNode;
22
+ // Move all child nodes of <p> or <div> to its parent <li>
23
+ while (element.firstChild) {
24
+ parent.insertBefore(element.firstChild, element);
25
+ }
26
+ // Remove the <p> or <div> element
27
+ parent.removeChild(element);
28
+ });
29
+
30
+ // claude.ai, copy list inbetween, some li tags are not wrapped with ul or ol
31
+ parsed.querySelectorAll("li").forEach(li => {
32
+ // Check if the parent of <li> is not a <ul> or <ol>
33
+ if (!li.parentElement || li.parentElement.tagName !== "UL" && li.parentElement.tagName !== "OL") {
34
+ // Create a <ul> element
35
+ const ul = document.createElement("ul");
36
+ // Append the <li> to the <ul>
37
+ ul.appendChild(li.cloneNode(true)); // Clone the <li>
38
+ // Replace the original <li> in the DOM with the <ul>
39
+ li.replaceWith(ul);
40
+ }
41
+ });
42
+ return parsed;
43
+ };
5
44
  const loopChildren = (children = [], defaultInsert) => {
6
45
  if (!children?.length) {
7
46
  return defaultInsert;
@@ -26,7 +65,7 @@ const getCurrentElement = editor => {
26
65
  return null;
27
66
  }
28
67
  };
29
- const getCurrentElementText = editor => {
68
+ export const getCurrentElementText = editor => {
30
69
  try {
31
70
  if (editor.selection) {
32
71
  return Editor.string(editor, editor?.selection?.anchor?.path);
@@ -61,12 +100,23 @@ const insertAtNextNode = (editor, formattedFragment) => {
61
100
  console.log(err);
62
101
  }
63
102
  };
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
- }
103
+
104
+ // const handleInsert = (editor, defaultInsert, fragment = []) => {
105
+ // if (
106
+ // getCurrentElementText(editor) &&
107
+ // fragment.some((f) => f.type === "table")
108
+ // ) {
109
+ // insertAtNextNode(editor, fragment);
110
+ // } else {
111
+ // defaultInsert();
112
+ // }
113
+ // };
114
+
115
+ const getTableCellChild = (fragment = []) => {
116
+ const table = fragment.find(node => node.type === "table");
117
+ const row = table?.children?.find(node => node.type === "table-row");
118
+ const cell = row?.children?.find(node => node.type === "table-cell");
119
+ return cell?.children || [];
70
120
  };
71
121
  const formatFragment = {
72
122
  "list-item": fragment => {
@@ -115,8 +165,21 @@ const withHtml = editor => {
115
165
  const html = data?.getData("text/html");
116
166
  const currentEl = getCurrentElement(editor);
117
167
  const eltype = currentEl?.type;
168
+ const firstNode = editor?.children?.[0];
169
+ const titlePath = firstNode?.type === "topbanner" ? 1 : 0;
170
+ const isTitlePath = editor.needLayout && editor?.selection?.anchor?.path[0] === titlePath;
118
171
  if (slateHTML && !formatFragment[eltype]) {
172
+ const [tableCellNode] = Editor.nodes(editor, {
173
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table-cell"
174
+ });
119
175
  const decoded = decodeAndParseBase64(slateHTML);
176
+ if (tableCellNode) {
177
+ const tableCellChild = getTableCellChild(decoded);
178
+ if (tableCellChild?.length) {
179
+ Transforms.insertFragment(editor, tableCellChild);
180
+ return;
181
+ }
182
+ }
120
183
  const tableNode = getFocusedNode(editor, "table");
121
184
  const onlyTextNode = getFocusedNode(editor, "freegrid");
122
185
 
@@ -154,22 +217,38 @@ const withHtml = editor => {
154
217
  Transforms.insertText(editor, text);
155
218
  }
156
219
  } else {
157
- handleInsert(editor, () => insertData(data), decoded);
220
+ const isTextNode = ALLOWED_TEXT_NODES.includes(decoded?.[0]?.type);
221
+ if (isTitlePath && !isTextNode) {
222
+ insertAtNextNode(editor, decoded);
223
+ return;
224
+ }
225
+ const currentText = getCurrentElementText(editor);
226
+ if (currentText?.trim() && !isTextNode) {
227
+ insertAtNextNode(editor, decoded);
228
+ return;
229
+ }
230
+ insertData(data);
158
231
  }
159
232
  } else if (html) {
160
- const parsed = new DOMParser().parseFromString(html, "text/html");
233
+ const parsed = parseCopiedHTML(html);
234
+ const rootElement = parsed.body;
235
+ const isNonText = rootElement ? rootElement?.querySelector(NON_TEXT_TAGS.toString()) : false;
161
236
  const isGoogleSheet = parsed.body.querySelector("google-sheets-html-origin");
162
237
  if (isGoogleSheet) {
163
238
  if (editor.isChatEditor) {
164
239
  return;
165
240
  }
166
- const table = parsed.body.querySelector("table");
241
+ const table = rootElement.querySelector("table");
167
242
  const colGrp = table.querySelector("colgroup");
168
243
  if (colGrp) {
169
244
  colGrp.remove();
170
245
  }
171
246
  const fragment = deserialize(table);
172
- Transforms.insertFragment(editor, [fragment]);
247
+ if (isTitlePath) {
248
+ insertAtNextNode(editor, [fragment]);
249
+ } else {
250
+ Transforms.insertFragment(editor, [fragment]);
251
+ }
173
252
  return;
174
253
  }
175
254
  const fragment = deserialize(parsed.body);
@@ -183,7 +262,16 @@ const withHtml = editor => {
183
262
  if (editor.isChatEditor && is_img_table) {
184
263
  return;
185
264
  }
186
- handleInsert(editor, () => Transforms.insertFragment(editor, formattedFragment), formattedFragment);
265
+ if (isTitlePath && isNonText) {
266
+ insertAtNextNode(editor, formattedFragment);
267
+ return;
268
+ }
269
+ const currentText = getCurrentElementText(editor);
270
+ if (currentText?.trim() && isNonText) {
271
+ insertAtNextNode(editor, formattedFragment);
272
+ return;
273
+ }
274
+ Transforms.insertFragment(editor, formattedFragment);
187
275
  return;
188
276
  } else {
189
277
  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) {