@sincpro/web-composer 0.1.0 → 1.1.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.
Files changed (41) hide show
  1. package/README.md +139 -67
  2. package/dist/domain/enums.d.ts +0 -10
  3. package/dist/domain/enums.js +0 -8
  4. package/dist/domain/index.d.ts +4 -4
  5. package/dist/domain/index.js +4 -4
  6. package/dist/domain/layout.d.ts +37 -20
  7. package/dist/domain/layout.js +136 -100
  8. package/dist/domain/registry.d.ts +33 -7
  9. package/dist/domain/url.d.ts +13 -0
  10. package/dist/domain/url.js +43 -5
  11. package/dist/domain/workspace.d.ts +43 -7
  12. package/dist/domain/workspace.js +136 -15
  13. package/dist/index.d.ts +9 -5
  14. package/dist/index.js +8 -4
  15. package/dist/shell/Composer.d.ts +5 -6
  16. package/dist/shell/Composer.js +42 -13
  17. package/dist/shell/Palette.js +11 -10
  18. package/dist/shell/PanelFrame.d.ts +10 -3
  19. package/dist/shell/PanelFrame.js +57 -31
  20. package/dist/shell/PanelHost.js +44 -31
  21. package/dist/shell/Peek.d.ts +26 -0
  22. package/dist/shell/Peek.js +64 -0
  23. package/dist/shell/RecordLink.js +12 -8
  24. package/dist/shell/ViewHost.js +17 -6
  25. package/dist/shell/copy.d.ts +10 -1
  26. package/dist/shell/copy.js +29 -7
  27. package/dist/shell/icons.d.ts +22 -0
  28. package/dist/shell/icons.js +19 -0
  29. package/dist/shell/skin.d.ts +72 -0
  30. package/dist/shell/skin.js +35 -0
  31. package/dist/shell/styles.d.ts +19 -0
  32. package/dist/shell/styles.js +212 -0
  33. package/dist/state/api.d.ts +7 -3
  34. package/dist/state/api.js +109 -63
  35. package/dist/state/store.d.ts +27 -3
  36. package/dist/state/store.js +165 -41
  37. package/dist/state/useKeyboard.d.ts +4 -0
  38. package/dist/state/useKeyboard.js +11 -3
  39. package/dist/state/useWorkspace.d.ts +5 -1
  40. package/dist/state/useWorkspace.js +6 -0
  41. package/package.json +11 -10
@@ -0,0 +1,212 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * The composer's own skin: the frames, the drawer, the rail, the dialog and ⌘K, with no design
4
+ * system behind it. It is the minimum that makes the windows usable — the views inside them are
5
+ * the application's, drawn with whatever it uses.
6
+ *
7
+ * Every color, radius and shadow is a CSS variable with a default, so an application themes it
8
+ * from anywhere above the workspace (`:root` included) without a stylesheet of its own:
9
+ *
10
+ * :root {
11
+ * --sc-surface: var(--my-surface);
12
+ * --sc-accent: var(--my-brand);
13
+ * }
14
+ *
15
+ * The classes (`sc-*`) are stable: they are how a skin is overridden. The sheet is a React 19
16
+ * `<style href precedence>`: hoisted to <head> and drawn once however many workspaces there are,
17
+ * so nothing has to be imported.
18
+ */
19
+ const CSS = `
20
+ .sc-root {
21
+ --_ground: var(--sc-ground, light-dark(#f6f6f4, #161615));
22
+ --_surface: var(--sc-surface, light-dark(#ffffff, #1f1f1d));
23
+ --_line: var(--sc-line, light-dark(#e4e3df, #2f2f2c));
24
+ --_line-strong: var(--sc-line-strong, light-dark(#cfcdc7, #44433f));
25
+ --_ink: var(--sc-ink, light-dark(#1d1d1b, #ecebe7));
26
+ --_muted: var(--sc-muted, light-dark(#6b6a66, #a3a29d));
27
+ --_accent: var(--sc-accent, light-dark(#2b4a8b, #8fb0f0));
28
+ --_danger: var(--sc-danger, light-dark(#b3261e, #f2958e));
29
+ --_on-danger: var(--sc-on-danger, #ffffff);
30
+ --_scrim: var(--sc-scrim, rgb(0 0 0 / 0.32));
31
+ --_shadow: var(--sc-shadow, 0 10px 30px rgb(0 0 0 / 0.16));
32
+ --_radius: var(--sc-radius, 8px);
33
+ --_radius-control: var(--sc-radius-control, 6px);
34
+ --_text: var(--sc-text, 13px);
35
+ --_text-small: var(--sc-text-small, 12px);
36
+ --_tint: color-mix(in srgb, var(--_accent) 10%, transparent);
37
+ --_hover: color-mix(in srgb, var(--_ink) 7%, transparent);
38
+
39
+ position: relative;
40
+ display: flex;
41
+ flex: 1;
42
+ flex-direction: column;
43
+ min-height: 0;
44
+ background: var(--_ground);
45
+ color: var(--_ink);
46
+ font-size: var(--_text);
47
+ }
48
+ .sc-root *, .sc-root *::before, .sc-root *::after { box-sizing: border-box; }
49
+ .sc-root :focus-visible { outline: 2px solid var(--_accent); outline-offset: 1px; }
50
+
51
+ .sc-empty { display: flex; flex: 1; min-height: 0; align-items: center; justify-content: center; padding: 32px; }
52
+ .sc-host { position: relative; flex: 1; min-height: 0; overflow: hidden; }
53
+ .sc-slot { position: absolute; isolation: isolate; min-height: 0; }
54
+ .sc-slot[data-page] { overflow: auto; }
55
+ .sc-slot[data-pad="all"] { padding: 4px; }
56
+ .sc-slot[data-pad="x"] { padding: 0 4px; }
57
+ .sc-slot[data-pad="y"] { padding: 4px 0; }
58
+
59
+ .sc-frame {
60
+ display: flex; flex-direction: column; height: 100%; min-height: 0; min-width: 0;
61
+ overflow: hidden; background: var(--_surface);
62
+ border: 1px solid var(--_line-strong); border-radius: var(--_radius);
63
+ }
64
+ .sc-frame[data-focused] { border-color: var(--_accent); box-shadow: 0 0 0 1px var(--_tint); }
65
+ .sc-frame[data-floating] { box-shadow: var(--_shadow); }
66
+ .sc-frame[data-dragging] { opacity: 0.4; }
67
+
68
+ .sc-header {
69
+ position: relative; display: flex; flex-shrink: 0; align-items: center; gap: 2px;
70
+ height: 34px; padding: 0 3px 0 10px; background: var(--_ground);
71
+ border-bottom: 1px solid var(--_line); user-select: none; cursor: grab;
72
+ }
73
+ .sc-header[data-floating] { cursor: move; touch-action: none; }
74
+ .sc-header[data-rail] {
75
+ flex: 1; flex-direction: column; height: auto; padding: 3px 0; border-bottom: 0;
76
+ }
77
+ .sc-title {
78
+ flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
79
+ font-size: var(--_text-small); font-weight: 500;
80
+ }
81
+ .sc-header[data-rail] .sc-title { min-height: 0; padding: 4px 0; writing-mode: vertical-rl; }
82
+ .sc-body { flex: 1; min-height: 0; overflow: auto; container-type: inline-size; }
83
+
84
+ .sc-control {
85
+ display: inline-flex; flex-shrink: 0; align-items: center; justify-content: center;
86
+ width: 26px; height: 26px; padding: 0; border: 0; border-radius: var(--_radius-control);
87
+ background: transparent; color: var(--_muted); cursor: pointer;
88
+ }
89
+ .sc-control:hover { background: var(--_hover); color: var(--_ink); }
90
+ .sc-control[aria-pressed="true"], .sc-control[aria-expanded="true"] { background: var(--_tint); color: var(--_accent); }
91
+ .sc-control[data-danger]:hover { color: var(--_danger); }
92
+
93
+ .sc-menu {
94
+ position: absolute; top: calc(100% + 2px); right: 4px; z-index: 50; min-width: 220px;
95
+ margin: 0; padding: 4px; list-style: none; background: var(--_surface);
96
+ border: 1px solid var(--_line-strong); border-radius: var(--_radius); box-shadow: var(--_shadow);
97
+ cursor: default;
98
+ }
99
+ .sc-menu-label { padding: 6px 8px 2px; color: var(--_muted); font-size: var(--_text-small); }
100
+ .sc-menu-item {
101
+ display: flex; width: 100%; align-items: center; gap: 8px; padding: 6px 8px;
102
+ border: 0; border-radius: var(--_radius-control); background: transparent;
103
+ color: var(--_ink); font: inherit; text-align: left; cursor: pointer;
104
+ }
105
+ .sc-menu-item:hover, .sc-menu-item:focus { background: var(--_hover); outline: 0; }
106
+ .sc-menu-item[aria-checked="true"] { color: var(--_accent); font-weight: 600; }
107
+ .sc-menu-hint { margin-left: auto; color: var(--_muted); font-size: var(--_text-small); font-weight: 400; }
108
+
109
+ .sc-handle { position: absolute; z-index: 10; transition: background-color 80ms; touch-action: none; }
110
+ .sc-handle[data-axis="x"] { cursor: col-resize; }
111
+ .sc-handle[data-axis="y"] { cursor: row-resize; }
112
+ .sc-handle:hover { background: color-mix(in srgb, var(--_accent) 25%, transparent); }
113
+ .sc-root .sc-handle:focus-visible { background: color-mix(in srgb, var(--_accent) 35%, transparent); outline: 0; }
114
+
115
+ .sc-grip { position: absolute; z-index: 10; touch-action: none; }
116
+ .sc-grip[data-grip="e"] { top: 0; right: 0; width: 8px; height: 100%; cursor: e-resize; }
117
+ .sc-grip[data-grip="s"] { bottom: 0; left: 0; width: 100%; height: 8px; cursor: s-resize; }
118
+ .sc-grip[data-grip="se"] { right: 0; bottom: 0; width: 16px; height: 16px; cursor: se-resize; }
119
+
120
+ .sc-drops { position: absolute; inset: 0; pointer-events: none; }
121
+ .sc-drop {
122
+ position: absolute; z-index: 30; display: flex; align-items: center; justify-content: center;
123
+ border: 2px dashed transparent; border-radius: var(--_radius); pointer-events: none;
124
+ color: var(--_accent); font-size: var(--_text-small); font-weight: 500;
125
+ }
126
+ .sc-drop[data-armed] { pointer-events: auto; }
127
+ .sc-drop[data-over] { border-color: var(--_accent); background: var(--_tint); }
128
+
129
+ .sc-overlay { position: absolute; z-index: 40; pointer-events: none; }
130
+ .sc-overlay > * { pointer-events: auto; }
131
+
132
+ .sc-peek {
133
+ position: absolute; top: 0; right: 0; bottom: 0; z-index: 30;
134
+ display: flex; flex-direction: column; width: min(30rem, 100%); overflow: hidden;
135
+ background: var(--_surface); border-left: 1px solid var(--_line-strong);
136
+ border-radius: var(--_radius) 0 0 var(--_radius); box-shadow: var(--_shadow); outline: 0;
137
+ }
138
+ .sc-peek-head { display: flex; flex-shrink: 0; align-items: center; gap: 8px; padding: 8px 8px 8px 12px; border-bottom: 1px solid var(--_line); }
139
+ .sc-peek-title {
140
+ flex: 1; min-width: 0; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
141
+ font-size: var(--_text); font-weight: 600;
142
+ }
143
+ .sc-peek-actions { display: flex; flex-shrink: 0; flex-wrap: wrap; gap: 6px; padding: 6px 12px; border-bottom: 1px solid var(--_line); }
144
+ .sc-peek-body { flex: 1; min-height: 0; overflow: auto; padding: 12px; container-type: inline-size; }
145
+
146
+ .sc-button {
147
+ display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px;
148
+ border: 1px solid var(--_line-strong); border-radius: var(--_radius-control);
149
+ background: var(--_surface); color: var(--_ink); font: inherit; font-size: var(--_text-small);
150
+ font-weight: 500; white-space: nowrap; cursor: pointer;
151
+ }
152
+ .sc-button:hover { background: var(--_hover); }
153
+ .sc-button[data-role="ghost"] { border-color: transparent; background: transparent; color: var(--_accent); }
154
+ .sc-button[data-role="ghost"]:hover { background: var(--_tint); }
155
+ .sc-button[data-role="danger"] { border-color: var(--_danger); background: var(--_danger); color: var(--_on-danger); }
156
+
157
+ .sc-dialog {
158
+ width: min(26rem, calc(100% - 32px)); padding: 0; border: 0; border-radius: var(--_radius);
159
+ background: var(--_surface); color: var(--_ink); box-shadow: var(--_shadow);
160
+ }
161
+ .sc-dialog::backdrop { background: var(--_scrim); }
162
+ .sc-dialog-title { margin: 0; padding: 16px 16px 0; font-size: 16px; font-weight: 600; }
163
+ .sc-dialog-body { margin: 0; padding: 10px 16px 16px; color: var(--_muted); }
164
+ .sc-dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--_line); background: var(--_ground); }
165
+
166
+ .sc-notice { padding: 24px; color: var(--_muted); text-align: center; }
167
+ .sc-notice strong { display: block; margin-bottom: 4px; color: var(--_ink); }
168
+ .sc-notice[data-tone="bad"] strong { color: var(--_danger); }
169
+ .sc-notice code { font-size: var(--_text-small); }
170
+ .sc-loading { padding: 16px; color: var(--_muted); font-size: var(--_text-small); }
171
+
172
+ .sc-scrim {
173
+ position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-start;
174
+ justify-content: center; padding: 96px 16px 0; background: var(--_scrim);
175
+ }
176
+ .sc-palette {
177
+ width: 100%; max-width: 36rem; overflow: hidden; background: var(--_surface);
178
+ border: 1px solid var(--_line-strong); border-radius: var(--_radius); box-shadow: var(--_shadow);
179
+ }
180
+ .sc-palette-search { display: flex; align-items: center; gap: 8px; padding: 0 12px; border-bottom: 1px solid var(--_line); color: var(--_muted); }
181
+ .sc-palette-search input {
182
+ flex: 1; min-width: 0; height: 44px; border: 0; background: transparent; color: var(--_ink);
183
+ font: inherit; font-size: 14px;
184
+ }
185
+ .sc-palette-search input:focus { outline: 0; }
186
+ .sc-palette-list { max-height: 24rem; margin: 0; padding: 4px; overflow-y: auto; list-style: none; }
187
+ .sc-palette-section { margin: 0; padding: 8px 8px 4px; color: var(--_muted); font-size: var(--_text-small); font-weight: 500; }
188
+ .sc-option { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: var(--_radius-control); cursor: default; }
189
+ .sc-option[aria-selected="true"] { background: var(--_tint); }
190
+ .sc-option-icon { display: flex; flex-shrink: 0; width: 16px; justify-content: center; color: var(--_muted); }
191
+ .sc-option-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
192
+ .sc-option-detail { flex-shrink: 0; color: var(--_muted); font-size: var(--_text-small); }
193
+ .sc-kbd { flex-shrink: 0; padding: 0 6px; border: 1px solid var(--_line); border-radius: var(--_radius-control); color: var(--_muted); font-size: var(--_text-small); }
194
+ .sc-palette-empty { padding: 24px 12px; color: var(--_muted); font-style: italic; text-align: center; }
195
+ .sc-palette-hint { margin: 0; padding: 6px 12px; border-top: 1px solid var(--_line); color: var(--_muted); font-size: var(--_text-small); }
196
+
197
+ .sc-link { display: inline-flex; min-width: 0; align-items: center; gap: 4px; }
198
+ .sc-link[data-dragging] { opacity: 0.4; }
199
+ .sc-link-name {
200
+ min-width: 0; padding: 0; overflow: hidden; border: 0; background: transparent;
201
+ color: var(--_accent); font: inherit; text-align: left; text-overflow: ellipsis;
202
+ white-space: nowrap; cursor: pointer;
203
+ }
204
+ .sc-link-name:hover { text-decoration: underline; text-underline-offset: 4px; }
205
+ .sc-link-icons { display: inline-flex; flex-shrink: 0; opacity: 0; transition: opacity 80ms; }
206
+ .sc-link:hover .sc-link-icons, .sc-link:focus-within .sc-link-icons { opacity: 1; }
207
+ .sc-link-icons .sc-control { width: 22px; height: 22px; }
208
+ `;
209
+ /** Drawn by `<Composer>`. Exported for an application that draws the parts on their own. */
210
+ export function ComposerStyles() {
211
+ return (_jsx("style", { href: "sincpro-web-composer", precedence: "low", children: CSS }));
212
+ }
@@ -1,9 +1,11 @@
1
1
  import { Destination, type Registry, type ResourceRef, Surface, type ViewSpec, type WorkspaceApi, Zone } from "../domain/index.js";
2
2
  import type { WorkspaceStore } from "./store.js";
3
3
  /**
4
- * The API each view receives is built once per surface and kept. Recreating it on every
5
- * workspace change swapped the prop on every mounted view, so moving one panel redrew the
6
- * other five.
4
+ * The API each view receives is built once per surface AND resource, and kept while the
5
+ * surface shows it. Recreating it on every workspace change swapped the prop on every mounted
6
+ * view, so moving one panel redrew the other five. Rebuilding it when the resource changes is
7
+ * what lets a late call from the view that WAS there — a name that arrives after navigating —
8
+ * be recognised and ignored.
7
9
  *
8
10
  * Anything that needs current state reads it with `store.get()` at call time, never captured —
9
11
  * that is what lets the object stay stable without going stale.
@@ -20,6 +22,8 @@ export type ApiFactory = {
20
22
  for: (resource: ResourceRef, target: Target) => WorkspaceApi;
21
23
  /** Zone to open into when nobody asks: the one the domain prefers. */
22
24
  zoneFor: (spec: ViewSpec | null) => Zone;
25
+ /** The name the shell draws for `ref`: the one its view gave, else its `ViewSpec` title. */
26
+ titleOf: (ref: ResourceRef) => string;
23
27
  /** Stops listening to the store. Call it when the workspace goes away. */
24
28
  dispose: () => void;
25
29
  };
package/dist/state/api.js CHANGED
@@ -1,26 +1,28 @@
1
1
  import * as model from "../domain/index.js";
2
- import { Destination, formatRef, PAGE, Surface, Zone, } from "../domain/index.js";
3
- const cacheKey = (target) => target.surface === Surface.Panel ? `${Surface.Panel}:${target.panelId}` : target.surface;
2
+ import { Destination, formatRef, PAGE, PEEK, Surface, Zone, } from "../domain/index.js";
3
+ /** The id the workspace knows the surface by: `PAGE`, `PEEK` or the panel id. */
4
+ const surfaceId = (target) => target.surface === Surface.Panel
5
+ ? target.panelId
6
+ : target.surface === Surface.Peek
7
+ ? PEEK
8
+ : PAGE;
9
+ /** A panel's frame already says what it shows. One array, so it reads as «unchanged». */
10
+ const NO_CRUMBS = [];
4
11
  export function createApiFactory(store, { registry, defaultOpen = Destination.Page } = {}) {
5
12
  const cache = new Map();
6
13
  const choosers = new Map();
7
14
  const zoneFor = (spec) => spec?.preferredZone ?? Zone.Right;
8
- const titleOf = (ref) => registry?.resolve(ref)?.title(ref) ?? formatRef(ref);
9
- /* A chooser whose panel is gone is forgotten, and so is a cached API of a surface that no
15
+ const titleOf = (ref) => model.nameOf(store.get(), ref) ?? registry?.resolve(ref)?.title(ref) ?? formatRef(ref);
16
+ /* A chooser whose surface is gone is forgotten, and so is a cached API of a surface that no
10
17
  longer exists — or every panel ever opened would stay in memory. */
11
18
  const stop = store.subscribe(() => {
12
19
  const w = store.get();
13
- for (const id of choosers.keys()) {
14
- if (id !== `${PAGE}:peek` && model.findPanel(w, id) === null)
20
+ for (const id of choosers.keys())
21
+ if (model.refOn(w, id) === null)
15
22
  choosers.delete(id);
16
- }
17
- for (const key of cache.keys()) {
18
- const id = key.startsWith(`${Surface.Panel}:`)
19
- ? key.slice(Surface.Panel.length + 1)
20
- : null;
21
- if (id !== null && model.findPanel(w, id) === null)
23
+ for (const key of cache.keys())
24
+ if (model.refOn(w, key) === null)
22
25
  cache.delete(key);
23
- }
24
26
  });
25
27
  const context = {
26
28
  focused: () => model.focusedRef(store.get()),
@@ -28,113 +30,157 @@ export function createApiFactory(store, { registry, defaultOpen = Destination.Pa
28
30
  subscribe: store.subscribe,
29
31
  };
30
32
  function build(resource, target) {
31
- const me = target.surface === Surface.Panel ? target.panelId : PAGE;
32
- function openSide(ref, zone) {
33
- store.openPanel(ref, zone);
34
- }
33
+ const me = surfaceId(target);
34
+ const inPeek = target.surface === Surface.Peek;
35
+ /** Still showing what this API was lent for. */
36
+ const here = () => {
37
+ const now = model.refOn(store.get(), me);
38
+ return now !== null && model.sameRef(now, resource);
39
+ };
35
40
  function open(ref, to) {
36
- if (to === Destination.Peek)
37
- store.peek(ref);
41
+ if (to === Destination.Peek) {
42
+ if (inPeek)
43
+ store.drillPeek(ref);
44
+ else
45
+ store.peek(ref);
46
+ }
38
47
  else if (to === Destination.Window)
39
- openSide(ref, Zone.Floating);
48
+ store.openPanel(ref, Zone.Floating);
40
49
  else if (to === Destination.Side)
41
- openSide(ref, zoneFor(registry?.resolve(ref) ?? null));
42
- else if (target.surface === Surface.Peek) {
43
- store.closePeek();
44
- store.push(ref);
45
- }
50
+ store.openPanel(ref, zoneFor(registry?.resolve(ref) ?? null));
46
51
  else
47
52
  store.push(ref);
48
53
  }
49
- const api = {
54
+ function replace(ref) {
55
+ if (target.surface === Surface.Panel)
56
+ store.navigatePanel(target.panelId, ref);
57
+ else if (inPeek)
58
+ store.replacePeek(ref);
59
+ else
60
+ store.replace(ref);
61
+ }
62
+ /** In the peek the page's crumbs leave the drawer — a crumb is the page — and its own steps
63
+ * stay in it. */
64
+ function freshCrumbs() {
65
+ const w = store.get();
66
+ const page = w.page ?? resource;
67
+ const pageCrumbs = w.trail.map((past, i) => ({
68
+ label: titleOf(past),
69
+ onClick: () => store.goTo(i),
70
+ }));
71
+ if (!inPeek)
72
+ return [...pageCrumbs, { label: titleOf(page) }];
73
+ return [
74
+ ...pageCrumbs,
75
+ { label: titleOf(page), onClick: store.closePeek },
76
+ ...w.peekTrail.map((past, i) => ({
77
+ label: titleOf(past),
78
+ onClick: () => store.peekGoTo(i),
79
+ })),
80
+ { label: titleOf(w.peek ?? resource) },
81
+ ];
82
+ }
83
+ /** The SAME array until a label or the length of the trail changes: `useCrumbs` subscribes
84
+ * with it, and a new array per read would redraw forever. The links are by position, so
85
+ * equal labels on an equal trail are an equal breadcrumb. */
86
+ let last = null;
87
+ function crumbs() {
88
+ if (target.surface === Surface.Panel)
89
+ return NO_CRUMBS;
90
+ const next = freshCrumbs();
91
+ const key = `${store.get().trail.length}\u0000${next.map((c) => c.label).join("\u0000")}`;
92
+ if (last?.key === key)
93
+ return last.crumbs;
94
+ last = { key, crumbs: next };
95
+ return next;
96
+ }
97
+ return {
50
98
  self: resource,
51
99
  surface: target.surface,
52
100
  context,
53
- open: (ref, options) => open(ref, options?.to ?? defaultOpen),
101
+ open: (ref, options) => open(ref, options?.to ??
102
+ (inPeek && defaultOpen === Destination.Page ? Destination.Peek : defaultOpen)),
54
103
  navigate: (to) => {
55
104
  if (target.surface === Surface.Panel)
56
105
  store.navigatePanel(target.panelId, to);
57
- else if (target.surface === Surface.Peek)
58
- store.peek(to);
106
+ else if (inPeek)
107
+ store.drillPeek(to);
59
108
  else
60
- store.apply((w) => model.push(w, to));
109
+ store.push(to);
110
+ },
111
+ replace,
112
+ setParams: (params) => {
113
+ const now = model.refOn(store.get(), me);
114
+ if (now === null || !model.sameRef(model.rootRef(now), model.rootRef(resource)))
115
+ return;
116
+ replace(model.withParams(now, params));
61
117
  },
62
118
  back: () => {
63
119
  if (target.surface === Surface.Page)
64
120
  store.back();
121
+ else if (inPeek)
122
+ store.peekBack();
65
123
  },
66
124
  expand: () => {
67
125
  if (target.surface === Surface.Panel)
68
126
  store.expandPanel(target.panelId);
69
- else if (target.surface === Surface.Peek)
127
+ else if (inPeek)
70
128
  store.peekToPage();
71
129
  },
72
130
  close: () => {
73
131
  if (target.surface === Surface.Panel)
74
132
  store.closePanel(target.panelId);
75
- else if (target.surface === Surface.Peek)
133
+ else if (inPeek)
76
134
  store.closePeek();
135
+ else
136
+ store.back();
77
137
  },
78
138
  focus: () => store.focusPanel(me),
79
- crumbs: () => {
80
- /* A panel, a window or the peek already carry the record's name in their frame: a
81
- breadcrumb of one would only repeat it. The way back belongs to the page. */
82
- if (target.surface !== Surface.Page)
83
- return [];
84
- const w = store.get();
85
- return [
86
- ...w.trail.map((past, i) => ({
87
- label: titleOf(past),
88
- onClick: () => store.goTo(i),
89
- })),
90
- { label: titleOf(w.page ?? api.self) },
91
- ];
139
+ crumbs,
140
+ setTitle: (title) => {
141
+ if (here())
142
+ store.setTitle(resource, title);
92
143
  },
144
+ setDirty: (dirty) => store.setDirty(me, resource, dirty),
93
145
  select: (refs) => store.apply((w) => model.select(w, me, refs)),
94
146
  pick: (ref, onPick, options) => {
95
147
  const to = options?.to ?? Destination.Window;
96
148
  if (to === Destination.Peek) {
97
149
  store.peek(ref);
98
- choosers.set(PAGE + ":peek", onPick);
150
+ choosers.set(PEEK, onPick);
99
151
  return;
100
152
  }
101
153
  open(ref, to);
102
154
  const id = store.get().focus;
103
- if (id !== PAGE)
155
+ if (id !== PAGE && id !== PEEK)
104
156
  choosers.set(id, onPick);
105
157
  },
106
158
  answer: (value) => {
107
- const key = target.surface === Surface.Peek ? `${PAGE}:peek` : me;
108
- const onPick = choosers.get(key);
159
+ const onPick = choosers.get(me);
109
160
  if (onPick === undefined)
110
161
  return;
111
162
  /* Forget it BEFORE closing, so closing is not mistaken for anything else. */
112
- choosers.delete(key);
163
+ choosers.delete(me);
113
164
  onPick(value);
114
- if (target.surface === Surface.Peek)
165
+ if (inPeek)
115
166
  store.closePeek();
116
167
  else if (target.surface === Surface.Panel)
117
168
  store.closePanel(target.panelId);
118
169
  },
119
170
  };
120
- return api;
121
171
  }
122
172
  return {
123
173
  for: (resource, target) => {
124
- const key = cacheKey(target);
174
+ const key = surfaceId(target);
125
175
  const cached = cache.get(key);
126
- if (cached === undefined) {
127
- const api = build(resource, target);
128
- cache.set(key, { resource, api });
129
- return api;
130
- }
131
- if (cached.resource !== resource) {
132
- cached.api.self = resource;
133
- cached.resource = resource;
134
- }
135
- return cached.api;
176
+ if (cached !== undefined && model.sameRef(cached.resource, resource))
177
+ return cached.api;
178
+ const api = build(resource, target);
179
+ cache.set(key, { resource, api });
180
+ return api;
136
181
  },
137
182
  zoneFor,
183
+ titleOf,
138
184
  dispose: stop,
139
185
  };
140
186
  }
@@ -3,8 +3,13 @@ import type { Dock, OpenPanelOptions, ResourceRef, WindowBox, Workspace, Zone }
3
3
  * The pure reducers already are the state handling; this only binds them to the browser. An
4
4
  * external store, not `useState`: with state in the component every action recreated the API
5
5
  * views receive, and every panel redrew on any change.
6
+ *
7
+ * Two things live here and not in the model, because they are about the browser and not about
8
+ * the workspace: the history entries, and what a view has typed and not saved.
6
9
  */
7
10
  export type Unsubscribe = () => void;
11
+ /** Asked before throwing away views with unsaved changes; `lost` is what they show. */
12
+ export type ConfirmDiscard = (lost: readonly ResourceRef[]) => boolean | Promise<boolean>;
8
13
  export type WorkspaceStore = {
9
14
  /** Current state. Read at call time, never captured. */
10
15
  get: () => Workspace;
@@ -13,7 +18,12 @@ export type WorkspaceStore = {
13
18
  apply: (change: (state: Workspace) => Workspace) => void;
14
19
  /** Back to the starting workspace — the `initial` it was created with. */
15
20
  reset: () => void;
21
+ /** Start over from `view`, the way a menu does: no breadcrumb behind it, no peek. The panels
22
+ * stay. */
23
+ start: (view: ResourceRef) => void;
16
24
  push: (view: ResourceRef) => void;
25
+ /** The page shows `view` with no crumb and no browser history entry. */
26
+ replace: (view: ResourceRef) => void;
17
27
  goTo: (index: number) => void;
18
28
  back: () => void;
19
29
  openPanel: (view: ResourceRef, options?: Zone | OpenPanelOptions) => void;
@@ -30,16 +40,30 @@ export type WorkspaceStore = {
30
40
  focusPanel: (target: string) => void;
31
41
  cycleFocus: (delta: number) => void;
32
42
  peek: (view: ResourceRef) => void;
43
+ drillPeek: (view: ResourceRef) => void;
44
+ replacePeek: (view: ResourceRef) => void;
45
+ peekGoTo: (index: number) => void;
46
+ peekBack: () => void;
33
47
  closePeek: () => void;
34
48
  peekToPage: () => void;
35
49
  peekToSide: (zone?: Zone) => void;
50
+ /** The name a view gives `ref` (see `api.setTitle`). */
51
+ setTitle: (ref: ResourceRef, title: string | null) => void;
52
+ /** `surface` (`PAGE`, `PEEK` or a panel id) has unsaved changes for `ref`. Ignored if it no
53
+ * longer shows it. */
54
+ setDirty: (surface: string, ref: ResourceRef, dirty: boolean) => void;
55
+ /** Where `<Composer>` installs its own dialog. A `confirmDiscard` given to the store wins. */
56
+ setConfirmDiscard: (confirm: ConfirmDiscard | null) => void;
36
57
  };
37
58
  export type StoreOptions = {
38
59
  initial?: Workspace;
39
- /** Persist the workspace in the URL hash. Browser history and «share this link» come from
40
- * here. */
60
+ /** Persist the workspace in the URL hash. The browser's Back and «share this link» come
61
+ * from here. */
41
62
  hash?: boolean;
42
63
  /** Called after every change. Hook for telemetry or saving the user's workspace. */
43
64
  onChange?: (state: Workspace) => void;
65
+ /** Asked before a change throws away a view with unsaved changes. Without it, `<Composer>`
66
+ * asks with its own dialog; with neither, nothing is asked. */
67
+ confirmDiscard?: ConfirmDiscard;
44
68
  };
45
- export declare function createWorkspaceStore({ initial, hash, onChange, }?: StoreOptions): WorkspaceStore;
69
+ export declare function createWorkspaceStore({ initial, hash, onChange, confirmDiscard, }?: StoreOptions): WorkspaceStore;