@solid-primitives/resize-observer
Advanced tools
Comparing version 2.0.11-beta.0 to 2.0.11
@@ -1,3 +0,3 @@ | ||
import { Accessor } from "solid-js"; | ||
import { MaybeAccessor, Many } from "@solid-primitives/utils"; | ||
import { Accessor } from 'solid-js'; | ||
import { MaybeAccessor, Many } from '@solid-primitives/utils'; | ||
@@ -12,8 +12,5 @@ type ResizeHandler = (rect: DOMRectReadOnly, element: Element, entry: ResizeObserverEntry) => void; | ||
*/ | ||
declare function makeResizeObserver<T extends Element>( | ||
callback: ResizeObserverCallback, | ||
options?: ResizeObserverOptions, | ||
): { | ||
observe: (ref: T) => void; | ||
unobserve: (ref: T) => void; | ||
declare function makeResizeObserver<T extends Element>(callback: ResizeObserverCallback, options?: ResizeObserverOptions): { | ||
observe: (ref: T) => void; | ||
unobserve: (ref: T) => void; | ||
}; | ||
@@ -35,7 +32,3 @@ /** | ||
*/ | ||
declare function createResizeObserver( | ||
targets: MaybeAccessor<Many<Element>>, | ||
onResize: ResizeHandler, | ||
options?: ResizeObserverOptions, | ||
): void; | ||
declare function createResizeObserver(targets: MaybeAccessor<Many<Element>>, onResize: ResizeHandler, options?: ResizeObserverOptions): void; | ||
/** | ||
@@ -45,4 +38,4 @@ * @returns object with width and height dimensions of window, page and screen. | ||
declare function getWindowSize(): { | ||
width: number; | ||
height: number; | ||
width: number; | ||
height: number; | ||
}; | ||
@@ -58,4 +51,4 @@ /** | ||
declare function createWindowSize(): { | ||
readonly width: number; | ||
readonly height: number; | ||
readonly width: number; | ||
readonly height: number; | ||
}; | ||
@@ -78,11 +71,9 @@ /** | ||
*/ | ||
declare function getElementSize(target: Element | false | undefined | null): | ||
| { | ||
width: number; | ||
height: number; | ||
} | ||
| { | ||
width: null; | ||
height: null; | ||
}; | ||
declare function getElementSize(target: Element | false | undefined | null): { | ||
width: number; | ||
height: number; | ||
} | { | ||
width: null; | ||
height: null; | ||
}; | ||
/** | ||
@@ -99,24 +90,13 @@ * Creates a reactive store-like object of current width and height dimensions of {@link target} element. | ||
declare function createElementSize(target: Element): { | ||
readonly width: number; | ||
readonly height: number; | ||
readonly width: number; | ||
readonly height: number; | ||
}; | ||
declare function createElementSize(target: Accessor<Element | false | undefined | null>): | ||
| { | ||
readonly width: number; | ||
readonly height: number; | ||
} | ||
| { | ||
readonly width: null; | ||
readonly height: null; | ||
}; | ||
declare function createElementSize(target: Accessor<Element | false | undefined | null>): { | ||
readonly width: number; | ||
readonly height: number; | ||
} | { | ||
readonly width: null; | ||
readonly height: null; | ||
}; | ||
export { | ||
ResizeHandler, | ||
createElementSize, | ||
createResizeObserver, | ||
createWindowSize, | ||
getElementSize, | ||
getWindowSize, | ||
makeResizeObserver, | ||
useWindowSize, | ||
}; | ||
export { ResizeHandler, createElementSize, createResizeObserver, createWindowSize, getElementSize, getWindowSize, makeResizeObserver, useWindowSize }; |
@@ -1,5 +0,5 @@ | ||
import { onCleanup, $PROXY, createEffect, on, onMount, $TRACK } from "solid-js"; | ||
import { asArray, handleDiffArray, createStaticStore } from "@solid-primitives/utils"; | ||
import { createSharedRoot } from "@solid-primitives/rootless"; | ||
import { makeEventListener } from "@solid-primitives/event-listener"; | ||
import { onCleanup, $PROXY, createEffect, on, onMount, $TRACK } from 'solid-js'; | ||
import { asArray, handleDiffArray, createStaticStore } from '@solid-primitives/utils'; | ||
import { createSharedRoot } from '@solid-primitives/rootless'; | ||
import { makeEventListener } from '@solid-primitives/event-listener'; | ||
@@ -11,4 +11,4 @@ // src/index.ts | ||
return { | ||
observe: ref => resizeObserver.observe(ref, options), | ||
unobserve: resizeObserver.unobserve.bind(resizeObserver), | ||
observe: (ref) => resizeObserver.observe(ref, options), | ||
unobserve: resizeObserver.unobserve.bind(resizeObserver) | ||
}; | ||
@@ -32,3 +32,4 @@ } | ||
let refs; | ||
if (typeof targets === "function") refs = () => asArray(targets()).slice(); | ||
if (typeof targets === "function") | ||
refs = () => asArray(targets()).slice(); | ||
else if (Array.isArray(targets) && $PROXY in targets) | ||
@@ -44,3 +45,3 @@ refs = () => { | ||
createEffect( | ||
on(refs, (current, prev = []) => handleDiffArray(current, prev, observe, unobserve)), | ||
on(refs, (current, prev = []) => handleDiffArray(current, prev, observe, unobserve)) | ||
); | ||
@@ -51,3 +52,3 @@ } | ||
width: window.innerWidth, | ||
height: window.innerHeight, | ||
height: window.innerHeight | ||
}; | ||
@@ -63,3 +64,4 @@ } | ||
function getElementSize(target) { | ||
if (!target) return { width: null, height: null }; | ||
if (!target) | ||
return { width: null, height: null }; | ||
const { width, height } = target.getBoundingClientRect(); | ||
@@ -70,10 +72,8 @@ return { width, height }; | ||
const [size, setSize] = createStaticStore( | ||
typeof target !== "function" | ||
? getElementSize(target) | ||
: (() => { | ||
onMount(() => setSize(getElementSize(target()))); | ||
return { width: null, height: null }; | ||
})(), | ||
typeof target !== "function" ? getElementSize(target) : (() => { | ||
onMount(() => setSize(getElementSize(target()))); | ||
return { width: null, height: null }; | ||
})() | ||
); | ||
const updateSize = e => setSize({ width: e.width, height: e.height }); | ||
const updateSize = (e) => setSize({ width: e.width, height: e.height }); | ||
createResizeObserver(typeof target === "function" ? () => target() || [] : target, updateSize); | ||
@@ -83,10 +83,2 @@ return size; | ||
export { | ||
createElementSize, | ||
createResizeObserver, | ||
createWindowSize, | ||
getElementSize, | ||
getWindowSize, | ||
makeResizeObserver, | ||
useWindowSize, | ||
}; | ||
export { createElementSize, createResizeObserver, createWindowSize, getElementSize, getWindowSize, makeResizeObserver, useWindowSize }; |
@@ -1,5 +0,5 @@ | ||
import "solid-js"; | ||
import "@solid-primitives/utils"; | ||
import { createSharedRoot } from "@solid-primitives/rootless"; | ||
import "@solid-primitives/event-listener"; | ||
import 'solid-js'; | ||
import '@solid-primitives/utils'; | ||
import { createSharedRoot } from '@solid-primitives/rootless'; | ||
import '@solid-primitives/event-listener'; | ||
@@ -10,4 +10,6 @@ // src/index.ts | ||
return { | ||
observe: () => {}, | ||
unobserve: () => {}, | ||
observe: () => { | ||
}, | ||
unobserve: () => { | ||
} | ||
}; | ||
@@ -37,10 +39,2 @@ } | ||
export { | ||
createElementSize, | ||
createResizeObserver, | ||
createWindowSize, | ||
getElementSize, | ||
getWindowSize, | ||
makeResizeObserver, | ||
useWindowSize, | ||
}; | ||
export { createElementSize, createResizeObserver, createWindowSize, getElementSize, getWindowSize, makeResizeObserver, useWindowSize }; |
{ | ||
"name": "@solid-primitives/resize-observer", | ||
"version": "2.0.11-beta.0", | ||
"version": "2.0.11", | ||
"description": "Reactive primitives for observing resizing of HTML elements.", | ||
@@ -80,5 +80,5 @@ "author": "Moshe Udimar", | ||
"dependencies": { | ||
"@solid-primitives/event-listener": "^2.2.8-beta.0", | ||
"@solid-primitives/rootless": "^1.2.6-beta.0", | ||
"@solid-primitives/utils": "^5.4.0-beta.0" | ||
"@solid-primitives/event-listener": "^2.2.8", | ||
"@solid-primitives/rootless": "^1.2.6", | ||
"@solid-primitives/utils": "^5.4.0" | ||
}, | ||
@@ -85,0 +85,0 @@ "peerDependencies": { |
@@ -0,0 +0,0 @@ <p> |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
20504
8
328