Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: [Popper] remove process.env #2296

Merged
merged 6 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
82 changes: 5 additions & 77 deletions src/createPopper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,11 @@ import getCompositeRect from './dom-utils/getCompositeRect';
import getLayoutRect from './dom-utils/getLayoutRect';
import listScrollParents from './dom-utils/listScrollParents';
import getOffsetParent from './dom-utils/getOffsetParent';
import getComputedStyle from './dom-utils/getComputedStyle';
import orderModifiers from './utils/orderModifiers';
import debounce from './utils/debounce';
import validateModifiers from './utils/validateModifiers';
import uniqueBy from './utils/uniqueBy';
import getBasePlacement from './utils/getBasePlacement';
import mergeByName from './utils/mergeByName';
import detectOverflow from './utils/detectOverflow';
import { isElement } from './dom-utils/instanceOf';
import { auto } from './enums';

const INVALID_ELEMENT_ERROR =
'Popper: Invalid reference or popper argument provided. They must be either a DOM element or virtual element.';
const INFINITE_LOOP_ERROR =
'Popper: An infinite loop in the modifiers cycle has been detected! The cycle has been interrupted to prevent a browser crash.';

const DEFAULT_OPTIONS: OptionsGeneric<any> = {
placement: 'bottom',
Expand All @@ -45,10 +35,8 @@ function areValidElements(...args: Array<any>): boolean {
}

export function popperGenerator(generatorOptions: PopperGeneratorArgs = {}) {
const {
defaultModifiers = [],
defaultOptions = DEFAULT_OPTIONS,
} = generatorOptions;
const { defaultModifiers = [], defaultOptions = DEFAULT_OPTIONS } =
generatorOptions;

return function createPopper<TModifier: $Shape<Modifier<any, any>>>(
reference: Element | VirtualElement,
Expand Down Expand Up @@ -106,57 +94,6 @@ export function popperGenerator(generatorOptions: PopperGeneratorArgs = {}) {
// Strip out disabled modifiers
state.orderedModifiers = orderedModifiers.filter((m) => m.enabled);

// Validate the provided modifiers so that the consumer will get warned
// if one of the modifiers is invalid for any reason
if (__DEV__) {
const modifiers = uniqueBy(
[...orderedModifiers, ...state.options.modifiers],
({ name }) => name
);

validateModifiers(modifiers);

if (getBasePlacement(state.options.placement) === auto) {
const flipModifier = state.orderedModifiers.find(
({ name }) => name === 'flip'
);

if (!flipModifier) {
console.error(
[
'Popper: "auto" placements require the "flip" modifier be',
'present and enabled to work.',
].join(' ')
);
}
}

const {
marginTop,
marginRight,
marginBottom,
marginLeft,
} = getComputedStyle(popper);

// We no longer take into account `margins` on the popper, and it can
// cause bugs with positioning, so we'll warn the consumer
if (
[marginTop, marginRight, marginBottom, marginLeft].some((margin) =>
parseFloat(margin)
)
) {
console.warn(
[
'Popper: CSS "margin" styles cannot be used to apply padding',
'between the popper and its reference element or boundary.',
'To replicate margin, use the `offset` modifier, as well as',
'the `padding` option in the `preventOverflow` and `flip`',
'modifiers.',
].join(' ')
);
}
}

runModifierEffects();

return instance.update();
Expand All @@ -177,9 +114,6 @@ export function popperGenerator(generatorOptions: PopperGeneratorArgs = {}) {
// Don't proceed if `reference` or `popper` are not valid elements
// anymore
if (!areValidElements(reference, popper)) {
if (__DEV__) {
console.error(INVALID_ELEMENT_ERROR);
}
return;
}

Expand Down Expand Up @@ -215,12 +149,9 @@ export function popperGenerator(generatorOptions: PopperGeneratorArgs = {}) {

let __debug_loops__ = 0;
for (let index = 0; index < state.orderedModifiers.length; index++) {
if (__DEV__) {
__debug_loops__ += 1;
if (__debug_loops__ > 100) {
console.error(INFINITE_LOOP_ERROR);
break;
}
__debug_loops__ += 1;
if (__debug_loops__ > 100) {
break;
benmccann marked this conversation as resolved.
Show resolved Hide resolved
}

if (state.reset === true) {
Expand Down Expand Up @@ -254,9 +185,6 @@ export function popperGenerator(generatorOptions: PopperGeneratorArgs = {}) {
};

if (!areValidElements(reference, popper)) {
if (__DEV__) {
console.error(INVALID_ELEMENT_ERROR);
}
return instance;
}

Expand Down
22 changes: 0 additions & 22 deletions src/modifiers/arrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { within } from '../utils/within';
import mergePaddingObject from '../utils/mergePaddingObject';
import expandToHashMap from '../utils/expandToHashMap';
import { left, right, basePlacements, top, bottom } from '../enums';
import { isHTMLElement } from '../dom-utils/instanceOf';

// eslint-disable-next-line import/no-unused-modules
export type Options = {
Expand Down Expand Up @@ -101,28 +100,7 @@ function effect({ state, options }: ModifierArguments<Options>) {
}
}

if (__DEV__) {
if (!isHTMLElement(arrowElement)) {
console.error(
[
'Popper: "arrow" element must be an HTMLElement (not an SVGElement).',
'To use an SVG arrow, wrap it in an HTMLElement that will be used as',
'the arrow.',
].join(' ')
);
}
}

if (!contains(state.elements.popper, arrowElement)) {
if (__DEV__) {
console.error(
[
'Popper: "arrow" modifier\'s `element` must be a child of the popper',
'element.',
].join(' ')
);
}

return;
}

Expand Down
31 changes: 1 addition & 30 deletions src/modifiers/computeStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ export function mapToStyles({
let { x = 0, y = 0 } = offsets;

({ x, y } =
typeof roundOffsets === 'function'
? roundOffsets({ x, y })
: { x, y });
typeof roundOffsets === 'function' ? roundOffsets({ x, y }) : { x, y });

const hasX = offsets.hasOwnProperty('x');
const hasY = offsets.hasOwnProperty('y');
Expand Down Expand Up @@ -183,33 +181,6 @@ function computeStyles({ state, options }: ModifierArguments<Options>) {
roundOffsets = true,
} = options;

if (__DEV__) {
const transitionProperty =
getComputedStyle(state.elements.popper).transitionProperty || '';

if (
adaptive &&
['transform', 'top', 'right', 'bottom', 'left'].some(
(property) => transitionProperty.indexOf(property) >= 0
)
) {
console.warn(
[
'Popper: Detected CSS transitions on at least one of the following',
'CSS properties: "transform", "top", "right", "bottom", "left".',
'\n\n',
'Disable the "computeStyles" modifier\'s `adaptive` option to allow',
'for smooth transitions, or remove these properties from the CSS',
'transition declaration on the popper element if only transitioning',
'opacity or background-color for example.',
'\n\n',
'We recommend using the popper element as a wrapper around an inner',
'element that can have any CSS property transitioned for animations.',
].join(' ')
);
}
}

const commonStyles = {
placement: getBasePlacement(state.placement),
variation: getVariation(state.placement),
Expand Down
12 changes: 0 additions & 12 deletions src/utils/computeAutoPlacement.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,6 @@ export default function computeAutoPlacement(

if (allowedPlacements.length === 0) {
allowedPlacements = placements;

if (__DEV__) {
console.error(
[
'Popper: The `allowedAutoPlacements` option did not allow any',
'placements. Ensure the `placement` option matches the variation',
'of the allowed placements.',
'For example, "auto" cannot be used to allow "bottom-start".',
'Use "auto-start" instead.',
].join(' ')
);
}
}

// $FlowFixMe[incompatible-type]: Flow seems to have problems with two array unions...
Expand Down
5 changes: 0 additions & 5 deletions src/utils/format.js

This file was deleted.

151 changes: 0 additions & 151 deletions src/utils/validateModifiers.js

This file was deleted.