@mmstack/primitives 22.8.2 → 22.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
|
@@ -1322,6 +1322,28 @@ declare function indexArray<T, U>(source: Signal<T[]> | (() => T[]), map: (value
|
|
|
1322
1322
|
*/
|
|
1323
1323
|
declare const mapArray: typeof indexArray;
|
|
1324
1324
|
|
|
1325
|
+
/**
|
|
1326
|
+
* Opt-in policy describing how `keyArray` should treat duplicate keys.
|
|
1327
|
+
*
|
|
1328
|
+
* With the `'ordinal'` policy, keys are coerced to strings and disambiguated by
|
|
1329
|
+
* their occurrence order: the first item with a given base key keeps `base`, the
|
|
1330
|
+
* second becomes `base#1`, the third `base#2`, and so on. Each duplicate therefore
|
|
1331
|
+
* gets a stable, distinct entry instead of collapsing.
|
|
1332
|
+
*
|
|
1333
|
+
* Identity follows position-among-duplicates: removing an earlier occurrence
|
|
1334
|
+
* promotes the next one to the base key, which changes its effective key and thus
|
|
1335
|
+
* re-creates its mapped entry.
|
|
1336
|
+
*/
|
|
1337
|
+
type DuplicateKeyPolicy = {
|
|
1338
|
+
/** Disambiguation strategy. Currently only ordinal (`base`, `base#1`, `base#2`, ...). */
|
|
1339
|
+
policy: 'ordinal';
|
|
1340
|
+
/**
|
|
1341
|
+
* Optional diagnostics side-channel. When a recompute observes duplicate keys,
|
|
1342
|
+
* this is invoked once with the duplicate base keys in first-occurrence order.
|
|
1343
|
+
* It is called untracked and must not be relied upon to create reactive dependencies.
|
|
1344
|
+
*/
|
|
1345
|
+
report?: (bases: readonly string[]) => void;
|
|
1346
|
+
};
|
|
1325
1347
|
/**
|
|
1326
1348
|
* Reactively maps items from a source array to a new array by value (identity).
|
|
1327
1349
|
*
|
|
@@ -1335,11 +1357,15 @@ declare const mapArray: typeof indexArray;
|
|
|
1335
1357
|
* when the list is reordered.
|
|
1336
1358
|
*
|
|
1337
1359
|
* @param source A `Signal<T[]>` or a function returning `T[]`.
|
|
1338
|
-
* @param mapFn The mapping function. Receives the item
|
|
1360
|
+
* @param mapFn The mapping function. Receives the item, its index as a Signal, and the
|
|
1361
|
+
* entry's key (the effective ordinal key when `duplicateKeys` is enabled, otherwise
|
|
1362
|
+
* the raw key) — stable for the lifetime of the mapped entry.
|
|
1339
1363
|
* @param options Optional configuration:
|
|
1340
1364
|
* - `onDestroy`: A callback invoked when a mapped item is removed from the array.
|
|
1341
1365
|
* - `key`: A custom key extractor for identity matching (e.g. `(item) => item.id`)
|
|
1342
1366
|
* when item references change but conceptual identity is preserved.
|
|
1367
|
+
* - `duplicateKeys`: Opt-in policy for handling duplicate keys. When omitted,
|
|
1368
|
+
* behavior is unchanged (duplicates collapse). See {@link DuplicateKeyPolicy}.
|
|
1343
1369
|
* @returns A `Signal<U[]>` containing the mapped array.
|
|
1344
1370
|
*
|
|
1345
1371
|
* @example
|
|
@@ -1363,7 +1389,7 @@ declare const mapArray: typeof indexArray;
|
|
|
1363
1389
|
* users.set([users()[1], users()[0]]);
|
|
1364
1390
|
* ```
|
|
1365
1391
|
*/
|
|
1366
|
-
declare function keyArray<T, U, K>(source: Signal<T[]> | (() => T[]), mapFn: (v: T, i: Signal<number
|
|
1392
|
+
declare function keyArray<T, U, K>(source: Signal<T[]> | (() => T[]), mapFn: (v: T, i: Signal<number>, key: K | string) => U, options?: {
|
|
1367
1393
|
onDestroy?: (value: U) => void;
|
|
1368
1394
|
/**
|
|
1369
1395
|
* Optional function to use a custom key for item comparison.
|
|
@@ -1371,6 +1397,12 @@ declare function keyArray<T, U, K>(source: Signal<T[]> | (() => T[]), mapFn: (v:
|
|
|
1371
1397
|
* even if the item reference changes.
|
|
1372
1398
|
*/
|
|
1373
1399
|
key?: (item: T) => K;
|
|
1400
|
+
/**
|
|
1401
|
+
* Opt-in policy for disambiguating duplicate keys. When present, keys are
|
|
1402
|
+
* coerced to strings and duplicates get distinct ordinal effective keys
|
|
1403
|
+
* (`base`, `base#1`, `base#2`, ...). When absent, behavior is unchanged.
|
|
1404
|
+
*/
|
|
1405
|
+
duplicateKeys?: DuplicateKeyPolicy;
|
|
1374
1406
|
}): Signal<U[]>;
|
|
1375
1407
|
|
|
1376
1408
|
type MappedObject<T extends object, U> = {
|
|
@@ -4493,4 +4525,4 @@ type CreateHistoryOptions<T> = Omit<CreateSignalOptions<T[]>, 'equal'> & {
|
|
|
4493
4525
|
declare function withHistory<T>(sourceOrValue: WritableSignal<T> | T, opt?: CreateHistoryOptions<T>): SignalWithHistory<T>;
|
|
4494
4526
|
|
|
4495
4527
|
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 };
|
|
4496
|
-
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 };
|
|
4528
|
+
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 };
|