@flozy/editor 5.1.5 → 5.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. package/dist/Editor/ChatEditor.js +25 -34
  2. package/dist/Editor/CommonEditor.js +15 -9
  3. package/dist/Editor/Editor.css +56 -12
  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/Styles.js +7 -1
  7. package/dist/Editor/Elements/AppHeader/AppHeader.js +6 -6
  8. package/dist/Editor/Elements/Button/EditorButton.js +1 -1
  9. package/dist/Editor/Elements/Carousel/CarouselItem.js +1 -1
  10. package/dist/Editor/Elements/Color Picker/ColorButtons.js +7 -5
  11. package/dist/Editor/Elements/Color Picker/Styles.js +7 -3
  12. package/dist/Editor/Elements/Color Picker/defaultColors.js +2 -2
  13. package/dist/Editor/Elements/DataView/DataView.js +109 -0
  14. package/dist/Editor/Elements/DataView/DataViewButton.js +23 -0
  15. package/dist/Editor/Elements/DataView/Layouts/ColumnView.js +66 -0
  16. package/dist/Editor/Elements/DataView/Layouts/DataTypes/CheckType.js +30 -0
  17. package/dist/Editor/Elements/DataView/Layouts/DataTypes/Components/Select.js +162 -0
  18. package/dist/Editor/Elements/DataView/Layouts/DataTypes/Components/SimpleSelect.js +40 -0
  19. package/dist/Editor/Elements/DataView/Layouts/DataTypes/Components/styles.js +67 -0
  20. package/dist/Editor/Elements/DataView/Layouts/DataTypes/DateType.js +30 -0
  21. package/dist/Editor/Elements/DataView/Layouts/DataTypes/MultiSelectType.js +39 -0
  22. package/dist/Editor/Elements/DataView/Layouts/DataTypes/NumberType.js +30 -0
  23. package/dist/Editor/Elements/DataView/Layouts/DataTypes/PersonType.js +30 -0
  24. package/dist/Editor/Elements/DataView/Layouts/DataTypes/SelectType.js +35 -0
  25. package/dist/Editor/Elements/DataView/Layouts/DataTypes/TextType.js +36 -0
  26. package/dist/Editor/Elements/DataView/Layouts/DataTypes/index.js +17 -0
  27. package/dist/Editor/Elements/DataView/Layouts/FilterSort/SortOptions/ChooseField.js +29 -0
  28. package/dist/Editor/Elements/DataView/Layouts/FilterSort/SortOptions/ChooseSort.js +38 -0
  29. package/dist/Editor/Elements/DataView/Layouts/FilterSort/SortOptions/index.js +74 -0
  30. package/dist/Editor/Elements/DataView/Layouts/FilterSort/index.js +64 -0
  31. package/dist/Editor/Elements/DataView/Layouts/FilterSort/styles.js +106 -0
  32. package/dist/Editor/Elements/DataView/Layouts/FilterView.js +174 -0
  33. package/dist/Editor/Elements/DataView/Layouts/Formula.js +29 -0
  34. package/dist/Editor/Elements/DataView/Layouts/Options/AddOptions.js +113 -0
  35. package/dist/Editor/Elements/DataView/Layouts/Options/AddProperty.js +37 -0
  36. package/dist/Editor/Elements/DataView/Layouts/Options/AllProperties.js +111 -0
  37. package/dist/Editor/Elements/DataView/Layouts/Options/ChangeProperty.js +60 -0
  38. package/dist/Editor/Elements/DataView/Layouts/Options/ColumnsList.js +36 -0
  39. package/dist/Editor/Elements/DataView/Layouts/Options/Constants.js +101 -0
  40. package/dist/Editor/Elements/DataView/Layouts/Options/EditOption.js +160 -0
  41. package/dist/Editor/Elements/DataView/Layouts/Options/EditProperty.js +190 -0
  42. package/dist/Editor/Elements/DataView/Layouts/Options/FilterProperty.js +42 -0
  43. package/dist/Editor/Elements/DataView/Layouts/Options/PropertyList.js +30 -0
  44. package/dist/Editor/Elements/DataView/Layouts/Options/index.js +110 -0
  45. package/dist/Editor/Elements/DataView/Layouts/Options/styles.js +179 -0
  46. package/dist/Editor/Elements/DataView/Layouts/TableStyles.js +112 -0
  47. package/dist/Editor/Elements/DataView/Layouts/TableView.js +227 -0
  48. package/dist/Editor/Elements/DataView/Layouts/ViewData.js +70 -0
  49. package/dist/Editor/Elements/DataView/Layouts/index.js +25 -0
  50. package/dist/Editor/Elements/DataView/Providers/DataViewProvider.js +288 -0
  51. package/dist/Editor/Elements/DataView/Utils/globalSearch.js +15 -0
  52. package/dist/Editor/Elements/DataView/Utils/multiSortRows.js +72 -0
  53. package/dist/Editor/Elements/DataView/styles.js +143 -0
  54. package/dist/Editor/Elements/Divider/Divider.js +15 -14
  55. package/dist/Editor/Elements/Form/Form.js +38 -2
  56. package/dist/Editor/Elements/Form/FormElements/FormCheckbox.js +7 -1
  57. package/dist/Editor/Elements/Form/FormElements/FormDate.js +7 -1
  58. package/dist/Editor/Elements/Form/FormElements/FormEmail.js +7 -1
  59. package/dist/Editor/Elements/Form/FormElements/FormNumbers.js +7 -1
  60. package/dist/Editor/Elements/Form/FormElements/FormRadioButton.js +7 -1
  61. package/dist/Editor/Elements/Form/FormElements/FormText.js +7 -1
  62. package/dist/Editor/Elements/Form/FormElements/FormTextArea.js +6 -1
  63. package/dist/Editor/Elements/Form/FormPopup.js +12 -9
  64. package/dist/Editor/Elements/FreeGrid/FreeGrid.js +1 -1
  65. package/dist/Editor/Elements/FreeGrid/FreeGridItem.js +20 -1
  66. package/dist/Editor/Elements/FreeGrid/breakpointConstants.js +4 -4
  67. package/dist/Editor/Elements/FreeGrid/styles.js +1 -1
  68. package/dist/Editor/Elements/Grid/GridButton.js +2 -2
  69. package/dist/Editor/Elements/Grid/GridItem.js +21 -18
  70. package/dist/Editor/Elements/Link/LinkButton.js +1 -1
  71. package/dist/Editor/Elements/Signature/Signature.css +1 -1
  72. package/dist/Editor/Elements/Signature/SignatureOptions/TypeSignature.js +2 -2
  73. package/dist/Editor/Elements/Signature/SignaturePopup.js +13 -48
  74. package/dist/Editor/Elements/SimpleText/index.js +8 -1
  75. package/dist/Editor/Elements/SimpleText/style.js +13 -1
  76. package/dist/Editor/Elements/Table/AddRowCol.js +77 -0
  77. package/dist/Editor/Elements/Table/DragButton.js +141 -0
  78. package/dist/Editor/Elements/Table/DragStyles.js +70 -0
  79. package/dist/Editor/Elements/Table/Draggable.js +25 -0
  80. package/dist/Editor/Elements/Table/Droppable.js +53 -0
  81. package/dist/Editor/Elements/Table/Styles.js +25 -43
  82. package/dist/Editor/Elements/Table/Table.js +205 -138
  83. package/dist/Editor/Elements/Table/TableCell.js +355 -102
  84. package/dist/Editor/Elements/Table/TablePopup.js +9 -3
  85. package/dist/Editor/Elements/Table/TableRow.js +10 -2
  86. package/dist/Editor/Elements/Table/TableTool.js +101 -0
  87. package/dist/Editor/Elements/Table/tableHelper.js +71 -0
  88. package/dist/Editor/Styles/EditorStyles.js +3 -1
  89. package/dist/Editor/Toolbar/FormatTools/BlockButton.js +10 -0
  90. package/dist/Editor/Toolbar/FormatTools/Dropdown.js +7 -12
  91. package/dist/Editor/Toolbar/FormatTools/FontFamilyAutocomplete.js +10 -4
  92. package/dist/Editor/Toolbar/FormatTools/MarkButton.js +3 -0
  93. package/dist/Editor/Toolbar/FormatTools/TextSize.js +0 -2
  94. package/dist/Editor/Toolbar/Mini/MiniToolbar.js +3 -6
  95. package/dist/Editor/Toolbar/Mini/Styles.js +4 -1
  96. package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/index.js +3 -3
  97. package/dist/Editor/Toolbar/PopupTool/PopperHeader.js +19 -15
  98. package/dist/Editor/Toolbar/PopupTool/PopupToolStyle.js +411 -49
  99. package/dist/Editor/Toolbar/PopupTool/TextFormat.js +62 -8
  100. package/dist/Editor/Toolbar/PopupTool/index.js +5 -6
  101. package/dist/Editor/Toolbar/Toolbar.js +6 -0
  102. package/dist/Editor/Toolbar/toolbarGroups.js +4 -0
  103. package/dist/Editor/assets/svg/BrainIcon.js +2 -2
  104. package/dist/Editor/assets/svg/TableIcons.js +220 -0
  105. package/dist/Editor/common/ColorPickerButton.js +3 -2
  106. package/dist/Editor/common/FontLoader/FontLoader.js +4 -4
  107. package/dist/Editor/common/Icon.js +20 -19
  108. package/dist/Editor/common/LinkSettings/NavComponents.js +2 -1
  109. package/dist/Editor/common/LinkSettings/index.js +2 -1
  110. package/dist/Editor/common/MentionsPopup/Styles.js +152 -8
  111. package/dist/Editor/common/MentionsPopup/index.js +1 -1
  112. package/dist/Editor/common/RnD/ElementSettings/Settings/FormSettings.js +108 -12
  113. package/dist/Editor/common/RnD/GuideLines/styles.js +3 -3
  114. package/dist/Editor/common/RnD/ShadowElement.js +1 -1
  115. package/dist/Editor/common/RnD/SwitchViewport/SwitchViewport.js +14 -2
  116. package/dist/Editor/common/Select/index.js +20 -0
  117. package/dist/Editor/common/Select/styles.js +17 -0
  118. package/dist/Editor/common/Shorthands/elements.js +13 -1
  119. package/dist/Editor/common/StyleBuilder/fieldTypes/backgroundImage.js +5 -0
  120. package/dist/Editor/common/StyleBuilder/fieldTypes/bannerSpacing.js +8 -4
  121. package/dist/Editor/common/StyleBuilder/fieldTypes/card.js +10 -2
  122. package/dist/Editor/common/StyleBuilder/fieldTypes/index.js +3 -1
  123. package/dist/Editor/common/StyleBuilder/fieldTypes/lineSpacing.js +79 -0
  124. package/dist/Editor/common/StyleBuilder/fieldTypes/radiusStyle.js +7 -7
  125. package/dist/Editor/common/StyleBuilder/fieldTypes/textOptions.js +5 -2
  126. package/dist/Editor/common/StyleBuilder/formStyle.js +268 -149
  127. package/dist/Editor/common/StyleBuilder/index.js +84 -11
  128. package/dist/Editor/common/StyleBuilder/pageSettingsStyle.js +4 -0
  129. package/dist/Editor/common/StyleBuilder/tableStyle.js +69 -25
  130. package/dist/Editor/common/SwipeableDrawer/style.js +15 -4
  131. package/dist/Editor/common/Uploader.js +8 -0
  132. package/dist/Editor/common/iconListV2.js +378 -40
  133. package/dist/Editor/common/iconslist.js +23 -17
  134. package/dist/Editor/commonStyle.js +126 -9
  135. package/dist/Editor/helper/deserialize/index.js +4 -1
  136. package/dist/Editor/helper/index.js +2 -2
  137. package/dist/Editor/helper/theme.js +24 -1
  138. package/dist/Editor/hooks/useMouseMove.js +5 -2
  139. package/dist/Editor/hooks/useTable.js +195 -0
  140. package/dist/Editor/plugins/withCustomDeleteBackward.js +3 -2
  141. package/dist/Editor/plugins/withHTML.js +17 -1
  142. package/dist/Editor/plugins/withLayout.js +48 -1
  143. package/dist/Editor/utils/SlateUtilityFunctions.js +18 -0
  144. package/dist/Editor/utils/button.js +4 -4
  145. package/dist/Editor/utils/chatEditor/SlateUtilityFunctions.js +21 -0
  146. package/dist/Editor/utils/dataView.js +43 -0
  147. package/dist/Editor/utils/embed.js +2 -1
  148. package/dist/Editor/utils/events.js +0 -1
  149. package/dist/Editor/utils/font.js +11 -4
  150. package/dist/Editor/utils/formfield.js +8 -4
  151. package/dist/Editor/utils/helper.js +67 -2
  152. package/dist/Editor/utils/insertNewLine.js +19 -1
  153. package/dist/Editor/utils/pageSettings.js +14 -2
  154. package/dist/Editor/utils/serializeToText.js +2 -0
  155. package/dist/Editor/utils/table.js +228 -24
  156. package/package.json +1 -1
@@ -1,12 +1,16 @@
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, Element, 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";
10
14
  import { jsx as _jsx } from "react/jsx-runtime";
11
15
  import { Fragment as _Fragment } from "react/jsx-runtime";
12
16
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -28,9 +32,14 @@ const Resizer = ({
28
32
  })
29
33
  });
30
34
  };
35
+ const isCellEditable = (startCellPath, path) => {
36
+ return startCellPath?.length && startCellPath?.toString() === path?.toString();
37
+ };
31
38
  const TableCell = props => {
32
- const themeType = localStorage.getItem("themeType");
33
- const classes = TableStyles(themeType);
39
+ const {
40
+ theme
41
+ } = useEditorContext();
42
+ const classes = TableStyles(theme);
34
43
  const {
35
44
  element,
36
45
  attributes,
@@ -44,11 +53,36 @@ const TableCell = props => {
44
53
  bgColor,
45
54
  borderColor,
46
55
  entireBgColor,
47
- entireBorderColor
56
+ entireBorderColor,
57
+ entireTextColor,
58
+ entireFontFamily,
59
+ entireFontWeight,
60
+ entireTextSize
48
61
  } = element;
49
62
  const [parentDOM, setParentDOM] = useState(null);
50
63
  const editor = useSlateStatic();
51
64
  const [showTool] = useEditorSelection(editor);
65
+ const {
66
+ hoverPath,
67
+ setHoverPath,
68
+ getSelectedCells,
69
+ updateTableSelection,
70
+ tableSelection,
71
+ tableResizing,
72
+ setTableResizing,
73
+ otherProps
74
+ } = useTable();
75
+ const {
76
+ active,
77
+ over
78
+ } = useDndContext();
79
+ const currentDraggingType = active?.data?.current?.dragType;
80
+ const {
81
+ dragRowBtnCls
82
+ } = otherProps || {};
83
+ const {
84
+ startCellPath
85
+ } = tableSelection;
52
86
  const path = ReactEditor.findPath(editor, element);
53
87
  const isHeader = path.length >= 2 ? path[path.length - 2] === 0 : false;
54
88
  const [size, onMouseDown, resizing, onLoad] = useTableResize({
@@ -56,6 +90,7 @@ const TableCell = props => {
56
90
  size: element?.size
57
91
  });
58
92
  const [tableSize, setTableSize] = useState({});
93
+ const [openSettings, setOpenSettings] = useState(false);
59
94
  const table = new TableUtil(editor);
60
95
  const tableProps = table.getTableProps();
61
96
  const [tableNode] = Editor.nodes(editor, {
@@ -66,47 +101,19 @@ const TableCell = props => {
66
101
  at: path,
67
102
  match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table-row"
68
103
  });
104
+ const currentPath = path.slice(-2) || []; // getting last 2 items from path, which gives row and column position of the cell
105
+ const [row, column] = currentPath;
106
+ const isFirstRow = row === 0;
107
+ const isFirstColumn = column === 0;
108
+ const [hoverRow, hoverCol] = hoverPath ? hoverPath.slice(-2) : [];
109
+ const showColDrag = isFirstRow && hoverCol === column && !resizing && !readOnly;
110
+ const showRowDrag = isFirstColumn && hoverRow === row && !resizing && !readOnly;
69
111
  const [parentProps] = tableNode || [{}];
70
112
  const [rowProps] = rowNode || [{}];
71
113
  const tableDOM = table.getDOMNode(path, true);
72
- const isCellSelected = table.isCellSelected(editor.selection);
114
+ const isCellSelected = getSelectedCells();
73
115
  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];
116
+ const containerEle = tableDOM?.parentNode?.parentNode;
110
117
  useEffect(() => {
111
118
  if (tableDOM) {
112
119
  const {
@@ -116,81 +123,327 @@ const TableCell = props => {
116
123
  const {
117
124
  width: parentWidth
118
125
  } = tableDOM?.parentNode?.parentNode?.getBoundingClientRect();
119
- const {
120
- styleProps
121
- } = tableProps || {};
122
- const columns = styleProps ? styleProps["table.columns"] : 2;
126
+ const cellWidth = element?.size?.width;
127
+ const columns = tableNode?.[0]?.columns;
128
+ const oldTableWidth = parentWidth / columns - 4;
123
129
  setTableSize({
124
130
  width,
125
131
  height,
126
132
  parentWidth,
127
- cellWidth: parentWidth / columns
133
+ cellWidth: cellWidth || oldTableWidth
128
134
  });
129
135
  }
130
- }, [tableDOM, anchorEl]);
136
+ }, [tableDOM]);
131
137
  useEffect(() => {
132
138
  if (editor && element && tableSize) {
133
139
  const dom = ReactEditor.toDOMNode(editor, element);
134
140
  setParentDOM(dom);
135
- onLoad(element?.size || {
136
- width: tableSize?.cellWidth,
141
+ const width = tableSize?.cellWidth;
142
+ const size = element?.size ? {
143
+ ...element?.size,
144
+ width
145
+ } : {
146
+ width,
137
147
  height: 100
138
- });
148
+ };
149
+ onLoad(size);
139
150
  }
140
- }, [tableSize, anchorEl]);
151
+ }, [tableSize]);
152
+ const resetSelection = () => {
153
+ Transforms.deselect(editor);
154
+ updateTableSelection(getDefaultTableSelection());
155
+ };
141
156
  useEffect(() => {
142
- if (!resizing && tableProps) {
143
- table.updateTableStyle({
157
+ const currentPath = path?.toString();
158
+ setTimeout(() => {
159
+ if (tableResizing === currentPath) {
160
+ setTableResizing(null);
161
+
162
+ // reset selection after resizing
163
+ resetSelection();
164
+ }
165
+ }, 200);
166
+ if (!resizing && tableResizing) {
167
+ table.resizeTableCell({
144
168
  "col.size": size
145
- }, tableProps);
169
+ }, path);
170
+ }
171
+ if (resizing) {
172
+ setTableResizing(currentPath);
173
+ }
174
+ }, [resizing]);
175
+ const onMouseEnter = path => {
176
+ setHoverPath(path);
177
+ if (tableSelection?.isDragging) {
178
+ updateTableSelection({
179
+ endCellPath: path
180
+ });
181
+ const isSelectingOneCellToAnotherCell = startCellPath?.length && !Path.equals(path, startCellPath);
182
+ if (isSelectingOneCellToAnotherCell) {
183
+ Transforms.deselect(editor);
184
+ }
185
+ }
186
+ };
187
+ const onMouseLeave = () => {
188
+ setHoverPath(null);
189
+ };
190
+ const onMouseDownInCell = e => {
191
+ if (
192
+ // for shift selection
193
+ e.shiftKey && startCellPath?.length && startCellPath.toString() !== path.toString()) {
194
+ updateTableSelection({
195
+ endCellPath: path
196
+ });
197
+ } else {
198
+ updateTableSelection({
199
+ startCellPath: path,
200
+ endCellPath: [],
201
+ isDragging: true
202
+ });
203
+ }
204
+ };
205
+ const onMouseUp = () => {
206
+ if (startCellPath?.length) {
207
+ updateTableSelection({
208
+ endCellPath: path,
209
+ isDragging: false
210
+ });
211
+ }
212
+ };
213
+ const onClick = () => {
214
+ const currentEditorSelection = editor?.selection?.focus?.path || [];
215
+ const selectionPath = currentEditorSelection?.slice(0, -2);
216
+ const isCellSelected = selectionPath?.length && Path.equals(selectionPath, path);
217
+ if (!isCellSelected) {
218
+ // 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.
219
+ updateTableSelection({
220
+ isDragging: false
221
+ });
146
222
  }
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))
223
+ };
224
+ const cellId = "table-cell" + path.toString();
225
+ const cellRef = document.getElementById(cellId);
226
+ const contentEditable = !readOnly && isCellEditable(startCellPath, path);
227
+ const commonTdProps = useMemo(() => {
228
+ const props = {
229
+ id: cellId
230
+ };
231
+
232
+ // if (!contentEditable) {
233
+ // props.contentEditable = false;
234
+ // }
235
+
236
+ return props;
237
+ }, [contentEditable, cellId]);
238
+ const handleTouchMove = e => {
239
+ const touch = e.touches[0]; // Get the current touch point
240
+ const element = document.elementFromPoint(touch.clientX, touch.clientY);
241
+ if (element && element.dataset.cell) {
242
+ const elementPath = element.dataset.cell.split(",").map(Number);
243
+ onMouseEnter(elementPath);
244
+ }
245
+ };
246
+ const handleTouchEnd = () => {
247
+ updateTableSelection({
248
+ isDragging: false
169
249
  });
170
250
  };
171
- const sizeProps = isHeader ? {
172
- width: size?.width || tableSize?.cellWidth
173
- } : {};
251
+ const tbProps = tableResizing || resizing || over || readOnly ? {
252
+ ...commonTdProps,
253
+ contentEditable: false
254
+ } : {
255
+ ...commonTdProps,
256
+ onMouseEnter: () => onMouseEnter(path),
257
+ onMouseLeave,
258
+ onMouseDown: onMouseDownInCell,
259
+ onMouseUp,
260
+ onClick,
261
+ // mobile events for selection
262
+ onTouchStart: onMouseDownInCell,
263
+ onTouchMove: handleTouchMove,
264
+ onTouchEnd: handleTouchEnd
265
+ };
266
+ const dndProps = {
267
+ id: cellId,
268
+ data: {
269
+ path
270
+ }
271
+ };
272
+ const isCellDragging = active?.id && active?.id === cellId;
273
+ const isRowDragging = isCellDragging && currentDraggingType === "row";
274
+ const isColDragging = isCellDragging && currentDraggingType === "col";
275
+ const width = isHeader ? size?.width || tableSize?.cellWidth : "0px";
276
+ const sizeProps = {
277
+ minWidth: width,
278
+ maxWidth: width
279
+ };
174
280
  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()]
281
+ const selectCurrentCell = () => {
282
+ const cellPath = Editor.start(editor, path);
283
+ const selection = {
284
+ anchor: cellPath,
285
+ focus: cellPath
286
+ };
287
+
288
+ // select the cell to insert/delete/duplicate/clear
289
+ Transforms.select(editor, selection);
290
+ };
291
+ const onRowDrag = () => {
292
+ const {
293
+ children
294
+ } = rowNode[0] || {};
295
+ const rowPath = rowNode[1] || [];
296
+ const rowStartCell = [...rowPath, 0];
297
+ const rowEndCell = [...rowPath, children?.length - 1];
298
+ updateTableSelection({
299
+ startCellPath: rowStartCell,
300
+ endCellPath: rowEndCell,
301
+ isDragging: false
302
+ });
303
+ selectCurrentCell();
304
+ };
305
+ const onColDrag = () => {
306
+ const [tableData, tablePath] = tableNode;
307
+ const {
308
+ rows
309
+ } = tableData;
310
+ const startColCell = [...tablePath, 0, column];
311
+ const endColCell = [...tablePath, rows - 1, column];
312
+ updateTableSelection({
313
+ startCellPath: startColCell,
314
+ endCellPath: endColCell,
315
+ isDragging: false
316
+ });
317
+ selectCurrentCell();
318
+ };
319
+ const handleToolAction = (value, option, dragType) => {
320
+ const isRowDrag = dragType === "row";
321
+ switch (value) {
322
+ case "insertAbove":
323
+ table.insertRow("at");
324
+ break;
325
+ case "insertBelow":
326
+ table.insertRow("after");
327
+ break;
328
+ case "delete":
329
+ const deleteFn = isRowDrag ? table.deleteRow : table.deleteColumn;
330
+ deleteFn();
331
+ setTimeout(() => resetSelection(), 200); // throws cannot find the descendant path error because of deletion
332
+ break;
333
+ case "duplicate":
334
+ if (isRowDrag) {
335
+ table.insertRow("duplicate");
336
+ } else {
337
+ table.duplicateColumn();
338
+ }
339
+ break;
340
+ case "clear":
341
+ if (isRowDrag) {
342
+ table.clearRow();
343
+ } else {
344
+ table.clearColumn();
345
+ }
346
+ break;
347
+ case "insertRight":
348
+ table.insertColumn("after");
349
+ break;
350
+ case "insertLeft":
351
+ table.insertColumn("at");
352
+ break;
353
+ case "color":
354
+ setOpenSettings(dragType);
355
+ break;
356
+ default:
357
+ return;
358
+ }
359
+ const omitValues = ["color", "delete"];
360
+ if (!omitValues.includes(value)) {
361
+ resetSelection();
362
+ }
363
+ };
364
+ const onClose = () => {
365
+ setOpenSettings(false);
366
+ };
367
+ const onSave = data => {
368
+ const updateData = {
369
+ ...data
370
+ };
371
+ delete updateData.children;
372
+ delete updateData.type;
373
+ table.updateTableStyle(updateData, {
374
+ ...tableProps
375
+ });
376
+ onClose();
377
+ };
378
+ const commonDragBtnProps = {
379
+ anchorEl: cellRef,
380
+ handleToolAction,
381
+ customProps,
382
+ dndProps,
383
+ resetSelection
384
+ };
385
+ const showRowDragBtn = (showRowDrag || isRowDragging) && containerEle?.scrollLeft <= 0;
386
+ return /*#__PURE__*/_jsxs(_Fragment, {
387
+ children: [/*#__PURE__*/_jsxs("td", {
388
+ ...element.attr,
389
+ ...attributes,
390
+ className: `editor-table-cell ${hasSelected ? "selection" : ""}`,
391
+ style: {
392
+ position: "relative",
393
+ background: bgColor || entireBgColor,
394
+ border: cellBorderColor ? `3px solid ${cellBorderColor}` : "1px solid #E0E0E0",
395
+ fontFamily: entireFontFamily || "inherit",
396
+ fontWeight: entireFontWeight || "inherit",
397
+ fontSize: entireTextSize || "inherit",
398
+ color: entireTextColor || "inherit",
399
+ cursor: "text",
400
+ verticalAlign: "top",
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
+ },
417
+ children: children
418
+ }), isHeader && !readOnly && tableSize?.height && !showTool ? /*#__PURE__*/_jsx(Resizer, {
419
+ classes: classes,
420
+ onMouseDown: onMouseDown,
421
+ height: tableDOM.getBoundingClientRect()?.height
422
+ }) : null, hasSelected && !readOnly && !tableResizing ? /*#__PURE__*/_jsx("div", {
423
+ className: "selection-area-tc",
424
+ contentEditable: false
425
+ }) : null, /*#__PURE__*/_jsx(DragButton, {
426
+ ...commonDragBtnProps,
427
+ placement: "top",
428
+ dragType: "col",
429
+ onDrag: onColDrag,
430
+ hideDelete: rowProps?.children?.length <= 1,
431
+ show: showColDrag || isColDragging
432
+ }), /*#__PURE__*/_jsx(DragButton, {
433
+ ...commonDragBtnProps,
434
+ dragType: "row",
435
+ onDrag: onRowDrag,
436
+ hideDelete: parentProps?.children?.length <= 1,
437
+ className: dragRowBtnCls,
438
+ show: showRowDragBtn
439
+ })]
440
+ }), openSettings ? /*#__PURE__*/_jsx(TablePopup, {
441
+ element: tableProps?.styleProps || {},
442
+ customProps: customProps,
443
+ onSave: onSave,
444
+ onClose: onClose,
445
+ styleType: openSettings
446
+ }) : null]
194
447
  });
195
448
  };
196
449
  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;