mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-04 07:48:49 +01:00
This commit is contained in:
parent
b62aba69c1
commit
d986473e17
4 changed files with 158 additions and 90 deletions
|
|
@ -52,6 +52,7 @@ import {isWindow} from "../util/functions";
|
|||
import {reloadProtyle} from "../protyle/util/reload";
|
||||
import {fullscreen} from "../protyle/breadcrumb/action";
|
||||
import {setPadding} from "../protyle/ui/initUI";
|
||||
import {openRecentDocs} from "../business/openRecentDocs";
|
||||
|
||||
const getRightBlock = (element: HTMLElement, x: number, y: number) => {
|
||||
let index = 1;
|
||||
|
|
@ -979,75 +980,6 @@ const dialogArrow = (element: HTMLElement, event: KeyboardEvent) => {
|
|||
}
|
||||
};
|
||||
|
||||
const openRecentDocs = () => {
|
||||
fetchPost("/api/storage/getRecentDocs", {}, (response) => {
|
||||
let range: Range;
|
||||
if (getSelection().rangeCount > 0) {
|
||||
range = getSelection().getRangeAt(0);
|
||||
}
|
||||
let tabHtml = "";
|
||||
response.data.forEach((item: any, index: number) => {
|
||||
tabHtml += `<li data-index="${index}" data-node-id="${item.rootID}" class="b3-list-item${index === 0 ? " b3-list-item--focus" : ""}">
|
||||
${unicode2Emoji(item.icon || Constants.SIYUAN_IMAGE_FILE, false, "b3-list-item__graphic", true)}
|
||||
<span class="b3-list-item__text">${escapeHtml(item.title)}</span>
|
||||
</li>`;
|
||||
});
|
||||
let dockHtml = "";
|
||||
if (!isWindow()) {
|
||||
dockHtml = `<ul class="b3-list b3-list--background" style="max-height: calc(70vh - 35px);overflow: auto">
|
||||
<li data-type="riffCard" data-index="0" class="b3-list-item${!tabHtml ? " b3-list-item--focus" : ""}">
|
||||
<svg class="b3-list-item__graphic"><use xlink:href="#iconRiffCard"></use></svg>
|
||||
<span class="b3-list-item__text">${window.siyuan.languages.riffCard}</span>
|
||||
<span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general.riffCard.custom)}</span>
|
||||
</li>`;
|
||||
getAllDocks().forEach((item, index) => {
|
||||
dockHtml += `<li data-type="${item.type}" data-index="${index + 1}" class="b3-list-item">
|
||||
<svg class="b3-list-item__graphic"><use xlink:href="#${item.icon}"></use></svg>
|
||||
<span class="b3-list-item__text">${window.siyuan.languages[item.hotkeyLangId]}</span>
|
||||
<span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general[item.hotkeyLangId].custom)}</span>
|
||||
</li>`;
|
||||
});
|
||||
dockHtml = dockHtml + "</ul>";
|
||||
}
|
||||
const dialog = new Dialog({
|
||||
title: window.siyuan.languages.recentDocs,
|
||||
content: `<div class="fn__flex-column switch-doc">
|
||||
<div class="fn__hr"><input style="opacity: 0;height: 1px;box-sizing: border-box"></div>
|
||||
<div class="fn__flex">${dockHtml}
|
||||
<ul${!isWindow() ? "" : ' style="border-left:0"'} class="b3-list b3-list--background fn__flex-1">${tabHtml}</ul>
|
||||
</div>
|
||||
<div class="switch-doc__path"></div>
|
||||
</div>`,
|
||||
destroyCallback: () => {
|
||||
if (range && range.getBoundingClientRect().height !== 0) {
|
||||
focusByRange(range);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (response.data.length > 0) {
|
||||
fetchPost("/api/filetree/getFullHPathByID", {
|
||||
id: response.data[0].rootID
|
||||
}, (response) => {
|
||||
dialog.element.querySelector(".switch-doc__path").innerHTML = escapeHtml(response.data);
|
||||
});
|
||||
} else {
|
||||
dialog.element.querySelector(".switch-doc__path").innerHTML = dialog.element.querySelector(".b3-list-item--focus").textContent;
|
||||
}
|
||||
dialog.element.querySelector("input").focus();
|
||||
dialog.element.setAttribute("data-key", window.siyuan.config.keymap.general.recentDocs.custom);
|
||||
dialog.element.addEventListener("click", (event) => {
|
||||
const liElement = hasClosestByClassName(event.target as HTMLElement, "b3-list-item");
|
||||
if (liElement) {
|
||||
dialog.element.querySelector(".b3-list-item--focus").classList.remove("b3-list-item--focus");
|
||||
liElement.classList.add("b3-list-item--focus");
|
||||
window.dispatchEvent(new KeyboardEvent("keydown", {key: "Enter"}));
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const editKeydown = (event: KeyboardEvent) => {
|
||||
const activeTabElement = document.querySelector(".layout__wnd--active .item--focus");
|
||||
let protyle: IProtyle;
|
||||
|
|
|
|||
79
app/src/business/openRecentDocs.ts
Normal file
79
app/src/business/openRecentDocs.ts
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
import {fetchPost} from "../util/fetch";
|
||||
import {unicode2Emoji} from "../emoji";
|
||||
import {Constants} from "../constants";
|
||||
import {escapeHtml} from "../util/escape";
|
||||
import {isWindow} from "../util/functions";
|
||||
import {updateHotkeyTip} from "../protyle/util/compatibility";
|
||||
import {getAllDocks} from "../layout/getAll";
|
||||
import {Dialog} from "../dialog";
|
||||
import {focusByRange} from "../protyle/util/selection";
|
||||
import {hasClosestByClassName} from "../protyle/util/hasClosest";
|
||||
|
||||
export const openRecentDocs = () => {
|
||||
fetchPost("/api/storage/getRecentDocs", {}, (response) => {
|
||||
let range: Range;
|
||||
if (getSelection().rangeCount > 0) {
|
||||
range = getSelection().getRangeAt(0);
|
||||
}
|
||||
let tabHtml = "";
|
||||
response.data.forEach((item: any, index: number) => {
|
||||
tabHtml += `<li data-index="${index}" data-node-id="${item.rootID}" class="b3-list-item${index === 0 ? " b3-list-item--focus" : ""}">
|
||||
${unicode2Emoji(item.icon || Constants.SIYUAN_IMAGE_FILE, false, "b3-list-item__graphic", true)}
|
||||
<span class="b3-list-item__text">${escapeHtml(item.title)}</span>
|
||||
</li>`;
|
||||
});
|
||||
let dockHtml = "";
|
||||
if (!isWindow()) {
|
||||
dockHtml = `<ul class="b3-list b3-list--background" style="max-height: calc(70vh - 35px);overflow: auto">
|
||||
<li data-type="riffCard" data-index="0" class="b3-list-item${!tabHtml ? " b3-list-item--focus" : ""}">
|
||||
<svg class="b3-list-item__graphic"><use xlink:href="#iconRiffCard"></use></svg>
|
||||
<span class="b3-list-item__text">${window.siyuan.languages.riffCard}</span>
|
||||
<span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general.riffCard.custom)}</span>
|
||||
</li>`;
|
||||
getAllDocks().forEach((item, index) => {
|
||||
dockHtml += `<li data-type="${item.type}" data-index="${index + 1}" class="b3-list-item">
|
||||
<svg class="b3-list-item__graphic"><use xlink:href="#${item.icon}"></use></svg>
|
||||
<span class="b3-list-item__text">${window.siyuan.languages[item.hotkeyLangId]}</span>
|
||||
<span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general[item.hotkeyLangId].custom)}</span>
|
||||
</li>`;
|
||||
});
|
||||
dockHtml = dockHtml + "</ul>";
|
||||
}
|
||||
const dialog = new Dialog({
|
||||
title: window.siyuan.languages.recentDocs,
|
||||
content: `<div class="fn__flex-column switch-doc">
|
||||
<div class="fn__hr"><input style="opacity: 0;height: 1px;box-sizing: border-box"></div>
|
||||
<div class="fn__flex">${dockHtml}
|
||||
<ul${!isWindow() ? "" : ' style="border-left:0"'} class="b3-list b3-list--background fn__flex-1">${tabHtml}</ul>
|
||||
</div>
|
||||
<div class="switch-doc__path"></div>
|
||||
</div>`,
|
||||
destroyCallback: () => {
|
||||
if (range && range.getBoundingClientRect().height !== 0) {
|
||||
focusByRange(range);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (response.data.length > 0) {
|
||||
fetchPost("/api/filetree/getFullHPathByID", {
|
||||
id: response.data[0].rootID
|
||||
}, (response) => {
|
||||
dialog.element.querySelector(".switch-doc__path").innerHTML = escapeHtml(response.data);
|
||||
});
|
||||
} else {
|
||||
dialog.element.querySelector(".switch-doc__path").innerHTML = dialog.element.querySelector(".b3-list-item--focus").textContent;
|
||||
}
|
||||
dialog.element.querySelector("input").focus();
|
||||
dialog.element.setAttribute("data-key", window.siyuan.config.keymap.general.recentDocs.custom);
|
||||
dialog.element.addEventListener("click", (event) => {
|
||||
const liElement = hasClosestByClassName(event.target as HTMLElement, "b3-list-item");
|
||||
if (liElement) {
|
||||
dialog.element.querySelector(".b3-list-item--focus").classList.remove("b3-list-item--focus");
|
||||
liElement.classList.add("b3-list-item--focus");
|
||||
window.dispatchEvent(new KeyboardEvent("keydown", {key: "Enter"}));
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
@ -36,6 +36,7 @@ import {getIdZoomInByPath} from "../util/pathName";
|
|||
import {openHistory} from "../history/history";
|
||||
import {Custom} from "./dock/Custom";
|
||||
import {newCardModel} from "../card/newCardTab";
|
||||
import { openRecentDocs } from "../business/openRecentDocs";
|
||||
|
||||
export const setPanelFocus = (element: Element) => {
|
||||
if (element.classList.contains("layout__tab--active") || element.classList.contains("layout__wnd--active")) {
|
||||
|
|
@ -802,26 +803,82 @@ export const newCenterEmptyTab = () => {
|
|||
<h1>${window.siyuan.languages.noOpenFile}</h1>
|
||||
<div class="fn__hr"></div>
|
||||
<div class="fn__hr"></div>
|
||||
<div class="b3-list-item" id="editorEmptySearch"><svg class="b3-list-item__graphic"><use xlink:href="#iconSearch"></use></svg><span>${window.siyuan.languages.search}</span><span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general.globalSearch.custom)}</span></div>
|
||||
<div class="b3-list-item${window.siyuan.config.readonly ? " fn__none" : ""}" id="editorEmptyFile"><svg class="b3-list-item__graphic"><use xlink:href="#iconFile"></use></svg><span>${window.siyuan.languages.newFile}</span><span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general.newFile.custom)}</span></div>
|
||||
<div class="b3-list-item${window.siyuan.config.readonly ? " fn__none" : ""}" id="editorEmptyNewNotebook"><svg class="b3-list-item__graphic"><use xlink:href="#iconFilesRoot"></use></svg><span>${window.siyuan.languages.newNotebook}</span></div>
|
||||
<div class="b3-list-item" id="editorEmptyHelp"><svg class="b3-list-item__graphic"><use xlink:href="#iconHelp"></use></svg><span>${window.siyuan.languages.help}</span></div>
|
||||
<div class="b3-list-item" id="editorEmptySearch">
|
||||
<svg class="b3-list-item__graphic"><use xlink:href="#iconSearch"></use></svg>
|
||||
<span>${window.siyuan.languages.search}</span>
|
||||
<span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general.globalSearch.custom)}</span>
|
||||
</div>
|
||||
<div id="editorEmptyRecent" class="b3-list-item">
|
||||
<svg class="b3-list-item__graphic"><use xlink:href="#iconList"></use></svg>
|
||||
<span>${window.siyuan.languages.recentDocs}</span>
|
||||
<span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general.recentDocs.custom)}</span>
|
||||
</div>
|
||||
<div id="editorEmptyHistory" class="b3-list-item${window.siyuan.config.readonly ? " fn__none" : ""}">
|
||||
<svg class="b3-list-item__graphic"><use xlink:href="#iconHistory"></use></svg>
|
||||
<span>${window.siyuan.languages.dataHistory}</span>
|
||||
<span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general.dataHistory.custom)}</span>
|
||||
</div>
|
||||
<div class="b3-list-item${window.siyuan.config.readonly ? " fn__none" : ""}" id="editorEmptyFile">
|
||||
<svg class="b3-list-item__graphic"><use xlink:href="#iconFile"></use></svg>
|
||||
<span>${window.siyuan.languages.newFile}</span>
|
||||
<span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general.newFile.custom)}</span>
|
||||
</div>
|
||||
<div class="b3-list-item${window.siyuan.config.readonly ? " fn__none" : ""}" id="editorEmptyNewNotebook">
|
||||
<svg class="b3-list-item__graphic"><use xlink:href="#iconFilesRoot"></use></svg>
|
||||
<span>${window.siyuan.languages.newNotebook}</span>
|
||||
</div>
|
||||
<div class="b3-list-item" id="editorEmptyHelp">
|
||||
<svg class="b3-list-item__graphic"><use xlink:href="#iconHelp"></use></svg>
|
||||
<span>${window.siyuan.languages.help}</span>
|
||||
</div>
|
||||
</div>`,
|
||||
callback(tab: Tab) {
|
||||
tab.panelElement.querySelector("#editorEmptyHelp").addEventListener("click", () => {
|
||||
mountHelp();
|
||||
});
|
||||
tab.panelElement.querySelector("#editorEmptySearch").addEventListener("click", () => {
|
||||
openSearch(window.siyuan.config.keymap.general.globalSearch.custom);
|
||||
});
|
||||
if (!window.siyuan.config.readonly) {
|
||||
tab.panelElement.querySelector("#editorEmptyNewNotebook").addEventListener("click", () => {
|
||||
newNotebook();
|
||||
});
|
||||
tab.panelElement.querySelector("#editorEmptyFile").addEventListener("click", () => {
|
||||
newFile(undefined, undefined, undefined, true);
|
||||
});
|
||||
}
|
||||
tab.panelElement.addEventListener("click", (event) => {
|
||||
let target = event.target as HTMLElement;
|
||||
while (target && !target.isEqualNode( tab.panelElement)) {
|
||||
if (target.id === "editorEmptySearch") {
|
||||
openSearch(window.siyuan.config.keymap.general.globalSearch.custom);
|
||||
event.stopPropagation();
|
||||
event.preventDefault()
|
||||
break;
|
||||
} else if (target.id === "editorEmptyRecent") {
|
||||
const openRecentDocsDialog = window.siyuan.dialogs.find(item => {
|
||||
if (item.element.getAttribute("data-key") === window.siyuan.config.keymap.general.recentDocs.custom) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
if (openRecentDocsDialog) {
|
||||
hideElements(["dialog"]);
|
||||
return;
|
||||
}
|
||||
openRecentDocs();
|
||||
event.stopPropagation();
|
||||
event.preventDefault()
|
||||
break;
|
||||
}else if (target.id === "editorEmptyHistory") {
|
||||
openHistory();
|
||||
event.stopPropagation();
|
||||
event.preventDefault()
|
||||
break;
|
||||
}else if (target.id === "editorEmptyFile") {
|
||||
newFile(undefined, undefined, undefined, true);
|
||||
event.stopPropagation();
|
||||
event.preventDefault()
|
||||
break;
|
||||
}else if (target.id === "editorEmptyNewNotebook") {
|
||||
newNotebook();
|
||||
event.stopPropagation();
|
||||
event.preventDefault()
|
||||
break;
|
||||
}else if (target.id === "editorEmptyHelp") {
|
||||
mountHelp()
|
||||
event.stopPropagation();
|
||||
event.preventDefault()
|
||||
break;
|
||||
}
|
||||
target = target.parentElement
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -22,13 +22,13 @@ export const setEmpty = () => {
|
|||
<div id="emptyRecent" class="b3-list-item">
|
||||
<svg class="b3-list-item__graphic"><use xlink:href="#iconList"></use></svg><span class="b3-list-item__text">${window.siyuan.languages.recentDocs}</span>
|
||||
</div>
|
||||
<div id="emptyHistory" class="b3-list-item">
|
||||
<div id="emptyHistory" class="b3-list-item${window.siyuan.config.readonly ? " fn__none" : ""}">
|
||||
<svg class="b3-list-item__graphic"><use xlink:href="#iconHistory"></use></svg><span class="b3-list-item__text">${window.siyuan.languages.dataHistory}</span>
|
||||
</div>
|
||||
<div id="emptyNewFile" class="b3-list-item${getOpenNotebookCount() > 0 ? "" : " fn__none"}">
|
||||
<div id="emptyNewFile" class="b3-list-item${(getOpenNotebookCount() > 0 || !window.siyuan.config.readonly) ? "" : " fn__none"}">
|
||||
<svg class="b3-list-item__graphic"><use xlink:href="#iconFile"></use></svg><span class="b3-list-item__text">${window.siyuan.languages.newFile}</span>
|
||||
</div>
|
||||
<div class="b3-list-item" id="emptyNewNotebook">
|
||||
<div class="b3-list-item" id="emptyNewNotebook${window.siyuan.config.readonly ? " fn__none" : ""}">
|
||||
<svg class="b3-list-item__graphic"><use xlink:href="#iconFilesRoot"></use></svg><span class="b3-list-item__text">${window.siyuan.languages.newNotebook}</span>
|
||||
</div>
|
||||
<div class="b3-list-item" id="emptyHelp">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue