@wyattjoh/herdr-ui 0.0.0-stage → 0.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.
- package/LICENSE +21 -0
- package/NOTICE.md +15 -0
- package/README.md +94 -2
- package/assets/icons/anchor-off.svg +4 -0
- package/assets/icons/anchor.svg +4 -0
- package/assets/icons/copy.svg +16 -0
- package/assets/icons/external-link.svg +5 -0
- package/assets/icons/globe.svg +1 -0
- package/assets/icons/log-in.svg +5 -0
- package/assets/icons/pin-filled.svg +1 -0
- package/assets/icons/return.svg +3 -0
- package/licenses/lucide.txt +43 -0
- package/package.json +54 -4
- package/src/assets.ts +33 -0
- package/src/color.ts +58 -0
- package/src/icons.ts +121 -0
- package/src/index.ts +15 -0
- package/src/menu-metrics.ts +117 -0
- package/src/pure.ts +8 -0
- package/src/record-scrolls.ts +50 -0
- package/src/tokens.ts +278 -0
- package/src/toolbar.ts +115 -0
- package/src/ui/cards.ts +305 -0
- package/src/ui/chips.ts +110 -0
- package/src/ui/controls.ts +83 -0
- package/src/ui/crumbs.ts +313 -0
- package/src/ui/document.ts +120 -0
- package/src/ui/frame.ts +177 -0
- package/src/ui/menu.ts +55 -0
- package/src/ui/scroll.ts +64 -0
- package/src/ui/states.ts +61 -0
- package/src/ui/tabs.ts +63 -0
- package/src/ui/theme.ts +37 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Per-record scroll ownership. Native scroll handles must be created outside render, so reads
|
|
2
|
+
// only queue missing records; the view flushes that queue from a deferred foreground task. Pure:
|
|
3
|
+
// the handle type and its factory come from the caller.
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Stable scroll handles keyed by record id, for one navigation target.
|
|
7
|
+
*/
|
|
8
|
+
export class RecordScrolls<Handle> {
|
|
9
|
+
private handles = new Map<string, Handle>();
|
|
10
|
+
private pending = new Set<string>();
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Reads an existing handle or queues its record for later allocation.
|
|
14
|
+
* @param id The record id.
|
|
15
|
+
* @returns Its stable handle, or undefined until the deferred flush.
|
|
16
|
+
*/
|
|
17
|
+
get(id: string): Handle | undefined {
|
|
18
|
+
const handle = this.handles.get(id);
|
|
19
|
+
if (handle === undefined) this.pending.add(id);
|
|
20
|
+
return handle;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Whether the view needs to schedule a deferred allocation task.
|
|
25
|
+
* @returns True when at least one record is waiting.
|
|
26
|
+
*/
|
|
27
|
+
get waiting(): boolean {
|
|
28
|
+
return this.pending.size > 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Allocates queued handles; call only outside render.
|
|
33
|
+
* @param create The native handle factory.
|
|
34
|
+
* @returns Whether any handles were created and a redraw is needed.
|
|
35
|
+
*/
|
|
36
|
+
flush(create: () => Handle): boolean {
|
|
37
|
+
const changed = this.pending.size > 0;
|
|
38
|
+
for (const id of this.pending) this.handles.set(id, create());
|
|
39
|
+
this.pending.clear();
|
|
40
|
+
return changed;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Clears ownership and queued allocations when the target or followed agent changes.
|
|
45
|
+
*/
|
|
46
|
+
reset(): void {
|
|
47
|
+
this.handles.clear();
|
|
48
|
+
this.pending.clear();
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/tokens.ts
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
// The Tasks panel's look as named numbers and theme role names. Pure: no gpui-kit or herdr
|
|
2
|
+
// import, so tests and build scripts can read it. Every value is copied from the Tasks panel's
|
|
3
|
+
// view, so a region built from these tokens lines up with the panel it came from.
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A `theme()` color role name, such as `"muted"` or `"ansi2"`.
|
|
7
|
+
*/
|
|
8
|
+
export type ThemeRole = string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The panel's outer geometry: the inset on every side, the top bar's vertical padding, and the
|
|
12
|
+
* corner radius Herdr's frame uses.
|
|
13
|
+
*/
|
|
14
|
+
export const PANEL = {
|
|
15
|
+
/**
|
|
16
|
+
* The panel's padding on every side.
|
|
17
|
+
*/
|
|
18
|
+
padding: 12,
|
|
19
|
+
/**
|
|
20
|
+
* The top bar's padding above and below its buttons.
|
|
21
|
+
*/
|
|
22
|
+
barPaddingY: 6,
|
|
23
|
+
/**
|
|
24
|
+
* The radius of the panel's top corners, matching Herdr's floating frame.
|
|
25
|
+
*/
|
|
26
|
+
frameRadius: 9,
|
|
27
|
+
/**
|
|
28
|
+
* The strip of frame color Herdr leaves above a floating block's content, which the top bar's
|
|
29
|
+
* backdrop reaches up over.
|
|
30
|
+
*/
|
|
31
|
+
frameTopInset: 5,
|
|
32
|
+
/**
|
|
33
|
+
* Between blocks inside the panel body.
|
|
34
|
+
*/
|
|
35
|
+
contentGap: 8,
|
|
36
|
+
/**
|
|
37
|
+
* Between cards on a screen.
|
|
38
|
+
*/
|
|
39
|
+
sectionGap: 10,
|
|
40
|
+
} as const;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Text sizes, in px.
|
|
44
|
+
*/
|
|
45
|
+
export const TEXT = {
|
|
46
|
+
/**
|
|
47
|
+
* A page title and the brand's wordmark.
|
|
48
|
+
*/
|
|
49
|
+
title: 15,
|
|
50
|
+
/**
|
|
51
|
+
* Row titles, markdown and state titles.
|
|
52
|
+
*/
|
|
53
|
+
body: 13,
|
|
54
|
+
/**
|
|
55
|
+
* Buttons, breadcrumbs, row keys, group headers and state details.
|
|
56
|
+
*/
|
|
57
|
+
label: 12,
|
|
58
|
+
/**
|
|
59
|
+
* Chips.
|
|
60
|
+
*/
|
|
61
|
+
caption: 10,
|
|
62
|
+
} as const;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The page title row under the breadcrumb band.
|
|
66
|
+
*/
|
|
67
|
+
export const TITLE = {
|
|
68
|
+
textSize: TEXT.title,
|
|
69
|
+
/**
|
|
70
|
+
* One line of the title: gpui's default line height (1.618 times the size), rounded. A leading
|
|
71
|
+
* icon or trailing control is centered in a box this tall so it sits on the first line.
|
|
72
|
+
*/
|
|
73
|
+
lineHeight: Math.round(TEXT.title * 1.618),
|
|
74
|
+
iconSize: 16,
|
|
75
|
+
paddingY: 10,
|
|
76
|
+
gap: 8,
|
|
77
|
+
} as const;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The breadcrumb band.
|
|
81
|
+
*/
|
|
82
|
+
export const CRUMB = {
|
|
83
|
+
height: 36,
|
|
84
|
+
gap: 6,
|
|
85
|
+
/**
|
|
86
|
+
* Between a crumb's icon and its label.
|
|
87
|
+
*/
|
|
88
|
+
itemGap: 5,
|
|
89
|
+
separator: "›",
|
|
90
|
+
} as const;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* A bordered content card, its external header, and the rows and group bands inside it.
|
|
94
|
+
*/
|
|
95
|
+
export const CARD = {
|
|
96
|
+
radius: 8,
|
|
97
|
+
/**
|
|
98
|
+
* The radius a band painted in a card's corner rounds itself to: one less than the card's, so
|
|
99
|
+
* it sits inside the 1px outline.
|
|
100
|
+
*/
|
|
101
|
+
innerRadius: 7,
|
|
102
|
+
headerHeight: 24,
|
|
103
|
+
headerGap: 6,
|
|
104
|
+
/**
|
|
105
|
+
* Between a section's header and its card.
|
|
106
|
+
*/
|
|
107
|
+
sectionGap: 2,
|
|
108
|
+
paddingX: 10,
|
|
109
|
+
paddingY: 8,
|
|
110
|
+
/**
|
|
111
|
+
* Between a row's mark, key, title and trailing items.
|
|
112
|
+
*/
|
|
113
|
+
rowGap: 7,
|
|
114
|
+
/**
|
|
115
|
+
* A collapsible group's header band.
|
|
116
|
+
*/
|
|
117
|
+
groupHeaderHeight: 28,
|
|
118
|
+
chevronSize: 12,
|
|
119
|
+
} as const;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Fixed row heights, so a group's open height is known without measuring.
|
|
123
|
+
*/
|
|
124
|
+
export const ROW = {
|
|
125
|
+
/**
|
|
126
|
+
* A row in a record's grouped list (a Spec's Tasks).
|
|
127
|
+
*/
|
|
128
|
+
compact: 32,
|
|
129
|
+
/**
|
|
130
|
+
* A row in a listing card.
|
|
131
|
+
*/
|
|
132
|
+
list: 34,
|
|
133
|
+
} as const;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* How a group's body folds: its height eases to its rows' total, or to nothing.
|
|
137
|
+
*/
|
|
138
|
+
export const FOLD_MOTION = { duration: 200, easing: "ease-out" } as const;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* A small badge: a label chip or a tinted count chip.
|
|
142
|
+
*/
|
|
143
|
+
export const CHIP = {
|
|
144
|
+
height: 18,
|
|
145
|
+
maxWidth: 180,
|
|
146
|
+
paddingX: 4,
|
|
147
|
+
gap: 3,
|
|
148
|
+
radius: 3,
|
|
149
|
+
iconSize: 12,
|
|
150
|
+
textSize: TEXT.caption,
|
|
151
|
+
/**
|
|
152
|
+
* The alpha suffix a tinted chip's background adds to its color (`#rrggbb1f`).
|
|
153
|
+
*/
|
|
154
|
+
tintAlpha: "1f",
|
|
155
|
+
/**
|
|
156
|
+
* Between chips in a row.
|
|
157
|
+
*/
|
|
158
|
+
rowGap: 4,
|
|
159
|
+
} as const;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* A progress bar and its fraction, fixed-width so bars line up down a list.
|
|
163
|
+
*/
|
|
164
|
+
export const PROGRESS = {
|
|
165
|
+
width: 56,
|
|
166
|
+
height: 6,
|
|
167
|
+
radius: 3,
|
|
168
|
+
gap: 6,
|
|
169
|
+
/**
|
|
170
|
+
* The room the `done/total` fraction gets.
|
|
171
|
+
*/
|
|
172
|
+
labelWidth: 34,
|
|
173
|
+
} as const;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* A breadcrumb's dropdown list.
|
|
177
|
+
*/
|
|
178
|
+
export const PICKER = {
|
|
179
|
+
rows: 7,
|
|
180
|
+
width: 260,
|
|
181
|
+
radius: 6,
|
|
182
|
+
optionPaddingX: 8,
|
|
183
|
+
optionGap: 6,
|
|
184
|
+
chevronPaddingX: 2,
|
|
185
|
+
chevronRadius: 4,
|
|
186
|
+
} as const;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* The brand mark and wordmark at the start of the overlay's top bar.
|
|
190
|
+
*/
|
|
191
|
+
export const BRAND = {
|
|
192
|
+
iconSize: 20,
|
|
193
|
+
textSize: TEXT.title,
|
|
194
|
+
gap: 6,
|
|
195
|
+
/**
|
|
196
|
+
* The top bar's allowance for the brand, used when fitting button labels beside it.
|
|
197
|
+
*/
|
|
198
|
+
width: 76,
|
|
199
|
+
} as const;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* A tab in a tab bar, sized like the panel's buttons.
|
|
203
|
+
*/
|
|
204
|
+
export const TAB = {
|
|
205
|
+
height: 26,
|
|
206
|
+
paddingX: 10,
|
|
207
|
+
gap: 4,
|
|
208
|
+
radius: 6,
|
|
209
|
+
textSize: TEXT.label,
|
|
210
|
+
} as const;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* A collapsible markdown document card.
|
|
214
|
+
*/
|
|
215
|
+
export const DOCUMENT = {
|
|
216
|
+
/**
|
|
217
|
+
* A collapsed document's height cap as a share of the window's height (web's 15vh).
|
|
218
|
+
*/
|
|
219
|
+
previewViewportRatio: 0.15,
|
|
220
|
+
fadeHeight: 120,
|
|
221
|
+
/**
|
|
222
|
+
* The fade's bands, top to bottom: each paints the card's color at this opacity.
|
|
223
|
+
*/
|
|
224
|
+
fadeOpacities: [
|
|
225
|
+
0.02, 0.04, 0.07, 0.11, 0.16, 0.23, 0.32, 0.42, 0.53, 0.64, 0.74, 0.83, 0.9, 0.95, 0.98, 1,
|
|
226
|
+
],
|
|
227
|
+
gap: 8,
|
|
228
|
+
} as const;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* An empty, error or loading message block.
|
|
232
|
+
*/
|
|
233
|
+
export const STATE = {
|
|
234
|
+
gap: 4,
|
|
235
|
+
} as const;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* The compact property menu's frame and its search input.
|
|
239
|
+
*/
|
|
240
|
+
export const MENU_SURFACE = {
|
|
241
|
+
radius: 7,
|
|
242
|
+
inputPaddingX: 8,
|
|
243
|
+
inputRadius: 6,
|
|
244
|
+
inputTextSize: TEXT.body,
|
|
245
|
+
} as const;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Domain-neutral tones, each the theme role the Tasks panel uses for that meaning: `neutral`
|
|
249
|
+
* for not started (slate), `info` for ready (blue), `active` for in progress (Herdr's amber
|
|
250
|
+
* `working`), `success` for done (green), `danger` for canceled or blocked (red), `warning`
|
|
251
|
+
* for blocking (yellow). Herdr's `done` role is blue in its default theme, so success doesn't
|
|
252
|
+
* use it.
|
|
253
|
+
*/
|
|
254
|
+
export const TONES = {
|
|
255
|
+
neutral: "dim",
|
|
256
|
+
info: "ansi4",
|
|
257
|
+
active: "working",
|
|
258
|
+
success: "ansi2",
|
|
259
|
+
danger: "ansi1",
|
|
260
|
+
warning: "ansi3",
|
|
261
|
+
muted: "muted",
|
|
262
|
+
} as const satisfies Record<string, ThemeRole>;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* A domain-neutral tone name.
|
|
266
|
+
*/
|
|
267
|
+
export type Tone = keyof typeof TONES;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Maps a domain's states to tones, so a consumer keeps its own status names.
|
|
271
|
+
* @param tones Each state's tone.
|
|
272
|
+
* @returns A function giving a state's theme role.
|
|
273
|
+
* @example const statusTone = toneMap({ queued: "neutral", running: "active", passed: "success" });
|
|
274
|
+
*/
|
|
275
|
+
export const toneMap =
|
|
276
|
+
<S extends string>(tones: Readonly<Record<S, Tone>>) =>
|
|
277
|
+
(state: S): ThemeRole =>
|
|
278
|
+
TONES[tones[state]];
|
package/src/toolbar.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// How a panel button looks, and which of a row's buttons fit their labels in a fixed width.
|
|
2
|
+
// Pure, so the label fitting is testable without Herdr.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* How a panel button looks: the stock `tabs` mod's `panelButton` (Files and Changes in Herdr's
|
|
6
|
+
* top bar) in its off state. Colors are `theme()` role names.
|
|
7
|
+
*/
|
|
8
|
+
export type ButtonStyle = {
|
|
9
|
+
height: number;
|
|
10
|
+
paddingX: number;
|
|
11
|
+
/**
|
|
12
|
+
* Between the icon and the label.
|
|
13
|
+
*/
|
|
14
|
+
gap: number;
|
|
15
|
+
radius: number;
|
|
16
|
+
textSize: number;
|
|
17
|
+
iconSize: number;
|
|
18
|
+
background: string;
|
|
19
|
+
text: string;
|
|
20
|
+
hover: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The style of every panel button.
|
|
25
|
+
*/
|
|
26
|
+
export const BUTTON_STYLE: ButtonStyle = {
|
|
27
|
+
height: 26,
|
|
28
|
+
paddingX: 8,
|
|
29
|
+
gap: 5,
|
|
30
|
+
radius: 6,
|
|
31
|
+
textSize: 12,
|
|
32
|
+
iconSize: 14,
|
|
33
|
+
background: "chrome",
|
|
34
|
+
text: "muted",
|
|
35
|
+
hover: "hover",
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Space between a toolbar's buttons, in px.
|
|
40
|
+
*/
|
|
41
|
+
export const TOOL_GAP = 6;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Space a floating overlay's toolbar keeps free, in px: it's what drags the overlay, and it
|
|
45
|
+
* absorbs a label a little wider than estimated.
|
|
46
|
+
*/
|
|
47
|
+
export const DRAG_ROOM = 24;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* A label's estimated width per character as a share of the text size: Herdr's UI font is
|
|
51
|
+
* JetBrains Mono (0.6em a glyph); proportional fonts run narrower.
|
|
52
|
+
*/
|
|
53
|
+
export const CHAR_WIDTH_RATIO = 0.6;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* One button of a toolbar, for fitting: its label, and whether it shows it (else it's an icon
|
|
57
|
+
* with the label as its tooltip).
|
|
58
|
+
*/
|
|
59
|
+
export type Tool<Id extends string = string> = {
|
|
60
|
+
id: Id;
|
|
61
|
+
label: string;
|
|
62
|
+
labelled: boolean;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A button's estimated width.
|
|
67
|
+
* @param tool The button.
|
|
68
|
+
* @param style Its style.
|
|
69
|
+
* @returns Its width in px.
|
|
70
|
+
*/
|
|
71
|
+
export function toolWidth(tool: Tool, style: ButtonStyle = BUTTON_STYLE): number {
|
|
72
|
+
const iconOnly = style.paddingX * 2 + style.iconSize;
|
|
73
|
+
return tool.labelled
|
|
74
|
+
? iconOnly + style.gap + tool.label.length * style.textSize * CHAR_WIDTH_RATIO
|
|
75
|
+
: iconOnly;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* A row of buttons' estimated width, gaps included.
|
|
80
|
+
* @param tools The buttons.
|
|
81
|
+
* @param style Their style.
|
|
82
|
+
* @returns Its width in px.
|
|
83
|
+
*/
|
|
84
|
+
export const toolsWidth = (tools: readonly Tool[], style: ButtonStyle = BUTTON_STYLE): number =>
|
|
85
|
+
tools.reduce((sum, tool) => sum + toolWidth(tool, style), 0) +
|
|
86
|
+
TOOL_GAP * Math.max(0, tools.length - 1);
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Gives labels to a fixed-width row's buttons while they fit, a group at a time, so the row
|
|
90
|
+
* never wraps or truncates.
|
|
91
|
+
* @param tools The row's buttons, all unlabelled or as the caller wants them by default.
|
|
92
|
+
* @param width The room for the row in px, or undefined in a pane, where the row wraps and
|
|
93
|
+
* `tools` is returned as given.
|
|
94
|
+
* @param order Groups of ids to label, most important first; a group is labelled only when the
|
|
95
|
+
* whole row still keeps `DRAG_ROOM` free.
|
|
96
|
+
* @param style The buttons' style.
|
|
97
|
+
* @returns The buttons, some labelled.
|
|
98
|
+
*/
|
|
99
|
+
export function fitLabels<Id extends string>(
|
|
100
|
+
tools: readonly Tool<Id>[],
|
|
101
|
+
width: number | undefined,
|
|
102
|
+
order: readonly (readonly Id[])[],
|
|
103
|
+
style: ButtonStyle = BUTTON_STYLE,
|
|
104
|
+
): Tool<Id>[] {
|
|
105
|
+
if (width === undefined) return [...tools];
|
|
106
|
+
return order.reduce<Tool<Id>[]>(
|
|
107
|
+
(row, group) => {
|
|
108
|
+
const next = row.map((tool) =>
|
|
109
|
+
group.includes(tool.id) ? { ...tool, labelled: true } : tool,
|
|
110
|
+
);
|
|
111
|
+
return toolsWidth(next, style) + DRAG_ROOM <= width ? next : row;
|
|
112
|
+
},
|
|
113
|
+
[...tools],
|
|
114
|
+
);
|
|
115
|
+
}
|