@nbtca/prompt 1.5.14 → 1.5.16
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/app.js +10 -5
- package/dist/app/chrome.js +16 -13
- package/dist/app/fields/list-field.js +7 -7
- package/dist/app/frame.js +11 -4
- package/dist/app/views/docs-render.js +7 -4
- package/dist/app/views/docs.js +35 -17
- package/dist/app/views/events-render.js +23 -9
- package/dist/app/views/events.js +52 -43
- package/dist/app/views/home.js +38 -43
- 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/cli.js +1 -1
- 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 +26 -11
- package/dist/features/calendar-query.js +39 -9
- package/dist/features/calendar-store.js +36 -4
- package/dist/features/calendar.js +47 -31
- package/dist/features/docs-client.js +12 -1
- package/dist/features/docs.js +25 -3
- 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 +35 -15
- package/dist/i18n/locales/zh.json +33 -13
- package/package.json +3 -7
package/dist/app/app.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ansi, ensureCursorRestored } from '../core/canvas.js';
|
|
2
|
-
import { composeFrameLines, computeBodyRows, diffFrame } from './frame.js';
|
|
2
|
+
import { composeFrameLines, computeBodyRows, diffFrame, frameWidth } from './frame.js';
|
|
3
3
|
import { isPrintableKey, KeyStreamDecoder, routeGlobalKey } from './keys.js';
|
|
4
4
|
import { renderHeader, renderFooter, resolveChromeLayout } from './chrome.js';
|
|
5
5
|
import { homeView } from './views/home.js';
|
|
@@ -46,9 +46,13 @@ export async function runApp() {
|
|
|
46
46
|
.finally(() => pendingLoads.delete(id));
|
|
47
47
|
pendingLoads.set(id, pending);
|
|
48
48
|
}
|
|
49
|
-
function
|
|
49
|
+
function terminalSize() {
|
|
50
50
|
return { rows: process.stdout.rows || 24, cols: process.stdout.columns || 80 };
|
|
51
51
|
}
|
|
52
|
+
function size() {
|
|
53
|
+
const terminal = terminalSize();
|
|
54
|
+
return { rows: terminal.rows, cols: frameWidth(terminal.cols) };
|
|
55
|
+
}
|
|
52
56
|
const ctx = {
|
|
53
57
|
signal: lifecycle.signal,
|
|
54
58
|
get size() {
|
|
@@ -76,6 +80,7 @@ export async function runApp() {
|
|
|
76
80
|
if (suspended || !running)
|
|
77
81
|
return;
|
|
78
82
|
const { rows, cols } = size();
|
|
83
|
+
const terminalCols = terminalSize().cols;
|
|
79
84
|
const active = nativeViews[view];
|
|
80
85
|
const tabs = getAppTabs();
|
|
81
86
|
const chrome = resolveChromeLayout(rows);
|
|
@@ -88,9 +93,9 @@ export async function runApp() {
|
|
|
88
93
|
const height = computeBodyRows(rows, chrome.headerLines, chrome.footerLines);
|
|
89
94
|
lastBody = { length: body.length, height };
|
|
90
95
|
const footer = renderFooter(view, cols, tabs.length, helpOpen ? t().help.close : active?.footerHint?.(tabs.length, cols), chrome.footerLines, !helpOpen && active?.scrollsBody?.() === true ? scrollPercent() : undefined);
|
|
91
|
-
const lines = composeFrameLines(header, body, footer, rows,
|
|
92
|
-
const patch = diffFrame(painted?.cols ===
|
|
93
|
-
painted = { cols, lines };
|
|
96
|
+
const lines = composeFrameLines(header, body, footer, rows, terminalCols, bodyScroll);
|
|
97
|
+
const patch = diffFrame(painted?.cols === terminalCols ? painted.lines : undefined, lines);
|
|
98
|
+
painted = { cols: terminalCols, lines };
|
|
94
99
|
if (patch)
|
|
95
100
|
process.stdout.write(patch);
|
|
96
101
|
scheduleBusyTick(active?.isBusy?.() === true);
|
package/dist/app/chrome.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type, space, glyph, brandMark
|
|
1
|
+
import { c, type, space, glyph, brandMark } from '../core/theme.js';
|
|
2
2
|
import { pickIcon } from '../core/icons.js';
|
|
3
3
|
import { t } from '../i18n/index.js';
|
|
4
|
-
import { clipAnsiToVisualWidth, visualWidth } from '../core/text.js';
|
|
4
|
+
import { clipAnsiToVisualWidth, visualWidth, wrapAnsiWithIndent } from '../core/text.js';
|
|
5
5
|
export const HEADER_LINES = 3;
|
|
6
6
|
export const FOOTER_LINES = 2;
|
|
7
7
|
export function resolveChromeLayout(rows) {
|
|
@@ -19,8 +19,7 @@ export function resolveChromeLayout(rows) {
|
|
|
19
19
|
return { headerLines: 0, footerLines: 0 };
|
|
20
20
|
}
|
|
21
21
|
function renderRule(cols) {
|
|
22
|
-
const
|
|
23
|
-
const width = Math.min(terminal, MAX_FRAME_COLS);
|
|
22
|
+
const width = Number.isFinite(cols) ? Math.max(1, Math.floor(cols)) : 80;
|
|
24
23
|
const indent = visualWidth(space.indent) < width ? space.indent : '';
|
|
25
24
|
const ruleWidth = Math.max(1, width - visualWidth(indent) * 2);
|
|
26
25
|
return indent + type.hint(glyph.rule().repeat(ruleWidth));
|
|
@@ -29,7 +28,7 @@ function renderTabs(views, active, cols) {
|
|
|
29
28
|
const dot = pickIcon('·', '-');
|
|
30
29
|
const full = space.indent +
|
|
31
30
|
views
|
|
32
|
-
.map((view) =>
|
|
31
|
+
.map((view) => view.id === active ? type.active(`[${view.title}]`) : type.hint(` ${view.title} `))
|
|
33
32
|
.join(` ${dot} `);
|
|
34
33
|
if (visualWidth(full) <= cols)
|
|
35
34
|
return full;
|
|
@@ -94,6 +93,10 @@ export function renderHeader(views, active, cols, lineCount = HEADER_LINES, cont
|
|
|
94
93
|
return [brand, tabs];
|
|
95
94
|
return [brand, tabs, rule];
|
|
96
95
|
}
|
|
96
|
+
export function offlineNotice(cols) {
|
|
97
|
+
const notice = `${c.warn(pickIcon('⚠', '!'))} ${t().common.offline}`;
|
|
98
|
+
return [...wrapAnsiWithIndent(notice, cols, space.indent), ''];
|
|
99
|
+
}
|
|
97
100
|
export function fitFooterHint(cols, ...candidates) {
|
|
98
101
|
return (candidates.find((candidate) => visualWidth(space.indent + candidate) <= cols) ??
|
|
99
102
|
candidates[candidates.length - 1] ??
|
|
@@ -102,28 +105,29 @@ export function fitFooterHint(cols, ...candidates) {
|
|
|
102
105
|
export function captureFooterHint(cols = Number.POSITIVE_INFINITY) {
|
|
103
106
|
const trans = t();
|
|
104
107
|
const dot = pickIcon('·', '-');
|
|
105
|
-
return fitFooterHint(cols, `Ctrl+C ${trans.common.exit}
|
|
108
|
+
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
109
|
}
|
|
107
110
|
export function digitTabHint(tabCount) {
|
|
108
111
|
const dot = pickIcon('·', '-');
|
|
109
|
-
return tabCount > 1 ? `1-${tabCount} / Tab ${dot} ` : '';
|
|
112
|
+
return tabCount > 1 ? `1-${tabCount} / Tab ${t().menu.hintTabs} ${dot} ` : '';
|
|
110
113
|
}
|
|
111
114
|
export function passiveFooterHint(tabCount, cols = Number.POSITIVE_INFINITY) {
|
|
112
115
|
const trans = t();
|
|
113
116
|
const dot = pickIcon('·', '-');
|
|
114
117
|
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');
|
|
118
|
+
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
119
|
}
|
|
117
120
|
function interactiveFooterHint(tabCount, cols) {
|
|
118
121
|
const trans = t();
|
|
119
122
|
const dot = pickIcon('·', '-');
|
|
120
123
|
const fullTabs = digitTabHint(tabCount);
|
|
121
124
|
const compactTabs = tabCount > 1 ? `1-${tabCount}/Tab ${dot} ` : '';
|
|
125
|
+
const localLabelled = `${trans.menu.hintMove} ${dot} ${trans.menu.hintOpen} ${dot} Esc ${trans.menu.hintBack} ${dot} q ${trans.menu.hintQuit}`;
|
|
122
126
|
const localFull = `${trans.menu.hintMove} ${dot} ${trans.menu.hintOpen} ${dot} Esc ${dot} q ${trans.menu.hintQuit}`;
|
|
123
127
|
const localCompact = `${trans.menu.hintMove} ${trans.menu.hintOpen} Esc q`;
|
|
124
128
|
const candidates = [
|
|
125
|
-
`${fullTabs}${
|
|
126
|
-
`${fullTabs}${
|
|
129
|
+
`${fullTabs}${localLabelled} ${dot} ${trans.help.hint}`,
|
|
130
|
+
`${fullTabs}${localLabelled}`,
|
|
127
131
|
`${compactTabs}${localFull}`,
|
|
128
132
|
localFull,
|
|
129
133
|
`${compactTabs}${localCompact}`,
|
|
@@ -148,9 +152,8 @@ export function renderFooter(_active, cols, tabCount, overrideHint, lineCount =
|
|
|
148
152
|
function withPosition(hint, hintText, indent, position, cols) {
|
|
149
153
|
if (position === undefined)
|
|
150
154
|
return hint;
|
|
151
|
-
const
|
|
152
|
-
const
|
|
153
|
-
const gap = frame - visualWidth(indent + hintText) - visualWidth(position) - visualWidth(margin);
|
|
155
|
+
const margin = visualWidth(space.indent) < cols ? space.indent : '';
|
|
156
|
+
const gap = cols - visualWidth(indent + hintText) - visualWidth(position) - visualWidth(margin);
|
|
154
157
|
if (gap < 2)
|
|
155
158
|
return hint;
|
|
156
159
|
return hint + ' '.repeat(gap) + type.hint(position) + margin;
|
|
@@ -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/frame.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ansi } from '../core/canvas.js';
|
|
2
|
+
import { MAX_FRAME_COLS } from '../core/theme.js';
|
|
2
3
|
import { clipAnsiToVisualWidth, visualWidth } from '../core/text.js';
|
|
3
4
|
export function clipToWidth(line, cols) {
|
|
4
5
|
if (visualWidth(line) <= cols)
|
|
@@ -18,12 +19,18 @@ export function fitBody(lines, height, scroll, cols) {
|
|
|
18
19
|
out.push(' '.repeat(cols));
|
|
19
20
|
return out;
|
|
20
21
|
}
|
|
22
|
+
export function frameWidth(cols) {
|
|
23
|
+
return Math.min(cols, MAX_FRAME_COLS);
|
|
24
|
+
}
|
|
21
25
|
export function composeFrameLines(header, body, footer, rows, cols, scroll) {
|
|
22
|
-
const
|
|
23
|
-
const
|
|
26
|
+
const width = frameWidth(cols);
|
|
27
|
+
const left = ' '.repeat(Math.floor((cols - width) / 2));
|
|
28
|
+
const right = ' '.repeat(cols - width - left.length);
|
|
29
|
+
const h = header.map((l) => fitLine(l, width));
|
|
30
|
+
const f = footer.map((l) => fitLine(l, width));
|
|
24
31
|
const bodyH = Math.max(0, rows - h.length - f.length);
|
|
25
|
-
const b = fitBody(body, bodyH, scroll,
|
|
26
|
-
return [...h, ...b, ...f].slice(0, rows);
|
|
32
|
+
const b = fitBody(body, bodyH, scroll, width);
|
|
33
|
+
return [...h, ...b, ...f].slice(0, rows).map((line) => left + line + right);
|
|
27
34
|
}
|
|
28
35
|
export function diffFrame(prev, next) {
|
|
29
36
|
if (prev?.length !== next.length)
|
|
@@ -1,6 +1,7 @@
|
|
|
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 { offlineNotice } from '../chrome.js';
|
|
4
5
|
import { visualWidth, wrapAnsiWithIndent } from '../../core/text.js';
|
|
5
6
|
import { loadingLines } from '../../core/components/spinner.js';
|
|
6
7
|
function hintLines(label, cols) {
|
|
@@ -41,23 +42,25 @@ export function renderDocs(state, cols = 80, bodyRows = Number.POSITIVE_INFINITY
|
|
|
41
42
|
break;
|
|
42
43
|
case 'sections':
|
|
43
44
|
lines = state.sectionsField
|
|
44
|
-
? renderListFieldWithContext(state.stale ?
|
|
45
|
+
? renderListFieldWithContext(state.stale ? offlineNotice(cols) : [], state.sectionsField, bodyRows, cols)
|
|
45
46
|
: [];
|
|
46
47
|
break;
|
|
47
48
|
case 'files':
|
|
48
|
-
lines = state.filesField?.render(bodyRows, cols) ??
|
|
49
|
+
lines = state.filesField?.render(bodyRows, cols) ?? loadingLines(trans.common.loading, cols);
|
|
49
50
|
break;
|
|
50
51
|
case 'archivedGroups':
|
|
51
52
|
lines = state.archivedGroupsField?.render(bodyRows, cols) ?? [];
|
|
52
53
|
break;
|
|
53
54
|
case 'archivedFiles':
|
|
54
|
-
lines =
|
|
55
|
+
lines =
|
|
56
|
+
state.archivedFilesField?.render(bodyRows, cols) ??
|
|
57
|
+
loadingLines(trans.common.loading, cols);
|
|
55
58
|
break;
|
|
56
59
|
case 'search':
|
|
57
60
|
lines = state.searchField?.render(cols) ?? [];
|
|
58
61
|
break;
|
|
59
62
|
case 'searchLoading':
|
|
60
|
-
lines =
|
|
63
|
+
lines = loadingLines(trans.docs.searching, cols);
|
|
61
64
|
break;
|
|
62
65
|
case 'searchResults':
|
|
63
66
|
lines = state.searchResultsField
|
package/dist/app/views/docs.js
CHANGED
|
@@ -7,7 +7,7 @@ import { pickIcon } from '../../core/icons.js';
|
|
|
7
7
|
import { glyph } from '../../core/theme.js';
|
|
8
8
|
import { fmt, getCurrentLanguage, t } from '../../i18n/index.js';
|
|
9
9
|
import { sanitizeTerminalLine, truncate } from '../../core/text.js';
|
|
10
|
-
import { localizeDocSections, fetchSections, peekSections, fetchDocMetadata, fetchSectionMetadata, searchDocuments, getArchivedGroups, displayDocTitle, loadDocForReader, openDocsInBrowser, docsUrlFromPath, clearDocsCache, } from '../../features/docs.js';
|
|
10
|
+
import { localizeDocSections, fetchSections, peekSections, fetchDocMetadata, fetchSectionMetadata, peekListedDocs, searchDocuments, getArchivedGroups, displayDocTitle, loadDocForReader, openDocsInBrowser, docsUrlFromPath, clearDocsCache, } from '../../features/docs.js';
|
|
11
11
|
let state = { mode: 'loading' };
|
|
12
12
|
let sections = [];
|
|
13
13
|
let archivedGroups = new Map();
|
|
@@ -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();
|
|
@@ -172,12 +177,12 @@ function relocalizeStateFields(value, maxVisible) {
|
|
|
172
177
|
if (value.mode === 'sections') {
|
|
173
178
|
return { ...value, sectionsField: buildSectionsField() };
|
|
174
179
|
}
|
|
175
|
-
if (value.mode === 'files' && currentSectionKey) {
|
|
180
|
+
if (value.mode === 'files' && value.filesField && currentSectionKey) {
|
|
176
181
|
const section = sections.find((candidate) => candidate.key === currentSectionKey);
|
|
177
182
|
return section
|
|
178
183
|
? {
|
|
179
184
|
...value,
|
|
180
|
-
filesField: buildFilesField(section, maxVisible, value.filesField
|
|
185
|
+
filesField: buildFilesField(section, maxVisible, value.filesField.selectedIndex),
|
|
181
186
|
}
|
|
182
187
|
: value;
|
|
183
188
|
}
|
|
@@ -187,10 +192,10 @@ function relocalizeStateFields(value, maxVisible) {
|
|
|
187
192
|
archivedGroupsField: buildArchivedGroupsField(archivedGroups, maxVisible, value.archivedGroupsField?.selectedIndex),
|
|
188
193
|
};
|
|
189
194
|
}
|
|
190
|
-
if (value.mode === 'archivedFiles' && currentArchivedGroupKey) {
|
|
195
|
+
if (value.mode === 'archivedFiles' && value.archivedFilesField && currentArchivedGroupKey) {
|
|
191
196
|
return {
|
|
192
197
|
...value,
|
|
193
|
-
archivedFilesField: buildArchivedFilesField(currentArchivedGroupKey, archivedGroups.get(currentArchivedGroupKey) ?? [], maxVisible, value.archivedFilesField
|
|
198
|
+
archivedFilesField: buildArchivedFilesField(currentArchivedGroupKey, archivedGroups.get(currentArchivedGroupKey) ?? [], maxVisible, value.archivedFilesField.selectedIndex),
|
|
194
199
|
};
|
|
195
200
|
}
|
|
196
201
|
if (value.mode === 'searchResults') {
|
|
@@ -222,10 +227,13 @@ async function openSectionFiles(ctx, section) {
|
|
|
222
227
|
return;
|
|
223
228
|
const requestId = ++metadataRequestId;
|
|
224
229
|
currentSectionKey = section.key;
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
230
|
+
const stored = peekListedDocs(section.files);
|
|
231
|
+
const known = { ...section, files: stored.docs };
|
|
232
|
+
state = { mode: 'files', filesField: buildFilesField(known, computeMaxVisible(ctx.bodyRows)) };
|
|
233
|
+
if (stored.complete) {
|
|
234
|
+
replaceSection(known);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
229
237
|
ctx.rerender();
|
|
230
238
|
try {
|
|
231
239
|
const hydrated = await fetchSectionMetadata(section, ctx.signal);
|
|
@@ -247,7 +255,11 @@ async function openSectionFiles(ctx, section) {
|
|
|
247
255
|
state.mode !== 'files' ||
|
|
248
256
|
currentSectionKey !== section.key)
|
|
249
257
|
return;
|
|
250
|
-
state = {
|
|
258
|
+
state = {
|
|
259
|
+
mode: 'files',
|
|
260
|
+
filesField: buildFilesField(section, computeMaxVisible(ctx.bodyRows)),
|
|
261
|
+
errorMessage: t().docs.loadError,
|
|
262
|
+
};
|
|
251
263
|
}
|
|
252
264
|
if (isLifecycleActive(ctx, generation))
|
|
253
265
|
ctx.rerender();
|
|
@@ -258,10 +270,15 @@ async function openArchivedFiles(ctx, groupKey, groupFiles) {
|
|
|
258
270
|
return;
|
|
259
271
|
const requestId = ++metadataRequestId;
|
|
260
272
|
currentArchivedGroupKey = groupKey;
|
|
273
|
+
const stored = peekListedDocs(groupFiles);
|
|
261
274
|
state = {
|
|
262
275
|
mode: 'archivedFiles',
|
|
263
|
-
archivedFilesField: buildArchivedFilesField(groupKey,
|
|
276
|
+
archivedFilesField: buildArchivedFilesField(groupKey, stored.docs, computeMaxVisible(ctx.bodyRows)),
|
|
264
277
|
};
|
|
278
|
+
if (stored.complete) {
|
|
279
|
+
archivedGroups.set(groupKey, stored.docs);
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
265
282
|
ctx.rerender();
|
|
266
283
|
try {
|
|
267
284
|
const hydrated = await fetchDocMetadata(groupFiles, ctx.signal);
|
|
@@ -283,7 +300,8 @@ async function openArchivedFiles(ctx, groupKey, groupFiles) {
|
|
|
283
300
|
currentArchivedGroupKey !== groupKey)
|
|
284
301
|
return;
|
|
285
302
|
state = {
|
|
286
|
-
|
|
303
|
+
mode: 'archivedFiles',
|
|
304
|
+
archivedFilesField: buildArchivedFilesField(groupKey, groupFiles, computeMaxVisible(ctx.bodyRows)),
|
|
287
305
|
errorMessage: t().docs.loadError,
|
|
288
306
|
};
|
|
289
307
|
}
|
|
@@ -513,9 +531,9 @@ export const docsView = {
|
|
|
513
531
|
const hasLinks = (state.readerLinks?.length ?? 0) > 0;
|
|
514
532
|
const linkHint = hasLinks ? `f ${trans.docs.readerLinksHint} ${dot} ` : '';
|
|
515
533
|
const pageHint = `${glyph.updown()} PgUp/PgDn ${dot} `;
|
|
516
|
-
const localFull = `${pageHint}${linkHint}b ${trans.docs.openBrowser} ${dot} Esc ${dot} q ${trans.menu.hintQuit}`;
|
|
534
|
+
const localFull = `${pageHint}${linkHint}b ${trans.docs.openBrowser} ${dot} Esc ${trans.menu.hintBack} ${dot} q ${trans.menu.hintQuit}`;
|
|
517
535
|
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');
|
|
536
|
+
return fitFooterHint(cols, `${digitTabHint(tabCount)}${localFull} ${dot} ${trans.help.hint}`, `${digitTabHint(tabCount)}${localFull}`, localFull, localCompact, `${hasLinks ? 'f ' : ''}b Esc q`, 'Esc q', 'q');
|
|
519
537
|
}
|
|
520
538
|
return undefined;
|
|
521
539
|
},
|
|
@@ -1,17 +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 {
|
|
4
|
+
import { offlineNotice } from '../chrome.js';
|
|
5
|
+
import { renderCountdownBanner, renderEventBriefLines, } from '../../features/calendar.js';
|
|
5
6
|
import { renderHeatmap } from '../../features/calendar-heatmap.js';
|
|
6
7
|
import { wrapAnsiWithIndent } from '../../core/text.js';
|
|
7
8
|
import { loadingLines } from '../../core/components/spinner.js';
|
|
8
9
|
function wrappedIndentedLines(label, cols, style) {
|
|
9
10
|
return wrapAnsiWithIndent(style(label), cols ?? Number.POSITIVE_INFINITY, space.indent);
|
|
10
11
|
}
|
|
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
12
|
const EXPANDED_HUB_MIN_BODY_ROWS = 29;
|
|
16
13
|
function renderHubBody(state, now, bodyRows, cols) {
|
|
17
14
|
const trans = t();
|
|
@@ -20,7 +17,7 @@ function renderHubBody(state, now, bodyRows, cols) {
|
|
|
20
17
|
? Math.max(0, Math.floor(bodyRows))
|
|
21
18
|
: Number.POSITIVE_INFINITY;
|
|
22
19
|
if (state.stale)
|
|
23
|
-
lines.push(...
|
|
20
|
+
lines.push(...offlineNotice(cols ?? Number.POSITIVE_INFINITY));
|
|
24
21
|
const banner = renderCountdownBanner(state.nextEvent, now, cols);
|
|
25
22
|
if (banner)
|
|
26
23
|
lines.push(...banner.split('\n'), '');
|
|
@@ -41,7 +38,7 @@ function renderHubBody(state, now, bodyRows, cols) {
|
|
|
41
38
|
const budget = Math.max(0, rows - lines.length - activityHeading.length - 1 - reservedFieldRows);
|
|
42
39
|
const collected = [];
|
|
43
40
|
for (const event of state.recentEvents ?? []) {
|
|
44
|
-
const wrapped =
|
|
41
|
+
const wrapped = renderEventBriefLines(event, now, cols);
|
|
45
42
|
if (collected.length + wrapped.length > budget)
|
|
46
43
|
break;
|
|
47
44
|
collected.push(...wrapped);
|
|
@@ -55,6 +52,12 @@ function renderHubBody(state, now, bodyRows, cols) {
|
|
|
55
52
|
if (eventLines.length > 0)
|
|
56
53
|
lines.push(...activityHeading, ...eventLines, '');
|
|
57
54
|
}
|
|
55
|
+
else if (!state.nextEvent) {
|
|
56
|
+
const notice = [...wrappedIndentedLines(trans.calendar.noEvents, cols, type.hint), ''];
|
|
57
|
+
const fieldRows = state.hubField?.render(Number.POSITIVE_INFINITY, cols).length ?? 0;
|
|
58
|
+
if (lines.length + notice.length + fieldRows <= rows)
|
|
59
|
+
lines.push(...notice);
|
|
60
|
+
}
|
|
58
61
|
if (state.hubField) {
|
|
59
62
|
return renderListFieldWithContext(lines, state.hubField, bodyRows, cols);
|
|
60
63
|
}
|
|
@@ -74,8 +77,19 @@ export function renderEvents(state, now, bodyRows = 100, cols) {
|
|
|
74
77
|
...(cols === undefined ? {} : { cols }),
|
|
75
78
|
}).split('\n')
|
|
76
79
|
: wrappedIndentedLines(trans.calendar.noEvents, cols, type.hint);
|
|
77
|
-
case 'list':
|
|
78
|
-
|
|
80
|
+
case 'list': {
|
|
81
|
+
if (!state.listField)
|
|
82
|
+
return [];
|
|
83
|
+
if (state.listNotice === undefined)
|
|
84
|
+
return state.listField.render(bodyRows, cols);
|
|
85
|
+
const context = [
|
|
86
|
+
...wrappedIndentedLines(state.listTitle ?? '', cols, type.heading),
|
|
87
|
+
'',
|
|
88
|
+
...wrappedIndentedLines(state.listNotice, cols, type.hint),
|
|
89
|
+
'',
|
|
90
|
+
];
|
|
91
|
+
return renderListFieldWithContext(context, state.listField, bodyRows, cols);
|
|
92
|
+
}
|
|
79
93
|
case 'detail': {
|
|
80
94
|
const context = [
|
|
81
95
|
...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
|
}
|