mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 19:59:02 +08:00
add extension class
This commit is contained in:
parent
6f1aedb2b2
commit
3b291c3a3c
@ -1,3 +1,5 @@
|
||||
import { Editor } from './src/Editor'
|
||||
|
||||
export default Editor
|
||||
export default Editor
|
||||
export { default as Extension } from './src/Extension'
|
||||
export { default as Node } from './src/Node'
|
@ -12,11 +12,13 @@ import insertText from './commands/insertText'
|
||||
import insertHTML from './commands/insertHTML'
|
||||
import focus from './commands/focus'
|
||||
|
||||
type EditorContent = string | JSON
|
||||
|
||||
interface EditorOptions {
|
||||
element: Node
|
||||
content: string
|
||||
content: EditorContent
|
||||
}
|
||||
|
||||
|
||||
export class Editor {
|
||||
|
||||
private lastCommand = Promise.resolve()
|
||||
@ -84,7 +86,7 @@ export class Editor {
|
||||
return this[name](...args)
|
||||
}
|
||||
|
||||
private createDocument(content: any): any {
|
||||
private createDocument(content: EditorContent): any {
|
||||
// if (content === null) {
|
||||
// return this.schema.nodeFromJSON(this.options.emptyDocument)
|
||||
// }
|
||||
|
52
packages/tiptap-core/src/Extension.ts
Normal file
52
packages/tiptap-core/src/Extension.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import { Editor } from './Editor'
|
||||
|
||||
export default class Extension {
|
||||
|
||||
editor: any
|
||||
options: { [key: string]: any } = {}
|
||||
defaultOptions: { [key: string]: any } = {}
|
||||
|
||||
constructor(options = {}) {
|
||||
this.options = {
|
||||
...this.defaultOptions,
|
||||
...options,
|
||||
}
|
||||
}
|
||||
|
||||
init(): any {
|
||||
return null
|
||||
}
|
||||
|
||||
bindEditor(editor: Editor): void {
|
||||
this.editor = editor
|
||||
}
|
||||
|
||||
get name(): any {
|
||||
return null
|
||||
}
|
||||
|
||||
get type(): any {
|
||||
return 'extension'
|
||||
}
|
||||
|
||||
get update(): any {
|
||||
return () => {}
|
||||
}
|
||||
|
||||
get plugins(): any {
|
||||
return []
|
||||
}
|
||||
|
||||
inputRules(): any {
|
||||
return []
|
||||
}
|
||||
|
||||
pasteRules(): any {
|
||||
return []
|
||||
}
|
||||
|
||||
keys(): any {
|
||||
return {}
|
||||
}
|
||||
|
||||
}
|
27
packages/tiptap-core/src/Node.ts
Normal file
27
packages/tiptap-core/src/Node.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import Extension from './Extension'
|
||||
|
||||
export default class Node extends Extension {
|
||||
|
||||
constructor(options = {}) {
|
||||
super(options)
|
||||
}
|
||||
|
||||
// protected type = 'node'
|
||||
|
||||
get type() {
|
||||
return 'node'
|
||||
}
|
||||
|
||||
get view(): any {
|
||||
return null
|
||||
}
|
||||
|
||||
get schema(): any {
|
||||
return null
|
||||
}
|
||||
|
||||
command() {
|
||||
return () => {}
|
||||
}
|
||||
|
||||
}
|
@ -5,7 +5,7 @@ import minMax from '../utils/minMax'
|
||||
|
||||
declare module '../Editor' {
|
||||
interface Editor {
|
||||
focus(position: any): Editor
|
||||
focus(position: Position): Editor
|
||||
}
|
||||
}
|
||||
|
||||
|
23
packages/tiptap-document-extension/index.ts
Normal file
23
packages/tiptap-document-extension/index.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { Node } from '@tiptap/core'
|
||||
|
||||
export default class Document extends Node {
|
||||
|
||||
// get name() {
|
||||
// return 'document'
|
||||
// }
|
||||
|
||||
// get schema() {
|
||||
// return {
|
||||
// content: 'block+',
|
||||
// }
|
||||
// }
|
||||
|
||||
// type = 'nope'
|
||||
|
||||
name = 'document'
|
||||
|
||||
schema = {
|
||||
content: 'block+',
|
||||
}
|
||||
|
||||
}
|
@ -41,10 +41,24 @@ export default {
|
||||
// console.log(html)
|
||||
// next()
|
||||
// })
|
||||
.focus('start')
|
||||
.insertText('<p>start</p>')
|
||||
.focus('end')
|
||||
.insertHTML('<p>end</p>')
|
||||
// .registerCommand('insertHello', async (next, editor) => {
|
||||
// await editor.insertHTML('<strong>HELLO</strong>')
|
||||
// next()
|
||||
// })
|
||||
// .registerCommand('insertHello', (next, editor) => {
|
||||
// editor
|
||||
// .focus('start')
|
||||
// .insertHTML('<strong>HELLO</strong>')
|
||||
// next()
|
||||
// })
|
||||
// .focus('start')
|
||||
// .insertHello()
|
||||
// .insertText('eins')
|
||||
// .insertText('zwei')
|
||||
// .insertText('drei')
|
||||
// .insertHello()
|
||||
// .focus('end')
|
||||
// .insertHTML('<p>end</p>')
|
||||
}
|
||||
}
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user