Skip to content

Commit

Permalink
chore: upgrade to Prettier 2
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiks committed Mar 22, 2020
1 parent adb7b5b commit c2ef6c3
Show file tree
Hide file tree
Showing 76 changed files with 478 additions and 484 deletions.
1 change: 0 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"singleQuote": true,
"bracketSpacing": false,
"trailingComma": "all",
"proseWrap": "always"
}
8 changes: 4 additions & 4 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function createPluginSCSS(output, shouldInjectNodeEnvTheme = false) {
processor(css) {
return postcss([autoprefixer, cssnano])
.process(css, {from: undefined})
.then(result => result.css);
.then((result) => result.css);
},
});
}
Expand All @@ -79,8 +79,8 @@ async function build() {
const cssConfig = createRollupConfig(
`css/${filename}`,
PLUGIN_CONFIG.concat(
createPluginSCSS(`./dist/${filename.replace('.js', '.css')}`, true),
),
createPluginSCSS(`./dist/${filename.replace('.js', '.css')}`, true)
)
);
const cssBundle = await rollup(cssConfig);
await cssBundle.write({
Expand All @@ -99,7 +99,7 @@ async function build() {

const config = createRollupConfig(
`${folder}/${filename}`,
PLUGIN_CONFIG.concat(createPluginSCSS(outputFile)),
PLUGIN_CONFIG.concat(createPluginSCSS(outputFile))
);
const bundle = await rollup(config);
await bundle.write({
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"lint-staged": "^9.5.0",
"postcss": "^7.0.26",
"poster": "0.0.9",
"prettier": "^1.19.1",
"prettier": "^2.0.1",
"promise": "^8.0.3",
"puppeteer": "^2.1.0",
"rimraf": "^3.0.0",
Expand Down
10 changes: 5 additions & 5 deletions src/addons/createSingleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {errorWhen} from '../validation';

const createSingleton: CreateSingleton = (
tippyInstances,
optionalProps = {},
optionalProps = {}
) => {
/* istanbul ignore else */
if (__DEV__) {
Expand All @@ -16,23 +16,23 @@ const createSingleton: CreateSingleton = (
'The first argument passed to createSingleton() must be an array of',
'tippy instances. The passed value was',
String(tippyInstances),
].join(' '),
].join(' ')
);
}

tippyInstances.forEach(instance => {
tippyInstances.forEach((instance) => {
instance.disable();
});

let currentTarget: Element;

const references = tippyInstances.map(instance => instance.reference);
const references = tippyInstances.map((instance) => instance.reference);

const singleton: Plugin = {
fn() {
return {
onDestroy(): void {
tippyInstances.forEach(instance => {
tippyInstances.forEach((instance) => {
instance.enable();
});
},
Expand Down
8 changes: 4 additions & 4 deletions src/addons/delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const BUBBLING_EVENTS_MAP = {
*/
function delegate(
targets: Targets,
props: Partial<Props> & {target: string},
props: Partial<Props> & {target: string}
): Instance | Instance[] {
/* istanbul ignore else */
if (__DEV__) {
Expand All @@ -26,7 +26,7 @@ function delegate(
[
'You must specity a `target` prop indicating a CSS selector string matching',
'the target elements that should receive a tippy.',
].join(' '),
].join(' ')
);
}

Expand Down Expand Up @@ -83,7 +83,7 @@ function delegate(
node: Element,
eventType: string,
handler: EventListener,
options: object | boolean = false,
options: object | boolean = false
): void {
node.addEventListener(eventType, handler, options);
listeners.push({node, eventType, handler, options});
Expand All @@ -108,7 +108,7 @@ function delegate(
const originalDestroy = instance.destroy;
instance.destroy = (shouldDestroyChildInstances = true): void => {
if (shouldDestroyChildInstances) {
childTippyInstances.forEach(instance => {
childTippyInstances.forEach((instance) => {
instance.destroy();
});
}
Expand Down
50 changes: 25 additions & 25 deletions src/createTippy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export let mountedInstances: Instance[] = [];

export default function createTippy(
reference: ReferenceElement,
passedProps: Partial<Props>,
passedProps: Partial<Props>
): Instance {
const props = evaluateProps(reference, {
...defaultProps,
Expand Down Expand Up @@ -130,7 +130,7 @@ export default function createTippy(
reference._tippy = instance;
popper._tippy = instance;

const pluginsHooks = plugins.map(plugin => plugin.fn(instance));
const pluginsHooks = plugins.map((plugin) => plugin.fn(instance));
const hasAriaExpanded = reference.hasAttribute('aria-expanded');

addListeners();
Expand All @@ -151,7 +151,7 @@ export default function createTippy(
}
});

popper.addEventListener('mouseleave', event => {
popper.addEventListener('mouseleave', (event) => {
if (
instance.props.interactive &&
instance.props.trigger.indexOf('mouseenter') >= 0
Expand Down Expand Up @@ -203,7 +203,7 @@ export default function createTippy(
return getValueAtIndexOrReturn(
instance.props.delay,
isShow ? 0 : 1,
defaultProps.delay,
defaultProps.delay
);
}

Expand All @@ -221,9 +221,9 @@ export default function createTippy(
function invokeHook(
hook: keyof LifecycleHooks,
args: [Instance, any?],
shouldInvokePropsHook = true,
shouldInvokePropsHook = true
): void {
pluginsHooks.forEach(pluginHooks => {
pluginsHooks.forEach((pluginHooks) => {
if (pluginHooks[hook]) {
pluginHooks[hook]!(...args);
}
Expand All @@ -245,7 +245,7 @@ export default function createTippy(
const id = popper.id;
const nodes = normalizeToArray(instance.props.triggerTarget || reference);

nodes.forEach(node => {
nodes.forEach((node) => {
const currentValue = node.getAttribute(attr);

if (instance.state.isVisible) {
Expand All @@ -269,13 +269,13 @@ export default function createTippy(

const nodes = normalizeToArray(instance.props.triggerTarget || reference);

nodes.forEach(node => {
nodes.forEach((node) => {
if (instance.props.interactive) {
node.setAttribute(
'aria-expanded',
instance.state.isVisible && node === getCurrentTarget()
? 'true'
: 'false',
: 'false'
);
} else {
node.removeAttribute('aria-expanded');
Expand All @@ -287,7 +287,7 @@ export default function createTippy(
doc.body.removeEventListener('mouseleave', scheduleHide);
doc.removeEventListener('mousemove', debouncedOnMouseMove);
mouseMoveListeners = mouseMoveListeners.filter(
listener => listener !== debouncedOnMouseMove,
(listener) => listener !== debouncedOnMouseMove
);
}

Expand Down Expand Up @@ -387,10 +387,10 @@ export default function createTippy(
function on(
eventType: string,
handler: EventListener,
options: boolean | object = false,
options: boolean | object = false
): void {
const nodes = normalizeToArray(instance.props.triggerTarget || reference);
nodes.forEach(node => {
nodes.forEach((node) => {
node.addEventListener(eventType, handler, options);
listeners.push({node, eventType, handler, options});
});
Expand All @@ -402,7 +402,7 @@ export default function createTippy(
on('touchend', onMouseLeave as EventListener, PASSIVE);
}

splitBySpaces(instance.props.trigger).forEach(eventType => {
splitBySpaces(instance.props.trigger).forEach((eventType) => {
if (eventType === 'manual') {
return;
}
Expand Down Expand Up @@ -451,7 +451,7 @@ export default function createTippy(
// over a new target, but `mousemove` events don't get fired. This
// causes interactive tooltips to get stuck open until the cursor is
// moved
mouseMoveListeners.forEach(listener => listener(event));
mouseMoveListeners.forEach((listener) => listener(event));
}

// Toggle show/hide when clicking click-triggered tooltips
Expand Down Expand Up @@ -497,7 +497,7 @@ export default function createTippy(

const popperTreeData = getNestedPopperTree()
.concat(popper)
.map(popper => {
.map((popper) => {
const instance = popper._tippy!;
const state = instance.popperInstance?.state;

Expand Down Expand Up @@ -592,7 +592,7 @@ export default function createTippy(
if (getIsDefaultRenderFn()) {
const {box} = getDefaultTemplateChildren();

['placement', 'reference-hidden', 'escaped'].forEach(attr => {
['placement', 'reference-hidden', 'escaped'].forEach((attr) => {
if (attr === 'placement') {
box.setAttribute('data-placement', state.placement);
} else {
Expand Down Expand Up @@ -717,14 +717,14 @@ export default function createTippy(
'keyboard navigation.',
'\n\n',
'See: https://atomiks.github.io/tippyjs/v6/accessibility/#interactivity',
].join(' '),
].join(' ')
);
}
}

function getNestedPopperTree(): PopperElement[] {
return arrayFrom(
popper.querySelectorAll('[data-__NAMESPACE_PREFIX__-root]'),
popper.querySelectorAll('[data-__NAMESPACE_PREFIX__-root]')
);
}

Expand Down Expand Up @@ -838,13 +838,13 @@ export default function createTippy(
cleanupInteractiveMouseListeners();
debouncedOnMouseMove = debounce(
onMouseMove,
nextProps.interactiveDebounce,
nextProps.interactiveDebounce
);
}

// Ensure stale aria-expanded attributes are removed
if (prevProps.triggerTarget && !nextProps.triggerTarget) {
normalizeToArray(prevProps.triggerTarget).forEach(node => {
normalizeToArray(prevProps.triggerTarget).forEach((node) => {
node.removeAttribute('aria-expanded');
});
} else if (nextProps.triggerTarget) {
Expand All @@ -865,7 +865,7 @@ export default function createTippy(
// and the nested ones get re-rendered first.
// https://github.com/atomiks/tippyjs-react/issues/177
// TODO: find a cleaner / more efficient solution(!)
getNestedPopperTree().forEach(nestedPopper => {
getNestedPopperTree().forEach((nestedPopper) => {
// React (and other UI libs likely) requires a rAF wrapper as it flushes
// its work in one
requestAnimationFrame(nestedPopper._tippy!.popperInstance!.forceUpdate);
Expand Down Expand Up @@ -894,7 +894,7 @@ export default function createTippy(
const duration = getValueAtIndexOrReturn(
instance.props.duration,
0,
defaultProps.duration,
defaultProps.duration
);

if (
Expand Down Expand Up @@ -990,7 +990,7 @@ export default function createTippy(
const duration = getValueAtIndexOrReturn(
instance.props.duration,
1,
defaultProps.duration,
defaultProps.duration
);

if (isAlreadyHidden || isDestroyed || isDisabled) {
Expand Down Expand Up @@ -1049,15 +1049,15 @@ export default function createTippy(
// If a popper is not interactive, it will be appended outside the popper
// tree by default. This seems mainly for interactive tippies, but we should
// find a workaround if possible
getNestedPopperTree().forEach(nestedPopper => {
getNestedPopperTree().forEach((nestedPopper) => {
nestedPopper._tippy!.unmount();
});

if (popper.parentNode) {
popper.parentNode.removeChild(popper);
}

mountedInstances = mountedInstances.filter(i => i !== instance);
mountedInstances = mountedInstances.filter((i) => i !== instance);

if (mountedInstances.length === 0) {
updateIOSClass(false);
Expand Down
16 changes: 8 additions & 8 deletions src/dom-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export function getArrayOfElements(value: Targets): Element[] {

export function setTransitionDuration(
els: (HTMLDivElement | null)[],
value: number,
value: number
): void {
els.forEach(el => {
els.forEach((el) => {
if (el) {
el.style.transitionDuration = `${value}ms`;
}
Expand All @@ -51,25 +51,25 @@ export function setTransitionDuration(

export function setVisibilityState(
els: (HTMLDivElement | null)[],
state: 'visible' | 'hidden',
state: 'visible' | 'hidden'
): void {
els.forEach(el => {
els.forEach((el) => {
if (el) {
el.setAttribute('data-state', state);
}
});
}

export function getOwnerDocument(
elementOrElements: Element | Element[],
elementOrElements: Element | Element[]
): Document {
const [element] = normalizeToArray(elementOrElements);
return element ? element.ownerDocument || document : document;
}

export function isCursorOutsideInteractiveBorder(
popperTreeData: PopperTreeData[],
event: MouseEvent,
event: MouseEvent
): boolean {
const {clientX, clientY} = event;

Expand Down Expand Up @@ -103,15 +103,15 @@ export function isCursorOutsideInteractiveBorder(
export function updateTransitionEndListener(
box: HTMLDivElement,
action: 'add' | 'remove',
listener: (event: TransitionEvent) => void,
listener: (event: TransitionEvent) => void
): void {
const method = `${action}EventListener` as
| 'addEventListener'
| 'removeEventListener';

// some browsers apparently support `transition` (unprefixed) but only fire
// `webkitTransitionEnd`...
['transitionend', 'webkitTransitionEnd'].forEach(event => {
['transitionend', 'webkitTransitionEnd'].forEach((event) => {
box[method](event, listener as EventListener);
});
}
Loading

0 comments on commit c2ef6c3

Please sign in to comment.