0.2.0 - Mid migration

This commit is contained in:
Daniel Mason 2022-04-25 14:47:15 +12:00
parent 139e6a915e
commit 7e38fdbd7d
42393 changed files with 5358157 additions and 62 deletions

12
web/node_modules/uncontrollable/lib/esm/hook.d.ts generated vendored Normal file
View file

@ -0,0 +1,12 @@
export declare type Handler = (...args: any[]) => any;
declare function useUncontrolledProp<TProp, THandler extends Handler = Handler>(propValue: TProp | undefined, defaultValue: TProp, handler?: THandler): readonly [TProp, THandler];
declare function useUncontrolledProp<TProp, THandler extends Handler = Handler>(propValue: TProp | undefined, defaultValue?: TProp | undefined, handler?: THandler): readonly [TProp | undefined, THandler];
export { useUncontrolledProp };
declare type FilterFlags<Base, Condition> = {
[Key in keyof Base]: NonNullable<Base[Key]> extends Condition ? Key : never;
};
declare type AllowedNames<Base, Condition> = FilterFlags<Base, Condition>[keyof Base];
declare type ConfigMap<TProps extends object> = {
[p in keyof TProps]?: AllowedNames<TProps, Function>;
};
export default function useUncontrolled<TProps extends object, TDefaults extends string = never>(props: TProps, config: ConfigMap<TProps>): Omit<TProps, TDefaults>;

58
web/node_modules/uncontrollable/lib/esm/hook.js generated vendored Normal file
View file

@ -0,0 +1,58 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
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); }
import { useCallback, useRef, useState } from 'react';
import * as Utils from './utils';
function useUncontrolledProp(propValue, defaultValue, handler) {
var wasPropRef = useRef(propValue !== undefined);
var _useState = 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, 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])];
}
export { useUncontrolledProp };
export default 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 = _objectWithoutPropertiesLoose(_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 _extends({}, rest, (_extends2 = {}, _extends2[fieldName] = value, _extends2[handlerName] = handler, _extends2));
}, props);
}

2
web/node_modules/uncontrollable/lib/esm/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,2 @@
export { default as useUncontrolled, useUncontrolledProp } from './hook';
export { default as uncontrollable } from './uncontrollable';

2
web/node_modules/uncontrollable/lib/esm/index.js generated vendored Normal file
View file

@ -0,0 +1,2 @@
export { default as useUncontrolled, useUncontrolledProp } from './hook';
export { default as uncontrollable } from './uncontrollable';

View file

@ -0,0 +1,176 @@
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';
import * as Utils from './utils';
export default function uncontrollable(Component, controlledValues, methods) {
if (methods === void 0) {
methods = [];
}
var displayName = Component.displayName || Component.name || 'Component';
var canAcceptRef = Utils.canAcceptRef(Component);
var controlledProps = Object.keys(controlledValues);
var PROPS_TO_OMIT = controlledProps.map(Utils.defaultKey);
!(canAcceptRef || !methods.length) ? process.env.NODE_ENV !== "production" ? invariant(false, '[uncontrollable] stateless function components cannot pass through methods ' + 'because they have no associated instances. Check component: ' + displayName + ', ' + 'attempting to pass through methods: ' + methods.join(', ')) : invariant(false) : void 0;
var UncontrolledComponent =
/*#__PURE__*/
function (_React$Component) {
_inheritsLoose(UncontrolledComponent, _React$Component);
function UncontrolledComponent() {
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
_this.handlers = Object.create(null);
controlledProps.forEach(function (propName) {
var handlerName = controlledValues[propName];
var handleChange = function handleChange(value) {
if (_this.props[handlerName]) {
var _this$props;
_this._notifying = true;
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
args[_key2 - 1] = arguments[_key2];
}
(_this$props = _this.props)[handlerName].apply(_this$props, [value].concat(args));
_this._notifying = false;
}
if (!_this.unmounted) _this.setState(function (_ref) {
var _extends2;
var values = _ref.values;
return {
values: _extends(Object.create(null), values, (_extends2 = {}, _extends2[propName] = value, _extends2))
};
});
};
_this.handlers[handlerName] = handleChange;
});
if (methods.length) _this.attachRef = function (ref) {
_this.inner = ref;
};
var values = Object.create(null);
controlledProps.forEach(function (key) {
values[key] = _this.props[Utils.defaultKey(key)];
});
_this.state = {
values: values,
prevProps: {}
};
return _this;
}
var _proto = UncontrolledComponent.prototype;
_proto.shouldComponentUpdate = function shouldComponentUpdate() {
//let setState trigger the update
return !this._notifying;
};
UncontrolledComponent.getDerivedStateFromProps = function getDerivedStateFromProps(props, _ref2) {
var values = _ref2.values,
prevProps = _ref2.prevProps;
var nextState = {
values: _extends(Object.create(null), values),
prevProps: {}
};
controlledProps.forEach(function (key) {
/**
* If a prop switches from controlled to Uncontrolled
* reset its value to the defaultValue
*/
nextState.prevProps[key] = props[key];
if (!Utils.isProp(props, key) && Utils.isProp(prevProps, key)) {
nextState.values[key] = props[Utils.defaultKey(key)];
}
});
return nextState;
};
_proto.componentWillUnmount = function componentWillUnmount() {
this.unmounted = true;
};
_proto.render = function render() {
var _this2 = this;
var _this$props2 = this.props,
innerRef = _this$props2.innerRef,
props = _objectWithoutPropertiesLoose(_this$props2, ["innerRef"]);
PROPS_TO_OMIT.forEach(function (prop) {
delete props[prop];
});
var newProps = {};
controlledProps.forEach(function (propName) {
var propValue = _this2.props[propName];
newProps[propName] = propValue !== undefined ? propValue : _this2.state.values[propName];
});
return React.createElement(Component, _extends({}, props, newProps, this.handlers, {
ref: innerRef || this.attachRef
}));
};
return UncontrolledComponent;
}(React.Component);
polyfill(UncontrolledComponent);
UncontrolledComponent.displayName = "Uncontrolled(" + displayName + ")";
UncontrolledComponent.propTypes = _extends({
innerRef: function innerRef() {}
}, Utils.uncontrolledPropTypes(controlledValues, displayName));
methods.forEach(function (method) {
UncontrolledComponent.prototype[method] = function $proxiedMethod() {
var _this$inner;
return (_this$inner = this.inner)[method].apply(_this$inner, arguments);
};
});
var WrappedComponent = UncontrolledComponent;
if (React.forwardRef) {
WrappedComponent = React.forwardRef(function (props, ref) {
return React.createElement(UncontrolledComponent, _extends({}, props, {
innerRef: ref,
__source: {
fileName: _jsxFileName,
lineNumber: 128
},
__self: this
}));
});
WrappedComponent.propTypes = UncontrolledComponent.propTypes;
}
WrappedComponent.ControlledComponent = Component;
/**
* useful when wrapping a Component and you want to control
* everything
*/
WrappedComponent.deferControlTo = function (newComponent, additions, nextMethods) {
if (additions === void 0) {
additions = {};
}
return uncontrollable(newComponent, _extends({}, controlledValues, additions), nextMethods);
};
return WrappedComponent;
}

12
web/node_modules/uncontrollable/lib/esm/utils.d.ts generated vendored Normal file
View file

@ -0,0 +1,12 @@
export declare function uncontrolledPropTypes(controlledValues: any, displayName: string): {};
export declare function isProp<P>(props: P, prop: keyof P): boolean;
export declare function defaultKey(key: string): string;
/**
* 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.
*/
export declare function canAcceptRef(component: any): any;

46
web/node_modules/uncontrollable/lib/esm/utils.js generated vendored Normal file
View file

@ -0,0 +1,46 @@
import invariant from '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 + "`."));
}
}
};
}
export 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" ? invariant(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;
}
export function isProp(props, prop) {
return props[prop] !== undefined;
}
export 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.
*/
export function canAcceptRef(component) {
return !!component && (typeof component !== 'function' || component.prototype && component.prototype.isReactComponent);
}