bits-ui 2.8.3 → 2.8.5
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.
|
@@ -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
|
|
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}="${
|
|
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();
|
|
@@ -340,6 +340,8 @@ export class CommandRootState {
|
|
|
340
340
|
return;
|
|
341
341
|
if (this.isGrid) {
|
|
342
342
|
const isFirstRowOfGroup = this.#itemIsFirstRowOfGroup(item);
|
|
343
|
+
// ensure item is visible
|
|
344
|
+
item.scrollIntoView({ block: "nearest" });
|
|
343
345
|
if (isFirstRowOfGroup) {
|
|
344
346
|
const closestGroupHeader = item
|
|
345
347
|
?.closest(COMMAND_GROUP_SELECTOR)
|
|
@@ -1056,7 +1058,7 @@ export class CommandInputState {
|
|
|
1056
1058
|
root;
|
|
1057
1059
|
attachment;
|
|
1058
1060
|
#selectedItemId = $derived.by(() => {
|
|
1059
|
-
const item = this.root.viewportNode?.querySelector(`${COMMAND_ITEM_SELECTOR}[${COMMAND_VALUE_ATTR}="${
|
|
1061
|
+
const item = this.root.viewportNode?.querySelector(`${COMMAND_ITEM_SELECTOR}[${COMMAND_VALUE_ATTR}="${cssEscape(this.root.opts.value.current)}"]`);
|
|
1060
1062
|
if (item === undefined || item === null)
|
|
1061
1063
|
return;
|
|
1062
1064
|
return item.getAttribute("id") ?? undefined;
|
|
@@ -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.
|
|
3
|
+
"version": "2.8.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": "github:huntabyte/bits-ui",
|
|
6
6
|
"funding": "https://github.com/sponsors/huntabyte",
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
"@sveltejs/kit": "^2.21.5",
|
|
24
24
|
"@sveltejs/package": "^2.3.11",
|
|
25
25
|
"@sveltejs/vite-plugin-svelte": "^5.1.0",
|
|
26
|
-
"@types/css.escape": "^1.5.2",
|
|
27
26
|
"@types/node": "^20.17.6",
|
|
28
27
|
"@types/resize-observer-browser": "^0.1.11",
|
|
29
28
|
"csstype": "^3.1.3",
|
|
@@ -41,7 +40,6 @@
|
|
|
41
40
|
"dependencies": {
|
|
42
41
|
"@floating-ui/core": "^1.7.1",
|
|
43
42
|
"@floating-ui/dom": "^1.7.1",
|
|
44
|
-
"css.escape": "^1.5.1",
|
|
45
43
|
"esm-env": "^1.1.2",
|
|
46
44
|
"runed": "^0.28.0",
|
|
47
45
|
"svelte-toolbelt": "^0.9.2",
|