mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-23 18:10:12 +01:00
This commit is contained in:
parent
228da65358
commit
3abccfe676
10 changed files with 101 additions and 83 deletions
|
|
@ -436,7 +436,7 @@ export const globalShortcut = (app: App) => {
|
|||
if (event.key === "Shift") {
|
||||
window.siyuan.shiftIsPressed = true;
|
||||
if (!event.repeat) {
|
||||
showPopover(app,true);
|
||||
showPopover(app, true);
|
||||
}
|
||||
} else {
|
||||
window.siyuan.shiftIsPressed = false;
|
||||
|
|
@ -478,9 +478,12 @@ 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) {
|
||||
rootId = ` data-node-id="${JSON.parse(initData).rootId}"`;
|
||||
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);
|
||||
}
|
||||
}
|
||||
tabHtml += `<li data-index="${index}" data-id="${item.id}"${rootId} class="b3-list-item${currentId === item.id ? " b3-list-item--focus" : ""}"${currentId === item.id ? ' data-original="true"' : ""}>${icon}<span class="b3-list-item__text">${escapeHtml(item.title)}</span></li>`;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,6 +110,16 @@ export const openFile = (options: IOpenFileOptions) => {
|
|||
}
|
||||
});
|
||||
if (custom) {
|
||||
if (options.afterOpen) {
|
||||
options.afterOpen();
|
||||
}
|
||||
return;
|
||||
}
|
||||
const hasModel = getUnInitTab(options);
|
||||
if (hasModel) {
|
||||
if (options.afterOpen) {
|
||||
options.afterOpen();
|
||||
}
|
||||
return;
|
||||
}
|
||||
} else if (options.searchData) {
|
||||
|
|
@ -284,7 +294,8 @@ const getUnInitTab = (options: IOpenFileOptions) => {
|
|||
const initData = item.headElement?.getAttribute("data-initdata");
|
||||
if (initData) {
|
||||
const initObj = JSON.parse(initData);
|
||||
if (initObj.rootId === options.rootID || initObj.blockId === options.rootID) {
|
||||
if (initObj.instance === "Editor" &&
|
||||
(initObj.rootId === options.rootID || initObj.blockId === options.rootID)) {
|
||||
initObj.blockId = options.id;
|
||||
initObj.mode = options.mode;
|
||||
if (options.zoomIn) {
|
||||
|
|
@ -296,6 +307,9 @@ const getUnInitTab = (options: IOpenFileOptions) => {
|
|||
item.headElement.setAttribute("data-initdata", JSON.stringify(initObj));
|
||||
item.parent.switchTab(item.headElement);
|
||||
return true;
|
||||
} else if (initObj.instance === "Custom" && objEquals(initObj.customModelData, options.custom.data)) {
|
||||
item.parent.switchTab(item.headElement);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ export class App {
|
|||
const initTab = tab.headElement.getAttribute("data-initdata");
|
||||
if (initTab) {
|
||||
const initTabData = JSON.parse(initTab);
|
||||
if (initTabData.rootId === data.data.id) {
|
||||
if (initTabData.instance === "Editor" && initTabData.rootId === data.data.id) {
|
||||
tab.updateTitle(data.data.title);
|
||||
}
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ export class App {
|
|||
const initTab = tab.headElement.getAttribute("data-initdata");
|
||||
if (initTab) {
|
||||
const initTabData = JSON.parse(initTab);
|
||||
if (data.data.box === initTabData.notebookId) {
|
||||
if (initTabData.instance === "Editor" && data.data.box === initTabData.notebookId) {
|
||||
tab.parent.removeTab(tab.id);
|
||||
}
|
||||
}
|
||||
|
|
@ -106,7 +106,7 @@ export class App {
|
|||
const initTab = tab.headElement.getAttribute("data-initdata");
|
||||
if (initTab) {
|
||||
const initTabData = JSON.parse(initTab);
|
||||
if (data.data.ids.includes(initTabData.rootId)) {
|
||||
if (initTabData.instance === "Editor" && data.data.ids.includes(initTabData.rootId)) {
|
||||
tab.parent.removeTab(tab.id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ export class Tab {
|
|||
id = (this.model as Editor).editor.protyle.block.rootID;
|
||||
} else if (!this.model) {
|
||||
const initData = JSON.parse(this.headElement.getAttribute("data-initdata") || "{}");
|
||||
if (initData) {
|
||||
if (initData && initData.instance === "Editor") {
|
||||
id = initData.blockId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import {genUUID} from "../util/genID";
|
|||
import {
|
||||
getInstanceById,
|
||||
getWndByLayout, JSONToCenter,
|
||||
newCenterEmptyTab, pdfIsLoading,
|
||||
newCenterEmptyTab, newModelByInitData, pdfIsLoading,
|
||||
resizeTabs,
|
||||
setPanelFocus,
|
||||
switchWnd
|
||||
|
|
@ -434,15 +434,7 @@ export class Wnd {
|
|||
if (currentTab && currentTab.headElement) {
|
||||
const initData = currentTab.headElement.getAttribute("data-initdata");
|
||||
if (initData) {
|
||||
const json = JSON.parse(initData);
|
||||
currentTab.addModel(new Editor({
|
||||
app: this.app,
|
||||
tab: currentTab,
|
||||
blockId: json.blockId,
|
||||
mode: json.mode,
|
||||
action: typeof json.action === "string" ? [json.action] : json.action,
|
||||
scrollAttr: json.scrollAttr,
|
||||
}));
|
||||
currentTab.addModel(newModelByInitData(this.app, currentTab, JSON.parse(initData)))
|
||||
currentTab.headElement.removeAttribute("data-initdata");
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -265,7 +265,7 @@ const JSONToDock = (json: any, app: App) => {
|
|||
window.siyuan.layout.bottomDock = new Dock({position: "Bottom", data: json.bottom, app});
|
||||
};
|
||||
|
||||
export const JSONToCenter = (app: App, json: ILayoutJSON, layout?: Layout | Wnd | Tab | Model, isStart = false) => {
|
||||
export const JSONToCenter = (app: App, json: ILayoutJSON, layout?: Layout | Wnd | Tab | Model) => {
|
||||
let child: Layout | Wnd | Tab | Model;
|
||||
if (json.instance === "Layout") {
|
||||
if (!layout) {
|
||||
|
|
@ -376,63 +376,37 @@ export const JSONToCenter = (app: App, json: ILayoutJSON, layout?: Layout | Wnd
|
|||
config: json.config
|
||||
}));
|
||||
} else if (json.instance === "Custom") {
|
||||
if (json.customModelType === "siyuan-card") {
|
||||
(layout as Tab).addModel(newCardModel({
|
||||
app,
|
||||
tab: (layout as Tab),
|
||||
data: json.customModelData
|
||||
}));
|
||||
} else {
|
||||
app.plugins.find(item => {
|
||||
if (item.models[json.customModelType]) {
|
||||
(layout as Tab).addModel(item.models[json.customModelType]({
|
||||
tab: (layout as Tab),
|
||||
data: json.customModelData
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
if (window.siyuan.config.fileTree.openFilesUseCurrentTab) {
|
||||
(layout as Tab).headElement.classList.add("item--unupdate");
|
||||
}
|
||||
(layout as Tab).headElement.setAttribute("data-initdata", JSON.stringify(json));
|
||||
}
|
||||
if (json.children) {
|
||||
if (Array.isArray(json.children)) {
|
||||
json.children.forEach((item: any, index: number) => {
|
||||
JSONToCenter(app, item, layout ? child : window.siyuan.layout.layout, isStart);
|
||||
if (item.instance === "Tab" && index === (json.children as ILayoutJSON[]).length - 1) {
|
||||
const activeTabElement = (child as Wnd).headersElement.querySelector('[data-init-active="true"]') as HTMLElement;
|
||||
if (activeTabElement) {
|
||||
if (window.siyuan.config.fileTree.closeTabsOnStart && isStart &&
|
||||
!item.pin && item.title) {
|
||||
// 启动时关闭所有页签就不应该再初始化它
|
||||
} else {
|
||||
activeTabElement.removeAttribute("data-init-active");
|
||||
(child as Wnd).switchTab(activeTabElement, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
json.children.forEach((item: any) => {
|
||||
JSONToCenter(app, item, layout ? child : window.siyuan.layout.layout);
|
||||
});
|
||||
} else {
|
||||
JSONToCenter(app, json.children, child, isStart);
|
||||
JSONToCenter(app, json.children, child);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const JSONToLayout = (app: App, isStart: boolean) => {
|
||||
JSONToCenter(app, window.siyuan.config.uiLayout.layout, undefined, isStart);
|
||||
JSONToCenter(app, window.siyuan.config.uiLayout.layout, undefined);
|
||||
JSONToDock(window.siyuan.config.uiLayout, app);
|
||||
// 启动时不打开页签,需要移除没有钉住的页签
|
||||
if (window.siyuan.config.fileTree.closeTabsOnStart && isStart) {
|
||||
getAllTabs().forEach(item => {
|
||||
if (item.headElement && !item.headElement.classList.contains("item--pin")) {
|
||||
item.parent.removeTab(item.id);
|
||||
item.parent.removeTab(item.id, false, false, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
app.plugins.forEach(item => {
|
||||
afterLoadPlugin(item);
|
||||
});
|
||||
const idZoomIn = getIdZoomInByPath();
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
// 启动时 layout 中有该文档,该文档还原会在此之后,因此需有延迟
|
||||
if (idZoomIn.id) {
|
||||
openFileById({
|
||||
app,
|
||||
|
|
@ -440,11 +414,13 @@ export const JSONToLayout = (app: App, isStart: boolean) => {
|
|||
action: idZoomIn.isZoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||
zoomIn: idZoomIn.isZoomIn
|
||||
});
|
||||
}
|
||||
app.plugins.forEach(item => {
|
||||
afterLoadPlugin(item);
|
||||
} 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
|
||||
tab.parent.switchTab(item, false, false);
|
||||
});
|
||||
}, Constants.TIMEOUT_LOAD);
|
||||
}
|
||||
};
|
||||
|
||||
export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any, dropEditScroll = false) => {
|
||||
|
|
@ -706,23 +682,52 @@ export const copyTab = (app: App, tab: Tab) => {
|
|||
}
|
||||
} else if (!tab.model && tab.headElement) {
|
||||
const initData = JSON.parse(tab.headElement.getAttribute("data-initdata") || "{}");
|
||||
if (initData) {
|
||||
// 历史数据兼容 2023-05-24
|
||||
if (initData.scrollAttr) {
|
||||
initData.scrollAttr.rootId = initData.rootId;
|
||||
}
|
||||
model = new Editor({
|
||||
app,
|
||||
tab: newTab,
|
||||
blockId: initData.blockId,
|
||||
mode: initData.mode,
|
||||
action: typeof initData.action === "string" ? [initData.action] : initData.action,
|
||||
scrollAttr: initData.scrollAttr,
|
||||
});
|
||||
model = newModelByInitData(app, newTab, initData);
|
||||
}
|
||||
}
|
||||
newTab.addModel(model);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const newModelByInitData = (app: App, tab: Tab, json: any) => {
|
||||
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]) {
|
||||
model = item.models[json.customModelType]({
|
||||
tab: tab,
|
||||
data: json.customModelData
|
||||
});
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (json.instance === "Editor") {
|
||||
model = new Editor({
|
||||
app,
|
||||
tab,
|
||||
blockId: json.blockId,
|
||||
mode: json.mode,
|
||||
action: typeof json.action === "string" ? [json.action] : json.action,
|
||||
scrollAttr: json.scrollAttr,
|
||||
});
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
export const pdfIsLoading = (element: HTMLElement) => {
|
||||
const isLoading = element.querySelector('.layout-tab-container > [data-loading="true"]') ? true : false;
|
||||
if (isLoading) {
|
||||
|
|
|
|||
|
|
@ -176,9 +176,11 @@ export const initTabMenu = (app: App, tab: Tab) => {
|
|||
const initData = tab.headElement.getAttribute("data-initdata");
|
||||
if (initData) {
|
||||
const initDataObj = JSON.parse(initData);
|
||||
if (initDataObj && initDataObj.instance === "Editor") {
|
||||
rootId = initDataObj.rootId || initDataObj.blockId;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rootId) {
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
label: window.siyuan.languages.copy,
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export const switchTabById = (id: string) => {
|
|||
const initTab = tab.headElement.getAttribute("data-initdata");
|
||||
if (initTab) {
|
||||
const initTabData = JSON.parse(initTab);
|
||||
if (initTabData.rootId === id) {
|
||||
if (initTabData.instance === "Editor" && initTabData.rootId === id) {
|
||||
tab.parent.switchTab(tab.headElement);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ class App {
|
|||
const initTab = tab.headElement.getAttribute("data-initdata");
|
||||
if (initTab) {
|
||||
const initTabData = JSON.parse(initTab);
|
||||
if (initTabData.rootId === data.data.id) {
|
||||
if (initTabData.instance === "Editor" && initTabData.rootId === data.data.id) {
|
||||
tab.updateTitle(data.data.title);
|
||||
}
|
||||
}
|
||||
|
|
@ -77,7 +77,7 @@ class App {
|
|||
const initTab = tab.headElement.getAttribute("data-initdata");
|
||||
if (initTab) {
|
||||
const initTabData = JSON.parse(initTab);
|
||||
if (data.data.box === initTabData.notebookId) {
|
||||
if (initTabData.instance === "Editor" && data.data.box === initTabData.notebookId) {
|
||||
tab.parent.removeTab(tab.id);
|
||||
}
|
||||
}
|
||||
|
|
@ -90,7 +90,7 @@ class App {
|
|||
const initTab = tab.headElement.getAttribute("data-initdata");
|
||||
if (initTab) {
|
||||
const initTabData = JSON.parse(initTab);
|
||||
if (data.data.ids.includes(initTabData.rootId)) {
|
||||
if (initTabData.instance === "Editor" && data.data.ids.includes(initTabData.rootId)) {
|
||||
tab.parent.removeTab(tab.id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,8 +66,10 @@ export const setModelsHash = () => {
|
|||
const initTab = tab.headElement.getAttribute("data-initdata");
|
||||
if (initTab) {
|
||||
const initTabData = JSON.parse(initTab);
|
||||
if (initTabData.instance === "Editor") {
|
||||
hash += initTabData.rootId + Constants.ZWSP;
|
||||
}
|
||||
}
|
||||
} else if (tab.model instanceof Editor) {
|
||||
hash += tab.model.editor.protyle.block.rootID + Constants.ZWSP;
|
||||
} else if (tab.model instanceof Asset) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue