diff --git a/packages/tiptap-core/src/Editor.ts b/packages/tiptap-core/src/Editor.ts index a4938fe5..8fd8675f 100644 --- a/packages/tiptap-core/src/Editor.ts +++ b/packages/tiptap-core/src/Editor.ts @@ -159,7 +159,8 @@ export class Editor extends EventEmitter { // @ts-ignore this[name] = this.chainCommand((...args: any) => { return new Promise(resolve => { - return method(resolve, this, ...args) + // return method(resolve, this, ...args) + return method(resolve as Function, this as Editor, ...args as any) }) }) diff --git a/packages/tiptap-core/src/Extension.ts b/packages/tiptap-core/src/Extension.ts index 6a0b66ca..35b65ee7 100644 --- a/packages/tiptap-core/src/Extension.ts +++ b/packages/tiptap-core/src/Extension.ts @@ -14,6 +14,7 @@ export default abstract class Extension { defaultOptions: { [key: string]: any } = {} public abstract name: string + // public abstract plugins: any public type = 'extension' diff --git a/packages/tiptap-core/src/Node.ts b/packages/tiptap-core/src/Node.ts index 9e5bbd45..01c16a99 100644 --- a/packages/tiptap-core/src/Node.ts +++ b/packages/tiptap-core/src/Node.ts @@ -23,6 +23,7 @@ export default abstract class Node extends Extension { // } public abstract schema: any + // public abstract plugins?: any // command() { // return () => {} diff --git a/packages/tiptap-history-extension/index.ts b/packages/tiptap-history-extension/index.ts new file mode 100644 index 00000000..171f62fc --- /dev/null +++ b/packages/tiptap-history-extension/index.ts @@ -0,0 +1,43 @@ +import Editor, { Extension } from '@tiptap/core' +import { + history, + undo, + redo, + undoDepth, + redoDepth, +} from 'prosemirror-history' + +declare module '@tiptap/core/src/Editor' { + interface Editor { + undo(): Editor, + } +} + +export default class History extends Extension { + + name = 'history' + + init() { + // @ts-ignore + this.editor.registerCommand('undo', (next, { view }) => { + undo(view.state, view.dispatch) + next() + }) + } + + get plugins() { + return [ + history() + ] + } + + // commands() { + // return { + // undo: () => undo, + // redo: () => redo, + // undoDepth: () => undoDepth, + // redoDepth: () => redoDepth, + // } + // } + +} \ No newline at end of file diff --git a/packages/tiptap-history-extension/package.json b/packages/tiptap-history-extension/package.json new file mode 100644 index 00000000..680a0df2 --- /dev/null +++ b/packages/tiptap-history-extension/package.json @@ -0,0 +1,20 @@ +{ + "name": "@tiptap/history-extension", + "version": "1.0.0", + "source": "index.ts", + "main": "dist/tiptap-history-extension.js", + "umd:main": "dist/tiptap-history-extension.umd.js", + "module": "dist/tiptap-history-extension.mjs", + "unpkg": "dist/tiptap-history-extension.js", + "jsdelivr": "dist/tiptap-history-extension.js", + "files": [ + "src", + "dist" + ], + "peerDependencies": { + "@tiptap/core": "2.x" + }, + "dependencies": { + "prosemirror-history": "^1.1.3" + } +} diff --git a/src/pages/tests/Basic.vue b/src/pages/tests/Basic.vue index 0b3c8dcb..3f6cdba9 100644 --- a/src/pages/tests/Basic.vue +++ b/src/pages/tests/Basic.vue @@ -9,6 +9,7 @@ import Editor from '@tiptap/core' import Document from '@tiptap/document-extension' import Paragraph from '@tiptap/paragraph-extension' import Text from '@tiptap/text-extension' +import History from '@tiptap/history-extension' export default { mounted() { @@ -19,10 +20,11 @@ export default { new Document(), new Paragraph(), new Text(), + new History(), ], }) - // .focus('end') // .insertText('foo') + // .undo() // .insertHTML('

hey

') // .registerCommand('lol', (next) => { // console.log('lol') diff --git a/yarn.lock b/yarn.lock index 87285f9c..2492d6e3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11076,6 +11076,15 @@ prosemirror-gapcursor@^1.1.3: prosemirror-state "^1.0.0" prosemirror-view "^1.0.0" +prosemirror-history@^1.1.3: + version "1.1.3" + resolved "https://registry.yarnpkg.com/prosemirror-history/-/prosemirror-history-1.1.3.tgz#4f76a1e71db4ef7cdf0e13dec6d8da2aeaecd489" + integrity sha512-zGDotijea+vnfnyyUGyiy1wfOQhf0B/b6zYcCouBV8yo6JmrE9X23M5q7Nf/nATywEZbgRLG70R4DmfSTC+gfg== + dependencies: + prosemirror-state "^1.2.2" + prosemirror-transform "^1.0.0" + rope-sequence "^1.3.0" + prosemirror-inputrules@^1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/prosemirror-inputrules/-/prosemirror-inputrules-1.1.2.tgz#487e46c763e1212a4577397aba7706139084f012" @@ -11099,7 +11108,7 @@ prosemirror-model@^1.0.0, prosemirror-model@^1.1.0, prosemirror-model@^1.9.1: dependencies: orderedmap "^1.1.0" -prosemirror-state@^1.0.0, prosemirror-state@^1.3.2: +prosemirror-state@^1.0.0, prosemirror-state@^1.2.2, prosemirror-state@^1.3.2: version "1.3.2" resolved "https://registry.yarnpkg.com/prosemirror-state/-/prosemirror-state-1.3.2.tgz#1b910b0dc01c1f00926bb9ba1589f7b7ac0d658b" integrity sha512-t/JqE3aR0SV9QrzFVkAXsQwsgrQBNs/BDbcFH20RssW0xauqNNdjTXxy/J/kM7F+0zYi6+BRmz7cMMQQFU3mwQ== @@ -12070,6 +12079,11 @@ rollup@^0.67.3: "@types/estree" "0.0.39" "@types/node" "*" +rope-sequence@^1.3.0: + version "1.3.2" + resolved "https://registry.yarnpkg.com/rope-sequence/-/rope-sequence-1.3.2.tgz#a19e02d72991ca71feb6b5f8a91154e48e3c098b" + integrity sha512-ku6MFrwEVSVmXLvy3dYph3LAMNS0890K7fabn+0YIRQ2T96T9F4gkFf0vf0WW0JUraNWwGRtInEpH7yO4tbQZg== + run-async@^2.2.0: version "2.4.0" resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.0.tgz#e59054a5b86876cfae07f431d18cbaddc594f1e8"