Skip to content

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

:art: fix https://github.com/siyuan-note/siyuan/issues/9762

Vanessa386a0927da61
diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts
index 31c08f30f3..ef990de423 100644
--- a/app/src/protyle/gutter/index.ts
+++ b/app/src/protyle/gutter/index.ts
@@ -401,8 +401,8 @@ export class Gutter {
label: string,
protyle: IProtyle,
selectsElement: Element[],
- type: string,
- level?: string
+ type: TTurnIntoOne,
+ level?: TTurnIntoOneSub
}) {
return {
icon: options.icon,
@@ -419,8 +419,8 @@ export class Gutter {
label: string,
protyle: IProtyle,
selectsElement: Element[],
- type: string,
- level?: number | string,
+ type: TTurnInto,
+ level?: number,
isContinue?: boolean
accelerator?: string
}) {
@@ -896,7 +896,6 @@ export class Gutter {
accelerator: window.siyuan.config.keymap.editor.heading.paragraph.custom,
protyle,
selectsElement: [nodeElement],
- level: 6,
type: "Blocks2Ps",
}));
if (subType !== "h1") {
diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.ts
index 2604877e22..6a7690873a 100644
--- a/app/src/protyle/index.ts
+++ b/app/src/protyle/index.ts
@@ -14,7 +14,13 @@ import {WYSIWYG} from "./wysiwyg";
import {Toolbar} from "./toolbar";
import {Gutter} from "./gutter";
import {Breadcrumb} from "./breadcrumb";
-import {onTransaction, transaction} from "./wysiwyg/transaction";
+import {
+ onTransaction,
+ transaction,
+ turnsIntoOneTransaction, turnsIntoTransaction,
+ updateBatchTransaction,
+ updateTransaction
+} from "./wysiwyg/transaction";
import {fetchPost} from "../util/fetch";
/// #if !MOBILE
import {Title} from "./header/Title";
@@ -31,6 +37,8 @@ import {getDocByScroll} from "./scroll/saveScroll";
import {App} from "../index";
import {insertHTML} from "./util/insertHTML";
import {avRender} from "./render/av/render";
+import {focusBlock, getEditorRange} from "./util/selection";
+import {hasClosestBlock} from "./util/hasClosest";
export class Protyle {
@@ -390,4 +398,51 @@ export class Protyle {
public transaction(doOperations: IOperation[], undoOperations?: IOperation[]) {
transaction(this.protyle, doOperations, undoOperations);
}
+
+ /**
+ * 多个块转换为一个块
+ * @param {TTurnIntoOneSub} [subType] type 为 "BlocksMergeSuperBlock" 时必传
+ */
+ public turnIntoOneTransaction(selectsElement: Element[], type: TTurnIntoOne, subType?: TTurnIntoOneSub) {
+ turnsIntoOneTransaction({
+ protyle: this.protyle,
+ selectsElement,
+ type,
+ level: subType
+ });
+ }
+
+ /**
+ * 多个块转换
+ * @param {Element} [nodeElement] 优先使用包含 protyle-wysiwyg--select 的块,否则使用 nodeElement 单块
+ * @param {number} [subType] type 为 "Blocks2Hs" 时必传
+ */
+ public turnIntoTransaction(nodeElement: Element, type: TTurnInto, subType?: number) {
+ turnsIntoTransaction({
+ protyle: this.protyle,
+ nodeElement,
+ type,
+ level: subType,
+ });
+ }
+
+ public updateTransaction(id: string, newHTML: string, html: string) {
+ updateTransaction(this.protyle, id, newHTML, html);
+ }
+
+ public updateBatchTransaction(nodeElements: Element[], cb: (e: HTMLElement) => void) {
+ updateBatchTransaction(nodeElements, this.protyle, cb);
+ }
+
+ public getRange(element: Element) {
+ getEditorRange(element);
+ }
+
+ public hasClosestBlock(element: Node) {
+ return hasClosestBlock(element);
+ }
+
+ public focusBlock(element: Element, toStart = true) {
+ return focusBlock(element, undefined, toStart);
+ }
}
diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts
index bbdfd03041..b427f40c00 100644
--- a/app/src/protyle/wysiwyg/transaction.ts
+++ b/app/src/protyle/wysiwyg/transaction.ts
@@ -723,8 +723,8 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo:
export const turnsIntoOneTransaction = (options: {
protyle: IProtyle,
selectsElement: Element[],
- type: string,
- level?: string
+ type: TTurnIntoOne,
+ level?: TTurnIntoOneSub
}) => {
let parentElement: Element;
const id = Lute.NewNodeID();
@@ -834,8 +834,8 @@ export const turnsIntoTransaction = (options: {
protyle: IProtyle,
selectsElement?: Element[],
nodeElement?: Element,
- type: string,
- level?: number | string,
+ type: TTurnInto,
+ level?: number,
isContinue?: boolean,
}) => {
let selectsElement: Element[] = options.selectsElement;
@@ -898,7 +898,7 @@ export const turnsIntoTransaction = (options: {
data: item.outerHTML
});
- if ((options.type === "Blocks2Ps" || options.type === "Blocks2Hs") && !options.isContinue) {
+ if (!options.isContinue) {
// @ts-ignore
item.outerHTML = options.protyle.lute[options.type](item.outerHTML, options.level);
} else {
diff --git a/app/src/types/protyle.d.ts b/app/src/types/protyle.d.ts
index c552238a35..062be23463 100644
--- a/app/src/types/protyle.d.ts
+++ b/app/src/types/protyle.d.ts
@@ -8,6 +8,12 @@ interface ILuteNode {
};
}
+type TTurnIntoOne = "BlocksMergeSuperBlock" | "Blocks2ULs" | "Blocks2OLs" | "Blocks2TLs" | "Blocks2Blockquote"
+
+type TTurnIntoOneSub = "row" | "col"
+
+type TTurnInto = "Blocks2Ps" | "Blocks2Hs"
+
type ILuteRenderCallback = (node: ILuteNode, entering: boolean) => [string, number];
/** @link https://ld246.com/article/1588412297062 */