Skip to content

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

:art: Improve mind map task states and node controls https://github.com/siyuan-note/siyuan/issues/19677

Vanessafdaf9dc8fa08
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 166bd6b8bf..f26f882711 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": "20260919234652"
+ "updated": "20260920104521"
},
"Children": [
{
@@ -11956,7 +11956,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20210106154319-ans1gna",
- "updated": "20260919232200"
+ "updated": "20260920104521"
},
"Children": [
{
@@ -11969,6 +11969,20 @@
}
]
},
+ {
+ "ID": "20260920104521-uqot5qy",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20260920104521-uqot5qy",
+ "updated": "20260920104521"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "The list mind map displays task checkboxes, including built-in and custom states. Icons, text colors, and strikethrough follow the original task list. Click a checkbox to toggle its state; right-click it or use the task status button in the selected node toolbar to choose a state or enter a custom marker. The task status shortcut below also works on a selected task node. Changes update the original list and support undo and redo; read-only views and exports only display states."
+ }
+ ]
+ },
{
"ID": "20210106154319-4oe7doq",
"Type": "NodeTable",
@@ -11980,7 +11994,7 @@
"Properties": {
"colgroup": "||",
"id": "20210106154319-4oe7doq",
- "updated": "20260919232200"
+ "updated": "20260920104521"
},
"Children": [
{
@@ -12232,7 +12246,7 @@
"Children": [
{
"Type": "NodeText",
- "Data": "Task list"
+ "Data": "Task list, or a selected task node in the list mind map"
}
]
}
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 39d41f0266..370fbf1900 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": "20260919234652"
+ "updated": "20260920104521"
},
"Children": [
{
@@ -11944,7 +11944,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20201227133317-x02vhoh",
- "updated": "20260919232200"
+ "updated": "20260920104521"
},
"Children": [
{
@@ -11953,6 +11953,20 @@
}
]
},
+ {
+ "ID": "20260920104521-bxv8u21",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20260920104521-bxv8u21",
+ "updated": "20260920104521"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "列表脑图显示任务复选框,支持内置状态和自定义状态,图标、正文颜色及删除线与原始任务列表一致。单击复选框切换状态;右键复选框,或使用选中节点工具栏中的任务状态按钮,可以选择状态或输入自定义标记。下表中的任务状态切换快捷键也适用于选中的任务节点。修改同步到原始列表,支持撤销和重做;只读视图和导出内容仅展示状态。"
+ }
+ ]
+ },
{
"ID": "20201227133317-yv5msrs",
"Type": "NodeTable",
@@ -11964,7 +11978,7 @@
"Properties": {
"colgroup": "||",
"id": "20201227133317-yv5msrs",
- "updated": "20260919232200"
+ "updated": "20260920104521"
},
"Children": [
{
@@ -12212,7 +12226,7 @@
"Children": [
{
"Type": "NodeText",
- "Data": "任务列表"
+ "Data": "任务列表,或列表脑图中选中的任务节点"
}
]
}
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 537f3be6f2..c830b0a491 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": "20260919234652"
+ "updated": "20260920104521"
},
"Children": [
{
@@ -11956,7 +11956,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20211226122652-td76oes",
- "updated": "20260919232200"
+ "updated": "20260920104521"
},
"Children": [
{
@@ -11965,6 +11965,20 @@
}
]
},
+ {
+ "ID": "20260920104521-18sbty5",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20260920104521-18sbty5",
+ "updated": "20260920104521"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "列表心智圖顯示任務覈取方塊,支援內建狀態和自訂狀態,圖示、內文色彩及刪除線與原始任務列表一致。點擊覈取方塊可切換狀態;在覈取方塊上按右鍵,或使用所選節點工具列中的任務狀態按鈕,可以選擇狀態或輸入自訂標記。下表中的任務狀態切換快捷鍵也適用於選取的任務節點。修改會同步至原始列表,支援復原和重做;唯讀檢視與匯出內容僅顯示狀態。"
+ }
+ ]
+ },
{
"ID": "20211226122652-qj1o02k",
"Type": "NodeTable",
@@ -11976,7 +11990,7 @@
"Properties": {
"colgroup": "||",
"id": "20211226122652-qj1o02k",
- "updated": "20260919232200"
+ "updated": "20260920104521"
},
"Children": [
{
@@ -12224,7 +12238,7 @@
"Children": [
{
"Type": "NodeText",
- "Data": "任務列表"
+ "Data": "任務列表,或列表心智圖中選取的任務節點"
}
]
}
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 ae9d2cb1e9..387103bd81 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": "20260919234652"
+ "updated": "20260920104521"
},
"Children": [
{
@@ -11900,7 +11900,7 @@
"Properties": {
"ID": "20240530101000-uaq4ub6",
"id": "20240530101000-yl0e0sq",
- "updated": "20260919232200"
+ "updated": "20260920104521"
},
"Children": [
{
@@ -11919,6 +11919,20 @@
}
]
},
+ {
+ "ID": "20260920104521-21dfduv",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20260920104521-21dfduv",
+ "updated": "20260920104521"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "リストのマインドマップにはタスクのチェックボックスが表示され、組み込み状態とカスタム状態に対応しています。アイコン、本文の色、取り消し線は元のタスクリストと同じです。チェックボックスをクリックすると状態が切り替わります。右クリックするか、選択したノードのツールバーにあるタスク状態ボタンを使うと、状態の選択やカスタム記号の入力ができます。下表のタスク状態切り替えショートカットは、選択したタスクノードでも使えます。変更は元のリストに反映され、元に戻す操作とやり直しに対応しています。読み取り専用ビューとエクスポートでは状態の表示のみ行います。"
+ }
+ ]
+ },
{
"ID": "20240530101000-wqr5cs1",
"Type": "NodeTable",
@@ -11930,7 +11944,7 @@
"Properties": {
"colgroup": "||",
"id": "20240530101000-wqr5cs1",
- "updated": "20260919232200"
+ "updated": "20260920104521"
},
"Children": [
{
@@ -12182,7 +12196,7 @@
"Children": [
{
"Type": "NodeText",
- "Data": "タスクリスト"
+ "Data": "タスクリスト、またはリストのマインドマップで選択したタスクノード"
}
]
}
diff --git a/app/src/assets/scss/component/_typography.scss b/app/src/assets/scss/component/_typography.scss
index ed850cd59d..518b362dd0 100644
--- a/app/src/assets/scss/component/_typography.scss
+++ b/app/src/assets/scss/component/_typography.scss
@@ -904,8 +904,7 @@
position: relative;
&--done:not([data-task="/"]) > div[data-node-id].p {
- color: var(--b3-theme-on-surface-light);
- text-decoration: line-through;
+ @include task.completed-text;
}
input {
diff --git a/app/src/assets/scss/protyle/_list-mindmap.scss b/app/src/assets/scss/protyle/_list-mindmap.scss
index 0aa017b6af..32d21c0080 100644
--- a/app/src/assets/scss/protyle/_list-mindmap.scss
+++ b/app/src/assets/scss/protyle/_list-mindmap.scss
@@ -1,4 +1,5 @@
@use "../util/mixin" as *;
+@use "task";
.protyle-wysiwyg,
.b3-typography {
@@ -148,11 +149,11 @@
&__node {
position: absolute;
- min-width: 64px;
+ min-width: 32px;
max-width: 300px;
width: max-content;
min-height: 32px;
- padding: 4px 12px;
+ padding: 4px 6px;
box-sizing: border-box;
border: 0;
border-radius: var(--b3-border-radius);
@@ -257,7 +258,7 @@
}
&__content {
- min-width: 36px;
+ min-width: 0;
min-height: 24px;
overflow-wrap: anywhere;
@@ -324,6 +325,73 @@
}
}
+ &__node[data-task] {
+ display: grid;
+ grid-template-columns: max-content minmax(0, 1fr);
+ column-gap: 6px;
+ align-items: start;
+
+ > .list-mindmap__content {
+ grid-column: 2;
+ grid-row: 1;
+ }
+ }
+
+ &__task {
+ position: relative;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ grid-column: 1;
+ grid-row: 1;
+ justify-self: start;
+ margin-top: calc((1.5em - max(14px, 1em - 4px)) / 2);
+ padding: 0;
+ border: 0;
+ border-radius: var(--b3-border-radius);
+ background: transparent;
+ color: var(--b3-theme-on-surface);
+ font: inherit;
+ cursor: pointer;
+ transition: var(--b3-transition);
+
+ &::after {
+ @include protyle-list-action-background(var(--b3-border-radius));
+ }
+
+ &:hover:not(:disabled) {
+ @include protyle-list-action-hover;
+ }
+
+ &:disabled {
+ cursor: default;
+ }
+
+ &:focus-visible {
+ outline: 1px solid var(--b3-theme-primary);
+ }
+
+ svg {
+ width: max(14px, 1em - 4px);
+ height: max(14px, 1em - 4px);
+ display: block;
+ position: relative;
+ z-index: 1;
+ fill: currentColor;
+ pointer-events: none;
+ }
+ }
+
+ &__node.protyle-task--done:not([data-task="/"]) > .list-mindmap__content {
+ > .p {
+ @include task.completed-text;
+ }
+
+ &.list-mindmap__editor .protyle-wysiwyg > .p {
+ @include task.completed-text;
+ }
+ }
+
&__editor .protyle-content[data-padding-mode] {
container-type: normal;
}
@@ -459,10 +527,26 @@
}
> .list-mindmap__add-bridge {
- bottom: -11px;
+ bottom: -12px;
+
+ // 补齐右下角斜向移出的路径,避免鼠标先落到连线上而收起操作按钮。
+ &::before {
+ content: "";
+ position: absolute;
+ right: 100%;
+ bottom: 0;
+ width: 12px;
+ height: 12px;
+ }
}
}
+ &__node--selected > &__add-child,
+ &__node--selected > &__fold,
+ &__node--selected > &__add-bridge,
+ &__node--line-hover > &__add-child,
+ &__node--line-hover > &__fold,
+ &__node--line-hover > &__add-bridge,
&__node:hover > &__add-child,
&__node:hover > &__fold,
&__node:focus-within > &__fold,
@@ -473,15 +557,6 @@
opacity: 1;
}
- @media (hover: none) {
- &__node--selected > &__fold,
- &__node--selected > &__add-child,
- &__node--selected > &__add-bridge {
- visibility: visible;
- opacity: 1;
- }
- }
-
&__viewport--dragging &__add-child,
&__viewport--dragging &__add-bridge {
visibility: hidden;
diff --git a/app/src/assets/scss/protyle/_task.scss b/app/src/assets/scss/protyle/_task.scss
index c30a8a0a17..72c6e483c2 100644
--- a/app/src/assets/scss/protyle/_task.scss
+++ b/app/src/assets/scss/protyle/_task.scss
@@ -1,6 +1,11 @@
@use "sass:string";
-.protyle-wysiwyg, .b3-typography {
+@mixin completed-text {
+ color: var(--b3-theme-on-surface-light);
+ text-decoration: line-through;
+}
+
+.protyle-wysiwyg, .b3-typography, .list-mindmap {
.protyle-action--task[data-task] {
--task-marker: attr(data-task);
}
@@ -85,7 +90,6 @@
.li[data-task="-"] > div.p,
.li > .protyle-action--task[data-task="-"] ~ div.p,
.tabs-task[data-task="-"] ~ .tabs-tab-label {
- color: var(--b3-theme-on-surface-light);
- text-decoration: line-through;
+ @include completed-text;
}
}
diff --git a/app/src/assets/scss/protyle/_wysiwyg.scss b/app/src/assets/scss/protyle/_wysiwyg.scss
index 9d86e77e81..f2067aee3b 100644
--- a/app/src/assets/scss/protyle/_wysiwyg.scss
+++ b/app/src/assets/scss/protyle/_wysiwyg.scss
@@ -287,15 +287,7 @@
}
&::after {
- content: "";
- position: absolute;
- top: 50%;
- left: 50%;
- height: max(18px, 1em);
- width: max(18px, 1em);
- margin: min(-9px, -0.5em) 0 0 min(-9px, -0.5em);
- border-radius: 50%;
- transition: var(--b3-transition);
+ @include mixin.protyle-list-action-background;
}
svg {
@@ -955,11 +947,7 @@
cursor: pointer;
&:hover {
- &::after {
- background-color: var(--b3-list-icon-hover);
- }
-
- color: var(--b3-theme-on-background);
+ @include mixin.protyle-list-action-hover;
}
}
diff --git a/app/src/assets/scss/util/_mixin.scss b/app/src/assets/scss/util/_mixin.scss
index 5cc1ee04e2..291a80634e 100644
--- a/app/src/assets/scss/util/_mixin.scss
+++ b/app/src/assets/scss/util/_mixin.scss
@@ -1,3 +1,23 @@
+@mixin protyle-list-action-background($radius: 50%) {
+ content: "";
+ position: absolute;
+ top: 50%;
+ left: 50%;
+ height: max(18px, 1em);
+ width: max(18px, 1em);
+ margin: min(-9px, -0.5em) 0 0 min(-9px, -0.5em);
+ border-radius: $radius;
+ transition: var(--b3-transition);
+}
+
+@mixin protyle-list-action-hover {
+ &::after {
+ background-color: var(--b3-list-icon-hover);
+ }
+
+ color: var(--b3-theme-on-background);
+}
+
@mixin protyle-toolbar-surface {
background-color: var(--b3-theme-background);
box-shadow: var(--b3-dialog-shadow);
diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.ts
index 0823925c32..83b9472fa5 100644
--- a/app/src/protyle/export/index.ts
+++ b/app/src/protyle/export/index.ts
@@ -22,6 +22,7 @@ const getExportLanguages = () => {
const keys = new Set([
"copy", "mindmap", "fontSize", "bold", "italic", "colorFont", "color", "undo", "redo", "fold", "collapse", "expand",
"fullscreen", "exitFullscreen", "zoomIn", "zoomOut", "delete", "close", "connect", "text",
+ "task", "taskStatusTodo", "taskStatusInProgress", "taskStatusDone", "taskStatusCanceled", "customTaskStatus",
]);
const languages = Object.fromEntries(Object.entries(window.siyuan.languages)
.filter(([key]) => keys.has(key) || key.startsWith("listMindmap")));
diff --git a/app/src/protyle/export/listMindmapExport.test.ts b/app/src/protyle/export/listMindmapExport.test.ts
index d7130f9499..c4d40d326d 100644
--- a/app/src/protyle/export/listMindmapExport.test.ts
+++ b/app/src/protyle/export/listMindmapExport.test.ts
@@ -21,6 +21,12 @@ test("mind map export labels preserve localized text without closing the generat
listMindmapToList: "List view",
fullscreen: "Fullscreen",
exitFullscreen: "Exit fullscreen",
+ task: "Task",
+ taskStatusTodo: "To do",
+ taskStatusInProgress: "In progress",
+ taskStatusDone: "Done",
+ taskStatusCanceled: "Canceled",
+ customTaskStatus: "Custom status",
unrelated: "Not exported",
};
const compiled = transpileModule(`(${declaration.initializer.getText(source)})()`, {
diff --git a/app/src/protyle/render/listMindmap/index.ts b/app/src/protyle/render/listMindmap/index.ts
index 520b974a5b..c3dd34053c 100644
--- a/app/src/protyle/render/listMindmap/index.ts
+++ b/app/src/protyle/render/listMindmap/index.ts
@@ -3,7 +3,10 @@ import {showMessage} from "../../../dialog/message";
import {fetchSyncPost} from "../../../util/fetch";
import {normalizeHTMLAssetIFrameBlockDOM} from "../../../asset/html";
import {updateTransaction, transaction} from "../../wysiwyg/transaction";
-import {genListItemElement} from "../../wysiwyg/list";
+import {genListItemElement, setTaskListItemMarker} from "../../wysiwyg/list";
+import {nextTaskListMarker, nextTaskListStatus} from "../../wysiwyg/taskListMarker";
+import {getTaskStatusItems} from "../../wysiwyg/taskStatusDialog";
+import {Menu} from "../../../plugin/Menu";
import {completeTabsListSource} from "../../wysiwyg/tabsList";
import {waitForPendingTransactions} from "../../util/transactionQueue";
import {hideAllElements, hideElements} from "../../ui/hideElements";
@@ -70,6 +73,7 @@ class ListMindmapController {
private activeEditor?: {finish: () => Promise<boolean>, destroy: () => void};
private editRequest = 0;
private disposed = false;
+ private taskChanges: Promise<void> = Promise.resolve();
constructor(owner: IProtyle, list: HTMLElement) {
this.owner = owner;
@@ -174,6 +178,21 @@ class ListMindmapController {
}
},
onEdit: (id, contentHost) => this.edit(id, contentHost),
+ onTaskToggle: (id, cycle) => this.setTask(id, cycle ? nextTaskListStatus : nextTaskListMarker),
+ onTaskMenu: (id, anchor) => {
+ if (!canEdit(owner, list)) {
+ return;
+ }
+ const marker = readListMindmap(list).nodes.get(id)?.taskMarker;
+ if (marker === undefined) {
+ return;
+ }
+ const menu = new Menu();
+ getTaskStatusItems(marker, next => this.setTask(id, () => next)).forEach(item => menu.addItem(item));
+ const rect = anchor.getBoundingClientRect();
+ menu.open({x: rect.left, y: rect.bottom, h: rect.height});
+ },
+ isTaskCycle: event => matchHotKey(window.siyuan.config.keymap.editor.list.checkToggle, event),
onRootTitleChange: title => this.metadata(metadata => {
metadata.rootTitle = title;
}),
@@ -231,6 +250,32 @@ class ListMindmapController {
});
}
+ private setTask(id: string, next: (marker: string) => string) {
+ // 连续操作串行提交,正文保存后重新查找源节点,避免使用过期状态覆盖任务。
+ this.taskChanges = this.taskChanges.then(async () => {
+ if (this.disposed || !this.list.isConnected || !canEdit(this.owner, this.list) ||
+ (this.activeEditor && !await this.activeEditor.finish())) {
+ return;
+ }
+ if (this.disposed || !this.list.isConnected || !canEdit(this.owner, this.list)) {
+ return;
+ }
+ const node = readListMindmap(this.list).nodes.get(id);
+ if (node?.taskMarker === undefined) {
+ return;
+ }
+ const marker = next(node.taskMarker);
+ if (marker !== node.taskMarker) {
+ setTaskListItemMarker(this.owner, node.element, marker);
+ this.refresh();
+ }
+ }).catch(error => {
+ console.error(error);
+ showMessage(window.siyuan.languages.listMindmapInvalid);
+ });
+ return this.taskChanges;
+ }
+
private async change(change: () => unknown, editing = false) {
if (this.disposed || !this.list.isConnected || !canEdit(this.owner, this.list)) {
return false;
diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.ts
index 0b96ceb27c..3765678a66 100644
--- a/app/src/protyle/render/listMindmap/model.test.ts
+++ b/app/src/protyle/render/listMindmap/model.test.ts
@@ -107,7 +107,7 @@ test("layout rejects cyclic or invalid trees and supports deep nesting without r
assert.equal(layoutListMindmap(root).nodes.size, 5001);
});
-const browserCases = async (sourceCode: string, css: string) => {
+const browserCases = async (sourceCode: string, css: string, taskSource: string, taskCSS: string) => {
const check = require("node:assert/strict");
const api = new Function("mathRender", "Constants", sourceCode + "; return {readListMindmap, moveListMindmapNode, addListMindmapNode, " +
"deleteListMindmapNode, replaceListMindmapContent, cleanListMindmapHTML, remapListMindmapIDs, writeListMindmapMetadata, ListMindmapView};")(
@@ -413,7 +413,7 @@ const browserCases = async (sourceCode: string, css: string) => {
const targetRect = nodeElement(beta).getBoundingClientRect();
const sourcePoint = {x: sourceRect.left + sourceRect.width / 2, y: sourceRect.top + sourceRect.height / 2};
const targetPoint = {x: targetRect.left + targetRect.width / 2, y: targetRect.top + targetRect.height / 2};
- check.ok(sourceRect.width >= 64 && sourceRect.height >= 32);
+ check.ok(sourceRect.width >= 32 && sourceRect.height >= 32);
check.equal(host.querySelector("[data-node-id]"), null);
sendPointer(nodeElement(alpha), "pointerdown", sourcePoint.x, sourcePoint.y);
sendPointer(viewport, "pointerup", sourcePoint.x, sourcePoint.y);
@@ -539,6 +539,26 @@ const browserCases = async (sourceCode: string, css: string) => {
await clickMouse(addChildButton(beta));
check.equal(additions.length, beforeRejectedAddition + 1);
check.deepEqual(additions[additions.length - 1], [beta, "child"]);
+ // 鼠标从节点右下角斜向移出时,过渡区域必须连续,不能先落到连线上导致按钮消失。
+ view.clearSelection();
+ await moveMouse(nodeElement(alpha));
+ const branchRect = nodeElement(alpha).getBoundingClientRect();
+ const branchScale = branchRect.width / nodeElement(alpha).offsetWidth;
+ const cornerPoint = {x: Math.round(branchRect.right - 3 * branchScale),
+ y: Math.round(branchRect.bottom + 3 * branchScale)};
+ await nativeInput([{type: "mouseMove", ...cornerPoint}]);
+ await settle();
+ const expandedFold = nodeElement(alpha).querySelector<HTMLButtonElement>(".list-mindmap__fold");
+ check.equal(visiblyRendered(expandedFold), true, "the lower inner corner keeps the fold control visible");
+ check.equal(document.elementFromPoint(cornerPoint.x, cornerPoint.y)?.closest(".list-mindmap__node"), nodeElement(alpha),
+ "the lower corner selects the node instead of its connection");
+ await moveMouse(expandedFold);
+ const expandedPoint = centerPoint(expandedFold);
+ check.equal(document.elementFromPoint(expandedPoint.x, expandedPoint.y)?.closest("button"), expandedFold);
+ await clickMouse(nodeElement(alpha));
+ await moveMouse();
+ check.equal(visiblyRendered(expandedFold), true, "selected nodes keep their fold control visible without hovering");
+ check.equal(visiblyRendered(addChildButton(alpha)), true);
model.nodes.get(alpha).collapsed = true;
view.update(model);
await settle();
@@ -711,6 +731,8 @@ const browserCases = async (sourceCode: string, css: string) => {
view.update(model);
check.equal(host.querySelector("canvas").getContext("2d").strokeStyle, "#123456");
check.equal(getComputedStyle(nodeElement(beta)).borderWidth, "0px");
+ view.clearSelection();
+ await moveMouse();
await settle();
const parentBounds = nodeElement(model.nodes.get(beta).parentId).getBoundingClientRect();
const childBounds = nodeElement(beta).getBoundingClientRect();
@@ -719,8 +741,16 @@ const browserCases = async (sourceCode: string, css: string) => {
const lineY = (parentY + childBounds.bottom) / 2;
sendPointer(viewport, "pointermove", lineX, lineY);
check.equal(viewport.classList.contains("list-mindmap__viewport--line-hover"), true);
+ check.equal(visiblyRendered(addChildButton(beta)), true, "hovering a tree curve exposes its node controls");
+ check.equal(nodeElement(beta).getAttribute("aria-selected"), "false", "line hover does not change selection");
+ const alphaBounds = nodeElement(alpha).getBoundingClientRect();
+ sendPointer(viewport, "pointermove", alphaBounds.left + alphaBounds.width / 2, alphaBounds.bottom + 1);
+ check.equal(visiblyRendered(nodeElement(alpha).querySelector<HTMLButtonElement>(".list-mindmap__fold")), true,
+ "hovering a branch underline exposes its fold control");
+ check.equal(visiblyRendered(addChildButton(beta)), false, "moving to another line clears the previous node controls");
viewport.dispatchEvent(new PointerEvent("pointerleave"));
check.equal(viewport.classList.contains("list-mindmap__viewport--line-hover"), false);
+ check.equal(nodeElement(alpha).classList.contains("list-mindmap__node--line-hover"), false);
sendPointer(viewport, "pointerdown", lineX, lineY);
sendPointer(viewport, "pointerup", lineX, lineY);
check.equal(inspector.hidden, false, "clicking the tree curve opens its settings");
@@ -1150,6 +1180,161 @@ const browserCases = async (sourceCode: string, css: string) => {
anchor.click();
check.equal(exportClick, true, "export anchor clicks reach the existing navigation handler");
exportView.destroy();
+
+ // 真实列表与脑图逐项比较图标、删除线和颜色,覆盖导出及脱离编辑器容器的全屏布局。
+ const taskStyle = document.createElement("style");
+ taskStyle.textContent = taskCSS;
+ document.head.append(taskStyle);
+ lute.SetArbitraryTaskListItemMarker(true);
+ lute.SetDataTask(true);
+ const taskParent = document.createElement("div");
+ taskParent.className = "protyle-wysiwyg";
+ taskParent.style.setProperty("--b3-theme-on-surface-light", "#8899aa");
+ taskParent.style.setProperty("--b3-theme-on-background", "#223344");
+ taskParent.innerHTML = lute.Md2BlockDOM("* [ ] Task\n\n Second paragraph\n\n * [/] Child\n* Ordinary\n");
+ document.body.append(taskParent);
+ const taskList = taskParent.firstElementChild as HTMLElement;
+ const ordinaryItem = taskParent.querySelector<HTMLElement>('.li[data-subtype="u"]');
+ taskList.insertBefore(ordinaryItem, taskList.lastElementChild);
+ const taskItem = taskList.querySelector<HTMLElement>(".li");
+ const taskId = taskItem.dataset.nodeId;
+ const taskHost = document.createElement("div");
+ taskHost.style.width = "700px";
+ taskParent.append(taskHost);
+ const operations: {id: string, before: string, after: string}[] = [];
+ const taskAPI = new Function("readListMindmap", "canEdit", "Constants", "dayjs", "updateTransaction", "showMessage",
+ taskSource + "; return {setTaskListItemMarker, nextTaskListMarker, nextTaskListStatus, TaskController};")(
+ api.readListMindmap, (owner: any) => !owner.disabled && !owner.history && !owner.embedded,
+ {CB_GET_HISTORY: "history", ATTRIBUTE_EDITING: "data-editing"},
+ () => ({format: () => "20260920000000"}),
+ (_owner: unknown, element: HTMLElement, before: string) => operations.push({id: element.dataset.nodeId,
+ before, after: element.outerHTML}), () => check.fail("Task update failed"));
+ const owner = {disabled: false, history: false, embedded: false, options: {action: [] as string[]}};
+ let finishTask: boolean | Promise<boolean> = true;
+ let menus = 0;
+ let taskEdits = 0;
+ const taskView = new api.ListMindmapView({host: taskHost, model: api.readListMindmap(taskList),
+ labels: new Proxy({}, {get: (_target, key) => String(key)}), onExit: () => {},
+ onEdit: () => taskEdits++, onMove: () => check.fail("Task control started a drag"),
+ onRelationAdd: () => check.fail("Task control created a relation"),
+ finishEdit: () => finishTask, onTaskMenu: () => menus++,
+ isTaskCycle: (event: KeyboardEvent) => event.ctrlKey && event.key === "l",
+ onTaskToggle: (id: string, cycle: boolean) => controller.setTask(id,
+ cycle ? taskAPI.nextTaskListStatus : taskAPI.nextTaskListMarker)});
+ const controller = Object.assign(new taskAPI.TaskController(), {owner, list: taskList, disposed: false,
+ taskChanges: Promise.resolve(), refresh: () => taskView.update(api.readListMindmap(taskList))});
+ const taskNode = () => taskHost.querySelector<HTMLElement>(`[data-mindmap-id="${taskId}"]`);
+ const taskButton = () => taskNode().querySelector<HTMLButtonElement>(".list-mindmap__task");
+ const compare = () => {
+ const sourceAction = taskItem.querySelector(".protyle-action--task");
+ const button = taskButton();
+ check.equal(button.querySelector("use").getAttribute("xlink:href"),
+ sourceAction.querySelector("use").getAttribute("xlink:href"));
+ for (const property of ["content", "fontSize", "transform"] as const) {
+ check.equal(getComputedStyle(button, "::before")[property],
+ getComputedStyle(sourceAction, "::before")[property]);
+ }
+ for (const property of ["maskImage", "height"] as const) {
+ check.equal(getComputedStyle(button.querySelector("svg"))[property],
+ getComputedStyle(sourceAction.querySelector("svg"))[property]);
+ }
+ const originals = taskItem.querySelectorAll(":scope > .p");
+ const previews = taskNode().querySelectorAll(":scope > .list-mindmap__content > .p");
+ check.equal(previews.length, originals.length);
+ originals.forEach((original, index) => {
+ for (const property of ["color", "textDecorationLine"] as const) {
+ check.equal(getComputedStyle(previews[index])[property], getComputedStyle(original)[property]);
+ }
+ });
+ };
+ taskParent.style.fontSize = "16px";
+ taskParent.style.color = "#223344";
+ for (const marker of [" ", "/", "X", "x", "-", "?", "A", "\"", "&", "<", "\\"]) {
+ taskAPI.setTaskListItemMarker(owner, taskItem, marker);
+ controller.refresh();
+ await settle();
+ compare();
+ check.equal(taskNode().querySelector("[data-node-id]"), null);
+ check.equal(taskHost.querySelectorAll(".list-mindmap__task").length, 2);
+ check.equal(taskView.model.root.taskMarker, undefined, "virtual roots are not tasks");
+ const child = taskView.model.nodes.get(taskId).children[0];
+ check.equal(taskView.model.nodes.get(child.id).taskMarker, "/");
+ const childNode = taskHost.querySelector(`[data-mindmap-id="${child.id}"] .p`);
+ check.equal(getComputedStyle(childNode).textDecorationLine, "none", "parent state never styles child tasks");
+ }
+ const taskSourceHTML = taskList.outerHTML;
+ taskView.setReadOnly(true);
+ taskButton().click();
+ taskButton().dispatchEvent(new MouseEvent("contextmenu", {bubbles: true, cancelable: true}));
+ await settle();
+ check.equal(taskList.outerHTML, taskSourceHTML);
+ check.equal(menus, 0);
+ check.equal(taskButton().disabled, true);
+ taskView.setReadOnly(false);
+ check.equal(taskButton().disabled, false);
+ taskButton().dispatchEvent(new MouseEvent("contextmenu", {bubbles: true, cancelable: true}));
+ check.equal(menus, 1);
+ taskAPI.setTaskListItemMarker(owner, taskItem, " ");
+ controller.refresh();
+ operations.length = 0;
+ taskButton().click();
+ taskButton().click();
+ await controller.taskChanges;
+ check.equal(taskItem.dataset.task, " ");
+ check.equal(operations.length, 2);
+ check.ok(operations.every(operation => operation.id === taskId && !operation.after.includes("list-mindmap__")));
+ const operation = operations[0];
+ const replay = document.createElement("div");
+ for (const [html, marker] of [[operation.after, "X"], [operation.before, " "]] as const) {
+ replay.innerHTML = lute.SpinBlockDOM(html);
+ check.equal(replay.querySelector(".li").getAttribute("data-task"), marker, "transaction snapshots preserve redo and undo states");
+ }
+ taskButton().dispatchEvent(new KeyboardEvent("keydown", {key: "l", ctrlKey: true, bubbles: true, cancelable: true}));
+ await controller.taskChanges;
+ check.equal(taskItem.dataset.task, "/");
+ taskButton().dispatchEvent(new MouseEvent("dblclick", {bubbles: true}));
+ check.equal(taskEdits, 0);
+ finishTask = false;
+ taskButton().click();
+ await controller.taskChanges;
+ check.equal(taskItem.dataset.task, "/", "failed content saves prevent task changes");
+ finishTask = true;
+ for (const mode of ["disabled", "history", "embedded"] as const) {
+ owner[mode] = true;
+ await controller.setTask(taskId, () => "X");
+ check.equal(taskItem.dataset.task, "/");
+ owner[mode] = false;
+ }
+ let release: (result: boolean) => void;
+ controller.activeEditor = {finish: () => new Promise<boolean>(resolve => release = resolve)};
+ const pendingChange = controller.setTask(taskId, () => "X");
+ await Promise.resolve();
+ owner.disabled = true;
+ release(true);
+ await pendingChange;
+ check.equal(taskItem.dataset.task, "/", "permission is rechecked after content saves");
+ owner.disabled = false;
+ controller.activeEditor = undefined;
+ taskView.enterFullscreen();
+ check.equal(getComputedStyle(taskButton().querySelector("svg")).maskImage.includes("task-in-progress.svg"), true);
+ taskView.exitFullscreen();
+ // 导出 DOM 的标记可以位于任务图标上;真实任务根节点仍显示复选框。
+ const exportedTaskList = taskList.cloneNode(true) as HTMLElement;
+ exportedTaskList.querySelectorAll<HTMLElement>('.li[data-subtype="t"]').forEach(item => {
+ item.querySelector(".protyle-action--task").setAttribute("data-task", item.dataset.task);
+ item.removeAttribute("data-task");
+ });
+ check.equal(api.readListMindmap(exportedTaskList).nodes.get(taskId).taskMarker, "/");
+ exportedTaskList.querySelector(':scope > .li[data-subtype="u"]').remove();
+ const rootModel = api.readListMindmap(exportedTaskList);
+ check.equal(rootModel.root.virtual, false);
+ check.equal(rootModel.root.taskMarker, "/");
+ taskView.setReadOnly(true);
+ taskView.update(rootModel);
+ check.ok(taskButton());
+ taskView.destroy();
+ taskParent.remove();
+ taskStyle.remove();
hostParent.remove();
style.remove();
return "List mindmap DOM cases passed";
@@ -1171,6 +1356,21 @@ test("list mindmap mutations preserve block data in the real DOM and Lute", {
const css = require("sass").compile(path.resolve(__dirname, "../../../assets/scss/business/_block.scss")).css +
require("sass").compile(path.resolve(__dirname, "../../../assets/scss/business/_color.scss")).css +
require("sass").compile(path.resolve(__dirname, "../../../assets/scss/protyle/_list-mindmap.scss")).css;
+ const taskCSS = require("sass").compile(path.resolve(__dirname, "../../../assets/scss/protyle/_wysiwyg.scss")).css +
+ require("sass").compile(path.resolve(__dirname, "../../../assets/scss/component/_typography.scss")).css;
+ const indexSource = typescript.createSourceFile("index.ts", readFileSync(path.join(__dirname, "index.ts"), "utf8"),
+ typescript.ScriptTarget.Latest, true);
+ const controller = indexSource.statements.find(typescript.isClassDeclaration);
+ const setTask = controller.members.find(member => member.name?.getText(indexSource) === "setTask");
+ const listSource = typescript.createSourceFile("list.ts", readFileSync(path.join(__dirname, "../../wysiwyg/list.ts"), "utf8"),
+ typescript.ScriptTarget.Latest, true);
+ const setter = listSource.statements.filter(typescript.isVariableStatement).find(statement =>
+ statement.declarationList.declarations.some(item => item.name.getText(listSource) === "setTaskListItemMarker"));
+ const taskSource = compile(path.join(__dirname, "../../wysiwyg/taskListMarker.ts")) +
+ typescript.transpileModule(setter.getText(listSource).replace(/^export /, "") +
+ `\nclass TaskController {${setTask.getText(indexSource)}}`, {
+ compilerOptions: {target: typescript.ScriptTarget.ES2021},
+ }).outputText;
const lutePath = path.resolve(__dirname, "../../../../stage/protyle/js/lute/lute.min.js");
const code = `const {app, BrowserWindow, ipcMain} = require("electron");
app.setPath("userData", ${JSON.stringify(path.join(temporary, "profile"))});
@@ -1191,7 +1391,7 @@ app.whenReady().then(async () => {
await win.loadURL("data:text/html,<html><body></body></html>");
await win.webContents.executeJavaScript(require("node:fs").readFileSync(${JSON.stringify(lutePath)}, "utf8"));
const result = await win.webContents.executeJavaScript(${JSON.stringify(
- `const __name = value => value; (${browserCases.toString()})(${JSON.stringify(source)}, ${JSON.stringify(css)})`)});
+ `const __name = value => value; (${browserCases.toString()})(${JSON.stringify(source)}, ${JSON.stringify(css)}, ${JSON.stringify(taskSource)}, ${JSON.stringify(taskCSS)})`)});
console.log(result);
win.destroy();
app.exit(0);
diff --git a/app/src/protyle/render/listMindmap/model.ts b/app/src/protyle/render/listMindmap/model.ts
index 00c1c0ef3c..3b3db1f91a 100644
--- a/app/src/protyle/render/listMindmap/model.ts
+++ b/app/src/protyle/render/listMindmap/model.ts
@@ -40,6 +40,7 @@ export interface ListMindmapNode {
children: ListMindmapNode[];
collapsed: boolean;
virtual: boolean;
+ taskMarker?: string;
}
export interface ListMindmapModel {
@@ -196,6 +197,9 @@ export const readListMindmap = (list: HTMLElement): ListMindmapModel => {
children: [],
collapsed: item.getAttribute("fold") === "1",
virtual: false,
+ taskMarker: item.getAttribute("data-subtype") === "t" ?
+ item.getAttribute("data-task") ?? item.querySelector(":scope > .protyle-action--task")?.getAttribute("data-task") ??
+ (item.classList.contains("protyle-task--done") ? "X" : " ") : undefined,
};
current.parent.children.push(node);
nodes.set(id, node);
diff --git a/app/src/protyle/render/listMindmap/view.ts b/app/src/protyle/render/listMindmap/view.ts
index cdb5b8ba04..c5b6abe7db 100644
--- a/app/src/protyle/render/listMindmap/view.ts
+++ b/app/src/protyle/render/listMindmap/view.ts
@@ -35,6 +35,9 @@ export interface ListMindmapViewOptions {
onAdd?: (id: string, kind: "child" | "sibling") => void;
onDelete?: (id: string) => void;
onFold?: (id: string) => void;
+ onTaskToggle?: (id: string, cycle?: boolean) => void;
+ onTaskMenu?: (id: string, anchor: HTMLElement) => void;
+ isTaskCycle?: (event: KeyboardEvent) => boolean;
onUndo?: () => void;
onRedo?: () => void;
onNodeStyle?: (id: string, patch: Partial<ListMindmapNodeStyle>) => void;
@@ -311,6 +314,10 @@ export class ListMindmapView {
addChild.hidden = value;
addChild.disabled = value;
element.querySelector<HTMLElement>(".list-mindmap__add-bridge").hidden = value;
+ const task = element.querySelector<HTMLButtonElement>(".list-mindmap__task");
+ if (task) {
+ task.disabled = value;
+ }
});
this.updateSelection();
}
@@ -401,6 +408,7 @@ export class ListMindmapView {
element.setAttribute("aria-label", model.metadata.rootTitle || this.label("listMindmapRoot"));
}
element.classList.toggle("list-mindmap__node--root", id === model.root.id);
+ this.renderTask(element, id);
element.classList.toggle("list-mindmap__node--branch", node.children.length > 0);
element.style.backgroundColor = model.metadata.nodes[id]?.backgroundColor || "";
element.style.color = model.metadata.nodes[id]?.textColor || "";
@@ -846,6 +854,44 @@ export class ListMindmapView {
context.fill();
}
+ private renderTask(element: HTMLElement, id: string) {
+ const marker = this.model.nodes.get(id)?.taskMarker;
+ let task = element.querySelector<HTMLButtonElement>(".list-mindmap__task");
+ if (marker === undefined) {
+ task?.remove();
+ element.removeAttribute("data-task");
+ element.classList.remove("protyle-task--done");
+ return;
+ }
+ element.dataset.task = marker;
+ element.classList.toggle("protyle-task--done", marker !== " ");
+ if (!task) {
+ task = this.makeButton("task", "iconUncheck", () => {
+ if (!this.options.readOnly && this.model.nodes.get(id)?.taskMarker !== undefined) {
+ this.options.onTaskToggle?.(id);
+ }
+ });
+ task.className = "protyle-action protyle-action--task list-mindmap__task";
+ task.addEventListener("contextmenu", event => {
+ event.preventDefault();
+ event.stopPropagation();
+ this.finishThen(() => this.openTaskMenu(id, task));
+ });
+ element.prepend(task);
+ }
+ task.dataset.task = marker;
+ task.disabled = !!this.options.readOnly;
+ const key = {" ": "taskStatusTodo", "/": "taskStatusInProgress", X: "taskStatusDone", "-": "taskStatusCanceled"}[marker.toUpperCase()];
+ task.setAttribute("aria-label", key ? this.label(key) : `${this.label("customTaskStatus")} ${marker}`);
+ task.querySelector("use").setAttribute("xlink:href", marker === " " ? "#iconUncheck" : "#iconCheck");
+ }
+
+ private openTaskMenu(id: string, anchor: HTMLElement) {
+ if (!this.options.readOnly && this.model.nodes.get(id)?.taskMarker !== undefined) {
+ this.options.onTaskMenu?.(id, anchor);
+ }
+ }
+
private selectNode(id: string) {
const changed = this.selectedId !== id || !!this.selectedRelation;
this.selectedId = id;
@@ -1086,7 +1132,13 @@ export class ListMindmapView {
if (key === this.hoveredLine) {
return;
}
+ if (this.hoveredLine?.startsWith("edge:")) {
+ this.nodeElements.get(this.hoveredLine.slice(5))?.classList.remove("list-mindmap__node--line-hover");
+ }
this.hoveredLine = key;
+ if (key?.startsWith("edge:")) {
+ this.nodeElements.get(key.slice(5))?.classList.add("list-mindmap__node--line-hover");
+ }
this.viewport.classList.toggle("list-mindmap__viewport--line-hover", !!key);
this.draw();
}
@@ -1428,6 +1480,21 @@ export class ListMindmapView {
if (event.isComposing || target.closest("input, textarea, select, .list-mindmap__node--editing")) {
return;
}
+ if (!this.options.readOnly && this.options.isTaskCycle?.(event)) {
+ const id = target.closest<HTMLElement>(".list-mindmap__node")?.dataset.mindmapId || this.selectedId;
+ if (this.model.nodes.get(id)?.taskMarker !== undefined) {
+ event.preventDefault();
+ event.stopPropagation();
+ if (!event.repeat) {
+ this.finishThen(() => {
+ if (!this.options.readOnly) {
+ this.options.onTaskToggle?.(id, true);
+ }
+ });
+ }
+ }
+ return;
+ }
if (["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", " "].includes(event.key) &&
!this.editingId && !this.relationFrom && this.selectedId &&
!event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey &&
@@ -1591,6 +1658,10 @@ export class ListMindmapView {
}
this.inspector.append(nodePalette);
const node = this.model.nodes.get(id);
+ if (node?.taskMarker !== undefined && this.options.onTaskMenu) {
+ const task = squareButton("checkToggle", "iconCheck", () => this.openTaskMenu(id, task));
+ nodePalette.append(task);
+ }
if (node && !node.virtual && node !== this.model.root) {
nodePalette.append(squareButton("delete", "iconTrashcan", () => this.deleteSelection()));
}