mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	feat(in-app-help): enable table of contents
This commit is contained in:
		
							parent
							
								
									aca0588b26
								
							
						
					
					
						commit
						e41a02893f
					
				@ -61,8 +61,8 @@ export interface NoteCommandData extends CommandData {
 | 
				
			|||||||
    viewScope?: ViewScope;
 | 
					    viewScope?: ViewScope;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface ExecuteCommandData extends CommandData {
 | 
					export interface ExecuteCommandData<T> extends CommandData {
 | 
				
			||||||
    resolve: unknown;
 | 
					    resolve: (data: T) => void
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@ -151,12 +151,12 @@ export type CommandMappings = {
 | 
				
			|||||||
        callback: (value: NoteDetailWidget | PromiseLike<NoteDetailWidget>) => void;
 | 
					        callback: (value: NoteDetailWidget | PromiseLike<NoteDetailWidget>) => void;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    executeWithTextEditor: CommandData &
 | 
					    executeWithTextEditor: CommandData &
 | 
				
			||||||
        ExecuteCommandData & {
 | 
					        ExecuteCommandData<TextEditor> & {
 | 
				
			||||||
            callback?: GetTextEditorCallback;
 | 
					            callback?: GetTextEditorCallback;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
    executeWithCodeEditor: CommandData & ExecuteCommandData;
 | 
					    executeWithCodeEditor: CommandData & ExecuteCommandData<null>;
 | 
				
			||||||
    executeWithContentElement: CommandData & ExecuteCommandData;
 | 
					    executeWithContentElement: CommandData & ExecuteCommandData<JQuery<HTMLElement>>;
 | 
				
			||||||
    executeWithTypeWidget: CommandData & ExecuteCommandData;
 | 
					    executeWithTypeWidget: CommandData & ExecuteCommandData<null>;
 | 
				
			||||||
    addTextToActiveEditor: CommandData & {
 | 
					    addTextToActiveEditor: CommandData & {
 | 
				
			||||||
        text: string;
 | 
					        text: string;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
				
			|||||||
@ -75,7 +75,15 @@ export default class TocWidget extends RightPanelWidget {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    isEnabled() {
 | 
					    isEnabled() {
 | 
				
			||||||
        return super.isEnabled() && this.note.type === "text" && !this.noteContext.viewScope.tocTemporarilyHidden && this.noteContext.viewScope.viewMode === "default";
 | 
					        if (!super.isEnabled()) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const isHelpNote = (this.note.type === "doc" && this.note.noteId.startsWith("_help"));
 | 
				
			||||||
 | 
					        const isTextNote = (this.note.type === "text");
 | 
				
			||||||
 | 
					        const isNoteSupported = isTextNote || isHelpNote;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return isNoteSupported && !this.noteContext.viewScope.tocTemporarilyHidden && this.noteContext.viewScope.viewMode === "default";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async doRenderBody() {
 | 
					    async doRenderBody() {
 | 
				
			||||||
@ -104,6 +112,14 @@ export default class TocWidget extends RightPanelWidget {
 | 
				
			|||||||
        if (this.note.type === "text") {
 | 
					        if (this.note.type === "text") {
 | 
				
			||||||
            const { content } = await note.getBlob();
 | 
					            const { content } = await note.getBlob();
 | 
				
			||||||
            ({ $toc, headingCount } = await this.getToc(content));
 | 
					            ({ $toc, headingCount } = await this.getToc(content));
 | 
				
			||||||
 | 
					        } else if (this.note.type === "doc") {
 | 
				
			||||||
 | 
					            const $contentEl = await this.noteContext.getContentElement();
 | 
				
			||||||
 | 
					            if ($contentEl) {
 | 
				
			||||||
 | 
					                const content = $contentEl.html();
 | 
				
			||||||
 | 
					                ({ $toc, headingCount } = await this.getToc(content));
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                console.warn("Unable to get content element for doctype");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.$toc.html($toc);
 | 
					        this.$toc.html($toc);
 | 
				
			||||||
 | 
				
			|||||||
@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					import type { EventData } from "../../components/app_context.js";
 | 
				
			||||||
import type FNote from "../../entities/fnote.js";
 | 
					import type FNote from "../../entities/fnote.js";
 | 
				
			||||||
import { applySyntaxHighlight } from "../../services/syntax_highlight.js";
 | 
					import { applySyntaxHighlight } from "../../services/syntax_highlight.js";
 | 
				
			||||||
import TypeWidget from "./type_widget.js";
 | 
					import TypeWidget from "./type_widget.js";
 | 
				
			||||||
@ -71,4 +72,14 @@ export default class DocTypeWidget extends TypeWidget {
 | 
				
			|||||||
        applySyntaxHighlight(this.$content);
 | 
					        applySyntaxHighlight(this.$content);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    async executeWithContentElementEvent({ resolve, ntxId }: EventData<"executeWithContentElement">) {
 | 
				
			||||||
 | 
					        if (!this.isNoteContext(ntxId)) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        await this.initialized;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        resolve(this.$content);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user