diff --git a/packages/tiptap-core/index.ts b/packages/tiptap-core/index.ts index b1b8bdb7..67b83709 100644 --- a/packages/tiptap-core/index.ts +++ b/packages/tiptap-core/index.ts @@ -1,3 +1,5 @@ import { Editor } from './src/Editor' -export default Editor \ No newline at end of file +export default Editor +export { default as Extension } from './src/Extension' +export { default as Node } from './src/Node' \ No newline at end of file diff --git a/packages/tiptap-core/src/Editor.ts b/packages/tiptap-core/src/Editor.ts index fa2b0987..e907303c 100644 --- a/packages/tiptap-core/src/Editor.ts +++ b/packages/tiptap-core/src/Editor.ts @@ -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) // } diff --git a/packages/tiptap-core/src/Extension.ts b/packages/tiptap-core/src/Extension.ts new file mode 100644 index 00000000..99e7cfbe --- /dev/null +++ b/packages/tiptap-core/src/Extension.ts @@ -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 {} + } + +} diff --git a/packages/tiptap-core/src/Node.ts b/packages/tiptap-core/src/Node.ts new file mode 100644 index 00000000..c9bcb915 --- /dev/null +++ b/packages/tiptap-core/src/Node.ts @@ -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 () => {} + } + +} diff --git a/packages/tiptap-core/src/commands/focus.ts b/packages/tiptap-core/src/commands/focus.ts index 28931482..7c3de881 100644 --- a/packages/tiptap-core/src/commands/focus.ts +++ b/packages/tiptap-core/src/commands/focus.ts @@ -5,7 +5,7 @@ import minMax from '../utils/minMax' declare module '../Editor' { interface Editor { - focus(position: any): Editor + focus(position: Position): Editor } } diff --git a/packages/tiptap-document-extension/index.ts b/packages/tiptap-document-extension/index.ts new file mode 100644 index 00000000..7666d574 --- /dev/null +++ b/packages/tiptap-document-extension/index.ts @@ -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+', + } + +} \ No newline at end of file diff --git a/src/templates/Post.vue b/src/templates/Post.vue index 72a9b5f1..99d0f231 100644 --- a/src/templates/Post.vue +++ b/src/templates/Post.vue @@ -41,10 +41,24 @@ export default { // console.log(html) // next() // }) - .focus('start') - .insertText('

start

') - .focus('end') - .insertHTML('

end

') + // .registerCommand('insertHello', async (next, editor) => { + // await editor.insertHTML('HELLO') + // next() + // }) + // .registerCommand('insertHello', (next, editor) => { + // editor + // .focus('start') + // .insertHTML('HELLO') + // next() + // }) + // .focus('start') + // .insertHello() + // .insertText('eins') + // .insertText('zwei') + // .insertText('drei') + // .insertHello() + // .focus('end') + // .insertHTML('

end

') } } \ No newline at end of file