bits-ui 2.14.2 → 2.14.4
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/calendar/components/calendar.svelte +2 -0
- package/dist/bits/command/command.svelte.js +17 -0
- package/dist/bits/context-menu/components/context-menu-trigger.svelte +1 -0
- package/dist/bits/date-field/components/date-field.svelte +2 -0
- package/dist/bits/date-picker/components/date-picker.svelte +2 -0
- package/dist/bits/date-range-field/components/date-range-field.svelte +6 -1
- package/dist/bits/date-range-picker/components/date-range-picker.svelte +2 -0
- package/dist/bits/range-calendar/components/range-calendar.svelte +2 -0
- package/dist/internal/date-time/utils.d.ts +3 -1
- package/dist/internal/date-time/utils.js +9 -3
- package/package.json +1 -1
|
@@ -134,6 +134,10 @@ export class CommandRootState {
|
|
|
134
134
|
if (!this._commandState.value || !this.#isInitialMount) {
|
|
135
135
|
this.#selectFirstItem();
|
|
136
136
|
}
|
|
137
|
+
else if (this.#isInitialMount && this._commandState.value) {
|
|
138
|
+
// scroll the initial value into view if it exists
|
|
139
|
+
this.#scrollInitialValue();
|
|
140
|
+
}
|
|
137
141
|
return;
|
|
138
142
|
}
|
|
139
143
|
const scores = this._commandState.filtered.items;
|
|
@@ -216,6 +220,19 @@ export class CommandRootState {
|
|
|
216
220
|
this.#isInitialMount = false;
|
|
217
221
|
});
|
|
218
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Scrolls the initial value into view if it exists and is not the first item.
|
|
225
|
+
* Called during initial mount when a value is provided.
|
|
226
|
+
*/
|
|
227
|
+
#scrollInitialValue() {
|
|
228
|
+
afterTick(() => {
|
|
229
|
+
const shouldPreventScroll = this.opts.disableInitialScroll.current;
|
|
230
|
+
if (!shouldPreventScroll) {
|
|
231
|
+
this.#scrollSelectedIntoView();
|
|
232
|
+
}
|
|
233
|
+
this.#isInitialMount = false;
|
|
234
|
+
});
|
|
235
|
+
}
|
|
219
236
|
/**
|
|
220
237
|
* Updates filtered items/groups based on search.
|
|
221
238
|
* Recalculates scores and filtered count.
|
|
@@ -44,7 +44,12 @@
|
|
|
44
44
|
|
|
45
45
|
function handleDefaultPlaceholder() {
|
|
46
46
|
if (placeholder !== undefined) return;
|
|
47
|
-
const defaultPlaceholder = getDefaultDate({
|
|
47
|
+
const defaultPlaceholder = getDefaultDate({
|
|
48
|
+
granularity,
|
|
49
|
+
defaultValue: value?.start,
|
|
50
|
+
minValue,
|
|
51
|
+
maxValue,
|
|
52
|
+
});
|
|
48
53
|
placeholder = defaultPlaceholder;
|
|
49
54
|
}
|
|
50
55
|
|
|
@@ -2,6 +2,8 @@ import { CalendarDateTime, type DateValue, ZonedDateTime } from "@internationali
|
|
|
2
2
|
import type { DateMatcher, Granularity, TimeGranularity, TimeValue } from "../../shared/date/types.js";
|
|
3
3
|
type GetDefaultDateProps = {
|
|
4
4
|
defaultValue?: DateValue | DateValue[] | undefined;
|
|
5
|
+
minValue?: DateValue;
|
|
6
|
+
maxValue?: DateValue;
|
|
5
7
|
granularity?: Granularity;
|
|
6
8
|
};
|
|
7
9
|
type GetDefaultTimeProps = {
|
|
@@ -11,7 +13,7 @@ type GetDefaultTimeProps = {
|
|
|
11
13
|
/**
|
|
12
14
|
* A helper function used throughout the various date builders
|
|
13
15
|
* to generate a default `DateValue` using the `defaultValue`,
|
|
14
|
-
* `defaultPlaceholder`, and `granularity` props.
|
|
16
|
+
* `defaultPlaceholder`, `minValue`, `maxValue`, and `granularity` props.
|
|
15
17
|
*
|
|
16
18
|
* It's important to match the `DateValue` type being used
|
|
17
19
|
* elsewhere in the builder, so they behave according to the
|
|
@@ -10,7 +10,7 @@ const defaultTimeDefaults = {
|
|
|
10
10
|
/**
|
|
11
11
|
* A helper function used throughout the various date builders
|
|
12
12
|
* to generate a default `DateValue` using the `defaultValue`,
|
|
13
|
-
* `defaultPlaceholder`, and `granularity` props.
|
|
13
|
+
* `defaultPlaceholder`, `minValue`, `maxValue`, and `granularity` props.
|
|
14
14
|
*
|
|
15
15
|
* It's important to match the `DateValue` type being used
|
|
16
16
|
* elsewhere in the builder, so they behave according to the
|
|
@@ -19,7 +19,7 @@ const defaultTimeDefaults = {
|
|
|
19
19
|
*/
|
|
20
20
|
export function getDefaultDate(opts) {
|
|
21
21
|
const withDefaults = { ...defaultDateDefaults, ...opts };
|
|
22
|
-
const { defaultValue, granularity } = withDefaults;
|
|
22
|
+
const { defaultValue, granularity, minValue, maxValue } = withDefaults;
|
|
23
23
|
if (Array.isArray(defaultValue) && defaultValue.length) {
|
|
24
24
|
return defaultValue[defaultValue.length - 1];
|
|
25
25
|
}
|
|
@@ -27,7 +27,13 @@ export function getDefaultDate(opts) {
|
|
|
27
27
|
return defaultValue;
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
30
|
-
|
|
30
|
+
let date = new Date();
|
|
31
|
+
if (minValue && date < minValue.toDate(getLocalTimeZone())) {
|
|
32
|
+
date = minValue.toDate(getLocalTimeZone());
|
|
33
|
+
}
|
|
34
|
+
else if (maxValue && date > maxValue.toDate(getLocalTimeZone())) {
|
|
35
|
+
date = maxValue.toDate(getLocalTimeZone());
|
|
36
|
+
}
|
|
31
37
|
const year = date.getFullYear();
|
|
32
38
|
const month = date.getMonth() + 1;
|
|
33
39
|
const day = date.getDate();
|