@jakubmazanec/cli 0.3.5-unstable.91147a2 → 0.3.5-unstable.9aff2d1

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.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  import fs from "fs-extra";
3
3
  import fetchLatestVersion from "latest-version";
4
- import path from "path";
4
+ import path from "node:path";
5
5
  import { CACHE_PATH } from "../constants.js";
6
6
  import { Failure, Help } from "../ui.js";
7
7
  import { Wrapper } from "../ui/internals.js";
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../source/program/Program.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any -- needed */\nimport {type Argv, type OptionsConfig, type ParametersConfig} from '@jakubmazanec/args';\nimport fs from 'fs-extra';\nimport fetchLatestVersion from 'latest-version';\nimport path from 'path';\nimport {type ComponentType} from 'react';\nimport {type FallbackProps} from 'react-error-boundary';\n\nimport {CACHE_PATH} from '../constants.js';\nimport {Failure, Help} from '../ui.js';\nimport {Wrapper} from '../ui/internals.js';\nimport {type Command} from './Command.js';\nimport {type ProgramCreateOptions} from './ProgramCreateOptions.js';\nimport {ProgramError} from './ProgramError.js';\nimport {type ProgramOptions} from './ProgramOptions.js';\nimport {type ProgramStreams} from './ProgramStreams.js';\n\n/**\n * Program manages and executes {@link Command} instances attached to it based on parsing command line arguments.\n */\nexport class Program {\n /** Program name. */\n readonly name?: string;\n\n /** More readable program name. */\n readonly displayName?: string;\n\n /** Program version. */\n readonly version?: string;\n\n /** Program latest version. */\n readonly latestVersion?: string;\n\n /** Program description. */\n readonly description?: string;\n\n /** Program executable name. */\n readonly bin?: string;\n\n /** Program commands */\n readonly commands: Array<\n Command<string, ParametersConfig | undefined, OptionsConfig | undefined, boolean, boolean>\n > = [];\n\n protected isRendering = false;\n\n readonly streams: ProgramStreams = {\n stderr: process.stderr,\n stdin: process.stdin,\n stdout: process.stdout,\n };\n\n /** Custom error boundary fallback component */\n ErrorBoundaryFallbackComponent: ComponentType<FallbackProps>;\n\n private constructor({\n name,\n displayName,\n version,\n latestVersion,\n description,\n bin,\n ErrorBoundaryFallbackComponent,\n }: ProgramOptions) {\n if (name) {\n this.name = name;\n }\n\n if (displayName) {\n this.displayName = displayName;\n }\n\n if (version) {\n this.version = version;\n }\n\n if (latestVersion) {\n this.latestVersion = latestVersion;\n }\n\n if (description) {\n this.description = description;\n }\n\n if (bin) {\n this.bin = bin;\n }\n\n if (ErrorBoundaryFallbackComponent) {\n this.ErrorBoundaryFallbackComponent = ErrorBoundaryFallbackComponent;\n } else {\n this.ErrorBoundaryFallbackComponent = Failure;\n }\n }\n\n static async create({\n name,\n version,\n description,\n bin,\n ErrorBoundaryFallbackComponent,\n checkForUpdate,\n }: ProgramCreateOptions) {\n let latestVersion: string | undefined;\n\n if (checkForUpdate && name) {\n // first we try to read the cached latest version\n type CachedLatestVersion = {\n value: string;\n datetime: number;\n };\n\n let cachePath = path.join(CACHE_PATH, name, 'latest-version.json');\n let cachedLatestVersion: CachedLatestVersion | undefined;\n\n try {\n cachedLatestVersion = (await fs.readJson(cachePath)) as CachedLatestVersion;\n } catch {\n // no-op\n }\n\n // if there is no cache or the cached value is old, refetch and recache\n if (!cachedLatestVersion || Date.now() - cachedLatestVersion.datetime > 86_400_00) {\n latestVersion = await fetchLatestVersion(name);\n\n await fs.ensureFile(cachePath);\n await fs.writeJson(cachePath, {\n value: latestVersion,\n datetime: Date.now(),\n });\n }\n }\n\n return new this({\n name,\n version,\n latestVersion,\n description,\n bin,\n ErrorBoundaryFallbackComponent,\n });\n }\n\n /**\n * Adds command to the program.\n *\n * @param command Command to add.\n * @returns Program instance.\n */\n addCommand(command: Command<any, any, any, any, any>): this {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- it doesn't matter here; `any` is used to make TypeScript happy in this method, but isn't propagated further.\n this.commands.push(command);\n\n return this;\n }\n\n /**\n * Renders a React element using Ink and outputs to the configured streams.\n *\n * @param element The React element to render.\n */\n async renderElement(element: React.ReactElement): Promise<void> {\n if (this.isRendering) {\n throw new ProgramError('NO_NESTED_RENDER');\n } else {\n this.isRendering = true;\n }\n\n let {render} = await import('ink');\n let {createElement} = await import('react');\n let {stdin, stdout, stderr} = this.streams;\n\n try {\n render(createElement(Wrapper, {program: this}, element), {\n exitOnCtrlC: true,\n patchConsole: true,\n stderr,\n stdin,\n stdout,\n });\n } catch (error: unknown) {\n if (error instanceof Error) {\n await this.renderElement(\n createElement(this.ErrorBoundaryFallbackComponent, {error, resetErrorBoundary: () => {}}),\n );\n }\n } finally {\n this.isRendering = false;\n }\n }\n\n /**\n * Runs the program.\n *\n * @param argv Unparsed command line arguments.\n */\n async run(argv: Argv): Promise<void> {\n let hasCommandRun = false;\n\n for (let command of this.commands) {\n let parsedArgs = command.parseArguments(argv);\n\n if (parsedArgs.command) {\n hasCommandRun = true;\n\n if (parsedArgs.errors.length) {\n let {createElement} = await import('react');\n\n for (let error of parsedArgs.errors) {\n process.exitCode = 1;\n\n await this.renderElement(\n createElement(this.ErrorBoundaryFallbackComponent, {\n error,\n resetErrorBoundary: () => {},\n }),\n );\n }\n } else {\n try {\n await command.run(parsedArgs, this);\n } catch (error: unknown) {\n let {createElement} = await import('react');\n\n if (error instanceof Error) {\n process.exitCode = 1;\n\n await this.renderElement(\n createElement(this.ErrorBoundaryFallbackComponent, {\n error,\n resetErrorBoundary: () => {},\n }),\n );\n }\n }\n\n break;\n }\n }\n }\n\n if (!hasCommandRun) {\n let {createElement} = await import('react');\n\n await this.renderElement(createElement(Help, {program: this}));\n }\n }\n}\n"],
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any -- needed */\nimport {type Argv, type OptionsConfig, type ParametersConfig} from '@jakubmazanec/args';\nimport fs from 'fs-extra';\nimport fetchLatestVersion from 'latest-version';\nimport path from 'node:path';\nimport {type ComponentType} from 'react';\nimport {type FallbackProps} from 'react-error-boundary';\n\nimport {CACHE_PATH} from '../constants.js';\nimport {Failure, Help} from '../ui.js';\nimport {Wrapper} from '../ui/internals.js';\nimport {type Command} from './Command.js';\nimport {type ProgramCreateOptions} from './ProgramCreateOptions.js';\nimport {ProgramError} from './ProgramError.js';\nimport {type ProgramOptions} from './ProgramOptions.js';\nimport {type ProgramStreams} from './ProgramStreams.js';\n\n/**\n * Program manages and executes {@link Command} instances attached to it based on parsing command line arguments.\n */\nexport class Program {\n /** Program name. */\n readonly name?: string;\n\n /** More readable program name. */\n readonly displayName?: string;\n\n /** Program version. */\n readonly version?: string;\n\n /** Program latest version. */\n readonly latestVersion?: string;\n\n /** Program description. */\n readonly description?: string;\n\n /** Program executable name. */\n readonly bin?: string;\n\n /** Program commands */\n readonly commands: Array<\n Command<string, ParametersConfig | undefined, OptionsConfig | undefined, boolean, boolean>\n > = [];\n\n protected isRendering = false;\n\n readonly streams: ProgramStreams = {\n stderr: process.stderr,\n stdin: process.stdin,\n stdout: process.stdout,\n };\n\n /** Custom error boundary fallback component */\n ErrorBoundaryFallbackComponent: ComponentType<FallbackProps>;\n\n private constructor({\n name,\n displayName,\n version,\n latestVersion,\n description,\n bin,\n ErrorBoundaryFallbackComponent,\n }: ProgramOptions) {\n if (name) {\n this.name = name;\n }\n\n if (displayName) {\n this.displayName = displayName;\n }\n\n if (version) {\n this.version = version;\n }\n\n if (latestVersion) {\n this.latestVersion = latestVersion;\n }\n\n if (description) {\n this.description = description;\n }\n\n if (bin) {\n this.bin = bin;\n }\n\n if (ErrorBoundaryFallbackComponent) {\n this.ErrorBoundaryFallbackComponent = ErrorBoundaryFallbackComponent;\n } else {\n this.ErrorBoundaryFallbackComponent = Failure;\n }\n }\n\n static async create({\n name,\n version,\n description,\n bin,\n ErrorBoundaryFallbackComponent,\n checkForUpdate,\n }: ProgramCreateOptions) {\n let latestVersion: string | undefined;\n\n if (checkForUpdate && name) {\n // first we try to read the cached latest version\n type CachedLatestVersion = {\n value: string;\n datetime: number;\n };\n\n let cachePath = path.join(CACHE_PATH, name, 'latest-version.json');\n let cachedLatestVersion: CachedLatestVersion | undefined;\n\n try {\n cachedLatestVersion = (await fs.readJson(cachePath)) as CachedLatestVersion;\n } catch {\n // no-op\n }\n\n // if there is no cache or the cached value is old, refetch and recache\n if (!cachedLatestVersion || Date.now() - cachedLatestVersion.datetime > 86_400_00) {\n latestVersion = await fetchLatestVersion(name);\n\n await fs.ensureFile(cachePath);\n await fs.writeJson(cachePath, {\n value: latestVersion,\n datetime: Date.now(),\n });\n }\n }\n\n return new this({\n name,\n version,\n latestVersion,\n description,\n bin,\n ErrorBoundaryFallbackComponent,\n });\n }\n\n /**\n * Adds command to the program.\n *\n * @param command Command to add.\n * @returns Program instance.\n */\n addCommand(command: Command<any, any, any, any, any>): this {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- it doesn't matter here; `any` is used to make TypeScript happy in this method, but isn't propagated further.\n this.commands.push(command);\n\n return this;\n }\n\n /**\n * Renders a React element using Ink and outputs to the configured streams.\n *\n * @param element The React element to render.\n */\n async renderElement(element: React.ReactElement): Promise<void> {\n if (this.isRendering) {\n throw new ProgramError('NO_NESTED_RENDER');\n } else {\n this.isRendering = true;\n }\n\n let {render} = await import('ink');\n let {createElement} = await import('react');\n let {stdin, stdout, stderr} = this.streams;\n\n try {\n render(createElement(Wrapper, {program: this}, element), {\n exitOnCtrlC: true,\n patchConsole: true,\n stderr,\n stdin,\n stdout,\n });\n } catch (error: unknown) {\n if (error instanceof Error) {\n await this.renderElement(\n createElement(this.ErrorBoundaryFallbackComponent, {error, resetErrorBoundary: () => {}}),\n );\n }\n } finally {\n this.isRendering = false;\n }\n }\n\n /**\n * Runs the program.\n *\n * @param argv Unparsed command line arguments.\n */\n async run(argv: Argv): Promise<void> {\n let hasCommandRun = false;\n\n for (let command of this.commands) {\n let parsedArgs = command.parseArguments(argv);\n\n if (parsedArgs.command) {\n hasCommandRun = true;\n\n if (parsedArgs.errors.length) {\n let {createElement} = await import('react');\n\n for (let error of parsedArgs.errors) {\n process.exitCode = 1;\n\n await this.renderElement(\n createElement(this.ErrorBoundaryFallbackComponent, {\n error,\n resetErrorBoundary: () => {},\n }),\n );\n }\n } else {\n try {\n await command.run(parsedArgs, this);\n } catch (error: unknown) {\n let {createElement} = await import('react');\n\n if (error instanceof Error) {\n process.exitCode = 1;\n\n await this.renderElement(\n createElement(this.ErrorBoundaryFallbackComponent, {\n error,\n resetErrorBoundary: () => {},\n }),\n );\n }\n }\n\n break;\n }\n }\n }\n\n if (!hasCommandRun) {\n let {createElement} = await import('react');\n\n await this.renderElement(createElement(Help, {program: this}));\n }\n }\n}\n"],
5
5
  "mappings": ";AAEA,OAAO,QAAQ;AACf,OAAO,wBAAwB;AAC/B,OAAO,UAAU;AAIjB,SAAQ,kBAAiB;AACzB,SAAQ,SAAS,YAAW;AAC5B,SAAQ,eAAc;AAGtB,SAAQ,oBAAmB;AAOpB,aAAM,QAAQ;AAAA;AAAA,EAEV;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA,WAEL,CAAC;AAAA,EAEK,cAAc;AAAA,EAEf,UAA0B;AAAA,IACjC,QAAQ,QAAQ;AAAA,IAChB,OAAO,QAAQ;AAAA,IACf,QAAQ,QAAQ;AAAA,EAClB;AAAA;AAAA,EAGA;AAAA,EAEQ,YAAY;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAAmB;AACjB,QAAI,MAAM;AACR,WAAK,OAAO;AAAA,IACd;AAEA,QAAI,aAAa;AACf,WAAK,cAAc;AAAA,IACrB;AAEA,QAAI,SAAS;AACX,WAAK,UAAU;AAAA,IACjB;AAEA,QAAI,eAAe;AACjB,WAAK,gBAAgB;AAAA,IACvB;AAEA,QAAI,aAAa;AACf,WAAK,cAAc;AAAA,IACrB;AAEA,QAAI,KAAK;AACP,WAAK,MAAM;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AC,eAAe;AAClB,UAAI,EAAC,cAAa,IAAI,MAAM,OAAO,OAAO;AAE1C,YAAM,KAAK,cAAc,cAAc,MAAM,EAAC,SAAS,KAAI,CAAC,CAAC;AAAA,IAC/D;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,11 +1,11 @@
1
1
  export * from './program/Command.js';
2
- export * from './program/CommandAction.js';
3
- export * from './program/CommandArguments.js';
4
- export * from './program/CommandOptions.js';
2
+ export type * from './program/CommandAction.js';
3
+ export type * from './program/CommandArguments.js';
4
+ export type * from './program/CommandOptions.js';
5
5
  export * from './program/getProgramDetail.js';
6
6
  export * from './program/Program.js';
7
- export * from './program/ProgramCreateOptions.js';
8
- export * from './program/ProgramDetail.js';
7
+ export type * from './program/ProgramCreateOptions.js';
8
+ export type * from './program/ProgramDetail.js';
9
9
  export * from './program/ProgramError.js';
10
- export * from './program/ProgramOptions.js';
11
- export * from './program/ProgramStreams.js';
10
+ export type * from './program/ProgramOptions.js';
11
+ export type * from './program/ProgramStreams.js';
package/build/program.js CHANGED
@@ -1,13 +1,6 @@
1
1
  "use strict";
2
2
  export * from "./program/Command.js";
3
- export * from "./program/CommandAction.js";
4
- export * from "./program/CommandArguments.js";
5
- export * from "./program/CommandOptions.js";
6
3
  export * from "./program/getProgramDetail.js";
7
4
  export * from "./program/Program.js";
8
- export * from "./program/ProgramCreateOptions.js";
9
- export * from "./program/ProgramDetail.js";
10
5
  export * from "./program/ProgramError.js";
11
- export * from "./program/ProgramOptions.js";
12
- export * from "./program/ProgramStreams.js";
13
6
  //# sourceMappingURL=program.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../source/program.ts"],
4
- "sourcesContent": ["export * from './program/Command.js';\nexport * from './program/CommandAction.js';\nexport * from './program/CommandArguments.js';\nexport * from './program/CommandOptions.js';\nexport * from './program/getProgramDetail.js';\nexport * from './program/Program.js';\nexport * from './program/ProgramCreateOptions.js';\nexport * from './program/ProgramDetail.js';\nexport * from './program/ProgramError.js';\nexport * from './program/ProgramOptions.js';\nexport * from './program/ProgramStreams.js';\n"],
5
- "mappings": ";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
4
+ "sourcesContent": ["export * from './program/Command.js';\nexport type * from './program/CommandAction.js';\nexport type * from './program/CommandArguments.js';\nexport type * from './program/CommandOptions.js';\nexport * from './program/getProgramDetail.js';\nexport * from './program/Program.js';\nexport type * from './program/ProgramCreateOptions.js';\nexport type * from './program/ProgramDetail.js';\nexport * from './program/ProgramError.js';\nexport type * from './program/ProgramOptions.js';\nexport type * from './program/ProgramStreams.js';\n"],
5
+ "mappings": ";AAAA,cAAc;AAId,cAAc;AACd,cAAc;AAGd,cAAc;",
6
6
  "names": []
7
7
  }
@@ -3,12 +3,12 @@ import { type ErrorDetail } from './ErrorDetail.js';
3
3
  /**
4
4
  * {@link Failure} component props.
5
5
  */
6
- export type FailureProps = {
6
+ export type FailureProps = BoxProps & {
7
7
  /** Error that describes a failure state. Function {@link getErrorDetail} is used for getting all the information from the error; you can use it to implement own retrieval logic and pass the result as `errorDetail` prop. */
8
8
  error: Error;
9
9
  /** Information about the failure state. Overrides information retireved from `error` prop. */
10
10
  errorDetail?: ErrorDetail;
11
- } & BoxProps;
11
+ };
12
12
  /**
13
13
  * A component that renders a failure state.
14
14
  */
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../source/ui/Failure.tsx"],
4
- "sourcesContent": ["import {Box, type BoxProps, Text} from 'ink';\n\nimport * as colors from './colors.js';\nimport {type ErrorDetail} from './ErrorDetail.js';\nimport {getErrorDetail} from './getErrorDetail.js';\nimport {Header} from './Header.js';\nimport * as icons from './icons.js';\n\n/**\n * {@link Failure} component props.\n */\nexport type FailureProps = {\n /** Error that describes a failure state. Function {@link getErrorDetail} is used for getting all the information from the error; you can use it to implement own retrieval logic and pass the result as `errorDetail` prop. */\n error: Error;\n\n /** Information about the failure state. Overrides information retireved from `error` prop. */\n errorDetail?: ErrorDetail;\n} & BoxProps;\n\n/**\n * A component that renders a failure state.\n */\nexport function Failure({error, errorDetail, ...boxProps}: FailureProps) {\n let {label, description, stack, cause} = errorDetail ?? getErrorDetail(error);\n\n return (\n <Box {...boxProps} flexDirection=\"column\">\n <Header icon={icons.error}>\n <Text color={colors.highlighted}>{label}</Text>\n </Header>\n\n {description ?\n <Box flexDirection=\"column\" marginLeft={2}>\n <Text color={colors.failure}>{description}</Text>\n </Box>\n : null}\n\n {stack ?\n <Box flexDirection=\"column\" marginLeft={2} marginTop={1}>\n <Text color={colors.muted}>{stack}</Text>\n </Box>\n : null}\n\n {cause ?\n <>\n <Box flexDirection=\"column\" marginLeft={2} marginTop={1}>\n <Text color={colors.muted}>{cause.description}</Text>\n </Box>\n\n {cause.stack ?\n <Box flexDirection=\"column\" marginLeft={2} marginTop={1}>\n <Text color={colors.muted}>{cause.stack}</Text>\n </Box>\n : null}\n </>\n : null}\n </Box>\n );\n}\n"],
4
+ "sourcesContent": ["import {Box, type BoxProps, Text} from 'ink';\n\nimport * as colors from './colors.js';\nimport {type ErrorDetail} from './ErrorDetail.js';\nimport {getErrorDetail} from './getErrorDetail.js';\nimport {Header} from './Header.js';\nimport * as icons from './icons.js';\n\n/**\n * {@link Failure} component props.\n */\nexport type FailureProps = BoxProps & {\n /** Error that describes a failure state. Function {@link getErrorDetail} is used for getting all the information from the error; you can use it to implement own retrieval logic and pass the result as `errorDetail` prop. */\n error: Error;\n\n /** Information about the failure state. Overrides information retireved from `error` prop. */\n errorDetail?: ErrorDetail;\n};\n\n/**\n * A component that renders a failure state.\n */\nexport function Failure({error, errorDetail, ...boxProps}: FailureProps) {\n let {label, description, stack, cause} = errorDetail ?? getErrorDetail(error);\n\n return (\n <Box {...boxProps} flexDirection=\"column\">\n <Header icon={icons.error}>\n <Text color={colors.highlighted}>{label}</Text>\n </Header>\n\n {description ?\n <Box flexDirection=\"column\" marginLeft={2}>\n <Text color={colors.failure}>{description}</Text>\n </Box>\n : null}\n\n {stack ?\n <Box flexDirection=\"column\" marginLeft={2} marginTop={1}>\n <Text color={colors.muted}>{stack}</Text>\n </Box>\n : null}\n\n {cause ?\n <>\n <Box flexDirection=\"column\" marginLeft={2} marginTop={1}>\n <Text color={colors.muted}>{cause.description}</Text>\n </Box>\n\n {cause.stack ?\n <Box flexDirection=\"column\" marginLeft={2} marginTop={1}>\n <Text color={colors.muted}>{cause.stack}</Text>\n </Box>\n : null}\n </>\n : null}\n </Box>\n );\n}\n"],
5
5
  "mappings": ";AA4BQ,SAgBA,UAhBA,KAgBA,YAhBA;AA5BR,SAAQ,KAAoB,YAAW;AAEvC,YAAY,YAAY;AAExB,SAAQ,sBAAqB;AAC7B,SAAQ,cAAa;AACrB,YAAY,WAAW;AAgBhB,gBAAS,QAAQ,EAAC,OAAO,aAAa,GAAG,SAAQ,GAAiB;AACvE,MAAI,EAAC,OAAO,aAAa,OAAO,MAAK,IAAI,eAAe,eAAe,KAAK;AAE5E,SACE,qBAAC,OAAK,GAAG,UAAU,eAAc,UAC/B;AAAA,wBAAC,UAAO,MAAM,MAAM,OAClB,8BAAC,QAAK,OAAO,OAAO,aAAc,iBAAM,GAC1C;AAAA,IAEC,cACC,oBAAC,OAAI,eAAc,UAAS,YAAY,GACtC,8BAAC,QAAK,OAAO,OAAO,SAAU,uBAAY,GAC5C,IACA;AAAA,IAED,QACC,oBAAC,OAAI,eAAc,UAAS,YAAY,GAAG,WAAW,GACpD,8BAAC,QAAK,OAAO,OAAO,OAAQ,iBAAM,GACpC,IACA;AAAA,IAED,QACC,iCACE;AAAA,0BAAC,OAAI,eAAc,UAAS,YAAY,GAAG,WAAW,GACpD,8BAAC,QAAK,OAAO,OAAO,OAAQ,gBAAM,aAAY,GAChD;AAAA,MAEC,MAAM,QACL,oBAAC,OAAI,eAAc,UAAS,YAAY,GAAG,WAAW,GACpD,8BAAC,QAAK,OAAO,OAAO,OAAQ,gBAAM,OAAM,GAC1C,IACA;AAAA,OACJ,IACA;AAAA,KACJ;AAEJ;",
6
6
  "names": []
7
7
  }
@@ -3,12 +3,12 @@ import { type PropsWithChildren } from 'react';
3
3
  /**
4
4
  * {@link Header} component props.
5
5
  */
6
- export type HeaderProps = {
6
+ export type HeaderProps = BoxProps & {
7
7
  /** Icon (recommended is 1 character) to render before the header itself. */
8
8
  icon?: string;
9
9
  /** Show spinner instead of the icon. */
10
10
  showSpinner?: boolean;
11
- } & BoxProps;
11
+ };
12
12
  /**
13
13
  * Header component.
14
14
  */
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../source/ui/Header.tsx"],
4
- "sourcesContent": ["import {Box, type BoxProps, Text} from 'ink';\nimport {type PropsWithChildren} from 'react';\n\nimport {Spinner} from './Spinner.js';\n\n/**\n * {@link Header} component props.\n */\nexport type HeaderProps = {\n /** Icon (recommended is 1 character) to render before the header itself. */\n icon?: string;\n\n /** Show spinner instead of the icon. */\n showSpinner?: boolean;\n} & BoxProps;\n\n/**\n * Header component.\n */\nexport function Header({\n children,\n icon,\n showSpinner = false,\n ...boxProps\n}: PropsWithChildren<HeaderProps>) {\n return (\n <Box {...boxProps}>\n {icon || showSpinner ?\n <Box marginRight={1}>\n {showSpinner ?\n <Spinner />\n : null}\n {!showSpinner && icon ?\n <Text>{icon}</Text>\n : null}\n </Box>\n : null}\n <Box>{children}</Box>\n </Box>\n );\n}\n"],
4
+ "sourcesContent": ["import {Box, type BoxProps, Text} from 'ink';\nimport {type PropsWithChildren} from 'react';\n\nimport {Spinner} from './Spinner.js';\n\n/**\n * {@link Header} component props.\n */\nexport type HeaderProps = BoxProps & {\n /** Icon (recommended is 1 character) to render before the header itself. */\n icon?: string;\n\n /** Show spinner instead of the icon. */\n showSpinner?: boolean;\n};\n\n/**\n * Header component.\n */\nexport function Header({\n children,\n icon,\n showSpinner = false,\n ...boxProps\n}: PropsWithChildren<HeaderProps>) {\n return (\n <Box {...boxProps}>\n {icon || showSpinner ?\n <Box marginRight={1}>\n {showSpinner ?\n <Spinner />\n : null}\n {!showSpinner && icon ?\n <Text>{icon}</Text>\n : null}\n </Box>\n : null}\n <Box>{children}</Box>\n </Box>\n );\n}\n"],
5
5
  "mappings": ";AA4BQ,SAEI,KAFJ;AA5BR,SAAQ,KAAoB,YAAW;AAGvC,SAAQ,eAAc;AAgBf,gBAAS,OAAO;AAAA,EACrB;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,GAAG;AACL,GAAmC;AACjC,SACE,qBAAC,OAAK,GAAG,UACN;AAAA,YAAQ,cACP,qBAAC,OAAI,aAAa,GACf;AAAA,oBACC,oBAAC,WAAQ,IACT;AAAA,MACD,CAAC,eAAe,OACf,oBAAC,QAAM,gBAAK,IACZ;AAAA,OACJ,IACA;AAAA,IACF,oBAAC,OAAK,UAAS;AAAA,KACjB;AAEJ;",
6
6
  "names": []
7
7
  }
@@ -3,10 +3,10 @@ import { type Program } from '../program.js';
3
3
  /**
4
4
  * {@link Help} component props.
5
5
  */
6
- export type HelpProps = {
6
+ export type HelpProps = BoxProps & {
7
7
  /** {@link Program} instance. */
8
8
  program: Program;
9
- } & BoxProps;
9
+ };
10
10
  /**
11
11
  * A component that renders help information.
12
12
  */
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../source/ui/Help.tsx"],
4
- "sourcesContent": ["import chalk from 'chalk';\nimport {Box, type BoxProps, Text} from 'ink';\n\nimport {type Program} from '../program.js';\nimport * as colors from './colors.js';\nimport {Header} from './Header.js';\nimport * as icons from './icons.js';\n\n/**\n * {@link Help} component props.\n */\nexport type HelpProps = {\n /** {@link Program} instance. */\n program: Program;\n} & BoxProps;\n\n/**\n * A component that renders help information.\n */\nexport function Help({program, ...boxProps}: HelpProps) {\n return (\n <Box {...boxProps} flexDirection=\"column\">\n <Text>{`${chalk[colors.notice](program.displayName ?? program.name ?? '?')} ${chalk[\n colors.muted\n ](program.version ?? '?')}`}</Text>\n <Text color={colors.body}>{program.description}</Text>\n\n {program.commands.length ?\n <>\n <Header icon={icons.info} marginTop={1}>\n <Text color={colors.highlighted}>Usage</Text>\n </Header>\n {program.commands.map((command) => {\n let line = `${chalk[colors.muted](program.bin ?? '?')} ${command.name}`;\n\n if (command.parameters) {\n if (command.parameters.some((parameterConfig) => !!parameterConfig.required)) {\n line += ` ${chalk[colors.muted]('<parameters>')}`;\n } else {\n line += ` ${chalk[colors.muted]('[<parameters>]')}`;\n }\n }\n\n if (command.options) {\n if (\n Object.entries(command.options).some(([, optionConfig]) => !!optionConfig.required)\n ) {\n line += ` ${chalk[colors.muted]('<options>')}`;\n } else {\n line += ` ${chalk[colors.muted]('[<options>]')}`;\n }\n }\n\n if (command.description) {\n line += ` ${command.description}`;\n }\n\n return (\n <Box key={command.name} flexDirection=\"column\" marginLeft={2}>\n <Text>{line}</Text>\n </Box>\n );\n })}\n </>\n : null}\n </Box>\n );\n}\n"],
4
+ "sourcesContent": ["import chalk from 'chalk';\nimport {Box, type BoxProps, Text} from 'ink';\n\nimport {type Program} from '../program.js';\nimport * as colors from './colors.js';\nimport {Header} from './Header.js';\nimport * as icons from './icons.js';\n\n/**\n * {@link Help} component props.\n */\nexport type HelpProps = BoxProps & {\n /** {@link Program} instance. */\n program: Program;\n};\n\n/**\n * A component that renders help information.\n */\nexport function Help({program, ...boxProps}: HelpProps) {\n return (\n <Box {...boxProps} flexDirection=\"column\">\n <Text>{`${chalk[colors.notice](program.displayName ?? program.name ?? '?')} ${chalk[\n colors.muted\n ](program.version ?? '?')}`}</Text>\n <Text color={colors.body}>{program.description}</Text>\n\n {program.commands.length ?\n <>\n <Header icon={icons.info} marginTop={1}>\n <Text color={colors.highlighted}>Usage</Text>\n </Header>\n {program.commands.map((command) => {\n let line = `${chalk[colors.muted](program.bin ?? '?')} ${command.name}`;\n\n if (command.parameters) {\n if (command.parameters.some((parameterConfig) => !!parameterConfig.required)) {\n line += ` ${chalk[colors.muted]('<parameters>')}`;\n } else {\n line += ` ${chalk[colors.muted]('[<parameters>]')}`;\n }\n }\n\n if (command.options) {\n if (\n Object.entries(command.options).some(([, optionConfig]) => !!optionConfig.required)\n ) {\n line += ` ${chalk[colors.muted]('<options>')}`;\n } else {\n line += ` ${chalk[colors.muted]('[<options>]')}`;\n }\n }\n\n if (command.description) {\n line += ` ${command.description}`;\n }\n\n return (\n <Box key={command.name} flexDirection=\"column\" marginLeft={2}>\n <Text>{line}</Text>\n </Box>\n );\n })}\n </>\n : null}\n </Box>\n );\n}\n"],
5
5
  "mappings": ";AAsBM,SAME,UANF,KAME,YANF;AAtBN,OAAO,WAAW;AAClB,SAAQ,KAAoB,YAAW;AAGvC,YAAY,YAAY;AACxB,SAAQ,cAAa;AACrB,YAAY,WAAW;AAahB,gBAAS,KAAK,EAAC,SAAS,GAAG,SAAQ,GAAc;AACtD,SACE,qBAAC,OAAK,GAAG,UAAU,eAAc,UAC/B;AAAA,wBAAC,QAAM,aAAG,MAAM,OAAO,MAAM,EAAE,QAAQ,eAAe,QAAQ,QAAQ,GAAG,CAAC,IAAI,MAC5E,OAAO,KACT,EAAE,QAAQ,WAAW,GAAG,CAAC,IAAG;AAAA,IAC5B,oBAAC,QAAK,OAAO,OAAO,MAAO,kBAAQ,aAAY;AAAA,IAE9C,QAAQ,SAAS,SAChB,iCACE;AAAA,0BAAC,UAAO,MAAM,MAAM,MAAM,WAAW,GACnC,8BAAC,QAAK,OAAO,OAAO,aAAa,mBAAK,GACxC;AAAA,MACC,QAAQ,SAAS,IAAI,CAAC,YAAY;AACjC,YAAI,OAAO,GAAG,MAAM,OAAO,KAAK,EAAE,QAAQ,OAAO,GAAG,CAAC,IAAI,QAAQ,IAAI;AAErE,YAAI,QAAQ,YAAY;AACtB,cAAI,QAAQ,WAAW,KAAK,CAAC,oBAAoB,CAAC,CAAC,gBAAgB,QAAQ,GAAG;AAC5E,oBAAQ,IAAI,MAAM,OAAO,KAAK,EAAE,cAAc,CAAC;AAAA,UACjD,OAAO;AACL,oBAAQ,IAAI,MAAM,OAAO,KAAK,EAAE,gBAAgB,CAAC;AAAA,UACnD;AAAA,QACF;AAEA,YAAI,QAAQ,SAAS;AACnB,cACE,OAAO,QAAQ,QAAQ,OAAO,EAAE,KAAK,CAAC,CAAC,EAAE,YAAY,MAAM,CAAC,CAAC,aAAa,QAAQ,GAClF;AACA,oBAAQ,IAAI,MAAM,OAAO,KAAK,EAAE,WAAW,CAAC;AAAA,UAC9C,OAAO;AACL,oBAAQ,IAAI,MAAM,OAAO,KAAK,EAAE,aAAa,CAAC;AAAA,UAChD;AAAA,QACF;AAEA,YAAI,QAAQ,aAAa;AACvB,kBAAQ,IAAI,QAAQ,WAAW;AAAA,QACjC;AAEA,eACE,oBAAC,OAAuB,eAAc,UAAS,YAAY,GACzD,8BAAC,QAAM,gBAAK,KADJ,QAAQ,IAElB;AAAA,MAEJ,CAAC;AAAA,OACH,IACA;AAAA,KACJ;AAEJ;",
6
6
  "names": []
7
7
  }
@@ -4,6 +4,6 @@ import { type FormProps } from './FormProps.js';
4
4
  /**
5
5
  * Form component.
6
6
  */
7
- export type Form<C extends FormConfig> = {
7
+ export type Form<C extends FormConfig> = FC<FormProps<C>> & {
8
8
  config: C;
9
- } & FC<FormProps<C>>;
9
+ };
@@ -18,7 +18,7 @@ type FormPropsRows<C extends FormConfig> = Pick<{
18
18
  /**
19
19
  * Form component props.
20
20
  */
21
- export type FormProps<C extends FormConfig> = FormPropsRows<C> extends Record<number | string | symbol, never> ? {
21
+ export type FormProps<C extends FormConfig> = FormPropsRows<C> extends Record<number | string | symbol, never> ? BoxProps & {
22
22
  /** Props for each row. */
23
23
  rows?: null | undefined;
24
24
  /** Form values */
@@ -27,7 +27,7 @@ export type FormProps<C extends FormConfig> = FormPropsRows<C> extends Record<nu
27
27
  onChange?: ((formResult: FormValues<C>) => void) | undefined;
28
28
  /** Handler function that is called when the value is accepted. */
29
29
  onComplete: (formResult: FormValues<C>) => void;
30
- } & BoxProps : {
30
+ } : BoxProps & {
31
31
  /** Props for each row. */
32
32
  rows: FormPropsRows<C>;
33
33
  /** Form values */
@@ -36,5 +36,5 @@ export type FormProps<C extends FormConfig> = FormPropsRows<C> extends Record<nu
36
36
  onChange?: ((formResult: FormValues<C>) => void) | undefined;
37
37
  /** Handler function that is called when the value is accepted. */
38
38
  onComplete: (formResult: FormValues<C>) => void;
39
- } & BoxProps;
39
+ };
40
40
  export {};
@@ -5,7 +5,7 @@ import { type FormRowConfig } from './FormRowConfig.js';
5
5
  /**
6
6
  * Form row component props.
7
7
  */
8
- type FormRowProps<C extends FormConfig> = {
8
+ type FormRowProps<C extends FormConfig> = BoxProps & {
9
9
  /** Form row configuration. */
10
10
  config: FormRowConfig;
11
11
  /** Props of all form rows. */
@@ -22,7 +22,7 @@ type FormRowProps<C extends FormConfig> = {
22
22
  onComplete: (value: unknown, inputName: keyof C['rows']) => void;
23
23
  /** Indicates whether value has been accepted. Component in the row then doesn't accept more input. */
24
24
  isComplete: boolean;
25
- } & BoxProps;
25
+ };
26
26
  /**
27
27
  * Form row component.
28
28
  */
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../source/ui/form/FormRow.tsx"],
4
- "sourcesContent": ["import {type BoxProps} from 'ink';\nimport {useCallback} from 'react';\n\nimport {type FormConfig} from './FormConfig.js';\nimport {type FormProps} from './FormProps.js';\nimport {type FormRowConfig} from './FormRowConfig.js';\nimport {SelectInput} from './SelectInput.js';\nimport {TextInput} from './TextInput.js';\n\n/**\n * Form row component props.\n */\ntype FormRowProps<C extends FormConfig> = {\n /** Form row configuration. */\n config: FormRowConfig;\n\n // TODO: Should all rows props be passed to each row?\n /** Props of all form rows. */\n rows: FormProps<C>['rows'] | null;\n\n /** Row name. */\n rowName: keyof C['rows'];\n\n /** Value. */\n value: unknown;\n\n /** Should component listen to Listen to user's input? Useful in case there are multiple input components at the same time and input must be \"routed\" to a specific component. */\n focus: boolean;\n\n /** Handler function that is called when value changes. */\n onChange: (value: unknown, inputName: keyof C['rows']) => void;\n\n /** Handler function that is called when the value is accepted. */\n onComplete: (value: unknown, inputName: keyof C['rows']) => void;\n\n /** Indicates whether value has been accepted. Component in the row then doesn't accept more input. */\n isComplete: boolean;\n} & BoxProps;\n\n/**\n * Form row component.\n */\nexport function FormRow<C extends FormConfig>({\n rowName,\n config,\n rows,\n value,\n focus,\n isComplete,\n onChange,\n onComplete,\n ...boxProps\n}: FormRowProps<C>) {\n // TODO: Each input component handles values and events differently; the APIs should be adjusted.\n let handleChange = useCallback(\n (newValue: unknown) => {\n onChange(newValue, rowName);\n },\n [rowName, onChange],\n );\n\n let handleFinish = useCallback(\n (newValue: unknown) => {\n onComplete(newValue, rowName);\n },\n [rowName, onComplete],\n );\n\n let handleSelectFinish = useCallback(\n (item: {value: unknown}) => {\n onComplete(item.value, rowName);\n },\n [rowName, onComplete],\n );\n\n switch (config.type) {\n case 'confirm': {\n return null;\n }\n case 'select': {\n return (\n <SelectInput\n key={String(rowName)}\n items={\n rows ?\n (\n (\n rows as {\n [key: string]: unknown;\n }\n )[rowName as string] as {choices: Array<{value: string; label: string}>}\n ).choices\n : []\n }\n focus={focus}\n isComplete={isComplete}\n label={config.label ?? ''}\n onSelect={handleSelectFinish}\n {...boxProps}\n />\n );\n }\n case 'text': {\n return (\n <TextInput\n key={String(rowName)}\n focus={focus}\n isComplete={isComplete}\n label={config.label ?? ''}\n validate={config.validate}\n value={value as string}\n onChange={handleChange}\n onSubmit={handleFinish}\n {...boxProps}\n />\n );\n }\n default: {\n config satisfies never;\n\n return null;\n }\n }\n}\n"],
4
+ "sourcesContent": ["import {type BoxProps} from 'ink';\nimport {useCallback} from 'react';\n\nimport {type FormConfig} from './FormConfig.js';\nimport {type FormProps} from './FormProps.js';\nimport {type FormRowConfig} from './FormRowConfig.js';\nimport {SelectInput} from './SelectInput.js';\nimport {TextInput} from './TextInput.js';\n\n/**\n * Form row component props.\n */\ntype FormRowProps<C extends FormConfig> = BoxProps & {\n /** Form row configuration. */\n config: FormRowConfig;\n\n // TODO: Should all rows props be passed to each row?\n /** Props of all form rows. */\n rows: FormProps<C>['rows'] | null;\n\n /** Row name. */\n rowName: keyof C['rows'];\n\n /** Value. */\n value: unknown;\n\n /** Should component listen to Listen to user's input? Useful in case there are multiple input components at the same time and input must be \"routed\" to a specific component. */\n focus: boolean;\n\n /** Handler function that is called when value changes. */\n onChange: (value: unknown, inputName: keyof C['rows']) => void;\n\n /** Handler function that is called when the value is accepted. */\n onComplete: (value: unknown, inputName: keyof C['rows']) => void;\n\n /** Indicates whether value has been accepted. Component in the row then doesn't accept more input. */\n isComplete: boolean;\n};\n\n/**\n * Form row component.\n */\nexport function FormRow<C extends FormConfig>({\n rowName,\n config,\n rows,\n value,\n focus,\n isComplete,\n onChange,\n onComplete,\n ...boxProps\n}: FormRowProps<C>) {\n // TODO: Each input component handles values and events differently; the APIs should be adjusted.\n let handleChange = useCallback(\n (newValue: unknown) => {\n onChange(newValue, rowName);\n },\n [rowName, onChange],\n );\n\n let handleFinish = useCallback(\n (newValue: unknown) => {\n onComplete(newValue, rowName);\n },\n [rowName, onComplete],\n );\n\n let handleSelectFinish = useCallback(\n (item: {value: unknown}) => {\n onComplete(item.value, rowName);\n },\n [rowName, onComplete],\n );\n\n switch (config.type) {\n case 'confirm': {\n return null;\n }\n case 'select': {\n return (\n <SelectInput\n key={String(rowName)}\n items={\n rows ?\n (\n (\n rows as {\n [key: string]: unknown;\n }\n )[rowName as string] as {choices: Array<{value: string; label: string}>}\n ).choices\n : []\n }\n focus={focus}\n isComplete={isComplete}\n label={config.label ?? ''}\n onSelect={handleSelectFinish}\n {...boxProps}\n />\n );\n }\n case 'text': {\n return (\n <TextInput\n key={String(rowName)}\n focus={focus}\n isComplete={isComplete}\n label={config.label ?? ''}\n validate={config.validate}\n value={value as string}\n onChange={handleChange}\n onSubmit={handleFinish}\n {...boxProps}\n />\n );\n }\n default: {\n config satisfies never;\n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AA,IACT;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -3,7 +3,7 @@ import { type SelectInputItem } from './SelectInputItem.js';
3
3
  /**
4
4
  * {@linkcode SelectInput} component props.
5
5
  */
6
- type SelectInputProps = {
6
+ type SelectInputProps = BoxProps & {
7
7
  /** Text to display as a label. */
8
8
  label: string;
9
9
  /** Items to display in a list. */
@@ -20,7 +20,7 @@ type SelectInputProps = {
20
20
  onHighlight?: ((item: SelectInputItem) => void) | undefined;
21
21
  /** Indicates whether value has been accepted. Component then doesn't accept more input. */
22
22
  isComplete?: boolean | undefined;
23
- } & BoxProps;
23
+ };
24
24
  /**
25
25
  * Select input component.
26
26
  */
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../source/ui/form/SelectInput.tsx"],
4
- "sourcesContent": ["import {Box, type BoxProps, type Key, Text, useInput} from 'ink';\nimport _ from 'lodash';\nimport {useEffect, useRef, useState} from 'react';\n\nimport * as colors from '../colors.js';\nimport * as icons from '../icons.js';\nimport {rotate} from '../internals.js';\nimport {type SelectInputItem} from './SelectInputItem.js';\n\n/**\n * {@linkcode SelectInput} component props.\n */\ntype SelectInputProps = {\n /** Text to display as a label. */\n label: string;\n\n /** Items to display in a list. */\n items: SelectInputItem[];\n\n /** Should component listen to user's input? Useful in case there are multiple input components at the same time and input must be handled only by a specific component. */\n focus?: boolean | undefined;\n\n /** Index of initially selected item. */\n initialIndex?: number | undefined;\n\n /** Number of items to display. */\n limit?: number | undefined;\n\n /** Handler function that is called when item is selected. */\n onSelect?: ((item: SelectInputItem) => void) | undefined;\n\n /** Handler function that is called when item is highlighted. */\n onHighlight?: ((item: SelectInputItem) => void) | undefined;\n\n /** Indicates whether value has been accepted. Component then doesn't accept more input. */\n isComplete?: boolean | undefined;\n} & BoxProps;\n\n/**\n * Select input component.\n */\nexport function SelectInput({\n label,\n items,\n focus = true,\n initialIndex = 0,\n limit: userDefinedLimit,\n onSelect,\n onHighlight,\n isComplete,\n ...boxProps\n}: SelectInputProps): JSX.Element {\n let [rotatedIndex, setRotatedIndex] = useState(0);\n let [selectedIndex, setSelectedIndex] = useState(initialIndex);\n let hasLimit = typeof userDefinedLimit === 'number' && items.length > userDefinedLimit;\n let limit = hasLimit ? Math.min(userDefinedLimit as number, items.length) : items.length;\n let previousItems = useRef<SelectInputItem[]>(items);\n\n useEffect(() => {\n if (\n !_.isEqual(\n previousItems.current.map((item) => item.value),\n items.map((item) => item.value),\n )\n ) {\n setRotatedIndex(0);\n setSelectedIndex(0);\n }\n\n previousItems.current = items;\n }, [items]);\n\n useInput(\n (input: string, key: Key) => {\n if (input === 'k' || key.upArrow) {\n let lastIndex = (hasLimit ? limit : items.length) - 1;\n let isAtFirstIndex = selectedIndex === 0;\n let nextIndex = hasLimit ? selectedIndex : lastIndex;\n let nextRotatedIndex = isAtFirstIndex ? rotatedIndex + 1 : rotatedIndex;\n let nextSelectedIndex = isAtFirstIndex ? nextIndex : selectedIndex - 1;\n\n setRotatedIndex(nextRotatedIndex);\n setSelectedIndex(nextSelectedIndex);\n\n let slicedItems = hasLimit ? rotate(items, nextRotatedIndex).slice(0, limit) : items;\n\n if (typeof onHighlight === 'function') {\n onHighlight(slicedItems[nextSelectedIndex] as SelectInputItem);\n }\n }\n\n if (input === 'j' || key.downArrow) {\n let isAtLastIndex = selectedIndex === (hasLimit ? limit : items.length) - 1;\n let nextIndex = hasLimit ? selectedIndex : 0;\n let nextRotatedIndex = isAtLastIndex ? rotatedIndex - 1 : rotatedIndex;\n let nextSelectedIndex = isAtLastIndex ? nextIndex : selectedIndex + 1;\n\n setRotatedIndex(nextRotatedIndex);\n setSelectedIndex(nextSelectedIndex);\n\n let slicedItems = hasLimit ? rotate(items, nextRotatedIndex).slice(0, limit) : items;\n\n if (typeof onHighlight === 'function') {\n onHighlight(slicedItems[nextSelectedIndex] as SelectInputItem);\n }\n }\n\n if (key.return) {\n let slicedItems = hasLimit ? rotate(items, rotatedIndex).slice(0, limit) : items;\n\n if (typeof onSelect === 'function') {\n onSelect(slicedItems[selectedIndex] as SelectInputItem);\n }\n }\n },\n {isActive: focus},\n );\n\n let visibleItems: SelectInputItem[] =\n hasLimit ? rotate(items, rotatedIndex).slice(0, limit) : items;\n\n return (\n <Box {...boxProps}>\n <Box marginRight={1}>\n <Text>{isComplete ? icons.success : icons.question}</Text>\n </Box>\n\n <Box flexDirection=\"column\">\n <Box marginRight={1}>\n <Text color={colors.highlighted}>{label}</Text>\n </Box>\n {isComplete ?\n <Text color={colors.body}>\n {items[selectedIndex]?.label ?? String(items[selectedIndex]?.value)}\n </Text>\n : <Box flexDirection=\"column\">\n {visibleItems.map((item, index) => {\n let isSelected = index === selectedIndex;\n\n return (\n <Box key={item.value}>\n <Box marginRight={1}>\n {isSelected ?\n <Text color={colors.selected}>{icons.selectedCircle}</Text>\n : <Text color={colors.unselected}>{icons.unselectedCircle}</Text>}\n </Box>\n <Text color={isSelected ? colors.highlighted : colors.muted}>{item.label}</Text>\n </Box>\n );\n })}\n </Box>\n }\n </Box>\n </Box>\n );\n}\n\n// partially based on https://github.com/vadimdemedes/ink-select-input/tree/309497ca641f55d8df0083ec2d07264f101358e4 (see https://github.com/vadimdemedes/ink-select-input/blob/309497ca641f55d8df0083ec2d07264f101358e4/license for license)\n"],
4
+ "sourcesContent": ["import {Box, type BoxProps, type Key, Text, useInput} from 'ink';\nimport _ from 'lodash';\nimport {useEffect, useRef, useState} from 'react';\n\nimport * as colors from '../colors.js';\nimport * as icons from '../icons.js';\nimport {rotate} from '../internals.js';\nimport {type SelectInputItem} from './SelectInputItem.js';\n\n/**\n * {@linkcode SelectInput} component props.\n */\ntype SelectInputProps = BoxProps & {\n /** Text to display as a label. */\n label: string;\n\n /** Items to display in a list. */\n items: SelectInputItem[];\n\n /** Should component listen to user's input? Useful in case there are multiple input components at the same time and input must be handled only by a specific component. */\n focus?: boolean | undefined;\n\n /** Index of initially selected item. */\n initialIndex?: number | undefined;\n\n /** Number of items to display. */\n limit?: number | undefined;\n\n /** Handler function that is called when item is selected. */\n onSelect?: ((item: SelectInputItem) => void) | undefined;\n\n /** Handler function that is called when item is highlighted. */\n onHighlight?: ((item: SelectInputItem) => void) | undefined;\n\n /** Indicates whether value has been accepted. Component then doesn't accept more input. */\n isComplete?: boolean | undefined;\n};\n\n/**\n * Select input component.\n */\nexport function SelectInput({\n label,\n items,\n focus = true,\n initialIndex = 0,\n limit: userDefinedLimit,\n onSelect,\n onHighlight,\n isComplete,\n ...boxProps\n}: SelectInputProps): JSX.Element {\n let [rotatedIndex, setRotatedIndex] = useState(0);\n let [selectedIndex, setSelectedIndex] = useState(initialIndex);\n let hasLimit = typeof userDefinedLimit === 'number' && items.length > userDefinedLimit;\n let limit = hasLimit ? Math.min(userDefinedLimit as number, items.length) : items.length;\n let previousItems = useRef<SelectInputItem[]>(items);\n\n useEffect(() => {\n if (\n !_.isEqual(\n previousItems.current.map((item) => item.value),\n items.map((item) => item.value),\n )\n ) {\n setRotatedIndex(0);\n setSelectedIndex(0);\n }\n\n previousItems.current = items;\n }, [items]);\n\n useInput(\n (input: string, key: Key) => {\n if (input === 'k' || key.upArrow) {\n let lastIndex = (hasLimit ? limit : items.length) - 1;\n let isAtFirstIndex = selectedIndex === 0;\n let nextIndex = hasLimit ? selectedIndex : lastIndex;\n let nextRotatedIndex = isAtFirstIndex ? rotatedIndex + 1 : rotatedIndex;\n let nextSelectedIndex = isAtFirstIndex ? nextIndex : selectedIndex - 1;\n\n setRotatedIndex(nextRotatedIndex);\n setSelectedIndex(nextSelectedIndex);\n\n let slicedItems = hasLimit ? rotate(items, nextRotatedIndex).slice(0, limit) : items;\n\n if (typeof onHighlight === 'function') {\n onHighlight(slicedItems[nextSelectedIndex] as SelectInputItem);\n }\n }\n\n if (input === 'j' || key.downArrow) {\n let isAtLastIndex = selectedIndex === (hasLimit ? limit : items.length) - 1;\n let nextIndex = hasLimit ? selectedIndex : 0;\n let nextRotatedIndex = isAtLastIndex ? rotatedIndex - 1 : rotatedIndex;\n let nextSelectedIndex = isAtLastIndex ? nextIndex : selectedIndex + 1;\n\n setRotatedIndex(nextRotatedIndex);\n setSelectedIndex(nextSelectedIndex);\n\n let slicedItems = hasLimit ? rotate(items, nextRotatedIndex).slice(0, limit) : items;\n\n if (typeof onHighlight === 'function') {\n onHighlight(slicedItems[nextSelectedIndex] as SelectInputItem);\n }\n }\n\n if (key.return) {\n let slicedItems = hasLimit ? rotate(items, rotatedIndex).slice(0, limit) : items;\n\n if (typeof onSelect === 'function') {\n onSelect(slicedItems[selectedIndex] as SelectInputItem);\n }\n }\n },\n {isActive: focus},\n );\n\n let visibleItems: SelectInputItem[] =\n hasLimit ? rotate(items, rotatedIndex).slice(0, limit) : items;\n\n return (\n <Box {...boxProps}>\n <Box marginRight={1}>\n <Text>{isComplete ? icons.success : icons.question}</Text>\n </Box>\n\n <Box flexDirection=\"column\">\n <Box marginRight={1}>\n <Text color={colors.highlighted}>{label}</Text>\n </Box>\n {isComplete ?\n <Text color={colors.body}>\n {items[selectedIndex]?.label ?? String(items[selectedIndex]?.value)}\n </Text>\n : <Box flexDirection=\"column\">\n {visibleItems.map((item, index) => {\n let isSelected = index === selectedIndex;\n\n return (\n <Box key={item.value}>\n <Box marginRight={1}>\n {isSelected ?\n <Text color={colors.selected}>{icons.selectedCircle}</Text>\n : <Text color={colors.unselected}>{icons.unselectedCircle}</Text>}\n </Box>\n <Text color={isSelected ? colors.highlighted : colors.muted}>{item.label}</Text>\n </Box>\n );\n })}\n </Box>\n }\n </Box>\n </Box>\n );\n}\n\n// partially based on https://github.com/vadimdemedes/ink-select-input/tree/309497ca641f55d8df0083ec2d07264f101358e4 (see https://github.com/vadimdemedes/ink-select-input/blob/309497ca641f55d8df0083ec2d07264f101358e4/license for license)\n"],
5
5
  "mappings": ";AA4HQ,cAgBQ,YAhBR;AA5HR,SAAQ,KAA8B,MAAM,gBAAe;AAC3D,OAAO,OAAO;AACd,SAAQ,WAAW,QAAQ,gBAAe;AAE1C,YAAY,YAA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,oBAAC,QAAK,OAAO,OAAO,YAAa,gBAAM,kBAAiB,GAC5D;AAAA,UACA,oBAAC,QAAK,OAAO,aAAa,OAAO,cAAc,OAAO,OAAQ,eAAK,OAAM;AAAA,aANjE,KAAK,KAOf;AAAA,MAEJ,CAAC,GACH;AAAA,OAEJ;AAAA,KACF;AAEJ;",
6
6
  "names": []
7
7
  }
@@ -2,7 +2,7 @@ import { type BoxProps } from 'ink';
2
2
  /**
3
3
  * Text input component props.
4
4
  */
5
- export type TextInputProps = {
5
+ export type TextInputProps = BoxProps & {
6
6
  /** Text to display as a label. */
7
7
  label: string;
8
8
  /** Text to display when `value` is empty. */
@@ -23,7 +23,7 @@ export type TextInputProps = {
23
23
  onSubmit?: ((value: string) => void) | undefined;
24
24
  /** Indicates whether value has been accepted. Component then doesn't accept more input. */
25
25
  isComplete?: boolean | undefined;
26
- } & BoxProps;
26
+ };
27
27
  /**
28
28
  * Text input component.
29
29
  */
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../source/ui/form/TextInput.tsx"],
4
- "sourcesContent": ["import chalk from 'chalk';\nimport {Box, type BoxProps, Text, useInput} from 'ink';\nimport {useEffect, useState} from 'react';\n\nimport * as colors from '../colors.js';\nimport * as icons from '../icons.js';\n\n/**\n * Text input component props.\n */\nexport type TextInputProps = {\n /** Text to display as a label. */\n label: string;\n\n /** Text to display when `value` is empty. */\n placeholder?: string | undefined;\n\n /** Value. */\n value: string;\n\n /** Should component listen to Listen to user's input? Useful in case there are multiple input components at the same time and input must be handled only by a specific component. */\n focus?: boolean | undefined;\n\n /** Replace all chars and mask the value. Useful for password inputs. */\n mask?: string | undefined;\n\n /** Show cursor and allow navigation using arrow keys. */\n showCursor?: boolean | undefined;\n\n /** Validation function that is called when value changes. If this function throws an error*/\n validate?: ((value: string) => void) | undefined;\n\n /** Handler function that is called when value changes. */\n onChange: (value: string) => void;\n\n /** Handler function that is called when enter is pressed. */\n onSubmit?: ((value: string) => void) | undefined;\n\n /** Indicates whether value has been accepted. Component then doesn't accept more input. */\n isComplete?: boolean | undefined;\n} & BoxProps;\n\n/**\n * Text input component.\n */\nexport function TextInput({\n label,\n validate,\n isComplete,\n value: originalValue,\n placeholder = '',\n focus = true,\n mask,\n showCursor = true,\n onChange,\n onSubmit,\n ...boxProps\n}: TextInputProps) {\n let [validationError, setValidationError] = useState('');\n let [state, setState] = useState({\n cursorOffset: (originalValue || '').length,\n cursorWidth: 0,\n });\n\n useEffect(() => {\n setState((previousState) => {\n if (!focus || !showCursor) {\n return previousState;\n }\n\n let newValue = originalValue || '';\n\n if (previousState.cursorOffset > newValue.length - 1) {\n return {\n cursorOffset: newValue.length,\n cursorWidth: 0,\n };\n }\n\n return previousState;\n });\n }, [originalValue, focus, showCursor]);\n\n let value = mask ? mask.repeat(originalValue.length) : originalValue;\n let renderedValue = value;\n let renderedPlaceholder = placeholder ? chalk[colors.muted](placeholder) : undefined;\n\n if (showCursor && focus) {\n renderedPlaceholder =\n placeholder.length > 0 ?\n chalk.inverse(placeholder[0]) + chalk[colors.muted](placeholder.slice(1))\n : chalk.inverse(' ');\n\n renderedValue = value.length > 0 ? '' : chalk.inverse(' ');\n\n for (let [i, character] of Object.entries(value)) {\n if (Number(i) >= state.cursorOffset && Number(i) <= state.cursorOffset) {\n renderedValue += chalk.inverse(character);\n } else {\n renderedValue += character;\n }\n }\n\n if (value.length > 0 && state.cursorOffset === value.length) {\n renderedValue += chalk.inverse(' ');\n }\n }\n\n useInput(\n (input, key) => {\n if (\n key.upArrow ||\n key.downArrow ||\n (key.ctrl && input === 'c') ||\n (key.shift && key.tab) ||\n key.tab\n ) {\n return;\n }\n\n if (key.return) {\n if (onSubmit) {\n if (validate) {\n try {\n validate(originalValue);\n } catch (error: unknown) {\n setValidationError((error as Error).message);\n\n return;\n }\n }\n\n if (validationError) {\n setValidationError('');\n } else {\n onSubmit(originalValue);\n }\n }\n\n return;\n }\n\n let nextCursorOffset = state.cursorOffset;\n let nextValue = originalValue;\n let nextCursorWidth = 0;\n\n if (key.leftArrow) {\n if (showCursor) {\n nextCursorOffset -= 1;\n }\n } else if (key.rightArrow) {\n if (showCursor) {\n nextCursorOffset += 1;\n }\n } else if (key.backspace || key.delete) {\n if (state.cursorOffset > 0) {\n nextValue =\n originalValue.slice(0, state.cursorOffset - 1) +\n originalValue.slice(state.cursorOffset);\n\n nextCursorOffset -= 1;\n }\n } else {\n nextValue =\n originalValue.slice(0, state.cursorOffset) +\n input +\n originalValue.slice(state.cursorOffset);\n\n nextCursorOffset += input.length;\n\n if (input.length > 1) {\n nextCursorWidth = input.length;\n }\n }\n\n if (state.cursorOffset < 0) {\n nextCursorOffset = 0;\n }\n\n if (state.cursorOffset > originalValue.length) {\n nextCursorOffset = originalValue.length;\n }\n\n setState({\n cursorOffset: nextCursorOffset,\n cursorWidth: nextCursorWidth,\n });\n\n if (nextValue !== originalValue) {\n onChange(nextValue);\n }\n },\n {isActive: focus},\n );\n\n return (\n <Box {...boxProps}>\n <Box marginRight={1}>\n <Text>{isComplete ? icons.success : icons.question}</Text>\n </Box>\n\n <Box flexDirection=\"column\">\n <Box marginRight={1}>\n <Text color={colors.highlighted}>{label}</Text>\n </Box>\n {isComplete ?\n <Text color={colors.body}>{value}</Text>\n : <Text color={colors.highlighted}>\n {placeholder ?\n value.length > 0 ?\n renderedValue\n : renderedPlaceholder\n : renderedValue}\n </Text>\n }\n {validationError ?\n <Box marginTop={0}>\n <Text color={colors.warning}>{validationError}</Text>\n </Box>\n : null}\n </Box>\n </Box>\n );\n}\n\n// partially based on https://github.com/vadimdemedes/ink-text-input/tree/0787c505415f0d059801d80600e4ccb0651385f3 (see https://github.com/vadimdemedes/ink-text-input/blob/0787c505415f0d059801d80600e4ccb0651385f3/license for license)\n"],
4
+ "sourcesContent": ["import chalk from 'chalk';\nimport {Box, type BoxProps, Text, useInput} from 'ink';\nimport {useEffect, useState} from 'react';\n\nimport * as colors from '../colors.js';\nimport * as icons from '../icons.js';\n\n/**\n * Text input component props.\n */\nexport type TextInputProps = BoxProps & {\n /** Text to display as a label. */\n label: string;\n\n /** Text to display when `value` is empty. */\n placeholder?: string | undefined;\n\n /** Value. */\n value: string;\n\n /** Should component listen to Listen to user's input? Useful in case there are multiple input components at the same time and input must be handled only by a specific component. */\n focus?: boolean | undefined;\n\n /** Replace all chars and mask the value. Useful for password inputs. */\n mask?: string | undefined;\n\n /** Show cursor and allow navigation using arrow keys. */\n showCursor?: boolean | undefined;\n\n /** Validation function that is called when value changes. If this function throws an error*/\n validate?: ((value: string) => void) | undefined;\n\n /** Handler function that is called when value changes. */\n onChange: (value: string) => void;\n\n /** Handler function that is called when enter is pressed. */\n onSubmit?: ((value: string) => void) | undefined;\n\n /** Indicates whether value has been accepted. Component then doesn't accept more input. */\n isComplete?: boolean | undefined;\n};\n\n/**\n * Text input component.\n */\nexport function TextInput({\n label,\n validate,\n isComplete,\n value: originalValue,\n placeholder = '',\n focus = true,\n mask,\n showCursor = true,\n onChange,\n onSubmit,\n ...boxProps\n}: TextInputProps) {\n let [validationError, setValidationError] = useState('');\n let [state, setState] = useState({\n cursorOffset: (originalValue || '').length,\n cursorWidth: 0,\n });\n\n useEffect(() => {\n setState((previousState) => {\n if (!focus || !showCursor) {\n return previousState;\n }\n\n let newValue = originalValue || '';\n\n if (previousState.cursorOffset > newValue.length - 1) {\n return {\n cursorOffset: newValue.length,\n cursorWidth: 0,\n };\n }\n\n return previousState;\n });\n }, [originalValue, focus, showCursor]);\n\n let value = mask ? mask.repeat(originalValue.length) : originalValue;\n let renderedValue = value;\n let renderedPlaceholder = placeholder ? chalk[colors.muted](placeholder) : undefined;\n\n if (showCursor && focus) {\n renderedPlaceholder =\n placeholder.length > 0 ?\n chalk.inverse(placeholder[0]) + chalk[colors.muted](placeholder.slice(1))\n : chalk.inverse(' ');\n\n renderedValue = value.length > 0 ? '' : chalk.inverse(' ');\n\n for (let [i, character] of Object.entries(value)) {\n if (Number(i) >= state.cursorOffset && Number(i) <= state.cursorOffset) {\n renderedValue += chalk.inverse(character);\n } else {\n renderedValue += character;\n }\n }\n\n if (value.length > 0 && state.cursorOffset === value.length) {\n renderedValue += chalk.inverse(' ');\n }\n }\n\n useInput(\n (input, key) => {\n if (\n key.upArrow ||\n key.downArrow ||\n (key.ctrl && input === 'c') ||\n (key.shift && key.tab) ||\n key.tab\n ) {\n return;\n }\n\n if (key.return) {\n if (onSubmit) {\n if (validate) {\n try {\n validate(originalValue);\n } catch (error: unknown) {\n setValidationError((error as Error).message);\n\n return;\n }\n }\n\n if (validationError) {\n setValidationError('');\n } else {\n onSubmit(originalValue);\n }\n }\n\n return;\n }\n\n let nextCursorOffset = state.cursorOffset;\n let nextValue = originalValue;\n let nextCursorWidth = 0;\n\n if (key.leftArrow) {\n if (showCursor) {\n nextCursorOffset -= 1;\n }\n } else if (key.rightArrow) {\n if (showCursor) {\n nextCursorOffset += 1;\n }\n } else if (key.backspace || key.delete) {\n if (state.cursorOffset > 0) {\n nextValue =\n originalValue.slice(0, state.cursorOffset - 1) +\n originalValue.slice(state.cursorOffset);\n\n nextCursorOffset -= 1;\n }\n } else {\n nextValue =\n originalValue.slice(0, state.cursorOffset) +\n input +\n originalValue.slice(state.cursorOffset);\n\n nextCursorOffset += input.length;\n\n if (input.length > 1) {\n nextCursorWidth = input.length;\n }\n }\n\n if (state.cursorOffset < 0) {\n nextCursorOffset = 0;\n }\n\n if (state.cursorOffset > originalValue.length) {\n nextCursorOffset = originalValue.length;\n }\n\n setState({\n cursorOffset: nextCursorOffset,\n cursorWidth: nextCursorWidth,\n });\n\n if (nextValue !== originalValue) {\n onChange(nextValue);\n }\n },\n {isActive: focus},\n );\n\n return (\n <Box {...boxProps}>\n <Box marginRight={1}>\n <Text>{isComplete ? icons.success : icons.question}</Text>\n </Box>\n\n <Box flexDirection=\"column\">\n <Box marginRight={1}>\n <Text color={colors.highlighted}>{label}</Text>\n </Box>\n {isComplete ?\n <Text color={colors.body}>{value}</Text>\n : <Text color={colors.highlighted}>\n {placeholder ?\n value.length > 0 ?\n renderedValue\n : renderedPlaceholder\n : renderedValue}\n </Text>\n }\n {validationError ?\n <Box marginTop={0}>\n <Text color={colors.warning}>{validationError}</Text>\n </Box>\n : null}\n </Box>\n </Box>\n );\n}\n\n// partially based on https://github.com/vadimdemedes/ink-text-input/tree/0787c505415f0d059801d80600e4ccb0651385f3 (see https://github.com/vadimdemedes/ink-text-input/blob/0787c505415f0d059801d80600e4ccb0651385f3/license for license)\n"],
5
5
  "mappings": ";AAsMQ,cAGF,YAHE;AAtMR,OAAO,WAAW;AAClB,SAAQ,KAAoB,MAAM,gBAAe;AACjD,SAAQ,WAAW,gBAAe;AAElC,YAAY,YAAY;AACxB,YAAY,WAAW;AAwChB,gBAAS,UAAU;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA,OAAO;AAAA,EACP,cAAc;AAAA,EACd,QAAQ;AAAA,EACR;AAAA,EACA,aAAa;AAAA,EACb;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAmB;AACjB,MAAI,CAAC,iBAAiB,kBAAkB,IAAI,SAAS,EAAE;AACvD,MAAI,CAAC,OAAO,QAAQ,IAAI,SAAS;AAAA,IAC/B,eAAe,iBAAiB,IAAI;AAAA,IACpC,aAAa;AAAA,EACf,CAAC;AAED,YAAU,MAAM;AACd,aAAS,CAAC,kBAAkB;AAC1B,UAAI,CAAC,SAAS,CAAC,YAAY;AACzB,eAAO;AAAA,MACT;AAEA,UAAI,WAAW,iBAAiB;AAEhC,UAAI,cAAc,eAAe,SAAS,SAAS,GAAG;AACpD,eAAO;AAAA,UACL,cAAc,SAAS;AAAA,UACvB,aAAa;AAAA,QACf;AAAA,MACF;AAEA,aAAO;AAAA,IACT,CAAC;AAAA,EACH,GAAG,CAAC,eAAe,OAAO,UAAU,CAAC;AAErC,MAAI,QAAQ,OAAO,KAAK,OAAO,cAAc,MAAM,IAAI;AACvD,MAAI,gBAAgB;AACpB,MAAI,sBAAsB,cAAc,MAAM,OAAO,KAAK,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/form/createForm.tsx"],
4
- "sourcesContent": ["import {Box, type BoxProps} from 'ink';\nimport {useCallback} from 'react';\n\nimport {type Form} from './Form.js';\nimport {type FormConfig} from './FormConfig.js';\nimport {type FormProps} from './FormProps.js';\nimport {FormRow} from './FormRow.js';\n\n/**\n * Creates form component that contains individual rows with inputs based on the provided config.\n *\n * @param formConfig Form configuration.\n * @returns Form component.\n */\nexport function createForm<C extends FormConfig>(formConfig: C): Form<C> {\n let Form = ({\n rows,\n values: results,\n onChange,\n onComplete: onFinish,\n ...boxProps\n }: FormProps<C>) => {\n let handleChange = useCallback(\n (value: unknown, rowName: keyof C['rows']) => {\n if (onChange) {\n onChange({\n ...results,\n [rowName]: {\n ...results[rowName],\n value,\n },\n });\n }\n },\n [onChange, results],\n );\n\n let handleFinish = useCallback(\n (value: unknown, rowName: keyof C['rows']) => {\n onFinish({\n ...results,\n [rowName]: {\n value,\n isComplete: true,\n },\n });\n },\n [onFinish, results],\n );\n\n let inputElements = [];\n let activeInputName: null | string = null;\n\n for (let [rowName] of Object.entries(formConfig.rows)) {\n if (!results[rowName as keyof C['rows']].isComplete) {\n activeInputName = String(rowName);\n\n break;\n }\n }\n\n for (let [rowName, input] of Object.entries(formConfig.rows)) {\n if (results[rowName as keyof C['rows']].isComplete || rowName === activeInputName) {\n inputElements.push(\n <FormRow\n key={rowName}\n config={input}\n focus={rowName === activeInputName}\n isComplete={results[rowName as keyof C['rows']].isComplete}\n marginTop={inputElements.length === 0 ? 0 : 1}\n rowName={rowName}\n rows={rows}\n value={results[rowName as keyof C['rows']].value}\n onChange={handleChange}\n onComplete={handleFinish}\n />,\n );\n }\n }\n\n return (\n <Box {...(boxProps as BoxProps)} flexDirection=\"column\">\n {inputElements}\n </Box>\n );\n };\n\n return Object.assign(Form, {config: formConfig});\n}\n"],
4
+ "sourcesContent": ["import {Box, type BoxProps} from 'ink';\nimport {useCallback} from 'react';\n\nimport {type Form} from './Form.js';\nimport {type FormConfig} from './FormConfig.js';\nimport {type FormProps} from './FormProps.js';\nimport {FormRow} from './FormRow.js';\n\n/**\n * Creates form component that contains individual rows with inputs based on the provided config.\n *\n * @param formConfig Form configuration.\n * @returns Form component.\n */\nexport function createForm<C extends FormConfig>(formConfig: C): Form<C> {\n let Form = ({\n rows,\n values: results,\n onChange,\n onComplete: onFinish,\n ...boxProps\n }: FormProps<C>) => {\n let handleChange = useCallback(\n (value: unknown, rowName: keyof C['rows']) => {\n if (onChange) {\n onChange({\n ...results,\n [rowName]: {\n ...results[rowName],\n value,\n },\n });\n }\n },\n [onChange, results],\n );\n\n let handleFinish = useCallback(\n (value: unknown, rowName: keyof C['rows']) => {\n onFinish({\n ...results,\n [rowName]: {\n value,\n isComplete: true,\n },\n });\n },\n [onFinish, results],\n );\n\n let inputElements = [];\n let activeInputName: string | null = null;\n\n for (let [rowName] of Object.entries(formConfig.rows)) {\n if (!results[rowName as keyof C['rows']].isComplete) {\n activeInputName = String(rowName);\n\n break;\n }\n }\n\n for (let [rowName, input] of Object.entries(formConfig.rows)) {\n if (results[rowName as keyof C['rows']].isComplete || rowName === activeInputName) {\n inputElements.push(\n <FormRow\n key={rowName}\n config={input}\n focus={rowName === activeInputName}\n isComplete={results[rowName as keyof C['rows']].isComplete}\n marginTop={inputElements.length === 0 ? 0 : 1}\n rowName={rowName}\n rows={rows}\n value={results[rowName as keyof C['rows']].value}\n onChange={handleChange}\n onComplete={handleFinish}\n />,\n );\n }\n }\n\n return (\n <Box {...(boxProps as BoxProps)} flexDirection=\"column\">\n {inputElements}\n </Box>\n );\n };\n\n return Object.assign(Form, {config: formConfig});\n}\n"],
5
5
  "mappings": ";AAgEU;AAhEV,SAAQ,WAAyB;AACjC,SAAQ,mBAAkB;AAK1B,SAAQ,eAAc;AAQf,gBAAS,WAAiC,YAAwB;AACvE,MAAI,OAAO,CAAC;AAAA,IACV;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA,YAAY;AAAA,IACZ,GAAG;AAAA,EACL,MAAoB;AAClB,QAAI,e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,WAAU,CAAC;AACjD;",
6
6
  "names": []
7
7
  }
package/build/ui.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * as colors from './ui/colors.js';
2
- export * from './ui/ErrorDetail.js';
2
+ export type * from './ui/ErrorDetail.js';
3
3
  export * from './ui/Failure.js';
4
4
  export * from './ui/form.js';
5
5
  export * from './ui/getErrorDetail.js';
package/build/ui.js CHANGED
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  export * as colors from "./ui/colors.js";
3
- export * from "./ui/ErrorDetail.js";
4
3
  export * from "./ui/Failure.js";
5
4
  export * from "./ui/form.js";
6
5
  export * from "./ui/getErrorDetail.js";
package/build/ui.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../source/ui.ts"],
4
- "sourcesContent": ["export * as colors from './ui/colors.js';\nexport * from './ui/ErrorDetail.js';\nexport * from './ui/Failure.js';\nexport * from './ui/form.js';\nexport * from './ui/getErrorDetail.js';\nexport * from './ui/Header.js';\nexport * from './ui/Help.js';\nexport * as icons from './ui/icons.js';\nexport * from './ui/Spinner.js';\nexport * from './ui/useProgram.js';\n"],
5
- "mappings": ";AAAA,YAAY,YAAY;AACxB,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,YAAY,WAAW;AACvB,cAAc;AACd,cAAc;",
4
+ "sourcesContent": ["export * as colors from './ui/colors.js';\nexport type * from './ui/ErrorDetail.js';\nexport * from './ui/Failure.js';\nexport * from './ui/form.js';\nexport * from './ui/getErrorDetail.js';\nexport * from './ui/Header.js';\nexport * from './ui/Help.js';\nexport * as icons from './ui/icons.js';\nexport * from './ui/Spinner.js';\nexport * from './ui/useProgram.js';\n"],
5
+ "mappings": ";AAAA,YAAY,YAAY;AAExB,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,YAAY,WAAW;AACvB,cAAc;AACd,cAAc;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jakubmazanec/cli",
3
- "version": "0.3.5-unstable.91147a2",
3
+ "version": "0.3.5-unstable.9aff2d1",
4
4
  "description": "TypeScript-first library for building CLIs.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -27,10 +27,10 @@
27
27
  "typecheck": "tsc --project tsconfig.typecheck.json"
28
28
  },
29
29
  "dependencies": {
30
- "@jakubmazanec/args": "2.0.5-unstable.91147a2",
31
- "@jakubmazanec/error": "3.0.5-unstable.91147a2",
32
- "@jakubmazanec/ts-utils": "3.0.5-unstable.91147a2",
33
- "@jakubmazanec/zod-utils": "2.0.5-unstable.91147a2",
30
+ "@jakubmazanec/args": "2.0.5-unstable.9aff2d1",
31
+ "@jakubmazanec/error": "3.0.5-unstable.9aff2d1",
32
+ "@jakubmazanec/ts-utils": "3.0.5-unstable.9aff2d1",
33
+ "@jakubmazanec/zod-utils": "2.0.5-unstable.9aff2d1",
34
34
  "chalk": "^5.3.0",
35
35
  "fs-extra": "^11.2.0",
36
36
  "latest-version": "^9.0.0",
@@ -39,7 +39,7 @@
39
39
  "zod": "^3.23.8"
40
40
  },
41
41
  "devDependencies": {
42
- "@jakubmazanec/eslint-config": "4.0.0-unstable.91147a2",
42
+ "@jakubmazanec/eslint-config": "4.0.0-unstable.9aff2d1",
43
43
  "@types/fs-extra": "^11.0.4",
44
44
  "@types/lodash": "^4.17.13",
45
45
  "@types/node": "^22.9.0",
@@ -2,7 +2,7 @@
2
2
  import {type Argv, type OptionsConfig, type ParametersConfig} from '@jakubmazanec/args';
3
3
  import fs from 'fs-extra';
4
4
  import fetchLatestVersion from 'latest-version';
5
- import path from 'path';
5
+ import path from 'node:path';
6
6
  import {type ComponentType} from 'react';
7
7
  import {type FallbackProps} from 'react-error-boundary';
8
8
 
package/source/program.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  export * from './program/Command.js';
2
- export * from './program/CommandAction.js';
3
- export * from './program/CommandArguments.js';
4
- export * from './program/CommandOptions.js';
2
+ export type * from './program/CommandAction.js';
3
+ export type * from './program/CommandArguments.js';
4
+ export type * from './program/CommandOptions.js';
5
5
  export * from './program/getProgramDetail.js';
6
6
  export * from './program/Program.js';
7
- export * from './program/ProgramCreateOptions.js';
8
- export * from './program/ProgramDetail.js';
7
+ export type * from './program/ProgramCreateOptions.js';
8
+ export type * from './program/ProgramDetail.js';
9
9
  export * from './program/ProgramError.js';
10
- export * from './program/ProgramOptions.js';
11
- export * from './program/ProgramStreams.js';
10
+ export type * from './program/ProgramOptions.js';
11
+ export type * from './program/ProgramStreams.js';
@@ -9,13 +9,13 @@ import * as icons from './icons.js';
9
9
  /**
10
10
  * {@link Failure} component props.
11
11
  */
12
- export type FailureProps = {
12
+ export type FailureProps = BoxProps & {
13
13
  /** Error that describes a failure state. Function {@link getErrorDetail} is used for getting all the information from the error; you can use it to implement own retrieval logic and pass the result as `errorDetail` prop. */
14
14
  error: Error;
15
15
 
16
16
  /** Information about the failure state. Overrides information retireved from `error` prop. */
17
17
  errorDetail?: ErrorDetail;
18
- } & BoxProps;
18
+ };
19
19
 
20
20
  /**
21
21
  * A component that renders a failure state.
@@ -6,13 +6,13 @@ import {Spinner} from './Spinner.js';
6
6
  /**
7
7
  * {@link Header} component props.
8
8
  */
9
- export type HeaderProps = {
9
+ export type HeaderProps = BoxProps & {
10
10
  /** Icon (recommended is 1 character) to render before the header itself. */
11
11
  icon?: string;
12
12
 
13
13
  /** Show spinner instead of the icon. */
14
14
  showSpinner?: boolean;
15
- } & BoxProps;
15
+ };
16
16
 
17
17
  /**
18
18
  * Header component.
@@ -9,10 +9,10 @@ import * as icons from './icons.js';
9
9
  /**
10
10
  * {@link Help} component props.
11
11
  */
12
- export type HelpProps = {
12
+ export type HelpProps = BoxProps & {
13
13
  /** {@link Program} instance. */
14
14
  program: Program;
15
- } & BoxProps;
15
+ };
16
16
 
17
17
  /**
18
18
  * A component that renders help information.
@@ -6,4 +6,4 @@ import {type FormProps} from './FormProps.js';
6
6
  /**
7
7
  * Form component.
8
8
  */
9
- export type Form<C extends FormConfig> = {config: C} & FC<FormProps<C>>;
9
+ export type Form<C extends FormConfig> = FC<FormProps<C>> & {config: C};
@@ -33,7 +33,7 @@ type FormPropsRows<C extends FormConfig> = Pick<
33
33
  */
34
34
  export type FormProps<C extends FormConfig> =
35
35
  FormPropsRows<C> extends Record<number | string | symbol, never> ?
36
- {
36
+ BoxProps & {
37
37
  /** Props for each row. */
38
38
  rows?: null | undefined;
39
39
 
@@ -45,8 +45,8 @@ export type FormProps<C extends FormConfig> =
45
45
 
46
46
  /** Handler function that is called when the value is accepted. */
47
47
  onComplete: (formResult: FormValues<C>) => void;
48
- } & BoxProps
49
- : {
48
+ }
49
+ : BoxProps & {
50
50
  /** Props for each row. */
51
51
  rows: FormPropsRows<C>;
52
52
 
@@ -58,4 +58,4 @@ export type FormProps<C extends FormConfig> =
58
58
 
59
59
  /** Handler function that is called when the value is accepted. */
60
60
  onComplete: (formResult: FormValues<C>) => void;
61
- } & BoxProps;
61
+ };
@@ -10,7 +10,7 @@ import {TextInput} from './TextInput.js';
10
10
  /**
11
11
  * Form row component props.
12
12
  */
13
- type FormRowProps<C extends FormConfig> = {
13
+ type FormRowProps<C extends FormConfig> = BoxProps & {
14
14
  /** Form row configuration. */
15
15
  config: FormRowConfig;
16
16
 
@@ -35,7 +35,7 @@ type FormRowProps<C extends FormConfig> = {
35
35
 
36
36
  /** Indicates whether value has been accepted. Component in the row then doesn't accept more input. */
37
37
  isComplete: boolean;
38
- } & BoxProps;
38
+ };
39
39
 
40
40
  /**
41
41
  * Form row component.
@@ -10,7 +10,7 @@ import {type SelectInputItem} from './SelectInputItem.js';
10
10
  /**
11
11
  * {@linkcode SelectInput} component props.
12
12
  */
13
- type SelectInputProps = {
13
+ type SelectInputProps = BoxProps & {
14
14
  /** Text to display as a label. */
15
15
  label: string;
16
16
 
@@ -34,7 +34,7 @@ type SelectInputProps = {
34
34
 
35
35
  /** Indicates whether value has been accepted. Component then doesn't accept more input. */
36
36
  isComplete?: boolean | undefined;
37
- } & BoxProps;
37
+ };
38
38
 
39
39
  /**
40
40
  * Select input component.
@@ -8,7 +8,7 @@ import * as icons from '../icons.js';
8
8
  /**
9
9
  * Text input component props.
10
10
  */
11
- export type TextInputProps = {
11
+ export type TextInputProps = BoxProps & {
12
12
  /** Text to display as a label. */
13
13
  label: string;
14
14
 
@@ -38,7 +38,7 @@ export type TextInputProps = {
38
38
 
39
39
  /** Indicates whether value has been accepted. Component then doesn't accept more input. */
40
40
  isComplete?: boolean | undefined;
41
- } & BoxProps;
41
+ };
42
42
 
43
43
  /**
44
44
  * Text input component.
@@ -49,7 +49,7 @@ export function createForm<C extends FormConfig>(formConfig: C): Form<C> {
49
49
  );
50
50
 
51
51
  let inputElements = [];
52
- let activeInputName: null | string = null;
52
+ let activeInputName: string | null = null;
53
53
 
54
54
  for (let [rowName] of Object.entries(formConfig.rows)) {
55
55
  if (!results[rowName as keyof C['rows']].isComplete) {
package/source/ui.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * as colors from './ui/colors.js';
2
- export * from './ui/ErrorDetail.js';
2
+ export type * from './ui/ErrorDetail.js';
3
3
  export * from './ui/Failure.js';
4
4
  export * from './ui/form.js';
5
5
  export * from './ui/getErrorDetail.js';