From b0a7dfba57fe88385a88ff6e84046d5b6a27a492 Mon Sep 17 00:00:00 2001 From: Hunter Johnston <64506580+huntabyte@users.noreply.github.com> Date: Mon, 4 Dec 2023 11:34:30 -0500 Subject: [PATCH] fix: Builder type (#201) --- .changeset/lovely-phones-retire.md | 5 +++++ .../bits/calendar/components/calendar-date.svelte | 1 + src/lib/helpers/builders.ts | 15 +++++++++------ 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 .changeset/lovely-phones-retire.md diff --git a/.changeset/lovely-phones-retire.md b/.changeset/lovely-phones-retire.md new file mode 100644 index 000000000..d69cac6b1 --- /dev/null +++ b/.changeset/lovely-phones-retire.md @@ -0,0 +1,5 @@ +--- +"bits-ui": patch +--- + +fix: Update `Builder` type to support all Melt UI builders diff --git a/src/lib/bits/calendar/components/calendar-date.svelte b/src/lib/bits/calendar/components/calendar-date.svelte index 48d3b22ed..a03578171 100644 --- a/src/lib/bits/calendar/components/calendar-date.svelte +++ b/src/lib/bits/calendar/components/calendar-date.svelte @@ -18,6 +18,7 @@ const attrs = getAttrs("date"); $: builder = $cell(date, month); + $: Object.assign(builder, attrs); const dispatch = createDispatcher(); diff --git a/src/lib/helpers/builders.ts b/src/lib/helpers/builders.ts index 060ad96f2..3e69dee78 100644 --- a/src/lib/helpers/builders.ts +++ b/src/lib/helpers/builders.ts @@ -1,13 +1,16 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import type { Action, ActionReturn } from "svelte/action"; -export type Builder = { - [x: PropertyKey]: unknown; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - action: Action; +export type Builder< + Element = any, + Param = any, + Attributes extends Record = Record +> = Record & { + action: Action; }; type BuilderActionsParams = { - builders: Builder[]; + builders: Builder[]; }; type BuilderActionsReturn = { @@ -36,7 +39,7 @@ export function builderActions( }; } -export function getAttrs(builders: Builder[]) { +export function getAttrs(builders: Builder[]) { const attrs: Record = {}; builders.forEach((builder) => { Object.keys(builder).forEach((key) => {