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") {
|
if (event.key === "Shift") {
|
||||||
window.siyuan.shiftIsPressed = true;
|
window.siyuan.shiftIsPressed = true;
|
||||||
if (!event.repeat) {
|
if (!event.repeat) {
|
||||||
showPopover(app,true);
|
showPopover(app, true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
window.siyuan.shiftIsPressed = false;
|
window.siyuan.shiftIsPressed = false;
|
||||||
|
|
@ -478,8 +478,11 @@ 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) {
|
||||||
rootId = ` data-node-id="${JSON.parse(initData).rootId}"`;
|
const initDataObj = JSON.parse(initData)
|
||||||
icon = unicode2Emoji(item.docIcon || Constants.SIYUAN_IMAGE_FILE, false, "b3-list-item__graphic", true);
|
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>`;
|
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 (custom) {
|
||||||
|
if (options.afterOpen) {
|
||||||
|
options.afterOpen();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const hasModel = getUnInitTab(options);
|
||||||
|
if (hasModel) {
|
||||||
|
if (options.afterOpen) {
|
||||||
|
options.afterOpen();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (options.searchData) {
|
} else if (options.searchData) {
|
||||||
|
|
@ -284,7 +294,8 @@ const getUnInitTab = (options: IOpenFileOptions) => {
|
||||||
const initData = item.headElement?.getAttribute("data-initdata");
|
const initData = item.headElement?.getAttribute("data-initdata");
|
||||||
if (initData) {
|
if (initData) {
|
||||||
const initObj = JSON.parse(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.blockId = options.id;
|
||||||
initObj.mode = options.mode;
|
initObj.mode = options.mode;
|
||||||
if (options.zoomIn) {
|
if (options.zoomIn) {
|
||||||
|
|
@ -296,6 +307,9 @@ const getUnInitTab = (options: IOpenFileOptions) => {
|
||||||
item.headElement.setAttribute("data-initdata", JSON.stringify(initObj));
|
item.headElement.setAttribute("data-initdata", JSON.stringify(initObj));
|
||||||
item.parent.switchTab(item.headElement);
|
item.parent.switchTab(item.headElement);
|
||||||
return true;
|
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");
|
const initTab = tab.headElement.getAttribute("data-initdata");
|
||||||
if (initTab) {
|
if (initTab) {
|
||||||
const initTabData = JSON.parse(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);
|
tab.updateTitle(data.data.title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -93,7 +93,7 @@ export class App {
|
||||||
const initTab = tab.headElement.getAttribute("data-initdata");
|
const initTab = tab.headElement.getAttribute("data-initdata");
|
||||||
if (initTab) {
|
if (initTab) {
|
||||||
const initTabData = JSON.parse(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);
|
tab.parent.removeTab(tab.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -106,7 +106,7 @@ export class App {
|
||||||
const initTab = tab.headElement.getAttribute("data-initdata");
|
const initTab = tab.headElement.getAttribute("data-initdata");
|
||||||
if (initTab) {
|
if (initTab) {
|
||||||
const initTabData = JSON.parse(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);
|
tab.parent.removeTab(tab.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ export class Tab {
|
||||||
id = (this.model as Editor).editor.protyle.block.rootID;
|
id = (this.model as Editor).editor.protyle.block.rootID;
|
||||||
} else if (!this.model) {
|
} else if (!this.model) {
|
||||||
const initData = JSON.parse(this.headElement.getAttribute("data-initdata") || "{}");
|
const initData = JSON.parse(this.headElement.getAttribute("data-initdata") || "{}");
|
||||||
if (initData) {
|
if (initData && initData.instance === "Editor") {
|
||||||
id = initData.blockId;
|
id = initData.blockId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import {genUUID} from "../util/genID";
|
||||||
import {
|
import {
|
||||||
getInstanceById,
|
getInstanceById,
|
||||||
getWndByLayout, JSONToCenter,
|
getWndByLayout, JSONToCenter,
|
||||||
newCenterEmptyTab, pdfIsLoading,
|
newCenterEmptyTab, newModelByInitData, pdfIsLoading,
|
||||||
resizeTabs,
|
resizeTabs,
|
||||||
setPanelFocus,
|
setPanelFocus,
|
||||||
switchWnd
|
switchWnd
|
||||||
|
|
@ -434,15 +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) {
|
||||||
const json = JSON.parse(initData);
|
currentTab.addModel(newModelByInitData(this.app, currentTab, 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.headElement.removeAttribute("data-initdata");
|
currentTab.headElement.removeAttribute("data-initdata");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -265,7 +265,7 @@ const JSONToDock = (json: any, app: App) => {
|
||||||
window.siyuan.layout.bottomDock = new Dock({position: "Bottom", data: json.bottom, 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;
|
let child: Layout | Wnd | Tab | Model;
|
||||||
if (json.instance === "Layout") {
|
if (json.instance === "Layout") {
|
||||||
if (!layout) {
|
if (!layout) {
|
||||||
|
|
@ -376,75 +376,51 @@ export const JSONToCenter = (app: App, json: ILayoutJSON, layout?: Layout | Wnd
|
||||||
config: json.config
|
config: json.config
|
||||||
}));
|
}));
|
||||||
} else if (json.instance === "Custom") {
|
} else if (json.instance === "Custom") {
|
||||||
if (json.customModelType === "siyuan-card") {
|
if (window.siyuan.config.fileTree.openFilesUseCurrentTab) {
|
||||||
(layout as Tab).addModel(newCardModel({
|
(layout as Tab).headElement.classList.add("item--unupdate");
|
||||||
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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
(layout as Tab).headElement.setAttribute("data-initdata", JSON.stringify(json));
|
||||||
}
|
}
|
||||||
if (json.children) {
|
if (json.children) {
|
||||||
if (Array.isArray(json.children)) {
|
if (Array.isArray(json.children)) {
|
||||||
json.children.forEach((item: any, index: number) => {
|
json.children.forEach((item: any) => {
|
||||||
JSONToCenter(app, item, layout ? child : window.siyuan.layout.layout, isStart);
|
JSONToCenter(app, item, layout ? child : window.siyuan.layout.layout);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
JSONToCenter(app, json.children, child, isStart);
|
JSONToCenter(app, json.children, child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const JSONToLayout = (app: App, isStart: boolean) => {
|
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);
|
JSONToDock(window.siyuan.config.uiLayout, app);
|
||||||
// 启动时不打开页签,需要移除没有钉住的页签
|
// 启动时不打开页签,需要移除没有钉住的页签
|
||||||
if (window.siyuan.config.fileTree.closeTabsOnStart && isStart) {
|
if (window.siyuan.config.fileTree.closeTabsOnStart && isStart) {
|
||||||
getAllTabs().forEach(item => {
|
getAllTabs().forEach(item => {
|
||||||
if (item.headElement && !item.headElement.classList.contains("item--pin")) {
|
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();
|
const idZoomIn = getIdZoomInByPath();
|
||||||
|
if (idZoomIn.id) {
|
||||||
|
openFileById({
|
||||||
setTimeout(() => {
|
app,
|
||||||
// 启动时 layout 中有该文档,该文档还原会在此之后,因此需有延迟
|
id: idZoomIn.id,
|
||||||
if (idZoomIn.id) {
|
action: idZoomIn.isZoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
openFileById({
|
zoomIn: idZoomIn.isZoomIn
|
||||||
app,
|
|
||||||
id: idZoomIn.id,
|
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
}, Constants.TIMEOUT_LOAD);
|
} 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);
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any, dropEditScroll = false) => {
|
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) {
|
} else if (!tab.model && tab.headElement) {
|
||||||
const initData = JSON.parse(tab.headElement.getAttribute("data-initdata") || "{}");
|
const initData = JSON.parse(tab.headElement.getAttribute("data-initdata") || "{}");
|
||||||
if (initData.scrollAttr) {
|
if (initData) {
|
||||||
initData.scrollAttr.rootId = initData.rootId;
|
// 历史数据兼容 2023-05-24
|
||||||
|
if (initData.scrollAttr) {
|
||||||
|
initData.scrollAttr.rootId = initData.rootId;
|
||||||
|
}
|
||||||
|
model = newModelByInitData(app, newTab, initData);
|
||||||
}
|
}
|
||||||
model = new Editor({
|
|
||||||
app,
|
|
||||||
tab: newTab,
|
|
||||||
blockId: initData.blockId,
|
|
||||||
mode: initData.mode,
|
|
||||||
action: typeof initData.action === "string" ? [initData.action] : initData.action,
|
|
||||||
scrollAttr: initData.scrollAttr,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
newTab.addModel(model);
|
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) => {
|
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;
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
|
|
|
||||||
|
|
@ -176,7 +176,9 @@ export const initTabMenu = (app: App, tab: Tab) => {
|
||||||
const initData = tab.headElement.getAttribute("data-initdata");
|
const initData = tab.headElement.getAttribute("data-initdata");
|
||||||
if (initData) {
|
if (initData) {
|
||||||
const initDataObj = JSON.parse(initData);
|
const initDataObj = JSON.parse(initData);
|
||||||
rootId = initDataObj.rootId || initDataObj.blockId;
|
if (initDataObj && initDataObj.instance === "Editor") {
|
||||||
|
rootId = initDataObj.rootId || initDataObj.blockId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rootId) {
|
if (rootId) {
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ export const switchTabById = (id: string) => {
|
||||||
const initTab = tab.headElement.getAttribute("data-initdata");
|
const initTab = tab.headElement.getAttribute("data-initdata");
|
||||||
if (initTab) {
|
if (initTab) {
|
||||||
const initTabData = JSON.parse(initTab);
|
const initTabData = JSON.parse(initTab);
|
||||||
if (initTabData.rootId === id) {
|
if (initTabData.instance === "Editor" && initTabData.rootId === id) {
|
||||||
tab.parent.switchTab(tab.headElement);
|
tab.parent.switchTab(tab.headElement);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ class App {
|
||||||
const initTab = tab.headElement.getAttribute("data-initdata");
|
const initTab = tab.headElement.getAttribute("data-initdata");
|
||||||
if (initTab) {
|
if (initTab) {
|
||||||
const initTabData = JSON.parse(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);
|
tab.updateTitle(data.data.title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -77,7 +77,7 @@ class App {
|
||||||
const initTab = tab.headElement.getAttribute("data-initdata");
|
const initTab = tab.headElement.getAttribute("data-initdata");
|
||||||
if (initTab) {
|
if (initTab) {
|
||||||
const initTabData = JSON.parse(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);
|
tab.parent.removeTab(tab.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -90,7 +90,7 @@ class App {
|
||||||
const initTab = tab.headElement.getAttribute("data-initdata");
|
const initTab = tab.headElement.getAttribute("data-initdata");
|
||||||
if (initTab) {
|
if (initTab) {
|
||||||
const initTabData = JSON.parse(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);
|
tab.parent.removeTab(tab.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,9 @@ export const setModelsHash = () => {
|
||||||
const initTab = tab.headElement.getAttribute("data-initdata");
|
const initTab = tab.headElement.getAttribute("data-initdata");
|
||||||
if (initTab) {
|
if (initTab) {
|
||||||
const initTabData = JSON.parse(initTab);
|
const initTabData = JSON.parse(initTab);
|
||||||
hash += initTabData.rootId + Constants.ZWSP;
|
if (initTabData.instance === "Editor") {
|
||||||
|
hash += initTabData.rootId + Constants.ZWSP;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (tab.model instanceof Editor) {
|
} else if (tab.model instanceof Editor) {
|
||||||
hash += tab.model.editor.protyle.block.rootID + Constants.ZWSP;
|
hash += tab.model.editor.protyle.block.rootID + Constants.ZWSP;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue