@parallelworks/tandem-web 0.139.3 → 0.141.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,99 +1,126 @@
1
1
  import { appURL as e, basePath as t } from "./base.js";
2
2
  import { api as n, unwrap as r } from "../api/client.js";
3
3
  import { useNavigate as i } from "./router.js";
4
- import { docsQuery as a, teamsQuery as o } from "../api/queries.js";
5
- import { useFavorites as s } from "./favorites.js";
6
- import { copyItem as c, useLinkItems as l } from "./menus.js";
7
- import { openShare as u } from "./share.js";
8
- import { menuDivider as d } from "@parallelworks/ui";
9
- import { useCallback as f } from "react";
10
- import { useTranslations as p } from "use-intl";
11
- import { useMutation as m, useQuery as h, useQueryClient as g } from "@tanstack/react-query";
4
+ import { docTemplatesQuery as a, docsQuery as o, meQuery as s, teamsQuery as c } from "../api/queries.js";
5
+ import { useFavorites as l } from "./favorites.js";
6
+ import { copyItem as u, useLinkItems as d } from "./menus.js";
7
+ import { openShare as f } from "./share.js";
8
+ import { menuDivider as p } from "@parallelworks/ui";
9
+ import { useCallback as m } from "react";
10
+ import { useFormatter as h, useTranslations as g } from "use-intl";
11
+ import { useMutation as _, useQuery as v, useQueryClient as y } from "@tanstack/react-query";
12
12
  // src/lib/docs.tsx
13
- function _(e) {
13
+ function b(e) {
14
14
  return e.ref || (e.slug ? `${e.slug}-${e.key}` : e.key);
15
15
  }
16
- function v(e) {
16
+ function x(e) {
17
17
  let t = (e.split("-").pop() ?? e).toLowerCase();
18
18
  return /^[a-z2-7]{10}$/.test(t) ? t : e.toLowerCase();
19
19
  }
20
- function y(e, t) {
21
- return `/${e}/docs/${_(t)}`;
20
+ function S() {
21
+ let e = h(), { data: t } = v(s);
22
+ return m(() => {
23
+ let n = /* @__PURE__ */ new Date();
24
+ return {
25
+ date: e.dateTime(n, { dateStyle: "long" }),
26
+ time: e.dateTime(n, { timeStyle: "short" }),
27
+ author: t?.user.name ?? ""
28
+ };
29
+ }, [e, t]);
22
30
  }
23
- function b(e) {
24
- let t = g(), a = i(), o = p("docs"), s = () => t.invalidateQueries({ queryKey: [
31
+ function C(e, t) {
32
+ return `/${e}/docs/${b(t)}`;
33
+ }
34
+ function w(e) {
35
+ let t = y(), o = i(), s = g("docs"), l = () => t.invalidateQueries({ queryKey: [
25
36
  "workspace",
26
37
  e,
27
38
  "docs"
28
- ] }), c = (t) => ({ path: {
39
+ ] }), u = (t) => ({ path: {
29
40
  workspace: e,
30
41
  doc: t
31
- } });
32
- return {
33
- create: m({
34
- mutationFn: async ({ team: t, parent: i, template: a }) => r(await n.POST("/api/v1/workspaces/{workspace}/docs", {
42
+ } }), d = S(), f = _({
43
+ mutationFn: async ({ team: t, parent: i, template: a }) => {
44
+ let o = a ?? await C(t, i);
45
+ return r(await n.POST("/api/v1/workspaces/{workspace}/docs", {
35
46
  params: { path: { workspace: e } },
36
47
  body: {
37
- ...a ? { template: a } : { title: o("untitled") },
48
+ ...o ? {
49
+ template: o,
50
+ variables: d()
51
+ } : { title: s("untitled") },
38
52
  ...t && { team: t },
39
53
  ...i && { parent: i.key }
40
54
  }
41
- })),
42
- onSuccess: (t) => {
43
- s(), a({
44
- to: "/$workspace/docs/$doc",
45
- params: {
46
- workspace: e,
47
- doc: _(t)
48
- },
49
- search: { rename: !0 }
50
- });
55
+ }));
56
+ },
57
+ onSuccess: (t) => {
58
+ l(), o({
59
+ to: "/$workspace/docs/$doc",
60
+ params: {
61
+ workspace: e,
62
+ doc: b(t)
63
+ },
64
+ search: { rename: !0 }
65
+ });
66
+ }
67
+ }), p = _({
68
+ mutationFn: async ({ doc: e, title: t }) => r(await n.PATCH("/api/v1/workspaces/{workspace}/docs/{doc}", {
69
+ params: u(e.key),
70
+ body: { title: t }
71
+ })),
72
+ onSettled: l
73
+ }), m = _({
74
+ mutationFn: async ({ doc: e, area: t }) => r(await n.PATCH("/api/v1/workspaces/{workspace}/docs/{doc}", {
75
+ params: u(e.key),
76
+ body: { area: t }
77
+ })),
78
+ onSettled: l
79
+ }), h = _({
80
+ mutationFn: async ({ doc: e, space: t, parent: i, after: a, before: o }) => r(await n.POST("/api/v1/workspaces/{workspace}/docs/{doc}/move", {
81
+ params: u(e.key),
82
+ body: {
83
+ ...t && { space: t },
84
+ ...i && { parent: i.key },
85
+ ...a && { after: a.key },
86
+ ...o && { before: o.key }
51
87
  }
52
- }),
53
- rename: m({
54
- mutationFn: async ({ doc: e, title: t }) => r(await n.PATCH("/api/v1/workspaces/{workspace}/docs/{doc}", {
55
- params: c(e.key),
56
- body: { title: t }
57
- })),
58
- onSettled: s
59
- }),
60
- fileUnder: m({
61
- mutationFn: async ({ doc: e, area: t }) => r(await n.PATCH("/api/v1/workspaces/{workspace}/docs/{doc}", {
62
- params: c(e.key),
63
- body: { area: t }
64
- })),
65
- onSettled: s
66
- }),
67
- move: m({
68
- mutationFn: async ({ doc: e, space: t, parent: i, after: a, before: o }) => r(await n.POST("/api/v1/workspaces/{workspace}/docs/{doc}/move", {
69
- params: c(e.key),
70
- body: {
71
- ...t && { space: t },
72
- ...i && { parent: i.key },
73
- ...a && { after: a.key },
74
- ...o && { before: o.key }
75
- }
76
- })),
77
- onSettled: s
78
- }),
79
- archive: m({
80
- mutationFn: async (e) => r(await n.POST("/api/v1/workspaces/{workspace}/docs/{doc}/archive", { params: c(e.key) })),
81
- onSettled: s
82
- }),
83
- restore: m({
84
- mutationFn: async (e) => r(await n.POST("/api/v1/workspaces/{workspace}/docs/{doc}/restore", { params: c(e.key) })),
85
- onSettled: s
86
- }),
87
- setTemplate: m({
88
+ })),
89
+ onSettled: l
90
+ }), v = _({
91
+ mutationFn: async (e) => r(await n.POST("/api/v1/workspaces/{workspace}/docs/{doc}/archive", { params: u(e.key) })),
92
+ onSettled: l
93
+ }), x = _({
94
+ mutationFn: async (e) => r(await n.POST("/api/v1/workspaces/{workspace}/docs/{doc}/restore", { params: u(e.key) })),
95
+ onSettled: l
96
+ }), C = async (n, r) => {
97
+ let [i, o] = await Promise.all([t.fetchQuery(a(e)), t.fetchQuery(c(e))]), s = r ? r.teamId ?? "" : o.find((e) => e.key === n)?.id ?? "";
98
+ return i.find((e) => e.spaceDefault && (e.teamId ?? "") === s)?.id;
99
+ }, w = _({
100
+ mutationFn: async ({ doc: e, spaceDefault: t }) => r(await n.PATCH("/api/v1/workspaces/{workspace}/docs/{doc}", {
101
+ params: u(e.key),
102
+ body: { spaceDefault: t }
103
+ })),
104
+ onSettled: l
105
+ });
106
+ return {
107
+ create: f,
108
+ rename: p,
109
+ fileUnder: m,
110
+ move: h,
111
+ archive: v,
112
+ restore: x,
113
+ setTemplate: _({
88
114
  mutationFn: async ({ doc: e, template: t }) => r(await n.PATCH("/api/v1/workspaces/{workspace}/docs/{doc}", {
89
- params: c(e.key),
115
+ params: u(e.key),
90
116
  body: { template: t }
91
117
  })),
92
- onSettled: s
118
+ onSettled: l
93
119
  }),
94
- setLook: m({
120
+ setSpaceDefault: w,
121
+ setLook: _({
95
122
  mutationFn: async ({ doc: e, ...t }) => r(await n.PATCH("/api/v1/workspaces/{workspace}/docs/{doc}", {
96
- params: c(e.key),
123
+ params: u(e.key),
97
124
  body: t
98
125
  })),
99
126
  onMutate: ({ doc: n, ...r }) => {
@@ -106,30 +133,30 @@ function b(e) {
106
133
  ...r
107
134
  } : e);
108
135
  },
109
- onSettled: s
136
+ onSettled: l
110
137
  }),
111
- duplicate: m({
138
+ duplicate: _({
112
139
  mutationFn: async ({ doc: t, team: i }) => {
113
- let a = r(await n.GET("/api/v1/workspaces/{workspace}/docs/{doc}", { params: c(t.key) })), s = a.ancestors?.at(-1)?.key, l = r(await n.POST("/api/v1/workspaces/{workspace}/docs", {
140
+ let a = r(await n.GET("/api/v1/workspaces/{workspace}/docs/{doc}", { params: u(t.key) })), o = a.ancestors?.at(-1)?.key, c = r(await n.POST("/api/v1/workspaces/{workspace}/docs", {
114
141
  params: { path: { workspace: e } },
115
142
  body: {
116
- title: o("copyOf", { title: a.title }),
143
+ title: s("copyOf", { title: a.title }),
117
144
  body: a.body ?? "",
118
145
  ...i && { team: i },
119
- ...s && { parent: s }
146
+ ...o && { parent: o }
120
147
  }
121
148
  }));
122
149
  return a.icon ? r(await n.PATCH("/api/v1/workspaces/{workspace}/docs/{doc}", {
123
- params: c(l.key),
150
+ params: u(c.key),
124
151
  body: { icon: a.icon }
125
- })) : l;
152
+ })) : c;
126
153
  },
127
154
  onSuccess: (t) => {
128
- s(), a({
155
+ l(), o({
129
156
  to: "/$workspace/docs/$doc",
130
157
  params: {
131
158
  workspace: e,
132
- doc: _(t)
159
+ doc: b(t)
133
160
  },
134
161
  search: { rename: !0 }
135
162
  });
@@ -137,73 +164,73 @@ function b(e) {
137
164
  })
138
165
  };
139
166
  }
140
- function x(e) {
141
- let t = i(), n = p("docs"), r = p("common"), m = p("favorites"), g = l(), v = s(e), x = b(e), { data: S = [] } = h(o(e)), { data: w = [] } = h(a(e, { top: !0 }));
142
- return f((i, { onRename: a } = {}) => {
143
- let o = S.find((e) => e.id === i.teamId), s = o?.key ?? "workspace", l = {
167
+ function T(e) {
168
+ let t = i(), n = g("docs"), r = g("common"), a = g("favorites"), s = d(), h = l(e), _ = w(e), { data: y = [] } = v(c(e)), { data: x = [] } = v(o(e, { top: !0 }));
169
+ return m((i, { onRename: o } = {}) => {
170
+ let c = y.find((e) => e.id === i.teamId), l = c?.key ?? "workspace", d = {
144
171
  label: r("open"),
145
172
  onClick: () => t({
146
173
  to: "/$workspace/docs/$doc",
147
174
  params: {
148
175
  workspace: e,
149
- doc: _(i)
176
+ doc: b(i)
150
177
  }
151
178
  })
152
- }, f = [...g(y(e, i)), c(n("copyKey"), i.key)];
179
+ }, m = [...s(C(e, i)), u(n("copyKey"), i.key)];
153
180
  if (i.archivedAt) return [
154
- l,
181
+ d,
155
182
  {
156
183
  label: n("restore"),
157
- onClick: () => x.restore.mutate(i)
184
+ onClick: () => _.restore.mutate(i)
158
185
  },
159
- d,
160
- ...f
186
+ p,
187
+ ...m
161
188
  ];
162
- let p = w.filter((e) => e.id !== i.id), h = [{
189
+ let g = x.filter((e) => e.id !== i.id), v = [{
163
190
  key: "workspace",
164
191
  name: n("workspaceSpace")
165
- }, ...S.filter((e) => !e.archivedAt).map((e) => ({
192
+ }, ...y.filter((e) => !e.archivedAt).map((e) => ({
166
193
  key: e.key,
167
194
  name: e.name
168
195
  }))];
169
196
  return [
170
- l,
197
+ d,
171
198
  {
172
199
  label: n("newInside"),
173
- onClick: () => x.create.mutate({ parent: i })
200
+ onClick: () => _.create.mutate({ parent: i })
174
201
  },
175
202
  {
176
203
  label: n("duplicate"),
177
- onClick: () => x.duplicate.mutate({
204
+ onClick: () => _.duplicate.mutate({
178
205
  doc: i,
179
- team: o?.key
206
+ team: c?.key
180
207
  })
181
208
  },
182
- ...a ? [{
209
+ ...o ? [{
183
210
  label: n("rename"),
184
- onClick: a
211
+ onClick: o
185
212
  }] : [],
186
213
  {
187
214
  label: n("moveTo"),
188
215
  items: [
189
- ...h.map((e) => {
190
- let t = !i.parentId && e.key === s;
216
+ ...v.map((e) => {
217
+ let t = !i.parentId && e.key === l;
191
218
  return {
192
219
  label: n("topOf", { space: e.name }),
193
220
  checked: t,
194
221
  disabled: t,
195
- onClick: () => x.move.mutate({
222
+ onClick: () => _.move.mutate({
196
223
  doc: i,
197
224
  space: e.key
198
225
  })
199
226
  };
200
227
  }),
201
- ...p.length > 0 ? [d] : [],
202
- ...p.map((e) => ({
228
+ ...g.length > 0 ? [p] : [],
229
+ ...g.map((e) => ({
203
230
  label: e.title,
204
231
  checked: e.id === i.parentId,
205
232
  disabled: e.id === i.parentId,
206
- onClick: () => x.move.mutate({
233
+ onClick: () => _.move.mutate({
207
234
  doc: i,
208
235
  parent: e
209
236
  })
@@ -212,64 +239,72 @@ function x(e) {
212
239
  },
213
240
  {
214
241
  label: n("share"),
215
- onClick: () => u({
242
+ onClick: () => f({
216
243
  doc: i.key,
217
244
  title: i.title
218
245
  })
219
246
  },
220
247
  {
221
- label: v.find("doc", i.id) ? m("remove") : m("add"),
222
- onClick: () => v.toggle("doc", i.id)
248
+ label: h.find("doc", i.id) ? a("remove") : a("add"),
249
+ onClick: () => h.toggle("doc", i.id)
223
250
  },
224
251
  {
225
252
  label: n("look.fullWidth"),
226
253
  checked: !!i.fullWidth,
227
- onClick: () => x.setLook.mutate({
254
+ onClick: () => _.setLook.mutate({
228
255
  doc: i,
229
256
  fullWidth: !i.fullWidth
230
257
  })
231
258
  },
232
259
  {
233
260
  label: i.template ? n("stopTemplate") : n("useAsTemplate"),
234
- onClick: () => x.setTemplate.mutate({
261
+ onClick: () => _.setTemplate.mutate({
235
262
  doc: i,
236
263
  template: !i.template
237
264
  })
238
265
  },
266
+ ...i.template ? [{
267
+ label: n("spaceDefault"),
268
+ checked: !!i.spaceDefault,
269
+ onClick: () => _.setSpaceDefault.mutate({
270
+ doc: i,
271
+ spaceDefault: !i.spaceDefault
272
+ })
273
+ }] : [],
239
274
  {
240
275
  label: n("exportMarkdown"),
241
- onClick: () => C(e, { doc: i.key })
276
+ onClick: () => D(e, { doc: i.key })
242
277
  },
243
- d,
244
- ...f,
245
- d,
278
+ p,
279
+ ...m,
280
+ p,
246
281
  {
247
282
  label: n("archive"),
248
283
  destructive: !0,
249
- onClick: () => x.archive.mutate(i)
284
+ onClick: () => _.archive.mutate(i)
250
285
  }
251
286
  ];
252
287
  }, [
253
- S,
254
- w,
288
+ y,
289
+ x,
255
290
  e,
256
291
  t,
257
- g,
258
- v,
259
- x,
292
+ s,
293
+ h,
294
+ _,
260
295
  n,
261
296
  r,
262
- m
297
+ a
263
298
  ]);
264
299
  }
265
- function S(t, n) {
266
- return e(y(t, n));
300
+ function E(t, n) {
301
+ return e(C(t, n));
267
302
  }
268
- function C(e, n) {
303
+ function D(e, n) {
269
304
  let r = new URLSearchParams({
270
305
  ...n,
271
306
  ...n.space && { knowledge: "true" }
272
307
  }), i = document.createElement("a");
273
308
  i.href = `${t}/api/v1/workspaces/${encodeURIComponent(e)}/docs/export?${r}`, i.download = "", i.click();
274
309
  }
275
- export { v as docKey, y as docPath, _ as docRef, S as docURL, C as downloadMarkdown, b as useDocActions, x as useDocMenu };
310
+ export { x as docKey, C as docPath, b as docRef, E as docURL, D as downloadMarkdown, w as useDocActions, T as useDocMenu, S as useTemplateValues };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parallelworks/tandem-web",
3
- "version": "0.139.3",
3
+ "version": "0.141.0",
4
4
  "description": "Tandem's pages, for a host app to render in its own",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",