mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-18 14:13:21 +08:00
add basic history extension
This commit is contained in:
parent
cb6a723d57
commit
f7b62be436
@ -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"
|
||||
}
|
||||
}
|
@ -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('<p>hey</p>')
|
||||
// .registerCommand('lol', (next) => {
|
||||
// console.log('lol')
|
||||
|
16
yarn.lock
16
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"
|
||||
|
Loading…
Reference in New Issue
Block a user