An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: Support resizing editors in multi-document popovers https://github.com/siyuan-note/siyuan/issues/12779
Daniel0a88e5f6898b
diff --git a/app/src/assets/scss/business/_block.scss b/app/src/assets/scss/business/_block.scssindex cc2494f3a3..914c0c7a2f 100644--- a/app/src/assets/scss/business/_block.scss+++ b/app/src/assets/scss/business/_block.scss@@ -77,6 +77,32 @@}}+ &__edit-resize {+ cursor: row-resize;+ flex-shrink: 0;+ height: 6px;+ margin: -3px 0;+ position: relative;+ touch-action: none;+ z-index: 6;++ &::after {+ background-color: var(--b3-theme-surface-lighter);+ content: "";+ height: .5px;+ left: 0;+ position: absolute;+ top: 3px;+ transition: var(--b3-transition);+ width: 100%;+ }++ &:hover::after,+ &--active::after {+ background-color: var(--b3-scroll-color);+ }+ }+&__icons {padding: 0 8px;display: flex;diff --git a/app/src/block/Panel.ts b/app/src/block/Panel.tsindex d9cef13e9f..8a464f2daa 100644--- a/app/src/block/Panel.ts+++ b/app/src/block/Panel.ts@@ -20,6 +20,8 @@ import {updateHotkeyAfterTip} from "../protyle/util/compatibility";import {getTopBarHeight} from "../layout/getTopBarHeight";import {activateAVLocateWithRetry} from "../protyle/render/av/locate";+const BLOCK_PANEL_EDITOR_MIN_HEIGHT = 155;+export class BlockPanel {public element: HTMLElement;public targetElement: HTMLElement;@@ -33,6 +35,7 @@ export class BlockPanel {private observerResize: ResizeObserver;private observerLoad: IntersectionObserver;private originalRefBlockIDs: IObject;+ private editorResizeCleanup?: () => void;// x,y 和 targetElement 二选一必传constructor(options: {@@ -146,15 +149,140 @@ export class BlockPanel {});/// #if !MOBILEmoveResize(this.element, () => {- const pinElement = this.element.firstElementChild.querySelector('[data-type="pin"]');- pinElement.setAttribute("aria-label", window.siyuan.languages.unpin);- pinElement.querySelector("use").setAttribute("xlink:href", "#iconUnpin");- this.element.setAttribute("data-pin", "true");+ this.pin();});/// #endifthis.render();}+ private pin() {+ const pinElement = this.element?.firstElementChild?.querySelector('[data-type="pin"]');+ if (!pinElement) {+ return;+ }+ pinElement.setAttribute("aria-label", window.siyuan.languages.unpin);+ pinElement.querySelector("use").setAttribute("xlink:href", "#iconUnpin");+ this.element.setAttribute("data-pin", "true");+ }++ private setAutoEditorHeight(editor: Protyle) {+ const editorElement = editor.protyle.element;+ editorElement.style.flex = "";+ editorElement.style.height = "";+ delete editorElement.dataset.resized;+ editorElement.style.minHeight = this.refDefs.length > 1 ?+ Math.min(30 + editor.protyle.wysiwyg.element.clientHeight, window.innerHeight / 3) + "px" : "";+ }++ private resizeEditor(editor: Protyle) {+ resize(editor.protyle);+ editor.protyle.scroll.element.parentElement.style.setProperty(+ "--b3-dynamicscroll-width",+ Math.min(editor.protyle.contentElement.clientHeight - 49, 200) + "px"+ );+ }++ private getEditor(editorElement: HTMLElement) {+ return this.editors.find(item => item.protyle.element === editorElement);+ }++ private bindEditorResize() {+ const contentElement = this.element.querySelector(".block__content") as HTMLElement;+ contentElement.querySelectorAll(".block__edit-resize").forEach((resizeElement: HTMLElement) => {+ resizeElement.addEventListener("mousedown", (event: MouseEvent) => {+ const editorElement = resizeElement.previousElementSibling as HTMLElement;+ if (!editorElement?.classList.contains("block__edit")) {+ return;+ }+ this.editorResizeCleanup?.();+ const documentSelf = document;+ const startY = event.clientY;+ const startHeight = editorElement.getBoundingClientRect().height;+ const panelHeight = this.element.getBoundingClientRect().height;+ const minHeight = Math.min(startHeight, BLOCK_PANEL_EDITOR_MIN_HEIGHT);+ const maxHeight = Math.max(startHeight, contentElement.clientHeight);+ let hasMove = false;+ let resizeFrame: number;+ const scheduleResize = () => {+ cancelAnimationFrame(resizeFrame);+ resizeFrame = requestAnimationFrame(() => {+ const editor = this.getEditor(editorElement);+ if (editor) {+ this.resizeEditor(editor);+ }+ });+ };+ const cleanup = () => {+ cancelAnimationFrame(resizeFrame);+ resizeElement.classList.remove("block__edit-resize--active");+ if (this.element) {+ this.element.style.userSelect = "";+ }+ documentSelf.onmousemove = null;+ documentSelf.onmouseup = null;+ documentSelf.ondragstart = null;+ documentSelf.onselectstart = null;+ documentSelf.onselect = null;+ if (this.editorResizeCleanup === cleanup) {+ this.editorResizeCleanup = undefined;+ }+ };+ this.editorResizeCleanup = cleanup;+ this.element.style.userSelect = "none";+ resizeElement.classList.add("block__edit-resize--active");+ documentSelf.ondragstart = () => false;+ documentSelf.onmousemove = (moveEvent: MouseEvent) => {+ moveEvent.preventDefault();+ moveEvent.stopPropagation();+ const height = Math.max(minHeight, Math.min(maxHeight, startHeight + moveEvent.clientY - startY));+ if (height === startHeight && !hasMove) {+ return;+ }+ if (!hasMove) {+ this.element.style.height = panelHeight + "px";+ this.element.style.maxHeight = "";+ this.pin();+ hasMove = true;+ }+ const roundedHeight = Math.round(height);+ editorElement.dataset.resized = "true";+ editorElement.style.flex = `0 0 ${roundedHeight}px`;+ editorElement.style.height = roundedHeight + "px";+ editorElement.style.minHeight = roundedHeight + "px";+ scheduleResize();+ };+ documentSelf.onmouseup = () => {+ cleanup();+ if (hasMove) {+ const editor = this.getEditor(editorElement);+ if (editor) {+ this.resizeEditor(editor);+ }+ }+ };+ event.preventDefault();+ event.stopPropagation();+ });+ resizeElement.addEventListener("dblclick", (event: MouseEvent) => {+ const editorElement = resizeElement.previousElementSibling as HTMLElement;+ if (!editorElement?.classList.contains("block__edit")) {+ return;+ }+ editorElement.style.flex = "";+ editorElement.style.height = "";+ editorElement.style.minHeight = "";+ delete editorElement.dataset.resized;+ const editor = this.getEditor(editorElement);+ if (editor) {+ this.setAutoEditorHeight(editor);+ this.resizeEditor(editor);+ }+ event.preventDefault();+ event.stopPropagation();+ });+ });+ }+private initProtyle(editorElement: HTMLElement, afterCB?: () => void) {const index = parseInt(editorElement.getAttribute("data-index"));fetchPost("/api/block/getBlockInfo", {id: this.refDefs[index].refID}, (response) => {@@ -210,8 +338,8 @@ export class BlockPanel {afterCB();}// https://ld246.com/article/1653639418266- if (editor.protyle.element.nextElementSibling || editor.protyle.element.previousElementSibling) {- editor.protyle.element.style.minHeight = Math.min(30 + editor.protyle.wysiwyg.element.clientHeight, window.innerHeight / 3) + "px";+ if (this.refDefs.length > 1 && editor.protyle.element.dataset.resized !== "true") {+ this.setAutoEditorHeight(editor);}// 由于 afterCB 中高度的设定,需在之后再进行设定// 49 = 16(上图标)+16(下图标)+8(padding)+9(底部距离)@@ -223,6 +351,7 @@ export class BlockPanel {}public destroy() {+ this.editorResizeCleanup?.();this.observerResize?.disconnect();this.observerLoad?.disconnect();window.siyuan.blockPanels.find((item, index) => {@@ -275,14 +404,24 @@ export class BlockPanel {if (this.refDefs.length === 0) {html += `<div class="ft__smaller ft__smaller ft__secondary b3-form__space--small" contenteditable="false">${window.siyuan.languages.refExpired}</div>`;} else {+ let editorResizeHTML = "";+ /// #if !MOBILE+ if (this.refDefs.length > 1) {+ editorResizeHTML = '<div class="block__edit-resize" role="separator" aria-orientation="horizontal"></div>';+ }+ /// #endifthis.refDefs.forEach((item, index) => {html += `<div class="block__edit fn__flex-1 protyle" data-index="${index}"></div>`;+ html += editorResizeHTML;});}if (html) {html += '</div><div class="resize__rd"></div><div class="resize__ld"></div><div class="resize__lt"></div><div class="resize__rt"></div><div class="resize__r"></div><div class="resize__d"></div><div class="resize__t"></div><div class="resize__l"></div>';}this.element.innerHTML = html;+ /// #if !MOBILE+ this.bindEditorResize();+ /// #endiflet resizeTimeout: number;this.observerResize = new ResizeObserver(() => {clearTimeout(resizeTimeout);