@bigpixelrocket/uiok 0.0.0-stage → 0.1.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/CHANGELOG.md +42 -0
- package/LICENSE +21 -0
- package/NOTICE +569 -0
- package/README.md +44 -2
- package/dist/VisuallyHidden.d.ts +13 -0
- package/dist/VisuallyHidden.js +13 -0
- package/dist/activity/ActivityBar.d.ts +29 -0
- package/dist/activity/ActivityBar.js +21 -0
- package/dist/activity/activity.css +43 -0
- package/dist/activity/index.d.ts +2 -0
- package/dist/activity/index.js +2 -0
- package/dist/button/Button.d.ts +26 -0
- package/dist/button/Button.js +14 -0
- package/dist/button/IconButton.d.ts +18 -0
- package/dist/button/IconButton.js +14 -0
- package/dist/button/button.css +95 -0
- package/dist/button/index.d.ts +3 -0
- package/dist/button/index.js +3 -0
- package/dist/charts/Drawing.d.ts +27 -0
- package/dist/charts/Drawing.js +117 -0
- package/dist/charts/Drawing.logic.d.ts +2 -0
- package/dist/charts/Drawing.logic.js +22 -0
- package/dist/charts/Line.logic.d.ts +33 -0
- package/dist/charts/Line.logic.js +72 -0
- package/dist/charts/LineChart.d.ts +34 -0
- package/dist/charts/LineChart.js +100 -0
- package/dist/charts/Pie.logic.d.ts +16 -0
- package/dist/charts/Pie.logic.js +28 -0
- package/dist/charts/PieChart.d.ts +20 -0
- package/dist/charts/PieChart.js +16 -0
- package/dist/charts/ResultChart.d.ts +47 -0
- package/dist/charts/ResultChart.js +175 -0
- package/dist/charts/ResultChart.logic.d.ts +42 -0
- package/dist/charts/ResultChart.logic.js +165 -0
- package/dist/charts/Scatter.logic.d.ts +55 -0
- package/dist/charts/Scatter.logic.js +134 -0
- package/dist/charts/ScatterChart.d.ts +36 -0
- package/dist/charts/ScatterChart.js +99 -0
- package/dist/charts/charts.css +310 -0
- package/dist/charts/index.d.ts +14 -0
- package/dist/charts/index.js +11 -0
- package/dist/charts/seriesColour.d.ts +2 -0
- package/dist/charts/seriesColour.js +8 -0
- package/dist/clock/index.d.ts +2 -0
- package/dist/clock/index.js +2 -0
- package/dist/clock/useClock.d.ts +14 -0
- package/dist/clock/useClock.js +57 -0
- package/dist/datetime/DateTimePicker.d.ts +50 -0
- package/dist/datetime/DateTimePicker.js +98 -0
- package/dist/datetime/DateTimePicker.logic.d.ts +59 -0
- package/dist/datetime/DateTimePicker.logic.js +103 -0
- package/dist/datetime/datetime.css +115 -0
- package/dist/datetime/index.d.ts +7 -0
- package/dist/datetime/index.js +7 -0
- package/dist/dialog/ConfirmDialog.d.ts +73 -0
- package/dist/dialog/ConfirmDialog.js +30 -0
- package/dist/dialog/DialogLegend.d.ts +21 -0
- package/dist/dialog/DialogLegend.js +28 -0
- package/dist/dialog/DialogLegend.logic.d.ts +145 -0
- package/dist/dialog/DialogLegend.logic.js +71 -0
- package/dist/dialog/ModalDialog.d.ts +101 -0
- package/dist/dialog/ModalDialog.js +184 -0
- package/dist/dialog/dialog.css +283 -0
- package/dist/dialog/index.d.ts +8 -0
- package/dist/dialog/index.js +8 -0
- package/dist/filter/FilterEscape.d.ts +16 -0
- package/dist/filter/FilterEscape.js +15 -0
- package/dist/filter/FilterIcon.d.ts +8 -0
- package/dist/filter/FilterIcon.js +11 -0
- package/dist/filter/filter.css +42 -0
- package/dist/filter/index.d.ts +3 -0
- package/dist/filter/index.js +3 -0
- package/dist/grid/DataGrid.d.ts +149 -0
- package/dist/grid/DataGrid.js +373 -0
- package/dist/grid/DataGrid.logic.d.ts +57 -0
- package/dist/grid/DataGrid.logic.js +121 -0
- package/dist/grid/grid.css +206 -0
- package/dist/grid/index.d.ts +7 -0
- package/dist/grid/index.js +7 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +32 -0
- package/dist/keyboard/BrowserKeys.d.ts +15 -0
- package/dist/keyboard/BrowserKeys.js +28 -0
- package/dist/keyboard/KeyChord.logic.d.ts +25 -0
- package/dist/keyboard/KeyChord.logic.js +50 -0
- package/dist/keyboard/Keyboard.logic.d.ts +84 -0
- package/dist/keyboard/Keyboard.logic.js +137 -0
- package/dist/keyboard/OverlayWatch.d.ts +28 -0
- package/dist/keyboard/OverlayWatch.js +119 -0
- package/dist/keyboard/PageSelectAll.d.ts +14 -0
- package/dist/keyboard/PageSelectAll.js +22 -0
- package/dist/keyboard/index.d.ts +9 -0
- package/dist/keyboard/index.js +9 -0
- package/dist/keychord/KeyChord.d.ts +16 -0
- package/dist/keychord/KeyChord.js +55 -0
- package/dist/keychord/index.d.ts +2 -0
- package/dist/keychord/index.js +2 -0
- package/dist/keychord/keychord.css +41 -0
- package/dist/labels/UiokLabels.d.ts +41 -0
- package/dist/labels/UiokLabels.js +31 -0
- package/dist/labels/UiokProvider.d.ts +44 -0
- package/dist/labels/UiokProvider.js +54 -0
- package/dist/labels/charts.d.ts +34 -0
- package/dist/labels/charts.js +15 -0
- package/dist/labels/dateTime.d.ts +32 -0
- package/dist/labels/dateTime.js +14 -0
- package/dist/labels/dialog.d.ts +18 -0
- package/dist/labels/dialog.js +6 -0
- package/dist/labels/index.d.ts +13 -0
- package/dist/labels/index.js +13 -0
- package/dist/labels/keys.d.ts +28 -0
- package/dist/labels/keys.js +53 -0
- package/dist/labels/legend.d.ts +21 -0
- package/dist/labels/legend.js +7 -0
- package/dist/labels/listing.d.ts +16 -0
- package/dist/labels/listing.js +8 -0
- package/dist/labels/pager.d.ts +32 -0
- package/dist/labels/pager.js +20 -0
- package/dist/labels/palette.d.ts +17 -0
- package/dist/labels/palette.js +6 -0
- package/dist/labels/selectAll.d.ts +15 -0
- package/dist/labels/selectAll.js +6 -0
- package/dist/labels/terminal.d.ts +25 -0
- package/dist/labels/terminal.js +9 -0
- package/dist/legend/KeyLegend.logic.d.ts +84 -0
- package/dist/legend/KeyLegend.logic.js +109 -0
- package/dist/legend/KeyLegendStrip.d.ts +36 -0
- package/dist/legend/KeyLegendStrip.js +82 -0
- package/dist/legend/index.d.ts +3 -0
- package/dist/legend/index.js +3 -0
- package/dist/legend/legend.css +148 -0
- package/dist/listing/CurrentDot.d.ts +15 -0
- package/dist/listing/CurrentDot.js +13 -0
- package/dist/listing/Listing.d.ts +230 -0
- package/dist/listing/Listing.js +265 -0
- package/dist/listing/PathParts.logic.d.ts +17 -0
- package/dist/listing/PathParts.logic.js +18 -0
- package/dist/listing/index.d.ts +10 -0
- package/dist/listing/index.js +10 -0
- package/dist/listing/listing.css +867 -0
- package/dist/menu/MenuQuery.logic.d.ts +69 -0
- package/dist/menu/MenuQuery.logic.js +75 -0
- package/dist/menu/fuzzyMatch.d.ts +31 -0
- package/dist/menu/fuzzyMatch.js +296 -0
- package/dist/menu/index.d.ts +9 -0
- package/dist/menu/index.js +9 -0
- package/dist/menu/menu.css +203 -0
- package/dist/menu/useBellBeat.d.ts +8 -0
- package/dist/menu/useBellBeat.js +26 -0
- package/dist/namecut/NameCut.d.ts +22 -0
- package/dist/namecut/NameCut.js +28 -0
- package/dist/namecut/NameCut.logic.d.ts +51 -0
- package/dist/namecut/NameCut.logic.js +120 -0
- package/dist/namecut/index.d.ts +3 -0
- package/dist/namecut/index.js +3 -0
- package/dist/namecut/namecut.css +67 -0
- package/dist/pager/Pager.d.ts +37 -0
- package/dist/pager/Pager.js +38 -0
- package/dist/pager/Pager.logic.d.ts +13 -0
- package/dist/pager/Pager.logic.js +63 -0
- package/dist/pager/index.d.ts +7 -0
- package/dist/pager/index.js +7 -0
- package/dist/pager/pager.css +62 -0
- package/dist/palette/Palette.d.ts +79 -0
- package/dist/palette/Palette.js +60 -0
- package/dist/palette/index.d.ts +6 -0
- package/dist/palette/index.js +6 -0
- package/dist/palette/palette.css +159 -0
- package/dist/pane/PaneActions.d.ts +104 -0
- package/dist/pane/PaneActions.js +62 -0
- package/dist/pane/PaneFrame.d.ts +51 -0
- package/dist/pane/PaneFrame.js +28 -0
- package/dist/pane/PaneKeys.d.ts +41 -0
- package/dist/pane/PaneKeys.js +104 -0
- package/dist/pane/PaneKeys.logic.d.ts +95 -0
- package/dist/pane/PaneKeys.logic.js +109 -0
- package/dist/pane/index.d.ts +11 -0
- package/dist/pane/index.js +11 -0
- package/dist/pane/usePaneKeys.d.ts +141 -0
- package/dist/pane/usePaneKeys.js +313 -0
- package/dist/run/RunHeader.d.ts +50 -0
- package/dist/run/RunHeader.js +31 -0
- package/dist/run/RunProgress.logic.d.ts +29 -0
- package/dist/run/RunProgress.logic.js +34 -0
- package/dist/run/index.d.ts +3 -0
- package/dist/run/index.js +3 -0
- package/dist/run/run.css +190 -0
- package/dist/segmented/SegmentedChoice.d.ts +22 -0
- package/dist/segmented/SegmentedChoice.js +31 -0
- package/dist/segmented/index.d.ts +2 -0
- package/dist/segmented/index.js +2 -0
- package/dist/segmented/segmented.css +49 -0
- package/dist/selectall/CheckRange.logic.d.ts +8 -0
- package/dist/selectall/CheckRange.logic.js +23 -0
- package/dist/selectall/SelectAllBar.d.ts +25 -0
- package/dist/selectall/SelectAllBar.js +24 -0
- package/dist/selectall/index.d.ts +7 -0
- package/dist/selectall/index.js +7 -0
- package/dist/selectall/selectall.css +31 -0
- package/dist/store/KeepUnchanged.logic.d.ts +19 -0
- package/dist/store/KeepUnchanged.logic.js +33 -0
- package/dist/store/SameProps.d.ts +15 -0
- package/dist/store/SameProps.js +46 -0
- package/dist/store/ValueStore.d.ts +17 -0
- package/dist/store/ValueStore.js +23 -0
- package/dist/store/index.d.ts +8 -0
- package/dist/store/index.js +8 -0
- package/dist/store/useStableHandlers.d.ts +13 -0
- package/dist/store/useStableHandlers.js +22 -0
- package/dist/styles.css +85 -0
- package/dist/tabs/PageTabs.d.ts +38 -0
- package/dist/tabs/PageTabs.js +33 -0
- package/dist/tabs/index.d.ts +2 -0
- package/dist/tabs/index.js +2 -0
- package/dist/tabs/tabs.css +64 -0
- package/dist/terminal/Terminal.d.ts +104 -0
- package/dist/terminal/Terminal.js +309 -0
- package/dist/terminal/Terminal.logic.d.ts +66 -0
- package/dist/terminal/Terminal.logic.js +156 -0
- package/dist/terminal/TerminalMenu.d.ts +36 -0
- package/dist/terminal/TerminalMenu.js +87 -0
- package/dist/terminal/TerminalMenu.logic.d.ts +78 -0
- package/dist/terminal/TerminalMenu.logic.js +68 -0
- package/dist/terminal/TerminalScrollback.d.ts +10 -0
- package/dist/terminal/TerminalScrollback.js +11 -0
- package/dist/terminal/ghostty/LICENSE +21 -0
- package/dist/terminal/ghostty/core.d.ts +315 -0
- package/dist/terminal/ghostty/core.js +1189 -0
- package/dist/terminal/ghostty/fallbackColors.d.ts +12 -0
- package/dist/terminal/ghostty/fallbackColors.js +23 -0
- package/dist/terminal/ghostty/fonts/LICENSE +21 -0
- package/dist/terminal/ghostty/fonts/SymbolsNerdFontMono-Regular.woff2 +0 -0
- package/dist/terminal/ghostty/keyCodes.logic.d.ts +20 -0
- package/dist/terminal/ghostty/keyCodes.logic.js +249 -0
- package/dist/terminal/ghostty/links.logic.d.ts +39 -0
- package/dist/terminal/ghostty/links.logic.js +84 -0
- package/dist/terminal/ghostty/renderer.d.ts +98 -0
- package/dist/terminal/ghostty/renderer.js +481 -0
- package/dist/terminal/ghostty/runtime.d.ts +126 -0
- package/dist/terminal/ghostty/runtime.js +346 -0
- package/dist/terminal/ghostty/spriteGlyphs.logic.d.ts +64 -0
- package/dist/terminal/ghostty/spriteGlyphs.logic.js +546 -0
- package/dist/terminal/ghostty/surface.d.ts +285 -0
- package/dist/terminal/ghostty/surface.js +1565 -0
- package/dist/terminal/ghostty/surface.logic.d.ts +181 -0
- package/dist/terminal/ghostty/surface.logic.js +392 -0
- package/dist/terminal/ghostty/vendor/LICENSE +21 -0
- package/dist/terminal/ghostty/vendor/ghostty-effects.wasm +0 -0
- package/dist/terminal/ghostty/vendor/ghostty-vt.wasm +0 -0
- package/dist/terminal/index.d.ts +12 -0
- package/dist/terminal/index.js +12 -0
- package/dist/terminal/terminal.css +169 -0
- package/dist/text/MarkedText.d.ts +14 -0
- package/dist/text/MarkedText.js +11 -0
- package/dist/text/highlightSegments.d.ts +13 -0
- package/dist/text/highlightSegments.js +29 -0
- package/dist/text/index.d.ts +3 -0
- package/dist/text/index.js +3 -0
- package/dist/text/text.css +11 -0
- package/dist/themes/attributes.d.ts +21 -0
- package/dist/themes/attributes.js +41 -0
- package/dist/themes/catalog.d.ts +125 -0
- package/dist/themes/catalog.js +940 -0
- package/dist/themes/color.d.ts +29 -0
- package/dist/themes/color.js +52 -0
- package/dist/themes/ids.d.ts +139 -0
- package/dist/themes/ids.js +59 -0
- package/dist/themes/index.d.ts +12 -0
- package/dist/themes/index.js +12 -0
- package/dist/themes/themes.generated.css +1830 -0
- package/dist/themes/tokens.d.ts +189 -0
- package/dist/themes/tokens.js +462 -0
- package/dist/tooltip/Tooltip.d.ts +21 -0
- package/dist/tooltip/Tooltip.js +105 -0
- package/dist/tooltip/Tooltip.logic.d.ts +49 -0
- package/dist/tooltip/Tooltip.logic.js +50 -0
- package/dist/tooltip/index.d.ts +3 -0
- package/dist/tooltip/index.js +3 -0
- package/dist/tooltip/tooltip.css +45 -0
- package/package.json +91 -4
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The pure parts of `DateTimePicker`: a date or time value read into its
|
|
3
|
+
* parts and written back, the days a month's grid shows from the week's
|
|
4
|
+
* first day, and a month's step.
|
|
5
|
+
*/
|
|
6
|
+
const pad = (value, width = 2) => String(Math.abs(value)).padStart(width, '0');
|
|
7
|
+
/** Today and now, in the computer's own time zone. */
|
|
8
|
+
export const nowParts = (now = new Date()) => ({
|
|
9
|
+
year: now.getFullYear(),
|
|
10
|
+
month: now.getMonth() + 1,
|
|
11
|
+
day: now.getDate(),
|
|
12
|
+
hour: now.getHours(),
|
|
13
|
+
minute: now.getMinutes(),
|
|
14
|
+
second: now.getSeconds(),
|
|
15
|
+
fraction: ''
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* A value's parts, or null when it is not a date or time the picker can
|
|
19
|
+
* show (a keyword such as `now`, the zero date `0000-00-00`, a time past a
|
|
20
|
+
* day), which the field keeps as typed. It reads `YYYY-MM-DD`, `HH:MM`,
|
|
21
|
+
* `HH:MM:SS` with up to six digits of a fraction, and a date and a time
|
|
22
|
+
* joined by `T` or a space.
|
|
23
|
+
*/
|
|
24
|
+
export function parsePicker(value) {
|
|
25
|
+
const match = /^(?:(\d{4})-(\d{2})-(\d{2}))?(?:[ T]?(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,6}))?)?)?$/u.exec(value.trim());
|
|
26
|
+
if (match === null || value.trim() === '')
|
|
27
|
+
return null;
|
|
28
|
+
const [, year, month, day, hour, minute, second, fraction] = match;
|
|
29
|
+
const parts = {
|
|
30
|
+
year: Number(year ?? 0),
|
|
31
|
+
month: Number(month ?? 1),
|
|
32
|
+
day: Number(day ?? 1),
|
|
33
|
+
hour: Number(hour ?? 0),
|
|
34
|
+
minute: Number(minute ?? 0),
|
|
35
|
+
second: Number(second ?? 0),
|
|
36
|
+
fraction: fraction ?? ''
|
|
37
|
+
};
|
|
38
|
+
if (year !== undefined && (parts.year === 0 || parts.month < 1 || parts.month > 12))
|
|
39
|
+
return null;
|
|
40
|
+
if (parts.day < 1 || parts.day > daysIn(parts.year, parts.month))
|
|
41
|
+
return null;
|
|
42
|
+
if (parts.hour > 23 || parts.minute > 59 || parts.second > 59)
|
|
43
|
+
return null;
|
|
44
|
+
return parts;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The parts written as `kind` keeps them: `YYYY-MM-DD`, `HH:MM:SS`, or both
|
|
48
|
+
* joined by `separator` (ISO 8601's `T` unless given; a space for a store
|
|
49
|
+
* that writes them so), the seconds followed by `fraction` digits of a
|
|
50
|
+
* second when `fraction` is above 0.
|
|
51
|
+
*/
|
|
52
|
+
export function formatPicker(kind, parts, fraction, separator = 'T') {
|
|
53
|
+
const date = `${pad(parts.year, 4)}-${pad(parts.month)}-${pad(parts.day)}`;
|
|
54
|
+
const digits = parts.fraction.padEnd(fraction, '0').slice(0, fraction);
|
|
55
|
+
const time = `${pad(parts.hour)}:${pad(parts.minute)}:${pad(parts.second)}${fraction > 0 ? `.${digits}` : ''}`;
|
|
56
|
+
return kind === 'date' ? date : kind === 'time' ? time : `${date}${separator}${time}`;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Midnight UTC on a day, `monthIndex` counting from 0 and overflowing as
|
|
60
|
+
* `Date.UTC` does. Unlike `Date.UTC`, it keeps years 0 to 99 as written
|
|
61
|
+
* rather than moving them to 1900 to 1999.
|
|
62
|
+
*/
|
|
63
|
+
export function utcDay(year, monthIndex, day) {
|
|
64
|
+
const date = new Date(0);
|
|
65
|
+
date.setUTCFullYear(year, monthIndex, day);
|
|
66
|
+
return date;
|
|
67
|
+
}
|
|
68
|
+
/** The days in a month, 1 to 12. */
|
|
69
|
+
export const daysIn = (year, month) => utcDay(year, month, 0).getUTCDate();
|
|
70
|
+
/**
|
|
71
|
+
* The days a month's grid shows, a week a row from `firstDay` (1 Monday to
|
|
72
|
+
* 7 Sunday): each date with whether it is in the month, the days of the
|
|
73
|
+
* weeks around it filling the first and last rows.
|
|
74
|
+
*/
|
|
75
|
+
export function monthGrid(year, month, firstDay) {
|
|
76
|
+
// getUTCDay counts Sunday as 0; `firstDay` counts it as 7.
|
|
77
|
+
const weekday = (utcDay(year, month - 1, 1).getUTCDay() + 6) % 7;
|
|
78
|
+
const lead = (weekday - (firstDay - 1) + 7) % 7;
|
|
79
|
+
const start = utcDay(year, month - 1, 1 - lead).getTime();
|
|
80
|
+
const count = Math.ceil((lead + daysIn(year, month)) / 7) * 7;
|
|
81
|
+
return Array.from({ length: count }, (_, index) => {
|
|
82
|
+
const date = new Date(start + index * 86_400_000);
|
|
83
|
+
return {
|
|
84
|
+
year: date.getUTCFullYear(),
|
|
85
|
+
month: date.getUTCMonth() + 1,
|
|
86
|
+
day: date.getUTCDate(),
|
|
87
|
+
inMonth: date.getUTCMonth() + 1 === month
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/** The month `by` months on, its day kept where the month has it. */
|
|
92
|
+
export function stepMonth(parts, by) {
|
|
93
|
+
const index = parts.year * 12 + (parts.month - 1) + by;
|
|
94
|
+
const year = Math.floor(index / 12);
|
|
95
|
+
const month = (index % 12) + 1;
|
|
96
|
+
return { ...parts, year, month, day: Math.min(parts.day, daysIn(year, month)) };
|
|
97
|
+
}
|
|
98
|
+
/** The weekday names from `firstDay` (1 Monday to 7 Sunday), short, in `locale`'s language. */
|
|
99
|
+
export function weekdayNames(firstDay, locale) {
|
|
100
|
+
const format = new Intl.DateTimeFormat(locale, { weekday: 'short', timeZone: 'UTC' });
|
|
101
|
+
// 2024-01-01 was a Monday.
|
|
102
|
+
return Array.from({ length: 7 }, (_, index) => format.format(new Date(Date.UTC(2024, 0, firstDay + index))));
|
|
103
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/* ---- Date and time picker (DateTimePicker) ----
|
|
2
|
+
|
|
3
|
+
A button beside its field, and the panel it opens under it. */
|
|
4
|
+
.date-picker {
|
|
5
|
+
position: relative;
|
|
6
|
+
display: inline-flex;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.date-picker-panel {
|
|
10
|
+
position: absolute;
|
|
11
|
+
top: calc(100% + 4px);
|
|
12
|
+
left: 0;
|
|
13
|
+
z-index: var(--z-panel);
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-direction: column;
|
|
16
|
+
gap: 8px;
|
|
17
|
+
width: max-content;
|
|
18
|
+
padding: 10px;
|
|
19
|
+
border: 1px solid var(--border);
|
|
20
|
+
border-radius: 6px;
|
|
21
|
+
background: var(--surface);
|
|
22
|
+
color: var(--text);
|
|
23
|
+
box-shadow: var(--shadow-menu);
|
|
24
|
+
font: 12px/1.4 var(--font-ui);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.date-picker-head {
|
|
28
|
+
display: flex;
|
|
29
|
+
align-items: center;
|
|
30
|
+
justify-content: space-between;
|
|
31
|
+
gap: 8px;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.date-picker-days {
|
|
35
|
+
display: flex;
|
|
36
|
+
flex-direction: column;
|
|
37
|
+
gap: 2px;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.date-picker-week {
|
|
41
|
+
display: grid;
|
|
42
|
+
grid-template-columns: repeat(7, 28px);
|
|
43
|
+
gap: 2px;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.date-picker-weekday {
|
|
47
|
+
color: var(--text-dim);
|
|
48
|
+
font-size: 11px;
|
|
49
|
+
text-align: center;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.date-picker-day {
|
|
53
|
+
height: 24px;
|
|
54
|
+
padding: 0;
|
|
55
|
+
border: none;
|
|
56
|
+
border-radius: 4px;
|
|
57
|
+
background: none;
|
|
58
|
+
color: inherit;
|
|
59
|
+
font: inherit;
|
|
60
|
+
font-variant-numeric: tabular-nums;
|
|
61
|
+
cursor: pointer;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.date-picker-day:hover:enabled {
|
|
65
|
+
background: var(--hover-wash);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.date-picker-day.outside {
|
|
69
|
+
color: var(--row-meta-text);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.date-picker-day.current {
|
|
73
|
+
background: var(--accent);
|
|
74
|
+
color: var(--on-accent);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.date-picker-time {
|
|
78
|
+
display: flex;
|
|
79
|
+
flex-wrap: wrap;
|
|
80
|
+
gap: 8px;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.date-picker-field {
|
|
84
|
+
display: flex;
|
|
85
|
+
flex-direction: column;
|
|
86
|
+
gap: 2px;
|
|
87
|
+
color: var(--text-dim);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* A time field: a well in the ground, ringed in the accent when focused. */
|
|
91
|
+
.date-picker-input {
|
|
92
|
+
width: 7ch;
|
|
93
|
+
height: 24px;
|
|
94
|
+
padding: 0 8px;
|
|
95
|
+
border: 1px solid var(--border-strong);
|
|
96
|
+
border-radius: 6px;
|
|
97
|
+
background: var(--ground);
|
|
98
|
+
color: var(--text);
|
|
99
|
+
font: inherit;
|
|
100
|
+
transition:
|
|
101
|
+
border-color 120ms,
|
|
102
|
+
box-shadow 120ms;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.date-picker-input:focus-visible {
|
|
106
|
+
outline: none;
|
|
107
|
+
border-color: var(--accent);
|
|
108
|
+
box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.date-picker-foot {
|
|
112
|
+
display: flex;
|
|
113
|
+
justify-content: space-between;
|
|
114
|
+
gap: 8px;
|
|
115
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `DateTimePicker`: the button beside a date or time field that opens a
|
|
3
|
+
* month grid and time fields; plus the pure rules that read, write, and lay
|
|
4
|
+
* out its values.
|
|
5
|
+
*/
|
|
6
|
+
export { DateTimePicker, type DateTimePickerProps } from './DateTimePicker.js';
|
|
7
|
+
export { daysIn, formatPicker, monthGrid, nowParts, parsePicker, stepMonth, weekdayNames, type PickerKind, type PickerParts } from './DateTimePicker.logic.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `DateTimePicker`: the button beside a date or time field that opens a
|
|
3
|
+
* month grid and time fields; plus the pure rules that read, write, and lay
|
|
4
|
+
* out its values.
|
|
5
|
+
*/
|
|
6
|
+
export { DateTimePicker } from './DateTimePicker.js';
|
|
7
|
+
export { daysIn, formatPicker, monthGrid, nowParts, parsePicker, stepMonth, weekdayNames } from './DateTimePicker.logic.js';
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { LucideIcon } from 'lucide-react';
|
|
2
|
+
import { type ReactElement, type ReactNode } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* A confirmation's tone: `danger` for a destructive action, `warning` for a
|
|
5
|
+
* question whose yes is the safe choice but still ends work, `primary` for
|
|
6
|
+
* a grant that changes nothing by itself.
|
|
7
|
+
*/
|
|
8
|
+
export type ConfirmTone = 'danger' | 'warning' | 'primary';
|
|
9
|
+
/** Copy and callbacks for {@link ConfirmDialog}. */
|
|
10
|
+
export interface ConfirmDialogProps {
|
|
11
|
+
/** What the action is, on the title strip. */
|
|
12
|
+
readonly title: string;
|
|
13
|
+
/** The consequence, as text or with a name set apart in bold (`<strong>`). */
|
|
14
|
+
readonly message: ReactNode;
|
|
15
|
+
/** The action's verb, the lit primary at the right edge. */
|
|
16
|
+
readonly confirmLabel: string;
|
|
17
|
+
/**
|
|
18
|
+
* The leave verb on Escape, named for what leaving keeps (Keep Editing);
|
|
19
|
+
* the `dialog.cancel` label unless given.
|
|
20
|
+
*/
|
|
21
|
+
readonly cancelLabel?: string;
|
|
22
|
+
/** The action's icon, the one its trigger or menu row wears (a trash can for Move to Trash). */
|
|
23
|
+
readonly icon: LucideIcon;
|
|
24
|
+
/**
|
|
25
|
+
* Where the action happens, on the title strip's right edge
|
|
26
|
+
* (`~/Downloads`, or a group's dot and name); none when nothing says it.
|
|
27
|
+
*/
|
|
28
|
+
readonly context?: ReactNode;
|
|
29
|
+
/**
|
|
30
|
+
* `danger` for destructive confirmations (the default): a red rule under
|
|
31
|
+
* the title and a red lit confirm. `warning` for a question whose yes is
|
|
32
|
+
* the safe choice but still ends work (cancelling a delete): an amber
|
|
33
|
+
* rule, with the confirm in the accent. `primary` for a grant that
|
|
34
|
+
* changes nothing by itself, which keeps the accent.
|
|
35
|
+
*/
|
|
36
|
+
readonly tone?: ConfirmTone;
|
|
37
|
+
/** Every path the action touches, listed in full so the user confirms exactly those. */
|
|
38
|
+
readonly paths?: readonly string[];
|
|
39
|
+
/**
|
|
40
|
+
* A choice the confirmation carries, drawn under the message (keep an
|
|
41
|
+
* item's data or move it to the Trash). The caller holds its state and
|
|
42
|
+
* reads it in `onConfirm`; the confirm verb stays the same whatever is
|
|
43
|
+
* chosen.
|
|
44
|
+
*/
|
|
45
|
+
readonly children?: ReactNode;
|
|
46
|
+
/** Extra class on the dialog box, for a body that needs its own width or layout. */
|
|
47
|
+
readonly className?: string;
|
|
48
|
+
/**
|
|
49
|
+
* True for a delete that cannot be undone (a volume with no Trash, a
|
|
50
|
+
* server, a database): the confirm verb stays at the right edge, lit, but
|
|
51
|
+
* moves off Return onto ⌥⌘⌫, Finder's Delete Immediately chord, and
|
|
52
|
+
* Return does nothing, so a Return pressed out of habit after ⌘⌫ never
|
|
53
|
+
* deletes anything for good.
|
|
54
|
+
*/
|
|
55
|
+
readonly forGood?: boolean;
|
|
56
|
+
/** The confirm verb, on Return (or ⌥⌘⌫ with `forGood`) and its slot. */
|
|
57
|
+
readonly onConfirm: () => void;
|
|
58
|
+
/** Escape, the leave slot, and a press outside. */
|
|
59
|
+
readonly onCancel: () => void;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The one confirmation surface, for destructive, privileged, and
|
|
63
|
+
* side-effect-bearing actions: title, consequence, optional path list, an
|
|
64
|
+
* optional choice the caller draws, then the legend's esc Cancel (or the
|
|
65
|
+
* leave verb named) and the named action at the right edge, on Return, or
|
|
66
|
+
* on ⌥⌘⌫ with Return running nothing for a delete that cannot be undone
|
|
67
|
+
* (`forGood`). The message describes the dialog (`aria-describedby`), so a
|
|
68
|
+
* screen reader reads the consequence, and any name it holds, with the
|
|
69
|
+
* title. It carries its own type, margins, and box sizing, so it renders
|
|
70
|
+
* the same portalled to the body as inside any page. Styled by the
|
|
71
|
+
* `.confirm-dialog` rules in `@bigpixelrocket/uiok/styles.css`; reads the `dialog` labels.
|
|
72
|
+
*/
|
|
73
|
+
export declare function ConfirmDialog({ title, message, confirmLabel, cancelLabel, icon, context, tone, paths, children, className, forGood, onConfirm, onCancel }: ConfirmDialogProps): ReactElement;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from 'react';
|
|
3
|
+
import { useLabels } from '../labels/UiokProvider.js';
|
|
4
|
+
import { ModalDialog } from './ModalDialog.js';
|
|
5
|
+
/** Finder's Delete Immediately chord, which confirms a delete that cannot be undone. */
|
|
6
|
+
const DELETE_IMMEDIATELY = { key: 'Backspace', meta: true, alt: true };
|
|
7
|
+
/**
|
|
8
|
+
* The one confirmation surface, for destructive, privileged, and
|
|
9
|
+
* side-effect-bearing actions: title, consequence, optional path list, an
|
|
10
|
+
* optional choice the caller draws, then the legend's esc Cancel (or the
|
|
11
|
+
* leave verb named) and the named action at the right edge, on Return, or
|
|
12
|
+
* on ⌥⌘⌫ with Return running nothing for a delete that cannot be undone
|
|
13
|
+
* (`forGood`). The message describes the dialog (`aria-describedby`), so a
|
|
14
|
+
* screen reader reads the consequence, and any name it holds, with the
|
|
15
|
+
* title. It carries its own type, margins, and box sizing, so it renders
|
|
16
|
+
* the same portalled to the body as inside any page. Styled by the
|
|
17
|
+
* `.confirm-dialog` rules in `@bigpixelrocket/uiok/styles.css`; reads the `dialog` labels.
|
|
18
|
+
*/
|
|
19
|
+
export function ConfirmDialog({ title, message, confirmLabel, cancelLabel, icon, context, tone = 'danger', paths = [], children, className, forGood = false, onConfirm, onCancel }) {
|
|
20
|
+
const labels = useLabels().dialog;
|
|
21
|
+
const labelId = useId();
|
|
22
|
+
const messageId = useId();
|
|
23
|
+
const legend = {
|
|
24
|
+
leave: { label: cancelLabel ?? labels.cancel },
|
|
25
|
+
primary: forGood
|
|
26
|
+
? { label: confirmLabel, chord: DELETE_IMMEDIATELY, onRun: onConfirm }
|
|
27
|
+
: { label: confirmLabel, onRun: onConfirm }
|
|
28
|
+
};
|
|
29
|
+
return (_jsxs(ModalDialog, { className: className ? `confirm-dialog ${className}` : 'confirm-dialog', describedBy: messageId, icon: icon, labelId: labelId, legend: legend, onCancel: onCancel, title: title, titleAside: context, tone: tone === 'primary' ? 'accent' : tone, children: [_jsx("p", { className: "dialog-message", id: messageId, children: message }), paths.length > 0 && (_jsx("ul", { "aria-label": labels.affectedItems(paths.length), className: "dialog-paths", tabIndex: 0, children: paths.map((path) => (_jsx("li", { children: path }, path))) })), children] }));
|
|
30
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import type { DialogLegendModel } from './DialogLegend.logic.js';
|
|
3
|
+
/** Props for {@link DialogLegend}. */
|
|
4
|
+
export interface DialogLegendProps {
|
|
5
|
+
/** The slots to draw. */
|
|
6
|
+
readonly legend: DialogLegendModel;
|
|
7
|
+
/** Runs the leave verb: the dialog's cancel, which Escape runs too. */
|
|
8
|
+
readonly onLeave: () => void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A dialog's footer drawn as a key legend: the leave verb on Escape and any
|
|
12
|
+
* secondary verbs line up from the left edge, the primary stands alone at
|
|
13
|
+
* the right edge with its cap lit (in the danger colour inside a
|
|
14
|
+
* destructive dialog), Return's unless it names its own chord. The slots
|
|
15
|
+
* are the keys' pointer targets; the keys themselves are bound by whatever
|
|
16
|
+
* holds the legend: `ModalDialog`, which renders it as its last child, or a
|
|
17
|
+
* surface without a dialog frame (a palette), which binds them itself with
|
|
18
|
+
* `legendKeyAction`. Styled by the `.dialog-legend` rules in
|
|
19
|
+
* `@bigpixelrocket/uiok/styles.css`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function DialogLegend({ legend, onLeave }: DialogLegendProps): ReactElement;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { KeyChord } from '../keychord/KeyChord.js';
|
|
3
|
+
const ESCAPE = { key: 'Escape' };
|
|
4
|
+
const RETURN = { key: 'Enter' };
|
|
5
|
+
/**
|
|
6
|
+
* One slot: the key cap, then the verb. A real button named by its verb
|
|
7
|
+
* alone (the cap is hidden from assistive technology), outside the Tab
|
|
8
|
+
* order and never taking focus from a press, because its key is the
|
|
9
|
+
* keyboard's way to it.
|
|
10
|
+
*/
|
|
11
|
+
function LegendSlot({ chord, verb, primary = false, onRun }) {
|
|
12
|
+
return (_jsxs("button", { className: primary ? 'legend-slot legend-primary' : 'legend-slot', disabled: verb.disabled, onClick: onRun, onMouseDown: (event) => event.preventDefault(), tabIndex: -1, type: "button", children: [_jsx("span", { "aria-hidden": true, className: "legend-slot-key", children: _jsx(KeyChord, { chord: chord }) }), verb.label] }));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A dialog's footer drawn as a key legend: the leave verb on Escape and any
|
|
16
|
+
* secondary verbs line up from the left edge, the primary stands alone at
|
|
17
|
+
* the right edge with its cap lit (in the danger colour inside a
|
|
18
|
+
* destructive dialog), Return's unless it names its own chord. The slots
|
|
19
|
+
* are the keys' pointer targets; the keys themselves are bound by whatever
|
|
20
|
+
* holds the legend: `ModalDialog`, which renders it as its last child, or a
|
|
21
|
+
* surface without a dialog frame (a palette), which binds them itself with
|
|
22
|
+
* `legendKeyAction`. Styled by the `.dialog-legend` rules in
|
|
23
|
+
* `@bigpixelrocket/uiok/styles.css`.
|
|
24
|
+
*/
|
|
25
|
+
export function DialogLegend({ legend, onLeave }) {
|
|
26
|
+
const { leave, secondary = [], primary } = legend;
|
|
27
|
+
return (_jsxs("div", { className: "dialog-legend", children: [leave && _jsx(LegendSlot, { chord: ESCAPE, onRun: onLeave, verb: leave }), secondary.map((slot) => (_jsx(LegendSlot, { chord: slot.chord, onRun: slot.onRun, verb: slot }, slot.label))), primary && (_jsx(LegendSlot, { chord: primary.chord ?? RETURN, onRun: primary.onRun, primary: true, verb: primary }))] }));
|
|
28
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The keys of a dialog's key legend footer (`DialogLegend`): which slot a
|
|
3
|
+
* keystroke runs. The rules are in `docs/components/dialog.md`, The legend.
|
|
4
|
+
*/
|
|
5
|
+
import type { Chord } from '../keyboard/Keyboard.logic.js';
|
|
6
|
+
import type { DialogLabels } from '../labels/dialog.js';
|
|
7
|
+
/** A verb the legend shows: its label, and whether it can run now. */
|
|
8
|
+
export interface DialogLegendVerb {
|
|
9
|
+
/** The verb as the slot prints it, and the slot's accessible name. */
|
|
10
|
+
readonly label: string;
|
|
11
|
+
/** True while the verb cannot run; its slot stays drawn, dimmed, and its key runs nothing. */
|
|
12
|
+
readonly disabled?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Escape's verb on a surface with a filter field (a palette, a menu): Clear
|
|
16
|
+
* while a filter is typed, since Escape empties it first and the next press
|
|
17
|
+
* leaves, and Cancel otherwise. Inside React, pass `useLabels().dialog`.
|
|
18
|
+
*/
|
|
19
|
+
export declare const filterLeaveLabel: (query: string, labels: Pick<DialogLabels, "cancel" | "clear">) => string;
|
|
20
|
+
/** A secondary verb besides the leave verb: its own chord and what it runs. */
|
|
21
|
+
export interface LegendSecondary extends DialogLegendVerb {
|
|
22
|
+
/**
|
|
23
|
+
* A chord with a modifier (`⌘[`); a named key Option leaves alone
|
|
24
|
+
* (`⌥⏎`), since Option composes letters on macOS and an Option letter
|
|
25
|
+
* never reports its letter; or a bare key (Space), which a control in the
|
|
26
|
+
* body keeps while it has the focus. Never plain Return, which the
|
|
27
|
+
* primary holds, and never Escape under any modifier: Escape is the
|
|
28
|
+
* leave verb's alone and is never drawn as a chord.
|
|
29
|
+
*/
|
|
30
|
+
readonly chord: Chord;
|
|
31
|
+
/** What the slot and its chord run. */
|
|
32
|
+
readonly onRun: () => void;
|
|
33
|
+
}
|
|
34
|
+
/** The forward verb at the right edge, on Return unless it names another chord. */
|
|
35
|
+
export interface LegendPrimary extends DialogLegendVerb {
|
|
36
|
+
/** What the slot and its key run. */
|
|
37
|
+
readonly onRun: () => void;
|
|
38
|
+
/**
|
|
39
|
+
* The primary's key when it is not Return: a delete for good stands on
|
|
40
|
+
* ⌥⌘⌫, Finder's Delete Immediately chord, and Return then runs nothing,
|
|
41
|
+
* so a Return pressed out of habit never deletes anything for good.
|
|
42
|
+
*/
|
|
43
|
+
readonly chord?: Chord;
|
|
44
|
+
/**
|
|
45
|
+
* Return stays with a focused body control that answers it itself (a
|
|
46
|
+
* text field, a pop-up menu, a button) and runs the primary only from
|
|
47
|
+
* elsewhere: a settings sheet's Done, where every control applies at once
|
|
48
|
+
* and a field adds the name it holds on Return.
|
|
49
|
+
*/
|
|
50
|
+
readonly yieldsReturn?: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A dialog's footer: how to leave, the secondary verbs, and the one primary,
|
|
54
|
+
* four slots at most. The leave verb comes first, at the left edge, on
|
|
55
|
+
* Escape, named for what Escape does there: Cancel by default, or a
|
|
56
|
+
* situational label (Clear, Keep Editing), never Close. Up to two secondary
|
|
57
|
+
* verbs follow in order of use, and the primary, the forward verb, stands
|
|
58
|
+
* alone at the right edge. A dialog with more verbs moves its choice into
|
|
59
|
+
* the body.
|
|
60
|
+
*/
|
|
61
|
+
export interface DialogLegendModel {
|
|
62
|
+
/**
|
|
63
|
+
* Escape's verb. The slot runs the dialog's own cancel, the same as
|
|
64
|
+
* Escape, so the slot and the key never do different things; disabled
|
|
65
|
+
* while Escape does nothing yet. Left out when the primary already does
|
|
66
|
+
* all Escape would (an outcome's OK, a sheet's Done): Escape and Return
|
|
67
|
+
* never share a slot, and Escape still runs the dialog's cancel, unshown.
|
|
68
|
+
*/
|
|
69
|
+
readonly leave?: DialogLegendVerb;
|
|
70
|
+
/** In order of use, after the leave verb. */
|
|
71
|
+
readonly secondary?: readonly [] | readonly [LegendSecondary] | readonly [LegendSecondary, LegendSecondary];
|
|
72
|
+
/** The forward verb at the right edge, lit. */
|
|
73
|
+
readonly primary?: LegendPrimary;
|
|
74
|
+
}
|
|
75
|
+
/** The part of a keydown the legend reads; keeps the rules testable. */
|
|
76
|
+
export interface LegendKeyStroke {
|
|
77
|
+
/** `KeyboardEvent.key`. */
|
|
78
|
+
readonly key: string;
|
|
79
|
+
/** Option (Alt) is held. */
|
|
80
|
+
readonly altKey: boolean;
|
|
81
|
+
/** Control is held. */
|
|
82
|
+
readonly ctrlKey: boolean;
|
|
83
|
+
/** Command (Meta) is held. */
|
|
84
|
+
readonly metaKey: boolean;
|
|
85
|
+
/** Shift is held. */
|
|
86
|
+
readonly shiftKey: boolean;
|
|
87
|
+
/** A held key's auto-repeat. */
|
|
88
|
+
readonly repeat: boolean;
|
|
89
|
+
/** An input method is composing; its keys are the composition's. */
|
|
90
|
+
readonly composing: boolean;
|
|
91
|
+
/** A control in the body has already kept the key (a field's open list of values). */
|
|
92
|
+
readonly handled: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* The key comes from a control in the body (a field, a button, a
|
|
95
|
+
* checkbox, a scrolling list) rather than from the dialog itself, so a
|
|
96
|
+
* bare key is that control's to answer.
|
|
97
|
+
*/
|
|
98
|
+
readonly fromControl: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* The key comes from a body control that answers Return itself (a text
|
|
101
|
+
* field, a pop-up menu, a button), which keeps it from a primary that
|
|
102
|
+
* yields Return.
|
|
103
|
+
*/
|
|
104
|
+
readonly fromReturnControl: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* The key comes from a text field holding text, which deletes with
|
|
107
|
+
* Backspace and forward Delete under any modifier (⌘⌫ to the line's
|
|
108
|
+
* start, ⌥⌫ a word), so a slot on one of them leaves the key to the
|
|
109
|
+
* field. An empty field has nothing to delete, and the slot runs.
|
|
110
|
+
*/
|
|
111
|
+
readonly fromFilledField: boolean;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* What a keystroke does in the legend: run a slot, or keep the key from
|
|
115
|
+
* the focused control while running nothing (Return on a disabled primary,
|
|
116
|
+
* or a held Return repeating), or nothing at all (`null`), which leaves the
|
|
117
|
+
* key to the focused control.
|
|
118
|
+
*/
|
|
119
|
+
export type LegendKeyAction = {
|
|
120
|
+
readonly kind: 'run';
|
|
121
|
+
readonly run: () => void;
|
|
122
|
+
} | {
|
|
123
|
+
readonly kind: 'keep';
|
|
124
|
+
} | null;
|
|
125
|
+
/**
|
|
126
|
+
* The slot a keystroke runs. A secondary chord runs its slot, except a bare
|
|
127
|
+
* one (Space) while a body control has the focus, or a deletion chord (⌘⌫)
|
|
128
|
+
* while a text field holding text has it, which keeps the key. The primary
|
|
129
|
+
* runs on its own chord (⌥⌘⌫ for a delete for good) under the same rule,
|
|
130
|
+
* or else on plain Return from anywhere in the dialog, a focused field or
|
|
131
|
+
* body button included, so it never clicks the focused control instead,
|
|
132
|
+
* unless it yields Return to a focused field, pop-up menu, or button.
|
|
133
|
+
* Return runs nothing while the primary is disabled or the key repeats, so a
|
|
134
|
+
* Return held from the step before cannot commit the next one, and no slot
|
|
135
|
+
* runs on a repeat. Escape is the dialog frame's own key and is not read
|
|
136
|
+
* here.
|
|
137
|
+
*/
|
|
138
|
+
export declare function legendKeyAction(legend: DialogLegendModel, stroke: LegendKeyStroke): LegendKeyAction;
|
|
139
|
+
/**
|
|
140
|
+
* What a legend draws, as a string: each slot's label, chord, and whether it
|
|
141
|
+
* can run, so two models that draw the same footer compare equal whatever
|
|
142
|
+
* functions they run. A holder that rebuilds its model on every render
|
|
143
|
+
* passes a new one on only when this changes.
|
|
144
|
+
*/
|
|
145
|
+
export declare function legendSignature(legend: DialogLegendModel): string;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The keys of a dialog's key legend footer (`DialogLegend`): which slot a
|
|
3
|
+
* keystroke runs. The rules are in `docs/components/dialog.md`, The legend.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Escape's verb on a surface with a filter field (a palette, a menu): Clear
|
|
7
|
+
* while a filter is typed, since Escape empties it first and the next press
|
|
8
|
+
* leaves, and Cancel otherwise. Inside React, pass `useLabels().dialog`.
|
|
9
|
+
*/
|
|
10
|
+
export const filterLeaveLabel = (query, labels) => (query === '' ? labels.cancel : labels.clear);
|
|
11
|
+
/** Whether a keystroke is exactly this chord: every modifier as declared, and the key. */
|
|
12
|
+
const matchesChord = (chord, stroke) => stroke.ctrlKey === (chord.ctrl ?? false) &&
|
|
13
|
+
stroke.metaKey === (chord.meta ?? false) &&
|
|
14
|
+
stroke.altKey === (chord.alt ?? false) &&
|
|
15
|
+
stroke.shiftKey === (chord.shift ?? false) &&
|
|
16
|
+
stroke.key.toLowerCase() === chord.key.toLowerCase();
|
|
17
|
+
const PLAIN_RETURN = { key: 'Enter' };
|
|
18
|
+
/** A chord with no modifier but Shift: a key a focused control types or presses. */
|
|
19
|
+
const isBare = (chord) => !(chord.meta ?? false) && !(chord.ctrl ?? false) && !(chord.alt ?? false);
|
|
20
|
+
/** A chord on a key a text field deletes with, whatever its modifiers. */
|
|
21
|
+
const isDeletion = (chord) => chord.key === 'Backspace' || chord.key === 'Delete';
|
|
22
|
+
/** Whether the focused control keeps a secondary slot's key from the legend. */
|
|
23
|
+
const controlKeeps = (chord, stroke) => (stroke.fromControl && isBare(chord)) || (stroke.fromFilledField && isDeletion(chord));
|
|
24
|
+
/**
|
|
25
|
+
* The slot a keystroke runs. A secondary chord runs its slot, except a bare
|
|
26
|
+
* one (Space) while a body control has the focus, or a deletion chord (⌘⌫)
|
|
27
|
+
* while a text field holding text has it, which keeps the key. The primary
|
|
28
|
+
* runs on its own chord (⌥⌘⌫ for a delete for good) under the same rule,
|
|
29
|
+
* or else on plain Return from anywhere in the dialog, a focused field or
|
|
30
|
+
* body button included, so it never clicks the focused control instead,
|
|
31
|
+
* unless it yields Return to a focused field, pop-up menu, or button.
|
|
32
|
+
* Return runs nothing while the primary is disabled or the key repeats, so a
|
|
33
|
+
* Return held from the step before cannot commit the next one, and no slot
|
|
34
|
+
* runs on a repeat. Escape is the dialog frame's own key and is not read
|
|
35
|
+
* here.
|
|
36
|
+
*/
|
|
37
|
+
export function legendKeyAction(legend, stroke) {
|
|
38
|
+
if (stroke.composing || stroke.handled) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const runs = (chord) => matchesChord(chord, stroke) && !controlKeeps(chord, stroke);
|
|
42
|
+
const { primary, secondary = [] } = legend;
|
|
43
|
+
const primaryRuns = primary !== undefined &&
|
|
44
|
+
(primary.chord === undefined
|
|
45
|
+
? matchesChord(PLAIN_RETURN, stroke) &&
|
|
46
|
+
!(primary.yieldsReturn === true && stroke.fromReturnControl)
|
|
47
|
+
: runs(primary.chord));
|
|
48
|
+
const slot = secondary.find((candidate) => runs(candidate.chord)) ?? (primaryRuns ? primary : undefined);
|
|
49
|
+
if (slot === undefined) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
return slot.disabled || stroke.repeat ? { kind: 'keep' } : { kind: 'run', run: slot.onRun };
|
|
53
|
+
}
|
|
54
|
+
/** A chord as a fixed string for comparison, never for display. */
|
|
55
|
+
const chordText = (chord) => `${chord.ctrl ? '⌃' : ''}${chord.alt ? '⌥' : ''}${chord.shift ? '⇧' : ''}${chord.meta ? '⌘' : ''}${chord.key}`;
|
|
56
|
+
/**
|
|
57
|
+
* What a legend draws, as a string: each slot's label, chord, and whether it
|
|
58
|
+
* can run, so two models that draw the same footer compare equal whatever
|
|
59
|
+
* functions they run. A holder that rebuilds its model on every render
|
|
60
|
+
* passes a new one on only when this changes.
|
|
61
|
+
*/
|
|
62
|
+
export function legendSignature(legend) {
|
|
63
|
+
const verb = (slot) => slot === undefined ? null : [slot.label, slot.disabled === true];
|
|
64
|
+
return JSON.stringify([
|
|
65
|
+
verb(legend.leave),
|
|
66
|
+
(legend.secondary ?? []).map((slot) => [...(verb(slot) ?? []), chordText(slot.chord)]),
|
|
67
|
+
legend.primary === undefined
|
|
68
|
+
? null
|
|
69
|
+
: [...(verb(legend.primary) ?? []), chordText(legend.primary.chord ?? PLAIN_RETURN)]
|
|
70
|
+
]);
|
|
71
|
+
}
|