This commit is contained in:
parent
732c0805ca
commit
f2d015267d
6 changed files with 49 additions and 34 deletions
|
@ -259,25 +259,20 @@ export const initWindow = (app: App) => {
|
|||
// siyuan://plugins/plugin-name/foo?bar=baz
|
||||
plugin.eventBus.emit("open-siyuan-url-plugin", {url});
|
||||
// siyuan://plugins/plugin-samplecustom_tab?title=自定义页签&icon=iconFace&data={"text": "This is the custom plugin tab I opened via protocol."}
|
||||
Object.keys(plugin.models).find(key => {
|
||||
if (key === pluginId) {
|
||||
let data = getSearch("data", url);
|
||||
try {
|
||||
data = JSON.parse(data || "{}");
|
||||
} catch (e) {
|
||||
console.log("Error open plugin tab with protocol:", e);
|
||||
}
|
||||
openFile({
|
||||
app,
|
||||
custom: {
|
||||
title: getSearch("title", url),
|
||||
icon: getSearch("icon", url),
|
||||
data,
|
||||
fn: plugin.models[key]
|
||||
},
|
||||
});
|
||||
return true;
|
||||
}
|
||||
let data = getSearch("data", url);
|
||||
try {
|
||||
data = JSON.parse(data || "{}");
|
||||
} catch (e) {
|
||||
console.log("Error open plugin tab with protocol:", e);
|
||||
}
|
||||
openFile({
|
||||
app,
|
||||
custom: {
|
||||
title: getSearch("title", url),
|
||||
icon: getSearch("icon", url),
|
||||
data,
|
||||
id: pluginId
|
||||
},
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ export const bindCardEvent = (options: {
|
|||
id: filterElement.getAttribute("data-id"),
|
||||
title: options.title
|
||||
},
|
||||
fn: newCardModel
|
||||
id: "siyuan-card"
|
||||
},
|
||||
});
|
||||
if (options.dialog) {
|
||||
|
|
|
@ -28,6 +28,7 @@ import {objEquals} from "../util/functions";
|
|||
import {resize} from "../protyle/util/resize";
|
||||
import {Search} from "../search";
|
||||
import {App} from "../index";
|
||||
import {newCardModel} from "../card/newCardTab";
|
||||
|
||||
export const openFileById = async (options: {
|
||||
app: App,
|
||||
|
@ -100,7 +101,7 @@ export const openFile = (options: IOpenFileOptions) => {
|
|||
}
|
||||
} else if (options.custom) {
|
||||
const custom = allModels.custom.find((item) => {
|
||||
if (objEquals(item.data, options.custom.data)) {
|
||||
if (objEquals(item.data, options.custom.data) && (!options.custom.id || options.custom.id === item.type)) {
|
||||
if (!pdfIsLoading(item.parent.parent.element)) {
|
||||
item.parent.parent.switchTab(item.parent.headElement);
|
||||
item.parent.parent.showHeading();
|
||||
|
@ -427,11 +428,32 @@ const newTab = (options: IOpenFileOptions) => {
|
|||
icon: options.custom.icon,
|
||||
title: options.custom.title,
|
||||
callback(tab) {
|
||||
tab.addModel(options.custom.fn({
|
||||
app: options.app,
|
||||
tab,
|
||||
data: options.custom.data
|
||||
}));
|
||||
if (options.custom.id) {
|
||||
if (options.custom.id === "siyuan-card") {
|
||||
tab.addModel(newCardModel({
|
||||
app: options.app,
|
||||
tab,
|
||||
data: options.custom.data
|
||||
}));
|
||||
} else {
|
||||
options.app.plugins.find(p => {
|
||||
if (p.models[options.custom.id]) {
|
||||
tab.addModel(p.models[options.custom.id]({
|
||||
tab,
|
||||
data: options.custom.data
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// plugin 0.8.3 历史兼容
|
||||
console.warn("0.8.3 将移除 custom.fn 参数,请参照 https://github.com/siyuan-note/plugin-sample/blob/91a716358941791b4269241f21db25fd22ae5ff5/src/index.ts 将其修改为 custom.id");
|
||||
tab.addModel(options.custom.fn({
|
||||
tab,
|
||||
data: options.custom.data
|
||||
}));
|
||||
}
|
||||
setPanelFocus(tab.panelElement.parentElement.parentElement);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -412,7 +412,7 @@ export const JSONToLayout = (app: App, isStart: boolean) => {
|
|||
const initData = item.getAttribute("data-initdata");
|
||||
if (initData) {
|
||||
const initDataObj = JSON.parse(initData);
|
||||
if (initDataObj.instance === "Custom") {
|
||||
if (initDataObj.instance === "Custom" && initDataObj.customModelType !== "siyuan-card") {
|
||||
let hasPlugin = false;
|
||||
app.plugins.find(plugin => {
|
||||
if (Object.keys(plugin.models).includes(initDataObj.customModelType)) {
|
||||
|
|
|
@ -8,13 +8,11 @@ import {getBackend, getFrontend} from "../util/functions";
|
|||
import {openFile, openFileById} from "../editor/util";
|
||||
/// #endif
|
||||
import {updateHotkeyTip} from "../protyle/util/compatibility";
|
||||
import {newCardModel} from "../card/newCardTab";
|
||||
import {App} from "../index";
|
||||
import {Constants} from "../constants";
|
||||
import {Model} from "../layout/Model";
|
||||
import {Setting} from "./Setting";
|
||||
import {Menu} from "./Menu";
|
||||
import { Protyle } from "../protyle";
|
||||
import {Protyle} from "../protyle";
|
||||
|
||||
let openTab;
|
||||
/// #if MOBILE
|
||||
|
@ -47,7 +45,7 @@ openTab = (options: {
|
|||
title: string,
|
||||
icon: string,
|
||||
data?: any
|
||||
fn?: () => Model,
|
||||
id: string
|
||||
}
|
||||
position?: "right" | "bottom",
|
||||
keepCursor?: boolean // 是否跳转到新 tab 上
|
||||
|
@ -128,7 +126,7 @@ openTab = (options: {
|
|||
id: options.card.id || "",
|
||||
title: options.card.title,
|
||||
},
|
||||
fn: newCardModel
|
||||
id: "siyuan-card"
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
4
app/src/types/index.d.ts
vendored
4
app/src/types/index.d.ts
vendored
|
@ -437,11 +437,11 @@ interface IOpenFileOptions {
|
|||
title: string,
|
||||
icon: string,
|
||||
data?: any
|
||||
id: string,
|
||||
fn?: (options: {
|
||||
tab: import("../layout/Tab").Tab,
|
||||
data: any,
|
||||
app: import("../index").App
|
||||
}) => import("../layout/Model").Model,
|
||||
}) => import("../layout/Model").Model, // plugin 0.8.3 历史兼容
|
||||
}
|
||||
assetPath?: string, // asset 必填
|
||||
fileName?: string, // file 必填
|
||||
|
|
Loading…
Add table
Reference in a new issue