@sia.soul/sia-react-ui 0.1.165 → 0.1.167

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 (40) hide show
  1. package/dist/chart.cjs +4553 -4513
  2. package/dist/chart.d.cts +1850 -1843
  3. package/dist/chart.d.ts +1850 -1843
  4. package/dist/chart.js +1 -1
  5. package/dist/chunk-2FZI7TP6.js +0 -0
  6. package/dist/{chunk-WR5YBY2A.js → chunk-5CGJVE4C.js} +57 -43
  7. package/dist/{chunk-2EC653G5.js → chunk-5KTQXNGL.js} +2 -2
  8. package/dist/{chunk-NHGCGOF2.js → chunk-A7TLMWMM.js} +4754 -4714
  9. package/dist/{chunk-G5EJJFUI.js → chunk-FSO46WEJ.js} +14 -6
  10. package/dist/{chunk-SX4LLT3H.js → chunk-KDNOLFDJ.js} +2 -2
  11. package/dist/{chunk-DKQ5UCN6.js → chunk-S6FA6NN3.js} +519 -220
  12. package/dist/{chunk-23FQ5ARA.js → chunk-XS7AVCHO.js} +27 -17
  13. package/dist/{core-r-smfiNN.d.cts → core-C7Was4Vc.d.cts} +11 -12
  14. package/dist/{core-XtqUDbbD.d.ts → core-D7C32Rdq.d.ts} +11 -12
  15. package/dist/core.cjs +267 -235
  16. package/dist/core.css +3125 -5327
  17. package/dist/core.d.cts +1 -1
  18. package/dist/core.d.ts +1 -1
  19. package/dist/core.js +4 -4
  20. package/dist/game.cjs +14 -6
  21. package/dist/game.css +1666 -3147
  22. package/dist/game.js +1 -1
  23. package/dist/index.cjs +6498 -6060
  24. package/dist/index.css +8721 -8545
  25. package/dist/index.d.cts +127 -111
  26. package/dist/index.d.ts +127 -111
  27. package/dist/index.js +817 -749
  28. package/dist/markdown-editor.css +461 -0
  29. package/dist/markdown-editor.js +2 -1
  30. package/dist/rich-text-editor.cjs +38 -20
  31. package/dist/rich-text-editor.css +461 -0
  32. package/dist/rich-text-editor.js +4 -3
  33. package/dist/{select-date-range-E1N5-oXv.d.ts → select-date-range-AOleKBXc.d.ts} +6 -9
  34. package/dist/{select-date-range-BnlISSPV.d.cts → select-date-range-BtTkMElI.d.cts} +6 -9
  35. package/dist/select-date-range.cjs +529 -222
  36. package/dist/select-date-range.d.cts +1 -1
  37. package/dist/select-date-range.d.ts +1 -1
  38. package/dist/select-date-range.js +4 -4
  39. package/package.json +5 -1
  40. /package/dist/{chunk-V4I32DPL.js → chunk-GKWSCL5Q.js} +0 -0
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  Select
3
- } from "./chunk-SX4LLT3H.js";
3
+ } from "./chunk-KDNOLFDJ.js";
4
4
  import {
5
5
  Icon
6
- } from "./chunk-G5EJJFUI.js";
6
+ } from "./chunk-FSO46WEJ.js";
7
7
  import {
8
8
  useFloatingPlaceholder
9
9
  } from "./chunk-OHAESA5R.js";
@@ -16,7 +16,7 @@ import {
16
16
  } from "./chunk-CUAXJCSH.js";
17
17
 
18
18
  // src/components/DatePicker.tsx
19
- import { useEffect as useEffect2, useId, useLayoutEffect as useLayoutEffect2, useMemo, useRef as useRef2, useState } from "react";
19
+ import { forwardRef, useEffect as useEffect2, useId, useLayoutEffect as useLayoutEffect2, useMemo, useRef as useRef2, useState } from "react";
20
20
 
21
21
  // src/components/DatePickerPanel.tsx
22
22
  import { useEffect, useLayoutEffect, useRef } from "react";
@@ -42,12 +42,6 @@ function addMonths(value, amount) {
42
42
  function addDays(value, amount) {
43
43
  return new Date(value.getFullYear(), value.getMonth(), value.getDate() + amount);
44
44
  }
45
- function daysBetween(left, right) {
46
- const leftDate = parseDate(left);
47
- const rightDate = parseDate(right);
48
- if (!leftDate || !rightDate) return 0;
49
- return Math.round((rightDate.getTime() - leftDate.getTime()) / 864e5);
50
- }
51
45
  function timePart(value, fallback = "00:00:00") {
52
46
  const match = value?.match(/[T ](\d{2}):(\d{2})(?::(\d{2}))?/);
53
47
  return match ? `${match[1]}:${match[2]}:${match[3] ?? "00"}` : fallback;
@@ -124,10 +118,11 @@ function CalendarMonth({
124
118
  const mondayIndex = (first.getDay() + 6) % 7;
125
119
  const gridStart = addDays(first, -mondayIndex);
126
120
  const today = dateKey(/* @__PURE__ */ new Date());
127
- const start = range[0];
128
- const end = range[1] || previewEnd || "";
121
+ const start = range[0] || (range[1] ? previewEnd || "" : "");
122
+ const end = range[1] || (range[0] ? previewEnd || "" : "");
129
123
  const low = start && end ? start <= end ? start : end : "";
130
124
  const high = start && end ? start <= end ? end : start : "";
125
+ const selectedSet = new Set(selectedDates);
131
126
  return /* @__PURE__ */ jsxs(
132
127
  "div",
133
128
  {
@@ -150,12 +145,16 @@ function CalendarMonth({
150
145
  const key = dateKey(date);
151
146
  const outside = date.getMonth() !== month.getMonth();
152
147
  const disabled = disabledDate?.(key) ?? false;
153
- const selected = selectedDates.includes(key);
148
+ const selected = selectedSet.has(key);
154
149
  const rangeStart = Boolean(start && key === start);
155
150
  const rangeEnd = Boolean(range[1] && key === range[1]);
156
- const inRange = Boolean(low && high && key >= low && key <= high);
157
- const segmentStart = inRange && (index % 7 === 0 || key === low);
158
- const segmentEnd = inRange && (index % 7 === 6 || key === high);
151
+ const inDateRange = Boolean(low && high && key >= low && key <= high);
152
+ const prevSelected = selected && selectedSet.has(dateKey(addDays(date, -1)));
153
+ const nextSelected = selected && selectedSet.has(dateKey(addDays(date, 1)));
154
+ const inMultiRun = selected && (prevSelected || nextSelected);
155
+ const inRange = inDateRange || inMultiRun;
156
+ const segmentStart = inDateRange ? index % 7 === 0 || key === low : inMultiRun && (index % 7 === 0 || !prevSelected);
157
+ const segmentEnd = inDateRange ? index % 7 === 6 || key === high : inMultiRun && (index % 7 === 6 || !nextSelected);
159
158
  return /* @__PURE__ */ jsx(
160
159
  "span",
161
160
  {
@@ -185,11 +184,15 @@ function CalendarHeader({
185
184
  label,
186
185
  range = false,
187
186
  onTitleClick,
187
+ onYearClick,
188
+ onMonthClick,
188
189
  onPreviousYear,
189
190
  onPreviousMonth,
190
191
  onNextMonth,
191
192
  onNextYear
192
193
  }) {
194
+ const yearText = `${month.getFullYear()}\u5E74`;
195
+ const monthText = `${month.getMonth() + 1}\u6708`;
193
196
  return /* @__PURE__ */ jsxs("div", { className: "sia-date-panel__header", children: [
194
197
  /* @__PURE__ */ jsxs("span", { className: "sia-date-panel__nav", children: [
195
198
  onPreviousYear ? /* @__PURE__ */ jsxs("button", { type: "button", "aria-label": "\u4E0A\u4E00\u5E74", onClick: onPreviousYear, children: [
@@ -198,21 +201,23 @@ function CalendarHeader({
198
201
  ] }) : null,
199
202
  onPreviousMonth ? /* @__PURE__ */ jsx("button", { type: "button", "aria-label": "\u4E0A\u4E2A\u6708", onClick: onPreviousMonth, children: /* @__PURE__ */ jsx(Icon, { name: "chevron-left", size: 15 }) }) : null
200
203
  ] }),
201
- onTitleClick ? /* @__PURE__ */ jsxs("button", { type: "button", className: "sia-date-panel__title", "aria-label": "\u9009\u62E9\u5E74\u4EFD", onClick: onTitleClick, children: [
204
+ onYearClick || onMonthClick ? /* @__PURE__ */ jsxs("div", { className: "sia-date-panel__title-group", children: [
205
+ label ? /* @__PURE__ */ jsx("small", { children: label }) : null,
206
+ onYearClick ? /* @__PURE__ */ jsx("button", { type: "button", className: "sia-date-panel__title-part", "aria-label": "\u9009\u62E9\u5E74\u4EFD", onClick: onYearClick, children: yearText }) : /* @__PURE__ */ jsx("span", { children: yearText }),
207
+ onMonthClick ? /* @__PURE__ */ jsx("button", { type: "button", className: "sia-date-panel__title-part", "aria-label": "\u9009\u62E9\u6708\u4EFD", onClick: onMonthClick, children: monthText }) : /* @__PURE__ */ jsx("span", { children: monthText })
208
+ ] }) : onTitleClick ? /* @__PURE__ */ jsxs("button", { type: "button", className: "sia-date-panel__title", "aria-label": "\u9009\u62E9\u5E74\u4EFD", onClick: onTitleClick, children: [
202
209
  label ? /* @__PURE__ */ jsx("small", { children: label }) : null,
203
210
  /* @__PURE__ */ jsxs("span", { children: [
204
- month.getFullYear(),
205
- "\u5E74\xA0 ",
206
- month.getMonth() + 1,
207
- "\u6708"
211
+ yearText,
212
+ "\xA0 ",
213
+ monthText
208
214
  ] })
209
215
  ] }) : /* @__PURE__ */ jsxs("strong", { children: [
210
216
  label ? /* @__PURE__ */ jsx("small", { children: label }) : null,
211
217
  /* @__PURE__ */ jsxs("span", { children: [
212
- month.getFullYear(),
213
- "\u5E74\xA0 ",
214
- month.getMonth() + 1,
215
- "\u6708"
218
+ yearText,
219
+ "\xA0 ",
220
+ monthText
216
221
  ] })
217
222
  ] }),
218
223
  /* @__PURE__ */ jsxs("span", { className: "sia-date-panel__nav", children: [
@@ -459,8 +464,229 @@ function DateTimePanelFooter({
459
464
  ] });
460
465
  }
461
466
 
467
+ // src/components/dateRangeLogic.ts
468
+ function parseDateOnly(value) {
469
+ const match = value.match(/^(\d{4})-(\d{2})-(\d{2})/);
470
+ if (!match) return null;
471
+ const date = new Date(Number(match[1]), Number(match[2]) - 1, Number(match[3]));
472
+ return Number.isNaN(date.getTime()) ? null : date;
473
+ }
474
+ function diffDays(left, right) {
475
+ const leftDate = parseDateOnly(left);
476
+ const rightDate = parseDateOnly(right);
477
+ if (!leftDate || !rightDate) return 0;
478
+ return Math.round((rightDate.getTime() - leftDate.getTime()) / 864e5);
479
+ }
480
+ function formatWithTime(date, time, showSecond) {
481
+ if (!date) return "";
482
+ const [hour = "00", minute = "00", second = "00"] = time.split(":");
483
+ return `${date} ${hour}:${minute}${showSecond ? `:${second}` : ""}`;
484
+ }
485
+ function dayOnly(value) {
486
+ const match = value.match(/^(\d{4}-\d{2}-\d{2})/);
487
+ return match ? match[1] : "";
488
+ }
489
+ function normalizeTimeForCompare(time, showSecond) {
490
+ const [h = "00", m = "00", s = "00"] = time.split(":");
491
+ return showSecond ? `${h}:${m}:${s}` : `${h}:${m}:00`;
492
+ }
493
+ function validateDateRange(next, options) {
494
+ const { currentValue, allowEmpty, endpointDisabled, minDate, maxDate, maxRangeDays, disabledDate } = options;
495
+ if (!next[0] && !next[1]) return { valid: false, reason: "empty" };
496
+ for (const index of [0, 1]) {
497
+ if (!next[index]) {
498
+ if (!allowEmpty[index]) return { valid: false, reason: "incomplete" };
499
+ continue;
500
+ }
501
+ if (endpointDisabled[index]) {
502
+ if (next[index] !== currentValue[index]) return { valid: false, reason: "locked" };
503
+ continue;
504
+ }
505
+ const day = dayOnly(next[index]);
506
+ if (!day) return { valid: false, reason: "invalid" };
507
+ if (minDate && day < minDate.slice(0, 10) || maxDate && day > maxDate.slice(0, 10)) {
508
+ return { valid: false, reason: "bounds", message: "\u6240\u9009\u65E5\u671F\u8D85\u51FA\u53EF\u9009\u8303\u56F4" };
509
+ }
510
+ const from = index === 1 ? dayOnly(next[0]) || void 0 : void 0;
511
+ if (disabledDate?.(day, { from, type: "date" })) {
512
+ return { valid: false, reason: "disabled", message: "\u5305\u542B\u4E0D\u53EF\u9009\u65E5\u671F" };
513
+ }
514
+ }
515
+ if (next[0] && next[1]) {
516
+ if (next[0] > next[1]) {
517
+ return { valid: false, reason: "order", message: "\u7ED3\u675F\u65F6\u95F4\u4E0D\u80FD\u65E9\u4E8E\u5F00\u59CB\u65F6\u95F4" };
518
+ }
519
+ if (maxRangeDays && Math.abs(diffDays(dayOnly(next[0]), dayOnly(next[1]))) >= maxRangeDays) {
520
+ return { valid: false, reason: "maxRange", message: `\u6700\u591A\u9009\u62E9 ${maxRangeDays} \u5929` };
521
+ }
522
+ }
523
+ return { valid: true };
524
+ }
525
+ function isRangeDayDisabled(day, options) {
526
+ const { activeIndex, rangeDates, endpointDisabled, minDate, maxDate, maxRangeDays, disabledDate } = options;
527
+ if (endpointDisabled[activeIndex]) return true;
528
+ if (minDate && day < minDate.slice(0, 10)) return true;
529
+ if (maxDate && day > maxDate.slice(0, 10)) return true;
530
+ const otherIndex = activeIndex === 0 ? 1 : 0;
531
+ const otherDay = rangeDates[otherIndex];
532
+ if (endpointDisabled[otherIndex] && otherDay) {
533
+ if (activeIndex === 0 && day > otherDay) return true;
534
+ if (activeIndex === 1 && day < otherDay) return true;
535
+ if (maxRangeDays && Math.abs(diffDays(otherDay, day)) >= maxRangeDays) return true;
536
+ } else if (activeIndex === 1 && rangeDates[0]) {
537
+ if (maxRangeDays && Math.abs(diffDays(rangeDates[0], day)) >= maxRangeDays) return true;
538
+ } else if (activeIndex === 0 && !rangeDates[0] && rangeDates[1]) {
539
+ if (maxRangeDays && Math.abs(diffDays(rangeDates[1], day)) >= maxRangeDays) return true;
540
+ }
541
+ const from = activeIndex === 1 ? rangeDates[0] || void 0 : !rangeDates[0] && rangeDates[1] ? rangeDates[1] : void 0;
542
+ return disabledDate?.(day, { from, type: "date" }) ?? false;
543
+ }
544
+ function isRangeTimeDisabled(candidateTime, activeIndex, rangeDates, times, endpointDisabled, showSecond) {
545
+ if (endpointDisabled[activeIndex]) return true;
546
+ if (!rangeDates[0] || !rangeDates[1] || rangeDates[0] !== rangeDates[1]) return false;
547
+ const candidate = normalizeTimeForCompare(candidateTime, showSecond);
548
+ const other = normalizeTimeForCompare(times[activeIndex === 0 ? 1 : 0], showSecond);
549
+ return activeIndex === 0 ? candidate > other : candidate < other;
550
+ }
551
+ function pickRangeDate(input) {
552
+ const { day, activeIndex, draftValue, times, defaultTimes, showTime, showSecond, endpointDisabled, maxRangeDays } = input;
553
+ const startDay = dayOnly(draftValue[0]);
554
+ const endDay = dayOnly(draftValue[1]);
555
+ const nextTimes = [times[0], times[1]];
556
+ const format = (targetDay, idx) => showTime ? formatWithTime(targetDay, nextTimes[idx], showSecond) : targetDay;
557
+ if (endpointDisabled[0] || endpointDisabled[1]) {
558
+ const editableIndex = endpointDisabled[0] ? 1 : 0;
559
+ if (showTime && !draftValue[editableIndex]) {
560
+ nextTimes[editableIndex] = defaultTimes[editableIndex];
561
+ }
562
+ const nextDraft = [draftValue[0], draftValue[1]];
563
+ nextDraft[editableIndex] = format(day, editableIndex);
564
+ return {
565
+ nextDraft,
566
+ nextTimes,
567
+ nextActiveIndex: editableIndex,
568
+ completedPair: Boolean(nextDraft[0] && nextDraft[1])
569
+ };
570
+ }
571
+ if (activeIndex === 0) {
572
+ if (showTime && !draftValue[0]) {
573
+ nextTimes[0] = defaultTimes[0];
574
+ }
575
+ if (!startDay && endDay) {
576
+ if (day > endDay) {
577
+ return {
578
+ nextDraft: [format(endDay, 0), format(day, 1)],
579
+ nextTimes,
580
+ nextActiveIndex: 0,
581
+ completedPair: true
582
+ };
583
+ }
584
+ return {
585
+ nextDraft: [format(day, 0), draftValue[1]],
586
+ nextTimes,
587
+ nextActiveIndex: 0,
588
+ completedPair: true
589
+ };
590
+ }
591
+ const withinMaxSpan = !maxRangeDays || endDay && Math.abs(diffDays(day, endDay)) < maxRangeDays;
592
+ if (endDay && day <= endDay && withinMaxSpan) {
593
+ return {
594
+ nextDraft: [format(day, 0), draftValue[1]],
595
+ nextTimes,
596
+ nextActiveIndex: 0,
597
+ completedPair: false
598
+ };
599
+ }
600
+ return {
601
+ nextDraft: [format(day, 0), ""],
602
+ nextTimes,
603
+ nextActiveIndex: 1,
604
+ completedPair: false
605
+ };
606
+ }
607
+ if (!startDay) {
608
+ if (showTime && !draftValue[1]) {
609
+ nextTimes[1] = defaultTimes[1];
610
+ }
611
+ return {
612
+ nextDraft: ["", format(day, 1)],
613
+ nextTimes,
614
+ nextActiveIndex: 0,
615
+ completedPair: false
616
+ };
617
+ }
618
+ if (day < startDay) {
619
+ if (showTime && !draftValue[1]) {
620
+ nextTimes[1] = defaultTimes[1];
621
+ }
622
+ return {
623
+ nextDraft: [format(day, 0), format(startDay, 1)],
624
+ nextTimes,
625
+ nextActiveIndex: 1,
626
+ completedPair: true
627
+ };
628
+ }
629
+ if (showTime && !draftValue[1]) {
630
+ nextTimes[1] = defaultTimes[1];
631
+ }
632
+ return {
633
+ nextDraft: [draftValue[0], format(day, 1)],
634
+ nextTimes,
635
+ nextActiveIndex: 1,
636
+ completedPair: true
637
+ };
638
+ }
639
+
462
640
  // src/components/DatePicker.tsx
463
641
  import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
642
+ function weekStart(now) {
643
+ const day = now.getDay();
644
+ const offset = day === 0 ? -6 : 1 - day;
645
+ return addDays(now, offset);
646
+ }
647
+ var DEFAULT_DATE_PRESETS = [
648
+ { label: "\u4ECA\u5929", value: () => dateKey(/* @__PURE__ */ new Date()) },
649
+ { label: "\u6628\u5929", value: () => dateKey(addDays(/* @__PURE__ */ new Date(), -1)) },
650
+ { label: "\u524D\u5929", value: () => dateKey(addDays(/* @__PURE__ */ new Date(), -2)) },
651
+ { label: "\u4E00\u5468\u524D", value: () => dateKey(addDays(/* @__PURE__ */ new Date(), -7)) },
652
+ { label: "\u534A\u6708\u524D", value: () => dateKey(addDays(/* @__PURE__ */ new Date(), -15)) },
653
+ { label: "\u4E00\u6708\u524D", value: () => dateKey(addDays(/* @__PURE__ */ new Date(), -30)) },
654
+ { label: "\u672C\u67081\u65E5", value: () => dateKey(startOfMonth(/* @__PURE__ */ new Date())) }
655
+ ];
656
+ var DEFAULT_RANGE_PRESETS = [
657
+ { label: "\u4ECA\u5929", value: () => {
658
+ const today = dateKey(/* @__PURE__ */ new Date());
659
+ return [today, today];
660
+ } },
661
+ { label: "\u6628\u5929", value: () => {
662
+ const yesterday = dateKey(addDays(/* @__PURE__ */ new Date(), -1));
663
+ return [yesterday, yesterday];
664
+ } },
665
+ { label: "\u672C\u5468", value: () => {
666
+ const now = /* @__PURE__ */ new Date();
667
+ return [dateKey(weekStart(now)), dateKey(now)];
668
+ } },
669
+ { label: "\u672C\u6708", value: () => {
670
+ const now = /* @__PURE__ */ new Date();
671
+ return [dateKey(startOfMonth(now)), dateKey(now)];
672
+ } },
673
+ { label: "\u8FD17\u5929", value: () => {
674
+ const now = /* @__PURE__ */ new Date();
675
+ return [dateKey(addDays(now, -6)), dateKey(now)];
676
+ } },
677
+ { label: "\u8FD115\u5929", value: () => {
678
+ const now = /* @__PURE__ */ new Date();
679
+ return [dateKey(addDays(now, -14)), dateKey(now)];
680
+ } },
681
+ { label: "\u8FD130\u5929", value: () => {
682
+ const now = /* @__PURE__ */ new Date();
683
+ return [dateKey(addDays(now, -29)), dateKey(now)];
684
+ } },
685
+ { label: "\u8FD160\u5929", value: () => {
686
+ const now = /* @__PURE__ */ new Date();
687
+ return [dateKey(addDays(now, -59)), dateKey(now)];
688
+ } }
689
+ ];
464
690
  function formatWeek(date) {
465
691
  const target = new Date(date);
466
692
  target.setHours(0, 0, 0, 0);
@@ -513,7 +739,7 @@ function hasExplicitTime(value) {
513
739
  function isZeroTime(time, showSecond) {
514
740
  return showSecond ? time === "00:00:00" : time.slice(0, 5) === "00:00";
515
741
  }
516
- function DatePicker({
742
+ var DatePickerRoot = forwardRef(function DatePicker({
517
743
  value,
518
744
  defaultValue,
519
745
  picker = "date",
@@ -540,10 +766,15 @@ function DatePicker({
540
766
  formatValue = (value2) => value2,
541
767
  renderExtraFooter,
542
768
  ...props
543
- }) {
769
+ }, forwardedRef) {
544
770
  const size = useControlSize(sizeProp);
545
771
  const id = useId();
546
772
  const rootRef = useRef2(null);
773
+ function setRootRef(node) {
774
+ rootRef.current = node;
775
+ if (typeof forwardedRef === "function") forwardedRef(node);
776
+ else if (forwardedRef) forwardedRef.current = node;
777
+ }
547
778
  const popupRef = useRef2(null);
548
779
  const initialValue = defaultValue ?? (multiple ? [] : "");
549
780
  const [currentValue, setCurrentValue] = useControllableState({ value, defaultValue: initialValue, onChange });
@@ -695,7 +926,8 @@ function DatePicker({
695
926
  const display = Array.isArray(currentValue) ? currentValue.map(formatValue).join("\u3001") : currentValue ? formatValue(currentValue) : "";
696
927
  const floating = useFloatingPlaceholder({ mode: placeholderMode, placeholder: placeholder ?? placeholderFor(picker, showTime, multiple), filled: Boolean(display), active: visible });
697
928
  const triggerLabel = props["aria-label"] ?? (typeof placeholder === "string" ? placeholder : "\u65E5\u671F\u9009\u62E9\u5668");
698
- return /* @__PURE__ */ jsxs2("span", { ref: rootRef, className: `sia-picker${floating.className} sia-picker--${size} sia-picker--${status}${visible ? " is-open" : ""}${disabled ? " is-disabled" : ""} ${className}`.trim(), children: [
929
+ const resolvedPresets = presets !== void 0 ? presets : picker === "date" && !multiple ? DEFAULT_DATE_PRESETS : void 0;
930
+ return /* @__PURE__ */ jsxs2("span", { ref: setRootRef, className: `sia-picker${floating.className} sia-picker--${size} sia-picker--${status}${visible ? " is-open" : ""}${disabled ? " is-disabled" : ""} ${className}`.trim(), children: [
699
931
  /* @__PURE__ */ jsxs2(
700
932
  "button",
701
933
  {
@@ -731,7 +963,7 @@ function DatePicker({
731
963
  ref: popupRef,
732
964
  anchorRef: rootRef,
733
965
  open: visible,
734
- className: `sia-date-panel${showTime ? " sia-date-panel--datetime" : ""}${presets?.length ? " sia-date-panel--with-presets" : ""}`,
966
+ className: `sia-date-panel${showTime ? " sia-date-panel--datetime" : ""}${resolvedPresets?.length ? " sia-date-panel--with-presets" : ""}`,
735
967
  role: "dialog",
736
968
  "aria-label": "\u65E5\u671F\u9009\u62E9\u9762\u677F",
737
969
  onKeyDown: (event) => {
@@ -742,12 +974,16 @@ function DatePicker({
742
974
  },
743
975
  children: [
744
976
  /* @__PURE__ */ jsxs2("div", { className: "sia-date-panel__body", children: [
745
- presets?.length ? /* @__PURE__ */ jsx2("aside", { className: "sia-date-panel__presets", children: presets.map((preset, index) => /* @__PURE__ */ jsx2("button", { type: "button", onClick: () => {
746
- const next = resolvePreset(preset.value);
747
- if (!next || isDisabled(dayFromValue(next))) return;
977
+ resolvedPresets?.length ? /* @__PURE__ */ jsx2("aside", { className: "sia-date-panel__presets", "aria-label": "\u5FEB\u6377\u65E5\u671F", children: resolvedPresets.map((preset, index) => /* @__PURE__ */ jsx2("button", { type: "button", onClick: () => {
978
+ const raw = resolvePreset(preset.value);
979
+ const next = normalizeDateValue(raw, showTime);
980
+ const day = dayFromValue(next);
981
+ if (!next || !day || isDisabled(day)) return;
748
982
  setDraftValue(next);
749
983
  setDraftTime(timePart(next, defaultTimeFrom(showTime)));
750
984
  setTimeExplicit(hasExplicitTime(next));
985
+ const parsed = parseDate(day);
986
+ if (parsed) setViewMonth(startOfMonth(parsed));
751
987
  if (!resolvedNeedConfirm) {
752
988
  setCurrentValue(next);
753
989
  changeOpen(false);
@@ -802,8 +1038,8 @@ function DatePicker({
802
1038
  }
803
1039
  )
804
1040
  ] });
805
- }
806
- function DateRangePicker({
1041
+ });
1042
+ var DateRangePicker = forwardRef(function DateRangePicker2({
807
1043
  value,
808
1044
  defaultValue = ["", ""],
809
1045
  placeholder = ["\u5F00\u59CB\u65E5\u671F", "\u7ED3\u675F\u65E5\u671F"],
@@ -833,10 +1069,15 @@ function DateRangePicker({
833
1069
  formatValue = (value2) => value2,
834
1070
  renderExtraFooter,
835
1071
  ...props
836
- }) {
1072
+ }, forwardedRef) {
837
1073
  const size = useControlSize(sizeProp);
838
1074
  const id = useId();
839
1075
  const rootRef = useRef2(null);
1076
+ function setRootRef(node) {
1077
+ rootRef.current = node;
1078
+ if (typeof forwardedRef === "function") forwardedRef(node);
1079
+ else if (forwardedRef) forwardedRef.current = node;
1080
+ }
840
1081
  const popupRef = useRef2(null);
841
1082
  const [currentValue, setCurrentValue] = useControllableState({ value: value === void 0 ? void 0 : Array.isArray(value) ? value : ["", ""], defaultValue, onChange });
842
1083
  const [visible, setVisible] = useControllableState({ value: open, defaultValue: defaultOpen, onChange: onOpenChange });
@@ -860,10 +1101,10 @@ function DateRangePicker({
860
1101
  }
861
1102
  return () => observer.disconnect();
862
1103
  });
863
- const [dateTimeViews, setDateTimeViews] = useState(["date", "date"]);
1104
+ const [dateTimeView, setDateTimeView] = useState("date");
1105
+ const [panelMode, setPanelMode] = useState("date");
864
1106
  const [hoverDate, setHoverDate] = useState("");
865
1107
  const [viewMonth, setViewMonth] = useState(() => startOfMonth(parseDate(dayFromValue(currentValue[0] || currentValue[1])) ?? /* @__PURE__ */ new Date()));
866
- const [endViewMonth, setEndViewMonth] = useState(() => startOfMonth(parseDate(dayFromValue(currentValue[1])) ?? (showTime ? parseDate(dayFromValue(currentValue[0])) ?? /* @__PURE__ */ new Date() : addMonths(parseDate(dayFromValue(currentValue[0])) ?? /* @__PURE__ */ new Date(), 1))));
867
1108
  const showSecond = showSecondFrom(showTime);
868
1109
  const defaultTime = defaultTimeFrom(showTime);
869
1110
  const defaultEndTime = defaultTimeFrom(showTime, 1);
@@ -873,7 +1114,18 @@ function DateRangePicker({
873
1114
  ]);
874
1115
  const resolvedNeedConfirm = showTime ? false : Boolean(needConfirm);
875
1116
  const rangeDates = [dayFromValue(draftValue[0]), dayFromValue(draftValue[1])];
876
- const invalidDateTimeRange = Boolean(showTime && draftValue[0] && draftValue[1] && draftValue[0] > draftValue[1]);
1117
+ const minBound = minDate ?? (props.min !== void 0 ? String(props.min) : void 0);
1118
+ const maxBound = maxDate ?? (props.max !== void 0 ? String(props.max) : void 0);
1119
+ const validation = validateDateRange(draftValue, {
1120
+ currentValue,
1121
+ allowEmpty,
1122
+ endpointDisabled,
1123
+ minDate: minBound,
1124
+ maxDate: maxBound,
1125
+ maxRangeDays,
1126
+ disabledDate
1127
+ });
1128
+ const invalidRangeMessage = !validation.valid && (validation.reason === "order" || validation.reason === "maxRange" || validation.reason === "bounds" || validation.reason === "disabled") ? validation.message : void 0;
877
1129
  useEffect2(() => {
878
1130
  if (!visible) return void 0;
879
1131
  const close = (event) => {
@@ -886,38 +1138,53 @@ function DateRangePicker({
886
1138
  function dismissPanel() {
887
1139
  setVisible(false);
888
1140
  }
1141
+ function focusEndpoint(endpoint, sourceValue = draftValue) {
1142
+ if (endpointDisabled[endpoint]) return;
1143
+ setActiveIndex(endpoint);
1144
+ setHoverDate("");
1145
+ const targetDay = dayFromValue(sourceValue[endpoint]);
1146
+ if (targetDay) {
1147
+ const parsed = parseDate(targetDay);
1148
+ if (parsed) setViewMonth(startOfMonth(parsed));
1149
+ }
1150
+ }
889
1151
  function changeOpen(next, endpoint) {
890
1152
  if (next && !visible) {
891
1153
  setDraftValue(currentValue);
892
1154
  setTimes([timePart(currentValue[0], defaultTime), timePart(currentValue[1], defaultEndTime)]);
893
- setActiveIndex(endpointDisabled[0] ? 1 : endpointDisabled[1] ? 0 : endpoint ?? (currentValue[0] && !currentValue[1] ? 1 : 0));
894
- setDateTimeViews(["date", "date"]);
895
- const nextStartMonth = startOfMonth(parseDate(dayFromValue(currentValue[0] || currentValue[1])) ?? /* @__PURE__ */ new Date());
896
- setViewMonth(nextStartMonth);
897
- setEndViewMonth(startOfMonth(parseDate(dayFromValue(currentValue[1])) ?? (showTime ? nextStartMonth : addMonths(nextStartMonth, 1))));
1155
+ const initialEndpoint = endpointDisabled[0] ? 1 : endpointDisabled[1] ? 0 : endpoint ?? (currentValue[0] && !currentValue[1] ? 1 : 0);
1156
+ setActiveIndex(initialEndpoint);
1157
+ setDateTimeView("date");
1158
+ setPanelMode("date");
1159
+ setHoverDate("");
1160
+ const focusDay = dayFromValue(currentValue[initialEndpoint] || currentValue[0] || currentValue[1]);
1161
+ setViewMonth(startOfMonth(parseDate(focusDay) ?? /* @__PURE__ */ new Date()));
1162
+ } else if (next && endpoint !== void 0 && !endpointDisabled[endpoint]) {
1163
+ focusEndpoint(endpoint);
898
1164
  }
899
- if (next && endpoint !== void 0 && !endpointDisabled[endpoint]) setActiveIndex(endpoint);
900
1165
  setVisible(next);
901
1166
  }
902
- function isDisabled(day, index = activeIndex, dateTimeStep = false) {
903
- if (endpointDisabled[index]) return true;
904
- const minimum = minDate ?? props.min;
905
- const maximum = maxDate ?? props.max;
906
- if (minimum && day < String(minimum).slice(0, 10)) return true;
907
- if (maximum && day > String(maximum).slice(0, 10)) return true;
908
- const from = index === 1 ? rangeDates[0] : void 0;
909
- if (dateTimeStep) {
910
- const otherIndex = index === 0 ? 1 : 0;
911
- const otherEndpoint = rangeDates[otherIndex];
912
- if (otherEndpoint) {
913
- if (index === 0 && day > otherEndpoint || index === 1 && day < otherEndpoint) return true;
914
- if (maxRangeDays && Math.abs(daysBetween(otherEndpoint, day)) >= maxRangeDays) return true;
915
- }
916
- } else if (from && maxRangeDays && Math.abs(daysBetween(from, day)) >= maxRangeDays) return true;
917
- return disabledDate?.(day, { from, type: "date" }) ?? false;
1167
+ function isDisabled(day, index = activeIndex) {
1168
+ return isRangeDayDisabled(day, {
1169
+ activeIndex: index,
1170
+ rangeDates,
1171
+ endpointDisabled,
1172
+ minDate: minBound,
1173
+ maxDate: maxBound,
1174
+ maxRangeDays,
1175
+ disabledDate
1176
+ });
918
1177
  }
919
- function buildRangeValue(day, index) {
920
- return showTime ? withTime(day, times[index], showSecond) : day;
1178
+ function isValidRange(next) {
1179
+ return validateDateRange(next, {
1180
+ currentValue,
1181
+ allowEmpty,
1182
+ endpointDisabled,
1183
+ minDate: minBound,
1184
+ maxDate: maxBound,
1185
+ maxRangeDays,
1186
+ disabledDate
1187
+ }).valid;
921
1188
  }
922
1189
  function updateDraft(next) {
923
1190
  setDraftValue(next);
@@ -927,44 +1194,26 @@ function DateRangePicker({
927
1194
  }
928
1195
  }
929
1196
  function selectDate(day) {
930
- if (isDisabled(day)) return;
931
- if (endpointDisabled.some(Boolean)) {
932
- const index = endpointDisabled[0] ? 1 : 0;
933
- const next = [...draftValue];
934
- next[index] = buildRangeValue(day, index);
935
- updateDraft(next);
936
- if (!resolvedNeedConfirm && isValidRange(next)) {
937
- changeOpen(false);
938
- }
939
- return;
940
- }
941
- if (activeIndex === 0 || !rangeDates[0] || rangeDates[1]) {
942
- const next = [buildRangeValue(day, 0), ""];
943
- updateDraft(next);
944
- setActiveIndex(1);
945
- setHoverDate("");
946
- return;
947
- }
948
- const startDay = rangeDates[0];
949
- const ordered = day < startDay ? [buildRangeValue(day, 0), buildRangeValue(startDay, 1)] : [draftValue[0], buildRangeValue(day, 1)];
950
- updateDraft(ordered);
951
- setActiveIndex(0);
1197
+ if (isDisabled(day, activeIndex)) return;
1198
+ const picked = pickRangeDate({
1199
+ day,
1200
+ activeIndex,
1201
+ draftValue,
1202
+ times,
1203
+ defaultTimes: [defaultTime, defaultEndTime],
1204
+ showTime: Boolean(showTime),
1205
+ showSecond,
1206
+ endpointDisabled,
1207
+ maxRangeDays
1208
+ });
1209
+ setTimes(picked.nextTimes);
1210
+ updateDraft(picked.nextDraft);
1211
+ setActiveIndex(picked.nextActiveIndex);
952
1212
  setHoverDate("");
953
- if (!resolvedNeedConfirm) {
1213
+ if (picked.completedPair && !showTime && !resolvedNeedConfirm && isValidRange(picked.nextDraft)) {
954
1214
  changeOpen(false);
955
1215
  }
956
1216
  }
957
- function selectDateTime(day, index, time = index === 1 ? "23:59:59" : times[index]) {
958
- if (isDisabled(day, index, true)) return;
959
- const nextTimes = [...times];
960
- nextTimes[index] = time;
961
- setTimes(nextTimes);
962
- const nextValue = [...draftValue];
963
- nextValue[index] = withTime(day, time, showSecond);
964
- updateDraft(nextValue);
965
- setHoverDate("");
966
- setActiveIndex(index);
967
- }
968
1217
  function changeTime(index, nextTime) {
969
1218
  if (endpointDisabled[index]) return;
970
1219
  const nextTimes = [...times];
@@ -977,28 +1226,6 @@ function DateRangePicker({
977
1226
  updateDraft(nextValue);
978
1227
  }
979
1228
  }
980
- function isValidRange(next) {
981
- if (!next.some(Boolean)) return false;
982
- for (const index of [0, 1]) {
983
- if (!next[index]) {
984
- if (!allowEmpty[index]) return false;
985
- else continue;
986
- }
987
- if (endpointDisabled[index]) {
988
- if (next[index] !== currentValue[index]) return false;
989
- else continue;
990
- }
991
- const day = dayFromValue(next[index]);
992
- if (!day) return false;
993
- if (minDate && day < minDate.slice(0, 10) || maxDate && day > maxDate.slice(0, 10)) return false;
994
- if (disabledDate?.(day, { from: index === 1 ? dayFromValue(next[0]) || void 0 : void 0, type: "date" })) return false;
995
- }
996
- if (next[0] && next[1]) {
997
- if (next[0] > next[1]) return false;
998
- if (maxRangeDays && Math.abs(daysBetween(dayFromValue(next[0]), dayFromValue(next[1]))) >= maxRangeDays) return false;
999
- }
1000
- return true;
1001
- }
1002
1229
  function confirm() {
1003
1230
  if (!isValidRange(draftValue)) return;
1004
1231
  setCurrentValue(draftValue);
@@ -1013,9 +1240,9 @@ function DateRangePicker({
1013
1240
  if (!isValidRange(next)) return;
1014
1241
  updateDraft(next);
1015
1242
  setTimes([timePart(next[0], defaultTime), timePart(next[1], defaultEndTime)]);
1016
- const nextStartMonth = startOfMonth(parseDate(dayFromValue(next[0] || next[1])) ?? /* @__PURE__ */ new Date());
1017
- setViewMonth(nextStartMonth);
1018
- setEndViewMonth(startOfMonth(parseDate(dayFromValue(next[1])) ?? (showTime ? nextStartMonth : addMonths(nextStartMonth, 1))));
1243
+ const focusDay = dayFromValue(next[0] || next[1]);
1244
+ setViewMonth(startOfMonth(parseDate(focusDay) ?? /* @__PURE__ */ new Date()));
1245
+ setHoverDate("");
1019
1246
  if (!resolvedNeedConfirm) {
1020
1247
  changeOpen(false);
1021
1248
  }
@@ -1025,77 +1252,114 @@ function DateRangePicker({
1025
1252
  const empty = [endpointDisabled[0] ? currentValue[0] : "", endpointDisabled[1] ? currentValue[1] : ""];
1026
1253
  updateDraft(empty);
1027
1254
  setCurrentValue(empty);
1028
- setActiveIndex(0);
1255
+ setActiveIndex(endpointDisabled[0] ? 1 : 0);
1256
+ setHoverDate("");
1029
1257
  }
1030
- function renderDateTimeGroup(index) {
1031
- const month = index === 0 ? viewMonth : endViewMonth;
1032
- const setMonth = index === 0 ? setViewMonth : setEndViewMonth;
1033
- const endpointLabel = index === 0 ? "\u5F00\u59CB" : "\u7ED3\u675F";
1258
+ const activeLabel = activeIndex === 0 ? "\u5F00\u59CB" : "\u7ED3\u675F";
1259
+ const showPreview = !endpointDisabled[0] && !endpointDisabled[1] && (activeIndex === 1 && Boolean(rangeDates[0]) && !rangeDates[1] || activeIndex === 0 && !rangeDates[0] && Boolean(rangeDates[1]));
1260
+ function renderSingleMonthCalendar() {
1261
+ if (panelMode === "year") {
1262
+ const startYear = Math.floor(viewMonth.getFullYear() / 10) * 10;
1263
+ const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
1264
+ const activeYear = viewMonth.getFullYear();
1265
+ return /* @__PURE__ */ jsxs2(Fragment2, { children: [
1266
+ /* @__PURE__ */ jsxs2("div", { className: "sia-date-panel__header", children: [
1267
+ /* @__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 }) }) }),
1268
+ /* @__PURE__ */ jsxs2("strong", { children: [
1269
+ startYear,
1270
+ "\u5E74 \u2014 ",
1271
+ startYear + 9,
1272
+ "\u5E74"
1273
+ ] }),
1274
+ /* @__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 }) }) })
1275
+ ] }),
1276
+ /* @__PURE__ */ jsx2("div", { className: "sia-date-panel__years", role: "grid", "aria-label": "\u9009\u62E9\u5E74\u4EFD", children: Array.from({ length: 10 }, (_, index) => {
1277
+ const year = startYear + index;
1278
+ const selected = year === activeYear;
1279
+ return /* @__PURE__ */ jsx2("span", { className: `sia-date-panel__cell${selected ? " is-selected" : ""}${year === currentYear ? " is-today" : ""}`, children: /* @__PURE__ */ jsx2(
1280
+ "button",
1281
+ {
1282
+ type: "button",
1283
+ "aria-label": `${year}\u5E74`,
1284
+ "aria-pressed": selected,
1285
+ onClick: () => {
1286
+ setViewMonth(new Date(year, viewMonth.getMonth(), 1));
1287
+ setPanelMode("date");
1288
+ },
1289
+ children: year
1290
+ }
1291
+ ) }, year);
1292
+ }) })
1293
+ ] });
1294
+ }
1295
+ if (panelMode === "month") {
1296
+ const now = /* @__PURE__ */ new Date();
1297
+ const viewYear = viewMonth.getFullYear();
1298
+ const activeMonth = viewMonth.getMonth();
1299
+ return /* @__PURE__ */ jsxs2(Fragment2, { children: [
1300
+ /* @__PURE__ */ jsxs2("div", { className: "sia-date-panel__header", children: [
1301
+ /* @__PURE__ */ jsx2("span", { className: "sia-date-panel__nav", children: /* @__PURE__ */ jsx2("button", { type: "button", "aria-label": "\u4E0A\u4E00\u5E74", onClick: () => setViewMonth(addMonths(viewMonth, -12)), children: /* @__PURE__ */ jsx2(Icon, { name: "chevron-left", size: 15 }) }) }),
1302
+ /* @__PURE__ */ jsx2("button", { type: "button", className: "sia-date-panel__title", "aria-label": "\u9009\u62E9\u5E74\u4EFD", onClick: () => setPanelMode("year"), children: /* @__PURE__ */ jsxs2("span", { children: [
1303
+ viewYear,
1304
+ "\u5E74"
1305
+ ] }) }),
1306
+ /* @__PURE__ */ jsx2("span", { className: "sia-date-panel__nav", children: /* @__PURE__ */ jsx2("button", { type: "button", "aria-label": "\u4E0B\u4E00\u5E74", onClick: () => setViewMonth(addMonths(viewMonth, 12)), children: /* @__PURE__ */ jsx2(Icon, { name: "chevron-right", size: 15 }) }) })
1307
+ ] }),
1308
+ /* @__PURE__ */ jsx2("div", { className: "sia-date-panel__years", role: "grid", "aria-label": "\u9009\u62E9\u6708\u4EFD", children: Array.from({ length: 12 }, (_, monthIndex) => {
1309
+ const selected = monthIndex === activeMonth;
1310
+ const isCurrentMonth = viewYear === now.getFullYear() && monthIndex === now.getMonth();
1311
+ return /* @__PURE__ */ jsx2("span", { className: `sia-date-panel__cell${selected ? " is-selected" : ""}${isCurrentMonth ? " is-today" : ""}`, children: /* @__PURE__ */ jsxs2(
1312
+ "button",
1313
+ {
1314
+ type: "button",
1315
+ "aria-label": `${viewYear}\u5E74${monthIndex + 1}\u6708`,
1316
+ "aria-pressed": selected,
1317
+ onClick: () => {
1318
+ setViewMonth(new Date(viewYear, monthIndex, 1));
1319
+ setPanelMode("date");
1320
+ },
1321
+ children: [
1322
+ monthIndex + 1,
1323
+ "\u6708"
1324
+ ]
1325
+ }
1326
+ ) }, monthIndex);
1327
+ }) })
1328
+ ] });
1329
+ }
1034
1330
  return /* @__PURE__ */ jsxs2(Fragment2, { children: [
1035
1331
  /* @__PURE__ */ jsx2(
1036
1332
  CalendarHeader,
1037
1333
  {
1038
- month,
1039
- label: endpointLabel,
1334
+ month: viewMonth,
1040
1335
  range: true,
1041
- onPreviousYear: () => setMonth(addMonths(month, -12)),
1042
- onPreviousMonth: () => setMonth(addMonths(month, -1)),
1043
- onNextMonth: () => setMonth(addMonths(month, 1)),
1044
- onNextYear: () => setMonth(addMonths(month, 12))
1336
+ onYearClick: () => setPanelMode("year"),
1337
+ onMonthClick: () => setPanelMode("month"),
1338
+ onPreviousYear: () => setViewMonth(addMonths(viewMonth, -12)),
1339
+ onPreviousMonth: () => setViewMonth(addMonths(viewMonth, -1)),
1340
+ onNextMonth: () => setViewMonth(addMonths(viewMonth, 1)),
1341
+ onNextYear: () => setViewMonth(addMonths(viewMonth, 12))
1045
1342
  }
1046
1343
  ),
1047
1344
  /* @__PURE__ */ jsx2(
1048
1345
  CalendarMonth,
1049
1346
  {
1050
- month,
1347
+ month: viewMonth,
1051
1348
  range: rangeDates,
1052
- disabledDate: (day) => isDisabled(day, index, true),
1053
- onSelect: (day) => selectDateTime(day, index)
1349
+ previewEnd: showPreview ? hoverDate : "",
1350
+ disabledDate: (day) => isDisabled(day, activeIndex),
1351
+ onSelect: selectDate,
1352
+ onHover: showPreview ? setHoverDate : void 0,
1353
+ onSwipeMonth: (direction) => setViewMonth((current) => addMonths(current, direction))
1054
1354
  }
1055
1355
  )
1056
1356
  ] });
1057
1357
  }
1058
- function switchDateTimeView(index, view) {
1059
- if (endpointDisabled[index]) return;
1060
- setActiveIndex(index);
1061
- setDateTimeViews((previous) => index === 0 ? [view, previous[1]] : [previous[0], view]);
1062
- }
1063
- function renderDateTimeEndpoint(index) {
1064
- const label = index === 0 ? "\u5F00\u59CB" : "\u7ED3\u675F";
1065
- const view = dateTimeViews[index];
1066
- return /* @__PURE__ */ jsxs2("section", { className: "sia-date-panel__endpoint", "aria-label": `${label}\u65E5\u671F\u65F6\u95F4`, children: [
1067
- /* @__PURE__ */ jsxs2("div", { className: "sia-date-panel__views", children: [
1068
- /* @__PURE__ */ jsx2("section", { className: `sia-date-panel__view sia-date-panel__view--date${view === "date" ? " is-active" : ""}`, "aria-hidden": view !== "date", ...view !== "date" ? { inert: "" } : {}, "aria-label": `${label}\u65E5\u671F`, children: renderDateTimeGroup(index) }),
1069
- /* @__PURE__ */ jsx2("div", { className: `sia-date-panel__view sia-date-panel__view--time${view === "time" ? " is-active" : ""}`, "aria-hidden": view !== "time", ...view !== "time" ? { inert: "" } : {}, children: /* @__PURE__ */ jsx2(
1070
- TimePanel,
1071
- {
1072
- value: times[index],
1073
- showSecond,
1074
- title: `\u9009\u62E9${label}\u65F6\u95F4`,
1075
- unitLabels: true,
1076
- ariaLabel: `\u9009\u62E9${label}\u65F6\u95F4`,
1077
- disabledTime: endpointDisabled[index] ? () => true : void 0,
1078
- onChange: (nextTime) => changeTime(index, nextTime)
1079
- }
1080
- ) })
1081
- ] }),
1082
- /* @__PURE__ */ jsx2(
1083
- DateTimePanelFooter,
1084
- {
1085
- date: rangeDates[index] || dateKey(/* @__PURE__ */ new Date()),
1086
- time: showSecond ? times[index] : times[index].slice(0, 5),
1087
- view,
1088
- disabled: endpointDisabled[index],
1089
- onSwitchDate: () => switchDateTimeView(index, "date"),
1090
- onSwitchTime: () => switchDateTimeView(index, "time")
1091
- }
1092
- )
1093
- ] }, index);
1094
- }
1358
+ const resolvedRangePresets = presets !== void 0 ? presets : DEFAULT_RANGE_PRESETS;
1095
1359
  const displayValue = visible && allowEmpty.some(Boolean) ? draftValue : currentValue;
1096
1360
  const startFloating = useFloatingPlaceholder({ mode: placeholderMode, placeholder: placeholder[0], filled: Boolean(displayValue[0]), active: visible });
1097
1361
  const endFloating = useFloatingPlaceholder({ mode: placeholderMode, placeholder: placeholder[1], filled: Boolean(displayValue[1]), active: visible });
1098
- return /* @__PURE__ */ jsxs2("span", { ref: rootRef, className: `sia-picker sia-picker-range-control sia-picker--${size} sia-picker--${status}${visible ? " is-open" : ""}${disabled ? " is-disabled" : ""} ${className}`.trim(), children: [
1362
+ return /* @__PURE__ */ jsxs2("span", { ref: setRootRef, className: `sia-picker sia-picker-range-control sia-picker--${size} sia-picker--${status}${visible ? " is-open" : ""}${disabled ? " is-disabled" : ""} ${className}`.trim(), children: [
1099
1363
  /* @__PURE__ */ jsxs2(
1100
1364
  "button",
1101
1365
  {
@@ -1113,7 +1377,7 @@ function DateRangePicker({
1113
1377
  onClick: (event) => {
1114
1378
  const field = event.target.closest("[data-range-endpoint]");
1115
1379
  const endpoint = field?.dataset.rangeEndpoint;
1116
- if (showTime && (endpoint === "0" || endpoint === "1")) {
1380
+ if (endpoint === "0" || endpoint === "1") {
1117
1381
  const index = Number(endpoint);
1118
1382
  if (!endpointDisabled[index]) changeOpen(true, index);
1119
1383
  } else if (visible) dismissPanel();
@@ -1141,7 +1405,7 @@ function DateRangePicker({
1141
1405
  ref: popupRef,
1142
1406
  anchorRef: rootRef,
1143
1407
  open: visible,
1144
- className: `sia-date-panel${showTime ? " sia-date-panel--datetime-range" : " sia-date-panel--range"}${presets?.length ? " sia-date-panel--with-presets" : ""}`,
1408
+ className: `sia-date-panel sia-date-panel--single-range${showTime ? " sia-date-panel--datetime" : ""}${resolvedRangePresets.length ? " sia-date-panel--with-presets" : ""}`,
1145
1409
  role: "dialog",
1146
1410
  "aria-label": "\u65E5\u671F\u8303\u56F4\u9009\u62E9\u9762\u677F",
1147
1411
  onKeyDown: (event) => {
@@ -1152,59 +1416,93 @@ function DateRangePicker({
1152
1416
  },
1153
1417
  children: [
1154
1418
  /* @__PURE__ */ jsxs2("div", { className: "sia-date-panel__body", children: [
1155
- 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,
1156
- showTime ? /* @__PURE__ */ jsxs2("div", { className: "sia-date-panel__datetime-endpoints", children: [
1157
- renderDateTimeEndpoint(0),
1158
- renderDateTimeEndpoint(1)
1159
- ] }) : /* @__PURE__ */ jsxs2("div", { className: "sia-date-panel__range-calendars", children: [
1160
- /* @__PURE__ */ jsxs2("section", { className: "sia-date-panel__calendar", children: [
1161
- /* @__PURE__ */ jsx2(
1162
- CalendarHeader,
1419
+ resolvedRangePresets.length ? /* @__PURE__ */ jsx2("aside", { className: "sia-date-panel__presets", "aria-label": "\u5FEB\u6377\u65E5\u671F\u8303\u56F4", children: resolvedRangePresets.map((preset, index) => /* @__PURE__ */ jsx2("button", { type: "button", onClick: () => applyPreset(preset), children: preset.label }, index)) }) : null,
1420
+ /* @__PURE__ */ jsxs2("section", { className: "sia-date-panel__single-range-main", "aria-label": "\u5355\u6708\u65E5\u671F\u8303\u56F4\u9762\u677F", children: [
1421
+ /* @__PURE__ */ jsxs2("div", { className: "sia-date-panel__range-tabs", role: "tablist", "aria-label": "\u5207\u6362\u8D77\u6B62\u65E5\u671F", children: [
1422
+ /* @__PURE__ */ jsxs2(
1423
+ "button",
1163
1424
  {
1164
- month: viewMonth,
1165
- range: true,
1166
- onPreviousYear: () => setViewMonth(addMonths(viewMonth, -12)),
1167
- onPreviousMonth: () => setViewMonth(addMonths(viewMonth, -1))
1425
+ type: "button",
1426
+ role: "tab",
1427
+ "aria-selected": activeIndex === 0,
1428
+ disabled: endpointDisabled[0],
1429
+ title: rangeDates[0] ? `\u5F00\u59CB\uFF1A${rangeDates[0]}` : "\u9009\u62E9\u5F00\u59CB\u65E5\u671F",
1430
+ className: `sia-date-panel__range-tab${activeIndex === 0 ? " is-active" : ""}`,
1431
+ onClick: () => {
1432
+ setPanelMode("date");
1433
+ focusEndpoint(0);
1434
+ },
1435
+ children: [
1436
+ /* @__PURE__ */ jsx2("span", { className: "sia-date-panel__range-tab-label", children: "\u5F00\u59CB" }),
1437
+ /* @__PURE__ */ jsx2("span", { className: `sia-date-panel__range-tab-value${rangeDates[0] ? "" : " is-placeholder"}`, children: rangeDates[0] || "\u672A\u9009" })
1438
+ ]
1168
1439
  }
1169
1440
  ),
1170
- /* @__PURE__ */ jsx2(CalendarMonth, { month: viewMonth, range: rangeDates, previewEnd: activeIndex === 1 ? hoverDate : "", disabledDate: isDisabled, onSelect: selectDate, onHover: activeIndex === 1 ? setHoverDate : void 0 })
1441
+ /* @__PURE__ */ jsx2("span", { className: "sia-date-panel__range-tabs-sep", "aria-hidden": "true", children: separator }),
1442
+ /* @__PURE__ */ jsxs2(
1443
+ "button",
1444
+ {
1445
+ type: "button",
1446
+ role: "tab",
1447
+ "aria-selected": activeIndex === 1,
1448
+ disabled: endpointDisabled[1],
1449
+ title: rangeDates[1] ? `\u7ED3\u675F\uFF1A${rangeDates[1]}` : "\u9009\u62E9\u7ED3\u675F\u65E5\u671F",
1450
+ className: `sia-date-panel__range-tab${activeIndex === 1 ? " is-active" : ""}`,
1451
+ onClick: () => {
1452
+ setPanelMode("date");
1453
+ focusEndpoint(1);
1454
+ },
1455
+ children: [
1456
+ /* @__PURE__ */ jsx2("span", { className: "sia-date-panel__range-tab-label", children: "\u7ED3\u675F" }),
1457
+ /* @__PURE__ */ jsx2("span", { className: `sia-date-panel__range-tab-value${rangeDates[1] ? "" : " is-placeholder"}`, children: rangeDates[1] || "\u672A\u9009" })
1458
+ ]
1459
+ }
1460
+ )
1171
1461
  ] }),
1172
- /* @__PURE__ */ jsxs2("section", { className: "sia-date-panel__calendar", children: [
1173
- /* @__PURE__ */ jsx2(
1174
- CalendarHeader,
1462
+ showTime ? /* @__PURE__ */ jsxs2("div", { className: "sia-date-panel__views", children: [
1463
+ /* @__PURE__ */ jsx2("section", { className: `sia-date-panel__view sia-date-panel__view--date${dateTimeView === "date" ? " is-active" : ""}`, "aria-hidden": dateTimeView !== "date", ...dateTimeView !== "date" ? { inert: "" } : {}, "aria-label": `${activeLabel}\u65E5\u671F`, children: renderSingleMonthCalendar() }),
1464
+ /* @__PURE__ */ jsx2("div", { className: `sia-date-panel__view sia-date-panel__view--time${dateTimeView === "time" ? " is-active" : ""}`, "aria-hidden": dateTimeView !== "time", ...dateTimeView !== "time" ? { inert: "" } : {}, children: /* @__PURE__ */ jsx2(
1465
+ TimePanel,
1175
1466
  {
1176
- month: addMonths(viewMonth, 1),
1177
- range: true,
1178
- onNextMonth: () => setViewMonth(addMonths(viewMonth, 1)),
1179
- onNextYear: () => setViewMonth(addMonths(viewMonth, 12))
1467
+ value: times[activeIndex],
1468
+ showSecond,
1469
+ title: `\u9009\u62E9${activeLabel}\u65F6\u95F4`,
1470
+ unitLabels: true,
1471
+ ariaLabel: `\u9009\u62E9${activeLabel}\u65F6\u95F4`,
1472
+ disabledTime: (candidate) => isRangeTimeDisabled(candidate, activeIndex, rangeDates, times, endpointDisabled, showSecond),
1473
+ onChange: (nextTime) => changeTime(activeIndex, nextTime)
1180
1474
  }
1181
- ),
1182
- /* @__PURE__ */ jsx2(CalendarMonth, { month: addMonths(viewMonth, 1), range: rangeDates, previewEnd: activeIndex === 1 ? hoverDate : "", disabledDate: isDisabled, onSelect: selectDate, onHover: activeIndex === 1 ? setHoverDate : void 0 })
1183
- ] })
1475
+ ) })
1476
+ ] }) : /* @__PURE__ */ jsx2("section", { className: "sia-date-panel__calendar", children: renderSingleMonthCalendar() })
1184
1477
  ] })
1185
1478
  ] }),
1186
- showTime ? renderExtraFooter || invalidDateTimeRange || maxRangeDays ? /* @__PURE__ */ jsx2(
1187
- DatePanelFooter,
1188
- {
1189
- showToday: false,
1190
- extra: /* @__PURE__ */ jsxs2(Fragment2, { children: [
1191
- renderExtraFooter?.(),
1192
- 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: [
1193
- "\u6700\u591A\u9009\u62E9 ",
1194
- maxRangeDays,
1195
- " \u5929"
1196
- ] }) : null
1197
- ] })
1198
- }
1199
- ) : null : /* @__PURE__ */ jsx2(
1479
+ showTime ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
1480
+ /* @__PURE__ */ jsx2(
1481
+ DateTimePanelFooter,
1482
+ {
1483
+ date: rangeDates[activeIndex] || dateKey(/* @__PURE__ */ new Date()),
1484
+ time: showSecond ? times[activeIndex] : times[activeIndex].slice(0, 5),
1485
+ view: dateTimeView,
1486
+ disabled: endpointDisabled[activeIndex],
1487
+ extra: renderExtraFooter?.(),
1488
+ onSwitchDate: () => setDateTimeView("date"),
1489
+ onSwitchTime: () => setDateTimeView("time")
1490
+ }
1491
+ ),
1492
+ invalidRangeMessage || maxRangeDays ? /* @__PURE__ */ jsx2("div", { className: "sia-date-panel__range-status", role: "status", children: invalidRangeMessage ? /* @__PURE__ */ jsx2("small", { className: "sia-date-panel__range-error", children: invalidRangeMessage }) : /* @__PURE__ */ jsxs2("small", { children: [
1493
+ "\u6700\u591A\u9009\u62E9 ",
1494
+ maxRangeDays,
1495
+ " \u5929"
1496
+ ] }) }) : null
1497
+ ] }) : /* @__PURE__ */ jsx2(
1200
1498
  DatePanelFooter,
1201
1499
  {
1202
- showToday: showToday && !presets?.length,
1500
+ showToday: showToday && !resolvedRangePresets.length,
1203
1501
  needConfirm: resolvedNeedConfirm || allowEmpty.some(Boolean),
1204
1502
  disabledConfirm: !isValidRange(draftValue),
1205
1503
  extra: /* @__PURE__ */ jsxs2(Fragment2, { children: [
1206
1504
  renderExtraFooter?.(),
1207
- 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: [
1505
+ invalidRangeMessage ? /* @__PURE__ */ jsx2("small", { className: "sia-date-panel__range-error", children: invalidRangeMessage }) : maxRangeDays ? /* @__PURE__ */ jsxs2("small", { children: [
1208
1506
  "\u6700\u591A\u9009\u62E9 ",
1209
1507
  maxRangeDays,
1210
1508
  " \u5929"
@@ -1213,7 +1511,7 @@ function DateRangePicker({
1213
1511
  onToday: () => {
1214
1512
  const now = /* @__PURE__ */ new Date();
1215
1513
  const day = dateKey(now);
1216
- if (isDisabled(day, activeIndex, Boolean(showTime))) return;
1514
+ if (isDisabled(day, activeIndex)) return;
1217
1515
  setViewMonth(startOfMonth(now));
1218
1516
  selectDate(day);
1219
1517
  },
@@ -1224,10 +1522,11 @@ function DateRangePicker({
1224
1522
  }
1225
1523
  )
1226
1524
  ] });
1227
- }
1228
- ((DatePicker2) => {
1229
- DatePicker2.RangePicker = DateRangePicker;
1230
- })(DatePicker || (DatePicker = {}));
1525
+ });
1526
+ var DatePicker2 = Object.assign(DatePickerRoot, {
1527
+ /** 日期区间选择器;采用单月面板与顶部起止端点切换栏(显示完整年月日),支持点击日历头部年份/月份分别进入年份和月份选择面板;修改起点且不晚于已有终点时保留原终点,晚于已有终点时清空终点并切到结束端(悬停实时预览范围,点早于起点自动交换);带时间时底部页脚在单月日历与当前端点时间视图间切换,同日起止自动校验时间先后并禁用非法时刻。 */
1528
+ RangePicker: DateRangePicker
1529
+ });
1231
1530
 
1232
1531
  // src/components/SelectDateRange.tsx
1233
1532
  import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
@@ -1273,7 +1572,7 @@ function SelectDateRange({
1273
1572
  }
1274
1573
  ),
1275
1574
  /* @__PURE__ */ jsx3(
1276
- DatePicker.RangePicker,
1575
+ DatePicker2.RangePicker,
1277
1576
  {
1278
1577
  className: "sia-select-date-range__picker",
1279
1578
  "aria-label": rangeAriaLabel,
@@ -1292,6 +1591,6 @@ function SelectDateRange({
1292
1591
 
1293
1592
  export {
1294
1593
  TimePanel,
1295
- DatePicker,
1594
+ DatePicker2 as DatePicker,
1296
1595
  SelectDateRange
1297
1596
  };