forked from jaredpalmer/formik
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run prettier and update monorepo deps
- Loading branch information
1 parent
a8b1700
commit 76dbc46
Showing
102 changed files
with
720 additions
and
740 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import '../styles/globals.css' | ||
import '../styles/globals.css'; | ||
|
||
function MyApp({ Component, pageProps }) { | ||
return <Component {...pageProps} /> | ||
return <Component {...pageProps} />; | ||
} | ||
|
||
export default MyApp | ||
export default MyApp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { default } from './intersection-observer' | ||
export { default } from './intersection-observer'; |
48 changes: 24 additions & 24 deletions
48
docs/src/components/blog/intersection-observer/manager.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,65 @@ | ||
import { hasEqualOptions, parseOptions } from './utils' | ||
import { hasEqualOptions, parseOptions } from './utils'; | ||
|
||
if (typeof window !== 'undefined') { | ||
require('intersection-observer') | ||
require('intersection-observer'); | ||
} | ||
|
||
const manager = (function makeManager() { | ||
const observers = new Map() | ||
const observers = new Map(); | ||
|
||
function getObserver(options) { | ||
return ( | ||
findObserver(options) || | ||
new IntersectionObserver(intersectionCallback, options) | ||
) | ||
); | ||
} | ||
|
||
function findObserver(options = {}) { | ||
const parsedOptions = parseOptions(options) | ||
const parsedOptions = parseOptions(options); | ||
for (const observer of observers.keys()) { | ||
if (hasEqualOptions(observer, parsedOptions)) { | ||
return observer | ||
return observer; | ||
} | ||
} | ||
return null | ||
return null; | ||
} | ||
|
||
function getObserverTargets(observer) { | ||
return !observers.has(observer) | ||
? observers.set(observer, new Map()).get(observer) | ||
: observers.get(observer) | ||
: observers.get(observer); | ||
} | ||
|
||
function observeTarget(observer, target, handler) { | ||
const targets = getObserverTargets(observer) | ||
targets.set(target, handler) | ||
observer.observe(target) | ||
const targets = getObserverTargets(observer); | ||
targets.set(target, handler); | ||
observer.observe(target); | ||
} | ||
|
||
function unobserveTarget(observer, target) { | ||
const handlers = getObserverTargets(observer) | ||
handlers.delete(target) | ||
observer.unobserve(target) | ||
const handlers = getObserverTargets(observer); | ||
handlers.delete(target); | ||
observer.unobserve(target); | ||
} | ||
|
||
function intersectionCallback(entries, observer) { | ||
for (let entry of entries) { | ||
const handlers = getObserverTargets(observer) | ||
const handler = handlers.get(entry.target) | ||
const handlers = getObserverTargets(observer); | ||
const handler = handlers.get(entry.target); | ||
if (handler) { | ||
handler(entry) | ||
handler(entry); | ||
} | ||
} | ||
} | ||
|
||
return { | ||
getObserver, | ||
observeTarget, | ||
unobserveTarget | ||
} | ||
})() | ||
unobserveTarget, | ||
}; | ||
})(); | ||
|
||
export default manager | ||
export const { getObserver } = manager | ||
export const { observeTarget } = manager | ||
export const { unobserveTarget } = manager | ||
export default manager; | ||
export const { getObserver } = manager; | ||
export const { observeTarget } = manager; | ||
export const { unobserveTarget } = manager; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,53 @@ | ||
export function isDOMNode(node) { | ||
return ( | ||
node && Object.prototype.hasOwnProperty.call(node, 'getBoundingClientRect') | ||
) | ||
); | ||
} | ||
|
||
export function parseOptions(options = {}) { | ||
return { | ||
root: options.root || null, | ||
rootMargin: parseRootMargin(options.rootMargin), | ||
threshold: parseThreshold(options.threshold) | ||
} | ||
threshold: parseThreshold(options.threshold), | ||
}; | ||
} | ||
|
||
export function hasEqualOptions(observer, options) { | ||
return ( | ||
equalPair(options.root, observer.root) && | ||
equalPair(options.rootMargin, observer.rootMargin) && | ||
equalPair(options.threshold, observer.thresholds) | ||
) | ||
); | ||
} | ||
|
||
function parseRootMargin(rootMargin) { | ||
const margins = (rootMargin || '0px').trim().split(/\s+/) | ||
margins.forEach(validateRootMargin) | ||
margins[1] = margins[1] || margins[0] | ||
margins[2] = margins[2] || margins[0] | ||
margins[3] = margins[3] || margins[1] | ||
return margins.join(' ') | ||
const margins = (rootMargin || '0px').trim().split(/\s+/); | ||
margins.forEach(validateRootMargin); | ||
margins[1] = margins[1] || margins[0]; | ||
margins[2] = margins[2] || margins[0]; | ||
margins[3] = margins[3] || margins[1]; | ||
return margins.join(' '); | ||
} | ||
|
||
function validateRootMargin(margin) { | ||
if (!/^-?\d*\.?\d+(px|%)$/.test(margin)) { | ||
throw new Error('rootMargin must be specified as a CSS margin property') | ||
throw new Error('rootMargin must be specified as a CSS margin property'); | ||
} | ||
} | ||
|
||
function parseThreshold(threshold) { | ||
return !Array.isArray(threshold) | ||
? [typeof threshold !== 'undefined' ? threshold : 0] | ||
: threshold | ||
: threshold; | ||
} | ||
|
||
function equalPair(optionA, optionB) { | ||
if (Array.isArray(optionA) && Array.isArray(optionB)) { | ||
if (optionA.length === optionB.length) { | ||
return optionA.every((element, idx) => | ||
equalPair(optionA[idx], optionB[idx]) | ||
) | ||
); | ||
} | ||
} | ||
return optionA === optionB | ||
return optionA === optionB; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.