Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions public/components/bundlephobia/bundlephobia.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,16 @@ class Bundlephobia extends LitElement {

#bunldeTask = new Task(this, {
task: async([name, version]) => {
try {
const {
gzip, size, dependencySizes
} = await getJSON(`/bundle/${this.#httpName(name)}/${version}`);
const fullSize = dependencySizes.reduce((prev, curr) => prev + curr.approximateSize, 0);

return {
gzip: prettyBytes(gzip),
min: prettyBytes(size),
full: prettyBytes(fullSize)
};
}
catch {
return null;
}
const {
gzip, size, dependencySizes
} = await getJSON(`/bundle/${this.#httpName(name)}/${version}`);
const fullSize = dependencySizes.reduce((prev, curr) => prev + curr.approximateSize, 0);

return {
gzip: prettyBytes(gzip),
min: prettyBytes(size),
full: prettyBytes(fullSize)
};
},
args: () => [this.name, this.version]
});
Expand Down
26 changes: 15 additions & 11 deletions public/components/package/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { EVENTS } from "../../core/events.js";

export class PackageInfo {
static DOMElementName = "package-info";
/**
* Used to force a specific menu to open when focusing a package in the network
*/
static ForcedPackageMenu = null;

static close() {
const domElement = document.getElementById(PackageInfo.DOMElementName);
Expand Down Expand Up @@ -78,14 +82,6 @@ export class PackageInfo {
packageHTMLElement.appendChild(
this.render()
);
this.enableNavigation(
window.settings.config.defaultPackageMenu
);
packageHTMLElement.setAttribute("class", "slide-in");

if (window.settings.config.disableExternalRequests) {
return;
}

const panFiles = packageHTMLElement.querySelector("#pan-files");
const files = document.createElement("package-files");
Expand Down Expand Up @@ -117,6 +113,12 @@ export class PackageInfo {
scripts.id = "pan-dependencies";
scripts.classList.add("package-container", "hidden");
panDependencies.parentElement.replaceChild(scripts, panDependencies);

const menuToOpen = PackageInfo.ForcedPackageMenu ??
window.settings.config.defaultPackageMenu;
this.enableNavigation(menuToOpen);
PackageInfo.ForcedPackageMenu = null;
packageHTMLElement.setAttribute("class", "slide-in");
}

/**
Expand Down Expand Up @@ -153,7 +155,9 @@ export class PackageInfo {
* @returns {void}
*/
enableNavigation(name) {
const div = this.menus.has(name) ? this.menus.get(name) : this.menus.get("info");
const div = this.menus.has(name) ?
this.menus.get(name) :
this.menus.get("info");

const isActive = div.classList.contains("active");
const isDisabled = div.classList.contains("disabled");
Expand All @@ -166,10 +170,10 @@ export class PackageInfo {
div.classList.add("active");
this.activeNavigation.classList.remove("active");

const targetPan = document.getElementById(`pan-${name}`);
const currentPan = document.getElementById(`pan-${this.activeNavigation.getAttribute("data-menu")}`);
targetPan.classList.remove("hidden");
currentPan.classList.add("hidden");
const targetPan = document.getElementById(`pan-${name}`);
targetPan.classList.remove("hidden");
document.querySelector(".container-title").textContent = dataTitle;

this.activeNavigation = div;
Expand Down
58 changes: 32 additions & 26 deletions public/components/package/pannels/files/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,40 @@ import { scrollbarStyle } from "../../../../common/scrollbar-style.js";
class Files extends LitElement {
static styles = [scrollbarStyle, css`
:host{
display: block;
overflow: hidden auto;
height: calc(100vh - 315px);
box-sizing: border-box;
display: block;
overflow: hidden auto;
height: calc(100vh - 315px);
box-sizing: border-box;
}

.head-title {
background: var(--primary-darker);
height: 28px;
flex-shrink: 0;
display: flex;
align-items: center;
border-bottom: 2px solid var(--primary-lighter);
border-radius: 2px 2px 0 0;
}
background: var(--primary-darker);
height: 28px;
flex-shrink: 0;
display: flex;
align-items: center;
border-bottom: 2px solid var(--primary-lighter);
border-radius: 2px 2px 0 0;
}

.head-title.no-margin {
margin-top: 0;
}
margin-top: 0;
}

.head-title>p {
text-shadow: 1px 1px 5px rgb(20 20 20 / 50%);
font-size: 18px;
font-variant: small-caps;

/* lowercase is needed with small-caps font variant */
text-transform: lowercase;
font-family: mononoki;
font-weight: bold;
letter-spacing: 1px;
padding: 0 10px;
}
text-shadow: 1px 1px 5px rgb(20 20 20 / 50%);
font-size: 18px;
font-variant: small-caps;

/* lowercase is needed with small-caps font variant */
text-transform: lowercase;
font-family: mononoki;
font-weight: bold;
letter-spacing: 1px;
padding: 0 10px;
}
`];

static properties = {
package: { type: Object }
};
Expand Down Expand Up @@ -107,7 +108,12 @@ class Files extends LitElement {
`,
() => nothing
)}
<bundle-phobia name=${name} version=${version}></bundle-phobia>

${when(
window.settings.config.disableExternalRequests === false,
() => html`<bundle-phobia name=${name} version=${version}></bundle-phobia>`,
() => nothing
)}
`;
}

Expand Down
80 changes: 67 additions & 13 deletions public/components/views/home/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import * as utils from "../../../common/utils.js";
import "../../gauge/gauge.js";
import "../../expandable/expandable.js";
import { EVENTS } from "../../../core/events.js";
import { fetchScorecardData, getScorecardLink } from "../../../common/scorecard.js";
import { PackageInfo } from "../../package/package.js";
import {
fetchScorecardData,
getScorecardLink
} from "../../../common/scorecard.js";

// Import Components
import "./maintainers/maintainers.js";
Expand All @@ -22,11 +26,35 @@ const kFlagsToWatch = new Set([
"hasScript"
]);

const kEmojiDescription = {
"📦": "scripts",
"⚔️": "sensitive files",
"🚨": "vulnerabilities",
"⛔️": "deprecated"
const kEmojiMetadata = {
"📦": {
description: "scripts",
menu: {
name: "dependencies",
priority: 3
}
},
"⚔️": {
description: "sensitive files",
menu: {
name: "files",
priority: 1
}
},
"🚨": {
description: "vulnerabilities",
menu: {
name: "vulnerabilities",
priority: 2
}
},
"⛔️": {
description: "deprecated",
menu: {
name: "info",
priority: 0
}
}
};

export class HomeView {
Expand Down Expand Up @@ -207,10 +235,16 @@ export class HomeView {
for (let id = 0; id < deps.length; id++) {
const dependency = deps[id];

const element = this.renderPackage(dependency);
const [element, menuToOpen] = this.renderPackage(dependency);
element.addEventListener("click", () => {
window.navigation.setNavByName("network--view");
setTimeout(() => this.nsn.focusNodeByNameAndVersion(dependency.name, dependency.version), 25);
setTimeout(() => {
PackageInfo.ForcedPackageMenu = menuToOpen;
this.nsn.focusNodeByNameAndVersion(
dependency.name,
dependency.version
);
}, 25);
});
if (hideItems && id >= maxPackages) {
element.classList.add("hidden");
Expand Down Expand Up @@ -238,13 +272,30 @@ export class HomeView {

renderPackage(dependencyVer) {
const { name, version, flags, deprecated } = dependencyVer;

const menuToOpen = {
name: "info",
priority: 0
};
const inlinedEmojis = getFlagsEmojisInlined(
flags.filter((name) => kFlagsToWatch.has(name)),
new Set(window.settings.config.ignore.flags)
);

const childs = utils.extractEmojis(inlinedEmojis)
.map((emoji) => utils.createDOMElement("p", { text: `${emoji} ${kEmojiDescription[emoji]}` }));
const childs = [];
for (const emoji of utils.extractEmojis(inlinedEmojis)) {
const { menu, description } = kEmojiMetadata[emoji];
if (menu.priority > menuToOpen.priority) {
menuToOpen.name = menu.name;
menuToOpen.priority = menu.priority;
}

childs.push(
utils.createDOMElement("p", {
text: `${emoji} ${description}`
})
);
}

const packageContents = [
utils.createDOMElement("div", {
Expand All @@ -267,9 +318,12 @@ export class HomeView {
packageContents.push(utils.createDOMElement("p", { text: deprecated }));
}

return utils.createDOMElement("div", {
childs: packageContents
});
return [
utils.createDOMElement("div", {
childs: packageContents
}),
menuToOpen.name
];
}

generateWarnings() {
Expand Down