Skip to content
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

feat: preserve toc expanded/collapsed state #4063

Open
wants to merge 2 commits into
base: ktl-review-fixes
Choose a base branch
from

Conversation

berezinant
Copy link
Contributor

No description provided.

@berezinant berezinant force-pushed the ktl-toc-expand-collapse branch 2 times, most recently from 95ce8a3 to 0680826 Compare March 26, 2025 17:15

Verified

This commit was signed with the committer’s verified signature.
berezinant Anton Berezin
@berezinant berezinant force-pushed the ktl-toc-expand-collapse branch from 0680826 to aa9ac4a Compare March 26, 2025 17:18
@berezinant berezinant marked this pull request as ready for review March 26, 2025 17:18
@@ -40,7 +40,6 @@ function initFilterSection(): void {
const dropdownButton = document.getElementById('filter-section-dropdown');

if (!navigation || !libraryVersion || !filterSection || !firstButtonAfterFilterSection || !dropdownButton) {
console.warn('Dokka: filter section is not found');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this log is not important, it only spams on pages without source set selectors

/** When Dokka is viewed via iframe, local storage could be inaccessible (see https://github.com/Kotlin/dokka/issues/3323)
* The wrapper around local storage to prevent errors in such cases is defined in the plugin-base scripts assets
* */
declare const safeLocalStorage: {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we just need a type declaration because safeLocalStorage is defined in a separate script outside of the ui-kit

/** When Dokka is viewed via iframe, local storage could be inaccessible (see https://github.com/Kotlin/dokka/issues/3323)
* This is a wrapper around local storage to prevent errors in such cases
* */
const safeLocalStorage = (() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SafeLocalStorage was moved to a separate script.
This was made to reduce duplication of it's declaration and to ensure that it's loaded before other scripts which depend on safeLocalStorage

@@ -2,7 +2,6 @@
* Copyright 2014-2025 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
import { ColumnResizer } from '@column-resizer/core';
import { safeLocalStorage } from '../safeLocalStorage';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to import as it is global now

@@ -119,10 +119,10 @@ public class DefaultTemplateModelFactory(
type = ScriptType.textJavaScript,
src = if (resource.isAbsolute) resource else "$pathToRoot$resource"
) {
if (resource == "scripts/main.js" || resource == "ui-kit/ui-kit.min.js" || resource.endsWith("_deferred.js"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refined this logic to allow loading regular blocking scripts


navigationPageText = fetch(pathToRoot + "navigation.html").then(response => response.text())
(function () {
function displayToc() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the part with the core ToC logics. It's loaded in a separate script to make sure that we load navigation as soon as possible

Verified

This commit was signed with the committer’s verified signature.
berezinant Anton Berezin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant