@micha.bigler/ui-core-micha 4.41.0 → 4.43.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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.43.0 - UCM-NOTIF-18
4
+
5
+ The canonical copyable push service worker now supports DCM-provided localized
6
+ `open` and `done` notification actions. `open` retains same-origin navigation;
7
+ `done` obtains a per-click masked CSRF token and posts the opaque completion
8
+ token without opening an app window. Existing base-only push payloads retain
9
+ their display and tap-to-open behaviour. Gustav can pin this additive release.
10
+
11
+ ## 4.42.0 - UCM-CHAT-21
12
+
13
+ In managed mode the chat model picker lists the offered families grouped by
14
+ provider (OpenAI: Astra, Sol, Terra, Luna; Claude: Fable, Opus, Sonnet,
15
+ Haiku), one row per provider/family, and sends the stable public ID
16
+ `provider:family` with the effort. Route, account, billing and model-version
17
+ fields of the catalogue are neither rendered nor kept, so a route-only change
18
+ keeps the explicit selection. Requires the managed public catalogue of
19
+ django-core-micha 3.32.0 (`entries[].{id, provider, family, efforts}`); the
20
+ unmanaged picker is unchanged.
21
+
3
22
  ## 4.41.0 - UCM-CHAT-22
4
23
 
5
24
  Chat workspaces support per-chat permission groups, including explicit
package/README.md CHANGED
@@ -239,6 +239,10 @@ extra peers are optional: `@micha.bigler/ui-core-micha/charts` (`@mui/x-charts`)
239
239
  (`react-markdown`, `remark-gfm`). Install those peers only in apps that import the sub-path. The 4.0.0 entry in
240
240
  `CHANGELOG.md` has the migration table.
241
241
 
242
+ ## Shared chat: group permissions
243
+
244
+ An app that registers a DCM group catalogue gets the shared chat permission control without extra `ChatWorkspace` props. For the selected private, unarchived chat, UCM reads `chats/<id>/group-grants/` under `apiBase`; unsupported apps and older servers retain their existing chat UI. The server supplies localized group and member labels, availability, write confirmation metadata and opaque revisions. UCM sends only selected group IDs and both revisions on save. A stale response requires a reload; failed saves retain the draft. Existing `api` overrides can provide `getGroupGrants(id)` and `saveGroupGrants(id, payload)` using the same response contract. Authorization and enforcement remain server responsibilities.
245
+
242
246
  ## Shared chat: compact composer (opt-in)
243
247
 
244
248
  `<ChatWorkspace composerLayout="compact" renderComposerContext={({ chat }) => ...}>` lays the composer out in two
@@ -8,7 +8,7 @@ import { useChatSocket } from './useChatSocket';
8
8
  import ChatList from './ChatList';
9
9
  import ChatThread from './ChatThread';
10
10
  import ChatComposer from './ChatComposer';
11
- import ModelPicker from './ModelPicker';
11
+ import ModelPicker, { publicFamilies } from './ModelPicker';
12
12
  const PENDING_ID = 'pending';
13
13
  const buildSendFrame = (message, getContext) => {
14
14
  if (typeof getContext !== 'function')
@@ -206,10 +206,15 @@ export function ChatWorkspace({ apiBase, wsUrl, api: apiOverrides, scope, preloa
206
206
  && sameChatId(shownChatId.current, chatId);
207
207
  if (!current || !validCatalogue(next))
208
208
  return null;
209
+ const safe = Object.prototype.hasOwnProperty.call(next, 'policy') ? {
210
+ entries: publicFamilies(next.entries),
211
+ default: next.default ? { entry: next.default.entry, effort: next.default.effort } : null,
212
+ policy: { revision: next.policy.revision },
213
+ } : next;
209
214
  catalogueFor.current = chatId !== null && chatId !== void 0 ? chatId : null;
210
- setCatalogue(next);
215
+ setCatalogue(safe);
211
216
  setCatalogueChatId(chatId !== null && chatId !== void 0 ? chatId : null);
212
- return next;
217
+ return safe;
213
218
  }
214
219
  catch (_b) {
215
220
  // A failed load for another chat must not leave the previous chat's models on offer.
@@ -1,11 +1,31 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import React, { useMemo, useRef, useState } from 'react';
2
+ import React, { useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { Box, Button, Drawer, IconButton, List, ListItemButton, Popover, Stack, ToggleButton, ToggleButtonGroup, Typography, useMediaQuery, useTheme } from '@mui/material';
4
4
  import CloseIcon from '@mui/icons-material/Close';
5
5
  import { useTranslation } from 'react-i18next';
6
6
  const LEVELS = ['top', 'best', 'balanced', 'fast'];
7
7
  const EFFORTS = ['low', 'medium', 'high', 'max'];
8
8
  const EFFORT_LABELS = { low: 'Low', medium: 'Medium', high: 'High', max: 'Max' };
9
+ const MANAGED_FAMILIES = {
10
+ openai: { astra: 'Astra', sol: 'Sol', terra: 'Terra', luna: 'Luna' },
11
+ claude: { fable: 'Fable', opus: 'Opus', sonnet: 'Sonnet', haiku: 'Haiku' },
12
+ };
13
+ const PROVIDER_LABELS = { openai: 'OpenAI', claude: 'Claude' };
14
+ export function publicFamilies(entries) {
15
+ const seen = new Set();
16
+ return entries.flatMap((entry) => {
17
+ var _a;
18
+ const label = (_a = MANAGED_FAMILIES[entry === null || entry === void 0 ? void 0 : entry.provider]) === null || _a === void 0 ? void 0 : _a[entry === null || entry === void 0 ? void 0 : entry.family];
19
+ const id = `${entry === null || entry === void 0 ? void 0 : entry.provider}:${entry === null || entry === void 0 ? void 0 : entry.family}`;
20
+ if (!label || entry.id !== id || seen.has(id) || !Array.isArray(entry.efforts))
21
+ return [];
22
+ const efforts = EFFORTS.filter((effort) => entry.efforts.includes(effort));
23
+ if (!efforts.length)
24
+ return [];
25
+ seen.add(id);
26
+ return [{ id, provider: entry.provider, family: entry.family, label, efforts }];
27
+ });
28
+ }
9
29
  export const CHAT_MODEL_TRIGGER_SX = { minWidth: 0, px: 1.25, color: 'text.secondary', whiteSpace: 'nowrap', flexShrink: 0, maxWidth: { xs: 140, sm: 'none' } };
10
30
  // The short label sits at the end of the compact composer's context row, which clips the host content first.
11
31
  export const CHAT_MODEL_TRIGGER_SHORT_SX = Object.assign(Object.assign({}, CHAT_MODEL_TRIGGER_SX), { maxWidth: 'none' });
@@ -62,7 +82,7 @@ function estimateText(entry, effort, t, language) {
62
82
  }
63
83
  return null;
64
84
  }
65
- export function ModelPicker({ entries = [], selection, onChange, disabled = false, open, onOpenChange, balance = null, shortLabel = false, managed = false }) {
85
+ export function ModelPicker({ entries: rawEntries = [], selection, onChange, disabled = false, open, onOpenChange, balance = null, shortLabel = false, managed = false }) {
66
86
  const { t, i18n } = useTranslation();
67
87
  const language = typeof (i18n === null || i18n === void 0 ? void 0 : i18n.language) === 'string' ? i18n.language.split('_')[0] || undefined : undefined;
68
88
  const theme = useTheme();
@@ -70,24 +90,33 @@ export function ModelPicker({ entries = [], selection, onChange, disabled = fals
70
90
  // The bottom sheet only on a narrow viewport, whatever the chat container's width (UCM-CHAT-12).
71
91
  const narrow = viewportNarrow;
72
92
  const anchor = useRef(null);
93
+ const choices = useRef(null);
73
94
  const [innerOpen, setInnerOpen] = useState(false);
74
95
  const isOpen = open !== null && open !== void 0 ? open : innerOpen;
96
+ useEffect(() => {
97
+ if (!isOpen)
98
+ return undefined;
99
+ const timer = window.setTimeout(() => { var _a, _b; return (_b = (_a = choices.current) === null || _a === void 0 ? void 0 : _a.querySelector('[role="radio"][aria-checked="true"]')) === null || _b === void 0 ? void 0 : _b.focus(); }, 0);
100
+ return () => window.clearTimeout(timer);
101
+ }, [isOpen]);
75
102
  const setOpen = (value) => { setInnerOpen(value); onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(value); };
103
+ const entries = useMemo(() => managed ? publicFamilies(rawEntries) : rawEntries, [managed, rawEntries]);
76
104
  const activeSelection = useMemo(() => validSelection(entries, selection) || (!managed ? fallback(entries) : null), [entries, selection, managed]);
77
105
  const active = entries.find((entry) => entry.id === (activeSelection === null || activeSelection === void 0 ? void 0 : activeSelection.entry));
78
106
  const effort = activeSelection === null || activeSelection === void 0 ? void 0 : activeSelection.effort;
79
107
  const duplicateRows = useMemo(() => repeatedLabels(entries, originalLabel), [entries]);
80
108
  const duplicateTriggers = useMemo(() => repeatedLabels(entries, (entry) => cleanLabel(entry, shortLabel)), [entries, shortLabel]);
81
- const grouped = LEVELS.map((level) => [level, entries.filter((entry) => entry.level === level)]).filter(([, items]) => items.length);
82
- const unknown = entries.filter((entry) => !LEVELS.includes(entry.level));
109
+ const grouped = (managed ? Object.keys(PROVIDER_LABELS).map((provider) => [provider, entries.filter((entry) => entry.provider === provider)])
110
+ : LEVELS.map((level) => [level, entries.filter((entry) => entry.level === level)])).filter(([, items]) => items.length);
111
+ const unknown = managed ? [] : entries.filter((entry) => !LEVELS.includes(entry.level));
83
112
  const orderedEntries = [...grouped.flatMap(([, items]) => items), ...unknown];
84
113
  const selectEntry = (entry) => { var _a; return onChange === null || onChange === void 0 ? void 0 : onChange({ entry: entry.id, effort: supported(entry, effort) ? effort : (_a = entry.efforts) === null || _a === void 0 ? void 0 : _a[0] }); };
85
114
  const entryRow = (entry, index) => {
86
115
  var _a;
87
116
  const shown = supported(entry, effort) ? effort : (_a = entry.efforts) === null || _a === void 0 ? void 0 : _a[0];
88
- const estimate = estimateText(entry, shown, t, language);
117
+ const estimate = managed ? null : estimateText(entry, shown, t, language);
89
118
  const checked = entry.id === (active === null || active === void 0 ? void 0 : active.id);
90
- return _jsx(ListItemButton, { role: "radio", "aria-checked": checked, tabIndex: checked || (!active && index === 0) ? 0 : -1, "data-model-entry": entry.id, selected: checked, sx: CHAT_MODEL_ENTRY_SX, onClick: () => selectEntry(entry), children: _jsxs(Box, { sx: CHAT_MODEL_ENTRY_CONTENT_SX, children: [_jsx(Typography, { variant: "body2", fontWeight: checked ? 600 : 400, children: sourceNamedLabel(entry, originalLabel(entry), duplicateRows) }), estimate ? _jsx(Typography, { variant: "caption", color: "text.secondary", sx: CHAT_MODEL_COST_SX, children: estimate }) : null] }) }, entry.id);
119
+ return _jsx(ListItemButton, { role: "radio", "aria-label": managed ? `${PROVIDER_LABELS[entry.provider]} ${entry.label}` : undefined, "aria-checked": checked, tabIndex: checked || (!active && index === 0) ? 0 : -1, "data-model-entry": entry.id, selected: checked, sx: managed && checked ? Object.assign(Object.assign({}, CHAT_MODEL_ENTRY_SX), { position: 'relative', '&::before': { content: '""', position: 'absolute', left: 0, top: 4, bottom: 4, width: 3, bgcolor: 'primary.main' } }) : CHAT_MODEL_ENTRY_SX, onClick: () => selectEntry(entry), children: _jsxs(Box, { sx: CHAT_MODEL_ENTRY_CONTENT_SX, children: [_jsx(Typography, { variant: "body2", fontWeight: checked ? 600 : 400, children: managed ? entry.label : sourceNamedLabel(entry, originalLabel(entry), duplicateRows) }), estimate ? _jsx(Typography, { variant: "caption", color: "text.secondary", sx: CHAT_MODEL_COST_SX, children: estimate }) : null] }) }, entry.id);
91
120
  };
92
121
  // Radio-group keyboard behaviour: arrows move the focus and the choice, only the checked row is a tab stop.
93
122
  const moveSelection = (event) => {
@@ -106,9 +135,9 @@ export function ModelPicker({ entries = [], selection, onChange, disabled = fals
106
135
  selectEntry(next);
107
136
  (_a = [...event.currentTarget.querySelectorAll('[data-model-entry]')].find((node) => node.dataset.modelEntry === next.id)) === null || _a === void 0 ? void 0 : _a.focus();
108
137
  };
109
- const content = (_jsx(Box, { role: "dialog", "aria-labelledby": "chat-model-picker-title", sx: narrow ? CHAT_MODEL_PANEL_SHEET_SX : CHAT_MODEL_PANEL_SX, children: _jsxs(Stack, { spacing: 1.25, children: [_jsxs(Stack, { direction: "row", alignItems: "center", gap: 1, children: [_jsx(Typography, { id: "chat-model-picker-title", variant: "subtitle1", sx: { fontWeight: 600 }, children: t('Chat.pickerTitle') }), _jsx(IconButton, { "aria-label": t('Chat.close'), size: "small", sx: CHAT_MODEL_CLOSE_SX, onClick: () => setOpen(false), children: _jsx(CloseIcon, { fontSize: "small" }) })] }), _jsx(Box, { role: "radiogroup", "aria-labelledby": "chat-model-picker-title", onKeyDown: moveSelection, children: _jsx(List, { dense: true, disablePadding: true, children: orderedEntries.map(entryRow) }) }), active ? _jsxs(Box, { children: [_jsx(Typography, { variant: "subtitle2", sx: { mb: 0.75 }, children: t('Chat.effortLabel') }), _jsx(ToggleButtonGroup, { exclusive: true, fullWidth: true, size: "small", value: effort || null, "aria-label": t('Chat.effortLabel'), onChange: (_event, next) => { if (next)
138
+ const content = (_jsx(Box, { role: "dialog", "aria-labelledby": "chat-model-picker-title", sx: narrow ? CHAT_MODEL_PANEL_SHEET_SX : CHAT_MODEL_PANEL_SX, children: _jsxs(Stack, { spacing: 1.25, children: [_jsxs(Stack, { direction: "row", alignItems: "center", gap: 1, children: [_jsx(Typography, { id: "chat-model-picker-title", variant: "subtitle1", sx: { fontWeight: 600 }, children: t('Chat.pickerTitle') }), _jsx(IconButton, { "aria-label": t('Chat.close'), size: "small", sx: CHAT_MODEL_CLOSE_SX, onClick: () => setOpen(false), children: _jsx(CloseIcon, { fontSize: "small" }) })] }), _jsx(Box, { ref: choices, role: "radiogroup", "aria-labelledby": "chat-model-picker-title", onKeyDown: moveSelection, children: managed ? (grouped.length ? grouped.map(([provider, items]) => _jsxs(Box, { sx: { my: 1 }, children: [_jsx(Typography, { variant: "subtitle2", sx: { ml: 1, mb: 0.5, fontWeight: 600 }, children: PROVIDER_LABELS[provider] }), _jsx(List, { dense: true, disablePadding: true, children: items.map((entry) => entryRow(entry, orderedEntries.indexOf(entry))) })] }, provider)) : _jsx(Typography, { variant: "body2", color: "text.secondary", children: t('Chat.unavailable') })) : _jsx(List, { dense: true, disablePadding: true, children: orderedEntries.map(entryRow) }) }), active ? _jsxs(Box, { children: [_jsx(Typography, { variant: "subtitle2", sx: { mb: 0.75 }, children: t('Chat.effortLabel') }), _jsx(ToggleButtonGroup, { exclusive: true, fullWidth: true, size: "small", value: effort || null, "aria-label": t('Chat.effortLabel'), onChange: (_event, next) => { if (next)
110
139
  onChange === null || onChange === void 0 ? void 0 : onChange({ entry: active.id, effort: next }); }, children: EFFORTS.filter((item) => { var _a; return (_a = active.efforts) === null || _a === void 0 ? void 0 : _a.includes(item); }).map((item) => _jsx(ToggleButton, { value: item, sx: CHAT_MODEL_EFFORT_SX, children: EFFORT_LABELS[item] }, item)) })] }) : null, Number.isInteger(balance) && balance >= 0 ? _jsx(Typography, { variant: "caption", color: "text.secondary", children: t('Chat.balanceLabel', { n: new Intl.NumberFormat(language).format(balance) }) }) : null] }) }));
111
- const trigger = _jsx(Button, { ref: anchor, size: "small", color: "inherit", sx: shortLabel ? CHAT_MODEL_TRIGGER_SHORT_SX : CHAT_MODEL_TRIGGER_SX, disabled: disabled || !entries.length, onClick: () => setOpen(true), "aria-haspopup": "dialog", children: _jsx(Box, { component: "span", sx: { overflow: 'hidden', textOverflow: 'ellipsis' }, children: active ? `${sourceNamedLabel(active, cleanLabel(active, shortLabel), duplicateTriggers)} · ${t(`Chat.effort.${effort}`)} ▾` : t('Chat.unavailable') }) });
140
+ const trigger = _jsx(Button, { ref: anchor, size: "small", color: "inherit", sx: shortLabel ? CHAT_MODEL_TRIGGER_SHORT_SX : CHAT_MODEL_TRIGGER_SX, disabled: disabled || (!managed && !entries.length), onClick: () => setOpen(true), "aria-haspopup": "dialog", children: _jsx(Box, { component: "span", sx: { overflow: 'hidden', textOverflow: 'ellipsis' }, children: active ? `${managed ? `${PROVIDER_LABELS[active.provider]} · ${active.label}` : sourceNamedLabel(active, cleanLabel(active, shortLabel), duplicateTriggers)} · ${t(`Chat.effort.${effort}`)} ▾` : t('Chat.unavailable') }) });
112
141
  return _jsxs(_Fragment, { children: [trigger, narrow ? _jsx(Drawer, { anchor: "bottom", open: isOpen, onClose: () => setOpen(false), children: content }) : _jsx(Popover, { open: isOpen, anchorEl: anchor.current, onClose: () => setOpen(false), anchorOrigin: { vertical: 'top', horizontal: 'left' }, transformOrigin: { vertical: 'bottom', horizontal: 'left' }, children: content })] });
113
142
  }
114
143
  export default ModelPicker;
@@ -3,15 +3,90 @@
3
3
  * Canonical service-worker source. Copy this file verbatim to each consuming
4
4
  * application's public/sw.js so it is served from that application's origin root.
5
5
  */
6
- const resolveSameOriginUrl = (url) => {
6
+ const PUSH_CSRF_URL = '/api/notifications/push/csrf/';
7
+ const PUSH_DONE_URL = '/api/notifications/push/done/';
8
+ const KNOWN_ACTIONS = new Set(['open', 'done']);
9
+ const doneActionsInFlight = new WeakSet();
10
+ const appUrl = (value) => {
7
11
  try {
8
- const resolvedUrl = new URL(url || '/', self.location.origin);
9
- if (resolvedUrl.origin !== self.location.origin)
10
- return '/';
11
- return `${resolvedUrl.pathname}${resolvedUrl.search}${resolvedUrl.hash}`;
12
+ if (typeof value !== 'string' || !value)
13
+ return undefined;
14
+ const resolvedUrl = new URL(value, self.location.origin);
15
+ if (resolvedUrl.origin !== self.location.origin || !['http:', 'https:'].includes(resolvedUrl.protocol) || resolvedUrl.username || resolvedUrl.password)
16
+ return undefined;
17
+ return resolvedUrl.href;
12
18
  }
13
19
  catch (_a) {
14
- return '/';
20
+ return undefined;
21
+ }
22
+ };
23
+ const safeAppUrl = (value) => appUrl(value) || new URL('/', self.location.origin).href;
24
+ const notificationAction = (actions, name) => (Array.isArray(actions)
25
+ ? actions.find((action) => action && action.action === name && typeof action.title === 'string' && action.title)
26
+ : undefined);
27
+ const displayOptions = (payload) => {
28
+ const openAction = notificationAction(payload.actions, 'open');
29
+ const doneAction = notificationAction(payload.actions, 'done');
30
+ const hasDoneToken = typeof payload.done_token === 'string' && payload.done_token;
31
+ const actions = [];
32
+ if (openAction)
33
+ actions.push({ action: 'open', title: openAction.title });
34
+ if (doneAction && hasDoneToken)
35
+ actions.push({ action: 'done', title: doneAction.title });
36
+ const base = {
37
+ body: typeof payload.body === 'string' ? payload.body : '',
38
+ data: { url: safeAppUrl(payload.url), openUrl: appUrl(openAction === null || openAction === void 0 ? void 0 : openAction.url) || safeAppUrl(payload.url), doneToken: hasDoneToken ? payload.done_token : undefined },
39
+ };
40
+ const optional = {};
41
+ if (typeof payload.icon === 'string' && payload.icon)
42
+ optional.icon = payload.icon;
43
+ if (typeof payload.badge === 'string' && payload.badge)
44
+ optional.badge = payload.badge;
45
+ if (typeof payload.tag === 'string' && payload.tag)
46
+ optional.tag = payload.tag;
47
+ if (optional.tag && typeof payload.renotify === 'boolean')
48
+ optional.renotify = payload.renotify;
49
+ if (actions.length)
50
+ optional.actions = actions;
51
+ return { base, optional };
52
+ };
53
+ const showPushNotification = async (payload) => {
54
+ const { base, optional } = displayOptions(payload);
55
+ const title = typeof payload.title === 'string' && payload.title ? payload.title : 'Notification';
56
+ try {
57
+ await self.registration.showNotification(title, Object.assign(Object.assign({}, base), optional));
58
+ }
59
+ catch (_a) {
60
+ await self.registration.showNotification(title, base);
61
+ }
62
+ };
63
+ const openAppWindow = async (url) => {
64
+ const target = safeAppUrl(url);
65
+ const clientList = await clients.matchAll({ type: 'window', includeUncontrolled: true });
66
+ for (const client of clientList) {
67
+ if (appUrl(client.url) && 'focus' in client) {
68
+ await client.navigate(target);
69
+ return client.focus();
70
+ }
71
+ }
72
+ return clients.openWindow ? clients.openWindow(target) : undefined;
73
+ };
74
+ const completeNotification = async (token) => {
75
+ try {
76
+ const csrfResponse = await fetch(PUSH_CSRF_URL, { method: 'GET', mode: 'same-origin', credentials: 'same-origin', redirect: 'error', cache: 'no-store' });
77
+ if (csrfResponse.status !== 200 || csrfResponse.redirected)
78
+ return false;
79
+ const csrfPayload = await csrfResponse.json();
80
+ if (!csrfPayload || typeof csrfPayload.csrf_token !== 'string' || !csrfPayload.csrf_token)
81
+ return false;
82
+ const doneResponse = await fetch(PUSH_DONE_URL, {
83
+ method: 'POST', mode: 'same-origin', credentials: 'same-origin', redirect: 'error', cache: 'no-store', referrerPolicy: 'same-origin',
84
+ headers: { 'Content-Type': 'application/json', 'X-CSRFToken': csrfPayload.csrf_token }, body: JSON.stringify({ token }),
85
+ });
86
+ return doneResponse.status === 204 && !doneResponse.redirected;
87
+ }
88
+ catch (_a) {
89
+ return false;
15
90
  }
16
91
  };
17
92
  self.addEventListener('push', (event) => {
@@ -24,26 +99,25 @@ self.addEventListener('push', (event) => {
24
99
  catch (_a) {
25
100
  payload = { body: event.data.text() };
26
101
  }
27
- const options = {
28
- body: payload.body || '',
29
- data: { url: resolveSameOriginUrl(payload.url) },
30
- };
31
- if (payload.icon)
32
- options.icon = payload.icon;
33
- if (payload.badge)
34
- options.badge = payload.badge;
35
- event.waitUntil(self.registration.showNotification(payload.title || 'Notification', options));
102
+ event.waitUntil(showPushNotification(payload && typeof payload === 'object' ? payload : {}));
36
103
  });
37
104
  self.addEventListener('notificationclick', (event) => {
38
- var _a;
39
- event.notification.close();
40
- const url = resolveSameOriginUrl((_a = event.notification.data) === null || _a === void 0 ? void 0 : _a.url);
41
- event.waitUntil(clients.matchAll({ type: 'window', includeUncontrolled: true }).then((clientList) => {
42
- for (const client of clientList) {
43
- if (client.url.includes(self.location.origin) && 'focus' in client) {
44
- return Promise.resolve(client.navigate(url)).then(() => client.focus());
45
- }
46
- }
47
- return clients.openWindow ? clients.openWindow(url) : undefined;
48
- }));
105
+ var _a, _b, _c, _d;
106
+ const { notification } = event;
107
+ if (event.action === 'done') {
108
+ const token = (_a = notification.data) === null || _a === void 0 ? void 0 : _a.doneToken;
109
+ if (!token || doneActionsInFlight.has(notification))
110
+ return;
111
+ doneActionsInFlight.add(notification);
112
+ event.waitUntil(completeNotification(token).then((completed) => { if (completed)
113
+ notification.close(); }).finally(() => doneActionsInFlight.delete(notification)));
114
+ return;
115
+ }
116
+ if (event.action && !KNOWN_ACTIONS.has(event.action))
117
+ return;
118
+ notification.close();
119
+ const target = event.action === 'open'
120
+ ? appUrl((_b = notification.data) === null || _b === void 0 ? void 0 : _b.openUrl) || safeAppUrl((_c = notification.data) === null || _c === void 0 ? void 0 : _c.url)
121
+ : (_d = notification.data) === null || _d === void 0 ? void 0 : _d.url;
122
+ event.waitUntil(openAppWindow(target));
49
123
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micha.bigler/ui-core-micha",
3
- "version": "4.41.0",
3
+ "version": "4.43.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "exports": {