bits-ui 2.8.2 → 2.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -56,7 +56,11 @@ export class CheckboxGroupLabelState {
56
56
  constructor(opts, group) {
57
57
  this.opts = opts;
58
58
  this.group = group;
59
- this.attachment = attachRef(this.opts.ref, (v) => (this.group.labelId = v?.id));
59
+ this.group.labelId = this.opts.id.current;
60
+ this.attachment = attachRef(this.opts.ref);
61
+ watch.pre(() => this.opts.id.current, (id) => {
62
+ this.group.labelId = id;
63
+ });
60
64
  }
61
65
  props = $derived.by(() => ({
62
66
  id: this.opts.id.current,
@@ -12,6 +12,7 @@ export declare class CollapsibleRootState {
12
12
  readonly opts: CollapsibleRootStateOpts;
13
13
  readonly attachment: RefAttachment;
14
14
  contentNode: HTMLElement | null;
15
+ contentId: string | undefined;
15
16
  constructor(opts: CollapsibleRootStateOpts);
16
17
  toggleOpen(): void;
17
18
  readonly props: {
@@ -15,6 +15,7 @@ export class CollapsibleRootState {
15
15
  opts;
16
16
  attachment;
17
17
  contentNode = $state(null);
18
+ contentId = $state(undefined);
18
19
  constructor(opts) {
19
20
  this.opts = opts;
20
21
  this.toggleOpen = this.toggleOpen.bind(this);
@@ -54,7 +55,11 @@ export class CollapsibleContentState {
54
55
  this.opts = opts;
55
56
  this.root = root;
56
57
  this.#isMountAnimationPrevented = root.opts.open.current;
58
+ this.root.contentId = this.opts.id.current;
57
59
  this.attachment = attachRef(this.opts.ref, (v) => (this.root.contentNode = v));
60
+ watch.pre(() => this.opts.id.current, (id) => {
61
+ this.root.contentId = id;
62
+ });
58
63
  $effect.pre(() => {
59
64
  const rAF = requestAnimationFrame(() => {
60
65
  this.#isMountAnimationPrevented = false;
@@ -142,7 +147,7 @@ export class CollapsibleTriggerState {
142
147
  id: this.opts.id.current,
143
148
  type: "button",
144
149
  disabled: this.#isDisabled,
145
- "aria-controls": this.root.contentNode?.id,
150
+ "aria-controls": this.root.contentId,
146
151
  "aria-expanded": getAriaExpanded(this.root.opts.open.current),
147
152
  "data-state": getDataOpenClosed(this.root.opts.open.current),
148
153
  "data-disabled": getDataDisabled(this.#isDisabled),
@@ -5,7 +5,7 @@ import { kbd } from "../../internal/kbd.js";
5
5
  import { createBitsAttrs, getAriaDisabled, getAriaExpanded, getAriaSelected, getDataDisabled, getDataSelected, } from "../../internal/attrs.js";
6
6
  import { getFirstNonCommentChild } from "../../internal/dom.js";
7
7
  import { computeCommandScore } from "./index.js";
8
- import cssesc from "css.escape";
8
+ import { cssEscape } from "../../internal/css-escape.js";
9
9
  const COMMAND_VALUE_ATTR = "data-value";
10
10
  const commandAttrs = createBitsAttrs({
11
11
  component: "command",
@@ -182,7 +182,7 @@ export class CommandRootState {
182
182
  }
183
183
  const sortedGroups = groups.sort((a, b) => b[1] - a[1]);
184
184
  for (const group of sortedGroups) {
185
- const element = listInsertionElement?.querySelector(`${COMMAND_GROUP_SELECTOR}[${COMMAND_VALUE_ATTR}="${cssesc(group[0])}"]`);
185
+ const element = listInsertionElement?.querySelector(`${COMMAND_GROUP_SELECTOR}[${COMMAND_VALUE_ATTR}="${cssEscape(group[0])}"]`);
186
186
  element?.parentElement?.appendChild(element);
187
187
  }
188
188
  this.#selectFirstItem();
@@ -1056,7 +1056,7 @@ export class CommandInputState {
1056
1056
  root;
1057
1057
  attachment;
1058
1058
  #selectedItemId = $derived.by(() => {
1059
- const item = this.root.viewportNode?.querySelector(`${COMMAND_ITEM_SELECTOR}[${COMMAND_VALUE_ATTR}="${cssesc(this.root.opts.value.current)}"]`);
1059
+ const item = this.root.viewportNode?.querySelector(`${COMMAND_ITEM_SELECTOR}[${COMMAND_VALUE_ATTR}="${cssEscape(this.root.opts.value.current)}"]`);
1060
1060
  if (item === undefined || item === null)
1061
1061
  return;
1062
1062
  return item.getAttribute("id") ?? undefined;
@@ -1,5 +1,5 @@
1
1
  import { attachRef, box, } from "svelte-toolbelt";
2
- import { Context } from "runed";
2
+ import { Context, watch } from "runed";
3
3
  import { createBitsAttrs, getAriaExpanded, getDataOpenClosed } from "../../internal/attrs.js";
4
4
  import { kbd } from "../../internal/kbd.js";
5
5
  import { OpenChangeComplete } from "../../internal/open-change-complete.js";
@@ -165,7 +165,11 @@ export class DialogTitleState {
165
165
  constructor(opts, root) {
166
166
  this.opts = opts;
167
167
  this.root = root;
168
- this.attachment = attachRef(this.opts.ref, (v) => (this.root.titleId = v?.id));
168
+ this.root.titleId = this.opts.id.current;
169
+ this.attachment = attachRef(this.opts.ref);
170
+ watch.pre(() => this.opts.id.current, (id) => {
171
+ this.root.titleId = id;
172
+ });
169
173
  }
170
174
  props = $derived.by(() => ({
171
175
  id: this.opts.id.current,
@@ -186,9 +190,12 @@ export class DialogDescriptionState {
186
190
  constructor(opts, root) {
187
191
  this.opts = opts;
188
192
  this.root = root;
193
+ this.root.descriptionId = this.opts.id.current;
189
194
  this.attachment = attachRef(this.opts.ref, (v) => {
190
195
  this.root.descriptionNode = v;
191
- this.root.descriptionId = v?.id;
196
+ });
197
+ watch.pre(() => this.opts.id.current, (id) => {
198
+ this.root.descriptionId = id;
192
199
  });
193
200
  }
194
201
  props = $derived.by(() => ({
@@ -0,0 +1,7 @@
1
+ /**
2
+ * https://github.com/mathiasbynens/CSS.escape
3
+ *
4
+ * @param value - The value to escape for use as a CSS identifier
5
+ * @returns The escaped CSS identifier string
6
+ */
7
+ export declare function cssEscape(value: string): string;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * https://github.com/mathiasbynens/CSS.escape
3
+ *
4
+ * @param value - The value to escape for use as a CSS identifier
5
+ * @returns The escaped CSS identifier string
6
+ */
7
+ export function cssEscape(value) {
8
+ if (typeof CSS !== "undefined" && typeof CSS.escape === "function") {
9
+ return CSS.escape(value);
10
+ }
11
+ const length = value.length;
12
+ let index = -1;
13
+ let codeUnit;
14
+ let result = "";
15
+ const firstCodeUnit = value.charCodeAt(0);
16
+ // If the character is the first character and is a `-` (U+002D), and
17
+ // there is no second character, escape it
18
+ if (length === 1 && firstCodeUnit === 0x002d)
19
+ return "\\" + value;
20
+ while (++index < length) {
21
+ codeUnit = value.charCodeAt(index);
22
+ // If the character is NULL (U+0000), then the REPLACEMENT CHARACTER (U+FFFD)
23
+ if (codeUnit === 0x0000) {
24
+ result += "\uFFFD";
25
+ continue;
26
+ }
27
+ if (
28
+ // If the character is in the range [\1-\1F] (U+0001 to U+001F) or is U+007F
29
+ (codeUnit >= 0x0001 && codeUnit <= 0x001f) ||
30
+ codeUnit === 0x007f ||
31
+ // If the character is the first character and is in the range [0-9] (U+0030 to U+0039)
32
+ (index === 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039) ||
33
+ // If the character is the second character and is in the range [0-9] (U+0030 to U+0039)
34
+ // and the first character is a `-` (U+002D)
35
+ (index === 1 && codeUnit >= 0x0030 && codeUnit <= 0x0039 && firstCodeUnit === 0x002d)) {
36
+ // https://drafts.csswg.org/cssom/#escape-a-character-as-code-point
37
+ result += "\\" + codeUnit.toString(16) + " ";
38
+ continue;
39
+ }
40
+ // If the character is not handled by one of the above rules and is
41
+ // greater than or equal to U+0080, is `-` (U+002D) or `_` (U+005F), or
42
+ // is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to U+005A),
43
+ // or [a-z] (U+0061 to U+007A)
44
+ if (codeUnit >= 0x0080 ||
45
+ codeUnit === 0x002d ||
46
+ codeUnit === 0x005f ||
47
+ (codeUnit >= 0x0030 && codeUnit <= 0x0039) ||
48
+ (codeUnit >= 0x0041 && codeUnit <= 0x005a) ||
49
+ (codeUnit >= 0x0061 && codeUnit <= 0x007a)) {
50
+ // Use the character itself
51
+ result += value.charAt(index);
52
+ continue;
53
+ }
54
+ // Otherwise, escape the character
55
+ // https://drafts.csswg.org/cssom/#escape-a-character
56
+ result += "\\" + value.charAt(index);
57
+ }
58
+ return result;
59
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bits-ui",
3
- "version": "2.8.2",
3
+ "version": "2.8.4",
4
4
  "license": "MIT",
5
5
  "repository": "github:huntabyte/bits-ui",
6
6
  "funding": "https://github.com/sponsors/huntabyte",
@@ -19,31 +19,27 @@
19
19
  "!dist/**/*.spec.*"
20
20
  ],
21
21
  "devDependencies": {
22
- "@internationalized/date": "^3.8.1",
23
- "@sveltejs/kit": "^2.21.1",
22
+ "@internationalized/date": "^3.8.2",
23
+ "@sveltejs/kit": "^2.21.5",
24
24
  "@sveltejs/package": "^2.3.11",
25
- "@sveltejs/vite-plugin-svelte": "5.0.3",
26
- "@types/css.escape": "^1.5.2",
25
+ "@sveltejs/vite-plugin-svelte": "^5.1.0",
27
26
  "@types/node": "^20.17.6",
28
27
  "@types/resize-observer-browser": "^0.1.11",
29
28
  "csstype": "^3.1.3",
30
- "jest-axe": "^9.0.0",
31
29
  "jsdom": "^24.1.3",
32
30
  "publint": "^0.2.12",
33
- "svelte": "^5.33.2",
34
- "svelte-check": "^4.2.1",
35
- "tslib": "^2.8.1",
31
+ "svelte": "5.33.2",
32
+ "svelte-check": "^4.2.2",
36
33
  "typescript": "^5.8.3",
37
34
  "vite": "^6.3.5",
38
- "vitest": "^3.1.4"
35
+ "vitest": "3.2.3"
39
36
  },
40
37
  "svelte": "./dist/index.js",
41
38
  "types": "./dist/index.d.ts",
42
39
  "type": "module",
43
40
  "dependencies": {
44
- "@floating-ui/core": "^1.7.0",
45
- "@floating-ui/dom": "^1.7.0",
46
- "css.escape": "^1.5.1",
41
+ "@floating-ui/core": "^1.7.1",
42
+ "@floating-ui/dom": "^1.7.1",
47
43
  "esm-env": "^1.1.2",
48
44
  "runed": "^0.28.0",
49
45
  "svelte-toolbelt": "^0.9.2",
@@ -54,7 +50,6 @@
54
50
  "svelte": "^5.33.0"
55
51
  },
56
52
  "engines": {
57
- "pnpm": ">=8.7.0",
58
53
  "node": ">=20"
59
54
  },
60
55
  "sideEffects": false,