mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 18:39:22 +08:00
chore(client/ts): port launcher & launcher_container
This commit is contained in:
parent
6966f92339
commit
e45052cead
@ -10,6 +10,7 @@ interface NoteRow {
|
|||||||
interface BranchRow {
|
interface BranchRow {
|
||||||
branchId: string;
|
branchId: string;
|
||||||
componentId: string;
|
componentId: string;
|
||||||
|
parentNoteId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AttributeRow {
|
export interface AttributeRow {
|
||||||
|
1
src/public/app/types.d.ts
vendored
1
src/public/app/types.d.ts
vendored
@ -42,6 +42,7 @@ interface CustomGlobals {
|
|||||||
instanceName: string;
|
instanceName: string;
|
||||||
appCssNoteIds: string[];
|
appCssNoteIds: string[];
|
||||||
triliumVersion: string;
|
triliumVersion: string;
|
||||||
|
TRILIUM_SAFE_MODE: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
type RequireMethod = (moduleName: string) => any;
|
type RequireMethod = (moduleName: string) => any;
|
||||||
|
@ -11,12 +11,22 @@ import utils from "../../services/utils.js";
|
|||||||
import TodayLauncher from "../buttons/launcher/today_launcher.js";
|
import TodayLauncher from "../buttons/launcher/today_launcher.js";
|
||||||
import HistoryNavigationButton from "../buttons/history_navigation.js";
|
import HistoryNavigationButton from "../buttons/history_navigation.js";
|
||||||
import QuickSearchLauncherWidget from "../quick_search_launcher.js";
|
import QuickSearchLauncherWidget from "../quick_search_launcher.js";
|
||||||
|
import FNote from "../../entities/fnote.js";
|
||||||
|
|
||||||
|
interface InnerWidget extends BasicWidget {
|
||||||
|
settings?: {
|
||||||
|
titlePlacement: "bottom"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default class LauncherWidget extends BasicWidget {
|
export default class LauncherWidget extends BasicWidget {
|
||||||
constructor(isHorizontalLayout) {
|
|
||||||
|
private innerWidget!: InnerWidget;
|
||||||
|
private isHorizontalLayout: boolean;
|
||||||
|
|
||||||
|
constructor(isHorizontalLayout: boolean) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.innerWidget = null;
|
|
||||||
this.isHorizontalLayout = isHorizontalLayout;
|
this.isHorizontalLayout = isHorizontalLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,7 +38,7 @@ export default class LauncherWidget extends BasicWidget {
|
|||||||
this.$widget = this.innerWidget.render();
|
this.$widget = this.innerWidget.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
async initLauncher(note) {
|
async initLauncher(note: FNote) {
|
||||||
if (note.type !== 'launcher') {
|
if (note.type !== 'launcher') {
|
||||||
throw new Error(`Note '${note.noteId}' '${note.title}' is not a launcher even though it's in the launcher subtree`);
|
throw new Error(`Note '${note.noteId}' '${note.title}' is not a launcher even though it's in the launcher subtree`);
|
||||||
}
|
}
|
||||||
@ -43,28 +53,30 @@ export default class LauncherWidget extends BasicWidget {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let widget: BasicWidget;
|
||||||
if (launcherType === 'command') {
|
if (launcherType === 'command') {
|
||||||
this.innerWidget = this.initCommandLauncherWidget(note)
|
widget = this.initCommandLauncherWidget(note)
|
||||||
.class("launcher-button");
|
.class("launcher-button");
|
||||||
} else if (launcherType === 'note') {
|
} else if (launcherType === 'note') {
|
||||||
this.innerWidget = new NoteLauncher(note)
|
widget = new NoteLauncher(note)
|
||||||
.class("launcher-button");
|
.class("launcher-button");
|
||||||
} else if (launcherType === 'script') {
|
} else if (launcherType === 'script') {
|
||||||
this.innerWidget = new ScriptLauncher(note)
|
widget = new ScriptLauncher(note)
|
||||||
.class("launcher-button");
|
.class("launcher-button");
|
||||||
} else if (launcherType === 'customWidget') {
|
} else if (launcherType === 'customWidget') {
|
||||||
this.innerWidget = await this.initCustomWidget(note);
|
widget = await this.initCustomWidget(note);
|
||||||
} else if (launcherType === 'builtinWidget') {
|
} else if (launcherType === 'builtinWidget') {
|
||||||
this.innerWidget = this.initBuiltinWidget(note);
|
widget = this.initBuiltinWidget(note);
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Unrecognized launcher type '${launcherType}' for launcher '${note.noteId}' title '${note.title}'`);
|
throw new Error(`Unrecognized launcher type '${launcherType}' for launcher '${note.noteId}' title '${note.title}'`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.innerWidget) {
|
if (!widget) {
|
||||||
throw new Error(`Unknown initialization error for note '${note.noteId}', title '${note.title}'`);
|
throw new Error(`Unknown initialization error for note '${note.noteId}', title '${note.title}'`);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.child(this.innerWidget);
|
this.child(widget);
|
||||||
|
this.innerWidget = widget as InnerWidget;
|
||||||
if (this.isHorizontalLayout && this.innerWidget.settings) {
|
if (this.isHorizontalLayout && this.innerWidget.settings) {
|
||||||
this.innerWidget.settings.titlePlacement = "bottom";
|
this.innerWidget.settings.titlePlacement = "bottom";
|
||||||
}
|
}
|
||||||
@ -72,14 +84,14 @@ export default class LauncherWidget extends BasicWidget {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
initCommandLauncherWidget(note) {
|
initCommandLauncherWidget(note: FNote) {
|
||||||
return new CommandButtonWidget()
|
return new CommandButtonWidget()
|
||||||
.title(() => note.title)
|
.title(() => note.title)
|
||||||
.icon(() => note.getIcon())
|
.icon(() => note.getIcon())
|
||||||
.command(() => note.getLabelValue("command"));
|
.command(() => note.getLabelValue("command"));
|
||||||
}
|
}
|
||||||
|
|
||||||
async initCustomWidget(note) {
|
async initCustomWidget(note: FNote) {
|
||||||
const widget = await note.getRelationTarget('widget');
|
const widget = await note.getRelationTarget('widget');
|
||||||
|
|
||||||
if (widget) {
|
if (widget) {
|
||||||
@ -89,7 +101,7 @@ export default class LauncherWidget extends BasicWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initBuiltinWidget(note) {
|
initBuiltinWidget(note: FNote) {
|
||||||
const builtinWidget = note.getLabelValue("builtinWidget");
|
const builtinWidget = note.getLabelValue("builtinWidget");
|
||||||
switch (builtinWidget) {
|
switch (builtinWidget) {
|
||||||
case "calendar":
|
case "calendar":
|
||||||
@ -98,7 +110,7 @@ export default class LauncherWidget extends BasicWidget {
|
|||||||
// || has to be inside since 0 is a valid value
|
// || has to be inside since 0 is a valid value
|
||||||
const baseSize = parseInt(note.getLabelValue("baseSize") || "40");
|
const baseSize = parseInt(note.getLabelValue("baseSize") || "40");
|
||||||
const growthFactor = parseInt(note.getLabelValue("growthFactor") || "100");
|
const growthFactor = parseInt(note.getLabelValue("growthFactor") || "100");
|
||||||
|
|
||||||
return new SpacerWidget(baseSize, growthFactor);
|
return new SpacerWidget(baseSize, growthFactor);
|
||||||
case "bookmarks":
|
case "bookmarks":
|
||||||
return new BookmarkButtons(this.isHorizontalLayout);
|
return new BookmarkButtons(this.isHorizontalLayout);
|
@ -1,10 +1,12 @@
|
|||||||
import FlexContainer from "./flex_container.js";
|
import FlexContainer from "./flex_container.js";
|
||||||
import froca from "../../services/froca.js";
|
import froca from "../../services/froca.js";
|
||||||
import appContext from "../../components/app_context.js";
|
import appContext, { EventData } from "../../components/app_context.js";
|
||||||
import LauncherWidget from "./launcher.js";
|
import LauncherWidget from "./launcher.js";
|
||||||
|
|
||||||
export default class LauncherContainer extends FlexContainer {
|
export default class LauncherContainer extends FlexContainer {
|
||||||
constructor(isHorizontalLayout) {
|
private isHorizontalLayout: boolean;
|
||||||
|
|
||||||
|
constructor(isHorizontalLayout: boolean) {
|
||||||
super(isHorizontalLayout ? "row" : "column");
|
super(isHorizontalLayout ? "row" : "column");
|
||||||
|
|
||||||
this.id('launcher-container');
|
this.id('launcher-container');
|
||||||
@ -66,8 +68,8 @@ export default class LauncherContainer extends FlexContainer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
entitiesReloadedEvent({loadResults}) {
|
entitiesReloadedEvent({loadResults}: EventData<"entitiesReloaded">) {
|
||||||
if (loadResults.getBranchRows().find(branch => froca.getNoteFromCache(branch.parentNoteId)?.isLaunchBarConfig())) {
|
if (loadResults.getBranchRows().find(branch => branch.parentNoteId && froca.getNoteFromCache(branch.parentNoteId)?.isLaunchBarConfig())) {
|
||||||
// changes in note placement require reload of all launchers, all other changes are handled by individual
|
// changes in note placement require reload of all launchers, all other changes are handled by individual
|
||||||
// launchers
|
// launchers
|
||||||
this.load();
|
this.load();
|
Loading…
x
Reference in New Issue
Block a user