@mmstack/primitives 20.15.3 → 20.16.0

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
@@ -1244,6 +1244,15 @@ declare function nestedEffect(effectFn: (registerCleanup: EffectCleanupRegisterF
1244
1244
  bindToFrame?: (parent: Frame | null) => Frame | null;
1245
1245
  }): EffectRef;
1246
1246
 
1247
+ /**
1248
+ * Options for {@link keepPrevious}: the signal options of the held value, plus
1249
+ * `fallback` — what to yield while there is nothing to hold yet (the source has
1250
+ * never been defined). Once a defined value has been seen the fallback is never
1251
+ * yielded again; the previous value is.
1252
+ */
1253
+ type KeepPreviousOptions<T> = CreateSignalOptions<T> & {
1254
+ readonly fallback?: T;
1255
+ };
1247
1256
  /**
1248
1257
  * Wraps a signal so it HOLDS its last defined value whenever the source becomes
1249
1258
  * `undefined`, yielding that value instead of the gap. This is the foundation of
@@ -1257,10 +1266,10 @@ declare function nestedEffect(effectFn: (registerCleanup: EffectCleanupRegisterF
1257
1266
  * so it stays a drop-in replacement. (Angular's `resource` is itself linkedSignal-backed
1258
1267
  * and exposes a writable `value` for optimistic updates; this preserves that.)
1259
1268
  */
1260
- declare function keepPrevious<T>(value: MutableSignal<T>, opt?: CreateSignalOptions<T>): MutableSignal<T>;
1261
- declare function keepPrevious<T, U>(value: DerivedSignal<T, U>, opt?: CreateSignalOptions<U>): DerivedSignal<T, U>;
1262
- declare function keepPrevious<T>(value: WritableSignal<T>, opt?: CreateSignalOptions<T>): WritableSignal<T>;
1263
- declare function keepPrevious<T>(value: Signal<T>, opt?: CreateSignalOptions<T>): Signal<T>;
1269
+ declare function keepPrevious<T>(value: MutableSignal<T>, opt?: KeepPreviousOptions<T>): MutableSignal<T>;
1270
+ declare function keepPrevious<T, U>(value: DerivedSignal<T, U>, opt?: KeepPreviousOptions<U>): DerivedSignal<T, U>;
1271
+ declare function keepPrevious<T>(value: WritableSignal<T>, opt?: KeepPreviousOptions<T>): WritableSignal<T>;
1272
+ declare function keepPrevious<T>(value: Signal<T>, opt?: KeepPreviousOptions<T>): Signal<T>;
1264
1273
 
1265
1274
  /**
1266
1275
  * Reactively maps items from a source array to a new array, creating stable signals for each item.
@@ -2848,7 +2857,10 @@ type Key$2 = string | number;
2848
2857
  /**
2849
2858
  * One structural operation. `set` on a key that did not previously exist carries NO `prev`
2850
2859
  * property (an absent key is not the same as a key holding `undefined` — the merge3 lesson),
2851
- * which is what lets {@link invertBatch} invert an add into a delete.
2860
+ * which is what lets {@link invertBatch} invert an add into a delete. A JSON text transport
2861
+ * collapses an own `prev: undefined` into an absent `prev` (structured-clone and in-process
2862
+ * channels preserve the distinction) — wire-serialized batches were already not invertible,
2863
+ * see {@link invertBatch}.
2852
2864
  *
2853
2865
  * `clear` is a sync-layer intent, not a value change: it retires a per-path register (the
2854
2866
  * observed-remove half of a subtree replace) and contributes NOTHING to a value: {@link applyOps}
@@ -3408,7 +3420,8 @@ type SyncOp = StoreOp & {
3408
3420
  * The wire/journal record. `writer` is an opaque principal pseudonym (natural identity never
3409
3421
  * enters the envelope); `origin` identifies the emitting replica. All ops in one envelope share
3410
3422
  * the envelope stamp, and an envelope carries at most one op per path, so `(origin, hlc)` is a
3411
- * unique dot per path register.
3423
+ * unique dot per path register. Op VALUES are wire data under the JSON-fidelity law — see
3424
+ * {@link wireValueViolation}; emission lints them in dev mode.
3412
3425
  */
3413
3426
  type OpEnvelope = {
3414
3427
  readonly proto: number;
@@ -3809,6 +3822,75 @@ declare function removeElement<T>(container: ContainerNode<T>, key: string): voi
3809
3822
  * reclaim precision after many same-gap inserts. Existing reading order is preserved.
3810
3823
  */
3811
3824
  declare function rebalanceContainer<T extends object>(sync: Pick<OpSync, 'override'>, container: ContainerNode<T>): void;
3825
+ /**
3826
+ * An element of a container in the WRAPPED representation: position beside the payload rather than
3827
+ * inside it, so the payload stays a closed record a schema can validate without knowing about
3828
+ * `~pos`. A move writes `[container, key, '~pos']` and a field edit writes
3829
+ * `[container, key, 'value', field]` — still disjoint one-field paths.
3830
+ */
3831
+ type ContainerEntry<T> = {
3832
+ readonly [POS_SEGMENT]: string;
3833
+ readonly value: T;
3834
+ };
3835
+ /** `key` derives an element's key from the value, for payloads carrying their own identity field. */
3836
+ type KeyedContainerConfig<T> = {
3837
+ readonly key?: (value: T) => string;
3838
+ };
3839
+ /** The helpers of one container flavour, with keys supplied by the caller. */
3840
+ type KeyedContainer<T extends object, E extends object = T> = {
3841
+ entries(container: Record<string, E>): OrderedEntry<T>[];
3842
+ insert(container: ContainerNode<E>, key: string, value: T, index?: number): string;
3843
+ move(container: ContainerNode<E>, key: string, index: number): string | undefined;
3844
+ remove(container: ContainerNode<E>, key: string): void;
3845
+ rebalance(sync: Pick<OpSync, 'override'>, container: ContainerNode<E>): void;
3846
+ };
3847
+ /** The same helpers where a configured `key` extractor supplies the key, so `insert` takes none. */
3848
+ type SelfKeyedContainer<T extends object, E extends object = T> = Omit<KeyedContainer<T, E>, 'insert'> & {
3849
+ insert(container: ContainerNode<E>, value: T, index?: number): string;
3850
+ };
3851
+ /**
3852
+ * Binds one container flavour to the whole set of helpers, so every read and write of a container
3853
+ * agrees on how its elements are shaped. Pass the container node itself per call: one flavour
3854
+ * serves every container of a type. Positions live INSIDE the element; for a payload that must
3855
+ * stay a closed record, use {@link wrappedContainer} instead.
3856
+ *
3857
+ * ```typescript
3858
+ * const slots = keyedContainer({ key: (n: Node) => n.id });
3859
+ * slots.insert(node, child, 2); // one set at [container, id]
3860
+ * slots.move(node, 'child-1', 0); // one set at [container, 'child-1', '~pos']
3861
+ * slots.entries(node()); // reading order
3862
+ * ```
3863
+ *
3864
+ * With no extractor, `insert` takes the key: `keyedContainer<Node>()`. A duplicate key OVERWRITES,
3865
+ * taking a fresh position at the requested index. An element's identity field is immutable while it
3866
+ * is resident — re-keying is a remove plus an insert, never an edit.
3867
+ */
3868
+ declare function keyedContainer<T extends object>(config: {
3869
+ key: (value: T) => string;
3870
+ }): SelfKeyedContainer<T>;
3871
+ declare function keyedContainer<T extends object>(config?: {
3872
+ key?: never;
3873
+ }): KeyedContainer<T>;
3874
+ /**
3875
+ * {@link keyedContainer} storing every element as a {@link ContainerEntry}: the position sits
3876
+ * beside the payload rather than inside it, so a schema that closes the payload record still
3877
+ * validates. `entries` reads back payloads, never wrappers.
3878
+ *
3879
+ * ```typescript
3880
+ * const slots = wrappedContainer({ key: (n: Node) => n.id });
3881
+ * slots.insert(node, child, 2); // one set at [container, id] carrying { '~pos', value }
3882
+ * ```
3883
+ *
3884
+ * A container's representation is fixed when it is created and is never carried on the wire, so
3885
+ * every peer of a synced container must agree on it — converting one after the fact is a data
3886
+ * migration, not a flag.
3887
+ */
3888
+ declare function wrappedContainer<T extends object>(config: {
3889
+ key: (value: T) => string;
3890
+ }): SelfKeyedContainer<T, ContainerEntry<T>>;
3891
+ declare function wrappedContainer<T extends object>(config?: {
3892
+ key?: never;
3893
+ }): KeyedContainer<T, ContainerEntry<T>>;
3812
3894
 
3813
3895
  type StoreHistory = {
3814
3896
  readonly canUndo: Signal<boolean>;
@@ -4594,5 +4676,5 @@ type CreateHistoryOptions<T> = Omit<CreateSignalOptions<T[]>, 'equal'> & {
4594
4676
  */
4595
4677
  declare function withHistory<T>(sourceOrValue: WritableSignal<T> | T, opt?: CreateHistoryOptions<T>): SignalWithHistory<T>;
4596
4678
 
4597
- 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, isStored, 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, pooledKeys, 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, traced, until, use, validateEnvelope, windowSize, withHistory };
4598
- 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, Traced, Transaction, TransactionRef, TransitionRef, TransitionScope, UntilOptions, UseSource, Vivify, WindowSize, WindowSizeOptions, WindowSizeSignal, WithVivify, WritableSignalStore, toStoreOptions };
4679
+ 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, isStored, keepPrevious, keyArray, keyedArray, keyedContainer, 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, pooledKeys, 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, traced, until, use, validateEnvelope, windowSize, withHistory, wrappedContainer };
4680
+ export type { AsyncStore, BatteryStatus, ClipboardSignal, Computation, ConcurrencyInstrumentation, Conflicted, ContainerEntry, 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, KeepPreviousOptions, KeyedContainer, KeyedContainerConfig, 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, SelfKeyedContainer, SensorRunOptions, SignalFromEventOptions, SignalStore, SignalWithHistory, StoreHistory, StoreHistoryOptions, StoreOp, StoreOptions, StoreTabSyncOptions, StoredSignal, SuspendType, SyncOp, SyncSibling, SyncSignalOptions, SyncedFork, TabSyncBus, ThrottledSignal, Traced, Transaction, TransactionRef, TransitionRef, TransitionScope, UntilOptions, UseSource, Vivify, WindowSize, WindowSizeOptions, WindowSizeSignal, WithVivify, WritableSignalStore, toStoreOptions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmstack/primitives",
3
- "version": "20.15.3",
3
+ "version": "20.16.0",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",