@sia.soul/sia-react-ui 0.1.159 → 0.1.162

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.
Files changed (41) hide show
  1. package/dist/{Select-DIdEbGwf.d.cts → Select-Dxevc0f6.d.cts} +1 -1
  2. package/dist/{Select-BCVUoK0I.d.ts → Select-tsENCXQI.d.ts} +1 -1
  3. package/dist/chart.cjs +9 -9
  4. package/dist/chart.js +5 -5
  5. package/dist/{chunk-6PIZGTNT.js → chunk-33WX54AU.js} +5 -5
  6. package/dist/{chunk-PU2V3VB5.js → chunk-4B7ATL6J.js} +1 -1
  7. package/dist/{chunk-XXFYFLZA.js → chunk-5WZR2RHA.js} +2 -2
  8. package/dist/{chunk-YO5OJQEH.js → chunk-CRA7VNOA.js} +1 -1
  9. package/dist/{chunk-ZIH5VLPT.js → chunk-KA3M4TE4.js} +2 -2
  10. package/dist/{chunk-6SSZVJO4.js → chunk-M4IASLGB.js} +3 -3
  11. package/dist/{chunk-UGCKRFZN.js → chunk-MXK6TKMO.js} +5 -5
  12. package/dist/{chunk-CDMCXNRK.js → chunk-Q3LEK2TL.js} +599 -270
  13. package/dist/{chunk-NRLIOMXY.js → chunk-UL54A2YN.js} +2 -2
  14. package/dist/{chunk-4CFFAKIJ.js → chunk-UPXL2QLJ.js} +6 -6
  15. package/dist/{chunk-SRWUDTCS.js → chunk-WMZYYPIW.js} +9 -9
  16. package/dist/{chunk-PJCO6PPW.js → chunk-ZNPNZD6O.js} +30 -15
  17. package/dist/{core-sU1bV7QH.d.ts → core-XtqUDbbD.d.ts} +5 -5
  18. package/dist/{core-B26pkBp_.d.cts → core-r-smfiNN.d.cts} +5 -5
  19. package/dist/core.cjs +27 -13
  20. package/dist/core.css +170 -22
  21. package/dist/core.d.cts +2 -2
  22. package/dist/core.d.ts +2 -2
  23. package/dist/core.js +8 -8
  24. package/dist/game.cjs +9 -9
  25. package/dist/game.js +3 -3
  26. package/dist/index.cjs +664 -320
  27. package/dist/index.css +170 -22
  28. package/dist/index.d.cts +13 -8
  29. package/dist/index.d.ts +13 -8
  30. package/dist/index.js +60 -59
  31. package/dist/markdown-editor.cjs +9 -9
  32. package/dist/markdown-editor.js +3 -3
  33. package/dist/rich-text-editor.cjs +40 -13
  34. package/dist/rich-text-editor.js +7 -7
  35. package/dist/{select-date-range-DYrA87Tl.d.ts → select-date-range-CIXBuoef.d.ts} +8 -9
  36. package/dist/{select-date-range-CIwE5nFu.d.cts → select-date-range-Cbh37zmU.d.cts} +8 -9
  37. package/dist/select-date-range.cjs +598 -269
  38. package/dist/select-date-range.d.cts +2 -2
  39. package/dist/select-date-range.d.ts +2 -2
  40. package/dist/select-date-range.js +8 -8
  41. package/package.json +1 -1
@@ -1,26 +1,26 @@
1
1
  import {
2
2
  Select
3
- } from "./chunk-UGCKRFZN.js";
3
+ } from "./chunk-MXK6TKMO.js";
4
4
  import {
5
5
  Icon
6
- } from "./chunk-ZIH5VLPT.js";
6
+ } from "./chunk-KA3M4TE4.js";
7
7
  import {
8
8
  useFloatingPlaceholder
9
- } from "./chunk-YO5OJQEH.js";
9
+ } from "./chunk-CRA7VNOA.js";
10
10
  import {
11
11
  FloatingScrollbarProvider,
12
12
  PopupPortal,
13
13
  useControlSize,
14
14
  useControllableState,
15
15
  withTitleTooltip
16
- } from "./chunk-SRWUDTCS.js";
16
+ } from "./chunk-WMZYYPIW.js";
17
17
 
18
18
  // src/components/DatePicker.tsx
19
- import { useEffect, useId, useLayoutEffect as useLayoutEffect2, useMemo, useRef as useRef2, useState } from "react";
19
+ import { useEffect as useEffect2, useId, useLayoutEffect as useLayoutEffect2, useMemo, useRef as useRef2, useState } from "react";
20
20
 
21
21
  // src/components/DatePickerPanel.tsx
22
- import { useLayoutEffect, useRef } from "react";
23
- import { jsx, jsxs } from "react/jsx-runtime";
22
+ import { useEffect, useLayoutEffect, useRef } from "react";
23
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
24
24
  function pad(value) {
25
25
  return String(value).padStart(2, "0");
26
26
  }
@@ -75,8 +75,51 @@ function CalendarMonth({
75
75
  previewEnd,
76
76
  disabledDate,
77
77
  onSelect,
78
- onHover
78
+ onHover,
79
+ onSwipeMonth
79
80
  }) {
81
+ const monthRef = useRef(null);
82
+ const swipe = useRef({ startX: 0, startY: 0, pointerId: -1, dragging: false, lastTime: 0, lastX: 0, velocity: 0 });
83
+ function onMonthPointerDown(event) {
84
+ if (!onSwipeMonth || event.button !== 0) return;
85
+ swipe.current = { startX: event.clientX, startY: event.clientY, pointerId: event.pointerId, dragging: false, lastTime: event.timeStamp, lastX: event.clientX, velocity: 0 };
86
+ }
87
+ function onMonthPointerMove(event) {
88
+ const state = swipe.current;
89
+ if (!onSwipeMonth || state.pointerId !== event.pointerId || !monthRef.current) return;
90
+ const dx = event.clientX - state.startX;
91
+ const dy = event.clientY - state.startY;
92
+ if (!state.dragging && Math.abs(dx) > 6 && Math.abs(dx) > Math.abs(dy)) {
93
+ state.dragging = true;
94
+ try {
95
+ monthRef.current?.setPointerCapture(event.pointerId);
96
+ } catch {
97
+ }
98
+ }
99
+ if (!state.dragging) return;
100
+ monthRef.current.style.transition = "none";
101
+ monthRef.current.style.transform = `translateX(${dx}px)`;
102
+ const dt = event.timeStamp - state.lastTime;
103
+ if (dt > 0) state.velocity = (event.clientX - state.lastX) / dt;
104
+ state.lastTime = event.timeStamp;
105
+ state.lastX = event.clientX;
106
+ }
107
+ function onMonthPointerUp(event) {
108
+ const state = swipe.current;
109
+ const node = monthRef.current;
110
+ if (state.pointerId !== event.pointerId || !node) return;
111
+ state.pointerId = -1;
112
+ try {
113
+ node.releasePointerCapture?.(event.pointerId);
114
+ } catch {
115
+ }
116
+ if (!state.dragging) return;
117
+ const dx = event.clientX - state.startX;
118
+ const shouldSwitch = Math.abs(dx) >= 56 || Math.abs(state.velocity) > 0.5;
119
+ if (shouldSwitch && onSwipeMonth) onSwipeMonth(dx < 0 ? 1 : -1);
120
+ node.style.transition = "transform 220ms cubic-bezier(.2, .7, .2, 1)";
121
+ node.style.transform = "translateX(0)";
122
+ }
80
123
  const first = startOfMonth(month);
81
124
  const mondayIndex = (first.getDay() + 6) % 7;
82
125
  const gridStart = addDays(first, -mondayIndex);
@@ -85,43 +128,61 @@ function CalendarMonth({
85
128
  const end = range[1] || previewEnd || "";
86
129
  const low = start && end ? start <= end ? start : end : "";
87
130
  const high = start && end ? start <= end ? end : start : "";
88
- return /* @__PURE__ */ jsxs("div", { className: "sia-date-panel__month", children: [
89
- /* @__PURE__ */ jsx("div", { className: "sia-date-panel__weekdays", "aria-hidden": "true", children: WEEKDAYS.map((day) => /* @__PURE__ */ jsx("span", { children: day }, day)) }),
90
- /* @__PURE__ */ jsx("div", { className: "sia-date-panel__days", children: Array.from({ length: 42 }, (_, index) => {
91
- const date = addDays(gridStart, index);
92
- const key = dateKey(date);
93
- const outside = date.getMonth() !== month.getMonth();
94
- const disabled = disabledDate?.(key) ?? false;
95
- const selected = selectedDates.includes(key);
96
- const rangeStart = Boolean(start && key === start);
97
- const rangeEnd = Boolean(range[1] && key === range[1]);
98
- const inRange = Boolean(low && high && key >= low && key <= high);
99
- return /* @__PURE__ */ jsx(
100
- "span",
101
- {
102
- className: `sia-date-panel__cell${outside ? " is-outside" : ""}${selected ? " is-selected" : ""}${rangeStart ? " is-range-start" : ""}${rangeEnd ? " is-range-end" : ""}${inRange ? " is-in-range" : ""}${key === today ? " is-today" : ""}`,
103
- children: /* @__PURE__ */ jsx(
104
- "button",
131
+ return /* @__PURE__ */ jsxs(
132
+ "div",
133
+ {
134
+ className: "sia-date-panel__month",
135
+ ref: monthRef,
136
+ onPointerDown: onMonthPointerDown,
137
+ onPointerMove: onMonthPointerMove,
138
+ onPointerUp: onMonthPointerUp,
139
+ onPointerCancel: onMonthPointerUp,
140
+ onClickCapture: (event) => {
141
+ if (!swipe.current.dragging) return;
142
+ event.preventDefault();
143
+ event.stopPropagation();
144
+ swipe.current.dragging = false;
145
+ },
146
+ children: [
147
+ /* @__PURE__ */ jsx("div", { className: "sia-date-panel__weekdays", "aria-hidden": "true", children: WEEKDAYS.map((day) => /* @__PURE__ */ jsx("span", { children: day }, day)) }),
148
+ /* @__PURE__ */ jsx("div", { className: "sia-date-panel__days", children: Array.from({ length: 42 }, (_, index) => {
149
+ const date = addDays(gridStart, index);
150
+ const key = dateKey(date);
151
+ const outside = date.getMonth() !== month.getMonth();
152
+ const disabled = disabledDate?.(key) ?? false;
153
+ const selected = selectedDates.includes(key);
154
+ const rangeStart = Boolean(start && key === start);
155
+ const rangeEnd = Boolean(range[1] && key === range[1]);
156
+ const inRange = Boolean(low && high && key >= low && key <= high);
157
+ return /* @__PURE__ */ jsx(
158
+ "span",
105
159
  {
106
- type: "button",
107
- "aria-label": key,
108
- "aria-pressed": selected || rangeStart || rangeEnd || void 0,
109
- disabled,
110
- onClick: () => onSelect(key),
111
- onMouseEnter: () => onHover?.(key),
112
- children: date.getDate()
113
- }
114
- )
115
- },
116
- key
117
- );
118
- }) })
119
- ] });
160
+ className: `sia-date-panel__cell${outside ? " is-outside" : ""}${selected ? " is-selected" : ""}${rangeStart ? " is-range-start" : ""}${rangeEnd ? " is-range-end" : ""}${inRange ? " is-in-range" : ""}${key === today ? " is-today" : ""}`,
161
+ children: /* @__PURE__ */ jsx(
162
+ "button",
163
+ {
164
+ type: "button",
165
+ "aria-label": key,
166
+ "aria-pressed": selected || rangeStart || rangeEnd || void 0,
167
+ disabled,
168
+ onClick: () => onSelect(key),
169
+ onMouseEnter: () => onHover?.(key),
170
+ children: date.getDate()
171
+ }
172
+ )
173
+ },
174
+ key
175
+ );
176
+ }) })
177
+ ]
178
+ }
179
+ );
120
180
  }
121
181
  function CalendarHeader({
122
182
  month,
123
183
  label,
124
184
  range = false,
185
+ onTitleClick,
125
186
  onPreviousYear,
126
187
  onPreviousMonth,
127
188
  onNextMonth,
@@ -135,7 +196,15 @@ function CalendarHeader({
135
196
  ] }) : null,
136
197
  onPreviousMonth ? /* @__PURE__ */ jsx("button", { type: "button", "aria-label": "\u4E0A\u4E2A\u6708", onClick: onPreviousMonth, children: /* @__PURE__ */ jsx(Icon, { name: "chevron-left", size: 15 }) }) : null
137
198
  ] }),
138
- /* @__PURE__ */ jsxs("strong", { children: [
199
+ onTitleClick ? /* @__PURE__ */ jsxs("button", { type: "button", className: "sia-date-panel__title", "aria-label": "\u9009\u62E9\u5E74\u4EFD", onClick: onTitleClick, children: [
200
+ label ? /* @__PURE__ */ jsx("small", { children: label }) : null,
201
+ /* @__PURE__ */ jsxs("span", { children: [
202
+ month.getFullYear(),
203
+ "\u5E74\xA0 ",
204
+ month.getMonth() + 1,
205
+ "\u6708"
206
+ ] })
207
+ ] }) : /* @__PURE__ */ jsxs("strong", { children: [
139
208
  label ? /* @__PURE__ */ jsx("small", { children: label }) : null,
140
209
  /* @__PURE__ */ jsxs("span", { children: [
141
210
  month.getFullYear(),
@@ -154,36 +223,146 @@ function CalendarHeader({
154
223
  range ? null : null
155
224
  ] });
156
225
  }
226
+ var TIME_OPTION_HEIGHT = 32;
227
+ var TIME_COLUMN_PADDING = 4;
228
+ function TimeColumn({
229
+ ariaLabel,
230
+ columnIndex,
231
+ count,
232
+ value,
233
+ siblings,
234
+ use12Hours = false,
235
+ unit = "",
236
+ unitLabels = false,
237
+ disabledTime,
238
+ onSelect
239
+ }) {
240
+ const listRef = useRef(null);
241
+ const drag = useRef({ startY: 0, startScroll: 0, pointerId: -1, dragging: false, samples: [], velocity: 0, frame: 0 });
242
+ useLayoutEffect(() => {
243
+ const column = listRef.current;
244
+ const selected = column?.querySelector('[aria-selected="true"]');
245
+ const first = column?.firstElementChild;
246
+ if (!column || !selected || !first) return;
247
+ const top = selected.offsetTop - first.offsetTop + parseFloat(getComputedStyle(column).paddingTop || "0");
248
+ const bottom = top + selected.offsetHeight;
249
+ if (top < column.scrollTop || bottom > column.scrollTop + column.clientHeight) {
250
+ column.scrollTop = Math.max(0, top - (column.clientHeight - selected.offsetHeight) / 2);
251
+ }
252
+ }, [value, count]);
253
+ useEffect(() => () => cancelAnimationFrame(drag.current.frame), []);
254
+ function stopWithSnap() {
255
+ const column = listRef.current;
256
+ if (!column) return;
257
+ const snapped = Math.round((column.scrollTop - TIME_COLUMN_PADDING) / TIME_OPTION_HEIGHT) * TIME_OPTION_HEIGHT + TIME_COLUMN_PADDING;
258
+ const max = column.scrollHeight - column.clientHeight;
259
+ column.scrollTo({ top: Math.max(0, Math.min(max, snapped)), behavior: "smooth" });
260
+ }
261
+ function onPointerDown(event) {
262
+ if (event.button !== 0) return;
263
+ const column = listRef.current;
264
+ if (!column) return;
265
+ drag.current = { startY: event.clientY, startScroll: column.scrollTop, pointerId: event.pointerId, dragging: false, samples: [event.timeStamp, event.clientY], velocity: 0, frame: 0 };
266
+ }
267
+ function onPointerMove(event) {
268
+ const state = drag.current;
269
+ const column = listRef.current;
270
+ if (state.pointerId !== event.pointerId || !column) return;
271
+ const dy = event.clientY - state.startY;
272
+ if (!state.dragging && Math.abs(dy) > 4) {
273
+ state.dragging = true;
274
+ try {
275
+ column.setPointerCapture(event.pointerId);
276
+ } catch {
277
+ }
278
+ }
279
+ if (!state.dragging) return;
280
+ column.scrollTop = state.startScroll - dy;
281
+ state.samples.push(event.timeStamp, event.clientY);
282
+ while (state.samples.length > 4 && event.timeStamp - state.samples[0] > 100) state.samples.splice(0, 2);
283
+ }
284
+ function onPointerUp(event) {
285
+ const state = drag.current;
286
+ const column = listRef.current;
287
+ if (state.pointerId !== event.pointerId || !column) return;
288
+ state.pointerId = -1;
289
+ try {
290
+ column.releasePointerCapture?.(event.pointerId);
291
+ } catch {
292
+ }
293
+ if (!state.dragging) return;
294
+ const samples = state.samples;
295
+ const dt = samples[samples.length - 2] - samples[0];
296
+ const dy = samples[samples.length - 1] - samples[1];
297
+ let velocity = dt > 4 ? dy / dt : 0;
298
+ velocity = Math.max(-2.5, Math.min(2.5, velocity));
299
+ cancelAnimationFrame(state.frame);
300
+ let last = performance.now();
301
+ const step = (now) => {
302
+ const elapsed = Math.min(32, now - last);
303
+ last = now;
304
+ column.scrollTop -= velocity * elapsed;
305
+ velocity *= Math.pow(0.94, elapsed / 16.7);
306
+ if (Math.abs(velocity) > 0.04) state.frame = requestAnimationFrame(step);
307
+ else stopWithSnap();
308
+ };
309
+ state.frame = requestAnimationFrame(step);
310
+ }
311
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
312
+ /* @__PURE__ */ jsx(
313
+ "div",
314
+ {
315
+ ref: listRef,
316
+ role: "listbox",
317
+ "aria-label": ariaLabel,
318
+ onPointerDown,
319
+ onPointerMove,
320
+ onPointerUp,
321
+ onPointerCancel: onPointerUp,
322
+ onClickCapture: (event) => {
323
+ if (!drag.current.dragging) return;
324
+ event.preventDefault();
325
+ event.stopPropagation();
326
+ drag.current.dragging = false;
327
+ },
328
+ children: Array.from({ length: count }, (_, index) => {
329
+ const next = pad(index);
330
+ const candidate = [...siblings];
331
+ candidate[columnIndex] = next;
332
+ const selected = next === value;
333
+ return /* @__PURE__ */ jsxs("button", { type: "button", role: "option", disabled: disabledTime?.(candidate.join(":")), "aria-selected": selected, className: selected ? "is-selected" : "", onKeyDown: (event) => {
334
+ if (!["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) return;
335
+ event.preventDefault();
336
+ const buttons = Array.from(event.currentTarget.parentElement.querySelectorAll("button:not(:disabled)"));
337
+ const position = buttons.indexOf(event.currentTarget);
338
+ const target = event.key === "Home" ? 0 : event.key === "End" ? buttons.length - 1 : Math.max(0, Math.min(buttons.length - 1, position + (event.key === "ArrowDown" ? 1 : -1)));
339
+ buttons[target]?.focus();
340
+ }, onClick: () => onSelect(next), children: [
341
+ use12Hours && columnIndex === 0 ? `${pad(index % 12 || 12)} ${index < 12 ? "AM" : "PM"}` : next,
342
+ unitLabels && selected ? unit : ""
343
+ ] }, next);
344
+ })
345
+ }
346
+ ),
347
+ /* @__PURE__ */ jsx(FloatingScrollbarProvider, { targetRef: listRef })
348
+ ] });
349
+ }
157
350
  function TimePanel({
158
351
  value,
159
352
  showSecond = false,
160
353
  ariaLabel = "\u65F6\u95F4",
161
354
  disabledTime,
162
355
  use12Hours = false,
356
+ title,
357
+ unitLabels = false,
163
358
  onChange
164
359
  }) {
165
360
  const [hour = "00", minute = "00", second = "00"] = value.split(":");
166
- const columnsRef = useRef(null);
167
- const hourRef = useRef(null);
168
- const minuteRef = useRef(null);
169
- const secondRef = useRef(null);
170
- const columnRefs = [hourRef, minuteRef, secondRef];
171
- useLayoutEffect(() => {
172
- for (const column of columnsRef.current?.children ?? []) {
173
- const selected = column.querySelector('[aria-selected="true"]');
174
- const first = column.firstElementChild;
175
- if (!selected || !first) continue;
176
- const top = selected.offsetTop - first.offsetTop + parseFloat(getComputedStyle(column).paddingTop || "0");
177
- const bottom = top + selected.offsetHeight;
178
- if (top < column.scrollTop || bottom > column.scrollTop + column.clientHeight) {
179
- column.scrollTop = Math.max(0, top - (column.clientHeight - selected.offsetHeight) / 2);
180
- }
181
- }
182
- }, [hour, minute, second, showSecond, ariaLabel]);
361
+ const siblings = [hour, minute, second];
183
362
  const columns = [
184
- { label: "\u5C0F\u65F6", value: hour, count: 24, index: 0 },
185
- { label: "\u5206\u949F", value: minute, count: 60, index: 1 },
186
- ...showSecond ? [{ label: "\u79D2", value: second, count: 60, index: 2 }] : []
363
+ { label: "\u5C0F\u65F6", unit: "\u65F6", value: hour, count: 24, index: 0 },
364
+ { label: "\u5206\u949F", unit: "\u5206", value: minute, count: 60, index: 1 },
365
+ ...showSecond ? [{ label: "\u79D2", unit: "\u79D2", value: second, count: 60, index: 2 }] : []
187
366
  ];
188
367
  function update(index, next) {
189
368
  const values = [hour, minute, second];
@@ -191,27 +370,29 @@ function TimePanel({
191
370
  onChange(values.join(":"));
192
371
  }
193
372
  return /* @__PURE__ */ jsxs("aside", { className: "sia-date-panel__time", "aria-label": ariaLabel, children: [
194
- /* @__PURE__ */ jsxs("strong", { children: [
373
+ title != null ? /* @__PURE__ */ jsx("strong", { className: "sia-date-panel__time-title", children: title }) : /* @__PURE__ */ jsxs("strong", { children: [
195
374
  use12Hours ? pad(Number(hour) % 12 || 12) : hour,
196
375
  ":",
197
376
  minute,
198
377
  showSecond ? `:${second}` : "",
199
378
  use12Hours ? Number(hour) < 12 ? " AM" : " PM" : ""
200
379
  ] }),
201
- /* @__PURE__ */ jsx("div", { ref: columnsRef, className: "sia-date-panel__time-columns", children: columns.map((column) => /* @__PURE__ */ jsx("div", { ref: columnRefs[column.index], role: "listbox", "aria-label": `${ariaLabel}${column.label}`, children: Array.from({ length: column.count }, (_, index) => {
202
- const next = pad(index);
203
- const candidate = [hour, minute, second];
204
- candidate[column.index] = next;
205
- return /* @__PURE__ */ jsx("button", { type: "button", role: "option", disabled: disabledTime?.(candidate.join(":")), "aria-selected": next === column.value, className: next === column.value ? "is-selected" : "", onKeyDown: (event) => {
206
- if (!["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) return;
207
- event.preventDefault();
208
- const buttons = Array.from(event.currentTarget.parentElement.querySelectorAll("button:not(:disabled)"));
209
- const position = buttons.indexOf(event.currentTarget);
210
- const target = event.key === "Home" ? 0 : event.key === "End" ? buttons.length - 1 : Math.max(0, Math.min(buttons.length - 1, position + (event.key === "ArrowDown" ? 1 : -1)));
211
- buttons[target]?.focus();
212
- }, onClick: () => update(column.index, next), children: use12Hours && column.index === 0 ? `${pad(index % 12 || 12)} ${index < 12 ? "AM" : "PM"}` : next }, next);
213
- }) }, column.label)) }),
214
- columns.map((column) => /* @__PURE__ */ jsx(FloatingScrollbarProvider, { targetRef: columnRefs[column.index] }, column.index))
380
+ /* @__PURE__ */ jsx("div", { className: "sia-date-panel__time-columns", children: columns.map((column) => /* @__PURE__ */ jsx(
381
+ TimeColumn,
382
+ {
383
+ ariaLabel: `${ariaLabel}${column.label}`,
384
+ columnIndex: column.index,
385
+ count: column.count,
386
+ value: column.value,
387
+ siblings,
388
+ use12Hours,
389
+ unit: column.unit,
390
+ unitLabels,
391
+ disabledTime,
392
+ onSelect: (next) => update(column.index, next)
393
+ },
394
+ column.label
395
+ )) })
215
396
  ] });
216
397
  }
217
398
  function DatePanelFooter({
@@ -231,9 +412,53 @@ function DatePanelFooter({
231
412
  needConfirm ? /* @__PURE__ */ jsx("button", { type: "button", className: "sia-date-panel__confirm", disabled: disabledConfirm, onClick: onConfirm, children: confirmText }) : null
232
413
  ] });
233
414
  }
415
+ function DateTimePanelFooter({
416
+ date,
417
+ time,
418
+ view,
419
+ disabled = false,
420
+ extra,
421
+ onSwitchDate,
422
+ onSwitchTime,
423
+ onClearTime
424
+ }) {
425
+ return /* @__PURE__ */ jsxs("footer", { className: "sia-date-panel__footer sia-date-panel__footer--datetime", children: [
426
+ /* @__PURE__ */ jsxs("span", { children: [
427
+ /* @__PURE__ */ jsxs("button", { type: "button", className: "sia-date-panel__chip", "aria-pressed": view === "date" || void 0, disabled, onClick: onSwitchDate, children: [
428
+ /* @__PURE__ */ jsx(Icon, { name: "calendar", size: 14, "aria-hidden": "true" }),
429
+ date
430
+ ] }),
431
+ extra
432
+ ] }),
433
+ /* @__PURE__ */ jsxs("button", { type: "button", className: `sia-date-panel__chip sia-date-panel__chip--time${onClearTime ? " is-clearable" : ""}`, "aria-pressed": view === "time" || void 0, disabled, onClick: onSwitchTime, children: [
434
+ /* @__PURE__ */ jsx(Icon, { name: "clock", size: 14, "aria-hidden": "true" }),
435
+ time,
436
+ onClearTime && !disabled ? /* @__PURE__ */ jsx(
437
+ "span",
438
+ {
439
+ role: "button",
440
+ tabIndex: 0,
441
+ "aria-label": "\u6E05\u7A7A\u65F6\u95F4",
442
+ className: "sia-date-panel__chip-clear",
443
+ onClick: (event) => {
444
+ event.stopPropagation();
445
+ onClearTime();
446
+ },
447
+ onKeyDown: (event) => {
448
+ if (event.key !== "Enter" && event.key !== " ") return;
449
+ event.preventDefault();
450
+ event.stopPropagation();
451
+ onClearTime();
452
+ },
453
+ children: /* @__PURE__ */ jsx(Icon, { name: "circle-close", variant: "filled", size: 13, "aria-hidden": "true" })
454
+ }
455
+ ) : null
456
+ ] })
457
+ ] });
458
+ }
234
459
 
235
460
  // src/components/DatePicker.tsx
236
- import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
461
+ import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
237
462
  function formatWeek(date) {
238
463
  const target = new Date(date);
239
464
  target.setHours(0, 0, 0, 0);
@@ -280,6 +505,12 @@ function resolvePreset(value) {
280
505
  function resolveRangePreset(value) {
281
506
  return typeof value === "function" ? value() : value;
282
507
  }
508
+ function hasExplicitTime(value) {
509
+ return /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}/.test(String(value ?? ""));
510
+ }
511
+ function isZeroTime(time, showSecond) {
512
+ return showSecond ? time === "00:00:00" : time.slice(0, 5) === "00:00";
513
+ }
283
514
  function DatePicker({
284
515
  value,
285
516
  defaultValue,
@@ -319,13 +550,17 @@ function DatePicker({
319
550
  const firstCurrent = Array.isArray(currentValue) ? currentValue[0] : currentValue;
320
551
  const [viewMonth, setViewMonth] = useState(() => startOfMonth(parseDate(dayFromValue(firstCurrent)) ?? /* @__PURE__ */ new Date()));
321
552
  const [draftTime, setDraftTime] = useState(() => timePart(firstCurrent, defaultTimeFrom(showTime)));
322
- const resolvedNeedConfirm = needConfirm ?? Boolean(showTime);
553
+ const showTimeDefaultProvided = typeof showTime === "object" && showTime.defaultValue !== void 0;
554
+ const [timeExplicit, setTimeExplicit] = useState(() => showTimeDefaultProvided || hasExplicitTime(typeof initialValue === "string" ? initialValue : void 0));
555
+ const [dateTimeView, setDateTimeView] = useState("date");
556
+ const [yearDrill, setYearDrill] = useState(false);
557
+ const resolvedNeedConfirm = showTime ? false : Boolean(needConfirm);
323
558
  const showSecond = showSecondFrom(showTime);
324
559
  const selectedDates = useMemo(() => {
325
560
  const values = Array.isArray(draftValue) ? draftValue : draftValue ? [draftValue] : [];
326
561
  return values.map(dayFromValue).filter(Boolean);
327
562
  }, [draftValue]);
328
- useEffect(() => {
563
+ useEffect2(() => {
329
564
  if (!visible) return void 0;
330
565
  const close = (event) => {
331
566
  const target = event.target;
@@ -340,6 +575,9 @@ function DatePicker({
340
575
  const current = Array.isArray(currentValue) ? currentValue[0] : currentValue;
341
576
  setViewMonth(startOfMonth(parseDate(dayFromValue(current)) ?? /* @__PURE__ */ new Date()));
342
577
  setDraftTime(timePart(current, defaultTimeFrom(showTime)));
578
+ setTimeExplicit(showTimeDefaultProvided || hasExplicitTime(typeof current === "string" ? current : void 0));
579
+ setDateTimeView("date");
580
+ setYearDrill(false);
343
581
  }
344
582
  setVisible(next);
345
583
  }
@@ -351,9 +589,11 @@ function DatePicker({
351
589
  if (maximum && day.slice(0, length) > String(maximum).slice(0, length)) return true;
352
590
  return disabledDate?.(day, { type: "date" }) ?? false;
353
591
  }
354
- function buildValue(day, time = draftTime) {
592
+ function buildValue(day, time = draftTime, explicit = timeExplicit) {
355
593
  const picked = formatPickerValue(day, picker);
356
- return showTime && picker === "date" ? withTime(picked, time, showSecond) : picked;
594
+ if (!(showTime && picker === "date")) return picked;
595
+ if (!explicit && isZeroTime(time, showSecond)) return picked;
596
+ return withTime(picked, time, showSecond);
357
597
  }
358
598
  function selectDate(day, time = draftTime, ensureSelected = false) {
359
599
  if (isDisabled(day)) return;
@@ -369,7 +609,7 @@ function DatePicker({
369
609
  setDraftValue(nextValue);
370
610
  if (!resolvedNeedConfirm) {
371
611
  setCurrentValue(nextValue);
372
- changeOpen(false);
612
+ if (!showTime) changeOpen(false);
373
613
  }
374
614
  }
375
615
  function commitDraft() {
@@ -378,6 +618,72 @@ function DatePicker({
378
618
  setCurrentValue(draftValue);
379
619
  changeOpen(false);
380
620
  }
621
+ function applyDraftTime(next) {
622
+ setDraftTime(next);
623
+ setTimeExplicit(true);
624
+ const day = typeof draftValue === "string" ? dayFromValue(draftValue) : "";
625
+ if (!day) return;
626
+ const nextValue = withTime(day, next, showSecond);
627
+ setDraftValue(nextValue);
628
+ setCurrentValue(nextValue);
629
+ }
630
+ function clearDraftTime() {
631
+ setDraftTime("00:00:00");
632
+ setTimeExplicit(false);
633
+ const day = typeof draftValue === "string" ? dayFromValue(draftValue) : "";
634
+ if (!day) return;
635
+ setDraftValue(day);
636
+ setCurrentValue(day);
637
+ }
638
+ function renderCalendarSection() {
639
+ return picker === "year" || yearDrill ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
640
+ /* @__PURE__ */ jsxs2("div", { className: "sia-date-panel__header", children: [
641
+ /* @__PURE__ */ jsx2("span", { className: "sia-date-panel__nav", children: /* @__PURE__ */ jsx2("button", { type: "button", "aria-label": "\u4E0A\u5341\u5E74", onClick: () => setViewMonth(addMonths(viewMonth, -120)), children: /* @__PURE__ */ jsx2(Icon, { name: "chevron-left", size: 15 }) }) }),
642
+ /* @__PURE__ */ jsxs2("strong", { children: [
643
+ Math.floor(viewMonth.getFullYear() / 10) * 10,
644
+ "\u5E74 \u2014 ",
645
+ Math.floor(viewMonth.getFullYear() / 10) * 10 + 9,
646
+ "\u5E74"
647
+ ] }),
648
+ /* @__PURE__ */ jsx2("span", { className: "sia-date-panel__nav", children: /* @__PURE__ */ jsx2("button", { type: "button", "aria-label": "\u4E0B\u5341\u5E74", onClick: () => setViewMonth(addMonths(viewMonth, 120)), children: /* @__PURE__ */ jsx2(Icon, { name: "chevron-right", size: 15 }) }) })
649
+ ] }),
650
+ /* @__PURE__ */ jsx2("div", { className: "sia-date-panel__years", children: Array.from({ length: 10 }, (_, index) => {
651
+ const year = String(Math.floor(viewMonth.getFullYear() / 10) * 10 + index);
652
+ const day = `${year}-01-01`;
653
+ const selected = selectedDates.some((value2) => value2.slice(0, 4) === year);
654
+ return /* @__PURE__ */ jsx2("span", { className: `sia-date-panel__cell${selected ? " is-selected" : ""}${year === String((/* @__PURE__ */ new Date()).getFullYear()) ? " is-today" : ""}`, children: /* @__PURE__ */ jsx2("button", { type: "button", "aria-label": `${year}\u5E74`, "aria-pressed": selected, disabled: isDisabled(day), onClick: () => {
655
+ if (yearDrill) {
656
+ setViewMonth(new Date(Number(year), viewMonth.getMonth(), 1));
657
+ setYearDrill(false);
658
+ } else {
659
+ selectDate(day);
660
+ }
661
+ }, children: year }) }, year);
662
+ }) })
663
+ ] }) : /* @__PURE__ */ jsxs2(Fragment2, { children: [
664
+ /* @__PURE__ */ jsx2(
665
+ CalendarHeader,
666
+ {
667
+ month: viewMonth,
668
+ onTitleClick: picker === "date" ? () => setYearDrill(true) : void 0,
669
+ onPreviousYear: () => setViewMonth(addMonths(viewMonth, -12)),
670
+ onPreviousMonth: () => setViewMonth(addMonths(viewMonth, -1)),
671
+ onNextMonth: () => setViewMonth(addMonths(viewMonth, 1)),
672
+ onNextYear: () => setViewMonth(addMonths(viewMonth, 12))
673
+ }
674
+ ),
675
+ /* @__PURE__ */ jsx2(
676
+ CalendarMonth,
677
+ {
678
+ month: viewMonth,
679
+ selectedDates,
680
+ disabledDate: isDisabled,
681
+ onSelect: selectDate,
682
+ onSwipeMonth: picker === "date" ? (direction) => setViewMonth(addMonths(viewMonth, direction)) : void 0
683
+ }
684
+ )
685
+ ] });
686
+ }
381
687
  function clearValue(event) {
382
688
  event.stopPropagation();
383
689
  const empty = multiple ? [] : "";
@@ -417,72 +723,82 @@ function DatePicker({
417
723
  ),
418
724
  floating.label,
419
725
  allowClear && display && !disabled ? /* @__PURE__ */ jsx2("button", { type: "button", className: "sia-picker__clear", "aria-label": "\u6E05\u9664\u65E5\u671F", onClick: clearValue, children: /* @__PURE__ */ jsx2(Icon, { name: "circle-close", variant: "filled", size: 15 }) }) : null,
420
- /* @__PURE__ */ jsxs2(PopupPortal, { ref: popupRef, anchorRef: rootRef, open: visible, className: `sia-date-panel${showTime ? " sia-date-panel--with-time" : ""}${presets?.length ? " sia-date-panel--with-presets" : ""}`, role: "dialog", "aria-label": "\u65E5\u671F\u9009\u62E9\u9762\u677F", children: [
421
- /* @__PURE__ */ jsxs2("div", { className: "sia-date-panel__body", children: [
422
- presets?.length ? /* @__PURE__ */ jsx2("aside", { className: "sia-date-panel__presets", children: presets.map((preset, index) => /* @__PURE__ */ jsx2("button", { type: "button", onClick: () => {
423
- const next = resolvePreset(preset.value);
424
- if (!next || isDisabled(dayFromValue(next))) return;
425
- setDraftValue(next);
426
- if (!resolvedNeedConfirm) {
427
- setCurrentValue(next);
726
+ /* @__PURE__ */ jsxs2(
727
+ PopupPortal,
728
+ {
729
+ ref: popupRef,
730
+ anchorRef: rootRef,
731
+ open: visible,
732
+ className: `sia-date-panel${showTime ? " sia-date-panel--datetime" : ""}${presets?.length ? " sia-date-panel--with-presets" : ""}`,
733
+ role: "dialog",
734
+ "aria-label": "\u65E5\u671F\u9009\u62E9\u9762\u677F",
735
+ onKeyDown: (event) => {
736
+ if (event.key === "Escape") {
737
+ event.stopPropagation();
428
738
  changeOpen(false);
429
739
  }
430
- }, children: preset.label }, index)) }) : null,
431
- /* @__PURE__ */ jsx2("section", { className: "sia-date-panel__calendar", children: picker === "year" ? /* @__PURE__ */ jsxs2(Fragment, { children: [
432
- /* @__PURE__ */ jsxs2("div", { className: "sia-date-panel__header", children: [
433
- /* @__PURE__ */ jsx2("span", { className: "sia-date-panel__nav", children: /* @__PURE__ */ jsx2("button", { type: "button", "aria-label": "\u4E0A\u5341\u5E74", onClick: () => setViewMonth(addMonths(viewMonth, -120)), children: /* @__PURE__ */ jsx2(Icon, { name: "chevron-left", size: 15 }) }) }),
434
- /* @__PURE__ */ jsxs2("strong", { children: [
435
- Math.floor(viewMonth.getFullYear() / 10) * 10,
436
- "\u5E74 \u2014 ",
437
- Math.floor(viewMonth.getFullYear() / 10) * 10 + 9,
438
- "\u5E74"
439
- ] }),
440
- /* @__PURE__ */ jsx2("span", { className: "sia-date-panel__nav", children: /* @__PURE__ */ jsx2("button", { type: "button", "aria-label": "\u4E0B\u5341\u5E74", onClick: () => setViewMonth(addMonths(viewMonth, 120)), children: /* @__PURE__ */ jsx2(Icon, { name: "chevron-right", size: 15 }) }) })
740
+ },
741
+ children: [
742
+ /* @__PURE__ */ jsxs2("div", { className: "sia-date-panel__body", children: [
743
+ presets?.length ? /* @__PURE__ */ jsx2("aside", { className: "sia-date-panel__presets", children: presets.map((preset, index) => /* @__PURE__ */ jsx2("button", { type: "button", onClick: () => {
744
+ const next = resolvePreset(preset.value);
745
+ if (!next || isDisabled(dayFromValue(next))) return;
746
+ setDraftValue(next);
747
+ setDraftTime(timePart(next, defaultTimeFrom(showTime)));
748
+ setTimeExplicit(hasExplicitTime(next));
749
+ if (!resolvedNeedConfirm) {
750
+ setCurrentValue(next);
751
+ changeOpen(false);
752
+ }
753
+ }, children: preset.label }, index)) }) : null,
754
+ showTime ? /* @__PURE__ */ jsxs2("div", { className: "sia-date-panel__views", children: [
755
+ /* @__PURE__ */ jsx2("section", { className: `sia-date-panel__view sia-date-panel__view--date${dateTimeView === "date" ? " is-active" : ""}`, "aria-hidden": dateTimeView !== "date", children: renderCalendarSection() }),
756
+ /* @__PURE__ */ jsx2("div", { className: `sia-date-panel__view sia-date-panel__view--time${dateTimeView === "time" ? " is-active" : ""}`, "aria-hidden": dateTimeView !== "time", children: /* @__PURE__ */ jsx2(
757
+ TimePanel,
758
+ {
759
+ value: draftTime,
760
+ showSecond,
761
+ title: "\u9009\u62E9\u65F6\u95F4",
762
+ unitLabels: true,
763
+ ariaLabel: "\u9009\u62E9\u65F6\u95F4",
764
+ onChange: applyDraftTime
765
+ }
766
+ ) })
767
+ ] }) : /* @__PURE__ */ jsx2("section", { className: "sia-date-panel__calendar", children: renderCalendarSection() })
441
768
  ] }),
442
- /* @__PURE__ */ jsx2("div", { className: "sia-date-panel__years", children: Array.from({ length: 10 }, (_, index) => {
443
- const year = String(Math.floor(viewMonth.getFullYear() / 10) * 10 + index);
444
- const day = `${year}-01-01`;
445
- const selected = selectedDates.some((value2) => value2.slice(0, 4) === year);
446
- return /* @__PURE__ */ jsx2("span", { className: `sia-date-panel__cell${selected ? " is-selected" : ""}${year === String((/* @__PURE__ */ new Date()).getFullYear()) ? " is-today" : ""}`, children: /* @__PURE__ */ jsx2("button", { type: "button", "aria-label": `${year}\u5E74`, "aria-pressed": selected, disabled: isDisabled(day), onClick: () => selectDate(day), children: year }) }, year);
447
- }) })
448
- ] }) : /* @__PURE__ */ jsxs2(Fragment, { children: [
449
- /* @__PURE__ */ jsx2(
450
- CalendarHeader,
769
+ showTime ? /* @__PURE__ */ jsx2(
770
+ DateTimePanelFooter,
451
771
  {
452
- month: viewMonth,
453
- onPreviousYear: () => setViewMonth(addMonths(viewMonth, -12)),
454
- onPreviousMonth: () => setViewMonth(addMonths(viewMonth, -1)),
455
- onNextMonth: () => setViewMonth(addMonths(viewMonth, 1)),
456
- onNextYear: () => setViewMonth(addMonths(viewMonth, 12))
772
+ date: (typeof draftValue === "string" ? dayFromValue(draftValue) : "") || dateKey(/* @__PURE__ */ new Date()),
773
+ time: showSecond ? draftTime : draftTime.slice(0, 5),
774
+ view: dateTimeView,
775
+ extra: renderExtraFooter?.(),
776
+ onSwitchDate: () => setDateTimeView("date"),
777
+ onSwitchTime: () => setDateTimeView("time"),
778
+ onClearTime: clearDraftTime
457
779
  }
458
- ),
459
- /* @__PURE__ */ jsx2(CalendarMonth, { month: viewMonth, selectedDates, disabledDate: isDisabled, onSelect: selectDate })
460
- ] }) }),
461
- showTime ? /* @__PURE__ */ jsx2(TimePanel, { value: draftTime, showSecond, onChange: (next) => {
462
- setDraftTime(next);
463
- if (typeof draftValue === "string" && draftValue) setDraftValue(withTime(dayFromValue(draftValue), next, showSecond));
464
- } }) : null
465
- ] }),
466
- /* @__PURE__ */ jsx2(
467
- DatePanelFooter,
468
- {
469
- extra: renderExtraFooter?.(),
470
- showToday,
471
- needConfirm: resolvedNeedConfirm,
472
- disabledConfirm: Array.isArray(draftValue) ? draftValue.length === 0 : !draftValue,
473
- onToday: () => {
474
- const now = /* @__PURE__ */ new Date();
475
- const day = dateKey(now);
476
- if (isDisabled(day)) return;
477
- const time = [now.getHours(), now.getMinutes(), now.getSeconds()].map(pad).join(":");
478
- if (showTime) setDraftTime(time);
479
- setViewMonth(startOfMonth(now));
480
- selectDate(day, time, true);
481
- },
482
- onConfirm: commitDraft
483
- }
484
- )
485
- ] })
780
+ ) : /* @__PURE__ */ jsx2(
781
+ DatePanelFooter,
782
+ {
783
+ extra: renderExtraFooter?.(),
784
+ showToday,
785
+ needConfirm: resolvedNeedConfirm,
786
+ disabledConfirm: Array.isArray(draftValue) ? draftValue.length === 0 : !draftValue,
787
+ onToday: () => {
788
+ const now = /* @__PURE__ */ new Date();
789
+ const day = dateKey(now);
790
+ if (isDisabled(day)) return;
791
+ const time = [now.getHours(), now.getMinutes(), now.getSeconds()].map(pad).join(":");
792
+ if (showTime) setDraftTime(time);
793
+ setViewMonth(startOfMonth(now));
794
+ selectDate(day, time, true);
795
+ },
796
+ onConfirm: commitDraft
797
+ }
798
+ )
799
+ ]
800
+ }
801
+ )
486
802
  ] });
487
803
  }
488
804
  function DateRangePicker({
@@ -542,8 +858,7 @@ function DateRangePicker({
542
858
  }
543
859
  return () => observer.disconnect();
544
860
  });
545
- const [confirmedIndex, setConfirmedIndex] = useState(null);
546
- const [presetSelected, setPresetSelected] = useState(false);
861
+ const [dateTimeView, setDateTimeView] = useState("date");
547
862
  const [hoverDate, setHoverDate] = useState("");
548
863
  const [viewMonth, setViewMonth] = useState(() => startOfMonth(parseDate(dayFromValue(currentValue[0] || currentValue[1])) ?? /* @__PURE__ */ new Date()));
549
864
  const [endViewMonth, setEndViewMonth] = useState(() => startOfMonth(parseDate(dayFromValue(currentValue[1])) ?? addMonths(parseDate(dayFromValue(currentValue[0])) ?? /* @__PURE__ */ new Date(), 1)));
@@ -554,10 +869,10 @@ function DateRangePicker({
554
869
  timePart(currentValue[0], defaultTime),
555
870
  timePart(currentValue[1], defaultEndTime)
556
871
  ]);
557
- const resolvedNeedConfirm = needConfirm ?? Boolean(showTime);
872
+ const resolvedNeedConfirm = showTime ? false : Boolean(needConfirm);
558
873
  const rangeDates = [dayFromValue(draftValue[0]), dayFromValue(draftValue[1])];
559
874
  const invalidDateTimeRange = Boolean(showTime && draftValue[0] && draftValue[1] && draftValue[0] > draftValue[1]);
560
- useEffect(() => {
875
+ useEffect2(() => {
561
876
  if (!visible) return void 0;
562
877
  const close = (event) => {
563
878
  const target = event.target;
@@ -571,11 +886,10 @@ function DateRangePicker({
571
886
  }
572
887
  function changeOpen(next, endpoint) {
573
888
  if (next && !visible) {
574
- setConfirmedIndex(null);
575
- setPresetSelected(false);
576
889
  setDraftValue(currentValue);
577
890
  setTimes([timePart(currentValue[0], defaultTime), timePart(currentValue[1], defaultEndTime)]);
578
891
  setActiveIndex(endpointDisabled[0] ? 1 : endpointDisabled[1] ? 0 : endpoint ?? (currentValue[0] && !currentValue[1] ? 1 : 0));
892
+ setDateTimeView("date");
579
893
  const nextStartMonth = startOfMonth(parseDate(dayFromValue(currentValue[0] || currentValue[1])) ?? /* @__PURE__ */ new Date());
580
894
  setViewMonth(nextStartMonth);
581
895
  setEndViewMonth(startOfMonth(parseDate(dayFromValue(currentValue[1])) ?? addMonths(nextStartMonth, 1)));
@@ -591,9 +905,9 @@ function DateRangePicker({
591
905
  if (maximum && day > String(maximum).slice(0, 10)) return true;
592
906
  const from = index === 1 ? rangeDates[0] : void 0;
593
907
  if (dateTimeStep) {
594
- const otherIndex2 = index === 0 ? 1 : 0;
595
- const otherEndpoint = rangeDates[otherIndex2];
596
- if (otherEndpoint && (endpointDisabled[otherIndex2] || confirmedIndex === otherIndex2)) {
908
+ const otherIndex = index === 0 ? 1 : 0;
909
+ const otherEndpoint = rangeDates[otherIndex];
910
+ if (otherEndpoint) {
597
911
  if (index === 0 && day > otherEndpoint || index === 1 && day < otherEndpoint) return true;
598
912
  if (maxRangeDays && Math.abs(daysBetween(otherEndpoint, day)) >= maxRangeDays) return true;
599
913
  }
@@ -604,10 +918,9 @@ function DateRangePicker({
604
918
  return showTime ? withTime(day, times[index], showSecond) : day;
605
919
  }
606
920
  function updateDraft(next) {
607
- setPresetSelected(false);
608
921
  setDraftValue(next);
609
922
  onCalendarChange?.(next);
610
- if (!showTime && isValidRange(next) && (next[0] !== currentValue[0] || next[1] !== currentValue[1])) {
923
+ if (isValidRange(next) && (next[0] !== currentValue[0] || next[1] !== currentValue[1])) {
611
924
  setCurrentValue(next);
612
925
  }
613
926
  }
@@ -648,6 +961,13 @@ function DateRangePicker({
648
961
  nextValue[index] = withTime(day, time, showSecond);
649
962
  updateDraft(nextValue);
650
963
  setHoverDate("");
964
+ const otherIndex = index === 0 ? 1 : 0;
965
+ if (!nextValue[otherIndex]) {
966
+ setActiveIndex(otherIndex);
967
+ const month = startOfMonth(parseDate(day) ?? /* @__PURE__ */ new Date());
968
+ (otherIndex === 0 ? setViewMonth : setEndViewMonth)(month);
969
+ return;
970
+ }
651
971
  setActiveIndex(index);
652
972
  }
653
973
  function changeTime(index, nextTime) {
@@ -684,19 +1004,7 @@ function DateRangePicker({
684
1004
  }
685
1005
  return true;
686
1006
  }
687
- const otherIndex = activeIndex === 0 ? 1 : 0;
688
- const needsOtherConfirmation = Boolean(showTime && !presetSelected && !endpointDisabled[otherIndex] && confirmedIndex !== otherIndex);
689
1007
  function confirm() {
690
- if (needsOtherConfirmation) {
691
- if (!draftValue[activeIndex] && !allowEmpty[activeIndex]) return;
692
- setConfirmedIndex(activeIndex);
693
- setActiveIndex(otherIndex);
694
- const month = startOfMonth(parseDate(dayFromValue(draftValue[activeIndex])) ?? /* @__PURE__ */ new Date());
695
- if (otherIndex === 0) setViewMonth(month);
696
- else setEndViewMonth(month);
697
- setHoverDate("");
698
- return;
699
- }
700
1008
  if (!isValidRange(draftValue)) return;
701
1009
  setCurrentValue(draftValue);
702
1010
  changeOpen(false);
@@ -709,13 +1017,11 @@ function DateRangePicker({
709
1017
  ];
710
1018
  if (!isValidRange(next)) return;
711
1019
  updateDraft(next);
712
- setConfirmedIndex(null);
713
- setPresetSelected(true);
714
1020
  setTimes([timePart(next[0], defaultTime), timePart(next[1], defaultEndTime)]);
715
1021
  const nextStartMonth = startOfMonth(parseDate(dayFromValue(next[0] || next[1])) ?? /* @__PURE__ */ new Date());
716
1022
  setViewMonth(nextStartMonth);
717
1023
  setEndViewMonth(startOfMonth(parseDate(dayFromValue(next[1])) ?? addMonths(nextStartMonth, 1)));
718
- if (!showTime && !resolvedNeedConfirm) {
1024
+ if (!resolvedNeedConfirm) {
719
1025
  changeOpen(false);
720
1026
  }
721
1027
  }
@@ -730,49 +1036,29 @@ function DateRangePicker({
730
1036
  const month = index === 0 ? viewMonth : endViewMonth;
731
1037
  const setMonth = index === 0 ? setViewMonth : setEndViewMonth;
732
1038
  const endpointLabel = index === 0 ? "\u5F00\u59CB" : "\u7ED3\u675F";
733
- return /* @__PURE__ */ jsxs2(
734
- "div",
735
- {
736
- className: `sia-date-panel__range-date-time-group${activeIndex === index ? " is-active" : ""}`,
737
- "aria-label": `${endpointLabel}\u65E5\u671F\u65F6\u95F4`,
738
- children: [
739
- /* @__PURE__ */ jsxs2("section", { className: "sia-date-panel__calendar", children: [
740
- /* @__PURE__ */ jsx2(
741
- CalendarHeader,
742
- {
743
- month,
744
- label: endpointLabel,
745
- range: true,
746
- onPreviousYear: () => setMonth(addMonths(month, -12)),
747
- onPreviousMonth: () => setMonth(addMonths(month, -1)),
748
- onNextMonth: () => setMonth(addMonths(month, 1)),
749
- onNextYear: () => setMonth(addMonths(month, 12))
750
- }
751
- ),
752
- /* @__PURE__ */ jsx2(
753
- CalendarMonth,
754
- {
755
- month,
756
- range: rangeDates,
757
- disabledDate: (day) => isDisabled(day, index, true),
758
- onSelect: (day) => selectDateTime(day, index)
759
- }
760
- )
761
- ] }),
762
- /* @__PURE__ */ jsx2(
763
- TimePanel,
764
- {
765
- value: times[index],
766
- showSecond,
767
- ariaLabel: `${endpointLabel}\u65F6\u95F4`,
768
- disabledTime: endpointDisabled[index] ? () => true : void 0,
769
- onChange: (nextTime) => changeTime(index, nextTime)
770
- }
771
- )
772
- ]
773
- },
774
- endpointLabel
775
- );
1039
+ return /* @__PURE__ */ jsxs2(Fragment2, { children: [
1040
+ /* @__PURE__ */ jsx2(
1041
+ CalendarHeader,
1042
+ {
1043
+ month,
1044
+ label: endpointLabel,
1045
+ range: true,
1046
+ onPreviousYear: () => setMonth(addMonths(month, -12)),
1047
+ onPreviousMonth: () => setMonth(addMonths(month, -1)),
1048
+ onNextMonth: () => setMonth(addMonths(month, 1)),
1049
+ onNextYear: () => setMonth(addMonths(month, 12))
1050
+ }
1051
+ ),
1052
+ /* @__PURE__ */ jsx2(
1053
+ CalendarMonth,
1054
+ {
1055
+ month,
1056
+ range: rangeDates,
1057
+ disabledDate: (day) => isDisabled(day, index, true),
1058
+ onSelect: (day) => selectDateTime(day, index)
1059
+ }
1060
+ )
1061
+ ] });
776
1062
  }
777
1063
  const displayValue = visible && allowEmpty.some(Boolean) ? draftValue : currentValue;
778
1064
  const startFloating = useFloatingPlaceholder({ mode: placeholderMode, placeholder: placeholder[0], filled: Boolean(displayValue[0]), active: visible });
@@ -817,67 +1103,110 @@ function DateRangePicker({
817
1103
  }
818
1104
  ),
819
1105
  allowClear && (displayValue[0] || displayValue[1]) && !disabled ? /* @__PURE__ */ jsx2("button", { type: "button", className: "sia-picker__clear", "aria-label": "\u6E05\u9664\u65E5\u671F\u8303\u56F4", onClick: clearValue, children: /* @__PURE__ */ jsx2(Icon, { name: "circle-close", variant: "filled", size: 15 }) }) : null,
820
- /* @__PURE__ */ jsxs2(PopupPortal, { ref: popupRef, anchorRef: rootRef, open: visible, className: `sia-date-panel sia-date-panel--range${showTime ? " sia-date-panel--with-time sia-date-panel--range-time-compact" : ""}${presets?.length ? " sia-date-panel--with-presets" : ""}`, role: "dialog", "aria-label": "\u65E5\u671F\u8303\u56F4\u9009\u62E9\u9762\u677F", children: [
821
- /* @__PURE__ */ jsxs2("div", { className: "sia-date-panel__body", children: [
822
- presets?.length ? /* @__PURE__ */ jsx2("aside", { className: "sia-date-panel__presets", "aria-label": "\u5FEB\u6377\u65E5\u671F\u8303\u56F4", children: presets.map((preset, index) => /* @__PURE__ */ jsx2("button", { type: "button", onClick: () => applyPreset(preset), children: preset.label }, index)) }) : null,
823
- showTime ? /* @__PURE__ */ jsx2("div", { className: "sia-date-panel__range-date-time", children: renderDateTimeGroup(activeIndex) }) : /* @__PURE__ */ jsxs2("div", { className: "sia-date-panel__range-calendars", children: [
824
- /* @__PURE__ */ jsxs2("section", { className: "sia-date-panel__calendar", children: [
825
- /* @__PURE__ */ jsx2(
826
- CalendarHeader,
827
- {
828
- month: viewMonth,
829
- range: true,
830
- onPreviousYear: () => setViewMonth(addMonths(viewMonth, -12)),
831
- onPreviousMonth: () => setViewMonth(addMonths(viewMonth, -1))
832
- }
833
- ),
834
- /* @__PURE__ */ jsx2(CalendarMonth, { month: viewMonth, range: rangeDates, previewEnd: activeIndex === 1 ? hoverDate : "", disabledDate: isDisabled, onSelect: selectDate, onHover: activeIndex === 1 ? setHoverDate : void 0 })
835
- ] }),
836
- /* @__PURE__ */ jsxs2("section", { className: "sia-date-panel__calendar", children: [
837
- /* @__PURE__ */ jsx2(
838
- CalendarHeader,
839
- {
840
- month: addMonths(viewMonth, 1),
841
- range: true,
842
- onNextMonth: () => setViewMonth(addMonths(viewMonth, 1)),
843
- onNextYear: () => setViewMonth(addMonths(viewMonth, 12))
844
- }
845
- ),
846
- /* @__PURE__ */ jsx2(CalendarMonth, { month: addMonths(viewMonth, 1), range: rangeDates, previewEnd: activeIndex === 1 ? hoverDate : "", disabledDate: isDisabled, onSelect: selectDate, onHover: activeIndex === 1 ? setHoverDate : void 0 })
847
- ] })
848
- ] })
849
- ] }),
850
- /* @__PURE__ */ jsx2(
851
- DatePanelFooter,
852
- {
853
- showToday: showToday && !presets?.length,
854
- needConfirm: Boolean(showTime) || resolvedNeedConfirm || allowEmpty.some(Boolean),
855
- disabledConfirm: needsOtherConfirmation ? !draftValue[activeIndex] && !allowEmpty[activeIndex] : !isValidRange(draftValue),
856
- extra: /* @__PURE__ */ jsxs2(Fragment, { children: [
857
- renderExtraFooter?.(),
858
- invalidDateTimeRange ? /* @__PURE__ */ jsx2("small", { className: "sia-date-panel__range-error", children: "\u7ED3\u675F\u65F6\u95F4\u4E0D\u80FD\u65E9\u4E8E\u5F00\u59CB\u65F6\u95F4" }) : maxRangeDays ? /* @__PURE__ */ jsxs2("small", { children: [
859
- "\u6700\u591A\u9009\u62E9 ",
860
- maxRangeDays,
861
- " \u5929"
862
- ] }) : null
1106
+ /* @__PURE__ */ jsxs2(
1107
+ PopupPortal,
1108
+ {
1109
+ ref: popupRef,
1110
+ anchorRef: rootRef,
1111
+ open: visible,
1112
+ className: `sia-date-panel${showTime ? " sia-date-panel--datetime" : " sia-date-panel--range"}${presets?.length ? " sia-date-panel--with-presets" : ""}`,
1113
+ role: "dialog",
1114
+ "aria-label": "\u65E5\u671F\u8303\u56F4\u9009\u62E9\u9762\u677F",
1115
+ onKeyDown: (event) => {
1116
+ if (event.key === "Escape") {
1117
+ event.stopPropagation();
1118
+ dismissPanel();
1119
+ }
1120
+ },
1121
+ children: [
1122
+ /* @__PURE__ */ jsxs2("div", { className: "sia-date-panel__body", children: [
1123
+ presets?.length ? /* @__PURE__ */ jsx2("aside", { className: "sia-date-panel__presets", "aria-label": "\u5FEB\u6377\u65E5\u671F\u8303\u56F4", children: presets.map((preset, index) => /* @__PURE__ */ jsx2("button", { type: "button", onClick: () => applyPreset(preset), children: preset.label }, index)) }) : null,
1124
+ showTime ? /* @__PURE__ */ jsxs2("div", { className: "sia-date-panel__views", children: [
1125
+ /* @__PURE__ */ jsx2("section", { className: `sia-date-panel__view sia-date-panel__view--date${dateTimeView === "date" ? " is-active" : ""}`, "aria-hidden": dateTimeView !== "date", "aria-label": `${activeIndex === 0 ? "\u5F00\u59CB" : "\u7ED3\u675F"}\u65E5\u671F`, children: renderDateTimeGroup(activeIndex) }, activeIndex === 0 ? "\u5F00\u59CB" : "\u7ED3\u675F"),
1126
+ /* @__PURE__ */ jsx2("div", { className: `sia-date-panel__view sia-date-panel__view--time${dateTimeView === "time" ? " is-active" : ""}`, "aria-hidden": dateTimeView !== "time", children: /* @__PURE__ */ jsx2(
1127
+ TimePanel,
1128
+ {
1129
+ value: times[activeIndex],
1130
+ showSecond,
1131
+ title: `\u9009\u62E9${activeIndex === 0 ? "\u5F00\u59CB" : "\u7ED3\u675F"}\u65F6\u95F4`,
1132
+ unitLabels: true,
1133
+ ariaLabel: `\u9009\u62E9${activeIndex === 0 ? "\u5F00\u59CB" : "\u7ED3\u675F"}\u65F6\u95F4`,
1134
+ disabledTime: endpointDisabled[activeIndex] ? () => true : void 0,
1135
+ onChange: (nextTime) => changeTime(activeIndex, nextTime)
1136
+ }
1137
+ ) })
1138
+ ] }) : /* @__PURE__ */ jsxs2("div", { className: "sia-date-panel__range-calendars", children: [
1139
+ /* @__PURE__ */ jsxs2("section", { className: "sia-date-panel__calendar", children: [
1140
+ /* @__PURE__ */ jsx2(
1141
+ CalendarHeader,
1142
+ {
1143
+ month: viewMonth,
1144
+ range: true,
1145
+ onPreviousYear: () => setViewMonth(addMonths(viewMonth, -12)),
1146
+ onPreviousMonth: () => setViewMonth(addMonths(viewMonth, -1))
1147
+ }
1148
+ ),
1149
+ /* @__PURE__ */ jsx2(CalendarMonth, { month: viewMonth, range: rangeDates, previewEnd: activeIndex === 1 ? hoverDate : "", disabledDate: isDisabled, onSelect: selectDate, onHover: activeIndex === 1 ? setHoverDate : void 0 })
1150
+ ] }),
1151
+ /* @__PURE__ */ jsxs2("section", { className: "sia-date-panel__calendar", children: [
1152
+ /* @__PURE__ */ jsx2(
1153
+ CalendarHeader,
1154
+ {
1155
+ month: addMonths(viewMonth, 1),
1156
+ range: true,
1157
+ onNextMonth: () => setViewMonth(addMonths(viewMonth, 1)),
1158
+ onNextYear: () => setViewMonth(addMonths(viewMonth, 12))
1159
+ }
1160
+ ),
1161
+ /* @__PURE__ */ jsx2(CalendarMonth, { month: addMonths(viewMonth, 1), range: rangeDates, previewEnd: activeIndex === 1 ? hoverDate : "", disabledDate: isDisabled, onSelect: selectDate, onHover: activeIndex === 1 ? setHoverDate : void 0 })
1162
+ ] })
1163
+ ] })
863
1164
  ] }),
864
- onToday: () => {
865
- const now = /* @__PURE__ */ new Date();
866
- const day = dateKey(now);
867
- if (isDisabled(day, activeIndex, Boolean(showTime))) return;
868
- if (showTime) {
869
- const time = [now.getHours(), now.getMinutes(), now.getSeconds()].map(pad).join(":");
870
- (activeIndex === 0 ? setViewMonth : setEndViewMonth)(startOfMonth(now));
871
- selectDateTime(day, activeIndex, time);
872
- } else {
873
- setViewMonth(startOfMonth(now));
874
- selectDate(day);
1165
+ showTime ? /* @__PURE__ */ jsx2(
1166
+ DateTimePanelFooter,
1167
+ {
1168
+ date: rangeDates[activeIndex] || dateKey(/* @__PURE__ */ new Date()),
1169
+ time: showSecond ? times[activeIndex] : times[activeIndex].slice(0, 5),
1170
+ view: dateTimeView,
1171
+ disabled: endpointDisabled[activeIndex],
1172
+ extra: /* @__PURE__ */ jsxs2(Fragment2, { children: [
1173
+ renderExtraFooter?.(),
1174
+ invalidDateTimeRange ? /* @__PURE__ */ jsx2("small", { className: "sia-date-panel__range-error", children: "\u7ED3\u675F\u65F6\u95F4\u4E0D\u80FD\u65E9\u4E8E\u5F00\u59CB\u65F6\u95F4" }) : maxRangeDays ? /* @__PURE__ */ jsxs2("small", { children: [
1175
+ "\u6700\u591A\u9009\u62E9 ",
1176
+ maxRangeDays,
1177
+ " \u5929"
1178
+ ] }) : null
1179
+ ] }),
1180
+ onSwitchDate: () => setDateTimeView("date"),
1181
+ onSwitchTime: () => setDateTimeView("time")
875
1182
  }
876
- },
877
- onConfirm: confirm
878
- }
879
- )
880
- ] })
1183
+ ) : /* @__PURE__ */ jsx2(
1184
+ DatePanelFooter,
1185
+ {
1186
+ showToday: showToday && !presets?.length,
1187
+ needConfirm: resolvedNeedConfirm || allowEmpty.some(Boolean),
1188
+ disabledConfirm: !isValidRange(draftValue),
1189
+ extra: /* @__PURE__ */ jsxs2(Fragment2, { children: [
1190
+ renderExtraFooter?.(),
1191
+ invalidDateTimeRange ? /* @__PURE__ */ jsx2("small", { className: "sia-date-panel__range-error", children: "\u7ED3\u675F\u65F6\u95F4\u4E0D\u80FD\u65E9\u4E8E\u5F00\u59CB\u65F6\u95F4" }) : maxRangeDays ? /* @__PURE__ */ jsxs2("small", { children: [
1192
+ "\u6700\u591A\u9009\u62E9 ",
1193
+ maxRangeDays,
1194
+ " \u5929"
1195
+ ] }) : null
1196
+ ] }),
1197
+ onToday: () => {
1198
+ const now = /* @__PURE__ */ new Date();
1199
+ const day = dateKey(now);
1200
+ if (isDisabled(day, activeIndex, Boolean(showTime))) return;
1201
+ setViewMonth(startOfMonth(now));
1202
+ selectDate(day);
1203
+ },
1204
+ onConfirm: confirm
1205
+ }
1206
+ )
1207
+ ]
1208
+ }
1209
+ )
881
1210
  ] });
882
1211
  }
883
1212
  ((DatePicker2) => {