sanity-plugin-visual-editor 1.0.0 → 1.1.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/LICENSE +1 -1
- package/README.md +137 -16
- package/TESTING.md +133 -0
- package/dist/PreviewBar-D_rw0bhP.js +3503 -0
- package/dist/PreviewBar-D_rw0bhP.js.map +1 -0
- package/dist/bar.d.ts +22 -0
- package/dist/bar.js +67 -0
- package/dist/bar.js.map +1 -0
- package/dist/cloudflare.d.ts +76 -0
- package/dist/cloudflare.js +1071 -0
- package/dist/cloudflare.js.map +1 -0
- package/dist/data-D0qotTtt.d.ts +177 -0
- package/dist/host-DreYJEmR.js +615 -0
- package/dist/host-DreYJEmR.js.map +1 -0
- package/dist/host.d.ts +160 -0
- package/dist/host.js +3 -0
- package/dist/index-4Zm_NjhC.d.ts +221 -0
- package/dist/index.d.ts +18 -18
- package/dist/index.js +7 -8
- package/dist/link-search-JtZkxz4k.js +14 -0
- package/dist/link-search-JtZkxz4k.js.map +1 -0
- package/dist/link-session-Dr4YkKFy.js +52 -0
- package/dist/link-session-Dr4YkKFy.js.map +1 -0
- package/dist/next-client.d.ts +15 -0
- package/dist/next-client.js +78 -0
- package/dist/next-client.js.map +1 -0
- package/dist/next.d.ts +38 -0
- package/dist/next.js +117 -0
- package/dist/next.js.map +1 -0
- package/dist/node-labels-CDiW5rMq.js +122 -0
- package/dist/node-labels-CDiW5rMq.js.map +1 -0
- package/dist/page-documents-BFFcH8lD.d.ts +54 -0
- package/dist/page-documents-mGfw_flR.js +67 -0
- package/dist/page-documents-mGfw_flR.js.map +1 -0
- package/dist/perspective-BmS9TVtr.js +106 -0
- package/dist/perspective-BmS9TVtr.js.map +1 -0
- package/dist/preview-links-BZDZyIey.js +119 -0
- package/dist/preview-links-BZDZyIey.js.map +1 -0
- package/dist/preview-links-DM6BCiLV.d.ts +87 -0
- package/dist/protocol-BNO38gYy.js +280 -0
- package/dist/protocol-BNO38gYy.js.map +1 -0
- package/dist/protocol-BnRCy2wJ.d.ts +386 -0
- package/dist/server.d.ts +4 -0
- package/dist/server.js +495 -0
- package/dist/server.js.map +1 -0
- package/dist/shell-DZotxRXX.d.ts +37 -0
- package/dist/studio.d.ts +93 -0
- package/dist/studio.js +1263 -0
- package/dist/studio.js.map +1 -0
- package/dist/sveltekit.d.ts +281 -0
- package/dist/sveltekit.js +395 -0
- package/dist/sveltekit.js.map +1 -0
- package/package.json +120 -39
- package/dist/index.d.mts +0 -21
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -8
- package/dist/index.mjs.map +0 -1
- package/sanity.json +0 -8
- package/src/index.ts +0 -27
- package/v2-incompatible.js +0 -11
|
@@ -0,0 +1,3503 @@
|
|
|
1
|
+
import { D as toUrlPath, E as toStudioPath, T as toPanePath, d as isPreviewBarMessage, l as isInspectorShortcut, p as readPreviewBarPosition, w as studioPathToString } from "./protocol-BNO38gYy.js";
|
|
2
|
+
import { a as RELEASE_TYPES, c as parsePerspective, d as releaseIdOf, f as releaseTone, l as perspectiveStack, m as serializePerspective, p as selectionOf, r as PUBLISHED, s as isScheduledDraft, t as DRAFTS, u as perspectiveTone } from "./perspective-BmS9TVtr.js";
|
|
3
|
+
import { StrictMode, Suspense, cloneElement, createContext, createElement, forwardRef, isValidElement, lazy, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { createRoot } from "react-dom/client";
|
|
5
|
+
import EllipsisHorizontalIcon from "@sanity/icons/EllipsisHorizontal";
|
|
6
|
+
import EyeClosedIcon from "@sanity/icons/EyeClosed";
|
|
7
|
+
import LeaveIcon from "@sanity/icons/Leave";
|
|
8
|
+
import { Box, Button, Card, Flex, Grid, Hotkeys, Label, LayerProvider, Spinner, Stack, Switch, Text, TextInput, TextSkeleton, ThemeProvider, useClickOutsideEvent, usePrefersDark } from "@sanity/ui";
|
|
9
|
+
import { Menu, MenuButton, MenuDivider, MenuItem } from "@sanity/ui/menu";
|
|
10
|
+
import AddIcon from "@sanity/icons/Add";
|
|
11
|
+
import BoltIcon from "@sanity/icons/Bolt";
|
|
12
|
+
import CalendarIcon from "@sanity/icons/Calendar";
|
|
13
|
+
import ChevronDownIcon from "@sanity/icons/ChevronDown";
|
|
14
|
+
import ClockIcon from "@sanity/icons/Clock";
|
|
15
|
+
import EyeOpenIcon from "@sanity/icons/EyeOpen";
|
|
16
|
+
import SearchIcon from "@sanity/icons/Search";
|
|
17
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
18
|
+
import { Tooltip } from "@sanity/ui/tooltip";
|
|
19
|
+
import CheckmarkCircleIcon from "@sanity/icons/CheckmarkCircle";
|
|
20
|
+
import CopyIcon from "@sanity/icons/Copy";
|
|
21
|
+
import ErrorOutlineIcon from "@sanity/icons/ErrorOutline";
|
|
22
|
+
import ShareIcon from "@sanity/icons/Share";
|
|
23
|
+
import { SanityMonogram } from "@sanity/logos";
|
|
24
|
+
import { Popover } from "@sanity/ui/popover";
|
|
25
|
+
import { createPortal } from "react-dom";
|
|
26
|
+
import "@sanity/ui/styles.css";
|
|
27
|
+
import { buildTheme } from "@sanity/ui/theme";
|
|
28
|
+
import { ToastProvider, useToast } from "@sanity/ui/toast";
|
|
29
|
+
import AddUserIcon from "@sanity/icons/AddUser";
|
|
30
|
+
import CogIcon from "@sanity/icons/Cog";
|
|
31
|
+
import CodeIcon from "@sanity/icons/Code";
|
|
32
|
+
import DocumentIcon from "@sanity/icons/Document";
|
|
33
|
+
import HomeIcon from "@sanity/icons/Home";
|
|
34
|
+
import DesktopIcon from "@sanity/icons/Desktop";
|
|
35
|
+
import MobileDeviceIcon from "@sanity/icons/MobileDevice";
|
|
36
|
+
import TabletDeviceIcon from "@sanity/icons/TabletDevice";
|
|
37
|
+
/**
|
|
38
|
+
* Document base for the pages that render pure Sanity UI (the bar's frame, the expired-link page).
|
|
39
|
+
* No site CSS loads there, so no Tailwind preflight: box model, the Studio's font smoothing and
|
|
40
|
+
* Inter from Sanity's CDN, the faces the standalone Studio document declares
|
|
41
|
+
* (`@sanity/cli-build` DefaultDocument). Injected once per document by the mount functions.
|
|
42
|
+
*/
|
|
43
|
+
const BASE_CSS = `
|
|
44
|
+
*, *::before, *::after { box-sizing: border-box; }
|
|
45
|
+
html, body {
|
|
46
|
+
margin: 0;
|
|
47
|
+
-webkit-font-smoothing: antialiased;
|
|
48
|
+
-moz-osx-font-smoothing: grayscale;
|
|
49
|
+
}
|
|
50
|
+
${[
|
|
51
|
+
[400, "Regular"],
|
|
52
|
+
[500, "Medium"],
|
|
53
|
+
[600, "SemiBold"]
|
|
54
|
+
].map(([weight, name]) => `@font-face { font-family: Inter; font-style: normal; font-weight: ${weight}; font-display: swap; src: url('https://studio-static.sanity.io/Inter-${name}.woff2') format('woff2'); }`).join("\n")}
|
|
55
|
+
`;
|
|
56
|
+
function injectStudioDocumentCss(document, { transparent = !1 } = {}) {
|
|
57
|
+
if (document.getElementById("sanity-plugin-visual-editor-document")) return;
|
|
58
|
+
let style = document.createElement("style");
|
|
59
|
+
style.id = "sanity-plugin-visual-editor-document", style.textContent = transparent ? BASE_CSS + "\n:root { color-scheme: normal; }\nhtml, body { height: 100%; overflow: hidden; background: transparent; }\n" : BASE_CSS, document.head.appendChild(style);
|
|
60
|
+
}
|
|
61
|
+
function isStylesheet(node) {
|
|
62
|
+
return node.localName === "style" || node.localName === "link" && /\bstylesheet\b/.test(node.rel);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Keeps styled-components' `<style>` tags after every other stylesheet in the frame's `<head>`, the
|
|
66
|
+
* order a standalone Studio page has (its CSS is in the HTML; styled-components appends at runtime).
|
|
67
|
+
*
|
|
68
|
+
* Studio components show and hide parts with styled-components rules that tie, on specificity,
|
|
69
|
+
* with Sanity UI's atomic classes (`.eBwYdj [data-ui="Select"] { display: none }` against
|
|
70
|
+
* `.u-…:not([hidden]) { display: inline-block }`), so the later stylesheet wins. Here `sanity` loads
|
|
71
|
+
* lazily and its CSS lands after styled-components' tag, which showed both the field-group tabs and
|
|
72
|
+
* their narrow-width select. Other stylesheets move in front of the styled tags; those tags never
|
|
73
|
+
* move, since moving one would drop the rules styled-components inserts through the CSSOM.
|
|
74
|
+
*/
|
|
75
|
+
function keepStyledComponentsLast(document) {
|
|
76
|
+
let head = document.head;
|
|
77
|
+
function reorder() {
|
|
78
|
+
let styled = head.querySelector("style[data-styled]");
|
|
79
|
+
if (!styled) return;
|
|
80
|
+
let node = styled.nextElementSibling;
|
|
81
|
+
for (; node;) {
|
|
82
|
+
let next = node.nextElementSibling;
|
|
83
|
+
isStylesheet(node) && !node.hasAttribute("data-styled") && head.insertBefore(node, styled), node = next;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
let observer = new MutationObserver(reorder);
|
|
87
|
+
return observer.observe(head, { childList: !0 }), reorder(), () => observer.disconnect();
|
|
88
|
+
}
|
|
89
|
+
const BarDataContext = createContext(null);
|
|
90
|
+
/** The bar's data: brand, Studio path, endpoints, search kinds. */
|
|
91
|
+
function useBarData() {
|
|
92
|
+
let data = useContext(BarDataContext);
|
|
93
|
+
if (!data) throw Error("sanity-visual-editor: useBarData outside the bar");
|
|
94
|
+
return data;
|
|
95
|
+
}
|
|
96
|
+
/** Which edge the bar sits on (the host sets it; `readPreviewBarPosition`). */
|
|
97
|
+
const BarPositionContext = createContext("bottom");
|
|
98
|
+
/**
|
|
99
|
+
* A popover placement written for the bottom bar (menus and tooltips open upward), flipped to
|
|
100
|
+
* open downward when the bar is at the top.
|
|
101
|
+
*/
|
|
102
|
+
function useBarPlacement() {
|
|
103
|
+
let position = useContext(BarPositionContext);
|
|
104
|
+
return (placement) => position === "top" ? placement.replace("top", "bottom") : placement;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Whether the viewer is signed in to the project's embedded Studio, read the way the Studio's auth
|
|
108
|
+
* store does (`sanity@6.23`): a token in `localStorage` under `__studio_auth_token_<projectId>`
|
|
109
|
+
* (token login), or Sanity's session cookie on the project API (cookie login). The bar runs on the
|
|
110
|
+
* Studio's origin, so it sees the same session. Shared-link guests usually have none.
|
|
111
|
+
*/
|
|
112
|
+
const AUTH_KEY_PREFIX = "__studio_auth_";
|
|
113
|
+
function storedToken(projectId) {
|
|
114
|
+
try {
|
|
115
|
+
let raw = window.localStorage.getItem(`${AUTH_KEY_PREFIX}token_${projectId}`), token = raw ? JSON.parse(raw).token : void 0;
|
|
116
|
+
return typeof token == "string" && token ? token : void 0;
|
|
117
|
+
} catch {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** A `/users/me` check that didn't say either way (a 429, a 5xx, the network). */
|
|
122
|
+
var SessionCheckError = class extends Error {
|
|
123
|
+
status;
|
|
124
|
+
constructor(status) {
|
|
125
|
+
super(status ? `Studio session check failed (${status})` : "Studio session check failed"), this.status = status, this.name = "SessionCheckError";
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* The signed-in user, or `null` when the API says there's none (401/403, or a body without a
|
|
130
|
+
* user: an anonymous session). Anything else (rate limits, server errors, network failures) throws
|
|
131
|
+
* `SessionCheckError`, so callers can keep the session they already know.
|
|
132
|
+
*/
|
|
133
|
+
async function fetchCurrentUser(projectId) {
|
|
134
|
+
let token = storedToken(projectId), response;
|
|
135
|
+
try {
|
|
136
|
+
response = await fetch(`https://${projectId}.api.sanity.io/v2021-06-07/users/me`, {
|
|
137
|
+
...token ? { headers: { authorization: `Bearer ${token}` } } : { credentials: "include" },
|
|
138
|
+
cache: "no-store"
|
|
139
|
+
});
|
|
140
|
+
} catch {
|
|
141
|
+
throw new SessionCheckError();
|
|
142
|
+
}
|
|
143
|
+
if (response.status === 401 || response.status === 403) return null;
|
|
144
|
+
if (!response.ok) throw new SessionCheckError(response.status);
|
|
145
|
+
let user;
|
|
146
|
+
try {
|
|
147
|
+
user = await response.json();
|
|
148
|
+
} catch {
|
|
149
|
+
throw new SessionCheckError(response.status);
|
|
150
|
+
}
|
|
151
|
+
return user && typeof user.id == "string" ? user : null;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The next session after a check: a definite answer replaces the session; a failed check keeps
|
|
155
|
+
* the last known one (still `loading` if there isn't one yet).
|
|
156
|
+
*/
|
|
157
|
+
function nextSession(current, result) {
|
|
158
|
+
return "user" in result ? result.user ? {
|
|
159
|
+
status: "signed-in",
|
|
160
|
+
user: result.user
|
|
161
|
+
} : { status: "signed-out" } : current;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The Studio session, rechecked when another window of this origin changes Studio auth (the
|
|
165
|
+
* sign-in popup writing its token or cookie state), and when this window regains focus.
|
|
166
|
+
*/
|
|
167
|
+
function useStudioSession(projectId, { enabled = !0 } = {}) {
|
|
168
|
+
let [session, setSession] = useState({ status: "loading" }), latest = useRef(0), refresh = useCallback(async () => {
|
|
169
|
+
if (!enabled) return;
|
|
170
|
+
if (!projectId) return setSession({ status: "signed-out" });
|
|
171
|
+
let request = ++latest.current, result;
|
|
172
|
+
try {
|
|
173
|
+
result = { user: await fetchCurrentUser(projectId) };
|
|
174
|
+
} catch (error) {
|
|
175
|
+
result = { error };
|
|
176
|
+
}
|
|
177
|
+
request === latest.current && setSession((current) => nextSession(current, result));
|
|
178
|
+
}, [projectId, enabled]);
|
|
179
|
+
return useEffect(() => {
|
|
180
|
+
if (!enabled) return;
|
|
181
|
+
refresh();
|
|
182
|
+
let onStorage = (event) => {
|
|
183
|
+
event.key?.startsWith(AUTH_KEY_PREFIX) && refresh();
|
|
184
|
+
}, onFocus = () => void refresh();
|
|
185
|
+
return window.addEventListener("storage", onStorage), window.addEventListener("focus", onFocus), () => {
|
|
186
|
+
window.removeEventListener("storage", onStorage), window.removeEventListener("focus", onFocus);
|
|
187
|
+
};
|
|
188
|
+
}, [refresh, enabled]), {
|
|
189
|
+
session,
|
|
190
|
+
refresh
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Opens the embedded Studio's own sign-in screen in a popup. The Studio completes the provider
|
|
195
|
+
* redirect itself; `onDone` runs (and the popup closes) once this window sees the session, or
|
|
196
|
+
* the popup is closed. When popups are blocked it opens a tab and calls `onDone` at once (the
|
|
197
|
+
* session is rechecked on focus). Returns a function that stops watching (call it on unmount).
|
|
198
|
+
*/
|
|
199
|
+
function openStudioSignIn(studioPath, check, onDone) {
|
|
200
|
+
let popup = window.open(studioPath, "sanity-plugin-visual-editor-sign-in", "popup,width=480,height=720");
|
|
201
|
+
if (!popup) return window.open(studioPath, "_blank"), onDone(), () => {};
|
|
202
|
+
let stopped = !1, checking = !1, stop = () => {
|
|
203
|
+
stopped = !0, window.clearInterval(timer);
|
|
204
|
+
}, timer = window.setInterval(async () => {
|
|
205
|
+
if (stopped || checking) return;
|
|
206
|
+
if (popup.closed) {
|
|
207
|
+
stop(), onDone();
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
checking = !0;
|
|
211
|
+
let signedIn = !1;
|
|
212
|
+
try {
|
|
213
|
+
signedIn = await check();
|
|
214
|
+
} catch {} finally {
|
|
215
|
+
checking = !1;
|
|
216
|
+
}
|
|
217
|
+
signedIn && !stopped && (stop(), popup.close(), onDone());
|
|
218
|
+
}, 1500);
|
|
219
|
+
return stop;
|
|
220
|
+
}
|
|
221
|
+
const WIDTH_KEY = "sanity-visual-editor:pane-width", OPEN_KEY = "sanity-visual-editor:pane-open";
|
|
222
|
+
function readNumber(key) {
|
|
223
|
+
try {
|
|
224
|
+
let value = Number(window.localStorage.getItem(key));
|
|
225
|
+
return Number.isFinite(value) && value > 0 ? value : null;
|
|
226
|
+
} catch {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function store(storage, key, value) {
|
|
231
|
+
try {
|
|
232
|
+
value === null ? window[storage].removeItem(key) : window[storage].setItem(key, value);
|
|
233
|
+
} catch {}
|
|
234
|
+
}
|
|
235
|
+
function readOpen() {
|
|
236
|
+
try {
|
|
237
|
+
return window.sessionStorage.getItem(OPEN_KEY) === "1";
|
|
238
|
+
} catch {
|
|
239
|
+
return !1;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* The pane's actual width for a preferred width and viewport. Beside the page it keeps the page at
|
|
244
|
+
* least `PREVIEW_PANEL_MIN_PAGE_WIDTH` wide; when even the narrowest pane can't, it overlays the
|
|
245
|
+
* page (not resizable) instead.
|
|
246
|
+
*/
|
|
247
|
+
function panelLayout(preferred, viewport) {
|
|
248
|
+
if (viewport - 320 < 360) return {
|
|
249
|
+
width: Math.min(420, viewport),
|
|
250
|
+
beside: !1
|
|
251
|
+
};
|
|
252
|
+
let max = viewport - 360;
|
|
253
|
+
return {
|
|
254
|
+
width: Math.round(Math.min(Math.max(preferred, 320), max)),
|
|
255
|
+
beside: !0
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function useViewportWidth() {
|
|
259
|
+
let [width, setWidth] = useState(() => window.innerWidth);
|
|
260
|
+
return useEffect(() => {
|
|
261
|
+
let onResize = () => setWidth(window.innerWidth);
|
|
262
|
+
return window.addEventListener("resize", onResize), () => window.removeEventListener("resize", onResize);
|
|
263
|
+
}, []), width;
|
|
264
|
+
}
|
|
265
|
+
/** A document's published ID: the pane takes it whatever version the page resolved. */
|
|
266
|
+
function publishedId(id) {
|
|
267
|
+
return id.replace(/^drafts\./, "").replace(/^versions\.[^.]+\./, "");
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* The pane's stack after a click-to-edit request. The page's document (`pageId`) opens at the
|
|
271
|
+
* path with nothing above it, keeping its other params; another document at the top is moved to
|
|
272
|
+
* the path; anything else goes on top, so × goes back to the page's. Returns `null` for a path
|
|
273
|
+
* that doesn't parse.
|
|
274
|
+
*/
|
|
275
|
+
function editStack(stack, request, pageId) {
|
|
276
|
+
let path = toPanePath(request.path);
|
|
277
|
+
if (!path) return null;
|
|
278
|
+
let id = publishedId(request.id), at = (entry) => entry?.id === id ? {
|
|
279
|
+
...entry,
|
|
280
|
+
params: {
|
|
281
|
+
...entry.params,
|
|
282
|
+
path
|
|
283
|
+
}
|
|
284
|
+
} : {
|
|
285
|
+
id,
|
|
286
|
+
type: request.documentType,
|
|
287
|
+
params: { path }
|
|
288
|
+
};
|
|
289
|
+
if (id === pageId) return [at(stack[0])];
|
|
290
|
+
let top = stack[stack.length - 1];
|
|
291
|
+
return top?.id === id ? [...stack.slice(0, -1), at(top)] : [...stack, at(void 0)];
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Applies a click-to-edit request to a pane stack held in state.
|
|
295
|
+
*
|
|
296
|
+
* A pane that mounts for the request focuses its `path` param on its own. One that stays mounted
|
|
297
|
+
* focuses only when `path` changes, and Sanity skips a focus path it believes it already has: the
|
|
298
|
+
* editor may have moved on in the form, or closed an array item's dialog (which keeps its focus
|
|
299
|
+
* path), or its open path still matches after a blur. So the path steps through its parent for
|
|
300
|
+
* one render first, which also reopens an item's dialog; a top-level field steps through a field
|
|
301
|
+
* no schema has. Checked against `sanity@6.23`'s `useDocumentForm` and `DocumentPaneProvider`.
|
|
302
|
+
*/
|
|
303
|
+
function applyEdit(current, request, pageId, setStack) {
|
|
304
|
+
let next = editStack(current, request, pageId);
|
|
305
|
+
if (!next) return;
|
|
306
|
+
let top = next[next.length - 1], shown = current[current.length - 1];
|
|
307
|
+
if (!shown || shown.id !== top.id || current.length !== next.length) {
|
|
308
|
+
setStack(() => next);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
let parent = toStudioPath(request.path).slice(0, -1), via = studioPathToString(parent.length ? parent : ["_previewBarRefocus"]);
|
|
312
|
+
setStack(() => next.map((entry, index) => index === next.length - 1 ? {
|
|
313
|
+
...entry,
|
|
314
|
+
params: {
|
|
315
|
+
...entry.params,
|
|
316
|
+
path: via
|
|
317
|
+
}
|
|
318
|
+
} : entry)), setTimeout(() => setStack((stack) => editStack(stack, request, pageId) ?? stack), 50);
|
|
319
|
+
}
|
|
320
|
+
function useDocumentPaneState({ enabled, pageDocument, setOverflow }) {
|
|
321
|
+
let viewport = useViewportWidth(), [preferred, setPreferred] = useState(() => readNumber(WIDTH_KEY) ?? 420), { width, beside } = useMemo(() => panelLayout(preferred, viewport), [preferred, viewport]), [stack, setStack] = useState([]), open = enabled && stack.length > 0, pageEntry = useMemo(() => pageDocument ? {
|
|
322
|
+
id: publishedId(pageDocument._id),
|
|
323
|
+
type: pageDocument._type,
|
|
324
|
+
params: {}
|
|
325
|
+
} : null, [pageDocument]);
|
|
326
|
+
useEffect(() => {
|
|
327
|
+
setStack((current) => pageEntry ? current.length === 0 ? readOpen() ? [pageEntry] : current : current[0]?.id === pageEntry.id ? current : [pageEntry] : current.length ? [] : current);
|
|
328
|
+
}, [pageEntry]);
|
|
329
|
+
let change = useCallback((next) => {
|
|
330
|
+
next.length === 0 && store("sessionStorage", OPEN_KEY, null), setStack(next);
|
|
331
|
+
}, []), openPane = useCallback(() => {
|
|
332
|
+
pageEntry && (store("sessionStorage", OPEN_KEY, "1"), setStack([pageEntry]));
|
|
333
|
+
}, [pageEntry]), openDocument = useCallback((entry) => {
|
|
334
|
+
store("sessionStorage", OPEN_KEY, "1"), setStack((current) => current.length ? [...current, entry] : [entry]);
|
|
335
|
+
}, []), toggle = useCallback(() => {
|
|
336
|
+
open ? change([]) : openPane();
|
|
337
|
+
}, [
|
|
338
|
+
open,
|
|
339
|
+
change,
|
|
340
|
+
openPane
|
|
341
|
+
]), latest = useRef(width);
|
|
342
|
+
latest.current = width;
|
|
343
|
+
let resizeStart = useCallback(() => setOverflow("pane-resize", !0), [setOverflow]), resizeTo = useCallback((next) => setPreferred(next), []), resizeEnd = useCallback(() => {
|
|
344
|
+
setOverflow("pane-resize", !1), setPreferred(latest.current), store("localStorage", WIDTH_KEY, String(latest.current));
|
|
345
|
+
}, [setOverflow]);
|
|
346
|
+
return {
|
|
347
|
+
stack,
|
|
348
|
+
open,
|
|
349
|
+
width,
|
|
350
|
+
beside,
|
|
351
|
+
canOpen: !!pageEntry,
|
|
352
|
+
openPane,
|
|
353
|
+
openDocument,
|
|
354
|
+
toggle,
|
|
355
|
+
change,
|
|
356
|
+
resize: beside ? {
|
|
357
|
+
start: resizeStart,
|
|
358
|
+
to: resizeTo,
|
|
359
|
+
end: resizeEnd
|
|
360
|
+
} : null
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
function SmallIcon({ name, children, ...rest }) {
|
|
364
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
365
|
+
"data-sanity-icon": name,
|
|
366
|
+
width: "1em",
|
|
367
|
+
height: "1em",
|
|
368
|
+
viewBox: "0 0 25 25",
|
|
369
|
+
fill: "none",
|
|
370
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
371
|
+
"aria-hidden": "true",
|
|
372
|
+
...rest,
|
|
373
|
+
children
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
/** Drafts. */
|
|
377
|
+
function RingIcon(props) {
|
|
378
|
+
return /* @__PURE__ */ jsx(SmallIcon, {
|
|
379
|
+
name: "ring",
|
|
380
|
+
...props,
|
|
381
|
+
children: /* @__PURE__ */ jsx("circle", {
|
|
382
|
+
cx: 12.5,
|
|
383
|
+
cy: 12.5,
|
|
384
|
+
r: 2.9,
|
|
385
|
+
stroke: "currentColor",
|
|
386
|
+
strokeWidth: 1.2
|
|
387
|
+
})
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
/** Published. */
|
|
391
|
+
function CircleSmallIcon(props) {
|
|
392
|
+
return /* @__PURE__ */ jsx(SmallIcon, {
|
|
393
|
+
name: "circle-small",
|
|
394
|
+
...props,
|
|
395
|
+
children: /* @__PURE__ */ jsx("circle", {
|
|
396
|
+
cx: 12.5,
|
|
397
|
+
cy: 12.5,
|
|
398
|
+
r: 3.5,
|
|
399
|
+
fill: "currentColor"
|
|
400
|
+
})
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
/** ASAP release. */
|
|
404
|
+
function BoltSmallIcon(props) {
|
|
405
|
+
return /* @__PURE__ */ jsx(SmallIcon, {
|
|
406
|
+
name: "bolt-small",
|
|
407
|
+
...props,
|
|
408
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
409
|
+
fillRule: "evenodd",
|
|
410
|
+
clipRule: "evenodd",
|
|
411
|
+
d: "M14.2496 6.64408C14.4167 6.52722 14.642 6.51898 14.818 6.63334C15.0184 6.76424 15.0999 7.01941 15.0143 7.24271L13.5797 10.9722H16.9283L16.9889 10.9771H16.9957C17.0202 10.9808 17.0448 10.9873 17.069 10.9947C17.2111 11.0383 17.3312 11.1433 17.3903 11.2857C17.4686 11.4754 17.4242 11.6935 17.2799 11.8384L10.8199 18.2984C10.7565 18.3618 10.6785 18.4063 10.5963 18.4292C10.5688 18.4369 10.5408 18.4419 10.5133 18.4449C10.457 18.4508 10.3992 18.4472 10.3434 18.4341C10.2873 18.4209 10.2329 18.398 10.1832 18.3658C10.0324 18.2676 9.94891 18.1 9.95275 17.9283C9.95408 17.8711 9.96557 17.813 9.98693 17.7574L11.4215 14.0269H8.08068C7.87549 14.0269 7.68973 13.9041 7.61095 13.7144C7.53245 13.5245 7.5764 13.3057 7.72131 13.1607L14.1813 6.70072L14.2496 6.64408ZM9.30529 13.0122H12.1676L12.2174 13.0152L12.2223 13.0162C12.3651 13.0338 12.4957 13.1114 12.5787 13.232C12.6615 13.3526 12.6878 13.5029 12.6529 13.6431L12.6344 13.7027L11.7926 15.8882L15.6949 11.9878H12.8404C12.8215 11.9878 12.7999 11.9866 12.7779 11.9839C12.7366 11.9788 12.6968 11.9687 12.6598 11.9546C12.6222 11.9403 12.5859 11.9211 12.5524 11.898C12.5181 11.8744 12.4875 11.8464 12.4606 11.816C12.4468 11.8004 12.4341 11.784 12.4225 11.7671C12.3278 11.6293 12.3069 11.4535 12.3668 11.2974L13.2076 9.10892L9.30529 13.0122Z",
|
|
412
|
+
fill: "currentColor"
|
|
413
|
+
})
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
/** Release at a scheduled time. */
|
|
417
|
+
function ClockSmallIcon(props) {
|
|
418
|
+
return /* @__PURE__ */ jsxs(SmallIcon, {
|
|
419
|
+
name: "clock-small",
|
|
420
|
+
...props,
|
|
421
|
+
children: [/* @__PURE__ */ jsx("path", {
|
|
422
|
+
fillRule: "evenodd",
|
|
423
|
+
clipRule: "evenodd",
|
|
424
|
+
d: "M13.1074 12.248L15.1113 14.252L14.252 15.1113L12.0703 12.9297C11.9565 12.8158 11.8926 12.6614 11.8926 12.5V9.24023H13.1074V12.248Z",
|
|
425
|
+
fill: "currentColor"
|
|
426
|
+
}), /* @__PURE__ */ jsx("path", {
|
|
427
|
+
fillRule: "evenodd",
|
|
428
|
+
clipRule: "evenodd",
|
|
429
|
+
d: "M12.5 6.79199C15.6524 6.79203 18.208 9.34762 18.208 12.5C18.208 15.6524 15.6524 18.208 12.5 18.208C9.34762 18.208 6.79203 15.6524 6.79199 12.5C6.79203 9.34762 9.34762 6.79203 12.5 6.79199ZM12.5 8.00781C10.0192 8.00785 8.00785 10.0192 8.00781 12.5C8.00785 14.9808 10.0192 16.9921 12.5 16.9922C14.9808 16.9921 16.9921 14.9808 16.9922 12.5C16.9921 10.0192 14.9808 8.00785 12.5 8.00781Z",
|
|
430
|
+
fill: "currentColor"
|
|
431
|
+
})]
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
/** Undecided release. */
|
|
435
|
+
function UnknownSmallIcon(props) {
|
|
436
|
+
return /* @__PURE__ */ jsxs(SmallIcon, {
|
|
437
|
+
name: "unknown-small",
|
|
438
|
+
...props,
|
|
439
|
+
children: [
|
|
440
|
+
/* @__PURE__ */ jsx("path", {
|
|
441
|
+
fillRule: "evenodd",
|
|
442
|
+
clipRule: "evenodd",
|
|
443
|
+
d: "M13.1074 15.0801H11.8916V13.6602H13.1074V15.0801Z",
|
|
444
|
+
fill: "currentColor"
|
|
445
|
+
}),
|
|
446
|
+
/* @__PURE__ */ jsx("path", {
|
|
447
|
+
fillRule: "evenodd",
|
|
448
|
+
clipRule: "evenodd",
|
|
449
|
+
d: "M12.5 9.17188C13.6047 9.17201 14.1278 10.1145 14.1279 10.7998C14.1279 11.1692 14.0317 11.4666 13.8545 11.7129C13.7017 11.925 13.4919 12.0813 13.3984 12.1592C13.2853 12.2535 13.2311 12.3108 13.1924 12.3818C13.1555 12.4495 13.1075 12.5788 13.1074 12.8398V13.04H11.8916C11.8916 13.04 11.8916 13.2582 11.8916 12.8398C11.8916 12.4215 11.9716 12.0828 12.126 11.7998C12.2782 11.5208 12.4788 11.3442 12.6211 11.2256C12.785 11.089 12.829 11.0549 12.8672 11.002C12.8775 10.9875 12.8866 10.9709 12.8945 10.9453C12.903 10.9177 12.9121 10.8727 12.9121 10.7998C12.912 10.6017 12.7625 10.3878 12.5 10.3877C12.284 10.3877 12.1354 10.4353 12.0049 10.5137C11.8662 10.597 11.7401 10.7188 11.5693 10.8896L11.4277 11.0312L10.71 10.3125L10.5684 10.1719L10.71 10.0303C11.0564 9.68383 11.5529 9.17196 12.5 9.17188Z",
|
|
450
|
+
fill: "currentColor"
|
|
451
|
+
}),
|
|
452
|
+
/* @__PURE__ */ jsx("path", {
|
|
453
|
+
fillRule: "evenodd",
|
|
454
|
+
clipRule: "evenodd",
|
|
455
|
+
d: "M17.2598 7.13184C17.5955 7.13184 17.8671 7.40455 17.8672 7.74023V17.2598C17.8672 17.5956 17.5956 17.8672 17.2598 17.8672H7.74023C7.40455 17.8671 7.13184 17.5955 7.13184 17.2598V7.74023C7.13196 7.40463 7.40463 7.13196 7.74023 7.13184H17.2598ZM8.34766 16.6523H16.6523V8.34766H8.34766V16.6523Z",
|
|
456
|
+
fill: "currentColor"
|
|
457
|
+
})
|
|
458
|
+
]
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
function StudioMenuItem({ icon: IconComponent, text, href, onClick, disabled, selected }) {
|
|
462
|
+
let content = /* @__PURE__ */ jsxs(Flex, {
|
|
463
|
+
align: "center",
|
|
464
|
+
gap: 2,
|
|
465
|
+
children: [/* @__PURE__ */ jsx(Box, {
|
|
466
|
+
paddingRight: 1,
|
|
467
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
468
|
+
style: {
|
|
469
|
+
display: "flex",
|
|
470
|
+
fontSize: 25,
|
|
471
|
+
marginInline: "-0.375rem",
|
|
472
|
+
marginBlock: "-0.5rem",
|
|
473
|
+
color: "var(--card-icon-color)"
|
|
474
|
+
},
|
|
475
|
+
children: /* @__PURE__ */ jsx(IconComponent, {})
|
|
476
|
+
})
|
|
477
|
+
}), /* @__PURE__ */ jsx(Flex, {
|
|
478
|
+
direction: "column",
|
|
479
|
+
flex: 1,
|
|
480
|
+
style: { minWidth: 0 },
|
|
481
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
482
|
+
size: 1,
|
|
483
|
+
weight: "medium",
|
|
484
|
+
textOverflow: "ellipsis",
|
|
485
|
+
style: { color: "var(--card-fg-color)" },
|
|
486
|
+
children: text
|
|
487
|
+
})
|
|
488
|
+
})]
|
|
489
|
+
});
|
|
490
|
+
return href ? /* @__PURE__ */ jsx(MenuItem, {
|
|
491
|
+
as: "a",
|
|
492
|
+
href,
|
|
493
|
+
target: "_blank",
|
|
494
|
+
rel: "noopener",
|
|
495
|
+
paddingX: 3,
|
|
496
|
+
paddingY: 3,
|
|
497
|
+
children: content
|
|
498
|
+
}) : /* @__PURE__ */ jsx(MenuItem, {
|
|
499
|
+
onClick,
|
|
500
|
+
disabled,
|
|
501
|
+
selected,
|
|
502
|
+
pressed: selected,
|
|
503
|
+
paddingX: 3,
|
|
504
|
+
paddingY: 3,
|
|
505
|
+
children: content
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
const APPLE = typeof window < "u" && /Mac|iPod|iPhone|iPad/.test(window.navigator.platform);
|
|
509
|
+
/**
|
|
510
|
+
* Key names as the Studio shows them: "Mod" is Cmd on Apple platforms and Ctrl elsewhere, and
|
|
511
|
+
* Apple platforms get the modifier symbols (⌘ ⇧ ⌥ ⌃), as in "Search ⌘K".
|
|
512
|
+
*/
|
|
513
|
+
function keyLabel(key) {
|
|
514
|
+
let name = key === "Mod" ? APPLE ? "Cmd" : "Ctrl" : key;
|
|
515
|
+
return APPLE ? {
|
|
516
|
+
Cmd: "⌘",
|
|
517
|
+
Shift: "⇧",
|
|
518
|
+
Alt: "⌥",
|
|
519
|
+
Option: "⌥",
|
|
520
|
+
Ctrl: "⌃"
|
|
521
|
+
}[name] ?? name : name;
|
|
522
|
+
}
|
|
523
|
+
function StudioTooltip({ content, hotkeys, disabled, children }) {
|
|
524
|
+
let place = useBarPlacement();
|
|
525
|
+
return /* @__PURE__ */ jsx(Tooltip, {
|
|
526
|
+
portal: !0,
|
|
527
|
+
animate: !0,
|
|
528
|
+
arrow: !1,
|
|
529
|
+
boundaryElement: null,
|
|
530
|
+
delay: { open: 400 },
|
|
531
|
+
disabled,
|
|
532
|
+
placement: place("top"),
|
|
533
|
+
fallbackPlacements: [
|
|
534
|
+
place("top-start"),
|
|
535
|
+
place("top-end"),
|
|
536
|
+
"bottom-start",
|
|
537
|
+
"bottom-end"
|
|
538
|
+
],
|
|
539
|
+
padding: 1,
|
|
540
|
+
content: /* @__PURE__ */ jsxs(Flex, {
|
|
541
|
+
align: "center",
|
|
542
|
+
children: [/* @__PURE__ */ jsx(Box, {
|
|
543
|
+
flex: 1,
|
|
544
|
+
padding: 1,
|
|
545
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
546
|
+
size: 1,
|
|
547
|
+
as: "div",
|
|
548
|
+
children: content
|
|
549
|
+
})
|
|
550
|
+
}), hotkeys && /* @__PURE__ */ jsx(Box, {
|
|
551
|
+
flex: "none",
|
|
552
|
+
children: /* @__PURE__ */ jsx(Hotkeys, { keys: hotkeys.map(keyLabel) })
|
|
553
|
+
})]
|
|
554
|
+
}),
|
|
555
|
+
children
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
const GROUP_LABELS = {
|
|
559
|
+
asap: "ASAP",
|
|
560
|
+
scheduled: "At time",
|
|
561
|
+
undecided: "Undecided"
|
|
562
|
+
};
|
|
563
|
+
/**
|
|
564
|
+
* Switching perspective, for the menu and for the document pane's Published / Draft chips.
|
|
565
|
+
* Optimistic: the bar shows the new stack (chip, dots, stack lines, tone) at once, built with the
|
|
566
|
+
* same `perspectiveStack` the endpoint uses. The cookie is stored in the background, then the host
|
|
567
|
+
* reruns the page's queries in place. Switches save one after another, so the cookie always ends
|
|
568
|
+
* on the last one; only the latest refreshes, and a failed one puts the bar back.
|
|
569
|
+
*/
|
|
570
|
+
function usePerspectiveSwitch({ basePath, releases, perspective, onChange, onRefresh }) {
|
|
571
|
+
let current = useRef({
|
|
572
|
+
perspective,
|
|
573
|
+
releases,
|
|
574
|
+
onChange,
|
|
575
|
+
onRefresh
|
|
576
|
+
});
|
|
577
|
+
return current.current = {
|
|
578
|
+
perspective,
|
|
579
|
+
releases,
|
|
580
|
+
onChange,
|
|
581
|
+
onRefresh
|
|
582
|
+
}, useMemo(() => createPerspectiveSwitch(basePath, () => current.current), [basePath]);
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* `usePerspectiveSwitch` without React. Returns the switch, which resolves once its save (not the
|
|
586
|
+
* page's refresh) has settled. Saves are chained; the refresh runs outside the chain, so a page
|
|
587
|
+
* that never answers `refreshed` can't hold later switches back.
|
|
588
|
+
*/
|
|
589
|
+
function createPerspectiveSwitch(basePath, state) {
|
|
590
|
+
let saves = Promise.resolve(), latest = 0;
|
|
591
|
+
return (next) => {
|
|
592
|
+
let { perspective: previous, releases: list, onChange: show } = state(), request = ++latest;
|
|
593
|
+
return show(perspectiveStack({
|
|
594
|
+
selected: next.selected,
|
|
595
|
+
releases: list,
|
|
596
|
+
excluded: next.excluded
|
|
597
|
+
})), saves = saves.then(async () => {
|
|
598
|
+
try {
|
|
599
|
+
let response = await fetch(`${basePath}/perspective`, {
|
|
600
|
+
method: "POST",
|
|
601
|
+
headers: { "content-type": "application/json" },
|
|
602
|
+
body: JSON.stringify(next)
|
|
603
|
+
});
|
|
604
|
+
if (!response.ok) throw Error(`HTTP ${response.status}`);
|
|
605
|
+
let { perspective: stored } = await response.json();
|
|
606
|
+
if (request !== latest) return;
|
|
607
|
+
state().onChange(stored);
|
|
608
|
+
} catch (err) {
|
|
609
|
+
console.error("Preview bar: could not change perspective", err), request === latest && state().onChange(previous);
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
state().onRefresh().catch((err) => console.error("Preview bar: could not refresh the page", err));
|
|
613
|
+
}), saves;
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
/** "Monday at 2:00 AM" within a week, "Dec 1 at 2:00 AM" (plus year if not this year) after. */
|
|
617
|
+
function formatPublishDate(value) {
|
|
618
|
+
let date = new Date(value), now = /* @__PURE__ */ new Date(), time = date.toLocaleTimeString(void 0, {
|
|
619
|
+
hour: "numeric",
|
|
620
|
+
minute: "2-digit"
|
|
621
|
+
}), days = (date.getTime() - now.getTime()) / 864e5;
|
|
622
|
+
return `${days >= 0 && days < 7 ? date.toLocaleDateString(void 0, { weekday: "long" }) : date.toLocaleDateString(void 0, {
|
|
623
|
+
month: "short",
|
|
624
|
+
day: "numeric",
|
|
625
|
+
...date.getFullYear() === now.getFullYear() ? {} : { year: "numeric" }
|
|
626
|
+
})} at ${time}`;
|
|
627
|
+
}
|
|
628
|
+
function layerTone(layer) {
|
|
629
|
+
return layer.kind === "published" ? "positive" : layer.kind === "drafts" ? "caution" : releaseTone(layer.release);
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* `ReleaseAvatarIcon`. In the menu it is the Studio's small icon at `fontSize={2}` (ring for drafts,
|
|
633
|
+
* dot for published, bolt/clock/unknown by release type), tinted `--card-badge-<tone>-icon-color`.
|
|
634
|
+
* The switcher button keeps its own approved icon.
|
|
635
|
+
*/
|
|
636
|
+
function LayerIcon({ layer, variant = "chip" }) {
|
|
637
|
+
let color = `var(--card-badge-${layerTone(layer)}-icon-color)`, type = layer.kind === "release" ? layer.release.metadata.releaseType : void 0;
|
|
638
|
+
if (variant === "menu") {
|
|
639
|
+
let small;
|
|
640
|
+
return small = layer.kind === "published" ? /* @__PURE__ */ jsx(CircleSmallIcon, {}) : layer.kind === "drafts" ? /* @__PURE__ */ jsx(RingIcon, {}) : jsx(type === "asap" ? BoltSmallIcon : type === "scheduled" ? ClockSmallIcon : UnknownSmallIcon, {}), /* @__PURE__ */ jsx(Text, {
|
|
641
|
+
size: 2,
|
|
642
|
+
style: { "--card-icon-color": color },
|
|
643
|
+
children: small
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
let icon;
|
|
647
|
+
return icon = type === "asap" ? /* @__PURE__ */ jsx(BoltIcon, {}) : type === "scheduled" ? /* @__PURE__ */ jsx(ClockIcon, {}) : /* @__PURE__ */ jsx("svg", {
|
|
648
|
+
width: "1em",
|
|
649
|
+
height: "1em",
|
|
650
|
+
viewBox: "0 0 25 25",
|
|
651
|
+
fill: "none",
|
|
652
|
+
"aria-hidden": "true",
|
|
653
|
+
children: layer.kind === "drafts" ? /* @__PURE__ */ jsx("circle", {
|
|
654
|
+
cx: "12.5",
|
|
655
|
+
cy: "12.5",
|
|
656
|
+
r: "3.25",
|
|
657
|
+
stroke: "currentColor",
|
|
658
|
+
strokeWidth: "1.5"
|
|
659
|
+
}) : /* @__PURE__ */ jsx("circle", {
|
|
660
|
+
cx: "12.5",
|
|
661
|
+
cy: "12.5",
|
|
662
|
+
r: "4",
|
|
663
|
+
fill: "currentColor"
|
|
664
|
+
})
|
|
665
|
+
}), /* @__PURE__ */ jsx(Text, {
|
|
666
|
+
size: 1,
|
|
667
|
+
style: { color },
|
|
668
|
+
children: icon
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
/** The stack line through the layers that make up the current perspective. */
|
|
672
|
+
function RangeLine({ position }) {
|
|
673
|
+
return position ? /* @__PURE__ */ jsx("span", {
|
|
674
|
+
"aria-hidden": "true",
|
|
675
|
+
style: {
|
|
676
|
+
position: "absolute",
|
|
677
|
+
left: 20,
|
|
678
|
+
width: 1,
|
|
679
|
+
top: position === "first" ? 13.5 : 0,
|
|
680
|
+
bottom: position === "last" ? "calc(100% - 16.5px)" : -4,
|
|
681
|
+
background: "var(--card-border-color)",
|
|
682
|
+
pointerEvents: "none",
|
|
683
|
+
zIndex: 1
|
|
684
|
+
}
|
|
685
|
+
}) : null;
|
|
686
|
+
}
|
|
687
|
+
function PerspectiveMenu({ releases, releasesError, perspective, onOpenChange, onSelect }) {
|
|
688
|
+
let { basePath, studioPath } = useBarData(), place = useBarPlacement(), [filter, setFilter] = useState(""), { selected, excluded } = useMemo(() => selectionOf(perspective, releases), [perspective, releases]), layers = useMemo(() => {
|
|
689
|
+
let listed = releases.filter((release) => !isScheduledDraft(release));
|
|
690
|
+
return [
|
|
691
|
+
{
|
|
692
|
+
kind: "published",
|
|
693
|
+
id: PUBLISHED,
|
|
694
|
+
title: "Published"
|
|
695
|
+
},
|
|
696
|
+
{
|
|
697
|
+
kind: "drafts",
|
|
698
|
+
id: DRAFTS,
|
|
699
|
+
title: "Drafts"
|
|
700
|
+
},
|
|
701
|
+
...RELEASE_TYPES.flatMap((type) => listed.filter((release) => release.metadata.releaseType === type).map((release) => ({
|
|
702
|
+
kind: "release",
|
|
703
|
+
id: releaseIdOf(release),
|
|
704
|
+
title: release.metadata.title || "Untitled release",
|
|
705
|
+
release
|
|
706
|
+
})))
|
|
707
|
+
];
|
|
708
|
+
}, [releases]), query = filter.trim().toLowerCase(), visible = query ? layers.filter((layer) => layer.title.toLowerCase().includes(query)) : layers, selectedLayer = layers.find((layer) => layer.id === selected) ?? layers[1], lastIndex = selected === "published" ? 0 : layers.indexOf(selectedLayer);
|
|
709
|
+
function rangePosition(index) {
|
|
710
|
+
if (!(query || lastIndex === 0)) return index === 0 ? "first" : index === lastIndex ? "last" : index < lastIndex ? "within" : void 0;
|
|
711
|
+
}
|
|
712
|
+
/** `ReleasesMenuItem`'s `canReleaseBeExcluded`. */
|
|
713
|
+
function canExclude(layer, index) {
|
|
714
|
+
if (layer.kind === "published") return !1;
|
|
715
|
+
if (layer.kind === "drafts") return selectedLayer.kind === "release";
|
|
716
|
+
if (layer.release.metadata.releaseType === "scheduled") return !1;
|
|
717
|
+
let position = rangePosition(index);
|
|
718
|
+
return position === "first" || position === "within";
|
|
719
|
+
}
|
|
720
|
+
function apply(next) {
|
|
721
|
+
onSelect(next);
|
|
722
|
+
}
|
|
723
|
+
function toggleExcluded(event, id) {
|
|
724
|
+
event.preventDefault(), event.stopPropagation();
|
|
725
|
+
let nextExcluded = excluded.includes(id) ? excluded.filter((name) => name !== id) : [...excluded, id];
|
|
726
|
+
apply({
|
|
727
|
+
selected,
|
|
728
|
+
excluded: nextExcluded
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
function renderLayer(layer) {
|
|
732
|
+
let index = layers.indexOf(layer), active = layer.id === selectedLayer.id, hidden = selectedLayer.kind === "release" && excluded.includes(layer.id), publishAt = layer.kind === "release" && layer.release.metadata.releaseType === "scheduled" ? layer.release.publishAt || layer.release.metadata.intendedPublishAt : null;
|
|
733
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
734
|
+
style: { position: "relative" },
|
|
735
|
+
children: [/* @__PURE__ */ jsx(RangeLine, { position: rangePosition(index) }), /* @__PURE__ */ jsx(MenuItem, {
|
|
736
|
+
selected: active,
|
|
737
|
+
padding: 1,
|
|
738
|
+
onClick: () => {
|
|
739
|
+
active || apply({
|
|
740
|
+
selected: layer.id,
|
|
741
|
+
excluded
|
|
742
|
+
});
|
|
743
|
+
},
|
|
744
|
+
children: /* @__PURE__ */ jsxs(Flex, {
|
|
745
|
+
align: "flex-start",
|
|
746
|
+
gap: 1,
|
|
747
|
+
style: { opacity: hidden ? .5 : 1 },
|
|
748
|
+
children: [
|
|
749
|
+
/* @__PURE__ */ jsx(Flex, {
|
|
750
|
+
flex: "none",
|
|
751
|
+
paddingX: 3,
|
|
752
|
+
paddingY: 2,
|
|
753
|
+
style: {
|
|
754
|
+
borderRadius: 3,
|
|
755
|
+
position: "relative",
|
|
756
|
+
zIndex: 2,
|
|
757
|
+
background: "var(--card-bg-color)"
|
|
758
|
+
},
|
|
759
|
+
children: /* @__PURE__ */ jsx(LayerIcon, {
|
|
760
|
+
layer,
|
|
761
|
+
variant: "menu"
|
|
762
|
+
})
|
|
763
|
+
}),
|
|
764
|
+
/* @__PURE__ */ jsxs(Flex, {
|
|
765
|
+
direction: "column",
|
|
766
|
+
flex: 1,
|
|
767
|
+
gap: 2,
|
|
768
|
+
paddingY: 2,
|
|
769
|
+
paddingRight: 2,
|
|
770
|
+
style: { minWidth: 0 },
|
|
771
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
772
|
+
size: 1,
|
|
773
|
+
weight: "medium",
|
|
774
|
+
textOverflow: "ellipsis",
|
|
775
|
+
style: {
|
|
776
|
+
minWidth: 0,
|
|
777
|
+
color: "inherit"
|
|
778
|
+
},
|
|
779
|
+
children: layer.title
|
|
780
|
+
}), publishAt && /* @__PURE__ */ jsx(Text, {
|
|
781
|
+
size: 1,
|
|
782
|
+
muted: !0,
|
|
783
|
+
style: {
|
|
784
|
+
color: "inherit",
|
|
785
|
+
opacity: .75
|
|
786
|
+
},
|
|
787
|
+
children: formatPublishDate(publishAt)
|
|
788
|
+
})]
|
|
789
|
+
}),
|
|
790
|
+
canExclude(layer, index) && /* @__PURE__ */ jsx(Box, {
|
|
791
|
+
flex: "none",
|
|
792
|
+
padding: 1,
|
|
793
|
+
children: /* @__PURE__ */ jsx(StudioTooltip, {
|
|
794
|
+
content: hidden ? "Show release" : "Hide release",
|
|
795
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
796
|
+
as: "span",
|
|
797
|
+
mode: "bleed",
|
|
798
|
+
padding: 2,
|
|
799
|
+
radius: "full",
|
|
800
|
+
fontSize: 1,
|
|
801
|
+
icon: hidden ? EyeClosedIcon : EyeOpenIcon,
|
|
802
|
+
"aria-label": hidden ? "Show release" : "Hide release",
|
|
803
|
+
onClick: (event) => toggleExcluded(event, layer.id)
|
|
804
|
+
})
|
|
805
|
+
})
|
|
806
|
+
})
|
|
807
|
+
]
|
|
808
|
+
})
|
|
809
|
+
})]
|
|
810
|
+
}, layer.id);
|
|
811
|
+
}
|
|
812
|
+
let systemLayers = visible.filter((layer) => layer.kind !== "release"), groups = RELEASE_TYPES.map((type) => ({
|
|
813
|
+
type,
|
|
814
|
+
items: visible.filter((layer) => layer.kind === "release" && layer.release.metadata.releaseType === type)
|
|
815
|
+
})).filter((group) => group.items.length > 0);
|
|
816
|
+
return /* @__PURE__ */ jsxs(Card, {
|
|
817
|
+
border: !0,
|
|
818
|
+
radius: "full",
|
|
819
|
+
tone: "inherit",
|
|
820
|
+
flex: "none",
|
|
821
|
+
style: {
|
|
822
|
+
display: "flex",
|
|
823
|
+
alignItems: "center",
|
|
824
|
+
gap: 2,
|
|
825
|
+
padding: 2,
|
|
826
|
+
margin: "-3px 0"
|
|
827
|
+
},
|
|
828
|
+
children: [/* @__PURE__ */ jsx(Box, {
|
|
829
|
+
padding: 2,
|
|
830
|
+
style: {
|
|
831
|
+
userSelect: "none",
|
|
832
|
+
overflow: "hidden"
|
|
833
|
+
},
|
|
834
|
+
children: /* @__PURE__ */ jsxs(Flex, {
|
|
835
|
+
align: "center",
|
|
836
|
+
gap: 2,
|
|
837
|
+
children: [/* @__PURE__ */ jsx(LayerIcon, { layer: selectedLayer }), /* @__PURE__ */ jsx(Text, {
|
|
838
|
+
size: 1,
|
|
839
|
+
weight: "medium",
|
|
840
|
+
textOverflow: "ellipsis",
|
|
841
|
+
children: selectedLayer.title
|
|
842
|
+
})]
|
|
843
|
+
})
|
|
844
|
+
}), /* @__PURE__ */ jsx(MenuButton, {
|
|
845
|
+
id: "preview-perspective",
|
|
846
|
+
onOpen: () => onOpenChange(!0),
|
|
847
|
+
onClose: () => {
|
|
848
|
+
setFilter(""), onOpenChange(!1);
|
|
849
|
+
},
|
|
850
|
+
popover: {
|
|
851
|
+
animate: !0,
|
|
852
|
+
placement: place("top-start"),
|
|
853
|
+
fallbackPlacements: [place("top-end")],
|
|
854
|
+
portal: !0,
|
|
855
|
+
constrainSize: !0,
|
|
856
|
+
tone: "default",
|
|
857
|
+
zOffset: 3e3
|
|
858
|
+
},
|
|
859
|
+
button: /* @__PURE__ */ jsx(Button, {
|
|
860
|
+
mode: "bleed",
|
|
861
|
+
padding: 2,
|
|
862
|
+
radius: "full",
|
|
863
|
+
iconRight: ChevronDownIcon,
|
|
864
|
+
"aria-label": `Perspective: ${selectedLayer.title}`
|
|
865
|
+
}),
|
|
866
|
+
menu: /* @__PURE__ */ jsxs(Menu, {
|
|
867
|
+
padding: 0,
|
|
868
|
+
style: {
|
|
869
|
+
width: 280,
|
|
870
|
+
maxWidth: "calc(100vw - 16px)"
|
|
871
|
+
},
|
|
872
|
+
children: [
|
|
873
|
+
/* @__PURE__ */ jsx(Box, {
|
|
874
|
+
padding: 2,
|
|
875
|
+
style: { borderBottom: "1px solid var(--card-border-color)" },
|
|
876
|
+
children: /* @__PURE__ */ jsx(TextInput, {
|
|
877
|
+
fontSize: 1,
|
|
878
|
+
radius: 2,
|
|
879
|
+
icon: SearchIcon,
|
|
880
|
+
placeholder: "Find a version or release",
|
|
881
|
+
value: filter,
|
|
882
|
+
onChange: (event) => setFilter(event.currentTarget.value),
|
|
883
|
+
onKeyDown: (event) => event.stopPropagation()
|
|
884
|
+
})
|
|
885
|
+
}),
|
|
886
|
+
/* @__PURE__ */ jsxs(Flex, {
|
|
887
|
+
direction: "column",
|
|
888
|
+
gap: 1,
|
|
889
|
+
padding: 1,
|
|
890
|
+
children: [
|
|
891
|
+
systemLayers.map(renderLayer),
|
|
892
|
+
groups.map((group) => {
|
|
893
|
+
let offset = layers.indexOf(group.items[0]);
|
|
894
|
+
return /* @__PURE__ */ jsxs(Box, { children: [/* @__PURE__ */ jsxs(Box, {
|
|
895
|
+
paddingTop: 3,
|
|
896
|
+
paddingBottom: 1,
|
|
897
|
+
style: {
|
|
898
|
+
position: "relative",
|
|
899
|
+
paddingLeft: 41
|
|
900
|
+
},
|
|
901
|
+
children: [/* @__PURE__ */ jsx(RangeLine, { position: !query && offset > 0 && lastIndex >= offset ? "within" : void 0 }), /* @__PURE__ */ jsx(Label, {
|
|
902
|
+
muted: !0,
|
|
903
|
+
size: 1,
|
|
904
|
+
children: GROUP_LABELS[group.type]
|
|
905
|
+
})]
|
|
906
|
+
}), group.items.map(renderLayer)] }, group.type);
|
|
907
|
+
}),
|
|
908
|
+
releasesError && /* @__PURE__ */ jsx(Box, {
|
|
909
|
+
padding: 3,
|
|
910
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
911
|
+
size: 1,
|
|
912
|
+
muted: !0,
|
|
913
|
+
children: "Couldn’t load content releases."
|
|
914
|
+
})
|
|
915
|
+
})
|
|
916
|
+
]
|
|
917
|
+
}),
|
|
918
|
+
/* @__PURE__ */ jsx(MenuDivider, {}),
|
|
919
|
+
/* @__PURE__ */ jsxs(Flex, {
|
|
920
|
+
direction: "column",
|
|
921
|
+
gap: 1,
|
|
922
|
+
padding: 1,
|
|
923
|
+
children: [
|
|
924
|
+
/* @__PURE__ */ jsx(StudioMenuItem, {
|
|
925
|
+
href: `${studioPath}/intent/releases-scheduled-drafts/view=drafts/`,
|
|
926
|
+
icon: CalendarIcon,
|
|
927
|
+
text: "View Scheduled Drafts"
|
|
928
|
+
}),
|
|
929
|
+
/* @__PURE__ */ jsx(StudioMenuItem, {
|
|
930
|
+
href: `${studioPath}/intent/release/`,
|
|
931
|
+
icon: CalendarIcon,
|
|
932
|
+
text: "View Content Releases"
|
|
933
|
+
}),
|
|
934
|
+
/* @__PURE__ */ jsx(StudioMenuItem, {
|
|
935
|
+
href: `${studioPath}/intent/release/`,
|
|
936
|
+
icon: AddIcon,
|
|
937
|
+
text: "New release"
|
|
938
|
+
})
|
|
939
|
+
]
|
|
940
|
+
})
|
|
941
|
+
]
|
|
942
|
+
})
|
|
943
|
+
})]
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
/** Studio URL search params that carry this perspective into the Visual Editor. */
|
|
947
|
+
function studioPerspectiveParams(perspective, releases) {
|
|
948
|
+
let { selected, excluded } = selectionOf(perspective, releases), params = new URLSearchParams();
|
|
949
|
+
return selected !== "drafts" && params.set("perspective", selected), excluded.length && params.set("excludedPerspectives", excluded.join(",")), params;
|
|
950
|
+
}
|
|
951
|
+
/**
|
|
952
|
+
* Presentation's share menu (`SharePreviewMenu`, `sanity@6.23`), in the bar: the "Share this
|
|
953
|
+
* preview" switch, a QR code to open the preview on a phone, and "Copy preview link". The same
|
|
954
|
+
* layout, copy and sizes; the link is the bar's own short `/p/<code>` link (minted by
|
|
955
|
+
* `/__visual-editor/share`, stored in KV, 2 days) instead of Presentation's URL with the secret in it.
|
|
956
|
+
*
|
|
957
|
+
* The switch is Sanity's preview sharing setting (`enablePreviewAccessSharing` /
|
|
958
|
+
* `disablePreviewAccessSharing` from `@sanity/preview-url-secret`, as Presentation toggles it):
|
|
959
|
+
* links are minted only while it's on. Toggling needs the editor's Studio client, so
|
|
960
|
+
* it works for signed-in editors (the Studio layer reports the client); everyone else sees it
|
|
961
|
+
* read-only.
|
|
962
|
+
*/
|
|
963
|
+
const QRCodeSVG = lazy(() => import("qrcode.react").then((module) => ({ default: module.QRCodeSVG })));
|
|
964
|
+
/** The share endpoint refused because preview sharing is off. */
|
|
965
|
+
var SharingOffError = class extends Error {};
|
|
966
|
+
/** Asks the server for a short `/p/<code>` link to `path` in the current perspective. */
|
|
967
|
+
async function requestShareLink(basePath, path) {
|
|
968
|
+
let response = await fetch(`${basePath}/share`, {
|
|
969
|
+
method: "POST",
|
|
970
|
+
headers: { "content-type": "application/json" },
|
|
971
|
+
body: JSON.stringify({ pathname: path })
|
|
972
|
+
});
|
|
973
|
+
if (response.status === 409) throw new SharingOffError();
|
|
974
|
+
if (!response.ok) throw Error(`HTTP ${response.status}`);
|
|
975
|
+
let { url } = await response.json();
|
|
976
|
+
return url;
|
|
977
|
+
}
|
|
978
|
+
/** The Clipboard API (as Presentation does), then the selection fallback. */
|
|
979
|
+
async function copyText(value) {
|
|
980
|
+
try {
|
|
981
|
+
return await navigator.clipboard.writeText(value), !0;
|
|
982
|
+
} catch {
|
|
983
|
+
let field = document.createElement("textarea");
|
|
984
|
+
field.value = value, field.setAttribute("readonly", ""), field.style.cssText = "position:fixed;opacity:0;pointer-events:none", document.body.appendChild(field), field.select();
|
|
985
|
+
let copied = document.execCommand("copy");
|
|
986
|
+
return field.remove(), copied;
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
/** Presentation's QR code: 224px, error level L, a 40px hole with the Sanity monogram on top. */
|
|
990
|
+
function PreviewQrCode({ url }) {
|
|
991
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(QRCodeSVG, {
|
|
992
|
+
value: url,
|
|
993
|
+
size: 224,
|
|
994
|
+
level: "L",
|
|
995
|
+
bgColor: "transparent",
|
|
996
|
+
fgColor: "currentColor",
|
|
997
|
+
title: `A QR Code which encodes the URL: ${url}`,
|
|
998
|
+
imageSettings: {
|
|
999
|
+
src: "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",
|
|
1000
|
+
height: 40,
|
|
1001
|
+
width: 40,
|
|
1002
|
+
excavate: !0
|
|
1003
|
+
},
|
|
1004
|
+
style: {
|
|
1005
|
+
color: "var(--card-fg-color)",
|
|
1006
|
+
display: "block"
|
|
1007
|
+
}
|
|
1008
|
+
}), /* @__PURE__ */ jsx(SanityMonogram, { style: {
|
|
1009
|
+
position: "absolute",
|
|
1010
|
+
top: "50%",
|
|
1011
|
+
left: "50%",
|
|
1012
|
+
width: 24,
|
|
1013
|
+
height: 24,
|
|
1014
|
+
transform: "translate(-50%, -50%)"
|
|
1015
|
+
} })] });
|
|
1016
|
+
}
|
|
1017
|
+
/** The sharing secret's `source`: the tool that toggled it. */
|
|
1018
|
+
const SHARING_SOURCE = "sanity-plugin-visual-editor/visual-editor";
|
|
1019
|
+
function ShareMenu({ sharing: initialSharing, path, perspectiveKey, studio, toolPath, setOverflow }) {
|
|
1020
|
+
let { basePath } = useBarData(), place = useBarPlacement(), [sharing, setSharing] = useState(initialSharing);
|
|
1021
|
+
useEffect(() => setSharing(initialSharing), [initialSharing]);
|
|
1022
|
+
let [open, setOpen] = useState(!1), [toggling, setToggling] = useState(null), [minting, setMinting] = useState(!1), [link, setLink] = useState(null), [confirmation, setConfirmation] = useState(null), [anchor, setAnchor] = useState(null), timer = useRef(void 0), key = `${perspectiveKey} ${path}`, url = sharing && link?.key === key ? link.url : null, busy = toggling !== null || minting;
|
|
1023
|
+
useEffect(() => {
|
|
1024
|
+
if (!open || !sharing || link?.key === key) return;
|
|
1025
|
+
let cancelled = !1;
|
|
1026
|
+
return setMinting(!0), requestShareLink(basePath, path).then((next) => {
|
|
1027
|
+
cancelled || setLink({
|
|
1028
|
+
key,
|
|
1029
|
+
url: next
|
|
1030
|
+
});
|
|
1031
|
+
}).catch((err) => {
|
|
1032
|
+
cancelled || (err instanceof SharingOffError ? setSharing(!1) : console.error("Preview bar: could not create a preview link", err));
|
|
1033
|
+
}).finally(() => {
|
|
1034
|
+
cancelled || setMinting(!1);
|
|
1035
|
+
}), () => {
|
|
1036
|
+
cancelled = !0, setMinting(!1);
|
|
1037
|
+
};
|
|
1038
|
+
}, [
|
|
1039
|
+
open,
|
|
1040
|
+
sharing,
|
|
1041
|
+
link,
|
|
1042
|
+
key,
|
|
1043
|
+
basePath,
|
|
1044
|
+
path
|
|
1045
|
+
]), useEffect(() => {
|
|
1046
|
+
if (confirmation) return setOverflow("copy-confirmation", !0), () => setOverflow("copy-confirmation", !1);
|
|
1047
|
+
}, [confirmation, setOverflow]), useEffect(() => () => window.clearTimeout(timer.current), []);
|
|
1048
|
+
async function toggleSharing() {
|
|
1049
|
+
if (!studio || toggling) return;
|
|
1050
|
+
let enable = !sharing;
|
|
1051
|
+
setToggling(enable ? "enabling" : "disabling");
|
|
1052
|
+
try {
|
|
1053
|
+
let { enablePreviewAccessSharing, disablePreviewAccessSharing } = await import("@sanity/preview-url-secret/toggle-preview-access-sharing"), studioUrl = `${window.location.origin}${toolPath}`, client = studio.client;
|
|
1054
|
+
enable ? await enablePreviewAccessSharing(client, SHARING_SOURCE, studioUrl, studio.userId) : (await disablePreviewAccessSharing(client, SHARING_SOURCE, studioUrl, studio.userId), setLink(null)), setSharing(enable);
|
|
1055
|
+
} catch (err) {
|
|
1056
|
+
console.error("Preview bar: could not change preview sharing", err);
|
|
1057
|
+
} finally {
|
|
1058
|
+
setToggling(null);
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
async function copyLink() {
|
|
1062
|
+
if (!url) return;
|
|
1063
|
+
let copied = await copyText(url);
|
|
1064
|
+
setConfirmation(copied ? "copied" : "failed"), window.clearTimeout(timer.current), timer.current = window.setTimeout(() => setConfirmation(null), 3e3);
|
|
1065
|
+
}
|
|
1066
|
+
let failed = confirmation === "failed", menu = /* @__PURE__ */ jsxs(Menu, {
|
|
1067
|
+
style: { maxWidth: 248 },
|
|
1068
|
+
children: [
|
|
1069
|
+
/* @__PURE__ */ jsx("label", {
|
|
1070
|
+
style: { cursor: studio ? "pointer" : "default" },
|
|
1071
|
+
children: /* @__PURE__ */ jsxs(Grid, {
|
|
1072
|
+
gapX: 3,
|
|
1073
|
+
gapY: 1,
|
|
1074
|
+
paddingTop: 3,
|
|
1075
|
+
paddingX: 3,
|
|
1076
|
+
style: {
|
|
1077
|
+
justifyContent: "center",
|
|
1078
|
+
alignItems: "center",
|
|
1079
|
+
gridTemplateColumns: "min-content 1fr",
|
|
1080
|
+
gridTemplateRows: "min-content"
|
|
1081
|
+
},
|
|
1082
|
+
children: [
|
|
1083
|
+
/* @__PURE__ */ jsx(Tooltip, {
|
|
1084
|
+
animate: !0,
|
|
1085
|
+
content: /* @__PURE__ */ jsx(Text, {
|
|
1086
|
+
size: 1,
|
|
1087
|
+
as: "div",
|
|
1088
|
+
children: studio ? url ? "Disable sharing" : "Enable sharing" : "Sign in to the Studio to change sharing"
|
|
1089
|
+
}),
|
|
1090
|
+
padding: 2,
|
|
1091
|
+
fallbackPlacements: [place("top-start")],
|
|
1092
|
+
placement: place("top"),
|
|
1093
|
+
portal: !0,
|
|
1094
|
+
zOffset: 3100,
|
|
1095
|
+
children: /* @__PURE__ */ jsx(Switch, {
|
|
1096
|
+
checked: toggling === "enabling" || sharing && toggling !== "disabling",
|
|
1097
|
+
readOnly: !studio || toggling !== null,
|
|
1098
|
+
onChange: () => void toggleSharing()
|
|
1099
|
+
})
|
|
1100
|
+
}),
|
|
1101
|
+
/* @__PURE__ */ jsx(Text, {
|
|
1102
|
+
size: 1,
|
|
1103
|
+
weight: "medium",
|
|
1104
|
+
as: "div",
|
|
1105
|
+
children: "Share this preview"
|
|
1106
|
+
}),
|
|
1107
|
+
/* @__PURE__ */ jsx("span", {}),
|
|
1108
|
+
/* @__PURE__ */ jsx(Text, {
|
|
1109
|
+
muted: !0,
|
|
1110
|
+
size: 1,
|
|
1111
|
+
as: "div",
|
|
1112
|
+
children: "with anyone who has the link"
|
|
1113
|
+
})
|
|
1114
|
+
]
|
|
1115
|
+
})
|
|
1116
|
+
}),
|
|
1117
|
+
/* @__PURE__ */ jsx(Box, {
|
|
1118
|
+
padding: 3,
|
|
1119
|
+
paddingTop: 2,
|
|
1120
|
+
children: /* @__PURE__ */ jsxs(Stack, {
|
|
1121
|
+
gap: 3,
|
|
1122
|
+
children: [/* @__PURE__ */ jsx(Card, {
|
|
1123
|
+
tone: busy || !url ? "transparent" : void 0,
|
|
1124
|
+
style: {
|
|
1125
|
+
position: "relative",
|
|
1126
|
+
aspectRatio: "1 / 1",
|
|
1127
|
+
display: "flex",
|
|
1128
|
+
alignItems: "center",
|
|
1129
|
+
justifyContent: "center"
|
|
1130
|
+
},
|
|
1131
|
+
children: busy ? /* @__PURE__ */ jsx(Spinner, { muted: !0 }) : url ? /* @__PURE__ */ jsx(Suspense, {
|
|
1132
|
+
fallback: /* @__PURE__ */ jsx(Spinner, {}),
|
|
1133
|
+
children: /* @__PURE__ */ jsx(PreviewQrCode, { url })
|
|
1134
|
+
}) : /* @__PURE__ */ jsx(Text, {
|
|
1135
|
+
muted: !0,
|
|
1136
|
+
size: 1,
|
|
1137
|
+
as: "div",
|
|
1138
|
+
style: {
|
|
1139
|
+
maxWidth: 100,
|
|
1140
|
+
textWrap: "pretty",
|
|
1141
|
+
textAlign: "center"
|
|
1142
|
+
},
|
|
1143
|
+
children: "QR code will appear here"
|
|
1144
|
+
})
|
|
1145
|
+
}), /* @__PURE__ */ jsx(Text, {
|
|
1146
|
+
muted: !0,
|
|
1147
|
+
size: 1,
|
|
1148
|
+
as: "div",
|
|
1149
|
+
children: "Scan the QR Code to open the preview on your phone."
|
|
1150
|
+
})]
|
|
1151
|
+
})
|
|
1152
|
+
}),
|
|
1153
|
+
/* @__PURE__ */ jsx(MenuDivider, {}),
|
|
1154
|
+
/* @__PURE__ */ jsx(MenuItem, {
|
|
1155
|
+
disabled: !url || toggling === "disabling",
|
|
1156
|
+
icon: CopyIcon,
|
|
1157
|
+
onClick: () => void copyLink(),
|
|
1158
|
+
text: "Copy preview link"
|
|
1159
|
+
})
|
|
1160
|
+
]
|
|
1161
|
+
}), confirmationContent = /* @__PURE__ */ jsxs(Flex, {
|
|
1162
|
+
align: "center",
|
|
1163
|
+
gap: 2,
|
|
1164
|
+
padding: 3,
|
|
1165
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
1166
|
+
size: 1,
|
|
1167
|
+
style: { "--card-icon-color": failed ? "var(--card-badge-critical-icon-color)" : "var(--card-badge-positive-icon-color)" },
|
|
1168
|
+
children: jsx(failed ? ErrorOutlineIcon : CheckmarkCircleIcon, {})
|
|
1169
|
+
}), /* @__PURE__ */ jsx(Text, {
|
|
1170
|
+
size: 1,
|
|
1171
|
+
children: failed ? "Copy failed" : "Link copied. Expires in 2 days."
|
|
1172
|
+
})]
|
|
1173
|
+
});
|
|
1174
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
1175
|
+
ref: setAnchor,
|
|
1176
|
+
style: { display: "flex" },
|
|
1177
|
+
children: [/* @__PURE__ */ jsx(MenuButton, {
|
|
1178
|
+
id: "preview-bar-share",
|
|
1179
|
+
onOpen: () => {
|
|
1180
|
+
setOpen(!0), setOverflow("share-menu", !0);
|
|
1181
|
+
},
|
|
1182
|
+
onClose: () => {
|
|
1183
|
+
setOpen(!1), setOverflow("share-menu", !1);
|
|
1184
|
+
},
|
|
1185
|
+
popover: {
|
|
1186
|
+
animate: !0,
|
|
1187
|
+
constrainSize: !0,
|
|
1188
|
+
placement: place("top"),
|
|
1189
|
+
fallbackPlacements: [place("top-end"), place("top-start")],
|
|
1190
|
+
portal: !0,
|
|
1191
|
+
tone: "default",
|
|
1192
|
+
zOffset: 3e3
|
|
1193
|
+
},
|
|
1194
|
+
button: /* @__PURE__ */ jsx(Button, {
|
|
1195
|
+
mode: "bleed",
|
|
1196
|
+
padding: 2,
|
|
1197
|
+
icon: ShareIcon,
|
|
1198
|
+
"aria-label": "Share preview"
|
|
1199
|
+
}),
|
|
1200
|
+
menu
|
|
1201
|
+
}), /* @__PURE__ */ jsx(Popover, {
|
|
1202
|
+
referenceElement: anchor,
|
|
1203
|
+
content: confirmationContent,
|
|
1204
|
+
open: confirmation !== null,
|
|
1205
|
+
portal: !0,
|
|
1206
|
+
animate: !0,
|
|
1207
|
+
placement: place("top"),
|
|
1208
|
+
fallbackPlacements: [place("top-end"), place("top-start")],
|
|
1209
|
+
tone: "default",
|
|
1210
|
+
zOffset: 3e3,
|
|
1211
|
+
role: "status"
|
|
1212
|
+
})]
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
/**
|
|
1216
|
+
* The document side pane: the Studio's own document editor (header with the Published / Draft
|
|
1217
|
+
* chips, the form, presence, and the footer with Publish and the other document actions), the same
|
|
1218
|
+
* pane Presentation shows next to its preview. Rendered inside the Studio layer's `StudioProvider`,
|
|
1219
|
+
* so it edits in the bar's perspective with the project's own config, plugins and actions.
|
|
1220
|
+
*
|
|
1221
|
+
* Presentation's recipe (`sanity@6.23`, `PresentationToolGrantsCheck` → `DocumentPane$1` and
|
|
1222
|
+
* `PresentationPaneRouterProvider`), with public `sanity/structure` exports only:
|
|
1223
|
+
* `StructureToolProvider` → `PaneLayout` → a minimal `PaneRouterContext` → `DocumentPane`.
|
|
1224
|
+
*
|
|
1225
|
+
* The pane router here is a small stack: reference links open the referenced document in the pane,
|
|
1226
|
+
* and the header's close button (the router's `BackLink`) goes back, closing the panel from the
|
|
1227
|
+
* page's document.
|
|
1228
|
+
*/
|
|
1229
|
+
/** An in-pane link: an anchor (the Studio styles these as buttons) that runs `action` on click. */
|
|
1230
|
+
function paneLink(name, action) {
|
|
1231
|
+
let Link = forwardRef(function PaneLink(props, ref) {
|
|
1232
|
+
let { children, onClick, childId: _childId, childType: _childType, childParameters: _childParameters, childPayload: _childPayload, documentId: _documentId, documentType: _documentType, parentRefPath: _parentRefPath, template: _template, params: _params, payload: _payload, searchParams: _searchParams, ...rest } = props;
|
|
1233
|
+
return /* @__PURE__ */ jsx("a", {
|
|
1234
|
+
...rest,
|
|
1235
|
+
ref,
|
|
1236
|
+
href: "#",
|
|
1237
|
+
onClick: (event) => {
|
|
1238
|
+
onClick?.(event), event.defaultPrevented || (event.preventDefault(), action(props));
|
|
1239
|
+
},
|
|
1240
|
+
children
|
|
1241
|
+
});
|
|
1242
|
+
});
|
|
1243
|
+
return Link.displayName = name, Link;
|
|
1244
|
+
}
|
|
1245
|
+
/** When the pane re-checks that the focused field is in view, after a path is asked for. */
|
|
1246
|
+
const KEEP_IN_VIEW_MS = [
|
|
1247
|
+
300,
|
|
1248
|
+
700,
|
|
1249
|
+
1200,
|
|
1250
|
+
2e3,
|
|
1251
|
+
2800
|
|
1252
|
+
];
|
|
1253
|
+
/**
|
|
1254
|
+
* Keeps the field Sanity focused for a `path` param in view while the form settles. Sanity scrolls
|
|
1255
|
+
* a field into view as it focuses it, but in a pane that has just mounted, images and rich text
|
|
1256
|
+
* above the field load afterwards and push it out of view. Re-checks a few times and scrolls it
|
|
1257
|
+
* back, until the editor scrolls, clicks or types.
|
|
1258
|
+
*/
|
|
1259
|
+
function useKeepFocusedFieldInView(path, key) {
|
|
1260
|
+
useEffect(() => {
|
|
1261
|
+
if (!path) return;
|
|
1262
|
+
let cancelled = !1, cancel = () => {
|
|
1263
|
+
cancelled = !0;
|
|
1264
|
+
}, events = [
|
|
1265
|
+
"wheel",
|
|
1266
|
+
"touchmove",
|
|
1267
|
+
"pointerdown",
|
|
1268
|
+
"keydown"
|
|
1269
|
+
];
|
|
1270
|
+
for (let name of events) window.addEventListener(name, cancel, {
|
|
1271
|
+
capture: !0,
|
|
1272
|
+
passive: !0
|
|
1273
|
+
});
|
|
1274
|
+
let timers = KEEP_IN_VIEW_MS.map((ms) => setTimeout(() => {
|
|
1275
|
+
if (cancelled) return;
|
|
1276
|
+
let field = document.activeElement;
|
|
1277
|
+
if (!(field instanceof HTMLElement)) return;
|
|
1278
|
+
let scroller = field.closest("[data-testid=\"document-panel-scroller\"]");
|
|
1279
|
+
if (!scroller) return;
|
|
1280
|
+
let view = scroller.getBoundingClientRect(), rect = field.getBoundingClientRect();
|
|
1281
|
+
rect.top >= view.top && rect.bottom <= view.bottom || field.scrollIntoView({ block: "center" });
|
|
1282
|
+
}, ms));
|
|
1283
|
+
return () => {
|
|
1284
|
+
for (let timer of timers) clearTimeout(timer);
|
|
1285
|
+
for (let name of events) window.removeEventListener(name, cancel, { capture: !0 });
|
|
1286
|
+
};
|
|
1287
|
+
}, [path, key]);
|
|
1288
|
+
}
|
|
1289
|
+
function noop(name) {
|
|
1290
|
+
return () => console.warn(`sanity-visual-editor: the document pane has no "${name}"`);
|
|
1291
|
+
}
|
|
1292
|
+
function queryString(params) {
|
|
1293
|
+
let defined = Object.entries(params).flatMap(([key, value]) => value === void 0 ? [] : [[key, value]]);
|
|
1294
|
+
return defined.length ? `?${new URLSearchParams(defined)}` : "";
|
|
1295
|
+
}
|
|
1296
|
+
function PaneRouter({ structure, entry, onParams, onOpen, onBack, onIntent, children }) {
|
|
1297
|
+
let links = useRef({
|
|
1298
|
+
onOpen,
|
|
1299
|
+
onBack,
|
|
1300
|
+
onIntent
|
|
1301
|
+
});
|
|
1302
|
+
links.current = {
|
|
1303
|
+
onOpen,
|
|
1304
|
+
onBack,
|
|
1305
|
+
onIntent
|
|
1306
|
+
};
|
|
1307
|
+
let components = useMemo(() => ({
|
|
1308
|
+
BackLink: paneLink("PaneBackLink", () => links.current.onBack()),
|
|
1309
|
+
ChildLink: paneLink("PaneChildLink", (props) => {
|
|
1310
|
+
props.childType ? links.current.onOpen({
|
|
1311
|
+
id: props.childId,
|
|
1312
|
+
type: props.childType,
|
|
1313
|
+
params: {}
|
|
1314
|
+
}) : links.current.onIntent("edit", { id: props.childId });
|
|
1315
|
+
}),
|
|
1316
|
+
ReferenceChildLink: paneLink("PaneReferenceChildLink", (props) => links.current.onOpen({
|
|
1317
|
+
id: props.documentId,
|
|
1318
|
+
type: props.documentType,
|
|
1319
|
+
params: {}
|
|
1320
|
+
})),
|
|
1321
|
+
ParameterizedLink: paneLink("PaneParameterizedLink", noop("ParameterizedLink"))
|
|
1322
|
+
}), [links]), value = useMemo(() => ({
|
|
1323
|
+
index: 0,
|
|
1324
|
+
groupIndex: 0,
|
|
1325
|
+
siblingIndex: 0,
|
|
1326
|
+
payload: {},
|
|
1327
|
+
params: entry.params,
|
|
1328
|
+
hasGroupSiblings: !1,
|
|
1329
|
+
groupLength: 1,
|
|
1330
|
+
routerPanesState: [],
|
|
1331
|
+
...components,
|
|
1332
|
+
handleEditReference: (options) => onOpen({
|
|
1333
|
+
id: options.id,
|
|
1334
|
+
type: options.type,
|
|
1335
|
+
params: {},
|
|
1336
|
+
template: options.template.id,
|
|
1337
|
+
templateParameters: options.template.params
|
|
1338
|
+
}),
|
|
1339
|
+
replaceCurrent: noop("replaceCurrent"),
|
|
1340
|
+
closeCurrent: onBack,
|
|
1341
|
+
closeCurrentAndAfter: onBack,
|
|
1342
|
+
duplicateCurrent: noop("duplicateCurrent"),
|
|
1343
|
+
setView: noop("setView"),
|
|
1344
|
+
setParams: (params) => onParams(params),
|
|
1345
|
+
setPayload: noop("setPayload"),
|
|
1346
|
+
navigateIntent: (name, params) => onIntent(name, params),
|
|
1347
|
+
createPathWithParams: (params) => queryString({
|
|
1348
|
+
...entry.params,
|
|
1349
|
+
...params
|
|
1350
|
+
})
|
|
1351
|
+
}), [
|
|
1352
|
+
components,
|
|
1353
|
+
entry.params,
|
|
1354
|
+
onBack,
|
|
1355
|
+
onOpen,
|
|
1356
|
+
onParams,
|
|
1357
|
+
onIntent
|
|
1358
|
+
]), { PaneRouterContext } = structure;
|
|
1359
|
+
return /* @__PURE__ */ jsx(PaneRouterContext.Provider, {
|
|
1360
|
+
value,
|
|
1361
|
+
children
|
|
1362
|
+
});
|
|
1363
|
+
}
|
|
1364
|
+
function DocumentPanel({ structure, stack, onChange, onIntent, onFocusPath, fallback }) {
|
|
1365
|
+
let entry = stack[stack.length - 1], depth = stack.length - 1, focusRef = useRef({
|
|
1366
|
+
onFocusPath,
|
|
1367
|
+
id: entry?.id
|
|
1368
|
+
});
|
|
1369
|
+
focusRef.current = {
|
|
1370
|
+
onFocusPath,
|
|
1371
|
+
id: entry?.id
|
|
1372
|
+
};
|
|
1373
|
+
let handleFocusPath = useCallback((path) => {
|
|
1374
|
+
let { onFocusPath: report, id } = focusRef.current, end = path.findIndex((segment) => typeof segment != "string" && typeof segment != "number" && !(typeof segment == "object" && segment && "_key" in segment)), urlPath = toUrlPath(end < 0 ? path : path.slice(0, end));
|
|
1375
|
+
report?.(id && urlPath ? {
|
|
1376
|
+
id,
|
|
1377
|
+
path: urlPath
|
|
1378
|
+
} : null);
|
|
1379
|
+
}, []), paneKey = `${depth}:${entry?.id}`;
|
|
1380
|
+
useEffect(() => {
|
|
1381
|
+
focusRef.current.onFocusPath?.(null);
|
|
1382
|
+
}, [paneKey]), useEffect(() => () => focusRef.current.onFocusPath?.(null), []);
|
|
1383
|
+
let onParams = useCallback((params) => onChange(stack.map((item, index) => index === depth ? {
|
|
1384
|
+
...item,
|
|
1385
|
+
params
|
|
1386
|
+
} : item)), [
|
|
1387
|
+
stack,
|
|
1388
|
+
depth,
|
|
1389
|
+
onChange
|
|
1390
|
+
]), onOpen = useCallback((next) => onChange([...stack, next]), [stack, onChange]), onBack = useCallback(() => onChange(stack.slice(0, -1)), [stack, onChange]);
|
|
1391
|
+
useKeepFocusedFieldInView(entry?.params.path, `${depth}:${entry?.id}`);
|
|
1392
|
+
let pane = useMemo(() => entry && {
|
|
1393
|
+
id: entry.id,
|
|
1394
|
+
type: "document",
|
|
1395
|
+
title: "",
|
|
1396
|
+
options: {
|
|
1397
|
+
id: entry.id,
|
|
1398
|
+
type: entry.type,
|
|
1399
|
+
template: entry.template,
|
|
1400
|
+
templateParameters: entry.templateParameters
|
|
1401
|
+
}
|
|
1402
|
+
}, [entry]);
|
|
1403
|
+
if (!entry || !pane) return null;
|
|
1404
|
+
let { StructureToolProvider, PaneLayout, DocumentPane } = structure;
|
|
1405
|
+
return /* @__PURE__ */ jsx(StructureToolProvider, { children: /* @__PURE__ */ jsx(PaneLayout, {
|
|
1406
|
+
style: { height: "100%" },
|
|
1407
|
+
children: /* @__PURE__ */ jsx(PaneRouter, {
|
|
1408
|
+
structure,
|
|
1409
|
+
entry,
|
|
1410
|
+
onParams,
|
|
1411
|
+
onOpen,
|
|
1412
|
+
onBack,
|
|
1413
|
+
onIntent,
|
|
1414
|
+
children: /* @__PURE__ */ jsx(Suspense, {
|
|
1415
|
+
fallback,
|
|
1416
|
+
children: /* @__PURE__ */ jsx(DocumentPane, {
|
|
1417
|
+
paneKey: "document",
|
|
1418
|
+
index: 1,
|
|
1419
|
+
itemId: "document",
|
|
1420
|
+
pane,
|
|
1421
|
+
onFocusPath: handleFocusPath
|
|
1422
|
+
}, `${depth}:${entry.id}`)
|
|
1423
|
+
})
|
|
1424
|
+
})
|
|
1425
|
+
}) });
|
|
1426
|
+
}
|
|
1427
|
+
/** `isQueryMatch`: every word of the query appears in the title. */
|
|
1428
|
+
function isQueryMatch(query, title) {
|
|
1429
|
+
let lowercaseTitle = title.toLowerCase();
|
|
1430
|
+
return query.trim().toLowerCase().split(/[\s\-_]+/).every((word) => lowercaseTitle.includes(word));
|
|
1431
|
+
}
|
|
1432
|
+
/** `sortResultRelevance`: titles starting with the query, then containing it. */
|
|
1433
|
+
function relevance(query, a, b) {
|
|
1434
|
+
let q = query.trim().toLowerCase(), x = a.toLowerCase(), y = b.toLowerCase();
|
|
1435
|
+
return x.startsWith(q) === y.startsWith(q) ? x.includes(q) === y.includes(q) ? 0 : x.includes(q) ? -1 : 1 : x.startsWith(q) ? -1 : 1;
|
|
1436
|
+
}
|
|
1437
|
+
function OptionIcon({ icon }) {
|
|
1438
|
+
if (!icon) return null;
|
|
1439
|
+
let props = {
|
|
1440
|
+
"aria-hidden": !0,
|
|
1441
|
+
style: {
|
|
1442
|
+
display: "block",
|
|
1443
|
+
fontSize: 21,
|
|
1444
|
+
margin: "-0.375rem",
|
|
1445
|
+
color: "var(--card-icon-color)"
|
|
1446
|
+
}
|
|
1447
|
+
}, node = isValidElement(icon) ? cloneElement(icon, props) : typeof icon == "function" || typeof icon == "object" && icon ? createElement(icon, props) : icon;
|
|
1448
|
+
return /* @__PURE__ */ jsx(Box, { children: node });
|
|
1449
|
+
}
|
|
1450
|
+
/** `NewDocumentListOption` with `preview: 'inline'`. */
|
|
1451
|
+
function OptionItem({ option, href, onSelect }) {
|
|
1452
|
+
let muted = option.hasPermission ? void 0 : { color: "var(--card-fg-color)" }, content = /* @__PURE__ */ jsxs(Flex, {
|
|
1453
|
+
align: "center",
|
|
1454
|
+
gap: 3,
|
|
1455
|
+
children: [/* @__PURE__ */ jsx(OptionIcon, { icon: option.icon }), /* @__PURE__ */ jsx(Text, {
|
|
1456
|
+
size: 1,
|
|
1457
|
+
as: "div",
|
|
1458
|
+
style: muted,
|
|
1459
|
+
children: option.title
|
|
1460
|
+
})]
|
|
1461
|
+
});
|
|
1462
|
+
return /* @__PURE__ */ jsx("div", { children: option.hasPermission ? /* @__PURE__ */ jsx(Card, {
|
|
1463
|
+
as: "a",
|
|
1464
|
+
href,
|
|
1465
|
+
marginBottom: 1,
|
|
1466
|
+
padding: 3,
|
|
1467
|
+
radius: 2,
|
|
1468
|
+
onClick: (event) => {
|
|
1469
|
+
event.metaKey || event.ctrlKey || event.shiftKey || event.button !== 0 || (event.preventDefault(), onSelect(option));
|
|
1470
|
+
},
|
|
1471
|
+
children: content
|
|
1472
|
+
}) : /* @__PURE__ */ jsx(Card, {
|
|
1473
|
+
as: "button",
|
|
1474
|
+
disabled: !0,
|
|
1475
|
+
marginBottom: 1,
|
|
1476
|
+
padding: 3,
|
|
1477
|
+
radius: 2,
|
|
1478
|
+
children: content
|
|
1479
|
+
}) });
|
|
1480
|
+
}
|
|
1481
|
+
function NewDocumentMenu({ sanity, studioPath, anchor, open, onClose, onSelect }) {
|
|
1482
|
+
let place = useBarPlacement(), source = sanity.useSource(), templateItems = useMemo(() => source.document.resolveNewDocumentOptions({ type: "global" }), [source]), [permissions, loading] = sanity.useTemplatePermissions({ templateItems }), getI18nText = sanity.useGetI18nText(templateItems), [query, setQuery] = useState(""), [input, setInput] = useState(null), popover = useRef(null), options = useMemo(() => templateItems.map((item) => ({
|
|
1483
|
+
...item,
|
|
1484
|
+
title: getI18nText({
|
|
1485
|
+
...item,
|
|
1486
|
+
title: item.title || item.id
|
|
1487
|
+
}).title ?? item.id,
|
|
1488
|
+
hasPermission: permissions?.find((p) => p.id === item.id)?.granted ?? !1
|
|
1489
|
+
})).sort((a, b) => a.title.localeCompare(b.title)).filter((option) => isQueryMatch(query, option.title)).sort((a, b) => relevance(query, a.title, b.title)), [
|
|
1490
|
+
templateItems,
|
|
1491
|
+
permissions,
|
|
1492
|
+
getI18nText,
|
|
1493
|
+
query
|
|
1494
|
+
]);
|
|
1495
|
+
function close() {
|
|
1496
|
+
setQuery(""), onClose();
|
|
1497
|
+
}
|
|
1498
|
+
useClickOutsideEvent(open && close, () => [anchor, popover.current]);
|
|
1499
|
+
let { CommandList } = sanity, content = /* @__PURE__ */ jsxs(Flex, {
|
|
1500
|
+
direction: "column",
|
|
1501
|
+
style: { width: 320 },
|
|
1502
|
+
onKeyDown: (event) => {
|
|
1503
|
+
(event.key === "Escape" || event.key === "Tab") && close();
|
|
1504
|
+
},
|
|
1505
|
+
children: [/* @__PURE__ */ jsx(Card, {
|
|
1506
|
+
borderBottom: !0,
|
|
1507
|
+
padding: 1,
|
|
1508
|
+
style: { minHeight: "max-content" },
|
|
1509
|
+
children: /* @__PURE__ */ jsx(TextInput, {
|
|
1510
|
+
ref: setInput,
|
|
1511
|
+
__unstable_disableFocusRing: !0,
|
|
1512
|
+
border: !1,
|
|
1513
|
+
fontSize: 1,
|
|
1514
|
+
radius: 1,
|
|
1515
|
+
icon: SearchIcon,
|
|
1516
|
+
placeholder: "Search document types",
|
|
1517
|
+
disabled: loading,
|
|
1518
|
+
value: query,
|
|
1519
|
+
onChange: (event) => setQuery(event.currentTarget.value)
|
|
1520
|
+
})
|
|
1521
|
+
}), /* @__PURE__ */ jsx(Flex, {
|
|
1522
|
+
direction: "column",
|
|
1523
|
+
overflow: "hidden",
|
|
1524
|
+
style: {
|
|
1525
|
+
position: "relative",
|
|
1526
|
+
maxHeight: "calc(33px * 10 + 0.5rem)",
|
|
1527
|
+
minHeight: 33,
|
|
1528
|
+
height: `calc(33px * ${Math.min(Math.max(options.length, 1), 10)} + 0.5rem)`
|
|
1529
|
+
},
|
|
1530
|
+
children: loading ? null : options.length === 0 ? /* @__PURE__ */ jsx(Flex, {
|
|
1531
|
+
align: "center",
|
|
1532
|
+
justify: "center",
|
|
1533
|
+
padding: 4,
|
|
1534
|
+
flex: 1,
|
|
1535
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
1536
|
+
align: "center",
|
|
1537
|
+
muted: !0,
|
|
1538
|
+
size: 1,
|
|
1539
|
+
as: "div",
|
|
1540
|
+
children: query ? `No results for "${query}"` : "No document types found"
|
|
1541
|
+
})
|
|
1542
|
+
}) : /* @__PURE__ */ jsx(CommandList, {
|
|
1543
|
+
activeItemDataAttr: "data-hovered",
|
|
1544
|
+
ariaLabel: "New document",
|
|
1545
|
+
autoFocus: "input",
|
|
1546
|
+
getItemDisabled: (index) => !(options[index]?.hasPermission ?? !0),
|
|
1547
|
+
inputElement: input,
|
|
1548
|
+
itemHeight: 33,
|
|
1549
|
+
items: options,
|
|
1550
|
+
overscan: 5,
|
|
1551
|
+
padding: 1,
|
|
1552
|
+
paddingBottom: 0,
|
|
1553
|
+
renderItem: (option) => /* @__PURE__ */ jsx(OptionItem, {
|
|
1554
|
+
option,
|
|
1555
|
+
href: `${studioPath}/intent/create/template=${encodeURIComponent(option.templateId)};type=${encodeURIComponent(option.schemaType)}`,
|
|
1556
|
+
onSelect: (picked) => {
|
|
1557
|
+
close(), onSelect(picked);
|
|
1558
|
+
}
|
|
1559
|
+
}, option.id)
|
|
1560
|
+
})
|
|
1561
|
+
})]
|
|
1562
|
+
});
|
|
1563
|
+
return /* @__PURE__ */ jsx(Popover, {
|
|
1564
|
+
ref: popover,
|
|
1565
|
+
referenceElement: anchor,
|
|
1566
|
+
open,
|
|
1567
|
+
content,
|
|
1568
|
+
constrainSize: !0,
|
|
1569
|
+
portal: !0,
|
|
1570
|
+
radius: 3,
|
|
1571
|
+
tone: "default",
|
|
1572
|
+
placement: place("top-start"),
|
|
1573
|
+
fallbackPlacements: [place("top-end")],
|
|
1574
|
+
zOffset: 3e3
|
|
1575
|
+
});
|
|
1576
|
+
}
|
|
1577
|
+
/**
|
|
1578
|
+
* The Studio layer: for signed-in editors only, a `StudioProvider` with the project's own Studio
|
|
1579
|
+
* config, so the bar can use Studio state and components. `sanity` and the config load lazily
|
|
1580
|
+
* (they're the embedded Studio's own chunks, usually cached already). The provider gets an
|
|
1581
|
+
* in-memory router, so it never touches the bar's URL.
|
|
1582
|
+
*
|
|
1583
|
+
* - Search: the Studio's own `SearchPopover` (previews, filters, recent searches), pre-filtered to
|
|
1584
|
+
* the types that have pages; picking a result reports `{_id, _type}` up instead of opening it.
|
|
1585
|
+
* - Document pane: the Studio's document editor for the page's document, in a column on the right
|
|
1586
|
+
* (`DocumentPanel`); `sanity/structure` loads the first time it opens.
|
|
1587
|
+
*
|
|
1588
|
+
* The provider's router follows the bar's perspective through its sticky `perspective` and
|
|
1589
|
+
* `excludedPerspectives` params (what the Studio's own URL carries), so the pane edits the drafts or
|
|
1590
|
+
* the release version the page is showing.
|
|
1591
|
+
*/
|
|
1592
|
+
/** The perspective params as the bar's menu selection (no param is drafts, as in the Studio). */
|
|
1593
|
+
function selectionFromParams(search) {
|
|
1594
|
+
let params = new URLSearchParams(search), excluded = params.get("excludedPerspectives");
|
|
1595
|
+
return {
|
|
1596
|
+
selected: params.get("perspective") || "drafts",
|
|
1597
|
+
excluded: excluded ? excluded.split(",").filter(Boolean) : []
|
|
1598
|
+
};
|
|
1599
|
+
}
|
|
1600
|
+
/** The perspective sticky params the bar controls. */
|
|
1601
|
+
const PERSPECTIVE_PARAMS = ["perspective", "excludedPerspectives"];
|
|
1602
|
+
/** Hides the "All fields" group on a type with field groups, and on inline object fields in it. */
|
|
1603
|
+
function hideAllFieldsGroup(definition, allFields) {
|
|
1604
|
+
if (typeof definition != "object" || !definition) return definition;
|
|
1605
|
+
let type = definition, next = type;
|
|
1606
|
+
if (Array.isArray(type.groups) && type.groups.length > 0) {
|
|
1607
|
+
let groups = type.groups.some((group) => group.name === allFields.name) ? type.groups.map((group) => group.name === allFields.name ? {
|
|
1608
|
+
...group,
|
|
1609
|
+
hidden: !0
|
|
1610
|
+
} : group) : [{
|
|
1611
|
+
...allFields,
|
|
1612
|
+
hidden: !0
|
|
1613
|
+
}, ...type.groups];
|
|
1614
|
+
next = {
|
|
1615
|
+
...next,
|
|
1616
|
+
groups
|
|
1617
|
+
};
|
|
1618
|
+
}
|
|
1619
|
+
return Array.isArray(type.fields) && (next = {
|
|
1620
|
+
...next,
|
|
1621
|
+
fields: type.fields.map((field) => hideAllFieldsGroup(field, allFields))
|
|
1622
|
+
}), Array.isArray(type.of) && (next = {
|
|
1623
|
+
...next,
|
|
1624
|
+
of: type.of.map((member) => hideAllFieldsGroup(member, allFields))
|
|
1625
|
+
}), next;
|
|
1626
|
+
}
|
|
1627
|
+
/**
|
|
1628
|
+
* The project's config with "All fields" hidden (Sanity's `ALL_FIELDS_GROUP` with `hidden: true`)
|
|
1629
|
+
* on every type that has field groups. The root config's `schema.types` resolves after every
|
|
1630
|
+
* plugin's, so wrapping it sees all types. Only the bar's own copy of the config changes; the
|
|
1631
|
+
* Studio itself still shows the group.
|
|
1632
|
+
*/
|
|
1633
|
+
function withoutAllFieldsGroup(config, allFields) {
|
|
1634
|
+
let hide = (types) => types.map((type) => hideAllFieldsGroup(type, allFields)), add = (workspace) => {
|
|
1635
|
+
let value = workspace, types = value.schema?.types;
|
|
1636
|
+
return {
|
|
1637
|
+
...value,
|
|
1638
|
+
schema: {
|
|
1639
|
+
...value.schema,
|
|
1640
|
+
types: (previous, context) => hide(typeof types == "function" ? types(previous, context) : [...previous, ...types ?? []])
|
|
1641
|
+
}
|
|
1642
|
+
};
|
|
1643
|
+
};
|
|
1644
|
+
return Array.isArray(config) ? config.map(add) : add(config);
|
|
1645
|
+
}
|
|
1646
|
+
/** Intent parameters from a Studio intent path segment, `id=abc;type=page`. */
|
|
1647
|
+
function intentParams(segment) {
|
|
1648
|
+
return Object.fromEntries(segment.split(";").flatMap((pair) => {
|
|
1649
|
+
let [key, value] = pair.split("=");
|
|
1650
|
+
return key && value !== void 0 ? [[decodeURIComponent(key), decodeURIComponent(value)]] : [];
|
|
1651
|
+
}));
|
|
1652
|
+
}
|
|
1653
|
+
/** The Studio's URL for an intent, `/studio/intent/edit/id=abc;type=page`. */
|
|
1654
|
+
function intentHref(studioPath, name, params) {
|
|
1655
|
+
let segment = Object.entries(params).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join(";");
|
|
1656
|
+
return `${studioPath}/intent/${encodeURIComponent(name)}/${segment}`;
|
|
1657
|
+
}
|
|
1658
|
+
/** Studio's pane resizer: an invisible strip on the pane's edge that shows a line while in use. */
|
|
1659
|
+
function PaneResizer({ width, side, resize }) {
|
|
1660
|
+
let direction = side === "right" ? -1 : 1, drag = useRef(null), [active, setActive] = useState(!1);
|
|
1661
|
+
function onPointerDown(event) {
|
|
1662
|
+
event.button === 0 && (event.preventDefault(), event.currentTarget.setPointerCapture(event.pointerId), drag.current = {
|
|
1663
|
+
x: event.clientX,
|
|
1664
|
+
width
|
|
1665
|
+
}, setActive(!0), resize.start());
|
|
1666
|
+
}
|
|
1667
|
+
function onPointerMove(event) {
|
|
1668
|
+
if (drag.current) {
|
|
1669
|
+
if (event.buttons === 0) return onPointerUp();
|
|
1670
|
+
resize.to(drag.current.width + direction * (event.clientX - drag.current.x));
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
function onPointerUp() {
|
|
1674
|
+
drag.current && (drag.current = null, setActive(!1), resize.end());
|
|
1675
|
+
}
|
|
1676
|
+
let endRef = useRef(onPointerUp);
|
|
1677
|
+
endRef.current = onPointerUp, useEffect(() => {
|
|
1678
|
+
if (!active) return;
|
|
1679
|
+
let end = () => endRef.current();
|
|
1680
|
+
return window.addEventListener("blur", end), () => window.removeEventListener("blur", end);
|
|
1681
|
+
}, [active]);
|
|
1682
|
+
function onKeyDown(event) {
|
|
1683
|
+
let step = event.shiftKey ? 64 : 16;
|
|
1684
|
+
if (event.key === "ArrowLeft") resize.to(width - direction * step);
|
|
1685
|
+
else if (event.key === "ArrowRight") resize.to(width + direction * step);
|
|
1686
|
+
else return;
|
|
1687
|
+
event.preventDefault();
|
|
1688
|
+
}
|
|
1689
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1690
|
+
role: "separator",
|
|
1691
|
+
"aria-orientation": "vertical",
|
|
1692
|
+
"aria-label": "Resize editor",
|
|
1693
|
+
"aria-valuenow": width,
|
|
1694
|
+
tabIndex: 0,
|
|
1695
|
+
className: "preview-bar-pane-resizer",
|
|
1696
|
+
"data-side": side,
|
|
1697
|
+
"data-active": active ? "" : void 0,
|
|
1698
|
+
onPointerDown,
|
|
1699
|
+
onPointerMove,
|
|
1700
|
+
onPointerUp,
|
|
1701
|
+
onPointerCancel: onPointerUp,
|
|
1702
|
+
onLostPointerCapture: onPointerUp,
|
|
1703
|
+
onKeyDown,
|
|
1704
|
+
onKeyUp: (event) => {
|
|
1705
|
+
(event.key === "ArrowLeft" || event.key === "ArrowRight") && resize.end();
|
|
1706
|
+
}
|
|
1707
|
+
});
|
|
1708
|
+
}
|
|
1709
|
+
/** Reports the editor's Studio client and user ID (the share menu's sharing switch). */
|
|
1710
|
+
function SharingClientBridge({ sanity, onClient }) {
|
|
1711
|
+
let client = sanity.useClient({ apiVersion: "2025-02-19" }), userId = sanity.useCurrentUser()?.id;
|
|
1712
|
+
return useEffect(() => (onClient({
|
|
1713
|
+
client,
|
|
1714
|
+
userId
|
|
1715
|
+
}), () => onClient(null)), [
|
|
1716
|
+
client,
|
|
1717
|
+
userId,
|
|
1718
|
+
onClient
|
|
1719
|
+
]), null;
|
|
1720
|
+
}
|
|
1721
|
+
/** Sets the Studio search's type filter to the page types once, the first time it opens. */
|
|
1722
|
+
function TypeFilterPreset({ sanity, types }) {
|
|
1723
|
+
let { state, dispatch } = sanity.useSearchState(), schema = sanity.useSchema(), done = useRef(!1);
|
|
1724
|
+
return useEffect(() => {
|
|
1725
|
+
if (done.current) return;
|
|
1726
|
+
done.current = !0;
|
|
1727
|
+
let current = new Set((state.terms.types ?? []).map((type) => type.name));
|
|
1728
|
+
for (let name of types) {
|
|
1729
|
+
let schemaType = schema.get(name);
|
|
1730
|
+
schemaType && !current.has(name) && dispatch({
|
|
1731
|
+
type: "TERMS_TYPE_ADD",
|
|
1732
|
+
schemaType
|
|
1733
|
+
});
|
|
1734
|
+
}
|
|
1735
|
+
}, []), null;
|
|
1736
|
+
}
|
|
1737
|
+
/**
|
|
1738
|
+
* The Studio's layout middleware (`studio.components.layout`) with the pane in place of the Studio's
|
|
1739
|
+
* own layout. Comments and Tasks mount their providers there (`AddonDatasetProvider`, …), and the
|
|
1740
|
+
* document pane needs them; Presentation gets them by running inside the Studio layout.
|
|
1741
|
+
*/
|
|
1742
|
+
const LayoutSlot = createContext(null);
|
|
1743
|
+
function LayoutSlotContent() {
|
|
1744
|
+
return /* @__PURE__ */ jsx(Fragment, { children: useContext(LayoutSlot) });
|
|
1745
|
+
}
|
|
1746
|
+
const layoutMiddleware = {
|
|
1747
|
+
pick: (plugin) => plugin.studio?.components?.layout,
|
|
1748
|
+
defaultComponent: LayoutSlotContent
|
|
1749
|
+
};
|
|
1750
|
+
function StudioLayoutMiddleware({ sanity, children }) {
|
|
1751
|
+
let Layout = sanity.useMiddlewareComponents(layoutMiddleware);
|
|
1752
|
+
return /* @__PURE__ */ jsx(LayoutSlot.Provider, {
|
|
1753
|
+
value: children,
|
|
1754
|
+
children: /* @__PURE__ */ jsx(Layout, {})
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1757
|
+
function PanelLoading() {
|
|
1758
|
+
return /* @__PURE__ */ jsx(Flex, {
|
|
1759
|
+
align: "center",
|
|
1760
|
+
justify: "center",
|
|
1761
|
+
height: "fill",
|
|
1762
|
+
children: /* @__PURE__ */ jsx(Spinner, { muted: !0 })
|
|
1763
|
+
});
|
|
1764
|
+
}
|
|
1765
|
+
/** The pane's column: right edge, top to bottom (or down to the bar, on narrow viewports). */
|
|
1766
|
+
/**
|
|
1767
|
+
* Presentation's "Preview this page" locations banner, which it adds above every document form,
|
|
1768
|
+
* is redundant beside the page itself. Its header renders only for the first Presentation options
|
|
1769
|
+
* registered in `PresentationDocumentContext` (so nested Presentation tools show one banner); this
|
|
1770
|
+
* outer context registers a placeholder first and ignores the plugin's own registration, so the
|
|
1771
|
+
* banner renders nothing. The context lives in `sanity/_singletons`, the one copy Presentation uses.
|
|
1772
|
+
*/
|
|
1773
|
+
const NO_LOCATIONS = {
|
|
1774
|
+
options: [{}],
|
|
1775
|
+
register: () => () => {}
|
|
1776
|
+
};
|
|
1777
|
+
/**
|
|
1778
|
+
* Studio links in the pane (intent links, links to other tools) would navigate the bar's in-memory
|
|
1779
|
+
* router, which shows nothing. A capture listener on the pane takes their clicks first (React
|
|
1780
|
+
* handles clicks at its root, after this): an edit intent opens in the pane, anything else opens
|
|
1781
|
+
* the Studio in a new tab. Links with `#` (the pane's own router links) are left alone.
|
|
1782
|
+
*/
|
|
1783
|
+
function useStudioLinks(studioPath, onIntent) {
|
|
1784
|
+
let [element, setElement] = useState(null);
|
|
1785
|
+
return useEffect(() => {
|
|
1786
|
+
if (!element) return;
|
|
1787
|
+
let root = studioPath.replace(/\/$/, "");
|
|
1788
|
+
function onClick(event) {
|
|
1789
|
+
if (event.defaultPrevented || event.button !== 0) return;
|
|
1790
|
+
let anchor = event.target?.closest?.("a[href]");
|
|
1791
|
+
if (!anchor || !element?.contains(anchor)) return;
|
|
1792
|
+
let url = new URL(anchor.getAttribute("href") ?? "", window.location.href);
|
|
1793
|
+
if (url.origin !== window.location.origin || !url.pathname.startsWith(`${root}/`)) return;
|
|
1794
|
+
event.preventDefault(), event.stopPropagation();
|
|
1795
|
+
let intent = url.pathname.slice(root.length).match(/^\/intent\/([^/]+)\/([^/]*)/);
|
|
1796
|
+
intent?.[1] && !(event.metaKey || event.ctrlKey || event.shiftKey) ? onIntent(decodeURIComponent(intent[1]), intentParams(intent[2] ?? "")) : window.open(`${url.pathname}${url.search}`, "_blank", "noopener");
|
|
1797
|
+
}
|
|
1798
|
+
return element.addEventListener("click", onClick, !0), () => element.removeEventListener("click", onClick, !0);
|
|
1799
|
+
}, [
|
|
1800
|
+
element,
|
|
1801
|
+
studioPath,
|
|
1802
|
+
onIntent
|
|
1803
|
+
]), setElement;
|
|
1804
|
+
}
|
|
1805
|
+
function PanelColumn({ sanity, panel, studioPath, onIntent }) {
|
|
1806
|
+
let linksRef = useStudioLinks(studioPath, onIntent), [modules, setModules] = useState(null);
|
|
1807
|
+
return useEffect(() => {
|
|
1808
|
+
let cancelled = !1;
|
|
1809
|
+
return Promise.all([import("sanity/structure"), import("sanity/_singletons")]).then(([structure, singletons]) => {
|
|
1810
|
+
cancelled || setModules({
|
|
1811
|
+
structure,
|
|
1812
|
+
presentationDocument: singletons.PresentationDocumentContext
|
|
1813
|
+
});
|
|
1814
|
+
}).catch((error) => console.error("sanity-visual-editor: could not load the document pane", error)), () => {
|
|
1815
|
+
cancelled = !0;
|
|
1816
|
+
};
|
|
1817
|
+
}, []), /* @__PURE__ */ jsxs("div", {
|
|
1818
|
+
ref: linksRef,
|
|
1819
|
+
"data-preview-bar-panel": "",
|
|
1820
|
+
style: {
|
|
1821
|
+
position: "fixed",
|
|
1822
|
+
top: !panel.fullHeight && panel.barPosition === "top" ? 50 : 0,
|
|
1823
|
+
[panel.side]: 0,
|
|
1824
|
+
bottom: !panel.fullHeight && panel.barPosition === "bottom" ? 50 : 0,
|
|
1825
|
+
width: panel.width
|
|
1826
|
+
},
|
|
1827
|
+
children: [/* @__PURE__ */ jsx(Card, {
|
|
1828
|
+
borderLeft: panel.side === "right",
|
|
1829
|
+
borderRight: panel.side === "left",
|
|
1830
|
+
shadow: 2,
|
|
1831
|
+
height: "fill",
|
|
1832
|
+
overflow: "hidden",
|
|
1833
|
+
children: modules ? /* @__PURE__ */ jsx(StudioLayoutMiddleware, {
|
|
1834
|
+
sanity,
|
|
1835
|
+
children: /* @__PURE__ */ jsx(modules.presentationDocument.Provider, {
|
|
1836
|
+
value: NO_LOCATIONS,
|
|
1837
|
+
children: /* @__PURE__ */ jsx(DocumentPanel, {
|
|
1838
|
+
structure: modules.structure,
|
|
1839
|
+
stack: panel.stack,
|
|
1840
|
+
onChange: panel.onChange,
|
|
1841
|
+
onIntent,
|
|
1842
|
+
fallback: /* @__PURE__ */ jsx(PanelLoading, {})
|
|
1843
|
+
})
|
|
1844
|
+
})
|
|
1845
|
+
}) : /* @__PURE__ */ jsx(PanelLoading, {})
|
|
1846
|
+
}), panel.resize && /* @__PURE__ */ jsx(PaneResizer, {
|
|
1847
|
+
width: panel.width,
|
|
1848
|
+
side: panel.side,
|
|
1849
|
+
resize: panel.resize
|
|
1850
|
+
})]
|
|
1851
|
+
});
|
|
1852
|
+
}
|
|
1853
|
+
/**
|
|
1854
|
+
* The search popover's own layer. `SearchPopover` closes on Escape and outside clicks only while
|
|
1855
|
+
* it is the top layer (no layers above it), and draws its backdrop and card in the layer's
|
|
1856
|
+
* z-index; without its own, it shares the Studio's root layer with the document pane's layers, so
|
|
1857
|
+
* it never closes while the pane is open and sits under the pane. In the Visual Editor
|
|
1858
|
+
* (`portal`), it also covers the whole tool, as the navbar's search covers the Studio: its
|
|
1859
|
+
* backdrop and card are absolutely positioned, so they're placed against a viewport-sized box on
|
|
1860
|
+
* the body instead of the bar's column.
|
|
1861
|
+
*/
|
|
1862
|
+
function SearchLayer({ portal, children }) {
|
|
1863
|
+
let layer = /* @__PURE__ */ jsx(LayerProvider, {
|
|
1864
|
+
zOffset: SEARCH_Z_OFFSET,
|
|
1865
|
+
children
|
|
1866
|
+
});
|
|
1867
|
+
return portal ? createPortal(/* @__PURE__ */ jsx("div", {
|
|
1868
|
+
className: "preview-bar-search-layer",
|
|
1869
|
+
style: {
|
|
1870
|
+
position: "absolute",
|
|
1871
|
+
inset: 0,
|
|
1872
|
+
pointerEvents: "none"
|
|
1873
|
+
},
|
|
1874
|
+
children: layer
|
|
1875
|
+
}), document.body) : layer;
|
|
1876
|
+
}
|
|
1877
|
+
/** Above the document pane's layers (its headers, menus and dialogs sit well below 1000). */
|
|
1878
|
+
const SEARCH_Z_OFFSET = 1e3;
|
|
1879
|
+
function StudioLayer({ load, studioPath, perspective, onPerspectiveChange, onSharingClient, newDocument, panel, allFieldsGroup = !0, search, native, onReady, onError }) {
|
|
1880
|
+
let [loaded, setLoaded] = useState(() => native ? {
|
|
1881
|
+
sanity: native,
|
|
1882
|
+
config: null,
|
|
1883
|
+
history: null
|
|
1884
|
+
} : null), location = perspective ? `${studioPath}?${perspective}` : studioPath, locationRef = useRef(location);
|
|
1885
|
+
locationRef.current = location, useEffect(() => {
|
|
1886
|
+
if (native) {
|
|
1887
|
+
onReady?.();
|
|
1888
|
+
return;
|
|
1889
|
+
}
|
|
1890
|
+
if (!load) return;
|
|
1891
|
+
let cancelled = !1;
|
|
1892
|
+
return Promise.all([
|
|
1893
|
+
import("sanity"),
|
|
1894
|
+
import("history"),
|
|
1895
|
+
load()
|
|
1896
|
+
]).then(([sanity, { createMemoryHistory }, config]) => {
|
|
1897
|
+
if (cancelled) return;
|
|
1898
|
+
let studio = sanity;
|
|
1899
|
+
setLoaded({
|
|
1900
|
+
sanity: studio,
|
|
1901
|
+
config: allFieldsGroup ? config : withoutAllFieldsGroup(config, studio.ALL_FIELDS_GROUP),
|
|
1902
|
+
history: createMemoryHistory({ initialEntries: [locationRef.current] })
|
|
1903
|
+
}), onReady?.();
|
|
1904
|
+
}).catch((error) => {
|
|
1905
|
+
console.error("sanity-visual-editor: could not load the Studio layer", error), onError?.(error);
|
|
1906
|
+
}), () => {
|
|
1907
|
+
cancelled = !0;
|
|
1908
|
+
};
|
|
1909
|
+
}, [load, studioPath]), useEffect(() => {
|
|
1910
|
+
if (!loaded?.history) return;
|
|
1911
|
+
let { pathname, search } = loaded.history.location, params = new URLSearchParams(search);
|
|
1912
|
+
for (let name of PERSPECTIVE_PARAMS) params.delete(name);
|
|
1913
|
+
for (let [name, value] of new URLSearchParams(perspective ?? "")) params.set(name, value);
|
|
1914
|
+
let query = params.toString(), next = query ? `${pathname}?${query}` : pathname;
|
|
1915
|
+
next !== `${pathname}${search}` && loaded.history.replace(next);
|
|
1916
|
+
}, [loaded, perspective]);
|
|
1917
|
+
let perspectiveRef = useRef({
|
|
1918
|
+
perspective,
|
|
1919
|
+
onPerspectiveChange
|
|
1920
|
+
});
|
|
1921
|
+
perspectiveRef.current = {
|
|
1922
|
+
perspective,
|
|
1923
|
+
onPerspectiveChange
|
|
1924
|
+
}, useEffect(() => {
|
|
1925
|
+
if (loaded?.history) return loaded.history.listen(({ location: next }) => {
|
|
1926
|
+
let { perspective: current, onPerspectiveChange: report } = perspectiveRef.current, studio = selectionFromParams(next.search), bar = selectionFromParams(current ?? "");
|
|
1927
|
+
(studio.selected !== bar.selected || [...studio.excluded].sort().join() !== [...bar.excluded].sort().join()) && report?.(studio);
|
|
1928
|
+
});
|
|
1929
|
+
}, [loaded]);
|
|
1930
|
+
let panelRef = useRef(panel);
|
|
1931
|
+
panelRef.current = panel;
|
|
1932
|
+
let openIntent = useRef((name, params) => {
|
|
1933
|
+
let current = panelRef.current;
|
|
1934
|
+
name === "edit" && params.id && params.type && current && current.stack.length > 0 ? current.onChange([...current.stack, {
|
|
1935
|
+
id: params.id,
|
|
1936
|
+
type: params.type,
|
|
1937
|
+
params: {}
|
|
1938
|
+
}]) : window.open(intentHref(studioPath, name, params), "_blank", "noopener");
|
|
1939
|
+
}).current;
|
|
1940
|
+
if (!loaded) return null;
|
|
1941
|
+
let { sanity } = loaded, { StudioProvider, SearchProvider, SearchPopover } = sanity, content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1942
|
+
onSharingClient && /* @__PURE__ */ jsx(SharingClientBridge, {
|
|
1943
|
+
sanity,
|
|
1944
|
+
onClient: onSharingClient
|
|
1945
|
+
}),
|
|
1946
|
+
newDocument?.open && /* @__PURE__ */ jsx(NewDocumentMenu, {
|
|
1947
|
+
sanity,
|
|
1948
|
+
studioPath,
|
|
1949
|
+
...newDocument
|
|
1950
|
+
}),
|
|
1951
|
+
search && /* @__PURE__ */ jsx(SearchLayer, {
|
|
1952
|
+
portal: !!native,
|
|
1953
|
+
children: /* @__PURE__ */ jsxs(SearchProvider, { children: [search.open && /* @__PURE__ */ jsx(TypeFilterPreset, {
|
|
1954
|
+
sanity,
|
|
1955
|
+
types: search.types
|
|
1956
|
+
}), /* @__PURE__ */ jsx(SearchPopover, {
|
|
1957
|
+
open: search.open,
|
|
1958
|
+
onClose: search.onClose,
|
|
1959
|
+
onItemSelect: search.onSelect,
|
|
1960
|
+
disableIntentLink: !0
|
|
1961
|
+
})] })
|
|
1962
|
+
}),
|
|
1963
|
+
panel && panel.stack.length > 0 && /* @__PURE__ */ jsx(PanelColumn, {
|
|
1964
|
+
sanity,
|
|
1965
|
+
panel,
|
|
1966
|
+
studioPath,
|
|
1967
|
+
onIntent: openIntent
|
|
1968
|
+
})
|
|
1969
|
+
] });
|
|
1970
|
+
return loaded.history ? /* @__PURE__ */ jsx(StudioProvider, {
|
|
1971
|
+
config: loaded.config,
|
|
1972
|
+
basePath: studioPath,
|
|
1973
|
+
unstable_history: loaded.history,
|
|
1974
|
+
unstable_noAuthBoundary: !0,
|
|
1975
|
+
children: content
|
|
1976
|
+
}) : content;
|
|
1977
|
+
}
|
|
1978
|
+
/**
|
|
1979
|
+
* Pending refresh requests: `request` posts a refresh and resolves on the next `settle` (the
|
|
1980
|
+
* host's `refreshed`), or after `timeoutMs` when the page never answers.
|
|
1981
|
+
*/
|
|
1982
|
+
function createRefreshWaiter(post, timeoutMs = 5e3) {
|
|
1983
|
+
let pending = /* @__PURE__ */ new Set();
|
|
1984
|
+
return {
|
|
1985
|
+
request: () => new Promise((resolve) => {
|
|
1986
|
+
let done = () => {
|
|
1987
|
+
clearTimeout(timer), pending.delete(done), resolve();
|
|
1988
|
+
}, timer = setTimeout(done, timeoutMs);
|
|
1989
|
+
pending.add(done), post();
|
|
1990
|
+
}),
|
|
1991
|
+
settle: () => {
|
|
1992
|
+
for (let done of [...pending]) done();
|
|
1993
|
+
}
|
|
1994
|
+
};
|
|
1995
|
+
}
|
|
1996
|
+
/**
|
|
1997
|
+
* The project's mark, as the Studio draws a workspace icon (`WorkspacePreviewIcon`): inline SVG
|
|
1998
|
+
* markup (trusted, from the server's options) in the text colour, or an image URL.
|
|
1999
|
+
*
|
|
2000
|
+
* - `small`, the navbar's `HomeButton`: a 25×25 `LogoMarkContainer` (`Card radius={2}`, 3px, with
|
|
2001
|
+
* `overflow: hidden`). An SVG mark is 22×23 like `MainIcon`; an image fills the tile.
|
|
2002
|
+
* - `large`, the workspace menu: a 41×41 `Media` box (`border-radius: 0.25rem`). The mark keeps its
|
|
2003
|
+
* own size, as Studio icons that fix it do (an SVG `MainIcon` at 22×23 with `margin: auto`,
|
|
2004
|
+
* centred; an `<img>` at 25px in the top-left corner).
|
|
2005
|
+
*/
|
|
2006
|
+
function Logo({ logo, size = "small" }) {
|
|
2007
|
+
let svg = logo.trimStart().startsWith("<svg");
|
|
2008
|
+
return size === "large" ? /* @__PURE__ */ jsx("span", {
|
|
2009
|
+
"aria-hidden": "true",
|
|
2010
|
+
style: {
|
|
2011
|
+
display: "block",
|
|
2012
|
+
flex: "none",
|
|
2013
|
+
width: 41,
|
|
2014
|
+
height: 41,
|
|
2015
|
+
borderRadius: 4
|
|
2016
|
+
},
|
|
2017
|
+
children: svg ? /* @__PURE__ */ jsx("span", {
|
|
2018
|
+
style: {
|
|
2019
|
+
display: "flex",
|
|
2020
|
+
width: 41,
|
|
2021
|
+
height: 41
|
|
2022
|
+
},
|
|
2023
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
2024
|
+
className: "preview-bar-logo",
|
|
2025
|
+
style: {
|
|
2026
|
+
display: "flex",
|
|
2027
|
+
width: 22,
|
|
2028
|
+
height: 23,
|
|
2029
|
+
margin: "auto",
|
|
2030
|
+
color: "var(--card-fg-color)"
|
|
2031
|
+
},
|
|
2032
|
+
dangerouslySetInnerHTML: { __html: logo }
|
|
2033
|
+
})
|
|
2034
|
+
}) : /* @__PURE__ */ jsx("img", {
|
|
2035
|
+
src: logo,
|
|
2036
|
+
alt: "",
|
|
2037
|
+
width: 25,
|
|
2038
|
+
height: 25,
|
|
2039
|
+
style: { display: "block" }
|
|
2040
|
+
})
|
|
2041
|
+
}) : svg ? /* @__PURE__ */ jsx("span", {
|
|
2042
|
+
"aria-hidden": "true",
|
|
2043
|
+
className: "preview-bar-logo",
|
|
2044
|
+
style: {
|
|
2045
|
+
display: "flex",
|
|
2046
|
+
width: 22,
|
|
2047
|
+
height: 23,
|
|
2048
|
+
color: "var(--card-fg-color)"
|
|
2049
|
+
},
|
|
2050
|
+
dangerouslySetInnerHTML: { __html: logo }
|
|
2051
|
+
}) : /* @__PURE__ */ jsx("img", {
|
|
2052
|
+
src: logo,
|
|
2053
|
+
alt: "",
|
|
2054
|
+
width: 25,
|
|
2055
|
+
height: 25,
|
|
2056
|
+
style: {
|
|
2057
|
+
display: "block",
|
|
2058
|
+
width: 25,
|
|
2059
|
+
height: 25,
|
|
2060
|
+
borderRadius: 3,
|
|
2061
|
+
objectFit: "cover"
|
|
2062
|
+
}
|
|
2063
|
+
});
|
|
2064
|
+
}
|
|
2065
|
+
/** `useEnvAwareSanityWebsiteUrl` for production projects. */
|
|
2066
|
+
const MANAGE_BUTTON_STYLE = { "--card-border-color": "unset" }, ICON_BOX_STYLE = {
|
|
2067
|
+
display: "flex",
|
|
2068
|
+
flex: "none",
|
|
2069
|
+
width: 41,
|
|
2070
|
+
height: 41,
|
|
2071
|
+
borderRadius: "0.25rem"
|
|
2072
|
+
};
|
|
2073
|
+
function WorkspaceMenu({ onOpenChange, onHoverChange }) {
|
|
2074
|
+
let { brand, projectId } = useBarData(), place = useBarPlacement(), [open, setOpen] = useState(!1), manageUrl = projectId ? `https://www.sanity.io/manage/project/${projectId}` : null;
|
|
2075
|
+
return /* @__PURE__ */ jsx("span", {
|
|
2076
|
+
style: {
|
|
2077
|
+
display: "flex",
|
|
2078
|
+
minWidth: 0
|
|
2079
|
+
},
|
|
2080
|
+
onMouseEnter: () => onHoverChange(!0),
|
|
2081
|
+
onMouseLeave: () => onHoverChange(!1),
|
|
2082
|
+
onFocus: () => onHoverChange(!0),
|
|
2083
|
+
onBlur: () => onHoverChange(!1),
|
|
2084
|
+
children: /* @__PURE__ */ jsx(StudioTooltip, {
|
|
2085
|
+
content: "Select workspace",
|
|
2086
|
+
disabled: open,
|
|
2087
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
2088
|
+
style: {
|
|
2089
|
+
display: "flex",
|
|
2090
|
+
minWidth: 0,
|
|
2091
|
+
"--preview-bar-workspace-fg": "var(--card-fg-color)"
|
|
2092
|
+
},
|
|
2093
|
+
children: /* @__PURE__ */ jsx(MenuButton, {
|
|
2094
|
+
id: "workspace-menu",
|
|
2095
|
+
onOpen: () => {
|
|
2096
|
+
setOpen(!0), onOpenChange(!0);
|
|
2097
|
+
},
|
|
2098
|
+
onClose: () => {
|
|
2099
|
+
setOpen(!1), onOpenChange(!1);
|
|
2100
|
+
},
|
|
2101
|
+
popover: {
|
|
2102
|
+
animate: !0,
|
|
2103
|
+
constrainSize: !0,
|
|
2104
|
+
placement: place("top-start"),
|
|
2105
|
+
fallbackPlacements: [place("top"), place("top-end")],
|
|
2106
|
+
portal: !0,
|
|
2107
|
+
tone: "default",
|
|
2108
|
+
zOffset: 3e3
|
|
2109
|
+
},
|
|
2110
|
+
button: /* @__PURE__ */ jsx(Button, {
|
|
2111
|
+
mode: "bleed",
|
|
2112
|
+
padding: 2,
|
|
2113
|
+
width: "fill",
|
|
2114
|
+
children: /* @__PURE__ */ jsxs(Flex, {
|
|
2115
|
+
align: "center",
|
|
2116
|
+
gap: 2,
|
|
2117
|
+
children: [/* @__PURE__ */ jsx(Box, {
|
|
2118
|
+
style: { minWidth: 0 },
|
|
2119
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
2120
|
+
size: 1,
|
|
2121
|
+
weight: "medium",
|
|
2122
|
+
textOverflow: "ellipsis",
|
|
2123
|
+
as: "div",
|
|
2124
|
+
style: { color: "var(--preview-bar-workspace-fg)" },
|
|
2125
|
+
children: brand.title
|
|
2126
|
+
})
|
|
2127
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
2128
|
+
"aria-hidden": "true",
|
|
2129
|
+
style: {
|
|
2130
|
+
display: "block",
|
|
2131
|
+
flex: "none",
|
|
2132
|
+
fontSize: 21,
|
|
2133
|
+
lineHeight: 0,
|
|
2134
|
+
margin: "-0.375rem",
|
|
2135
|
+
color: "var(--preview-bar-workspace-fg)"
|
|
2136
|
+
},
|
|
2137
|
+
children: /* @__PURE__ */ jsx(ChevronDownIcon, { style: { display: "block" } })
|
|
2138
|
+
})]
|
|
2139
|
+
})
|
|
2140
|
+
}),
|
|
2141
|
+
menu: /* @__PURE__ */ jsx(Menu, {
|
|
2142
|
+
padding: 0,
|
|
2143
|
+
style: {
|
|
2144
|
+
maxWidth: 350,
|
|
2145
|
+
minWidth: 250,
|
|
2146
|
+
overflowY: "hidden"
|
|
2147
|
+
},
|
|
2148
|
+
children: /* @__PURE__ */ jsxs(Flex, {
|
|
2149
|
+
direction: "column",
|
|
2150
|
+
paddingX: 4,
|
|
2151
|
+
paddingTop: 4,
|
|
2152
|
+
paddingBottom: 4,
|
|
2153
|
+
children: [/* @__PURE__ */ jsxs(Flex, {
|
|
2154
|
+
align: "center",
|
|
2155
|
+
children: [brand.icon ? /* @__PURE__ */ jsx("span", {
|
|
2156
|
+
"aria-hidden": "true",
|
|
2157
|
+
style: ICON_BOX_STYLE,
|
|
2158
|
+
children: brand.icon
|
|
2159
|
+
}) : brand.logo && /* @__PURE__ */ jsx(Logo, {
|
|
2160
|
+
logo: brand.logo,
|
|
2161
|
+
size: "large"
|
|
2162
|
+
}), /* @__PURE__ */ jsxs(Flex, {
|
|
2163
|
+
direction: "column",
|
|
2164
|
+
gap: 2,
|
|
2165
|
+
marginLeft: 2,
|
|
2166
|
+
children: [brand.project && /* @__PURE__ */ jsx(Text, {
|
|
2167
|
+
size: 0,
|
|
2168
|
+
as: "div",
|
|
2169
|
+
children: brand.project
|
|
2170
|
+
}), /* @__PURE__ */ jsx(Text, {
|
|
2171
|
+
size: 2,
|
|
2172
|
+
weight: "medium",
|
|
2173
|
+
as: "div",
|
|
2174
|
+
children: brand.title
|
|
2175
|
+
})]
|
|
2176
|
+
})]
|
|
2177
|
+
}), manageUrl && /* @__PURE__ */ jsxs(Flex, {
|
|
2178
|
+
justify: "flex-start",
|
|
2179
|
+
gap: 3,
|
|
2180
|
+
paddingTop: 4,
|
|
2181
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
2182
|
+
as: "a",
|
|
2183
|
+
href: manageUrl,
|
|
2184
|
+
target: "_blank",
|
|
2185
|
+
rel: "noopener",
|
|
2186
|
+
mode: "bleed",
|
|
2187
|
+
gap: 2,
|
|
2188
|
+
padding: 2,
|
|
2189
|
+
icon: CogIcon,
|
|
2190
|
+
text: "Manage project",
|
|
2191
|
+
style: MANAGE_BUTTON_STYLE
|
|
2192
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
2193
|
+
as: "a",
|
|
2194
|
+
href: `${manageUrl}/members?invite=true`,
|
|
2195
|
+
target: "_blank",
|
|
2196
|
+
rel: "noopener",
|
|
2197
|
+
mode: "bleed",
|
|
2198
|
+
gap: 2,
|
|
2199
|
+
padding: 2,
|
|
2200
|
+
icon: AddUserIcon,
|
|
2201
|
+
text: "Invite members",
|
|
2202
|
+
style: MANAGE_BUTTON_STYLE
|
|
2203
|
+
})]
|
|
2204
|
+
})]
|
|
2205
|
+
})
|
|
2206
|
+
})
|
|
2207
|
+
})
|
|
2208
|
+
})
|
|
2209
|
+
})
|
|
2210
|
+
});
|
|
2211
|
+
}
|
|
2212
|
+
const theme = buildTheme(), SHARED_BAR_CSS = "\n.preview-bar-search-layer * { pointer-events: auto; }\n.preview-bar-home { display: flex; border-radius: 3px; outline: none; text-decoration: none; }\n.preview-bar-home:focus-visible { box-shadow: 0 0 0 1px var(--card-bg-color), 0 0 0 3px var(--card-focus-ring-color); }\n.preview-bar-layout { display: flex; align-items: center; gap: 4px; }\n.preview-bar-start { display: flex; align-items: center; gap: 4px; flex: none; }\n.preview-bar-center { display: flex; align-items: center; flex: 1; min-width: 0; }\n.preview-bar-end { display: flex; align-items: center; gap: 4px; flex: none; }\n::-webkit-scrollbar { width: 12px; height: 12px; }\n::-webkit-scrollbar-corner { background-color: transparent; }\n::-webkit-scrollbar-thumb { background-clip: content-box; background-color: var(--card-border-color); border: 4px solid transparent; }\n::-webkit-scrollbar-thumb:hover { background-color: var(--card-muted-fg-color); }\n::-webkit-scrollbar-track { background: transparent; }\n.preview-bar-pane-resizer { position: absolute; top: 0; bottom: 0; left: 0; width: 6px; cursor: ew-resize; touch-action: none; outline: none; z-index: 1000; }\n.preview-bar-pane-resizer[data-side=\"left\"] { left: auto; right: 0; }\n.preview-bar-pane-resizer::after { content: ''; position: absolute; top: 0; bottom: 0; left: 0; width: 2px; background: transparent; transition: background-color 0.1s; }\n.preview-bar-pane-resizer[data-side=\"left\"]::after { left: auto; right: 0; }\n.preview-bar-pane-resizer:hover::after, .preview-bar-pane-resizer[data-active]::after, .preview-bar-pane-resizer:focus-visible::after { background: var(--card-focus-ring-color, #556bfc); }\n@keyframes preview-bar-spin { to { transform: rotate(360deg); } }\n.preview-bar-spinner { animation: preview-bar-spin 0.6s linear infinite; }\n";
|
|
2213
|
+
let host = {
|
|
2214
|
+
post: (message) => window.parent.postMessage(message, window.location.origin),
|
|
2215
|
+
subscribe(listener) {
|
|
2216
|
+
function onMessage(event) {
|
|
2217
|
+
event.origin === window.location.origin && event.source === window.parent && isPreviewBarMessage(event.data) && listener(event.data);
|
|
2218
|
+
}
|
|
2219
|
+
return window.addEventListener("message", onMessage), () => window.removeEventListener("message", onMessage);
|
|
2220
|
+
},
|
|
2221
|
+
initialPath() {
|
|
2222
|
+
try {
|
|
2223
|
+
let { pathname, search } = window.parent.location;
|
|
2224
|
+
return `${pathname}${search}`;
|
|
2225
|
+
} catch {
|
|
2226
|
+
return null;
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
};
|
|
2230
|
+
function bindBarHost(h) {
|
|
2231
|
+
host = h;
|
|
2232
|
+
}
|
|
2233
|
+
function getBarHost() {
|
|
2234
|
+
return host;
|
|
2235
|
+
}
|
|
2236
|
+
function postToHost(message) {
|
|
2237
|
+
host.post(message);
|
|
2238
|
+
}
|
|
2239
|
+
function readParentPath() {
|
|
2240
|
+
return host.initialPath();
|
|
2241
|
+
}
|
|
2242
|
+
function useHostPath() {
|
|
2243
|
+
let [path, setPath] = useState(readParentPath);
|
|
2244
|
+
return useEffect(() => {
|
|
2245
|
+
function onMessage(message) {
|
|
2246
|
+
message.type === "sanity-visual-editor:path" && setPath(message.path);
|
|
2247
|
+
}
|
|
2248
|
+
let unsubscribe = host.subscribe(onMessage);
|
|
2249
|
+
return postToHost({ type: "sanity-visual-editor:ready" }), () => unsubscribe();
|
|
2250
|
+
}, []), path;
|
|
2251
|
+
}
|
|
2252
|
+
const LIVE_STATUS_TOAST_ID = "sanity-visual-editor:live-status";
|
|
2253
|
+
function useLiveStatusToasts() {
|
|
2254
|
+
let toast = useToast(), previous = useRef(null);
|
|
2255
|
+
useEffect(() => host.subscribe((message) => {
|
|
2256
|
+
if (message.type !== "sanity-visual-editor:live-status") return;
|
|
2257
|
+
let { status } = message, prior = previous.current;
|
|
2258
|
+
previous.current = status, status === "offline" ? toast.push({
|
|
2259
|
+
id: LIVE_STATUS_TOAST_ID,
|
|
2260
|
+
status: "error",
|
|
2261
|
+
title: "Live updates paused",
|
|
2262
|
+
description: "Can't reach the preview hub. Retrying…",
|
|
2263
|
+
closable: !0,
|
|
2264
|
+
duration: 1e4
|
|
2265
|
+
}) : prior === "offline" && toast.push({
|
|
2266
|
+
id: LIVE_STATUS_TOAST_ID,
|
|
2267
|
+
status: "success",
|
|
2268
|
+
title: "Live updates restored",
|
|
2269
|
+
duration: 2500
|
|
2270
|
+
});
|
|
2271
|
+
}), [toast]);
|
|
2272
|
+
}
|
|
2273
|
+
/**
|
|
2274
|
+
* Asks the host to rerun the storefront's queries and resolves once it reports `refreshed`, or
|
|
2275
|
+
* after `HOST_REFRESH_TIMEOUT_MS`: a page mid-load, a 404 or a page without the host never answers.
|
|
2276
|
+
*/
|
|
2277
|
+
function useHostRefresh() {
|
|
2278
|
+
let waiter = useMemo(() => createRefreshWaiter(() => postToHost({ type: "sanity-visual-editor:refresh" })), []);
|
|
2279
|
+
return useEffect(() => {
|
|
2280
|
+
let unsubscribe = host.subscribe((message) => {
|
|
2281
|
+
message.type === "sanity-visual-editor:refreshed" && waiter.settle();
|
|
2282
|
+
});
|
|
2283
|
+
return () => {
|
|
2284
|
+
unsubscribe(), waiter.settle();
|
|
2285
|
+
};
|
|
2286
|
+
}, [waiter]), waiter.request;
|
|
2287
|
+
}
|
|
2288
|
+
function useHostOverflow() {
|
|
2289
|
+
let open = useRef(/* @__PURE__ */ new Set()), hostOpen = useRef(!1), closeTimer = useRef(void 0);
|
|
2290
|
+
return useEffect(() => () => clearTimeout(closeTimer.current), []), useCallback((key, visible) => {
|
|
2291
|
+
let overlays = open.current;
|
|
2292
|
+
visible ? overlays.add(key) : overlays.delete(key), clearTimeout(closeTimer.current), overlays.size > 0 ? hostOpen.current || (hostOpen.current = !0, postToHost({
|
|
2293
|
+
type: "sanity-visual-editor:menu",
|
|
2294
|
+
open: !0
|
|
2295
|
+
})) : hostOpen.current && (closeTimer.current = setTimeout(() => {
|
|
2296
|
+
hostOpen.current = !1, postToHost({
|
|
2297
|
+
type: "sanity-visual-editor:menu",
|
|
2298
|
+
open: !1
|
|
2299
|
+
});
|
|
2300
|
+
}, 250));
|
|
2301
|
+
}, []);
|
|
2302
|
+
}
|
|
2303
|
+
function overflowWhileHovered(key, setOverflow) {
|
|
2304
|
+
return {
|
|
2305
|
+
onMouseEnter: () => setOverflow(key, !0),
|
|
2306
|
+
onMouseLeave: () => setOverflow(key, !1),
|
|
2307
|
+
onFocus: () => setOverflow(key, !0),
|
|
2308
|
+
onBlur: () => setOverflow(key, !1)
|
|
2309
|
+
};
|
|
2310
|
+
}
|
|
2311
|
+
function usePaneOverlays(open, width, side, setOverflow) {
|
|
2312
|
+
useEffect(() => {
|
|
2313
|
+
if (!open) return;
|
|
2314
|
+
let frame = 0;
|
|
2315
|
+
function check() {
|
|
2316
|
+
frame = 0, setOverflow("pane-overlay", [...document.querySelectorAll("[data-ui=\"Dialog\"], [data-ui=\"Popover\"], [data-ui=\"Tooltip\"]")].some((element) => {
|
|
2317
|
+
if (element.closest("[data-preview-bar-panel]")) return !1;
|
|
2318
|
+
if (element.dataset.ui === "Dialog") return !0;
|
|
2319
|
+
let rect = element.getBoundingClientRect();
|
|
2320
|
+
return rect.width === 0 ? !1 : side === "right" ? rect.left < window.innerWidth - width - 1 : rect.right > width + 1;
|
|
2321
|
+
}));
|
|
2322
|
+
}
|
|
2323
|
+
let observer = new MutationObserver(() => {
|
|
2324
|
+
frame ||= requestAnimationFrame(check);
|
|
2325
|
+
});
|
|
2326
|
+
return observer.observe(document.body, {
|
|
2327
|
+
childList: !0,
|
|
2328
|
+
subtree: !0,
|
|
2329
|
+
attributes: !0,
|
|
2330
|
+
attributeFilter: ["style", "data-placement"]
|
|
2331
|
+
}), () => {
|
|
2332
|
+
observer.disconnect(), cancelAnimationFrame(frame), setOverflow("pane-overlay", !1);
|
|
2333
|
+
};
|
|
2334
|
+
}, [
|
|
2335
|
+
open,
|
|
2336
|
+
width,
|
|
2337
|
+
side,
|
|
2338
|
+
setOverflow
|
|
2339
|
+
]);
|
|
2340
|
+
}
|
|
2341
|
+
function isEditable(target) {
|
|
2342
|
+
return !!target?.closest?.("input, textarea, select, [contenteditable=\"\"], [contenteditable=\"true\"]");
|
|
2343
|
+
}
|
|
2344
|
+
function usePaneShortcut(toggle, enabled) {
|
|
2345
|
+
useEffect(() => {
|
|
2346
|
+
if (!enabled) return;
|
|
2347
|
+
function onKeyDown(event) {
|
|
2348
|
+
event.key.toLowerCase() !== "e" || event.metaKey || event.ctrlKey || event.altKey || event.repeat || event.isComposing || isEditable(event.target) || (event.preventDefault(), toggle());
|
|
2349
|
+
}
|
|
2350
|
+
function onMessage(message) {
|
|
2351
|
+
message.type === "sanity-visual-editor:pane" && toggle();
|
|
2352
|
+
}
|
|
2353
|
+
window.addEventListener("keydown", onKeyDown);
|
|
2354
|
+
let unsubscribe = host.subscribe(onMessage);
|
|
2355
|
+
return () => {
|
|
2356
|
+
window.removeEventListener("keydown", onKeyDown), unsubscribe();
|
|
2357
|
+
};
|
|
2358
|
+
}, [toggle, enabled]);
|
|
2359
|
+
}
|
|
2360
|
+
function useSearchShortcut(open, enabled) {
|
|
2361
|
+
useEffect(() => {
|
|
2362
|
+
if (!enabled) return;
|
|
2363
|
+
function onKeyDown(event) {
|
|
2364
|
+
(event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k" && (event.preventDefault(), open());
|
|
2365
|
+
}
|
|
2366
|
+
function onMessage(message) {
|
|
2367
|
+
message.type === "sanity-visual-editor:search" && open();
|
|
2368
|
+
}
|
|
2369
|
+
window.addEventListener("keydown", onKeyDown);
|
|
2370
|
+
let unsubscribe = host.subscribe(onMessage);
|
|
2371
|
+
return () => {
|
|
2372
|
+
window.removeEventListener("keydown", onKeyDown), unsubscribe();
|
|
2373
|
+
};
|
|
2374
|
+
}, [open, enabled]);
|
|
2375
|
+
}
|
|
2376
|
+
function useElementWidth(element) {
|
|
2377
|
+
let [width, setWidth] = useState(() => window.innerWidth);
|
|
2378
|
+
return useEffect(() => {
|
|
2379
|
+
if (!element) return;
|
|
2380
|
+
let observer = new ResizeObserver(([entry]) => {
|
|
2381
|
+
entry && setWidth(Math.round(entry.borderBoxSize?.[0]?.inlineSize ?? entry.contentRect.width));
|
|
2382
|
+
});
|
|
2383
|
+
return observer.observe(element), () => observer.disconnect();
|
|
2384
|
+
}, [element]), width;
|
|
2385
|
+
}
|
|
2386
|
+
function useToolEditor(enabled, initial) {
|
|
2387
|
+
let [state, setState] = useState(initial ?? { open: !1 });
|
|
2388
|
+
return useEffect(() => {
|
|
2389
|
+
if (!enabled) return;
|
|
2390
|
+
function onMessage(message) {
|
|
2391
|
+
message.type === "sanity-visual-editor:editor-state" && setState({
|
|
2392
|
+
open: message.open,
|
|
2393
|
+
available: message.available,
|
|
2394
|
+
toggle: message.toggle
|
|
2395
|
+
});
|
|
2396
|
+
}
|
|
2397
|
+
let unsubscribe = host.subscribe(onMessage);
|
|
2398
|
+
return () => unsubscribe();
|
|
2399
|
+
}, [enabled]), state;
|
|
2400
|
+
}
|
|
2401
|
+
function sameSelection(a, b) {
|
|
2402
|
+
return a.selected === b.selected && [...a.excluded].sort().join() === [...b.excluded].sort().join();
|
|
2403
|
+
}
|
|
2404
|
+
/** The Visual Editor's inspector (click-to-edit) is on for this tab. */
|
|
2405
|
+
const INSPECTOR_KEY = "sanity-visual-editor:inspector";
|
|
2406
|
+
function readInspector() {
|
|
2407
|
+
try {
|
|
2408
|
+
return window.sessionStorage.getItem(INSPECTOR_KEY) === "1";
|
|
2409
|
+
} catch {
|
|
2410
|
+
return !1;
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
function Brand({ mode, showTitle, onSearch, showSearch = !0, searchDisabled = !1, newDocument, setOverflow }) {
|
|
2414
|
+
let { brand, studioPath, search } = useBarData(), inTool = mode === "tool";
|
|
2415
|
+
return /* @__PURE__ */ jsxs(Flex, {
|
|
2416
|
+
align: "center",
|
|
2417
|
+
gap: 1,
|
|
2418
|
+
flex: "none",
|
|
2419
|
+
children: [
|
|
2420
|
+
/* @__PURE__ */ jsx("a", {
|
|
2421
|
+
href: studioPath,
|
|
2422
|
+
target: inTool ? "_top" : "_blank",
|
|
2423
|
+
rel: inTool ? void 0 : "noopener",
|
|
2424
|
+
"aria-label": inTool ? "Back to Sanity Studio" : "Open Sanity Studio",
|
|
2425
|
+
className: "preview-bar-home",
|
|
2426
|
+
onClick: (event) => {
|
|
2427
|
+
!inTool || event.metaKey || event.ctrlKey || event.shiftKey || event.button !== 0 || (event.preventDefault(), postToHost({ type: "sanity-visual-editor:studio-home" }));
|
|
2428
|
+
},
|
|
2429
|
+
children: /* @__PURE__ */ jsx(Flex, {
|
|
2430
|
+
align: "center",
|
|
2431
|
+
justify: "center",
|
|
2432
|
+
style: {
|
|
2433
|
+
width: 25,
|
|
2434
|
+
height: 25,
|
|
2435
|
+
borderRadius: 3,
|
|
2436
|
+
overflow: "hidden"
|
|
2437
|
+
},
|
|
2438
|
+
children: brand.icon ?? (brand.logo && /* @__PURE__ */ jsx(Logo, { logo: brand.logo }))
|
|
2439
|
+
})
|
|
2440
|
+
}),
|
|
2441
|
+
showTitle && /* @__PURE__ */ jsx(WorkspaceMenu, {
|
|
2442
|
+
onOpenChange: (open) => setOverflow("workspace-menu", open),
|
|
2443
|
+
onHoverChange: (hovered) => setOverflow("workspace-button", hovered)
|
|
2444
|
+
}),
|
|
2445
|
+
newDocument && /* @__PURE__ */ jsx("span", {
|
|
2446
|
+
style: { display: "flex" },
|
|
2447
|
+
...overflowWhileHovered("new-document-button", setOverflow),
|
|
2448
|
+
children: /* @__PURE__ */ jsx(StudioTooltip, {
|
|
2449
|
+
content: "Create new document",
|
|
2450
|
+
disabled: newDocument.open,
|
|
2451
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
2452
|
+
ref: newDocument.ref,
|
|
2453
|
+
mode: "bleed",
|
|
2454
|
+
padding: 2,
|
|
2455
|
+
icon: AddIcon,
|
|
2456
|
+
selected: newDocument.open,
|
|
2457
|
+
"aria-label": "Create new document",
|
|
2458
|
+
"aria-haspopup": "true",
|
|
2459
|
+
"aria-expanded": newDocument.open,
|
|
2460
|
+
onClick: newDocument.onToggle
|
|
2461
|
+
})
|
|
2462
|
+
})
|
|
2463
|
+
}),
|
|
2464
|
+
search && mode === "site" && showSearch && /* @__PURE__ */ jsx("span", {
|
|
2465
|
+
style: { display: "flex" },
|
|
2466
|
+
...overflowWhileHovered("search-button", setOverflow),
|
|
2467
|
+
children: /* @__PURE__ */ jsx(StudioTooltip, {
|
|
2468
|
+
content: "Search",
|
|
2469
|
+
hotkeys: ["Mod", "K"],
|
|
2470
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
2471
|
+
mode: "bleed",
|
|
2472
|
+
padding: 2,
|
|
2473
|
+
icon: SearchIcon,
|
|
2474
|
+
"aria-label": "Search",
|
|
2475
|
+
disabled: searchDisabled,
|
|
2476
|
+
onClick: onSearch
|
|
2477
|
+
})
|
|
2478
|
+
})
|
|
2479
|
+
})
|
|
2480
|
+
]
|
|
2481
|
+
});
|
|
2482
|
+
}
|
|
2483
|
+
const STUDIO_SCHEME_KEY = "sanityStudio:ui:colorScheme";
|
|
2484
|
+
function readStudioScheme() {
|
|
2485
|
+
try {
|
|
2486
|
+
let value = window.localStorage.getItem(STUDIO_SCHEME_KEY);
|
|
2487
|
+
return value === "light" || value === "dark" ? value : "system";
|
|
2488
|
+
} catch {
|
|
2489
|
+
return "system";
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
function useStudioScheme() {
|
|
2493
|
+
let prefersDark = usePrefersDark(), [setting, setSetting] = useState(readStudioScheme);
|
|
2494
|
+
return useEffect(() => {
|
|
2495
|
+
function onStorage(event) {
|
|
2496
|
+
(event.key === STUDIO_SCHEME_KEY || event.key === null) && setSetting(readStudioScheme());
|
|
2497
|
+
}
|
|
2498
|
+
return window.addEventListener("storage", onStorage), () => window.removeEventListener("storage", onStorage);
|
|
2499
|
+
}, []), setting === "system" ? prefersDark ? "dark" : "light" : setting;
|
|
2500
|
+
}
|
|
2501
|
+
function BarProviders({ data, position, css, children }) {
|
|
2502
|
+
let scheme = useStudioScheme();
|
|
2503
|
+
return /* @__PURE__ */ jsx(ThemeProvider, {
|
|
2504
|
+
theme,
|
|
2505
|
+
scheme,
|
|
2506
|
+
children: /* @__PURE__ */ jsx(ToastProvider, {
|
|
2507
|
+
zOffset: 4e3,
|
|
2508
|
+
children: /* @__PURE__ */ jsx(BarDataContext.Provider, {
|
|
2509
|
+
value: data,
|
|
2510
|
+
children: /* @__PURE__ */ jsxs(BarPositionContext.Provider, {
|
|
2511
|
+
value: position,
|
|
2512
|
+
children: [/* @__PURE__ */ jsx("style", { children: css }), children]
|
|
2513
|
+
})
|
|
2514
|
+
})
|
|
2515
|
+
})
|
|
2516
|
+
});
|
|
2517
|
+
}
|
|
2518
|
+
const SITE_BAR_CSS = `${SHARED_BAR_CSS}
|
|
2519
|
+
.site-preview-bar.preview-bar-wide .preview-bar-layout {
|
|
2520
|
+
display: grid;
|
|
2521
|
+
grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
|
|
2522
|
+
}
|
|
2523
|
+
.site-preview-bar.preview-bar-wide .preview-bar-center { justify-self: center; }
|
|
2524
|
+
.site-preview-bar.preview-bar-wide .preview-bar-end { justify-self: end; }
|
|
2525
|
+
`;
|
|
2526
|
+
function MoreMenu$1({ setOverflow }) {
|
|
2527
|
+
let { basePath } = useBarData(), place = useBarPlacement(), [exiting, setExiting] = useState(!1), [open, setOpen] = useState(!1);
|
|
2528
|
+
async function exitPreview() {
|
|
2529
|
+
setExiting(!0);
|
|
2530
|
+
try {
|
|
2531
|
+
let response = await fetch(`${basePath}/exit`, { method: "POST" });
|
|
2532
|
+
if (!response.ok) throw Error(`HTTP ${response.status}`);
|
|
2533
|
+
postToHost({ type: "sanity-visual-editor:refresh" });
|
|
2534
|
+
} catch (err) {
|
|
2535
|
+
console.error("Preview bar: could not exit preview", err), setExiting(!1);
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
return /* @__PURE__ */ jsx("span", {
|
|
2539
|
+
style: { display: "flex" },
|
|
2540
|
+
...overflowWhileHovered("more-button", setOverflow),
|
|
2541
|
+
children: /* @__PURE__ */ jsx(StudioTooltip, {
|
|
2542
|
+
content: "Show more",
|
|
2543
|
+
disabled: open,
|
|
2544
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
2545
|
+
style: { display: "flex" },
|
|
2546
|
+
children: /* @__PURE__ */ jsx(MenuButton, {
|
|
2547
|
+
id: "preview-bar-more",
|
|
2548
|
+
onOpen: () => {
|
|
2549
|
+
setOpen(!0), setOverflow("more", !0);
|
|
2550
|
+
},
|
|
2551
|
+
onClose: () => {
|
|
2552
|
+
setOpen(!1), setOverflow("more", !1);
|
|
2553
|
+
},
|
|
2554
|
+
popover: {
|
|
2555
|
+
animate: !0,
|
|
2556
|
+
placement: place("top-end"),
|
|
2557
|
+
fallbackPlacements: [place("top-start")],
|
|
2558
|
+
portal: !0,
|
|
2559
|
+
tone: "default",
|
|
2560
|
+
zOffset: 3e3
|
|
2561
|
+
},
|
|
2562
|
+
button: /* @__PURE__ */ jsx(Button, {
|
|
2563
|
+
mode: "bleed",
|
|
2564
|
+
padding: 2,
|
|
2565
|
+
icon: EllipsisHorizontalIcon,
|
|
2566
|
+
"aria-label": "More preview options"
|
|
2567
|
+
}),
|
|
2568
|
+
menu: /* @__PURE__ */ jsxs(Menu, {
|
|
2569
|
+
padding: 1,
|
|
2570
|
+
children: [/* @__PURE__ */ jsx(StudioMenuItem, {
|
|
2571
|
+
icon: EyeClosedIcon,
|
|
2572
|
+
text: "Hide bar",
|
|
2573
|
+
onClick: () => postToHost({ type: "sanity-visual-editor:hide" })
|
|
2574
|
+
}), /* @__PURE__ */ jsx(StudioMenuItem, {
|
|
2575
|
+
icon: LeaveIcon,
|
|
2576
|
+
text: "Exit preview",
|
|
2577
|
+
disabled: exiting,
|
|
2578
|
+
onClick: () => void exitPreview()
|
|
2579
|
+
})]
|
|
2580
|
+
})
|
|
2581
|
+
})
|
|
2582
|
+
})
|
|
2583
|
+
})
|
|
2584
|
+
});
|
|
2585
|
+
}
|
|
2586
|
+
function SitePreviewBar({ data, options }) {
|
|
2587
|
+
let path = useHostPath(), position = useContext(BarPositionContext);
|
|
2588
|
+
useLiveStatusToasts();
|
|
2589
|
+
let visualEditorTool = options.visualEditor ? typeof options.visualEditor == "object" && options.visualEditor.tool || "visual-editor" : null, [barElement, setBarElement] = useState(null), barWidth = useElementWidth(barElement), showLabels = barWidth >= 600, [perspective, setPerspective] = useState(() => parsePerspective(data.perspective)), refreshHost = useHostRefresh(), switchPerspective = usePerspectiveSwitch({
|
|
2590
|
+
basePath: data.basePath,
|
|
2591
|
+
releases: data.releases,
|
|
2592
|
+
perspective,
|
|
2593
|
+
onChange: setPerspective,
|
|
2594
|
+
onRefresh: refreshHost
|
|
2595
|
+
}), setOverflow = useHostOverflow(), [searchOpen, setSearchOpen] = useState(!1), openSearch = useCallback(() => {
|
|
2596
|
+
setOverflow("search", !0), setSearchOpen(!0);
|
|
2597
|
+
}, [setOverflow]), searchOpenRef = useRef(searchOpen);
|
|
2598
|
+
searchOpenRef.current = searchOpen;
|
|
2599
|
+
let openSearchShortcut = useCallback(() => {
|
|
2600
|
+
searchOpenRef.current || openSearch();
|
|
2601
|
+
}, [openSearch]), editorParams = studioPerspectiveParams(perspective, data.releases), { session, refresh: refreshSession } = useStudioSession(data.projectId), [signingIn, setSigningIn] = useState(!1), cancelSignIn = useRef(null);
|
|
2602
|
+
useEffect(() => () => cancelSignIn.current?.(), []);
|
|
2603
|
+
let signedIn = session.status === "signed-in", [studioReady, setStudioReady] = useState(!1), [studioSharing, setStudioSharing] = useState(null), studioSearch = signedIn && studioReady && !!data.search;
|
|
2604
|
+
useSearchShortcut(openSearchShortcut, studioSearch);
|
|
2605
|
+
let searchTypes = (data.search ?? []).flatMap(({ kind }) => kind === "route" ? [] : [kind]), [pageDocument, setPageDocument] = useState(null);
|
|
2606
|
+
useEffect(() => {
|
|
2607
|
+
if (!options.documentPane || !signedIn || !studioReady || !data.pageDocuments || path === null) return;
|
|
2608
|
+
let cancelled = !1;
|
|
2609
|
+
return fetch(`${data.basePath}/document?${new URLSearchParams({ path })}`).then((response) => response.ok ? response.json() : { document: null }).then(({ document }) => {
|
|
2610
|
+
cancelled || setPageDocument(document);
|
|
2611
|
+
}).catch(() => {
|
|
2612
|
+
cancelled || setPageDocument(null);
|
|
2613
|
+
}), () => {
|
|
2614
|
+
cancelled = !0;
|
|
2615
|
+
};
|
|
2616
|
+
}, [
|
|
2617
|
+
options.documentPane,
|
|
2618
|
+
signedIn,
|
|
2619
|
+
studioReady,
|
|
2620
|
+
data.pageDocuments,
|
|
2621
|
+
data.basePath,
|
|
2622
|
+
path
|
|
2623
|
+
]);
|
|
2624
|
+
let panelEnabled = !!(options.documentPane && options.studioConfig), paneOptions = typeof options.documentPane == "object" ? options.documentPane : {}, pane = useDocumentPaneState({
|
|
2625
|
+
enabled: panelEnabled && signedIn,
|
|
2626
|
+
pageDocument,
|
|
2627
|
+
setOverflow
|
|
2628
|
+
}), paneSide = paneOptions.side === "right" ? "right" : "left", barBesidePanel = pane.open && pane.beside;
|
|
2629
|
+
useEffect(() => {
|
|
2630
|
+
postToHost({
|
|
2631
|
+
type: "sanity-visual-editor:panel",
|
|
2632
|
+
open: pane.open,
|
|
2633
|
+
width: pane.open ? pane.width : 0,
|
|
2634
|
+
side: paneSide
|
|
2635
|
+
});
|
|
2636
|
+
}, [
|
|
2637
|
+
pane.open,
|
|
2638
|
+
pane.width,
|
|
2639
|
+
paneSide
|
|
2640
|
+
]), usePaneOverlays(pane.open, pane.width, paneSide, setOverflow), usePaneShortcut(pane.toggle, panelEnabled && signedIn && (pane.open || pane.canOpen));
|
|
2641
|
+
function openPanel() {
|
|
2642
|
+
setOverflow("edit-button", !1), pane.openPane();
|
|
2643
|
+
}
|
|
2644
|
+
let editAction = signedIn ? visualEditorTool ? "tool-link" : panelEnabled && pane.canOpen && !pane.open ? "site-pane" : null : null;
|
|
2645
|
+
function closeStudioSearch() {
|
|
2646
|
+
setSearchOpen(!1), window.setTimeout(() => setOverflow("search", !1), 450);
|
|
2647
|
+
}
|
|
2648
|
+
async function openStudioSearchResult(item) {
|
|
2649
|
+
let params = new URLSearchParams({
|
|
2650
|
+
type: item._type,
|
|
2651
|
+
id: item._id
|
|
2652
|
+
}), response = await fetch(`${data.basePath}/resolve?${params}`).catch(() => null), { href } = response?.ok ? await response.json() : {};
|
|
2653
|
+
if (closeStudioSearch(), href) {
|
|
2654
|
+
postToHost({
|
|
2655
|
+
type: "sanity-visual-editor:navigate",
|
|
2656
|
+
href
|
|
2657
|
+
});
|
|
2658
|
+
return;
|
|
2659
|
+
}
|
|
2660
|
+
let id = item._id.replace(/^drafts\./, "").replace(/^versions\.[^.]+\./, "");
|
|
2661
|
+
window.open(`${data.studioPath}/intent/edit/id=${encodeURIComponent(id)};type=${encodeURIComponent(item._type)}`, "_blank", "noopener");
|
|
2662
|
+
}
|
|
2663
|
+
function signIn() {
|
|
2664
|
+
if (!data.projectId) return;
|
|
2665
|
+
let projectId = data.projectId;
|
|
2666
|
+
setSigningIn(!0), cancelSignIn.current?.(), cancelSignIn.current = openStudioSignIn(data.studioPath, () => fetchCurrentUser(projectId).then(Boolean), () => {
|
|
2667
|
+
cancelSignIn.current = null, setSigningIn(!1), refreshSession();
|
|
2668
|
+
});
|
|
2669
|
+
}
|
|
2670
|
+
let studioPerspective = editorParams.toString();
|
|
2671
|
+
editorParams.set("preview", path ?? "/");
|
|
2672
|
+
let wideLayout = barWidth >= 1024 && !pane.open;
|
|
2673
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2674
|
+
style: {
|
|
2675
|
+
display: "flex",
|
|
2676
|
+
flexDirection: "column",
|
|
2677
|
+
alignItems: "flex-end",
|
|
2678
|
+
justifyContent: position === "top" ? "flex-start" : "flex-end",
|
|
2679
|
+
width: "100%",
|
|
2680
|
+
height: "100%"
|
|
2681
|
+
},
|
|
2682
|
+
children: [/* @__PURE__ */ jsx(Card, {
|
|
2683
|
+
tone: perspectiveTone(perspective, data.releases),
|
|
2684
|
+
as: "nav",
|
|
2685
|
+
"aria-label": "Sanity preview",
|
|
2686
|
+
padding: 3,
|
|
2687
|
+
borderTop: position === "bottom",
|
|
2688
|
+
borderBottom: position === "top",
|
|
2689
|
+
ref: setBarElement,
|
|
2690
|
+
className: wideLayout ? "preview-bar-card site-preview-bar preview-bar-wide" : "preview-bar-card site-preview-bar",
|
|
2691
|
+
style: barBesidePanel ? {
|
|
2692
|
+
width: `calc(100% - ${pane.width}px)`,
|
|
2693
|
+
alignSelf: paneSide === "right" ? "flex-start" : "flex-end"
|
|
2694
|
+
} : { width: "100%" },
|
|
2695
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
2696
|
+
className: "preview-bar-layout",
|
|
2697
|
+
children: [
|
|
2698
|
+
/* @__PURE__ */ jsx("div", {
|
|
2699
|
+
className: "preview-bar-start",
|
|
2700
|
+
children: /* @__PURE__ */ jsx(Brand, {
|
|
2701
|
+
mode: "site",
|
|
2702
|
+
showTitle: showLabels,
|
|
2703
|
+
onSearch: openSearch,
|
|
2704
|
+
showSearch: signedIn,
|
|
2705
|
+
searchDisabled: !studioSearch,
|
|
2706
|
+
newDocument: null,
|
|
2707
|
+
setOverflow
|
|
2708
|
+
})
|
|
2709
|
+
}),
|
|
2710
|
+
/* @__PURE__ */ jsx("div", {
|
|
2711
|
+
className: "preview-bar-center",
|
|
2712
|
+
children: /* @__PURE__ */ jsx(PerspectiveMenu, {
|
|
2713
|
+
releases: data.releases,
|
|
2714
|
+
releasesError: data.releasesError,
|
|
2715
|
+
perspective,
|
|
2716
|
+
onOpenChange: (open) => setOverflow("perspective", open),
|
|
2717
|
+
onSelect: switchPerspective
|
|
2718
|
+
})
|
|
2719
|
+
}),
|
|
2720
|
+
/* @__PURE__ */ jsxs("div", {
|
|
2721
|
+
className: "preview-bar-end",
|
|
2722
|
+
children: [
|
|
2723
|
+
data.links && /* @__PURE__ */ jsx(ShareMenu, {
|
|
2724
|
+
sharing: data.sharing,
|
|
2725
|
+
path: path ?? "/",
|
|
2726
|
+
perspectiveKey: serializePerspective(perspective),
|
|
2727
|
+
studio: signedIn ? studioSharing : null,
|
|
2728
|
+
toolPath: `${data.studioPath.replace(/\/$/, "")}/${visualEditorTool ?? "visual-editor"}`,
|
|
2729
|
+
setOverflow
|
|
2730
|
+
}),
|
|
2731
|
+
/* @__PURE__ */ jsx(MoreMenu$1, { setOverflow }),
|
|
2732
|
+
editAction && /* @__PURE__ */ jsx("span", {
|
|
2733
|
+
style: { display: "flex" },
|
|
2734
|
+
...overflowWhileHovered("edit-button", setOverflow),
|
|
2735
|
+
children: /* @__PURE__ */ jsx(StudioTooltip, {
|
|
2736
|
+
content: "Edit this page",
|
|
2737
|
+
hotkeys: editAction === "site-pane" ? ["E"] : void 0,
|
|
2738
|
+
children: editAction === "tool-link" ? /* @__PURE__ */ jsx(Button, {
|
|
2739
|
+
as: "a",
|
|
2740
|
+
mode: "default",
|
|
2741
|
+
padding: 2,
|
|
2742
|
+
text: "Edit",
|
|
2743
|
+
"aria-label": "Edit this page",
|
|
2744
|
+
href: `${data.studioPath}/${visualEditorTool}?${editorParams}`,
|
|
2745
|
+
target: "_top"
|
|
2746
|
+
}) : /* @__PURE__ */ jsx(Button, {
|
|
2747
|
+
mode: "default",
|
|
2748
|
+
padding: 2,
|
|
2749
|
+
text: "Edit",
|
|
2750
|
+
"aria-label": "Edit this page",
|
|
2751
|
+
onClick: openPanel
|
|
2752
|
+
})
|
|
2753
|
+
})
|
|
2754
|
+
}),
|
|
2755
|
+
session.status === "signed-out" ? /* @__PURE__ */ jsx(Button, {
|
|
2756
|
+
mode: "default",
|
|
2757
|
+
padding: 2,
|
|
2758
|
+
text: signingIn ? "Signing in…" : "Sign in",
|
|
2759
|
+
disabled: signingIn,
|
|
2760
|
+
onClick: signIn
|
|
2761
|
+
}) : panelEnabled || visualEditorTool ? null : /* @__PURE__ */ jsx(Button, {
|
|
2762
|
+
as: "a",
|
|
2763
|
+
mode: "default",
|
|
2764
|
+
padding: 2,
|
|
2765
|
+
text: "Visual Editor",
|
|
2766
|
+
"aria-label": "Visual Editor",
|
|
2767
|
+
href: `${data.studioPath}/presentation?${editorParams}`,
|
|
2768
|
+
target: "_blank",
|
|
2769
|
+
rel: "noopener"
|
|
2770
|
+
})
|
|
2771
|
+
]
|
|
2772
|
+
})
|
|
2773
|
+
]
|
|
2774
|
+
})
|
|
2775
|
+
}), signedIn && options.studioConfig && /* @__PURE__ */ jsx("div", {
|
|
2776
|
+
style: {
|
|
2777
|
+
position: "absolute",
|
|
2778
|
+
width: 0,
|
|
2779
|
+
height: 0
|
|
2780
|
+
},
|
|
2781
|
+
children: /* @__PURE__ */ jsx(StudioLayer, {
|
|
2782
|
+
load: options.studioConfig,
|
|
2783
|
+
studioPath: data.studioPath,
|
|
2784
|
+
perspective: studioPerspective,
|
|
2785
|
+
onPerspectiveChange: switchPerspective,
|
|
2786
|
+
onSharingClient: setStudioSharing,
|
|
2787
|
+
allFieldsGroup: paneOptions.allFieldsGroup !== !1,
|
|
2788
|
+
panel: panelEnabled ? {
|
|
2789
|
+
stack: pane.open ? pane.stack : [],
|
|
2790
|
+
onChange: pane.change,
|
|
2791
|
+
width: pane.width,
|
|
2792
|
+
fullHeight: pane.beside,
|
|
2793
|
+
barPosition: position,
|
|
2794
|
+
side: paneSide,
|
|
2795
|
+
resize: pane.resize
|
|
2796
|
+
} : void 0,
|
|
2797
|
+
onReady: () => setStudioReady(!0),
|
|
2798
|
+
search: {
|
|
2799
|
+
open: studioSearch && searchOpen,
|
|
2800
|
+
types: searchTypes,
|
|
2801
|
+
onClose: closeStudioSearch,
|
|
2802
|
+
onSelect: openStudioSearchResult
|
|
2803
|
+
}
|
|
2804
|
+
})
|
|
2805
|
+
})]
|
|
2806
|
+
});
|
|
2807
|
+
}
|
|
2808
|
+
function SitePreviewBarApp({ data, options, position }) {
|
|
2809
|
+
return /* @__PURE__ */ jsx(BarProviders, {
|
|
2810
|
+
data,
|
|
2811
|
+
position,
|
|
2812
|
+
css: SITE_BAR_CSS,
|
|
2813
|
+
children: /* @__PURE__ */ jsx(SitePreviewBar, {
|
|
2814
|
+
data,
|
|
2815
|
+
options
|
|
2816
|
+
})
|
|
2817
|
+
});
|
|
2818
|
+
}
|
|
2819
|
+
/**
|
|
2820
|
+
* "Activate inspector" (Shopify's theme editor toolbar), in the Visual Editor only: turns
|
|
2821
|
+
* click-to-edit on the framed page on and off. A toggle with the Studio's tooltip and the ⌘⇧I
|
|
2822
|
+
* hint; the bar owns its state.
|
|
2823
|
+
*/
|
|
2824
|
+
/**
|
|
2825
|
+
* A selection with a pointer, drawn like `@sanity/icons`: a 25px grid, 1.2 strokes with round
|
|
2826
|
+
* joins, open corner brackets on the half-pixel grid (as in `ExpandIcon`), no dashes.
|
|
2827
|
+
*/
|
|
2828
|
+
const InspectIcon = forwardRef(function InspectIcon(props, ref) {
|
|
2829
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
2830
|
+
"data-sanity-icon": "inspect",
|
|
2831
|
+
width: "1em",
|
|
2832
|
+
height: "1em",
|
|
2833
|
+
viewBox: "0 0 25 25",
|
|
2834
|
+
fill: "none",
|
|
2835
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2836
|
+
...props,
|
|
2837
|
+
ref,
|
|
2838
|
+
children: [/* @__PURE__ */ jsx("path", {
|
|
2839
|
+
d: "M5.5 9.5V5.5H9.5M15.5 5.5H19.5V9.5M9.5 19.5H5.5V15.5",
|
|
2840
|
+
stroke: "currentColor",
|
|
2841
|
+
strokeWidth: 1.2,
|
|
2842
|
+
strokeLinejoin: "round"
|
|
2843
|
+
}), /* @__PURE__ */ jsx("path", {
|
|
2844
|
+
d: "M12.5 12.5L19.5 15.5L16 16L15.5 19.5L12.5 12.5Z",
|
|
2845
|
+
stroke: "currentColor",
|
|
2846
|
+
strokeWidth: 1.2,
|
|
2847
|
+
strokeLinejoin: "round"
|
|
2848
|
+
})]
|
|
2849
|
+
});
|
|
2850
|
+
});
|
|
2851
|
+
function InspectorButton({ active, onToggle, onHoverChange }) {
|
|
2852
|
+
let label = active ? "Deactivate inspector" : "Activate inspector";
|
|
2853
|
+
return /* @__PURE__ */ jsx("span", {
|
|
2854
|
+
style: { display: "flex" },
|
|
2855
|
+
onMouseEnter: () => onHoverChange(!0),
|
|
2856
|
+
onMouseLeave: () => onHoverChange(!1),
|
|
2857
|
+
onFocus: () => onHoverChange(!0),
|
|
2858
|
+
onBlur: () => onHoverChange(!1),
|
|
2859
|
+
children: /* @__PURE__ */ jsx(StudioTooltip, {
|
|
2860
|
+
content: label,
|
|
2861
|
+
hotkeys: [
|
|
2862
|
+
"Mod",
|
|
2863
|
+
"Shift",
|
|
2864
|
+
"I"
|
|
2865
|
+
],
|
|
2866
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
2867
|
+
mode: "bleed",
|
|
2868
|
+
padding: 2,
|
|
2869
|
+
icon: InspectIcon,
|
|
2870
|
+
selected: active,
|
|
2871
|
+
"aria-label": label,
|
|
2872
|
+
"aria-pressed": active,
|
|
2873
|
+
onClick: onToggle
|
|
2874
|
+
})
|
|
2875
|
+
})
|
|
2876
|
+
});
|
|
2877
|
+
}
|
|
2878
|
+
/**
|
|
2879
|
+
* The Visual Editor's page picker, beside the perspective switcher in the middle of the bar, like
|
|
2880
|
+
* the page menu in Shopify's theme editor, and drawn like the switcher: a bordered pill with the
|
|
2881
|
+
* current page, then a round chevron button. The page shows its document's schema type icon and
|
|
2882
|
+
* live preview title (as the Studio previews it), or its path; either opens the bar's search
|
|
2883
|
+
* to go to another page.
|
|
2884
|
+
*/
|
|
2885
|
+
/** The switcher's label row: a size-1 icon, then the medium size-1 title. */
|
|
2886
|
+
function PageRow({ icon, title }) {
|
|
2887
|
+
return /* @__PURE__ */ jsxs(Flex, {
|
|
2888
|
+
align: "center",
|
|
2889
|
+
gap: 2,
|
|
2890
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
2891
|
+
size: 1,
|
|
2892
|
+
children: icon
|
|
2893
|
+
}), /* @__PURE__ */ jsx(Text, {
|
|
2894
|
+
size: 1,
|
|
2895
|
+
weight: "medium",
|
|
2896
|
+
textOverflow: "ellipsis",
|
|
2897
|
+
children: title
|
|
2898
|
+
})]
|
|
2899
|
+
});
|
|
2900
|
+
}
|
|
2901
|
+
/** The label row's placeholder while the page's document or its title loads. */
|
|
2902
|
+
function PageRowSkeleton() {
|
|
2903
|
+
return /* @__PURE__ */ jsxs(Flex, {
|
|
2904
|
+
align: "center",
|
|
2905
|
+
gap: 2,
|
|
2906
|
+
children: [/* @__PURE__ */ jsx(TextSkeleton, {
|
|
2907
|
+
size: 1,
|
|
2908
|
+
animated: !0,
|
|
2909
|
+
radius: 1,
|
|
2910
|
+
style: { width: 13 }
|
|
2911
|
+
}), /* @__PURE__ */ jsx(TextSkeleton, {
|
|
2912
|
+
size: 1,
|
|
2913
|
+
animated: !0,
|
|
2914
|
+
radius: 1,
|
|
2915
|
+
style: { width: 88 }
|
|
2916
|
+
})]
|
|
2917
|
+
});
|
|
2918
|
+
}
|
|
2919
|
+
/** A schema type's icon (a component, an element or an emoji), as the Studio draws it. */
|
|
2920
|
+
function TypeIcon({ icon }) {
|
|
2921
|
+
return isValidElement(icon) ? icon : typeof icon == "function" || typeof icon == "object" && icon ? createElement(icon) : /* @__PURE__ */ jsx(DocumentIcon, {});
|
|
2922
|
+
}
|
|
2923
|
+
/**
|
|
2924
|
+
* The page's document as the Studio previews it (inside a running Studio only): its schema type's
|
|
2925
|
+
* own icon and its live preview title, drawn in the switcher's row rather than the Studio's
|
|
2926
|
+
* `Preview` layout, whose padding would make the pill taller than the switcher.
|
|
2927
|
+
*/
|
|
2928
|
+
function NativePagePreview({ sanity, document, fallback }) {
|
|
2929
|
+
let { useSchema, useDocumentPreviewStore } = sanity, schemaType = useSchema().get(document.type), previewStore = useDocumentPreviewStore(), [title, setTitle] = useState(void 0);
|
|
2930
|
+
return useEffect(() => {
|
|
2931
|
+
if (setTitle(void 0), !schemaType) return;
|
|
2932
|
+
let subscription = previewStore.observeForPreview({
|
|
2933
|
+
_id: document.id,
|
|
2934
|
+
_type: document.type
|
|
2935
|
+
}, schemaType).subscribe(({ snapshot }) => {
|
|
2936
|
+
setTitle(typeof snapshot?.title == "string" ? snapshot.title : null);
|
|
2937
|
+
});
|
|
2938
|
+
return () => subscription.unsubscribe();
|
|
2939
|
+
}, [
|
|
2940
|
+
previewStore,
|
|
2941
|
+
schemaType,
|
|
2942
|
+
document.id,
|
|
2943
|
+
document.type
|
|
2944
|
+
]), schemaType && title === void 0 ? /* @__PURE__ */ jsx(PageRowSkeleton, {}) : /* @__PURE__ */ jsx(PageRow, {
|
|
2945
|
+
icon: /* @__PURE__ */ jsx(TypeIcon, { icon: schemaType?.icon }),
|
|
2946
|
+
title: title ?? schemaType?.title ?? fallback
|
|
2947
|
+
});
|
|
2948
|
+
}
|
|
2949
|
+
/** The page picker's fallback label: home or the path. */
|
|
2950
|
+
function pageFallbackTitle(path) {
|
|
2951
|
+
return path === null || path === "/" || path.startsWith("/?") ? "Home page" : path ?? "/";
|
|
2952
|
+
}
|
|
2953
|
+
function PagePicker({ preview, path, loading = !1, onOpen, onHoverChange }) {
|
|
2954
|
+
let home = path === null || path === "/" || path.startsWith("/?");
|
|
2955
|
+
return /* @__PURE__ */ jsx("span", {
|
|
2956
|
+
style: {
|
|
2957
|
+
display: "flex",
|
|
2958
|
+
minWidth: 0
|
|
2959
|
+
},
|
|
2960
|
+
onMouseEnter: () => onHoverChange(!0),
|
|
2961
|
+
onMouseLeave: () => onHoverChange(!1),
|
|
2962
|
+
onFocus: () => onHoverChange(!0),
|
|
2963
|
+
onBlur: () => onHoverChange(!1),
|
|
2964
|
+
children: /* @__PURE__ */ jsx(StudioTooltip, {
|
|
2965
|
+
content: "Go to page",
|
|
2966
|
+
hotkeys: ["Mod", "K"],
|
|
2967
|
+
children: /* @__PURE__ */ jsxs(Card, {
|
|
2968
|
+
border: !0,
|
|
2969
|
+
radius: "full",
|
|
2970
|
+
tone: "inherit",
|
|
2971
|
+
flex: "none",
|
|
2972
|
+
style: {
|
|
2973
|
+
display: "flex",
|
|
2974
|
+
alignItems: "center",
|
|
2975
|
+
gap: 2,
|
|
2976
|
+
padding: 2,
|
|
2977
|
+
margin: "-3px 0",
|
|
2978
|
+
maxWidth: 260,
|
|
2979
|
+
minWidth: 0
|
|
2980
|
+
},
|
|
2981
|
+
children: [/* @__PURE__ */ jsx(Box, {
|
|
2982
|
+
padding: 2,
|
|
2983
|
+
role: "button",
|
|
2984
|
+
tabIndex: -1,
|
|
2985
|
+
onClick: onOpen,
|
|
2986
|
+
style: {
|
|
2987
|
+
userSelect: "none",
|
|
2988
|
+
overflow: "hidden",
|
|
2989
|
+
minWidth: 0,
|
|
2990
|
+
cursor: "pointer"
|
|
2991
|
+
},
|
|
2992
|
+
children: preview ?? (loading ? /* @__PURE__ */ jsx(PageRowSkeleton, {}) : /* @__PURE__ */ jsx(PageRow, {
|
|
2993
|
+
icon: jsx(home ? HomeIcon : DocumentIcon, {}),
|
|
2994
|
+
title: pageFallbackTitle(path)
|
|
2995
|
+
}))
|
|
2996
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
2997
|
+
mode: "bleed",
|
|
2998
|
+
padding: 2,
|
|
2999
|
+
radius: "full",
|
|
3000
|
+
iconRight: ChevronDownIcon,
|
|
3001
|
+
"aria-label": "Go to another page",
|
|
3002
|
+
onClick: onOpen
|
|
3003
|
+
})]
|
|
3004
|
+
})
|
|
3005
|
+
})
|
|
3006
|
+
});
|
|
3007
|
+
}
|
|
3008
|
+
/**
|
|
3009
|
+
* The Visual Editor's viewport menu: desktop width, a 768px tablet or a 375px phone. The button
|
|
3010
|
+
* shows the current size's device icon; the tool animates the site's frame between sizes.
|
|
3011
|
+
*/
|
|
3012
|
+
const VIEWPORTS = [
|
|
3013
|
+
{
|
|
3014
|
+
mode: "desktop",
|
|
3015
|
+
title: "Desktop",
|
|
3016
|
+
icon: DesktopIcon
|
|
3017
|
+
},
|
|
3018
|
+
{
|
|
3019
|
+
mode: "tablet",
|
|
3020
|
+
title: "Tablet",
|
|
3021
|
+
icon: TabletDeviceIcon
|
|
3022
|
+
},
|
|
3023
|
+
{
|
|
3024
|
+
mode: "mobile",
|
|
3025
|
+
title: "Mobile",
|
|
3026
|
+
icon: MobileDeviceIcon
|
|
3027
|
+
}
|
|
3028
|
+
];
|
|
3029
|
+
function ViewportButton({ onChange, onOpenChange, onHoverChange }) {
|
|
3030
|
+
let place = useBarPlacement(), [mode, setMode] = useState("desktop"), [open, setOpen] = useState(!1), current = VIEWPORTS.find((viewport) => viewport.mode === mode) ?? VIEWPORTS[0];
|
|
3031
|
+
return /* @__PURE__ */ jsx("span", {
|
|
3032
|
+
style: { display: "flex" },
|
|
3033
|
+
onMouseEnter: () => onHoverChange(!0),
|
|
3034
|
+
onMouseLeave: () => onHoverChange(!1),
|
|
3035
|
+
onFocus: () => onHoverChange(!0),
|
|
3036
|
+
onBlur: () => onHoverChange(!1),
|
|
3037
|
+
children: /* @__PURE__ */ jsx(StudioTooltip, {
|
|
3038
|
+
content: "Viewport",
|
|
3039
|
+
disabled: open,
|
|
3040
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
3041
|
+
style: { display: "flex" },
|
|
3042
|
+
children: /* @__PURE__ */ jsx(MenuButton, {
|
|
3043
|
+
id: "preview-bar-viewport",
|
|
3044
|
+
onOpen: () => {
|
|
3045
|
+
setOpen(!0), onOpenChange(!0);
|
|
3046
|
+
},
|
|
3047
|
+
onClose: () => {
|
|
3048
|
+
setOpen(!1), onOpenChange(!1);
|
|
3049
|
+
},
|
|
3050
|
+
popover: {
|
|
3051
|
+
animate: !0,
|
|
3052
|
+
placement: place("top-end"),
|
|
3053
|
+
fallbackPlacements: [place("top-start")],
|
|
3054
|
+
portal: !0,
|
|
3055
|
+
tone: "default",
|
|
3056
|
+
zOffset: 3e3
|
|
3057
|
+
},
|
|
3058
|
+
button: /* @__PURE__ */ jsx(Button, {
|
|
3059
|
+
mode: "bleed",
|
|
3060
|
+
padding: 2,
|
|
3061
|
+
icon: current.icon,
|
|
3062
|
+
selected: open,
|
|
3063
|
+
"aria-label": `Viewport: ${current.title}`
|
|
3064
|
+
}),
|
|
3065
|
+
menu: /* @__PURE__ */ jsx(Menu, {
|
|
3066
|
+
padding: 1,
|
|
3067
|
+
children: VIEWPORTS.map((viewport) => /* @__PURE__ */ jsx(StudioMenuItem, {
|
|
3068
|
+
icon: viewport.icon,
|
|
3069
|
+
text: viewport.title,
|
|
3070
|
+
selected: viewport.mode === mode,
|
|
3071
|
+
onClick: () => {
|
|
3072
|
+
setMode(viewport.mode), onChange(viewport.mode);
|
|
3073
|
+
}
|
|
3074
|
+
}, viewport.mode))
|
|
3075
|
+
})
|
|
3076
|
+
})
|
|
3077
|
+
})
|
|
3078
|
+
})
|
|
3079
|
+
});
|
|
3080
|
+
}
|
|
3081
|
+
const TOOL_BAR_CSS = `${SHARED_BAR_CSS}
|
|
3082
|
+
.visual-editor-bar .preview-bar-layout { gap: 6px; }
|
|
3083
|
+
.visual-editor-bar { border-bottom: 1px solid var(--card-border-color); container-type: inline-size; }
|
|
3084
|
+
.visual-editor-bar .preview-bar-center { justify-content: center; width: 100%; }
|
|
3085
|
+
@container (min-width: 760px) {
|
|
3086
|
+
.visual-editor-bar .preview-bar-layout {
|
|
3087
|
+
display: grid;
|
|
3088
|
+
grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
|
|
3089
|
+
}
|
|
3090
|
+
.visual-editor-bar .preview-bar-center { justify-self: center; }
|
|
3091
|
+
.visual-editor-bar .preview-bar-end { justify-self: end; }
|
|
3092
|
+
}
|
|
3093
|
+
`;
|
|
3094
|
+
function VisualEditorBar({ data, options, native, editorState, initialPageDocument }) {
|
|
3095
|
+
let path = useHostPath(), position = useContext(BarPositionContext);
|
|
3096
|
+
useLiveStatusToasts();
|
|
3097
|
+
let toolEditor = useToolEditor(!0, editorState), [toolPage, setToolPage] = useState(initialPageDocument);
|
|
3098
|
+
useEffect(() => getBarHost().subscribe((message) => {
|
|
3099
|
+
message.type === "sanity-visual-editor:page-document" && setToolPage(message.document);
|
|
3100
|
+
}), []);
|
|
3101
|
+
let toolEditorOpen = toolEditor.open, [barElement, setBarElement] = useState(null);
|
|
3102
|
+
useElementWidth(barElement);
|
|
3103
|
+
let [perspective, setPerspective] = useState(() => parsePerspective(data.perspective)), refreshHost = useHostRefresh(), switchPerspective = usePerspectiveSwitch({
|
|
3104
|
+
basePath: data.basePath,
|
|
3105
|
+
releases: data.releases,
|
|
3106
|
+
perspective,
|
|
3107
|
+
onChange: setPerspective,
|
|
3108
|
+
onRefresh: refreshHost
|
|
3109
|
+
}), setOverflow = useHostOverflow(), [searchOpen, setSearchOpen] = useState(!1), openSearch = useCallback(() => {
|
|
3110
|
+
setOverflow("search", !0), setSearchOpen(!0);
|
|
3111
|
+
}, [setOverflow]), searchOpenRef = useRef(searchOpen);
|
|
3112
|
+
searchOpenRef.current = searchOpen, useSearchShortcut(useCallback(() => {
|
|
3113
|
+
searchOpenRef.current || openSearch();
|
|
3114
|
+
}, [openSearch]), !!data.search);
|
|
3115
|
+
let { session, refresh: refreshSession } = useStudioSession(data.projectId, { enabled: native === void 0 }), [signingIn, setSigningIn] = useState(!1), cancelSignIn = useRef(null);
|
|
3116
|
+
useEffect(() => () => cancelSignIn.current?.(), []);
|
|
3117
|
+
let signedIn = native !== void 0 || session.status === "signed-in", [studioReady, setStudioReady] = useState(native !== void 0), [studioSharing, setStudioSharing] = useState(null), studioSearch = signedIn && studioReady && !!data.search, searchTypes = (data.search ?? []).flatMap(({ kind }) => kind === "route" ? [] : [kind]), [pageDocument, setPageDocument] = useState(null);
|
|
3118
|
+
useEffect(() => {
|
|
3119
|
+
if (!signedIn || !studioReady || !data.pageDocuments || path === null) return;
|
|
3120
|
+
let cancelled = !1;
|
|
3121
|
+
return fetch(`${data.basePath}/document?${new URLSearchParams({ path })}`).then((response) => response.ok ? response.json() : { document: null }).then(({ document }) => {
|
|
3122
|
+
cancelled || setPageDocument(document);
|
|
3123
|
+
}).catch(() => {
|
|
3124
|
+
cancelled || setPageDocument(null);
|
|
3125
|
+
}), () => {
|
|
3126
|
+
cancelled = !0;
|
|
3127
|
+
};
|
|
3128
|
+
}, [
|
|
3129
|
+
signedIn,
|
|
3130
|
+
studioReady,
|
|
3131
|
+
data.pageDocuments,
|
|
3132
|
+
data.basePath,
|
|
3133
|
+
path
|
|
3134
|
+
]);
|
|
3135
|
+
let perspectiveRef = useRef({
|
|
3136
|
+
perspective,
|
|
3137
|
+
releases: data.releases,
|
|
3138
|
+
switchPerspective
|
|
3139
|
+
});
|
|
3140
|
+
perspectiveRef.current = {
|
|
3141
|
+
perspective,
|
|
3142
|
+
releases: data.releases,
|
|
3143
|
+
switchPerspective
|
|
3144
|
+
}, useEffect(() => {
|
|
3145
|
+
postToHost({
|
|
3146
|
+
type: "sanity-visual-editor:perspective",
|
|
3147
|
+
selection: selectionOf(perspective, data.releases)
|
|
3148
|
+
});
|
|
3149
|
+
}, [perspective, data.releases]), useEffect(() => {
|
|
3150
|
+
function onMessage(message) {
|
|
3151
|
+
if (message.type !== "sanity-visual-editor:set-perspective") return;
|
|
3152
|
+
let current = perspectiveRef.current;
|
|
3153
|
+
sameSelection(message.selection, selectionOf(current.perspective, current.releases)) || current.switchPerspective(message.selection);
|
|
3154
|
+
}
|
|
3155
|
+
return getBarHost().subscribe(onMessage);
|
|
3156
|
+
}, []);
|
|
3157
|
+
let [inspector, setInspector] = useState(() => readInspector()), toggleInspector = useCallback(() => {
|
|
3158
|
+
setOverflow("inspector", !1), setInspector((active) => !active);
|
|
3159
|
+
}, [setOverflow]);
|
|
3160
|
+
useEffect(() => {
|
|
3161
|
+
store("sessionStorage", INSPECTOR_KEY, inspector ? "1" : null), postToHost({
|
|
3162
|
+
type: "sanity-visual-editor:inspector",
|
|
3163
|
+
active: inspector
|
|
3164
|
+
});
|
|
3165
|
+
}, [inspector]), useEffect(() => {
|
|
3166
|
+
function onKeyDown(event) {
|
|
3167
|
+
isInspectorShortcut(event) && (event.preventDefault(), toggleInspector());
|
|
3168
|
+
}
|
|
3169
|
+
window.addEventListener("keydown", onKeyDown);
|
|
3170
|
+
let unsubscribe = getBarHost().subscribe((message) => {
|
|
3171
|
+
message.type === "sanity-visual-editor:toggle-inspector" && toggleInspector();
|
|
3172
|
+
});
|
|
3173
|
+
return () => {
|
|
3174
|
+
window.removeEventListener("keydown", onKeyDown), unsubscribe();
|
|
3175
|
+
};
|
|
3176
|
+
}, [toggleInspector]);
|
|
3177
|
+
let [newDocumentOpen, setNewDocumentOpen] = useState(!1), [newDocumentAnchor, setNewDocumentAnchor] = useState(null);
|
|
3178
|
+
function toggleNewDocument() {
|
|
3179
|
+
setOverflow("new-document-button", !1), setNewDocumentOpen((open) => !open);
|
|
3180
|
+
}
|
|
3181
|
+
useEffect(() => {
|
|
3182
|
+
setOverflow("new-document", newDocumentOpen);
|
|
3183
|
+
}, [newDocumentOpen, setOverflow]);
|
|
3184
|
+
function createDocument(option) {
|
|
3185
|
+
setNewDocumentOpen(!1), postToHost({
|
|
3186
|
+
type: "sanity-visual-editor:open-document",
|
|
3187
|
+
document: {
|
|
3188
|
+
id: crypto.randomUUID(),
|
|
3189
|
+
type: option.schemaType,
|
|
3190
|
+
template: option.templateId,
|
|
3191
|
+
templateParameters: option.parameters
|
|
3192
|
+
}
|
|
3193
|
+
});
|
|
3194
|
+
}
|
|
3195
|
+
function openPanel() {
|
|
3196
|
+
setOverflow("edit-button", !1), editPressed ? postToHost({ type: "sanity-visual-editor:close-editor" }) : toolEditor.available === void 0 ? pageDocument && postToHost({
|
|
3197
|
+
type: "sanity-visual-editor:open-document",
|
|
3198
|
+
document: {
|
|
3199
|
+
id: publishedId(pageDocument._id),
|
|
3200
|
+
type: pageDocument._type
|
|
3201
|
+
}
|
|
3202
|
+
}) : postToHost({ type: "sanity-visual-editor:open-editor" });
|
|
3203
|
+
}
|
|
3204
|
+
let editToggle = toolEditor.toggle === !0, editPressed = editToggle && toolEditorOpen, editAction = (toolEditor.available ?? !!pageDocument) && (!toolEditorOpen || editToggle) ? "tool-pane" : null;
|
|
3205
|
+
function closeStudioSearch() {
|
|
3206
|
+
setSearchOpen(!1), window.setTimeout(() => setOverflow("search", !1), 450);
|
|
3207
|
+
}
|
|
3208
|
+
async function openStudioSearchResult(item) {
|
|
3209
|
+
let params = new URLSearchParams({
|
|
3210
|
+
type: item._type,
|
|
3211
|
+
id: item._id
|
|
3212
|
+
}), response = await fetch(`${data.basePath}/resolve?${params}`).catch(() => null), { href } = response?.ok ? await response.json() : {};
|
|
3213
|
+
closeStudioSearch(), postToHost(href ? {
|
|
3214
|
+
type: "sanity-visual-editor:navigate",
|
|
3215
|
+
href
|
|
3216
|
+
} : {
|
|
3217
|
+
type: "sanity-visual-editor:open-document",
|
|
3218
|
+
document: {
|
|
3219
|
+
id: publishedId(item._id),
|
|
3220
|
+
type: item._type
|
|
3221
|
+
}
|
|
3222
|
+
});
|
|
3223
|
+
}
|
|
3224
|
+
function signIn() {
|
|
3225
|
+
if (!data.projectId) return;
|
|
3226
|
+
let projectId = data.projectId;
|
|
3227
|
+
setSigningIn(!0), cancelSignIn.current?.(), cancelSignIn.current = openStudioSignIn(data.studioPath, () => fetchCurrentUser(projectId).then(Boolean), () => {
|
|
3228
|
+
cancelSignIn.current = null, setSigningIn(!1), refreshSession();
|
|
3229
|
+
});
|
|
3230
|
+
}
|
|
3231
|
+
let studioPerspective = studioPerspectiveParams(perspective, data.releases).toString();
|
|
3232
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
3233
|
+
style: {
|
|
3234
|
+
display: "flex",
|
|
3235
|
+
flexDirection: "column",
|
|
3236
|
+
alignItems: "flex-end",
|
|
3237
|
+
justifyContent: position === "top" ? "flex-start" : "flex-end",
|
|
3238
|
+
width: "100%",
|
|
3239
|
+
height: "100%"
|
|
3240
|
+
},
|
|
3241
|
+
children: [/* @__PURE__ */ jsx(Card, {
|
|
3242
|
+
tone: perspectiveTone(perspective, data.releases),
|
|
3243
|
+
as: "nav",
|
|
3244
|
+
"aria-label": "Visual Editor",
|
|
3245
|
+
padding: 3,
|
|
3246
|
+
borderBottom: !1,
|
|
3247
|
+
ref: setBarElement,
|
|
3248
|
+
className: "preview-bar-card visual-editor-bar",
|
|
3249
|
+
style: { width: "100%" },
|
|
3250
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
3251
|
+
className: "preview-bar-layout",
|
|
3252
|
+
children: [
|
|
3253
|
+
/* @__PURE__ */ jsxs("div", {
|
|
3254
|
+
className: "preview-bar-start",
|
|
3255
|
+
children: [
|
|
3256
|
+
/* @__PURE__ */ jsx("span", {
|
|
3257
|
+
style: { display: "flex" },
|
|
3258
|
+
...overflowWhileHovered("exit-tool", setOverflow),
|
|
3259
|
+
children: /* @__PURE__ */ jsx(StudioTooltip, {
|
|
3260
|
+
content: "Exit Visual Editor",
|
|
3261
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
3262
|
+
mode: "bleed",
|
|
3263
|
+
padding: 2,
|
|
3264
|
+
icon: LeaveIcon,
|
|
3265
|
+
"aria-label": "Exit Visual Editor",
|
|
3266
|
+
onClick: () => postToHost({ type: "sanity-visual-editor:studio-home" })
|
|
3267
|
+
})
|
|
3268
|
+
})
|
|
3269
|
+
}),
|
|
3270
|
+
signedIn && studioReady && /* @__PURE__ */ jsx("span", {
|
|
3271
|
+
style: { display: "flex" },
|
|
3272
|
+
...overflowWhileHovered("new-document-button", setOverflow),
|
|
3273
|
+
children: /* @__PURE__ */ jsx(StudioTooltip, {
|
|
3274
|
+
content: "Create new document",
|
|
3275
|
+
disabled: newDocumentOpen,
|
|
3276
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
3277
|
+
ref: setNewDocumentAnchor,
|
|
3278
|
+
mode: "bleed",
|
|
3279
|
+
padding: 2,
|
|
3280
|
+
icon: AddIcon,
|
|
3281
|
+
selected: newDocumentOpen,
|
|
3282
|
+
"aria-label": "Create new document",
|
|
3283
|
+
"aria-haspopup": "true",
|
|
3284
|
+
"aria-expanded": newDocumentOpen,
|
|
3285
|
+
onClick: toggleNewDocument
|
|
3286
|
+
})
|
|
3287
|
+
})
|
|
3288
|
+
}),
|
|
3289
|
+
/* @__PURE__ */ jsx(PerspectiveMenu, {
|
|
3290
|
+
releases: data.releases,
|
|
3291
|
+
releasesError: data.releasesError,
|
|
3292
|
+
perspective,
|
|
3293
|
+
onOpenChange: (open) => setOverflow("perspective", open),
|
|
3294
|
+
onSelect: switchPerspective
|
|
3295
|
+
})
|
|
3296
|
+
]
|
|
3297
|
+
}),
|
|
3298
|
+
/* @__PURE__ */ jsx("div", {
|
|
3299
|
+
className: "preview-bar-center",
|
|
3300
|
+
children: data.search && /* @__PURE__ */ jsx(PagePicker, {
|
|
3301
|
+
preview: toolPage ? /* @__PURE__ */ jsx(NativePagePreview, {
|
|
3302
|
+
sanity: native,
|
|
3303
|
+
document: toolPage,
|
|
3304
|
+
fallback: pageFallbackTitle(path)
|
|
3305
|
+
}) : null,
|
|
3306
|
+
path,
|
|
3307
|
+
loading: toolPage === void 0,
|
|
3308
|
+
onOpen: openSearch,
|
|
3309
|
+
onHoverChange: (hovered) => setOverflow("page-picker", hovered)
|
|
3310
|
+
})
|
|
3311
|
+
}),
|
|
3312
|
+
/* @__PURE__ */ jsxs("div", {
|
|
3313
|
+
className: "preview-bar-end",
|
|
3314
|
+
children: [
|
|
3315
|
+
/* @__PURE__ */ jsx(InspectorButton, {
|
|
3316
|
+
active: inspector,
|
|
3317
|
+
onToggle: toggleInspector,
|
|
3318
|
+
onHoverChange: (hovered) => setOverflow("inspector", hovered)
|
|
3319
|
+
}),
|
|
3320
|
+
/* @__PURE__ */ jsx(ViewportButton, {
|
|
3321
|
+
onChange: (mode) => postToHost({
|
|
3322
|
+
type: "sanity-visual-editor:viewport",
|
|
3323
|
+
mode
|
|
3324
|
+
}),
|
|
3325
|
+
onOpenChange: (open) => setOverflow("viewport-menu", open),
|
|
3326
|
+
onHoverChange: (hovered) => setOverflow("viewport", hovered)
|
|
3327
|
+
}),
|
|
3328
|
+
data.links && /* @__PURE__ */ jsx(ShareMenu, {
|
|
3329
|
+
sharing: data.sharing,
|
|
3330
|
+
path: path ?? "/",
|
|
3331
|
+
perspectiveKey: serializePerspective(perspective),
|
|
3332
|
+
studio: signedIn ? studioSharing : null,
|
|
3333
|
+
toolPath: window.location.pathname,
|
|
3334
|
+
setOverflow
|
|
3335
|
+
}),
|
|
3336
|
+
/* @__PURE__ */ jsx(MoreMenu, {
|
|
3337
|
+
path,
|
|
3338
|
+
menu: options.menu,
|
|
3339
|
+
setOverflow
|
|
3340
|
+
}),
|
|
3341
|
+
editAction && /* @__PURE__ */ jsx("span", {
|
|
3342
|
+
style: {
|
|
3343
|
+
display: "flex",
|
|
3344
|
+
marginLeft: 4
|
|
3345
|
+
},
|
|
3346
|
+
...overflowWhileHovered("edit-button", setOverflow),
|
|
3347
|
+
children: /* @__PURE__ */ jsx(StudioTooltip, {
|
|
3348
|
+
content: editPressed ? "Back to the page" : "Edit this page",
|
|
3349
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
3350
|
+
mode: editPressed ? "ghost" : "default",
|
|
3351
|
+
selected: editPressed,
|
|
3352
|
+
padding: 2,
|
|
3353
|
+
text: "Edit",
|
|
3354
|
+
"aria-label": "Edit this page",
|
|
3355
|
+
"aria-pressed": editToggle ? editPressed : void 0,
|
|
3356
|
+
onClick: openPanel
|
|
3357
|
+
})
|
|
3358
|
+
})
|
|
3359
|
+
}),
|
|
3360
|
+
!signedIn && session.status === "signed-out" && /* @__PURE__ */ jsx(Button, {
|
|
3361
|
+
mode: "default",
|
|
3362
|
+
padding: 2,
|
|
3363
|
+
text: signingIn ? "Signing in…" : "Sign in",
|
|
3364
|
+
disabled: signingIn,
|
|
3365
|
+
onClick: signIn
|
|
3366
|
+
})
|
|
3367
|
+
]
|
|
3368
|
+
})
|
|
3369
|
+
]
|
|
3370
|
+
})
|
|
3371
|
+
}), signedIn && (options.studioConfig || native !== void 0) && /* @__PURE__ */ jsx("div", {
|
|
3372
|
+
style: {
|
|
3373
|
+
position: "absolute",
|
|
3374
|
+
width: 0,
|
|
3375
|
+
height: 0
|
|
3376
|
+
},
|
|
3377
|
+
children: /* @__PURE__ */ jsx(StudioLayer, {
|
|
3378
|
+
load: options.studioConfig,
|
|
3379
|
+
native,
|
|
3380
|
+
studioPath: data.studioPath,
|
|
3381
|
+
perspective: studioPerspective,
|
|
3382
|
+
onPerspectiveChange: switchPerspective,
|
|
3383
|
+
onSharingClient: setStudioSharing,
|
|
3384
|
+
newDocument: {
|
|
3385
|
+
open: newDocumentOpen,
|
|
3386
|
+
anchor: newDocumentAnchor,
|
|
3387
|
+
onClose: () => setNewDocumentOpen(!1),
|
|
3388
|
+
onSelect: createDocument
|
|
3389
|
+
},
|
|
3390
|
+
allFieldsGroup: !0,
|
|
3391
|
+
onReady: () => setStudioReady(!0),
|
|
3392
|
+
search: {
|
|
3393
|
+
open: studioSearch && searchOpen,
|
|
3394
|
+
types: searchTypes,
|
|
3395
|
+
onClose: closeStudioSearch,
|
|
3396
|
+
onSelect: openStudioSearchResult
|
|
3397
|
+
}
|
|
3398
|
+
})
|
|
3399
|
+
})]
|
|
3400
|
+
});
|
|
3401
|
+
}
|
|
3402
|
+
/** The Studio document pane's "…" menu, beside Edit. */
|
|
3403
|
+
function MoreMenu({ path, menu, setOverflow }) {
|
|
3404
|
+
let [open, setOpen] = useState(!1);
|
|
3405
|
+
return /* @__PURE__ */ jsx("span", {
|
|
3406
|
+
style: { display: "flex" },
|
|
3407
|
+
...overflowWhileHovered("more-button", setOverflow),
|
|
3408
|
+
children: /* @__PURE__ */ jsx(StudioTooltip, {
|
|
3409
|
+
content: "Show more",
|
|
3410
|
+
disabled: open,
|
|
3411
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
3412
|
+
style: { display: "flex" },
|
|
3413
|
+
children: /* @__PURE__ */ jsx(MenuButton, {
|
|
3414
|
+
id: "visual-editor-more",
|
|
3415
|
+
onOpen: () => {
|
|
3416
|
+
setOpen(!0), setOverflow("more", !0);
|
|
3417
|
+
},
|
|
3418
|
+
onClose: () => {
|
|
3419
|
+
setOpen(!1), setOverflow("more", !1);
|
|
3420
|
+
},
|
|
3421
|
+
popover: {
|
|
3422
|
+
animate: !0,
|
|
3423
|
+
placement: "bottom-end",
|
|
3424
|
+
fallbackPlacements: ["bottom-start"],
|
|
3425
|
+
portal: !0,
|
|
3426
|
+
tone: "default",
|
|
3427
|
+
zOffset: 3e3
|
|
3428
|
+
},
|
|
3429
|
+
button: /* @__PURE__ */ jsx(Button, {
|
|
3430
|
+
mode: "bleed",
|
|
3431
|
+
padding: 2,
|
|
3432
|
+
icon: EllipsisHorizontalIcon,
|
|
3433
|
+
"aria-label": "Show more"
|
|
3434
|
+
}),
|
|
3435
|
+
menu: /* @__PURE__ */ jsxs(Menu, {
|
|
3436
|
+
padding: 1,
|
|
3437
|
+
children: [
|
|
3438
|
+
/* @__PURE__ */ jsx(StudioMenuItem, {
|
|
3439
|
+
icon: EyeOpenIcon,
|
|
3440
|
+
text: "View",
|
|
3441
|
+
href: path ?? "/"
|
|
3442
|
+
}),
|
|
3443
|
+
(menu?.code || menu?.editPreferences) && /* @__PURE__ */ jsx(MenuDivider, {}),
|
|
3444
|
+
menu?.code && /* @__PURE__ */ jsx(StudioMenuItem, {
|
|
3445
|
+
icon: CodeIcon,
|
|
3446
|
+
text: "Edit code",
|
|
3447
|
+
href: menu.code
|
|
3448
|
+
}),
|
|
3449
|
+
menu?.editPreferences && /* @__PURE__ */ jsx(StudioMenuItem, {
|
|
3450
|
+
icon: CogIcon,
|
|
3451
|
+
text: "Edit preferences",
|
|
3452
|
+
onClick: menu.editPreferences
|
|
3453
|
+
})
|
|
3454
|
+
]
|
|
3455
|
+
})
|
|
3456
|
+
})
|
|
3457
|
+
})
|
|
3458
|
+
})
|
|
3459
|
+
});
|
|
3460
|
+
}
|
|
3461
|
+
function VisualEditorBarApp({ data, options, native, editorState, pageDocument }) {
|
|
3462
|
+
return /* @__PURE__ */ jsx(BarProviders, {
|
|
3463
|
+
data,
|
|
3464
|
+
position: "top",
|
|
3465
|
+
css: TOOL_BAR_CSS,
|
|
3466
|
+
children: /* @__PURE__ */ jsx(VisualEditorBar, {
|
|
3467
|
+
data,
|
|
3468
|
+
options,
|
|
3469
|
+
native,
|
|
3470
|
+
editorState,
|
|
3471
|
+
initialPageDocument: pageDocument
|
|
3472
|
+
})
|
|
3473
|
+
});
|
|
3474
|
+
}
|
|
3475
|
+
/**
|
|
3476
|
+
* The bar rendered natively inside a running Studio, for the Visual Editor tool
|
|
3477
|
+
* (`sanity-plugin-visual-editor/studio`): no frame, the Studio's own context (pass its `sanity` module), and
|
|
3478
|
+
* the tool as the host. Always at the top, in tool mode.
|
|
3479
|
+
*/
|
|
3480
|
+
function PreviewBarView({ data, host: toolHost, sanity, options = {}, editorState, pageDocument }) {
|
|
3481
|
+
return bindBarHost(toolHost), /* @__PURE__ */ jsx(VisualEditorBarApp, {
|
|
3482
|
+
data,
|
|
3483
|
+
options,
|
|
3484
|
+
native: sanity,
|
|
3485
|
+
editorState,
|
|
3486
|
+
pageDocument
|
|
3487
|
+
});
|
|
3488
|
+
}
|
|
3489
|
+
/** Renders the bar into `element` and returns its unmount function. */
|
|
3490
|
+
function mountPreviewBar(element, data, options = {}) {
|
|
3491
|
+
injectStudioDocumentCss(element.ownerDocument, { transparent: !0 });
|
|
3492
|
+
let stopReordering = keepStyledComponentsLast(element.ownerDocument), root = createRoot(element), position = readPreviewBarPosition(window.location.search);
|
|
3493
|
+
return root.render(/* @__PURE__ */ jsx(StrictMode, { children: /* @__PURE__ */ jsx(SitePreviewBarApp, {
|
|
3494
|
+
data,
|
|
3495
|
+
options,
|
|
3496
|
+
position
|
|
3497
|
+
}) })), () => {
|
|
3498
|
+
root.unmount(), stopReordering();
|
|
3499
|
+
};
|
|
3500
|
+
}
|
|
3501
|
+
export { PaneResizer as a, panelLayout as c, injectStudioDocumentCss as d, SitePreviewBar as i, readNumber as l, mountPreviewBar as n, DocumentPanel as o, VisualEditorBar as r, applyEdit as s, PreviewBarView as t, store as u };
|
|
3502
|
+
|
|
3503
|
+
//# sourceMappingURL=PreviewBar-D_rw0bhP.js.map
|