mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 08:30:42 +02:00
This commit is contained in:
parent
2bf5f6be64
commit
386a0927da
4 changed files with 71 additions and 11 deletions
|
@ -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") {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
6
app/src/types/protyle.d.ts
vendored
6
app/src/types/protyle.d.ts
vendored
|
@ -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 */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue