Commit 6cc198bf authored by Sangjune Bae's avatar Sangjune Bae
Browse files

first commit

parent 81c6da4b
import { Modifier } from "../types";
export default function orderModifiers(modifiers: Array<Modifier<any, any>>): Array<Modifier<any, any>>;
import { modifierPhases } from "../enums.js"; // source: https://stackoverflow.com/questions/49875255
function order(modifiers) {
var map = new Map();
var visited = new Set();
var result = [];
modifiers.forEach(function (modifier) {
map.set(modifier.name, modifier);
}); // On visiting object, check for its dependencies and visit them recursively
function sort(modifier) {
visited.add(modifier.name);
var requires = [].concat(modifier.requires || [], modifier.requiresIfExists || []);
requires.forEach(function (dep) {
if (!visited.has(dep)) {
var depModifier = map.get(dep);
if (depModifier) {
sort(depModifier);
}
}
});
result.push(modifier);
}
modifiers.forEach(function (modifier) {
if (!visited.has(modifier.name)) {
// check for visited object
sort(modifier);
}
});
return result;
}
export default function orderModifiers(modifiers) {
// order based on dependencies
var orderedModifiers = order(modifiers); // order based on phase
return modifierPhases.reduce(function (acc, phase) {
return acc.concat(orderedModifiers.filter(function (modifier) {
return modifier.phase === phase;
}));
}, []);
}
\ No newline at end of file
// @flow
import type { Modifier } from '../types';
import { modifierPhases } from '../enums';
// source: https://stackoverflow.com/questions/49875255
function order(modifiers) {
const map = new Map();
const visited = new Set();
const result = [];
modifiers.forEach(modifier => {
map.set(modifier.name, modifier);
});
// On visiting object, check for its dependencies and visit them recursively
function sort(modifier: Modifier<any, any>) {
visited.add(modifier.name);
const requires = [
...(modifier.requires || []),
...(modifier.requiresIfExists || []),
];
requires.forEach(dep => {
if (!visited.has(dep)) {
const depModifier = map.get(dep);
if (depModifier) {
sort(depModifier);
}
}
});
result.push(modifier);
}
modifiers.forEach(modifier => {
if (!visited.has(modifier.name)) {
// check for visited object
sort(modifier);
}
});
return result;
}
export default function orderModifiers(
modifiers: Array<Modifier<any, any>>
): Array<Modifier<any, any>> {
// order based on dependencies
const orderedModifiers = order(modifiers);
// order based on phase
return modifierPhases.reduce((acc, phase) => {
return acc.concat(
orderedModifiers.filter(modifier => modifier.phase === phase)
);
}, []);
}
import { Rect, ClientRectObject } from "../types";
export default function rectToClientRect(rect: Rect): ClientRectObject;
export default function rectToClientRect(rect) {
return Object.assign(Object.assign({}, rect), {}, {
left: rect.x,
top: rect.y,
right: rect.x + rect.width,
bottom: rect.y + rect.height
});
}
\ No newline at end of file
// @flow
import type { Rect, ClientRectObject } from '../types';
export default function rectToClientRect(rect: Rect): ClientRectObject {
return {
...rect,
left: rect.x,
top: rect.y,
right: rect.x + rect.width,
bottom: rect.y + rect.height,
};
}
export default function uniqueBy<T>(arr: Array<T>, fn: (arg0: T) => any): Array<T>;
export default function uniqueBy(arr, fn) {
var identifiers = new Set();
return arr.filter(function (item) {
var identifier = fn(item);
if (!identifiers.has(identifier)) {
identifiers.add(identifier);
return true;
}
});
}
\ No newline at end of file
// @flow
export default function uniqueBy<T>(arr: Array<T>, fn: T => any): Array<T> {
const identifiers = new Set();
return arr.filter(item => {
const identifier = fn(item);
if (!identifiers.has(identifier)) {
identifiers.add(identifier);
return true;
}
});
}
export default function validateModifiers(modifiers: Array<any>): void;
import format from "./format.js";
import { modifierPhases } from "../enums.js";
var INVALID_MODIFIER_ERROR = 'Popper: modifier "%s" provided an invalid %s property, expected %s but got %s';
var MISSING_DEPENDENCY_ERROR = 'Popper: modifier "%s" requires "%s", but "%s" modifier is not available';
var VALID_PROPERTIES = ['name', 'enabled', 'phase', 'fn', 'effect', 'requires', 'options'];
export default function validateModifiers(modifiers) {
modifiers.forEach(function (modifier) {
Object.keys(modifier).forEach(function (key) {
switch (key) {
case 'name':
if (typeof modifier.name !== 'string') {
console.error(format(INVALID_MODIFIER_ERROR, String(modifier.name), '"name"', '"string"', "\"" + String(modifier.name) + "\""));
}
break;
case 'enabled':
if (typeof modifier.enabled !== 'boolean') {
console.error(format(INVALID_MODIFIER_ERROR, modifier.name, '"enabled"', '"boolean"', "\"" + String(modifier.enabled) + "\""));
}
case 'phase':
if (modifierPhases.indexOf(modifier.phase) < 0) {
console.error(format(INVALID_MODIFIER_ERROR, modifier.name, '"phase"', "either " + modifierPhases.join(', '), "\"" + String(modifier.phase) + "\""));
}
break;
case 'fn':
if (typeof modifier.fn !== 'function') {
console.error(format(INVALID_MODIFIER_ERROR, modifier.name, '"fn"', '"function"', "\"" + String(modifier.fn) + "\""));
}
break;
case 'effect':
if (typeof modifier.effect !== 'function') {
console.error(format(INVALID_MODIFIER_ERROR, modifier.name, '"effect"', '"function"', "\"" + String(modifier.fn) + "\""));
}
break;
case 'requires':
if (!Array.isArray(modifier.requires)) {
console.error(format(INVALID_MODIFIER_ERROR, modifier.name, '"requires"', '"array"', "\"" + String(modifier.requires) + "\""));
}
break;
case 'requiresIfExists':
if (!Array.isArray(modifier.requiresIfExists)) {
console.error(format(INVALID_MODIFIER_ERROR, modifier.name, '"requiresIfExists"', '"array"', "\"" + String(modifier.requiresIfExists) + "\""));
}
break;
case 'options':
case 'data':
break;
default:
console.error("PopperJS: an invalid property has been provided to the \"" + modifier.name + "\" modifier, valid properties are " + VALID_PROPERTIES.map(function (s) {
return "\"" + s + "\"";
}).join(', ') + "; but \"" + key + "\" was provided.");
}
modifier.requires && modifier.requires.forEach(function (requirement) {
if (modifiers.find(function (mod) {
return mod.name === requirement;
}) == null) {
console.error(format(MISSING_DEPENDENCY_ERROR, String(modifier.name), requirement, requirement));
}
});
});
});
}
\ No newline at end of file
// @flow
import format from './format';
import { modifierPhases } from '../enums';
const INVALID_MODIFIER_ERROR =
'Popper: modifier "%s" provided an invalid %s property, expected %s but got %s';
const MISSING_DEPENDENCY_ERROR =
'Popper: modifier "%s" requires "%s", but "%s" modifier is not available';
const VALID_PROPERTIES = [
'name',
'enabled',
'phase',
'fn',
'effect',
'requires',
'options',
];
export default function validateModifiers(modifiers: Array<any>): void {
modifiers.forEach(modifier => {
Object.keys(modifier).forEach(key => {
switch (key) {
case 'name':
if (typeof modifier.name !== 'string') {
console.error(
format(
INVALID_MODIFIER_ERROR,
String(modifier.name),
'"name"',
'"string"',
`"${String(modifier.name)}"`
)
);
}
break;
case 'enabled':
if (typeof modifier.enabled !== 'boolean') {
console.error(
format(
INVALID_MODIFIER_ERROR,
modifier.name,
'"enabled"',
'"boolean"',
`"${String(modifier.enabled)}"`
)
);
}
case 'phase':
if (modifierPhases.indexOf(modifier.phase) < 0) {
console.error(
format(
INVALID_MODIFIER_ERROR,
modifier.name,
'"phase"',
`either ${modifierPhases.join(', ')}`,
`"${String(modifier.phase)}"`
)
);
}
break;
case 'fn':
if (typeof modifier.fn !== 'function') {
console.error(
format(
INVALID_MODIFIER_ERROR,
modifier.name,
'"fn"',
'"function"',
`"${String(modifier.fn)}"`
)
);
}
break;
case 'effect':
if (typeof modifier.effect !== 'function') {
console.error(
format(
INVALID_MODIFIER_ERROR,
modifier.name,
'"effect"',
'"function"',
`"${String(modifier.fn)}"`
)
);
}
break;
case 'requires':
if (!Array.isArray(modifier.requires)) {
console.error(
format(
INVALID_MODIFIER_ERROR,
modifier.name,
'"requires"',
'"array"',
`"${String(modifier.requires)}"`
)
);
}
break;
case 'requiresIfExists':
if (!Array.isArray(modifier.requiresIfExists)) {
console.error(
format(
INVALID_MODIFIER_ERROR,
modifier.name,
'"requiresIfExists"',
'"array"',
`"${String(modifier.requiresIfExists)}"`
)
);
}
break;
case 'options':
case 'data':
break;
default:
console.error(
`PopperJS: an invalid property has been provided to the "${
modifier.name
}" modifier, valid properties are ${VALID_PROPERTIES.map(
s => `"${s}"`
).join(', ')}; but "${key}" was provided.`
);
}
modifier.requires &&
modifier.requires.forEach(requirement => {
if (modifiers.find(mod => mod.name === requirement) == null) {
console.error(
format(
MISSING_DEPENDENCY_ERROR,
String(modifier.name),
requirement,
requirement
)
);
}
});
});
});
}
export default function within(min: number, value: number, max: number): number;
export default function within(min, value, max) {
return Math.max(min, Math.min(value, max));
}
\ No newline at end of file
// @flow
export default function within(
min: number,
value: number,
max: number
): number {
return Math.max(min, Math.min(value, max));
}
{
"_from": "@popperjs/core@^2.5.3",
"_id": "@popperjs/core@2.6.0",
"_inBundle": false,
"_integrity": "sha512-cPqjjzuFWNK3BSKLm0abspP0sp/IGOli4p5I5fKFAzdS8fvjdOwDCfZqAaIiXd9lPkOWi3SUUfZof3hEb7J/uw==",
"_location": "/@popperjs/core",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "@popperjs/core@^2.5.3",
"name": "@popperjs/core",
"escapedName": "@popperjs%2fcore",
"scope": "@popperjs",
"rawSpec": "^2.5.3",
"saveSpec": null,
"fetchSpec": "^2.5.3"
},
"_requiredBy": [
"/react-overlays"
],
"_resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.6.0.tgz",
"_shasum": "f022195afdfc942e088ee2101285a1d31c7d727f",
"_spec": "@popperjs/core@^2.5.3",
"_where": "C:\\Users\\reyel\\OneDrive\\바탕 화면\\2020winter\\search-page\\node_modules\\react-overlays",
"author": {
"name": "Federico Zivolo",
"email": "federico.zivolo@gmail.com"
},
"babel": {
"extends": "./.config/babel.config"
},
"bugs": {
"url": "https://github.com/popperjs/popper-core/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Tooltip and Popover Positioning Engine",
"devDependencies": {
"@ampproject/rollup-plugin-closure-compiler": "^0.25.2",
"@atomico/rollup-plugin-sizes": "^1.1.4",
"@babel/cli": "^7.8.3",
"@babel/core": "^7.7.5",
"@babel/plugin-transform-flow-strip-types": "^7.7.4",
"@babel/plugin-transform-runtime": "^7.7.6",
"@babel/preset-env": "^7.7.6",
"@fezvrasta/tsc-silent": "^1.3.0",
"@khanacademy/flow-to-ts": "^0.1.7",
"@rollup/plugin-babel": "^5.0.0",
"@rollup/plugin-replace": "^2.3.2",
"babel-eslint": "^10.0.3",
"babel-jest": "^25.5.1",
"babel-plugin-add-import-extension": "^1.3.0",
"babel-plugin-annotate-pure-calls": "^0.4.0",
"babel-plugin-dev-expression": "^0.2.2",
"babel-plugin-inline-replace-variables": "^1.3.1",
"babel-plugin-transform-inline-environment-variables": "^0.4.3",
"concurrently": "^5.2.0",
"dotenv": "^8.2.0",
"eslint": "^6.8.0",
"eslint-plugin-flowtype": "^4.6.0",
"eslint-plugin-import": "^2.20.0",
"eslint-plugin-unused-imports": "^0.1.2",
"flow-bin": "^0.139.0",
"flow-copy-source": "^2.0.9",
"get-port-cli": "^2.0.0",
"husky": "^4.2.1",
"jest": "^25.5.1",
"jest-environment-jsdom-sixteen": "^1.0.3",
"jest-environment-puppeteer": "^4.4.0",
"jest-image-snapshot": "^3.1.0",
"jest-puppeteer": "^4.4.0",
"poster": "^0.0.9",
"prettier": "^2.0.5",
"pretty-quick": "^2.0.1",
"puppeteer": "^3.0.2",
"replace-in-files-cli": "^0.3.1",
"rollup": "^2.7.3",
"rollup-plugin-flow-entry": "^0.3.3",
"rollup-plugin-license": "^2.0.0",
"rollup-plugin-terser": "^5.2.0",
"rollup-plugin-visualizer": "^4.0.3",
"serve": "^11.3.0",
"typescript": "^3.7.5"
},
"eslintConfig": {
"extends": "./.config/eslint.config"
},
"files": [
"index.d.ts",
"/dist",
"/lib"
],
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/popperjs"
},
"homepage": "https://github.com/popperjs/popper-core#readme",
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
}
},
"jest": {
"preset": "./.config/jest.config"
},
"keywords": [
"tooltip",
"popover",
"dropdown",
"popup",
"popper",
"positioning engine"
],
"license": "MIT",
"main": "dist/cjs/popper.js",
"main:umd": "dist/umd/popper.js",
"module": "lib/index.js",
"name": "@popperjs/core",
"prettier": {
"semi": true,
"trailingComma": "es5",
"singleQuote": true,
"proseWrap": "always"
},
"repository": {
"type": "git",
"url": "git+https://github.com/popperjs/popper-core.git"
},
"scripts": {
"build": "yarn clean && yarn build:es && yarn build:esbrowser && yarn build:bundles && yarn build:flow && yarn build:typescript",
"build:bundles": "rollup -c .config/rollup.config.js",
"build:dev": "NODE_ENV=dev babel src -d tests/visual/dist",
"build:es": "babel src -d lib --ignore '**/*.test.js','**/__mocks__'",
"build:esbrowser": "BROWSER_COMPAT=true yarn build:es -d dist/esm",
"build:flow": "flow-copy-source --ignore \"**/*.test.js\" src lib && replace-in-files --string=__DEV__ --replacement=false 'lib/**/*.flow'",
"build:typescript": "rimraf dist/typescript; flow-to-ts \"src/**/*.js\" --write --inline-utility-types; tsc-silent --project .config/tsconfig.json --createSourceFile .config/createSourceFile.js --suppress @; rimraf \"src/**/*.ts\"",
"clean": "rimraf lib && rimraf dist && rimraf test/visual/dist",
"dev": "NODE_ENV=dev concurrently 'yarn serve' 'yarn build:dev --watch'",
"prepublishOnly": "yarn build",
"serve": "serve -l ${DEV_PORT:-5000} tests/visual",
"test": "yarn test:unit && yarn test:functional",
"test:eslint": "eslint .",
"test:flow": "flow",
"test:functional": "DEV_PORT=`get-port` jest tests/functional",
"test:typescript": "tsc --project tests/typescript/tsconfig.json",
"test:unit": "jest --coverage src"
},
"sideEffects": false,
"unpkg": "dist/umd/popper.min.js",
"version": "2.6.0"
}
MIT License
Copyright (c) 2018 4Catalyzer
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.
# @restart/context [![npm][npm-badge]][npm]
React context helpers.
## Install
```sh
npm install @restart/context
```
## Usage
```js
import React from 'react';
import mapContextToProps from '@restart/context/mapContextToProps';
const MyValueContext = React.createContext(null);
function MyComponent(props) {
/* ... */
}
const MyComponentWithMyValue = mapContextToProps(
MyValueContext,
myValue => ({ myValue }),
MyComponent,
);
const withMyValue = Component =>
mapContextToProps(
{
consumers: MyValueContext,
mapToProps: myValue => ({ myValue }),
displayName: `withMyValue(${Component.displayName || Component.name})`,
},
Component,
);
```
[npm-badge]: https://img.shields.io/npm/v/@restart/context.svg
[npm]: https://www.npmjs.org/package/@restart/context
// TypeScript Version: 3.0
declare module '@restart/context/forwardRef' {
import * as React from 'react';
interface ForwardRefOptions<TProps> {
displayName?: string;
propTypes?: React.ValidationMap<TProps>;
defaultProps?: Partial<TProps>;
allowFallback?: boolean;
}
function forwardRef<TRef, TProps>(
renderFn: (
props: TProps & { children?: React.ReactNode },
ref: React.Ref<TRef> | null,
) => React.ReactElement<any> | null,
options?: ForwardRefOptions<TProps>,
): React.ForwardRefExoticComponent<
React.PropsWithRef<TProps> & React.RefAttributes<TRef>
>;
export default forwardRef;
}
import React from 'react';
export default function forwardRef(renderFn, _temp) {
var _ref = _temp === void 0 ? {} : _temp,
propTypes = _ref.propTypes,
defaultProps = _ref.defaultProps,
_ref$allowFallback = _ref.allowFallback,
allowFallback = _ref$allowFallback === void 0 ? false : _ref$allowFallback,
_ref$displayName = _ref.displayName,
displayName = _ref$displayName === void 0 ? renderFn.name || renderFn.displayName : _ref$displayName;
var render = function render(props, ref) {
return renderFn(props, ref);
};
return Object.assign(React.forwardRef || !allowFallback ? React.forwardRef(render) : function (props) {
return render(props, null);
}, {
displayName: displayName,
propTypes: propTypes,
defaultProps: defaultProps
});
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment