@design.estate/dees-catalog 22.3.1 → 22.4.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.
@@ -234,15 +234,30 @@ export interface IViewNavigationOptions {
234
234
  * left behind. `replace` rewrites the current entry instead — for a screen
235
235
  * that corrects its own route, such as a redirect to a default section or a
236
236
  * normalized identifier, which must not become a step of its own. `return`
237
- * ends a step the reader took from the screen asked for — a flow opened
238
- * from a list that goes back to it once it is done or closed: when the
239
- * entry before the current one shows that screen, the shell goes back to
240
- * it, so the flow's entry stays only as Forward and Back leaves the screen
241
- * the reader came from rather than showing it once more; otherwise, as
242
- * after a reload or a deep link into the flow, it replaces the current
243
- * entry.
237
+ * ends a flow the reader opened from the screen asked for — a flow opened
238
+ * from a list that goes back to it once it is done or closed: when an entry
239
+ * before the current one shows that screen, the shell goes back to it,
240
+ * across the entries the flow pushed for its steps on its own screen, so
241
+ * they stay only as Forward and Back leaves the screen the reader came from
242
+ * rather than showing it, or a step of the flow, once more; otherwise, as
243
+ * after a reload, a deep link into the flow or a stop on another screen in
244
+ * between, it replaces the current entry.
244
245
  */
245
246
  history?: 'push' | 'replace' | 'return';
247
+ /**
248
+ * With `history: 'return'`, the screen the flow started from, where the
249
+ * flow ends on another screen — the record it created, say. The shell goes
250
+ * back to the entry showing the origin, as a return to it would, and pushes
251
+ * the screen asked for after it, so Back from the record returns to the
252
+ * list rather than into the finished flow. Where a return to the origin
253
+ * would replace, or the origin names no screen, the screen asked for
254
+ * replaces the current entry.
255
+ */
256
+ origin?: {
257
+ viewId: string;
258
+ params?: Record<string, string>;
259
+ query?: Record<string, string>;
260
+ };
246
261
  }
247
262
  /**
248
263
  * View lifecycle hooks interface
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@design.estate/dees-catalog",
3
- "version": "22.3.1",
3
+ "version": "22.4.0",
4
4
  "private": false,
5
5
  "description": "A comprehensive library that provides dynamic web components for building sophisticated and modern web applications using JavaScript and TypeScript.",
6
6
  "main": "dist_ts_web/index.js",
package/readme.md CHANGED
@@ -3024,9 +3024,12 @@ rather than written to history from there, and the traversal decides.
3024
3024
  `navigateToView(viewId, params?, query?, { history: 'replace' })` and
3025
3025
  `navigateToUrl(href, { history: 'replace' })` rewrite the current history entry instead
3026
3026
  of adding one, so a screen that corrects its own route does not become a step of its own.
3027
- `{ history: 'return' }` ends a step taken from the screen asked for, such as a flow opened
3028
- from a list: the shell goes back to that screen when the entry before shows it, so Back
3029
- does not show it a second time, and replaces the current entry otherwise.
3027
+ `{ history: 'return' }` ends a flow opened from the screen asked for, such as a list: the
3028
+ shell goes back to that screen across the entries the flow pushed for its steps on its own
3029
+ view, so Back shows neither it nor a step a second time, and replaces the current entry
3030
+ where no entry before shows it. With `origin: { viewId, params?, query? }` a return ends
3031
+ the flow on another screen, such as the record it created: the shell goes back to the
3032
+ origin and pushes that screen after it.
3030
3033
  Unset, navigation pushes as before.
3031
3034
 
3032
3035
  **Secondary Menu Item Types:**
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@design.estate/dees-catalog',
6
- version: '22.3.1',
6
+ version: '22.4.0',
7
7
  description: 'A comprehensive library that provides dynamic web components for building sophisticated and modern web applications using JavaScript and TypeScript.'
8
8
  }
@@ -76,10 +76,10 @@ type TNavigationIntent = 'reader' | 'system';
76
76
 
77
77
  /**
78
78
  * How a navigation meets the browser's history: `push` adds an entry, `replace`
79
- * rewrites the current one, `return` goes back to the entry before the current
80
- * one where that shows the screen and replaces the current one elsewhere, and
81
- * `traverse` follows a move the browser already made itself — Back, Forward,
82
- * an edited address.
79
+ * rewrites the current one, `return` goes back across a flow's steps to the
80
+ * entry that shows the screen the flow started from where one does, and
81
+ * replaces the current one elsewhere, and `traverse` follows a move the browser
82
+ * already made itself — Back, Forward, an edited address.
83
83
  */
84
84
  type TNavigationMode = 'push' | 'replace' | 'return' | 'traverse';
85
85
 
@@ -94,6 +94,16 @@ interface IHistoryMarker {
94
94
  previous?: number;
95
95
  }
96
96
 
97
+ /**
98
+ * What the shell knows of a history entry it wrote, by the entry's number: the
99
+ * location it shows, the view showing it, and the entry it was pushed from.
100
+ */
101
+ interface IHistoryEntry {
102
+ location: string;
103
+ viewId?: string;
104
+ previous?: number;
105
+ }
106
+
97
107
  /** A navigation whose screen failed to load, kept so the reader can try it again. */
98
108
  interface IFailedNavigation {
99
109
  view: interfaces.IViewDefinition;
@@ -102,6 +112,8 @@ interface IFailedNavigation {
102
112
  mode: TNavigationMode;
103
113
  /** The location the navigation would have written. */
104
114
  location: string;
115
+ /** For a return that ends a flow somewhere else, the location of the screen the flow started from; `null` for an origin that names no screen. */
116
+ origin?: string | null;
105
117
  }
106
118
 
107
119
  /** What the shell shows around a view: its section menu, its content tabs and its content heading. */
@@ -2508,8 +2520,10 @@ export class DeesAppui extends DeesElement {
2508
2520
  * `options.history` decides whether that leaves a step behind: `push` (the
2509
2521
  * default) adds a history entry, `replace` rewrites the current one, which is
2510
2522
  * what a screen correcting its own route needs, and `return` goes back to the
2511
- * screen a step was taken from, where the entry before the current one shows
2512
- * it, and replaces the current entry elsewhere.
2523
+ * screen a flow was started from, across the steps it took on its own screen,
2524
+ * and replaces the current entry where no entry before shows it. With
2525
+ * `options.origin`, a return ends the flow on another screen, such as the one
2526
+ * it made: it goes back to the origin and pushes the screen after it.
2513
2527
  */
2514
2528
  public navigateToView(
2515
2529
  viewId: string,
@@ -2518,10 +2532,19 @@ export class DeesAppui extends DeesElement {
2518
2532
  options?: interfaces.IViewNavigationOptions,
2519
2533
  ): Promise<boolean> {
2520
2534
  const mode = options?.history === 'replace' || options?.history === 'return' ? options.history : 'push';
2535
+ // An origin that names no screen is one no entry shows: the return replaces (`null`).
2536
+ const origin = mode === 'return' && options?.origin ? this.locationOf(options.origin) ?? null : undefined;
2521
2537
  // A replacing navigation is a screen correcting its own route: nobody asked
2522
2538
  // to be taken anywhere, so the focus stays where the reader put it. A return
2523
2539
  // takes the reader back, as Back does.
2524
- return this.queueNavigation(viewId, { ...params }, { ...query }, mode, mode === 'replace' ? 'system' : 'reader');
2540
+ return this.queueNavigation(
2541
+ viewId, { ...params }, { ...query }, mode, mode === 'replace' ? 'system' : 'reader', undefined, undefined, origin);
2542
+ }
2543
+
2544
+ /** The location of a screen named by a view and its parameters; none for a route that names no screen. */
2545
+ private locationOf(routeArg: { viewId: string; params?: Record<string, string>; query?: Record<string, string> }): string | undefined {
2546
+ const address = this.addressOf({ viewId: routeArg.viewId, params: { ...routeArg.params }, query: { ...routeArg.query } });
2547
+ return address === undefined ? undefined : this.addressing.locationOf(address);
2525
2548
  }
2526
2549
 
2527
2550
  private navigationQueue: Promise<boolean> = Promise.resolve(true);
@@ -2532,8 +2555,8 @@ export class DeesAppui extends DeesElement {
2532
2555
  private historyIndex = 0;
2533
2556
  /** Numbers the history entries this shell writes, so an entry it pushes can name the one it was pushed from. */
2534
2557
  private historyEntries = 0;
2535
- /** The location each history entry this shell wrote shows, by the entry's number: what a return finds before it (`returnsBack`). */
2536
- private historyEntryLocations = new Map<number, string>();
2558
+ /** Each history entry this shell wrote, by its number: what a return finds before the current one (`stepsBackTo`). */
2559
+ private historyEntryRecords = new Map<number, IHistoryEntry>();
2537
2560
  /** The traversal back a refused browser change started, to `location`; the next change of any address ends it. */
2538
2561
  private restoringHistory?: { location: string; resolve: () => void };
2539
2562
 
@@ -2545,9 +2568,10 @@ export class DeesAppui extends DeesElement {
2545
2568
  intent: TNavigationIntent,
2546
2569
  index?: number,
2547
2570
  traversalLocation?: string,
2571
+ origin?: string | null,
2548
2572
  ): Promise<boolean> {
2549
2573
  return this.enqueue((generation, request) =>
2550
- this.performNavigation(viewId, params, query, mode, intent, generation, request, index, traversalLocation));
2574
+ this.performNavigation(viewId, params, query, mode, intent, generation, request, index, traversalLocation, origin));
2551
2575
  }
2552
2576
 
2553
2577
  /**
@@ -2585,6 +2609,7 @@ export class DeesAppui extends DeesElement {
2585
2609
  request: number,
2586
2610
  index?: number,
2587
2611
  traversalLocation?: string,
2612
+ origin?: string | null,
2588
2613
  ): Promise<boolean> {
2589
2614
  // Out of date: the shell was disconnected or configured again since the request.
2590
2615
  const stale = () => !this.isConnected || generation !== this.routingGeneration;
@@ -2660,11 +2685,18 @@ export class DeesAppui extends DeesElement {
2660
2685
  void this.takeReaderTo(element);
2661
2686
  void this.announceView(view.name);
2662
2687
  }
2688
+ const stepsBack = mode === 'return' && origin !== null ? this.stepsBackTo(origin ?? location) : 0;
2663
2689
  if (mode === 'push') {
2664
2690
  this.historyIndex++;
2665
2691
  window.history.pushState(this.routeHistoryState(location, true), '', location);
2666
- } else if (mode === 'return' && this.returnsBack(location)) {
2667
- await this.goBackTo(location);
2692
+ } else if (stepsBack > 0) {
2693
+ await this.goBackTo(origin ?? location, stepsBack);
2694
+ // A flow that ends on a screen of its own, such as the one it made, leaves
2695
+ // it one step after the screen it started from — once the browser stands there.
2696
+ if (origin !== undefined && origin !== location && !stale() && this.addressing.currentLocation() === origin) {
2697
+ this.historyIndex++;
2698
+ window.history.pushState(this.routeHistoryState(location, true), '', location);
2699
+ }
2668
2700
  } else {
2669
2701
  if (index !== undefined) this.historyIndex = index;
2670
2702
  // Traversal already moved the browser. Do not overwrite a newer queued traversal.
@@ -2677,7 +2709,7 @@ export class DeesAppui extends DeesElement {
2677
2709
  if (superseded()) return false;
2678
2710
  this.viewLifecycle$.next({ type: 'loadError', viewId, error });
2679
2711
  // The content area speaks about the screen that was asked for, and the menu marks it.
2680
- this.failedNavigation = { view, params, query, mode, location };
2712
+ this.failedNavigation = { view, params, query, mode, location, origin };
2681
2713
  this.markViewInMainMenu(viewId);
2682
2714
  return false;
2683
2715
  }
@@ -2724,7 +2756,8 @@ export class DeesAppui extends DeesElement {
2724
2756
  const mode = failed.mode === 'replace' || this.addressing.currentLocation() === failed.location
2725
2757
  ? 'replace'
2726
2758
  : failed.mode === 'return' ? 'return' : 'push';
2727
- void this.queueNavigation(failed.view.id, failed.params, failed.query, mode, 'reader');
2759
+ const origin = mode === 'return' ? failed.origin : undefined;
2760
+ void this.queueNavigation(failed.view.id, failed.params, failed.query, mode, 'reader', undefined, undefined, origin);
2728
2761
  }
2729
2762
 
2730
2763
  /**
@@ -2753,15 +2786,17 @@ export class DeesAppui extends DeesElement {
2753
2786
  * The state of a history entry the shell writes, showing a location: where the
2754
2787
  * entry stands (`historyIndex`) and a number of its own. An entry pushed also
2755
2788
  * names the entry it was pushed from, the one right before it; one rewritten
2756
- * keeps its number and the entry before it. The location an entry shows is
2757
- * kept by its number, so a return can tell what the entry before shows
2758
- * (`returnsBack`).
2789
+ * keeps its number and the entry before it. The location an entry shows, the
2790
+ * view on show there and the entry before it are kept by its number, so a
2791
+ * return can tell what the entries before show (`stepsBackTo`).
2759
2792
  */
2760
2793
  private routeHistoryState(locationArg?: string, pushedArg = false) {
2761
2794
  const current = this.historyMarker();
2762
2795
  const entry = pushedArg || !current ? ++this.historyEntries : current.entry;
2763
2796
  const previous = pushedArg ? current?.entry : current?.previous;
2764
- if (locationArg !== undefined) this.historyEntryLocations.set(entry, locationArg);
2797
+ if (locationArg !== undefined) {
2798
+ this.historyEntryRecords.set(entry, { location: locationArg, viewId: this.currentRoute?.viewId, previous });
2799
+ }
2765
2800
  const marker: IHistoryMarker = { owner: this.historyOwner, index: this.historyIndex, entry, previous };
2766
2801
  return { ...window.history.state, deesAppui: marker };
2767
2802
  }
@@ -2789,33 +2824,43 @@ export class DeesAppui extends DeesElement {
2789
2824
  }
2790
2825
 
2791
2826
  /**
2792
- * Whether a return to a location goes back: the browser stands where this
2793
- * shell is, on an entry it pushed, and the entry that one was pushed from —
2794
- * the one right before it — still shows the location. An entry the shell did
2795
- * not push from one of its own, such as the first one after a reload or a deep
2796
- * link into a flow, has no entry before it the shell knows, so a return from it
2797
- * replaces. So does one whose address shows the location already: going back
2798
- * from it would change no address, and no change would say it landed.
2827
+ * How many entries a return to a location goes back: the browser stands where
2828
+ * this shell is, on an entry it pushed, and walks back along the entries each
2829
+ * one was pushed from — the one right before it — to the nearest that shows
2830
+ * the location. The entries it passes are the steps of a flow on the current
2831
+ * entry's own screen; an entry of another screen in between was a stop of the
2832
+ * reader's own, so the walk ends there and the return replaces, as it does
2833
+ * from an entry the shell did not push from one of its own, such as the first
2834
+ * one after a reload or a deep link into a flow. So does a return from an
2835
+ * entry whose address shows the location already: going back from it would
2836
+ * change no address, and no change would say it landed. None is `0`.
2799
2837
  */
2800
- private returnsBack(locationArg: string): boolean {
2838
+ private stepsBackTo(locationArg: string): number {
2801
2839
  const marker = this.historyMarker();
2802
- return marker?.index === this.historyIndex
2803
- && marker.previous !== undefined
2804
- && this.historyEntryLocations.get(marker.previous) === locationArg
2805
- && this.addressing.currentLocation() !== locationArg;
2840
+ if (marker?.index !== this.historyIndex || this.addressing.currentLocation() === locationArg) return 0;
2841
+ const flowView = this.historyEntryRecords.get(marker.entry)?.viewId;
2842
+ let previous = marker.previous;
2843
+ for (let steps = 1; previous !== undefined; steps++) {
2844
+ const record = this.historyEntryRecords.get(previous);
2845
+ if (!record) return 0;
2846
+ if (record.location === locationArg) return steps;
2847
+ if (record.viewId !== flowView) return 0;
2848
+ previous = record.previous;
2849
+ }
2850
+ return 0;
2806
2851
  }
2807
2852
 
2808
2853
  /**
2809
- * Goes back one entry, to the location of the screen already on show, and
2810
- * waits until the browser stands there, so no request writes history from
2811
- * the entry it leaves. The change the browser brings finds that location
2812
- * and is not taken as a move of the reader's (`restoringHistory`).
2854
+ * Goes back a number of entries, to the location they show, and waits until
2855
+ * the browser stands there, so no request writes history from the entry it
2856
+ * leaves. The change the browser brings finds that location and is not taken
2857
+ * as a move of the reader's (`restoringHistory`).
2813
2858
  */
2814
- private goBackTo(locationArg: string): Promise<void> {
2815
- this.historyIndex--;
2859
+ private goBackTo(locationArg: string, stepsArg: number): Promise<void> {
2860
+ this.historyIndex -= stepsArg;
2816
2861
  return new Promise<void>((resolve) => {
2817
2862
  this.restoringHistory = { location: locationArg, resolve };
2818
- window.history.back();
2863
+ window.history.go(-stepsArg);
2819
2864
  });
2820
2865
  }
2821
2866
 
@@ -3033,7 +3078,7 @@ export class DeesAppui extends DeesElement {
3033
3078
  this.failedNavigation = undefined;
3034
3079
  this.historyOwner = `${Date.now()}-${Math.random()}`;
3035
3080
  this.historyIndex = 0;
3036
- this.historyEntryLocations.clear();
3081
+ this.historyEntryRecords.clear();
3037
3082
  }
3038
3083
 
3039
3084
  /** Follow the address: mark the entry the shell stands on, listen for its changes, show the first screen. */
@@ -1467,19 +1467,28 @@ A fourth argument decides what the navigation leaves behind:
1467
1467
  `navigateToView(viewId, params, query, { history: 'replace' })` rewrites the current
1468
1468
  history entry instead of adding one, which is what a screen correcting its own route — a
1469
1469
  redirect to a default section, a normalized identifier — needs so that Back still returns
1470
- to the screen the reader came from. `{ history: 'return' }` ends a step the reader took
1470
+ to the screen the reader came from. `{ history: 'return' }` ends a flow the reader opened
1471
1471
  from the screen asked for — a flow opened from a list that goes back to it once it is done
1472
- or closed: when the entry before the current one shows that screen, the shell goes back to
1473
- it, so the flow's entry stays only as Forward and Back leaves the list rather than showing
1474
- it once more; otherwise, as after a reload or a deep link into the flow, it replaces the
1475
- current entry. `navigateToUrl(href, { history })` takes the same options. Unset, both
1476
- push, as they always have.
1472
+ or closed: when an entry before the current one shows that screen, the shell goes back to
1473
+ it, across the entries the flow pushed for its steps on its own view, so they stay only as
1474
+ Forward and Back leaves the list rather than showing it, or a step of the flow, once more;
1475
+ otherwise, as after a reload, a deep link into the flow or a stop on another view in
1476
+ between, it replaces the current entry. A flow that ends on another screen — the record it
1477
+ created — names the screen it started from as `origin`: the shell goes back to that screen
1478
+ and pushes the record after it, so Back from the record returns to the list; where a return
1479
+ to the origin would replace, or the origin names no screen, the record replaces the current
1480
+ entry.
1481
+ `navigateToUrl(href, { history, origin })` takes the same options. Unset, both push, as
1482
+ they always have.
1477
1483
 
1478
1484
  ```typescript
1479
- // The list opens the flow as a step of its own…
1485
+ // The list opens the flow as a step of its own, and each step pushes one more…
1480
1486
  await appui.navigateToView('invoice', { id: 'new' });
1481
- // …and the flow, once done or closed, goes back to the list it was opened from.
1487
+ await appui.navigateToView('invoice', { id: 'new' }, { step: 'details' });
1488
+ // …and the flow, once closed, goes back to the list it was opened from…
1482
1489
  await appui.navigateToView('invoices', {}, {}, { history: 'return' });
1490
+ // …or, once done, shows what it made one step after that list.
1491
+ await appui.navigateToView('invoice', { id: created.id }, {}, { history: 'return', origin: { viewId: 'invoices' } });
1483
1492
  ```
1484
1493
 
1485
1494
  A guard that returns a string asks a question, and the shell asks it in a `dees-modal`
@@ -248,15 +248,30 @@ export interface IViewNavigationOptions {
248
248
  * left behind. `replace` rewrites the current entry instead — for a screen
249
249
  * that corrects its own route, such as a redirect to a default section or a
250
250
  * normalized identifier, which must not become a step of its own. `return`
251
- * ends a step the reader took from the screen asked for — a flow opened
252
- * from a list that goes back to it once it is done or closed: when the
253
- * entry before the current one shows that screen, the shell goes back to
254
- * it, so the flow's entry stays only as Forward and Back leaves the screen
255
- * the reader came from rather than showing it once more; otherwise, as
256
- * after a reload or a deep link into the flow, it replaces the current
257
- * entry.
251
+ * ends a flow the reader opened from the screen asked for — a flow opened
252
+ * from a list that goes back to it once it is done or closed: when an entry
253
+ * before the current one shows that screen, the shell goes back to it,
254
+ * across the entries the flow pushed for its steps on its own screen, so
255
+ * they stay only as Forward and Back leaves the screen the reader came from
256
+ * rather than showing it, or a step of the flow, once more; otherwise, as
257
+ * after a reload, a deep link into the flow or a stop on another screen in
258
+ * between, it replaces the current entry.
258
259
  */
259
260
  history?: 'push' | 'replace' | 'return';
261
+ /**
262
+ * With `history: 'return'`, the screen the flow started from, where the
263
+ * flow ends on another screen — the record it created, say. The shell goes
264
+ * back to the entry showing the origin, as a return to it would, and pushes
265
+ * the screen asked for after it, so Back from the record returns to the
266
+ * list rather than into the finished flow. Where a return to the origin
267
+ * would replace, or the origin names no screen, the screen asked for
268
+ * replaces the current entry.
269
+ */
270
+ origin?: {
271
+ viewId: string;
272
+ params?: Record<string, string>;
273
+ query?: Record<string, string>;
274
+ };
260
275
  }
261
276
 
262
277
  /**