@@ -2,7 +2,7 @@ import { EditorView, ViewUpdate } from "@codemirror/view"
2
2
import JSONSS from "json-stable-stringify"
3
3
import { around } from "monkey-around"
4
4
import { editorInfoField , requireApiVersion , WorkspaceLeaf } from "obsidian"
5
- import { BBox , Canvas , CanvasData , CanvasEdge , CanvasEdgeData , CanvasElement , CanvasNode , CanvasNodeData , CanvasPopupMenu , CanvasView , NodeInteractionLayer } from "src/@types/Canvas"
5
+ import { BBox , Canvas , CanvasData , CanvasEdge , CanvasEdgeData , CanvasElement , CanvasNode , CanvasNodeData , CanvasPopupMenu , CanvasView , NodeInteractionLayer , Position , SelectionData } from "src/@types/Canvas"
6
6
import PatchHelper from "src/utils/patch-helper"
7
7
import JSONC from "tiny-jsonc"
8
8
import { CanvasEvent } from "../events"
@@ -59,7 +59,7 @@ export default class CanvasPatcher extends Patcher {
59
59
}
60
60
}
61
61
} ) ,
62
- setViewData : PatchHelper . OverrideExisting ( next => function ( json : string , ...args : any ) {
62
+ setViewData : PatchHelper . OverrideExisting ( next => function ( json : string , ...args : any ) : void {
63
63
json = json !== '' ? json : '{}'
64
64
65
65
let result
@@ -83,13 +83,13 @@ export default class CanvasPatcher extends Patcher {
83
83
84
84
// Patch canvas
85
85
PatchHelper . patchPrototype < Canvas > ( this . plugin , canvasView . canvas , {
86
- markViewportChanged : PatchHelper . OverrideExisting ( next => function ( ...args : any ) {
86
+ markViewportChanged : PatchHelper . OverrideExisting ( next => function ( ...args : any ) : void {
87
87
that . triggerWorkspaceEvent ( CanvasEvent . ViewportChanged . Before , this )
88
88
const result = next . call ( this , ...args )
89
89
that . triggerWorkspaceEvent ( CanvasEvent . ViewportChanged . After , this )
90
90
return result
91
91
} ) ,
92
- markMoved : PatchHelper . OverrideExisting ( next => function ( node : CanvasNode ) {
92
+ markMoved : PatchHelper . OverrideExisting ( next => function ( node : CanvasNode ) : void {
93
93
const result = next . call ( this , node )
94
94
95
95
if ( ! this . viewportChanged ) {
@@ -108,124 +108,124 @@ export default class CanvasPatcher extends Patcher {
108
108
109
109
return result
110
110
} ) ,
111
- onDoubleClick : PatchHelper . OverrideExisting ( next => function ( event : MouseEvent ) {
111
+ onDoubleClick : PatchHelper . OverrideExisting ( next => function ( event : MouseEvent ) : void {
112
112
const preventDefault = { value : false }
113
113
that . triggerWorkspaceEvent ( CanvasEvent . DoubleClick , this , event , preventDefault )
114
114
if ( ! preventDefault . value ) next . call ( this , event )
115
115
} ) ,
116
- setDragging : PatchHelper . OverrideExisting ( next => function ( dragging : boolean ) {
116
+ setDragging : PatchHelper . OverrideExisting ( next => function ( dragging : boolean ) : void {
117
117
const result = next . call ( this , dragging )
118
118
that . triggerWorkspaceEvent ( CanvasEvent . DraggingStateChanged , this , dragging )
119
119
return result
120
120
} ) ,
121
- getContainingNodes : PatchHelper . OverrideExisting ( next => function ( bbox : BBox ) {
121
+ getContainingNodes : PatchHelper . OverrideExisting ( next => function ( bbox : BBox ) : CanvasNode [ ] {
122
122
const result = next . call ( this , bbox )
123
123
that . triggerWorkspaceEvent ( CanvasEvent . ContainingNodesRequested , this , bbox , result )
124
124
return result
125
125
} ) ,
126
- updateSelection : PatchHelper . OverrideExisting ( next => function ( update : ( ) => void ) {
126
+ updateSelection : PatchHelper . OverrideExisting ( next => function ( update : ( ) => void ) : void {
127
127
const oldSelection = new Set ( this . selection )
128
128
const result = next . call ( this , update )
129
129
that . triggerWorkspaceEvent ( CanvasEvent . SelectionChanged , this , oldSelection , ( ( update : ( ) => void ) => next . call ( this , update ) ) )
130
130
return result
131
131
} ) ,
132
- createTextNode : PatchHelper . OverrideExisting ( next => function ( ...args : any ) {
132
+ createTextNode : PatchHelper . OverrideExisting ( next => function ( ...args : any ) : CanvasNode {
133
133
const node = next . call ( this , ...args )
134
134
that . triggerWorkspaceEvent ( CanvasEvent . NodeCreated , this , node )
135
135
return node
136
136
} ) ,
137
- createFileNode : PatchHelper . OverrideExisting ( next => function ( ...args : any ) {
137
+ createFileNode : PatchHelper . OverrideExisting ( next => function ( ...args : any ) : CanvasNode {
138
138
const node = next . call ( this , ...args )
139
139
that . triggerWorkspaceEvent ( CanvasEvent . NodeCreated , this , node )
140
140
return node
141
141
} ) ,
142
- createFileNodes : PatchHelper . OverrideExisting ( next => function ( ...args : any ) {
142
+ createFileNodes : PatchHelper . OverrideExisting ( next => function ( ...args : any ) : CanvasNode [ ] {
143
143
const nodes = next . call ( this , ...args )
144
144
nodes . forEach ( ( node : CanvasNode ) => that . triggerWorkspaceEvent ( CanvasEvent . NodeCreated , this , node ) )
145
145
return nodes
146
146
} ) ,
147
- createGroupNode : PatchHelper . OverrideExisting ( next => function ( ...args : any ) {
147
+ createGroupNode : PatchHelper . OverrideExisting ( next => function ( ...args : any ) : CanvasNode {
148
148
const node = next . call ( this , ...args )
149
149
that . triggerWorkspaceEvent ( CanvasEvent . NodeCreated , this , node )
150
150
return node
151
151
} ) ,
152
- createLinkNode : PatchHelper . OverrideExisting ( next => function ( ...args : any ) {
152
+ createLinkNode : PatchHelper . OverrideExisting ( next => function ( ...args : any ) : CanvasNode {
153
153
const node = next . call ( this , ...args )
154
154
that . triggerWorkspaceEvent ( CanvasEvent . NodeCreated , this , node )
155
155
return node
156
156
} ) ,
157
- addNode : PatchHelper . OverrideExisting ( next => function ( node : CanvasNode ) {
157
+ addNode : PatchHelper . OverrideExisting ( next => function ( node : CanvasNode ) : void {
158
158
that . patchNode ( node )
159
159
return next . call ( this , node )
160
160
} ) ,
161
- addEdge : PatchHelper . OverrideExisting ( next => function ( edge : CanvasEdge ) {
161
+ addEdge : PatchHelper . OverrideExisting ( next => function ( edge : CanvasEdge ) : void {
162
162
that . patchEdge ( edge )
163
163
if ( ! this . viewportChanged ) that . triggerWorkspaceEvent ( CanvasEvent . EdgeCreated , this , edge )
164
164
return next . call ( this , edge )
165
165
} ) ,
166
- removeNode : PatchHelper . OverrideExisting ( next => function ( node : CanvasNode ) {
166
+ removeNode : PatchHelper . OverrideExisting ( next => function ( node : CanvasNode ) : void {
167
167
const result = next . call ( this , node )
168
168
if ( ! this . isClearing ) that . triggerWorkspaceEvent ( CanvasEvent . NodeRemoved , this , node )
169
169
return result
170
170
} ) ,
171
- removeEdge : PatchHelper . OverrideExisting ( next => function ( edge : CanvasEdge ) {
171
+ removeEdge : PatchHelper . OverrideExisting ( next => function ( edge : CanvasEdge ) : void {
172
172
const result = next . call ( this , edge )
173
173
if ( ! this . isClearing ) that . triggerWorkspaceEvent ( CanvasEvent . EdgeRemoved , this , edge )
174
174
return result
175
175
} ) ,
176
- handleCopy : PatchHelper . OverrideExisting ( next => function ( ...args : any ) {
176
+ handleCopy : PatchHelper . OverrideExisting ( next => function ( ...args : any ) : void {
177
177
this . isCopying = true
178
178
const result = next . call ( this , ...args )
179
179
this . isCopying = false
180
180
181
181
return result
182
182
} ) ,
183
- getSelectionData : PatchHelper . OverrideExisting ( next => function ( ...args : any ) {
183
+ getSelectionData : PatchHelper . OverrideExisting ( next => function ( ...args : any ) : SelectionData {
184
184
const result = next . call ( this , ...args )
185
185
if ( this . isCopying ) that . triggerWorkspaceEvent ( CanvasEvent . OnCopy , this , result )
186
186
return result
187
187
} ) ,
188
- zoomToBbox : PatchHelper . OverrideExisting ( next => function ( bbox : BBox ) {
188
+ zoomToBbox : PatchHelper . OverrideExisting ( next => function ( bbox : BBox ) : void {
189
189
that . triggerWorkspaceEvent ( CanvasEvent . ZoomToBbox . Before , this , bbox )
190
190
const result = next . call ( this , bbox )
191
191
that . triggerWorkspaceEvent ( CanvasEvent . ZoomToBbox . After , this , bbox )
192
192
return result
193
193
} ) ,
194
- setReadonly : PatchHelper . OverrideExisting ( next => function ( readonly : boolean ) {
194
+ setReadonly : PatchHelper . OverrideExisting ( next => function ( readonly : boolean ) : void {
195
195
const result = next . call ( this , readonly )
196
196
that . triggerWorkspaceEvent ( CanvasEvent . ReadonlyChanged , this , readonly )
197
197
return result
198
198
} ) ,
199
- undo : PatchHelper . OverrideExisting ( next => function ( ...args : any ) {
199
+ undo : PatchHelper . OverrideExisting ( next => function ( ...args : any ) : void {
200
200
const result = next . call ( this , ...args )
201
201
this . importData ( this . getData ( ) , true ) // Force update the canvas data
202
202
that . triggerWorkspaceEvent ( CanvasEvent . Undo , this )
203
203
return result
204
204
} ) ,
205
- redo : PatchHelper . OverrideExisting ( next => function ( ...args : any ) {
205
+ redo : PatchHelper . OverrideExisting ( next => function ( ...args : any ) : void {
206
206
const result = next . call ( this , ...args )
207
207
this . importData ( this . getData ( ) , true ) // Force update the canvas data
208
208
that . triggerWorkspaceEvent ( CanvasEvent . Redo , this )
209
209
return result
210
210
} ) ,
211
- clear : PatchHelper . OverrideExisting ( next => function ( ...args : any ) {
211
+ clear : PatchHelper . OverrideExisting ( next => function ( ...args : any ) : void {
212
212
this . isClearing = true
213
213
const result = next . call ( this , ...args )
214
214
this . isClearing = false
215
215
return result
216
216
} ) ,
217
- /*setData: PatchHelper.OverrideExisting(next => function (...args: any) {
217
+ /*setData: PatchHelper.OverrideExisting(next => function (...args: any): void {
218
218
//
219
219
const result = next.call(this, ...args)
220
220
//
221
221
return result
222
222
}),*/
223
- getData : PatchHelper . OverrideExisting ( next => function ( ...args : any ) {
223
+ getData : PatchHelper . OverrideExisting ( next => function ( ...args : any ) : CanvasData {
224
224
const result = next . call ( this , ...args )
225
225
that . triggerWorkspaceEvent ( CanvasEvent . DataRequested , this , result )
226
226
return result
227
227
} ) ,
228
- importData : PatchHelper . OverrideExisting ( next => function ( data : CanvasData , clearCanvas ?: boolean , silent ?: boolean ) {
228
+ importData : PatchHelper . OverrideExisting ( next => function ( data : CanvasData , clearCanvas ?: boolean , silent ?: boolean ) : void {
229
229
const targetFilePath = this . view . file . path
230
230
const setData = ( data : CanvasData ) => {
231
231
// Skip if the canvas got unloaded or the file changed
@@ -239,7 +239,7 @@ export default class CanvasPatcher extends Patcher {
239
239
240
240
return result
241
241
} ) ,
242
- requestSave : PatchHelper . OverrideExisting ( next => function ( ...args : any ) {
242
+ requestSave : PatchHelper . OverrideExisting ( next => function ( ...args : any ) : void {
243
243
that . triggerWorkspaceEvent ( CanvasEvent . CanvasSaved . Before , this )
244
244
const result = next . call ( this , ...args )
245
245
that . triggerWorkspaceEvent ( CanvasEvent . CanvasSaved . After , this )
@@ -249,7 +249,7 @@ export default class CanvasPatcher extends Patcher {
249
249
250
250
// Patch canvas popup menu
251
251
PatchHelper . patchPrototype < CanvasPopupMenu > ( this . plugin , canvasView . canvas . menu , {
252
- render : PatchHelper . OverrideExisting ( next => function ( ...args : any ) {
252
+ render : PatchHelper . OverrideExisting ( next => function ( ...args : any ) : void {
253
253
const result = next . call ( this , ...args )
254
254
that . triggerWorkspaceEvent ( CanvasEvent . PopupMenuCreated , this . canvas )
255
255
next . call ( this ) // Re-Center the popup menu
@@ -259,7 +259,7 @@ export default class CanvasPatcher extends Patcher {
259
259
260
260
// Patch interaction layer
261
261
PatchHelper . patchPrototype < NodeInteractionLayer > ( this . plugin , canvasView . canvas . nodeInteractionLayer , {
262
- setTarget : PatchHelper . OverrideExisting ( next => function ( node : CanvasNode ) {
262
+ setTarget : PatchHelper . OverrideExisting ( next => function ( node : CanvasNode ) : void {
263
263
const result = next . call ( this , node )
264
264
that . triggerWorkspaceEvent ( CanvasEvent . NodeInteraction , this . canvas , node )
265
265
return result
@@ -291,7 +291,7 @@ export default class CanvasPatcher extends Patcher {
291
291
const that = this
292
292
293
293
PatchHelper . patch < CanvasNode > ( this . plugin , node , {
294
- setData : PatchHelper . OverrideExisting ( next => function ( data : CanvasNodeData , addHistory ?: boolean ) {
294
+ setData : PatchHelper . OverrideExisting ( next => function ( data : CanvasNodeData , addHistory ?: boolean ) : void {
295
295
const result = next . call ( this , data )
296
296
297
297
if ( node . initialized && ! node . isDirty ) {
@@ -309,17 +309,17 @@ export default class CanvasPatcher extends Patcher {
309
309
310
310
return result
311
311
} ) ,
312
- setIsEditing : PatchHelper . OverrideExisting ( next => function ( editing : boolean , ...args : any ) {
312
+ setIsEditing : PatchHelper . OverrideExisting ( next => function ( editing : boolean , ...args : any ) : void {
313
313
const result = next . call ( this , editing , ...args )
314
314
that . triggerWorkspaceEvent ( CanvasEvent . NodeEditingStateChanged , this . canvas , node , editing )
315
315
return result
316
316
} ) ,
317
- updateBreakpoint : PatchHelper . OverrideExisting ( next => function ( breakpoint : boolean ) {
317
+ updateBreakpoint : PatchHelper . OverrideExisting ( next => function ( breakpoint : boolean ) : void {
318
318
const breakpointRef = { value : breakpoint }
319
319
that . triggerWorkspaceEvent ( CanvasEvent . NodeBreakpointChanged , this . canvas , node , breakpointRef )
320
320
return next . call ( this , breakpointRef . value )
321
321
} ) ,
322
- getBBox : PatchHelper . OverrideExisting ( next => function ( ...args : any ) {
322
+ getBBox : PatchHelper . OverrideExisting ( next => function ( ...args : any ) : BBox {
323
323
const result = next . call ( this , ...args )
324
324
that . triggerWorkspaceEvent ( CanvasEvent . NodeBBoxRequested , this . canvas , node , result )
325
325
return result
@@ -336,7 +336,7 @@ export default class CanvasPatcher extends Patcher {
336
336
const that = this
337
337
338
338
PatchHelper . patch < CanvasEdge > ( this . plugin , edge , {
339
- setData : PatchHelper . OverrideExisting ( next => function ( data : CanvasEdgeData , addHistory ?: boolean ) {
339
+ setData : PatchHelper . OverrideExisting ( next => function ( data : CanvasEdgeData , addHistory ?: boolean ) : void {
340
340
const result = next . call ( this , data )
341
341
342
342
if ( edge . initialized && ! edge . isDirty ) {
@@ -354,12 +354,12 @@ export default class CanvasPatcher extends Patcher {
354
354
355
355
return result
356
356
} ) ,
357
- render : PatchHelper . OverrideExisting ( next => function ( ...args : any ) {
357
+ render : PatchHelper . OverrideExisting ( next => function ( ...args : any ) : void {
358
358
const result = next . call ( this , ...args )
359
359
that . triggerWorkspaceEvent ( CanvasEvent . EdgeChanged , this . canvas , edge )
360
360
return result
361
361
} ) ,
362
- getCenter : PatchHelper . OverrideExisting ( next => function ( ...args : any ) {
362
+ getCenter : PatchHelper . OverrideExisting ( next => function ( ...args : any ) : Position {
363
363
const result = next . call ( this , ...args )
364
364
that . triggerWorkspaceEvent ( CanvasEvent . EdgeCenterRequested , this . canvas , edge , result )
365
365
return result
@@ -382,7 +382,7 @@ export default class CanvasPatcher extends Patcher {
382
382
383
383
// Patch CanvasElement object
384
384
const uninstall = around ( canvasElement , {
385
- initialize : next => function ( ...args : any ) {
385
+ initialize : next => function ( ...args : any ) : void {
386
386
const result = next . call ( this , ...args )
387
387
388
388
onReady ( )
@@ -395,7 +395,7 @@ export default class CanvasPatcher extends Patcher {
395
395
that . plugin . register ( uninstall )
396
396
}
397
397
398
- private triggerWorkspaceEvent ( event : string , ...args : any ) {
398
+ private triggerWorkspaceEvent ( event : string , ...args : any ) : void {
399
399
this . plugin . app . workspace . trigger ( event , ...args )
400
400
}
401
401
}
0 commit comments