diff --git a/apps/client/src/widgets/collections/interface.ts b/apps/client/src/widgets/collections/interface.ts index a162be81e..0b2fdb22d 100644 --- a/apps/client/src/widgets/collections/interface.ts +++ b/apps/client/src/widgets/collections/interface.ts @@ -1,8 +1,6 @@ import FNote from "../../entities/fnote"; -import type { ViewModeArgs } from "../view_widgets/view_mode"; export const allViewTypes = ["list", "grid", "calendar", "table", "geoMap", "board"] as const; -export type ArgsWithoutNoteId = Omit; export type ViewTypeOptions = typeof allViewTypes[number]; export interface ViewModeProps { diff --git a/apps/client/src/widgets/collections/note_list_renderer.ts.bak b/apps/client/src/widgets/collections/note_list_renderer.ts.bak deleted file mode 100644 index 0b0e48962..000000000 --- a/apps/client/src/widgets/collections/note_list_renderer.ts.bak +++ /dev/null @@ -1,45 +0,0 @@ -import type FNote from "../../entities/fnote.js"; -import BoardView from "../view_widgets/board_view/index.js"; -import CalendarView from "../view_widgets/calendar_view.js"; -import GeoView from "../view_widgets/geo_view/index.js"; -import ListOrGridView from "../view_widgets/list_or_grid_view.js"; -import TableView from "../view_widgets/table_view/index.js"; -import type ViewMode from "../view_widgets/view_mode.js"; - -export default class NoteListRenderer { - - private viewType: ViewTypeOptions; - private args: ArgsWithoutNoteId; - public viewMode?: ViewMode; - - constructor(args: ArgsWithoutNoteId) { - this.args = args; - this.viewType = this.#getViewType(args.parentNote); - } - - async renderList() { - const args = this.args; - const viewMode = this.#buildViewMode(args); - this.viewMode = viewMode; - await viewMode.beforeRender(); - return await viewMode.renderList(); - } - - #buildViewMode(args: ViewModeArgs) { - switch (this.viewType) { - case "calendar": - return new CalendarView(args); - case "table": - return new TableView(args); - case "geoMap": - return new GeoView(args); - case "board": - return new BoardView(args); - case "list": - case "grid": - default: - return new ListOrGridView(this.viewType, args); - } - } - -} diff --git a/apps/client/src/widgets/view_widgets/view_mode_storage.ts b/apps/client/src/widgets/collections/view_mode_storage.ts similarity index 100% rename from apps/client/src/widgets/view_widgets/view_mode_storage.ts rename to apps/client/src/widgets/collections/view_mode_storage.ts diff --git a/apps/client/src/widgets/view_widgets/calendar_view.ts b/apps/client/src/widgets/view_widgets/calendar_view.ts deleted file mode 100644 index e689e1bc4..000000000 --- a/apps/client/src/widgets/view_widgets/calendar_view.ts +++ /dev/null @@ -1,104 +0,0 @@ -import type { Calendar, DateSelectArg, DatesSetArg, EventChangeArg, EventDropArg, EventInput, EventSourceFunc, EventSourceFuncArg, EventSourceInput, LocaleInput, PluginDef } from "@fullcalendar/core"; -import froca from "../../services/froca.js"; -import ViewMode, { type ViewModeArgs } from "./view_mode.js"; -import type FNote from "../../entities/fnote.js"; -import server from "../../services/server.js"; -import { t } from "../../services/i18n.js"; -import options from "../../services/options.js"; -import dialogService from "../../services/dialog.js"; -import attributes from "../../services/attributes.js"; -import type { CommandListenerData, EventData } from "../../components/app_context.js"; -import utils, { hasTouchBar } from "../../services/utils.js"; -import date_notes from "../../services/date_notes.js"; -import appContext from "../../components/app_context.js"; -import type { EventImpl } from "@fullcalendar/core/internal"; -import debounce, { type DebouncedFunction } from "debounce"; -import type { TouchBarItem } from "../../components/touch_bar.js"; -import type { SegmentedControlSegment } from "electron"; -import { LOCALE_IDS } from "@triliumnext/commons"; - - -export default class CalendarView extends ViewMode<{}> { - - private $root: JQuery; - private $calendarContainer: JQuery; - private calendar?: Calendar; - private isCalendarRoot: boolean; - - constructor(args: ViewModeArgs) { - super(args, "calendar"); - - this.$root = $(TPL); - this.$calendarContainer = this.$root.find(".calendar-container"); - args.$parent.append(this.$root); - } - - #onDatesSet(e: DatesSetArg) { - if (hasTouchBar) { - appContext.triggerCommand("refreshTouchBar"); - } - } - - buildTouchBarCommand({ TouchBar, buildIcon }: CommandListenerData<"buildTouchBar">) { - if (!this.calendar) { - return; - } - - const items: TouchBarItem[] = []; - const $toolbarItems = this.$calendarContainer.find(".fc-toolbar-chunk .fc-button-group, .fc-toolbar-chunk > button"); - - for (const item of $toolbarItems) { - // Button groups. - if (item.classList.contains("fc-button-group")) { - let mode: "single" | "buttons" = "single"; - let selectedIndex = 0; - const segments: SegmentedControlSegment[] = []; - const subItems = item.childNodes as NodeListOf; - let index = 0; - for (const subItem of subItems) { - if (subItem.ariaPressed === "true") { - selectedIndex = index; - } - index++; - - - // Icon button. - const iconEl = subItem.querySelector("span.fc-icon"); - let icon: string | null = null; - if (iconEl?.classList.contains("fc-icon-chevron-left")) { - icon = "NSImageNameTouchBarGoBackTemplate"; - mode = "buttons"; - } else if (iconEl?.classList.contains("fc-icon-chevron-right")) { - icon = "NSImageNameTouchBarGoForwardTemplate"; - mode = "buttons"; - } - - if (icon) { - segments.push({ - icon: buildIcon(icon) - }); - } - } - - items.push(new TouchBar.TouchBarSegmentedControl({ - mode, - segments, - selectedIndex, - change: (selectedIndex, isSelected) => subItems[selectedIndex].click() - })); - continue; - } - - // Standalone item. - if (item.innerText) { - items.push(new TouchBar.TouchBarButton({ - label: item.innerText, - click: () => item.click() - })); - } - } - - return items; - } - -} diff --git a/apps/client/src/widgets/view_widgets/view_mode.ts b/apps/client/src/widgets/view_widgets/view_mode.ts deleted file mode 100644 index 1bce10499..000000000 --- a/apps/client/src/widgets/view_widgets/view_mode.ts +++ /dev/null @@ -1,56 +0,0 @@ -import type { EventData } from "../../components/app_context.js"; -import appContext from "../../components/app_context.js"; -import Component from "../../components/component.js"; -import type FNote from "../../entities/fnote.js"; -import { ViewTypeOptions } from "../collections/interface.js"; -import ViewModeStorage from "./view_mode_storage.js"; - -export interface ViewModeArgs { - $parent: JQuery; - parentNote: FNote; - parentNotePath?: string | null; - showNotePath?: boolean; -} - -export default abstract class ViewMode extends Component { - - private _viewStorage: ViewModeStorage | null; - protected parentNote: FNote; - protected viewType: ViewTypeOptions; - protected noteIds: string[]; - protected args: ViewModeArgs; - - constructor(args: ViewModeArgs, viewType: ViewTypeOptions) { - super(); - this.parentNote = args.parentNote; - this._viewStorage = null; - // note list must be added to the DOM immediately, otherwise some functionality scripting (canvas) won't work - args.$parent.empty(); - this.viewType = viewType; - this.args = args; - this.noteIds = []; - } - - async beforeRender() { - await this.#refreshNoteIds(); - } - - abstract renderList(): Promise | undefined>; - - /** - * Called whenever an "entitiesReloaded" event has been received by the parent component. - * - * @param e the event data. - * @return {@code true} if the view should be re-rendered, a falsy value otherwise. - */ - async onEntitiesReloaded(e: EventData<"entitiesReloaded">): Promise { - // Do nothing by default. - } - - async entitiesReloadedEvent(e: EventData<"entitiesReloaded">) { - if (await this.onEntitiesReloaded(e)) { - appContext.triggerEvent("refreshNoteList", { noteId: this.parentNote.noteId }); - } - } - -}