Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

@@ -0,0 +1,10 @@
import * as React from 'react';
export interface ClickAwayListenerProps {
children: React.ReactNode;
onClickAway: (event: React.ChangeEvent<{}>) => void;
}
declare const ClickAwayListener: React.ComponentType<ClickAwayListenerProps>;
export default ClickAwayListener;

View File

@@ -0,0 +1,58 @@
import React from 'react';
import { findDOMNode } from 'react-dom';
import EventListener from 'react-event-listener';
const isDescendant = (el, target) => {
if (target !== null && target.parentNode) {
return el === target || isDescendant(el, target.parentNode);
}
return false;
};
/**
* Listen for click events that are triggered outside of the component children.
*/
class ClickAwayListener extends React.Component {
constructor(...args) {
var _temp;
return _temp = super(...args), this.mounted = false, this.handleClickAway = event => {
// Ignore events that have been `event.preventDefault()` marked.
if (event.defaultPrevented) {
return;
}
// IE11 support, which trigger the handleClickAway even after the unbind
if (this.mounted) {
const el = findDOMNode(this);
if (event.target instanceof HTMLElement && document.documentElement && document.documentElement.contains(event.target) && !isDescendant(el, event.target)) {
this.props.onClickAway(event);
}
}
}, _temp;
}
componentDidMount() {
this.mounted = true;
}
componentWillUnmount() {
this.mounted = false;
}
render() {
return React.createElement(
EventListener,
{
target: 'document',
onMouseup: this.handleClickAway,
onTouchend: this.handleClickAway
},
this.props.children
);
}
}
export default ClickAwayListener;

View File

@@ -0,0 +1,6 @@
export default function addEventListener(
node: Node,
event: string,
handler: (e: Event) => never,
capture?: boolean
): { remove(): void };

View File

@@ -0,0 +1,11 @@
import addEventListener from 'dom-helpers/events/on';
import removeEventListener from 'dom-helpers/events/off';
export default function (node, event, handler, capture) {
addEventListener(node, event, handler, capture);
return {
remove() {
removeEventListener(node, event, handler, capture);
}
};
}

View File

@@ -0,0 +1,20 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
// This module is based on https://github.com/airbnb/prop-types-exact repository.
// However, in order to reduce the number of dependencies and to remove some extra safe checks
// the module was forked.
export const specialProperty = 'exact-prop: \u200b';
export default function exactProp(propTypes, componentNameInError) {
return _extends({}, propTypes, {
// eslint-disable-next-line prefer-arrow-callback
[specialProperty]: props => {
const unknownProps = Object.keys(props).filter(prop => !propTypes.hasOwnProperty(prop));
if (unknownProps.length > 0) {
return new TypeError(`${componentNameInError}: unknown props found: ${unknownProps.join(', ')}. Please remove the unknown properties.`);
}
return null;
}
});
}

View File

@@ -0,0 +1,7 @@
export function capitalizeFirstLetter(str: string): string;
export function contains(obj: Object, pred: Object): boolean;
export function findIndex(arr: any[], pred: any): number;
export function find<T>(arr: T[], pred: any): T;
export function createChainedFunction(
...funcs: Function[]
): (...args: any[]) => never;

View File

@@ -0,0 +1,56 @@
// weak
import warning from 'warning';
export function capitalizeFirstLetter(string) {
warning(typeof string === 'string', 'Material-UI: capitalizeFirstLetter(string) expects a string argument.');
return string.charAt(0).toUpperCase() + string.slice(1);
}
export function contains(obj, pred) {
return Object.keys(pred).every(key => {
return obj.hasOwnProperty(key) && obj[key] === pred[key];
});
}
export function findIndex(arr, pred) {
const predType = typeof pred;
for (let i = 0; i < arr.length; i += 1) {
if (predType === 'function' && !!pred(arr[i], i, arr) === true) {
return i;
}
if (predType === 'object' && contains(arr[i], pred)) {
return i;
}
if (['string', 'number', 'boolean'].indexOf(predType) !== -1) {
return arr.indexOf(pred);
}
}
return -1;
}
export function find(arr, pred) {
const index = findIndex(arr, pred);
return index > -1 ? arr[index] : undefined;
}
/**
* Safe chained function
*
* Will only create a new function if needed,
* otherwise will pass back existing functions or null.
*
* @param {function} functions to chain
* @returns {function|null}
*/
export function createChainedFunction(...funcs) {
return funcs.filter(func => func != null).reduce((acc, func) => {
warning(typeof func === 'function', 'Material-UI: invalid Argument Type, must only provide functions, undefined, or null.');
return function chainedFunction(...args) {
acc.apply(this, args);
func.apply(this, args);
};
}, () => {});
}

View File

@@ -0,0 +1,12 @@
export function focusKeyPressed(pressed: boolean): boolean;
export function detectKeyboardFocus(
instance: {
keyboardFocusTimeout: any;
keyboardFocusCheckTime: number;
keyboardFocusMaxCheckTimes: number;
},
element: Element,
cb: Function,
attempt: number
): never;
export function listenForFocusKeys(): never;

View File

@@ -0,0 +1,51 @@
// weak
import keycode from 'keycode';
import warning from 'warning';
import contains from 'dom-helpers/query/contains';
import addEventListener from '../utils/addEventListener';
const internal = {
listening: false,
focusKeyPressed: false
};
export function focusKeyPressed(pressed) {
if (typeof pressed !== 'undefined') {
internal.focusKeyPressed = Boolean(pressed);
}
return internal.focusKeyPressed;
}
export function detectKeyboardFocus(instance, element, callback, attempt = 1) {
warning(instance.keyboardFocusCheckTime, 'Material-UI: missing instance.keyboardFocusCheckTime');
warning(instance.keyboardFocusMaxCheckTimes, 'Material-UI: missing instance.keyboardFocusMaxCheckTimes');
instance.keyboardFocusTimeout = setTimeout(() => {
if (focusKeyPressed() && (document.activeElement === element || contains(element, document.activeElement))) {
callback();
} else if (attempt < instance.keyboardFocusMaxCheckTimes) {
detectKeyboardFocus(instance, element, callback, attempt + 1);
}
}, instance.keyboardFocusCheckTime);
}
const FOCUS_KEYS = ['tab', 'enter', 'space', 'esc', 'up', 'down', 'left', 'right'];
function isFocusKey(event) {
return FOCUS_KEYS.indexOf(keycode(event)) !== -1;
}
export function listenForFocusKeys() {
// It's a singleton, we only need to listen once.
// Also, this logic is client side only, we don't need a teardown.
if (!internal.listening) {
addEventListener(window, 'keyup', event => {
if (isFocusKey(event)) {
internal.focusKeyPressed = true;
}
});
internal.listening = true;
}
}

View File

@@ -0,0 +1,3 @@
export function ariaHidden(show: boolean, node: Node): never;
export function hideSiblings(container: Element, mountNode: Node): never;
export function showSiblings(container: Element, mountNode: Node): never;

View File

@@ -0,0 +1,33 @@
// weak
const BLACKLIST = ['template', 'script', 'style'];
const isHidable = ({ nodeType, tagName }) => nodeType === 1 && BLACKLIST.indexOf(tagName.toLowerCase()) === -1;
const siblings = (container, mount, cb) => {
mount = [].concat(mount); // eslint-disable-line no-param-reassign
[].forEach.call(container.children, node => {
if (mount.indexOf(node) === -1 && isHidable(node)) {
cb(node);
}
});
};
export function ariaHidden(show, node) {
if (!node) {
return;
}
if (show) {
node.setAttribute('aria-hidden', 'true');
} else {
node.removeAttribute('aria-hidden');
}
}
export function hideSiblings(container, mountNode) {
siblings(container, mountNode, node => ariaHidden(true, node));
}
export function showSiblings(container, mountNode) {
siblings(container, mountNode, node => ariaHidden(false, node));
}

View File

@@ -0,0 +1,4 @@
export function cloneChildrenWithClassName<T>(
children: React.ReactNode,
className: string
): T[];

View File

@@ -0,0 +1,21 @@
/* eslint-disable import/prefer-default-export */
import { cloneElement, Children, isValidElement } from 'react';
export function cloneChildrenWithClassName(children, className) {
return Children.map(children, child => {
return isValidElement(child) && cloneElement(child, {
className: child.props.hasOwnProperty('className') ? `${child.props.className} ${className}` : className
});
});
}
export function isMuiElement(element, muiNames) {
return isValidElement(element) && muiNames.indexOf(element.type.muiName) !== -1;
}
export function isMuiComponent(element, muiNames) {
return muiNames.indexOf(element.muiName) !== -1;
}

View File

@@ -0,0 +1 @@
export default function requirePropFactory(componentNameInError: string): any;

View File

@@ -0,0 +1,16 @@
// weak
const requirePropFactory = componentNameInError => {
const requireProp = requiredProp => (props, propName, componentName, location, propFullName) => {
const propFullNameSafe = propFullName || propName;
if (typeof props[propName] !== 'undefined' && !props[requiredProp]) {
return new Error(`The property \`${propFullNameSafe}\` of ` + `\`${componentNameInError}\` must be used on \`${requiredProp}\`.`);
}
return null;
};
return requireProp;
};
export default requirePropFactory;

View File

@@ -0,0 +1,21 @@
import { Breakpoint } from '../styles/createBreakpoints';
export interface WithWidthOptions {
resizeInterval: number;
}
export interface WithWidthProps {
width: Breakpoint;
}
export function isWidthUp(
breakpoint: Breakpoint,
screenWidth: number,
inclusive?: boolean
): boolean;
export default function withWidth<P = {}>(
options?: WithWidthOptions
): (
component: React.ComponentType<P>
) => React.ComponentClass<P & WithWidthProps>;

View File

@@ -0,0 +1,143 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
// weak
// flow sanity check (DO NOT DELETE) https://flow.org/try/#0JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wG4AoUSWOGATzCTgG84BhXSAOyS5gBUGTAL5xsuAkXQwy5OQHp5cALSq16jZuVwdccorgB3YDAAW-U0hBMAEgHk25JAA9qWAK5cMwCFyMnzS2sAHgAFHDAAZwAuFmEAPgAKcl12Tl9eGFiOcAy+QUZg1jMrJFi7ACMAKyQMOFEAMjhwiCj4gBpyAEps9J58oTCIyPiWOR00ABsUSMi4AHUAi1K4FxheABM55GkAOhzuTKHWyPaWWiCyuEqauoSx1KIuDaQoRK6H1LgiGHcoP2CBzy8GYuzBZmAkV2YGGohK1gAvMwIVDIjAUOtdvCkKJ5PEKKlhAT6ilvkhfv8FktLuRhAolFpGUy1PolMYzMtrHAAKqRFAAcyQ5CmMzmAEFVs51s9tsQYPs+kdipdytVavBGiwULEuO4QBVXmcKjq9QaoPdmHS0L40XBOUgNkD+vAEf4OZdEmKuhQDPMmBtfPh4DwHbQIHAwKK4MA-AADbGx1YAN14Fwg7n5pjgsYAsnQnZlE0QAI7uYBEOYmXbkYL2x2KvhwFBIgCMogqSIATLj4vSVMyB6lWW7TIsNmY4PZHC43LQhHAAEJSADWkBjLoIzki+DgAB8CJEQDv9-gQBtjwRJvyL-hnJNZOR6IwqePTC0onBXcxSTGTMAUJMY5mAA-LES6oKuEDrp0OjGK+oGLiua58J0dJOK40AeF4MA+H47KjsAr7vJ8mCeN4virFwpgoF4SDHFEsRAW+wxJKSqQFnwvS5M6BR0cwcFmGBSFQShcBgrs76RAkMFwD0aTcZkvH0SMYxsXAIqzFSZhMZK0pbIgcoKgpfDKaM35fGSzyvMR5kWepNogr+OEAUxZwCaYoiuii0LDGpjzkn8AIcSC4neTCJyiO5SL4Ie+A9sShIJSSak-IFWkEa+xJEuMZIUn4vDUbRFBoQYA5leow7uHygrCtMmkLrpmyynswVFO5QkQchMBnNqcC6vqhrGn1pqvBapJPC8bwfLZEwOSw7meRckI+ScKUBZSwQbMASZwHipJ0lac1MQ6wWfiOTHvIkC7esOfpwAGXBBn1SChjA4aRppMbZu5iZICmfhmOmmbZnmwVFkgpblkglbyjWx31sZ8DNswbZwB2zDdrt+JAA
import React from 'react';
import EventListener from 'react-event-listener';
import debounce from 'lodash/debounce';
import wrapDisplayName from 'recompose/wrapDisplayName';
import withTheme from '../styles/withTheme';
import { keys as breakpointKeys } from '../styles/createBreakpoints';
/**
* By default, returns true if screen width is the same or greater than the given breakpoint.
*
* @param screenWidth
* @param breakpoint
* @param inclusive - defaults to true
*/
export const isWidthUp = (breakpoint, screenWidth, inclusive = true) => {
if (inclusive) {
return breakpointKeys.indexOf(breakpoint) <= breakpointKeys.indexOf(screenWidth);
}
return breakpointKeys.indexOf(breakpoint) < breakpointKeys.indexOf(screenWidth);
};
/**
* By default, returns true if screen width is the same or less than the given breakpoint.
*
* @param screenWidth
* @param breakpoint
* @param inclusive - defaults to true
*/
export const isWidthDown = (breakpoint, screenWidth, inclusive = true) => {
if (inclusive) {
return breakpointKeys.indexOf(screenWidth) <= breakpointKeys.indexOf(breakpoint);
}
return breakpointKeys.indexOf(screenWidth) < breakpointKeys.indexOf(breakpoint);
};
// optional props introduced by this HOC
const withWidth = (
// eslint-disable-line prettier/prettier
options = {}) => Component => {
const {
resizeInterval = 166 // Corresponds to 10 frames at 60 Hz.
} = options;
// `theme` is injected below by withTheme
class Width extends React.Component {
constructor(...args) {
var _temp;
return _temp = super(...args), this.state = {
width: undefined
}, this.handleResize = debounce(() => {
this.updateWidth(window.innerWidth);
}, resizeInterval), _temp;
}
componentDidMount() {
this.updateWidth(window.innerWidth);
}
componentWillUnmount() {
this.handleResize.cancel();
}
updateWidth(innerWidth) {
if (this.props.theme) {
const breakpoints = this.props.theme.breakpoints;
let width = null;
/**
* Start with the slowest value as low end devices often have a small screen.
*
* innerWidth |0 xs sm md lg xl
* |-------|-------|-------|-------|-------|------>
* width | xs | xs | sm | md | lg | xl
*/
let index = 1;
while (width === null && index < breakpointKeys.length) {
const currentWidth = breakpointKeys[index];
// @media are inclusive, so reproduce the behavior here.
if (innerWidth < breakpoints.values[currentWidth]) {
width = breakpointKeys[index - 1];
break;
}
index += 1;
}
width = width || 'xl';
if (width !== this.state.width) {
this.setState({
width
});
}
}
}
render() {
const _props = this.props,
{ initialWidth, theme, width } = _props,
other = _objectWithoutProperties(_props, ['initialWidth', 'theme', 'width']);
const props = _extends({
width: width || this.state.width || initialWidth
}, other);
// When rendering the component on the server,
// we have no idea about the client browser screen width.
// In order to prevent blinks and help the reconciliation of the React tree
// we are not rendering the child component.
//
// An alternative is to use the `initialWidth` property.
if (props.width === undefined) {
return null;
}
return React.createElement(
EventListener,
{ target: 'window', onResize: this.handleResize },
React.createElement(Component, props)
);
}
}
if (process.env.NODE_ENV !== 'production') {
Width.displayName = wrapDisplayName(Component, 'withWidth');
}
return withTheme()(Width);
};
export default withWidth;