diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.ts index 0c155c1e8..bbd124864 100644 --- a/apps/client/src/components/app_context.ts +++ b/apps/client/src/components/app_context.ts @@ -28,6 +28,7 @@ import TouchBarComponent from "./touch_bar.js"; import type { CKTextEditor } from "@triliumnext/ckeditor5"; import type CodeMirror from "@triliumnext/codemirror"; import { StartupChecks } from "./startup_checks.js"; +import type { CreateNoteOpts } from "../services/note_create.js"; interface Layout { getRootWidget: (appContext: AppContext) => RootWidget; @@ -276,6 +277,12 @@ export type CommandMappings = { geoMapCreateChildNote: CommandData; + // Table view + addNewRow: CommandData & { + customOpts: CreateNoteOpts; + parentNotePath?: string; + }; + buildTouchBar: CommandData & { TouchBar: typeof TouchBar; buildIcon(name: string): NativeImage; diff --git a/apps/client/src/widgets/view_widgets/table_view/context_menu.ts b/apps/client/src/widgets/view_widgets/table_view/context_menu.ts index 70054d2ea..910c65895 100644 --- a/apps/client/src/widgets/view_widgets/table_view/context_menu.ts +++ b/apps/client/src/widgets/view_widgets/table_view/context_menu.ts @@ -6,6 +6,7 @@ import { t } from "../../../services/i18n.js"; import link_context_menu from "../../../menus/link_context_menu.js"; import type FNote from "../../../entities/fnote.js"; import froca from "../../../services/froca.js"; +import type Component from "../../../components/component.js"; export function setupContextMenu(tabulator: Tabulator, parentNote: FNote) { tabulator.on("rowContext", (e, row) => showRowContextMenu(e, row, parentNote)); @@ -105,32 +106,20 @@ export function showRowContextMenu(_e: UIEvent, row: RowComponent, parentNote: F { title: t("table_view.row-insert-above"), uiIcon: "bx bx-list-plus", - handler: () => { - const target = e.target; - if (!target) { - return; + handler: () => getParentComponent(e)?.triggerCommand("addNewRow", { + customOpts: { + target: "before", + targetBranchId: rowData.branchId, } - const component = $(target).closest(".component").prop("component"); - component.triggerCommand("addNewRow", { - customOpts: { - target: "before", - targetBranchId: rowData.branchId, - } - }); - } + }) }, { title: t("table_view.row-insert-child"), uiIcon: "bx bx-empty", handler: async () => { - const target = e.target; - if (!target) { - return; - } const branchId = row.getData().branchId; const note = await froca.getBranch(branchId)?.getNote(); - const component = $(target).closest(".component").prop("component"); - component.triggerCommand("addNewRow", { + getParentComponent(e)?.triggerCommand("addNewRow", { parentNotePath: note?.noteId, customOpts: { target: "after", @@ -142,19 +131,12 @@ export function showRowContextMenu(_e: UIEvent, row: RowComponent, parentNote: F { title: t("table_view.row-insert-below"), uiIcon: "bx bx-empty", - handler: () => { - const target = e.target; - if (!target) { - return; + handler: () => getParentComponent(e)?.triggerCommand("addNewRow", { + customOpts: { + target: "after", + targetBranchId: rowData.branchId, } - const component = $(target).closest(".component").prop("component"); - component.triggerCommand("addNewRow", { - customOpts: { - target: "after", - targetBranchId: rowData.branchId, - } - }); - } + }) }, { title: "----" }, { @@ -169,3 +151,13 @@ export function showRowContextMenu(_e: UIEvent, row: RowComponent, parentNote: F }); e.preventDefault(); } + +function getParentComponent(e: MouseEvent) { + if (!e.target) { + return; + } + + return $(e.target) + .closest(".component") + .prop("component") as Component; +} diff --git a/apps/client/src/widgets/view_widgets/table_view/index.ts b/apps/client/src/widgets/view_widgets/table_view/index.ts index 03f1a25fd..bcb674420 100644 --- a/apps/client/src/widgets/view_widgets/table_view/index.ts +++ b/apps/client/src/widgets/view_widgets/table_view/index.ts @@ -229,14 +229,13 @@ export default class TableView extends ViewMode { console.log("Save attributes", this.newAttribute); } - addNewRowCommand({ customOpts, parentNotePath: customNotePath }: { customOpts: CreateNoteOpts, parentNotePath?: string }) { + addNewRowCommand({ customOpts, parentNotePath: customNotePath }: CommandListenerData<"addNewRow">) { const parentNotePath = customNotePath ?? this.args.parentNotePath; if (parentNotePath) { const opts: CreateNoteOpts = { activate: false, ...customOpts } - console.log("Create with ", opts); note_create.createNote(parentNotePath, opts).then(({ branch }) => { if (branch) { setTimeout(() => {