Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from services.account_ui import render_account_menu, render_account_page
from services.accessibility import render_accessibility_controls
from services.page_registry import existing_focus_pages
from services.study_navigation import render_study_context
from services.ui_style import BRAND_LOGO, BRAND_PLANE, apply_app_styles
from services.tutor_assistant_ui import clear_tutor_browser_state, render_tutor_assistant

Expand Down Expand Up @@ -145,8 +146,7 @@
render_account_menu(account_page)

if selected_course := st.session_state.get("current_course"):
with st.container(key="flight_course_context"):
st.caption(f"{selected_course.course_name} / {navigation.title}")
render_study_context(selected_course, navigation.url_path, navigation.title)

render_tutor_assistant()
navigation.run()
47 changes: 47 additions & 0 deletions assets/paper_zz_coherence.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* Quiet shared affordances across the existing paper pages. */
[data-testid="stApp"] {
--exam-muted: var(--ep-text-secondary);
--exam-blue: var(--ep-action);
--exam-blue-dark: var(--ep-action-hover);
}
[data-testid="stMain"] :is(button, input, textarea, [role="tab"]):focus-visible,
[data-testid="stSidebarNav"] a:focus-visible {
outline: 2px solid var(--ep-focus);
outline-offset: 3px;
}
.st-key-flight_course_context {
padding: var(--ep-space-2) 0 var(--ep-space-3);
border-bottom: 1px solid var(--ep-border);
margin-bottom: var(--ep-space-4);
}
.st-key-flight_course_context [data-testid="stCaptionContainer"] { margin: 0; }
.st-key-study_return_action button { min-height: var(--ep-control-height); }
.st-key-practice_paused_notice {
border-left: 3px solid var(--ep-rust-700);
background: var(--ep-surface-subtle);
border-radius: var(--ep-radius-control);
padding: var(--ep-space-3) var(--ep-space-4);
margin-block: var(--ep-space-2) var(--ep-space-4);
}
.st-key-practice_paused_notice p { margin: 0; color: var(--ep-text-primary); }
.flight-clock.is-paused { border-color: var(--ep-rust-700); background: var(--ep-surface-subtle); }
.flight-waypoint.is-current { display: grid; place-items: center; background: transparent; }
.flight-waypoint.is-current svg { display: block; width: 26px; height: 22px; }
[data-testid="stMain"] .st-key-study_return_action button { white-space: normal; }
@media (max-width: 640px) {
.st-key-flight_course_context [data-testid="stHorizontalBlock"] { flex-wrap: wrap; gap: var(--ep-space-2); }
.st-key-study_return_action { margin-left: 0; max-width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
.flight-waypoint, .tutor-bubble { animation: none !important; transition: none !important; }
}
/* On phones the open sidebar owns the screen. Do not cover its collapse
control or accessibility menu with fixed account/Pilot controls. */
@media (max-width: 760px) {
[data-testid="stApp"]:has(section[data-testid="stSidebar"][aria-expanded="true"]) :is(.st-key-account_menu, .st-key-floating_tutor) {
visibility: hidden;
pointer-events: none;
}
[data-testid="stSidebarCollapseButton"] button,
button[data-testid="stExpandSidebarButton"] { min-width: 44px; min-height: 44px; }
}
56 changes: 34 additions & 22 deletions assets/tutor_assistant.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 24 additions & 2 deletions assets/tutor_assistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ export default function(component) {
left: visual ? visual.offsetLeft : 0, top: visual ? visual.offsetTop : 0 };
};
const clamp = (value, min, max) => Math.min(Math.max(value, min), Math.max(min, max));
const avoidFocusedControl = () => {
if (state.open) return;
const active = document.activeElement;
if (!active || active === document.body || active === bubble || active.contains(root)) return;
const focusTarget = active.matches('input[type="radio"], input[type="checkbox"]') ? active.closest("label") || active : active;
const target = focusTarget.getBoundingClientRect();
const entry = bubble.getBoundingClientRect();
if (!target.width || !target.height || target.bottom <= entry.top || target.top >= entry.bottom
|| target.right <= entry.left || target.left >= entry.right) return;
const view = viewport();
const headerBottom = document.querySelector('[data-testid="stHeader"]')?.getBoundingClientRect().bottom || view.top;
const above = target.top - entry.height - 12;
const below = target.bottom + 12;
const y = above >= Math.max(view.top + 12, headerBottom + 12) ? above : below;
bubble.style.top = `${clamp(y, Math.max(view.top + 12, headerBottom + 12), view.top + view.height - entry.height - 12)}px`;
};
const position = () => {
const view = viewport();
const margin = 12;
Expand Down Expand Up @@ -127,6 +143,7 @@ export default function(component) {
bubble.classList.toggle('is-panel-overlap', state.open && overlap);
bubble.tabIndex = state.open && overlap ? -1 : 0;
bubble.setAttribute('aria-hidden', String(state.open && overlap));
avoidFocusedControl();
};
const updateInput = () => {
const busy = Boolean(state.pending);
Expand Down Expand Up @@ -191,13 +208,13 @@ export default function(component) {
if (!destroyed && !question.disabled) question.focus({ preventScroll: true });
});
};
const closePanel = () => {
const closePanel = (restoreFocus = true) => {
state.open = false;
panel.hidden = true;
bubble.setAttribute('aria-expanded', 'false');
bubble.setAttribute('aria-label', text('Open Pilot, your AI study assistant', '打开 Pilot AI 学习助手'));
position();
bubble.focus({ preventScroll: true });
if (restoreFocus) bubble.focus({ preventScroll: true });
};
const submit = (event) => {
if (event) event.preventDefault();
Expand Down Expand Up @@ -320,6 +337,11 @@ export default function(component) {
state.validation = '';
setTriggerValue('clear', { request_id: crypto.randomUUID(), session_id: data.session_id, course_id: courseId });
});
// A non-modal helper must not conceal keyboard focus in the study page.
on(document, 'focusin', event => {
if (state.open && !event.composedPath().includes(root)) closePanel(false);
avoidFocusedControl();
});
on(window, 'resize', position);
if (window.visualViewport) {
on(window.visualViewport, 'resize', position);
Expand Down
Loading
Loading