mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 08:00:13 +01:00
This commit is contained in:
parent
732c0805ca
commit
f2d015267d
6 changed files with 49 additions and 34 deletions
|
|
@ -259,8 +259,6 @@ export const initWindow = (app: App) => {
|
||||||
// siyuan://plugins/plugin-name/foo?bar=baz
|
// siyuan://plugins/plugin-name/foo?bar=baz
|
||||||
plugin.eventBus.emit("open-siyuan-url-plugin", {url});
|
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."}
|
// 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);
|
let data = getSearch("data", url);
|
||||||
try {
|
try {
|
||||||
data = JSON.parse(data || "{}");
|
data = JSON.parse(data || "{}");
|
||||||
|
|
@ -273,15 +271,12 @@ export const initWindow = (app: App) => {
|
||||||
title: getSearch("title", url),
|
title: getSearch("title", url),
|
||||||
icon: getSearch("icon", url),
|
icon: getSearch("icon", url),
|
||||||
data,
|
data,
|
||||||
fn: plugin.models[key]
|
id: pluginId
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isSYProtocol(url)) {
|
if (isSYProtocol(url)) {
|
||||||
|
|
|
||||||
|
|
@ -221,7 +221,7 @@ export const bindCardEvent = (options: {
|
||||||
id: filterElement.getAttribute("data-id"),
|
id: filterElement.getAttribute("data-id"),
|
||||||
title: options.title
|
title: options.title
|
||||||
},
|
},
|
||||||
fn: newCardModel
|
id: "siyuan-card"
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (options.dialog) {
|
if (options.dialog) {
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import {objEquals} from "../util/functions";
|
||||||
import {resize} from "../protyle/util/resize";
|
import {resize} from "../protyle/util/resize";
|
||||||
import {Search} from "../search";
|
import {Search} from "../search";
|
||||||
import {App} from "../index";
|
import {App} from "../index";
|
||||||
|
import {newCardModel} from "../card/newCardTab";
|
||||||
|
|
||||||
export const openFileById = async (options: {
|
export const openFileById = async (options: {
|
||||||
app: App,
|
app: App,
|
||||||
|
|
@ -100,7 +101,7 @@ export const openFile = (options: IOpenFileOptions) => {
|
||||||
}
|
}
|
||||||
} else if (options.custom) {
|
} else if (options.custom) {
|
||||||
const custom = allModels.custom.find((item) => {
|
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)) {
|
if (!pdfIsLoading(item.parent.parent.element)) {
|
||||||
item.parent.parent.switchTab(item.parent.headElement);
|
item.parent.parent.switchTab(item.parent.headElement);
|
||||||
item.parent.parent.showHeading();
|
item.parent.parent.showHeading();
|
||||||
|
|
@ -427,11 +428,32 @@ const newTab = (options: IOpenFileOptions) => {
|
||||||
icon: options.custom.icon,
|
icon: options.custom.icon,
|
||||||
title: options.custom.title,
|
title: options.custom.title,
|
||||||
callback(tab) {
|
callback(tab) {
|
||||||
tab.addModel(options.custom.fn({
|
if (options.custom.id) {
|
||||||
|
if (options.custom.id === "siyuan-card") {
|
||||||
|
tab.addModel(newCardModel({
|
||||||
app: options.app,
|
app: options.app,
|
||||||
tab,
|
tab,
|
||||||
data: options.custom.data
|
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);
|
setPanelFocus(tab.panelElement.parentElement.parentElement);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -412,7 +412,7 @@ export const JSONToLayout = (app: App, isStart: boolean) => {
|
||||||
const initData = item.getAttribute("data-initdata");
|
const initData = item.getAttribute("data-initdata");
|
||||||
if (initData) {
|
if (initData) {
|
||||||
const initDataObj = JSON.parse(initData);
|
const initDataObj = JSON.parse(initData);
|
||||||
if (initDataObj.instance === "Custom") {
|
if (initDataObj.instance === "Custom" && initDataObj.customModelType !== "siyuan-card") {
|
||||||
let hasPlugin = false;
|
let hasPlugin = false;
|
||||||
app.plugins.find(plugin => {
|
app.plugins.find(plugin => {
|
||||||
if (Object.keys(plugin.models).includes(initDataObj.customModelType)) {
|
if (Object.keys(plugin.models).includes(initDataObj.customModelType)) {
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,11 @@ import {getBackend, getFrontend} from "../util/functions";
|
||||||
import {openFile, openFileById} from "../editor/util";
|
import {openFile, openFileById} from "../editor/util";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {updateHotkeyTip} from "../protyle/util/compatibility";
|
import {updateHotkeyTip} from "../protyle/util/compatibility";
|
||||||
import {newCardModel} from "../card/newCardTab";
|
|
||||||
import {App} from "../index";
|
import {App} from "../index";
|
||||||
import {Constants} from "../constants";
|
import {Constants} from "../constants";
|
||||||
import {Model} from "../layout/Model";
|
|
||||||
import {Setting} from "./Setting";
|
import {Setting} from "./Setting";
|
||||||
import {Menu} from "./Menu";
|
import {Menu} from "./Menu";
|
||||||
import { Protyle } from "../protyle";
|
import {Protyle} from "../protyle";
|
||||||
|
|
||||||
let openTab;
|
let openTab;
|
||||||
/// #if MOBILE
|
/// #if MOBILE
|
||||||
|
|
@ -47,7 +45,7 @@ openTab = (options: {
|
||||||
title: string,
|
title: string,
|
||||||
icon: string,
|
icon: string,
|
||||||
data?: any
|
data?: any
|
||||||
fn?: () => Model,
|
id: string
|
||||||
}
|
}
|
||||||
position?: "right" | "bottom",
|
position?: "right" | "bottom",
|
||||||
keepCursor?: boolean // 是否跳转到新 tab 上
|
keepCursor?: boolean // 是否跳转到新 tab 上
|
||||||
|
|
@ -128,7 +126,7 @@ openTab = (options: {
|
||||||
id: options.card.id || "",
|
id: options.card.id || "",
|
||||||
title: options.card.title,
|
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,
|
title: string,
|
||||||
icon: string,
|
icon: string,
|
||||||
data?: any
|
data?: any
|
||||||
|
id: string,
|
||||||
fn?: (options: {
|
fn?: (options: {
|
||||||
tab: import("../layout/Tab").Tab,
|
tab: import("../layout/Tab").Tab,
|
||||||
data: any,
|
data: any,
|
||||||
app: import("../index").App
|
}) => import("../layout/Model").Model, // plugin 0.8.3 历史兼容
|
||||||
}) => import("../layout/Model").Model,
|
|
||||||
}
|
}
|
||||||
assetPath?: string, // asset 必填
|
assetPath?: string, // asset 必填
|
||||||
fileName?: string, // file 必填
|
fileName?: string, // file 必填
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue