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

21
web/node_modules/mini-create-react-context/LICENSE generated vendored Normal file
View file

@ -0,0 +1,21 @@
Copyright (c) 2019-present StringEpsilon <StringEpsilon@gmail.com>
Copyright (c) 2017-2019 James Kyle <me@thejameskyle.com>
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.

124
web/node_modules/mini-create-react-context/README.md generated vendored Normal file
View file

@ -0,0 +1,124 @@
# mini-create-react-context
<p align="center">
<a href="https://packagephobia.now.sh/result?p=mini-create-react-context">
<img alt="npm install size" src="https://packagephobia.now.sh/badge?p=mini-create-react-context">
</a>
<a href="https://bundlephobia.com/result?p=mini-create-react-context@latest">
<img alt="npm bundle size" src="https://img.shields.io/bundlephobia/min/mini-create-react-context/latest.svg?style=flat-square">
</a>
<a href="https://www.npmjs.com/package/mini-create-react-context">
<img alt="npm" src="https://img.shields.io/npm/v/mini-create-react-context.svg?style=flat-square">
</a>
</p>
> (A smaller) Polyfill for the [React context API](https://github.com/reactjs/rfcs/pull/2)
## Install
```sh
npm install mini-create-react-context
```
You'll need to also have `react` and `prop-types` installed.
## API
```js
const Context = createReactContext(defaultValue);
/*
<Context.Provider value={providedValue}>
{children}
</Context.Provider>
...
<Context.Consumer>
{value => children}
</Context.Consumer>
*/
```
## Example
```js
// @flow
import React, { type Node } from 'react';
import createReactContext, { type Context } from 'mini-create-react-context';
type Theme = 'light' | 'dark';
// Pass a default theme to ensure type correctness
const ThemeContext: Context<Theme> = createReactContext('light');
class ThemeToggler extends React.Component<
{ children: Node },
{ theme: Theme }
> {
state = { theme: 'light' };
render() {
return (
// Pass the current context value to the Provider's `value` prop.
// Changes are detected using strict comparison (Object.is)
<ThemeContext.Provider value={this.state.theme}>
<button
onClick={() => {
this.setState(state => ({
theme: state.theme === 'light' ? 'dark' : 'light'
}));
}}
>
Toggle theme
</button>
{this.props.children}
</ThemeContext.Provider>
);
}
}
class Title extends React.Component<{ children: Node }> {
render() {
return (
// The Consumer uses a render prop API. Avoids conflicts in the
// props namespace.
<ThemeContext.Consumer>
{theme => (
<h1 style={{ color: theme === 'light' ? '#000' : '#fff' }}>
{this.props.children}
</h1>
)}
</ThemeContext.Consumer>
);
}
}
```
## Compatibility
This package only "ponyfills" the `React.createContext` API, not other unrelated React 16+ APIs. If you are using a version of React <16, keep in mind that you can only use features available in that version.
For example, you cannot pass children types aren't valid pre React 16:
```js
<Context.Provider>
<div/>
<div/>
</Context.Provider>
```
It will throw `A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object.` because `<Context.Provider>` can only receive a single child element. To fix the error just wrap everyting in a single `<div>`:
```js
<Context.Provider>
<div>
<div/>
<div/>
</div>
</Context.Provider>
```
## Size difference to the original:
| | original | **mini**
|------------|----------|-----
|install size| [**50 kB**](https://packagephobia.now.sh/result?p=create-react-context) | [140 kB](https://packagephobia.now.sh/result?p=mini-create-react-context)
|minified | [3.3 kB](https://bundlephobia.com/result?p=create-react-context) | [**2.3kB**](https://bundlephobia.com/result?p=mini-create-react-context)
|minzip | 1.3 kB | **1.0kB**

View file

@ -0,0 +1,167 @@
'use strict';var React=require('react'),_inheritsLoose=require('@babel/runtime/helpers/inheritsLoose'),PropTypes=require('prop-types'),warning=require('tiny-warning');function _interopDefaultLegacy(e){return e&&typeof e==='object'&&'default'in e?e:{'default':e}}var React__default=/*#__PURE__*/_interopDefaultLegacy(React);var _inheritsLoose__default=/*#__PURE__*/_interopDefaultLegacy(_inheritsLoose);var PropTypes__default=/*#__PURE__*/_interopDefaultLegacy(PropTypes);var warning__default=/*#__PURE__*/_interopDefaultLegacy(warning);var MAX_SIGNED_31_BIT_INT = 1073741823;
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : {};
function getUniqueId() {
var key = '__global_unique_id__';
return commonjsGlobal[key] = (commonjsGlobal[key] || 0) + 1;
}
function objectIs(x, y) {
if (x === y) {
return x !== 0 || 1 / x === 1 / y;
} else {
return x !== x && y !== y;
}
}
function createEventEmitter(value) {
var handlers = [];
return {
on: function on(handler) {
handlers.push(handler);
},
off: function off(handler) {
handlers = handlers.filter(function (h) {
return h !== handler;
});
},
get: function get() {
return value;
},
set: function set(newValue, changedBits) {
value = newValue;
handlers.forEach(function (handler) {
return handler(value, changedBits);
});
}
};
}
function onlyChild(children) {
return Array.isArray(children) ? children[0] : children;
}
function createReactContext(defaultValue, calculateChangedBits) {
var _Provider$childContex, _Consumer$contextType;
var contextProp = '__create-react-context-' + getUniqueId() + '__';
var Provider = /*#__PURE__*/function (_Component) {
_inheritsLoose__default['default'](Provider, _Component);
function Provider() {
var _this;
_this = _Component.apply(this, arguments) || this;
_this.emitter = createEventEmitter(_this.props.value);
return _this;
}
var _proto = Provider.prototype;
_proto.getChildContext = function getChildContext() {
var _ref;
return _ref = {}, _ref[contextProp] = this.emitter, _ref;
};
_proto.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
if (this.props.value !== nextProps.value) {
var oldValue = this.props.value;
var newValue = nextProps.value;
var changedBits;
if (objectIs(oldValue, newValue)) {
changedBits = 0;
} else {
changedBits = typeof calculateChangedBits === 'function' ? calculateChangedBits(oldValue, newValue) : MAX_SIGNED_31_BIT_INT;
if (process.env.NODE_ENV !== 'production') {
warning__default['default']((changedBits & MAX_SIGNED_31_BIT_INT) === changedBits, 'calculateChangedBits: Expected the return value to be a ' + '31-bit integer. Instead received: ' + changedBits);
}
changedBits |= 0;
if (changedBits !== 0) {
this.emitter.set(nextProps.value, changedBits);
}
}
}
};
_proto.render = function render() {
return this.props.children;
};
return Provider;
}(React.Component);
Provider.childContextTypes = (_Provider$childContex = {}, _Provider$childContex[contextProp] = PropTypes__default['default'].object.isRequired, _Provider$childContex);
var Consumer = /*#__PURE__*/function (_Component2) {
_inheritsLoose__default['default'](Consumer, _Component2);
function Consumer() {
var _this2;
_this2 = _Component2.apply(this, arguments) || this;
_this2.state = {
value: _this2.getValue()
};
_this2.onUpdate = function (newValue, changedBits) {
var observedBits = _this2.observedBits | 0;
if ((observedBits & changedBits) !== 0) {
_this2.setState({
value: _this2.getValue()
});
}
};
return _this2;
}
var _proto2 = Consumer.prototype;
_proto2.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
var observedBits = nextProps.observedBits;
this.observedBits = observedBits === undefined || observedBits === null ? MAX_SIGNED_31_BIT_INT : observedBits;
};
_proto2.componentDidMount = function componentDidMount() {
if (this.context[contextProp]) {
this.context[contextProp].on(this.onUpdate);
}
var observedBits = this.props.observedBits;
this.observedBits = observedBits === undefined || observedBits === null ? MAX_SIGNED_31_BIT_INT : observedBits;
};
_proto2.componentWillUnmount = function componentWillUnmount() {
if (this.context[contextProp]) {
this.context[contextProp].off(this.onUpdate);
}
};
_proto2.getValue = function getValue() {
if (this.context[contextProp]) {
return this.context[contextProp].get();
} else {
return defaultValue;
}
};
_proto2.render = function render() {
return onlyChild(this.props.children)(this.state.value);
};
return Consumer;
}(React.Component);
Consumer.contextTypes = (_Consumer$contextType = {}, _Consumer$contextType[contextProp] = PropTypes__default['default'].object, _Consumer$contextType);
return {
Provider: Provider,
Consumer: Consumer
};
}var index = React__default['default'].createContext || createReactContext;module.exports=index;

View file

@ -0,0 +1 @@
"use strict";var t=require("react"),e=require("@babel/runtime/helpers/inheritsLoose"),n=require("prop-types"),r=require("tiny-warning");function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=o(t),u=o(e),a=o(n),s=o(r),c="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{};function l(t){var e=[];return{on:function(t){e.push(t)},off:function(t){e=e.filter((function(e){return e!==t}))},get:function(){return t},set:function(n,r){t=n,e.forEach((function(e){return e(t,r)}))}}}var p=i.default.createContext||function(e,n){var r,o,i,p="__create-react-context-"+((c[i="__global_unique_id__"]=(c[i]||0)+1)+"__"),f=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).emitter=l(e.props.value),e}u.default(e,t);var r=e.prototype;return r.getChildContext=function(){var t;return(t={})[p]=this.emitter,t},r.componentWillReceiveProps=function(t){if(this.props.value!==t.value){var e,r=this.props.value,o=t.value;((i=r)===(u=o)?0!==i||1/i==1/u:i!=i&&u!=u)?e=0:(e="function"==typeof n?n(r,o):1073741823,"production"!==process.env.NODE_ENV&&s.default((1073741823&e)===e,"calculateChangedBits: Expected the return value to be a 31-bit integer. Instead received: "+e),0!==(e|=0)&&this.emitter.set(t.value,e))}var i,u},r.render=function(){return this.props.children},e}(t.Component);f.childContextTypes=((r={})[p]=a.default.object.isRequired,r);var d=function(t){function n(){var e;return(e=t.apply(this,arguments)||this).state={value:e.getValue()},e.onUpdate=function(t,n){0!=((0|e.observedBits)&n)&&e.setState({value:e.getValue()})},e}u.default(n,t);var r=n.prototype;return r.componentWillReceiveProps=function(t){var e=t.observedBits;this.observedBits=null==e?1073741823:e},r.componentDidMount=function(){this.context[p]&&this.context[p].on(this.onUpdate);var t=this.props.observedBits;this.observedBits=null==t?1073741823:t},r.componentWillUnmount=function(){this.context[p]&&this.context[p].off(this.onUpdate)},r.getValue=function(){return this.context[p]?this.context[p].get():e},r.render=function(){return(t=this.props.children,Array.isArray(t)?t[0]:t)(this.state.value);var t},n}(t.Component);return d.contextTypes=((o={})[p]=a.default.object,o),{Provider:f,Consumer:d}};module.exports=p;

View file

@ -0,0 +1,176 @@
import React, { Component } from 'react';
import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
import PropTypes from 'prop-types';
import warning from 'tiny-warning';
var MAX_SIGNED_31_BIT_INT = 1073741823;
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : {};
function getUniqueId() {
var key = '__global_unique_id__';
return commonjsGlobal[key] = (commonjsGlobal[key] || 0) + 1;
}
function objectIs(x, y) {
if (x === y) {
return x !== 0 || 1 / x === 1 / y;
} else {
return x !== x && y !== y;
}
}
function createEventEmitter(value) {
var handlers = [];
return {
on: function on(handler) {
handlers.push(handler);
},
off: function off(handler) {
handlers = handlers.filter(function (h) {
return h !== handler;
});
},
get: function get() {
return value;
},
set: function set(newValue, changedBits) {
value = newValue;
handlers.forEach(function (handler) {
return handler(value, changedBits);
});
}
};
}
function onlyChild(children) {
return Array.isArray(children) ? children[0] : children;
}
function createReactContext(defaultValue, calculateChangedBits) {
var _Provider$childContex, _Consumer$contextType;
var contextProp = '__create-react-context-' + getUniqueId() + '__';
var Provider = /*#__PURE__*/function (_Component) {
_inheritsLoose(Provider, _Component);
function Provider() {
var _this;
_this = _Component.apply(this, arguments) || this;
_this.emitter = createEventEmitter(_this.props.value);
return _this;
}
var _proto = Provider.prototype;
_proto.getChildContext = function getChildContext() {
var _ref;
return _ref = {}, _ref[contextProp] = this.emitter, _ref;
};
_proto.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
if (this.props.value !== nextProps.value) {
var oldValue = this.props.value;
var newValue = nextProps.value;
var changedBits;
if (objectIs(oldValue, newValue)) {
changedBits = 0;
} else {
changedBits = typeof calculateChangedBits === 'function' ? calculateChangedBits(oldValue, newValue) : MAX_SIGNED_31_BIT_INT;
if (process.env.NODE_ENV !== 'production') {
warning((changedBits & MAX_SIGNED_31_BIT_INT) === changedBits, 'calculateChangedBits: Expected the return value to be a ' + '31-bit integer. Instead received: ' + changedBits);
}
changedBits |= 0;
if (changedBits !== 0) {
this.emitter.set(nextProps.value, changedBits);
}
}
}
};
_proto.render = function render() {
return this.props.children;
};
return Provider;
}(Component);
Provider.childContextTypes = (_Provider$childContex = {}, _Provider$childContex[contextProp] = PropTypes.object.isRequired, _Provider$childContex);
var Consumer = /*#__PURE__*/function (_Component2) {
_inheritsLoose(Consumer, _Component2);
function Consumer() {
var _this2;
_this2 = _Component2.apply(this, arguments) || this;
_this2.state = {
value: _this2.getValue()
};
_this2.onUpdate = function (newValue, changedBits) {
var observedBits = _this2.observedBits | 0;
if ((observedBits & changedBits) !== 0) {
_this2.setState({
value: _this2.getValue()
});
}
};
return _this2;
}
var _proto2 = Consumer.prototype;
_proto2.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
var observedBits = nextProps.observedBits;
this.observedBits = observedBits === undefined || observedBits === null ? MAX_SIGNED_31_BIT_INT : observedBits;
};
_proto2.componentDidMount = function componentDidMount() {
if (this.context[contextProp]) {
this.context[contextProp].on(this.onUpdate);
}
var observedBits = this.props.observedBits;
this.observedBits = observedBits === undefined || observedBits === null ? MAX_SIGNED_31_BIT_INT : observedBits;
};
_proto2.componentWillUnmount = function componentWillUnmount() {
if (this.context[contextProp]) {
this.context[contextProp].off(this.onUpdate);
}
};
_proto2.getValue = function getValue() {
if (this.context[contextProp]) {
return this.context[contextProp].get();
} else {
return defaultValue;
}
};
_proto2.render = function render() {
return onlyChild(this.props.children)(this.state.value);
};
return Consumer;
}(Component);
Consumer.contextTypes = (_Consumer$contextType = {}, _Consumer$contextType[contextProp] = PropTypes.object, _Consumer$contextType);
return {
Provider: Provider,
Consumer: Consumer
};
}
var index = React.createContext || createReactContext;
export default index;

View file

@ -0,0 +1,24 @@
import * as React from 'react';
export default function createReactContext<T>(
defaultValue: T,
calculateChangedBits?: (prev: T, next: T) => number
): Context<T>;
type RenderFn<T> = (value: T) => React.ReactNode;
export type Context<T> = {
Provider: React.ComponentClass<ProviderProps<T>>;
Consumer: React.ComponentClass<ConsumerProps<T>>;
};
export type ProviderProps<T> = {
value: T;
children?: React.ReactNode;
observedBits?: any,
};
export type ConsumerProps<T> = {
children: RenderFn<T> | [RenderFn<T>];
observedBits?: number;
};

View file

@ -0,0 +1,64 @@
{
"name": "mini-create-react-context",
"version": "0.4.1",
"description": "Smaller Polyfill for the proposed React context API",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/index.d.ts",
"repository": "https://github.com/StringEpsilon/mini-create-react-context",
"author": "StringEpsilon",
"license": "MIT",
"keywords": [
"react",
"context",
"contextTypes",
"polyfill",
"ponyfill"
],
"files": [
"dist/**"
],
"scripts": {
"test": "jest",
"build": "rollup -c rollup.config.js",
"prepublish": "npm run build"
},
"dependencies": {
"@babel/runtime": "^7.12.1",
"tiny-warning": "^1.0.3"
},
"peerDependencies": {
"prop-types": "^15.0.0",
"react": "^0.14.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
},
"devDependencies": {
"@babel/core": "^7.12.3",
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/preset-env": "^7.12.1",
"@babel/preset-react": "^7.12.1",
"@babel/preset-typescript": "^7.12.1",
"@types/enzyme": "^3.10.5",
"@types/jest": "^26.0.10",
"@types/react": "^16.9.46",
"@wessberg/rollup-plugin-ts": "^1.3.6",
"babel-jest": "^25.5.1",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.5",
"enzyme-to-json": "^3.6.1",
"jest": "^26.6.0",
"prop-types": "^15.6.0",
"raf": "^3.4.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"rollup": "^2.32.1",
"rollup-plugin-commonjs": "^10.0.1",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-terser": "^7.0.2",
"typescript": "^4.0.3"
},
"jest": {
"snapshotSerializers": [
"enzyme-to-json/serializer"
]
}
}