mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 21:11:30 +08:00 
			
		
		
		
	feat(note_language): add in-app help
This commit is contained in:
		
							parent
							
								
									e514396c42
								
							
						
					
					
						commit
						dd28ce9e5d
					
				| @ -1,5 +1,8 @@ | |||||||
| import dayjs from "dayjs"; | import dayjs from "dayjs"; | ||||||
| import { Modal } from "bootstrap"; | import { Modal } from "bootstrap"; | ||||||
|  | import type { ViewScope } from "./link.js"; | ||||||
|  | import appContext from "../components/app_context.js"; | ||||||
|  | import { setLogLevel } from "mermaid/dist/logger.js"; | ||||||
| 
 | 
 | ||||||
| function reloadFrontendApp(reason?: string) { | function reloadFrontendApp(reason?: string) { | ||||||
|     if (reason) { |     if (reason) { | ||||||
| @ -388,6 +391,10 @@ function initHelpDropdown($el: JQuery<HTMLElement>) { | |||||||
| const wikiBaseUrl = "https://triliumnext.github.io/Docs/Wiki/"; | const wikiBaseUrl = "https://triliumnext.github.io/Docs/Wiki/"; | ||||||
| 
 | 
 | ||||||
| function openHelp($button: JQuery<HTMLElement>) { | function openHelp($button: JQuery<HTMLElement>) { | ||||||
|  |     if ($button.length === 0) { | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     const helpPage = $button.attr("data-help-page"); |     const helpPage = $button.attr("data-help-page"); | ||||||
| 
 | 
 | ||||||
|     if (helpPage) { |     if (helpPage) { | ||||||
| @ -397,12 +404,42 @@ function openHelp($button: JQuery<HTMLElement>) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | function openInAppHelp($button: JQuery<HTMLElement>) { | ||||||
|  |     if ($button.length === 0) { | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     const inAppHelpPage = $button.attr("data-in-app-help"); | ||||||
|  |     if (inAppHelpPage) { | ||||||
|  |         const subContexts = appContext.tabManager.getActiveContext().getSubContexts(); | ||||||
|  |         const targetNote = `_help_${inAppHelpPage}`; | ||||||
|  |         const helpSubcontext = subContexts.find((s) => s.viewScope?.viewMode === "contextual-help"); | ||||||
|  |         const viewScope: ViewScope = { | ||||||
|  |             viewMode: "contextual-help", | ||||||
|  |         }; | ||||||
|  |         if (!helpSubcontext) { | ||||||
|  |             // The help is not already open, open a new split with it.
 | ||||||
|  |             const { ntxId } = subContexts[subContexts.length - 1]; | ||||||
|  |             appContext.triggerCommand("openNewNoteSplit", { | ||||||
|  |                 ntxId, | ||||||
|  |                 notePath: targetNote, | ||||||
|  |                 hoistedNoteId: "_help", | ||||||
|  |                 viewScope | ||||||
|  |             }) | ||||||
|  |         } else { | ||||||
|  |             // There is already a help window open, make sure it opens on the right note.
 | ||||||
|  |             helpSubcontext.setNote(targetNote, { viewScope }); | ||||||
|  |         } | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| function initHelpButtons($el: JQuery<HTMLElement> | JQuery<Window>) { | function initHelpButtons($el: JQuery<HTMLElement> | JQuery<Window>) { | ||||||
|     // for some reason, the .on(event, listener, handler) does not work here (e.g. Options -> Sync -> Help button)
 |     // for some reason, the .on(event, listener, handler) does not work here (e.g. Options -> Sync -> Help button)
 | ||||||
|     // so we do it manually
 |     // so we do it manually
 | ||||||
|     $el.on("click", (e) => { |     $el.on("click", (e) => { | ||||||
|         const $helpButton = $(e.target).closest("[data-help-page]"); |         openHelp($(e.target).closest("[data-help-page]")); | ||||||
|         openHelp($helpButton); |         openInAppHelp($(e.target).closest("[data-in-app-help]")); | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,4 +1,5 @@ | |||||||
| import appContext, { type EventData } from "../../components/app_context.js"; | import appContext, { type EventData } from "../../components/app_context.js"; | ||||||
|  | import type FNote from "../../entities/fnote.js"; | ||||||
| import type { NoteType } from "../../entities/fnote.js"; | import type { NoteType } from "../../entities/fnote.js"; | ||||||
| import { t } from "../../services/i18n.js"; | import { t } from "../../services/i18n.js"; | ||||||
| import type { ViewScope } from "../../services/link.js"; | import type { ViewScope } from "../../services/link.js"; | ||||||
| @ -39,47 +40,28 @@ const byBookType: Record<ViewTypeOptions, string | null> = { | |||||||
| 
 | 
 | ||||||
| export default class ContextualHelpButton extends NoteContextAwareWidget { | export default class ContextualHelpButton extends NoteContextAwareWidget { | ||||||
| 
 | 
 | ||||||
|     private helpNoteIdToOpen?: string | null; |  | ||||||
| 
 |  | ||||||
|     isEnabled() { |     isEnabled() { | ||||||
|         this.helpNoteIdToOpen = null; |  | ||||||
| 
 |  | ||||||
|         if (!super.isEnabled()) { |         if (!super.isEnabled()) { | ||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (this.note && this.note.type !== "book" && byNoteType[this.note.type]) { |         return !!ContextualHelpButton.#getUrlToOpen(this.note); | ||||||
|             this.helpNoteIdToOpen = byNoteType[this.note.type]; |  | ||||||
|         } else if (this.note && this.note.type === "book") { |  | ||||||
|             this.helpNoteIdToOpen = byBookType[this.note.getAttributeValue("label", "viewType") as ViewTypeOptions ?? ""] |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         return !!this.helpNoteIdToOpen; |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     doRender() { |     doRender() { | ||||||
|         this.$widget = $(TPL); |         this.$widget = $(TPL); | ||||||
|         this.$widget.on("click", () => { |     } | ||||||
|             const subContexts = appContext.tabManager.getActiveContext().getSubContexts(); | 
 | ||||||
|             const targetNote = `_help_${this.helpNoteIdToOpen}`; |     static #getUrlToOpen(note: FNote | null | undefined) { | ||||||
|             const helpSubcontext = subContexts.find((s) => s.viewScope?.viewMode === "contextual-help"); |         if (note && note.type !== "book" && byNoteType[note.type]) { | ||||||
|             const viewScope: ViewScope = { |             return byNoteType[note.type]; | ||||||
|                 viewMode: "contextual-help", |         } else if (note && note.type === "book") { | ||||||
|             }; |             return byBookType[note.getAttributeValue("label", "viewType") as ViewTypeOptions ?? ""] | ||||||
|             if (!helpSubcontext) { |         } | ||||||
|                 // The help is not already open, open a new split with it.
 |     } | ||||||
|                 const { ntxId } = subContexts[subContexts.length - 1]; | 
 | ||||||
|                 this.triggerCommand("openNewNoteSplit", { |     async refreshWithNote(note: FNote | null | undefined): Promise<void> { | ||||||
|                     ntxId, |         this.$widget.attr("data-in-app-help", ContextualHelpButton.#getUrlToOpen(this.note) ?? ""); | ||||||
|                     notePath: targetNote, |  | ||||||
|                     hoistedNoteId: "_help", |  | ||||||
|                     viewScope |  | ||||||
|                 }) |  | ||||||
|             } else { |  | ||||||
|                 // There is already a help window open, make sure it opens on the right note.
 |  | ||||||
|                 helpSubcontext.setNote(targetNote, { viewScope }); |  | ||||||
|             } |  | ||||||
|         }); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) { |     entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) { | ||||||
|  | |||||||
| @ -16,6 +16,7 @@ const TPL = `\ | |||||||
|         <span class="caret"></span> |         <span class="caret"></span> | ||||||
|     </button> |     </button> | ||||||
|     <div class="note-language-dropdown dropdown-menu dropdown-menu-left tn-dropdown-list"></div> |     <div class="note-language-dropdown dropdown-menu dropdown-menu-left tn-dropdown-list"></div> | ||||||
|  |     <button class="language-help-button icon-action bx bx-help-circle" type="button" data-in-app-help="B0lcI9xz1r8K" title="${t("open-help-page")}"></button> | ||||||
| 
 | 
 | ||||||
|     <style> |     <style> | ||||||
|         .note-language-dropdown [dir=rtl] { |         .note-language-dropdown [dir=rtl] { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Elian Doran
						Elian Doran