@tooee/ask 0.1.21 → 0.2.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 +36 -0
- package/dist/Ask.d.ts +8 -11
- package/dist/Ask.d.ts.map +1 -1
- package/dist/Ask.js +22 -101
- package/dist/Ask.js.map +1 -1
- package/dist/AskEditor.d.ts +10 -0
- package/dist/AskEditor.d.ts.map +1 -0
- package/dist/AskEditor.js +19 -0
- package/dist/AskEditor.js.map +1 -0
- package/dist/AskOverlay.d.ts +19 -1
- package/dist/AskOverlay.d.ts.map +1 -1
- package/dist/AskOverlay.js +18 -280
- package/dist/AskOverlay.js.map +1 -1
- package/dist/AskPanel.d.ts +49 -0
- package/dist/AskPanel.d.ts.map +1 -0
- package/dist/AskPanel.js +25 -0
- package/dist/AskPanel.js.map +1 -0
- package/dist/EditorScrollbar.d.ts +24 -0
- package/dist/EditorScrollbar.d.ts.map +1 -0
- package/dist/EditorScrollbar.js +41 -0
- package/dist/EditorScrollbar.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/launch.d.ts +2 -0
- package/dist/launch.d.ts.map +1 -1
- package/dist/launch.js +1 -1
- package/dist/launch.js.map +1 -1
- package/dist/use-ask-editor.d.ts +93 -0
- package/dist/use-ask-editor.d.ts.map +1 -0
- package/dist/use-ask-editor.js +414 -0
- package/dist/use-ask-editor.js.map +1 -0
- package/package.json +11 -11
- package/src/Ask.tsx +31 -164
- package/src/AskEditor.tsx +69 -0
- package/src/AskOverlay.tsx +52 -367
- package/src/AskPanel.tsx +152 -0
- package/src/EditorScrollbar.tsx +55 -0
- package/src/index.ts +16 -0
- package/src/launch.tsx +3 -0
- package/src/use-ask-editor.ts +558 -0
package/README.md
CHANGED
|
@@ -3,3 +3,39 @@
|
|
|
3
3
|
Terminal text input gathering.
|
|
4
4
|
|
|
5
5
|
Part of the [Tooee](https://github.com/gingerhendrix/tooee) monorepo. See the main repo for documentation.
|
|
6
|
+
|
|
7
|
+
## Architecture
|
|
8
|
+
|
|
9
|
+
Three layers, each independently exported:
|
|
10
|
+
|
|
11
|
+
- `useAskEditor()` — headless core. Owns editor state and registers all editing
|
|
12
|
+
commands (vim motions, insert entries, submit/cancel/escape) on the nearest
|
|
13
|
+
command surface. Returns a `controller` (programmatic text control: `getText`,
|
|
14
|
+
`setText`, `insertText`, `setCursorToEnd`, `submit`, `mode`/`setMode`) and an
|
|
15
|
+
`editor` view-model for `<AskEditor/>`.
|
|
16
|
+
- `<AskEditor/>` / `<AskPanel/>` — presentational parts. `AskEditor` renders the
|
|
17
|
+
themed textarea/input plus scrollbar; `AskPanel` is the bordered panel chrome
|
|
18
|
+
with `title`, `prompt`, `hints`, `statusRight`, `footer`, and `inset` slots.
|
|
19
|
+
`buildAskHints(mode, { multiline, extra })` builds the default hint entries.
|
|
20
|
+
- `<Ask/>` (fullscreen), `<AskOverlay/>` (embedded), `launch()` — thin
|
|
21
|
+
assemblies of the core. `AskOverlay` additionally accepts `commands`
|
|
22
|
+
(extra `ActionDefinition[]` on this surface), `controllerRef`, chrome
|
|
23
|
+
pass-throughs, and `children` for nested overlays.
|
|
24
|
+
|
|
25
|
+
Composites that open a nested picker should wrap it in a modal
|
|
26
|
+
`CommandSurfaceProvider` — while mounted it owns the keyboard, and every ask
|
|
27
|
+
command plus editor focus suspends automatically; no `when` guards or
|
|
28
|
+
`pickerOpen` props are needed.
|
|
29
|
+
|
|
30
|
+
The low-level vim helpers (`handleEditBufferVimMotion`, `appendAtCursor`,
|
|
31
|
+
`openLineAtCursor`) are exported for non-React or custom hosts.
|
|
32
|
+
|
|
33
|
+
## Reserved keys
|
|
34
|
+
|
|
35
|
+
Cursor mode: `h j k l 0 $ w b g G i a o O q Escape Enter Shift+Enter`, arrows,
|
|
36
|
+
`home`/`end`. Insert mode: `Escape`, the submit key(s).
|
|
37
|
+
|
|
38
|
+
Consumers extending with `commands` should avoid these; `m`, `d`, `x`, `c`, and
|
|
39
|
+
ctrl-chords are free today. Future vim work (`x`, `dd`, counts) will claim more
|
|
40
|
+
single letters — composites should prefer ctrl-chords or leader sequences for
|
|
41
|
+
anything beyond one or two mnemonic keys.
|
package/dist/Ask.d.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import type { ActionDefinition } from "@tooee/commands";
|
|
2
2
|
import type { AskOptions } from "./types.js";
|
|
3
|
-
|
|
4
|
-
interface CommandContext {
|
|
5
|
-
/** Contributed by Ask: the current input value. */
|
|
6
|
-
ask: {
|
|
7
|
-
value: string;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
interface AskProps extends AskOptions {
|
|
3
|
+
export interface AskProps extends AskOptions {
|
|
12
4
|
actions?: ActionDefinition[];
|
|
5
|
+
/**
|
|
6
|
+
* Called with the submitted text. Defaults to writing the value to stdout
|
|
7
|
+
* and destroying the renderer (the standalone `ask` CLI behaviour). A
|
|
8
|
+
* `submit` action takes precedence over both.
|
|
9
|
+
*/
|
|
10
|
+
onSubmit?: (value: string) => void;
|
|
13
11
|
}
|
|
14
|
-
export declare function Ask({ title, prompt, placeholder, defaultValue, multiline, actions, }: AskProps): import("react").ReactNode;
|
|
15
|
-
export {};
|
|
12
|
+
export declare function Ask({ title, prompt, placeholder, defaultValue, multiline, actions, onSubmit, }: AskProps): import("react").ReactNode;
|
|
16
13
|
//# sourceMappingURL=Ask.d.ts.map
|
package/dist/Ask.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Ask.d.ts","sourceRoot":"","sources":["../src/Ask.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Ask.d.ts","sourceRoot":"","sources":["../src/Ask.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAI5C,MAAM,WAAW,QAAS,SAAQ,UAAU;IAC1C,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAA;IAC5B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CACnC;AAED,wBAAgB,GAAG,CAAC,EAClB,KAAK,EACL,MAAM,EACN,WAAW,EACX,YAAY,EACZ,SAAgB,EAChB,OAAO,EACP,QAAQ,GACT,EAAE,QAAQ,6BA+FV"}
|
package/dist/Ask.js
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "@opentui/react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { useKeyboard, useRenderer } from "@opentui/react";
|
|
4
|
-
import { readPrimaryText } from "@tooee/clipboard";
|
|
2
|
+
import { useRenderer } from "@opentui/react";
|
|
5
3
|
import { AppLayout } from "@tooee/layout";
|
|
6
4
|
import { useHasOverlay } from "@tooee/overlays";
|
|
7
5
|
import { ThemePicker, useTheme } from "@tooee/themes";
|
|
8
6
|
import { useThemeCommands, useQuitCommand, usePasteCommands } from "@tooee/shell";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
7
|
+
import { useActions, useProvideCommandContext, useCommandContext } from "@tooee/commands";
|
|
8
|
+
import { AskEditor } from "./AskEditor.js";
|
|
9
|
+
import { useAskEditor } from "./use-ask-editor.js";
|
|
10
|
+
export function Ask({ title, prompt, placeholder, defaultValue, multiline = true, actions, onSubmit, }) {
|
|
12
11
|
const renderer = useRenderer();
|
|
13
|
-
const [value, setValue] = useState(defaultValue ?? "");
|
|
14
|
-
const textareaRef = useRef(null);
|
|
15
|
-
const inputRef = useRef(null);
|
|
16
|
-
const didPositionInitialCursorRef = useRef(false);
|
|
17
|
-
const vimMotionStateRef = useRef({ pendingG: false });
|
|
18
12
|
const { invoke } = useCommandContext();
|
|
19
13
|
const { theme } = useTheme();
|
|
20
14
|
const { name: themeName, picker: themePicker } = useThemeCommands();
|
|
@@ -24,108 +18,35 @@ export function Ask({ title, prompt, placeholder, defaultValue, multiline = true
|
|
|
24
18
|
process.exit(0);
|
|
25
19
|
},
|
|
26
20
|
});
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
// Legacy overlays don't push a command surface; keep blurring the editor
|
|
22
|
+
// under them via the shell's overlay state.
|
|
29
23
|
const hasOverlay = useHasOverlay();
|
|
30
|
-
const
|
|
31
|
-
const cursorStyle = mode === "cursor" ? { style: "block", blinking: false } : { style: "line", blinking: true };
|
|
32
|
-
const cursorColor = mode === "cursor" ? theme.accent : theme.primary;
|
|
33
|
-
const preventCursorModeEditorInput = (event) => {
|
|
34
|
-
if (mode === "cursor")
|
|
35
|
-
event.preventDefault();
|
|
36
|
-
};
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
if (didPositionInitialCursorRef.current || !defaultValue)
|
|
39
|
-
return;
|
|
40
|
-
const target = multiline ? textareaRef.current : inputRef.current;
|
|
41
|
-
if (!target)
|
|
42
|
-
return;
|
|
43
|
-
target.cursorOffset = target.plainText.length;
|
|
44
|
-
didPositionInitialCursorRef.current = true;
|
|
45
|
-
}, [defaultValue, multiline]);
|
|
46
|
-
const handleSubmit = () => {
|
|
47
|
-
const text = multiline ? (textareaRef.current?.plainText ?? "") : value;
|
|
24
|
+
const handleSubmit = (text) => {
|
|
48
25
|
if (actions?.some((a) => a.id === "submit")) {
|
|
49
26
|
invoke("submit");
|
|
50
27
|
return;
|
|
51
28
|
}
|
|
29
|
+
if (onSubmit) {
|
|
30
|
+
onSubmit(text);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
52
33
|
process.stdout.write(text + "\n");
|
|
53
34
|
renderer.destroy();
|
|
54
35
|
};
|
|
36
|
+
const { controller, editor } = useAskEditor({
|
|
37
|
+
multiline,
|
|
38
|
+
defaultValue,
|
|
39
|
+
placeholder,
|
|
40
|
+
onSubmit: handleSubmit,
|
|
41
|
+
suspended: hasOverlay,
|
|
42
|
+
});
|
|
55
43
|
useProvideCommandContext(() => ({
|
|
56
|
-
ask: { value: multiline ? (textareaRef.current?.plainText ?? "") : value },
|
|
57
44
|
exit: () => renderer.destroy(),
|
|
58
45
|
}));
|
|
59
46
|
useActions(actions);
|
|
60
47
|
// Paste commands (available via command palette)
|
|
61
|
-
usePasteCommands({
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
useKeyboard((key) => {
|
|
65
|
-
if (hasOverlay)
|
|
66
|
-
return;
|
|
67
|
-
if (key.name === "escape") {
|
|
68
|
-
if (mode === "insert") {
|
|
69
|
-
setMode("cursor");
|
|
70
|
-
}
|
|
71
|
-
// In cursor mode, escape does nothing - use 'q' to quit
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (mode === "cursor") {
|
|
75
|
-
const target = multiline ? textareaRef.current : inputRef.current;
|
|
76
|
-
if (key.name === "i" || key.raw === "i") {
|
|
77
|
-
key.preventDefault();
|
|
78
|
-
vimMotionStateRef.current.pendingG = false;
|
|
79
|
-
setMode("insert");
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
if (key.name === "a" || key.raw === "a") {
|
|
83
|
-
key.preventDefault();
|
|
84
|
-
vimMotionStateRef.current.pendingG = false;
|
|
85
|
-
appendAtCursor(target);
|
|
86
|
-
setMode("insert");
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
if (multiline && ((key.name === "o" && key.shift) || key.raw === "O")) {
|
|
90
|
-
key.preventDefault();
|
|
91
|
-
vimMotionStateRef.current.pendingG = false;
|
|
92
|
-
openLineAtCursor(target, "above");
|
|
93
|
-
setMode("insert");
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
if (multiline && (key.name === "o" || key.raw === "o")) {
|
|
97
|
-
key.preventDefault();
|
|
98
|
-
vimMotionStateRef.current.pendingG = false;
|
|
99
|
-
openLineAtCursor(target, "below");
|
|
100
|
-
setMode("insert");
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
if (handleEditBufferVimMotion(key, target, vimMotionStateRef.current))
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
vimMotionStateRef.current.pendingG = false;
|
|
108
|
-
}
|
|
109
|
-
if (key.name === "return") {
|
|
110
|
-
if (multiline ? key.shift : true) {
|
|
111
|
-
key.preventDefault();
|
|
112
|
-
handleSubmit();
|
|
113
|
-
}
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
// Middle-click paste from primary selection
|
|
118
|
-
const handleMouseDown = useCallback((event) => {
|
|
119
|
-
if (event.button === 1) {
|
|
120
|
-
event.preventDefault();
|
|
121
|
-
void readPrimaryText().then((text) => {
|
|
122
|
-
if (!text)
|
|
123
|
-
return;
|
|
124
|
-
const target = multiline ? textareaRef.current : inputRef.current;
|
|
125
|
-
target?.insertText(text);
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}, [multiline]);
|
|
48
|
+
usePasteCommands({ getTarget: () => controller });
|
|
49
|
+
const mode = editor.mode;
|
|
129
50
|
const submitHint = multiline ? "Shift+Enter submit" : "Enter submit";
|
|
130
51
|
const hintParts = mode === "insert"
|
|
131
52
|
? [submitHint, "Esc commands"]
|
|
@@ -136,6 +57,6 @@ export function Ask({ title, prompt, placeholder, defaultValue, multiline = true
|
|
|
136
57
|
{ label: "Theme:", value: themeName },
|
|
137
58
|
{ label: "", value: hintParts.join(" ") },
|
|
138
59
|
],
|
|
139
|
-
}, scrollProps: { focused: false }, overlay: themePicker.isOpen ? (_jsx(ThemePicker, { entries: themePicker.entries, currentTheme: themeName, onSelect: themePicker.confirm, onClose: themePicker.close, onNavigate: themePicker.preview })) : undefined, children: _jsx("box", { flexDirection: "column", alignItems: "center", justifyContent: "center", style: { flexGrow: 1 }, onMouseDown:
|
|
60
|
+
}, scrollProps: { focused: false }, overlay: themePicker.isOpen ? (_jsx(ThemePicker, { entries: themePicker.entries, currentTheme: themeName, onSelect: themePicker.confirm, onClose: themePicker.close, onNavigate: themePicker.preview })) : undefined, children: _jsx("box", { flexDirection: "column", alignItems: "center", justifyContent: "center", style: { flexGrow: 1 }, onMouseDown: editor.onMouseDown, children: _jsxs("box", { flexDirection: "column", width: "100%", maxWidth: 80, style: { flexGrow: 1, padding: 1 }, children: [prompt && (_jsx("text", { fg: theme.text, style: { marginBottom: 1 }, children: _jsx("strong", { children: prompt }) })), _jsx(AskEditor, { editor: editor })] }) }) }));
|
|
140
61
|
}
|
|
141
62
|
//# sourceMappingURL=Ask.js.map
|
package/dist/Ask.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Ask.js","sourceRoot":"","sources":["../src/Ask.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"Ask.js","sourceRoot":"","sources":["../src/Ask.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACjF,OAAO,EAAE,UAAU,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAGzF,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAYlD,MAAM,UAAU,GAAG,CAAC,EAClB,KAAK,EACL,MAAM,EACN,WAAW,EACX,YAAY,EACZ,SAAS,GAAG,IAAI,EAChB,OAAO,EACP,QAAQ,GACC;IACT,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAA;IAC9B,MAAM,EAAE,MAA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eAAK,aAAa,EAAC,QAAQ,EAAC,KAAK,EAAC,MAAM,EAAC,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,aACtF,MAAM,IAAI,CACT,eAAM,EAAE,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,YAC9C,2BAAS,MAAM,GAAU,GACpB,CACR,EACD,KAAC,SAAS,IAAC,MAAM,EAAE,MAAM,GAAI,IACzB,GACF,GACI,CACb,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AskEditorViewModel } from "./use-ask-editor.js";
|
|
2
|
+
export interface AskEditorProps {
|
|
3
|
+
editor: AskEditorViewModel;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Presentational ask editor: the themed textarea/input plus scrollbar. All
|
|
7
|
+
* behaviour lives in the view-model from `useAskEditor`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function AskEditor({ editor }: AskEditorProps): import("react").ReactNode;
|
|
10
|
+
//# sourceMappingURL=AskEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AskEditor.d.ts","sourceRoot":"","sources":["../src/AskEditor.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAE7D,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,kBAAkB,CAAA;CAC3B;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,EAAE,MAAM,EAAE,EAAE,cAAc,6BAuDnD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@opentui/react/jsx-runtime";
|
|
2
|
+
import { useTheme } from "@tooee/themes";
|
|
3
|
+
import { EditorScrollbar } from "./EditorScrollbar.js";
|
|
4
|
+
/**
|
|
5
|
+
* Presentational ask editor: the themed textarea/input plus scrollbar. All
|
|
6
|
+
* behaviour lives in the view-model from `useAskEditor`.
|
|
7
|
+
*/
|
|
8
|
+
export function AskEditor({ editor }) {
|
|
9
|
+
const { theme } = useTheme();
|
|
10
|
+
const cursorStyle = editor.mode === "cursor"
|
|
11
|
+
? { style: "block", blinking: false }
|
|
12
|
+
: { style: "line", blinking: true };
|
|
13
|
+
const cursorColor = editor.mode === "cursor" ? theme.accent : theme.primary;
|
|
14
|
+
if (editor.multiline) {
|
|
15
|
+
return (_jsxs("box", { flexDirection: "row", style: { flexGrow: 1 }, onMouseScroll: editor.bumpScroll, children: [_jsx("textarea", { ref: editor.textareaRef, focused: editor.focused, initialValue: editor.defaultValue, placeholder: editor.placeholder, textColor: theme.text, placeholderColor: theme.textMuted, cursorColor: cursorColor, cursorStyle: cursorStyle, backgroundColor: "transparent", onSubmit: editor.submit, onKeyDown: editor.onEditorKeyDown, onPaste: editor.onEditorPaste, onCursorChange: editor.bumpScroll, onContentChange: editor.bumpScroll, style: { flexGrow: 1 } }), _jsx(EditorScrollbar, { target: editor.textareaRef.current, revision: editor.scrollRevision, color: theme.textMuted })] }));
|
|
16
|
+
}
|
|
17
|
+
return (_jsx("input", { ref: editor.inputRef, focused: editor.focused, value: editor.value, onInput: editor.onInput, onSubmit: editor.submit, placeholder: editor.placeholder, textColor: theme.text, placeholderColor: theme.textMuted, cursorColor: cursorColor, cursorStyle: cursorStyle, backgroundColor: "transparent", onKeyDown: editor.onEditorKeyDown, onPaste: editor.onEditorPaste }));
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=AskEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AskEditor.js","sourceRoot":"","sources":["../src/AskEditor.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAOtD;;;GAGG;AACH,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MAAM,CAAC,cAAc,EAC/B,KAAK,EAAE,KAAK,CAAC,SAAS,GACtB,IACE,CACP,CAAA;IACH,CAAC;IAED,OAAO,CACL,gBACE,GAAG,EAAE,MAAM,CAAC,QAAQ,EACpB,OAAO,EAAE,MAAM,CAAC,OAAO,EACvB,KAAK,EAAE,MAAM,CAAC,KAAK,EACnB,OAAO,EAAE,MAAM,CAAC,OAAO,EACvB,QAAQ,EAAE,MAAM,CAAC,MAAM,EACvB,WAAW,EAAE,MAAM,CAAC,WAAW,EAC/B,SAAS,EAAE,KAAK,CAAC,IAAI,EACrB,gBAAgB,EAAE,KAAK,CAAC,SAAS,EACjC,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,eAAe,EAAC,aAAa,EAC7B,SAAS,EAAE,MAAM,CAAC,eAAe,EACjC,OAAO,EAAE,MAAM,CAAC,aAAa,GAC7B,CACH,CAAA;AACH,CAAC"}
|
package/dist/AskOverlay.d.ts
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
|
+
import { type ReactNode, type Ref } from "react";
|
|
2
|
+
import { type ActionDefinition } from "@tooee/commands";
|
|
3
|
+
import { type AskPanelProps } from "./AskPanel.js";
|
|
4
|
+
import { type AskEditorController } from "./use-ask-editor.js";
|
|
1
5
|
export interface AskOverlayProps {
|
|
2
6
|
prompt: string;
|
|
7
|
+
/** Title bar content; when set, `prompt` renders as a line above the editor. */
|
|
8
|
+
title?: string;
|
|
3
9
|
multiline?: boolean;
|
|
4
10
|
defaultValue?: string;
|
|
11
|
+
placeholder?: string;
|
|
5
12
|
onSubmit: (value: string) => void | Promise<void>;
|
|
6
13
|
onCancel: () => void;
|
|
14
|
+
/** Extra commands registered on this surface (same shape as Ask's actions). */
|
|
15
|
+
commands?: ActionDefinition[];
|
|
16
|
+
/** Access to the text controller (dictation, prefill, transforms). */
|
|
17
|
+
controllerRef?: Ref<AskEditorController>;
|
|
18
|
+
/** Chrome pass-throughs. */
|
|
19
|
+
hints?: AskPanelProps["hints"];
|
|
20
|
+
statusRight?: ReactNode;
|
|
21
|
+
footer?: ReactNode;
|
|
22
|
+
inset?: AskPanelProps["inset"];
|
|
23
|
+
/** Nested overlays (pickers) rendered above the panel. */
|
|
24
|
+
children?: ReactNode;
|
|
7
25
|
}
|
|
8
|
-
export declare function AskOverlay({ prompt, multiline, defaultValue, onSubmit, onCancel, }: AskOverlayProps):
|
|
26
|
+
export declare function AskOverlay({ prompt, title, multiline, defaultValue, placeholder, onSubmit, onCancel, commands, controllerRef, hints, statusRight, footer, inset, children, }: AskOverlayProps): ReactNode;
|
|
9
27
|
//# sourceMappingURL=AskOverlay.d.ts.map
|
package/dist/AskOverlay.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AskOverlay.d.ts","sourceRoot":"","sources":["../src/AskOverlay.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AskOverlay.d.ts","sourceRoot":"","sources":["../src/AskOverlay.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,SAAS,EAAE,KAAK,GAAG,EAAE,MAAM,OAAO,CAAA;AACrE,OAAO,EAAc,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAEnE,OAAO,EAAY,KAAK,aAAa,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,EAAgB,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAE5E,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,gFAAgF;IAChF,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACjD,QAAQ,EAAE,MAAM,IAAI,CAAA;IACpB,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,gBAAgB,EAAE,CAAA;IAC7B,sEAAsE;IACtE,aAAa,CAAC,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAA;IACxC,4BAA4B;IAC5B,KAAK,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAA;IAC9B,WAAW,CAAC,EAAE,SAAS,CAAA;IACvB,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB,KAAK,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAA;IAC9B,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB;AAED,wBAAgB,UAAU,CAAC,EACzB,MAAM,EACN,KAAK,EACL,SAAS,EACT,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,KAAK,EACL,WAAW,EACX,MAAM,EACN,KAAK,EACL,QAAQ,GACT,EAAE,eAAe,aA+BjB"}
|
package/dist/AskOverlay.js
CHANGED
|
@@ -1,282 +1,20 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "@opentui/react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
export function AskOverlay({ prompt, multiline, defaultValue, onSubmit, onCancel, }) {
|
|
8
|
-
const {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const preventCursorModeEditorInput = (event) => {
|
|
20
|
-
if (mode === "cursor")
|
|
21
|
-
event.preventDefault();
|
|
22
|
-
};
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
if (didPositionInitialCursorRef.current || !defaultValue)
|
|
25
|
-
return;
|
|
26
|
-
const target = multiline ? textareaRef.current : inputRef.current;
|
|
27
|
-
if (!target)
|
|
28
|
-
return;
|
|
29
|
-
target.cursorOffset = target.plainText.length;
|
|
30
|
-
didPositionInitialCursorRef.current = true;
|
|
31
|
-
}, [defaultValue, multiline]);
|
|
32
|
-
const handleSubmit = () => {
|
|
33
|
-
const text = multiline ? (textareaRef.current?.plainText ?? "") : value;
|
|
34
|
-
onSubmit(text);
|
|
35
|
-
};
|
|
36
|
-
const enterInsertMode = useCallback(() => {
|
|
37
|
-
vimMotionStateRef.current.pendingG = false;
|
|
38
|
-
setMode("insert");
|
|
39
|
-
}, [setMode]);
|
|
40
|
-
const appendAndEnterInsertMode = useCallback(() => {
|
|
41
|
-
vimMotionStateRef.current.pendingG = false;
|
|
42
|
-
appendAtCursor(multiline ? textareaRef.current : inputRef.current);
|
|
43
|
-
setMode("insert");
|
|
44
|
-
}, [multiline, setMode]);
|
|
45
|
-
const openLineAbove = useCallback(() => {
|
|
46
|
-
if (!multiline)
|
|
47
|
-
return;
|
|
48
|
-
vimMotionStateRef.current.pendingG = false;
|
|
49
|
-
openLineAtCursor(textareaRef.current, "above");
|
|
50
|
-
setMode("insert");
|
|
51
|
-
}, [multiline, setMode]);
|
|
52
|
-
const openLineBelow = useCallback(() => {
|
|
53
|
-
if (!multiline)
|
|
54
|
-
return;
|
|
55
|
-
vimMotionStateRef.current.pendingG = false;
|
|
56
|
-
openLineAtCursor(textareaRef.current, "below");
|
|
57
|
-
setMode("insert");
|
|
58
|
-
}, [multiline, setMode]);
|
|
59
|
-
const leaveInsertMode = useCallback(() => {
|
|
60
|
-
vimMotionStateRef.current.pendingG = false;
|
|
61
|
-
setMode("cursor");
|
|
62
|
-
}, [setMode]);
|
|
63
|
-
useCommand({
|
|
64
|
-
id: "ask-overlay:leave-insert-mode",
|
|
65
|
-
title: "Command mode",
|
|
66
|
-
hotkey: "Escape",
|
|
67
|
-
modes: ["insert"],
|
|
68
|
-
hidden: true,
|
|
69
|
-
handler: leaveInsertMode,
|
|
70
|
-
});
|
|
71
|
-
useCommand({
|
|
72
|
-
id: "ask-overlay:cancel",
|
|
73
|
-
title: "Cancel",
|
|
74
|
-
hotkey: "q",
|
|
75
|
-
modes: ["cursor"],
|
|
76
|
-
hidden: true,
|
|
77
|
-
handler: onCancel,
|
|
78
|
-
});
|
|
79
|
-
useCommand({
|
|
80
|
-
id: "ask-overlay:insert-mode-i",
|
|
81
|
-
title: "Insert mode",
|
|
82
|
-
hotkey: "i",
|
|
83
|
-
modes: ["cursor"],
|
|
84
|
-
hidden: true,
|
|
85
|
-
handler: enterInsertMode,
|
|
86
|
-
});
|
|
87
|
-
useCommand({
|
|
88
|
-
id: "ask-overlay:insert-mode-a",
|
|
89
|
-
title: "Append",
|
|
90
|
-
hotkey: "a",
|
|
91
|
-
modes: ["cursor"],
|
|
92
|
-
hidden: true,
|
|
93
|
-
handler: appendAndEnterInsertMode,
|
|
94
|
-
});
|
|
95
|
-
useCommand({
|
|
96
|
-
id: "ask-overlay:open-line-above",
|
|
97
|
-
title: "Open line above",
|
|
98
|
-
hotkey: "shift+o",
|
|
99
|
-
modes: ["cursor"],
|
|
100
|
-
hidden: true,
|
|
101
|
-
when: () => multiline === true,
|
|
102
|
-
handler: openLineAbove,
|
|
103
|
-
});
|
|
104
|
-
useCommand({
|
|
105
|
-
id: "ask-overlay:open-line-below",
|
|
106
|
-
title: "Open line below",
|
|
107
|
-
hotkey: "o",
|
|
108
|
-
modes: ["cursor"],
|
|
109
|
-
hidden: true,
|
|
110
|
-
when: () => multiline === true,
|
|
111
|
-
handler: openLineBelow,
|
|
112
|
-
});
|
|
113
|
-
useCommand({
|
|
114
|
-
id: "ask-overlay:submit-single-line",
|
|
115
|
-
title: "Submit",
|
|
116
|
-
hotkey: "Enter",
|
|
117
|
-
modes: ["insert", "cursor"],
|
|
118
|
-
hidden: true,
|
|
119
|
-
when: () => multiline !== true,
|
|
120
|
-
handler: handleSubmit,
|
|
121
|
-
});
|
|
122
|
-
useCommand({
|
|
123
|
-
id: "ask-overlay:submit-multiline",
|
|
124
|
-
title: "Submit",
|
|
125
|
-
hotkey: "shift+Enter",
|
|
126
|
-
modes: ["insert", "cursor"],
|
|
127
|
-
hidden: true,
|
|
128
|
-
when: () => multiline === true,
|
|
129
|
-
handler: handleSubmit,
|
|
130
|
-
});
|
|
131
|
-
const getMotionTarget = useCallback(() => (multiline ? textareaRef.current : inputRef.current), [multiline]);
|
|
132
|
-
const motion = useCallback((run) => {
|
|
133
|
-
const target = getMotionTarget();
|
|
134
|
-
if (target)
|
|
135
|
-
run(target);
|
|
136
|
-
vimMotionStateRef.current.pendingG = false;
|
|
137
|
-
}, [getMotionTarget]);
|
|
138
|
-
useCommand({
|
|
139
|
-
id: "ask-overlay:move-left",
|
|
140
|
-
title: "Move left",
|
|
141
|
-
hotkey: "h",
|
|
142
|
-
modes: ["cursor"],
|
|
143
|
-
hidden: true,
|
|
144
|
-
handler: () => motion((target) => target.moveCursorLeft()),
|
|
145
|
-
});
|
|
146
|
-
useCommand({
|
|
147
|
-
id: "ask-overlay:move-left-arrow",
|
|
148
|
-
title: "Move left",
|
|
149
|
-
hotkey: "left",
|
|
150
|
-
modes: ["cursor"],
|
|
151
|
-
hidden: true,
|
|
152
|
-
handler: () => motion((target) => target.moveCursorLeft()),
|
|
153
|
-
});
|
|
154
|
-
useCommand({
|
|
155
|
-
id: "ask-overlay:move-right",
|
|
156
|
-
title: "Move right",
|
|
157
|
-
hotkey: "l",
|
|
158
|
-
modes: ["cursor"],
|
|
159
|
-
hidden: true,
|
|
160
|
-
handler: () => motion((target) => target.moveCursorRight()),
|
|
161
|
-
});
|
|
162
|
-
useCommand({
|
|
163
|
-
id: "ask-overlay:move-right-arrow",
|
|
164
|
-
title: "Move right",
|
|
165
|
-
hotkey: "right",
|
|
166
|
-
modes: ["cursor"],
|
|
167
|
-
hidden: true,
|
|
168
|
-
handler: () => motion((target) => target.moveCursorRight()),
|
|
169
|
-
});
|
|
170
|
-
useCommand({
|
|
171
|
-
id: "ask-overlay:move-down",
|
|
172
|
-
title: "Move down",
|
|
173
|
-
hotkey: "j",
|
|
174
|
-
modes: ["cursor"],
|
|
175
|
-
hidden: true,
|
|
176
|
-
handler: () => motion((target) => target.moveCursorDown()),
|
|
177
|
-
});
|
|
178
|
-
useCommand({
|
|
179
|
-
id: "ask-overlay:move-down-arrow",
|
|
180
|
-
title: "Move down",
|
|
181
|
-
hotkey: "down",
|
|
182
|
-
modes: ["cursor"],
|
|
183
|
-
hidden: true,
|
|
184
|
-
handler: () => motion((target) => target.moveCursorDown()),
|
|
185
|
-
});
|
|
186
|
-
useCommand({
|
|
187
|
-
id: "ask-overlay:move-up",
|
|
188
|
-
title: "Move up",
|
|
189
|
-
hotkey: "k",
|
|
190
|
-
modes: ["cursor"],
|
|
191
|
-
hidden: true,
|
|
192
|
-
handler: () => motion((target) => target.moveCursorUp()),
|
|
193
|
-
});
|
|
194
|
-
useCommand({
|
|
195
|
-
id: "ask-overlay:move-up-arrow",
|
|
196
|
-
title: "Move up",
|
|
197
|
-
hotkey: "up",
|
|
198
|
-
modes: ["cursor"],
|
|
199
|
-
hidden: true,
|
|
200
|
-
handler: () => motion((target) => target.moveCursorUp()),
|
|
201
|
-
});
|
|
202
|
-
useCommand({
|
|
203
|
-
id: "ask-overlay:line-home",
|
|
204
|
-
title: "Line home",
|
|
205
|
-
hotkey: "0",
|
|
206
|
-
modes: ["cursor"],
|
|
207
|
-
hidden: true,
|
|
208
|
-
handler: () => motion((target) => target.gotoLineHome()),
|
|
209
|
-
});
|
|
210
|
-
useCommand({
|
|
211
|
-
id: "ask-overlay:line-home-key",
|
|
212
|
-
title: "Line home",
|
|
213
|
-
hotkey: "home",
|
|
214
|
-
modes: ["cursor"],
|
|
215
|
-
hidden: true,
|
|
216
|
-
handler: () => motion((target) => target.gotoLineHome()),
|
|
217
|
-
});
|
|
218
|
-
useCommand({
|
|
219
|
-
id: "ask-overlay:line-end",
|
|
220
|
-
title: "Line end",
|
|
221
|
-
hotkey: "shift+4",
|
|
222
|
-
modes: ["cursor"],
|
|
223
|
-
hidden: true,
|
|
224
|
-
handler: () => motion((target) => target.gotoLineEnd()),
|
|
225
|
-
});
|
|
226
|
-
useCommand({
|
|
227
|
-
id: "ask-overlay:line-end-key",
|
|
228
|
-
title: "Line end",
|
|
229
|
-
hotkey: "end",
|
|
230
|
-
modes: ["cursor"],
|
|
231
|
-
hidden: true,
|
|
232
|
-
handler: () => motion((target) => target.gotoLineEnd()),
|
|
233
|
-
});
|
|
234
|
-
useCommand({
|
|
235
|
-
id: "ask-overlay:word-forward",
|
|
236
|
-
title: "Word forward",
|
|
237
|
-
hotkey: "w",
|
|
238
|
-
modes: ["cursor"],
|
|
239
|
-
hidden: true,
|
|
240
|
-
handler: () => motion((target) => target.moveWordForward()),
|
|
241
|
-
});
|
|
242
|
-
useCommand({
|
|
243
|
-
id: "ask-overlay:word-backward",
|
|
244
|
-
title: "Word backward",
|
|
245
|
-
hotkey: "b",
|
|
246
|
-
modes: ["cursor"],
|
|
247
|
-
hidden: true,
|
|
248
|
-
handler: () => motion((target) => target.moveWordBackward()),
|
|
249
|
-
});
|
|
250
|
-
useCommand({
|
|
251
|
-
id: "ask-overlay:buffer-home",
|
|
252
|
-
title: "Buffer home",
|
|
253
|
-
hotkey: "g g",
|
|
254
|
-
modes: ["cursor"],
|
|
255
|
-
hidden: true,
|
|
256
|
-
handler: () => motion((target) => target.gotoBufferHome()),
|
|
257
|
-
});
|
|
258
|
-
useCommand({
|
|
259
|
-
id: "ask-overlay:buffer-end",
|
|
260
|
-
title: "Buffer end",
|
|
261
|
-
hotkey: "shift+g",
|
|
262
|
-
modes: ["cursor"],
|
|
263
|
-
hidden: true,
|
|
264
|
-
handler: () => motion((target) => target.gotoBufferEnd()),
|
|
265
|
-
});
|
|
266
|
-
// Middle-click paste from primary selection
|
|
267
|
-
const handleMouseDown = useCallback((event) => {
|
|
268
|
-
if (event.button === 1) {
|
|
269
|
-
event.preventDefault();
|
|
270
|
-
void readPrimaryText().then((text) => {
|
|
271
|
-
if (!text)
|
|
272
|
-
return;
|
|
273
|
-
const target = multiline ? textareaRef.current : inputRef.current;
|
|
274
|
-
target?.insertText(text);
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
}, [multiline]);
|
|
278
|
-
const submitHint = multiline ? "Shift+Enter submit" : "Enter submit";
|
|
279
|
-
const hintText = mode === "insert" ? `${submitHint} Esc commands` : `i insert q quit ${submitHint}`;
|
|
280
|
-
return (_jsxs("box", { position: "absolute", left: "20%", right: "20%", top: "20%", bottom: "20%", flexDirection: "column", backgroundColor: theme.backgroundPanel, border: true, borderColor: theme.borderActive, onMouseDown: handleMouseDown, children: [_jsxs("box", { flexDirection: "row", height: 1, paddingLeft: 1, paddingRight: 1, backgroundColor: theme.backgroundElement, children: [_jsx("text", { content: prompt, fg: theme.accent, style: { flexGrow: 1 } }), _jsx(CloseButton, { onClose: onCancel })] }), _jsx("box", { flexDirection: "column", style: { flexGrow: 1, paddingLeft: 1, paddingRight: 1 }, children: multiline ? (_jsx("textarea", { ref: textareaRef, focused: inputFocused, initialValue: defaultValue, textColor: theme.text, placeholderColor: theme.textMuted, cursorColor: cursorColor, cursorStyle: cursorStyle, backgroundColor: "transparent", onSubmit: handleSubmit, onKeyDown: preventCursorModeEditorInput, onPaste: preventCursorModeEditorInput, style: { flexGrow: 1 } })) : (_jsx("input", { ref: inputRef, focused: inputFocused, value: value, onInput: setValue, onSubmit: handleSubmit, textColor: theme.text, placeholderColor: theme.textMuted, cursorColor: cursorColor, cursorStyle: cursorStyle, backgroundColor: "transparent", onKeyDown: preventCursorModeEditorInput, onPaste: preventCursorModeEditorInput })) }), _jsx("box", { height: 1, paddingLeft: 1, paddingRight: 1, backgroundColor: theme.backgroundElement, children: _jsx("text", { content: hintText, fg: theme.textMuted }) })] }));
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "@opentui/react/jsx-runtime";
|
|
2
|
+
import { useImperativeHandle } from "react";
|
|
3
|
+
import { useActions } from "@tooee/commands";
|
|
4
|
+
import { AskEditor } from "./AskEditor.js";
|
|
5
|
+
import { AskPanel } from "./AskPanel.js";
|
|
6
|
+
import { useAskEditor } from "./use-ask-editor.js";
|
|
7
|
+
export function AskOverlay({ prompt, title, multiline, defaultValue, placeholder, onSubmit, onCancel, commands, controllerRef, hints, statusRight, footer, inset, children, }) {
|
|
8
|
+
const { controller, editor } = useAskEditor({
|
|
9
|
+
multiline,
|
|
10
|
+
defaultValue,
|
|
11
|
+
placeholder,
|
|
12
|
+
onSubmit,
|
|
13
|
+
onCancel,
|
|
14
|
+
commandScope: "ask-overlay",
|
|
15
|
+
});
|
|
16
|
+
useImperativeHandle(controllerRef, () => controller, [controller]);
|
|
17
|
+
useActions(commands);
|
|
18
|
+
return (_jsxs(_Fragment, { children: [_jsx(AskPanel, { title: title ?? prompt, prompt: title !== undefined ? prompt : undefined, multiline: multiline === true, hints: hints, statusRight: statusRight, footer: footer, onClose: onCancel, inset: inset, onMouseDown: editor.onMouseDown, children: _jsx(AskEditor, { editor: editor }) }), children] }));
|
|
281
19
|
}
|
|
282
20
|
//# sourceMappingURL=AskOverlay.js.map
|