compote-ui 0.52.2 → 0.52.3

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.
@@ -2,7 +2,14 @@
2
2
  import { DateInput } from '@ark-ui/svelte/date-input';
3
3
  import { Field } from '@ark-ui/svelte/field';
4
4
  import { useLocaleContext } from '@ark-ui/svelte/locale';
5
- import type { DateInputProps } from './types';
5
+ import {
6
+ fromDateToLocal,
7
+ getLocalTimeZone,
8
+ parseAbsoluteToLocal,
9
+ parseDate,
10
+ parseDateTime
11
+ } from '@internationalized/date';
12
+ import type { DateValue, DateInputProps, NativeDateInput } from './types';
6
13
 
7
14
  let {
8
15
  value = $bindable(),
@@ -14,15 +21,40 @@
14
21
  }: DateInputProps = $props();
15
22
 
16
23
  const locale = useLocaleContext();
24
+
25
+ function toDateValue(v: NativeDateInput): DateValue | null {
26
+ if (v == null) return null;
27
+ if (typeof v === 'string') {
28
+ if (!v) return null;
29
+ if (v.includes('T')) {
30
+ if (v.endsWith('Z') || /[+-]\d{2}:\d{2}$/.test(v)) return parseAbsoluteToLocal(v);
31
+ return parseDateTime(v);
32
+ }
33
+ return parseDate(v);
34
+ }
35
+ if (v instanceof Date) return fromDateToLocal(v);
36
+ return v;
37
+ }
38
+
39
+ function fromDateValue(dv: DateValue | null, source: NativeDateInput): NativeDateInput {
40
+ if (dv == null) return null;
41
+ if (typeof source === 'string') return dv.toString();
42
+ if (source instanceof Date) return dv.toDate(getLocalTimeZone());
43
+ return dv;
44
+ }
45
+
46
+ const arkValue = $derived(toDateValue(value));
47
+ const arkDefault = $derived(toDateValue(defaultValue));
17
48
  </script>
18
49
 
19
50
  <DateInput.Root
20
51
  {...restProps}
21
52
  locale={locale().locale}
22
- value={value ? [value] : []}
23
- defaultValue={defaultValue ? [defaultValue] : undefined}
53
+ value={arkValue ? [arkValue] : []}
54
+ defaultValue={arkDefault ? [arkDefault] : undefined}
24
55
  onValueChange={(details) => {
25
- value = details.value[0] ?? null;
56
+ const dv = details.value[0] ?? null;
57
+ value = fromDateValue(dv, value);
26
58
  onValueChange?.(details);
27
59
  }}
28
60
  >
@@ -1,8 +1,10 @@
1
1
  import type { DateInputRootBaseProps } from '@ark-ui/svelte/date-input';
2
2
  import type { DateInputDateValue as DateValue } from '@ark-ui/svelte/date-input';
3
+ export type { DateValue };
4
+ export type NativeDateInput = DateValue | string | Date | null | undefined;
3
5
  export interface DateInputProps extends Omit<DateInputRootBaseProps, 'value' | 'defaultValue'> {
4
- value?: DateValue | null;
5
- defaultValue?: DateValue;
6
+ value?: NativeDateInput;
7
+ defaultValue?: NativeDateInput;
6
8
  label?: string;
7
9
  name?: string;
8
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "compote-ui",
3
- "version": "0.52.2",
3
+ "version": "0.52.3",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "dev": "vite dev --open",