@sincpro/web-composer 0.1.0 → 1.0.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.
- package/README.md +135 -64
- package/dist/domain/enums.d.ts +0 -10
- package/dist/domain/enums.js +0 -8
- package/dist/domain/index.d.ts +4 -4
- package/dist/domain/index.js +4 -4
- package/dist/domain/layout.d.ts +37 -20
- package/dist/domain/layout.js +136 -100
- package/dist/domain/registry.d.ts +30 -7
- package/dist/domain/url.d.ts +13 -0
- package/dist/domain/url.js +43 -5
- package/dist/domain/workspace.d.ts +43 -7
- package/dist/domain/workspace.js +136 -15
- package/dist/index.d.ts +8 -4
- package/dist/index.js +7 -3
- package/dist/shell/Composer.d.ts +5 -6
- package/dist/shell/Composer.js +42 -13
- package/dist/shell/Palette.js +11 -10
- package/dist/shell/PanelFrame.d.ts +10 -3
- package/dist/shell/PanelFrame.js +57 -31
- package/dist/shell/PanelHost.js +44 -31
- package/dist/shell/Peek.d.ts +26 -0
- package/dist/shell/Peek.js +64 -0
- package/dist/shell/RecordLink.js +12 -8
- package/dist/shell/ViewHost.js +17 -6
- package/dist/shell/copy.d.ts +10 -1
- package/dist/shell/copy.js +29 -7
- package/dist/shell/icons.d.ts +22 -0
- package/dist/shell/icons.js +19 -0
- package/dist/shell/skin.d.ts +72 -0
- package/dist/shell/skin.js +35 -0
- package/dist/shell/styles.d.ts +19 -0
- package/dist/shell/styles.js +212 -0
- package/dist/state/api.d.ts +7 -3
- package/dist/state/api.js +93 -63
- package/dist/state/store.d.ts +27 -3
- package/dist/state/store.js +165 -41
- package/dist/state/useKeyboard.d.ts +4 -0
- package/dist/state/useKeyboard.js +11 -3
- 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
|
+
}
|
package/dist/state/api.d.ts
CHANGED
|
@@ -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
|
|
5
|
-
*
|
|
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,26 @@
|
|
|
1
1
|
import * as model from "../domain/index.js";
|
|
2
|
-
import { Destination, formatRef, PAGE, Surface, Zone, } from "../domain/index.js";
|
|
3
|
-
|
|
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;
|
|
4
9
|
export function createApiFactory(store, { registry, defaultOpen = Destination.Page } = {}) {
|
|
5
10
|
const cache = new Map();
|
|
6
11
|
const choosers = new Map();
|
|
7
12
|
const zoneFor = (spec) => spec?.preferredZone ?? Zone.Right;
|
|
8
|
-
const titleOf = (ref) => registry?.resolve(ref)?.title(ref) ?? formatRef(ref);
|
|
9
|
-
/* A chooser whose
|
|
13
|
+
const titleOf = (ref) => model.nameOf(store.get(), ref) ?? registry?.resolve(ref)?.title(ref) ?? formatRef(ref);
|
|
14
|
+
/* A chooser whose surface is gone is forgotten, and so is a cached API of a surface that no
|
|
10
15
|
longer exists — or every panel ever opened would stay in memory. */
|
|
11
16
|
const stop = store.subscribe(() => {
|
|
12
17
|
const w = store.get();
|
|
13
|
-
for (const id of choosers.keys())
|
|
14
|
-
if (
|
|
18
|
+
for (const id of choosers.keys())
|
|
19
|
+
if (model.refOn(w, id) === null)
|
|
15
20
|
choosers.delete(id);
|
|
16
|
-
|
|
17
|
-
|
|
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)
|
|
21
|
+
for (const key of cache.keys())
|
|
22
|
+
if (model.refOn(w, key) === null)
|
|
22
23
|
cache.delete(key);
|
|
23
|
-
}
|
|
24
24
|
});
|
|
25
25
|
const context = {
|
|
26
26
|
focused: () => model.focusedRef(store.get()),
|
|
@@ -28,113 +28,143 @@ export function createApiFactory(store, { registry, defaultOpen = Destination.Pa
|
|
|
28
28
|
subscribe: store.subscribe,
|
|
29
29
|
};
|
|
30
30
|
function build(resource, target) {
|
|
31
|
-
const me = target
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
const me = surfaceId(target);
|
|
32
|
+
const inPeek = target.surface === Surface.Peek;
|
|
33
|
+
/** Still showing what this API was lent for. */
|
|
34
|
+
const here = () => {
|
|
35
|
+
const now = model.refOn(store.get(), me);
|
|
36
|
+
return now !== null && model.sameRef(now, resource);
|
|
37
|
+
};
|
|
35
38
|
function open(ref, to) {
|
|
36
|
-
if (to === Destination.Peek)
|
|
37
|
-
|
|
39
|
+
if (to === Destination.Peek) {
|
|
40
|
+
if (inPeek)
|
|
41
|
+
store.drillPeek(ref);
|
|
42
|
+
else
|
|
43
|
+
store.peek(ref);
|
|
44
|
+
}
|
|
38
45
|
else if (to === Destination.Window)
|
|
39
|
-
|
|
46
|
+
store.openPanel(ref, Zone.Floating);
|
|
40
47
|
else if (to === Destination.Side)
|
|
41
|
-
|
|
42
|
-
else if (target.surface === Surface.Peek) {
|
|
43
|
-
store.closePeek();
|
|
44
|
-
store.push(ref);
|
|
45
|
-
}
|
|
48
|
+
store.openPanel(ref, zoneFor(registry?.resolve(ref) ?? null));
|
|
46
49
|
else
|
|
47
50
|
store.push(ref);
|
|
48
51
|
}
|
|
49
|
-
|
|
52
|
+
function replace(ref) {
|
|
53
|
+
if (target.surface === Surface.Panel)
|
|
54
|
+
store.navigatePanel(target.panelId, ref);
|
|
55
|
+
else if (inPeek)
|
|
56
|
+
store.replacePeek(ref);
|
|
57
|
+
else
|
|
58
|
+
store.replace(ref);
|
|
59
|
+
}
|
|
60
|
+
/** In the peek the page's crumbs leave the drawer — a crumb is the page — and its own steps
|
|
61
|
+
* stay in it. */
|
|
62
|
+
function crumbs() {
|
|
63
|
+
const w = store.get();
|
|
64
|
+
const page = w.page ?? resource;
|
|
65
|
+
const pageCrumbs = w.trail.map((past, i) => ({
|
|
66
|
+
label: titleOf(past),
|
|
67
|
+
onClick: () => store.goTo(i),
|
|
68
|
+
}));
|
|
69
|
+
if (!inPeek)
|
|
70
|
+
return [...pageCrumbs, { label: titleOf(page) }];
|
|
71
|
+
return [
|
|
72
|
+
...pageCrumbs,
|
|
73
|
+
{ label: titleOf(page), onClick: store.closePeek },
|
|
74
|
+
...w.peekTrail.map((past, i) => ({
|
|
75
|
+
label: titleOf(past),
|
|
76
|
+
onClick: () => store.peekGoTo(i),
|
|
77
|
+
})),
|
|
78
|
+
{ label: titleOf(w.peek ?? resource) },
|
|
79
|
+
];
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
50
82
|
self: resource,
|
|
51
83
|
surface: target.surface,
|
|
52
84
|
context,
|
|
53
|
-
open: (ref, options) => open(ref, options?.to ??
|
|
85
|
+
open: (ref, options) => open(ref, options?.to ??
|
|
86
|
+
(inPeek && defaultOpen === Destination.Page ? Destination.Peek : defaultOpen)),
|
|
54
87
|
navigate: (to) => {
|
|
55
88
|
if (target.surface === Surface.Panel)
|
|
56
89
|
store.navigatePanel(target.panelId, to);
|
|
57
|
-
else if (
|
|
58
|
-
store.
|
|
90
|
+
else if (inPeek)
|
|
91
|
+
store.drillPeek(to);
|
|
59
92
|
else
|
|
60
|
-
store.
|
|
93
|
+
store.push(to);
|
|
94
|
+
},
|
|
95
|
+
replace,
|
|
96
|
+
setParams: (params) => {
|
|
97
|
+
const now = model.refOn(store.get(), me);
|
|
98
|
+
if (now === null || !model.sameRef(model.rootRef(now), model.rootRef(resource)))
|
|
99
|
+
return;
|
|
100
|
+
replace(model.withParams(now, params));
|
|
61
101
|
},
|
|
62
102
|
back: () => {
|
|
63
103
|
if (target.surface === Surface.Page)
|
|
64
104
|
store.back();
|
|
105
|
+
else if (inPeek)
|
|
106
|
+
store.peekBack();
|
|
65
107
|
},
|
|
66
108
|
expand: () => {
|
|
67
109
|
if (target.surface === Surface.Panel)
|
|
68
110
|
store.expandPanel(target.panelId);
|
|
69
|
-
else if (
|
|
111
|
+
else if (inPeek)
|
|
70
112
|
store.peekToPage();
|
|
71
113
|
},
|
|
72
114
|
close: () => {
|
|
73
115
|
if (target.surface === Surface.Panel)
|
|
74
116
|
store.closePanel(target.panelId);
|
|
75
|
-
else if (
|
|
117
|
+
else if (inPeek)
|
|
76
118
|
store.closePeek();
|
|
119
|
+
else
|
|
120
|
+
store.back();
|
|
77
121
|
},
|
|
78
122
|
focus: () => store.focusPanel(me),
|
|
79
|
-
crumbs: () =>
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
];
|
|
123
|
+
crumbs: () => (target.surface === Surface.Panel ? [] : crumbs()),
|
|
124
|
+
setTitle: (title) => {
|
|
125
|
+
if (here())
|
|
126
|
+
store.setTitle(resource, title);
|
|
92
127
|
},
|
|
128
|
+
setDirty: (dirty) => store.setDirty(me, resource, dirty),
|
|
93
129
|
select: (refs) => store.apply((w) => model.select(w, me, refs)),
|
|
94
130
|
pick: (ref, onPick, options) => {
|
|
95
131
|
const to = options?.to ?? Destination.Window;
|
|
96
132
|
if (to === Destination.Peek) {
|
|
97
133
|
store.peek(ref);
|
|
98
|
-
choosers.set(
|
|
134
|
+
choosers.set(PEEK, onPick);
|
|
99
135
|
return;
|
|
100
136
|
}
|
|
101
137
|
open(ref, to);
|
|
102
138
|
const id = store.get().focus;
|
|
103
|
-
if (id !== PAGE)
|
|
139
|
+
if (id !== PAGE && id !== PEEK)
|
|
104
140
|
choosers.set(id, onPick);
|
|
105
141
|
},
|
|
106
142
|
answer: (value) => {
|
|
107
|
-
const
|
|
108
|
-
const onPick = choosers.get(key);
|
|
143
|
+
const onPick = choosers.get(me);
|
|
109
144
|
if (onPick === undefined)
|
|
110
145
|
return;
|
|
111
146
|
/* Forget it BEFORE closing, so closing is not mistaken for anything else. */
|
|
112
|
-
choosers.delete(
|
|
147
|
+
choosers.delete(me);
|
|
113
148
|
onPick(value);
|
|
114
|
-
if (
|
|
149
|
+
if (inPeek)
|
|
115
150
|
store.closePeek();
|
|
116
151
|
else if (target.surface === Surface.Panel)
|
|
117
152
|
store.closePanel(target.panelId);
|
|
118
153
|
},
|
|
119
154
|
};
|
|
120
|
-
return api;
|
|
121
155
|
}
|
|
122
156
|
return {
|
|
123
157
|
for: (resource, target) => {
|
|
124
|
-
const key =
|
|
158
|
+
const key = surfaceId(target);
|
|
125
159
|
const cached = cache.get(key);
|
|
126
|
-
if (cached
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (cached.resource !== resource) {
|
|
132
|
-
cached.api.self = resource;
|
|
133
|
-
cached.resource = resource;
|
|
134
|
-
}
|
|
135
|
-
return cached.api;
|
|
160
|
+
if (cached !== undefined && model.sameRef(cached.resource, resource))
|
|
161
|
+
return cached.api;
|
|
162
|
+
const api = build(resource, target);
|
|
163
|
+
cache.set(key, { resource, api });
|
|
164
|
+
return api;
|
|
136
165
|
},
|
|
137
166
|
zoneFor,
|
|
167
|
+
titleOf,
|
|
138
168
|
dispose: stop,
|
|
139
169
|
};
|
|
140
170
|
}
|
package/dist/state/store.d.ts
CHANGED
|
@@ -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.
|
|
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;
|