@symfony/ux-notify 2.23.0
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.
- package/LICENSE +19 -0
- package/README.md +14 -0
- package/dist/controller.d.ts +18 -0
- package/dist/controller.js +69 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2020-present Fabien Potencier
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is furnished
|
|
8
|
+
to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# @symfony/ux-notify
|
|
2
|
+
|
|
3
|
+
Native notification integration for Symfony using Mercure.
|
|
4
|
+
|
|
5
|
+
**ℹ️ Direct installation of this package is for advanced users only.** We strongly recommend installing it through the PHP package [symfony/ux-notify](https://packagist.org/packages/symfony/ux-notify) in a Symfony application with Flex enabled.
|
|
6
|
+
|
|
7
|
+
If you still want to install this package directly, **make sure its version exactly matches [symfony/ux-notify](https://packagist.org/packages/symfony/ux-notify) PHP package version.**
|
|
8
|
+
|
|
9
|
+
## Resources
|
|
10
|
+
|
|
11
|
+
- [Documentation](https://symfony.com/bundles/ux-notify/current/index.html)
|
|
12
|
+
- [Report issues](https://github.com/symfony/ux/issues) and
|
|
13
|
+
[send Pull Requests](https://github.com/symfony/ux/pulls)
|
|
14
|
+
in the [main Symfony UX repository](https://github.com/symfony/ux)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
|
2
|
+
export default class extends Controller {
|
|
3
|
+
static values: {
|
|
4
|
+
hub: StringConstructor;
|
|
5
|
+
topics: ArrayConstructor;
|
|
6
|
+
};
|
|
7
|
+
hubValue: string;
|
|
8
|
+
topicsValue: Array<string>;
|
|
9
|
+
readonly hasHubValue: boolean;
|
|
10
|
+
readonly hasTopicsValue: boolean;
|
|
11
|
+
eventSources: Array<EventSource>;
|
|
12
|
+
listeners: WeakMap<EventSource, (event: MessageEvent) => void>;
|
|
13
|
+
initialize(): void;
|
|
14
|
+
connect(): void;
|
|
15
|
+
disconnect(): void;
|
|
16
|
+
_notify(content: string | undefined): void;
|
|
17
|
+
private dispatchEvent;
|
|
18
|
+
}
|
|
@@ -0,0 +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();
|
|
8
|
+
}
|
|
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
|
+
});
|
|
22
|
+
}
|
|
23
|
+
connect() {
|
|
24
|
+
if (!('Notification' in window)) {
|
|
25
|
+
console.warn('This browser does not support desktop notifications.');
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
this.eventSources.forEach((eventSource) => {
|
|
29
|
+
const listener = (event) => this._notify(JSON.parse(event.data).summary);
|
|
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(content) {
|
|
46
|
+
if (!content)
|
|
47
|
+
return;
|
|
48
|
+
if ('granted' === Notification.permission) {
|
|
49
|
+
new Notification(content);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if ('denied' !== Notification.permission) {
|
|
53
|
+
Notification.requestPermission().then((permission) => {
|
|
54
|
+
if ('granted' === permission) {
|
|
55
|
+
new Notification(content);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
dispatchEvent(name, payload) {
|
|
61
|
+
this.dispatch(name, { detail: payload, prefix: 'notify' });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
default_1.values = {
|
|
65
|
+
hub: String,
|
|
66
|
+
topics: Array,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export { default_1 as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@symfony/ux-notify",
|
|
3
|
+
"description": "Native notification integration for Symfony using Mercure",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"version": "2.23.0",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"symfony-ux"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://ux.symfony.com/notify",
|
|
10
|
+
"repository": "https://github.com/symfony/ux-notify",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"main": "dist/controller.js",
|
|
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
|
+
"symfony": {
|
|
25
|
+
"controllers": {
|
|
26
|
+
"notify": {
|
|
27
|
+
"main": "dist/controller.js",
|
|
28
|
+
"webpackMode": "eager",
|
|
29
|
+
"fetch": "eager",
|
|
30
|
+
"enabled": true
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"importmap": {
|
|
34
|
+
"@hotwired/stimulus": "^3.0.0"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@hotwired/stimulus": "^3.0.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@hotwired/stimulus": "^3.0.0"
|
|
42
|
+
}
|
|
43
|
+
}
|