-
-
Notifications
You must be signed in to change notification settings - Fork 274
feat: page hierarchy overview #1449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
0dedd11
a1e7523
51d62fc
46ae091
b9a303b
f0ca1c3
ff156a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,31 @@ safeRun(async () => { | |
); | ||
// @ts-ignore: on purpose | ||
globalThis.client = client; | ||
|
||
// Widget utilities for collapsible sections | ||
// @ts-ignore: on purpose | ||
globalThis.sbWidgets = globalThis.sbWidgets || {}; | ||
|
||
// Toggle function for collapsible hierarchy | ||
// @ts-ignore: on purpose | ||
globalThis.sbWidgets.toggleHierarchy = function(header: HTMLElement) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems a little misplaced imo. This could just be in the widget code as a script tag, couldn't it? |
||
try { | ||
const widget = header.closest('.collapsible-hierarchy') as HTMLElement; | ||
if (!widget) return; | ||
|
||
const isCollapsed = widget.classList.contains('collapsed'); | ||
if (isCollapsed) { | ||
widget.classList.remove('collapsed'); | ||
header.setAttribute('aria-expanded', 'true'); | ||
} else { | ||
widget.classList.add('collapsed'); | ||
header.setAttribute('aria-expanded', 'false'); | ||
} | ||
} catch (error) { | ||
console.error('Error toggling hierarchy:', error); | ||
} | ||
}; | ||
|
||
await client.init(); | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,8 +114,11 @@ export class LuaWidget extends WidgetType { | |
if (widgetContent.cssClasses) { | ||
div.className = widgetContent.cssClasses.join(" "); | ||
} | ||
let htmlFromHtml: HTMLElement | undefined; | ||
let htmlFromMarkdown: HTMLElement | undefined; | ||
|
||
if (widgetContent.html) { | ||
html = typeof widgetContent.html === "string" | ||
htmlFromHtml = typeof widgetContent.html === "string" | ||
? parseHtmlString(widgetContent.html) | ||
: widgetContent.html; | ||
|
||
|
@@ -167,7 +170,7 @@ export class LuaWidget extends WidgetType { | |
trimmedMarkdown, | ||
); | ||
|
||
html = parseHtmlString(renderMarkdownToHtml(mdTree, { | ||
htmlFromMarkdown = parseHtmlString(renderMarkdownToHtml(mdTree, { | ||
translateUrls: (url) => { | ||
if (isLocalPath(url)) { | ||
url = resolvePath( | ||
|
@@ -181,7 +184,18 @@ export class LuaWidget extends WidgetType { | |
preserveAttributes: true, | ||
}, this.client.ui.viewState.allPages)); | ||
} | ||
if (html) { | ||
|
||
// Combine HTML from both sources: Markdown and HTML | ||
if (htmlFromHtml || htmlFromMarkdown) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like weird behaviour to me, it's not intuitive. |
||
if (htmlFromHtml && htmlFromMarkdown) { | ||
const combinedWrapper = document.createElement("div"); | ||
combinedWrapper.appendChild(htmlFromHtml); | ||
combinedWrapper.appendChild(htmlFromMarkdown); | ||
html = combinedWrapper; | ||
} else { | ||
// Only one type of content | ||
html = htmlFromHtml || htmlFromMarkdown!; | ||
} | ||
div.replaceChildren(this.wrapHtml(block, html)); | ||
attachWidgetEventHandlers( | ||
div, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,3 +159,63 @@ body { | |
.sb-markdown-toolbar:hover { | ||
opacity: 1; | ||
} | ||
|
||
/* Collapsible hierarchy widget styles */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be put into a style tag in the lua. Imo, keeping as much out of SB itself is the main objective |
||
.collapsible-hierarchy { | ||
margin: 1rem 0 2rem; | ||
|
||
h1 { | ||
margin: 0; | ||
padding: 0.5rem 0; | ||
font-size: 1.2rem; | ||
cursor: pointer; | ||
user-select: none; | ||
display: flex; | ||
align-items: center; | ||
gap: 0.5rem; | ||
|
||
&:hover { | ||
background-color: var(--ui-background-color); | ||
} | ||
|
||
&:focus { | ||
outline: 2px solid var(--accent-color); | ||
outline-offset: 2px; | ||
} | ||
} | ||
|
||
.chevron-icon { | ||
display: inline-block; | ||
width: 32px; | ||
height: 32px; | ||
margin-right: 8px; | ||
vertical-align: text-bottom; | ||
background-color: currentColor; | ||
-webkit-mask: var(--chevron-right-icon) no-repeat center; | ||
mask: var(--chevron-right-icon) no-repeat center; | ||
-webkit-mask-size: 70%; | ||
mask-size: 70%; | ||
} | ||
|
||
.hierarchy-content { | ||
overflow: hidden; | ||
transition: max-height 0.3s ease-in-out; | ||
max-height: 1000px; | ||
} | ||
|
||
&:not(.collapsed) { | ||
.chevron-icon { | ||
-webkit-mask: var(--chevron-down-icon) no-repeat center; | ||
mask: var(--chevron-down-icon) no-repeat center; | ||
-webkit-mask-size: 70%; | ||
mask-size: 70%; | ||
} | ||
} | ||
|
||
&.collapsed { | ||
|
||
.hierarchy-content { | ||
max-height: 0; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -302,3 +302,9 @@ html[data-theme="dark"] { | |
--admonition-icon: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path><line x1="12" y1="9" x2="12" y2="13"></line><line x1="12" y1="17" x2="12.01" y2="17"></line></svg>'); | ||
--admonition-color: #ff9100; | ||
} | ||
|
||
/* Chevron icons for collapsible sections */ | ||
html { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See the other comments |
||
--chevron-right-icon: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9,18 15,12 9,6"></polyline></svg>'); | ||
--chevron-down-icon: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6,9 12,15 18,9"></polyline></svg>'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't the multiline string syntax be better suited here?
[[ ... ]]