@mmstack/primitives 21.2.2 → 21.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmstack/primitives",
3
- "version": "21.2.2",
3
+ "version": "21.3.0",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",
@@ -1937,6 +1937,14 @@ type PointerDragState = {
1937
1937
  modifiers: PointerModifiers;
1938
1938
  /** Mouse button that started the gesture (`-1` when idle). */
1939
1939
  button: number;
1940
+ /** The pointing device: `'mouse' | 'touch' | 'pen'` (`''` when idle). */
1941
+ pointerType: string;
1942
+ /**
1943
+ * The element the gesture started on: the `handleSelector` match when one is
1944
+ * set (so a single delegated listener can tell which child started the drag),
1945
+ * otherwise the listener's element. `null` when idle.
1946
+ */
1947
+ origin: HTMLElement | null;
1940
1948
  };
1941
1949
  type PointerDragOptions = SensorRunOptions & {
1942
1950
  /**
@@ -1949,12 +1957,24 @@ type PointerDragOptions = SensorRunOptions & {
1949
1957
  coordinateSpace?: 'client' | 'page';
1950
1958
  /** Pixels the pointer must travel before `active` flips true. @default 3 */
1951
1959
  activationThreshold?: number;
1952
- /** Throttle (ms) for `current`/`delta` updates. @default 16 */
1960
+ /**
1961
+ * Throttle (ms) for `current`/`delta` updates. @default 16
1962
+ *
1963
+ * Note: a final sub-throttle move right before `pointerup` may not surface on
1964
+ * the throttled view (it coalesces into the terminal idle). Logic that must act
1965
+ * on the *exact* release position should read {@link PointerDragSignal.unthrottled}.
1966
+ */
1953
1967
  throttle?: number;
1954
1968
  /** Only start when the pointerdown target matches this selector (delegated handles). */
1955
1969
  handleSelector?: string;
1956
1970
  /** Mouse buttons that may start a gesture. @default [0] (primary) */
1957
1971
  buttons?: number[];
1972
+ /**
1973
+ * Stop the `pointerdown` from propagating once this sensor claims it. Lets an
1974
+ * inner sensor win over an outer one on the same element tree (e.g. a nested
1975
+ * sortable inside another). @default false
1976
+ */
1977
+ stopPropagation?: boolean;
1958
1978
  };
1959
1979
  /** A gesture signal with an `unthrottled` view and an imperative `cancel()`. */
1960
1980
  type PointerDragSignal = Signal<PointerDragState> & {
@@ -2592,18 +2612,64 @@ type MutableSignalStore<T> = MutableSignal<UnwrapOpaque<T>> & {
2592
2612
  readonly [LEAF]: () => boolean;
2593
2613
  } : NonNullable<T> extends any[] ? MutableArrayStore<NonNullable<T>> : MutableSignalStoreObject<T>);
2594
2614
 
2615
+ declare const STORE_SHARED_GLOBALS: unique symbol;
2616
+ /**
2617
+ * @internal
2618
+ * Maps a store's backing signal to its lazily-built child proxies, each held via a `WeakRef`.
2619
+ */
2620
+ type ProxyCache = WeakMap<object, Map<PropertyKey, WeakRef<Signal<any>>>>;
2621
+ /**
2622
+ * @internal
2623
+ * Prunes a cache entry once its proxy is reclaimed by the GC.
2624
+ */
2625
+ type ProxyCleanupRegistry = FinalizationRegistry<{
2626
+ target: object;
2627
+ prop: PropertyKey;
2628
+ }>;
2595
2629
  /**
2596
2630
  * @internal
2597
2631
  * Validates whether a value is a Signal Store.
2598
2632
  */
2599
2633
  declare function isStore<T>(value: unknown): value is SignalStore<T>;
2600
2634
 
2601
- declare function toStore<T extends AnyRecord>(source: MutableSignal<T>, injector?: Injector, vivify?: Vivify, noUnionLeaves?: boolean): MutableSignalStore<T>;
2602
- declare function toStore<T extends AnyRecord>(source: WritableSignal<T>, injector?: Injector, vivify?: Vivify, noUnionLeaves?: boolean): WritableSignalStore<T>;
2603
- declare function toStore<T extends AnyRecord>(source: Signal<T>, injector?: Injector, vivify?: Vivify, noUnionLeaves?: boolean): SignalStore<T>;
2604
- declare function extendStore<T extends AnyRecord, L extends AnyRecord>(store: MutableSignalStore<T>, source: MutableSignal<L> | L, injector?: Injector): MutableSignalStore<Simplify<Omit<NonNullable<T>, keyof L> & L>>;
2605
- declare function extendStore<T extends AnyRecord, L extends AnyRecord>(store: WritableSignalStore<T>, source: WritableSignal<L> | L, injector?: Injector): WritableSignalStore<Simplify<Omit<NonNullable<T>, keyof L> & L>>;
2606
- declare function extendStore<T extends AnyRecord, L extends AnyRecord>(store: SignalStore<T>, source: Signal<L> | L, injector?: Injector): SignalStore<Simplify<Omit<NonNullable<T>, keyof L> & L>>;
2635
+ type toStoreOptions = {
2636
+ injector?: Injector;
2637
+ /**
2638
+ * Opt-in autovivification: when writing through a `null`/`undefined` path, create the
2639
+ * missing intermediate containers instead of dropping the write. Off by default.
2640
+ *
2641
+ * Levels whose current value is a known object/array re-vivify as that same shape — the
2642
+ * knowledge is captured when the path is first accessed and cached, so it holds even after
2643
+ * the value is later nulled. This option governs only genuinely-unknown (currently
2644
+ * `null`/`undefined`) levels: `'auto'` (an array for index keys, an object otherwise), an
2645
+ * explicit `'object'`/`'array'`, or a `() => container` factory. See {@link Vivify}.
2646
+ */
2647
+ vivify?: Vivify;
2648
+ /**
2649
+ * Performance opt-in: promise that no node ever switches between leaf and substore (i.e. no
2650
+ * unions mixing a primitive with an object/array). With this on, each node's leaf-ness is
2651
+ * resolved once on the first {@link isLeaf} probe and cached as a constant, skipping the
2652
+ * reactive `computed`. If a node's shape does change anyway, {@link isLeaf} keeps its first
2653
+ * answer. Off by default.
2654
+ */
2655
+ noUnionLeaves?: boolean;
2656
+ /**
2657
+ * @internal
2658
+ * Shared cleanup singletons, they get injected/passed automatically
2659
+ */
2660
+ [STORE_SHARED_GLOBALS]?: {
2661
+ cache: ProxyCache;
2662
+ registry: ProxyCleanupRegistry;
2663
+ };
2664
+ };
2665
+ type StoreOptions<T> = CreateSignalOptions<T> & toStoreOptions;
2666
+ declare function toStore<T extends AnyRecord>(source: MutableSignal<T>, options?: toStoreOptions): MutableSignalStore<T>;
2667
+ declare function toStore<T extends AnyRecord>(source: WritableSignal<T>, options?: toStoreOptions): WritableSignalStore<T>;
2668
+ declare function toStore<T extends AnyRecord>(source: Signal<T>, options?: toStoreOptions): SignalStore<T>;
2669
+ type ExtendStoreOptions = Omit<toStoreOptions, 'vivify' | 'noUnionLeaves' | typeof STORE_SHARED_GLOBALS>;
2670
+ declare function extendStore<T extends AnyRecord, L extends AnyRecord>(store: MutableSignalStore<T>, source: MutableSignal<L> | L, options?: ExtendStoreOptions): MutableSignalStore<Simplify<Omit<NonNullable<T>, keyof L> & L>>;
2671
+ declare function extendStore<T extends AnyRecord, L extends AnyRecord>(store: WritableSignalStore<T>, source: WritableSignal<L> | L, options?: ExtendStoreOptions): WritableSignalStore<Simplify<Omit<NonNullable<T>, keyof L> & L>>;
2672
+ declare function extendStore<T extends AnyRecord, L extends AnyRecord>(store: SignalStore<T>, source: Signal<L> | L, options?: ExtendStoreOptions): SignalStore<Simplify<Omit<NonNullable<T>, keyof L> & L>>;
2607
2673
  /**
2608
2674
  * Creates a WritableSignalStore from a value.
2609
2675
  * @see {@link toStore}
@@ -2717,22 +2783,13 @@ type Fork<T> = {
2717
2783
  * leaves compare by value, so equal primitives are correctly seen as unchanged.
2718
2784
  */
2719
2785
  declare function merge3<T>(ancestor: T, mine: T, theirs: T): T;
2720
- declare function forkStore<T extends Record<string, any>>(base: WritableSignalStore<T>, opt?: {
2786
+ /**
2787
+ * ForkStoreOptions, vivify/noUnionLeaves should remain the same & are automatically inherited, override carefully (advanced usecases)
2788
+ */
2789
+ type ForkStoreOptions<T> = toStoreOptions & {
2721
2790
  strategy?: ForkStrategy<T>;
2722
- injector?: Injector;
2723
- /**
2724
- * Store config for the FORK's store — NOT inherited from `base` (it's closed over inside
2725
- * the base's `toStore` and can't be read back). If the base was created with these, pass
2726
- * the same values or the fork's write semantics will differ:
2727
- * - `vivify`: without it, a write through a `null`/`undefined` path is silently dropped on
2728
- * the fork even though the base would have created the container. Match the base.
2729
- * - `noUnionLeaves`: a perf promise; off just means the slower reactive leaf-probe. NOTE it
2730
- * is a whole-store guarantee — a fork that flips a node's type (leaf↔substore) violates it,
2731
- * and on `commit` the base receives the flipped value with stale cached leaf-ness.
2732
- */
2733
- vivify?: Vivify;
2734
- noUnionLeaves?: boolean;
2735
- }): Fork<T>;
2791
+ };
2792
+ declare function forkStore<T extends Record<string, any>>(base: WritableSignalStore<T>, opt?: ForkStoreOptions<T>): Fork<T>;
2736
2793
 
2737
2794
  /**
2738
2795
  * Interface for storage mechanisms compatible with the `stored` signal.
@@ -3193,4 +3250,4 @@ type CreateHistoryOptions<T> = Omit<CreateSignalOptions<T[]>, 'equal'> & {
3193
3250
  declare function withHistory<T>(sourceOrValue: WritableSignal<T> | T, opt?: CreateHistoryOptions<T>): SignalWithHistory<T>;
3194
3251
 
3195
3252
  export { MmActivity, PAUSABLE_OPTIONS, SuspenseBoundary, SuspenseBoundaryBase, UnscopedSuspenseBoundary, activeTransaction, batteryStatus, chunked, clipboard, combineWith, createForwardingScope, createTransaction, createTransitionScope, debounce, debounced, derived, distinct, elementSize, elementVisibility, extendStore, filter, filterWith, focusWithin, forkStore, geolocation, getTransitionScope, holdUntilReady, idle, indexArray, injectPaused, injectRegisterResource, injectStartTransaction, injectStartTransition, injectTransitionScope, isDerivation, isLeaf, isMutable, isOpaque, isStore, keepPrevious, keyArray, map, mapArray, mapObject, mediaQuery, merge3, mousePosition, mutable, mutableStore, nestedEffect, networkStatus, opaque, orientation, pageVisibility, pairwise, pausableComputed, pausableEffect, pausableSignal, pipeable, piped, pointerDrag, pooled, pooledArray, pooledMap, pooledSet, prefersDarkMode, prefersReducedMotion, provideForwardingTransitionScope, providePausableOptions, providePaused, provideTransitionScope, registerResource, resolvePause, scan, scrollPosition, select, sensor, sensors, signalFromEvent, startWith, store, stored, tabSync, tap, throttle, throttled, toFakeDerivation, toFakeSignalDerivation, toStore, toWritable, until, windowSize, withHistory };
3196
- export type { BatteryStatus, ClipboardSignal, Computation, CreateChunkedOptions, CreateDebouncedOptions, CreateHistoryOptions, CreatePooledOptions, CreateProvidedPooledOptions, CreateStoredOptions, CreateThrottledOptions, DebouncedSignal, DerivedSignal, ElementSize, ElementSizeOptions, ElementSizeSignal, ElementVisibilityOptions, ElementVisibilitySignal, Fork, ForkStrategy, ForwardingTransitionScope, Frame, GeolocationOptions, GeolocationSignal, IdleOptions, IdleSignal, MousePositionOptions, MousePositionSignal, MutableSignal, MutableSignalStore, NetworkStatusSignal, Opaque, PausableOptions, PauseOption, PipeableSignal, PointerDragOptions, PointerDragSignal, PointerDragState, PointerModifiers, PointerPoint, ReconcileFn, RegisterOptions, ScreenOrientation, ScreenOrientationState, ScrollPosition, ScrollPositionOptions, ScrollPositionSignal, SensorRunOptions, SignalFromEventOptions, SignalStore, SignalWithHistory, StoredSignal, SuspendType, ThrottledSignal, Transaction, TransactionRef, TransitionRef, TransitionScope, UntilOptions, Vivify, WindowSize, WindowSizeOptions, WindowSizeSignal, WithVivify, WritableSignalStore };
3253
+ export type { BatteryStatus, ClipboardSignal, Computation, CreateChunkedOptions, CreateDebouncedOptions, CreateHistoryOptions, CreatePooledOptions, CreateProvidedPooledOptions, CreateStoredOptions, CreateThrottledOptions, DebouncedSignal, DerivedSignal, ElementSize, ElementSizeOptions, ElementSizeSignal, ElementVisibilityOptions, ElementVisibilitySignal, ExtendStoreOptions, Fork, ForkStoreOptions, ForkStrategy, ForwardingTransitionScope, Frame, GeolocationOptions, GeolocationSignal, IdleOptions, IdleSignal, MousePositionOptions, MousePositionSignal, MutableSignal, MutableSignalStore, NetworkStatusSignal, Opaque, PausableOptions, PauseOption, PipeableSignal, PointerDragOptions, PointerDragSignal, PointerDragState, PointerModifiers, PointerPoint, ReconcileFn, RegisterOptions, ScreenOrientation, ScreenOrientationState, ScrollPosition, ScrollPositionOptions, ScrollPositionSignal, SensorRunOptions, SignalFromEventOptions, SignalStore, SignalWithHistory, StoreOptions, StoredSignal, SuspendType, ThrottledSignal, Transaction, TransactionRef, TransitionRef, TransitionScope, UntilOptions, Vivify, WindowSize, WindowSizeOptions, WindowSizeSignal, WithVivify, WritableSignalStore, toStoreOptions };