mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	chore(client/ts): port components/app_context
This commit is contained in:
		| @@ -1,7 +1,7 @@ | |||||||
| import froca from "../services/froca.js"; | import froca from "../services/froca.js"; | ||||||
| import bundleService from "../services/bundle.js"; | import bundleService from "../services/bundle.js"; | ||||||
| import RootCommandExecutor from "./root_command_executor.js"; | import RootCommandExecutor from "./root_command_executor.js"; | ||||||
| import Entrypoints from "./entrypoints.js"; | import Entrypoints, { SqlExecuteResults } from "./entrypoints.js"; | ||||||
| import options from "../services/options.js"; | import options from "../services/options.js"; | ||||||
| import utils from "../services/utils.js"; | import utils from "../services/utils.js"; | ||||||
| import zoomComponent from "./zoom.js"; | import zoomComponent from "./zoom.js"; | ||||||
| @@ -52,6 +52,12 @@ export interface ContextMenuCommandData extends CommandData { | |||||||
|     selectedOrActiveNoteIds: any; // TODO: Remove  any once type is defined |     selectedOrActiveNoteIds: any; // TODO: Remove  any once type is defined | ||||||
| } | } | ||||||
|  |  | ||||||
|  | export interface NoteCommandData extends CommandData { | ||||||
|  |     notePath: string; | ||||||
|  |     hoistedNoteId?: string; | ||||||
|  |     viewScope?: ViewScope; | ||||||
|  | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * The keys represent the different commands that can be triggered via {@link AppContext#triggerCommand} (first argument), and the values represent the data or arguments definition of the given command. All data for commands must extend {@link CommandData}. |  * The keys represent the different commands that can be triggered via {@link AppContext#triggerCommand} (first argument), and the values represent the data or arguments definition of the given command. All data for commands must extend {@link CommandData}. | ||||||
|  */ |  */ | ||||||
| @@ -79,17 +85,8 @@ export type CommandMappings = { | |||||||
|     showPromptDialog: PromptDialogOptions; |     showPromptDialog: PromptDialogOptions; | ||||||
|     showInfoDialog: ConfirmWithMessageOptions; |     showInfoDialog: ConfirmWithMessageOptions; | ||||||
|     showConfirmDialog: ConfirmWithMessageOptions; |     showConfirmDialog: ConfirmWithMessageOptions; | ||||||
|     openNewNoteSplit: CommandData & { |     openNewNoteSplit: NoteCommandData; | ||||||
|         ntxId: string; |     openInWindow: NoteCommandData, | ||||||
|         notePath: string; |  | ||||||
|         hoistedNoteId?: string; |  | ||||||
|         viewScope?: ViewScope; |  | ||||||
|     }; |  | ||||||
|     openInWindow: CommandData & { |  | ||||||
|         notePath: string; |  | ||||||
|         hoistedNoteId: string; |  | ||||||
|         viewScope: ViewScope; |  | ||||||
|     }, |  | ||||||
|     openNoteInNewTab: CommandData; |     openNoteInNewTab: CommandData; | ||||||
|     openNoteInNewSplit: CommandData; |     openNoteInNewSplit: CommandData; | ||||||
|     openNoteInNewWindow: CommandData; |     openNoteInNewWindow: CommandData; | ||||||
| @@ -173,6 +170,10 @@ type EventMappings = { | |||||||
|     }; |     }; | ||||||
|     addNewLabel: CommandData; |     addNewLabel: CommandData; | ||||||
|     addNewRelation: CommandData; |     addNewRelation: CommandData; | ||||||
|  |     sqlQueryResults: { | ||||||
|  |         ntxId: string; | ||||||
|  |         results: SqlExecuteResults; | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| export type EventListener<T extends EventNames> = { | export type EventListener<T extends EventNames> = { | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ import utils from "../services/utils.js"; | |||||||
| import dateNoteService from "../services/date_notes.js"; | import dateNoteService from "../services/date_notes.js"; | ||||||
| import protectedSessionHolder from '../services/protected_session_holder.js'; | import protectedSessionHolder from '../services/protected_session_holder.js'; | ||||||
| import server from "../services/server.js"; | import server from "../services/server.js"; | ||||||
| import appContext from "./app_context.js"; | import appContext, { NoteCommandData } from "./app_context.js"; | ||||||
| import Component from "./component.js"; | import Component from "./component.js"; | ||||||
| import toastService from "../services/toast.js"; | import toastService from "../services/toast.js"; | ||||||
| import ws from "../services/ws.js"; | import ws from "../services/ws.js"; | ||||||
| @@ -10,6 +10,22 @@ import bundleService from "../services/bundle.js"; | |||||||
| import froca from "../services/froca.js"; | import froca from "../services/froca.js"; | ||||||
| import linkService from "../services/link.js"; | import linkService from "../services/link.js"; | ||||||
| import { t } from "../services/i18n.js"; | import { t } from "../services/i18n.js"; | ||||||
|  | import FNote from "../entities/fnote.js"; | ||||||
|  | 
 | ||||||
|  | // TODO: Move somewhere else nicer.
 | ||||||
|  | export type SqlExecuteResults = unknown[]; | ||||||
|  | 
 | ||||||
|  | // TODO: Deduplicate with server.
 | ||||||
|  | interface SqlExecuteResponse { | ||||||
|  |     success: boolean; | ||||||
|  |     error?: string; | ||||||
|  |     results: SqlExecuteResults; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // TODO: Deduplicate with server.
 | ||||||
|  | interface CreateChildrenResponse { | ||||||
|  |     note: FNote; | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| export default class Entrypoints extends Component { | export default class Entrypoints extends Component { | ||||||
|     constructor() { |     constructor() { | ||||||
| @@ -31,8 +47,12 @@ export default class Entrypoints extends Component { | |||||||
| 
 | 
 | ||||||
|     async createNoteIntoInboxCommand() { |     async createNoteIntoInboxCommand() { | ||||||
|         const inboxNote = await dateNoteService.getInboxNote(); |         const inboxNote = await dateNoteService.getInboxNote(); | ||||||
|  |         if (!inboxNote) { | ||||||
|  |             console.warn("Missing inbox note."); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
|         const {note} = await server.post(`notes/${inboxNote.noteId}/children?target=into`, { |         const {note} = await server.post<CreateChildrenResponse>(`notes/${inboxNote.noteId}/children?target=into`, { | ||||||
|             content: '', |             content: '', | ||||||
|             type: 'text', |             type: 'text', | ||||||
|             isProtected: inboxNote.isProtected && protectedSessionHolder.isProtectedSessionAvailable() |             isProtected: inboxNote.isProtected && protectedSessionHolder.isProtectedSessionAvailable() | ||||||
| @@ -46,18 +66,21 @@ export default class Entrypoints extends Component { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async toggleNoteHoistingCommand({noteId = appContext.tabManager.getActiveContextNoteId()}) { |     async toggleNoteHoistingCommand({noteId = appContext.tabManager.getActiveContextNoteId()}) { | ||||||
|  |         if (!noteId) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         const noteToHoist = await froca.getNote(noteId); |         const noteToHoist = await froca.getNote(noteId); | ||||||
|         const activeNoteContext = appContext.tabManager.getActiveContext(); |         const activeNoteContext = appContext.tabManager.getActiveContext(); | ||||||
| 
 | 
 | ||||||
|         if (noteToHoist.noteId === activeNoteContext.hoistedNoteId) { |         if (noteToHoist?.noteId === activeNoteContext.hoistedNoteId) { | ||||||
|             await activeNoteContext.unhoist(); |             await activeNoteContext.unhoist(); | ||||||
|         } |         } else if (noteToHoist?.type !== 'search') { | ||||||
|         else if (noteToHoist.type !== 'search') { |  | ||||||
|             await activeNoteContext.setHoistedNoteId(noteId); |             await activeNoteContext.setHoistedNoteId(noteId); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async hoistNoteCommand({noteId}) { |     async hoistNoteCommand({noteId}: { noteId: string }) { | ||||||
|         const noteContext = appContext.tabManager.getActiveContext(); |         const noteContext = appContext.tabManager.getActiveContext(); | ||||||
| 
 | 
 | ||||||
|         if (noteContext.hoistedNoteId !== noteId) { |         if (noteContext.hoistedNoteId !== noteId) { | ||||||
| @@ -137,7 +160,7 @@ export default class Entrypoints extends Component { | |||||||
|         utils.reloadFrontendApp("Switching to mobile version"); |         utils.reloadFrontendApp("Switching to mobile version"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async openInWindowCommand({notePath, hoistedNoteId, viewScope}) { |     async openInWindowCommand({notePath, hoistedNoteId, viewScope}: NoteCommandData) { | ||||||
|         const extraWindowHash = linkService.calculateHash({notePath, hoistedNoteId, viewScope}); |         const extraWindowHash = linkService.calculateHash({notePath, hoistedNoteId, viewScope}); | ||||||
| 
 | 
 | ||||||
|         if (utils.isElectron()) { |         if (utils.isElectron()) { | ||||||
| @@ -170,7 +193,7 @@ export default class Entrypoints extends Component { | |||||||
|         } else if (note.mime.endsWith("env=backend")) { |         } else if (note.mime.endsWith("env=backend")) { | ||||||
|             await server.post(`script/run/${note.noteId}`); |             await server.post(`script/run/${note.noteId}`); | ||||||
|         } else if (note.mime === 'text/x-sqlite;schema=trilium') { |         } else if (note.mime === 'text/x-sqlite;schema=trilium') { | ||||||
|             const resp = await server.post(`sql/execute/${note.noteId}`); |             const resp = await server.post<SqlExecuteResponse>(`sql/execute/${note.noteId}`); | ||||||
| 
 | 
 | ||||||
|             if (!resp.success) { |             if (!resp.success) { | ||||||
|                 toastService.showError(t("entrypoints.sql-error", { message: resp.error })); |                 toastService.showError(t("entrypoints.sql-error", { message: resp.error })); | ||||||
| @@ -1,6 +1,6 @@ | |||||||
| import treeService from './tree.js'; | import treeService from './tree.js'; | ||||||
| import linkContextMenuService from "../menus/link_context_menu.js"; | import linkContextMenuService from "../menus/link_context_menu.js"; | ||||||
| import appContext from "../components/app_context.js"; | import appContext, { NoteCommandData } from "../components/app_context.js"; | ||||||
| import froca from "./froca.js"; | import froca from "./froca.js"; | ||||||
| import utils from "./utils.js"; | import utils from "./utils.js"; | ||||||
|  |  | ||||||
| @@ -141,14 +141,7 @@ async function createLink(notePath: string, options: CreateLinkOptions = {}) { | |||||||
|     return $container; |     return $container; | ||||||
| } | } | ||||||
|  |  | ||||||
| interface CalculateHashOpts { | function calculateHash({notePath, ntxId, hoistedNoteId, viewScope = {}}: NoteCommandData) { | ||||||
|     notePath: string; |  | ||||||
|     ntxId?: string; |  | ||||||
|     hoistedNoteId?: string; |  | ||||||
|     viewScope: ViewScope; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| function calculateHash({notePath, ntxId, hoistedNoteId, viewScope = {}}: CalculateHashOpts) { |  | ||||||
|     notePath = notePath || ""; |     notePath = notePath || ""; | ||||||
|     const params = [ |     const params = [ | ||||||
|         ntxId ? { ntxId: ntxId } : null, |         ntxId ? { ntxId: ntxId } : null, | ||||||
|   | |||||||
							
								
								
									
										10
									
								
								src/public/app/types.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										10
									
								
								src/public/app/types.d.ts
									
									
									
									
										vendored
									
									
								
							| @@ -93,6 +93,16 @@ declare global { | |||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     interface JQueryStatic { | ||||||
|  |         hotkeys: { | ||||||
|  |             options: { | ||||||
|  |                 filterInputAcceptingElements: boolean; | ||||||
|  |                 filterContentEditable: boolean; | ||||||
|  |                 filterTextInputs: boolean; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     var logError: (message: string, e?: Error) => void; |     var logError: (message: string, e?: Error) => void; | ||||||
|     var logInfo: (message: string) => void; |     var logInfo: (message: string) => void; | ||||||
|     var glob: CustomGlobals; |     var glob: CustomGlobals; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user