@yuneta/gobj-ui 7.26.47 → 7.26.48

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 CHANGED
@@ -234,7 +234,13 @@ Published as `@yuneta/gobj-ui`. Built on top of [`@yuneta/gobj-js`](https://gith
234
234
  > later Back lands on one and is absorbed. In 7.26.46 the stop retired them with
235
235
  > `history.back()`, which is asynchronous, and a stopped shell no longer hears
236
236
  > where it lands: a logout followed by a new shell in the same turn had it take
237
- > the new shell's first marker (Chromium), and the next Back left the app. A
237
+ > the new shell's first marker (Chromium), and the next Back left the app. An
238
+ > overlay parked on an action route (`redirect: "stay"`) whose `on_close` calls
239
+ > `yui_shell_unpark_route()` has the URL rewritten in place to the resting
240
+ > route, not taken back (7.26.48): a single `back()` landed on the action entry
241
+ > under the marker left in place, and the next shell opened the overlay again.
242
+ > An app that unparks with its OWN `history.back()` has the same defect: call
243
+ > `yui_shell_unpark_route()` instead. A
238
244
  > question open at the stop answers what Escape answers -- `false` for a yes/no
239
245
  > or a danger question, `"cancel"` for yes/no/cancel --; a
240
246
  > `yui_shell_confirm_ok()` resolves as on every close, so code awaiting it runs
@@ -1215,6 +1215,7 @@ function secondary_nav_renders(item, layout) {
1215
1215
  ***************************************************************/
1216
1216
  var GCLASS_NAME$22 = "C_YUI_SHELL";
1217
1217
  var __live_shells__ = [];
1218
+ var __retiring_shell__ = null;
1218
1219
  var __shell_watchers__ = [];
1219
1220
  var __window_z__ = 10;
1220
1221
  var ZONE_IDS = [
@@ -2814,7 +2815,13 @@ function close_overlays(gobj) {
2814
2815
  function retire_overlays(gobj) {
2815
2816
  let priv = gobj.priv;
2816
2817
  if (priv && priv.overlay_stack) priv.overlay_stack.splice(0);
2817
- close_overlays(gobj);
2818
+ let outer = __retiring_shell__;
2819
+ __retiring_shell__ = gobj;
2820
+ try {
2821
+ close_overlays(gobj);
2822
+ } finally {
2823
+ __retiring_shell__ = outer;
2824
+ }
2818
2825
  }
2819
2826
  function pop_escape(gobj, handler) {
2820
2827
  let priv = gobj.priv;
@@ -3756,9 +3763,39 @@ function yui_shell_overlay_dismissed(shell_gobj, overlay) {
3756
3763
  * stranded action entries and RE-FIRES the action, reopening
3757
3764
  * the overlay and hijacking the navigation the user asked
3758
3765
  * for. Only back() while the URL still sits on the route.
3766
+ *
3767
+ * A close that comes from a shell that STOPS (a logout with the
3768
+ * overlay up) does not go back: the URL is rewritten in place,
3769
+ * to the resting route under the overlay. A back() is
3770
+ * asynchronous and the stopped shell would never hear where it
3771
+ * lands -- the overlay's own marker is left in place, so a
3772
+ * single back() landed on the action entry, the URL stayed on
3773
+ * the action route, and a new shell built in the same turn read
3774
+ * it and opened the overlay again (up to gobj-ui 7.26.47).
3759
3775
  ************************************************************/
3760
3776
  function yui_shell_unpark_route(route) {
3761
- if (window.location.hash === route_to_hash(normalize_route(route))) window.history.back();
3777
+ let hash = route_to_hash(normalize_route(route));
3778
+ if (window.location.hash !== hash) return;
3779
+ let shell = __retiring_shell__;
3780
+ if (shell) {
3781
+ let resting = resting_route_of(shell);
3782
+ try {
3783
+ window.history.replaceState(window.history.state, "", route_to_hash(resting));
3784
+ } catch (e) {
3785
+ (0, _yuneta_gobj_js.log_warning)(`C_YUI_SHELL: unparking '${route}' at stop failed: ${e}`);
3786
+ }
3787
+ return;
3788
+ }
3789
+ window.history.back();
3790
+ }
3791
+ /************************************************************
3792
+ * The resting route a shell shows under its overlays: the
3793
+ * current one (only ever written for a RESTING route), else
3794
+ * the main stage's, else the default.
3795
+ ************************************************************/
3796
+ function resting_route_of(gobj) {
3797
+ let priv = gobj.priv || {};
3798
+ return (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "current_route") || priv.stages && priv.stages.main && priv.stages.main.active_route || (0, _yuneta_gobj_js.gobj_read_attr)(gobj, "default_route") || "/";
3762
3799
  }
3763
3800
  /************************************************************
3764
3801
  * Avatar provider — toolbar items with type:"avatar" call the
@@ -1210,6 +1210,7 @@ function secondary_nav_renders(item, layout) {
1210
1210
  ***************************************************************/
1211
1211
  var GCLASS_NAME$22 = "C_YUI_SHELL";
1212
1212
  var __live_shells__ = [];
1213
+ var __retiring_shell__ = null;
1213
1214
  var __shell_watchers__ = [];
1214
1215
  var __window_z__ = 10;
1215
1216
  var ZONE_IDS = [
@@ -2809,7 +2810,13 @@ function close_overlays(gobj) {
2809
2810
  function retire_overlays(gobj) {
2810
2811
  let priv = gobj.priv;
2811
2812
  if (priv && priv.overlay_stack) priv.overlay_stack.splice(0);
2812
- close_overlays(gobj);
2813
+ let outer = __retiring_shell__;
2814
+ __retiring_shell__ = gobj;
2815
+ try {
2816
+ close_overlays(gobj);
2817
+ } finally {
2818
+ __retiring_shell__ = outer;
2819
+ }
2813
2820
  }
2814
2821
  function pop_escape(gobj, handler) {
2815
2822
  let priv = gobj.priv;
@@ -3751,9 +3758,39 @@ function yui_shell_overlay_dismissed(shell_gobj, overlay) {
3751
3758
  * stranded action entries and RE-FIRES the action, reopening
3752
3759
  * the overlay and hijacking the navigation the user asked
3753
3760
  * for. Only back() while the URL still sits on the route.
3761
+ *
3762
+ * A close that comes from a shell that STOPS (a logout with the
3763
+ * overlay up) does not go back: the URL is rewritten in place,
3764
+ * to the resting route under the overlay. A back() is
3765
+ * asynchronous and the stopped shell would never hear where it
3766
+ * lands -- the overlay's own marker is left in place, so a
3767
+ * single back() landed on the action entry, the URL stayed on
3768
+ * the action route, and a new shell built in the same turn read
3769
+ * it and opened the overlay again (up to gobj-ui 7.26.47).
3754
3770
  ************************************************************/
3755
3771
  function yui_shell_unpark_route(route) {
3756
- if (window.location.hash === route_to_hash(normalize_route(route))) window.history.back();
3772
+ let hash = route_to_hash(normalize_route(route));
3773
+ if (window.location.hash !== hash) return;
3774
+ let shell = __retiring_shell__;
3775
+ if (shell) {
3776
+ let resting = resting_route_of(shell);
3777
+ try {
3778
+ window.history.replaceState(window.history.state, "", route_to_hash(resting));
3779
+ } catch (e) {
3780
+ log_warning(`C_YUI_SHELL: unparking '${route}' at stop failed: ${e}`);
3781
+ }
3782
+ return;
3783
+ }
3784
+ window.history.back();
3785
+ }
3786
+ /************************************************************
3787
+ * The resting route a shell shows under its overlays: the
3788
+ * current one (only ever written for a RESTING route), else
3789
+ * the main stage's, else the default.
3790
+ ************************************************************/
3791
+ function resting_route_of(gobj) {
3792
+ let priv = gobj.priv || {};
3793
+ return gobj_read_attr(gobj, "current_route") || priv.stages && priv.stages.main && priv.stages.main.active_route || gobj_read_attr(gobj, "default_route") || "/";
3757
3794
  }
3758
3795
  /************************************************************
3759
3796
  * Avatar provider — toolbar items with type:"avatar" call the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.26.47",
3
+ "version": "7.26.48",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",
@@ -94,6 +94,11 @@ const GCLASS_NAME = "C_YUI_SHELL";
94
94
  * that remained -- up to 7.26.41. They go to that shell now. */
95
95
  let __live_shells__ = [];
96
96
 
97
+ /* The shell whose overlays are being closed because it stops, while
98
+ * they close: their close paths run inside it (yui_shell_unpark_route
99
+ * reads it). */
100
+ let __retiring_shell__ = null;
101
+
97
102
  /* The gobjs that keep DOM in a shell's layers without being its
98
103
  * children: a C_YUI_WINDOW parented to the app, the dock of
99
104
  * C_YUI_WINDOW_MANAGER. Each is sent EV_SHELL_CHANGED when a shell is
@@ -2822,7 +2827,13 @@ function retire_overlays(gobj)
2822
2827
  if(priv && priv.overlay_stack) {
2823
2828
  priv.overlay_stack.splice(0);
2824
2829
  }
2825
- close_overlays(gobj);
2830
+ let outer = __retiring_shell__;
2831
+ __retiring_shell__ = gobj;
2832
+ try {
2833
+ close_overlays(gobj);
2834
+ } finally {
2835
+ __retiring_shell__ = outer;
2836
+ }
2826
2837
  }
2827
2838
 
2828
2839
  function pop_escape(gobj, handler)
@@ -4588,12 +4599,47 @@ function yui_shell_overlay_dismissed(shell_gobj, overlay)
4588
4599
  * stranded action entries and RE-FIRES the action, reopening
4589
4600
  * the overlay and hijacking the navigation the user asked
4590
4601
  * for. Only back() while the URL still sits on the route.
4602
+ *
4603
+ * A close that comes from a shell that STOPS (a logout with the
4604
+ * overlay up) does not go back: the URL is rewritten in place,
4605
+ * to the resting route under the overlay. A back() is
4606
+ * asynchronous and the stopped shell would never hear where it
4607
+ * lands -- the overlay's own marker is left in place, so a
4608
+ * single back() landed on the action entry, the URL stayed on
4609
+ * the action route, and a new shell built in the same turn read
4610
+ * it and opened the overlay again (up to gobj-ui 7.26.47).
4591
4611
  ************************************************************/
4592
4612
  function yui_shell_unpark_route(route)
4593
4613
  {
4594
- if(window.location.hash === route_to_hash(normalize_route(route))) {
4595
- window.history.back();
4614
+ let hash = route_to_hash(normalize_route(route));
4615
+ if(window.location.hash !== hash) {
4616
+ return;
4596
4617
  }
4618
+ let shell = __retiring_shell__;
4619
+ if(shell) {
4620
+ let resting = resting_route_of(shell);
4621
+ try {
4622
+ window.history.replaceState(window.history.state, "", route_to_hash(resting));
4623
+ } catch(e) {
4624
+ log_warning(`C_YUI_SHELL: unparking '${route}' at stop failed: ${e}`);
4625
+ }
4626
+ return;
4627
+ }
4628
+ window.history.back();
4629
+ }
4630
+
4631
+ /************************************************************
4632
+ * The resting route a shell shows under its overlays: the
4633
+ * current one (only ever written for a RESTING route), else
4634
+ * the main stage's, else the default.
4635
+ ************************************************************/
4636
+ function resting_route_of(gobj)
4637
+ {
4638
+ let priv = gobj.priv || {};
4639
+ return gobj_read_attr(gobj, "current_route") ||
4640
+ (priv.stages && priv.stages.main && priv.stages.main.active_route) ||
4641
+ gobj_read_attr(gobj, "default_route") ||
4642
+ "/";
4597
4643
  }
4598
4644
 
4599
4645
  /************************************************************
@@ -20,10 +20,10 @@ install_dom_double();
20
20
 
21
21
  const {
22
22
  SDATA_END, gclass_create,
23
- gobj_start_up, gobj_create_yuno, gobj_create, gobj_start, gobj_stop, gobj_destroy,
23
+ gobj_start_up, gobj_create_yuno, gobj_create, gobj_start, gobj_stop, gobj_destroy, gobj_read_attr,
24
24
  set_log_callback,
25
25
  } = await import("@yuneta/gobj-js");
26
- const {register_c_yui_shell, yui_shell_open_drawer} = await import("./c_yui_shell.js");
26
+ const {register_c_yui_shell, yui_shell_open_drawer, yui_shell_unpark_route} = await import("./c_yui_shell.js");
27
27
  const {register_c_yui_nav} = await import("./c_yui_nav.js");
28
28
  const {yui_shell_show_modal, yui_shell_confirm_yesno} = await import("./shell_modals.js");
29
29
  const {focus_trap_panel} = await import("./shell_focus_trap.js");
@@ -172,4 +172,57 @@ describe("a shell stopped with an overlay up", () => {
172
172
  expect(focus_trap_panel()).toBe(null);
173
173
  expect(errors()).toEqual([]);
174
174
  });
175
+
176
+ test("an action route the app parked is taken off in place, not with a back()", async () => {
177
+ window.location.hash = "#/home";
178
+ const shell = make_shell(true);
179
+ const resting = gobj_read_attr(shell, "current_route") || "/";
180
+
181
+ /* `redirect:"stay"`: the URL sits on the action route while
182
+ * the overlay is up, and the app's on_close takes it off. */
183
+ window.history.pushState(null, "", "#/prefs");
184
+ let closed = 0;
185
+ yui_shell_show_modal(shell, "the prefs", {
186
+ dialog: true, logical_class: "TEST_STOP_PREFS", title: "preferences",
187
+ on_close: () => {
188
+ closed++;
189
+ yui_shell_unpark_route("/prefs");
190
+ }
191
+ });
192
+
193
+ /* The back() landed on the action entry (the marker above it
194
+ * keeps its hash): the URL stayed on #/prefs, and a shell built
195
+ * next read it and opened the overlay again. */
196
+ const back = vi.spyOn(window.history, "back");
197
+ try {
198
+ gobj_stop(shell);
199
+ gobj_destroy(shell);
200
+ await settle();
201
+ expect(closed).toBe(1);
202
+ expect(back).not.toHaveBeenCalled();
203
+ expect(window.location.hash).toBe(`#${resting.startsWith("/") ? resting : "/" + resting}`);
204
+ } finally {
205
+ back.mockRestore();
206
+ window.location.hash = "";
207
+ }
208
+ expect(errors()).toEqual([]);
209
+ });
210
+
211
+ test("closed by the user, an overlay still unparks with a back()", async () => {
212
+ window.location.hash = "#/home";
213
+ const shell = make_shell(true);
214
+ window.history.pushState(null, "", "#/prefs");
215
+ const back = vi.spyOn(window.history, "back");
216
+ try {
217
+ yui_shell_unpark_route("/prefs");
218
+ expect(back).toHaveBeenCalledTimes(1);
219
+ yui_shell_unpark_route("/other");
220
+ expect(back).toHaveBeenCalledTimes(1);
221
+ } finally {
222
+ back.mockRestore();
223
+ gobj_stop(shell);
224
+ gobj_destroy(shell);
225
+ window.location.hash = "";
226
+ }
227
+ });
175
228
  });