@nbtca/prompt 1.5.14 → 1.5.15
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/app/chrome.js +7 -6
- package/dist/app/fields/list-field.js +7 -7
- package/dist/app/views/docs-render.js +1 -1
- package/dist/app/views/docs.js +10 -5
- package/dist/app/views/events-render.js +21 -8
- package/dist/app/views/events.js +52 -43
- package/dist/app/views/home.js +34 -37
- package/dist/app/views/schedule-render.js +63 -21
- package/dist/app/views/schedule.js +49 -6
- package/dist/app/views/settings.js +7 -4
- package/dist/auth/cookie-jar.js +206 -0
- package/dist/auth/cookie-transport.js +53 -29
- package/dist/auth/nbt-auth.js +10 -9
- package/dist/core/components/menu.js +44 -9
- package/dist/core/logo.js +37 -18
- package/dist/core/motion.js +23 -5
- package/dist/core/text.js +2 -2
- package/dist/core/theme.js +25 -9
- package/dist/features/calendar-query.js +39 -9
- package/dist/features/calendar.js +26 -22
- package/dist/features/docs.js +1 -1
- package/dist/features/links.js +16 -2
- package/dist/features/schedule-render.js +152 -69
- package/dist/features/schedule-view.js +19 -33
- package/dist/i18n/locales/en.json +33 -12
- package/dist/i18n/locales/zh.json +31 -10
- package/package.json +2 -6
package/dist/app/chrome.js
CHANGED
|
@@ -29,7 +29,7 @@ function renderTabs(views, active, cols) {
|
|
|
29
29
|
const dot = pickIcon('·', '-');
|
|
30
30
|
const full = space.indent +
|
|
31
31
|
views
|
|
32
|
-
.map((view) =>
|
|
32
|
+
.map((view) => view.id === active ? type.active(`[${view.title}]`) : type.hint(` ${view.title} `))
|
|
33
33
|
.join(` ${dot} `);
|
|
34
34
|
if (visualWidth(full) <= cols)
|
|
35
35
|
return full;
|
|
@@ -102,28 +102,29 @@ export function fitFooterHint(cols, ...candidates) {
|
|
|
102
102
|
export function captureFooterHint(cols = Number.POSITIVE_INFINITY) {
|
|
103
103
|
const trans = t();
|
|
104
104
|
const dot = pickIcon('·', '-');
|
|
105
|
-
return fitFooterHint(cols, `Ctrl+C ${trans.common.exit}
|
|
105
|
+
return fitFooterHint(cols, `Ctrl+C ${trans.common.exit} ${dot} Esc ${trans.common.back} ${dot} Enter ${trans.common.confirm}`, 'Ctrl+C Esc Enter', 'Ctrl+C Esc', 'Ctrl+C');
|
|
106
106
|
}
|
|
107
107
|
export function digitTabHint(tabCount) {
|
|
108
108
|
const dot = pickIcon('·', '-');
|
|
109
|
-
return tabCount > 1 ? `1-${tabCount} / Tab ${dot} ` : '';
|
|
109
|
+
return tabCount > 1 ? `1-${tabCount} / Tab ${t().menu.hintTabs} ${dot} ` : '';
|
|
110
110
|
}
|
|
111
111
|
export function passiveFooterHint(tabCount, cols = Number.POSITIVE_INFINITY) {
|
|
112
112
|
const trans = t();
|
|
113
113
|
const dot = pickIcon('·', '-');
|
|
114
114
|
const compactTabs = tabCount > 1 ? `1-${tabCount}/Tab ${dot} ` : '';
|
|
115
|
-
return fitFooterHint(cols, `${digitTabHint(tabCount)}Esc ${dot} q ${trans.menu.hintQuit} ${dot} ${trans.help.hint}`, `${digitTabHint(tabCount)}Esc ${dot} q ${trans.menu.hintQuit}`, `${compactTabs}Esc ${dot} q ${dot} ?`, `Esc ${dot} q ${dot} ?`, `Esc ${dot} q`, 'q');
|
|
115
|
+
return fitFooterHint(cols, `${digitTabHint(tabCount)}Esc ${trans.menu.hintBack} ${dot} q ${trans.menu.hintQuit} ${dot} ${trans.help.hint}`, `${digitTabHint(tabCount)}Esc ${trans.menu.hintBack} ${dot} q ${trans.menu.hintQuit}`, `${compactTabs}Esc ${dot} q ${dot} ?`, `Esc ${dot} q ${dot} ?`, `Esc ${dot} q`, 'q');
|
|
116
116
|
}
|
|
117
117
|
function interactiveFooterHint(tabCount, cols) {
|
|
118
118
|
const trans = t();
|
|
119
119
|
const dot = pickIcon('·', '-');
|
|
120
120
|
const fullTabs = digitTabHint(tabCount);
|
|
121
121
|
const compactTabs = tabCount > 1 ? `1-${tabCount}/Tab ${dot} ` : '';
|
|
122
|
+
const localLabelled = `${trans.menu.hintMove} ${dot} ${trans.menu.hintOpen} ${dot} Esc ${trans.menu.hintBack} ${dot} q ${trans.menu.hintQuit}`;
|
|
122
123
|
const localFull = `${trans.menu.hintMove} ${dot} ${trans.menu.hintOpen} ${dot} Esc ${dot} q ${trans.menu.hintQuit}`;
|
|
123
124
|
const localCompact = `${trans.menu.hintMove} ${trans.menu.hintOpen} Esc q`;
|
|
124
125
|
const candidates = [
|
|
125
|
-
`${fullTabs}${
|
|
126
|
-
`${fullTabs}${
|
|
126
|
+
`${fullTabs}${localLabelled} ${dot} ${trans.help.hint}`,
|
|
127
|
+
`${fullTabs}${localLabelled}`,
|
|
127
128
|
`${compactTabs}${localFull}`,
|
|
128
129
|
localFull,
|
|
129
130
|
`${compactTabs}${localCompact}`,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { renderMenu, renderMenuOption, nextIndex, parseKey, } from '../../core/components/menu.js';
|
|
2
|
-
import { space, type } from '../../core/theme.js';
|
|
1
|
+
import { renderMenu, renderMenuOption, menuColumns, nextIndex, parseKey, } from '../../core/components/menu.js';
|
|
2
|
+
import { glyph, space, type } from '../../core/theme.js';
|
|
3
3
|
import { pickIcon } from '../../core/icons.js';
|
|
4
4
|
import { t, fmt } from '../../i18n/index.js';
|
|
5
5
|
import { visualWidth, wrapAnsiToVisualWidth } from '../../core/text.js';
|
|
6
6
|
export function computeMaxVisible(bodyRows) {
|
|
7
7
|
return Math.max(3, bodyRows - 4);
|
|
8
8
|
}
|
|
9
|
-
function renderIndentedOutput(value, cols) {
|
|
9
|
+
function renderIndentedOutput(value, cols, preferredIndent = space.indent) {
|
|
10
10
|
const width = Number.isFinite(cols) ? Math.max(1, Math.floor(cols)) : Number.POSITIVE_INFINITY;
|
|
11
|
-
const indent =
|
|
11
|
+
const indent = [preferredIndent, space.indent].find((i) => visualWidth(i) < width) ?? '';
|
|
12
12
|
const contentWidth = Math.max(1, width - visualWidth(indent));
|
|
13
13
|
return wrapAnsiToVisualWidth(value, contentWidth).map((line) => `${indent}${line}`);
|
|
14
14
|
}
|
|
@@ -64,7 +64,7 @@ export class ListField {
|
|
|
64
64
|
above > 0 ? fmt(trans.common.moreAbove, { count: above }) : null,
|
|
65
65
|
below > 0 ? fmt(trans.common.moreBelow, { count: below }) : null,
|
|
66
66
|
].filter((part) => part !== null);
|
|
67
|
-
lines.push(...renderIndentedOutput(type.hint(parts.join(` ${pickIcon('·', '-')} `)), cols));
|
|
67
|
+
lines.push(...renderIndentedOutput(type.hint(parts.join(` ${pickIcon('·', '-')} `)), cols, `${space.indent}${' '.repeat(visualWidth(glyph.cursor()) + 1)}`));
|
|
68
68
|
}
|
|
69
69
|
if (footer)
|
|
70
70
|
lines.push('', ...renderIndentedOutput(type.hint(footer), cols));
|
|
@@ -77,8 +77,8 @@ export class ListField {
|
|
|
77
77
|
if (options.length === 0) {
|
|
78
78
|
return title ? renderIndentedOutput(type.heading(title), cols).slice(0, maxRows) : [];
|
|
79
79
|
}
|
|
80
|
-
const
|
|
81
|
-
const optionGroups = options.map((option, index) => renderMenuOption(option, index === this.index,
|
|
80
|
+
const columns = menuColumns(options);
|
|
81
|
+
const optionGroups = options.map((option, index) => renderMenuOption(option, index === this.index, columns, cols));
|
|
82
82
|
const selectedLines = optionGroups[this.index] ?? [];
|
|
83
83
|
const titleValue = !title
|
|
84
84
|
? ''
|
|
@@ -57,7 +57,7 @@ export function renderDocs(state, cols = 80, bodyRows = Number.POSITIVE_INFINITY
|
|
|
57
57
|
lines = state.searchField?.render(cols) ?? [];
|
|
58
58
|
break;
|
|
59
59
|
case 'searchLoading':
|
|
60
|
-
lines =
|
|
60
|
+
lines = loadingLines(trans.docs.searching, cols);
|
|
61
61
|
break;
|
|
62
62
|
case 'searchResults':
|
|
63
63
|
lines = state.searchResultsField
|
package/dist/app/views/docs.js
CHANGED
|
@@ -78,13 +78,18 @@ async function openBrowserFromView(ctx, path, generation = lifecycleGeneration)
|
|
|
78
78
|
}
|
|
79
79
|
function buildSectionsField() {
|
|
80
80
|
const trans = t();
|
|
81
|
+
const countWidth = Math.max(0, ...sections.map((sec) => String(sec.count).length));
|
|
81
82
|
const options = [
|
|
82
|
-
...sections.map((sec) => ({
|
|
83
|
-
|
|
83
|
+
...sections.map((sec) => ({
|
|
84
|
+
value: sec.key,
|
|
85
|
+
label: sec.label,
|
|
86
|
+
hint: String(sec.count).padStart(countWidth),
|
|
87
|
+
})),
|
|
88
|
+
{ value: '__search__', label: trans.docs.searchPrompt },
|
|
84
89
|
{ value: '__refresh__', label: trans.docs.refreshCache },
|
|
85
90
|
{ value: '__browser__', label: trans.docs.openBrowser },
|
|
86
91
|
];
|
|
87
|
-
return new ListField({
|
|
92
|
+
return new ListField({ options });
|
|
88
93
|
}
|
|
89
94
|
function buildFilesField(section, maxVisible, initialIndex = 0) {
|
|
90
95
|
const trans = t();
|
|
@@ -513,9 +518,9 @@ export const docsView = {
|
|
|
513
518
|
const hasLinks = (state.readerLinks?.length ?? 0) > 0;
|
|
514
519
|
const linkHint = hasLinks ? `f ${trans.docs.readerLinksHint} ${dot} ` : '';
|
|
515
520
|
const pageHint = `${glyph.updown()} PgUp/PgDn ${dot} `;
|
|
516
|
-
const localFull = `${pageHint}${linkHint}b ${trans.docs.openBrowser} ${dot} Esc ${dot} q ${trans.menu.hintQuit}`;
|
|
521
|
+
const localFull = `${pageHint}${linkHint}b ${trans.docs.openBrowser} ${dot} Esc ${trans.menu.hintBack} ${dot} q ${trans.menu.hintQuit}`;
|
|
517
522
|
const localCompact = `${pageHint}${hasLinks ? `f ${dot} ` : ''}b ${dot} Esc ${dot} q`;
|
|
518
|
-
return fitFooterHint(cols, `${digitTabHint(tabCount)}${localFull}`, localFull, localCompact, `${hasLinks ? 'f ' : ''}b Esc q`, 'Esc q', 'q');
|
|
523
|
+
return fitFooterHint(cols, `${digitTabHint(tabCount)}${localFull} ${dot} ${trans.help.hint}`, `${digitTabHint(tabCount)}${localFull}`, localFull, localCompact, `${hasLinks ? 'f ' : ''}b Esc q`, 'Esc q', 'q');
|
|
519
524
|
}
|
|
520
525
|
return undefined;
|
|
521
526
|
},
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import { type, space } from '../../core/theme.js';
|
|
2
2
|
import { t } from '../../i18n/index.js';
|
|
3
3
|
import { renderListFieldWithContext } from '../fields/list-field.js';
|
|
4
|
-
import { renderCountdownBanner,
|
|
4
|
+
import { renderCountdownBanner, renderEventBriefLines, } from '../../features/calendar.js';
|
|
5
5
|
import { renderHeatmap } from '../../features/calendar-heatmap.js';
|
|
6
6
|
import { wrapAnsiWithIndent } from '../../core/text.js';
|
|
7
7
|
import { loadingLines } from '../../core/components/spinner.js';
|
|
8
8
|
function wrappedIndentedLines(label, cols, style) {
|
|
9
9
|
return wrapAnsiWithIndent(style(label), cols ?? Number.POSITIVE_INFINITY, space.indent);
|
|
10
10
|
}
|
|
11
|
-
function wrappedRenderedLine(line, cols) {
|
|
12
|
-
const content = line.startsWith(space.indent) ? line.slice(space.indent.length) : line;
|
|
13
|
-
return wrappedIndentedLines(content, cols, (value) => value);
|
|
14
|
-
}
|
|
15
11
|
const EXPANDED_HUB_MIN_BODY_ROWS = 29;
|
|
16
12
|
function renderHubBody(state, now, bodyRows, cols) {
|
|
17
13
|
const trans = t();
|
|
@@ -41,7 +37,7 @@ function renderHubBody(state, now, bodyRows, cols) {
|
|
|
41
37
|
const budget = Math.max(0, rows - lines.length - activityHeading.length - 1 - reservedFieldRows);
|
|
42
38
|
const collected = [];
|
|
43
39
|
for (const event of state.recentEvents ?? []) {
|
|
44
|
-
const wrapped =
|
|
40
|
+
const wrapped = renderEventBriefLines(event, now, cols);
|
|
45
41
|
if (collected.length + wrapped.length > budget)
|
|
46
42
|
break;
|
|
47
43
|
collected.push(...wrapped);
|
|
@@ -55,6 +51,12 @@ function renderHubBody(state, now, bodyRows, cols) {
|
|
|
55
51
|
if (eventLines.length > 0)
|
|
56
52
|
lines.push(...activityHeading, ...eventLines, '');
|
|
57
53
|
}
|
|
54
|
+
else if (!state.nextEvent) {
|
|
55
|
+
const notice = [...wrappedIndentedLines(trans.calendar.noEvents, cols, type.hint), ''];
|
|
56
|
+
const fieldRows = state.hubField?.render(Number.POSITIVE_INFINITY, cols).length ?? 0;
|
|
57
|
+
if (lines.length + notice.length + fieldRows <= rows)
|
|
58
|
+
lines.push(...notice);
|
|
59
|
+
}
|
|
58
60
|
if (state.hubField) {
|
|
59
61
|
return renderListFieldWithContext(lines, state.hubField, bodyRows, cols);
|
|
60
62
|
}
|
|
@@ -74,8 +76,19 @@ export function renderEvents(state, now, bodyRows = 100, cols) {
|
|
|
74
76
|
...(cols === undefined ? {} : { cols }),
|
|
75
77
|
}).split('\n')
|
|
76
78
|
: wrappedIndentedLines(trans.calendar.noEvents, cols, type.hint);
|
|
77
|
-
case 'list':
|
|
78
|
-
|
|
79
|
+
case 'list': {
|
|
80
|
+
if (!state.listField)
|
|
81
|
+
return [];
|
|
82
|
+
if (state.listNotice === undefined)
|
|
83
|
+
return state.listField.render(bodyRows, cols);
|
|
84
|
+
const context = [
|
|
85
|
+
...wrappedIndentedLines(state.listTitle ?? '', cols, type.heading),
|
|
86
|
+
'',
|
|
87
|
+
...wrappedIndentedLines(state.listNotice, cols, type.hint),
|
|
88
|
+
'',
|
|
89
|
+
];
|
|
90
|
+
return renderListFieldWithContext(context, state.listField, bodyRows, cols);
|
|
91
|
+
}
|
|
79
92
|
case 'detail': {
|
|
80
93
|
const context = [
|
|
81
94
|
...wrappedIndentedLines(state.detailTitle ?? '', cols, type.heading),
|
package/dist/app/views/events.js
CHANGED
|
@@ -4,18 +4,20 @@ import { TextField } from '../fields/text-field.js';
|
|
|
4
4
|
import { renderEvents } from './events-render.js';
|
|
5
5
|
import { setVimKeysActive } from '../../core/vim-keys.js';
|
|
6
6
|
import { pickIcon } from '../../core/icons.js';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
7
|
+
import { padEndV, visualWidth } from '../../core/text.js';
|
|
8
|
+
import { fmt, t } from '../../i18n/index.js';
|
|
9
|
+
import { eventWhen, exportEventIcs, loadCalendarOrCache, recurringMark, toDisplayEvent, yearHeatmap, } from '../../features/calendar.js';
|
|
10
|
+
import { currentEvents, monthRange, pastEvents, searchEvents, weekRange, } from '../../features/calendar-query.js';
|
|
11
11
|
let state = { mode: 'loading' };
|
|
12
12
|
let calendar = null;
|
|
13
13
|
let stale = false;
|
|
14
14
|
let currentList = [];
|
|
15
|
+
let listState;
|
|
16
|
+
let hubField;
|
|
15
17
|
function backLabel() {
|
|
16
18
|
return t().common.back;
|
|
17
19
|
}
|
|
18
|
-
function buildHubField() {
|
|
20
|
+
function buildHubField(initialIndex) {
|
|
19
21
|
const trans = t();
|
|
20
22
|
const options = [
|
|
21
23
|
{ value: 'upcoming', label: trans.calendar.next30Days },
|
|
@@ -25,50 +27,56 @@ function buildHubField() {
|
|
|
25
27
|
{ value: 'past', label: trans.calendar.pastEvents },
|
|
26
28
|
{ value: 'heatmap', label: trans.calendar.heatmap.title },
|
|
27
29
|
];
|
|
28
|
-
return new ListField({ title: trans.calendar.browse, options });
|
|
30
|
+
return new ListField({ title: trans.calendar.browse, options, initialIndex });
|
|
29
31
|
}
|
|
30
|
-
function
|
|
32
|
+
function showList(ctx, title, events, emptyMessage, endedFrom = events.length) {
|
|
31
33
|
const trans = t();
|
|
34
|
+
const dot = pickIcon('·', '-');
|
|
32
35
|
const display = events.map(toDisplayEvent);
|
|
36
|
+
const whenWidth = Math.max(0, ...display.map((event) => visualWidth(eventWhen(event))));
|
|
33
37
|
const options = [
|
|
34
|
-
...display.map((event, index) =>
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
...display.map((event, index) => {
|
|
39
|
+
const ended = index >= endedFrom;
|
|
40
|
+
return {
|
|
41
|
+
value: String(index),
|
|
42
|
+
label: `${padEndV(eventWhen(event), whenWidth)} ${event.title}${recurringMark(event)}`,
|
|
43
|
+
hint: ended ? `${trans.calendar.endedLabel} ${dot} ${event.location}` : event.location,
|
|
44
|
+
hintColumn: true,
|
|
45
|
+
dim: ended,
|
|
46
|
+
};
|
|
47
|
+
}),
|
|
39
48
|
{ value: '__back__', label: backLabel() },
|
|
40
49
|
];
|
|
41
|
-
return new ListField({
|
|
42
|
-
title: title || trans.menu.events,
|
|
43
|
-
options: options.length > 1
|
|
44
|
-
? options
|
|
45
|
-
: [{ value: '__back__', label: `${trans.calendar.noEvents} — ${backLabel()}` }],
|
|
46
|
-
maxVisible,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
function showList(title, events, ctx) {
|
|
50
50
|
currentList = events;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
const maxVisible = computeMaxVisible(ctx.bodyRows);
|
|
52
|
+
state =
|
|
53
|
+
events.length > 0
|
|
54
|
+
? { mode: 'list', listField: new ListField({ title, options, maxVisible }) }
|
|
55
|
+
: {
|
|
56
|
+
mode: 'list',
|
|
57
|
+
listTitle: title,
|
|
58
|
+
listNotice: emptyMessage,
|
|
59
|
+
listField: new ListField({ options, maxVisible }),
|
|
60
|
+
};
|
|
55
61
|
}
|
|
56
|
-
const
|
|
62
|
+
const RECENT_EVENTS_CAP = 5;
|
|
57
63
|
function goToHub() {
|
|
58
64
|
const now = new Date();
|
|
59
65
|
const upcoming = calendar ? currentEvents(calendar, now) : [];
|
|
60
66
|
const nextEvent = upcoming.find((event) => event.start >= now);
|
|
67
|
+
hubField = buildHubField(hubField?.selectedIndex ?? 0);
|
|
61
68
|
state = {
|
|
62
69
|
mode: 'hub',
|
|
63
|
-
hubField
|
|
70
|
+
hubField,
|
|
64
71
|
...(stale ? { stale } : {}),
|
|
65
72
|
...(nextEvent === undefined ? {} : { nextEvent: toDisplayEvent(nextEvent) }),
|
|
66
73
|
heatmapBuckets: calendar ? yearHeatmap(calendar, now) : [],
|
|
67
|
-
recentEvents: upcoming.slice(0,
|
|
74
|
+
recentEvents: upcoming.slice(0, RECENT_EVENTS_CAP).map(toDisplayEvent),
|
|
68
75
|
};
|
|
69
76
|
}
|
|
70
77
|
function showDetail(raw) {
|
|
71
78
|
const trans = t();
|
|
79
|
+
listState = state;
|
|
72
80
|
const e = toDisplayEvent(raw);
|
|
73
81
|
const dot = pickIcon('·', '-');
|
|
74
82
|
state = {
|
|
@@ -93,6 +101,7 @@ export const eventsView = {
|
|
|
93
101
|
if (ctx.signal?.aborted)
|
|
94
102
|
return;
|
|
95
103
|
state = { mode: 'loading' };
|
|
104
|
+
hubField = undefined;
|
|
96
105
|
ctx.rerender();
|
|
97
106
|
try {
|
|
98
107
|
const loaded = await loadCalendarOrCache(ctx.signal);
|
|
@@ -130,6 +139,10 @@ export const eventsView = {
|
|
|
130
139
|
return passive ? passiveFooterHint(tabCount, cols) : undefined;
|
|
131
140
|
},
|
|
132
141
|
handleBack() {
|
|
142
|
+
if (state.mode === 'detail' && listState) {
|
|
143
|
+
state = listState;
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
133
146
|
if (state.mode === 'list' ||
|
|
134
147
|
state.mode === 'detail' ||
|
|
135
148
|
state.mode === 'search' ||
|
|
@@ -150,22 +163,19 @@ export const eventsView = {
|
|
|
150
163
|
if (!result?.selected)
|
|
151
164
|
return;
|
|
152
165
|
const now = new Date();
|
|
166
|
+
const trans = t();
|
|
153
167
|
if (result.selected === 'upcoming') {
|
|
154
|
-
showList(
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
if (result.selected === 'week') {
|
|
158
|
-
const r = weekRange(now);
|
|
159
|
-
showList(t().calendar.thisWeek, calendar.inRange(r.start, r.end), ctx);
|
|
168
|
+
showList(ctx, trans.calendar.next30Days, currentEvents(calendar, now), trans.calendar.noEvents);
|
|
160
169
|
return;
|
|
161
170
|
}
|
|
162
|
-
if (result.selected === 'month') {
|
|
163
|
-
const r = monthRange(now);
|
|
164
|
-
|
|
171
|
+
if (result.selected === 'week' || result.selected === 'month') {
|
|
172
|
+
const r = result.selected === 'week' ? weekRange(now) : monthRange(now);
|
|
173
|
+
const title = result.selected === 'week' ? trans.calendar.thisWeek : trans.calendar.thisMonth;
|
|
174
|
+
showList(ctx, title, calendar.inRange(r.start, r.end), trans.calendar.noEventsInRange);
|
|
165
175
|
return;
|
|
166
176
|
}
|
|
167
177
|
if (result.selected === 'past') {
|
|
168
|
-
showList(
|
|
178
|
+
showList(ctx, trans.calendar.pastEvents, pastEvents(calendar, now), trans.calendar.noPastEvents);
|
|
169
179
|
return;
|
|
170
180
|
}
|
|
171
181
|
if (result.selected === 'heatmap') {
|
|
@@ -207,7 +217,7 @@ export const eventsView = {
|
|
|
207
217
|
if (!result?.selected)
|
|
208
218
|
return;
|
|
209
219
|
if (result.selected === '__back__') {
|
|
210
|
-
|
|
220
|
+
eventsView.handleBack();
|
|
211
221
|
return;
|
|
212
222
|
}
|
|
213
223
|
if (result.selected === 'export' && state.detailEvent) {
|
|
@@ -235,10 +245,9 @@ export const eventsView = {
|
|
|
235
245
|
goToHub();
|
|
236
246
|
return;
|
|
237
247
|
}
|
|
238
|
-
const
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
showList(`${t().calendar.search}: ${query}`, results, ctx);
|
|
248
|
+
const { upcoming, past } = searchEvents(calendar, query, new Date());
|
|
249
|
+
const trans = t();
|
|
250
|
+
showList(ctx, `${trans.calendar.search}: ${query}`, [...upcoming, ...past], fmt(trans.calendar.searchNoResultsFor, { query }), upcoming.length);
|
|
242
251
|
}
|
|
243
252
|
return;
|
|
244
253
|
}
|
package/dist/app/views/home.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { c, type, space, glyph } from '../../core/theme.js';
|
|
2
|
-
import { t } from '../../i18n/index.js';
|
|
2
|
+
import { t, fmt } from '../../i18n/index.js';
|
|
3
3
|
import { pickIcon } from '../../core/icons.js';
|
|
4
4
|
import { padEndV, visualWidth, wrapAnsiWithIndent } from '../../core/text.js';
|
|
5
|
-
import {
|
|
5
|
+
import { nextClassLine, peekSchedule, todayLines, weekAheadInfo, } from '../../features/schedule-view.js';
|
|
6
6
|
import { loadCalendarOrThrow, peekCalendar, toDisplayEvent, renderEventBrief, } from '../../features/calendar.js';
|
|
7
7
|
import { weekdayShortLabel } from '../../features/schedule-render.js';
|
|
8
8
|
import { passiveFooterHint } from '../chrome.js';
|
|
@@ -75,29 +75,32 @@ function renderWeekAheadGrid(classDays, eventDays, cols) {
|
|
|
75
75
|
export function renderHome(data, now, bodyRows = 100, cols = 80) {
|
|
76
76
|
const trans = t();
|
|
77
77
|
const lines = [];
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
lines.push(renderDayProgress(now, cols));
|
|
86
|
-
if (data.todayLines && data.todayLines.length > 0) {
|
|
87
|
-
for (const line of data.todayLines)
|
|
88
|
-
lines.push(...wrappedRenderedLines(line, cols));
|
|
78
|
+
if (data.schedule === null) {
|
|
79
|
+
lines.push(...panelHeading(trans.timetable.menuTitle, cols));
|
|
80
|
+
lines.push(...wrappedIndentedLines(fmt(trans.timetable.homeLoginCta, {
|
|
81
|
+
tab: trans.timetable.menuEntry,
|
|
82
|
+
action: trans.timetable.publicLoginAction,
|
|
83
|
+
}), cols, type.hint));
|
|
84
|
+
lines.push('');
|
|
89
85
|
}
|
|
90
|
-
else {
|
|
91
|
-
|
|
86
|
+
else if (data.schedule) {
|
|
87
|
+
const next = nextClassLine(data.schedule, now, cols);
|
|
88
|
+
lines.push(...panelHeading(trans.timetable.nextClass, cols));
|
|
89
|
+
lines.push(...(next ? [next] : wrappedIndentedLines(trans.timetable.noNextClass, cols, type.hint)));
|
|
90
|
+
lines.push('');
|
|
91
|
+
lines.push(...panelHeading(trans.timetable.hubToday, cols));
|
|
92
|
+
lines.push(renderDayProgress(now, cols));
|
|
93
|
+
lines.push(...todayLines(data.schedule, now, cols));
|
|
94
|
+
lines.push('');
|
|
92
95
|
}
|
|
93
|
-
lines.push('');
|
|
94
96
|
if (data.weekAhead) {
|
|
95
97
|
lines.push(...panelHeading(trans.timetable.weekOverviewTitle, cols));
|
|
96
98
|
lines.push(...renderWeekAheadGrid(data.weekAhead.classDays, data.weekAhead.eventDays, cols).split('\n'));
|
|
97
99
|
lines.push('');
|
|
98
100
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
const unresolvedCount = data.schedule?.timetable.unresolvedItems.length ?? 0;
|
|
102
|
+
if (unresolvedCount > 0) {
|
|
103
|
+
lines.push(...wrappedIndentedLines(`${pickIcon('⚠', '!')} ${trans.timetable.hubUnresolved} · ${unresolvedCount}`, cols, c.warn));
|
|
101
104
|
lines.push('');
|
|
102
105
|
}
|
|
103
106
|
const eventsStale = data.eventsLoadFailed === true && (data.eventLines?.length ?? 0) > 0;
|
|
@@ -132,14 +135,14 @@ export function renderHome(data, now, bodyRows = 100, cols = 80) {
|
|
|
132
135
|
return lines;
|
|
133
136
|
}
|
|
134
137
|
const HOME_EVENT_FETCH_CAP = 15;
|
|
135
|
-
function calendarSnapshot(cal,
|
|
138
|
+
function calendarSnapshot(cal, weekAhead) {
|
|
136
139
|
const now = new Date();
|
|
137
140
|
const eventLines = currentEvents(cal, now)
|
|
138
141
|
.slice(0, HOME_EVENT_FETCH_CAP)
|
|
139
142
|
.map((event) => renderEventBrief(toDisplayEvent(event), now));
|
|
140
|
-
if (!
|
|
143
|
+
if (!weekAhead)
|
|
141
144
|
return { eventLines };
|
|
142
|
-
const { weekStart } =
|
|
145
|
+
const { weekStart } = weekAhead;
|
|
143
146
|
const monday = campusDateTime(weekStart, '00:00');
|
|
144
147
|
const daySet = new Set(cal
|
|
145
148
|
.inRange(new Date(monday.getTime() - DAY_MS), new Date(monday.getTime() + 8 * DAY_MS))
|
|
@@ -150,7 +153,7 @@ function calendarSnapshot(cal, weekAheadInfo) {
|
|
|
150
153
|
return {
|
|
151
154
|
eventLines,
|
|
152
155
|
weekAhead: {
|
|
153
|
-
classDays:
|
|
156
|
+
classDays: weekAhead.classDays,
|
|
154
157
|
eventDays: WEEKDAYS.map((weekday) => daySet.has(weekday)),
|
|
155
158
|
},
|
|
156
159
|
};
|
|
@@ -165,22 +168,16 @@ export const homeView = {
|
|
|
165
168
|
async load(ctx) {
|
|
166
169
|
if (ctx.signal?.aborted)
|
|
167
170
|
return;
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
...(weekAheadInfo ? { weekAhead: { classDays: weekAheadInfo.classDays } } : {}),
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
catch {
|
|
179
|
-
data = { loading: true };
|
|
180
|
-
}
|
|
171
|
+
const schedule = peekSchedule();
|
|
172
|
+
const weekAhead = schedule ? weekAheadInfo(schedule) : null;
|
|
173
|
+
data = {
|
|
174
|
+
loading: true,
|
|
175
|
+
schedule,
|
|
176
|
+
...(weekAhead ? { weekAhead: { classDays: weekAhead.classDays } } : {}),
|
|
177
|
+
};
|
|
181
178
|
const cached = peekCalendar();
|
|
182
179
|
if (cached)
|
|
183
|
-
data = { ...data, ...calendarSnapshot(cached,
|
|
180
|
+
data = { ...data, ...calendarSnapshot(cached, weekAhead) };
|
|
184
181
|
if (ctx.signal?.aborted)
|
|
185
182
|
return;
|
|
186
183
|
ctx.rerender();
|
|
@@ -188,7 +185,7 @@ export const homeView = {
|
|
|
188
185
|
const cal = await loadCalendarOrThrow(ctx.signal);
|
|
189
186
|
if (ctx.signal?.aborted)
|
|
190
187
|
return;
|
|
191
|
-
data = { ...data, ...calendarSnapshot(cal,
|
|
188
|
+
data = { ...data, ...calendarSnapshot(cal, weekAhead) };
|
|
192
189
|
}
|
|
193
190
|
catch {
|
|
194
191
|
if (ctx.signal?.aborted)
|
|
@@ -3,7 +3,7 @@ import { c, type, space, glyph } from '../../core/theme.js';
|
|
|
3
3
|
import { pickIcon } from '../../core/icons.js';
|
|
4
4
|
import { t, fmt } from '../../i18n/index.js';
|
|
5
5
|
import { renderListFieldWithContext } from '../fields/list-field.js';
|
|
6
|
-
import { renderNextClassBanner, renderWeekGrid, renderUnresolvedItems, renderTodayTimeline, weekdayShortLabel, renderTermDensity, renderMeetingDetail, renderDayTimeline, renderDaySwitcher, } from '../../features/schedule-render.js';
|
|
6
|
+
import { renderNextClassBanner, renderWeekGrid, renderUnresolvedItems, renderTodayTimeline, weekdayShortLabel, renderTermDensity, renderMeetingDetail, renderDayTimeline, renderDaySwitcher, renderWeekAgenda, lineBudget, } from '../../features/schedule-render.js';
|
|
7
7
|
import { sanitizeTerminalLine, visualWidth, wrapAnsiWithIndent } from '../../core/text.js';
|
|
8
8
|
import { isoDayDifference } from '../../core/calendar-day.js';
|
|
9
9
|
import { loadingLines } from '../../core/components/spinner.js';
|
|
@@ -42,7 +42,7 @@ export function hubShortcuts(tt) {
|
|
|
42
42
|
return shortcuts;
|
|
43
43
|
}
|
|
44
44
|
function renderShortcutLines(shortcuts, cols, compact = false) {
|
|
45
|
-
const available = Math.max(1, cols - visualWidth(space.indent));
|
|
45
|
+
const available = Math.max(1, lineBudget(cols) - visualWidth(space.indent));
|
|
46
46
|
const parts = shortcuts.map((shortcut) => {
|
|
47
47
|
const text = compact
|
|
48
48
|
? shortcut.showKey === false
|
|
@@ -105,37 +105,64 @@ function hubPreGridLines(state, now, cols) {
|
|
|
105
105
|
week: String(week),
|
|
106
106
|
})),
|
|
107
107
|
...renderTodayTimeline(today, tt.periods, now, cols).split('\n'),
|
|
108
|
+
'',
|
|
108
109
|
weekHeading,
|
|
109
110
|
];
|
|
110
111
|
return { inlineLines, fallbackLines: [...lines, weekHeading], week, tt };
|
|
111
112
|
}
|
|
112
113
|
const MIN_GRID_COLS = 100;
|
|
113
|
-
function
|
|
114
|
+
function fittingWeekGrid(tt, week, now, rows, cols, cursor) {
|
|
114
115
|
if (cols < MIN_GRID_COLS)
|
|
115
|
-
return
|
|
116
|
-
const
|
|
117
|
-
return
|
|
116
|
+
return null;
|
|
117
|
+
const grid = renderWeekGrid(tt, week, now, cols, cursor).split('\n');
|
|
118
|
+
return grid.length <= rows ? grid : null;
|
|
118
119
|
}
|
|
119
|
-
function
|
|
120
|
-
if (gridFitsInline(inlineLines.length, tt, week, now, bodyRows, cols, cursor, reservedRows)) {
|
|
121
|
-
return [...inlineLines, ...renderWeekGrid(tt, week, now, cols, cursor).split('\n')];
|
|
122
|
-
}
|
|
120
|
+
function renderDayFallback(tt, week, todayWd, now, cols, cursor) {
|
|
123
121
|
const selectedWd = cursor?.weekday ?? todayWd;
|
|
124
|
-
const dayMeetings = createTimetableSchedule(tt).meetingsOnDay(week, selectedWd);
|
|
125
122
|
return [
|
|
126
|
-
...fallbackLines,
|
|
127
123
|
renderDaySwitcher(selectedWd, todayWd, cols),
|
|
128
|
-
...renderDayTimeline(
|
|
124
|
+
...renderDayTimeline(createTimetableSchedule(tt).meetingsOnDay(week, selectedWd), tt.periods, now, { weekday: selectedWd, isToday: selectedWd === todayWd }, cursor?.period, cols).split('\n'),
|
|
129
125
|
];
|
|
130
126
|
}
|
|
127
|
+
function renderAdaptiveWeekGrid(inlineLines, fallbackLines, tt, week, todayWd, now, bodyRows, cols, cursor, reservedRows) {
|
|
128
|
+
const grid = fittingWeekGrid(tt, week, now, bodyRows - reservedRows - inlineLines.length, cols, cursor);
|
|
129
|
+
if (grid)
|
|
130
|
+
return [...inlineLines, ...grid];
|
|
131
|
+
return [...fallbackLines, ...renderDayFallback(tt, week, todayWd, now, cols, cursor)];
|
|
132
|
+
}
|
|
133
|
+
function renderWeekBody(tt, week, todayWd, now, bodyRows, cols, cursor) {
|
|
134
|
+
const rows = Math.max(0, Math.floor(bodyRows));
|
|
135
|
+
const title = heading(t().timetable.hubWeek);
|
|
136
|
+
const layouts = [
|
|
137
|
+
fittingWeekGrid(tt, week, now, rows - 2, cols, cursor),
|
|
138
|
+
renderWeekAgenda(tt, week, now, cols, cursor),
|
|
139
|
+
renderWeekAgenda(tt, week, now, cols, cursor, true),
|
|
140
|
+
];
|
|
141
|
+
for (const layout of layouts) {
|
|
142
|
+
if (!layout)
|
|
143
|
+
continue;
|
|
144
|
+
if (layout.length + 2 <= rows)
|
|
145
|
+
return [title, '', ...layout];
|
|
146
|
+
if (layout.length + 1 <= rows)
|
|
147
|
+
return [title, ...layout];
|
|
148
|
+
}
|
|
149
|
+
const dense = layouts.at(-1);
|
|
150
|
+
if (dense && dense.length <= rows)
|
|
151
|
+
return dense;
|
|
152
|
+
return [
|
|
153
|
+
...hintLines(t().timetable.weekTooSmall, cols),
|
|
154
|
+
...renderDayFallback(tt, week, todayWd, now, cols, cursor),
|
|
155
|
+
];
|
|
156
|
+
}
|
|
157
|
+
const MIN_HUB_CONTENT_ROWS = 4;
|
|
131
158
|
function renderHubBody(state, now, bodyRows, cols) {
|
|
132
159
|
const tt = state.timetable;
|
|
133
160
|
const pre = hubPreGridLines(state, now, cols);
|
|
134
161
|
const shortcuts = tt ? hubShortcuts(tt) : [];
|
|
135
162
|
const rows = Math.max(0, Math.floor(bodyRows));
|
|
136
|
-
const build = (shortcutLines) => {
|
|
163
|
+
const build = (shortcutLines, gap = true) => {
|
|
137
164
|
const tail = [];
|
|
138
|
-
if (pre && (state.statusMessage || shortcutLines.length > 0))
|
|
165
|
+
if (gap && pre && (state.statusMessage || shortcutLines.length > 0))
|
|
139
166
|
tail.push('');
|
|
140
167
|
if (state.statusMessage) {
|
|
141
168
|
tail.push(...hintLines(state.statusMessage, cols));
|
|
@@ -148,9 +175,15 @@ function renderHubBody(state, now, bodyRows, cols) {
|
|
|
148
175
|
: [];
|
|
149
176
|
return { content, tail };
|
|
150
177
|
};
|
|
151
|
-
const
|
|
178
|
+
const labelled = renderShortcutLines(shortcuts, cols);
|
|
179
|
+
const full = build(labelled);
|
|
152
180
|
if (full.content.length + full.tail.length <= rows)
|
|
153
181
|
return [...full.content, ...full.tail];
|
|
182
|
+
const tight = build(labelled, false);
|
|
183
|
+
if (rows - tight.tail.length >= MIN_HUB_CONTENT_ROWS) {
|
|
184
|
+
const content = tight.content.filter((line) => line !== '');
|
|
185
|
+
return [...content.slice(0, rows - tight.tail.length), ...tight.tail];
|
|
186
|
+
}
|
|
154
187
|
const compact = build(renderShortcutLines(shortcuts, cols, true));
|
|
155
188
|
if (compact.tail.length >= rows)
|
|
156
189
|
return rows > 0 ? compact.tail.slice(-rows) : [];
|
|
@@ -241,16 +274,25 @@ export function renderSchedule(state, now, bodyRows = 100, cols = 80) {
|
|
|
241
274
|
const schedule = createTimetableSchedule(state.timetable, {
|
|
242
275
|
weekOneMonday: state.weekOne,
|
|
243
276
|
});
|
|
244
|
-
|
|
245
|
-
const weekLines = [heading(trans.timetable.hubWeek), ''];
|
|
246
|
-
return renderAdaptiveWeekGrid(weekLines, weekLines, state.timetable, week, schedule.weekdayAt(now), now, bodyRows, cols, state.gridCursor, 2);
|
|
277
|
+
return renderWeekBody(state.timetable, Math.max(1, schedule.weekAt(now)), schedule.weekdayAt(now), now, bodyRows, cols, state.gridCursor);
|
|
247
278
|
}
|
|
248
279
|
case 'termDensity':
|
|
249
280
|
if (!state.timetable || !state.weekOne)
|
|
250
281
|
return [hint(trans.timetable.genericError)];
|
|
251
282
|
return renderTermDensity(state.timetable.meetings, state.weekOne, createTimetableSchedule(state.timetable, { weekOneMonday: state.weekOne }).weekAt(now), cols).split('\n');
|
|
252
|
-
case 'termPicker':
|
|
253
|
-
|
|
283
|
+
case 'termPicker': {
|
|
284
|
+
if (!state.termField)
|
|
285
|
+
return [];
|
|
286
|
+
const note = state.termPickerNote
|
|
287
|
+
? [
|
|
288
|
+
...headingLines(trans.timetable.hubSwitchTerm, cols),
|
|
289
|
+
'',
|
|
290
|
+
...hintLines(state.termPickerNote, cols),
|
|
291
|
+
'',
|
|
292
|
+
]
|
|
293
|
+
: [];
|
|
294
|
+
return renderListFieldWithContext(note, state.termField, bodyRows, cols);
|
|
295
|
+
}
|
|
254
296
|
case 'unresolved':
|
|
255
297
|
return [
|
|
256
298
|
heading(trans.timetable.unresolvedTitle),
|