bits-ui 2.4.1 → 2.6.0

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.
Files changed (48) hide show
  1. package/dist/bits/calendar/calendar.svelte.d.ts +77 -1
  2. package/dist/bits/calendar/calendar.svelte.js +169 -9
  3. package/dist/bits/calendar/components/calendar-month-select.svelte +54 -0
  4. package/dist/bits/calendar/components/calendar-month-select.svelte.d.ts +4 -0
  5. package/dist/bits/calendar/components/calendar-year-select.svelte +51 -0
  6. package/dist/bits/calendar/components/calendar-year-select.svelte.d.ts +4 -0
  7. package/dist/bits/calendar/components/calendar.svelte +6 -0
  8. package/dist/bits/calendar/exports.d.ts +3 -1
  9. package/dist/bits/calendar/exports.js +2 -0
  10. package/dist/bits/calendar/types.d.ts +94 -12
  11. package/dist/bits/combobox/types.d.ts +1 -1
  12. package/dist/bits/command/command.svelte.d.ts +26 -2
  13. package/dist/bits/command/command.svelte.js +378 -27
  14. package/dist/bits/command/components/command.svelte +4 -0
  15. package/dist/bits/command/components/command.svelte.d.ts +1 -1
  16. package/dist/bits/command/types.d.ts +16 -2
  17. package/dist/bits/date-field/date-field.svelte.js +5 -1
  18. package/dist/bits/date-picker/components/date-picker-calendar.svelte +3 -0
  19. package/dist/bits/date-picker/components/date-picker.svelte +4 -0
  20. package/dist/bits/date-picker/date-picker.svelte.d.ts +2 -0
  21. package/dist/bits/date-picker/exports.d.ts +3 -1
  22. package/dist/bits/date-picker/exports.js +2 -0
  23. package/dist/bits/date-picker/types.d.ts +13 -1
  24. package/dist/bits/date-range-field/date-range-field.svelte.js +5 -1
  25. package/dist/bits/date-range-picker/components/date-range-picker-calendar.svelte +5 -0
  26. package/dist/bits/date-range-picker/components/date-range-picker.svelte +10 -0
  27. package/dist/bits/date-range-picker/date-range-picker.svelte.d.ts +5 -0
  28. package/dist/bits/date-range-picker/exports.d.ts +3 -1
  29. package/dist/bits/date-range-picker/exports.js +2 -0
  30. package/dist/bits/date-range-picker/types.d.ts +33 -1
  31. package/dist/bits/range-calendar/components/range-calendar.svelte +10 -0
  32. package/dist/bits/range-calendar/exports.d.ts +3 -1
  33. package/dist/bits/range-calendar/exports.js +2 -0
  34. package/dist/bits/range-calendar/range-calendar.svelte.d.ts +20 -0
  35. package/dist/bits/range-calendar/range-calendar.svelte.js +120 -6
  36. package/dist/bits/range-calendar/types.d.ts +44 -12
  37. package/dist/bits/select/components/select-hidden-input.svelte +6 -2
  38. package/dist/bits/select/components/select-hidden-input.svelte.d.ts +2 -1
  39. package/dist/bits/select/components/select.svelte +3 -2
  40. package/dist/bits/select/types.d.ts +5 -0
  41. package/dist/internal/date-time/calendar-helpers.svelte.d.ts +8 -2
  42. package/dist/internal/date-time/calendar-helpers.svelte.js +47 -15
  43. package/dist/internal/date-time/formatter.d.ts +8 -1
  44. package/dist/internal/date-time/formatter.js +16 -3
  45. package/dist/internal/kbd-constants.d.ts +2 -0
  46. package/dist/internal/kbd-constants.js +2 -0
  47. package/dist/shared/attributes.d.ts +3 -1
  48. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import type { DateValue } from "@internationalized/date";
2
2
  import type { OnChangeFn, WithChild, Without } from "../../internal/types.js";
3
- import type { BitsPrimitiveButtonAttributes, BitsPrimitiveDivAttributes, BitsPrimitiveHeaderAttributes, BitsPrimitiveTableAttributes, BitsPrimitiveTbodyAttributes, BitsPrimitiveTdAttributes, BitsPrimitiveThAttributes, BitsPrimitiveTheadAttributes, BitsPrimitiveTrAttributes } from "../../shared/attributes.js";
3
+ import type { BitsPrimitiveButtonAttributes, BitsPrimitiveDivAttributes, BitsPrimitiveHeaderAttributes, BitsPrimitiveSelectAttributes, BitsPrimitiveTableAttributes, BitsPrimitiveTbodyAttributes, BitsPrimitiveTdAttributes, BitsPrimitiveThAttributes, BitsPrimitiveTheadAttributes, BitsPrimitiveTrAttributes } from "../../shared/attributes.js";
4
4
  import type { DateMatcher, Month, WeekStartsOn } from "../../shared/date/types.js";
5
5
  export type CalendarRootSnippetProps = {
6
6
  months: Month<DateValue>[];
@@ -11,7 +11,7 @@ type CalendarBaseRootPropsWithoutHTML = {
11
11
  * The placeholder date, used to control the view of the
12
12
  * calendar when no value is present.
13
13
  *
14
- * @defaultValue the current date
14
+ * @default the current date
15
15
  */
16
16
  placeholder?: DateValue;
17
17
  /**
@@ -23,7 +23,7 @@ type CalendarBaseRootPropsWithoutHTML = {
23
23
  * Whether or not users can deselect a date once selected
24
24
  * without selecting another date.
25
25
  *
26
- * @defaultValue false
26
+ * @default false
27
27
  */
28
28
  preventDeselect?: boolean;
29
29
  /**
@@ -37,7 +37,7 @@ type CalendarBaseRootPropsWithoutHTML = {
37
37
  /**
38
38
  * Whether or not the calendar is disabled.
39
39
  *
40
- * @defaultValue false
40
+ * @default false
41
41
  */
42
42
  disabled?: boolean;
43
43
  /**
@@ -51,7 +51,7 @@ type CalendarBaseRootPropsWithoutHTML = {
51
51
  * February), clicking the next button changes the view to March and April. If `pagedNavigation`
52
52
  * is `false`, the view shifts to February and March.
53
53
  *
54
- * @defaultValue false
54
+ * @default false
55
55
  */
56
56
  pagedNavigation?: boolean;
57
57
  /**
@@ -59,7 +59,7 @@ type CalendarBaseRootPropsWithoutHTML = {
59
59
  * be a number between 0 and 6, where 0 is Sunday and 6 is
60
60
  * Saturday.
61
61
  *
62
- * @defaultValue 0 (Sunday)
62
+ * @default 0 (Sunday)
63
63
  */
64
64
  weekStartsOn?: WeekStartsOn;
65
65
  /**
@@ -72,7 +72,7 @@ type CalendarBaseRootPropsWithoutHTML = {
72
72
  * - "narrow": "S", "M", "T", etc.
73
73
  *```
74
74
  *
75
- * @defaultValue "narrow"
75
+ * @default "narrow"
76
76
  *
77
77
  * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#weekday
78
78
  */
@@ -110,14 +110,14 @@ type CalendarBaseRootPropsWithoutHTML = {
110
110
  * To display 6 weeks per month, you will need to render out the previous
111
111
  * and next month's dates in the calendar as well.
112
112
  *
113
- * @defaultValue false
113
+ * @default false
114
114
  */
115
115
  fixedWeeks?: boolean;
116
116
  /**
117
117
  * Determines the number of months to display on the calendar simultaneously.
118
118
  * For navigation between months, refer to the `pagedNavigation` prop.
119
119
  *
120
- * @defaultValue 1
120
+ * @default 1
121
121
  */
122
122
  numberOfMonths?: number;
123
123
  /**
@@ -134,7 +134,7 @@ type CalendarBaseRootPropsWithoutHTML = {
134
134
  /**
135
135
  * The default locale setting.
136
136
  *
137
- * @defaultValue 'en'
137
+ * @default 'en'
138
138
  */
139
139
  locale?: string;
140
140
  /**
@@ -143,7 +143,7 @@ type CalendarBaseRootPropsWithoutHTML = {
143
143
  * dates. @see disabled for a similar prop that prevents focusing
144
144
  * and selecting dates.
145
145
  *
146
- * @defaultValue false
146
+ * @default false
147
147
  */
148
148
  readonly?: boolean;
149
149
  /**
@@ -156,9 +156,28 @@ type CalendarBaseRootPropsWithoutHTML = {
156
156
  * days outside the current month are rendered to fill the calendar grid, but they
157
157
  * are not selectable. Setting this prop to `true` will disable this behavior.
158
158
  *
159
- * @defaultValue false
159
+ * @default false
160
160
  */
161
161
  disableDaysOutsideMonth?: boolean;
162
+ /**
163
+ * The maximum number of days that can be selected in multiple mode.
164
+ * When set, users cannot select more dates than this number.
165
+ *
166
+ * @default undefined
167
+ */
168
+ maxDays?: number;
169
+ /**
170
+ * The format of the month names in the calendar.
171
+ *
172
+ * @default "long"
173
+ */
174
+ monthFormat?: Intl.DateTimeFormatOptions["month"] | ((month: number) => string);
175
+ /**
176
+ * The format of the year names in the calendar.
177
+ *
178
+ * @default "numeric"
179
+ */
180
+ yearFormat?: Intl.DateTimeFormatOptions["year"] | ((year: number) => string);
162
181
  };
163
182
  export type CalendarSingleRootPropsWithoutHTML = {
164
183
  /**
@@ -245,4 +264,67 @@ export type CalendarNextButtonPropsWithoutHTML = WithChild;
245
264
  export type CalendarNextButtonProps = CalendarNextButtonPropsWithoutHTML & Without<BitsPrimitiveButtonAttributes, CalendarNextButtonPropsWithoutHTML>;
246
265
  export type CalendarPrevButtonPropsWithoutHTML = WithChild;
247
266
  export type CalendarPrevButtonProps = CalendarPrevButtonPropsWithoutHTML & Without<BitsPrimitiveButtonAttributes, CalendarPrevButtonPropsWithoutHTML>;
267
+ export type CalendarMonthSelectSnippetProps = {
268
+ monthItems: Array<{
269
+ value: number;
270
+ label: string;
271
+ }>;
272
+ selectedMonthItem: {
273
+ value: number;
274
+ label: string;
275
+ };
276
+ };
277
+ export type CalendarMonthSelectPropsWithoutHTML = WithChild<{
278
+ /**
279
+ * An array of month numbers (1-12) to display in the select.
280
+ * This allows for flexible month selection, such as showing only
281
+ * specific months or seasons.
282
+ *
283
+ * @default [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] (all months)
284
+ */
285
+ months?: number[];
286
+ /**
287
+ * How the month names should be formatted in the select options.
288
+ *
289
+ * - "long": "January", "February", etc.
290
+ * - "short": "Jan", "Feb", etc.
291
+ * - "narrow": "J", "F", etc.
292
+ * - "numeric": "1", "2", etc.
293
+ * - "2-digit": "01", "02", etc.
294
+ *
295
+ * @default "long"
296
+ */
297
+ monthFormat?: Intl.DateTimeFormatOptions["month"] | ((month: number) => string);
298
+ }, CalendarMonthSelectSnippetProps>;
299
+ export type CalendarMonthSelectProps = CalendarMonthSelectPropsWithoutHTML & Without<BitsPrimitiveSelectAttributes, CalendarMonthSelectPropsWithoutHTML>;
300
+ export type CalendarYearSelectSnippetProps = {
301
+ yearItems: Array<{
302
+ value: number;
303
+ label: string;
304
+ }>;
305
+ selectedYearItem: {
306
+ value: number;
307
+ label: string;
308
+ };
309
+ };
310
+ export type CalendarYearSelectPropsWithoutHTML = WithChild<{
311
+ /**
312
+ * An array of years to display in the select.
313
+ * This allows for complete control over which years appear,
314
+ * such as showing only years with data or excluding certain periods.
315
+ *
316
+ * @default Array from currentYear - 100 to currentYear
317
+ */
318
+ years?: number[];
319
+ /**
320
+ * How the year should be formatted in the select options.
321
+ *
322
+ * - "numeric": "2024", "2023", etc.
323
+ * - "2-digit": "24", "23", etc.
324
+ *
325
+ * @default "numeric"
326
+ */
327
+ yearFormat?: Intl.DateTimeFormatOptions["year"] | ((year: number) => string);
328
+ }, CalendarYearSelectSnippetProps>;
329
+ export type CalendarYearSelectProps = CalendarYearSelectPropsWithoutHTML & Without<BitsPrimitiveSelectAttributes, CalendarYearSelectPropsWithoutHTML>;
248
330
  export {};
@@ -1,7 +1,7 @@
1
1
  import type { BitsPrimitiveInputAttributes } from "../../shared/attributes.js";
2
2
  import type { SelectBaseRootPropsWithoutHTML, SelectMultipleRootPropsWithoutHTML, SelectSingleRootPropsWithoutHTML } from "../select/types.js";
3
3
  import type { WithChild, Without } from "../../internal/types.js";
4
- export type ComboboxBaseRootPropsWithoutHTML = SelectBaseRootPropsWithoutHTML & {
4
+ export type ComboboxBaseRootPropsWithoutHTML = Omit<SelectBaseRootPropsWithoutHTML, "autocomplete"> & {
5
5
  /**
6
6
  * A read-only value that can be used to programmatically
7
7
  * update the input value.
@@ -1,12 +1,20 @@
1
1
  import type { CommandState } from "./types.js";
2
2
  import type { BitsKeyboardEvent, BitsMouseEvent, BitsPointerEvent, WithRefProps } from "../../internal/types.js";
3
3
  import type { ReadableBoxedValues, WritableBoxedValues } from "../../internal/box.svelte.js";
4
+ type GridItem = {
5
+ index: number;
6
+ firstRowOfGroup: boolean;
7
+ ref: HTMLElement;
8
+ };
9
+ type ItemsGrid = GridItem[][];
4
10
  type CommandRootStateProps = WithRefProps<ReadableBoxedValues<{
5
11
  filter: (value: string, search: string, keywords?: string[]) => number;
6
12
  shouldFilter: boolean;
7
13
  loop: boolean;
8
14
  vimBindings: boolean;
15
+ columns: number | null;
9
16
  disablePointerSelection: boolean;
17
+ disableInitialScroll: boolean;
10
18
  onStateChange?: (state: Readonly<CommandState>) => void;
11
19
  }> & WritableBoxedValues<{
12
20
  value: string;
@@ -28,7 +36,7 @@ declare class CommandRootState {
28
36
  labelNode: HTMLElement | null;
29
37
  commandState: CommandState;
30
38
  _commandState: CommandState;
31
- setState<K extends keyof CommandState>(key: K, value: CommandState[K], opts?: boolean): void;
39
+ setState<K extends keyof CommandState>(key: K, value: CommandState[K], preventScroll?: boolean): void;
32
40
  constructor(opts: CommandRootStateProps);
33
41
  /**
34
42
  * Sets current value and triggers re-render if cleared.
@@ -43,6 +51,20 @@ declare class CommandRootState {
43
51
  * @remarks Exposed for direct item access and bound checking
44
52
  */
45
53
  getValidItems(): HTMLElement[];
54
+ /**
55
+ * Gets all visible command items.
56
+ *
57
+ * @returns Array of valid item elements
58
+ * @remarks Exposed for direct item access and bound checking
59
+ */
60
+ getVisibleItems(): HTMLElement[];
61
+ /** Returns all visible items in a matrix structure
62
+ *
63
+ * @remarks Returns empty if the command isn't configured as a grid
64
+ *
65
+ * @returns
66
+ */
67
+ get itemsGrid(): ItemsGrid;
46
68
  /**
47
69
  * Sets selection to item at specified index in valid items array.
48
70
  * If index is out of bounds, does nothing.
@@ -80,7 +102,7 @@ declare class CommandRootState {
80
102
  * // get all valid items
81
103
  * const items = getValidItems()
82
104
  */
83
- updateSelectedByItem(change: 1 | -1): void;
105
+ updateSelectedByItem(change: number): void;
84
106
  /**
85
107
  * Moves selection to the first valid item in the next/previous group.
86
108
  * If no group is found, falls back to selecting the next/previous item globally.
@@ -120,6 +142,7 @@ declare class CommandRootState {
120
142
  * @returns Cleanup function
121
143
  */
122
144
  registerGroup(id: string): () => void;
145
+ get isGrid(): boolean;
123
146
  onkeydown(e: BitsKeyboardEvent): void;
124
147
  props: {
125
148
  readonly id: string;
@@ -230,6 +253,7 @@ declare class CommandItemState {
230
253
  readonly "data-disabled": "" | undefined;
231
254
  readonly "data-selected": "" | undefined;
232
255
  readonly "data-value": string;
256
+ readonly "data-group": string | undefined;
233
257
  readonly role: "option";
234
258
  readonly onpointermove: (_: BitsPointerEvent) => void;
235
259
  readonly onclick: (_: BitsMouseEvent) => void;