mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 07:38:53 +02:00
chore(react/collections/table): bring back dragging rows
This commit is contained in:
parent
3d97b317f2
commit
6eea921820
@ -6,6 +6,8 @@ import { RefObject } from "preact";
|
|||||||
import { setAttribute, setLabel } from "../../../services/attributes";
|
import { setAttribute, setLabel } from "../../../services/attributes";
|
||||||
import froca from "../../../services/froca";
|
import froca from "../../../services/froca";
|
||||||
import server from "../../../services/server";
|
import server from "../../../services/server";
|
||||||
|
import FNote from "../../../entities/fnote";
|
||||||
|
import branches from "../../../services/branches";
|
||||||
|
|
||||||
export default function useTableEditing(api: RefObject<Tabulator>, parentNotePath: string): Partial<EventCallBackMethods> {
|
export default function useTableEditing(api: RefObject<Tabulator>, parentNotePath: string): Partial<EventCallBackMethods> {
|
||||||
// Adding new rows
|
// Adding new rows
|
||||||
@ -55,6 +57,20 @@ export default function useTableEditing(api: RefObject<Tabulator>, 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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function canReorderRows(parentNote: FNote) {
|
||||||
|
return !parentNote.hasLabel("sorted")
|
||||||
|
&& parentNote.type !== "search";
|
||||||
|
}
|
||||||
|
@ -3,7 +3,6 @@ import { ViewModeProps } from "../interface";
|
|||||||
import { buildColumnDefinitions } from "./columns";
|
import { buildColumnDefinitions } from "./columns";
|
||||||
import getAttributeDefinitionInformation, { buildRowDefinitions, TableData } from "./rows";
|
import getAttributeDefinitionInformation, { buildRowDefinitions, TableData } from "./rows";
|
||||||
import { useNoteLabelInt, useSpacedUpdate } from "../../react/hooks";
|
import { useNoteLabelInt, useSpacedUpdate } from "../../react/hooks";
|
||||||
import { canReorderRows } from "../../view_widgets/table_view/dragging";
|
|
||||||
import Tabulator from "./tabulator";
|
import Tabulator from "./tabulator";
|
||||||
import { Tabulator as VanillaTabulator, SortModule, FormatModule, InteractionModule, EditModule, ResizeColumnsModule, FrozenColumnsModule, PersistenceModule, MoveColumnsModule, MoveRowsModule, ColumnDefinition, DataTreeModule, Options} from 'tabulator-tables';
|
import { Tabulator as VanillaTabulator, SortModule, FormatModule, InteractionModule, EditModule, ResizeColumnsModule, FrozenColumnsModule, PersistenceModule, MoveColumnsModule, MoveRowsModule, ColumnDefinition, DataTreeModule, Options} from 'tabulator-tables';
|
||||||
import { useContextMenu } from "./context_menu";
|
import { useContextMenu } from "./context_menu";
|
||||||
@ -12,7 +11,7 @@ import FNote from "../../../entities/fnote";
|
|||||||
import { t } from "../../../services/i18n";
|
import { t } from "../../../services/i18n";
|
||||||
import Button from "../../react/Button";
|
import Button from "../../react/Button";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
import useTableEditing from "./editing";
|
import useTableEditing, { canReorderRows } from "./editing";
|
||||||
|
|
||||||
interface TableConfig {
|
interface TableConfig {
|
||||||
tableData?: {
|
tableData?: {
|
||||||
|
@ -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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user