Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/yjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"platejs": ">=49.2.21",
"react": ">=18.0.0",
"react-dom": ">=18.0.0",
"y-indexeddb": ">=9.0.12",
"y-webrtc": "10.3.0"
},
"publishConfig": {
Expand Down
37 changes: 37 additions & 0 deletions packages/yjs/src/lib/providers/indexeddb-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { Awareness } from 'y-protocols/awareness';
import type * as Y from 'yjs';

import { IndexeddbPersistence } from 'y-indexeddb';

import type { IndexeddbProviderConfig, UnifiedProvider } from './types';

export class IndexeddbProviderWrapper implements UnifiedProvider {
public _synced = false;
public readonly awareness: Awareness;
connect = () => {
return;
};
destroy = () => {
this.provider.destroy();
};
disconnect = () => {
return;
};
public readonly document: Y.Doc;
public readonly provider: IndexeddbPersistence;
public readonly type = 'indexeddb';
constructor({ options }: IndexeddbProviderConfig) {
this.provider = new IndexeddbPersistence(options.docName, options.ydoc);
this.document = this.provider.ydoc;
this.provider.once('synced', () => {
this._synced = true;
});
this.awareness = options.awareness;
}
get isConnected() {
return this._synced;
}
get isSynced() {
return this._synced;
}
}
15 changes: 14 additions & 1 deletion packages/yjs/src/lib/providers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ export type WebRTCProviderOptions = {
signaling?: string[];
};

export type IndexeddbProviderConfiguration = {
docName: string;
ydoc?: Y.Doc;
};

export type IndexeddbProviderConfig = BaseYjsProviderConfig & {
options: IndexeddbProviderConfiguration;
type: 'indexeddb';
};

export type YjsConfig = PluginConfig<
'yjs',
{
Expand Down Expand Up @@ -138,7 +148,10 @@ export type YjsConfig = PluginConfig<
>;

// Union type for all known provider configurations
export type YjsProviderConfig = HocuspocusProviderConfig | WebRTCProviderConfig; // Add custom config types here if needed
export type YjsProviderConfig =
| HocuspocusProviderConfig
| IndexeddbProviderConfig
| WebRTCProviderConfig; // Add custom config types here if needed

// Extensible provider type that can include custom types
export type YjsProviderType = DefaultYjsProviderType | string;
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3801,6 +3801,7 @@ __metadata:
platejs: ">=49.2.21"
react: ">=18.0.0"
react-dom: ">=18.0.0"
y-indexeddb: ">=9.0.12"
y-webrtc: 10.3.0
languageName: unknown
linkType: soft
Expand Down
Loading