@yuneta/gobj-ui 7.26.1 → 7.26.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuneta/gobj-ui",
3
- "version": "7.26.1",
3
+ "version": "7.26.2",
4
4
  "type": "module",
5
5
  "main": "dist/gobj-ui.cjs.js",
6
6
  "module": "dist/gobj-ui.es.js",
@@ -3276,6 +3276,37 @@ function yui_shell_last_route_under(shell_gobj, route)
3276
3276
  return route;
3277
3277
  }
3278
3278
 
3279
+ /************************************************************
3280
+ * Where the reader last was OUTSIDE `route`: the most recent
3281
+ * visited route that is neither `route` nor below it, or "" when
3282
+ * there is none (the page landed there and never left).
3283
+ *
3284
+ * It is the other half of yui_shell_last_route_under(), and it is
3285
+ * what a "back" button of a view means: the view the reader CAME
3286
+ * FROM, wherever that was. Browser Back already does that; a
3287
+ * button that names one fixed route instead only agrees with it
3288
+ * when the reader happened to come from there. Excluding the
3289
+ * whole subtree is the point -- going from one record of a detail
3290
+ * view to the next must not make "back" step through them.
3291
+ *
3292
+ * Like the other memories, a mirror of the url for the page: the
3293
+ * caller decides what to do with "" (a fixed fallback, usually).
3294
+ ************************************************************/
3295
+ function yui_shell_last_route_outside(shell_gobj, route)
3296
+ {
3297
+ let priv = shell_gobj && shell_gobj.priv;
3298
+ if(!priv || !is_array(priv.route_mru) || !route) {
3299
+ return "";
3300
+ }
3301
+ for(let i = priv.route_mru.length - 1; i >= 0; i--) {
3302
+ let r = priv.route_mru[i];
3303
+ if(r !== route && r.indexOf(route + "/") !== 0) {
3304
+ return r;
3305
+ }
3306
+ }
3307
+ return "";
3308
+ }
3309
+
3279
3310
  /************************************************************
3280
3311
  * Resolve the shell that governs `gobj`: the nearest
3281
3312
  * C_YUI_SHELL ancestor, else the last shell created on the
@@ -3716,6 +3747,7 @@ export {
3716
3747
  yui_shell_zone,
3717
3748
  yui_shell_navigate,
3718
3749
  yui_shell_last_route_under,
3750
+ yui_shell_last_route_outside,
3719
3751
  yui_shell_nav_map,
3720
3752
  yui_shell_set_sub_routes,
3721
3753
  yui_shell_register_event_handler,
@@ -0,0 +1,53 @@
1
+ /*
2
+ * yui_shell_last_route_under() / yui_shell_last_route_outside():
3
+ * the two questions asked of the shell's memory of visited routes.
4
+ * They read only `priv.route_mru`, so a bare object stands in for
5
+ * the shell.
6
+ */
7
+ import {describe, it, expect} from "vitest";
8
+ import {
9
+ yui_shell_last_route_under,
10
+ yui_shell_last_route_outside,
11
+ } from "./c_yui_shell.js";
12
+
13
+ function shell(mru)
14
+ {
15
+ return {priv: {route_mru: mru}};
16
+ }
17
+
18
+ describe("yui_shell_last_route_outside", () => {
19
+ it("answers the view the reader came from", () => {
20
+ const s = shell(["/devices/list", "/devices/map/table", "/devices/detail/E1"]);
21
+ expect(yui_shell_last_route_outside(s, "/devices/detail")).toBe("/devices/map/table");
22
+ });
23
+
24
+ it("skips every record of the same view, not only the current one", () => {
25
+ const s = shell(["/alarms", "/devices/detail/E1", "/devices/detail/E2"]);
26
+ expect(yui_shell_last_route_outside(s, "/devices/detail")).toBe("/alarms");
27
+ });
28
+
29
+ it("answers the bare route of a view too", () => {
30
+ const s = shell(["/devices/map", "/devices/detail"]);
31
+ expect(yui_shell_last_route_outside(s, "/devices/detail")).toBe("/devices/map");
32
+ });
33
+
34
+ it("does not take a sibling that only shares a prefix for a child", () => {
35
+ const s = shell(["/devices/detailed", "/devices/detail/E1"]);
36
+ expect(yui_shell_last_route_outside(s, "/devices/detail")).toBe("/devices/detailed");
37
+ });
38
+
39
+ it("answers empty when the page never left the view", () => {
40
+ expect(yui_shell_last_route_outside(shell(["/devices/detail/E1"]), "/devices/detail")).toBe("");
41
+ expect(yui_shell_last_route_outside(shell([]), "/devices/detail")).toBe("");
42
+ expect(yui_shell_last_route_outside(null, "/devices/detail")).toBe("");
43
+ expect(yui_shell_last_route_outside(shell(["/x"]), "")).toBe("");
44
+ });
45
+ });
46
+
47
+ describe("yui_shell_last_route_under", () => {
48
+ it("answers the deepest recent position under a route, or the route", () => {
49
+ const s = shell(["/graph/users", "/alarms"]);
50
+ expect(yui_shell_last_route_under(s, "/graph")).toBe("/graph/users");
51
+ expect(yui_shell_last_route_under(s, "/cards")).toBe("/cards");
52
+ });
53
+ });