From 88ddae70426226b5ea64794e34aaf9f4b5cd982c Mon Sep 17 00:00:00 2001 From: imperosol Date: Mon, 11 May 2026 11:44:20 +0200 Subject: [PATCH] refactor: assemble main js files into a single bundle --- core/static/bundled/alpine-index.js | 12 ------ core/static/bundled/base-bundle-index.ts | 43 +++++++++++++++++++ .../core/{navbar-index.ts => navbar.ts} | 15 ++++--- core/static/bundled/country-flags-index.ts | 3 -- core/static/bundled/htmx-index.js | 11 ----- core/templates/core/base.jinja | 7 +-- package-lock.json | 11 +++++ package.json | 1 + 8 files changed, 66 insertions(+), 37 deletions(-) delete mode 100644 core/static/bundled/alpine-index.js create mode 100644 core/static/bundled/base-bundle-index.ts rename core/static/bundled/core/{navbar-index.ts => navbar.ts} (84%) delete mode 100644 core/static/bundled/country-flags-index.ts delete mode 100644 core/static/bundled/htmx-index.js diff --git a/core/static/bundled/alpine-index.js b/core/static/bundled/alpine-index.js deleted file mode 100644 index 9a4d7948..00000000 --- a/core/static/bundled/alpine-index.js +++ /dev/null @@ -1,12 +0,0 @@ -import sort from "@alpinejs/sort"; -import Alpine from "alpinejs"; -import { limitedChoices } from "#core:alpine/limited-choices.ts"; -import { alpinePlugin as notificationPlugin } from "#core:utils/notifications.ts"; - -Alpine.plugin([sort, limitedChoices]); -Alpine.magic("notifications", notificationPlugin); -window.Alpine = Alpine; - -window.addEventListener("DOMContentLoaded", () => { - Alpine.start(); -}); diff --git a/core/static/bundled/base-bundle-index.ts b/core/static/bundled/base-bundle-index.ts new file mode 100644 index 00000000..633fcd24 --- /dev/null +++ b/core/static/bundled/base-bundle-index.ts @@ -0,0 +1,43 @@ +import sort from "@alpinejs/sort"; +import Alpine from "alpinejs"; +import { polyfillCountryFlagEmojis } from "country-flag-emoji-polyfill"; +import htmx from "htmx.org"; +import { limitedChoices } from "#core:alpine/limited-choices"; +import { default as navbar } from "#core:core/navbar"; +import { alpinePlugin as notificationPlugin } from "#core:utils/notifications"; + +/** + * Alpine + */ +Alpine.plugin([sort, limitedChoices]); +Alpine.magic("notifications", notificationPlugin); + +// biome-ignore lint/style/useNamingConvention: it's how it's named +Object.assign(window, { Alpine }); + +window.addEventListener("DOMContentLoaded", () => { + Alpine.start(); +}); + +/** + * Polyfill for country flags (used for language choice) + */ +polyfillCountryFlagEmojis(); + +/** + * HTMX + */ +document.body.addEventListener("htmx:beforeRequest", (event: CustomEvent) => { + event.detail.target.ariaBusy = true; +}); + +document.body.addEventListener("htmx:beforeSwap", (event: CustomEvent) => { + event.detail.target.ariaBusy = null; +}); + +Object.assign(window, { htmx }); + +/** + * navbar + */ +navbar(); diff --git a/core/static/bundled/core/navbar-index.ts b/core/static/bundled/core/navbar.ts similarity index 84% rename from core/static/bundled/core/navbar-index.ts rename to core/static/bundled/core/navbar.ts index 18f7e3e3..9abc3aec 100644 --- a/core/static/bundled/core/navbar-index.ts +++ b/core/static/bundled/core/navbar.ts @@ -1,12 +1,10 @@ -import { exportToHtml } from "#core:utils/globals.ts"; - -exportToHtml("showMenu", () => { +function showMenu() { const navbar = document.getElementById("navbar-content"); const current = navbar.getAttribute("mobile-display"); navbar.setAttribute("mobile-display", current === "hidden" ? "revealed" : "hidden"); -}); +} -document.addEventListener("alpine:init", () => { +function navbarInit() { const menuItems = document.querySelectorAll(".navbar details[name='navbar'].menu"); const isDesktop = () => { return window.innerWidth >= 500; @@ -33,4 +31,9 @@ document.addEventListener("alpine:init", () => { } }); } -}); +} + +export default () => { + Object.assign(document, { showMenu }); + document.addEventListener("alpine:init", navbarInit); +}; diff --git a/core/static/bundled/country-flags-index.ts b/core/static/bundled/country-flags-index.ts deleted file mode 100644 index 1dc005c3..00000000 --- a/core/static/bundled/country-flags-index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { polyfillCountryFlagEmojis } from "country-flag-emoji-polyfill"; - -polyfillCountryFlagEmojis(); diff --git a/core/static/bundled/htmx-index.js b/core/static/bundled/htmx-index.js deleted file mode 100644 index 5880668d..00000000 --- a/core/static/bundled/htmx-index.js +++ /dev/null @@ -1,11 +0,0 @@ -import htmx from "htmx.org"; - -document.body.addEventListener("htmx:beforeRequest", (event) => { - event.detail.target.ariaBusy = true; -}); - -document.body.addEventListener("htmx:beforeSwap", (event) => { - event.detail.target.ariaBusy = null; -}); - -Object.assign(window, { htmx }); diff --git a/core/templates/core/base.jinja b/core/templates/core/base.jinja index 025dacdf..0d8a06fe 100644 --- a/core/templates/core/base.jinja +++ b/core/templates/core/base.jinja @@ -35,12 +35,9 @@ - + - - - - + {% block additional_css %}{% endblock %} {% block additional_js %}{% endblock %} diff --git a/package-lock.json b/package-lock.json index 649ebdbf..81cd022f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44,6 +44,7 @@ "@biomejs/biome": "^2.4.13", "@hey-api/openapi-ts": "^0.94.5", "@types/alpinejs": "^3.13.11", + "@types/alpinejs__sort": "^3.13.0", "@types/cytoscape-cxtmenu": "^3.4.5", "@types/cytoscape-klay": "^3.1.5", "@types/js-cookie": "^3.0.6", @@ -2481,6 +2482,16 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/alpinejs__sort": { + "version": "3.13.0", + "resolved": "https://registry.npmjs.org/@types/alpinejs__sort/-/alpinejs__sort-3.13.0.tgz", + "integrity": "sha512-iR9vEy6e3yXbYAK45/hpulzlt8SSKTsvYUl/t5nuWjtbJPoGxzxUUqOm3egp83Gqtf//TyJnDCI4OTebAKDRAA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/alpinejs": "*" + } + }, "node_modules/@types/codemirror": { "version": "5.60.17", "resolved": "https://registry.npmjs.org/@types/codemirror/-/codemirror-5.60.17.tgz", diff --git a/package.json b/package.json index 61ae7bfa..b4f6e4a6 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "@biomejs/biome": "^2.4.13", "@hey-api/openapi-ts": "^0.94.5", "@types/alpinejs": "^3.13.11", + "@types/alpinejs__sort": "^3.13.0", "@types/cytoscape-cxtmenu": "^3.4.5", "@types/cytoscape-klay": "^3.1.5", "@types/js-cookie": "^3.0.6",