Skip to content

Commit 28f7606

Browse files
feat: search packages with websocket (#434)
* feat: search packages with websocket * refactor: enhance searchnav styles * chore: finalize style * feat: add hint for min & max package length * chore: enhance search view css * fix: use dataset to work with package name * refactor: hide network searchbar when not required * chore: improve logs * fix: use template to render home view * refactor: enhance initSearchBar * fix: bug with searchbar display: none * fix(css): remove overflow-x: auto on .packages * chore: improve package close button css * chore: add i18n for searchbar placeholder * feat(search): allow to remove packages from cache * fix: make new current package active on reload * feat(search): add spinner while searching packages * feat(search): add spinner while searching package versions * feat(search): move search spinner into input * fix: init on reload when removed last active package only * refactor: split interface init function * feat: highlight exact match package * feat: close package info when switching network * fix: network searchbar --------- Co-authored-by: fraxken <[email protected]>
1 parent 016ba9a commit 28f7606

File tree

34 files changed

+1742
-360
lines changed

34 files changed

+1742
-360
lines changed

eslint.config.mjs

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,24 @@
1-
// Import Node.js Dependencies
2-
import path from "node:path";
3-
import { fileURLToPath } from "node:url";
1+
import { ESLintConfig, globals } from "@openally/config.eslint";
42

5-
// Import Third-party Dependencies
6-
import { FlatCompat } from "@eslint/eslintrc";
7-
8-
const __filename = fileURLToPath(import.meta.url);
9-
const __dirname = path.dirname(__filename);
10-
11-
const compat = new FlatCompat({
12-
baseDirectory: __dirname
13-
});
14-
15-
export default [{
16-
ignores: ["**/node_modules/", "**/tmp/", "**/dist/", "**/coverage/", "**/fixtures/"]
17-
}, ...compat.extends("@nodesecure/eslint-config"), {
18-
languageOptions: {
19-
sourceType: "module",
20-
21-
parserOptions: {
22-
requireConfigFile: false
3+
export default [
4+
...ESLintConfig,
5+
{
6+
rules: {
7+
"func-style": "off",
8+
"no-invalid-this": "off",
9+
"no-inner-declarations": "off",
10+
"no-case-declarations": "off",
11+
// TODO: enable this rule when migrating to @topcli/cmder
12+
"default-param-last": "off"
13+
},
14+
languageOptions: {
15+
sourceType: "module",
16+
globals: {
17+
...globals.browser
18+
}
2319
}
2420
},
25-
26-
rules: {
27-
"func-style": "off",
28-
"no-invalid-this": "off",
29-
"no-inner-declarations": "off",
30-
"no-case-declarations": "off"
21+
{
22+
ignores: ["**/node_modules/", "**/tmp/", "**/dist/", "**/coverage/", "**/fixtures/"]
3123
}
32-
}];
24+
];

i18n/english.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/* eslint-disable max-len */
1+
/* eslint-disable @stylistic/max-len */
2+
23
// Import Third-party Dependencies
34
import { taggedString as tS } from "@nodesecure/i18n";
45

@@ -188,7 +189,11 @@ const ui = {
188189
"Node.js core modules": "Node.js core modules",
189190
"Available licenses": "Available licenses",
190191
"Available flags": "Available flags",
191-
default: "Search options"
192+
default: "Search options",
193+
packagesCache: "Packages available in the cache",
194+
noPackageFound: "No package found",
195+
packageLengthErr: "Package name must be between 2 and 64 characters.",
196+
registryPlaceholder: "Search packages"
192197
},
193198
legend: {
194199
default: "The package is fine.",

i18n/french.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/* eslint-disable max-len */
1+
/* eslint-disable @stylistic/max-len */
2+
23
// Import Third-party Dependencies
34
import { taggedString as tS } from "@nodesecure/i18n";
45

@@ -188,7 +189,11 @@ const ui = {
188189
"Node.js core modules": "Modules de base de Node.js",
189190
"Available licenses": "Licences disponibles",
190191
"Available flags": "Drapeaux disponibles",
191-
default: "Options de recherche"
192+
default: "Options de recherche",
193+
packagesCache: "Packages disponibles dans le cache",
194+
noPackageFound: "Aucun package trouvé",
195+
packageLengthErr: "Le nom du package doit être compris entre 2 et 64 caractères.",
196+
registryPlaceholder: "Recherche de packages"
192197
},
193198
legend: {
194199
default: "Rien à signaler.",

package.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
"node": ">=18"
1313
},
1414
"scripts": {
15-
"eslint": "eslint bin src test workspaces",
16-
"eslint-fix": "npm run eslint -- --fix",
15+
"lint": "eslint bin src test workspaces",
16+
"lint-fix": "npm run lint -- --fix",
1717
"prepublishOnly": "rimraf ./dist && npm run build && pkg-ok",
1818
"build": "node ./esbuild.config.js",
19-
"test": "npm run test-only && npm run eslint",
20-
"test-only": "glob -c \"node --loader=esmock --no-warnings --test\" \"test/**/*.test.js\"",
21-
"coverage": "c8 --reporter=lcov npm run test"
19+
"test": "npm run test-only && npm run lint",
20+
"test-only": "glob -c \"node --loader=esmock --no-warnings --test-concurrency 1 --test\" \"test/**/*.test.js\"",
21+
"coverage": "c8 --reporter=lcov npm run test",
22+
"clear:cache": "node ./scripts/clear-cache.js"
2223
},
2324
"files": [
2425
"bin",
@@ -62,14 +63,13 @@
6263
"homepage": "https://github.com/NodeSecure/cli#readme",
6364
"devDependencies": {
6465
"@myunisoft/httpie": "^5.0.0",
65-
"@nodesecure/eslint-config": "2.0.0-beta.0",
6666
"@nodesecure/size-satisfies": "^1.1.0",
6767
"@nodesecure/vis-network": "^1.4.0",
68+
"@openally/config.eslint": "^1.1.0",
6869
"@types/node": "^22.2.0",
6970
"c8": "^10.1.2",
7071
"cross-env": "^7.0.3",
7172
"esbuild": "^0.23.0",
72-
"eslint": "^9.8.0",
7373
"esmock": "^2.6.7",
7474
"glob": "^11.0.0",
7575
"http-server": "^14.1.1",
@@ -104,10 +104,13 @@
104104
"kleur": "^4.1.5",
105105
"ms": "^2.1.3",
106106
"open": "^10.1.0",
107+
"pino": "^9.3.2",
108+
"pino-pretty": "^11.2.2",
107109
"polka": "^0.5.2",
108110
"sade": "^1.8.1",
109111
"semver": "^7.6.3",
110112
"sirv": "^2.0.4",
113+
"ws": "^8.18.0",
111114
"zup": "0.0.2"
112115
}
113116
}

public/common/utils.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,15 @@ export function currentLang() {
250250

251251
return detectedLang in window.i18n ? detectedLang : "english";
252252
}
253+
254+
export function debounce(callback, delay) {
255+
let timer;
256+
257+
// eslint-disable-next-line func-names
258+
return function() {
259+
clearTimeout(timer);
260+
timer = setTimeout(() => {
261+
callback();
262+
}, delay);
263+
};
264+
}
Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
nav {
1+
nav#aside {
22
width: 70px;
33
flex-shrink: 0;
44
background: var(--primary);
@@ -8,60 +8,66 @@ nav {
88
flex-direction: column;
99
z-index: 40;
1010
}
11-
nav > .nsecure-logo {
12-
margin-top: 20px;
13-
}
1411

15-
nav > ul {
16-
width: inherit;
17-
display: flex;
18-
margin-top: 10px;
19-
flex-direction: column;
20-
flex-grow: 1;
21-
margin-bottom: 20px;
22-
}
12+
nav#aside>.nsecure-logo {
13+
margin-top: 20px;
14+
}
2315

24-
nav > ul li {
25-
height: 70px;
26-
display: flex;
27-
position: relative;
28-
justify-content: center;
29-
align-items: center;
30-
}
31-
nav > ul li+li {
32-
margin-top: 10px;
33-
}
16+
nav#aside>ul {
17+
width: inherit;
18+
display: flex;
19+
margin-top: 10px;
20+
flex-direction: column;
21+
flex-grow: 1;
22+
margin-bottom: 20px;
23+
}
3424

35-
nav > ul li:not(.active):hover {
36-
cursor: pointer;
37-
background: rgba(50, 200, 255, 0.085);
38-
}
25+
nav#aside>ul li {
26+
height: 70px;
27+
display: flex;
28+
position: relative;
29+
justify-content: center;
30+
align-items: center;
31+
}
32+
33+
nav#aside>ul li+li {
34+
margin-top: 10px;
35+
}
3936

40-
nav > ul li.active:before {
41-
background: var(--secondary);
42-
position: absolute;
43-
left: 0;
44-
top: 17.5px;
45-
height: 35px;
46-
width: 4px;
47-
border-radius: 0 4px 4px 0;
48-
content: "";
49-
}
37+
nav#aside>ul li:not(.active):hover {
38+
cursor: pointer;
39+
background: rgba(50, 200, 255, 0.085);
40+
}
41+
42+
nav#aside>ul li.active:before {
43+
background: var(--secondary);
44+
position: absolute;
45+
left: 0;
46+
top: 17.5px;
47+
height: 35px;
48+
width: 4px;
49+
border-radius: 0 4px 4px 0;
50+
content: "";
51+
}
52+
53+
nav#aside>ul li>i {
54+
font-size: 24px;
55+
}
56+
57+
nav#aside>ul li.active,
58+
nav#aside>ul li.active span {
59+
color: var(--secondary);
60+
}
61+
62+
nav#aside>ul li>span {
63+
position: absolute;
64+
left: 10px;
65+
bottom: 5px;
66+
font-size: 12px;
67+
color: #FFF;
68+
font-weight: bold;
69+
}
5070

51-
nav > ul li > i {
52-
font-size: 24px;
53-
}
54-
nav > ul li.active, nav > ul li.active span {
55-
color: var(--secondary);
56-
}
57-
nav > ul li > span {
58-
position: absolute;
59-
left: 10px;
60-
bottom: 5px;
61-
font-size: 12px;
62-
color: #FFF;
63-
font-weight: bold;
64-
}
65-
.bottom-nav {
71+
nav#aside>ul li.bottom-nav {
6672
margin-top: auto;
6773
}

public/components/navigation/navigation.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { PackageInfo } from "../package/package.js";
55
const kAvailableView = new Set([
66
"network--view",
77
"home--view",
8+
"search--view",
89
"settings--view"
910
]);
1011

@@ -50,6 +51,10 @@ export class ViewNavigation {
5051
this.onNavigationSelected(this.menus.get("settings--view"));
5152
break;
5253
}
54+
case hotkeys.search: {
55+
this.onNavigationSelected(this.menus.get("search--view"));
56+
break;
57+
}
5358
}
5459
});
5560
}
@@ -68,6 +73,11 @@ export class ViewNavigation {
6873
selectedNav.classList.add("active");
6974
this.setAnchor(menuName);
7075

76+
const searchbar = document.getElementById("searchbar");
77+
if (searchbar) {
78+
searchbar.style.display = menuName === "network--view" ? "flex" : "none";
79+
}
80+
7181
this.activeMenu = selectedNav;
7282
}
7383

0 commit comments

Comments
 (0)