inquirer-select-pro
Version:
An inquirer select that supports multiple selections and filtering.
1,581 lines (1,552 loc) • 55.3 kB
JavaScript
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
SelectStatus: () => SelectStatus,
Separator: () => import_core4.Separator,
select: () => select,
useSelect: () => useSelect
});
module.exports = __toCommonJS(src_exports);
var import_core3 = require("@inquirer/core");
// node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/vendor/ansi-styles/index.js
var ANSI_BACKGROUND_OFFSET = 10;
var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
var styles = {
modifier: {
reset: [0, 0],
// 21 isn't widely supported and 22 does the same thing
bold: [1, 22],
dim: [2, 22],
italic: [3, 23],
underline: [4, 24],
overline: [53, 55],
inverse: [7, 27],
hidden: [8, 28],
strikethrough: [9, 29]
},
color: {
black: [30, 39],
red: [31, 39],
green: [32, 39],
yellow: [33, 39],
blue: [34, 39],
magenta: [35, 39],
cyan: [36, 39],
white: [37, 39],
// Bright color
blackBright: [90, 39],
gray: [90, 39],
// Alias of `blackBright`
grey: [90, 39],
// Alias of `blackBright`
redBright: [91, 39],
greenBright: [92, 39],
yellowBright: [93, 39],
blueBright: [94, 39],
magentaBright: [95, 39],
cyanBright: [96, 39],
whiteBright: [97, 39]
},
bgColor: {
bgBlack: [40, 49],
bgRed: [41, 49],
bgGreen: [42, 49],
bgYellow: [43, 49],
bgBlue: [44, 49],
bgMagenta: [45, 49],
bgCyan: [46, 49],
bgWhite: [47, 49],
// Bright color
bgBlackBright: [100, 49],
bgGray: [100, 49],
// Alias of `bgBlackBright`
bgGrey: [100, 49],
// Alias of `bgBlackBright`
bgRedBright: [101, 49],
bgGreenBright: [102, 49],
bgYellowBright: [103, 49],
bgBlueBright: [104, 49],
bgMagentaBright: [105, 49],
bgCyanBright: [106, 49],
bgWhiteBright: [107, 49]
}
};
var modifierNames = Object.keys(styles.modifier);
var foregroundColorNames = Object.keys(styles.color);
var backgroundColorNames = Object.keys(styles.bgColor);
var colorNames = [...foregroundColorNames, ...backgroundColorNames];
function assembleStyles() {
const codes = /* @__PURE__ */ new Map();
for (const [groupName, group] of Object.entries(styles)) {
for (const [styleName, style] of Object.entries(group)) {
styles[styleName] = {
open: `\x1B[${style[0]}m`,
close: `\x1B[${style[1]}m`
};
group[styleName] = styles[styleName];
codes.set(style[0], style[1]);
}
Object.defineProperty(styles, groupName, {
value: group,
enumerable: false
});
}
Object.defineProperty(styles, "codes", {
value: codes,
enumerable: false
});
styles.color.close = "\x1B[39m";
styles.bgColor.close = "\x1B[49m";
styles.color.ansi = wrapAnsi16();
styles.color.ansi256 = wrapAnsi256();
styles.color.ansi16m = wrapAnsi16m();
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
Object.defineProperties(styles, {
rgbToAnsi256: {
value(red, green, blue) {
if (red === green && green === blue) {
if (red < 8) {
return 16;
}
if (red > 248) {
return 231;
}
return Math.round((red - 8) / 247 * 24) + 232;
}
return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
},
enumerable: false
},
hexToRgb: {
value(hex) {
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
if (!matches) {
return [0, 0, 0];
}
let [colorString] = matches;
if (colorString.length === 3) {
colorString = [...colorString].map((character) => character + character).join("");
}
const integer = Number.parseInt(colorString, 16);
return [
/* eslint-disable no-bitwise */
integer >> 16 & 255,
integer >> 8 & 255,
integer & 255
/* eslint-enable no-bitwise */
];
},
enumerable: false
},
hexToAnsi256: {
value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
enumerable: false
},
ansi256ToAnsi: {
value(code) {
if (code < 8) {
return 30 + code;
}
if (code < 16) {
return 90 + (code - 8);
}
let red;
let green;
let blue;
if (code >= 232) {
red = ((code - 232) * 10 + 8) / 255;
green = red;
blue = red;
} else {
code -= 16;
const remainder = code % 36;
red = Math.floor(code / 36) / 5;
green = Math.floor(remainder / 6) / 5;
blue = remainder % 6 / 5;
}
const value = Math.max(red, green, blue) * 2;
if (value === 0) {
return 30;
}
let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
if (value === 2) {
result += 60;
}
return result;
},
enumerable: false
},
rgbToAnsi: {
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
enumerable: false
},
hexToAnsi: {
value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
enumerable: false
}
});
return styles;
}
var ansiStyles = assembleStyles();
var ansi_styles_default = ansiStyles;
// node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/vendor/supports-color/index.js
var import_node_process = __toESM(require("process"), 1);
var import_node_os = __toESM(require("os"), 1);
var import_node_tty = __toESM(require("tty"), 1);
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : import_node_process.default.argv) {
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
const position = argv.indexOf(prefix + flag);
const terminatorPosition = argv.indexOf("--");
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
}
var { env } = import_node_process.default;
var flagForceColor;
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
flagForceColor = 0;
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
flagForceColor = 1;
}
function envForceColor() {
if ("FORCE_COLOR" in env) {
if (env.FORCE_COLOR === "true") {
return 1;
}
if (env.FORCE_COLOR === "false") {
return 0;
}
return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
}
}
function translateLevel(level) {
if (level === 0) {
return false;
}
return {
level,
hasBasic: true,
has256: level >= 2,
has16m: level >= 3
};
}
function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
const noFlagForceColor = envForceColor();
if (noFlagForceColor !== void 0) {
flagForceColor = noFlagForceColor;
}
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
if (forceColor === 0) {
return 0;
}
if (sniffFlags) {
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
return 3;
}
if (hasFlag("color=256")) {
return 2;
}
}
if ("TF_BUILD" in env && "AGENT_NAME" in env) {
return 1;
}
if (haveStream && !streamIsTTY && forceColor === void 0) {
return 0;
}
const min = forceColor || 0;
if (env.TERM === "dumb") {
return min;
}
if (import_node_process.default.platform === "win32") {
const osRelease = import_node_os.default.release().split(".");
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
return Number(osRelease[2]) >= 14931 ? 3 : 2;
}
return 1;
}
if ("CI" in env) {
if ("GITHUB_ACTIONS" in env || "GITEA_ACTIONS" in env) {
return 3;
}
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
return 1;
}
return min;
}
if ("TEAMCITY_VERSION" in env) {
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
}
if (env.COLORTERM === "truecolor") {
return 3;
}
if (env.TERM === "xterm-kitty") {
return 3;
}
if ("TERM_PROGRAM" in env) {
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
switch (env.TERM_PROGRAM) {
case "iTerm.app": {
return version >= 3 ? 3 : 2;
}
case "Apple_Terminal": {
return 2;
}
}
}
if (/-256(color)?$/i.test(env.TERM)) {
return 2;
}
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
return 1;
}
if ("COLORTERM" in env) {
return 1;
}
return min;
}
function createSupportsColor(stream, options = {}) {
const level = _supportsColor(stream, {
streamIsTTY: stream && stream.isTTY,
...options
});
return translateLevel(level);
}
var supportsColor = {
stdout: createSupportsColor({ isTTY: import_node_tty.default.isatty(1) }),
stderr: createSupportsColor({ isTTY: import_node_tty.default.isatty(2) })
};
var supports_color_default = supportsColor;
// node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/utilities.js
function stringReplaceAll(string, substring, replacer) {
let index = string.indexOf(substring);
if (index === -1) {
return string;
}
const substringLength = substring.length;
let endIndex = 0;
let returnValue = "";
do {
returnValue += string.slice(endIndex, index) + substring + replacer;
endIndex = index + substringLength;
index = string.indexOf(substring, endIndex);
} while (index !== -1);
returnValue += string.slice(endIndex);
return returnValue;
}
function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
let endIndex = 0;
let returnValue = "";
do {
const gotCR = string[index - 1] === "\r";
returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
endIndex = index + 1;
index = string.indexOf("\n", endIndex);
} while (index !== -1);
returnValue += string.slice(endIndex);
return returnValue;
}
// node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/index.js
var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
var GENERATOR = Symbol("GENERATOR");
var STYLER = Symbol("STYLER");
var IS_EMPTY = Symbol("IS_EMPTY");
var levelMapping = [
"ansi",
"ansi",
"ansi256",
"ansi16m"
];
var styles2 = /* @__PURE__ */ Object.create(null);
var applyOptions = (object, options = {}) => {
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
throw new Error("The `level` option should be an integer from 0 to 3");
}
const colorLevel = stdoutColor ? stdoutColor.level : 0;
object.level = options.level === void 0 ? colorLevel : options.level;
};
var chalkFactory = (options) => {
const chalk2 = (...strings) => strings.join(" ");
applyOptions(chalk2, options);
Object.setPrototypeOf(chalk2, createChalk.prototype);
return chalk2;
};
function createChalk(options) {
return chalkFactory(options);
}
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
for (const [styleName, style] of Object.entries(ansi_styles_default)) {
styles2[styleName] = {
get() {
const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
Object.defineProperty(this, styleName, { value: builder });
return builder;
}
};
}
styles2.visible = {
get() {
const builder = createBuilder(this, this[STYLER], true);
Object.defineProperty(this, "visible", { value: builder });
return builder;
}
};
var getModelAnsi = (model, level, type, ...arguments_) => {
if (model === "rgb") {
if (level === "ansi16m") {
return ansi_styles_default[type].ansi16m(...arguments_);
}
if (level === "ansi256") {
return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
}
return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
}
if (model === "hex") {
return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
}
return ansi_styles_default[type][model](...arguments_);
};
var usedModels = ["rgb", "hex", "ansi256"];
for (const model of usedModels) {
styles2[model] = {
get() {
const { level } = this;
return function(...arguments_) {
const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
return createBuilder(this, styler, this[IS_EMPTY]);
};
}
};
const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
styles2[bgModel] = {
get() {
const { level } = this;
return function(...arguments_) {
const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
return createBuilder(this, styler, this[IS_EMPTY]);
};
}
};
}
var proto = Object.defineProperties(() => {
}, {
...styles2,
level: {
enumerable: true,
get() {
return this[GENERATOR].level;
},
set(level) {
this[GENERATOR].level = level;
}
}
});
var createStyler = (open, close, parent) => {
let openAll;
let closeAll;
if (parent === void 0) {
openAll = open;
closeAll = close;
} else {
openAll = parent.openAll + open;
closeAll = close + parent.closeAll;
}
return {
open,
close,
openAll,
closeAll,
parent
};
};
var createBuilder = (self2, _styler, _isEmpty) => {
const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
Object.setPrototypeOf(builder, proto);
builder[GENERATOR] = self2;
builder[STYLER] = _styler;
builder[IS_EMPTY] = _isEmpty;
return builder;
};
var applyStyle = (self2, string) => {
if (self2.level <= 0 || !string) {
return self2[IS_EMPTY] ? "" : string;
}
let styler = self2[STYLER];
if (styler === void 0) {
return string;
}
const { openAll, closeAll } = styler;
if (string.includes("\x1B")) {
while (styler !== void 0) {
string = stringReplaceAll(string, styler.close, styler.open);
styler = styler.parent;
}
}
const lfIndex = string.indexOf("\n");
if (lfIndex !== -1) {
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
}
return openAll + string + closeAll;
};
Object.defineProperties(createChalk.prototype, styles2);
var chalk = createChalk();
var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
var source_default = chalk;
// node_modules/.pnpm/@inquirer+figures@1.0.1/node_modules/@inquirer/figures/dist/esm/index.mjs
var import_node_process2 = __toESM(require("process"), 1);
function isUnicodeSupported() {
if (import_node_process2.default.platform !== "win32") {
return import_node_process2.default.env["TERM"] !== "linux";
}
return Boolean(import_node_process2.default.env["WT_SESSION"]) || // Windows Terminal
Boolean(import_node_process2.default.env["TERMINUS_SUBLIME"]) || // Terminus (<0.2.27)
import_node_process2.default.env["ConEmuTask"] === "{cmd::Cmder}" || // ConEmu and cmder
import_node_process2.default.env["TERM_PROGRAM"] === "Terminus-Sublime" || import_node_process2.default.env["TERM_PROGRAM"] === "vscode" || import_node_process2.default.env["TERM"] === "xterm-256color" || import_node_process2.default.env["TERM"] === "alacritty" || import_node_process2.default.env["TERMINAL_EMULATOR"] === "JetBrains-JediTerm";
}
var common = {
circleQuestionMark: "(?)",
questionMarkPrefix: "(?)",
square: "\u2588",
squareDarkShade: "\u2593",
squareMediumShade: "\u2592",
squareLightShade: "\u2591",
squareTop: "\u2580",
squareBottom: "\u2584",
squareLeft: "\u258C",
squareRight: "\u2590",
squareCenter: "\u25A0",
bullet: "\u25CF",
dot: "\u2024",
ellipsis: "\u2026",
pointerSmall: "\u203A",
triangleUp: "\u25B2",
triangleUpSmall: "\u25B4",
triangleDown: "\u25BC",
triangleDownSmall: "\u25BE",
triangleLeftSmall: "\u25C2",
triangleRightSmall: "\u25B8",
home: "\u2302",
heart: "\u2665",
musicNote: "\u266A",
musicNoteBeamed: "\u266B",
arrowUp: "\u2191",
arrowDown: "\u2193",
arrowLeft: "\u2190",
arrowRight: "\u2192",
arrowLeftRight: "\u2194",
arrowUpDown: "\u2195",
almostEqual: "\u2248",
notEqual: "\u2260",
lessOrEqual: "\u2264",
greaterOrEqual: "\u2265",
identical: "\u2261",
infinity: "\u221E",
subscriptZero: "\u2080",
subscriptOne: "\u2081",
subscriptTwo: "\u2082",
subscriptThree: "\u2083",
subscriptFour: "\u2084",
subscriptFive: "\u2085",
subscriptSix: "\u2086",
subscriptSeven: "\u2087",
subscriptEight: "\u2088",
subscriptNine: "\u2089",
oneHalf: "\xBD",
oneThird: "\u2153",
oneQuarter: "\xBC",
oneFifth: "\u2155",
oneSixth: "\u2159",
oneEighth: "\u215B",
twoThirds: "\u2154",
twoFifths: "\u2156",
threeQuarters: "\xBE",
threeFifths: "\u2157",
threeEighths: "\u215C",
fourFifths: "\u2158",
fiveSixths: "\u215A",
fiveEighths: "\u215D",
sevenEighths: "\u215E",
line: "\u2500",
lineBold: "\u2501",
lineDouble: "\u2550",
lineDashed0: "\u2504",
lineDashed1: "\u2505",
lineDashed2: "\u2508",
lineDashed3: "\u2509",
lineDashed4: "\u254C",
lineDashed5: "\u254D",
lineDashed6: "\u2574",
lineDashed7: "\u2576",
lineDashed8: "\u2578",
lineDashed9: "\u257A",
lineDashed10: "\u257C",
lineDashed11: "\u257E",
lineDashed12: "\u2212",
lineDashed13: "\u2013",
lineDashed14: "\u2010",
lineDashed15: "\u2043",
lineVertical: "\u2502",
lineVerticalBold: "\u2503",
lineVerticalDouble: "\u2551",
lineVerticalDashed0: "\u2506",
lineVerticalDashed1: "\u2507",
lineVerticalDashed2: "\u250A",
lineVerticalDashed3: "\u250B",
lineVerticalDashed4: "\u254E",
lineVerticalDashed5: "\u254F",
lineVerticalDashed6: "\u2575",
lineVerticalDashed7: "\u2577",
lineVerticalDashed8: "\u2579",
lineVerticalDashed9: "\u257B",
lineVerticalDashed10: "\u257D",
lineVerticalDashed11: "\u257F",
lineDownLeft: "\u2510",
lineDownLeftArc: "\u256E",
lineDownBoldLeftBold: "\u2513",
lineDownBoldLeft: "\u2512",
lineDownLeftBold: "\u2511",
lineDownDoubleLeftDouble: "\u2557",
lineDownDoubleLeft: "\u2556",
lineDownLeftDouble: "\u2555",
lineDownRight: "\u250C",
lineDownRightArc: "\u256D",
lineDownBoldRightBold: "\u250F",
lineDownBoldRight: "\u250E",
lineDownRightBold: "\u250D",
lineDownDoubleRightDouble: "\u2554",
lineDownDoubleRight: "\u2553",
lineDownRightDouble: "\u2552",
lineUpLeft: "\u2518",
lineUpLeftArc: "\u256F",
lineUpBoldLeftBold: "\u251B",
lineUpBoldLeft: "\u251A",
lineUpLeftBold: "\u2519",
lineUpDoubleLeftDouble: "\u255D",
lineUpDoubleLeft: "\u255C",
lineUpLeftDouble: "\u255B",
lineUpRight: "\u2514",
lineUpRightArc: "\u2570",
lineUpBoldRightBold: "\u2517",
lineUpBoldRight: "\u2516",
lineUpRightBold: "\u2515",
lineUpDoubleRightDouble: "\u255A",
lineUpDoubleRight: "\u2559",
lineUpRightDouble: "\u2558",
lineUpDownLeft: "\u2524",
lineUpBoldDownBoldLeftBold: "\u252B",
lineUpBoldDownBoldLeft: "\u2528",
lineUpDownLeftBold: "\u2525",
lineUpBoldDownLeftBold: "\u2529",
lineUpDownBoldLeftBold: "\u252A",
lineUpDownBoldLeft: "\u2527",
lineUpBoldDownLeft: "\u2526",
lineUpDoubleDownDoubleLeftDouble: "\u2563",
lineUpDoubleDownDoubleLeft: "\u2562",
lineUpDownLeftDouble: "\u2561",
lineUpDownRight: "\u251C",
lineUpBoldDownBoldRightBold: "\u2523",
lineUpBoldDownBoldRight: "\u2520",
lineUpDownRightBold: "\u251D",
lineUpBoldDownRightBold: "\u2521",
lineUpDownBoldRightBold: "\u2522",
lineUpDownBoldRight: "\u251F",
lineUpBoldDownRight: "\u251E",
lineUpDoubleDownDoubleRightDouble: "\u2560",
lineUpDoubleDownDoubleRight: "\u255F",
lineUpDownRightDouble: "\u255E",
lineDownLeftRight: "\u252C",
lineDownBoldLeftBoldRightBold: "\u2533",
lineDownLeftBoldRightBold: "\u252F",
lineDownBoldLeftRight: "\u2530",
lineDownBoldLeftBoldRight: "\u2531",
lineDownBoldLeftRightBold: "\u2532",
lineDownLeftRightBold: "\u252E",
lineDownLeftBoldRight: "\u252D",
lineDownDoubleLeftDoubleRightDouble: "\u2566",
lineDownDoubleLeftRight: "\u2565",
lineDownLeftDoubleRightDouble: "\u2564",
lineUpLeftRight: "\u2534",
lineUpBoldLeftBoldRightBold: "\u253B",
lineUpLeftBoldRightBold: "\u2537",
lineUpBoldLeftRight: "\u2538",
lineUpBoldLeftBoldRight: "\u2539",
lineUpBoldLeftRightBold: "\u253A",
lineUpLeftRightBold: "\u2536",
lineUpLeftBoldRight: "\u2535",
lineUpDoubleLeftDoubleRightDouble: "\u2569",
lineUpDoubleLeftRight: "\u2568",
lineUpLeftDoubleRightDouble: "\u2567",
lineUpDownLeftRight: "\u253C",
lineUpBoldDownBoldLeftBoldRightBold: "\u254B",
lineUpDownBoldLeftBoldRightBold: "\u2548",
lineUpBoldDownLeftBoldRightBold: "\u2547",
lineUpBoldDownBoldLeftRightBold: "\u254A",
lineUpBoldDownBoldLeftBoldRight: "\u2549",
lineUpBoldDownLeftRight: "\u2540",
lineUpDownBoldLeftRight: "\u2541",
lineUpDownLeftBoldRight: "\u253D",
lineUpDownLeftRightBold: "\u253E",
lineUpBoldDownBoldLeftRight: "\u2542",
lineUpDownLeftBoldRightBold: "\u253F",
lineUpBoldDownLeftBoldRight: "\u2543",
lineUpBoldDownLeftRightBold: "\u2544",
lineUpDownBoldLeftBoldRight: "\u2545",
lineUpDownBoldLeftRightBold: "\u2546",
lineUpDoubleDownDoubleLeftDoubleRightDouble: "\u256C",
lineUpDoubleDownDoubleLeftRight: "\u256B",
lineUpDownLeftDoubleRightDouble: "\u256A",
lineCross: "\u2573",
lineBackslash: "\u2572",
lineSlash: "\u2571"
};
var specialMainSymbols = {
tick: "\u2714",
info: "\u2139",
warning: "\u26A0",
cross: "\u2718",
squareSmall: "\u25FB",
squareSmallFilled: "\u25FC",
circle: "\u25EF",
circleFilled: "\u25C9",
circleDotted: "\u25CC",
circleDouble: "\u25CE",
circleCircle: "\u24DE",
circleCross: "\u24E7",
circlePipe: "\u24BE",
radioOn: "\u25C9",
radioOff: "\u25EF",
checkboxOn: "\u2612",
checkboxOff: "\u2610",
checkboxCircleOn: "\u24E7",
checkboxCircleOff: "\u24BE",
pointer: "\u276F",
triangleUpOutline: "\u25B3",
triangleLeft: "\u25C0",
triangleRight: "\u25B6",
lozenge: "\u25C6",
lozengeOutline: "\u25C7",
hamburger: "\u2630",
smiley: "\u32E1",
mustache: "\u0DF4",
star: "\u2605",
play: "\u25B6",
nodejs: "\u2B22",
oneSeventh: "\u2150",
oneNinth: "\u2151",
oneTenth: "\u2152"
};
var specialFallbackSymbols = {
tick: "\u221A",
info: "i",
warning: "\u203C",
cross: "\xD7",
squareSmall: "\u25A1",
squareSmallFilled: "\u25A0",
circle: "( )",
circleFilled: "(*)",
circleDotted: "( )",
circleDouble: "( )",
circleCircle: "(\u25CB)",
circleCross: "(\xD7)",
circlePipe: "(\u2502)",
radioOn: "(*)",
radioOff: "( )",
checkboxOn: "[\xD7]",
checkboxOff: "[ ]",
checkboxCircleOn: "(\xD7)",
checkboxCircleOff: "( )",
pointer: ">",
triangleUpOutline: "\u2206",
triangleLeft: "\u25C4",
triangleRight: "\u25BA",
lozenge: "\u2666",
lozengeOutline: "\u25CA",
hamburger: "\u2261",
smiley: "\u263A",
mustache: "\u250C\u2500\u2510",
star: "\u2736",
play: "\u25BA",
nodejs: "\u2666",
oneSeventh: "1/7",
oneNinth: "1/9",
oneTenth: "1/10"
};
var mainSymbols = { ...common, ...specialMainSymbols };
var fallbackSymbols = {
...common,
...specialFallbackSymbols
};
var shouldUseMain = isUnicodeSupported();
var figures = shouldUseMain ? mainSymbols : fallbackSymbols;
var esm_default = figures;
var replacements = Object.entries(specialMainSymbols);
// node_modules/.pnpm/ansi-escapes@7.0.0/node_modules/ansi-escapes/base.js
var base_exports = {};
__export(base_exports, {
beep: () => beep,
clearScreen: () => clearScreen,
clearTerminal: () => clearTerminal,
cursorBackward: () => cursorBackward,
cursorDown: () => cursorDown,
cursorForward: () => cursorForward,
cursorGetPosition: () => cursorGetPosition,
cursorHide: () => cursorHide,
cursorLeft: () => cursorLeft,
cursorMove: () => cursorMove,
cursorNextLine: () => cursorNextLine,
cursorPrevLine: () => cursorPrevLine,
cursorRestorePosition: () => cursorRestorePosition,
cursorSavePosition: () => cursorSavePosition,
cursorShow: () => cursorShow,
cursorTo: () => cursorTo,
cursorUp: () => cursorUp,
enterAlternativeScreen: () => enterAlternativeScreen,
eraseDown: () => eraseDown,
eraseEndLine: () => eraseEndLine,
eraseLine: () => eraseLine,
eraseLines: () => eraseLines,
eraseScreen: () => eraseScreen,
eraseStartLine: () => eraseStartLine,
eraseUp: () => eraseUp,
exitAlternativeScreen: () => exitAlternativeScreen,
iTerm: () => iTerm,
image: () => image,
link: () => link,
scrollDown: () => scrollDown,
scrollUp: () => scrollUp
});
var import_node_process3 = __toESM(require("process"), 1);
// node_modules/.pnpm/environment@1.0.0/node_modules/environment/index.js
var isBrowser = globalThis.window?.document !== void 0;
var isNode = globalThis.process?.versions?.node !== void 0;
var isBun = globalThis.process?.versions?.bun !== void 0;
var isDeno = globalThis.Deno?.version?.deno !== void 0;
var isElectron = globalThis.process?.versions?.electron !== void 0;
var isJsDom = globalThis.navigator?.userAgent?.includes("jsdom") === true;
var isWebWorker = typeof WorkerGlobalScope !== "undefined" && globalThis instanceof WorkerGlobalScope;
var isDedicatedWorker = typeof DedicatedWorkerGlobalScope !== "undefined" && globalThis instanceof DedicatedWorkerGlobalScope;
var isSharedWorker = typeof SharedWorkerGlobalScope !== "undefined" && globalThis instanceof SharedWorkerGlobalScope;
var isServiceWorker = typeof ServiceWorkerGlobalScope !== "undefined" && globalThis instanceof ServiceWorkerGlobalScope;
// node_modules/.pnpm/ansi-escapes@7.0.0/node_modules/ansi-escapes/base.js
var ESC = "\x1B[";
var OSC = "\x1B]";
var BEL = "\x07";
var SEP = ";";
var isTerminalApp = !isBrowser && import_node_process3.default.env.TERM_PROGRAM === "Apple_Terminal";
var isWindows = !isBrowser && import_node_process3.default.platform === "win32";
var cwdFunction = isBrowser ? () => {
throw new Error("`process.cwd()` only works in Node.js, not the browser.");
} : import_node_process3.default.cwd;
var cursorTo = (x, y) => {
if (typeof x !== "number") {
throw new TypeError("The `x` argument is required");
}
if (typeof y !== "number") {
return ESC + (x + 1) + "G";
}
return ESC + (y + 1) + SEP + (x + 1) + "H";
};
var cursorMove = (x, y) => {
if (typeof x !== "number") {
throw new TypeError("The `x` argument is required");
}
let returnValue = "";
if (x < 0) {
returnValue += ESC + -x + "D";
} else if (x > 0) {
returnValue += ESC + x + "C";
}
if (y < 0) {
returnValue += ESC + -y + "A";
} else if (y > 0) {
returnValue += ESC + y + "B";
}
return returnValue;
};
var cursorUp = (count = 1) => ESC + count + "A";
var cursorDown = (count = 1) => ESC + count + "B";
var cursorForward = (count = 1) => ESC + count + "C";
var cursorBackward = (count = 1) => ESC + count + "D";
var cursorLeft = ESC + "G";
var cursorSavePosition = isTerminalApp ? "\x1B7" : ESC + "s";
var cursorRestorePosition = isTerminalApp ? "\x1B8" : ESC + "u";
var cursorGetPosition = ESC + "6n";
var cursorNextLine = ESC + "E";
var cursorPrevLine = ESC + "F";
var cursorHide = ESC + "?25l";
var cursorShow = ESC + "?25h";
var eraseLines = (count) => {
let clear = "";
for (let i = 0; i < count; i++) {
clear += eraseLine + (i < count - 1 ? cursorUp() : "");
}
if (count) {
clear += cursorLeft;
}
return clear;
};
var eraseEndLine = ESC + "K";
var eraseStartLine = ESC + "1K";
var eraseLine = ESC + "2K";
var eraseDown = ESC + "J";
var eraseUp = ESC + "1J";
var eraseScreen = ESC + "2J";
var scrollUp = ESC + "S";
var scrollDown = ESC + "T";
var clearScreen = "\x1Bc";
var clearTerminal = isWindows ? `${eraseScreen}${ESC}0f` : `${eraseScreen}${ESC}3J${ESC}H`;
var enterAlternativeScreen = ESC + "?1049h";
var exitAlternativeScreen = ESC + "?1049l";
var beep = BEL;
var link = (text, url) => [
OSC,
"8",
SEP,
SEP,
url,
BEL,
text,
OSC,
"8",
SEP,
SEP,
BEL
].join("");
var image = (data, options = {}) => {
let returnValue = `${OSC}1337;File=inline=1`;
if (options.width) {
returnValue += `;width=${options.width}`;
}
if (options.height) {
returnValue += `;height=${options.height}`;
}
if (options.preserveAspectRatio === false) {
returnValue += ";preserveAspectRatio=0";
}
return returnValue + ":" + Buffer.from(data).toString("base64") + BEL;
};
var iTerm = {
setCwd: (cwd = cwdFunction()) => `${OSC}50;CurrentDir=${cwd}${BEL}`,
annotation(message, options = {}) {
let returnValue = `${OSC}1337;`;
const hasX = options.x !== void 0;
const hasY = options.y !== void 0;
if ((hasX || hasY) && !(hasX && hasY && options.length !== void 0)) {
throw new Error("`x`, `y` and `length` must be defined when `x` or `y` is defined");
}
message = message.replaceAll("|", "");
returnValue += options.isHidden ? "AddHiddenAnnotation=" : "AddAnnotation=";
if (options.length > 0) {
returnValue += (hasX ? [message, options.length, options.x, options.y] : [options.length, message]).join("|");
} else {
returnValue += message;
}
return returnValue + BEL;
}
};
// src/useSelect.ts
var import_core2 = require("@inquirer/core");
// node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isObject.js
function isObject(value) {
var type = typeof value;
return value != null && (type == "object" || type == "function");
}
var isObject_default = isObject;
// node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_freeGlobal.js
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
var freeGlobal_default = freeGlobal;
// node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_root.js
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
var root = freeGlobal_default || freeSelf || Function("return this")();
var root_default = root;
// node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/now.js
var now = function() {
return root_default.Date.now();
};
var now_default = now;
// node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_trimmedEndIndex.js
var reWhitespace = /\s/;
function trimmedEndIndex(string) {
var index = string.length;
while (index-- && reWhitespace.test(string.charAt(index))) {
}
return index;
}
var trimmedEndIndex_default = trimmedEndIndex;
// node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseTrim.js
var reTrimStart = /^\s+/;
function baseTrim(string) {
return string ? string.slice(0, trimmedEndIndex_default(string) + 1).replace(reTrimStart, "") : string;
}
var baseTrim_default = baseTrim;
// node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_Symbol.js
var Symbol2 = root_default.Symbol;
var Symbol_default = Symbol2;
// node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_getRawTag.js
var objectProto = Object.prototype;
var hasOwnProperty = objectProto.hasOwnProperty;
var nativeObjectToString = objectProto.toString;
var symToStringTag = Symbol_default ? Symbol_default.toStringTag : void 0;
function getRawTag(value) {
var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
try {
value[symToStringTag] = void 0;
var unmasked = true;
} catch (e) {
}
var result = nativeObjectToString.call(value);
if (unmasked) {
if (isOwn) {
value[symToStringTag] = tag;
} else {
delete value[symToStringTag];
}
}
return result;
}
var getRawTag_default = getRawTag;
// node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_objectToString.js
var objectProto2 = Object.prototype;
var nativeObjectToString2 = objectProto2.toString;
function objectToString(value) {
return nativeObjectToString2.call(value);
}
var objectToString_default = objectToString;
// node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseGetTag.js
var nullTag = "[object Null]";
var undefinedTag = "[object Undefined]";
var symToStringTag2 = Symbol_default ? Symbol_default.toStringTag : void 0;
function baseGetTag(value) {
if (value == null) {
return value === void 0 ? undefinedTag : nullTag;
}
return symToStringTag2 && symToStringTag2 in Object(value) ? getRawTag_default(value) : objectToString_default(value);
}
var baseGetTag_default = baseGetTag;
// node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isObjectLike.js
function isObjectLike(value) {
return value != null && typeof value == "object";
}
var isObjectLike_default = isObjectLike;
// node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isSymbol.js
var symbolTag = "[object Symbol]";
function isSymbol(value) {
return typeof value == "symbol" || isObjectLike_default(value) && baseGetTag_default(value) == symbolTag;
}
var isSymbol_default = isSymbol;
// node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/toNumber.js
var NAN = 0 / 0;
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
var reIsBinary = /^0b[01]+$/i;
var reIsOctal = /^0o[0-7]+$/i;
var freeParseInt = parseInt;
function toNumber(value) {
if (typeof value == "number") {
return value;
}
if (isSymbol_default(value)) {
return NAN;
}
if (isObject_default(value)) {
var other = typeof value.valueOf == "function" ? value.valueOf() : value;
value = isObject_default(other) ? other + "" : other;
}
if (typeof value != "string") {
return value === 0 ? value : +value;
}
value = baseTrim_default(value);
var isBinary = reIsBinary.test(value);
return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
}
var toNumber_default = toNumber;
// node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/debounce.js
var FUNC_ERROR_TEXT = "Expected a function";
var nativeMax = Math.max;
var nativeMin = Math.min;
function debounce(func, wait, options) {
var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
if (typeof func != "function") {
throw new TypeError(FUNC_ERROR_TEXT);
}
wait = toNumber_default(wait) || 0;
if (isObject_default(options)) {
leading = !!options.leading;
maxing = "maxWait" in options;
maxWait = maxing ? nativeMax(toNumber_default(options.maxWait) || 0, wait) : maxWait;
trailing = "trailing" in options ? !!options.trailing : trailing;
}
function invokeFunc(time) {
var args = lastArgs, thisArg = lastThis;
lastArgs = lastThis = void 0;
lastInvokeTime = time;
result = func.apply(thisArg, args);
return result;
}
function leadingEdge(time) {
lastInvokeTime = time;
timerId = setTimeout(timerExpired, wait);
return leading ? invokeFunc(time) : result;
}
function remainingWait(time) {
var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime, timeWaiting = wait - timeSinceLastCall;
return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
}
function shouldInvoke(time) {
var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime;
return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
}
function timerExpired() {
var time = now_default();
if (shouldInvoke(time)) {
return trailingEdge(time);
}
timerId = setTimeout(timerExpired, remainingWait(time));
}
function trailingEdge(time) {
timerId = void 0;
if (trailing && lastArgs) {
return invokeFunc(time);
}
lastArgs = lastThis = void 0;
return result;
}
function cancel() {
if (timerId !== void 0) {
clearTimeout(timerId);
}
lastInvokeTime = 0;
lastArgs = lastCallTime = lastThis = timerId = void 0;
}
function flush() {
return timerId === void 0 ? result : trailingEdge(now_default());
}
function debounced() {
var time = now_default(), isInvoking = shouldInvoke(time);
lastArgs = arguments;
lastThis = this;
lastCallTime = time;
if (isInvoking) {
if (timerId === void 0) {
return leadingEdge(lastCallTime);
}
if (maxing) {
clearTimeout(timerId);
timerId = setTimeout(timerExpired, wait);
return invokeFunc(lastCallTime);
}
}
if (timerId === void 0) {
timerId = setTimeout(timerExpired, wait);
}
return result;
}
debounced.cancel = cancel;
debounced.flush = flush;
return debounced;
}
var debounce_default = debounce;
// src/utils.ts
var import_core = require("@inquirer/core");
function isUpKey(key) {
return key.name === "up";
}
function isDownKey(key) {
return key.name === "down";
}
function isDirectionKey(key) {
return key.name === "up" || key.name === "down" || key.name === "left" || key.name === "right";
}
function isEscKey(key) {
return key.name === "escape";
}
function isTabKey(key) {
return key.name === "tab";
}
function isSelectAllKey(key) {
return key.name === "a" && key.ctrl;
}
function isSelectable(item) {
return !import_core.Separator.isSeparator(item) && !item.disabled;
}
function toggle(item) {
return isSelectable(item) ? { ...item, checked: !item.checked } : item;
}
function check(item, checked = true) {
return isSelectable(item) && item.checked !== checked ? { ...item, checked } : item;
}
function useDebounce(func, wait) {
const ref = (0, import_core.useRef)();
ref.current = func;
return (0, import_core.useMemo)(
() => debounce_default(() => {
ref.current?.();
}, wait),
[wait]
);
}
// src/types.ts
var SelectStatus = /* @__PURE__ */ ((SelectStatus2) => {
SelectStatus2["UNLOADED"] = "unloaded";
SelectStatus2["FILTERING"] = "filtering";
SelectStatus2["LOADED"] = "loaded";
SelectStatus2["SUBMITTED"] = "submitted";
return SelectStatus2;
})(SelectStatus || {});
// src/useSelect.ts
function value2Name(value) {
return typeof value === "string" || typeof value === "number" || typeof value === "bigint" || typeof value === "boolean" ? value.toString() : "";
}
function transformDefaultValue(values, multiple) {
if (!values)
return [];
if (multiple) {
if (!Array.isArray(values))
throw new import_core2.ValidationError(
"In `multiple` mode, please pass the array as the default value."
);
return values.map(
(value) => ({
name: value2Name(value),
value,
focused: false
})
);
}
return [
{
name: value2Name(values),
value: values
}
];
}
function transformSelections(selections, multiple) {
if (multiple) {
return selections.map((s) => s.value);
}
return selections.length > 0 ? selections[0].value : null;
}
function useSelect(props) {
const {
options,
loop = false,
multiple = true,
selectFocusedOnSubmit = false,
filter = true,
required = false,
defaultValue,
clearInputWhenSelected = false,
canToggleAll = false,
confirmDelete = false,
inputDelay = 200,
validate = () => true,
equals = (a, b) => a === b,
onSubmitted
} = props;
const enableFilter = Array.isArray(options) ? false : filter;
const [displayItems, setDisplayItems] = (0, import_core2.useState)([]);
const bounds = (0, import_core2.useMemo)(() => {
const first = displayItems.findIndex(isSelectable);
const last = displayItems.findLastIndex(isSelectable);
return { first, last };
}, [displayItems]);
const [cursor, setCursor] = (0, import_core2.useState)(-1);
const [status, setStatus] = (0, import_core2.useState)("unloaded" /* UNLOADED */);
const [error, setError] = (0, import_core2.useState)("");
const loader = (0, import_core2.useRef)();
const [filterInput, setFilterInput] = (0, import_core2.useState)("");
const [focused, setFocused] = (0, import_core2.useState)(-1);
const selections = (0, import_core2.useRef)(
transformDefaultValue(defaultValue, multiple)
);
const [behaviors, setBehaviors] = (0, import_core2.useState)({
submit: false,
select: false,
deselect: false,
filter: false,
setCursor: false,
deleteOption: false,
blur: false
});
function setBehavior(key, value) {
if (behaviors[key] === value)
return;
setBehaviors({
...behaviors,
[key]: value
});
}
function clearFilterInput(rl) {
setFilterInput("");
rl.clearLine(0);
}
function keepFilterInput(rl) {
rl.clearLine(0);
rl.write(filterInput);
}
function handleSelect(rl, clearInput = clearInputWhenSelected) {
if (cursor < 0 || displayItems.length <= 0) {
if (enableFilter) {
keepFilterInput(rl);
}
return;
}
const targetOption = displayItems[cursor];
if (isSelectable(targetOption)) {
if (multiple) {
if (targetOption.checked) {
const currentSelection = selections.current.filter(
(op) => !equals(targetOption.value, op.value)
);
setBehavior("deselect", true);
selections.current = currentSelection;
} else {
setBehavior("select", true);
selections.current = [...selections.current, { ...targetOption }];
}
} else {
setBehavior("select", true);
selections.current = [{ ...targetOption }];
}
if (enableFilter && !targetOption.checked && clearInput) {
clearFilterInput(rl);
} else {
keepFilterInput(rl);
}
}
setDisplayItems(
displayItems.map((item, i) => {
return i === cursor ? toggle(item) : item;
})
);
}
function toggleAll(rl) {
if (cursor < 0 || displayItems.length <= 0) {
if (enableFilter) {
keepFilterInput(rl);
}
return;
}
const hasSelectAll = !displayItems.find(
(item) => isSelectable(item) && !item.checked
);
if (hasSelectAll) {
selections.current = [];
setBehavior("deselect", true);
setDisplayItems(displayItems.map((item) => check(item, false)));
} else {
selections.current = displayItems.reduce((ss, item) => {
if (isSelectable(item)) {
ss.push({ ...item });
}
return ss;
}, []);
setBehavior("select", true);
setDisplayItems(displayItems.map((item) => check(item, true)));
}
}
function removeLastSection() {
if (selections.current.length <= 0)
return;
const lastIndex = selections.current.length - 1;
const lastSection = selections.current[lastIndex];
if (confirmDelete && focused < 0) {
lastSection.focused = true;
setFocused(lastIndex);
return;
}
const ss = selections.current.slice(0, lastIndex);
setBehavior("deleteOption", true);
selections.current = ss;
setDisplayItems(
displayItems.map(
(item) => isSelectable(item) && equals(item.value, lastSection.value) ? toggle(item) : item
)
);
}
async function submit() {
setBehavior("submit", true);
const isValid = await validate([...selections.current]);
if (required && selections.current.length <= 0) {
setError("At least one option must be selected");
} else if (isValid === true) {
setStatus("submitted" /* SUBMITTED */);
if (onSubmitted) {
const finalValue = transformSelections(
selections.current,
multiple
);
onSubmitted(finalValue);
}
} else {
setError(isValid || "You must select a valid value");
}
}
(0, import_core2.useKeypress)(async (key, rl) => {
if (focused >= 0) {
if ((0, import_core2.isBackspaceKey)(key)) {
removeLastSection();
setFocused(-1);
} else if (isDirectionKey(key) || isEscKey(key)) {
const focusedSelection = selections.current[focused];
focusedSelection.focused = false;
setFocused(-1);
setBehavior("blur", true);
}
clearFilterInput(rl);
return;
}
if ((0, import_core2.isEnterKey)(key)) {
if (status !== "loaded" /* LOADED */) {
return;
}
if (!multiple || selectFocusedOnSubmit && selections.current.length === 0) {
handleSelect(rl);
}
await submit();
} else if ((0, import_core2.isBackspaceKey)(key) && !filterInput) {
setFilterInput("");
removeLastSection();
} else if (isUpKey(key) || isDownKey(key)) {
if (bounds.first < 0 || status !== "loaded" /* LOADED */)
return;
if (loop || isUpKey(key) && cursor !== bounds.first || isDownKey(key) && cursor !== bounds.last) {
const offset = isUpKey(key) ? -1 : 1;
let next = cursor;
do {
next = (next + offset + displayItems.length) % displayItems.length;
} while (!isSelectable(displayItems[next]));
setBehavior("setCursor", true);
setCursor(next);
}
} else if (canToggleAll && multiple && isSelectAllKey(key)) {
toggleAll(rl);
} else if (multiple && isTabKey(key)) {
handleSelect(rl);
} else {
if (!enableFilter || status === "unloaded" /* UNLOADED */)
return;
setError("");
setBehavior("filter", true);
setFilterInput(rl.line);
}
});
function handleItems(items) {
if (items.length <= 0) {
setDisplayItems([]);
setCursor(-1);
return;
}
const ss = [...selections.current];
let firstChecked = -1;
let firstSelectable = -1;
const finalItems = items.map((item, index) => {
const finalItem = { ...item };
if (isSelectable(finalItem)) {
if (firstSelectable < 0) {
firstSelectable = index;
}
ss.forEach((op) => {
if (equals(op.value, finalItem.value)) {
finalItem.checked = true;
op.name = finalItem.name;
if (firstChecked < 0) {
firstChecked = index;
}
}
});
}
return finalItem;
});
setDisplayItems(finalItems);
selections.current = ss;
if (multiple) {
setCursor(firstSelectable);
} else {
setCursor(firstChecked < 0 ? firstSelectable : firstChecked);
}
}
async function loadData() {
if (status !== "unloaded" /* UNLOADED */) {
setStatus("filtering" /* FILTERING */);
}
setError("");
if (loader.current) {
await loader.current;
}
const result = options instanceof Function ? enableFilter ? options(filterInput) : options() : options;
loader.current = (result instanceof Promise ? result : Promise.resolve(result)).then(handleItems).catch((err) => setError(err)).finally(() => setStatus("loaded" /* LOADED */));
}
const debouncedLoadData = useDebounce(loadData, inputDelay);
if (enableFilter) {
(0, import_core2.useEffect)(() => {
debouncedLoadData();
}, [filterInput]);
} else {
(0, import_core2.useEffect)(() => {
loadData();
}, []);
}
return {
selections: selections.current,
focusedSelection: focused,
confirmDelete,
filterInput,
displayItems,
cursor,
status,
error,
loop,
multiple,
enableFilter,
canToggleAll,
required,
behaviors
};
}
// src/index.ts
var import_core4 = require("@inquirer/core");
var defaultSelectTheme = (multiple) => ({
icon: {
checked: multiple ? `[${source_default.green(esm_default.tick)}]` : "",
unchecked: multiple ? "[ ]" : "",
cursor: ">",
inputCursor: source_default.cyan(">>")
},
style: {
disabledOption: (text) => source_default.dim(`-[x] ${text}`),
renderSelectedOptions: (selectedOptions) => selectedOptions.map(
(option) => option.focused ? (
/* v8 ignore next 3 */
source_default.inverse(option.name || option.value)
) : option.name || option.value
).join(", "),
emptyText: (text) => `${source_default.blue(esm_default.info)} ${source_default.bold(text)}`,