chore: establish learning module baseline
This commit is contained in:
commit
2d04197f3f
2409 files changed
+533050
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import { EditorState } from 'prosemirror-state';
|
||||
import { type DirectEditorProps, EditorView } from 'prosemirror-view';
|
||||
import { Schema, DOMParser } from 'prosemirror-model';
|
||||
import { buildPlugins, type PluginOptions } from './plugins/index';
|
||||
import { schemaNodes, schemaMarks } from './schema/index';
|
||||
|
||||
const schema = new Schema({
|
||||
nodes: schemaNodes,
|
||||
marks: schemaMarks,
|
||||
});
|
||||
|
||||
export const createDocument = (content: string) => {
|
||||
const htmlString = `<div>${content}</div>`;
|
||||
const parser = new window.DOMParser();
|
||||
const element = parser.parseFromString(htmlString, 'text/html').body.firstElementChild;
|
||||
return DOMParser.fromSchema(schema).parse(element as Element);
|
||||
};
|
||||
|
||||
export const initProsemirrorEditor = (
|
||||
dom: Element,
|
||||
content: string,
|
||||
props: Omit<DirectEditorProps, 'state'>,
|
||||
pluginOptions?: PluginOptions,
|
||||
) => {
|
||||
return new EditorView(dom, {
|
||||
state: EditorState.create({
|
||||
doc: createDocument(content),
|
||||
plugins: buildPlugins(schema, pluginOptions),
|
||||
}),
|
||||
...props,
|
||||
});
|
||||
};
|
||||
Reference in new issue
Block a user