@parallelworks/tandem-web 0.164.0 → 0.165.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/lib/knowledge.js CHANGED
@@ -5,23 +5,23 @@ import { areasQuery as r, docQuery as i, docsQuery as a, knowledgeQuery as o, te
5
5
  import { copyItem as l, useLinkItems as u } from "./menus.js";
6
6
  import { AreaIcon as ee, FileTextIcon as d } from "../components/icons.js";
7
7
  import { headings as te } from "./glossary.js";
8
- import { entryPath as f, kinds as ne, termRef as p } from "./knowledgeKinds.js";
9
- import { Button as m, Combobox as h, ErrorText as g, Input as _, Modal as re, Select as v, Textarea as ie, menuDivider as y } from "@parallelworks/ui";
10
- import { useCallback as b, useState as x } from "react";
11
- import { useErrorMessage as ae } from "@parallelworks/problem/react";
12
- import { useTranslations as S } from "use-intl";
13
- import { Fragment as oe, jsx as C, jsxs as w } from "react/jsx-runtime";
14
- import { keepPreviousData as se, useMutation as T, useQuery as E, useQueryClient as D, useSuspenseQuery as O } from "@tanstack/react-query";
8
+ import { entryPath as f, kinds as p, termRef as m } from "./knowledgeKinds.js";
9
+ import { Button as h, Combobox as g, ErrorText as _, Input as v, Modal as ne, Select as y, Textarea as re, menuDivider as b } from "@parallelworks/ui";
10
+ import { useCallback as x, useState as S } from "react";
11
+ import { useErrorMessage as ie } from "@parallelworks/problem/react";
12
+ import { useTranslations as C } from "use-intl";
13
+ import { Fragment as ae, jsx as w, jsxs as T } from "react/jsx-runtime";
14
+ import { keepPreviousData as oe, useMutation as E, useQuery as D, useQueryClient as O, useSuspenseQuery as k } from "@tanstack/react-query";
15
15
  // src/lib/knowledge.tsx
16
- function k(e) {
17
- let { data: t } = E(o(e));
18
- return b((e) => {
16
+ function A(e) {
17
+ let { data: t } = D(o(e));
18
+ return x((e) => {
19
19
  let n = t?.find((t) => t.id === e);
20
- return n ? p(n) : e;
20
+ return n ? m(n) : e;
21
21
  }, [t]);
22
22
  }
23
- function A(n) {
24
- let r = D(), i = () => {
23
+ function j(n) {
24
+ let r = O(), i = () => {
25
25
  r.invalidateQueries({ queryKey: [
26
26
  "workspace",
27
27
  n,
@@ -40,47 +40,47 @@ function A(n) {
40
40
  entry: e
41
41
  } });
42
42
  return {
43
- create: T({
43
+ create: E({
44
44
  mutationFn: async (r) => t(await e.POST("/api/v1/workspaces/{workspace}/knowledge", {
45
45
  params: { path: { workspace: n } },
46
46
  body: r
47
47
  })),
48
48
  onSettled: i
49
49
  }),
50
- update: T({
50
+ update: E({
51
51
  mutationFn: async ({ id: n, ...r }) => t(await e.PATCH("/api/v1/workspaces/{workspace}/knowledge/{entry}", {
52
52
  params: a(n),
53
53
  body: r
54
54
  })),
55
55
  onSettled: i
56
56
  }),
57
- supersede: T({
57
+ supersede: E({
58
58
  mutationFn: async ({ id: n, by: r }) => t(await e.POST("/api/v1/workspaces/{workspace}/knowledge/{entry}/supersede", {
59
59
  params: a(n),
60
60
  body: { by: r }
61
61
  })),
62
62
  onSettled: i
63
63
  }),
64
- archive: T({
64
+ archive: E({
65
65
  mutationFn: async (n) => t(await e.POST("/api/v1/workspaces/{workspace}/knowledge/{entry}/archive", { params: a(n) })),
66
66
  onSettled: i
67
67
  }),
68
- restore: T({
68
+ restore: E({
69
69
  mutationFn: async (n) => t(await e.POST("/api/v1/workspaces/{workspace}/knowledge/{entry}/restore", { params: a(n) })),
70
70
  onSettled: i
71
71
  })
72
72
  };
73
73
  }
74
- function j(e, t) {
75
- let r = S("knowledge"), i = S("common"), a = A(e), o = u(), s = n();
76
- return b((n) => {
77
- let c = [...o(f(e, p(n))), l(i("copyName"), n.name)], u = {
74
+ function M(e, t) {
75
+ let r = C("knowledge"), i = C("common"), a = j(e), o = u(), s = n();
76
+ return x((n) => {
77
+ let c = [...o(f(e, m(n))), l(i("copyName"), n.name)], u = {
78
78
  label: i("open"),
79
79
  onClick: () => s({
80
80
  to: "/$workspace/knowledge/$term",
81
81
  params: {
82
82
  workspace: e,
83
- term: p(n)
83
+ term: m(n)
84
84
  }
85
85
  })
86
86
  };
@@ -90,7 +90,7 @@ function j(e, t) {
90
90
  label: r("restore"),
91
91
  onClick: () => a.restore.mutate(n.id)
92
92
  },
93
- y,
93
+ b,
94
94
  ...c
95
95
  ] : [
96
96
  u,
@@ -107,19 +107,13 @@ function j(e, t) {
107
107
  id: n.id,
108
108
  status: "decided"
109
109
  })
110
- }] : n.kind === "term" ? [] : [n.status === "proposed" ? {
111
- label: r("accept"),
110
+ }] : n.status === "added" ? [{
111
+ label: r("confirm"),
112
112
  onClick: () => a.update.mutate({
113
113
  id: n.id,
114
114
  status: "decided"
115
115
  })
116
- } : {
117
- label: r("markProposed"),
118
- onClick: () => a.update.mutate({
119
- id: n.id,
120
- status: "proposed"
121
- })
122
- }],
116
+ }] : [],
123
117
  ...n.status === "superseded" ? [] : [{
124
118
  label: r("supersede"),
125
119
  onClick: () => t({
@@ -127,14 +121,13 @@ function j(e, t) {
127
121
  supersedes: n,
128
122
  defaults: {
129
123
  kind: n.kind,
130
- status: "decided",
131
124
  name: n.name
132
125
  }
133
126
  })
134
127
  }],
135
- y,
128
+ b,
136
129
  ...c,
137
- y,
130
+ b,
138
131
  {
139
132
  label: r("archive"),
140
133
  destructive: !0,
@@ -151,137 +144,122 @@ function j(e, t) {
151
144
  i
152
145
  ]);
153
146
  }
154
- function M({ workspace: e, mode: t, onClose: n, onSaved: o }) {
155
- let l = S("planning"), u = S("knowledge"), f = S("common"), p = ae(), { data: y } = O(s(e)), { data: b } = O(c(e)), T = A(e), D = t.kind === "edit" ? t.entry : void 0, k = t.kind === "create" ? t.defaults ?? {} : {}, j = t.kind === "create" ? t.supersedes : void 0, [M, ce] = x(D?.name ?? k.name ?? ""), [N, P] = x((D?.aliases ?? k.aliases ?? []).join(", ")), [F, le] = x(D?.kind ?? k.kind ?? "term"), [I, ue] = x(k.status ?? "proposed"), [L, de] = x(D?.definition ?? k.definition ?? ""), [R, fe] = x(k.team ?? y.find((e) => e.id === j?.teamId)?.key ?? ""), [z, B] = x(D?.areaId ?? ""), { data: V = [] } = E(r(e)), H = D ? D.teamId : y.find((e) => e.key === R)?.id, U = V.find((e) => e.id === z)?.key ?? "", [W, pe] = x(D?.source.doc?.key ?? k.source?.doc ?? ""), [G, K] = x(D?.source.section ?? k.source?.section ?? ""), [q, me] = x(D?.source.identifier ?? k.source?.issue ?? ""), [J, he] = x(!1), [Y, ge] = x(""), { data: _e = [] } = E({
147
+ function N({ workspace: e, mode: t, onClose: n, onSaved: o }) {
148
+ let l = C("planning"), u = C("knowledge"), f = C("common"), m = ie(), { data: b } = k(s(e)), { data: x } = k(c(e)), E = j(e), O = t.kind === "edit" ? t.entry : void 0, A = t.kind === "create" ? t.defaults ?? {} : {}, M = t.kind === "create" ? t.supersedes : void 0, [N, P] = S(O?.name ?? A.name ?? ""), [F, se] = S((O?.aliases ?? A.aliases ?? []).join(", ")), [I, ce] = S(O?.kind ?? A.kind ?? "term"), [L, le] = S(O?.definition ?? A.definition ?? ""), [R, ue] = S(A.team ?? b.find((e) => e.id === M?.teamId)?.key ?? ""), [z, B] = S(O?.areaId ?? ""), { data: V = [] } = D(r(e)), H = O ? O.teamId : b.find((e) => e.key === R)?.id, U = V.find((e) => e.id === z)?.key ?? "", [W, de] = S(O?.source.doc?.key ?? A.source?.doc ?? ""), [G, K] = S(O?.source.section ?? A.source?.section ?? ""), [q, fe] = S(O?.source.identifier ?? A.source?.issue ?? ""), [J, pe] = S(!1), [Y, me] = S(""), { data: he = [] } = D({
156
149
  ...a(e, Y ? { title: Y } : {
157
150
  top: !0,
158
151
  limit: 20
159
152
  }),
160
153
  enabled: J,
161
- placeholderData: se
162
- }), [ve, X] = x(null), { data: Z } = E({
154
+ placeholderData: oe
155
+ }), [ge, X] = S(null), { data: Z } = D({
163
156
  ...i(e, W),
164
157
  enabled: !!W
165
- }), ye = Z ?? (D?.source.doc?.key === W ? D.source.doc : void 0), Q = te(Z?.body ?? ""), $ = T.create.isPending || T.update.isPending || T.supersede.isPending, be = async () => {
158
+ }), _e = Z ?? (O?.source.doc?.key === W ? O.source.doc : void 0), Q = te(Z?.body ?? ""), $ = E.create.isPending || E.update.isPending || E.supersede.isPending, ve = async () => {
166
159
  X(null);
167
160
  let e = {
168
161
  ...W && { doc: W },
169
162
  ...W && G && { section: G },
170
- ...q.trim() && { issue: q.trim() },
171
- ...k.source?.decision && { decision: k.source.decision }
172
- }, t = N.split(",").map((e) => e.trim()).filter(Boolean);
163
+ ...q.trim() && { issue: q.trim() }
164
+ }, t = F.split(",").map((e) => e.trim()).filter(Boolean);
173
165
  try {
174
166
  let r;
175
- D ? r = await T.update.mutateAsync({
176
- id: D.id,
177
- name: M,
167
+ O ? r = await E.update.mutateAsync({
168
+ id: O.id,
169
+ name: N,
178
170
  aliases: t,
179
- kind: F,
171
+ kind: I,
180
172
  definition: L,
181
173
  ...(!z || U) && { area: U },
182
174
  source: e,
183
- ifVersion: D.version
184
- }) : (r = await T.create.mutateAsync({
185
- name: M,
175
+ ifVersion: O.version
176
+ }) : (r = await E.create.mutateAsync({
177
+ name: N,
186
178
  aliases: t,
187
- kind: F,
188
- status: I,
179
+ kind: I,
189
180
  definition: L,
190
181
  ...R && { team: R },
191
182
  ...U && { area: U },
192
183
  source: e
193
- }), j && await T.supersede.mutateAsync({
194
- id: j.id,
184
+ }), M && await E.supersede.mutateAsync({
185
+ id: M.id,
195
186
  by: r.id
196
187
  })), o?.(r), n();
197
188
  } catch (e) {
198
- X(p(e));
189
+ X(m(e));
199
190
  }
200
- }, xe = D ? u("editTitle", { name: D.name }) : j ? u("supersedeTitle", { name: j.name }) : u("newTitle");
201
- return /* @__PURE__ */ C(re, {
191
+ }, ye = O ? u("editTitle", { name: O.name }) : M ? u("supersedeTitle", { name: M.name }) : u("newTitle");
192
+ return /* @__PURE__ */ w(ne, {
202
193
  open: !0,
203
194
  onClose: n,
204
195
  dismissible: !$,
205
196
  size: "lg",
206
- title: xe,
207
- description: j ? u("supersedeHint") : void 0,
208
- onSubmit: () => be(),
209
- footer: /* @__PURE__ */ w(oe, { children: [/* @__PURE__ */ C(m, {
197
+ title: ye,
198
+ description: M ? u("supersedeHint") : void 0,
199
+ onSubmit: () => ve(),
200
+ footer: /* @__PURE__ */ T(ae, { children: [/* @__PURE__ */ w(h, {
210
201
  type: "button",
211
202
  variant: "ghost",
212
203
  onClick: n,
213
204
  children: f("cancel")
214
- }), /* @__PURE__ */ C(m, {
205
+ }), /* @__PURE__ */ w(h, {
215
206
  type: "submit",
216
207
  variant: "primary",
217
- disabled: !M.trim() || !L.trim(),
208
+ disabled: !N.trim() || !L.trim(),
218
209
  loading: $,
219
- children: j ? u("saveAndSupersede") : f("save")
210
+ children: M ? u("saveAndSupersede") : f("save")
220
211
  })] }),
221
- children: /* @__PURE__ */ w("div", {
212
+ children: /* @__PURE__ */ T("div", {
222
213
  className: "space-y-3",
223
214
  children: [
224
- /* @__PURE__ */ w("label", {
215
+ /* @__PURE__ */ T("label", {
225
216
  className: "block text-xs font-medium text-muted-foreground",
226
- children: [u("name"), /* @__PURE__ */ C(_, {
227
- value: M,
228
- onChange: (e) => ce(e.target.value),
217
+ children: [u("name"), /* @__PURE__ */ w(v, {
218
+ value: N,
219
+ onChange: (e) => P(e.target.value),
229
220
  maxLength: 100,
230
221
  required: !0,
231
222
  className: "mt-1"
232
223
  })]
233
224
  }),
234
- /* @__PURE__ */ w("label", {
225
+ /* @__PURE__ */ T("label", {
235
226
  className: "block text-xs font-medium text-muted-foreground",
236
- children: [u("aliases"), /* @__PURE__ */ C(_, {
237
- value: N,
238
- onChange: (e) => P(e.target.value),
227
+ children: [u("aliases"), /* @__PURE__ */ w(v, {
228
+ value: F,
229
+ onChange: (e) => se(e.target.value),
239
230
  placeholder: u("aliasesPlaceholder"),
240
231
  className: "mt-1"
241
232
  })]
242
233
  }),
243
- /* @__PURE__ */ w("div", {
234
+ /* @__PURE__ */ T("div", {
244
235
  className: "flex flex-wrap gap-2",
245
236
  children: [
246
- /* @__PURE__ */ C(v, {
237
+ /* @__PURE__ */ w(y, {
247
238
  "aria-label": u("kindLabel"),
248
239
  width: "content",
249
- value: F,
250
- onValueChange: le,
251
- items: ne.map((e) => ({
240
+ value: I,
241
+ onValueChange: ce,
242
+ items: p.map((e) => ({
252
243
  value: e,
253
244
  label: u(`kind.${e}`)
254
245
  }))
255
246
  }),
256
- !D && F !== "term" && /* @__PURE__ */ C(v, {
257
- "aria-label": u("statusLabel"),
258
- width: "content",
259
- value: I,
260
- onValueChange: ue,
261
- items: [{
262
- value: "proposed",
263
- label: u("status.proposed")
264
- }, {
265
- value: "decided",
266
- label: u("status.decided")
267
- }]
268
- }),
269
- !D && /* @__PURE__ */ C(v, {
247
+ !O && /* @__PURE__ */ w(y, {
270
248
  "aria-label": u("spaceLabel"),
271
249
  width: "content",
272
250
  value: R,
273
251
  onValueChange: (e) => {
274
- fe(e), B("");
252
+ ue(e), B("");
275
253
  },
276
254
  items: [{
277
255
  value: "",
278
- label: b.name
279
- }, ...y.filter((e) => !e.archivedAt).map((e) => ({
256
+ label: x.name
257
+ }, ...b.filter((e) => !e.archivedAt).map((e) => ({
280
258
  value: e.key,
281
259
  label: e.name
282
260
  }))]
283
261
  }),
284
- /* @__PURE__ */ C(h, {
262
+ /* @__PURE__ */ w(g, {
285
263
  items: [{
286
264
  value: "",
287
265
  label: l("noArea")
@@ -292,10 +270,10 @@ function M({ workspace: e, mode: t, onClose: n, onSaved: o }) {
292
270
  value: z,
293
271
  onValueChange: (e) => e !== null && B(e),
294
272
  placeholder: l("area"),
295
- trigger: /* @__PURE__ */ w(m, {
273
+ trigger: /* @__PURE__ */ T(h, {
296
274
  type: "button",
297
275
  "aria-label": l("area"),
298
- children: [/* @__PURE__ */ C(ee, { className: "size-3.5 shrink-0 text-muted-foreground" }), V.find((e) => e.id === z)?.title ?? /* @__PURE__ */ C("span", {
276
+ children: [/* @__PURE__ */ w(ee, { className: "size-3.5 shrink-0 text-muted-foreground" }), V.find((e) => e.id === z)?.title ?? /* @__PURE__ */ w("span", {
299
277
  className: "text-muted-foreground",
300
278
  children: l("noArea")
301
279
  })]
@@ -303,11 +281,11 @@ function M({ workspace: e, mode: t, onClose: n, onSaved: o }) {
303
281
  })
304
282
  ]
305
283
  }),
306
- /* @__PURE__ */ w("label", {
284
+ /* @__PURE__ */ T("label", {
307
285
  className: "block text-xs font-medium text-muted-foreground",
308
- children: [u("definition"), /* @__PURE__ */ C(ie, {
286
+ children: [u("definition"), /* @__PURE__ */ w(re, {
309
287
  value: L,
310
- onChange: (e) => de(e.target.value),
288
+ onChange: (e) => le(e.target.value),
311
289
  maxLength: 1e3,
312
290
  required: !0,
313
291
  rows: 3,
@@ -315,41 +293,41 @@ function M({ workspace: e, mode: t, onClose: n, onSaved: o }) {
315
293
  className: "mt-1"
316
294
  })]
317
295
  }),
318
- /* @__PURE__ */ w("fieldset", {
296
+ /* @__PURE__ */ T("fieldset", {
319
297
  className: "space-y-2",
320
298
  children: [
321
- /* @__PURE__ */ C("legend", {
299
+ /* @__PURE__ */ w("legend", {
322
300
  className: "text-xs font-medium text-muted-foreground",
323
301
  children: u("source")
324
302
  }),
325
- /* @__PURE__ */ w("div", {
303
+ /* @__PURE__ */ T("div", {
326
304
  className: "flex flex-wrap items-center gap-2",
327
- children: [/* @__PURE__ */ C(h, {
305
+ children: [/* @__PURE__ */ w(g, {
328
306
  open: J,
329
- onOpenChange: he,
307
+ onOpenChange: pe,
330
308
  items: [{
331
309
  value: "",
332
310
  label: u("noDoc")
333
- }, ..._e.map((e) => ({
311
+ }, ...he.map((e) => ({
334
312
  value: e.key,
335
313
  label: e.title,
336
- icon: /* @__PURE__ */ C(d, { className: "size-3.5" })
314
+ icon: /* @__PURE__ */ w(d, { className: "size-3.5" })
337
315
  }))],
338
316
  value: W,
339
317
  onValueChange: (e) => {
340
- e !== null && (pe(e), K(""));
318
+ e !== null && (de(e), K(""));
341
319
  },
342
- onQueryChange: ge,
320
+ onQueryChange: me,
343
321
  placeholder: u("chooseDoc"),
344
- trigger: /* @__PURE__ */ w(m, {
322
+ trigger: /* @__PURE__ */ T(h, {
345
323
  type: "button",
346
324
  className: "max-w-56",
347
- children: [/* @__PURE__ */ C(d, { className: "size-3.5 text-muted-foreground" }), /* @__PURE__ */ C("span", {
325
+ children: [/* @__PURE__ */ w(d, { className: "size-3.5 text-muted-foreground" }), /* @__PURE__ */ w("span", {
348
326
  className: "truncate",
349
- children: ye?.title ?? u("chooseDoc")
327
+ children: _e?.title ?? u("chooseDoc")
350
328
  })]
351
329
  })
352
- }), W && /* @__PURE__ */ C(v, {
330
+ }), W && /* @__PURE__ */ w(y, {
353
331
  "aria-label": u("section"),
354
332
  width: "content",
355
333
  value: G,
@@ -370,18 +348,18 @@ function M({ workspace: e, mode: t, onClose: n, onSaved: o }) {
370
348
  ]
371
349
  })]
372
350
  }),
373
- /* @__PURE__ */ C(_, {
351
+ /* @__PURE__ */ w(v, {
374
352
  value: q,
375
- onChange: (e) => me(e.target.value),
353
+ onChange: (e) => fe(e.target.value),
376
354
  placeholder: u("issuePlaceholder"),
377
355
  "aria-label": u("issue"),
378
356
  className: "max-w-40"
379
357
  })
380
358
  ]
381
359
  }),
382
- /* @__PURE__ */ C(g, { children: ve })
360
+ /* @__PURE__ */ w(_, { children: ge })
383
361
  ]
384
362
  })
385
363
  });
386
364
  }
387
- export { M as EntryDialog, A as useKnowledgeActions, j as useKnowledgeMenu, k as useTermRefs };
365
+ export { N as EntryDialog, j as useKnowledgeActions, M as useKnowledgeMenu, A as useTermRefs };
@@ -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.0",
3
+ "version": "0.165.0",
4
4
  "description": "Tandem's pages, for a host app to render in its own",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",