diff --git a/app/src/menus/commonMenuItem.ts b/app/src/menus/commonMenuItem.ts index 09c0a6ea4..115d436f0 100644 --- a/app/src/menus/commonMenuItem.ts +++ b/app/src/menus/commonMenuItem.ts @@ -257,7 +257,7 @@ export const openFileAttr = (attrs: IObject, focusName = "bookmark", protyle?: I dialog.element.addEventListener("click", (event) => { let target = event.target as HTMLElement; if (typeof event.detail === "string") { - target = dialog.element.querySelector('.item--full[data-type="NodeAttributeView"]'); + target = dialog.element.querySelector(`.item--full[data-type="${event.detail}"]`); } while (!target.isSameNode(dialog.element)) { const type = target.dataset.action; @@ -358,13 +358,15 @@ export const openFileAttr = (attrs: IObject, focusName = "bookmark", protyle?: I } }); dialog.element.querySelectorAll(".b3-text-field").forEach((item: HTMLInputElement) => { - if (focusName !== "av" && focusName === item.getAttribute("data-name")) { + if (focusName !== "av" && focusName !== "custom" && focusName === item.getAttribute("data-name")) { item.focus(); } bindAttrInput(item, attrs.id); }); if (focusName === "av") { - dialog.element.dispatchEvent(new CustomEvent("click", {detail: "av"})); + dialog.element.dispatchEvent(new CustomEvent("click", {detail: "NodeAttributeView"})); + } else if (focusName === "custom") { + dialog.element.dispatchEvent(new CustomEvent("click", {detail: "custom"})); } }; diff --git a/app/src/plugin/API.ts b/app/src/plugin/API.ts index 6d6eac746..eba1bbd25 100644 --- a/app/src/plugin/API.ts +++ b/app/src/plugin/API.ts @@ -22,6 +22,7 @@ import {Model} from "../layout/Model"; import {getDockByType} from "../layout/tabUtil"; import {getAllEditor, getAllModels} from "../layout/getAll"; import {openSetting} from "../config"; +import {openAttr, openFileAttr} from "../menus/commonMenuItem"; let openTab; let openWindow; @@ -177,6 +178,19 @@ const getModelByDockType = (type: TDock | string) => { /// #endif }; +const openAttributePanel = (options: { + data?: IObject // 块属性值 + nodeElement?: HTMLElement, // 块元素 + focusName: "bookmark" | "name" | "alias" | "memo" | "av" | "custom", // av 为数据库页签,custom 为自定义页签,其余为内置输入框 + protyle?: IProtyle, // 有数据库时需要传入 protyle +}) => { + if (options.data) { + openFileAttr(options.data, options.focusName, options.protyle); + } else { + openAttr(options.nodeElement, options.focusName, options.protyle); + } +}; + export const API = { adaptHotkey: updateHotkeyTip, confirm: confirmDialog, @@ -201,5 +215,6 @@ export const API = { getAllEditor, getAllModels, platformUtils, - openSetting + openSetting, + openAttributePanel, };