@design.estate/dees-catalog 24.3.0 → 24.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.
@@ -4,9 +4,11 @@ import type {
4
4
  IAppShellStorageErrorEvent,
5
5
  IAppTrayTab,
6
6
  TAppuiAside,
7
- TAppuiPane,
8
7
  } from '../../interfaces/appconfig.js';
9
8
 
9
+ /** A pane that has a width of its own: the section menu, and the side panel whichever tool it shows. */
10
+ export type TShellPane = 'secondary' | 'aside';
11
+
10
12
  /**
11
13
  * What the shell keeps through a host's storage adapter, one key each, stored
12
14
  * as `dees-appui.<key>` with a JSON value.
@@ -15,7 +17,10 @@ export interface IShellStoredState {
15
17
  mainMenuCollapsed: boolean;
16
18
  secondaryMenuCollapsed: boolean;
17
19
  secondaryPaneWidth: number;
20
+ asidePaneWidth: number;
21
+ /** Read only: the activity log's width from before the side panel had one width. */
18
22
  activityPaneWidth: number;
23
+ /** Read only: the assistant's width from before the side panel had one width. */
19
24
  assistantPaneWidth: number;
20
25
  aside: TAppuiAside | null;
21
26
  lastView: IAppRoute;
@@ -24,8 +29,24 @@ export interface IShellStoredState {
24
29
 
25
30
  export type TShellStoredKey = keyof IShellStoredState;
26
31
 
32
+ /** The keys whose values have the shape `V`. */
33
+ type TShellStoredKeyOf<V> = { [K in TShellStoredKey]: IShellStoredState[K] extends V ? K : never }[TShellStoredKey];
34
+
27
35
  /** The key a pane's width is kept under. */
28
- export const paneWidthKey = (pane: TAppuiPane) => `${pane}PaneWidth` as const;
36
+ export const paneWidthKey = (pane: TShellPane) => `${pane}PaneWidth` as const;
37
+
38
+ /**
39
+ * Keys a newer key took over from, asked together with it and taken in this
40
+ * order while the newer one holds nothing usable. The first that holds a value
41
+ * is applied and written under the newer key, so it is taken once: the shell
42
+ * writes only the newer key, which answers from then on. Asked in the same
43
+ * round as the newer key, they cost an adapter over a server no extra wait.
44
+ * The side panel's one width starts from the assistant's width a reader left,
45
+ * else the activity log's.
46
+ */
47
+ const supersededKeys: { [K in TShellStoredKey]?: readonly TShellStoredKeyOf<IShellStoredState[K]>[] } = {
48
+ asidePaneWidth: ['assistantPaneWidth', 'activityPaneWidth'],
49
+ };
29
50
 
30
51
  /** The key the adapter sees: the shell's keys live under one namespace. */
31
52
  const storageKey = (key: TShellStoredKey): string => `dees-appui.${key}`;
@@ -63,6 +84,7 @@ const storedShapes: { [K in TShellStoredKey]: (value: unknown) => value is IShel
63
84
  mainMenuCollapsed: isBoolean,
64
85
  secondaryMenuCollapsed: isBoolean,
65
86
  secondaryPaneWidth: isWidth,
87
+ asidePaneWidth: isWidth,
66
88
  activityPaneWidth: isWidth,
67
89
  assistantPaneWidth: isWidth,
68
90
  aside: (value): value is TAppuiAside | null => value === null || value === 'activity' || value === 'assistant',
@@ -95,20 +117,29 @@ export class ShellStorage {
95
117
  * Applies a key's stored value. An adapter that answers at once is applied
96
118
  * at once, before the render the caller is part of, so nothing shows the
97
119
  * value it replaces. A later answer is applied when it arrives, unless
98
- * another storage took over or the key was written meanwhile. Resolves once
99
- * the answer is applied or dropped.
120
+ * another storage took over or the key was written meanwhile. The keys it
121
+ * superseded are asked with it; while the key holds nothing usable, the
122
+ * first of them that does is applied and written under the key. Resolves
123
+ * once the answer is applied or dropped.
100
124
  */
101
125
  public restore<K extends TShellStoredKey>(key: K, apply: (value: IShellStoredState[K]) => void): Promise<void> {
102
- const settle = (stored: string | undefined) => {
103
- const value = this.decode(key, stored);
104
- if (value !== undefined) apply(value);
126
+ // A superseded key holds a value of its successor's shape, which its own guard checks.
127
+ const sources = [key, ...(supersededKeys[key] ?? [])] as K[];
128
+ const settle = (stored: (string | undefined)[]) => {
129
+ for (const [index, source] of sources.entries()) {
130
+ const value = this.decode(source, stored[index]);
131
+ if (value === undefined) continue;
132
+ apply(value);
133
+ if (source !== key) this.write(key, value);
134
+ return;
135
+ }
105
136
  };
106
- const answer = this.readStored(key);
107
- if (!(answer instanceof Promise)) {
108
- settle(answer);
137
+ const answers = sources.map((source) => this.readStored(source));
138
+ if (!answers.some((answer) => answer instanceof Promise)) {
139
+ settle(answers as (string | undefined)[]);
109
140
  return Promise.resolve();
110
141
  }
111
- return answer.then((stored) => {
142
+ return Promise.all(answers).then((stored) => {
112
143
  if (!this.retired && !this.written.has(key)) settle(stored);
113
144
  });
114
145
  }
@@ -109,11 +109,13 @@ export interface IBottomBarAPI {
109
109
  }
110
110
 
111
111
  /**
112
- * A pane a reader can resize: `secondary` is the section menu, `activity` the
113
- * activity log and `assistant` the host's assistant, the two tools of the side
114
- * panel. The main menu is not one: it is either a rail or expanded.
112
+ * A pane a reader can resize: `secondary` is the section menu, `aside` the
113
+ * side panel, which has one width whichever tool it shows. `activity` and
114
+ * `assistant` are deprecated names of `aside`, from when each tool had a width
115
+ * of its own: they size and read the same one width. The main menu is not
116
+ * one: it is either a rail or expanded.
115
117
  */
116
- export type TAppuiPane = 'secondary' | 'activity' | 'assistant';
118
+ export type TAppuiPane = 'secondary' | 'aside' | 'activity' | 'assistant';
117
119
 
118
120
  /**
119
121
  * A tool the side panel on the content's end edge shows, one at a time:
@@ -463,9 +465,10 @@ export interface IActivityLogConfig {
463
465
  */
464
466
  toggle?: boolean;
465
467
  /**
466
- * The activity log's width in CSS pixels, clamped to 240–480. Unset keeps the
467
- * width the pane has: 280 at first. A width the reader left it at, read from
468
- * `IAppConfig.storage`, wins.
468
+ * The side panel's first width in CSS pixels, as `IAppConfig.asideWidth`
469
+ * sets it, which wins, as does `IAppAssistantConfig.width`.
470
+ * @deprecated The side panel has one width whichever tool it shows: set
471
+ * `IAppConfig.asideWidth`.
469
472
  */
470
473
  width?: number;
471
474
  }
@@ -485,9 +488,10 @@ export interface IAppAssistantConfig {
485
488
  /** The icon of the app bar button and the palette command (default: `lucide:Sparkles`). */
486
489
  iconName?: string;
487
490
  /**
488
- * The assistant's width in CSS pixels, clamped to 320–640. Unset keeps the
489
- * width the pane has: 400 at first. A width the reader left it at, read from
490
- * `IAppConfig.storage`, wins.
491
+ * The side panel's first width in CSS pixels, as `IAppConfig.asideWidth`
492
+ * sets it, which wins; this wins over `IActivityLogConfig.width`.
493
+ * @deprecated The side panel has one width whichever tool it shows: set
494
+ * `IAppConfig.asideWidth`.
491
495
  */
492
496
  width?: number;
493
497
  /**
@@ -609,6 +613,15 @@ export interface IAppConfig {
609
613
  */
610
614
  aside?: TAppuiAside | null;
611
615
 
616
+ /**
617
+ * The side panel's width in CSS pixels, clamped to 320–640, the same
618
+ * whichever tool it shows: opening, switching and closing a tool never
619
+ * change it. Unset keeps the width the panel has: 400 at first. A width the
620
+ * reader left it at, read from `storage`, wins. Wins over the deprecated
621
+ * `assistant.width`, which wins over the deprecated `activityLog.width`.
622
+ */
623
+ asideWidth?: number;
624
+
612
625
  /** Bottom bar configuration */
613
626
  bottomBar?: IBottomBarConfig;
614
627
 
@@ -671,6 +684,12 @@ export interface IViewChangeEvent {
671
684
  * new width, in CSS pixels — at the end of a drag, or with a key.
672
685
  */
673
686
  export interface IPaneResizeEvent {
687
+ /**
688
+ * `secondary`, or for the side panel the tool it showed, `activity` or
689
+ * `assistant`, as hosts written while each tool had a width of its own
690
+ * expect. Either is a deprecated name of `aside`: `width` is the panel's one
691
+ * width, whichever tool it shows.
692
+ */
674
693
  pane: TAppuiPane;
675
694
  width: number;
676
695
  }