@epilot/spark-ui 0.29.0 → 0.30.1
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/calendar-lists-CTby2kR5.d.cts +27 -0
- package/dist/calendar-lists-DoloqsCN.d.ts +27 -0
- package/dist/components/accordion.cjs +1 -1
- package/dist/components/accordion.js +1 -1
- package/dist/components/attachment.cjs +1 -1
- package/dist/components/attachment.d.cts +1 -1
- package/dist/components/attachment.d.ts +1 -1
- package/dist/components/attachment.js +1 -1
- package/dist/components/autocomplete.cjs +10 -2
- package/dist/components/autocomplete.cjs.map +1 -1
- package/dist/components/autocomplete.js +11 -3
- package/dist/components/autocomplete.js.map +1 -1
- package/dist/components/badge.cjs +1 -1
- package/dist/components/badge.js +1 -1
- package/dist/components/banner.cjs +1 -1
- package/dist/components/banner.js +1 -1
- package/dist/components/box.js +1 -1
- package/dist/components/breadcrumbs.cjs +1 -1
- package/dist/components/breadcrumbs.js +1 -1
- package/dist/components/bubble.cjs +1 -1
- package/dist/components/bubble.d.cts +1 -1
- package/dist/components/bubble.d.ts +1 -1
- package/dist/components/bubble.js +1 -1
- package/dist/components/button-group.cjs +1 -1
- package/dist/components/button-group.js +1 -1
- package/dist/components/button.cjs +1 -1
- package/dist/components/button.d.cts +1 -1
- package/dist/components/button.d.ts +1 -1
- package/dist/components/button.js +1 -1
- package/dist/components/calendar.cjs +23 -4
- package/dist/components/calendar.cjs.map +1 -1
- package/dist/components/calendar.d.cts +11 -2
- package/dist/components/calendar.d.ts +11 -2
- package/dist/components/calendar.js +23 -4
- package/dist/components/calendar.js.map +1 -1
- package/dist/components/callout.cjs +1 -1
- package/dist/components/callout.js +1 -1
- package/dist/components/card.cjs +1 -1
- package/dist/components/card.js +2 -2
- package/dist/components/combobox.cjs +47 -16
- package/dist/components/combobox.cjs.map +1 -1
- package/dist/components/combobox.d.cts +2 -0
- package/dist/components/combobox.d.ts +2 -0
- package/dist/components/combobox.js +48 -17
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/drawer.cjs +1 -1
- package/dist/components/drawer.js +1 -1
- package/dist/components/empty-state.cjs +1 -1
- package/dist/components/empty-state.js +1 -1
- package/dist/components/entity-card.cjs +1 -1
- package/dist/components/entity-card.js +1 -1
- package/dist/components/field.cjs +19 -4
- package/dist/components/field.cjs.map +1 -1
- package/dist/components/field.d.cts +3 -1
- package/dist/components/field.d.ts +3 -1
- package/dist/components/field.js +19 -5
- package/dist/components/field.js.map +1 -1
- package/dist/components/hero-metric.cjs +1 -1
- package/dist/components/hero-metric.js +1 -1
- package/dist/components/info-block.cjs +1 -1
- package/dist/components/info-block.js +1 -1
- package/dist/components/input-date-time.cjs +212 -0
- package/dist/components/input-date-time.cjs.map +1 -0
- package/dist/components/input-date-time.d.cts +38 -0
- package/dist/components/input-date-time.d.ts +38 -0
- package/dist/components/input-date-time.js +205 -0
- package/dist/components/input-date-time.js.map +1 -0
- package/dist/components/input-date.cjs +11 -1
- package/dist/components/input-date.cjs.map +1 -1
- package/dist/components/input-date.js +11 -1
- package/dist/components/input-date.js.map +1 -1
- package/dist/components/input-group.cjs +2 -2
- package/dist/components/input-group.js +2 -2
- package/dist/components/input-otp.cjs +2 -1
- package/dist/components/input-otp.cjs.map +1 -1
- package/dist/components/input-otp.js +3 -2
- package/dist/components/input-otp.js.map +1 -1
- package/dist/components/input.cjs +1 -1
- package/dist/components/input.js +1 -1
- package/dist/components/list.cjs +1 -1
- package/dist/components/list.js +1 -1
- package/dist/components/marker.cjs +1 -1
- package/dist/components/marker.d.cts +1 -1
- package/dist/components/marker.d.ts +1 -1
- package/dist/components/marker.js +1 -1
- package/dist/components/message-scroller.cjs +1 -1
- package/dist/components/message-scroller.js +1 -1
- package/dist/components/page-header.cjs +1 -1
- package/dist/components/page-header.d.cts +1 -1
- package/dist/components/page-header.d.ts +1 -1
- package/dist/components/page-header.js +1 -1
- package/dist/components/popover.cjs +1 -1
- package/dist/components/popover.js +1 -1
- package/dist/components/select.cjs +2 -1
- package/dist/components/select.cjs.map +1 -1
- package/dist/components/select.js +2 -1
- package/dist/components/select.js.map +1 -1
- package/dist/components/separator.cjs +1 -1
- package/dist/components/separator.js +1 -1
- package/dist/components/skeleton.cjs +1 -1
- package/dist/components/skeleton.js +1 -1
- package/dist/components/textarea.cjs +1 -1
- package/dist/components/textarea.js +1 -1
- package/dist/components/theme.cjs +3 -1
- package/dist/components/theme.cjs.map +1 -1
- package/dist/components/theme.js +3 -1
- package/dist/components/theme.js.map +1 -1
- package/dist/components/toggle.cjs +1 -1
- package/dist/components/toggle.js +1 -1
- package/dist/hooks/use-focus-modality.cjs +55 -0
- package/dist/hooks/use-focus-modality.cjs.map +1 -0
- package/dist/hooks/use-focus-modality.d.cts +8 -0
- package/dist/hooks/use-focus-modality.d.ts +8 -0
- package/dist/hooks/use-focus-modality.js +53 -0
- package/dist/hooks/use-focus-modality.js.map +1 -0
- package/dist/lib/accent-theme.cjs +75 -17
- package/dist/lib/accent-theme.cjs.map +1 -1
- package/dist/lib/accent-theme.d.cts +14 -1
- package/dist/lib/accent-theme.d.ts +14 -1
- package/dist/lib/accent-theme.js +74 -18
- package/dist/lib/accent-theme.js.map +1 -1
- package/dist/lib/calendar-lists.cjs +222 -0
- package/dist/lib/calendar-lists.cjs.map +1 -0
- package/dist/lib/calendar-lists.d.cts +4 -0
- package/dist/lib/calendar-lists.d.ts +4 -0
- package/dist/lib/calendar-lists.js +217 -0
- package/dist/lib/calendar-lists.js.map +1 -0
- package/dist/lib/control-glyphs.cjs +37 -0
- package/dist/lib/control-glyphs.cjs.map +1 -0
- package/dist/lib/control-glyphs.d.cts +11 -0
- package/dist/lib/control-glyphs.d.ts +11 -0
- package/dist/lib/control-glyphs.js +35 -0
- package/dist/lib/control-glyphs.js.map +1 -0
- package/dist/lib/date-time-mask.cjs +155 -0
- package/dist/lib/date-time-mask.cjs.map +1 -0
- package/dist/lib/date-time-mask.d.cts +56 -0
- package/dist/lib/date-time-mask.d.ts +56 -0
- package/dist/lib/date-time-mask.js +147 -0
- package/dist/lib/date-time-mask.js.map +1 -0
- package/dist/lib/input-date-parts.cjs +154 -0
- package/dist/lib/input-date-parts.cjs.map +1 -0
- package/dist/lib/input-date-parts.d.cts +53 -0
- package/dist/lib/input-date-parts.d.ts +53 -0
- package/dist/lib/input-date-parts.js +147 -0
- package/dist/lib/input-date-parts.js.map +1 -0
- package/dist/styles/spark-default.css +366 -24
- package/dist/styles/theme.css +45 -3
- package/package.json +1 -1
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use client";
|
|
3
|
+
import { cn } from "../utils/cn.js";
|
|
4
|
+
import { buttonVariants } from "../components/button.js";
|
|
5
|
+
import * as React$1 from "react";
|
|
6
|
+
import { MonthGrid as MonthGrid$1, useDayPicker } from "@daypicker/react";
|
|
7
|
+
import { ArrowDropDown, Check, ChevronLeft, ChevronRight } from "@epilot/spark-icons";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
//#region src/lib/calendar-lists.tsx
|
|
10
|
+
const ListContext = React$1.createContext({
|
|
11
|
+
labels: {
|
|
12
|
+
nextYear: "Next year",
|
|
13
|
+
previousYear: "Previous year"
|
|
14
|
+
},
|
|
15
|
+
setView: () => void 0,
|
|
16
|
+
view: "days"
|
|
17
|
+
});
|
|
18
|
+
const monthOf = (year, month) => new Date(year, month, 1);
|
|
19
|
+
function useBounds() {
|
|
20
|
+
const { dayPickerProps } = useDayPicker();
|
|
21
|
+
const year = (/* @__PURE__ */ new Date()).getFullYear();
|
|
22
|
+
const start = dayPickerProps.startMonth ?? monthOf(year - 100, 0);
|
|
23
|
+
const end = dayPickerProps.endMonth ?? monthOf(year + 100, 11);
|
|
24
|
+
return {
|
|
25
|
+
end: monthOf(end.getFullYear(), end.getMonth()),
|
|
26
|
+
start: monthOf(start.getFullYear(), start.getMonth())
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const clamp = (date, start, end) => date < start ? start : date > end ? end : date;
|
|
30
|
+
function useMonthName() {
|
|
31
|
+
const { dayPickerProps } = useDayPicker();
|
|
32
|
+
return React$1.useMemo(() => new Intl.DateTimeFormat(dayPickerProps.locale?.code, { month: "long" }), [dayPickerProps.locale?.code]);
|
|
33
|
+
}
|
|
34
|
+
const arrowClassName = cn(buttonVariants({
|
|
35
|
+
size: "icon-small",
|
|
36
|
+
variant: "tertiary"
|
|
37
|
+
}), "text-gray-light hover:text-gray focus-visible:focus-outline disabled:opacity-30 data-hidden:invisible [[data-high-contrast]_&]:text-gray-a12");
|
|
38
|
+
function Stepper({ label, listLabel, nextLabel, onNext, onPrevious, previousLabel, type }) {
|
|
39
|
+
const { setView, view } = React$1.useContext(ListContext);
|
|
40
|
+
const listOpen = view !== "days";
|
|
41
|
+
const open = view === type;
|
|
42
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
43
|
+
className: "flex items-center gap-1",
|
|
44
|
+
children: [
|
|
45
|
+
/* @__PURE__ */ jsx("button", {
|
|
46
|
+
"aria-label": previousLabel,
|
|
47
|
+
className: arrowClassName,
|
|
48
|
+
"data-hidden": listOpen || void 0,
|
|
49
|
+
disabled: !onPrevious,
|
|
50
|
+
onClick: onPrevious,
|
|
51
|
+
tabIndex: listOpen ? -1 : void 0,
|
|
52
|
+
type: "button",
|
|
53
|
+
children: /* @__PURE__ */ jsx(ChevronLeft, { className: "[--spark-icon-size:20px]" })
|
|
54
|
+
}),
|
|
55
|
+
/* @__PURE__ */ jsxs("button", {
|
|
56
|
+
"aria-expanded": open,
|
|
57
|
+
"aria-haspopup": "listbox",
|
|
58
|
+
"aria-label": `${label}, ${listLabel}`,
|
|
59
|
+
className: cn("inline-flex h-8 cursor-pointer items-center rounded-md pl-2 text-sm font-bold text-gray hover:bg-gray-a3 focus-visible:focus-outline", listOpen && !open && "opacity-50"),
|
|
60
|
+
"data-slot": "calendar-list-button",
|
|
61
|
+
"data-type": type,
|
|
62
|
+
onClick: () => setView(open ? "days" : type),
|
|
63
|
+
type: "button",
|
|
64
|
+
children: [label, /* @__PURE__ */ jsx(ArrowDropDown, { className: cn("[--spark-icon-size:20px]", listOpen && !open && "invisible") })]
|
|
65
|
+
}),
|
|
66
|
+
/* @__PURE__ */ jsx("button", {
|
|
67
|
+
"aria-label": nextLabel,
|
|
68
|
+
className: arrowClassName,
|
|
69
|
+
"data-hidden": listOpen || void 0,
|
|
70
|
+
disabled: !onNext,
|
|
71
|
+
onClick: onNext,
|
|
72
|
+
tabIndex: listOpen ? -1 : void 0,
|
|
73
|
+
type: "button",
|
|
74
|
+
children: /* @__PURE__ */ jsx(ChevronRight, { className: "[--spark-icon-size:20px]" })
|
|
75
|
+
})
|
|
76
|
+
]
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function MonthCaption({ calendarMonth, className, displayIndex: _, ...props }) {
|
|
80
|
+
const { goToMonth, labels: dayPickerLabels } = useDayPicker();
|
|
81
|
+
const { labels } = React$1.useContext(ListContext);
|
|
82
|
+
const { end, start } = useBounds();
|
|
83
|
+
const monthName = useMonthName();
|
|
84
|
+
const date = calendarMonth.date;
|
|
85
|
+
const year = date.getFullYear();
|
|
86
|
+
const month = date.getMonth();
|
|
87
|
+
const go = (target) => goToMonth(clamp(target, start, end));
|
|
88
|
+
const previousMonth = monthOf(year, month - 1);
|
|
89
|
+
const nextMonth = monthOf(year, month + 1);
|
|
90
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
91
|
+
...props,
|
|
92
|
+
className: cn("flex h-10 items-center justify-between gap-4", className),
|
|
93
|
+
"data-slot": "calendar-header",
|
|
94
|
+
children: [/* @__PURE__ */ jsx(Stepper, {
|
|
95
|
+
label: monthName.format(date),
|
|
96
|
+
listLabel: dayPickerLabels.labelMonthDropdown(),
|
|
97
|
+
nextLabel: dayPickerLabels.labelNext(nextMonth),
|
|
98
|
+
onNext: nextMonth <= end ? () => go(nextMonth) : void 0,
|
|
99
|
+
onPrevious: previousMonth >= start ? () => go(previousMonth) : void 0,
|
|
100
|
+
previousLabel: dayPickerLabels.labelPrevious(previousMonth),
|
|
101
|
+
type: "month"
|
|
102
|
+
}), /* @__PURE__ */ jsx(Stepper, {
|
|
103
|
+
label: String(year),
|
|
104
|
+
listLabel: dayPickerLabels.labelYearDropdown(),
|
|
105
|
+
nextLabel: labels.nextYear,
|
|
106
|
+
onNext: year < end.getFullYear() ? () => go(monthOf(year + 1, month)) : void 0,
|
|
107
|
+
onPrevious: year > start.getFullYear() ? () => go(monthOf(year - 1, month)) : void 0,
|
|
108
|
+
previousLabel: labels.previousYear,
|
|
109
|
+
type: "year"
|
|
110
|
+
})]
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function OptionList({ label, onClose, onPick, options }) {
|
|
114
|
+
const listRef = React$1.useRef(null);
|
|
115
|
+
React$1.useEffect(() => {
|
|
116
|
+
const current = listRef.current?.querySelector("[aria-selected=\"true\"]");
|
|
117
|
+
current?.scrollIntoView?.({ block: "center" });
|
|
118
|
+
current?.focus();
|
|
119
|
+
}, []);
|
|
120
|
+
const onKeyDown = (event) => {
|
|
121
|
+
if (event.key === "Escape") {
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
event.stopPropagation();
|
|
124
|
+
onClose(listRef.current);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const items = Array.from(listRef.current?.querySelectorAll("[role=\"option\"]:not(:disabled)") ?? []);
|
|
128
|
+
const index = items.indexOf(document.activeElement);
|
|
129
|
+
const target = {
|
|
130
|
+
ArrowDown: index + 1,
|
|
131
|
+
ArrowUp: index - 1,
|
|
132
|
+
End: items.length - 1,
|
|
133
|
+
Home: 0
|
|
134
|
+
}[event.key];
|
|
135
|
+
if (target === void 0) return;
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
items[Math.max(0, Math.min(items.length - 1, target))]?.focus();
|
|
138
|
+
};
|
|
139
|
+
return /* @__PURE__ */ jsx("div", {
|
|
140
|
+
"aria-label": label,
|
|
141
|
+
className: "mt-1 flex max-h-72 w-full flex-col gap-0.5 overflow-y-auto [scrollbar-width:none]",
|
|
142
|
+
"data-slot": "calendar-list",
|
|
143
|
+
onKeyDown,
|
|
144
|
+
ref: listRef,
|
|
145
|
+
role: "listbox",
|
|
146
|
+
tabIndex: -1,
|
|
147
|
+
children: options.map((option) => /* @__PURE__ */ jsxs("button", {
|
|
148
|
+
"aria-selected": option.selected,
|
|
149
|
+
className: cn("flex shrink-0 cursor-pointer items-center gap-3 rounded-md py-2 pr-2 pl-3 text-left text-sm text-gray hover:bg-gray-a3 focus-visible:focus-outline disabled:cursor-not-allowed disabled:opacity-50", option.selected && "bg-(--spark-style-bg,var(--color-primary)) text-(--spark-style-fg,var(--color-primary-foreground)) hover:bg-(--spark-style-bg-hover,var(--color-primary-hover))"),
|
|
150
|
+
disabled: option.disabled,
|
|
151
|
+
onClick: () => onPick(option.value, listRef.current),
|
|
152
|
+
role: "option",
|
|
153
|
+
tabIndex: option.selected ? 0 : -1,
|
|
154
|
+
type: "button",
|
|
155
|
+
children: [/* @__PURE__ */ jsx(Check, { className: cn("[--spark-icon-size:20px]", !option.selected && "invisible") }), option.label]
|
|
156
|
+
}, option.value))
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function MonthGrid(props) {
|
|
160
|
+
const { goToMonth, labels: dayPickerLabels, months } = useDayPicker();
|
|
161
|
+
const { setView, view } = React$1.useContext(ListContext);
|
|
162
|
+
const { end, start } = useBounds();
|
|
163
|
+
const monthName = useMonthName();
|
|
164
|
+
if (view === "days") return /* @__PURE__ */ jsx(MonthGrid$1, { ...props });
|
|
165
|
+
const shown = months[0]?.date ?? /* @__PURE__ */ new Date();
|
|
166
|
+
const year = shown.getFullYear();
|
|
167
|
+
const month = shown.getMonth();
|
|
168
|
+
const close = (list) => {
|
|
169
|
+
const opener = list?.parentElement?.querySelector(`[data-slot=calendar-list-button][data-type=${view}]`);
|
|
170
|
+
setView("days");
|
|
171
|
+
requestAnimationFrame(() => opener?.focus());
|
|
172
|
+
};
|
|
173
|
+
const pick = (target, list) => {
|
|
174
|
+
goToMonth(clamp(target, start, end));
|
|
175
|
+
close(list);
|
|
176
|
+
};
|
|
177
|
+
if (view === "month") return /* @__PURE__ */ jsx(OptionList, {
|
|
178
|
+
label: dayPickerLabels.labelMonthDropdown(),
|
|
179
|
+
onClose: close,
|
|
180
|
+
onPick: (value, list) => pick(monthOf(year, value), list),
|
|
181
|
+
options: Array.from({ length: 12 }, (_, value) => ({
|
|
182
|
+
disabled: monthOf(year, value) < start || monthOf(year, value) > end,
|
|
183
|
+
label: monthName.format(monthOf(year, value)),
|
|
184
|
+
selected: value === month,
|
|
185
|
+
value
|
|
186
|
+
}))
|
|
187
|
+
});
|
|
188
|
+
return /* @__PURE__ */ jsx(OptionList, {
|
|
189
|
+
label: dayPickerLabels.labelYearDropdown(),
|
|
190
|
+
onClose: close,
|
|
191
|
+
onPick: (value, list) => pick(monthOf(value, month), list),
|
|
192
|
+
options: Array.from({ length: end.getFullYear() - start.getFullYear() + 1 }, (_, index) => {
|
|
193
|
+
const value = start.getFullYear() + index;
|
|
194
|
+
return {
|
|
195
|
+
label: String(value),
|
|
196
|
+
selected: value === year,
|
|
197
|
+
value
|
|
198
|
+
};
|
|
199
|
+
})
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
function CalendarListsProvider({ children, labels }) {
|
|
203
|
+
const [view, setView] = React$1.useState("days");
|
|
204
|
+
const value = React$1.useMemo(() => ({
|
|
205
|
+
labels,
|
|
206
|
+
setView,
|
|
207
|
+
view
|
|
208
|
+
}), [labels, view]);
|
|
209
|
+
return /* @__PURE__ */ jsx(ListContext.Provider, {
|
|
210
|
+
value,
|
|
211
|
+
children
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
//#endregion
|
|
215
|
+
export { CalendarListsProvider, MonthCaption as ListMonthCaption, MonthGrid as ListMonthGrid };
|
|
216
|
+
|
|
217
|
+
//# sourceMappingURL=calendar-lists.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar-lists.js","names":["React","DayGrid"],"sources":["../../src/lib/calendar-lists.tsx"],"sourcesContent":["'use client'\n\nimport {\n MonthGrid as DayGrid,\n type MonthCaptionProps,\n type MonthGridProps,\n useDayPicker,\n} from '@daypicker/react'\nimport {\n ArrowDropDown,\n Check,\n ChevronLeft,\n ChevronRight,\n} from '@epilot/spark-icons'\nimport * as React from 'react'\nimport { buttonVariants } from '../components/button'\nimport { cn } from '../utils/cn'\n\ntype View = 'days' | 'month' | 'year'\n\nexport type CalendarListLabels = {\n nextYear: string\n previousYear: string\n}\n\nconst ListContext = React.createContext<{\n labels: CalendarListLabels\n setView: (view: View) => void\n view: View\n}>({\n labels: { nextYear: 'Next year', previousYear: 'Previous year' },\n setView: () => undefined,\n view: 'days',\n})\n\nconst monthOf = (year: number, month: number) => new Date(year, month, 1)\n\nfunction useBounds() {\n const { dayPickerProps } = useDayPicker()\n const year = new Date().getFullYear()\n const start = dayPickerProps.startMonth ?? monthOf(year - 100, 0)\n const end = dayPickerProps.endMonth ?? monthOf(year + 100, 11)\n return {\n end: monthOf(end.getFullYear(), end.getMonth()),\n start: monthOf(start.getFullYear(), start.getMonth()),\n }\n}\n\nconst clamp = (date: Date, start: Date, end: Date) =>\n date < start ? start : date > end ? end : date\n\nfunction useMonthName() {\n const { dayPickerProps } = useDayPicker()\n return React.useMemo(\n () =>\n new Intl.DateTimeFormat(dayPickerProps.locale?.code, { month: 'long' }),\n [dayPickerProps.locale?.code],\n )\n}\n\nconst arrowClassName = cn(\n buttonVariants({ size: 'icon-small', variant: 'tertiary' }),\n 'text-gray-light hover:text-gray focus-visible:focus-outline disabled:opacity-30 data-hidden:invisible [[data-high-contrast]_&]:text-gray-a12',\n)\n\nfunction Stepper({\n label,\n listLabel,\n nextLabel,\n onNext,\n onPrevious,\n previousLabel,\n type,\n}: {\n label: string\n listLabel: string\n nextLabel: string\n onNext?: () => void\n onPrevious?: () => void\n previousLabel: string\n type: 'month' | 'year'\n}) {\n const { setView, view } = React.useContext(ListContext)\n const listOpen = view !== 'days'\n const open = view === type\n return (\n <div className=\"flex items-center gap-1\">\n <button\n aria-label={previousLabel}\n className={arrowClassName}\n data-hidden={listOpen || undefined}\n disabled={!onPrevious}\n onClick={onPrevious}\n tabIndex={listOpen ? -1 : undefined}\n type=\"button\"\n >\n <ChevronLeft className=\"[--spark-icon-size:20px]\" />\n </button>\n <button\n aria-expanded={open}\n aria-haspopup=\"listbox\"\n aria-label={`${label}, ${listLabel}`}\n className={cn(\n 'inline-flex h-8 cursor-pointer items-center rounded-md pl-2 text-sm font-bold text-gray hover:bg-gray-a3 focus-visible:focus-outline',\n listOpen && !open && 'opacity-50',\n )}\n data-slot=\"calendar-list-button\"\n data-type={type}\n onClick={() => setView(open ? 'days' : type)}\n type=\"button\"\n >\n {label}\n <ArrowDropDown\n className={cn(\n '[--spark-icon-size:20px]',\n listOpen && !open && 'invisible',\n )}\n />\n </button>\n <button\n aria-label={nextLabel}\n className={arrowClassName}\n data-hidden={listOpen || undefined}\n disabled={!onNext}\n onClick={onNext}\n tabIndex={listOpen ? -1 : undefined}\n type=\"button\"\n >\n <ChevronRight className=\"[--spark-icon-size:20px]\" />\n </button>\n </div>\n )\n}\n\nfunction MonthCaption({\n calendarMonth,\n className,\n displayIndex: _,\n ...props\n}: MonthCaptionProps) {\n const { goToMonth, labels: dayPickerLabels } = useDayPicker()\n const { labels } = React.useContext(ListContext)\n const { end, start } = useBounds()\n const monthName = useMonthName()\n const date = calendarMonth.date\n const year = date.getFullYear()\n const month = date.getMonth()\n const go = (target: Date) => goToMonth(clamp(target, start, end))\n const previousMonth = monthOf(year, month - 1)\n const nextMonth = monthOf(year, month + 1)\n return (\n <div\n {...props}\n className={cn('flex h-10 items-center justify-between gap-4', className)}\n data-slot=\"calendar-header\"\n >\n <Stepper\n label={monthName.format(date)}\n listLabel={dayPickerLabels.labelMonthDropdown()}\n nextLabel={dayPickerLabels.labelNext(nextMonth)}\n onNext={nextMonth <= end ? () => go(nextMonth) : undefined}\n onPrevious={\n previousMonth >= start ? () => go(previousMonth) : undefined\n }\n previousLabel={dayPickerLabels.labelPrevious(previousMonth)}\n type=\"month\"\n />\n <Stepper\n label={String(year)}\n listLabel={dayPickerLabels.labelYearDropdown()}\n nextLabel={labels.nextYear}\n onNext={\n year < end.getFullYear()\n ? () => go(monthOf(year + 1, month))\n : undefined\n }\n onPrevious={\n year > start.getFullYear()\n ? () => go(monthOf(year - 1, month))\n : undefined\n }\n previousLabel={labels.previousYear}\n type=\"year\"\n />\n </div>\n )\n}\n\ntype Option = {\n disabled?: boolean\n label: string\n selected: boolean\n value: number\n}\n\nfunction OptionList({\n label,\n onClose,\n onPick,\n options,\n}: {\n label: string\n onClose: (list: HTMLElement | null) => void\n onPick: (value: number, list: HTMLElement | null) => void\n options: Option[]\n}) {\n const listRef = React.useRef<HTMLDivElement>(null)\n\n // the current month or year is in view and focused when the list opens\n React.useEffect(() => {\n const current = listRef.current?.querySelector<HTMLButtonElement>(\n '[aria-selected=\"true\"]',\n )\n current?.scrollIntoView?.({ block: 'center' })\n current?.focus()\n }, [])\n\n const onKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (event.key === 'Escape') {\n // closes the list, not the popup it sits in\n event.preventDefault()\n event.stopPropagation()\n onClose(listRef.current)\n return\n }\n const items = Array.from(\n listRef.current?.querySelectorAll<HTMLButtonElement>(\n '[role=\"option\"]:not(:disabled)',\n ) ?? [],\n )\n const index = items.indexOf(document.activeElement as HTMLButtonElement)\n const target = {\n ArrowDown: index + 1,\n ArrowUp: index - 1,\n End: items.length - 1,\n Home: 0,\n }[event.key]\n if (target === undefined) return\n event.preventDefault()\n items[Math.max(0, Math.min(items.length - 1, target))]?.focus()\n }\n\n return (\n <div\n aria-label={label}\n className=\"mt-1 flex max-h-72 w-full flex-col gap-0.5 overflow-y-auto [scrollbar-width:none]\"\n data-slot=\"calendar-list\"\n onKeyDown={onKeyDown}\n ref={listRef}\n role=\"listbox\"\n tabIndex={-1}\n >\n {options.map((option) => (\n <button\n aria-selected={option.selected}\n className={cn(\n 'flex shrink-0 cursor-pointer items-center gap-3 rounded-md py-2 pr-2 pl-3 text-left text-sm text-gray hover:bg-gray-a3 focus-visible:focus-outline disabled:cursor-not-allowed disabled:opacity-50',\n option.selected &&\n 'bg-(--spark-style-bg,var(--color-primary)) text-(--spark-style-fg,var(--color-primary-foreground)) hover:bg-(--spark-style-bg-hover,var(--color-primary-hover))',\n )}\n disabled={option.disabled}\n key={option.value}\n onClick={() => onPick(option.value, listRef.current)}\n role=\"option\"\n tabIndex={option.selected ? 0 : -1}\n type=\"button\"\n >\n <Check\n className={cn(\n '[--spark-icon-size:20px]',\n !option.selected && 'invisible',\n )}\n />\n {option.label}\n </button>\n ))}\n </div>\n )\n}\n\nfunction MonthGrid(props: MonthGridProps) {\n const { goToMonth, labels: dayPickerLabels, months } = useDayPicker()\n const { setView, view } = React.useContext(ListContext)\n const { end, start } = useBounds()\n const monthName = useMonthName()\n\n if (view === 'days') return <DayGrid {...props} />\n\n const shown = months[0]?.date ?? new Date()\n const year = shown.getFullYear()\n const month = shown.getMonth()\n // focus goes back to the month or year button the list opened from; it sits in the caption,\n // a separate DayPicker part, so it is found from the list's month container\n const close = (list: HTMLElement | null) => {\n const opener = list?.parentElement?.querySelector<HTMLButtonElement>(\n `[data-slot=calendar-list-button][data-type=${view}]`,\n )\n setView('days')\n requestAnimationFrame(() => opener?.focus())\n }\n const pick = (target: Date, list: HTMLElement | null) => {\n goToMonth(clamp(target, start, end))\n close(list)\n }\n\n if (view === 'month') {\n return (\n <OptionList\n label={dayPickerLabels.labelMonthDropdown()}\n onClose={close}\n onPick={(value, list) => pick(monthOf(year, value), list)}\n options={Array.from({ length: 12 }, (_, value) => ({\n disabled: monthOf(year, value) < start || monthOf(year, value) > end,\n label: monthName.format(monthOf(year, value)),\n selected: value === month,\n value,\n }))}\n />\n )\n }\n\n return (\n <OptionList\n label={dayPickerLabels.labelYearDropdown()}\n onClose={close}\n onPick={(value, list) => pick(monthOf(value, month), list)}\n options={Array.from(\n { length: end.getFullYear() - start.getFullYear() + 1 },\n (_, index) => {\n const value = start.getFullYear() + index\n return { label: String(value), selected: value === year, value }\n },\n )}\n />\n )\n}\n\nfunction CalendarListsProvider({\n children,\n labels,\n}: {\n children: React.ReactNode\n labels: CalendarListLabels\n}) {\n const [view, setView] = React.useState<View>('days')\n const value = React.useMemo(() => ({ labels, setView, view }), [labels, view])\n return <ListContext.Provider value={value}>{children}</ListContext.Provider>\n}\n\nexport {\n CalendarListsProvider,\n MonthCaption as ListMonthCaption,\n MonthGrid as ListMonthGrid,\n}\n"],"mappings":";;;;;;;;;AAyBA,MAAM,cAAcA,QAAM,cAIvB;CACD,QAAQ;EAAE,UAAU;EAAa,cAAc;CAAgB;CAC/D,eAAe,KAAA;CACf,MAAM;AACR,CAAC;AAED,MAAM,WAAW,MAAc,UAAkB,IAAI,KAAK,MAAM,OAAO,CAAC;AAExE,SAAS,YAAY;CACnB,MAAM,EAAE,mBAAmB,aAAa;CACxC,MAAM,wBAAO,IAAI,KAAK,GAAE,YAAY;CACpC,MAAM,QAAQ,eAAe,cAAc,QAAQ,OAAO,KAAK,CAAC;CAChE,MAAM,MAAM,eAAe,YAAY,QAAQ,OAAO,KAAK,EAAE;CAC7D,OAAO;EACL,KAAK,QAAQ,IAAI,YAAY,GAAG,IAAI,SAAS,CAAC;EAC9C,OAAO,QAAQ,MAAM,YAAY,GAAG,MAAM,SAAS,CAAC;CACtD;AACF;AAEA,MAAM,SAAS,MAAY,OAAa,QACtC,OAAO,QAAQ,QAAQ,OAAO,MAAM,MAAM;AAE5C,SAAS,eAAe;CACtB,MAAM,EAAE,mBAAmB,aAAa;CACxC,OAAOA,QAAM,cAET,IAAI,KAAK,eAAe,eAAe,QAAQ,MAAM,EAAE,OAAO,OAAO,CAAC,GACxE,CAAC,eAAe,QAAQ,IAAI,CAC9B;AACF;AAEA,MAAM,iBAAiB,GACrB,eAAe;CAAE,MAAM;C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#region src/lib/control-glyphs.tsx
|
|
5
|
+
function Glyph({ d, ...props }) {
|
|
6
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
7
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
8
|
+
viewBox: "0 0 16 16",
|
|
9
|
+
width: 16,
|
|
10
|
+
height: 16,
|
|
11
|
+
fill: "none",
|
|
12
|
+
stroke: "currentColor",
|
|
13
|
+
strokeWidth: 1.5,
|
|
14
|
+
strokeLinecap: "round",
|
|
15
|
+
strokeLinejoin: "round",
|
|
16
|
+
"aria-hidden": true,
|
|
17
|
+
...props,
|
|
18
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d })
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function ChevronDownGlyph(props) {
|
|
22
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Glyph, {
|
|
23
|
+
d: "M4 6.25 8 10.25l4-4",
|
|
24
|
+
...props
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function ClearGlyph(props) {
|
|
28
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Glyph, {
|
|
29
|
+
d: "m4.5 4.5 7 7m0-7-7 7",
|
|
30
|
+
...props
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
exports.ChevronDownGlyph = ChevronDownGlyph;
|
|
35
|
+
exports.ClearGlyph = ClearGlyph;
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=control-glyphs.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control-glyphs.cjs","names":[],"sources":["../../src/lib/control-glyphs.tsx"],"sourcesContent":["import type * as React from 'react'\n\ntype GlyphProps = Omit<React.ComponentProps<'svg'>, 'children'>\n\n// Control chrome drawn as strokes: the iconset's weight-400 outlines read too thin at 14px.\nfunction Glyph({ d, ...props }: GlyphProps & { d: string }) {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 16 16\"\n width={16}\n height={16}\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth={1.5}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden\n {...props}\n >\n <path d={d} />\n </svg>\n )\n}\n\nexport function ChevronDownGlyph(props: GlyphProps) {\n return <Glyph d=\"M4 6.25 8 10.25l4-4\" {...props} />\n}\n\nexport function ClearGlyph(props: GlyphProps) {\n return <Glyph d=\"m4.5 4.5 7 7m0-7-7 7\" {...props} />\n}\n"],"mappings":";;;;AAKA,SAAS,MAAM,EAAE,GAAG,GAAG,SAAqC;CAC1D,OACE,iBAAA,GAAA,kBAAA,KAAC,OAAD;EACE,OAAM;EACN,SAAQ;EACR,OAAO;EACP,QAAQ;EACR,MAAK;EACL,QAAO;EACP,aAAa;EACb,eAAc;EACd,gBAAe;EACf,eAAA;EACA,GAAI;YAEJ,iBAAA,GAAA,kBAAA,KAAC,QAAD,EAAS,EAAI,CAAA;CACV,CAAA;AAET;AAEA,SAAgB,iBAAiB,OAAmB;CAClD,OAAO,iBAAA,GAAA,kBAAA,KAAC,OAAD;EAAO,GAAE;EAAsB,GAAI;CAAQ,CAAA;AACpD;AAEA,SAAgB,WAAW,OAAmB;CAC5C,OAAO,iBAAA,GAAA,kBAAA,KAAC,OAAD;EAAO,GAAE;EAAuB,GAAI;CAAQ,CAAA;AACrD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React$1 from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/control-glyphs.d.ts
|
|
6
|
+
type GlyphProps = Omit<React$1.ComponentProps<'svg'>, 'children'>;
|
|
7
|
+
declare function ChevronDownGlyph(props: GlyphProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
declare function ClearGlyph(props: GlyphProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ChevronDownGlyph, ClearGlyph };
|
|
11
|
+
//# sourceMappingURL=control-glyphs.d.cts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React$1 from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/control-glyphs.d.ts
|
|
6
|
+
type GlyphProps = Omit<React$1.ComponentProps<'svg'>, 'children'>;
|
|
7
|
+
declare function ChevronDownGlyph(props: GlyphProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
declare function ClearGlyph(props: GlyphProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ChevronDownGlyph, ClearGlyph };
|
|
11
|
+
//# sourceMappingURL=control-glyphs.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
//#region src/lib/control-glyphs.tsx
|
|
4
|
+
function Glyph({ d, ...props }) {
|
|
5
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
6
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
7
|
+
viewBox: "0 0 16 16",
|
|
8
|
+
width: 16,
|
|
9
|
+
height: 16,
|
|
10
|
+
fill: "none",
|
|
11
|
+
stroke: "currentColor",
|
|
12
|
+
strokeWidth: 1.5,
|
|
13
|
+
strokeLinecap: "round",
|
|
14
|
+
strokeLinejoin: "round",
|
|
15
|
+
"aria-hidden": true,
|
|
16
|
+
...props,
|
|
17
|
+
children: /* @__PURE__ */ jsx("path", { d })
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function ChevronDownGlyph(props) {
|
|
21
|
+
return /* @__PURE__ */ jsx(Glyph, {
|
|
22
|
+
d: "M4 6.25 8 10.25l4-4",
|
|
23
|
+
...props
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function ClearGlyph(props) {
|
|
27
|
+
return /* @__PURE__ */ jsx(Glyph, {
|
|
28
|
+
d: "m4.5 4.5 7 7m0-7-7 7",
|
|
29
|
+
...props
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { ChevronDownGlyph, ClearGlyph };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=control-glyphs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control-glyphs.js","names":[],"sources":["../../src/lib/control-glyphs.tsx"],"sourcesContent":["import type * as React from 'react'\n\ntype GlyphProps = Omit<React.ComponentProps<'svg'>, 'children'>\n\n// Control chrome drawn as strokes: the iconset's weight-400 outlines read too thin at 14px.\nfunction Glyph({ d, ...props }: GlyphProps & { d: string }) {\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 16 16\"\n width={16}\n height={16}\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth={1.5}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden\n {...props}\n >\n <path d={d} />\n </svg>\n )\n}\n\nexport function ChevronDownGlyph(props: GlyphProps) {\n return <Glyph d=\"M4 6.25 8 10.25l4-4\" {...props} />\n}\n\nexport function ClearGlyph(props: GlyphProps) {\n return <Glyph d=\"m4.5 4.5 7 7m0-7-7 7\" {...props} />\n}\n"],"mappings":";;;AAKA,SAAS,MAAM,EAAE,GAAG,GAAG,SAAqC;CAC1D,OACE,oBAAC,OAAD;EACE,OAAM;EACN,SAAQ;EACR,OAAO;EACP,QAAQ;EACR,MAAK;EACL,QAAO;EACP,aAAa;EACb,eAAc;EACd,gBAAe;EACf,eAAA;EACA,GAAI;YAEJ,oBAAC,QAAD,EAAS,EAAI,CAAA;CACV,CAAA;AAET;AAEA,SAAgB,iBAAiB,OAAmB;CAClD,OAAO,oBAAC,OAAD;EAAO,GAAE;EAAsB,GAAI;CAAQ,CAAA;AACpD;AAEA,SAAgB,WAAW,OAAmB;CAC5C,OAAO,oBAAC,OAAD;EAAO,GAAE;EAAuB,GAAI;CAAQ,CAAA;AACrD"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
let ictus = require("ictus");
|
|
4
|
+
let ictus_time = require("ictus/time");
|
|
5
|
+
//#region src/lib/date-time-mask.ts
|
|
6
|
+
const DATE_LENGTH = 10;
|
|
7
|
+
const JOIN = ", ";
|
|
8
|
+
const TIME_START = 12;
|
|
9
|
+
const splitValue = (value) => ({
|
|
10
|
+
date: value.slice(0, DATE_LENGTH),
|
|
11
|
+
time: value.length > DATE_LENGTH ? value.slice(TIME_START) : ""
|
|
12
|
+
});
|
|
13
|
+
const join = (date, time) => time ? `${date}${JOIN}${time}` : date;
|
|
14
|
+
/** Keys the mask consumes; any other printable key is ignored. */
|
|
15
|
+
function isDateTimeMaskKey(key, withTime = false) {
|
|
16
|
+
return (0, ictus.isDateMaskKey)(key) || withTime && (0, ictus_time.isTimeMaskKey)(key);
|
|
17
|
+
}
|
|
18
|
+
function stepOverSeparators(value, caret, key) {
|
|
19
|
+
const isSeparator = (char) => char !== void 0 && !/\d/.test(char);
|
|
20
|
+
let at = caret;
|
|
21
|
+
if (key === "Backspace") while (at > 0 && isSeparator(value[at - 1])) at--;
|
|
22
|
+
if (key === "Delete") while (at < value.length && isSeparator(value[at])) at++;
|
|
23
|
+
return at;
|
|
24
|
+
}
|
|
25
|
+
function applyDate(value, caret, key, separator, selectionEnd) {
|
|
26
|
+
if (selectionEnd !== void 0 && selectionEnd !== caret) return (0, ictus.apply)({
|
|
27
|
+
value,
|
|
28
|
+
caret,
|
|
29
|
+
selectionEnd,
|
|
30
|
+
key,
|
|
31
|
+
separator
|
|
32
|
+
});
|
|
33
|
+
return (0, ictus.apply)({
|
|
34
|
+
value,
|
|
35
|
+
caret: stepOverSeparators(value, caret, key),
|
|
36
|
+
key,
|
|
37
|
+
separator
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/** One keystroke through the date (and time) mask: the next value and caret. */
|
|
41
|
+
function applyDateTimeMask({ caret, key, selectionEnd, separator, value, withTime = false }) {
|
|
42
|
+
if (!withTime) return applyDate(value, caret, key, separator, selectionEnd);
|
|
43
|
+
const { date, time } = splitValue(value);
|
|
44
|
+
const end = selectionEnd ?? caret;
|
|
45
|
+
const dateComplete = date.length === DATE_LENGTH;
|
|
46
|
+
if (end !== caret && caret < DATE_LENGTH && end > DATE_LENGTH) return applyDate(date, caret, key, separator, DATE_LENGTH);
|
|
47
|
+
if (!(caret > DATE_LENGTH || caret === DATE_LENGTH && dateComplete && key !== "Backspace")) {
|
|
48
|
+
const next = applyDate(date, caret, key, separator, end !== caret ? end : void 0);
|
|
49
|
+
return {
|
|
50
|
+
value: join(next.value, time),
|
|
51
|
+
caret: next.caret
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return applyTimePart({
|
|
55
|
+
caret,
|
|
56
|
+
date,
|
|
57
|
+
end,
|
|
58
|
+
key,
|
|
59
|
+
separator,
|
|
60
|
+
time,
|
|
61
|
+
value
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function applyTimePart({ caret, date, end, key, separator, time, value }) {
|
|
65
|
+
if (!(0, ictus_time.isTimeMaskKey)(key)) return {
|
|
66
|
+
value,
|
|
67
|
+
caret
|
|
68
|
+
};
|
|
69
|
+
const timeCaret = Math.max(0, caret - TIME_START);
|
|
70
|
+
const timeEnd = Math.max(0, end - TIME_START);
|
|
71
|
+
const hasSelection = timeEnd !== timeCaret;
|
|
72
|
+
if (key === "Backspace" && !hasSelection && timeCaret === 0) {
|
|
73
|
+
const next = applyDate(date, DATE_LENGTH, key, separator);
|
|
74
|
+
return {
|
|
75
|
+
value: join(next.value, time),
|
|
76
|
+
caret: next.caret
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const next = (0, ictus_time.applyTime)({
|
|
80
|
+
value: time,
|
|
81
|
+
caret: hasSelection ? timeCaret : stepOverSeparators(time, timeCaret, key),
|
|
82
|
+
selectionEnd: hasSelection ? timeEnd : void 0,
|
|
83
|
+
key
|
|
84
|
+
});
|
|
85
|
+
return {
|
|
86
|
+
value: join(date, next.value),
|
|
87
|
+
caret: TIME_START + next.caret
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/** Pasted text through the mask, e.g. `24.11.2026 14:30` or `24/11/2026`. */
|
|
91
|
+
function applyDateTimePaste({ caret, pasted, selectionEnd, separator, value, withTime = false }) {
|
|
92
|
+
const [datePart = "", timePart = ""] = pasted.trim().split(/[,\sT]+/);
|
|
93
|
+
if (!withTime || !timePart) return (0, ictus.applyPaste)({
|
|
94
|
+
value,
|
|
95
|
+
caret,
|
|
96
|
+
selectionEnd,
|
|
97
|
+
pasted: datePart,
|
|
98
|
+
separator
|
|
99
|
+
});
|
|
100
|
+
const date = (0, ictus.applyPaste)({
|
|
101
|
+
value: "",
|
|
102
|
+
caret: 0,
|
|
103
|
+
pasted: datePart,
|
|
104
|
+
separator
|
|
105
|
+
}).value;
|
|
106
|
+
const time = (0, ictus_time.applyTimePaste)({
|
|
107
|
+
value: "",
|
|
108
|
+
caret: 0,
|
|
109
|
+
pasted: timePart
|
|
110
|
+
}).value;
|
|
111
|
+
const next = join(date, time);
|
|
112
|
+
return {
|
|
113
|
+
value: next,
|
|
114
|
+
caret: next.length
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/** `empty`, `incomplete`, `invalid` or `valid`, for the date and, with `withTime`, the time. */
|
|
118
|
+
function dateTimeStatus(text, withTime = false) {
|
|
119
|
+
const { date, time } = splitValue(text);
|
|
120
|
+
const dateState = (0, ictus.dateStatus)(date);
|
|
121
|
+
if (!withTime || dateState === "empty" || dateState === "invalid") return dateState;
|
|
122
|
+
if (dateState === "incomplete") return "incomplete";
|
|
123
|
+
const timeState = time ? (0, ictus_time.timeStatus)(time) : "incomplete";
|
|
124
|
+
return timeState === "empty" ? "incomplete" : timeState;
|
|
125
|
+
}
|
|
126
|
+
/** The date in the text, with its time when `withTime`; undefined until it is complete and real. */
|
|
127
|
+
function parseDateTime(text, withTime = false) {
|
|
128
|
+
if (dateTimeStatus(text, withTime) !== "valid") return void 0;
|
|
129
|
+
const { date, time } = splitValue(text);
|
|
130
|
+
const day = (0, ictus.parseDate)(date);
|
|
131
|
+
if (!day || !withTime) return day;
|
|
132
|
+
const clock = (0, ictus_time.parseTime)(time);
|
|
133
|
+
if (!clock) return void 0;
|
|
134
|
+
day.setHours(clock.hours, clock.minutes, 0, 0);
|
|
135
|
+
return day;
|
|
136
|
+
}
|
|
137
|
+
/** The day in the text, even while its time is still being typed. */
|
|
138
|
+
function parseDatePart(text) {
|
|
139
|
+
return (0, ictus.parseDate)(splitValue(text).date);
|
|
140
|
+
}
|
|
141
|
+
/** The masked text for a date: `24.11.2026` or `24.11.2026, 14:30`. */
|
|
142
|
+
function formatDateTime(date, separator, withTime = false) {
|
|
143
|
+
return join((0, ictus.formatDate)(date, separator), withTime ? (0, ictus_time.formatTime)(date) : "");
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
exports.applyDateTimeMask = applyDateTimeMask;
|
|
147
|
+
exports.applyDateTimePaste = applyDateTimePaste;
|
|
148
|
+
exports.dateTimeStatus = dateTimeStatus;
|
|
149
|
+
exports.formatDateTime = formatDateTime;
|
|
150
|
+
exports.formatTime = ictus_time.formatTime;
|
|
151
|
+
exports.isDateTimeMaskKey = isDateTimeMaskKey;
|
|
152
|
+
exports.parseDatePart = parseDatePart;
|
|
153
|
+
exports.parseDateTime = parseDateTime;
|
|
154
|
+
|
|
155
|
+
//# sourceMappingURL=date-time-mask.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-time-mask.cjs","names":[],"sources":["../../src/lib/date-time-mask.ts"],"sourcesContent":["import {\n apply,\n applyPaste,\n dateStatus,\n formatDate,\n isDateMaskKey,\n parseDate,\n} from 'ictus'\nimport {\n applyTime,\n applyTimePaste,\n formatTime,\n isTimeMaskKey,\n parseTime,\n timeStatus,\n} from 'ictus/time'\n\n// Fixed positions: `DD.MM.YYYY` then `, HH:MM`, i.e. day-month-year with a one-character\n// separator, the only layout Input Date Time types\nconst DATE_LENGTH = 10\nconst JOIN = ', '\nconst TIME_START = DATE_LENGTH + JOIN.length\n\ntype MaskOptions = { separator: string; withTime?: boolean }\n\nexport type DateTimeMaskInput = MaskOptions & {\n caret: number\n key: string\n selectionEnd?: number\n value: string\n}\n\nexport type DateTimeMaskResult = { caret: number; value: string }\n\nexport type DateTimeStatus = 'empty' | 'incomplete' | 'invalid' | 'valid'\n\nconst splitValue = (value: string) => ({\n date: value.slice(0, DATE_LENGTH),\n time: value.length > DATE_LENGTH ? value.slice(TIME_START) : '',\n})\n\nconst join = (date: string, time: string) =>\n time ? `${date}${JOIN}${time}` : date\n\n/** Keys the mask consumes; any other printable key is ignored. */\nexport function isDateTimeMaskKey(key: string, withTime = false) {\n return isDateMaskKey(key) || (withTime && isTimeMaskKey(key))\n}\n\n// Backspace right after a separator deletes the digit before it, Delete right before one the digit after\nfunction stepOverSeparators(value: string, caret: number, key: string) {\n const isSeparator = (char: string | undefined) =>\n char !== undefined && !/\\d/.test(char)\n let at = caret\n if (key === 'Backspace') while (at > 0 && isSeparator(value[at - 1])) at--\n if (key === 'Delete') while (at < value.length && isSeparator(value[at])) at++\n return at\n}\n\nfunction applyDate(\n value: string,\n caret: number,\n key: string,\n separator: string,\n selectionEnd?: number,\n): DateTimeMaskResult {\n if (selectionEnd !== undefined && selectionEnd !== caret)\n return apply({ value, caret, selectionEnd, key, separator })\n return apply({\n value,\n caret: stepOverSeparators(value, caret, key),\n key,\n separator,\n })\n}\n\n/** One keystroke through the date (and time) mask: the next value and caret. */\nexport function applyDateTimeMask({\n caret,\n key,\n selectionEnd,\n separator,\n value,\n withTime = false,\n}: DateTimeMaskInput): DateTimeMaskResult {\n if (!withTime) return applyDate(value, caret, key, separator, selectionEnd)\n\n const { date, time } = splitValue(value)\n const end = selectionEnd ?? caret\n const dateComplete = date.length === DATE_LENGTH\n\n // A selection reaching into the time drops the time; one inside it edits the time only\n if (end !== caret && caret < DATE_LENGTH && end > DATE_LENGTH)\n return applyDate(date, caret, key, separator, DATE_LENGTH)\n\n const inTime =\n caret > DATE_LENGTH ||\n (caret === DATE_LENGTH && dateComplete && key !== 'Backspace')\n if (!inTime) {\n const next = applyDate(\n date,\n caret,\n key,\n separator,\n end !== caret ? end : undefined,\n )\n return { value: join(next.value, time), caret: next.caret }\n }\n\n return applyTimePart({ caret, date, end, key, separator, time, value })\n}\n\nfunction applyTimePart({\n caret,\n date,\n end,\n key,\n separator,\n time,\n value,\n}: {\n caret: number\n date: string\n end: number\n key: string\n separator: string\n time: string\n value: string\n}): DateTimeMaskResult {\n if (!isTimeMaskKey(key)) return { value, caret }\n const timeCaret = Math.max(0, caret - TIME_START)\n const timeEnd = Math.max(0, end - TIME_START)\n const hasSelection = timeEnd !== timeCaret\n\n // Backspace at the start of the time steps back into the year\n if (key === 'Backspace' && !hasSelection && timeCaret === 0) {\n const next = applyDate(date, DATE_LENGTH, key, separator)\n return { value: join(next.value, time), caret: next.caret }\n }\n\n const next = applyTime({\n value: time,\n caret: hasSelection ? timeCaret : stepOverSeparators(time, timeCaret, key),\n selectionEnd: hasSelection ? timeEnd : undefined,\n key,\n })\n return { value: join(date, next.value), caret: TIME_START + next.caret }\n}\n\n/** Pasted text through the mask, e.g. `24.11.2026 14:30` or `24/11/2026`. */\nexport function applyDateTimePaste({\n caret,\n pasted,\n selectionEnd,\n separator,\n value,\n withTime = false,\n}: MaskOptions & {\n caret: number\n pasted: string\n selectionEnd?: number\n value: string\n}): DateTimeMaskResult {\n const [datePart = '', timePart = ''] = pasted.trim().split(/[,\\sT]+/)\n if (!withTime || !timePart)\n return applyPaste({\n value,\n caret,\n selectionEnd,\n pasted: datePart,\n separator,\n })\n\n const date = applyPaste({\n value: '',\n caret: 0,\n pasted: datePart,\n separator,\n }).value\n const time = applyTimePaste({ value: '', caret: 0, pasted: timePart }).value\n const next = join(date, time)\n return { value: next, caret: next.length }\n}\n\n/** `empty`, `incomplete`, `invalid` or `valid`, for the date and, with `withTime`, the time. */\nexport function dateTimeStatus(text: string, withTime = false): DateTimeStatus {\n const { date, time } = splitValue(text)\n const dateState = dateStatus(date)\n if (!withTime || dateState === 'empty' || dateState === 'invalid')\n return dateState\n if (dateState === 'incomplete') return 'incomplete'\n const timeState = time ? timeStatus(time) : 'incomplete'\n return timeState === 'empty' ? 'incomplete' : timeState\n}\n\n/** The date in the text, with its time when `withTime`; undefined until it is complete and real. */\nexport function parseDateTime(\n text: string,\n withTime = false,\n): Date | undefined {\n if (dateTimeStatus(text, withTime) !== 'valid') return undefined\n const { date, time } = splitValue(text)\n const day = parseDate(date)\n if (!day || !withTime) return day\n const clock = parseTime(time)\n if (!clock) return undefined\n day.setHours(clock.hours, clock.minutes, 0, 0)\n return day\n}\n\n/** The day in the text, even while its time is still being typed. */\nexport function parseDatePart(text: string) {\n return parseDate(splitValue(text).date)\n}\n\n/** The masked text for a date: `24.11.2026` or `24.11.2026, 14:30`. */\nexport function formatDateTime(\n date: Date,\n separator: string,\n withTime = false,\n) {\n return join(formatDate(date, separator), withTime ? formatTime(date) : '')\n}\n\nexport { formatTime }\n"],"mappings":";;;;;AAmBA,MAAM,cAAc;AACpB,MAAM,OAAO;AACb,MAAM,aAAa;AAenB,MAAM,cAAc,WAAmB;CACrC,MAAM,MAAM,MAAM,GAAG,WAAW;CAChC,MAAM,MAAM,SAAS,cAAc,MAAM,MAAM,UAAU,IAAI;AAC/D;AAEA,MAAM,QAAQ,MAAc,SAC1B,OAAO,GAAG,OAAO,OAAO,SAAS;;AAGnC,SAAgB,kBAAkB,KAAa,WAAW,OAAO;CAC/D,QAAA,GAAA,MAAA,eAAqB,GAAG,KAAM,aAAA,GAAA,WAAA,eAA0B,GAAG;AAC7D;AAGA,SAAS,mBAAmB,OAAe,OAAe,KAAa;CACrE,MAAM,eAAe,SACnB,SAAS,KAAA,KAAa,CAAC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AAc,OAAO;CACvC,MAAM,YAAY,QAAA,GAAA,WAAA,YAAkB,IAAI,IAAI;CAC5C,OAAO,cAAc,UAAU,eAAe;AAChD;;AAGA,SAAgB,cACd,MACA,WAAW,OACO;CAClB,IAAI,eAAe,MAAM,QAAQ,MAAM,SAAS,OAAO,KAAA;CACvD,MAAM,EAAE,MAAM,SAAS,WAAW,IAAI;CACtC,MAAM,OAAA,GAAA,MAAA,WAAgB,IAAI;CAC1B,IAAI,CAAC,OAAO,CAAC,UAAU,OAAO;CAC9B,MAAM,SAAA,GAAA,WAAA,WAAkB,IAAI;CAC5B,IAAI,CAAC,OAAO,OAAO,KAAA;CACnB,IAAI,SAAS,MAAM,OAAO,MAAM,SAAS,GAAG,CAAC;CAC7C,OAAO;AACT;;AAGA,SAAgB,cAAc,MAAc;CAC1C,QAAA,GAAA,MAAA,WAAiB,WAAW,IAAI,EAAE,IAAI;AACxC;;AAGA,SAAgB,eACd,MACA,WACA,WAAW,OACX;CACA,OAAO,MAAA,GAAA,MAAA,YAAgB,MAAM,SAAS,GAAG,YAAA,GAAA,WAAA,YAAsB,IAAI,IAAI,EAAE;AAC3E"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { formatTime } from "ictus/time";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/date-time-mask.d.ts
|
|
6
|
+
type MaskOptions = {
|
|
7
|
+
separator: string;
|
|
8
|
+
withTime?: boolean;
|
|
9
|
+
};
|
|
10
|
+
type DateTimeMaskInput = MaskOptions & {
|
|
11
|
+
caret: number;
|
|
12
|
+
key: string;
|
|
13
|
+
selectionEnd?: number;
|
|
14
|
+
value: string;
|
|
15
|
+
};
|
|
16
|
+
type DateTimeMaskResult = {
|
|
17
|
+
caret: number;
|
|
18
|
+
value: string;
|
|
19
|
+
};
|
|
20
|
+
type DateTimeStatus = 'empty' | 'incomplete' | 'invalid' | 'valid';
|
|
21
|
+
/** Keys the mask consumes; any other printable key is ignored. */
|
|
22
|
+
declare function isDateTimeMaskKey(key: string, withTime?: boolean): boolean;
|
|
23
|
+
/** One keystroke through the date (and time) mask: the next value and caret. */
|
|
24
|
+
declare function applyDateTimeMask({
|
|
25
|
+
caret,
|
|
26
|
+
key,
|
|
27
|
+
selectionEnd,
|
|
28
|
+
separator,
|
|
29
|
+
value,
|
|
30
|
+
withTime
|
|
31
|
+
}: DateTimeMaskInput): DateTimeMaskResult;
|
|
32
|
+
/** Pasted text through the mask, e.g. `24.11.2026 14:30` or `24/11/2026`. */
|
|
33
|
+
declare function applyDateTimePaste({
|
|
34
|
+
caret,
|
|
35
|
+
pasted,
|
|
36
|
+
selectionEnd,
|
|
37
|
+
separator,
|
|
38
|
+
value,
|
|
39
|
+
withTime
|
|
40
|
+
}: MaskOptions & {
|
|
41
|
+
caret: number;
|
|
42
|
+
pasted: string;
|
|
43
|
+
selectionEnd?: number;
|
|
44
|
+
value: string;
|
|
45
|
+
}): DateTimeMaskResult;
|
|
46
|
+
/** `empty`, `incomplete`, `invalid` or `valid`, for the date and, with `withTime`, the time. */
|
|
47
|
+
declare function dateTimeStatus(text: string, withTime?: boolean): DateTimeStatus;
|
|
48
|
+
/** The date in the text, with its time when `withTime`; undefined until it is complete and real. */
|
|
49
|
+
declare function parseDateTime(text: string, withTime?: boolean): Date | undefined;
|
|
50
|
+
/** The day in the text, even while its time is still being typed. */
|
|
51
|
+
declare function parseDatePart(text: string): Date | undefined;
|
|
52
|
+
/** The masked text for a date: `24.11.2026` or `24.11.2026, 14:30`. */
|
|
53
|
+
declare function formatDateTime(date: Date, separator: string, withTime?: boolean): string;
|
|
54
|
+
//#endregion
|
|
55
|
+
export { DateTimeMaskInput, DateTimeMaskResult, DateTimeStatus, applyDateTimeMask, applyDateTimePaste, dateTimeStatus, formatDateTime, formatTime, isDateTimeMaskKey, parseDatePart, parseDateTime };
|
|
56
|
+
//# sourceMappingURL=date-time-mask.d.cts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { formatTime } from "ictus/time";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/date-time-mask.d.ts
|
|
6
|
+
type MaskOptions = {
|
|
7
|
+
separator: string;
|
|
8
|
+
withTime?: boolean;
|
|
9
|
+
};
|
|
10
|
+
type DateTimeMaskInput = MaskOptions & {
|
|
11
|
+
caret: number;
|
|
12
|
+
key: string;
|
|
13
|
+
selectionEnd?: number;
|
|
14
|
+
value: string;
|
|
15
|
+
};
|
|
16
|
+
type DateTimeMaskResult = {
|
|
17
|
+
caret: number;
|
|
18
|
+
value: string;
|
|
19
|
+
};
|
|
20
|
+
type DateTimeStatus = 'empty' | 'incomplete' | 'invalid' | 'valid';
|
|
21
|
+
/** Keys the mask consumes; any other printable key is ignored. */
|
|
22
|
+
declare function isDateTimeMaskKey(key: string, withTime?: boolean): boolean;
|
|
23
|
+
/** One keystroke through the date (and time) mask: the next value and caret. */
|
|
24
|
+
declare function applyDateTimeMask({
|
|
25
|
+
caret,
|
|
26
|
+
key,
|
|
27
|
+
selectionEnd,
|
|
28
|
+
separator,
|
|
29
|
+
value,
|
|
30
|
+
withTime
|
|
31
|
+
}: DateTimeMaskInput): DateTimeMaskResult;
|
|
32
|
+
/** Pasted text through the mask, e.g. `24.11.2026 14:30` or `24/11/2026`. */
|
|
33
|
+
declare function applyDateTimePaste({
|
|
34
|
+
caret,
|
|
35
|
+
pasted,
|
|
36
|
+
selectionEnd,
|
|
37
|
+
separator,
|
|
38
|
+
value,
|
|
39
|
+
withTime
|
|
40
|
+
}: MaskOptions & {
|
|
41
|
+
caret: number;
|
|
42
|
+
pasted: string;
|
|
43
|
+
selectionEnd?: number;
|
|
44
|
+
value: string;
|
|
45
|
+
}): DateTimeMaskResult;
|
|
46
|
+
/** `empty`, `incomplete`, `invalid` or `valid`, for the date and, with `withTime`, the time. */
|
|
47
|
+
declare function dateTimeStatus(text: string, withTime?: boolean): DateTimeStatus;
|
|
48
|
+
/** The date in the text, with its time when `withTime`; undefined until it is complete and real. */
|
|
49
|
+
declare function parseDateTime(text: string, withTime?: boolean): Date | undefined;
|
|
50
|
+
/** The day in the text, even while its time is still being typed. */
|
|
51
|
+
declare function parseDatePart(text: string): Date | undefined;
|
|
52
|
+
/** The masked text for a date: `24.11.2026` or `24.11.2026, 14:30`. */
|
|
53
|
+
declare function formatDateTime(date: Date, separator: string, withTime?: boolean): string;
|
|
54
|
+
//#endregion
|
|
55
|
+
export { DateTimeMaskInput, DateTimeMaskResult, DateTimeStatus, applyDateTimeMask, applyDateTimePaste, dateTimeStatus, formatDateTime, formatTime, isDateTimeMaskKey, parseDatePart, parseDateTime };
|
|
56
|
+
//# sourceMappingURL=date-time-mask.d.ts.map
|