@backmatter/studio 0.0.3 → 0.0.5

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,294 @@
1
+ import { jsxs as p, jsx as n, Fragment as N } from "react/jsx-runtime";
2
+ import { useRef as m, useState as w, useLayoutEffect as O, useEffect as f } from "react";
3
+ import { c as z, a as T, p as W, l as _, P as B, S as D, m as H, T as M, E as V, C as G, b as U, d as j, e as q, u as J, D as I, f as S, i as $, g as y, h as K, j as Y } from "./chunks/status-bar-action-DiXhfcj3.js";
4
+ import { E as Q } from "./chunks/EmbedPublishPage-hx1xoAhI.js";
5
+ const t = "backmatter-devbar";
6
+ function be({
7
+ doc: e,
8
+ branch: o,
9
+ tree: r,
10
+ exiting: c,
11
+ onExit: u,
12
+ onDocChanged: s,
13
+ onSessionExpired: b,
14
+ proxyPath: x = "/api/backmatter/cms",
15
+ version: i
16
+ }) {
17
+ const l = m(b);
18
+ l.current = b, w(() => (z({
19
+ baseUrl: x.replace(/\/+$/, ""),
20
+ credentials: "same-origin",
21
+ dev: !1,
22
+ version: i,
23
+ onUnauthorized: ({
24
+ status: a
25
+ }) => {
26
+ var h;
27
+ a === 401 && ((h = l.current) == null || h.call(l));
28
+ }
29
+ }), !0)), O(() => T(document.documentElement, W(_).className), []);
30
+ const [d, g] = w(!1), [k, v] = w(!1), [C, P] = w(0), A = e ? `${e.type}/${e.slug}` : "No document";
31
+ function R() {
32
+ s == null || s();
33
+ }
34
+ f(() => {
35
+ function a(h) {
36
+ q(h) === "chat" && (h.preventDefault(), v(!1), g((L) => !L));
37
+ }
38
+ return document.addEventListener("keydown", a, !0), () => document.removeEventListener("keydown", a, !0);
39
+ }, []);
40
+ const F = /* @__PURE__ */ p("footer", { "aria-label": "Backmatter", className: t, style: oe, children: [
41
+ /* @__PURE__ */ n("span", { style: ae, children: A }),
42
+ /* @__PURE__ */ n(E, { children: "Preview" }),
43
+ o ? /* @__PURE__ */ n(E, { children: o }) : null,
44
+ r ? /* @__PURE__ */ n(E, { children: "draft" }) : null,
45
+ /* @__PURE__ */ p("button", { type: "button", className: `${t}-btn${k ? ` ${t}-on` : ""}`, "aria-pressed": k, disabled: !e, onClick: () => {
46
+ g(!1), v((a) => !a);
47
+ }, children: [
48
+ /* @__PURE__ */ n(B, {}),
49
+ /* @__PURE__ */ p("span", { children: [
50
+ "Publish",
51
+ C ? ` ${C}` : ""
52
+ ] })
53
+ ] }),
54
+ /* @__PURE__ */ p("button", { type: "button", className: `${t}-btn ${t}-agent${d ? ` ${t}-on` : ""}`, "aria-pressed": d, "aria-keyshortcuts": "Meta+J Control+J", disabled: !e, onClick: () => {
55
+ v(!1), g((a) => !a);
56
+ }, children: [
57
+ /* @__PURE__ */ n(D, {}),
58
+ /* @__PURE__ */ n("span", { children: "Agent" }),
59
+ /* @__PURE__ */ p("kbd", { children: [
60
+ H(),
61
+ "J"
62
+ ] })
63
+ ] }),
64
+ /* @__PURE__ */ n("button", { type: "button", "aria-label": "Exit preview", disabled: c, onClick: u, style: re, children: "Exit" })
65
+ ] });
66
+ return /* @__PURE__ */ p(N, { children: [
67
+ /* @__PURE__ */ n("style", { children: le }),
68
+ e ? /* @__PURE__ */ n(M, { children: /* @__PURE__ */ n(V, { children: /* @__PURE__ */ p(G, { workspaceId: e.workspaceId, pointer: !0, children: [
69
+ /* @__PURE__ */ n(X, { doc: e }),
70
+ /* @__PURE__ */ n(Z, { onDocChanged: R }),
71
+ /* @__PURE__ */ n(ee, { open: d }),
72
+ /* @__PURE__ */ n(te, { onClose: () => g(!1) }),
73
+ /* @__PURE__ */ n(ne, { doc: e }),
74
+ /* @__PURE__ */ n(U, { children: d ? /* @__PURE__ */ n(j, { site: !0 }) : null })
75
+ ] }) }) }) : null,
76
+ e ? /* @__PURE__ */ n("div", { "data-backmatter-panel": "", hidden: !k, style: se, children: /* @__PURE__ */ n(Q, { workspaceId: e.workspaceId, onStatus: ({
77
+ changeCount: a
78
+ }) => P(a), onPublished: () => {
79
+ v(!1), P(0), R();
80
+ } }) }) : null,
81
+ F
82
+ ] });
83
+ }
84
+ function X({
85
+ doc: e
86
+ }) {
87
+ const {
88
+ setFocus: o
89
+ } = J();
90
+ return f(() => {
91
+ o({
92
+ docRef: {
93
+ locale: e.locale,
94
+ type: e.type,
95
+ slug: e.slug
96
+ },
97
+ frontmatter: {},
98
+ body: "",
99
+ selection: null
100
+ });
101
+ }, [e.locale, e.type, e.slug, o]), null;
102
+ }
103
+ function Z({
104
+ onDocChanged: e
105
+ }) {
106
+ const o = m(e);
107
+ return o.current = e, f(() => {
108
+ function r() {
109
+ o.current();
110
+ }
111
+ return window.addEventListener(I, r), () => window.removeEventListener(I, r);
112
+ }, []), null;
113
+ }
114
+ function ee({
115
+ open: e
116
+ }) {
117
+ const {
118
+ dispatch: o
119
+ } = S();
120
+ return f(() => {
121
+ o({
122
+ type: e ? "open" : "close"
123
+ }), e && requestAnimationFrame(() => {
124
+ window.dispatchEvent(new Event("backmatter:chat-focus"));
125
+ });
126
+ }, [e, o]), null;
127
+ }
128
+ function te({
129
+ onClose: e
130
+ }) {
131
+ const {
132
+ panel: o
133
+ } = S(), r = o.mode, c = m(r), u = m(e);
134
+ return u.current = e, f(() => {
135
+ const s = $(c.current);
136
+ c.current = r, s && !$(r) && u.current();
137
+ }, [r]), null;
138
+ }
139
+ function ne({
140
+ doc: e
141
+ }) {
142
+ const {
143
+ addPointer: o,
144
+ panel: r
145
+ } = S(), c = $(r.mode), u = m(c), s = m(e);
146
+ return u.current = c, s.current = e, f(() => {
147
+ const b = K(document, {
148
+ bar: () => document.querySelector(`.${t}`),
149
+ ignore: (i) => !(i instanceof Element) || i.closest("[data-backmatter-panel]") ? !0 : i.closest("iframe") !== null,
150
+ onGrab: (i) => {
151
+ const l = Y(s.current, i);
152
+ l && (o(l), requestAnimationFrame(() => {
153
+ window.dispatchEvent(new Event("backmatter:chat-focus"));
154
+ }));
155
+ },
156
+ onEscape: () => {
157
+ window.dispatchEvent(new CustomEvent(y, {
158
+ detail: {
159
+ on: !1
160
+ }
161
+ }));
162
+ }
163
+ });
164
+ function x(i) {
165
+ var d;
166
+ ((d = i.detail) == null ? void 0 : d.on) && u.current ? b.arm() : b.disarm();
167
+ }
168
+ return window.addEventListener(y, x), () => {
169
+ window.removeEventListener(y, x), b.dispose();
170
+ };
171
+ }, [o]), null;
172
+ }
173
+ function E({
174
+ children: e
175
+ }) {
176
+ return /* @__PURE__ */ n("span", { style: ie, children: e });
177
+ }
178
+ const oe = {
179
+ position: "fixed",
180
+ right: "max(16px, env(safe-area-inset-right, 0px))",
181
+ bottom: 0,
182
+ zIndex: 2147483e3,
183
+ isolation: "isolate",
184
+ display: "flex",
185
+ alignItems: "center",
186
+ gap: 2,
187
+ width: "max-content",
188
+ maxWidth: "calc(100vw - 32px)",
189
+ minHeight: 36,
190
+ padding: "0 6px 0 10px",
191
+ boxSizing: "border-box",
192
+ border: "1px solid #e4e4e7",
193
+ borderRadius: "12px 12px 0 0",
194
+ background: "#ffffff",
195
+ color: "#71717a",
196
+ boxShadow: "0 10px 28px rgba(24, 24, 27, 0.12), 0 1px 2px rgba(24, 24, 27, 0.06)",
197
+ font: '12px/1 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif',
198
+ WebkitFontSmoothing: "antialiased"
199
+ }, re = {
200
+ border: 0,
201
+ borderRadius: 8,
202
+ background: "transparent",
203
+ color: "#18181b",
204
+ font: "inherit",
205
+ cursor: "pointer",
206
+ padding: "0 8px",
207
+ minHeight: 28
208
+ }, ae = {
209
+ fontWeight: 600,
210
+ color: "#18181b",
211
+ maxWidth: 200,
212
+ overflow: "hidden",
213
+ textOverflow: "ellipsis",
214
+ whiteSpace: "nowrap",
215
+ padding: "0 6px"
216
+ }, ie = {
217
+ color: "#71717a",
218
+ fontSize: 12,
219
+ margin: 0,
220
+ padding: "0 6px",
221
+ maxWidth: 140,
222
+ overflow: "hidden",
223
+ textOverflow: "ellipsis",
224
+ whiteSpace: "nowrap"
225
+ }, se = {
226
+ position: "fixed",
227
+ right: "max(16px, env(safe-area-inset-right, 0px))",
228
+ bottom: "calc(env(safe-area-inset-bottom, 0px) + 48px)",
229
+ zIndex: 2147483001,
230
+ width: "min(320px, calc(100vw - 32px))",
231
+ maxHeight: "min(420px, calc(100vh - 80px))",
232
+ overflow: "auto",
233
+ border: "1px solid #e4e4e7",
234
+ borderRadius: 10,
235
+ background: "#ffffff",
236
+ boxShadow: "0 16px 40px rgba(24, 24, 27, 0.14), 0 2px 8px rgba(24, 24, 27, 0.06)"
237
+ }, le = `
238
+ @keyframes backmatter-devbar-in {
239
+ from { opacity: 0; transform: translateY(10px) scale(0.98); }
240
+ to { opacity: 1; transform: none; }
241
+ }
242
+ .${t} { animation: backmatter-devbar-in 240ms cubic-bezier(0.23, 1, 0.32, 1) both; }
243
+ @media (prefers-reduced-motion: reduce) {
244
+ .${t} { animation: none; }
245
+ }
246
+ .${t}-btn {
247
+ display: inline-flex;
248
+ align-items: center;
249
+ gap: 6px;
250
+ height: 26px;
251
+ margin-inline: 4px;
252
+ padding: 0 8px;
253
+ border: 1px solid #e4e4e7;
254
+ border-radius: 6px;
255
+ background: #ffffff;
256
+ color: #18181b;
257
+ font-size: 11px;
258
+ font-weight: 500;
259
+ line-height: 1;
260
+ cursor: pointer;
261
+ }
262
+ .${t}-agent kbd {
263
+ font-family: Geist Mono, ui-monospace, SFMono-Regular, Menlo, monospace;
264
+ font-size: 11px;
265
+ font-weight: 400;
266
+ opacity: 0.7;
267
+ }
268
+ .${t} button.${t}-on,
269
+ .${t} button.${t}-on:hover:not(:disabled) {
270
+ background: #18181b;
271
+ border-color: #18181b;
272
+ color: #fafafa;
273
+ }
274
+ @media (hover: hover) {
275
+ .${t} button:hover:not(:disabled) { background: #f4f4f5; }
276
+ .${t} button.${t}-btn:hover:not(:disabled) {
277
+ background: rgba(24, 24, 27, 0.05);
278
+ }
279
+ .${t} button.${t}-on:hover:not(:disabled) {
280
+ background: #18181b;
281
+ }
282
+ }
283
+ .${t} button:focus-visible { outline: 2px solid #18181b; outline-offset: 2px; }
284
+ .${t} button:disabled { cursor: default; opacity: 0.5; }
285
+ html.backmatter-pointing, html.backmatter-pointing * { cursor: crosshair !important; }
286
+ html.backmatter-pointing .${t},
287
+ html.backmatter-pointing .${t} *,
288
+ html.backmatter-pointing [data-backmatter-panel],
289
+ html.backmatter-pointing [data-backmatter-panel] * { cursor: pointer !important; }
290
+ html.backmatter-pointing .${t} button:disabled { cursor: default !important; }
291
+ `;
292
+ export {
293
+ be as SiteWidget
294
+ };