bits-ui 1.5.0 → 1.5.2

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.
@@ -7,6 +7,7 @@ import type { DateMatcher, Month } from "../../shared/index.js";
7
7
  import { type Announcer } from "../../internal/date-time/announcer.js";
8
8
  import { type Formatter } from "../../internal/date-time/formatter.js";
9
9
  import { type CalendarParts } from "../../internal/date-time/calendar-helpers.svelte.js";
10
+ import type { WeekStartsOn } from "../../shared/date/types.js";
10
11
  type CalendarRootStateProps = WithRefProps<WritableBoxedValues<{
11
12
  value: DateValue | undefined | DateValue[];
12
13
  placeholder: DateValue;
@@ -16,7 +17,7 @@ type CalendarRootStateProps = WithRefProps<WritableBoxedValues<{
16
17
  maxValue: DateValue | undefined;
17
18
  disabled: boolean;
18
19
  pagedNavigation: boolean;
19
- weekStartsOn: 0 | 1 | 2 | 3 | 4 | 5 | 6;
20
+ weekStartsOn: WeekStartsOn | undefined;
20
21
  weekdayFormat: Intl.DateTimeFormatOptions["weekday"];
21
22
  isDateDisabled: DateMatcher;
22
23
  isDateUnavailable: DateMatcher;
@@ -18,7 +18,7 @@
18
18
  placeholder = $bindable(),
19
19
  onPlaceholderChange = noop,
20
20
  weekdayFormat = "narrow",
21
- weekStartsOn = 0,
21
+ weekStartsOn,
22
22
  pagedNavigation = false,
23
23
  isDateDisabled = () => false,
24
24
  isDateUnavailable = () => false,
@@ -94,6 +94,7 @@ export declare class DateFieldRootState {
94
94
  };
95
95
  isInvalid: boolean;
96
96
  inferredGranularity: Granularity;
97
+ dateRef: DateValue;
97
98
  allSegmentContent: {
98
99
  obj: import("../../internal/date-time/field/types.js").SegmentContentObj;
99
100
  arr: {
@@ -317,12 +317,13 @@ export class DateFieldRootState {
317
317
  const inferred = inferGranularity(this.placeholder.current, this.granularity.current);
318
318
  return inferred;
319
319
  });
320
+ dateRef = $derived.by(() => this.value.current ?? this.placeholder.current);
320
321
  allSegmentContent = $derived.by(() => createContent({
321
322
  segmentValues: this.segmentValues,
322
323
  formatter: this.formatter,
323
324
  locale: this.locale.current,
324
325
  granularity: this.inferredGranularity,
325
- dateRef: this.placeholder.current,
326
+ dateRef: this.dateRef,
326
327
  hideTimeZone: this.hideTimeZone.current,
327
328
  hourCycle: this.hourCycle.current,
328
329
  }));
@@ -35,7 +35,7 @@
35
35
  disableDaysOutsideMonth = true,
36
36
  preventDeselect = false,
37
37
  pagedNavigation = false,
38
- weekStartsOn = 0,
38
+ weekStartsOn,
39
39
  weekdayFormat = "narrow",
40
40
  isDateDisabled = () => false,
41
41
  fixedWeeks = false,
@@ -22,7 +22,7 @@ type DatePickerRootStateProps = WritableBoxedValues<{
22
22
  required: boolean;
23
23
  preventDeselect: boolean;
24
24
  pagedNavigation: boolean;
25
- weekStartsOn: WeekStartsOn;
25
+ weekStartsOn: WeekStartsOn | undefined;
26
26
  weekdayFormat: Intl.DateTimeFormatOptions["weekday"];
27
27
  fixedWeeks: boolean;
28
28
  numberOfMonths: number;
@@ -37,7 +37,7 @@
37
37
  disableDaysOutsideMonth = true,
38
38
  preventDeselect = false,
39
39
  pagedNavigation = false,
40
- weekStartsOn = 0,
40
+ weekStartsOn,
41
41
  weekdayFormat = "narrow",
42
42
  isDateDisabled = () => false,
43
43
  fixedWeeks = false,
@@ -24,7 +24,7 @@ type DateRangePickerRootStateProps = WritableBoxedValues<{
24
24
  required: boolean;
25
25
  preventDeselect: boolean;
26
26
  pagedNavigation: boolean;
27
- weekStartsOn: WeekStartsOn;
27
+ weekStartsOn: WeekStartsOn | undefined;
28
28
  weekdayFormat: Intl.DateTimeFormatOptions["weekday"];
29
29
  fixedWeeks: boolean;
30
30
  numberOfMonths: number;
@@ -173,8 +173,7 @@ class NavigationMenuListState {
173
173
  });
174
174
  this.rovingFocusGroup = useRovingFocus({
175
175
  rootNodeId: opts.id,
176
- candidateAttr: NAVIGATION_MENU_ITEM_ATTR,
177
- candidateSelector: `:is([${NAVIGATION_MENU_TRIGGER_ATTR}], [data-list-link]):not([data-disabled])`,
176
+ candidateSelector: `:is([${NAVIGATION_MENU_TRIGGER_ATTR}], [${NAVIGATION_MENU_LINK_ATTR}]):not([data-disabled])`,
178
177
  loop: box.with(() => false),
179
178
  orientation: this.context.opts.orientation,
180
179
  });
@@ -18,7 +18,7 @@
18
18
  placeholder = $bindable(),
19
19
  onPlaceholderChange = noop,
20
20
  weekdayFormat = "narrow",
21
- weekStartsOn = 0,
21
+ weekStartsOn,
22
22
  pagedNavigation = false,
23
23
  isDateDisabled = () => false,
24
24
  isDateUnavailable = () => false,
@@ -5,6 +5,7 @@ import type { BitsFocusEvent, BitsKeyboardEvent, BitsMouseEvent, WithRefProps }
5
5
  import { type Announcer } from "../../internal/date-time/announcer.js";
6
6
  import { type Formatter } from "../../internal/date-time/formatter.js";
7
7
  import { type CalendarParts } from "../../internal/date-time/calendar-helpers.svelte.js";
8
+ import type { WeekStartsOn } from "../../shared/date/types.js";
8
9
  type RangeCalendarRootStateProps = WithRefProps<WritableBoxedValues<{
9
10
  value: DateRange;
10
11
  placeholder: DateValue;
@@ -16,7 +17,7 @@ type RangeCalendarRootStateProps = WithRefProps<WritableBoxedValues<{
16
17
  maxValue: DateValue | undefined;
17
18
  disabled: boolean;
18
19
  pagedNavigation: boolean;
19
- weekStartsOn: 0 | 1 | 2 | 3 | 4 | 5 | 6;
20
+ weekStartsOn: WeekStartsOn | undefined;
20
21
  weekdayFormat: Intl.DateTimeFormatOptions["weekday"];
21
22
  isDateDisabled: (date: DateValue) => boolean;
22
23
  isDateUnavailable: (date: DateValue) => boolean;
@@ -21,7 +21,7 @@ export type CreateMonthProps = {
21
21
  /**
22
22
  * The day of the week to start the calendar on (0 for Sunday, 1 for Monday, etc.).
23
23
  */
24
- weekStartsOn: number;
24
+ weekStartsOn: number | undefined;
25
25
  /**
26
26
  * Whether to always render 6 weeks in the calendar, even if the month doesn't
27
27
  * span 6 weeks.
@@ -102,7 +102,7 @@ type HandleCalendarPageProps = {
102
102
  setMonths: (months: Month<DateValue>[]) => void;
103
103
  numberOfMonths: number;
104
104
  pagedNavigation: boolean;
105
- weekStartsOn: number;
105
+ weekStartsOn: number | undefined;
106
106
  locale: string;
107
107
  fixedWeeks: boolean;
108
108
  setPlaceholder: (date: DateValue) => void;
@@ -116,7 +116,7 @@ type GetWeekdaysProps = {
116
116
  };
117
117
  export declare function getWeekdays({ months, formatter, weekdayFormat }: GetWeekdaysProps): string[];
118
118
  type UseMonthViewSyncProps = {
119
- weekStartsOn: ReadableBox<number>;
119
+ weekStartsOn: ReadableBox<number | undefined>;
120
120
  locale: ReadableBox<string>;
121
121
  fixedWeeks: ReadableBox<boolean>;
122
122
  numberOfMonths: ReadableBox<number>;
@@ -141,7 +141,7 @@ export declare function createAccessibleHeading({ calendarNode, label, accessibl
141
141
  type UseMonthViewPlaceholderSyncProps = {
142
142
  placeholder: WritableBox<DateValue>;
143
143
  getVisibleMonths: () => DateValue[];
144
- weekStartsOn: ReadableBox<number>;
144
+ weekStartsOn: ReadableBox<number | undefined>;
145
145
  locale: ReadableBox<string>;
146
146
  fixedWeeks: ReadableBox<boolean>;
147
147
  numberOfMonths: ReadableBox<number>;
@@ -52,8 +52,12 @@ function createMonth(props) {
52
52
  const datesArray = Array.from({ length: daysInMonth }, (_, i) => dateObj.set({ day: i + 1 }));
53
53
  const firstDayOfMonth = startOfMonth(dateObj);
54
54
  const lastDayOfMonth = endOfMonth(dateObj);
55
- const lastSunday = getLastFirstDayOfWeek(firstDayOfMonth, weekStartsOn, locale);
56
- const nextSaturday = getNextLastDayOfWeek(lastDayOfMonth, weekStartsOn, locale);
55
+ const lastSunday = weekStartsOn !== undefined
56
+ ? getLastFirstDayOfWeek(firstDayOfMonth, weekStartsOn, "en-US")
57
+ : getLastFirstDayOfWeek(firstDayOfMonth, 0, locale);
58
+ const nextSaturday = weekStartsOn !== undefined
59
+ ? getNextLastDayOfWeek(lastDayOfMonth, weekStartsOn, "en-US")
60
+ : getNextLastDayOfWeek(lastDayOfMonth, 0, locale);
57
61
  const lastMonthDays = getDaysBetween(lastSunday.subtract({ days: 1 }), firstDayOfMonth);
58
62
  const nextMonthDays = getDaysBetween(lastDayOfMonth, nextSaturday.add({ days: 1 }));
59
63
  const totalDays = lastMonthDays.length + datesArray.length + nextMonthDays.length;
@@ -1,14 +1,18 @@
1
1
  import { type ReadableBox } from "svelte-toolbelt";
2
2
  import type { Orientation } from "../shared/index.js";
3
- type UseRovingFocusProps = {
3
+ type UseRovingFocusProps = ({
4
4
  /**
5
5
  * The selector used to find the focusable candidates.
6
6
  */
7
7
  candidateAttr: string;
8
+ candidateSelector?: undefined;
9
+ } | {
8
10
  /**
9
11
  * Custom candidate selector
10
12
  */
11
- candidateSelector?: string;
13
+ candidateSelector: string;
14
+ candidateAttr?: undefined;
15
+ }) & {
12
16
  /**
13
17
  * The id of the root node
14
18
  */
@@ -15,10 +15,11 @@ export function useRovingFocus(props) {
15
15
  const candidates = Array.from(node.querySelectorAll(props.candidateSelector));
16
16
  return candidates;
17
17
  }
18
- else {
18
+ else if (props.candidateAttr) {
19
19
  const candidates = Array.from(node.querySelectorAll(`[${props.candidateAttr}]:not([data-disabled])`));
20
20
  return candidates;
21
21
  }
22
+ return [];
22
23
  }
23
24
  function focusFirstCandidate() {
24
25
  const items = getCandidateNodes();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bits-ui",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "license": "MIT",
5
5
  "repository": "github:huntabyte/bits-ui",
6
6
  "funding": "https://github.com/sponsors/huntabyte",