mirror of
https://github.com/zadam/trilium.git
synced 2025-10-09 07:05:31 +08:00
feat(views/table): insert row below
This commit is contained in:
parent
7a48333b4f
commit
5dd5af90c2
3 changed files with 40 additions and 10 deletions
|
@ -11,7 +11,7 @@ import type FBranch from "../entities/fbranch.js";
|
||||||
import type { ChooseNoteTypeResponse } from "../widgets/dialogs/note_type_chooser.js";
|
import type { ChooseNoteTypeResponse } from "../widgets/dialogs/note_type_chooser.js";
|
||||||
import type { CKTextEditor } from "@triliumnext/ckeditor5";
|
import type { CKTextEditor } from "@triliumnext/ckeditor5";
|
||||||
|
|
||||||
interface CreateNoteOpts {
|
export interface CreateNoteOpts {
|
||||||
isProtected?: boolean;
|
isProtected?: boolean;
|
||||||
saveSelection?: boolean;
|
saveSelection?: boolean;
|
||||||
title?: string | null;
|
title?: string | null;
|
||||||
|
|
|
@ -4,18 +4,45 @@ import { TableData } from "./rows.js";
|
||||||
import branches from "../../../services/branches.js";
|
import branches from "../../../services/branches.js";
|
||||||
import { t } from "../../../services/i18n.js";
|
import { t } from "../../../services/i18n.js";
|
||||||
import link_context_menu from "../../../menus/link_context_menu.js";
|
import link_context_menu from "../../../menus/link_context_menu.js";
|
||||||
|
import type FNote from "../../../entities/fnote.js";
|
||||||
|
import appContext from "../../../components/app_context.js";
|
||||||
|
|
||||||
export function setupContextMenu(tabulator: Tabulator) {
|
export function setupContextMenu(tabulator: Tabulator, parentNote: FNote) {
|
||||||
tabulator.on("rowContext", showRowContextMenu);
|
tabulator.on("rowContext", (e, row) => showRowContextMenu(e, row, parentNote));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function showRowContextMenu(_e: UIEvent, row: RowComponent) {
|
export function showRowContextMenu(_e: UIEvent, row: RowComponent, parentNote: FNote) {
|
||||||
const e = _e as MouseEvent;
|
const e = _e as MouseEvent;
|
||||||
const rowData = row.getData() as TableData;
|
const rowData = row.getData() as TableData;
|
||||||
contextMenu.show({
|
contextMenu.show({
|
||||||
items: [
|
items: [
|
||||||
...link_context_menu.getItems(),
|
...link_context_menu.getItems(),
|
||||||
{ title: "----" },
|
{ title: "----" },
|
||||||
|
{
|
||||||
|
title: "Insert row above",
|
||||||
|
uiIcon: "bx bx-list-plus",
|
||||||
|
handler: () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Insert row below",
|
||||||
|
uiIcon: "bx bx-empty",
|
||||||
|
handler: () => {
|
||||||
|
const target = e.target;
|
||||||
|
if (!target) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const component = $(target).closest(".component").prop("component");
|
||||||
|
component.triggerCommand("addNewRow", {
|
||||||
|
customOpts: {
|
||||||
|
target: "after",
|
||||||
|
targetBranchId: rowData.branchId,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ title: "----" },
|
||||||
{
|
{
|
||||||
title: t("table_context_menu.delete_row"),
|
title: t("table_context_menu.delete_row"),
|
||||||
uiIcon: "bx bx-trash",
|
uiIcon: "bx bx-trash",
|
||||||
|
|
|
@ -5,7 +5,7 @@ import server from "../../../services/server.js";
|
||||||
import SpacedUpdate from "../../../services/spaced_update.js";
|
import SpacedUpdate from "../../../services/spaced_update.js";
|
||||||
import type { CommandListenerData, EventData } from "../../../components/app_context.js";
|
import type { CommandListenerData, EventData } from "../../../components/app_context.js";
|
||||||
import type { Attribute } from "../../../services/attribute_parser.js";
|
import type { Attribute } from "../../../services/attribute_parser.js";
|
||||||
import note_create from "../../../services/note_create.js";
|
import note_create, { CreateNoteOpts } from "../../../services/note_create.js";
|
||||||
import {Tabulator, SortModule, FormatModule, InteractionModule, EditModule, ResizeColumnsModule, FrozenColumnsModule, PersistenceModule, MoveColumnsModule, MenuModule, MoveRowsModule, ColumnDefinition} from 'tabulator-tables';
|
import {Tabulator, SortModule, FormatModule, InteractionModule, EditModule, ResizeColumnsModule, FrozenColumnsModule, PersistenceModule, MoveColumnsModule, MenuModule, MoveRowsModule, ColumnDefinition} from 'tabulator-tables';
|
||||||
import "tabulator-tables/dist/css/tabulator.css";
|
import "tabulator-tables/dist/css/tabulator.css";
|
||||||
import "../../../../src/stylesheets/table.css";
|
import "../../../../src/stylesheets/table.css";
|
||||||
|
@ -145,7 +145,7 @@ export default class TableView extends ViewMode<StateInfo> {
|
||||||
persistenceReaderFunc: (_id, type: string) => this.persistentData?.[type],
|
persistenceReaderFunc: (_id, type: string) => this.persistentData?.[type],
|
||||||
});
|
});
|
||||||
configureReorderingRows(this.api);
|
configureReorderingRows(this.api);
|
||||||
setupContextMenu(this.api);
|
setupContextMenu(this.api, this.parentNote);
|
||||||
this.setupEditing();
|
this.setupEditing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,12 +198,15 @@ export default class TableView extends ViewMode<StateInfo> {
|
||||||
console.log("Save attributes", this.newAttribute);
|
console.log("Save attributes", this.newAttribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
addNewRowCommand() {
|
addNewRowCommand({ customOpts }: { customOpts: CreateNoteOpts }) {
|
||||||
const parentNotePath = this.args.parentNotePath;
|
const parentNotePath = this.args.parentNotePath;
|
||||||
if (parentNotePath) {
|
if (parentNotePath) {
|
||||||
note_create.createNote(parentNotePath, {
|
const opts: CreateNoteOpts = {
|
||||||
activate: false
|
activate: false,
|
||||||
}).then(({ note }) => {
|
...customOpts
|
||||||
|
}
|
||||||
|
console.log("Create with ", opts);
|
||||||
|
note_create.createNote(parentNotePath, opts).then(({ note }) => {
|
||||||
if (!note) {
|
if (!note) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue