@nbtca/prompt 1.5.13 → 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/tabs.js +1 -1
- package/dist/app/views/docs-render.js +8 -6
- package/dist/app/views/docs.js +26 -9
- package/dist/app/views/events-render.js +21 -8
- package/dist/app/views/events.js +53 -44
- package/dist/app/views/home.js +42 -56
- package/dist/app/views/schedule-grid-cursor.js +7 -2
- package/dist/app/views/schedule-render.js +63 -21
- package/dist/app/views/schedule.js +55 -12
- package/dist/app/views/settings.js +28 -40
- package/dist/auth/cookie-jar.js +206 -0
- package/dist/auth/cookie-transport.js +53 -29
- package/dist/auth/login-page.js +141 -0
- package/dist/auth/nbt-auth.js +17 -21
- 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 +16 -14
- package/dist/core/theme.js +27 -9
- package/dist/features/calendar-query.js +39 -9
- package/dist/features/calendar.js +26 -22
- package/dist/features/docs-client.js +7 -2
- package/dist/features/docs-markdown.js +265 -0
- package/dist/features/docs-store.js +37 -27
- package/dist/features/docs.js +32 -133
- package/dist/features/links.js +16 -2
- package/dist/features/schedule-render.js +156 -71
- package/dist/features/schedule-view.js +19 -33
- package/dist/i18n/locales/en.json +40 -16
- package/dist/i18n/locales/zh.json +38 -14
- package/package.json +3 -9
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
|
? ''
|
package/dist/app/tabs.js
CHANGED
|
@@ -2,7 +2,7 @@ import { t } from '../i18n/index.js';
|
|
|
2
2
|
export function getAppTabs() {
|
|
3
3
|
const trans = t();
|
|
4
4
|
return [
|
|
5
|
-
{ id: 'home', title:
|
|
5
|
+
{ id: 'home', title: trans.menu.home },
|
|
6
6
|
{ id: 'schedule', title: trans.timetable.menuEntry },
|
|
7
7
|
{ id: 'events', title: trans.menu.events },
|
|
8
8
|
{ id: 'docs', title: trans.menu.docs },
|
|
@@ -1,14 +1,14 @@
|
|
|
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 { visualWidth,
|
|
4
|
+
import { visualWidth, wrapAnsiWithIndent } from '../../core/text.js';
|
|
5
5
|
import { loadingLines } from '../../core/components/spinner.js';
|
|
6
6
|
function hintLines(label, cols) {
|
|
7
7
|
return wrapAnsiWithIndent(type.hint(label), cols, space.indent);
|
|
8
8
|
}
|
|
9
|
-
function renderReader(
|
|
9
|
+
function renderReader(render, cols) {
|
|
10
10
|
const contentWidth = Math.max(1, Math.min(80, cols - visualWidth(space.indent)));
|
|
11
|
-
return
|
|
11
|
+
return render(contentWidth).map((line) => (line ? `${space.indent}${line}` : ''));
|
|
12
12
|
}
|
|
13
13
|
function listFieldForState(state) {
|
|
14
14
|
switch (state.mode) {
|
|
@@ -40,7 +40,9 @@ export function renderDocs(state, cols = 80, bodyRows = Number.POSITIVE_INFINITY
|
|
|
40
40
|
lines = loadingLines(trans.common.loading, cols);
|
|
41
41
|
break;
|
|
42
42
|
case 'sections':
|
|
43
|
-
lines = state.sectionsField
|
|
43
|
+
lines = state.sectionsField
|
|
44
|
+
? renderListFieldWithContext(state.stale ? [...hintLines(trans.docs.stale, cols), ''] : [], state.sectionsField, bodyRows, cols)
|
|
45
|
+
: [];
|
|
44
46
|
break;
|
|
45
47
|
case 'files':
|
|
46
48
|
lines = state.filesField?.render(bodyRows, cols) ?? [];
|
|
@@ -55,7 +57,7 @@ export function renderDocs(state, cols = 80, bodyRows = Number.POSITIVE_INFINITY
|
|
|
55
57
|
lines = state.searchField?.render(cols) ?? [];
|
|
56
58
|
break;
|
|
57
59
|
case 'searchLoading':
|
|
58
|
-
lines =
|
|
60
|
+
lines = loadingLines(trans.docs.searching, cols);
|
|
59
61
|
break;
|
|
60
62
|
case 'searchResults':
|
|
61
63
|
lines = state.searchResultsField
|
|
@@ -72,7 +74,7 @@ export function renderDocs(state, cols = 80, bodyRows = Number.POSITIVE_INFINITY
|
|
|
72
74
|
case 'reader':
|
|
73
75
|
lines = state.readerLinksField
|
|
74
76
|
? state.readerLinksField.render(bodyRows, cols)
|
|
75
|
-
: renderReader(state.
|
|
77
|
+
: renderReader(state.readerRender ?? (() => []), cols);
|
|
76
78
|
break;
|
|
77
79
|
case 'error':
|
|
78
80
|
return hintLines(state.errorMessage ?? trans.docs.loadError, cols);
|
package/dist/app/views/docs.js
CHANGED
|
@@ -12,6 +12,7 @@ let state = { mode: 'loading' };
|
|
|
12
12
|
let sections = [];
|
|
13
13
|
let archivedGroups = new Map();
|
|
14
14
|
let loaded = false;
|
|
15
|
+
let stale = false;
|
|
15
16
|
let loadedLanguage = null;
|
|
16
17
|
let currentSectionKey = null;
|
|
17
18
|
let currentArchivedGroupKey = null;
|
|
@@ -77,13 +78,18 @@ async function openBrowserFromView(ctx, path, generation = lifecycleGeneration)
|
|
|
77
78
|
}
|
|
78
79
|
function buildSectionsField() {
|
|
79
80
|
const trans = t();
|
|
81
|
+
const countWidth = Math.max(0, ...sections.map((sec) => String(sec.count).length));
|
|
80
82
|
const options = [
|
|
81
|
-
...sections.map((sec) => ({
|
|
82
|
-
|
|
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 },
|
|
83
89
|
{ value: '__refresh__', label: trans.docs.refreshCache },
|
|
84
90
|
{ value: '__browser__', label: trans.docs.openBrowser },
|
|
85
91
|
];
|
|
86
|
-
return new ListField({
|
|
92
|
+
return new ListField({ options });
|
|
87
93
|
}
|
|
88
94
|
function buildFilesField(section, maxVisible, initialIndex = 0) {
|
|
89
95
|
const trans = t();
|
|
@@ -210,7 +216,7 @@ function goToSections() {
|
|
|
210
216
|
currentSectionKey = null;
|
|
211
217
|
currentArchivedGroupKey = null;
|
|
212
218
|
currentSearchResults = [];
|
|
213
|
-
state = { mode: 'sections', sectionsField: buildSectionsField() };
|
|
219
|
+
state = { mode: 'sections', sectionsField: buildSectionsField(), stale };
|
|
214
220
|
}
|
|
215
221
|
function replaceSection(section) {
|
|
216
222
|
sections = sections.map((current) => (current.key === section.key ? section : current));
|
|
@@ -338,7 +344,7 @@ async function openInReader(ctx, path, pushCurrent) {
|
|
|
338
344
|
state = {
|
|
339
345
|
mode: 'reader',
|
|
340
346
|
readerTitle: doc.title,
|
|
341
|
-
|
|
347
|
+
readerRender: doc.render,
|
|
342
348
|
readerLinks: doc.links,
|
|
343
349
|
};
|
|
344
350
|
ctx.resetScroll();
|
|
@@ -401,13 +407,24 @@ export const docsView = {
|
|
|
401
407
|
sections = localized;
|
|
402
408
|
loaded = true;
|
|
403
409
|
loadedLanguage = getCurrentLanguage();
|
|
404
|
-
|
|
410
|
+
stale = false;
|
|
411
|
+
if (!cached || (changed && state.mode === 'sections'))
|
|
405
412
|
goToSections();
|
|
413
|
+
else if (state.mode === 'sections')
|
|
414
|
+
state = { ...state, stale };
|
|
406
415
|
}
|
|
407
416
|
catch {
|
|
408
417
|
if (!isLifecycleActive(ctx, generation) || requestId !== sectionsRequestId)
|
|
409
418
|
return;
|
|
410
|
-
|
|
419
|
+
if (cached) {
|
|
420
|
+
loaded = true;
|
|
421
|
+
stale = true;
|
|
422
|
+
if (state.mode === 'sections')
|
|
423
|
+
state = { ...state, stale };
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
state = { mode: 'error', errorMessage: t().docs.loadError };
|
|
427
|
+
}
|
|
411
428
|
}
|
|
412
429
|
if (isLifecycleActive(ctx, generation))
|
|
413
430
|
ctx.rerender();
|
|
@@ -501,9 +518,9 @@ export const docsView = {
|
|
|
501
518
|
const hasLinks = (state.readerLinks?.length ?? 0) > 0;
|
|
502
519
|
const linkHint = hasLinks ? `f ${trans.docs.readerLinksHint} ${dot} ` : '';
|
|
503
520
|
const pageHint = `${glyph.updown()} PgUp/PgDn ${dot} `;
|
|
504
|
-
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}`;
|
|
505
522
|
const localCompact = `${pageHint}${hasLinks ? `f ${dot} ` : ''}b ${dot} Esc ${dot} q`;
|
|
506
|
-
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');
|
|
507
524
|
}
|
|
508
525
|
return undefined;
|
|
509
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,71 +4,79 @@ 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
|
-
{ value: 'upcoming', label: trans.
|
|
23
|
+
{ value: 'upcoming', label: trans.calendar.next30Days },
|
|
22
24
|
{ value: 'week', label: trans.calendar.thisWeek },
|
|
23
25
|
{ value: 'month', label: trans.calendar.thisMonth },
|
|
24
26
|
{ value: 'search', label: trans.calendar.search },
|
|
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.
|
|
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';
|
|
@@ -50,65 +50,57 @@ function renderWeekAheadGrid(classDays, eventDays, cols) {
|
|
|
50
50
|
const blankCell = ' ';
|
|
51
51
|
const rowLabelW = Math.max(visualWidth(trans.timetable.weekAheadClasses), visualWidth(trans.menu.events)) + 1;
|
|
52
52
|
const days = [1, 2, 3, 4, 5, 6, 7];
|
|
53
|
+
const classCell = (wd) => classDays[wd - 1] ? hasClassChar : wd >= 6 ? weekendChar : freeChar;
|
|
54
|
+
const eventCell = (wd) => eventDays ? (eventDays[wd - 1] ? hasClassChar : freeChar) : blankCell;
|
|
55
|
+
const legendText = `${hasClassChar} ${trans.timetable.weekAheadBusy} ${freeChar} ${trans.timetable.weekAheadFree} ${weekendChar} ${trans.timetable.weekAheadNone}`;
|
|
53
56
|
const dayLabels = days.map((wd) => type.hint(weekdayShortLabel(wd))).join(' ');
|
|
54
57
|
const headerLine = `${space.indent}${padEndV('', rowLabelW)}${dayLabels}`;
|
|
55
|
-
const classCells = days
|
|
56
|
-
.map((wd) => {
|
|
57
|
-
const isWeekend = wd === 6 || wd === 7;
|
|
58
|
-
const glyphChar = isWeekend ? weekendChar : classDays[wd - 1] ? hasClassChar : freeChar;
|
|
59
|
-
return type.body(glyphChar);
|
|
60
|
-
})
|
|
61
|
-
.join(' ');
|
|
58
|
+
const classCells = days.map((wd) => type.body(classCell(wd))).join(' ');
|
|
62
59
|
const classLine = `${space.indent}${type.hint(padEndV(trans.timetable.weekAheadClasses, rowLabelW))}${classCells}`;
|
|
63
|
-
const eventCells = days
|
|
64
|
-
.map((wd) => {
|
|
65
|
-
if (!eventDays)
|
|
66
|
-
return blankCell;
|
|
67
|
-
return type.body(eventDays[wd - 1] ? hasClassChar : freeChar);
|
|
68
|
-
})
|
|
69
|
-
.join(' ');
|
|
60
|
+
const eventCells = days.map((wd) => type.body(eventCell(wd))).join(' ');
|
|
70
61
|
const eventLine = `${space.indent}${type.hint(padEndV(trans.menu.events, rowLabelW))}${eventCells}`;
|
|
71
|
-
const legend = `${space.indent}${type.hint(
|
|
62
|
+
const legend = `${space.indent}${type.hint(legendText)}`;
|
|
72
63
|
const wideLines = [headerLine, classLine, eventLine, legend];
|
|
73
64
|
const width = Number.isFinite(cols) ? Math.max(1, Math.floor(cols)) : Number.POSITIVE_INFINITY;
|
|
74
65
|
if (wideLines.every((line) => visualWidth(line) <= width))
|
|
75
66
|
return wideLines.join('\n');
|
|
76
67
|
const compactHeading = wrappedIndentedLines(`${trans.timetable.weekAheadClasses} / ${trans.menu.events}`, cols, type.hint);
|
|
77
68
|
const compactDays = days.flatMap((wd) => {
|
|
78
|
-
const
|
|
79
|
-
const eventCell = eventDays ? (eventDays[wd - 1] ? hasClassChar : freeChar) : blankCell;
|
|
80
|
-
const row = `${type.hint(weekdayShortLabel(wd))} ${type.body(classCell)} ${type.body(eventCell)}`;
|
|
69
|
+
const row = `${type.hint(weekdayShortLabel(wd))} ${type.body(classCell(wd))} ${type.body(eventCell(wd))}`;
|
|
81
70
|
return wrappedIndentedLines(row, cols, (value) => value);
|
|
82
71
|
});
|
|
83
|
-
const compactLegend = wrappedIndentedLines(
|
|
72
|
+
const compactLegend = wrappedIndentedLines(legendText, cols, type.hint);
|
|
84
73
|
return [...compactHeading, ...compactDays, ...compactLegend].join('\n');
|
|
85
74
|
}
|
|
86
75
|
export function renderHome(data, now, bodyRows = 100, cols = 80) {
|
|
87
76
|
const trans = t();
|
|
88
77
|
const lines = [];
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
lines.push(renderDayProgress(now, cols));
|
|
97
|
-
if (data.todayLines && data.todayLines.length > 0) {
|
|
98
|
-
for (const line of data.todayLines)
|
|
99
|
-
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('');
|
|
100
85
|
}
|
|
101
|
-
else {
|
|
102
|
-
|
|
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('');
|
|
103
95
|
}
|
|
104
|
-
lines.push('');
|
|
105
96
|
if (data.weekAhead) {
|
|
106
97
|
lines.push(...panelHeading(trans.timetable.weekOverviewTitle, cols));
|
|
107
98
|
lines.push(...renderWeekAheadGrid(data.weekAhead.classDays, data.weekAhead.eventDays, cols).split('\n'));
|
|
108
99
|
lines.push('');
|
|
109
100
|
}
|
|
110
|
-
|
|
111
|
-
|
|
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));
|
|
112
104
|
lines.push('');
|
|
113
105
|
}
|
|
114
106
|
const eventsStale = data.eventsLoadFailed === true && (data.eventLines?.length ?? 0) > 0;
|
|
@@ -143,14 +135,14 @@ export function renderHome(data, now, bodyRows = 100, cols = 80) {
|
|
|
143
135
|
return lines;
|
|
144
136
|
}
|
|
145
137
|
const HOME_EVENT_FETCH_CAP = 15;
|
|
146
|
-
function calendarSnapshot(cal,
|
|
138
|
+
function calendarSnapshot(cal, weekAhead) {
|
|
147
139
|
const now = new Date();
|
|
148
140
|
const eventLines = currentEvents(cal, now)
|
|
149
141
|
.slice(0, HOME_EVENT_FETCH_CAP)
|
|
150
142
|
.map((event) => renderEventBrief(toDisplayEvent(event), now));
|
|
151
|
-
if (!
|
|
143
|
+
if (!weekAhead)
|
|
152
144
|
return { eventLines };
|
|
153
|
-
const { weekStart } =
|
|
145
|
+
const { weekStart } = weekAhead;
|
|
154
146
|
const monday = campusDateTime(weekStart, '00:00');
|
|
155
147
|
const daySet = new Set(cal
|
|
156
148
|
.inRange(new Date(monday.getTime() - DAY_MS), new Date(monday.getTime() + 8 * DAY_MS))
|
|
@@ -161,7 +153,7 @@ function calendarSnapshot(cal, weekAheadInfo) {
|
|
|
161
153
|
return {
|
|
162
154
|
eventLines,
|
|
163
155
|
weekAhead: {
|
|
164
|
-
classDays:
|
|
156
|
+
classDays: weekAhead.classDays,
|
|
165
157
|
eventDays: WEEKDAYS.map((weekday) => daySet.has(weekday)),
|
|
166
158
|
},
|
|
167
159
|
};
|
|
@@ -176,22 +168,16 @@ export const homeView = {
|
|
|
176
168
|
async load(ctx) {
|
|
177
169
|
if (ctx.signal?.aborted)
|
|
178
170
|
return;
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
...(weekAheadInfo ? { weekAhead: { classDays: weekAheadInfo.classDays } } : {}),
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
catch {
|
|
190
|
-
data = { loading: true };
|
|
191
|
-
}
|
|
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
|
+
};
|
|
192
178
|
const cached = peekCalendar();
|
|
193
179
|
if (cached)
|
|
194
|
-
data = { ...data, ...calendarSnapshot(cached,
|
|
180
|
+
data = { ...data, ...calendarSnapshot(cached, weekAhead) };
|
|
195
181
|
if (ctx.signal?.aborted)
|
|
196
182
|
return;
|
|
197
183
|
ctx.rerender();
|
|
@@ -199,7 +185,7 @@ export const homeView = {
|
|
|
199
185
|
const cal = await loadCalendarOrThrow(ctx.signal);
|
|
200
186
|
if (ctx.signal?.aborted)
|
|
201
187
|
return;
|
|
202
|
-
data = { ...data, ...calendarSnapshot(cal,
|
|
188
|
+
data = { ...data, ...calendarSnapshot(cal, weekAhead) };
|
|
203
189
|
}
|
|
204
190
|
catch {
|
|
205
191
|
if (ctx.signal?.aborted)
|