@haatlabs-core/ui 0.19.0 → 0.22.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.
Files changed (88) hide show
  1. package/README.md +14 -3
  2. package/dist/client/LoginPage.d.ts +8 -2
  3. package/dist/client/LoginPage.js +24 -4
  4. package/dist/client/LoginPage.js.map +1 -1
  5. package/dist/client/UsagePage.d.ts +10 -1
  6. package/dist/client/UsagePage.js +44 -14
  7. package/dist/client/UsagePage.js.map +1 -1
  8. package/dist/client/index.d.ts +13 -1
  9. package/dist/client/index.js +11 -0
  10. package/dist/client/index.js.map +1 -1
  11. package/dist/client/sign-in-styles.d.ts +1 -1
  12. package/dist/client/sign-in-styles.js +6 -0
  13. package/dist/client/sign-in-styles.js.map +1 -1
  14. package/dist/client/usage-css.d.ts +1 -1
  15. package/dist/client/usage-css.js +5 -0
  16. package/dist/client/usage-css.js.map +1 -1
  17. package/dist/index.d.ts +9 -3
  18. package/dist/index.js +8 -3
  19. package/dist/index.js.map +1 -1
  20. package/dist/notifications/NotificationBell.d.ts +12 -0
  21. package/dist/notifications/NotificationBell.js +94 -0
  22. package/dist/notifications/NotificationBell.js.map +1 -0
  23. package/dist/notifications/NotificationInbox.d.ts +23 -0
  24. package/dist/notifications/NotificationInbox.js +92 -0
  25. package/dist/notifications/NotificationInbox.js.map +1 -0
  26. package/dist/notifications/NotificationPreferences.d.ts +10 -0
  27. package/dist/notifications/NotificationPreferences.js +135 -0
  28. package/dist/notifications/NotificationPreferences.js.map +1 -0
  29. package/dist/notifications/notifications-css.d.ts +6 -0
  30. package/dist/notifications/notifications-css.js +62 -0
  31. package/dist/notifications/notifications-css.js.map +1 -0
  32. package/dist/notifications/types.d.ts +80 -0
  33. package/dist/notifications/types.js +12 -0
  34. package/dist/notifications/types.js.map +1 -0
  35. package/dist/notifications/use-notification-stream.d.ts +15 -0
  36. package/dist/notifications/use-notification-stream.js +123 -0
  37. package/dist/notifications/use-notification-stream.js.map +1 -0
  38. package/dist/shell/Account.d.ts +24 -0
  39. package/dist/shell/Account.js +48 -0
  40. package/dist/shell/Account.js.map +1 -0
  41. package/dist/shell/AppShell.d.ts +13 -7
  42. package/dist/shell/AppShell.js +139 -65
  43. package/dist/shell/AppShell.js.map +1 -1
  44. package/dist/shell/BottomNav.d.ts +34 -0
  45. package/dist/shell/BottomNav.js +40 -0
  46. package/dist/shell/BottomNav.js.map +1 -0
  47. package/dist/shell/MoreSheet.d.ts +21 -0
  48. package/dist/shell/MoreSheet.js +46 -0
  49. package/dist/shell/MoreSheet.js.map +1 -0
  50. package/dist/shell/ShellSearch.d.ts +6 -2
  51. package/dist/shell/ShellSearch.js +3 -3
  52. package/dist/shell/ShellSearch.js.map +1 -1
  53. package/dist/shell/ShortcutsDialog.d.ts +11 -0
  54. package/dist/shell/ShortcutsDialog.js +26 -0
  55. package/dist/shell/ShortcutsDialog.js.map +1 -0
  56. package/dist/shell/bottom-nav-css.d.ts +6 -0
  57. package/dist/shell/bottom-nav-css.js +40 -0
  58. package/dist/shell/bottom-nav-css.js.map +1 -0
  59. package/dist/shell/breakpoint.d.ts +12 -0
  60. package/dist/shell/breakpoint.js +29 -0
  61. package/dist/shell/breakpoint.js.map +1 -0
  62. package/dist/shell/focus-trap.d.ts +9 -0
  63. package/dist/shell/focus-trap.js +35 -0
  64. package/dist/shell/focus-trap.js.map +1 -0
  65. package/dist/shell/icons.d.ts +23 -0
  66. package/dist/shell/icons.js +21 -0
  67. package/dist/shell/icons.js.map +1 -0
  68. package/dist/shell/nav.d.ts +22 -0
  69. package/dist/shell/nav.js +22 -0
  70. package/dist/shell/nav.js.map +1 -1
  71. package/dist/shell/shell-css.d.ts +1 -1
  72. package/dist/shell/shell-css.js +67 -16
  73. package/dist/shell/shell-css.js.map +1 -1
  74. package/dist/shell/shortcuts.d.ts +22 -0
  75. package/dist/shell/shortcuts.js +48 -0
  76. package/dist/shell/shortcuts.js.map +1 -0
  77. package/dist/shell/sidebar-state.d.ts +5 -0
  78. package/dist/shell/sidebar-state.js +38 -0
  79. package/dist/shell/sidebar-state.js.map +1 -0
  80. package/dist/theme/ThemeStyles.js +2 -1
  81. package/dist/theme/ThemeStyles.js.map +1 -1
  82. package/dist/theme/ThemeSwitch.d.ts +12 -2
  83. package/dist/theme/ThemeSwitch.js +19 -3
  84. package/dist/theme/ThemeSwitch.js.map +1 -1
  85. package/dist/theme/tokens.d.ts +7 -2
  86. package/dist/theme/tokens.js +24 -1
  87. package/dist/theme/tokens.js.map +1 -1
  88. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -3,13 +3,18 @@ export { EmptyState } from './EmptyState.js';
3
3
  export { FullScreen } from './FullScreen.js';
4
4
  export { Loading } from './Loading.js';
5
5
  export { SearchBox } from './SearchBox.js';
6
- export { ACCENTS, NEUTRALS, themeCss } from './theme/tokens.js';
6
+ export { ACCENTS, NEUTRALS, accentHover, themeCss } from './theme/tokens.js';
7
7
  export { ThemeStyles } from './theme/ThemeStyles.js';
8
8
  export { contrastRatio } from './theme/contrast.js';
9
9
  export { THEME_BOOT_SCRIPT, THEME_STORAGE_KEY, applyThemeChoice, readThemeChoice, useTheme, } from './theme/theme-choice.js';
10
- export { ThemeSwitch } from './theme/ThemeSwitch.js';
10
+ export { ThemeCycle, ThemeSwitch } from './theme/ThemeSwitch.js';
11
11
  export { AppShell } from './shell/AppShell.js';
12
- export { flattenNav } from './shell/nav.js';
12
+ export { bottomItems, flattenNav } from './shell/nav.js';
13
+ export { BottomNav, MobileNav } from './shell/BottomNav.js';
14
+ export { MoreSheet } from './shell/MoreSheet.js';
15
+ export { NAV_ICON_NAMES, NavIcon } from './shell/icons.js';
16
+ export { BOTTOM_NAV_CSS } from './shell/bottom-nav-css.js';
17
+ export { NARROW_BREAKPOINT, NARROW_QUERY, useNarrow } from './shell/breakpoint.js';
13
18
  export { ShellSearch } from './shell/ShellSearch.js';
14
19
  export { PageHeader } from './layout/PageHeader.js';
15
20
  export { Card } from './layout/Card.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEhE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,QAAQ,GACT,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,iBA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AM,wBAAwB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { ReactElement } from 'react';
2
+ import type { NotificationsClient } from './types.js';
3
+ /**
4
+ * The top bar's bell: the unread count, live, and a popover with the 10 newest, "Mark all
5
+ * read" and "See all". `onOpenItem` gets an item's link, only when it is an app path, and
6
+ * `inboxPath` for "See all".
7
+ */
8
+ export declare function NotificationBell(props: {
9
+ client: NotificationsClient;
10
+ onOpenItem: (link: string) => void;
11
+ inboxPath?: string;
12
+ }): ReactElement;
@@ -0,0 +1,94 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import { EmptyState } from '../EmptyState.js';
4
+ import { Loading } from '../Loading.js';
5
+ import { LoadError, NotificationRow, openNotification } from './NotificationInbox.js';
6
+ import { useNotificationStream } from './use-notification-stream.js';
7
+ /** How many items the popover shows. */
8
+ const NEWEST = 10;
9
+ const MAX_BADGE = 99;
10
+ const badgeText = (unread) => unread > MAX_BADGE ? `${String(MAX_BADGE)}+` : String(unread);
11
+ /**
12
+ * The top bar's bell: the unread count, live, and a popover with the 10 newest, "Mark all
13
+ * read" and "See all". `onOpenItem` gets an item's link, only when it is an app path, and
14
+ * `inboxPath` for "See all".
15
+ */
16
+ export function NotificationBell(props) {
17
+ const { client, onOpenItem, inboxPath = '/notifications' } = props;
18
+ const { unread, latest, setUnread } = useNotificationStream(client);
19
+ const [open, setOpen] = useState(false);
20
+ const [listed, setListed] = useState(null);
21
+ const [failed, setFailed] = useState(false);
22
+ const [reloads, setReloads] = useState(0);
23
+ const [markFailed, setMarkFailed] = useState(false);
24
+ const [readIds, setReadIds] = useState(() => new Set());
25
+ const root = useRef(null);
26
+ const button = useRef(null);
27
+ const panel = useRef(null);
28
+ const close = () => {
29
+ setOpen(false);
30
+ button.current?.focus();
31
+ };
32
+ useEffect(() => {
33
+ if (!open)
34
+ return;
35
+ let live = true;
36
+ setListed(null);
37
+ setFailed(false);
38
+ client.list({}).then((page) => {
39
+ if (live)
40
+ setListed(page.items);
41
+ }, () => {
42
+ if (live)
43
+ setFailed(true);
44
+ });
45
+ panel.current?.focus();
46
+ const onPointer = (event) => {
47
+ if (root.current && !root.current.contains(event.target)) {
48
+ setOpen(false);
49
+ button.current?.focus();
50
+ }
51
+ };
52
+ document.addEventListener('pointerdown', onPointer);
53
+ return () => {
54
+ live = false;
55
+ document.removeEventListener('pointerdown', onPointer);
56
+ };
57
+ }, [open, client, reloads]);
58
+ // Streamed items first (they are newer), then the page, without repeats.
59
+ const seen = new Set();
60
+ const items = [...latest, ...(listed ?? [])]
61
+ .filter((item) => !seen.has(item.id) && Boolean(seen.add(item.id)))
62
+ .slice(0, NEWEST);
63
+ const isRead = (item) => item.readAt !== null || readIds.has(item.id);
64
+ const openItem = (item) => {
65
+ setReadIds((ids) => new Set(ids).add(item.id));
66
+ setOpen(false);
67
+ openNotification(client, item, isRead(item), onOpenItem, setUnread);
68
+ };
69
+ const markAll = () => {
70
+ setMarkFailed(false);
71
+ client.markAllRead().then((count) => {
72
+ setUnread(count);
73
+ setReadIds((ids) => new Set([...ids, ...items.map((item) => item.id)]));
74
+ }, () => setMarkFailed(true));
75
+ };
76
+ // Focus moving to something else on the page closes it; focus lost to nowhere (a button
77
+ // that went disabled, the window) does not.
78
+ const onBlur = (event) => {
79
+ const next = event.relatedTarget;
80
+ if (next instanceof Node && !event.currentTarget.contains(next))
81
+ setOpen(false);
82
+ };
83
+ const onKeyDown = (event) => {
84
+ if (event.key === 'Escape') {
85
+ event.stopPropagation();
86
+ close();
87
+ }
88
+ };
89
+ return (_jsxs("div", { className: "hl-notify", ref: root, onKeyDown: open ? onKeyDown : undefined, onBlur: open ? onBlur : undefined, children: [_jsxs("button", { ref: button, type: "button", className: "hl-notify__bell", "aria-label": unread > 0 ? `Notifications, ${String(unread)} unread` : 'Notifications', "aria-expanded": open, "aria-haspopup": "dialog", onClick: () => (open ? close() : setOpen(true)), children: [_jsxs("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", "aria-hidden": "true", children: [_jsx("path", { d: "M6 8a6 6 0 1 1 12 0c0 7 3 9 3 9H3s3-2 3-9" }), _jsx("path", { d: "M10.3 21a1.94 1.94 0 0 0 3.4 0" })] }), unread > 0 && (_jsx("span", { className: "hl-notify__badge", "aria-hidden": "true", children: badgeText(unread) }))] }), open && (_jsxs("div", { ref: panel, role: "dialog", "aria-label": "Notifications", className: "hl-notify__popover", tabIndex: -1, children: [_jsxs("div", { className: "hl-notify__head", children: [_jsx("strong", { children: "Notifications" }), _jsx("button", { type: "button", className: "hl-notify__action", disabled: unread === 0 && items.every(isRead), onClick: markAll, children: "Mark all read" })] }), failed && _jsx(LoadError, { what: "notifications", onRetry: () => setReloads((n) => n + 1) }), markFailed && (_jsx("p", { role: "alert", className: "hl-notify__error", children: "Couldn\u2019t mark them read. Try again." })), listed === null && !failed && latest.length === 0 && (_jsx(Loading, { label: "Loading notifications" })), listed !== null && items.length === 0 && _jsx(EmptyState, { title: "Nothing here yet" }), items.length > 0 && (_jsx("ul", { className: "hl-notify__list", children: items.map((item) => (_jsx(NotificationRow, { item: item, read: isRead(item), onOpen: () => openItem(item) }, item.id))) })), _jsx("div", { className: "hl-notify__foot", children: _jsx("button", { type: "button", className: "hl-notify__action", onClick: () => {
90
+ setOpen(false);
91
+ onOpenItem(inboxPath);
92
+ }, children: "See all" }) })] }))] }));
93
+ }
94
+ //# sourceMappingURL=NotificationBell.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotificationBell.js","sourceRoot":"","sources":["../../src/notifications/NotificationBell.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,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,CACnB,KAAC,eAAe,IAEd,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,EAClB,MAAM,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAHvB,IAAI,CAAC,EAAE,CAIZ,CACH,CAAC,GACC,CACN,EACD,cAAK,SAAS,EAAC,iBAAiB,YAC9B,iBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,mBAAmB,EAC7B,OAAO,EAAE,GAAG,EAAE;gCACZ,OAAO,CAAC,KAAK,CAAC,CAAC;gCACf,UAAU,CAAC,SAAS,CAAC,CAAC;4BACxB,CAAC,wBAGM,GACL,IACF,CACP,IACG,CACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,23 @@
1
+ import type { ReactElement } from 'react';
2
+ import type { NotificationItemData, NotificationsClient } from './types.js';
3
+ /** A load error, with a button that tries again. */
4
+ export declare function LoadError(props: {
5
+ what: string;
6
+ onRetry: () => void;
7
+ }): ReactElement;
8
+ /**
9
+ * Marks the item read (when it is unread) and opens its link, only when the link is an app
10
+ * path: a link from anywhere else is never followed (`https:`, `//host`, `javascript:`).
11
+ */
12
+ export declare function openNotification(client: NotificationsClient, item: NotificationItemData, read: boolean, onOpenItem: (link: string) => void, onUnread: (unread: number) => void): void;
13
+ /** One item, as a button: it never renders the link itself. */
14
+ export declare function NotificationRow(props: {
15
+ item: NotificationItemData;
16
+ read: boolean;
17
+ onOpen: () => void;
18
+ }): ReactElement;
19
+ /** The full inbox page: All or Unread, newest first, a page at a time. */
20
+ export declare function NotificationInbox(props: {
21
+ client: NotificationsClient;
22
+ onOpenItem: (link: string) => void;
23
+ }): ReactElement;
@@ -0,0 +1,92 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import { EmptyState } from '../EmptyState.js';
4
+ import { Loading } from '../Loading.js';
5
+ import { isAppPath } from './types.js';
6
+ const when = new Intl.DateTimeFormat('en-GB', { dateStyle: 'medium', timeStyle: 'short' });
7
+ /** The time, or nothing for a date that does not parse. */
8
+ const shown = (iso) => {
9
+ const date = new Date(iso);
10
+ return Number.isNaN(date.getTime()) ? '' : when.format(date);
11
+ };
12
+ /** A load error, with a button that tries again. */
13
+ export function LoadError(props) {
14
+ return (_jsxs("p", { role: "alert", className: "hl-notify__error", children: ["Couldn\u2019t load ", props.what, ".", _jsx("button", { type: "button", className: "hl-notify__action", onClick: props.onRetry, children: "Try again" })] }));
15
+ }
16
+ /**
17
+ * Marks the item read (when it is unread) and opens its link, only when the link is an app
18
+ * path: a link from anywhere else is never followed (`https:`, `//host`, `javascript:`).
19
+ */
20
+ export function openNotification(client, item, read, onOpenItem, onUnread) {
21
+ if (!read)
22
+ client.markRead([item.id]).then(onUnread, () => undefined);
23
+ if (item.link !== null && isAppPath(item.link))
24
+ onOpenItem(item.link);
25
+ }
26
+ /** One item, as a button: it never renders the link itself. */
27
+ export function NotificationRow(props) {
28
+ const { item, read } = props;
29
+ return (_jsx("li", { className: read ? 'hl-notify__item' : 'hl-notify__item hl-notify__item--unread', children: _jsxs("button", { type: "button", className: "hl-notify__open", onClick: props.onOpen, children: [!read && _jsx("span", { className: "hl-notify__sr", children: "Unread: " }), _jsx("strong", { children: item.title }), item.body && _jsx("span", { className: "hl-notify__body", children: item.body }), _jsx("time", { dateTime: item.createdAt, children: shown(item.createdAt) })] }) }));
30
+ }
31
+ /** The full inbox page: All or Unread, newest first, a page at a time. */
32
+ export function NotificationInbox(props) {
33
+ const { client, onOpenItem } = props;
34
+ const [filter, setFilter] = useState('all');
35
+ const [items, setItems] = useState(null);
36
+ const [cursor, setCursor] = useState(null);
37
+ const [loadingMore, setLoadingMore] = useState(false);
38
+ const [failed, setFailed] = useState(false);
39
+ const [readIds, setReadIds] = useState(() => new Set());
40
+ const [reloads, setReloads] = useState(0);
41
+ // Which filter's pages are showing: a page that arrives after the filter changed is dropped.
42
+ const generation = useRef(0);
43
+ const query = (next) => ({
44
+ ...(filter === 'unread' ? { unread: true } : {}),
45
+ ...(next === undefined ? {} : { cursor: next }),
46
+ });
47
+ useEffect(() => {
48
+ let live = true;
49
+ generation.current += 1;
50
+ setItems(null);
51
+ setFailed(false);
52
+ client
53
+ .list(filter === 'unread' ? { unread: true } : {})
54
+ .then((page) => {
55
+ if (!live)
56
+ return;
57
+ setItems(page.items);
58
+ setCursor(page.nextCursor);
59
+ })
60
+ .catch(() => {
61
+ if (live)
62
+ setFailed(true);
63
+ });
64
+ return () => {
65
+ live = false;
66
+ };
67
+ }, [client, filter, reloads]);
68
+ const loadMore = () => {
69
+ if (cursor === null)
70
+ return;
71
+ const asked = generation.current;
72
+ setLoadingMore(true);
73
+ setFailed(false);
74
+ client
75
+ .list(query(cursor))
76
+ .then((page) => {
77
+ if (asked !== generation.current)
78
+ return;
79
+ setItems((current) => [...(current ?? []), ...page.items]);
80
+ setCursor(page.nextCursor);
81
+ })
82
+ .catch(() => setFailed(true))
83
+ .finally(() => setLoadingMore(false));
84
+ };
85
+ const isRead = (item) => item.readAt !== null || readIds.has(item.id);
86
+ const open = (item) => {
87
+ setReadIds((ids) => new Set(ids).add(item.id));
88
+ openNotification(client, item, isRead(item), onOpenItem, () => undefined);
89
+ };
90
+ return (_jsxs("div", { className: "hl-notify-page", children: [_jsx("div", { role: "group", "aria-label": "Show", className: "hl-notify__segments", children: ['all', 'unread'].map((value) => (_jsx("button", { type: "button", "aria-pressed": filter === value, onClick: () => setFilter(value), children: value === 'all' ? 'All' : 'Unread' }, value))) }), failed && (_jsx(LoadError, { what: "notifications", onRetry: () => (items === null ? setReloads((n) => n + 1) : loadMore()) })), items === null && !failed && _jsx(Loading, { label: "Loading notifications", rows: 4 }), items?.length === 0 && _jsx(EmptyState, { title: "Nothing here yet" }), items && items.length > 0 && (_jsx("ul", { className: "hl-notify__list", children: items.map((item) => (_jsx(NotificationRow, { item: item, read: isRead(item), onOpen: () => open(item) }, item.id))) })), cursor !== null && items !== null && (_jsx("button", { type: "button", className: "hl-notify__more", disabled: loadingMore, onClick: loadMore, children: "Load more" }))] }));
91
+ }
92
+ //# sourceMappingURL=NotificationInbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotificationInbox.js","sourceRoot":"","sources":["../../src/notifications/NotificationInbox.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;AAC3F,2DAA2D;AAC3D,MAAM,KAAK,GAAG,CAAC,GAAW,EAAU,EAAE;IACpC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3B,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC/D,CAAC,CAAC;AAEF,oDAAoD;AACpD,MAAM,UAAU,SAAS,CAAC,KAA4C;IACpE,OAAO,CACL,aAAG,IAAI,EAAC,OAAO,EAAC,SAAS,EAAC,kBAAkB,oCAC3B,KAAK,CAAC,IAAI,OACzB,iBAAQ,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,mBAAmB,EAAC,OAAO,EAAE,KAAK,CAAC,OAAO,0BAEjE,IACP,CACL,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAA2B,EAC3B,IAA0B,EAC1B,IAAa,EACb,UAAkC,EAClC,Q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AC5B,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CACnB,KAAC,eAAe,IAEd,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,EAClB,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAHnB,IAAI,CAAC,EAAE,CAIZ,CACH,CAAC,GACC,CACN,EACA,MAAM,KAAK,IAAI,IAAI,KAAK,KAAK,IAAI,IAAI,CACpC,iBAAQ,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,iBAAiB,EAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,0BAEjF,CACV,IACG,CACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { ReactElement } from 'react';
2
+ import type { NotificationsClient } from './types.js';
3
+ /**
4
+ * Which notifications go by email and push, per event, grouped. Each switch saves at once;
5
+ * a failed save puts it back and says so. A locked switch (a required event's email) is off
6
+ * limits. The inbox gets every event whatever is chosen here.
7
+ */
8
+ export declare function NotificationPreferences(props: {
9
+ client: NotificationsClient;
10
+ }): ReactElement;
@@ -0,0 +1,135 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import { Loading } from '../Loading.js';
4
+ import { LoadError } from './NotificationInbox.js';
5
+ const CHANNELS = [
6
+ { channel: 'email', label: 'Email' },
7
+ { channel: 'push', label: 'Push' },
8
+ ];
9
+ /** What a device that cannot ask for push says instead of the button. */
10
+ const PUSH_UNAVAILABLE = {
11
+ embedded: 'Push isn’t available inside Shopify — turn it on from the dashboard',
12
+ 'needs-install': 'Add this site to your Home Screen to get push',
13
+ unsupported: 'This browser can’t get push notifications',
14
+ };
15
+ const ENABLE_RESULT = {
16
+ subscribed: 'Push is on for this device',
17
+ denied: 'Push is blocked for this site — allow notifications in the browser’s settings',
18
+ ...PUSH_UNAVAILABLE,
19
+ };
20
+ /** The preferences with one event's channel changed, every other cell as it was. */
21
+ function withCell(data, event, channel, change) {
22
+ return {
23
+ events: data.events.map((row) => row.event === event
24
+ ? {
25
+ ...row,
26
+ channels: { ...row.channels, [channel]: { ...row.channels[channel], ...change } },
27
+ }
28
+ : row),
29
+ };
30
+ }
31
+ /** The events by group, in the order the app lists them. */
32
+ function groups(events) {
33
+ const out = [];
34
+ for (const row of events) {
35
+ const last = out.find(([group]) => group === row.group);
36
+ if (last)
37
+ last[1].push(row);
38
+ else
39
+ out.push([row.group, [row]]);
40
+ }
41
+ return out;
42
+ }
43
+ /** Push on this device: the button, or why this device cannot have it. */
44
+ function DevicePush({ push }) {
45
+ const [support] = useState(() => push.support());
46
+ const [state, setState] = useState({
47
+ busy: false,
48
+ });
49
+ useEffect(() => {
50
+ if (support !== 'supported' || !push.isSubscribed)
51
+ return;
52
+ let live = true;
53
+ push.isSubscribed().then((subscribed) => {
54
+ // A click since then knows better than this first look.
55
+ if (live && subscribed)
56
+ setState((current) => current.busy || current.result ? current : { busy: false, result: 'subscribed' });
57
+ },
58
+ // Not known: the button offers to enable, which is safe to press again.
59
+ () => undefined);
60
+ return () => {
61
+ live = false;
62
+ };
63
+ }, [push, support]);
64
+ const unavailable = PUSH_UNAVAILABLE[support] ??
65
+ (support === 'supported' ? undefined : PUSH_UNAVAILABLE.unsupported);
66
+ if (unavailable)
67
+ return _jsx("p", { className: "hl-notify__note", children: unavailable });
68
+ const enable = () => {
69
+ setState({ busy: true });
70
+ push.enable().then((result) => setState({ busy: false, result }), () => setState({ busy: false, failed: true }));
71
+ };
72
+ const disable = () => {
73
+ setState({ busy: true, result: 'subscribed' });
74
+ push.disable().then(() => setState({ busy: false }), () => setState({ busy: false, result: 'subscribed', failed: true }));
75
+ };
76
+ const on = state.result === 'subscribed';
77
+ return (_jsxs("div", { className: "hl-notify__device", children: [_jsx("button", { type: "button", className: "hl-notify__action", disabled: state.busy, onClick: on ? disable : enable, children: on ? 'Turn off push on this device' : 'Enable push on this device' }), state.result && _jsx("span", { className: "hl-notify__note", children: ENABLE_RESULT[state.result] }), state.failed && (_jsx("span", { role: "alert", className: "hl-notify__error", children: "Couldn\u2019t change push on this device. Try again." }))] }));
78
+ }
79
+ /**
80
+ * Which notifications go by email and push, per event, grouped. Each switch saves at once;
81
+ * a failed save puts it back and says so. A locked switch (a required event's email) is off
82
+ * limits. The inbox gets every event whatever is chosen here.
83
+ */
84
+ export function NotificationPreferences(props) {
85
+ const { client } = props;
86
+ const [data, setData] = useState(null);
87
+ const [loadFailed, setLoadFailed] = useState(false);
88
+ const [saveFailed, setSaveFailed] = useState(false);
89
+ const [reloads, setReloads] = useState(0);
90
+ // The newest save per cell (`event:channel`): an older answer never undoes a newer toggle,
91
+ // and each answer only sets its own cell, so saves of other cells in flight stay as shown.
92
+ const newest = useRef({});
93
+ useEffect(() => {
94
+ let live = true;
95
+ setLoadFailed(false);
96
+ client.preferences().then((loaded) => {
97
+ if (live)
98
+ setData(loaded);
99
+ }, () => {
100
+ if (live)
101
+ setLoadFailed(true);
102
+ });
103
+ return () => {
104
+ live = false;
105
+ };
106
+ }, [client, reloads]);
107
+ const toggle = (event, channel, on) => {
108
+ const cell = `${event}:${channel}`;
109
+ const save = (newest.current[cell] ?? 0) + 1;
110
+ newest.current[cell] = save;
111
+ setSaveFailed(false);
112
+ setData((current) => current && withCell(current, event, channel, { on }));
113
+ client.setPreferences([{ event, channel, on }]).then((saved) => {
114
+ if (newest.current[cell] !== save)
115
+ return;
116
+ const state = saved.events.find((row) => row.event === event)?.channels[channel];
117
+ if (state)
118
+ setData((current) => current && withCell(current, event, channel, state));
119
+ }, () => {
120
+ if (newest.current[cell] !== save)
121
+ return;
122
+ setData((current) => current && withCell(current, event, channel, { on: !on }));
123
+ setSaveFailed(true);
124
+ });
125
+ };
126
+ if (loadFailed)
127
+ return (_jsx("div", { className: "hl-notify-prefs", children: _jsx(LoadError, { what: "your notification settings", onRetry: () => setReloads((n) => n + 1) }) }));
128
+ if (!data)
129
+ return _jsx(Loading, { label: "Loading notification settings", rows: 3 });
130
+ return (_jsxs("div", { className: "hl-notify-prefs", children: [saveFailed && (_jsx("p", { role: "alert", className: "hl-notify__error", children: "Couldn\u2019t save that change, so it\u2019s back as it was. Try again." })), _jsx("div", { className: "hl-notify__table-box", children: _jsxs("table", { children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: "Notification" }), CHANNELS.map(({ channel, label }) => (_jsx("th", { scope: "col", children: label }, channel)))] }) }), groups(data.events).map(([group, rows]) => (_jsxs("tbody", { children: [_jsx("tr", { children: _jsx("th", { scope: "rowgroup", colSpan: 3, className: "hl-notify__group", children: group }) }), rows.map((row) => (_jsxs("tr", { children: [_jsx("th", { scope: "row", children: row.label }), CHANNELS.map(({ channel, label }) => {
131
+ const state = row.channels[channel];
132
+ return (_jsx("td", { children: _jsxs("span", { className: "hl-notify__cell", children: [_jsx("input", { type: "checkbox", role: "switch", className: "hl-notify__switch", "aria-label": `${label} for ${row.label}`, checked: state.on, disabled: state.locked, onChange: (e) => toggle(row.event, channel, e.target.checked) }), state.locked && _jsx("span", { className: "hl-notify__required", children: "Required" })] }) }, channel));
133
+ })] }, row.event)))] }, group)))] }) }), client.push && _jsx(DevicePush, { push: client.push })] }));
134
+ }
135
+ //# sourceMappingURL=NotificationPreferences.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotificationPreferences.js","sourceRoot":"","sources":["../../src/notifications/NotificationPreferences.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AASnD,MAAM,QAAQ,GAAsD;IAClE,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE;IACpC,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK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AC,mBAAmB,gBACjB,GAAG,KAAK,QAAQ,GAAG,CAAC,KAAK,EAAE,EACvC,OAAO,EAAE,KAAK,CAAC,EAAE,EACjB,QAAQ,EAAE,KAAK,CAAC,MAAM,EACtB,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAC7D,EACD,KAAK,CAAC,MAAM,IAAI,eAAM,SAAS,EAAC,qBAAqB,yBAAgB,IACjE,IAZA,OAAO,CAaX,CACN,CAAC;wCACJ,CAAC,CAAC,KApBK,GAAG,CAAC,KAAK,CAqBb,CACN,CAAC,KA7BQ,KAAK,CA8BT,CACT,CAAC,IACI,GACJ,EACL,MAAM,CAAC,IAAI,IAAI,KAAC,UAAU,IAAC,IAAI,EAAE,MAAM,CAAC,IAAI,GAAI,IAC7C,CACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The bell, the inbox page and the preferences, on the theme tokens only, at the admin
3
+ * density (13px). Scoped to `.hl-notify*`; button rules out-rank an app's own
4
+ * `button:hover:not(:disabled)`.
5
+ */
6
+ export declare const NOTIFICATIONS_CSS = "\n.hl-notify { position: relative; display: inline-flex; }\n.hl-notify button.hl-notify__bell, .hl-notify button.hl-notify__bell:hover:not(:disabled) { position: relative; width: 32px; height: 32px; min-height: 32px; padding: 0; box-sizing: border-box; display: grid; place-items: center; border: 1px solid var(--hl-border); border-radius: 999px; background: var(--hl-surface); color: var(--hl-text); cursor: pointer; }\n.hl-notify button.hl-notify__bell:hover:not(:disabled), .hl-notify button.hl-notify__bell[aria-expanded=\"true\"] { border-color: var(--hl-accent); }\n.hl-notify__badge { position: absolute; top: -5px; right: -7px; min-width: 18px; height: 18px; padding: 0 5px; box-sizing: border-box; border-radius: 999px; background: var(--hl-accent); color: var(--hl-on-accent); font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }\n.hl-notify__popover { position: absolute; top: calc(100% + 8px); right: 0; z-index: 20; width: 360px; max-width: calc(100vw - 32px); max-height: 70vh; display: flex; flex-direction: column; background: var(--hl-surface); color: var(--hl-text); border: 1px solid var(--hl-border); border-radius: var(--hl-radius-card); box-shadow: 0 12px 32px color-mix(in srgb, var(--hl-text) 18%, transparent); font-size: 13px; overflow: hidden; }\n.hl-notify__popover:focus { outline: none; }\n.hl-notify__popover:focus-visible { outline: 3px solid var(--hl-accent); outline-offset: 2px; }\n.hl-notify__head, .hl-notify__foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; }\n.hl-notify__head { border-bottom: 1px solid var(--hl-border); }\n.hl-notify__foot { border-top: 1px solid var(--hl-border); justify-content: center; }\n.hl-notify__popover .hl-notify__list { overflow-y: auto; }\n.hl-notify__list { list-style: none; margin: 0; padding: 0; }\n.hl-notify__item + .hl-notify__item { border-top: 1px solid var(--hl-border); }\n.hl-notify__item button.hl-notify__open, .hl-notify__item button.hl-notify__open:hover:not(:disabled) { width: 100%; min-height: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 8px 12px 8px 24px; position: relative; border: 0; border-radius: 0; background: transparent; color: var(--hl-text); font: inherit; font-size: 13px; font-weight: 400; text-align: left; cursor: pointer; }\n.hl-notify__item button.hl-notify__open:hover:not(:disabled) { background: var(--hl-faint); }\n.hl-notify__item--unread button.hl-notify__open::before { content: \"\"; position: absolute; left: 10px; top: 14px; width: 7px; height: 7px; border-radius: 999px; background: var(--hl-accent); }\n.hl-notify__item strong { font-weight: 500; }\n.hl-notify__item--unread strong { font-weight: 700; }\n.hl-notify__body { color: var(--hl-muted); }\n.hl-notify__item time { color: var(--hl-muted); font-size: 12px; }\n.hl-notify__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }\n.hl-notify button.hl-notify__action, .hl-notify-page button.hl-notify__action, .hl-notify-prefs button.hl-notify__action, .hl-notify-page button.hl-notify__more { min-height: 30px; padding: 0 10px; border: 1px solid var(--hl-border); border-radius: var(--hl-radius-control); background: var(--hl-surface); color: var(--hl-text); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }\n.hl-notify .hl-notify__head button.hl-notify__action { border-color: transparent; color: var(--hl-accent-text); }\n.hl-notify button.hl-notify__action:hover:not(:disabled), .hl-notify-page button.hl-notify__more:hover:not(:disabled), .hl-notify-prefs button.hl-notify__action:hover:not(:disabled) { border-color: var(--hl-accent); }\n.hl-notify button.hl-notify__action:disabled, .hl-notify-page button.hl-notify__more:disabled, .hl-notify-prefs button.hl-notify__action:disabled { opacity: .55; cursor: not-allowed; }\n.hl-notify__error { margin: 8px 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--hl-danger); font-size: 13px; }\n.hl-notify__popover .empty, .hl-notify-page .empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 24px 12px; color: var(--hl-muted); text-align: center; }\n.hl-notify__popover .empty strong, .hl-notify-page .empty strong { color: var(--hl-text); }\n.hl-notify-page { display: flex; flex-direction: column; gap: 12px; font-size: 13px; }\n.hl-notify-page .hl-notify__list { background: var(--hl-surface); border: 1px solid var(--hl-border); border-radius: var(--hl-radius-card); overflow: hidden; }\n.hl-notify-page .hl-notify__more { align-self: center; }\n.hl-notify-page .hl-notify__error { margin: 0; }\n.hl-notify__segments { display: inline-flex; align-self: flex-start; gap: 2px; padding: 3px; border-radius: 999px; background: var(--hl-faint); }\n.hl-notify__segments button, .hl-notify__segments button:hover:not(:disabled) { min-height: 28px; padding: 0 14px; border: 0; border-radius: 999px; background: transparent; color: var(--hl-muted); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }\n.hl-notify__segments button:hover:not(:disabled) { color: var(--hl-text); }\n.hl-notify__segments button[aria-pressed=\"true\"], .hl-notify__segments button[aria-pressed=\"true\"]:hover:not(:disabled) { background: var(--hl-surface); color: var(--hl-text); }\n.hl-notify-prefs { display: flex; flex-direction: column; gap: 12px; font-size: 13px; }\n.hl-notify-prefs .hl-notify__error { margin: 0; }\n.hl-notify-prefs .hl-notify__table-box { background: var(--hl-surface); border: 1px solid var(--hl-border); border-radius: var(--hl-radius-card); overflow-x: auto; }\n.hl-notify-prefs table { width: 100%; border-collapse: collapse; color: var(--hl-text); }\n.hl-notify-prefs th, .hl-notify-prefs td { padding: 8px 14px; text-align: left; border-bottom: 1px solid var(--hl-border); vertical-align: middle; font-weight: 400; }\n.hl-notify-prefs thead th { color: var(--hl-muted); font-size: 12px; font-weight: 700; }\n.hl-notify-prefs thead th + th, .hl-notify-prefs td { width: 120px; }\n.hl-notify-prefs th.hl-notify__group { padding-top: 12px; background: var(--hl-faint); font-weight: 700; }\n.hl-notify__cell { display: inline-flex; align-items: center; gap: 8px; }\n.hl-notify__required { color: var(--hl-muted); font-size: 12px; }\n.hl-notify__switch { appearance: none; position: relative; width: 32px; height: 18px; margin: 0; flex: none; border-radius: 999px; background: var(--hl-muted); cursor: pointer; transition: background .15s; }\n.hl-notify__switch::before { content: \"\"; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 999px; background: var(--hl-surface); transition: transform .15s; }\n.hl-notify__switch:checked { background: var(--hl-accent); }\n.hl-notify__switch:checked::before { transform: translateX(14px); background: var(--hl-on-accent); }\n.hl-notify__switch:disabled { opacity: .55; cursor: not-allowed; }\n.hl-notify__device { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }\n.hl-notify__note { margin: 0; color: var(--hl-muted); }\n@media (prefers-reduced-motion: reduce) { .hl-notify__switch, .hl-notify__switch::before { transition: none; } }\n";
@@ -0,0 +1,62 @@
1
+ /**
2
+ * The bell, the inbox page and the preferences, on the theme tokens only, at the admin
3
+ * density (13px). Scoped to `.hl-notify*`; button rules out-rank an app's own
4
+ * `button:hover:not(:disabled)`.
5
+ */
6
+ export const NOTIFICATIONS_CSS = `
7
+ .hl-notify { position: relative; display: inline-flex; }
8
+ .hl-notify button.hl-notify__bell, .hl-notify button.hl-notify__bell:hover:not(:disabled) { position: relative; width: 32px; height: 32px; min-height: 32px; padding: 0; box-sizing: border-box; display: grid; place-items: center; border: 1px solid var(--hl-border); border-radius: 999px; background: var(--hl-surface); color: var(--hl-text); cursor: pointer; }
9
+ .hl-notify button.hl-notify__bell:hover:not(:disabled), .hl-notify button.hl-notify__bell[aria-expanded="true"] { border-color: var(--hl-accent); }
10
+ .hl-notify__badge { position: absolute; top: -5px; right: -7px; min-width: 18px; height: 18px; padding: 0 5px; box-sizing: border-box; border-radius: 999px; background: var(--hl-accent); color: var(--hl-on-accent); font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
11
+ .hl-notify__popover { position: absolute; top: calc(100% + 8px); right: 0; z-index: 20; width: 360px; max-width: calc(100vw - 32px); max-height: 70vh; display: flex; flex-direction: column; background: var(--hl-surface); color: var(--hl-text); border: 1px solid var(--hl-border); border-radius: var(--hl-radius-card); box-shadow: 0 12px 32px color-mix(in srgb, var(--hl-text) 18%, transparent); font-size: 13px; overflow: hidden; }
12
+ .hl-notify__popover:focus { outline: none; }
13
+ .hl-notify__popover:focus-visible { outline: 3px solid var(--hl-accent); outline-offset: 2px; }
14
+ .hl-notify__head, .hl-notify__foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; }
15
+ .hl-notify__head { border-bottom: 1px solid var(--hl-border); }
16
+ .hl-notify__foot { border-top: 1px solid var(--hl-border); justify-content: center; }
17
+ .hl-notify__popover .hl-notify__list { overflow-y: auto; }
18
+ .hl-notify__list { list-style: none; margin: 0; padding: 0; }
19
+ .hl-notify__item + .hl-notify__item { border-top: 1px solid var(--hl-border); }
20
+ .hl-notify__item button.hl-notify__open, .hl-notify__item button.hl-notify__open:hover:not(:disabled) { width: 100%; min-height: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 8px 12px 8px 24px; position: relative; border: 0; border-radius: 0; background: transparent; color: var(--hl-text); font: inherit; font-size: 13px; font-weight: 400; text-align: left; cursor: pointer; }
21
+ .hl-notify__item button.hl-notify__open:hover:not(:disabled) { background: var(--hl-faint); }
22
+ .hl-notify__item--unread button.hl-notify__open::before { content: ""; position: absolute; left: 10px; top: 14px; width: 7px; height: 7px; border-radius: 999px; background: var(--hl-accent); }
23
+ .hl-notify__item strong { font-weight: 500; }
24
+ .hl-notify__item--unread strong { font-weight: 700; }
25
+ .hl-notify__body { color: var(--hl-muted); }
26
+ .hl-notify__item time { color: var(--hl-muted); font-size: 12px; }
27
+ .hl-notify__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
28
+ .hl-notify button.hl-notify__action, .hl-notify-page button.hl-notify__action, .hl-notify-prefs button.hl-notify__action, .hl-notify-page button.hl-notify__more { min-height: 30px; padding: 0 10px; border: 1px solid var(--hl-border); border-radius: var(--hl-radius-control); background: var(--hl-surface); color: var(--hl-text); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
29
+ .hl-notify .hl-notify__head button.hl-notify__action { border-color: transparent; color: var(--hl-accent-text); }
30
+ .hl-notify button.hl-notify__action:hover:not(:disabled), .hl-notify-page button.hl-notify__more:hover:not(:disabled), .hl-notify-prefs button.hl-notify__action:hover:not(:disabled) { border-color: var(--hl-accent); }
31
+ .hl-notify button.hl-notify__action:disabled, .hl-notify-page button.hl-notify__more:disabled, .hl-notify-prefs button.hl-notify__action:disabled { opacity: .55; cursor: not-allowed; }
32
+ .hl-notify__error { margin: 8px 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--hl-danger); font-size: 13px; }
33
+ .hl-notify__popover .empty, .hl-notify-page .empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 24px 12px; color: var(--hl-muted); text-align: center; }
34
+ .hl-notify__popover .empty strong, .hl-notify-page .empty strong { color: var(--hl-text); }
35
+ .hl-notify-page { display: flex; flex-direction: column; gap: 12px; font-size: 13px; }
36
+ .hl-notify-page .hl-notify__list { background: var(--hl-surface); border: 1px solid var(--hl-border); border-radius: var(--hl-radius-card); overflow: hidden; }
37
+ .hl-notify-page .hl-notify__more { align-self: center; }
38
+ .hl-notify-page .hl-notify__error { margin: 0; }
39
+ .hl-notify__segments { display: inline-flex; align-self: flex-start; gap: 2px; padding: 3px; border-radius: 999px; background: var(--hl-faint); }
40
+ .hl-notify__segments button, .hl-notify__segments button:hover:not(:disabled) { min-height: 28px; padding: 0 14px; border: 0; border-radius: 999px; background: transparent; color: var(--hl-muted); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
41
+ .hl-notify__segments button:hover:not(:disabled) { color: var(--hl-text); }
42
+ .hl-notify__segments button[aria-pressed="true"], .hl-notify__segments button[aria-pressed="true"]:hover:not(:disabled) { background: var(--hl-surface); color: var(--hl-text); }
43
+ .hl-notify-prefs { display: flex; flex-direction: column; gap: 12px; font-size: 13px; }
44
+ .hl-notify-prefs .hl-notify__error { margin: 0; }
45
+ .hl-notify-prefs .hl-notify__table-box { background: var(--hl-surface); border: 1px solid var(--hl-border); border-radius: var(--hl-radius-card); overflow-x: auto; }
46
+ .hl-notify-prefs table { width: 100%; border-collapse: collapse; color: var(--hl-text); }
47
+ .hl-notify-prefs th, .hl-notify-prefs td { padding: 8px 14px; text-align: left; border-bottom: 1px solid var(--hl-border); vertical-align: middle; font-weight: 400; }
48
+ .hl-notify-prefs thead th { color: var(--hl-muted); font-size: 12px; font-weight: 700; }
49
+ .hl-notify-prefs thead th + th, .hl-notify-prefs td { width: 120px; }
50
+ .hl-notify-prefs th.hl-notify__group { padding-top: 12px; background: var(--hl-faint); font-weight: 700; }
51
+ .hl-notify__cell { display: inline-flex; align-items: center; gap: 8px; }
52
+ .hl-notify__required { color: var(--hl-muted); font-size: 12px; }
53
+ .hl-notify__switch { appearance: none; position: relative; width: 32px; height: 18px; margin: 0; flex: none; border-radius: 999px; background: var(--hl-muted); cursor: pointer; transition: background .15s; }
54
+ .hl-notify__switch::before { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 999px; background: var(--hl-surface); transition: transform .15s; }
55
+ .hl-notify__switch:checked { background: var(--hl-accent); }
56
+ .hl-notify__switch:checked::before { transform: translateX(14px); background: var(--hl-on-accent); }
57
+ .hl-notify__switch:disabled { opacity: .55; cursor: not-allowed; }
58
+ .hl-notify__device { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
59
+ .hl-notify__note { margin: 0; color: var(--hl-muted); }
60
+ @media (prefers-reduced-motion: reduce) { .hl-notify__switch, .hl-notify__switch::before { transition: none; } }
61
+ `;
62
+ //# sourceMappingURL=notifications-css.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notifications-css.js","sourceRoot":"","sources":["../../src/notifications/notifications-css.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuDhC,CAAC"}
@@ -0,0 +1,80 @@
1
+ /** One inbox item. `link` is an app path, or null. */
2
+ export interface NotificationItemData {
3
+ id: string;
4
+ event: string;
5
+ title: string;
6
+ body: string;
7
+ link: string | null;
8
+ readAt: string | null;
9
+ createdAt: string;
10
+ }
11
+ export type NotificationChannel = 'email' | 'push';
12
+ export interface NotificationChannelState {
13
+ on: boolean;
14
+ /** The person cannot change it (a required event's email). */
15
+ locked: boolean;
16
+ }
17
+ /** One event's row in the preferences. */
18
+ export interface NotificationPreferenceData {
19
+ event: string;
20
+ label: string;
21
+ group: string;
22
+ required: boolean;
23
+ channels: Record<NotificationChannel, NotificationChannelState>;
24
+ }
25
+ /** `GET` and `PUT /notifications/preferences`. */
26
+ export interface PreferencesData {
27
+ events: NotificationPreferenceData[];
28
+ }
29
+ export interface NotificationPreferenceChange {
30
+ event: string;
31
+ channel: NotificationChannel;
32
+ on: boolean;
33
+ }
34
+ /** What the stream sends: the unread count (on connect and after every change), or a new item. */
35
+ export type NotificationStreamEvent = {
36
+ kind: 'unread';
37
+ unread: number;
38
+ } | {
39
+ kind: 'notification';
40
+ item: NotificationItemData;
41
+ };
42
+ /** The notification routes, as the app's API client calls them. */
43
+ export interface NotificationsClient {
44
+ list(q: {
45
+ unread?: boolean;
46
+ cursor?: string;
47
+ }): Promise<{
48
+ items: NotificationItemData[];
49
+ nextCursor: string | null;
50
+ unread?: number;
51
+ }>;
52
+ unreadCount(): Promise<number>;
53
+ /** Marks the caller's items read; resolves to the caller's unread count. */
54
+ markRead(ids: string[]): Promise<number>;
55
+ /** Resolves to the caller's unread count (0). */
56
+ markAllRead(): Promise<number>;
57
+ /**
58
+ * Reads `GET /notifications/stream` until `signal` aborts or the connection ends, calling
59
+ * `onEvent` per event. With fetch streaming, so bearer auth works inside the Shopify frame.
60
+ * Without it, the bell polls the unread count.
61
+ */
62
+ stream?(signal: AbortSignal, onEvent: (e: NotificationStreamEvent) => void): Promise<void>;
63
+ preferences(): Promise<PreferencesData>;
64
+ setPreferences(changes: NotificationPreferenceChange[]): Promise<PreferencesData>;
65
+ /** Push on this device, usually from `@haatlabs-core/notifications/browser`. */
66
+ push?: {
67
+ /** `supported`, `embedded`, `needs-install` or `unsupported`. */
68
+ support(): string;
69
+ /** Asks for permission and subscribes; resolves to `subscribed`, `denied` or why not. */
70
+ enable(): Promise<string>;
71
+ disable(): Promise<void>;
72
+ /** Whether this device already has push on, so the button offers to turn it off. */
73
+ isSubscribed?(): Promise<boolean>;
74
+ };
75
+ }
76
+ /**
77
+ * A link is an in-app path: one leading slash, no spaces or backslashes, at most 512
78
+ * characters. The same rule as `@haatlabs-core/notifications`, copied so the UI does not load it.
79
+ */
80
+ export declare function isAppPath(link: string): boolean;