import { Client } from '@yorkie-js/sdk';
import { ClientOptions } from '@yorkie-js/sdk';
import { Counter } from '@yorkie-js/sdk';
import { default as default_2 } from 'react';
import { Document as Document_2 } from '@yorkie-js/sdk';
import { Indexable } from '@yorkie-js/sdk';
import { JSONArray } from '@yorkie-js/sdk';
import { JSONObject } from '@yorkie-js/sdk';
import { JSX } from 'react/jsx-dev-runtime';
import { Presence } from '@yorkie-js/sdk';
import { PropsWithChildren } from 'react';
import { RevisionSummary } from '@yorkie-js/sdk';
import { StreamConnectionStatus } from '@yorkie-js/sdk';
import { SyncMode } from '@yorkie-js/sdk';
import { Text as Text_2 } from '@yorkie-js/sdk';
import { Tree } from '@yorkie-js/sdk';
/**
* `ChannelProvider` is a component that provides Channel context to its children.
* It must be used within a YorkieProvider to access the client.
*
* @example
* ```tsx
* import { ChannelProvider, SyncMode } from '@yorkie-js/react';
*
*
*
*
*
*
* ```
*
* The boolean `isRealtime` prop is also accepted as a shortcut for
* the Realtime/Manual choice (`true` → Realtime, `false` → Manual).
*/
export declare const ChannelProvider: React.FC;
/**
* `ChannelProviderProps` represents the props for ChannelProvider.
*/
declare type ChannelProviderProps = PropsWithChildren<{
/**
* `channelKey` is the key for the channel.
*/
channelKey: string;
/**
* `syncMode` selects how the channel keeps presence in sync with the server.
* - `SyncMode.Realtime` (default): open a watch stream and run the
* heartbeat. Required to receive broadcast events.
* - `SyncMode.Polling`: heartbeat-only. No watch stream is opened.
* Recommended for large channels where broadcast is not needed.
* - `SyncMode.Manual`: no automatic activity.
*
* If `isRealtime` is also set, `syncMode` wins.
*/
syncMode?: SyncMode;
/**
* `isRealtime` is a convenience prop covering only Realtime/Manual.
* - `true`: equivalent to `syncMode={SyncMode.Realtime}`.
* - `false`: equivalent to `syncMode={SyncMode.Manual}`.
*
* Use `syncMode` directly when you want `SyncMode.Polling`, which this
* boolean prop cannot express. When neither prop is set, the channel
* falls back to `SyncMode.Realtime`.
*/
isRealtime?: boolean;
/**
* `channelHeartbeatInterval` overrides the heartbeat interval (ms).
* Applied at attach time. Defaults: Polling=3000, Realtime=30000.
*/
channelHeartbeatInterval?: number;
}>;
export { Counter }
/**
* `createDocumentSelector` is a factory function that provides a selector-based `useDocument` hook.
* By currying this function, type T can be inferred from the selector function.
*/
export declare const createDocumentSelector: () => >(selector: (state: DocumentContextType) => T, equalityFn?: (a: T, b: T) => boolean) => T;
export { Document_2 as Document }
declare type DocumentContextType = {
doc: Document_2 | undefined;
root: R;
presences: Array<{
clientID: string;
presence: P;
}>;
connection: StreamConnectionStatus;
update: (callback: (root: R, presence: Presence
) => void) => void;
loading: boolean;
error: Error | undefined;
};
/**
* `DocumentProvider` is a component that provides a document to its children.
* This component must be under a `YorkieProvider` component to initialize the
* Yorkie client properly.
*/
export declare const DocumentProvider: ({ docKey, initialRoot, initialPresence, enableDevtools, syncMode, documentPollInterval, disableGC, disablePresence, children, }: {
docKey: string;
initialRoot?: R;
initialPresence?: P;
enableDevtools?: boolean;
/**
* `syncMode` defines the synchronization mode of the document.
* Defaults to `SyncMode.Realtime`.
*/
syncMode?: SyncMode;
/**
* `documentPollInterval` (ms) — only used when `syncMode` is `Polling`.
* Default: 3000. Applied at attach time.
*/
documentPollInterval?: number;
/**
* `disableGC` declares that this attachment will not produce or consume
* tombstones. Use only with Counter or primitive workloads; misuse on a
* document that uses Tree, Text, or Array deletions leads to undefined
* GC behavior on this client.
*/
disableGC?: boolean;
/**
* `disablePresence` declares that this document does not use presence.
* Forwarded to both `new Document(...)` and `client.attach(...)`. The
* server fixates the value on first attach — subsequent attaches
* inherit the server's value regardless of what this prop carries.
* Useful for counter-only documents where the per-client presence
* map would otherwise leak memory.
*/
disablePresence?: boolean;
children?: default_2.ReactNode;
}) => JSX.Element;
export { JSONArray }
export { JSONObject }
export { RevisionSummary }
/**
* Performs a shallow equality check between two values.
*/
export declare function shallowEqual(valueA: T, valueB: T): boolean;
export { SyncMode }
export { Text_2 as Text }
export { Tree }
/**
* `useChannel` is a custom hook that returns the channel state.
* It must be used within a ChannelProvider.
*
* @returns An object containing sessionCount, loading, error state and
* a `detach` function for permanently stopping the channel.
*
* @example
* ```tsx
* function ChatRoom() {
* const { sessionCount, loading, error } = useChannel();
*
* if (loading) return
Loading...
;
* if (error) return
Error: {error.message}
;
*
* return
{sessionCount} online
;
* }
* ```
*/
export declare const useChannel: () => {
sessionCount: number;
loading: boolean;
error: Error | undefined;
detach: () => Promise;
};
/**
* `useChannelSessionCount` is a custom hook that returns only the session count value.
* It must be used within a ChannelProvider.
* This is a convenience hook for when you only need the session count.
*
* @returns The current online session count
*
* @example
* ```tsx
* function UserCounter() {
* const count = useChannelSessionCount();
* return {count} online;
* }
* ```
*/
export declare const useChannelSessionCount: () => number;
/**
* `useConnection` is a custom hook that returns the connection status of the document.
*/
export declare const useConnection: () => StreamConnectionStatus;
/**
* `useDocument` is a custom hook that returns the complete document context.
* This hook must be used within a `DocumentProvider`.
* @returns The complete document context.
*/
export declare function useDocument(): DocumentContextType;
/**
* `usePeekChannel` reads a channel's current session count without joining
* the channel. By default it fetches once on mount; pass `pollInterval` to
* opt into continuous polling. The caller does not create a Session on the
* server, does not receive broadcasts, and does not contribute to the
* channel's count.
*
* Prefer this over `` when many viewers need to
* display a count and only a few become real participants — e.g. a global
* "N people writing" badge shown on every surrounding page.
*
* @example One-shot (snapshot at entry)
* ```tsx
* function WritersBadge() {
* const { sessionCount, loading } = usePeekChannel('post-writers');
* if (loading) return null;
* return {sessionCount} writing;
* }
* ```
*
* @example Continuous polling
* ```tsx
* function LiveCounter() {
* const { sessionCount } = usePeekChannel('post-writers', {
* pollInterval: 3000,
* });
* return {sessionCount} writing;
* }
* ```
*
* @example Imperative refetch
* ```tsx
* function WithRefresh() {
* const { sessionCount, refetch } = usePeekChannel('post-writers');
* return (
*
* );
* }
* ```
*/
export declare function usePeekChannel(channelKey: string, opts?: UsePeekChannelOptions): UsePeekChannelResult;
/**
* `UsePeekChannelOptions` are user-settable options for `usePeekChannel`.
*/
export declare interface UsePeekChannelOptions {
/**
* `pollInterval` opts the hook into continuous polling at the given
* cadence (ms). When unset, the hook fetches once on mount and stops —
* this matches the common "snapshot at entry" pattern. Use polling only
* when the UI genuinely needs a live-updating count.
*/
pollInterval?: number;
/**
* `enabled` toggles execution. When false, the hook does not fetch and
* holds the last value. Default: true.
*/
enabled?: boolean;
}
/**
* `UsePeekChannelResult` is the state exposed by `usePeekChannel`.
*/
export declare interface UsePeekChannelResult {
/**
* `sessionCount` is the most recently fetched count. Starts at 0 before
* the first successful fetch; gate display on `loading` if 0-vs-unfetched
* matters in your UI.
*/
sessionCount: number;
/**
* `loading` is true before the first successful fetch (or while a
* `refetch()` is in flight). Becomes false on success or error.
*/
loading: boolean;
/**
* `error` holds the last error from a fetch, if any.
*/
error?: Error;
/**
* `refetch` issues a peek immediately, ignoring `pollInterval`. Useful on
* button clicks or after user actions that may have changed the count.
*/
refetch: () => Promise;
}
/**
* `usePresences` is a custom hook that returns the presences of the document.
*/
export declare const usePresences:
() => Array<{
clientID: string;
presence: P;
}>;
/**
* `useRemoveDocument` returns a function that removes the current document
* from the server via `client.remove` (as opposed to `client.detach`).
* After it resolves the document is gone for every client and the key can
* be reattached as a fresh document. The returned function rejects until
* the document is attached, and the removal error is propagated to the
* caller. This hook must be used within a `DocumentProvider`.
*/
export declare const useRemoveDocument: () => () => Promise;
/**
* `useRevisions` is a custom hook that provides revision management methods
* for the current document. It wraps the client's revision API methods
* and automatically binds the current client and document.
* This hook must be used within a `DocumentProvider`.
*/
export declare const useRevisions: () => {
createRevision: (label: string, description?: string) => Promise;
listRevisions: (options?: {
pageSize?: number;
offset?: number;
isForward?: boolean;
}) => Promise>;
getRevision: (revisionID: string) => Promise;
restoreRevision: (revisionID: string) => Promise;
};
/**
* `useRoot` is a custom hook that returns the root object of the document.
* This hook must be used within a `DocumentProvider`.
*/
export declare const useRoot: () => {
root: R;
};
/**
* `useYorkie` is a custom hook that returns the Yorkie client and its loading state.
* @returns
*/
export declare const useYorkie: () => {
client: Client | undefined;
loading: boolean;
error: Error | undefined;
};
/**
* `useYorkieDoc` is a custom hook that initializes a Yorkie Client and a
* document in a single hook.
*/
export declare function useYorkieDoc(apiKey: string, docKey: string, opts?: Omit & {
initialRoot?: R;
initialPresence?: P;
enableDevtools?: boolean;
syncMode?: SyncMode;
documentPollInterval?: number;
/**
* `disableGC` declares that this attachment will not produce or consume
* tombstones. Use only with Counter or primitive workloads; misuse on a
* document that uses Tree, Text, or Array deletions leads to undefined
* GC behavior on this client.
*/
disableGC?: boolean;
/**
* `disablePresence` declares that this document does not use presence.
* Forwarded to both `new Document(...)` and `client.attach(...)`. The
* server fixates the value on first attach — subsequent attaches
* inherit the server's value regardless of what this option carries.
*/
disablePresence?: boolean;
}): {
root: R;
presences: Array<{
clientID: string;
presence: P;
}>;
connection: StreamConnectionStatus;
update: (callback: (root: R, presence: Presence
) => void) => void;
loading: boolean;
error: Error | undefined;
};
/**
* `YorkieProvider` is a component that provides the Yorkie client to its children.
* It initializes the Yorkie client with the given API key and RPC address.
*/
export declare const YorkieProvider: React.FC>;
/**
* `YorkieProviderProps` extends `ClientOptions` with provider-level options.
*
* - `activate` (default `true`): whether to call `client.activate()` on mount
* and `client.deactivate()` on unmount. Set to `false` for apps that only
* use Channels — under the RefreshChannel-only lifecycle the SDK
* lazy-attaches the client on the first heartbeat, so explicit activate
* round trips become unnecessary. Document use cases (`useDocument`,
* `useYorkieDoc`) still require activation, so leave this `true` if any
* descendant attaches a document.
*/
declare type YorkieProviderProps = Omit & {
activate?: boolean;
/**
* The client key, as `ClientOptions.key`.
*
* It is spelled differently here because `key` is reserved by React: React
* strips it at element creation — as a JSX attribute and through a spread
* alike — so a `key` prop never reaches this component and could never reach
* the `Client` constructor. `ClientOptions.key` is therefore unreachable
* through the provider without an alias, which matters for offline
* persistence: the SDK's store is keyed by `apiKey/clientKey/docKey`, so a
* client whose key is random per session resumes nothing.
*
* Changing it builds a new client, since the key is what the client carries.
*/
clientKey?: string;
};
export { }