fix: remove svelte sidebar but keep customisations

This commit is contained in:
AdenMGB committed 2026-09-07 10:28:11 +09:30
1 parent 2c0642f418
commit 7a8a3cb70e
20 files changed
+484 -2383

No files matched your search

+4 -215
View File
@@ -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;
}
-35
View File
@@ -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;
}
}
+101 -140
View File
@@ -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;
}
+27 -11
View File
@@ -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;
@@ -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");
+5 -8
View File
@@ -209,8 +209,8 @@ function SortMessagePageItems(messagesParentElement: any) {
async function LoadPageElements(): Promise<void> {
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");
}
+17 -44
View File
@@ -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<any> | 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(
-455
View File
@@ -1,455 +0,0 @@
<script lang="ts">
import { onDestroy } from "svelte";
import Sortable from "sortablejs";
import { settingsState } from "@/seqta/utils/listeners/SettingsState";
import { sidebarState } from "./sidebarState.svelte";
import SidebarItem from "./SidebarItem.svelte";
import type {
SidebarDrillFrame,
SidebarItem as SidebarItemModel,
} from "./types";
type Props = {
menuEl: HTMLElement;
};
let { menuEl }: Props = $props();
let listEl = $state<HTMLElement | null>(null);
let coverEl: HTMLElement | null = null;
let sortable: Sortable | null = null;
let dragging = $state(false);
const BACK_SVG = `<svg width="24" height="24" viewBox="0 0 24 24" aria-hidden="true"><g style="fill: currentcolor;"><path d="M15.422 16.078l-1.406 1.406-6-6 6-6 1.406 1.406-4.594 4.594z"></path></g></svg>`;
function itemVisible(key: string): boolean {
return (
(settingsState.menuitems as Record<string, { toggle?: boolean }>)[key]
?.toggle !== false
);
}
function onActivate(item: SidebarItemModel) {
sidebarState.activateItem(item, menuEl);
}
function closeEdit() {
sidebarState.setEditMode(false);
void import("@/seqta/utils/Openers/menuOptionsState").then((mod) => {
mod.setMenuOptionsOpen(false);
});
}
const drillFolders = $derived(
sidebarState.drillStack.map((frame) => ({
frame,
folder: sidebarState.findByKey(frame.key),
})),
);
function onToggleVisible(key: string, visible: boolean) {
sidebarState.setItemVisibility(key, visible);
}
function destroySortable() {
sortable?.destroy();
sortable = null;
dragging = false;
document.documentElement.style.removeProperty("--bsplus-drag-width");
}
function syncSortableFromState() {
if (!sortable || dragging) return;
const order = sidebarState.editRootItems.map((item) => item.key);
sortable.sort(order, true);
}
function restoreDefault() {
sidebarState.restoreDefaultOrder();
queueMicrotask(syncSortableFromState);
}
$effect(() => {
const editing = sidebarState.editMode;
const list = listEl;
destroySortable();
if (!editing || !list) return;
sortable = Sortable.create(list, {
animation: 220,
easing: "cubic-bezier(0.22, 1, 0.36, 1)",
draggable: ".bsplus-sidebar-item.draggable",
filter: ".toggle, .toggle input, .bsplus-sidebar-edit-header, .bsplus-sidebar-edit-actions",
preventOnFilter: false,
dataIdAttr: "data-key",
ghostClass: "bsplus-sortable-ghost",
chosenClass: "bsplus-sortable-chosen",
dragClass: "bsplus-sortable-drag",
forceFallback: true,
fallbackOnBody: true,
fallbackTolerance: 3,
swapThreshold: 0.65,
direction: "vertical",
onStart: (evt) => {
dragging = true;
const width = evt.item.getBoundingClientRect().width;
document.documentElement.style.setProperty(
"--bsplus-drag-width",
`${Math.round(width)}px`,
);
// Fallback clone is created just after onStart; pin size + drop
// Active styling makes fallback clones wider; keep the source width.
requestAnimationFrame(() => {
const dragEl = document.querySelector(
".bsplus-sortable-drag",
) as HTMLElement | null;
if (!dragEl) return;
dragEl.style.width = `${Math.round(width)}px`;
dragEl.style.maxWidth = `${Math.round(width)}px`;
dragEl.classList.remove("bsplus-active");
});
},
onEnd: (evt) => {
dragging = false;
document.documentElement.style.removeProperty("--bsplus-drag-width");
if (evt.from !== evt.to) return;
if (evt.oldIndex == null || evt.newIndex == null) return;
if (evt.oldIndex === evt.newIndex) return;
sidebarState.applyMenuOrder(sortable?.toArray() ?? []);
},
});
return () => {
destroySortable();
};
});
$effect(() => {
const editing = sidebarState.editMode;
const container = document.getElementById("container");
if (editing && container && !coverEl) {
const cover = document.createElement("div");
cover.className = "notMenuCover bsplus-sidebar-edit-cover";
cover.addEventListener("click", closeEdit);
container.appendChild(cover);
menuEl.style.zIndex = "20";
menuEl.classList.add("bsplus-sidebar-edit-mode");
coverEl = cover;
}
if (!editing) {
coverEl?.remove();
coverEl = null;
menuEl.style.removeProperty("z-index");
menuEl.classList.remove("bsplus-sidebar-edit-mode");
}
return () => {
coverEl?.remove();
coverEl = null;
menuEl.style.removeProperty("z-index");
};
});
// Drill `.sub` is position:absolute inside this scrollport — if the list was
// scrolled down (e.g. Folios/Goals near the bottom), the panel sits under the
// logo until we reset. Also reset when going back up the stack.
$effect(() => {
void sidebarState.drillStack.length;
void sidebarState.enterFrameKey;
const root = document.getElementById("bsplus-sidebar-root");
if (!root) return;
root.scrollTop = 0;
requestAnimationFrame(() => {
root.scrollTop = 0;
});
});
onDestroy(() => {
destroySortable();
coverEl?.remove();
coverEl = null;
});
</script>
<!--
Direct `#menu > ul.logo-link` child so theme selectors like
`#menu > ul > li.item` / `#menu .sub` / `:has(> ul > li.hasChildren.active)` match.
-->
<ul
id="bsplus-sidebar-root"
class="logo-link bsplus-sidebar-list"
class:noscroll={sidebarState.isDrilling}
class:drilling={sidebarState.isDrilling}
class:drill-entering={sidebarState.enterFrameKey != null}
class:drill-returning={sidebarState.drillReturning}
class:compact={sidebarState.compact}
class:edit-mode={sidebarState.editMode}
class:is-sorting={dragging}
aria-label="Main"
bind:this={listEl}
>
{#if sidebarState.editMode}
<li class="item bsplus-sidebar-edit-header" aria-hidden="true">
<!-- svelte-ignore a11y_label_has_associated_control -->
<label><span class="label">Edit Sidebar</span></label>
</li>
{#each sidebarState.editRootItems as item (item.key)}
<SidebarItem
{item}
active={sidebarState.activeKey === item.key}
compact={false}
editMode={true}
visible={itemVisible(item.key)}
{onActivate}
{onToggleVisible}
/>
{/each}
<li class="item bsplus-sidebar-edit-actions">
<button type="button" class="edit-btn" onclick={restoreDefault}>
Restore Default
</button>
<button type="button" class="edit-btn primary" onclick={closeEdit}>
Save
</button>
</li>
{:else if drillFolders.length}
<!-- Keep root rows in the DOM so sidebar-animation.scss can slide siblings.
Never mark root leaves active while drilling — theme decorations
(Beach palm/sand) would show through the transparent .sub panel. -->
{#each sidebarState.visibleRootItems as item (item.key)}
{#if item.key === drillFolders[0].frame.key}
{@render drillLevel(drillFolders, 0)}
{:else}
<SidebarItem
{item}
active={false}
compact={false}
editMode={false}
visible={true}
{onActivate}
/>
{/if}
{/each}
{:else}
{#each sidebarState.visibleRootItems as item (item.key)}
<SidebarItem
{item}
active={sidebarState.activeKey === item.key}
compact={sidebarState.compact}
editMode={false}
visible={true}
{onActivate}
/>
{/each}
{/if}
</ul>
{#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}
<li
class="item hasChildren bsplus-sidebar-item"
class:bsplus-active={true}
data-key={current.frame.key}
data-path={folder?.path ?? undefined}
style:--item-colour={folder?.itemColour || undefined}
>
<!-- svelte-ignore a11y_label_has_associated_control -->
<label>
{#if folder?.iconHtml}
{@html folder.iconHtml}
{/if}
<span class="label">{current.frame.label}</span>
</label>
<div
class="sub"
class:bsplus-sub-enter={sidebarState.enterFrameKey === current.frame.key}
onanimationend={(e) => {
if (e.target !== e.currentTarget) return;
if (sidebarState.enterFrameKey === current.frame.key) {
sidebarState.clearEnterFrame(current.frame.key);
}
}}
>
<div class="nav">
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div
class="back"
role="button"
tabindex="0"
aria-label="Back"
onclick={(e) => {
e.preventDefault();
e.stopPropagation();
sidebarState.goBack();
}}
onkeydown={(e) => {
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
e.stopPropagation();
sidebarState.goBack();
}
}}
>
{@html BACK_SVG}
<div class="backLabel">{current.frame.label}</div>
</div>
</div>
<ul>
{#if isLast}
{#each current.frame.items as item (item.key)}
<SidebarItem
{item}
active={sidebarState.activeKey === item.key}
compact={false}
editMode={false}
visible={true}
drillEnter={sidebarState.enterFrameKey === current.frame.key}
{onActivate}
/>
{/each}
{:else}
{#each current.frame.items as item (item.key)}
{#if item.key === nextKey}
{@render drillLevel(frames, depth + 1)}
{:else}
<SidebarItem
{item}
active={sidebarState.activeKey === item.key}
compact={false}
editMode={false}
visible={true}
{onActivate}
/>
{/if}
{/each}
{/if}
</ul>
</div>
</li>
{/snippet}
<style>
.bsplus-sidebar-list {
list-style: none;
margin: 0;
padding: 0 0 16px;
flex: 1 1 auto;
min-height: 0;
width: 100%;
height: 100%;
overflow-y: auto;
overflow-x: hidden;
position: relative;
box-sizing: border-box;
color: var(--text-color, #fff);
scrollbar-width: thin;
z-index: 2;
}
.bsplus-sidebar-list.noscroll,
.bsplus-sidebar-list.drilling {
overflow: hidden;
}
.bsplus-sidebar-list.compact {
display: flex;
flex-direction: column;
align-items: center;
}
.bsplus-sidebar-list.is-sorting {
cursor: grabbing;
user-select: none;
}
.bsplus-sidebar-edit-header {
pointer-events: none;
width: 85%;
margin: 8px auto 4px;
font-weight: 700;
font-size: 16px;
}
.bsplus-sidebar-edit-header > label {
display: block;
padding: 12px 16px 4px;
}
.bsplus-sidebar-edit-actions {
display: flex;
gap: 8px;
width: calc(100% - 12px);
margin: 12px 6px 16px;
padding: 0;
list-style: none;
cursor: default;
box-sizing: border-box;
}
.edit-btn {
flex: 1 1 0;
min-width: 0;
padding: 10px 8px;
border: none;
border-radius: 10px;
background: rgba(0, 0, 0, 0.2);
color: inherit;
font-family: inherit;
font-size: 13px;
font-weight: 700;
line-height: 1.2;
white-space: nowrap;
cursor: pointer;
transition:
background-color 0.2s ease,
transform 0.2s ease;
}
.edit-btn:hover {
background: rgba(0, 0, 0, 0.32);
transform: scale(1.02);
}
.edit-btn:active {
transform: scale(0.98);
}
.edit-btn.primary {
background: rgba(0, 0, 0, 0.4);
}
/* SortableJS classes (applied to our items; must be :global). */
.bsplus-sidebar-list :global(.bsplus-sortable-ghost) {
opacity: 0.35 !important;
background: rgba(255, 255, 255, 0.08) !important;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}
.bsplus-sidebar-list :global(.bsplus-sortable-chosen) {
background: rgba(0, 0, 0, 0.28) !important;
}
.bsplus-sidebar-list :global(.bsplus-sortable-drag),
:global(.bsplus-sortable-drag) {
opacity: 1 !important;
cursor: grabbing !important;
z-index: 10000 !important;
width: var(--bsplus-drag-width, 240px) !important;
max-width: var(--bsplus-drag-width, 240px) !important;
box-sizing: border-box !important;
box-shadow:
0 14px 32px rgba(0, 0, 0, 0.35),
0 0 0 1px rgba(255, 255, 255, 0.12) !important;
transform: scale(1.03);
background: rgba(0, 0, 0, 0.45) !important;
}
</style>
-246
View File
@@ -1,246 +0,0 @@
<script lang="ts">
import type { SidebarItem } from "./types";
type Props = {
item: SidebarItem;
active: boolean;
compact: boolean;
editMode: boolean;
visible: boolean;
/** Reserved — panel slide handles enter motion; no per-item fly. */
drillEnter?: boolean;
onActivate: (item: SidebarItem) => void;
onToggleVisible?: (key: string, visible: boolean) => void;
};
let {
item,
active,
compact,
editMode,
visible,
drillEnter: _drillEnter = false,
onActivate,
onToggleVisible,
}: Props = $props();
const CHEVRON_SVG = `<svg width="24" height="24" viewBox="0 0 24 24" aria-hidden="true"><g style="fill: currentcolor;"><path d="M8.578 16.359l4.594-4.594-4.594-4.594 1.406-1.406 6 6-6 6z"></path></g></svg>`;
const GRIP_SVG = `<svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><circle cx="5" cy="3" r="1.35" fill="currentColor"/><circle cx="11" cy="3" r="1.35" fill="currentColor"/><circle cx="5" cy="8" r="1.35" fill="currentColor"/><circle cx="11" cy="8" r="1.35" fill="currentColor"/><circle cx="5" cy="13" r="1.35" fill="currentColor"/><circle cx="11" cy="13" r="1.35" fill="currentColor"/></svg>`;
</script>
<!-- Keep SEQTA's structural attributes so existing themes recognize each row. -->
<!-- svelte-ignore a11y_no_noninteractive_element_to_interactive_role -->
<li
class="item bsplus-sidebar-item"
class:bsplus-active={active}
class:hasChildren={item.hasChildren}
class:edit-mode={editMode}
class:hidden-item={editMode && !visible}
class:compact={compact}
class:draggable={editMode}
style:--item-colour={item.itemColour || undefined}
data-colour={item.itemColour || undefined}
data-key={item.key}
data-path={item.path ?? undefined}
data-betterseqta={item.betterseqta ? "true" : undefined}
id={item.id ?? undefined}
role="button"
tabindex={editMode ? -1 : 0}
aria-label={item.label}
aria-current={active ? "page" : undefined}
onclick={(e) => {
// 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}
<span class="drag-grip" aria-hidden="true">{@html GRIP_SVG}</span>
{/if}
<!-- svelte-ignore a11y_label_has_associated_control -->
<label>
{#if item.iconHtml}
<!-- svelte-ignore a11y_distracting_elements -->
{@html item.iconHtml}
{/if}
<span class="label">{item.label}</span>
{#if item.hasChildren && !compact && !editMode}
<span class="chevron" aria-hidden="true">{@html CHEVRON_SVG}</span>
{/if}
</label>
{#if editMode}
<label class="toggle">
<input
type="checkbox"
checked={visible}
onclick={(e) => e.stopPropagation()}
onchange={(e) =>
onToggleVisible?.(
item.key,
(e.currentTarget as HTMLInputElement).checked,
)}
/>
</label>
{/if}
</li>
<style>
/* Layout defaults — theme #menu rules (often !important) win for look. */
.bsplus-sidebar-item {
position: relative;
list-style: none;
width: auto;
margin: 2px 6px;
padding: 0;
border-radius: 12px;
color: var(--text-color, #fff);
cursor: pointer;
display: flex;
align-items: center;
box-sizing: border-box;
transition:
background-color 0.2s ease,
box-shadow 0.2s ease,
opacity 0.2s ease;
user-select: none;
}
.bsplus-sidebar-item > label:not(.toggle) {
display: flex;
align-items: center;
flex: 1 1 auto;
width: auto;
min-width: 0;
margin: 0;
padding: 12px;
cursor: inherit;
color: inherit;
}
.bsplus-sidebar-item:hover:not(.bsplus-active) {
background: rgba(0, 0, 0, 0.15);
}
.bsplus-sidebar-item:focus-visible {
outline: none;
box-shadow: 0 0 0 2px var(--theme-primary, #fff);
}
.bsplus-sidebar-item.bsplus-active:not(.hasChildren),
.bsplus-sidebar-item.bsplus-active:not(.hasChildren):hover {
background: rgba(0, 0, 0, 0.35);
color: #fff;
}
.bsplus-sidebar-item.compact {
justify-content: center;
}
.bsplus-sidebar-item.compact > label:not(.toggle) {
padding: 8px;
justify-content: center;
}
.bsplus-sidebar-item.hidden-item {
opacity: 0.45;
}
.bsplus-sidebar-item.edit-mode {
cursor: grab;
gap: 0;
}
.bsplus-sidebar-item.edit-mode:active {
cursor: grabbing;
}
/* Keep the same label padding/size as normal items; only reserve toggle space. */
.bsplus-sidebar-item.edit-mode > label:not(.toggle) {
flex: 1 1 auto;
width: auto;
min-width: 0;
padding: 12px;
padding-left: 4px;
}
.drag-grip {
display: inline-flex;
align-items: center;
justify-content: center;
flex: 0 0 auto;
width: 20px;
margin-left: 10px;
opacity: 0.45;
color: inherit;
pointer-events: none;
}
.bsplus-sidebar-item.edit-mode:hover .drag-grip {
opacity: 0.8;
}
.bsplus-sidebar-item :global(label > svg) {
flex-shrink: 0;
}
.compact :global(label > svg) {
margin: 0;
}
.label {
flex: 1;
min-width: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
line-height: 1.2;
}
.compact .label,
.compact .chevron {
display: none;
}
.chevron {
display: inline-flex;
flex-shrink: 0;
margin-left: auto;
opacity: 0.85;
}
.chevron :global(svg) {
width: 24px;
height: 24px;
}
.toggle {
margin: 0 10px 0 0;
display: inline-flex;
align-items: center;
justify-content: center;
cursor: pointer;
flex: 0 0 auto;
width: auto;
padding: 0;
position: relative;
z-index: 2;
}
.toggle input {
width: 18px;
height: 18px;
margin: 0;
flex-shrink: 0;
accent-color: var(--theme-primary, #fff);
}
</style>
+109
View File
@@ -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<boolean> {
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;
}
@@ -1,87 +0,0 @@
/**
* @jest-environment jsdom
*/
import {
applyCustomMenuActive,
scheduleRestoreCustomMenuActive,
} from "./customMenuActive";
describe("applyCustomMenuActive", () => {
beforeEach(() => {
document.body.innerHTML = `
<ul id="bsplus-sidebar-root" class="drilling">
<li class="item hasChildren" data-key="assessments">
<label><span>Assessments</span></label>
<div class="sub">
<div class="nav"><div class="back"><div class="backLabel">Assessments</div></div></div>
<ul>
<li class="item" data-key="4804:11066" aria-current="page">
<label><span>English</span></label>
</li>
</ul>
</div>
</li>
</ul>
`;
});
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 = `
<ul id="bsplus-sidebar-root" class="drilling">
<li class="item hasChildren" data-key="assessments">
<div class="sub"><ul>
<li class="item" data-key="upcoming" aria-current="page"></li>
</ul></div>
</li>
</ul>
`;
});
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);
});
});
-72
View File
@@ -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<typeof setTimeout> | 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);
});
}
+18 -7
View File
@@ -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";
-409
View File
@@ -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<typeof mount> | null = null;
let menuEl: HTMLElement | null = null;
let menuObserver: MutationObserver | null = null;
let syncTimer: ReturnType<typeof setTimeout> | null = null;
let hashListenerAttached = false;
let sidebarCaptureAttached = false;
let earlyPrepareStarted = false;
let catchupTimers: ReturnType<typeof setTimeout>[] = [];
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<boolean> {
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();
}
@@ -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 = `
<div id="menu">
<ul>
<li class="item" data-key="home" id="homebutton" data-path="/home" data-betterseqta="true">
<label><svg></svg><span>Home</span></label>
</li>
<li class="item hasChildren" data-key="assessments" data-path="/assessments">
<label><svg></svg><span>Assessments</span></label>
<div class="sub"><ul>
<li class="item betterseqta-assessments-overview-item" data-betterseqta="true">
<label>Overview</label>
</li>
<li class="item" data-key="upcoming" data-path="/assessments/upcoming">
<label>Upcoming</label>
</li>
</ul></div>
</li>
</ul>
</div>
`;
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 = `
<div id="menu">
<ul class="logo-link">
<li class="item" data-key="home" data-path="/home">
<label>Home</label>
</li>
</ul>
<ul id="bsplus-sidebar-root" class="logo-link bsplus-sidebar-list">
<li class="item" data-key="fake" data-path="/fake">
<label>Fake</label>
</li>
</ul>
</div>
`;
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 = `
<div id="menu">
<ul>
<li class="item hasChildren" data-key="courses" data-path="/courses">
<label>Courses</label>
<div class="sub"><ul>
<li class="item hasChildren" data-key="4804:11066">
<label>English</label>
<div class="sub"><ul>
<li class="item" data-key="4804:11066" data-path="/courses/4804:11066">
<label>Course</label>
</li>
<li class="item" data-key="4804:11066" data-path="/assessments/4804:11066">
<label>Assessments</label>
</li>
</ul></div>
</li>
</ul></div>
</li>
</ul>
</div>
`;
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 = `
<div id="menu">
<ul>
<li class="item hasChildren" data-key="assessments" data-path="/assessments">
<label>Assessments</label>
<div class="sub"><ul>
<li class="item hasChildren">
<label>Year 12</label>
<div class="sub"><ul>
<li class="item" data-key="4804:11066" data-colour="#f00">
<label>English</label>
</li>
</ul></div>
</li>
</ul></div>
</li>
<li class="item hasChildren" data-key="courses" data-path="/courses">
<label>Courses</label>
<div class="sub"><ul>
<li class="item hasChildren" data-key="4804:11066">
<label>English</label>
<div class="sub"><ul>
<li class="item" data-key="4804:11066" data-path="/courses/4804:11066">
<label>Course</label>
</li>
</ul></div>
</li>
</ul></div>
</li>
</ul>
</div>
`;
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);
});
});
+2 -4
View File
@@ -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 {
+198
View File
@@ -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<HTMLElement>(
":scope > li > label, :scope > li > svg, :scope > section > label, :scope > section > svg",
),
];
}
function clearInlineReturnStyles(nodes: Iterable<HTMLElement>) {
for (const node of nodes) {
node.style.removeProperty("transition");
node.style.removeProperty("transform");
}
}
let returnTimer: ReturnType<typeof setTimeout> | 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;
}
-401
View File
@@ -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<string>();
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<SidebarItem[]>([]);
drillStack = $state.raw<SidebarDrillFrame[]>([]);
activeKey = $state<string | null>(null);
activePath = $state("");
editMode = $state(false);
iconOnly = $state(false);
/** Folder key playing the one-shot panel enter animation. */
enterFrameKey = $state<string | null>(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<string, { toggle: boolean }>),
};
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<string, { toggle: boolean }> = {};
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();
@@ -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;
+1 -3
View File
@@ -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;