@parallelworks/tandem-web 0.191.1 → 0.192.1

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.
@@ -0,0 +1,374 @@
1
+ import { api as e, unwrap as t } from "../api/client.js";
2
+ import { docCommentsQuery as n, docTemplatesQuery as r } from "../api/queries.js";
3
+ import { fromIsoDate as i } from "../lib/datePhrases.js";
4
+ import { docPropertiesQuery as a, spaceScope as o } from "../lib/docProperties.js";
5
+ import { docSeriesQuery as ee } from "../lib/docSeries.js";
6
+ import { docRef as s, docURL as te, useDocMenu as ne } from "../lib/docs.js";
7
+ import { usePeople as re } from "../lib/people.js";
8
+ import { useCan as ie } from "../lib/roles.js";
9
+ import { openShare as ae } from "../lib/share.js";
10
+ import { AddProperty as oe, PropertyField as se } from "./DocProperties.js";
11
+ import { Editor as c } from "./Editor.js";
12
+ import { FavoriteStar as l } from "./FavoriteStar.js";
13
+ import { AddIcon as ce, ExpandIcon as le, FileTextIcon as ue, LinkIcon as de } from "./icons.js";
14
+ import { Button as fe, ErrorText as pe, IconButton as u, Modal as me, cx as he, toast as ge, useOpenMenu as _e } from "@parallelworks/ui";
15
+ import { useNavigate as ve } from "@tanstack/react-router";
16
+ import { useEffect as ye, useRef as d, useState as f } from "react";
17
+ import { useErrorMessage as be } from "@parallelworks/problem/react";
18
+ import { useFormatter as xe, useTranslations as p } from "use-intl";
19
+ import { jsx as m, jsxs as h } from "react/jsx-runtime";
20
+ import { useMutation as g, useQuery as _, useQueryClient as Se } from "@tanstack/react-query";
21
+ import { MoreIcon as Ce, ShareIcon as we } from "@parallelworks/ui/icons";
22
+ // src/components/NewPageModal.tsx
23
+ var Te = 400;
24
+ function v({ workspace: v, parent: y, space: b, day: x, dateProperty: S, viewTemplate: C, onClose: w }) {
25
+ let T = p("newPage"), E = p("subpages"), D = xe(), O = be(), k = Se(), A = ve(), Ee = _e(), De = ne(v), { nameOf: Oe } = re(v), ke = ie(v, "manage_labels", o(b)), { data: Ae = [] } = _(a(v, b)), { data: je = [] } = _(r(v)), { data: Me = [] } = _(ee(v, b, x, x)), [j, M] = f(), N = d(void 0), [P, Ne] = f(""), F = d(""), [I, Pe] = f(S ? { [S]: x } : {}), L = d(I), [R, Fe] = f(!1), [z, B] = f(-1), [V, H] = f(""), [U, Ie] = f(), { data: Le = [] } = _({
26
+ ...n(v, j?.key ?? ""),
27
+ enabled: !!j
28
+ }), W = () => k.invalidateQueries({ queryKey: [
29
+ "workspace",
30
+ v,
31
+ "docs"
32
+ ] }), G = (e) => ({ path: {
33
+ workspace: v,
34
+ doc: e
35
+ } }), K = { date: D.dateTime(i(x), { dateStyle: "long" }) }, q = [
36
+ ...je.filter((e) => e.starter || !e.teamId || e.teamId === y.teamId).sort((e, t) => Number(t.id === C) - Number(e.id === C)).map((e) => ({
37
+ kind: "template",
38
+ id: e.id,
39
+ label: e.title
40
+ })),
41
+ ...Me.filter((e) => e.parentId === y.id && !e.stoppedAt && e.template).map((e) => ({
42
+ kind: "series",
43
+ series: e,
44
+ label: e.title
45
+ })),
46
+ {
47
+ kind: "empty",
48
+ label: T("empty")
49
+ }
50
+ ], J = (e) => j ? Promise.resolve(j) : (N.current ??= Re(e).then((e) => (M(e), W(), e), (e) => {
51
+ throw N.current = void 0, e;
52
+ }), N.current), Re = async (n) => {
53
+ let r = P.trim();
54
+ F.current = r;
55
+ let i;
56
+ if (n?.kind === "series" && n.series.upcoming?.includes(x)) i = t(await e.POST("/api/v1/workspaces/{workspace}/doc-series/{series}/docs", {
57
+ params: { path: {
58
+ workspace: v,
59
+ series: n.series.id
60
+ } },
61
+ body: { day: x }
62
+ })), r && (i = t(await e.PATCH("/api/v1/workspaces/{workspace}/docs/{doc}", {
63
+ params: G(i.key),
64
+ body: { title: r }
65
+ })));
66
+ else {
67
+ let a = n?.kind === "template" ? n.id : n?.kind === "series" ? n.series.template : void 0, o = n?.kind === "series" ? n.series.title : E("untitled");
68
+ i = t(await e.POST("/api/v1/workspaces/{workspace}/docs", {
69
+ params: { path: { workspace: v } },
70
+ body: {
71
+ parent: y.key,
72
+ ...r || n?.kind !== "template" ? { title: r || o } : {},
73
+ ...a && {
74
+ template: a,
75
+ variables: K
76
+ }
77
+ }
78
+ }));
79
+ }
80
+ let a = Object.fromEntries(Object.entries(L.current).filter(([, e]) => e != null && e !== ""));
81
+ if (Object.keys(a).length > 0) {
82
+ let { properties: n } = t(await e.PATCH("/api/v1/workspaces/{workspace}/docs/{doc}/properties", {
83
+ params: G(i.key),
84
+ body: { values: a }
85
+ }));
86
+ i = {
87
+ ...i,
88
+ properties: n
89
+ };
90
+ }
91
+ return i;
92
+ }, Y = (e) => e.catch((e) => {
93
+ Ie(e);
94
+ });
95
+ ye(() => {
96
+ let n = P.trim();
97
+ if (n === F.current) return;
98
+ let r = setTimeout(() => {
99
+ (n || j) && Y(J().then(async (r) => {
100
+ n !== F.current && (F.current = n, M(t(await e.PATCH("/api/v1/workspaces/{workspace}/docs/{doc}", {
101
+ params: G(r.key),
102
+ body: { title: n || E("untitled") }
103
+ }))), W());
104
+ }));
105
+ }, Te);
106
+ return () => clearTimeout(r);
107
+ });
108
+ let X = (n) => {
109
+ Fe(!0), B(-1), Y((async () => {
110
+ if (!j && !N.current) {
111
+ await J(n);
112
+ return;
113
+ }
114
+ let r = await J(), i = n.kind === "template" ? n.id : n.kind === "series" ? n.series.template : void 0;
115
+ if (!i) return;
116
+ let a = t(await e.PATCH("/api/v1/workspaces/{workspace}/docs/{doc}", {
117
+ params: G(r.key),
118
+ body: {
119
+ startFrom: i,
120
+ variables: K
121
+ }
122
+ }));
123
+ F.current && a.title !== F.current && (a = t(await e.PATCH("/api/v1/workspaces/{workspace}/docs/{doc}", {
124
+ params: G(r.key),
125
+ body: { title: F.current }
126
+ }))), M(a), W();
127
+ })());
128
+ }, ze = (n, r) => {
129
+ L.current = {
130
+ ...L.current,
131
+ [n]: r
132
+ }, Pe(L.current), Y((async () => {
133
+ if (!j && !N.current) {
134
+ await J();
135
+ return;
136
+ }
137
+ let i = await J(), { properties: a } = t(await e.PATCH("/api/v1/workspaces/{workspace}/docs/{doc}/properties", {
138
+ params: G(i.key),
139
+ body: { values: { [n]: r } }
140
+ }));
141
+ M((e) => e ? {
142
+ ...e,
143
+ properties: a
144
+ } : {
145
+ ...i,
146
+ properties: a
147
+ }), W();
148
+ })());
149
+ }, Be = (r) => {
150
+ r.preventDefault();
151
+ let i = V.trim();
152
+ i && (H(""), Y(J().then(async (r) => {
153
+ t(await e.POST("/api/v1/workspaces/{workspace}/docs/{doc}/comments", {
154
+ params: G(r.key),
155
+ body: { body: i }
156
+ })), await k.invalidateQueries({ queryKey: n(v, r.key).queryKey });
157
+ })));
158
+ }, Ve = () => {
159
+ let t = P.trim();
160
+ t && t !== F.current && J().then(async (n) => {
161
+ t !== F.current && (await e.PATCH("/api/v1/workspaces/{workspace}/docs/{doc}", {
162
+ params: G(n.key),
163
+ body: { title: t }
164
+ }), W());
165
+ }), w();
166
+ }, Z = (e) => () => {
167
+ Y(J().then(e));
168
+ }, Q = Z((e) => {
169
+ w(), A({
170
+ to: "/$workspace/docs/$doc",
171
+ params: {
172
+ workspace: v,
173
+ doc: s(e)
174
+ }
175
+ });
176
+ }), He = Z((e) => ae({
177
+ doc: e.key,
178
+ title: e.title
179
+ })), Ue = Z((e) => {
180
+ navigator.clipboard.writeText(te(v, e)).then(() => ge.success(T("linkCopied")));
181
+ }), $ = g({
182
+ mutationFn: async () => {
183
+ let n = t(await e.POST("/api/v1/workspaces/{workspace}/docs", {
184
+ params: { path: { workspace: v } },
185
+ body: {
186
+ title: T("newTemplateTitle"),
187
+ ...b !== "workspace" && { team: b }
188
+ }
189
+ }));
190
+ return t(await e.PATCH("/api/v1/workspaces/{workspace}/docs/{doc}", {
191
+ params: G(n.key),
192
+ body: { template: !0 }
193
+ }));
194
+ },
195
+ onSuccess: (e) => {
196
+ W(), w(), A({
197
+ to: "/$workspace/docs/$doc",
198
+ params: {
199
+ workspace: v,
200
+ doc: s(e)
201
+ }
202
+ });
203
+ }
204
+ }), We = (e) => {
205
+ if (R) e.key === "Enter" && e.preventDefault();
206
+ else if (e.key === "ArrowDown") e.preventDefault(), B((e) => Math.min(e + 1, q.length - 1));
207
+ else if (e.key === "ArrowUp") e.preventDefault(), B((e) => Math.max(e - 1, -1));
208
+ else if (e.key === "Enter") {
209
+ e.preventDefault();
210
+ let t = q[z] ?? q[q.length - 1];
211
+ t && X(t);
212
+ }
213
+ }, Ge = {
214
+ ...I,
215
+ ...j?.properties ?? {}
216
+ };
217
+ return /* @__PURE__ */ h(me, {
218
+ open: !0,
219
+ onClose: Ve,
220
+ align: "center",
221
+ "aria-label": P.trim() || T("title"),
222
+ className: "flex max-h-[85vh] w-[min(900px,calc(100vw-2rem))] flex-col overflow-hidden",
223
+ children: [/* @__PURE__ */ h("div", {
224
+ className: "flex h-11 shrink-0 items-center gap-1 border-b border-border px-3",
225
+ children: [/* @__PURE__ */ m(u, {
226
+ size: "sm",
227
+ variant: "ghost",
228
+ icon: /* @__PURE__ */ m(le, {}),
229
+ label: T("openFull"),
230
+ onClick: Q
231
+ }), /* @__PURE__ */ h("span", {
232
+ className: "ml-auto flex items-center gap-1",
233
+ children: [
234
+ /* @__PURE__ */ m(fe, {
235
+ size: "sm",
236
+ variant: "ghost",
237
+ icon: /* @__PURE__ */ m(we, {}),
238
+ onClick: He,
239
+ children: T("share")
240
+ }),
241
+ /* @__PURE__ */ m(u, {
242
+ size: "sm",
243
+ variant: "ghost",
244
+ icon: /* @__PURE__ */ m(de, {}),
245
+ label: T("copyLink"),
246
+ onClick: Ue
247
+ }),
248
+ j && /* @__PURE__ */ m(l, {
249
+ workspace: v,
250
+ kind: "doc",
251
+ target: j.id
252
+ }),
253
+ /* @__PURE__ */ m(u, {
254
+ size: "sm",
255
+ variant: "ghost",
256
+ icon: /* @__PURE__ */ m(Ce, {}),
257
+ label: T("more"),
258
+ disabled: !j,
259
+ onClick: (e) => j && Ee(e.currentTarget, De(j))
260
+ })
261
+ ]
262
+ })]
263
+ }), /* @__PURE__ */ h("div", {
264
+ className: "min-h-0 flex-1 overflow-y-auto px-10 pt-8 pb-6 max-sm:px-5",
265
+ children: [
266
+ /* @__PURE__ */ m("textarea", {
267
+ autoFocus: !0,
268
+ rows: 1,
269
+ value: P,
270
+ onChange: (e) => Ne(e.target.value.replace(/\n/g, "")),
271
+ onKeyDown: We,
272
+ placeholder: T("title"),
273
+ "aria-label": T("titleLabel"),
274
+ className: "w-full resize-none bg-transparent text-3xl font-bold outline-none placeholder:text-muted-foreground/60"
275
+ }),
276
+ /* @__PURE__ */ h("section", {
277
+ "aria-label": T("properties"),
278
+ className: "mt-3 space-y-0.5 text-sm",
279
+ children: [Ae.map((e) => /* @__PURE__ */ h("div", {
280
+ className: "flex min-h-8 items-center gap-2",
281
+ children: [/* @__PURE__ */ m("span", {
282
+ className: "w-36 shrink-0 truncate text-muted-foreground",
283
+ children: e.name
284
+ }), /* @__PURE__ */ m("div", {
285
+ className: "min-w-0 flex-1",
286
+ children: /* @__PURE__ */ m(se, {
287
+ workspace: v,
288
+ property: e,
289
+ value: Ge[e.id],
290
+ editable: !0,
291
+ onChange: (t) => ze(e.id, t)
292
+ })
293
+ })]
294
+ }, e.id)), ke && /* @__PURE__ */ m(oe, {
295
+ workspace: v,
296
+ space: b,
297
+ unset: [],
298
+ admin: !0,
299
+ onPick: () => {}
300
+ })]
301
+ }),
302
+ j?.body?.trim() && /* @__PURE__ */ m("div", {
303
+ className: "mt-6 border-t border-border pt-4",
304
+ children: /* @__PURE__ */ m(c, {
305
+ value: j.body,
306
+ editable: !1
307
+ })
308
+ }),
309
+ /* @__PURE__ */ h("section", {
310
+ "aria-label": T("discussions"),
311
+ className: "mt-6",
312
+ children: [
313
+ /* @__PURE__ */ m("h3", {
314
+ className: "mb-2 text-sm font-medium text-muted-foreground",
315
+ children: T("discussions")
316
+ }),
317
+ Le.filter((e) => !e.parentId && !e.deletedAt).map((e) => /* @__PURE__ */ h("p", {
318
+ className: "mb-1 text-sm",
319
+ children: [
320
+ /* @__PURE__ */ m("span", {
321
+ className: "font-medium",
322
+ children: Oe(e.author.kind, e.author.handle)
323
+ }),
324
+ " ",
325
+ e.body
326
+ ]
327
+ }, e.id)),
328
+ /* @__PURE__ */ m("form", {
329
+ onSubmit: Be,
330
+ children: /* @__PURE__ */ m("input", {
331
+ value: V,
332
+ onChange: (e) => H(e.target.value),
333
+ placeholder: T("addComment"),
334
+ "aria-label": T("addComment"),
335
+ className: "h-9 w-full rounded-md bg-transparent px-2 text-sm outline-none placeholder:text-muted-foreground hover:bg-muted focus:bg-muted"
336
+ })
337
+ })
338
+ ]
339
+ }),
340
+ !R && /* @__PURE__ */ h("section", {
341
+ "aria-label": T("templates"),
342
+ className: "mt-6 border-t border-border pt-4",
343
+ children: [/* @__PURE__ */ m("p", {
344
+ className: "mb-2 text-sm text-muted-foreground",
345
+ children: T("hint")
346
+ }), /* @__PURE__ */ h("ul", {
347
+ className: "space-y-0.5",
348
+ children: [q.map((e, t) => /* @__PURE__ */ m("li", { children: /* @__PURE__ */ h("button", {
349
+ type: "button",
350
+ "aria-current": t === z || void 0,
351
+ onMouseEnter: () => B(t),
352
+ onClick: () => X(e),
353
+ className: he("flex h-8 w-full items-center gap-2 rounded-md px-2 text-left text-sm", t === z ? "bg-muted" : "hover:bg-muted"),
354
+ children: [/* @__PURE__ */ m(ue, { className: "size-4 shrink-0 text-muted-foreground" }), /* @__PURE__ */ m("span", {
355
+ className: "truncate",
356
+ children: e.label
357
+ })]
358
+ }) }, e.kind === "template" ? e.id : e.kind === "series" ? e.series.id : "empty")), /* @__PURE__ */ m("li", { children: /* @__PURE__ */ h("button", {
359
+ type: "button",
360
+ onClick: () => $.mutate(),
361
+ className: "flex h-8 w-full items-center gap-2 rounded-md px-2 text-left text-sm text-muted-foreground hover:bg-muted",
362
+ children: [/* @__PURE__ */ m(ce, { className: "size-4 shrink-0" }), T("newTemplate")]
363
+ }) })]
364
+ })]
365
+ }),
366
+ (U || $.error) && /* @__PURE__ */ m(pe, {
367
+ className: "mt-3",
368
+ children: O(U ?? $.error)
369
+ })
370
+ ]
371
+ })]
372
+ });
373
+ }
374
+ export { v as NewPageModal };