@enso-ui/notifications 3.2.9 → 3.2.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enso-ui/notifications",
3
- "version": "3.2.9",
3
+ "version": "3.2.11",
4
4
  "description": "Notification center pages and navbar widgets for Enso UI",
5
5
  "main": "src/bulma/pages/Index.vue",
6
6
  "repository": {
@@ -21,7 +21,6 @@
21
21
  "@fortawesome/fontawesome-svg-core": "^7.2.0",
22
22
  "@fortawesome/free-solid-svg-icons": "^7.2.0",
23
23
  "@fortawesome/vue-fontawesome": "3.1.3",
24
- "favico.js": "^0.3.10",
25
24
  "lodash": "^4.17.20"
26
25
  },
27
26
  "peerDependencies": {
@@ -18,7 +18,8 @@
18
18
  </figure>
19
19
  </template>
20
20
  <template #items>
21
- <dropdown-item v-for="position in positions"
21
+ <dropdown-item class="p-2"
22
+ v-for="position in positions"
22
23
  :key="position"
23
24
  :selected="toastrPosition === position"
24
25
  @select="update(position)">
@@ -50,24 +51,29 @@ export default {
50
51
 
51
52
  <style lang="scss">
52
53
  .toastr-position {
53
- .dropdown-trigger .button.input .image {
54
- margin: 0;
54
+ .dropdown-trigger .button.input {
55
+ position: relative;
55
56
  }
56
57
 
57
- .dropdown-trigger .button.input .image img,
58
- .dropdown-content .dropdown-item .image img {
59
- display: block;
60
- width: 0.95rem;
61
- height: 0.95rem;
62
- margin: auto;
63
- object-fit: contain;
58
+ .dropdown-trigger .button.input .dropdown-indicator {
59
+ top: 50%;
60
+ margin-top: -0.6rem;
64
61
  }
65
62
 
66
- .dropdown .dropdown-content {
67
- width: 4.6em;
63
+ .dropdown-menu {
64
+ .dropdown-content {
65
+ min-width: 3.3rem;
66
+ width: 100%;
68
67
 
69
- .items figure {
70
- margin: auto;
68
+ .dropdown-item {
69
+ display: flex;
70
+ align-items: center;
71
+ justify-content: center;
72
+ }
73
+
74
+ figure {
75
+ margin: 0;
76
+ }
71
77
  }
72
78
  }
73
79
  }
@@ -1,11 +1,11 @@
1
1
  <script>
2
2
  import { debounce } from 'lodash';
3
- import Favico from 'favico.js';
4
3
  import eventBus from '@enso-ui/ui/src/core/services/eventBus';
5
4
  import format from '@enso-ui/ui/src/modules/plugins/date-fns/format';
6
5
  import formatDistance from '@enso-ui/ui/src/modules/plugins/date-fns/formatDistance';
7
6
  import { app } from '@enso-ui/ui/src/pinia/app';
8
7
  import { websockets } from '@enso-ui/ui/src/pinia/websockets';
8
+ import FaviconBadge from '../../services/FaviconBadge';
9
9
 
10
10
  export default {
11
11
  name: 'Notifications',
@@ -24,7 +24,7 @@ export default {
24
24
  },
25
25
 
26
26
  data: v => ({
27
- favico: new Favico({ animation: v.favicoAnimation }),
27
+ favico: new FaviconBadge(),
28
28
  notifications: [],
29
29
  unread: 0,
30
30
  needsUpdate: true,
@@ -0,0 +1,105 @@
1
+ const favicon = () => {
2
+ const current = document.querySelector('link[rel~="icon"]');
3
+
4
+ if (current) {
5
+ return current;
6
+ }
7
+
8
+ const link = document.createElement('link');
9
+ link.rel = 'icon';
10
+ document.head.appendChild(link);
11
+
12
+ return link;
13
+ };
14
+
15
+ const label = value => (value > 99 ? '99+' : `${value}`);
16
+
17
+ const drawLabel = (context, value, size) => {
18
+ const radius = size * 0.34;
19
+ const center = size - radius;
20
+
21
+ context.fillStyle = '#d63638';
22
+ context.beginPath();
23
+ context.arc(center, center, radius, 0, Math.PI * 2);
24
+ context.fill();
25
+
26
+ context.fillStyle = '#fff';
27
+ context.font = `700 ${value > 99 ? size * 0.25 : size * 0.32}px sans-serif`;
28
+ context.textAlign = 'center';
29
+ context.textBaseline = 'middle';
30
+ context.fillText(label(value), center, center + 1);
31
+ };
32
+
33
+ export default class FaviconBadge {
34
+ constructor() {
35
+ this.link = typeof document === 'undefined' ? null : favicon();
36
+ this.originalHref = this.link?.href || null;
37
+ this.request = 0;
38
+ }
39
+
40
+ badge(value) {
41
+ if (!this.link) {
42
+ return;
43
+ }
44
+
45
+ const unread = Number(value) || 0;
46
+ this.request++;
47
+
48
+ if (!unread) {
49
+ if (this.originalHref) {
50
+ this.link.href = this.originalHref;
51
+ } else {
52
+ this.link.removeAttribute('href');
53
+ }
54
+
55
+ return;
56
+ }
57
+
58
+ this.draw(unread, this.request);
59
+ }
60
+
61
+ draw(value, request) {
62
+ if (!this.originalHref) {
63
+ this.updateFallback(value, request);
64
+
65
+ return;
66
+ }
67
+
68
+ const image = new Image();
69
+ image.crossOrigin = 'anonymous';
70
+ image.onload = () => this.updateWithImage(image, value, request);
71
+ image.onerror = () => this.updateFallback(value, request);
72
+ image.src = this.originalHref;
73
+ }
74
+
75
+ updateWithImage(image, value, request) {
76
+ if (request !== this.request) {
77
+ return;
78
+ }
79
+
80
+ const size = 32;
81
+ const canvas = document.createElement('canvas');
82
+ canvas.width = size;
83
+ canvas.height = size;
84
+ const context = canvas.getContext('2d');
85
+
86
+ context.drawImage(image, 0, 0, size, size);
87
+ drawLabel(context, value, size);
88
+ this.link.href = canvas.toDataURL('image/png');
89
+ }
90
+
91
+ updateFallback(value, request) {
92
+ if (request !== this.request) {
93
+ return;
94
+ }
95
+
96
+ const size = 32;
97
+ const canvas = document.createElement('canvas');
98
+ canvas.width = size;
99
+ canvas.height = size;
100
+ const context = canvas.getContext('2d');
101
+
102
+ drawLabel(context, value, size);
103
+ this.link.href = canvas.toDataURL('image/png');
104
+ }
105
+ }