@parallelworks/tandem-web 0.179.2 → 0.181.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.
@@ -0,0 +1,475 @@
1
+ import { docTemplatesQuery as e, docsQuery as t } from "../api/queries.js";
2
+ import { fromIsoDate as n, isoDate as r } from "../lib/datePhrases.js";
3
+ import { docPropertiesQuery as i, useDocPropertyActions as a } from "../lib/docProperties.js";
4
+ import { docSeriesQuery as o, useDocSeriesActions as s } from "../lib/docSeries.js";
5
+ import { docRef as c } from "../lib/docs.js";
6
+ import { useCan as l } from "../lib/roles.js";
7
+ import { readSubpageConfig as u, subpageViewsQuery as d, useSubpageActions as f } from "../lib/subpageViews.js";
8
+ import { DocIcon as p } from "./DocIcon.js";
9
+ import { SeriesMenu as m } from "./DocSeries.js";
10
+ import { AddIcon as h, CalendarIcon as g, ChevronRightIcon as _, CycleIcon as v, ListViewIcon as y, SettingsIcon as b } from "./icons.js";
11
+ import { Button as x, ErrorText as S, Input as C, Popover as w, Select as T, cx as E } from "@parallelworks/ui";
12
+ import { Link as D, useNavigate as O } from "@tanstack/react-router";
13
+ import { useMemo as k, useState as A } from "react";
14
+ import { useErrorMessage as j } from "@parallelworks/problem/react";
15
+ import { useFormatter as M, useLocale as N, useTranslations as P } from "use-intl";
16
+ import { Fragment as F, jsx as I, jsxs as L } from "react/jsx-runtime";
17
+ import { useQuery as R } from "@tanstack/react-query";
18
+ // src/components/SubpageViews.tsx
19
+ var z = (e, t) => new Date(e.getFullYear(), e.getMonth(), e.getDate() + t);
20
+ function B(e) {
21
+ let t = new Intl.Locale(e);
22
+ return (t.getWeekInfo?.().firstDay ?? t.weekInfo?.firstDay ?? 7) % 7;
23
+ }
24
+ function V({ workspace: e, doc: t, space: n }) {
25
+ let r = P("subpages"), { data: i = [] } = R(d(e, t.key)), [a, o] = A(), s = l(e, "edit_docs", n === "workspace" ? void 0 : { team: n }), c = f(e);
26
+ if (i.length === 0) return null;
27
+ let p = i.find((e) => e.id === a) ?? i[0], m = (e) => c.addView.mutate({
28
+ doc: t.key,
29
+ name: r(e === "calendar" ? "calendarView" : "feed"),
30
+ layout: e,
31
+ config: { ...u(p.config) }
32
+ }, { onSuccess: (e) => o(e.id) });
33
+ return /* @__PURE__ */ L("section", {
34
+ className: "not-prose my-4",
35
+ "aria-label": r("views"),
36
+ children: [/* @__PURE__ */ L("div", {
37
+ className: "flex items-center gap-1 border-b border-border",
38
+ children: [i.map((e) => /* @__PURE__ */ L("button", {
39
+ type: "button",
40
+ onClick: () => o(e.id),
41
+ "aria-pressed": e.id === p.id,
42
+ className: E("-mb-px flex items-center gap-1.5 border-b-2 px-2 py-1.5 text-sm", e.id === p.id ? "border-foreground font-medium" : "border-transparent text-muted-foreground hover:text-foreground"),
43
+ children: [e.layout === "feed" ? /* @__PURE__ */ I(y, { className: "size-4" }) : /* @__PURE__ */ I(g, { className: "size-4" }), e.name]
44
+ }, e.id)), s && /* @__PURE__ */ I(w, {
45
+ trigger: /* @__PURE__ */ I(x, {
46
+ size: "xs",
47
+ variant: "ghost",
48
+ "aria-label": r("addView"),
49
+ children: /* @__PURE__ */ I(h, {})
50
+ }),
51
+ align: "start",
52
+ "aria-label": r("addView"),
53
+ children: /* @__PURE__ */ L("div", {
54
+ className: "flex flex-col gap-1",
55
+ children: [/* @__PURE__ */ L(x, {
56
+ size: "sm",
57
+ variant: "ghost",
58
+ onClick: () => m("calendar"),
59
+ children: [/* @__PURE__ */ I(g, {}), r("calendarView")]
60
+ }), /* @__PURE__ */ L(x, {
61
+ size: "sm",
62
+ variant: "ghost",
63
+ onClick: () => m("feed"),
64
+ children: [/* @__PURE__ */ I(y, {}), r("feed")]
65
+ })]
66
+ })
67
+ })]
68
+ }), /* @__PURE__ */ I(H, {
69
+ workspace: e,
70
+ doc: t,
71
+ space: n,
72
+ view: p,
73
+ canWrite: s
74
+ }, p.id)]
75
+ });
76
+ }
77
+ function H({ workspace: e, doc: a, space: o, view: s, canWrite: l }) {
78
+ let d = P("subpages"), g = j(), _ = O(), v = u(s.config), { data: y = [] } = R(t(e, { parent: a.key })), { data: b = [] } = R(i(e, o)), T = b.find((e) => e.id === v.dateProperty && e.kind === "date"), [E, k] = A(""), M = f(e), N = E.trim().toLowerCase(), z = N ? y.filter((e) => e.title.toLowerCase().includes(N)) : y, B = (e) => {
79
+ let t = T && e.properties?.[T.id];
80
+ return typeof t == "string" && n(t) ? t : void 0;
81
+ }, V = z.filter((e) => !B(e)), H = (t) => M.newSubpage.mutate({
82
+ parent: a,
83
+ title: t ? d("titleOn", {
84
+ title: a.title,
85
+ date: t
86
+ }) : d("untitled"),
87
+ template: v.template,
88
+ dateProperty: T?.id,
89
+ date: t
90
+ }, { onSuccess: (t) => _({
91
+ to: "/$workspace/docs/$doc",
92
+ params: {
93
+ workspace: e,
94
+ doc: c(t)
95
+ }
96
+ }) }), K = /* @__PURE__ */ L(F, { children: [
97
+ T && s.layout === "calendar" && /* @__PURE__ */ I(w, {
98
+ trigger: /* @__PURE__ */ I(x, {
99
+ size: "xs",
100
+ variant: "ghost",
101
+ children: d("noDate", { count: V.length })
102
+ }),
103
+ align: "start",
104
+ className: "max-h-80 w-72 overflow-y-auto",
105
+ "aria-label": d("noDateTitle"),
106
+ children: V.length === 0 ? /* @__PURE__ */ I("p", {
107
+ className: "text-sm text-muted-foreground",
108
+ children: d("allDated")
109
+ }) : /* @__PURE__ */ I("ul", {
110
+ className: "space-y-1",
111
+ children: V.map((t) => /* @__PURE__ */ I("li", { children: /* @__PURE__ */ L(D, {
112
+ to: "/$workspace/docs/$doc",
113
+ params: {
114
+ workspace: e,
115
+ doc: c(t)
116
+ },
117
+ className: "flex items-center gap-1.5 truncate text-sm hover:underline",
118
+ children: [/* @__PURE__ */ I(p, { icon: t.icon }), /* @__PURE__ */ I("span", {
119
+ className: "truncate",
120
+ children: t.title
121
+ })]
122
+ }) }, t.id))
123
+ })
124
+ }),
125
+ /* @__PURE__ */ I(C, {
126
+ type: "search",
127
+ size: "sm",
128
+ value: E,
129
+ onChange: (e) => k(e.target.value),
130
+ placeholder: d("search"),
131
+ "aria-label": d("search"),
132
+ className: "w-40"
133
+ }),
134
+ l && /* @__PURE__ */ L(F, { children: [
135
+ /* @__PURE__ */ I(U, {
136
+ workspace: e,
137
+ space: o,
138
+ view: s,
139
+ config: v
140
+ }),
141
+ T && /* @__PURE__ */ I(m, {
142
+ workspace: e,
143
+ space: o,
144
+ dateProperty: T.id,
145
+ parent: {
146
+ id: a.id,
147
+ key: a.key
148
+ }
149
+ }),
150
+ /* @__PURE__ */ L(x, {
151
+ size: "xs",
152
+ variant: "primary",
153
+ loading: M.newSubpage.isPending,
154
+ onClick: () => H(T ? r(/* @__PURE__ */ new Date()) : void 0),
155
+ children: [/* @__PURE__ */ I(h, {}), d("new")]
156
+ })
157
+ ] })
158
+ ] });
159
+ return /* @__PURE__ */ L("div", {
160
+ className: "pt-2",
161
+ children: [M.newSubpage.error && /* @__PURE__ */ I(S, { children: g(M.newSubpage.error) }), s.layout === "feed" ? /* @__PURE__ */ I(G, {
162
+ workspace: e,
163
+ docs: z,
164
+ dateOf: B,
165
+ toolbar: K
166
+ }) : T ? /* @__PURE__ */ I(W, {
167
+ workspace: e,
168
+ docs: z,
169
+ dateOf: B,
170
+ toolbar: K,
171
+ parent: a,
172
+ space: o,
173
+ onNew: l ? (e) => H(e) : void 0
174
+ }) : /* @__PURE__ */ L("div", {
175
+ className: "flex flex-wrap items-center gap-2 py-3 text-sm text-muted-foreground",
176
+ children: [d("pickDate"), l && /* @__PURE__ */ I(U, {
177
+ workspace: e,
178
+ space: o,
179
+ view: s,
180
+ config: v,
181
+ open: !0
182
+ })]
183
+ })]
184
+ });
185
+ }
186
+ function U({ workspace: t, space: n, view: r, config: o, open: s }) {
187
+ let c = P("subpages"), l = j(), u = f(t), d = a(t), { data: p = [] } = R(i(t, n)), { data: m = [] } = R(e(t)), h = p.filter((e) => e.kind === "date"), g = (e) => u.updateView.mutate({
188
+ view: r,
189
+ config: { ...e }
190
+ }), _ = "block text-xs font-medium text-muted-foreground";
191
+ return /* @__PURE__ */ I(w, {
192
+ trigger: s ? /* @__PURE__ */ I(x, {
193
+ size: "xs",
194
+ children: c("settings")
195
+ }) : /* @__PURE__ */ I(x, {
196
+ size: "xs",
197
+ variant: "ghost",
198
+ "aria-label": c("settings"),
199
+ children: /* @__PURE__ */ I(b, {})
200
+ }),
201
+ align: "end",
202
+ className: "w-72",
203
+ "aria-label": c("settings"),
204
+ children: /* @__PURE__ */ L("div", {
205
+ className: "space-y-3",
206
+ children: [
207
+ /* @__PURE__ */ L("div", {
208
+ className: _,
209
+ children: [c("dateProperty"), /* @__PURE__ */ L("div", {
210
+ className: "mt-1 flex items-center gap-2",
211
+ children: [h.length > 0 && /* @__PURE__ */ I(T, {
212
+ value: o.dateProperty ?? "",
213
+ items: [{
214
+ value: "",
215
+ label: c("noDateProperty")
216
+ }, ...h.map((e) => ({
217
+ value: e.id,
218
+ label: e.name
219
+ }))],
220
+ onValueChange: (e) => g({
221
+ ...o,
222
+ dateProperty: e || void 0
223
+ }),
224
+ "aria-label": c("dateProperty"),
225
+ size: "sm"
226
+ }), /* @__PURE__ */ I(x, {
227
+ size: "xs",
228
+ loading: d.create.isPending,
229
+ onClick: async () => {
230
+ let e = await d.create.mutateAsync({
231
+ space: n,
232
+ name: c("dateName"),
233
+ kind: "date"
234
+ });
235
+ g({
236
+ ...o,
237
+ dateProperty: e.id
238
+ });
239
+ },
240
+ children: c("addDate")
241
+ })]
242
+ })]
243
+ }),
244
+ /* @__PURE__ */ L("div", {
245
+ className: _,
246
+ children: [c("template"), /* @__PURE__ */ I("div", {
247
+ className: "mt-1",
248
+ children: /* @__PURE__ */ I(T, {
249
+ value: o.template ?? "",
250
+ items: [{
251
+ value: "",
252
+ label: c("noTemplate")
253
+ }, ...m.map((e) => ({
254
+ value: e.id,
255
+ label: e.title
256
+ }))],
257
+ onValueChange: (e) => g({
258
+ ...o,
259
+ template: e || void 0
260
+ }),
261
+ "aria-label": c("template"),
262
+ size: "sm"
263
+ })
264
+ })]
265
+ }),
266
+ (u.updateView.error ?? d.create.error) && /* @__PURE__ */ I(S, { children: l(u.updateView.error ?? d.create.error) }),
267
+ /* @__PURE__ */ I(x, {
268
+ size: "xs",
269
+ variant: "danger",
270
+ onClick: () => u.removeView.mutate(r),
271
+ children: c("removeView")
272
+ })
273
+ ]
274
+ })
275
+ });
276
+ }
277
+ function W({ workspace: e, docs: t, dateOf: i, toolbar: a, parent: l, space: u, onNew: d }) {
278
+ let f = P("subpages"), m = M(), g = N(), y = O(), b = k(() => /* @__PURE__ */ new Date(), []), [S, C] = A(b), w = new Date(S.getFullYear(), S.getMonth(), 1), T = B(g), j = z(w, -((w.getDay() - T + 7) % 7)), F = new Date(S.getFullYear(), S.getMonth() + 1, 0), V = Math.ceil(((F.getTime() - j.getTime()) / 864e5 + 1) / 7), H = Array.from({ length: V * 7 }, (e, t) => z(j, t)), { data: U = [] } = R(o(e, u, r(H[0]), r(H[H.length - 1]))), W = s(e), G = k(() => {
279
+ let e = /* @__PURE__ */ new Map();
280
+ for (let n of t) {
281
+ let t = i(n);
282
+ t && e.set(t, [...e.get(t) ?? [], n]);
283
+ }
284
+ return e;
285
+ }, [t, i]), K = k(() => {
286
+ let e = /* @__PURE__ */ new Map();
287
+ for (let t of U) if (t.parentId === l.id && !t.stoppedAt) for (let n of t.upcoming ?? []) e.set(n, [...e.get(n) ?? [], t]);
288
+ return e;
289
+ }, [U, l.id]), q = r(b), J = (t) => /* @__PURE__ */ L(D, {
290
+ to: "/$workspace/docs/$doc",
291
+ params: {
292
+ workspace: e,
293
+ doc: c(t)
294
+ },
295
+ className: "flex min-w-0 items-center gap-1 rounded bg-card px-1.5 py-0.5 text-xs shadow-xs ring-1 ring-border hover:bg-accent",
296
+ children: [/* @__PURE__ */ I(p, { icon: t.icon }), /* @__PURE__ */ I("span", {
297
+ className: "truncate",
298
+ children: t.title
299
+ })]
300
+ }, t.id), Y = (t, n) => /* @__PURE__ */ L("button", {
301
+ type: "button",
302
+ disabled: !d || W.makeDoc.isPending,
303
+ onClick: () => W.makeDoc.mutate({
304
+ id: t.id,
305
+ day: n
306
+ }, { onSuccess: (t) => y({
307
+ to: "/$workspace/docs/$doc",
308
+ params: {
309
+ workspace: e,
310
+ doc: c(t)
311
+ }
312
+ }) }),
313
+ "aria-label": f("makeSeriesDoc", { series: t.title }),
314
+ className: "flex min-w-0 items-center gap-1 rounded border border-dashed border-border px-1.5 py-0.5 text-left text-xs text-muted-foreground enabled:hover:border-primary enabled:hover:text-foreground",
315
+ children: [/* @__PURE__ */ I(v, { className: "size-3 shrink-0" }), /* @__PURE__ */ I("span", {
316
+ className: "truncate",
317
+ children: t.title
318
+ })]
319
+ }, `${t.id}-${n}`), X = (e, t = !1) => d && /* @__PURE__ */ I("button", {
320
+ type: "button",
321
+ onClick: () => d(e),
322
+ "aria-label": f("newOn", { date: m.dateTime(n(e), { dateStyle: "medium" }) }),
323
+ className: E("rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:opacity-100", !t && "opacity-0 group-hover:opacity-100"),
324
+ children: /* @__PURE__ */ I(h, { className: "size-3.5" })
325
+ }), Z = (e) => e.getDay() === 0 || e.getDay() === 6, Q = (e) => e.getMonth() === S.getMonth(), $ = H.filter((e) => Q(e) && (G.has(r(e)) || K.has(r(e)) || r(e) === q));
326
+ return /* @__PURE__ */ L("div", {
327
+ className: "flex flex-col",
328
+ children: [
329
+ /* @__PURE__ */ L("div", {
330
+ className: "flex flex-wrap items-center gap-2 py-2",
331
+ children: [
332
+ /* @__PURE__ */ I("h3", {
333
+ className: "text-base font-semibold",
334
+ children: m.dateTime(w, {
335
+ month: "long",
336
+ year: "numeric"
337
+ })
338
+ }),
339
+ /* @__PURE__ */ I("span", {
340
+ className: "flex flex-wrap items-center gap-1",
341
+ children: a
342
+ }),
343
+ /* @__PURE__ */ L("span", {
344
+ className: "ml-auto flex items-center gap-1",
345
+ children: [
346
+ /* @__PURE__ */ I(x, {
347
+ size: "xs",
348
+ variant: "ghost",
349
+ onClick: () => C(new Date(S.getFullYear(), S.getMonth() - 1, 1)),
350
+ "aria-label": f("previousMonth"),
351
+ children: /* @__PURE__ */ I(_, { className: "rotate-180" })
352
+ }),
353
+ /* @__PURE__ */ I(x, {
354
+ size: "xs",
355
+ variant: "ghost",
356
+ onClick: () => C(b),
357
+ children: f("today")
358
+ }),
359
+ /* @__PURE__ */ I(x, {
360
+ size: "xs",
361
+ variant: "ghost",
362
+ onClick: () => C(new Date(S.getFullYear(), S.getMonth() + 1, 1)),
363
+ "aria-label": f("nextMonth"),
364
+ children: /* @__PURE__ */ I(_, {})
365
+ })
366
+ ]
367
+ })
368
+ ]
369
+ }),
370
+ /* @__PURE__ */ L("div", {
371
+ className: "overflow-hidden rounded-md border border-border max-sm:hidden",
372
+ children: [/* @__PURE__ */ I("div", {
373
+ className: "grid grid-cols-7 border-b border-border text-xs text-muted-foreground",
374
+ children: H.slice(0, 7).map((e) => /* @__PURE__ */ I("span", {
375
+ className: E("px-2 py-1.5", Z(e) && "bg-muted/40"),
376
+ children: m.dateTime(e, { weekday: "short" })
377
+ }, e.getDay()))
378
+ }), /* @__PURE__ */ I("ol", {
379
+ className: "grid grid-cols-7",
380
+ "aria-label": f("calendarView"),
381
+ children: H.map((e) => {
382
+ let t = r(e);
383
+ return /* @__PURE__ */ L("li", {
384
+ "aria-label": m.dateTime(e, { dateStyle: "full" }),
385
+ className: E("group flex min-h-28 min-w-0 flex-col gap-1 border-r border-b border-border p-1 [&:nth-child(7n)]:border-r-0", Z(e) && "bg-muted/40", !Q(e) && "text-muted-foreground"),
386
+ children: [
387
+ /* @__PURE__ */ L("span", {
388
+ className: "flex items-center justify-between",
389
+ children: [X(t), /* @__PURE__ */ I("span", {
390
+ className: E("ml-auto flex h-6 min-w-6 items-center justify-center whitespace-nowrap rounded-full px-1 text-xs tabular-nums", t === q && "bg-primary font-medium text-primary-foreground"),
391
+ children: e.getDate() === 1 ? m.dateTime(e, {
392
+ month: "short",
393
+ day: "numeric"
394
+ }) : e.getDate()
395
+ })]
396
+ }),
397
+ (G.get(t) ?? []).map(J),
398
+ (K.get(t) ?? []).map((e) => Y(e, t))
399
+ ]
400
+ }, t);
401
+ })
402
+ })]
403
+ }),
404
+ /* @__PURE__ */ I("ol", {
405
+ className: "divide-y divide-border rounded-md border border-border sm:hidden",
406
+ children: $.map((e) => {
407
+ let t = r(e);
408
+ return /* @__PURE__ */ L("li", {
409
+ className: "flex flex-col gap-1 px-3 py-2",
410
+ children: [
411
+ /* @__PURE__ */ L("span", {
412
+ className: "flex items-center justify-between text-xs",
413
+ children: [/* @__PURE__ */ I("span", {
414
+ className: t === q ? "font-medium text-primary" : "text-muted-foreground",
415
+ children: m.dateTime(e, {
416
+ weekday: "long",
417
+ month: "short",
418
+ day: "numeric"
419
+ })
420
+ }), X(t, !0)]
421
+ }),
422
+ (G.get(t) ?? []).map(J),
423
+ (K.get(t) ?? []).map((e) => Y(e, t))
424
+ ]
425
+ }, t);
426
+ })
427
+ })
428
+ ]
429
+ });
430
+ }
431
+ function G({ workspace: e, docs: t, dateOf: r, toolbar: i }) {
432
+ let a = P("subpages"), o = M(), s = [...t].sort((e, t) => {
433
+ let n = r(e) ?? "", i = r(t) ?? "";
434
+ return n === i ? t.updatedAt < e.updatedAt ? -1 : 1 : n < i ? 1 : -1;
435
+ });
436
+ return /* @__PURE__ */ L("div", {
437
+ className: "flex flex-col",
438
+ children: [/* @__PURE__ */ I("div", {
439
+ className: "flex flex-wrap items-center gap-1 py-2",
440
+ children: i
441
+ }), s.length === 0 ? /* @__PURE__ */ I("p", {
442
+ className: "py-3 text-sm text-muted-foreground",
443
+ children: a("none")
444
+ }) : /* @__PURE__ */ I("ul", {
445
+ className: "divide-y divide-border",
446
+ children: s.map((t) => {
447
+ let i = r(t);
448
+ return /* @__PURE__ */ I("li", { children: /* @__PURE__ */ L(D, {
449
+ to: "/$workspace/docs/$doc",
450
+ params: {
451
+ workspace: e,
452
+ doc: c(t)
453
+ },
454
+ className: "flex items-center gap-3 py-2 text-sm hover:bg-accent/40",
455
+ children: [
456
+ /* @__PURE__ */ I("span", {
457
+ className: "w-28 shrink-0 text-xs text-muted-foreground tabular-nums",
458
+ children: i ? o.dateTime(n(i), { dateStyle: "medium" }) : a("undated")
459
+ }),
460
+ /* @__PURE__ */ I(p, { icon: t.icon }),
461
+ /* @__PURE__ */ I("span", {
462
+ className: "min-w-0 flex-1 truncate font-medium",
463
+ children: t.title
464
+ }),
465
+ /* @__PURE__ */ I("span", {
466
+ className: "shrink-0 text-xs text-muted-foreground",
467
+ children: o.relativeTime(new Date(t.updatedAt))
468
+ })
469
+ ]
470
+ }) }, t.id);
471
+ })
472
+ })]
473
+ });
474
+ }
475
+ export { V as SubpageViews };