diff --git a/app/src/protyle/render/av/openMenuPanel.ts b/app/src/protyle/render/av/openMenuPanel.ts index bba64b6f3..1d43a371d 100644 --- a/app/src/protyle/render/av/openMenuPanel.ts +++ b/app/src/protyle/render/av/openMenuPanel.ts @@ -30,7 +30,8 @@ export const openMenuPanel = (options: { blockElement: Element, type: "select" | "properties" | "config" | "sorts" | "filters" | "edit" | "date" | "asset", colId?: string, // for edit - cellElements?: HTMLElement[] // for select & date + cellElements?: HTMLElement[], // for select & date + cb?: (avPanelElement: Element) => void }) => { let avPanelElement = document.querySelector(".av__panel"); if (avPanelElement) { @@ -97,6 +98,9 @@ export const openMenuPanel = (options: { bindViewEvent({protyle: options.protyle, data, menuElement}); } } + if (options.cb) { + options.cb(avPanelElement); + } avPanelElement.addEventListener("dragstart", (event: DragEvent) => { window.siyuan.dragElement = event.target as HTMLElement; window.siyuan.dragElement.style.opacity = ".1"; diff --git a/app/src/protyle/render/av/render.ts b/app/src/protyle/render/av/render.ts index ceade5329..de25c5e35 100644 --- a/app/src/protyle/render/av/render.ts +++ b/app/src/protyle/render/av/render.ts @@ -52,11 +52,17 @@ export const avRender = (element: Element, protyle: IProtyle, cb?: () => void, v } const created = protyle.options.history?.created; const snapshot = protyle.options.history?.snapshot; + let newViewID = ""; + if (typeof viewID === "string") { + newViewID = viewID; + } else if (typeof viewID === "undefined") { + newViewID = e.querySelector(".av__header .item--focus")?.getAttribute("data-id") + } fetchPost(created ? "/api/av/renderHistoryAttributeView" : (snapshot ? "/api/av/renderSnapshotAttributeView" : "/api/av/renderAttributeView"), { id: e.getAttribute("data-av-id"), created, snapshot, - viewID: viewID || e.querySelector(".av__header .item--focus")?.getAttribute("data-id") + viewID: newViewID }, (response) => { const data = response.data.view as IAVTable; // header @@ -322,7 +328,8 @@ export const refreshAV = (protyle: IProtyle, operation: IOperation, isUndo: bool if (!isUndo && operation.action === "insertAttrViewBlock" && operation.isDetached) { popTextCell(protyle, [item.querySelector(`.av__row[data-id="${operation.srcIDs[0]}"] .av__cell[data-detached="true"]`)], "block"); } - }); + }, ["addAttrViewView", "duplicateAttrViewView"].includes(operation.action) ? operation.id : + (operation.action === "removeAttrViewView" ? null : undefined)); }); } diff --git a/app/src/protyle/render/av/view.ts b/app/src/protyle/render/av/view.ts index e358ba8ab..f36082368 100644 --- a/app/src/protyle/render/av/view.ts +++ b/app/src/protyle/render/av/view.ts @@ -15,8 +15,14 @@ export const openViewMenu = (options: { protyle: IProtyle, blockElement: HTMLEle icon: "iconEdit", label: window.siyuan.languages.rename, click() { - openMenuPanel({protyle: options.protyle, blockElement: options.blockElement, type: "config"}); - (document.querySelector('.av__panel .b3-text-field[data-type="name"]') as HTMLInputElement).focus() + openMenuPanel({ + protyle: options.protyle, + blockElement: options.blockElement, + type: "config", + cb: (avPanelElement) => { + (avPanelElement.querySelector('.b3-text-field[data-type="name"]') as HTMLInputElement).focus() + } + }); } }) menu.addItem({