This commit is contained in:
Vanessa 2023-05-24 20:06:32 +08:00
parent 1744d6b5cd
commit 580fb4007e
6 changed files with 37 additions and 33 deletions

View file

@ -478,7 +478,7 @@ export const globalShortcut = (app: App) => {
rootId = ` data-node-id="${item.model.editor.protyle.block.rootID}"`;
icon = unicode2Emoji(item.docIcon || Constants.SIYUAN_IMAGE_FILE, false, "b3-list-item__graphic", true);
} else if (initData) {
const initDataObj = JSON.parse(initData)
const initDataObj = JSON.parse(initData);
if (initDataObj.instance === "Editor") {
rootId = ` data-node-id="${initDataObj.rootId}"`;
icon = unicode2Emoji(item.docIcon || Constants.SIYUAN_IMAGE_FILE, false, "b3-list-item__graphic", true);

View file

@ -434,7 +434,7 @@ export class Wnd {
if (currentTab && currentTab.headElement) {
const initData = currentTab.headElement.getAttribute("data-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");
return;
}

View file

@ -65,23 +65,23 @@ export class Dock {
this.position = options.position;
this.pin = options.data.pin;
this.data = {};
let showDock = false
let showDock = false;
if (options.data.data.length !== 0) {
if (!showDock) {
options.data.data[0].find(item => {
if (TYPES.includes(item.type)) {
showDock = true
return true
showDock = true;
return true;
}
})
});
}
if (!showDock && options.data.data[1]) {
options.data.data[1].find(item => {
if (TYPES.includes(item.type)) {
showDock = true
return true
showDock = true;
return true;
}
})
});
}
}
if (!showDock) {

View file

@ -408,20 +408,20 @@ export const JSONToLayout = (app: App, isStart: boolean) => {
});
// 移除没有插件的 tab
document.querySelectorAll('li[data-type="tab-header"]').forEach((item: HTMLElement) => {
const initData = item.getAttribute("data-initdata")
const initData = item.getAttribute("data-initdata");
if (initData) {
const initDataObj = JSON.parse(initData);
if (initDataObj.instance === "Custom") {
let hasPlugin = false;
app.plugins.find(plugin => {
if (Object.keys(plugin.models).includes(initDataObj.customModelType)) {
hasPlugin = true
return true
hasPlugin = true;
return true;
}
});
if (!hasPlugin) {
const tabId = item.getAttribute("data-id")
const tab = getInstanceById(tabId) as Tab
const tabId = item.getAttribute("data-id");
const tab = getInstanceById(tabId) as Tab;
if (tab) {
tab.parent.removeTab(tabId, false, false, false);
}
@ -440,7 +440,7 @@ export const JSONToLayout = (app: App, isStart: boolean) => {
} else {
document.querySelectorAll('li[data-type="tab-header"][data-init-active="true"]').forEach((item: HTMLElement) => {
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);
});
}
@ -719,14 +719,14 @@ export const copyTab = (app: App, tab: Tab) => {
};
export const newModelByInitData = (app: App, tab: Tab, json: any) => {
let model: Model
let model: Model;
if (json.instance === "Custom") {
if (json.customModelType === "siyuan-card") {
model = newCardModel({
app,
tab: tab,
data: json.customModelData
})
});
} else {
app.plugins.find(item => {
if (item.models[json.customModelType]) {
@ -749,7 +749,7 @@ export const newModelByInitData = (app: App, tab: Tab, json: any) => {
});
}
return model;
}
};
export const pdfIsLoading = (element: HTMLElement) => {
const isLoading = element.querySelector('.layout-tab-container > [data-loading="true"]') ? true : false;

View file

@ -80,7 +80,7 @@ export const loadPlugin = (app: App, item: IPluginData) => {
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) => {
if (dockKeys.includes(tabItem.type)) {
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.size = tabItem.size;
}
})
}
});
};
export const afterLoadPlugin = (plugin: Plugin) => {
try {
@ -113,14 +113,14 @@ export const afterLoadPlugin = (plugin: Plugin) => {
});
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) => {
updateDock(dockItem, index, plugin, "Right")
})
updateDock(dockItem, index, plugin, "Right");
});
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 => {
const dock = plugin.docks[key];
if (dock.config.position.startsWith("Left")) {
@ -153,4 +153,4 @@ export const afterLoadPlugin = (plugin: Plugin) => {
}
});
// 等待 tab 完成后再 init Tab model
}
};

View file

@ -2,6 +2,7 @@ import {App} from "../index";
import {Plugin} from "../plugin";
import {getAllModels} from "../layout/getAll";
import {exportLayout} from "../layout/util";
import {Constants} from "../constants";
export const uninstall = (app: App, name: string) => {
app.plugins.find((plugin: Plugin, index) => {
@ -43,11 +44,14 @@ export const uninstall = (app: App, name: string) => {
});
// rm plugin
app.plugins.splice(index, 1);
exportLayout({
reload: false,
onlyData: false,
errorExit: false
});
setTimeout(() => {
exportLayout({
reload: false,
onlyData: false,
errorExit: false
});
}, Constants.TIMEOUT_LOAD); // 移除页签时切换到新的文档页签,需等待新页签初始化完成,才有 editor.protyle.block 等数据
return true;
}
});