ember-nav-stack 6.1.1 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +165 -21
- package/addon-main.cjs +4 -0
- package/dist/_app_/components/nav-stack.js +1 -0
- package/dist/_app_/components/to-nav-stack.js +1 -0
- package/dist/_app_/helpers/nav-layer-indices.js +1 -0
- package/dist/_app_/modifiers/back-swipe.js +1 -0
- package/dist/_app_/services/gesture.js +1 -0
- package/dist/_app_/services/nav-stacks.js +1 -0
- package/dist/_app_/templates/stackable.js +1 -0
- package/dist/back-swipe-gesture.js +261 -0
- package/dist/back-swipe-gesture.js.map +1 -0
- package/dist/components/nav-stack.js +627 -0
- package/dist/components/nav-stack.js.map +1 -0
- package/dist/components/to-nav-stack.js +22 -0
- package/dist/components/to-nav-stack.js.map +1 -0
- package/dist/helpers/nav-layer-indices.js +21 -0
- package/dist/helpers/nav-layer-indices.js.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/modifiers/back-swipe.js +40 -0
- package/dist/modifiers/back-swipe.js.map +1 -0
- package/dist/routes/stackable-route.js +99 -0
- package/dist/routes/stackable-route.js.map +1 -0
- package/{addon → dist}/services/gesture.js +7 -9
- package/dist/services/gesture.js.map +1 -0
- package/dist/services/nav-stacks.js +137 -0
- package/dist/services/nav-stacks.js.map +1 -0
- package/dist/styles/nav-stack.css +399 -0
- package/dist/templates/stackable.js +8 -0
- package/dist/templates/stackable.js.map +1 -0
- package/{addon-test-support → dist/test-support}/in-viewport.js +7 -10
- package/dist/test-support/in-viewport.js.map +1 -0
- package/dist/test-support/index.js +2 -0
- package/dist/test-support/index.js.map +1 -0
- package/{addon → dist}/utils/animation.js +17 -40
- package/dist/utils/animation.js.map +1 -0
- package/{addon → dist}/utils/back-swipe-recognizer.js +29 -49
- package/dist/utils/back-swipe-recognizer.js.map +1 -0
- package/dist/utils/clone-store.js +88 -0
- package/dist/utils/clone-store.js.map +1 -0
- package/dist/utils/component.js +107 -0
- package/dist/utils/component.js.map +1 -0
- package/dist/utils/header-style.js +46 -0
- package/dist/utils/header-style.js.map +1 -0
- package/dist/utils/transition-decision.js +71 -0
- package/dist/utils/transition-decision.js.map +1 -0
- package/dist/utils/waiter-state.js +130 -0
- package/dist/utils/waiter-state.js.map +1 -0
- package/package.json +78 -91
- package/CHANGELOG.md +0 -200
- package/MODULE_REPORT.md +0 -27
- package/RELEASE.md +0 -54
- package/addon/components/nav-stack/component.js +0 -683
- package/addon/components/nav-stack/template.hbs +0 -37
- package/addon/components/to-nav-stack.js +0 -32
- package/addon/helpers/nav-layer-indices.js +0 -29
- package/addon/routes/stackable-route.js +0 -61
- package/addon/services/nav-stacks.js +0 -157
- package/addon/utils/component.js +0 -40
- package/app/components/nav-stack/component.js +0 -1
- package/app/components/nav-stack/template.js +0 -1
- package/app/components/to-nav-stack.js +0 -1
- package/app/helpers/nav-layer-indices.js +0 -1
- package/app/services/gesture.js +0 -1
- package/app/services/nav-stacks.js +0 -1
- package/app/styles/nav-stack.scss +0 -117
- package/app/templates/stackable.hbs +0 -8
- package/app/utils/animation.js +0 -1
- package/config/deploy.js +0 -29
- package/config/environment.js +0 -5
- package/config/release.js +0 -21
- package/index.js +0 -15
- package/tsconfig.json +0 -6
- package/vendor/wobble-shim.js +0 -3
|
@@ -0,0 +1,627 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { action } from '@ember/object';
|
|
3
|
+
import { scheduleOnce, run, next } from '@ember/runloop';
|
|
4
|
+
import { setTransform } from '../utils/animation.js';
|
|
5
|
+
import { Spring } from 'wobble';
|
|
6
|
+
import { macroCondition, isTesting } from '@embroider/macros';
|
|
7
|
+
import { getOwner } from '@ember/application';
|
|
8
|
+
import { service } from '@ember/service';
|
|
9
|
+
import { reads, mapBy, bool } from 'macro-decorators';
|
|
10
|
+
import { guidFor } from '@ember/object/internals';
|
|
11
|
+
import { extractComponentKey, extractComponentName } from '../utils/component.js';
|
|
12
|
+
import { decideTransition } from '../utils/transition-decision.js';
|
|
13
|
+
import { styleHeaderElements, currentTransitionPercentage, HEADER_PARALLAX_OFFSET } from '../utils/header-style.js';
|
|
14
|
+
import CloneStore from '../utils/clone-store.js';
|
|
15
|
+
import { precompileTemplate } from '@ember/template-compilation';
|
|
16
|
+
import { g, i, n } from 'decorator-transforms/runtime';
|
|
17
|
+
import { setComponentTemplate } from '@ember/component';
|
|
18
|
+
|
|
19
|
+
var TEMPLATE = precompileTemplate("<div\n id={{this.elementId}}\n class={{concat\n \"NavStack \"\n (if this.birdsEyeDebugging \"is-birdsEyeDebugging \")\n this.layerIndexCssClass\n \" \"\n (if this.hasFooter \"NavStack--withFooter \")\n }}\n {{back-swipe\n onReady=this.handleBackSwipeReady\n getCanNavigateBack=this.getCanNavigateBack\n onBack=this.handleBack\n onBackSwipeOverlay=this.handleBackSwipeOverlay\n }}\n {{did-update this.handleStackFingerprintChange this.stackItemsFingerprint}}\n ...attributes\n>\n <div class=\"NavStack-itemContainer\">\n {{#each this.renderableEntries as |entry|}}\n <div class={{concat \"NavStack-item NavStack-item-\" entry.index}}>\n {{#if entry.shouldRender}}\n {{component entry.component}}\n {{/if}}\n </div>\n {{/each}}\n </div>\n <div class=\"NavStack-header\">\n {{#if this.parentItemHeaderComponent}}\n <div class=\"NavStack-headerContainer NavStack-parentItemHeaderContainer\">\n {{component\n this.parentItemHeaderComponent\n class=\"NavStack-headerComponent\"\n back=@back\n }}\n </div>\n {{/if}}\n <div class=\"NavStack-headerContainer NavStack-currentHeaderContainer\">\n {{component\n this.headerComponent\n class=\"NavStack-headerComponent\"\n back=@back\n }}\n </div>\n </div>\n {{#if this.hasFooter}}\n <div class=\"NavStack-footer\">\n {{component @footer}}\n </div>\n {{/if}}\n</div>");
|
|
20
|
+
|
|
21
|
+
class NavStack extends Component {
|
|
22
|
+
get birdsEyeDebugging() {
|
|
23
|
+
return this.args.birdsEyeDebugging || false;
|
|
24
|
+
}
|
|
25
|
+
element;
|
|
26
|
+
get elementId() {
|
|
27
|
+
return guidFor(this);
|
|
28
|
+
}
|
|
29
|
+
get layer() {
|
|
30
|
+
return this.args.layer;
|
|
31
|
+
}
|
|
32
|
+
static {
|
|
33
|
+
g(this.prototype, "navStacksService", [service('nav-stacks')]);
|
|
34
|
+
}
|
|
35
|
+
#navStacksService = (i(this, "navStacksService"), void 0);
|
|
36
|
+
static {
|
|
37
|
+
g(this.prototype, "gesture", [service]);
|
|
38
|
+
}
|
|
39
|
+
#gesture = (i(this, "gesture"), void 0);
|
|
40
|
+
constructor() {
|
|
41
|
+
super(...arguments);
|
|
42
|
+
this.navStacksService.register(this);
|
|
43
|
+
let config = getOwner(this).resolveRegistration('config:environment');
|
|
44
|
+
this.#suppressAnimation = !!config?.['ember-nav-stack']?.suppressAnimation;
|
|
45
|
+
}
|
|
46
|
+
willDestroy() {
|
|
47
|
+
super.willDestroy(...arguments);
|
|
48
|
+
this.navStacksService.unregister(this);
|
|
49
|
+
// Defensive: sweep every tracked clone in case some transition was
|
|
50
|
+
// abandoned before its normal cleanup ran (e.g. a back-swipe in flight
|
|
51
|
+
// when the consumer tore down the route). The `parentNode?` guard in
|
|
52
|
+
// CloneStore handles clones whose parents are already detached. The
|
|
53
|
+
// detached slide-down clone is not tracked here, so it survives this
|
|
54
|
+
// sweep and keeps animating after we're gone.
|
|
55
|
+
this._clones.clearAll();
|
|
56
|
+
this._pendingGestureBackOverlay = null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Called by the service's `_process` immediately before it publishes
|
|
60
|
+
// `this.stacks = newStacks` for the case where our layer's stack just
|
|
61
|
+
// went from non-empty to empty. This is the only moment when our DOM is
|
|
62
|
+
// still attached and we have advance notice that we're about to be torn
|
|
63
|
+
// down by the host's `{{#each (nav-layer-indices)}}`. willDestroy is too
|
|
64
|
+
// late (Glimmer has already detached `this.element` by then, leaving us
|
|
65
|
+
// with no parent to attach the clone to). `_runDetachedSlideDown`
|
|
66
|
+
// self-guards against double-fire from `_applyTransition('slideDown')`,
|
|
67
|
+
// which is the parallel path for setups that don't use nav-layer-indices.
|
|
68
|
+
layerDidEmpty() {
|
|
69
|
+
if (this.args.layer === 0) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this._runDetachedSlideDown();
|
|
73
|
+
}
|
|
74
|
+
get layerIndexCssClass() {
|
|
75
|
+
return `NavStack--layer${this.args.layer}`;
|
|
76
|
+
}
|
|
77
|
+
get headerComponent() {
|
|
78
|
+
if (this.stackItems.length === 0) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
return this.stackItems[this.stackItems.length - 1].headerComponent;
|
|
82
|
+
}
|
|
83
|
+
get parentItemHeaderComponent() {
|
|
84
|
+
if (this.stackItems.length < 2) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
return this.stackItems[this.stackItems.length - 2].headerComponent;
|
|
88
|
+
}
|
|
89
|
+
get stackItems() {
|
|
90
|
+
return this.navStacksService.stacks[`layer${this.args.layer}`] || [];
|
|
91
|
+
}
|
|
92
|
+
static {
|
|
93
|
+
g(this.prototype, "stackDepth", [reads('stackItems.length')]);
|
|
94
|
+
}
|
|
95
|
+
#stackDepth = (i(this, "stackDepth"), void 0);
|
|
96
|
+
static {
|
|
97
|
+
g(this.prototype, "components", [mapBy('stackItems', 'component')]);
|
|
98
|
+
}
|
|
99
|
+
#components = (i(this, "components"), void 0);
|
|
100
|
+
// One entry per stack item. The template renders an empty `.NavStack-item-N`
|
|
101
|
+
// div for each (so the layout's left-offset CSS classes are correct), but
|
|
102
|
+
// only mounts the actual curried component when `shouldRender` is true —
|
|
103
|
+
// i.e. only the last two items in the stack are alive at any time. Items
|
|
104
|
+
// further back are positioned off-screen by the cut animation and their
|
|
105
|
+
// contents aren't worth keeping mounted.
|
|
106
|
+
get renderableEntries() {
|
|
107
|
+
let components = this.components;
|
|
108
|
+
let renderThreshold = components.length - 2;
|
|
109
|
+
return components.map((component, index) => ({
|
|
110
|
+
index,
|
|
111
|
+
component,
|
|
112
|
+
shouldRender: index >= renderThreshold
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
static {
|
|
116
|
+
g(this.prototype, "hasFooter", [bool('args.footer')]);
|
|
117
|
+
}
|
|
118
|
+
#hasFooter = (i(this, "hasFooter"), void 0);
|
|
119
|
+
// Resolved once in the constructor from
|
|
120
|
+
// `config.environment['ember-nav-stack'].suppressAnimation`.
|
|
121
|
+
#suppressAnimation = false;
|
|
122
|
+
|
|
123
|
+
// Tracks groups of cloned DOM nodes for unified cleanup. Groups used:
|
|
124
|
+
// - 'stackItems' cloned by _slideBack (the leaving last item)
|
|
125
|
+
// - 'headers' cloned for slide animations (leaving header)
|
|
126
|
+
// - 'gestureBackOverlays' target-header snapshot during a back-swipe;
|
|
127
|
+
// cleanup is queued via `_pendingGestureBackOverlay` and performed by
|
|
128
|
+
// `_finishGestureBack` — scheduled from `_handleStackDepthChange` once
|
|
129
|
+
// the stack pop actually lands, NOT on a fixed delay from finalize.
|
|
130
|
+
// Tying cleanup to the observed pop matters because the default `back`
|
|
131
|
+
// action calls `router.transitionTo`, which resolves asynchronously
|
|
132
|
+
// through route hooks; cleaning up before the pop lands would restore
|
|
133
|
+
// `.NavStack-currentHeaderContainer` to full opacity while it still
|
|
134
|
+
// holds the leaving page's header, flashing it. willDestroy sweeps
|
|
135
|
+
// any clones left from abandoned transitions via _clones.clearAll().
|
|
136
|
+
_clones = new CloneStore();
|
|
137
|
+
|
|
138
|
+
// The {{back-swipe}} modifier (template-level) calls this once its
|
|
139
|
+
// BackSwipeGesture is instantiated against the rendered element. We
|
|
140
|
+
// hold the gesture reference so _transitionDidBegin / _transitionDidEnd
|
|
141
|
+
// can pause / re-arm the pan recognizer during programmatic
|
|
142
|
+
// transitions, and the element reference because
|
|
143
|
+
// _horizontalTransition / _verticalTransition / _cut / _slide* all read
|
|
144
|
+
// from `this.element`.
|
|
145
|
+
handleBackSwipeReady(gesture, element) {
|
|
146
|
+
this._backSwipeGesture = gesture;
|
|
147
|
+
this.element = element;
|
|
148
|
+
let isInitialRender = this.navStacksService.isInitialRender;
|
|
149
|
+
scheduleOnce('afterRender', this, this._handleStackDepthChange, isInitialRender);
|
|
150
|
+
}
|
|
151
|
+
static {
|
|
152
|
+
n(this.prototype, "handleBackSwipeReady", [action]);
|
|
153
|
+
}
|
|
154
|
+
getCanNavigateBack() {
|
|
155
|
+
return !!this.args.back && this.stackDepth > 1;
|
|
156
|
+
}
|
|
157
|
+
static {
|
|
158
|
+
n(this.prototype, "getCanNavigateBack", [action]);
|
|
159
|
+
}
|
|
160
|
+
handleBack() {
|
|
161
|
+
run(this.args, this.args.back);
|
|
162
|
+
}
|
|
163
|
+
static {
|
|
164
|
+
n(this.prototype, "handleBack", [action]);
|
|
165
|
+
}
|
|
166
|
+
handleBackSwipeOverlay(clone) {
|
|
167
|
+
if (!clone) return;
|
|
168
|
+
this._clones.track('gestureBackOverlays', clone);
|
|
169
|
+
this._pendingGestureBackOverlay = clone;
|
|
170
|
+
}
|
|
171
|
+
static {
|
|
172
|
+
n(this.prototype, "handleBackSwipeOverlay", [action]);
|
|
173
|
+
}
|
|
174
|
+
stackItemsDidChange() {
|
|
175
|
+
this._handleStackDepthChange(false);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// A fingerprint over stackItems that reflects BOTH structural changes
|
|
179
|
+
// (push/pop) and per-item arg changes (e.g. a curried component whose
|
|
180
|
+
// bound model.id has changed). Reading each item's component via
|
|
181
|
+
// `extractComponentKey` consumes the underlying Glimmer reference tags,
|
|
182
|
+
// so this getter invalidates when any of those references change. The
|
|
183
|
+
// `{{did-update}}` modifier in the template observes this fingerprint
|
|
184
|
+
// and re-runs the transition logic when it changes — which is how we
|
|
185
|
+
// pick up arg-only changes (e.g. a parent route re-currying with a new
|
|
186
|
+
// model on a dynamic-segment transition) that don't produce a
|
|
187
|
+
// pushItem/removeItem on the service.
|
|
188
|
+
static {
|
|
189
|
+
n(this.prototype, "stackItemsDidChange", [action]);
|
|
190
|
+
}
|
|
191
|
+
get stackItemsFingerprint() {
|
|
192
|
+
let items = this.stackItems;
|
|
193
|
+
let extract = this.args.extractComponentKey || extractComponentKey;
|
|
194
|
+
return items.map(item => {
|
|
195
|
+
if (!item || !item.component) return '_';
|
|
196
|
+
return extract(item.component);
|
|
197
|
+
}).join('|');
|
|
198
|
+
}
|
|
199
|
+
handleStackFingerprintChange() {
|
|
200
|
+
this._handleStackDepthChange(false);
|
|
201
|
+
}
|
|
202
|
+
static {
|
|
203
|
+
n(this.prototype, "handleStackFingerprintChange", [action]);
|
|
204
|
+
}
|
|
205
|
+
_clearRootJustChanged() {
|
|
206
|
+
this._rootJustChanged = false;
|
|
207
|
+
}
|
|
208
|
+
_handleStackDepthChange(isInitialRender) {
|
|
209
|
+
if (this.isDestroying || this.isDestroyed) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
let stackItems = this.stackItems || [];
|
|
213
|
+
let stackDepth = stackItems.length;
|
|
214
|
+
let extract = this.args.extractComponentKey || extractComponentKey;
|
|
215
|
+
let rootComponentRef = stackItems[0]?.component;
|
|
216
|
+
let rootComponentKey = extract(rootComponentRef);
|
|
217
|
+
let pendingGestureBackOverlay = this._pendingGestureBackOverlay;
|
|
218
|
+
this._pendingGestureBackOverlay = null;
|
|
219
|
+
let intent = decideTransition({
|
|
220
|
+
isInitialRender,
|
|
221
|
+
previousDepth: this._stackDepth,
|
|
222
|
+
newDepth: stackDepth,
|
|
223
|
+
previousRootKey: this._rootComponentKey,
|
|
224
|
+
newRootKey: rootComponentKey,
|
|
225
|
+
layer: this.args.layer,
|
|
226
|
+
rootJustChanged: this._rootJustChanged
|
|
227
|
+
});
|
|
228
|
+
if (intent.startsRootChange) {
|
|
229
|
+
this._rootJustChanged = true;
|
|
230
|
+
next(this, this._clearRootJustChanged);
|
|
231
|
+
}
|
|
232
|
+
this._applyTransition(intent);
|
|
233
|
+
|
|
234
|
+
// Gesture-back overlay cleanup is orthogonal to which transition runs —
|
|
235
|
+
// it just needs the stack pop to have landed (newDepth < previousDepth).
|
|
236
|
+
// The overlay snapshot was made by `finalize` after the back-swipe
|
|
237
|
+
// completed; we restore the live header containers once the re-render
|
|
238
|
+
// following `args.back` has swapped their content. `next()` defers the
|
|
239
|
+
// cleanup past the current flush so the swap is visible by the time we
|
|
240
|
+
// restore opacity.
|
|
241
|
+
if (pendingGestureBackOverlay) {
|
|
242
|
+
if (stackDepth < this._stackDepth) {
|
|
243
|
+
next(this, this._finishGestureBack, pendingGestureBackOverlay);
|
|
244
|
+
} else {
|
|
245
|
+
this._clones.remove('gestureBackOverlays', pendingGestureBackOverlay);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Fire the active-item-change callback when the top stack item's
|
|
250
|
+
// component identity changes (push, pop, or root swap). Compared via
|
|
251
|
+
// component name only — `extractComponentName` skips the `:model.id`
|
|
252
|
+
// suffix that `extractComponentKey` adds, because the model ref's
|
|
253
|
+
// `lastValue` populates lazily and would otherwise produce two fires
|
|
254
|
+
// per push (`track` → `track:1` across consecutive render ticks).
|
|
255
|
+
// Consumers needing finer per-model granularity should watch their
|
|
256
|
+
// own model state via `did-update` or similar. Initial render fires
|
|
257
|
+
// once when the stack starts non-empty.
|
|
258
|
+
let topComponentRef = stackItems[stackDepth - 1]?.component;
|
|
259
|
+
let currentTopKey = stackDepth === 0 ? undefined : extractComponentName(topComponentRef);
|
|
260
|
+
let previousTopKey = this._activeItemKey;
|
|
261
|
+
if (currentTopKey !== previousTopKey) {
|
|
262
|
+
this.args.onActiveItemChange?.({
|
|
263
|
+
isInitialRender,
|
|
264
|
+
previousDepth: this._stackDepth ?? 0,
|
|
265
|
+
currentDepth: stackDepth,
|
|
266
|
+
previousTopKey,
|
|
267
|
+
currentTopKey
|
|
268
|
+
});
|
|
269
|
+
this._activeItemKey = currentTopKey;
|
|
270
|
+
}
|
|
271
|
+
this._stackDepth = stackDepth;
|
|
272
|
+
this._rootComponentKey = rootComponentKey;
|
|
273
|
+
}
|
|
274
|
+
_applyTransition(intent) {
|
|
275
|
+
switch (intent.kind) {
|
|
276
|
+
case 'cut':
|
|
277
|
+
this._schedule(this._cut);
|
|
278
|
+
break;
|
|
279
|
+
case 'slideUp':
|
|
280
|
+
this._schedule(this._slideUp);
|
|
281
|
+
break;
|
|
282
|
+
case 'slideDown':
|
|
283
|
+
this._runDetachedSlideDown();
|
|
284
|
+
break;
|
|
285
|
+
case 'slideBack':
|
|
286
|
+
this._cloneLastStackItem();
|
|
287
|
+
this._cloneHeader();
|
|
288
|
+
this._schedule(this._slideBack);
|
|
289
|
+
break;
|
|
290
|
+
case 'slideForward':
|
|
291
|
+
this._cloneHeader();
|
|
292
|
+
this._schedule(this._slideForward);
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
_schedule(method) {
|
|
297
|
+
scheduleOnce('afterRender', this, method);
|
|
298
|
+
}
|
|
299
|
+
_computeXPosition() {
|
|
300
|
+
let stackDepth = this.stackDepth;
|
|
301
|
+
if (stackDepth === 0) {
|
|
302
|
+
return 0;
|
|
303
|
+
}
|
|
304
|
+
let currentStackItemElement = this.element.querySelector('.NavStack-item:last-child');
|
|
305
|
+
if (!currentStackItemElement) {
|
|
306
|
+
return 0;
|
|
307
|
+
}
|
|
308
|
+
let itemWidth = currentStackItemElement.getBoundingClientRect().width;
|
|
309
|
+
let layerX = (stackDepth - 1) * itemWidth * -1;
|
|
310
|
+
return layerX;
|
|
311
|
+
}
|
|
312
|
+
repositionX() {
|
|
313
|
+
let itemContainerElement = this.element.querySelector('.NavStack-itemContainer');
|
|
314
|
+
let newX = this._computeXPosition();
|
|
315
|
+
setTransform(itemContainerElement, `translateX(${newX}px)`);
|
|
316
|
+
}
|
|
317
|
+
static {
|
|
318
|
+
n(this.prototype, "repositionX", [action]);
|
|
319
|
+
}
|
|
320
|
+
_cut() {
|
|
321
|
+
if (this.isDestroying || this.isDestroyed) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
this._horizontalTransition({
|
|
325
|
+
toValue: this._computeXPosition(),
|
|
326
|
+
animate: false
|
|
327
|
+
});
|
|
328
|
+
if (this.args.layer > 0 && this.stackDepth > 0) {
|
|
329
|
+
this._verticalTransition({
|
|
330
|
+
element: this.element,
|
|
331
|
+
toValue: 0,
|
|
332
|
+
animate: false
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
_slideForward() {
|
|
337
|
+
if (this.isDestroying || this.isDestroyed) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
this._horizontalTransition({
|
|
341
|
+
toValue: this._computeXPosition(),
|
|
342
|
+
finishCallback: () => {
|
|
343
|
+
this._clones.clear('headers');
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
_slideBack() {
|
|
348
|
+
if (this.isDestroying || this.isDestroyed) {
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
this._horizontalTransition({
|
|
352
|
+
toValue: this._computeXPosition(),
|
|
353
|
+
finishCallback: () => {
|
|
354
|
+
this._clones.clear('stackItems');
|
|
355
|
+
this._clones.clear('headers');
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
_slideUp() {
|
|
360
|
+
if (this.isDestroying || this.isDestroyed) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
let debug = this.birdsEyeDebugging;
|
|
364
|
+
this._verticalTransition({
|
|
365
|
+
element: this.element,
|
|
366
|
+
toValue: 0,
|
|
367
|
+
fromValue: debug ? 480 : this.element.getBoundingClientRect().height
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// Runs the slide-down dismissal entirely outside our own lifecycle.
|
|
372
|
+
// Called from two sites:
|
|
373
|
+
// 1. `layerDidEmpty()` — invoked by the service's `_process` immediately
|
|
374
|
+
// BEFORE it publishes `this.stacks = newStacks`, when our layer just
|
|
375
|
+
// transitioned non-empty → empty. This is the common case under
|
|
376
|
+
// `nav-layer-indices`, where publishing the new stacks causes the
|
|
377
|
+
// host's `{{#each}}` to tear us down. willDestroy would be too
|
|
378
|
+
// late (Glimmer detaches `this.element` before willDestroy fires,
|
|
379
|
+
// leaving us with no parent to attach the clone to), which is why
|
|
380
|
+
// we hook in pre-publish while our DOM is still mounted.
|
|
381
|
+
// 2. `_applyTransition('slideDown')`, for setups that keep the NavStack
|
|
382
|
+
// alive while its items go to zero (manual layer management without
|
|
383
|
+
// `nav-layer-indices`). In that case `layerDidEmpty` still fires —
|
|
384
|
+
// both paths can land on the same NavStack in degenerate flows, so
|
|
385
|
+
// we self-guard against a double fire.
|
|
386
|
+
// Clone+parent uses our DOM neighbor (which survives our teardown), the
|
|
387
|
+
// live element is hidden, and the spring runs with closure-captured
|
|
388
|
+
// refs — completion and DOM cleanup happen regardless of NavStack
|
|
389
|
+
// lifecycle. We bypass CloneStore so willDestroy's clearAll sweep can't
|
|
390
|
+
// tear our animation out, and we talk to the service directly for waiter
|
|
391
|
+
// tracking (the `_notifyTransition*` indirections would no-op once we're
|
|
392
|
+
// destroyed).
|
|
393
|
+
_runDetachedSlideDown() {
|
|
394
|
+
if (this._slideDownFired) {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
this._slideDownFired = true;
|
|
398
|
+
let element = this.element;
|
|
399
|
+
let parent = element?.parentNode;
|
|
400
|
+
if (!element || !parent) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
let clone = element.cloneNode(true);
|
|
404
|
+
clone.setAttribute('id', `${this.elementId}_clone`);
|
|
405
|
+
parent.appendChild(clone);
|
|
406
|
+
element.style.display = 'none';
|
|
407
|
+
// Force layout so the upcoming transform animates from rest, not from
|
|
408
|
+
// wherever the browser would interpolate from with no committed style.
|
|
409
|
+
void clone.offsetHeight;
|
|
410
|
+
let toValue = this.birdsEyeDebugging ? 480 : clone.getBoundingClientRect().height;
|
|
411
|
+
let service = this.navStacksService;
|
|
412
|
+
let removeClone = () => {
|
|
413
|
+
clone.parentNode?.removeChild(clone);
|
|
414
|
+
};
|
|
415
|
+
if (this.#suppressAnimation || toValue === 0) {
|
|
416
|
+
// No-op short-circuit: when there's nothing to animate (animations
|
|
417
|
+
// suppressed, or the element rendered with no height — which happens
|
|
418
|
+
// when the host's container is torn down before us, e.g. on app
|
|
419
|
+
// teardown during a test), snap to the final state and bail. Don't
|
|
420
|
+
// open a transition waiter for a spring that has no work — wobble's
|
|
421
|
+
// onStop doesn't reliably fire for a degenerate 0→0 spring, which
|
|
422
|
+
// would leave the waiter perpetually open and hang `settled()`.
|
|
423
|
+
setTransform(clone, `translateY(${toValue}px)`);
|
|
424
|
+
removeClone();
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
service.notifyTransitionStart();
|
|
428
|
+
new Spring({
|
|
429
|
+
initialVelocity: 0,
|
|
430
|
+
fromValue: 0,
|
|
431
|
+
toValue,
|
|
432
|
+
stiffness: 1000,
|
|
433
|
+
damping: 500,
|
|
434
|
+
mass: 3
|
|
435
|
+
}).onUpdate(s => {
|
|
436
|
+
setTransform(clone, `translateY(${s.currentValue}px)`);
|
|
437
|
+
}).onStop(() => {
|
|
438
|
+
removeClone();
|
|
439
|
+
service.notifyTransitionEnd();
|
|
440
|
+
}).start();
|
|
441
|
+
}
|
|
442
|
+
_horizontalTransition({
|
|
443
|
+
toValue,
|
|
444
|
+
fromValue,
|
|
445
|
+
animate = !this.#suppressAnimation,
|
|
446
|
+
finishCallback
|
|
447
|
+
}) {
|
|
448
|
+
let itemContainerElement = this.element.querySelector('.NavStack-itemContainer');
|
|
449
|
+
let currentHeaderElement = this.element.querySelector('.NavStack-currentHeaderContainer');
|
|
450
|
+
let clonedHeaderElement = this.element.querySelector('.NavStack-clonedHeaderContainer');
|
|
451
|
+
|
|
452
|
+
// If a prior horizontal transition is still animating (e.g. an intermediate
|
|
453
|
+
// slideBack scheduled during a staged route change like a tab switch),
|
|
454
|
+
// stop it so this transition can take over from the current position.
|
|
455
|
+
// The prior spring's onStop runs its finish (cleaning up its clones and
|
|
456
|
+
// decrementing the transition counter) before we begin the new one.
|
|
457
|
+
if (this._horizontalSpring) {
|
|
458
|
+
let prior = this._horizontalSpring;
|
|
459
|
+
this._horizontalSpring = null;
|
|
460
|
+
prior.stop();
|
|
461
|
+
}
|
|
462
|
+
this._transitionDidBegin();
|
|
463
|
+
this._notifyTransitionStart();
|
|
464
|
+
let isNoOp = false;
|
|
465
|
+
let finish = () => {
|
|
466
|
+
setTransform(itemContainerElement, `translateX(${toValue}px)`);
|
|
467
|
+
// The no-op case occurs during slideBack after a completed back-swipe:
|
|
468
|
+
// the header styles were already set as part of the swipe, so we don't
|
|
469
|
+
// want to change them further here.
|
|
470
|
+
if (!isNoOp) {
|
|
471
|
+
styleHeaderElements(currentTransitionPercentage(fromValue, toValue, toValue), fromValue === undefined || fromValue > toValue, currentHeaderElement, clonedHeaderElement);
|
|
472
|
+
}
|
|
473
|
+
this._notifyTransitionEnd();
|
|
474
|
+
this._transitionDidEnd();
|
|
475
|
+
if (finishCallback) {
|
|
476
|
+
finishCallback();
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
if (animate) {
|
|
480
|
+
fromValue = fromValue || this._getX(itemContainerElement);
|
|
481
|
+
if (fromValue === toValue) {
|
|
482
|
+
isNoOp = true;
|
|
483
|
+
run(finish);
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
let spring = this._createSpring({
|
|
487
|
+
fromValue,
|
|
488
|
+
toValue
|
|
489
|
+
});
|
|
490
|
+
this._horizontalSpring = spring;
|
|
491
|
+
spring.onUpdate(s => {
|
|
492
|
+
setTransform(itemContainerElement, `translateX(${s.currentValue}px)`);
|
|
493
|
+
styleHeaderElements(currentTransitionPercentage(fromValue, toValue, s.currentValue), fromValue > toValue, currentHeaderElement, clonedHeaderElement);
|
|
494
|
+
}).onStop(() => {
|
|
495
|
+
if (this._horizontalSpring === spring) {
|
|
496
|
+
this._horizontalSpring = null;
|
|
497
|
+
}
|
|
498
|
+
run(finish);
|
|
499
|
+
}).start();
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
run(finish);
|
|
503
|
+
}
|
|
504
|
+
_verticalTransition({
|
|
505
|
+
element,
|
|
506
|
+
toValue,
|
|
507
|
+
fromValue,
|
|
508
|
+
animate = !this.#suppressAnimation,
|
|
509
|
+
finishCallback
|
|
510
|
+
}) {
|
|
511
|
+
this._transitionDidBegin();
|
|
512
|
+
this._notifyTransitionStart();
|
|
513
|
+
let finish = () => {
|
|
514
|
+
setTransform(element, `translateY(${toValue}px)`);
|
|
515
|
+
this._notifyTransitionEnd();
|
|
516
|
+
this._transitionDidEnd();
|
|
517
|
+
if (finishCallback) {
|
|
518
|
+
finishCallback();
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
if (animate) {
|
|
522
|
+
fromValue = fromValue || element.getBoundingClientRect().top;
|
|
523
|
+
if (fromValue === toValue) {
|
|
524
|
+
run(finish);
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
let spring = this._createSpring({
|
|
528
|
+
fromValue,
|
|
529
|
+
toValue
|
|
530
|
+
});
|
|
531
|
+
spring.onUpdate(s => {
|
|
532
|
+
setTransform(element, `translateY(${s.currentValue}px)`);
|
|
533
|
+
}).onStop(() => {
|
|
534
|
+
run(finish);
|
|
535
|
+
}).start();
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
run(finish);
|
|
539
|
+
}
|
|
540
|
+
_createSpring({
|
|
541
|
+
initialVelocity = 0,
|
|
542
|
+
fromValue,
|
|
543
|
+
toValue
|
|
544
|
+
}) {
|
|
545
|
+
return new Spring({
|
|
546
|
+
initialVelocity,
|
|
547
|
+
fromValue,
|
|
548
|
+
toValue,
|
|
549
|
+
stiffness: 1000,
|
|
550
|
+
damping: 500,
|
|
551
|
+
mass: 3
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
_transitionDidBegin() {
|
|
555
|
+
this._backSwipeGesture?.disablePan();
|
|
556
|
+
}
|
|
557
|
+
_transitionDidEnd() {
|
|
558
|
+
if (!this.element || this.stackDepth <= 1) {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
this._backSwipeGesture?.setupContext();
|
|
562
|
+
}
|
|
563
|
+
_notifyTransitionStart() {
|
|
564
|
+
this.navStacksService.notifyTransitionStart();
|
|
565
|
+
}
|
|
566
|
+
_notifyTransitionEnd() {
|
|
567
|
+
this.navStacksService.notifyTransitionEnd();
|
|
568
|
+
}
|
|
569
|
+
_finishGestureBack(parentClone) {
|
|
570
|
+
if (this.isDestroying || this.isDestroyed) {
|
|
571
|
+
this._clones.remove('gestureBackOverlays', parentClone);
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
let currentHeaderElement = this.element?.querySelector('.NavStack-currentHeaderContainer');
|
|
575
|
+
let parentHeaderElement = this.element?.querySelector('.NavStack-parentItemHeaderContainer');
|
|
576
|
+
if (currentHeaderElement) {
|
|
577
|
+
currentHeaderElement.style.opacity = 1;
|
|
578
|
+
setTransform(currentHeaderElement, 'translateX(0px)');
|
|
579
|
+
}
|
|
580
|
+
if (parentHeaderElement) {
|
|
581
|
+
parentHeaderElement.style.opacity = 0;
|
|
582
|
+
setTransform(parentHeaderElement, `translateX(${-HEADER_PARALLAX_OFFSET}px)`);
|
|
583
|
+
}
|
|
584
|
+
this._clones.remove('gestureBackOverlays', parentClone);
|
|
585
|
+
}
|
|
586
|
+
_cloneLastStackItem() {
|
|
587
|
+
let clone = this.element.querySelector('.NavStack-item:last-child').cloneNode(true);
|
|
588
|
+
clone.setAttribute('id', `${this.elementId}_clonedStackItem`);
|
|
589
|
+
this._clones.track('stackItems', clone);
|
|
590
|
+
this.element.querySelector('.NavStack-itemContainer').appendChild(clone);
|
|
591
|
+
}
|
|
592
|
+
_cloneHeader() {
|
|
593
|
+
this._clones.clear('headers');
|
|
594
|
+
let liveHeader = this.element.querySelector('.NavStack-currentHeaderContainer');
|
|
595
|
+
if (!liveHeader) {
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
let clone = liveHeader.cloneNode(true);
|
|
599
|
+
clone.classList.remove('NavStack-currentHeaderContainer');
|
|
600
|
+
clone.classList.add('NavStack-clonedHeaderContainer');
|
|
601
|
+
this._clones.track('headers', clone);
|
|
602
|
+
let headerWrapper = this.element.querySelector('.NavStack-header');
|
|
603
|
+
headerWrapper.insertBefore(clone, headerWrapper.firstChild);
|
|
604
|
+
}
|
|
605
|
+
_getTestContainerEl() {
|
|
606
|
+
if (this._testContainerEl === undefined) {
|
|
607
|
+
this._testContainerEl = document.querySelector('#ember-testing') || false;
|
|
608
|
+
}
|
|
609
|
+
return this._testContainerEl;
|
|
610
|
+
}
|
|
611
|
+
_getX(element) {
|
|
612
|
+
return this._adjustX(element.getBoundingClientRect().left);
|
|
613
|
+
}
|
|
614
|
+
_adjustX(x) {
|
|
615
|
+
if (macroCondition(isTesting())) {
|
|
616
|
+
let testContainerEl = this._getTestContainerEl();
|
|
617
|
+
if (testContainerEl) {
|
|
618
|
+
return x - testContainerEl.getBoundingClientRect().left;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
return x;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
setComponentTemplate(TEMPLATE, NavStack);
|
|
625
|
+
|
|
626
|
+
export { NavStack as default };
|
|
627
|
+
//# sourceMappingURL=nav-stack.js.map
|