2025-02-16 13:22:44 +02:00
|
|
|
import type { EventData } from "../../components/app_context.js";
|
2025-06-27 22:19:09 +03:00
|
|
|
import Component from "../../components/component.js";
|
2025-02-13 23:23:18 +02:00
|
|
|
import type FNote from "../../entities/fnote.js";
|
2025-06-25 16:18:34 +03:00
|
|
|
import type { ViewTypeOptions } from "../../services/note_list_renderer.js";
|
|
|
|
|
import ViewModeStorage from "./view_mode_storage.js";
|
2025-02-13 23:23:18 +02:00
|
|
|
|
2025-02-15 10:13:47 +02:00
|
|
|
export interface ViewModeArgs {
|
|
|
|
|
$parent: JQuery<HTMLElement>;
|
|
|
|
|
parentNote: FNote;
|
2025-07-01 12:09:13 +03:00
|
|
|
parentNotePath?: string | null;
|
2025-02-15 10:13:47 +02:00
|
|
|
noteIds: string[];
|
|
|
|
|
showNotePath?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-27 22:19:09 +03:00
|
|
|
export default abstract class ViewMode<T extends object> extends Component {
|
2025-02-13 23:23:18 +02:00
|
|
|
|
2025-06-25 16:18:34 +03:00
|
|
|
private _viewStorage: ViewModeStorage<T> | null;
|
|
|
|
|
protected parentNote: FNote;
|
|
|
|
|
protected viewType: ViewTypeOptions;
|
|
|
|
|
|
|
|
|
|
constructor(args: ViewModeArgs, viewType: ViewTypeOptions) {
|
2025-06-27 22:19:09 +03:00
|
|
|
super();
|
2025-06-25 16:18:34 +03:00
|
|
|
this.parentNote = args.parentNote;
|
|
|
|
|
this._viewStorage = null;
|
2025-02-13 23:46:20 +02:00
|
|
|
// note list must be added to the DOM immediately, otherwise some functionality scripting (canvas) won't work
|
2025-02-15 10:13:47 +02:00
|
|
|
args.$parent.empty();
|
2025-06-25 16:18:34 +03:00
|
|
|
this.viewType = viewType;
|
2025-02-13 23:23:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
abstract renderList(): Promise<JQuery<HTMLElement> | undefined>;
|
|
|
|
|
|
2025-02-21 17:52:11 +02:00
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
onEntitiesReloaded(e: EventData<"entitiesReloaded">): boolean | void {
|
2025-02-16 13:22:44 +02:00
|
|
|
// Do nothing by default.
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-21 17:17:53 +02:00
|
|
|
get isFullHeight() {
|
|
|
|
|
// Override to change its value.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-25 16:18:34 +03:00
|
|
|
get viewStorage() {
|
|
|
|
|
if (this._viewStorage) {
|
|
|
|
|
return this._viewStorage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this._viewStorage = new ViewModeStorage(this.parentNote, this.viewType);
|
|
|
|
|
return this._viewStorage;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-13 23:23:18 +02:00
|
|
|
}
|