From 7a8a3cb70ef8d38087440a427b468c72bc7c5712 Mon Sep 17 00:00:00 2001 From: Aden Lindsay Date: Mon, 7 Sep 2026 10:28:11 +0930 Subject: [PATCH] fix: remove svelte sidebar but keep customisations --- src/css/injected.scss | 219 +-------- src/css/injected/performance-mode.scss | 35 -- src/css/injected/sidebar-animation.scss | 241 ++++------ src/css/injected/sidebar-styles.scss | 38 +- .../gradeAnalytics/injectAnalyticsMenuItem.ts | 16 +- src/plugins/monofile.ts | 13 +- src/seqta/ui/AddBetterSEQTAElements.ts | 61 +-- src/seqta/ui/sidebar/Sidebar.svelte | 455 ------------------ src/seqta/ui/sidebar/SidebarItem.svelte | 246 ---------- src/seqta/ui/sidebar/applyNativeSidebar.ts | 109 +++++ src/seqta/ui/sidebar/customMenuActive.test.ts | 87 ---- src/seqta/ui/sidebar/customMenuActive.ts | 72 --- src/seqta/ui/sidebar/index.ts | 25 +- src/seqta/ui/sidebar/mountCustomSidebar.ts | 409 ---------------- src/seqta/ui/sidebar/parseNativeMenu.test.ts | 224 --------- src/seqta/ui/sidebar/parseNativeMenu.ts | 6 +- src/seqta/ui/sidebar/sidebarDrillReturn.ts | 198 ++++++++ src/seqta/ui/sidebar/sidebarState.svelte.ts | 401 --------------- src/seqta/utils/Openers/OpenMenuOptions.ts | 8 - src/seqta/utils/menuItemVisibility.ts | 4 +- 20 files changed, 484 insertions(+), 2383 deletions(-) delete mode 100644 src/seqta/ui/sidebar/Sidebar.svelte delete mode 100644 src/seqta/ui/sidebar/SidebarItem.svelte create mode 100644 src/seqta/ui/sidebar/applyNativeSidebar.ts delete mode 100644 src/seqta/ui/sidebar/customMenuActive.test.ts delete mode 100644 src/seqta/ui/sidebar/customMenuActive.ts delete mode 100644 src/seqta/ui/sidebar/mountCustomSidebar.ts delete mode 100644 src/seqta/ui/sidebar/parseNativeMenu.test.ts create mode 100644 src/seqta/ui/sidebar/sidebarDrillReturn.ts delete mode 100644 src/seqta/ui/sidebar/sidebarState.svelte.ts diff --git a/src/css/injected.scss b/src/css/injected.scss index c6b69265..d0b6486b 100644 --- a/src/css/injected.scss +++ b/src/css/injected.scss @@ -541,8 +541,7 @@ ul.magicDelete > li.deleting { visibility: visible !important; } -/* Edit rows should match normal custom-sidebar item size (not shrunk). */ -#menu.bsplus-sidebar-edit-mode > #bsplus-sidebar-root > li.item.draggable, +/* Edit rows should match normal sidebar item size (not shrunk). */ #menu.bsplus-sidebar-edit-mode .item.draggable { display: flex !important; align-items: center !important; @@ -628,26 +627,6 @@ ul.magicDelete > li.deleting { transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1); } -/* Hide native menu as soon as possible (during loading), before Svelte mounts. - Keep `#bsplus-sidebar-root` visible — themes target `#menu > ul > li.item` on it. */ -html.bsplus-custom-sidebar-pending #menu > ul:not(#bsplus-sidebar-root), -html.bsplus-custom-sidebar-pending #menu > #userInfo, -html.bsplus-custom-sidebar-pending #menu > .icon-cover, -#menu.bsplus-custom-sidebar > ul:not(#bsplus-sidebar-root), -#menu.bsplus-custom-sidebar > #userInfo, -#menu.bsplus-custom-sidebar > .icon-cover { - position: absolute !important; - left: -10000px !important; - width: 1px !important; - height: 1px !important; - margin: 0 !important; - padding: 0 !important; - overflow: hidden !important; - opacity: 0 !important; - pointer-events: none !important; - clip: rect(0, 0, 0, 0) !important; -} - /* Custom title bar: keep native `#title` children for sync, hide them visually. Loading overlay stays until waitForCustomTitleBarReady() so this is ready underneath. */ html.bsplus-custom-title-pending #title > :not(#bsplus-title-root), @@ -674,179 +653,6 @@ html.bsplus-custom-title-pending #title > :not(#bsplus-title-root), align-items: center; } -/* Custom Svelte sidebar: keep `#menu > ul > li.item` / `.sub` shape for theme CSS. */ -#menu.bsplus-custom-sidebar { - position: absolute !important; - top: 0 !important; - bottom: 0 !important; - left: 0 !important; - display: flex !important; - flex-direction: column !important; - box-sizing: border-box !important; - height: auto !important; - max-height: none !important; - overflow: hidden !important; - - > #bsplus-sidebar-root { - flex: 1 1 auto; - min-height: 0; - width: 100%; - height: 100%; - z-index: 2; - position: relative; - padding-top: 0 !important; - - /* - * Extend the logo spacer for the same gap as between items. - * SEQTA's #menu>ul::before border-bottom is the hairline under the logo. - */ - &::before { - box-shadow: none !important; - border-bottom: none !important; - height: calc(71px + 8px) !important; - } - } - - li.hasChildren { - position: static !important; - } - - /* Native list may keep `.active` after click-through; force our rows clickable, - then lock siblings only while a custom drill `.sub` is open. */ - > #bsplus-sidebar-root .bsplus-sidebar-item { - width: auto !important; - max-width: none !important; - margin: 0 6px 8px !important; - box-sizing: border-box !important; - } - - /* Open folder rows wrap the absolute `.sub` panel. Filters/overflow on the - row clip every course/assessment label (especially glass + Edge). */ - > #bsplus-sidebar-root .bsplus-sidebar-item:has(> .sub) { - overflow: visible !important; - backdrop-filter: none !important; - -webkit-backdrop-filter: none !important; - contain: none !important; - background: transparent !important; - box-shadow: none !important; - } - - > #bsplus-sidebar-root > li.item { - pointer-events: auto !important; - } - - &:has(> #bsplus-sidebar-root > li.hasChildren.bsplus-active > .sub) - > #bsplus-sidebar-root - > li:not(.hasChildren.bsplus-active), - &:has(> #bsplus-sidebar-root > li.hasChildren.bsplus-active > .sub) - > #bsplus-sidebar-root - > li:not(.hasChildren.bsplus-active) - * { - pointer-events: none !important; - } - - /* Same locks keyed off `.drilling` so nested leaf clicks do not flicker when - SEQTA briefly strips `.active` from folder rows. */ - > #bsplus-sidebar-root.drilling > li:not(.hasChildren), - > #bsplus-sidebar-root.drilling > li:not(.hasChildren) * { - pointer-events: none !important; - } - - > #bsplus-sidebar-root .sub { - pointer-events: none; - } - - > #bsplus-sidebar-root li.hasChildren.bsplus-active > .sub { - pointer-events: auto; - background: transparent !important; - background-image: none !important; - } - - > #bsplus-sidebar-root li.hasChildren.bsplus-active > .sub:not(.bsplus-sub-enter) { - transform: none; - } - - > #bsplus-sidebar-root li.hasChildren.bsplus-active - > .sub:has(.hasChildren.bsplus-active) { - pointer-events: none !important; - } - - > #bsplus-sidebar-root li.hasChildren.bsplus-active - .hasChildren.bsplus-active - > .sub { - pointer-events: auto !important; - background: transparent !important; - background-image: none !important; - } - - > #bsplus-sidebar-root.drilling li.hasChildren > .sub:not(:has(.sub)) { - pointer-events: auto !important; - background: transparent !important; - background-image: none !important; - } - - > #bsplus-sidebar-root.drilling li.hasChildren > .sub:has(.sub) { - pointer-events: none !important; - } - - > #bsplus-sidebar-root.drilling li.hasChildren > .sub .sub { - pointer-events: auto !important; - background: transparent !important; - background-image: none !important; - } - - > #bsplus-sidebar-root > li.hasChildren.bsplus-active > label, - > #bsplus-sidebar-root.drilling > li.hasChildren > label { - pointer-events: none !important; - } - - /* Theme decorations on root leaves (Beach palm/sand) must not show through - the transparent drill `.sub` panel. */ - > #bsplus-sidebar-root:has(> li.hasChildren.bsplus-active > .sub) - > li:not(.hasChildren.bsplus-active)::before, - > #bsplus-sidebar-root:has(> li.hasChildren.bsplus-active > .sub) - > li:not(.hasChildren.bsplus-active)::after { - content: none !important; - display: none !important; - animation: none !important; - opacity: 0 !important; - } - - > #bsplus-sidebar-root.drilling:not(.drill-entering) > li:not(.hasChildren)::before, - > #bsplus-sidebar-root.drilling:not(.drill-entering) > li:not(.hasChildren)::after { - content: none !important; - display: none !important; - animation: none !important; - opacity: 0 !important; - } - - #bsplus-sidebar-root .sub .back { - display: flex; - align-items: center; - gap: 4px; - padding: 12px 16px 8px; - cursor: pointer; - font-weight: 700; - color: inherit; - } - - #bsplus-sidebar-root .sub .back:hover { - opacity: 0.9; - } - - #bsplus-sidebar-root .sub .backLabel { - font-size: 16px; - font-weight: 700; - } - - #bsplus-sidebar-root .sub > ul { - list-style: none; - margin: 0; - padding: 8px 0 16px; - } - -} - #menu li > label > svg, #menu section > label > svg { margin: 0 10px 0 4px; @@ -942,19 +748,6 @@ body.icon-only-sidebar:not(:has(#menu li.hasChildren:is(.active, .bsplus-active) } -/* Icon-only + drill: keep subject/back labels visible even if `:has()` misses. */ -body.icon-only-sidebar #menu.bsplus-custom-sidebar #bsplus-sidebar-root.drilling { - li > label, - li > label span, - .backLabel { - display: inline !important; - font-size: 16px !important; - } - - li > label { - display: flex !important; - } -} [class*="notifications__items___"] { -ms-overflow-style: none !important; scrollbar-width: none !important; @@ -1032,10 +825,6 @@ body > .sortable-fallback.bsplus-sortable-drag, li.active > .sub > ul > .active { background: rgba(0, 0, 0, 0.3) !important; } - - li.hasChildren.bsplus-active > .sub > ul > .bsplus-sidebar-item.bsplus-active:not(.hasChildren) { - background: rgba(0, 0, 0, 0.3) !important; - } } #userActions { @@ -1166,9 +955,9 @@ ol:has([class*="MessageList__avatar___"] svg) { -webkit-box-shadow: 0px 5px 16px 6px rgba(0, 0, 0, 0.2) !important; box-shadow: 0px 0px 4px 2px rgba(0, 0, 0, 0.2) !important; } -/* Custom sidebar: keep title depth to the right, not a hairline under the logo into the menu. */ -body:has(#menu.bsplus-custom-sidebar) #container #content #title, -body:has(#menu.bsplus-custom-sidebar).menuShown #container #content #title { +/* Styled sidebar: keep title depth to the right, not a hairline under the logo into the menu. */ +body:has(#menu.bsplus-styled-sidebar) #container #content #title, +body:has(#menu.bsplus-styled-sidebar).menuShown #container #content #title { -webkit-box-shadow: 6px 0 8px -4px rgba(0, 0, 0, 0.25) !important; box-shadow: 6px 0 8px -4px rgba(0, 0, 0, 0.25) !important; } diff --git a/src/css/injected/performance-mode.scss b/src/css/injected/performance-mode.scss index 56d80f38..c6ff5a25 100644 --- a/src/css/injected/performance-mode.scss +++ b/src/css/injected/performance-mode.scss @@ -49,38 +49,3 @@ html.performanceMode [class*="backdrop-blur"] { backdrop-filter: none !important; -webkit-backdrop-filter: none !important; } - -/* Sidebar drill locks: `.drilling` on the list handles pointer-events in perf mode — - skip expensive `:has()` selectors that drive hit-test cost during mouse moves. */ -html.performanceMode #menu.bsplus-custom-sidebar { - &:has(> #bsplus-sidebar-root > li.hasChildren.bsplus-active > .sub) - > #bsplus-sidebar-root - > li:not(.hasChildren.bsplus-active), - &:has(> #bsplus-sidebar-root > li.hasChildren.bsplus-active > .sub) - > #bsplus-sidebar-root - > li:not(.hasChildren.bsplus-active) - * { - pointer-events: unset !important; - } - - > #bsplus-sidebar-root:has(> li.hasChildren.bsplus-active > .sub) - > li:not(.hasChildren.bsplus-active)::before, - > #bsplus-sidebar-root:has(> li.hasChildren.bsplus-active > .sub) - > li:not(.hasChildren.bsplus-active)::after { - content: none !important; - display: none !important; - } - - > #bsplus-sidebar-root li.hasChildren.bsplus-active - > .sub:has(.hasChildren.bsplus-active) { - pointer-events: unset !important; - } - - > #bsplus-sidebar-root.drilling li.hasChildren > .sub:not(:has(.sub)) { - pointer-events: auto !important; - } - - > #bsplus-sidebar-root.drilling li.hasChildren > .sub:has(.sub) { - pointer-events: unset !important; - } -} diff --git a/src/css/injected/sidebar-animation.scss b/src/css/injected/sidebar-animation.scss index d5124c41..9bbd4c50 100644 --- a/src/css/injected/sidebar-animation.scss +++ b/src/css/injected/sidebar-animation.scss @@ -8,14 +8,14 @@ overflow-y: scroll !important; } -#menu:not(.bsplus-custom-sidebar) > ul:has(li.hasChildren:is(.active, .bsplus-active)) > li::before, -#menu:not(.bsplus-custom-sidebar) > ul:has(li.hasChildren:is(.active, .bsplus-active)) > li::after, -#menu:not(.bsplus-custom-sidebar) > ul ul:has(li.hasChildren:is(.active, .bsplus-active)) > li::before, -#menu:not(.bsplus-custom-sidebar) > ul ul:has(li.hasChildren:is(.active, .bsplus-active)) > li::after, -#menu:not(.bsplus-custom-sidebar) > ul:has(li.hasChildren:is(.active, .bsplus-active)) > li > label, -#menu:not(.bsplus-custom-sidebar) > ul:has(li.hasChildren:is(.active, .bsplus-active)) > li > svg, -#menu:not(.bsplus-custom-sidebar) > ul ul:has(li.hasChildren:is(.active, .bsplus-active)) > li > label, -#menu:not(.bsplus-custom-sidebar) > ul ul:has(li.hasChildren:is(.active, .bsplus-active)) > li > svg { +#menu > ul:has(li.hasChildren:is(.active, .bsplus-active)) > li::before, +#menu > ul:has(li.hasChildren:is(.active, .bsplus-active)) > li::after, +#menu > ul ul:has(li.hasChildren:is(.active, .bsplus-active)) > li::before, +#menu > ul ul:has(li.hasChildren:is(.active, .bsplus-active)) > li::after, +#menu > ul:has(li.hasChildren:is(.active, .bsplus-active)) > li > label, +#menu > ul:has(li.hasChildren:is(.active, .bsplus-active)) > li > svg, +#menu > ul ul:has(li.hasChildren:is(.active, .bsplus-active)) > li > label, +#menu > ul ul:has(li.hasChildren:is(.active, .bsplus-active)) > li > svg { /* !important beats theme animations (e.g. Beach palm-slide forwards). */ transform: translateX(-320px) !important; animation: none !important; @@ -26,19 +26,56 @@ transition: transform 0.3s ease; } +/* Frontmost drill panel: rows move with `.sub` only — no separate enter animation. */ +#menu + li.hasChildren:is(.active, .bsplus-active):not( + :has(.sub li.hasChildren:is(.active, .bsplus-active)) + ) + > .sub + > ul + > li, +#menu + li.hasChildren:is(.active, .bsplus-active):not( + :has(.sub li.hasChildren:is(.active, .bsplus-active)) + ) + > .sub + > ul + > li + > label, +#menu + li.hasChildren:is(.active, .bsplus-active):not( + :has(.sub li.hasChildren:is(.active, .bsplus-active)) + ) + > .sub + > ul + > li + > svg, +#menu + li.hasChildren:is(.active, .bsplus-active):not( + :has(.sub li.hasChildren:is(.active, .bsplus-active)) + ) + > .sub + > ul + > li::before, +#menu + li.hasChildren:is(.active, .bsplus-active):not( + :has(.sub li.hasChildren:is(.active, .bsplus-active)) + ) + > .sub + > ul + > li::after { + animation: none !important; + transition: none !important; + transform: none !important; +} + #menu .sub { transition: transform 0.3s ease, left 0.4s cubic-bezier(0.4, 0, 0.2, 1); } -/* Custom sidebar — single timing source. */ -#menu.bsplus-custom-sidebar { - --bsplus-drill-duration: 350ms; - --bsplus-drill-ease: cubic-bezier(0.4, 0, 0.2, 1); - --bsplus-slide-off: -320px; - - .sub { - transition: none !important; - } +#menu .sub ul:has(> li.hasChildren:is(.active, .bsplus-active)) + > li:not(:is(.active, .bsplus-active)) { + pointer-events: none !important; } #menu > ul:has(li.hasChildren:is(.active, .bsplus-active)) @@ -59,131 +96,16 @@ display: none !important; } -/* Icon-only collapsed: submenu slides over narrow icons (native sidebar only). */ -body.icon-only-sidebar:not(:has(#menu li.hasChildren:is(.active, .bsplus-active))) - #menu:not(.bsplus-custom-sidebar) - > ul:has(li.hasChildren:is(.active, .bsplus-active)) - > li::before, -body.icon-only-sidebar:not(:has(#menu li.hasChildren:is(.active, .bsplus-active))) - #menu:not(.bsplus-custom-sidebar) - > ul - ul:has(li.hasChildren:is(.active, .bsplus-active)) - > li::before, -body.icon-only-sidebar:not(:has(#menu li.hasChildren:is(.active, .bsplus-active))) - #menu:not(.bsplus-custom-sidebar) - > ul:has(li.hasChildren:is(.active, .bsplus-active)) - > li - > label, -body.icon-only-sidebar:not(:has(#menu li.hasChildren:is(.active, .bsplus-active))) - #menu:not(.bsplus-custom-sidebar) - > ul:has(li.hasChildren:is(.active, .bsplus-active)) - > li - > svg, -body.icon-only-sidebar:not(:has(#menu li.hasChildren:is(.active, .bsplus-active))) - #menu:not(.bsplus-custom-sidebar) - > ul - ul:has(li.hasChildren:is(.active, .bsplus-active)) - > li - > label, -body.icon-only-sidebar:not(:has(#menu li.hasChildren:is(.active, .bsplus-active))) - #menu:not(.bsplus-custom-sidebar) - > ul - ul:has(li.hasChildren:is(.active, .bsplus-active)) - > li - > svg { - transform: translateX(-70px); +#menu { + --bsplus-slide-off: -320px; } -/* - * Custom sidebar drill slides — use `.drilling` / `.drill-entering` / `.drill-returning`, - * not `:has(.active)` (SEQTA strips `.active` on nested clicks). - */ -#menu.bsplus-custom-sidebar #bsplus-sidebar-root { - &.drilling { - overflow: hidden !important; - - /* Hold siblings off-screen after the enter animation completes. */ - &:not(.drill-returning):not(.drill-entering) { - > li::before, - > li::after, - > li > label, - > li > svg, - .sub:has(.sub) > ul > li::before, - .sub:has(.sub) > ul > li::after, - .sub:has(.sub) > ul > li > label, - .sub:has(.sub) > ul > li > svg { - transform: translateX(var(--bsplus-slide-off)) !important; - transition: none !important; - animation: none !important; - } - - > li.hasChildren.bsplus-active > .sub:not(.bsplus-sub-enter) { - transform: translateX(0) !important; - } - } - - /* Slide siblings out in sync with the incoming .sub panel. */ - &.drill-entering:not(.drill-returning) { - > li::before, - > li::after, - > li > label, - > li > svg, - .sub:has(.sub) > ul > li::before, - .sub:has(.sub) > ul > li::after, - .sub:has(.sub) > ul > li > label, - .sub:has(.sub) > ul > li > svg { - transform: translateX(var(--bsplus-slide-off)) !important; - transition: transform var(--bsplus-drill-duration) var(--bsplus-drill-ease) !important; - animation: none !important; - } - } - - .sub:has(.sub) > .nav > .back { - display: none !important; - } - } - - &.drill-entering .sub.bsplus-sub-enter { - animation: bsplus-submenu-enter var(--bsplus-drill-duration) var(--bsplus-drill-ease) both !important; - } - - &.drill-returning:not(.drilling) > li::before, - &.drill-returning:not(.drilling) > li::after, - &.drill-returning:not(.drilling) > li > label, - &.drill-returning:not(.drilling) > li > svg, - &.drilling.drill-returning > li.hasChildren > .sub > ul > li::before, - &.drilling.drill-returning > li.hasChildren > .sub > ul > li::after, - &.drilling.drill-returning > li.hasChildren > .sub > ul > li > label, - &.drilling.drill-returning > li.hasChildren > .sub > ul > li > svg { - transition: none !important; - animation: bsplus-sidebar-return var(--bsplus-drill-duration) var(--bsplus-drill-ease) - both !important; - } -} - -@keyframes bsplus-submenu-enter { - from { - transform: translateX(100%); - } - to { - transform: translateX(0); - } -} - -/* Icon-only rail uses a shorter slide distance. */ -body.icon-only-sidebar #menu.bsplus-custom-sidebar #bsplus-sidebar-root { - --bsplus-slide-off: -70px; -} - -/* Hide off-screen siblings only after the slide finishes (not during enter). */ -body.icon-only-sidebar - #menu.bsplus-custom-sidebar - #bsplus-sidebar-root.drilling:not(.drill-returning):not(.drill-entering) { - > li:not(.bsplus-active) { - opacity: 0 !important; - visibility: hidden !important; - pointer-events: none !important; - } +/* Reverse slide when drilling back — label/svg motion is driven inline in JS + so text stays off-screen until `.active` clears. Pseudo-elements use CSS. */ +#menu.bsplus-sidebar-returning ul.bsplus-drill-return-target > li::before, +#menu.bsplus-sidebar-returning ul.bsplus-drill-return-target > li::after { + animation: bsplus-sidebar-return 0.3s cubic-bezier(0.4, 0, 0.2, 1) both !important; + transition: none !important; } @keyframes bsplus-sidebar-return { @@ -194,3 +116,42 @@ body.icon-only-sidebar transform: translateX(0); } } + +/* Icon-only collapsed: submenu slides over narrow icons. */ +body.icon-only-sidebar:not(:has(#menu li.hasChildren:is(.active, .bsplus-active))) + #menu + > ul:has(li.hasChildren:is(.active, .bsplus-active)) + > li::before, +body.icon-only-sidebar:not(:has(#menu li.hasChildren:is(.active, .bsplus-active))) + #menu + > ul + ul:has(li.hasChildren:is(.active, .bsplus-active)) + > li::before, +body.icon-only-sidebar:not(:has(#menu li.hasChildren:is(.active, .bsplus-active))) + #menu + > ul:has(li.hasChildren:is(.active, .bsplus-active)) + > li + > label, +body.icon-only-sidebar:not(:has(#menu li.hasChildren:is(.active, .bsplus-active))) + #menu + > ul:has(li.hasChildren:is(.active, .bsplus-active)) + > li + > svg, +body.icon-only-sidebar:not(:has(#menu li.hasChildren:is(.active, .bsplus-active))) + #menu + > ul + ul:has(li.hasChildren:is(.active, .bsplus-active)) + > li + > label, +body.icon-only-sidebar:not(:has(#menu li.hasChildren:is(.active, .bsplus-active))) + #menu + > ul + ul:has(li.hasChildren:is(.active, .bsplus-active)) + > li + > svg { + transform: translateX(-70px); +} + +body.icon-only-sidebar #menu { + --bsplus-slide-off: -70px; +} diff --git a/src/css/injected/sidebar-styles.scss b/src/css/injected/sidebar-styles.scss index 47f28f9c..729959c6 100644 --- a/src/css/injected/sidebar-styles.scss +++ b/src/css/injected/sidebar-styles.scss @@ -1,4 +1,4 @@ -/* Custom sidebar style presets + Look (density / radius / indicator). */ +/* Native sidebar style presets + Look (density / radius / indicator). */ $sidebar-motion: 0.4s cubic-bezier(0.4, 0, 0.2, 1); @@ -18,25 +18,35 @@ $sidebar-motion: 0.4s cubic-bezier(0.4, 0, 0.2, 1); display: block !important; } -#menu.bsplus-custom-sidebar { - $item: "> #bsplus-sidebar-root .bsplus-sidebar-item"; - $label: "> #bsplus-sidebar-root .bsplus-sidebar-item > label:not(.toggle)"; - $active: "> #bsplus-sidebar-root .bsplus-sidebar-item.bsplus-active:not(.hasChildren)"; +#menu.bsplus-styled-sidebar { + $rootItem: "> ul > li.item"; + $subItem: ".sub li.item"; + $item: "#{$rootItem}, #{$subItem}"; + $rootLabel: "> ul > li.item > label:not(.toggle)"; + $subLabel: ".sub li.item > label:not(.toggle)"; + $label: "#{$rootLabel}, #{$subLabel}"; + $active: "> ul > li.item.active:not(.hasChildren), .sub li.item.active:not(.hasChildren)"; - /* Look: base radius (pill / sharp / strip override). - Density/radius animate with the same easing as sidebar width. */ - #{$item} { + /* Look: base radius — layout transitions only on root rows (settings tweaks). + Submenu rows must not animate margin/padding during folder drill slides. */ + #{$rootItem} { border-radius: var(--bsplus-sidebar-radius, 12px) !important; transition: padding $sidebar-motion, margin $sidebar-motion, border-radius $sidebar-motion, background-color 0.2s ease, - box-shadow 0.2s ease, - opacity 0.2s ease; + box-shadow 0.2s ease; } - #{$label} { + #{$subItem} { + border-radius: var(--bsplus-sidebar-radius, 12px) !important; + transition: + background-color 0.2s ease, + box-shadow 0.2s ease; + } + + #{$rootLabel} { min-height: 28px !important; transition: font-size $sidebar-motion, @@ -52,6 +62,11 @@ $sidebar-motion: 0.4s cubic-bezier(0.4, 0, 0.2, 1); } } + #{$subLabel} { + min-height: 28px !important; + transition: none; + } + /* —— Style presets —— */ &.bsplus-sidebar-style-soft { #{$item} { @@ -90,6 +105,7 @@ $sidebar-motion: 0.4s cubic-bezier(0.4, 0, 0.2, 1); -webkit-backdrop-filter: none !important; box-shadow: none !important; overflow: visible !important; + contain: none !important; } #{$active} { background: rgba(255, 255, 255, 0.2) !important; diff --git a/src/plugins/built-in/gradeAnalytics/injectAnalyticsMenuItem.ts b/src/plugins/built-in/gradeAnalytics/injectAnalyticsMenuItem.ts index 87d6b35f..5b0d41c4 100644 --- a/src/plugins/built-in/gradeAnalytics/injectAnalyticsMenuItem.ts +++ b/src/plugins/built-in/gradeAnalytics/injectAnalyticsMenuItem.ts @@ -35,26 +35,14 @@ export async function injectAnalyticsMenuItem(): Promise<() => void> { `#menu .${ANALYTICS_MENU_CLASS}, #menu [data-key="${ANALYTICS_MENU_KEY}"]`, ) .forEach((node) => { - // Only touch the native list copy — custom sidebar mirrors via sync. - if (node.closest("#bsplus-sidebar-root")) return; node.remove(); }); - await waitForElm( - "#menu > ul:not(#bsplus-sidebar-root), #menu > ul", - true, - 50, - 120, - ); + await waitForElm("#menu > ul", true, 50, 120); let menuList = getNativeMenuList(); if (!menuList) { - menuList = (await waitForElm( - "#menu > ul:not(#bsplus-sidebar-root), #menu ul", - true, - 50, - 120, - )) as HTMLElement; + menuList = (await waitForElm("#menu > ul", true, 50, 120)) as HTMLElement; } const analyticsItem = document.createElement("li"); diff --git a/src/plugins/monofile.ts b/src/plugins/monofile.ts index 2f96381a..2c24318f 100644 --- a/src/plugins/monofile.ts +++ b/src/plugins/monofile.ts @@ -209,8 +209,8 @@ function SortMessagePageItems(messagesParentElement: any) { async function LoadPageElements(): Promise { await AddBetterSEQTAElements(); - void import("@/seqta/ui/sidebar/mountCustomSidebar").then((mod) => { - void mod.mountCustomSidebar(); + void import("@/seqta/ui/sidebar/applyNativeSidebar").then((mod) => { + void mod.applyNativeSidebar(); }); void import("@/seqta/ui/titlebar/mountCustomTitleBar").then((mod) => { void mod.mountCustomTitleBar(); @@ -745,19 +745,16 @@ export function init() { document.querySelector(".legacy-root")?.classList.add("hidden"); } - // Learn only: hide native sidebar + mount Svelte replacement during loading. - // Engage keeps its native React menu — never apply the pending hide class there. + // Learn only: apply sidebar CSS vars early; Engage keeps its native React menu. if (!onLogin && !isSeqtaEngageExperience()) { - document.documentElement.classList.add("bsplus-custom-sidebar-pending"); document.documentElement.classList.add("bsplus-custom-title-pending"); - void import("@/seqta/ui/sidebar/mountCustomSidebar").then((mod) => { - mod.prepareCustomSidebarEarly(); + void import("@/seqta/ui/sidebar/applyNativeSidebar").then((mod) => { + mod.prepareNativeSidebarEarly(); }); void import("@/seqta/ui/titlebar/mountCustomTitleBar").then((mod) => { mod.prepareCustomTitleBarEarly(); }); } else { - document.documentElement.classList.remove("bsplus-custom-sidebar-pending"); document.documentElement.classList.remove("bsplus-custom-title-pending"); } diff --git a/src/seqta/ui/AddBetterSEQTAElements.ts b/src/seqta/ui/AddBetterSEQTAElements.ts index 71f379bb..a71b51a0 100644 --- a/src/seqta/ui/AddBetterSEQTAElements.ts +++ b/src/seqta/ui/AddBetterSEQTAElements.ts @@ -19,6 +19,11 @@ import { LUCIDE_SUN_ICON_SVG } from "@/lib/icons/lucideSun"; import { ensureTitlebarFounderBadgeMounted, refreshTitlebarFounderBadge } from "@/seqta/ui/founderBadge/mountTitlebarFounderBadge"; import { isPerformanceMode } from "@/seqta/utils/performanceMode"; import { rafThrottle } from "@/seqta/utils/rafThrottle"; +import { + installSidebarDrillReturn, + runSidebarDrillReturn, + getSidebarDrillDepth, +} from "@/seqta/ui/sidebar/sidebarDrillReturn"; let cachedUserInfo: any = null; let userInfoFetchPromise: Promise | null = null; @@ -581,8 +586,6 @@ function customizeMenuToggle() { } function maybeSetupSidebarAccessibility() { - const menu = document.getElementById("menu"); - if (menu?.classList.contains("bsplus-custom-sidebar")) return; setupSidebarAccessibility(); } @@ -594,30 +597,7 @@ function setupSidebarAccessibility() { sidebarAccessibilityObserver?.disconnect(); const throttledA11yUpdate = rafThrottle(scheduleSidebarAccessibilityUpdate); - sidebarAccessibilityObserver = new MutationObserver((mutations) => { - // Custom Svelte sidebar owns drill a11y — ignore its DOM (opening Goals/Folios - // mutates a lot; re-running here used to help freeze the tab). - if (menu.classList.contains("bsplus-custom-sidebar")) { - const root = document.getElementById("bsplus-sidebar-root"); - if ( - root && - mutations.every( - (m) => root === m.target || root.contains(m.target as Node), - ) - ) { - return; - } - // Still ignore class/style-only native noise while custom sidebar is on. - if ( - mutations.every( - (m) => - m.type === "attributes" && - (m.attributeName === "class" || m.attributeName === "style"), - ) - ) { - return; - } - } + sidebarAccessibilityObserver = new MutationObserver(() => { throttledA11yUpdate(); }); sidebarAccessibilityObserver.observe(menu, { @@ -631,6 +611,8 @@ function setupSidebarAccessibility() { document.addEventListener("keydown", handleSidebarKeyboardActivation); sidebarAccessibilityListenersAttached = true; } + + installSidebarDrillReturn(menu); } function scheduleSidebarAccessibilityUpdate() { @@ -677,6 +659,10 @@ function handleSidebarKeyboardActivation(event: KeyboardEvent) { if (!parentEntry) return; event.preventDefault(); + const depthBefore = getSidebarDrillDepth(menu); + if (depthBefore > 0) { + runSidebarDrillReturn(menu, depthBefore - 1); + } parentEntry.classList.remove("active"); scheduleSidebarAccessibilityUpdate(); requestAnimationFrame(() => { @@ -760,20 +746,6 @@ function updateSidebarAccessibility() { const menu = document.getElementById("menu"); if (!menu) return; - // Custom Svelte sidebar owns its own a11y / drill UI — do not mark its - // `#bsplus-sidebar-root` items offscreen based on the hidden native list. - if (menu.classList.contains("bsplus-custom-sidebar")) { - const root = document.getElementById("bsplus-sidebar-root"); - if (root) { - for (const entry of root.querySelectorAll(`.${BSPLUS_SIDEBAR_OFFSCREEN}`)) { - if (entry instanceof HTMLElement) { - entry.classList.remove(BSPLUS_SIDEBAR_OFFSCREEN); - } - } - } - return; - } - const visibleList = getVisibleSidebarList(menu); const visibleEntries = new Set( visibleList ? getDirectSidebarEntries(visibleList) : [], @@ -791,7 +763,10 @@ function updateSidebarAccessibility() { visibleEntries.has(entry) || drillFolders.has(entry); if (!interactive) { - entry.classList.add(BSPLUS_SIDEBAR_OFFSCREEN); + // Keep rows in normal layout — offscreen position/opacity snaps cause a + // pop-in when drilling back to the root list. Visual hide uses translateX + // in sidebar-animation.scss; keyboard uses tabindex only. + entry.classList.remove(BSPLUS_SIDEBAR_OFFSCREEN); entry.tabIndex = -1; label.tabIndex = -1; continue; @@ -819,9 +794,7 @@ function getDirectSidebarEntries(list: HTMLElement) { } function getVisibleSidebarList(menu: HTMLElement) { - let currentList = menu.querySelector( - ":scope > ul:not(#bsplus-sidebar-root)", - ) as HTMLElement | null; + let currentList = menu.querySelector(":scope > ul") as HTMLElement | null; while (currentList) { const activeSubmenuParent = currentList.querySelector( diff --git a/src/seqta/ui/sidebar/Sidebar.svelte b/src/seqta/ui/sidebar/Sidebar.svelte deleted file mode 100644 index ed36ae47..00000000 --- a/src/seqta/ui/sidebar/Sidebar.svelte +++ /dev/null @@ -1,455 +0,0 @@ - - - - - -{#snippet drillLevel( - frames: Array<{ frame: SidebarDrillFrame; folder: SidebarItemModel | null }>, - depth: number, -)} - {@const current = frames[depth]} - {@const isLast = depth === frames.length - 1} - {@const nextKey = isLast ? null : frames[depth + 1].frame.key} - {@const folder = current.folder} -
  • - - -
    { - if (e.target !== e.currentTarget) return; - if (sidebarState.enterFrameKey === current.frame.key) { - sidebarState.clearEnterFrame(current.frame.key); - } - }} - > - -
      - {#if isLast} - {#each current.frame.items as item (item.key)} - - {/each} - {:else} - {#each current.frame.items as item (item.key)} - {#if item.key === nextKey} - {@render drillLevel(frames, depth + 1)} - {:else} - - {/if} - {/each} - {/if} -
    -
    -
  • -{/snippet} - - diff --git a/src/seqta/ui/sidebar/SidebarItem.svelte b/src/seqta/ui/sidebar/SidebarItem.svelte deleted file mode 100644 index ede557a8..00000000 --- a/src/seqta/ui/sidebar/SidebarItem.svelte +++ /dev/null @@ -1,246 +0,0 @@ - - - - -
  • { - // Keep SEQTA's #menu handlers from seeing custom-list clicks — that fights - // our drill UI and can freeze the tab (Goals / Folios / etc.). - e.preventDefault(); - e.stopPropagation(); - if (!editMode) onActivate(item); - }} - onkeydown={(e) => { - if (editMode) return; - if (e.key === "Enter" || e.key === " ") { - e.preventDefault(); - e.stopPropagation(); - onActivate(item); - } - }} -> - {#if editMode} - - {/if} - - - {#if editMode} - - {/if} -
  • - - diff --git a/src/seqta/ui/sidebar/applyNativeSidebar.ts b/src/seqta/ui/sidebar/applyNativeSidebar.ts new file mode 100644 index 00000000..72376154 --- /dev/null +++ b/src/seqta/ui/sidebar/applyNativeSidebar.ts @@ -0,0 +1,109 @@ +import type { SettingsState } from "@/types/storage"; +import { settingsState } from "@/seqta/utils/listeners/SettingsState"; +import { isSeqtaEngageExperience, isSeqtaLoginPage } from "@/seqta/utils/isSeqtaEngage"; +import { waitForElm } from "@/seqta/utils/waitForElm"; +import { + applySidebarLook, + applySidebarStyleClass, + clearSidebarAppearance, +} from "./sidebarStyles"; + +const MENU_CLASS = "bsplus-styled-sidebar"; + +type ChangeListener = (newValue: unknown, oldValue: unknown) => void; + +let menuEl: HTMLElement | null = null; +let sidebarLookScheduled = false; +let settingsListenersAttached = false; + +const settingsListeners: Array<{ + key: keyof SettingsState; + listener: ChangeListener; +}> = []; + +function scheduleSidebarLook() { + if (!menuEl || sidebarLookScheduled) return; + sidebarLookScheduled = true; + requestAnimationFrame(() => { + sidebarLookScheduled = false; + if (menuEl) applySidebarLook(menuEl); + }); +} + +function registerSetting(key: keyof SettingsState, listener: ChangeListener) { + settingsState.register(key, listener); + settingsListeners.push({ key, listener }); +} + +function clearSettingListeners() { + for (const { key, listener } of settingsListeners) { + settingsState.unregister(key, listener); + } + settingsListeners.length = 0; + settingsListenersAttached = false; +} + +function attachSettingsListeners() { + if (settingsListenersAttached || !menuEl) return; + settingsListenersAttached = true; + clearSettingListeners(); + + registerSetting("sidebarStyle", () => + applySidebarStyleClass(menuEl, settingsState.sidebarStyle), + ); + for (const key of [ + "sidebarDensity", + "sidebarCornerRadius", + "sidebarActiveIndicator", + "sidebarWidth", + "sidebarBlur", + "transparencyEffects", + ] as const) { + registerSetting(key, () => scheduleSidebarLook()); + } +} + +function applyToMenu(menu: HTMLElement) { + menuEl = menu; + menu.classList.add(MENU_CLASS); + applySidebarStyleClass(menu, settingsState.sidebarStyle); + applySidebarLook(menu); + attachSettingsListeners(); +} + +/** Apply sidebar width/blur CSS vars as soon as `#menu` exists (before full load). */ +export function prepareNativeSidebarEarly() { + if (isSeqtaEngageExperience() || isSeqtaLoginPage()) return; + if (!settingsState.onoff) return; + applySidebarLook(document.getElementById("menu")); +} + +export async function applyNativeSidebar(): Promise { + if (isSeqtaEngageExperience() || isSeqtaLoginPage()) return false; + if (!settingsState.onoff) return false; + + if (menuEl?.isConnected) { + applyToMenu(menuEl); + return true; + } + + let menu: HTMLElement | null = null; + try { + menu = (await waitForElm("#menu", true, 50, 200)) as HTMLElement; + } catch { + return false; + } + if (!menu) return false; + + applyToMenu(menu); + return true; +} + +export function clearNativeSidebar() { + clearSettingListeners(); + if (menuEl) { + menuEl.classList.remove(MENU_CLASS); + clearSidebarAppearance(menuEl); + } + menuEl = null; +} diff --git a/src/seqta/ui/sidebar/customMenuActive.test.ts b/src/seqta/ui/sidebar/customMenuActive.test.ts deleted file mode 100644 index c0076428..00000000 --- a/src/seqta/ui/sidebar/customMenuActive.test.ts +++ /dev/null @@ -1,87 +0,0 @@ -/** - * @jest-environment jsdom - */ -import { - applyCustomMenuActive, - scheduleRestoreCustomMenuActive, -} from "./customMenuActive"; - -describe("applyCustomMenuActive", () => { - beforeEach(() => { - document.body.innerHTML = ` -
      -
    • - -
      - -
        -
      • - -
      • -
      -
      -
    • -
    - `; - }); - - it("restores .active and .bsplus-active after SEQTA strips them", () => { - applyCustomMenuActive({ - activeKey: "4804:11066", - drilling: true, - }); - - const folder = document.querySelector( - "#bsplus-sidebar-root > li.hasChildren", - ); - const leaf = document.querySelector('li.item[data-key="4804:11066"]'); - - expect(folder?.classList.contains("active")).toBe(true); - expect(folder?.classList.contains("bsplus-active")).toBe(true); - expect(leaf?.classList.contains("active")).toBe(true); - expect(leaf?.classList.contains("bsplus-active")).toBe(true); - }); -}); - -describe("scheduleRestoreCustomMenuActive", () => { - beforeEach(() => { - jest.useFakeTimers(); - jest - .spyOn(window, "requestAnimationFrame") - .mockImplementation((cb: FrameRequestCallback) => { - cb(0); - return 0; - }); - document.body.innerHTML = ` -
      -
    • -
        -
      • -
      -
    • -
    - `; - }); - - afterEach(() => { - jest.restoreAllMocks(); - jest.useRealTimers(); - }); - - it("re-applies active classes after SEQTA strips them on the next frames", () => { - const folder = document.querySelector( - "#bsplus-sidebar-root > li.hasChildren", - ) as HTMLElement; - - scheduleRestoreCustomMenuActive({ - activeKey: "upcoming", - drilling: true, - }); - - folder.classList.remove("active", "bsplus-active"); - jest.advanceTimersByTime(50); - - expect(folder.classList.contains("active")).toBe(true); - expect(folder.classList.contains("bsplus-active")).toBe(true); - }); -}); diff --git a/src/seqta/ui/sidebar/customMenuActive.ts b/src/seqta/ui/sidebar/customMenuActive.ts deleted file mode 100644 index 436cc17c..00000000 --- a/src/seqta/ui/sidebar/customMenuActive.ts +++ /dev/null @@ -1,72 +0,0 @@ -export type CustomMenuActiveState = { - activeKey: string | null; - drilling: boolean; -}; - -function ensureActive(el: Element | null | undefined, withBsplus = false) { - if (!(el instanceof HTMLElement)) return; - if (!el.classList.contains("active")) el.classList.add("active"); - if (withBsplus && !el.classList.contains("bsplus-active")) { - el.classList.add("bsplus-active"); - } -} - -/** - * SEQTA strips `.active` (and sometimes our `.bsplus-active`) after navigation. - * Theme chrome, `.sub` hit-testing, and icon-only expand all depend on those classes. - */ -export function applyCustomMenuActive(state: CustomMenuActiveState) { - const root = document.getElementById("bsplus-sidebar-root"); - if (!root) return; - - for (const li of root.querySelectorAll("li.hasChildren")) { - if (!(li instanceof HTMLElement)) continue; - if (!li.querySelector(":scope > .sub")) continue; - ensureActive(li, true); - } - - const { activeKey, drilling } = state; - - if (drilling) { - if (activeKey) { - ensureActive( - root.querySelector(`.sub li.item[data-key="${CSS.escape(activeKey)}"]`), - true, - ); - } - for (const li of root.querySelectorAll( - '.sub li.item[aria-current="page"]', - )) { - ensureActive(li, true); - } - return; - } - - if (activeKey) { - ensureActive( - root.querySelector(`li.item[data-key="${CSS.escape(activeKey)}"]`), - true, - ); - } - - for (const li of root.querySelectorAll('li.item[aria-current="page"]')) { - ensureActive(li, true); - } -} - -let restoreTimer: ReturnType | null = null; - -/** - * Restore after SEQTA's click/hash handlers have finished rewriting `#menu` classes. - * One rAF is not enough on assessments — SEQTA often strips `.active` a frame later. - */ -export function scheduleRestoreCustomMenuActive(state: CustomMenuActiveState) { - requestAnimationFrame(() => { - applyCustomMenuActive(state); - if (restoreTimer) clearTimeout(restoreTimer); - restoreTimer = setTimeout(() => { - restoreTimer = null; - applyCustomMenuActive(state); - }, 50); - }); -} diff --git a/src/seqta/ui/sidebar/index.ts b/src/seqta/ui/sidebar/index.ts index 90bc092d..51fc8bba 100644 --- a/src/seqta/ui/sidebar/index.ts +++ b/src/seqta/ui/sidebar/index.ts @@ -1,8 +1,19 @@ export { - prepareCustomSidebarEarly, - mountCustomSidebar, - unmountCustomSidebar, - openCustomSidebarEditor, -} from "./mountCustomSidebar"; -export { sidebarState } from "./sidebarState.svelte"; -export type { SidebarItem, SidebarDrillFrame } from "./types"; + prepareNativeSidebarEarly, + applyNativeSidebar, + clearNativeSidebar, +} from "./applyNativeSidebar"; +export { + installSidebarDrillReturn, + runSidebarDrillReturn, + getSidebarDrillDepth, +} from "./sidebarDrillReturn"; +export { + applySidebarLook, + applySidebarStyleClass, + clearSidebarAppearance, + getSidebarStyle, + normalizeSidebarStyleId, + SIDEBAR_STYLES, +} from "./sidebarStyles"; +export { getNativeMenuList, parseNativeMenu, getPagePathFromHash } from "./parseNativeMenu"; diff --git a/src/seqta/ui/sidebar/mountCustomSidebar.ts b/src/seqta/ui/sidebar/mountCustomSidebar.ts deleted file mode 100644 index 9e79843c..00000000 --- a/src/seqta/ui/sidebar/mountCustomSidebar.ts +++ /dev/null @@ -1,409 +0,0 @@ -import { mount, unmount } from "svelte"; -import type { SettingsState } from "@/types/storage"; -import { settingsState } from "@/seqta/utils/listeners/SettingsState"; -import { isSeqtaEngageExperience, isSeqtaLoginPage } from "@/seqta/utils/isSeqtaEngage"; -import { waitForElm } from "@/seqta/utils/waitForElm"; -import { waitForSeqtaMenu } from "@/seqta/utils/waitForSeqtaShell"; -import Sidebar from "./Sidebar.svelte"; -import { getNativeMenuList } from "./parseNativeMenu"; -import { scheduleRestoreCustomMenuActive } from "./customMenuActive"; -import { - clearNativeDrillActive, - sidebarState, -} from "./sidebarState.svelte"; -import { - applySidebarLook, - applySidebarStyleClass, - clearSidebarAppearance, -} from "./sidebarStyles"; -import { isPerformanceMode } from "@/seqta/utils/performanceMode"; -import { applyMenuItemVisibility } from "@/seqta/utils/menuItemVisibility"; - -const ROOT_ID = "bsplus-sidebar-root"; -const MENU_CLASS = "bsplus-custom-sidebar"; -const PENDING_CLASS = "bsplus-custom-sidebar-pending"; - -type ChangeListener = (newValue: unknown, oldValue: unknown) => void; - -let app: ReturnType | null = null; -let menuEl: HTMLElement | null = null; -let menuObserver: MutationObserver | null = null; -let syncTimer: ReturnType | null = null; -let hashListenerAttached = false; -let sidebarCaptureAttached = false; -let earlyPrepareStarted = false; -let catchupTimers: ReturnType[] = []; -let nativeMenuListenerAttached = false; -let lastMenuFingerprint = ""; -let catchupSessionStarted = false; -let sidebarLookScheduled = false; - -const settingsListeners: Array<{ - key: keyof SettingsState; - listener: ChangeListener; -}> = []; - -/** Stable fingerprint of native menu keys so unchanged DOM does not re-sync. */ -function menuFingerprint(menu: HTMLElement): string { - const list = getNativeMenuList(menu); - if (!list) return ""; - const keys: string[] = []; - for (const node of list.children) { - const el = node as HTMLElement; - if (el.id === ROOT_ID) continue; - const key = el.dataset.key ?? ""; - const path = el.dataset.path ?? ""; - const colour = el.dataset.colour ?? ""; - keys.push(`${key}|${path}|${colour}`); - } - return `${keys.length}:${keys.join(",")}`; -} - -function syncFromMenu(force = false) { - if (!menuEl) return; - getNativeMenuList(menuEl)?.setAttribute("aria-hidden", "true"); - const next = menuFingerprint(menuEl); - if (!force && next === lastMenuFingerprint) return; - lastMenuFingerprint = next; - sidebarState.syncFromNative(menuEl); -} - -/** - * Sparse catch-up after mount: plugins inject menu items shortly after first paint. - * MutationObserver + scheduleSync cover ongoing changes; this only covers a short window. - */ -function startCatchupSync() { - if (catchupSessionStarted) { - syncFromMenu(); - return; - } - catchupSessionStarted = true; - - for (const t of catchupTimers) clearTimeout(t); - catchupTimers = []; - // Immediate, then a few delayed passes (~1s total) instead of 50ms×60. - const delays = isPerformanceMode() ? [0, 400, 1000] : [0, 200, 500, 1000]; - for (const ms of delays) { - catchupTimers.push( - setTimeout(() => { - syncFromMenu(); - }, ms), - ); - } - if (typeof requestIdleCallback === "function") { - requestIdleCallback(() => syncFromMenu(), { timeout: 1500 }); - } -} - -function scheduleSidebarLook() { - if (!menuEl || sidebarLookScheduled) return; - sidebarLookScheduled = true; - requestAnimationFrame(() => { - sidebarLookScheduled = false; - if (menuEl) applySidebarLook(menuEl); - }); -} - -function onNativeMenuUpdated() { - syncFromMenu(true); -} - -function scheduleSync() { - if (syncTimer) clearTimeout(syncTimer); - const delay = isPerformanceMode() ? 120 : 50; - syncTimer = setTimeout(() => { - syncTimer = null; - syncFromMenu(); - }, delay); -} - -/** - * Capture-phase: own all clicks inside the custom list so SEQTA's #menu handlers - * never see them. Opening Goals/Folios via SEQTA + our drill UI freezes the tab. - */ -function onCustomSidebarCaptureClick(event: MouseEvent) { - if (!menuEl || sidebarState.editMode || sidebarState.drillReturning) return; - - const root = document.getElementById(ROOT_ID); - const target = event.target; - if (!(target instanceof Element) || !root?.contains(target)) return; - - event.preventDefault(); - event.stopPropagation(); - event.stopImmediatePropagation(); - - const back = target.closest(".back"); - if (back instanceof HTMLElement && root.contains(back)) { - sidebarState.goBack(); - return; - } - - const li = target.closest("li.item[data-key]"); - if (!(li instanceof HTMLElement) || !root.contains(li)) return; - - // Already-open folder chrome (renders its own `.sub`) — ignore; use Back. - if ( - li.classList.contains("hasChildren") && - li.querySelector(":scope > .sub") - ) { - return; - } - - const key = li.dataset.key; - const path = li.dataset.path; - const item = sidebarState.resolveItem(key, path); - if (item) sidebarState.activateItem(item, menuEl); -} - -function onHashChange() { - sidebarState.syncActiveFromLocation(); - if (menuEl) clearNativeDrillActive(menuEl); - if (sidebarState.isDrilling) { - scheduleRestoreCustomMenuActive({ - activeKey: sidebarState.activeKey, - drilling: true, - }); - } - - if (!sidebarState.isDrilling) return; - - const path = sidebarState.activePath; - if (!path) return; - - const openKey = sidebarState.drillStack[0]?.key; - const top = sidebarState.visibleRootItems.find( - (item) => - item.key === openKey || - item.path === path || - (item.path != null && path.startsWith(`${item.path}/`)), - ); - - if (openKey && top?.key === openKey) return; - if (!path.includes("/")) sidebarState.resetDrill(); -} - -function ensureDefaultMenuOrder(menu: HTMLElement) { - const list = getNativeMenuList(menu); - if (!list) return; - - const keys = [...list.children] - .map((node) => (node as HTMLElement).dataset.key) - .filter((key): key is string => !!key); - - const current = settingsState.defaultmenuorder ?? []; - if (!current.length) { - settingsState.defaultmenuorder = keys; - return; - } - - const missing = keys.filter((key) => !current.includes(key)); - if (missing.length) { - settingsState.defaultmenuorder = [...current, ...missing]; - } -} - -function registerSetting( - key: keyof SettingsState, - listener: ChangeListener, -) { - settingsState.register(key, listener); - settingsListeners.push({ key, listener }); -} - -function clearSettingListeners() { - for (const { key, listener } of settingsListeners) { - settingsState.unregister(key, listener); - } - settingsListeners.length = 0; -} - -function clearPendingClass() { - document.documentElement.classList.remove(PENDING_CLASS); -} - -/** - * Hide the native SEQTA menu immediately (even under the loading overlay) - * and begin mounting the Svelte sidebar as soon as `#menu` exists. - */ -export function prepareCustomSidebarEarly() { - if (isSeqtaEngageExperience() || isSeqtaLoginPage()) return; - if (!settingsState.onoff) return; - if (earlyPrepareStarted) return; - - earlyPrepareStarted = true; - document.documentElement.classList.add(PENDING_CLASS); - // Width/blur vars before mount so layout doesn't jump. - applySidebarLook(document.getElementById("menu")); - void mountCustomSidebar(); -} - -export function openCustomSidebarEditor() { - if (!app || !menuEl) return false; - sidebarState.setEditMode(true); - menuEl.classList.add("bsplus-sidebar-edit-mode"); - return true; -} - -export async function mountCustomSidebar(): Promise { - if (isSeqtaEngageExperience()) return false; - if (!settingsState.onoff) return false; - - // Already mounted — re-sync after Home/News/Analytics injections. - if (app && menuEl) { - ensureDefaultMenuOrder(menuEl); - applySidebarStyleClass(menuEl, settingsState.sidebarStyle); - applySidebarLook(menuEl); - sidebarState.syncSettings(); - syncFromMenu(); - startCatchupSync(); - clearPendingClass(); - return true; - } - - document.documentElement.classList.add(PENDING_CLASS); - - let menu: HTMLElement | null = null; - try { - menu = (await waitForSeqtaMenu(50, 200)) as HTMLElement; - } catch { - return false; - } - if (!menu) return false; - - // Prefer a populated native list, but don't block forever during loading. - let list = getNativeMenuList(menu); - if (!list) { - await waitForElm("#menu > ul:not(#bsplus-sidebar-root)", true, 50, 120); - list = getNativeMenuList(menu); - } - if (!list) return false; - - menuEl = menu; - ensureDefaultMenuOrder(menu); - sidebarState.syncSettings(); - syncFromMenu(); - - if (app) { - clearPendingClass(); - return true; - } - - menu.classList.add(MENU_CLASS); - applySidebarStyleClass(menu, settingsState.sidebarStyle); - applySidebarLook(menu); - document.getElementById(ROOT_ID)?.remove(); - - app = mount(Sidebar, { - target: menu, - props: { menuEl: menu }, - }); - - menu - .querySelectorAll(".bsplus-sidebar-offscreen") - .forEach((node) => node.classList.remove("bsplus-sidebar-offscreen")); - - menuObserver?.disconnect(); - menuObserver = new MutationObserver((mutations) => { - const ours = document.getElementById(ROOT_ID); - // Ignore our list entirely. Ignore native class/style churn — SEQTA and - // theme transitions rewrite those constantly; syncing on them freezes the tab. - const relevant = mutations.some((m) => { - if (ours?.contains(m.target as Node)) return false; - if (m.type === "attributes") { - const attr = m.attributeName; - if (attr === "class" || attr === "style") return false; - } - return true; - }); - if (!relevant) return; - scheduleSync(); - }); - menuObserver.observe(menu, { - subtree: true, - childList: true, - attributes: true, - attributeFilter: ["data-key", "data-path", "data-colour"], - }); - - if (!sidebarCaptureAttached) { - document.addEventListener("click", onCustomSidebarCaptureClick, true); - sidebarCaptureAttached = true; - } - - if (!hashListenerAttached) { - window.addEventListener("hashchange", onHashChange); - hashListenerAttached = true; - } - - if (!nativeMenuListenerAttached) { - window.addEventListener("bsplus-native-menu-updated", onNativeMenuUpdated); - nativeMenuListenerAttached = true; - } - - clearSettingListeners(); - registerSetting("iconOnlySidebar", () => sidebarState.syncSettings()); - registerSetting("sidebarStyle", () => - applySidebarStyleClass(menuEl, settingsState.sidebarStyle), - ); - for (const key of [ - "sidebarDensity", - "sidebarCornerRadius", - "sidebarActiveIndicator", - "sidebarWidth", - "sidebarBlur", - ] as const) { - registerSetting(key, () => scheduleSidebarLook()); - } - const resync = () => syncFromMenu(true); - registerSetting("menuorder", resync); - registerSetting("menuitems", () => applyMenuItemVisibility()); - - startCatchupSync(); - clearPendingClass(); - return true; -} - -export function unmountCustomSidebar() { - menuObserver?.disconnect(); - menuObserver = null; - if (syncTimer) clearTimeout(syncTimer); - syncTimer = null; - for (const t of catchupTimers) clearTimeout(t); - catchupTimers = []; - lastMenuFingerprint = ""; - catchupSessionStarted = false; - - clearSettingListeners(); - - if (hashListenerAttached) { - window.removeEventListener("hashchange", onHashChange); - hashListenerAttached = false; - } - - if (sidebarCaptureAttached) { - document.removeEventListener("click", onCustomSidebarCaptureClick, true); - sidebarCaptureAttached = false; - } - - if (nativeMenuListenerAttached) { - window.removeEventListener("bsplus-native-menu-updated", onNativeMenuUpdated); - nativeMenuListenerAttached = false; - } - - if (app) { - unmount(app); - app = null; - } - - document.getElementById(ROOT_ID)?.remove(); - if (menuEl) { - getNativeMenuList(menuEl)?.removeAttribute("aria-hidden"); - menuEl.classList.remove(MENU_CLASS, "bsplus-sidebar-edit-mode"); - clearSidebarAppearance(menuEl); - } - menuEl = null; - sidebarState.resetDrill(); - sidebarState.setEditMode(false); - earlyPrepareStarted = false; - clearPendingClass(); -} diff --git a/src/seqta/ui/sidebar/parseNativeMenu.test.ts b/src/seqta/ui/sidebar/parseNativeMenu.test.ts deleted file mode 100644 index fdaf4653..00000000 --- a/src/seqta/ui/sidebar/parseNativeMenu.test.ts +++ /dev/null @@ -1,224 +0,0 @@ -/** - * @jest-environment jsdom - */ -import { - findNativeMenuEntry, - folderNeedsNativePopulate, - getPagePathFromHash, - parseNativeMenu, -} from "./parseNativeMenu"; - -describe("parseNativeMenu", () => { - it("parses top-level items and nested folders", () => { - document.body.innerHTML = ` - - `; - - const menu = document.getElementById("menu")!; - const items = parseNativeMenu(menu); - - expect(items.map((i) => i.key)).toEqual(["home", "assessments"]); - expect(items[0].betterseqta).toBe(true); - expect(items[1].hasChildren).toBe(true); - expect(items[1].children.map((c) => c.key)).toEqual([ - "assessments-overview", - "upcoming", - ]); - expect(items[1].children[0].label).toBe("Overview"); - }); - - it("reads page path from hash", () => { - expect(getPagePathFromHash("#?page=/timetable")).toBe("/timetable"); - expect(getPagePathFromHash("#?page=/assessments/upcoming&x=1")).toBe( - "/assessments/upcoming", - ); - }); - - it("ignores the custom Svelte sidebar list when parsing", () => { - document.body.innerHTML = ` - - `; - - const menu = document.getElementById("menu")!; - const items = parseNativeMenu(menu); - - expect(items.map((i) => i.key)).toEqual(["home"]); - }); - - it("findNativeMenuEntry prefers path over duplicate data-key", () => { - document.body.innerHTML = ` - - `; - - const menu = document.getElementById("menu")!; - const course = findNativeMenuEntry(menu, { - key: "4804:11066", - id: null, - path: "/courses/4804:11066", - label: "Course", - }); - const assessments = findNativeMenuEntry(menu, { - key: "4804:11066", - id: null, - path: "/assessments/4804:11066", - label: "Assessments", - }); - - expect(course?.dataset.path).toBe("/courses/4804:11066"); - expect(assessments?.dataset.path).toBe("/assessments/4804:11066"); - }); - - it("synthesizes assessment subject paths when SEQTA omits data-path", () => { - document.body.innerHTML = ` - - `; - - const menu = document.getElementById("menu")!; - const items = parseNativeMenu(menu); - const english = items - .find((item) => item.key === "assessments") - ?.children[0]?.children[0]; - - expect(english?.path).toBe("/assessments/4804:11066"); - - const native = findNativeMenuEntry(menu, { - key: "4804:11066", - id: null, - path: english?.path ?? null, - label: "English", - }); - - expect(native?.closest("[data-key='assessments']")).not.toBeNull(); - expect(native?.closest("[data-key='courses']")).toBeNull(); - }); - - it("detects assessments/courses folders that still need SEQTA to populate subjects", () => { - expect( - folderNeedsNativePopulate({ - key: "assessments", - path: "/assessments", - id: null, - label: "Assessments", - iconHtml: "", - hasChildren: true, - itemColour: null, - betterseqta: false, - children: [ - { - key: "assessments-overview", - path: null, - id: null, - label: "Overview", - iconHtml: "", - hasChildren: false, - itemColour: null, - betterseqta: true, - children: [], - }, - ], - }), - ).toBe(true); - - expect( - folderNeedsNativePopulate({ - key: "courses", - path: "/courses", - id: null, - label: "Courses", - iconHtml: "", - hasChildren: true, - itemColour: null, - betterseqta: false, - children: [ - { - key: "4804:11066", - path: "/courses/4804:11066", - id: null, - label: "English", - iconHtml: "", - hasChildren: true, - itemColour: null, - betterseqta: false, - children: [], - }, - ], - }), - ).toBe(false); - }); -}); diff --git a/src/seqta/ui/sidebar/parseNativeMenu.ts b/src/seqta/ui/sidebar/parseNativeMenu.ts index 53b976c9..d713bdb2 100644 --- a/src/seqta/ui/sidebar/parseNativeMenu.ts +++ b/src/seqta/ui/sidebar/parseNativeMenu.ts @@ -1,13 +1,11 @@ import type { SidebarItem } from "./types"; -/** Native SEQTA list only — never the custom Svelte `#bsplus-sidebar-root`. */ +/** Native SEQTA root menu list. */ export function getNativeMenuList( menu: HTMLElement | null = document.getElementById("menu"), ): HTMLElement | null { if (!menu) return null; - return menu.querySelector( - ":scope > ul:not(#bsplus-sidebar-root)", - ) as HTMLElement | null; + return menu.querySelector(":scope > ul") as HTMLElement | null; } function readLabelText(label: HTMLElement | null): string { diff --git a/src/seqta/ui/sidebar/sidebarDrillReturn.ts b/src/seqta/ui/sidebar/sidebarDrillReturn.ts new file mode 100644 index 00000000..aa2bc573 --- /dev/null +++ b/src/seqta/ui/sidebar/sidebarDrillReturn.ts @@ -0,0 +1,198 @@ +const MENU_RETURN_CLASS = "bsplus-sidebar-returning"; +const LIST_RETURN_CLASS = "bsplus-drill-return-target"; +const RETURN_MS = 300; +const RETURN_EASE = "cubic-bezier(0.4, 0, 0.2, 1)"; + +/** Count open folder levels (0 = root list only). */ +export function getSidebarDrillDepth( + menu: HTMLElement | null = document.getElementById("menu"), +): number { + if (!menu) return 0; + + let depth = 0; + let list = menu.querySelector(":scope > ul") as HTMLElement | null; + + while (list) { + const activeFolder = list.querySelector( + ":scope > li.hasChildren.active, :scope > section.hasChildren.active", + ) as HTMLElement | null; + if (!activeFolder) break; + + depth += 1; + list = activeFolder.querySelector(":scope > .sub > ul") as HTMLElement | null; + } + + return depth; +} + +/** List that becomes visible after drilling back to `targetDepth`. */ +function getSidebarListAtDepth( + menu: HTMLElement, + targetDepth: number, +): HTMLElement | null { + if (targetDepth <= 0) { + return menu.querySelector(":scope > ul") as HTMLElement | null; + } + + let list = menu.querySelector(":scope > ul") as HTMLElement | null; + let depth = 0; + + while (list && depth < targetDepth) { + const activeFolder = list.querySelector( + ":scope > li.hasChildren.active, :scope > section.hasChildren.active", + ) as HTMLElement | null; + if (!activeFolder) return list; + list = activeFolder.querySelector(":scope > .sub > ul") as HTMLElement | null; + depth += 1; + } + + return list; +} + +function getSlideOff(menu: HTMLElement): string { + const value = getComputedStyle(menu).getPropertyValue("--bsplus-slide-off").trim(); + return value || "-320px"; +} + +function getReturnSlideNodes(list: HTMLElement): HTMLElement[] { + return [ + ...list.querySelectorAll( + ":scope > li > label, :scope > li > svg, :scope > section > label, :scope > section > svg", + ), + ]; +} + +function clearInlineReturnStyles(nodes: Iterable) { + for (const node of nodes) { + node.style.removeProperty("transition"); + node.style.removeProperty("transform"); + } +} + +let returnTimer: ReturnType | null = null; +let lastAnimatedNodes: HTMLElement[] = []; +let lastDrillDepth = 0; +let menuObserver: MutationObserver | null = null; +let backCaptureAttached = false; + +function clearReturnClasses(menu: HTMLElement) { + menu.classList.remove(MENU_RETURN_CLASS); + menu.querySelectorAll(`.${LIST_RETURN_CLASS}`).forEach((node) => { + node.classList.remove(LIST_RETURN_CLASS); + }); +} + +export function runSidebarDrillReturn( + menu: HTMLElement | null = document.getElementById("menu"), + targetDepth?: number, +) { + if (!menu || menu.classList.contains(MENU_RETURN_CLASS)) return; + + const depth = targetDepth ?? Math.max(0, getSidebarDrillDepth(menu)); + const list = getSidebarListAtDepth(menu, depth); + if (!list) return; + + const nodes = getReturnSlideNodes(list); + if (nodes.length === 0) return; + + if (returnTimer) clearTimeout(returnTimer); + clearReturnClasses(menu); + clearInlineReturnStyles(lastAnimatedNodes); + lastAnimatedNodes = nodes; + + const slideOff = getSlideOff(menu); + + // Hold the off-screen transform before SEQTA clears `.active` and drops `:has()`. + for (const node of nodes) { + node.style.transition = "none"; + node.style.transform = `translateX(${slideOff})`; + } + + menu.classList.add(MENU_RETURN_CLASS); + list.classList.add(LIST_RETURN_CLASS); + lastDrillDepth = depth; + + requestAnimationFrame(() => { + requestAnimationFrame(() => { + for (const node of nodes) { + node.style.transition = `transform ${RETURN_MS}ms ${RETURN_EASE}`; + node.style.transform = "translateX(0)"; + } + }); + }); + + returnTimer = setTimeout(() => { + returnTimer = null; + clearReturnClasses(menu); + clearInlineReturnStyles(nodes); + lastAnimatedNodes = []; + }, RETURN_MS + 50); +} + +function onDrillDepthChange(menu: HTMLElement) { + if (menu.classList.contains(MENU_RETURN_CLASS)) return; + + const depth = getSidebarDrillDepth(menu); + if (depth < lastDrillDepth) { + runSidebarDrillReturn(menu, depth); + return; + } + lastDrillDepth = depth; +} + +function onMenuClickCapture(event: MouseEvent) { + const menu = document.getElementById("menu"); + if (!menu || menu.classList.contains(MENU_RETURN_CLASS)) return; + + const target = event.target; + if (!(target instanceof Element)) return; + if (!target.closest(".sub .back")) return; + + const depthBefore = getSidebarDrillDepth(menu); + if (depthBefore > 0) { + runSidebarDrillReturn(menu, depthBefore - 1); + } +} + +/** Drive the reverse slide when folder `.active` is cleared. */ +export function installSidebarDrillReturn( + menu: HTMLElement | null = document.getElementById("menu"), +) { + if (!menu || menuObserver) return; + + lastDrillDepth = getSidebarDrillDepth(menu); + + menuObserver = new MutationObserver(() => { + onDrillDepthChange(menu); + }); + menuObserver.observe(menu, { + subtree: true, + attributes: true, + attributeFilter: ["class"], + }); + + if (!backCaptureAttached) { + menu.addEventListener("click", onMenuClickCapture, true); + backCaptureAttached = true; + } +} + +export function uninstallSidebarDrillReturn() { + menuObserver?.disconnect(); + menuObserver = null; + if (returnTimer) clearTimeout(returnTimer); + returnTimer = null; + lastDrillDepth = 0; + + const menu = document.getElementById("menu"); + if (menu) { + clearReturnClasses(menu); + clearInlineReturnStyles(lastAnimatedNodes); + lastAnimatedNodes = []; + if (backCaptureAttached) { + menu.removeEventListener("click", onMenuClickCapture, true); + backCaptureAttached = false; + } + } + backCaptureAttached = false; +} diff --git a/src/seqta/ui/sidebar/sidebarState.svelte.ts b/src/seqta/ui/sidebar/sidebarState.svelte.ts deleted file mode 100644 index 8a465ab4..00000000 --- a/src/seqta/ui/sidebar/sidebarState.svelte.ts +++ /dev/null @@ -1,401 +0,0 @@ -import { settingsState } from "@/seqta/utils/listeners/SettingsState"; -import { animationsEnabled } from "@/seqta/utils/performanceMode"; -import { - applyCustomMenuActive, - scheduleRestoreCustomMenuActive, -} from "./customMenuActive"; -import { - findNativeMenuEntry, - folderNeedsNativePopulate, - getNativeMenuList, - getPagePathFromHash, - parseNativeMenu, -} from "./parseNativeMenu"; -import type { SidebarDrillFrame, SidebarItem } from "./types"; - -export const BSPLUS_DRILL_MS = 350; - -function orderItems(items: SidebarItem[], order: string[]): SidebarItem[] { - if (!order.length) return items; - - const byKey = new Map(items.map((item) => [item.key, item])); - const seen = new Set(); - const ordered: SidebarItem[] = []; - - for (const key of order) { - const item = byKey.get(key); - if (!item) continue; - ordered.push(item); - seen.add(key); - } - - for (const item of items) { - if (!seen.has(item.key)) ordered.push(item); - } - - return ordered; -} - -function filterVisible(items: SidebarItem[]): SidebarItem[] { - const menuItems = settingsState.menuitems as Record< - string, - { toggle?: boolean } | undefined - >; - - return items.filter((item) => menuItems[item.key]?.toggle !== false); -} - -function resetSidebarScroll() { - const root = document.getElementById("bsplus-sidebar-root"); - if (root instanceof HTMLElement) root.scrollTop = 0; -} - -function customMenuActiveState() { - return { - activeKey: sidebarState.activeKey, - drilling: sidebarState.isDrilling, - }; -} - -/** - * SEQTA strips `.active` from menu items after navigation. Restore the custom list - * state so the active subject/folder still matches the route and theme chrome. - */ -export function restoreCustomMenuActive() { - applyCustomMenuActive(customMenuActiveState()); -} - -function scheduleRestoreAfterSeqta() { - scheduleRestoreCustomMenuActive(customMenuActiveState()); -} - -/** Clear native drill state so it cannot steal pointer-events from the custom list. */ -export function clearNativeDrillActive(menu: HTMLElement) { - getNativeMenuList(menu) - ?.querySelectorAll("li.hasChildren.active, section.hasChildren.active") - .forEach((node) => node.classList.remove("active")); -} - -export function findItemByPath( - items: SidebarItem[], - path: string, -): SidebarItem | null { - for (const item of items) { - if (item.path === path) return item; - if (item.children.length) { - const nested = findItemByPath(item.children, path); - if (nested) return nested; - } - } - return null; -} - -function findItemByKeyInList( - items: SidebarItem[], - key: string, -): SidebarItem | null { - for (const item of items) { - if (item.key === key) return item; - if (item.children.length) { - const nested = findItemByKeyInList(item.children, key); - if (nested) return nested; - } - } - return null; -} - -function menuTreeEqual(a: SidebarItem[], b: SidebarItem[]): boolean { - if (a === b) return true; - if (a.length !== b.length) return false; - for (let i = 0; i < a.length; i++) { - const left = a[i]; - const right = b[i]; - if ( - left.key !== right.key || - left.path !== right.path || - left.label !== right.label || - left.iconHtml !== right.iconHtml || - left.hasChildren !== right.hasChildren || - left.itemColour !== right.itemColour || - left.betterseqta !== right.betterseqta || - left.id !== right.id || - !menuTreeEqual(left.children, right.children) - ) { - return false; - } - } - return true; -} - -function drillStackEqual( - a: SidebarDrillFrame[], - b: SidebarDrillFrame[], -): boolean { - if (a === b) return true; - if (a.length !== b.length) return false; - for (let i = 0; i < a.length; i++) { - const left = a[i]; - const right = b[i]; - if ( - left.key !== right.key || - left.label !== right.label || - left.items.length !== right.items.length || - left.items.some((item, j) => item.key !== right.items[j]?.key) - ) { - return false; - } - } - return true; -} - -class SidebarState { - items = $state.raw([]); - drillStack = $state.raw([]); - activeKey = $state(null); - activePath = $state(""); - editMode = $state(false); - iconOnly = $state(false); - /** Folder key playing the one-shot panel enter animation. */ - enterFrameKey = $state(null); - drillReturning = $state(false); - - visibleRootItems = $derived( - filterVisible(orderItems(this.items, settingsState.menuorder ?? [])), - ); - - /** Full ordered root list for edit mode (includes hidden items). */ - editRootItems = $derived( - orderItems(this.items, settingsState.menuorder ?? []), - ); - - isDrilling = $derived(this.drillStack.length > 0); - - compact = $derived(this.iconOnly && !this.isDrilling && !this.editMode); - - syncFromNative(menu: HTMLElement) { - const next = parseNativeMenu(menu); - if (!menuTreeEqual(this.items, next)) { - this.items = next; - } - this.syncActiveFromLocation(); - this.pruneDrillStack(); - } - - syncSettings() { - this.iconOnly = settingsState.iconOnlySidebar === true; - } - - syncActiveFromLocation() { - const path = getPagePathFromHash(); - this.activePath = path; - - if (!path) { - this.activeKey = null; - return; - } - - const exact = findItemByPath(this.items, path); - if (exact) { - this.activeKey = exact.key; - return; - } - - // Nested routes like /assessments/upcoming → assessments - const segments = path.split("/").filter(Boolean); - while (segments.length > 1) { - segments.pop(); - const parent = findItemByPath(this.items, `/${segments.join("/")}`); - if (parent) { - this.activeKey = parent.key; - return; - } - } - - this.activeKey = null; - } - - pruneDrillStack() { - if (!this.drillStack.length) return; - - const next: SidebarDrillFrame[] = []; - let cursor = this.visibleRootItems; - - for (const frame of this.drillStack) { - const folder = cursor.find((item) => item.key === frame.key); - if (!folder?.hasChildren) { - next.push(...this.drillStack.slice(next.length)); - break; - } - const children = filterVisible(folder.children); - next.push({ key: folder.key, label: folder.label, items: children }); - cursor = children; - } - - if (!drillStackEqual(this.drillStack, next)) { - this.drillStack = next; - } - } - - openFolder(item: SidebarItem, menu?: HTMLElement) { - if (!item.hasChildren || this.drillReturning) return; - if (this.drillStack.at(-1)?.key === item.key) return; - - this.drillReturning = false; - - const frame: SidebarDrillFrame = { - key: item.key, - label: item.label, - items: filterVisible(item.children), - }; - const isRoot = this.visibleRootItems.some( - (entry) => entry.key === item.key, - ); - - this.drillStack = isRoot ? [frame] : [...this.drillStack, frame]; - this.enterFrameKey = item.key; - - if (!animationsEnabled()) { - queueMicrotask(() => this.clearEnterFrame(item.key)); - } - - // Keep native drill closed so SEQTA CSS :has(> ul > li.hasChildren.active) - // does not lock pointer-events on the custom list. - if (menu) { - if (folderNeedsNativePopulate(item)) { - const native = findNativeMenuEntry(menu, item); - native?.click(); - } - clearNativeDrillActive(menu); - } - - // Absolute `.sub` panels live inside the scrollport — jump to top so the - // drilled page isn't left under the logo when the list was scrolled down. - resetSidebarScroll(); - scheduleRestoreAfterSeqta(); - } - - clearEnterFrame(key?: string) { - if (key == null || this.enterFrameKey === key) { - this.enterFrameKey = null; - } - } - - goBack() { - if (!this.drillStack.length || this.drillReturning) return; - - this.enterFrameKey = null; - this.drillStack = this.drillStack.slice(0, -1); - resetSidebarScroll(); - - if (!animationsEnabled()) return; - - this.drillReturning = true; - window.setTimeout(() => { - this.drillReturning = false; - }, BSPLUS_DRILL_MS + 20); - } - - resetDrill() { - this.enterFrameKey = null; - this.drillReturning = false; - this.drillStack = []; - resetSidebarScroll(); - } - - setEditMode(enabled: boolean) { - this.editMode = enabled; - if (enabled) this.resetDrill(); - } - - applyMenuOrder(keys: string[]) { - if (!keys.length) return; - settingsState.menuorder = [...keys]; - } - - reorderRoot(fromKey: string, toKey: string) { - if (fromKey === toKey) return; - const keys = this.editRootItems.map((item) => item.key); - const from = keys.indexOf(fromKey); - const to = keys.indexOf(toKey); - if (from < 0 || to < 0) return; - - const next = [...keys]; - const [moved] = next.splice(from, 1); - next.splice(to, 0, moved); - this.applyMenuOrder(next); - } - - setItemVisibility(key: string, visible: boolean) { - const current = { - ...(settingsState.menuitems as Record), - }; - current[key] = { toggle: visible }; - settingsState.menuitems = current as typeof settingsState.menuitems; - } - - restoreDefaultOrder() { - const defaults = settingsState.defaultmenuorder; - if (defaults?.length) { - settingsState.menuorder = [...defaults]; - } - - const restored: Record = {}; - for (const item of this.items) { - restored[item.key] = { toggle: true }; - } - settingsState.menuitems = restored as typeof settingsState.menuitems; - } - - activateItem(item: SidebarItem, menu: HTMLElement) { - if (this.editMode || this.drillReturning) return; - - if (item.hasChildren) { - this.openFolder(item, menu); - return; - } - - this.activeKey = item.key; - if (item.path) this.activePath = item.path; - - // Already inside this folder — never replay the one-shot enter animation when - // SEQTA rewrites `.active` on the route change. - if (this.isDrilling) { - this.enterFrameKey = null; - } - - const native = findNativeMenuEntry(menu, item); - if (native) { - native.click(); - scheduleRestoreAfterSeqta(); - return; - } - - if (item.path) { - location.hash = `?page=${item.path}`; - scheduleRestoreAfterSeqta(); - } - } - - findByKey(key: string) { - for (let i = this.drillStack.length - 1; i >= 0; i--) { - const hit = this.drillStack[i].items.find((item) => item.key === key); - if (hit) return hit; - } - return findItemByKeyInList(this.items, key); - } - - findByPath(path: string) { - return findItemByPath(this.items, path); - } - - resolveItem(key: string | undefined, path: string | undefined) { - if (path) { - const byPath = this.findByPath(path); - if (byPath) return byPath; - } - if (key) return this.findByKey(key); - return null; - } -} - -export const sidebarState = new SidebarState(); diff --git a/src/seqta/utils/Openers/OpenMenuOptions.ts b/src/seqta/utils/Openers/OpenMenuOptions.ts index 7622fff5..93256177 100644 --- a/src/seqta/utils/Openers/OpenMenuOptions.ts +++ b/src/seqta/utils/Openers/OpenMenuOptions.ts @@ -198,14 +198,6 @@ function restoreMenuItemsFromEditMode( export function OpenMenuOptions() { if (isMenuOptionsOpen()) return; - // Custom Svelte sidebar owns edit mode when mounted. - if (document.getElementById("bsplus-sidebar-root")) { - void import("@/seqta/ui/sidebar/mountCustomSidebar").then((mod) => { - if (mod.openCustomSidebarEditor()) setMenuOptionsOpen(true); - }); - return; - } - const container = document.getElementById("container"); const menu = document.getElementById("menu"); if (!container || !menu) return; diff --git a/src/seqta/utils/menuItemVisibility.ts b/src/seqta/utils/menuItemVisibility.ts index 28552362..50e8aaef 100644 --- a/src/seqta/utils/menuItemVisibility.ts +++ b/src/seqta/utils/menuItemVisibility.ts @@ -8,9 +8,7 @@ function buildMenuItemVisibilityCss(): string { let css = ""; for (const [menuItem, config] of Object.entries(settingsState.menuitems ?? {})) { if (config && !config.toggle) { - // Scope to the native SEQTA list only — the custom Svelte sidebar - // filters visibility in JS and must not be forced hidden by this rule. - css += `#menu > ul:not(#bsplus-sidebar-root) li[data-key=${menuItem}],#menu > ul:not(#bsplus-sidebar-root) section[data-key=${menuItem}]{display:var(--menuHidden) !important;}`; + css += `#menu > ul li[data-key=${menuItem}],#menu > ul section[data-key=${menuItem}]{display:var(--menuHidden) !important;}`; } } return css;