@backmatter/studio 0.0.8 → 0.0.10

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.
Files changed (65) hide show
  1. package/dist/chunks/UiKitApp-BxvTwsko.js +2410 -0
  2. package/dist/chunks/WorkspaceRoutes-BKKEkAq7.js +90126 -0
  3. package/dist/chunks/{dashboard-bNp6AbKE.js → dashboard-8rjkfEXl.js} +380 -382
  4. package/dist/chunks/{index-DoDE-hwB.js → index-laWAz5_p.js} +111 -112
  5. package/dist/dashboard.js +2 -2
  6. package/dist/index.js +287 -146
  7. package/dist/site-widget.css +1615 -0
  8. package/dist/site-widget.js +30903 -628
  9. package/dist/studio.css +268 -67
  10. package/package.json +4 -4
  11. package/src/App.tsx +12 -29
  12. package/src/api.ts +55 -0
  13. package/src/chat/ChangeCard.tsx +2 -0
  14. package/src/chat/ChatMessage.tsx +73 -62
  15. package/src/chat/ChatPanel.tsx +110 -15
  16. package/src/chat/DocListCard.tsx +2 -0
  17. package/src/chat/LiveStatus.tsx +78 -8
  18. package/src/chat/Reveal.tsx +34 -0
  19. package/src/chat/Shimmer.tsx +65 -23
  20. package/src/chat/chat-helpers.ts +35 -0
  21. package/src/chat/motion.ts +73 -0
  22. package/src/chat/useStickToBottom.ts +129 -14
  23. package/src/chrome/ContentExplorerSidebar.tsx +23 -8
  24. package/src/chrome/content-tree-visibility.ts +55 -0
  25. package/src/devbar-state.ts +125 -0
  26. package/src/index.css +3 -131
  27. package/src/pages/CliAuthorizePage.tsx +61 -28
  28. package/src/pages/MediaGalleryPage.tsx +74 -11
  29. package/src/pages/MediaLightbox.tsx +93 -1
  30. package/src/pages/SettingsUsagePage.tsx +23 -1
  31. package/src/pages/media-grid.ts +13 -0
  32. package/src/pages/ui-kit/UiKitApp.tsx +164 -0
  33. package/src/pages/ui-kit/buttons.tsx +30 -0
  34. package/src/pages/ui-kit/catalog.tsx +41 -0
  35. package/src/pages/ui-kit/colors.tsx +95 -0
  36. package/src/pages/ui-kit/devbar.tsx +160 -0
  37. package/src/pages/ui-kit/feedback.tsx +39 -0
  38. package/src/pages/ui-kit/fields.tsx +47 -0
  39. package/src/pages/ui-kit/lists.tsx +19 -0
  40. package/src/pages/ui-kit/overlays.tsx +39 -0
  41. package/src/pages/ui-kit/path.ts +9 -0
  42. package/src/pages/ui-kit/sections.tsx +32 -0
  43. package/src/pages/ui-kit/surfaces.tsx +121 -0
  44. package/src/pages/ui-kit/topic.tsx +112 -0
  45. package/src/pages/ui-kit/topics.ts +71 -0
  46. package/src/pages/ui-kit/type.tsx +55 -0
  47. package/src/preview-frame-radius.ts +51 -0
  48. package/src/preview-frame.tsx +108 -49
  49. package/src/shell-resets.css +155 -0
  50. package/src/site-bar.tsx +1810 -425
  51. package/src/site-dashboard-href.ts +21 -0
  52. package/src/site-devbar-overlay-inject.ts +15 -0
  53. package/src/site-devbar-overlay.css +217 -0
  54. package/src/site-pointer.ts +1 -1
  55. package/src/site-publish-menu.tsx +33 -0
  56. package/src/site-widget-styles.ts +7 -0
  57. package/src/site-widget.tsx +61 -21
  58. package/src/studio-prose-ui.css +39 -0
  59. package/src/theme/ThemeProvider.tsx +4 -1
  60. package/src/workspace-path.ts +10 -6
  61. package/dist/chunks/EmbedPublishPage-CtIlaeGO.js +0 -149
  62. package/dist/chunks/UiKitPage-DcnSQ-Hf.js +0 -173
  63. package/dist/chunks/WorkspaceRoutes-DVpUOaMV.js +0 -59550
  64. package/dist/chunks/status-bar-action-C0fsAWvD.js +0 -30618
  65. package/src/pages/UiKitPage.tsx +0 -331
package/dist/dashboard.js CHANGED
@@ -1,5 +1,5 @@
1
- import { A as a, i as s } from "./chunks/dashboard-bNp6AbKE.js";
2
- import { w as t, Q as f } from "./chunks/status-bar-action-C0fsAWvD.js";
1
+ import { A as a, i as s } from "./chunks/dashboard-8rjkfEXl.js";
2
+ import { w as t, x as f } from "./chunks/WorkspaceRoutes-BKKEkAq7.js";
3
3
  export {
4
4
  a as DashboardApp,
5
5
  t as configureStudio,
package/dist/index.js CHANGED
@@ -1,42 +1,40 @@
1
- import { jsx as r, jsxs as l } from "react/jsx-runtime";
2
- import { useLayoutEffect as I, useEffect as u, useRef as C, useState as S } from "react";
3
- import { i as L, T, E as N, C as M, z, A as D, D as O, F as g, H as x, I as v, L as _, M as A, N as B, O as F, w as P, Q as w, R as V, U as j, f as q, V as G, W as m, X as b } from "./chunks/status-bar-action-C0fsAWvD.js";
4
- import { Y as Se } from "./chunks/status-bar-action-C0fsAWvD.js";
5
- import { f as H, s as W, g as $, R as K, h as X, i as Y, L as Q, w as J, T as E, r as Z } from "./chunks/WorkspaceRoutes-DVpUOaMV.js";
6
- import { u as ee, S as te } from "./chunks/define-studio-BYtYDGLX.js";
7
- import { d as Pe } from "./chunks/define-studio-BYtYDGLX.js";
8
- import { E as ne } from "./chunks/EmbedPublishPage-CtIlaeGO.js";
9
- const p = {
1
+ import { jsx as t, jsxs as d } from "react/jsx-runtime";
2
+ import { useLayoutEffect as re, useEffect as f, useRef as W, useState as g, useMemo as oe } from "react";
3
+ import { i as J, T as ae, E as se, C as ce, a as le, b as de, u as ue, D as A, c as X, d as B, e as xe, f as Y, g as G, h as me, p as z, j as C, k as N, r as fe, n as he, s as pe, l as ge, m as we, o as be, q as ye, B as ve, t as ke, S as qe, v as Ee, w as Q, x as P, y as ze, z as Ce, A as Ne, R as Se, F as Re, G as Le, H as Pe, I as S, N as I, L as Ue, J as je, K as F, M as Te } from "./chunks/WorkspaceRoutes-BKKEkAq7.js";
4
+ import { O as ot } from "./chunks/WorkspaceRoutes-BKKEkAq7.js";
5
+ import { u as Me, S as _e } from "./chunks/define-studio-BYtYDGLX.js";
6
+ import { d as st } from "./chunks/define-studio-BYtYDGLX.js";
7
+ const R = {
10
8
  accent: "var(--x11n7hvk)",
11
9
  accentHover: "var(--x1vnpaut)",
12
10
  focus: "var(--x1nzi8h4)"
13
11
  };
14
- function re(e) {
15
- const t = /^var\((--[^,)]+)/.exec(e);
16
- return (t == null ? void 0 : t[1]) ?? null;
17
- }
18
- const oe = [p.accent, p.accentHover, p.focus];
19
- function ie() {
20
- var t, i;
21
- const e = (i = (t = ee().theme) == null ? void 0 : t.accent) == null ? void 0 : i.trim();
22
- return I(() => {
12
+ function $e(e) {
13
+ const n = /^var\((--[^,)]+)/.exec(e);
14
+ return (n == null ? void 0 : n[1]) ?? null;
15
+ }
16
+ const De = [R.accent, R.accentHover, R.focus];
17
+ function Oe() {
18
+ var n, a;
19
+ const e = (a = (n = Me().theme) == null ? void 0 : n.accent) == null ? void 0 : a.trim();
20
+ return re(() => {
23
21
  if (!e) return;
24
- const a = document.documentElement, n = oe.map(re).filter((o) => !!o);
25
- for (const o of n) a.style.setProperty(o, e);
22
+ const o = document.documentElement, r = De.map($e).filter((s) => !!s);
23
+ for (const s of r) o.style.setProperty(s, e);
26
24
  return () => {
27
- for (const o of n) a.style.removeProperty(o);
25
+ for (const s of r) o.style.removeProperty(s);
28
26
  };
29
27
  }, [e]), null;
30
28
  }
31
- function ae({ workspaceId: e }) {
32
- return u(() => L(), []), /* @__PURE__ */ r(T, { children: /* @__PURE__ */ r(N, { children: /* @__PURE__ */ r(M, { workspaceId: e, startOpen: !0, pointer: !0, children: /* @__PURE__ */ l(z, { children: [
33
- /* @__PURE__ */ r(se, {}),
34
- /* @__PURE__ */ r(ce, {}),
35
- /* @__PURE__ */ r(de, {}),
36
- /* @__PURE__ */ r(D, { fill: !0 })
29
+ function Ae({ workspaceId: e }) {
30
+ return f(() => J(), []), /* @__PURE__ */ t(ae, { children: /* @__PURE__ */ t(se, { children: /* @__PURE__ */ t(ce, { workspaceId: e, startOpen: !0, pointer: !0, children: /* @__PURE__ */ d(le, { children: [
31
+ /* @__PURE__ */ t(Be, {}),
32
+ /* @__PURE__ */ t(Ge, {}),
33
+ /* @__PURE__ */ t(Ie, {}),
34
+ /* @__PURE__ */ t(de, { fill: !0 })
37
35
  ] }) }) }) });
38
36
  }
39
- function f() {
37
+ function y() {
40
38
  if (!document.referrer) return "";
41
39
  try {
42
40
  return new URL(document.referrer).origin;
@@ -44,164 +42,307 @@ function f() {
44
42
  return "";
45
43
  }
46
44
  }
47
- function se() {
48
- const { setFocus: e } = O();
49
- return u(() => {
50
- const t = f();
51
- function i(a) {
52
- if (!t || a.origin !== t) return;
53
- const n = a.data;
54
- if ((n == null ? void 0 : n.type) !== "backmatter:focus") return;
55
- const o = n.doc;
56
- !(o != null && o.locale) || !o.type || !o.slug || e({
57
- docRef: { locale: o.locale, type: o.type, slug: o.slug },
45
+ function Be() {
46
+ const { setFocus: e } = ue();
47
+ return f(() => {
48
+ const n = y();
49
+ function a(o) {
50
+ if (!n || o.origin !== n) return;
51
+ const r = o.data;
52
+ if ((r == null ? void 0 : r.type) !== "backmatter:focus") return;
53
+ const s = r.doc;
54
+ !(s != null && s.locale) || !s.type || !s.slug || e({
55
+ docRef: { locale: s.locale, type: s.type, slug: s.slug },
58
56
  frontmatter: {},
59
57
  body: "",
60
58
  selection: null
61
59
  });
62
60
  }
63
- return window.addEventListener("message", i), t && window.parent.postMessage({ type: "backmatter:chat-ready" }, t), () => window.removeEventListener("message", i);
64
- }, [e]), u(() => {
65
- const t = f();
66
- function i(a) {
67
- const n = a.detail;
68
- !t || !(n != null && n.docRef) || window.parent.postMessage({ type: "backmatter:doc-changed", doc: n.docRef }, t);
61
+ return window.addEventListener("message", a), n && window.parent.postMessage({ type: "backmatter:chat-ready" }, n), () => window.removeEventListener("message", a);
62
+ }, [e]), f(() => {
63
+ const n = y();
64
+ function a(o) {
65
+ const r = o.detail;
66
+ !n || !(r != null && r.docRef) || window.parent.postMessage({ type: "backmatter:doc-changed", doc: r.docRef }, n);
69
67
  }
70
- return window.addEventListener(g, i), () => window.removeEventListener(g, i);
68
+ return window.addEventListener(A, a), () => window.removeEventListener(A, a);
71
69
  }, []), null;
72
70
  }
73
- function ce() {
74
- const { addPointer: e } = x();
75
- return u(() => {
76
- const t = f();
77
- function i(a) {
78
- if (!t || a.origin !== t || a.source !== window.parent) return;
79
- const n = a.data;
80
- if ((n == null ? void 0 : n.type) !== "backmatter:pointer-grab") return;
81
- const o = _(
82
- n.doc ?? {},
83
- n.grab
71
+ function Ge() {
72
+ const { addPointer: e } = X();
73
+ return f(() => {
74
+ const n = y();
75
+ function a(o) {
76
+ if (!n || o.origin !== n || o.source !== window.parent) return;
77
+ const r = o.data;
78
+ if ((r == null ? void 0 : r.type) !== "backmatter:pointer-grab") return;
79
+ const s = xe(
80
+ r.doc ?? {},
81
+ r.grab
84
82
  );
85
- o && e(o);
83
+ s && e(s);
86
84
  }
87
- return window.addEventListener("message", i), () => window.removeEventListener("message", i);
85
+ return window.addEventListener("message", a), () => window.removeEventListener("message", a);
88
86
  }, [e]), null;
89
87
  }
90
- function de() {
91
- const { panel: e, dispatch: t } = x(), i = e.mode, a = C(i);
92
- return u(() => {
93
- const n = f();
94
- if (!n || window.parent === window) return;
95
- const o = v(a.current);
96
- a.current = i, o && !v(i) && window.parent.postMessage({ type: "backmatter:chat-closed" }, n);
97
- }, [i]), u(() => {
98
- const n = f();
99
- function o(c) {
100
- var d;
101
- !n || c.origin !== n || ((d = c.data) == null ? void 0 : d.type) === "backmatter:chat-open" && (t({ type: "open" }), requestAnimationFrame(() => {
88
+ function Ie() {
89
+ const { panel: e, dispatch: n } = X(), a = e.mode, o = W(a);
90
+ return f(() => {
91
+ const r = y();
92
+ if (!r || window.parent === window) return;
93
+ const s = B(o.current);
94
+ o.current = a, s && !B(a) && window.parent.postMessage({ type: "backmatter:chat-closed" }, r);
95
+ }, [a]), f(() => {
96
+ const r = y();
97
+ function s(h) {
98
+ var m;
99
+ !r || h.origin !== r || ((m = h.data) == null ? void 0 : m.type) === "backmatter:chat-open" && (n({ type: "open" }), requestAnimationFrame(() => {
102
100
  window.dispatchEvent(new Event("backmatter:chat-focus"));
103
101
  }));
104
102
  }
105
- return window.addEventListener("message", o), () => window.removeEventListener("message", o);
106
- }, [t]), null;
103
+ return window.addEventListener("message", s), () => window.removeEventListener("message", s);
104
+ }, [n]), null;
105
+ }
106
+ const Fe = 8e3;
107
+ function K() {
108
+ if (!document.referrer) return "";
109
+ try {
110
+ return new URL(document.referrer).origin;
111
+ } catch {
112
+ return "";
113
+ }
114
+ }
115
+ function Ke(e) {
116
+ if (!(e instanceof Error)) return "Commit failed";
117
+ const n = e;
118
+ return n.code === "conflict" ? "Resolve conflicts before committing" : n.code === "nothing_to_commit" ? "Nothing to commit" : n.code === "validation" ? e.message.replace(/^validation:\s*/, "Validation failed: ") : n.code === "github_not_bound" ? "Connect GitHub first" : e.message;
119
+ }
120
+ function L(e) {
121
+ return `${e.locale}/${e.type}/${e.slug}`;
122
+ }
123
+ const He = {
124
+ modified: "modified",
125
+ added: "new",
126
+ conflict: "conflict",
127
+ deleted: "deleted"
128
+ };
129
+ function Ve({
130
+ workspaceId: e,
131
+ onStatus: n,
132
+ onPublished: a
133
+ }) {
134
+ f(() => J(), []);
135
+ const [o, r] = g(null), [s, h] = g("viewer"), [m, w] = g(""), [c, p] = g(null), [v, U] = g(!1), [k, j] = g(null);
136
+ f(() => {
137
+ let i = !1;
138
+ return Y(e).then((l) => {
139
+ i || h(l.workspace.role);
140
+ }).catch(() => {
141
+ i || p("Could not load this workspace");
142
+ }), () => {
143
+ i = !0;
144
+ };
145
+ }, [e]);
146
+ const q = W(n);
147
+ q.current = n, f(() => {
148
+ let i = !1;
149
+ const l = () => {
150
+ N(e).then((x) => {
151
+ var O;
152
+ if (i) return;
153
+ r(x);
154
+ const _ = x.changes.length, $ = G(x);
155
+ (O = q.current) == null || O.call(q, {
156
+ changeCount: _,
157
+ conflictCount: $
158
+ });
159
+ const D = K();
160
+ !D || window.parent === window || window.parent.postMessage({
161
+ type: "backmatter:git",
162
+ changeCount: _,
163
+ conflictCount: $
164
+ }, D);
165
+ }).catch((x) => {
166
+ i || p(x instanceof Error ? x.message : "Git status failed");
167
+ });
168
+ };
169
+ l();
170
+ const b = window.setInterval(l, Fe);
171
+ return () => {
172
+ i = !0, window.clearInterval(b);
173
+ };
174
+ }, [e]);
175
+ const u = (o == null ? void 0 : o.changes) ?? [], ee = G(o), E = pe(ee, be(s)), T = oe(() => u.filter((i) => i.status === "conflict"), [u]), te = me(u);
176
+ async function M(i, l) {
177
+ const b = `${L(i)}:${l}`;
178
+ j(b), p(null);
179
+ try {
180
+ await fe(e, i.locale, i.type, i.slug, l), he({
181
+ workspaceId: e,
182
+ locale: i.locale,
183
+ type: i.type,
184
+ slug: i.slug,
185
+ status: l === "theirs" ? "clean" : "modified"
186
+ });
187
+ const x = await N(e);
188
+ r(x);
189
+ } catch (x) {
190
+ p(x instanceof Error ? x.message : "Resolve failed");
191
+ } finally {
192
+ j(null);
193
+ }
194
+ }
195
+ async function ne(i) {
196
+ if (i.preventDefault(), !(v || E !== "commit" || u.length === 0)) {
197
+ U(!0), p(null);
198
+ try {
199
+ const l = await ge(e, m);
200
+ w(""), we(e, l.files), a == null || a();
201
+ const b = K();
202
+ b && window.parent !== window && window.parent.postMessage({
203
+ type: "backmatter:published"
204
+ }, b), r(await N(e));
205
+ } catch (l) {
206
+ p(Ke(l));
207
+ } finally {
208
+ U(!1);
209
+ }
210
+ }
211
+ }
212
+ const ie = (o == null ? void 0 : o.currentBranch) ?? "main";
213
+ return T.length > 0 ? /* @__PURE__ */ d("div", { className: "x78zum5 xdt5ytf xmqd7ac x1hb2obb xqjzbou", children: [
214
+ /* @__PURE__ */ t("p", { ...z(C.groupLabel), children: "Resolve conflicts" }),
215
+ /* @__PURE__ */ t("p", { className: "x1ghz6dp x173sf5p xq98a72 x10qp4ay x37zpob x111yfic", children: "Pick a side for each file. Commit stays blocked until every conflict is resolved." }),
216
+ c ? /* @__PURE__ */ t("p", { className: "x1ghz6dp x173sf5p xq98a72 x10qp4ay x1trrqm4", children: c }) : null,
217
+ /* @__PURE__ */ t("ul", { className: "x1ghz6dp x1717udv xe8uvvx x1odjw0f x1kbliiw xq3t0pi", children: T.map((i) => {
218
+ const l = L(i);
219
+ return /* @__PURE__ */ d("li", { className: "x78zum5 xdt5ytf xpw8yq9 x1l8q8zy x1om5956 x1ar5oo6 x10qp4ay", children: [
220
+ /* @__PURE__ */ d("span", { className: "xeuugli x98rzlu xb3r6kr xlyipyv xuxw1ft", children: [
221
+ i.type,
222
+ "/",
223
+ i.slug
224
+ ] }),
225
+ /* @__PURE__ */ d("div", { className: "x78zum5 xpw8yq9", children: [
226
+ /* @__PURE__ */ t("button", { type: "button", disabled: k !== null, onClick: () => void M(i, "mine"), className: "xxk0z11 x1l8q8zy xmkeg23 x1y0btm7 x1j0qoeq x13oidi x1hb2obb xqjzbou x10qp4ay x1ypdohk xk0mbs4 x1s07b3s x784prv x9v5kkp x1yxvn1h x13iak60", children: k === `${l}:mine` ? "Keeping…" : "Keep mine" }),
227
+ /* @__PURE__ */ t("button", { type: "button", disabled: k !== null, onClick: () => void M(i, "theirs"), className: "xxk0z11 x1l8q8zy xmkeg23 x1y0btm7 x13oidi x1hb2obb x10qp4ay x1ypdohk xk0mbs4 x1s07b3s x784prv x9v5kkp x1yxvn1h x13iak60 x1nf6o4h x1trrqm4", children: k === `${l}:theirs` ? "Taking…" : "Take theirs" })
228
+ ] })
229
+ ] }, l);
230
+ }) })
231
+ ] }) : /* @__PURE__ */ d("form", { className: "x78zum5 xdt5ytf xmqd7ac x1hb2obb xqjzbou", onSubmit: (i) => void ne(i), children: [
232
+ /* @__PURE__ */ t("p", { ...z(C.groupLabel), children: u.length === 0 ? "Nothing to publish" : `${u.length} ${u.length === 1 ? "file" : "files"} → ${ie}` }),
233
+ u.length > 0 ? /* @__PURE__ */ t("ul", { className: "x1ghz6dp x1717udv xe8uvvx xctk3hg x1odjw0f x1kbliiw", children: u.map((i) => /* @__PURE__ */ t("li", { children: /* @__PURE__ */ d("div", { className: "x78zum5 x6s0dn4 x3smv4v x1rz828m x1ghz6dp x1obou79 x1l8q8zy x1om5956 x1ar5oo6 x10qp4ay x111yfic", children: [
234
+ /* @__PURE__ */ d("span", { className: "xeuugli x98rzlu xb3r6kr xlyipyv xuxw1ft", children: [
235
+ i.type,
236
+ "/",
237
+ i.slug
238
+ ] }),
239
+ /* @__PURE__ */ t("span", { ...z(C.itemMeta), children: He[i.status] })
240
+ ] }) }, L(i))) }) : null,
241
+ u.length > 0 ? /* @__PURE__ */ t("div", { ...z(C.separator) }) : null,
242
+ u.length > 0 ? /* @__PURE__ */ d("div", { className: "x78zum5 xdt5ytf x1qjc9v5 x1ndbd79 x173sf5p x1l7y7l0 xreod0t", children: [
243
+ /* @__PURE__ */ t("input", { value: m, onChange: (i) => w(i.target.value), placeholder: te, "aria-label": "Commit message", autoComplete: "off", spellCheck: !1, "data-no-ring": !0, "data-1p-ignore": !0, "data-lpignore": !0, disabled: v || E !== "commit", className: "xh8yej3 x9f619 xe0p6wg x1l8q8zy x1om5956 xmkeg23 x1y0btm7 x1j0qoeq x13oidi xawfm1v xqjzbou x1vrk1b5 x1a2a7pz x1uvtmcs x1t8xw5s xk2swo9 xk0mbs4 x9ecp23" }),
244
+ c ? /* @__PURE__ */ t("p", { className: "x1ghz6dp x10qp4ay x1trrqm4 xnjsko4 x18d9i69", children: c }) : null,
245
+ E === "blocked" ? /* @__PURE__ */ t("p", { className: "x1ghz6dp x173sf5p xq98a72 x10qp4ay x37zpob x111yfic", children: "Writers cannot publish" }) : /* @__PURE__ */ t("button", { type: "submit", disabled: v || E !== "commit", className: "x78zum5 xh8yej3 x6s0dn4 xl56j7k x1fgtraw x161b3w3 xmkeg23 x1y0btm7 x14aomtw x13oidi xrb6rkd xfja90d x10qp4ay xk50ysn xuxw1ft x1ypdohk x2q2s9b x1dih85f xk0mbs4 x1s07b3s xd3so5o x784prv x9v5kkp x1yxvn1h x13iak60 xb93eig", children: v ? "Committing…" : "Commit & push" })
246
+ ] }) : c ? /* @__PURE__ */ t("p", { className: "x1ghz6dp x173sf5p xq98a72 x10qp4ay x1trrqm4", children: c }) : null
247
+ ] });
107
248
  }
108
- const k = "backmatter:enter-at", ue = 1e4;
109
- function R(e, t) {
249
+ const H = "backmatter:enter-at", We = 1e4;
250
+ function Z(e, n) {
110
251
  if (typeof window > "u") return !1;
111
- const i = !!(window.top && window.top !== window);
112
- if (B(i) === "parent")
252
+ const a = !!(window.top && window.top !== window);
253
+ if (ke(a) === "parent")
113
254
  return window.parent.postMessage({
114
- type: F
255
+ type: qe
115
256
  }, window.location.origin), !0;
116
- const a = Number(window.sessionStorage.getItem(k) ?? 0);
117
- return Date.now() - a < ue ? !1 : (window.sessionStorage.setItem(k, String(Date.now())), window.location.assign(W(t, {
257
+ const o = Number(window.sessionStorage.getItem(H) ?? 0);
258
+ return Date.now() - o < We ? !1 : (window.sessionStorage.setItem(H, String(Date.now())), window.location.assign(Ee(n, {
118
259
  workspaceId: e,
119
260
  returnUrl: window.location.href
120
261
  })), !0);
121
262
  }
122
- function le(e) {
123
- const t = e.dashboardUrl ?? "https://dash.backmatter.app";
124
- return P({
263
+ function Je(e) {
264
+ const n = e.dashboardUrl ?? "https://dash.backmatter.app";
265
+ return Q({
125
266
  baseUrl: e.proxyPath ?? "/api/backmatter/cms",
126
267
  publicApiUrl: e.apiUrl,
127
268
  credentials: "same-origin",
128
269
  dev: !1,
129
270
  version: e.version,
130
- dashboardUrl: t,
271
+ dashboardUrl: n,
131
272
  onUnauthorized: ({
132
- status: i
273
+ status: a
133
274
  }) => {
134
- i === 401 && R(e.workspaceId, t);
275
+ a === 401 && Z(e.workspaceId, n);
135
276
  }
136
- }), w();
277
+ }), P();
137
278
  }
138
- function Ee(e) {
139
- const t = e.basePath ?? "/backmatter", [i] = S(() => le(e));
140
- return /* @__PURE__ */ r(te, { definition: e.studio, children: /* @__PURE__ */ l(H, { children: [
141
- /* @__PURE__ */ r(ie, {}),
142
- /* @__PURE__ */ r(A, { basename: t, children: /* @__PURE__ */ r(fe, { ...e }) })
279
+ function nt(e) {
280
+ const n = e.basePath ?? "/backmatter", [a] = g(() => Je(e));
281
+ return /* @__PURE__ */ t(_e, { definition: e.studio, children: /* @__PURE__ */ d(ye, { children: [
282
+ /* @__PURE__ */ t(Oe, {}),
283
+ /* @__PURE__ */ t(ve, { basename: n, children: /* @__PURE__ */ t(Xe, { ...e }) })
143
284
  ] }) });
144
285
  }
145
- function fe(e) {
146
- const t = V(), i = e.dashboardUrl ?? "https://dash.backmatter.app", [a, n] = S("loading");
147
- if (u(() => {
148
- let d = !1;
149
- const h = w().onUnauthorized;
150
- return P({
151
- ...w(),
152
- onUnauthorized: (s) => {
153
- s.status === 426 ? n("outdated") : h == null || h(s);
286
+ function Xe(e) {
287
+ const n = ze(), a = e.dashboardUrl ?? "https://dash.backmatter.app", [o, r] = g("loading");
288
+ if (f(() => {
289
+ let m = !1;
290
+ const w = P().onUnauthorized;
291
+ return Q({
292
+ ...P(),
293
+ onUnauthorized: (c) => {
294
+ c.status === 426 ? r("outdated") : w == null || w(c);
154
295
  }
155
- }), j().then(async (s) => {
156
- if (d) return;
157
- if (!(s != null && s.user)) {
158
- R(e.workspaceId, i) || n("unauthorized");
296
+ }), Ce().then(async (c) => {
297
+ if (m) return;
298
+ if (!(c != null && c.user)) {
299
+ Z(e.workspaceId, a) || r("unauthorized");
159
300
  return;
160
301
  }
161
302
  const {
162
- workspace: U
163
- } = await q(e.workspaceId);
164
- d || n({
303
+ workspace: p
304
+ } = await Y(e.workspaceId);
305
+ m || r({
165
306
  user: {
166
- id: s.user.id,
167
- email: s.user.email
307
+ id: c.user.id,
308
+ email: c.user.email
168
309
  },
169
- slug: U.slug
310
+ slug: p.slug
170
311
  });
171
312
  }).catch(() => {
172
- d || n((s) => s === "outdated" ? s : "unauthorized");
313
+ m || r((c) => c === "outdated" ? c : "unauthorized");
173
314
  }), () => {
174
- d = !0;
315
+ m = !0;
175
316
  };
176
- }, [e.workspaceId, i]), a === "loading") return /* @__PURE__ */ r($, {});
177
- if (a === "outdated")
178
- return /* @__PURE__ */ l(y, { title: "This site's editor is out of date", children: [
317
+ }, [e.workspaceId, a]), o === "loading") return /* @__PURE__ */ t(Ne, {});
318
+ if (o === "outdated")
319
+ return /* @__PURE__ */ d(V, { title: "This site's editor is out of date", children: [
179
320
  "Update ",
180
- /* @__PURE__ */ r("code", { children: "@backmatter/studio" }),
321
+ /* @__PURE__ */ t("code", { children: "@backmatter/studio" }),
181
322
  " and ",
182
- /* @__PURE__ */ r("code", { children: "@backmatter/next" }),
323
+ /* @__PURE__ */ t("code", { children: "@backmatter/next" }),
183
324
  " on the site, then reload."
184
325
  ] });
185
- if (a === "unauthorized")
186
- return /* @__PURE__ */ l(y, { title: "Could not start editing", children: [
326
+ if (o === "unauthorized")
327
+ return /* @__PURE__ */ d(V, { title: "Could not start editing", children: [
187
328
  "The site did not receive a session from the dashboard. Check that this site's origin is listed in the workspace settings and that ",
188
- /* @__PURE__ */ r("code", { children: "/api/backmatter" }),
329
+ /* @__PURE__ */ t("code", { children: "/api/backmatter" }),
189
330
  " routes are deployed."
190
331
  ] });
191
- const o = t.pathname.match(/^\/embed\/chat\/([^/]+)\/?$/);
192
- if (o != null && o[1])
193
- return /* @__PURE__ */ r(ae, { workspaceId: decodeURIComponent(o[1]) });
194
- const c = t.pathname.match(/^\/embed\/publish\/([^/]+)\/?$/);
195
- return c != null && c[1] ? /* @__PURE__ */ r(ne, { workspaceId: decodeURIComponent(c[1]) }) : /* @__PURE__ */ r(K, { user: a.user, children: /* @__PURE__ */ r(X, { children: /* @__PURE__ */ r(Y, { userId: a.user.id, email: a.user.email, onLogout: () => {
196
- he(e.previewEntryPath ?? "/api/backmatter/preview", i);
197
- }, children: /* @__PURE__ */ l(G, { children: [
198
- /* @__PURE__ */ r(m, { path: "/", element: /* @__PURE__ */ r(b, { to: `/${a.slug}`, replace: !0 }) }),
199
- /* @__PURE__ */ r(m, { path: "/workspaces/:workspaceId/*", element: /* @__PURE__ */ r(Q, {}) }),
200
- J(),
201
- /* @__PURE__ */ r(m, { path: "*", element: /* @__PURE__ */ r(b, { to: "/", replace: !0 }) })
332
+ const s = n.pathname.match(/^\/embed\/chat\/([^/]+)\/?$/);
333
+ if (s != null && s[1])
334
+ return /* @__PURE__ */ t(Ae, { workspaceId: decodeURIComponent(s[1]) });
335
+ const h = n.pathname.match(/^\/embed\/publish\/([^/]+)\/?$/);
336
+ return h != null && h[1] ? /* @__PURE__ */ t(Ve, { workspaceId: decodeURIComponent(h[1]) }) : /* @__PURE__ */ t(Se, { user: o.user, children: /* @__PURE__ */ t(Re, { children: /* @__PURE__ */ t(Le, { userId: o.user.id, email: o.user.email, onLogout: () => {
337
+ Ye(e.previewEntryPath ?? "/api/backmatter/preview", a);
338
+ }, children: /* @__PURE__ */ d(Pe, { children: [
339
+ /* @__PURE__ */ t(S, { path: "/", element: /* @__PURE__ */ t(I, { to: `/${o.slug}`, replace: !0 }) }),
340
+ /* @__PURE__ */ t(S, { path: "/workspaces/:workspaceId/*", element: /* @__PURE__ */ t(Ue, {}) }),
341
+ je(),
342
+ /* @__PURE__ */ t(S, { path: "*", element: /* @__PURE__ */ t(I, { to: "/", replace: !0 }) })
202
343
  ] }) }) }) });
203
344
  }
204
- async function he(e, t) {
345
+ async function Ye(e, n) {
205
346
  try {
206
347
  await fetch(e, {
207
348
  method: "POST",
@@ -209,23 +350,23 @@ async function he(e, t) {
209
350
  });
210
351
  } catch {
211
352
  }
212
- Z.wipe(), window.location.assign(t);
353
+ Te.wipe(), window.location.assign(n);
213
354
  }
214
- function y({
355
+ function V({
215
356
  title: e,
216
- children: t
357
+ children: n
217
358
  }) {
218
- return /* @__PURE__ */ r("div", { className: "x1ov3xa9 xrvj5dj x1ku5rj1 x1t7e3gq", children: /* @__PURE__ */ l("div", { className: "x78zum5 xdt5ytf x1ndbd79 xq2pcee x1t7e3gq x4pepcl x1d0qn7y", children: [
219
- /* @__PURE__ */ r(E, { size: "lg", weight: "medium", children: e }),
220
- /* @__PURE__ */ r(E, { tone: "muted", children: t })
359
+ return /* @__PURE__ */ t("div", { className: "x1ov3xa9 xrvj5dj x1ku5rj1 x1t7e3gq", children: /* @__PURE__ */ d("div", { className: "x78zum5 xdt5ytf x1ndbd79 xq2pcee x1t7e3gq x4pepcl x1d0qn7y", children: [
360
+ /* @__PURE__ */ t(F, { size: "lg", weight: "medium", children: e }),
361
+ /* @__PURE__ */ t(F, { tone: "muted", children: n })
221
362
  ] }) });
222
363
  }
223
364
  export {
224
- Ee as SiteStudio,
225
- Se as apiUrl,
226
- R as bounceToEnter,
227
- le as configureSiteStudio,
228
- P as configureStudio,
229
- Pe as defineStudio,
230
- w as studioConfig
365
+ nt as SiteStudio,
366
+ ot as apiUrl,
367
+ Z as bounceToEnter,
368
+ Je as configureSiteStudio,
369
+ Q as configureStudio,
370
+ st as defineStudio,
371
+ P as studioConfig
231
372
  };