@optique/clack 1.4.0-dev.2728 → 1.4.0-dev.2729
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.
- package/dist/index.cjs +48 -3
- package/dist/index.d.cts +51 -5
- package/dist/index.d.ts +51 -5
- package/dist/index.js +49 -4
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -28,6 +28,8 @@ const __optique_prompt = __toESM(require("@optique/prompt"));
|
|
|
28
28
|
//#region src/index.ts
|
|
29
29
|
const promptFunctionsOverrideSymbol = Symbol.for("@optique/clack/prompt-functions");
|
|
30
30
|
const defaultPromptFunctions = {
|
|
31
|
+
autocomplete: __clack_prompts.autocomplete,
|
|
32
|
+
autocompleteMultiselect: __clack_prompts.autocompleteMultiselect,
|
|
31
33
|
spinner: __clack_prompts.spinner,
|
|
32
34
|
text: __clack_prompts.text,
|
|
33
35
|
password: __clack_prompts.password,
|
|
@@ -132,7 +134,18 @@ async function executePromptRaw(config, context) {
|
|
|
132
134
|
if ("prompter" in cfg && cfg.prompter != null) result = await cfg.prompter(context);
|
|
133
135
|
else {
|
|
134
136
|
if (context.previousValidationMessage !== void 0) prompts.logError((0, __optique_core_message.formatMessage)(context.previousValidationMessage));
|
|
135
|
-
|
|
137
|
+
const disabled = cfg.type === "autocomplete-multiselect" ? new Set(normalizeOptions(cfg.options).filter((option) => option.disabled).map((option) => option.value)) : void 0;
|
|
138
|
+
while (true) {
|
|
139
|
+
result = await executeClackPromptWithSignal(cfg, prompts, context.signal);
|
|
140
|
+
if (cfg.type !== "autocomplete-multiselect" || disabled === void 0 || !Array.isArray(result)) break;
|
|
141
|
+
const values = result.filter((value) => typeof value !== "string" || !disabled.has(value));
|
|
142
|
+
if (cfg.required === true && result.length > 0 && values.length === 0) {
|
|
143
|
+
prompts.logError("No option selected.");
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
result = values;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
136
149
|
}
|
|
137
150
|
if (prompts.isCancel(result)) {
|
|
138
151
|
if (context.signal?.aborted === true) throw context.signal.reason;
|
|
@@ -142,7 +155,11 @@ async function executePromptRaw(config, context) {
|
|
|
142
155
|
};
|
|
143
156
|
}
|
|
144
157
|
if (cfg.type === "number") return normalizeNumberResult(result);
|
|
145
|
-
if (cfg.type === "
|
|
158
|
+
if (cfg.type === "autocomplete" && typeof result !== "string") return {
|
|
159
|
+
success: false,
|
|
160
|
+
error: __optique_core_message.message`No option selected.`
|
|
161
|
+
};
|
|
162
|
+
if (cfg.type === "multiselect" || cfg.type === "autocomplete-multiselect") return normalizeMultiselectResult(result, cfg);
|
|
146
163
|
return {
|
|
147
164
|
success: true,
|
|
148
165
|
value: result
|
|
@@ -161,7 +178,7 @@ async function executeClackPromptWithSignal(cfg, prompts, signal) {
|
|
|
161
178
|
}
|
|
162
179
|
}
|
|
163
180
|
function isPromptType(value) {
|
|
164
|
-
return value === "text" || value === "password" || value === "confirm" || value === "number" || value === "select" || value === "multiselect";
|
|
181
|
+
return value === "text" || value === "password" || value === "confirm" || value === "number" || value === "select" || value === "multiselect" || value === "autocomplete" || value === "autocomplete-multiselect";
|
|
165
182
|
}
|
|
166
183
|
function executeClackPrompt(cfg, prompts, signal) {
|
|
167
184
|
switch (cfg.type) {
|
|
@@ -202,6 +219,34 @@ function executeClackPrompt(cfg, prompts, signal) {
|
|
|
202
219
|
options: normalizeOptions(cfg.options),
|
|
203
220
|
...cfg.initialValue !== void 0 ? { initialValue: cfg.initialValue } : {}
|
|
204
221
|
});
|
|
222
|
+
case "autocomplete": {
|
|
223
|
+
const options = normalizeOptions(cfg.options);
|
|
224
|
+
return prompts.autocomplete({
|
|
225
|
+
message: cfg.message,
|
|
226
|
+
options,
|
|
227
|
+
...signal === void 0 ? {} : { signal },
|
|
228
|
+
...cfg.initialValue === void 0 ? {} : { initialValue: cfg.initialValue },
|
|
229
|
+
...cfg.initialUserInput === void 0 ? {} : { initialUserInput: cfg.initialUserInput },
|
|
230
|
+
...cfg.placeholder === void 0 ? {} : { placeholder: cfg.placeholder },
|
|
231
|
+
...cfg.maxItems === void 0 ? {} : { maxItems: cfg.maxItems },
|
|
232
|
+
...cfg.filter === void 0 ? {} : { filter: cfg.filter },
|
|
233
|
+
validate: (value) => {
|
|
234
|
+
if (typeof value !== "string") return "No option selected.";
|
|
235
|
+
if (options.some((option) => option.value === value && option.disabled)) return "Option is unavailable.";
|
|
236
|
+
return cfg.validate?.(value) ?? void 0;
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
case "autocomplete-multiselect": return prompts.autocompleteMultiselect({
|
|
241
|
+
message: cfg.message,
|
|
242
|
+
options: normalizeOptions(cfg.options),
|
|
243
|
+
...signal === void 0 ? {} : { signal },
|
|
244
|
+
...cfg.initialValues === void 0 ? {} : { initialValues: [...cfg.initialValues] },
|
|
245
|
+
...cfg.required === void 0 ? {} : { required: cfg.required },
|
|
246
|
+
...cfg.placeholder === void 0 ? {} : { placeholder: cfg.placeholder },
|
|
247
|
+
...cfg.maxItems === void 0 ? {} : { maxItems: cfg.maxItems },
|
|
248
|
+
...cfg.filter === void 0 ? {} : { filter: cfg.filter }
|
|
249
|
+
});
|
|
205
250
|
case "multiselect": return prompts.multiselect({
|
|
206
251
|
message: cfg.message,
|
|
207
252
|
...signal === void 0 ? {} : { signal },
|
package/dist/index.d.cts
CHANGED
|
@@ -5,7 +5,7 @@ import { DerivePromptConfigContext, DerivePromptConfigNoDepsContext, DerivePromp
|
|
|
5
5
|
//#region src/index.d.ts
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* A choice item for
|
|
8
|
+
* A choice item for selection and autocomplete prompts.
|
|
9
9
|
*
|
|
10
10
|
* @since 1.2.0
|
|
11
11
|
*/
|
|
@@ -150,12 +150,58 @@ interface MultiselectConfig {
|
|
|
150
150
|
*/
|
|
151
151
|
readonly prompter?: (context: PromptExecutionContext$1) => Promise<readonly string[]>;
|
|
152
152
|
}
|
|
153
|
+
/** Shared settings for filtering a list of options. */
|
|
154
|
+
interface AutocompleteSettings {
|
|
155
|
+
/** The question to display to the user. */
|
|
156
|
+
readonly message: string;
|
|
157
|
+
/** Available options. Use a derived config to load them lazily. */
|
|
158
|
+
readonly options: readonly (string | Option)[];
|
|
159
|
+
/** Hint text shown when the search input is empty. */
|
|
160
|
+
readonly placeholder?: string;
|
|
161
|
+
/** Maximum number of options displayed at once. */
|
|
162
|
+
readonly maxItems?: number;
|
|
163
|
+
/** Matches search input against a normalized option. */
|
|
164
|
+
readonly filter?: (search: string, option: Option) => boolean;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Configuration for an `autocomplete` prompt that filters a local list.
|
|
168
|
+
*
|
|
169
|
+
* @since 1.4.0
|
|
170
|
+
*/
|
|
171
|
+
interface AutocompleteConfig extends AutocompleteSettings {
|
|
172
|
+
readonly type: "autocomplete";
|
|
173
|
+
/** Initially selected option value. */
|
|
174
|
+
readonly initialValue?: string;
|
|
175
|
+
/** Initial text in the search input. */
|
|
176
|
+
readonly initialUserInput?: string;
|
|
177
|
+
/** Synchronous validation of the selected value inside the prompt. */
|
|
178
|
+
readonly validate?: (value: string) => string | void;
|
|
179
|
+
/** Overrides prompt execution. Useful for testing. */
|
|
180
|
+
readonly prompter?: (context: PromptExecutionContext$1) => Promise<string>;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Configuration for an `autocomplete-multiselect` prompt.
|
|
184
|
+
*
|
|
185
|
+
* Use shared prompt options for validation; Clack does not run a custom
|
|
186
|
+
* validator for this prompt type.
|
|
187
|
+
*
|
|
188
|
+
* @since 1.4.0
|
|
189
|
+
*/
|
|
190
|
+
interface AutocompleteMultiselectConfig extends AutocompleteSettings {
|
|
191
|
+
readonly type: "autocomplete-multiselect";
|
|
192
|
+
/** Initially selected option values. */
|
|
193
|
+
readonly initialValues?: readonly string[];
|
|
194
|
+
/** Whether at least one option must be selected. */
|
|
195
|
+
readonly required?: boolean;
|
|
196
|
+
/** Overrides prompt execution. Useful for testing. */
|
|
197
|
+
readonly prompter?: (context: PromptExecutionContext$1) => Promise<readonly string[]>;
|
|
198
|
+
}
|
|
153
199
|
/**
|
|
154
200
|
* A union of all string-valued prompt configurations.
|
|
155
201
|
*
|
|
156
202
|
* @since 1.2.0
|
|
157
203
|
*/
|
|
158
|
-
type StringPromptConfig = TextConfig | PasswordConfig | SelectConfig;
|
|
204
|
+
type StringPromptConfig = TextConfig | PasswordConfig | SelectConfig | AutocompleteConfig;
|
|
159
205
|
/**
|
|
160
206
|
* Type-safe Clack prompt configuration for a given parser value type `T`.
|
|
161
207
|
*
|
|
@@ -163,7 +209,7 @@ type StringPromptConfig = TextConfig | PasswordConfig | SelectConfig;
|
|
|
163
209
|
* @since 1.3.0 Added conditional prompt skipping.
|
|
164
210
|
*/
|
|
165
211
|
type PromptConfig<T> = BasePromptConfig<Exclude<T, null | undefined>> & PromptCondition<T>;
|
|
166
|
-
type BasePromptConfig<T> = T extends boolean ? ConfirmConfig : T extends number ? NumberPromptConfig : T extends string ? StringPromptConfig : T extends readonly string[] ? MultiselectConfig : never;
|
|
212
|
+
type BasePromptConfig<T> = T extends boolean ? ConfirmConfig : T extends number ? NumberPromptConfig : T extends string ? StringPromptConfig : T extends readonly string[] ? MultiselectConfig | AutocompleteMultiselectConfig : never;
|
|
167
213
|
/**
|
|
168
214
|
* Union of every prompt configuration this package can execute,
|
|
169
215
|
* regardless of the parser value type.
|
|
@@ -175,7 +221,7 @@ type BasePromptConfig<T> = T extends boolean ? ConfirmConfig : T extends number
|
|
|
175
221
|
*
|
|
176
222
|
* @since 1.3.0
|
|
177
223
|
*/
|
|
178
|
-
type RuntimePromptConfig = ConfirmConfig | NumberPromptConfig | StringPromptConfig | MultiselectConfig;
|
|
224
|
+
type RuntimePromptConfig = ConfirmConfig | NumberPromptConfig | StringPromptConfig | MultiselectConfig | AutocompleteMultiselectConfig;
|
|
179
225
|
/**
|
|
180
226
|
* Shared prompt options and Clack's derived configuration pending indicator.
|
|
181
227
|
*
|
|
@@ -213,4 +259,4 @@ interface ClackPromptOptions<TValue> extends PromptOptions$1<TValue> {
|
|
|
213
259
|
*/
|
|
214
260
|
declare function prompt<M extends Mode, TValue, TState>(parser: Parser<M, TValue, TState>, config: PromptConfig<TValue> | DerivedPromptConfig$1<RuntimePromptConfig, NoInfer<TValue>>, options?: ClackPromptOptions<NoInfer<TValue>>): FluentParser<"async", TValue, TState>;
|
|
215
261
|
//#endregion
|
|
216
|
-
export { ClackPromptOptions, ConfirmConfig, type DerivePromptConfigContext, type DerivePromptConfigNoDepsContext, type DerivePromptConfigNoDepsOptions, type DerivePromptConfigOptions, type DerivePromptConfigsContext, type DerivePromptConfigsOptions, type DerivedPromptConfig, MultiselectConfig, NumberPromptConfig, Option, PasswordConfig, PromptConfig, type PromptExecutionContext, type PromptOptions, type PromptValidator, RuntimePromptConfig, SelectConfig, StringPromptConfig, TextConfig, derivePromptConfig, isDerivedPromptConfig, prompt };
|
|
262
|
+
export { AutocompleteConfig, AutocompleteMultiselectConfig, ClackPromptOptions, ConfirmConfig, type DerivePromptConfigContext, type DerivePromptConfigNoDepsContext, type DerivePromptConfigNoDepsOptions, type DerivePromptConfigOptions, type DerivePromptConfigsContext, type DerivePromptConfigsOptions, type DerivedPromptConfig, MultiselectConfig, NumberPromptConfig, Option, PasswordConfig, PromptConfig, type PromptExecutionContext, type PromptOptions, type PromptValidator, RuntimePromptConfig, SelectConfig, StringPromptConfig, TextConfig, derivePromptConfig, isDerivedPromptConfig, prompt };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { Mode, Parser } from "@optique/core/parser";
|
|
|
5
5
|
//#region src/index.d.ts
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* A choice item for
|
|
8
|
+
* A choice item for selection and autocomplete prompts.
|
|
9
9
|
*
|
|
10
10
|
* @since 1.2.0
|
|
11
11
|
*/
|
|
@@ -150,12 +150,58 @@ interface MultiselectConfig {
|
|
|
150
150
|
*/
|
|
151
151
|
readonly prompter?: (context: PromptExecutionContext$1) => Promise<readonly string[]>;
|
|
152
152
|
}
|
|
153
|
+
/** Shared settings for filtering a list of options. */
|
|
154
|
+
interface AutocompleteSettings {
|
|
155
|
+
/** The question to display to the user. */
|
|
156
|
+
readonly message: string;
|
|
157
|
+
/** Available options. Use a derived config to load them lazily. */
|
|
158
|
+
readonly options: readonly (string | Option)[];
|
|
159
|
+
/** Hint text shown when the search input is empty. */
|
|
160
|
+
readonly placeholder?: string;
|
|
161
|
+
/** Maximum number of options displayed at once. */
|
|
162
|
+
readonly maxItems?: number;
|
|
163
|
+
/** Matches search input against a normalized option. */
|
|
164
|
+
readonly filter?: (search: string, option: Option) => boolean;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Configuration for an `autocomplete` prompt that filters a local list.
|
|
168
|
+
*
|
|
169
|
+
* @since 1.4.0
|
|
170
|
+
*/
|
|
171
|
+
interface AutocompleteConfig extends AutocompleteSettings {
|
|
172
|
+
readonly type: "autocomplete";
|
|
173
|
+
/** Initially selected option value. */
|
|
174
|
+
readonly initialValue?: string;
|
|
175
|
+
/** Initial text in the search input. */
|
|
176
|
+
readonly initialUserInput?: string;
|
|
177
|
+
/** Synchronous validation of the selected value inside the prompt. */
|
|
178
|
+
readonly validate?: (value: string) => string | void;
|
|
179
|
+
/** Overrides prompt execution. Useful for testing. */
|
|
180
|
+
readonly prompter?: (context: PromptExecutionContext$1) => Promise<string>;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Configuration for an `autocomplete-multiselect` prompt.
|
|
184
|
+
*
|
|
185
|
+
* Use shared prompt options for validation; Clack does not run a custom
|
|
186
|
+
* validator for this prompt type.
|
|
187
|
+
*
|
|
188
|
+
* @since 1.4.0
|
|
189
|
+
*/
|
|
190
|
+
interface AutocompleteMultiselectConfig extends AutocompleteSettings {
|
|
191
|
+
readonly type: "autocomplete-multiselect";
|
|
192
|
+
/** Initially selected option values. */
|
|
193
|
+
readonly initialValues?: readonly string[];
|
|
194
|
+
/** Whether at least one option must be selected. */
|
|
195
|
+
readonly required?: boolean;
|
|
196
|
+
/** Overrides prompt execution. Useful for testing. */
|
|
197
|
+
readonly prompter?: (context: PromptExecutionContext$1) => Promise<readonly string[]>;
|
|
198
|
+
}
|
|
153
199
|
/**
|
|
154
200
|
* A union of all string-valued prompt configurations.
|
|
155
201
|
*
|
|
156
202
|
* @since 1.2.0
|
|
157
203
|
*/
|
|
158
|
-
type StringPromptConfig = TextConfig | PasswordConfig | SelectConfig;
|
|
204
|
+
type StringPromptConfig = TextConfig | PasswordConfig | SelectConfig | AutocompleteConfig;
|
|
159
205
|
/**
|
|
160
206
|
* Type-safe Clack prompt configuration for a given parser value type `T`.
|
|
161
207
|
*
|
|
@@ -163,7 +209,7 @@ type StringPromptConfig = TextConfig | PasswordConfig | SelectConfig;
|
|
|
163
209
|
* @since 1.3.0 Added conditional prompt skipping.
|
|
164
210
|
*/
|
|
165
211
|
type PromptConfig<T> = BasePromptConfig<Exclude<T, null | undefined>> & PromptCondition<T>;
|
|
166
|
-
type BasePromptConfig<T> = T extends boolean ? ConfirmConfig : T extends number ? NumberPromptConfig : T extends string ? StringPromptConfig : T extends readonly string[] ? MultiselectConfig : never;
|
|
212
|
+
type BasePromptConfig<T> = T extends boolean ? ConfirmConfig : T extends number ? NumberPromptConfig : T extends string ? StringPromptConfig : T extends readonly string[] ? MultiselectConfig | AutocompleteMultiselectConfig : never;
|
|
167
213
|
/**
|
|
168
214
|
* Union of every prompt configuration this package can execute,
|
|
169
215
|
* regardless of the parser value type.
|
|
@@ -175,7 +221,7 @@ type BasePromptConfig<T> = T extends boolean ? ConfirmConfig : T extends number
|
|
|
175
221
|
*
|
|
176
222
|
* @since 1.3.0
|
|
177
223
|
*/
|
|
178
|
-
type RuntimePromptConfig = ConfirmConfig | NumberPromptConfig | StringPromptConfig | MultiselectConfig;
|
|
224
|
+
type RuntimePromptConfig = ConfirmConfig | NumberPromptConfig | StringPromptConfig | MultiselectConfig | AutocompleteMultiselectConfig;
|
|
179
225
|
/**
|
|
180
226
|
* Shared prompt options and Clack's derived configuration pending indicator.
|
|
181
227
|
*
|
|
@@ -213,4 +259,4 @@ interface ClackPromptOptions<TValue> extends PromptOptions$1<TValue> {
|
|
|
213
259
|
*/
|
|
214
260
|
declare function prompt<M extends Mode, TValue, TState>(parser: Parser<M, TValue, TState>, config: PromptConfig<TValue> | DerivedPromptConfig$1<RuntimePromptConfig, NoInfer<TValue>>, options?: ClackPromptOptions<NoInfer<TValue>>): FluentParser<"async", TValue, TState>;
|
|
215
261
|
//#endregion
|
|
216
|
-
export { ClackPromptOptions, ConfirmConfig, type DerivePromptConfigContext, type DerivePromptConfigNoDepsContext, type DerivePromptConfigNoDepsOptions, type DerivePromptConfigOptions, type DerivePromptConfigsContext, type DerivePromptConfigsOptions, type DerivedPromptConfig, MultiselectConfig, NumberPromptConfig, Option, PasswordConfig, PromptConfig, type PromptExecutionContext, type PromptOptions, type PromptValidator, RuntimePromptConfig, SelectConfig, StringPromptConfig, TextConfig, derivePromptConfig, isDerivedPromptConfig, prompt };
|
|
262
|
+
export { AutocompleteConfig, AutocompleteMultiselectConfig, ClackPromptOptions, ConfirmConfig, type DerivePromptConfigContext, type DerivePromptConfigNoDepsContext, type DerivePromptConfigNoDepsOptions, type DerivePromptConfigOptions, type DerivePromptConfigsContext, type DerivePromptConfigsOptions, type DerivedPromptConfig, MultiselectConfig, NumberPromptConfig, Option, PasswordConfig, PromptConfig, type PromptExecutionContext, type PromptOptions, type PromptValidator, RuntimePromptConfig, SelectConfig, StringPromptConfig, TextConfig, derivePromptConfig, isDerivedPromptConfig, prompt };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { confirm, isCancel, log, multiselect, password, select, spinner, text } from "@clack/prompts";
|
|
1
|
+
import { autocomplete, autocompleteMultiselect, confirm, isCancel, log, multiselect, password, select, spinner, text } from "@clack/prompts";
|
|
2
2
|
import { formatMessage, message } from "@optique/core/message";
|
|
3
3
|
import { createPromptAdapter, derivePromptConfig, isDerivedPromptConfig } from "@optique/prompt";
|
|
4
4
|
|
|
5
5
|
//#region src/index.ts
|
|
6
6
|
const promptFunctionsOverrideSymbol = Symbol.for("@optique/clack/prompt-functions");
|
|
7
7
|
const defaultPromptFunctions = {
|
|
8
|
+
autocomplete,
|
|
9
|
+
autocompleteMultiselect,
|
|
8
10
|
spinner,
|
|
9
11
|
text,
|
|
10
12
|
password,
|
|
@@ -109,7 +111,18 @@ async function executePromptRaw(config, context) {
|
|
|
109
111
|
if ("prompter" in cfg && cfg.prompter != null) result = await cfg.prompter(context);
|
|
110
112
|
else {
|
|
111
113
|
if (context.previousValidationMessage !== void 0) prompts.logError(formatMessage(context.previousValidationMessage));
|
|
112
|
-
|
|
114
|
+
const disabled = cfg.type === "autocomplete-multiselect" ? new Set(normalizeOptions(cfg.options).filter((option) => option.disabled).map((option) => option.value)) : void 0;
|
|
115
|
+
while (true) {
|
|
116
|
+
result = await executeClackPromptWithSignal(cfg, prompts, context.signal);
|
|
117
|
+
if (cfg.type !== "autocomplete-multiselect" || disabled === void 0 || !Array.isArray(result)) break;
|
|
118
|
+
const values = result.filter((value) => typeof value !== "string" || !disabled.has(value));
|
|
119
|
+
if (cfg.required === true && result.length > 0 && values.length === 0) {
|
|
120
|
+
prompts.logError("No option selected.");
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
result = values;
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
113
126
|
}
|
|
114
127
|
if (prompts.isCancel(result)) {
|
|
115
128
|
if (context.signal?.aborted === true) throw context.signal.reason;
|
|
@@ -119,7 +132,11 @@ async function executePromptRaw(config, context) {
|
|
|
119
132
|
};
|
|
120
133
|
}
|
|
121
134
|
if (cfg.type === "number") return normalizeNumberResult(result);
|
|
122
|
-
if (cfg.type === "
|
|
135
|
+
if (cfg.type === "autocomplete" && typeof result !== "string") return {
|
|
136
|
+
success: false,
|
|
137
|
+
error: message`No option selected.`
|
|
138
|
+
};
|
|
139
|
+
if (cfg.type === "multiselect" || cfg.type === "autocomplete-multiselect") return normalizeMultiselectResult(result, cfg);
|
|
123
140
|
return {
|
|
124
141
|
success: true,
|
|
125
142
|
value: result
|
|
@@ -138,7 +155,7 @@ async function executeClackPromptWithSignal(cfg, prompts, signal) {
|
|
|
138
155
|
}
|
|
139
156
|
}
|
|
140
157
|
function isPromptType(value) {
|
|
141
|
-
return value === "text" || value === "password" || value === "confirm" || value === "number" || value === "select" || value === "multiselect";
|
|
158
|
+
return value === "text" || value === "password" || value === "confirm" || value === "number" || value === "select" || value === "multiselect" || value === "autocomplete" || value === "autocomplete-multiselect";
|
|
142
159
|
}
|
|
143
160
|
function executeClackPrompt(cfg, prompts, signal) {
|
|
144
161
|
switch (cfg.type) {
|
|
@@ -179,6 +196,34 @@ function executeClackPrompt(cfg, prompts, signal) {
|
|
|
179
196
|
options: normalizeOptions(cfg.options),
|
|
180
197
|
...cfg.initialValue !== void 0 ? { initialValue: cfg.initialValue } : {}
|
|
181
198
|
});
|
|
199
|
+
case "autocomplete": {
|
|
200
|
+
const options = normalizeOptions(cfg.options);
|
|
201
|
+
return prompts.autocomplete({
|
|
202
|
+
message: cfg.message,
|
|
203
|
+
options,
|
|
204
|
+
...signal === void 0 ? {} : { signal },
|
|
205
|
+
...cfg.initialValue === void 0 ? {} : { initialValue: cfg.initialValue },
|
|
206
|
+
...cfg.initialUserInput === void 0 ? {} : { initialUserInput: cfg.initialUserInput },
|
|
207
|
+
...cfg.placeholder === void 0 ? {} : { placeholder: cfg.placeholder },
|
|
208
|
+
...cfg.maxItems === void 0 ? {} : { maxItems: cfg.maxItems },
|
|
209
|
+
...cfg.filter === void 0 ? {} : { filter: cfg.filter },
|
|
210
|
+
validate: (value) => {
|
|
211
|
+
if (typeof value !== "string") return "No option selected.";
|
|
212
|
+
if (options.some((option) => option.value === value && option.disabled)) return "Option is unavailable.";
|
|
213
|
+
return cfg.validate?.(value) ?? void 0;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
case "autocomplete-multiselect": return prompts.autocompleteMultiselect({
|
|
218
|
+
message: cfg.message,
|
|
219
|
+
options: normalizeOptions(cfg.options),
|
|
220
|
+
...signal === void 0 ? {} : { signal },
|
|
221
|
+
...cfg.initialValues === void 0 ? {} : { initialValues: [...cfg.initialValues] },
|
|
222
|
+
...cfg.required === void 0 ? {} : { required: cfg.required },
|
|
223
|
+
...cfg.placeholder === void 0 ? {} : { placeholder: cfg.placeholder },
|
|
224
|
+
...cfg.maxItems === void 0 ? {} : { maxItems: cfg.maxItems },
|
|
225
|
+
...cfg.filter === void 0 ? {} : { filter: cfg.filter }
|
|
226
|
+
});
|
|
182
227
|
case "multiselect": return prompts.multiselect({
|
|
183
228
|
message: cfg.message,
|
|
184
229
|
...signal === void 0 ? {} : { signal },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/clack",
|
|
3
|
-
"version": "1.4.0-dev.
|
|
3
|
+
"version": "1.4.0-dev.2729",
|
|
4
4
|
"description": "Interactive prompt support for Optique via Clack",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -62,12 +62,12 @@
|
|
|
62
62
|
"sideEffects": false,
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@clack/prompts": "^1.6.0",
|
|
65
|
-
"@optique/core": "1.4.0-dev.
|
|
66
|
-
"@optique/prompt": "1.4.0-dev.
|
|
65
|
+
"@optique/core": "1.4.0-dev.2729+72048695",
|
|
66
|
+
"@optique/prompt": "1.4.0-dev.2729+72048695"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@optique/env": "1.4.0-dev.
|
|
70
|
-
"@optique/run": "1.4.0-dev.
|
|
69
|
+
"@optique/env": "1.4.0-dev.2729+72048695",
|
|
70
|
+
"@optique/run": "1.4.0-dev.2729+72048695",
|
|
71
71
|
"@types/node": "^24.0.0",
|
|
72
72
|
"fast-check": "^4.7.0",
|
|
73
73
|
"tsdown": "^0.13.0",
|