This commit is contained in:
Vanessa 2023-11-28 17:19:22 +08:00
parent 2bf5f6be64
commit 386a0927da
4 changed files with 71 additions and 11 deletions

View file

@ -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") {

View file

@ -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);
}
}

View file

@ -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 {

View file

@ -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 */