compote-ui 0.52.3 → 0.52.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.
@@ -1,13 +1,13 @@
1
1
  <script lang="ts">
2
2
  import { DateInput } from '@ark-ui/svelte/date-input';
3
3
  import { Field } from '@ark-ui/svelte/field';
4
- import { useLocaleContext } from '@ark-ui/svelte/locale';
5
4
  import {
6
5
  fromDateToLocal,
7
6
  getLocalTimeZone,
8
- parseAbsoluteToLocal,
7
+ parseAbsolute,
9
8
  parseDate,
10
- parseDateTime
9
+ parseDateTime,
10
+ parseZonedDateTime
11
11
  } from '@internationalized/date';
12
12
  import type { DateValue, DateInputProps, NativeDateInput } from './types';
13
13
 
@@ -20,14 +20,16 @@
20
20
  ...restProps
21
21
  }: DateInputProps = $props();
22
22
 
23
- const locale = useLocaleContext();
23
+ const absoluteDateTimeRe = /(?:Z|[+-]\d{2}:\d{2})$/;
24
24
 
25
25
  function toDateValue(v: NativeDateInput): DateValue | null {
26
26
  if (v == null) return null;
27
27
  if (typeof v === 'string') {
28
28
  if (!v) return null;
29
29
  if (v.includes('T')) {
30
- if (v.endsWith('Z') || /[+-]\d{2}:\d{2}$/.test(v)) return parseAbsoluteToLocal(v);
30
+ // ZonedDateTime.toString() format: "2024-01-15T10:30:00+02:00[Europe/Belgrade]"
31
+ if (v.includes('[')) return parseZonedDateTime(v);
32
+ if (absoluteDateTimeRe.test(v)) return parseAbsolute(v, 'UTC');
31
33
  return parseDateTime(v);
32
34
  }
33
35
  return parseDate(v);
@@ -38,7 +40,10 @@
38
40
 
39
41
  function fromDateValue(dv: DateValue | null, source: NativeDateInput): NativeDateInput {
40
42
  if (dv == null) return null;
41
- if (typeof source === 'string') return dv.toString();
43
+ if (typeof source === 'string') {
44
+ if (absoluteDateTimeRe.test(source)) return dv.toDate('UTC').toISOString();
45
+ return dv.toString();
46
+ }
42
47
  if (source instanceof Date) return dv.toDate(getLocalTimeZone());
43
48
  return dv;
44
49
  }
@@ -49,11 +54,12 @@
49
54
 
50
55
  <DateInput.Root
51
56
  {...restProps}
52
- locale={locale().locale}
53
57
  value={arkValue ? [arkValue] : []}
54
58
  defaultValue={arkDefault ? [arkDefault] : undefined}
55
59
  onValueChange={(details) => {
56
60
  const dv = details.value[0] ?? null;
61
+ // Guard: skip if Ark UI echoes back the same date (prevents reactive loop)
62
+ if (dv?.toString() === arkValue?.toString()) return;
57
63
  value = fromDateValue(dv, value);
58
64
  onValueChange?.(details);
59
65
  }}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "compote-ui",
3
- "version": "0.52.3",
3
+ "version": "0.52.4",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "dev": "vite dev --open",