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

first commit

parent 81c6da4b
import { createPopper, popperGenerator, detectOverflow } from "./createPopper";
export * from "./types";
export { createPopper, popperGenerator, detectOverflow };
import { createPopper, popperGenerator, detectOverflow } from "./createPopper.js";
// eslint-disable-next-line import/no-unused-modules
export { createPopper, popperGenerator, detectOverflow };
\ No newline at end of file
// @flow
import { createPopper, popperGenerator, detectOverflow } from './createPopper';
export type * from './types';
// eslint-disable-next-line import/no-unused-modules
export { createPopper, popperGenerator, detectOverflow };
import { popperGenerator, detectOverflow } from "./createPopper";
export * from "./types";
declare const defaultModifiers: (import("./types").Modifier<"popperOffsets", {}> | import("./types").Modifier<"eventListeners", import("./modifiers/eventListeners").Options> | import("./types").Modifier<"computeStyles", import("./modifiers/computeStyles").Options> | import("./types").Modifier<"applyStyles", {}>)[];
declare const createPopper: <TModifier extends Partial<import("./types").Modifier<any, any>>>(reference: Element | import("./types").VirtualElement, popper: HTMLElement, options?: Partial<import("./types").OptionsGeneric<TModifier>>) => import("./types").Instance;
export { createPopper, popperGenerator, defaultModifiers, detectOverflow };
import { popperGenerator, detectOverflow } from "./createPopper.js";
import eventListeners from "./modifiers/eventListeners.js";
import popperOffsets from "./modifiers/popperOffsets.js";
import computeStyles from "./modifiers/computeStyles.js";
import applyStyles from "./modifiers/applyStyles.js";
var defaultModifiers = [eventListeners, popperOffsets, computeStyles, applyStyles];
var createPopper = /*#__PURE__*/popperGenerator({
defaultModifiers: defaultModifiers
}); // eslint-disable-next-line import/no-unused-modules
export { createPopper, popperGenerator, defaultModifiers, detectOverflow };
\ No newline at end of file
// @flow
import { popperGenerator, detectOverflow } from './createPopper';
import eventListeners from './modifiers/eventListeners';
import popperOffsets from './modifiers/popperOffsets';
import computeStyles from './modifiers/computeStyles';
import applyStyles from './modifiers/applyStyles';
export type * from './types';
const defaultModifiers = [
eventListeners,
popperOffsets,
computeStyles,
applyStyles,
];
const createPopper = popperGenerator({ defaultModifiers });
// eslint-disable-next-line import/no-unused-modules
export { createPopper, popperGenerator, defaultModifiers, detectOverflow };
import { popperGenerator, detectOverflow } from "./createPopper";
export * from "./types";
declare const defaultModifiers: (import("./types").Modifier<"popperOffsets", {}> | import("./types").Modifier<"flip", import("./modifiers/flip").Options> | import("./types").Modifier<"hide", {}> | import("./types").Modifier<"offset", import("./modifiers/offset").Options> | import("./types").Modifier<"eventListeners", import("./modifiers/eventListeners").Options> | import("./types").Modifier<"computeStyles", import("./modifiers/computeStyles").Options> | import("./types").Modifier<"arrow", import("./modifiers/arrow").Options> | import("./types").Modifier<"preventOverflow", import("./modifiers/preventOverflow").Options> | import("./types").Modifier<"applyStyles", {}>)[];
declare const createPopper: <TModifier extends Partial<import("./types").Modifier<any, any>>>(reference: Element | import("./types").VirtualElement, popper: HTMLElement, options?: Partial<import("./types").OptionsGeneric<TModifier>>) => import("./types").Instance;
export { createPopper, popperGenerator, defaultModifiers, detectOverflow };
export { createPopper as createPopperLite } from "./popper-lite";
export * from "./modifiers";
import { popperGenerator, detectOverflow } from "./createPopper.js";
import eventListeners from "./modifiers/eventListeners.js";
import popperOffsets from "./modifiers/popperOffsets.js";
import computeStyles from "./modifiers/computeStyles.js";
import applyStyles from "./modifiers/applyStyles.js";
import offset from "./modifiers/offset.js";
import flip from "./modifiers/flip.js";
import preventOverflow from "./modifiers/preventOverflow.js";
import arrow from "./modifiers/arrow.js";
import hide from "./modifiers/hide.js";
var defaultModifiers = [eventListeners, popperOffsets, computeStyles, applyStyles, offset, flip, preventOverflow, arrow, hide];
var createPopper = /*#__PURE__*/popperGenerator({
defaultModifiers: defaultModifiers
}); // eslint-disable-next-line import/no-unused-modules
export { createPopper, popperGenerator, defaultModifiers, detectOverflow }; // eslint-disable-next-line import/no-unused-modules
export { createPopper as createPopperLite } from "./popper-lite.js"; // eslint-disable-next-line import/no-unused-modules
export * from "./modifiers/index.js";
\ No newline at end of file
// @flow
import { popperGenerator, detectOverflow } from './createPopper';
import eventListeners from './modifiers/eventListeners';
import popperOffsets from './modifiers/popperOffsets';
import computeStyles from './modifiers/computeStyles';
import applyStyles from './modifiers/applyStyles';
import offset from './modifiers/offset';
import flip from './modifiers/flip';
import preventOverflow from './modifiers/preventOverflow';
import arrow from './modifiers/arrow';
import hide from './modifiers/hide';
export type * from './types';
const defaultModifiers = [
eventListeners,
popperOffsets,
computeStyles,
applyStyles,
offset,
flip,
preventOverflow,
arrow,
hide,
];
const createPopper = popperGenerator({ defaultModifiers });
// eslint-disable-next-line import/no-unused-modules
export { createPopper, popperGenerator, defaultModifiers, detectOverflow };
// eslint-disable-next-line import/no-unused-modules
export { createPopper as createPopperLite } from './popper-lite';
// eslint-disable-next-line import/no-unused-modules
export * from './modifiers';
import { Placement, ModifierPhases } from "./enums";
import { PopperOffsetsModifier } from "./modifiers/popperOffsets";
import { FlipModifier } from "./modifiers/flip";
import { HideModifier } from "./modifiers/hide";
import { OffsetModifier } from "./modifiers/offset";
import { EventListenersModifier } from "./modifiers/eventListeners";
import { ComputeStylesModifier } from "./modifiers/computeStyles";
import { ArrowModifier } from "./modifiers/arrow";
import { PreventOverflowModifier } from "./modifiers/preventOverflow";
import { ApplyStylesModifier } from "./modifiers/applyStyles";
export declare type Obj = {
[key: string]: any;
};
export declare type VisualViewport = EventTarget & {
width: number;
height: number;
offsetLeft: number;
offsetTop: number;
scale: number;
};
export declare type Window = {
innerHeight: number;
offsetHeight: number;
innerWidth: number;
offsetWidth: number;
pageXOffset: number;
pageYOffset: number;
getComputedStyle: typeof getComputedStyle;
addEventListener(type: any, listener: any, optionsOrUseCapture?: any): void;
removeEventListener(type: any, listener: any, optionsOrUseCapture?: any): void;
Element: Element;
HTMLElement: HTMLElement;
Node: Node;
toString(): "[object Window]";
devicePixelRatio: number;
visualViewport?: VisualViewport;
ShadowRoot: ShadowRoot;
};
export declare type Rect = {
width: number;
height: number;
x: number;
y: number;
};
export declare type Offsets = {
y: number;
x: number;
};
export declare type PositioningStrategy = "absolute" | "fixed";
export declare type StateRects = {
reference: Rect;
popper: Rect;
};
export declare type StateOffsets = {
popper: Offsets;
arrow?: Offsets;
};
declare type OffsetData = {
[key in Placement]: Offsets;
};
export declare type State = {
elements: {
reference: Element | VirtualElement;
popper: HTMLElement;
arrow?: HTMLElement;
};
options: OptionsGeneric<any>;
placement: Placement;
strategy: PositioningStrategy;
orderedModifiers: Array<Modifier<any, any>>;
rects: StateRects;
scrollParents: {
reference: Array<Element | Window | VisualViewport>;
popper: Array<Element | Window | VisualViewport>;
};
styles: {
[key: string]: Partial<CSSStyleDeclaration>;
};
attributes: {
[key: string]: {
[key: string]: string | boolean;
};
};
modifiersData: {
arrow?: {
x?: number;
y?: number;
centerOffset: number;
};
hide?: {
isReferenceHidden: boolean;
hasPopperEscaped: boolean;
referenceClippingOffsets: SideObject;
popperEscapeOffsets: SideObject;
};
offset?: OffsetData;
preventOverflow?: Offsets;
popperOffsets?: Offsets;
[key: string]: any;
};
reset: boolean;
};
export declare type Instance = {
state: State;
destroy: () => void;
forceUpdate: () => void;
update: () => Promise<Partial<State>>;
setOptions: (options: Partial<OptionsGeneric<any>>) => Promise<Partial<State>>;
};
export declare type ModifierArguments<Options extends Obj> = {
state: State;
instance: Instance;
options: Partial<Options>;
name: string;
};
export declare type Modifier<Name, Options> = {
name: Name;
enabled: boolean;
phase: ModifierPhases;
requires?: Array<string>;
requiresIfExists?: Array<string>;
fn: (arg0: ModifierArguments<Options>) => State | void;
effect?: (arg0: ModifierArguments<Options>) => (() => void) | void;
options?: Partial<Options>;
data?: Obj;
};
export declare type StrictModifiers = Partial<OffsetModifier> | Partial<ApplyStylesModifier> | Partial<ArrowModifier> | Partial<HideModifier> | Partial<ComputeStylesModifier> | Partial<EventListenersModifier> | Partial<FlipModifier> | Partial<PreventOverflowModifier> | Partial<PopperOffsetsModifier>;
export declare type EventListeners = {
scroll: boolean;
resize: boolean;
};
export declare type Options = {
placement: Placement;
modifiers: Array<Partial<Modifier<any, any>>>;
strategy: PositioningStrategy;
onFirstUpdate?: (arg0: Partial<State>) => void;
};
export declare type OptionsGeneric<TModifier> = {
placement: Placement;
modifiers: Array<TModifier>;
strategy: PositioningStrategy;
onFirstUpdate?: (arg0: Partial<State>) => void;
};
export declare type UpdateCallback = (arg0: State) => void;
export declare type ClientRectObject = {
x: number;
y: number;
top: number;
left: number;
right: number;
bottom: number;
width: number;
height: number;
};
export declare type SideObject = {
top: number;
left: number;
right: number;
bottom: number;
};
export declare type Padding = number | Partial<SideObject>;
export declare type VirtualElement = {
getBoundingClientRect: () => ClientRect | DOMRect;
contextElement?: Element;
};
export {};
// @flow
/* eslint-disable import/no-unused-modules */
import type { Placement, ModifierPhases } from './enums';
import type { PopperOffsetsModifier } from './modifiers/popperOffsets';
import type { FlipModifier } from './modifiers/flip';
import type { HideModifier } from './modifiers/hide';
import type { OffsetModifier } from './modifiers/offset';
import type { EventListenersModifier } from './modifiers/eventListeners';
import type { ComputeStylesModifier } from './modifiers/computeStyles';
import type { ArrowModifier } from './modifiers/arrow';
import type { PreventOverflowModifier } from './modifiers/preventOverflow';
import type { ApplyStylesModifier } from './modifiers/applyStyles';
export type Obj = { [key: string]: any };
export type VisualViewport = EventTarget & {
width: number,
height: number,
offsetLeft: number,
offsetTop: number,
scale: number,
};
// This is a limited subset of the Window object, Flow doesn't provide one
// so we define our own, with just the properties we need
export type Window = {|
innerHeight: number,
offsetHeight: number,
innerWidth: number,
offsetWidth: number,
pageXOffset: number,
pageYOffset: number,
getComputedStyle: typeof getComputedStyle,
addEventListener(type: any, listener: any, optionsOrUseCapture?: any): void,
removeEventListener(
type: any,
listener: any,
optionsOrUseCapture?: any
): void,
Element: Element,
HTMLElement: HTMLElement,
Node: Node,
toString(): '[object Window]',
devicePixelRatio: number,
visualViewport?: VisualViewport,
ShadowRoot: ShadowRoot,
|};
export type Rect = {|
width: number,
height: number,
x: number,
y: number,
|};
export type Offsets = {|
y: number,
x: number,
|};
export type PositioningStrategy = 'absolute' | 'fixed';
export type StateRects = {|
reference: Rect,
popper: Rect,
|};
export type StateOffsets = {|
popper: Offsets,
arrow?: Offsets,
|};
/*:: type OffsetData = { [Placement]: Offsets }; */
/*;; type OffsetData = { [key in Placement]: Offsets } */
export type State = {|
elements: {|
reference: Element | VirtualElement,
popper: HTMLElement,
arrow?: HTMLElement,
|},
options: OptionsGeneric<any>,
placement: Placement,
strategy: PositioningStrategy,
orderedModifiers: Array<Modifier<any, any>>,
rects: StateRects,
scrollParents: {|
reference: Array<Element | Window | VisualViewport>,
popper: Array<Element | Window | VisualViewport>,
|},
styles: {|
[key: string]: $Shape<CSSStyleDeclaration>,
|},
attributes: {|
[key: string]: { [key: string]: string | boolean },
|},
modifiersData: {
arrow?: {
x?: number,
y?: number,
centerOffset: number,
},
hide?: {
isReferenceHidden: boolean,
hasPopperEscaped: boolean,
referenceClippingOffsets: SideObject,
popperEscapeOffsets: SideObject,
},
offset?: OffsetData,
preventOverflow?: Offsets,
popperOffsets?: Offsets,
[key: string]: any,
},
reset: boolean,
|};
export type Instance = {|
state: State,
destroy: () => void,
forceUpdate: () => void,
update: () => Promise<$Shape<State>>,
setOptions: (options: $Shape<OptionsGeneric<any>>) => Promise<$Shape<State>>,
|};
export type ModifierArguments<Options: Obj> = {
state: State,
instance: Instance,
options: $Shape<Options>,
name: string,
};
export type Modifier<Name, Options> = {|
name: Name,
enabled: boolean,
phase: ModifierPhases,
requires?: Array<string>,
requiresIfExists?: Array<string>,
fn: (ModifierArguments<Options>) => State | void,
effect?: (ModifierArguments<Options>) => (() => void) | void,
options?: $Shape<Options>,
data?: Obj,
|};
export type StrictModifiers =
| $Shape<OffsetModifier>
| $Shape<ApplyStylesModifier>
| $Shape<ArrowModifier>
| $Shape<HideModifier>
| $Shape<ComputeStylesModifier>
| $Shape<EventListenersModifier>
| $Shape<FlipModifier>
| $Shape<PreventOverflowModifier>
| $Shape<PopperOffsetsModifier>;
export type EventListeners = {| scroll: boolean, resize: boolean |};
export type Options = {|
placement: Placement,
modifiers: Array<$Shape<Modifier<any, any>>>,
strategy: PositioningStrategy,
onFirstUpdate?: ($Shape<State>) => void,
|};
export type OptionsGeneric<TModifier> = {|
placement: Placement,
modifiers: Array<TModifier>,
strategy: PositioningStrategy,
onFirstUpdate?: ($Shape<State>) => void,
|};
export type UpdateCallback = (State) => void;
export type ClientRectObject = {|
x: number,
y: number,
top: number,
left: number,
right: number,
bottom: number,
width: number,
height: number,
|};
export type SideObject = {|
top: number,
left: number,
right: number,
bottom: number,
|};
export type Padding = number | $Shape<SideObject>;
export type VirtualElement = {|
getBoundingClientRect: () => ClientRect | DOMRect,
contextElement?: Element,
|};
import { State, Padding } from "../types";
import { Placement, ComputedPlacement, Boundary, RootBoundary } from "../enums";
declare type Options = {
placement: Placement;
padding: Padding;
boundary: Boundary;
rootBoundary: RootBoundary;
flipVariations: boolean;
allowedAutoPlacements?: Array<Placement>;
};
export default function computeAutoPlacement(state: Partial<State>, options?: Options): Array<ComputedPlacement>;
export {};
import getVariation from "./getVariation.js";
import { variationPlacements, basePlacements, placements as allPlacements } from "../enums.js";
import detectOverflow from "./detectOverflow.js";
import getBasePlacement from "./getBasePlacement.js";
/*:: type OverflowsMap = { [ComputedPlacement]: number }; */
/*;; type OverflowsMap = { [key in ComputedPlacement]: number }; */
export default function computeAutoPlacement(state, options) {
if (options === void 0) {
options = {};
}
var _options = options,
placement = _options.placement,
boundary = _options.boundary,
rootBoundary = _options.rootBoundary,
padding = _options.padding,
flipVariations = _options.flipVariations,
_options$allowedAutoP = _options.allowedAutoPlacements,
allowedAutoPlacements = _options$allowedAutoP === void 0 ? allPlacements : _options$allowedAutoP;
var variation = getVariation(placement);
var placements = variation ? flipVariations ? variationPlacements : variationPlacements.filter(function (placement) {
return getVariation(placement) === variation;
}) : basePlacements;
var allowedPlacements = placements.filter(function (placement) {
return allowedAutoPlacements.indexOf(placement) >= 0;
});
if (allowedPlacements.length === 0) {
allowedPlacements = placements;
if (process.env.NODE_ENV !== "production") {
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...
var overflows = allowedPlacements.reduce(function (acc, placement) {
acc[placement] = detectOverflow(state, {
placement: placement,
boundary: boundary,
rootBoundary: rootBoundary,
padding: padding
})[getBasePlacement(placement)];
return acc;
}, {});
return Object.keys(overflows).sort(function (a, b) {
return overflows[a] - overflows[b];
});
}
\ No newline at end of file
// @flow
import type { State, Padding } from '../types';
import type {
Placement,
ComputedPlacement,
Boundary,
RootBoundary,
} from '../enums';
import getVariation from './getVariation';
import {
variationPlacements,
basePlacements,
placements as allPlacements,
} from '../enums';
import detectOverflow from './detectOverflow';
import getBasePlacement from './getBasePlacement';
type Options = {
placement: Placement,
padding: Padding,
boundary: Boundary,
rootBoundary: RootBoundary,
flipVariations: boolean,
allowedAutoPlacements?: Array<Placement>,
};
/*:: type OverflowsMap = { [ComputedPlacement]: number }; */
/*;; type OverflowsMap = { [key in ComputedPlacement]: number }; */
export default function computeAutoPlacement(
state: $Shape<State>,
options: Options = {}
): Array<ComputedPlacement> {
const {
placement,
boundary,
rootBoundary,
padding,
flipVariations,
allowedAutoPlacements = allPlacements,
} = options;
const variation = getVariation(placement);
const placements = variation
? flipVariations
? variationPlacements
: variationPlacements.filter(
(placement) => getVariation(placement) === variation
)
: basePlacements;
let allowedPlacements = placements.filter(
(placement) => allowedAutoPlacements.indexOf(placement) >= 0
);
if (allowedPlacements.length === 0) {
allowedPlacements = placements;
if (false) {
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...
const overflows: OverflowsMap = allowedPlacements.reduce((acc, placement) => {
acc[placement] = detectOverflow(state, {
placement,
boundary,
rootBoundary,
padding,
})[getBasePlacement(placement)];
return acc;
}, {});
return Object.keys(overflows).sort((a, b) => overflows[a] - overflows[b]);
}
import { Rect, PositioningStrategy, Offsets, ClientRectObject } from "../types";
import { Placement } from "../enums";
export default function computeOffsets({ reference, element, placement }: {
reference: Rect | ClientRectObject;
element: Rect | ClientRectObject;
strategy: PositioningStrategy;
placement?: Placement;
}): Offsets;
import getBasePlacement from "./getBasePlacement.js";
import getVariation from "./getVariation.js";
import getMainAxisFromPlacement from "./getMainAxisFromPlacement.js";
import { top, right, bottom, left, start, end } from "../enums.js";
export default function computeOffsets(_ref) {
var reference = _ref.reference,
element = _ref.element,
placement = _ref.placement;
var basePlacement = placement ? getBasePlacement(placement) : null;
var variation = placement ? getVariation(placement) : null;
var commonX = reference.x + reference.width / 2 - element.width / 2;
var commonY = reference.y + reference.height / 2 - element.height / 2;
var offsets;
switch (basePlacement) {
case top:
offsets = {
x: commonX,
y: reference.y - element.height
};
break;
case bottom:
offsets = {
x: commonX,
y: reference.y + reference.height
};
break;
case right:
offsets = {
x: reference.x + reference.width,
y: commonY
};
break;
case left:
offsets = {
x: reference.x - element.width,
y: commonY
};
break;
default:
offsets = {
x: reference.x,
y: reference.y
};
}
var mainAxis = basePlacement ? getMainAxisFromPlacement(basePlacement) : null;
if (mainAxis != null) {
var len = mainAxis === 'y' ? 'height' : 'width';
switch (variation) {
case start:
offsets[mainAxis] = offsets[mainAxis] - (reference[len] / 2 - element[len] / 2);
break;
case end:
offsets[mainAxis] = offsets[mainAxis] + (reference[len] / 2 - element[len] / 2);
break;
default:
}
}
return offsets;
}
\ No newline at end of file
// @flow
import getBasePlacement from './getBasePlacement';
import getVariation from './getVariation';
import getMainAxisFromPlacement from './getMainAxisFromPlacement';
import type {
Rect,
PositioningStrategy,
Offsets,
ClientRectObject,
} from '../types';
import { top, right, bottom, left, start, end, type Placement } from '../enums';
export default function computeOffsets({
reference,
element,
placement,
}: {
reference: Rect | ClientRectObject,
element: Rect | ClientRectObject,
strategy: PositioningStrategy,
placement?: Placement,
}): Offsets {
const basePlacement = placement ? getBasePlacement(placement) : null;
const variation = placement ? getVariation(placement) : null;
const commonX = reference.x + reference.width / 2 - element.width / 2;
const commonY = reference.y + reference.height / 2 - element.height / 2;
let offsets;
switch (basePlacement) {
case top:
offsets = {
x: commonX,
y: reference.y - element.height,
};
break;
case bottom:
offsets = {
x: commonX,
y: reference.y + reference.height,
};
break;
case right:
offsets = {
x: reference.x + reference.width,
y: commonY,
};
break;
case left:
offsets = {
x: reference.x - element.width,
y: commonY,
};
break;
default:
offsets = {
x: reference.x,
y: reference.y,
};
}
const mainAxis = basePlacement
? getMainAxisFromPlacement(basePlacement)
: null;
if (mainAxis != null) {
const len = mainAxis === 'y' ? 'height' : 'width';
switch (variation) {
case start:
offsets[mainAxis] =
offsets[mainAxis] - (reference[len] / 2 - element[len] / 2);
break;
case end:
offsets[mainAxis] =
offsets[mainAxis] + (reference[len] / 2 - element[len] / 2);
break;
default:
}
}
return offsets;
}
export default function debounce<T>(fn: Function): () => Promise<T>;
export default function debounce(fn) {
var pending;
return function () {
if (!pending) {
pending = new Promise(function (resolve) {
Promise.resolve().then(function () {
pending = undefined;
resolve(fn());
});
});
}
return pending;
};
}
\ 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