@teaui/core 1.5.8 → 1.7.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dist/Screen.d.ts +6 -6
- package/.dist/Screen.js +9 -8
- package/.dist/Screen.js.map +1 -1
- package/.dist/Viewport.d.ts +12 -1
- package/.dist/Viewport.js +17 -2
- package/.dist/Viewport.js.map +1 -1
- package/.dist/components/Accordion.js +1 -1
- package/.dist/components/Accordion.js.map +1 -1
- package/.dist/components/Breadcrumb.d.ts +93 -0
- package/.dist/components/Breadcrumb.js +287 -0
- package/.dist/components/Breadcrumb.js.map +1 -0
- package/.dist/components/Button.js +23 -11
- package/.dist/components/Button.js.map +1 -1
- package/.dist/components/Calendar.d.ts +36 -0
- package/.dist/components/Calendar.js +721 -0
- package/.dist/components/Calendar.js.map +1 -0
- package/.dist/components/Canvas.d.ts +48 -0
- package/.dist/components/Canvas.js +230 -0
- package/.dist/components/Canvas.js.map +1 -0
- package/.dist/components/Checkbox.d.ts +3 -2
- package/.dist/components/Checkbox.js +31 -9
- package/.dist/components/Checkbox.js.map +1 -1
- package/.dist/components/Digits.js +18 -6
- package/.dist/components/Digits.js.map +1 -1
- package/.dist/components/Dropdown.d.ts +1 -1
- package/.dist/components/Dropdown.js +14 -6
- package/.dist/components/Dropdown.js.map +1 -1
- package/.dist/components/Geometry.d.ts +29 -0
- package/.dist/components/Geometry.js +40 -0
- package/.dist/components/Geometry.js.map +1 -0
- package/.dist/components/HotKey.js +3 -4
- package/.dist/components/HotKey.js.map +1 -1
- package/.dist/components/Input.js +4 -0
- package/.dist/components/Input.js.map +1 -1
- package/.dist/components/Keyboard.d.ts +20 -0
- package/.dist/components/Keyboard.js +31 -0
- package/.dist/components/Keyboard.js.map +1 -0
- package/.dist/components/Log.js +1 -1
- package/.dist/components/Log.js.map +1 -1
- package/.dist/components/Logo.d.ts +19 -0
- package/.dist/components/Logo.js +204 -0
- package/.dist/components/Logo.js.map +1 -0
- package/.dist/components/Modal.d.ts +74 -0
- package/.dist/components/Modal.js +113 -0
- package/.dist/components/Modal.js.map +1 -0
- package/.dist/components/Mouse.d.ts +25 -0
- package/.dist/components/Mouse.js +46 -0
- package/.dist/components/Mouse.js.map +1 -0
- package/.dist/components/Pane.d.ts +43 -0
- package/.dist/components/Pane.js +321 -0
- package/.dist/components/Pane.js.map +1 -0
- package/.dist/components/Pin.d.ts +25 -0
- package/.dist/components/Pin.js +80 -0
- package/.dist/components/Pin.js.map +1 -0
- package/.dist/components/Plot.d.ts +25 -0
- package/.dist/components/Plot.js +171 -0
- package/.dist/components/Plot.js.map +1 -0
- package/.dist/components/Scrollable.d.ts +6 -0
- package/.dist/components/Scrollable.js +14 -2
- package/.dist/components/Scrollable.js.map +1 -1
- package/.dist/components/ScrollableList.d.ts +2 -2
- package/.dist/components/ScrollableList.js +4 -4
- package/.dist/components/ScrollableList.js.map +1 -1
- package/.dist/components/Slider.d.ts +2 -0
- package/.dist/components/Slider.js +11 -1
- package/.dist/components/Slider.js.map +1 -1
- package/.dist/components/Table.d.ts +79 -0
- package/.dist/components/Table.js +603 -0
- package/.dist/components/Table.js.map +1 -0
- package/.dist/components/Tabs.d.ts +2 -0
- package/.dist/components/Tabs.js +14 -1
- package/.dist/components/Tabs.js.map +1 -1
- package/.dist/components/ZStack.d.ts +19 -0
- package/.dist/components/ZStack.js +34 -0
- package/.dist/components/ZStack.js.map +1 -0
- package/.dist/components/charts/BarChart.d.ts +27 -0
- package/.dist/components/charts/BarChart.js +122 -0
- package/.dist/components/charts/BarChart.js.map +1 -0
- package/.dist/components/charts/Chart.d.ts +43 -0
- package/.dist/components/charts/Chart.js +41 -0
- package/.dist/components/charts/Chart.js.map +1 -0
- package/.dist/components/charts/LineChart.d.ts +23 -0
- package/.dist/components/charts/LineChart.js +109 -0
- package/.dist/components/charts/LineChart.js.map +1 -0
- package/.dist/components/charts/index.d.ts +3 -0
- package/.dist/components/charts/index.js +4 -0
- package/.dist/components/charts/index.js.map +1 -0
- package/.dist/components/index.d.ts +14 -0
- package/.dist/components/index.js +14 -0
- package/.dist/components/index.js.map +1 -1
- package/.dist/iTerm2.js +1 -3
- package/.dist/iTerm2.js.map +1 -1
- package/.dist/inspect.js +1 -1
- package/.dist/inspect.js.map +1 -1
- package/.dist/managers/FocusManager.d.ts +5 -0
- package/.dist/managers/FocusManager.js +16 -0
- package/.dist/managers/FocusManager.js.map +1 -1
- package/.dist/managers/ModalManager.d.ts +2 -1
- package/.dist/managers/ModalManager.js +23 -51
- package/.dist/managers/ModalManager.js.map +1 -1
- package/.dist/renderToAnsi.js +1 -0
- package/.dist/renderToAnsi.js.map +1 -1
- package/.dist/testing.d.ts +5 -0
- package/.dist/testing.js +22 -3
- package/.dist/testing.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import * as unicode from '@teaui/term';
|
|
2
|
+
import { Container } from '../Container.js';
|
|
3
|
+
import { Point, Size } from '../geometry.js';
|
|
4
|
+
import { isMouseClicked, isMouseEnter, isMouseExit, isMouseMove, } from '../events/index.js';
|
|
5
|
+
import { Style } from '../Style.js';
|
|
6
|
+
const MAX_TITLE_WIDTH = 25;
|
|
7
|
+
export class Breadcrumb extends Container {
|
|
8
|
+
#items = [];
|
|
9
|
+
#isActive = true;
|
|
10
|
+
#palette = DEFAULT_PALETTE;
|
|
11
|
+
#segments = [];
|
|
12
|
+
#hoverIndex = null;
|
|
13
|
+
constructor(props) {
|
|
14
|
+
super(props);
|
|
15
|
+
this.#update(props);
|
|
16
|
+
}
|
|
17
|
+
update(props) {
|
|
18
|
+
this.#update(props);
|
|
19
|
+
super.update(props);
|
|
20
|
+
}
|
|
21
|
+
#update({ items, isActive, palette }) {
|
|
22
|
+
this.#items = items ?? [];
|
|
23
|
+
this.#isActive = isActive ?? true;
|
|
24
|
+
this.#palette = palette ?? DEFAULT_PALETTE;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Given a Color, return a brighter version suitable for hover highlighting.
|
|
28
|
+
* Maps standard terminal colours → their bright variants.
|
|
29
|
+
*/
|
|
30
|
+
static brightenColor(color) {
|
|
31
|
+
if (typeof color !== 'string') {
|
|
32
|
+
return color;
|
|
33
|
+
}
|
|
34
|
+
const map = {
|
|
35
|
+
black: 'gray',
|
|
36
|
+
red: 'brightRed',
|
|
37
|
+
green: 'brightGreen',
|
|
38
|
+
yellow: 'brightYellow',
|
|
39
|
+
blue: 'brightBlue',
|
|
40
|
+
magenta: 'brightMagenta',
|
|
41
|
+
cyan: 'brightCyan',
|
|
42
|
+
white: 'brightWhite',
|
|
43
|
+
gray: 'brightWhite',
|
|
44
|
+
grey: 'brightWhite',
|
|
45
|
+
};
|
|
46
|
+
return map[color] ?? color;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Compute the styles for a breadcrumb segment, accounting for hover state.
|
|
50
|
+
*
|
|
51
|
+
* Returns { segmentStyle, arrowStyle, finalArrowStyle } where arrowStyle is
|
|
52
|
+
* the style for the leading arrow (left separator) and finalArrowStyle is
|
|
53
|
+
* only set for the last item (the trailing arrow).
|
|
54
|
+
*
|
|
55
|
+
* @param colors - fg/bg for this item
|
|
56
|
+
* @param prevColors - fg/bg for the previous item (null if first)
|
|
57
|
+
* @param nextColors - fg/bg for the next item (null if last — used for trailing arrow)
|
|
58
|
+
* @param isHovered - whether this item is being hovered
|
|
59
|
+
* @param isFirst - whether this is the first item
|
|
60
|
+
* @param isLast - whether this is the last item
|
|
61
|
+
* @param prevHovered - whether the previous item is hovered (affects this item's left arrow)
|
|
62
|
+
*/
|
|
63
|
+
static highlightStyles(colors, prevColors, isHovered, isActive, isFirst, isLast, prevHovered) {
|
|
64
|
+
const bg = isHovered ? Breadcrumb.hoverBg(colors) : colors.bg;
|
|
65
|
+
const fg = isHovered ? Breadcrumb.hoverFg(colors) : colors.fg;
|
|
66
|
+
const segmentStyle = new Style({
|
|
67
|
+
foreground: fg,
|
|
68
|
+
background: bg,
|
|
69
|
+
underline: isHovered && !isActive,
|
|
70
|
+
});
|
|
71
|
+
let arrowStyle = null;
|
|
72
|
+
if (!isFirst && prevColors) {
|
|
73
|
+
// The left arrow's fg = previous item's bg, bg = this item's bg
|
|
74
|
+
const prevBg = prevHovered
|
|
75
|
+
? Breadcrumb.hoverBg(prevColors)
|
|
76
|
+
: prevColors.bg;
|
|
77
|
+
arrowStyle = new Style({
|
|
78
|
+
foreground: prevBg,
|
|
79
|
+
background: bg,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
let finalArrowStyle = null;
|
|
83
|
+
if (isLast) {
|
|
84
|
+
finalArrowStyle = new Style({
|
|
85
|
+
foreground: bg,
|
|
86
|
+
background: 'default',
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return { segmentStyle, arrowStyle, finalArrowStyle };
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Resolve the hover foreground for a palette entry.
|
|
93
|
+
* Uses the explicit `fgHover` colour if provided, otherwise falls back to `fg`.
|
|
94
|
+
*/
|
|
95
|
+
static hoverFg(entry) {
|
|
96
|
+
return entry.fgHover ?? entry.fg;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Resolve the hover background for a palette entry.
|
|
100
|
+
* Uses the explicit `bgHover` colour if provided, otherwise falls back to
|
|
101
|
+
* `brightenColor(bg)`.
|
|
102
|
+
*/
|
|
103
|
+
static hoverBg(entry) {
|
|
104
|
+
return entry.bgHover ?? Breadcrumb.brightenColor(entry.bg);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Build a clipped title string: truncates to MAX_TITLE_WIDTH and adds "…" if needed.
|
|
108
|
+
*/
|
|
109
|
+
static clippedTitle(title) {
|
|
110
|
+
const width = unicode.lineWidth(title);
|
|
111
|
+
if (width <= MAX_TITLE_WIDTH) {
|
|
112
|
+
return title;
|
|
113
|
+
}
|
|
114
|
+
// Truncate by characters until we fit (accounting for wide chars)
|
|
115
|
+
let result = '';
|
|
116
|
+
let w = 0;
|
|
117
|
+
for (const ch of title) {
|
|
118
|
+
const cw = unicode.lineWidth(ch);
|
|
119
|
+
if (w + cw > MAX_TITLE_WIDTH - 1) {
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
result += ch;
|
|
123
|
+
w += cw;
|
|
124
|
+
}
|
|
125
|
+
return result + '…';
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Measure the segments for the current items. This builds the SegmentRegion
|
|
129
|
+
* array so that mouse hit-testing works correctly.
|
|
130
|
+
*/
|
|
131
|
+
static measureSegments(items) {
|
|
132
|
+
const segments = [];
|
|
133
|
+
let x = 0;
|
|
134
|
+
for (let i = 0; i < items.length; i++) {
|
|
135
|
+
const title = Breadcrumb.clippedTitle(items[i].title);
|
|
136
|
+
const isFirst = i === 0;
|
|
137
|
+
if (isFirst) {
|
|
138
|
+
// " 🏠 {title} " — no leading arrow
|
|
139
|
+
const text = ` 🏠 ${title} `;
|
|
140
|
+
const textWidth = unicode.lineWidth(text);
|
|
141
|
+
segments.push({
|
|
142
|
+
index: i,
|
|
143
|
+
arrowX: x,
|
|
144
|
+
arrowWidth: 0,
|
|
145
|
+
textX: x,
|
|
146
|
+
textWidth,
|
|
147
|
+
});
|
|
148
|
+
x += textWidth;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
// Leading arrow (1 cell) then " {title} "
|
|
152
|
+
const arrowX = x;
|
|
153
|
+
const arrowWidth = 1;
|
|
154
|
+
const textX = x + arrowWidth;
|
|
155
|
+
const text = ` ${title} `;
|
|
156
|
+
const textWidth = unicode.lineWidth(text);
|
|
157
|
+
segments.push({
|
|
158
|
+
index: i,
|
|
159
|
+
arrowX,
|
|
160
|
+
arrowWidth,
|
|
161
|
+
textX,
|
|
162
|
+
textWidth,
|
|
163
|
+
});
|
|
164
|
+
x += arrowWidth + textWidth;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return segments;
|
|
168
|
+
}
|
|
169
|
+
naturalSize(available) {
|
|
170
|
+
if (this.#items.length === 0) {
|
|
171
|
+
return new Size(0, 1);
|
|
172
|
+
}
|
|
173
|
+
const segments = Breadcrumb.measureSegments(this.#items);
|
|
174
|
+
const last = segments[segments.length - 1];
|
|
175
|
+
// Total width = end of last segment + 1 for the trailing arrow
|
|
176
|
+
const width = last.textX + last.textWidth + 1;
|
|
177
|
+
return new Size(width, 1);
|
|
178
|
+
}
|
|
179
|
+
receiveMouse(event, system) {
|
|
180
|
+
super.receiveMouse(event, system);
|
|
181
|
+
if (isMouseExit(event)) {
|
|
182
|
+
this.#hoverIndex = null;
|
|
183
|
+
}
|
|
184
|
+
else if (isMouseEnter(event) || isMouseMove(event)) {
|
|
185
|
+
this.#hoverIndex = this.#indexAtX(event.position.x);
|
|
186
|
+
}
|
|
187
|
+
if (isMouseClicked(event)) {
|
|
188
|
+
const index = this.#indexAtX(event.position.x);
|
|
189
|
+
if (index !== null) {
|
|
190
|
+
this.#items[index]?.onPress?.();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
#indexAtX(x) {
|
|
195
|
+
for (const seg of this.#segments) {
|
|
196
|
+
// Hit test against the full segment area (arrow + text)
|
|
197
|
+
const segStart = seg.arrowX;
|
|
198
|
+
const segEnd = seg.textX + seg.textWidth;
|
|
199
|
+
if (x >= segStart && x < segEnd) {
|
|
200
|
+
return seg.index;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
render(viewport) {
|
|
206
|
+
if (viewport.isEmpty || this.#items.length === 0) {
|
|
207
|
+
return super.render(viewport);
|
|
208
|
+
}
|
|
209
|
+
viewport.registerMouse(['mouse.button.left', 'mouse.move']);
|
|
210
|
+
this.#segments = Breadcrumb.measureSegments(this.#items);
|
|
211
|
+
for (const seg of this.#segments) {
|
|
212
|
+
const i = seg.index;
|
|
213
|
+
const item = this.#items[i];
|
|
214
|
+
const isFirst = i === 0;
|
|
215
|
+
const isLast = i === this.#items.length - 1;
|
|
216
|
+
const title = Breadcrumb.clippedTitle(item.title);
|
|
217
|
+
const isHovered = this.#hoverIndex === i;
|
|
218
|
+
const prevHovered = this.#hoverIndex === i - 1;
|
|
219
|
+
if (this.#isActive) {
|
|
220
|
+
const colorIndex = i % this.#palette.length;
|
|
221
|
+
const colors = this.#palette[colorIndex];
|
|
222
|
+
const prevColors = !isFirst
|
|
223
|
+
? this.#palette[(i - 1) % this.#palette.length]
|
|
224
|
+
: null;
|
|
225
|
+
const { segmentStyle, arrowStyle, finalArrowStyle } = Breadcrumb.highlightStyles(colors, prevColors, isHovered, this.#isActive, isFirst, isLast, prevHovered);
|
|
226
|
+
// Draw leading arrow
|
|
227
|
+
if (!isFirst && arrowStyle) {
|
|
228
|
+
viewport.write(ACTIVE_ARROW, new Point(seg.arrowX, 0), arrowStyle);
|
|
229
|
+
}
|
|
230
|
+
// Draw padded text
|
|
231
|
+
const text = isFirst ? ` 🏠 ${title} ` : ` ${title} `;
|
|
232
|
+
let x = seg.textX;
|
|
233
|
+
for (const ch of text) {
|
|
234
|
+
if (x < viewport.contentSize.width) {
|
|
235
|
+
viewport.write(ch, new Point(x, 0), segmentStyle);
|
|
236
|
+
}
|
|
237
|
+
x += unicode.lineWidth(ch);
|
|
238
|
+
}
|
|
239
|
+
// Draw trailing arrow for last item
|
|
240
|
+
if (isLast && finalArrowStyle) {
|
|
241
|
+
const trailX = seg.textX + seg.textWidth;
|
|
242
|
+
if (trailX < viewport.contentSize.width) {
|
|
243
|
+
viewport.write(ACTIVE_ARROW, new Point(trailX, 0), finalArrowStyle);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
// Inactive rendering — plain text with muted separators
|
|
249
|
+
if (!isFirst) {
|
|
250
|
+
const mutedStyle = new Style({ foreground: 'gray' });
|
|
251
|
+
viewport.write(INACTIVE_ARROW, new Point(seg.arrowX, 0), mutedStyle);
|
|
252
|
+
}
|
|
253
|
+
const plainStyle = isHovered
|
|
254
|
+
? new Style({ underline: true })
|
|
255
|
+
: this.theme.ui({});
|
|
256
|
+
const text = isFirst ? ` 🏠 ${title} ` : ` ${title} `;
|
|
257
|
+
let x = seg.textX;
|
|
258
|
+
for (const ch of text) {
|
|
259
|
+
if (x < viewport.contentSize.width) {
|
|
260
|
+
viewport.write(ch, new Point(x, 0), plainStyle);
|
|
261
|
+
}
|
|
262
|
+
x += unicode.lineWidth(ch);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
super.render(viewport);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// Default colour palette — 12-bit colours with pre-computed hover variants
|
|
270
|
+
const DEFAULT_PALETTE = [
|
|
271
|
+
{ fg: '#333', fgHover: '#333', bg: '#817', bgHover: '#c256ad' },
|
|
272
|
+
{ fg: '#333', fgHover: '#333', bg: '#a35', bgHover: '#e76d87' },
|
|
273
|
+
{ fg: '#333', fgHover: '#333', bg: '#c66', bgHover: '#ff9d9a' },
|
|
274
|
+
{ fg: '#333', fgHover: '#333', bg: '#e94', bgHover: '#ffd281' },
|
|
275
|
+
{ fg: '#333', fgHover: '#333', bg: '#ed0', bgHover: '#ffff77' },
|
|
276
|
+
{ fg: '#333', fgHover: '#333', bg: '#9d5', bgHover: '#d2ff93' },
|
|
277
|
+
{ fg: '#333', fgHover: '#333', bg: '#4d8', bgHover: '#8bffc0' },
|
|
278
|
+
{ fg: '#333', fgHover: '#333', bg: '#2cb', bgHover: '#79fff4' },
|
|
279
|
+
{ fg: '#333', fgHover: '#333', bg: '#0bc', bgHover: '#71f5ff' },
|
|
280
|
+
{ fg: '#333', fgHover: '#333', bg: '#09c', bgHover: '#66d2ff' },
|
|
281
|
+
{ fg: '#333', fgHover: '#333', bg: '#36b', bgHover: '#679df7' },
|
|
282
|
+
{ fg: '#333', fgHover: '#333', bg: '#639', bgHover: '#996ad3' },
|
|
283
|
+
];
|
|
284
|
+
// Arrow constants for breadcrumb separators
|
|
285
|
+
const INACTIVE_ARROW = ''; // For inactive/muted breadcrumbs
|
|
286
|
+
const ACTIVE_ARROW = ''; // For active breadcrumbs (Powerline right triangle)
|
|
287
|
+
//# sourceMappingURL=Breadcrumb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Breadcrumb.js","sourceRoot":"","sources":["../../lib/components/Breadcrumb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,aAAa,CAAA;AAGtC,OAAO,EAA+B,SAAS,EAAC,MAAM,iBAAiB,CAAA;AACvE,OAAO,EAAC,KAAK,EAAE,IAAI,EAAC,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAEL,cAAc,EACd,YAAY,EACZ,WAAW,EACX,WAAW,GACZ,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAC,KAAK,EAAC,MAAM,aAAa,CAAA;AAuCjC,MAAM,eAAe,GAAG,EAAE,CAAA;AAE1B,MAAM,OAAO,UAAW,SAAQ,SAAS;IACvC,MAAM,GAAqB,EAAE,CAAA;IAC7B,SAAS,GAAY,IAAI,CAAA;IACzB,QAAQ,GAAmB,eAAe,CAAA;IAC1C,SAAS,GAAoB,EAAE,CAAA;IAC/B,WAAW,GAAkB,IAAI,CAAA;IAEjC,YAAY,KAAY;QACtB,KAAK,CAAC,KAAK,CAAC,CAAA;QACZ,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACrB,CAAC;IAED,MAAM,CAAC,KAAY;QACjB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QACnB,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IACrB,CAAC;IAED,OAAO,CAAC,EAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAQ;QACvC,IAAI,CAAC,MAAM,GAAG,KAAK,IAAI,EAAE,CAAA;QACzB,IAAI,CAAC,SAAS,GAAG,QAAQ,IAAI,IAAI,CAAA;QACjC,IAAI,CAAC,Q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,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAC;IAC7D,EAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAC;IAC7D,EAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAC;CAC9D,CAAA;AAED,4CAA4C;AAC5C,MAAM,cAAc,GAAG,GAAG,CAAA,CAAC,iCAAiC;AAC5D,MAAM,YAAY,GAAG,GAAG,CAAA,CAAC,oDAAoD"}
|
|
@@ -10,6 +10,7 @@ export class Button extends Container {
|
|
|
10
10
|
#textView;
|
|
11
11
|
#border = 'default';
|
|
12
12
|
#align = 'center';
|
|
13
|
+
#hasFocus = false;
|
|
13
14
|
constructor(props) {
|
|
14
15
|
super(props);
|
|
15
16
|
this.#textView = new Text({ alignment: 'center' });
|
|
@@ -21,7 +22,7 @@ export class Button extends Container {
|
|
|
21
22
|
super.update(props);
|
|
22
23
|
}
|
|
23
24
|
childTheme(view) {
|
|
24
|
-
return childTheme(super.childTheme(view), this.isPressed, this.isHover);
|
|
25
|
+
return childTheme(super.childTheme(view), this.isPressed, this.isHover || this.#hasFocus);
|
|
25
26
|
}
|
|
26
27
|
#update({ title, border, align, hotKey, onClick }) {
|
|
27
28
|
const styledText = hotKey ? styleTextForHotKey(title ?? '', hotKey) : title;
|
|
@@ -32,7 +33,7 @@ export class Button extends Container {
|
|
|
32
33
|
this.#onClick = onClick;
|
|
33
34
|
}
|
|
34
35
|
naturalSize(available) {
|
|
35
|
-
const [left, right] = this.#borderSize();
|
|
36
|
+
const [left, right] = this.#borderSize(false);
|
|
36
37
|
return super.naturalSize(available).grow(left + right, 0);
|
|
37
38
|
}
|
|
38
39
|
get title() {
|
|
@@ -45,8 +46,9 @@ export class Button extends Container {
|
|
|
45
46
|
this.#textView.text = styledText;
|
|
46
47
|
this.invalidateSize();
|
|
47
48
|
}
|
|
48
|
-
#borderSize() {
|
|
49
|
-
const
|
|
49
|
+
#borderSize(hasFocus) {
|
|
50
|
+
const borders = hasFocus ? BORDERS_FOCUS : BORDERS;
|
|
51
|
+
const [left, right] = borders[this.#border];
|
|
50
52
|
return [unicode.lineWidth(left), unicode.lineWidth(right)];
|
|
51
53
|
}
|
|
52
54
|
receiveMouse(event, system) {
|
|
@@ -59,6 +61,8 @@ export class Button extends Container {
|
|
|
59
61
|
this.#onClick?.();
|
|
60
62
|
}
|
|
61
63
|
render(viewport) {
|
|
64
|
+
const hasFocus = viewport.registerFocus();
|
|
65
|
+
this.#hasFocus = hasFocus;
|
|
62
66
|
if (viewport.isEmpty) {
|
|
63
67
|
return super.render(viewport);
|
|
64
68
|
}
|
|
@@ -68,11 +72,11 @@ export class Button extends Container {
|
|
|
68
72
|
}
|
|
69
73
|
const textStyle = this.theme.ui({
|
|
70
74
|
isPressed: this.isPressed,
|
|
71
|
-
isHover: this.isHover,
|
|
75
|
+
isHover: this.isHover || hasFocus,
|
|
72
76
|
});
|
|
73
77
|
const topsStyle = this.theme.ui({
|
|
74
78
|
isPressed: this.isPressed,
|
|
75
|
-
isHover: this.isHover,
|
|
79
|
+
isHover: this.isHover || hasFocus,
|
|
76
80
|
isOrnament: true,
|
|
77
81
|
});
|
|
78
82
|
const useEmoji = this.theme.emoji;
|
|
@@ -89,14 +93,15 @@ export class Button extends Container {
|
|
|
89
93
|
viewport.write(' ', pt, textStyle);
|
|
90
94
|
}
|
|
91
95
|
});
|
|
92
|
-
const [leftWidth, rightWidth] = this.#borderSize();
|
|
96
|
+
const [leftWidth, rightWidth] = this.#borderSize(hasFocus);
|
|
93
97
|
const naturalSize = super.naturalSize(viewport.contentSize.shrink(leftWidth + rightWidth, 0));
|
|
94
98
|
const offsetLeft = this.#align === 'center'
|
|
95
99
|
? Math.round((viewport.contentSize.width - naturalSize.width) / 2)
|
|
96
100
|
: this.#align === 'left'
|
|
97
101
|
? 1
|
|
98
102
|
: viewport.contentSize.width - naturalSize.width - 1, offset = new Point(offsetLeft, Math.round((viewport.contentSize.height - naturalSize.height) / 2));
|
|
99
|
-
const
|
|
103
|
+
const borders = hasFocus ? BORDERS_FOCUS : BORDERS;
|
|
104
|
+
const [left, right] = borders[this.#border], leftX = offset.x - leftWidth, rightX = offset.x + naturalSize.width;
|
|
100
105
|
for (let y = 0; y < naturalSize.height; y++) {
|
|
101
106
|
viewport.write(left, new Point(leftX, offset.y + y), textStyle);
|
|
102
107
|
viewport.write(right, new Point(rightX, offset.y + y), textStyle);
|
|
@@ -108,9 +113,16 @@ export class Button extends Container {
|
|
|
108
113
|
}
|
|
109
114
|
const BORDERS = {
|
|
110
115
|
default: ['[ ', ' ]'],
|
|
111
|
-
arrows: [' ', ' '],
|
|
116
|
+
// arrows: [' ', ' '],
|
|
117
|
+
arrows: ['\uE0B3', '\uE0B1'],
|
|
112
118
|
none: [' ', ' '],
|
|
113
119
|
};
|
|
114
|
-
|
|
115
|
-
|
|
120
|
+
const BORDERS_FOCUS = {
|
|
121
|
+
default: ['⟦ ', ' ⟧'],
|
|
122
|
+
// arrows: [' ', ' '],
|
|
123
|
+
arrows: ['\uE0B2', '\uE0B0'],
|
|
124
|
+
none: [' ', ' '],
|
|
125
|
+
};
|
|
126
|
+
// E0A0 \uE0A0\uE0A1\uE0A2
|
|
127
|
+
// E0B0 \uE0B0\uE0B1\uE0B2\uE0B3
|
|
116
128
|
//# sourceMappingURL=Button.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.js","sourceRoot":"","sources":["../../lib/components/Button.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,aAAa,CAAA;AAGtC,OAAO,EAA+B,SAAS,EAAC,MAAM,iBAAiB,CAAA;AACvE,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAC9B,OAAO,EAAC,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AAI,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE;YAClE,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QACtB,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAED,MAAM,OAAO,GAAgC;IAC3C,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;IACrB,wBAAwB;IACxB,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;CACjB,CAAA;AAED,MAAM,aAAa,GAAgC;IACjD,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;IACrB,wBAAwB;IACxB,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,IAAI,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;CACjB,CAAA;AAED,uCAAuC;AACvC,yCAAyC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Viewport } from '../Viewport.js';
|
|
2
|
+
import { type Props as ViewProps, View } from '../View.js';
|
|
3
|
+
import { Size } from '../geometry.js';
|
|
4
|
+
import { type KeyEvent, type MouseEvent } from '../events/index.js';
|
|
5
|
+
import { System } from '../System.js';
|
|
6
|
+
type DisplayMode = 'days' | 'months' | 'years';
|
|
7
|
+
type Selection = 'single' | 'range';
|
|
8
|
+
interface Props extends ViewProps {
|
|
9
|
+
/** Selected date */
|
|
10
|
+
date?: Date;
|
|
11
|
+
/** Displayed month/year */
|
|
12
|
+
visibleDate?: Date;
|
|
13
|
+
/** Called when navigating months/years (day is always 1) */
|
|
14
|
+
onChangeVisible?: (date: Date) => void;
|
|
15
|
+
/** Called when selecting a date (date2 == date1 for single selection) */
|
|
16
|
+
onChange?: (date1: Date, date2: Date) => void;
|
|
17
|
+
/** Single date or range selection. Default: 'single' */
|
|
18
|
+
selection?: Selection;
|
|
19
|
+
/** 0=Sunday (default), 1=Monday */
|
|
20
|
+
firstDayOfWeek?: 0 | 1;
|
|
21
|
+
}
|
|
22
|
+
export declare class Calendar extends View {
|
|
23
|
+
#private;
|
|
24
|
+
constructor(props?: Props);
|
|
25
|
+
update(props: Props): void;
|
|
26
|
+
get date(): Date;
|
|
27
|
+
set date(value: Date);
|
|
28
|
+
get visibleDate(): Date;
|
|
29
|
+
set visibleDate(value: Date);
|
|
30
|
+
get displayMode(): DisplayMode;
|
|
31
|
+
naturalSize(): Size;
|
|
32
|
+
receiveMouse(event: MouseEvent, system: System): void;
|
|
33
|
+
receiveKey(event: KeyEvent): void;
|
|
34
|
+
render(viewport: Viewport): void;
|
|
35
|
+
}
|
|
36
|
+
export {};
|