@flozy/editor 4.9.1 → 4.9.3

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 (34) hide show
  1. package/dist/Editor/Editor.css +17 -4
  2. package/dist/Editor/Elements/AI/CustomSelect.js +17 -10
  3. package/dist/Editor/Elements/AI/Styles.js +7 -1
  4. package/dist/Editor/Elements/Embed/Video.js +3 -2
  5. package/dist/Editor/Elements/FreeGrid/FreeGrid.js +1 -1
  6. package/dist/Editor/Elements/Grid/GridItem.js +28 -9
  7. package/dist/Editor/Elements/Grid/Styles.js +1 -0
  8. package/dist/Editor/Elements/Search/SearchAttachment.js +27 -18
  9. package/dist/Editor/Elements/Search/SearchButton.js +66 -9
  10. package/dist/Editor/Elements/Search/SearchList.js +87 -75
  11. package/dist/Editor/Elements/Table/AddRowCol.js +76 -0
  12. package/dist/Editor/Elements/Table/DragButton.js +134 -0
  13. package/dist/Editor/Elements/Table/DragStyles.js +43 -0
  14. package/dist/Editor/Elements/Table/Draggable.js +25 -0
  15. package/dist/Editor/Elements/Table/Droppable.js +53 -0
  16. package/dist/Editor/Elements/Table/Styles.js +23 -41
  17. package/dist/Editor/Elements/Table/Table.js +185 -137
  18. package/dist/Editor/Elements/Table/TableCell.js +339 -101
  19. package/dist/Editor/Elements/Table/TablePopup.js +9 -3
  20. package/dist/Editor/Elements/Table/TableRow.js +10 -2
  21. package/dist/Editor/Elements/Table/TableTool.js +101 -0
  22. package/dist/Editor/Toolbar/PopupTool/index.js +6 -8
  23. package/dist/Editor/assets/svg/DocsIcon.js +77 -10
  24. package/dist/Editor/assets/svg/TableIcons.js +220 -0
  25. package/dist/Editor/assets/svg/UserIcon.js +2 -2
  26. package/dist/Editor/common/RnD/ElementSettings/Settings/FormSettings.js +27 -38
  27. package/dist/Editor/common/StyleBuilder/embedVideoStyle.js +1 -1
  28. package/dist/Editor/common/StyleBuilder/index.js +43 -57
  29. package/dist/Editor/common/StyleBuilder/tableStyle.js +92 -1
  30. package/dist/Editor/common/iconListV2.js +52 -0
  31. package/dist/Editor/hooks/useTable.js +164 -0
  32. package/dist/Editor/utils/helper.js +1 -1
  33. package/dist/Editor/utils/table.js +204 -21
  34. package/package.json +1 -1
@@ -1,3 +1,6 @@
1
+ import { toolbarGroups } from "../../Toolbar/toolbarGroups";
2
+ import { fontOptions } from "../../utils/font";
3
+ import { jsx as _jsx } from "react/jsx-runtime";
1
4
  const tableStyle = [{
2
5
  tab: "Table",
3
6
  value: "tableSettings",
@@ -48,4 +51,92 @@ const tableStyle = [{
48
51
  placeholder: "Hide on Mobile"
49
52
  }]
50
53
  }];
51
- export default tableStyle;
54
+ export default tableStyle;
55
+ const allTools = toolbarGroups.flat();
56
+ const fontWeight = allTools.find(f => f.format === "fontWeight");
57
+ export const tableRowStyle = [{
58
+ tab: "Row",
59
+ value: "rowSettings",
60
+ fields: [{
61
+ label: "Font Family",
62
+ key: "row.fontFamily",
63
+ type: "textOptions",
64
+ webFont: true,
65
+ options: fontOptions,
66
+ renderOption: option => {
67
+ return /*#__PURE__*/_jsx("span", {
68
+ style: {
69
+ fontFamily: option.value
70
+ },
71
+ children: option.text
72
+ });
73
+ }
74
+ }, {
75
+ label: "Font Weight",
76
+ key: "row.fontWeight",
77
+ type: "textOptions",
78
+ options: fontWeight?.options,
79
+ width: 7
80
+ }, {
81
+ label: "Font Size",
82
+ key: "row.textSize",
83
+ type: "fontSize",
84
+ width: 5,
85
+ placeholder: "16px or 1em"
86
+ }, {
87
+ label: "Text Color",
88
+ key: "row.textColor",
89
+ type: "color"
90
+ }, {
91
+ label: "Background",
92
+ key: "row.bgColor",
93
+ type: "color"
94
+ }, {
95
+ label: "Border",
96
+ key: "row.borderColor",
97
+ type: "color"
98
+ }]
99
+ }];
100
+ export const tableColumnStyle = [{
101
+ tab: "Column",
102
+ value: "columnSettings",
103
+ fields: [{
104
+ label: "Font Family",
105
+ key: "col.entireFontFamily",
106
+ type: "textOptions",
107
+ webFont: true,
108
+ options: fontOptions,
109
+ renderOption: option => {
110
+ return /*#__PURE__*/_jsx("span", {
111
+ style: {
112
+ fontFamily: option.value
113
+ },
114
+ children: option.text
115
+ });
116
+ }
117
+ }, {
118
+ label: "Font Weight",
119
+ key: "col.entireFontWeight",
120
+ type: "textOptions",
121
+ options: fontWeight?.options,
122
+ width: 7
123
+ }, {
124
+ label: "Font Size",
125
+ key: "col.entireTextSize",
126
+ type: "fontSize",
127
+ width: 5,
128
+ placeholder: "16px or 1em"
129
+ }, {
130
+ label: "Entire Text Color",
131
+ key: "col.entireTextColor",
132
+ type: "color"
133
+ }, {
134
+ label: "Background",
135
+ key: "col.entireBgColor",
136
+ type: "color"
137
+ }, {
138
+ label: "Border",
139
+ key: "col.entireBorderColor",
140
+ type: "color"
141
+ }]
142
+ }];
@@ -1192,4 +1192,56 @@ export function CodeElementIcon() {
1192
1192
  strokeLinejoin: "round"
1193
1193
  })]
1194
1194
  });
1195
+ }
1196
+ export function DragIcon() {
1197
+ return /*#__PURE__*/_jsxs("svg", {
1198
+ width: "16",
1199
+ height: "12",
1200
+ viewBox: "0 0 10 6",
1201
+ fill: "none",
1202
+ xmlns: "http://www.w3.org/2000/svg",
1203
+ children: [/*#__PURE__*/_jsx("ellipse", {
1204
+ cx: "1.49462",
1205
+ cy: "4.42384",
1206
+ rx: "0.779289",
1207
+ ry: "0.779289",
1208
+ transform: "rotate(-90 1.49462 4.42384)",
1209
+ fill: "#94A3B8"
1210
+ }), /*#__PURE__*/_jsx("ellipse", {
1211
+ cx: "4.99999",
1212
+ cy: "4.42384",
1213
+ rx: "0.779289",
1214
+ ry: "0.779289",
1215
+ transform: "rotate(-90 4.99999 4.42384)",
1216
+ fill: "#94A3B8"
1217
+ }), /*#__PURE__*/_jsx("ellipse", {
1218
+ cx: "8.50732",
1219
+ cy: "4.42384",
1220
+ rx: "0.779289",
1221
+ ry: "0.779289",
1222
+ transform: "rotate(-90 8.50732 4.42384)",
1223
+ fill: "#94A3B8"
1224
+ }), /*#__PURE__*/_jsx("ellipse", {
1225
+ cx: "1.49462",
1226
+ cy: "0.91993",
1227
+ rx: "0.779289",
1228
+ ry: "0.779289",
1229
+ transform: "rotate(-90 1.49462 0.91993)",
1230
+ fill: "#94A3B8"
1231
+ }), /*#__PURE__*/_jsx("ellipse", {
1232
+ cx: "4.99999",
1233
+ cy: "0.91993",
1234
+ rx: "0.779289",
1235
+ ry: "0.779289",
1236
+ transform: "rotate(-90 4.99999 0.91993)",
1237
+ fill: "#94A3B8"
1238
+ }), /*#__PURE__*/_jsx("ellipse", {
1239
+ cx: "8.50732",
1240
+ cy: "0.91993",
1241
+ rx: "0.779289",
1242
+ ry: "0.779289",
1243
+ transform: "rotate(-90 8.50732 0.91993)",
1244
+ fill: "#94A3B8"
1245
+ })]
1246
+ });
1195
1247
  }
@@ -0,0 +1,164 @@
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, PointerSensor, useSensor, useSensors } from "@dnd-kit/core";
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ const handleDragEnd = (dragData, editor, resetAll) => {
8
+ const {
9
+ active,
10
+ over
11
+ } = dragData;
12
+ if (over) {
13
+ const {
14
+ dragType,
15
+ path: startCellPath
16
+ } = active?.data?.current || {};
17
+ const {
18
+ path: overCellPath
19
+ } = over?.data?.current || {};
20
+ if (startCellPath?.length) {
21
+ if (dragType === "row") {
22
+ const startRowPath = startCellPath.slice(0, -1);
23
+ const overRowPath = overCellPath.slice(0, -1);
24
+ Transforms.moveNodes(editor, {
25
+ at: startRowPath,
26
+ to: overRowPath
27
+ });
28
+ } else {
29
+ const [startCol] = startCellPath.slice(-1);
30
+ const [overCol] = overCellPath.slice(-1);
31
+ const [tableData] = Editor.nodes(editor, {
32
+ at: startCellPath,
33
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
34
+ });
35
+ const [tableNode, tablePath] = tableData;
36
+ const rows = tableNode?.rows || 0;
37
+ for (let row = 0; row < rows; row++) {
38
+ const startColPath = [...tablePath, row, startCol];
39
+ const overColPath = [...tablePath, row, overCol];
40
+ Transforms.moveNodes(editor, {
41
+ at: startColPath,
42
+ to: overColPath
43
+ });
44
+ }
45
+ }
46
+ resetAll();
47
+ }
48
+ }
49
+ };
50
+ const getRectangleBounds = tableSelection => {
51
+ const {
52
+ startCellPath,
53
+ endCellPath
54
+ } = tableSelection;
55
+ if (!startCellPath?.length) return [];
56
+ const startPath = startCellPath.slice(0, -2);
57
+ const startCell = startCellPath.slice(-2);
58
+ const endCell = endCellPath.slice(-2);
59
+ const [startRow, startCol] = startCell;
60
+ const [endRow, endCol] = endCell?.length ? endCell : startCell;
61
+ const minRow = Math.min(startRow, endRow);
62
+ const maxRow = Math.max(startRow, endRow);
63
+ const minCol = Math.min(startCol, endCol);
64
+ const maxCol = Math.max(startCol, endCol);
65
+ const selectedPaths = [];
66
+ for (let row = minRow; row <= maxRow; row++) {
67
+ for (let col = minCol; col <= maxCol; col++) {
68
+ selectedPaths.push([...startPath, row, col]);
69
+ }
70
+ }
71
+ return selectedPaths;
72
+ };
73
+ const TableContext = /*#__PURE__*/createContext();
74
+ export function getDefaultTableSelection() {
75
+ return {
76
+ startCellPath: [],
77
+ endCellPath: [],
78
+ isDragging: false
79
+ };
80
+ }
81
+ export const TableProvider = ({
82
+ editor,
83
+ children,
84
+ otherProps
85
+ }) => {
86
+ const [hoverPath, setHoverPath] = useState(null);
87
+ const [tableSelection, setTableSelection] = useState(getDefaultTableSelection());
88
+ const [tableResizing, setTableResizing] = useState(null);
89
+
90
+ // for the button events (like onclick,...etc) inside draggable component to work correctly
91
+ const sensors = useSensors(useSensor(PointerSensor, {
92
+ activationConstraint: {
93
+ delay: 250,
94
+ distance: 0 // throws exceeded distance error
95
+ }
96
+ }));
97
+
98
+ const getSelectedCells = () => {
99
+ return getRectangleBounds(tableSelection);
100
+ };
101
+ const updateTableSelection = update => {
102
+ setTableSelection(prev => ({
103
+ ...prev,
104
+ ...update
105
+ }));
106
+ };
107
+ const resetAll = () => {
108
+ setTableSelection(getDefaultTableSelection());
109
+ Transforms.deselect(editor);
110
+
111
+ // hide drag icons after drag completion
112
+ setTimeout(() => setHoverPath(null), 200);
113
+ };
114
+ const values = useMemo(() => {
115
+ return {
116
+ hoverPath,
117
+ setHoverPath,
118
+ editor,
119
+ getSelectedCells,
120
+ updateTableSelection,
121
+ tableSelection,
122
+ tableResizing,
123
+ setTableResizing,
124
+ otherProps
125
+ };
126
+ }, [hoverPath, editor?.selection, tableSelection, tableResizing]);
127
+ useEffect(() => {
128
+ const handleKeyDown = event => {
129
+ if (event.key === "Backspace") {
130
+ const selectedCells = getSelectedCells();
131
+ if (selectedCells?.length > 1) {
132
+ selectedCells.forEach(currentCellPath => {
133
+ clearCellText(editor, currentCellPath);
134
+ });
135
+ }
136
+ }
137
+ };
138
+ window.addEventListener("keydown", handleKeyDown);
139
+ return () => {
140
+ window.removeEventListener("keydown", handleKeyDown);
141
+ };
142
+ }, [tableSelection]);
143
+ useEffect(() => {
144
+ // on deselect table on insert
145
+ Transforms.deselect(editor);
146
+ }, []);
147
+ return /*#__PURE__*/_jsx(TableContext.Provider, {
148
+ value: values,
149
+ children: /*#__PURE__*/_jsx(ClickAwayListener, {
150
+ onClickAway: () => setTableSelection(getDefaultTableSelection()),
151
+ children: /*#__PURE__*/_jsx(DndContext, {
152
+ sensors: sensors,
153
+ onDragEnd: data => handleDragEnd(data, editor, resetAll),
154
+ children: /*#__PURE__*/_jsx("div", {
155
+ children: children
156
+ })
157
+ })
158
+ })
159
+ });
160
+ };
161
+ function useTable() {
162
+ return useContext(TableContext);
163
+ }
164
+ export default useTable;
@@ -157,7 +157,7 @@ export const isListItem = editor => {
157
157
  });
158
158
  return node;
159
159
  };
160
- const getNode = (editor, path) => {
160
+ export const getNode = (editor, path) => {
161
161
  try {
162
162
  return Node.get(editor, path);
163
163
  } catch (err) {
@@ -1,6 +1,6 @@
1
1
  import { Transforms, Editor, Range, Element, Path, Node } from "slate";
2
2
  import { ReactEditor } from "slate-react";
3
- import { customInsertNode } from "./helper";
3
+ import { customInsertNode, getNode } from "./helper";
4
4
  export const DEFAULT_TABLE_NODE = () => ({
5
5
  type: "table",
6
6
  children: [{
@@ -13,7 +13,10 @@ export const DEFAULT_TABLE_NODE = () => ({
13
13
  text: ""
14
14
  }],
15
15
  cellBgColor: "#FFFFFF"
16
- }]
16
+ }],
17
+ size: {
18
+ width: 120
19
+ }
17
20
  }, {
18
21
  type: "table-cell",
19
22
  children: [{
@@ -22,7 +25,10 @@ export const DEFAULT_TABLE_NODE = () => ({
22
25
  text: ""
23
26
  }],
24
27
  cellBgColor: "#FFFFFF"
25
- }]
28
+ }],
29
+ size: {
30
+ width: 120
31
+ }
26
32
  }, {
27
33
  type: "table-cell",
28
34
  children: [{
@@ -31,7 +37,10 @@ export const DEFAULT_TABLE_NODE = () => ({
31
37
  text: ""
32
38
  }],
33
39
  cellBgColor: "#FFFFFF"
34
- }]
40
+ }],
41
+ size: {
42
+ width: 120
43
+ }
35
44
  }]
36
45
  }, {
37
46
  type: "table-row",
@@ -43,7 +52,10 @@ export const DEFAULT_TABLE_NODE = () => ({
43
52
  text: ""
44
53
  }],
45
54
  cellBgColor: "#FFFFFF"
46
- }]
55
+ }],
56
+ size: {
57
+ width: 120
58
+ }
47
59
  }, {
48
60
  type: "table-cell",
49
61
  children: [{
@@ -52,7 +64,10 @@ export const DEFAULT_TABLE_NODE = () => ({
52
64
  text: ""
53
65
  }],
54
66
  cellBgColor: "#FFFFFF"
55
- }]
67
+ }],
68
+ size: {
69
+ width: 120
70
+ }
56
71
  }, {
57
72
  type: "table-cell",
58
73
  children: [{
@@ -63,9 +78,7 @@ export const DEFAULT_TABLE_NODE = () => ({
63
78
  cellBgColor: "#FFFFFF"
64
79
  }],
65
80
  size: {
66
- widthInPercent: 100,
67
- height: 100,
68
- width: 365.3307291666667
81
+ width: 120
69
82
  }
70
83
  }]
71
84
  }, {
@@ -78,7 +91,10 @@ export const DEFAULT_TABLE_NODE = () => ({
78
91
  text: ""
79
92
  }],
80
93
  cellBgColor: "#FFFFFF"
81
- }]
94
+ }],
95
+ size: {
96
+ width: 120
97
+ }
82
98
  }, {
83
99
  type: "table-cell",
84
100
  children: [{
@@ -87,7 +103,10 @@ export const DEFAULT_TABLE_NODE = () => ({
87
103
  text: ""
88
104
  }],
89
105
  cellBgColor: "#FFFFFF"
90
- }]
106
+ }],
107
+ size: {
108
+ width: 120
109
+ }
91
110
  }, {
92
111
  type: "table-cell",
93
112
  children: [{
@@ -98,14 +117,14 @@ export const DEFAULT_TABLE_NODE = () => ({
98
117
  cellBgColor: "#FFFFFF"
99
118
  }],
100
119
  size: {
101
- height: 300,
102
- widthInPercent: 100
120
+ width: 120
103
121
  }
104
122
  }]
105
123
  }],
106
124
  rows: 3,
107
125
  columns: 3
108
126
  });
127
+ const isFreeGridTable = n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "freegridItem" && n.childType === "table";
109
128
  const prefixKey = (obj, pk = "") => {
110
129
  return Object.keys(obj).reduce((a, b) => {
111
130
  a[`${pk}${b}`] = obj[b];
@@ -144,12 +163,49 @@ export class TableUtil {
144
163
  customInsertNode(this.editor, newTable);
145
164
  };
146
165
  removeTable = () => {
147
- Transforms.removeNodes(this.editor, {
148
- match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
149
- // mode:'highest'
166
+ const [freeGridItem] = Editor.nodes(this.editor, {
167
+ match: isFreeGridTable
150
168
  });
169
+ if (freeGridItem) {
170
+ Transforms.removeNodes(this.editor, {
171
+ match: isFreeGridTable
172
+ });
173
+ } else {
174
+ Transforms.removeNodes(this.editor, {
175
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
176
+ });
177
+ }
178
+ };
179
+ duplicateTable = () => {
180
+ const {
181
+ selection
182
+ } = this.editor;
183
+ if (!!selection && Range.isCollapsed(selection)) {
184
+ const [freeGridItem] = Editor.nodes(this.editor, {
185
+ match: isFreeGridTable
186
+ });
187
+ let clone;
188
+ let path;
189
+ if (freeGridItem) {
190
+ const [freeGridNode, freeGridPath] = freeGridItem;
191
+ clone = freeGridNode;
192
+ path = freeGridPath;
193
+ } else {
194
+ const [[tableNode, tablePath]] = Editor.nodes(this.editor, {
195
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
196
+ });
197
+ clone = tableNode;
198
+ path = tablePath;
199
+ }
200
+ const nextPath = Path.next(path);
201
+ if (clone) {
202
+ const clonedNode = JSON.parse(JSON.stringify(clone));
203
+ Transforms.insertNodes(this.editor, clonedNode, {
204
+ at: nextPath
205
+ });
206
+ }
207
+ }
151
208
  };
152
-
153
209
  getDOMNode = path => {
154
210
  try {
155
211
  const [tableNode] = Editor.nodes(this.editor, {
@@ -186,9 +242,12 @@ export class TableUtil {
186
242
  const [[table, tablePath]] = Editor.nodes(this.editor, {
187
243
  match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
188
244
  });
189
- const [, currentRow] = tableNode;
190
- const path = action === "after" ? Path.next(currentRow) : currentRow;
191
- Transforms.insertNodes(this.editor, createRow(Array(table.columns).fill("")), {
245
+ const [currentRowData, currentRow] = tableNode;
246
+ const isDuplicate = action === "duplicate";
247
+ const isInsertNext = action === "after" || isDuplicate;
248
+ const path = isInsertNext ? Path.next(currentRow) : currentRow;
249
+ const insertData = isDuplicate ? JSON.parse(JSON.stringify(currentRowData)) : createRow(Array(table.columns).fill(""));
250
+ Transforms.insertNodes(this.editor, insertData, {
192
251
  at: path
193
252
  });
194
253
  Transforms.setNodes(this.editor, {
@@ -199,6 +258,23 @@ export class TableUtil {
199
258
  }
200
259
  }
201
260
  };
261
+ clearRow = () => {
262
+ const {
263
+ selection
264
+ } = this.editor;
265
+ if (!!selection && Range.isCollapsed(selection)) {
266
+ const [tableRow] = Editor.nodes(this.editor, {
267
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table-row"
268
+ });
269
+ if (tableRow) {
270
+ const [tableRowNode, tableRowPath] = tableRow;
271
+ tableRowNode?.children?.forEach((cell, index) => {
272
+ const currentCellPath = [...tableRowPath, index];
273
+ clearCellText(this.editor, currentCellPath);
274
+ });
275
+ }
276
+ }
277
+ };
202
278
  deleteRow = () => {
203
279
  try {
204
280
  const {
@@ -259,6 +335,58 @@ export class TableUtil {
259
335
  }
260
336
  }
261
337
  };
338
+ duplicateColumn = () => {
339
+ const {
340
+ selection
341
+ } = this.editor;
342
+ if (!!selection && Range.isCollapsed(selection)) {
343
+ const [tableNode] = Editor.nodes(this.editor, {
344
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table-cell"
345
+ });
346
+ if (tableNode) {
347
+ const [[table, tablePath]] = Editor.nodes(this.editor, {
348
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
349
+ });
350
+ const [, currentCell] = tableNode;
351
+ const currentCellPath = currentCell;
352
+ const insertNextCellPath = Path.next(currentCell);
353
+ for (let row = 0; row < table.rows; row++) {
354
+ currentCellPath[currentCellPath.length - 2] = row;
355
+ insertNextCellPath[insertNextCellPath?.length - 2] = row;
356
+ const cellNode = getNode(this.editor, currentCellPath);
357
+ Transforms.insertNodes(this.editor, JSON.parse(JSON.stringify(cellNode)), {
358
+ at: insertNextCellPath
359
+ });
360
+ }
361
+ Transforms.setNodes(this.editor, {
362
+ columns: table.columns + 1
363
+ }, {
364
+ at: tablePath
365
+ });
366
+ }
367
+ }
368
+ };
369
+ clearColumn = () => {
370
+ const {
371
+ selection
372
+ } = this.editor;
373
+ if (!!selection && Range.isCollapsed(selection)) {
374
+ const [tableNode] = Editor.nodes(this.editor, {
375
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table-cell"
376
+ });
377
+ if (tableNode) {
378
+ const [[table]] = Editor.nodes(this.editor, {
379
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
380
+ });
381
+ const [, currentCell] = tableNode;
382
+ const currentCellPath = currentCell;
383
+ for (let row = 0; row < table.rows; row++) {
384
+ currentCellPath[currentCellPath.length - 2] = row;
385
+ clearCellText(this.editor, currentCellPath);
386
+ }
387
+ }
388
+ }
389
+ };
262
390
  deleteColumn = () => {
263
391
  try {
264
392
  const {
@@ -326,6 +454,7 @@ export class TableUtil {
326
454
  }, {
327
455
  at: currentCellPath
328
456
  });
457
+ applyColumnStyle(this.editor, currentCellPath, currentTablePath, cellProps, tableProps?.rows);
329
458
 
330
459
  // cell bg entire
331
460
  if (cellProps?.entireBgColor || tableProps?.borderColor || rowProps?.borderColor) {
@@ -363,6 +492,18 @@ export class TableUtil {
363
492
  console.log(err);
364
493
  }
365
494
  };
495
+ resizeTableCell = (styleProps, rowNode) => {
496
+ const cellProps = parseByPrefixKey(styleProps, "col.");
497
+ const [rowData, rowPath] = rowNode;
498
+ rowData?.children.forEach((_, i) => {
499
+ const cellPath = [...rowPath, i];
500
+ Transforms.setNodes(this.editor, {
501
+ ...cellProps
502
+ }, {
503
+ at: cellPath
504
+ });
505
+ });
506
+ };
366
507
  getTableProps = () => {
367
508
  const {
368
509
  selection
@@ -500,7 +641,10 @@ export const createTableCell = text => {
500
641
  children: [{
501
642
  text
502
643
  }]
503
- }]
644
+ }],
645
+ size: {
646
+ width: 120
647
+ }
504
648
  };
505
649
  };
506
650
 
@@ -549,4 +693,43 @@ const createTableNode = (cellText, rows, columns) => {
549
693
  columns
550
694
  };
551
695
  return tableNode;
696
+ };
697
+ const columnStyleKeys = ["entireBgColor", "entireBorderColor", "entireTextColor", "entireFontFamily", "entireFontWeight", "entireTextSize"];
698
+ const applyColumnStyle = (editor, currentCellPath, currentTablePath, cellProps, rows) => {
699
+ const colStyle = columnStyleKeys.reduce((acc, key) => {
700
+ const style = cellProps[key];
701
+ if (style) {
702
+ acc[key] = style;
703
+ }
704
+ return acc;
705
+ }, {});
706
+ for (let r = 0; r < rows; r++) {
707
+ const cellPosition = currentCellPath[currentCellPath?.length - 1]; // cell position on each row as per selected column cell
708
+
709
+ Transforms.setNodes(editor, colStyle, {
710
+ at: [...currentTablePath, r, cellPosition]
711
+ });
712
+ }
713
+ };
714
+ export const clearCellText = (editor, currentCellPath) => {
715
+ try {
716
+ const existingCellNode = getNode(editor, currentCellPath);
717
+ Transforms.removeNodes(editor, {
718
+ at: currentCellPath
719
+ });
720
+ Transforms.insertNodes(editor, {
721
+ ...(existingCellNode || {}),
722
+ children: [{
723
+ type: "paragraph",
724
+ children: [{
725
+ text: ""
726
+ }],
727
+ cellBgColor: "#FFFFFF"
728
+ }]
729
+ }, {
730
+ at: currentCellPath
731
+ });
732
+ } catch (err) {
733
+ console.log(err);
734
+ }
552
735
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "4.9.1",
3
+ "version": "4.9.3",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"