@flozy/editor 5.5.9 → 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 +34 -3
  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,12 +1,17 @@
1
- import React, { useState, useEffect } from "react";
2
- import { Editor, Element, Transforms } from "slate";
3
- import { Box, MenuItem, Popper, Typography } from "@mui/material";
1
+ import React, { useState, useEffect, useMemo } from "react";
2
+ import { Editor, Path, Transforms } from "slate";
3
+ import { Box } from "@mui/material";
4
4
  import { useSlateStatic, ReactEditor } from "slate-react";
5
5
  import useTableResize from "../../utils/customHooks/useTableResize";
6
6
  import { TableUtil } from "../../utils/table";
7
7
  import TableStyles from "./Styles";
8
- import { useEditorSelection } from "../../hooks/useMouseMove";
9
- import useClickOutside from "../../hooks/useClickOutside";
8
+ import { useEditorContext, useEditorSelection } from "../../hooks/useMouseMove";
9
+ import useTable, { getDefaultTableSelection } from "../../hooks/useTable";
10
+ import DragButton from "./DragButton";
11
+ import TablePopup from "./TablePopup";
12
+ import { Droppable } from "./Droppable";
13
+ import { useDndContext } from "@dnd-kit/core";
14
+ import { getNodeWithType } from "../../utils/helper";
10
15
  import { jsx as _jsx } from "react/jsx-runtime";
11
16
  import { Fragment as _Fragment } from "react/jsx-runtime";
12
17
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -28,9 +33,14 @@ const Resizer = ({
28
33
  })
29
34
  });
30
35
  };
36
+ const isCellEditable = (startCellPath, path) => {
37
+ return startCellPath?.length && startCellPath?.toString() === path?.toString();
38
+ };
31
39
  const TableCell = props => {
32
- const themeType = localStorage.getItem("themeType");
33
- const classes = TableStyles(themeType);
40
+ const {
41
+ theme
42
+ } = useEditorContext();
43
+ const classes = TableStyles(theme);
34
44
  const {
35
45
  element,
36
46
  attributes,
@@ -44,69 +54,65 @@ const TableCell = props => {
44
54
  bgColor,
45
55
  borderColor,
46
56
  entireBgColor,
47
- entireBorderColor
57
+ entireBorderColor,
58
+ entireTextColor,
59
+ entireFontFamily,
60
+ entireFontWeight,
61
+ entireTextSize,
62
+ size: elementSize
48
63
  } = element;
49
64
  const [parentDOM, setParentDOM] = useState(null);
50
65
  const editor = useSlateStatic();
51
66
  const [showTool] = useEditorSelection(editor);
67
+ const {
68
+ hoverPath,
69
+ setHoverPath,
70
+ getSelectedCells,
71
+ updateTableSelection,
72
+ tableSelection,
73
+ tableResizing,
74
+ setTableResizing,
75
+ otherProps
76
+ } = useTable();
77
+ const {
78
+ active,
79
+ over
80
+ } = useDndContext();
81
+ const currentDraggingType = active?.data?.current?.dragType;
82
+ const {
83
+ dragRowBtnCls
84
+ } = otherProps || {};
85
+ const {
86
+ startCellPath
87
+ } = tableSelection;
52
88
  const path = ReactEditor.findPath(editor, element);
53
89
  const isHeader = path.length >= 2 ? path[path.length - 2] === 0 : false;
54
90
  const [size, onMouseDown, resizing, onLoad] = useTableResize({
55
91
  parentDOM,
56
- size: element?.size
92
+ size: element?.size,
93
+ minMaxProps: {
94
+ minWidth: 30
95
+ }
57
96
  });
58
97
  const [tableSize, setTableSize] = useState({});
98
+ const [openSettings, setOpenSettings] = useState(false);
59
99
  const table = new TableUtil(editor);
60
100
  const tableProps = table.getTableProps();
61
- const [tableNode] = Editor.nodes(editor, {
62
- at: path,
63
- match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
64
- });
65
- const [rowNode] = Editor.nodes(editor, {
66
- at: path,
67
- match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table-row"
68
- });
101
+ const [tableNode] = getNodeWithType(editor, "table", path); // getting cannot find the descendant path error, while deleting table because of unknown re-render issue, so wrapping it with try catch
102
+ const [rowNode] = getNodeWithType(editor, "table-row", path);
103
+ const currentPath = path.slice(-2) || []; // getting last 2 items from path, which gives row and column position of the cell
104
+ const [row, column] = currentPath;
105
+ const isFirstRow = row === 0;
106
+ const isFirstColumn = column === 0;
107
+ const [hoverRow, hoverCol] = hoverPath ? hoverPath.slice(-2) : [];
108
+ const showColDrag = isFirstRow && hoverCol === column && !resizing && !readOnly;
109
+ const showRowDrag = isFirstColumn && hoverRow === row && !resizing && !readOnly;
69
110
  const [parentProps] = tableNode || [{}];
70
111
  const [rowProps] = rowNode || [{}];
71
112
  const tableDOM = table.getDOMNode(path, true);
72
- const isCellSelected = table.isCellSelected(editor.selection);
113
+ const isCellSelected = getSelectedCells();
73
114
  const hasSelected = (isCellSelected || [])?.findIndex(f => f.join(",") === path.join(",")) > -1;
74
- const [anchorEl, setAnchorEl] = useState(null);
75
- const open = Boolean(anchorEl);
76
- const popperOptions = [{
77
- value: "Delete Row"
78
- }, {
79
- value: "Delete Column"
80
- }];
81
- const onRightClick = e => {
82
- e.preventDefault();
83
- if (hasSelected) {
84
- setAnchorEl(e.currentTarget);
85
- }
86
- };
87
- const closePoper = () => {
88
- setAnchorEl(null);
89
- };
90
- const handleMenuItemClick = value => {
91
- Transforms.select(editor, editor.selection);
92
- switch (value) {
93
- case "Delete Row":
94
- table.deleteRow();
95
- break;
96
- case "Delete Column":
97
- table.deleteColumn();
98
- break;
99
- default:
100
- return;
101
- }
102
- // closePoper();
103
- };
104
-
105
- // Use the useClickOutside hook
106
- const popperRef = useClickOutside({
107
- onClickOutside: closePoper,
108
- refCount: 1
109
- })[0];
115
+ const containerEle = tableDOM?.parentNode?.parentNode;
110
116
  useEffect(() => {
111
117
  if (tableDOM) {
112
118
  const {
@@ -116,81 +122,329 @@ const TableCell = props => {
116
122
  const {
117
123
  width: parentWidth
118
124
  } = tableDOM?.parentNode?.parentNode?.getBoundingClientRect();
119
- const {
120
- styleProps
121
- } = tableProps || {};
122
- const columns = styleProps ? styleProps["table.columns"] : 2;
125
+ const cellWidth = element?.size?.width;
126
+ const columns = tableNode?.[0]?.columns;
127
+ const oldTableWidth = parentWidth / columns - 4;
123
128
  setTableSize({
124
129
  width,
125
130
  height,
126
131
  parentWidth,
127
- cellWidth: parentWidth / columns
132
+ cellWidth: cellWidth || oldTableWidth
128
133
  });
129
134
  }
130
- }, [tableDOM, anchorEl]);
135
+ }, [tableDOM]);
131
136
  useEffect(() => {
132
137
  if (editor && element && tableSize) {
133
138
  const dom = ReactEditor.toDOMNode(editor, element);
134
139
  setParentDOM(dom);
135
- onLoad(element?.size || {
136
- width: tableSize?.cellWidth,
140
+ const width = tableSize?.cellWidth;
141
+ const size = element?.size ? {
142
+ ...element?.size,
143
+ width
144
+ } : {
145
+ width,
137
146
  height: 100
138
- });
147
+ };
148
+ onLoad(size);
139
149
  }
140
- }, [tableSize, anchorEl]);
150
+ }, [tableSize]);
151
+ const resetSelection = () => {
152
+ Transforms.deselect(editor);
153
+ updateTableSelection(getDefaultTableSelection());
154
+ };
141
155
  useEffect(() => {
142
- if (!resizing && tableProps) {
143
- table.updateTableStyle({
156
+ const currentPath = path?.toString();
157
+ setTimeout(() => {
158
+ if (tableResizing === currentPath) {
159
+ setTableResizing(null);
160
+
161
+ // reset selection after resizing
162
+ resetSelection();
163
+ }
164
+ }, 200);
165
+ if (!resizing && tableResizing) {
166
+ table.resizeTableCell({
144
167
  "col.size": size
145
- }, tableProps);
168
+ }, path);
169
+ }
170
+ if (resizing) {
171
+ setTableResizing(currentPath);
172
+ }
173
+ }, [resizing]);
174
+ const onMouseEnter = path => {
175
+ setHoverPath(path);
176
+ if (tableSelection?.isDragging) {
177
+ updateTableSelection({
178
+ endCellPath: path
179
+ });
180
+ const isSelectingOneCellToAnotherCell = startCellPath?.length && !Path.equals(path, startCellPath);
181
+ if (isSelectingOneCellToAnotherCell) {
182
+ Transforms.deselect(editor);
183
+ }
184
+ }
185
+ };
186
+ const onMouseLeave = () => {
187
+ setHoverPath(null);
188
+ };
189
+ const onMouseDownInCell = e => {
190
+ if (
191
+ // for shift selection
192
+ e.shiftKey && startCellPath?.length && startCellPath.toString() !== path.toString()) {
193
+ updateTableSelection({
194
+ endCellPath: path
195
+ });
196
+ } else {
197
+ updateTableSelection({
198
+ startCellPath: path,
199
+ endCellPath: [],
200
+ isDragging: true
201
+ });
202
+ }
203
+ };
204
+ const onMouseUp = () => {
205
+ if (startCellPath?.length) {
206
+ updateTableSelection({
207
+ endCellPath: path,
208
+ isDragging: false
209
+ });
146
210
  }
147
- }, [resizing, anchorEl]);
148
- const poperForDeltion = () => {
149
- return /*#__PURE__*/_jsx(Popper, {
150
- open: open,
151
- anchorEl: anchorEl,
152
- placement: "bottom-start",
153
- disablePortal: true,
154
- ref: popperRef,
155
- sx: classes.deleteCellsPopUp,
156
- children: popperOptions.map(option => /*#__PURE__*/_jsx(MenuItem, {
157
- value: option.value,
158
- onClick: () => handleMenuItemClick(option.value),
159
- contentEditable: false,
160
- sx: classes.menuItemPopUp,
161
- children: /*#__PURE__*/_jsx(Typography, {
162
- sx: {
163
- fontSize: "12px",
164
- userSelect: "none"
165
- },
166
- children: option.value
167
- })
168
- }, option.value))
211
+ };
212
+ const onClick = () => {
213
+ const currentEditorSelection = editor?.selection?.focus?.path || [];
214
+ const selectionPath = currentEditorSelection?.slice(0, -2);
215
+ const isCellSelected = selectionPath?.length && Path.equals(selectionPath, path);
216
+ if (!isCellSelected) {
217
+ // after mousedown event, onclick is triggered, while onclick, dragging should be disabled and focus should be on that clicked cell to edit the contents inside it.
218
+ updateTableSelection({
219
+ isDragging: false
220
+ });
221
+ }
222
+ };
223
+ const cellId = "table-cell" + path.toString();
224
+ const cellRef = document.getElementById(cellId);
225
+ const contentEditable = !readOnly && isCellEditable(startCellPath, path);
226
+ const commonTdProps = useMemo(() => {
227
+ const props = {
228
+ id: cellId
229
+ };
230
+
231
+ // if (!contentEditable) {
232
+ // props.contentEditable = false;
233
+ // }
234
+
235
+ return props;
236
+ }, [contentEditable, cellId]);
237
+ const handleTouchMove = e => {
238
+ const touch = e.touches[0]; // Get the current touch point
239
+ const element = document.elementFromPoint(touch.clientX, touch.clientY);
240
+ if (element && element.dataset.cell) {
241
+ const elementPath = element.dataset.cell.split(",").map(Number);
242
+ onMouseEnter(elementPath);
243
+ }
244
+ };
245
+ const handleTouchEnd = () => {
246
+ updateTableSelection({
247
+ isDragging: false
169
248
  });
170
249
  };
171
- const sizeProps = isHeader ? {
172
- width: size?.width || tableSize?.cellWidth
173
- } : {};
250
+ const tbProps = tableResizing || resizing || over || readOnly ? {
251
+ ...commonTdProps,
252
+ contentEditable: false
253
+ } : {
254
+ ...commonTdProps,
255
+ onMouseEnter: () => onMouseEnter(path),
256
+ onMouseLeave,
257
+ onMouseDown: onMouseDownInCell,
258
+ onMouseUp,
259
+ onClick,
260
+ // mobile events for selection
261
+ onTouchStart: onMouseDownInCell,
262
+ onTouchMove: handleTouchMove,
263
+ onTouchEnd: handleTouchEnd
264
+ };
265
+ const dndProps = {
266
+ id: cellId,
267
+ data: {
268
+ path
269
+ }
270
+ };
271
+ const isCellDragging = active?.id && active?.id === cellId;
272
+ const isRowDragging = isCellDragging && currentDraggingType === "row";
273
+ const isColDragging = isCellDragging && currentDraggingType === "col";
274
+ const width = isHeader ? size?.width || tableSize?.cellWidth || elementSize?.width : "0px";
275
+ const sizeProps = {
276
+ minWidth: width,
277
+ maxWidth: width
278
+ };
174
279
  const cellBorderColor = borderColor || rowProps?.borderColor || parentProps?.borderColor || entireBorderColor;
175
- return /*#__PURE__*/_jsxs("td", {
176
- ...element.attr,
177
- ...attributes,
178
- className: `editor-table-cell ${hasSelected ? "selection" : ""}`,
179
- style: {
180
- position: "relative",
181
- background: bgColor || entireBgColor,
182
- border: cellBorderColor ? `3px solid ${cellBorderColor}` : "",
183
- ...(sizeProps || {})
184
- },
185
- onContextMenu: onRightClick,
186
- children: [children, isHeader && !readOnly && tableSize?.height && !showTool ? /*#__PURE__*/_jsx(Resizer, {
187
- classes: classes,
188
- onMouseDown: onMouseDown,
189
- height: tableDOM.getBoundingClientRect()?.height
190
- }) : null, hasSelected && !readOnly ? /*#__PURE__*/_jsx("div", {
191
- className: "selection-area-tc",
192
- contentEditable: false
193
- }) : null, poperForDeltion()]
280
+ const selectCurrentCell = () => {
281
+ const cellPath = Editor.start(editor, path);
282
+ const selection = {
283
+ anchor: cellPath,
284
+ focus: cellPath
285
+ };
286
+
287
+ // select the cell to insert/delete/duplicate/clear
288
+ Transforms.select(editor, selection);
289
+ };
290
+ const onRowDrag = () => {
291
+ const {
292
+ children
293
+ } = rowNode[0] || {};
294
+ const rowPath = rowNode[1] || [];
295
+ const rowStartCell = [...rowPath, 0];
296
+ const rowEndCell = [...rowPath, children?.length - 1];
297
+ updateTableSelection({
298
+ startCellPath: rowStartCell,
299
+ endCellPath: rowEndCell,
300
+ isDragging: false
301
+ });
302
+ selectCurrentCell();
303
+ };
304
+ const onColDrag = () => {
305
+ const [tableData, tablePath] = tableNode;
306
+ const {
307
+ rows
308
+ } = tableData;
309
+ const startColCell = [...tablePath, 0, column];
310
+ const endColCell = [...tablePath, rows - 1, column];
311
+ updateTableSelection({
312
+ startCellPath: startColCell,
313
+ endCellPath: endColCell,
314
+ isDragging: false
315
+ });
316
+ selectCurrentCell();
317
+ };
318
+ const handleToolAction = (value, option, dragType) => {
319
+ const isRowDrag = dragType === "row";
320
+ switch (value) {
321
+ case "insertAbove":
322
+ table.insertRow("at");
323
+ break;
324
+ case "insertBelow":
325
+ table.insertRow("after");
326
+ break;
327
+ case "delete":
328
+ const deleteFn = isRowDrag ? table.deleteRow : table.deleteColumn;
329
+ deleteFn();
330
+ setTimeout(() => resetSelection(), 200); // throws cannot find the descendant path error because of deletion
331
+ break;
332
+ case "duplicate":
333
+ if (isRowDrag) {
334
+ table.insertRow("duplicate");
335
+ } else {
336
+ table.duplicateColumn();
337
+ }
338
+ break;
339
+ case "clear":
340
+ if (isRowDrag) {
341
+ table.clearRow();
342
+ } else {
343
+ table.clearColumn();
344
+ }
345
+ break;
346
+ case "insertRight":
347
+ table.insertColumn("after");
348
+ break;
349
+ case "insertLeft":
350
+ table.insertColumn("at");
351
+ break;
352
+ case "color":
353
+ setOpenSettings(dragType);
354
+ break;
355
+ default:
356
+ return;
357
+ }
358
+ const omitValues = ["color", "delete"];
359
+ if (!omitValues.includes(value)) {
360
+ resetSelection();
361
+ }
362
+ };
363
+ const onClose = () => {
364
+ setOpenSettings(false);
365
+ };
366
+ const onSave = data => {
367
+ const updateData = {
368
+ ...data
369
+ };
370
+ delete updateData.children;
371
+ delete updateData.type;
372
+ table.updateTableStyle(updateData, {
373
+ ...tableProps
374
+ });
375
+ onClose();
376
+ };
377
+ const commonDragBtnProps = {
378
+ anchorEl: cellRef,
379
+ handleToolAction,
380
+ customProps,
381
+ dndProps,
382
+ resetSelection
383
+ };
384
+ const showRowDragBtn = (showRowDrag || isRowDragging) && containerEle?.scrollLeft <= 0;
385
+ return /*#__PURE__*/_jsxs(_Fragment, {
386
+ children: [/*#__PURE__*/_jsxs("td", {
387
+ ...element.attr,
388
+ ...attributes,
389
+ className: `editor-table-cell ${hasSelected ? "selection" : ""}`,
390
+ style: {
391
+ position: "relative",
392
+ background: bgColor || entireBgColor,
393
+ border: cellBorderColor ? `3px solid ${cellBorderColor}` : "1px solid #E0E0E0",
394
+ fontFamily: entireFontFamily || "inherit",
395
+ fontWeight: entireFontWeight || "inherit",
396
+ fontSize: entireTextSize || "inherit",
397
+ color: entireTextColor || "inherit",
398
+ cursor: "text",
399
+ verticalAlign: "top",
400
+ padding: "0px",
401
+ ...(sizeProps || {})
402
+ },
403
+ ...tbProps,
404
+ "data-cell": path.toString(),
405
+ children: [isFirstRow && currentDraggingType === "col" ? /*#__PURE__*/_jsx(Droppable, {
406
+ ...dndProps,
407
+ dragType: currentDraggingType,
408
+ tableDOM: tableDOM
409
+ }) : null, isFirstColumn && currentDraggingType === "row" ? /*#__PURE__*/_jsx(Droppable, {
410
+ ...dndProps,
411
+ dragType: currentDraggingType,
412
+ tableDOM: tableDOM
413
+ }) : null, /*#__PURE__*/_jsx("div", {
414
+ style: {
415
+ overflow: "auto hidden",
416
+ padding: "8px"
417
+ },
418
+ children: children
419
+ }), isHeader && !readOnly && tableSize?.height && !showTool ? /*#__PURE__*/_jsx(Resizer, {
420
+ classes: classes,
421
+ onMouseDown: onMouseDown,
422
+ height: tableDOM?.getBoundingClientRect()?.height
423
+ }) : null, hasSelected && !readOnly && !tableResizing ? /*#__PURE__*/_jsx("div", {
424
+ className: "selection-area-tc",
425
+ contentEditable: false
426
+ }) : null, /*#__PURE__*/_jsx(DragButton, {
427
+ ...commonDragBtnProps,
428
+ placement: "top",
429
+ dragType: "col",
430
+ onDrag: onColDrag,
431
+ hideDelete: rowProps?.children?.length <= 1,
432
+ show: showColDrag || isColDragging
433
+ }), /*#__PURE__*/_jsx(DragButton, {
434
+ ...commonDragBtnProps,
435
+ dragType: "row",
436
+ onDrag: onRowDrag,
437
+ hideDelete: parentProps?.children?.length <= 1,
438
+ className: dragRowBtnCls,
439
+ show: showRowDragBtn
440
+ })]
441
+ }), openSettings ? /*#__PURE__*/_jsx(TablePopup, {
442
+ element: tableProps?.styleProps || {},
443
+ customProps: customProps,
444
+ onSave: onSave,
445
+ onClose: onClose,
446
+ styleType: openSettings
447
+ }) : null]
194
448
  });
195
449
  };
196
450
  export default TableCell;
@@ -1,21 +1,27 @@
1
1
  import React from "react";
2
2
  import StyleBuilder from "../../common/StyleBuilder";
3
- import tableStyle from "../../common/StyleBuilder/tableStyle";
3
+ import tableStyle, { tableColumnStyle, tableRowStyle } from "../../common/StyleBuilder/tableStyle";
4
4
  import { jsx as _jsx } from "react/jsx-runtime";
5
+ const STYLE_TYPES = {
6
+ row: tableRowStyle,
7
+ col: tableColumnStyle
8
+ };
5
9
  const TablePopup = props => {
6
10
  const {
7
11
  element,
8
12
  onSave,
9
13
  onClose,
10
- customProps
14
+ customProps,
15
+ styleType
11
16
  } = props;
17
+ const styles = STYLE_TYPES[styleType] || tableStyle;
12
18
  return /*#__PURE__*/_jsx(StyleBuilder, {
13
19
  title: "Table",
14
20
  type: "gridStyle",
15
21
  element: element,
16
22
  onSave: onSave,
17
23
  onClose: onClose,
18
- renderTabs: tableStyle,
24
+ renderTabs: styles,
19
25
  customProps: customProps
20
26
  });
21
27
  };
@@ -10,7 +10,11 @@ const TableRow = props => {
10
10
  } = props;
11
11
  const {
12
12
  bgColor,
13
- borderColor
13
+ borderColor,
14
+ fontFamily,
15
+ fontWeight,
16
+ textSize,
17
+ textColor
14
18
  } = element;
15
19
  const editor = useSlateStatic();
16
20
  const path = ReactEditor.findPath(editor, element);
@@ -24,7 +28,11 @@ const TableRow = props => {
24
28
  ...attributes,
25
29
  style: {
26
30
  backgroundColor: bgColor,
27
- border: rowBorderColor ? `1px solid ${rowBorderColor}` : ""
31
+ border: rowBorderColor ? `1px solid ${rowBorderColor}` : "",
32
+ fontFamily,
33
+ fontWeight,
34
+ fontSize: textSize,
35
+ color: textColor
28
36
  },
29
37
  children: children
30
38
  });
@@ -0,0 +1,101 @@
1
+ import CustomSelect from "../AI/CustomSelect";
2
+ import Styles from "../AI/Styles";
3
+ import { CloseIcon, DeleteIcon } from "../../assets/svg/AIIcons";
4
+ import { AboveArrow, BelowArrow, DuplicateIcon, LeftArrow, PaintIcon, RightArrow } from "../../assets/svg/TableIcons";
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ const wholeTableTools = [{
7
+ group: "",
8
+ groupLabel: "",
9
+ options: [{
10
+ label: "Duplicate",
11
+ value: "duplicate",
12
+ Icon: DuplicateIcon
13
+ }, {
14
+ label: "Delete",
15
+ value: "delete",
16
+ Icon: DeleteIcon
17
+ }]
18
+ }];
19
+ const insertColOptions = [{
20
+ label: "Insert Right",
21
+ value: "insertRight",
22
+ Icon: RightArrow
23
+ }, {
24
+ label: "Insert Left",
25
+ value: "insertLeft",
26
+ Icon: LeftArrow
27
+ }];
28
+ const insertRowOptions = [{
29
+ label: "Insert Above",
30
+ value: "insertAbove",
31
+ Icon: AboveArrow,
32
+ replace: false
33
+ }, {
34
+ label: "Insert Below",
35
+ value: "insertBelow",
36
+ Icon: BelowArrow,
37
+ replace: false
38
+ }];
39
+ function getTools(dragType, hideDelete) {
40
+ const insertOptions = dragType === "col" ? insertColOptions : insertRowOptions;
41
+ const deleteOption = hideDelete ? [] : [{
42
+ label: "Delete",
43
+ value: "delete",
44
+ Icon: DeleteIcon,
45
+ replace: false
46
+ }];
47
+ let tools = [{
48
+ group: "",
49
+ groupLabel: "",
50
+ options: [{
51
+ label: "Color",
52
+ value: "color",
53
+ Icon: PaintIcon
54
+ }, {
55
+ label: "Duplicate",
56
+ value: "duplicate",
57
+ Icon: DuplicateIcon
58
+ }, ...insertOptions, {
59
+ label: "Clear Contents",
60
+ value: "clear",
61
+ Icon: CloseIcon
62
+ }, ...deleteOption]
63
+ }];
64
+ return tools;
65
+ }
66
+ export function TableToolOnDrag({
67
+ theme,
68
+ dragType,
69
+ handleToolAction,
70
+ hideDelete
71
+ }) {
72
+ const classes = Styles(theme);
73
+ const tools = getTools(dragType, hideDelete);
74
+ return /*#__PURE__*/_jsx(CustomSelect, {
75
+ classes: classes,
76
+ show: true,
77
+ options: tools,
78
+ onSend: (value, option) => {
79
+ handleToolAction(value, option, dragType);
80
+ },
81
+ btnProps: {
82
+ onMouseDown: e => e.stopPropagation(),
83
+ onMouseUp: e => e.stopPropagation()
84
+ }
85
+ });
86
+ }
87
+ function TableTool({
88
+ theme,
89
+ handleToolAction
90
+ }) {
91
+ const classes = Styles(theme);
92
+ return /*#__PURE__*/_jsx(CustomSelect, {
93
+ classes: classes,
94
+ show: true,
95
+ options: wholeTableTools,
96
+ onSend: (value, option) => {
97
+ handleToolAction(value, option);
98
+ }
99
+ });
100
+ }
101
+ export default TableTool;