This commit is contained in:
Vanessa 2023-06-04 00:13:54 +08:00
parent 8e3ebe8fa1
commit abf7b57827
4 changed files with 21 additions and 24 deletions

View file

@ -1,8 +1,6 @@
import {Dialog} from "../dialog"; import {Dialog} from "../dialog";
import {confirmDialog} from "../dialog/confirmDialog"; import {confirmDialog} from "../dialog/confirmDialog";
import {Constants} from "../constants"; import {Constants} from "../constants";
import {hasClosestByClassName} from "../protyle/util/hasClosest";
import {renderAssetsPreview} from "../asset/renderAssets";
import {Protyle} from "../protyle"; import {Protyle} from "../protyle";
import {disabledProtyle, onGet} from "../protyle/util/onGet"; import {disabledProtyle, onGet} from "../protyle/util/onGet";
import * as dayjs from "dayjs"; import * as dayjs from "dayjs";
@ -23,7 +21,7 @@ const renderDoc = (element: HTMLElement, currentPage: number, id: string) => {
previousElement.setAttribute("disabled", "disabled"); previousElement.setAttribute("disabled", "disabled");
} }
const opElement = element.querySelector('.b3-select[data-type="opselect"]') as HTMLSelectElement; const opElement = element.querySelector('.b3-select[data-type="opselect"]') as HTMLSelectElement;
const listElement = element.querySelector('.b3-list--background') const listElement = element.querySelector(".b3-list--background");
element.querySelector('.history__text[data-type="docPanel"]').classList.add("fn__none"); element.querySelector('.history__text[data-type="docPanel"]').classList.add("fn__none");
element.querySelector('.history__text[data-type="mdPanel"]').classList.remove("fn__none"); element.querySelector('.history__text[data-type="mdPanel"]').classList.remove("fn__none");
fetchPost("/api/history/searchHistory", { fetchPost("/api/history/searchHistory", {
@ -126,7 +124,7 @@ export const openDocHistory = (options: {
while (target && !target.isEqualNode(dialog.element)) { while (target && !target.isEqualNode(dialog.element)) {
const type = target.getAttribute("data-type"); const type = target.getAttribute("data-type");
if (type === "close") { if (type === "close") {
dialog.destroy() dialog.destroy();
} else if (type === "rollback" && !isLoading) { } else if (type === "rollback" && !isLoading) {
getHistoryPath(target.parentElement, opElement.value, options.id, (dataPath) => { getHistoryPath(target.parentElement, opElement.value, options.id, (dataPath) => {
isLoading = false; isLoading = false;
@ -181,7 +179,7 @@ export const openDocHistory = (options: {
const getHistoryPath = (target: Element, op: string, id: string, cb: (path: string) => void) => { const getHistoryPath = (target: Element, op: string, id: string, cb: (path: string) => void) => {
isLoading = true; isLoading = true;
const path = target.getAttribute("data-path") const path = target.getAttribute("data-path");
if (path) { if (path) {
cb(path); cb(path);
} }
@ -191,6 +189,6 @@ const getHistoryPath = (target: Element, op: string, id: string, cb: (path: stri
type: 3, type: 3,
created: target.getAttribute("data-created") created: target.getAttribute("data-created")
}, (response) => { }, (response) => {
cb(response.data.items[0].path) cb(response.data.items[0].path);
}); });
} };

View file

@ -282,11 +282,11 @@ const openPlugin = (app: App, target: Element) => {
click() { click() {
if (hasUnpin) { if (hasUnpin) {
window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].splice(window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].indexOf(item.id), 1); window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].splice(window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].indexOf(item.id), 1);
item.classList.remove("fn__none") item.classList.remove("fn__none");
} else { } else {
window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].push(item.id); window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].push(item.id);
window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN] = Array.from(new Set(window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN])); window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN] = Array.from(new Set(window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN]));
item.classList.add("fn__none") item.classList.add("fn__none");
} }
setStorageVal(Constants.LOCAL_PLUGINTOPUNPIN, window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN]); setStorageVal(Constants.LOCAL_PLUGINTOPUNPIN, window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN]);
} }
@ -298,31 +298,31 @@ const openPlugin = (app: App, target: Element) => {
click() { click() {
plugin.openSetting(); plugin.openSetting();
}, },
}) });
} }
const menuOption: IMenu = { const menuOption: IMenu = {
icon: "iconInfo", icon: "iconInfo",
label: item.getAttribute("aria-label"), label: item.getAttribute("aria-label"),
click() { click() {
item.dispatchEvent(new CustomEvent("click")) item.dispatchEvent(new CustomEvent("click"));
}, },
type: "submenu", type: "submenu",
submenu submenu
} };
if (item.querySelector("use")) { if (item.querySelector("use")) {
menuOption.icon = item.querySelector("use").getAttribute("xlink:href").replace("#", ""); menuOption.icon = item.querySelector("use").getAttribute("xlink:href").replace("#", "");
} else { } else {
const svgElement = item.querySelector("svg").cloneNode(true) as HTMLElement; const svgElement = item.querySelector("svg").cloneNode(true) as HTMLElement;
svgElement.classList.add("b3-menu__icon") svgElement.classList.add("b3-menu__icon");
menuOption.iconHTML = svgElement.outerHTML; menuOption.iconHTML = svgElement.outerHTML;
} }
menu.addItem(menuOption); menu.addItem(menuOption);
hasPlugin = true hasPlugin = true;
}) });
}) });
if (hasPlugin) { if (hasPlugin) {
menu.addSeparator() menu.addSeparator();
} }
menu.addItem({ menu.addItem({
icon: "iconSettings", icon: "iconSettings",
@ -336,5 +336,5 @@ const openPlugin = (app: App, target: Element) => {
if (rect.width === 0) { if (rect.width === 0) {
rect = document.querySelector("#barMore").getBoundingClientRect(); rect = document.querySelector("#barMore").getBoundingClientRect();
} }
menu.open({x: rect.right, y: rect.bottom, isLeft: true}) menu.open({x: rect.right, y: rect.bottom, isLeft: true});
} };

View file

@ -43,7 +43,7 @@ export class Setting {
}); });
const contentElement = dialog.element.querySelector(".b3-dialog__content"); const contentElement = dialog.element.querySelector(".b3-dialog__content");
this.items.forEach((item) => { this.items.forEach((item) => {
let html = "" let html = "";
let actionElement = item.actionElement; let actionElement = item.actionElement;
if (!item.actionElement && item.createActionElement) { if (!item.actionElement && item.createActionElement) {
actionElement = item.createActionElement(); actionElement = item.createActionElement();
@ -55,7 +55,7 @@ export class Setting {
${item.description ? `<div class="b3-label__text">${item.description}</div>` : ""} ${item.description ? `<div class="b3-label__text">${item.description}</div>` : ""}
<div class="fn__hr"></div> <div class="fn__hr"></div>
</div> </div>
</label>` </label>`;
} else { } else {
html = `<label class="fn__flex b3-label config__item"> html = `<label class="fn__flex b3-label config__item">
<div class="fn__flex-1"> <div class="fn__flex-1">
@ -63,7 +63,7 @@ export class Setting {
${item.description ? `<div class="b3-label__text">${item.description}</div>` : ""} ${item.description ? `<div class="b3-label__text">${item.description}</div>` : ""}
</div> </div>
<span class="fn__space${actionElement ? "" : " fn__none"}"></span> <span class="fn__space${actionElement ? "" : " fn__none"}"></span>
</label>` </label>`;
} }
contentElement.insertAdjacentHTML("beforeend", html); contentElement.insertAdjacentHTML("beforeend", html);
if (actionElement) { if (actionElement) {
@ -78,7 +78,7 @@ export class Setting {
contentElement.lastElementChild.insertAdjacentElement("beforeend", actionElement); contentElement.lastElementChild.insertAdjacentElement("beforeend", actionElement);
} }
} }
}) });
contentElement.querySelector("input")?.focus(); contentElement.querySelector("input")?.focus();
const btnsElement = dialog.element.querySelectorAll(".b3-dialog__action .b3-button"); const btnsElement = dialog.element.querySelectorAll(".b3-dialog__action .b3-button");
btnsElement[0].addEventListener("click", () => { btnsElement[0].addEventListener("click", () => {

View file

@ -9,7 +9,6 @@ import {Tab} from "../layout/Tab";
import {getDockByType, setPanelFocus} from "../layout/util"; import {getDockByType, setPanelFocus} from "../layout/util";
import {hasClosestByAttribute} from "../protyle/util/hasClosest"; import {hasClosestByAttribute} from "../protyle/util/hasClosest";
import {BlockPanel} from "../block/Panel"; import {BlockPanel} from "../block/Panel";
import {genUUID} from "../util/genID";
import {Setting} from "./Setting"; import {Setting} from "./Setting";
export class Plugin { export class Plugin {