@flozy/editor 10.9.3 → 10.9.4

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.
@@ -291,7 +291,8 @@ const Table = props => {
291
291
  dragRowBtnCls,
292
292
  tablePath: path,
293
293
  openSetttings,
294
- exandTools
294
+ exandTools,
295
+ tableNode: element
295
296
  },
296
297
  children: [/*#__PURE__*/_jsxs("div", {
297
298
  style: {
@@ -25,6 +25,63 @@ import { createCopiedTableStructure, getRectangleBounds, tableNodeToDom } from "
25
25
  // };
26
26
  import { jsx as _jsx } from "react/jsx-runtime";
27
27
  import { jsxs as _jsxs } from "react/jsx-runtime";
28
+ function moveToAdjacentTableCell(editor, reverse = false, otherProps, tableSelection, updateTableSelection) {
29
+ try {
30
+ const {
31
+ startCellPath,
32
+ endCellPath
33
+ } = tableSelection;
34
+ if (startCellPath && startCellPath.toString() === endCellPath.toString()) {
35
+ const {
36
+ tableNode,
37
+ tablePath
38
+ } = otherProps;
39
+ const cellPath = startCellPath.slice(tablePath.length - 1);
40
+ const rows = tableNode.children;
41
+ const currentRowIndex = cellPath[1];
42
+ const currentColIndex = cellPath[2];
43
+ const numRows = rows.length;
44
+ const numCols = rows[0]?.children?.length || 0;
45
+
46
+ // Calculate new indices
47
+ let newRowIndex = currentRowIndex;
48
+ let newColIndex = currentColIndex;
49
+ if (reverse) {
50
+ // ALT + TAB: Go to previous cell
51
+ if (currentColIndex > 0) {
52
+ newColIndex--;
53
+ } else if (currentRowIndex > 0) {
54
+ newRowIndex--;
55
+ newColIndex = rows[newRowIndex].children.length - 1;
56
+ } else {
57
+ return; // At first cell, do nothing
58
+ }
59
+ } else {
60
+ // TAB: Go to next cell
61
+ if (currentColIndex < numCols - 1) {
62
+ newColIndex++;
63
+ } else if (currentRowIndex < numRows - 1) {
64
+ newRowIndex++;
65
+ newColIndex = 0;
66
+ } else {
67
+ return; // At last cell, do nothing
68
+ }
69
+ }
70
+
71
+ const nextCellPath = [...tablePath, newRowIndex, newColIndex];
72
+
73
+ // Move the selection into the next cell
74
+ Transforms.select(editor, Editor.start(editor, nextCellPath));
75
+ updateTableSelection({
76
+ startCellPath: nextCellPath,
77
+ endCellPath: nextCellPath,
78
+ isDragging: false
79
+ });
80
+ }
81
+ } catch (err) {
82
+ console.log("Error on pressing tab in table", err);
83
+ }
84
+ }
28
85
  const handleDragEnd = (dragData, editor, resetAll) => {
29
86
  const {
30
87
  active,
@@ -127,7 +184,11 @@ export const TableProvider = ({
127
184
  let isTextSelected;
128
185
  const handleKeyDown = event => {
129
186
  const isCutKey = (event.ctrlKey || event.metaKey) && event.key === "x";
130
- if (isCutKey) {
187
+ if (event.key === "Tab") {
188
+ event.preventDefault();
189
+ const isReverse = event.altKey;
190
+ moveToAdjacentTableCell(editor, isReverse, otherProps, tableSelection, updateTableSelection);
191
+ } else if (isCutKey) {
131
192
  isTextSelected = isHavingSelection(editor);
132
193
  } else if (event.key === "Backspace") {
133
194
  const selectedCells = getSelectedCells();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "10.9.3",
3
+ "version": "10.9.4",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"