@mmstack/primitives 22.10.3 → 22.11.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/README.md +22 -1
- package/fesm2022/mmstack-primitives.mjs +137 -29
- package/fesm2022/mmstack-primitives.mjs.map +1 -1
- package/package.json +1 -1
- package/types/mmstack-primitives.d.ts +90 -8
package/package.json
CHANGED
|
@@ -1251,6 +1251,15 @@ declare function nestedEffect(effectFn: (registerCleanup: EffectCleanupRegisterF
|
|
|
1251
1251
|
bindToFrame?: (parent: Frame | null) => Frame | null;
|
|
1252
1252
|
}): EffectRef;
|
|
1253
1253
|
|
|
1254
|
+
/**
|
|
1255
|
+
* Options for {@link keepPrevious}: the signal options of the held value, plus
|
|
1256
|
+
* `fallback` — what to yield while there is nothing to hold yet (the source has
|
|
1257
|
+
* never been defined). Once a defined value has been seen the fallback is never
|
|
1258
|
+
* yielded again; the previous value is.
|
|
1259
|
+
*/
|
|
1260
|
+
type KeepPreviousOptions<T> = CreateSignalOptions<T> & {
|
|
1261
|
+
readonly fallback?: T;
|
|
1262
|
+
};
|
|
1254
1263
|
/**
|
|
1255
1264
|
* Wraps a signal so it HOLDS its last defined value whenever the source becomes
|
|
1256
1265
|
* `undefined`, yielding that value instead of the gap. This is the foundation of
|
|
@@ -1264,10 +1273,10 @@ declare function nestedEffect(effectFn: (registerCleanup: EffectCleanupRegisterF
|
|
|
1264
1273
|
* so it stays a drop-in replacement. (Angular's `resource` is itself linkedSignal-backed
|
|
1265
1274
|
* and exposes a writable `value` for optimistic updates; this preserves that.)
|
|
1266
1275
|
*/
|
|
1267
|
-
declare function keepPrevious<T>(value: MutableSignal<T>, opt?:
|
|
1268
|
-
declare function keepPrevious<T, U>(value: DerivedSignal<T, U>, opt?:
|
|
1269
|
-
declare function keepPrevious<T>(value: WritableSignal<T>, opt?:
|
|
1270
|
-
declare function keepPrevious<T>(value: Signal<T>, opt?:
|
|
1276
|
+
declare function keepPrevious<T>(value: MutableSignal<T>, opt?: KeepPreviousOptions<T>): MutableSignal<T>;
|
|
1277
|
+
declare function keepPrevious<T, U>(value: DerivedSignal<T, U>, opt?: KeepPreviousOptions<U>): DerivedSignal<T, U>;
|
|
1278
|
+
declare function keepPrevious<T>(value: WritableSignal<T>, opt?: KeepPreviousOptions<T>): WritableSignal<T>;
|
|
1279
|
+
declare function keepPrevious<T>(value: Signal<T>, opt?: KeepPreviousOptions<T>): Signal<T>;
|
|
1271
1280
|
|
|
1272
1281
|
/**
|
|
1273
1282
|
* Reactively maps items from a source array to a new array, creating stable signals for each item.
|
|
@@ -2855,7 +2864,10 @@ type Key$2 = string | number;
|
|
|
2855
2864
|
/**
|
|
2856
2865
|
* One structural operation. `set` on a key that did not previously exist carries NO `prev`
|
|
2857
2866
|
* property (an absent key is not the same as a key holding `undefined` — the merge3 lesson),
|
|
2858
|
-
* which is what lets {@link invertBatch} invert an add into a delete.
|
|
2867
|
+
* which is what lets {@link invertBatch} invert an add into a delete. A JSON text transport
|
|
2868
|
+
* collapses an own `prev: undefined` into an absent `prev` (structured-clone and in-process
|
|
2869
|
+
* channels preserve the distinction) — wire-serialized batches were already not invertible,
|
|
2870
|
+
* see {@link invertBatch}.
|
|
2859
2871
|
*
|
|
2860
2872
|
* `clear` is a sync-layer intent, not a value change: it retires a per-path register (the
|
|
2861
2873
|
* observed-remove half of a subtree replace) and contributes NOTHING to a value: {@link applyOps}
|
|
@@ -3415,7 +3427,8 @@ type SyncOp = StoreOp & {
|
|
|
3415
3427
|
* The wire/journal record. `writer` is an opaque principal pseudonym (natural identity never
|
|
3416
3428
|
* enters the envelope); `origin` identifies the emitting replica. All ops in one envelope share
|
|
3417
3429
|
* the envelope stamp, and an envelope carries at most one op per path, so `(origin, hlc)` is a
|
|
3418
|
-
* unique dot per path register.
|
|
3430
|
+
* unique dot per path register. Op VALUES are wire data under the JSON-fidelity law — see
|
|
3431
|
+
* {@link wireValueViolation}; emission lints them in dev mode.
|
|
3419
3432
|
*/
|
|
3420
3433
|
type OpEnvelope = {
|
|
3421
3434
|
readonly proto: number;
|
|
@@ -3816,6 +3829,75 @@ declare function removeElement<T>(container: ContainerNode<T>, key: string): voi
|
|
|
3816
3829
|
* reclaim precision after many same-gap inserts. Existing reading order is preserved.
|
|
3817
3830
|
*/
|
|
3818
3831
|
declare function rebalanceContainer<T extends object>(sync: Pick<OpSync, 'override'>, container: ContainerNode<T>): void;
|
|
3832
|
+
/**
|
|
3833
|
+
* An element of a container in the WRAPPED representation: position beside the payload rather than
|
|
3834
|
+
* inside it, so the payload stays a closed record a schema can validate without knowing about
|
|
3835
|
+
* `~pos`. A move writes `[container, key, '~pos']` and a field edit writes
|
|
3836
|
+
* `[container, key, 'value', field]` — still disjoint one-field paths.
|
|
3837
|
+
*/
|
|
3838
|
+
type ContainerEntry<T> = {
|
|
3839
|
+
readonly [POS_SEGMENT]: string;
|
|
3840
|
+
readonly value: T;
|
|
3841
|
+
};
|
|
3842
|
+
/** `key` derives an element's key from the value, for payloads carrying their own identity field. */
|
|
3843
|
+
type KeyedContainerConfig<T> = {
|
|
3844
|
+
readonly key?: (value: T) => string;
|
|
3845
|
+
};
|
|
3846
|
+
/** The helpers of one container flavour, with keys supplied by the caller. */
|
|
3847
|
+
type KeyedContainer<T extends object, E extends object = T> = {
|
|
3848
|
+
entries(container: Record<string, E>): OrderedEntry<T>[];
|
|
3849
|
+
insert(container: ContainerNode<E>, key: string, value: T, index?: number): string;
|
|
3850
|
+
move(container: ContainerNode<E>, key: string, index: number): string | undefined;
|
|
3851
|
+
remove(container: ContainerNode<E>, key: string): void;
|
|
3852
|
+
rebalance(sync: Pick<OpSync, 'override'>, container: ContainerNode<E>): void;
|
|
3853
|
+
};
|
|
3854
|
+
/** The same helpers where a configured `key` extractor supplies the key, so `insert` takes none. */
|
|
3855
|
+
type SelfKeyedContainer<T extends object, E extends object = T> = Omit<KeyedContainer<T, E>, 'insert'> & {
|
|
3856
|
+
insert(container: ContainerNode<E>, value: T, index?: number): string;
|
|
3857
|
+
};
|
|
3858
|
+
/**
|
|
3859
|
+
* Binds one container flavour to the whole set of helpers, so every read and write of a container
|
|
3860
|
+
* agrees on how its elements are shaped. Pass the container node itself per call: one flavour
|
|
3861
|
+
* serves every container of a type. Positions live INSIDE the element; for a payload that must
|
|
3862
|
+
* stay a closed record, use {@link wrappedContainer} instead.
|
|
3863
|
+
*
|
|
3864
|
+
* ```typescript
|
|
3865
|
+
* const slots = keyedContainer({ key: (n: Node) => n.id });
|
|
3866
|
+
* slots.insert(node, child, 2); // one set at [container, id]
|
|
3867
|
+
* slots.move(node, 'child-1', 0); // one set at [container, 'child-1', '~pos']
|
|
3868
|
+
* slots.entries(node()); // reading order
|
|
3869
|
+
* ```
|
|
3870
|
+
*
|
|
3871
|
+
* With no extractor, `insert` takes the key: `keyedContainer<Node>()`. A duplicate key OVERWRITES,
|
|
3872
|
+
* taking a fresh position at the requested index. An element's identity field is immutable while it
|
|
3873
|
+
* is resident — re-keying is a remove plus an insert, never an edit.
|
|
3874
|
+
*/
|
|
3875
|
+
declare function keyedContainer<T extends object>(config: {
|
|
3876
|
+
key: (value: T) => string;
|
|
3877
|
+
}): SelfKeyedContainer<T>;
|
|
3878
|
+
declare function keyedContainer<T extends object>(config?: {
|
|
3879
|
+
key?: never;
|
|
3880
|
+
}): KeyedContainer<T>;
|
|
3881
|
+
/**
|
|
3882
|
+
* {@link keyedContainer} storing every element as a {@link ContainerEntry}: the position sits
|
|
3883
|
+
* beside the payload rather than inside it, so a schema that closes the payload record still
|
|
3884
|
+
* validates. `entries` reads back payloads, never wrappers.
|
|
3885
|
+
*
|
|
3886
|
+
* ```typescript
|
|
3887
|
+
* const slots = wrappedContainer({ key: (n: Node) => n.id });
|
|
3888
|
+
* slots.insert(node, child, 2); // one set at [container, id] carrying { '~pos', value }
|
|
3889
|
+
* ```
|
|
3890
|
+
*
|
|
3891
|
+
* A container's representation is fixed when it is created and is never carried on the wire, so
|
|
3892
|
+
* every peer of a synced container must agree on it — converting one after the fact is a data
|
|
3893
|
+
* migration, not a flag.
|
|
3894
|
+
*/
|
|
3895
|
+
declare function wrappedContainer<T extends object>(config: {
|
|
3896
|
+
key: (value: T) => string;
|
|
3897
|
+
}): SelfKeyedContainer<T, ContainerEntry<T>>;
|
|
3898
|
+
declare function wrappedContainer<T extends object>(config?: {
|
|
3899
|
+
key?: never;
|
|
3900
|
+
}): KeyedContainer<T, ContainerEntry<T>>;
|
|
3819
3901
|
|
|
3820
3902
|
type StoreHistory = {
|
|
3821
3903
|
readonly canUndo: Signal<boolean>;
|
|
@@ -4618,5 +4700,5 @@ type CreateHistoryOptions<T> = Omit<CreateSignalOptions<T[]>, 'equal'> & {
|
|
|
4618
4700
|
*/
|
|
4619
4701
|
declare function withHistory<T>(sourceOrValue: WritableSignal<T> | T, opt?: CreateHistoryOptions<T>): SignalWithHistory<T>;
|
|
4620
4702
|
|
|
4621
|
-
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 };
|
|
4622
|
-
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 };
|
|
4703
|
+
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 };
|
|
4704
|
+
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 };
|