@symfony/ux-notify 2.27.0 → 2.28.2

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
  static values: {
4
5
  hub: StringConstructor;
5
6
  topics: ArrayConstructor;
@@ -16,3 +17,5 @@ export default class extends Controller {
16
17
  _notify(title: string | undefined, options: NotificationOptions | undefined): void;
17
18
  private dispatchEvent;
18
19
  }
20
+
21
+ export { export_default as default };
@@ -1,72 +1,69 @@
1
- import { Controller } from '@hotwired/stimulus';
2
-
3
- class default_1 extends Controller {
4
- constructor() {
5
- super(...arguments);
6
- this.eventSources = [];
7
- this.listeners = new WeakMap();
1
+ // src/controller.ts
2
+ import { Controller } from "@hotwired/stimulus";
3
+ var controller_default = class extends Controller {
4
+ constructor() {
5
+ super(...arguments);
6
+ this.eventSources = [];
7
+ this.listeners = /* @__PURE__ */ new WeakMap();
8
+ }
9
+ initialize() {
10
+ const errorMessages = [];
11
+ if (!this.hasHubValue) errorMessages.push('A "hub" value pointing to the Mercure hub must be provided.');
12
+ if (!this.hasTopicsValue) errorMessages.push('A "topics" value must be provided.');
13
+ if (errorMessages.length) throw new Error(errorMessages.join(" "));
14
+ this.eventSources = this.topicsValue.map((topic) => {
15
+ const u = new URL(this.hubValue);
16
+ u.searchParams.append("topic", topic);
17
+ return new EventSource(u);
18
+ });
19
+ }
20
+ connect() {
21
+ if (!("Notification" in window)) {
22
+ console.warn("This browser does not support desktop notifications.");
23
+ return;
8
24
  }
9
- initialize() {
10
- const errorMessages = [];
11
- if (!this.hasHubValue)
12
- errorMessages.push('A "hub" value pointing to the Mercure hub must be provided.');
13
- if (!this.hasTopicsValue)
14
- errorMessages.push('A "topics" value must be provided.');
15
- if (errorMessages.length)
16
- throw new Error(errorMessages.join(' '));
17
- this.eventSources = this.topicsValue.map((topic) => {
18
- const u = new URL(this.hubValue);
19
- u.searchParams.append('topic', topic);
20
- return new EventSource(u);
21
- });
25
+ this.eventSources.forEach((eventSource) => {
26
+ const listener = (event) => {
27
+ const { summary, content } = JSON.parse(event.data);
28
+ this._notify(summary, content);
29
+ };
30
+ eventSource.addEventListener("message", listener);
31
+ this.listeners.set(eventSource, listener);
32
+ });
33
+ this.dispatchEvent("connect", { eventSources: this.eventSources });
34
+ }
35
+ disconnect() {
36
+ this.eventSources.forEach((eventSource) => {
37
+ const listener = this.listeners.get(eventSource);
38
+ if (listener) {
39
+ eventSource.removeEventListener("message", listener);
40
+ }
41
+ eventSource.close();
42
+ });
43
+ this.eventSources = [];
44
+ }
45
+ _notify(title, options) {
46
+ if (!title) return;
47
+ if ("granted" === Notification.permission) {
48
+ new Notification(title, options);
49
+ return;
22
50
  }
23
- connect() {
24
- if (!('Notification' in window)) {
25
- console.warn('This browser does not support desktop notifications.');
26
- return;
51
+ if ("denied" !== Notification.permission) {
52
+ Notification.requestPermission().then((permission) => {
53
+ if ("granted" === permission) {
54
+ new Notification(title, options);
27
55
  }
28
- this.eventSources.forEach((eventSource) => {
29
- const listener = (event) => {
30
- const { summary, content } = JSON.parse(event.data);
31
- this._notify(summary, content);
32
- };
33
- eventSource.addEventListener('message', listener);
34
- this.listeners.set(eventSource, listener);
35
- });
36
- this.dispatchEvent('connect', { eventSources: this.eventSources });
56
+ });
37
57
  }
38
- disconnect() {
39
- this.eventSources.forEach((eventSource) => {
40
- const listener = this.listeners.get(eventSource);
41
- if (listener) {
42
- eventSource.removeEventListener('message', listener);
43
- }
44
- eventSource.close();
45
- });
46
- this.eventSources = [];
47
- }
48
- _notify(title, options) {
49
- if (!title)
50
- return;
51
- if ('granted' === Notification.permission) {
52
- new Notification(title, options);
53
- return;
54
- }
55
- if ('denied' !== Notification.permission) {
56
- Notification.requestPermission().then((permission) => {
57
- if ('granted' === permission) {
58
- new Notification(title, options);
59
- }
60
- });
61
- }
62
- }
63
- dispatchEvent(name, payload) {
64
- this.dispatch(name, { detail: payload, prefix: 'notify' });
65
- }
66
- }
67
- default_1.values = {
68
- hub: String,
69
- topics: Array,
58
+ }
59
+ dispatchEvent(name, payload) {
60
+ this.dispatch(name, { detail: payload, prefix: "notify" });
61
+ }
62
+ };
63
+ controller_default.values = {
64
+ hub: String,
65
+ topics: Array
66
+ };
67
+ export {
68
+ controller_default as default
70
69
  };
71
-
72
- export { default_1 as default };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@symfony/ux-notify",
3
3
  "description": "Native notification integration for Symfony using Mercure",
4
4
  "license": "MIT",
5
- "version": "2.27.0",
5
+ "version": "2.28.2",
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
  "notify": {
@@ -38,6 +31,21 @@
38
31
  "@hotwired/stimulus": "^3.0.0"
39
32
  },
40
33
  "devDependencies": {
41
- "@hotwired/stimulus": "^3.0.0"
34
+ "@hotwired/stimulus": "^3.0.0",
35
+ "@testing-library/dom": "^10.4.0",
36
+ "@testing-library/jest-dom": "^6.6.3",
37
+ "@testing-library/user-event": "^14.6.1",
38
+ "jsdom": "^26.1.0",
39
+ "tslib": "^2.8.1",
40
+ "tsx": "^4.20.3",
41
+ "typescript": "^5.8.3",
42
+ "vitest": "^3.2.4"
43
+ },
44
+ "scripts": {
45
+ "build": "tsx ../../../bin/build_package.ts .",
46
+ "watch": "tsx ../../../bin/build_package.ts . --watch",
47
+ "test": "../../../bin/test_package.sh .",
48
+ "check": "biome check",
49
+ "ci": "biome ci"
42
50
  }
43
51
  }