@sia.soul/sia-react-ui 0.1.160 → 0.1.163
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.
- package/dist/{Select-DIdEbGwf.d.cts → Select-Dxevc0f6.d.cts} +1 -1
- package/dist/{Select-BCVUoK0I.d.ts → Select-tsENCXQI.d.ts} +1 -1
- package/dist/chart.cjs +10 -10
- package/dist/chart.js +5 -5
- package/dist/{chunk-EMBCJFJM.js → chunk-23FQ5ARA.js} +4 -4
- package/dist/{chunk-H6UTSSZM.js → chunk-2EC653G5.js} +5 -5
- package/dist/{chunk-SRWUDTCS.js → chunk-CUAXJCSH.js} +10 -10
- package/dist/{chunk-KDIJYXKW.js → chunk-DKQ5UCN6.js} +618 -273
- package/dist/{chunk-ZIH5VLPT.js → chunk-G5EJJFUI.js} +2 -2
- package/dist/{chunk-NRLIOMXY.js → chunk-J6BPKBEL.js} +2 -2
- package/dist/{chunk-6SSZVJO4.js → chunk-NHGCGOF2.js} +3 -3
- package/dist/{chunk-YO5OJQEH.js → chunk-OHAESA5R.js} +1 -1
- package/dist/{chunk-PU2V3VB5.js → chunk-PAWEP65C.js} +1 -1
- package/dist/{chunk-REAWVQH2.js → chunk-SX4LLT3H.js} +5 -5
- package/dist/{chunk-XXFYFLZA.js → chunk-V4I32DPL.js} +2 -2
- package/dist/{chunk-P5ZCOIKQ.js → chunk-WR5YBY2A.js} +6 -6
- package/dist/{core--AEiGVOU.d.ts → core-XtqUDbbD.d.ts} +3 -3
- package/dist/{core-DolUEUCo.d.cts → core-r-smfiNN.d.cts} +3 -3
- package/dist/core.cjs +10 -10
- package/dist/core.css +245 -29
- package/dist/core.d.cts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.js +8 -8
- package/dist/game.cjs +10 -10
- package/dist/game.js +3 -3
- package/dist/index.cjs +666 -320
- package/dist/index.css +245 -29
- package/dist/index.d.cts +13 -8
- package/dist/index.d.ts +13 -8
- package/dist/index.js +60 -59
- package/dist/markdown-editor.cjs +10 -10
- package/dist/markdown-editor.js +3 -3
- package/dist/rich-text-editor.cjs +10 -10
- package/dist/rich-text-editor.js +7 -7
- package/dist/{select-date-range-CIwE5nFu.d.cts → select-date-range-C9lTBQFX.d.cts} +10 -11
- package/dist/{select-date-range-DYrA87Tl.d.ts → select-date-range-CQCGGkkt.d.ts} +10 -11
- package/dist/select-date-range.cjs +618 -273
- package/dist/select-date-range.d.cts +2 -2
- package/dist/select-date-range.d.ts +2 -2
- package/dist/select-date-range.js +8 -8
- package/package.json +1 -1
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Select
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SX4LLT3H.js";
|
|
4
4
|
import {
|
|
5
5
|
Icon
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-G5EJJFUI.js";
|
|
7
7
|
import {
|
|
8
8
|
useFloatingPlaceholder
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-OHAESA5R.js";
|
|
10
10
|
import {
|
|
11
11
|
FloatingScrollbarProvider,
|
|
12
12
|
PopupPortal,
|
|
13
13
|
useControlSize,
|
|
14
14
|
useControllableState,
|
|
15
15
|
withTitleTooltip
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-CUAXJCSH.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,63 @@ 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(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
+
const segmentStart = inRange && (index % 7 === 0 || key === low);
|
|
158
|
+
const segmentEnd = inRange && (index % 7 === 6 || key === high);
|
|
159
|
+
return /* @__PURE__ */ jsx(
|
|
160
|
+
"span",
|
|
105
161
|
{
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
162
|
+
className: `sia-date-panel__cell${outside ? " is-outside" : ""}${selected ? " is-selected" : ""}${rangeStart ? " is-range-start" : ""}${rangeEnd ? " is-range-end" : ""}${inRange ? " is-in-range" : ""}${segmentStart ? " is-range-segment-start" : ""}${segmentEnd ? " is-range-segment-end" : ""}${key === today ? " is-today" : ""}`,
|
|
163
|
+
children: /* @__PURE__ */ jsx(
|
|
164
|
+
"button",
|
|
165
|
+
{
|
|
166
|
+
type: "button",
|
|
167
|
+
"aria-label": key,
|
|
168
|
+
"aria-pressed": selected || rangeStart || rangeEnd || void 0,
|
|
169
|
+
disabled,
|
|
170
|
+
onClick: () => onSelect(key),
|
|
171
|
+
onMouseEnter: () => onHover?.(key),
|
|
172
|
+
children: date.getDate()
|
|
173
|
+
}
|
|
174
|
+
)
|
|
175
|
+
},
|
|
176
|
+
key
|
|
177
|
+
);
|
|
178
|
+
}) })
|
|
179
|
+
]
|
|
180
|
+
}
|
|
181
|
+
);
|
|
120
182
|
}
|
|
121
183
|
function CalendarHeader({
|
|
122
184
|
month,
|
|
123
185
|
label,
|
|
124
186
|
range = false,
|
|
187
|
+
onTitleClick,
|
|
125
188
|
onPreviousYear,
|
|
126
189
|
onPreviousMonth,
|
|
127
190
|
onNextMonth,
|
|
@@ -135,7 +198,15 @@ function CalendarHeader({
|
|
|
135
198
|
] }) : null,
|
|
136
199
|
onPreviousMonth ? /* @__PURE__ */ jsx("button", { type: "button", "aria-label": "\u4E0A\u4E2A\u6708", onClick: onPreviousMonth, children: /* @__PURE__ */ jsx(Icon, { name: "chevron-left", size: 15 }) }) : null
|
|
137
200
|
] }),
|
|
138
|
-
/* @__PURE__ */ jsxs("
|
|
201
|
+
onTitleClick ? /* @__PURE__ */ jsxs("button", { type: "button", className: "sia-date-panel__title", "aria-label": "\u9009\u62E9\u5E74\u4EFD", onClick: onTitleClick, children: [
|
|
202
|
+
label ? /* @__PURE__ */ jsx("small", { children: label }) : null,
|
|
203
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
204
|
+
month.getFullYear(),
|
|
205
|
+
"\u5E74\xA0 ",
|
|
206
|
+
month.getMonth() + 1,
|
|
207
|
+
"\u6708"
|
|
208
|
+
] })
|
|
209
|
+
] }) : /* @__PURE__ */ jsxs("strong", { children: [
|
|
139
210
|
label ? /* @__PURE__ */ jsx("small", { children: label }) : null,
|
|
140
211
|
/* @__PURE__ */ jsxs("span", { children: [
|
|
141
212
|
month.getFullYear(),
|
|
@@ -154,36 +225,146 @@ function CalendarHeader({
|
|
|
154
225
|
range ? null : null
|
|
155
226
|
] });
|
|
156
227
|
}
|
|
228
|
+
var TIME_OPTION_HEIGHT = 32;
|
|
229
|
+
var TIME_COLUMN_PADDING = 4;
|
|
230
|
+
function TimeColumn({
|
|
231
|
+
ariaLabel,
|
|
232
|
+
columnIndex,
|
|
233
|
+
count,
|
|
234
|
+
value,
|
|
235
|
+
siblings,
|
|
236
|
+
use12Hours = false,
|
|
237
|
+
unit = "",
|
|
238
|
+
unitLabels = false,
|
|
239
|
+
disabledTime,
|
|
240
|
+
onSelect
|
|
241
|
+
}) {
|
|
242
|
+
const listRef = useRef(null);
|
|
243
|
+
const drag = useRef({ startY: 0, startScroll: 0, pointerId: -1, dragging: false, samples: [], velocity: 0, frame: 0 });
|
|
244
|
+
useLayoutEffect(() => {
|
|
245
|
+
const column = listRef.current;
|
|
246
|
+
const selected = column?.querySelector('[aria-selected="true"]');
|
|
247
|
+
const first = column?.firstElementChild;
|
|
248
|
+
if (!column || !selected || !first) return;
|
|
249
|
+
const top = selected.offsetTop - first.offsetTop + parseFloat(getComputedStyle(column).paddingTop || "0");
|
|
250
|
+
const bottom = top + selected.offsetHeight;
|
|
251
|
+
if (top < column.scrollTop || bottom > column.scrollTop + column.clientHeight) {
|
|
252
|
+
column.scrollTop = Math.max(0, top - (column.clientHeight - selected.offsetHeight) / 2);
|
|
253
|
+
}
|
|
254
|
+
}, [value, count]);
|
|
255
|
+
useEffect(() => () => cancelAnimationFrame(drag.current.frame), []);
|
|
256
|
+
function stopWithSnap() {
|
|
257
|
+
const column = listRef.current;
|
|
258
|
+
if (!column) return;
|
|
259
|
+
const snapped = Math.round((column.scrollTop - TIME_COLUMN_PADDING) / TIME_OPTION_HEIGHT) * TIME_OPTION_HEIGHT + TIME_COLUMN_PADDING;
|
|
260
|
+
const max = column.scrollHeight - column.clientHeight;
|
|
261
|
+
column.scrollTo({ top: Math.max(0, Math.min(max, snapped)), behavior: "smooth" });
|
|
262
|
+
}
|
|
263
|
+
function onPointerDown(event) {
|
|
264
|
+
if (event.button !== 0) return;
|
|
265
|
+
const column = listRef.current;
|
|
266
|
+
if (!column) return;
|
|
267
|
+
drag.current = { startY: event.clientY, startScroll: column.scrollTop, pointerId: event.pointerId, dragging: false, samples: [event.timeStamp, event.clientY], velocity: 0, frame: 0 };
|
|
268
|
+
}
|
|
269
|
+
function onPointerMove(event) {
|
|
270
|
+
const state = drag.current;
|
|
271
|
+
const column = listRef.current;
|
|
272
|
+
if (state.pointerId !== event.pointerId || !column) return;
|
|
273
|
+
const dy = event.clientY - state.startY;
|
|
274
|
+
if (!state.dragging && Math.abs(dy) > 4) {
|
|
275
|
+
state.dragging = true;
|
|
276
|
+
try {
|
|
277
|
+
column.setPointerCapture(event.pointerId);
|
|
278
|
+
} catch {
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (!state.dragging) return;
|
|
282
|
+
column.scrollTop = state.startScroll - dy;
|
|
283
|
+
state.samples.push(event.timeStamp, event.clientY);
|
|
284
|
+
while (state.samples.length > 4 && event.timeStamp - state.samples[0] > 100) state.samples.splice(0, 2);
|
|
285
|
+
}
|
|
286
|
+
function onPointerUp(event) {
|
|
287
|
+
const state = drag.current;
|
|
288
|
+
const column = listRef.current;
|
|
289
|
+
if (state.pointerId !== event.pointerId || !column) return;
|
|
290
|
+
state.pointerId = -1;
|
|
291
|
+
try {
|
|
292
|
+
column.releasePointerCapture?.(event.pointerId);
|
|
293
|
+
} catch {
|
|
294
|
+
}
|
|
295
|
+
if (!state.dragging) return;
|
|
296
|
+
const samples = state.samples;
|
|
297
|
+
const dt = samples[samples.length - 2] - samples[0];
|
|
298
|
+
const dy = samples[samples.length - 1] - samples[1];
|
|
299
|
+
let velocity = dt > 4 ? dy / dt : 0;
|
|
300
|
+
velocity = Math.max(-2.5, Math.min(2.5, velocity));
|
|
301
|
+
cancelAnimationFrame(state.frame);
|
|
302
|
+
let last = performance.now();
|
|
303
|
+
const step = (now) => {
|
|
304
|
+
const elapsed = Math.min(32, now - last);
|
|
305
|
+
last = now;
|
|
306
|
+
column.scrollTop -= velocity * elapsed;
|
|
307
|
+
velocity *= Math.pow(0.94, elapsed / 16.7);
|
|
308
|
+
if (Math.abs(velocity) > 0.04) state.frame = requestAnimationFrame(step);
|
|
309
|
+
else stopWithSnap();
|
|
310
|
+
};
|
|
311
|
+
state.frame = requestAnimationFrame(step);
|
|
312
|
+
}
|
|
313
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
314
|
+
/* @__PURE__ */ jsx(
|
|
315
|
+
"div",
|
|
316
|
+
{
|
|
317
|
+
ref: listRef,
|
|
318
|
+
role: "listbox",
|
|
319
|
+
"aria-label": ariaLabel,
|
|
320
|
+
onPointerDown,
|
|
321
|
+
onPointerMove,
|
|
322
|
+
onPointerUp,
|
|
323
|
+
onPointerCancel: onPointerUp,
|
|
324
|
+
onClickCapture: (event) => {
|
|
325
|
+
if (!drag.current.dragging) return;
|
|
326
|
+
event.preventDefault();
|
|
327
|
+
event.stopPropagation();
|
|
328
|
+
drag.current.dragging = false;
|
|
329
|
+
},
|
|
330
|
+
children: Array.from({ length: count }, (_, index) => {
|
|
331
|
+
const next = pad(index);
|
|
332
|
+
const candidate = [...siblings];
|
|
333
|
+
candidate[columnIndex] = next;
|
|
334
|
+
const selected = next === value;
|
|
335
|
+
return /* @__PURE__ */ jsxs("button", { type: "button", role: "option", disabled: disabledTime?.(candidate.join(":")), "aria-selected": selected, className: selected ? "is-selected" : "", onKeyDown: (event) => {
|
|
336
|
+
if (!["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) return;
|
|
337
|
+
event.preventDefault();
|
|
338
|
+
const buttons = Array.from(event.currentTarget.parentElement.querySelectorAll("button:not(:disabled)"));
|
|
339
|
+
const position = buttons.indexOf(event.currentTarget);
|
|
340
|
+
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)));
|
|
341
|
+
buttons[target]?.focus();
|
|
342
|
+
}, onClick: () => onSelect(next), children: [
|
|
343
|
+
use12Hours && columnIndex === 0 ? `${pad(index % 12 || 12)} ${index < 12 ? "AM" : "PM"}` : next,
|
|
344
|
+
unitLabels && selected ? unit : ""
|
|
345
|
+
] }, next);
|
|
346
|
+
})
|
|
347
|
+
}
|
|
348
|
+
),
|
|
349
|
+
/* @__PURE__ */ jsx(FloatingScrollbarProvider, { targetRef: listRef })
|
|
350
|
+
] });
|
|
351
|
+
}
|
|
157
352
|
function TimePanel({
|
|
158
353
|
value,
|
|
159
354
|
showSecond = false,
|
|
160
355
|
ariaLabel = "\u65F6\u95F4",
|
|
161
356
|
disabledTime,
|
|
162
357
|
use12Hours = false,
|
|
358
|
+
title,
|
|
359
|
+
unitLabels = false,
|
|
163
360
|
onChange
|
|
164
361
|
}) {
|
|
165
362
|
const [hour = "00", minute = "00", second = "00"] = value.split(":");
|
|
166
|
-
const
|
|
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]);
|
|
363
|
+
const siblings = [hour, minute, second];
|
|
183
364
|
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 }] : []
|
|
365
|
+
{ label: "\u5C0F\u65F6", unit: "\u65F6", value: hour, count: 24, index: 0 },
|
|
366
|
+
{ label: "\u5206\u949F", unit: "\u5206", value: minute, count: 60, index: 1 },
|
|
367
|
+
...showSecond ? [{ label: "\u79D2", unit: "\u79D2", value: second, count: 60, index: 2 }] : []
|
|
187
368
|
];
|
|
188
369
|
function update(index, next) {
|
|
189
370
|
const values = [hour, minute, second];
|
|
@@ -191,27 +372,29 @@ function TimePanel({
|
|
|
191
372
|
onChange(values.join(":"));
|
|
192
373
|
}
|
|
193
374
|
return /* @__PURE__ */ jsxs("aside", { className: "sia-date-panel__time", "aria-label": ariaLabel, children: [
|
|
194
|
-
/* @__PURE__ */ jsxs("strong", { children: [
|
|
375
|
+
title != null ? /* @__PURE__ */ jsx("strong", { className: "sia-date-panel__time-title", children: title }) : /* @__PURE__ */ jsxs("strong", { children: [
|
|
195
376
|
use12Hours ? pad(Number(hour) % 12 || 12) : hour,
|
|
196
377
|
":",
|
|
197
378
|
minute,
|
|
198
379
|
showSecond ? `:${second}` : "",
|
|
199
380
|
use12Hours ? Number(hour) < 12 ? " AM" : " PM" : ""
|
|
200
381
|
] }),
|
|
201
|
-
/* @__PURE__ */ jsx("div", {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
382
|
+
/* @__PURE__ */ jsx("div", { className: "sia-date-panel__time-columns", children: columns.map((column) => /* @__PURE__ */ jsx(
|
|
383
|
+
TimeColumn,
|
|
384
|
+
{
|
|
385
|
+
ariaLabel: `${ariaLabel}${column.label}`,
|
|
386
|
+
columnIndex: column.index,
|
|
387
|
+
count: column.count,
|
|
388
|
+
value: column.value,
|
|
389
|
+
siblings,
|
|
390
|
+
use12Hours,
|
|
391
|
+
unit: column.unit,
|
|
392
|
+
unitLabels,
|
|
393
|
+
disabledTime,
|
|
394
|
+
onSelect: (next) => update(column.index, next)
|
|
395
|
+
},
|
|
396
|
+
column.label
|
|
397
|
+
)) })
|
|
215
398
|
] });
|
|
216
399
|
}
|
|
217
400
|
function DatePanelFooter({
|
|
@@ -231,9 +414,53 @@ function DatePanelFooter({
|
|
|
231
414
|
needConfirm ? /* @__PURE__ */ jsx("button", { type: "button", className: "sia-date-panel__confirm", disabled: disabledConfirm, onClick: onConfirm, children: confirmText }) : null
|
|
232
415
|
] });
|
|
233
416
|
}
|
|
417
|
+
function DateTimePanelFooter({
|
|
418
|
+
date,
|
|
419
|
+
time,
|
|
420
|
+
view,
|
|
421
|
+
disabled = false,
|
|
422
|
+
extra,
|
|
423
|
+
onSwitchDate,
|
|
424
|
+
onSwitchTime,
|
|
425
|
+
onClearTime
|
|
426
|
+
}) {
|
|
427
|
+
return /* @__PURE__ */ jsxs("footer", { className: "sia-date-panel__footer sia-date-panel__footer--datetime", children: [
|
|
428
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
429
|
+
/* @__PURE__ */ jsxs("button", { type: "button", className: "sia-date-panel__chip", "aria-pressed": view === "date" || void 0, disabled, onClick: onSwitchDate, children: [
|
|
430
|
+
/* @__PURE__ */ jsx(Icon, { name: "calendar", size: 14, "aria-hidden": "true" }),
|
|
431
|
+
date
|
|
432
|
+
] }),
|
|
433
|
+
extra
|
|
434
|
+
] }),
|
|
435
|
+
/* @__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: [
|
|
436
|
+
/* @__PURE__ */ jsx(Icon, { name: "clock", size: 14, "aria-hidden": "true" }),
|
|
437
|
+
time,
|
|
438
|
+
onClearTime && !disabled ? /* @__PURE__ */ jsx(
|
|
439
|
+
"span",
|
|
440
|
+
{
|
|
441
|
+
role: "button",
|
|
442
|
+
tabIndex: 0,
|
|
443
|
+
"aria-label": "\u6E05\u7A7A\u65F6\u95F4",
|
|
444
|
+
className: "sia-date-panel__chip-clear",
|
|
445
|
+
onClick: (event) => {
|
|
446
|
+
event.stopPropagation();
|
|
447
|
+
onClearTime();
|
|
448
|
+
},
|
|
449
|
+
onKeyDown: (event) => {
|
|
450
|
+
if (event.key !== "Enter" && event.key !== " ") return;
|
|
451
|
+
event.preventDefault();
|
|
452
|
+
event.stopPropagation();
|
|
453
|
+
onClearTime();
|
|
454
|
+
},
|
|
455
|
+
children: /* @__PURE__ */ jsx(Icon, { name: "circle-close", variant: "filled", size: 13, "aria-hidden": "true" })
|
|
456
|
+
}
|
|
457
|
+
) : null
|
|
458
|
+
] })
|
|
459
|
+
] });
|
|
460
|
+
}
|
|
234
461
|
|
|
235
462
|
// src/components/DatePicker.tsx
|
|
236
|
-
import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
463
|
+
import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
237
464
|
function formatWeek(date) {
|
|
238
465
|
const target = new Date(date);
|
|
239
466
|
target.setHours(0, 0, 0, 0);
|
|
@@ -280,6 +507,12 @@ function resolvePreset(value) {
|
|
|
280
507
|
function resolveRangePreset(value) {
|
|
281
508
|
return typeof value === "function" ? value() : value;
|
|
282
509
|
}
|
|
510
|
+
function hasExplicitTime(value) {
|
|
511
|
+
return /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}/.test(String(value ?? ""));
|
|
512
|
+
}
|
|
513
|
+
function isZeroTime(time, showSecond) {
|
|
514
|
+
return showSecond ? time === "00:00:00" : time.slice(0, 5) === "00:00";
|
|
515
|
+
}
|
|
283
516
|
function DatePicker({
|
|
284
517
|
value,
|
|
285
518
|
defaultValue,
|
|
@@ -319,13 +552,17 @@ function DatePicker({
|
|
|
319
552
|
const firstCurrent = Array.isArray(currentValue) ? currentValue[0] : currentValue;
|
|
320
553
|
const [viewMonth, setViewMonth] = useState(() => startOfMonth(parseDate(dayFromValue(firstCurrent)) ?? /* @__PURE__ */ new Date()));
|
|
321
554
|
const [draftTime, setDraftTime] = useState(() => timePart(firstCurrent, defaultTimeFrom(showTime)));
|
|
322
|
-
const
|
|
555
|
+
const showTimeDefaultProvided = typeof showTime === "object" && showTime.defaultValue !== void 0;
|
|
556
|
+
const [timeExplicit, setTimeExplicit] = useState(() => showTimeDefaultProvided || hasExplicitTime(typeof initialValue === "string" ? initialValue : void 0));
|
|
557
|
+
const [dateTimeView, setDateTimeView] = useState("date");
|
|
558
|
+
const [yearDrill, setYearDrill] = useState(false);
|
|
559
|
+
const resolvedNeedConfirm = showTime ? false : Boolean(needConfirm);
|
|
323
560
|
const showSecond = showSecondFrom(showTime);
|
|
324
561
|
const selectedDates = useMemo(() => {
|
|
325
562
|
const values = Array.isArray(draftValue) ? draftValue : draftValue ? [draftValue] : [];
|
|
326
563
|
return values.map(dayFromValue).filter(Boolean);
|
|
327
564
|
}, [draftValue]);
|
|
328
|
-
|
|
565
|
+
useEffect2(() => {
|
|
329
566
|
if (!visible) return void 0;
|
|
330
567
|
const close = (event) => {
|
|
331
568
|
const target = event.target;
|
|
@@ -340,6 +577,9 @@ function DatePicker({
|
|
|
340
577
|
const current = Array.isArray(currentValue) ? currentValue[0] : currentValue;
|
|
341
578
|
setViewMonth(startOfMonth(parseDate(dayFromValue(current)) ?? /* @__PURE__ */ new Date()));
|
|
342
579
|
setDraftTime(timePart(current, defaultTimeFrom(showTime)));
|
|
580
|
+
setTimeExplicit(showTimeDefaultProvided || hasExplicitTime(typeof current === "string" ? current : void 0));
|
|
581
|
+
setDateTimeView("date");
|
|
582
|
+
setYearDrill(false);
|
|
343
583
|
}
|
|
344
584
|
setVisible(next);
|
|
345
585
|
}
|
|
@@ -351,9 +591,11 @@ function DatePicker({
|
|
|
351
591
|
if (maximum && day.slice(0, length) > String(maximum).slice(0, length)) return true;
|
|
352
592
|
return disabledDate?.(day, { type: "date" }) ?? false;
|
|
353
593
|
}
|
|
354
|
-
function buildValue(day, time = draftTime) {
|
|
594
|
+
function buildValue(day, time = draftTime, explicit = timeExplicit) {
|
|
355
595
|
const picked = formatPickerValue(day, picker);
|
|
356
|
-
|
|
596
|
+
if (!(showTime && picker === "date")) return picked;
|
|
597
|
+
if (!explicit && isZeroTime(time, showSecond)) return picked;
|
|
598
|
+
return withTime(picked, time, showSecond);
|
|
357
599
|
}
|
|
358
600
|
function selectDate(day, time = draftTime, ensureSelected = false) {
|
|
359
601
|
if (isDisabled(day)) return;
|
|
@@ -369,7 +611,7 @@ function DatePicker({
|
|
|
369
611
|
setDraftValue(nextValue);
|
|
370
612
|
if (!resolvedNeedConfirm) {
|
|
371
613
|
setCurrentValue(nextValue);
|
|
372
|
-
changeOpen(false);
|
|
614
|
+
if (!showTime) changeOpen(false);
|
|
373
615
|
}
|
|
374
616
|
}
|
|
375
617
|
function commitDraft() {
|
|
@@ -378,6 +620,72 @@ function DatePicker({
|
|
|
378
620
|
setCurrentValue(draftValue);
|
|
379
621
|
changeOpen(false);
|
|
380
622
|
}
|
|
623
|
+
function applyDraftTime(next) {
|
|
624
|
+
setDraftTime(next);
|
|
625
|
+
setTimeExplicit(true);
|
|
626
|
+
const day = typeof draftValue === "string" ? dayFromValue(draftValue) : "";
|
|
627
|
+
if (!day) return;
|
|
628
|
+
const nextValue = withTime(day, next, showSecond);
|
|
629
|
+
setDraftValue(nextValue);
|
|
630
|
+
setCurrentValue(nextValue);
|
|
631
|
+
}
|
|
632
|
+
function clearDraftTime() {
|
|
633
|
+
setDraftTime("00:00:00");
|
|
634
|
+
setTimeExplicit(false);
|
|
635
|
+
const day = typeof draftValue === "string" ? dayFromValue(draftValue) : "";
|
|
636
|
+
if (!day) return;
|
|
637
|
+
setDraftValue(day);
|
|
638
|
+
setCurrentValue(day);
|
|
639
|
+
}
|
|
640
|
+
function renderCalendarSection() {
|
|
641
|
+
return picker === "year" || yearDrill ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
642
|
+
/* @__PURE__ */ jsxs2("div", { className: "sia-date-panel__header", children: [
|
|
643
|
+
/* @__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 }) }) }),
|
|
644
|
+
/* @__PURE__ */ jsxs2("strong", { children: [
|
|
645
|
+
Math.floor(viewMonth.getFullYear() / 10) * 10,
|
|
646
|
+
"\u5E74 \u2014 ",
|
|
647
|
+
Math.floor(viewMonth.getFullYear() / 10) * 10 + 9,
|
|
648
|
+
"\u5E74"
|
|
649
|
+
] }),
|
|
650
|
+
/* @__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 }) }) })
|
|
651
|
+
] }),
|
|
652
|
+
/* @__PURE__ */ jsx2("div", { className: "sia-date-panel__years", children: Array.from({ length: 10 }, (_, index) => {
|
|
653
|
+
const year = String(Math.floor(viewMonth.getFullYear() / 10) * 10 + index);
|
|
654
|
+
const day = `${year}-01-01`;
|
|
655
|
+
const selected = selectedDates.some((value2) => value2.slice(0, 4) === year);
|
|
656
|
+
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: () => {
|
|
657
|
+
if (yearDrill) {
|
|
658
|
+
setViewMonth(new Date(Number(year), viewMonth.getMonth(), 1));
|
|
659
|
+
setYearDrill(false);
|
|
660
|
+
} else {
|
|
661
|
+
selectDate(day);
|
|
662
|
+
}
|
|
663
|
+
}, children: year }) }, year);
|
|
664
|
+
}) })
|
|
665
|
+
] }) : /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
666
|
+
/* @__PURE__ */ jsx2(
|
|
667
|
+
CalendarHeader,
|
|
668
|
+
{
|
|
669
|
+
month: viewMonth,
|
|
670
|
+
onTitleClick: picker === "date" ? () => setYearDrill(true) : void 0,
|
|
671
|
+
onPreviousYear: () => setViewMonth(addMonths(viewMonth, -12)),
|
|
672
|
+
onPreviousMonth: () => setViewMonth(addMonths(viewMonth, -1)),
|
|
673
|
+
onNextMonth: () => setViewMonth(addMonths(viewMonth, 1)),
|
|
674
|
+
onNextYear: () => setViewMonth(addMonths(viewMonth, 12))
|
|
675
|
+
}
|
|
676
|
+
),
|
|
677
|
+
/* @__PURE__ */ jsx2(
|
|
678
|
+
CalendarMonth,
|
|
679
|
+
{
|
|
680
|
+
month: viewMonth,
|
|
681
|
+
selectedDates,
|
|
682
|
+
disabledDate: isDisabled,
|
|
683
|
+
onSelect: selectDate,
|
|
684
|
+
onSwipeMonth: picker === "date" ? (direction) => setViewMonth(addMonths(viewMonth, direction)) : void 0
|
|
685
|
+
}
|
|
686
|
+
)
|
|
687
|
+
] });
|
|
688
|
+
}
|
|
381
689
|
function clearValue(event) {
|
|
382
690
|
event.stopPropagation();
|
|
383
691
|
const empty = multiple ? [] : "";
|
|
@@ -417,72 +725,82 @@ function DatePicker({
|
|
|
417
725
|
),
|
|
418
726
|
floating.label,
|
|
419
727
|
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(
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
728
|
+
/* @__PURE__ */ jsxs2(
|
|
729
|
+
PopupPortal,
|
|
730
|
+
{
|
|
731
|
+
ref: popupRef,
|
|
732
|
+
anchorRef: rootRef,
|
|
733
|
+
open: visible,
|
|
734
|
+
className: `sia-date-panel${showTime ? " sia-date-panel--datetime" : ""}${presets?.length ? " sia-date-panel--with-presets" : ""}`,
|
|
735
|
+
role: "dialog",
|
|
736
|
+
"aria-label": "\u65E5\u671F\u9009\u62E9\u9762\u677F",
|
|
737
|
+
onKeyDown: (event) => {
|
|
738
|
+
if (event.key === "Escape") {
|
|
739
|
+
event.stopPropagation();
|
|
428
740
|
changeOpen(false);
|
|
429
741
|
}
|
|
430
|
-
},
|
|
431
|
-
|
|
432
|
-
/* @__PURE__ */ jsxs2("div", { className: "sia-date-
|
|
433
|
-
/* @__PURE__ */ jsx2("
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
742
|
+
},
|
|
743
|
+
children: [
|
|
744
|
+
/* @__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;
|
|
748
|
+
setDraftValue(next);
|
|
749
|
+
setDraftTime(timePart(next, defaultTimeFrom(showTime)));
|
|
750
|
+
setTimeExplicit(hasExplicitTime(next));
|
|
751
|
+
if (!resolvedNeedConfirm) {
|
|
752
|
+
setCurrentValue(next);
|
|
753
|
+
changeOpen(false);
|
|
754
|
+
}
|
|
755
|
+
}, children: preset.label }, index)) }) : null,
|
|
756
|
+
showTime ? /* @__PURE__ */ jsxs2("div", { className: "sia-date-panel__views", children: [
|
|
757
|
+
/* @__PURE__ */ jsx2("section", { className: `sia-date-panel__view sia-date-panel__view--date${dateTimeView === "date" ? " is-active" : ""}`, "aria-hidden": dateTimeView !== "date", children: renderCalendarSection() }),
|
|
758
|
+
/* @__PURE__ */ jsx2("div", { className: `sia-date-panel__view sia-date-panel__view--time${dateTimeView === "time" ? " is-active" : ""}`, "aria-hidden": dateTimeView !== "time", children: /* @__PURE__ */ jsx2(
|
|
759
|
+
TimePanel,
|
|
760
|
+
{
|
|
761
|
+
value: draftTime,
|
|
762
|
+
showSecond,
|
|
763
|
+
title: "\u9009\u62E9\u65F6\u95F4",
|
|
764
|
+
unitLabels: true,
|
|
765
|
+
ariaLabel: "\u9009\u62E9\u65F6\u95F4",
|
|
766
|
+
onChange: applyDraftTime
|
|
767
|
+
}
|
|
768
|
+
) })
|
|
769
|
+
] }) : /* @__PURE__ */ jsx2("section", { className: "sia-date-panel__calendar", children: renderCalendarSection() })
|
|
441
770
|
] }),
|
|
442
|
-
/* @__PURE__ */ jsx2(
|
|
443
|
-
|
|
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,
|
|
771
|
+
showTime ? /* @__PURE__ */ jsx2(
|
|
772
|
+
DateTimePanelFooter,
|
|
451
773
|
{
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
774
|
+
date: (typeof draftValue === "string" ? dayFromValue(draftValue) : "") || dateKey(/* @__PURE__ */ new Date()),
|
|
775
|
+
time: showSecond ? draftTime : draftTime.slice(0, 5),
|
|
776
|
+
view: dateTimeView,
|
|
777
|
+
extra: renderExtraFooter?.(),
|
|
778
|
+
onSwitchDate: () => setDateTimeView("date"),
|
|
779
|
+
onSwitchTime: () => setDateTimeView("time"),
|
|
780
|
+
onClearTime: clearDraftTime
|
|
457
781
|
}
|
|
458
|
-
)
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
selectDate(day, time, true);
|
|
481
|
-
},
|
|
482
|
-
onConfirm: commitDraft
|
|
483
|
-
}
|
|
484
|
-
)
|
|
485
|
-
] })
|
|
782
|
+
) : /* @__PURE__ */ jsx2(
|
|
783
|
+
DatePanelFooter,
|
|
784
|
+
{
|
|
785
|
+
extra: renderExtraFooter?.(),
|
|
786
|
+
showToday,
|
|
787
|
+
needConfirm: resolvedNeedConfirm,
|
|
788
|
+
disabledConfirm: Array.isArray(draftValue) ? draftValue.length === 0 : !draftValue,
|
|
789
|
+
onToday: () => {
|
|
790
|
+
const now = /* @__PURE__ */ new Date();
|
|
791
|
+
const day = dateKey(now);
|
|
792
|
+
if (isDisabled(day)) return;
|
|
793
|
+
const time = [now.getHours(), now.getMinutes(), now.getSeconds()].map(pad).join(":");
|
|
794
|
+
if (showTime) setDraftTime(time);
|
|
795
|
+
setViewMonth(startOfMonth(now));
|
|
796
|
+
selectDate(day, time, true);
|
|
797
|
+
},
|
|
798
|
+
onConfirm: commitDraft
|
|
799
|
+
}
|
|
800
|
+
)
|
|
801
|
+
]
|
|
802
|
+
}
|
|
803
|
+
)
|
|
486
804
|
] });
|
|
487
805
|
}
|
|
488
806
|
function DateRangePicker({
|
|
@@ -542,11 +860,10 @@ function DateRangePicker({
|
|
|
542
860
|
}
|
|
543
861
|
return () => observer.disconnect();
|
|
544
862
|
});
|
|
545
|
-
const [
|
|
546
|
-
const [presetSelected, setPresetSelected] = useState(false);
|
|
863
|
+
const [dateTimeViews, setDateTimeViews] = useState(["date", "date"]);
|
|
547
864
|
const [hoverDate, setHoverDate] = useState("");
|
|
548
865
|
const [viewMonth, setViewMonth] = useState(() => startOfMonth(parseDate(dayFromValue(currentValue[0] || currentValue[1])) ?? /* @__PURE__ */ new Date()));
|
|
549
|
-
const [endViewMonth, setEndViewMonth] = useState(() => startOfMonth(parseDate(dayFromValue(currentValue[1])) ?? addMonths(parseDate(dayFromValue(currentValue[0])) ?? /* @__PURE__ */ new Date(), 1)));
|
|
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))));
|
|
550
867
|
const showSecond = showSecondFrom(showTime);
|
|
551
868
|
const defaultTime = defaultTimeFrom(showTime);
|
|
552
869
|
const defaultEndTime = defaultTimeFrom(showTime, 1);
|
|
@@ -554,10 +871,10 @@ function DateRangePicker({
|
|
|
554
871
|
timePart(currentValue[0], defaultTime),
|
|
555
872
|
timePart(currentValue[1], defaultEndTime)
|
|
556
873
|
]);
|
|
557
|
-
const resolvedNeedConfirm =
|
|
874
|
+
const resolvedNeedConfirm = showTime ? false : Boolean(needConfirm);
|
|
558
875
|
const rangeDates = [dayFromValue(draftValue[0]), dayFromValue(draftValue[1])];
|
|
559
876
|
const invalidDateTimeRange = Boolean(showTime && draftValue[0] && draftValue[1] && draftValue[0] > draftValue[1]);
|
|
560
|
-
|
|
877
|
+
useEffect2(() => {
|
|
561
878
|
if (!visible) return void 0;
|
|
562
879
|
const close = (event) => {
|
|
563
880
|
const target = event.target;
|
|
@@ -571,14 +888,13 @@ function DateRangePicker({
|
|
|
571
888
|
}
|
|
572
889
|
function changeOpen(next, endpoint) {
|
|
573
890
|
if (next && !visible) {
|
|
574
|
-
setConfirmedIndex(null);
|
|
575
|
-
setPresetSelected(false);
|
|
576
891
|
setDraftValue(currentValue);
|
|
577
892
|
setTimes([timePart(currentValue[0], defaultTime), timePart(currentValue[1], defaultEndTime)]);
|
|
578
893
|
setActiveIndex(endpointDisabled[0] ? 1 : endpointDisabled[1] ? 0 : endpoint ?? (currentValue[0] && !currentValue[1] ? 1 : 0));
|
|
894
|
+
setDateTimeViews(["date", "date"]);
|
|
579
895
|
const nextStartMonth = startOfMonth(parseDate(dayFromValue(currentValue[0] || currentValue[1])) ?? /* @__PURE__ */ new Date());
|
|
580
896
|
setViewMonth(nextStartMonth);
|
|
581
|
-
setEndViewMonth(startOfMonth(parseDate(dayFromValue(currentValue[1])) ?? addMonths(nextStartMonth, 1)));
|
|
897
|
+
setEndViewMonth(startOfMonth(parseDate(dayFromValue(currentValue[1])) ?? (showTime ? nextStartMonth : addMonths(nextStartMonth, 1))));
|
|
582
898
|
}
|
|
583
899
|
if (next && endpoint !== void 0 && !endpointDisabled[endpoint]) setActiveIndex(endpoint);
|
|
584
900
|
setVisible(next);
|
|
@@ -591,9 +907,9 @@ function DateRangePicker({
|
|
|
591
907
|
if (maximum && day > String(maximum).slice(0, 10)) return true;
|
|
592
908
|
const from = index === 1 ? rangeDates[0] : void 0;
|
|
593
909
|
if (dateTimeStep) {
|
|
594
|
-
const
|
|
595
|
-
const otherEndpoint = rangeDates[
|
|
596
|
-
if (otherEndpoint
|
|
910
|
+
const otherIndex = index === 0 ? 1 : 0;
|
|
911
|
+
const otherEndpoint = rangeDates[otherIndex];
|
|
912
|
+
if (otherEndpoint) {
|
|
597
913
|
if (index === 0 && day > otherEndpoint || index === 1 && day < otherEndpoint) return true;
|
|
598
914
|
if (maxRangeDays && Math.abs(daysBetween(otherEndpoint, day)) >= maxRangeDays) return true;
|
|
599
915
|
}
|
|
@@ -604,10 +920,9 @@ function DateRangePicker({
|
|
|
604
920
|
return showTime ? withTime(day, times[index], showSecond) : day;
|
|
605
921
|
}
|
|
606
922
|
function updateDraft(next) {
|
|
607
|
-
setPresetSelected(false);
|
|
608
923
|
setDraftValue(next);
|
|
609
924
|
onCalendarChange?.(next);
|
|
610
|
-
if (
|
|
925
|
+
if (isValidRange(next) && (next[0] !== currentValue[0] || next[1] !== currentValue[1])) {
|
|
611
926
|
setCurrentValue(next);
|
|
612
927
|
}
|
|
613
928
|
}
|
|
@@ -684,19 +999,7 @@ function DateRangePicker({
|
|
|
684
999
|
}
|
|
685
1000
|
return true;
|
|
686
1001
|
}
|
|
687
|
-
const otherIndex = activeIndex === 0 ? 1 : 0;
|
|
688
|
-
const needsOtherConfirmation = Boolean(showTime && !presetSelected && !endpointDisabled[otherIndex] && confirmedIndex !== otherIndex);
|
|
689
1002
|
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
1003
|
if (!isValidRange(draftValue)) return;
|
|
701
1004
|
setCurrentValue(draftValue);
|
|
702
1005
|
changeOpen(false);
|
|
@@ -709,13 +1012,11 @@ function DateRangePicker({
|
|
|
709
1012
|
];
|
|
710
1013
|
if (!isValidRange(next)) return;
|
|
711
1014
|
updateDraft(next);
|
|
712
|
-
setConfirmedIndex(null);
|
|
713
|
-
setPresetSelected(true);
|
|
714
1015
|
setTimes([timePart(next[0], defaultTime), timePart(next[1], defaultEndTime)]);
|
|
715
1016
|
const nextStartMonth = startOfMonth(parseDate(dayFromValue(next[0] || next[1])) ?? /* @__PURE__ */ new Date());
|
|
716
1017
|
setViewMonth(nextStartMonth);
|
|
717
|
-
setEndViewMonth(startOfMonth(parseDate(dayFromValue(next[1])) ?? addMonths(nextStartMonth, 1)));
|
|
718
|
-
if (!
|
|
1018
|
+
setEndViewMonth(startOfMonth(parseDate(dayFromValue(next[1])) ?? (showTime ? nextStartMonth : addMonths(nextStartMonth, 1))));
|
|
1019
|
+
if (!resolvedNeedConfirm) {
|
|
719
1020
|
changeOpen(false);
|
|
720
1021
|
}
|
|
721
1022
|
}
|
|
@@ -730,49 +1031,66 @@ function DateRangePicker({
|
|
|
730
1031
|
const month = index === 0 ? viewMonth : endViewMonth;
|
|
731
1032
|
const setMonth = index === 0 ? setViewMonth : setEndViewMonth;
|
|
732
1033
|
const endpointLabel = index === 0 ? "\u5F00\u59CB" : "\u7ED3\u675F";
|
|
733
|
-
return /* @__PURE__ */ jsxs2(
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
1034
|
+
return /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
1035
|
+
/* @__PURE__ */ jsx2(
|
|
1036
|
+
CalendarHeader,
|
|
1037
|
+
{
|
|
1038
|
+
month,
|
|
1039
|
+
label: endpointLabel,
|
|
1040
|
+
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))
|
|
1045
|
+
}
|
|
1046
|
+
),
|
|
1047
|
+
/* @__PURE__ */ jsx2(
|
|
1048
|
+
CalendarMonth,
|
|
1049
|
+
{
|
|
1050
|
+
month,
|
|
1051
|
+
range: rangeDates,
|
|
1052
|
+
disabledDate: (day) => isDisabled(day, index, true),
|
|
1053
|
+
onSelect: (day) => selectDateTime(day, index)
|
|
1054
|
+
}
|
|
1055
|
+
)
|
|
1056
|
+
] });
|
|
1057
|
+
}
|
|
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);
|
|
776
1094
|
}
|
|
777
1095
|
const displayValue = visible && allowEmpty.some(Boolean) ? draftValue : currentValue;
|
|
778
1096
|
const startFloating = useFloatingPlaceholder({ mode: placeholderMode, placeholder: placeholder[0], filled: Boolean(displayValue[0]), active: visible });
|
|
@@ -817,67 +1135,94 @@ function DateRangePicker({
|
|
|
817
1135
|
}
|
|
818
1136
|
),
|
|
819
1137
|
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(
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
/* @__PURE__ */ jsxs2("
|
|
837
|
-
/* @__PURE__ */ jsx2(
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
1138
|
+
/* @__PURE__ */ jsxs2(
|
|
1139
|
+
PopupPortal,
|
|
1140
|
+
{
|
|
1141
|
+
ref: popupRef,
|
|
1142
|
+
anchorRef: rootRef,
|
|
1143
|
+
open: visible,
|
|
1144
|
+
className: `sia-date-panel${showTime ? " sia-date-panel--datetime-range" : " sia-date-panel--range"}${presets?.length ? " sia-date-panel--with-presets" : ""}`,
|
|
1145
|
+
role: "dialog",
|
|
1146
|
+
"aria-label": "\u65E5\u671F\u8303\u56F4\u9009\u62E9\u9762\u677F",
|
|
1147
|
+
onKeyDown: (event) => {
|
|
1148
|
+
if (event.key === "Escape") {
|
|
1149
|
+
event.stopPropagation();
|
|
1150
|
+
dismissPanel();
|
|
1151
|
+
}
|
|
1152
|
+
},
|
|
1153
|
+
children: [
|
|
1154
|
+
/* @__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,
|
|
1163
|
+
{
|
|
1164
|
+
month: viewMonth,
|
|
1165
|
+
range: true,
|
|
1166
|
+
onPreviousYear: () => setViewMonth(addMonths(viewMonth, -12)),
|
|
1167
|
+
onPreviousMonth: () => setViewMonth(addMonths(viewMonth, -1))
|
|
1168
|
+
}
|
|
1169
|
+
),
|
|
1170
|
+
/* @__PURE__ */ jsx2(CalendarMonth, { month: viewMonth, range: rangeDates, previewEnd: activeIndex === 1 ? hoverDate : "", disabledDate: isDisabled, onSelect: selectDate, onHover: activeIndex === 1 ? setHoverDate : void 0 })
|
|
1171
|
+
] }),
|
|
1172
|
+
/* @__PURE__ */ jsxs2("section", { className: "sia-date-panel__calendar", children: [
|
|
1173
|
+
/* @__PURE__ */ jsx2(
|
|
1174
|
+
CalendarHeader,
|
|
1175
|
+
{
|
|
1176
|
+
month: addMonths(viewMonth, 1),
|
|
1177
|
+
range: true,
|
|
1178
|
+
onNextMonth: () => setViewMonth(addMonths(viewMonth, 1)),
|
|
1179
|
+
onNextYear: () => setViewMonth(addMonths(viewMonth, 12))
|
|
1180
|
+
}
|
|
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
|
+
] })
|
|
1184
|
+
] })
|
|
863
1185
|
] }),
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
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
|
+
] })
|
|
875
1198
|
}
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
1199
|
+
) : null : /* @__PURE__ */ jsx2(
|
|
1200
|
+
DatePanelFooter,
|
|
1201
|
+
{
|
|
1202
|
+
showToday: showToday && !presets?.length,
|
|
1203
|
+
needConfirm: resolvedNeedConfirm || allowEmpty.some(Boolean),
|
|
1204
|
+
disabledConfirm: !isValidRange(draftValue),
|
|
1205
|
+
extra: /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
1206
|
+
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: [
|
|
1208
|
+
"\u6700\u591A\u9009\u62E9 ",
|
|
1209
|
+
maxRangeDays,
|
|
1210
|
+
" \u5929"
|
|
1211
|
+
] }) : null
|
|
1212
|
+
] }),
|
|
1213
|
+
onToday: () => {
|
|
1214
|
+
const now = /* @__PURE__ */ new Date();
|
|
1215
|
+
const day = dateKey(now);
|
|
1216
|
+
if (isDisabled(day, activeIndex, Boolean(showTime))) return;
|
|
1217
|
+
setViewMonth(startOfMonth(now));
|
|
1218
|
+
selectDate(day);
|
|
1219
|
+
},
|
|
1220
|
+
onConfirm: confirm
|
|
1221
|
+
}
|
|
1222
|
+
)
|
|
1223
|
+
]
|
|
1224
|
+
}
|
|
1225
|
+
)
|
|
881
1226
|
] });
|
|
882
1227
|
}
|
|
883
1228
|
((DatePicker2) => {
|