mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 21:19:01 +01:00 
			
		
		
		
	feat(slash): include note
This commit is contained in:
		
							parent
							
								
									c09a9aa7d3
								
							
						
					
					
						commit
						6069518749
					
				@ -2,11 +2,13 @@ import type { Editor } from 'ckeditor5';
 | 
				
			|||||||
import type { SlashCommandEditorConfig  } from 'ckeditor5-premium-features';
 | 
					import type { SlashCommandEditorConfig  } from 'ckeditor5-premium-features';
 | 
				
			||||||
import { icons as admonitionIcons } from '@triliumnext/ckeditor5-admonition';
 | 
					import { icons as admonitionIcons } from '@triliumnext/ckeditor5-admonition';
 | 
				
			||||||
import { icons as footnoteIcons } from '@triliumnext/ckeditor5-footnotes';
 | 
					import { icons as footnoteIcons } from '@triliumnext/ckeditor5-footnotes';
 | 
				
			||||||
import { COMMAND_NAME as INSERT_DATE_TIME_COMMAND } from './plugins/insert_date_time';
 | 
					import { COMMAND_NAME as INSERT_DATE_TIME_COMMAND } from './plugins/insert_date_time.js';
 | 
				
			||||||
import { COMMAND_NAME as INTERNAL_LINK_COMMAND } from './plugins/internallink';
 | 
					import { COMMAND_NAME as INTERNAL_LINK_COMMAND } from './plugins/internallink.js';
 | 
				
			||||||
 | 
					import { COMMAND_NAME as INCLUDE_NOTE_COMMAND } from './plugins/includenote.js';
 | 
				
			||||||
import { ADMONITION_TYPES, type AdmonitionType } from '@triliumnext/ckeditor5-admonition';
 | 
					import { ADMONITION_TYPES, type AdmonitionType } from '@triliumnext/ckeditor5-admonition';
 | 
				
			||||||
import dateTimeIcon from './icons/date-time.svg?raw';
 | 
					import dateTimeIcon from './icons/date-time.svg?raw';
 | 
				
			||||||
import internalLinkIcon from './icons/trilium.svg?raw';
 | 
					import internalLinkIcon from './icons/trilium.svg?raw';
 | 
				
			||||||
 | 
					import noteIcon from './icons/note.svg?raw';
 | 
				
			||||||
import { icons as mathIcons, MathUI } from '@triliumnext/ckeditor5-math';
 | 
					import { icons as mathIcons, MathUI } from '@triliumnext/ckeditor5-math';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type SlashCommandDefinition = SlashCommandEditorConfig["extraCommands"][number];
 | 
					type SlashCommandDefinition = SlashCommandEditorConfig["extraCommands"][number];
 | 
				
			||||||
@ -41,6 +43,13 @@ export default function buildExtraCommands(): SlashCommandDefinition[] {
 | 
				
			|||||||
            description: "Insert a math equation",
 | 
					            description: "Insert a math equation",
 | 
				
			||||||
            icon: mathIcons.ckeditor,
 | 
					            icon: mathIcons.ckeditor,
 | 
				
			||||||
            execute: (editor: Editor) => editor.plugins.get(MathUI)._showUI()
 | 
					            execute: (editor: Editor) => editor.plugins.get(MathUI)._showUI()
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            id: "include-note",
 | 
				
			||||||
 | 
					            title: "Include note",
 | 
				
			||||||
 | 
					            description: "Display the content of another note in this note",
 | 
				
			||||||
 | 
					            icon: noteIcon,
 | 
				
			||||||
 | 
					            commandName: INCLUDE_NOTE_COMMAND
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    ];
 | 
					    ];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,8 @@
 | 
				
			|||||||
import { ButtonView, Command, Plugin, toWidget, Widget, type Editor, type Observable } from 'ckeditor5';
 | 
					import { ButtonView, Command, Plugin, toWidget, Widget, type Editor, type Observable } from 'ckeditor5';
 | 
				
			||||||
import noteIcon from '../icons/note.svg?raw';
 | 
					import noteIcon from '../icons/note.svg?raw';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const COMMAND_NAME = 'insertIncludeNote';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default class IncludeNote extends Plugin {
 | 
					export default class IncludeNote extends Plugin {
 | 
				
			||||||
	static get requires() {
 | 
						static get requires() {
 | 
				
			||||||
		return [ IncludeNoteEditing, IncludeNoteUI ];
 | 
							return [ IncludeNoteEditing, IncludeNoteUI ];
 | 
				
			||||||
@ -16,7 +18,7 @@ class IncludeNoteUI extends Plugin {
 | 
				
			|||||||
		// to be displayed in the toolbar.
 | 
							// to be displayed in the toolbar.
 | 
				
			||||||
		editor.ui.componentFactory.add( 'includeNote', locale => {
 | 
							editor.ui.componentFactory.add( 'includeNote', locale => {
 | 
				
			||||||
			// The state of the button will be bound to the widget command.
 | 
								// The state of the button will be bound to the widget command.
 | 
				
			||||||
			const command = editor.commands.get( 'insertIncludeNote' );
 | 
								const command = editor.commands.get( COMMAND_NAME );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// The button will be an instance of ButtonView.
 | 
								// The button will be an instance of ButtonView.
 | 
				
			||||||
			const buttonView = new ButtonView( locale );
 | 
								const buttonView = new ButtonView( locale );
 | 
				
			||||||
@ -35,7 +37,7 @@ class IncludeNoteUI extends Plugin {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// Execute the command when the button is clicked (executed).
 | 
								// Execute the command when the button is clicked (executed).
 | 
				
			||||||
			this.listenTo( buttonView, 'execute', () => editor.execute( 'insertIncludeNote' ) );
 | 
								this.listenTo( buttonView, 'execute', () => editor.execute( COMMAND_NAME ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			return buttonView;
 | 
								return buttonView;
 | 
				
			||||||
		} );
 | 
							} );
 | 
				
			||||||
@ -51,7 +53,7 @@ class IncludeNoteEditing extends Plugin {
 | 
				
			|||||||
		this._defineSchema();
 | 
							this._defineSchema();
 | 
				
			||||||
		this._defineConverters();
 | 
							this._defineConverters();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		this.editor.commands.add( 'insertIncludeNote', new InsertIncludeNoteCommand( this.editor ) );
 | 
							this.editor.commands.add( COMMAND_NAME, new InsertIncludeNoteCommand( this.editor ) );
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_defineSchema() {
 | 
						_defineSchema() {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user