@symfony/ux-chartjs 2.27.0 → 2.28.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import { Controller } from '@hotwired/stimulus';
2
- export default class extends Controller {
2
+
3
+ declare class export_default extends Controller {
3
4
  readonly viewValue: any;
4
5
  static values: {
5
6
  view: ObjectConstructor;
@@ -10,3 +11,5 @@ export default class extends Controller {
10
11
  viewValueChanged(): void;
11
12
  private dispatchEvent;
12
13
  }
14
+
15
+ export { export_default as default };
@@ -1,73 +1,77 @@
1
- import { Controller } from '@hotwired/stimulus';
2
- import { registerables, Chart } from 'chart.js';
3
-
1
+ // src/controller.ts
2
+ import { Controller } from "@hotwired/stimulus";
3
+ import { Chart, registerables } from "chart.js";
4
4
  if (registerables) {
5
- Chart.register(...registerables);
5
+ Chart.register(...registerables);
6
6
  }
7
- let isChartInitialized = false;
8
- class default_1 extends Controller {
9
- constructor() {
10
- super(...arguments);
11
- this.chart = null;
7
+ var isChartInitialized = false;
8
+ var controller_default = class extends Controller {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.chart = null;
12
+ }
13
+ connect() {
14
+ if (!isChartInitialized) {
15
+ isChartInitialized = true;
16
+ this.dispatchEvent("init", {
17
+ Chart
18
+ });
12
19
  }
13
- connect() {
14
- if (!isChartInitialized) {
15
- isChartInitialized = true;
16
- this.dispatchEvent('init', {
17
- Chart,
18
- });
19
- }
20
- if (!(this.element instanceof HTMLCanvasElement)) {
21
- throw new Error('Invalid element');
22
- }
23
- const payload = this.viewValue;
24
- if (Array.isArray(payload.options) && 0 === payload.options.length) {
25
- payload.options = {};
26
- }
27
- this.dispatchEvent('pre-connect', {
28
- options: payload.options,
29
- config: payload,
30
- });
31
- const canvasContext = this.element.getContext('2d');
32
- if (!canvasContext) {
33
- throw new Error('Could not getContext() from Element');
34
- }
35
- this.chart = new Chart(canvasContext, payload);
36
- this.dispatchEvent('connect', { chart: this.chart });
20
+ if (!(this.element instanceof HTMLCanvasElement)) {
21
+ throw new Error("Invalid element");
37
22
  }
38
- disconnect() {
39
- this.dispatchEvent('disconnect', { chart: this.chart });
40
- if (this.chart) {
41
- this.chart.destroy();
42
- this.chart = null;
43
- }
23
+ const payload = this.viewValue;
24
+ if (Array.isArray(payload.options) && 0 === payload.options.length) {
25
+ payload.options = {};
44
26
  }
45
- viewValueChanged() {
46
- if (this.chart) {
47
- const viewValue = { data: this.viewValue.data, options: this.viewValue.options };
48
- if (Array.isArray(viewValue.options) && 0 === viewValue.options.length) {
49
- viewValue.options = {};
50
- }
51
- this.dispatchEvent('view-value-change', viewValue);
52
- this.chart.data = viewValue.data;
53
- this.chart.options = viewValue.options;
54
- this.chart.update();
55
- const parentElement = this.element.parentElement;
56
- if (parentElement && this.chart.options.responsive) {
57
- const originalWidth = parentElement.style.width;
58
- parentElement.style.width = `${parentElement.offsetWidth + 1}px`;
59
- setTimeout(() => {
60
- parentElement.style.width = originalWidth;
61
- }, 0);
62
- }
63
- }
27
+ this.dispatchEvent("pre-connect", {
28
+ options: payload.options,
29
+ config: payload
30
+ });
31
+ const canvasContext = this.element.getContext("2d");
32
+ if (!canvasContext) {
33
+ throw new Error("Could not getContext() from Element");
64
34
  }
65
- dispatchEvent(name, payload) {
66
- this.dispatch(name, { detail: payload, prefix: 'chartjs' });
35
+ this.chart = new Chart(canvasContext, payload);
36
+ this.dispatchEvent("connect", { chart: this.chart });
37
+ }
38
+ disconnect() {
39
+ this.dispatchEvent("disconnect", { chart: this.chart });
40
+ if (this.chart) {
41
+ this.chart.destroy();
42
+ this.chart = null;
67
43
  }
68
- }
69
- default_1.values = {
70
- view: Object,
44
+ }
45
+ /**
46
+ * If the underlying data or options change, let's update the chart!
47
+ */
48
+ viewValueChanged() {
49
+ if (this.chart) {
50
+ const viewValue = { data: this.viewValue.data, options: this.viewValue.options };
51
+ if (Array.isArray(viewValue.options) && 0 === viewValue.options.length) {
52
+ viewValue.options = {};
53
+ }
54
+ this.dispatchEvent("view-value-change", viewValue);
55
+ this.chart.data = viewValue.data;
56
+ this.chart.options = viewValue.options;
57
+ this.chart.update();
58
+ const parentElement = this.element.parentElement;
59
+ if (parentElement && this.chart.options.responsive) {
60
+ const originalWidth = parentElement.style.width;
61
+ parentElement.style.width = `${parentElement.offsetWidth + 1}px`;
62
+ setTimeout(() => {
63
+ parentElement.style.width = originalWidth;
64
+ }, 0);
65
+ }
66
+ }
67
+ }
68
+ dispatchEvent(name, payload) {
69
+ this.dispatch(name, { detail: payload, prefix: "chartjs" });
70
+ }
71
+ };
72
+ controller_default.values = {
73
+ view: Object
74
+ };
75
+ export {
76
+ controller_default as default
71
77
  };
72
-
73
- export { default_1 as default };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@symfony/ux-chartjs",
3
3
  "description": "Chart.js integration for Symfony",
4
4
  "license": "MIT",
5
- "version": "2.27.0",
5
+ "version": "2.28.1",
6
6
  "keywords": [
7
7
  "symfony-ux"
8
8
  ],
@@ -14,13 +14,6 @@
14
14
  ],
15
15
  "main": "dist/controller.js",
16
16
  "types": "dist/controller.d.ts",
17
- "scripts": {
18
- "build": "node ../../../bin/build_package.js .",
19
- "watch": "node ../../../bin/build_package.js . --watch",
20
- "test": "../../../bin/test_package.sh .",
21
- "check": "biome check",
22
- "ci": "biome ci"
23
- },
24
17
  "symfony": {
25
18
  "controllers": {
26
19
  "chart": {
@@ -41,8 +34,23 @@
41
34
  },
42
35
  "devDependencies": {
43
36
  "@hotwired/stimulus": "^3.0.0",
37
+ "@testing-library/dom": "^10.4.0",
38
+ "@testing-library/jest-dom": "^6.6.3",
39
+ "@testing-library/user-event": "^14.6.1",
44
40
  "chart.js": "^3.4.1 || ^4.0",
41
+ "jsdom": "^26.1.0",
45
42
  "resize-observer-polyfill": "^1.5.1",
43
+ "tslib": "^2.8.1",
44
+ "tsx": "^4.20.3",
45
+ "typescript": "^5.8.3",
46
+ "vitest": "^3.2.4",
46
47
  "vitest-canvas-mock": "^0.3.3"
48
+ },
49
+ "scripts": {
50
+ "build": "tsx ../../../bin/build_package.ts .",
51
+ "watch": "tsx ../../../bin/build_package.ts . --watch",
52
+ "test": "../../../bin/test_package.sh .",
53
+ "check": "biome check",
54
+ "ci": "biome ci"
47
55
  }
48
56
  }