@aria-framework/notify 0.3.1 → 0.4.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/README.md CHANGED
@@ -105,3 +105,29 @@ table and may add to it; nothing here reads a column it was not given.
105
105
 
106
106
  Wire `hub.closeAll()` into graceful shutdown. An SSE response is a request that never finishes,
107
107
  so `server.close()` otherwise waits for a drain that never comes.
108
+
109
+ ## The bell
110
+
111
+ `views/notify/bell.ejs` (markup), `assets/bell.js` (behaviour) and `assets/bell.css` (the unread
112
+ look) ship together. Mount `assetsDir` once (e.g. at `/js/notify`), include the view and load the
113
+ script; the view links the stylesheet itself (local `notifAssets`, default `/js/notify`).
114
+
115
+ Unread rows sit under **New** with a count, read rows under **Earlier**; the labels appear only
116
+ when both groups exist. Unread is a brand-colour tint, a left edge, a dot and full-strength text;
117
+ read rows fade. It is not `bg-light` + bold on purpose: an app that remaps `.bg-light` in dark
118
+ mode made the tint the dropdown's own colour, and the bold never reached the muted title.
119
+
120
+ An app's own notifications page uses the same classes, which every page with the bell already
121
+ has:
122
+
123
+ ```html
124
+ <div class="notif-section">New<span class="notif-section-count">3</span></div>
125
+ <a class="list-group-item notif-row is-unread" href="…">
126
+ <span class="notif-who">Warren</span> <span class="notif-what">replied on TBL-4821</span>
127
+ </a>
128
+ <div class="notif-section">Earlier</div>
129
+ <a class="list-group-item notif-row is-read" href="…">…</a>
130
+ ```
131
+
132
+ Colours come from @aria-framework/theme's tokens (`--brand-rgb`, `--text`, `--text-faint`), with
133
+ Bootstrap's variables as the fallback.
@@ -0,0 +1,69 @@
1
+ /* @aria-framework/notify — unread vs read, for the bell AND an app's own notifications page.
2
+ *
3
+ * Linked by views/notify/bell.ejs, so every page with the bell has these classes.
4
+ *
5
+ * Unread used to be Bootstrap's `bg-light fw-semibold`. In dark mode an app that remaps
6
+ * .bg-light to its page colour made the tint the dropdown's own colour (invisible), and on
7
+ * white #F8F9FA was barely there. The bold only reached the actor's name, because the title is
8
+ * muted. So unread now carries three cues: a tint and an edge built from the BRAND colour
9
+ * (visible on light and dark), a dot, and full-strength text. Read rows fade.
10
+ *
11
+ * Colours come from @aria-framework/theme's tokens, falling back to Bootstrap's own variables,
12
+ * so an app without the theme still gets a working look.
13
+ *
14
+ * .notif-row any row (bell item or list-group item)
15
+ * .notif-row.is-unread tint + edge + dot + strong text
16
+ * .notif-row.is-read faded text
17
+ * .notif-section the "New" / "Earlier" label; .notif-section-count is the pill on "New"
18
+ */
19
+ .notif-row{
20
+ position:relative;
21
+ padding-left:1.75rem !important;
22
+ white-space:normal;
23
+ }
24
+ .notif-row.is-unread{
25
+ background-color:rgba(var(--brand-rgb, var(--bs-primary-rgb)), .12);
26
+ box-shadow:inset 3px 0 0 var(--brand, var(--bs-primary));
27
+ }
28
+ .notif-row.is-unread:hover,
29
+ .notif-row.is-unread:focus{
30
+ background-color:rgba(var(--brand-rgb, var(--bs-primary-rgb)), .2);
31
+ }
32
+ .notif-row.is-unread::before{
33
+ content:"";
34
+ position:absolute;
35
+ left:.7rem;
36
+ top:1.05em;
37
+ width:8px;
38
+ height:8px;
39
+ border-radius:50%;
40
+ background:var(--brand, var(--bs-primary));
41
+ }
42
+ .notif-row.is-unread .notif-who,
43
+ .notif-row.is-unread .notif-what{
44
+ color:var(--text, var(--bs-body-color)) !important;
45
+ font-weight:600;
46
+ }
47
+ .notif-row.is-read .notif-who,
48
+ .notif-row.is-read .notif-what{
49
+ color:var(--text-faint, var(--bs-secondary-color)) !important;
50
+ font-weight:400;
51
+ }
52
+ .notif-section{
53
+ font-family:var(--font-mono, var(--bs-font-monospace));
54
+ font-size:.66rem;
55
+ letter-spacing:.08em;
56
+ text-transform:uppercase;
57
+ color:var(--text-faint, var(--bs-secondary-color));
58
+ padding:.5rem .9rem .25rem;
59
+ }
60
+ .notif-section-count{
61
+ display:inline-block;
62
+ margin-left:.4rem;
63
+ padding:0 .4rem;
64
+ border-radius:99px;
65
+ background:var(--bs-danger);
66
+ color:#fff;
67
+ font-family:var(--bs-body-font-family);
68
+ letter-spacing:0;
69
+ }
package/assets/bell.js CHANGED
@@ -74,18 +74,20 @@
74
74
  function row(item) {
75
75
  var a = document.createElement('a');
76
76
  a.href = safeHref(item.link);
77
- a.className = 'dropdown-item py-2 border-bottom' + (item.is_read ? '' : ' bg-light fw-semibold');
78
- a.style.whiteSpace = 'normal';
77
+ // Unread vs read is bell.css's (.notif-row.is-unread / .is-read), NOT bg-light + bold: an app
78
+ // that remaps .bg-light in dark mode made the tint the dropdown's own colour.
79
+ a.className = 'dropdown-item py-2 border-bottom notif-row ' + (item.is_read ? 'is-read' : 'is-unread');
79
80
 
80
81
  var top = document.createElement('div');
81
82
  top.className = 'small';
82
83
  if (item.actor_name) {
83
84
  var who = document.createElement('span');
85
+ who.className = 'notif-who';
84
86
  who.textContent = item.actor_name + ' ';
85
87
  top.appendChild(who);
86
88
  }
87
89
  var what = document.createElement('span');
88
- what.className = 'text-muted';
90
+ what.className = 'notif-what';
89
91
  what.textContent = item.title || '';
90
92
  top.appendChild(what);
91
93
  a.appendChild(top);
@@ -112,7 +114,28 @@
112
114
  list.appendChild(empty);
113
115
  return;
114
116
  }
115
- data.items.forEach(function (it) { list.appendChild(row(it)); });
117
+ // Unread under "New (n)", read under "Earlier". Labels only when both groups exist: one label
118
+ // over the whole list says nothing.
119
+ var fresh = data.items.filter(function (it) { return !it.is_read; });
120
+ var seen = data.items.filter(function (it) { return it.is_read; });
121
+ var both = fresh.length && seen.length;
122
+ if (fresh.length && (both || !seen.length)) list.appendChild(section('New', fresh.length));
123
+ fresh.forEach(function (it) { list.appendChild(row(it)); });
124
+ if (both) list.appendChild(section('Earlier'));
125
+ seen.forEach(function (it) { list.appendChild(row(it)); });
126
+ }
127
+
128
+ function section(label, count) {
129
+ var h = document.createElement('div');
130
+ h.className = 'notif-section';
131
+ h.textContent = label;
132
+ if (count) {
133
+ var pill = document.createElement('span');
134
+ pill.className = 'notif-section-count';
135
+ pill.textContent = count > 99 ? '99+' : String(count);
136
+ h.appendChild(pill);
137
+ }
138
+ return h;
116
139
  }
117
140
 
118
141
  function sync() {
package/package.json CHANGED
@@ -1,30 +1,31 @@
1
- {
2
- "name": "@aria-framework/notify",
3
- "version": "0.3.1",
4
- "description": "Aria App Framework — notify module. In-app notifications: ownership-scoped rows, a per-process SSE hub for live delivery, and a fire-and-forget emitter that needs no request and no actor, so a scheduler can raise one.",
5
- "license": "UNLICENSED",
6
- "private": false,
7
- "publishConfig": {
8
- "access": "public"
9
- },
10
- "main": "index.js",
11
- "files": [
12
- "index.js",
13
- "store.js",
14
- "hub.js",
15
- "emit.js",
16
- "assets/",
17
- "views/"
18
- ],
19
- "peerDependencies": {
20
- "better-sqlite3": ">=11"
21
- },
22
- "peerDependenciesMeta": {
23
- "better-sqlite3": {
24
- "optional": true
25
- }
26
- },
27
- "scripts": {
28
- "test": "node test/store.js && node test/schema-parity.js && node test/hub.js && node test/emit.js && node test/bell.js"
29
- }
30
- }
1
+ {
2
+ "name": "@aria-framework/notify",
3
+ "version": "0.4.0",
4
+ "description": "Aria App Framework \u2014 notify module. In-app notifications: ownership-scoped rows, a per-process SSE hub for live delivery, and a fire-and-forget emitter that needs no request and no actor, so a scheduler can raise one.",
5
+ "license": "UNLICENSED",
6
+ "private": false,
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "main": "index.js",
11
+ "files": [
12
+ "index.js",
13
+ "store.js",
14
+ "hub.js",
15
+ "emit.js",
16
+ "assets/",
17
+ "views/"
18
+ ],
19
+ "peerDependencies": {
20
+ "better-sqlite3": ">=11"
21
+ },
22
+ "peerDependenciesMeta": {
23
+ "better-sqlite3": {
24
+ "optional": true
25
+ }
26
+ },
27
+ "scripts": {
28
+ "test": "node test/store.js && node test/schema-parity.js && node test/hub.js && node test/emit.js && node test/bell.js",
29
+ "prepublishOnly": "node ../../test/packaging.js notify"
30
+ }
31
+ }
@@ -9,14 +9,18 @@
9
9
  notifQuiet comma list of SSE frame types that must NOT re-sync the bell (e.g. 'ticket,draft')
10
10
  notifUnread server-rendered initial unread count (keeps the badge honest before JS runs,
11
11
  and with JS off the bell stays a working link to the notifications page)
12
- notifWidth dropdown width (default '340px') %>
12
+ notifWidth dropdown width (default '340px')
13
+ notifAssets where assets/ is mounted (default '/js/notify'; bell.css is linked from it,
14
+ so the unread look ships with the markup and an app cannot forget it) %>
13
15
  <%
14
16
  var __base = (typeof notifBase === 'undefined') ? '/notifications' : notifBase;
15
17
  var __fill = (typeof notifFill === 'undefined') ? 'load' : notifFill;
16
18
  var __quiet = (typeof notifQuiet === 'undefined') ? '' : notifQuiet;
17
19
  var __unread = (typeof notifUnread === 'undefined') ? 0 : Number(notifUnread) || 0;
18
20
  var __width = (typeof notifWidth === 'undefined') ? '340px' : notifWidth;
21
+ var __assets = (typeof notifAssets === 'undefined') ? '/js/notify' : notifAssets;
19
22
  %>
23
+ <link rel="stylesheet" href="<%= __assets %>/bell.css">
20
24
  <div class="dropdown" id="notif-menu" data-notif-base="<%= __base %>" data-notif-fill="<%= __fill %>"<% if (__quiet) { %> data-notif-quiet="<%= __quiet %>"<% } %>>
21
25
  <a href="<%= __base %>" class="bell-btn" role="button"
22
26
  data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false" title="Notifications">