@mmstack/primitives 22.3.0 → 22.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/README.md +38 -1
- package/fesm2022/mmstack-primitives.mjs +263 -44
- package/fesm2022/mmstack-primitives.mjs.map +1 -1
- package/package.json +1 -1
- package/types/mmstack-primitives.d.ts +85 -7
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ npm install @mmstack/primitives
|
|
|
19
19
|
- [Timing & propagation](#timing--propagation) — `debounced`, `throttled`, `until`
|
|
20
20
|
- [Reactive collections](#reactive-collections) — `indexArray`, `keyArray`, `mapObject`
|
|
21
21
|
- [Effects](#effects) — `nestedEffect`
|
|
22
|
-
- [Concurrency & transitions](#concurrency--transitions) — `keepPrevious`, keep-alive (`MmActivity`), `pausable*` / `providePausableOptions`, Suspense (`mm-suspense`), `startTransition` / `startTransaction`, `holdUntilReady`
|
|
22
|
+
- [Concurrency & transitions](#concurrency--transitions) — `keepPrevious`, keep-alive (`MmActivity`), `pausable*` / `providePausableOptions`, Suspense (`mm-suspense`), hold-and-swap (`*mmTransition`), `startTransition` / `startTransaction`, `holdUntilReady`
|
|
23
23
|
- [History & persistence](#history--persistence) — `withHistory`, `stored`, `tabSync`
|
|
24
24
|
- [Performance helpers](#performance-helpers) — `chunked`, `pooled` / `pooledArray` / `pooledMap` / `pooledSet`
|
|
25
25
|
- [Sensors](#sensors) — `sensor()` facade + browser-state signals
|
|
@@ -119,6 +119,10 @@ Top-level array support isn't exposed yet — use `indexArray` / `keyArray` for
|
|
|
119
119
|
|
|
120
120
|
**Union leaves (perf opt-in).** `noUnionLeaves: true` promises no node ever flips between a leaf and a sub-store, so each node's leaf-ness is resolved once on first access and cached instead of staying reactive. Off by default — leave it off if a value can switch between a primitive and an object/array.
|
|
121
121
|
|
|
122
|
+
**Unions are fully supported by default.** A node may flip between array ↔ record ↔ primitive ↔ `null` freely: routing (`keys`/iteration/prototype) follows the live kind, and a child signal you grabbed **before** a flip stays correct after it — reads resolve against the new shape (`undefined` through a `null` parent, no throw) and writes copy by the container's live shape, so writing through a pre-flip child never turns an array into a plain object.
|
|
123
|
+
|
|
124
|
+
> Reserved keys: `set`, `update`, `mutate`, `inline`, `asReadonly` (and `extend`, until its removal next minor) resolve to the signal's own methods, so record keys with those names aren't reachable as child stores — read them off the value (`s().set`) instead.
|
|
125
|
+
|
|
122
126
|
### `extendStore` (scoped overlay)
|
|
123
127
|
|
|
124
128
|
`extendStore(store, seed)` (on any store kind) creates a **scoped overlay** — a child store that **shares** the parent's signals for inherited keys (the same `WritableSignal`: writes go through to the parent and parent changes flow down) while keeping the seed and any new keys in a **local layer** that never propagates upward. No diffing, no syncing — local keys simply aren't wired to the parent.
|
|
@@ -437,6 +441,25 @@ This is also the pattern for coordinating resources registered _above_ a boundar
|
|
|
437
441
|
|
|
438
442
|
**Forwarding scope (advanced).** `provideForwardingTransitionScope()` provides a scope that can be **re-pointed at a different target at runtime** via `setTarget(scope | null)` — reads follow the current target, while `add`/`remove` pin to the target a resource was registered under (so re-pointing never strands a registration). It's the building block for a coordinator that hosts several independent sub-scopes and switches which one it observes — e.g. a router outlet that, per navigation, points at the incoming route's own scope (read it from any injector with `getTransitionScope(injector)`). Most apps reach for `provideTransitionScope()`; this is for that one extra level of control.
|
|
439
443
|
|
|
444
|
+
### Hold-and-swap — `*mmTransition`
|
|
445
|
+
|
|
446
|
+
The transition itself, for any branch change — tabs, wizard steps, master-detail. Suspense decides placeholder-vs-content _within_ a branch, but it can't stop an `@switch` from unmounting the old branch the instant the value flips. `*mmTransition` holds it: when the bound value changes, the **old view stays mounted and visible** (keeping its old value) while the **new view mounts hidden with its own transition scope**; resources created in the incoming subtree register there just by existing, and once they've gone in flight and settled the views swap in one frame.
|
|
447
|
+
|
|
448
|
+
```html
|
|
449
|
+
<div *mmTransition="selectedTab(); let tab">
|
|
450
|
+
@switch (tab) {
|
|
451
|
+
@case ('overview') {
|
|
452
|
+
<overview-pane />
|
|
453
|
+
}
|
|
454
|
+
@case ('activity') {
|
|
455
|
+
<activity-pane />
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
</div>
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
The first render is immediate (nothing to hold). An interrupting change mid-hold destroys the half-ready hidden view and re-targets — the stable view stays visible until the newest branch settles. A branch that loads nothing swaps right after its first render, and per-view scopes mean the outgoing branch's background work can never delay the swap. `immediate: true` skips holding; `viewTransition: true` wraps the swap in `document.startViewTransition` (feature detected). This is `@mmstack/router-core`'s `<mm-transition-outlet>` without the router — same semantics, any signal as the trigger.
|
|
462
|
+
|
|
440
463
|
### `injectStartTransition`
|
|
441
464
|
|
|
442
465
|
The analog of React's `useTransition`. `startTransition(fn)` runs your state mutations (which commit immediately); any resource that reloads as a result **holds its value and reveals together once everything settles** — so a multi-resource update lands as one consistent frame instead of a torn mix of new and stale. The returned handle gives you a unified `pending` signal and a `done` promise for imperative coordination (disable a button, await completion).
|
|
@@ -461,6 +484,15 @@ const t = startTransaction(() => applyBulkEdit()); // live state updates; the di
|
|
|
461
484
|
await t.done; // committed, display revealed in one frame
|
|
462
485
|
```
|
|
463
486
|
|
|
487
|
+
Every exit settles: a throwing body rolls back, and if the calling context is **destroyed
|
|
488
|
+
mid-flight** the hold is released (writes kept) and `done` resolves — a transaction can never
|
|
489
|
+
leave a surviving ancestor scope frozen.
|
|
490
|
+
|
|
491
|
+
Attribution is **per transaction**: a load already in flight when it starts is not adopted —
|
|
492
|
+
it can neither commit the transaction early nor block its settle. (The same applies to
|
|
493
|
+
`startTransition`.) A pre-existing flight re-triggered by the transaction's own writes counts
|
|
494
|
+
once it restarts.
|
|
495
|
+
|
|
464
496
|
### `holdUntilReady`
|
|
465
497
|
|
|
466
498
|
The **structural** counterpart to `keepPrevious`: where that holds a _value_ through a reload, this holds a _structure_ through a swap. Given a `target` signal and a `ready` predicate, it keeps yielding the previous value until `ready()` is true, then swaps to the current target. Mount the incoming structure off to the side so its resources can settle and flip `ready`, keep showing the held one meanwhile, and let the old one go once `ready` releases the swap. (`@mmstack/router-core`'s `<mm-transition-outlet>` is this pattern applied to routes.)
|
|
@@ -677,6 +709,11 @@ outer one on the same tree (e.g. a nested sortable). Reads are throttled
|
|
|
677
709
|
(`throttle`, default 16ms); `drag.unthrottled()` exposes the un-throttled view
|
|
678
710
|
for logic that needs the exact release position.
|
|
679
711
|
|
|
712
|
+
The idle state carries the **end reason**: `cancelled` is `true` when the gesture
|
|
713
|
+
was aborted (Escape, `pointercancel`, `.cancel()`) rather than released, and stays
|
|
714
|
+
set until the next `pointerdown` — so a drag consumer can tell "drop here" from
|
|
715
|
+
"abort" (`@mmstack/dnd` uses this to cancel instead of committing).
|
|
716
|
+
|
|
680
717
|
```typescript
|
|
681
718
|
import { sensor } from '@mmstack/primitives';
|
|
682
719
|
|
|
@@ -633,6 +633,38 @@ function provideForwardingTransitionScope() {
|
|
|
633
633
|
function getTransitionScope(injector) {
|
|
634
634
|
return injector.get(TRANSITION_SCOPE, null);
|
|
635
635
|
}
|
|
636
|
+
/**
|
|
637
|
+
* @internal Transaction-attributed pending for `startTransition`/`startTransaction`: like
|
|
638
|
+
* `scope.pending`, but loads already in flight when the tracker is created are NOT attributed —
|
|
639
|
+
* a pre-existing background load can neither settle the transaction early nor block its settle
|
|
640
|
+
* forever. A pre-existing flight is excluded only until it first settles; a later re-trigger of
|
|
641
|
+
* the same resource (e.g. the transaction's write changed its request) counts as the
|
|
642
|
+
* transaction's own work.
|
|
643
|
+
*/
|
|
644
|
+
function createAttributedPending(scope) {
|
|
645
|
+
const isInFlight = (ref) => {
|
|
646
|
+
const s = untracked(ref.status);
|
|
647
|
+
return s === 'loading' || s === 'reloading';
|
|
648
|
+
};
|
|
649
|
+
const preexisting = new Set(untracked(scope.resources).filter(isInFlight));
|
|
650
|
+
return computed(() => {
|
|
651
|
+
let pending = false;
|
|
652
|
+
for (const ref of scope.resources()) {
|
|
653
|
+
const s = ref.status();
|
|
654
|
+
const loading = s === 'loading' || s === 'reloading';
|
|
655
|
+
if (preexisting.has(ref)) {
|
|
656
|
+
// deletes are monotonic, so this stays sound under re-computation
|
|
657
|
+
if (loading)
|
|
658
|
+
continue;
|
|
659
|
+
preexisting.delete(ref);
|
|
660
|
+
continue;
|
|
661
|
+
}
|
|
662
|
+
if (loading)
|
|
663
|
+
pending = true;
|
|
664
|
+
}
|
|
665
|
+
return pending;
|
|
666
|
+
});
|
|
667
|
+
}
|
|
636
668
|
/**
|
|
637
669
|
* Returns a register function bound to the nearest transition scope: it adds a resource
|
|
638
670
|
* to the scope and removes it when the caller's injection context is destroyed. Pass any
|
|
@@ -670,38 +702,43 @@ function registerResource(res, opt) {
|
|
|
670
702
|
function injectStartTransition() {
|
|
671
703
|
const scope = injectTransitionScope();
|
|
672
704
|
const injector = inject(Injector);
|
|
705
|
+
const destroyRef = inject(DestroyRef);
|
|
673
706
|
const onServer = isPlatformServer(inject(PLATFORM_ID, { optional: true }) ?? 'browser');
|
|
674
707
|
return (fn) => {
|
|
708
|
+
// attributed: loads already in flight when the transition starts are not ours —
|
|
709
|
+
// they can neither settle this transition early nor block it forever
|
|
710
|
+
const pending = createAttributedPending(scope);
|
|
675
711
|
untracked(fn);
|
|
676
712
|
let sawPending = false;
|
|
677
713
|
const done = new Promise((resolve) => {
|
|
714
|
+
const settle = () => {
|
|
715
|
+
releaseDestroy();
|
|
716
|
+
watcher.destroy();
|
|
717
|
+
resolve();
|
|
718
|
+
};
|
|
678
719
|
const watcher = effect(() => {
|
|
679
|
-
const p =
|
|
720
|
+
const p = pending();
|
|
680
721
|
if (p)
|
|
681
722
|
sawPending = true;
|
|
682
723
|
// settle: requests went in flight and then drained
|
|
683
|
-
if (sawPending && !p)
|
|
684
|
-
|
|
685
|
-
resolve();
|
|
686
|
-
}
|
|
724
|
+
if (sawPending && !p)
|
|
725
|
+
settle();
|
|
687
726
|
}, { ...(ngDevMode ? { debugName: "watcher" } : /* istanbul ignore next */ {}), injector });
|
|
727
|
+
// a destroy mid-flight kills the watcher — resolve so awaiters never hang
|
|
728
|
+
const releaseDestroy = destroyRef.onDestroy(settle);
|
|
688
729
|
if (onServer) {
|
|
689
|
-
if (!untracked(
|
|
690
|
-
|
|
691
|
-
resolve();
|
|
692
|
-
}
|
|
730
|
+
if (!untracked(pending))
|
|
731
|
+
settle();
|
|
693
732
|
return;
|
|
694
733
|
}
|
|
695
734
|
// no-async fallback: once the reactive system has processed the writes (afterNextRender),
|
|
696
735
|
// if nothing ever went in flight, the transition is already complete.
|
|
697
736
|
afterNextRender(() => {
|
|
698
|
-
if (!sawPending && !untracked(
|
|
699
|
-
|
|
700
|
-
resolve();
|
|
701
|
-
}
|
|
737
|
+
if (!sawPending && !untracked(pending))
|
|
738
|
+
settle();
|
|
702
739
|
}, { injector });
|
|
703
740
|
});
|
|
704
|
-
return { pending
|
|
741
|
+
return { pending, done };
|
|
705
742
|
};
|
|
706
743
|
}
|
|
707
744
|
|
|
@@ -774,8 +811,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImpor
|
|
|
774
811
|
}] });
|
|
775
812
|
/**
|
|
776
813
|
* Unscoped suspense boundary — **reads the ambient scope** instead of providing one. For cases where
|
|
777
|
-
* the resources to coordinate are registered *above* the boundary
|
|
778
|
-
* manifests/connectors register at a higher injector), so the boundary observes that outer scope
|
|
814
|
+
* the resources to coordinate are registered *above* the boundary so the boundary observes that outer scope
|
|
779
815
|
* rather than opening a fresh one. Pair with a `provideTransitionScope()` (or another boundary) in an
|
|
780
816
|
* ancestor.
|
|
781
817
|
*/
|
|
@@ -840,9 +876,13 @@ function runInTransaction(txn, fn) {
|
|
|
840
876
|
function injectStartTransaction() {
|
|
841
877
|
const scope = injectTransitionScope();
|
|
842
878
|
const injector = inject(Injector);
|
|
879
|
+
const destroyRef = inject(DestroyRef);
|
|
843
880
|
const onServer = isPlatformServer(inject(PLATFORM_ID, { optional: true }) ?? 'browser');
|
|
844
881
|
return (fn) => {
|
|
845
882
|
const txn = createTransaction();
|
|
883
|
+
// attributed: loads already in flight when the transaction starts are not ours —
|
|
884
|
+
// they can neither commit this transaction early nor block its settle forever
|
|
885
|
+
const pending = createAttributedPending(scope);
|
|
846
886
|
// Hold BEFORE the writes, so the display freezes at pre-transaction values.
|
|
847
887
|
scope.beginHold();
|
|
848
888
|
let finished = false;
|
|
@@ -859,6 +899,7 @@ function injectStartTransaction() {
|
|
|
859
899
|
if (finished)
|
|
860
900
|
return;
|
|
861
901
|
finished = true;
|
|
902
|
+
releaseDestroy();
|
|
862
903
|
watcher?.destroy();
|
|
863
904
|
if (restore)
|
|
864
905
|
txn.restore();
|
|
@@ -867,6 +908,10 @@ function injectStartTransaction() {
|
|
|
867
908
|
scope.endHold();
|
|
868
909
|
resolveDone();
|
|
869
910
|
};
|
|
911
|
+
// The scope may outlive the calling context (a component transacting on an ancestor
|
|
912
|
+
// boundary): a destroy mid-flight kills the settle watcher, so without this the hold
|
|
913
|
+
// would leak and freeze the surviving scope forever. Keep the writes — they landed live.
|
|
914
|
+
const releaseDestroy = destroyRef.onDestroy(() => finish(false));
|
|
870
915
|
try {
|
|
871
916
|
runInTransaction(txn, fn);
|
|
872
917
|
}
|
|
@@ -876,31 +921,194 @@ function injectStartTransaction() {
|
|
|
876
921
|
}
|
|
877
922
|
let sawPending = false;
|
|
878
923
|
watcher = effect(() => {
|
|
879
|
-
const p =
|
|
924
|
+
const p = pending();
|
|
880
925
|
if (p)
|
|
881
926
|
sawPending = true;
|
|
882
927
|
if (sawPending && !p)
|
|
883
928
|
finish(false);
|
|
884
929
|
}, { injector });
|
|
885
930
|
if (onServer) {
|
|
886
|
-
if (!untracked(
|
|
931
|
+
if (!untracked(pending))
|
|
887
932
|
finish(false);
|
|
888
933
|
}
|
|
889
934
|
else {
|
|
890
935
|
// no-async fallback: if nothing ever went in flight, settle once the writes are processed.
|
|
891
936
|
afterNextRender(() => {
|
|
892
|
-
if (!sawPending && !untracked(
|
|
937
|
+
if (!sawPending && !untracked(pending))
|
|
893
938
|
finish(false);
|
|
894
939
|
}, { injector });
|
|
895
940
|
}
|
|
896
941
|
return {
|
|
897
|
-
pending
|
|
942
|
+
pending,
|
|
898
943
|
done,
|
|
899
944
|
abort: () => finish(true),
|
|
900
945
|
};
|
|
901
946
|
};
|
|
902
947
|
}
|
|
903
948
|
|
|
949
|
+
/**
|
|
950
|
+
* Generic hold-and-swap: the non-router `TransitionRouterOutlet`. When the bound value changes,
|
|
951
|
+
* the OLD view stays mounted and visible (it keeps its old context value — that's the hold) while
|
|
952
|
+
* the NEW view mounts hidden with its **own transition scope**; resources created in the incoming
|
|
953
|
+
* subtree register into that scope just by existing, and once they've gone in flight and settled
|
|
954
|
+
* the views swap in one frame. Tabs, wizard steps, master-detail — any branch change that would
|
|
955
|
+
* otherwise flash a loading state.
|
|
956
|
+
*
|
|
957
|
+
* ```html
|
|
958
|
+
* <div *mmTransition="selectedTab(); let tab">
|
|
959
|
+
* @switch (tab) { ... }
|
|
960
|
+
* </div>
|
|
961
|
+
* ```
|
|
962
|
+
*
|
|
963
|
+
* Distinct from `<mm-suspense>` (the readiness gate): suspense decides placeholder-vs-content
|
|
964
|
+
* *within* one branch, but can't stop an `@switch` from unmounting the old branch the instant the
|
|
965
|
+
* value flips. This directive is the swap itself — the old branch survives until the new one is
|
|
966
|
+
* ready. Compose them freely: suspense inside a transitioned branch handles its first load.
|
|
967
|
+
*
|
|
968
|
+
* Semantics mirror the outlet: the first render is immediate (nothing to hold); an interrupting
|
|
969
|
+
* value change mid-hold destroys the half-ready hidden view and re-targets; a branch that loads
|
|
970
|
+
* nothing swaps right after its first render. Per-view scopes mean the outgoing branch's
|
|
971
|
+
* background work can never delay the swap. Set `mmTransitionImmediate` to skip holding, and
|
|
972
|
+
* `mmTransitionViewTransition` to wrap the swap in `document.startViewTransition` (feature
|
|
973
|
+
* detected). On the server every change swaps immediately.
|
|
974
|
+
*/
|
|
975
|
+
class MmTransition {
|
|
976
|
+
tpl = inject(TemplateRef);
|
|
977
|
+
vcr = inject(ViewContainerRef);
|
|
978
|
+
parent = inject(Injector);
|
|
979
|
+
onServer = isPlatformServer(inject(PLATFORM_ID, { optional: true }) ?? 'browser');
|
|
980
|
+
/** The value whose changes are transitioned. Each view keeps the value it was created with. */
|
|
981
|
+
value = input.required({ ...(ngDevMode ? { debugName: "value" } : /* istanbul ignore next */ {}), alias: 'mmTransition' });
|
|
982
|
+
/** Skip holding entirely — every change swaps at once (the plain re-render behavior). */
|
|
983
|
+
immediate = input(false, { ...(ngDevMode ? { debugName: "immediate" } : /* istanbul ignore next */ {}), alias: 'mmTransitionImmediate' });
|
|
984
|
+
/** Wrap the swap in the View Transitions API for an animated cross-fade (feature detected). */
|
|
985
|
+
viewTransition = input(false, { ...(ngDevMode ? { debugName: "viewTransition" } : /* istanbul ignore next */ {}), alias: 'mmTransitionViewTransition' });
|
|
986
|
+
current = null;
|
|
987
|
+
incoming = null;
|
|
988
|
+
/** Bumped on every re-target/teardown so a superseded (possibly deferred) swap can't commit. */
|
|
989
|
+
swapEpoch = 0;
|
|
990
|
+
holding = signal(false, /* @ts-ignore */
|
|
991
|
+
...(ngDevMode ? [{ debugName: "holding" }] : /* istanbul ignore next */ []));
|
|
992
|
+
/** True while an incoming view is mounted hidden, waiting to settle. */
|
|
993
|
+
pending = this.holding.asReadonly();
|
|
994
|
+
static ngTemplateContextGuard(dir,
|
|
995
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
996
|
+
ctx) {
|
|
997
|
+
return true;
|
|
998
|
+
}
|
|
999
|
+
constructor() {
|
|
1000
|
+
effect(() => {
|
|
1001
|
+
const v = this.value();
|
|
1002
|
+
untracked(() => this.onValue(v));
|
|
1003
|
+
});
|
|
1004
|
+
inject(DestroyRef).onDestroy(() => {
|
|
1005
|
+
this.swapEpoch++; // a deferred view-transition callback must not touch destroyed state
|
|
1006
|
+
this.dropIncoming();
|
|
1007
|
+
// `current` is destroyed with the container
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
onValue(v) {
|
|
1011
|
+
if (!this.current) {
|
|
1012
|
+
// first render: nothing to hold yet — show immediately (also what SSR serializes)
|
|
1013
|
+
this.current = this.createView(v).view;
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
this.dropIncoming(); // an interrupting change supersedes the previous hold
|
|
1017
|
+
this.swapEpoch++;
|
|
1018
|
+
const epoch = this.swapEpoch;
|
|
1019
|
+
if (this.onServer || this.immediate()) {
|
|
1020
|
+
this.finishSwap(epoch, this.createView(v).view);
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
const { view, scope } = this.createView(v);
|
|
1024
|
+
this.setHidden(view, true);
|
|
1025
|
+
this.holding.set(true);
|
|
1026
|
+
// Registration happens synchronously during view creation, so a resource already in
|
|
1027
|
+
// flight counts from the start; later kickoffs are caught by the watcher.
|
|
1028
|
+
let sawPending = untracked(scope.pending);
|
|
1029
|
+
const watcher = effect(() => {
|
|
1030
|
+
const pending = scope.pending();
|
|
1031
|
+
untracked(() => {
|
|
1032
|
+
if (epoch !== this.swapEpoch)
|
|
1033
|
+
return;
|
|
1034
|
+
if (pending)
|
|
1035
|
+
sawPending = true;
|
|
1036
|
+
if (sawPending && !pending)
|
|
1037
|
+
this.commitSwap(epoch, view);
|
|
1038
|
+
});
|
|
1039
|
+
}, { ...(ngDevMode ? { debugName: "watcher" } : /* istanbul ignore next */ {}), injector: this.parent });
|
|
1040
|
+
this.incoming = { view, watcher };
|
|
1041
|
+
// Fallback for a branch that loads nothing.
|
|
1042
|
+
afterNextRender(() => {
|
|
1043
|
+
if (epoch === this.swapEpoch &&
|
|
1044
|
+
!sawPending &&
|
|
1045
|
+
!untracked(scope.pending)) {
|
|
1046
|
+
this.commitSwap(epoch, view);
|
|
1047
|
+
}
|
|
1048
|
+
}, { injector: this.parent });
|
|
1049
|
+
}
|
|
1050
|
+
commitSwap(epoch, view) {
|
|
1051
|
+
if (epoch !== this.swapEpoch)
|
|
1052
|
+
return;
|
|
1053
|
+
if (this.viewTransition() &&
|
|
1054
|
+
typeof document !== 'undefined' &&
|
|
1055
|
+
document.startViewTransition) {
|
|
1056
|
+
// the browser snapshots the old frame first; the epoch guard covers the deferral
|
|
1057
|
+
document.startViewTransition(() => this.finishSwap(epoch, view));
|
|
1058
|
+
}
|
|
1059
|
+
else {
|
|
1060
|
+
this.finishSwap(epoch, view);
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
/** The actual swap: destroy the old view, reveal the new one. Always instant. */
|
|
1064
|
+
finishSwap(epoch, view) {
|
|
1065
|
+
if (epoch !== this.swapEpoch)
|
|
1066
|
+
return; // superseded while deferred — not ours to commit
|
|
1067
|
+
this.swapEpoch++; // consume: the watcher and the render fallback can both fire, one commits
|
|
1068
|
+
this.current?.destroy();
|
|
1069
|
+
this.setHidden(view, false);
|
|
1070
|
+
this.current = view;
|
|
1071
|
+
this.incoming?.watcher.destroy();
|
|
1072
|
+
this.incoming = null;
|
|
1073
|
+
this.holding.set(false);
|
|
1074
|
+
}
|
|
1075
|
+
dropIncoming() {
|
|
1076
|
+
if (!this.incoming)
|
|
1077
|
+
return;
|
|
1078
|
+
this.incoming.watcher.destroy();
|
|
1079
|
+
this.incoming.view.destroy();
|
|
1080
|
+
this.incoming = null;
|
|
1081
|
+
this.holding.set(false);
|
|
1082
|
+
}
|
|
1083
|
+
createView(v) {
|
|
1084
|
+
// Each view gets its own scope, so its subtree's resources register here by existing —
|
|
1085
|
+
// and the outgoing view's background work can't block the swap (per-view isolation).
|
|
1086
|
+
const injector = Injector.create({
|
|
1087
|
+
parent: this.parent,
|
|
1088
|
+
providers: [provideTransitionScope()],
|
|
1089
|
+
});
|
|
1090
|
+
const scope = getTransitionScope(injector);
|
|
1091
|
+
const view = this.vcr.createEmbeddedView(this.tpl, { $implicit: v, mmTransition: v }, { injector });
|
|
1092
|
+
return { view, scope };
|
|
1093
|
+
}
|
|
1094
|
+
setHidden(view, hidden) {
|
|
1095
|
+
for (const node of view.rootNodes) {
|
|
1096
|
+
// covers HTML and SVG roots; text/comment roots can't be styled — prefer an element root
|
|
1097
|
+
if (node instanceof HTMLElement || node instanceof SVGElement)
|
|
1098
|
+
node.style.display = hidden ? 'none' : '';
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: MmTransition, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1102
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.0.2", type: MmTransition, isStandalone: true, selector: "[mmTransition]", inputs: { value: { classPropertyName: "value", publicName: "mmTransition", isSignal: true, isRequired: true, transformFunction: null }, immediate: { classPropertyName: "immediate", publicName: "mmTransitionImmediate", isSignal: true, isRequired: false, transformFunction: null }, viewTransition: { classPropertyName: "viewTransition", publicName: "mmTransitionViewTransition", isSignal: true, isRequired: false, transformFunction: null } }, exportAs: ["mmTransition"], ngImport: i0 });
|
|
1103
|
+
}
|
|
1104
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImport: i0, type: MmTransition, decorators: [{
|
|
1105
|
+
type: Directive,
|
|
1106
|
+
args: [{
|
|
1107
|
+
selector: '[mmTransition]',
|
|
1108
|
+
exportAs: 'mmTransition',
|
|
1109
|
+
}]
|
|
1110
|
+
}], ctorParameters: () => [], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "mmTransition", required: true }] }], immediate: [{ type: i0.Input, args: [{ isSignal: true, alias: "mmTransitionImmediate", required: false }] }], viewTransition: [{ type: i0.Input, args: [{ isSignal: true, alias: "mmTransitionViewTransition", required: false }] }] } });
|
|
1111
|
+
|
|
904
1112
|
/**
|
|
905
1113
|
* @internal
|
|
906
1114
|
*/
|
|
@@ -2921,9 +3129,13 @@ const IDLE = {
|
|
|
2921
3129
|
button: -1,
|
|
2922
3130
|
pointerType: '',
|
|
2923
3131
|
origin: null,
|
|
3132
|
+
cancelled: false,
|
|
2924
3133
|
};
|
|
3134
|
+
/** Terminal state of an aborted gesture — same idle shape, `cancelled: true`. */
|
|
3135
|
+
const CANCELLED = { ...IDLE, cancelled: true };
|
|
2925
3136
|
function stateEqual(a, b) {
|
|
2926
3137
|
return (a.active === b.active &&
|
|
3138
|
+
a.cancelled === b.cancelled &&
|
|
2927
3139
|
a.pointerId === b.pointerId &&
|
|
2928
3140
|
a.current.x === b.current.x &&
|
|
2929
3141
|
a.current.y === b.current.y &&
|
|
@@ -3001,7 +3213,7 @@ function createPointerDrag(opt) {
|
|
|
3001
3213
|
ctrl: e.ctrlKey,
|
|
3002
3214
|
meta: e.metaKey,
|
|
3003
3215
|
});
|
|
3004
|
-
const end = () => {
|
|
3216
|
+
const end = (cancelled = false) => {
|
|
3005
3217
|
gesture?.abort();
|
|
3006
3218
|
gesture = null;
|
|
3007
3219
|
activePointerId = null;
|
|
@@ -3009,8 +3221,8 @@ function createPointerDrag(opt) {
|
|
|
3009
3221
|
activePointerType = '';
|
|
3010
3222
|
activeOrigin = null;
|
|
3011
3223
|
activated = false;
|
|
3012
|
-
state.set(IDLE);
|
|
3013
|
-
state.flush(); // terminal transition: reflect
|
|
3224
|
+
state.set(cancelled ? CANCELLED : IDLE);
|
|
3225
|
+
state.flush(); // terminal transition: reflect idle now, not on the trailing edge
|
|
3014
3226
|
};
|
|
3015
3227
|
const onMove = (e) => {
|
|
3016
3228
|
if (e.pointerId !== activePointerId)
|
|
@@ -3030,6 +3242,7 @@ function createPointerDrag(opt) {
|
|
|
3030
3242
|
button: activeButton, // pointermove button is -1; keep the down-button
|
|
3031
3243
|
pointerType: activePointerType,
|
|
3032
3244
|
origin: activeOrigin,
|
|
3245
|
+
cancelled: false,
|
|
3033
3246
|
});
|
|
3034
3247
|
};
|
|
3035
3248
|
const onUp = (e) => {
|
|
@@ -3038,11 +3251,11 @@ function createPointerDrag(opt) {
|
|
|
3038
3251
|
};
|
|
3039
3252
|
const onCancel = (e) => {
|
|
3040
3253
|
if (e.pointerId === activePointerId)
|
|
3041
|
-
end();
|
|
3254
|
+
end(true);
|
|
3042
3255
|
};
|
|
3043
3256
|
const onKey = (e) => {
|
|
3044
3257
|
if (e.key === 'Escape' && activePointerId !== null)
|
|
3045
|
-
end();
|
|
3258
|
+
end(true);
|
|
3046
3259
|
};
|
|
3047
3260
|
const onDown = (el) => (e) => {
|
|
3048
3261
|
if (activePointerId !== null)
|
|
@@ -3087,6 +3300,7 @@ function createPointerDrag(opt) {
|
|
|
3087
3300
|
button: e.button,
|
|
3088
3301
|
pointerType: activePointerType,
|
|
3089
3302
|
origin: activeOrigin,
|
|
3303
|
+
cancelled: false,
|
|
3090
3304
|
});
|
|
3091
3305
|
};
|
|
3092
3306
|
const attach = (el) => {
|
|
@@ -3096,7 +3310,7 @@ function createPointerDrag(opt) {
|
|
|
3096
3310
|
});
|
|
3097
3311
|
return () => {
|
|
3098
3312
|
controller.abort();
|
|
3099
|
-
end();
|
|
3313
|
+
end(true); // teardown mid-gesture is an abort, not a drop
|
|
3100
3314
|
};
|
|
3101
3315
|
};
|
|
3102
3316
|
if (isSignal(target)) {
|
|
@@ -3114,7 +3328,7 @@ function createPointerDrag(opt) {
|
|
|
3114
3328
|
}
|
|
3115
3329
|
const base = state.asReadonly();
|
|
3116
3330
|
base.unthrottled = state.original;
|
|
3117
|
-
base.cancel = end;
|
|
3331
|
+
base.cancel = () => end(true);
|
|
3118
3332
|
return base;
|
|
3119
3333
|
}
|
|
3120
3334
|
|
|
@@ -3710,30 +3924,35 @@ function getCachedChild(target, prop, build, cache, cleanupRegistry) {
|
|
|
3710
3924
|
cleanupRegistry.register(proxy, { target, prop }, ref);
|
|
3711
3925
|
return proxy;
|
|
3712
3926
|
}
|
|
3927
|
+
/**
|
|
3928
|
+
* @internal Whether a mutable parent's child value must always re-notify: in-place mutation
|
|
3929
|
+
* keeps an object child's reference stable, so `Object.is` would swallow the change. Decided
|
|
3930
|
+
* per-VALUE (not snapshotted at build) so a union child that becomes an object later still
|
|
3931
|
+
* propagates parent-level mutations.
|
|
3932
|
+
*/
|
|
3933
|
+
function mutableChildEqual(a, b) {
|
|
3934
|
+
if (typeof a === 'object' && a !== null)
|
|
3935
|
+
return false;
|
|
3936
|
+
return Object.is(a, b);
|
|
3937
|
+
}
|
|
3713
3938
|
/**
|
|
3714
3939
|
* @internal Builds the derived child signal for `prop` and wraps it as an array/object substore.
|
|
3715
|
-
*
|
|
3716
|
-
*
|
|
3717
|
-
* is constructed.
|
|
3940
|
+
* Both the read (`v?.[prop]`) and the write (`createFallbackOnChange` copies by the container's
|
|
3941
|
+
* LIVE shape) are shape-adaptive, so a child cached before an array↔record↔null union flip stays
|
|
3942
|
+
* correct after it. The only place a child node is constructed — shared by every container kind.
|
|
3718
3943
|
*/
|
|
3719
3944
|
function buildChildNode(target, prop, isMutableSource, options) {
|
|
3720
3945
|
const value = untracked(target);
|
|
3721
|
-
const valueIsRecord = isRecord(value);
|
|
3722
|
-
const valueIsArray = Array.isArray(value);
|
|
3723
3946
|
const nodeVivify = resolveVivify(value, options.vivify);
|
|
3724
3947
|
const vivifyFn = createVivify(nodeVivify);
|
|
3725
|
-
const equalFn = (
|
|
3726
|
-
|
|
3727
|
-
typeof value[prop] === 'object'
|
|
3728
|
-
? () => false
|
|
3948
|
+
const equalFn = isMutableSource && (isRecord(value) || Array.isArray(value))
|
|
3949
|
+
? mutableChildEqual
|
|
3729
3950
|
: undefined;
|
|
3730
|
-
const computation =
|
|
3731
|
-
|
|
3732
|
-
:
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
equal: equalFn,
|
|
3736
|
-
});
|
|
3951
|
+
const computation = derived(target, {
|
|
3952
|
+
from: (v) => v?.[prop],
|
|
3953
|
+
onChange: createFallbackOnChange(target, prop, vivifyFn, isMutableSource),
|
|
3954
|
+
equal: equalFn,
|
|
3955
|
+
});
|
|
3737
3956
|
const childSample = untracked(computation);
|
|
3738
3957
|
const childVivify = resolveVivify(childSample, options.vivify);
|
|
3739
3958
|
const proxy = toStore(computation, options);
|
|
@@ -4623,5 +4842,5 @@ function withHistory(sourceOrValue, opt) {
|
|
|
4623
4842
|
* Generated bundle index. Do not edit.
|
|
4624
4843
|
*/
|
|
4625
4844
|
|
|
4626
|
-
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 };
|
|
4845
|
+
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 };
|
|
4627
4846
|
//# sourceMappingURL=mmstack-primitives.mjs.map
|