Skip to content

Commit

Permalink
Merge branch 'main' into feat/event-listener
Browse files Browse the repository at this point in the history
  • Loading branch information
TGlide committed Apr 22, 2024
2 parents 0fd2705 + 424bf56 commit 4d07578
Show file tree
Hide file tree
Showing 21 changed files with 117 additions and 107 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { isBrowser } from "$lib/internal/utils/browser.js";


/**
* Returns a reactive value that is equal to `document.activeElement`.
* It automatically listens for changes, keeping the reference up to date.
*
* @export
* @returns {{ value: Readonly<Element | null> }}
*/
export function useActiveElement(): { value: Readonly<Element | null> } {
const activeElement = $state({ value: isBrowser() ? document.activeElement : null });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import type { FunctionArgs, ValueOrGetter } from "$lib/internal/types.js";
* The second parameter is the time to wait before calling the original callback.
* Alternatively, it can also be a getter function that returns the time to wait.
*
* @export
* @template {FunctionArgs} Callback
* @param {Callback} callback
* @param {number} wait
*/
export function useDebounce<Callback extends FunctionArgs>(
callback: Callback,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,31 @@ type Options = {
box?: "content-box" | "border-box";
};


/**
* Returns a reactive value holding the size of `node`.
*
* @export
* @param {ValueOrGetter<HTMLElement | undefined>} node
* @param {Options} [options={
* box: "border-box",
* }]
* @returns {*}
*/
export function useElementSize(
_node: ValueOrGetter<HTMLElement | undefined>,
node: ValueOrGetter<HTMLElement | undefined>,
options: Options = {
box: "border-box",
}
) {
const node = boxed(_node);
const $node = boxed(node);
const size = $state({
width: options.initialSize?.width ?? 0,
height: options.initialSize?.height ?? 0,
});

$effect(() => {
if (!node.value) return;
if (!$node.value) return;

const observer = new ResizeObserver((entries) => {
for (const entry of entries) {
Expand All @@ -33,7 +44,7 @@ export function useElementSize(
size.height = boxSizeArr.reduce((acc, size) => Math.max(acc, size.blockSize), 0);
}
});
observer.observe(node.value);
observer.observe($node.value);

return () => {
observer.disconnect();
Expand Down

This file was deleted.

8 changes: 4 additions & 4 deletions pnpm-lock.yaml

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

14 changes: 4 additions & 10 deletions sites/docs/content/functions/use-active-element.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,10 @@ import { UseActiveElementDemo } from '$lib/components/demos';
import { useActiveElement } from "runed";
const activeElement = useActiveElement();
const text = $derived(
`Currently active element: ${
activeElement.value !== nulla
? activeElement.value.localName
: "No active element found"
}`a
);
</script>
<div class="rounded-md bg-card p-8">
<p>{text}</p>
</div>
<p>
Currently active element:
{activeElement.value?.localName ?? 'No active element found'}
</p>
```
4 changes: 2 additions & 2 deletions sites/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"clsx": "^2.1.0",
"concurrently": "^8.2.2",
"contentlayer": "^0.3.4",
"mdsx": "^0.0.3",
"mdsx": "^0.0.5",
"phosphor-svelte": "^1.4.2",
"postcss": "^8.4.35",
"postcss-load-config": "^5.0.3",
Expand All @@ -67,8 +67,8 @@
"@melt-ui/svelte": "^0.74.0",
"bits-ui": "^0.18.1",
"mode-watcher": "^0.2.1",
"runed": "workspace:^",
"rehype-slug": "^6.0.0",
"runed": "workspace:^",
"svelte-sonner": "^0.3.17",
"vaul-svelte": "^0.2.3"
}
Expand Down
12 changes: 6 additions & 6 deletions sites/docs/src/lib/components/demos/use-active-element.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import { useActiveElement } from "runed";
const activeElement = useActiveElement();
const text = $derived(
`Currently active element: ${
activeElement.value !== null ? activeElement.value.localName : "No active element found"
}`
);
</script>

<div class="rounded-md bg-card p-8">
<p>{text}</p>
<p>
Currently active element:
<span class="font-bold">
{activeElement.value?.localName ?? "No active element found"}
</span>
</p>
</div>
3 changes: 2 additions & 1 deletion sites/docs/src/lib/components/demos/use-debounce.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

<div class="rounded-md bg-card p-8">
<button
class="relative z-20 inline-flex items-center justify-center rounded-md border bg-brand/50 px-3 py-1.5 text-sm font-medium transition-all hover:bg-brand/25 focus:outline-none"
class="relative z-20 inline-flex items-center justify-center rounded-md border bg-brand/50
px-3 py-1.5 text-sm font-medium transition-all hover:bg-brand/25 focus:outline-none active:bg-brand/15"
onclick={ding}>DING DING DING</button
>
<p>{logged || "Press the button!"}</p>
Expand Down
10 changes: 8 additions & 2 deletions sites/docs/src/lib/components/layout/navbar/navbar-logo.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<script lang="ts">
import RunedLight from "$lib/components/logos/runed-light.svelte";
import RunedDark from "$lib/components/logos/runed-dark.svelte";
</script>

<div class="flex items-center gap-1.5 lg:flex-1">
<a
href="/"
class="flex flex-shrink-0 items-end gap-1.5 text-xl font-bold text-gray-900 dark:text-white"
>
<p>Runed</p>
<span class="sr-only"> Current Page Here </span>
<RunedLight class="block h-7 w-auto dark:hidden" />
<RunedDark class="hidden h-7 w-auto dark:block" />
<span class="sr-only"> Home </span>
</a>
</div>
Loading

0 comments on commit 4d07578

Please sign in to comment.