From 872191d0782cfb03ccb3ab483cb37c3176f1c1e2 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sun, 1 Feb 2026 17:37:57 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/11569 --- app/src/config/image.ts | 37 +++++++++++++++++++++++++---- app/src/config/index.ts | 2 +- app/src/history/history.ts | 2 +- app/src/mobile/menu/index.ts | 4 ++-- app/src/mobile/settings/assets.ts | 5 ++-- app/src/protyle/render/av/action.ts | 2 +- app/src/protyle/render/av/render.ts | 14 +++++------ 7 files changed, 47 insertions(+), 19 deletions(-) diff --git a/app/src/config/image.ts b/app/src/config/image.ts index 4c1825c73..12cbec2ef 100644 --- a/app/src/config/image.ts +++ b/app/src/config/image.ts @@ -12,8 +12,11 @@ import {openBy} from "../editor/util"; import {renderAssetsPreview} from "../asset/renderAssets"; import {writeText} from "../protyle/util/compatibility"; import {Constants} from "../constants"; -import {avRender} from "../protyle/render/av/render"; import {showMessage} from "../dialog/message"; +import {Protyle} from "../protyle"; +import {App} from "../index"; +import {disabledProtyle, onGet} from "../protyle/util/onGet"; +import {removeLoading} from "../protyle/ui/initUI"; export const image = { element: undefined as Element, @@ -78,9 +81,22 @@ export const image = { `; }, - bindEvent: () => { + bindEvent: (app: App) => { const assetsListElement = image.element.querySelector('.config-assets[data-type="remove"] .config-assets__list'); const avListElement = image.element.querySelector('.config-assets[data-type="removeAV"] .config-assets__list'); + const editor = new Protyle(app, avListElement.nextElementSibling as HTMLElement, { + blockId: "", + action: [Constants.CB_GET_HISTORY], + render: { + background: false, + gutter: false, + breadcrumb: false, + breadcrumbDocName: false, + }, + typewriterMode: false, + }); + disabledProtyle(editor.protyle); + removeLoading(editor.protyle); image.element.addEventListener("click", (event) => { let target = event.target as HTMLElement; while (target && !target.isEqualNode(image.element)) { @@ -138,14 +154,25 @@ export const image = { event.stopPropagation(); break; } else if (target.getAttribute("data-tab-type") === "unRefAV") { - avListElement.nextElementSibling.innerHTML = `
${Constants.ZWSP}
`; - avRender(avListElement.nextElementSibling.firstElementChild, null); + onGet({ + data: { + data: { + content: `
${Constants.ZWSP}
`, + id: Lute.NewNodeID(), + rootID: Lute.NewNodeID(), + }, + msg: "", + code: 0 + }, + protyle: editor.protyle, + action: [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML], + }); event.preventDefault(); event.stopPropagation(); break; } else if (type === "copy") { if (target.parentElement.getAttribute("data-tab-type") === "unRefAV") { - writeText(`
`); + writeText(`
`); } else { writeText(target.parentElement.querySelector(".b3-list-item__text").textContent.trim()); } diff --git a/app/src/config/index.ts b/app/src/config/index.ts index 84c82e367..8b1e6a168 100644 --- a/app/src/config/index.ts +++ b/app/src/config/index.ts @@ -43,7 +43,7 @@ export const genItemPanel = (type: string, containerElement: Element, app: App) case "image": containerElement.innerHTML = image.genHTML(); image.element = containerElement; - image.bindEvent(); + image.bindEvent(app); break; case "export": containerElement.innerHTML = exportConfig.genHTML(); diff --git a/app/src/history/history.ts b/app/src/history/history.ts index fe26dafcd..82395b89c 100644 --- a/app/src/history/history.ts +++ b/app/src/history/history.ts @@ -753,7 +753,7 @@ const bindEvent = (app: App, element: Element, dialog?: Dialog) => { onGet({ data: { data: { - content: `
${Constants.ZWSP}
`, + content: `
${Constants.ZWSP}
`, id: Lute.NewNodeID(), rootID: Lute.NewNodeID(), }, diff --git a/app/src/mobile/menu/index.ts b/app/src/mobile/menu/index.ts index 0f832d09c..bd91a23bf 100644 --- a/app/src/mobile/menu/index.ts +++ b/app/src/mobile/menu/index.ts @@ -1,6 +1,6 @@ import {popSearch} from "./search"; import {initAppearance} from "../settings/appearance"; -import {initAssets} from "../settings/assets"; +import {initConfigAssets} from "../settings/assets"; import {closePanel} from "../util/closePanel"; import {mountHelp, newDailyNote, newNotebook} from "../../util/mount"; import {repos} from "../../config/repos"; @@ -178,7 +178,7 @@ export const initRightMenu = (app: App) => { event.stopPropagation(); break; } else if (target.id === "menuAssets") { - initAssets(); + initConfigAssets(app); event.preventDefault(); event.stopPropagation(); break; diff --git a/app/src/mobile/settings/assets.ts b/app/src/mobile/settings/assets.ts index 39de47b4d..88a8ddeae 100644 --- a/app/src/mobile/settings/assets.ts +++ b/app/src/mobile/settings/assets.ts @@ -1,14 +1,15 @@ import {openModel} from "../menu/model"; import {image} from "../../config/image"; +import {App} from "../../index"; -export const initAssets = () => { +export const initConfigAssets = (app: App) => { openModel({ title: window.siyuan.languages.assets, icon: "iconImage", html: image.genHTML(), bindEvent(modelMainElement: HTMLElement) { image.element = modelMainElement.firstElementChild; - image.bindEvent(); + image.bindEvent(app); } }); }; diff --git a/app/src/protyle/render/av/action.ts b/app/src/protyle/render/av/action.ts index 9fdbb45b8..14cbef2de 100644 --- a/app/src/protyle/render/av/action.ts +++ b/app/src/protyle/render/av/action.ts @@ -864,7 +864,7 @@ export const duplicateCompletely = (protyle: IProtyle, nodeElement: HTMLElement) fetchPost("/api/av/duplicateAttributeViewBlock", {avID: nodeElement.getAttribute("data-av-id")}, (response) => { nodeElement.classList.remove("protyle-wysiwyg--select"); const tempElement = document.createElement("template"); - tempElement.innerHTML = protyle.lute.SpinBlockDOM(`
`); + tempElement.innerHTML = protyle.lute.SpinBlockDOM(`
`); const cloneElement = tempElement.content.firstElementChild; nodeElement.after(cloneElement); avRender(cloneElement, protyle, () => { diff --git a/app/src/protyle/render/av/render.ts b/app/src/protyle/render/av/render.ts index f1a1eaed1..a5df3aea3 100644 --- a/app/src/protyle/render/av/render.ts +++ b/app/src/protyle/render/av/render.ts @@ -270,7 +270,7 @@ const renderGroupTable = (options: ITableOptions) => { }); if (options.renderAll) { options.blockElement.firstElementChild.outerHTML = `
- ${genTabHeaderHTML(options.data, isSearching || !!query, options.protyle ? (!options.protyle.disabled && !hasClosestByAttribute(options.blockElement, "data-type", "NodeBlockQueryEmbed")) : false)} + ${genTabHeaderHTML(options.data, isSearching || !!query, !options.protyle.disabled && !hasClosestByAttribute(options.blockElement, "data-type", "NodeBlockQueryEmbed"))}
${avBodyHTML}
@@ -290,13 +290,13 @@ const afterRenderTable = (options: ITableOptions) => { options.blockElement.setAttribute("data-render", "true"); options.blockElement.querySelector(".av__scroll").scrollLeft = options.resetData.left; options.blockElement.style.alignSelf = options.resetData.alignSelf; - const editRect = options.protyle ? options.protyle.contentElement.getBoundingClientRect() : null; + const editRect = options.protyle.contentElement.getBoundingClientRect(); if (options.resetData.headerTransform) { const headerTransformElement = options.blockElement.querySelector(`.av__body[data-group-id="${options.resetData.headerTransform.groupId}"] .av__row--header`) as HTMLElement; if (headerTransformElement) { headerTransformElement.style.transform = options.resetData.headerTransform.transform; } - } else if (editRect && options.protyle && !options.protyle.options.action.includes(Constants.CB_GET_HISTORY)) { + } else if (editRect && !options.protyle.options.action.includes(Constants.CB_GET_HISTORY)) { // 需等待渲染完,否则 getBoundingClientRect 错误 https://github.com/siyuan-note/siyuan/issues/13787 setTimeout(() => { stickyRow(options.blockElement, editRect, "top"); @@ -307,7 +307,7 @@ const afterRenderTable = (options: ITableOptions) => { if (footerTransformElement) { footerTransformElement.style.transform = options.resetData.footerTransform.transform; } - } else if (editRect && options.protyle && !options.protyle.options.action.includes(Constants.CB_GET_HISTORY)) { + } else if (editRect && !options.protyle.options.action.includes(Constants.CB_GET_HISTORY)) { // 需等待渲染完,否则 getBoundingClientRect 错误 https://github.com/siyuan-note/siyuan/issues/13787 setTimeout(() => { stickyRow(options.blockElement, editRect, "bottom"); @@ -552,8 +552,8 @@ export const avRender = async (element: Element, protyle: IProtyle, cb?: (data: const avPageSize = getPageSize(e); let data: IAV; if (!avData) { - const created = protyle ? protyle.options.history?.created : false; - const snapshot = protyle ? protyle.options.history?.snapshot : false; + const created = protyle.options.history?.created; + const snapshot = protyle.options.history?.snapshot; const response = await fetchSyncPost(created ? "/api/av/renderHistoryAttributeView" : (snapshot ? "/api/av/renderSnapshotAttributeView" : "/api/av/renderAttributeView"), { id: e.getAttribute("data-av-id"), created, @@ -588,7 +588,7 @@ export const avRender = async (element: Element, protyle: IProtyle, cb?: (data:
`; if (renderAll) { e.firstElementChild.outerHTML = `
- ${genTabHeaderHTML(data, resetData.isSearching || !!resetData.query, protyle ? (!protyle.disabled && !hasClosestByAttribute(e, "data-type", "NodeBlockQueryEmbed")) : false)} + ${genTabHeaderHTML(data, resetData.isSearching || !!resetData.query, !protyle.disabled && !hasClosestByAttribute(e, "data-type", "NodeBlockQueryEmbed"))}
${avBodyHTML}