@mmstack/primitives 19.6.0 → 19.7.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 +264 -44
- package/fesm2022/mmstack-primitives.mjs.map +1 -1
- package/lib/concurrent/index.d.ts +1 -0
- package/lib/concurrent/start-transition.d.ts +3 -2
- package/lib/concurrent/suspense-boundary.d.ts +1 -2
- package/lib/concurrent/transaction.d.ts +2 -1
- package/lib/concurrent/transition-scope.d.ts +9 -0
- package/lib/concurrent/transition.d.ts +62 -0
- package/lib/sensors/pointer-drag.d.ts +7 -0
- package/package.json +1 -1
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
|
|
|
@@ -634,6 +634,38 @@ function provideForwardingTransitionScope() {
|
|
|
634
634
|
function getTransitionScope(injector) {
|
|
635
635
|
return injector.get(TRANSITION_SCOPE, null);
|
|
636
636
|
}
|
|
637
|
+
/**
|
|
638
|
+
* @internal Transaction-attributed pending for `startTransition`/`startTransaction`: like
|
|
639
|
+
* `scope.pending`, but loads already in flight when the tracker is created are NOT attributed —
|
|
640
|
+
* a pre-existing background load can neither settle the transaction early nor block its settle
|
|
641
|
+
* forever. A pre-existing flight is excluded only until it first settles; a later re-trigger of
|
|
642
|
+
* the same resource (e.g. the transaction's write changed its request) counts as the
|
|
643
|
+
* transaction's own work.
|
|
644
|
+
*/
|
|
645
|
+
function createAttributedPending(scope) {
|
|
646
|
+
const isInFlight = (ref) => {
|
|
647
|
+
const s = untracked(ref.status);
|
|
648
|
+
return s === ResourceStatus.Loading || s === ResourceStatus.Reloading;
|
|
649
|
+
};
|
|
650
|
+
const preexisting = new Set(untracked(scope.resources).filter(isInFlight));
|
|
651
|
+
return computed(() => {
|
|
652
|
+
let pending = false;
|
|
653
|
+
for (const ref of scope.resources()) {
|
|
654
|
+
const s = ref.status();
|
|
655
|
+
const loading = s === ResourceStatus.Loading || s === ResourceStatus.Reloading;
|
|
656
|
+
if (preexisting.has(ref)) {
|
|
657
|
+
// deletes are monotonic, so this stays sound under re-computation
|
|
658
|
+
if (loading)
|
|
659
|
+
continue;
|
|
660
|
+
preexisting.delete(ref);
|
|
661
|
+
continue;
|
|
662
|
+
}
|
|
663
|
+
if (loading)
|
|
664
|
+
pending = true;
|
|
665
|
+
}
|
|
666
|
+
return pending;
|
|
667
|
+
});
|
|
668
|
+
}
|
|
637
669
|
/**
|
|
638
670
|
* Returns a register function bound to the nearest transition scope: it adds a resource
|
|
639
671
|
* to the scope and removes it when the caller's injection context is destroyed. Pass any
|
|
@@ -671,38 +703,43 @@ function registerResource(res, opt) {
|
|
|
671
703
|
function injectStartTransition() {
|
|
672
704
|
const scope = injectTransitionScope();
|
|
673
705
|
const injector = inject(Injector);
|
|
706
|
+
const destroyRef = inject(DestroyRef);
|
|
674
707
|
const onServer = isPlatformServer(inject(PLATFORM_ID, { optional: true }) ?? 'browser');
|
|
675
708
|
return (fn) => {
|
|
709
|
+
// attributed: loads already in flight when the transition starts are not ours —
|
|
710
|
+
// they can neither settle this transition early nor block it forever
|
|
711
|
+
const pending = createAttributedPending(scope);
|
|
676
712
|
untracked(fn);
|
|
677
713
|
let sawPending = false;
|
|
678
714
|
const done = new Promise((resolve) => {
|
|
715
|
+
const settle = () => {
|
|
716
|
+
releaseDestroy();
|
|
717
|
+
watcher.destroy();
|
|
718
|
+
resolve();
|
|
719
|
+
};
|
|
679
720
|
const watcher = effect(() => {
|
|
680
|
-
const p =
|
|
721
|
+
const p = pending();
|
|
681
722
|
if (p)
|
|
682
723
|
sawPending = true;
|
|
683
724
|
// settle: requests went in flight and then drained
|
|
684
|
-
if (sawPending && !p)
|
|
685
|
-
|
|
686
|
-
resolve();
|
|
687
|
-
}
|
|
725
|
+
if (sawPending && !p)
|
|
726
|
+
settle();
|
|
688
727
|
}, { injector });
|
|
728
|
+
// a destroy mid-flight kills the watcher — resolve so awaiters never hang
|
|
729
|
+
const releaseDestroy = destroyRef.onDestroy(settle);
|
|
689
730
|
if (onServer) {
|
|
690
|
-
if (!untracked(
|
|
691
|
-
|
|
692
|
-
resolve();
|
|
693
|
-
}
|
|
731
|
+
if (!untracked(pending))
|
|
732
|
+
settle();
|
|
694
733
|
return;
|
|
695
734
|
}
|
|
696
735
|
// no-async fallback: once the reactive system has processed the writes (afterNextRender),
|
|
697
736
|
// if nothing ever went in flight, the transition is already complete.
|
|
698
737
|
afterNextRender(() => {
|
|
699
|
-
if (!sawPending && !untracked(
|
|
700
|
-
|
|
701
|
-
resolve();
|
|
702
|
-
}
|
|
738
|
+
if (!sawPending && !untracked(pending))
|
|
739
|
+
settle();
|
|
703
740
|
}, { injector });
|
|
704
741
|
});
|
|
705
|
-
return { pending
|
|
742
|
+
return { pending, done };
|
|
706
743
|
};
|
|
707
744
|
}
|
|
708
745
|
|
|
@@ -773,8 +810,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.19", ngImpo
|
|
|
773
810
|
}] });
|
|
774
811
|
/**
|
|
775
812
|
* Unscoped suspense boundary — **reads the ambient scope** instead of providing one. For cases where
|
|
776
|
-
* the resources to coordinate are registered *above* the boundary
|
|
777
|
-
* manifests/connectors register at a higher injector), so the boundary observes that outer scope
|
|
813
|
+
* the resources to coordinate are registered *above* the boundary so the boundary observes that outer scope
|
|
778
814
|
* rather than opening a fresh one. Pair with a `provideTransitionScope()` (or another boundary) in an
|
|
779
815
|
* ancestor.
|
|
780
816
|
*/
|
|
@@ -839,9 +875,13 @@ function runInTransaction(txn, fn) {
|
|
|
839
875
|
function injectStartTransaction() {
|
|
840
876
|
const scope = injectTransitionScope();
|
|
841
877
|
const injector = inject(Injector);
|
|
878
|
+
const destroyRef = inject(DestroyRef);
|
|
842
879
|
const onServer = isPlatformServer(inject(PLATFORM_ID, { optional: true }) ?? 'browser');
|
|
843
880
|
return (fn) => {
|
|
844
881
|
const txn = createTransaction();
|
|
882
|
+
// attributed: loads already in flight when the transaction starts are not ours —
|
|
883
|
+
// they can neither commit this transaction early nor block its settle forever
|
|
884
|
+
const pending = createAttributedPending(scope);
|
|
845
885
|
// Hold BEFORE the writes, so the display freezes at pre-transaction values.
|
|
846
886
|
scope.beginHold();
|
|
847
887
|
let finished = false;
|
|
@@ -858,6 +898,7 @@ function injectStartTransaction() {
|
|
|
858
898
|
if (finished)
|
|
859
899
|
return;
|
|
860
900
|
finished = true;
|
|
901
|
+
releaseDestroy();
|
|
861
902
|
watcher?.destroy();
|
|
862
903
|
if (restore)
|
|
863
904
|
txn.restore();
|
|
@@ -866,6 +907,10 @@ function injectStartTransaction() {
|
|
|
866
907
|
scope.endHold();
|
|
867
908
|
resolveDone();
|
|
868
909
|
};
|
|
910
|
+
// The scope may outlive the calling context (a component transacting on an ancestor
|
|
911
|
+
// boundary): a destroy mid-flight kills the settle watcher, so without this the hold
|
|
912
|
+
// would leak and freeze the surviving scope forever. Keep the writes — they landed live.
|
|
913
|
+
const releaseDestroy = destroyRef.onDestroy(() => finish(false));
|
|
869
914
|
try {
|
|
870
915
|
runInTransaction(txn, fn);
|
|
871
916
|
}
|
|
@@ -875,31 +920,195 @@ function injectStartTransaction() {
|
|
|
875
920
|
}
|
|
876
921
|
let sawPending = false;
|
|
877
922
|
watcher = effect(() => {
|
|
878
|
-
const p =
|
|
923
|
+
const p = pending();
|
|
879
924
|
if (p)
|
|
880
925
|
sawPending = true;
|
|
881
926
|
if (sawPending && !p)
|
|
882
927
|
finish(false);
|
|
883
928
|
}, { injector });
|
|
884
929
|
if (onServer) {
|
|
885
|
-
if (!untracked(
|
|
930
|
+
if (!untracked(pending))
|
|
886
931
|
finish(false);
|
|
887
932
|
}
|
|
888
933
|
else {
|
|
889
934
|
// no-async fallback: if nothing ever went in flight, settle once the writes are processed.
|
|
890
935
|
afterNextRender(() => {
|
|
891
|
-
if (!sawPending && !untracked(
|
|
936
|
+
if (!sawPending && !untracked(pending))
|
|
892
937
|
finish(false);
|
|
893
938
|
}, { injector });
|
|
894
939
|
}
|
|
895
940
|
return {
|
|
896
|
-
pending
|
|
941
|
+
pending,
|
|
897
942
|
done,
|
|
898
943
|
abort: () => finish(true),
|
|
899
944
|
};
|
|
900
945
|
};
|
|
901
946
|
}
|
|
902
947
|
|
|
948
|
+
/**
|
|
949
|
+
* Generic hold-and-swap: the non-router `TransitionRouterOutlet`. When the bound value changes,
|
|
950
|
+
* the OLD view stays mounted and visible (it keeps its old context value — that's the hold) while
|
|
951
|
+
* the NEW view mounts hidden with its **own transition scope**; resources created in the incoming
|
|
952
|
+
* subtree register into that scope just by existing, and once they've gone in flight and settled
|
|
953
|
+
* the views swap in one frame. Tabs, wizard steps, master-detail — any branch change that would
|
|
954
|
+
* otherwise flash a loading state.
|
|
955
|
+
*
|
|
956
|
+
* ```html
|
|
957
|
+
* <div *mmTransition="selectedTab(); let tab">
|
|
958
|
+
* @switch (tab) { ... }
|
|
959
|
+
* </div>
|
|
960
|
+
* ```
|
|
961
|
+
*
|
|
962
|
+
* Distinct from `<mm-suspense>` (the readiness gate): suspense decides placeholder-vs-content
|
|
963
|
+
* *within* one branch, but can't stop an `@switch` from unmounting the old branch the instant the
|
|
964
|
+
* value flips. This directive is the swap itself — the old branch survives until the new one is
|
|
965
|
+
* ready. Compose them freely: suspense inside a transitioned branch handles its first load.
|
|
966
|
+
*
|
|
967
|
+
* Semantics mirror the outlet: the first render is immediate (nothing to hold); an interrupting
|
|
968
|
+
* value change mid-hold destroys the half-ready hidden view and re-targets; a branch that loads
|
|
969
|
+
* nothing swaps right after its first render. Per-view scopes mean the outgoing branch's
|
|
970
|
+
* background work can never delay the swap. Set `mmTransitionImmediate` to skip holding, and
|
|
971
|
+
* `mmTransitionViewTransition` to wrap the swap in `document.startViewTransition` (feature
|
|
972
|
+
* detected). On the server every change swaps immediately.
|
|
973
|
+
*/
|
|
974
|
+
class MmTransition {
|
|
975
|
+
tpl = inject(TemplateRef);
|
|
976
|
+
vcr = inject(ViewContainerRef);
|
|
977
|
+
parent = inject(Injector);
|
|
978
|
+
onServer = isPlatformServer(inject(PLATFORM_ID, { optional: true }) ?? 'browser');
|
|
979
|
+
/** The value whose changes are transitioned. Each view keeps the value it was created with. */
|
|
980
|
+
value = input.required({ alias: 'mmTransition' });
|
|
981
|
+
/** Skip holding entirely — every change swaps at once (the plain re-render behavior). */
|
|
982
|
+
immediate = input(false, { alias: 'mmTransitionImmediate' });
|
|
983
|
+
/** Wrap the swap in the View Transitions API for an animated cross-fade (feature detected). */
|
|
984
|
+
viewTransition = input(false, {
|
|
985
|
+
alias: 'mmTransitionViewTransition',
|
|
986
|
+
});
|
|
987
|
+
current = null;
|
|
988
|
+
incoming = null;
|
|
989
|
+
/** Bumped on every re-target/teardown so a superseded (possibly deferred) swap can't commit. */
|
|
990
|
+
swapEpoch = 0;
|
|
991
|
+
holding = signal(false);
|
|
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
|
+
}, { 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: "19.2.19", ngImport: i0, type: MmTransition, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1102
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.19", 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: "19.2.19", ngImport: i0, type: MmTransition, decorators: [{
|
|
1105
|
+
type: Directive,
|
|
1106
|
+
args: [{
|
|
1107
|
+
selector: '[mmTransition]',
|
|
1108
|
+
exportAs: 'mmTransition',
|
|
1109
|
+
}]
|
|
1110
|
+
}], ctorParameters: () => [] });
|
|
1111
|
+
|
|
903
1112
|
/**
|
|
904
1113
|
* @internal
|
|
905
1114
|
*/
|
|
@@ -2907,9 +3116,13 @@ const IDLE = {
|
|
|
2907
3116
|
button: -1,
|
|
2908
3117
|
pointerType: '',
|
|
2909
3118
|
origin: null,
|
|
3119
|
+
cancelled: false,
|
|
2910
3120
|
};
|
|
3121
|
+
/** Terminal state of an aborted gesture — same idle shape, `cancelled: true`. */
|
|
3122
|
+
const CANCELLED = { ...IDLE, cancelled: true };
|
|
2911
3123
|
function stateEqual(a, b) {
|
|
2912
3124
|
return (a.active === b.active &&
|
|
3125
|
+
a.cancelled === b.cancelled &&
|
|
2913
3126
|
a.pointerId === b.pointerId &&
|
|
2914
3127
|
a.current.x === b.current.x &&
|
|
2915
3128
|
a.current.y === b.current.y &&
|
|
@@ -2987,7 +3200,7 @@ function createPointerDrag(opt) {
|
|
|
2987
3200
|
ctrl: e.ctrlKey,
|
|
2988
3201
|
meta: e.metaKey,
|
|
2989
3202
|
});
|
|
2990
|
-
const end = () => {
|
|
3203
|
+
const end = (cancelled = false) => {
|
|
2991
3204
|
gesture?.abort();
|
|
2992
3205
|
gesture = null;
|
|
2993
3206
|
activePointerId = null;
|
|
@@ -2995,8 +3208,8 @@ function createPointerDrag(opt) {
|
|
|
2995
3208
|
activePointerType = '';
|
|
2996
3209
|
activeOrigin = null;
|
|
2997
3210
|
activated = false;
|
|
2998
|
-
state.set(IDLE);
|
|
2999
|
-
state.flush(); // terminal transition: reflect
|
|
3211
|
+
state.set(cancelled ? CANCELLED : IDLE);
|
|
3212
|
+
state.flush(); // terminal transition: reflect idle now, not on the trailing edge
|
|
3000
3213
|
};
|
|
3001
3214
|
const onMove = (e) => {
|
|
3002
3215
|
if (e.pointerId !== activePointerId)
|
|
@@ -3016,6 +3229,7 @@ function createPointerDrag(opt) {
|
|
|
3016
3229
|
button: activeButton, // pointermove button is -1; keep the down-button
|
|
3017
3230
|
pointerType: activePointerType,
|
|
3018
3231
|
origin: activeOrigin,
|
|
3232
|
+
cancelled: false,
|
|
3019
3233
|
});
|
|
3020
3234
|
};
|
|
3021
3235
|
const onUp = (e) => {
|
|
@@ -3024,11 +3238,11 @@ function createPointerDrag(opt) {
|
|
|
3024
3238
|
};
|
|
3025
3239
|
const onCancel = (e) => {
|
|
3026
3240
|
if (e.pointerId === activePointerId)
|
|
3027
|
-
end();
|
|
3241
|
+
end(true);
|
|
3028
3242
|
};
|
|
3029
3243
|
const onKey = (e) => {
|
|
3030
3244
|
if (e.key === 'Escape' && activePointerId !== null)
|
|
3031
|
-
end();
|
|
3245
|
+
end(true);
|
|
3032
3246
|
};
|
|
3033
3247
|
const onDown = (el) => (e) => {
|
|
3034
3248
|
if (activePointerId !== null)
|
|
@@ -3073,6 +3287,7 @@ function createPointerDrag(opt) {
|
|
|
3073
3287
|
button: e.button,
|
|
3074
3288
|
pointerType: activePointerType,
|
|
3075
3289
|
origin: activeOrigin,
|
|
3290
|
+
cancelled: false,
|
|
3076
3291
|
});
|
|
3077
3292
|
};
|
|
3078
3293
|
const attach = (el) => {
|
|
@@ -3082,7 +3297,7 @@ function createPointerDrag(opt) {
|
|
|
3082
3297
|
});
|
|
3083
3298
|
return () => {
|
|
3084
3299
|
controller.abort();
|
|
3085
|
-
end();
|
|
3300
|
+
end(true); // teardown mid-gesture is an abort, not a drop
|
|
3086
3301
|
};
|
|
3087
3302
|
};
|
|
3088
3303
|
if (isSignal(target)) {
|
|
@@ -3100,7 +3315,7 @@ function createPointerDrag(opt) {
|
|
|
3100
3315
|
}
|
|
3101
3316
|
const base = state.asReadonly();
|
|
3102
3317
|
base.unthrottled = state.original;
|
|
3103
|
-
base.cancel = end;
|
|
3318
|
+
base.cancel = () => end(true);
|
|
3104
3319
|
return base;
|
|
3105
3320
|
}
|
|
3106
3321
|
|
|
@@ -3693,30 +3908,35 @@ function getCachedChild(target, prop, build, cache, cleanupRegistry) {
|
|
|
3693
3908
|
cleanupRegistry.register(proxy, { target, prop }, ref);
|
|
3694
3909
|
return proxy;
|
|
3695
3910
|
}
|
|
3911
|
+
/**
|
|
3912
|
+
* @internal Whether a mutable parent's child value must always re-notify: in-place mutation
|
|
3913
|
+
* keeps an object child's reference stable, so `Object.is` would swallow the change. Decided
|
|
3914
|
+
* per-VALUE (not snapshotted at build) so a union child that becomes an object later still
|
|
3915
|
+
* propagates parent-level mutations.
|
|
3916
|
+
*/
|
|
3917
|
+
function mutableChildEqual(a, b) {
|
|
3918
|
+
if (typeof a === 'object' && a !== null)
|
|
3919
|
+
return false;
|
|
3920
|
+
return Object.is(a, b);
|
|
3921
|
+
}
|
|
3696
3922
|
/**
|
|
3697
3923
|
* @internal Builds the derived child signal for `prop` and wraps it as an array/object substore.
|
|
3698
|
-
*
|
|
3699
|
-
*
|
|
3700
|
-
* is constructed.
|
|
3924
|
+
* Both the read (`v?.[prop]`) and the write (`createFallbackOnChange` copies by the container's
|
|
3925
|
+
* LIVE shape) are shape-adaptive, so a child cached before an array↔record↔null union flip stays
|
|
3926
|
+
* correct after it. The only place a child node is constructed — shared by every container kind.
|
|
3701
3927
|
*/
|
|
3702
3928
|
function buildChildNode(target, prop, isMutableSource, options) {
|
|
3703
3929
|
const value = untracked(target);
|
|
3704
|
-
const valueIsRecord = isRecord(value);
|
|
3705
|
-
const valueIsArray = Array.isArray(value);
|
|
3706
3930
|
const nodeVivify = resolveVivify(value, options.vivify);
|
|
3707
3931
|
const vivifyFn = createVivify(nodeVivify);
|
|
3708
|
-
const equalFn = (
|
|
3709
|
-
|
|
3710
|
-
typeof value[prop] === 'object'
|
|
3711
|
-
? () => false
|
|
3932
|
+
const equalFn = isMutableSource && (isRecord(value) || Array.isArray(value))
|
|
3933
|
+
? mutableChildEqual
|
|
3712
3934
|
: undefined;
|
|
3713
|
-
const computation =
|
|
3714
|
-
|
|
3715
|
-
:
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
equal: equalFn,
|
|
3719
|
-
});
|
|
3935
|
+
const computation = derived(target, {
|
|
3936
|
+
from: (v) => v?.[prop],
|
|
3937
|
+
onChange: createFallbackOnChange(target, prop, vivifyFn, isMutableSource),
|
|
3938
|
+
equal: equalFn,
|
|
3939
|
+
});
|
|
3720
3940
|
const childSample = untracked(computation);
|
|
3721
3941
|
const childVivify = resolveVivify(childSample, options.vivify);
|
|
3722
3942
|
const proxy = toStore(computation, options);
|
|
@@ -4605,5 +4825,5 @@ function withHistory(sourceOrValue, opt) {
|
|
|
4605
4825
|
* Generated bundle index. Do not edit.
|
|
4606
4826
|
*/
|
|
4607
4827
|
|
|
4608
|
-
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 };
|
|
4828
|
+
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 };
|
|
4609
4829
|
//# sourceMappingURL=mmstack-primitives.mjs.map
|