mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-01 09:29:02 +08:00
refactoring
This commit is contained in:
parent
486d0e0f5f
commit
a067259da1
@ -11,14 +11,16 @@ import { gapCursor } from 'prosemirror-gapcursor'
|
|||||||
import elementFromString from './utils/elementFromString'
|
import elementFromString from './utils/elementFromString'
|
||||||
import injectCSS from './utils/injectCSS'
|
import injectCSS from './utils/injectCSS'
|
||||||
import ExtensionManager from './ExtensionManager'
|
import ExtensionManager from './ExtensionManager'
|
||||||
|
import Extension from './Extension'
|
||||||
|
import Node from './Node'
|
||||||
|
|
||||||
type EditorContent = string | JSON
|
type EditorContent = string | JSON
|
||||||
type Command = (next: Function, editor: Editor, ...args: any) => any
|
type Command = (next: Function, editor: Editor, ...args: any) => any
|
||||||
|
|
||||||
interface Options {
|
interface Options {
|
||||||
element?: Node
|
element?: globalThis.Node
|
||||||
content: EditorContent
|
content: EditorContent
|
||||||
extensions: [any?]
|
extensions: (Extension | Node)[]
|
||||||
injectCSS: Boolean
|
injectCSS: Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,9 +18,9 @@ export default abstract class Extension {
|
|||||||
|
|
||||||
public type = 'extension'
|
public type = 'extension'
|
||||||
|
|
||||||
protected created() {}
|
public created() {}
|
||||||
|
|
||||||
protected bindEditor(editor: Editor): void {
|
public bindEditor(editor: Editor): void {
|
||||||
this.editor = editor
|
this.editor = editor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
import { keymap } from 'prosemirror-keymap'
|
import { keymap } from 'prosemirror-keymap'
|
||||||
import collect from 'collect.js'
|
import collect from 'collect.js'
|
||||||
import { Editor } from './Editor'
|
import { Editor } from './Editor'
|
||||||
|
import Extension from './Extension'
|
||||||
|
import Node from './Node'
|
||||||
|
|
||||||
export default class ExtensionManager {
|
export default class ExtensionManager {
|
||||||
|
|
||||||
extensions: [any?]
|
extensions: (Extension | Node)[]
|
||||||
|
|
||||||
constructor(extensions: any = [], editor: Editor) {
|
constructor(extensions: (Extension | Node)[], editor: Editor) {
|
||||||
this.extensions = extensions
|
this.extensions = extensions
|
||||||
this.extensions.forEach(extension => {
|
this.extensions.forEach(extension => {
|
||||||
extension.bindEditor(editor)
|
extension.bindEditor(editor)
|
||||||
@ -15,7 +17,7 @@ export default class ExtensionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get topNode() {
|
get topNode() {
|
||||||
const topNode = this.extensions.find(extension => extension.topNode)
|
const topNode = collect(this.extensions).firstWhere('topNode', true)
|
||||||
|
|
||||||
if (topNode) {
|
if (topNode) {
|
||||||
return topNode.name
|
return topNode.name
|
||||||
|
Loading…
Reference in New Issue
Block a user