Skip to content

Commit 5114f21

Browse files
committed
Changes browser targets and simplfy notification responses, reduces external dependencies.
- Fixes: Apexcharts no longer supports functions as color. - Changed: nut-notification's dismiss triggers can be defined within the special container class. Component itself automatically attaches to clickable DOM elements for dismiss action. - Changed: Bumps all dependencies to the latest. - Changed: Updates target browser versions based on 2023 usage reports. - Changed: Inlined NUT parser functions. (-O flag most likely inline them anyway.) - Removed: Unique id generation for notifications elements.
1 parent 38aba37 commit 5114f21

File tree

16 files changed

+3355
-2288
lines changed

16 files changed

+3355
-2288
lines changed

client/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88
"version": "0.4.0",
99
"description": "Bundles all client side web components and dependencies.",
1010
"scripts": {
11-
"dev-js": "esbuild ./src/index.js --bundle --outdir=./dist/debug --target=firefox98,chrome86,safari15 --format=iife --watch=forever",
11+
"dev-js": "esbuild ./src/index.js --bundle --outdir=./dist/debug --target=firefox109,chrome108,safari15 --format=iife --watch=forever",
1212
"dev-css": "tailwindcss -i ./src/style.css -o ./dist/debug/style.css --minify --watch",
1313
"build": "node ./scripts/build.js --outdir=./dist/release"
1414
},
1515
"keywords": [],
1616
"author": "Timur Olur",
1717
"devDependencies": {
18-
"daisyui": "^4.12.13",
18+
"daisyui": "^4.12.14",
1919
"esbuild": "^0.24.0",
20-
"tailwindcss": "^3.4.13",
21-
"typescript": "^5.6.3"
20+
"tailwindcss": "^3.4.15",
21+
"typescript": "^5.7.2"
2222
},
2323
"dependencies": {
24-
"apexcharts": "3.53.0",
24+
"apexcharts": "3.54.1",
2525
"htmx.org": "^2.0.3",
2626
"idiomorph": "^0.3.0"
2727
}

client/pnpm-lock.yaml

+51-51
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/scripts/build.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ async function build(config) {
134134
entryPoints: ["./src/index.js"],
135135
format: "iife",
136136
minify: config.minify,
137-
target: ["firefox98", "chrome86", "safari15"],
137+
target: ["firefox109", "chrome108", "safari15"],
138138
treeShaking: true,
139139
outdir: config.outdir,
140140
});

client/src/components/charts/gauge.js

+23-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { link_host_styles } from "../../utils.js";
22
import ApexCharts from "apexcharts";
33

4+
/** @import {ApexOptions} from "apexcharts" */
5+
46
/**
57
* @typedef {"value" | "height" | "width" | "theme" | "class" } AttributeKeys
68
*/
@@ -11,8 +13,23 @@ export default class Gauge extends HTMLElement {
1113
/** @type {() => void} **/
1214
#theme_listener = () => {
1315
if (this.#chart) {
14-
// Re-renders chart to update svg fill colors when theme updated.
15-
this.#chart.updateOptions({}, false, false).catch(console.error);
16+
/** @type {ApexOptions} **/
17+
const new_options = {
18+
plotOptions: {
19+
radialBar: {
20+
dataLabels: {
21+
value: {
22+
color: [window.getComputedStyle(this).color],
23+
},
24+
},
25+
},
26+
},
27+
fill: {
28+
colors: [window.getComputedStyle(this).fill],
29+
},
30+
};
31+
32+
this.#chart.updateOptions(new_options, false, false).catch(console.error);
1633
}
1734
};
1835

@@ -36,6 +53,7 @@ export default class Gauge extends HTMLElement {
3653
let value_number = Number(value_text);
3754
value_number = isNaN(value_number) ? 0 : value_number;
3855

56+
/** @type {ApexOptions} **/
3957
const options = {
4058
series: [value_number],
4159
chart: {
@@ -67,14 +85,14 @@ export default class Gauge extends HTMLElement {
6785
value: {
6886
offsetY: -2,
6987
fontSize: "2.5rem",
70-
color: [() => window.getComputedStyle(this).color],
88+
color: [window.getComputedStyle(this).color],
7189
},
7290
},
7391
},
7492
},
7593
fill: {
7694
type: "solid",
77-
colors: [() => window.getComputedStyle(this).fill],
95+
colors: [window.getComputedStyle(this).fill],
7896
opacity: 0.5,
7997
},
8098
};
@@ -94,7 +112,7 @@ export default class Gauge extends HTMLElement {
94112
* @param {string} old_value
95113
* @param {string} new_value
96114
*/
97-
attributeChangedCallback(name, old_value, new_value) {
115+
attributeChangedCallback(name, _old_value, new_value) {
98116
if (!this.#chart) return;
99117

100118
switch (name) {

client/src/components/notification.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
/**
2-
* @typedef {"ttl" | "title" | "closeable" | "type"} AttributeKeys
3-
*/
1+
/** @typedef {"ttl" | "title" | "closeable" | "type"} AttributeKeys */
2+
3+
const TRIGGER_QUERY =
4+
".nut-notification-trigger button, .nut-notification-trigger a, .nut-notification-trigger [role=button]";
45

56
export default class NutNotification extends HTMLElement {
67
/** @type {number|undefined} */
@@ -15,6 +16,11 @@ export default class NutNotification extends HTMLElement {
1516
const ttl_attr = Number(this.getAttribute("ttl"));
1617
const type = this.getAttribute("type") ?? "info";
1718
const ttl = isNaN(ttl_attr) || ttl_attr < 1 ? 3000 : ttl_attr;
19+
const dismissElements = this.querySelectorAll(TRIGGER_QUERY);
20+
21+
for (const element of dismissElements) {
22+
element.addEventListener("click", () => this?.remove());
23+
}
1824

1925
this.className = `${this.className} alert alert-${type}`;
2026
this.#timer = setTimeout(() => {

0 commit comments

Comments
 (0)