mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 01:20:12 +01:00
This commit is contained in:
parent
16216796b6
commit
17fc039ad5
5 changed files with 111 additions and 2 deletions
|
|
@ -302,7 +302,7 @@ export const bazaar = {
|
||||||
app.plugins.find((item: Plugin) => {
|
app.plugins.find((item: Plugin) => {
|
||||||
if (item.name === dataObj.name) {
|
if (item.name === dataObj.name) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
hasSetting = item.__proto__.hasOwnProperty("openSetting");
|
hasSetting = item.setting || item.__proto__.hasOwnProperty("openSetting");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import {newCardModel} from "../card/newCardTab";
|
||||||
import {App} from "../index";
|
import {App} from "../index";
|
||||||
import {Constants} from "../constants";
|
import {Constants} from "../constants";
|
||||||
import {Model} from "../layout/Model";
|
import {Model} from "../layout/Model";
|
||||||
|
import {Setting} from "./Setting";
|
||||||
|
|
||||||
export class Menu {
|
export class Menu {
|
||||||
private menu: SiyuanMenu;
|
private menu: SiyuanMenu;
|
||||||
|
|
@ -208,4 +209,5 @@ export const API = {
|
||||||
Plugin,
|
Plugin,
|
||||||
Dialog,
|
Dialog,
|
||||||
Menu,
|
Menu,
|
||||||
|
Setting
|
||||||
};
|
};
|
||||||
|
|
|
||||||
94
app/src/plugin/Setting.ts
Normal file
94
app/src/plugin/Setting.ts
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
import {isMobile} from "../util/functions";
|
||||||
|
import {Dialog} from "../dialog";
|
||||||
|
|
||||||
|
export class Setting {
|
||||||
|
private items: IPluginSettingOption[] = [];
|
||||||
|
private confirmCallback: () => void;
|
||||||
|
private destroyCallback: () => void;
|
||||||
|
private width: string;
|
||||||
|
private height: string;
|
||||||
|
|
||||||
|
constructor(options: {
|
||||||
|
height?: string,
|
||||||
|
width?: string,
|
||||||
|
destroyCallback?: () => void
|
||||||
|
confirmCallback?: () => void
|
||||||
|
}) {
|
||||||
|
this.confirmCallback = options.confirmCallback;
|
||||||
|
this.width = options.width || (isMobile() ? "92vw" : "768px");
|
||||||
|
this.height = options.height || "80vh";
|
||||||
|
}
|
||||||
|
|
||||||
|
public addItem(options: IPluginSettingOption) {
|
||||||
|
this.items.push(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
public open(name: string) {
|
||||||
|
const dialog = new Dialog({
|
||||||
|
title: name,
|
||||||
|
content: `<div class="b3-dialog__content">
|
||||||
|
</div>
|
||||||
|
<div class="b3-dialog__action${this.confirmCallback ? "" : " fn__none"}">
|
||||||
|
<button class="b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button>
|
||||||
|
<div class="fn__space${this.confirmCallback ? "" : " fn__none"}"></div>
|
||||||
|
<button class="b3-button b3-button--text${this.confirmCallback ? "" : " fn__none"}">${window.siyuan.languages.save}</button>
|
||||||
|
</div>`,
|
||||||
|
width: this.width,
|
||||||
|
height: this.height,
|
||||||
|
destroyCallback: () => {
|
||||||
|
if (this.destroyCallback) {
|
||||||
|
this.destroyCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const contentElement = dialog.element.querySelector(".b3-dialog__content");
|
||||||
|
this.items.forEach((item) => {
|
||||||
|
let html = ""
|
||||||
|
let actionElement = item.actionElement;
|
||||||
|
if (!item.actionElement && item.createActionElement) {
|
||||||
|
actionElement = item.createActionElement();
|
||||||
|
}
|
||||||
|
if (actionElement && actionElement.tagName === "TEXTAREA") {
|
||||||
|
html = `<label class="b3-label fn__flex">
|
||||||
|
<div class="fn__flex-1">
|
||||||
|
${item.title}
|
||||||
|
${item.description ? `<div class="b3-label__text">${item.description}</div>` : ""}
|
||||||
|
<div class="fn__hr"></div>
|
||||||
|
</div>
|
||||||
|
</label>`
|
||||||
|
} else {
|
||||||
|
html = `<label class="fn__flex b3-label config__item">
|
||||||
|
<div class="fn__flex-1">
|
||||||
|
${item.title}
|
||||||
|
${item.description ? `<div class="b3-label__text">${item.description}</div>` : ""}
|
||||||
|
</div>
|
||||||
|
<span class="fn__space${actionElement ? "" : " fn__none"}"></span>
|
||||||
|
</label>`
|
||||||
|
}
|
||||||
|
contentElement.insertAdjacentHTML("beforeend", html);
|
||||||
|
if (actionElement) {
|
||||||
|
if (["INPUT", "TEXTAREA"].includes(actionElement.tagName)) {
|
||||||
|
dialog.bindInput(actionElement as HTMLInputElement, () => {
|
||||||
|
(btnsElement[1] as HTMLButtonElement).click();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (actionElement.tagName === "TEXTAREA") {
|
||||||
|
contentElement.lastElementChild.lastElementChild.insertAdjacentElement("beforeend", actionElement);
|
||||||
|
} else {
|
||||||
|
contentElement.lastElementChild.insertAdjacentElement("beforeend", actionElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
contentElement.querySelector("input")?.focus();
|
||||||
|
const btnsElement = dialog.element.querySelectorAll(".b3-dialog__action .b3-button");
|
||||||
|
btnsElement[0].addEventListener("click", () => {
|
||||||
|
dialog.destroy();
|
||||||
|
});
|
||||||
|
btnsElement[1].addEventListener("click", () => {
|
||||||
|
if (this.confirmCallback) {
|
||||||
|
this.confirmCallback();
|
||||||
|
}
|
||||||
|
dialog.destroy();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,7 @@ 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 {genUUID} from "../util/genID";
|
||||||
|
import {Setting} from "./Setting";
|
||||||
|
|
||||||
export class Plugin {
|
export class Plugin {
|
||||||
private app: App;
|
private app: App;
|
||||||
|
|
@ -18,6 +19,7 @@ export class Plugin {
|
||||||
public data: any = {};
|
public data: any = {};
|
||||||
public name: string;
|
public name: string;
|
||||||
public topBarIcons: Element[] = [];
|
public topBarIcons: Element[] = [];
|
||||||
|
public setting: Setting;
|
||||||
public statusBarIcons: Element[] = [];
|
public statusBarIcons: Element[] = [];
|
||||||
public commands: ICommand[] = [];
|
public commands: ICommand[] = [];
|
||||||
public models: {
|
public models: {
|
||||||
|
|
@ -103,7 +105,10 @@ export class Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public openSetting() {
|
public openSetting() {
|
||||||
// 打开设置
|
if (!this.setting) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.setting.open(this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public loadData(storageName: string) {
|
public loadData(storageName: string) {
|
||||||
|
|
|
||||||
8
app/src/types/index.d.ts
vendored
8
app/src/types/index.d.ts
vendored
|
|
@ -83,6 +83,14 @@ interface ICard {
|
||||||
nextDues: IObject
|
nextDues: IObject
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IPluginSettingOption {
|
||||||
|
title: string
|
||||||
|
description?: string
|
||||||
|
actionElement?: HTMLElement
|
||||||
|
|
||||||
|
createActionElement?(): HTMLElement
|
||||||
|
}
|
||||||
|
|
||||||
interface ISearchOption {
|
interface ISearchOption {
|
||||||
page: number
|
page: number
|
||||||
removed?: boolean // 移除后需记录搜索内容 https://github.com/siyuan-note/siyuan/issues/7745
|
removed?: boolean // 移除后需记录搜索内容 https://github.com/siyuan-note/siyuan/issues/7745
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue