From 9518b0334dd76831f1130b04fa24b28c09cd5ab1 Mon Sep 17 00:00:00 2001 From: Pierre Demailly Date: Mon, 6 Jan 2025 22:14:51 +0100 Subject: [PATCH] feat: show single package search-nav --- public/core/search-nav.js | 33 ++++++++++++++++++++++++++------- public/main.js | 11 +++++++++-- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/public/core/search-nav.js b/public/core/search-nav.js index bde4b94..fcaf0ad 100644 --- a/public/core/search-nav.js +++ b/public/core/search-nav.js @@ -3,14 +3,20 @@ import { createDOMElement, parseNpmSpec } from "../common/utils"; import { SearchBar } from "../components/searchbar/searchbar"; export function initSearchNav(data, options) { - const { initFromZero = true, searchOptions = null } = options; + const { initFromZero = true, searchOptions = null, initSinglePackage } = options; const searchNavElement = document.getElementById("search-nav"); if (!searchNavElement) { throw new Error("Unable to found search navigation"); } - if (initFromZero) { + if (initSinglePackage) { + searchNavElement.innerHTML = ""; + searchNavElement.appendChild( + initSingleNavigation(initSinglePackage) + ); + } + else if (initFromZero) { searchNavElement.innerHTML = ""; searchNavElement.appendChild( initPackagesNavigation(data) @@ -123,9 +129,22 @@ function renderPackageRemoveButton(packageName, options) { return removeButton; } -export function hideSearchNav() { - const searchNavElement = document.getElementById("search-nav"); - if (searchNavElement) { - searchNavElement.classList.add("hidden"); - } +function initSingleNavigation(packageName) { + const fragment = document.createDocumentFragment(); + const container = createDOMElement("div", { + classList: ["packages"] + }); + + const pkgElement = createDOMElement("div", { + classList: ["package"], + childs: [ + createDOMElement("p", { text: packageName }) + ] + }); + pkgElement.dataset.name = packageName; + + container.appendChild(pkgElement); + fragment.append(container); + + return fragment; } diff --git a/public/main.js b/public/main.js index 10d858c..2ca6195 100644 --- a/public/main.js +++ b/public/main.js @@ -17,7 +17,7 @@ import { SearchView } from "./components/views/search/search.js"; // Import Core Components import { NetworkNavigation } from "./core/network-navigation.js"; import { i18n } from "./core/i18n.js"; -import { initSearchNav, hideSearchNav } from "./core/search-nav.js"; +import { initSearchNav } from "./core/search-nav.js"; // Import Utils import * as utils from "./common/utils.js"; @@ -36,7 +36,6 @@ document.addEventListener("DOMContentLoaded", async() => { if (window.settings.config.standalone) { console.log(`[INFO] Standalone mode activated`); window.navigation.hideMenu("search--view", { navigateAway: true }); - hideSearchNav(); } window.i18n = await new i18n().fetch(); window.wiki = new Wiki(); @@ -117,6 +116,14 @@ async function init(options = {}) { if (window.settings.config.standalone === false) { searchview ??= new SearchView(secureDataSet, nsn); } + else { + initSearchNav(void 0, { + initSinglePackage: secureDataSet.data.rootDependencyName, + searchOptions: { + nsn, secureDataSet + } + }); + } window.addEventListener("package-info-closed", () => { window.networkNav.currentNodeParams = null;