@@ -28,6 +28,7 @@ import {objEquals} from "../util/functions";
28
28
import { resize } from "../protyle/util/resize" ;
29
29
import { Search } from "../search" ;
30
30
import { App } from "../index" ;
31
+ import { newCardModel } from "../card/newCardTab" ;
31
32
32
33
export const openFileById = async ( options : {
33
34
app : App ,
@@ -100,7 +101,7 @@ export const openFile = (options: IOpenFileOptions) => {
100
101
}
101
102
} else if ( options . custom ) {
102
103
const custom = allModels . custom . find ( ( item ) => {
103
- if ( objEquals ( item . data , options . custom . data ) ) {
104
+ if ( objEquals ( item . data , options . custom . data ) && ( ! options . custom . id || options . custom . id === item . type ) ) {
104
105
if ( ! pdfIsLoading ( item . parent . parent . element ) ) {
105
106
item . parent . parent . switchTab ( item . parent . headElement ) ;
106
107
item . parent . parent . showHeading ( ) ;
@@ -427,11 +428,32 @@ const newTab = (options: IOpenFileOptions) => {
427
428
icon : options . custom . icon ,
428
429
title : options . custom . title ,
429
430
callback ( tab ) {
430
- tab . addModel ( options . custom . fn ( {
431
- app : options . app ,
432
- tab,
433
- data : options . custom . data
434
- } ) ) ;
431
+ if ( options . custom . id ) {
432
+ if ( options . custom . id === "siyuan-card" ) {
433
+ tab . addModel ( newCardModel ( {
434
+ app : options . app ,
435
+ tab,
436
+ data : options . custom . data
437
+ } ) ) ;
438
+ } else {
439
+ options . app . plugins . find ( p => {
440
+ if ( p . models [ options . custom . id ] ) {
441
+ tab . addModel ( p . models [ options . custom . id ] ( {
442
+ tab,
443
+ data : options . custom . data
444
+ } ) ) ;
445
+ return true ;
446
+ }
447
+ } )
448
+ }
449
+ } else {
450
+ // plugin 0.8.3 历史兼容
451
+ console . warn ( "0.8.3 将移除 custom.fn 参数,请参照 https://github.com/siyuan-note/plugin-sample/blob/91a716358941791b4269241f21db25fd22ae5ff5/src/index.ts 将其修改为 custom.id" ) ;
452
+ tab . addModel ( options . custom . fn ( {
453
+ tab,
454
+ data : options . custom . data
455
+ } ) ) ;
456
+ }
435
457
setPanelFocus ( tab . panelElement . parentElement . parentElement ) ;
436
458
}
437
459
} ) ;
0 commit comments