@mmstack/primitives 21.8.2 → 21.8.4

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.2",
3
+ "version": "21.8.4",
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
  *
@@ -1328,11 +1350,15 @@ declare const mapArray: typeof indexArray;
1328
1350
  * when the list is reordered.
1329
1351
  *
1330
1352
  * @param source A `Signal<T[]>` or a function returning `T[]`.
1331
- * @param mapFn The mapping function. Receives the item and its index as a Signal.
1353
+ * @param mapFn The mapping function. Receives the item, its index as a Signal, and the
1354
+ * entry's key (the effective ordinal key when `duplicateKeys` is enabled, otherwise
1355
+ * the raw key) — stable for the lifetime of the mapped entry.
1332
1356
  * @param options Optional configuration:
1333
1357
  * - `onDestroy`: A callback invoked when a mapped item is removed from the array.
1334
1358
  * - `key`: A custom key extractor for identity matching (e.g. `(item) => item.id`)
1335
1359
  * when item references change but conceptual identity is preserved.
1360
+ * - `duplicateKeys`: Opt-in policy for handling duplicate keys. When omitted,
1361
+ * behavior is unchanged (duplicates collapse). See {@link DuplicateKeyPolicy}.
1336
1362
  * @returns A `Signal<U[]>` containing the mapped array.
1337
1363
  *
1338
1364
  * @example
@@ -1356,7 +1382,7 @@ declare const mapArray: typeof indexArray;
1356
1382
  * users.set([users()[1], users()[0]]);
1357
1383
  * ```
1358
1384
  */
1359
- declare function keyArray<T, U, K>(source: Signal<T[]> | (() => T[]), mapFn: (v: T, i: Signal<number>) => U, options?: {
1385
+ declare function keyArray<T, U, K>(source: Signal<T[]> | (() => T[]), mapFn: (v: T, i: Signal<number>, key: K | string) => U, options?: {
1360
1386
  onDestroy?: (value: U) => void;
1361
1387
  /**
1362
1388
  * Optional function to use a custom key for item comparison.
@@ -1364,6 +1390,12 @@ declare function keyArray<T, U, K>(source: Signal<T[]> | (() => T[]), mapFn: (v:
1364
1390
  * even if the item reference changes.
1365
1391
  */
1366
1392
  key?: (item: T) => K;
1393
+ /**
1394
+ * Opt-in policy for disambiguating duplicate keys. When present, keys are
1395
+ * coerced to strings and duplicates get distinct ordinal effective keys
1396
+ * (`base`, `base#1`, `base#2`, ...). When absent, behavior is unchanged.
1397
+ */
1398
+ duplicateKeys?: DuplicateKeyPolicy;
1367
1399
  }): Signal<U[]>;
1368
1400
 
1369
1401
  type MappedObject<T extends object, U> = {
@@ -4486,4 +4518,4 @@ type CreateHistoryOptions<T> = Omit<CreateSignalOptions<T[]>, 'equal'> & {
4486
4518
  declare function withHistory<T>(sourceOrValue: WritableSignal<T> | T, opt?: CreateHistoryOptions<T>): SignalWithHistory<T>;
4487
4519
 
4488
4520
  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 };
4489
- 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 };
4521
+ 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 };