ink-text-input
Advanced tools
Comparing version 4.0.3 to 5.0.0
@@ -1,4 +0,4 @@ | ||
import type { FC } from 'react'; | ||
/// <reference types="react" /> | ||
import type { Except } from 'type-fest'; | ||
interface Props { | ||
type Props = { | ||
/** | ||
@@ -37,6 +37,6 @@ * Text to display when `value` is empty. | ||
onSubmit?: (value: string) => void; | ||
} | ||
declare const TextInput: FC<Props>; | ||
}; | ||
declare function TextInput({ value: originalValue, placeholder, focus, mask, highlightPastedText, showCursor, onChange, onSubmit }: Props): JSX.Element; | ||
export default TextInput; | ||
interface UncontrolledProps extends Except<Props, 'value' | 'onChange'> { | ||
type UncontrolledProps = { | ||
/** | ||
@@ -46,3 +46,3 @@ * Initial value. | ||
initialValue?: string; | ||
} | ||
export declare const UncontrolledTextInput: FC<UncontrolledProps>; | ||
} & Except<Props, 'value' | 'onChange'>; | ||
export declare function UncontrolledTextInput({ initialValue, ...props }: UncontrolledProps): JSX.Element; |
@@ -1,14 +0,11 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.UncontrolledTextInput = void 0; | ||
const React = require("react"); | ||
const react_1 = require("react"); | ||
const ink_1 = require("ink"); | ||
const chalk = require("chalk"); | ||
const TextInput = ({ value: originalValue, placeholder = '', focus = true, mask, highlightPastedText = false, showCursor = true, onChange, onSubmit }) => { | ||
const [{ cursorOffset, cursorWidth }, setState] = react_1.useState({ | ||
import React, { useState, useEffect } from 'react'; | ||
import { Text, useInput } from 'ink'; | ||
import chalk from 'chalk'; | ||
function TextInput({ value: originalValue, placeholder = '', focus = true, mask, highlightPastedText = false, showCursor = true, onChange, onSubmit }) { | ||
const [state, setState] = useState({ | ||
cursorOffset: (originalValue || '').length, | ||
cursorWidth: 0 | ||
}); | ||
react_1.useEffect(() => { | ||
const { cursorOffset, cursorWidth } = state; | ||
useEffect(() => { | ||
setState(previousState => { | ||
@@ -41,8 +38,6 @@ if (!focus || !showCursor) { | ||
for (const char of value) { | ||
if (i >= cursorOffset - cursorActualWidth && i <= cursorOffset) { | ||
renderedValue += chalk.inverse(char); | ||
} | ||
else { | ||
renderedValue += char; | ||
} | ||
renderedValue += | ||
i >= cursorOffset - cursorActualWidth && i <= cursorOffset | ||
? chalk.inverse(char) | ||
: char; | ||
i++; | ||
@@ -54,3 +49,3 @@ } | ||
} | ||
ink_1.useInput((input, key) => { | ||
useInput((input, key) => { | ||
if (key.upArrow || | ||
@@ -114,3 +109,3 @@ key.downArrow || | ||
}, { isActive: focus }); | ||
return (React.createElement(ink_1.Text, null, placeholder | ||
return (React.createElement(Text, null, placeholder | ||
? value.length > 0 | ||
@@ -120,7 +115,8 @@ ? renderedValue | ||
: renderedValue)); | ||
}; | ||
exports.default = TextInput; | ||
exports.UncontrolledTextInput = ({ initialValue = '', ...props }) => { | ||
const [value, setValue] = react_1.useState(initialValue); | ||
return React.createElement(TextInput, Object.assign({}, props, { value: value, onChange: setValue })); | ||
}; | ||
} | ||
export default TextInput; | ||
export function UncontrolledTextInput({ initialValue = '', ...props }) { | ||
const [value, setValue] = useState(initialValue); | ||
return React.createElement(TextInput, { ...props, value: value, onChange: setValue }); | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "ink-text-input", | ||
"version": "4.0.3", | ||
"version": "5.0.0", | ||
"description": "Text input component for Ink", | ||
@@ -9,9 +9,12 @@ "license": "MIT", | ||
"name": "Vadim Demedes", | ||
"email": "vdemedes@gmail.com", | ||
"url": "github.com/vadimdemedes" | ||
"email": "vadimdemedes@hey.com", | ||
"url": "https://github.com/vadimdemedes" | ||
}, | ||
"main": "build", | ||
"types": "build/index.d.ts", | ||
"type": "module", | ||
"exports": { | ||
"types": "./build/index.d.ts", | ||
"default": "./build/index.js" | ||
}, | ||
"engines": { | ||
"node": ">=10" | ||
"node": ">=14.16" | ||
}, | ||
@@ -40,38 +43,36 @@ "scripts": { | ||
"dependencies": { | ||
"chalk": "^4.1.0", | ||
"type-fest": "^0.15.1" | ||
"chalk": "^5.2.0", | ||
"type-fest": "^3.6.1" | ||
}, | ||
"devDependencies": { | ||
"@ava/babel": "^1.0.1", | ||
"@babel/preset-react": "^7.10.1", | ||
"@sindresorhus/tsconfig": "^0.7.0", | ||
"@types/react": "^16.8.8", | ||
"@vdemedes/prettier-config": "^1.0.0", | ||
"ava": "^3.9.0", | ||
"delay": "^4.3.0", | ||
"eslint-config-xo-react": "^0.23.0", | ||
"eslint-plugin-react": "^7.20.0", | ||
"eslint-plugin-react-hooks": "^4.0.4", | ||
"husky": "^4.2.5", | ||
"ink": "^3.0.5", | ||
"ink-testing-library": "^2.0.0", | ||
"@sindresorhus/tsconfig": "^3.0.1", | ||
"@types/react": "^18.0.0", | ||
"@types/sinon": "^10.0.13", | ||
"@vdemedes/prettier-config": "^1.0.1", | ||
"ava": "^5.1.1", | ||
"delay": "^5.0.0", | ||
"eslint-config-xo-react": "^0.27.0", | ||
"eslint-plugin-react": "^7.32.2", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"ink": "^4.0.0", | ||
"ink-testing-library": "^3.0.0", | ||
"prettier": "^2.0.5", | ||
"pretty-quick": "^2.0.1", | ||
"react": "^17.0.0", | ||
"sinon": "^7.2.7", | ||
"typescript": "^3.9.5", | ||
"xo": "^0.32.0" | ||
"react": "^18.0.0", | ||
"sinon": "^15.0.1", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.9.5", | ||
"xo": "^0.53.0" | ||
}, | ||
"peerDependencies": { | ||
"ink": "^3.0.0-3", | ||
"react": "^16.5.2 || ^17.0.0" | ||
"ink": "^4.0.0", | ||
"react": "^18.0.0" | ||
}, | ||
"ava": { | ||
"babel": { | ||
"testOptions": { | ||
"presets": [ | ||
"@babel/preset-react" | ||
] | ||
} | ||
} | ||
"extensions": { | ||
"ts": "module", | ||
"tsx": "module" | ||
}, | ||
"nodeArguments": [ | ||
"--loader=ts-node/esm" | ||
] | ||
}, | ||
@@ -82,18 +83,8 @@ "xo": { | ||
], | ||
"plugins": [ | ||
"react" | ||
], | ||
"prettier": true, | ||
"rules": { | ||
"react/no-unused-prop-types": 0, | ||
"react/prop-types": 0, | ||
"unicorn/no-hex-escape": 0 | ||
} | ||
}, | ||
"prettier": "@vdemedes/prettier-config", | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "pretty-quick --staged" | ||
} | ||
} | ||
"prettier": "@vdemedes/prettier-config" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14776
17
6
Yes
163
+ Added@alcalzone/ansi-tokenize@0.1.3(transitive)
+ Addedansi-escapes@6.2.1(transitive)
+ Addedansi-regex@6.1.0(transitive)
+ Addedansi-styles@6.2.1(transitive)
+ Addedauto-bind@5.0.1(transitive)
+ Addedchalk@5.3.0(transitive)
+ Addedci-info@3.9.0(transitive)
+ Addedcli-boxes@3.0.0(transitive)
+ Addedcli-cursor@4.0.0(transitive)
+ Addedcli-truncate@3.1.0(transitive)
+ Addedcode-excerpt@4.0.0(transitive)
+ Addedconvert-to-spaces@2.0.1(transitive)
+ Addedeastasianwidth@0.2.0(transitive)
+ Addedemoji-regex@9.2.2(transitive)
+ Addedindent-string@5.0.0(transitive)
+ Addedink@4.4.1(transitive)
+ Addedis-ci@3.0.1(transitive)
+ Addedis-fullwidth-code-point@4.0.0(transitive)
+ Addedis-lower-case@2.0.2(transitive)
+ Addedis-upper-case@2.0.2(transitive)
+ Addedpatch-console@2.0.0(transitive)
+ Addedreact@18.3.1(transitive)
+ Addedreact-reconciler@0.29.2(transitive)
+ Addedrestore-cursor@4.0.0(transitive)
+ Addedscheduler@0.23.2(transitive)
+ Addedslice-ansi@5.0.06.0.0(transitive)
+ Addedstring-width@5.1.2(transitive)
+ Addedstrip-ansi@7.1.0(transitive)
+ Addedtslib@2.7.0(transitive)
+ Addedtype-fest@3.13.1(transitive)
+ Addedwidest-line@4.0.1(transitive)
+ Addedwrap-ansi@8.1.0(transitive)
+ Addedws@8.18.0(transitive)
+ Addedyoga-wasm-web@0.3.3(transitive)
- Removed@types/yoga-layout@1.9.2(transitive)
- Removedansi-escapes@4.3.2(transitive)
- Removedansi-regex@5.0.1(transitive)
- Removedansi-styles@4.3.0(transitive)
- Removedastral-regex@2.0.0(transitive)
- Removedauto-bind@4.0.0(transitive)
- Removedchalk@4.1.2(transitive)
- Removedci-info@2.0.0(transitive)
- Removedcli-boxes@2.2.1(transitive)
- Removedcli-cursor@3.1.0(transitive)
- Removedcli-truncate@2.1.0(transitive)
- Removedcode-excerpt@3.0.0(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removedconvert-to-spaces@1.0.2(transitive)
- Removedemoji-regex@8.0.0(transitive)
- Removedhas-flag@4.0.0(transitive)
- Removedindent-string@4.0.0(transitive)
- Removedink@3.2.0(transitive)
- Removedis-ci@2.0.0(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedpatch-console@1.0.0(transitive)
- Removedreact@17.0.2(transitive)
- Removedreact-devtools-core@4.28.5(transitive)
- Removedreact-reconciler@0.26.2(transitive)
- Removedrestore-cursor@3.1.0(transitive)
- Removedscheduler@0.20.2(transitive)
- Removedshell-quote@1.8.1(transitive)
- Removedslice-ansi@3.0.0(transitive)
- Removedstring-width@4.2.3(transitive)
- Removedstrip-ansi@6.0.1(transitive)
- Removedsupports-color@7.2.0(transitive)
- Removedtype-fest@0.15.10.21.3(transitive)
- Removedwidest-line@3.1.0(transitive)
- Removedwrap-ansi@6.2.0(transitive)
- Removedws@7.5.10(transitive)
- Removedyoga-layout-prebuilt@1.10.0(transitive)
Updatedchalk@^5.2.0
Updatedtype-fest@^3.6.1