Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next: downgrade svelte #575

Merged
merged 1 commit into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"prettier": "^3.2.5",
"prettier-plugin-svelte": "^3.2.2",
"prettier-plugin-tailwindcss": "0.5.13",
"svelte": "5.0.0-next.155",
"svelte": "5.0.0-next.143",
"svelte-eslint-parser": "^0.34.1",
"wrangler": "^3.44.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/bits-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"jsdom": "^24.0.0",
"publint": "^0.2.7",
"resize-observer-polyfill": "^1.5.1",
"svelte": "5.0.0-next.155",
"svelte": "5.0.0-next.143",
"svelte-check": "^3.6.9",
"tslib": "^2.6.2",
"typescript": "^5.3.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
import PopperLayer from "$lib/bits/utilities/popper-layer/popper-layer.svelte";
import { isElement } from "$lib/internal/is.js";
import type { InteractOutsideEvent } from "$lib/bits/utilities/dismissable-layer/types.js";
import Mounted from "$lib/bits/utilities/mounted.svelte";

let {
id = useId(),
asChild,
child,
children,
ref = $bindable(),
ref = $bindable(null),
loop = true,
onInteractOutside = noop,
// we need to explicitly pass this prop to the PopperLayer to override
Expand All @@ -25,18 +26,25 @@
...restProps
}: ContentProps = $props();

let isMounted = $state(false);

const contentState = useMenuContent({
id: box.with(() => id),
loop: box.with(() => loop),
ref: box.with(
() => ref,
(v) => (ref = v)
),
isMounted: box.with(() => isMounted),
});

function handleInteractOutsideStart(e: InteractOutsideEvent) {
if (!isElement(e.target)) return;
if (e.target.id === contentState.parentMenu.triggerId.value) {
if (e.target.id === contentState.parentMenu.triggerNode?.id) {
e.preventDefault();
return;
}
if (e.target.closest(`#${contentState.parentMenu.triggerId.value}`)) {
if (e.target.closest(`#${contentState.parentMenu.triggerNode?.id}`)) {
e.preventDefault();
}
}
Expand Down Expand Up @@ -88,5 +96,6 @@
{@render children?.()}
</div>
{/if}
<Mounted bind:isMounted />
{/snippet}
</PopperLayer>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

let {
id = useId(),
ref = $bindable(),
ref = $bindable(null),
asChild,
child,
children,
Expand All @@ -19,6 +19,10 @@
const triggerState = useMenuContextTrigger({
id: box.with(() => id),
disabled: box.with(() => disabled),
ref: box.with(
() => ref,
(v) => (ref = v)
),
});

const mergedProps = $derived(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,31 @@
import { noop } from "$lib/internal/callbacks.js";
import PopperLayer from "$lib/bits/utilities/popper-layer/popper-layer.svelte";
import { isElementOrSVGElement } from "$lib/internal/is.js";
import Mounted from "$lib/bits/utilities/mounted.svelte";

let {
id = useId(),
asChild,
child,
children,
ref = $bindable(),
ref = $bindable(null),
loop = true,
onInteractOutside = noop,
onEscapeKeydown = noop,
forceMount = false,
...restProps
}: ContentProps = $props();

let isMounted = $state(false);

const contentState = useMenuContent({
id: box.with(() => id),
loop: box.with(() => loop),
ref: box.with(
() => ref,
(v) => (ref = v)
),
isMounted: box.with(() => isMounted),
});

const mergedProps = $derived(
Expand All @@ -48,21 +56,21 @@
present={contentState.parentMenu.open.value || forceMount}
onInteractOutsideStart={(e) => {
if (!isElementOrSVGElement(e.target)) return;
if (e.target.id === contentState.parentMenu.triggerId.value) {
if (e.target.id === contentState.parentMenu.triggerNode?.id) {
e.preventDefault();
return;
}
if (e.target.closest(`#${contentState.parentMenu.triggerId.value}`)) {
if (e.target.closest(`#${contentState.parentMenu.triggerNode?.id}`)) {
e.preventDefault();
}
}}
onInteractOutside={(e) => {
if (!isElementOrSVGElement(e.target)) return;
if (e.target.id === contentState.parentMenu.triggerId.value) {
if (e.target.id === contentState.parentMenu.triggerNode?.id) {
e.preventDefault();
return;
}
if (e.target.closest(`#${contentState.parentMenu.triggerId.value}`)) {
if (e.target.closest(`#${contentState.parentMenu.triggerNode?.id}`)) {
e.preventDefault();
return;
}
Expand All @@ -87,5 +95,6 @@
{@render children?.()}
</div>
{/if}
<Mounted bind:isMounted />
{/snippet}
</PopperLayer>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
asChild,
child,
children,
ref = $bindable(),
ref = $bindable(null),
checked = $bindable(false),
id = useId(),
onCheckedChange = noop,
Expand All @@ -32,6 +32,10 @@
id: box.with(() => id),
disabled: box.with(() => disabled),
onSelect: box.with(() => handleSelect),
ref: box.with(
() => ref,
(v) => (ref = v)
),
});

function handleSelect(e: Event) {
Expand Down
15 changes: 12 additions & 3 deletions packages/bits-ui/src/lib/bits/menu/components/menu-content.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,40 @@
import PopperLayer from "$lib/bits/utilities/popper-layer/popper-layer.svelte";
import { isElement } from "$lib/internal/is.js";
import type { InteractOutsideEvent } from "$lib/bits/utilities/dismissable-layer/types.js";
import Mounted from "$lib/bits/utilities/mounted.svelte";

let {
id = useId(),
asChild,
child,
children,
ref = $bindable(),
ref = $bindable(null),
loop = true,
onInteractOutside = noop,
onEscapeKeydown = noop,
forceMount = false,
...restProps
}: ContentProps = $props();

let isMounted = $state(false);

const contentState = useMenuContent({
id: box.with(() => id),
loop: box.with(() => loop),
ref: box.with(
() => ref,
(v) => (ref = v)
),
isMounted: box.with(() => isMounted),
});

function handleInteractOutsideStart(e: InteractOutsideEvent) {
if (!isElement(e.target)) return;
if (e.target.id === contentState.parentMenu.triggerId.value) {
if (e.target.id === contentState.parentMenu.triggerNode?.id) {
e.preventDefault();
return;
}
if (e.target.closest(`#${contentState.parentMenu.triggerId.value}`)) {
if (e.target.closest(`#${contentState.parentMenu.triggerNode?.id}`)) {
e.preventDefault();
}
}
Expand Down Expand Up @@ -71,5 +79,6 @@
{@render children?.()}
</div>
{/if}
<Mounted bind:isMounted />
{/snippet}
</PopperLayer>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
asChild,
child,
children,
ref = $bindable(),
ref = $bindable(null),
id = useId(),
disabled = false,
onSelect = noop,
Expand All @@ -21,6 +21,10 @@
id: box.with(() => id),
disabled: box.with(() => disabled),
onSelect: box.with(() => onSelect),
ref: box.with(
() => ref,
(v) => (ref = v)
),
});

const mergedProps = $derived(mergeProps(restProps, itemState.props));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import { useMenuRadioGroup } from "../menu.svelte.js";
import { noop } from "$lib/internal/callbacks.js";
import { mergeProps } from "$lib/internal/mergeProps.js";
import { useId } from "$lib/internal/useId.svelte.js";

let {
id = useId(),
asChild,
children,
child,
ref = $bindable(),
ref = $bindable(null),
value = $bindable(""),
onValueChange = noop,
...restProps
Expand All @@ -25,6 +27,11 @@
}
}
),
ref: box.with(
() => ref,
(v) => (ref = v)
),
id: box.with(() => id),
});

const mergedProps = $derived(mergeProps(restProps, radioGroupState.props));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
asChild,
children,
child,
ref = $bindable(),
ref = $bindable(null),
value,
onSelect = noop,
id = useId(),
Expand All @@ -23,6 +23,10 @@
id: box.with(() => id),
disabled: box.with(() => disabled),
onSelect: box.with(() => handleSelect),
ref: box.with(
() => ref,
(v) => (ref = v)
),
});

function handleSelect(e: Event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import { noop } from "$lib/internal/callbacks.js";
import { isHTMLElement } from "$lib/internal/is.js";
import { afterTick } from "$lib/internal/afterTick.js";
import Mounted from "$lib/bits/utilities/mounted.svelte";

let {
id = useId(),
ref = $bindable(),
ref = $bindable(null),
asChild,
children,
child,
Expand All @@ -26,9 +27,16 @@
...restProps
}: SubContentProps = $props();

let isMounted = $state(false);

const subContentState = useMenuContent({
id: box.with(() => id),
loop: box.with(() => loop),
ref: box.with(
() => ref,
(v) => (ref = v)
),
isMounted: box.with(() => isMounted),
});

function onkeydown(e: KeyboardEvent) {
Expand All @@ -38,9 +46,7 @@
);
if (isKeyDownInside && isCloseKey) {
subContentState.parentMenu.onClose();
const triggerNode = document.getElementById(
subContentState.parentMenu.triggerId.value ?? ""
);
const triggerNode = subContentState.parentMenu.triggerNode;
triggerNode?.focus();
e.preventDefault();
}
Expand Down Expand Up @@ -92,7 +98,7 @@
// on pointer interaction.
if (!isHTMLElement(e.target)) return;

if (e.target.id !== subContentState.parentMenu.triggerId.value) {
if (e.target.id !== subContentState.parentMenu.triggerNode?.id) {
subContentState.parentMenu.onClose();
}
}}
Expand All @@ -108,5 +114,6 @@
{@render children?.()}
</div>
{/if}
<Mounted bind:isMounted />
{/snippet}
</PopperLayer>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
let {
id = useId(),
disabled = false,
ref = $bindable(),
ref = $bindable(null),
asChild,
children,
child,
Expand All @@ -18,6 +18,10 @@
const subTriggerState = useMenuSubTrigger({
disabled: box.with(() => disabled),
id: box.with(() => id),
ref: box.with(
() => ref,
(v) => (ref = v)
),
});

const mergedProps = $derived(mergeProps(restProps, subTriggerState.props));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

let {
id = useId(),
ref = $bindable(),
ref = $bindable(null),
asChild,
child,
children,
Expand All @@ -19,6 +19,10 @@
const triggerState = useMenuDropdownTrigger({
id: box.with(() => id),
disabled: box.with(() => disabled),
ref: box.with(
() => ref,
(v) => (ref = v)
),
});

const mergedProps = $derived(mergeProps(restProps, triggerState.props));
Expand Down
Loading
Loading