mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-22 12:11:41 +08:00
chore(client/ts): port components/shortcut_component
This commit is contained in:
parent
8a47b2f5a8
commit
018be8c926
@ -37,7 +37,7 @@ export default class MainTreeExecutors extends Component {
|
||||
async createNoteIntoCommand() {
|
||||
const activeNoteContext = appContext.tabManager.getActiveContext();
|
||||
|
||||
if (!activeNoteContext) {
|
||||
if (!activeNoteContext || !activeNoteContext.notePath || !activeNoteContext.note) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ class NoteContext extends Component
|
||||
hoistedNoteId: string;
|
||||
private mainNtxId: string | null;
|
||||
|
||||
private notePath?: string | null;
|
||||
notePath?: string | null;
|
||||
private noteId?: string | null;
|
||||
private parentNoteId?: string | null;
|
||||
private viewScope?: ViewScope;
|
||||
@ -62,11 +62,15 @@ class NoteContext extends Component
|
||||
return !this.noteId;
|
||||
}
|
||||
|
||||
async setNote(inputNotePath: string, opts: SetNoteOpts = {}) {
|
||||
async setNote(inputNotePath: string | undefined, opts: SetNoteOpts = {}) {
|
||||
opts.triggerSwitchEvent = opts.triggerSwitchEvent !== undefined ? opts.triggerSwitchEvent : true;
|
||||
opts.viewScope = opts.viewScope || {};
|
||||
opts.viewScope.viewMode = opts.viewScope.viewMode || "default";
|
||||
|
||||
if (!inputNotePath) {
|
||||
return;
|
||||
}
|
||||
|
||||
const resolvedNotePath = await this.getResolvedNotePath(inputNotePath);
|
||||
|
||||
if (!resolvedNotePath) {
|
||||
@ -301,7 +305,7 @@ class NoteContext extends Component
|
||||
&& !this.note.isLabelTruthy('hideChildrenOverview');
|
||||
}
|
||||
|
||||
async getTextEditor(callback: GetTextEditorCallback) {
|
||||
async getTextEditor(callback?: GetTextEditorCallback) {
|
||||
return this.timeout(new Promise(resolve => appContext.triggerCommand('executeWithTextEditor', {
|
||||
callback,
|
||||
resolve,
|
||||
|
@ -1,37 +1,42 @@
|
||||
import appContext from "./app_context.js";
|
||||
import appContext, { EventData, EventListener } from "./app_context.js";
|
||||
import shortcutService from "../services/shortcuts.js";
|
||||
import server from "../services/server.js";
|
||||
import Component from "./component.js";
|
||||
import froca from "../services/froca.js";
|
||||
import { AttributeRow } from "../services/load_results.js";
|
||||
|
||||
export default class ShortcutComponent extends Component {
|
||||
export default class ShortcutComponent extends Component
|
||||
implements EventListener<"entitiesReloaded">
|
||||
{
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
server.get('keyboard-shortcuts-for-notes').then(shortcutAttributes => {
|
||||
server.get<AttributeRow[]>('keyboard-shortcuts-for-notes').then(shortcutAttributes => {
|
||||
for (const attr of shortcutAttributes) {
|
||||
this.bindNoteShortcutHandler(attr);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
bindNoteShortcutHandler(labelOrRow) {
|
||||
bindNoteShortcutHandler(labelOrRow: AttributeRow) {
|
||||
const handler = () => appContext.tabManager.getActiveContext().setNote(labelOrRow.noteId);
|
||||
const namespace = labelOrRow.attributeId;
|
||||
|
||||
if (labelOrRow.isDeleted) { // only applicable if row
|
||||
if (namespace) {
|
||||
shortcutService.removeGlobalShortcut(namespace);
|
||||
} else {
|
||||
}
|
||||
} else if (labelOrRow.value) {
|
||||
shortcutService.bindGlobalShortcut(labelOrRow.value, handler, namespace);
|
||||
}
|
||||
}
|
||||
|
||||
async entitiesReloadedEvent({loadResults}) {
|
||||
async entitiesReloadedEvent({loadResults}: EventData<"entitiesReloaded">) {
|
||||
for (const attr of loadResults.getAttributeRows()) {
|
||||
if (attr.type === 'label' && attr.name === 'keyboardShortcut') {
|
||||
if (attr.type === 'label' && attr.name === 'keyboardShortcut' && attr.noteId) {
|
||||
const note = await froca.getNote(attr.noteId);
|
||||
// launcher shortcuts are handled specifically
|
||||
if (note && note.type !== 'launcher') {
|
||||
if (note && attr && note.type !== 'launcher') {
|
||||
this.bindNoteShortcutHandler(attr);
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
import { NoteRow } from "../../../becca/entities/rows.js";
|
||||
import { AttributeType } from "../entities/fattribute.js";
|
||||
import { EntityChange } from "../server_types.js";
|
||||
|
||||
interface BranchRow {
|
||||
@ -11,6 +12,10 @@ export interface AttributeRow {
|
||||
attributeId: string;
|
||||
componentId: string;
|
||||
isInheritable?: boolean;
|
||||
isDeleted?: boolean;
|
||||
name?: string;
|
||||
value?: string;
|
||||
type?: AttributeType;
|
||||
}
|
||||
|
||||
interface RevisionRow {
|
||||
@ -26,6 +31,10 @@ interface ContentNoteIdToComponentIdRow {
|
||||
|
||||
interface AttachmentRow {}
|
||||
|
||||
interface OptionRow {}
|
||||
|
||||
interface NoteReorderingRow {}
|
||||
|
||||
interface ContentNoteIdToComponentIdRow {
|
||||
noteId: string;
|
||||
componentId: string;
|
||||
@ -34,7 +43,10 @@ interface ContentNoteIdToComponentIdRow {
|
||||
type EntityRowMappings = {
|
||||
"notes": NoteRow,
|
||||
"branches": BranchRow,
|
||||
"attributes": AttributeRow
|
||||
"attributes": AttributeRow,
|
||||
"options": OptionRow,
|
||||
"revisions": RevisionRow,
|
||||
"note_reordering": NoteReorderingRow
|
||||
}
|
||||
|
||||
export type EntityRowNames = keyof EntityRowMappings;
|
||||
|
Loading…
x
Reference in New Issue
Block a user