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: Block icons support quickly inserting blocks above or below https://github.com/siyuan-note/siyuan/issues/17900
Daniel0240022bb7f6
diff --git a/app/appearance/icons/index.html b/app/appearance/icons/index.htmlindex 9c8b6f7c8f..f07abfb885 100644--- a/app/appearance/icons/index.html+++ b/app/appearance/icons/index.html@@ -1,6 +1,6 @@<html><head>- <style>+<style>.fn__clear > div {float: left;width: 150px;@@ -28,6 +28,12 @@<body><h2>SiYuan</h2><div class="fn__clear">+ <div>+ <svg>+ <use xlink:href="#iconSquarePlus"></use>+ </svg>+ iconSquarePlus+ </div><div><svg><use xlink:href="#iconSquareStop"></use>diff --git a/app/appearance/icons/litheness/icon.js b/app/appearance/icons/litheness/icon.jsindex 20faf15209..17932bb621 100644--- a/app/appearance/icons/litheness/icon.js+++ b/app/appearance/icons/litheness/icon.js@@ -1,5 +1,8 @@document.body.insertAdjacentHTML('afterbegin', `<svg id="iconsLitheness" style="position: absolute; width: 0; height: 0; overflow: hidden;"><defs>+ <symbol id="iconSquarePlus" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">+ <rect width="18" height="18" x="3" y="3" rx="2"/><path d="M8 12h8"/><path d="M12 8v8"/>+ </symbol><symbol id="iconSquareStop" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="18" x="3" y="3" rx="2"/><rect x="9" y="9" width="6" height="6" rx="1"/></symbol>diff --git a/app/src/assets/scss/protyle/_protyle.scss b/app/src/assets/scss/protyle/_protyle.scssindex 98bc03fe9d..1f37fcf2bf 100644--- a/app/src/assets/scss/protyle/_protyle.scss+++ b/app/src/assets/scss/protyle/_protyle.scss@@ -114,6 +114,30 @@}}+// 块标上下/左右边缘悬浮触发的+号按钮,与 .protyle-gutters 同为 fixed 坐标系,由 JS 按鼠标位置定位+// 选择器需带 button 标签以提升特异性,覆盖 .protyle-gutters button 的 position:relative 与 svg 尺寸+// z-index 需高于块标 button 内 span 覆盖层(z-index:2),以便与块标重叠时仍可点击+.protyle-gutters button.protyle-gutters__plus {+ position: fixed;+ z-index: 3;+ border: 0;+ padding: 1px;+ cursor: copy;+ background-color: transparent;++ svg {+ color: var(--b3-theme-on-surface-light);+ width: 14px;+ height: 14px;+ float: none;+ transition: var(--b3-color-transition);+ }++ &:hover svg {+ color: var(--b3-theme-primary);+ }+}+.protyle-select {position: fixed;background-color: var(--b3-theme-primary-lightest);diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.tsindex ebf9a9a4a9..f84744467d 100644--- a/app/src/protyle/gutter/index.ts+++ b/app/src/protyle/gutter/index.ts@@ -300,6 +300,16 @@ export class Gutter {return;}const gutterRect = buttonElement.getBoundingClientRect();+ if (buttonElement.dataset.type === "gutterPlusBefore" || buttonElement.dataset.type === "gutterPlusAfter") {+ // 块标边缘+号:在对应块上方/下方插入新块,复用 insertEmptyBlock(列表项自动生成新列表项)+ if (protyle.disabled || !id) {+ return;+ }+ hideElements(["gutter"], protyle);+ countBlockWord([], protyle.block.rootID);+ insertEmptyBlock(protyle, buttonElement.dataset.type === "gutterPlusBefore" ? "beforebegin" : "afterend", id);+ return;+ }if (buttonElement.dataset.type === "NodeAttributeViewRowMenu" || buttonElement.dataset.type === "NodeAttributeViewRow") {const rowElement = Array.from(protyle.wysiwyg.element.querySelectorAll(`.av[data-node-id="${buttonElement.dataset.nodeId}"] .av__row[data-id="${buttonElement.dataset.rowId}"]`)).find((item: HTMLElement) => {if (!isInEmbedBlock(item)) {@@ -504,13 +514,104 @@ export class Gutter {event.preventDefault();event.stopPropagation();});+ // 延迟隐藏计时器,鼠标在块标与+号之间移动时提供缓冲,避免中途 mouseleave 误隐藏+号+ let hidePlusTimeout: number;this.element.addEventListener("mouseleave", (event: MouseEvent & { target: HTMLInputElement }) => {- Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--hl, .av__row--hl")).forEach(item => {- item.classList.remove("protyle-wysiwyg--hl", "av__row--hl");- });+ // 鼠标移向+号时不隐藏(+号定位在容器外侧,移出容器几何范围会触发 mouseleave)+ const relatedType = (event.relatedTarget as HTMLElement)?.dataset?.type;+ if (relatedType === "gutterPlusBefore" || relatedType === "gutterPlusAfter") {+ return;+ }+ // 延迟隐藏,若期间鼠标进入+号(mousemove 会被取消)则保持显示+ window.clearTimeout(hidePlusTimeout);+ hidePlusTimeout = window.setTimeout(() => {+ Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--hl, .av__row--hl")).forEach(item => {+ item.classList.remove("protyle-wysiwyg--hl", "av__row--hl");+ });+ this.element.querySelectorAll(".protyle-gutters__plus").forEach(item => {+ (item as HTMLElement).style.display = "none";+ });+ }, 200);event.preventDefault();event.stopPropagation();});+ // 鼠标悬浮块标上下边缘(正常模式)或左右边缘(压缩模式)时定位并显示+号+ this.element.addEventListener("mousemove", (event: MouseEvent & { target: HTMLElement }) => {+ const beforeElement = this.element.querySelector('.protyle-gutters__plus[data-type="gutterPlusBefore"]') as HTMLElement;+ const afterElement = this.element.querySelector('.protyle-gutters__plus[data-type="gutterPlusAfter"]') as HTMLElement;+ if (protyle.disabled || !beforeElement || !afterElement) {+ beforeElement?.style.setProperty("display", "none");+ afterElement?.style.setProperty("display", "none");+ return;+ }+ // 鼠标已移到+号上,保持当前显示不重定位+ const overPlusType = (event.target as HTMLElement)?.dataset?.type;+ if (overPlusType === "gutterPlusBefore" || overPlusType === "gutterPlusAfter") {+ window.clearTimeout(hidePlusTimeout);+ return;+ }+ const buttonElement = hasClosestByTag(event.target, "BUTTON");+ if (!buttonElement || buttonElement.classList.contains("protyle-gutters__plus")) {+ return;+ }+ const type = buttonElement.getAttribute("data-type");+ // 跳过折叠箭头、数据库行+号、数据库行拖拽手柄,保持其原有行为+ if (type === "fold" || type === "NodeAttributeViewRow" || type === "NodeAttributeViewRowMenu") {+ beforeElement.style.display = "none";+ afterElement.style.display = "none";+ return;+ }+ const id = buttonElement.getAttribute("data-node-id");+ if (!id) {+ beforeElement.style.display = "none";+ afterElement.style.display = "none";+ return;+ }+ beforeElement.dataset.nodeId = id;+ afterElement.dataset.nodeId = id;+ const rect = buttonElement.getBoundingClientRect();+ // 压缩模式:块标容器宽 24px 且按钮垂直堆叠,+号改放到水平方向避免与堆叠按钮重叠+ const compressed = this.element.style.width === "24px";+ // 显示目标方向的+号,隐藏另一个;先 display 再测 offset 以避免 display:none 时尺寸为 0+ const showPlus = (plusElement: HTMLElement, vertical: boolean) => {+ const otherElement = plusElement === beforeElement ? afterElement : beforeElement;+ otherElement.style.display = "none";+ plusElement.style.display = "";+ const plusWidth = plusElement.offsetWidth;+ const plusHeight = plusElement.offsetHeight;+ if (vertical) {+ // 正常模式:+号与 button 边缘重叠 2px(中心更贴近块标,且鼠标移出 button 即进入+号)+ plusElement.style.left = `${rect.left + (rect.width - plusWidth) / 2}px`;+ plusElement.style.top = `${(plusElement === beforeElement ? rect.top - plusHeight + 2 : rect.bottom - 2)}px`;+ } else {+ // 压缩模式:+号都放在 button 右侧(避开左侧 tooltip),垂直对齐块标图标中心+ const iconSvg = buttonElement.querySelector("svg");+ const iconRect = iconSvg.getBoundingClientRect();+ plusElement.style.top = `${iconRect.top + iconRect.height / 2 - plusHeight / 2}px`;+ plusElement.style.left = `${rect.right - 2}px`;+ }+ };+ if (compressed) {+ // 压缩模式:右侧横排显示两个+号,下方插入在前(更靠近块标,更常用),上方插入在后+ const iconSvg = buttonElement.querySelector("svg");+ const iconRect = iconSvg.getBoundingClientRect();+ const iconMid = iconRect.top + iconRect.height / 2;+ afterElement.style.display = "";+ beforeElement.style.display = "";+ const plusWidth = afterElement.offsetWidth;+ const plusHeight = afterElement.offsetHeight;+ const top = iconMid - plusHeight / 2;+ afterElement.style.left = `${rect.right - 2}px`;+ afterElement.style.top = `${top}px`;+ beforeElement.style.left = `${rect.right - 2 + plusWidth + 1}px`;+ beforeElement.style.top = `${top}px`;+ } else {+ // 正常模式下上边缘=上方插入,下边缘=下方插入+ showPlus(event.clientY < rect.top + rect.height / 2 ? beforeElement : afterElement, true);+ }+ // 鼠标在块标上移动,取消可能挂起的延迟隐藏+ window.clearTimeout(hidePlusTimeout);+ });// https://github.com/siyuan-note/siyuan/issues/12751this.element.addEventListener("mousewheel", (event) => {hideElements(["gutter"], protyle);@@ -2734,7 +2835,8 @@ data-type="fold" style="cursor:inherit;"><svg style="width: 10px;${fold && fold}}let match = true;- const buttonsElement = this.element.querySelectorAll("button");+ // 统计时排除块标边缘+号按钮,它们由 render 末尾单独追加,不参与防抖比较+ const buttonsElement = this.element.querySelectorAll("button:not(.protyle-gutters__plus)");if (buttonsElement.length !== html.split("</button>").length - 1) {match = false;} else {@@ -2793,6 +2895,10 @@ data-type="fold" style="cursor:inherit;"><svg style="width: 10px;${fold && foldthis.element.style.left = `${rect.left - this.element.clientWidth - space / 2 + 3}px`;html = "";Array.from(this.element.children).reverse().forEach((item, index) => {+ // 跳过块标边缘+号按钮,避免被压缩重排+ if (item.classList.contains("protyle-gutters__plus")) {+ return;+ }if (index !== 0) {(item.firstElementChild as HTMLElement).style.height = "14px";}@@ -2804,5 +2910,7 @@ data-type="fold" style="cursor:inherit;"><svg style="width: 10px;${fold && folditem.style.height = "";});}+ // 追加块标上下/左右边缘悬浮触发的+号按钮(默认隐藏),由 mousemove 按鼠标位置定位显示+ this.element.insertAdjacentHTML("beforeend", `<button class="protyle-gutters__plus ariaLabel" data-type="gutterPlusBefore" data-position="parentW" aria-label="${window.siyuan.languages.insertBefore}" style="display:none"><svg><use xlink:href="#iconSquarePlus"></use></svg></button><button class="protyle-gutters__plus ariaLabel" data-type="gutterPlusAfter" data-position="parentW" aria-label="${window.siyuan.languages.insertAfter}" style="display:none"><svg><use xlink:href="#iconSquarePlus"></use></svg></button>`);}}