UNPKG

askeroo

Version:

A modern CLI prompt library with flow control, history navigation, and conditional prompts

64 lines 2.46 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { Text, Box } from "ink"; import { createPrompt } from "../../core/registry.js"; /** * Create a group of prompts * * Groups are container plugins that organize prompts into logical sections. * They support different flow types and can be nested. * * @example Progressive group (default) * ```typescript * const answers = await group( * async () => { * const name = await text({ label: "Name" }); * const email = await text({ label: "Email" }); * return { name, email }; * }, * { label: "User Info" } * ); * ``` * * @example Static group with arrow navigation * ```typescript * const answers = await group( * async () => { * const name = await text({ label: "Name" }); * const email = await text({ label: "Email" }); * return { name, email }; * }, * { label: "User Info", flow: "static", enableArrowNavigation: true } * ); * ``` * * @example Group that hides after completion * ```typescript * const answers = await group( * async () => { * const name = await text({ label: "Name" }); * const email = await text({ label: "Email" }); * return { name, email }; * }, * { label: "User Info", hideOnCompletion: true } * ); * ``` */ export const group = ((plugin) => (body, opts) => plugin({ ...opts, body }))(createPrompt({ type: "group", autoSubmit: true, isContainer: true, component: ({ node, options, events }) => { // Hide entirely if hideOnCompletion is true and group is completed if (options.hideOnCompletion && node.state === "completed") { return null; } return (_jsxs(Box, { flexDirection: "column", children: [options.label && (_jsx(Box, { children: _jsx(Text, { color: "yellow", children: options.label }) })), node.flow === "phased" && node.state === "completed" && (_jsx(Box, { marginLeft: options.label ? 3 : 0, children: _jsx(Text, { color: "blue", children: "Completed" }) })), node.children && !(node.flow === "phased" && node.state === "completed") && (_jsx(Box, { flexDirection: "column", marginLeft: options.label ? 3 : 0, gap: 1, children: node.children }))] })); }, execute: async (runtime, opts, body) => await runtime.executeGroupBody(opts, body), transform: (opts, context) => ({ ...opts, groupName: context.currentGroup, }), })); //# sourceMappingURL=index.js.map