@mmstack/primitives 21.8.1 → 21.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmstack/primitives",
3
- "version": "21.8.1",
3
+ "version": "21.8.3",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",
@@ -1315,6 +1315,28 @@ declare function indexArray<T, U>(source: Signal<T[]> | (() => T[]), map: (value
1315
1315
  */
1316
1316
  declare const mapArray: typeof indexArray;
1317
1317
 
1318
+ /**
1319
+ * Opt-in policy describing how `keyArray` should treat duplicate keys.
1320
+ *
1321
+ * With the `'ordinal'` policy, keys are coerced to strings and disambiguated by
1322
+ * their occurrence order: the first item with a given base key keeps `base`, the
1323
+ * second becomes `base#1`, the third `base#2`, and so on. Each duplicate therefore
1324
+ * gets a stable, distinct entry instead of collapsing.
1325
+ *
1326
+ * Identity follows position-among-duplicates: removing an earlier occurrence
1327
+ * promotes the next one to the base key, which changes its effective key and thus
1328
+ * re-creates its mapped entry.
1329
+ */
1330
+ type DuplicateKeyPolicy = {
1331
+ /** Disambiguation strategy. Currently only ordinal (`base`, `base#1`, `base#2`, ...). */
1332
+ policy: 'ordinal';
1333
+ /**
1334
+ * Optional diagnostics side-channel. When a recompute observes duplicate keys,
1335
+ * this is invoked once with the duplicate base keys in first-occurrence order.
1336
+ * It is called untracked and must not be relied upon to create reactive dependencies.
1337
+ */
1338
+ report?: (bases: readonly string[]) => void;
1339
+ };
1318
1340
  /**
1319
1341
  * Reactively maps items from a source array to a new array by value (identity).
1320
1342
  *
@@ -1333,6 +1355,8 @@ declare const mapArray: typeof indexArray;
1333
1355
  * - `onDestroy`: A callback invoked when a mapped item is removed from the array.
1334
1356
  * - `key`: A custom key extractor for identity matching (e.g. `(item) => item.id`)
1335
1357
  * when item references change but conceptual identity is preserved.
1358
+ * - `duplicateKeys`: Opt-in policy for handling duplicate keys. When omitted,
1359
+ * behavior is unchanged (duplicates collapse). See {@link DuplicateKeyPolicy}.
1336
1360
  * @returns A `Signal<U[]>` containing the mapped array.
1337
1361
  *
1338
1362
  * @example
@@ -1364,6 +1388,12 @@ declare function keyArray<T, U, K>(source: Signal<T[]> | (() => T[]), mapFn: (v:
1364
1388
  * even if the item reference changes.
1365
1389
  */
1366
1390
  key?: (item: T) => K;
1391
+ /**
1392
+ * Opt-in policy for disambiguating duplicate keys. When present, keys are
1393
+ * coerced to strings and duplicates get distinct ordinal effective keys
1394
+ * (`base`, `base#1`, `base#2`, ...). When absent, behavior is unchanged.
1395
+ */
1396
+ duplicateKeys?: DuplicateKeyPolicy;
1367
1397
  }): Signal<U[]>;
1368
1398
 
1369
1399
  type MappedObject<T extends object, U> = {
@@ -3094,10 +3124,14 @@ declare const STORE_SHARED_GLOBALS: unique symbol;
3094
3124
  type ProxyCache = WeakMap<object, Map<PropertyKey, WeakRef<Signal<any>>>>;
3095
3125
  /**
3096
3126
  * @internal
3097
- * Prunes a cache entry once its proxy is reclaimed by the GC.
3127
+ * Prunes a cache entry once its proxy is reclaimed by the GC. The held value must reference
3128
+ * `target` only weakly: held values are retained by the registry until its cleanup callbacks
3129
+ * run (host tasks — they never run inside a synchronous burst), so a strong `target` here
3130
+ * keeps every dropped subtree's backing-signal ancestry alive across GCs. If `target` is
3131
+ * already dead its whole cache entry died with it (WeakMap), and there is nothing to prune.
3098
3132
  */
3099
3133
  type ProxyCleanupRegistry = FinalizationRegistry<{
3100
- target: object;
3134
+ targetRef: WeakRef<object>;
3101
3135
  prop: PropertyKey;
3102
3136
  }>;
3103
3137
  /**
@@ -4482,4 +4516,4 @@ type CreateHistoryOptions<T> = Omit<CreateSignalOptions<T[]>, 'equal'> & {
4482
4516
  declare function withHistory<T>(sourceOrValue: WritableSignal<T> | T, opt?: CreateHistoryOptions<T>): SignalWithHistory<T>;
4483
4517
 
4484
4518
  export { CONCURRENCY_INSTRUMENTATION, MmActivity, MmTransition, MmViewTransitionName, OP_PROTO_VERSION, PAUSABLE_OPTIONS, PERSISTED_STORE_OPTIONS, POS_SEGMENT, SuspenseBoundary, SuspenseBoundaryBase, UnscopedSuspenseBoundary, activeTransaction, applyOps, batteryStatus, bridgeScopeToPendingTasks, chunked, clipboard, combineWith, compareHlc, compareSiblings, compareTotal, createAttributedPending, createConvergingApply, createForwardingScope, createHlcClock, createStoreContext, createTransaction, createTransitionScope, debounce, debounced, defaultFold, deferredValue, derived, diffOps, distinct, elementSize, elementVisibility, extendStore, filter, filterWith, focusWithin, forkStore, geolocation, getTransitionScope, holdUntilReady, idle, indexArray, injectPaused, injectRegisterResource, injectStartTransaction, injectStartTransition, injectTransitionScope, insertElement, invertBatch, isConflicted, isDerivation, isLeaf, isMutable, isOpaque, isStore, keepPrevious, keyArray, keyedArray, latest, lww, map, mapArray, mapObject, mediaQuery, merge3, mergeThree, mousePosition, moveElement, mutable, mutableStore, nestedEffect, networkStatus, opLog, opSync, opaque, orderedEntries, orientation, pageVisibility, pairwise, pausableComputed, pausableEffect, pausableSignal, perfCustomTracks, persist, persistedStore, pipeable, piped, pointerDrag, policyStrategy, pooled, pooledArray, pooledMap, pooledSet, posBetween, prefersDarkMode, prefersReducedMotion, preserve, projection, provideConcurrencyInstrumentation, provideForwardingTransitionScope, providePausableOptions, providePaused, providePersistedStoreOptions, provideTransitionScope, rebalanceContainer, rebaseOps, reconcile, registerResource, removeElement, resolvePause, scan, scrollPosition, select, sensor, sensors, signalFromEvent, startWith, store, storeHistory, stored, syncedFork, tabSync, tap, throttle, throttled, toFakeDerivation, toFakeSignalDerivation, toStore, toWritable, until, use, validateEnvelope, windowSize, withHistory };
4485
- export type { AsyncStore, BatteryStatus, ClipboardSignal, Computation, ConcurrencyInstrumentation, Conflicted, ContainerNode, ConvergingApply, CreateChunkedOptions, CreateDebouncedOptions, CreateHistoryOptions, CreateLatestOptions, CreateOpLogOptions, CreatePooledOptions, CreateProvidedPooledOptions, CreateStoredOptions, CreateThrottledOptions, CreateTransitionScopeOptions, DebouncedSignal, DeferStrategy, DeferredSignal, DeferredValueOptions, DerivedSignal, Dot, DotFrontier, ElementSize, ElementSizeOptions, ElementSizeSignal, ElementVisibilityOptions, ElementVisibilitySignal, ExtendStoreOptions, FoldFn, FoldPolicyEntry, FoldResult, Fork, ForkStoreOptions, ForkStrategy, ForwardingTransitionScope, Frame, GeolocationOptions, GeolocationSignal, Hlc, HlcClock, IdleOptions, IdleSignal, LatestSignal, MergeContext, MergeFn, MergePolicyEntry, MmTransitionContext, MousePositionOptions, MousePositionSignal, MutableSignal, MutableSignalStore, NetworkStatusSignal, OpBatch, OpEnvelope, OpLog, OpLogDriver, OpSync, OpSyncCheckpoint, OpSyncOptions, Opaque, OrderedEntry, PausableOptions, PauseOption, PersistHandle, PersistOptions, PersistedStore, PersistedStoreDefaults, PersistedStoreOptions, PipeableSignal, PointerDragOptions, PointerDragSignal, PointerDragState, PointerModifiers, PointerPoint, ProjectionOptions, RebaseResult, ReconcileFn, ReconcileKey, RegisterCheckpoint, RegisterOptions, ResourceLike, ScreenOrientation, ScreenOrientationState, ScrollPosition, ScrollPositionOptions, ScrollPositionSignal, SensorRunOptions, SignalFromEventOptions, SignalStore, SignalWithHistory, StoreHistory, StoreHistoryOptions, StoreOp, StoreOptions, StoreTabSyncOptions, StoredSignal, SuspendType, SyncOp, SyncSibling, SyncSignalOptions, SyncedFork, TabSyncBus, ThrottledSignal, Transaction, TransactionRef, TransitionRef, TransitionScope, UntilOptions, UseSource, Vivify, WindowSize, WindowSizeOptions, WindowSizeSignal, WithVivify, WritableSignalStore, toStoreOptions };
4519
+ export type { AsyncStore, BatteryStatus, ClipboardSignal, Computation, ConcurrencyInstrumentation, Conflicted, ContainerNode, ConvergingApply, CreateChunkedOptions, CreateDebouncedOptions, CreateHistoryOptions, CreateLatestOptions, CreateOpLogOptions, CreatePooledOptions, CreateProvidedPooledOptions, CreateStoredOptions, CreateThrottledOptions, CreateTransitionScopeOptions, DebouncedSignal, DeferStrategy, DeferredSignal, DeferredValueOptions, DerivedSignal, Dot, DotFrontier, DuplicateKeyPolicy, ElementSize, ElementSizeOptions, ElementSizeSignal, ElementVisibilityOptions, ElementVisibilitySignal, ExtendStoreOptions, FoldFn, FoldPolicyEntry, FoldResult, Fork, ForkStoreOptions, ForkStrategy, ForwardingTransitionScope, Frame, GeolocationOptions, GeolocationSignal, Hlc, HlcClock, IdleOptions, IdleSignal, LatestSignal, MergeContext, MergeFn, MergePolicyEntry, MmTransitionContext, MousePositionOptions, MousePositionSignal, MutableSignal, MutableSignalStore, NetworkStatusSignal, OpBatch, OpEnvelope, OpLog, OpLogDriver, OpSync, OpSyncCheckpoint, OpSyncOptions, Opaque, OrderedEntry, PausableOptions, PauseOption, PersistHandle, PersistOptions, PersistedStore, PersistedStoreDefaults, PersistedStoreOptions, PipeableSignal, PointerDragOptions, PointerDragSignal, PointerDragState, PointerModifiers, PointerPoint, ProjectionOptions, RebaseResult, ReconcileFn, ReconcileKey, RegisterCheckpoint, RegisterOptions, ResourceLike, ScreenOrientation, ScreenOrientationState, ScrollPosition, ScrollPositionOptions, ScrollPositionSignal, SensorRunOptions, SignalFromEventOptions, SignalStore, SignalWithHistory, StoreHistory, StoreHistoryOptions, StoreOp, StoreOptions, StoreTabSyncOptions, StoredSignal, SuspendType, SyncOp, SyncSibling, SyncSignalOptions, SyncedFork, TabSyncBus, ThrottledSignal, Transaction, TransactionRef, TransitionRef, TransitionScope, UntilOptions, UseSource, Vivify, WindowSize, WindowSizeOptions, WindowSizeSignal, WithVivify, WritableSignalStore, toStoreOptions };