@tooee/renderers 0.8.0 → 0.9.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 (55) hide show
  1. package/dist/chooser/choose-filter.d.ts +13 -0
  2. package/dist/chooser/choose-filter.d.ts.map +1 -0
  3. package/dist/chooser/choose-filter.js +22 -0
  4. package/dist/chooser/choose-filter.js.map +1 -0
  5. package/dist/chooser/choose-highlighted-text.d.ts +9 -0
  6. package/dist/chooser/choose-highlighted-text.d.ts.map +1 -0
  7. package/dist/chooser/choose-highlighted-text.js +32 -0
  8. package/dist/chooser/choose-highlighted-text.js.map +1 -0
  9. package/dist/chooser/choose-list.d.ts +29 -0
  10. package/dist/chooser/choose-list.d.ts.map +1 -0
  11. package/dist/chooser/choose-list.js +66 -0
  12. package/dist/chooser/choose-list.js.map +1 -0
  13. package/dist/chooser/choose-store.d.ts +58 -0
  14. package/dist/chooser/choose-store.d.ts.map +1 -0
  15. package/dist/chooser/choose-store.js +102 -0
  16. package/dist/chooser/choose-store.js.map +1 -0
  17. package/dist/chooser/chooser.d.ts +18 -0
  18. package/dist/chooser/chooser.d.ts.map +1 -0
  19. package/dist/chooser/chooser.js +25 -0
  20. package/dist/chooser/chooser.js.map +1 -0
  21. package/dist/chooser/fuzzy.d.ts +9 -0
  22. package/dist/chooser/fuzzy.d.ts.map +1 -0
  23. package/dist/chooser/fuzzy.js +5 -0
  24. package/dist/chooser/fuzzy.js.map +1 -0
  25. package/dist/chooser/source.d.ts +5 -0
  26. package/dist/chooser/source.d.ts.map +1 -0
  27. package/dist/chooser/source.js +26 -0
  28. package/dist/chooser/source.js.map +1 -0
  29. package/dist/chooser/types.d.ts +22 -0
  30. package/dist/chooser/types.d.ts.map +1 -0
  31. package/dist/chooser/types.js +2 -0
  32. package/dist/chooser/types.js.map +1 -0
  33. package/dist/chooser/use-choose.d.ts +84 -0
  34. package/dist/chooser/use-choose.d.ts.map +1 -0
  35. package/dist/chooser/use-choose.js +382 -0
  36. package/dist/chooser/use-choose.js.map +1 -0
  37. package/dist/command-palette.d.ts.map +1 -1
  38. package/dist/command-palette.js +14 -68
  39. package/dist/command-palette.js.map +1 -1
  40. package/dist/index.d.ts +16 -0
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +8 -0
  43. package/dist/index.js.map +1 -1
  44. package/package.json +8 -6
  45. package/src/chooser/choose-filter.tsx +66 -0
  46. package/src/chooser/choose-highlighted-text.tsx +49 -0
  47. package/src/chooser/choose-list.tsx +159 -0
  48. package/src/chooser/choose-store.ts +147 -0
  49. package/src/chooser/chooser.tsx +80 -0
  50. package/src/chooser/fuzzy.ts +13 -0
  51. package/src/chooser/source.ts +36 -0
  52. package/src/chooser/types.ts +28 -0
  53. package/src/chooser/use-choose.ts +540 -0
  54. package/src/command-palette.tsx +45 -148
  55. package/src/index.ts +39 -0
@@ -0,0 +1,13 @@
1
+ import type { ReactNode } from "react";
2
+ import type { UseChooseResult } from "./use-choose.js";
3
+ export interface ChooseFilterProps {
4
+ choose: UseChooseResult;
5
+ prompt?: ReactNode;
6
+ placeholder?: string;
7
+ right?: ReactNode;
8
+ onClose?: () => void;
9
+ count?: "matches" | "ratio" | false;
10
+ }
11
+ /** Controlled filter row shared by fullscreen and overlay chooser assemblies. */
12
+ export declare const ChooseFilter: ({ choose, prompt, placeholder, right, onClose, count, }: ChooseFilterProps) => ReactNode;
13
+ //# sourceMappingURL=choose-filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"choose-filter.d.ts","sourceRoot":"","sources":["../../src/chooser/choose-filter.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,eAAe,CAAC;IACxB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,KAAK,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,KAAK,CAAC;CACrC;AAED,iFAAiF;AACjF,eAAO,MAAM,YAAY,4DAOtB,iBAAiB,KAAG,SA2CtB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "@opentui/react/jsx-runtime";
2
+ import { CloseButton, decodeReactContent } from "@tooee/layout";
3
+ import { useTheme } from "@tooee/themes";
4
+ /** Controlled filter row shared by fullscreen and overlay chooser assemblies. */
5
+ export const ChooseFilter = function ChooseFilter({ choose, prompt = "> ", placeholder = "Filter...", right, onClose, count = "ratio", }) {
6
+ const { theme } = useTheme();
7
+ const { state, view } = choose;
8
+ const handleFilterInput = view.onFilterInput;
9
+ const handleFilterKeyDown = view.onFilterKeyDown;
10
+ const promptContent = decodeReactContent(prompt);
11
+ let renderedPrompt = null;
12
+ if (promptContent.kind === "string") {
13
+ renderedPrompt = _jsx("text", { content: promptContent.value, fg: theme.accent });
14
+ }
15
+ else if (promptContent.kind === "node") {
16
+ renderedPrompt = promptContent.value;
17
+ }
18
+ return (_jsxs("box", { flexDirection: "row", height: 1, style: { paddingLeft: 1, paddingRight: 1 }, children: [renderedPrompt, _jsx("input", { ref: view.filterRef, focused: view.filterFocused, value: state.filterQuery, placeholder: placeholder, onInput: handleFilterInput, onKeyDown: handleFilterKeyDown, backgroundColor: "transparent", textColor: theme.text, placeholderColor: theme.textMuted, cursorColor: theme.primary, style: { flexGrow: 1 } }), count !== false && (_jsx("text", { content: count === "matches"
19
+ ? ` ${state.matches.length}`
20
+ : ` ${state.matches.length}/${state.items.length}`, fg: theme.textMuted })), right, onClose && _jsx(CloseButton, { onClose: onClose })] }));
21
+ };
22
+ //# sourceMappingURL=choose-filter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"choose-filter.js","sourceRo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iBAAiB,EAC1B,SAAS,EAAE,mBAAmB,EAC9B,eAAe,EAAC,aAAa,EAC7B,SAAS,EAAE,KAAK,CAAC,IAAI,EACrB,gBAAgB,EAAE,KAAK,CAAC,SAAS,EACjC,WAAW,EAAE,KAAK,CAAC,OAAO,EAC1B,KAAK,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,GACtB,EACD,KAAK,KAAK,KAAK,IAAI,CAClB,eACE,OAAO,EACL,KAAK,KAAK,SAAS;oBACjB,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE;oBAC5B,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,EAEtD,EAAE,EAAE,KAAK,CAAC,SAAS,GACnB,CACH,EACA,KAAK,EACL,OAAO,IAAI,KAAC,WAAW,IAAC,OAAO,EAAE,OAAO,GAAI,IACzC,CACP,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { ReactNode } from "react";
2
+ export interface ChooseHighlightedTextProps {
3
+ text: string;
4
+ positions: number[];
5
+ highlightColor: string;
6
+ }
7
+ /** Render fuzzy-match characters with one shared segmentation implementation. */
8
+ export declare const ChooseHighlightedText: ({ text, positions, highlightColor, }: ChooseHighlightedTextProps) => ReactNode;
9
+ //# sourceMappingURL=choose-highlighted-text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"choose-highlighted-text.d.ts","sourceRoot":"","sources":["../../src/chooser/choose-highlighted-text.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,iFAAiF;AACjF,eAAO,MAAM,qBAAqB,yCAI/B,0BAA0B,KAAG,SAkC/B,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { jsx as _jsx } from "@opentui/react/jsx-runtime";
2
+ import { Fragment } from "react";
3
+ /** Render fuzzy-match characters with one shared segmentation implementation. */
4
+ export const ChooseHighlightedText = function ChooseHighlightedText({ text, positions, highlightColor, }) {
5
+ if (positions.length === 0) {
6
+ return text;
7
+ }
8
+ const positionSet = new Set(positions);
9
+ const parts = [];
10
+ let current = "";
11
+ let currentHighlighted = false;
12
+ for (let index = 0; index < text.length; index += 1) {
13
+ const highlighted = positionSet.has(index);
14
+ if (index === 0) {
15
+ current = text[index];
16
+ currentHighlighted = highlighted;
17
+ }
18
+ else if (highlighted === currentHighlighted) {
19
+ current += text[index];
20
+ }
21
+ else {
22
+ parts.push({ highlighted: currentHighlighted, text: current });
23
+ current = text[index];
24
+ currentHighlighted = highlighted;
25
+ }
26
+ }
27
+ if (current) {
28
+ parts.push({ highlighted: currentHighlighted, text: current });
29
+ }
30
+ return parts.map((part, index) => (_jsx(Fragment, { children: part.highlighted ? _jsx("span", { fg: highlightColor, children: part.text }) : part.text }, index)));
31
+ };
32
+ //# sourceMappingURL=choose-highlighted-text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"choose-highlighted-text.js","sourceRoot":"","sources":["../../src/chooser/choose-highlighted-text.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AASjC,iFAAiF;AACjF,MAAM,CAAC,MAAM,qBAAqB,GAAG,SAAS,qBAAqB,CAAC,EAClE,IAAI,EACJ,SAAS,EACT,cAAc,GACa;IAC3B,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC;IACvC,MAAM,KAAK,GAA6C,EAAE,CAAC;IAC3D,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,IAAI,kBAAkB,GAAG,KAAK,CAAC;IAE/B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACpD,MAAM,WAAW,GAAG,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC3C,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YAChB,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;YACtB,kBAAkB,GAAG,WAAW,CAAC;QACnC,CAAC;aAAM,IAAI,WAAW,KAAK,kBAAkB,EAAE,CAAC;YAC9C,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,kBAAkB,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;YAC/D,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;YACtB,kBAAkB,GAAG,WAAW,CAAC;QACnC,CAAC;IACH,CAAC;IACD,IAAI,OAAO,EAAE,CAAC;QACZ,KAAK,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,kBAAkB,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IACjE,CAAC;IAED,OAAO,KAAK,CAAC,GAAG,CACd,CAAC,IAAI,EAAE,KAAK,EAAa,EAAE,CAAC,CAC1B,KAAC,QAAQ,cACN,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,eAAM,EAAE,EAAE,cAAc,YAAG,IAAI,CAAC,IAAI,GAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,IAD/D,KAAK,CAET,CACZ,CACF,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { ReactNode } from "react";
2
+ import type { FuzzyMatch } from "./fuzzy.js";
3
+ import type { ChooseItem } from "./types.js";
4
+ import type { UseChooseResult } from "./use-choose.js";
5
+ export interface ChooseItemRenderContext {
6
+ item: ChooseItem;
7
+ match: FuzzyMatch;
8
+ index: number;
9
+ originalIndex: number;
10
+ positions: number[];
11
+ isActive: boolean;
12
+ isSelected: boolean;
13
+ defaultContent: ReactNode;
14
+ }
15
+ export interface ChooseListProps {
16
+ choose: UseChooseResult;
17
+ /** Fullscreen defaults to activate; picker overlays default to submit. */
18
+ rowClick?: "activate" | "submit" | "none";
19
+ renderItem?: (context: ChooseItemRenderContext) => ReactNode;
20
+ loadingContent?: ReactNode;
21
+ errorContent?: (error: string) => ReactNode;
22
+ emptyContent?: ReactNode;
23
+ rowHeight?: number;
24
+ /** Mouse guard for visible rows covered by another surface. */
25
+ suspended?: boolean;
26
+ }
27
+ /** Scrollable chooser rows plus loading/error/empty presentation. */
28
+ export declare const ChooseList: ({ choose, rowClick, renderItem, loadingContent, errorContent, emptyContent, rowHeight, suspended, }: ChooseListProps) => ReactNode;
29
+ //# sourceMappingURL=choose-list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"choose-list.d.ts","sourceRoot":"","sources":["../../src/chooser/choose-list.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,UAAU,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,cAAc,EAAE,SAAS,CAAC;CAC3B;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,eAAe,CAAC;IACxB,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,UAAU,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC1C,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,uBAAuB,KAAK,SAAS,CAAC;IAC7D,cAAc,CAAC,EAAE,SAAS,CAAC;IAC3B,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC;IAC5C,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AA2BD,qEAAqE;AACrE,eAAO,MAAM,UAAU,wGASpB,eAAe,KAAG,SAyFpB,CAAC"}
@@ -0,0 +1,66 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "@opentui/react/jsx-runtime";
2
+ import { useEffect, useRef } from "react";
3
+ import { decodeReactContent } from "@tooee/layout";
4
+ import { useTheme } from "@tooee/themes";
5
+ import { ChooseHighlightedText } from "./choose-highlighted-text.js";
6
+ const ThemedLine = function ThemedLine({ content, color, }) {
7
+ const decoded = decodeReactContent(content);
8
+ let rendered = null;
9
+ if (decoded.kind === "string") {
10
+ rendered = _jsx("text", { content: decoded.value, fg: color });
11
+ }
12
+ else if (decoded.kind === "node") {
13
+ rendered = decoded.value;
14
+ }
15
+ return (_jsx("box", { height: 1, style: { paddingLeft: 2 }, children: rendered }));
16
+ };
17
+ const defaultErrorContent = function defaultErrorContent(error) {
18
+ return `Error: ${error}`;
19
+ };
20
+ /** Scrollable chooser rows plus loading/error/empty presentation. */
21
+ export const ChooseList = function ChooseList({ choose, rowClick = "activate", renderItem, loadingContent = "Loading...", errorContent = defaultErrorContent, emptyContent, rowHeight, suspended, }) {
22
+ const { theme } = useTheme();
23
+ const scrollRef = useRef(null);
24
+ const { state, controller } = choose;
25
+ const interactionSuspended = choose.view.suspended || (suspended ?? false);
26
+ useEffect(() => {
27
+ const activeMatch = state.matches[state.activeIndex];
28
+ if (scrollRef.current && activeMatch !== undefined) {
29
+ scrollRef.current.scrollChildIntoView(`choose-item-${activeMatch.originalIndex}`);
30
+ }
31
+ }, [state.activeIndex, state.matches]);
32
+ return (_jsxs("scrollbox", { ref: scrollRef, style: { flexGrow: 1 }, focused: false, children: [state.loading && _jsx(ThemedLine, { content: loadingContent, color: theme.textMuted }), !state.loading && state.error !== null && state.error !== "" && (_jsx(ThemedLine, { content: errorContent(state.error), color: theme.error })), !state.loading &&
33
+ (state.error?.length ?? 0) === 0 &&
34
+ state.matches.length === 0 &&
35
+ emptyContent !== null &&
36
+ emptyContent !== undefined && _jsx(ThemedLine, { content: emptyContent, color: theme.textMuted }), state.matches.map((match, index) => {
37
+ const isActive = index === state.activeIndex;
38
+ const isSelected = state.selectedOriginalIndices.has(match.originalIndex);
39
+ const defaultContent = (_jsxs("text", { fg: isActive ? theme.primary : theme.text, style: { flexGrow: 1 }, children: [state.multi && (_jsx("span", { fg: isSelected ? theme.accent : theme.textMuted, children: isSelected ? "✓ " : " " })), (match.item.icon?.length ?? 0) > 0 && (_jsx("span", { fg: theme.textMuted, children: `${match.item.icon} ` })), _jsx(ChooseHighlightedText, { text: match.item.text, positions: match.positions, highlightColor: theme.warning }), (match.item.description?.length ?? 0) > 0 && (_jsx("span", { fg: theme.textMuted, children: ` ${match.item.description}` }))] }));
40
+ const context = {
41
+ defaultContent,
42
+ index,
43
+ isActive,
44
+ isSelected,
45
+ item: match.item,
46
+ match,
47
+ originalIndex: match.originalIndex,
48
+ positions: match.positions,
49
+ };
50
+ return (_jsx("box", { id: `choose-item-${match.originalIndex}`, flexDirection: "row", height: rowHeight, backgroundColor: isActive ? theme.backgroundElement : undefined, style: { paddingLeft: 1, paddingRight: 1 }, onMouseDown: (event) => {
51
+ if (interactionSuspended || event.button !== 0 || rowClick === "none") {
52
+ return;
53
+ }
54
+ if (rowClick === "submit") {
55
+ event.preventDefault();
56
+ event.stopPropagation();
57
+ controller.setActiveIndex(index);
58
+ controller.submit();
59
+ }
60
+ else {
61
+ controller.setActiveIndex(index);
62
+ }
63
+ }, children: renderItem ? renderItem(context) : defaultContent }, match.originalIndex));
64
+ })] }));
65
+ };
66
+ //# sourceMappingURL=choose-list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"choose-list.js","sourceRoot":"","sources":["../../src/chooser/choose-list.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AA6BrE,MAAM,UAAU,GAAG,SAAS,UAAU,CAAC,EACrC,OAAO,EACP,KAAK,GAIN;IACC,MAAM,OAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC5C,IAAI,QAAQ,GAAc,IAAI,CAAC;IAC/B,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9B,QAAQ,GAAG,eAAM,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,EAAE,KAAK,GAAI,CAAC;IACzD,CAAC;SAAM,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QACnC,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC;IAC3B,CAAC;IACD,OAAO,CACL,cAAK,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,YACtC,QAAQ,GACL,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,mBAAmB,GAAG,SAAS,mBAAmB,CAAC,KAAa;IACpE,OAAO,UAAU,KAAK,EAAE,CAAC;AAC3B,CAAC,CAAC;AAEF,qEAAqE;AACrE,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,UAAU,CAAC,EAC5C,MAAM,EACN,QAAQ,GAAG,U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AAK,CAAC,aAAa,CAqBpB,CACP,CAAC;YACJ,CAAC,CAAC,IACQ,CACb,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,58 @@
1
+ import type { FuzzyMatch } from "./fuzzy.js";
2
+ import type { ChooseItem } from "./types.js";
3
+ export interface ChooseStoreContext {
4
+ items: ChooseItem[];
5
+ matches: FuzzyMatch[];
6
+ filterQuery: string;
7
+ activeIndex: number;
8
+ selectedOriginalIndices: ReadonlySet<number>;
9
+ loading: boolean;
10
+ error: string | null;
11
+ requestId: number;
12
+ reloadRevision: number;
13
+ }
14
+ interface ChooseStoreEventDefinitions {
15
+ filterChanged: {
16
+ query: string;
17
+ };
18
+ activeIndexSet: {
19
+ index: number;
20
+ };
21
+ moved: {
22
+ delta: number;
23
+ };
24
+ activeToggled: Record<never, never>;
25
+ requestStarted: Record<never, never>;
26
+ loadingStarted: {
27
+ requestId: number;
28
+ };
29
+ loadSucceeded: {
30
+ requestId: number;
31
+ items: ChooseItem[];
32
+ };
33
+ loadFailed: {
34
+ requestId: number;
35
+ error: string;
36
+ };
37
+ reloadRequested: Record<never, never>;
38
+ }
39
+ export type ChooseStoreEvents = {
40
+ [EventName in keyof ChooseStoreEventDefinitions]: ChooseStoreEventDefinitions[EventName];
41
+ };
42
+ export declare const createChooseStore: (options: {
43
+ items?: ChooseItem[];
44
+ initialFilter?: string;
45
+ initialActiveIndex?: number;
46
+ loading?: boolean;
47
+ }) => import("@xstate/store").Store<ChooseStoreContext, ChooseStoreEvents, never>;
48
+ export type ChooseStore = ReturnType<typeof createChooseStore>;
49
+ export declare const selectItems: (ctx: ChooseStoreContext) => ChooseItem[];
50
+ export declare const selectMatches: (ctx: ChooseStoreContext) => FuzzyMatch[];
51
+ export declare const selectFilterQuery: (ctx: ChooseStoreContext) => string;
52
+ export declare const selectActiveIndex: (ctx: ChooseStoreContext) => number;
53
+ export declare const selectSelectedOriginalIndices: (ctx: ChooseStoreContext) => ReadonlySet<number>;
54
+ export declare const selectLoading: (ctx: ChooseStoreContext) => boolean;
55
+ export declare const selectError: (ctx: ChooseStoreContext) => string | null;
56
+ export declare const selectReloadRevision: (ctx: ChooseStoreContext) => number;
57
+ export {};
58
+ //# sourceMappingURL=choose-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"choose-store.d.ts","sourceRoot":"","sources":["../../src/chooser/choose-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,uBAAuB,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC7C,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,UAAU,2BAA2B;IACnC,aAAa,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACjC,cAAc,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAClC,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACpC,cAAc,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACrC,cAAc,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IACtC,aAAa,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,UAAU,EAAE,CAAA;KAAE,CAAC;IAC1D,UAAU,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACjD,eAAe,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;CACvC;AAED,MAAM,MAAM,iBAAiB,GAAG;KAC7B,SAAS,IAAI,MAAM,2BAA2B,GAAG,2BAA2B,CAAC,SAAS,CAAC;CACzF,CAAC;AAmBF,eAAO,MAAM,iBAAiB,YAAuC;IACnE,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,gFA+EA,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE/D,eAAO,MAAM,WAAW,QAAS,kBAAkB,KAAG,UAAU,EAAe,CAAC;AAChF,eAAO,MAAM,aAAa,QAAS,kBAAkB,KAAG,UAAU,EAAiB,CAAC;AACpF,eAAO,MAAM,iBAAiB,QAAS,kBAAkB,KAAG,MAAyB,CAAC;AACtF,eAAO,MAAM,iBAAiB,QAAS,kBAAkB,KAAG,MAAyB,CAAC;AACtF,eAAO,MAAM,6BAA6B,QAAS,kBAAkB,KAAG,WAAW,CAAC,MAAM,CAC7D,CAAC;AAC9B,eAAO,MAAM,aAAa,QAAS,kBAAkB,KAAG,OAAsB,CAAC;AAC/E,eAAO,MAAM,WAAW,QAAS,kBAAkB,KAAG,MAAM,GAAG,IAAiB,CAAC;AACjF,eAAO,MAAM,oBAAoB,QAAS,kBAAkB,KAAG,MAA4B,CAAC"}
@@ -0,0 +1,102 @@
1
+ import { createStore } from "@xstate/store";
2
+ import { fuzzyFilter } from "./fuzzy.js";
3
+ const replaceItems = function replaceItems(ctx, items) {
4
+ return {
5
+ ...ctx,
6
+ activeIndex: 0,
7
+ items,
8
+ matches: fuzzyFilter(items, ctx.filterQuery),
9
+ selectedOriginalIndices: new Set(),
10
+ };
11
+ };
12
+ const clampActiveIndex = function clampActiveIndex(index, matchCount) {
13
+ return Math.min(Math.max(0, matchCount - 1), Math.max(0, index));
14
+ };
15
+ export const createChooseStore = function createChooseStore(options) {
16
+ const items = options.items ?? [];
17
+ const filterQuery = options.initialFilter ?? "";
18
+ return createStore({
19
+ context: {
20
+ activeIndex: clampActiveIndex(options.initialActiveIndex ?? 0, items.length),
21
+ error: null,
22
+ filterQuery,
23
+ items,
24
+ loading: options.loading ?? false,
25
+ matches: fuzzyFilter(items, filterQuery),
26
+ reloadRevision: 0,
27
+ requestId: 0,
28
+ selectedOriginalIndices: new Set(),
29
+ },
30
+ on: {
31
+ activeIndexSet: (ctx, event) => {
32
+ const activeIndex = clampActiveIndex(event.index, ctx.matches.length);
33
+ return activeIndex === ctx.activeIndex ? ctx : { ...ctx, activeIndex };
34
+ },
35
+ activeToggled: (ctx) => {
36
+ const originalIndex = ctx.matches[ctx.activeIndex]?.originalIndex;
37
+ if (originalIndex === undefined) {
38
+ return ctx;
39
+ }
40
+ const selectedOriginalIndices = new Set(ctx.selectedOriginalIndices);
41
+ if (selectedOriginalIndices.has(originalIndex)) {
42
+ selectedOriginalIndices.delete(originalIndex);
43
+ }
44
+ else {
45
+ selectedOriginalIndices.add(originalIndex);
46
+ }
47
+ return { ...ctx, selectedOriginalIndices };
48
+ },
49
+ filterChanged: (ctx, event) => {
50
+ if (event.query === ctx.filterQuery) {
51
+ return ctx;
52
+ }
53
+ return {
54
+ ...ctx,
55
+ activeIndex: 0,
56
+ filterQuery: event.query,
57
+ matches: fuzzyFilter(ctx.items, event.query),
58
+ };
59
+ },
60
+ loadFailed: (ctx, event) => {
61
+ if (event.requestId !== ctx.requestId) {
62
+ return ctx;
63
+ }
64
+ return {
65
+ ...replaceItems(ctx, []),
66
+ error: event.error,
67
+ loading: false,
68
+ };
69
+ },
70
+ loadSucceeded: (ctx, event) => {
71
+ if (event.requestId !== ctx.requestId) {
72
+ return ctx;
73
+ }
74
+ return {
75
+ ...replaceItems(ctx, event.items),
76
+ error: null,
77
+ loading: false,
78
+ };
79
+ },
80
+ loadingStarted: (ctx, event) => event.requestId === ctx.requestId && !ctx.loading ? { ...ctx, loading: true } : ctx,
81
+ moved: (ctx, event) => {
82
+ const activeIndex = clampActiveIndex(ctx.activeIndex + event.delta, ctx.matches.length);
83
+ return activeIndex === ctx.activeIndex ? ctx : { ...ctx, activeIndex };
84
+ },
85
+ reloadRequested: (ctx) => ({ ...ctx, reloadRevision: ctx.reloadRevision + 1 }),
86
+ requestStarted: (ctx) => ({
87
+ ...ctx,
88
+ error: null,
89
+ requestId: ctx.requestId + 1,
90
+ }),
91
+ },
92
+ });
93
+ };
94
+ export const selectItems = (ctx) => ctx.items;
95
+ export const selectMatches = (ctx) => ctx.matches;
96
+ export const selectFilterQuery = (ctx) => ctx.filterQuery;
97
+ export const selectActiveIndex = (ctx) => ctx.activeIndex;
98
+ export const selectSelectedOriginalIndices = (ctx) => ctx.selectedOriginalIndices;
99
+ export const selectLoading = (ctx) => ctx.loading;
100
+ export const selectError = (ctx) => ctx.error;
101
+ export const selectReloadRevision = (ctx) => ctx.reloadRevision;
102
+ //# sourceMappingURL=choose-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"choose-store.js","sourceRoot":"","sources":["../../src/chooser/choose-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAgCzC,MAAM,YAAY,GAAG,SAAS,YAAY,CACxC,GAAuB,EACvB,KAAmB;IAEnB,OAAO;QACL,GAAG,GAAG;QACN,WAAW,EAAE,CAAC;QACd,KAAK;QACL,OAAO,EAAE,WAAW,CAAC,KAAK,EAAE,GAAG,CAAC,WAAW,CAAC;QAC5C,uBAAuB,EAAE,IAAI,GAAG,EAAE;KACnC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG,SAAS,gBAAgB,CAA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AM,iBAAiB,GAAG,CAAC,GAAuB,EAAU,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC;AACtF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,GAAuB,EAAU,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC;AACtF,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,GAAuB,EAAuB,EAAE,CAC5F,GAAG,CAAC,uBAAuB,CAAC;AAC9B,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAuB,EAAW,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC;AAC/E,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAuB,EAAiB,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC;AACjF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAuB,EAAU,EAAE,CAAC,GAAG,CAAC,cAAc,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { ReactNode } from "react";
2
+ import type { ChooseListProps } from "./choose-list.js";
3
+ import type { ChooseItem } from "./types.js";
4
+ export interface ChooserProps {
5
+ items: ChooseItem[];
6
+ commandScope: string;
7
+ prompt: ReactNode;
8
+ placeholder?: string;
9
+ initialActiveIndex?: number;
10
+ onActiveChange?: (item: ChooseItem | undefined) => void;
11
+ onSelect: (item: ChooseItem) => void | Promise<void>;
12
+ onCancel: () => void;
13
+ renderItem?: ChooseListProps["renderItem"];
14
+ emptyContent?: ReactNode;
15
+ }
16
+ /** Shared modal filtered-list assembly used by shell chooser surfaces. */
17
+ export declare const Chooser: ({ items, commandScope, prompt, placeholder, initialActiveIndex, onActiveChange, onSelect, onCancel, renderItem, emptyContent, }: ChooserProps) => ReactNode;
18
+ //# sourceMappingURL=chooser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chooser.d.ts","sourceRoot":"","sources":["../../src/chooser/chooser.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAG7C,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,SAAS,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,KAAK,IAAI,CAAC;IACxD,QAAQ,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,UAAU,CAAC,EAAE,eAAe,CAAC,YAAY,CAAC,CAAC;IAC3C,YAAY,CAAC,EAAE,SAAS,CAAC;CAC1B;AAED,0EAA0E;AAC1E,eAAO,MAAM,OAAO,oIAWjB,YAAY,KAAG,SA8CjB,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "@opentui/react/jsx-runtime";
2
+ import { useTheme } from "@tooee/themes";
3
+ import { ChooseFilter } from "./choose-filter.js";
4
+ import { ChooseList } from "./choose-list.js";
5
+ import { useChoose } from "./use-choose.js";
6
+ /** Shared modal filtered-list assembly used by shell chooser surfaces. */
7
+ export const Chooser = function Chooser({ items, commandScope, prompt, placeholder, initialActiveIndex, onActiveChange, onSelect, onCancel, renderItem, emptyContent, }) {
8
+ const { theme } = useTheme();
9
+ const choose = useChoose({
10
+ commandScope,
11
+ escapeToCursor: false,
12
+ initialActiveIndex,
13
+ onActiveChange,
14
+ onCancel,
15
+ onSubmit: async ({ items: selectedItems }) => {
16
+ const [item] = selectedItems;
17
+ if (item !== undefined) {
18
+ await onSelect(item);
19
+ }
20
+ },
21
+ source: items,
22
+ });
23
+ return (_jsxs("box", { position: "absolute", left: "20%", right: "20%", top: 2, maxHeight: "60%", flexDirection: "column", backgroundColor: theme.backgroundPanel, border: true, borderColor: theme.border, children: [_jsx(ChooseFilter, { choose: choose, prompt: prompt, placeholder: placeholder, count: "matches", onClose: onCancel }), _jsx("box", { height: 1, width: "100%", backgroundColor: theme.border }), _jsx(ChooseList, { choose: choose, rowClick: "submit", rowHeight: 1, renderItem: renderItem, emptyContent: emptyContent })] }));
24
+ };
25
+ //# sourceMappingURL=chooser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chooser.js","sourceRoot":"","sources":["../../src/chooser/chooser.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAe5C,0EAA0E;AAC1E,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,OAAO,CAAC,EACtC,KAAK,EACL,YAAY,EACZ,MAAM,EACN,WAAW,EACX,kBAAkB,EAClB,cAAc,EACd,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,YAAY,GACC;IACb,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ,EAAE,CAAC;IAC7B,MAAM,MAAM,GAAG,SAAS,CAAC;QACvB,YAAY;QACZ,cAAc,EAAE,KAAK;QACrB,kBAAkB;QAClB,cAAc;QACd,QAAQ;QACR,QAAQ,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,EAAE,EAAE;YAC3C,MAAM,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC;YAC7B,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACvB,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC;YACvB,CAAC;QACH,CAAC;QACD,MAAM,EAAE,KAAK;KACd,CAAC,CAAC;IAEH,OAAO,CACL,eACE,QAAQ,EAAC,UAAU,EACnB,IAAI,EAAC,KAAK,EACV,KAAK,EAAC,KAAK,EACX,GAAG,EAAE,CAAC,EACN,SAAS,EAAC,KAAK,EACf,aAAa,EAAC,QAAQ,EACtB,eAAe,EAAE,KAAK,CAAC,eAAe,EACtC,MAAM,QACN,WAAW,EAAE,KAAK,CAAC,MAAM,aAEzB,KAAC,YAAY,IACX,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,KAAK,EAAC,SAAS,EACf,OAAO,EAAE,QAAQ,GACjB,EACF,cAAK,MAAM,EAAE,CAAC,EAAE,KAAK,EAAC,MAAM,EAAC,eAAe,EAAE,KAAK,CAAC,MAAM,GAAI,EAC9D,KAAC,UAAU,IACT,MAAM,EAAE,MAAM,EACd,QAAQ,EAAC,QAAQ,EACjB,SAAS,EAAE,CAAC,EACZ,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,YAAY,GAC1B,IACE,CACP,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { ChooseItem } from "./types.js";
2
+ export interface FuzzyMatch {
3
+ item: ChooseItem;
4
+ originalIndex: number;
5
+ score: number;
6
+ positions: number[];
7
+ }
8
+ export declare const fuzzyFilter: (items: ChooseItem[], query: string) => FuzzyMatch[];
9
+ //# sourceMappingURL=fuzzy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fuzzy.d.ts","sourceRoot":"","sources":["../../src/chooser/fuzzy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,UAAU,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,eAAO,MAAM,WAAW,UAA+B,UAAU,EAAE,SAAS,MAAM,KAAG,UAAU,EAE9F,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { rankBy } from "@tooee/fuzzy";
2
+ export const fuzzyFilter = function fuzzyFilter(items, query) {
3
+ return rankBy(items, query, (item) => item.text);
4
+ };
5
+ //# sourceMappingURL=fuzzy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fuzzy.js","sourceRoot":"","sources":["../../src/chooser/fuzzy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAUtC,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,WAAW,CAAC,KAAmB,EAAE,KAAa;IAChF,OAAO,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACnD,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { ChooseItem, ChooseSource } from "./types.js";
2
+ /** Resolve every public Choose source shape through one compatibility boundary. */
3
+ export declare const loadChooseSource: (source: ChooseSource) => ChooseItem[] | Promise<ChooseItem[]>;
4
+ export declare const chooseSourceError: (error: unknown) => string;
5
+ //# sourceMappingURL=source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/chooser/source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAyB,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAkBlF,mFAAmF;AACnF,eAAO,MAAM,gBAAgB,WACnB,YAAY,KACnB,UAAU,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CASrC,CAAC;AAGF,eAAO,MAAM,iBAAiB,UAAqC,OAAO,KAAG,MAE5E,CAAC"}
@@ -0,0 +1,26 @@
1
+ const decodeChooseSource = function decodeChooseSource(source) {
2
+ if (Array.isArray(source)) {
3
+ return { items: source, kind: "items" };
4
+ }
5
+ // oxlint-disable-next-line anti-slop/no-runtime-typeof -- public source boundary distinguishes the documented loader callback from a provider
6
+ if (typeof source === "function") {
7
+ return { kind: "loader", load: source };
8
+ }
9
+ return { kind: "provider", provider: source };
10
+ };
11
+ /** Resolve every public Choose source shape through one compatibility boundary. */
12
+ export const loadChooseSource = function loadChooseSource(source) {
13
+ const decoded = decodeChooseSource(source);
14
+ if (decoded.kind === "items") {
15
+ return decoded.items;
16
+ }
17
+ if (decoded.kind === "loader") {
18
+ return decoded.load();
19
+ }
20
+ return decoded.provider.load();
21
+ };
22
+ // oxlint-disable-next-line anti-slop/no-unknown-parameters -- caught loader failures enter here before conversion to display text
23
+ export const chooseSourceError = function chooseSourceError(error) {
24
+ return error instanceof Error ? error.message : String(error);
25
+ };
26
+ //# sourceMappingURL=source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.js","sourceRoot":"","sources":["../../src/chooser/source.ts"],"names":[],"mappings":"AAOA,MAAM,kBAAkB,GAAG,SAAS,kBAAkB,CAAC,MAAoB;IACzE,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAC1C,CAAC;IACD,8IAA8I;IAC9I,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;QACjC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAC1C,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAChD,CAAC,CAAC;AAEF,mFAAmF;AACnF,MAAM,CAAC,MAAM,gBAAgB,GAAG,SAAS,gBAAgB,CACvD,MAAoB;IAEpB,MAAM,OAAO,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC3C,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC7B,OAAO,OAAO,CAAC,KAAK,CAAC;IACvB,CAAC;IACD,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC;IACxB,CAAC;IACD,OAAO,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;AACjC,CAAC,CAAC;AAEF,kIAAkI;AAClI,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS,iBAAiB,CAAC,KAAc;IACxE,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC,CAAC"}
@@ -0,0 +1,22 @@
1
+ export interface ChooseItem {
2
+ text: string;
3
+ value?: string;
4
+ icon?: string;
5
+ description?: string;
6
+ }
7
+ export interface ChooseContentProvider {
8
+ load: () => Promise<ChooseItem[]> | ChooseItem[];
9
+ }
10
+ /** Any item source accepted by the shared chooser core. */
11
+ export type ChooseSource = ChooseItem[] | ChooseContentProvider | (() => ChooseItem[] | Promise<ChooseItem[]>);
12
+ export interface ChooseResult {
13
+ items: ChooseItem[];
14
+ }
15
+ export interface ChooseOptions {
16
+ multi?: boolean;
17
+ title?: string;
18
+ prompt?: string;
19
+ placeholder?: string;
20
+ emptyMessage?: string;
21
+ }
22
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/chooser/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC,GAAG,UAAU,EAAE,CAAC;CAClD;AAED,2DAA2D;AAC3D,MAAM,MAAM,YAAY,GACpB,UAAU,EAAE,GACZ,qBAAqB,GACrB,CAAC,MAAM,UAAU,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;AAEjD,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,UAAU,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/chooser/types.ts"],"names":[],"mappings":""}