add basic lowlight extension

This commit is contained in:
Philipp Kühn
2021-04-02 00:07:40 +02:00
parent 4d882af5d7
commit 7adf1853d7
16 changed files with 476 additions and 0 deletions

View File

@@ -58,6 +58,7 @@ export class Editor extends EventEmitter {
parseOptions: {},
enableInputRules: true,
enablePasteRules: true,
onBeforeCreate: () => null,
onCreate: () => null,
onUpdate: () => null,
onSelectionUpdate: () => null,
@@ -75,6 +76,8 @@ export class Editor extends EventEmitter {
this.createExtensionManager()
this.createCommandManager()
this.createSchema()
this.on('beforeCreate', this.options.onCreate)
this.emit('beforeCreate', { editor: this })
this.createView()
this.injectCSS()
this.on('create', this.options.onCreate)

View File

@@ -94,6 +94,14 @@ declare module '@tiptap/core' {
[key: string]: any,
}) | null,
/**
* The editor is not ready yet.
*/
onBeforeCreate?: ((this: {
options: Options,
editor: Editor,
}) => void) | null,
/**
* The editor is ready.
*/

View File

@@ -43,6 +43,13 @@ export default class ExtensionManager {
}
}
// console.log(extension.config.onBeforeCreate)
if (typeof extension.config.onBeforeCreate === 'function') {
console.log('JOOO')
this.editor.on('beforeCreate', extension.config.onBeforeCreate.bind(context))
}
if (typeof extension.config.onCreate === 'function') {
this.editor.on('create', extension.config.onCreate.bind(context))
}

View File

@@ -104,6 +104,15 @@ declare module '@tiptap/core' {
[key: string]: any,
}) | null,
/**
* The editor is not ready yet.
*/
onBeforeCreate?: ((this: {
options: Options,
editor: Editor,
type: MarkType,
}) => void) | null,
/**
* The editor is ready.
*/

View File

@@ -109,6 +109,15 @@ declare module '@tiptap/core' {
[key: string]: any,
}) | null,
/**
* The editor is not ready yet.
*/
onBeforeCreate?: ((this: {
options: Options,
editor: Editor,
type: NodeType,
}) => void) | null,
/**
* The editor is ready.
*/

View File

@@ -29,6 +29,7 @@ export interface EditorOptions {
parseOptions: ParseOptions,
enableInputRules: boolean,
enablePasteRules: boolean,
onBeforeCreate: (props: { editor: Editor }) => void,
onCreate: (props: { editor: Editor }) => void,
onUpdate: (props: { editor: Editor }) => void,
onViewUpdate: (props: { editor: Editor }) => void,