From 98af8ac3707de844a494415ef1034b3b6929b3b9 Mon Sep 17 00:00:00 2001 From: Hunter Johnston <64506580+huntabyte@users.noreply.github.com> Date: Thu, 11 Apr 2024 12:10:40 -0400 Subject: [PATCH 1/3] fix: toolbar onValueChange firing (#448) --- .changeset/fifty-stingrays-flash.md | 5 +++++ .../bits/toolbar/components/toolbar-group.svelte | 11 ++++++++--- .../bits-ui/src/tests/toolbar/Toolbar.spec.ts | 3 --- pnpm-lock.yaml | 7 +++---- sites/docs/package.json | 1 + sites/docs/svelte.config.js | 16 ++++++++++------ 6 files changed, 27 insertions(+), 16 deletions(-) create mode 100644 .changeset/fifty-stingrays-flash.md diff --git a/.changeset/fifty-stingrays-flash.md b/.changeset/fifty-stingrays-flash.md new file mode 100644 index 000000000..7cfa936fc --- /dev/null +++ b/.changeset/fifty-stingrays-flash.md @@ -0,0 +1,5 @@ +--- +"bits-ui": patch +--- + +fix: toolbar onValueChange firing diff --git a/packages/bits-ui/src/lib/bits/toolbar/components/toolbar-group.svelte b/packages/bits-ui/src/lib/bits/toolbar/components/toolbar-group.svelte index 3f61f6d20..56755dbd1 100644 --- a/packages/bits-ui/src/lib/bits/toolbar/components/toolbar-group.svelte +++ b/packages/bits-ui/src/lib/bits/toolbar/components/toolbar-group.svelte @@ -2,6 +2,7 @@ import { melt } from "@melt-ui/svelte"; import { setGroupCtx } from "../ctx.js"; import type { GroupProps } from "../index.js"; + import { arraysAreEqual } from "$lib/internal/arrays.js"; type T = $$Generic<"single" | "multiple">; type $$Props = GroupProps; @@ -24,8 +25,11 @@ defaultValue: value, onValueChange: (({ next }: { next: $$Props["value"] }) => { if (Array.isArray(next)) { - onValueChange?.(next); - value = next; + if (!Array.isArray(value) || !arraysAreEqual(value, next)) { + onValueChange?.(next); + value = next; + return next; + } return next; } @@ -39,7 +43,8 @@ const attrs = getAttrs("group"); - $: value !== undefined && localValue.set(value); + $: value !== undefined && + localValue.set(Array.isArray(value) ? ([...value] as $$Props["value"]) : (value as any)); $: updateOption("disabled", disabled); $: updateOption("type", type); diff --git a/packages/bits-ui/src/tests/toolbar/Toolbar.spec.ts b/packages/bits-ui/src/tests/toolbar/Toolbar.spec.ts index 26f3aaa98..26403abfe 100644 --- a/packages/bits-ui/src/tests/toolbar/Toolbar.spec.ts +++ b/packages/bits-ui/src/tests/toolbar/Toolbar.spec.ts @@ -205,9 +205,6 @@ describe("toolbar", () => { singleProps: { onValueChange: singleOnValueChange }, }); - expect(newMultipleValue).toStrictEqual(["bold"]); - expect(newSingleValue).toBe(undefined); - await user.click(groupMultipleItemStrikethrough); expect(newMultipleValue).toStrictEqual(["bold", "strikethrough"]); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8305e378e..17f588af9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -130,6 +130,9 @@ importers: specifier: workspace:* version: link:../../packages/bits-ui devDependencies: + '@melt-ui/pp': + specifier: ^0.3.0 + version: 0.3.0(@melt-ui/svelte@0.76.2)(svelte@4.2.12) '@prettier/sync': specifier: 0.3.0 version: 0.3.0(prettier@3.2.5) @@ -752,10 +755,6 @@ packages: peerDependencies: '@effect-ts/otel-node': '*' peerDependenciesMeta: - '@effect-ts/core': - optional: true - '@effect-ts/otel': - optional: true '@effect-ts/otel-node': optional: true dependencies: diff --git a/sites/docs/package.json b/sites/docs/package.json index 219e4d7fb..d78a3ea71 100644 --- a/sites/docs/package.json +++ b/sites/docs/package.json @@ -15,6 +15,7 @@ "check": "pnpm build:content && svelte-kit sync && svelte-check --tsconfig ./tsconfig.json" }, "devDependencies": { + "@melt-ui/pp": "^0.3.0", "@prettier/sync": "0.3.0", "@sveltejs/adapter-cloudflare": "^4.2.0", "@sveltejs/kit": "^2.5.0", diff --git a/sites/docs/svelte.config.js b/sites/docs/svelte.config.js index 86657c83e..0bbca6cdd 100644 --- a/sites/docs/svelte.config.js +++ b/sites/docs/svelte.config.js @@ -3,6 +3,7 @@ import url from "node:url"; import adapter from "@sveltejs/adapter-cloudflare"; import { vitePreprocess } from "@sveltejs/vite-plugin-svelte"; import { mdsx } from "mdsx"; +import { preprocessMeltUI, sequence } from "@melt-ui/pp"; import { mdsxConfig } from "./mdsx.config.js"; const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); @@ -11,13 +12,16 @@ const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); const config = { preprocess: [ mdsx(mdsxConfig), - vitePreprocess({ - style: { - css: { - postcss: path.join(__dirname, "postcss.config.cjs"), + sequence([ + vitePreprocess({ + style: { + css: { + postcss: path.join(__dirname, "postcss.config.cjs"), + }, }, - }, - }), + }), + preprocessMeltUI(), + ]), ], extensions: [".svelte", ".md"], From 5b3706d29f35703a25d49615981254a52ec67528 Mon Sep 17 00:00:00 2001 From: Hunter Johnston <64506580+huntabyte@users.noreply.github.com> Date: Thu, 11 Apr 2024 12:21:10 -0400 Subject: [PATCH 2/3] chore: update sponsors img source (#450) --- README.md | 2 +- packages/bits-ui/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ed5a893e2..8eeea1bc1 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ This project is supported by the following beautiful people/organizations:

- Logos from Sponsors + Logos from Sponsors

diff --git a/packages/bits-ui/README.md b/packages/bits-ui/README.md index ed5a893e2..8eeea1bc1 100644 --- a/packages/bits-ui/README.md +++ b/packages/bits-ui/README.md @@ -25,7 +25,7 @@ This project is supported by the following beautiful people/organizations:

- Logos from Sponsors + Logos from Sponsors

From 912601d10a4cbd63cb538b7f962c3ebced94dc63 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 11 Apr 2024 12:28:25 -0400 Subject: [PATCH 3/3] Version Packages (#449) Co-authored-by: github-actions[bot] --- .changeset/fifty-stingrays-flash.md | 5 ----- packages/bits-ui/CHANGELOG.md | 6 ++++++ packages/bits-ui/package.json | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) delete mode 100644 .changeset/fifty-stingrays-flash.md diff --git a/.changeset/fifty-stingrays-flash.md b/.changeset/fifty-stingrays-flash.md deleted file mode 100644 index 7cfa936fc..000000000 --- a/.changeset/fifty-stingrays-flash.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"bits-ui": patch ---- - -fix: toolbar onValueChange firing diff --git a/packages/bits-ui/CHANGELOG.md b/packages/bits-ui/CHANGELOG.md index 9d7fdf917..b2d3ba14c 100644 --- a/packages/bits-ui/CHANGELOG.md +++ b/packages/bits-ui/CHANGELOG.md @@ -1,5 +1,11 @@ # bits-ui +## 0.21.3 + +### Patch Changes + +- fix: toolbar onValueChange firing ([#448](https://github.com/huntabyte/bits-ui/pull/448)) + ## 0.21.2 ### Patch Changes diff --git a/packages/bits-ui/package.json b/packages/bits-ui/package.json index 3b7d5cae7..50aa18ebe 100644 --- a/packages/bits-ui/package.json +++ b/packages/bits-ui/package.json @@ -1,6 +1,6 @@ { "name": "bits-ui", - "version": "0.21.2", + "version": "0.21.3", "license": "MIT", "repository": "github:huntabyte/bits-ui", "funding": "https://github.com/sponsors/huntabyte",