bits-ui 2.9.6 → 2.9.7
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.
- package/dist/bits/checkbox/checkbox.svelte.d.ts +3 -1
- package/dist/bits/checkbox/checkbox.svelte.js +8 -0
- package/dist/bits/command/command.svelte.js +9 -5
- package/dist/bits/radio-group/radio-group.svelte.d.ts +3 -1
- package/dist/bits/radio-group/radio-group.svelte.js +8 -3
- package/dist/internal/roving-focus-group.d.ts +1 -0
- package/dist/internal/roving-focus-group.js +10 -0
- package/dist/internal/warn.d.ts +1 -0
- package/dist/internal/warn.js +14 -0
- package/dist/shared/date/types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ReadableBoxedValues, type WritableBoxedValues } from "svelte-toolbelt";
|
|
2
2
|
import type { HTMLButtonAttributes } from "svelte/elements";
|
|
3
3
|
import { Context } from "runed";
|
|
4
|
-
import type { BitsKeyboardEvent, BitsMouseEvent, OnChangeFn, RefAttachment, WithRefOpts } from "../../internal/types.js";
|
|
4
|
+
import type { BitsFocusEvent, BitsKeyboardEvent, BitsMouseEvent, OnChangeFn, RefAttachment, WithRefOpts } from "../../internal/types.js";
|
|
5
5
|
interface CheckboxGroupStateOpts extends WithRefOpts, ReadableBoxedValues<{
|
|
6
6
|
name: string | undefined;
|
|
7
7
|
disabled: boolean;
|
|
@@ -91,6 +91,7 @@ export declare class CheckboxInputState {
|
|
|
91
91
|
readonly trueChecked: boolean;
|
|
92
92
|
readonly shouldRender: boolean;
|
|
93
93
|
constructor(root: CheckboxRootState);
|
|
94
|
+
onfocus(_: BitsFocusEvent): void;
|
|
94
95
|
readonly props: {
|
|
95
96
|
readonly type: "checkbox";
|
|
96
97
|
readonly checked: boolean;
|
|
@@ -99,6 +100,7 @@ export declare class CheckboxInputState {
|
|
|
99
100
|
readonly name: string | undefined;
|
|
100
101
|
readonly value: string | undefined;
|
|
101
102
|
readonly readonly: boolean;
|
|
103
|
+
readonly onfocus: (_: BitsFocusEvent) => void;
|
|
102
104
|
};
|
|
103
105
|
}
|
|
104
106
|
export {};
|
|
@@ -3,6 +3,7 @@ import { Context, watch } from "runed";
|
|
|
3
3
|
import { createBitsAttrs, getAriaChecked, getAriaReadonly, getAriaRequired, getDataDisabled, getDataReadonly, } from "../../internal/attrs.js";
|
|
4
4
|
import { kbd } from "../../internal/kbd.js";
|
|
5
5
|
import { arraysAreEqual } from "../../internal/arrays.js";
|
|
6
|
+
import { isHTMLElement } from "../../internal/is.js";
|
|
6
7
|
const checkboxAttrs = createBitsAttrs({
|
|
7
8
|
component: "checkbox",
|
|
8
9
|
parts: ["root", "group", "group-label", "input"],
|
|
@@ -192,6 +193,12 @@ export class CheckboxInputState {
|
|
|
192
193
|
shouldRender = $derived.by(() => Boolean(this.root.trueName));
|
|
193
194
|
constructor(root) {
|
|
194
195
|
this.root = root;
|
|
196
|
+
this.onfocus = this.onfocus.bind(this);
|
|
197
|
+
}
|
|
198
|
+
onfocus(_) {
|
|
199
|
+
if (!isHTMLElement(this.root.opts.ref.current))
|
|
200
|
+
return;
|
|
201
|
+
this.root.opts.ref.current.focus();
|
|
195
202
|
}
|
|
196
203
|
props = $derived.by(() => ({
|
|
197
204
|
type: "checkbox",
|
|
@@ -201,6 +208,7 @@ export class CheckboxInputState {
|
|
|
201
208
|
name: this.root.trueName,
|
|
202
209
|
value: this.root.opts.value.current,
|
|
203
210
|
readonly: this.root.trueReadonly,
|
|
211
|
+
onfocus: this.onfocus,
|
|
204
212
|
}));
|
|
205
213
|
}
|
|
206
214
|
function getCheckboxDataState(checked, indeterminate) {
|
|
@@ -528,7 +528,6 @@ export class CommandRootState {
|
|
|
528
528
|
this.#scheduleUpdate();
|
|
529
529
|
return () => {
|
|
530
530
|
const selectedItem = this.#getSelectedItem();
|
|
531
|
-
this.allIds.delete(id);
|
|
532
531
|
this.allItems.delete(id);
|
|
533
532
|
this.commandState.filtered.items.delete(id);
|
|
534
533
|
this.#filterItems();
|
|
@@ -1132,16 +1131,21 @@ export class CommandItemState {
|
|
|
1132
1131
|
() => this.#group?.trueValue,
|
|
1133
1132
|
() => this.opts.forceMount.current,
|
|
1134
1133
|
], () => {
|
|
1135
|
-
if (this.opts.forceMount.current)
|
|
1134
|
+
if (this.opts.forceMount.current || !this.trueValue)
|
|
1136
1135
|
return;
|
|
1137
1136
|
return this.root.registerItem(this.trueValue, this.#group?.trueValue);
|
|
1138
1137
|
});
|
|
1139
1138
|
watch([() => this.opts.value.current, () => this.opts.ref.current], () => {
|
|
1140
|
-
if (
|
|
1139
|
+
if (this.opts.value.current) {
|
|
1140
|
+
this.trueValue = this.opts.value.current;
|
|
1141
|
+
}
|
|
1142
|
+
else if (this.opts.ref.current?.textContent) {
|
|
1141
1143
|
this.trueValue = this.opts.ref.current.textContent.trim();
|
|
1142
1144
|
}
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
+
if (this.trueValue) {
|
|
1146
|
+
this.root.registerValue(this.trueValue, opts.keywords.current.map((kw) => kw.trim()));
|
|
1147
|
+
this.opts.ref.current?.setAttribute(COMMAND_VALUE_ATTR, this.trueValue);
|
|
1148
|
+
}
|
|
1145
1149
|
});
|
|
1146
1150
|
// bindings
|
|
1147
1151
|
this.onclick = this.onclick.bind(this);
|
|
@@ -73,12 +73,14 @@ export declare class RadioGroupInputState {
|
|
|
73
73
|
static create(): RadioGroupInputState;
|
|
74
74
|
readonly root: RadioGroupRootState;
|
|
75
75
|
readonly shouldRender: boolean;
|
|
76
|
+
constructor(root: RadioGroupRootState);
|
|
77
|
+
onfocus(_: BitsFocusEvent): void;
|
|
76
78
|
readonly props: {
|
|
77
79
|
readonly name: string | undefined;
|
|
78
80
|
readonly value: string;
|
|
79
81
|
readonly required: boolean;
|
|
80
82
|
readonly disabled: boolean;
|
|
83
|
+
readonly onfocus: (_: BitsFocusEvent) => void;
|
|
81
84
|
};
|
|
82
|
-
constructor(root: RadioGroupRootState);
|
|
83
85
|
}
|
|
84
86
|
export {};
|
|
@@ -130,13 +130,18 @@ export class RadioGroupInputState {
|
|
|
130
130
|
}
|
|
131
131
|
root;
|
|
132
132
|
shouldRender = $derived.by(() => this.root.opts.name.current !== undefined);
|
|
133
|
+
constructor(root) {
|
|
134
|
+
this.root = root;
|
|
135
|
+
this.onfocus = this.onfocus.bind(this);
|
|
136
|
+
}
|
|
137
|
+
onfocus(_) {
|
|
138
|
+
this.root.rovingFocusGroup.focusCurrentTabStop();
|
|
139
|
+
}
|
|
133
140
|
props = $derived.by(() => ({
|
|
134
141
|
name: this.root.opts.name.current,
|
|
135
142
|
value: this.root.opts.value.current,
|
|
136
143
|
required: this.root.opts.required.current,
|
|
137
144
|
disabled: this.root.opts.disabled.current,
|
|
145
|
+
onfocus: this.onfocus,
|
|
138
146
|
}));
|
|
139
|
-
constructor(root) {
|
|
140
|
-
this.root = root;
|
|
141
|
-
}
|
|
142
147
|
}
|
|
@@ -39,5 +39,6 @@ export declare class RovingFocusGroup {
|
|
|
39
39
|
handleKeydown(node: HTMLElement | null | undefined, e: KeyboardEvent, both?: boolean): HTMLElement | undefined;
|
|
40
40
|
getTabIndex(node: HTMLElement | null | undefined): 0 | -1;
|
|
41
41
|
setCurrentTabStopId(id: string): void;
|
|
42
|
+
focusCurrentTabStop(): void;
|
|
42
43
|
}
|
|
43
44
|
export {};
|
|
@@ -3,6 +3,7 @@ import { getElemDirection } from "./locale.js";
|
|
|
3
3
|
import { getDirectionalKeys } from "./get-directional-keys.js";
|
|
4
4
|
import { kbd } from "./kbd.js";
|
|
5
5
|
import { BROWSER } from "esm-env";
|
|
6
|
+
import { isHTMLElement } from "./is.js";
|
|
6
7
|
export class RovingFocusGroup {
|
|
7
8
|
#opts;
|
|
8
9
|
#currentTabStopId = box(null);
|
|
@@ -84,4 +85,13 @@ export class RovingFocusGroup {
|
|
|
84
85
|
setCurrentTabStopId(id) {
|
|
85
86
|
this.#currentTabStopId.current = id;
|
|
86
87
|
}
|
|
88
|
+
focusCurrentTabStop() {
|
|
89
|
+
const currentTabStopId = this.#currentTabStopId.current;
|
|
90
|
+
if (!currentTabStopId)
|
|
91
|
+
return;
|
|
92
|
+
const currentTabStop = this.#opts.rootNode.current?.querySelector(`#${currentTabStopId}`);
|
|
93
|
+
if (!currentTabStop || !isHTMLElement(currentTabStop))
|
|
94
|
+
return;
|
|
95
|
+
currentTabStop.focus();
|
|
96
|
+
}
|
|
87
97
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function warn(...messages: string[]): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DEV } from "esm-env";
|
|
2
|
+
let set;
|
|
3
|
+
if (DEV) {
|
|
4
|
+
set = new Set();
|
|
5
|
+
}
|
|
6
|
+
export function warn(...messages) {
|
|
7
|
+
if (!DEV)
|
|
8
|
+
return;
|
|
9
|
+
const msg = messages.join(" ");
|
|
10
|
+
if (set.has(msg))
|
|
11
|
+
return;
|
|
12
|
+
set.add(msg);
|
|
13
|
+
console.warn(`[Bits UI]: ${msg}`);
|
|
14
|
+
}
|
|
@@ -72,7 +72,7 @@ export type EditableTimeSegmentPart = (typeof EDITABLE_TIME_SEGMENT_PARTS)[numbe
|
|
|
72
72
|
export type EditableSegmentPart = (typeof EDITABLE_SEGMENT_PARTS)[number];
|
|
73
73
|
export type NonEditableSegmentPart = (typeof NON_EDITABLE_SEGMENT_PARTS)[number];
|
|
74
74
|
export type SegmentPart = EditableSegmentPart | NonEditableSegmentPart;
|
|
75
|
-
export type TimeSegmentPart = EditableTimeSegmentPart | "literal";
|
|
75
|
+
export type TimeSegmentPart = EditableTimeSegmentPart | "literal" | "timeZoneName";
|
|
76
76
|
export type AnyTimeExceptLiteral = Exclude<TimeSegmentPart, "literal">;
|
|
77
77
|
export type AnyExceptLiteral = Exclude<SegmentPart, "literal">;
|
|
78
78
|
export type DayPeriod = "AM" | "PM" | null;
|