@pluv/react 0.14.1 → 0.16.0

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/dist/index.js CHANGED
@@ -32,18 +32,17 @@ var src_exports = {};
32
32
  __export(src_exports, {
33
33
  ConnectionState: () => import_client2.ConnectionState,
34
34
  createBundle: () => createBundle,
35
- createClient: () => import_client2.createClient,
36
- y: () => import_client2.y
35
+ createClient: () => import_client2.createClient
37
36
  });
38
37
  module.exports = __toCommonJS(src_exports);
39
38
  var import_client2 = require("@pluv/client");
40
39
 
41
40
  // src/createBundle.tsx
42
41
  var import_react3 = require("react");
43
- var import_react4 = require("react");
44
42
 
45
43
  // src/createRoomBundle.tsx
46
44
  var import_client = require("@pluv/client");
45
+ var import_crdt = require("@pluv/crdt");
47
46
  var import_fast_deep_equal = __toESM(require("fast-deep-equal"));
48
47
  var import_react2 = require("react");
49
48
 
@@ -69,7 +68,9 @@ var shallowArrayEqual = (a, b) => {
69
68
 
70
69
  // src/createRoomBundle.tsx
71
70
  var import_jsx_runtime = require("react/jsx-runtime");
72
- var createRoomBundle = (client, options = {}) => {
71
+ var createRoomBundle = (client, options) => {
72
+ var _a;
73
+ const _initialStorage = (_a = options.initialStorage) != null ? _a : import_crdt.noop.doc();
73
74
  const PluvRoomContext = (0, import_react2.createContext)(null);
74
75
  const MockedRoomContext = (0, import_react2.createContext)({ room: null });
75
76
  const MockedRoomProvider = (0, import_react2.memo)((props) => {
@@ -82,12 +83,10 @@ var createRoomBundle = (client, options = {}) => {
82
83
  } = props;
83
84
  const [room] = (0, import_react2.useState)(() => {
84
85
  return new import_client.MockedRoom(_room, {
85
- captureTimeout: options.captureTimeout,
86
86
  events,
87
87
  initialPresence,
88
- initialStorage: typeof initialStorage === "function" ? initialStorage : options.initialStorage,
89
- presence: options.presence,
90
- trackedOrigins: options.trackedOrigins
88
+ initialStorage: typeof initialStorage === "function" ? _initialStorage.getFactory(initialStorage) : _initialStorage,
89
+ presence: options.presence
91
90
  });
92
91
  });
93
92
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MockedRoomContext.Provider, { value: { room }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PluvRoomContext.Provider, { value: room, children }) });
@@ -107,13 +106,11 @@ var createRoomBundle = (client, options = {}) => {
107
106
  const [room] = (0, import_react2.useState)(() => {
108
107
  return client.createRoom(_room, {
109
108
  addons: options.addons,
110
- captureTimeout: options.captureTimeout,
111
109
  debug,
112
110
  initialPresence,
113
- initialStorage: typeof initialStorage === "function" ? initialStorage : options.initialStorage,
111
+ initialStorage: typeof initialStorage === "function" ? _initialStorage.getFactory(initialStorage) : _initialStorage,
114
112
  presence: options.presence,
115
- onAuthorizationFail,
116
- trackedOrigins: options.trackedOrigins
113
+ onAuthorizationFail
117
114
  });
118
115
  });
119
116
  (0, import_react2.useEffect)(() => {
@@ -133,9 +130,9 @@ var createRoomBundle = (client, options = {}) => {
133
130
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PluvRoomContext.Provider, { value: mockedRoom != null ? mockedRoom : room, children });
134
131
  });
135
132
  PluvRoomProvider.displayName = "PluvRoomProvider";
136
- const usePluvRoom = () => (0, import_react2.useContext)(PluvRoomContext);
137
- const usePluvBroadcast = () => {
138
- const room = usePluvRoom();
133
+ const useRoom = () => (0, import_react2.useContext)(PluvRoomContext);
134
+ const useBroadcast = () => {
135
+ const room = useRoom();
139
136
  return (0, import_react2.useCallback)(
140
137
  (event, data) => {
141
138
  room.broadcast(event, data);
@@ -143,8 +140,8 @@ var createRoomBundle = (client, options = {}) => {
143
140
  [room]
144
141
  );
145
142
  };
146
- const usePluvCanRedo = () => {
147
- const room = usePluvRoom();
143
+ const useCanRedo = () => {
144
+ const room = useRoom();
148
145
  const subscribe = (0, import_react2.useCallback)(
149
146
  (onStoreChange) => room.storageRoot(onStoreChange),
150
147
  [room]
@@ -158,8 +155,8 @@ var createRoomBundle = (client, options = {}) => {
158
155
  );
159
156
  return canRedo;
160
157
  };
161
- const usePluvCanUndo = () => {
162
- const room = usePluvRoom();
158
+ const useCanUndo = () => {
159
+ const room = useRoom();
163
160
  const subscribe = (0, import_react2.useCallback)(
164
161
  (onStoreChange) => room.storageRoot(onStoreChange),
165
162
  [room]
@@ -173,9 +170,9 @@ var createRoomBundle = (client, options = {}) => {
173
170
  );
174
171
  return canRedo;
175
172
  };
176
- const usePluvConnection = (selector = identity, options2) => {
177
- var _a;
178
- const room = usePluvRoom();
173
+ const useConnection = (selector = identity, options2) => {
174
+ var _a2;
175
+ const room = useRoom();
179
176
  const subscribe = (0, import_react2.useCallback)(
180
177
  (onStoreChange) => {
181
178
  return room.subscribe("connection", onStoreChange);
@@ -192,15 +189,15 @@ var createRoomBundle = (client, options = {}) => {
192
189
  getSnapshot,
193
190
  getSnapshot,
194
191
  _selector,
195
- (_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : import_fast_deep_equal.default
192
+ (_a2 = options2 == null ? void 0 : options2.isEqual) != null ? _a2 : import_fast_deep_equal.default
196
193
  );
197
194
  };
198
- const usePluvDoc = () => {
199
- const room = usePluvRoom();
195
+ const useDoc = () => {
196
+ const room = useRoom();
200
197
  return room.getDoc();
201
198
  };
202
- const usePluvEvent = (type, callback) => {
203
- const room = usePluvRoom();
199
+ const useEvent = (type, callback) => {
200
+ const room = useRoom();
204
201
  (0, import_react2.useEffect)(() => {
205
202
  const unsubscribe = room.event(type, callback);
206
203
  return () => {
@@ -208,9 +205,9 @@ var createRoomBundle = (client, options = {}) => {
208
205
  };
209
206
  }, [callback, room, type]);
210
207
  };
211
- const usePluvMyPresence = (selector = identity, options2) => {
212
- var _a;
213
- const room = usePluvRoom();
208
+ const useMyPresence = (selector = identity, options2) => {
209
+ var _a2;
210
+ const room = useRoom();
214
211
  const subscribe = (0, import_react2.useCallback)(
215
212
  (onStoreChange) => {
216
213
  return room.subscribe("my-presence", onStoreChange);
@@ -227,7 +224,7 @@ var createRoomBundle = (client, options = {}) => {
227
224
  getSnapshot,
228
225
  getSnapshot,
229
226
  _selector,
230
- (_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : import_fast_deep_equal.default
227
+ (_a2 = options2 == null ? void 0 : options2.isEqual) != null ? _a2 : import_fast_deep_equal.default
231
228
  );
232
229
  const updateMyPresence = (0, import_react2.useCallback)(
233
230
  (value) => {
@@ -238,9 +235,9 @@ var createRoomBundle = (client, options = {}) => {
238
235
  );
239
236
  return [myPresence, updateMyPresence];
240
237
  };
241
- const usePluvMyself = (selector = identity, options2) => {
242
- var _a;
243
- const room = usePluvRoom();
238
+ const useMyself = (selector = identity, options2) => {
239
+ var _a2;
240
+ const room = useRoom();
244
241
  const subscribe = (0, import_react2.useCallback)(
245
242
  (onStoreChange) => {
246
243
  return room.subscribe("myself", onStoreChange);
@@ -259,12 +256,12 @@ var createRoomBundle = (client, options = {}) => {
259
256
  getSnapshot,
260
257
  getSnapshot,
261
258
  _selector,
262
- (_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : import_fast_deep_equal.default
259
+ (_a2 = options2 == null ? void 0 : options2.isEqual) != null ? _a2 : import_fast_deep_equal.default
263
260
  );
264
261
  };
265
- const usePluvOther = (connectionId, selector = identity, options2) => {
266
- var _a;
267
- const room = usePluvRoom();
262
+ const useOther = (connectionId, selector = identity, options2) => {
263
+ var _a2;
264
+ const room = useRoom();
268
265
  const subscribe = (0, import_react2.useCallback)(
269
266
  (onStoreChange) => {
270
267
  return room.other(connectionId, onStoreChange);
@@ -286,12 +283,12 @@ var createRoomBundle = (client, options = {}) => {
286
283
  getSnapshot,
287
284
  getSnapshot,
288
285
  _selector,
289
- (_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : import_fast_deep_equal.default
286
+ (_a2 = options2 == null ? void 0 : options2.isEqual) != null ? _a2 : import_fast_deep_equal.default
290
287
  );
291
288
  };
292
- const usePluvOthers = (selector = identity, options2) => {
293
- var _a;
294
- const room = usePluvRoom();
289
+ const useOthers = (selector = identity, options2) => {
290
+ var _a2;
291
+ const room = useRoom();
295
292
  const subscribe = (0, import_react2.useCallback)(
296
293
  (onStoreChange) => {
297
294
  return room.subscribe("others", onStoreChange);
@@ -304,26 +301,31 @@ var createRoomBundle = (client, options = {}) => {
304
301
  getSnapshot,
305
302
  getSnapshot,
306
303
  selector,
307
- (_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : shallowArrayEqual
304
+ (_a2 = options2 == null ? void 0 : options2.isEqual) != null ? _a2 : shallowArrayEqual
308
305
  );
309
306
  };
310
- const usePluvRedo = () => {
311
- const room = usePluvRoom();
307
+ const useRedo = () => {
308
+ const room = useRoom();
312
309
  return room.redo;
313
310
  };
314
- const usePluvStorage = (key, selector = identity, options2) => {
315
- var _a;
316
- const room = usePluvRoom();
311
+ const useStorage = (key, selector = identity, options2) => {
312
+ var _a2, _b;
313
+ const room = useRoom();
314
+ const rerender = useRerender();
315
+ room.subscribe("storage-loaded", () => {
316
+ rerender();
317
+ });
317
318
  const subscribe = (0, import_react2.useCallback)(
318
319
  (onStoreChange) => room.storage(key, onStoreChange),
319
320
  [key, room]
320
321
  );
321
322
  const getSnapshot = (0, import_react2.useCallback)(() => {
322
- return room.getStorage(key).toJSON();
323
+ var _a3;
324
+ return (_a3 = room.getStorage(key)) == null ? void 0 : _a3.toJson();
323
325
  }, [key, room]);
324
326
  const _selector = (0, import_react2.useCallback)(
325
327
  (snapshot) => {
326
- return selector(snapshot);
328
+ return snapshot === null ? null : selector(snapshot);
327
329
  },
328
330
  [selector]
329
331
  );
@@ -332,17 +334,17 @@ var createRoomBundle = (client, options = {}) => {
332
334
  getSnapshot,
333
335
  getSnapshot,
334
336
  _selector,
335
- (_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : import_fast_deep_equal.default
337
+ (_a2 = options2 == null ? void 0 : options2.isEqual) != null ? _a2 : import_fast_deep_equal.default
336
338
  );
337
- const sharedType = room.getStorage(key);
339
+ const sharedType = (_b = room.getStorage(key)) != null ? _b : null;
338
340
  return [data, sharedType];
339
341
  };
340
- const usePluvTransact = () => {
341
- const room = usePluvRoom();
342
+ const useTransact = () => {
343
+ const room = useRoom();
342
344
  return room.transact;
343
345
  };
344
- const usePluvUndo = () => {
345
- const room = usePluvRoom();
346
+ const useUndo = () => {
347
+ const room = useRoom();
346
348
  return room.undo;
347
349
  };
348
350
  return {
@@ -350,21 +352,21 @@ var createRoomBundle = (client, options = {}) => {
350
352
  MockedRoomProvider,
351
353
  PluvRoomProvider,
352
354
  // hooks
353
- usePluvBroadcast,
354
- usePluvCanRedo,
355
- usePluvCanUndo,
356
- usePluvConnection,
357
- usePluvDoc,
358
- usePluvEvent,
359
- usePluvMyPresence,
360
- usePluvMyself,
361
- usePluvOther,
362
- usePluvOthers,
363
- usePluvRedo,
364
- usePluvRoom,
365
- usePluvStorage,
366
- usePluvTransact,
367
- usePluvUndo
355
+ useBroadcast,
356
+ useCanRedo,
357
+ useCanUndo,
358
+ useConnection,
359
+ useDoc,
360
+ useEvent,
361
+ useMyPresence,
362
+ useMyself,
363
+ useOther,
364
+ useOthers,
365
+ useRedo,
366
+ useRoom,
367
+ useStorage,
368
+ useTransact,
369
+ useUndo
368
370
  };
369
371
  };
370
372
 
@@ -372,23 +374,22 @@ var createRoomBundle = (client, options = {}) => {
372
374
  var import_jsx_runtime2 = require("react/jsx-runtime");
373
375
  var createBundle = (client) => {
374
376
  const PluvContext = (0, import_react3.createContext)(null);
375
- const PluvProvider = (0, import_react4.memo)((props) => {
377
+ const PluvProvider = (0, import_react3.memo)((props) => {
376
378
  const { children } = props;
377
379
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PluvContext.Provider, { value: client, children });
378
380
  });
379
381
  PluvProvider.displayName = "PluvProvider";
380
- const usePluvClient = () => (0, import_react4.useContext)(PluvContext);
381
- const createRoomBundle2 = (options = {}) => createRoomBundle(client, options);
382
+ const useClient = () => (0, import_react3.useContext)(PluvContext);
383
+ const createRoomBundle2 = (options) => createRoomBundle(client, options);
382
384
  return {
383
385
  createRoomBundle: createRoomBundle2,
384
386
  PluvProvider,
385
- usePluvClient
387
+ useClient
386
388
  };
387
389
  };
388
390
  // Annotate the CommonJS export names for ESM import in node:
389
391
  0 && (module.exports = {
390
392
  ConnectionState,
391
393
  createBundle,
392
- createClient,
393
- y
394
+ createClient
394
395
  });
package/dist/index.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  // src/index.ts
2
- import { ConnectionState, createClient, y } from "@pluv/client";
2
+ import { ConnectionState, createClient } from "@pluv/client";
3
3
 
4
4
  // src/createBundle.tsx
5
- import { createContext as createContext2 } from "react";
6
- import { memo as memo2, useContext as useContext2 } from "react";
5
+ import { createContext as createContext2, memo as memo2, useContext as useContext2 } from "react";
7
6
 
8
7
  // src/createRoomBundle.tsx
9
8
  import { MockedRoom } from "@pluv/client";
9
+ import { noop } from "@pluv/crdt";
10
10
  import fastDeepEqual from "fast-deep-equal";
11
11
  import {
12
12
  createContext,
@@ -39,7 +39,9 @@ var shallowArrayEqual = (a, b) => {
39
39
 
40
40
  // src/createRoomBundle.tsx
41
41
  import { jsx } from "react/jsx-runtime";
42
- var createRoomBundle = (client, options = {}) => {
42
+ var createRoomBundle = (client, options) => {
43
+ var _a;
44
+ const _initialStorage = (_a = options.initialStorage) != null ? _a : noop.doc();
43
45
  const PluvRoomContext = createContext(null);
44
46
  const MockedRoomContext = createContext({ room: null });
45
47
  const MockedRoomProvider = memo((props) => {
@@ -52,12 +54,10 @@ var createRoomBundle = (client, options = {}) => {
52
54
  } = props;
53
55
  const [room] = useState2(() => {
54
56
  return new MockedRoom(_room, {
55
- captureTimeout: options.captureTimeout,
56
57
  events,
57
58
  initialPresence,
58
- initialStorage: typeof initialStorage === "function" ? initialStorage : options.initialStorage,
59
- presence: options.presence,
60
- trackedOrigins: options.trackedOrigins
59
+ initialStorage: typeof initialStorage === "function" ? _initialStorage.getFactory(initialStorage) : _initialStorage,
60
+ presence: options.presence
61
61
  });
62
62
  });
63
63
  return /* @__PURE__ */ jsx(MockedRoomContext.Provider, { value: { room }, children: /* @__PURE__ */ jsx(PluvRoomContext.Provider, { value: room, children }) });
@@ -77,13 +77,11 @@ var createRoomBundle = (client, options = {}) => {
77
77
  const [room] = useState2(() => {
78
78
  return client.createRoom(_room, {
79
79
  addons: options.addons,
80
- captureTimeout: options.captureTimeout,
81
80
  debug,
82
81
  initialPresence,
83
- initialStorage: typeof initialStorage === "function" ? initialStorage : options.initialStorage,
82
+ initialStorage: typeof initialStorage === "function" ? _initialStorage.getFactory(initialStorage) : _initialStorage,
84
83
  presence: options.presence,
85
- onAuthorizationFail,
86
- trackedOrigins: options.trackedOrigins
84
+ onAuthorizationFail
87
85
  });
88
86
  });
89
87
  useEffect(() => {
@@ -103,9 +101,9 @@ var createRoomBundle = (client, options = {}) => {
103
101
  return /* @__PURE__ */ jsx(PluvRoomContext.Provider, { value: mockedRoom != null ? mockedRoom : room, children });
104
102
  });
105
103
  PluvRoomProvider.displayName = "PluvRoomProvider";
106
- const usePluvRoom = () => useContext(PluvRoomContext);
107
- const usePluvBroadcast = () => {
108
- const room = usePluvRoom();
104
+ const useRoom = () => useContext(PluvRoomContext);
105
+ const useBroadcast = () => {
106
+ const room = useRoom();
109
107
  return useCallback2(
110
108
  (event, data) => {
111
109
  room.broadcast(event, data);
@@ -113,8 +111,8 @@ var createRoomBundle = (client, options = {}) => {
113
111
  [room]
114
112
  );
115
113
  };
116
- const usePluvCanRedo = () => {
117
- const room = usePluvRoom();
114
+ const useCanRedo = () => {
115
+ const room = useRoom();
118
116
  const subscribe = useCallback2(
119
117
  (onStoreChange) => room.storageRoot(onStoreChange),
120
118
  [room]
@@ -128,8 +126,8 @@ var createRoomBundle = (client, options = {}) => {
128
126
  );
129
127
  return canRedo;
130
128
  };
131
- const usePluvCanUndo = () => {
132
- const room = usePluvRoom();
129
+ const useCanUndo = () => {
130
+ const room = useRoom();
133
131
  const subscribe = useCallback2(
134
132
  (onStoreChange) => room.storageRoot(onStoreChange),
135
133
  [room]
@@ -143,9 +141,9 @@ var createRoomBundle = (client, options = {}) => {
143
141
  );
144
142
  return canRedo;
145
143
  };
146
- const usePluvConnection = (selector = identity, options2) => {
147
- var _a;
148
- const room = usePluvRoom();
144
+ const useConnection = (selector = identity, options2) => {
145
+ var _a2;
146
+ const room = useRoom();
149
147
  const subscribe = useCallback2(
150
148
  (onStoreChange) => {
151
149
  return room.subscribe("connection", onStoreChange);
@@ -162,15 +160,15 @@ var createRoomBundle = (client, options = {}) => {
162
160
  getSnapshot,
163
161
  getSnapshot,
164
162
  _selector,
165
- (_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : fastDeepEqual
163
+ (_a2 = options2 == null ? void 0 : options2.isEqual) != null ? _a2 : fastDeepEqual
166
164
  );
167
165
  };
168
- const usePluvDoc = () => {
169
- const room = usePluvRoom();
166
+ const useDoc = () => {
167
+ const room = useRoom();
170
168
  return room.getDoc();
171
169
  };
172
- const usePluvEvent = (type, callback) => {
173
- const room = usePluvRoom();
170
+ const useEvent = (type, callback) => {
171
+ const room = useRoom();
174
172
  useEffect(() => {
175
173
  const unsubscribe = room.event(type, callback);
176
174
  return () => {
@@ -178,9 +176,9 @@ var createRoomBundle = (client, options = {}) => {
178
176
  };
179
177
  }, [callback, room, type]);
180
178
  };
181
- const usePluvMyPresence = (selector = identity, options2) => {
182
- var _a;
183
- const room = usePluvRoom();
179
+ const useMyPresence = (selector = identity, options2) => {
180
+ var _a2;
181
+ const room = useRoom();
184
182
  const subscribe = useCallback2(
185
183
  (onStoreChange) => {
186
184
  return room.subscribe("my-presence", onStoreChange);
@@ -197,7 +195,7 @@ var createRoomBundle = (client, options = {}) => {
197
195
  getSnapshot,
198
196
  getSnapshot,
199
197
  _selector,
200
- (_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : fastDeepEqual
198
+ (_a2 = options2 == null ? void 0 : options2.isEqual) != null ? _a2 : fastDeepEqual
201
199
  );
202
200
  const updateMyPresence = useCallback2(
203
201
  (value) => {
@@ -208,9 +206,9 @@ var createRoomBundle = (client, options = {}) => {
208
206
  );
209
207
  return [myPresence, updateMyPresence];
210
208
  };
211
- const usePluvMyself = (selector = identity, options2) => {
212
- var _a;
213
- const room = usePluvRoom();
209
+ const useMyself = (selector = identity, options2) => {
210
+ var _a2;
211
+ const room = useRoom();
214
212
  const subscribe = useCallback2(
215
213
  (onStoreChange) => {
216
214
  return room.subscribe("myself", onStoreChange);
@@ -229,12 +227,12 @@ var createRoomBundle = (client, options = {}) => {
229
227
  getSnapshot,
230
228
  getSnapshot,
231
229
  _selector,
232
- (_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : fastDeepEqual
230
+ (_a2 = options2 == null ? void 0 : options2.isEqual) != null ? _a2 : fastDeepEqual
233
231
  );
234
232
  };
235
- const usePluvOther = (connectionId, selector = identity, options2) => {
236
- var _a;
237
- const room = usePluvRoom();
233
+ const useOther = (connectionId, selector = identity, options2) => {
234
+ var _a2;
235
+ const room = useRoom();
238
236
  const subscribe = useCallback2(
239
237
  (onStoreChange) => {
240
238
  return room.other(connectionId, onStoreChange);
@@ -256,12 +254,12 @@ var createRoomBundle = (client, options = {}) => {
256
254
  getSnapshot,
257
255
  getSnapshot,
258
256
  _selector,
259
- (_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : fastDeepEqual
257
+ (_a2 = options2 == null ? void 0 : options2.isEqual) != null ? _a2 : fastDeepEqual
260
258
  );
261
259
  };
262
- const usePluvOthers = (selector = identity, options2) => {
263
- var _a;
264
- const room = usePluvRoom();
260
+ const useOthers = (selector = identity, options2) => {
261
+ var _a2;
262
+ const room = useRoom();
265
263
  const subscribe = useCallback2(
266
264
  (onStoreChange) => {
267
265
  return room.subscribe("others", onStoreChange);
@@ -274,26 +272,31 @@ var createRoomBundle = (client, options = {}) => {
274
272
  getSnapshot,
275
273
  getSnapshot,
276
274
  selector,
277
- (_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : shallowArrayEqual
275
+ (_a2 = options2 == null ? void 0 : options2.isEqual) != null ? _a2 : shallowArrayEqual
278
276
  );
279
277
  };
280
- const usePluvRedo = () => {
281
- const room = usePluvRoom();
278
+ const useRedo = () => {
279
+ const room = useRoom();
282
280
  return room.redo;
283
281
  };
284
- const usePluvStorage = (key, selector = identity, options2) => {
285
- var _a;
286
- const room = usePluvRoom();
282
+ const useStorage = (key, selector = identity, options2) => {
283
+ var _a2, _b;
284
+ const room = useRoom();
285
+ const rerender = useRerender();
286
+ room.subscribe("storage-loaded", () => {
287
+ rerender();
288
+ });
287
289
  const subscribe = useCallback2(
288
290
  (onStoreChange) => room.storage(key, onStoreChange),
289
291
  [key, room]
290
292
  );
291
293
  const getSnapshot = useCallback2(() => {
292
- return room.getStorage(key).toJSON();
294
+ var _a3;
295
+ return (_a3 = room.getStorage(key)) == null ? void 0 : _a3.toJson();
293
296
  }, [key, room]);
294
297
  const _selector = useCallback2(
295
298
  (snapshot) => {
296
- return selector(snapshot);
299
+ return snapshot === null ? null : selector(snapshot);
297
300
  },
298
301
  [selector]
299
302
  );
@@ -302,17 +305,17 @@ var createRoomBundle = (client, options = {}) => {
302
305
  getSnapshot,
303
306
  getSnapshot,
304
307
  _selector,
305
- (_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : fastDeepEqual
308
+ (_a2 = options2 == null ? void 0 : options2.isEqual) != null ? _a2 : fastDeepEqual
306
309
  );
307
- const sharedType = room.getStorage(key);
310
+ const sharedType = (_b = room.getStorage(key)) != null ? _b : null;
308
311
  return [data, sharedType];
309
312
  };
310
- const usePluvTransact = () => {
311
- const room = usePluvRoom();
313
+ const useTransact = () => {
314
+ const room = useRoom();
312
315
  return room.transact;
313
316
  };
314
- const usePluvUndo = () => {
315
- const room = usePluvRoom();
317
+ const useUndo = () => {
318
+ const room = useRoom();
316
319
  return room.undo;
317
320
  };
318
321
  return {
@@ -320,21 +323,21 @@ var createRoomBundle = (client, options = {}) => {
320
323
  MockedRoomProvider,
321
324
  PluvRoomProvider,
322
325
  // hooks
323
- usePluvBroadcast,
324
- usePluvCanRedo,
325
- usePluvCanUndo,
326
- usePluvConnection,
327
- usePluvDoc,
328
- usePluvEvent,
329
- usePluvMyPresence,
330
- usePluvMyself,
331
- usePluvOther,
332
- usePluvOthers,
333
- usePluvRedo,
334
- usePluvRoom,
335
- usePluvStorage,
336
- usePluvTransact,
337
- usePluvUndo
326
+ useBroadcast,
327
+ useCanRedo,
328
+ useCanUndo,
329
+ useConnection,
330
+ useDoc,
331
+ useEvent,
332
+ useMyPresence,
333
+ useMyself,
334
+ useOther,
335
+ useOthers,
336
+ useRedo,
337
+ useRoom,
338
+ useStorage,
339
+ useTransact,
340
+ useUndo
338
341
  };
339
342
  };
340
343
 
@@ -347,17 +350,16 @@ var createBundle = (client) => {
347
350
  return /* @__PURE__ */ jsx2(PluvContext.Provider, { value: client, children });
348
351
  });
349
352
  PluvProvider.displayName = "PluvProvider";
350
- const usePluvClient = () => useContext2(PluvContext);
351
- const createRoomBundle2 = (options = {}) => createRoomBundle(client, options);
353
+ const useClient = () => useContext2(PluvContext);
354
+ const createRoomBundle2 = (options) => createRoomBundle(client, options);
352
355
  return {
353
356
  createRoomBundle: createRoomBundle2,
354
357
  PluvProvider,
355
- usePluvClient
358
+ useClient
356
359
  };
357
360
  };
358
361
  export {
359
362
  ConnectionState,
360
363
  createBundle,
361
- createClient,
362
- y
364
+ createClient
363
365
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/react",
3
- "version": "0.14.1",
3
+ "version": "0.16.0",
4
4
  "description": "@pluv/client React.js bindings",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -17,25 +17,24 @@
17
17
  "access": "public"
18
18
  },
19
19
  "dependencies": {
20
- "@types/react": "^18.2.45",
20
+ "@types/react": "^18.2.55",
21
21
  "@types/use-sync-external-store": "^0.0.6",
22
22
  "fast-deep-equal": "^3.1.3",
23
23
  "use-sync-external-store": "^1.2.0",
24
- "@pluv/client": "^0.14.1",
25
- "@pluv/types": "^0.14.1"
24
+ "@pluv/client": "^0.16.0",
25
+ "@pluv/crdt": "^0.16.0",
26
+ "@pluv/types": "^0.16.0"
26
27
  },
27
28
  "peerDependencies": {
28
- "react": "^17.0.0 || ^18.0.0",
29
- "yjs": "^13.0.0"
29
+ "react": "^17.0.0 || ^18.0.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "eslint": "^8.56.0",
33
33
  "react": "^18.2.0",
34
- "tsup": "^8.0.1",
35
- "typescript": "^5.2.2",
36
- "yjs": "^13.6.10",
37
- "@pluv/tsconfig": "^0.14.1",
38
- "eslint-config-pluv": "^0.14.1"
34
+ "tsup": "^8.0.2",
35
+ "typescript": "^5.3.3",
36
+ "@pluv/tsconfig": "^0.16.0",
37
+ "eslint-config-pluv": "^0.16.0"
39
38
  },
40
39
  "scripts": {
41
40
  "build": "tsup src/index.ts --format esm,cjs --dts --external react",