@nbtca/prompt 1.5.15 → 1.5.17
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 +36 -32
- package/dist/app/chrome.js +25 -30
- package/dist/app/fields/list-field.js +2 -2
- package/dist/app/frame.js +8 -4
- package/dist/app/help.js +2 -2
- package/dist/app/views/docs-render.js +29 -10
- package/dist/app/views/docs.js +153 -88
- package/dist/app/views/events-render.js +44 -25
- package/dist/app/views/events.js +50 -18
- package/dist/app/views/home.js +5 -7
- package/dist/app/views/schedule-render.js +70 -27
- package/dist/app/views/schedule.js +5 -2
- package/dist/app/views/settings-render.js +1 -0
- package/dist/app/views/settings.js +37 -12
- package/dist/cli.js +1 -1
- package/dist/core/components/menu.js +7 -4
- package/dist/core/logo.js +23 -5
- package/dist/core/text.js +6 -14
- package/dist/core/theme.js +11 -2
- package/dist/features/about.js +2 -2
- package/dist/features/calendar-heatmap.js +49 -59
- package/dist/features/calendar-query.js +1 -1
- package/dist/features/calendar-store.js +36 -4
- package/dist/features/calendar.js +39 -11
- package/dist/features/docs-client.js +16 -3
- package/dist/features/docs-markdown.js +16 -24
- package/dist/features/docs.js +64 -19
- package/dist/features/schedule-render.js +160 -139
- package/dist/features/status.js +5 -1
- package/dist/i18n/locales/en.json +30 -13
- package/dist/i18n/locales/zh.json +23 -6
- package/package.json +3 -3
package/dist/app/views/docs.js
CHANGED
|
@@ -6,8 +6,9 @@ import { setVimKeysActive } from '../../core/vim-keys.js';
|
|
|
6
6
|
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
|
-
import { sanitizeTerminalLine
|
|
10
|
-
import { localizeDocSections, fetchSections, peekSections, fetchDocMetadata, fetchSectionMetadata, searchDocuments, getArchivedGroups, displayDocTitle, loadDocForReader, openDocsInBrowser, docsUrlFromPath, clearDocsCache, } from '../../features/docs.js';
|
|
9
|
+
import { sanitizeTerminalLine } from '../../core/text.js';
|
|
10
|
+
import { localizeDocSections, fetchSections, peekSections, fetchDocMetadata, fetchSectionMetadata, peekListedDocs, searchDocuments, getArchivedGroups, displayDocTitle, loadDocForReader, openDocsInBrowser, docsUrlFromPath, clearDocsCache, withFileNameTitle, } from '../../features/docs.js';
|
|
11
|
+
import { launchBrowserUrl } from '../../features/links.js';
|
|
11
12
|
let state = { mode: 'loading' };
|
|
12
13
|
let sections = [];
|
|
13
14
|
let archivedGroups = new Map();
|
|
@@ -17,6 +18,7 @@ let loadedLanguage = null;
|
|
|
17
18
|
let currentSectionKey = null;
|
|
18
19
|
let currentArchivedGroupKey = null;
|
|
19
20
|
let currentSearchResults = [];
|
|
21
|
+
let currentSearchQuery = '';
|
|
20
22
|
let sectionsRequestId = 0;
|
|
21
23
|
let metadataRequestId = 0;
|
|
22
24
|
let searchRequestId = 0;
|
|
@@ -26,7 +28,6 @@ let readerPrevState = null;
|
|
|
26
28
|
let readerLoadingPrevState = null;
|
|
27
29
|
let readerRequestId = 0;
|
|
28
30
|
let lifecycleGeneration = 0;
|
|
29
|
-
const DOC_HINT_WIDTH = 44;
|
|
30
31
|
function isLifecycleActive(ctx, generation) {
|
|
31
32
|
return generation === lifecycleGeneration && ctx.signal?.aborted !== true;
|
|
32
33
|
}
|
|
@@ -40,10 +41,10 @@ function backLabel() {
|
|
|
40
41
|
return t().common.back;
|
|
41
42
|
}
|
|
42
43
|
function optionalHint(hint) {
|
|
43
|
-
return hint
|
|
44
|
+
return hint ? { hint, hintColumn: true } : {};
|
|
44
45
|
}
|
|
45
|
-
function
|
|
46
|
-
return
|
|
46
|
+
function docLabel(doc) {
|
|
47
|
+
return doc.title ? { label: doc.title } : { label: pickIcon('…', '...'), dim: true };
|
|
47
48
|
}
|
|
48
49
|
function withoutReaderLinksField(value) {
|
|
49
50
|
const next = { ...value };
|
|
@@ -55,21 +56,16 @@ function withoutErrorMessage(value) {
|
|
|
55
56
|
delete next.errorMessage;
|
|
56
57
|
return next;
|
|
57
58
|
}
|
|
58
|
-
async function
|
|
59
|
+
async function openBrowserFromView(ctx, path, generation = lifecycleGeneration) {
|
|
60
|
+
await openUrlFromView(ctx, docsUrlFromPath(path), () => openDocsInBrowser(path, ctx.signal), generation);
|
|
61
|
+
}
|
|
62
|
+
async function openUrlFromView(ctx, url, open, generation = lifecycleGeneration) {
|
|
59
63
|
let opened;
|
|
60
64
|
await ctx.runClassic(async () => {
|
|
61
|
-
opened =
|
|
62
|
-
path === undefined
|
|
63
|
-
? await openDocsInBrowser(undefined, ctx.signal)
|
|
64
|
-
: await openDocsInBrowser(path, ctx.signal);
|
|
65
|
+
opened = await open();
|
|
65
66
|
});
|
|
66
|
-
return opened;
|
|
67
|
-
}
|
|
68
|
-
async function openBrowserFromView(ctx, path, generation = lifecycleGeneration) {
|
|
69
|
-
const opened = await runBrowserOpen(ctx, path);
|
|
70
67
|
if (!isLifecycleActive(ctx, generation) || opened === true)
|
|
71
68
|
return;
|
|
72
|
-
const url = docsUrlFromPath(path);
|
|
73
69
|
state = {
|
|
74
70
|
...state,
|
|
75
71
|
errorMessage: sanitizeTerminalLine(`${t().docs.browserError}. ${fmt(t().links.openManually, { url })}`),
|
|
@@ -100,8 +96,8 @@ function buildFilesField(section, maxVisible, initialIndex = 0) {
|
|
|
100
96
|
...(index ? [{ value: index.path, label: trans.docs.overviewLabel }] : []),
|
|
101
97
|
...files.map((file) => ({
|
|
102
98
|
value: file.path,
|
|
103
|
-
|
|
104
|
-
...optionalHint(
|
|
99
|
+
...docLabel(file),
|
|
100
|
+
...optionalHint(file.summary),
|
|
105
101
|
})),
|
|
106
102
|
{ value: '__back__', label: backLabel() },
|
|
107
103
|
];
|
|
@@ -134,10 +130,10 @@ function buildArchivedFilesField(groupKey, groupFiles, maxVisible, initialIndex
|
|
|
134
130
|
const sub = f.path.split('/').slice(2, -1).join('/');
|
|
135
131
|
return {
|
|
136
132
|
value: f.path,
|
|
137
|
-
|
|
138
|
-
...optionalHint(
|
|
133
|
+
...docLabel(f),
|
|
134
|
+
...optionalHint(subDirs.size > 1
|
|
139
135
|
? [sanitizeTerminalLine(sub), f.summary].filter(Boolean).join(' · ')
|
|
140
|
-
: f.summary)
|
|
136
|
+
: f.summary),
|
|
141
137
|
};
|
|
142
138
|
}),
|
|
143
139
|
{ value: '__back__', label: backLabel() },
|
|
@@ -152,7 +148,14 @@ function buildArchivedFilesField(groupKey, groupFiles, maxVisible, initialIndex
|
|
|
152
148
|
function buildReaderLinksField(links, maxVisible, initialIndex = 0) {
|
|
153
149
|
const trans = t();
|
|
154
150
|
const options = [
|
|
155
|
-
...links.map((l) =>
|
|
151
|
+
...links.map((l) => {
|
|
152
|
+
const address = l.external ? l.href.replace(/^https?:\/\//i, '').replace(/\/$/, '') : '';
|
|
153
|
+
return {
|
|
154
|
+
value: l.href,
|
|
155
|
+
label: l.text,
|
|
156
|
+
...optionalHint(address === l.text ? undefined : address),
|
|
157
|
+
};
|
|
158
|
+
}),
|
|
156
159
|
{ value: '__back__', label: backLabel() },
|
|
157
160
|
];
|
|
158
161
|
return new ListField({ title: trans.docs.readerLinksTitle, options, maxVisible, initialIndex });
|
|
@@ -163,26 +166,31 @@ function buildSearchResultsField(matches, maxVisible, initialIndex = 0) {
|
|
|
163
166
|
...matches.map((result) => ({
|
|
164
167
|
value: result.path,
|
|
165
168
|
label: displayDocTitle(result.name, result.title),
|
|
166
|
-
...optionalHint(
|
|
169
|
+
...optionalHint(result.excerpt ||
|
|
167
170
|
result.summary ||
|
|
168
171
|
(result.path.includes('/')
|
|
169
172
|
? sanitizeTerminalLine(result.path.split('/').slice(0, -1).join('/'))
|
|
170
|
-
: undefined))
|
|
173
|
+
: undefined)),
|
|
171
174
|
})),
|
|
172
175
|
{ value: '__back__', label: backLabel() },
|
|
173
176
|
];
|
|
174
|
-
return new ListField({
|
|
177
|
+
return new ListField({
|
|
178
|
+
title: fmt(trans.docs.searchResultsTitle, { query: currentSearchQuery, count: matches.length }),
|
|
179
|
+
options,
|
|
180
|
+
maxVisible,
|
|
181
|
+
initialIndex,
|
|
182
|
+
});
|
|
175
183
|
}
|
|
176
184
|
function relocalizeStateFields(value, maxVisible) {
|
|
177
185
|
if (value.mode === 'sections') {
|
|
178
186
|
return { ...value, sectionsField: buildSectionsField() };
|
|
179
187
|
}
|
|
180
|
-
if (value.mode === 'files' && currentSectionKey) {
|
|
188
|
+
if (value.mode === 'files' && value.filesField && currentSectionKey) {
|
|
181
189
|
const section = sections.find((candidate) => candidate.key === currentSectionKey);
|
|
182
190
|
return section
|
|
183
191
|
? {
|
|
184
192
|
...value,
|
|
185
|
-
filesField: buildFilesField(section, maxVisible, value.filesField
|
|
193
|
+
filesField: buildFilesField(section, maxVisible, value.filesField.selectedIndex),
|
|
186
194
|
}
|
|
187
195
|
: value;
|
|
188
196
|
}
|
|
@@ -192,10 +200,10 @@ function relocalizeStateFields(value, maxVisible) {
|
|
|
192
200
|
archivedGroupsField: buildArchivedGroupsField(archivedGroups, maxVisible, value.archivedGroupsField?.selectedIndex),
|
|
193
201
|
};
|
|
194
202
|
}
|
|
195
|
-
if (value.mode === 'archivedFiles' && currentArchivedGroupKey) {
|
|
203
|
+
if (value.mode === 'archivedFiles' && value.archivedFilesField && currentArchivedGroupKey) {
|
|
196
204
|
return {
|
|
197
205
|
...value,
|
|
198
|
-
archivedFilesField: buildArchivedFilesField(currentArchivedGroupKey, archivedGroups.get(currentArchivedGroupKey) ?? [], maxVisible, value.archivedFilesField
|
|
206
|
+
archivedFilesField: buildArchivedFilesField(currentArchivedGroupKey, archivedGroups.get(currentArchivedGroupKey) ?? [], maxVisible, value.archivedFilesField.selectedIndex),
|
|
199
207
|
};
|
|
200
208
|
}
|
|
201
209
|
if (value.mode === 'searchResults') {
|
|
@@ -218,6 +226,19 @@ function goToSections() {
|
|
|
218
226
|
currentSearchResults = [];
|
|
219
227
|
state = { mode: 'sections', sectionsField: buildSectionsField(), stale };
|
|
220
228
|
}
|
|
229
|
+
function showLoadError() {
|
|
230
|
+
const trans = t();
|
|
231
|
+
state = {
|
|
232
|
+
mode: 'error',
|
|
233
|
+
errorMessage: trans.docs.offlineError,
|
|
234
|
+
errorField: new ListField({
|
|
235
|
+
options: [
|
|
236
|
+
{ value: '__retry__', label: trans.docs.retryLoad },
|
|
237
|
+
{ value: '__browser__', label: trans.docs.openBrowser },
|
|
238
|
+
],
|
|
239
|
+
}),
|
|
240
|
+
};
|
|
241
|
+
}
|
|
221
242
|
function replaceSection(section) {
|
|
222
243
|
sections = sections.map((current) => (current.key === section.key ? section : current));
|
|
223
244
|
}
|
|
@@ -227,32 +248,43 @@ async function openSectionFiles(ctx, section) {
|
|
|
227
248
|
return;
|
|
228
249
|
const requestId = ++metadataRequestId;
|
|
229
250
|
currentSectionKey = section.key;
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
251
|
+
const stored = peekListedDocs(section.files);
|
|
252
|
+
const known = { ...section, files: stored.docs };
|
|
253
|
+
const isCurrent = () => isLifecycleActive(ctx, generation) &&
|
|
254
|
+
requestId === metadataRequestId &&
|
|
255
|
+
state.mode === 'files' &&
|
|
256
|
+
currentSectionKey === section.key;
|
|
257
|
+
const show = (value, extra = {}) => {
|
|
258
|
+
state = {
|
|
259
|
+
mode: 'files',
|
|
260
|
+
filesField: buildFilesField(value, computeMaxVisible(ctx.bodyRows), state.filesField?.selectedIndex),
|
|
261
|
+
...extra,
|
|
262
|
+
};
|
|
233
263
|
};
|
|
264
|
+
show(known);
|
|
265
|
+
if (stored.complete) {
|
|
266
|
+
replaceSection(known);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
234
269
|
ctx.rerender();
|
|
235
270
|
try {
|
|
236
|
-
const hydrated = await fetchSectionMetadata(section, ctx.signal)
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
271
|
+
const hydrated = await fetchSectionMetadata(section, ctx.signal, (index, doc) => {
|
|
272
|
+
if (!isCurrent() || known.files[index]?.title)
|
|
273
|
+
return;
|
|
274
|
+
known.files[index] = doc;
|
|
275
|
+
show(known);
|
|
276
|
+
ctx.rerender();
|
|
277
|
+
});
|
|
278
|
+
if (!isCurrent())
|
|
241
279
|
return;
|
|
242
280
|
const localized = localizeDocSections([hydrated], t())[0] ?? hydrated;
|
|
243
281
|
replaceSection(localized);
|
|
244
|
-
|
|
245
|
-
mode: 'files',
|
|
246
|
-
filesField: buildFilesField(localized, computeMaxVisible(ctx.bodyRows), state.filesField?.selectedIndex),
|
|
247
|
-
};
|
|
282
|
+
show(localized);
|
|
248
283
|
}
|
|
249
284
|
catch {
|
|
250
|
-
if (!
|
|
251
|
-
requestId !== metadataRequestId ||
|
|
252
|
-
state.mode !== 'files' ||
|
|
253
|
-
currentSectionKey !== section.key)
|
|
285
|
+
if (!isCurrent())
|
|
254
286
|
return;
|
|
255
|
-
|
|
287
|
+
show({ ...known, files: known.files.map(withFileNameTitle) }, { errorMessage: t().docs.loadError });
|
|
256
288
|
}
|
|
257
289
|
if (isLifecycleActive(ctx, generation))
|
|
258
290
|
ctx.rerender();
|
|
@@ -263,34 +295,41 @@ async function openArchivedFiles(ctx, groupKey, groupFiles) {
|
|
|
263
295
|
return;
|
|
264
296
|
const requestId = ++metadataRequestId;
|
|
265
297
|
currentArchivedGroupKey = groupKey;
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
298
|
+
const stored = peekListedDocs(groupFiles);
|
|
299
|
+
const isCurrent = () => isLifecycleActive(ctx, generation) &&
|
|
300
|
+
requestId === metadataRequestId &&
|
|
301
|
+
state.mode === 'archivedFiles' &&
|
|
302
|
+
currentArchivedGroupKey === groupKey;
|
|
303
|
+
const show = (files, extra = {}) => {
|
|
304
|
+
state = {
|
|
305
|
+
mode: 'archivedFiles',
|
|
306
|
+
archivedFilesField: buildArchivedFilesField(groupKey, files, computeMaxVisible(ctx.bodyRows), state.archivedFilesField?.selectedIndex),
|
|
307
|
+
...extra,
|
|
308
|
+
};
|
|
269
309
|
};
|
|
310
|
+
show(stored.docs);
|
|
311
|
+
if (stored.complete) {
|
|
312
|
+
archivedGroups.set(groupKey, stored.docs);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
270
315
|
ctx.rerender();
|
|
271
316
|
try {
|
|
272
|
-
const hydrated = await fetchDocMetadata(groupFiles, ctx.signal)
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
317
|
+
const hydrated = await fetchDocMetadata(groupFiles, ctx.signal, (index, doc) => {
|
|
318
|
+
if (!isCurrent() || stored.docs[index]?.title)
|
|
319
|
+
return;
|
|
320
|
+
stored.docs[index] = doc;
|
|
321
|
+
show(stored.docs);
|
|
322
|
+
ctx.rerender();
|
|
323
|
+
});
|
|
324
|
+
if (!isCurrent())
|
|
277
325
|
return;
|
|
278
326
|
archivedGroups.set(groupKey, hydrated);
|
|
279
|
-
|
|
280
|
-
mode: 'archivedFiles',
|
|
281
|
-
archivedFilesField: buildArchivedFilesField(groupKey, hydrated, computeMaxVisible(ctx.bodyRows), state.archivedFilesField?.selectedIndex),
|
|
282
|
-
};
|
|
327
|
+
show(hydrated);
|
|
283
328
|
}
|
|
284
329
|
catch {
|
|
285
|
-
if (!
|
|
286
|
-
requestId !== metadataRequestId ||
|
|
287
|
-
state.mode !== 'archivedFiles' ||
|
|
288
|
-
currentArchivedGroupKey !== groupKey)
|
|
330
|
+
if (!isCurrent())
|
|
289
331
|
return;
|
|
290
|
-
|
|
291
|
-
...state,
|
|
292
|
-
errorMessage: t().docs.loadError,
|
|
293
|
-
};
|
|
332
|
+
show(stored.docs.map(withFileNameTitle), { errorMessage: t().docs.loadError });
|
|
294
333
|
}
|
|
295
334
|
if (isLifecycleActive(ctx, generation))
|
|
296
335
|
ctx.rerender();
|
|
@@ -303,9 +342,15 @@ async function runSearch(ctx, query) {
|
|
|
303
342
|
state = { mode: 'searchLoading' };
|
|
304
343
|
ctx.rerender();
|
|
305
344
|
try {
|
|
306
|
-
const matches = await searchDocuments(query, ctx.signal)
|
|
345
|
+
const matches = await searchDocuments(query, ctx.signal, (done, total) => {
|
|
346
|
+
if (!isLifecycleActive(ctx, generation) || requestId !== searchRequestId)
|
|
347
|
+
return;
|
|
348
|
+
state = { mode: 'searchLoading', searchProgress: { done, total } };
|
|
349
|
+
ctx.rerender();
|
|
350
|
+
});
|
|
307
351
|
if (!isLifecycleActive(ctx, generation) || requestId !== searchRequestId)
|
|
308
352
|
return;
|
|
353
|
+
currentSearchQuery = query;
|
|
309
354
|
currentSearchResults = matches;
|
|
310
355
|
state = {
|
|
311
356
|
mode: 'searchResults',
|
|
@@ -367,6 +412,25 @@ function enterReaderFrom(ctx, path) {
|
|
|
367
412
|
readerCurrentPath = null;
|
|
368
413
|
void openInReader(ctx, path, false);
|
|
369
414
|
}
|
|
415
|
+
function reloadDocs(ctx) {
|
|
416
|
+
clearDocsCache();
|
|
417
|
+
sectionsRequestId++;
|
|
418
|
+
metadataRequestId++;
|
|
419
|
+
searchRequestId++;
|
|
420
|
+
loaded = false;
|
|
421
|
+
loadedLanguage = null;
|
|
422
|
+
sections = [];
|
|
423
|
+
archivedGroups = new Map();
|
|
424
|
+
currentSectionKey = null;
|
|
425
|
+
currentArchivedGroupKey = null;
|
|
426
|
+
currentSearchResults = [];
|
|
427
|
+
readerCurrentPath = null;
|
|
428
|
+
readerNavStack = [];
|
|
429
|
+
readerPrevState = null;
|
|
430
|
+
readerLoadingPrevState = null;
|
|
431
|
+
readerRequestId++;
|
|
432
|
+
void docsView.load(ctx);
|
|
433
|
+
}
|
|
370
434
|
export const docsView = {
|
|
371
435
|
id: 'docs',
|
|
372
436
|
title: t().menu.docs,
|
|
@@ -423,7 +487,7 @@ export const docsView = {
|
|
|
423
487
|
state = { ...state, stale };
|
|
424
488
|
}
|
|
425
489
|
else {
|
|
426
|
-
|
|
490
|
+
showLoadError();
|
|
427
491
|
}
|
|
428
492
|
}
|
|
429
493
|
if (isLifecycleActive(ctx, generation))
|
|
@@ -502,12 +566,15 @@ export const docsView = {
|
|
|
502
566
|
state.mode === 'archivedGroups' ||
|
|
503
567
|
state.mode === 'archivedFiles' ||
|
|
504
568
|
state.mode === 'searchResults' ||
|
|
569
|
+
(state.mode === 'error' && state.errorField !== undefined) ||
|
|
505
570
|
(state.mode === 'reader' && state.readerLinksField !== undefined));
|
|
506
571
|
},
|
|
507
572
|
footerHint(tabCount, cols = Number.POSITIVE_INFINITY) {
|
|
508
573
|
if (state.mode === 'search')
|
|
509
574
|
return captureFooterHint(cols);
|
|
510
|
-
if (state.mode === 'loading' ||
|
|
575
|
+
if (state.mode === 'loading' ||
|
|
576
|
+
state.mode === 'searchLoading' ||
|
|
577
|
+
(state.mode === 'error' && !state.errorField))
|
|
511
578
|
return passiveFooterHint(tabCount, cols);
|
|
512
579
|
if (state.mode === 'readerLoading') {
|
|
513
580
|
return fitFooterHint(cols, `${digitTabHint(tabCount)}q ${t().menu.hintQuit}`, `${digitTabHint(tabCount)}q`, 'q');
|
|
@@ -598,23 +665,7 @@ export const docsView = {
|
|
|
598
665
|
return;
|
|
599
666
|
}
|
|
600
667
|
if (result.selected === '__refresh__') {
|
|
601
|
-
|
|
602
|
-
sectionsRequestId++;
|
|
603
|
-
metadataRequestId++;
|
|
604
|
-
searchRequestId++;
|
|
605
|
-
loaded = false;
|
|
606
|
-
loadedLanguage = null;
|
|
607
|
-
sections = [];
|
|
608
|
-
archivedGroups = new Map();
|
|
609
|
-
currentSectionKey = null;
|
|
610
|
-
currentArchivedGroupKey = null;
|
|
611
|
-
currentSearchResults = [];
|
|
612
|
-
readerCurrentPath = null;
|
|
613
|
-
readerNavStack = [];
|
|
614
|
-
readerPrevState = null;
|
|
615
|
-
readerLoadingPrevState = null;
|
|
616
|
-
readerRequestId++;
|
|
617
|
-
void docsView.load(ctx);
|
|
668
|
+
reloadDocs(ctx);
|
|
618
669
|
return;
|
|
619
670
|
}
|
|
620
671
|
if (result.selected === '__browser__') {
|
|
@@ -713,8 +764,15 @@ export const docsView = {
|
|
|
713
764
|
state = withoutReaderLinksField(state);
|
|
714
765
|
return;
|
|
715
766
|
}
|
|
716
|
-
|
|
767
|
+
const link = state.readerLinks?.find((candidate) => candidate.href === result.selected);
|
|
768
|
+
if (link?.external) {
|
|
769
|
+
const href = link.href;
|
|
770
|
+
state = withoutReaderLinksField(state);
|
|
771
|
+
void openUrlFromView(ctx, href, () => launchBrowserUrl(href));
|
|
772
|
+
}
|
|
773
|
+
else if (result.selected) {
|
|
717
774
|
void openInReader(ctx, result.selected, true);
|
|
775
|
+
}
|
|
718
776
|
return;
|
|
719
777
|
}
|
|
720
778
|
if (key === 'f' && (state.readerLinks?.length ?? 0) > 0) {
|
|
@@ -730,7 +788,14 @@ export const docsView = {
|
|
|
730
788
|
}
|
|
731
789
|
return;
|
|
732
790
|
}
|
|
733
|
-
case 'error':
|
|
791
|
+
case 'error': {
|
|
792
|
+
const result = state.errorField?.handleKey(key);
|
|
793
|
+
if (result?.selected === '__retry__')
|
|
794
|
+
reloadDocs(ctx);
|
|
795
|
+
if (result?.selected === '__browser__')
|
|
796
|
+
void openBrowserFromView(ctx);
|
|
797
|
+
return;
|
|
798
|
+
}
|
|
734
799
|
case 'loading':
|
|
735
800
|
case 'readerLoading':
|
|
736
801
|
case 'searchLoading':
|
|
@@ -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 { renderCountdownBanner, renderEventBriefLines, } from '../../features/calendar.js';
|
|
5
6
|
import { renderHeatmap } from '../../features/calendar-heatmap.js';
|
|
6
7
|
import { wrapAnsiWithIndent } from '../../core/text.js';
|
|
@@ -9,6 +10,15 @@ function wrappedIndentedLines(label, cols, style) {
|
|
|
9
10
|
return wrapAnsiWithIndent(style(label), cols ?? Number.POSITIVE_INFINITY, space.indent);
|
|
10
11
|
}
|
|
11
12
|
const EXPANDED_HUB_MIN_BODY_ROWS = 29;
|
|
13
|
+
export function hubShowsHeatmap(bodyRows, buckets = []) {
|
|
14
|
+
return bodyRows >= EXPANDED_HUB_MIN_BODY_ROWS && buckets.length > 0;
|
|
15
|
+
}
|
|
16
|
+
function heatmapLines(buckets, now, cols) {
|
|
17
|
+
return renderHeatmap(buckets, now, {
|
|
18
|
+
color: true,
|
|
19
|
+
...(cols === undefined ? {} : { cols }),
|
|
20
|
+
}).split('\n');
|
|
21
|
+
}
|
|
12
22
|
function renderHubBody(state, now, bodyRows, cols) {
|
|
13
23
|
const trans = t();
|
|
14
24
|
const lines = [];
|
|
@@ -16,18 +26,13 @@ function renderHubBody(state, now, bodyRows, cols) {
|
|
|
16
26
|
? Math.max(0, Math.floor(bodyRows))
|
|
17
27
|
: Number.POSITIVE_INFINITY;
|
|
18
28
|
if (state.stale)
|
|
19
|
-
lines.push(...
|
|
29
|
+
lines.push(...offlineNotice(cols ?? Number.POSITIVE_INFINITY));
|
|
20
30
|
const banner = renderCountdownBanner(state.nextEvent, now, cols);
|
|
21
31
|
if (banner)
|
|
22
32
|
lines.push(...banner.split('\n'), '');
|
|
23
33
|
const buckets = state.heatmapBuckets;
|
|
24
|
-
if (
|
|
25
|
-
lines.push(...
|
|
26
|
-
color: true,
|
|
27
|
-
...(cols === undefined ? {} : { cols }),
|
|
28
|
-
}).split('\n'));
|
|
29
|
-
lines.push('');
|
|
30
|
-
}
|
|
34
|
+
if (buckets && hubShowsHeatmap(bodyRows, buckets))
|
|
35
|
+
lines.push(...heatmapLines(buckets, now, cols), '');
|
|
31
36
|
if (state.recentEvents && state.recentEvents.length > 0) {
|
|
32
37
|
const activityHeading = wrappedIndentedLines(trans.calendar.recentActivity, cols, type.heading);
|
|
33
38
|
const fieldRows = state.hubField
|
|
@@ -64,33 +69,36 @@ function renderHubBody(state, now, bodyRows, cols) {
|
|
|
64
69
|
}
|
|
65
70
|
export function renderEvents(state, now, bodyRows = 100, cols) {
|
|
66
71
|
const trans = t();
|
|
72
|
+
const notice = state.stale ? offlineNotice(cols ?? Number.POSITIVE_INFINITY) : [];
|
|
67
73
|
switch (state.mode) {
|
|
68
74
|
case 'loading':
|
|
69
75
|
return loadingLines(trans.calendar.loading, cols);
|
|
70
76
|
case 'hub':
|
|
71
77
|
return renderHubBody(state, now, bodyRows, cols);
|
|
72
78
|
case 'heatmap':
|
|
73
|
-
return
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
return [
|
|
80
|
+
...notice,
|
|
81
|
+
...(state.heatmapBuckets && state.heatmapBuckets.length > 0
|
|
82
|
+
? heatmapLines(state.heatmapBuckets, now, cols)
|
|
83
|
+
: wrappedIndentedLines(trans.calendar.noEvents, cols, type.hint)),
|
|
84
|
+
];
|
|
79
85
|
case 'list': {
|
|
80
86
|
if (!state.listField)
|
|
81
87
|
return [];
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
const context = state.listNotice === undefined
|
|
89
|
+
? notice
|
|
90
|
+
: [
|
|
91
|
+
...notice,
|
|
92
|
+
...wrappedIndentedLines(state.listTitle ?? '', cols, type.heading),
|
|
93
|
+
'',
|
|
94
|
+
...wrappedIndentedLines(state.listNotice, cols, type.hint),
|
|
95
|
+
'',
|
|
96
|
+
];
|
|
90
97
|
return renderListFieldWithContext(context, state.listField, bodyRows, cols);
|
|
91
98
|
}
|
|
92
99
|
case 'detail': {
|
|
93
100
|
const context = [
|
|
101
|
+
...notice,
|
|
94
102
|
...wrappedIndentedLines(state.detailTitle ?? '', cols, type.heading),
|
|
95
103
|
...wrappedIndentedLines(state.detailMeta ?? '', cols, type.hint),
|
|
96
104
|
'',
|
|
@@ -111,9 +119,20 @@ export function renderEvents(state, now, bodyRows = 100, cols) {
|
|
|
111
119
|
: context;
|
|
112
120
|
}
|
|
113
121
|
case 'search':
|
|
114
|
-
return state.searchField?.render(cols) ?? [];
|
|
115
|
-
case 'error':
|
|
116
|
-
|
|
122
|
+
return [...notice, ...(state.searchField?.render(cols) ?? [])];
|
|
123
|
+
case 'error': {
|
|
124
|
+
const context = [
|
|
125
|
+
...wrappedIndentedLines(state.errorMessage ?? trans.calendar.error, cols, type.body),
|
|
126
|
+
...wrappedIndentedLines(trans.calendar.errorHint, cols, type.hint),
|
|
127
|
+
'',
|
|
128
|
+
];
|
|
129
|
+
if (state.errorField) {
|
|
130
|
+
return renderListFieldWithContext(context, state.errorField, bodyRows, cols);
|
|
131
|
+
}
|
|
132
|
+
return Number.isFinite(bodyRows)
|
|
133
|
+
? context.slice(0, Math.max(0, Math.floor(bodyRows)))
|
|
134
|
+
: context;
|
|
135
|
+
}
|
|
117
136
|
default:
|
|
118
137
|
return [];
|
|
119
138
|
}
|