bits-ui 1.3.18 → 1.3.19

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,7 +7,7 @@ import { getAriaDisabled, getAriaHidden, getAriaReadonly, getAriaSelected, getDa
7
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
- import { createAccessibleHeading, createMonths, getCalendarElementProps, getCalendarHeadingValue, getIsNextButtonDisabled, getIsPrevButtonDisabled, getWeekdays, handleCalendarKeydown, handleCalendarNextPage, handleCalendarPrevPage, shiftCalendarFocus, useEnsureNonDisabledPlaceholder, useMonthViewOptionsSync, useMonthViewPlaceholderSync, } from "../../internal/date-time/calendar-helpers.svelte.js";
10
+ import { createAccessibleHeading, createMonths, getCalendarElementProps, getCalendarHeadingValue, getDateWithPreviousTime, getIsNextButtonDisabled, getIsPrevButtonDisabled, getWeekdays, handleCalendarKeydown, handleCalendarNextPage, handleCalendarPrevPage, shiftCalendarFocus, useEnsureNonDisabledPlaceholder, useMonthViewOptionsSync, useMonthViewPlaceholderSync, } from "../../internal/date-time/calendar-helpers.svelte.js";
11
11
  import { getDateValueType, isBefore, toDate } from "../../internal/date-time/utils.js";
12
12
  export class CalendarRootState {
13
13
  opts;
@@ -258,9 +258,7 @@ export class CalendarRootState {
258
258
  else if (!value) {
259
259
  return false;
260
260
  }
261
- else {
262
- return isSameDay(value, date);
263
- }
261
+ return isSameDay(value, date);
264
262
  }
265
263
  shiftFocus(node, add) {
266
264
  return shiftCalendarFocus({
@@ -275,13 +273,12 @@ export class CalendarRootState {
275
273
  });
276
274
  }
277
275
  handleCellClick(_, date) {
278
- const readonly = this.opts.readonly.current;
279
- if (readonly)
276
+ if (this.opts.readonly.current)
280
277
  return;
281
- const isDateDisabled = this.opts.isDateDisabled.current;
282
- const isDateUnavailable = this.opts.isDateUnavailable.current;
283
- if (isDateDisabled?.(date) || isDateUnavailable?.(date))
278
+ if (this.opts.isDateDisabled.current?.(date) ||
279
+ this.opts.isDateUnavailable.current?.(date)) {
284
280
  return;
281
+ }
285
282
  const prev = this.opts.value.current;
286
283
  const multiple = this.opts.type.current === "multiple";
287
284
  if (multiple) {
@@ -289,19 +286,17 @@ export class CalendarRootState {
289
286
  this.opts.value.current = this.handleMultipleUpdate(prev, date);
290
287
  }
291
288
  }
292
- else {
293
- if (!Array.isArray(prev)) {
294
- const next = this.handleSingleUpdate(prev, date);
295
- if (!next) {
296
- this.announcer.announce("Selected date is now empty.", "polite", 5000);
297
- }
298
- else {
299
- this.announcer.announce(`Selected Date: ${this.formatter.selectedDate(next, false)}`, "polite");
300
- }
301
- this.opts.value.current = next;
302
- if (next !== undefined) {
303
- this.opts.onDateSelect?.current?.();
304
- }
289
+ else if (!Array.isArray(prev)) {
290
+ const next = this.handleSingleUpdate(prev, date);
291
+ if (!next) {
292
+ this.announcer.announce("Selected date is now empty.", "polite", 5000);
293
+ }
294
+ else {
295
+ this.announcer.announce(`Selected Date: ${this.formatter.selectedDate(next, false)}`, "polite");
296
+ }
297
+ this.opts.value.current = getDateWithPreviousTime(next, prev);
298
+ if (next !== undefined) {
299
+ this.opts.onDateSelect?.current?.();
305
300
  }
306
301
  }
307
302
  }
@@ -45,7 +45,7 @@
45
45
  }
46
46
 
47
47
  if (value === undefined) {
48
- const defaultValue = type === "single" ? "" : [];
48
+ const defaultValue = type === "single" ? undefined : [];
49
49
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
50
  value = defaultValue as any;
51
51
  }
@@ -29,6 +29,20 @@ const COMMAND_VALID_ITEM_SELECTOR = `${COMMAND_ITEM_SELECTOR}:not([aria-disabled
29
29
  const CommandRootContext = new Context("Command.Root");
30
30
  const CommandListContext = new Context("Command.List");
31
31
  const CommandGroupContainerContext = new Context("Command.Group");
32
+ const defaultState = {
33
+ /** Value of the search query */
34
+ search: "",
35
+ /** Currently selected item value */
36
+ value: "",
37
+ filtered: {
38
+ /** The count of all visible items. */
39
+ count: 0,
40
+ /** Map from visible item id to its search store. */
41
+ items: new Map(),
42
+ /** Set of groups with at least one visible item. */
43
+ groups: new Set(),
44
+ },
45
+ };
32
46
  class CommandRootState {
33
47
  opts;
34
48
  #updateScheduled = false;
@@ -43,9 +57,9 @@ class CommandRootState {
43
57
  inputNode = $state(null);
44
58
  labelNode = $state(null);
45
59
  // published state that the components and other things can react to
46
- commandState = $state.raw(null);
60
+ commandState = $state.raw(defaultState);
47
61
  // internal state that we mutate in batches and publish to the `state` at once
48
- _commandState = $state(null);
62
+ _commandState = $state(defaultState);
49
63
  // whether the search has had a value other than ""
50
64
  searchHasHadValue = $state(false);
51
65
  #snapshot() {
@@ -89,22 +103,9 @@ class CommandRootState {
89
103
  }
90
104
  constructor(opts) {
91
105
  this.opts = opts;
92
- const defaultState = {
93
- /** Value of the search query */
94
- search: "",
95
- /** Currently selected item value */
96
- value: this.opts.value.current ?? "",
97
- filtered: {
98
- /** The count of all visible items. */
99
- count: 0,
100
- /** Map from visible item id to its search store. */
101
- items: new Map(),
102
- /** Set of groups with at least one visible item. */
103
- groups: new Set(),
104
- },
105
- };
106
- this._commandState = defaultState;
107
- this.commandState = defaultState;
106
+ const defaults = { ...this._commandState, value: this.opts.value.current ?? "" };
107
+ this._commandState = defaults;
108
+ this.commandState = defaults;
108
109
  useRefById(opts);
109
110
  this.onkeydown = this.onkeydown.bind(this);
110
111
  $effect(() => {
@@ -197,4 +197,5 @@ export declare function useEnsureNonDisabledPlaceholder({ ref, placeholder, defa
197
197
  maxValue: ReadableBox<DateValue | undefined>;
198
198
  defaultPlaceholder: DateValue;
199
199
  }): void;
200
+ export declare function getDateWithPreviousTime(date: DateValue | undefined, prev: DateValue | undefined): DateValue | undefined;
200
201
  export {};
@@ -1,7 +1,7 @@
1
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, parseAnyDateValue, parseStringToDateValue, toDate, } from "./utils.js";
4
+ import { getDaysInMonth, getLastFirstDayOfWeek, getNextLastDayOfWeek, hasTime, 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";
@@ -495,3 +495,16 @@ export function useEnsureNonDisabledPlaceholder({ ref, placeholder, defaultPlace
495
495
  }
496
496
  });
497
497
  }
498
+ export function getDateWithPreviousTime(date, prev) {
499
+ if (!date || !prev)
500
+ return date;
501
+ if (hasTime(date) && hasTime(prev)) {
502
+ return date.set({
503
+ hour: prev.hour,
504
+ minute: prev.minute,
505
+ millisecond: prev.millisecond,
506
+ second: prev.second,
507
+ });
508
+ }
509
+ return date;
510
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bits-ui",
3
- "version": "1.3.18",
3
+ "version": "1.3.19",
4
4
  "license": "MIT",
5
5
  "repository": "github:huntabyte/bits-ui",
6
6
  "funding": "https://github.com/sponsors/huntabyte",