mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 09:30:14 +01:00
🚨
This commit is contained in:
parent
1744d6b5cd
commit
580fb4007e
6 changed files with 37 additions and 33 deletions
|
|
@ -478,7 +478,7 @@ export const globalShortcut = (app: App) => {
|
||||||
rootId = ` data-node-id="${item.model.editor.protyle.block.rootID}"`;
|
rootId = ` data-node-id="${item.model.editor.protyle.block.rootID}"`;
|
||||||
icon = unicode2Emoji(item.docIcon || Constants.SIYUAN_IMAGE_FILE, false, "b3-list-item__graphic", true);
|
icon = unicode2Emoji(item.docIcon || Constants.SIYUAN_IMAGE_FILE, false, "b3-list-item__graphic", true);
|
||||||
} else if (initData) {
|
} else if (initData) {
|
||||||
const initDataObj = JSON.parse(initData)
|
const initDataObj = JSON.parse(initData);
|
||||||
if (initDataObj.instance === "Editor") {
|
if (initDataObj.instance === "Editor") {
|
||||||
rootId = ` data-node-id="${initDataObj.rootId}"`;
|
rootId = ` data-node-id="${initDataObj.rootId}"`;
|
||||||
icon = unicode2Emoji(item.docIcon || Constants.SIYUAN_IMAGE_FILE, false, "b3-list-item__graphic", true);
|
icon = unicode2Emoji(item.docIcon || Constants.SIYUAN_IMAGE_FILE, false, "b3-list-item__graphic", true);
|
||||||
|
|
|
||||||
|
|
@ -434,7 +434,7 @@ export class Wnd {
|
||||||
if (currentTab && currentTab.headElement) {
|
if (currentTab && currentTab.headElement) {
|
||||||
const initData = currentTab.headElement.getAttribute("data-initdata");
|
const initData = currentTab.headElement.getAttribute("data-initdata");
|
||||||
if (initData) {
|
if (initData) {
|
||||||
currentTab.addModel(newModelByInitData(this.app, currentTab, JSON.parse(initData)))
|
currentTab.addModel(newModelByInitData(this.app, currentTab, JSON.parse(initData)));
|
||||||
currentTab.headElement.removeAttribute("data-initdata");
|
currentTab.headElement.removeAttribute("data-initdata");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,23 +65,23 @@ export class Dock {
|
||||||
this.position = options.position;
|
this.position = options.position;
|
||||||
this.pin = options.data.pin;
|
this.pin = options.data.pin;
|
||||||
this.data = {};
|
this.data = {};
|
||||||
let showDock = false
|
let showDock = false;
|
||||||
if (options.data.data.length !== 0) {
|
if (options.data.data.length !== 0) {
|
||||||
if (!showDock) {
|
if (!showDock) {
|
||||||
options.data.data[0].find(item => {
|
options.data.data[0].find(item => {
|
||||||
if (TYPES.includes(item.type)) {
|
if (TYPES.includes(item.type)) {
|
||||||
showDock = true
|
showDock = true;
|
||||||
return true
|
return true;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
if (!showDock && options.data.data[1]) {
|
if (!showDock && options.data.data[1]) {
|
||||||
options.data.data[1].find(item => {
|
options.data.data[1].find(item => {
|
||||||
if (TYPES.includes(item.type)) {
|
if (TYPES.includes(item.type)) {
|
||||||
showDock = true
|
showDock = true;
|
||||||
return true
|
return true;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!showDock) {
|
if (!showDock) {
|
||||||
|
|
|
||||||
|
|
@ -408,20 +408,20 @@ export const JSONToLayout = (app: App, isStart: boolean) => {
|
||||||
});
|
});
|
||||||
// 移除没有插件的 tab
|
// 移除没有插件的 tab
|
||||||
document.querySelectorAll('li[data-type="tab-header"]').forEach((item: HTMLElement) => {
|
document.querySelectorAll('li[data-type="tab-header"]').forEach((item: HTMLElement) => {
|
||||||
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") {
|
||||||
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)) {
|
||||||
hasPlugin = true
|
hasPlugin = true;
|
||||||
return true
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!hasPlugin) {
|
if (!hasPlugin) {
|
||||||
const tabId = item.getAttribute("data-id")
|
const tabId = item.getAttribute("data-id");
|
||||||
const tab = getInstanceById(tabId) as Tab
|
const tab = getInstanceById(tabId) as Tab;
|
||||||
if (tab) {
|
if (tab) {
|
||||||
tab.parent.removeTab(tabId, false, false, false);
|
tab.parent.removeTab(tabId, false, false, false);
|
||||||
}
|
}
|
||||||
|
|
@ -440,7 +440,7 @@ export const JSONToLayout = (app: App, isStart: boolean) => {
|
||||||
} else {
|
} else {
|
||||||
document.querySelectorAll('li[data-type="tab-header"][data-init-active="true"]').forEach((item: HTMLElement) => {
|
document.querySelectorAll('li[data-type="tab-header"][data-init-active="true"]').forEach((item: HTMLElement) => {
|
||||||
item.removeAttribute("data-init-active");
|
item.removeAttribute("data-init-active");
|
||||||
const tab = getInstanceById(item.getAttribute("data-id")) as Tab
|
const tab = getInstanceById(item.getAttribute("data-id")) as Tab;
|
||||||
tab.parent.switchTab(item, false, false);
|
tab.parent.switchTab(item, false, false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -719,14 +719,14 @@ export const copyTab = (app: App, tab: Tab) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const newModelByInitData = (app: App, tab: Tab, json: any) => {
|
export const newModelByInitData = (app: App, tab: Tab, json: any) => {
|
||||||
let model: Model
|
let model: Model;
|
||||||
if (json.instance === "Custom") {
|
if (json.instance === "Custom") {
|
||||||
if (json.customModelType === "siyuan-card") {
|
if (json.customModelType === "siyuan-card") {
|
||||||
model = newCardModel({
|
model = newCardModel({
|
||||||
app,
|
app,
|
||||||
tab: tab,
|
tab: tab,
|
||||||
data: json.customModelData
|
data: json.customModelData
|
||||||
})
|
});
|
||||||
} else {
|
} else {
|
||||||
app.plugins.find(item => {
|
app.plugins.find(item => {
|
||||||
if (item.models[json.customModelType]) {
|
if (item.models[json.customModelType]) {
|
||||||
|
|
@ -749,7 +749,7 @@ export const newModelByInitData = (app: App, tab: Tab, json: any) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return model;
|
return model;
|
||||||
}
|
};
|
||||||
|
|
||||||
export const pdfIsLoading = (element: HTMLElement) => {
|
export const pdfIsLoading = (element: HTMLElement) => {
|
||||||
const isLoading = element.querySelector('.layout-tab-container > [data-loading="true"]') ? true : false;
|
const isLoading = element.querySelector('.layout-tab-container > [data-loading="true"]') ? true : false;
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ export const loadPlugin = (app: App, item: IPluginData) => {
|
||||||
|
|
||||||
|
|
||||||
const updateDock = (dockItem: IDockTab[], index: number, plugin: Plugin, type: string) => {
|
const updateDock = (dockItem: IDockTab[], index: number, plugin: Plugin, type: string) => {
|
||||||
const dockKeys = Object.keys(plugin.docks)
|
const dockKeys = Object.keys(plugin.docks);
|
||||||
dockItem.forEach((tabItem: IDockTab, tabIndex: number) => {
|
dockItem.forEach((tabItem: IDockTab, tabIndex: number) => {
|
||||||
if (dockKeys.includes(tabItem.type)) {
|
if (dockKeys.includes(tabItem.type)) {
|
||||||
if (type === "Left") {
|
if (type === "Left") {
|
||||||
|
|
@ -94,8 +94,8 @@ const updateDock = (dockItem: IDockTab[], index: number, plugin: Plugin, type: s
|
||||||
plugin.docks[tabItem.type].config.show = tabItem.show;
|
plugin.docks[tabItem.type].config.show = tabItem.show;
|
||||||
plugin.docks[tabItem.type].config.size = tabItem.size;
|
plugin.docks[tabItem.type].config.size = tabItem.size;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
export const afterLoadPlugin = (plugin: Plugin) => {
|
export const afterLoadPlugin = (plugin: Plugin) => {
|
||||||
try {
|
try {
|
||||||
|
|
@ -113,14 +113,14 @@ export const afterLoadPlugin = (plugin: Plugin) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
window.siyuan.config.uiLayout.left.data.forEach((dockItem: IDockTab[], index: number) => {
|
window.siyuan.config.uiLayout.left.data.forEach((dockItem: IDockTab[], index: number) => {
|
||||||
updateDock(dockItem, index, plugin, "Left")
|
updateDock(dockItem, index, plugin, "Left");
|
||||||
})
|
});
|
||||||
window.siyuan.config.uiLayout.right.data.forEach((dockItem: IDockTab[], index: number) => {
|
window.siyuan.config.uiLayout.right.data.forEach((dockItem: IDockTab[], index: number) => {
|
||||||
updateDock(dockItem, index, plugin, "Right")
|
updateDock(dockItem, index, plugin, "Right");
|
||||||
})
|
});
|
||||||
window.siyuan.config.uiLayout.bottom.data.forEach((dockItem: IDockTab[], index: number) => {
|
window.siyuan.config.uiLayout.bottom.data.forEach((dockItem: IDockTab[], index: number) => {
|
||||||
updateDock(dockItem, index, plugin, "Bottom")
|
updateDock(dockItem, index, plugin, "Bottom");
|
||||||
})
|
});
|
||||||
Object.keys(plugin.docks).forEach(key => {
|
Object.keys(plugin.docks).forEach(key => {
|
||||||
const dock = plugin.docks[key];
|
const dock = plugin.docks[key];
|
||||||
if (dock.config.position.startsWith("Left")) {
|
if (dock.config.position.startsWith("Left")) {
|
||||||
|
|
@ -153,4 +153,4 @@ export const afterLoadPlugin = (plugin: Plugin) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 等待 tab 完成后再 init Tab model
|
// 等待 tab 完成后再 init Tab model
|
||||||
}
|
};
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {App} from "../index";
|
||||||
import {Plugin} from "../plugin";
|
import {Plugin} from "../plugin";
|
||||||
import {getAllModels} from "../layout/getAll";
|
import {getAllModels} from "../layout/getAll";
|
||||||
import {exportLayout} from "../layout/util";
|
import {exportLayout} from "../layout/util";
|
||||||
|
import {Constants} from "../constants";
|
||||||
|
|
||||||
export const uninstall = (app: App, name: string) => {
|
export const uninstall = (app: App, name: string) => {
|
||||||
app.plugins.find((plugin: Plugin, index) => {
|
app.plugins.find((plugin: Plugin, index) => {
|
||||||
|
|
@ -43,11 +44,14 @@ export const uninstall = (app: App, name: string) => {
|
||||||
});
|
});
|
||||||
// rm plugin
|
// rm plugin
|
||||||
app.plugins.splice(index, 1);
|
app.plugins.splice(index, 1);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
exportLayout({
|
exportLayout({
|
||||||
reload: false,
|
reload: false,
|
||||||
onlyData: false,
|
onlyData: false,
|
||||||
errorExit: false
|
errorExit: false
|
||||||
});
|
});
|
||||||
|
}, Constants.TIMEOUT_LOAD); // 移除页签时切换到新的文档页签,需等待新页签初始化完成,才有 editor.protyle.block 等数据
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue