add basic history extension
This commit is contained in:
@@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ export default abstract class Extension {
|
||||
defaultOptions: { [key: string]: any } = {}
|
||||
|
||||
public abstract name: string
|
||||
// public abstract plugins: any
|
||||
|
||||
public type = 'extension'
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ export default abstract class Node extends Extension {
|
||||
// }
|
||||
|
||||
public abstract schema: any
|
||||
// public abstract plugins?: any
|
||||
|
||||
// command() {
|
||||
// return () => {}
|
||||
|
||||
43
packages/tiptap-history-extension/index.ts
Normal file
43
packages/tiptap-history-extension/index.ts
Normal file
@@ -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,
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
20
packages/tiptap-history-extension/package.json
Normal file
20
packages/tiptap-history-extension/package.json
Normal file
@@ -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"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user