From 6eea921820a2c12bcd08d7b65212037f84421fbc Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 7 Sep 2025 21:23:04 +0300 Subject: [PATCH] chore(react/collections/table): bring back dragging rows --- .../src/widgets/collections/table/editing.ts | 21 ++++++++++++++++ .../src/widgets/collections/table/index.tsx | 3 +-- .../view_widgets/table_view/dragging.ts | 25 ------------------- 3 files changed, 22 insertions(+), 27 deletions(-) delete mode 100644 apps/client/src/widgets/view_widgets/table_view/dragging.ts diff --git a/apps/client/src/widgets/collections/table/editing.ts b/apps/client/src/widgets/collections/table/editing.ts index e71aa7bb4..b8d66ea7f 100644 --- a/apps/client/src/widgets/collections/table/editing.ts +++ b/apps/client/src/widgets/collections/table/editing.ts @@ -6,6 +6,8 @@ import { RefObject } from "preact"; import { setAttribute, setLabel } from "../../../services/attributes"; import froca from "../../../services/froca"; import server from "../../../services/server"; +import FNote from "../../../entities/fnote"; +import branches from "../../../services/branches"; export default function useTableEditing(api: RefObject, parentNotePath: string): Partial { // Adding new rows @@ -55,6 +57,20 @@ export default function useTableEditing(api: RefObject, parentNotePat } } } + }, + rowMoved(row) { + const branchIdsToMove = [ row.getData().branchId ]; + + const prevRow = row.getPrevRow(); + if (prevRow) { + branches.moveAfterBranch(branchIdsToMove, prevRow.getData().branchId); + return; + } + + const nextRow = row.getNextRow(); + if (nextRow) { + branches.moveBeforeBranch(branchIdsToMove, nextRow.getData().branchId); + } } }; } @@ -87,3 +103,8 @@ function findRowDataById(rows: RowComponent[], branchId: string): RowComponent | } return null; } + +export function canReorderRows(parentNote: FNote) { + return !parentNote.hasLabel("sorted") + && parentNote.type !== "search"; +} diff --git a/apps/client/src/widgets/collections/table/index.tsx b/apps/client/src/widgets/collections/table/index.tsx index f880d4873..532622982 100644 --- a/apps/client/src/widgets/collections/table/index.tsx +++ b/apps/client/src/widgets/collections/table/index.tsx @@ -3,7 +3,6 @@ import { ViewModeProps } from "../interface"; import { buildColumnDefinitions } from "./columns"; import getAttributeDefinitionInformation, { buildRowDefinitions, TableData } from "./rows"; import { useNoteLabelInt, useSpacedUpdate } from "../../react/hooks"; -import { canReorderRows } from "../../view_widgets/table_view/dragging"; import Tabulator from "./tabulator"; import { Tabulator as VanillaTabulator, SortModule, FormatModule, InteractionModule, EditModule, ResizeColumnsModule, FrozenColumnsModule, PersistenceModule, MoveColumnsModule, MoveRowsModule, ColumnDefinition, DataTreeModule, Options} from 'tabulator-tables'; import { useContextMenu } from "./context_menu"; @@ -12,7 +11,7 @@ import FNote from "../../../entities/fnote"; import { t } from "../../../services/i18n"; import Button from "../../react/Button"; import "./index.css"; -import useTableEditing from "./editing"; +import useTableEditing, { canReorderRows } from "./editing"; interface TableConfig { tableData?: { diff --git a/apps/client/src/widgets/view_widgets/table_view/dragging.ts b/apps/client/src/widgets/view_widgets/table_view/dragging.ts deleted file mode 100644 index 39d5a0178..000000000 --- a/apps/client/src/widgets/view_widgets/table_view/dragging.ts +++ /dev/null @@ -1,25 +0,0 @@ -import type { Tabulator } from "tabulator-tables"; -import type FNote from "../../../entities/fnote.js"; -import branches from "../../../services/branches.js"; - -export function canReorderRows(parentNote: FNote) { - return !parentNote.hasLabel("sorted") - && parentNote.type !== "search"; -} - -export function configureReorderingRows(tabulator: Tabulator) { - tabulator.on("rowMoved", (row) => { - const branchIdsToMove = [ row.getData().branchId ]; - - const prevRow = row.getPrevRow(); - if (prevRow) { - branches.moveAfterBranch(branchIdsToMove, prevRow.getData().branchId); - return; - } - - const nextRow = row.getNextRow(); - if (nextRow) { - branches.moveBeforeBranch(branchIdsToMove, nextRow.getData().branchId); - } - }); -}