@parallelworks/tandem-web 0.192.2 → 0.193.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/docs.js CHANGED
@@ -1,26 +1,26 @@
1
1
  import { api as e, unwrap as t } from "../api/client.js";
2
- import { docTemplatesQuery as n, docsQuery as r, meQuery as i, teamsQuery as a } from "../api/queries.js";
3
- import { appURL as o, basePath as s } from "./base.js";
4
- import { useFavorites as c } from "./favorites.js";
5
- import { copyItem as l, useLinkItems as u } from "./menus.js";
6
- import { useNavigate as d } from "./router.js";
7
- import { openShare as f } from "./share.js";
8
- import { useSubpageActions as p } from "./subpageViews.js";
9
- import { menuDivider as m } from "@parallelworks/ui";
10
- import { useCallback as h } from "react";
11
- import { useFormatter as g, useTranslations as _ } from "use-intl";
12
- import { useMutation as v, useQuery as y, useQueryClient as b } from "@tanstack/react-query";
2
+ import { docTemplatesQuery as n, docsQuery as r, meQuery as i, permissionsQuery as a, teamsQuery as o } from "../api/queries.js";
3
+ import { appURL as s, basePath as c } from "./base.js";
4
+ import { useFavorites as l } from "./favorites.js";
5
+ import { copyItem as u, menuOpenedOn as d, menuOpenerProps as f, useLinkItems as p } from "./menus.js";
6
+ import { useNavigate as m } from "./router.js";
7
+ import { openShare as h } from "./share.js";
8
+ import { useSubpageActions as g } from "./subpageViews.js";
9
+ import { menuDivider as _, toast as v, useMenuOpenedBy as y, useOpenMenu as b } from "@parallelworks/ui";
10
+ import { useCallback as x, useRef as S, useSyncExternalStore as C } from "react";
11
+ import { useFormatter as w, useTranslations as T } from "use-intl";
12
+ import { useMutation as E, useQueries as D, useQuery as O, useQueryClient as k } from "@tanstack/react-query";
13
13
  // src/lib/docs.tsx
14
- function x(e) {
14
+ function A(e) {
15
15
  return e.ref || (e.slug ? `${e.slug}-${e.key}` : e.key);
16
16
  }
17
- function S(e) {
17
+ function j(e) {
18
18
  let t = (e.split("-").pop() ?? e).toLowerCase();
19
19
  return /^[a-z2-7]{10}$/.test(t) ? t : e.toLowerCase();
20
20
  }
21
- function C() {
22
- let e = g(), { data: t } = y(i);
23
- return h(() => {
21
+ function M() {
22
+ let e = w(), { data: t } = O(i);
23
+ return x(() => {
24
24
  let n = /* @__PURE__ */ new Date();
25
25
  return {
26
26
  date: e.dateTime(n, { dateStyle: "long" }),
@@ -29,20 +29,20 @@ function C() {
29
29
  };
30
30
  }, [e, t]);
31
31
  }
32
- function w(e, t) {
33
- return `/${e}/docs/${x(t)}`;
32
+ function N(e, t) {
33
+ return `/${e}/docs/${A(t)}`;
34
34
  }
35
- function T(r) {
36
- let i = b(), o = d(), s = _("docs"), c = () => i.invalidateQueries({ queryKey: [
35
+ function P(r) {
36
+ let i = k(), a = m(), s = T("docs"), c = () => i.invalidateQueries({ queryKey: [
37
37
  "workspace",
38
38
  r,
39
39
  "docs"
40
40
  ] }), l = (e) => ({ path: {
41
41
  workspace: r,
42
42
  doc: e
43
- } }), u = C(), f = v({
43
+ } }), u = M(), d = E({
44
44
  mutationFn: async ({ team: n, parent: i, template: a }) => {
45
- let o = a ?? await S(n, i);
45
+ let o = a ?? await v(n, i);
46
46
  return t(await e.POST("/api/v1/workspaces/{workspace}/docs", {
47
47
  params: { path: { workspace: r } },
48
48
  body: {
@@ -56,28 +56,28 @@ function T(r) {
56
56
  }));
57
57
  },
58
58
  onSuccess: (e) => {
59
- c(), o({
59
+ c(), a({
60
60
  to: "/$workspace/docs/$doc",
61
61
  params: {
62
62
  workspace: r,
63
- doc: x(e)
63
+ doc: A(e)
64
64
  },
65
65
  search: { rename: !0 }
66
66
  });
67
67
  }
68
- }), p = v({
68
+ }), f = E({
69
69
  mutationFn: async ({ doc: n, title: r }) => t(await e.PATCH("/api/v1/workspaces/{workspace}/docs/{doc}", {
70
70
  params: l(n.key),
71
71
  body: { title: r }
72
72
  })),
73
73
  onSettled: c
74
- }), m = v({
74
+ }), p = E({
75
75
  mutationFn: async ({ doc: n, area: r }) => t(await e.PATCH("/api/v1/workspaces/{workspace}/docs/{doc}", {
76
76
  params: l(n.key),
77
77
  body: { area: r }
78
78
  })),
79
79
  onSettled: c
80
- }), h = v({
80
+ }), h = E({
81
81
  mutationFn: async ({ doc: n, space: r, parent: i, after: a, before: o }) => t(await e.POST("/api/v1/workspaces/{workspace}/docs/{doc}/move", {
82
82
  params: l(n.key),
83
83
  body: {
@@ -88,16 +88,16 @@ function T(r) {
88
88
  }
89
89
  })),
90
90
  onSettled: c
91
- }), g = v({
91
+ }), g = E({
92
92
  mutationFn: async (n) => t(await e.POST("/api/v1/workspaces/{workspace}/docs/{doc}/archive", { params: l(n.key) })),
93
93
  onSettled: c
94
- }), y = v({
94
+ }), _ = E({
95
95
  mutationFn: async (n) => t(await e.POST("/api/v1/workspaces/{workspace}/docs/{doc}/restore", { params: l(n.key) })),
96
96
  onSettled: c
97
- }), S = async (e, t) => {
98
- let [o, s] = await Promise.all([i.fetchQuery(n(r)), i.fetchQuery(a(r))]), c = t ? t.teamId ?? "" : s.find((t) => t.key === e)?.id ?? "";
99
- return o.find((e) => e.spaceDefault && (e.teamId ?? "") === c)?.id;
100
- }, w = v({
97
+ }), v = async (e, t) => {
98
+ let [a, s] = await Promise.all([i.fetchQuery(n(r)), i.fetchQuery(o(r))]), c = t ? t.teamId ?? "" : s.find((t) => t.key === e)?.id ?? "";
99
+ return a.find((e) => e.spaceDefault && (e.teamId ?? "") === c)?.id;
100
+ }, y = E({
101
101
  mutationFn: async ({ doc: n, spaceDefault: r }) => t(await e.PATCH("/api/v1/workspaces/{workspace}/docs/{doc}", {
102
102
  params: l(n.key),
103
103
  body: { spaceDefault: r }
@@ -105,21 +105,21 @@ function T(r) {
105
105
  onSettled: c
106
106
  });
107
107
  return {
108
- create: f,
109
- rename: p,
110
- fileUnder: m,
108
+ create: d,
109
+ rename: f,
110
+ fileUnder: p,
111
111
  move: h,
112
112
  archive: g,
113
- restore: y,
114
- setTemplate: v({
113
+ restore: _,
114
+ setTemplate: E({
115
115
  mutationFn: async ({ doc: n, template: r }) => t(await e.PATCH("/api/v1/workspaces/{workspace}/docs/{doc}", {
116
116
  params: l(n.key),
117
117
  body: { template: r }
118
118
  })),
119
119
  onSettled: c
120
120
  }),
121
- setSpaceDefault: w,
122
- setLook: v({
121
+ setSpaceDefault: y,
122
+ setLook: E({
123
123
  mutationFn: async ({ doc: n, ...r }) => t(await e.PATCH("/api/v1/workspaces/{workspace}/docs/{doc}", {
124
124
  params: l(n.key),
125
125
  body: r
@@ -136,7 +136,7 @@ function T(r) {
136
136
  },
137
137
  onSettled: c
138
138
  }),
139
- duplicate: v({
139
+ duplicate: E({
140
140
  mutationFn: async ({ doc: n, team: i }) => {
141
141
  let a = t(await e.GET("/api/v1/workspaces/{workspace}/docs/{doc}", { params: l(n.key) })), o = a.ancestors?.at(-1)?.key, c = t(await e.POST("/api/v1/workspaces/{workspace}/docs", {
142
142
  params: { path: { workspace: r } },
@@ -153,11 +153,11 @@ function T(r) {
153
153
  })) : c;
154
154
  },
155
155
  onSuccess: (e) => {
156
- c(), o({
156
+ c(), a({
157
157
  to: "/$workspace/docs/$doc",
158
158
  params: {
159
159
  workspace: r,
160
- doc: x(e)
160
+ doc: A(e)
161
161
  },
162
162
  search: { rename: !0 }
163
163
  });
@@ -165,157 +165,227 @@ function T(r) {
165
165
  })
166
166
  };
167
167
  }
168
- function E(e) {
169
- let t = d(), n = _("docs"), i = _("common"), o = _("favorites"), s = u(), g = c(e), v = T(e), b = p(e), S = _("subpages"), { data: C = [] } = y(a(e)), { data: E = [] } = y(r(e, { top: !0 }));
170
- return h((r, { onRename: a } = {}) => {
171
- let c = C.find((e) => e.id === r.teamId), u = c?.key ?? "workspace", d = {
172
- label: i("open"),
168
+ function F(e) {
169
+ let { data: t } = O(i), { data: n = [] } = O(o(e)), r = D({
170
+ queries: n.map((t) => a(e, { team: t.key })),
171
+ combine: (e) => e.map((e) => e.data)
172
+ }), s = t?.workspaces.find((t) => t.slug === e)?.permissions;
173
+ return x((e) => {
174
+ let t = n.findIndex((t) => t.id === e.teamId);
175
+ return ((t >= 0 ? r[t] : void 0) ?? s ?? []).includes("edit_docs");
176
+ }, [
177
+ n,
178
+ r,
179
+ s
180
+ ]);
181
+ }
182
+ var I = null, L = /* @__PURE__ */ new Set(), R = (e) => {
183
+ I = e;
184
+ for (let e of L) e();
185
+ };
186
+ function z() {
187
+ return [C((e) => (L.add(e), () => L.delete(e)), () => I), () => R(null)];
188
+ }
189
+ function B(e) {
190
+ let t = m(), n = k(), i = T("docs"), a = T("common"), s = T("favorites"), c = p(), f = l(e), b = P(e), C = g(e), w = T("subpages"), E = F(e), { data: D = [] } = O(o(e)), { data: j = [] } = O(r(e, { top: !0 })), M = y(), I = S(null);
191
+ return I.current = M, x((o, { onRename: l } = {}) => {
192
+ let p = D.find((e) => e.id === o.teamId), m = p?.key ?? "workspace", g = {
193
+ label: a("open"),
173
194
  onClick: () => t({
174
195
  to: "/$workspace/docs/$doc",
175
196
  params: {
176
197
  workspace: e,
177
- doc: x(r)
198
+ doc: A(o)
178
199
  }
179
200
  })
180
- }, p = [...s(w(e, r)), l(n("copyKey"), r.key)];
181
- if (r.archivedAt) return [
182
- d,
201
+ }, [y, x] = c(N(e, o)), S = u(i("copyKey"), o.key), T = [
202
+ y,
203
+ x,
204
+ S
205
+ ];
206
+ if (!E(o)) return [
207
+ g,
208
+ y,
209
+ x
210
+ ];
211
+ if (o.archivedAt) return [
212
+ g,
183
213
  {
184
- label: n("restore"),
185
- onClick: () => v.restore.mutate(r)
214
+ label: i("restore"),
215
+ onClick: () => b.restore.mutate(o)
186
216
  },
187
- m,
188
- ...p
217
+ _,
218
+ ...T
189
219
  ];
190
- let h = E.filter((e) => e.id !== r.id), _ = [{
220
+ let O = n.getQueryData(r(e).queryKey);
221
+ O || n.prefetchQuery(r(e));
222
+ let k = /* @__PURE__ */ new Set([o.id]);
223
+ for (let e = !0; e;) {
224
+ e = !1;
225
+ for (let t of O ?? []) t.parentId && k.has(t.parentId) && !k.has(t.id) && (k.add(t.id), e = !0);
226
+ }
227
+ let M = (O ?? j).filter((e) => !k.has(e.id)), P = [{
191
228
  key: "workspace",
192
- name: n("workspaceSpace")
193
- }, ...C.filter((e) => !e.archivedAt).map((e) => ({
229
+ name: i("workspaceSpace")
230
+ }, ...D.filter((e) => !e.archivedAt).map((e) => ({
194
231
  key: e.key,
195
232
  name: e.name
196
- }))];
233
+ }))], F = (e) => D.find((t) => t.id === e.teamId)?.key;
197
234
  return [
198
- d,
235
+ g,
236
+ y,
237
+ _,
199
238
  {
200
- label: n("newInside"),
201
- onClick: () => v.create.mutate({ parent: r })
239
+ label: f.find("doc", o.id) ? s("remove") : s("add"),
240
+ onClick: () => f.toggle("doc", o.id)
202
241
  },
242
+ x,
203
243
  {
204
- label: n("showSubpagesAsCalendar"),
205
- onClick: () => b.addView.mutate({
206
- doc: r.key,
207
- name: S("calendarView"),
208
- layout: "calendar"
244
+ label: i("duplicate"),
245
+ onClick: () => b.duplicate.mutate({
246
+ doc: o,
247
+ team: p?.key
209
248
  })
210
249
  },
211
250
  {
212
- label: n("duplicate"),
213
- onClick: () => v.duplicate.mutate({
214
- doc: r,
215
- team: c?.key
216
- })
251
+ label: i("rename"),
252
+ onClick: l ?? (() => t({
253
+ to: "/$workspace/docs/$doc",
254
+ params: {
255
+ workspace: e,
256
+ doc: A(o)
257
+ },
258
+ search: { rename: !0 }
259
+ }))
260
+ },
261
+ {
262
+ label: o.icon ? i("look.changeIcon") : i("look.addIcon"),
263
+ onClick: () => {
264
+ let e = I.current ?? d();
265
+ e?.isConnected && R({
266
+ doc: o,
267
+ at: e
268
+ });
269
+ }
217
270
  },
218
- ...a ? [{
219
- label: n("rename"),
220
- onClick: a
221
- }] : [],
222
271
  {
223
- label: n("moveTo"),
272
+ label: i("moveTo"),
273
+ search: {
274
+ placeholder: i("moveToSearch"),
275
+ empty: i("moveToNone")
276
+ },
224
277
  items: [
225
- ..._.map((e) => {
226
- let t = !r.parentId && e.key === u;
278
+ ...P.map((e) => {
279
+ let t = !o.parentId && e.key === m;
227
280
  return {
228
- label: n("topOf", { space: e.name }),
281
+ label: i("topOf", { space: e.name }),
229
282
  checked: t,
230
283
  disabled: t,
231
- onClick: () => v.move.mutate({
232
- doc: r,
284
+ onClick: () => b.move.mutate({
285
+ doc: o,
233
286
  space: e.key
234
287
  })
235
288
  };
236
289
  }),
237
- ...h.length > 0 ? [m] : [],
238
- ...h.map((e) => ({
290
+ ...M.length > 0 ? [_] : [],
291
+ ...M.map((e) => ({
239
292
  label: e.title,
240
- checked: e.id === r.parentId,
241
- disabled: e.id === r.parentId,
242
- onClick: () => v.move.mutate({
243
- doc: r,
293
+ hint: F(e),
294
+ checked: e.id === o.parentId,
295
+ disabled: e.id === o.parentId,
296
+ onClick: () => b.move.mutate({
297
+ doc: o,
244
298
  parent: e
245
299
  })
246
300
  }))
247
301
  ]
248
302
  },
249
303
  {
250
- label: n("share"),
251
- onClick: () => f({
252
- doc: r.key,
253
- title: r.title
304
+ label: i("archive"),
305
+ destructive: !0,
306
+ onClick: () => b.archive.mutate(o, { onSuccess: () => v.success(i("archivedToast", { title: o.title }), { action: {
307
+ label: i("undo"),
308
+ onClick: () => b.restore.mutate(o)
309
+ } }) })
310
+ },
311
+ _,
312
+ {
313
+ label: i("newInside"),
314
+ onClick: () => b.create.mutate({ parent: o })
315
+ },
316
+ {
317
+ label: i("showSubpagesAsCalendar"),
318
+ onClick: () => C.addView.mutate({
319
+ doc: o.key,
320
+ name: w("calendarView"),
321
+ layout: "calendar"
254
322
  })
255
323
  },
256
324
  {
257
- label: g.find("doc", r.id) ? o("remove") : o("add"),
258
- onClick: () => g.toggle("doc", r.id)
325
+ label: i("share"),
326
+ onClick: () => h({
327
+ doc: o.key,
328
+ title: o.title
329
+ })
259
330
  },
260
331
  {
261
- label: n("look.fullWidth"),
262
- checked: !!r.fullWidth,
263
- onClick: () => v.setLook.mutate({
264
- doc: r,
265
- fullWidth: !r.fullWidth
332
+ label: i("look.fullWidth"),
333
+ checked: !!o.fullWidth,
334
+ onClick: () => b.setLook.mutate({
335
+ doc: o,
336
+ fullWidth: !o.fullWidth
266
337
  })
267
338
  },
268
339
  {
269
- label: r.template ? n("stopTemplate") : n("useAsTemplate"),
270
- onClick: () => v.setTemplate.mutate({
271
- doc: r,
272
- template: !r.template
340
+ label: o.template ? i("stopTemplate") : i("useAsTemplate"),
341
+ onClick: () => b.setTemplate.mutate({
342
+ doc: o,
343
+ template: !o.template
273
344
  })
274
345
  },
275
- ...r.template ? [{
276
- label: n("spaceDefault"),
277
- checked: !!r.spaceDefault,
278
- onClick: () => v.setSpaceDefault.mutate({
279
- doc: r,
280
- spaceDefault: !r.spaceDefault
346
+ ...o.template ? [{
347
+ label: i("spaceDefault"),
348
+ checked: !!o.spaceDefault,
349
+ onClick: () => b.setSpaceDefault.mutate({
350
+ doc: o,
351
+ spaceDefault: !o.spaceDefault
281
352
  })
282
353
  }] : [],
283
354
  {
284
- label: n("exportMarkdown"),
285
- onClick: () => O(e, { doc: r.key })
355
+ label: i("exportMarkdown"),
356
+ onClick: () => U(e, { doc: o.key })
286
357
  },
287
- m,
288
- ...p,
289
- m,
290
- {
291
- label: n("archive"),
292
- destructive: !0,
293
- onClick: () => v.archive.mutate(r)
294
- }
358
+ S
295
359
  ];
296
360
  }, [
297
- C,
298
- E,
361
+ D,
362
+ j,
299
363
  e,
300
364
  t,
301
- s,
302
- g,
303
- v,
304
- b,
305
365
  n,
306
- S,
366
+ c,
367
+ f,
368
+ b,
369
+ C,
370
+ E,
307
371
  i,
308
- o
372
+ w,
373
+ a,
374
+ s
309
375
  ]);
310
376
  }
311
- function D(e, t) {
312
- return o(w(e, t));
377
+ function V(e) {
378
+ let t = b(), n = B(e);
379
+ return x((e, r) => f(t, () => n(e, r)), [t, n]);
380
+ }
381
+ function H(e, t) {
382
+ return s(N(e, t));
313
383
  }
314
- function O(e, t) {
384
+ function U(e, t) {
315
385
  let n = new URLSearchParams({
316
386
  ...t,
317
387
  ...t.space && { knowledge: "true" }
318
388
  }), r = document.createElement("a");
319
- r.href = `${s}/api/v1/workspaces/${encodeURIComponent(e)}/docs/export?${n}`, r.download = "", r.click();
389
+ r.href = `${c}/api/v1/workspaces/${encodeURIComponent(e)}/docs/export?${n}`, r.download = "", r.click();
320
390
  }
321
- export { S as docKey, w as docPath, x as docRef, D as docURL, O as downloadMarkdown, T as useDocActions, E as useDocMenu, C as useTemplateValues };
391
+ export { j as docKey, N as docPath, A as docRef, H as docURL, U as downloadMarkdown, P as useDocActions, V as useDocContextMenu, F as useDocEditable, B as useDocMenu, z as useIconRequest, M as useTemplateValues };
package/lib/menus.js CHANGED
@@ -22,4 +22,18 @@ function i(e, t) {
22
22
  copy: { text: t }
23
23
  };
24
24
  }
25
- export { i as copyItem, r as useLinkItems };
25
+ var a = null, o = () => a;
26
+ function s(e, t) {
27
+ let n = (n, r) => {
28
+ a = r, e(n, t());
29
+ };
30
+ return {
31
+ onContextMenu: (e) => {
32
+ !e.shiftKey && e.currentTarget.contains(e.target) && (e.stopPropagation(), n(e, e.currentTarget));
33
+ },
34
+ onKeyDown: (e) => {
35
+ (e.key === "ContextMenu" || e.shiftKey && e.key === "F10") && e.currentTarget.contains(e.target) && (e.preventDefault(), e.stopPropagation(), n(e.currentTarget, e.currentTarget));
36
+ }
37
+ };
38
+ }
39
+ export { i as copyItem, o as menuOpenedOn, s as menuOpenerProps, r as useLinkItems };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parallelworks/tandem-web",
3
- "version": "0.192.2",
3
+ "version": "0.193.0",
4
4
  "description": "Tandem's pages, for a host app to render in its own",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",