Skip to content

Commit

Permalink
next: update Svelte and other deps (#664)
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte authored Sep 20, 2024
1 parent a37ff8c commit 4daae5f
Show file tree
Hide file tree
Showing 99 changed files with 2,303 additions and 1,225 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
"@huntabyte/eslint-plugin": "^0.1.0",
"@svitejs/changesets-changelog-github-compact": "^1.1.0",
"eslint": "^9.0.0",
"eslint-plugin-svelte": "^2.37.0",
"eslint-plugin-svelte": "^2.44.0",
"prettier": "^3.2.5",
"prettier-plugin-svelte": "^3.2.2",
"prettier-plugin-tailwindcss": "0.5.13",
"svelte": "5.0.0-next.208",
"svelte-eslint-parser": "^0.41.0",
"svelte": "5.0.0-next.251",
"svelte-eslint-parser": "^0.41.1",
"wrangler": "^3.44.0"
},
"type": "module",
Expand Down
20 changes: 10 additions & 10 deletions packages/bits-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
],
"devDependencies": {
"@sveltejs/kit": "^2.5.18",
"@sveltejs/package": "^2.3.2",
"@sveltejs/vite-plugin-svelte": "^3.1.1",
"@sveltejs/package": "^2.3.5",
"@sveltejs/vite-plugin-svelte": "4.0.0-next.7",
"@testing-library/dom": "^10.3.1",
"@testing-library/jest-dom": "^6.4.6",
"@testing-library/svelte": "^5.2.1",
Expand All @@ -42,13 +42,13 @@
"csstype": "^3.1.3",
"jest-axe": "^9.0.0",
"jsdom": "^24.1.0",
"publint": "^0.2.8",
"publint": "^0.2.11",
"resize-observer-polyfill": "^1.5.1",
"svelte": "5.0.0-next.208",
"svelte-check": "^3.8.4",
"tslib": "^2.6.3",
"typescript": "^5.5.3",
"vite": "^5.3.3",
"svelte": "5.0.0-next.251",
"svelte-check": "3.8.6",
"tslib": "^2.7.0",
"typescript": "^5.6.2",
"vite": "^5.4.6",
"vitest": "^2.0.2"
},
"svelte": "./dist/index.js",
Expand All @@ -60,11 +60,11 @@
"@internationalized/date": "^3.5.4",
"clsx": "^2.1.1",
"esm-env": "^1.0.0",
"runed": "^0.15.0",
"runed": "^0.15.2",
"scule": "^1.3.0",
"style-object-to-css-string": "^1.1.3",
"style-to-object": "^1.0.6",
"svelte-toolbelt": "^0.1.0"
"svelte-toolbelt": "^0.3.1"
},
"peerDependencies": {
"svelte": "^5.0.0-next.1"
Expand Down
21 changes: 12 additions & 9 deletions packages/bits-ui/src/lib/bits/calendar/calendar.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,19 @@ export class CalendarRootState {
/**
* Synchronize the placeholder value with the current value.
*/
watch(this.value, () => {
const value = this.value.current;
if (Array.isArray(value) && value.length) {
const lastValue = value[value.length - 1];
if (lastValue && this.placeholder.current !== lastValue) {
this.placeholder.current = lastValue;
$effect(() => {
this.value.current;
untrack(() => {
const value = this.value.current;
if (Array.isArray(value) && value.length) {
const lastValue = value[value.length - 1];
if (lastValue && this.placeholder.current !== lastValue) {
this.placeholder.current = lastValue;
}
} else if (!Array.isArray(value) && value && this.placeholder.current !== value) {
this.placeholder.current = value;
}
} else if (!Array.isArray(value) && value && this.placeholder.current !== value) {
this.placeholder.current = value;
}
});
});
}

Expand Down
2 changes: 2 additions & 0 deletions packages/bits-ui/src/lib/bits/combobox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export { default as Portal } from "$lib/bits/utilities/portal/portal.svelte";

export {
Content,
ContentStatic,
Item,
Group,
GroupLabel,
Expand All @@ -18,6 +19,7 @@ export {
export type {
ComboboxRootProps as RootProps,
ComboboxContentProps as ContentProps,
ComboboxContentStaticProps as ContentStaticProps,
ComboboxInputProps as InputProps,
ComboboxItemProps as ItemProps,
ComboboxGroupProps as GroupProps,
Expand Down
2 changes: 2 additions & 0 deletions packages/bits-ui/src/lib/bits/combobox/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export type {
ListboxBaseRootPropsWithoutHTML as ComboboxBaseRootPropsWithoutHTML,
ListboxContentProps as ComboboxContentProps,
ListboxContentPropsWithoutHTML as ComboboxContentPropsWithoutHTML,
ListboxContentStaticProps as ComboboxContentStaticProps,
ListboxContentStaticPropsWithoutHTML as ComboboxContentStaticPropsWithoutHTML,
ListboxItemProps as ComboboxItemProps,
ListboxItemPropsWithoutHTML as ComboboxItemPropsWithoutHTML,
ListboxItemSnippetProps as ComboboxItemSnippetProps,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<script lang="ts">
import { box } from "svelte-toolbelt";
import type { ContentStaticProps } from "../index.js";
import { CONTEXT_MENU_TRIGGER_ATTR, useMenuContent } from "$lib/bits/menu/menu.svelte.js";
import { useId } from "$lib/internal/useId.js";
import { mergeProps } from "$lib/internal/mergeProps.js";
import { noop } from "$lib/internal/callbacks.js";
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(),
child,
children,
ref = $bindable(null),
loop = true,
onInteractOutside = noop,
// we need to explicitly pass this prop to the PopperLayer to override
// the default menu behavior of handling outside interactions on the trigger
onInteractOutsideStart = noop,
onEscapeKeydown = noop,
forceMount = false,
...restProps
}: ContentStaticProps = $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.triggerNode?.id) {
e.preventDefault();
return;
}
if (e.target.closest(`#${contentState.parentMenu.triggerNode?.id}`)) {
e.preventDefault();
}
}
const mergedProps = $derived(
mergeProps(restProps, contentState.props, {
onInteractOutsideStart: handleInteractOutsideStart,
})
);
</script>

<PopperLayer
{...mergedProps}
side="right"
sideOffset={2}
align="start"
present={contentState.parentMenu.open.current || forceMount}
{onInteractOutsideStart}
onInteractOutside={(e) => {
onInteractOutside(e);
if (e.defaultPrevented) return;
contentState.parentMenu.onClose();
}}
onEscapeKeydown={(e) => {
onEscapeKeydown(e);
if (e.defaultPrevented) return;
contentState.parentMenu.onClose();
}}
isValidEvent={(e) => {
if ("button" in e && e.button === 2) {
const target = e.target as HTMLElement;
if (!target) return false;
const isAnotherContextTrigger =
target.closest(`[${CONTEXT_MENU_TRIGGER_ATTR}]`) !==
contentState.parentMenu.triggerNode;
return isAnotherContextTrigger;
}
return false;
}}
trapFocus
{loop}
>
{#snippet popper({ props })}
{#if child}
{@render child({ props })}
{:else}
<div {...props}>
{@render children?.()}
</div>
{/if}
<Mounted bind:isMounted />
{/snippet}
</PopperLayer>
2 changes: 2 additions & 0 deletions packages/bits-ui/src/lib/bits/context-menu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export { default as Group } from "$lib/bits/menu/components/menu-group.svelte";
export { default as GroupLabel } from "$lib/bits/menu/components/menu-group-label.svelte";
export { default as Arrow } from "$lib/bits/menu/components/menu-arrow.svelte";
export { default as Content } from "./components/context-menu-content.svelte";
export { default as ContentStatic } from "./components/context-menu-content-static.svelte";
export { default as Trigger } from "./components/context-menu-trigger.svelte";
export { default as RadioItem } from "$lib/bits/menu/components/menu-radio-item.svelte";
export { default as Separator } from "$lib/bits/menu/components/menu-separator.svelte";
Expand All @@ -28,6 +29,7 @@ export type {
ContextMenuSubProps as SubProps,
ContextMenuSubTriggerProps as SubTriggerProps,
ContextMenuContentProps as ContentProps,
ContextMenuContentStaticProps as ContentStaticProps,
ContextMenuTriggerProps as TriggerProps,
ContextMenuPortalProps as PortalProps,
} from "./types.js";
2 changes: 2 additions & 0 deletions packages/bits-ui/src/lib/bits/context-menu/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type ContextMenuTriggerProps = ContextMenuTriggerPropsWithoutHTML &

export type {
ArrowProps as ContextMenuArrowProps,
ContentStaticProps as ContextMenuContentStaticProps,
CheckboxItemProps as ContextMenuCheckboxItemProps,
GroupProps as ContextMenuGroupProps,
ItemProps as ContextMenuItemProps,
Expand All @@ -41,6 +42,7 @@ export type {

export type {
MenuRootPropsWithoutHTML as ContextMenuRootPropsWithoutHTML,
MenuContentStaticPropsWithoutHTML as ContextMenuContentStaticPropsWithoutHTML,
MenuArrowPropsWithoutHTML as ContextMenuArrowPropsWithoutHTML,
MenuCheckboxItemPropsWithoutHTML as ContextMenuCheckboxItemPropsWithoutHTML,
MenuGroupPropsWithoutHTML as ContextMenuGroupPropsWithoutHTML,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script lang="ts">
import type { ContentStaticProps } from "../index.js";
import PopoverContentStatic from "$lib/bits/popover/components/popover-content-static.svelte";
import { pickerOpenFocus } from "$lib/shared/date/index.js";
import { mergeProps } from "$lib/internal/mergeProps.js";
let { ref = $bindable(null), onMountAutoFocus, ...restProps }: ContentStaticProps = $props();
const mergedProps = $derived(
mergeProps({ onMountAutoFocus }, { onMountAutoFocus: pickerOpenFocus })
) as any;
</script>

<PopoverContentStatic {...mergedProps} bind:ref {...restProps} />
2 changes: 2 additions & 0 deletions packages/bits-ui/src/lib/bits/date-picker/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export { default as Root } from "./components/date-picker.svelte";
export { default as Calendar } from "./components/date-picker-calendar.svelte";
export { default as Content } from "./components/date-picker-content.svelte";
export { default as ContentStatic } from "./components/date-picker-content-static.svelte";
export { default as Trigger } from "./components/date-picker-trigger.svelte";
export { Arrow } from "$lib/bits/popover/index.js";
export { default as Close } from "$lib/bits/popover/components/popover-close.svelte";
Expand All @@ -27,6 +28,7 @@ export type {
DatePickerArrowProps as ArrowProps,
DatePickerCloseProps as CloseProps,
DatePickerContentProps as ContentProps,
DatePickerContentStaticProps as ContentStaticProps,
DatePickerTriggerProps as TriggerProps,
DatePickerCalendarProps as CalendarProps,
DatePickerCellProps as CellProps,
Expand Down
2 changes: 2 additions & 0 deletions packages/bits-ui/src/lib/bits/date-picker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ export type {
PopoverTriggerProps as DatePickerTriggerProps,
PopoverContentPropsWithoutHTML as DatePickerContentPropsWithoutHTML,
PopoverContentProps as DatePickerContentProps,
PopoverContentStaticPropsWithoutHTML as DatePickerContentStaticPropsWithoutHTML,
PopoverContentStaticProps as DatePickerContentStaticProps,
PopoverArrowPropsWithoutHTML as DatePickerArrowPropsWithoutHTML,
PopoverArrowProps as DatePickerArrowProps,
PopoverClosePropsWithoutHTML as DatePickerClosePropsWithoutHTML,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@
value: box.with(
() => value as DateRange,
(v) => {
if (!$state.is(value, v)) {
value = v;
onValueChange(v);
}
value = v;
onValueChange(v);
}
),
placeholder: box.with(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<script lang="ts">
import { box } from "svelte-toolbelt";
import type { ContentStaticProps } from "../index.js";
import { useMenuContent } from "$lib/bits/menu/menu.svelte.js";
import { useId } from "$lib/internal/useId.js";
import { mergeProps } from "$lib/internal/mergeProps.js";
import { noop } from "$lib/internal/callbacks.js";
import PopperLayer from "$lib/bits/utilities/popper-layer/popper-layer.svelte";
import Mounted from "$lib/bits/utilities/mounted.svelte";
let {
id = useId(),
child,
children,
ref = $bindable(null),
loop = true,
onInteractOutside = noop,
onEscapeKeydown = noop,
forceMount = false,
...restProps
}: ContentStaticProps = $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(mergeProps(restProps, contentState.props));
</script>

<PopperLayer
isStatic={true}
{...mergedProps}
present={contentState.parentMenu.open.current || forceMount}
onInteractOutsideStart={(e) => {
contentState.handleInteractOutside(e);
}}
onInteractOutside={(e) => {
contentState.handleInteractOutside(e);
if (e.defaultPrevented) return;
onInteractOutside(e);
contentState.parentMenu.onClose();
}}
onEscapeKeydown={(e) => {
onEscapeKeydown(e);
if (e.defaultPrevented) return;
contentState.parentMenu.onClose();
}}
trapFocus
{loop}
>
{#snippet popper({ props })}
{@const finalProps = mergeProps(props)}
{#if child}
{@render child({ props: finalProps })}
{:else}
<div {...finalProps}>
{@render children?.()}
</div>
{/if}
<Mounted bind:isMounted />
{/snippet}
</PopperLayer>
Loading

0 comments on commit 4daae5f

Please sign in to comment.