@mmstack/primitives 20.4.4 → 20.4.5

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/index.d.ts CHANGED
@@ -1160,6 +1160,48 @@ type StoredSignal<T> = WritableSignal<T> & {
1160
1160
  */
1161
1161
  declare function stored<T>(fallback: T, { key, store: providedStore, serialize, deserialize, syncTabs, equal, onKeyChange, cleanupOldKey, ...rest }: CreateStoredOptions<T>): StoredSignal<T>;
1162
1162
 
1163
+ type SyncSignalOptions = {
1164
+ id?: string;
1165
+ };
1166
+ /**
1167
+ * Synchronizes a WritableSignal across browser tabs using BroadcastChannel API.
1168
+ *
1169
+ * Creates a shared signal that automatically syncs its value between all tabs
1170
+ * of the same application. When the signal is updated in one tab, all other
1171
+ * tabs will receive the new value automatically.
1172
+ *
1173
+ * @template T - The type of the WritableSignal
1174
+ * @param sig - The WritableSignal to synchronize across tabs
1175
+ * @param opt - Optional configuration object
1176
+ * @param opt.id - Explicit channel ID for synchronization. If not provided,
1177
+ * a deterministic ID is generated based on the call site.
1178
+ * Use explicit IDs in production for reliability.
1179
+ *
1180
+ * @returns The same WritableSignal instance, now synchronized across tabs
1181
+ *
1182
+ * @throws {Error} When deterministic ID generation fails and no explicit ID is provided
1183
+ *
1184
+ * @example
1185
+ * ```typescript
1186
+ * // Basic usage - auto-generates channel ID from call site
1187
+ * const theme = tabSync(signal('dark'));
1188
+ *
1189
+ * // With explicit ID (recommended for production)
1190
+ * const userPrefs = tabSync(signal({ lang: 'en' }), { id: 'user-preferences' });
1191
+ *
1192
+ * // Changes in one tab will sync to all other tabs
1193
+ * theme.set('light'); // All tabs will update to 'light'
1194
+ * ```
1195
+ *
1196
+ * @remarks
1197
+ * - Only works in browser environments (returns original signal on server)
1198
+ * - Uses a single BroadcastChannel for all synchronized signals
1199
+ * - Automatically cleans up listeners when the injection context is destroyed
1200
+ * - Initial signal value after sync setup is not broadcasted to prevent loops
1201
+ *
1202
+ */
1203
+ declare function tabSync<T extends WritableSignal<any>>(sig: T, opt?: SyncSignalOptions): T;
1204
+
1163
1205
  /**
1164
1206
  * Options for creating a throttled writable signal.
1165
1207
  * Extends Angular's `CreateSignalOptions` with a throttle time setting.
@@ -1414,5 +1456,5 @@ type CreateHistoryOptions<T> = Omit<CreateSignalOptions<T[]>, 'equal'> & {
1414
1456
  */
1415
1457
  declare function withHistory<T>(source: WritableSignal<T>, opt?: CreateHistoryOptions<T>): SignalWithHistory<T>;
1416
1458
 
1417
- export { combineWith, debounce, debounced, derived, distinct, elementVisibility, filter, isDerivation, isMutable, map, mapArray, mediaQuery, mousePosition, mutable, networkStatus, pageVisibility, pipeable, piped, prefersDarkMode, prefersReducedMotion, scrollPosition, select, sensor, stored, tap, throttle, throttled, toFakeDerivation, toFakeSignalDerivation, toWritable, until, windowSize, withHistory };
1459
+ export { combineWith, debounce, debounced, derived, distinct, elementVisibility, filter, isDerivation, isMutable, map, mapArray, mediaQuery, mousePosition, mutable, networkStatus, pageVisibility, pipeable, piped, prefersDarkMode, prefersReducedMotion, scrollPosition, select, sensor, stored, tabSync, tap, throttle, throttled, toFakeDerivation, toFakeSignalDerivation, toWritable, until, windowSize, withHistory };
1418
1460
  export type { CreateDebouncedOptions, CreateHistoryOptions, CreateStoredOptions, CreateThrottledOptions, DebouncedSignal, DerivedSignal, ElementVisibilityOptions, ElementVisibilitySignal, MousePositionOptions, MousePositionSignal, MutableSignal, NetworkStatusSignal, PipeableSignal, ScrollPosition, ScrollPositionOptions, ScrollPositionSignal, SignalWithHistory, StoredSignal, ThrottledSignal, UntilOptions, WindowSize, WindowSizeOptions, WindowSizeSignal };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmstack/primitives",
3
- "version": "20.4.4",
3
+ "version": "20.4.5",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",