mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-18 06:03:22 +08:00
remove proxy
This commit is contained in:
parent
21b93e65f8
commit
744dab5601
@ -1,7 +1,6 @@
|
||||
import { EditorState, Plugin, Transaction } from 'prosemirror-state'
|
||||
import { EditorView } from 'prosemirror-view'
|
||||
import { Schema, DOMParser, Node } from 'prosemirror-model'
|
||||
import magicMethods from './utilities/magicMethods'
|
||||
import elementFromString from './utilities/elementFromString'
|
||||
import getNodeAttributes from './helpers/getNodeAttributes'
|
||||
import getMarkAttributes from './helpers/getMarkAttributes'
|
||||
@ -29,11 +28,8 @@ export interface HTMLElement {
|
||||
editor?: Editor
|
||||
}
|
||||
|
||||
@magicMethods
|
||||
export class Editor extends EventEmitter {
|
||||
|
||||
private proxy!: Editor
|
||||
|
||||
private commandManager!: CommandManager
|
||||
|
||||
public extensionManager!: ExtensionManager
|
||||
@ -69,13 +65,6 @@ export class Editor extends EventEmitter {
|
||||
constructor(options: Partial<EditorOptions> = {}) {
|
||||
super()
|
||||
this.options = { ...this.options, ...options }
|
||||
this.on('createdProxy', this.init)
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called after the proxy is initialized.
|
||||
*/
|
||||
private init(): void {
|
||||
this.createExtensionManager()
|
||||
this.createCommandManager()
|
||||
this.createSchema()
|
||||
@ -95,16 +84,6 @@ export class Editor extends EventEmitter {
|
||||
}, 0)
|
||||
}
|
||||
|
||||
/**
|
||||
* A magic method to call commands.
|
||||
*
|
||||
* @param name The name of the command
|
||||
*/
|
||||
// eslint-disable-next-line
|
||||
private __get(name: string) {
|
||||
// TODO: maybe remove proxy
|
||||
}
|
||||
|
||||
/**
|
||||
* An object of all registered commands.
|
||||
*/
|
||||
@ -201,14 +180,14 @@ export class Editor extends EventEmitter {
|
||||
return ['extension', 'node', 'mark'].includes(extension?.type)
|
||||
})
|
||||
|
||||
this.extensionManager = new ExtensionManager(allExtensions, this.proxy)
|
||||
this.extensionManager = new ExtensionManager(allExtensions, this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an command manager.
|
||||
*/
|
||||
private createCommandManager(): void {
|
||||
this.commandManager = new CommandManager(this.proxy, this.extensionManager.commands)
|
||||
this.commandManager = new CommandManager(this, this.extensionManager.commands)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -243,7 +222,7 @@ export class Editor extends EventEmitter {
|
||||
// Let’s store the editor instance in the DOM element.
|
||||
// So we’ll have access to it for tests.
|
||||
const dom = this.view.dom as HTMLElement
|
||||
dom.editor = this.proxy
|
||||
dom.editor = this
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,34 +0,0 @@
|
||||
export default function magicMethods(Clazz: any): any {
|
||||
const classHandler = Object.create(null)
|
||||
|
||||
classHandler.construct = (_: any, args: any) => {
|
||||
const instance = new Clazz(...args)
|
||||
const instanceHandler = Object.create(null)
|
||||
const get = Object.getOwnPropertyDescriptor(Clazz.prototype, '__get')
|
||||
|
||||
if (get) {
|
||||
instanceHandler.get = (target: any, name: any) => {
|
||||
if (typeof name !== 'string') {
|
||||
return
|
||||
}
|
||||
|
||||
const exists = name in target
|
||||
|| name.startsWith('_')
|
||||
|| ['then', 'catch'].includes(name)
|
||||
|
||||
if (exists) {
|
||||
return target[name]
|
||||
}
|
||||
|
||||
return get.value.call(target, name)
|
||||
}
|
||||
}
|
||||
|
||||
instance.proxy = new Proxy(instance, instanceHandler)
|
||||
instance.emit('createdProxy')
|
||||
|
||||
return instance.proxy
|
||||
}
|
||||
|
||||
return new Proxy(Clazz, classHandler)
|
||||
}
|
Loading…
Reference in New Issue
Block a user