giggles 0.3.1 → 0.3.2
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.
|
@@ -27,6 +27,7 @@ var InputProvider = ({ children }) => {
|
|
|
27
27
|
bindings: new Map(entries),
|
|
28
28
|
capture: (options == null ? void 0 : options.capture) ?? false,
|
|
29
29
|
onKeypress: options == null ? void 0 : options.onKeypress,
|
|
30
|
+
passthrough: (options == null ? void 0 : options.passthrough) ? new Set(options.passthrough) : void 0,
|
|
30
31
|
layer: options == null ? void 0 : options.layer
|
|
31
32
|
};
|
|
32
33
|
bindingsRef.current.set(nodeId, registration);
|
|
@@ -281,7 +282,9 @@ function normalizeKey(input, key) {
|
|
|
281
282
|
if (key.rightArrow) return "right";
|
|
282
283
|
if (key.return) return "enter";
|
|
283
284
|
if (key.escape) return "escape";
|
|
285
|
+
if (key.tab && key.shift) return "shift+tab";
|
|
284
286
|
if (key.tab) return "tab";
|
|
287
|
+
if (input === "\x1B[3~") return "delete";
|
|
285
288
|
if (key.backspace || key.delete) return "backspace";
|
|
286
289
|
if (key.pageUp) return "pageup";
|
|
287
290
|
if (key.pageDown) return "pagedown";
|
|
@@ -299,6 +302,7 @@ function InputRouter({ children }) {
|
|
|
299
302
|
const { getFocusedId, getActiveBranchPath } = useFocusContext();
|
|
300
303
|
const { getNodeBindings, getTrapNodeId, getAllBindings } = useInputContext();
|
|
301
304
|
useInput((input, key) => {
|
|
305
|
+
var _a;
|
|
302
306
|
const focusedId = getFocusedId();
|
|
303
307
|
if (!focusedId) return;
|
|
304
308
|
const path = getActiveBranchPath();
|
|
@@ -314,6 +318,9 @@ function InputRouter({ children }) {
|
|
|
314
318
|
return;
|
|
315
319
|
}
|
|
316
320
|
if (nodeBindings.capture && nodeBindings.onKeypress) {
|
|
321
|
+
if ((_a = nodeBindings.passthrough) == null ? void 0 : _a.has(keyName)) {
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
317
324
|
nodeBindings.onKeypress(input, key);
|
|
318
325
|
return;
|
|
319
326
|
}
|
|
@@ -396,7 +403,7 @@ function FocusGroup({
|
|
|
396
403
|
if (!navigable) return {};
|
|
397
404
|
const next = () => navigateSibling("next", wrap);
|
|
398
405
|
const prev = () => navigateSibling("prev", wrap);
|
|
399
|
-
|
|
406
|
+
const base = direction === "vertical" ? {
|
|
400
407
|
j: next,
|
|
401
408
|
k: prev,
|
|
402
409
|
down: next,
|
|
@@ -407,6 +414,7 @@ function FocusGroup({
|
|
|
407
414
|
right: next,
|
|
408
415
|
left: prev
|
|
409
416
|
};
|
|
417
|
+
return { ...base, tab: next, "shift+tab": prev };
|
|
410
418
|
}, [navigable, direction, wrap, navigateSibling]);
|
|
411
419
|
const mergedBindings = useMemo(
|
|
412
420
|
() => ({ ...navigationKeys, ...customBindings }),
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as React$1 from 'react';
|
|
3
3
|
import React__default from 'react';
|
|
4
|
-
import { K as Keybindings, a as KeybindingOptions, R as RegisteredKeybinding } from './types-
|
|
5
|
-
export { b as KeyHandler } from './types-
|
|
4
|
+
import { K as Keybindings, a as KeybindingOptions, R as RegisteredKeybinding } from './types-Dmw9TKt4.js';
|
|
5
|
+
export { b as KeyHandler } from './types-Dmw9TKt4.js';
|
|
6
6
|
export { Key } from 'ink';
|
|
7
7
|
|
|
8
8
|
declare class GigglesError extends Error {
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Key } from 'ink';
|
|
2
2
|
|
|
3
3
|
type KeyHandler = (input: string, key: Key) => void;
|
|
4
|
-
type SpecialKey = 'up' | 'down' | 'left' | 'right' | 'enter' | 'escape' | 'tab' | 'backspace' | 'pageup' | 'pagedown' | 'home' | 'end';
|
|
4
|
+
type SpecialKey = 'up' | 'down' | 'left' | 'right' | 'enter' | 'escape' | 'tab' | 'backspace' | 'delete' | 'pageup' | 'pagedown' | 'home' | 'end';
|
|
5
5
|
type KeyName = SpecialKey | (string & {});
|
|
6
6
|
type KeybindingDefinition = KeyHandler | {
|
|
7
7
|
action: KeyHandler;
|
|
@@ -12,6 +12,7 @@ type Keybindings = Partial<Record<KeyName, KeybindingDefinition>>;
|
|
|
12
12
|
type KeybindingOptions = {
|
|
13
13
|
capture?: boolean;
|
|
14
14
|
onKeypress?: (input: string, key: Key) => void;
|
|
15
|
+
passthrough?: string[];
|
|
15
16
|
layer?: string;
|
|
16
17
|
};
|
|
17
18
|
type RegisteredKeybinding = {
|
package/dist/ui/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React__default from 'react';
|
|
3
|
-
import { R as RegisteredKeybinding } from '../types-
|
|
3
|
+
import { R as RegisteredKeybinding } from '../types-Dmw9TKt4.js';
|
|
4
4
|
import 'ink';
|
|
5
5
|
|
|
6
6
|
type CommandPaletteRenderProps = {
|
|
@@ -15,4 +15,21 @@ type CommandPaletteProps = {
|
|
|
15
15
|
};
|
|
16
16
|
declare function CommandPalette({ onClose, render }: CommandPaletteProps): react_jsx_runtime.JSX.Element;
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
type TextInputRenderProps = {
|
|
19
|
+
value: string;
|
|
20
|
+
focused: boolean;
|
|
21
|
+
before: string;
|
|
22
|
+
cursorChar: string;
|
|
23
|
+
after: string;
|
|
24
|
+
};
|
|
25
|
+
type TextInputProps = {
|
|
26
|
+
label?: string;
|
|
27
|
+
value: string;
|
|
28
|
+
onChange: (value: string) => void;
|
|
29
|
+
onSubmit?: (value: string) => void;
|
|
30
|
+
placeholder?: string;
|
|
31
|
+
render?: (props: TextInputRenderProps) => React__default.ReactNode;
|
|
32
|
+
};
|
|
33
|
+
declare function TextInput({ label, value, onChange, onSubmit, placeholder, render }: TextInputProps): react_jsx_runtime.JSX.Element;
|
|
34
|
+
|
|
35
|
+
export { CommandPalette, type CommandPaletteRenderProps, TextInput, type TextInputRenderProps };
|
package/dist/ui/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
useFocus,
|
|
4
4
|
useKeybindingRegistry,
|
|
5
5
|
useKeybindings
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-OYQZHF73.js";
|
|
7
7
|
|
|
8
8
|
// src/ui/CommandPalette.tsx
|
|
9
9
|
import { useState } from "react";
|
|
@@ -95,6 +95,86 @@ function Inner({ onClose, render }) {
|
|
|
95
95
|
function CommandPalette({ onClose, render }) {
|
|
96
96
|
return /* @__PURE__ */ jsx(FocusTrap, { children: /* @__PURE__ */ jsx(Inner, { onClose, render }) });
|
|
97
97
|
}
|
|
98
|
+
|
|
99
|
+
// src/ui/TextInput.tsx
|
|
100
|
+
import { useReducer, useRef } from "react";
|
|
101
|
+
import { Text as Text2 } from "ink";
|
|
102
|
+
import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
103
|
+
function TextInput({ label, value, onChange, onSubmit, placeholder, render }) {
|
|
104
|
+
const focus = useFocus();
|
|
105
|
+
const cursorRef = useRef(value.length);
|
|
106
|
+
const [, forceRender] = useReducer((c) => c + 1, 0);
|
|
107
|
+
const cursor = Math.min(cursorRef.current, value.length);
|
|
108
|
+
cursorRef.current = cursor;
|
|
109
|
+
useKeybindings(
|
|
110
|
+
focus,
|
|
111
|
+
{
|
|
112
|
+
left: () => {
|
|
113
|
+
cursorRef.current = Math.max(0, cursorRef.current - 1);
|
|
114
|
+
forceRender();
|
|
115
|
+
},
|
|
116
|
+
right: () => {
|
|
117
|
+
cursorRef.current = Math.min(value.length, cursorRef.current + 1);
|
|
118
|
+
forceRender();
|
|
119
|
+
},
|
|
120
|
+
home: () => {
|
|
121
|
+
cursorRef.current = 0;
|
|
122
|
+
forceRender();
|
|
123
|
+
},
|
|
124
|
+
end: () => {
|
|
125
|
+
cursorRef.current = value.length;
|
|
126
|
+
forceRender();
|
|
127
|
+
},
|
|
128
|
+
backspace: () => {
|
|
129
|
+
const c = cursorRef.current;
|
|
130
|
+
if (c > 0) {
|
|
131
|
+
cursorRef.current = c - 1;
|
|
132
|
+
onChange(value.slice(0, c - 1) + value.slice(c));
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
delete: () => {
|
|
136
|
+
const c = cursorRef.current;
|
|
137
|
+
if (c < value.length) {
|
|
138
|
+
onChange(value.slice(0, c) + value.slice(c + 1));
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
...onSubmit && { enter: () => onSubmit(value) }
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
capture: true,
|
|
145
|
+
passthrough: ["tab", "shift+tab", "enter", "escape"],
|
|
146
|
+
onKeypress: (input, key) => {
|
|
147
|
+
if (input.length === 1 && !key.ctrl && !key.return && !key.escape && !key.tab) {
|
|
148
|
+
const c = cursorRef.current;
|
|
149
|
+
cursorRef.current = c + 1;
|
|
150
|
+
onChange(value.slice(0, c) + input + value.slice(c));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
);
|
|
155
|
+
const before = value.slice(0, cursor);
|
|
156
|
+
const cursorChar = value[cursor] ?? " ";
|
|
157
|
+
const after = value.slice(cursor + 1);
|
|
158
|
+
if (render) {
|
|
159
|
+
return /* @__PURE__ */ jsx2(Fragment2, { children: render({ value, focused: focus.focused, before, cursorChar, after }) });
|
|
160
|
+
}
|
|
161
|
+
const displayValue = value.length > 0 ? value : placeholder ?? "";
|
|
162
|
+
const isPlaceholder = value.length === 0;
|
|
163
|
+
const prefix = label != null ? `${label} ` : "";
|
|
164
|
+
if (focus.focused) {
|
|
165
|
+
return /* @__PURE__ */ jsxs2(Text2, { children: [
|
|
166
|
+
prefix,
|
|
167
|
+
before,
|
|
168
|
+
/* @__PURE__ */ jsx2(Text2, { inverse: true, children: cursorChar }),
|
|
169
|
+
after
|
|
170
|
+
] });
|
|
171
|
+
}
|
|
172
|
+
return /* @__PURE__ */ jsxs2(Text2, { children: [
|
|
173
|
+
prefix,
|
|
174
|
+
/* @__PURE__ */ jsx2(Text2, { dimColor: isPlaceholder, children: displayValue })
|
|
175
|
+
] });
|
|
176
|
+
}
|
|
98
177
|
export {
|
|
99
|
-
CommandPalette
|
|
178
|
+
CommandPalette,
|
|
179
|
+
TextInput
|
|
100
180
|
};
|