@mdbase-dev/ui 0.2.1 → 0.2.2
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/README.md +119 -0
- package/css/controls.css +37 -0
- package/css/date-picker.css +176 -0
- package/css/filter-builder.css +336 -0
- package/css/properties.css +398 -0
- package/dist/AnchoredPopover.d.ts +20 -0
- package/dist/AnchoredPopover.js +100 -0
- package/dist/Combo.d.ts +41 -0
- package/dist/Combo.js +82 -0
- package/dist/DatePicker.d.ts +69 -0
- package/dist/DatePicker.js +317 -0
- package/dist/Menu.d.ts +3 -1
- package/dist/Menu.js +3 -2
- package/dist/QuickCreate.js +1 -16
- package/dist/date-picker-model.d.ts +31 -0
- package/dist/date-picker-model.js +97 -0
- package/dist/filter-builder/AddFilter.d.ts +13 -0
- package/dist/filter-builder/AddFilter.js +295 -0
- package/dist/filter-builder/FilterBuilder.d.ts +36 -0
- package/dist/filter-builder/FilterBuilder.js +225 -0
- package/dist/filter-builder/FilterPill.d.ts +17 -0
- package/dist/filter-builder/FilterPill.js +494 -0
- package/dist/filter-builder/context.d.ts +40 -0
- package/dist/filter-builder/context.js +67 -0
- package/dist/filter-builder/editors.d.ts +31 -0
- package/dist/filter-builder/editors.js +294 -0
- package/dist/filter-builder/filter-ast.d.ts +13 -0
- package/dist/filter-builder/filter-ast.js +382 -0
- package/dist/filter-builder/labels.d.ts +99 -0
- package/dist/filter-builder/labels.js +555 -0
- package/dist/filter-builder/menu.d.ts +21 -0
- package/dist/filter-builder/menu.js +60 -0
- package/dist/filter-builder/operators.d.ts +30 -0
- package/dist/filter-builder/operators.js +192 -0
- package/dist/filter-builder/tree.d.ts +12 -0
- package/dist/filter-builder/tree.js +61 -0
- package/dist/filter-builder/types.d.ts +69 -0
- package/dist/filter-builder/types.js +48 -0
- package/dist/filter-builder.d.ts +13 -0
- package/dist/filter-builder.js +10 -0
- package/dist/glyphs.d.ts +32 -0
- package/dist/glyphs.js +143 -0
- package/dist/locales/de/messages.json +1 -1
- package/dist/locales/en/messages.json +1 -1
- package/dist/locales/es/messages.json +1 -1
- package/dist/locales/fr/messages.json +1 -1
- package/dist/locales/it/messages.json +1 -1
- package/dist/locales/ja/messages.json +1 -1
- package/dist/locales/ko/messages.json +1 -1
- package/dist/locales/pt/messages.json +1 -1
- package/dist/locales/ru/messages.json +1 -1
- package/dist/locales/zh/messages.json +1 -1
- package/dist/popover.d.ts +5 -0
- package/dist/popover.js +15 -0
- package/dist/properties/PropertyList.d.ts +31 -0
- package/dist/properties/PropertyList.js +233 -0
- package/dist/properties/PropertyValue.d.ts +42 -0
- package/dist/properties/PropertyValue.js +304 -0
- package/dist/properties/fields.d.ts +20 -0
- package/dist/properties/fields.js +81 -0
- package/dist/properties/labels.d.ts +29 -0
- package/dist/properties/labels.js +127 -0
- package/dist/properties/model.d.ts +52 -0
- package/dist/properties/model.js +195 -0
- package/dist/properties.d.ts +13 -0
- package/dist/properties.js +9 -0
- package/package.json +25 -2
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type JSX } from "react";
|
|
2
|
+
import { type DayWords } from "./date-picker-model.js";
|
|
3
|
+
export { dayText, parseDay } from "./date-picker-model.js";
|
|
4
|
+
/** The date picker's own text. */
|
|
5
|
+
export interface DateLabels extends DayWords {
|
|
6
|
+
/** The field's placeholder: what can be typed in it. */
|
|
7
|
+
readonly typeDate: string;
|
|
8
|
+
readonly clear: string;
|
|
9
|
+
readonly previousMonth: string;
|
|
10
|
+
readonly nextMonth: string;
|
|
11
|
+
/** The calendar's accessible name. */
|
|
12
|
+
readonly calendar: string;
|
|
13
|
+
}
|
|
14
|
+
/** The date picker's text in the current language. */
|
|
15
|
+
export declare function dateLabels(): DateLabels;
|
|
16
|
+
/**
|
|
17
|
+
* What someone typed as a day: a date as it is stored (`2026-11-28`), today, tomorrow or
|
|
18
|
+
* yesterday by name, a weekday (the next one), or a number of days or weeks from today (`+3`,
|
|
19
|
+
* `-1`, `2w`). Null when it is none of those.
|
|
20
|
+
*/
|
|
21
|
+
export declare function readDay(text: string, options?: {
|
|
22
|
+
readonly labels?: DayWords;
|
|
23
|
+
readonly now?: Date;
|
|
24
|
+
readonly locale?: string;
|
|
25
|
+
}): string | null;
|
|
26
|
+
/** A stored day as people read it: `28 Nov 2026`, without the year when it is this one and `short` is set. Other text is returned as it is. */
|
|
27
|
+
export declare function formatDay(value: string, options?: {
|
|
28
|
+
readonly short?: boolean;
|
|
29
|
+
readonly now?: Date;
|
|
30
|
+
readonly locale?: string;
|
|
31
|
+
}): string;
|
|
32
|
+
export interface CalendarProps {
|
|
33
|
+
/** The chosen day, as it is stored. */
|
|
34
|
+
value: string | null;
|
|
35
|
+
onPick: (value: string) => void;
|
|
36
|
+
/** Offer to take the date away. */
|
|
37
|
+
onClear?: (() => void) | undefined;
|
|
38
|
+
/** Whether the text field asks for the focus when the calendar appears in a popover. */
|
|
39
|
+
autoFocus?: boolean | undefined;
|
|
40
|
+
/** The locale the month is drawn in. By default, the language of the interface. */
|
|
41
|
+
locale?: string | undefined;
|
|
42
|
+
/** Text to show in place of the shared catalogue's. */
|
|
43
|
+
labels?: Partial<DateLabels> | undefined;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A month to pick a day from, under a field that takes a typed one. The arrow keys move through
|
|
47
|
+
* the days from either the field or the grid; Enter takes the day they are on.
|
|
48
|
+
*/
|
|
49
|
+
export declare function Calendar(props: CalendarProps): JSX.Element;
|
|
50
|
+
export interface DateFieldProps {
|
|
51
|
+
/** The date as it is stored, or empty. */
|
|
52
|
+
value: string;
|
|
53
|
+
/** Names the field for assistive technology. */
|
|
54
|
+
label: string;
|
|
55
|
+
/** Shown while there is no date. */
|
|
56
|
+
placeholder: string;
|
|
57
|
+
className?: string | undefined;
|
|
58
|
+
/** Open the calendar as soon as the field appears. */
|
|
59
|
+
defaultOpen?: boolean | undefined;
|
|
60
|
+
/** Leave the year out when it is this one: for a card, where room is short. */
|
|
61
|
+
short?: boolean | undefined;
|
|
62
|
+
onChange: (value: string | null) => void;
|
|
63
|
+
/** The calendar was closed, with or without a date chosen. */
|
|
64
|
+
onClose?: (() => void) | undefined;
|
|
65
|
+
/** Text to show in place of the shared catalogue's. */
|
|
66
|
+
labels?: Partial<DateLabels> | undefined;
|
|
67
|
+
}
|
|
68
|
+
/** A date that reads as a date and opens a calendar to change it. */
|
|
69
|
+
export declare function DateField(props: DateFieldProps): JSX.Element;
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { i18n } from "@lingui/core";
|
|
3
|
+
import { i18n as _i18n } from "@lingui/core";
|
|
4
|
+
import { useMemo, useRef, useState } from "react";
|
|
5
|
+
import { AnchoredPopover } from "./AnchoredPopover.js";
|
|
6
|
+
import { DAY, dayText, formatDay as formatDayIn, monthGrid, parseDay, readDay as readDayIn, stamp, todayStamp, weekdayNames, weekStart } from "./date-picker-model.js";
|
|
7
|
+
import { Glyph } from "./glyphs.js";
|
|
8
|
+
import { useLocaleRevision } from "./i18n.js";
|
|
9
|
+
export { dayText, parseDay } from "./date-picker-model.js";
|
|
10
|
+
/** The date picker's text in the current language. */
|
|
11
|
+
export function dateLabels() {
|
|
12
|
+
return {
|
|
13
|
+
typeDate: _i18n._(
|
|
14
|
+
/** i18n */
|
|
15
|
+
{
|
|
16
|
+
id: "LgOpgW",
|
|
17
|
+
message: "A date, \u201Ctomorrow\u201D, \u201Cfri\u201D or \u201C+3\u201D"
|
|
18
|
+
}),
|
|
19
|
+
today: _i18n._(
|
|
20
|
+
/** i18n */
|
|
21
|
+
{
|
|
22
|
+
id: "ecUA8p",
|
|
23
|
+
message: "Today"
|
|
24
|
+
}),
|
|
25
|
+
tomorrow: _i18n._(
|
|
26
|
+
/** i18n */
|
|
27
|
+
{
|
|
28
|
+
id: "BRMXj0",
|
|
29
|
+
message: "Tomorrow"
|
|
30
|
+
}),
|
|
31
|
+
yesterday: _i18n._(
|
|
32
|
+
/** i18n */
|
|
33
|
+
{
|
|
34
|
+
id: "y_0uwd",
|
|
35
|
+
message: "Yesterday"
|
|
36
|
+
}),
|
|
37
|
+
clear: _i18n._(
|
|
38
|
+
/** i18n */
|
|
39
|
+
{
|
|
40
|
+
id: "xCJdfg",
|
|
41
|
+
message: "Clear"
|
|
42
|
+
}),
|
|
43
|
+
previousMonth: _i18n._(
|
|
44
|
+
/** i18n */
|
|
45
|
+
{
|
|
46
|
+
id: "1xwZj_",
|
|
47
|
+
message: "Previous month"
|
|
48
|
+
}),
|
|
49
|
+
nextMonth: _i18n._(
|
|
50
|
+
/** i18n */
|
|
51
|
+
{
|
|
52
|
+
id: "g8JmSC",
|
|
53
|
+
message: "Next month"
|
|
54
|
+
}),
|
|
55
|
+
calendar: _i18n._(
|
|
56
|
+
/** i18n */
|
|
57
|
+
{
|
|
58
|
+
id: "AjVXBS",
|
|
59
|
+
message: "Calendar"
|
|
60
|
+
})
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The locale dates are written in: the language of the interface, in the browser's own variant
|
|
65
|
+
* of it when it has one, since that says which day starts the week and how a date is ordered.
|
|
66
|
+
*/
|
|
67
|
+
function displayLocale() {
|
|
68
|
+
const language = i18n.locale || "en";
|
|
69
|
+
const browser = typeof navigator === "undefined" ? undefined : navigator.language;
|
|
70
|
+
if (browser && browser.toLowerCase().split("-")[0] === language) return browser;
|
|
71
|
+
return language === "pt" ? "pt-BR" : language === "zh" ? "zh-CN" : language;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* What someone typed as a day: a date as it is stored (`2026-11-28`), today, tomorrow or
|
|
75
|
+
* yesterday by name, a weekday (the next one), or a number of days or weeks from today (`+3`,
|
|
76
|
+
* `-1`, `2w`). Null when it is none of those.
|
|
77
|
+
*/
|
|
78
|
+
export function readDay(text, options = {}) {
|
|
79
|
+
const at = readDayIn(text, options.labels ?? dateLabels(), options.now, options.locale ?? displayLocale());
|
|
80
|
+
return at === null ? null : dayText(at);
|
|
81
|
+
}
|
|
82
|
+
/** A stored day as people read it: `28 Nov 2026`, without the year when it is this one and `short` is set. Other text is returned as it is. */
|
|
83
|
+
export function formatDay(value, options = {}) {
|
|
84
|
+
return formatDayIn(value, {
|
|
85
|
+
...options,
|
|
86
|
+
locale: options.locale ?? displayLocale()
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* A month to pick a day from, under a field that takes a typed one. The arrow keys move through
|
|
91
|
+
* the days from either the field or the grid; Enter takes the day they are on.
|
|
92
|
+
*/
|
|
93
|
+
export function Calendar(props) {
|
|
94
|
+
useLocaleRevision();
|
|
95
|
+
const labels = {
|
|
96
|
+
...dateLabels(),
|
|
97
|
+
...props.labels
|
|
98
|
+
};
|
|
99
|
+
const locale = props.locale ?? displayLocale();
|
|
100
|
+
const chosen = props.value ? parseDay(props.value) : null;
|
|
101
|
+
const today = todayStamp();
|
|
102
|
+
const [cursor, setCursor] = useState(chosen ?? today);
|
|
103
|
+
const [text, setText] = useState("");
|
|
104
|
+
const grid = useRef(null);
|
|
105
|
+
const firstDay = useMemo(() => weekStart(locale), [locale]);
|
|
106
|
+
const names = useMemo(() => ({
|
|
107
|
+
narrow: weekdayNames(locale, "narrow"),
|
|
108
|
+
long: weekdayNames(locale, "long")
|
|
109
|
+
}), [locale]);
|
|
110
|
+
const at = new Date(cursor);
|
|
111
|
+
const [year, month] = [at.getUTCFullYear(), at.getUTCMonth()];
|
|
112
|
+
const weeks = useMemo(() => monthGrid(year, month, firstDay), [year, month, firstDay]);
|
|
113
|
+
const title = new Intl.DateTimeFormat(locale, {
|
|
114
|
+
month: "long",
|
|
115
|
+
year: "numeric",
|
|
116
|
+
timeZone: "UTC"
|
|
117
|
+
}).format(stamp(year, month, 1));
|
|
118
|
+
const full = useMemo(() => new Intl.DateTimeFormat(locale, {
|
|
119
|
+
weekday: "long",
|
|
120
|
+
day: "numeric",
|
|
121
|
+
month: "long",
|
|
122
|
+
year: "numeric",
|
|
123
|
+
timeZone: "UTC"
|
|
124
|
+
}), [locale]);
|
|
125
|
+
const typed = readDayIn(text, labels, new Date(), locale);
|
|
126
|
+
const shiftMonth = by => {
|
|
127
|
+
const target = new Date(stamp(year, month + by, 1));
|
|
128
|
+
const last = new Date(stamp(target.getUTCFullYear(), target.getUTCMonth() + 1, 0)).getUTCDate();
|
|
129
|
+
setCursor(stamp(target.getUTCFullYear(), target.getUTCMonth(), Math.min(at.getUTCDate(), last)));
|
|
130
|
+
};
|
|
131
|
+
const move = (event, inGrid) => {
|
|
132
|
+
const steps = {
|
|
133
|
+
ArrowUp: -7,
|
|
134
|
+
ArrowDown: 7,
|
|
135
|
+
...(inGrid ? {
|
|
136
|
+
ArrowLeft: -1,
|
|
137
|
+
ArrowRight: 1
|
|
138
|
+
} : {})
|
|
139
|
+
};
|
|
140
|
+
const step = steps[event.key];
|
|
141
|
+
if (step !== undefined) {
|
|
142
|
+
setCursor(cursor + step * DAY);
|
|
143
|
+
} else if (event.key === "PageUp" || event.key === "PageDown") {
|
|
144
|
+
shiftMonth((event.key === "PageUp" ? -1 : 1) * (event.shiftKey ? 12 : 1));
|
|
145
|
+
} else if (inGrid && (event.key === "Home" || event.key === "End")) {
|
|
146
|
+
const column = (at.getUTCDay() - firstDay + 7) % 7;
|
|
147
|
+
setCursor(cursor + (event.key === "Home" ? -column : 6 - column) * DAY);
|
|
148
|
+
} else {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
return true;
|
|
153
|
+
};
|
|
154
|
+
return _jsxs("div", {
|
|
155
|
+
className: "mdbase-calendar",
|
|
156
|
+
children: [_jsx("input", {
|
|
157
|
+
className: "mdbase-field mdbase-calendar-input",
|
|
158
|
+
"data-autofocus": props.autoFocus === false ? undefined : "",
|
|
159
|
+
value: text,
|
|
160
|
+
placeholder: labels.typeDate,
|
|
161
|
+
"aria-label": labels.typeDate,
|
|
162
|
+
spellCheck: false,
|
|
163
|
+
autoComplete: "off",
|
|
164
|
+
onChange: event => {
|
|
165
|
+
setText(event.target.value);
|
|
166
|
+
const found = readDayIn(event.target.value, labels, new Date(), locale);
|
|
167
|
+
if (found !== null) setCursor(found);
|
|
168
|
+
},
|
|
169
|
+
onKeyDown: event => {
|
|
170
|
+
if (event.key === "Enter") {
|
|
171
|
+
event.preventDefault();
|
|
172
|
+
event.stopPropagation();
|
|
173
|
+
// Something typed that is not a date is not a reason to take the day shown.
|
|
174
|
+
if (!text.trim() || typed !== null) props.onPick(dayText(typed ?? cursor));
|
|
175
|
+
} else if (move(event, false)) {
|
|
176
|
+
event.stopPropagation();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}), text.trim() ? _jsx("p", {
|
|
180
|
+
className: "mdbase-calendar-read",
|
|
181
|
+
"data-unread": typed === null ? "" : undefined,
|
|
182
|
+
"aria-live": "polite",
|
|
183
|
+
children: typed === null ? "—" : full.format(typed)
|
|
184
|
+
}) : null, _jsxs("div", {
|
|
185
|
+
className: "mdbase-calendar-head",
|
|
186
|
+
children: [_jsx("span", {
|
|
187
|
+
className: "mdbase-calendar-title",
|
|
188
|
+
"aria-live": "polite",
|
|
189
|
+
children: title
|
|
190
|
+
}), _jsx("button", {
|
|
191
|
+
type: "button",
|
|
192
|
+
className: "mdbase-calendar-step",
|
|
193
|
+
"aria-label": labels.previousMonth,
|
|
194
|
+
title: labels.previousMonth,
|
|
195
|
+
onClick: () => shiftMonth(-1),
|
|
196
|
+
children: _jsx(Glyph, {
|
|
197
|
+
name: "left"
|
|
198
|
+
})
|
|
199
|
+
}), _jsx("button", {
|
|
200
|
+
type: "button",
|
|
201
|
+
className: "mdbase-calendar-step",
|
|
202
|
+
"aria-label": labels.nextMonth,
|
|
203
|
+
title: labels.nextMonth,
|
|
204
|
+
onClick: () => shiftMonth(1),
|
|
205
|
+
children: _jsx(Glyph, {
|
|
206
|
+
name: "right"
|
|
207
|
+
})
|
|
208
|
+
})]
|
|
209
|
+
}), _jsxs("div", {
|
|
210
|
+
ref: grid,
|
|
211
|
+
className: "mdbase-calendar-grid",
|
|
212
|
+
role: "grid",
|
|
213
|
+
"aria-label": labels.calendar,
|
|
214
|
+
onKeyDown: event => {
|
|
215
|
+
if (move(event, true)) {
|
|
216
|
+
event.stopPropagation();
|
|
217
|
+
// The day the keys land on takes the focus once it is drawn.
|
|
218
|
+
requestAnimationFrame(() => grid.current?.querySelector('[tabindex="0"]')?.focus({
|
|
219
|
+
preventScroll: true
|
|
220
|
+
}));
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
children: [_jsx("div", {
|
|
224
|
+
className: "mdbase-calendar-week",
|
|
225
|
+
role: "row",
|
|
226
|
+
children: Array.from({
|
|
227
|
+
length: 7
|
|
228
|
+
}, (_unused, index) => _jsx("span", {
|
|
229
|
+
role: "columnheader",
|
|
230
|
+
"aria-label": names.long[(index + firstDay) % 7],
|
|
231
|
+
children: names.narrow[(index + firstDay) % 7]
|
|
232
|
+
}, index))
|
|
233
|
+
}), weeks.map(week => _jsx("div", {
|
|
234
|
+
className: "mdbase-calendar-week",
|
|
235
|
+
role: "row",
|
|
236
|
+
children: week.map(day => _jsx("button", {
|
|
237
|
+
type: "button",
|
|
238
|
+
role: "gridcell",
|
|
239
|
+
className: "mdbase-calendar-day",
|
|
240
|
+
tabIndex: day === cursor ? 0 : -1,
|
|
241
|
+
"aria-label": full.format(day),
|
|
242
|
+
"aria-selected": day === chosen,
|
|
243
|
+
"aria-current": day === today ? "date" : undefined,
|
|
244
|
+
"data-outside": new Date(day).getUTCMonth() === month ? undefined : "",
|
|
245
|
+
"data-cursor": day === cursor ? "" : undefined,
|
|
246
|
+
onClick: () => props.onPick(dayText(day)),
|
|
247
|
+
children: new Date(day).getUTCDate()
|
|
248
|
+
}, day))
|
|
249
|
+
}, week[0]))]
|
|
250
|
+
}), _jsxs("div", {
|
|
251
|
+
className: "mdbase-calendar-foot",
|
|
252
|
+
children: [_jsx("button", {
|
|
253
|
+
type: "button",
|
|
254
|
+
className: "mdbase-calendar-quick",
|
|
255
|
+
onClick: () => props.onPick(dayText(today)),
|
|
256
|
+
children: labels.today
|
|
257
|
+
}), _jsx("button", {
|
|
258
|
+
type: "button",
|
|
259
|
+
className: "mdbase-calendar-quick",
|
|
260
|
+
onClick: () => props.onPick(dayText(today + DAY)),
|
|
261
|
+
children: labels.tomorrow
|
|
262
|
+
}), props.onClear && props.value ? _jsx("button", {
|
|
263
|
+
type: "button",
|
|
264
|
+
className: "mdbase-calendar-quick",
|
|
265
|
+
"data-clear": "",
|
|
266
|
+
onClick: props.onClear,
|
|
267
|
+
children: labels.clear
|
|
268
|
+
}) : null]
|
|
269
|
+
})]
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
/** A date that reads as a date and opens a calendar to change it. */
|
|
273
|
+
export function DateField(props) {
|
|
274
|
+
useLocaleRevision();
|
|
275
|
+
const [open, setOpen] = useState(Boolean(props.defaultOpen));
|
|
276
|
+
const anchor = useRef(null);
|
|
277
|
+
const close = refocus => {
|
|
278
|
+
setOpen(false);
|
|
279
|
+
if (refocus) anchor.current?.focus({
|
|
280
|
+
preventScroll: true
|
|
281
|
+
});
|
|
282
|
+
props.onClose?.();
|
|
283
|
+
};
|
|
284
|
+
const shown = props.value ? formatDay(props.value, {
|
|
285
|
+
short: Boolean(props.short)
|
|
286
|
+
}) : props.placeholder;
|
|
287
|
+
return _jsxs(_Fragment, {
|
|
288
|
+
children: [_jsx("button", {
|
|
289
|
+
ref: anchor,
|
|
290
|
+
type: "button",
|
|
291
|
+
className: ["mdbase-date-field", props.className].filter(Boolean).join(" "),
|
|
292
|
+
"aria-label": `${props.label}: ${shown}`,
|
|
293
|
+
"aria-haspopup": "dialog",
|
|
294
|
+
"aria-expanded": open,
|
|
295
|
+
"data-empty": props.value ? undefined : "",
|
|
296
|
+
onClick: () => setOpen(!open),
|
|
297
|
+
children: shown
|
|
298
|
+
}), open ? _jsx(AnchoredPopover, {
|
|
299
|
+
anchor: anchor,
|
|
300
|
+
label: props.label,
|
|
301
|
+
className: "mdbase-date-popover",
|
|
302
|
+
onClose: close,
|
|
303
|
+
children: _jsx(Calendar, {
|
|
304
|
+
value: props.value || null,
|
|
305
|
+
labels: props.labels,
|
|
306
|
+
onPick: value => {
|
|
307
|
+
if (value !== props.value) props.onChange(value);
|
|
308
|
+
close(true);
|
|
309
|
+
},
|
|
310
|
+
onClear: () => {
|
|
311
|
+
props.onChange(null);
|
|
312
|
+
close(true);
|
|
313
|
+
}
|
|
314
|
+
})
|
|
315
|
+
}) : null]
|
|
316
|
+
});
|
|
317
|
+
}
|
package/dist/Menu.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type KeyboardEvent, type ReactNode, type RefObject } from "react";
|
|
2
|
-
export declare function Menu({ open, triggerRef, onClose, id, label, className, children, point }: {
|
|
2
|
+
export declare function Menu({ open, triggerRef, onClose, id, label, className, children, point, align }: {
|
|
3
3
|
readonly open: boolean;
|
|
4
4
|
readonly triggerRef: RefObject<HTMLElement | null>;
|
|
5
5
|
readonly onClose: (refocus: boolean) => void;
|
|
@@ -11,6 +11,8 @@ export declare function Menu({ open, triggerRef, onClose, id, label, className,
|
|
|
11
11
|
readonly left: number;
|
|
12
12
|
readonly top: number;
|
|
13
13
|
} | undefined;
|
|
14
|
+
/** Which edge of the trigger the menu lines up with. */
|
|
15
|
+
readonly align?: "start" | "end" | undefined;
|
|
14
16
|
}): import("react").JSX.Element | null;
|
|
15
17
|
export declare function useMenuTrigger(): {
|
|
16
18
|
id: string;
|
package/dist/Menu.js
CHANGED
|
@@ -10,14 +10,15 @@ export function Menu({
|
|
|
10
10
|
label,
|
|
11
11
|
className = "mdbase-menu",
|
|
12
12
|
children,
|
|
13
|
-
point
|
|
13
|
+
point,
|
|
14
|
+
align = "end"
|
|
14
15
|
}) {
|
|
15
16
|
const {
|
|
16
17
|
ref,
|
|
17
18
|
present
|
|
18
19
|
} = useOverlay(open);
|
|
19
20
|
useMenuPopover(ref, triggerRef, onClose, {
|
|
20
|
-
align
|
|
21
|
+
align,
|
|
21
22
|
open,
|
|
22
23
|
point
|
|
23
24
|
});
|
package/dist/QuickCreate.js
CHANGED
|
@@ -3,24 +3,9 @@ import { i18n as _i18n } from "@lingui/core";
|
|
|
3
3
|
import { useEffect, useEffectEvent, useLayoutEffect, useRef } from "react";
|
|
4
4
|
import { createPortal } from "react-dom";
|
|
5
5
|
import { useLocaleRevision } from "./i18n.js";
|
|
6
|
-
import { anchoredPlacement } from "./popover.js";
|
|
6
|
+
import { activeModalDialog, anchoredPlacement } from "./popover.js";
|
|
7
7
|
const FOCUSABLE = ':is(button, input, select, textarea, [tabindex="0"]):not(:disabled)';
|
|
8
8
|
const OPEN_LIST = '[aria-expanded="true"], [role="listbox"], [role="menu"]';
|
|
9
|
-
/**
|
|
10
|
-
* The topmost open modal `<dialog>`, if one is showing. A modal dialog makes everything outside
|
|
11
|
-
* its subtree inert—even a top-layer popover—so a form opened while one is open mounts inside it.
|
|
12
|
-
*/
|
|
13
|
-
function activeModalDialog() {
|
|
14
|
-
if (typeof document === "undefined") return null;
|
|
15
|
-
try {
|
|
16
|
-
const modal = document.querySelectorAll("dialog:modal");
|
|
17
|
-
if (modal.length) return modal[modal.length - 1];
|
|
18
|
-
} catch {
|
|
19
|
-
// Fall through when :modal is unsupported.
|
|
20
|
-
}
|
|
21
|
-
const open = document.querySelectorAll('dialog[open][aria-modal="true"]');
|
|
22
|
-
return open.length ? open[open.length - 1] : null;
|
|
23
|
-
}
|
|
24
9
|
/**
|
|
25
10
|
* A short form for a record made in passing, beside the place it is made from: its name, then
|
|
26
11
|
* the fields the app asks for. It opens in the top layer and takes the keyboard until it is
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** The names of the days nearest today, as they can be typed into a date field. */
|
|
2
|
+
export interface DayWords {
|
|
3
|
+
readonly today: string;
|
|
4
|
+
readonly tomorrow: string;
|
|
5
|
+
readonly yesterday: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const DAY = 86400000;
|
|
8
|
+
/** A calendar day as a number of days, free of time zones: midnight UTC of that day. */
|
|
9
|
+
export declare const stamp: (year: number, month: number, day: number) => number;
|
|
10
|
+
/** `2026-11-28` as a day, or null when it is not a real date. */
|
|
11
|
+
export declare function parseDay(text: string): number | null;
|
|
12
|
+
export declare function dayText(at: number): string;
|
|
13
|
+
/** Today, where the person is. */
|
|
14
|
+
export declare function todayStamp(now?: Date): number;
|
|
15
|
+
export declare const weekdayNames: (locale: string | undefined, width: "long" | "short" | "narrow") => string[];
|
|
16
|
+
/**
|
|
17
|
+
* What someone typed as a day: a date as it is stored (`2026-11-28`), one of the day's names
|
|
18
|
+
* (today, tomorrow, yesterday), a weekday (the next one), or a number of days or weeks from
|
|
19
|
+
* today (`+3`, `-1`, `2w`). Null when it is none of those.
|
|
20
|
+
*/
|
|
21
|
+
export declare function readDay(text: string, words: DayWords, now?: Date, locale?: string): number | null;
|
|
22
|
+
/** A day as people read it: `28 Nov 2026`, without the year when it is this one and `short` is set. */
|
|
23
|
+
export declare function formatDay(value: string, options?: {
|
|
24
|
+
short?: boolean;
|
|
25
|
+
now?: Date;
|
|
26
|
+
locale?: string;
|
|
27
|
+
}): string;
|
|
28
|
+
/** The first day of the week where the person is: 0 for Sunday. Monday where the browser cannot say. */
|
|
29
|
+
export declare function weekStart(locale: string | undefined): number;
|
|
30
|
+
/** The six weeks a month is shown in, starting on the week's first day. */
|
|
31
|
+
export declare function monthGrid(year: number, month: number, firstDay: number): number[][];
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export const DAY = 86_400_000;
|
|
2
|
+
const iso = /^(\d{4})-(\d{2})-(\d{2})$/u;
|
|
3
|
+
/** A calendar day as a number of days, free of time zones: midnight UTC of that day. */
|
|
4
|
+
export const stamp = (year, month, day) => Date.UTC(year, month, day);
|
|
5
|
+
/** `2026-11-28` as a day, or null when it is not a real date. */
|
|
6
|
+
export function parseDay(text) {
|
|
7
|
+
const match = iso.exec(text.trim());
|
|
8
|
+
if (!match) return null;
|
|
9
|
+
const [year, month, day] = [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
10
|
+
const at = stamp(year, month - 1, day);
|
|
11
|
+
const date = new Date(at);
|
|
12
|
+
return date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day ? at : null;
|
|
13
|
+
}
|
|
14
|
+
export function dayText(at) {
|
|
15
|
+
return new Date(at).toISOString().slice(0, 10);
|
|
16
|
+
}
|
|
17
|
+
/** Today, where the person is. */
|
|
18
|
+
export function todayStamp(now = new Date()) {
|
|
19
|
+
return stamp(now.getFullYear(), now.getMonth(), now.getDate());
|
|
20
|
+
}
|
|
21
|
+
export const weekdayNames = (locale, width) => {
|
|
22
|
+
const format = new Intl.DateTimeFormat(locale, {
|
|
23
|
+
weekday: width,
|
|
24
|
+
timeZone: "UTC"
|
|
25
|
+
});
|
|
26
|
+
// 2024-01-07 was a Sunday.
|
|
27
|
+
return Array.from({
|
|
28
|
+
length: 7
|
|
29
|
+
}, (_unused, index) => format.format(stamp(2024, 0, 7 + index)));
|
|
30
|
+
};
|
|
31
|
+
/** Text as it is compared: a typed apostrophe is the one a catalogue writes (`aujourd’hui`). */
|
|
32
|
+
const plain = text => text.trim().toLowerCase().replaceAll("’", "'");
|
|
33
|
+
/**
|
|
34
|
+
* What someone typed as a day: a date as it is stored (`2026-11-28`), one of the day's names
|
|
35
|
+
* (today, tomorrow, yesterday), a weekday (the next one), or a number of days or weeks from
|
|
36
|
+
* today (`+3`, `-1`, `2w`). Null when it is none of those.
|
|
37
|
+
*/
|
|
38
|
+
export function readDay(text, words, now = new Date(), locale) {
|
|
39
|
+
const typed = plain(text);
|
|
40
|
+
if (!typed) return null;
|
|
41
|
+
const exact = parseDay(typed);
|
|
42
|
+
if (exact !== null) return exact;
|
|
43
|
+
const today = todayStamp(now);
|
|
44
|
+
const named = [[words.today, 0], [words.tomorrow, 1], [words.yesterday, -1]];
|
|
45
|
+
for (const [word, offset] of named) {
|
|
46
|
+
if (plain(word) === typed) return today + offset * DAY;
|
|
47
|
+
}
|
|
48
|
+
const relative = /^([+-]?)(\d{1,4})\s*([dw]?)$/u.exec(typed);
|
|
49
|
+
if (relative && (relative[1] || relative[3])) {
|
|
50
|
+
const days = Number(relative[2]) * (relative[3] === "w" ? 7 : 1);
|
|
51
|
+
return today + (relative[1] === "-" ? -days : days) * DAY;
|
|
52
|
+
}
|
|
53
|
+
if (typed.length >= 2) {
|
|
54
|
+
const long = weekdayNames(locale, "long").map(name => name.toLowerCase());
|
|
55
|
+
const index = long.findIndex(name => name.startsWith(typed));
|
|
56
|
+
if (index >= 0) {
|
|
57
|
+
const ahead = (index - new Date(today).getUTCDay() + 7) % 7 || 7;
|
|
58
|
+
return today + ahead * DAY;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
/** A day as people read it: `28 Nov 2026`, without the year when it is this one and `short` is set. */
|
|
64
|
+
export function formatDay(value, options = {}) {
|
|
65
|
+
const at = parseDay(value);
|
|
66
|
+
if (at === null) return value;
|
|
67
|
+
const sameYear = new Date(at).getUTCFullYear() === (options.now ?? new Date()).getFullYear();
|
|
68
|
+
return new Intl.DateTimeFormat(options.locale, {
|
|
69
|
+
day: "numeric",
|
|
70
|
+
month: "short",
|
|
71
|
+
...(options.short && sameYear ? {} : {
|
|
72
|
+
year: "numeric"
|
|
73
|
+
}),
|
|
74
|
+
timeZone: "UTC"
|
|
75
|
+
}).format(at);
|
|
76
|
+
}
|
|
77
|
+
/** The first day of the week where the person is: 0 for Sunday. Monday where the browser cannot say. */
|
|
78
|
+
export function weekStart(locale) {
|
|
79
|
+
try {
|
|
80
|
+
const info = new Intl.Locale(locale ?? navigator.language);
|
|
81
|
+
const first = info.getWeekInfo?.().firstDay ?? info.weekInfo?.firstDay;
|
|
82
|
+
return typeof first === "number" ? first % 7 : 1;
|
|
83
|
+
} catch {
|
|
84
|
+
return 1;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** The six weeks a month is shown in, starting on the week's first day. */
|
|
88
|
+
export function monthGrid(year, month, firstDay) {
|
|
89
|
+
const first = stamp(year, month, 1);
|
|
90
|
+
const lead = (new Date(first).getUTCDay() - firstDay + 7) % 7;
|
|
91
|
+
const start = first - lead * DAY;
|
|
92
|
+
return Array.from({
|
|
93
|
+
length: 6
|
|
94
|
+
}, (_week, week) => Array.from({
|
|
95
|
+
length: 7
|
|
96
|
+
}, (_day, day) => start + (week * 7 + day) * DAY));
|
|
97
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type JSX } from "react";
|
|
2
|
+
import { type Tier } from "./context.js";
|
|
3
|
+
export interface AddFilterProps {
|
|
4
|
+
tier: Tier;
|
|
5
|
+
/** The group new filters join; null for the root of the chosen scope. */
|
|
6
|
+
groupId: string | null;
|
|
7
|
+
onClose: (restoreFocus: boolean) => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* What `Filter` opens: a list of fields to search, then (in place) the value for the field
|
|
11
|
+
* picked. A checked value applies at once; a typed one on Enter or its button.
|
|
12
|
+
*/
|
|
13
|
+
export declare function AddFilter({ tier, groupId, onClose }: AddFilterProps): JSX.Element;
|