Skip to content

Commit ca946cc

Browse files
author
Raulo Erwan.
committed
feat: highlight packages
1 parent ed588fa commit ca946cc

20 files changed

Lines changed: 260 additions & 83 deletions

File tree

.changeset/little-light-bulb.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@nodesecure/vis-network": minor
3+
---
4+
5+
Visualize highlited packages with dashed yellow border
6+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ Type a package name directly to search, or prefix with a filter name followed by
151151
- `ext` — file extension present in the package (e.g. `.js`, `.ts`).
152152
- `builtin` — Node.js core module used by the package (e.g. `fs`, `path`).
153153
- `size` — size range (see [size-satisfies](https://github.com/NodeSecure/size-satisfies#usage-example), e.g. `>50kb`, `10kb..200kb`).
154+
- `highlighted` — all highlighted packages by default.
154155

155156
## FAQ
156157

i18n/arabic.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ const ui = {
243243
legend: {
244244
default: "الحزمة بخير.",
245245
warn: "الحزمة بها تحذيرات.",
246-
friendly: "الحزمة تتم صيانتها بواسطة نفس مؤلفي الحزمة الجذرية."
246+
friendly: "الحزمة تتم صيانتها بواسطة نفس مؤلفي الحزمة الجذرية.",
247+
highlighted: "الحزمة جزء من الحزم المميزة"
247248
},
248249
lockedNavigation: {
249250
next: "التالي",

i18n/english.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,15 @@ const ui = {
315315
author: "name or email",
316316
ext: "file extension",
317317
builtin: "node.js module",
318-
size: "e.g. >50kb"
318+
size: "e.g. >50kb",
319+
highlighted: "all"
319320
}
320321
},
321322
legend: {
322323
default: "The package is fine.",
323324
warn: "The package has warnings.",
324-
friendly: "The package is maintained by the same authors as the root package."
325+
friendly: "The package is maintained by the same authors as the root package.",
326+
highlighted: "The package is part of highlighted packages"
325327
},
326328
lockedNavigation: {
327329
next: "Next",

i18n/french.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,15 @@ const ui = {
315315
author: "nom ou email",
316316
ext: "extension de fichier",
317317
builtin: "module node.js",
318-
size: "ex. >50kb"
318+
size: "ex. >50kb",
319+
highlighted: "all"
319320
}
320321
},
321322
legend: {
322323
default: "Rien à signaler.",
323324
warn: "La dépendance contient des menaces.",
324-
friendly: "La dépendance est maintenu par des auteurs du package principal."
325+
friendly: "La dépendance est maintenu par des auteurs du package principal.",
326+
highlighted: "Le package fait partie des packages mis en évidence"
325327
},
326328
lockedNavigation: {
327329
next: "Suivant",

i18n/turkish.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ const ui = {
245245
legend: {
246246
default: "Paket sorunsuz.",
247247
warn: "Pakette uyarılar var.",
248-
friendly: "Paket, kök paketin yazarlarıyla aynı kişiler tarafından bakılmaktadır."
248+
friendly: "Paket, kök paketin yazarlarıyla aynı kişiler tarafından bakılmaktadır.",
249+
highlighted: "Paket, vurgulanan paketlerin bir parçasıdır"
249250
},
250251
lockedNavigation: {
251252
next: "Sonraki",

public/components/command-palette/command-palette.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
FILTER_HAS_HELPERS,
1212
FILTER_MULTI_SELECT,
1313
PRESETS,
14+
FILTER_INSTANT_CONFIRM,
1415
computeMatches,
1516
getHelperValues
1617
} from "./filters.js";
@@ -94,12 +95,13 @@ class CommandPalette extends LitElement {
9495
#init = ({ detail: { linker, packages, network } }) => {
9596
this.#linker = linker;
9697
this.#network = network;
97-
this.#packages = packages.map(({ id, name, version, flags }) => {
98+
this.#packages = packages.map(({ id, name, version, flags, isHighlighted }) => {
9899
return {
99100
id: String(id),
100101
name,
101102
version,
102-
flags
103+
flags,
104+
isHighlighted
103105
};
104106
});
105107
};
@@ -323,10 +325,15 @@ class CommandPalette extends LitElement {
323325

324326
#selectHelper(helper) {
325327
if (helper.type === "filter") {
326-
this.inputValue = `${helper.value}:`;
327-
this.activeFilter = helper.value;
328-
this.selectedIndex = -1;
329-
this.results = [];
328+
if (FILTER_INSTANT_CONFIRM.has(helper.value)) {
329+
this.#addQuery(helper.value, "all");
330+
}
331+
else {
332+
this.inputValue = `${helper.value}:`;
333+
this.activeFilter = helper.value;
334+
this.selectedIndex = -1;
335+
this.results = [];
336+
}
330337
}
331338
else {
332339
this.#addQuery(this.activeFilter, helper.value);

public/components/command-palette/filters.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const VERSION_PRESETS = [
2020
{ label: "≥ 1.0", value: ">=1.0.0" },
2121
{ label: "< 1.0", value: "<1.0.0" }
2222
];
23-
export const FILTERS_NAME = new Set(["package", "version", "flag", "license", "author", "ext", "builtin", "size"]);
23+
export const FILTERS_NAME = new Set(["package", "version", "flag", "license", "author", "ext", "builtin", "size", "highlighted"]);
2424
export const PRESETS = [
2525
{ id: "has_vulnerabilities", filter: "flag", value: "hasVulnerabilities" },
2626
{ id: "has_scripts", filter: "flag", value: "hasScript" },
@@ -32,6 +32,8 @@ export const PRESETS = [
3232
export const FILTER_HAS_HELPERS = new Set(["license", "ext", "builtin", "author"]);
3333
// Filters where the mode persists after selection (multi-select)
3434
export const FILTER_MULTI_SELECT = new Set(["flag"]);
35+
// Filters that auto-confirm immediately on selection (no text input needed)
36+
export const FILTER_INSTANT_CONFIRM = new Set(["highlighted"]);
3537

3638
/**
3739
* Returns per-flag package counts across the full linker.
@@ -243,6 +245,8 @@ function matchesFilter(opt, filterName, inputValue) {
243245
}
244246
case "flag":
245247
return opt.flags.includes(inputValue);
248+
case "highlighted":
249+
return inputValue === "all" ? opt.isHighlighted === true : opt.isHighlighted !== true;
246250
default:
247251
return false;
248252
}

public/components/legend/legend.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class Legend extends LitElement {
9090
${this.#createLegendBoxElement(colors.WARN, legend.warn)}
9191
${this.#createLegendBoxElement(colors.FRIENDLY, legend.friendly)}
9292
${this.#createLegendBoxElement(colors.DEFAULT, legend.default)}
93+
${this.#createLegendBoxElement(colors.HIGHLIGHTED, legend.highlighted)}
9394
</div>
9495
`;
9596
}
@@ -98,7 +99,7 @@ class Legend extends LitElement {
9899
theme,
99100
text
100101
) {
101-
const style = `background-color: ${theme.color}; color: ${theme.font.color};`;
102+
const style = `background-color: ${theme.color}; color: ${(theme.font ?? COLORS.LIGHT.DEFAULT.font).color};`;
102103

103104
return html`
104105
<div class="legend-box" style=${style}>

public/components/views/home/maintainers/maintainers.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ width: 16px;
238238
const { packages, email, url = null, npmAvatar } = data;
239239
const personClasses = {
240240
person: true,
241-
highlighted: this.secureDataSet.isHighlighted(data)
241+
highlighted: this.secureDataSet.isHighlightedContact(data)
242242
};
243243
244244
return html`
@@ -289,9 +289,9 @@ width: 16px;
289289

290290
#highlightContacts(authors) {
291291
const highlightedAuthors = authors
292-
.filter(([_, contact]) => this.secureDataSet.isHighlighted(contact));
292+
.filter(([_, contact]) => this.secureDataSet.isHighlightedContact(contact));
293293

294-
const authorsRest = authors.filter(([_, contact]) => !this.secureDataSet.isHighlighted(contact));
294+
const authorsRest = authors.filter(([_, contact]) => !this.secureDataSet.isHighlightedContact(contact));
295295

296296
return [...highlightedAuthors, ...authorsRest];
297297
}

0 commit comments

Comments
 (0)