import { sync, type SyncPlugin as NativeSyncPlugin, type SyncPluginOptions as NativeSyncPluginOptions, } from 'plitejs/sync'; import { definePlugin } from '../core'; import { peekEditorAuthor } from '../lib/editor/editorUser.internal'; import type { InternalBasePluginRuntimeExtension } from '../lib/plugin/BasePlugin'; import { createBasePluginFactory } from '../lib/plugin/basePluginFactory.internal'; import type { InternalPluginDefinitionOf } from '../lib/plugin/pluginDefinitionLookup.internal'; /** * Options for `SyncPlugin.create(options)`. Actor identity is derived from the * editor's `userId` (and writing view `authorId` when present). */ export type SyncPluginOptions = Omit; const BaseSyncBridge = definePlugin('sync', {}); type BaseSyncBridgeDefinition = InternalPluginDefinitionOf< typeof BaseSyncBridge >; type PlateSyncPlugin = InternalBasePluginRuntimeExtension< typeof BaseSyncBridge, BaseSyncBridgeDefinition, NativeSyncPlugin >; interface SyncPluginFactoryType { readonly input: SyncPluginOptions; readonly output: PlateSyncPlugin; } /** * Creates headless Plate sync plugins backed by a collaborative v4 room, * automatically attributing edits and presence to the editor's `userId`. */ export const SyncPlugin = createBasePluginFactory( (options) => BaseSyncBridge.extend( sync({ ...options, actor: peekEditorAuthor, }) ) );