Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
shortcut improvements
zadam6883b71ce7e7
diff --git a/db/migrations/0203__set_notes_as_doc_type.sql b/db/migrations/0203__set_notes_as_doc_type.sqlnew file mode 100644index 0000000000..140e945ad0--- /dev/null+++ b/db/migrations/0203__set_notes_as_doc_type.sql@@ -0,0 +1 @@+UPDATE notes SET type = 'doc' WHERE noteId IN ('share, hidden', 'sqlconsole', 'search');\ No newline at end of filediff --git a/src/public/app/doc_notes/hidden.html b/src/public/app/doc_notes/hidden.htmlnew file mode 100644index 0000000000..98e79fd93a--- /dev/null+++ b/src/public/app/doc_notes/hidden.html@@ -0,0 +1 @@+<p>Hidden tree is used to record various application-level data which can stay most of the time hidden from the user view.</p>\ No newline at end of filediff --git a/src/public/app/doc_notes/share.html b/src/public/app/doc_notes/share.htmlnew file mode 100644index 0000000000..499cf35e87--- /dev/null+++ b/src/public/app/doc_notes/share.html@@ -0,0 +1 @@+<p>Here you can find all shared notes.</p>\ No newline at end of filediff --git a/src/public/app/entities/note_short.js b/src/public/app/entities/note_short.jsindex 15dad902e2..b918d24706 100644--- a/src/public/app/entities/note_short.js+++ b/src/public/app/entities/note_short.js@@ -21,7 +21,8 @@ const NOTE_TYPE_ICONS = {"mermaid": "bx bx-selection","canvas": "bx bx-pen","web-view": "bx bx-globe-alt",- "shortcut": "bx bx-up-arrow-circle"+ "shortcut": "bx bx-up-arrow-circle",+ "doc": "bx bx-file-doc"};/**diff --git a/src/public/app/menus/shortcut_context_menu.js b/src/public/app/menus/shortcut_context_menu.jsindex 74b05f0729..ba78003eea 100644--- a/src/public/app/menus/shortcut_context_menu.js+++ b/src/public/app/menus/shortcut_context_menu.js@@ -1,6 +1,8 @@import treeService from '../services/tree.js';import froca from "../services/froca.js";import contextMenu from "./context_menu.js";+import dialogService from "../services/dialog.js";+import server from "../services/server.js";export default class ShortcutContextMenu {/**@@ -25,12 +27,13 @@ export default class ShortcutContextMenu {const note = await froca.getNote(this.node.data.noteId);const parentNoteId = this.node.getParent().data.noteId;- const isLbRoot = note.noteId === 'lb_root';const isVisibleRoot = note.noteId === 'lb_visibleshortcuts';const isAvailableRoot = note.noteId === 'lb_availableshortcuts';const isVisibleItem = parentNoteId === 'lb_visibleshortcuts';const isAvailableItem = parentNoteId === 'lb_availableshortcuts';const isItem = isVisibleItem || isAvailableItem;+ const canBeDeleted = !note.noteId.startsWith("lb_");+ const canBeReset = note.noteId.startsWith("lb_");return [(isVisibleRoot || isAvailableRoot) ? { title: 'Add note shortcut', command: 'addNoteShortcut', uiIcon: "bx bx-plus" } : null,@@ -38,8 +41,8 @@ export default class ShortcutContextMenu {(isVisibleRoot || isAvailableRoot) ? { title: 'Add widget shortcut', command: 'addWidgetShortcut', uiIcon: "bx bx-plus" } : null,(isVisibleRoot || isAvailableRoot) ? { title: 'Add spacer', command: 'addSpacerShortcut', uiIcon: "bx bx-plus" } : null,(isVisibleRoot || isAvailableRoot) ? { title: "----" } : null,- { title: 'Delete <kbd data-command="deleteNotes"></kbd>', command: "deleteNotes", uiIcon: "bx bx-trash",- enabled: !isLbRoot}, // allow everything to be deleted as a form of a reset. Root can't be deleted because it's a hoisted note+ { title: 'Delete <kbd data-command="deleteNotes"></kbd>', command: "deleteNotes", uiIcon: "bx bx-trash", enabled: canBeDeleted },+ { title: 'Reset', command: "resetShortcut", uiIcon: "bx bx-empty", enabled: canBeReset},{ title: "----" },isAvailableItem ? { title: 'Move to visible shortcuts', command: "moveShortcutToVisible", uiIcon: "bx bx-show", enabled: true } : null,isVisibleItem ? { title: 'Move to available shortcuts', command: "moveShortcutToAvailable", uiIcon: "bx bx-hide", enabled: true } : null,@@ -49,6 +52,18 @@ export default class ShortcutContextMenu {}async selectMenuItemHandler({command}) {+ if (command === 'resetShortcut') {+ const confirmed = await dialogService.confirm(`Do you really want to reset "${this.node.title}"?+ All data / settings in this shortcut (and its children) will be lost+ and the shortcut will be returned to its original location.`);++ if (confirmed) {+ await server.post(`special-notes/shortcuts/${this.node.data.noteId}/reset`);+ }++ return;+ }+this.treeWidget.triggerCommand(command, {node: this.node,notePath: treeService.getNotePath(this.node),diff --git a/src/public/app/services/branches.js b/src/public/app/services/branches.jsindex 0b885bb02b..a1a9bb4d12 100644--- a/src/public/app/services/branches.js+++ b/src/public/app/services/branches.js@@ -10,8 +10,8 @@ async function moveBeforeBranch(branchIdsToMove, beforeBranchId) {branchIdsToMove = filterRootNote(branchIdsToMove);branchIdsToMove = filterSearchBranches(branchIdsToMove);- if (beforeBranchId === 'root') {- toastService.showError('Cannot move notes before root note.');+ if (['root', 'lb_root', 'lb_availableshortcuts', 'lb_visibleshortcuts'].includes(beforeBranchId)) {+ toastService.showError('Cannot move notes here.');return;}@@ -31,8 +31,16 @@ async function moveAfterBranch(branchIdsToMove, afterBranchId) {const afterNote = await froca.getBranch(afterBranchId).getNote();- if (afterNote.noteId === 'root' || afterNote.noteId === hoistedNoteService.getHoistedNoteId()) {- toastService.showError('Cannot move notes after root note.');+ const forbiddenNoteIds = [+ 'root',+ hoistedNoteService.getHoistedNoteId(),+ 'lb_root',+ 'lb_availableshortcuts',+ 'lb_visibleshortcuts'+ ];++ if (forbiddenNoteIds.includes(afterNote.noteId)) {+ toastService.showError('Cannot move notes here.');return;}@@ -49,6 +57,11 @@ async function moveAfterBranch(branchIdsToMove, afterBranchId) {}async function moveToParentNote(branchIdsToMove, newParentBranchId) {+ if (newParentBranchId === 'lb_root') {+ toastService.showError('Cannot move notes here.');+ return;+ }+branchIdsToMove = filterRootNote(branchIdsToMove);for (const branchIdToMove of branchIdsToMove) {diff --git a/src/public/app/widgets/dialog.js b/src/public/app/services/dialog.jssimilarity index 93%rename from src/public/app/widgets/dialog.jsrename to src/public/app/services/dialog.jsindex 7c7b935a92..9a401e52fa 100644--- a/src/public/app/widgets/dialog.js+++ b/src/public/app/services/dialog.js@@ -1,4 +1,4 @@-import appContext from "../services/app_context.js";+import appContext from "./app_context.js";async function info(message) {return new Promise(res =>diff --git a/src/public/app/services/hoisted_note.js b/src/public/app/services/hoisted_note.jsindex b188d27a0d..361276c867 100644--- a/src/public/app/services/hoisted_note.js+++ b/src/public/app/services/hoisted_note.js@@ -1,6 +1,6 @@import appContext from "./app_context.js";import treeService from "./tree.js";-import dialogService from "../widgets/dialog.js";+import dialogService from "./dialog.js";import froca from "./froca.js";function getHoistedNoteId() {diff --git a/src/public/app/services/root_command_executor.js b/src/public/app/services/root_command_executor.jsindex e562420079..764e34e8df 100644--- a/src/public/app/services/root_command_executor.js+++ b/src/public/app/services/root_command_executor.js@@ -74,7 +74,13 @@ export default class RootCommandExecutor extends Component {async showLaunchBarShortcutsCommand() {await appContext.tabManager.openContextWithNote('lb_root', true, null, 'lb_root');+ }+ async showShareSubtreeCommand() {+ await appContext.tabManager.openContextWithNote('share', true, null, 'share');+ }+ async showHiddenSubtreeCommand() {+ await appContext.tabManager.openContextWithNote('hidden', true, null, 'hidden');}}diff --git a/src/public/app/widgets/buttons/button_from_note.js b/src/public/app/widgets/buttons/button_from_note.jsnew file mode 100644index 0000000000..bafc809b47--- /dev/null+++ b/src/public/app/widgets/buttons/button_from_note.js@@ -0,0 +1,40 @@+import ButtonWidget from "./button_widget.js";+import froca from "../../services/froca.js";+import attributeService from "../../services/attributes.js";++export default class ButtonFromNoteWidget extends ButtonWidget {+ constructor() {+ super();++ this.settings.buttonNoteId = null;+ }++ buttonNoteId(noteId) {+ this.settings.buttonNoteId = noteId;+ return this;+ }++ doRender() {+ super.doRender();++ this.updateIcon();+ }++ updateIcon() {+ froca.getNote(this.settings.buttonNoteId).then(note => {+ this.settings.icon = note.getLabelValue("iconClass");++ this.refreshIcon();+ });+ }++ entitiesReloadedEvent({loadResults}) {+ if (loadResults.getAttributes(this.componentId).find(attr =>+ attr.type === 'label'+ && attr.name === 'iconClass'+ && attributeService.isAffecting(attr, this.note))) {++ this.updateIcon();+ }+ }+}\ No newline at end of filediff --git a/src/public/app/widgets/buttons/button_widget.js b/src/public/app/widgets/buttons/button_widget.jsindex 92f4d701d5..623facfe60 100644--- a/src/public/app/widgets/buttons/button_widget.js+++ b/src/public/app/widgets/buttons/button_widget.js@@ -18,7 +18,12 @@ export default class ButtonWidget extends NoteContextAwareWidget {super();this.settings = {- titlePlacement: 'right'+ titlePlacement: 'right',+ title: null,+ icon: null,+ command: null,+ onClick: null,+ onContextMenu: null};}@@ -39,6 +44,14 @@ export default class ButtonWidget extends NoteContextAwareWidget {});}+ if (this.settings.onContextMenu) {+ this.$widget.on("contextmenu", e => {+ this.$widget.tooltip("hide");++ this.settings.onContextMenu(e);+ });+ }+this.$widget.attr("data-placement", this.settings.titlePlacement);this.$widget.tooltip({@@ -70,8 +83,7 @@ export default class ButtonWidget extends NoteContextAwareWidget {}}- this.$widget- .addClass(this.settings.icon);+ this.$widget.addClass(this.settings.icon);}initialRenderCompleteEvent() {@@ -102,4 +114,8 @@ export default class ButtonWidget extends NoteContextAwareWidget {this.settings.onClick = handler;return this;}++ onContextMenu(handler) {+ this.settings.onContextMenu = handler;+ }}diff --git a/src/public/app/widgets/buttons/global_menu.js b/src/public/app/widgets/buttons/global_menu.jsindex 45fa441336..0ae7bf1dbc 100644--- a/src/public/app/widgets/buttons/global_menu.js+++ b/src/public/app/widgets/buttons/global_menu.js@@ -124,11 +124,16 @@ const TPL = `<kbd ></kbd></li>- <li class="dropdown-item options-button" data-trigger-command="showLaunchBarShortcuts">+ <li class="dropdown-item" data-trigger-command="showLaunchBarShortcuts"><span class="bx bx-sidebar"></span>Configure launchbar shortcuts</li>+ <li class="dropdown-item" data-trigger-command="showShareSubtree">+ <span class="bx bx-share-alt"></span>+ Show share subtree+ </li>+<li class="dropdown-item dropdown-submenu"><span class="dropdown-toggle"><span class="bx bx-empty"></span>@@ -160,6 +165,11 @@ const TPL = `Reload frontend<kbd data-command="reloadFrontendApp"></kbd></li>++ <li class="dropdown-item" data-trigger-command="showHiddenSubtree">+ <span class="bx bx-empty"></span>+ Show hidden subtree+ </li></ul></li>diff --git a/src/public/app/widgets/history_navigation.js b/src/public/app/widgets/buttons/history/abstract_history.jssimilarity index 58%rename from src/public/app/widgets/history_navigation.jsrename to src/public/app/widgets/buttons/history/abstract_history.jsindex 182cad0c1b..c356961e13 100644--- a/src/public/app/widgets/history_navigation.js+++ b/src/public/app/widgets/buttons/history/abstract_history.js@@ -1,48 +1,17 @@-import BasicWidget from "./basic_widget.js";-import utils from "../services/utils.js";-import contextMenu from "../menus/context_menu.js";-import treeService from "../services/tree.js";--const TPL = `-<div class="history-navigation">- <style>- .history-navigation {- margin: 0 15px 0 5px;+import utils from "../../../services/utils.js";+import contextMenu from "../../../menus/context_menu.js";+import treeService from "../../../services/tree.js";+import ButtonFromNoteWidget from "../button_from_note.js";++export default class AbstractHistoryNavigationWidget extends ButtonFromNoteWidget {+ isEnabled() {+ return super.isEnabled() && utils.isElectron();}- </style>- <a title="Go to previous note." data-trigger-command="backInNoteHistory" class="icon-action bx bx-left-arrow-circle"></a>-- <a title="Go to next note." data-trigger-command="forwardInNoteHistory" class="icon-action bx bx-right-arrow-circle"></a>-</div>-`;--export default class HistoryNavigationWidget extends BasicWidget {doRender() {- if (!utils.isElectron()) {- this.$widget = $("<div>");- return;- }-- this.$widget = $(TPL);-- const contextMenuHandler = e => {- e.preventDefault();-- if (this.webContents.history.length < 2) {- return;- }+ super.doRender();- this.showContextMenu(e);- };-- this.$backInHistory = this.$widget.find("[data-trigger-command='backInNoteHistory']");- this.$backInHistory.on('contextmenu', contextMenuHandler);-- this.$forwardInHistory = this.$widget.find("[data-trigger-command='forwardInNoteHistory']");- this.$forwardInHistory.on('contextmenu', contextMenuHandler);-- this.webContents = utils.dynamicRequire('@electron/remote').webContents;+ this.webContents = utils.dynamicRequire('@electron/remote').getCurrentWebContents();// without this the history is preserved across frontend reloadsthis.webContents.clearHistory();@@ -51,6 +20,16 @@ export default class HistoryNavigationWidget extends BasicWidget {}async showContextMenu(e) {+ e.preventDefault();++ // API is broken and will be replaced: https://github.com/electron/electron/issues/33899+ // until then no context menu+ return;++ if (this.webContents.history.length < 2) {+ return;+ }+let items = [];const activeIndex = this.webContents.getActiveIndex();diff --git a/src/public/app/widgets/buttons/history/history_back.js b/src/public/app/widgets/buttons/history/history_back.jsnew file mode 100644index 0000000000..63fc51f584--- /dev/null+++ b/src/public/app/widgets/buttons/history/history_back.js@@ -0,0 +1,14 @@+import AbstractHistoryNavigationWidget from "./abstract_history.js";++export default class BackInHistoryButtonWidget extends AbstractHistoryNavigationWidget {+ constructor() {+ super();++ this.icon('bx-left-arrow-circle')+ .title("Go to previous note.")+ .command("backInNoteHistory")+ .titlePlacement("right")+ .buttonNoteId('lb_backinhistory')+ .onContextMenu(e => this.showContextMenu(e));+ }+}diff --git a/src/public/app/widgets/buttons/history/history_forward.js b/src/public/app/widgets/buttons/history/history_forward.jsnew file mode 100644index 0000000000..9b5fde0041--- /dev/null+++ b/src/public/app/widgets/buttons/history/history_forward.js@@ -0,0 +1,14 @@+import AbstractHistoryNavigationWidget from "./abstract_history.js";++export default class ForwardInHistoryButtonWidget extends AbstractHistoryNavigationWidget {+ constructor() {+ super();++ this.icon('bx-left-arrow-circle')+ .title("Go to next note.")+ .command("forwardInNoteHistory")+ .titlePlacement("right")+ .buttonNoteId('lb_forwardinhistory')+ .onContextMenu(e => this.showContextMenu(e));+ }+}diff --git a/src/public/app/widgets/buttons/note_revisions_button.js b/src/public/app/widgets/buttons/note_revisions_button.jsindex a8bb1945ff..dace67dcb5 100644--- a/src/public/app/widgets/buttons/note_revisions_button.js+++ b/src/public/app/widgets/buttons/note_revisions_button.js@@ -11,6 +11,6 @@ export default class NoteRevisionsButton extends ButtonWidget {}isEnabled() {- return super.isEnabled() && this.note?.type !== 'shortcut';+ return super.isEnabled() && !['shortcut', 'doc'].includes(this.note?.type);}}\ No newline at end of filediff --git a/src/public/app/widgets/buttons/show_note_source.js b/src/public/app/widgets/buttons/show_note_source.jsdeleted file mode 100644index c3d8c7d1c6..0000000000--- a/src/public/app/widgets/buttons/show_note_source.js+++ /dev/null@@ -1,16 +0,0 @@-import ButtonWidget from "./button_widget.js";--export default class ShowNoteSourceButton extends ButtonWidget {- isEnabled() {- return super.isEnabled() && this.note && ['text', 'relation-map'].includes(this.note.type);- }-- constructor() {- super();-- this.icon('bx bx-code')- .title("Show Note Source")- .command("openNoteSourceDialog")- .titlePlacement("bottom");- }-}diff --git a/src/public/app/widgets/containers/shortcut_container.js b/src/public/app/widgets/containers/shortcut_container.jsindex ee8f30fe55..9422c5812b 100644--- a/src/public/app/widgets/containers/shortcut_container.js+++ b/src/public/app/widgets/containers/shortcut_container.js@@ -7,6 +7,8 @@ import SpacerWidget from "../spacer.js";import BookmarkButtons from "../bookmark_buttons.js";import ProtectedSessionStatusWidget from "../buttons/protected_session_status.js";import SyncStatusWidget from "../sync_status.js";+import BackInHistoryButtonWidget from "../buttons/history/history_back.js";+import ForwardInHistoryButtonWidget from "../buttons/history/history_forward.js";export default class ShortcutContainer extends FlexContainer {constructor() {@@ -63,6 +65,10 @@ export default class ShortcutContainer extends FlexContainer {this.child(new ProtectedSessionStatusWidget());} else if (builtinWidget === 'syncStatus') {this.child(new SyncStatusWidget());+ } else if (builtinWidget === 'backInHistoryButton') {+ this.child(new BackInHistoryButtonWidget());+ } else if (builtinWidget === 'forwardInHistoryButton') {+ this.child(new ForwardInHistoryButtonWidget());} else {console.log(`Unrecognized builtin widget ${builtinWidget} for shortcut ${shortcut.noteId} "${shortcut.title}"`);}diff --git a/src/public/app/widgets/dialogs/note_revisions.js b/src/public/app/widgets/dialogs/note_revisions.jsindex 7df8ea5920..9560ad575a 100644--- a/src/public/app/widgets/dialogs/note_revisions.js+++ b/src/public/app/widgets/dialogs/note_revisions.js@@ -6,7 +6,7 @@ import libraryLoader from "../../services/library_loader.js";import openService from "../../services/open.js";import protectedSessionHolder from "../../services/protected_session_holder.js";import BasicWidget from "../basic_widget.js";-import dialogService from "../dialog.js";+import dialogService from "../../services/dialog.js";const TPL = `<div class="note-revisions-dialog modal fade mx-auto" tabindex="-1" role="dialog">diff --git a/src/public/app/widgets/dialogs/options/etapi.js b/src/public/app/widgets/dialogs/options/etapi.jsindex 7bbaf4dc49..0c662b4672 100644--- a/src/public/app/widgets/dialogs/options/etapi.js+++ b/src/public/app/widgets/dialogs/options/etapi.js@@ -1,5 +1,5 @@import server from "../../../services/server.js";-import dialogService from "../../dialog.js";+import dialogService from "../../../services/dialog.js";import toastService from "../../../services/toast.js";import OptionsTab from "./options_tab.js";diff --git a/src/public/app/widgets/dialogs/options/shortcuts.js b/src/public/app/widgets/dialogs/options/shortcuts.jsindex 34abd5c29f..a0836b8114 100644--- a/src/public/app/widgets/dialogs/options/shortcuts.js+++ b/src/public/app/widgets/dialogs/options/shortcuts.js@@ -1,6 +1,6 @@import server from "../../../services/server.js";import utils from "../../../services/utils.js";-import dialogService from "../../dialog.js";+import dialogService from "../../../services/dialog.js";import OptionsTab from "./options_tab.js";const TPL = `diff --git a/src/public/app/widgets/dialogs/recent_changes.js b/src/public/app/widgets/dialogs/recent_changes.jsindex 10f1187d7d..c9e5d35106 100644--- a/src/public/app/widgets/dialogs/recent_changes.js+++ b/src/public/app/widgets/dialogs/recent_changes.js@@ -6,7 +6,7 @@ import froca from "../../services/froca.js";import appContext from "../../services/app_context.js";import hoistedNoteService from "../../services/hoisted_note.js";import BasicWidget from "../basic_widget.js";-import dialogService from "../dialog.js";+import dialogService from "../../services/dialog.js";import toastService from "../../services/toast.js";const TPL = `diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.jsindex 425fd9dde0..4d9e791b19 100644--- a/src/public/app/widgets/note_tree.js+++ b/src/public/app/widgets/note_tree.js@@ -17,7 +17,7 @@ import linkService from "../services/link.js";import syncService from "../services/sync.js";import options from "../services/options.js";import protectedSessionHolder from "../services/protected_session_holder.js";-import dialogService from "./dialog.js";+import dialogService from "../services/dialog.js";const TPL = `<div class="tree-wrapper">@@ -368,7 +368,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {},beforeActivate: (event, data) => {// hidden subtree is hidden hackily, prevent activating it e.g. by keyboard- return data.node.data.noteId !== 'hidden';+ return hoistedNoteService.getHoistedNoteId() === 'hidden' || data.node.data.noteId !== 'hidden';},activate: async (event, data) => {// click event won't propagate so let's close context menu manuallydiff --git a/src/public/app/widgets/note_type.js b/src/public/app/widgets/note_type.jsindex 60c9799736..0603d86849 100644--- a/src/public/app/widgets/note_type.js+++ b/src/public/app/widgets/note_type.js@@ -1,7 +1,7 @@import server from '../services/server.js';import mimeTypesService from '../services/mime_types.js';import NoteContextAwareWidget from "./note_context_aware_widget.js";-import dialogService from "./dialog.js";+import dialogService from "../services/dialog.js";const NOTE_TYPES = [{ type: "file", title: "File", selectable: false },@@ -9,6 +9,7 @@ const NOTE_TYPES = [{ type: "search", title: "Saved Search", selectable: false },{ type: "note-map", mime: '', title: "Note Map", selectable: false },{ type: "shortcut", mime: '', title: "Shortcut", selectable: false },+ { type: "doc", mime: '', title: "Doc", selectable: false },{ type: "text", mime: "text/html", title: "Text", selectable: true },{ type: "relation-map", mime: "application/json", title: "Relation Map", selectable: true },diff --git a/src/public/app/widgets/shared_switch.js b/src/public/app/widgets/shared_switch.jsindex e7f10d5909..c9b2ba7a21 100644--- a/src/public/app/widgets/shared_switch.js+++ b/src/public/app/widgets/shared_switch.js@@ -3,7 +3,7 @@ import branchService from "../services/branches.js";import server from "../services/server.js";import utils from "../services/utils.js";import syncService from "../services/sync.js";-import dialogService from "./dialog.js";+import dialogService from "../services/dialog.js";export default class SharedSwitchWidget extends SwitchWidget {isEnabled() {diff --git a/src/public/app/widgets/type_widgets/relation_map.js b/src/public/app/widgets/type_widgets/relation_map.jsindex 3064ab2e0a..4625f36725 100644--- a/src/public/app/widgets/type_widgets/relation_map.js+++ b/src/public/app/widgets/type_widgets/relation_map.js@@ -8,7 +8,7 @@ import TypeWidget from "./type_widget.js";import appContext from "../../services/app_context.js";import utils from "../../services/utils.js";import froca from "../../services/froca.js";-import dialogService from "../../widgets/dialog.js";+import dialogService from "../../services/dialog.js";const uniDirectionalOverlays = [[ "Arrow", {diff --git a/src/routes/api/special_notes.js b/src/routes/api/special_notes.jsindex 6e6d50d830..cbbc4b1f10 100644--- a/src/routes/api/special_notes.js+++ b/src/routes/api/special_notes.js@@ -70,6 +70,10 @@ function createShortcut(req) {return specialNotesService.createShortcut(req.params.parentNoteId, req.params.type);}+function resetShortcut(req) {+ return specialNotesService.resetShortcut(req.params.noteId);+}+module.exports = {getInboxNote,getDayNote,@@ -81,5 +85,6 @@ module.exports = {saveSqlConsole,createSearchNote,saveSearchNote,- createShortcut+ createShortcut,+ resetShortcut};diff --git a/src/routes/routes.js b/src/routes/routes.jsindex b7b08b959e..4cd7ebb98a 100644--- a/src/routes/routes.js+++ b/src/routes/routes.js@@ -326,6 +326,7 @@ function register(app) {apiRoute(POST, '/api/special-notes/save-sql-console', specialNotesRoute.saveSqlConsole);apiRoute(POST, '/api/special-notes/search-note', specialNotesRoute.createSearchNote);apiRoute(POST, '/api/special-notes/save-search-note', specialNotesRoute.saveSearchNote);+ apiRoute(POST, '/api/special-notes/shortcuts/:noteId/reset', specialNotesRoute.resetShortcut);apiRoute(POST, '/api/special-notes/shortcuts/:parentNoteId/:type', specialNotesRoute.createShortcut);// :filename is not used by trilium, but instead used for "save as" to assign a human-readable filenamediff --git a/src/services/app_info.js b/src/services/app_info.jsindex f9f73d368a..7953258dac 100644--- a/src/services/app_info.js+++ b/src/services/app_info.js@@ -4,7 +4,7 @@ const build = require('./build');const packageJson = require('../../package');const {TRILIUM_DATA_DIR} = require('./data_dir');-const APP_DB_VERSION = 202;+const APP_DB_VERSION = 203;const SYNC_VERSION = 27;const CLIPPER_PROTOCOL_VERSION = "1.0";diff --git a/src/services/note_types.js b/src/services/note_types.jsindex 38172beefb..d467d9f24a 100644--- a/src/services/note_types.js+++ b/src/services/note_types.js@@ -11,5 +11,6 @@ module.exports = ['mermaid','canvas','web-view',- 'shortcut'+ 'shortcut',+ 'doc'];diff --git a/src/services/special_notes.js b/src/services/special_notes.jsindex c5b7c66b71..2aacc32dce 100644--- a/src/services/special_notes.js+++ b/src/services/special_notes.js@@ -37,7 +37,7 @@ function getHiddenRoot() {branchId: 'hidden',noteId: 'hidden',title: 'hidden',- type: 'text',+ type: 'doc',content: '',parentNoteId: 'root'}).note;@@ -46,6 +46,11 @@ function getHiddenRoot() {// the flag is not inherited to the childrenhidden.addLabel('archived', "", false);hidden.addLabel('excludeFromNoteMap', "", true);+ hidden.addLabel('iconClass', "bx bx-chip", false);+ }++ if (!hidden.hasOwnedLabel("docName")) {+ hidden.addLabel("docName", "hidden");}return hidden;@@ -59,7 +64,7 @@ function getSearchRoot() {branchId: 'search',noteId: 'search',title: 'search',- type: 'text',+ type: 'doc',content: '',parentNoteId: getHiddenRoot().noteId}).note;@@ -95,10 +100,12 @@ function getSqlConsoleRoot() {branchId: 'sqlconsole',noteId: 'sqlconsole',title: 'SQL Console',- type: 'text',+ type: 'doc',content: '',parentNoteId: getHiddenRoot().noteId}).note;++ sqlConsoleRoot.addLabel('iconClass', 'bx bx-data');}return sqlConsoleRoot;@@ -114,6 +121,7 @@ function createSqlConsole() {});note.setLabel("sqlConsole", dateUtils.localNowDate());+ note.setLabel('iconClass', 'bx bx-data');return note;}@@ -199,12 +207,16 @@ function getShareRoot() {branchId: 'share',noteId: 'share',title: 'Shared notes',- type: 'text',+ type: 'doc',content: '',parentNoteId: hiddenRoot.noteId}).note;}+ if (!shareRoot.hasOwnedLabel("docName")) {+ shareRoot.addLabel("docName", "share");+ }+return shareRoot;}@@ -233,7 +245,7 @@ function getLaunchBarRoot() {branchId: 'lb_root',noteId: 'lb_root',title: 'Launch bar',- type: 'shortcut',+ type: 'doc',content: '',parentNoteId: getHiddenRoot().noteId}).note;@@ -253,7 +265,7 @@ function getLaunchBarAvailableShortcutsRoot() {branchId: 'lb_availableshortcuts',noteId: 'lb_availableshortcuts',title: 'Available shortcuts',- type: 'shortcut',+ type: 'doc',content: '',parentNoteId: getLaunchBarRoot().noteId}).note;@@ -279,7 +291,7 @@ function getLaunchBarVisibleShortcutsRoot() {branchId: 'lb_visibleshortcuts',noteId: 'lb_visibleshortcuts',title: 'Visible shortcuts',- type: 'shortcut',+ type: 'doc',content: '',parentNoteId: getLaunchBarRoot().noteId}).note;@@ -298,11 +310,11 @@ function getLaunchBarVisibleShortcutsRoot() {}const shortcuts = [+ // visible shortcuts:{ id: 'lb_newnote', command: 'createNoteIntoInbox', title: 'New note', icon: 'bx bx-file-blank', isVisible: true },{ id: 'lb_search', command: 'searchNotes', title: 'Search notes', icon: 'bx bx-search', isVisible: true },{ id: 'lb_jumpto', command: 'jumpToNote', title: 'Jump to note', icon: 'bx bx-send', isVisible: true },{ id: 'lb_notemap', targetNoteId: 'globalnotemap', title: 'Note map', icon: 'bx bx-map-alt', isVisible: true },- { id: 'lb_recentchanges', command: 'showRecentChanges', title: 'Recent changes', icon: 'bx bx-history', isVisible: false },{ id: 'lb_calendar', builtinWidget: 'calendar', title: 'Calendar', icon: 'bx bx-calendar', isVisible: true },{ id: 'lb_spacer1', builtinWidget: 'spacer', title: 'Spacer', icon: 'bx bx-move-vertical', isVisible: true, labels: [{ type: "number", name: "baseSize", value: "40" },@@ -316,6 +328,11 @@ const shortcuts = [] },{ id: 'lb_protectedsession', builtinWidget: 'protectedSession', title: 'Protected session', icon: 'bx bx bx-shield-quarter', isVisible: true },{ id: 'lb_syncstatus', builtinWidget: 'syncStatus', title: 'Sync status', icon: 'bx bx-wifi', isVisible: true },++ // available shortcuts:+ { id: 'lb_recentchanges', command: 'showRecentChanges', title: 'Recent changes', icon: 'bx bx-history', isVisible: false },+ { id: 'lb_backinhistory', builtinWidget: 'backInHistoryButton', title: 'Back in history', icon: 'bx bxs-left-arrow-square', isVisible: false },+ { id: 'lb_forwardinhistory', builtinWidget: 'forwardInHistoryButton', title: 'Forward in history', icon: 'bx bxs-right-arrow-square', isVisible: false },];function createMissingSpecialNotes() {@@ -324,7 +341,8 @@ function createMissingSpecialNotes() {getBulkActionNote();getLaunchBarRoot();getLaunchBarAvailableShortcutsRoot();- getLaunchBarVisibleShortcutsRoot()+ getLaunchBarVisibleShortcutsRoot();+ getShareRoot();for (const shortcut of shortcuts) {let note = becca.getNote(shortcut.id);@@ -333,7 +351,10 @@ function createMissingSpecialNotes() {continue;}- const parentNoteId = shortcut.isVisible ? getLaunchBarVisibleShortcutsRoot().noteId : getLaunchBarAvailableShortcutsRoot().noteId;+ const parentNoteId = shortcut.isVisible+ ? getLaunchBarVisibleShortcutsRoot().noteId+ : getLaunchBarAvailableShortcutsRoot().noteId;+note = noteService.createNewNote({noteId: shortcut.id,title: shortcut.title,@@ -428,6 +449,29 @@ function createShortcut(parentNoteId, type) {};}+function resetShortcut(noteId) {+ if (noteId.startsWith('lb_')) {+ const note = becca.getNote(noteId);++ if (note) {+ if (noteId === 'lb_root') {+ // deleting hoisted notes are not allowed, so we just reset the children+ for (const childNote of note.getChildNotes()) {+ childNote.deleteNote();+ }+ } else {+ note.deleteNote();+ }+ } else {+ log.info(`Note ${noteId} has not been found and cannot be reset.`);+ }+ } else {+ log.info(`Note ${noteId} is not a resettable shortcut note.`);+ }++ createMissingSpecialNotes();+}+module.exports = {getInboxNote,createSqlConsole,@@ -438,5 +482,6 @@ module.exports = {getShareRoot,getHiddenRoot,getBulkActionNote,- createShortcut+ createShortcut,+ resetShortcut};