bits-ui 1.3.16 → 1.3.18

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.
@@ -55,10 +55,13 @@ declare class AvatarFallbackState {
55
55
  readonly opts: AvatarFallbackStateProps;
56
56
  readonly root: AvatarRootState;
57
57
  constructor(opts: AvatarFallbackStateProps, root: AvatarRootState);
58
+ style: {
59
+ display: string;
60
+ } | undefined;
58
61
  props: {
59
62
  readonly style: {
60
- readonly display: "none" | undefined;
61
- };
63
+ display: string;
64
+ } | undefined;
62
65
  readonly "data-status": AvatarImageLoadingStatus;
63
66
  readonly "data-avatar-fallback": "";
64
67
  };
@@ -77,10 +77,9 @@ class AvatarFallbackState {
77
77
  this.root = root;
78
78
  useRefById(opts);
79
79
  }
80
+ style = $derived.by(() => this.root.opts.loadingStatus.current === "loaded" ? { display: "none" } : undefined);
80
81
  props = $derived.by(() => ({
81
- style: {
82
- display: this.root.opts.loadingStatus.current === "loaded" ? "none" : undefined,
83
- },
82
+ style: this.style,
84
83
  "data-status": this.root.opts.loadingStatus.current,
85
84
  [AVATAR_FALLBACK_ATTR]: "",
86
85
  }));
@@ -138,6 +138,7 @@ declare class CalendarCellState {
138
138
  readonly "data-focused": "" | undefined;
139
139
  readonly "data-selected": "" | undefined;
140
140
  readonly "data-value": string;
141
+ readonly "data-type": string;
141
142
  readonly "data-disabled": "" | undefined;
142
143
  };
143
144
  props: {
@@ -148,6 +149,7 @@ declare class CalendarCellState {
148
149
  readonly "data-focused": "" | undefined;
149
150
  readonly "data-selected": "" | undefined;
150
151
  readonly "data-value": string;
152
+ readonly "data-type": string;
151
153
  readonly "data-disabled": "" | undefined;
152
154
  readonly id: string;
153
155
  readonly role: "gridcell";
@@ -179,6 +181,7 @@ declare class CalendarDayState {
179
181
  readonly "data-focused": "" | undefined;
180
182
  readonly "data-selected": "" | undefined;
181
183
  readonly "data-value": string;
184
+ readonly "data-type": string;
182
185
  readonly "data-disabled": "" | undefined;
183
186
  readonly id: string;
184
187
  readonly role: "button";
@@ -8,7 +8,7 @@ import { useId } from "../../internal/use-id.js";
8
8
  import { getAnnouncer } from "../../internal/date-time/announcer.js";
9
9
  import { createFormatter } from "../../internal/date-time/formatter.js";
10
10
  import { createAccessibleHeading, createMonths, getCalendarElementProps, getCalendarHeadingValue, getIsNextButtonDisabled, getIsPrevButtonDisabled, getWeekdays, handleCalendarKeydown, handleCalendarNextPage, handleCalendarPrevPage, shiftCalendarFocus, useEnsureNonDisabledPlaceholder, useMonthViewOptionsSync, useMonthViewPlaceholderSync, } from "../../internal/date-time/calendar-helpers.svelte.js";
11
- import { isBefore, toDate } from "../../internal/date-time/utils.js";
11
+ import { getDateValueType, isBefore, toDate } from "../../internal/date-time/utils.js";
12
12
  export class CalendarRootState {
13
13
  opts;
14
14
  months = $state([]);
@@ -429,6 +429,7 @@ class CalendarCellState {
429
429
  "data-focused": this.isFocusedDate ? "" : undefined,
430
430
  "data-selected": getDataSelected(this.isSelectedDate),
431
431
  "data-value": this.opts.date.current.toString(),
432
+ "data-type": getDateValueType(this.opts.date.current),
432
433
  "data-disabled": getDataDisabled(this.isDisabled ||
433
434
  (this.isOutsideMonth && this.root.opts.disableDaysOutsideMonth.current)),
434
435
  }));
@@ -19,7 +19,7 @@ class PaginationRootState {
19
19
  range = $derived.by(() => {
20
20
  const start = (this.opts.page.current - 1) * this.opts.perPage.current;
21
21
  const end = Math.min(start + this.opts.perPage.current, this.opts.count.current);
22
- return { start, end };
22
+ return { start: start + 1, end };
23
23
  });
24
24
  pages = $derived.by(() => getPageItems({
25
25
  page: this.opts.page.current,
@@ -138,6 +138,7 @@ export declare class RangeCalendarCellState {
138
138
  readonly "data-highlighted": "" | undefined;
139
139
  readonly "data-selected": "" | undefined;
140
140
  readonly "data-value": string;
141
+ readonly "data-type": string;
141
142
  readonly "data-disabled": "" | undefined;
142
143
  };
143
144
  props: {
@@ -151,6 +152,7 @@ export declare class RangeCalendarCellState {
151
152
  readonly "data-highlighted": "" | undefined;
152
153
  readonly "data-selected": "" | undefined;
153
154
  readonly "data-value": string;
155
+ readonly "data-type": string;
154
156
  readonly "data-disabled": "" | undefined;
155
157
  readonly id: string;
156
158
  readonly role: "gridcell";
@@ -189,6 +191,7 @@ declare class RangeCalendarDayState {
189
191
  readonly "data-highlighted": "" | undefined;
190
192
  readonly "data-selected": "" | undefined;
191
193
  readonly "data-value": string;
194
+ readonly "data-type": string;
192
195
  readonly "data-disabled": "" | undefined;
193
196
  readonly id: string;
194
197
  readonly role: "button";
@@ -7,7 +7,7 @@ import { getAriaDisabled, getAriaSelected, getDataDisabled, getDataSelected, get
7
7
  import { getAnnouncer } from "../../internal/date-time/announcer.js";
8
8
  import { createFormatter } from "../../internal/date-time/formatter.js";
9
9
  import { createMonths, getCalendarElementProps, getCalendarHeadingValue, getIsNextButtonDisabled, getIsPrevButtonDisabled, getWeekdays, handleCalendarKeydown, handleCalendarNextPage, handleCalendarPrevPage, shiftCalendarFocus, useEnsureNonDisabledPlaceholder, useMonthViewOptionsSync, useMonthViewPlaceholderSync, } from "../../internal/date-time/calendar-helpers.svelte.js";
10
- import { areAllDaysBetweenValid, isAfter, isBefore, isBetweenInclusive, toDate, } from "../../internal/date-time/utils.js";
10
+ import { areAllDaysBetweenValid, getDateValueType, isAfter, isBefore, isBetweenInclusive, toDate, } from "../../internal/date-time/utils.js";
11
11
  export class RangeCalendarRootState {
12
12
  opts;
13
13
  months = $state([]);
@@ -466,6 +466,7 @@ export class RangeCalendarCellState {
466
466
  "data-highlighted": this.isHighlighted ? "" : undefined,
467
467
  "data-selected": getDataSelected(this.isSelectedDate),
468
468
  "data-value": this.opts.date.current.toString(),
469
+ "data-type": getDateValueType(this.opts.date.current),
469
470
  "data-disabled": getDataDisabled(this.isDisabled ||
470
471
  (this.isOutsideMonth && this.root.opts.disableDaysOutsideMonth.current)),
471
472
  }));
@@ -1,4 +1,4 @@
1
- import { CalendarDate, type DateValue } from "@internationalized/date";
1
+ import { type DateValue } from "@internationalized/date";
2
2
  import { type ReadableBox, type WritableBox } from "svelte-toolbelt";
3
3
  import type { Formatter } from "./formatter.js";
4
4
  import type { DateMatcher, Month } from "../../shared/index.js";
@@ -183,7 +183,7 @@ export declare function getCalendarElementProps({ fullCalendarLabel, id, isInval
183
183
  };
184
184
  export type CalendarParts = "root" | "grid" | "cell" | "next-button" | "prev-button" | "day" | "grid-body" | "grid-head" | "grid-row" | "head-cell" | "header" | "heading";
185
185
  export declare function pickerOpenFocus(e: Event): void;
186
- export declare function getFirstNonDisabledDateInView(calendarRef: HTMLElement): CalendarDate | undefined;
186
+ export declare function getFirstNonDisabledDateInView(calendarRef: HTMLElement): DateValue | undefined;
187
187
  /**
188
188
  * Ensures the placeholder is not set to a disabled date,
189
189
  * which would prevent the user from entering the Calendar
@@ -1,7 +1,7 @@
1
- import { CalendarDate, endOfMonth, isSameDay, isSameMonth, parseDate, startOfMonth, } from "@internationalized/date";
1
+ import { endOfMonth, isSameDay, isSameMonth, startOfMonth, } from "@internationalized/date";
2
2
  import { afterTick, styleToString } from "svelte-toolbelt";
3
3
  import { untrack } from "svelte";
4
- import { getDaysInMonth, getLastFirstDayOfWeek, getNextLastDayOfWeek, isAfter, isBefore, parseStringToDateValue, toDate, } from "./utils.js";
4
+ import { getDaysInMonth, getLastFirstDayOfWeek, getNextLastDayOfWeek, isAfter, isBefore, parseAnyDateValue, parseStringToDateValue, toDate, } from "./utils.js";
5
5
  import { getDataDisabled, getDataInvalid, getDataReadonly } from "../attrs.js";
6
6
  import { chunk, isValidIndex } from "../arrays.js";
7
7
  import { isBrowser, isHTMLElement } from "../is.js";
@@ -450,10 +450,12 @@ export function getFirstNonDisabledDateInView(calendarRef) {
450
450
  const daysInView = Array.from(calendarRef.querySelectorAll("[data-bits-day]:not([aria-disabled=true])"));
451
451
  if (daysInView.length === 0)
452
452
  return;
453
- const value = daysInView[0]?.getAttribute("data-value");
454
- if (!value)
453
+ const element = daysInView[0];
454
+ const value = element?.getAttribute("data-value");
455
+ const type = element?.getAttribute("data-type");
456
+ if (!value || !type)
455
457
  return;
456
- return parseDate(value);
458
+ return parseAnyDateValue(value, type);
457
459
  }
458
460
  /**
459
461
  * Ensures the placeholder is not set to a disabled date,
@@ -29,6 +29,8 @@ export declare function parseStringToDateValue(dateStr: string, referenceVal: Da
29
29
  * If no timezone is provided, the date will be converted to the local timezone.
30
30
  */
31
31
  export declare function toDate(dateValue: DateValue, tz?: string): Date;
32
+ export declare function getDateValueType(date: DateValue): string;
33
+ export declare function parseAnyDateValue(value: string, type: string): DateValue;
32
34
  export declare function isZonedDateTime(dateValue: DateValue): dateValue is ZonedDateTime;
33
35
  export declare function hasTime(dateValue: DateValue): dateValue is CalendarDateTime | ZonedDateTime;
34
36
  /**
@@ -70,6 +70,27 @@ export function toDate(dateValue, tz = getLocalTimeZone()) {
70
70
  return dateValue.toDate(tz);
71
71
  }
72
72
  }
73
+ export function getDateValueType(date) {
74
+ if (date instanceof CalendarDate)
75
+ return "date";
76
+ if (date instanceof CalendarDateTime)
77
+ return "datetime";
78
+ if (date instanceof ZonedDateTime)
79
+ return "zoneddatetime";
80
+ throw new Error("Unknown date type");
81
+ }
82
+ export function parseAnyDateValue(value, type) {
83
+ switch (type) {
84
+ case "date":
85
+ return parseDate(value);
86
+ case "datetime":
87
+ return parseDateTime(value);
88
+ case "zoneddatetime":
89
+ return parseZonedDateTime(value);
90
+ default:
91
+ throw new Error(`Unknown date type: ${type}`);
92
+ }
93
+ }
73
94
  function isCalendarDateTime(dateValue) {
74
95
  return dateValue instanceof CalendarDateTime;
75
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bits-ui",
3
- "version": "1.3.16",
3
+ "version": "1.3.18",
4
4
  "license": "MIT",
5
5
  "repository": "github:huntabyte/bits-ui",
6
6
  "funding": "https://github.com/sponsors/huntabyte",