@yorkie-js/react 0.7.7 → 0.7.9

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.
package/README.md CHANGED
@@ -8,7 +8,7 @@ To get started using Yorkie React SDK, see: https://yorkie.dev/docs/getting-star
8
8
 
9
9
  ## Contributing
10
10
 
11
- See [CONTRIBUTING](CONTRIBUTING.md) for details on submitting patches and the contribution workflow.
11
+ See [CONTRIBUTING](../../CONTRIBUTING.md) for details on submitting patches and the contribution workflow.
12
12
 
13
13
  ## Contributors ✨
14
14
 
@@ -10,6 +10,7 @@ import { Presence } from '@yorkie-js/sdk';
10
10
  import { PropsWithChildren } from 'react';
11
11
  import { RevisionSummary } from '@yorkie-js/sdk';
12
12
  import { StreamConnectionStatus } from '@yorkie-js/sdk';
13
+ import { SyncMode } from '@yorkie-js/sdk';
13
14
  import { Text as Text_2 } from '@yorkie-js/sdk';
14
15
  import { Tree } from '@yorkie-js/sdk';
15
16
 
@@ -19,12 +20,17 @@ import { Tree } from '@yorkie-js/sdk';
19
20
  *
20
21
  * @example
21
22
  * ```tsx
23
+ * import { ChannelProvider, SyncMode } from '@yorkie-js/react';
24
+ *
22
25
  * <YorkieProvider apiKey="..." rpcAddr="...">
23
- * <ChannelProvider channelKey="room-123" isRealtime={true}>
26
+ * <ChannelProvider channelKey="room-123" syncMode={SyncMode.Realtime}>
24
27
  * <ChatRoom />
25
28
  * </ChannelProvider>
26
29
  * </YorkieProvider>
27
30
  * ```
31
+ *
32
+ * The boolean `isRealtime` prop is also accepted as a shortcut for
33
+ * the Realtime/Manual choice (`true` → Realtime, `false` → Manual).
28
34
  */
29
35
  export declare const ChannelProvider: React.FC<ChannelProviderProps>;
30
36
 
@@ -37,12 +43,31 @@ declare type ChannelProviderProps = PropsWithChildren<{
37
43
  */
38
44
  channelKey: string;
39
45
  /**
40
- * `isRealtime` determines the synchronization mode.
41
- * - true: Realtime mode (automatic updates via watch stream)
42
- * - false: Manual mode (requires manual sync)
43
- * @default true
46
+ * `syncMode` selects how the channel keeps presence in sync with the server.
47
+ * - `SyncMode.Realtime` (default): open a watch stream and run the
48
+ * heartbeat. Required to receive broadcast events.
49
+ * - `SyncMode.Polling`: heartbeat-only. No watch stream is opened.
50
+ * Recommended for large channels where broadcast is not needed.
51
+ * - `SyncMode.Manual`: no automatic activity.
52
+ *
53
+ * If `isRealtime` is also set, `syncMode` wins.
54
+ */
55
+ syncMode?: SyncMode;
56
+ /**
57
+ * `isRealtime` is a convenience prop covering only Realtime/Manual.
58
+ * - `true`: equivalent to `syncMode={SyncMode.Realtime}`.
59
+ * - `false`: equivalent to `syncMode={SyncMode.Manual}`.
60
+ *
61
+ * Use `syncMode` directly when you want `SyncMode.Polling`, which this
62
+ * boolean prop cannot express. When neither prop is set, the channel
63
+ * falls back to `SyncMode.Realtime`.
44
64
  */
45
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;
46
71
  }>;
47
72
 
48
73
  export { Counter }
@@ -73,11 +98,21 @@ declare type DocumentContextType<R, P extends Indexable = Indexable> = {
73
98
  * This component must be under a `YorkieProvider` component to initialize the
74
99
  * Yorkie client properly.
75
100
  */
76
- 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, }: {
77
102
  docKey: string;
78
103
  initialRoot?: R;
79
104
  initialPresence?: P;
80
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;
81
116
  children?: default_2.ReactNode;
82
117
  }) => JSX.Element;
83
118
 
@@ -92,6 +127,8 @@ export { RevisionSummary }
92
127
  */
93
128
  export declare function shallowEqual<T>(valueA: T, valueB: T): boolean;
94
129
 
130
+ export { SyncMode }
131
+
95
132
  export { Text_2 as Text }
96
133
 
97
134
  export { Tree }
@@ -149,6 +186,92 @@ export declare const useConnection: () => StreamConnectionStatus;
149
186
  */
150
187
  export declare function useDocument<R, P extends Indexable = Indexable>(): DocumentContextType<R, P>;
151
188
 
189
+ /**
190
+ * `usePeekChannel` reads a channel's current session count without joining
191
+ * the channel. By default it fetches once on mount; pass `pollInterval` to
192
+ * opt into continuous polling. The caller does not create a Session on the
193
+ * server, does not receive broadcasts, and does not contribute to the
194
+ * channel's count.
195
+ *
196
+ * Prefer this over `<ChannelProvider readOnly>` when many viewers need to
197
+ * display a count and only a few become real participants — e.g. a global
198
+ * "N people writing" badge shown on every surrounding page.
199
+ *
200
+ * @example One-shot (snapshot at entry)
201
+ * ```tsx
202
+ * function WritersBadge() {
203
+ * const { sessionCount, loading } = usePeekChannel('post-writers');
204
+ * if (loading) return null;
205
+ * return <span>{sessionCount} writing</span>;
206
+ * }
207
+ * ```
208
+ *
209
+ * @example Continuous polling
210
+ * ```tsx
211
+ * function LiveCounter() {
212
+ * const { sessionCount } = usePeekChannel('post-writers', {
213
+ * pollInterval: 3000,
214
+ * });
215
+ * return <span>{sessionCount} writing</span>;
216
+ * }
217
+ * ```
218
+ *
219
+ * @example Imperative refetch
220
+ * ```tsx
221
+ * function WithRefresh() {
222
+ * const { sessionCount, refetch } = usePeekChannel('post-writers');
223
+ * return (
224
+ * <button onClick={() => refetch()}>{sessionCount} (refresh)</button>
225
+ * );
226
+ * }
227
+ * ```
228
+ */
229
+ export declare function usePeekChannel(channelKey: string, opts?: UsePeekChannelOptions): UsePeekChannelResult;
230
+
231
+ /**
232
+ * `UsePeekChannelOptions` are user-settable options for `usePeekChannel`.
233
+ */
234
+ export declare interface UsePeekChannelOptions {
235
+ /**
236
+ * `pollInterval` opts the hook into continuous polling at the given
237
+ * cadence (ms). When unset, the hook fetches once on mount and stops —
238
+ * this matches the common "snapshot at entry" pattern. Use polling only
239
+ * when the UI genuinely needs a live-updating count.
240
+ */
241
+ pollInterval?: number;
242
+ /**
243
+ * `enabled` toggles execution. When false, the hook does not fetch and
244
+ * holds the last value. Default: true.
245
+ */
246
+ enabled?: boolean;
247
+ }
248
+
249
+ /**
250
+ * `UsePeekChannelResult` is the state exposed by `usePeekChannel`.
251
+ */
252
+ export declare interface UsePeekChannelResult {
253
+ /**
254
+ * `sessionCount` is the most recently fetched count. Starts at 0 before
255
+ * the first successful fetch; gate display on `loading` if 0-vs-unfetched
256
+ * matters in your UI.
257
+ */
258
+ sessionCount: number;
259
+ /**
260
+ * `loading` is true before the first successful fetch (or while a
261
+ * `refetch()` is in flight). Becomes false on success or error.
262
+ */
263
+ loading: boolean;
264
+ /**
265
+ * `error` holds the last error from a fetch, if any.
266
+ */
267
+ error?: Error;
268
+ /**
269
+ * `refetch` issues a peek immediately, ignoring `pollInterval`. Useful on
270
+ * button clicks or after user actions that may have changed the count.
271
+ */
272
+ refetch: () => Promise<void>;
273
+ }
274
+
152
275
  /**
153
276
  * `usePresences` is a custom hook that returns the presences of the document.
154
277
  */
@@ -190,6 +313,8 @@ export declare function useYorkieDoc<R, P extends Indexable = Indexable>(apiKey:
190
313
  initialRoot?: R;
191
314
  initialPresence?: P;
192
315
  enableDevtools?: boolean;
316
+ syncMode?: SyncMode;
317
+ documentPollInterval?: number;
193
318
  }): {
194
319
  root: R;
195
320
  presences: Array<{