@parallelworks/tandem-web 0.164.1 → 0.166.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.
@@ -1,75 +1,84 @@
1
1
  import { basePath as e } from "./base.js";
2
2
  import { api as t, unwrap as n } from "../api/client.js";
3
3
  import { notificationsQuery as r, pushSettingsQuery as i } from "../api/queries.js";
4
- import { useCallback as a, useEffect as o, useRef as s, useState as c } from "react";
5
- import { useTranslations as l } from "use-intl";
6
- import { useMutation as u, useQuery as d, useQueryClient as f } from "@tanstack/react-query";
4
+ import { markRead as a } from "./notificationRead.js";
5
+ import { useCallback as o, useEffect as s, useRef as c, useState as l } from "react";
6
+ import { useTranslations as u } from "use-intl";
7
+ import { useMutation as d, useQuery as f, useQueryClient as p } from "@tanstack/react-query";
7
8
  // src/lib/notifications.ts
8
- function p(e) {
9
- let i = f();
10
- return u({
9
+ async function m(e, t, n, i) {
10
+ let { queryKey: o } = r(t);
11
+ await e.cancelQueries({ queryKey: o });
12
+ let s = (/* @__PURE__ */ new Date()).toISOString();
13
+ e.setQueryData(o, (e) => e && a(e, n, i, s));
14
+ }
15
+ function h(e) {
16
+ let i = p();
17
+ return d({
11
18
  mutationFn: async (r) => {
12
19
  n(await t.POST("/api/v1/notifications/read", { body: {
13
20
  workspace: e,
14
21
  ...r && { ids: r }
15
- } })), await y(r);
22
+ } })), await x(r);
16
23
  },
24
+ onMutate: (t) => m(i, e, t, !0),
17
25
  onSettled: () => i.invalidateQueries({ queryKey: r(e).queryKey })
18
26
  });
19
27
  }
20
- function m(e) {
21
- let i = f();
22
- return u({
28
+ function g(e) {
29
+ let i = p();
30
+ return d({
23
31
  mutationFn: async (r) => n(await t.POST("/api/v1/notifications/unread", { body: {
24
32
  workspace: e,
25
33
  ids: r
26
34
  } })),
35
+ onMutate: (t) => m(i, e, t, !1),
27
36
  onSettled: () => i.invalidateQueries({ queryKey: r(e).queryKey })
28
37
  });
29
38
  }
30
- function h(e) {
31
- let i = f();
32
- return u({
39
+ function _(e) {
40
+ let i = p();
41
+ return d({
33
42
  mutationFn: async (r) => {
34
43
  n(await t.POST("/api/v1/notifications/archive", { body: {
35
44
  workspace: e,
36
45
  ...r && { ids: r }
37
- } })), r && await y(r);
46
+ } })), r && await x(r);
38
47
  },
39
48
  onSettled: () => i.invalidateQueries({ queryKey: r(e).queryKey })
40
49
  });
41
50
  }
42
- function g(e, t) {
43
- let { data: n } = d(r(e)), { mutate: i } = p(e), a = s(/* @__PURE__ */ new Set()), c = t.toUpperCase(), l = (n?.notifications ?? []).filter((e) => !e.readAt && e.identifier.toUpperCase() === c && !a.current.has(e.id)).map((e) => e.id).join(",");
44
- o(() => {
51
+ function v(e, t) {
52
+ let { data: n } = f(r(e)), { mutate: i } = h(e), a = c(/* @__PURE__ */ new Set()), o = t.toUpperCase(), l = (n?.notifications ?? []).filter((e) => !e.readAt && e.identifier.toUpperCase() === o && !a.current.has(e.id)).map((e) => e.id).join(",");
53
+ s(() => {
45
54
  if (!l) return;
46
55
  let e = l.split(",");
47
56
  for (let t of e) a.current.add(t);
48
57
  i(e);
49
58
  }, [l, i]);
50
59
  }
51
- var _ = () => `${e}/`;
52
- async function v() {
53
- if ("serviceWorker" in navigator) return navigator.serviceWorker.getRegistration(_());
60
+ var y = () => `${e}/`;
61
+ async function b() {
62
+ if ("serviceWorker" in navigator) return navigator.serviceWorker.getRegistration(y());
54
63
  }
55
- async function y(e) {
56
- let t = await v();
64
+ async function x(e) {
65
+ let t = await b();
57
66
  for (let n of await t?.getNotifications() ?? []) (!e || e.includes(n.tag)) && n.close();
58
67
  }
59
- var b = () => typeof window < "u" && "serviceWorker" in navigator && "PushManager" in window && "Notification" in window;
60
- function x(e) {
68
+ var S = () => typeof window < "u" && "serviceWorker" in navigator && "PushManager" in window && "Notification" in window;
69
+ function C(e) {
61
70
  let t = e.replace(/-/g, "+").replace(/_/g, "/");
62
71
  return Uint8Array.from(atob(t + "=".repeat((4 - t.length % 4) % 4)), (e) => e.charCodeAt(0));
63
72
  }
64
- function S(e, t) {
73
+ function w(e, t) {
65
74
  let n = e.options.applicationServerKey;
66
75
  if (!n) return !1;
67
76
  let r = new Uint8Array(n);
68
77
  return r.length === t.length && r.every((e, n) => e === t[n]);
69
78
  }
70
- function C() {
71
- let e = l("notifications.push");
72
- return a(() => ({
79
+ function T() {
80
+ let e = u("notifications.push");
81
+ return o(() => ({
73
82
  title: e.raw("title"),
74
83
  decision_requested: e.raw("decision_requested"),
75
84
  assigned: e.raw("assigned"),
@@ -83,64 +92,64 @@ function C() {
83
92
  fallback: e.raw("fallback")
84
93
  }), [e]);
85
94
  }
86
- async function w(r, i) {
87
- await navigator.serviceWorker.register(`${e}/sw.js`, { scope: _() });
95
+ async function E(r, i) {
96
+ await navigator.serviceWorker.register(`${e}/sw.js`, { scope: y() });
88
97
  let a = await navigator.serviceWorker.ready;
89
98
  a.active?.postMessage({
90
99
  type: "messages",
91
100
  messages: i
92
101
  });
93
- let o = x(r), s = await a.pushManager.getSubscription();
94
- s && !S(s, o) && (await s.unsubscribe(), s = null), s ??= await a.pushManager.subscribe({
102
+ let o = C(r), s = await a.pushManager.getSubscription();
103
+ s && !w(s, o) && (await s.unsubscribe(), s = null), s ??= await a.pushManager.subscribe({
95
104
  userVisibleOnly: !0,
96
105
  applicationServerKey: o
97
106
  }), n(await t.POST("/api/v1/push/subscriptions", { body: { endpoint: s.endpoint } }));
98
107
  }
99
- function T() {
100
- let { data: e } = d(i), n = C(), [r, s] = c("off"), [l, u] = c(!1), f = a(async () => {
101
- if (!b()) return s("unsupported");
108
+ function D() {
109
+ let { data: e } = f(i), n = T(), [r, a] = l("off"), [c, u] = l(!1), d = o(async () => {
110
+ if (!S()) return a("unsupported");
102
111
  if (!e) return;
103
- if (!e.enabled) return s("unavailable");
104
- if (Notification.permission === "denied") return s("denied");
105
- let t = await (await v())?.pushManager.getSubscription();
106
- s(t && Notification.permission === "granted" ? "on" : "off");
112
+ if (!e.enabled) return a("unavailable");
113
+ if (Notification.permission === "denied") return a("denied");
114
+ let t = await (await b())?.pushManager.getSubscription();
115
+ a(t && Notification.permission === "granted" ? "on" : "off");
107
116
  }, [e]);
108
- return o(() => {
109
- f();
110
- }, [f]), {
117
+ return s(() => {
118
+ d();
119
+ }, [d]), {
111
120
  state: r,
112
- pending: l,
113
- enable: a(async () => {
121
+ pending: c,
122
+ enable: o(async () => {
114
123
  if (e?.publicKey) {
115
124
  u(!0);
116
125
  try {
117
- await Notification.requestPermission() === "granted" && await w(e.publicKey, n());
126
+ await Notification.requestPermission() === "granted" && await E(e.publicKey, n());
118
127
  } finally {
119
- u(!1), await f();
128
+ u(!1), await d();
120
129
  }
121
130
  }
122
131
  }, [
123
132
  e,
124
133
  n,
125
- f
134
+ d
126
135
  ]),
127
- disable: a(async () => {
136
+ disable: o(async () => {
128
137
  u(!0);
129
138
  try {
130
- let e = await (await v())?.pushManager.getSubscription();
139
+ let e = await (await b())?.pushManager.getSubscription();
131
140
  e && (await t.DELETE("/api/v1/push/subscriptions", { params: { query: { endpoint: e.endpoint } } }), await e.unsubscribe());
132
141
  } finally {
133
- u(!1), await f();
142
+ u(!1), await d();
134
143
  }
135
- }, [f])
144
+ }, [d])
136
145
  };
137
146
  }
138
- function E() {
139
- let { data: e } = d(i), t = C();
140
- o(() => {
141
- b() && e?.enabled && e.publicKey && Notification.permission === "granted" && v().then(async (n) => {
142
- n && await n.pushManager.getSubscription() && await w(e.publicKey, t());
147
+ function O() {
148
+ let { data: e } = f(i), t = T();
149
+ s(() => {
150
+ S() && e?.enabled && e.publicKey && Notification.permission === "granted" && b().then(async (n) => {
151
+ n && await n.pushManager.getSubscription() && await E(e.publicKey, t());
143
152
  }).catch(() => {});
144
153
  }, [e, t]);
145
154
  }
146
- export { h as useArchiveNotifications, T as usePush, E as usePushSync, g as useReadIssueNotifications, p as useReadNotifications, m as useUnreadNotifications };
155
+ export { _ as useArchiveNotifications, D as usePush, O as usePushSync, v as useReadIssueNotifications, h as useReadNotifications, g as useUnreadNotifications };
@@ -0,0 +1,7 @@
1
+ // src/lib/shortcutName.ts
2
+ function e(e) {
3
+ if (!e.metaKey && !e.ctrlKey) return e.key;
4
+ let t = e.key.length === 1 ? e.key.toLowerCase() : e.key;
5
+ return `${e.shiftKey ? "Shift+" : ""}Mod+${t}`;
6
+ }
7
+ export { e as shortcutName };
package/lib/shortcuts.js CHANGED
@@ -1,23 +1,17 @@
1
- import { useEffect as e, useRef as t } from "react";
1
+ import { shortcutName as e } from "./shortcutName.js";
2
+ import { isTextEntryContext as t } from "@parallelworks/ui";
3
+ import { useEffect as n, useRef as r } from "react";
2
4
  // src/lib/shortcuts.ts
3
- function n(e) {
4
- let t = e;
5
- return !!t && (t.isContentEditable || [
6
- "INPUT",
7
- "TEXTAREA",
8
- "SELECT"
9
- ].includes(t.tagName));
10
- }
11
- function r(r, i = !0) {
12
- let a = t(r);
13
- a.current = r, e(() => {
14
- if (!i) return;
15
- let e = (e) => {
16
- if (e.metaKey || e.ctrlKey || e.altKey || n(e.target)) return;
17
- let t = a.current[e.key];
18
- t && (e.preventDefault(), t(e));
5
+ function i(i, a = !0) {
6
+ let o = r(i);
7
+ o.current = i, n(() => {
8
+ if (!a) return;
9
+ let n = (n) => {
10
+ if (n.altKey || n.defaultPrevented || t(n.target)) return;
11
+ let r = o.current[e(n)];
12
+ r && (n.preventDefault(), r(n));
19
13
  };
20
- return window.addEventListener("keydown", e), () => window.removeEventListener("keydown", e);
21
- }, [i]);
14
+ return window.addEventListener("keydown", n), () => window.removeEventListener("keydown", n);
15
+ }, [a]);
22
16
  }
23
- export { r as useShortcuts };
17
+ export { i as useShortcuts };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parallelworks/tandem-web",
3
- "version": "0.164.1",
3
+ "version": "0.166.0",
4
4
  "description": "Tandem's pages, for a host app to render in its own",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",