@tooee/ask 0.2.4 → 0.3.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 (67) hide show
  1. package/README.md +2 -2
  2. package/dist/{AskEditor.d.ts → ask-editor.d.ts} +2 -2
  3. package/dist/ask-editor.d.ts.map +1 -0
  4. package/dist/ask-editor.js +26 -0
  5. package/dist/ask-editor.js.map +1 -0
  6. package/dist/{AskOverlay.d.ts → ask-overlay.d.ts} +6 -6
  7. package/dist/ask-overlay.d.ts.map +1 -0
  8. package/dist/{AskOverlay.js → ask-overlay.js} +11 -10
  9. package/dist/ask-overlay.js.map +1 -0
  10. package/dist/{AskPanel.d.ts → ask-panel.d.ts} +5 -5
  11. package/dist/ask-panel.d.ts.map +1 -0
  12. package/dist/ask-panel.js +33 -0
  13. package/dist/ask-panel.js.map +1 -0
  14. package/dist/{Ask.d.ts → ask.d.ts} +2 -2
  15. package/dist/ask.d.ts.map +1 -0
  16. package/dist/{Ask.js → ask.js} +15 -12
  17. package/dist/ask.js.map +1 -0
  18. package/dist/{EditorScrollbar.d.ts → editor-scrollbar.d.ts} +2 -2
  19. package/dist/editor-scrollbar.d.ts.map +1 -0
  20. package/dist/{EditorScrollbar.js → editor-scrollbar.js} +15 -10
  21. package/dist/editor-scrollbar.js.map +1 -0
  22. package/dist/index.d.ts +8 -8
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +4 -4
  25. package/dist/index.js.map +1 -1
  26. package/dist/launch.d.ts +1 -1
  27. package/dist/launch.d.ts.map +1 -1
  28. package/dist/launch.js +5 -4
  29. package/dist/launch.js.map +1 -1
  30. package/dist/types.d.ts.map +1 -1
  31. package/dist/use-ask-dialog.d.ts +4 -4
  32. package/dist/use-ask-dialog.d.ts.map +1 -1
  33. package/dist/use-ask-dialog.js +45 -38
  34. package/dist/use-ask-dialog.js.map +1 -1
  35. package/dist/use-ask-editor.d.ts +9 -9
  36. package/dist/use-ask-editor.d.ts.map +1 -1
  37. package/dist/use-ask-editor.js +211 -138
  38. package/dist/use-ask-editor.js.map +1 -1
  39. package/dist/vim-motions.d.ts +3 -3
  40. package/dist/vim-motions.d.ts.map +1 -1
  41. package/dist/vim-motions.js +73 -44
  42. package/dist/vim-motions.js.map +1 -1
  43. package/package.json +8 -8
  44. package/src/{AskEditor.tsx → ask-editor.tsx} +30 -23
  45. package/src/ask-overlay.tsx +80 -0
  46. package/src/{AskPanel.tsx → ask-panel.tsx} +49 -41
  47. package/src/{Ask.tsx → ask.tsx} +48 -45
  48. package/src/{EditorScrollbar.tsx → editor-scrollbar.tsx} +40 -28
  49. package/src/index.ts +17 -17
  50. package/src/launch.tsx +11 -10
  51. package/src/types.ts +5 -5
  52. package/src/use-ask-dialog.tsx +102 -90
  53. package/src/use-ask-editor.ts +377 -292
  54. package/src/vim-motions.ts +110 -71
  55. package/dist/Ask.d.ts.map +0 -1
  56. package/dist/Ask.js.map +0 -1
  57. package/dist/AskEditor.d.ts.map +0 -1
  58. package/dist/AskEditor.js +0 -19
  59. package/dist/AskEditor.js.map +0 -1
  60. package/dist/AskOverlay.d.ts.map +0 -1
  61. package/dist/AskOverlay.js.map +0 -1
  62. package/dist/AskPanel.d.ts.map +0 -1
  63. package/dist/AskPanel.js +0 -25
  64. package/dist/AskPanel.js.map +0 -1
  65. package/dist/EditorScrollbar.d.ts.map +0 -1
  66. package/dist/EditorScrollbar.js.map +0 -1
  67. package/src/AskOverlay.tsx +0 -75
@@ -1,25 +1,25 @@
1
- import { useRenderer } from "@opentui/react"
2
- import { AppLayout } from "@tooee/layout"
3
- import { useHasOverlay } from "@tooee/overlays"
4
- import { useTheme } from "@tooee/themes"
5
- import { useThemeCommands, useQuitCommand, usePasteCommands } from "@tooee/shell"
6
- import { useActions, useProvideCommandContext, useCommandContext } from "@tooee/commands"
7
- import type { ActionDefinition } from "@tooee/commands"
8
- import type { AskOptions } from "./types.js"
9
- import { AskEditor } from "./AskEditor.js"
10
- import { useAskEditor } from "./use-ask-editor.js"
1
+ import { useRenderer } from "@opentui/react";
2
+ import { AppLayout } from "@tooee/layout";
3
+ import { useHasOverlay } from "@tooee/overlays";
4
+ import { useTheme } from "@tooee/themes";
5
+ import { useThemeCommands, useQuitCommand, usePasteCommands } from "@tooee/shell";
6
+ import { useActions, useProvideCommandContext, useCommandContext } from "@tooee/commands";
7
+ import type { ActionDefinition } from "@tooee/commands";
8
+ import type { AskOptions } from "./types.js";
9
+ import { AskEditor } from "./ask-editor.js";
10
+ import { useAskEditor } from "./use-ask-editor.js";
11
11
 
12
12
  export interface AskProps extends AskOptions {
13
- actions?: ActionDefinition[]
13
+ actions?: ActionDefinition[];
14
14
  /**
15
15
  * Called with the submitted text. Defaults to writing the value to stdout
16
16
  * and destroying the renderer (the standalone `ask` CLI behaviour). A
17
17
  * `submit` action takes precedence over both.
18
18
  */
19
- onSubmit?: (value: string) => void
19
+ onSubmit?: (value: string) => void;
20
20
  }
21
21
 
22
- export function Ask({
22
+ export const Ask = function Ask({
23
23
  title,
24
24
  prompt,
25
25
  placeholder,
@@ -27,63 +27,66 @@ export function Ask({
27
27
  multiline = true,
28
28
  actions,
29
29
  onSubmit,
30
- }: AskProps) {
31
- const renderer = useRenderer()
32
- const { invoke } = useCommandContext()
30
+ }: AskProps): React.ReactNode {
31
+ const renderer = useRenderer();
32
+ const { invoke } = useCommandContext();
33
33
 
34
- const { theme } = useTheme()
35
- const { name: themeName } = useThemeCommands()
34
+ const { theme } = useTheme();
35
+ const { name: themeName } = useThemeCommands();
36
36
  useQuitCommand({
37
37
  onQuit: () => {
38
- renderer.destroy()
39
- process.exit(0)
38
+ renderer.destroy();
39
+ process.exit(0);
40
40
  },
41
- })
41
+ });
42
42
 
43
43
  // Legacy overlays don't push a command surface; keep blurring the editor
44
44
  // under them via the shell's overlay state.
45
- const hasOverlay = useHasOverlay()
45
+ const hasOverlay = useHasOverlay();
46
46
 
47
47
  const handleSubmit = (text: string) => {
48
- if (actions?.some((a) => a.id === "submit")) {
49
- invoke("submit")
50
- return
48
+ if (actions?.some((a) => a.id === "submit") === true) {
49
+ invoke("submit");
50
+ return;
51
51
  }
52
52
  if (onSubmit) {
53
- onSubmit(text)
54
- return
53
+ onSubmit(text);
54
+ return;
55
55
  }
56
- process.stdout.write(text + "\n")
57
- renderer.destroy()
58
- }
56
+ process.stdout.write(`${text}\n`);
57
+ renderer.destroy();
58
+ };
59
59
 
60
60
  const { controller, editor } = useAskEditor({
61
- multiline,
62
61
  defaultValue,
63
- placeholder,
62
+ multiline,
64
63
  onSubmit: handleSubmit,
64
+ placeholder,
65
65
  suspended: hasOverlay,
66
- })
66
+ });
67
+ const handleMouseDown = editor.onMouseDown;
67
68
 
68
69
  useProvideCommandContext(() => ({
69
- exit: () => renderer.destroy(),
70
- }))
70
+ exit: () => {
71
+ renderer.destroy();
72
+ },
73
+ }));
71
74
 
72
- useActions(actions)
75
+ useActions(actions);
73
76
 
74
77
  // Paste commands (available via command palette)
75
- usePasteCommands({ getTarget: () => controller })
78
+ usePasteCommands({ getTarget: () => controller });
76
79
 
77
- const mode = editor.mode
78
- const submitHint = multiline ? "Shift+Enter submit" : "Enter submit"
80
+ const { mode } = editor;
81
+ const submitHint = multiline ? "Shift+Enter submit" : "Enter submit";
79
82
  const hintParts =
80
83
  mode === "insert"
81
84
  ? [submitHint, "Esc commands"]
82
- : ["i insert", "q quit", ": palette", submitHint]
85
+ : ["i insert", "q quit", ": palette", submitHint];
83
86
 
84
87
  return (
85
88
  <AppLayout
86
- titleBar={title ? { title } : undefined}
89
+ titleBar={title !== undefined && title !== "" ? { title } : undefined}
87
90
  statusBar={{
88
91
  items: [
89
92
  { label: "Mode:", value: mode },
@@ -98,10 +101,10 @@ export function Ask({
98
101
  alignItems="center"
99
102
  justifyContent="center"
100
103
  style={{ flexGrow: 1 }}
101
- onMouseDown={editor.onMouseDown}
104
+ onMouseDown={handleMouseDown}
102
105
  >
103
106
  <box flexDirection="column" width="100%" maxWidth={80} style={{ flexGrow: 1, padding: 1 }}>
104
- {prompt && (
107
+ {(prompt?.length ?? 0) > 0 && (
105
108
  <text fg={theme.text} style={{ marginBottom: 1 }}>
106
109
  <strong>{prompt}</strong>
107
110
  </text>
@@ -110,5 +113,5 @@ export function Ask({
110
113
  </box>
111
114
  </box>
112
115
  </AppLayout>
113
- )
114
- }
116
+ );
117
+ };
@@ -1,18 +1,18 @@
1
- import type { TextareaRenderable, InputRenderable } from "@opentui/core"
1
+ import type { TextareaRenderable, InputRenderable } from "@opentui/core";
2
2
 
3
3
  export interface EditorScrollbarProps {
4
4
  /** The editor whose viewport this scrollbar reflects. */
5
- target: TextareaRenderable | InputRenderable | null
5
+ target: TextareaRenderable | InputRenderable | null;
6
6
  /**
7
7
  * Bump this whenever the editor viewport may have changed (cursor move,
8
8
  * content change, wheel scroll) so the thumb position re-computes.
9
9
  */
10
- revision: number
11
- color: string
10
+ revision: number;
11
+ color: string;
12
12
  }
13
13
 
14
- const THUMB_CHAR = "█"
15
- const TRACK_CHAR = "░"
14
+ const THUMB_CHAR = "█";
15
+ const TRACK_CHAR = "░";
16
16
 
17
17
  /**
18
18
  * A one-column vertical scrollbar that mirrors an editor's internal viewport.
@@ -25,31 +25,43 @@ const TRACK_CHAR = "░"
25
25
  *
26
26
  * Renders nothing when content fits within the viewport (no overflow).
27
27
  */
28
- export function EditorScrollbar({ target, color }: EditorScrollbarProps) {
29
- if (!target) return null
28
+ export const EditorScrollbar = function EditorScrollbar({
29
+ target,
30
+ color,
31
+ }: EditorScrollbarProps): React.ReactNode {
32
+ if (!target) {
33
+ return null;
34
+ }
30
35
 
31
36
  // Rendered height of the editor in rows (available post-layout).
32
- const height = target.height
33
- if (height <= 0) return null
37
+ const { height } = target;
38
+ if (height <= 0) {
39
+ return null;
40
+ }
34
41
 
35
42
  // Total virtual (wrapped) line count, not the count currently in view.
36
- const total = target.editorView.getTotalVirtualLineCount()
37
- if (total <= height) return null // fits, no overflow -> no scrollbar
38
-
39
- const offsetY = target.scrollY
40
- const maxOffset = Math.max(1, total - height)
41
- const clampedOffset = Math.min(Math.max(offsetY, 0), maxOffset)
42
-
43
- const thumbSize = Math.max(1, Math.round((height / total) * height))
44
- const maxThumbTop = Math.max(0, height - thumbSize)
45
- const thumbTop = Math.round((clampedOffset / maxOffset) * maxThumbTop)
46
-
47
- let content = ""
48
- for (let i = 0; i < height; i++) {
49
- const isThumb = i >= thumbTop && i < thumbTop + thumbSize
50
- content += isThumb ? THUMB_CHAR : TRACK_CHAR
51
- if (i < height - 1) content += "\n"
43
+ const total = target.editorView.getTotalVirtualLineCount();
44
+ // Content fits, so no scrollbar is needed.
45
+ if (total <= height) {
46
+ return null;
52
47
  }
53
48
 
54
- return <text content={content} fg={color} selectable={false} />
55
- }
49
+ const offsetY = target.scrollY;
50
+ const maxOffset = Math.max(1, total - height);
51
+ const clampedOffset = Math.min(Math.max(offsetY, 0), maxOffset);
52
+
53
+ const thumbSize = Math.max(1, Math.round((height / total) * height));
54
+ const maxThumbTop = Math.max(0, height - thumbSize);
55
+ const thumbTop = Math.round((clampedOffset / maxOffset) * maxThumbTop);
56
+
57
+ let content = "";
58
+ for (let i = 0; i < height; i += 1) {
59
+ const isThumb = i >= thumbTop && i < thumbTop + thumbSize;
60
+ content += isThumb ? THUMB_CHAR : TRACK_CHAR;
61
+ if (i < height - 1) {
62
+ content += "\n";
63
+ }
64
+ }
65
+
66
+ return <text content={content} fg={color} selectable={false} />;
67
+ };
package/src/index.ts CHANGED
@@ -1,12 +1,12 @@
1
- export { Ask } from "./Ask.js"
2
- export type { AskProps } from "./Ask.js"
3
- export { AskOverlay } from "./AskOverlay.js"
4
- export type { AskOverlayProps } from "./AskOverlay.js"
5
- export { AskPanel, buildAskHints } from "./AskPanel.js"
6
- export type { AskPanelProps, AskPanelInset, AskPanelInsetValue } from "./AskPanel.js"
7
- export { AskEditor } from "./AskEditor.js"
8
- export type { AskEditorProps } from "./AskEditor.js"
9
- export { useAskEditor } from "./use-ask-editor.js"
1
+ export { Ask } from "./ask.js";
2
+ export type { AskProps } from "./ask.js";
3
+ export { AskOverlay } from "./ask-overlay.js";
4
+ export type { AskOverlayProps } from "./ask-overlay.js";
5
+ export { AskPanel, buildAskHints } from "./ask-panel.js";
6
+ export type { AskPanelProps, AskPanelInset, AskPanelInsetValue } from "./ask-panel.js";
7
+ export { AskEditor } from "./ask-editor.js";
8
+ export type { AskEditorProps } from "./ask-editor.js";
9
+ export { useAskEditor } from "./use-ask-editor.js";
10
10
  export type {
11
11
  AskEditorCommandGroup,
12
12
  AskEditorController,
@@ -14,11 +14,11 @@ export type {
14
14
  AskSubmitKey,
15
15
  UseAskEditorOptions,
16
16
  UseAskEditorResult,
17
- } from "./use-ask-editor.js"
18
- export { useAskDialog } from "./use-ask-dialog.js"
19
- export type { AskDialogHandle, AskDialogOptions } from "./use-ask-dialog.js"
20
- export { launch } from "./launch.js"
21
- export type { AskLaunchOptions } from "./launch.js"
22
- export type { AskOptions } from "./types.js"
23
- export { appendAtCursor, handleEditBufferVimMotion, openLineAtCursor } from "./vim-motions.js"
24
- export type { EditableInsertTarget, VimMotionState } from "./vim-motions.js"
17
+ } from "./use-ask-editor.js";
18
+ export { useAskDialog } from "./use-ask-dialog.js";
19
+ export type { AskDialogHandle, AskDialogOptions } from "./use-ask-dialog.js";
20
+ export { launch } from "./launch.js";
21
+ export type { AskLaunchOptions } from "./launch.js";
22
+ export type { AskOptions } from "./types.js";
23
+ export { appendAtCursor, handleEditBufferVimMotion, openLineAtCursor } from "./vim-motions.js";
24
+ export type { EditableInsertTarget, VimMotionState } from "./vim-motions.js";
package/src/launch.tsx CHANGED
@@ -1,15 +1,16 @@
1
- import { launchCli } from "@tooee/shell"
2
- import type { ActionDefinition } from "@tooee/commands"
3
- import { Ask } from "./Ask.js"
4
- import type { AskOptions } from "./types.js"
1
+ import { launchCli } from "@tooee/shell";
2
+ import type { ActionDefinition } from "@tooee/commands";
3
+ import { Ask } from "./ask.js";
4
+ import type { AskOptions } from "./types.js";
5
5
 
6
6
  export interface AskLaunchOptions extends AskOptions {
7
- actions?: ActionDefinition[]
7
+ actions?: ActionDefinition[];
8
8
  /** Called with the submitted text. Default: write to stdout and exit. */
9
- onSubmit?: (value: string) => void
9
+ onSubmit?: (value: string) => void;
10
10
  }
11
11
 
12
- export async function launch(options: AskLaunchOptions): Promise<void> {
12
+ export const launch = async function launch(options: AskLaunchOptions): Promise<void> {
13
+ const handleSubmit = options.onSubmit;
13
14
  await launchCli(
14
15
  <Ask
15
16
  title={options.title}
@@ -18,8 +19,8 @@ export async function launch(options: AskLaunchOptions): Promise<void> {
18
19
  defaultValue={options.defaultValue}
19
20
  multiline={options.multiline}
20
21
  actions={options.actions}
21
- onSubmit={options.onSubmit}
22
+ onSubmit={handleSubmit}
22
23
  />,
23
24
  { exitOnCtrlC: false, provider: { initialMode: "insert" } },
24
- )
25
- }
25
+ );
26
+ };
package/src/types.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export interface AskOptions {
2
- title?: string
3
- prompt?: string
4
- placeholder?: string
5
- defaultValue?: string
6
- multiline?: boolean
2
+ title?: string;
3
+ prompt?: string;
4
+ placeholder?: string;
5
+ defaultValue?: string;
6
+ multiline?: boolean;
7
7
  }
@@ -1,9 +1,11 @@
1
- import { useEffect, useRef, type ReactNode, type Ref } from "react"
2
- import type { ActionDefinition } from "@tooee/commands"
3
- import { useOverlay, type OverlayHandle } from "@tooee/overlays"
4
- import { AskOverlay } from "./AskOverlay.js"
5
- import type { AskPanelProps } from "./AskPanel.js"
6
- import type { AskEditorController } from "./use-ask-editor.js"
1
+ import { useEffect, useRef } from "react";
2
+ import type { ReactNode, Ref } from "react";
3
+ import type { ActionDefinition } from "@tooee/commands";
4
+ import { useOverlay } from "@tooee/overlays";
5
+ import type { OverlayHandle } from "@tooee/overlays";
6
+ import { AskOverlay } from "./ask-overlay.js";
7
+ import type { AskPanelProps } from "./ask-panel.js";
8
+ import type { AskEditorController } from "./use-ask-editor.js";
7
9
 
8
10
  /**
9
11
  * Per-open unique overlay id. A module-level sequence guarantees that
@@ -11,28 +13,28 @@ import type { AskEditorController } from "./use-ask-editor.js"
11
13
  * same process — never share an overlay id, so one dialog can never displace
12
14
  * another through same-id replacement.
13
15
  */
14
- let askDialogSequence = 0
16
+ let askDialogSequence = 0;
15
17
 
16
18
  export interface AskDialogOptions {
17
- prompt: string
19
+ prompt: string;
18
20
  /** Title bar content; when set, `prompt` renders as a line above the editor. */
19
- title?: string
20
- multiline?: boolean
21
- defaultValue?: string
22
- placeholder?: string
21
+ title?: string;
22
+ multiline?: boolean;
23
+ defaultValue?: string;
24
+ placeholder?: string;
23
25
  /**
24
26
  * Extra commands registered on the dialog's own command surface (same shape
25
27
  * as Ask's actions). Handlers may open further dialogs; the nested dialog
26
28
  * suspends this one until it settles.
27
29
  */
28
- commands?: ActionDefinition[]
30
+ commands?: ActionDefinition[];
29
31
  /** Access to the text controller while open (dictation, prefill, transforms). */
30
- controllerRef?: Ref<AskEditorController>
32
+ controllerRef?: Ref<AskEditorController>;
31
33
  /** Chrome pass-throughs (see AskOverlay). */
32
- hints?: AskPanelProps["hints"]
33
- statusRight?: ReactNode
34
- footer?: ReactNode
35
- inset?: AskPanelProps["inset"]
34
+ hints?: AskPanelProps["hints"];
35
+ statusRight?: ReactNode;
36
+ footer?: ReactNode;
37
+ inset?: AskPanelProps["inset"];
36
38
  }
37
39
 
38
40
  export interface AskDialogHandle {
@@ -41,7 +43,7 @@ export interface AskDialogHandle {
41
43
  * when the dialog is cancelled, replaced, or unmounted. Settles exactly
42
44
  * once per call.
43
45
  */
44
- open(options: AskDialogOptions): Promise<string | null>
46
+ open: (options: AskDialogOptions) => Promise<string | null>;
45
47
  }
46
48
 
47
49
  /**
@@ -58,87 +60,97 @@ export interface AskDialogHandle {
58
60
  * (`AppLayout` does this automatically; custom hosts render
59
61
  * `useCurrentOverlay()`).
60
62
  */
61
- export function useAskDialog(): AskDialogHandle {
62
- const overlay = useOverlay()
63
- const overlayRef = useRef(overlay)
64
- overlayRef.current = overlay
63
+ export const useAskDialog = function useAskDialog(): AskDialogHandle {
64
+ const overlay = useOverlay();
65
+ const overlayRef = useRef(overlay);
66
+ overlayRef.current = overlay;
65
67
 
66
68
  // Open dialogs by overlay id, so unmounting the owner closes (and thereby
67
69
  // settles) every dialog it opened.
68
- const openHandlesRef = useRef(new Map<string, OverlayHandle<undefined>>())
69
- const unmountedRef = useRef(false)
70
+ const openHandlesRef = useRef(new Map<string, OverlayHandle<undefined>>());
71
+ const unmountedRef = useRef(false);
70
72
 
71
73
  useEffect(() => {
72
- unmountedRef.current = false
73
- const handles = openHandlesRef.current
74
+ unmountedRef.current = false;
75
+ const handles = openHandlesRef.current;
74
76
  return () => {
75
- unmountedRef.current = true
77
+ unmountedRef.current = true;
76
78
  // Map iteration tolerates deletion: settle() removes entries as each
77
79
  // close lands.
78
- for (const handle of handles.values()) handle.close("unmounted")
79
- handles.clear()
80
- }
81
- }, [])
80
+ for (const handle of handles.values()) {
81
+ handle.close("unmounted");
82
+ }
83
+ handles.clear();
84
+ };
85
+ }, []);
82
86
 
83
87
  // Stable identity so command handlers and effects can capture the handle.
84
- const handleRef = useRef<AskDialogHandle | null>(null)
85
- if (handleRef.current === null) {
86
- handleRef.current = {
87
- open(options: AskDialogOptions): Promise<string | null> {
88
- return new Promise<string | null>((resolvePromise) => {
89
- if (unmountedRef.current) {
90
- resolvePromise(null)
91
- return
92
- }
88
+ const handleRef = useRef<AskDialogHandle | null>(null);
89
+ handleRef.current ??= {
90
+ async open(options: AskDialogOptions): Promise<string | null> {
91
+ const { promise, resolve } = Promise.withResolvers<string | null>();
92
+ if (unmountedRef.current) {
93
+ resolve(null);
94
+ return await promise;
95
+ }
93
96
 
94
- const id = `ask-dialog-${++askDialogSequence}`
95
- let settled = false
96
- const settle = (value: string | null) => {
97
- if (settled) return
98
- settled = true
99
- openHandlesRef.current.delete(id)
100
- resolvePromise(value)
101
- }
97
+ askDialogSequence += 1;
98
+ const id = `ask-dialog-${askDialogSequence}`;
99
+ let settled = false;
100
+ const settle = (value: string | null) => {
101
+ if (settled) {
102
+ return;
103
+ }
104
+ settled = true;
105
+ openHandlesRef.current.delete(id);
106
+ resolve(value);
107
+ };
102
108
 
103
- const handle = overlayRef.current.open(
104
- id,
105
- () => (
106
- <AskOverlay
107
- prompt={options.prompt}
108
- title={options.title}
109
- multiline={options.multiline}
110
- defaultValue={options.defaultValue}
111
- placeholder={options.placeholder}
112
- commands={options.commands}
113
- controllerRef={options.controllerRef}
114
- hints={options.hints}
115
- statusRight={options.statusRight}
116
- footer={options.footer}
117
- inset={options.inset}
118
- onSubmit={(value) => {
119
- if (settled) return
120
- settle(value)
121
- handle.close("close")
122
- }}
123
- onCancel={() => handle.close("escape")}
124
- />
125
- ),
126
- undefined,
127
- {
128
- ownCommands: true,
129
- role: "modal",
130
- surfaceMode: "insert",
131
- // Single settlement funnel: every close path (cancel, escape,
132
- // replacement, unmount, external closeTop) lands here. Submit
133
- // settles first, making this a no-op.
134
- onClose: () => settle(null),
135
- },
136
- )
137
- openHandlesRef.current.set(id, handle)
138
- })
139
- },
140
- }
141
- }
109
+ const handle = overlayRef.current.open(
110
+ id,
111
+ (): ReactNode => (
112
+ <AskOverlay
113
+ prompt={options.prompt}
114
+ title={options.title}
115
+ multiline={options.multiline}
116
+ defaultValue={options.defaultValue}
117
+ placeholder={options.placeholder}
118
+ commands={options.commands}
119
+ controllerRef={options.controllerRef}
120
+ hints={options.hints}
121
+ statusRight={options.statusRight}
122
+ footer={options.footer}
123
+ inset={options.inset}
124
+ onSubmit={(value) => {
125
+ if (settled) {
126
+ return;
127
+ }
128
+ settle(value);
129
+ handle.close("close");
130
+ }}
131
+ onCancel={() => {
132
+ handle.close("escape");
133
+ }}
134
+ />
135
+ ),
136
+ undefined,
137
+ {
138
+ // Single settlement funnel: every close path (cancel, escape,
139
+ // replacement, unmount, external closeTop) lands here. Submit
140
+ // settles first, making this a no-op.
141
+ onClose: () => {
142
+ settle(null);
143
+ },
144
+ ownCommands: true,
145
+ role: "modal",
146
+ surfaceMode: "insert",
147
+ },
148
+ );
149
+ openHandlesRef.current.set(id, handle);
150
+ const result = await promise;
151
+ return result;
152
+ },
153
+ };
142
154
 
143
- return handleRef.current
144
- }
155
+ return handleRef.current;
156
+ };