Skip to content

Commit

Permalink
Add attribute "data-key" for Dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
mdzz2048 committed Jan 10, 2024
1 parent 2b6dc09 commit 5305dd6
Show file tree
Hide file tree
Showing 29 changed files with 103 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/src/ai/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const AIActions = (elements: Element[], protyle: IProtyle) => {
</div>`,
width: isMobile() ? "92vw" : "520px",
});
dialog.element.setAttribute("data-key", Constants.DIALOG_AICUSTOMACTION);
const nameElement = dialog.element.querySelector("input");
const customElement = dialog.element.querySelector("textarea");
const btnsElement = dialog.element.querySelectorAll(".b3-button");
Expand Down Expand Up @@ -111,6 +112,7 @@ export const AIActions = (elements: Element[], protyle: IProtyle) => {
</div>`,
width: isMobile() ? "92vw" : "520px",
});
dialog.element.setAttribute("data-key", Constants.DIALOG_AIUPDATECUSTOMACTION);
const nameElement = dialog.element.querySelector("input");
nameElement.value = item.name;
const customElement = dialog.element.querySelector("textarea");
Expand Down
2 changes: 2 additions & 0 deletions app/src/boot/openChangelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {fetchPost} from "../util/fetch";
import {Dialog} from "../dialog";
import {highlightRender} from "../protyle/render/highlightRender";
import {isMobile} from "../util/functions";
import {Constants} from "../constants";

export const openChangelog = () => {
fetchPost("/api/system/getChangelog", {}, (response) => {
Expand All @@ -14,6 +15,7 @@ export const openChangelog = () => {
height: isMobile() ? "80vh" : "70vh",
content: `<div style="overflow:auto;" class="b3-dialog__content b3-typography b3-typography--default">${response.data.html}</div>`
});
dialog.element.setAttribute("data-key", Constants.DIALOG_CHANGELOG);
highlightRender(dialog.element);
});
};
1 change: 1 addition & 0 deletions app/src/config/about.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ export const about = {
</div>`,
width: "520px",
});
passwordDialog.element.setAttribute("data-key", Constants.DIALOG_PASSWORD);
const textAreaElement = passwordDialog.element.querySelector("textarea");
textAreaElement.focus();
const btnsElement = passwordDialog.element.querySelectorAll(".b3-button");
Expand Down
2 changes: 2 additions & 0 deletions app/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {ai} from "./ai";
import {flashcard} from "./flashcard";
import {App} from "../index";
import {isHuawei} from "../protyle/util/compatibility";
import {Constants} from "../constants";

export const genItemPanel = (type: string, containerElement: Element, app: App) => {
switch (type) {
Expand Down Expand Up @@ -137,6 +138,7 @@ export const openSetting = (app: App) => {
width: "90vw",
height: "90vh",
});
dialog.element.setAttribute("data-key", Constants.DIALOG_SETTING);

initConfigSearch(dialog.element, app);
(dialog.element.querySelector(".b3-dialog__container") as HTMLElement).style.maxWidth = "1280px";
Expand Down
2 changes: 2 additions & 0 deletions app/src/config/util/about.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Dialog} from "../../dialog";
import {isMobile} from "../../util/functions";
import {fetchPost} from "../../util/fetch";
import {Constants} from "../../constants";

export const setAccessAuthCode = () => {
const dialog = new Dialog({
Expand All @@ -17,6 +18,7 @@ export const setAccessAuthCode = () => {
});
const inputElement = dialog.element.querySelector("input") as HTMLInputElement;
const btnsElement = dialog.element.querySelectorAll(".b3-button");
dialog.element.setAttribute("data-key", Constants.DIALOG_ACCESSAUTHCODE);
dialog.bindInput(inputElement, () => {
(btnsElement[1] as HTMLButtonElement).click();
});
Expand Down
2 changes: 2 additions & 0 deletions app/src/config/util/snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {fetchPost} from "../../util/fetch";
import {Dialog} from "../../dialog";
import {objEquals} from "../../util/functions";
import {confirmDialog} from "../../dialog/confirmDialog";
import {Constants} from "../../constants";

export const renderSnippet = () => {
fetchPost("/api/snippet/getSnippet", {type: "all", enabled: 2}, (response) => {
Expand Down Expand Up @@ -100,6 +101,7 @@ export const openSnippets = () => {
contentElement.textContent = item.content;
});
const removeIds: string[] = [];
dialog.element.setAttribute("data-key", Constants.DIALOG_SNIPPETS);
dialog.element.addEventListener("click", (event) => {
let target = event.target as HTMLElement;
while (target && !target.isSameNode(dialog.element)) {
Expand Down
46 changes: 46 additions & 0 deletions app/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,52 @@ export abstract class Constants {
public static readonly DIALOG_GLOBALSEARCH = "dialog-globalsearch";
public static readonly DIALOG_HISTORYCOMPARE = "dialog-historycompare";

public static readonly DIALOG_ACCESSAUTHCODE = "dialog-accessauthcode"; // 访问鉴权码
public static readonly DIALOG_AICUSTOMACTION = "dialog-aicustomaction"; // AI 自定义操作
public static readonly DIALOG_AIUPDATECUSTOMACTION = "dialog-aiupdatecustomaction"; // 更新 AI 自定义操作
public static readonly DIALOG_BACKGROUNDLINK = "dialog-backgroundlink"; // 题头图-随机
public static readonly DIALOG_BACKGROUNDRANDOM = "dialog-backgroundrandom"; // 题头图-链接
public static readonly DIALOG_CHANGELOG = "dialog-changelog"; // 更新日志
public static readonly DIALOG_COMMANDPANEL = "dialog-commandpanel"; // 插件命令面板
public static readonly DIALOG_DEACTIVATEUSER = "dialog-deactivateuser"; // 注销账户
public static readonly DIALOG_EMOJIS = "dialog-emojis"; // 文档、笔记本图表
public static readonly DIALOG_EXPORTIMAGE = "dialog-exportimage"; // 导出为图片
public static readonly DIALOG_EXPORTTEMPLATE = "dialog-exporttemplate"; // 导出为模板
public static readonly DIALOG_EXPORTWORD = "dialog-exportword"; // 导出为 word
public static readonly DIALOG_HISTORY = "dialog-history"; // 数据历史(Alt + H)
public static readonly DIALOG_HISTORYDOC = "dialog-historydoc"; // 文档历史
public static readonly DIALOG_MOVEPATHTO = "dialog-movepathto"; // 移动文档
public static readonly DIALOG_RENAME = "dialog-rename"; // 重命名
public static readonly DIALOG_RENAMEASSETS = "dialog-renameassets"; // 重命名资源文件
public static readonly DIALOG_RENAMEBOOKMARK = "dialog-renamebookmark"; // 重命名书签
public static readonly DIALOG_RENAMETAG = "dialog-renametag"; // 重命名标签
public static readonly DIALOG_REPLACETYPE = "dialog-replacetype"; // 替换 - 替换类型
public static readonly DIALOG_SAVECRITERION = "dialog-savecriterion"; // 保存查询条件
public static readonly DIALOG_SEARCHTYPE = "dialog-searchtype"; // 搜索 - 类型
public static readonly DIALOG_SEARCHASSETSTYPE = "dialog-searchassetstype"; // 搜索资源文件 - 类型
public static readonly DIALOG_SETTING = "dialog-setting"; // 设置面板
public static readonly DIALOG_SNAPSHOTTAG = "dialog-snapshottag"; // 标记快照
public static readonly DIALOG_SNAPSHOTMEMO = "dialog-snapshotmemo"; // 快照备注
public static readonly DIALOG_SNIPPETS = "dialog-snippets"; // 代码片段
public static readonly DIALOG_SYNCADDCLOUDDIR = "dialog-syncaddclouddir"; // 新建云端同步目录
public static readonly DIALOG_SYNCCHOOSEDIR = "dialog-syncchoosedir"; // 选择云端同步目录
public static readonly DIALOG_SYNCCHOOSEDIRECTION = "dialog-syncchoosedirection"; // 选择云端同步方向
public static readonly DIALOG_TRANSFERBLOCKREF = "dialog-transferblockref"; // 转移引用
public static readonly DIALOG_WECHATREMINDER = "dialog-wechatreminder"; // 微信提醒

public static readonly DIALOG_PASSWORD = "dialog-password"; // 导入同步密钥
public static readonly DIALOG_SETPASSWORD = "dialog-setpassword"; // 设置同步密钥
public static readonly DIALOG_BOOTSYNCFAILED = "dialog-bootsyncfailed"; // 启动时同步数据失败
public static readonly DIALOG_KERNELFAULT = "dialog-kernelfault"; // 内核退出
public static readonly DIALOG_STATEEXCEPTED = "dialog-stateexcepted"; // 状态异常
public static readonly DIALOG_ATTR = "dialog-attr"; // 设置块属性
public static readonly DIALOG_SETCUSTOMATTR = "dialog-setcustomattr"; // 设置自定义属性
public static readonly DIALOG_CREATENOTEBOOK = "dialog-createnotebook"; // 创建笔记本
public static readonly DIALOG_NOTEBOOKCONF = "dialog-notebookconf"; // 笔记本设置
public static readonly DIALOG_CREATEWORKSPACE = "dialog-createworkspace"; // 创建工作空间
public static readonly DIALOG_OPENWORKSPACE = "dialog-openworkspace"; // 打开工作空间
public static readonly DIALOG_SAVEWORKSPACE = "dialog-saveworkspace"; // 保存工作空间

// timeout
public static readonly TIMEOUT_DBLCLICK = 190;
public static readonly TIMEOUT_INPUT = 256;
Expand Down
3 changes: 3 additions & 0 deletions app/src/dialog/processSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export const kernelError = () => {
</div>`
});
dialog.element.id = "errorLog";
dialog.element.setAttribute("data-key", Constants.DIALOG_ERRORKERNELFAULT);
const restartElement = dialog.element.querySelector(".b3-button");
if (restartElement) {
restartElement.addEventListener("click", () => {
Expand Down Expand Up @@ -257,6 +258,7 @@ export const transactionError = () => {
</div>`,
width: isMobile() ? "92vw" : "520px",
});
dialog.element.setAttribute("data-key", Constants.DIALOG_ERRORSTATEEXCEPTED);
const btnsElement = dialog.element.querySelectorAll(".b3-button");
btnsElement[0].addEventListener("click", () => {
/// #if MOBILE
Expand Down Expand Up @@ -355,6 +357,7 @@ export const bootSync = () => {
<button class="b3-button b3-button--text">${window.siyuan.languages.syncNow}</button>
</div>`
});
dialog.element.setAttribute("data-key", Constants.DIALOG_ERRORBOOTSYNCFAILED);
const btnsElement = dialog.element.querySelectorAll(".b3-button");
btnsElement[0].addEventListener("click", () => {
dialog.destroy();
Expand Down
2 changes: 2 additions & 0 deletions app/src/editor/rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const rename = (options: {
}
}
});
dialog.element.setAttribute("data-key", Constants.DIALOG_RENAME);
const inputElement = dialog.element.querySelector("input") as HTMLInputElement;
const btnsElement = dialog.element.querySelectorAll(".b3-button");
dialog.bindInput(inputElement, () => {
Expand Down Expand Up @@ -113,6 +114,7 @@ export const renameAsset = (assetPath: string) => {
</div>`,
width: isMobile() ? "92vw" : "520px",
});
dialog.element.setAttribute("data-key", Constants.DIALOG_RENAMEASSETS);
const inputElement = dialog.element.querySelector("input") as HTMLInputElement;
const btnsElement = dialog.element.querySelectorAll(".b3-button");
dialog.bindInput(inputElement, () => {
Expand Down
1 change: 1 addition & 0 deletions app/src/emoji/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export const openEmojiPanel = (id: string, type: "doc" | "notebook" | "av", posi
</div>
</div>`
});
dialog.element.setAttribute("data-key", Constants.DIALOG_EMOJIS);
dialog.element.querySelector(".b3-dialog__container").setAttribute("data-menu", "true");
const dialogElement = dialog.element.querySelector(".b3-dialog") as HTMLElement;
dialogElement.style.justifyContent = "inherit";
Expand Down
1 change: 1 addition & 0 deletions app/src/history/doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const openDocHistory = (options: {
historyEditor = undefined;
}
});
dialog.element.setAttribute("data-key", Constants.DIALOG_HISTORYDOC);

const opElement = dialog.element.querySelector(".b3-select") as HTMLSelectElement;
opElement.addEventListener("change", () => {
Expand Down
3 changes: 3 additions & 0 deletions app/src/history/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ export const openHistory = (app: App) => {
historyEditor = undefined;
}
});
dialog.element.setAttribute("data-key", Constants.DIALOG_HISTORY);
bindEvent(app, dialog.element, dialog);
}
};
Expand Down Expand Up @@ -647,6 +648,7 @@ const bindEvent = (app: App, element: Element, dialog?: Dialog) => {
</div>`,
width: isMobile() ? "92vw" : "520px",
});
genRepoDialog.element.setAttribute("data-key", Constants.DIALOG_SNAPSHOTMEMO);
const textareaElement = genRepoDialog.element.querySelector("textarea");
textareaElement.focus();
const btnsElement = genRepoDialog.element.querySelectorAll(".b3-button");
Expand Down Expand Up @@ -704,6 +706,7 @@ const bindEvent = (app: App, element: Element, dialog?: Dialog) => {
</div>`,
width: isMobile() ? "92vw" : "520px",
});
genTagDialog.element.setAttribute("data-key", Constants.DIALOG_SNAPSHOTTAG);
const inputElement = genTagDialog.element.querySelector(".b3-text-field") as HTMLInputElement;
inputElement.select();
const btnsElement = genTagDialog.element.querySelectorAll(".b3-button");
Expand Down
2 changes: 2 additions & 0 deletions app/src/menus/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {MenuItem} from "./Menu";
import {Dialog} from "../dialog";
import {isMobile} from "../util/functions";
import {fetchPost} from "../util/fetch";
import {Constants} from "../constants";

export const transferBlockRef = (id: string) => {
window.siyuan.menus.menu.append(new MenuItem({
Expand All @@ -20,6 +21,7 @@ export const transferBlockRef = (id: string) => {
</div>`,
width: isMobile() ? "92vw" : "520px",
});
renameDialog.element.setAttribute("data-key", Constants.DIALOG_TRANSFERBLOCKREF);
const inputElement = renameDialog.element.querySelector("input") as HTMLInputElement;
const btnsElement = renameDialog.element.querySelectorAll(".b3-button");
renameDialog.bindInput(inputElement, () => {
Expand Down
2 changes: 2 additions & 0 deletions app/src/menus/bookmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {copySubMenu} from "./commonMenuItem";
import {Bookmark} from "../layout/dock/Bookmark";
import {isMobile} from "../util/functions";
import {MobileBookmarks} from "../mobile/dock/MobileBookmarks";
import {Constants} from "../constants";

export const openBookmarkMenu = (element: HTMLElement, event: MouseEvent, bookmarkObj: Bookmark | MobileBookmarks) => {
if (!window.siyuan.menus.menu.element.classList.contains("fn__none") &&
Expand All @@ -31,6 +32,7 @@ export const openBookmarkMenu = (element: HTMLElement, event: MouseEvent, bookma
</div>`,
width: isMobile() ? "92vw" : "520px",
});
dialog.element.setAttribute("data-key", Constants.DIALOG_RENAMEBOOKMARK);
const btnsElement = dialog.element.querySelectorAll(".b3-button");
btnsElement[0].addEventListener("click", () => {
dialog.destroy();
Expand Down
5 changes: 5 additions & 0 deletions app/src/menus/commonMenuItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const openWechatNotify = (nodeElement: Element) => {
focusByRange(range);
}
});
dialog.element.setAttribute("data-key", Constants.DIALOG_WECHATREMINDER);
const btnsElement = dialog.element.querySelectorAll(".b3-button");
btnsElement[0].addEventListener("click", () => {
dialog.destroy();
Expand Down Expand Up @@ -120,6 +121,7 @@ export const openFileWechatNotify = (protyle: IProtyle) => {
<button class="b3-button b3-button--text">${window.siyuan.languages.confirm}</button>
</div>`
});
dialog.element.setAttribute("data-key", Constants.DIALOG_WECHATREMINDER);
const btnsElement = dialog.element.querySelectorAll(".b3-button");
btnsElement[0].addEventListener("click", () => {
dialog.destroy();
Expand Down Expand Up @@ -240,6 +242,7 @@ export const openFileAttr = (attrs: IObject, focusName = "bookmark", protyle?: I
focusByRange(range);
}
});
dialog.element.setAttribute("data-key", Constants.DIALOG_ATTR);
(dialog.element.querySelector('.b3-text-field[data-name="bookmark"]') as HTMLInputElement).value = attrs.bookmark || "";
(dialog.element.querySelector('.b3-text-field[data-name="name"]') as HTMLInputElement).value = attrs.name || "";
(dialog.element.querySelector('.b3-text-field[data-name="alias"]') as HTMLInputElement).value = attrs.alias || "";
Expand Down Expand Up @@ -309,6 +312,7 @@ export const openFileAttr = (attrs: IObject, focusName = "bookmark", protyle?: I
</div>`,
width: isMobile() ? "92vw" : "520px",
});
addDialog.element.setAttribute("data-key", Constants.DIALOG_SETCUSTOMATTR);
const inputElement = addDialog.element.querySelector("input") as HTMLInputElement;
const btnsElement = addDialog.element.querySelectorAll(".b3-button");
addDialog.bindInput(inputElement, () => {
Expand Down Expand Up @@ -452,6 +456,7 @@ export const exportMd = (id: string) => {
</div>`,
width: isMobile() ? "92vw" : "520px",
});
dialog.element.setAttribute("data-key", Constants.DIALOG_EXPORTTEMPLATE);
const inputElement = dialog.element.querySelector("input") as HTMLInputElement;
const btnsElement = dialog.element.querySelectorAll(".b3-button");
dialog.bindInput(inputElement, () => {
Expand Down
2 changes: 2 additions & 0 deletions app/src/menus/onGetnotebookconf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {escapeHtml} from "../util/escape";
import {writeText} from "../protyle/util/compatibility";
import {showMessage} from "../dialog/message";
import {openModel} from "../mobile/menu/model";
import {Constants} from "../constants";

declare interface INotebookConf {
name: string,
Expand Down Expand Up @@ -64,6 +65,7 @@ export const onGetnotebookconf = (data: INotebookConf) => {
content: contentHTML
});
contentElement = dialog.element;
contentElement.setAttribute("data-key", Constants.DIALOG_NOTEBOOKCONF);
bindSettingEvent(contentElement, data);
}
};
Expand Down
3 changes: 3 additions & 0 deletions app/src/menus/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const workspaceMenu = (app: App, rect: DOMRect) => {
</div>`,
width: "520px",
});
createWorkspaceDialog.element.setAttribute("data-key", Constants.DIALOG_CREATEWORKSPACE);
const inputElement = createWorkspaceDialog.element.querySelector("input");
inputElement.focus();
const btnsElement = createWorkspaceDialog.element.querySelectorAll(".b3-button");
Expand Down Expand Up @@ -159,6 +160,7 @@ export const workspaceMenu = (app: App, rect: DOMRect) => {
</div>`,
width: "520px",
});
openWorkspaceDialog.element.setAttribute("data-key", Constants.DIALOG_OPENWORKSPACE);
const btnsElement = openWorkspaceDialog.element.querySelectorAll(".b3-button");
btnsElement[0].addEventListener("click", () => {
openWorkspaceDialog.destroy();
Expand Down Expand Up @@ -235,6 +237,7 @@ export const workspaceMenu = (app: App, rect: DOMRect) => {
</div>`,
width: "520px",
});
saveDialog.element.setAttribute("data-key", Constants.DIALOG_SAVEWORKSPACE);
const btnsElement = saveDialog.element.querySelectorAll(".b3-button");
saveDialog.bindInput(saveDialog.element.querySelector("input"), () => {
btnsElement[1].dispatchEvent(new CustomEvent("click"));
Expand Down
Loading

0 comments on commit 5305dd6

Please sign in to comment.