@mdbase-dev/ui 0.2.0 → 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/collections/CollectionGate.js +20 -13
- package/dist/collections/use-collection-ui.d.ts +14 -2
- package/dist/collections/use-collection-ui.js +13 -0
- 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
|
|
@@ -10,7 +10,7 @@ import { ActionButton, CollectionMark, GateFooter, ItemCopy, ItemMore, NoticeBlo
|
|
|
10
10
|
import { SetupReview } from "./SetupReview.js";
|
|
11
11
|
import { BringInBanner, UnsyncedLine } from "./UnsyncedWork.js";
|
|
12
12
|
import { unsyncedApi } from "./unsynced.js";
|
|
13
|
-
import { useAutoStart, useCollectionUi } from "./use-collection-ui.js";
|
|
13
|
+
import { cancelAuthorizationApi, useAutoStart, useCollectionUi } from "./use-collection-ui.js";
|
|
14
14
|
/**
|
|
15
15
|
* Everything before a collection is open: sign-in, choosing, approval, setup
|
|
16
16
|
* review and problems. In phase `ready` it renders the app, with a banner
|
|
@@ -299,18 +299,25 @@ function GateBody({
|
|
|
299
299
|
})]
|
|
300
300
|
});
|
|
301
301
|
case "authorizing":
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
302
|
+
{
|
|
303
|
+
// Signing in from work before connecting: cancelling goes back to it.
|
|
304
|
+
const unsynced = view.purpose === "sign_in" && ui.options.unsynced && unsyncedApi(ui.options.mdbase);
|
|
305
|
+
const cancellable = cancelAuthorizationApi(ui.options.mdbase) !== null || busy === "sign_in" || busy === "add" || busy === "approve";
|
|
306
|
+
return _jsxs("div", {
|
|
307
|
+
className: "mdbase-collections-actions",
|
|
308
|
+
children: [_jsx(ActionButton, {
|
|
309
|
+
tone: "secondary",
|
|
310
|
+
inert: busy === "cancel",
|
|
311
|
+
onClick: actions.reopen,
|
|
312
|
+
children: copy.openWindowAgain
|
|
313
|
+
}), cancellable && _jsx(ActionButton, {
|
|
314
|
+
tone: "quiet",
|
|
315
|
+
inert: busy === "cancel",
|
|
316
|
+
onClick: actions.cancel,
|
|
317
|
+
children: unsynced ? copy.continueWithoutConnecting : copy.cancel
|
|
318
|
+
})]
|
|
319
|
+
});
|
|
320
|
+
}
|
|
314
321
|
case "choosing":
|
|
315
322
|
return _jsxs(_Fragment, {
|
|
316
323
|
children: [view.notice && _jsx(NoticeBlock, {
|
|
@@ -97,7 +97,7 @@ export interface CollectionUiOptions {
|
|
|
97
97
|
readonly unsynced?: CollectionUnsyncedOptions | boolean | undefined;
|
|
98
98
|
}
|
|
99
99
|
/** `add_private` remains available to legacy track callers; both add APIs now emit `add`. */
|
|
100
|
-
export type CollectionActionName = "sign_in" | "add" | "add_private" | "approve" | "select" | "choose_another" | "assess" | "start" | "sign_out" | "setup" | "open_unsynced" | "bring_in" | "discard_unsynced";
|
|
100
|
+
export type CollectionActionName = "sign_in" | "add" | "add_private" | "approve" | "select" | "choose_another" | "assess" | "start" | "sign_out" | "setup" | "open_unsynced" | "bring_in" | "discard_unsynced" | "cancel";
|
|
101
101
|
export interface CollectionUi {
|
|
102
102
|
readonly view: CollectionView;
|
|
103
103
|
readonly copy: CollectionCopy;
|
|
@@ -130,7 +130,9 @@ export interface CollectionActions {
|
|
|
130
130
|
chooseAnother(): void;
|
|
131
131
|
/** Open the Connect window again for the authorization in progress. */
|
|
132
132
|
reopen(): void;
|
|
133
|
-
/**
|
|
133
|
+
/** Stop waiting for Connect: signed out again (or back to work before
|
|
134
|
+
* connecting), or the collection list when signed in. On an SDK without
|
|
135
|
+
* `cancelAuthorization` it only abandons the call this page started. */
|
|
134
136
|
cancel(): void;
|
|
135
137
|
assess(): void;
|
|
136
138
|
start(): void;
|
|
@@ -153,6 +155,15 @@ export interface CollectionActions {
|
|
|
153
155
|
discardUnsynced(): void;
|
|
154
156
|
dismissUnsyncedNotice(): void;
|
|
155
157
|
}
|
|
158
|
+
type CancelAuthorization = (options: {
|
|
159
|
+
readonly signal?: AbortSignal;
|
|
160
|
+
}) => Promise<unknown>;
|
|
161
|
+
/**
|
|
162
|
+
* `mdbase.cancelAuthorization`, or null on an SDK release that predates it.
|
|
163
|
+
* Read structurally because this package builds against the vendored
|
|
164
|
+
* production SDK; drop it once that SDK and the peer floor include it.
|
|
165
|
+
*/
|
|
166
|
+
export declare function cancelAuthorizationApi(mdbase: Mdbase): CancelAuthorization | null;
|
|
156
167
|
/** The first current item across the app's sections. */
|
|
157
168
|
export declare function appOpenItem(sections: readonly CollectionSection[] | undefined): OpenSectionItem | null;
|
|
158
169
|
/**
|
|
@@ -163,3 +174,4 @@ export declare function appOpenItem(sections: readonly CollectionSection[] | und
|
|
|
163
174
|
export declare function useAutoStart(mdbase: Mdbase, enabled?: boolean): void;
|
|
164
175
|
/** Subscribe to the app's mdbase entry and get its view plus gesture-safe actions. */
|
|
165
176
|
export declare function useCollectionUi(options: CollectionUiOptions): CollectionUi;
|
|
177
|
+
export {};
|
|
@@ -5,6 +5,15 @@ import { defaultCollectionCopy, fill } from "./copy.js";
|
|
|
5
5
|
import { actionNotice, collectionView } from "./model.js";
|
|
6
6
|
import { planNeedsReview, unsyncedApi } from "./unsynced.js";
|
|
7
7
|
const popupActions = new Set(["sign_in", "add", "add_private", "approve"]);
|
|
8
|
+
/**
|
|
9
|
+
* `mdbase.cancelAuthorization`, or null on an SDK release that predates it.
|
|
10
|
+
* Read structurally because this package builds against the vendored
|
|
11
|
+
* production SDK; drop it once that SDK and the peer floor include it.
|
|
12
|
+
*/
|
|
13
|
+
export function cancelAuthorizationApi(mdbase) {
|
|
14
|
+
const cancel = mdbase.cancelAuthorization;
|
|
15
|
+
return typeof cancel === "function" ? options => cancel.call(mdbase, options) : null;
|
|
16
|
+
}
|
|
8
17
|
/** The first current item across the app's sections. */
|
|
9
18
|
export function appOpenItem(sections) {
|
|
10
19
|
for (const section of sections ?? []) {
|
|
@@ -224,6 +233,10 @@ export function useCollectionUi(options) {
|
|
|
224
233
|
cancel: () => {
|
|
225
234
|
const current = running.current;
|
|
226
235
|
if (current && popupActions.has(current.name)) current.controller.abort();
|
|
236
|
+
const cancel = cancelAuthorizationApi(mdbase);
|
|
237
|
+
if (cancel) void run("cancel", signal => cancel({
|
|
238
|
+
signal
|
|
239
|
+
}), true);
|
|
227
240
|
},
|
|
228
241
|
assess: () => {
|
|
229
242
|
void run("assess", signal => mdbase.assess({
|
|
@@ -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[][];
|