mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2026-01-05 12:25:23 +01:00
npm install
This commit is contained in:
47
conf/site/node_modules/uncontrollable/.babelrc
generated
vendored
Normal file
47
conf/site/node_modules/uncontrollable/.babelrc
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"presets": [
|
||||
[
|
||||
"jason",
|
||||
{
|
||||
"debug": true,
|
||||
"targets": {
|
||||
"browsers": [
|
||||
">= .25%",
|
||||
"ie 11",
|
||||
"not dead",
|
||||
"not op_mini all",
|
||||
"not Android 4.4.3-4.4.4",
|
||||
"not ios_saf < 10",
|
||||
"not Chrome < 50", // caniuse lastest is reporting chrome 29
|
||||
"firefox ESR"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"@babel/preset-typescript"
|
||||
],
|
||||
"env": {
|
||||
"esm": {
|
||||
"presets": [
|
||||
[
|
||||
"jason",
|
||||
{
|
||||
"modules": false,
|
||||
"targets": {
|
||||
"browsers": [
|
||||
">= .25%",
|
||||
"ie 11",
|
||||
"not dead",
|
||||
"not op_mini all",
|
||||
"not Android 4.4.3-4.4.4",
|
||||
"not ios_saf < 10",
|
||||
"not Chrome < 50", // caniuse lastest is reporting chrome 29
|
||||
"firefox ESR"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
9
conf/site/node_modules/uncontrollable/.travis.yml
generated
vendored
Normal file
9
conf/site/node_modules/uncontrollable/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
language: node_js
|
||||
cache: yarn
|
||||
notifications:
|
||||
email: false
|
||||
node_js:
|
||||
- "stable"
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
134
conf/site/node_modules/uncontrollable/CHANGELOG.md
generated
vendored
Normal file
134
conf/site/node_modules/uncontrollable/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
# [7.2.0](https://github.com/jquense/uncontrollable/compare/v7.1.1...v7.2.0) (2021-01-25)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Allow React 17 types ([#50](https://github.com/jquense/uncontrollable/issues/50)) ([d1f5274](https://github.com/jquense/uncontrollable/commit/d1f527437b93af5baf4c1c038ee1d0afd4ce0d73))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [7.1.1](https://github.com/jquense/uncontrollable/compare/v7.1.0...v7.1.1) (2019-10-31)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* bump fstream from 1.0.11 to 1.0.12 ([#45](https://github.com/jquense/uncontrollable/issues/45)) ([97b1287](https://github.com/jquense/uncontrollable/commit/97b1287))
|
||||
* bump sshpk from 1.11.0 to 1.16.1 ([#46](https://github.com/jquense/uncontrollable/issues/46)) ([80e19d5](https://github.com/jquense/uncontrollable/commit/80e19d5))
|
||||
* clean up types ([bd29932](https://github.com/jquense/uncontrollable/commit/bd29932))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [7.1.0](https://github.com/jquense/uncontrollable/compare/v7.0.2...v7.1.0) (2019-10-30)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add useUncontrolledProp and types ([6e0837d](https://github.com/jquense/uncontrollable/commit/6e0837d))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [7.0.2](https://github.com/jquense/uncontrollable/compare/v7.0.1...v7.0.2) (2019-10-03)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* migrate unsafe lifecycle ([#40](https://github.com/jquense/uncontrollable/issues/40)) ([1607fff](https://github.com/jquense/uncontrollable/commit/1607fff))
|
||||
|
||||
## [7.0.1](https://github.com/jquense/uncontrollable/compare/v7.0.0...v7.0.1) (2019-09-06)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* rename License.txt to LICENSE ([#39](https://github.com/jquense/uncontrollable/issues/39)) ([171e821](https://github.com/jquense/uncontrollable/commit/171e821))
|
||||
|
||||
# [7.0.0](https://github.com/jquense/uncontrollable/compare/v6.2.3...v7.0.0) (2019-06-18)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* consistent exports ([#37](https://github.com/jquense/uncontrollable/issues/37)) ([6b51ec6](https://github.com/jquense/uncontrollable/commit/6b51ec6))
|
||||
|
||||
|
||||
### BREAKING CHANGES
|
||||
|
||||
* no more default export
|
||||
|
||||
- removed default export
|
||||
- name files properly
|
||||
|
||||
* Use default exports
|
||||
|
||||
## [6.2.3](https://github.com/jquense/uncontrollable/compare/v6.2.2...v6.2.3) (2019-06-17)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* republish again to fix build lol ([38f3bf8](https://github.com/jquense/uncontrollable/commit/38f3bf8))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [6.2.2](https://github.com/jquense/uncontrollable/compare/v6.2.1...v6.2.2) (2019-06-17)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* make default import ([e7ff375](https://github.com/jquense/uncontrollable/commit/e7ff375))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [6.2.1](https://github.com/jquense/uncontrollable/compare/v6.2.0...v6.2.1) (2019-06-17)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* bad publish ([82ef3fc](https://github.com/jquense/uncontrollable/commit/82ef3fc))
|
||||
|
||||
# [6.2.0](https://github.com/jquense/uncontrollable/compare/v6.1.0...v6.2.0) (2019-06-17)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add esm support ([2457bf3](https://github.com/jquense/uncontrollable/commit/2457bf3))
|
||||
|
||||
# [6.1.0](https://github.com/jquense/uncontrollable/compare/v6.0.0...v6.1.0) (2019-02-12)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add hook ([35c194d](https://github.com/jquense/uncontrollable/commit/35c194d))
|
||||
|
||||
|
||||
|
||||
<a name="6.0.0"></a>
|
||||
# [6.0.0](https://github.com/jquense/uncontrollable/compare/v5.1.0...v6.0.0) (2018-05-02)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Support forwardRef() ([a558754](https://github.com/jquense/uncontrollable/commit/a558754))
|
||||
|
||||
|
||||
### BREAKING CHANGES
|
||||
|
||||
* attached refs are now the original components, and not
|
||||
the uncontrolled component instance
|
||||
* removed getControlledInstance so there are no special
|
||||
methods on the uncontrolled component
|
||||
|
||||
<a name="5.1.0"></a>
|
||||
# [5.1.0](https://github.com/jquense/uncontrollable/compare/v5.0.0...v5.1.0) (2018-03-31)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* better release tooling ([41bfc32](https://github.com/jquense/uncontrollable/commit/41bfc32))
|
||||
21
conf/site/node_modules/uncontrollable/lib/LICENSE
generated
vendored
Normal file
21
conf/site/node_modules/uncontrollable/lib/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Jason Quense
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
146
conf/site/node_modules/uncontrollable/lib/README.md
generated
vendored
Normal file
146
conf/site/node_modules/uncontrollable/lib/README.md
generated
vendored
Normal file
@@ -0,0 +1,146 @@
|
||||
# uncontrollable
|
||||
|
||||
Wrap a controlled react component, to allow specific prop/handler pairs to be omitted by Component consumers. Uncontrollable allows you to write React components, with minimal state, and then wrap them in a component that will manage state for prop/handlers if they are excluded.
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm i -S uncontrollable
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
If you are a bit unsure on the _why_ of this module read the next section first. If you just want to see some real-world examples, check out [React Widgets](https://github.com/jquense/react-widgets) which makes [heavy use of this strategy](https://github.com/jquense/react-widgets/blob/5d1b530cb094cdc72f577fe01abe4a02dd265400/src/Multiselect.jsx#L521).
|
||||
|
||||
```js
|
||||
import { uncontrollable } from 'uncontrollable'
|
||||
```
|
||||
|
||||
### API
|
||||
|
||||
#### `uncontrollable(Component, propHandlerHash, [methods])`
|
||||
|
||||
- `Component`: is a valid react component, such as the result of `createClass`
|
||||
- `propHandlerHash`: define the pairs of prop/handlers you want to be uncontrollable, e.g. `{ value: 'onChange'}`
|
||||
- `methods`: since uncontrollable wraps your component in another component, methods are not immediately accessible. You can proxy them through by providing the names of the methods you want to continue to expose. **You don't need this if you are using React >= v16.3.0, the ref will automatically be forwarded to the uinderlying component**
|
||||
|
||||
For every prop you indicate as uncontrollable, the returned component will also accept an initial, `default` value for that prop. For example, `open` can be left uncontrolled but the initial value can be set via `defaultOpen={true}` if we want it to start open.
|
||||
|
||||
```js
|
||||
import { uncontrollable } from 'uncontrollable'
|
||||
|
||||
const UncontrolledCombobox = uncontrollable(Combobox, {
|
||||
value: 'onChange',
|
||||
open: 'onToggle',
|
||||
searchTerm: 'onSearch', //the current typed value (maybe it filters the dropdown list)
|
||||
})
|
||||
```
|
||||
|
||||
Since uncontrollable creates a new component that wraps your existing one, methods on your underlying component
|
||||
won't be immediately accessible. In general this sort of access is not idiomatic React, but it does have its place.
|
||||
The third argument of `uncontrollable()` is an optional array of method names you want uncontrollable to "pass through"
|
||||
to the original component.
|
||||
|
||||
```js
|
||||
let UncontrolledForm = uncontrollable(Form, { value: 'onChange' }, ['submit'])
|
||||
|
||||
//when you use a ref this will work
|
||||
this.refs.myForm.submit()
|
||||
```
|
||||
|
||||
#### `useUncontrolled(props, propsHandlerHash) => controlledProps`
|
||||
|
||||
A React hook that can be used in place of the above Higher order Component. It
|
||||
returns a complete set of `props` which are safe to spread through to a child element.
|
||||
|
||||
```js
|
||||
import { useUncontrolled } from 'uncontrollable'
|
||||
|
||||
const UncontrolledCombobox = props => {
|
||||
// filters out defaultValue, defaultOpen and returns controlled
|
||||
// versions of onChange, and onToggle.
|
||||
const controlledProps = useUncontrolled(props, {
|
||||
value: 'onChange',
|
||||
open: 'onToggle',
|
||||
})
|
||||
|
||||
return <Checkbox {...controlledProps} />
|
||||
}
|
||||
```
|
||||
|
||||
### Use Case
|
||||
|
||||
One of the strengths of React is its extensibility model, enabled by a common practice of pushing component state as high up the tree as possible. While great for enabling extremely flexible and easy to reason about components, this can produce a lot of boilerplate to wire components up with every use. For simple components (like an input) this is usually a matter of tying the input `value` prop to a parent state property via its `onChange` handler. Here is an extremely common pattern:
|
||||
|
||||
```jsx
|
||||
render() {
|
||||
return (
|
||||
<input type='text'
|
||||
value={this.state.value}
|
||||
onChange={ e => this.setState({ value: e.target.value })}
|
||||
/>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
This pattern moves the responsibility of managing the `value` from the input to its parent and mimics "two-way" databinding. Sometimes, however, there is no need for the parent to manage the input's state directly. In that case, all we want to do is set the initial `value` of the input and let the input manage it from then on. React deals with this through "uncontrolled" inputs, where if you don't indicate that you want to control the state of the input externally via a `value` prop it will just do the book-keeping for you.
|
||||
|
||||
This is a great pattern which we can make use of in our own Components. It is often best to build each component to be as stateless as possible, assuming that the parent will want to control everything that makes sense. Take a simple Dropdown component as an example
|
||||
|
||||
```js
|
||||
class SimpleDropdown extends React.Component {
|
||||
static propTypes = {
|
||||
value: React.PropTypes.string,
|
||||
onChange: React.PropTypes.func,
|
||||
open: React.PropTypes.bool,
|
||||
onToggle: React.PropTypes.func,
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<input
|
||||
value={this.props.value}
|
||||
onChange={e => this.props.onChange(e.target.value)}
|
||||
/>
|
||||
<button onClick={e => this.props.onToggle(!this.props.open)}>
|
||||
open
|
||||
</button>
|
||||
{this.props.open && (
|
||||
<ul className="open">
|
||||
<li>option 1</li>
|
||||
<li>option 2</li>
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Notice how we don't track any state in our simple dropdown? This is great because a consumer of our module will have the all the flexibility to decide what the behavior of the dropdown should be. Also notice our public API (propTypes), it consists of common pattern: a property we want set (`value`, `open`), and a set of handlers that indicate _when_ we want them set (`onChange`, `onToggle`). It is up to the parent component to change the `value` and `open` props in response to the handlers.
|
||||
|
||||
While this pattern offers an excellent amount of flexibility to consumers, it also requires them to write a bunch of boilerplate code that probably won't change much from use to use. In all likelihood they will always want to set `open` in response to `onToggle`, and only in rare cases will want to override that behavior. This is where the controlled/uncontrolled pattern comes in.
|
||||
|
||||
We want to just handle the open/onToggle case ourselves if the consumer doesn't provide a `open` prop (indicating that they want to control it). Rather than complicating our dropdown component with all that logic, obscuring the business logic of our dropdown, we can add it later, by taking our dropdown and wrapping it inside another component that handles that for us.
|
||||
|
||||
`uncontrollable` allows you separate out the logic necessary to create controlled/uncontrolled inputs letting you focus on creating a completely controlled input and wrapping it later. This tends to be a lot simpler to reason about as well.
|
||||
|
||||
```js
|
||||
import { uncontrollable } from 'uncontrollable';
|
||||
|
||||
const UncontrollableDropdown = uncontrollable(SimpleDropdown, {
|
||||
value: 'onChange',
|
||||
open: 'onToggle'
|
||||
})
|
||||
|
||||
<UncontrollableDropdown
|
||||
value={this.state.val} // we can still control these props if we want
|
||||
onChange={val => this.setState({ val })}
|
||||
defaultOpen={true} /> // or just let the UncontrollableDropdown handle it
|
||||
// and we just set an initial value (or leave it out completely)!
|
||||
```
|
||||
|
||||
Now we don't need to worry about the open onToggle! The returned component will track `open` for us by assuming that it should just set `open` to whatever `onToggle` returns. If we _do_ want to worry about it we can just provide `open` and `onToggle` props and the uncontrolled input will just pass them through.
|
||||
|
||||
The above is a contrived example but it allows you to wrap even more complex Components, giving you a lot of flexibility in the API you can offer a consumer of your Component. For every pair of prop/handlers you also get a defaultProp of the form "default[PropName]" so `value` -> `defaultValue`, and `open` -> `defaultOpen`, etc. [React Widgets](https://github.com/jquense/react-widgets) makes heavy use of this strategy, you can see it in action here: https://github.com/jquense/react-widgets/blob/5d1b530cb094cdc72f577fe01abe4a02dd265400/src/Multiselect.jsx#L521
|
||||
@@ -1,9 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||
|
||||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = uncontrollable;
|
||||
|
||||
@@ -21,6 +21,8 @@ var _invariant = _interopRequireDefault(require("invariant"));
|
||||
|
||||
var Utils = _interopRequireWildcard(require("./utils"));
|
||||
|
||||
var _jsxFileName = "/Users/jquense/src/uncontrollable/src/uncontrollable.js";
|
||||
|
||||
function uncontrollable(Component, controlledValues, methods) {
|
||||
if (methods === void 0) {
|
||||
methods = [];
|
||||
@@ -161,7 +163,12 @@ function uncontrollable(Component, controlledValues, methods) {
|
||||
if (_react.default.forwardRef) {
|
||||
WrappedComponent = _react.default.forwardRef(function (props, ref) {
|
||||
return _react.default.createElement(UncontrolledComponent, (0, _extends3.default)({}, props, {
|
||||
innerRef: ref
|
||||
innerRef: ref,
|
||||
__source: {
|
||||
fileName: _jsxFileName,
|
||||
lineNumber: 128
|
||||
},
|
||||
__self: this
|
||||
}));
|
||||
});
|
||||
WrappedComponent.propTypes = UncontrolledComponent.propTypes;
|
||||
@@ -1,6 +1,7 @@
|
||||
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
|
||||
var _jsxFileName = "/Users/jquense/src/uncontrollable/src/uncontrollable.js";
|
||||
import React from 'react';
|
||||
import { polyfill } from 'react-lifecycles-compat';
|
||||
import invariant from 'invariant';
|
||||
@@ -146,7 +147,12 @@ export default function uncontrollable(Component, controlledValues, methods) {
|
||||
if (React.forwardRef) {
|
||||
WrappedComponent = React.forwardRef(function (props, ref) {
|
||||
return React.createElement(UncontrolledComponent, _extends({}, props, {
|
||||
innerRef: ref
|
||||
innerRef: ref,
|
||||
__source: {
|
||||
fileName: _jsxFileName,
|
||||
lineNumber: 128
|
||||
},
|
||||
__self: this
|
||||
}));
|
||||
});
|
||||
WrappedComponent.propTypes = UncontrolledComponent.propTypes;
|
||||
69
conf/site/node_modules/uncontrollable/lib/hook.js
generated
vendored
Normal file
69
conf/site/node_modules/uncontrollable/lib/hook.js
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.useUncontrolledProp = useUncontrolledProp;
|
||||
exports.default = useUncontrolled;
|
||||
|
||||
var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
||||
|
||||
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
||||
|
||||
var _react = require("react");
|
||||
|
||||
var Utils = _interopRequireWildcard(require("./utils"));
|
||||
|
||||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
||||
|
||||
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
||||
|
||||
function useUncontrolledProp(propValue, defaultValue, handler) {
|
||||
var wasPropRef = (0, _react.useRef)(propValue !== undefined);
|
||||
|
||||
var _useState = (0, _react.useState)(defaultValue),
|
||||
stateValue = _useState[0],
|
||||
setState = _useState[1];
|
||||
|
||||
var isProp = propValue !== undefined;
|
||||
var wasProp = wasPropRef.current;
|
||||
wasPropRef.current = isProp;
|
||||
/**
|
||||
* If a prop switches from controlled to Uncontrolled
|
||||
* reset its value to the defaultValue
|
||||
*/
|
||||
|
||||
if (!isProp && wasProp && stateValue !== defaultValue) {
|
||||
setState(defaultValue);
|
||||
}
|
||||
|
||||
return [isProp ? propValue : stateValue, (0, _react.useCallback)(function (value) {
|
||||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
||||
args[_key - 1] = arguments[_key];
|
||||
}
|
||||
|
||||
if (handler) handler.apply(void 0, [value].concat(args));
|
||||
setState(value);
|
||||
}, [handler])];
|
||||
}
|
||||
|
||||
function useUncontrolled(props, config) {
|
||||
return Object.keys(config).reduce(function (result, fieldName) {
|
||||
var _extends2;
|
||||
|
||||
var _ref = result,
|
||||
defaultValue = _ref[Utils.defaultKey(fieldName)],
|
||||
propsValue = _ref[fieldName],
|
||||
rest = (0, _objectWithoutPropertiesLoose2.default)(_ref, [Utils.defaultKey(fieldName), fieldName].map(_toPropertyKey));
|
||||
|
||||
var handlerName = config[fieldName];
|
||||
|
||||
var _useUncontrolledProp = useUncontrolledProp(propsValue, defaultValue, props[handlerName]),
|
||||
value = _useUncontrolledProp[0],
|
||||
handler = _useUncontrolledProp[1];
|
||||
|
||||
return (0, _extends3.default)({}, rest, (_extends2 = {}, _extends2[fieldName] = value, _extends2[handlerName] = handler, _extends2));
|
||||
}, props);
|
||||
}
|
||||
17
conf/site/node_modules/uncontrollable/lib/index.js
generated
vendored
Normal file
17
conf/site/node_modules/uncontrollable/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||
|
||||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.useUncontrolledProp = exports.uncontrollable = exports.useUncontrolled = void 0;
|
||||
|
||||
var _hook = _interopRequireWildcard(require("./hook"));
|
||||
|
||||
exports.useUncontrolled = _hook.default;
|
||||
exports.useUncontrolledProp = _hook.useUncontrolledProp;
|
||||
|
||||
var _uncontrollable = _interopRequireDefault(require("./uncontrollable"));
|
||||
|
||||
exports.uncontrollable = _uncontrollable.default;
|
||||
45
conf/site/node_modules/uncontrollable/lib/package.json
generated
vendored
Normal file
45
conf/site/node_modules/uncontrollable/lib/package.json
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "uncontrollable",
|
||||
"version": "7.2.0",
|
||||
"description": "Wrap a controlled react component, to allow specific prop/handler pairs to be uncontrolled",
|
||||
"author": {
|
||||
"name": "Jason Quense",
|
||||
"email": "monastic.panic@gmail.com"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/jquense/uncontrollable.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"main": "cjs/index.js",
|
||||
"module": "esm/index.js",
|
||||
"keywords": [
|
||||
"uncontrolled-component",
|
||||
"react-component",
|
||||
"input",
|
||||
"controlled",
|
||||
"uncontrolled",
|
||||
"form"
|
||||
],
|
||||
"publishConfig": {
|
||||
"directory": "lib"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=15.0.0"
|
||||
},
|
||||
"jest": {
|
||||
"rootDir": "./test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.6.3",
|
||||
"@types/react": ">=16.9.11",
|
||||
"invariant": "^2.2.4",
|
||||
"react-lifecycles-compat": "^3.0.4"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/jquense/uncontrollable/issues"
|
||||
},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"homepage": "https://github.com/jquense/uncontrollable#readme",
|
||||
"_id": "uncontrollable@7.1.0"
|
||||
}
|
||||
59
conf/site/node_modules/uncontrollable/lib/utils.js
generated
vendored
Normal file
59
conf/site/node_modules/uncontrollable/lib/utils.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.uncontrolledPropTypes = uncontrolledPropTypes;
|
||||
exports.isProp = isProp;
|
||||
exports.defaultKey = defaultKey;
|
||||
exports.canAcceptRef = canAcceptRef;
|
||||
|
||||
var _invariant = _interopRequireDefault(require("invariant"));
|
||||
|
||||
var noop = function noop() {};
|
||||
|
||||
function readOnlyPropType(handler, name) {
|
||||
return function (props, propName) {
|
||||
if (props[propName] !== undefined) {
|
||||
if (!props[handler]) {
|
||||
return new Error("You have provided a `" + propName + "` prop to `" + name + "` " + ("without an `" + handler + "` handler prop. This will render a read-only field. ") + ("If the field should be mutable use `" + defaultKey(propName) + "`. ") + ("Otherwise, set `" + handler + "`."));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function uncontrolledPropTypes(controlledValues, displayName) {
|
||||
var propTypes = {};
|
||||
Object.keys(controlledValues).forEach(function (prop) {
|
||||
// add default propTypes for folks that use runtime checks
|
||||
propTypes[defaultKey(prop)] = noop;
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
var handler = controlledValues[prop];
|
||||
!(typeof handler === 'string' && handler.trim().length) ? process.env.NODE_ENV !== "production" ? (0, _invariant.default)(false, 'Uncontrollable - [%s]: the prop `%s` needs a valid handler key name in order to make it uncontrollable', displayName, prop) : invariant(false) : void 0;
|
||||
propTypes[prop] = readOnlyPropType(handler, displayName);
|
||||
}
|
||||
});
|
||||
return propTypes;
|
||||
}
|
||||
|
||||
function isProp(props, prop) {
|
||||
return props[prop] !== undefined;
|
||||
}
|
||||
|
||||
function defaultKey(key) {
|
||||
return 'default' + key.charAt(0).toUpperCase() + key.substr(1);
|
||||
}
|
||||
/**
|
||||
* Copyright (c) 2013-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
|
||||
function canAcceptRef(component) {
|
||||
return !!component && (typeof component !== 'function' || component.prototype && component.prototype.isReactComponent);
|
||||
}
|
||||
1
conf/site/node_modules/uncontrollable/manual-releases.md
generated
vendored
Normal file
1
conf/site/node_modules/uncontrollable/manual-releases.md
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
times manually bumped: 1
|
||||
113
conf/site/node_modules/uncontrollable/package.json
generated
vendored
113
conf/site/node_modules/uncontrollable/package.json
generated
vendored
@@ -1,51 +1,18 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"uncontrollable@7.1.1",
|
||||
"/home/henry/Documents/git/Speedtest-tracker-docker/conf/site"
|
||||
]
|
||||
],
|
||||
"_from": "uncontrollable@7.1.1",
|
||||
"_id": "uncontrollable@7.1.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-EcPYhot3uWTS3w00R32R2+vS8Vr53tttrvMj/yA1uYRhf8hbTG2GyugGqWDY0qIskxn0uTTojVd6wPYW9ZEf8Q==",
|
||||
"_location": "/uncontrollable",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "uncontrollable@7.1.1",
|
||||
"name": "uncontrollable",
|
||||
"escapedName": "uncontrollable",
|
||||
"rawSpec": "7.1.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "7.1.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/react-bootstrap",
|
||||
"/react-overlays"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/uncontrollable/-/uncontrollable-7.1.1.tgz",
|
||||
"_spec": "7.1.1",
|
||||
"_where": "/home/henry/Documents/git/Speedtest-tracker-docker/conf/site",
|
||||
"name": "uncontrollable",
|
||||
"version": "7.2.1",
|
||||
"description": "Wrap a controlled react component, to allow specific prop/handler pairs to be uncontrolled",
|
||||
"author": {
|
||||
"name": "Jason Quense",
|
||||
"email": "monastic.panic@gmail.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/jquense/uncontrollable/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.6.3",
|
||||
"@types/react": "^16.9.11",
|
||||
"invariant": "^2.2.4",
|
||||
"react-lifecycles-compat": "^3.0.4"
|
||||
},
|
||||
"description": "Wrap a controlled react component, to allow specific prop/handler pairs to be uncontrolled",
|
||||
"homepage": "https://github.com/jquense/uncontrollable#readme",
|
||||
"jest": {
|
||||
"rootDir": "./test"
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/jquense/uncontrollable.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"main": "lib/cjs/index.js",
|
||||
"module": "lib/esm/index.js",
|
||||
"keywords": [
|
||||
"uncontrolled-component",
|
||||
"react-component",
|
||||
@@ -54,19 +21,61 @@
|
||||
"uncontrolled",
|
||||
"form"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "cjs/index.js",
|
||||
"module": "esm/index.js",
|
||||
"name": "uncontrollable",
|
||||
"peerDependencies": {
|
||||
"react": ">=15.0.0"
|
||||
"scripts": {
|
||||
"test": "jest",
|
||||
"tdd": "jest --watch",
|
||||
"lint": "eslint src test",
|
||||
"build": "build src",
|
||||
"prepublishOnly": "npm run build"
|
||||
},
|
||||
"publishConfig": {
|
||||
"directory": "lib"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/jquense/uncontrollable.git"
|
||||
"peerDependencies": {
|
||||
"react": ">=15.0.0"
|
||||
},
|
||||
"version": "7.1.1"
|
||||
"jest": {
|
||||
"rootDir": "./test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@4c/build": "^2.0.1",
|
||||
"@4c/semantic-release-config": "^2.0.3",
|
||||
"@4c/tsconfig": "^0.3.0",
|
||||
"@babel/cli": "^7.6.4",
|
||||
"@babel/core": "^7.6.4",
|
||||
"@babel/preset-typescript": "^7.6.0",
|
||||
"@typescript-eslint/eslint-plugin": "^2.5.0",
|
||||
"@typescript-eslint/parser": "^2.5.0",
|
||||
"babel-core": "^7.0.0-0",
|
||||
"babel-jest": "^24.9.0",
|
||||
"babel-preset-jason": "^6.0.1",
|
||||
"cpy": "^7.3.0",
|
||||
"enzyme": "^3.10.0",
|
||||
"enzyme-adapter-react-16": "^1.15.1",
|
||||
"eslint": "^6.6.0",
|
||||
"eslint-config-4catalyzer-typescript": "^1.1.0",
|
||||
"eslint-config-jason": "^6.1.0",
|
||||
"eslint-config-prettier": "^6.5.0",
|
||||
"eslint-plugin-import": "^2.18.2",
|
||||
"eslint-plugin-react": "^7.16.0",
|
||||
"jest": "^24.9.0",
|
||||
"prop-types": "^15.7.2",
|
||||
"react": "^16.11.0",
|
||||
"react-dom": "^16.11.0",
|
||||
"release-script": "^1.0.2",
|
||||
"rimraf": "^3.0.0",
|
||||
"typescript": "^3.6.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.6.3",
|
||||
"@types/react": ">=16.9.11",
|
||||
"invariant": "^2.2.4",
|
||||
"react-lifecycles-compat": "^3.0.4"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/jquense/uncontrollable/issues"
|
||||
},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"homepage": "https://github.com/jquense/uncontrollable#readme",
|
||||
"_id": "uncontrollable@7.1.0"
|
||||
}
|
||||
|
||||
5
conf/site/node_modules/uncontrollable/test/.eslintrc
generated
vendored
Normal file
5
conf/site/node_modules/uncontrollable/test/.eslintrc
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"rules": {
|
||||
"no-console": "off"
|
||||
}
|
||||
}
|
||||
466
conf/site/node_modules/uncontrollable/test/test.js
generated
vendored
Normal file
466
conf/site/node_modules/uncontrollable/test/test.js
generated
vendored
Normal file
@@ -0,0 +1,466 @@
|
||||
import Enzyme, { mount } from 'enzyme'
|
||||
import Adapter from 'enzyme-adapter-react-16'
|
||||
/* eslint-env jest */
|
||||
/* eslint-disable react/prop-types */
|
||||
import PropTypes from 'prop-types'
|
||||
import React from 'react'
|
||||
import { uncontrollable, useUncontrolled } from '../src'
|
||||
|
||||
Enzyme.configure({ adapter: new Adapter() })
|
||||
|
||||
describe('uncontrollable', () => {
|
||||
var Base
|
||||
|
||||
beforeEach(() => {
|
||||
Base = class extends React.Component {
|
||||
static propTypes = {
|
||||
value: PropTypes.number,
|
||||
checked: PropTypes.bool,
|
||||
onChange: PropTypes.func,
|
||||
|
||||
open: PropTypes.bool,
|
||||
onToggle: PropTypes.func,
|
||||
|
||||
onRender: PropTypes.func,
|
||||
}
|
||||
|
||||
handleChange = val => {
|
||||
var target = this.input
|
||||
|
||||
if (val) target.value = val
|
||||
|
||||
this.props.onChange(val)
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.props.onRender) this.props.onRender(this.props)
|
||||
|
||||
const { value, checked } = this.props
|
||||
|
||||
return (
|
||||
<div>
|
||||
<button onClick={this.props.onToggle}>toggle</button>
|
||||
{this.props.open && <span className="open">open!</span>}
|
||||
<input
|
||||
className="valueInput"
|
||||
ref={r => {
|
||||
this.input = r
|
||||
}}
|
||||
value={value == null ? '' : value}
|
||||
onChange={e => this.props.onChange(e.value)}
|
||||
/>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={checked ? '' : null}
|
||||
value={value == null ? '' : value}
|
||||
onChange={e => this.props.onChange(e.checked)}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
foo(num) {
|
||||
return num + num
|
||||
}
|
||||
|
||||
bar = () => {
|
||||
return 'value: ' + this.props.value
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it('should warn when handlers are missing', () => {
|
||||
var Control = uncontrollable(Base, { value: 'onChange' })
|
||||
|
||||
expect(Control.propTypes.value({ value: 3 }, 'value').message).toContain(
|
||||
'You have provided a `value` prop to `Base` without an `onChange` ' +
|
||||
'handler prop. This will render a read-only field.'
|
||||
)
|
||||
})
|
||||
|
||||
it('should include default PropTypes', () => {
|
||||
var Control = uncontrollable(Base, { value: 'onChange' })
|
||||
|
||||
expect(Control.propTypes.defaultValue).not.toBeNull()
|
||||
})
|
||||
|
||||
it('should adjust displayName', () => {
|
||||
var Control = uncontrollable(Base, { value: 'onChange' })
|
||||
|
||||
expect(mount(<Control />).find('Uncontrolled(Base)')).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('should expose the original component', () => {
|
||||
var Control = uncontrollable(Base, { value: 'onChange' })
|
||||
|
||||
expect(Control.ControlledComponent).toEqual(Base)
|
||||
})
|
||||
|
||||
describe('without forwardRef()', () => {
|
||||
let forwardRef
|
||||
|
||||
beforeEach(() => {
|
||||
forwardRef = React.forwardRef
|
||||
delete React.forwardRef
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
React.forwardRef = forwardRef
|
||||
})
|
||||
|
||||
it('should forward methods', () => {
|
||||
var Control = uncontrollable(Base, { value: 'onChange' }, ['foo', 'bar'])
|
||||
|
||||
let wrapper = mount(<Control value={5} onChange={() => {}} />)
|
||||
const instance = wrapper.instance()
|
||||
|
||||
expect(instance.constructor.name).toBe('UncontrolledComponent')
|
||||
|
||||
expect(typeof instance.foo).toBe('function')
|
||||
expect(typeof instance.bar).toBe('function')
|
||||
|
||||
expect(instance.foo(10)).toEqual(20)
|
||||
expect(instance.bar()).toEqual('value: 5')
|
||||
})
|
||||
|
||||
it('should pass through uncontrollables', () => {
|
||||
let Control = uncontrollable(Base, { value: 'onChange' }, ['foo'])
|
||||
let instance = mount(<Control defaultValue={10} defaultOpen />).instance()
|
||||
|
||||
expect(typeof instance.foo).toEqual('function')
|
||||
expect(instance.foo(2)).toEqual(4)
|
||||
expect(instance.inner).toEqual(expect.anything())
|
||||
})
|
||||
|
||||
it('should work with stateless components', () => {
|
||||
jest.spyOn(console, 'error')
|
||||
|
||||
var Control = uncontrollable(() => <span />, { value: 'onChange' })
|
||||
|
||||
expect(
|
||||
mount(<Control defaultValue={10} defaultOpen />).instance().inner
|
||||
).not.toEqual(expect.anything())
|
||||
|
||||
expect(console.error).not.toHaveBeenCalled()
|
||||
console.error.mockRestore()
|
||||
})
|
||||
})
|
||||
|
||||
it('should passthrough ref', () => {
|
||||
let Control = uncontrollable(Base, { value: 'onChange' })
|
||||
|
||||
class Example extends React.Component {
|
||||
render() {
|
||||
return <Control ref="control" defaultValue={10} defaultOpen />
|
||||
}
|
||||
}
|
||||
|
||||
expect(mount(<Example />).instance().refs.control instanceof Base).toEqual(
|
||||
true
|
||||
)
|
||||
})
|
||||
|
||||
it('should compose ref with method passthrough', () => {
|
||||
let Control = uncontrollable(Base, { value: 'onChange' }, ['foo'])
|
||||
let ref = null
|
||||
|
||||
class Example extends React.Component {
|
||||
render() {
|
||||
return <Control ref={r => (ref = r)} defaultValue={10} defaultOpen />
|
||||
}
|
||||
}
|
||||
|
||||
mount(<Example />)
|
||||
|
||||
expect(ref instanceof Base).toEqual(true)
|
||||
})
|
||||
|
||||
it('should work with forwardRef components', () => {
|
||||
const OtherBase = React.forwardRef((props, ref) => (
|
||||
<Base {...props} ref={ref} />
|
||||
))
|
||||
let Control = uncontrollable(OtherBase, { value: 'onChange' })
|
||||
let ref
|
||||
class Example extends React.Component {
|
||||
render() {
|
||||
return <Control ref={r => (ref = r)} defaultValue={10} defaultOpen />
|
||||
}
|
||||
}
|
||||
mount(<Example />)
|
||||
|
||||
expect(ref instanceof Base).toEqual(true)
|
||||
})
|
||||
|
||||
it('should warn when passing through uncontrollables to stateless components', () => {
|
||||
expect(() => {
|
||||
uncontrollable(() => null, { value: 'onChange' }, ['foo'])
|
||||
}).toThrow(/stateless function components.+Component.+foo/g)
|
||||
})
|
||||
|
||||
it('should track internally if not specified', () => {
|
||||
var Control = uncontrollable(Base, { value: 'onChange' })
|
||||
|
||||
let inst = mount(<Control />)
|
||||
|
||||
inst
|
||||
.find('input')
|
||||
.first()
|
||||
.simulate('change', { value: 42 })
|
||||
|
||||
expect(inst.children().instance().state.values.value).toEqual(42)
|
||||
})
|
||||
|
||||
it('should allow for defaultProp', () => {
|
||||
let Control = uncontrollable(Base, {
|
||||
value: 'onChange',
|
||||
open: 'onToggle',
|
||||
})
|
||||
|
||||
let inst = mount(<Control defaultValue={10} defaultOpen />)
|
||||
|
||||
inst.find('.open').first()
|
||||
|
||||
inst
|
||||
.find('input')
|
||||
.first()
|
||||
.tap(inst => expect(inst.getDOMNode().value).toEqual('10'))
|
||||
.simulate('change', { value: 42 })
|
||||
|
||||
expect(inst.children().instance().state.values.value).toEqual(42)
|
||||
})
|
||||
|
||||
it('should not forward default props through', () => {
|
||||
let Control = uncontrollable(Base, {
|
||||
value: 'onChange',
|
||||
open: 'onToggle',
|
||||
})
|
||||
|
||||
let inst = mount(<Control defaultValue={10} defaultOpen />)
|
||||
|
||||
let props = inst.find(Base).props()
|
||||
|
||||
expect(Object.keys(props)).not.toEqual(
|
||||
expect.arrayContaining(['defaultValue', 'defaultOpen'])
|
||||
)
|
||||
|
||||
expect(Object.keys(props)).toEqual(
|
||||
expect.arrayContaining(['value', 'open'])
|
||||
)
|
||||
})
|
||||
|
||||
it('should not throw when not batching', () => {
|
||||
let spy = jest.fn()
|
||||
|
||||
let Control = uncontrollable(Base, {
|
||||
value: 'onChange',
|
||||
open: 'onToggle',
|
||||
})
|
||||
|
||||
let inst = mount(<Control defaultValue={10} defaultOpen onChange={spy} />)
|
||||
let base = inst.find(Base).instance()
|
||||
|
||||
inst.find('.open')
|
||||
|
||||
expect(() => base.handleChange(42)).not.toThrow()
|
||||
|
||||
expect(spy).toHaveBeenCalledTimes(1)
|
||||
expect(inst.children().instance().state.values.value).toEqual(42)
|
||||
})
|
||||
|
||||
it('should update in the right order when controlled', () => {
|
||||
var Control = uncontrollable(Base, { value: 'onChange' }),
|
||||
spy = jest.fn()
|
||||
|
||||
class Parent extends React.Component {
|
||||
state = { value: 5 }
|
||||
render() {
|
||||
return (
|
||||
<Control
|
||||
onRender={spy}
|
||||
value={this.state.value}
|
||||
onChange={value => this.setState({ value })}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
mount(<Parent />)
|
||||
.find('input')
|
||||
.first()
|
||||
.simulate('change', { value: 42 })
|
||||
|
||||
expect(spy.mock.calls.length).toEqual(2)
|
||||
expect(spy.mock.calls[0][0].value).toEqual(5)
|
||||
expect(spy.mock.calls[1][0].value).toEqual(42)
|
||||
})
|
||||
|
||||
it('should update in the right order', () => {
|
||||
var Control = uncontrollable(Base, { value: 'onChange' }),
|
||||
spy = jest.fn()
|
||||
|
||||
class Parent extends React.Component {
|
||||
state = { value: 5 }
|
||||
render() {
|
||||
return <Control onRender={spy} defaultValue={this.state.value} />
|
||||
}
|
||||
}
|
||||
|
||||
var inst = mount(<Parent />)
|
||||
|
||||
inst
|
||||
.find('input')
|
||||
.first()
|
||||
.simulate('change', { value: 42 })
|
||||
|
||||
expect(spy.mock.calls.length).toEqual(2)
|
||||
expect(spy.mock.calls[0][0].value).toEqual(5)
|
||||
expect(spy.mock.calls[1][0].value).toEqual(42)
|
||||
|
||||
spy.mockReset()
|
||||
|
||||
inst
|
||||
.find(Base)
|
||||
.instance()
|
||||
.handleChange(84)
|
||||
|
||||
expect(spy.mock.calls.length).toEqual(1)
|
||||
expect(spy.mock.calls[0][0].value).toEqual(84)
|
||||
})
|
||||
|
||||
it('should revert to defaultProp when switched to uncontrollable', () => {
|
||||
var Control = uncontrollable(Base, { value: 'onChange' }),
|
||||
spy = jest.fn()
|
||||
|
||||
class Parent extends React.Component {
|
||||
state = { value: 5, defaultValue: 6 }
|
||||
render() {
|
||||
return (
|
||||
<Control
|
||||
onRender={spy}
|
||||
value={this.state.value}
|
||||
defaultValue={this.state.defaultValue}
|
||||
onChange={value => this.setState({ value })}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
var inst = mount(<Parent />)
|
||||
|
||||
expect(spy.mock.calls.length).toEqual(1)
|
||||
expect(spy.mock.calls[0][0].value).toEqual(5)
|
||||
|
||||
inst.setState({ value: undefined })
|
||||
|
||||
expect(spy.mock.calls.length).toEqual(2)
|
||||
expect(spy.mock.calls[1][0].value).toEqual(6)
|
||||
|
||||
inst.setState({ value: 63 })
|
||||
|
||||
expect(spy.mock.calls.length).toEqual(3)
|
||||
expect(spy.mock.calls[2][0].value).toEqual(63)
|
||||
|
||||
inst.setState({ value: undefined, defaultValue: 52 })
|
||||
|
||||
expect(spy.mock.calls.length).toEqual(4)
|
||||
expect(spy.mock.calls[3][0].value).toEqual(52)
|
||||
})
|
||||
|
||||
describe('hook', () => {
|
||||
it('should track internally if not specified', () => {
|
||||
let ref = {}
|
||||
let Control = props => {
|
||||
props = useUncontrolled(props, { value: 'onChange' })
|
||||
ref.current = props
|
||||
|
||||
return (
|
||||
<input
|
||||
{...props}
|
||||
value={props.value == null ? '' : props.value}
|
||||
onChange={e => props.onChange(e.value)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
let inst = mount(<Control />)
|
||||
|
||||
inst
|
||||
.find('input')
|
||||
.first()
|
||||
.simulate('change', { value: 42 })
|
||||
|
||||
expect(ref.current.value).toEqual(42)
|
||||
})
|
||||
|
||||
it('should allow for defaultProp', () => {
|
||||
let ref = {}
|
||||
let Control = props => {
|
||||
props = useUncontrolled(props, {
|
||||
value: 'onChange',
|
||||
open: 'onToggle',
|
||||
})
|
||||
|
||||
ref.current = props
|
||||
|
||||
return (
|
||||
<input
|
||||
{...props}
|
||||
className={props.open ? 'open' : ''}
|
||||
value={props.value == null ? '' : props.value}
|
||||
onChange={e => props.onChange(e.value)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
let inst = mount(<Control defaultValue={10} defaultOpen />)
|
||||
|
||||
expect(inst.find('.open')).toHaveLength(1)
|
||||
|
||||
const inputProps = inst.find('input').props()
|
||||
|
||||
expect(inputProps.defaultValue).not.toBeDefined()
|
||||
expect(inputProps.defaultOpen).not.toBeDefined()
|
||||
|
||||
inst
|
||||
.find('input')
|
||||
.first()
|
||||
.tap(inst => expect(inst.getDOMNode().value).toEqual('10'))
|
||||
.simulate('change', { value: 42 })
|
||||
|
||||
expect(ref.current.value).toEqual(42)
|
||||
})
|
||||
|
||||
it('should revert to defaultProp when switched to uncontrolled', () => {
|
||||
let ref = {}
|
||||
let Control = props => {
|
||||
props = useUncontrolled(props, { value: 'onChange' })
|
||||
ref.current = props
|
||||
|
||||
return (
|
||||
<input
|
||||
{...props}
|
||||
value={props.value == null ? '' : props.value}
|
||||
onChange={e => props.onChange(e.value)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
let inst = mount(
|
||||
<Control defaultValue="foo" value="bar" onChange={() => {}} />
|
||||
)
|
||||
|
||||
expect(ref.current.value).toEqual('bar')
|
||||
|
||||
inst.setProps({ value: undefined })
|
||||
|
||||
expect(ref.current.value).toEqual('foo')
|
||||
|
||||
inst.setProps({ value: 'bar' })
|
||||
|
||||
expect(ref.current.value).toEqual('bar')
|
||||
|
||||
inst.setProps({ value: undefined, defaultValue: 'baz' })
|
||||
|
||||
expect(ref.current.value).toEqual('baz')
|
||||
})
|
||||
})
|
||||
})
|
||||
28
conf/site/node_modules/uncontrollable/test/types-test.tsx
generated
vendored
Normal file
28
conf/site/node_modules/uncontrollable/test/types-test.tsx
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
import { useUncontrolled, useUncontrolledProp } from '../src'
|
||||
|
||||
interface Props {
|
||||
value?: string
|
||||
defaultValue: string | undefined
|
||||
onChange?(value: string, meta: {}): void
|
||||
}
|
||||
|
||||
function Foo(props: Props) {
|
||||
// $ExpectType [string, (value: string, meta: {}) => void]
|
||||
const [value, onChange] = useUncontrolledProp(
|
||||
props.value,
|
||||
props.defaultValue,
|
||||
props.onChange
|
||||
)
|
||||
}
|
||||
|
||||
function FooA(props: Props) {
|
||||
// $ExpectType { value: string, onChange: (value: string, meta: {}) => void }
|
||||
const a = useUncontrolled<Props, 'defaultValue'>(props, {
|
||||
value: 'onChange',
|
||||
})
|
||||
|
||||
// $ExpectType Props
|
||||
const b = useUncontrolled(props, {
|
||||
value: 'onChange',
|
||||
})
|
||||
}
|
||||
8
conf/site/node_modules/uncontrollable/tsconfig.json
generated
vendored
Normal file
8
conf/site/node_modules/uncontrollable/tsconfig.json
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "@4c/tsconfig/web.json",
|
||||
"compilerOptions": {
|
||||
"noImplicitAny": false,
|
||||
"rootDir": "src"
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
Reference in New Issue
Block a user