import * as Y from "yjs"; import { Doc, ID, PermanentUserData, RelativePosition, RelativePosition as RelativePosition$1, Snapshot, Text, UndoManager, XmlFragment, XmlHook } from "yjs"; import { DecorationAttrs, DecorationSet, EditorView } from "prosemirror-view"; import { EditorState, Plugin, PluginKey, Selection, Transaction } from "prosemirror-state"; import * as PModel from "prosemirror-model"; import { Fragment, MarkType, Node, Schema } from "prosemirror-model"; import { Awareness } from "y-protocols/awareness"; //#region src/types/CursorUser.d.ts /** User data passed to cursor and selection builders. */ interface CursorUser { name: string; color: string; [key: string]: unknown; } //#endregion //#region src/types/CursorPluginOptions.d.ts /** Options for rendering and publishing awareness cursors. */ interface CursorPluginOptions { awarenessStateFilter?: (currentClientId: number, userClientId: number, state: Record) => boolean; cursorBuilder?: (user: CursorUser, clientId: number) => HTMLElement; selectionBuilder?: (user: CursorUser, clientId: number) => DecorationAttrs; getSelection?: (state: EditorState) => Selection; } //#endregion //#region src/lib/plugins/yCursorPlugin.d.ts declare const defaultAwarenessStateFilter: (currentClientId: number, userClientId: number, _user: Record) => boolean; /** Creates the default remote cursor element from awareness user details. */ declare const defaultCursorBuilder: (user: CursorUser) => HTMLSpanElement; /** Creates the default decoration attributes for a remote selection. */ declare const defaultSelectionBuilder: (user: CursorUser) => { style: string; class: string; }; declare const createDecorations: (state: EditorState, awareness: Awareness, awarenessFilter: NonNullable, createCursor: (user: CursorUser, clientId: number) => Element, createSelection: NonNullable) => DecorationSet; /** Renders remote cursors and publishes the local selection through awareness. */ declare const yCursorPlugin: (awareness: Awareness, { awarenessStateFilter, cursorBuilder, selectionBuilder, getSelection }?: CursorPluginOptions, cursorStateField?: string) => Plugin; //#endregion //#region src/types/ColorDef.d.ts /** Colors used to render additions and deletions in snapshots. */ interface ColorDef { light: string; dark: string; } //#endregion //#region src/types/YType.d.ts type YType = XmlFragment | Text | XmlHook; //#endregion //#region src/types/ProsemirrorMapping.d.ts /** Maps shared Yjs types to ProseMirror nodes or adjacent text nodes. */ type ProsemirrorMapping = Map; //#endregion //#region src/types/SyncPluginOptions.d.ts /** Options for synchronizing a Yjs fragment with ProseMirror. */ interface SyncPluginOptions { colors?: ColorDef[]; colorMapping?: Map; permanentUserData?: PermanentUserData | null; mapping?: ProsemirrorMapping; onFirstRender?: () => void; } //#endregion //#region src/types/RelativeSelection.d.ts /** Selection endpoints and their positions before a Yjs document update. */ interface RelativeSelection { type: string; depth: number | undefined; anchor: RelativePosition$1; head: RelativePosition$1; absAnchor: number; absHead: number; } //#endregion //#region src/types/PositionMigration.d.ts interface PositionCharacter { client: number; clock: number; text: string; type: ID; position: number | null; } interface PositionMigrationPlan { doc: Node; characters: PositionCharacter[]; nodes: PositionNode[]; emptyTexts: PositionNode[]; } interface PositionNode { id: ID; position: number | null; end: number | null; } //#endregion //#region src/lib/utils/binding/ProsemirrorBinding.d.ts /** Synchronizes one integrated Yjs XML fragment with a ProseMirror editor view. */ declare class ProsemirrorBinding { readonly type: Y.XmlFragment; prosemirrorView: EditorView | null; readonly mux: import("lib0/mutex.js").mutex; readonly mapping: ProsemirrorMapping; readonly isOMark: Map; readonly doc: Y.Doc; beforeTransactionSelection: RelativeSelection | null; readonly _observeFunction: Parameters[0]; readonly beforeAllTransactions: () => void; readonly afterAllTransactions: () => void; _domSelectionInView: boolean | null; syncedDoc: PModel.Node | null; private _projectionError; /** * Returns the last projection error. Shared writes stop until a compatible projection succeeds. * @returns The projection error, or null when shared content can be rendered. */ get projectionError(): Error | null; constructor(yXmlFragment: Y.XmlFragment, mapping?: ProsemirrorMapping); private get view(); get _tr(): Transaction; _isLocalCursorInView(): boolean | null; _isDomSelectionInView(): boolean; renderSnapshot(snapshot: SyncPluginState['snapshot'], prevSnapshot: SyncPluginState['prevSnapshot']): void; private createDocumentFragment; private handleProjectionError; private createDocumentTransaction; unrenderSnapshot(): void; _forceRerender(): void; _renderSnapshot(snapshot: SyncPluginState['snapshot'], prevSnapshot: SyncPluginState['prevSnapshot'], pluginState: SyncPluginState): void; _typeChanged(events: Parameters[0]>[0], transaction: Y.Transaction): void; _prosemirrorChanged(doc: PModel.Node, plan?: PositionMigrationPlan | null): void; initView(prosemirrorView: EditorView): void; destroy(): void; } //#endregion //#region src/types/SyncPluginState.d.ts /** Shared document and rendering state exposed by the sync plugin. */ interface SyncPluginState { type: XmlFragment; doc: Doc; binding: ProsemirrorBinding; snapshot?: Snapshot | Uint8Array | null; prevSnapshot?: Snapshot | Uint8Array | null; restore?: boolean; isChangeOrigin: boolean; isUndoRedoOperation: boolean; addToHistory: boolean; colors: ColorDef[]; colorMapping: Map; permanentUserData: PermanentUserData | null; positionMigration?: PositionMigrationPlan | null; } //#endregion //#region src/lib/plugins/ySyncPlugin.d.ts /** Binds a Yjs XML fragment to the editor document. The fragment must belong to a Yjs document. */ declare const ySyncPlugin: (yXmlFragment: Y.XmlFragment, { colors, colorMapping, permanentUserData, onFirstRender, mapping }?: SyncPluginOptions) => Plugin; //#endregion //#region src/lib/utils/binding/isVisible.d.ts /** Reports whether a Yjs item is visible in the current document or a snapshot. */ declare const isVisible: (item: Y.Item, snapshot?: Y.Snapshot) => boolean; //#endregion //#region src/lib/utils/positions/getRelativeSelection.d.ts /** Captures the current selection as Yjs relative positions and absolute fallback positions. */ declare const getRelativeSelection: (pmbinding: ProsemirrorBinding, state: EditorState) => RelativeSelection; //#endregion //#region src/types/BindingMetadata.d.ts /** Mapping and overlapping-mark cache shared by document conversions. */ interface BindingMetadata { mapping: ProsemirrorMapping; isOMark: Map; } //#endregion //#region src/types/TransactionSource.d.ts interface TransactionSource { transact(callback: () => void, origin?: unknown): unknown; } //#endregion //#region src/lib/utils/reconciliation/updateYFragment.d.ts /** Updates a Yjs XML fragment to match a ProseMirror node while preserving mapped children. */ declare const updateYFragment: (y: TransactionSource, yDomFragment: Y.XmlFragment, pNode: PModel.Node, meta: BindingMetadata) => void; //#endregion //#region src/types/UndoPluginOptions.d.ts /** Options for local undo history and protected node types. */ interface UndoPluginOptions { protectedNodes?: Set; trackedOrigins?: unknown[]; undoManager?: UndoManager | null; } //#endregion //#region src/types/UndoPluginState.d.ts /** Local undo history and the selection saved before each transaction. */ interface UndoPluginState { undoManager: UndoManager; prevSel: RelativeSelection | null; hasUndoOps: boolean; hasRedoOps: boolean; destroyListeners: Set<(document: Doc) => void>; } //#endregion //#region src/lib/plugins/yUndoPlugin.d.ts /** Undoes a local change through the editor's Yjs undo manager. */ declare const undo: (state: EditorState) => boolean | undefined; /** Redoes a local change through the editor's Yjs undo manager. */ declare const redo: (state: EditorState) => boolean | undefined; declare const defaultProtectedNodes: Set; /** Keeps protected structural nodes when an undo operation would delete them. */ declare const defaultDeleteFilter: (item: unknown, protectedNodes: Set) => boolean; /** Tracks local Yjs changes for undo and redo while preserving remote changes. */ declare const yUndoPlugin: ({ protectedNodes, trackedOrigins, undoManager }?: UndoPluginOptions) => Plugin; //#endregion //#region src/lib/plugins/keys.d.ts declare const ySyncPluginKey: PluginKey; declare const yUndoPluginKey: PluginKey; declare const yCursorPluginKey: PluginKey; //#endregion //#region src/lib/utils/positions/absolutePositionToRelativePosition.d.ts /** Converts a ProseMirror position to a Yjs relative position. */ declare const absolutePositionToRelativePosition: (pos: number, type: Y.XmlFragment, mapping: ProsemirrorMapping) => Y.RelativePosition; //#endregion //#region src/lib/utils/positions/relativePositionToAbsolutePosition.d.ts /** Resolves a Yjs relative position, returning null when it cannot be mapped. */ declare const relativePositionToAbsolutePosition: (y: Y.Doc, documentType: Y.XmlFragment, relPos: Y.RelativePosition, mapping: ProsemirrorMapping) => number | null; //#endregion //#region src/types/MetaKey.d.ts type MetaKey = string | Plugin | PluginKey; //#endregion //#region src/lib/plugins/setMeta.d.ts /** Queues plugin metadata and batches repeated updates for the same key. */ declare function setMeta(view: EditorView, key: MetaKey, value: unknown): void; //#endregion //#region src/lib/utils/positions/findAbsolutePositionAfterStructuralChange.d.ts /** Recovers a position in a moved block, returning null when the match is ambiguous. */ declare const findAbsolutePositionAfterStructuralChange: (oldDoc: Node, newDoc: Node, absPos: number) => number | null; //#endregion //#region src/lib/utils/positions/isMisresolvedTextPosition.d.ts /** Detects a text position that resolved outside its original block. */ declare const isMisresolvedTextPosition: (y: Y.Doc, relPos: Y.RelativePosition, absPos: number | null) => boolean; //#endregion //#region src/lib/utils/positions/isMisresolvedAfterStructuralChange.d.ts /** Detects a position that moved into a different block. */ declare const isMisresolvedAfterStructuralChange: (oldDoc: Node, newDoc: Node, oldAbs: number, resolvedAbs: number | null) => boolean; //#endregion //#region src/lib/utils/positions/isStructuralTransaction.d.ts /** Reports whether a transaction changes the document structure. */ declare const isStructuralTransaction: (tr: Transaction, oldDoc: Node) => boolean; //#endregion //#region src/lib/utils/conversion/prosemirrorJSONToYDoc.d.ts /** Creates a Yjs document from ProseMirror JSON using the supplied schema. */ declare function prosemirrorJSONToYDoc(schema: Schema, state: unknown, xmlFragment?: string): import("yjs").Doc; //#endregion //#region src/lib/utils/conversion/yDocToProsemirrorJSON.d.ts /** Reads ProseMirror JSON from the named Yjs XML fragment. */ declare function yDocToProsemirrorJSON(ydoc: Y.Doc, xmlFragment?: string): { type: string; content: (ProsemirrorJSONNode | ProsemirrorJSONNode[])[]; }; //#endregion //#region src/lib/utils/conversion/yDocToProsemirror.d.ts /** Creates a ProseMirror document from the named Yjs XML fragment. */ declare function yDocToProsemirror(schema: Schema, ydoc: Y.Doc): Node; //#endregion //#region src/lib/utils/conversion/prosemirrorToYDoc.d.ts /** Creates a Yjs document from a ProseMirror document. */ declare function prosemirrorToYDoc(doc: Node, xmlFragment?: string): Y.Doc; //#endregion //#region src/lib/utils/conversion/prosemirrorJSONToYXmlFragment.d.ts /** Converts ProseMirror JSON into a new or existing Yjs XML fragment. */ declare function prosemirrorJSONToYXmlFragment(schema: Schema, state: unknown, xmlFragment?: Y.XmlFragment): Y.XmlFragment; //#endregion //#region src/types/ProsemirrorJSONNode.d.ts interface ProsemirrorJSONMark { type: string; attrs?: Record; } /** JSON node structure produced by the Yjs conversion helpers. */ interface ProsemirrorJSONNode { type: string; text?: string; attrs?: Record; marks?: ProsemirrorJSONMark[]; content?: (ProsemirrorJSONNode | ProsemirrorJSONNode[])[]; } //#endregion //#region src/lib/utils/conversion/yXmlFragmentToProsemirrorJSON.d.ts /** Reads ProseMirror JSON from a Yjs XML fragment. */ declare function yXmlFragmentToProsemirrorJSON(xmlFragment: Y.XmlFragment): { type: string; content: (ProsemirrorJSONNode | ProsemirrorJSONNode[])[]; }; //#endregion //#region src/lib/utils/conversion/yXmlFragmentToProsemirror.d.ts /** Creates a ProseMirror document from a Yjs XML fragment. */ declare function yXmlFragmentToProsemirror(schema: Schema, xmlFragment: Y.XmlFragment): Node; //#endregion //#region src/lib/utils/conversion/prosemirrorToYXmlFragment.d.ts /** Converts a ProseMirror document into a new or existing Yjs XML fragment. */ declare function prosemirrorToYXmlFragment(doc: Node, xmlFragment?: Y.XmlFragment): Y.XmlFragment; //#endregion //#region src/lib/utils/conversion/yXmlFragmentToProseMirrorRootNode.d.ts /** Converts Yjs XML content to the schema's top-level document node. */ declare const yXmlFragmentToProseMirrorRootNode: (yXmlFragment: Y.XmlFragment, schema: Schema) => Node; //#endregion //#region src/lib/utils/conversion/yXmlFragmentToProseMirrorFragment.d.ts /** Converts Yjs XML content to a ProseMirror fragment using the supplied schema. */ declare const yXmlFragmentToProseMirrorFragment: (yXmlFragment: Y.XmlFragment, schema: Schema) => Fragment; //#endregion //#region src/types/InitialProseMirrorDoc.d.ts /** Initial editor document and the caches required to bind its Yjs fragment. */ interface InitialProseMirrorDoc { doc: Node; meta: BindingMetadata; mapping: ProsemirrorMapping; } //#endregion //#region src/lib/utils/conversion/initProseMirrorDoc.d.ts /** Creates the initial ProseMirror document and its Yjs node mapping. */ declare const initProseMirrorDoc: (yXmlFragment: Y.XmlFragment, schema: Schema) => InitialProseMirrorDoc; //#endregion export { type BindingMetadata, type ColorDef, type CursorPluginOptions, type CursorUser, type InitialProseMirrorDoc, ProsemirrorBinding, type ProsemirrorJSONMark, type ProsemirrorJSONNode, type ProsemirrorMapping, type RelativePosition, type RelativeSelection, type SyncPluginOptions, type SyncPluginState, type UndoPluginOptions, type UndoPluginState, absolutePositionToRelativePosition, createDecorations, defaultAwarenessStateFilter, defaultCursorBuilder, defaultDeleteFilter, defaultProtectedNodes, defaultSelectionBuilder, findAbsolutePositionAfterStructuralChange, getRelativeSelection, initProseMirrorDoc, isMisresolvedAfterStructuralChange, isMisresolvedTextPosition, isStructuralTransaction, isVisible, prosemirrorJSONToYDoc, prosemirrorJSONToYXmlFragment, prosemirrorToYDoc, prosemirrorToYXmlFragment, redo, relativePositionToAbsolutePosition, setMeta, undo, updateYFragment, yCursorPlugin, yCursorPluginKey, yDocToProsemirror, yDocToProsemirrorJSON, ySyncPlugin, ySyncPluginKey, yUndoPlugin, yUndoPluginKey, yXmlFragmentToProseMirrorFragment, yXmlFragmentToProseMirrorRootNode, yXmlFragmentToProsemirror, yXmlFragmentToProsemirrorJSON }; //# sourceMappingURL=index.d.ts.map