@inquirer/core 8.0.1 → 8.2.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.
- package/dist/cjs/lib/Separator.js +1 -1
- package/dist/cjs/lib/create-prompt.js +4 -4
- package/dist/cjs/lib/hook-engine.js +1 -0
- package/dist/cjs/lib/make-theme.js +27 -3
- package/dist/cjs/lib/pagination/lines.js +2 -2
- package/dist/cjs/lib/screen-manager.js +1 -1
- package/dist/cjs/types/lib/make-theme.d.ts +1 -1
- package/dist/cjs/types/lib/theme.d.ts +1 -1
- package/dist/cjs/types/lib/use-ref.d.ts +3 -0
- package/dist/cjs/types/lib/use-state.d.ts +1 -0
- package/dist/esm/lib/Separator.mjs +1 -1
- package/dist/esm/lib/create-prompt.mjs +4 -4
- package/dist/esm/lib/hook-engine.mjs +1 -0
- package/dist/esm/lib/make-theme.mjs +27 -3
- package/dist/esm/lib/pagination/lines.mjs +2 -2
- package/dist/esm/lib/screen-manager.mjs +1 -1
- package/dist/esm/types/lib/make-theme.d.mts +1 -1
- package/dist/esm/types/lib/theme.d.mts +1 -1
- package/dist/esm/types/lib/use-ref.d.mts +3 -0
- package/dist/esm/types/lib/use-state.d.mts +1 -0
- package/package.json +5 -5
|
@@ -16,7 +16,7 @@ class Separator {
|
|
|
16
16
|
enumerable: true,
|
|
17
17
|
configurable: true,
|
|
18
18
|
writable: true,
|
|
19
|
-
value: chalk_1.default.dim(
|
|
19
|
+
value: chalk_1.default.dim(Array.from({ length: 15 }).join(figures_1.default.line))
|
|
20
20
|
});
|
|
21
21
|
Object.defineProperty(this, "type", {
|
|
22
22
|
enumerable: true,
|
|
@@ -64,8 +64,8 @@ function createPrompt(view) {
|
|
|
64
64
|
cleanFn === null || cleanFn === void 0 ? void 0 : cleanFn();
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
|
-
catch (
|
|
68
|
-
reject(
|
|
67
|
+
catch (error) {
|
|
68
|
+
reject(error);
|
|
69
69
|
}
|
|
70
70
|
if (context === null || context === void 0 ? void 0 : context.clearPromptOnDone) {
|
|
71
71
|
screen.clean();
|
|
@@ -98,9 +98,9 @@ function createPrompt(view) {
|
|
|
98
98
|
screen.render(content, bottomContent);
|
|
99
99
|
hook_engine_mjs_1.effectScheduler.run();
|
|
100
100
|
}
|
|
101
|
-
catch (
|
|
101
|
+
catch (error) {
|
|
102
102
|
onExit();
|
|
103
|
-
reject(
|
|
103
|
+
reject(error);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
workLoop(config);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint @typescript-eslint/no-explicit-any: ["off"] */
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.effectScheduler = exports.handleChange = exports.withPointer = exports.withUpdates = exports.readline = exports.withHooks = void 0;
|
|
4
5
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
@@ -2,9 +2,33 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeTheme = void 0;
|
|
4
4
|
const theme_mjs_1 = require('./theme.js');
|
|
5
|
+
function isPlainObject(value) {
|
|
6
|
+
if (typeof value !== 'object' || value === null)
|
|
7
|
+
return false;
|
|
8
|
+
let proto = value;
|
|
9
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
10
|
+
proto = Object.getPrototypeOf(proto);
|
|
11
|
+
}
|
|
12
|
+
return Object.getPrototypeOf(value) === proto;
|
|
13
|
+
}
|
|
14
|
+
function deepMerge(...objects) {
|
|
15
|
+
const output = {};
|
|
16
|
+
for (const obj of objects) {
|
|
17
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
18
|
+
const prevValue = output[key];
|
|
19
|
+
output[key] =
|
|
20
|
+
isPlainObject(prevValue) && isPlainObject(value)
|
|
21
|
+
? deepMerge(prevValue, value)
|
|
22
|
+
: value;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return output;
|
|
26
|
+
}
|
|
5
27
|
function makeTheme(...themes) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
28
|
+
const themesToMerge = [
|
|
29
|
+
theme_mjs_1.defaultTheme,
|
|
30
|
+
...themes.filter((theme) => theme != null),
|
|
31
|
+
];
|
|
32
|
+
return deepMerge(...themesToMerge);
|
|
9
33
|
}
|
|
10
34
|
exports.makeTheme = makeTheme;
|
|
@@ -13,7 +13,7 @@ function split(content, width) {
|
|
|
13
13
|
function rotate(count, items) {
|
|
14
14
|
const max = items.length;
|
|
15
15
|
const offset = ((count % max) + max) % max;
|
|
16
|
-
return items.slice(offset)
|
|
16
|
+
return [...items.slice(offset), ...items.slice(0, offset)];
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* Renders a page of items as lines that fit within the given width ensuring
|
|
@@ -30,7 +30,7 @@ function lines({ items, width, renderItem, active, position: requested, pageSize
|
|
|
30
30
|
const layoutsInPage = rotate(active - requested, layouts).slice(0, pageSize);
|
|
31
31
|
const renderItemAt = (index) => split(renderItem(layoutsInPage[index]), width);
|
|
32
32
|
// Create a blank array of lines for the page
|
|
33
|
-
const pageBuffer =
|
|
33
|
+
const pageBuffer = Array.from({ length: pageSize });
|
|
34
34
|
// Render the active item to decide the position
|
|
35
35
|
const activeItem = renderItemAt(requested).slice(0, pageSize);
|
|
36
36
|
const position = requested + activeItem.length <= pageSize ? requested : pageSize - activeItem.length;
|
|
@@ -48,7 +48,7 @@ class ScreenManager {
|
|
|
48
48
|
// rl.line (mainly because of the password prompt), so just rely on it's
|
|
49
49
|
// length.
|
|
50
50
|
let prompt = rawPromptLine;
|
|
51
|
-
if (this.rl.line.length) {
|
|
51
|
+
if (this.rl.line.length > 0) {
|
|
52
52
|
prompt = prompt.slice(0, -this.rl.line.length);
|
|
53
53
|
}
|
|
54
54
|
this.rl.setPrompt(prompt);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Prettify, PartialDeep } from '@inquirer/type';
|
|
2
2
|
import { type Theme } from './theme.js';
|
|
3
|
-
export declare function makeTheme<SpecificTheme extends
|
|
3
|
+
export declare function makeTheme<SpecificTheme extends object>(...themes: ReadonlyArray<undefined | PartialDeep<Theme<SpecificTheme>>>): Prettify<Theme<SpecificTheme>>;
|
|
@@ -15,6 +15,6 @@ type DefaultTheme = {
|
|
|
15
15
|
key: (text: string) => string;
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
|
-
export type Theme<Extension extends
|
|
18
|
+
export type Theme<Extension extends object = object> = Prettify<Extension & DefaultTheme>;
|
|
19
19
|
export declare const defaultTheme: DefaultTheme;
|
|
20
20
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
type NotFunction<T> = T extends Function ? never : T;
|
|
2
2
|
export declare function useState<Value>(defaultValue: NotFunction<Value> | (() => Value)): [Value, (newValue: Value) => void];
|
|
3
|
+
export declare function useState<Value>(defaultValue?: NotFunction<Value> | (() => Value)): [Value | undefined, (newValue?: Value | undefined) => void];
|
|
3
4
|
export {};
|
|
@@ -5,7 +5,7 @@ import figures from '@inquirer/figures';
|
|
|
5
5
|
* Used to space/separate choices group
|
|
6
6
|
*/
|
|
7
7
|
export class Separator {
|
|
8
|
-
separator = chalk.dim(
|
|
8
|
+
separator = chalk.dim(Array.from({ length: 15 }).join(figures.line));
|
|
9
9
|
type = 'separator';
|
|
10
10
|
constructor(separator) {
|
|
11
11
|
if (separator) {
|
|
@@ -34,8 +34,8 @@ export function createPrompt(view) {
|
|
|
34
34
|
cleanFn?.();
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
-
catch (
|
|
38
|
-
reject(
|
|
37
|
+
catch (error) {
|
|
38
|
+
reject(error);
|
|
39
39
|
}
|
|
40
40
|
if (context?.clearPromptOnDone) {
|
|
41
41
|
screen.clean();
|
|
@@ -68,9 +68,9 @@ export function createPrompt(view) {
|
|
|
68
68
|
screen.render(content, bottomContent);
|
|
69
69
|
effectScheduler.run();
|
|
70
70
|
}
|
|
71
|
-
catch (
|
|
71
|
+
catch (error) {
|
|
72
72
|
onExit();
|
|
73
|
-
reject(
|
|
73
|
+
reject(error);
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
workLoop(config);
|
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
import { defaultTheme } from './theme.mjs';
|
|
2
|
+
function isPlainObject(value) {
|
|
3
|
+
if (typeof value !== 'object' || value === null)
|
|
4
|
+
return false;
|
|
5
|
+
let proto = value;
|
|
6
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
7
|
+
proto = Object.getPrototypeOf(proto);
|
|
8
|
+
}
|
|
9
|
+
return Object.getPrototypeOf(value) === proto;
|
|
10
|
+
}
|
|
11
|
+
function deepMerge(...objects) {
|
|
12
|
+
const output = {};
|
|
13
|
+
for (const obj of objects) {
|
|
14
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
15
|
+
const prevValue = output[key];
|
|
16
|
+
output[key] =
|
|
17
|
+
isPlainObject(prevValue) && isPlainObject(value)
|
|
18
|
+
? deepMerge(prevValue, value)
|
|
19
|
+
: value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return output;
|
|
23
|
+
}
|
|
2
24
|
export function makeTheme(...themes) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
25
|
+
const themesToMerge = [
|
|
26
|
+
defaultTheme,
|
|
27
|
+
...themes.filter((theme) => theme != null),
|
|
28
|
+
];
|
|
29
|
+
return deepMerge(...themesToMerge);
|
|
6
30
|
}
|
|
@@ -10,7 +10,7 @@ function split(content, width) {
|
|
|
10
10
|
function rotate(count, items) {
|
|
11
11
|
const max = items.length;
|
|
12
12
|
const offset = ((count % max) + max) % max;
|
|
13
|
-
return items.slice(offset)
|
|
13
|
+
return [...items.slice(offset), ...items.slice(0, offset)];
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Renders a page of items as lines that fit within the given width ensuring
|
|
@@ -27,7 +27,7 @@ export function lines({ items, width, renderItem, active, position: requested, p
|
|
|
27
27
|
const layoutsInPage = rotate(active - requested, layouts).slice(0, pageSize);
|
|
28
28
|
const renderItemAt = (index) => split(renderItem(layoutsInPage[index]), width);
|
|
29
29
|
// Create a blank array of lines for the page
|
|
30
|
-
const pageBuffer =
|
|
30
|
+
const pageBuffer = Array.from({ length: pageSize });
|
|
31
31
|
// Render the active item to decide the position
|
|
32
32
|
const activeItem = renderItemAt(requested).slice(0, pageSize);
|
|
33
33
|
const position = requested + activeItem.length <= pageSize ? requested : pageSize - activeItem.length;
|
|
@@ -24,7 +24,7 @@ export default class ScreenManager {
|
|
|
24
24
|
// rl.line (mainly because of the password prompt), so just rely on it's
|
|
25
25
|
// length.
|
|
26
26
|
let prompt = rawPromptLine;
|
|
27
|
-
if (this.rl.line.length) {
|
|
27
|
+
if (this.rl.line.length > 0) {
|
|
28
28
|
prompt = prompt.slice(0, -this.rl.line.length);
|
|
29
29
|
}
|
|
30
30
|
this.rl.setPrompt(prompt);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Prettify, PartialDeep } from '@inquirer/type';
|
|
2
2
|
import { type Theme } from './theme.mjs';
|
|
3
|
-
export declare function makeTheme<SpecificTheme extends
|
|
3
|
+
export declare function makeTheme<SpecificTheme extends object>(...themes: ReadonlyArray<undefined | PartialDeep<Theme<SpecificTheme>>>): Prettify<Theme<SpecificTheme>>;
|
|
@@ -15,6 +15,6 @@ type DefaultTheme = {
|
|
|
15
15
|
key: (text: string) => string;
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
|
-
export type Theme<Extension extends
|
|
18
|
+
export type Theme<Extension extends object = object> = Prettify<Extension & DefaultTheme>;
|
|
19
19
|
export declare const defaultTheme: DefaultTheme;
|
|
20
20
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
type NotFunction<T> = T extends Function ? never : T;
|
|
2
2
|
export declare function useState<Value>(defaultValue: NotFunction<Value> | (() => Value)): [Value, (newValue: Value) => void];
|
|
3
|
+
export declare function useState<Value>(defaultValue?: NotFunction<Value> | (() => Value)): [Value | undefined, (newValue?: Value | undefined) => void];
|
|
3
4
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/core",
|
|
3
|
-
"version": "8.0
|
|
3
|
+
"version": "8.2.0",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=18"
|
|
6
6
|
},
|
|
@@ -58,9 +58,9 @@
|
|
|
58
58
|
"homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/core/README.md",
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@inquirer/figures": "^1.0.1",
|
|
61
|
-
"@inquirer/type": "^1.3.
|
|
61
|
+
"@inquirer/type": "^1.3.1",
|
|
62
62
|
"@types/mute-stream": "^0.0.4",
|
|
63
|
-
"@types/node": "^20.12.
|
|
63
|
+
"@types/node": "^20.12.11",
|
|
64
64
|
"@types/wrap-ansi": "^3.0.0",
|
|
65
65
|
"ansi-escapes": "^4.3.2",
|
|
66
66
|
"chalk": "^4.1.2",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"wrap-ansi": "^6.2.0"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@inquirer/testing": "^2.1.
|
|
75
|
+
"@inquirer/testing": "^2.1.19"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"tsc": "yarn run tsc:esm && yarn run tsc:cjs",
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
},
|
|
98
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "27d1c0ae9e88edbc9bebcf58901a5104022074a9"
|
|
99
99
|
}
|