@pluv/react 0.3.0 → 0.5.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.
@@ -1,17 +1,17 @@
1
1
 
2
- > @pluv/react@0.3.0 build /home/runner/work/pluv/pluv/packages/react
2
+ > @pluv/react@0.5.0 build /home/runner/work/pluv/pluv/packages/react
3
3
  > tsup src/index.ts --format esm,cjs --dts --external react
4
4
 
5
5
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
- CLI tsup v6.5.0
7
+ CLI tsup v6.6.3
8
8
  CLI Target: es6
9
9
  ESM Build start
10
10
  CJS Build start
11
- ESM dist/index.mjs 8.27 KB
12
- ESM ⚡️ Build success in 134ms
13
- CJS dist/index.js 10.35 KB
14
- CJS ⚡️ Build success in 164ms
11
+ ESM dist/index.mjs 8.56 KB
12
+ ESM ⚡️ Build success in 80ms
13
+ CJS dist/index.js 10.98 KB
14
+ CJS ⚡️ Build success in 81ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 4002ms
16
+ DTS ⚡️ Build success in 5535ms
17
17
  DTS dist/index.d.ts 4.37 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # @pluv/react
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 327a6ef: renamed y.unstable\_\_object to y.object
8
+
9
+ ### Patch Changes
10
+
11
+ - 78a6119: Fixed MockedRoom not sending storage updates
12
+ - 8bf62cb: bumped dependencies
13
+ - 7e52685: Bumped dependencies
14
+ - b1cb325: Updated dependencies
15
+ - b4e34bc: chore(deps): update dependency @types/react to v18.0.28
16
+ - ec50c73: fix: fixed mocked room not working
17
+ - 8e97fb2: Updated dependencies
18
+ - Updated dependencies [78a6119]
19
+ - Updated dependencies [8bf62cb]
20
+ - Updated dependencies [7e52685]
21
+ - Updated dependencies [b1cb325]
22
+ - Updated dependencies [327a6ef]
23
+ - Updated dependencies [8e97fb2]
24
+ - @pluv/client@0.5.0
25
+ - @pluv/types@0.1.3
26
+
27
+ ## 0.4.0
28
+
29
+ ### Minor Changes
30
+
31
+ - 043c915: Added MockedDataProvider from createRoomBundle
32
+
33
+ ### Patch Changes
34
+
35
+ - 93f8c54: chore(deps): update dependency @types/react to v18.0.27
36
+ - Updated dependencies [595e66f]
37
+ - @pluv/client@0.4.0
38
+
3
39
  ## 0.3.0
4
40
 
5
41
  ### Minor Changes
package/README.md CHANGED
@@ -95,7 +95,7 @@ export const {
95
95
  } = createRoomBundle({
96
96
  initialStorage: () => ({
97
97
  messages: y.array([
98
- y.unstable__object({
98
+ y.object({
99
99
  message: "Hello World!",
100
100
  name: "johnathan_doe",
101
101
  }),
package/dist/index.js CHANGED
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  return to;
19
19
  };
20
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
@@ -54,7 +58,7 @@ var useRerender = () => {
54
58
  };
55
59
 
56
60
  // src/internal/hooks/useSyncExternalStoreWithSelector.ts
57
- var import_with_selector = require("use-sync-external-store/with-selector");
61
+ var import_with_selector = require("use-sync-external-store/with-selector.js");
58
62
 
59
63
  // src/internal/utils/identity.ts
60
64
  var identity = (x) => x;
@@ -68,6 +72,7 @@ var shallowArrayEqual = (a, b) => {
68
72
  var import_jsx_runtime = require("react/jsx-runtime");
69
73
  var createRoomBundle = (client, options = {}) => {
70
74
  const PluvRoomContext = (0, import_react2.createContext)(null);
75
+ const MockedRoomContext = (0, import_react2.createContext)({ room: null });
71
76
  const MockedRoomProvider = (0, import_react3.memo)((props) => {
72
77
  const {
73
78
  children,
@@ -80,14 +85,11 @@ var createRoomBundle = (client, options = {}) => {
80
85
  return new import_client.MockedRoom(_room, {
81
86
  events,
82
87
  initialPresence,
83
- initialStorage,
88
+ initialStorage: typeof initialStorage === "function" ? initialStorage : options.initialStorage,
84
89
  presence: options.presence
85
90
  });
86
91
  });
87
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PluvRoomContext.Provider, {
88
- value: room,
89
- children
90
- });
92
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MockedRoomContext.Provider, { value: { room }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PluvRoomContext.Provider, { value: room, children }) });
91
93
  });
92
94
  MockedRoomProvider.displayName = "MockedRoomProvider";
93
95
  const PluvRoomProvider = (0, import_react3.memo)((props) => {
@@ -100,6 +102,7 @@ var createRoomBundle = (client, options = {}) => {
100
102
  room: _room
101
103
  } = props;
102
104
  const rerender = useRerender();
105
+ const { room: mockedRoom } = (0, import_react3.useContext)(MockedRoomContext);
103
106
  const [room] = (0, import_react2.useState)(() => {
104
107
  return client.createRoom(_room, {
105
108
  debug,
@@ -123,10 +126,7 @@ var createRoomBundle = (client, options = {}) => {
123
126
  client.leave(room);
124
127
  };
125
128
  }, [room]);
126
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PluvRoomContext.Provider, {
127
- value: room,
128
- children
129
- });
129
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PluvRoomContext.Provider, { value: mockedRoom != null ? mockedRoom : room, children });
130
130
  });
131
131
  PluvRoomProvider.displayName = "PluvRoomProvider";
132
132
  const usePluvRoom = () => (0, import_react3.useContext)(PluvRoomContext);
@@ -299,8 +299,10 @@ var createRoomBundle = (client, options = {}) => {
299
299
  return [data, sharedType];
300
300
  };
301
301
  return {
302
+ // components
302
303
  MockedRoomProvider,
303
304
  PluvRoomProvider,
305
+ // hooks
304
306
  usePluvBroadcast,
305
307
  usePluvConnection,
306
308
  usePluvEvent,
@@ -319,10 +321,7 @@ var createBundle = (client) => {
319
321
  const PluvContext = (0, import_react4.createContext)(null);
320
322
  const PluvProvider = (0, import_react5.memo)((props) => {
321
323
  const { children } = props;
322
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PluvContext.Provider, {
323
- value: client,
324
- children
325
- });
324
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PluvContext.Provider, { value: client, children });
326
325
  });
327
326
  PluvProvider.displayName = "PluvProvider";
328
327
  const usePluvClient = () => (0, import_react5.useContext)(PluvContext);
package/dist/index.mjs CHANGED
@@ -21,7 +21,7 @@ var useRerender = () => {
21
21
  };
22
22
 
23
23
  // src/internal/hooks/useSyncExternalStoreWithSelector.ts
24
- import { useSyncExternalStoreWithSelector } from "use-sync-external-store/with-selector";
24
+ import { useSyncExternalStoreWithSelector } from "use-sync-external-store/with-selector.js";
25
25
 
26
26
  // src/internal/utils/identity.ts
27
27
  var identity = (x) => x;
@@ -35,6 +35,7 @@ var shallowArrayEqual = (a, b) => {
35
35
  import { jsx } from "react/jsx-runtime";
36
36
  var createRoomBundle = (client, options = {}) => {
37
37
  const PluvRoomContext = createContext(null);
38
+ const MockedRoomContext = createContext({ room: null });
38
39
  const MockedRoomProvider = memo((props) => {
39
40
  const {
40
41
  children,
@@ -47,14 +48,11 @@ var createRoomBundle = (client, options = {}) => {
47
48
  return new MockedRoom(_room, {
48
49
  events,
49
50
  initialPresence,
50
- initialStorage,
51
+ initialStorage: typeof initialStorage === "function" ? initialStorage : options.initialStorage,
51
52
  presence: options.presence
52
53
  });
53
54
  });
54
- return /* @__PURE__ */ jsx(PluvRoomContext.Provider, {
55
- value: room,
56
- children
57
- });
55
+ return /* @__PURE__ */ jsx(MockedRoomContext.Provider, { value: { room }, children: /* @__PURE__ */ jsx(PluvRoomContext.Provider, { value: room, children }) });
58
56
  });
59
57
  MockedRoomProvider.displayName = "MockedRoomProvider";
60
58
  const PluvRoomProvider = memo((props) => {
@@ -67,6 +65,7 @@ var createRoomBundle = (client, options = {}) => {
67
65
  room: _room
68
66
  } = props;
69
67
  const rerender = useRerender();
68
+ const { room: mockedRoom } = useContext(MockedRoomContext);
70
69
  const [room] = useState2(() => {
71
70
  return client.createRoom(_room, {
72
71
  debug,
@@ -90,10 +89,7 @@ var createRoomBundle = (client, options = {}) => {
90
89
  client.leave(room);
91
90
  };
92
91
  }, [room]);
93
- return /* @__PURE__ */ jsx(PluvRoomContext.Provider, {
94
- value: room,
95
- children
96
- });
92
+ return /* @__PURE__ */ jsx(PluvRoomContext.Provider, { value: mockedRoom != null ? mockedRoom : room, children });
97
93
  });
98
94
  PluvRoomProvider.displayName = "PluvRoomProvider";
99
95
  const usePluvRoom = () => useContext(PluvRoomContext);
@@ -266,8 +262,10 @@ var createRoomBundle = (client, options = {}) => {
266
262
  return [data, sharedType];
267
263
  };
268
264
  return {
265
+ // components
269
266
  MockedRoomProvider,
270
267
  PluvRoomProvider,
268
+ // hooks
271
269
  usePluvBroadcast,
272
270
  usePluvConnection,
273
271
  usePluvEvent,
@@ -286,10 +284,7 @@ var createBundle = (client) => {
286
284
  const PluvContext = createContext2(null);
287
285
  const PluvProvider = memo2((props) => {
288
286
  const { children } = props;
289
- return /* @__PURE__ */ jsx2(PluvContext.Provider, {
290
- value: client,
291
- children
292
- });
287
+ return /* @__PURE__ */ jsx2(PluvContext.Provider, { value: client, children });
293
288
  });
294
289
  PluvProvider.displayName = "PluvProvider";
295
290
  const usePluvClient = () => useContext2(PluvContext);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/react",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "@pluv/client React.js bindings",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -20,21 +20,21 @@
20
20
  "@types/use-sync-external-store": "^0.0.3",
21
21
  "fast-deep-equal": "^3.1.3",
22
22
  "use-sync-external-store": "^1.2.0",
23
- "@pluv/client": "^0.3.0",
24
- "@pluv/types": "^0.1.2"
23
+ "@pluv/client": "^0.5.0",
24
+ "@pluv/types": "^0.1.3"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "react": "^17.0.0 || ^18.0.0",
28
28
  "yjs": "^13.0.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@types/react": "18.0.27",
31
+ "@types/react": "18.0.28",
32
32
  "react": "18.2.0",
33
- "tsup": "^6.5.0",
34
- "typescript": "^4.9.4",
35
- "yjs": "^13.5.44",
36
- "@pluv/tsconfig": "^0.1.2",
37
- "eslint-config-pluv": "^0.1.3"
33
+ "tsup": "^6.6.3",
34
+ "typescript": "^4.9.5",
35
+ "yjs": "^13.5.49",
36
+ "@pluv/tsconfig": "^0.1.3",
37
+ "eslint-config-pluv": "^0.1.4"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "tsup src/index.ts --format esm,cjs --dts --external react",
@@ -145,6 +145,10 @@ export const createRoomBundle = <
145
145
  AbstractRoom<TIO, TPresence, TStorage>
146
146
  >(null as any);
147
147
 
148
+ const MockedRoomContext = createContext<{
149
+ room: AbstractRoom<TIO, TPresence, TStorage> | null;
150
+ }>({ room: null });
151
+
148
152
  const MockedRoomProvider = memo<
149
153
  MockedRoomProviderProps<TIO, TPresence, TStorage>
150
154
  >((props) => {
@@ -160,15 +164,20 @@ export const createRoomBundle = <
160
164
  return new MockedRoom<TIO, TPresence, TStorage>(_room, {
161
165
  events,
162
166
  initialPresence,
163
- initialStorage,
167
+ initialStorage:
168
+ typeof initialStorage === "function"
169
+ ? initialStorage
170
+ : options.initialStorage,
164
171
  presence: options.presence,
165
172
  });
166
173
  });
167
174
 
168
175
  return (
169
- <PluvRoomContext.Provider value={room}>
170
- {children}
171
- </PluvRoomContext.Provider>
176
+ <MockedRoomContext.Provider value={{ room }}>
177
+ <PluvRoomContext.Provider value={room}>
178
+ {children}
179
+ </PluvRoomContext.Provider>
180
+ </MockedRoomContext.Provider>
172
181
  );
173
182
  });
174
183
 
@@ -187,6 +196,7 @@ export const createRoomBundle = <
187
196
  } = props;
188
197
 
189
198
  const rerender = useRerender();
199
+ const { room: mockedRoom } = useContext(MockedRoomContext);
190
200
 
191
201
  const [room] = useState<PluvRoom<TIO, TPresence, TStorage>>(() => {
192
202
  return client.createRoom<TPresence, TStorage>(_room, {
@@ -220,7 +230,7 @@ export const createRoomBundle = <
220
230
  }, [room]);
221
231
 
222
232
  return (
223
- <PluvRoomContext.Provider value={room}>
233
+ <PluvRoomContext.Provider value={mockedRoom ?? room}>
224
234
  {children}
225
235
  </PluvRoomContext.Provider>
226
236
  );
@@ -5,10 +5,11 @@ export const useSyncExternalStore = <TSnapshot extends unknown>(
5
5
  subscribe: (onStoreChange: () => void) => () => void,
6
6
  getSnapshot: () => TSnapshot,
7
7
  getServerSnapshot: undefined | null | (() => TSnapshot)
8
- ) =>
9
- useSyncExternalStoreWithSelector(
8
+ ) => {
9
+ return useSyncExternalStoreWithSelector(
10
10
  subscribe,
11
11
  getSnapshot,
12
12
  getServerSnapshot,
13
13
  identity
14
14
  );
15
+ };
@@ -1 +1 @@
1
- export { useSyncExternalStoreWithSelector } from "use-sync-external-store/with-selector";
1
+ export { useSyncExternalStoreWithSelector } from "use-sync-external-store/with-selector.js";