An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Move batch heading conversion into the outline context menu https://github.com/siyuan-note/siyuan/issues/19138
Daniel6cc58985d88a
diff --git a/app/src/layout/dock/Outline.ts b/app/src/layout/dock/Outline.tsindex 6e086a4b23..dd0bdeb490 100644--- a/app/src/layout/dock/Outline.ts+++ b/app/src/layout/dock/Outline.ts@@ -35,7 +35,7 @@ import {} from "../../protyle/util/headingNumberCore";import {applyHeadingLevelUpdates, getHeadingLevelUpdateOperations} from "../../protyle/util/headingTransform";import {syncDocTitleIAL} from "../../protyle/util/docTitleIAL";-import {canBatchConvertHeadings, showHeadingBatchDialog, updateHeadingBatchButton} from "../../protyle/util/headingBatch";+import {canBatchConvertHeadings, showHeadingBatchDialog} from "../../protyle/util/headingBatch";export class Outline extends Model {public tree: Tree;@@ -92,8 +92,6 @@ export class Outline extends Model {<svg><use xlink:href="#iconContract"></use></svg></span><span class="${this.type === "local" ? "fn__none " : ""}fn__space"></span>- <button data-type="headingBatch" disabled class="block__icon ariaLabel" data-position="north" aria-label="${window.siyuan.languages.headingBatch}"><svg><use xlink:href="#iconHeadings"></use></svg></button>- <span class="fn__space"></span><span data-type="min" class="${this.type === "local" ? "fn__none " : ""}block__icon ariaLabel" data-position="north" aria-label="${window.siyuan.languages.min}${updateHotkeyAfterTip(window.siyuan.config.keymap.general.closeTab.custom)}"><svg><use xlink:href='#iconMin'></use></svg></span>@@ -264,16 +262,6 @@ export class Outline extends Model {if (target.classList.contains("block__icon")) {const type = target.getAttribute("data-type");switch (type) {- case "headingBatch": {- const protyle = getAllModels().editor.find(item =>- item.editor.protyle.block.rootID === this.blockId)?.editor.protyle;- if (canBatchConvertHeadings(protyle, this.blockId, this.isPreview)) {- void showHeadingBatchDialog(protyle, () =>- canBatchConvertHeadings(protyle, this.blockId, this.isPreview) && protyle.element.isConnected);- }- isFocus = false;- break;- }case "min":getDockByType("outline").toggleModel("outline", false, true);isFocus = false;@@ -707,11 +695,6 @@ export class Outline extends Model {this.notebookId = typeof notebookId === "undefined" ? "" : notebookId;}this.tree.updateData(data.data);- const protyle = getAllModels().editor.find(item =>- item.editor.protyle.block.rootID === this.blockId)?.editor.protyle;- const rootID = this.blockId;- updateHeadingBatchButton(this.headerElement.querySelector('[data-type="headingBatch"]'), protyle,- !!data.data?.length, () => rootID === this.blockId && canBatchConvertHeadings(protyle, rootID, this.isPreview));if (this.isPreview) {this.tree.element.querySelectorAll(".popover__block").forEach(item => {@@ -1078,6 +1061,20 @@ export class Outline extends Model {}).element);}+ const rootID = this.blockId;+ window.siyuan.menus.menu.append(new MenuItem({+ id: "headingBatch",+ icon: "iconHeadings",+ label: window.siyuan.languages.headingBatch,+ click: () => {+ const protyle = getAllModels().editor.find(item =>+ item.editor.protyle.block.rootID === rootID)?.editor.protyle;+ if (canBatchConvertHeadings(protyle, rootID, this.isPreview)) {+ void showHeadingBatchDialog(protyle, () => rootID === this.blockId &&+ canBatchConvertHeadings(protyle, rootID, this.isPreview) && protyle.element.isConnected);+ }+ }+ }).element);window.siyuan.menus.menu.append(new MenuItem({id: "separator_1", type: "separator"}).element);// 在前面插入同级标题diff --git a/app/src/mobile/dock/MobileOutline.ts b/app/src/mobile/dock/MobileOutline.tsindex 1ba262cd5d..c89d6a5b80 100644--- a/app/src/mobile/dock/MobileOutline.ts+++ b/app/src/mobile/dock/MobileOutline.ts@@ -20,7 +20,7 @@ import {dragOverScroll, stopScrollAnimation} from "../../boot/globalEvent/dragovimport {escapeHtml} from "../../util/escape";import {getFileTreeIconHTML} from "../../emoji/fileTreeIcon";import {syncDocTitleIAL} from "../../protyle/util/docTitleIAL";-import {canBatchConvertHeadings, showHeadingBatchDialog, updateHeadingBatchButton} from "../../protyle/util/headingBatch";+import {canBatchConvertHeadings, showHeadingBatchDialog} from "../../protyle/util/headingBatch";import {bindMousePointerTouchBridge, isMousePointerTouchEvent} from "../util/mousePointerTouchBridge";import {operationsMayChangeOutline,@@ -72,18 +72,10 @@ export class MobileOutline extends Model {<svg data-type="expandLevel" class="toolbar__icon"><use xlink:href="#iconList"></use></svg><svg data-type="expand" class="toolbar__icon"><use xlink:href="#iconExpand"></use></svg><svg data-type="collapse" class="toolbar__icon"><use xlink:href="#iconContract"></use></svg>- <button data-type="headingBatch" disabled class="toolbar__button" aria-label="${window.siyuan.languages.headingBatch}"><svg><use xlink:href="#iconHeadings"></use></svg></button></div><div class="b3-list-item fn__none" data-type="doc-title"></div><div class="fn__flex-1" style="padding: 3px 0 calc(8px + env(safe-area-inset-bottom))"></div>`;const inputElement = this.element.querySelector("input.b3-text-field.search__label") as HTMLInputElement;- this.element.querySelector('[data-type="headingBatch"]').addEventListener("click", () => {- const protyle = window.siyuan.mobile.editor?.protyle;- if (canBatchConvertHeadings(protyle, this.blockId, this.isPreview)) {- void showHeadingBatchDialog(protyle, () => window.siyuan.mobile.editor?.protyle === protyle &&- canBatchConvertHeadings(protyle, this.blockId, this.isPreview));- }- });inputElement.addEventListener("blur", () => {inputElement.classList.add("fn__none");const filterIconElement = inputElement.nextElementSibling as HTMLElement; // search 图标@@ -576,11 +568,6 @@ export class MobileOutline extends Model {}const scrollTop = this.tree.element.scrollTop;this.tree.updateData(data.data);- const protyle = window.siyuan.mobile.editor?.protyle;- const rootID = this.blockId;- updateHeadingBatchButton(this.element.querySelector('[data-type="headingBatch"]'), protyle,- !!data.data?.length, () => rootID === this.blockId && window.siyuan.mobile.editor?.protyle === protyle &&- canBatchConvertHeadings(protyle, rootID, this.isPreview));if (this.isPreview) {this.tree.element.querySelectorAll(".popover__block").forEach(item => {@@ -944,6 +931,20 @@ export class MobileOutline extends Model {}).element);}+ const rootID = this.blockId;+ window.siyuan.menus.menu.append(new MenuItem({+ id: "headingBatch",+ icon: "iconHeadings",+ label: window.siyuan.languages.headingBatch,+ click: () => {+ const protyle = window.siyuan.mobile.editor?.protyle;+ if (canBatchConvertHeadings(protyle, rootID, this.isPreview)) {+ void showHeadingBatchDialog(protyle, () => rootID === this.blockId &&+ window.siyuan.mobile.editor?.protyle === protyle &&+ canBatchConvertHeadings(protyle, rootID, this.isPreview));+ }+ }+ }).element);window.siyuan.menus.menu.append(new MenuItem({id: "separator_1", type: "separator"}).element);// 在前面插入同级标题diff --git a/app/src/protyle/util/headingBatch.ts b/app/src/protyle/util/headingBatch.tsindex 80fec0a49c..54f0778c94 100644--- a/app/src/protyle/util/headingBatch.ts+++ b/app/src/protyle/util/headingBatch.ts@@ -11,24 +11,6 @@ export const canBatchConvertHeadings = (protyle: IProtyle, rootID: string, previ!protyle.lite && !window.siyuan.config.readonly && !window.siyuan.isPublish;};-export const updateHeadingBatchButton = (button: HTMLButtonElement, protyle: IProtyle,- hasHeadings: boolean, isCurrent: () => boolean) => {- button.disabled = !isCurrent();- if (button.disabled || hasHeadings) {- return;- }- button.disabled = true;- // 大纲不展示引述块等容器内的标题,空大纲仍需按完整文档判断。- fetchPost("/api/block/getDocHeadingLevelTransaction", {- id: protyle.block.rootID,- notebook: protyle.notebookId,- }, response => {- if (button.isConnected && isCurrent()) {- button.disabled = !response.data?.counts?.some((count: number) => count > 0);- }- });-};-export const showHeadingBatchDialog = async (protyle: IProtyle, isCurrent: () => boolean) => {const rootID = protyle.block.rootID;const available = () => isCurrent() && canBatchConvertHeadings(protyle, rootID, false);