add extension class
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
import { Editor } from './src/Editor'
|
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,9 +12,11 @@ import insertText from './commands/insertText'
|
|||||||
import insertHTML from './commands/insertHTML'
|
import insertHTML from './commands/insertHTML'
|
||||||
import focus from './commands/focus'
|
import focus from './commands/focus'
|
||||||
|
|
||||||
|
type EditorContent = string | JSON
|
||||||
|
|
||||||
interface EditorOptions {
|
interface EditorOptions {
|
||||||
element: Node
|
element: Node
|
||||||
content: string
|
content: EditorContent
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Editor {
|
export class Editor {
|
||||||
@@ -84,7 +86,7 @@ export class Editor {
|
|||||||
return this[name](...args)
|
return this[name](...args)
|
||||||
}
|
}
|
||||||
|
|
||||||
private createDocument(content: any): any {
|
private createDocument(content: EditorContent): any {
|
||||||
// if (content === null) {
|
// if (content === null) {
|
||||||
// return this.schema.nodeFromJSON(this.options.emptyDocument)
|
// 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' {
|
declare module '../Editor' {
|
||||||
interface 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)
|
// console.log(html)
|
||||||
// next()
|
// next()
|
||||||
// })
|
// })
|
||||||
.focus('start')
|
// .registerCommand('insertHello', async (next, editor) => {
|
||||||
.insertText('<p>start</p>')
|
// await editor.insertHTML('<strong>HELLO</strong>')
|
||||||
.focus('end')
|
// next()
|
||||||
.insertHTML('<p>end</p>')
|
// })
|
||||||
|
// .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>
|
</script>
|
||||||
Reference in New Issue
Block a user