Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:lipstick: Improve mind map block resizing with drag handles https://github.com/siyuan-note/siyuan/issues/20017

Daniel379438c5aeb2
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-6yi0dv5/20200924101225-k254i8g.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-6yi0dv5/20200924101225-k254i8g.sy
index 1a2c419be7..ee823c9052 100644
--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-6yi0dv5/20200924101225-k254i8g.sy
+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-6yi0dv5/20200924101225-k254i8g.sy
@@ -2652,6 +2652,43 @@
}
]
},
+ {
+ "ID": "20261001015635-3w0f58c",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20261001015635-3w0f58c",
+ "updated": "20261001015635"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "Hover over the outer frame to reveal the resize handles. Drag the right edge to change width, the bottom edge to change height, or the bottom-right corner to change both. On touch devices, drag the handles directly. This changes the block size in the document, not the canvas zoom. Releasing saves one undoable change; press "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Esc"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " or cancel the touch gesture to restore the original size. The block menu’s width and height settings remain available."
+ }
+ ]
+ },
+ {
+ "ID": "20261001015635-8tls0r0",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20261001015635-8tls0r0",
+ "updated": "20261001015635"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "Resize handles are hidden in read-only, locked, and full-screen views. A mind map directly inside a super block has only the bottom height handle; use the super block’s column divider to change its width."
+ }
+ ]
+ },
{
"ID": "20260926151827-kkcg79g",
"Type": "NodeParagraph",
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy
index b32ccd1da7..753d0ad149 100644
--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy
+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy
@@ -7,7 +7,7 @@
"id": "20200924100950-9op5xi1",
"title": "Shortcuts",
"type": "doc",
- "updated": "20260930234403"
+ "updated": "20261001015635"
},
"Children": [
{
@@ -4224,7 +4224,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20210106154056-koo4wdj",
- "updated": "20260930171029"
+ "updated": "20261001015635"
},
"Children": [
{
@@ -12757,7 +12757,7 @@
"Type": "NodeHeading",
"Properties": {
"id": "20260921105011-4zeuyl4",
- "updated": "20260926152753"
+ "updated": "20261001015635"
},
"HeadingLevel": 3,
"Children": [
@@ -13299,6 +13299,38 @@
}
]
},
+ {
+ "ID": "20261001015635-5eooc5g",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20261001015635-5eooc5g",
+ "updated": "20261001015635"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "When a mind map resize handle has keyboard focus, use the arrow keys to adjust its width or height by 10 px, or hold "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Shift"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " with an arrow key for 1 px steps. These keys apply only to the focused resize handle. Press "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Esc"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " during a drag to cancel resizing."
+ }
+ ]
+ },
{
"ID": "20210106154319-jeh8w1g",
"Type": "NodeHeading",
diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-fqgskfj/20200905090211-2vixtlf.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-fqgskfj/20200905090211-2vixtlf.sy
index a5b5be93eb..c3f0396fac 100644
--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-fqgskfj/20200905090211-2vixtlf.sy
+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-fqgskfj/20200905090211-2vixtlf.sy
@@ -2731,6 +2731,43 @@
}
]
},
+ {
+ "ID": "20261001015635-u2ja640",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20261001015635-u2ja640",
+ "updated": "20261001015635"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "将鼠标移到脑图外框上即可显示尺寸手柄:拖动右边缘调整宽度,拖动下边缘调整高度,拖动右下角同时调整宽高;触屏可直接拖动手柄。此操作调整脑图块在文档中的尺寸,不改变画布缩放比例。松手后保存一次可撤销的修改;按 "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Esc"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " 或取消触摸操作可恢复原尺寸。仍可通过块菜单设置宽度和高度。"
+ }
+ ]
+ },
+ {
+ "ID": "20261001015635-7mfff9a",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20261001015635-7mfff9a",
+ "updated": "20261001015635"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "只读、锁定视图和全屏状态下不显示尺寸手柄。脑图作为超级块的直接子块时,只显示底部高度手柄;宽度通过超级块的分栏分隔线调整。"
+ }
+ ]
+ },
{
"ID": "20260926151827-8wl1iml",
"Type": "NodeParagraph",
diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy
index d68d540043..7fe03dbfb4 100644
--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy
+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy
@@ -7,7 +7,7 @@
"id": "20200813004551-gm0pbn1",
"title": "快捷键",
"type": "doc",
- "updated": "20260930234403"
+ "updated": "20261001015635"
},
"Children": [
{
@@ -4222,7 +4222,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20201227133317-rkh4bji",
- "updated": "20260930171029"
+ "updated": "20261001015635"
},
"Children": [
{
@@ -12747,7 +12747,7 @@
"Type": "NodeHeading",
"Properties": {
"id": "20260921105011-hmrchvc",
- "updated": "20260926152753"
+ "updated": "20261001015635"
},
"HeadingLevel": 3,
"Children": [
@@ -13377,6 +13377,38 @@
}
]
},
+ {
+ "ID": "20261001015635-hkwweog",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20261001015635-hkwweog",
+ "updated": "20261001015635"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "脑图尺寸手柄获得键盘焦点后,使用方向键按 10 px 调整对应的宽度或高度;按住 "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Shift"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " 再按方向键则每次调整 1 px。这些按键仅作用于当前聚焦的尺寸手柄。拖动过程中按 "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Esc"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " 可取消尺寸调整。"
+ }
+ ]
+ },
{
"ID": "20201227133317-xpgtzbg",
"Type": "NodeHeading",
diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226115825-mhcslw2/20211226120147-ib6yy3i.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226115825-mhcslw2/20211226120147-ib6yy3i.sy
index fae7bc8e63..cee98781d3 100644
--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226115825-mhcslw2/20211226120147-ib6yy3i.sy
+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226115825-mhcslw2/20211226120147-ib6yy3i.sy
@@ -2667,6 +2667,43 @@
}
]
},
+ {
+ "ID": "20261001015635-x8m40zw",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20261001015635-x8m40zw",
+ "updated": "20261001015635"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "將滑鼠移到心智圖外框上即可顯示尺寸控制點:拖曳右邊緣調整寬度,拖曳下邊緣調整高度,拖曳右下角同時調整寬高;觸控螢幕可直接拖曳控制點。此操作調整心智圖區塊在文件中的尺寸,不改變畫布縮放比例。放開後儲存一次可復原的修改;按 "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Esc"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " 或取消觸控操作可恢復原尺寸。仍可透過區塊選單設定寬度和高度。"
+ }
+ ]
+ },
+ {
+ "ID": "20261001015635-ytql4qf",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20261001015635-ytql4qf",
+ "updated": "20261001015635"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "唯讀、鎖定視圖與全螢幕狀態下不顯示尺寸控制點。心智圖作為超級區塊的直接子區塊時,只顯示底部高度控制點;寬度透過超級區塊的分欄分隔線調整。"
+ }
+ ]
+ },
{
"ID": "20260926151827-6pycwgr",
"Type": "NodeParagraph",
diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy
index 99e71b1310..f1651bc500 100644
--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy
+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy
@@ -7,7 +7,7 @@
"id": "20211226122549-jktxego",
"title": "快捷鍵",
"type": "doc",
- "updated": "20260930234403"
+ "updated": "20261001015635"
},
"Children": [
{
@@ -4216,7 +4216,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20211226122652-htptsmh",
- "updated": "20260930171029"
+ "updated": "20261001015635"
},
"Children": [
{
@@ -12753,7 +12753,7 @@
"Type": "NodeHeading",
"Properties": {
"id": "20260921105011-z0oyw36",
- "updated": "20260926152753"
+ "updated": "20261001015635"
},
"HeadingLevel": 3,
"Children": [
@@ -13295,6 +13295,38 @@
}
]
},
+ {
+ "ID": "20261001015635-nxedhhs",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20261001015635-nxedhhs",
+ "updated": "20261001015635"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "心智圖尺寸控制點取得鍵盤焦點後,使用方向鍵按 10 px 調整對應的寬度或高度;按住 "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Shift"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " 再按方向鍵則每次調整 1 px。這些按鍵僅作用於目前取得焦點的尺寸控制點。拖曳過程中按 "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Esc"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " 可取消尺寸調整。"
+ }
+ ]
+ },
{
"ID": "20211226122652-x2dmpab",
"Type": "NodeHeading",
diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy
index 96e5585595..5a1bb892a5 100644
--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy
+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy
@@ -9,7 +9,7 @@
"id": "20240530101000-xsbxokr",
"title": "ショートカット",
"type": "doc",
- "updated": "20260930234403"
+ "updated": "20261001015635"
},
"Children": [
{
@@ -4178,7 +4178,7 @@
"Properties": {
"ID": "20240530101000-twmuxke",
"id": "20240530101000-675gu9g",
- "updated": "20260930171029"
+ "updated": "20261001015635"
},
"Children": [
{
@@ -12707,7 +12707,7 @@
"Type": "NodeHeading",
"Properties": {
"id": "20260921105011-icqlkb6",
- "updated": "20260926152753"
+ "updated": "20261001015635"
},
"HeadingLevel": 3,
"Children": [
@@ -13249,6 +13249,38 @@
}
]
},
+ {
+ "ID": "20261001015635-i5efca0",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20261001015635-i5efca0",
+ "updated": "20261001015635"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "マインドマップのサイズ変更ハンドルにキーボードのフォーカスがあるとき、矢印キーで対応する幅または高さを 10 px ずつ変更できます。"
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Shift"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " を押しながら矢印キーを押すと 1 px ずつ変更します。これらのキーはフォーカス中のサイズ変更ハンドルにのみ作用します。ドラッグ中に "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Esc"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " を押すとサイズ変更をキャンセルします。"
+ }
+ ]
+ },
{
"ID": "20240530101000-9x0xqew",
"Type": "NodeHeading",
diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-gvtksyj/20240530101000-35bbvcx.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-gvtksyj/20240530101000-35bbvcx.sy
index 29fa3dcbe7..30fa75ade5 100644
--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-gvtksyj/20240530101000-35bbvcx.sy
+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-gvtksyj/20240530101000-35bbvcx.sy
@@ -2818,6 +2818,43 @@
}
]
},
+ {
+ "ID": "20261001015635-ganogsj",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20261001015635-ganogsj",
+ "updated": "20261001015635"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "外枠にマウスカーソルを合わせると、サイズ変更ハンドルが表示されます。右端をドラッグすると幅、下端は高さ、右下の角は両方を変更できます。タッチ操作ではハンドルを直接ドラッグします。文書内のブロックのサイズが変わり、キャンバスのズーム倍率は変わりません。指を離すと元に戻せる一回の変更として保存されます。"
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Esc"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " を押すかタッチ操作をキャンセルすると元のサイズに戻ります。ブロックメニューの幅と高さの設定も引き続き使用できます。"
+ }
+ ]
+ },
+ {
+ "ID": "20261001015635-v3ggg2j",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20261001015635-v3ggg2j",
+ "updated": "20261001015635"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "読み取り専用、表示ロック、全画面表示ではサイズ変更ハンドルは表示されません。スーパーブロックの直下にあるマインドマップでは下端の高さハンドルのみ表示され、幅はスーパーブロックの列の区切りで変更します。"
+ }
+ ]
+ },
{
"ID": "20260926151827-vknoaqd",
"Type": "NodeParagraph",
diff --git a/app/src/assets/scss/protyle/_mindmap-view.scss b/app/src/assets/scss/protyle/_mindmap-view.scss
index 5b58434de9..958c07a046 100644
--- a/app/src/assets/scss/protyle/_mindmap-view.scss
+++ b/app/src/assets/scss/protyle/_mindmap-view.scss
@@ -98,6 +98,51 @@
flex: 1;
}
+ &__resize {
+ z-index: 5;
+ opacity: 0;
+
+ &.resize__r {
+ right: 0;
+ top: 42px;
+ bottom: 16px;
+ }
+
+ &.resize__d {
+ bottom: 0;
+ right: 16px;
+ }
+
+ &.resize__rd {
+ right: 0;
+ bottom: 0;
+ }
+
+ &::before {
+ content: "";
+ position: absolute;
+ inset: 2px;
+ border-radius: var(--b3-border-radius);
+ background-color: var(--b3-theme-surface-lighter);
+ pointer-events: none;
+ }
+
+ &:focus-visible {
+ outline: 1px solid var(--b3-theme-primary);
+ outline-offset: -2px;
+ }
+ }
+
+ &:hover &__resize,
+ &:focus-within &__resize,
+ &__resize.touch-resize-active {
+ opacity: 1;
+ }
+
+ &.fullscreen &__resize {
+ display: none;
+ }
+
&--locked &__viewport {
touch-action: pan-y;
}
@@ -825,6 +870,32 @@
}
+@media (any-pointer: coarse) {
+ // 脑图把手位于边框内,不沿用外层弹窗向外扩展的触摸定位。
+ .mindmap-view > .mindmap-view__resize {
+ opacity: 1;
+
+ &.resize__r {
+ width: 14px;
+ right: 0;
+ bottom: 24px;
+ }
+
+ &.resize__d {
+ height: 14px;
+ bottom: 0;
+ right: 24px;
+ }
+
+ &.resize__rd {
+ width: 24px;
+ height: 24px;
+ right: 0;
+ bottom: 0;
+ }
+ }
+}
+
@media print {
.mindmap-view {
break-inside: avoid;
@@ -832,6 +903,7 @@
min-height: 0;
&__toolbar,
+ &__resize,
&__inspector,
&__tooltip,
&__route-handle,
diff --git a/app/src/protyle/render/listMindmap/index.ts b/app/src/protyle/render/listMindmap/index.ts
index 3dde211aed..80d027730e 100644
--- a/app/src/protyle/render/listMindmap/index.ts
+++ b/app/src/protyle/render/listMindmap/index.ts
@@ -35,6 +35,8 @@ import {prepareListMindmapConversion} from "./conversion";
import type {ListMindmapMetadata, ListMindmapModel} from "./model";
import {getListMindmapElements, registerListMindmapRoot, registerListMindmapView} from "./render";
import {syncListMindmapHeight} from "./height";
+import {bindListMindmapResize} from "./resize";
+import {setBlockHeight} from "../../gutter/height";
import {ListMindmapView} from "./view";
import {openListMindmapEditor} from "./editor";
import {focusListMindmap} from "./create";
@@ -128,6 +130,7 @@ class ListMindmapController {
private disposed = false;
private taskChanges: Promise<void> = Promise.resolve();
private unregisterVisible?: () => void;
+ private resize: ReturnType<typeof bindListMindmapResize>;
constructor(owner: IProtyle, list: HTMLElement) {
this.owner = owner;
@@ -395,6 +398,21 @@ class ListMindmapController {
}),
});
list.dataset.mindmapViewRendered = "true";
+ this.resize = bindListMindmapResize({
+ block: list, host: this.host,
+ labels: {width: window.siyuan.languages.width, height: window.siyuan.languages.height},
+ canResize: () => canEdit(owner, list) && !this.view.isLocked(),
+ prepare: () => this.finish(),
+ commit: size => this.change(() => {
+ if (size.width !== undefined && !list.parentElement?.classList.contains("sb")) {
+ list.style.width = `${size.width}px`;
+ list.style.flex = "none";
+ }
+ if (size.height !== undefined) {
+ setBlockHeight(list, `${size.height}px`);
+ }
+ }),
+ });
this.unregisterVisible = registerListMindmapView(list, this.view, this.host);
this.snapshot = cleanListMindmapHTML(list.outerHTML);
if (canEdit(owner, list)) {
@@ -614,6 +632,7 @@ class ListMindmapController {
public refresh() {
this.view.setReadOnly(!canEdit(this.owner, this.list));
syncListMindmapHeight(this.list, this.host);
+ this.resize.refresh();
const snapshot = cleanListMindmapHTML(this.list.outerHTML);
if (snapshot === this.snapshot) {
return;
@@ -631,6 +650,7 @@ class ListMindmapController {
const restoreFocus = this.host.contains(document.activeElement) && this.list.isConnected &&
this.list.dataset.type !== "NodeMindmap" && this.list.getAttribute(Constants.CUSTOM_SY_LIST_MINDMAP) !== "1";
this.activeEditor?.destroy();
+ this.resize.destroy();
this.unregisterVisible?.();
this.view.destroy();
this.host.remove();
diff --git a/app/src/protyle/render/listMindmap/resize.test.ts b/app/src/protyle/render/listMindmap/resize.test.ts
new file mode 100644
index 0000000000..026fd98d4b
--- /dev/null
+++ b/app/src/protyle/render/listMindmap/resize.test.ts
@@ -0,0 +1,321 @@
+import * as assert from "node:assert/strict";
+import {readFileSync} from "node:fs";
+import {test} from "node:test";
+import {runInNewContext} from "node:vm";
+import {ModuleKind, ScriptTarget, transpileModule} from "typescript";
+import {getListMindmapResizeSize, ListMindmapSize} from "./resize";
+
+const compiled = transpileModule(readFileSync("src/protyle/render/listMindmap/resize.ts", "utf8"), {
+ compilerOptions: {module: ModuleKind.CommonJS, target: ScriptTarget.ES2021},
+}).outputText;
+
+class Target {
+ listeners = new Map<string, Set<(event: any) => void>>();
+ addEventListener(type: string, listener: (event: any) => void) {
+ const listeners = this.listeners.get(type) || new Set();
+ listeners.add(listener);
+ this.listeners.set(type, listeners);
+ }
+ removeEventListener(type: string, listener: (event: any) => void) {
+ this.listeners.get(type)?.delete(listener);
+ }
+ dispatch(type: string, properties: Record<string, unknown> = {}) {
+ const event = {button: 0, isPrimary: true, pointerId: 1, clientX: 500, clientY: 300,
+ defaultPrevented: false, stopped: false,
+ preventDefault() { this.defaultPrevented = true; },
+ stopPropagation() { this.stopped = true; },
+ stopImmediatePropagation() { this.stopped = true; }, ...properties};
+ this.listeners.get(type)?.forEach(listener => listener(event));
+ return event;
+ }
+}
+
+class Style {
+ width = "";
+ height = "";
+ flex = "";
+ values = new Map<string, string>();
+ priorities = new Map<string, string>();
+ setProperty(key: string, value: string, priority = "") {
+ this.values.set(key, value);
+ this.priorities.set(key, priority);
+ }
+ getPropertyValue(key: string) { return this.values.get(key) || ""; }
+ getPropertyPriority(key: string) { return this.priorities.get(key) || ""; }
+ removeProperty(key: string) { this.values.delete(key); this.priorities.delete(key); }
+}
+
+class Element extends Target {
+ classes = new Set<string>();
+ classList = {contains: (name: string) => this.classes.has(name),
+ add: (name: string) => this.classes.add(name), remove: (name: string) => this.classes.delete(name)};
+ style = new Style();
+ dataset: Record<string, string> = {};
+ attributes = new Map<string, string>();
+ children: Element[] = [];
+ parentElement?: Element;
+ isConnected = true;
+ captured?: number;
+ hidden = false;
+ ownerDocument: {defaultView: Target, createElement: () => Element};
+ baseWidth = 500;
+ baseHeight = 300;
+ left = 20;
+ scale = 1;
+ dispatch(type: string, properties: Record<string, unknown> = {}) {
+ const event = super.dispatch(type, properties);
+ if (!event.stopped && this.parentElement) {
+ this.parentElement.dispatch(type, event);
+ }
+ return event;
+ }
+ get offsetWidth() { return parseFloat(this.style.width) || this.baseWidth; }
+ get offsetHeight() { return parseFloat(this.style.getPropertyValue("--mindmap-view-height")) || this.baseHeight; }
+ getBoundingClientRect() {
+ return {left: this.left, right: this.left + this.offsetWidth * this.scale,
+ width: this.offsetWidth * this.scale, height: this.offsetHeight * this.scale};
+ }
+ getAttribute(key: string) {
+ return key === "style" ? `${this.style.width};${this.style.height};${this.style.flex}` : this.attributes.get(key);
+ }
+ setAttribute(key: string, value: string) { this.attributes.set(key, value); }
+ appendChild(child: Element) { this.children.push(child); child.parentElement = this; }
+ setPointerCapture(id: number) { this.captured = id; }
+ hasPointerCapture(id: number) { return this.captured === id; }
+ releasePointerCapture(id: number) {
+ this.captured = undefined;
+ this.dispatch("lostpointercapture", {pointerId: id});
+ }
+ remove() { this.isConnected = false; this.parentElement.children = this.parentElement.children.filter(child => child !== this); }
+}
+
+const settle = async () => {
+ for (let index = 0; index < 8; index++) {
+ await Promise.resolve();
+ }
+};
+
+const setup = () => {
+ const windowSelf = new Target();
+ const documentSelf = {defaultView: windowSelf, createElement: () => {
+ const element = new Element();
+ element.ownerDocument = documentSelf;
+ return element;
+ }};
+ Object.assign(windowSelf, {getComputedStyle: (element: Element) => ({width: String(element.offsetWidth),
+ paddingRight: "20px", borderRightWidth: "0px"})});
+ const parent = documentSelf.createElement();
+ parent.baseWidth = 1000;
+ parent.left = 0;
+ const block = documentSelf.createElement();
+ block.style.height = "300px";
+ const host = documentSelf.createElement();
+ host.style.setProperty("--mindmap-view-height", "300px");
+ parent.appendChild(block);
+ block.appendChild(host);
+ const commits: ListMindmapSize[] = [];
+ let allowed = true;
+ let prepare = async () => true;
+ let observe: () => void;
+ const exports: {bindListMindmapResize?: (options: unknown) => {refresh: () => void, destroy: () => void}} = {};
+ runInNewContext(compiled, {exports, console,
+ MutationObserver: class {
+ constructor(callback: () => void) { observe = callback; }
+ observe() {}
+ disconnect() {}
+ }});
+ const binding = exports.bindListMindmapResize({block, host, labels: {width: "Width", height: "Height"},
+ canResize: () => allowed, prepare: () => prepare(), commit: async (size: ListMindmapSize) => {
+ commits.push({...size});
+ if (size.width !== undefined) {
+ block.style.width = `${size.width}px`;
+ host.baseWidth = size.width;
+ }
+ if (size.height !== undefined) {
+ block.style.height = `${size.height}px`;
+ host.style.setProperty("--mindmap-view-height", `${size.height}px`);
+ }
+ return true;
+ }});
+ const handle = (axis = "both") => host.children.find(child => child.dataset.resizeAxis === axis);
+ return {block, host, parent, windowSelf, commits, binding, handle,
+ setAllowed: (value: boolean) => { allowed = value; binding.refresh(); },
+ prepare: (callback: () => Promise<boolean>) => prepare = callback,
+ observe: () => observe(),
+ start: async (axis = "both", extra = {}) => {
+ handle(axis).dispatch("pointerdown", extra);
+ await settle();
+ },
+ move: (x: number, y: number, extra = {}) => windowSelf.dispatch("pointermove", {clientX: x, clientY: y, ...extra}),
+ end: async (x: number, y: number, extra = {}) => {
+ windowSelf.dispatch("pointerup", {clientX: x, clientY: y, ...extra});
+ await settle();
+ }};
+};
+
+test("resize geometry separates axes, accounts for editor scale and preserves already compact blocks", () => {
+ const initial = {width: 500, height: 300, blockWidth: 500, maxWidth: 600, scaleX: 2, scaleY: 2};
+ assert.deepEqual(getListMindmapResizeSize(initial, "both", 100, -100), {width: 550, height: 250});
+ assert.deepEqual(getListMindmapResizeSize(initial, "width", 1000, 100), {width: 600});
+ assert.deepEqual(getListMindmapResizeSize(initial, "both", -2000, -2000), {width: 120, height: 80});
+ assert.deepEqual(getListMindmapResizeSize({...initial, width: 60, height: 40}, "both", -100, -100), {width: 60, height: 40});
+ assert.deepEqual(getListMindmapResizeSize({...initial, maxWidth: 400}, "both", 0, 0), {width: 500, height: 300});
+});
+
+for (const pointerType of ["mouse", "touch"]) {
+ test(`${pointerType} corner drag previews only the host and commits both dimensions once on release`, async () => {
+ const fixture = setup();
+ const before = fixture.block.getAttribute("style");
+ await fixture.start("both", {pointerType});
+ fixture.move(650, 400);
+ assert.equal(fixture.host.style.width, "650px");
+ assert.equal(fixture.host.style.getPropertyValue("--mindmap-view-height"), "400px");
+ assert.equal(fixture.block.getAttribute("style"), before);
+ assert.equal(fixture.commits.length, 0);
+ fixture.move(700, 450);
+ await fixture.end(700, 450);
+ assert.deepEqual(fixture.commits, [{width: 700, height: 450}]);
+ assert.equal(fixture.host.style.width, "");
+ assert.equal(fixture.host.style.getPropertyValue("--mindmap-view-height"), "450px");
+ assert.equal(fixture.handle().captured, undefined);
+ assert.equal(fixture.handle().dispatch("touchstart").stopped, true);
+ assert.equal(fixture.handle().getAttribute("data-prevent-swipe"), "true");
+ });
+}
+
+test("individual handles preserve the other dimension and respect the parent content boundary", async () => {
+ const fixture = setup();
+ await fixture.start("width");
+ await fixture.end(2000, 1000);
+ assert.deepEqual(fixture.commits, [{width: 960}]);
+ await fixture.start("height");
+ await fixture.end(10, 200);
+ assert.deepEqual(fixture.commits[1], {height: 200});
+});
+
+for (const interruption of ["pointercancel", "lostpointercapture", "blur", "Escape", "destroy", "readonly", "fullscreen"]) {
+ test(`${interruption} restores the preview without saving`, async () => {
+ const fixture = setup();
+ await fixture.start();
+ fixture.move(650, 400);
+ if (interruption === "lostpointercapture") {
+ fixture.handle().dispatch(interruption);
+ } else if (interruption === "Escape") {
+ fixture.windowSelf.dispatch("keydown", {key: "Escape"});
+ } else if (interruption === "destroy") {
+ fixture.binding.destroy();
+ } else if (interruption === "readonly") {
+ fixture.setAllowed(false);
+ } else if (interruption === "fullscreen") {
+ fixture.host.classList.add("fullscreen");
+ fixture.observe();
+ } else {
+ fixture.windowSelf.dispatch(interruption);
+ }
+ await fixture.end(650, 400);
+ assert.deepEqual(fixture.commits, []);
+ assert.equal(fixture.host.style.width, "");
+ assert.equal(fixture.host.style.getPropertyValue("--mindmap-view-height"), "300px");
+ });
+}
+
+test("read-only, full screen and superblock widths cannot be resized", async () => {
+ const fixture = setup();
+ fixture.setAllowed(false);
+ assert.ok(fixture.host.children.every(handle => handle.hidden));
+ await fixture.start();
+ await fixture.end(650, 400);
+ fixture.setAllowed(true);
+ fixture.parent.classList.add("sb");
+ fixture.binding.refresh();
+ assert.equal(fixture.handle("width").hidden, true);
+ assert.equal(fixture.handle().hidden, true);
+ assert.equal(fixture.handle("height").hidden, false);
+ await fixture.start();
+ await fixture.end(650, 400);
+ assert.deepEqual(fixture.commits, []);
+ await fixture.start("height");
+ await fixture.end(650, 400);
+ assert.deepEqual(fixture.commits, [{height: 400}]);
+});
+
+test("late editor completion cannot resurrect a released or destroyed drag", async () => {
+ for (const destroy of [false, true]) {
+ const fixture = setup();
+ let release: (ready: boolean) => void;
+ fixture.prepare(() => new Promise(resolve => release = resolve));
+ await fixture.start();
+ fixture.move(650, 400);
+ if (destroy) {
+ fixture.binding.destroy();
+ } else {
+ await fixture.end(650, 400);
+ }
+ release(true);
+ await settle();
+ assert.deepEqual(fixture.commits, []);
+ assert.equal(fixture.host.style.width, "");
+ }
+});
+
+test("a click, failed editor save or unrelated pointer does not save a size", async () => {
+ const fixture = setup();
+ await fixture.start();
+ fixture.move(700, 400, {pointerId: 2});
+ await fixture.end(500, 300);
+ fixture.prepare(async () => false);
+ await fixture.start();
+ await fixture.end(700, 400);
+ assert.deepEqual(fixture.commits, []);
+});
+
+test("concurrent source style changes cancel the drag without replacing newer dimensions", async () => {
+ const fixture = setup();
+ await fixture.start();
+ fixture.move(650, 400);
+ fixture.block.style.height = "50vh";
+ await fixture.end(700, 450);
+ assert.deepEqual(fixture.commits, []);
+ assert.equal(fixture.block.style.height, "50vh");
+ assert.equal(fixture.host.style.getPropertyValue("--mindmap-view-height"), "50vh");
+});
+
+test("source refresh preserves an active preview but cancels when the saved dimensions change", async () => {
+ const fixture = setup();
+ await fixture.start();
+ fixture.move(650, 400);
+ fixture.host.style.setProperty("--mindmap-view-height", fixture.block.style.height);
+ fixture.binding.refresh();
+ assert.equal(fixture.host.style.getPropertyValue("--mindmap-view-height"), "400px");
+ fixture.block.style.height = "50vh";
+ fixture.host.style.setProperty("--mindmap-view-height", fixture.block.style.height);
+ fixture.binding.refresh();
+ assert.equal(fixture.host.style.getPropertyValue("--mindmap-view-height"), "50vh");
+ await fixture.end(700, 450);
+ assert.deepEqual(fixture.commits, []);
+});
+
+test("focused handles support precise keyboard resizing without consuming unrelated arrows", async () => {
+ const fixture = setup();
+ assert.equal(fixture.handle("width").dispatch("keydown", {key: "ArrowUp"}).defaultPrevented, false);
+ assert.equal(fixture.handle("width").dispatch("keydown", {key: "ArrowRight"}).defaultPrevented, true);
+ await settle();
+ assert.deepEqual(fixture.commits, [{width: 510}]);
+ fixture.handle("height").dispatch("keydown", {key: "ArrowDown", shiftKey: true});
+ await settle();
+ assert.deepEqual(fixture.commits[1], {height: 301});
+ fixture.binding.destroy();
+ assert.ok([...fixture.windowSelf.listeners.values()].every(listeners => listeners.size === 0));
+});
+
+test("handle focus navigation and typing never reach canvas node shortcuts", () => {
+ const fixture = setup();
+ let canvasKeys = 0;
+ fixture.host.addEventListener("keydown", () => canvasKeys++);
+ for (const key of ["Tab", "Enter", "Delete", "Backspace", "a", "ArrowUp"]) {
+ const event = fixture.handle("width").dispatch("keydown", {key});
+ assert.equal(event.defaultPrevented, false, key);
+ assert.equal(event.stopped, true, key);
+ }
+ assert.equal(canvasKeys, 0);
+});
diff --git a/app/src/protyle/render/listMindmap/resize.ts b/app/src/protyle/render/listMindmap/resize.ts
new file mode 100644
index 0000000000..88e1bcdfbd
--- /dev/null
+++ b/app/src/protyle/render/listMindmap/resize.ts
@@ -0,0 +1,291 @@
+type ResizeAxis = "width" | "height" | "both";
+
+export interface ListMindmapSize {
+ width?: number;
+ height?: number;
+}
+
+interface ResizeOptions {
+ block: HTMLElement;
+ host: HTMLElement;
+ labels: {width: string, height: string};
+ canResize: () => boolean;
+ prepare: () => Promise<boolean>;
+ commit: (size: ListMindmapSize) => Promise<boolean>;
+}
+
+interface ResizeGeometry {
+ width: number;
+ height: number;
+ blockWidth: number;
+ scaleX: number;
+ scaleY: number;
+ maxWidth: number;
+}
+
+export const getListMindmapResizeSize = (geometry: ResizeGeometry, axis: ResizeAxis, x: number, y: number) => {
+ const size: ListMindmapSize = {};
+ if (axis !== "height") {
+ size.width = x === 0 ? geometry.width : Math.round(Math.min(geometry.maxWidth,
+ Math.max(Math.min(120, geometry.width, geometry.maxWidth), geometry.width + x / geometry.scaleX)));
+ }
+ if (axis !== "width") {
+ size.height = Math.round(Math.max(Math.min(80, geometry.height), geometry.height + y / geometry.scaleY));
+ }
+ return size;
+};
+
+// 拖动期间只改变派生视图,松手后一次性更新源块,避免预览尺寸进入其他正文事务。
+export const bindListMindmapResize = (options: ResizeOptions) => {
+ const {block, host} = options;
+ const documentSelf = host.ownerDocument;
+ const windowSelf = documentSelf.defaultView;
+ const handles = new Map<ResizeAxis, HTMLElement>();
+ let disposed = false;
+ let saving = false;
+ let sequence = 0;
+ let active: {
+ handle: HTMLElement, axis: ResizeAxis, id: number, x: number, y: number,
+ lastX: number, lastY: number, geometry?: ResizeGeometry, size?: ListMindmapSize,
+ width: string, height: string, heightPriority: string, sourceStyle: string,
+ };
+ const horizontal = () => !block.parentElement?.classList.contains("sb");
+ const available = () => !disposed && block.isConnected && host.parentElement === block &&
+ !host.classList.contains("fullscreen") && options.canResize();
+ const allowed = (axis: ResizeAxis) => available() && (axis === "height" || horizontal());
+ const describeSize = (handle: HTMLElement, axis: "width" | "height", value: number) => {
+ handle.setAttribute("aria-valuemin", "0");
+ handle.setAttribute("aria-valuemax", String(Math.max(value,
+ axis === "width" ? block.parentElement?.offsetWidth || value : windowSelf.innerHeight || value)));
+ handle.setAttribute("aria-valuenow", String(value));
+ handle.setAttribute("aria-valuetext", `${value}px`);
+ };
+ const geometry = (): ResizeGeometry => {
+ const rect = host.getBoundingClientRect();
+ const parent = block.parentElement;
+ const parentRect = parent.getBoundingClientRect();
+ const parentStyle = windowSelf.getComputedStyle(parent);
+ const scaleX = rect.width / host.offsetWidth || 1;
+ const scaleY = rect.height / host.offsetHeight || 1;
+ const parentScale = parentRect.width / parent.offsetWidth || scaleX;
+ const rightInset = parseFloat(parentStyle.paddingRight) + parseFloat(parentStyle.borderRightWidth);
+ return {
+ width: host.offsetWidth, height: host.offsetHeight,
+ blockWidth: parseFloat(windowSelf.getComputedStyle(block).width) || block.offsetWidth,
+ scaleX, scaleY,
+ maxWidth: Math.max(1, (parentRect.right - (rightInset || 0) * parentScale - rect.left) / scaleX),
+ };
+ };
+ const restore = () => {
+ const previous = active;
+ active = undefined;
+ if (!previous) {
+ return;
+ }
+ host.style.width = previous.width;
+ const changed = (block.getAttribute("style") || "") !== previous.sourceStyle;
+ const height = changed ? block.style.height : previous.height;
+ if (height) {
+ host.style.setProperty("--mindmap-view-height", height, changed ? "" : previous.heightPriority);
+ } else {
+ host.style.removeProperty("--mindmap-view-height");
+ }
+ previous.handle.classList.remove("touch-resize-active");
+ if (previous.handle.hasPointerCapture(previous.id)) {
+ previous.handle.releasePointerCapture(previous.id);
+ }
+ return previous;
+ };
+ const cancel = () => {
+ sequence++;
+ restore();
+ };
+ const save = async (size: ListMindmapSize, initial: ResizeGeometry) => {
+ const next: ListMindmapSize = {};
+ if (size.width !== undefined && size.width !== initial.width) {
+ next.width = Math.max(1, initial.blockWidth + size.width - initial.width);
+ }
+ if (size.height !== undefined && size.height !== initial.height) {
+ next.height = size.height;
+ }
+ if (next.width === undefined && next.height === undefined) {
+ return;
+ }
+ saving = true;
+ try {
+ await options.commit(next);
+ } catch (error) {
+ console.error(error);
+ } finally {
+ saving = false;
+ }
+ };
+ const preview = () => {
+ if (!active?.geometry) {
+ return;
+ }
+ if (!allowed(active.axis) || (block.getAttribute("style") || "") !== active.sourceStyle) {
+ cancel();
+ return;
+ }
+ active.size = getListMindmapResizeSize(active.geometry, active.axis,
+ active.lastX - active.x, active.lastY - active.y);
+ if (active.axis !== "both") {
+ describeSize(active.handle, active.axis, active.size[active.axis]);
+ }
+ if (active.size.width !== undefined) {
+ host.style.width = `${active.size.width}px`;
+ }
+ if (active.size.height !== undefined) {
+ host.style.setProperty("--mindmap-view-height", `${active.size.height}px`);
+ }
+ };
+ const move = (event: PointerEvent) => {
+ if (!active || event.pointerId !== active.id) {
+ return;
+ }
+ event.preventDefault();
+ event.stopPropagation();
+ active.lastX = event.clientX;
+ active.lastY = event.clientY;
+ preview();
+ };
+ const end = (event: PointerEvent) => {
+ if (!active || event.pointerId !== active.id) {
+ return;
+ }
+ event.preventDefault();
+ event.stopPropagation();
+ move(event);
+ const previous = restore();
+ sequence++;
+ if (previous?.geometry && previous.size && allowed(previous.axis)) {
+ void save(previous.size, previous.geometry);
+ }
+ };
+ const interrupted = (event: PointerEvent) => {
+ if (active?.id === event.pointerId) {
+ cancel();
+ }
+ };
+ const keyDown = (event: KeyboardEvent) => {
+ if (active && event.key === "Escape") {
+ event.preventDefault();
+ event.stopImmediatePropagation();
+ cancel();
+ }
+ };
+ const stopTouch = (event: Event) => event.stopPropagation();
+ for (const axis of ["width", "height", "both"] as const) {
+ const handle = documentSelf.createElement("div");
+ handle.className = `resize__${axis === "width" ? "r" : axis === "height" ? "d" : "rd"} mindmap-view__resize`;
+ handle.dataset.resizeAxis = axis;
+ handle.setAttribute("data-prevent-swipe", "true");
+ if (axis !== "both") {
+ handle.setAttribute("role", "separator");
+ handle.setAttribute("aria-label", options.labels[axis]);
+ handle.setAttribute("aria-orientation", axis === "width" ? "vertical" : "horizontal");
+ handle.tabIndex = 0;
+ } else {
+ // 键盘通过两个单轴把手操作,双轴角落仅作为指针命中区域。
+ handle.setAttribute("aria-hidden", "true");
+ }
+ handle.addEventListener("pointerdown", event => {
+ if (active || saving || event.button !== 0 || !event.isPrimary || !allowed(axis)) {
+ return;
+ }
+ event.preventDefault();
+ event.stopPropagation();
+ const current = ++sequence;
+ active = {handle, axis, id: event.pointerId, x: event.clientX, y: event.clientY,
+ lastX: event.clientX, lastY: event.clientY, width: host.style.width,
+ height: host.style.getPropertyValue("--mindmap-view-height"),
+ heightPriority: host.style.getPropertyPriority("--mindmap-view-height"),
+ sourceStyle: block.getAttribute("style") || ""};
+ handle.setPointerCapture(event.pointerId);
+ handle.classList.add("touch-resize-active");
+ void options.prepare().then(ready => {
+ if (current !== sequence || !active) {
+ return;
+ }
+ if (!ready || !allowed(axis)) {
+ cancel();
+ return;
+ }
+ active.geometry = geometry();
+ active.width = host.style.width;
+ active.height = host.style.getPropertyValue("--mindmap-view-height");
+ active.heightPriority = host.style.getPropertyPriority("--mindmap-view-height");
+ active.sourceStyle = block.getAttribute("style") || "";
+ preview();
+ }).catch(error => {
+ if (current === sequence) {
+ cancel();
+ }
+ console.error(error);
+ });
+ });
+ handle.addEventListener("lostpointercapture", interrupted);
+ handle.addEventListener("keydown", event => {
+ // 把手保留 Tab 的默认焦点导航,不把按键交给画布新增或删除节点。
+ event.stopPropagation();
+ const key = event.key;
+ if (active || saving || event.altKey || event.ctrlKey || event.metaKey || !allowed(axis) ||
+ !["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(key) ||
+ axis === "width" && ["ArrowUp", "ArrowDown"].includes(key) ||
+ axis === "height" && ["ArrowLeft", "ArrowRight"].includes(key)) {
+ return;
+ }
+ event.preventDefault();
+ event.stopImmediatePropagation();
+ const current = ++sequence;
+ saving = true;
+ void options.prepare().then(async ready => {
+ if (!ready || current !== sequence || !allowed(axis)) {
+ return;
+ }
+ const initial = geometry();
+ const step = event.shiftKey ? 1 : 10;
+ const x = key === "ArrowLeft" ? -step : key === "ArrowRight" ? step : 0;
+ const y = key === "ArrowUp" ? -step : key === "ArrowDown" ? step : 0;
+ await save(getListMindmapResizeSize(initial,
+ x ? "width" : "height", x * initial.scaleX, y * initial.scaleY), initial);
+ }).catch(error => console.error(error)).finally(() => saving = false);
+ });
+ ["touchstart", "touchmove", "touchend", "touchcancel"].forEach(type => handle.addEventListener(type, stopTouch));
+ handles.set(axis, handle);
+ host.appendChild(handle);
+ }
+ const refresh = () => {
+ handles.forEach((handle, axis) => {
+ handle.hidden = !allowed(axis);
+ if (axis !== "both") {
+ describeSize(handle, axis, axis === "width" ? host.offsetWidth : host.offsetHeight);
+ }
+ });
+ if (active && !allowed(active.axis)) {
+ cancel();
+ } else {
+ preview();
+ }
+ };
+ const observer = new MutationObserver(refresh);
+ observer.observe(host, {attributes: true, attributeFilter: ["class"]});
+ windowSelf.addEventListener("pointermove", move, {capture: true, passive: false});
+ windowSelf.addEventListener("pointerup", end, {capture: true, passive: false});
+ windowSelf.addEventListener("pointercancel", interrupted, true);
+ windowSelf.addEventListener("blur", cancel);
+ windowSelf.addEventListener("keydown", keyDown, true);
+ refresh();
+ return {refresh, destroy: () => {
+ disposed = true;
+ cancel();
+ observer.disconnect();
+ windowSelf.removeEventListener("pointermove", move, true);
+ windowSelf.removeEventListener("pointerup", end, true);
+ windowSelf.removeEventListener("pointercancel", interrupted, true);
+ windowSelf.removeEventListener("blur", cancel);
+ windowSelf.removeEventListener("keydown", keyDown, true);
+ handles.forEach(handle => handle.remove());
+ }};
+};
diff --git a/app/src/protyle/render/listMindmap/resizeTransaction.test.ts b/app/src/protyle/render/listMindmap/resizeTransaction.test.ts
new file mode 100644
index 0000000000..6464267a38
--- /dev/null
+++ b/app/src/protyle/render/listMindmap/resizeTransaction.test.ts
@@ -0,0 +1,66 @@
+import * as assert from "node:assert/strict";
+import {readFileSync} from "node:fs";
+import {test} from "node:test";
+import {runInNewContext} from "node:vm";
+import {createSourceFile, isClassDeclaration, isPropertyAssignment, ScriptTarget, transpileModule} from "typescript";
+
+test("resizing uses one source update with both dimensions and retains the exact undo source", async () => {
+ const source = createSourceFile("index.ts", readFileSync("src/protyle/render/listMindmap/index.ts", "utf8"),
+ ScriptTarget.ES2021, true);
+ const controller = source.statements.find(item => isClassDeclaration(item) && item.name?.text === "ListMindmapController");
+ assert.ok(controller && isClassDeclaration(controller));
+ let callback = "";
+ const visit = (item: import("typescript").Node) => {
+ if (isPropertyAssignment(item) && item.name.getText(source) === "commit") {
+ callback = item.initializer.getText(source);
+ }
+ item.forEachChild(visit);
+ };
+ visit(controller);
+ assert.ok(callback);
+ const change = controller.members.find(item => item.name?.getText(source) === "change");
+ assert.ok(change);
+ const compiled = transpileModule(`class Controller {
+ ${change.getText(source)}
+ constructor(list) { this.list = list; this.commit = ${callback}; }
+ }
+ globalThis.Controller = Controller;`, {compilerOptions: {target: ScriptTarget.ES2021}}).outputText;
+ let title = "Before editing";
+ const list = {isConnected: true, parentElement: {classList: {contains: () => false}},
+ style: {width: "50%", height: "40vh", flex: ""},
+ get outerHTML() { return JSON.stringify({style: this.style, title}); }};
+ const transactions: {before: string, after: string}[] = [];
+ const root = {id: "root", children: [] as unknown[]};
+ const context: any = {
+ canEdit: () => true, readListMindmap: () => ({root, nodes: new Map([["root", root]])}),
+ getListMindmapSiblingIDs: () => new Map(), normalizeListMindmapSummaryMetadata: () => {},
+ cleanListMindmapHTML: (html: string) => html,
+ setBlockHeight: (block: typeof list, height: string) => block.style.height = height,
+ updateTransaction: (_owner: unknown, _list: unknown, before: string) => transactions.push({before, after: list.outerHTML}),
+ showMessage: (message: string) => assert.fail(message), window: {siyuan: {languages: {listMindmapInvalid: "Invalid"}}}, console,
+ };
+ runInNewContext(compiled, context);
+ const target = Object.assign(new context.Controller(list), {owner: {},
+ view: {getSelectedId: () => "root"}, refresh() {}, activeEditor: {finish: async () => {
+ title = "Saved node content";
+ return true;
+ }}});
+ assert.equal(await target.commit({width: 320, height: 180}), true);
+ assert.equal(transactions.length, 1);
+ assert.deepEqual(JSON.parse(transactions[0].before), {
+ style: {width: "50%", height: "40vh", flex: ""}, title: "Saved node content",
+ });
+ assert.deepEqual(JSON.parse(transactions[0].after), {
+ style: {width: "320px", height: "180px", flex: "none"}, title: "Saved node content",
+ });
+ for (let cycle = 0; cycle < 2; cycle++) {
+ Object.assign(list.style, JSON.parse(transactions[0].before).style);
+ assert.equal(list.style.width, "50%");
+ assert.equal(list.style.height, "40vh");
+ Object.assign(list.style, JSON.parse(transactions[0].after).style);
+ assert.equal(list.style.width, "320px");
+ assert.equal(list.style.height, "180px");
+ }
+ assert.equal(await target.commit({width: 320, height: 180}), true);
+ assert.equal(transactions.length, 1, "unchanged dimensions do not create another transaction");
+});
diff --git a/docs/LIST-MINDMAP.md b/docs/LIST-MINDMAP.md
index 094b2a5261..d5c206011c 100644
--- a/docs/LIST-MINDMAP.md
+++ b/docs/LIST-MINDMAP.md
@@ -25,6 +25,8 @@
- 选中关系线后,空心圆标出连接起点,实心圆标出连接终点,与箭头方向无关;拖动圆形手柄更换对应节点,可连接的节点会高亮;松手后重新计算路径并保存到同一事务,保留关系文字和样式,支持撤销;落在空白处、原节点、自身或已有的同向连接上不修改关系线;节点上的具体连接位置仍由系统自动选择,不支持自由拖动端点位置
- 节点默认无背景、不显示边框,正文格式通过节点内的 Protyle 编辑;选中节点后,脑图面板底部显示单排配色工具栏,仅展示节点配色及颜色管理入口,复用外观面板中的文字色与背景色组合,包含内置及自定义颜色并遵循其顺序和可见性,可恢复默认色;点击树连线或关系线,在脑图面板底部显示对应的设置菜单,线条颜色复用外观背景色,菜单不显示标题栏、虚线及宽度控件;双击关系线文字,在原位置显示输入框进行编辑
- 滚轮或触控板滚动用于移动画布,Ctrl + 滚轮或触控板双指捏合以鼠标位置为中心缩放;工具栏提供缩放、适应画布和全屏;全屏沿用编辑器的窗口内全屏及窗口控件避让,点击全屏按钮或按 Esc 退出并回到原列表位置
+- 鼠标移入脑图外框时显示尺寸手柄,右边缘调整宽度、下边缘调整高度、右下角同时调整宽高,触屏可直接拖动;调整的是块在文档中的尺寸,不改变内部画布缩放,原有块菜单宽高设置仍可使用;松手保存一次可撤销的修改,Esc 或指针取消恢复原尺寸
+- 尺寸手柄获得键盘焦点时,方向键按 10px 调整对应尺寸,Shift + 方向键按 1px 调整,仅作用于该手柄;只读、锁定及全屏状态不显示手柄,超级块的直接子块只提供高度手柄,宽度仍由超级块分栏分隔线调整
- 选中范围首节点后点击工具栏的概要按钮,再点击末端同级节点,创建连续范围的方括号概要;范围不能跨层、重叠或嵌套,移动端使用相同的点选方式
- 选择概要范围时也可使用上下方向键选择末端节点,Enter 确认范围,Esc 取消
- 双击概要文字或使用底部编辑按钮修改纯文本,Enter 保存、Esc 取消;底部面板支持配色与删除,Delete 和 Backspace 也可删除选中的概要,操作进入文档撤销记录