2023-01-16 21:33:20 +08:00
|
|
|
import {Dialog} from "../dialog";
|
|
|
|
|
import {fetchPost} from "./fetch";
|
|
|
|
|
import {isMobile} from "./functions";
|
2023-12-12 12:09:31 +08:00
|
|
|
import {Constants} from "../constants";
|
2024-09-29 22:08:49 +08:00
|
|
|
import {pathPosix} from "./pathName";
|
2025-03-26 22:44:05 +08:00
|
|
|
/// #if !MOBILE
|
|
|
|
|
import {getDockByType} from "../layout/tabUtil";
|
|
|
|
|
import {Files} from "../layout/dock/Files";
|
|
|
|
|
/// #endif
|
2023-01-16 21:33:20 +08:00
|
|
|
|
|
|
|
|
// 需独立出来,否则移动端引用的时候会引入 pc 端大量无用代码
|
|
|
|
|
export const renameTag = (labelName: string) => {
|
|
|
|
|
const dialog = new Dialog({
|
|
|
|
|
title: window.siyuan.languages.rename,
|
|
|
|
|
content: `<div class="b3-dialog__content"><input class="b3-text-field fn__block" value="${labelName}"></div>
|
|
|
|
|
<div class="b3-dialog__action">
|
|
|
|
|
<button class="b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button><div class="fn__space"></div>
|
|
|
|
|
<button class="b3-button b3-button--text">${window.siyuan.languages.confirm}</button>
|
|
|
|
|
</div>`,
|
2024-05-29 11:17:20 +08:00
|
|
|
width: isMobile() ? "92vw" : "520px",
|
2023-01-16 21:33:20 +08:00
|
|
|
});
|
2024-01-10 22:31:28 +08:00
|
|
|
dialog.element.setAttribute("data-key", Constants.DIALOG_RENAMETAG);
|
2023-01-16 21:33:20 +08:00
|
|
|
const btnsElement = dialog.element.querySelectorAll(".b3-button");
|
|
|
|
|
btnsElement[0].addEventListener("click", () => {
|
|
|
|
|
dialog.destroy();
|
|
|
|
|
});
|
|
|
|
|
const inputElement = dialog.element.querySelector("input");
|
|
|
|
|
dialog.bindInput(inputElement, () => {
|
|
|
|
|
(btnsElement[1] as HTMLButtonElement).click();
|
|
|
|
|
});
|
|
|
|
|
inputElement.focus();
|
|
|
|
|
inputElement.select();
|
|
|
|
|
btnsElement[1].addEventListener("click", () => {
|
|
|
|
|
fetchPost("/api/tag/renameTag", {oldLabel: labelName, newLabel: inputElement.value});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getWorkspaceName = () => {
|
2024-09-29 22:08:49 +08:00
|
|
|
return pathPosix().basename(window.siyuan.config.system.workspaceDir.replace(/\\/g, "/"));
|
2023-01-16 21:33:20 +08:00
|
|
|
};
|
2023-12-12 12:09:31 +08:00
|
|
|
|
2024-10-23 11:47:06 +08:00
|
|
|
export const checkFold = (id: string, cb: (zoomIn: boolean, action: TProtyleAction[], isRoot: boolean) => void) => {
|
2023-12-12 12:09:31 +08:00
|
|
|
if (!id) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
2024-05-29 11:17:20 +08:00
|
|
|
cb(foldResponse.data.isFolded,
|
|
|
|
|
foldResponse.data.isFolded ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],
|
|
|
|
|
foldResponse.data.isRoot);
|
2023-12-12 12:09:31 +08:00
|
|
|
});
|
|
|
|
|
};
|
2025-03-26 22:44:05 +08:00
|
|
|
|
|
|
|
|
export const setLocalShorthandCount = () => {
|
|
|
|
|
let fileElement;
|
|
|
|
|
/// #if MOBILE
|
|
|
|
|
fileElement = window.siyuan.mobile.docks.file.element;
|
|
|
|
|
/// #else
|
|
|
|
|
const dockFile = getDockByType("file");
|
|
|
|
|
if (!dockFile) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
fileElement = (dockFile.data.file as Files).element;
|
|
|
|
|
/// #endif
|
2025-03-27 20:31:45 +08:00
|
|
|
const helpIDs: string[] = [];
|
|
|
|
|
Object.keys(Constants.HELP_PATH).forEach((key) => {
|
|
|
|
|
helpIDs.push(Constants.HELP_PATH[key]);
|
|
|
|
|
});
|
2025-03-26 22:44:05 +08:00
|
|
|
fileElement.childNodes.forEach((item: Element) => {
|
2025-03-27 20:31:45 +08:00
|
|
|
if (item.querySelector('[data-type="addLocal"]') || helpIDs.includes(item.getAttribute("data-url"))) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-03-26 22:44:05 +08:00
|
|
|
item.querySelector('[data-type="more-root"]').insertAdjacentHTML("beforebegin", `<span data-type="addLocal" class="b3-list-item__action">
|
|
|
|
|
<svg><use xlink:href="#iconRiffCard"></use></svg>
|
|
|
|
|
</span>`);
|
|
|
|
|
});
|
2025-03-27 23:26:42 +08:00
|
|
|
};
|