@bakers-build/addon-bakers-ui 0.10.0 → 0.10.1-next.10

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.
@@ -3,7 +3,9 @@ import { copyThrough } from '../../../lib/clipboard.js';
3
3
  import { serverMessage } from '../../../lib/jsonapi-error.js';
4
4
  import { BORDER, textNode } from '../../../lib/vnode.js';
5
5
  import { AsyncScreen, } from '../../../Screen/async-screen.js';
6
+ import { confirmNavigation } from '../../../Screen/confirm-dialog.js';
6
7
  import { runRowAction } from '../../../Screen/row-action.js';
8
+ import { activeRunInfo } from '../../run/Data/active-run.js';
7
9
  import { ADDONS_KEY, hasAddonsMessages, TicketContent, } from '../Component/ticket-content/index.js';
8
10
  import { initialExpandedKeys, resolveSelectedKey, retainExpandedKeys, ticketContentModel, ticketContentRowId, } from '../Component/ticket-content/model.js';
9
11
  import { handleTicketCopy, ticketCopyActions, ticketEditAction, ticketHeaderTree, ticketTitleOf, } from '../Component/ticket-detail/index.js';
@@ -11,8 +13,10 @@ import { ticketTeaserLines, ticketTeaserTree, } from '../Component/ticket-teaser
11
13
  import { readTicketAddons } from '../Data/addons.js';
12
14
  import { loadTicketDetail } from '../Data/detail.js';
13
15
  import { ticketDetailInputContext } from '../Data/input.js';
14
- import { loadTicketView, readTicket, refreshTicket, saveTicket, ticketLoaded, watchTicket, } from '../Data/store.js';
16
+ import { loadTicketView, mergeTicketDocuments, readTicket, refreshTicket, saveTicket, ticketLoaded, watchTicket, } from '../Data/store.js';
15
17
  import { updateTicketFrozen } from '../Data/write.js';
18
+ import { isTicketCancellable } from '../Form/edit.js';
19
+ import { cancelTicketRequest, restartRunRequest } from './ticket-actions.js';
16
20
  /** Overview width when the context carries none — a pipe has no terminal. */
17
21
  const DEFAULT_COLUMNS = 80;
18
22
  /**
@@ -318,20 +322,46 @@ export class TicketContentScreen extends AsyncScreen {
318
322
  return this.select(keys.length - 1, context);
319
323
  return false;
320
324
  }
325
+ cancellable() {
326
+ return !!this.document && isTicketCancellable(this.document);
327
+ }
328
+ restartable() {
329
+ return !!this.document && activeRunInfo(this.document) !== null;
330
+ }
321
331
  commandForInput(input) {
322
- return this.state === 'ready' && this.viewMode === 'full' && input === 'e'
323
- ? 'edit-assignment'
324
- : undefined;
332
+ if (this.state !== 'ready' || this.viewMode !== 'full')
333
+ return undefined;
334
+ if (input === 'e')
335
+ return 'edit-assignment';
336
+ if (input === 'x' && this.cancellable())
337
+ return 'cancel-ticket';
338
+ if (input === 'r' && this.restartable())
339
+ return 'restart-run';
340
+ return undefined;
325
341
  }
326
342
  actionForInput(input, context) {
327
- return this.commandForInput(input) === 'edit-assignment'
328
- ? ticketEditAction(context, this.document)
329
- : undefined;
343
+ const command = this.commandForInput(input);
344
+ if (command === 'edit-assignment')
345
+ return ticketEditAction(context, this.document);
346
+ if (command === 'cancel-ticket' && this.document)
347
+ return confirmNavigation(cancelTicketRequest(this.document));
348
+ if (command === 'restart-run' && this.document)
349
+ return confirmNavigation(restartRunRequest(this.document.data?.id ?? context.params?.ticketId ?? '', ticketTitleOf(this.document).identifier));
350
+ return undefined;
330
351
  }
331
352
  receiveResult(result, context) {
332
- if (result &&
333
- typeof result === 'object' &&
334
- result.type === 'ticket-assignment-updated') {
353
+ const type = result && typeof result === 'object'
354
+ ? result.type
355
+ : undefined;
356
+ if (type === 'ticket-cancelled' || type === 'run-cancelled') {
357
+ const document = result.document;
358
+ // Restart run returns a sparse read: merged, so this view's includes stay.
359
+ if (document)
360
+ this.replaceReady(saveTicket(context, mergeTicketDocuments(this.document, document)));
361
+ context.requestDraw();
362
+ return;
363
+ }
364
+ if (type === 'ticket-assignment-updated') {
335
365
  const returned = result;
336
366
  if (returned.document)
337
367
  this.replaceReady(saveTicket(context, returned.document));
@@ -384,6 +414,12 @@ export class TicketContentScreen extends AsyncScreen {
384
414
  return [
385
415
  actionItem('detail-tab', 'Tab', 'section'),
386
416
  actionItem('detail-edit', 'e', 'edit'),
417
+ ...(this.cancellable()
418
+ ? [actionItem('ticket-cancel', 'x', 'cancel ticket')]
419
+ : []),
420
+ ...(this.restartable()
421
+ ? [actionItem('detail-restart', 'r', 'restart run')]
422
+ : []),
387
423
  // Freeze and paging before copy: at 80 columns the footer clips the
388
424
  // tail, and `Y:Copy link` is the hint that yields.
389
425
  actionItem('detail-freeze', 'f', this.isFrozen() ? 'unfreeze' : 'freeze'),
@@ -42,10 +42,10 @@ export declare class TicketRunsScreen extends AsyncScreen<TicketDetailDocument>
42
42
  select(index: number, context: ScreenContext): boolean;
43
43
  activate(index: number, context: ScreenContext): boolean;
44
44
  handleInput(input: string, context: ScreenContext): boolean;
45
- /** The selected run, when it can still be edited (claimed or running). */
46
- private editableRun;
45
+ /** The selected run, when it can still be cancelled (claimed or running). */
46
+ private cancellableRun;
47
47
  commandForInput(input: string): string | undefined;
48
- actionForInput(input: string, context: ScreenContext): ScreenAction | undefined;
48
+ actionForInput(input: string): ScreenAction | undefined;
49
49
  receiveResult(result: unknown, context: ScreenContext): void;
50
50
  protected renderReady(document: TicketDetailDocument, context: ScreenContext): VNode;
51
51
  protected chrome(context: ScreenContext): FullScreenChrome;
@@ -3,9 +3,11 @@ import { flattenSections } from '../../../Component/section-list/index.js';
3
3
  import { ListCursor } from '../../../lib/cursor.js';
4
4
  import { columnNode } from '../../../lib/vnode.js';
5
5
  import { AsyncScreen } from '../../../Screen/async-screen.js';
6
+ import { confirmNavigation } from '../../../Screen/confirm-dialog.js';
6
7
  import { listRowIds, listTableRows, listTableTree } from '../../collection.js';
7
8
  import { TICKET_RUN_TABLE, ticketRunRows } from '../../run/Data/runs.js';
8
9
  import { isRunCancellable } from '../../run/Form/edit.js';
10
+ import { cancelRunRequest } from '../../run/Screen/run-actions.js';
9
11
  import { handleTicketCopy, ticketCopyActions, ticketHeaderTree, ticketTitleOf, } from '../Component/ticket-detail/index.js';
10
12
  import { ticketDetailInputContext, ticketInputContext } from '../Data/input.js';
11
13
  import { loadTicketView, readTicket, refreshTicket, saveTicket, ticketLoaded, watchTicket, } from '../Data/store.js';
@@ -132,31 +134,23 @@ export class TicketRunsScreen extends AsyncScreen {
132
134
  return this.select(view.selectable - 1, context);
133
135
  return false;
134
136
  }
135
- /** The selected run, when it can still be edited (claimed or running). */
136
- editableRun() {
137
+ /** The selected run, when it can still be cancelled (claimed or running). */
138
+ cancellableRun() {
137
139
  if (!this.document)
138
140
  return undefined;
139
141
  const run = ticketRunRows(this.document)[this.cursor.index];
140
142
  return run?.id && isRunCancellable(run.state) ? { id: run.id } : undefined;
141
143
  }
142
144
  commandForInput(input) {
143
- return this.state === 'ready' && input === 'e' && this.editableRun()
144
- ? 'edit-run'
145
+ return this.state === 'ready' && input === 'x' && this.cancellableRun()
146
+ ? 'cancel-run'
145
147
  : undefined;
146
148
  }
147
- actionForInput(input, context) {
148
- const run = this.editableRun();
149
- if (this.commandForInput(input) !== 'edit-run' || !run)
149
+ actionForInput(input) {
150
+ const run = this.cancellableRun();
151
+ if (this.commandForInput(input) !== 'cancel-run' || !run || !this.document)
150
152
  return undefined;
151
- return {
152
- type: 'navigate',
153
- routeId: 'run.edit',
154
- params: {
155
- ticketId: this.document?.data?.id ?? context.params?.ticketId ?? '',
156
- runId: run.id,
157
- },
158
- result: this.document,
159
- };
153
+ return confirmNavigation(cancelRunRequest(this.document, run.id));
160
154
  }
161
155
  receiveResult(result, context) {
162
156
  if (result &&
@@ -194,8 +188,8 @@ export class TicketRunsScreen extends AsyncScreen {
194
188
  const view = this.currentView(context);
195
189
  return [
196
190
  actionItem('detail-tab', 'Tab', 'section'),
197
- ...(this.editableRun()
198
- ? [actionItem('detail-edit', 'e', 'edit run')]
191
+ ...(this.cancellableRun()
192
+ ? [actionItem('run-cancel', 'x', 'cancel run')]
199
193
  : []),
200
194
  ...ticketCopyActions(),
201
195
  actionItem('detail-arrows', '↑↓', view.selectable > 1 ? 'select' : 'scroll'),
@@ -2,19 +2,24 @@ import { type VNode } from '@opentui/core';
2
2
  import { SPLASH_MS } from '../lib/theme.js';
3
3
  import type { TuiOptions } from '../types.js';
4
4
  export { SPLASH_MS };
5
- /** OpenTUI ASCIIFont name for the splash wordmark. */
6
- export declare const SPLASH_FONT: "block";
7
5
  /** Splash wordmark text (ASCIIFont has no emoji glyphs). */
8
- export declare const SPLASH_TEXT = "bakers";
6
+ export declare const SPLASH_TEXT = "bakers.build";
9
7
  /** Vertical padding inside the splash frame. */
10
8
  export declare const SPLASH_FRAME_PAD_Y = 2;
11
9
  /** Horizontal padding inside the splash frame. */
12
10
  export declare const SPLASH_FRAME_PAD_X = 4;
13
- /** Outer frame width: mark + horizontal pad + border columns. */
14
- export declare const SPLASH_FRAME_WIDTH: number;
11
+ export interface SplashWordmark {
12
+ tier: 'block' | 'tiny' | 'text';
13
+ frameWidth: number;
14
+ }
15
+ /** The largest wordmark whose frame fits `width` columns; plain text otherwise. */
16
+ export declare const splashWordmark: (width: number) => SplashWordmark;
15
17
  /**
16
- * Centered BORDER box with an ASCIIFont bakers mark — modal-like, not a wash.
17
- * Font is OpenTUI block letters; the terminal typeface is unchanged.
18
+ * Centered BORDER box with the bakers.build wordmark sized for `width` columns —
19
+ * modal-like, not a wash. The terminal typeface is unchanged.
20
+ *
21
+ * shortcut: the tier is picked once at mount, a resize during the 500 ms hold is
22
+ * not followed; re-pick on resize if the splash is ever held longer.
18
23
  *
19
24
  * `position: 'absolute'` is load-bearing: the splash is mounted into the SAME
20
25
  * `shell` that `createRegions` has already filled with `region-chrome`,
@@ -24,7 +29,7 @@ export declare const SPLASH_FRAME_WIDTH: number;
24
29
  * `justifyContent`/`alignItems: center` place the frame in the true middle —
25
30
  * the same treatment `region-modal` gets (`regions.ts`).
26
31
  */
27
- export declare const splashTree: () => VNode;
32
+ export declare const splashTree: (width: number) => VNode;
28
33
  export type SplashWait = (ms: number) => Promise<void>;
29
34
  /** Hold for `ms` (injectable clock for tests). Failures must not block boot. */
30
35
  export declare const awaitSplash: (ms?: number, wait?: SplashWait) => Promise<void>;
@@ -2,26 +2,53 @@
2
2
  // Non-TTY / pipe never enters this path. Injected-renderer harnesses skip by
3
3
  // default (`shouldSkipSplash`) so the bun suite does not pay SPLASH_MS.
4
4
  //
5
- // OpenTUI cannot change the terminal typeface. Splash “bakers” uses ASCIIFont
6
- // (multi-line block letters) so the mark reads large inside a BORDER box.
7
- import { ASCIIFontRenderable, BoxRenderable, h, measureText, } from '@opentui/core';
8
- import { BORDER, DEFAULT_BACKGROUND, DEFAULT_FOREGROUND, SPLASH_MS, } from '../lib/theme.js';
5
+ // OpenTUI cannot change the terminal typeface. The “bakers.build” wordmark uses
6
+ // the largest ASCIIFont that keeps the BORDER box inside the terminal, and plain
7
+ // text below that, so the splash never wraps or clips from 39 columns up.
8
+ import { ASCIIFontRenderable, BoxRenderable, h, measureText, TextRenderable, } from '@opentui/core';
9
+ import { BORDER, BORDER_EMPHASIS, DEFAULT_BACKGROUND, SPLASH_MS, } from '../lib/theme.js';
9
10
  import { LOGO_WIDTH, logoTree } from './logo.js';
10
11
  export { SPLASH_MS };
11
- /** OpenTUI ASCIIFont name for the splash wordmark. */
12
- export const SPLASH_FONT = 'block';
13
12
  /** Splash wordmark text (ASCIIFont has no emoji glyphs). */
14
- export const SPLASH_TEXT = 'bakers';
13
+ export const SPLASH_TEXT = 'bakers.build';
15
14
  /** Vertical padding inside the splash frame. */
16
15
  export const SPLASH_FRAME_PAD_Y = 2;
17
16
  /** Horizontal padding inside the splash frame. */
18
17
  export const SPLASH_FRAME_PAD_X = 4;
19
- const splashMarkSize = measureText({ text: SPLASH_TEXT, font: SPLASH_FONT });
20
- /** Outer frame width: mark + horizontal pad + border columns. */
21
- export const SPLASH_FRAME_WIDTH = splashMarkSize.width + LOGO_WIDTH + 3 + SPLASH_FRAME_PAD_X * 2 + 2;
18
+ /** Logo, gap 3, horizontal padding and the two border columns around the mark. */
19
+ const frameWidthFor = (markWidth) => markWidth + LOGO_WIDTH + 3 + SPLASH_FRAME_PAD_X * 2 + 2;
20
+ // Largest first; `tiny` is half blocks like the logo.
21
+ const FONT_TIERS = ['block', 'tiny'].map((font) => ({
22
+ tier: font,
23
+ frameWidth: frameWidthFor(measureText({ text: SPLASH_TEXT, font }).width),
24
+ }));
25
+ /** The largest wordmark whose frame fits `width` columns; plain text otherwise. */
26
+ export const splashWordmark = (width) => FONT_TIERS.find((tier) => tier.frameWidth <= width) ?? {
27
+ tier: 'text',
28
+ frameWidth: frameWidthFor(SPLASH_TEXT.length),
29
+ };
30
+ const wordmarkTree = (tier) => tier === 'text'
31
+ ? h(TextRenderable, {
32
+ id: 'splash-wordmark',
33
+ content: SPLASH_TEXT,
34
+ fg: BORDER_EMPHASIS,
35
+ bg: DEFAULT_BACKGROUND,
36
+ selectable: false,
37
+ })
38
+ : h(ASCIIFontRenderable, {
39
+ id: 'splash-wordmark',
40
+ text: SPLASH_TEXT,
41
+ font: tier,
42
+ color: BORDER_EMPHASIS,
43
+ backgroundColor: DEFAULT_BACKGROUND,
44
+ selectable: false,
45
+ });
22
46
  /**
23
- * Centered BORDER box with an ASCIIFont bakers mark — modal-like, not a wash.
24
- * Font is OpenTUI block letters; the terminal typeface is unchanged.
47
+ * Centered BORDER box with the bakers.build wordmark sized for `width` columns —
48
+ * modal-like, not a wash. The terminal typeface is unchanged.
49
+ *
50
+ * shortcut: the tier is picked once at mount, a resize during the 500 ms hold is
51
+ * not followed; re-pick on resize if the splash is ever held longer.
25
52
  *
26
53
  * `position: 'absolute'` is load-bearing: the splash is mounted into the SAME
27
54
  * `shell` that `createRegions` has already filled with `region-chrome`,
@@ -31,45 +58,41 @@ export const SPLASH_FRAME_WIDTH = splashMarkSize.width + LOGO_WIDTH + 3 + SPLASH
31
58
  * `justifyContent`/`alignItems: center` place the frame in the true middle —
32
59
  * the same treatment `region-modal` gets (`regions.ts`).
33
60
  */
34
- export const splashTree = () => h(BoxRenderable, {
35
- id: 'splash-root',
36
- position: 'absolute',
37
- left: 0,
38
- top: 0,
39
- flexDirection: 'column',
40
- width: '100%',
41
- height: '100%',
42
- justifyContent: 'center',
43
- alignItems: 'center',
44
- backgroundColor: DEFAULT_BACKGROUND,
45
- }, h(BoxRenderable, {
46
- id: 'splash-frame',
47
- border: true,
48
- borderStyle: 'rounded',
49
- borderColor: BORDER,
50
- backgroundColor: DEFAULT_BACKGROUND,
51
- width: SPLASH_FRAME_WIDTH,
52
- paddingLeft: SPLASH_FRAME_PAD_X,
53
- paddingRight: SPLASH_FRAME_PAD_X,
54
- paddingTop: SPLASH_FRAME_PAD_Y,
55
- paddingBottom: SPLASH_FRAME_PAD_Y,
56
- flexDirection: 'row',
57
- gap: 3,
58
- justifyContent: 'center',
59
- alignItems: 'center',
60
- }, h(BoxRenderable, {
61
- id: 'splash-logo',
62
- width: LOGO_WIDTH,
63
- flexShrink: 0,
64
- flexDirection: 'column',
65
- }, ...logoTree()), h(ASCIIFontRenderable, {
66
- id: 'splash-bakers',
67
- text: SPLASH_TEXT,
68
- font: SPLASH_FONT,
69
- color: DEFAULT_FOREGROUND,
70
- backgroundColor: DEFAULT_BACKGROUND,
71
- selectable: false,
72
- })));
61
+ export const splashTree = (width) => {
62
+ const mark = splashWordmark(width);
63
+ return h(BoxRenderable, {
64
+ id: 'splash-root',
65
+ position: 'absolute',
66
+ left: 0,
67
+ top: 0,
68
+ flexDirection: 'column',
69
+ width: '100%',
70
+ height: '100%',
71
+ justifyContent: 'center',
72
+ alignItems: 'center',
73
+ backgroundColor: DEFAULT_BACKGROUND,
74
+ }, h(BoxRenderable, {
75
+ id: 'splash-frame',
76
+ border: true,
77
+ borderStyle: 'rounded',
78
+ borderColor: BORDER,
79
+ backgroundColor: DEFAULT_BACKGROUND,
80
+ width: mark.frameWidth,
81
+ paddingLeft: SPLASH_FRAME_PAD_X,
82
+ paddingRight: SPLASH_FRAME_PAD_X,
83
+ paddingTop: SPLASH_FRAME_PAD_Y,
84
+ paddingBottom: SPLASH_FRAME_PAD_Y,
85
+ flexDirection: 'row',
86
+ gap: 3,
87
+ justifyContent: 'center',
88
+ alignItems: 'center',
89
+ }, h(BoxRenderable, {
90
+ id: 'splash-logo',
91
+ width: LOGO_WIDTH,
92
+ flexShrink: 0,
93
+ flexDirection: 'column',
94
+ }, ...logoTree()), wordmarkTree(mark.tier)));
95
+ };
73
96
  const defaultWait = (ms) => new Promise((resolve) => {
74
97
  setTimeout(resolve, ms);
75
98
  });
@@ -329,7 +329,7 @@ export async function runTicketTui(_document, _context, services, options = {})
329
329
  // Best-effort: paint/timer failure must not block reaching the main UI.
330
330
  if (interactive && renderer && shell && !shouldSkipSplash(options)) {
331
331
  try {
332
- const splash = mountTree(renderer, shell, splashTree());
332
+ const splash = mountTree(renderer, shell, splashTree(renderer.width));
333
333
  renderer.requestRender();
334
334
  await awaitSplash(SPLASH_MS, options.wait);
335
335
  unmountTree(shell, splash);
@@ -6,7 +6,6 @@ import { ProjectConductorsScreen } from '../Entity/conductor/Screen/project-cond
6
6
  import { ProjectOverviewScreen } from '../Entity/project/Screen/project-overview.js';
7
7
  import { ProjectPickerScreen } from '../Entity/project/Screen/project-picker.js';
8
8
  import { ProjectsScreen } from '../Entity/project/Screen/projects-screen.js';
9
- import { EditRunFormScreen } from '../Entity/run/Screen/edit-run-form.js';
10
9
  import { RunDetailScreen } from '../Entity/run/Screen/run-detail.js';
11
10
  import { RunsScreen } from '../Entity/run/Screen/runs.js';
12
11
  import { WorkspaceMemberRunsScreen } from '../Entity/run/Screen/user-runs.js';
@@ -27,6 +26,7 @@ import { WhoFilterScreen } from '../Entity/ticket/Screen/who-filter-form.js';
27
26
  import { WorkspaceMemberOverviewScreen } from '../Entity/user/Screen/member-overview.js';
28
27
  import { UsersScreen } from '../Entity/user/Screen/users.js';
29
28
  import { WorkspacePickerScreen } from '../Entity/workspace/Screen/workspace-picker.js';
29
+ import { ConfirmDialogScreen } from '../Screen/confirm-dialog.js';
30
30
  import { defineRoutes } from './registry.js';
31
31
  export const bootLocationFor = (route) => {
32
32
  if (!route)
@@ -84,7 +84,7 @@ const BUILT_IN = [
84
84
  TicketAddonsScreen,
85
85
  AddonActionFormScreen,
86
86
  RunDetailScreen,
87
- EditRunFormScreen,
87
+ ConfirmDialogScreen,
88
88
  ];
89
89
  export function buildRoutes(contributed = [], isWorkspaceAdmin = false) {
90
90
  const builtIn = isWorkspaceAdmin
@@ -0,0 +1,49 @@
1
+ import type { VNode } from '@opentui/core';
2
+ import { AsyncModalScreen } from './async-modal-screen.js';
3
+ import type { ModalChrome } from './modal-screen.js';
4
+ import type { ScreenAction, ScreenContext } from './screen.js';
5
+ /** What the dialog shows once its request is prepared. */
6
+ export interface ConfirmPrompt {
7
+ readonly message: string;
8
+ readonly detail?: string;
9
+ /** Absent: there is nothing to confirm, and Enter writes nothing. */
10
+ readonly confirm?: (context: ScreenContext) => Promise<unknown>;
11
+ }
12
+ /**
13
+ * One confirmable action. The dialog knows no entity: each slice builds its
14
+ * own request, so a shared screen never imports a slice.
15
+ */
16
+ export interface ConfirmRequest {
17
+ readonly title: string;
18
+ readonly prepare: (context: ScreenContext) => Promise<ConfirmPrompt>;
19
+ }
20
+ export declare const confirmRequestContext: import("../Routing/context.js").ContextKey<ConfirmRequest>;
21
+ /** The action that opens the dialog for `request`. */
22
+ export declare const confirmNavigation: (request: ConfirmRequest) => ScreenAction;
23
+ /** The confirmation dialog: Enter confirms, Esc closes and writes nothing. */
24
+ export declare class ConfirmDialogScreen extends AsyncModalScreen<ConfirmPrompt> {
25
+ static readonly route: {
26
+ id: string;
27
+ path: string;
28
+ presentation: "modal";
29
+ context: (_params: Readonly<Record<string, string>>, state: unknown, base: import("../Routing/context.js").ContextBag) => import("../Routing/context.js").ContextBag;
30
+ };
31
+ readonly id: string;
32
+ private request;
33
+ private action;
34
+ private message;
35
+ private submitting;
36
+ /** Index of the focused button; Confirm, the first, when there is one. */
37
+ private focus;
38
+ private buttons;
39
+ protected load(context: ScreenContext): Promise<ConfirmPrompt>;
40
+ protected renderLoading(): string[];
41
+ protected renderReady(prompt: ConfirmPrompt): VNode;
42
+ protected modalChrome(): ModalChrome;
43
+ protected actions(): import("../Component/footer-actions/index.js").ActionItem[];
44
+ takeAction(): ScreenAction | undefined;
45
+ handleInput(input: string, context: ScreenContext): boolean;
46
+ /** Closing drops the prompt: the next open carries a different request. */
47
+ leave(): void;
48
+ reset(): void;
49
+ }
@@ -0,0 +1,148 @@
1
+ import { actionItem } from '../Component/footer-actions/index.js';
2
+ import { serverMessage } from '../lib/jsonapi-error.js';
3
+ import { columnNode, rowNode, textNode } from '../lib/vnode.js';
4
+ import { wrapToWidth } from '../lib/width.js';
5
+ import { defineContext } from '../Routing/context.js';
6
+ import { AsyncModalScreen } from './async-modal-screen.js';
7
+ export const confirmRequestContext = defineContext('confirm-request', 'input');
8
+ /** The action that opens the dialog for `request`. */
9
+ export const confirmNavigation = (request) => ({
10
+ type: 'navigate',
11
+ routeId: ConfirmDialogScreen.route.id,
12
+ params: {},
13
+ result: request,
14
+ });
15
+ /** Text width inside the popup, as the edit popup measures it. */
16
+ const WIDTH = 58;
17
+ /** One node per physical row: a server message is longer than the popup. */
18
+ const rowsOf = (id, text) => text
19
+ .split('\n')
20
+ .flatMap((line) => wrapToWidth(line, WIDTH))
21
+ .map((content, index) => textNode({ id: `${id}-${index}`, content }));
22
+ const BUTTON_LABELS = {
23
+ confirm: 'Confirm',
24
+ close: 'Close',
25
+ };
26
+ /** The confirmation dialog: Enter confirms, Esc closes and writes nothing. */
27
+ export class ConfirmDialogScreen extends AsyncModalScreen {
28
+ static route = {
29
+ id: 'confirm',
30
+ path: '/confirm',
31
+ presentation: 'modal',
32
+ context: (_params, state, base) => state ? base.set(confirmRequestContext, state) : base,
33
+ };
34
+ id = ConfirmDialogScreen.route.id;
35
+ request;
36
+ action;
37
+ message = '';
38
+ submitting = false;
39
+ /** Index of the focused button; Confirm, the first, when there is one. */
40
+ focus = 0;
41
+ buttons() {
42
+ return this.readyValue?.confirm ? ['confirm', 'close'] : ['close'];
43
+ }
44
+ load(context) {
45
+ this.request = context.contexts?.has(confirmRequestContext)
46
+ ? context.contexts.get(confirmRequestContext)
47
+ : undefined;
48
+ return this.request?.prepare(context) ?? Promise.resolve({ message: '' });
49
+ }
50
+ renderLoading() {
51
+ return ['Loading…'];
52
+ }
53
+ renderReady(prompt) {
54
+ return columnNode('confirm-dialog', ...rowsOf('confirm-dialog-message', prompt.message), ...rowsOf('confirm-dialog-detail', this.message || prompt.detail || ''), textNode({ id: 'confirm-dialog-gap', content: '' }), rowNode('confirm-dialog-buttons', ...this.buttons().flatMap((button, index) => [
55
+ ...(index > 0
56
+ ? [textNode({ id: `confirm-dialog-gap-${index}`, content: ' ' })]
57
+ : []),
58
+ textNode({
59
+ id: `confirm-dialog-button-${button}`,
60
+ content: `${index === this.focus ? '▸' : ' '}[ ${BUTTON_LABELS[button]} ]`,
61
+ selected: index === this.focus,
62
+ }),
63
+ ])));
64
+ }
65
+ modalChrome() {
66
+ return { title: this.request?.title ?? '' };
67
+ }
68
+ actions() {
69
+ return [
70
+ actionItem('confirm-move', '←→', 'button'),
71
+ actionItem('confirm-press', 'Enter', 'press'),
72
+ actionItem('confirm-esc', 'Esc', 'close'),
73
+ ];
74
+ }
75
+ takeAction() {
76
+ const action = this.action;
77
+ this.action = undefined;
78
+ return action;
79
+ }
80
+ handleInput(input, context) {
81
+ if (super.handleInput(input, context))
82
+ return true;
83
+ if (!this.readyValue)
84
+ return false;
85
+ const buttons = this.buttons();
86
+ const step = input === 'right' || input === 'tab'
87
+ ? 1
88
+ : input === 'left' || input === 'shift+tab'
89
+ ? -1
90
+ : 0;
91
+ if (step !== 0) {
92
+ if (!this.submitting)
93
+ this.focus = (this.focus + step + buttons.length) % buttons.length;
94
+ context.requestDraw();
95
+ return true;
96
+ }
97
+ const pressed = input === 'escape'
98
+ ? 'close'
99
+ : input === 'enter' || input === ' '
100
+ ? buttons[this.focus]
101
+ : undefined;
102
+ if (!pressed)
103
+ return false;
104
+ // A pending write still lands; leaving now would let its result pop the
105
+ // screen below as well, and a second confirm would write twice.
106
+ if (this.submitting)
107
+ return true;
108
+ const confirm = this.readyValue.confirm;
109
+ if (pressed === 'close' || !confirm) {
110
+ this.action = { type: 'back' };
111
+ context.requestDraw();
112
+ return true;
113
+ }
114
+ this.submitting = true;
115
+ this.message = '';
116
+ void confirm(context)
117
+ .then((result) => {
118
+ if (!context.isActive())
119
+ return;
120
+ if (context.back)
121
+ context.back(result);
122
+ else
123
+ this.action = { type: 'back', result };
124
+ })
125
+ .catch((caught) => {
126
+ this.message = serverMessage(caught);
127
+ })
128
+ .finally(() => {
129
+ this.submitting = false;
130
+ if (context.isActive())
131
+ context.requestDraw();
132
+ });
133
+ return true;
134
+ }
135
+ /** Closing drops the prompt: the next open carries a different request. */
136
+ leave() {
137
+ this.reset();
138
+ super.leave();
139
+ }
140
+ reset() {
141
+ this.request = undefined;
142
+ this.action = undefined;
143
+ this.message = '';
144
+ this.submitting = false;
145
+ this.focus = 0;
146
+ super.reset();
147
+ }
148
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/addon-bakers-ui",
3
- "version": "0.10.0",
3
+ "version": "0.10.1-next.10",
4
4
  "description": "bakers.build TUI: interactive terminal UI (dashboard, projects, tickets) as a dropsh `tui` renderer plugin.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -32,11 +32,11 @@
32
32
  "zustand": "^5.0.15"
33
33
  },
34
34
  "peerDependencies": {
35
- "@bakers-build/core": "^0.10.0",
36
- "@bakers-build/message": "^0.10.0"
35
+ "@bakers-build/core": "^0.10.1-next.10",
36
+ "@bakers-build/message": "^0.10.1-next.10"
37
37
  },
38
38
  "bakersBuild": {
39
- "commit": "5857b00008bc0926fd52fdc8d9366d6d52444e35",
40
- "channel": "latest"
39
+ "commit": "d0f650fbe4c44eda2a26be62d28d30c22c56c386",
40
+ "channel": "next"
41
41
  }
42
42
  }
@@ -1,26 +0,0 @@
1
- import type { VNode } from '@opentui/core';
2
- import { AsyncModalScreen } from '../../../Screen/async-modal-screen.js';
3
- import type { ModalChrome } from '../../../Screen/modal-screen.js';
4
- import type { ScreenAction, ScreenContext } from '../../../Screen/screen.js';
5
- import type { TicketDetailDocument } from '../../../types.js';
6
- export declare class EditRunFormScreen extends AsyncModalScreen<TicketDetailDocument> {
7
- readonly modal = true;
8
- static readonly route: {
9
- id: string;
10
- path: string;
11
- parent: string;
12
- presentation: "modal";
13
- context: (_params: Readonly<Record<string, string>>, state: unknown, base: import("../../../Routing/context.js").ContextBag) => import("../../../Routing/context.js").ContextBag;
14
- };
15
- readonly id: string;
16
- private action;
17
- private message;
18
- private submitting;
19
- protected load(context: ScreenContext): Promise<TicketDetailDocument>;
20
- protected renderLoading(): string[];
21
- protected renderReady(document: TicketDetailDocument, context: ScreenContext): VNode;
22
- protected modalChrome(_context: ScreenContext): ModalChrome;
23
- protected actions(): import("../../../Component/footer-actions/index.js").ActionItem[];
24
- takeAction(): ScreenAction | undefined;
25
- handleInput(input: string, context: ScreenContext): boolean;
26
- }