Skip to content

Commit

Permalink
Feature/tiptap collab versioning (#650)
Browse files Browse the repository at this point in the history
* adds versioning helpers to TiptapCollabProvider

* tiptapcollabprovider versioning helpers

* fixes naming of type

* adds wrapper for createVersion, watchVersions, unwatchVersions

* adds warning about methods being useless
  • Loading branch information
janthurau authored Jul 14, 2023
1 parent de3e34c commit e1af06e
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions packages/provider/src/TiptapCollabProvider.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { AbstractType, YArrayEvent } from 'yjs'
import {
HocuspocusProvider,
HocuspocusProviderConfiguration,
Expand All @@ -20,7 +21,15 @@ export interface AdditionalTiptapCollabProviderConfiguration {
websocketProvider?: TiptapCollabProviderWebsocket
}

export type AuditHistoryVersion = {
name?: string;
version: number;
date: number;
}

export class TiptapCollabProvider extends HocuspocusProvider {
tiptapCollabConfigurationPrefix = '__tiptapcollab__'

constructor(configuration: TiptapCollabProviderConfiguration) {
if (!configuration.websocketProvider) {
configuration.websocketProvider = new TiptapCollabProviderWebsocket({ appId: (configuration as Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'appId'>>).appId })
Expand All @@ -32,4 +41,45 @@ export class TiptapCollabProvider extends HocuspocusProvider {

super(configuration as HocuspocusProviderConfiguration)
}

createVersion(name?: string) {
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev')
return this.sendStateless(JSON.stringify({ action: 'version.create', name }))
}

revertToVersion(targetVersion: number) {
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev')
return this.sendStateless(JSON.stringify({ action: 'version.revert', version: targetVersion }))
}

getVersions(): AuditHistoryVersion[] {
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev')
return this.configuration.document.getArray<AuditHistoryVersion>(`${this.tiptapCollabConfigurationPrefix}versions`).toArray()
}

watchVersions(callback: Parameters<AbstractType<YArrayEvent<AuditHistoryVersion>>['observe']>[0]) {
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev')
return this.configuration.document.getArray<AuditHistoryVersion>('__tiptapcollab__versions').observe(callback)
}

unwatchVersions(callback: Parameters<AbstractType<YArrayEvent<AuditHistoryVersion>>['unobserve']>[0]) {
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev')
return this.configuration.document.getArray<AuditHistoryVersion>('__tiptapcollab__versions').unobserve(callback)
}

isAutoVersioning(): boolean {
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev')
return !!this.configuration.document.getMap<number>(`${this.tiptapCollabConfigurationPrefix}config`).get('autoVersioning')
}

enableAutoVersioning() {
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev')
return this.configuration.document.getMap<number>(`${this.tiptapCollabConfigurationPrefix}config`).set('autoVersioning', 1)
}

disableAutoVersioning() {
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev')
return this.configuration.document.getMap<number>(`${this.tiptapCollabConfigurationPrefix}config`).set('autoVersioning', 0)
}

}

0 comments on commit e1af06e

Please sign in to comment.