mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 21:11:30 +08:00 
			
		
		
		
	chore(ckeditor5/plugins): integrate includenote
This commit is contained in:
		
							parent
							
								
									9d11f0e9c3
								
							
						
					
					
						commit
						96fbf610d6
					
				| @ -8,6 +8,7 @@ declare global { | |||||||
|     interface EditorComponent extends Component { |     interface EditorComponent extends Component { | ||||||
|         loadReferenceLinkTitle($el: JQuery<HTMLElement>, href: string): Promise<void>; |         loadReferenceLinkTitle($el: JQuery<HTMLElement>, href: string): Promise<void>; | ||||||
|         createNoteForReferenceLink(title: string): Promise<string>; |         createNoteForReferenceLink(title: string): Promise<string>; | ||||||
|  |         loadIncludedNote(noteId: string, $el: JQuery<HTMLElement>): void; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     var glob: { |     var glob: { | ||||||
|  | |||||||
| Before Width: | Height: | Size: 449 B After Width: | Height: | Size: 449 B | 
| @ -11,6 +11,7 @@ import SpecialCharactersEmojiPlugin from "./plugins/special_characters_emoji.js" | |||||||
| import IndentBlockShortcutPlugin from "./plugins/indent_block_shortcut.js"; | import IndentBlockShortcutPlugin from "./plugins/indent_block_shortcut.js"; | ||||||
| import MarkdownImportPlugin from "./plugins/markdownimport.js"; | import MarkdownImportPlugin from "./plugins/markdownimport.js"; | ||||||
| import MentionCustomization from "./plugins/mention_customization.js"; | import MentionCustomization from "./plugins/mention_customization.js"; | ||||||
|  | import IncludeNote from "./plugins/includenote.js"; | ||||||
| 
 | 
 | ||||||
| const TRILIUM_PLUGINS: typeof Plugin[] = [ | const TRILIUM_PLUGINS: typeof Plugin[] = [ | ||||||
|     CutToNotePlugin, |     CutToNotePlugin, | ||||||
| @ -23,7 +24,8 @@ const TRILIUM_PLUGINS: typeof Plugin[] = [ | |||||||
|     SpecialCharactersEmojiPlugin, |     SpecialCharactersEmojiPlugin, | ||||||
|     IndentBlockShortcutPlugin, |     IndentBlockShortcutPlugin, | ||||||
|     MarkdownImportPlugin, |     MarkdownImportPlugin, | ||||||
|     MentionCustomization |     MentionCustomization, | ||||||
|  |     IncludeNote | ||||||
| ]; | ]; | ||||||
| 
 | 
 | ||||||
| export const COMMON_PLUGINS: typeof Plugin[] = [ | export const COMMON_PLUGINS: typeof Plugin[] = [ | ||||||
|  | |||||||
| @ -1,9 +1,5 @@ | |||||||
| import Plugin from '@ckeditor/ckeditor5-core/src/plugin'; | import { ButtonView, Command, Plugin, toWidget, Widget, type Editor, type Observable } from 'ckeditor5'; | ||||||
| import {toWidget} from '@ckeditor/ckeditor5-widget/src/utils'; | import noteIcon from '../icons/note.svg?raw'; | ||||||
| import Widget from '@ckeditor/ckeditor5-widget/src/widget'; |  | ||||||
| import Command from '@ckeditor/ckeditor5-core/src/command'; |  | ||||||
| import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; |  | ||||||
| import noteIcon from './icons/note.svg'; |  | ||||||
| 
 | 
 | ||||||
| export default class IncludeNote extends Plugin { | export default class IncludeNote extends Plugin { | ||||||
| 	static get requires() { | 	static get requires() { | ||||||
| @ -34,7 +30,9 @@ class IncludeNoteUI extends Plugin { | |||||||
| 			} ); | 			} ); | ||||||
| 
 | 
 | ||||||
| 			// Bind the state of the button to the command.
 | 			// Bind the state of the button to the command.
 | ||||||
| 			buttonView.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' ); |             if (command) { | ||||||
|  |                 buttonView.bind( 'isOn', 'isEnabled' ).to( command as Observable & { value: boolean; } & { isEnabled: boolean; }, 'value', 'isEnabled' ); | ||||||
|  |             } | ||||||
| 
 | 
 | ||||||
| 			// 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( 'insertIncludeNote' ) ); | ||||||
| @ -103,7 +101,7 @@ class IncludeNoteEditing extends Plugin { | |||||||
| 			model: 'includeNote', | 			model: 'includeNote', | ||||||
| 			view: ( modelElement, { writer: viewWriter } ) => { | 			view: ( modelElement, { writer: viewWriter } ) => { | ||||||
| 
 | 
 | ||||||
| 				const noteId = modelElement.getAttribute( 'noteId' ); | 				const noteId = modelElement.getAttribute( 'noteId' ) as string; | ||||||
| 				const boxSize = modelElement.getAttribute( 'boxSize' ); | 				const boxSize = modelElement.getAttribute( 'boxSize' ); | ||||||
| 
 | 
 | ||||||
| 				const section = viewWriter.createContainerElement( 'section', { | 				const section = viewWriter.createContainerElement( 'section', { | ||||||
| @ -119,7 +117,7 @@ class IncludeNoteEditing extends Plugin { | |||||||
| 					const domElement = this.toDomElement( domDocument ); | 					const domElement = this.toDomElement( domDocument ); | ||||||
| 
 | 
 | ||||||
| 					const editorEl = editor.editing.view.getDomRoot(); | 					const editorEl = editor.editing.view.getDomRoot(); | ||||||
| 					const component = glob.getComponentByEl( editorEl ); | 					const component = glob.getComponentByEl<EditorComponent>( editorEl ); | ||||||
| 
 | 
 | ||||||
| 					component.loadIncludedNote( noteId, $( domElement ) ); | 					component.loadIncludedNote( noteId, $( domElement ) ); | ||||||
| 
 | 
 | ||||||
| @ -147,7 +145,8 @@ class InsertIncludeNoteCommand extends Command { | |||||||
| 	refresh() { | 	refresh() { | ||||||
| 		const model = this.editor.model; | 		const model = this.editor.model; | ||||||
| 		const selection = model.document.selection; | 		const selection = model.document.selection; | ||||||
| 		const allowedIn = model.schema.findAllowedParent( selection.getFirstPosition(), 'includeNote' ); |         const firstPosition = selection.getFirstPosition(); | ||||||
|  | 		const allowedIn = firstPosition && model.schema.findAllowedParent( firstPosition, 'includeNote' ); | ||||||
| 
 | 
 | ||||||
| 		this.isEnabled = allowedIn !== null; | 		this.isEnabled = allowedIn !== null; | ||||||
| 	} | 	} | ||||||
| @ -157,7 +156,7 @@ class InsertIncludeNoteCommand extends Command { | |||||||
|  * Hack coming from https://github.com/ckeditor/ckeditor5/issues/4465
 |  * Hack coming from https://github.com/ckeditor/ckeditor5/issues/4465
 | ||||||
|  * Source issue: https://github.com/zadam/trilium/issues/1117
 |  * Source issue: https://github.com/zadam/trilium/issues/1117
 | ||||||
|  */ |  */ | ||||||
| function preventCKEditorHandling( domElement, editor ) { | function preventCKEditorHandling( domElement: HTMLElement, editor: Editor ) { | ||||||
| 	// Prevent the editor from listening on below events in order to stop rendering selection.
 | 	// Prevent the editor from listening on below events in order to stop rendering selection.
 | ||||||
| 
 | 
 | ||||||
| 	// commenting out click events to allow link click handler to still work
 | 	// commenting out click events to allow link click handler to still work
 | ||||||
| @ -168,9 +167,10 @@ function preventCKEditorHandling( domElement, editor ) { | |||||||
| 	// Prevents TAB handling or other editor keys listeners which might be executed on editors selection.
 | 	// Prevents TAB handling or other editor keys listeners which might be executed on editors selection.
 | ||||||
| 	domElement.addEventListener( 'keydown', stopEventPropagationAndHackRendererFocus, { capture: true } ); | 	domElement.addEventListener( 'keydown', stopEventPropagationAndHackRendererFocus, { capture: true } ); | ||||||
| 
 | 
 | ||||||
| 	function stopEventPropagationAndHackRendererFocus( evt ) { | 	function stopEventPropagationAndHackRendererFocus( evt: Event ) { | ||||||
| 		evt.stopPropagation(); | 		evt.stopPropagation(); | ||||||
| 		// This prevents rendering changed view selection thus preventing to changing DOM selection while inside a widget.
 | 		// This prevents rendering changed view selection thus preventing to changing DOM selection while inside a widget.
 | ||||||
|  |         //@ts-expect-error: We are accessing a private field.
 | ||||||
| 		editor.editing.view._renderer.isFocused = false; | 		editor.editing.view._renderer.isFocused = false; | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Elian Doran
						Elian Doran