From 0aed36c8d9e44a18fc9f3377bace30f48f73274c 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 --- com/templates/com/screen_slideshow.jinja | 2 +- core/static/bundled/alpine-index.ts | 21 -------- core/static/bundled/base-bundle-index.ts | 53 +++++++++++++++++++ .../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 + 9 files changed, 77 insertions(+), 47 deletions(-) delete mode 100644 core/static/bundled/alpine-index.ts 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/com/templates/com/screen_slideshow.jinja b/com/templates/com/screen_slideshow.jinja index 4a928cc4..0cd7449c 100644 --- a/com/templates/com/screen_slideshow.jinja +++ b/com/templates/com/screen_slideshow.jinja @@ -4,7 +4,7 @@ {% trans %}Slideshow{% endtrans %} - + { - $notifications: NotificationPlugin; - } -} - -Alpine.plugin([sort, limitedChoices, notifications]); -// biome-ignore lint/style/useNamingConvention: it's how it's named -Object.assign(window, { 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..810378d8 --- /dev/null +++ b/core/static/bundled/base-bundle-index.ts @@ -0,0 +1,53 @@ +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 { expireOldStorage } from "#core:core/cache"; +import { default as navbar } from "#core:core/navbar"; +import { type NotificationPlugin, notificationsPlugin as notifications, } from "#core:utils/notifications"; + +/** + * Alpine + */ +declare module "alpinejs" { + interface Magics { + $notifications: NotificationPlugin; + } +} + +Alpine.plugin([sort, limitedChoices, notifications]); +// 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(); + +/** + * Script that clears the cache when the cache version changes + */ +expireOldStorage(); 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 577546be..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 8dd3583c..8778d436 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44,6 +44,7 @@ "@biomejs/biome": "^2.4.15", "@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", @@ -2499,6 +2500,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 16604f0b..52faf51b 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "@biomejs/biome": "^2.4.15", "@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",