feat(engine):#87 增加 setMarkdown 方法
This commit is contained in:
parent
bc102a139b
commit
df3c9d62ab
|
@ -250,6 +250,34 @@ class ChangeModel implements ChangeInterface {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setMarkdown(text: string, callback?: (count: number) => void) {
|
||||||
|
const textNode = $(document.createTextNode(text));
|
||||||
|
this.engine.trigger('paste:markdown-before', textNode);
|
||||||
|
this.engine.trigger('paste:markdown', textNode);
|
||||||
|
this.engine.trigger('paste:markdown-after', textNode);
|
||||||
|
const { card, container } = this.engine;
|
||||||
|
textNode.get<Text>()?.normalize();
|
||||||
|
this.#nativeEvent.paste(
|
||||||
|
textNode.text(),
|
||||||
|
undefined,
|
||||||
|
callback,
|
||||||
|
true,
|
||||||
|
(
|
||||||
|
fragment: DocumentFragment,
|
||||||
|
_range?: RangeInterface,
|
||||||
|
_rangeCallback?: (range: RangeInterface) => void,
|
||||||
|
_followActiveMark?: boolean,
|
||||||
|
) => {
|
||||||
|
container.empty().append(fragment);
|
||||||
|
card.render(undefined, (count) => {
|
||||||
|
this.initValue(undefined, false);
|
||||||
|
this.engine.trigger('paste:after');
|
||||||
|
if (callback) callback(count);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
getOriginValue(container: NodeInterface = this.engine.container) {
|
getOriginValue(container: NodeInterface = this.engine.container) {
|
||||||
const { schema, conversion } = this.engine;
|
const { schema, conversion } = this.engine;
|
||||||
return new Parser(
|
return new Parser(
|
||||||
|
|
|
@ -203,6 +203,22 @@ class Engine<T extends EngineOptions = EngineOptions>
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setMarkdown(text: string, callback?: (count: number) => void) {
|
||||||
|
this.change.setMarkdown(text, (count) => {
|
||||||
|
this.normalize();
|
||||||
|
this.container.allChildren(true).forEach((child) => {
|
||||||
|
if (this.node.isInline(child)) {
|
||||||
|
this.inline.repairCursor(child);
|
||||||
|
} else if (this.node.isMark(child)) {
|
||||||
|
this.mark.repairCursor(child);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (callback) callback(count);
|
||||||
|
});
|
||||||
|
this.nodeId.generateAll(this.container);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
setJsonValue(value: Array<any>, callback?: (count: number) => void) {
|
setJsonValue(value: Array<any>, callback?: (count: number) => void) {
|
||||||
const dom = $(toDOM(value));
|
const dom = $(toDOM(value));
|
||||||
const attributes = dom.get<Element>()?.attributes;
|
const attributes = dom.get<Element>()?.attributes;
|
||||||
|
|
|
@ -239,6 +239,12 @@ export interface ChangeInterface {
|
||||||
* @param callback 异步渲染卡片后回调
|
* @param callback 异步渲染卡片后回调
|
||||||
*/
|
*/
|
||||||
setHtml(html: string, callback?: (count: number) => void): void;
|
setHtml(html: string, callback?: (count: number) => void): void;
|
||||||
|
/**
|
||||||
|
* 设置markdown,会格式化为合法的编辑器值
|
||||||
|
* @param text markdown文本
|
||||||
|
* @param callback 异步渲染卡片后回调
|
||||||
|
*/
|
||||||
|
setMarkdown(text: string, callback?: (count: number) => void): void;
|
||||||
/**
|
/**
|
||||||
* 获取编辑器值
|
* 获取编辑器值
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -156,6 +156,15 @@ export interface EngineInterface<T extends EngineOptions = EngineOptions>
|
||||||
* @param callback 异步渲染卡片后的回调
|
* @param callback 异步渲染卡片后的回调
|
||||||
*/
|
*/
|
||||||
setHtml(html: string, callback?: (count: number) => void): EngineInterface;
|
setHtml(html: string, callback?: (count: number) => void): EngineInterface;
|
||||||
|
/**
|
||||||
|
* 设置markdown,会格式化为合法的编辑器值
|
||||||
|
* @param text markdown文本
|
||||||
|
* @param callback 异步渲染卡片后回调
|
||||||
|
*/
|
||||||
|
setMarkdown(
|
||||||
|
text: string,
|
||||||
|
callback?: (count: number) => void,
|
||||||
|
): EngineInterface;
|
||||||
/**
|
/**
|
||||||
* 设置json格式值,主要用于协同
|
* 设置json格式值,主要用于协同
|
||||||
* @param callback 异步渲染卡片后的回调
|
* @param callback 异步渲染卡片后的回调
|
||||||
|
|
Loading…
Reference in New Issue