11import { Decoration , DecorationSet , EditorView , ViewPlugin , ViewUpdate } from '@codemirror/view' ;
2- import { Range } from '@codemirror/state' ;
2+ import { Range , RangeSet } from '@codemirror/state' ;
33import { syntaxTree , tokenClassNodeProp } from '@codemirror/language' ;
44import { SyntaxNode } from '@lezer/common' ;
55import { Component , editorLivePreviewField , TFile } from 'obsidian' ;
66import MetaBindPlugin from '../main' ;
7- import { MBWidgetType } from './Cm6_Widgets' ;
7+ import { MarkdownRenderChildWidget , MBWidgetType } from './Cm6_Widgets' ;
88import { Cm6_Util } from './Cm6_Util' ;
99
1010export function createMarkdownRenderChildWidgetEditorPlugin ( plugin : MetaBindPlugin ) {
@@ -19,10 +19,9 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
1919 this . decorations = this . renderWidgets ( view ) ?? Decoration . none ;
2020 }
2121
22- update ( update : ViewUpdate ) {
22+ update ( update : ViewUpdate ) : void {
2323 // only activate in LP and not source mode
2424 if ( ! update . state . field ( editorLivePreviewField ) ) {
25- console . log ( 'not LP' ) ;
2625 this . decorations = Decoration . none ;
2726 return ;
2827 }
@@ -40,7 +39,7 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
4039 }
4140 }
4241
43- updateTree ( view : EditorView ) {
42+ updateTree ( view : EditorView ) : void {
4443 for ( const { from, to } of view . visibleRanges ) {
4544 syntaxTree ( view . state ) . iterate ( {
4645 from,
@@ -69,7 +68,7 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
6968 }
7069 }
7170
72- removeDecoration ( node : SyntaxNode ) {
71+ removeDecoration ( node : SyntaxNode ) : void {
7372 this . decorations . between ( node . from - 1 , node . to + 1 , ( from , to , value ) => {
7473 this . decorations = this . decorations . update ( {
7574 filterFrom : from ,
@@ -79,7 +78,7 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
7978 } ) ;
8079 }
8180
82- addDecoration ( node : SyntaxNode , view : EditorView , content : string , widgetType : MBWidgetType ) {
81+ addDecoration ( node : SyntaxNode , view : EditorView , content : string , widgetType : MBWidgetType ) : void {
8382 const from = node . from - 1 ;
8483 const to = node . to + 1 ;
8584
@@ -93,7 +92,7 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
9392 return ;
9493 }
9594
96- const newDecoration = this . renderWidget ( node , widgetType , content , currentFile ) ?. value ;
95+ const newDecoration : Decoration | undefined = this . renderWidget ( node , widgetType , content , currentFile ) ?. value ;
9796 if ( ! newDecoration ) {
9897 return ;
9998 }
@@ -145,10 +144,10 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
145144 } ;
146145 }
147146
148- renderWidgets ( view : EditorView ) {
147+ renderWidgets ( view : EditorView ) : RangeSet < Decoration > | undefined {
149148 const currentFile = Cm6_Util . getCurrentFile ( view ) ;
150149 if ( ! currentFile ) {
151- return ;
150+ return undefined ;
152151 }
153152
154153 const widgets : Range < Decoration > [ ] = [ ] ;
@@ -184,8 +183,8 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
184183 return Decoration . set ( widgets , true ) ;
185184 }
186185
187- renderWidget ( node : SyntaxNode , widgetType : MBWidgetType , content : string , currentFile : TFile ) {
188- const widget = Cm6_Util . constructMarkdownRenderChildWidget ( widgetType , content , currentFile . path , plugin ) ;
186+ renderWidget ( node : SyntaxNode , widgetType : MBWidgetType , content : string , currentFile : TFile ) : Range < Decoration > | undefined {
187+ const widget = Cm6_Util . constructMarkdownRenderChildWidget ( widgetType , content , currentFile . path , this . component , plugin ) ;
189188 if ( ! widget ) {
190189 return ;
191190 }
@@ -195,7 +194,7 @@ export function createMarkdownRenderChildWidgetEditorPlugin(plugin: MetaBindPlug
195194 } ) . range ( node . from - 1 , node . to + 1 ) ;
196195 }
197196
198- destroy ( ) {
197+ destroy ( ) : void {
199198 this . component . unload ( ) ;
200199 }
201200 } ,
0 commit comments