use-everywhere 1.0.1 → 1.0.3

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
@@ -22,10 +22,10 @@ Two transports behind one library:
22
22
  tabs hydrate to the current value; concurrent writes converge to one winner.
23
23
 
24
24
  ```tsx
25
- import { useSharedState } from 'use-everywhere';
25
+ import { useSharedState } from "use-everywhere";
26
26
 
27
27
  function Counter() {
28
- const [count, setCount] = useSharedState('count', 0);
28
+ const [count, setCount] = useSharedState("count", 0);
29
29
  return <button onClick={() => setCount((c) => c + 1)}>{count}</button>;
30
30
  }
31
31
  ```
@@ -33,9 +33,9 @@ function Counter() {
33
33
  The third argument delimits how far a value travels:
34
34
 
35
35
  ```tsx
36
- useSharedState('draft', '', { scope: 'everywhere' }); // tabs + windows + workers (default)
37
- useSharedState('draft', '', { scope: 'tabs' }); // ignore writes from workers
38
- useSharedState('draft', '', { scope: 'tab' }); // this tab only
36
+ useSharedState("draft", "", { scope: "everywhere" }); // tabs + windows + workers (default)
37
+ useSharedState("draft", "", { scope: "tabs" }); // ignore writes from workers
38
+ useSharedState("draft", "", { scope: "tab" }); // this tab only
39
39
  ```
40
40
 
41
41
  ## Events: `defineChannel`
@@ -46,22 +46,22 @@ channel's name and message map once at module level; every component gets
46
46
  fully typed hooks with nothing to repeat:
47
47
 
48
48
  ```tsx
49
- import { defineChannel } from 'use-everywhere';
50
- import { useState } from 'react';
49
+ import { defineChannel } from "use-everywhere";
50
+ import { useState } from "react";
51
51
 
52
- type ShopEvents = { 'cart-updated': { items: number } };
53
- const shop = defineChannel<ShopEvents>('shop');
52
+ type ShopEvents = { "cart-updated": { items: number } };
53
+ const shop = defineChannel<ShopEvents>("shop");
54
54
 
55
55
  function CartBadge() {
56
56
  const [items, setItems] = useState(0);
57
57
  const send = shop.useSend();
58
58
 
59
59
  // Fires when any OTHER tab posts 'cart-updated'.
60
- shop.useOnMessage('cart-updated', (payload) => setItems(payload.items));
60
+ shop.useOnMessage("cart-updated", (payload) => setItems(payload.items));
61
61
 
62
62
  const addToCart = () => {
63
63
  setItems(items + 1); // this tab
64
- send('cart-updated', { items: items + 1 }); // every other tab
64
+ send("cart-updated", { items: items + 1 }); // every other tab
65
65
  };
66
66
 
67
67
  return <button onClick={addToCart}>Cart ({items})</button>;
@@ -75,7 +75,7 @@ module-level binding, for one-off use.
75
75
  ## Presence: `usePeers`
76
76
 
77
77
  ```tsx
78
- import { usePeers } from 'use-everywhere';
78
+ import { usePeers } from "use-everywhere";
79
79
 
80
80
  function DuplicateTabWarning() {
81
81
  const peers = usePeers();
@@ -90,7 +90,7 @@ Open a window on another domain, exchange typed messages, and await its
90
90
  result — the whole lifecycle folded into render state.
91
91
 
92
92
  ```tsx
93
- import { openWindow, useWindowResult } from 'use-everywhere';
93
+ import { openWindow, useWindowResult } from "use-everywhere";
94
94
 
95
95
  type ToPayment = { order: { orderId: string; amount: string } };
96
96
  type FromPayment = { progress: { step: string } };
@@ -98,17 +98,17 @@ type Receipt = { receiptId: string; last4: string };
98
98
 
99
99
  function PayButton() {
100
100
  const pay = useWindowResult<ToPayment, FromPayment, Receipt>(() =>
101
- openWindow('https://pay.example.com/checkout', {
102
- peerOrigin: 'https://pay.example.com', // required — '*' throws
101
+ openWindow("https://pay.example.com/checkout", {
102
+ peerOrigin: "https://pay.example.com", // required — '*' throws
103
103
  }),
104
104
  );
105
105
 
106
- if (pay.status === 'done') return <p>Paid — receipt {pay.result.receiptId}</p>;
107
- if (pay.status === 'closed-early') return <p>Payment window was closed.</p>;
106
+ if (pay.status === "done") return <p>Paid — receipt {pay.result.receiptId}</p>;
107
+ if (pay.status === "closed-early") return <p>Payment window was closed.</p>;
108
108
 
109
109
  return (
110
- <button onClick={pay.open} disabled={pay.status !== 'idle'}>
111
- {pay.status === 'idle' ? 'Pay in secure window' : 'Waiting for payment…'}
110
+ <button onClick={pay.open} disabled={pay.status !== "idle"}>
111
+ {pay.status === "idle" ? "Pay in secure window" : "Waiting for payment…"}
112
112
  </button>
113
113
  );
114
114
  }
@@ -117,13 +117,13 @@ function PayButton() {
117
117
  On the opened page (the other domain), use the core API:
118
118
 
119
119
  ```tsx
120
- import { connectToOpener } from 'use-everywhere';
120
+ import { connectToOpener } from "use-everywhere";
121
121
 
122
122
  const conn = connectToOpener<ToPayment, FromPayment, Receipt>({
123
- peerOrigin: 'https://shop.example.com',
123
+ peerOrigin: "https://shop.example.com",
124
124
  });
125
- conn.on('order', (order) => setOrder(order)); // e.g. a useState setter
126
- conn.finish({ receiptId: 'r-123', last4: '4242' }); // resolves the opener's pay.result
125
+ conn.on("order", (order) => setOrder(order)); // e.g. a useState setter
126
+ conn.finish({ receiptId: "r-123", last4: "4242" }); // resolves the opener's pay.result
127
127
  ```
128
128
 
129
129
  Messages sent before the (possibly slow-loading) child connects are queued,
@@ -142,13 +142,13 @@ per-connection nonce, and source window.
142
142
  - Values must survive structured clone (no functions, DOM nodes); state lives
143
143
  as long as at least one context holds it — nothing is persisted.
144
144
  - Testing is first-class: inject a `MemoryHub` transport to simulate many tabs
145
- in one test. See the [testing guide](https://rxova.org/packages/use-everywhere/guides/testing).
145
+ in one test. See the [testing guide](https://rxova.dev/packages/use-everywhere/guides/testing).
146
146
 
147
147
  This package re-exports the full framework-agnostic surface of
148
148
  [`@use-everywhere/core`](https://www.npmjs.com/package/@use-everywhere/core),
149
149
  so you never need to install core directly.
150
150
 
151
- 📖 **[Documentation](https://rxova.org/packages/use-everywhere/)** — mental
151
+ 📖 **[Documentation](https://rxova.dev/packages/use-everywhere/)** — mental
152
152
  model, how sync works, security model, recipes, and generated API reference.
153
153
  Source and demo app: [github.com/rxova/use-everywhere](https://github.com/rxova/use-everywhere)
154
154
 
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const require_use_peers = require("../use-peers-RhIB77TV.cjs");
3
+ const require_use_peers = require("../use-peers-vGlb1_qA.cjs");
4
4
  let react = require("react");
5
5
  let _use_everywhere_core = require("@use-everywhere/core");
6
6
  let react_dom = require("react-dom");
@@ -4,7 +4,7 @@ interface InspectorProps {
4
4
  /** Which bus to watch. Defaults to the shared default name. */
5
5
  name?: string;
6
6
  /** Corner to dock in. Default 'bottom-right'. */
7
- position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
7
+ position?: "bottom-right" | "bottom-left" | "top-right" | "top-left";
8
8
  /** How many wires to keep in the log. Default 50. */
9
9
  limit?: number;
10
10
  /** Start expanded. Default false. */
@@ -4,7 +4,7 @@ interface InspectorProps {
4
4
  /** Which bus to watch. Defaults to the shared default name. */
5
5
  name?: string;
6
6
  /** Corner to dock in. Default 'bottom-right'. */
7
- position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
7
+ position?: "bottom-right" | "bottom-left" | "top-right" | "top-left";
8
8
  /** How many wires to keep in the log. Default 50. */
9
9
  limit?: number;
10
10
  /** Start expanded. Default false. */
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import { n as usePeers, u as getSharedStore } from "../use-peers-DtpHGzXE.js";
2
+ import { n as usePeers, u as getSharedStore } from "../use-peers-CU0f6F6U.js";
3
3
  import { useCallback, useEffect, useRef, useState, useSyncExternalStore } from "react";
4
4
  import { DEFAULT_NAME, observeBus } from "@use-everywhere/core";
5
5
  import { createPortal } from "react-dom";
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const require_use_peers = require("./use-peers-RhIB77TV.cjs");
3
+ const require_use_peers = require("./use-peers-vGlb1_qA.cjs");
4
4
  let react = require("react");
5
5
  let _use_everywhere_core = require("@use-everywhere/core");
6
6
  //#region src/use-shared-state.ts
package/dist/index.d.cts CHANGED
@@ -7,7 +7,7 @@ import { AskOptions, BroadcastChannelTransport, BusEvent, BusObserver, BusWire,
7
7
  * - 'tabs' — tabs and windows only; writes coming from workers are ignored
8
8
  * - 'tab' — this tab only (state is still shared between components)
9
9
  */
10
- type ShareScope = 'everywhere' | 'tabs' | 'tab';
10
+ type ShareScope = "everywhere" | "tabs" | "tab";
11
11
  interface UseSharedStateOptions {
12
12
  /** Store name; keys live in a namespace per store. Default 'use-everywhere'. */
13
13
  store?: string;
@@ -167,9 +167,9 @@ export declare function useAnswer<M extends MessageMap$1, R extends ReplyMap$1<M
167
167
  enabled?: boolean;
168
168
  }): void;
169
169
  /** The channel's post function (stable identity per channel). */
170
- export declare function useSend<M extends MessageMap$1, R extends ReplyMap$1<M>>(channel: Channel$1<M, R>): Channel$1<M, R>['post'];
170
+ export declare function useSend<M extends MessageMap$1, R extends ReplyMap$1<M>>(channel: Channel$1<M, R>): Channel$1<M, R>["post"];
171
171
  /** The channel's ask function (stable identity per channel). */
172
- export declare function useAsk<M extends MessageMap$1, R extends ReplyMap$1<M>>(channel: Channel$1<M, R>): Channel$1<M, R>['ask'];
172
+ export declare function useAsk<M extends MessageMap$1, R extends ReplyMap$1<M>>(channel: Channel$1<M, R>): Channel$1<M, R>["ask"];
173
173
  //#endregion
174
174
  //#region src/define-channel.types.d.ts
175
175
  /** A channel bound to a name and message map: typed hooks with no per-call generics. */
@@ -177,7 +177,7 @@ interface ChannelHooks<M extends MessageMap$1> {
177
177
  /** The underlying channel instance (the same one the hooks use) — for non-React code. */
178
178
  get: () => Channel$1<M>;
179
179
  /** The channel's post function (stable identity). */
180
- useSend: () => Channel$1<M>['post'];
180
+ useSend: () => Channel$1<M>["post"];
181
181
  /**
182
182
  * Subscribe to one message type. Same contract as the standalone
183
183
  * `useOnMessage`: the handler is kept fresh without resubscribing.
@@ -354,7 +354,7 @@ export declare function useLeaderEffect(effect: () => void | (() => void), optio
354
354
  interface ReactNamespace extends Namespace$1 {
355
355
  createStoreHooks<S extends Record<string, unknown> = Record<string, unknown>>(name: string, options?: CreateStoreHooksOptions): StoreHooks<S>;
356
356
  defineChannel<M extends MessageMap$1>(name?: string, options?: ChannelOptions$1<M>): ChannelHooks<M>;
357
- getSharedStore(name?: string, scope?: UseSharedStateOptions['scope']): AnyStore;
357
+ getSharedStore(name?: string, scope?: UseSharedStateOptions["scope"]): AnyStore;
358
358
  useSharedState<T>(key: string, initial: T, options?: UseSharedStateOptions): [T, (next: T | ((prev: T) => T)) => void];
359
359
  useSharedSelector<S extends Record<string, unknown>, T>(selector: (state: S) => T, options?: UseSharedSelectorOptions): T;
360
360
  usePeers(options?: UsePeersOptions): readonly Peer$1[];
@@ -391,7 +391,7 @@ interface ReactNamespace extends Namespace$1 {
391
391
  export declare function createNamespace(namespace: string): ReactNamespace;
392
392
  //#endregion
393
393
  //#region src/use-window-result.types.d.ts
394
- type OpenedWindowStatus = 'idle' | 'opening' | 'connected' | 'done' | 'closed-early' | 'error';
394
+ type OpenedWindowStatus = "idle" | "opening" | "connected" | "done" | "closed-early" | "error";
395
395
  /**
396
396
  * The flow's state as a discriminated union, so `status` narrows `result` and
397
397
  * `error` for you. Three independent fields could not: `result` was `R |
@@ -399,31 +399,31 @@ type OpenedWindowStatus = 'idle' | 'opening' | 'connected' | 'done' | 'closed-ea
399
399
  * non-null assertion at every call site.
400
400
  */
401
401
  type OpenedWindowState<R> = {
402
- status: 'idle';
402
+ status: "idle";
403
403
  result: undefined;
404
404
  error: undefined;
405
405
  } | {
406
- status: 'opening';
406
+ status: "opening";
407
407
  result: undefined;
408
408
  error: undefined;
409
409
  } | {
410
- status: 'connected';
410
+ status: "connected";
411
411
  result: undefined;
412
412
  error: undefined;
413
413
  } | {
414
- status: 'done';
414
+ status: "done";
415
415
  result: R;
416
416
  error: undefined;
417
417
  } |
418
418
  /** The child window went away before calling finish(). */
419
419
  {
420
- status: 'closed-early';
420
+ status: "closed-early";
421
421
  result: undefined;
422
422
  error: WindowClosedError$1;
423
423
  } |
424
424
  /** The handshake timed out, the popup was blocked, or the factory threw. */
425
425
  {
426
- status: 'error';
426
+ status: "error";
427
427
  result: undefined;
428
428
  error: unknown;
429
429
  };
@@ -431,7 +431,7 @@ interface OpenedWindowControls<Out extends MessageMap$1, In extends MessageMap$1
431
431
  /** Call from a click handler (popup blockers require a user gesture). */
432
432
  open: () => void;
433
433
  /** Post to the child; no-op while nothing is open. */
434
- post: OpenedWindow$1<Out, In, R>['post'];
434
+ post: OpenedWindow$1<Out, In, R>["post"];
435
435
  close: () => void;
436
436
  }
437
437
  type UseWindowResult<Out extends MessageMap$1, In extends MessageMap$1, R> = OpenedWindowState<R> & OpenedWindowControls<Out, In, R>;
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ import { AskOptions, BroadcastChannelTransport, BusEvent, BusObserver, BusWire,
7
7
  * - 'tabs' — tabs and windows only; writes coming from workers are ignored
8
8
  * - 'tab' — this tab only (state is still shared between components)
9
9
  */
10
- type ShareScope = 'everywhere' | 'tabs' | 'tab';
10
+ type ShareScope = "everywhere" | "tabs" | "tab";
11
11
  interface UseSharedStateOptions {
12
12
  /** Store name; keys live in a namespace per store. Default 'use-everywhere'. */
13
13
  store?: string;
@@ -167,9 +167,9 @@ export declare function useAnswer<M extends MessageMap$1, R extends ReplyMap$1<M
167
167
  enabled?: boolean;
168
168
  }): void;
169
169
  /** The channel's post function (stable identity per channel). */
170
- export declare function useSend<M extends MessageMap$1, R extends ReplyMap$1<M>>(channel: Channel$1<M, R>): Channel$1<M, R>['post'];
170
+ export declare function useSend<M extends MessageMap$1, R extends ReplyMap$1<M>>(channel: Channel$1<M, R>): Channel$1<M, R>["post"];
171
171
  /** The channel's ask function (stable identity per channel). */
172
- export declare function useAsk<M extends MessageMap$1, R extends ReplyMap$1<M>>(channel: Channel$1<M, R>): Channel$1<M, R>['ask'];
172
+ export declare function useAsk<M extends MessageMap$1, R extends ReplyMap$1<M>>(channel: Channel$1<M, R>): Channel$1<M, R>["ask"];
173
173
  //#endregion
174
174
  //#region src/define-channel.types.d.ts
175
175
  /** A channel bound to a name and message map: typed hooks with no per-call generics. */
@@ -177,7 +177,7 @@ interface ChannelHooks<M extends MessageMap$1> {
177
177
  /** The underlying channel instance (the same one the hooks use) — for non-React code. */
178
178
  get: () => Channel$1<M>;
179
179
  /** The channel's post function (stable identity). */
180
- useSend: () => Channel$1<M>['post'];
180
+ useSend: () => Channel$1<M>["post"];
181
181
  /**
182
182
  * Subscribe to one message type. Same contract as the standalone
183
183
  * `useOnMessage`: the handler is kept fresh without resubscribing.
@@ -354,7 +354,7 @@ export declare function useLeaderEffect(effect: () => void | (() => void), optio
354
354
  interface ReactNamespace extends Namespace$1 {
355
355
  createStoreHooks<S extends Record<string, unknown> = Record<string, unknown>>(name: string, options?: CreateStoreHooksOptions): StoreHooks<S>;
356
356
  defineChannel<M extends MessageMap$1>(name?: string, options?: ChannelOptions$1<M>): ChannelHooks<M>;
357
- getSharedStore(name?: string, scope?: UseSharedStateOptions['scope']): AnyStore;
357
+ getSharedStore(name?: string, scope?: UseSharedStateOptions["scope"]): AnyStore;
358
358
  useSharedState<T>(key: string, initial: T, options?: UseSharedStateOptions): [T, (next: T | ((prev: T) => T)) => void];
359
359
  useSharedSelector<S extends Record<string, unknown>, T>(selector: (state: S) => T, options?: UseSharedSelectorOptions): T;
360
360
  usePeers(options?: UsePeersOptions): readonly Peer$1[];
@@ -391,7 +391,7 @@ interface ReactNamespace extends Namespace$1 {
391
391
  export declare function createNamespace(namespace: string): ReactNamespace;
392
392
  //#endregion
393
393
  //#region src/use-window-result.types.d.ts
394
- type OpenedWindowStatus = 'idle' | 'opening' | 'connected' | 'done' | 'closed-early' | 'error';
394
+ type OpenedWindowStatus = "idle" | "opening" | "connected" | "done" | "closed-early" | "error";
395
395
  /**
396
396
  * The flow's state as a discriminated union, so `status` narrows `result` and
397
397
  * `error` for you. Three independent fields could not: `result` was `R |
@@ -399,31 +399,31 @@ type OpenedWindowStatus = 'idle' | 'opening' | 'connected' | 'done' | 'closed-ea
399
399
  * non-null assertion at every call site.
400
400
  */
401
401
  type OpenedWindowState<R> = {
402
- status: 'idle';
402
+ status: "idle";
403
403
  result: undefined;
404
404
  error: undefined;
405
405
  } | {
406
- status: 'opening';
406
+ status: "opening";
407
407
  result: undefined;
408
408
  error: undefined;
409
409
  } | {
410
- status: 'connected';
410
+ status: "connected";
411
411
  result: undefined;
412
412
  error: undefined;
413
413
  } | {
414
- status: 'done';
414
+ status: "done";
415
415
  result: R;
416
416
  error: undefined;
417
417
  } |
418
418
  /** The child window went away before calling finish(). */
419
419
  {
420
- status: 'closed-early';
420
+ status: "closed-early";
421
421
  result: undefined;
422
422
  error: WindowClosedError$1;
423
423
  } |
424
424
  /** The handshake timed out, the popup was blocked, or the factory threw. */
425
425
  {
426
- status: 'error';
426
+ status: "error";
427
427
  result: undefined;
428
428
  error: unknown;
429
429
  };
@@ -431,7 +431,7 @@ interface OpenedWindowControls<Out extends MessageMap$1, In extends MessageMap$1
431
431
  /** Call from a click handler (popup blockers require a user gesture). */
432
432
  open: () => void;
433
433
  /** Post to the child; no-op while nothing is open. */
434
- post: OpenedWindow$1<Out, In, R>['post'];
434
+ post: OpenedWindow$1<Out, In, R>["post"];
435
435
  close: () => void;
436
436
  }
437
437
  type UseWindowResult<Out extends MessageMap$1, In extends MessageMap$1, R> = OpenedWindowState<R> & OpenedWindowControls<Out, In, R>;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import { a as configureChannel, c as getLeader, d as getStore, f as warnOnInitialMismatch, i as DEFAULT_NAME, l as getReducer, n as usePeers, o as configureStore, r as usePresenceMetadata, s as getChannel, t as useClientId, u as getSharedStore } from "./use-peers-DtpHGzXE.js";
2
+ import { a as configureChannel, c as getLeader, d as getStore, f as warnOnInitialMismatch, i as DEFAULT_NAME, l as getReducer, n as usePeers, o as configureStore, r as usePresenceMetadata, s as getChannel, t as useClientId, u as getSharedStore } from "./use-peers-CU0f6F6U.js";
3
3
  import { useCallback, useEffect, useRef, useState, useSyncExternalStore } from "react";
4
4
  import { BroadcastChannelTransport, CID_PARAM, HandshakeTimeoutError, NoopTransport, SharedWorkerTransport, StorageTransport, WIRE_VERSION, WindowClosedError, WindowClosedError as WindowClosedError$1, connectToOpener, createChannel, createLeader, createNamespace as createNamespace$1, createPresence, createSharedReducer, createSharedStore, defaultTransport, enableDebug, getBusNames, getTransportKind, getWireSkew, indexedDbAdapter, isBroadcastChannelAvailable, isSharedWorkerAvailable, isStorageEventAvailable, jsonSerializer, localStorageAdapter, newer, observeBus, openWindow, sessionStorageAdapter, webStorageAdapter } from "@use-everywhere/core";
5
5
  //#region src/use-shared-state.ts
@@ -1,31 +1,74 @@
1
1
  'use client';
2
2
  import { useCallback, useEffect, useSyncExternalStore } from "react";
3
3
  import { DEFAULT_NAME as DEFAULT_NAME$1, NoopTransport, createChannel, createLeader, createPresence, createSharedReducer, createSharedStore } from "@use-everywhere/core";
4
- //#region src/dev.ts
5
- let inDev = false;
6
- try {
7
- inDev = process.env.NODE_ENV !== "production";
8
- } catch {}
9
- const warned = /* @__PURE__ */ new Set();
10
- const DOCS = "https://rxova.org/packages/use-everywhere/errors";
4
+ //#region ../../node_modules/.pnpm/@rxova+ts-utils@0.2.1_react@19.2.8/node_modules/@rxova/ts-utils/dist/match-media-list-C1t1r7On.js
11
5
  /**
12
- * Stamp a diagnostic with its code and the page that explains it. Core's twin
13
- * of this, for the same reason the twin of `devWarn` exists — see above.
6
+ * Whether developer-facing diagnostics should run.
7
+ *
8
+ * A boolean `__DEV__` global wins outright. Otherwise anything but
9
+ * `NODE_ENV=production` is development, React's rule: an unset `NODE_ENV` is
10
+ * someone's machine, and a stray warning there costs less than a swallowed one.
14
11
  *
15
- * Codes are permanent, and a retired one is never reused: an old build in
16
- * somebody's browser is still emitting it. Core owns UE1xxx, this package
17
- * UE2xxx.
12
+ * `process.env.NODE_ENV` is spelled out literally, and inside a try rather than
13
+ * behind `typeof process`: browser bundlers replace that exact expression with a
14
+ * string but provide no `process` global, so a `typeof process` guard reads
15
+ * false in precisely the browser development builds the check exists for. Run
16
+ * unbundled in a browser, the read throws and the answer is "no" — nobody is
17
+ * watching a console there that the warning was written for.
18
18
  */
19
- function diagnostic(code, message) {
20
- return `[use-everywhere] ${code}: ${message}\n → ${DOCS}/#${code.toLowerCase()}`;
21
- }
19
+ const isDevelopment = () => {
20
+ const flag = globalThis.__DEV__;
21
+ if (typeof flag === "boolean") return flag;
22
+ try {
23
+ return process.env.NODE_ENV !== "production";
24
+ } catch {
25
+ return false;
26
+ }
27
+ };
28
+ /**
29
+ * One package's development warnings: a prefix, an optional stable code with a
30
+ * link to the page that explains it, and a warn-once that dedupes by key.
31
+ *
32
+ * Production builds only drop the message strings when the call site itself
33
+ * sits under a check the bundler can fold, so wrap hot or verbose calls in
34
+ * `if (process.env.NODE_ENV !== 'production')` where the bytes matter.
35
+ */
36
+ const createDevWarner = ({ prefix, docsUrl, enabled = isDevelopment, sink = (...args) => {
37
+ console.warn(...args);
38
+ } }) => {
39
+ const seen = /* @__PURE__ */ new Set();
40
+ const format = (message, code) => {
41
+ if (code === void 0) return `[${prefix}] ${message}`;
42
+ return `[${prefix}] ${code}: ${message}${docsUrl === void 0 ? "" : `\n → ${docsUrl}#${code.toLowerCase()}`}`;
43
+ };
44
+ const warn = (message, { code, detail } = {}) => {
45
+ if (!enabled()) return;
46
+ const line = format(message, code);
47
+ if (detail === void 0) sink(line);
48
+ else sink("%s", line, detail);
49
+ };
50
+ return {
51
+ format,
52
+ warn,
53
+ warnOnce: (key, message, options) => {
54
+ if (!enabled() || seen.has(key)) return;
55
+ seen.add(key);
56
+ warn(message, options);
57
+ },
58
+ reset: () => {
59
+ seen.clear();
60
+ }
61
+ };
62
+ };
63
+ //#endregion
64
+ //#region src/dev.ts
65
+ const warner = createDevWarner({
66
+ prefix: "use-everywhere",
67
+ docsUrl: "https://rxova.dev/packages/use-everywhere/errors/"
68
+ });
22
69
  /** Warn once per distinct message, development only. */
23
70
  function devWarn(code, message) {
24
- if (!inDev) return;
25
- const line = diagnostic(code, message);
26
- if (warned.has(line)) return;
27
- warned.add(line);
28
- console.warn(line);
71
+ warner.warnOnce(`${code} ${message}`, message, { code });
29
72
  }
30
73
  /** The initial each key was first registered with. Populated only in development — dynamic keys would otherwise grow it without bound. */
31
74
  const seenInitials = /* @__PURE__ */ new Map();
@@ -35,7 +78,7 @@ const seenInitials = /* @__PURE__ */ new Map();
35
78
  * disagreement that surfaces much later as "why is this value not what I set".
36
79
  */
37
80
  function warnOnInitialMismatch(storeName, key, initial) {
38
- if (!inDev) return;
81
+ if (!isDevelopment()) return;
39
82
  const id = `${storeName} ${key}`;
40
83
  if (!seenInitials.has(id)) {
41
84
  seenInitials.set(id, initial);
@@ -1,31 +1,74 @@
1
1
  'use client';
2
2
  let react = require("react");
3
3
  let _use_everywhere_core = require("@use-everywhere/core");
4
- //#region src/dev.ts
5
- let inDev = false;
6
- try {
7
- inDev = process.env.NODE_ENV !== "production";
8
- } catch {}
9
- const warned = /* @__PURE__ */ new Set();
10
- const DOCS = "https://rxova.org/packages/use-everywhere/errors";
4
+ //#region ../../node_modules/.pnpm/@rxova+ts-utils@0.2.1_react@19.2.8/node_modules/@rxova/ts-utils/dist/match-media-list-C1t1r7On.js
11
5
  /**
12
- * Stamp a diagnostic with its code and the page that explains it. Core's twin
13
- * of this, for the same reason the twin of `devWarn` exists — see above.
6
+ * Whether developer-facing diagnostics should run.
7
+ *
8
+ * A boolean `__DEV__` global wins outright. Otherwise anything but
9
+ * `NODE_ENV=production` is development, React's rule: an unset `NODE_ENV` is
10
+ * someone's machine, and a stray warning there costs less than a swallowed one.
14
11
  *
15
- * Codes are permanent, and a retired one is never reused: an old build in
16
- * somebody's browser is still emitting it. Core owns UE1xxx, this package
17
- * UE2xxx.
12
+ * `process.env.NODE_ENV` is spelled out literally, and inside a try rather than
13
+ * behind `typeof process`: browser bundlers replace that exact expression with a
14
+ * string but provide no `process` global, so a `typeof process` guard reads
15
+ * false in precisely the browser development builds the check exists for. Run
16
+ * unbundled in a browser, the read throws and the answer is "no" — nobody is
17
+ * watching a console there that the warning was written for.
18
18
  */
19
- function diagnostic(code, message) {
20
- return `[use-everywhere] ${code}: ${message}\n → ${DOCS}/#${code.toLowerCase()}`;
21
- }
19
+ const isDevelopment = () => {
20
+ const flag = globalThis.__DEV__;
21
+ if (typeof flag === "boolean") return flag;
22
+ try {
23
+ return process.env.NODE_ENV !== "production";
24
+ } catch {
25
+ return false;
26
+ }
27
+ };
28
+ /**
29
+ * One package's development warnings: a prefix, an optional stable code with a
30
+ * link to the page that explains it, and a warn-once that dedupes by key.
31
+ *
32
+ * Production builds only drop the message strings when the call site itself
33
+ * sits under a check the bundler can fold, so wrap hot or verbose calls in
34
+ * `if (process.env.NODE_ENV !== 'production')` where the bytes matter.
35
+ */
36
+ const createDevWarner = ({ prefix, docsUrl, enabled = isDevelopment, sink = (...args) => {
37
+ console.warn(...args);
38
+ } }) => {
39
+ const seen = /* @__PURE__ */ new Set();
40
+ const format = (message, code) => {
41
+ if (code === void 0) return `[${prefix}] ${message}`;
42
+ return `[${prefix}] ${code}: ${message}${docsUrl === void 0 ? "" : `\n → ${docsUrl}#${code.toLowerCase()}`}`;
43
+ };
44
+ const warn = (message, { code, detail } = {}) => {
45
+ if (!enabled()) return;
46
+ const line = format(message, code);
47
+ if (detail === void 0) sink(line);
48
+ else sink("%s", line, detail);
49
+ };
50
+ return {
51
+ format,
52
+ warn,
53
+ warnOnce: (key, message, options) => {
54
+ if (!enabled() || seen.has(key)) return;
55
+ seen.add(key);
56
+ warn(message, options);
57
+ },
58
+ reset: () => {
59
+ seen.clear();
60
+ }
61
+ };
62
+ };
63
+ //#endregion
64
+ //#region src/dev.ts
65
+ const warner = createDevWarner({
66
+ prefix: "use-everywhere",
67
+ docsUrl: "https://rxova.dev/packages/use-everywhere/errors/"
68
+ });
22
69
  /** Warn once per distinct message, development only. */
23
70
  function devWarn(code, message) {
24
- if (!inDev) return;
25
- const line = diagnostic(code, message);
26
- if (warned.has(line)) return;
27
- warned.add(line);
28
- console.warn(line);
71
+ warner.warnOnce(`${code} ${message}`, message, { code });
29
72
  }
30
73
  /** The initial each key was first registered with. Populated only in development — dynamic keys would otherwise grow it without bound. */
31
74
  const seenInitials = /* @__PURE__ */ new Map();
@@ -35,7 +78,7 @@ const seenInitials = /* @__PURE__ */ new Map();
35
78
  * disagreement that surfaces much later as "why is this value not what I set".
36
79
  */
37
80
  function warnOnInitialMismatch(storeName, key, initial) {
38
- if (!inDev) return;
81
+ if (!isDevelopment()) return;
39
82
  const id = `${storeName} ${key}`;
40
83
  if (!seenInitials.has(id)) {
41
84
  seenInitials.set(id, initial);
package/llms.txt CHANGED
@@ -105,9 +105,9 @@ in `@use-everywhere/core` is re-exported from here too — see that package's
105
105
 
106
106
  ## Docs
107
107
 
108
- - Full documentation: https://rxova.org/packages/use-everywhere/
109
- - Agent-facing index: https://rxova.org/packages/use-everywhere/llms.txt
108
+ - Full documentation: https://rxova.dev/packages/use-everywhere/
109
+ - Agent-facing index: https://rxova.dev/packages/use-everywhere/llms.txt
110
110
  - Every page as raw markdown: add `.md` to any docs URL
111
- - Hooks reference: https://rxova.org/packages/use-everywhere/hooks/overview.md
112
- - Error codes: https://rxova.org/packages/use-everywhere/errors.md
111
+ - Hooks reference: https://rxova.dev/packages/use-everywhere/hooks/overview.md
112
+ - Error codes: https://rxova.dev/packages/use-everywhere/errors.md
113
113
  - Source: https://github.com/rxova/use-everywhere
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "use-everywhere",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "React hooks for state and messages shared across tabs, windows, and workers",
5
5
  "license": "MIT",
6
6
  "author": "Jonatan Kruszewski <jonakrusze@gmail.com>",
@@ -9,7 +9,7 @@
9
9
  "url": "git+https://github.com/rxova/use-everywhere.git",
10
10
  "directory": "packages/react"
11
11
  },
12
- "homepage": "https://rxova.org/packages/use-everywhere/",
12
+ "homepage": "https://rxova.dev/packages/use-everywhere/",
13
13
  "bugs": "https://github.com/rxova/use-everywhere/issues",
14
14
  "keywords": [
15
15
  "react",
@@ -106,55 +106,55 @@
106
106
  "name": "useSharedState",
107
107
  "path": "dist/index.js",
108
108
  "import": "{ useSharedState }",
109
- "limit": "4.24 kB"
109
+ "limit": "4.50 kB"
110
110
  },
111
111
  {
112
112
  "name": "useSharedSelector",
113
113
  "path": "dist/index.js",
114
114
  "import": "{ useSharedSelector, shallowEqual }",
115
- "limit": "4.40 kB"
115
+ "limit": "4.67 kB"
116
116
  },
117
117
  {
118
118
  "name": "useSharedReducer",
119
119
  "path": "dist/index.js",
120
120
  "import": "{ useSharedReducer }",
121
- "limit": "4.21 kB"
121
+ "limit": "4.49 kB"
122
122
  },
123
123
  {
124
124
  "name": "useChannel + useOnMessage + useSend",
125
125
  "path": "dist/index.js",
126
126
  "import": "{ useChannel, useOnMessage, useSend }",
127
- "limit": "3.07 kB"
127
+ "limit": "3.34 kB"
128
128
  },
129
129
  {
130
130
  "name": "usePeers + useClientId",
131
131
  "path": "dist/index.js",
132
132
  "import": "{ usePeers, useClientId }",
133
- "limit": "2.77 kB"
133
+ "limit": "3.05 kB"
134
134
  },
135
135
  {
136
136
  "name": "useWindowResult + openWindow",
137
137
  "path": "dist/index.js",
138
138
  "import": "{ useWindowResult, openWindow }",
139
- "limit": "1.47 kB"
139
+ "limit": "1.74 kB"
140
140
  },
141
141
  {
142
142
  "name": "useLeader + useLeaderEffect",
143
143
  "path": "dist/index.js",
144
144
  "import": "{ useLeader, useLeaderEffect }",
145
- "limit": "3.65 kB"
145
+ "limit": "3.90 kB"
146
146
  },
147
147
  {
148
148
  "name": "createStoreHooks (persisted)",
149
149
  "path": "dist/index.js",
150
150
  "import": "{ createStoreHooks, localStorageAdapter }",
151
- "limit": "4.67 kB"
151
+ "limit": "4.68 kB"
152
152
  },
153
153
  {
154
154
  "name": "Inspector (devtools subpath)",
155
155
  "path": "dist/devtools/index.js",
156
156
  "import": "{ Inspector }",
157
- "limit": "7.20 kB"
157
+ "limit": "7.63 kB"
158
158
  },
159
159
  {
160
160
  "name": "SharedWorker relay (shared-worker subpath)",
@@ -170,7 +170,7 @@
170
170
  }
171
171
  ],
172
172
  "dependencies": {
173
- "@use-everywhere/core": "1.0.1"
173
+ "@use-everywhere/core": "1.0.3"
174
174
  },
175
175
  "peerDependencies": {
176
176
  "react": ">=18",
@@ -195,8 +195,7 @@
195
195
  "size-limit": "^13.0.3",
196
196
  "tsdown": "^0.23.0",
197
197
  "typescript": "^6.0.3",
198
- "vitest": "^4.1.11",
199
- "@repo/config": "0.0.0"
198
+ "vitest": "^4.1.11"
200
199
  },
201
200
  "typesVersions": {
202
201
  "*": {
@@ -217,6 +216,6 @@
217
216
  "typecheck": "tsc --noEmit",
218
217
  "size": "size-limit",
219
218
  "check:exports": "publint --strict && attw --pack .",
220
- "pack:smoke": "node --import tsx ../tooling/pack-smoke.ts"
219
+ "pack:smoke": "rxova-repo-config pack-smoke && node -e \"if (!/^['\\\"]use client/.test(require('fs').readFileSync('dist/index.js', 'utf8'))) throw new Error('dist/index.js lost its use client directive')\""
221
220
  }
222
221
  }