sanity
Version:
Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches
537 lines (535 loc) • 25.4 kB
JavaScript
import { c } from "react-compiler-runtime";
import { useContext, useEffect, useState, useLayoutEffect, lazy, Suspense } from "react";
import { PresentationSharedStateContext, PresentationContext, PresentationDocumentContext, PresentationNavigateContext, PresentationParamsContext } from "sanity/_singletons";
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
import { defineLocaleResourceBundle, useDocumentStore, useDocumentPreviewStore, usePerspective, useTranslation, defineDocumentFieldAction, useWorkspace, pathToString, isRecord, getPublishedId, definePlugin, getVersionFromId, isDocumentSchemaType } from "sanity";
import { ComposeIcon, ErrorOutlineIcon, WarningOutlineIcon, InfoOutlineIcon, ChevronRightIcon, DesktopIcon, MasterDetailIcon } from "@sanity/icons";
import { apiVersion } from "@sanity/preview-url-secret/constants";
import { Card, Flex, Box, Spinner, Text, Stack, rem } from "@sanity/ui";
import { getTheme_v2 } from "@sanity/ui/theme";
import { styled, css } from "styled-components";
import { useIntentLink, useRouter, encodeJsonParams, route } from "sanity/router";
import { of, isObservable, map } from "rxjs";
import { useEffectEvent } from "use-effect-event";
import { uuid } from "@sanity/uuid";
const useSharedState = (key, value) => {
const $ = c(5), context = useContext(PresentationSharedStateContext);
if (!context)
throw new Error("Preview Snapshots context is missing");
const {
setValue
} = context;
let t0, t1;
$[0] !== key || $[1] !== setValue || $[2] !== value ? (t0 = () => {
setValue(key, value);
}, t1 = [key, value, setValue], $[0] = key, $[1] = setValue, $[2] = value, $[3] = t0, $[4] = t1) : (t0 = $[3], t1 = $[4]), useEffect(t0, t1);
}, DEFAULT_TOOL_ICON = ComposeIcon, DEFAULT_TOOL_NAME = "presentation", DEFAULT_TOOL_TITLE = "Presentation", EDIT_INTENT_MODE = "presentation", MAX_TIME_TO_OVERLAYS_CONNECTION = 3e3, API_VERSION = apiVersion, MIN_LOADER_QUERY_LISTEN_HEARTBEAT_INTERVAL = 1e3, LOADER_QUERY_GC_INTERVAL = 3e4, POPUP_CHECK_INTERVAL = 1e3, presentationLocaleNamespace = "presentation", presentationUsEnglishLocaleBundle = defineLocaleResourceBundle({
locale: "en-US",
namespace: presentationLocaleNamespace,
resources: () => import("./resources7.mjs")
}), INITIAL_STATE = {
locations: []
};
function useDocumentLocations(props) {
const $ = c(23), {
id,
resolvers,
type,
version
} = props, documentStore = useDocumentStore(), documentPreviewStore = useDocumentPreviewStore(), {
perspectiveStack
} = usePerspective(), [locationsState, setLocationsState] = useState(INITIAL_STATE), resolver = resolvers && (typeof resolvers == "function" ? resolvers : resolvers[type.name]), [locationsStatus, setLocationsStatus] = useState(resolver ? "resolving" : "empty");
let t0;
bb0: {
if (!resolver) {
t0 = void 0;
break bb0;
}
if (typeof resolver == "function") {
let t13;
if ($[0] !== documentStore || $[1] !== id || $[2] !== perspectiveStack || $[3] !== resolver || $[4] !== type.name || $[5] !== version) {
const params = {
id,
type: type.name,
version,
perspectiveStack
}, _result = resolver(params, {
documentStore
});
t13 = isObservable(_result) ? _result : of(_result), $[0] = documentStore, $[1] = id, $[2] = perspectiveStack, $[3] = resolver, $[4] = type.name, $[5] = version, $[6] = t13;
} else
t13 = $[6];
t0 = t13;
break bb0;
}
if ("select" in resolver && "resolve" in resolver) {
let t13;
if ($[7] !== documentPreviewStore || $[8] !== id || $[9] !== perspectiveStack || $[10] !== resolver || $[11] !== type) {
const doc = {
_type: "reference",
_ref: id
}, _type = {
...type,
preview: {
select: resolver.select
}
}, options = {
perspective: perspectiveStack
};
let t22;
$[13] !== resolver ? (t22 = (preview) => resolver.resolve(preview.snapshot || null), $[13] = resolver, $[14] = t22) : t22 = $[14], t13 = documentPreviewStore.observeForPreview(doc, _type, options).pipe(map(t22)), $[7] = documentPreviewStore, $[8] = id, $[9] = perspectiveStack, $[10] = resolver, $[11] = type, $[12] = t13;
} else
t13 = $[12];
t0 = t13;
break bb0;
}
let t12;
$[15] !== resolver ? (t12 = of(resolver), $[15] = resolver, $[16] = t12) : t12 = $[16], t0 = t12;
}
const result = t0;
let t1, t2;
$[17] !== result ? (t1 = () => {
const sub = result?.subscribe((state) => {
setLocationsState(state || INITIAL_STATE), setLocationsStatus(state ? "resolved" : "empty");
});
return () => sub?.unsubscribe();
}, t2 = [result], $[17] = result, $[18] = t1, $[19] = t2) : (t1 = $[18], t2 = $[19]), useEffect(t1, t2);
let t3;
return $[20] !== locationsState || $[21] !== locationsStatus ? (t3 = {
state: locationsState,
status: locationsStatus
}, $[20] = locationsState, $[21] = locationsStatus, $[22] = t3) : t3 = $[22], t3;
}
function usePresentationTool(t0) {
const throwOnMissingContext = t0 === void 0 ? !0 : t0, presentation = useContext(PresentationContext);
if (throwOnMissingContext && !presentation)
throw new Error("Presentation context is missing");
return presentation;
}
function useCurrentPresentationToolName() {
return usePresentationTool(!1)?.name ?? void 0;
}
const TONE_ICONS = {
positive: InfoOutlineIcon,
caution: WarningOutlineIcon,
critical: ErrorOutlineIcon
};
function LocationsBanner(props) {
const $ = c(39), {
documentId,
options,
resolvers,
schemaType,
showPresentationTitle,
version
} = props;
let t0;
$[0] !== documentId || $[1] !== resolvers || $[2] !== schemaType || $[3] !== version ? (t0 = {
id: documentId,
version,
resolvers,
type: schemaType
}, $[0] = documentId, $[1] = resolvers, $[2] = schemaType, $[3] = version, $[4] = t0) : t0 = $[4];
const {
state,
status
} = useDocumentLocations(t0), isResolving = status === "resolving", {
locations,
message,
tone
} = state, locationsCount = locations?.length || 0, {
t
} = useTranslation(presentationLocaleNamespace), presentation = useContext(PresentationContext), presentationName = presentation?.name, [expanded, setExpanded] = useState(!1);
let t1;
$[5] !== locationsCount ? (t1 = () => {
locationsCount && setExpanded(_temp$2);
}, $[5] = locationsCount, $[6] = t1) : t1 = $[6];
const toggle = t1;
let t2;
$[7] !== isResolving || $[8] !== locationsCount || $[9] !== message || $[10] !== t ? (t2 = isResolving ? t("locations-banner.resolving.text") : message || t("locations-banner.locations-count", {
count: locationsCount
}), $[7] = isResolving, $[8] = locationsCount, $[9] = message, $[10] = t, $[11] = t2) : t2 = $[11];
const title = t2, ToneIcon = tone ? TONE_ICONS[tone] : void 0;
if (!resolvers || status === "empty")
return null;
let t3;
$[12] === Symbol.for("react.memo_cache_sentinel") ? (t3 = {
margin: -1
}, $[12] = t3) : t3 = $[12];
let t4;
$[13] !== ToneIcon || $[14] !== locations || $[15] !== options || $[16] !== showPresentationTitle || $[17] !== title || $[18] !== tone ? (t4 = !locations && /* @__PURE__ */ jsxs(Flex, { align: "flex-start", gap: 3, padding: 3, children: [
tone && ToneIcon && /* @__PURE__ */ jsx(Box, { flex: "none", children: /* @__PURE__ */ jsx(Text, { size: 1, children: /* @__PURE__ */ jsx(ToneIcon, {}) }) }),
/* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsxs(Text, { size: 1, weight: "medium", children: [
showPresentationTitle && /* @__PURE__ */ jsxs(Fragment, { children: [
options.title || DEFAULT_TOOL_TITLE,
" \xB7 "
] }),
title
] }) })
] }), $[13] = ToneIcon, $[14] = locations, $[15] = options, $[16] = showPresentationTitle, $[17] = title, $[18] = tone, $[19] = t4) : t4 = $[19];
let t5;
$[20] !== documentId || $[21] !== expanded || $[22] !== isResolving || $[23] !== locations || $[24] !== locationsCount || $[25] !== options || $[26] !== presentation || $[27] !== presentationName || $[28] !== schemaType || $[29] !== showPresentationTitle || $[30] !== title || $[31] !== toggle ? (t5 = locations && /* @__PURE__ */ jsxs(Fragment, { children: [
/* @__PURE__ */ jsx(Card, { as: locationsCount ? "button" : void 0, onClick: toggle, padding: 3, radius: 1, tone: "inherit", children: /* @__PURE__ */ jsxs(Flex, { gap: 3, children: [
/* @__PURE__ */ jsx(Box, { flex: "none", children: isResolving ? /* @__PURE__ */ jsx(Spinner, { size: 1 }) : /* @__PURE__ */ jsx(Text, { size: 1, children: locationsCount === 0 ? /* @__PURE__ */ jsx(InfoOutlineIcon, {}) : /* @__PURE__ */ jsx(ChevronRightIcon, { style: {
transform: `rotate(${expanded ? "90deg" : 0})`,
transition: "transform 100ms ease-in-out"
} }) }) }),
/* @__PURE__ */ jsx(Box, { flex: 1, children: /* @__PURE__ */ jsxs(Text, { size: 1, weight: "medium", children: [
showPresentationTitle && /* @__PURE__ */ jsxs(Fragment, { children: [
options.title || DEFAULT_TOOL_TITLE,
" \xB7 "
] }),
title
] }) })
] }) }),
/* @__PURE__ */ jsx(Stack, { hidden: !expanded, marginTop: 1, space: 1, children: locations.map((l) => {
let active = !1;
return (options.name || DEFAULT_TOOL_NAME) === presentationName && presentation?.params.preview && (active = areUrlsMatching(presentation.params.preview, l.href)), /* @__PURE__ */ jsx(LocationItem, { active, documentId, documentType: schemaType.name, node: l, toolName: options.name || DEFAULT_TOOL_NAME }, l.href);
}) })
] }), $[20] = documentId, $[21] = expanded, $[22] = isResolving, $[23] = locations, $[24] = locationsCount, $[25] = options, $[26] = presentation, $[27] = presentationName, $[28] = schemaType, $[29] = showPresentationTitle, $[30] = title, $[31] = toggle, $[32] = t5) : t5 = $[32];
let t6;
$[33] !== t4 || $[34] !== t5 ? (t6 = /* @__PURE__ */ jsxs("div", { style: t3, children: [
t4,
t5
] }), $[33] = t4, $[34] = t5, $[35] = t6) : t6 = $[35];
let t7;
return $[36] !== t6 || $[37] !== tone ? (t7 = /* @__PURE__ */ jsx(Card, { padding: 1, radius: 2, border: !0, tone, children: t6 }), $[36] = t6, $[37] = tone, $[38] = t7) : t7 = $[38], t7;
}
function _temp$2(v) {
return !v;
}
function LocationItem(props) {
const $ = c(26), {
documentId,
documentType,
node,
active,
toolName
} = props, presentation = useContext(PresentationContext), currentPresentationToolName = useCurrentPresentationToolName(), isCurrentTool = toolName === currentPresentationToolName, navigate = presentation?.navigate, t0 = presentation?.structureParams;
let t1;
$[0] !== documentId || $[1] !== documentType || $[2] !== node.href || $[3] !== t0 || $[4] !== toolName ? (t1 = {
intent: "edit",
params: {
id: documentId,
type: documentType,
mode: "presentation",
presentation: toolName,
...t0,
preview: node.href
}
}, $[0] = documentId, $[1] = documentType, $[2] = node.href, $[3] = t0, $[4] = toolName, $[5] = t1) : t1 = $[5];
const presentationLinkProps = useIntentLink(t1);
let t2;
$[6] !== navigate || $[7] !== node.href ? (t2 = () => {
navigate?.({
params: {
preview: node.href
}
});
}, $[6] = navigate, $[7] = node.href, $[8] = t2) : t2 = $[8];
const handleCurrentToolClick = t2;
let t3;
$[9] !== isCurrentTool || $[10] !== presentationLinkProps ? (t3 = isCurrentTool ? {} : presentationLinkProps, $[9] = isCurrentTool, $[10] = presentationLinkProps, $[11] = t3) : t3 = $[11];
const t4 = isCurrentTool ? handleCurrentToolClick : presentationLinkProps.onClick;
let t5;
$[12] === Symbol.for("react.memo_cache_sentinel") ? (t5 = /* @__PURE__ */ jsx(Box, { flex: "none", children: /* @__PURE__ */ jsx(Text, { size: 1, children: /* @__PURE__ */ jsx(DesktopIcon, {}) }) }), $[12] = t5) : t5 = $[12];
let t6;
$[13] !== node.title ? (t6 = /* @__PURE__ */ jsx(Text, { size: 1, weight: "medium", children: node.title }), $[13] = node.title, $[14] = t6) : t6 = $[14];
let t7;
$[15] !== node.href ? (t7 = /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, textOverflow: "ellipsis", children: node.href }), $[15] = node.href, $[16] = t7) : t7 = $[16];
let t8;
$[17] !== t6 || $[18] !== t7 ? (t8 = /* @__PURE__ */ jsxs(Flex, { gap: 3, children: [
t5,
/* @__PURE__ */ jsxs(Stack, { flex: 1, space: 2, children: [
t6,
t7
] })
] }), $[17] = t6, $[18] = t7, $[19] = t8) : t8 = $[19];
let t9;
return $[20] !== active || $[21] !== node.href || $[22] !== t3 || $[23] !== t4 || $[24] !== t8 ? (t9 = /* @__PURE__ */ jsx(Card, { ...t3, as: "a", onClick: t4, padding: 3, radius: 1, pressed: active, tone: "inherit", children: t8 }, node.href), $[20] = active, $[21] = node.href, $[22] = t3, $[23] = t4, $[24] = t8, $[25] = t9) : t9 = $[25], t9;
}
function areUrlsMatching(previewUrlString, locationUrlString) {
try {
const previewUrl = new URL(previewUrlString, location.origin), locationUrl = new URL(locationUrlString, previewUrl.origin);
if (previewUrl.origin !== locationUrl.origin || previewUrl.pathname !== locationUrl.pathname)
return !1;
const locationParams = new URLSearchParams(locationUrl.search), previewParams = new URLSearchParams(previewUrl.search);
for (const [key, value] of locationParams.entries())
if (previewParams.get(key) !== value)
return !1;
return !0;
} catch {
return !1;
}
}
const LocationStack = styled.div((props) => {
const theme = getTheme_v2(props.theme);
return css`
display: flex;
flex-direction: column;
gap: ${rem(theme.space[2])};
min-height: ${rem(42)};
margin-bottom: ${rem(theme.space[5])};
&:empty {
display: none;
}
`;
});
function PresentationDocumentHeader(props) {
const $ = c(19), {
documentId,
options,
schemaType,
version
} = props, context = useContext(PresentationDocumentContext);
let t0;
$[0] !== context?.options ? (t0 = context?.options || [], $[0] = context?.options, $[1] = t0) : t0 = $[1];
const contextOptions = t0;
let resolvers, t1;
$[2] !== contextOptions ? (resolvers = contextOptions.map(_temp$1), t1 = resolvers.some(Boolean), $[2] = contextOptions, $[3] = resolvers, $[4] = t1) : (resolvers = $[3], t1 = $[4]);
const hasResolvers = t1;
if (context && context.options[0] !== options || !hasResolvers)
return null;
let t2;
if ($[5] !== contextOptions || $[6] !== documentId || $[7] !== resolvers || $[8] !== schemaType || $[9] !== version) {
let t32;
$[11] !== contextOptions.length || $[12] !== documentId || $[13] !== resolvers || $[14] !== schemaType || $[15] !== version ? (t32 = (_options, idx) => /* @__PURE__ */ jsx(LocationsBanner, { documentId, options: _options, resolvers: resolvers[idx], schemaType, showPresentationTitle: contextOptions.length > 1, version }, idx), $[11] = contextOptions.length, $[12] = documentId, $[13] = resolvers, $[14] = schemaType, $[15] = version, $[16] = t32) : t32 = $[16], t2 = contextOptions.map(t32), $[5] = contextOptions, $[6] = documentId, $[7] = resolvers, $[8] = schemaType, $[9] = version, $[10] = t2;
} else
t2 = $[10];
let t3;
return $[17] !== t2 ? (t3 = /* @__PURE__ */ jsx(LocationStack, { children: t2 }), $[17] = t2, $[18] = t3) : t3 = $[18], t3;
}
function _temp$1(o) {
return o.resolve?.locations || o.locate;
}
function PresentationDocumentProvider(props) {
const $ = c(15), {
children,
options
} = props, parent = useContext(PresentationDocumentContext), parentRegister = parent?.register, [optionsArray, setOptionsArray] = useState(_temp);
let t0;
$[0] !== parentRegister ? (t0 = (options_0) => parentRegister ? parentRegister(options_0) : (setOptionsArray((prev) => [options_0].concat(prev)), () => {
setOptionsArray((prev_0) => prev_0.filter((o) => o !== options_0));
}), $[0] = parentRegister, $[1] = t0) : t0 = $[1];
const register = t0;
let t1;
const t2 = parent?.options || optionsArray;
let t3;
$[2] !== register || $[3] !== t2 ? (t3 = {
options: t2,
register
}, $[2] = register, $[3] = t2, $[4] = t3) : t3 = $[4], t1 = t3;
const context = t1;
let t4;
$[5] !== register ? (t4 = (options_1) => register(options_1), $[5] = register, $[6] = t4) : t4 = $[6];
const registerEffectEvent = useEffectEvent(t4);
let t5;
$[7] !== options || $[8] !== registerEffectEvent ? (t5 = () => registerEffectEvent(options), $[7] = options, $[8] = registerEffectEvent, $[9] = t5) : t5 = $[9];
let t6;
$[10] !== options ? (t6 = [options], $[10] = options, $[11] = t6) : t6 = $[11], useLayoutEffect(t5, t6);
let t7;
return $[12] !== children || $[13] !== context ? (t7 = /* @__PURE__ */ jsx(PresentationDocumentContext.Provider, { value: context, children }), $[12] = children, $[13] = context, $[14] = t7) : t7 = $[14], t7;
}
function _temp() {
return [];
}
function useOpenInStructureAction(props) {
const $ = c(13), {
documentId,
documentType,
path
} = props, workspace = useWorkspace(), {
navigateIntent
} = useRouter(), presentation = useContext(PresentationContext);
let t0;
const t1 = presentation?.name || DEFAULT_TOOL_NAME;
let t2;
$[0] !== documentId || $[1] !== documentType || $[2] !== t1 || $[3] !== workspace.tools ? (t2 = findStructureTool(workspace.tools, documentId, documentType, t1), $[0] = documentId, $[1] = documentType, $[2] = t1, $[3] = workspace.tools, $[4] = t2) : t2 = $[4], t0 = t2;
const defaultStructureTool = t0, t3 = !presentation || path.length > 0 || !defaultStructureTool, t4 = defaultStructureTool?.icon || MasterDetailIcon, t5 = `Open in ${defaultStructureTool?.title || "Structure"}`;
let t6;
return $[5] !== documentId || $[6] !== documentType || $[7] !== navigateIntent || $[8] !== path || $[9] !== t3 || $[10] !== t4 || $[11] !== t5 ? (t6 = {
type: "action",
hidden: t3,
icon: t4,
title: t5,
onAction() {
navigateIntent("edit", {
id: documentId,
type: documentType,
mode: "structure",
path: pathToString(path)
});
},
renderAsButton: !0
}, $[5] = documentId, $[6] = documentType, $[7] = navigateIntent, $[8] = path, $[9] = t3, $[10] = t4, $[11] = t5, $[12] = t6) : t6 = $[12], t6;
}
const openInStructure = defineDocumentFieldAction({
name: "presentation/openInStructure",
useAction: useOpenInStructureAction
});
function findStructureTool(tools, documentId, documentType, presentationToolName) {
const results = tools.filter((t) => t.name !== presentationToolName).map((t) => {
const match = t.canHandleIntent?.("edit", {
id: documentId,
type: documentType,
mode: "structure"
}, {});
return {
tool: t,
match
};
}), modeMatches = results.filter((t) => isRecord(t.match) && t.match.mode);
return modeMatches.length > 0 ? modeMatches[0].tool : results.filter((t) => t.match)[0]?.tool;
}
const preservedSearchParamKeys = ["preview", "viewport"];
function getIntentState(intent, params, routerState, payload) {
const {
id,
mode,
path,
presentation,
type,
...searchParams
} = params, _searchParams = {
...(routerState?._searchParams || []).filter(([key]) => preservedSearchParamKeys.includes(key)).reduce((acc, [key, value]) => ({
...acc,
[key]: value
}), {}),
...searchParams
};
return intent === "edit" && id ? (_searchParams.preview = _searchParams.preview || new URLSearchParams(window.location.search).get("preview") || "/", {
type: type || "*",
id: getPublishedId(id),
path,
_searchParams: Object.entries(_searchParams)
}) : intent === "create" ? (_searchParams.preview = _searchParams.preview || new URLSearchParams(window.location.search).get("preview") || "/", payload && typeof payload == "object" && (_searchParams.templateParams = encodeJsonParams(payload)), {
type: type || "*",
id: id || uuid(),
_searchParams: Object.entries(_searchParams)
}) : {
intent,
params,
payload
};
}
function PresentationSpinner() {
const $ = c(1);
let t0;
return $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = /* @__PURE__ */ jsx(Flex, { align: "center", direction: "column", height: "fill", justify: "center", style: {
width: "100%"
}, children: /* @__PURE__ */ jsx(Spinner, {}) }), $[0] = t0) : t0 = $[0], t0;
}
const router = route.create("/", {
__unsafe_disableScopedSearchParams: !0
}, [route.intents("/intent"), route.create(":type", [route.create(":id", [route.create(":path")])])]), PresentationTool = lazy(() => import("./PresentationToolGrantsCheck.mjs")), BroadcastDisplayedDocument = lazy(() => import("./BroadcastDisplayedDocument.mjs"));
function defineLocations(resolver) {
return resolver;
}
function defineDocuments(resolvers) {
return resolvers;
}
const presentationTool = definePlugin((options) => {
const toolName = options.name || DEFAULT_TOOL_NAME;
"locate" in options && console.warn("Presentation\u2019s `locate` option is deprecated. Use `resolve.locations` instead.");
const hasLocationsResolver = !!(options.resolve?.locations || options.locate);
function PresentationDocumentInput(props) {
const $ = c(22), value = props.value;
let t0;
$[0] !== value?._id ? (t0 = value?._id ? getPublishedId(value?._id) : void 0, $[0] = value?._id, $[1] = t0) : t0 = $[1];
const documentId = t0;
let t1;
$[2] !== value ? (t1 = value?._id ? getVersionFromId(value._id) : void 0, $[2] = value, $[3] = t1) : t1 = $[3];
const documentVersion = t1;
if (isDocumentSchemaType(props.schemaType)) {
let t22;
$[4] !== documentId || $[5] !== documentVersion || $[6] !== props.schemaType ? (t22 = hasLocationsResolver && documentId && /* @__PURE__ */ jsx(PresentationDocumentHeader, { documentId, version: documentVersion, options, schemaType: props.schemaType }), $[4] = documentId, $[5] = documentVersion, $[6] = props.schemaType, $[7] = t22) : t22 = $[7];
let t3;
$[8] === Symbol.for("react.memo_cache_sentinel") ? (t3 = /* @__PURE__ */ jsx(PresentationSpinner, {}), $[8] = t3) : t3 = $[8];
let t4;
$[9] !== props ? (t4 = props.renderDefault(props), $[9] = props, $[10] = t4) : t4 = $[10];
let t5;
$[11] !== t4 ? (t5 = /* @__PURE__ */ jsx(Suspense, { fallback: t3, children: t4 }), $[11] = t4, $[12] = t5) : t5 = $[12];
let t6;
$[13] !== documentId || $[14] !== value ? (t6 = /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(BroadcastDisplayedDocument, { value }, documentId) }, "broadcast-displayed-document"), $[13] = documentId, $[14] = value, $[15] = t6) : t6 = $[15];
let t7;
return $[16] !== t22 || $[17] !== t5 || $[18] !== t6 ? (t7 = /* @__PURE__ */ jsxs(PresentationDocumentProvider, { options, children: [
t22,
t5,
t6
] }), $[16] = t22, $[17] = t5, $[18] = t6, $[19] = t7) : t7 = $[19], t7;
}
let t2;
return $[20] !== props ? (t2 = props.renderDefault(props), $[20] = props, $[21] = t2) : t2 = $[21], t2;
}
function canHandleCreateIntent(params) {
return !("type" in params) || "presentation" in params && params.presentation !== toolName ? !1 : "template" in params ? {
template: !0
} : !0;
}
function canHandleEditIntent(params) {
return !("type" in params) || !("id" in params) || "presentation" in params && params.presentation !== toolName ? !1 : "mode" in params ? {
mode: params.mode === EDIT_INTENT_MODE
} : !0;
}
return {
i18n: {
bundles: [presentationUsEnglishLocaleBundle]
},
document: {
unstable_fieldActions: (prev) => [
...prev.filter((a) => a.name !== openInStructure.name),
// prevent duplication
openInStructure
]
},
form: {
components: {
input: PresentationDocumentInput
}
},
tools: [{
icon: options.icon || DEFAULT_TOOL_ICON,
name: toolName,
title: options.title,
component: PresentationTool,
options,
canHandleIntent(intent, params) {
return intent === "create" ? canHandleCreateIntent(params) : intent === "edit" ? canHandleEditIntent(params) : !1;
},
getIntentState,
router,
__internalApplicationType: "sanity/presentation"
}]
};
});
function usePresentationNavigate() {
const navigate = useContext(PresentationNavigateContext);
if (!navigate)
throw new Error("Presentation navigate context is missing");
return navigate;
}
function usePresentationParams(t0) {
const throwOnMissingContext = t0 === void 0 ? !0 : t0, params = useContext(PresentationParamsContext);
if (throwOnMissingContext && !params)
throw new Error("Presentation params context is missing");
return params;
}
export {
API_VERSION,
DEFAULT_TOOL_NAME,
EDIT_INTENT_MODE,
LOADER_QUERY_GC_INTERVAL,
MAX_TIME_TO_OVERLAYS_CONNECTION,
MIN_LOADER_QUERY_LISTEN_HEARTBEAT_INTERVAL,
POPUP_CHECK_INTERVAL,
PresentationSpinner,
defineDocuments,
defineLocations,
presentationLocaleNamespace,
presentationTool,
usePresentationNavigate,
usePresentationParams,
usePresentationTool,
useSharedState
};
//# sourceMappingURL=presentation.mjs.map