compote-ui 0.52.3 → 0.52.5

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
 
@@ -16,18 +16,26 @@
16
16
  defaultValue,
17
17
  label,
18
18
  name,
19
+ timeZone = getLocalTimeZone(),
20
+ hideTimeZone,
19
21
  onValueChange,
20
22
  ...restProps
21
23
  }: DateInputProps = $props();
22
24
 
23
- const locale = useLocaleContext();
25
+ const absoluteDateTimeRe = /(?:Z|[+-]\d{2}:\d{2})$/;
26
+
27
+ function isAbsoluteDateTime(v: NativeDateInput): boolean {
28
+ return typeof v === 'string' && v.includes('T') && absoluteDateTimeRe.test(v);
29
+ }
24
30
 
25
31
  function toDateValue(v: NativeDateInput): DateValue | null {
26
32
  if (v == null) return null;
27
33
  if (typeof v === 'string') {
28
34
  if (!v) return null;
29
35
  if (v.includes('T')) {
30
- if (v.endsWith('Z') || /[+-]\d{2}:\d{2}$/.test(v)) return parseAbsoluteToLocal(v);
36
+ // ZonedDateTime.toString() format: "2024-01-15T10:30:00+02:00[Europe/Belgrade]"
37
+ if (v.includes('[')) return parseZonedDateTime(v);
38
+ if (absoluteDateTimeRe.test(v)) return parseAbsolute(v, timeZone);
31
39
  return parseDateTime(v);
32
40
  }
33
41
  return parseDate(v);
@@ -38,22 +46,29 @@
38
46
 
39
47
  function fromDateValue(dv: DateValue | null, source: NativeDateInput): NativeDateInput {
40
48
  if (dv == null) return null;
41
- if (typeof source === 'string') return dv.toString();
49
+ if (typeof source === 'string') {
50
+ if (absoluteDateTimeRe.test(source)) return dv.toDate(timeZone).toISOString();
51
+ return dv.toString();
52
+ }
42
53
  if (source instanceof Date) return dv.toDate(getLocalTimeZone());
43
54
  return dv;
44
55
  }
45
56
 
46
57
  const arkValue = $derived(toDateValue(value));
47
58
  const arkDefault = $derived(toDateValue(defaultValue));
59
+ const shouldHideTimeZone = $derived(hideTimeZone ?? isAbsoluteDateTime(value));
48
60
  </script>
49
61
 
50
62
  <DateInput.Root
51
63
  {...restProps}
52
- locale={locale().locale}
64
+ {timeZone}
65
+ hideTimeZone={shouldHideTimeZone}
53
66
  value={arkValue ? [arkValue] : []}
54
67
  defaultValue={arkDefault ? [arkDefault] : undefined}
55
68
  onValueChange={(details) => {
56
69
  const dv = details.value[0] ?? null;
70
+ // Guard: skip if Ark UI echoes back the same date (prevents reactive loop)
71
+ if (dv?.toString() === arkValue?.toString()) return;
57
72
  value = fromDateValue(dv, value);
58
73
  onValueChange?.(details);
59
74
  }}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "compote-ui",
3
- "version": "0.52.3",
3
+ "version": "0.52.5",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "dev": "vite dev --open",