mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-08-06 13:38:49 +08:00
Merge branch 'main' of github.com:ueberdosis/tiptap-next into main
# Conflicts: # docs/src/demos/Examples/CollaborativeEditing/index.vue
This commit is contained in:
commit
af708c4fb7
@ -125,7 +125,6 @@ export default {
|
||||
name: this.getRandomName(),
|
||||
color: this.getRandomColor(),
|
||||
},
|
||||
provider: null,
|
||||
indexdb: null,
|
||||
editor: null,
|
||||
users: [],
|
||||
@ -135,9 +134,9 @@ export default {
|
||||
|
||||
mounted() {
|
||||
const ydoc = new Y.Doc()
|
||||
this.provider = new WebrtcProvider('tiptap-collaboration-example', ydoc)
|
||||
// this.provider = new WebsocketProvider('ws://127.0.0.1:1234', 'tiptap-collaboration-example', ydoc)
|
||||
this.provider.on('status', event => {
|
||||
const provider = new WebrtcProvider('tiptap-collaboration-example', ydoc)
|
||||
// const provider = new WebsocketProvider('ws://127.0.0.1:1234', 'tiptap-collaboration-example', ydoc)
|
||||
provider.on('status', event => {
|
||||
this.status = event.status
|
||||
})
|
||||
|
||||
@ -147,10 +146,10 @@ export default {
|
||||
extensions: [
|
||||
...defaultExtensions(),
|
||||
Collaboration.configure({
|
||||
provider: this.provider,
|
||||
provider,
|
||||
}),
|
||||
CollaborationCursor.configure({
|
||||
provider: this.provider,
|
||||
provider,
|
||||
user: this.currentUser,
|
||||
onUpdate: users => {
|
||||
this.users = users
|
||||
@ -198,7 +197,6 @@ export default {
|
||||
|
||||
beforeDestroy() {
|
||||
this.editor.destroy()
|
||||
this.provider.destroy()
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
@ -385,6 +385,8 @@ export class Editor extends EventEmitter {
|
||||
* Destroy the editor.
|
||||
*/
|
||||
public destroy() {
|
||||
this.emit('destroy')
|
||||
|
||||
if (this.view) {
|
||||
this.view.destroy()
|
||||
}
|
||||
|
@ -62,6 +62,11 @@ export interface ExtensionConfig<Options = any, Commands = {}> {
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
}) => Plugin[],
|
||||
|
||||
onDestroy?: ((this: {
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
}) => void) | null,
|
||||
}
|
||||
|
||||
export class Extension<Options = any, Commands = any> {
|
||||
@ -76,6 +81,7 @@ export class Extension<Options = any, Commands = any> {
|
||||
addInputRules: () => [],
|
||||
addPasteRules: () => [],
|
||||
addProseMirrorPlugins: () => [],
|
||||
onDestroy: null,
|
||||
}
|
||||
|
||||
options!: Options
|
||||
|
@ -33,6 +33,10 @@ export default class ExtensionManager {
|
||||
const commands = extension.config.addCommands.bind(context)()
|
||||
|
||||
editor.registerCommands(commands)
|
||||
|
||||
if (typeof extension.config.onDestroy === 'function') {
|
||||
this.editor.on('destroy', extension.config.onDestroy.bind(context))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -108,6 +108,12 @@ export interface MarkConfig<Options = any, Commands = {}> extends Overwrite<Exte
|
||||
editor: Editor,
|
||||
type: MarkType,
|
||||
}) => Plugin[],
|
||||
|
||||
onDestroy?: ((this: {
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
type: MarkType,
|
||||
}) => void) | null,
|
||||
}> {}
|
||||
|
||||
export class Mark<Options = any, Commands = {}> {
|
||||
@ -129,6 +135,7 @@ export class Mark<Options = any, Commands = {}> {
|
||||
parseHTML: () => null,
|
||||
renderHTML: null,
|
||||
addAttributes: () => ({}),
|
||||
onDestroy: null,
|
||||
}
|
||||
|
||||
options!: Options
|
||||
|
@ -152,6 +152,12 @@ export interface NodeConfig<Options = any, Commands = {}> extends Overwrite<Exte
|
||||
editor: Editor,
|
||||
type: NodeType,
|
||||
}) => NodeViewRenderer) | null,
|
||||
|
||||
onDestroy?: ((this: {
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
type: NodeType,
|
||||
}) => void) | null,
|
||||
}> {}
|
||||
|
||||
export class Node<Options = any, Commands = {}> {
|
||||
@ -181,6 +187,7 @@ export class Node<Options = any, Commands = {}> {
|
||||
renderHTML: null,
|
||||
addAttributes: () => ({}),
|
||||
addNodeView: null,
|
||||
onDestroy: null,
|
||||
}
|
||||
|
||||
options!: Options
|
||||
|
@ -31,6 +31,10 @@ const Collaboration = Extension.create({
|
||||
'Mod-Shift-z': redo,
|
||||
}
|
||||
},
|
||||
|
||||
onDestroy() {
|
||||
this.options.provider?.destroy()
|
||||
},
|
||||
})
|
||||
|
||||
export default Collaboration
|
||||
|
Loading…
Reference in New Issue
Block a user