@mmstack/primitives 19.5.2 → 19.6.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.
@@ -25,6 +25,14 @@ export type PointerDragState = {
25
25
  modifiers: PointerModifiers;
26
26
  /** Mouse button that started the gesture (`-1` when idle). */
27
27
  button: number;
28
+ /** The pointing device: `'mouse' | 'touch' | 'pen'` (`''` when idle). */
29
+ pointerType: string;
30
+ /**
31
+ * The element the gesture started on: the `handleSelector` match when one is
32
+ * set (so a single delegated listener can tell which child started the drag),
33
+ * otherwise the listener's element. `null` when idle.
34
+ */
35
+ origin: HTMLElement | null;
28
36
  };
29
37
  export type PointerDragOptions = SensorRunOptions & {
30
38
  /**
@@ -37,12 +45,24 @@ export type PointerDragOptions = SensorRunOptions & {
37
45
  coordinateSpace?: 'client' | 'page';
38
46
  /** Pixels the pointer must travel before `active` flips true. @default 3 */
39
47
  activationThreshold?: number;
40
- /** Throttle (ms) for `current`/`delta` updates. @default 16 */
48
+ /**
49
+ * Throttle (ms) for `current`/`delta` updates. @default 16
50
+ *
51
+ * Note: a final sub-throttle move right before `pointerup` may not surface on
52
+ * the throttled view (it coalesces into the terminal idle). Logic that must act
53
+ * on the *exact* release position should read {@link PointerDragSignal.unthrottled}.
54
+ */
41
55
  throttle?: number;
42
56
  /** Only start when the pointerdown target matches this selector (delegated handles). */
43
57
  handleSelector?: string;
44
58
  /** Mouse buttons that may start a gesture. @default [0] (primary) */
45
59
  buttons?: number[];
60
+ /**
61
+ * Stop the `pointerdown` from propagating once this sensor claims it. Lets an
62
+ * inner sensor win over an outer one on the same element tree (e.g. a nested
63
+ * sortable inside another). @default false
64
+ */
65
+ stopPropagation?: boolean;
46
66
  };
47
67
  /** A gesture signal with an `unthrottled` view and an imperative `cancel()`. */
48
68
  export type PointerDragSignal = Signal<PointerDragState> & {
@@ -1,6 +1,5 @@
1
- import { type Injector } from '@angular/core';
2
- import { type Vivify } from '../util';
3
- import { type WritableSignalStore } from './store';
1
+ import { type toStoreOptions } from './store';
2
+ import type { WritableSignalStore } from './types';
4
3
  /**
5
4
  * A 3-way merge of a forked value against a changed base: given the common `ancestor` (the base
6
5
  * value the fork last diverged from), `mine` (the fork's current value), and `theirs` (the base
@@ -61,19 +60,10 @@ export type Fork<T> = {
61
60
  * leaves compare by value, so equal primitives are correctly seen as unchanged.
62
61
  */
63
62
  export declare function merge3<T>(ancestor: T, mine: T, theirs: T): T;
64
- export declare function forkStore<T extends Record<string, any>>(base: WritableSignalStore<T>, opt?: {
63
+ /**
64
+ * ForkStoreOptions, vivify/noUnionLeaves should remain the same & are automatically inherited, override carefully (advanced usecases)
65
+ */
66
+ export type ForkStoreOptions<T> = toStoreOptions & {
65
67
  strategy?: ForkStrategy<T>;
66
- injector?: Injector;
67
- /**
68
- * Store config for the FORK's store — NOT inherited from `base` (it's closed over inside
69
- * the base's `toStore` and can't be read back). If the base was created with these, pass
70
- * the same values or the fork's write semantics will differ:
71
- * - `vivify`: without it, a write through a `null`/`undefined` path is silently dropped on
72
- * the fork even though the base would have created the container. Match the base.
73
- * - `noUnionLeaves`: a perf promise; off just means the slower reactive leaf-probe. NOTE it
74
- * is a whole-store guarantee — a fork that flips a node's type (leaf↔substore) violates it,
75
- * and on `commit` the base receives the flipped value with stale cached leaf-ness.
76
- */
77
- vivify?: Vivify;
78
- noUnionLeaves?: boolean;
79
- }): Fork<T>;
68
+ };
69
+ export declare function forkStore<T extends Record<string, any>>(base: WritableSignalStore<T>, opt?: ForkStoreOptions<T>): Fork<T>;
@@ -1,7 +1,9 @@
1
- import { type Signal } from '@angular/core';
1
+ import { InjectionToken, type Signal } from '@angular/core';
2
2
  import { type SignalStore } from './types';
3
3
  export declare const IS_STORE: unique symbol;
4
4
  export declare const SCOPE_PARENT: unique symbol;
5
+ export declare const STORE_SHARED_GLOBALS: unique symbol;
6
+ export declare const STORE_SHARED_OPTIONS: unique symbol;
5
7
  /**
6
8
  * @internal Brand carrying a store's writability ('mutable' | 'writable' | 'readonly'), stamped
7
9
  * on every store proxy. Read by `extendStore` instead of re-deriving via `isWritableSignal`,
@@ -9,27 +11,22 @@ export declare const SCOPE_PARENT: unique symbol;
9
11
  */
10
12
  export declare const STORE_KIND: unique symbol;
11
13
  export type StoreKind = 'mutable' | 'writable' | 'readonly';
12
- /**
13
- * @internal Brand exposing the injector a store was built with, so `extendStore` inherits it the
14
- * same way `store.extend(...)` does (via closure) — no injection context needed at the call site.
15
- */
16
- export declare const STORE_INJECTOR: unique symbol;
17
14
  export declare const SIGNAL_FN_PROP: Set<string>;
18
15
  /**
19
16
  * @internal
20
- * Test-only handle on the proxy cache (deliberately NOT re-exported from the public barrel).
21
17
  * Maps a store's backing signal to its lazily-built child proxies, each held via a `WeakRef`.
22
18
  */
23
- export declare const PROXY_CACHE: WeakMap<object, Map<PropertyKey, WeakRef<Signal<any>>>>;
19
+ export type ProxyCache = WeakMap<object, Map<PropertyKey, WeakRef<Signal<any>>>>;
24
20
  /**
25
21
  * @internal
26
- * Test-only handle on the finalization registry (deliberately NOT re-exported from the public
27
- * barrel). Prunes a cache entry once its proxy is reclaimed by the GC.
22
+ * Prunes a cache entry once its proxy is reclaimed by the GC.
28
23
  */
29
- export declare const PROXY_CLEANUP: FinalizationRegistry<{
24
+ export type ProxyCleanupRegistry = FinalizationRegistry<{
30
25
  target: object;
31
26
  prop: PropertyKey;
32
27
  }>;
28
+ export declare const PROXY_CACHE_TOKEN: InjectionToken<ProxyCache>;
29
+ export declare const PROXY_CLEANUP_TOKEN: InjectionToken<ProxyCleanupRegistry>;
33
30
  /**
34
31
  * @internal
35
32
  * Validates whether a value is a Signal Store.
@@ -1,2 +1,6 @@
1
1
  export * from './fork-store';
2
- export { extendStore, isLeaf, isOpaque, isStore, mutableStore, opaque, store, toStore, type MutableSignalStore, type Opaque, type SignalStore, type WritableSignalStore, } from './store';
2
+ export { isStore } from './internals';
3
+ export { isLeaf } from './leaf';
4
+ export { isOpaque, opaque, type Opaque } from './opaque';
5
+ export { extendStore, mutableStore, store, toStore, type ExtendStoreOptions, type StoreOptions, type toStoreOptions, } from './store';
6
+ export type { MutableSignalStore, SignalStore, WritableSignalStore, } from './types';
@@ -1,17 +1,46 @@
1
1
  import { Injector, type CreateSignalOptions, type Signal, type WritableSignal } from '@angular/core';
2
2
  import { type MutableSignal } from '../mutable';
3
3
  import { type Vivify } from '../util';
4
+ import { STORE_SHARED_GLOBALS, type ProxyCache, type ProxyCleanupRegistry } from './internals';
4
5
  import { type AnyRecord, type MutableSignalStore, type SignalStore, type Simplify, type WritableSignalStore } from './types';
5
- export { isStore, PROXY_CACHE, PROXY_CLEANUP } from './internals';
6
- export { isLeaf, LEAF } from './leaf';
7
- export { isOpaque, OPAQUE, opaque, type Opaque, type UnwrapOpaque, } from './opaque';
8
- export { type MutableSignalStore, type SignalStore, type WritableSignalStore, } from './types';
9
- export declare function toStore<T extends AnyRecord>(source: MutableSignal<T>, injector?: Injector, vivify?: Vivify, noUnionLeaves?: boolean): MutableSignalStore<T>;
10
- export declare function toStore<T extends AnyRecord>(source: WritableSignal<T>, injector?: Injector, vivify?: Vivify, noUnionLeaves?: boolean): WritableSignalStore<T>;
11
- export declare function toStore<T extends AnyRecord>(source: Signal<T>, injector?: Injector, vivify?: Vivify, noUnionLeaves?: boolean): SignalStore<T>;
12
- export 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>>;
13
- export 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>>;
14
- export 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>>;
6
+ export type toStoreOptions = {
7
+ injector?: Injector;
8
+ /**
9
+ * Opt-in autovivification: when writing through a `null`/`undefined` path, create the
10
+ * missing intermediate containers instead of dropping the write. Off by default.
11
+ *
12
+ * Levels whose current value is a known object/array re-vivify as that same shape — the
13
+ * knowledge is captured when the path is first accessed and cached, so it holds even after
14
+ * the value is later nulled. This option governs only genuinely-unknown (currently
15
+ * `null`/`undefined`) levels: `'auto'` (an array for index keys, an object otherwise), an
16
+ * explicit `'object'`/`'array'`, or a `() => container` factory. See {@link Vivify}.
17
+ */
18
+ vivify?: Vivify;
19
+ /**
20
+ * Performance opt-in: promise that no node ever switches between leaf and substore (i.e. no
21
+ * unions mixing a primitive with an object/array). With this on, each node's leaf-ness is
22
+ * resolved once on the first {@link isLeaf} probe and cached as a constant, skipping the
23
+ * reactive `computed`. If a node's shape does change anyway, {@link isLeaf} keeps its first
24
+ * answer. Off by default.
25
+ */
26
+ noUnionLeaves?: boolean;
27
+ /**
28
+ * @internal
29
+ * Shared cleanup singletons, they get injected/passed automatically
30
+ */
31
+ [STORE_SHARED_GLOBALS]?: {
32
+ cache: ProxyCache;
33
+ registry: ProxyCleanupRegistry;
34
+ };
35
+ };
36
+ export type StoreOptions<T> = CreateSignalOptions<T> & toStoreOptions;
37
+ export declare function toStore<T extends AnyRecord>(source: MutableSignal<T>, options?: toStoreOptions): MutableSignalStore<T>;
38
+ export declare function toStore<T extends AnyRecord>(source: WritableSignal<T>, options?: toStoreOptions): WritableSignalStore<T>;
39
+ export declare function toStore<T extends AnyRecord>(source: Signal<T>, options?: toStoreOptions): SignalStore<T>;
40
+ export type ExtendStoreOptions = Omit<toStoreOptions, 'vivify' | 'noUnionLeaves' | typeof STORE_SHARED_GLOBALS>;
41
+ export 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>>;
42
+ export 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>>;
43
+ export 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>>;
15
44
  /**
16
45
  * Creates a WritableSignalStore from a value.
17
46
  * @see {@link toStore}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmstack/primitives",
3
- "version": "19.5.2",
3
+ "version": "19.6.0",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",