giggles 0.2.4 → 0.3.1

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.
@@ -0,0 +1,26 @@
1
+ import { Key } from 'ink';
2
+
3
+ type KeyHandler = (input: string, key: Key) => void;
4
+ type SpecialKey = 'up' | 'down' | 'left' | 'right' | 'enter' | 'escape' | 'tab' | 'backspace' | 'pageup' | 'pagedown' | 'home' | 'end';
5
+ type KeyName = SpecialKey | (string & {});
6
+ type KeybindingDefinition = KeyHandler | {
7
+ action: KeyHandler;
8
+ name: string;
9
+ when?: 'focused' | 'mounted';
10
+ };
11
+ type Keybindings = Partial<Record<KeyName, KeybindingDefinition>>;
12
+ type KeybindingOptions = {
13
+ capture?: boolean;
14
+ onKeypress?: (input: string, key: Key) => void;
15
+ layer?: string;
16
+ };
17
+ type RegisteredKeybinding = {
18
+ nodeId: string;
19
+ key: string;
20
+ handler: KeyHandler;
21
+ name?: string;
22
+ when?: 'focused' | 'mounted';
23
+ layer?: string;
24
+ };
25
+
26
+ export type { Keybindings as K, RegisteredKeybinding as R, KeybindingOptions as a, KeyHandler as b };
@@ -0,0 +1,18 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React__default from 'react';
3
+ import { R as RegisteredKeybinding } from '../types-ClgDW3fy.js';
4
+ import 'ink';
5
+
6
+ type CommandPaletteRenderProps = {
7
+ query: string;
8
+ filtered: RegisteredKeybinding[];
9
+ selectedIndex: number;
10
+ onSelect: (cmd: RegisteredKeybinding) => void;
11
+ };
12
+ type CommandPaletteProps = {
13
+ onClose: () => void;
14
+ render?: (props: CommandPaletteRenderProps) => React__default.ReactNode;
15
+ };
16
+ declare function CommandPalette({ onClose, render }: CommandPaletteProps): react_jsx_runtime.JSX.Element;
17
+
18
+ export { CommandPalette, type CommandPaletteRenderProps };
@@ -0,0 +1,100 @@
1
+ import {
2
+ FocusTrap,
3
+ useFocus,
4
+ useKeybindingRegistry,
5
+ useKeybindings
6
+ } from "../chunk-4LED4GXQ.js";
7
+
8
+ // src/ui/CommandPalette.tsx
9
+ import { useState } from "react";
10
+ import { Box, Text } from "ink";
11
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
12
+ var EMPTY_KEY = {
13
+ upArrow: false,
14
+ downArrow: false,
15
+ leftArrow: false,
16
+ rightArrow: false,
17
+ pageDown: false,
18
+ pageUp: false,
19
+ home: false,
20
+ end: false,
21
+ return: false,
22
+ escape: false,
23
+ ctrl: false,
24
+ shift: false,
25
+ tab: false,
26
+ backspace: false,
27
+ delete: false,
28
+ meta: false,
29
+ super: false,
30
+ hyper: false,
31
+ capsLock: false,
32
+ numLock: false
33
+ };
34
+ function fuzzyMatch(name, query) {
35
+ if (!query) return true;
36
+ const lowerName = name.toLowerCase();
37
+ const lowerQuery = query.toLowerCase();
38
+ let qi = 0;
39
+ for (let i = 0; i < lowerName.length && qi < lowerQuery.length; i++) {
40
+ if (lowerName[i] === lowerQuery[qi]) qi++;
41
+ }
42
+ return qi === lowerQuery.length;
43
+ }
44
+ function Inner({ onClose, render }) {
45
+ const focus = useFocus();
46
+ const [query, setQuery] = useState("");
47
+ const [selectedIndex, setSelectedIndex] = useState(0);
48
+ const registry = useKeybindingRegistry();
49
+ const filtered = registry.all.filter((cmd) => fuzzyMatch(cmd.name, query));
50
+ const clampedIndex = Math.min(selectedIndex, Math.max(0, filtered.length - 1));
51
+ const onSelect = (cmd) => {
52
+ cmd.handler("", EMPTY_KEY);
53
+ onClose();
54
+ };
55
+ useKeybindings(
56
+ focus,
57
+ {
58
+ escape: onClose,
59
+ enter: () => {
60
+ const cmd = filtered[clampedIndex];
61
+ if (cmd) onSelect(cmd);
62
+ },
63
+ up: () => setSelectedIndex((i) => Math.max(0, i - 1)),
64
+ down: () => setSelectedIndex((i) => Math.max(0, Math.min(filtered.length - 1, i + 1))),
65
+ backspace: () => {
66
+ setQuery((q) => q.slice(0, -1));
67
+ setSelectedIndex(0);
68
+ }
69
+ },
70
+ {
71
+ capture: true,
72
+ onKeypress: (input, key) => {
73
+ if (input.length === 1 && !key.ctrl) {
74
+ setQuery((q) => q + input);
75
+ setSelectedIndex(0);
76
+ }
77
+ }
78
+ }
79
+ );
80
+ if (render) {
81
+ return /* @__PURE__ */ jsx(Fragment, { children: render({ query, filtered, selectedIndex: clampedIndex, onSelect }) });
82
+ }
83
+ return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", borderStyle: "round", width: 40, children: [
84
+ /* @__PURE__ */ jsxs(Box, { paddingX: 1, children: [
85
+ /* @__PURE__ */ jsx(Text, { dimColor: true, children: "> " }),
86
+ /* @__PURE__ */ jsx(Text, { children: query }),
87
+ /* @__PURE__ */ jsx(Text, { inverse: true, children: " " })
88
+ ] }),
89
+ /* @__PURE__ */ jsx(Box, { flexDirection: "column", children: filtered.length === 0 ? /* @__PURE__ */ jsx(Box, { paddingX: 1, children: /* @__PURE__ */ jsx(Text, { dimColor: true, children: "No commands found" }) }) : filtered.map((cmd, i) => /* @__PURE__ */ jsxs(Box, { justifyContent: "space-between", paddingX: 1, children: [
90
+ /* @__PURE__ */ jsx(Text, { inverse: i === clampedIndex, children: cmd.name }),
91
+ /* @__PURE__ */ jsx(Text, { dimColor: true, children: cmd.key })
92
+ ] }, `${cmd.nodeId}-${cmd.key}`)) })
93
+ ] });
94
+ }
95
+ function CommandPalette({ onClose, render }) {
96
+ return /* @__PURE__ */ jsx(FocusTrap, { children: /* @__PURE__ */ jsx(Inner, { onClose, render }) });
97
+ }
98
+ export {
99
+ CommandPalette
100
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "giggles",
3
- "version": "0.2.4",
3
+ "version": "0.3.1",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -13,6 +13,14 @@
13
13
  ".": {
14
14
  "import": "./dist/index.js",
15
15
  "types": "./dist/index.d.ts"
16
+ },
17
+ "./terminal": {
18
+ "import": "./dist/terminal/index.js",
19
+ "types": "./dist/terminal/index.d.ts"
20
+ },
21
+ "./ui": {
22
+ "import": "./dist/ui/index.js",
23
+ "types": "./dist/ui/index.d.ts"
16
24
  }
17
25
  },
18
26
  "keywords": [
@@ -54,5 +62,8 @@
54
62
  "tsx": "^4.21.0",
55
63
  "typescript": "^5.0.3",
56
64
  "typescript-eslint": "^8.0.0"
65
+ },
66
+ "dependencies": {
67
+ "execa": "^9.6.1"
57
68
  }
58
69
  }