@yorkie-js/react 0.7.8 → 0.7.10-rc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -63,6 +63,11 @@ declare type ChannelProviderProps = PropsWithChildren<{
63
63
  * falls back to `SyncMode.Realtime`.
64
64
  */
65
65
  isRealtime?: boolean;
66
+ /**
67
+ * `channelHeartbeatInterval` overrides the heartbeat interval (ms).
68
+ * Applied at attach time. Defaults: Polling=3000, Realtime=30000.
69
+ */
70
+ channelHeartbeatInterval?: number;
66
71
  }>;
67
72
 
68
73
  export { Counter }
@@ -93,11 +98,21 @@ declare type DocumentContextType<R, P extends Indexable = Indexable> = {
93
98
  * This component must be under a `YorkieProvider` component to initialize the
94
99
  * Yorkie client properly.
95
100
  */
96
- export declare const DocumentProvider: <R, P extends Indexable = Indexable>({ docKey, initialRoot, initialPresence, enableDevtools, children, }: {
101
+ export declare const DocumentProvider: <R, P extends Indexable = Indexable>({ docKey, initialRoot, initialPresence, enableDevtools, syncMode, documentPollInterval, children, }: {
97
102
  docKey: string;
98
103
  initialRoot?: R;
99
104
  initialPresence?: P;
100
105
  enableDevtools?: boolean;
106
+ /**
107
+ * `syncMode` defines the synchronization mode of the document.
108
+ * Defaults to `SyncMode.Realtime`.
109
+ */
110
+ syncMode?: SyncMode;
111
+ /**
112
+ * `documentPollInterval` (ms) — only used when `syncMode` is `Polling`.
113
+ * Default: 3000. Applied at attach time.
114
+ */
115
+ documentPollInterval?: number;
101
116
  children?: default_2.ReactNode;
102
117
  }) => JSX.Element;
103
118
 
@@ -122,7 +137,8 @@ export { Tree }
122
137
  * `useChannel` is a custom hook that returns the channel state.
123
138
  * It must be used within a ChannelProvider.
124
139
  *
125
- * @returns An object containing sessionCount, loading, and error state
140
+ * @returns An object containing sessionCount, loading, error state and
141
+ * a `detach` function for permanently stopping the channel.
126
142
  *
127
143
  * @example
128
144
  * ```tsx
@@ -140,6 +156,7 @@ export declare const useChannel: () => {
140
156
  sessionCount: number;
141
157
  loading: boolean;
142
158
  error: Error | undefined;
159
+ detach: () => Promise<void>;
143
160
  };
144
161
 
145
162
  /**
@@ -171,6 +188,92 @@ export declare const useConnection: () => StreamConnectionStatus;
171
188
  */
172
189
  export declare function useDocument<R, P extends Indexable = Indexable>(): DocumentContextType<R, P>;
173
190
 
191
+ /**
192
+ * `usePeekChannel` reads a channel's current session count without joining
193
+ * the channel. By default it fetches once on mount; pass `pollInterval` to
194
+ * opt into continuous polling. The caller does not create a Session on the
195
+ * server, does not receive broadcasts, and does not contribute to the
196
+ * channel's count.
197
+ *
198
+ * Prefer this over `<ChannelProvider readOnly>` when many viewers need to
199
+ * display a count and only a few become real participants — e.g. a global
200
+ * "N people writing" badge shown on every surrounding page.
201
+ *
202
+ * @example One-shot (snapshot at entry)
203
+ * ```tsx
204
+ * function WritersBadge() {
205
+ * const { sessionCount, loading } = usePeekChannel('post-writers');
206
+ * if (loading) return null;
207
+ * return <span>{sessionCount} writing</span>;
208
+ * }
209
+ * ```
210
+ *
211
+ * @example Continuous polling
212
+ * ```tsx
213
+ * function LiveCounter() {
214
+ * const { sessionCount } = usePeekChannel('post-writers', {
215
+ * pollInterval: 3000,
216
+ * });
217
+ * return <span>{sessionCount} writing</span>;
218
+ * }
219
+ * ```
220
+ *
221
+ * @example Imperative refetch
222
+ * ```tsx
223
+ * function WithRefresh() {
224
+ * const { sessionCount, refetch } = usePeekChannel('post-writers');
225
+ * return (
226
+ * <button onClick={() => refetch()}>{sessionCount} (refresh)</button>
227
+ * );
228
+ * }
229
+ * ```
230
+ */
231
+ export declare function usePeekChannel(channelKey: string, opts?: UsePeekChannelOptions): UsePeekChannelResult;
232
+
233
+ /**
234
+ * `UsePeekChannelOptions` are user-settable options for `usePeekChannel`.
235
+ */
236
+ export declare interface UsePeekChannelOptions {
237
+ /**
238
+ * `pollInterval` opts the hook into continuous polling at the given
239
+ * cadence (ms). When unset, the hook fetches once on mount and stops —
240
+ * this matches the common "snapshot at entry" pattern. Use polling only
241
+ * when the UI genuinely needs a live-updating count.
242
+ */
243
+ pollInterval?: number;
244
+ /**
245
+ * `enabled` toggles execution. When false, the hook does not fetch and
246
+ * holds the last value. Default: true.
247
+ */
248
+ enabled?: boolean;
249
+ }
250
+
251
+ /**
252
+ * `UsePeekChannelResult` is the state exposed by `usePeekChannel`.
253
+ */
254
+ export declare interface UsePeekChannelResult {
255
+ /**
256
+ * `sessionCount` is the most recently fetched count. Starts at 0 before
257
+ * the first successful fetch; gate display on `loading` if 0-vs-unfetched
258
+ * matters in your UI.
259
+ */
260
+ sessionCount: number;
261
+ /**
262
+ * `loading` is true before the first successful fetch (or while a
263
+ * `refetch()` is in flight). Becomes false on success or error.
264
+ */
265
+ loading: boolean;
266
+ /**
267
+ * `error` holds the last error from a fetch, if any.
268
+ */
269
+ error?: Error;
270
+ /**
271
+ * `refetch` issues a peek immediately, ignoring `pollInterval`. Useful on
272
+ * button clicks or after user actions that may have changed the count.
273
+ */
274
+ refetch: () => Promise<void>;
275
+ }
276
+
174
277
  /**
175
278
  * `usePresences` is a custom hook that returns the presences of the document.
176
279
  */
@@ -212,6 +315,8 @@ export declare function useYorkieDoc<R, P extends Indexable = Indexable>(apiKey:
212
315
  initialRoot?: R;
213
316
  initialPresence?: P;
214
317
  enableDevtools?: boolean;
318
+ syncMode?: SyncMode;
319
+ documentPollInterval?: number;
215
320
  }): {
216
321
  root: R;
217
322
  presences: Array<{
@@ -228,6 +333,21 @@ export declare function useYorkieDoc<R, P extends Indexable = Indexable>(apiKey:
228
333
  * `YorkieProvider` is a component that provides the Yorkie client to its children.
229
334
  * It initializes the Yorkie client with the given API key and RPC address.
230
335
  */
231
- export declare const YorkieProvider: React.FC<PropsWithChildren<ClientOptions>>;
336
+ export declare const YorkieProvider: React.FC<PropsWithChildren<YorkieProviderProps>>;
337
+
338
+ /**
339
+ * `YorkieProviderProps` extends `ClientOptions` with provider-level options.
340
+ *
341
+ * - `activate` (default `true`): whether to call `client.activate()` on mount
342
+ * and `client.deactivate()` on unmount. Set to `false` for apps that only
343
+ * use Channels — under the RefreshChannel-only lifecycle the SDK
344
+ * lazy-attaches the client on the first heartbeat, so explicit activate
345
+ * round trips become unnecessary. Document use cases (`useDocument`,
346
+ * `useYorkieDoc`) still require activation, so leave this `true` if any
347
+ * descendant attaches a document.
348
+ */
349
+ declare type YorkieProviderProps = ClientOptions & {
350
+ activate?: boolean;
351
+ };
232
352
 
233
353
  export { }