@bigpixelrocket/uiok 0.3.0 → 0.5.0
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 +50 -1
- package/dist/button/TextLink.d.ts +19 -3
- package/dist/button/TextLink.js +4 -3
- package/dist/dialog/ConfirmDialog.d.ts +7 -1
- package/dist/dialog/ConfirmDialog.js +2 -2
- package/dist/dialog/ModalDialog.js +8 -2
- package/dist/dialog/ProgressDialog.d.ts +7 -1
- package/dist/dialog/ProgressDialog.js +2 -2
- package/dist/dialog/TypedNameDialog.d.ts +8 -0
- package/dist/field/Check.d.ts +9 -2
- package/dist/field/Check.js +5 -4
- package/dist/field/Controls.d.ts +198 -0
- package/dist/field/Controls.js +94 -0
- package/dist/field/FieldLayout.d.ts +126 -0
- package/dist/field/FieldLayout.js +89 -0
- package/dist/field/index.d.ts +9 -6
- package/dist/field/index.js +9 -6
- package/dist/frame/Dock.js +1 -1
- package/dist/frame/SidebarResizer.js +1 -1
- package/dist/frame/Tree.d.ts +17 -4
- package/dist/frame/Tree.js +34 -9
- package/dist/frame/WindowFrame.js +2 -1
- package/dist/frame/frame.css +26 -4
- package/dist/icon/ProductMark.d.ts +57 -0
- package/dist/icon/ProductMark.js +26 -0
- package/dist/icon/icon.css +53 -0
- package/dist/icon/index.d.ts +3 -1
- package/dist/icon/index.js +3 -1
- package/dist/labels/UiokLabels.d.ts +3 -0
- package/dist/labels/UiokLabels.js +3 -1
- package/dist/labels/index.d.ts +1 -0
- package/dist/labels/index.js +1 -0
- package/dist/labels/settings.d.ts +6 -0
- package/dist/labels/settings.js +1 -0
- package/dist/labels/viewer.d.ts +193 -0
- package/dist/labels/viewer.js +124 -0
- package/dist/listing/Listing.d.ts +60 -4
- package/dist/listing/Listing.js +39 -10
- package/dist/listing/ListingScope.d.ts +7 -0
- package/dist/listing/ListingScope.js +8 -0
- package/dist/listing/PaneMessage.d.ts +28 -0
- package/dist/listing/PaneMessage.js +12 -0
- package/dist/listing/Timeline.d.ts +51 -0
- package/dist/listing/Timeline.js +28 -0
- package/dist/listing/index.d.ts +7 -3
- package/dist/listing/index.js +6 -2
- package/dist/listing/listing.css +185 -22
- package/dist/log/Ansi.logic.d.ts +27 -0
- package/dist/log/Ansi.logic.js +203 -0
- package/dist/log/LogWell.d.ts +11 -2
- package/dist/log/LogWell.js +15 -3
- package/dist/log/index.d.ts +1 -0
- package/dist/log/index.js +1 -0
- package/dist/log/log.css +80 -0
- package/dist/menu/Menu.d.ts +89 -0
- package/dist/menu/Menu.js +143 -0
- package/dist/menu/Menu.logic.d.ts +56 -0
- package/dist/menu/Menu.logic.js +64 -0
- package/dist/menu/index.d.ts +5 -1
- package/dist/menu/index.js +5 -1
- package/dist/menu/menu.css +51 -0
- package/dist/palette/Palette.d.ts +3 -2
- package/dist/palette/Palette.js +8 -4
- package/dist/palette/PaletteRows.d.ts +129 -0
- package/dist/palette/PaletteRows.js +74 -0
- package/dist/palette/index.d.ts +5 -2
- package/dist/palette/index.js +5 -2
- package/dist/pane/PaneFrame.d.ts +22 -1
- package/dist/pane/PaneFrame.js +42 -5
- package/dist/pane/index.d.ts +1 -1
- package/dist/shell/SettingsDialog.d.ts +20 -2
- package/dist/shell/SettingsDialog.js +13 -3
- package/dist/shell/index.d.ts +1 -1
- package/dist/styles.css +4 -0
- package/dist/surface/Card.d.ts +18 -0
- package/dist/surface/Card.js +10 -0
- package/dist/surface/FactTable.d.ts +44 -0
- package/dist/surface/FactTable.js +33 -0
- package/dist/surface/Notice.d.ts +45 -0
- package/dist/surface/Notice.js +27 -0
- package/dist/surface/index.d.ts +7 -3
- package/dist/surface/index.js +7 -3
- package/dist/surface/surface.css +64 -0
- package/dist/tabs/PageTabs.d.ts +6 -0
- package/dist/tabs/PageTabs.js +1 -1
- package/dist/tabs/tabs.css +14 -0
- package/dist/terminal/TerminalBox.d.ts +30 -0
- package/dist/terminal/TerminalBox.js +17 -0
- package/dist/terminal/index.d.ts +3 -1
- package/dist/terminal/index.js +3 -1
- package/dist/terminal/terminal.css +29 -0
- package/dist/themes/themes.generated.css +21 -0
- package/dist/themes/tokens.d.ts +1 -0
- package/dist/themes/tokens.js +16 -1
- package/dist/viewer/AudioView.d.ts +13 -0
- package/dist/viewer/AudioView.js +25 -0
- package/dist/viewer/HexJump.logic.d.ts +16 -0
- package/dist/viewer/HexJump.logic.js +27 -0
- package/dist/viewer/HexRows.logic.d.ts +55 -0
- package/dist/viewer/HexRows.logic.js +84 -0
- package/dist/viewer/HexSelection.logic.d.ts +57 -0
- package/dist/viewer/HexSelection.logic.js +68 -0
- package/dist/viewer/HexView.d.ts +10 -0
- package/dist/viewer/HexView.js +291 -0
- package/dist/viewer/HexViewport.logic.d.ts +61 -0
- package/dist/viewer/HexViewport.logic.js +79 -0
- package/dist/viewer/ImageView.d.ts +19 -0
- package/dist/viewer/ImageView.js +230 -0
- package/dist/viewer/ImageZoom.logic.d.ts +65 -0
- package/dist/viewer/ImageZoom.logic.js +119 -0
- package/dist/viewer/LatestRead.logic.d.ts +27 -0
- package/dist/viewer/LatestRead.logic.js +55 -0
- package/dist/viewer/MediaControls.d.ts +25 -0
- package/dist/viewer/MediaControls.js +183 -0
- package/dist/viewer/MediaPlayer.logic.d.ts +53 -0
- package/dist/viewer/MediaPlayer.logic.js +68 -0
- package/dist/viewer/PdfView.d.ts +23 -0
- package/dist/viewer/PdfView.js +25 -0
- package/dist/viewer/QuietFocus.d.ts +19 -0
- package/dist/viewer/QuietFocus.js +27 -0
- package/dist/viewer/ScaledScroll.logic.d.ts +30 -0
- package/dist/viewer/ScaledScroll.logic.js +28 -0
- package/dist/viewer/ScaledScrollbar.d.ts +19 -0
- package/dist/viewer/ScaledScrollbar.js +71 -0
- package/dist/viewer/SyntaxHighlighter.d.ts +29 -0
- package/dist/viewer/SyntaxHighlighter.js +144 -0
- package/dist/viewer/SyntaxLanguage.logic.d.ts +110 -0
- package/dist/viewer/SyntaxLanguage.logic.js +283 -0
- package/dist/viewer/SyntaxService.d.ts +75 -0
- package/dist/viewer/SyntaxService.js +49 -0
- package/dist/viewer/SyntaxSession.logic.d.ts +78 -0
- package/dist/viewer/SyntaxSession.logic.js +221 -0
- package/dist/viewer/SyntaxWorker.d.ts +6 -0
- package/dist/viewer/SyntaxWorker.js +8 -0
- package/dist/viewer/TextEncoding.logic.d.ts +35 -0
- package/dist/viewer/TextEncoding.logic.js +58 -0
- package/dist/viewer/TextRows.logic.d.ts +86 -0
- package/dist/viewer/TextRows.logic.js +241 -0
- package/dist/viewer/TextSelection.logic.d.ts +97 -0
- package/dist/viewer/TextSelection.logic.js +139 -0
- package/dist/viewer/TextView.d.ts +13 -0
- package/dist/viewer/TextView.js +448 -0
- package/dist/viewer/TextViewport.logic.d.ts +70 -0
- package/dist/viewer/TextViewport.logic.js +116 -0
- package/dist/viewer/VideoView.d.ts +18 -0
- package/dist/viewer/VideoView.js +53 -0
- package/dist/viewer/ViewerClipboard.d.ts +30 -0
- package/dist/viewer/ViewerClipboard.js +70 -0
- package/dist/viewer/ViewerFrame.logic.d.ts +61 -0
- package/dist/viewer/ViewerFrame.logic.js +130 -0
- package/dist/viewer/ViewerKeys.d.ts +16 -0
- package/dist/viewer/ViewerKeys.js +14 -0
- package/dist/viewer/ViewerScope.d.ts +12 -0
- package/dist/viewer/ViewerScope.js +22 -0
- package/dist/viewer/ViewerViews.d.ts +28 -0
- package/dist/viewer/ViewerViews.js +22 -0
- package/dist/viewer/ViewerWindow.d.ts +53 -0
- package/dist/viewer/ViewerWindow.js +219 -0
- package/dist/viewer/index.d.ts +12 -0
- package/dist/viewer/index.js +12 -0
- package/dist/viewer/types.d.ts +151 -0
- package/dist/viewer/types.js +26 -0
- package/dist/viewer/useElementHeight.d.ts +6 -0
- package/dist/viewer/useElementHeight.js +22 -0
- package/dist/viewer/useElementSize.d.ts +7 -0
- package/dist/viewer/useElementSize.js +24 -0
- package/dist/viewer/useEscapeToClear.d.ts +8 -0
- package/dist/viewer/useEscapeToClear.js +26 -0
- package/dist/viewer/useHexDocument.d.ts +41 -0
- package/dist/viewer/useHexDocument.js +144 -0
- package/dist/viewer/useMediaElement.d.ts +10 -0
- package/dist/viewer/useMediaElement.js +24 -0
- package/dist/viewer/useSyntaxHighlight.d.ts +24 -0
- package/dist/viewer/useSyntaxHighlight.js +133 -0
- package/dist/viewer/useTextDocument.d.ts +66 -0
- package/dist/viewer/useTextDocument.js +245 -0
- package/dist/viewer/viewer.css +645 -0
- package/package.json +7 -1
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/** The eight ANSI colours by name, in SGR order (30–37, 40–47; 90–97 and 100–107 are the same names). */
|
|
2
|
+
export const ANSI_COLOURS = [
|
|
3
|
+
'black',
|
|
4
|
+
'red',
|
|
5
|
+
'green',
|
|
6
|
+
'yellow',
|
|
7
|
+
'blue',
|
|
8
|
+
'magenta',
|
|
9
|
+
'cyan',
|
|
10
|
+
'white'
|
|
11
|
+
];
|
|
12
|
+
const ESC = 0x1b;
|
|
13
|
+
const BEL = 0x07;
|
|
14
|
+
/** The 8-bit string terminator (ST), the one-byte form of `ESC \`. */
|
|
15
|
+
const ST = 0x9c;
|
|
16
|
+
/** The 8-bit CSI, the one-byte form of `ESC [`. */
|
|
17
|
+
const CSI = 0x9b;
|
|
18
|
+
/** The 8-bit control-string introducers: DCS, SOS, OSC, PM, APC (`ESC P`, `X`, `]`, `^`, `_`). */
|
|
19
|
+
const STRING_INTRODUCERS = new Set([0x90, 0x98, 0x9d, 0x9e, 0x9f]);
|
|
20
|
+
/** Where a sequence or a control may start: `ESC`, or any 8-bit control (C1). */
|
|
21
|
+
// The escape and the 8-bit controls are what the pattern exists to find.
|
|
22
|
+
// eslint-disable-next-line no-control-regex
|
|
23
|
+
const CONTROL = /[\u001b\u0080-\u009f]/g;
|
|
24
|
+
/** Whether `code` lies in the inclusive byte range `low`–`high`. */
|
|
25
|
+
function within(code, low, high) {
|
|
26
|
+
return code >= low && code <= high;
|
|
27
|
+
}
|
|
28
|
+
/** Index of the first byte at or after `from` that is not in `low`–`high`. */
|
|
29
|
+
function skipRange(text, from, low, high) {
|
|
30
|
+
let at = from;
|
|
31
|
+
while (at < text.length && within(text.charCodeAt(at), low, high))
|
|
32
|
+
at += 1;
|
|
33
|
+
return at;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The end of a control string (OSC, DCS, SOS, PM, APC) whose payload starts
|
|
37
|
+
* at `from`: past its BEL or ST (`ESC \` or the 8-bit ST), at an escape
|
|
38
|
+
* that starts the next sequence, or at the end of the text when it never
|
|
39
|
+
* ends. Any other byte, an 8-bit control included, is payload (SOS may
|
|
40
|
+
* carry anything but SOS and ST), so none of it shows.
|
|
41
|
+
*/
|
|
42
|
+
function controlStringEnd(text, from) {
|
|
43
|
+
for (let at = from; at < text.length; at += 1) {
|
|
44
|
+
const code = text.charCodeAt(at);
|
|
45
|
+
if (code === BEL || code === ST)
|
|
46
|
+
return at + 1;
|
|
47
|
+
if (code === ESC)
|
|
48
|
+
return text.charCodeAt(at + 1) === 0x5c ? at + 2 : at;
|
|
49
|
+
}
|
|
50
|
+
return text.length;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Reads the sequence starting at the `ESC` or 8-bit control at `start`,
|
|
54
|
+
* after ECMA-48: a CSI (`ESC [` or its 8-bit form, parameter bytes `0`–`?`,
|
|
55
|
+
* intermediate bytes space–`/`, a final byte `@`–`~`); an OSC (`ESC ]`) or
|
|
56
|
+
* DCS, SOS, PM, or APC (`ESC P`, `X`, `^`, `_`), or their 8-bit forms, a
|
|
57
|
+
* string to BEL or ST; any other escape (intermediates then one final
|
|
58
|
+
* byte); or a lone 8-bit control, dropped alone. A sequence cut off by the end of the text runs to
|
|
59
|
+
* the end; one broken by a control byte ends before it, so the `ESC` never
|
|
60
|
+
* shows. Only a CSI ending in `m`, with no intermediate and no private
|
|
61
|
+
* marker (`<`, `=`, `>`, `?`), is an SGR.
|
|
62
|
+
*/
|
|
63
|
+
function readEscape(text, start) {
|
|
64
|
+
const lead = text.charCodeAt(start);
|
|
65
|
+
// The 8-bit forms: a CSI, a control string, or a lone control.
|
|
66
|
+
if (lead === CSI)
|
|
67
|
+
return readCsi(text, start + 1);
|
|
68
|
+
if (STRING_INTRODUCERS.has(lead))
|
|
69
|
+
return { end: controlStringEnd(text, start + 1) };
|
|
70
|
+
if (lead !== ESC)
|
|
71
|
+
return { end: start + 1 };
|
|
72
|
+
const kind = text.charCodeAt(start + 1);
|
|
73
|
+
if (kind === 0x5b)
|
|
74
|
+
return readCsi(text, start + 2);
|
|
75
|
+
if (kind === 0x5d || kind === 0x50 || kind === 0x58 || kind === 0x5e || kind === 0x5f) {
|
|
76
|
+
return { end: controlStringEnd(text, start + 2) };
|
|
77
|
+
}
|
|
78
|
+
const intermediatesEnd = skipRange(text, start + 1, 0x20, 0x2f);
|
|
79
|
+
if (intermediatesEnd >= text.length)
|
|
80
|
+
return { end: text.length };
|
|
81
|
+
return within(text.charCodeAt(intermediatesEnd), 0x30, 0x7e)
|
|
82
|
+
? { end: intermediatesEnd + 1 }
|
|
83
|
+
: { end: intermediatesEnd };
|
|
84
|
+
}
|
|
85
|
+
/** Reads a CSI whose parameters start at `from` (after `ESC [` or the 8-bit CSI). */
|
|
86
|
+
function readCsi(text, from) {
|
|
87
|
+
const parametersEnd = skipRange(text, from, 0x30, 0x3f);
|
|
88
|
+
const intermediatesEnd = skipRange(text, parametersEnd, 0x20, 0x2f);
|
|
89
|
+
if (intermediatesEnd >= text.length)
|
|
90
|
+
return { end: text.length };
|
|
91
|
+
const final = text.charCodeAt(intermediatesEnd);
|
|
92
|
+
if (!within(final, 0x40, 0x7e))
|
|
93
|
+
return { end: intermediatesEnd };
|
|
94
|
+
const parameters = text.slice(from, parametersEnd);
|
|
95
|
+
const sgr = final === 0x6d && intermediatesEnd === parametersEnd && !/[<=>?]/.test(parameters)
|
|
96
|
+
? parameters
|
|
97
|
+
: undefined;
|
|
98
|
+
return sgr === undefined ? { end: intermediatesEnd + 1 } : { end: intermediatesEnd + 1, sgr };
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Applies one SGR's parameters to `style`. Parameters split on `;`; a
|
|
102
|
+
* group joined by `:` is one parameter with subparameters (`4:3` is a
|
|
103
|
+
* curly underline, `4:0` underline off, `38:2::r:g:b` a colour). Extended colours (38, 48, and
|
|
104
|
+
* the underline colour 58) name no ANSI colour, so each is skipped whole,
|
|
105
|
+
* in either form; any other colon group but underline's is ignored.
|
|
106
|
+
*/
|
|
107
|
+
function applySgr(style, parameters) {
|
|
108
|
+
const groups = parameters.split(';');
|
|
109
|
+
let next = { ...style };
|
|
110
|
+
for (let index = 0; index < groups.length; index += 1) {
|
|
111
|
+
const group = groups[index] ?? '';
|
|
112
|
+
if (group.includes(':')) {
|
|
113
|
+
const [main, kind] = group.split(':', 2).map((part) => Number(part || 0));
|
|
114
|
+
if (main === 4 && kind === 0)
|
|
115
|
+
next.underline = false;
|
|
116
|
+
else if (main === 4 && kind !== undefined && kind >= 1 && kind <= 5)
|
|
117
|
+
next.underline = true;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const code = Number(group || 0);
|
|
121
|
+
if (code === 38 || code === 48 || code === 58) {
|
|
122
|
+
// 38;5;n or 38;2;r;g;b: the colour is the theme's to choose, so it is skipped whole.
|
|
123
|
+
// The mode is a number, so `02` is `2`.
|
|
124
|
+
const mode = Number(groups[index + 1] ?? '');
|
|
125
|
+
index += mode === 5 ? 2 : mode === 2 ? 4 : 1;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (code === 0)
|
|
129
|
+
next = {};
|
|
130
|
+
else if (code === 1)
|
|
131
|
+
next.bold = true;
|
|
132
|
+
else if (code === 2)
|
|
133
|
+
next.dim = true;
|
|
134
|
+
else if (code === 3)
|
|
135
|
+
next.italic = true;
|
|
136
|
+
else if (code === 4)
|
|
137
|
+
next.underline = true;
|
|
138
|
+
else if (code === 7)
|
|
139
|
+
next.inverse = true;
|
|
140
|
+
else if (code === 22)
|
|
141
|
+
next = { ...next, bold: false, dim: false };
|
|
142
|
+
else if (code === 23)
|
|
143
|
+
next.italic = false;
|
|
144
|
+
else if (code === 24)
|
|
145
|
+
next.underline = false;
|
|
146
|
+
else if (code === 27)
|
|
147
|
+
next.inverse = false;
|
|
148
|
+
else if (code === 39)
|
|
149
|
+
delete next.fg;
|
|
150
|
+
else if (code === 49)
|
|
151
|
+
delete next.bg;
|
|
152
|
+
else if ((code >= 30 && code <= 37) || (code >= 90 && code <= 97)) {
|
|
153
|
+
next.fg = ANSI_COLOURS[code % 10];
|
|
154
|
+
}
|
|
155
|
+
else if ((code >= 40 && code <= 47) || (code >= 100 && code <= 107)) {
|
|
156
|
+
next.bg = ANSI_COLOURS[code % 10];
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return next;
|
|
160
|
+
}
|
|
161
|
+
/** A segment of `text` in `style`, with inverse turned into a filled run and unset flags left out. */
|
|
162
|
+
function segment(text, style) {
|
|
163
|
+
const fg = style.inverse ? style.bg : style.fg;
|
|
164
|
+
const bg = style.inverse ? (style.fg ?? 'white') : style.bg;
|
|
165
|
+
return {
|
|
166
|
+
text,
|
|
167
|
+
...(fg === undefined ? {} : { fg }),
|
|
168
|
+
...(bg === undefined ? {} : { bg }),
|
|
169
|
+
...(style.bold === true ? { bold: true } : {}),
|
|
170
|
+
...(style.dim === true ? { dim: true } : {}),
|
|
171
|
+
...(style.italic === true ? { italic: true } : {}),
|
|
172
|
+
...(style.underline === true ? { underline: true } : {})
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* A log line's text as runs of one style each, read from its SGR escape
|
|
177
|
+
* sequences: the eight colours and their bright forms (as the same name),
|
|
178
|
+
* backgrounds, bold, dim, italic, underline, and inverse, each reset as
|
|
179
|
+
* SGR resets it, in the 7-bit form (`ESC [`) or the 8-bit one. Extended
|
|
180
|
+
* colours (256 and true colour) are skipped, and every other escape
|
|
181
|
+
* sequence, control string, 8-bit control, and cut-off escape is dropped, so the runs hold printable text alone. A line with no escape is
|
|
182
|
+
* one plain run. Linear in the text's length, and pure: the text is never
|
|
183
|
+
* read as markup.
|
|
184
|
+
*/
|
|
185
|
+
export function ansiSegments(text) {
|
|
186
|
+
const segments = [];
|
|
187
|
+
let style = {};
|
|
188
|
+
let at = 0;
|
|
189
|
+
while (at < text.length) {
|
|
190
|
+
CONTROL.lastIndex = at;
|
|
191
|
+
const escape = CONTROL.exec(text)?.index ?? -1;
|
|
192
|
+
const textEnd = escape === -1 ? text.length : escape;
|
|
193
|
+
if (textEnd > at)
|
|
194
|
+
segments.push(segment(text.slice(at, textEnd), style));
|
|
195
|
+
if (escape === -1)
|
|
196
|
+
break;
|
|
197
|
+
const read = readEscape(text, escape);
|
|
198
|
+
if (read.sgr !== undefined)
|
|
199
|
+
style = applySgr(style, read.sgr);
|
|
200
|
+
at = read.end;
|
|
201
|
+
}
|
|
202
|
+
return segments;
|
|
203
|
+
}
|
package/dist/log/LogWell.d.ts
CHANGED
|
@@ -21,6 +21,13 @@ export interface LogWellProps {
|
|
|
21
21
|
readonly follow?: boolean;
|
|
22
22
|
/** The words shown while the log has no line. */
|
|
23
23
|
readonly empty?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Reads the SGR escape sequences in each line whose text is a string
|
|
26
|
+
* (`ansiSegments`): its colours, backgrounds, bold, dim, italic, and
|
|
27
|
+
* underline, drawn in the theme's text tones; every other escape
|
|
28
|
+
* sequence is dropped. Off, a string is drawn as written.
|
|
29
|
+
*/
|
|
30
|
+
readonly ansi?: boolean;
|
|
24
31
|
}
|
|
25
32
|
/**
|
|
26
33
|
* A log in a well: each line in the code face, its source first in a
|
|
@@ -29,6 +36,8 @@ export interface LogWellProps {
|
|
|
29
36
|
* host marks takes its tone. The words can be selected and copied. With
|
|
30
37
|
* `follow`, a new line scrolls into view while the reader is at the foot.
|
|
31
38
|
* It is a `log` region, so a screen reader hears new lines without being
|
|
32
|
-
* moved; it takes the focus so the keys scroll it.
|
|
39
|
+
* moved; it takes the focus so the keys scroll it. With `ansi`, a line's
|
|
40
|
+
* SGR colours and weights are drawn in the theme's text tones, its other
|
|
41
|
+
* escape sequences dropped.
|
|
33
42
|
*/
|
|
34
|
-
export declare function LogWell({ lines, label, sources, follow, empty }: LogWellProps): ReactElement;
|
|
43
|
+
export declare function LogWell({ lines, label, sources, follow, empty, ansi }: LogWellProps): ReactElement;
|
package/dist/log/LogWell.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useLayoutEffect, useRef } from 'react';
|
|
3
|
+
import { ansiSegments } from './Ansi.logic.js';
|
|
3
4
|
import { logSourceColour, logSourceIndexes, logSourceWidth } from './LogWell.logic.js';
|
|
5
|
+
/** A line's text as styled runs, each colour painted by log.css from its data attributes. */
|
|
6
|
+
function AnsiText({ text }) {
|
|
7
|
+
return ansiSegments(text).map((run, index) => run.fg === undefined &&
|
|
8
|
+
run.bg === undefined &&
|
|
9
|
+
run.bold === undefined &&
|
|
10
|
+
run.dim === undefined &&
|
|
11
|
+
run.italic === undefined &&
|
|
12
|
+
run.underline === undefined ? (run.text) : (_jsx("span", { className: "log-ansi", "data-bg": run.bg, "data-bold": run.bold || undefined, "data-dim": run.dim || undefined, "data-fg": run.fg, "data-italic": run.italic || undefined, "data-underline": run.underline || undefined, children: run.text }, index)));
|
|
13
|
+
}
|
|
4
14
|
/** How near the foot, in pixels, still counts as reading the newest line. */
|
|
5
15
|
const FOOT_SLACK = 8;
|
|
6
16
|
/**
|
|
@@ -10,9 +20,11 @@ const FOOT_SLACK = 8;
|
|
|
10
20
|
* host marks takes its tone. The words can be selected and copied. With
|
|
11
21
|
* `follow`, a new line scrolls into view while the reader is at the foot.
|
|
12
22
|
* It is a `log` region, so a screen reader hears new lines without being
|
|
13
|
-
* moved; it takes the focus so the keys scroll it.
|
|
23
|
+
* moved; it takes the focus so the keys scroll it. With `ansi`, a line's
|
|
24
|
+
* SGR colours and weights are drawn in the theme's text tones, its other
|
|
25
|
+
* escape sequences dropped.
|
|
14
26
|
*/
|
|
15
|
-
export function LogWell({ lines, label, sources = [], follow = true, empty }) {
|
|
27
|
+
export function LogWell({ lines, label, sources = [], follow = true, empty, ansi = false }) {
|
|
16
28
|
const well = useRef(null);
|
|
17
29
|
const atFoot = useRef(true);
|
|
18
30
|
const names = lines.map((line) => line.source);
|
|
@@ -34,6 +46,6 @@ export function LogWell({ lines, label, sources = [], follow = true, empty }) {
|
|
|
34
46
|
const index = source === null ? undefined : indexes.get(source);
|
|
35
47
|
return (_jsxs("div", { className: "log-line", "data-tone": line.tone, children: [width > 0 ? (_jsx("span", { className: "log-source", style: index === undefined
|
|
36
48
|
? undefined
|
|
37
|
-
: { '--log-source': logSourceColour(index) }, children: source })) : null, width > 0 ? (_jsx("span", { "aria-hidden": true, className: "log-bar", children: "|" })) : null, _jsx("span", { className: "log-text", children: line.text })] }, line.key));
|
|
49
|
+
: { '--log-source': logSourceColour(index) }, children: source })) : null, width > 0 ? (_jsx("span", { "aria-hidden": true, className: "log-bar", children: "|" })) : null, _jsx("span", { className: "log-text", children: ansi && typeof line.text === 'string' ? _jsx(AnsiText, { text: line.text }) : line.text })] }, line.key));
|
|
38
50
|
})] }));
|
|
39
51
|
}
|
package/dist/log/index.d.ts
CHANGED
|
@@ -4,5 +4,6 @@
|
|
|
4
4
|
* (`logSourceIndexes`, `logSourceColour`, `logSourceWidth`). Its look is
|
|
5
5
|
* `log.css` in `@bigpixelrocket/uiok/styles.css`.
|
|
6
6
|
*/
|
|
7
|
+
export { ANSI_COLOURS, ansiSegments, type AnsiColour, type AnsiSegment } from './Ansi.logic.js';
|
|
7
8
|
export { LogWell, type LogLine, type LogWellProps } from './LogWell.js';
|
|
8
9
|
export { LOG_SOURCE_COLOURS, logSourceColour, logSourceIndexes, logSourceWidth } from './LogWell.logic.js';
|
package/dist/log/index.js
CHANGED
|
@@ -4,5 +4,6 @@
|
|
|
4
4
|
* (`logSourceIndexes`, `logSourceColour`, `logSourceWidth`). Its look is
|
|
5
5
|
* `log.css` in `@bigpixelrocket/uiok/styles.css`.
|
|
6
6
|
*/
|
|
7
|
+
export { ANSI_COLOURS, ansiSegments } from './Ansi.logic.js';
|
|
7
8
|
export { LogWell } from './LogWell.js';
|
|
8
9
|
export { LOG_SOURCE_COLOURS, logSourceColour, logSourceIndexes, logSourceWidth } from './LogWell.logic.js';
|
package/dist/log/log.css
CHANGED
|
@@ -55,3 +55,83 @@
|
|
|
55
55
|
color: var(--text-dim);
|
|
56
56
|
font-family: var(--font-ui);
|
|
57
57
|
}
|
|
58
|
+
|
|
59
|
+
/* A line's SGR styling (LogWell's `ansi`): each ANSI colour drawn in the
|
|
60
|
+
theme's text tone nearest its meaning, each legible on the well, never
|
|
61
|
+
the terminal's own palette, which is tuned for the terminal's ground. A
|
|
62
|
+
background is a filled run in the tone's solid fill and its on-colour,
|
|
63
|
+
as a badge is. Black and white take the text's own two tones. */
|
|
64
|
+
.log-ansi[data-fg='black'] {
|
|
65
|
+
color: var(--text-dim);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.log-ansi[data-fg='red'] {
|
|
69
|
+
color: var(--danger-text);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.log-ansi[data-fg='green'] {
|
|
73
|
+
color: var(--success-text);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.log-ansi[data-fg='yellow'] {
|
|
77
|
+
color: var(--warning-text);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.log-ansi[data-fg='blue'] {
|
|
81
|
+
color: var(--accent-text);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.log-ansi[data-fg='magenta'] {
|
|
85
|
+
color: var(--log-source-2);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.log-ansi[data-fg='cyan'] {
|
|
89
|
+
color: var(--log-source-5);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.log-ansi[data-fg='white'] {
|
|
93
|
+
color: var(--text);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.log-ansi[data-bg] {
|
|
97
|
+
padding-inline: var(--space-1);
|
|
98
|
+
border-radius: var(--radius-xs);
|
|
99
|
+
background: var(--fill);
|
|
100
|
+
color: var(--text);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.log-ansi[data-bg='red'] {
|
|
104
|
+
background: var(--danger);
|
|
105
|
+
color: var(--on-danger);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.log-ansi[data-bg='green'] {
|
|
109
|
+
background: var(--success);
|
|
110
|
+
color: var(--on-success);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.log-ansi[data-bg='yellow'] {
|
|
114
|
+
background: var(--warning);
|
|
115
|
+
color: var(--on-warning);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.log-ansi:is([data-bg='blue'], [data-bg='magenta'], [data-bg='cyan']) {
|
|
119
|
+
background: var(--accent);
|
|
120
|
+
color: var(--on-accent);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.log-ansi[data-bold] {
|
|
124
|
+
font-weight: var(--font-weight-strong);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.log-ansi[data-dim]:not([data-bg]) {
|
|
128
|
+
color: var(--text-dim);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.log-ansi[data-italic] {
|
|
132
|
+
font-style: italic;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.log-ansi[data-underline] {
|
|
136
|
+
text-decoration: underline;
|
|
137
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { LucideIcon } from 'lucide-react';
|
|
2
|
+
import { type ReactElement, type ReactNode } from 'react';
|
|
3
|
+
import type { Chord } from '../keyboard/Keyboard.logic.js';
|
|
4
|
+
import { type MenuPoint } from './Menu.logic.js';
|
|
5
|
+
/** An item of a menu: a verb that runs, or a place to go. */
|
|
6
|
+
export interface MenuItemEntry {
|
|
7
|
+
readonly kind?: 'item';
|
|
8
|
+
/** Names the item to `onPick`; unique in the menu. */
|
|
9
|
+
readonly id: string;
|
|
10
|
+
/** The verb or the place, in words: "Open in Terminal", "17 · 17.7". */
|
|
11
|
+
readonly label: string;
|
|
12
|
+
/** A lucide glyph in the icon column. */
|
|
13
|
+
readonly icon?: LucideIcon;
|
|
14
|
+
/** Anything else in the icon column (a `ProductMark`, a state dot), when `icon` is absent. */
|
|
15
|
+
readonly mark?: ReactNode;
|
|
16
|
+
/** The chord that runs the same verb, drawn as key caps at the row's end. */
|
|
17
|
+
readonly chord?: Chord;
|
|
18
|
+
/** A destructive verb (Delete, Remove): the danger tone, its glyph with it. */
|
|
19
|
+
readonly danger?: boolean;
|
|
20
|
+
/** Listed but not runnable now: dimmed and passed over by the keys. Say why in `tip`. */
|
|
21
|
+
readonly disabled?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* A setting the item turns on and off: true draws the check mark in the
|
|
24
|
+
* icon column (`menuitemcheckbox`); absent, it is a plain item.
|
|
25
|
+
*/
|
|
26
|
+
readonly checked?: boolean;
|
|
27
|
+
/** Marks the current one (the place shown), with what current means as the dot's name: "Shown". */
|
|
28
|
+
readonly current?: string | null;
|
|
29
|
+
/** More about the item, or why it is disabled: its tooltip and description. */
|
|
30
|
+
readonly tip?: string;
|
|
31
|
+
}
|
|
32
|
+
/** A hairline between groups of items that need no name. */
|
|
33
|
+
export interface MenuSeparatorEntry {
|
|
34
|
+
readonly kind: 'separator';
|
|
35
|
+
}
|
|
36
|
+
/** A group's name over its items. */
|
|
37
|
+
export interface MenuHeadingEntry {
|
|
38
|
+
readonly kind: 'heading';
|
|
39
|
+
readonly label: string;
|
|
40
|
+
}
|
|
41
|
+
/** One entry of a menu, in order. */
|
|
42
|
+
export type MenuEntry = MenuItemEntry | MenuSeparatorEntry | MenuHeadingEntry;
|
|
43
|
+
/** Props for {@link Menu}. */
|
|
44
|
+
export interface MenuProps {
|
|
45
|
+
/** The menu's accessible name: "Actions", "Other versions". */
|
|
46
|
+
readonly label: string;
|
|
47
|
+
/** Its entries, in order. */
|
|
48
|
+
readonly entries: readonly MenuEntry[];
|
|
49
|
+
/** Opens it at a point in window coordinates (a secondary click). */
|
|
50
|
+
readonly at?: MenuPoint;
|
|
51
|
+
/**
|
|
52
|
+
* Drops it from an element (a crumb, a button), under its leading edge.
|
|
53
|
+
* Presses on the element do not close the menu, so the element can
|
|
54
|
+
* toggle it. Used when `at` is absent.
|
|
55
|
+
*/
|
|
56
|
+
readonly anchor?: HTMLElement | null;
|
|
57
|
+
/** The item the cursor starts on (the current one); the first that can run when absent. */
|
|
58
|
+
readonly initial?: string | null;
|
|
59
|
+
/** The small size, for a menu of short commands (`.folder-menu-compact`). */
|
|
60
|
+
readonly compact?: boolean;
|
|
61
|
+
/** Runs an item that can run, by its id; the caller closes the menu. */
|
|
62
|
+
readonly onPick: (id: string) => void;
|
|
63
|
+
/**
|
|
64
|
+
* Closes the menu, saying how it was dismissed: by a key in it (Escape,
|
|
65
|
+
* Tab), after which the caller puts the focus back where it was, or by a
|
|
66
|
+
* press or a focus elsewhere, which has its own destination.
|
|
67
|
+
*/
|
|
68
|
+
readonly onClose: (by: 'keyboard' | 'pointer') => void;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A menu of verbs or places, opened at a point (a secondary click's) or
|
|
72
|
+
* dropped from an element (a crumb's ⌄, an Actions button): each item its
|
|
73
|
+
* glyph, its words, and its chord as key caps; a destructive one in the
|
|
74
|
+
* danger tone; a setting with its check; the current place with its dot;
|
|
75
|
+
* separators and group headings between them. It is the menu look
|
|
76
|
+
* (`.folder-menu`) drawn through a portal on the document's body (or the
|
|
77
|
+
* element shown full screen), so no pane or dialog clips it, placed inside
|
|
78
|
+
* the window (`placeMenu`); React still carries its events to its owner.
|
|
79
|
+
*
|
|
80
|
+
* It takes the focus and holds the keys while open (`menuKeyAction`: ↑ ↓,
|
|
81
|
+
* Home, End, Return and Space, Escape and Tab), which travel no further, so
|
|
82
|
+
* neither a dialog nor the page hears them; `data-native-keyboard` keeps
|
|
83
|
+
* the browser-key guard and a page's own key handlers out
|
|
84
|
+
* (`isNativeKeyboardTarget`), and `data-overlay` marks it an open overlay
|
|
85
|
+
* while it shows. A press on it never takes the focus from it; a press or
|
|
86
|
+
* a focus anywhere else closes it. A menu taller than the window less its
|
|
87
|
+
* margins scrolls, and the keys keep the cursor's item in view.
|
|
88
|
+
*/
|
|
89
|
+
export declare function Menu({ label, entries, at, anchor, initial, compact, onPick, onClose }: MenuProps): ReactElement;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useId, useLayoutEffect, useRef, useState } from 'react';
|
|
3
|
+
import { createPortal } from 'react-dom';
|
|
4
|
+
import { ICON_MD } from '../icon/sizes.js';
|
|
5
|
+
import { KeyChord } from '../keychord/KeyChord.js';
|
|
6
|
+
import { CurrentDot } from '../listing/CurrentDot.js';
|
|
7
|
+
import { describedTooltip } from '../tooltip/Tooltip.logic.js';
|
|
8
|
+
import { menuKeyAction, placeMenu } from './Menu.logic.js';
|
|
9
|
+
import { movedPickableCursor, pickableCursor } from './MenuQuery.logic.js';
|
|
10
|
+
/** Scrolls a menu's item at `position` into the menu's view, the least it takes; jsdom has no scrollIntoView. */
|
|
11
|
+
const revealItem = (itemId, position) => {
|
|
12
|
+
if (position === null)
|
|
13
|
+
return;
|
|
14
|
+
document.getElementById(`${itemId}-${position}`)?.scrollIntoView?.({ block: 'nearest' });
|
|
15
|
+
};
|
|
16
|
+
const isItem = (entry) => entry.kind === undefined || entry.kind === 'item';
|
|
17
|
+
/**
|
|
18
|
+
* A menu of verbs or places, opened at a point (a secondary click's) or
|
|
19
|
+
* dropped from an element (a crumb's ⌄, an Actions button): each item its
|
|
20
|
+
* glyph, its words, and its chord as key caps; a destructive one in the
|
|
21
|
+
* danger tone; a setting with its check; the current place with its dot;
|
|
22
|
+
* separators and group headings between them. It is the menu look
|
|
23
|
+
* (`.folder-menu`) drawn through a portal on the document's body (or the
|
|
24
|
+
* element shown full screen), so no pane or dialog clips it, placed inside
|
|
25
|
+
* the window (`placeMenu`); React still carries its events to its owner.
|
|
26
|
+
*
|
|
27
|
+
* It takes the focus and holds the keys while open (`menuKeyAction`: ↑ ↓,
|
|
28
|
+
* Home, End, Return and Space, Escape and Tab), which travel no further, so
|
|
29
|
+
* neither a dialog nor the page hears them; `data-native-keyboard` keeps
|
|
30
|
+
* the browser-key guard and a page's own key handlers out
|
|
31
|
+
* (`isNativeKeyboardTarget`), and `data-overlay` marks it an open overlay
|
|
32
|
+
* while it shows. A press on it never takes the focus from it; a press or
|
|
33
|
+
* a focus anywhere else closes it. A menu taller than the window less its
|
|
34
|
+
* margins scrolls, and the keys keep the cursor's item in view.
|
|
35
|
+
*/
|
|
36
|
+
export function Menu({ label, entries, at, anchor = null, initial = null, compact = false, onPick, onClose }) {
|
|
37
|
+
const rootRef = useRef(null);
|
|
38
|
+
const itemId = useId();
|
|
39
|
+
const [pointed, setPointed] = useState(initial);
|
|
40
|
+
const items = entries.filter(isItem);
|
|
41
|
+
const rows = items.map((item) => ({ key: item.id, taken: item.disabled === true }));
|
|
42
|
+
const cursor = pickableCursor(rows, pointed);
|
|
43
|
+
const cursorItem = cursor === null ? null : (items[cursor] ?? null);
|
|
44
|
+
const onCloseRef = useRef(onClose);
|
|
45
|
+
const cursorRef = useRef(cursor);
|
|
46
|
+
useLayoutEffect(() => {
|
|
47
|
+
onCloseRef.current = onClose;
|
|
48
|
+
cursorRef.current = cursor;
|
|
49
|
+
});
|
|
50
|
+
// Placed after layout, when its own size is known, and given the keys;
|
|
51
|
+
// placed again when the window resizes, so it never stands outside it,
|
|
52
|
+
// with the cursor's item kept in view and the focus left where it is.
|
|
53
|
+
useLayoutEffect(() => {
|
|
54
|
+
const menu = rootRef.current;
|
|
55
|
+
if (menu === null)
|
|
56
|
+
return;
|
|
57
|
+
const place = () => {
|
|
58
|
+
const size = { width: menu.offsetWidth, height: menu.offsetHeight };
|
|
59
|
+
const viewport = { width: window.innerWidth, height: window.innerHeight };
|
|
60
|
+
const spot = placeMenu(at !== undefined
|
|
61
|
+
? { point: at }
|
|
62
|
+
: { box: anchor?.getBoundingClientRect() ?? { left: 0, top: 0, right: 0, bottom: 0 } }, size, viewport);
|
|
63
|
+
menu.style.left = `${spot.left}px`;
|
|
64
|
+
menu.style.top = `${spot.top}px`;
|
|
65
|
+
};
|
|
66
|
+
// A window that shrinks under a tall menu can hide the cursor's item.
|
|
67
|
+
const replace = () => {
|
|
68
|
+
place();
|
|
69
|
+
revealItem(itemId, cursorRef.current);
|
|
70
|
+
};
|
|
71
|
+
place();
|
|
72
|
+
menu.focus({ preventScroll: true });
|
|
73
|
+
// A menu taller than the window scrolls; it opens with its cursor in view.
|
|
74
|
+
revealItem(itemId, cursorRef.current);
|
|
75
|
+
window.addEventListener('resize', replace);
|
|
76
|
+
return () => window.removeEventListener('resize', replace);
|
|
77
|
+
}, [at, anchor, itemId]);
|
|
78
|
+
// A press outside closes it, but one on its anchor, which toggles it.
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
const listener = (event) => {
|
|
81
|
+
const target = event.target;
|
|
82
|
+
if (!(target instanceof Node))
|
|
83
|
+
return;
|
|
84
|
+
if (rootRef.current?.contains(target) || anchor?.contains(target))
|
|
85
|
+
return;
|
|
86
|
+
onCloseRef.current('pointer');
|
|
87
|
+
};
|
|
88
|
+
document.addEventListener('mousedown', listener, true);
|
|
89
|
+
return () => document.removeEventListener('mousedown', listener, true);
|
|
90
|
+
}, [anchor]);
|
|
91
|
+
const run = (item) => {
|
|
92
|
+
if (item !== null && item.disabled !== true)
|
|
93
|
+
onPick(item.id);
|
|
94
|
+
};
|
|
95
|
+
let index = -1;
|
|
96
|
+
return createPortal(_jsx("div", { "aria-activedescendant": cursor === null ? undefined : `${itemId}-${cursor}`, "aria-label": label, className: compact ? 'folder-menu folder-menu-compact menu-popup' : 'folder-menu menu-popup', "data-native-keyboard": true, "data-overlay": true, onBlur: (event) => {
|
|
97
|
+
const to = event.relatedTarget;
|
|
98
|
+
if (to instanceof Node && (event.currentTarget.contains(to) || anchor?.contains(to)))
|
|
99
|
+
return;
|
|
100
|
+
onClose('pointer');
|
|
101
|
+
}, onContextMenu: (event) => event.preventDefault(), onKeyDown: (event) => {
|
|
102
|
+
const action = menuKeyAction(event);
|
|
103
|
+
if (action === null)
|
|
104
|
+
return;
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
event.stopPropagation();
|
|
107
|
+
if (action.kind === 'close')
|
|
108
|
+
onClose('keyboard');
|
|
109
|
+
else if (action.kind === 'run')
|
|
110
|
+
run(cursorItem);
|
|
111
|
+
else {
|
|
112
|
+
const next = action.kind === 'move'
|
|
113
|
+
? movedPickableCursor(rows, cursor, action.delta)
|
|
114
|
+
: movedPickableCursor(rows, null, action.to === 'first' ? 1 : -1);
|
|
115
|
+
setPointed(next === null ? null : (items[next]?.id ?? null));
|
|
116
|
+
// Only the keys scroll: an item under the pointer is already in view.
|
|
117
|
+
revealItem(itemId, next);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
// A press on an item must not take the focus from the menu, which holds the keys.
|
|
121
|
+
onMouseDown: (event) => event.preventDefault(), ref: rootRef, role: "menu", tabIndex: -1, children: entries.map((entry, entryIndex) => {
|
|
122
|
+
if (entry.kind === 'separator') {
|
|
123
|
+
return (_jsx("div", { className: "folder-menu-separator", role: "separator" }, `separator-${entryIndex}`));
|
|
124
|
+
}
|
|
125
|
+
if (entry.kind === 'heading') {
|
|
126
|
+
return (_jsx("div", { className: "entry-menu-heading", role: "presentation", children: entry.label }, `heading-${entryIndex}`));
|
|
127
|
+
}
|
|
128
|
+
index += 1;
|
|
129
|
+
const position = index;
|
|
130
|
+
const Icon = entry.icon;
|
|
131
|
+
const classes = [
|
|
132
|
+
'folder-menu-option',
|
|
133
|
+
position === cursor ? 'cursor' : '',
|
|
134
|
+
entry.danger === true ? 'danger' : ''
|
|
135
|
+
]
|
|
136
|
+
.filter(Boolean)
|
|
137
|
+
.join(' ');
|
|
138
|
+
return (_jsxs("div", { "aria-checked": entry.checked, "aria-disabled": entry.disabled === true || undefined, className: classes, id: `${itemId}-${position}`, onClick: () => run(entry), onMouseMove: () => {
|
|
139
|
+
if (entry.disabled !== true)
|
|
140
|
+
setPointed(entry.id);
|
|
141
|
+
}, role: entry.checked === undefined ? 'menuitem' : 'menuitemcheckbox', ...describedTooltip(entry.tip), children: [_jsx("span", { "aria-hidden": true, className: "row-icon", children: Icon === undefined ? entry.mark : _jsx(Icon, { size: ICON_MD }) }), _jsxs("span", { className: "menu-label", children: [_jsx("span", { className: "menu-label-text", children: entry.label }), entry.current === undefined || entry.current === null ? null : (_jsx(CurrentDot, { label: entry.current }))] }), entry.chord === undefined ? null : _jsx(KeyChord, { chord: entry.chord })] }, entry.id));
|
|
142
|
+
}) }), document.fullscreenElement ?? document.body);
|
|
143
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** A point in window coordinates: where a secondary click landed. */
|
|
2
|
+
export interface MenuPoint {
|
|
3
|
+
readonly x: number;
|
|
4
|
+
readonly y: number;
|
|
5
|
+
}
|
|
6
|
+
/** A box in window coordinates: what a menu drops from (a crumb, a button). */
|
|
7
|
+
export interface MenuBox {
|
|
8
|
+
readonly left: number;
|
|
9
|
+
readonly top: number;
|
|
10
|
+
readonly right: number;
|
|
11
|
+
readonly bottom: number;
|
|
12
|
+
}
|
|
13
|
+
/** A size in pixels. */
|
|
14
|
+
export interface MenuSize {
|
|
15
|
+
readonly width: number;
|
|
16
|
+
readonly height: number;
|
|
17
|
+
}
|
|
18
|
+
/** The room a menu keeps from the window's edges, and the gap it leaves under what it drops from, in pixels. */
|
|
19
|
+
export declare const MENU_MARGIN = 4;
|
|
20
|
+
/**
|
|
21
|
+
* Where a menu stands, its top-left corner in window coordinates. Opened at
|
|
22
|
+
* a point, it hangs down and right from it, moved in to stay inside the
|
|
23
|
+
* window, and opens upward from the point when there is no room below.
|
|
24
|
+
* Dropped from a box, it starts under the box's leading edge, a margin
|
|
25
|
+
* below, and stands over the box instead when there is room above and none
|
|
26
|
+
* below; either way it stays inside the window. A menu its stylesheet
|
|
27
|
+
* caps at the window's height less both margins (`.menu-popup`) measures
|
|
28
|
+
* at that cap, so it starts at the top margin.
|
|
29
|
+
*/
|
|
30
|
+
export declare function placeMenu(from: {
|
|
31
|
+
readonly point: MenuPoint;
|
|
32
|
+
} | {
|
|
33
|
+
readonly box: MenuBox;
|
|
34
|
+
}, size: MenuSize, viewport: MenuSize): {
|
|
35
|
+
readonly left: number;
|
|
36
|
+
readonly top: number;
|
|
37
|
+
};
|
|
38
|
+
/** What a key pressed in an open menu does. */
|
|
39
|
+
export type MenuKeyAction = {
|
|
40
|
+
readonly kind: 'move';
|
|
41
|
+
readonly delta: number;
|
|
42
|
+
} | {
|
|
43
|
+
readonly kind: 'edge';
|
|
44
|
+
readonly to: 'first' | 'last';
|
|
45
|
+
} | {
|
|
46
|
+
readonly kind: 'run';
|
|
47
|
+
} | {
|
|
48
|
+
readonly kind: 'close';
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* The menu's keys, as a desktop menu's: ↑ and ↓ move the cursor over the
|
|
52
|
+
* items that can run, Home and End to the first and the last, Return and
|
|
53
|
+
* Space run the cursor's item, Escape and Tab close it. A chord with a
|
|
54
|
+
* modifier is not the menu's (null), and neither is any other key.
|
|
55
|
+
*/
|
|
56
|
+
export declare function menuKeyAction(event: Pick<KeyboardEvent, 'key' | 'metaKey' | 'ctrlKey' | 'altKey' | 'shiftKey'>): MenuKeyAction | null;
|