@mmstack/primitives 21.3.0 → 21.4.1

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.3.0",
3
+ "version": "21.4.1",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",
@@ -189,8 +189,9 @@ declare function providePaused(source: Signal<boolean>): Provider;
189
189
  declare function holdUntilReady<T>(target: Signal<T>, ready: () => boolean): Signal<T>;
190
190
 
191
191
  /**
192
- * Handle for an in-progress transition: a `pending` signal (true while the transition's
193
- * resources are in flight) and a `done` promise that resolves once they all settle.
192
+ * Handle for an in-progress transition: a `pending` signal (true while the transition's OWN
193
+ * resources are in flight loads already in flight when it started are not attributed) and a
194
+ * `done` promise that resolves once they all settle.
194
195
  */
195
196
  type TransitionRef = {
196
197
  readonly pending: Signal<boolean>;
@@ -292,6 +293,15 @@ declare function createForwardingScope(): ForwardingTransitionScope;
292
293
  declare function provideForwardingTransitionScope(): Provider;
293
294
  /** Read the transition scope reachable from `injector`, or null if none is provided there. */
294
295
  declare function getTransitionScope(injector: Injector): TransitionScope | null;
296
+ /**
297
+ * @internal Transaction-attributed pending for `startTransition`/`startTransaction`: like
298
+ * `scope.pending`, but loads already in flight when the tracker is created are NOT attributed —
299
+ * a pre-existing background load can neither settle the transaction early nor block its settle
300
+ * forever. A pre-existing flight is excluded only until it first settles; a later re-trigger of
301
+ * the same resource (e.g. the transaction's write changed its request) counts as the
302
+ * transaction's own work.
303
+ */
304
+ declare function createAttributedPending(scope: TransitionScope): Signal<boolean>;
295
305
  /**
296
306
  * Returns a register function bound to the nearest transition scope: it adds a resource
297
307
  * to the scope and removes it when the caller's injection context is destroyed. Pass any
@@ -342,8 +352,7 @@ declare class SuspenseBoundary extends SuspenseBoundaryBase {
342
352
  }
343
353
  /**
344
354
  * Unscoped suspense boundary — **reads the ambient scope** instead of providing one. For cases where
345
- * the resources to coordinate are registered *above* the boundary (e.g. an app-builder page whose
346
- * manifests/connectors register at a higher injector), so the boundary observes that outer scope
355
+ * the resources to coordinate are registered *above* the boundary so the boundary observes that outer scope
347
356
  * rather than opening a fresh one. Pair with a `provideTransitionScope()` (or another boundary) in an
348
357
  * ancestor.
349
358
  */
@@ -368,7 +377,8 @@ type Transaction = {
368
377
  declare function createTransaction(): Transaction;
369
378
  /** The transaction in effect right now, or `null`. Stateful actions consult this to record undo. */
370
379
  declare function activeTransaction(): Transaction | null;
371
- /** Handle for an in-progress transaction (Tier 3): the transition `pending`/`done`, plus `abort`. */
380
+ /** Handle for an in-progress transaction (Tier 3): the transaction's own `pending`/`done`
381
+ * (loads already in flight at start are not attributed to it), plus `abort`. */
372
382
  type TransactionRef = {
373
383
  readonly pending: Signal<boolean>;
374
384
  readonly done: Promise<void>;
@@ -393,6 +403,67 @@ type TransactionRef = {
393
403
  */
394
404
  declare function injectStartTransaction(): (fn: () => void) => TransactionRef;
395
405
 
406
+ type MmTransitionContext<T> = {
407
+ readonly $implicit: T;
408
+ readonly mmTransition: T;
409
+ };
410
+ /**
411
+ * Generic hold-and-swap: the non-router `TransitionRouterOutlet`. When the bound value changes,
412
+ * the OLD view stays mounted and visible (it keeps its old context value — that's the hold) while
413
+ * the NEW view mounts hidden with its **own transition scope**; resources created in the incoming
414
+ * subtree register into that scope just by existing, and once they've gone in flight and settled
415
+ * the views swap in one frame. Tabs, wizard steps, master-detail — any branch change that would
416
+ * otherwise flash a loading state.
417
+ *
418
+ * ```html
419
+ * <div *mmTransition="selectedTab(); let tab">
420
+ * @switch (tab) { ... }
421
+ * </div>
422
+ * ```
423
+ *
424
+ * Distinct from `<mm-suspense>` (the readiness gate): suspense decides placeholder-vs-content
425
+ * *within* one branch, but can't stop an `@switch` from unmounting the old branch the instant the
426
+ * value flips. This directive is the swap itself — the old branch survives until the new one is
427
+ * ready. Compose them freely: suspense inside a transitioned branch handles its first load.
428
+ *
429
+ * Semantics mirror the outlet: the first render is immediate (nothing to hold); an interrupting
430
+ * value change mid-hold destroys the half-ready hidden view and re-targets; a branch that loads
431
+ * nothing swaps right after its first render. Per-view scopes mean the outgoing branch's
432
+ * background work can never delay the swap. Set `mmTransitionImmediate` to skip holding, and
433
+ * `mmTransitionViewTransition` to wrap the swap in `document.startViewTransition` (feature
434
+ * detected). On the server every change swaps immediately.
435
+ */
436
+ declare class MmTransition<T> {
437
+ private readonly tpl;
438
+ private readonly vcr;
439
+ private readonly parent;
440
+ private readonly onServer;
441
+ /** The value whose changes are transitioned. Each view keeps the value it was created with. */
442
+ readonly value: i0.InputSignal<T>;
443
+ /** Skip holding entirely — every change swaps at once (the plain re-render behavior). */
444
+ readonly immediate: i0.InputSignal<boolean>;
445
+ /** Wrap the swap in the View Transitions API for an animated cross-fade (feature detected). */
446
+ readonly viewTransition: i0.InputSignal<boolean>;
447
+ private current;
448
+ private incoming;
449
+ /** Bumped on every re-target/teardown so a superseded (possibly deferred) swap can't commit. */
450
+ private swapEpoch;
451
+ private readonly holding;
452
+ /** True while an incoming view is mounted hidden, waiting to settle. */
453
+ readonly pending: Signal<boolean>;
454
+ static ngTemplateContextGuard<T>(dir: MmTransition<T>, ctx: unknown): ctx is MmTransitionContext<T>;
455
+ constructor();
456
+ private onValue;
457
+ private commitSwap;
458
+ /** The actual swap: destroy the old view, reveal the new one. Always instant. */
459
+ private finishSwap;
460
+ private dropIncoming;
461
+ private createView;
462
+ private setHidden;
463
+ static ɵfac: i0.ɵɵFactoryDeclaration<MmTransition<any>, never>;
464
+ static ɵdir: i0.ɵɵDirectiveDeclaration<MmTransition<any>, "[mmTransition]", ["mmTransition"], { "value": { "alias": "mmTransition"; "required": true; "isSignal": true; }; "immediate": { "alias": "mmTransitionImmediate"; "required": false; "isSignal": true; }; "viewTransition": { "alias": "mmTransitionViewTransition"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
465
+ }
466
+
396
467
  /**
397
468
  * Options for creating a debounced writable signal.
398
469
  * Extends Angular's `CreateSignalOptions` with a debounce time setting.
@@ -1945,6 +2016,13 @@ type PointerDragState = {
1945
2016
  * otherwise the listener's element. `null` when idle.
1946
2017
  */
1947
2018
  origin: HTMLElement | null;
2019
+ /**
2020
+ * Whether the LAST gesture ended by being aborted (`pointercancel` /
2021
+ * `lostpointercapture` / Escape / `cancel()`) rather than a normal `pointerup`.
2022
+ * Only meaningful on the idle transition — consumers ending a drag branch on it
2023
+ * to distinguish "drop here" from "abort". Sticky until the next `pointerdown`.
2024
+ */
2025
+ cancelled: boolean;
1948
2026
  };
1949
2027
  type PointerDragOptions = SensorRunOptions & {
1950
2028
  /**
@@ -3249,5 +3327,5 @@ type CreateHistoryOptions<T> = Omit<CreateSignalOptions<T[]>, 'equal'> & {
3249
3327
  */
3250
3328
  declare function withHistory<T>(sourceOrValue: WritableSignal<T> | T, opt?: CreateHistoryOptions<T>): SignalWithHistory<T>;
3251
3329
 
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 };
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 };
3330
+ export { MmActivity, MmTransition, PAUSABLE_OPTIONS, SuspenseBoundary, SuspenseBoundaryBase, UnscopedSuspenseBoundary, activeTransaction, batteryStatus, chunked, clipboard, combineWith, createAttributedPending, 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 };
3331
+ 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, MmTransitionContext, 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 };