An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: https://github.com/siyuan-note/siyuan/issues/14299
Vanessa8d24e0bf2516
diff --git a/app/src/protyle/render/blockRender.ts b/app/src/protyle/render/blockRender.tsindex 88c3d0a957..6cfc2dcc9f 100644--- a/app/src/protyle/render/blockRender.ts+++ b/app/src/protyle/render/blockRender.ts@@ -1,10 +1,10 @@-import {hasClosestByAttribute, hasTopClosestByClassName, isInEmbedBlock} from "../util/hasClosest";+import {hasClosestByAttribute, hasTopClosestByClassName} from "../util/hasClosest";import {fetchPost, fetchSyncPost} from "../../util/fetch";import {processRender} from "../util/processCode";import {highlightRender} from "./highlightRender";-import {Constants} from "../../constants";import {genBreadcrumb, improveBreadcrumbAppearance} from "../wysiwyg/renderBacklink";import {avRender} from "./av/render";+import {genRenderFrame} from "./util";export const blockRender = (protyle: IProtyle, element: Element, top?: number) => {let blockElements: Element[] = [];@@ -23,12 +23,8 @@ export const blockRender = (protyle: IProtyle, element: Element, top?: number) =}// 需置于请求返回前,否则快速滚动会导致重复加载 https://ld246.com/article/1666857862494?r=88250item.setAttribute("data-render", "true");+ genRenderFrame(item);item.style.height = (item.clientHeight - 4) + "px"; // 减少抖动 https://ld246.com/article/1668669380171- item.innerHTML = `<div class="protyle-icons${isInEmbedBlock(item) ? " fn__none" : ""}">- <span aria-label="${window.siyuan.languages.refresh}" class="b3-tooltips__nw b3-tooltips protyle-icon protyle-action__reload protyle-icon--first"><svg class="fn__rotate"><use xlink:href="#iconRefresh"></use></svg></span>- <span aria-label="${window.siyuan.languages.update} SQL" class="b3-tooltips__nw b3-tooltips protyle-icon protyle-action__edit"><svg><use xlink:href="#iconEdit"></use></svg></span>- <span aria-label="${window.siyuan.languages.more}" class="b3-tooltips__nw b3-tooltips protyle-icon protyle-action__menu protyle-icon--last"><svg><use xlink:href="#iconMore"></use></svg></span>-</div>${item.lastElementChild.outerHTML}`;const content = Lute.UnEscapeHTMLStr(item.getAttribute("data-content"));let breadcrumb: boolean | string = item.getAttribute("breadcrumb");if (breadcrumb) {@@ -112,13 +108,10 @@ const renderEmbed = (blocks: {html += `<div class="protyle-wysiwyg__embed" data-id="${blocksItem.block.id}">${breadcrumbHTML}${blocksItem.block.content}</div>`;});if (blocks.length > 0) {- item.lastElementChild.insertAdjacentHTML("beforebegin", html +- // 辅助上下移动时进行选中- `<div style="position: absolute;">${Constants.ZWSP}</div>`);+ item.firstElementChild.insertAdjacentHTML("afterend", html);improveBreadcrumbAppearance(item.querySelector(".protyle-wysiwyg__embed"));} else {- item.lastElementChild.insertAdjacentHTML("beforebegin", `<div class="ft__smaller ft__secondary b3-form__space--small" contenteditable="false">${window.siyuan.languages.refExpired}</div>-<div style="position: absolute;">${Constants.ZWSP}</div>`);+ item.firstElementChild.insertAdjacentHTML("afterend", `<div class="ft__smaller ft__secondary b3-form__space--small" contenteditable="false">${window.siyuan.languages.refExpired}</div>`);}processRender(item);diff --git a/app/src/protyle/render/util.ts b/app/src/protyle/render/util.tsindex a1c26b0cb7..7bf606174d 100644--- a/app/src/protyle/render/util.ts+++ b/app/src/protyle/render/util.ts@@ -1,3 +1,6 @@+import {isInEmbedBlock} from "../util/hasClosest";+import {Constants} from "../../constants";+export const genIconHTML = (element?: false | HTMLElement) => {let enable = true;if (element) {@@ -14,6 +17,17 @@ export const genIconHTML = (element?: false | HTMLElement) => {</div>`;};+export const genRenderFrame = (renderElement:Element) => {+ if (renderElement.querySelector(".protyle-icons")) {+ return;+ }+ renderElement.insertAdjacentHTML("afterbegin",`<div class="protyle-icons${isInEmbedBlock(renderElement) ? " fn__none" : ""}">+ <span aria-label="${window.siyuan.languages.refresh}" class="b3-tooltips__nw b3-tooltips protyle-icon protyle-action__reload protyle-icon--first"><svg class="fn__rotate"><use xlink:href="#iconRefresh"></use></svg></span>+ <span aria-label="${window.siyuan.languages.update} SQL" class="b3-tooltips__nw b3-tooltips protyle-icon protyle-action__edit"><svg><use xlink:href="#iconEdit"></use></svg></span>+ <span aria-label="${window.siyuan.languages.more}" class="b3-tooltips__nw b3-tooltips protyle-icon protyle-action__menu protyle-icon--last"><svg><use xlink:href="#iconMore"></use></svg></span>+</div><div style="position: absolute;">${Constants.ZWSP}</div>`)+}+export const processClonePHElement = (item: Element) => {if (item.getAttribute("data-type") === "NodeHTMLBlock") {const phElement = item.querySelector("protyle-html");diff --git a/app/src/protyle/util/insertHTML.ts b/app/src/protyle/util/insertHTML.tsindex ceaf3e74b6..726b226a43 100644--- a/app/src/protyle/util/insertHTML.ts+++ b/app/src/protyle/util/insertHTML.ts@@ -282,6 +282,7 @@ const processTable = (range: Range, html: string, protyle: IProtyle, blockElemenexport const insertHTML = (html: string, protyle: IProtyle, isBlock = false,// 移动端插入嵌入块时,获取到的 range 为旧值useProtyleRange = false,+ // 在开头粘贴块则插入上方insertByCursor = false) => {if (html === "") {return;diff --git a/app/src/protyle/util/selection.ts b/app/src/protyle/util/selection.tsindex 1cff3011e0..252b5791b1 100644--- a/app/src/protyle/util/selection.ts+++ b/app/src/protyle/util/selection.ts@@ -8,6 +8,7 @@ import {import {hasClosestByAttribute, hasClosestByTag} from "./hasClosest";import {countBlockWord, countSelectWord} from "../../layout/status";import {hideElements} from "../ui/hideElements";+import {genRenderFrame} from "../render/util";const selectIsEditor = (editor: Element, range?: Range) => {if (!range) {@@ -547,14 +548,9 @@ export const focusBlock = (element: Element, parentElement?: HTMLElement, toStarrange.selectNodeContents(element.firstElementChild);setRange = true;} else if (type === "NodeBlockQueryEmbed") {- if (element.lastElementChild.previousElementSibling?.firstChild) {- range.selectNodeContents(element.lastElementChild.previousElementSibling.firstChild);- range.collapse(true);- } else {- // https://github.com/siyuan-note/siyuan/issues/5267- range.selectNodeContents(element);- range.collapse(true);- }+ genRenderFrame(element);+ range.selectNodeContents(element.lastElementChild.previousElementSibling.firstChild);+ range.collapse(true);setRange = true;} else if (["NodeMathBlock", "NodeHTMLBlock"].includes(type)) {if (element.lastElementChild.previousElementSibling?.lastElementChild?.firstChild) {