@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/views/home.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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
|
-
import { passiveFooterHint } from '../chrome.js';
|
|
8
|
+
import { offlineNotice, passiveFooterHint } from '../chrome.js';
|
|
9
9
|
import { campusDateTime, campusIsoDate } from '@nbtca/nbtcal/timetable';
|
|
10
10
|
import { isoDayDifference, localDayDifference, parseLocalDate } from '../../core/calendar-day.js';
|
|
11
11
|
import { currentEvents } from '../../features/calendar-query.js';
|
|
@@ -74,36 +74,37 @@ function renderWeekAheadGrid(classDays, eventDays, cols) {
|
|
|
74
74
|
}
|
|
75
75
|
export function renderHome(data, now, bodyRows = 100, cols = 80) {
|
|
76
76
|
const trans = t();
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (data.todayLines && data.todayLines.length > 0) {
|
|
87
|
-
for (const line of data.todayLines)
|
|
88
|
-
lines.push(...wrappedRenderedLines(line, cols));
|
|
77
|
+
const eventsStale = data.eventsLoadFailed === true && (data.eventLines?.length ?? 0) > 0;
|
|
78
|
+
const lines = eventsStale ? offlineNotice(cols) : [];
|
|
79
|
+
if (data.schedule === null) {
|
|
80
|
+
lines.push(...panelHeading(trans.timetable.menuTitle, cols));
|
|
81
|
+
lines.push(...wrappedIndentedLines(fmt(trans.timetable.homeLoginCta, {
|
|
82
|
+
tab: trans.timetable.menuEntry,
|
|
83
|
+
action: trans.timetable.publicLoginAction,
|
|
84
|
+
}), cols, type.hint));
|
|
85
|
+
lines.push('');
|
|
89
86
|
}
|
|
90
|
-
else {
|
|
91
|
-
|
|
87
|
+
else if (data.schedule) {
|
|
88
|
+
const next = nextClassLine(data.schedule, now, cols);
|
|
89
|
+
lines.push(...panelHeading(trans.timetable.nextClass, cols));
|
|
90
|
+
lines.push(...(next ? [next] : wrappedIndentedLines(trans.timetable.noNextClass, cols, type.hint)));
|
|
91
|
+
lines.push('');
|
|
92
|
+
lines.push(...panelHeading(trans.timetable.hubToday, cols));
|
|
93
|
+
lines.push(renderDayProgress(now, cols));
|
|
94
|
+
lines.push(...todayLines(data.schedule, now, cols));
|
|
95
|
+
lines.push('');
|
|
92
96
|
}
|
|
93
|
-
lines.push('');
|
|
94
97
|
if (data.weekAhead) {
|
|
95
98
|
lines.push(...panelHeading(trans.timetable.weekOverviewTitle, cols));
|
|
96
99
|
lines.push(...renderWeekAheadGrid(data.weekAhead.classDays, data.weekAhead.eventDays, cols).split('\n'));
|
|
97
100
|
lines.push('');
|
|
98
101
|
}
|
|
99
|
-
|
|
100
|
-
|
|
102
|
+
const unresolvedCount = data.schedule?.timetable.unresolvedItems.length ?? 0;
|
|
103
|
+
if (unresolvedCount > 0) {
|
|
104
|
+
lines.push(...wrappedIndentedLines(`${pickIcon('⚠', '!')} ${trans.timetable.hubUnresolved} · ${unresolvedCount}`, cols, c.warn));
|
|
101
105
|
lines.push('');
|
|
102
106
|
}
|
|
103
|
-
|
|
104
|
-
lines.push(...(eventsStale
|
|
105
|
-
? wrappedIndentedLines(`${type.heading(trans.menu.events)} ${type.hint(`${pickIcon('·', '-')} ${trans.calendar.stale}`)}`, cols, (value) => value)
|
|
106
|
-
: panelHeading(trans.menu.events, cols)));
|
|
107
|
+
lines.push(...panelHeading(trans.menu.events, cols));
|
|
107
108
|
if (data.eventLines && data.eventLines.length > 0) {
|
|
108
109
|
const remaining = Number.isFinite(bodyRows)
|
|
109
110
|
? Math.max(0, Math.floor(bodyRows) - lines.length)
|
|
@@ -132,14 +133,14 @@ export function renderHome(data, now, bodyRows = 100, cols = 80) {
|
|
|
132
133
|
return lines;
|
|
133
134
|
}
|
|
134
135
|
const HOME_EVENT_FETCH_CAP = 15;
|
|
135
|
-
function calendarSnapshot(cal,
|
|
136
|
+
function calendarSnapshot(cal, weekAhead) {
|
|
136
137
|
const now = new Date();
|
|
137
138
|
const eventLines = currentEvents(cal, now)
|
|
138
139
|
.slice(0, HOME_EVENT_FETCH_CAP)
|
|
139
140
|
.map((event) => renderEventBrief(toDisplayEvent(event), now));
|
|
140
|
-
if (!
|
|
141
|
+
if (!weekAhead)
|
|
141
142
|
return { eventLines };
|
|
142
|
-
const { weekStart } =
|
|
143
|
+
const { weekStart } = weekAhead;
|
|
143
144
|
const monday = campusDateTime(weekStart, '00:00');
|
|
144
145
|
const daySet = new Set(cal
|
|
145
146
|
.inRange(new Date(monday.getTime() - DAY_MS), new Date(monday.getTime() + 8 * DAY_MS))
|
|
@@ -150,7 +151,7 @@ function calendarSnapshot(cal, weekAheadInfo) {
|
|
|
150
151
|
return {
|
|
151
152
|
eventLines,
|
|
152
153
|
weekAhead: {
|
|
153
|
-
classDays:
|
|
154
|
+
classDays: weekAhead.classDays,
|
|
154
155
|
eventDays: WEEKDAYS.map((weekday) => daySet.has(weekday)),
|
|
155
156
|
},
|
|
156
157
|
};
|
|
@@ -165,22 +166,16 @@ export const homeView = {
|
|
|
165
166
|
async load(ctx) {
|
|
166
167
|
if (ctx.signal?.aborted)
|
|
167
168
|
return;
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
...(weekAheadInfo ? { weekAhead: { classDays: weekAheadInfo.classDays } } : {}),
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
catch {
|
|
179
|
-
data = { loading: true };
|
|
180
|
-
}
|
|
169
|
+
const schedule = peekSchedule();
|
|
170
|
+
const weekAhead = schedule ? weekAheadInfo(schedule) : null;
|
|
171
|
+
data = {
|
|
172
|
+
loading: true,
|
|
173
|
+
schedule,
|
|
174
|
+
...(weekAhead ? { weekAhead: { classDays: weekAhead.classDays } } : {}),
|
|
175
|
+
};
|
|
181
176
|
const cached = peekCalendar();
|
|
182
177
|
if (cached)
|
|
183
|
-
data = { ...data, ...calendarSnapshot(cached,
|
|
178
|
+
data = { ...data, ...calendarSnapshot(cached, weekAhead) };
|
|
184
179
|
if (ctx.signal?.aborted)
|
|
185
180
|
return;
|
|
186
181
|
ctx.rerender();
|
|
@@ -188,7 +183,7 @@ export const homeView = {
|
|
|
188
183
|
const cal = await loadCalendarOrThrow(ctx.signal);
|
|
189
184
|
if (ctx.signal?.aborted)
|
|
190
185
|
return;
|
|
191
|
-
data = { ...data, ...calendarSnapshot(cal,
|
|
186
|
+
data = { ...data, ...calendarSnapshot(cal, weekAhead) };
|
|
192
187
|
}
|
|
193
188
|
catch {
|
|
194
189
|
if (ctx.signal?.aborted)
|
|
@@ -3,7 +3,7 @@ import { c, type, space, glyph } from '../../core/theme.js';
|
|
|
3
3
|
import { pickIcon } from '../../core/icons.js';
|
|
4
4
|
import { t, fmt } from '../../i18n/index.js';
|
|
5
5
|
import { renderListFieldWithContext } from '../fields/list-field.js';
|
|
6
|
-
import { renderNextClassBanner, renderWeekGrid, renderUnresolvedItems, renderTodayTimeline, weekdayShortLabel, renderTermDensity, renderMeetingDetail, renderDayTimeline, renderDaySwitcher, } from '../../features/schedule-render.js';
|
|
6
|
+
import { renderNextClassBanner, renderWeekGrid, renderUnresolvedItems, renderTodayTimeline, weekdayShortLabel, renderTermDensity, renderMeetingDetail, renderDayTimeline, renderDaySwitcher, renderWeekAgenda, lineBudget, } from '../../features/schedule-render.js';
|
|
7
7
|
import { sanitizeTerminalLine, visualWidth, wrapAnsiWithIndent } from '../../core/text.js';
|
|
8
8
|
import { isoDayDifference } from '../../core/calendar-day.js';
|
|
9
9
|
import { loadingLines } from '../../core/components/spinner.js';
|
|
@@ -42,7 +42,7 @@ export function hubShortcuts(tt) {
|
|
|
42
42
|
return shortcuts;
|
|
43
43
|
}
|
|
44
44
|
function renderShortcutLines(shortcuts, cols, compact = false) {
|
|
45
|
-
const available = Math.max(1, cols - visualWidth(space.indent));
|
|
45
|
+
const available = Math.max(1, lineBudget(cols) - visualWidth(space.indent));
|
|
46
46
|
const parts = shortcuts.map((shortcut) => {
|
|
47
47
|
const text = compact
|
|
48
48
|
? shortcut.showKey === false
|
|
@@ -105,37 +105,64 @@ function hubPreGridLines(state, now, cols) {
|
|
|
105
105
|
week: String(week),
|
|
106
106
|
})),
|
|
107
107
|
...renderTodayTimeline(today, tt.periods, now, cols).split('\n'),
|
|
108
|
+
'',
|
|
108
109
|
weekHeading,
|
|
109
110
|
];
|
|
110
111
|
return { inlineLines, fallbackLines: [...lines, weekHeading], week, tt };
|
|
111
112
|
}
|
|
112
113
|
const MIN_GRID_COLS = 100;
|
|
113
|
-
function
|
|
114
|
+
function fittingWeekGrid(tt, week, now, rows, cols, cursor) {
|
|
114
115
|
if (cols < MIN_GRID_COLS)
|
|
115
|
-
return
|
|
116
|
-
const
|
|
117
|
-
return
|
|
116
|
+
return null;
|
|
117
|
+
const grid = renderWeekGrid(tt, week, now, cols, cursor).split('\n');
|
|
118
|
+
return grid.length <= rows ? grid : null;
|
|
118
119
|
}
|
|
119
|
-
function
|
|
120
|
-
if (gridFitsInline(inlineLines.length, tt, week, now, bodyRows, cols, cursor, reservedRows)) {
|
|
121
|
-
return [...inlineLines, ...renderWeekGrid(tt, week, now, cols, cursor).split('\n')];
|
|
122
|
-
}
|
|
120
|
+
function renderDayFallback(tt, week, todayWd, now, cols, cursor) {
|
|
123
121
|
const selectedWd = cursor?.weekday ?? todayWd;
|
|
124
|
-
const dayMeetings = createTimetableSchedule(tt).meetingsOnDay(week, selectedWd);
|
|
125
122
|
return [
|
|
126
|
-
...fallbackLines,
|
|
127
123
|
renderDaySwitcher(selectedWd, todayWd, cols),
|
|
128
|
-
...renderDayTimeline(
|
|
124
|
+
...renderDayTimeline(createTimetableSchedule(tt).meetingsOnDay(week, selectedWd), tt.periods, now, { weekday: selectedWd, isToday: selectedWd === todayWd }, cursor?.period, cols).split('\n'),
|
|
129
125
|
];
|
|
130
126
|
}
|
|
127
|
+
function renderAdaptiveWeekGrid(inlineLines, fallbackLines, tt, week, todayWd, now, bodyRows, cols, cursor, reservedRows) {
|
|
128
|
+
const grid = fittingWeekGrid(tt, week, now, bodyRows - reservedRows - inlineLines.length, cols, cursor);
|
|
129
|
+
if (grid)
|
|
130
|
+
return [...inlineLines, ...grid];
|
|
131
|
+
return [...fallbackLines, ...renderDayFallback(tt, week, todayWd, now, cols, cursor)];
|
|
132
|
+
}
|
|
133
|
+
function renderWeekBody(tt, week, todayWd, now, bodyRows, cols, cursor) {
|
|
134
|
+
const rows = Math.max(0, Math.floor(bodyRows));
|
|
135
|
+
const title = heading(t().timetable.hubWeek);
|
|
136
|
+
const layouts = [
|
|
137
|
+
fittingWeekGrid(tt, week, now, rows - 2, cols, cursor),
|
|
138
|
+
renderWeekAgenda(tt, week, now, cols, cursor),
|
|
139
|
+
renderWeekAgenda(tt, week, now, cols, cursor, true),
|
|
140
|
+
];
|
|
141
|
+
for (const layout of layouts) {
|
|
142
|
+
if (!layout)
|
|
143
|
+
continue;
|
|
144
|
+
if (layout.length + 2 <= rows)
|
|
145
|
+
return [title, '', ...layout];
|
|
146
|
+
if (layout.length + 1 <= rows)
|
|
147
|
+
return [title, ...layout];
|
|
148
|
+
}
|
|
149
|
+
const dense = layouts.at(-1);
|
|
150
|
+
if (dense && dense.length <= rows)
|
|
151
|
+
return dense;
|
|
152
|
+
return [
|
|
153
|
+
...hintLines(t().timetable.weekTooSmall, cols),
|
|
154
|
+
...renderDayFallback(tt, week, todayWd, now, cols, cursor),
|
|
155
|
+
];
|
|
156
|
+
}
|
|
157
|
+
const MIN_HUB_CONTENT_ROWS = 4;
|
|
131
158
|
function renderHubBody(state, now, bodyRows, cols) {
|
|
132
159
|
const tt = state.timetable;
|
|
133
160
|
const pre = hubPreGridLines(state, now, cols);
|
|
134
161
|
const shortcuts = tt ? hubShortcuts(tt) : [];
|
|
135
162
|
const rows = Math.max(0, Math.floor(bodyRows));
|
|
136
|
-
const build = (shortcutLines) => {
|
|
163
|
+
const build = (shortcutLines, gap = true) => {
|
|
137
164
|
const tail = [];
|
|
138
|
-
if (pre && (state.statusMessage || shortcutLines.length > 0))
|
|
165
|
+
if (gap && pre && (state.statusMessage || shortcutLines.length > 0))
|
|
139
166
|
tail.push('');
|
|
140
167
|
if (state.statusMessage) {
|
|
141
168
|
tail.push(...hintLines(state.statusMessage, cols));
|
|
@@ -148,9 +175,15 @@ function renderHubBody(state, now, bodyRows, cols) {
|
|
|
148
175
|
: [];
|
|
149
176
|
return { content, tail };
|
|
150
177
|
};
|
|
151
|
-
const
|
|
178
|
+
const labelled = renderShortcutLines(shortcuts, cols);
|
|
179
|
+
const full = build(labelled);
|
|
152
180
|
if (full.content.length + full.tail.length <= rows)
|
|
153
181
|
return [...full.content, ...full.tail];
|
|
182
|
+
const tight = build(labelled, false);
|
|
183
|
+
if (rows - tight.tail.length >= MIN_HUB_CONTENT_ROWS) {
|
|
184
|
+
const content = tight.content.filter((line) => line !== '');
|
|
185
|
+
return [...content.slice(0, rows - tight.tail.length), ...tight.tail];
|
|
186
|
+
}
|
|
154
187
|
const compact = build(renderShortcutLines(shortcuts, cols, true));
|
|
155
188
|
if (compact.tail.length >= rows)
|
|
156
189
|
return rows > 0 ? compact.tail.slice(-rows) : [];
|
|
@@ -241,16 +274,25 @@ export function renderSchedule(state, now, bodyRows = 100, cols = 80) {
|
|
|
241
274
|
const schedule = createTimetableSchedule(state.timetable, {
|
|
242
275
|
weekOneMonday: state.weekOne,
|
|
243
276
|
});
|
|
244
|
-
|
|
245
|
-
const weekLines = [heading(trans.timetable.hubWeek), ''];
|
|
246
|
-
return renderAdaptiveWeekGrid(weekLines, weekLines, state.timetable, week, schedule.weekdayAt(now), now, bodyRows, cols, state.gridCursor, 2);
|
|
277
|
+
return renderWeekBody(state.timetable, Math.max(1, schedule.weekAt(now)), schedule.weekdayAt(now), now, bodyRows, cols, state.gridCursor);
|
|
247
278
|
}
|
|
248
279
|
case 'termDensity':
|
|
249
280
|
if (!state.timetable || !state.weekOne)
|
|
250
281
|
return [hint(trans.timetable.genericError)];
|
|
251
282
|
return renderTermDensity(state.timetable.meetings, state.weekOne, createTimetableSchedule(state.timetable, { weekOneMonday: state.weekOne }).weekAt(now), cols).split('\n');
|
|
252
|
-
case 'termPicker':
|
|
253
|
-
|
|
283
|
+
case 'termPicker': {
|
|
284
|
+
if (!state.termField)
|
|
285
|
+
return [];
|
|
286
|
+
const note = state.termPickerNote
|
|
287
|
+
? [
|
|
288
|
+
...headingLines(trans.timetable.hubSwitchTerm, cols),
|
|
289
|
+
'',
|
|
290
|
+
...hintLines(state.termPickerNote, cols),
|
|
291
|
+
'',
|
|
292
|
+
]
|
|
293
|
+
: [];
|
|
294
|
+
return renderListFieldWithContext(note, state.termField, bodyRows, cols);
|
|
295
|
+
}
|
|
254
296
|
case 'unresolved':
|
|
255
297
|
return [
|
|
256
298
|
heading(trans.timetable.unresolvedTitle),
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { createNbtTimetableClient, createTimetableSchedule, timetableToIcs, } from '@nbtca/nbtcal/timetable';
|
|
3
|
-
import { captureFooterHint, passiveFooterHint } from '../chrome.js';
|
|
3
|
+
import { captureFooterHint, digitTabHint, fitFooterHint, passiveFooterHint } from '../chrome.js';
|
|
4
4
|
import { ListField, computeMaxVisible } from '../fields/list-field.js';
|
|
5
5
|
import { TextField } from '../fields/text-field.js';
|
|
6
6
|
import { renderSchedule, hubShortcuts } from './schedule-render.js';
|
|
7
7
|
import { handleGridKey, todayGridCursor } from './schedule-grid-cursor.js';
|
|
8
8
|
import { setVimKeysActive } from '../../core/vim-keys.js';
|
|
9
9
|
import { t } from '../../i18n/index.js';
|
|
10
|
+
import { pickIcon } from '../../core/icons.js';
|
|
11
|
+
import { glyph } from '../../core/theme.js';
|
|
10
12
|
import { AuthError } from '../../auth/errors.js';
|
|
11
13
|
import { loginWithStudentPassword, restoreNbtSession, } from '../../auth/nbt-auth.js';
|
|
12
14
|
import { createSessionStore } from '../../auth/session-store.js';
|
|
@@ -23,6 +25,21 @@ let catalog = [];
|
|
|
23
25
|
let pendingId = '';
|
|
24
26
|
let lifecycleGeneration = 0;
|
|
25
27
|
const closingSessions = new WeakMap();
|
|
28
|
+
function gridKeys() {
|
|
29
|
+
return {
|
|
30
|
+
days: pickIcon('← →', 'left/right'),
|
|
31
|
+
periods: glyph.updown(),
|
|
32
|
+
enter: glyph.enter(),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function gridFooterHint(tabCount, cols) {
|
|
36
|
+
const trans = t();
|
|
37
|
+
const dot = pickIcon('·', '-');
|
|
38
|
+
const keys = gridKeys();
|
|
39
|
+
const local = `${keys.days} ${trans.timetable.footerDay} ${dot} ${keys.periods} ${trans.timetable.footerClass} ${dot} ${keys.enter} ${trans.timetable.footerDetail}`;
|
|
40
|
+
const quit = `Esc ${dot} q ${trans.menu.hintQuit}`;
|
|
41
|
+
return fitFooterHint(cols, `${digitTabHint(tabCount)}${local} ${dot} ${quit} ${dot} ${trans.help.hint}`, `${digitTabHint(tabCount)}${local} ${dot} ${quit}`, `${local} ${dot} ${quit}`, `${local} ${dot} Esc ${dot} q`, local, `Esc ${dot} q`, 'q');
|
|
42
|
+
}
|
|
26
43
|
function isLifecycleActive(ctx, generation) {
|
|
27
44
|
return generation === lifecycleGeneration && ctx.signal?.aborted !== true;
|
|
28
45
|
}
|
|
@@ -299,9 +316,18 @@ export const scheduleView = {
|
|
|
299
316
|
return state.mode === 'loading';
|
|
300
317
|
},
|
|
301
318
|
shortcuts() {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
319
|
+
if ((state.mode !== 'hub' && state.mode !== 'week') || !state.timetable)
|
|
320
|
+
return [];
|
|
321
|
+
const trans = t();
|
|
322
|
+
const keys = gridKeys();
|
|
323
|
+
const grid = [
|
|
324
|
+
{ key: keys.days, label: trans.timetable.helpSwitchDay },
|
|
325
|
+
{ key: keys.periods, label: trans.timetable.helpPickClass },
|
|
326
|
+
{ key: keys.enter, label: trans.timetable.helpOpenClass },
|
|
327
|
+
];
|
|
328
|
+
if (state.mode === 'week')
|
|
329
|
+
return grid;
|
|
330
|
+
return [...grid, ...hubShortcuts(state.timetable).map(({ key, label }) => ({ key, label }))];
|
|
305
331
|
},
|
|
306
332
|
capturesInput() {
|
|
307
333
|
return (state.mode === 'needsLoginId' ||
|
|
@@ -323,7 +349,11 @@ export const scheduleView = {
|
|
|
323
349
|
state.mode === 'meetingDetail' ||
|
|
324
350
|
state.mode === 'unresolved' ||
|
|
325
351
|
state.mode === 'termDensity';
|
|
326
|
-
|
|
352
|
+
if (passive)
|
|
353
|
+
return passiveFooterHint(tabCount, cols);
|
|
354
|
+
return state.mode === 'hub' || state.mode === 'week'
|
|
355
|
+
? gridFooterHint(tabCount, cols)
|
|
356
|
+
: undefined;
|
|
327
357
|
},
|
|
328
358
|
handleBack(ctx) {
|
|
329
359
|
if (state.mode === 'needsLoginId') {
|
|
@@ -491,12 +521,21 @@ export const scheduleView = {
|
|
|
491
521
|
label: tm.academicYearLabel,
|
|
492
522
|
...(tm.current ? { hint: t().common.current } : {}),
|
|
493
523
|
}));
|
|
524
|
+
const note = options.length > 0
|
|
525
|
+
? undefined
|
|
526
|
+
: session
|
|
527
|
+
? t().timetable.noTerms
|
|
528
|
+
: t().timetable.termPickerNeedsLogin;
|
|
529
|
+
if (!session && options.length === 0) {
|
|
530
|
+
options.push({ value: '__login__', label: t().timetable.termPickerLoginAction });
|
|
531
|
+
}
|
|
494
532
|
options.push({ value: '__back__', label: t().common.back });
|
|
495
533
|
state = {
|
|
496
534
|
...state,
|
|
497
535
|
mode: 'termPicker',
|
|
536
|
+
...(note === undefined ? {} : { termPickerNote: note }),
|
|
498
537
|
termField: new ListField({
|
|
499
|
-
title: t().timetable.hubSwitchTerm,
|
|
538
|
+
...(note === undefined ? { title: t().timetable.hubSwitchTerm } : {}),
|
|
500
539
|
options,
|
|
501
540
|
maxVisible: computeMaxVisible(ctx.bodyRows),
|
|
502
541
|
}),
|
|
@@ -576,6 +615,10 @@ export const scheduleView = {
|
|
|
576
615
|
returnToHub();
|
|
577
616
|
return;
|
|
578
617
|
}
|
|
618
|
+
if (result.selected === '__login__') {
|
|
619
|
+
goToLoginId();
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
579
622
|
const term = resolveTerm(catalog, result.selected);
|
|
580
623
|
const newTermKey = termKey(term);
|
|
581
624
|
const weekOne = loadWeekOne(newTermKey);
|
|
@@ -5,6 +5,7 @@ import { resetIconCache, pickIcon } from '../../core/icons.js';
|
|
|
5
5
|
import { APP_INFO, URLS } from '../../config/data.js';
|
|
6
6
|
import { t, getCurrentLanguage, saveLanguagePreference, clearTranslationCache, } from '../../i18n/index.js';
|
|
7
7
|
import { padEndV } from '../../core/text.js';
|
|
8
|
+
import { type } from '../../core/theme.js';
|
|
8
9
|
import { resetCapabilities } from '../../core/capabilities.js';
|
|
9
10
|
let state = { mode: 'menu' };
|
|
10
11
|
function currentHint(current, hint) {
|
|
@@ -45,7 +46,7 @@ function buildMenuField(statusMessage) {
|
|
|
45
46
|
return {
|
|
46
47
|
mode: 'menu',
|
|
47
48
|
...(statusMessage === undefined ? {} : { statusMessage }),
|
|
48
|
-
menuField: new ListField({
|
|
49
|
+
menuField: new ListField({ options }),
|
|
49
50
|
};
|
|
50
51
|
}
|
|
51
52
|
function goToMenu(statusMessage) {
|
|
@@ -112,7 +113,7 @@ export const settingsView = {
|
|
|
112
113
|
state = {
|
|
113
114
|
mode: 'icon',
|
|
114
115
|
subField: new ListField({
|
|
115
|
-
title: trans.theme.
|
|
116
|
+
title: trans.theme.iconMode,
|
|
116
117
|
options,
|
|
117
118
|
initialIndex: idx,
|
|
118
119
|
}),
|
|
@@ -126,7 +127,7 @@ export const settingsView = {
|
|
|
126
127
|
state = {
|
|
127
128
|
mode: 'color',
|
|
128
129
|
subField: new ListField({
|
|
129
|
-
title: trans.theme.
|
|
130
|
+
title: trans.theme.colorMode,
|
|
130
131
|
options,
|
|
131
132
|
initialIndex: idx,
|
|
132
133
|
}),
|
|
@@ -147,6 +148,8 @@ export const settingsView = {
|
|
|
147
148
|
state = {
|
|
148
149
|
mode: 'about',
|
|
149
150
|
aboutLines: [
|
|
151
|
+
type.heading(trans.about.title),
|
|
152
|
+
'',
|
|
150
153
|
row(trans.about.project, APP_INFO.name),
|
|
151
154
|
row(trans.about.version, `v${APP_INFO.version}`),
|
|
152
155
|
row(trans.about.description, trans.about.descriptionText),
|
|
@@ -158,7 +161,7 @@ export const settingsView = {
|
|
|
158
161
|
row(trans.about.license, `MIT ${pickIcon('·', '-')} ${trans.about.author}: m1ngsama`),
|
|
159
162
|
],
|
|
160
163
|
backField: new ListField({
|
|
161
|
-
title:
|
|
164
|
+
title: '',
|
|
162
165
|
options: [{ value: '__back__', label: trans.common.back }],
|
|
163
166
|
}),
|
|
164
167
|
};
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
const CAMPUS_DOMAIN = 'nbt.edu.cn';
|
|
2
|
+
const MAX_COOKIES = 100;
|
|
3
|
+
const MAX_PAIR_LENGTH = 4096;
|
|
4
|
+
const MAX_ATTRIBUTE_LENGTH = 1024;
|
|
5
|
+
const MAX_LIFETIME_MS = 400 * 24 * 60 * 60 * 1000;
|
|
6
|
+
const CONTROL = /[\u0000-\u001f\u007f]/;
|
|
7
|
+
const DATE_DELIMITER = /[\x09\x20-\x2f\x3b-\x40\x5b-\x60\x7b-\x7e]+/;
|
|
8
|
+
const MONTHS = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
|
|
9
|
+
function isCampusDomain(domain) {
|
|
10
|
+
return domain === CAMPUS_DOMAIN || domain.endsWith(`.${CAMPUS_DOMAIN}`);
|
|
11
|
+
}
|
|
12
|
+
function domainMatches(host, domain) {
|
|
13
|
+
return host === domain || host.endsWith(`.${domain}`);
|
|
14
|
+
}
|
|
15
|
+
function pathMatches(requestPath, cookiePath) {
|
|
16
|
+
return (requestPath === cookiePath ||
|
|
17
|
+
(requestPath.startsWith(cookiePath) &&
|
|
18
|
+
(cookiePath.endsWith('/') || requestPath[cookiePath.length] === '/')));
|
|
19
|
+
}
|
|
20
|
+
function defaultPath(requestPath) {
|
|
21
|
+
const lastSlash = requestPath.lastIndexOf('/');
|
|
22
|
+
return lastSlash <= 0 ? '/' : requestPath.slice(0, lastSlash);
|
|
23
|
+
}
|
|
24
|
+
function parseCookieDate(text) {
|
|
25
|
+
let time;
|
|
26
|
+
let day;
|
|
27
|
+
let month;
|
|
28
|
+
let year;
|
|
29
|
+
for (const token of text.split(DATE_DELIMITER)) {
|
|
30
|
+
let match;
|
|
31
|
+
if (!time && (match = /^(\d{1,2}):(\d{1,2}):(\d{1,2})(?!\d)/.exec(token))) {
|
|
32
|
+
time = match.slice(1).map(Number);
|
|
33
|
+
}
|
|
34
|
+
else if (day === undefined && (match = /^\d{1,2}(?!\d)/.exec(token))) {
|
|
35
|
+
day = Number(match[0]);
|
|
36
|
+
}
|
|
37
|
+
else if (month === undefined && MONTHS.includes(token.slice(0, 3).toLowerCase())) {
|
|
38
|
+
month = MONTHS.indexOf(token.slice(0, 3).toLowerCase());
|
|
39
|
+
}
|
|
40
|
+
else if (year === undefined && (match = /^\d{2,4}(?!\d)/.exec(token))) {
|
|
41
|
+
year = Number(match[0]);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (!time || day === undefined || month === undefined || year === undefined)
|
|
45
|
+
return undefined;
|
|
46
|
+
if (year >= 70 && year <= 99)
|
|
47
|
+
year += 1900;
|
|
48
|
+
else if (year <= 69)
|
|
49
|
+
year += 2000;
|
|
50
|
+
const [hours = 0, minutes = 0, seconds = 0] = time;
|
|
51
|
+
if (day < 1 || year < 1601 || hours > 23 || minutes > 59 || seconds > 59)
|
|
52
|
+
return undefined;
|
|
53
|
+
const date = new Date(Date.UTC(year, month, day, hours, minutes, seconds));
|
|
54
|
+
return date.getUTCMonth() === month && date.getUTCDate() === day ? date.getTime() : undefined;
|
|
55
|
+
}
|
|
56
|
+
function isStoredCookie(value) {
|
|
57
|
+
if (typeof value !== 'object' || value === null)
|
|
58
|
+
return false;
|
|
59
|
+
const cookie = value;
|
|
60
|
+
return (typeof cookie['name'] === 'string' &&
|
|
61
|
+
cookie['name'] !== '' &&
|
|
62
|
+
!CONTROL.test(cookie['name']) &&
|
|
63
|
+
typeof cookie['value'] === 'string' &&
|
|
64
|
+
!CONTROL.test(cookie['value']) &&
|
|
65
|
+
typeof cookie['domain'] === 'string' &&
|
|
66
|
+
isCampusDomain(cookie['domain']) &&
|
|
67
|
+
typeof cookie['path'] === 'string' &&
|
|
68
|
+
cookie['path'].startsWith('/') &&
|
|
69
|
+
typeof cookie['hostOnly'] === 'boolean' &&
|
|
70
|
+
typeof cookie['secure'] === 'boolean' &&
|
|
71
|
+
typeof cookie['httpOnly'] === 'boolean' &&
|
|
72
|
+
(cookie['expires'] === undefined || Number.isFinite(cookie['expires'])));
|
|
73
|
+
}
|
|
74
|
+
function isSerializedJar(value) {
|
|
75
|
+
if (typeof value !== 'object' || value === null)
|
|
76
|
+
return false;
|
|
77
|
+
const { version, cookies } = value;
|
|
78
|
+
return (version === 1 &&
|
|
79
|
+
Array.isArray(cookies) &&
|
|
80
|
+
cookies.length <= MAX_COOKIES &&
|
|
81
|
+
cookies.every(isStoredCookie));
|
|
82
|
+
}
|
|
83
|
+
export function createCookieJar(serialized) {
|
|
84
|
+
const cookies = new Map();
|
|
85
|
+
const keyOf = (cookie) => JSON.stringify([cookie.domain, cookie.path, cookie.name]);
|
|
86
|
+
if (serialized !== undefined) {
|
|
87
|
+
if (!isSerializedJar(serialized))
|
|
88
|
+
throw new TypeError('Unsupported cookie jar.');
|
|
89
|
+
for (const { name, value, domain, path, hostOnly, secure, httpOnly, expires, } of serialized.cookies) {
|
|
90
|
+
const cookie = { name, value, domain, path, hostOnly, secure, httpOnly };
|
|
91
|
+
cookies.set(keyOf(cookie), expires === undefined ? cookie : { ...cookie, expires });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function isExpired(cookie, now) {
|
|
95
|
+
return cookie.expires !== undefined && cookie.expires <= now;
|
|
96
|
+
}
|
|
97
|
+
function storeOne(url, header, now) {
|
|
98
|
+
const [pair = '', ...attributes] = header.trim().split(';');
|
|
99
|
+
const separator = pair.indexOf('=');
|
|
100
|
+
const name = pair.slice(0, separator).trim();
|
|
101
|
+
const value = pair.slice(separator + 1).trim();
|
|
102
|
+
if (separator <= 0 || !name || CONTROL.test(name) || CONTROL.test(value))
|
|
103
|
+
return;
|
|
104
|
+
if (name.length + value.length > MAX_PAIR_LENGTH)
|
|
105
|
+
return;
|
|
106
|
+
let domain;
|
|
107
|
+
let path;
|
|
108
|
+
let expires;
|
|
109
|
+
let maxAge;
|
|
110
|
+
let secure = false;
|
|
111
|
+
let httpOnly = false;
|
|
112
|
+
for (const attribute of attributes) {
|
|
113
|
+
const split = attribute.indexOf('=');
|
|
114
|
+
const key = (split === -1 ? attribute : attribute.slice(0, split)).trim().toLowerCase();
|
|
115
|
+
const argument = split === -1 ? '' : attribute.slice(split + 1).trim();
|
|
116
|
+
if (argument.length > MAX_ATTRIBUTE_LENGTH)
|
|
117
|
+
continue;
|
|
118
|
+
if (key === 'expires')
|
|
119
|
+
expires = parseCookieDate(argument) ?? expires;
|
|
120
|
+
else if (key === 'max-age' && /^-?\d+$/.test(argument))
|
|
121
|
+
maxAge = Number(argument);
|
|
122
|
+
else if (key === 'domain' && argument.replace(/^\./, ''))
|
|
123
|
+
domain = argument.replace(/^\./, '').toLowerCase();
|
|
124
|
+
else if (key === 'path')
|
|
125
|
+
path = argument.startsWith('/') ? argument : undefined;
|
|
126
|
+
else if (key === 'secure')
|
|
127
|
+
secure = true;
|
|
128
|
+
else if (key === 'httponly')
|
|
129
|
+
httpOnly = true;
|
|
130
|
+
}
|
|
131
|
+
const host = url.hostname;
|
|
132
|
+
if (domain !== undefined && !domainMatches(host, domain))
|
|
133
|
+
return;
|
|
134
|
+
const cookie = {
|
|
135
|
+
name,
|
|
136
|
+
value,
|
|
137
|
+
domain: domain ?? host,
|
|
138
|
+
path: path ?? defaultPath(url.pathname),
|
|
139
|
+
hostOnly: domain === undefined,
|
|
140
|
+
secure,
|
|
141
|
+
httpOnly,
|
|
142
|
+
};
|
|
143
|
+
if (!isCampusDomain(cookie.domain))
|
|
144
|
+
return;
|
|
145
|
+
if (secure && url.protocol !== 'https:')
|
|
146
|
+
return;
|
|
147
|
+
if (name.startsWith('__Secure-') && !secure)
|
|
148
|
+
return;
|
|
149
|
+
if (name.startsWith('__Host-') && (!secure || !cookie.hostOnly || cookie.path !== '/'))
|
|
150
|
+
return;
|
|
151
|
+
const expiry = maxAge === undefined ? expires : maxAge <= 0 ? 0 : now + maxAge * 1000;
|
|
152
|
+
if (expiry !== undefined)
|
|
153
|
+
cookie.expires = Math.min(expiry, now + MAX_LIFETIME_MS);
|
|
154
|
+
const key = keyOf(cookie);
|
|
155
|
+
if (isExpired(cookie, now)) {
|
|
156
|
+
cookies.delete(key);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
cookies.set(key, cookie);
|
|
160
|
+
if (cookies.size <= MAX_COOKIES)
|
|
161
|
+
return;
|
|
162
|
+
for (const [staleKey, stale] of cookies)
|
|
163
|
+
if (isExpired(stale, now))
|
|
164
|
+
cookies.delete(staleKey);
|
|
165
|
+
for (const staleKey of cookies.keys()) {
|
|
166
|
+
if (cookies.size <= MAX_COOKIES)
|
|
167
|
+
break;
|
|
168
|
+
cookies.delete(staleKey);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
store(url, setCookieHeaders) {
|
|
173
|
+
const now = Date.now();
|
|
174
|
+
for (const header of setCookieHeaders)
|
|
175
|
+
storeOne(url, header, now);
|
|
176
|
+
},
|
|
177
|
+
cookieHeader(url) {
|
|
178
|
+
const now = Date.now();
|
|
179
|
+
const matches = [];
|
|
180
|
+
for (const [key, cookie] of cookies) {
|
|
181
|
+
if (isExpired(cookie, now))
|
|
182
|
+
cookies.delete(key);
|
|
183
|
+
else if ((cookie.hostOnly
|
|
184
|
+
? url.hostname === cookie.domain
|
|
185
|
+
: domainMatches(url.hostname, cookie.domain)) &&
|
|
186
|
+
pathMatches(url.pathname, cookie.path) &&
|
|
187
|
+
(!cookie.secure || url.protocol === 'https:'))
|
|
188
|
+
matches.push(cookie);
|
|
189
|
+
}
|
|
190
|
+
return matches
|
|
191
|
+
.sort((a, b) => b.path.length - a.path.length)
|
|
192
|
+
.map((cookie) => `${cookie.name}=${cookie.value}`)
|
|
193
|
+
.join('; ');
|
|
194
|
+
},
|
|
195
|
+
serialize() {
|
|
196
|
+
const now = Date.now();
|
|
197
|
+
return {
|
|
198
|
+
version: 1,
|
|
199
|
+
cookies: [...cookies.values()].filter((cookie) => !isExpired(cookie, now)),
|
|
200
|
+
};
|
|
201
|
+
},
|
|
202
|
+
clear() {
|
|
203
|
+
cookies.clear();
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|