@sanity/sdk-react 0.0.0-alpha.3 → 0.0.0-alpha.30
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/README.md +6 -100
- package/dist/index.d.ts +2390 -2
- package/dist/index.js +1119 -2
- package/dist/index.js.map +1 -1
- package/package.json +35 -49
- package/src/_exports/index.ts +2 -10
- package/src/_exports/sdk-react.ts +73 -0
- package/src/components/SDKProvider.test.tsx +103 -0
- package/src/components/SDKProvider.tsx +52 -0
- package/src/components/SanityApp.test.tsx +244 -0
- package/src/components/SanityApp.tsx +106 -0
- package/src/components/auth/AuthBoundary.test.tsx +204 -29
- package/src/components/auth/AuthBoundary.tsx +96 -19
- package/src/components/auth/ConfigurationError.ts +22 -0
- package/src/components/auth/LoginCallback.test.tsx +22 -24
- package/src/components/auth/LoginCallback.tsx +6 -16
- package/src/components/auth/LoginError.test.tsx +11 -18
- package/src/components/auth/LoginError.tsx +43 -25
- package/src/components/utils.ts +22 -0
- package/src/context/ResourceProvider.test.tsx +157 -0
- package/src/context/ResourceProvider.tsx +111 -0
- package/src/context/SanityInstanceContext.ts +4 -0
- package/src/hooks/_synchronous-groq-js.mjs +4 -0
- package/src/hooks/auth/useAuthState.tsx +4 -5
- package/src/hooks/auth/useAuthToken.tsx +1 -1
- package/src/hooks/auth/useCurrentUser.tsx +28 -4
- package/src/hooks/auth/useDashboardOrganizationId.test.tsx +42 -0
- package/src/hooks/auth/useDashboardOrganizationId.tsx +30 -0
- package/src/hooks/auth/useHandleAuthCallback.test.tsx +16 -0
- package/src/hooks/auth/{useHandleCallback.tsx → useHandleAuthCallback.tsx} +7 -6
- package/src/hooks/auth/useLogOut.test.tsx +2 -2
- package/src/hooks/auth/useLogOut.tsx +1 -1
- package/src/hooks/auth/useLoginUrl.tsx +14 -0
- package/src/hooks/auth/useVerifyOrgProjects.test.tsx +136 -0
- package/src/hooks/auth/useVerifyOrgProjects.tsx +48 -0
- package/src/hooks/client/useClient.ts +13 -33
- package/src/hooks/comlink/useFrameConnection.test.tsx +167 -0
- package/src/hooks/comlink/useFrameConnection.ts +107 -0
- package/src/hooks/comlink/useManageFavorite.test.ts +368 -0
- package/src/hooks/comlink/useManageFavorite.ts +210 -0
- package/src/hooks/comlink/useRecordDocumentHistoryEvent.test.ts +85 -0
- package/src/hooks/comlink/useRecordDocumentHistoryEvent.ts +115 -0
- package/src/hooks/comlink/useWindowConnection.test.ts +135 -0
- package/src/hooks/comlink/useWindowConnection.ts +123 -0
- package/src/hooks/context/useSanityInstance.test.tsx +157 -15
- package/src/hooks/context/useSanityInstance.ts +68 -11
- package/src/hooks/dashboard/useNavigateToStudioDocument.test.ts +276 -0
- package/src/hooks/dashboard/useNavigateToStudioDocument.ts +139 -0
- package/src/hooks/dashboard/useStudioWorkspacesByProjectIdDataset.test.tsx +291 -0
- package/src/hooks/dashboard/useStudioWorkspacesByProjectIdDataset.ts +101 -0
- package/src/hooks/datasets/useDatasets.test.ts +80 -0
- package/src/hooks/datasets/useDatasets.ts +52 -0
- package/src/hooks/document/useApplyDocumentActions.test.ts +20 -0
- package/src/hooks/document/useApplyDocumentActions.ts +124 -0
- package/src/hooks/document/useDocument.test.ts +118 -0
- package/src/hooks/document/useDocument.ts +212 -0
- package/src/hooks/document/useDocumentEvent.test.ts +62 -0
- package/src/hooks/document/useDocumentEvent.ts +94 -0
- package/src/hooks/document/useDocumentPermissions.test.ts +204 -0
- package/src/hooks/document/useDocumentPermissions.ts +131 -0
- package/src/hooks/document/useDocumentSyncStatus.test.ts +23 -0
- package/src/hooks/document/useDocumentSyncStatus.ts +61 -0
- package/src/hooks/document/useEditDocument.test.ts +196 -0
- package/src/hooks/document/useEditDocument.ts +314 -0
- package/src/hooks/documents/useDocuments.test.tsx +179 -0
- package/src/hooks/documents/useDocuments.ts +300 -0
- package/src/hooks/helpers/createCallbackHook.test.tsx +2 -2
- package/src/hooks/helpers/createCallbackHook.tsx +1 -1
- package/src/hooks/helpers/createStateSourceHook.test.tsx +67 -1
- package/src/hooks/helpers/createStateSourceHook.tsx +27 -11
- package/src/hooks/paginatedDocuments/usePaginatedDocuments.test.tsx +284 -0
- package/src/hooks/paginatedDocuments/usePaginatedDocuments.ts +353 -0
- package/src/hooks/preview/usePreview.test.tsx +85 -17
- package/src/hooks/preview/usePreview.tsx +81 -22
- package/src/hooks/projection/useProjection.test.tsx +283 -0
- package/src/hooks/projection/useProjection.ts +232 -0
- package/src/hooks/projects/useProject.test.ts +80 -0
- package/src/hooks/projects/useProject.ts +51 -0
- package/src/hooks/projects/useProjects.test.ts +77 -0
- package/src/hooks/projects/useProjects.ts +45 -0
- package/src/hooks/query/useQuery.test.tsx +188 -0
- package/src/hooks/query/useQuery.ts +193 -0
- package/src/hooks/releases/useActiveReleases.test.tsx +84 -0
- package/src/hooks/releases/useActiveReleases.ts +39 -0
- package/src/hooks/releases/usePerspective.test.tsx +120 -0
- package/src/hooks/releases/usePerspective.ts +49 -0
- package/src/hooks/users/useUsers.test.tsx +330 -0
- package/src/hooks/users/useUsers.ts +120 -0
- package/src/utils/getEnv.ts +21 -0
- package/src/version.ts +8 -0
- package/src/vite-env.d.ts +10 -0
- package/dist/_chunks-es/useLogOut.js +0 -44
- package/dist/_chunks-es/useLogOut.js.map +0 -1
- package/dist/assets/bundle-CcAyERuZ.css +0 -11
- package/dist/components.d.ts +0 -259
- package/dist/components.js +0 -301
- package/dist/components.js.map +0 -1
- package/dist/hooks.d.ts +0 -186
- package/dist/hooks.js +0 -81
- package/dist/hooks.js.map +0 -1
- package/src/_exports/components.ts +0 -13
- package/src/_exports/hooks.ts +0 -9
- package/src/components/DocumentGridLayout/DocumentGridLayout.stories.tsx +0 -113
- package/src/components/DocumentGridLayout/DocumentGridLayout.test.tsx +0 -42
- package/src/components/DocumentGridLayout/DocumentGridLayout.tsx +0 -21
- package/src/components/DocumentListLayout/DocumentListLayout.stories.tsx +0 -105
- package/src/components/DocumentListLayout/DocumentListLayout.test.tsx +0 -42
- package/src/components/DocumentListLayout/DocumentListLayout.tsx +0 -12
- package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.md +0 -49
- package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.stories.tsx +0 -39
- package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.test.tsx +0 -30
- package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.tsx +0 -171
- package/src/components/Login/LoginLinks.test.tsx +0 -100
- package/src/components/Login/LoginLinks.tsx +0 -73
- package/src/components/auth/Login.test.tsx +0 -41
- package/src/components/auth/Login.tsx +0 -45
- package/src/components/auth/LoginFooter.test.tsx +0 -29
- package/src/components/auth/LoginFooter.tsx +0 -65
- package/src/components/auth/LoginLayout.test.tsx +0 -33
- package/src/components/auth/LoginLayout.tsx +0 -81
- package/src/components/context/SanityProvider.test.tsx +0 -25
- package/src/components/context/SanityProvider.tsx +0 -42
- package/src/css/css.config.js +0 -220
- package/src/css/paramour.css +0 -2347
- package/src/css/styles.css +0 -11
- package/src/hooks/auth/useHandleCallback.test.tsx +0 -16
- package/src/hooks/auth/useLoginUrls.test.tsx +0 -68
- package/src/hooks/auth/useLoginUrls.tsx +0 -51
- package/src/hooks/client/useClient.test.tsx +0 -130
- package/src/hooks/documentCollection/useDocuments.test.ts +0 -130
- package/src/hooks/documentCollection/useDocuments.ts +0 -87
package/dist/index.js
CHANGED
|
@@ -1,6 +1,1123 @@
|
|
|
1
|
-
|
|
1
|
+
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { c } from "react-compiler-runtime";
|
|
3
|
+
import { getAuthState, getLoginUrlState, observeOrganizationVerificationState, handleAuthCallback, logout, AuthStateType, createSanityInstance, getTokenState, getCurrentUserState, getDashboardOrganizationId, getClientState, getOrCreateController, getOrCreateChannel, releaseChannel, getOrCreateNode, releaseNode, getFavoritesState, resolveFavoritesState, resolveDatasets, getDatasetsState, applyDocumentActions, resolveDocument, getDocumentState, subscribeDocumentEvents, getPermissionsState, getDocumentSyncStatus, editDocument, getQueryKey, parseQueryKey, getQueryState, resolveQuery, createGroqSearchFilter, getPreviewState, resolvePreview, getProjectionState, resolveProjection, resolveProject, getProjectState, resolveProjects, getProjectsState, getActiveReleasesState, getPerspectiveState, getUsersKey, parseUsersKey, getUsersState, resolveUsers, loadMoreUsers } from "@sanity/sdk";
|
|
4
|
+
export * from "@sanity/sdk";
|
|
5
|
+
import { createContext, useContext, useSyncExternalStore, useState, useEffect, useRef, Suspense, useMemo, useCallback, useInsertionEffect, useTransition } from "react";
|
|
6
|
+
import { ErrorBoundary } from "react-error-boundary";
|
|
7
|
+
import { ClientError } from "@sanity/client";
|
|
8
|
+
import { identity, firstValueFrom, filter, Observable, startWith, distinctUntilChanged, switchMap, EMPTY } from "rxjs";
|
|
9
|
+
import { SDK_CHANNEL_NAME, SDK_NODE_NAME } from "@sanity/message-protocol";
|
|
10
|
+
import { pick } from "lodash-es";
|
|
11
|
+
const SanityInstanceContext = createContext(null), useSanityInstance = (config) => {
|
|
12
|
+
const $ = c(3), instance = useContext(SanityInstanceContext);
|
|
13
|
+
if (!instance)
|
|
14
|
+
throw new Error(`SanityInstance context not found. ${config ? `Requested config: ${JSON.stringify(config, null, 2)}. ` : ""}Please ensure that your component is wrapped in a <ResourceProvider> or a <SanityApp>.`);
|
|
15
|
+
if (!config)
|
|
16
|
+
return instance;
|
|
17
|
+
let t0;
|
|
18
|
+
$[0] !== config || $[1] !== instance ? (t0 = instance.match(config), $[0] = config, $[1] = instance, $[2] = t0) : t0 = $[2];
|
|
19
|
+
const match = t0;
|
|
20
|
+
if (!match)
|
|
21
|
+
throw new Error(`Could not find a matching Sanity instance for the requested configuration: ${JSON.stringify(config, null, 2)}.
|
|
22
|
+
Please ensure there is a <ResourceProvider> with a matching configuration in the component hierarchy.`);
|
|
23
|
+
return match;
|
|
24
|
+
};
|
|
25
|
+
function createStateSourceHook(options) {
|
|
26
|
+
const getState = typeof options == "function" ? options : options.getState, getConfig = "getConfig" in options ? options.getConfig : void 0, suspense = "shouldSuspend" in options && "suspender" in options ? options : void 0;
|
|
27
|
+
function useHook(...t0) {
|
|
28
|
+
const $ = c(5), params = t0;
|
|
29
|
+
let t1;
|
|
30
|
+
$[0] !== params ? (t1 = getConfig?.(...params), $[0] = params, $[1] = t1) : t1 = $[1];
|
|
31
|
+
const instance = useSanityInstance(t1);
|
|
32
|
+
if (suspense?.suspender && suspense?.shouldSuspend?.(instance, ...params))
|
|
33
|
+
throw suspense.suspender(instance, ...params);
|
|
34
|
+
let t2;
|
|
35
|
+
$[2] !== instance || $[3] !== params ? (t2 = getState(instance, ...params), $[2] = instance, $[3] = params, $[4] = t2) : t2 = $[4];
|
|
36
|
+
const state = t2;
|
|
37
|
+
return useSyncExternalStore(state.subscribe, state.getCurrent);
|
|
38
|
+
}
|
|
39
|
+
return useHook;
|
|
40
|
+
}
|
|
41
|
+
const useAuthState = createStateSourceHook(getAuthState);
|
|
42
|
+
function useLoginUrl() {
|
|
43
|
+
const $ = c(2), instance = useSanityInstance();
|
|
44
|
+
let t0, t1;
|
|
45
|
+
$[0] !== instance ? (t1 = getLoginUrlState(instance), $[0] = instance, $[1] = t1) : t1 = $[1], t0 = t1;
|
|
46
|
+
const {
|
|
47
|
+
subscribe,
|
|
48
|
+
getCurrent
|
|
49
|
+
} = t0;
|
|
50
|
+
return useSyncExternalStore(subscribe, getCurrent);
|
|
51
|
+
}
|
|
52
|
+
function useVerifyOrgProjects(t0, projectIds) {
|
|
53
|
+
const $ = c(6), disabled = t0 === void 0 ? !1 : t0, instance = useSanityInstance(), [error, setError] = useState(null);
|
|
54
|
+
let t1, t2;
|
|
55
|
+
return $[0] !== disabled || $[1] !== error || $[2] !== instance || $[3] !== projectIds ? (t1 = () => {
|
|
56
|
+
if (disabled || !projectIds || projectIds.length === 0) {
|
|
57
|
+
error !== null && setError(null);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const subscription = observeOrganizationVerificationState(instance, projectIds).subscribe((result) => {
|
|
61
|
+
setError(result.error);
|
|
62
|
+
});
|
|
63
|
+
return () => {
|
|
64
|
+
subscription.unsubscribe();
|
|
65
|
+
};
|
|
66
|
+
}, t2 = [instance, disabled, error, projectIds], $[0] = disabled, $[1] = error, $[2] = instance, $[3] = projectIds, $[4] = t1, $[5] = t2) : (t1 = $[4], t2 = $[5]), useEffect(t1, t2), error;
|
|
67
|
+
}
|
|
68
|
+
function isInIframe() {
|
|
69
|
+
return typeof window < "u" && window.self !== window.top;
|
|
70
|
+
}
|
|
71
|
+
function isLocalUrl(window2) {
|
|
72
|
+
const url = typeof window2 < "u" ? window2.location.href : "";
|
|
73
|
+
return url.startsWith("http://localhost") || url.startsWith("https://localhost") || url.startsWith("http://127.0.0.1") || url.startsWith("https://127.0.0.1");
|
|
74
|
+
}
|
|
75
|
+
class AuthError extends Error {
|
|
76
|
+
constructor(error) {
|
|
77
|
+
typeof error == "object" && error && "message" in error && typeof error.message == "string" ? super(error.message) : super(), this.cause = error;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
class ConfigurationError extends Error {
|
|
81
|
+
constructor(error) {
|
|
82
|
+
typeof error == "object" && error && "message" in error && typeof error.message == "string" ? super(error.message) : super(), this.cause = error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function createCallbackHook(callback) {
|
|
86
|
+
function useHook() {
|
|
87
|
+
const $ = c(2), instance = useSanityInstance();
|
|
88
|
+
let t0;
|
|
89
|
+
return $[0] !== instance ? (t0 = (...t1) => callback(instance, ...t1), $[0] = instance, $[1] = t0) : t0 = $[1], t0;
|
|
90
|
+
}
|
|
91
|
+
return useHook;
|
|
92
|
+
}
|
|
93
|
+
const useHandleAuthCallback = createCallbackHook(handleAuthCallback);
|
|
94
|
+
function LoginCallback() {
|
|
95
|
+
const $ = c(3), handleAuthCallback2 = useHandleAuthCallback();
|
|
96
|
+
let t0, t1;
|
|
97
|
+
return $[0] !== handleAuthCallback2 ? (t0 = () => {
|
|
98
|
+
const url = new URL(location.href);
|
|
99
|
+
handleAuthCallback2(url.toString()).then(_temp$6);
|
|
100
|
+
}, t1 = [handleAuthCallback2], $[0] = handleAuthCallback2, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), useEffect(t0, t1), null;
|
|
101
|
+
}
|
|
102
|
+
function _temp$6(replacementLocation) {
|
|
103
|
+
replacementLocation && history.replaceState(null, "", replacementLocation);
|
|
104
|
+
}
|
|
105
|
+
const useLogOut = createCallbackHook(logout);
|
|
106
|
+
function LoginError(t0) {
|
|
107
|
+
const $ = c(24), {
|
|
108
|
+
error,
|
|
109
|
+
resetErrorBoundary
|
|
110
|
+
} = t0;
|
|
111
|
+
if (!(error instanceof AuthError || error instanceof ConfigurationError))
|
|
112
|
+
throw error;
|
|
113
|
+
const logout2 = useLogOut(), authState = useAuthState(), [authErrorMessage, setAuthErrorMessage] = useState("Please try again or contact support if the problem persists.");
|
|
114
|
+
let t1;
|
|
115
|
+
$[0] !== logout2 || $[1] !== resetErrorBoundary ? (t1 = async () => {
|
|
116
|
+
await logout2(), resetErrorBoundary();
|
|
117
|
+
}, $[0] = logout2, $[1] = resetErrorBoundary, $[2] = t1) : t1 = $[2];
|
|
118
|
+
const handleRetry = t1;
|
|
119
|
+
let t2;
|
|
120
|
+
$[3] !== authState.error || $[4] !== authState.type || $[5] !== error || $[6] !== handleRetry ? (t2 = () => {
|
|
121
|
+
if (authState.type === AuthStateType.ERROR && authState.error instanceof ClientError) {
|
|
122
|
+
if (authState.error.statusCode === 401)
|
|
123
|
+
handleRetry();
|
|
124
|
+
else if (authState.error.statusCode === 404) {
|
|
125
|
+
const errorMessage = authState.error.response.body.message || "";
|
|
126
|
+
errorMessage.startsWith("Session with sid") && errorMessage.endsWith("not found") ? setAuthErrorMessage("The session ID is invalid or expired.") : setAuthErrorMessage("The login link is invalid or expired. Please try again.");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
authState.type !== AuthStateType.ERROR && error instanceof ConfigurationError && setAuthErrorMessage(error.message);
|
|
130
|
+
}, $[3] = authState.error, $[4] = authState.type, $[5] = error, $[6] = handleRetry, $[7] = t2) : t2 = $[7];
|
|
131
|
+
let t3;
|
|
132
|
+
$[8] !== authState || $[9] !== error || $[10] !== handleRetry ? (t3 = [authState, handleRetry, error], $[8] = authState, $[9] = error, $[10] = handleRetry, $[11] = t3) : t3 = $[11], useEffect(t2, t3);
|
|
133
|
+
const t4 = error instanceof AuthError ? "Authentication Error" : "Configuration Error";
|
|
134
|
+
let t5;
|
|
135
|
+
$[12] !== t4 ? (t5 = /* @__PURE__ */ jsx("h2", { className: "sc-login-error__title", children: t4 }), $[12] = t4, $[13] = t5) : t5 = $[13];
|
|
136
|
+
let t6;
|
|
137
|
+
$[14] !== authErrorMessage ? (t6 = /* @__PURE__ */ jsx("p", { className: "sc-login-error__description", children: authErrorMessage }), $[14] = authErrorMessage, $[15] = t6) : t6 = $[15];
|
|
138
|
+
let t7;
|
|
139
|
+
$[16] !== t5 || $[17] !== t6 ? (t7 = /* @__PURE__ */ jsxs("div", { className: "sc-login-error__content", children: [
|
|
140
|
+
t5,
|
|
141
|
+
t6
|
|
142
|
+
] }), $[16] = t5, $[17] = t6, $[18] = t7) : t7 = $[18];
|
|
143
|
+
let t8;
|
|
144
|
+
$[19] !== handleRetry ? (t8 = /* @__PURE__ */ jsx("button", { className: "sc-login-error__button", onClick: handleRetry, children: "Retry" }), $[19] = handleRetry, $[20] = t8) : t8 = $[20];
|
|
145
|
+
let t9;
|
|
146
|
+
return $[21] !== t7 || $[22] !== t8 ? (t9 = /* @__PURE__ */ jsxs("div", { className: "sc-login-error", children: [
|
|
147
|
+
t7,
|
|
148
|
+
t8
|
|
149
|
+
] }), $[21] = t7, $[22] = t8, $[23] = t9) : t9 = $[23], t9;
|
|
150
|
+
}
|
|
151
|
+
if (isInIframe() && !document.querySelector("[data-sanity-core]")) {
|
|
152
|
+
const parsedUrl = new URL(window.location.href), mode = new URLSearchParams(parsedUrl.hash.slice(1)).get("mode"), script = document.createElement("script");
|
|
153
|
+
script.src = mode === "core-ui--staging" ? "https://core.sanity-cdn.work/bridge.js" : "https://core.sanity-cdn.com/bridge.js", script.type = "module", script.async = !0, document.head.appendChild(script);
|
|
154
|
+
}
|
|
155
|
+
function AuthBoundary(t0) {
|
|
156
|
+
const $ = c(10);
|
|
157
|
+
let props, t1;
|
|
158
|
+
$[0] !== t0 ? ({
|
|
159
|
+
LoginErrorComponent: t1,
|
|
160
|
+
...props
|
|
161
|
+
} = t0, $[0] = t0, $[1] = props, $[2] = t1) : (props = $[1], t1 = $[2]);
|
|
162
|
+
const LoginErrorComponent = t1 === void 0 ? LoginError : t1;
|
|
163
|
+
let t2, t3;
|
|
164
|
+
$[3] !== LoginErrorComponent ? (t3 = function(fallbackProps) {
|
|
165
|
+
return /* @__PURE__ */ jsx(LoginErrorComponent, { ...fallbackProps });
|
|
166
|
+
}, $[3] = LoginErrorComponent, $[4] = t3) : t3 = $[4], t2 = t3;
|
|
167
|
+
const FallbackComponent = t2;
|
|
168
|
+
let t4;
|
|
169
|
+
$[5] !== props ? (t4 = /* @__PURE__ */ jsx(AuthSwitch, { ...props }), $[5] = props, $[6] = t4) : t4 = $[6];
|
|
170
|
+
let t5;
|
|
171
|
+
return $[7] !== FallbackComponent || $[8] !== t4 ? (t5 = /* @__PURE__ */ jsx(ErrorBoundary, { FallbackComponent, children: t4 }), $[7] = FallbackComponent, $[8] = t4, $[9] = t5) : t5 = $[9], t5;
|
|
172
|
+
}
|
|
173
|
+
function AuthSwitch(t0) {
|
|
174
|
+
const $ = c(13);
|
|
175
|
+
let children, projectIds, props, t1, t2;
|
|
176
|
+
$[0] !== t0 ? ({
|
|
177
|
+
CallbackComponent: t1,
|
|
178
|
+
children,
|
|
179
|
+
verifyOrganization: t2,
|
|
180
|
+
projectIds,
|
|
181
|
+
...props
|
|
182
|
+
} = t0, $[0] = t0, $[1] = children, $[2] = projectIds, $[3] = props, $[4] = t1, $[5] = t2) : (children = $[1], projectIds = $[2], props = $[3], t1 = $[4], t2 = $[5]);
|
|
183
|
+
const CallbackComponent = t1 === void 0 ? LoginCallback : t1, verifyOrganization = t2 === void 0 ? !0 : t2, authState = useAuthState(), orgError = useVerifyOrgProjects(!verifyOrganization, projectIds), isLoggedOut = authState.type === AuthStateType.LOGGED_OUT && !authState.isDestroyingSession, loginUrl = useLoginUrl();
|
|
184
|
+
let t3, t4;
|
|
185
|
+
if ($[6] !== isLoggedOut || $[7] !== loginUrl ? (t3 = () => {
|
|
186
|
+
isLoggedOut && !isInIframe() && (window.location.href = loginUrl);
|
|
187
|
+
}, t4 = [isLoggedOut, loginUrl], $[6] = isLoggedOut, $[7] = loginUrl, $[8] = t3, $[9] = t4) : (t3 = $[8], t4 = $[9]), useEffect(t3, t4), verifyOrganization && orgError)
|
|
188
|
+
throw new ConfigurationError({
|
|
189
|
+
message: orgError
|
|
190
|
+
});
|
|
191
|
+
switch (authState.type) {
|
|
192
|
+
case AuthStateType.ERROR:
|
|
193
|
+
throw new AuthError(authState.error);
|
|
194
|
+
case AuthStateType.LOGGING_IN: {
|
|
195
|
+
let t5;
|
|
196
|
+
return $[10] !== CallbackComponent || $[11] !== props ? (t5 = /* @__PURE__ */ jsx(CallbackComponent, { ...props }), $[10] = CallbackComponent, $[11] = props, $[12] = t5) : t5 = $[12], t5;
|
|
197
|
+
}
|
|
198
|
+
case AuthStateType.LOGGED_IN:
|
|
199
|
+
return children;
|
|
200
|
+
case AuthStateType.LOGGED_OUT:
|
|
201
|
+
return null;
|
|
202
|
+
default:
|
|
203
|
+
throw new Error(`Invalid auth state: ${authState.type}`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
const DEFAULT_FALLBACK = /* @__PURE__ */ jsx(Fragment, { children: "Warning: No fallback provided. Please supply a fallback prop to ensure proper Suspense handling." });
|
|
207
|
+
function ResourceProvider(t0) {
|
|
208
|
+
const $ = c(16);
|
|
209
|
+
let children, config, fallback;
|
|
210
|
+
$[0] !== t0 ? ({
|
|
211
|
+
children,
|
|
212
|
+
fallback,
|
|
213
|
+
...config
|
|
214
|
+
} = t0, $[0] = t0, $[1] = children, $[2] = config, $[3] = fallback) : (children = $[1], config = $[2], fallback = $[3]);
|
|
215
|
+
const parent = useContext(SanityInstanceContext);
|
|
216
|
+
let t1, t2;
|
|
217
|
+
$[4] !== config || $[5] !== parent ? (t2 = parent ? parent.createChild(config) : createSanityInstance(config), $[4] = config, $[5] = parent, $[6] = t2) : t2 = $[6], t1 = t2;
|
|
218
|
+
const instance = t1, disposal = useRef(null);
|
|
219
|
+
let t3, t4;
|
|
220
|
+
$[7] !== instance ? (t3 = () => (disposal.current !== null && instance === disposal.current.instance && (clearTimeout(disposal.current.timeoutId), disposal.current = null), () => {
|
|
221
|
+
disposal.current = {
|
|
222
|
+
instance,
|
|
223
|
+
timeoutId: setTimeout(() => {
|
|
224
|
+
instance.isDisposed() || instance.dispose();
|
|
225
|
+
}, 0)
|
|
226
|
+
};
|
|
227
|
+
}), t4 = [instance], $[7] = instance, $[8] = t3, $[9] = t4) : (t3 = $[8], t4 = $[9]), useEffect(t3, t4);
|
|
228
|
+
const t5 = fallback ?? DEFAULT_FALLBACK;
|
|
229
|
+
let t6;
|
|
230
|
+
$[10] !== children || $[11] !== t5 ? (t6 = /* @__PURE__ */ jsx(Suspense, { fallback: t5, children }), $[10] = children, $[11] = t5, $[12] = t6) : t6 = $[12];
|
|
231
|
+
let t7;
|
|
232
|
+
return $[13] !== instance || $[14] !== t6 ? (t7 = /* @__PURE__ */ jsx(SanityInstanceContext.Provider, { value: instance, children: t6 }), $[13] = instance, $[14] = t6, $[15] = t7) : t7 = $[15], t7;
|
|
233
|
+
}
|
|
234
|
+
function SDKProvider({
|
|
235
|
+
children,
|
|
236
|
+
config,
|
|
237
|
+
fallback,
|
|
238
|
+
...props
|
|
239
|
+
}) {
|
|
240
|
+
const configs = (Array.isArray(config) ? config : [config]).slice().reverse(), projectIds = configs.map((c2) => c2.projectId).filter((id) => !!id), createNestedProviders = (index) => index >= configs.length ? /* @__PURE__ */ jsx(AuthBoundary, { ...props, projectIds, children }) : /* @__PURE__ */ jsx(ResourceProvider, { ...configs[index], fallback, children: createNestedProviders(index + 1) });
|
|
241
|
+
return createNestedProviders(0);
|
|
242
|
+
}
|
|
243
|
+
const REDIRECT_URL = "https://sanity.io/welcome";
|
|
244
|
+
function SanityApp(t0) {
|
|
245
|
+
const $ = c(13);
|
|
246
|
+
let children, fallback, props, t1;
|
|
247
|
+
$[0] !== t0 ? ({
|
|
248
|
+
children,
|
|
249
|
+
fallback,
|
|
250
|
+
config: t1,
|
|
251
|
+
...props
|
|
252
|
+
} = t0, $[0] = t0, $[1] = children, $[2] = fallback, $[3] = props, $[4] = t1) : (children = $[1], fallback = $[2], props = $[3], t1 = $[4]);
|
|
253
|
+
let t2;
|
|
254
|
+
$[5] !== t1 ? (t2 = t1 === void 0 ? [] : t1, $[5] = t1, $[6] = t2) : t2 = $[6];
|
|
255
|
+
const config = t2;
|
|
256
|
+
let t3;
|
|
257
|
+
$[7] === Symbol.for("react.memo_cache_sentinel") ? (t3 = [], $[7] = t3) : t3 = $[7], useEffect(_temp2$1, t3);
|
|
258
|
+
let t4;
|
|
259
|
+
return $[8] !== children || $[9] !== config || $[10] !== fallback || $[11] !== props ? (t4 = /* @__PURE__ */ jsx(SDKProvider, { ...props, fallback, config, children }), $[8] = children, $[9] = config, $[10] = fallback, $[11] = props, $[12] = t4) : t4 = $[12], t4;
|
|
260
|
+
}
|
|
261
|
+
function _temp2$1() {
|
|
262
|
+
let timeout;
|
|
263
|
+
return !isInIframe() && !isLocalUrl(window) && (timeout = setTimeout(_temp$5, 1e3)), () => clearTimeout(timeout);
|
|
264
|
+
}
|
|
265
|
+
function _temp$5() {
|
|
266
|
+
console.warn("Redirecting to core", REDIRECT_URL), window.location.replace(REDIRECT_URL);
|
|
267
|
+
}
|
|
268
|
+
const useAuthToken = createStateSourceHook(getTokenState), useCurrentUser = createStateSourceHook(getCurrentUserState);
|
|
269
|
+
function useDashboardOrganizationId() {
|
|
270
|
+
const $ = c(2), instance = useSanityInstance();
|
|
271
|
+
let t0, t1;
|
|
272
|
+
$[0] !== instance ? (t1 = getDashboardOrganizationId(instance), $[0] = instance, $[1] = t1) : t1 = $[1], t0 = t1;
|
|
273
|
+
const {
|
|
274
|
+
subscribe,
|
|
275
|
+
getCurrent
|
|
276
|
+
} = t0;
|
|
277
|
+
return useSyncExternalStore(subscribe, getCurrent);
|
|
278
|
+
}
|
|
279
|
+
const useClient = createStateSourceHook({
|
|
280
|
+
getState: getClientState,
|
|
281
|
+
getConfig: identity
|
|
282
|
+
});
|
|
283
|
+
function useFrameConnection(options) {
|
|
284
|
+
const $ = c(12), {
|
|
285
|
+
onMessage,
|
|
286
|
+
targetOrigin,
|
|
287
|
+
name,
|
|
288
|
+
connectTo,
|
|
289
|
+
heartbeat,
|
|
290
|
+
onStatus
|
|
291
|
+
} = options, instance = useSanityInstance(), controllerRef = useRef(null), channelRef = useRef(null);
|
|
292
|
+
let t0, t1;
|
|
293
|
+
$[0] !== connectTo || $[1] !== heartbeat || $[2] !== instance || $[3] !== name || $[4] !== onMessage || $[5] !== onStatus || $[6] !== targetOrigin ? (t0 = () => {
|
|
294
|
+
const controller = getOrCreateController(instance, targetOrigin), channel = getOrCreateChannel(instance, {
|
|
295
|
+
name,
|
|
296
|
+
connectTo,
|
|
297
|
+
heartbeat
|
|
298
|
+
});
|
|
299
|
+
controllerRef.current = controller, channelRef.current = channel, channel.onStatus((event) => {
|
|
300
|
+
onStatus?.(event.status);
|
|
301
|
+
});
|
|
302
|
+
const messageUnsubscribers = [];
|
|
303
|
+
return onMessage && Object.entries(onMessage).forEach((t22) => {
|
|
304
|
+
const [type, handler] = t22, unsubscribe = channel.on(type, handler);
|
|
305
|
+
messageUnsubscribers.push(unsubscribe);
|
|
306
|
+
}), () => {
|
|
307
|
+
messageUnsubscribers.forEach(_temp$4), releaseChannel(instance, name), channelRef.current = null, controllerRef.current = null;
|
|
308
|
+
};
|
|
309
|
+
}, t1 = [targetOrigin, name, connectTo, heartbeat, onMessage, instance, onStatus], $[0] = connectTo, $[1] = heartbeat, $[2] = instance, $[3] = name, $[4] = onMessage, $[5] = onStatus, $[6] = targetOrigin, $[7] = t0, $[8] = t1) : (t0 = $[7], t1 = $[8]), useEffect(t0, t1);
|
|
310
|
+
let t2;
|
|
311
|
+
$[9] === Symbol.for("react.memo_cache_sentinel") ? (t2 = (frameWindow) => {
|
|
312
|
+
const removeTarget = controllerRef.current?.addTarget(frameWindow);
|
|
313
|
+
return () => {
|
|
314
|
+
removeTarget?.();
|
|
315
|
+
};
|
|
316
|
+
}, $[9] = t2) : t2 = $[9];
|
|
317
|
+
const connect = t2;
|
|
318
|
+
let t3;
|
|
319
|
+
$[10] === Symbol.for("react.memo_cache_sentinel") ? (t3 = (type_0, data) => {
|
|
320
|
+
channelRef.current?.post(type_0, data);
|
|
321
|
+
}, $[10] = t3) : t3 = $[10];
|
|
322
|
+
const sendMessage = t3;
|
|
323
|
+
let t4;
|
|
324
|
+
return $[11] === Symbol.for("react.memo_cache_sentinel") ? (t4 = {
|
|
325
|
+
connect,
|
|
326
|
+
sendMessage
|
|
327
|
+
}, $[11] = t4) : t4 = $[11], t4;
|
|
328
|
+
}
|
|
329
|
+
function _temp$4(unsub) {
|
|
330
|
+
return unsub();
|
|
331
|
+
}
|
|
332
|
+
function useWindowConnection(t0) {
|
|
333
|
+
const $ = c(11), {
|
|
334
|
+
name,
|
|
335
|
+
connectTo,
|
|
336
|
+
onMessage,
|
|
337
|
+
onStatus
|
|
338
|
+
} = t0, nodeRef = useRef(null);
|
|
339
|
+
let t1;
|
|
340
|
+
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = [], $[0] = t1) : t1 = $[0];
|
|
341
|
+
const messageUnsubscribers = useRef(t1), instance = useSanityInstance();
|
|
342
|
+
let t2, t3;
|
|
343
|
+
$[1] !== connectTo || $[2] !== instance || $[3] !== name || $[4] !== onMessage || $[5] !== onStatus ? (t2 = () => {
|
|
344
|
+
const node = getOrCreateNode(instance, {
|
|
345
|
+
name,
|
|
346
|
+
connectTo
|
|
347
|
+
});
|
|
348
|
+
nodeRef.current = node;
|
|
349
|
+
const statusUnsubscribe = node.onStatus((eventStatus) => {
|
|
350
|
+
onStatus?.(eventStatus);
|
|
351
|
+
});
|
|
352
|
+
return onMessage && Object.entries(onMessage).forEach((t42) => {
|
|
353
|
+
const [type, handler] = t42, messageUnsubscribe = node.on(type, handler);
|
|
354
|
+
messageUnsubscribers.current.push(messageUnsubscribe);
|
|
355
|
+
}), () => {
|
|
356
|
+
statusUnsubscribe(), messageUnsubscribers.current.forEach(_temp$3), messageUnsubscribers.current = [], releaseNode(instance, name), nodeRef.current = null;
|
|
357
|
+
};
|
|
358
|
+
}, t3 = [instance, name, connectTo, onMessage, onStatus], $[1] = connectTo, $[2] = instance, $[3] = name, $[4] = onMessage, $[5] = onStatus, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]), useEffect(t2, t3);
|
|
359
|
+
let t4;
|
|
360
|
+
$[8] === Symbol.for("react.memo_cache_sentinel") ? (t4 = (type_0, data) => {
|
|
361
|
+
if (!nodeRef.current)
|
|
362
|
+
throw new Error("Cannot send message before connection is established");
|
|
363
|
+
nodeRef.current.post(type_0, data);
|
|
364
|
+
}, $[8] = t4) : t4 = $[8];
|
|
365
|
+
const sendMessage = t4;
|
|
366
|
+
let t5;
|
|
367
|
+
$[9] === Symbol.for("react.memo_cache_sentinel") ? (t5 = (type_1, data_0, fetchOptions) => {
|
|
368
|
+
if (!nodeRef.current)
|
|
369
|
+
throw new Error("Cannot fetch before connection is established");
|
|
370
|
+
return nodeRef.current?.fetch(type_1, data_0, fetchOptions ?? {});
|
|
371
|
+
}, $[9] = t5) : t5 = $[9];
|
|
372
|
+
const fetch = t5;
|
|
373
|
+
let t6;
|
|
374
|
+
return $[10] === Symbol.for("react.memo_cache_sentinel") ? (t6 = {
|
|
375
|
+
sendMessage,
|
|
376
|
+
fetch
|
|
377
|
+
}, $[10] = t6) : t6 = $[10], t6;
|
|
378
|
+
}
|
|
379
|
+
function _temp$3(unsubscribe) {
|
|
380
|
+
return unsubscribe();
|
|
381
|
+
}
|
|
382
|
+
function useManageFavorite({
|
|
383
|
+
documentId,
|
|
384
|
+
documentType,
|
|
385
|
+
projectId: paramProjectId,
|
|
386
|
+
dataset: paramDataset,
|
|
387
|
+
resourceId: paramResourceId,
|
|
388
|
+
resourceType,
|
|
389
|
+
schemaName
|
|
390
|
+
}) {
|
|
391
|
+
const [status, setStatus] = useState("idle"), {
|
|
392
|
+
fetch
|
|
393
|
+
} = useWindowConnection({
|
|
394
|
+
name: SDK_NODE_NAME,
|
|
395
|
+
connectTo: SDK_CHANNEL_NAME,
|
|
396
|
+
onStatus: setStatus
|
|
397
|
+
}), instance = useSanityInstance(), {
|
|
398
|
+
config
|
|
399
|
+
} = instance, instanceProjectId = config?.projectId, instanceDataset = config?.dataset, projectId = paramProjectId ?? instanceProjectId, dataset = paramDataset ?? instanceDataset;
|
|
400
|
+
if (resourceType === "studio" && (!projectId || !dataset))
|
|
401
|
+
throw new Error("projectId and dataset are required for studio resources");
|
|
402
|
+
const resourceId = resourceType === "studio" && !paramResourceId ? `${projectId}.${dataset}` : paramResourceId;
|
|
403
|
+
if (!resourceId)
|
|
404
|
+
throw new Error("resourceId is required for media-library and canvas resources");
|
|
405
|
+
const context = useMemo(() => ({
|
|
406
|
+
documentId,
|
|
407
|
+
documentType,
|
|
408
|
+
resourceId,
|
|
409
|
+
resourceType,
|
|
410
|
+
schemaName
|
|
411
|
+
}), [documentId, documentType, resourceId, resourceType, schemaName]), favoriteState = getFavoritesState(instance, context), state = useSyncExternalStore(favoriteState.subscribe, favoriteState.getCurrent), isFavorited = state?.isFavorited ?? !1, handleFavoriteAction = useCallback(async (action) => {
|
|
412
|
+
if (!(status !== "connected" || !fetch || !documentId || !documentType || !resourceType))
|
|
413
|
+
try {
|
|
414
|
+
const payload = {
|
|
415
|
+
eventType: action,
|
|
416
|
+
document: {
|
|
417
|
+
id: documentId,
|
|
418
|
+
type: documentType,
|
|
419
|
+
resource: {
|
|
420
|
+
id: resourceId,
|
|
421
|
+
type: resourceType,
|
|
422
|
+
...schemaName ? {
|
|
423
|
+
schemaName
|
|
424
|
+
} : {}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
(await fetch("dashboard/v1/events/favorite/mutate", payload)).success && await resolveFavoritesState(instance, context);
|
|
429
|
+
} catch (err) {
|
|
430
|
+
throw console.error(`Failed to ${action === "added" ? "favorite" : "unfavorite"} document:`, err), err;
|
|
431
|
+
}
|
|
432
|
+
}, [fetch, documentId, documentType, resourceId, resourceType, schemaName, instance, context, status]), favorite = useCallback(() => handleFavoriteAction("added"), [handleFavoriteAction]), unfavorite = useCallback(() => handleFavoriteAction("removed"), [handleFavoriteAction]);
|
|
433
|
+
if (!state)
|
|
434
|
+
try {
|
|
435
|
+
throw resolveFavoritesState(instance, context);
|
|
436
|
+
} catch (err_0) {
|
|
437
|
+
if (err_0 instanceof Error && err_0.message === "Favorites service connection timeout")
|
|
438
|
+
return {
|
|
439
|
+
favorite: async () => {
|
|
440
|
+
},
|
|
441
|
+
unfavorite: async () => {
|
|
442
|
+
},
|
|
443
|
+
isFavorited: !1,
|
|
444
|
+
isConnected: !1
|
|
445
|
+
};
|
|
446
|
+
throw err_0;
|
|
447
|
+
}
|
|
448
|
+
return {
|
|
449
|
+
favorite,
|
|
450
|
+
unfavorite,
|
|
451
|
+
isFavorited,
|
|
452
|
+
isConnected: status === "connected"
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
function useRecordDocumentHistoryEvent(t0) {
|
|
456
|
+
const $ = c(11), {
|
|
457
|
+
documentId,
|
|
458
|
+
documentType,
|
|
459
|
+
resourceType,
|
|
460
|
+
resourceId,
|
|
461
|
+
schemaName
|
|
462
|
+
} = t0, [status, setStatus] = useState("idle");
|
|
463
|
+
let t1;
|
|
464
|
+
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = {
|
|
465
|
+
name: SDK_NODE_NAME,
|
|
466
|
+
connectTo: SDK_CHANNEL_NAME,
|
|
467
|
+
onStatus: setStatus
|
|
468
|
+
}, $[0] = t1) : t1 = $[0];
|
|
469
|
+
const {
|
|
470
|
+
sendMessage
|
|
471
|
+
} = useWindowConnection(t1);
|
|
472
|
+
if (resourceType !== "studio" && !resourceId)
|
|
473
|
+
throw new Error("resourceId is required for media-library and canvas resources");
|
|
474
|
+
let t2;
|
|
475
|
+
$[1] !== documentId || $[2] !== documentType || $[3] !== resourceId || $[4] !== resourceType || $[5] !== schemaName || $[6] !== sendMessage ? (t2 = (eventType) => {
|
|
476
|
+
try {
|
|
477
|
+
const message = {
|
|
478
|
+
type: "dashboard/v1/events/history",
|
|
479
|
+
data: {
|
|
480
|
+
eventType,
|
|
481
|
+
document: {
|
|
482
|
+
id: documentId,
|
|
483
|
+
type: documentType,
|
|
484
|
+
resource: {
|
|
485
|
+
id: resourceId,
|
|
486
|
+
type: resourceType,
|
|
487
|
+
schemaName
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
sendMessage(message.type, message.data);
|
|
493
|
+
} catch (t32) {
|
|
494
|
+
const error = t32;
|
|
495
|
+
throw console.error("Failed to record history event:", error), error;
|
|
496
|
+
}
|
|
497
|
+
}, $[1] = documentId, $[2] = documentType, $[3] = resourceId, $[4] = resourceType, $[5] = schemaName, $[6] = sendMessage, $[7] = t2) : t2 = $[7];
|
|
498
|
+
const recordEvent = t2, t3 = status === "connected";
|
|
499
|
+
let t4;
|
|
500
|
+
return $[8] !== recordEvent || $[9] !== t3 ? (t4 = {
|
|
501
|
+
recordEvent,
|
|
502
|
+
isConnected: t3
|
|
503
|
+
}, $[8] = recordEvent, $[9] = t3, $[10] = t4) : t4 = $[10], t4;
|
|
504
|
+
}
|
|
505
|
+
function useStudioWorkspacesByProjectIdDataset() {
|
|
506
|
+
const $ = c(10);
|
|
507
|
+
let t0;
|
|
508
|
+
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = {}, $[0] = t0) : t0 = $[0];
|
|
509
|
+
const [workspacesByProjectIdAndDataset, setWorkspacesByProjectIdAndDataset] = useState(t0), [status, setStatus] = useState("idle"), [error, setError] = useState(null);
|
|
510
|
+
let t1;
|
|
511
|
+
$[1] === Symbol.for("react.memo_cache_sentinel") ? (t1 = {
|
|
512
|
+
name: SDK_NODE_NAME,
|
|
513
|
+
connectTo: SDK_CHANNEL_NAME,
|
|
514
|
+
onStatus: setStatus
|
|
515
|
+
}, $[1] = t1) : t1 = $[1];
|
|
516
|
+
const {
|
|
517
|
+
fetch
|
|
518
|
+
} = useWindowConnection(t1);
|
|
519
|
+
let t2, t3;
|
|
520
|
+
$[2] !== fetch || $[3] !== status ? (t2 = () => {
|
|
521
|
+
if (!fetch || status !== "connected")
|
|
522
|
+
return;
|
|
523
|
+
const fetchWorkspaces = async function(signal) {
|
|
524
|
+
try {
|
|
525
|
+
const data = await fetch("dashboard/v1/bridge/context", void 0, {
|
|
526
|
+
signal
|
|
527
|
+
}), workspaceMap = {}, noProjectIdAndDataset = [];
|
|
528
|
+
data.context.availableResources.forEach((resource) => {
|
|
529
|
+
if (resource.type !== "studio")
|
|
530
|
+
return;
|
|
531
|
+
if (!resource.projectId || !resource.dataset) {
|
|
532
|
+
noProjectIdAndDataset.push(resource);
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
const key = `${resource.projectId}:${resource.dataset}`;
|
|
536
|
+
workspaceMap[key] || (workspaceMap[key] = []), workspaceMap[key].push(resource);
|
|
537
|
+
}), noProjectIdAndDataset.length > 0 && (workspaceMap["NO_PROJECT_ID:NO_DATASET"] = noProjectIdAndDataset), setWorkspacesByProjectIdAndDataset(workspaceMap), setError(null);
|
|
538
|
+
} catch (t42) {
|
|
539
|
+
const err = t42;
|
|
540
|
+
if (err instanceof Error) {
|
|
541
|
+
if (err.name === "AbortError")
|
|
542
|
+
return;
|
|
543
|
+
setError("Failed to fetch workspaces");
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}, controller = new AbortController();
|
|
547
|
+
return fetchWorkspaces(controller.signal), () => {
|
|
548
|
+
controller.abort();
|
|
549
|
+
};
|
|
550
|
+
}, t3 = [fetch, status], $[2] = fetch, $[3] = status, $[4] = t2, $[5] = t3) : (t2 = $[4], t3 = $[5]), useEffect(t2, t3);
|
|
551
|
+
const t4 = status === "connected";
|
|
552
|
+
let t5;
|
|
553
|
+
return $[6] !== error || $[7] !== t4 || $[8] !== workspacesByProjectIdAndDataset ? (t5 = {
|
|
554
|
+
workspacesByProjectIdAndDataset,
|
|
555
|
+
error,
|
|
556
|
+
isConnected: t4
|
|
557
|
+
}, $[6] = error, $[7] = t4, $[8] = workspacesByProjectIdAndDataset, $[9] = t5) : t5 = $[9], t5;
|
|
558
|
+
}
|
|
559
|
+
function useNavigateToStudioDocument(documentHandle, preferredStudioUrl) {
|
|
560
|
+
const $ = c(11), {
|
|
561
|
+
workspacesByProjectIdAndDataset,
|
|
562
|
+
isConnected: workspacesConnected
|
|
563
|
+
} = useStudioWorkspacesByProjectIdDataset(), [status, setStatus] = useState("idle");
|
|
564
|
+
let t0;
|
|
565
|
+
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = {
|
|
566
|
+
name: SDK_NODE_NAME,
|
|
567
|
+
connectTo: SDK_CHANNEL_NAME,
|
|
568
|
+
onStatus: setStatus
|
|
569
|
+
}, $[0] = t0) : t0 = $[0];
|
|
570
|
+
const {
|
|
571
|
+
sendMessage
|
|
572
|
+
} = useWindowConnection(t0);
|
|
573
|
+
let t1;
|
|
574
|
+
$[1] !== documentHandle || $[2] !== preferredStudioUrl || $[3] !== sendMessage || $[4] !== status || $[5] !== workspacesByProjectIdAndDataset || $[6] !== workspacesConnected ? (t1 = () => {
|
|
575
|
+
const {
|
|
576
|
+
projectId,
|
|
577
|
+
dataset
|
|
578
|
+
} = documentHandle;
|
|
579
|
+
if (!workspacesConnected || status !== "connected") {
|
|
580
|
+
console.warn("Not connected to Dashboard");
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
if (!projectId || !dataset) {
|
|
584
|
+
console.warn("Project ID and dataset are required to navigate to a studio document");
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
let workspace;
|
|
588
|
+
if (preferredStudioUrl)
|
|
589
|
+
workspace = [...workspacesByProjectIdAndDataset[`${projectId}:${dataset}`] || [], ...workspacesByProjectIdAndDataset["NO_PROJECT_ID:NO_DATASET"] || []].find((w) => w.url === preferredStudioUrl);
|
|
590
|
+
else {
|
|
591
|
+
const workspaces = workspacesByProjectIdAndDataset[`${projectId}:${dataset}`];
|
|
592
|
+
workspaces?.length > 1 && (console.warn("Multiple workspaces found for document and no preferred studio url", documentHandle), console.warn("Using the first one", workspaces[0])), workspace = workspaces?.[0];
|
|
593
|
+
}
|
|
594
|
+
if (!workspace) {
|
|
595
|
+
console.warn(`No workspace found for document with projectId: ${projectId} and dataset: ${dataset}${preferredStudioUrl ? ` or with preferred studio url: ${preferredStudioUrl}` : ""}`);
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
const message = {
|
|
599
|
+
type: "dashboard/v1/bridge/navigate-to-resource",
|
|
600
|
+
data: {
|
|
601
|
+
resourceId: workspace.id,
|
|
602
|
+
resourceType: "studio",
|
|
603
|
+
path: `/intent/edit/id=${documentHandle.documentId};type=${documentHandle.documentType}`
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
sendMessage(message.type, message.data);
|
|
607
|
+
}, $[1] = documentHandle, $[2] = preferredStudioUrl, $[3] = sendMessage, $[4] = status, $[5] = workspacesByProjectIdAndDataset, $[6] = workspacesConnected, $[7] = t1) : t1 = $[7];
|
|
608
|
+
const navigateToStudioDocument = t1, t2 = workspacesConnected && status === "connected";
|
|
609
|
+
let t3;
|
|
610
|
+
return $[8] !== navigateToStudioDocument || $[9] !== t2 ? (t3 = {
|
|
611
|
+
navigateToStudioDocument,
|
|
612
|
+
isConnected: t2
|
|
613
|
+
}, $[8] = navigateToStudioDocument, $[9] = t2, $[10] = t3) : t3 = $[10], t3;
|
|
614
|
+
}
|
|
615
|
+
const useDatasets = createStateSourceHook({
|
|
616
|
+
getState: getDatasetsState,
|
|
617
|
+
shouldSuspend: (instance, projectHandle) => (
|
|
618
|
+
// remove `undefined` since we're suspending when that is the case
|
|
619
|
+
getDatasetsState(instance, projectHandle).getCurrent() === void 0
|
|
620
|
+
),
|
|
621
|
+
suspender: resolveDatasets,
|
|
622
|
+
getConfig: identity
|
|
623
|
+
}), useApplyDocumentActions = createCallbackHook(applyDocumentActions), useDocument = createStateSourceHook({
|
|
624
|
+
// Pass options directly to getDocumentState
|
|
625
|
+
getState: (instance, options) => getDocumentState(instance, options),
|
|
626
|
+
// Pass options directly to getDocumentState for checking current value
|
|
627
|
+
shouldSuspend: (instance, {
|
|
628
|
+
path: _path,
|
|
629
|
+
...options
|
|
630
|
+
}) => getDocumentState(instance, options).getCurrent() === void 0,
|
|
631
|
+
// Extract handle part for resolveDocument
|
|
632
|
+
suspender: (instance, options) => resolveDocument(instance, options),
|
|
633
|
+
getConfig: identity
|
|
634
|
+
});
|
|
635
|
+
function useDocumentEvent(options) {
|
|
636
|
+
const $ = c(9);
|
|
637
|
+
let datasetHandle, onEvent;
|
|
638
|
+
$[0] !== options ? ({
|
|
639
|
+
onEvent,
|
|
640
|
+
...datasetHandle
|
|
641
|
+
} = options, $[0] = options, $[1] = datasetHandle, $[2] = onEvent) : (datasetHandle = $[1], onEvent = $[2]);
|
|
642
|
+
const ref = useRef(onEvent);
|
|
643
|
+
let t0;
|
|
644
|
+
$[3] !== onEvent ? (t0 = () => {
|
|
645
|
+
ref.current = onEvent;
|
|
646
|
+
}, $[3] = onEvent, $[4] = t0) : t0 = $[4], useInsertionEffect(t0);
|
|
647
|
+
let t1;
|
|
648
|
+
$[5] === Symbol.for("react.memo_cache_sentinel") ? (t1 = (documentEvent) => ref.current(documentEvent), $[5] = t1) : t1 = $[5];
|
|
649
|
+
const stableHandler = t1, instance = useSanityInstance(datasetHandle);
|
|
650
|
+
let t2, t3;
|
|
651
|
+
$[6] !== instance ? (t2 = () => subscribeDocumentEvents(instance, stableHandler), t3 = [instance, stableHandler], $[6] = instance, $[7] = t2, $[8] = t3) : (t2 = $[7], t3 = $[8]), useEffect(t2, t3);
|
|
652
|
+
}
|
|
653
|
+
function useDocumentPermissions(actionOrActions) {
|
|
654
|
+
const $ = c(13);
|
|
655
|
+
let t0;
|
|
656
|
+
$[0] !== actionOrActions ? (t0 = Array.isArray(actionOrActions) ? actionOrActions : [actionOrActions], $[0] = actionOrActions, $[1] = t0) : t0 = $[1];
|
|
657
|
+
const actions = t0;
|
|
658
|
+
let projectId, dataset;
|
|
659
|
+
if ($[2] !== actions || $[3] !== dataset || $[4] !== projectId) {
|
|
660
|
+
for (const action of actions)
|
|
661
|
+
if (action.projectId) {
|
|
662
|
+
if (projectId || (projectId = action.projectId), action.projectId !== projectId)
|
|
663
|
+
throw new Error(`Mismatched project IDs found in actions. All actions must belong to the same project. Found "${action.projectId}" but expected "${projectId}".`);
|
|
664
|
+
if (action.dataset && (dataset || (dataset = action.dataset), action.dataset !== dataset))
|
|
665
|
+
throw new Error(`Mismatched datasets found in actions. All actions must belong to the same dataset. Found "${action.dataset}" but expected "${dataset}".`);
|
|
666
|
+
}
|
|
667
|
+
$[2] = actions, $[3] = dataset, $[4] = projectId, $[5] = projectId, $[6] = dataset;
|
|
668
|
+
} else
|
|
669
|
+
projectId = $[5], dataset = $[6];
|
|
670
|
+
let t1;
|
|
671
|
+
$[7] !== dataset || $[8] !== projectId ? (t1 = {
|
|
672
|
+
projectId,
|
|
673
|
+
dataset
|
|
674
|
+
}, $[7] = dataset, $[8] = projectId, $[9] = t1) : t1 = $[9];
|
|
675
|
+
const instance = useSanityInstance(t1);
|
|
676
|
+
if (getPermissionsState(instance, actionOrActions).getCurrent() === void 0)
|
|
677
|
+
throw firstValueFrom(getPermissionsState(instance, actionOrActions).observable.pipe(filter(_temp$2)));
|
|
678
|
+
let t2, t3;
|
|
679
|
+
$[10] !== actionOrActions || $[11] !== instance ? (t3 = getPermissionsState(instance, actionOrActions), $[10] = actionOrActions, $[11] = instance, $[12] = t3) : t3 = $[12], t2 = t3;
|
|
680
|
+
const {
|
|
681
|
+
subscribe,
|
|
682
|
+
getCurrent
|
|
683
|
+
} = t2;
|
|
684
|
+
return useSyncExternalStore(subscribe, getCurrent);
|
|
685
|
+
}
|
|
686
|
+
function _temp$2(result) {
|
|
687
|
+
return result !== void 0;
|
|
688
|
+
}
|
|
689
|
+
const useDocumentSyncStatus = createStateSourceHook({
|
|
690
|
+
getState: getDocumentSyncStatus,
|
|
691
|
+
shouldSuspend: (instance, doc) => getDocumentSyncStatus(instance, doc).getCurrent() === void 0,
|
|
692
|
+
suspender: (instance, doc) => resolveDocument(instance, doc),
|
|
693
|
+
getConfig: identity
|
|
694
|
+
}), ignoredKeys = ["_id", "_type", "_createdAt", "_updatedAt", "_rev"];
|
|
695
|
+
function useEditDocument(t0) {
|
|
696
|
+
const $ = c(8);
|
|
697
|
+
let doc, path;
|
|
698
|
+
$[0] !== t0 ? ({
|
|
699
|
+
path,
|
|
700
|
+
...doc
|
|
701
|
+
} = t0, $[0] = t0, $[1] = doc, $[2] = path) : (doc = $[1], path = $[2]);
|
|
702
|
+
const instance = useSanityInstance(doc), apply = useApplyDocumentActions();
|
|
703
|
+
if (getDocumentState(instance, doc).getCurrent() === void 0)
|
|
704
|
+
throw resolveDocument(instance, doc);
|
|
705
|
+
let t1;
|
|
706
|
+
return $[3] !== apply || $[4] !== doc || $[5] !== instance || $[6] !== path ? (t1 = (updater) => {
|
|
707
|
+
const currentPath = path;
|
|
708
|
+
if (currentPath) {
|
|
709
|
+
const currentValue = getDocumentState(instance, {
|
|
710
|
+
...doc,
|
|
711
|
+
path
|
|
712
|
+
}).getCurrent(), nextValue = typeof updater == "function" ? updater(currentValue) : updater;
|
|
713
|
+
return apply(editDocument(doc, {
|
|
714
|
+
set: {
|
|
715
|
+
[currentPath]: nextValue
|
|
716
|
+
}
|
|
717
|
+
}));
|
|
718
|
+
}
|
|
719
|
+
const current = getDocumentState(instance, {
|
|
720
|
+
...doc,
|
|
721
|
+
path
|
|
722
|
+
}).getCurrent(), nextValue_0 = typeof updater == "function" ? updater(current) : updater;
|
|
723
|
+
if (typeof nextValue_0 != "object" || !nextValue_0)
|
|
724
|
+
throw new Error("No path was provided to `useEditDocument` and the value provided was not a document object.");
|
|
725
|
+
const editActions = Object.keys({
|
|
726
|
+
...current,
|
|
727
|
+
...nextValue_0
|
|
728
|
+
}).filter(_temp$1).filter((key_0) => current?.[key_0] !== nextValue_0[key_0]).map((key_1) => key_1 in nextValue_0 ? editDocument(doc, {
|
|
729
|
+
set: {
|
|
730
|
+
[key_1]: nextValue_0[key_1]
|
|
731
|
+
}
|
|
732
|
+
}) : editDocument(doc, {
|
|
733
|
+
unset: [key_1]
|
|
734
|
+
}));
|
|
735
|
+
return apply(editActions);
|
|
736
|
+
}, $[3] = apply, $[4] = doc, $[5] = instance, $[6] = path, $[7] = t1) : t1 = $[7], t1;
|
|
737
|
+
}
|
|
738
|
+
function _temp$1(key) {
|
|
739
|
+
return !ignoredKeys.includes(key);
|
|
740
|
+
}
|
|
741
|
+
function useQuery(options) {
|
|
742
|
+
const instance = useSanityInstance(options), [isPending, startTransition] = useTransition(), queryKey = getQueryKey(options), [deferredQueryKey, setDeferredQueryKey] = useState(queryKey), deferred = useMemo(() => parseQueryKey(deferredQueryKey), [deferredQueryKey]), ref = useRef(new AbortController());
|
|
743
|
+
useEffect(() => {
|
|
744
|
+
queryKey !== deferredQueryKey && startTransition(() => {
|
|
745
|
+
ref && !ref.current.signal.aborted && (ref.current.abort(), ref.current = new AbortController()), setDeferredQueryKey(queryKey);
|
|
746
|
+
});
|
|
747
|
+
}, [deferredQueryKey, queryKey]);
|
|
748
|
+
const {
|
|
749
|
+
getCurrent,
|
|
750
|
+
subscribe
|
|
751
|
+
} = useMemo(() => getQueryState(instance, deferred), [instance, deferred]);
|
|
752
|
+
if (getCurrent() === void 0) {
|
|
753
|
+
const currentSignal = ref.current.signal;
|
|
754
|
+
throw resolveQuery(instance, {
|
|
755
|
+
...deferred,
|
|
756
|
+
signal: currentSignal
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
const data = useSyncExternalStore(subscribe, getCurrent);
|
|
760
|
+
return useMemo(() => ({
|
|
761
|
+
data,
|
|
762
|
+
isPending
|
|
763
|
+
}), [data, isPending]);
|
|
764
|
+
}
|
|
765
|
+
const DEFAULT_BATCH_SIZE = 25;
|
|
766
|
+
function useDocuments({
|
|
767
|
+
batchSize = DEFAULT_BATCH_SIZE,
|
|
768
|
+
params,
|
|
769
|
+
search,
|
|
770
|
+
filter: filter2,
|
|
771
|
+
orderings,
|
|
772
|
+
documentType,
|
|
773
|
+
...options
|
|
774
|
+
}) {
|
|
775
|
+
const instance = useSanityInstance(options), [limit, setLimit] = useState(batchSize), documentTypes = useMemo(() => (Array.isArray(documentType) ? documentType : [documentType]).filter((i) => typeof i == "string"), [documentType]), key = JSON.stringify({
|
|
776
|
+
filter: filter2,
|
|
777
|
+
search,
|
|
778
|
+
params,
|
|
779
|
+
orderings,
|
|
780
|
+
batchSize,
|
|
781
|
+
types: documentTypes,
|
|
782
|
+
...options
|
|
783
|
+
});
|
|
784
|
+
useEffect(() => {
|
|
785
|
+
setLimit(batchSize);
|
|
786
|
+
}, [key, batchSize]);
|
|
787
|
+
const filterClause = useMemo(() => {
|
|
788
|
+
const conditions = [], trimmedSearch = search?.trim();
|
|
789
|
+
if (trimmedSearch) {
|
|
790
|
+
const searchFilter = createGroqSearchFilter(trimmedSearch);
|
|
791
|
+
searchFilter && conditions.push(searchFilter);
|
|
792
|
+
}
|
|
793
|
+
return documentTypes?.length && conditions.push("(_type in $__types)"), filter2 && conditions.push(`(${filter2})`), conditions.length ? `[${conditions.join(" && ")}]` : "";
|
|
794
|
+
}, [filter2, search, documentTypes]), orderClause = orderings ? `| order(${orderings.map((ordering) => [ordering.field, ordering.direction.toLowerCase()].map((str) => str.trim()).filter(Boolean).join(" ")).join(",")})` : "", dataQuery = `*${filterClause}${orderClause}[0...${limit}]{"documentId":_id,"documentType":_type,...$__handle}`, countQuery = `count(*${filterClause})`, {
|
|
795
|
+
data: {
|
|
796
|
+
count,
|
|
797
|
+
data
|
|
798
|
+
},
|
|
799
|
+
isPending
|
|
800
|
+
} = useQuery({
|
|
801
|
+
...options,
|
|
802
|
+
query: `{"count":${countQuery},"data":${dataQuery}}`,
|
|
803
|
+
params: {
|
|
804
|
+
...params,
|
|
805
|
+
__handle: {
|
|
806
|
+
...pick(instance.config, "projectId", "dataset", "perspective"),
|
|
807
|
+
...pick(options, "projectId", "dataset", "perspective")
|
|
808
|
+
},
|
|
809
|
+
__types: documentTypes
|
|
810
|
+
}
|
|
811
|
+
}), hasMore = data.length < count, loadMore = useCallback(() => {
|
|
812
|
+
setLimit((prev) => Math.min(prev + batchSize, count));
|
|
813
|
+
}, [count, batchSize]);
|
|
814
|
+
return useMemo(() => ({
|
|
815
|
+
data,
|
|
816
|
+
hasMore,
|
|
817
|
+
count,
|
|
818
|
+
isPending,
|
|
819
|
+
loadMore
|
|
820
|
+
}), [count, data, hasMore, isPending, loadMore]);
|
|
821
|
+
}
|
|
822
|
+
function usePaginatedDocuments(t0) {
|
|
823
|
+
const $ = c(62);
|
|
824
|
+
let documentType, options, orderings, search, t1, t2, t3;
|
|
825
|
+
$[0] !== t0 ? ({
|
|
826
|
+
documentType,
|
|
827
|
+
filter: t1,
|
|
828
|
+
pageSize: t2,
|
|
829
|
+
params: t3,
|
|
830
|
+
orderings,
|
|
831
|
+
search,
|
|
832
|
+
...options
|
|
833
|
+
} = t0, $[0] = t0, $[1] = documentType, $[2] = options, $[3] = orderings, $[4] = search, $[5] = t1, $[6] = t2, $[7] = t3) : (documentType = $[1], options = $[2], orderings = $[3], search = $[4], t1 = $[5], t2 = $[6], t3 = $[7]);
|
|
834
|
+
const filter2 = t1 === void 0 ? "" : t1, pageSize = t2 === void 0 ? 25 : t2;
|
|
835
|
+
let t4;
|
|
836
|
+
$[8] !== t3 ? (t4 = t3 === void 0 ? {} : t3, $[8] = t3, $[9] = t4) : t4 = $[9];
|
|
837
|
+
const params = t4, instance = useSanityInstance(options), [pageIndex, setPageIndex] = useState(0);
|
|
838
|
+
let t5;
|
|
839
|
+
$[10] !== filter2 || $[11] !== orderings || $[12] !== pageSize || $[13] !== params || $[14] !== search ? (t5 = JSON.stringify({
|
|
840
|
+
filter: filter2,
|
|
841
|
+
search,
|
|
842
|
+
params,
|
|
843
|
+
orderings,
|
|
844
|
+
pageSize
|
|
845
|
+
}), $[10] = filter2, $[11] = orderings, $[12] = pageSize, $[13] = params, $[14] = search, $[15] = t5) : t5 = $[15];
|
|
846
|
+
const key = t5;
|
|
847
|
+
let t6;
|
|
848
|
+
$[16] === Symbol.for("react.memo_cache_sentinel") ? (t6 = () => {
|
|
849
|
+
setPageIndex(0);
|
|
850
|
+
}, $[16] = t6) : t6 = $[16];
|
|
851
|
+
let t7;
|
|
852
|
+
$[17] !== key ? (t7 = [key], $[17] = key, $[18] = t7) : t7 = $[18], useEffect(t6, t7);
|
|
853
|
+
const startIndex = pageIndex * pageSize, endIndex = (pageIndex + 1) * pageSize;
|
|
854
|
+
let t8;
|
|
855
|
+
$[19] !== documentType ? (t8 = Array.isArray(documentType) ? documentType : [documentType], $[19] = documentType, $[20] = t8) : t8 = $[20];
|
|
856
|
+
let t9;
|
|
857
|
+
$[21] !== t8 ? (t9 = t8.filter(_temp), $[21] = t8, $[22] = t9) : t9 = $[22];
|
|
858
|
+
const documentTypes = t9;
|
|
859
|
+
let t10;
|
|
860
|
+
const conditions = [], trimmedSearch = search?.trim();
|
|
861
|
+
if (trimmedSearch) {
|
|
862
|
+
const searchFilter = createGroqSearchFilter(trimmedSearch);
|
|
863
|
+
searchFilter && conditions.push(searchFilter);
|
|
864
|
+
}
|
|
865
|
+
documentTypes?.length && conditions.push("(_type in $__types)"), filter2 && conditions.push(`(${filter2})`), t10 = conditions.length ? `[${conditions.join(" && ")}]` : "";
|
|
866
|
+
const filterClause = t10, orderClause = orderings ? `| order(${orderings.map(_temp3).join(",")})` : "", dataQuery = `*${filterClause}${orderClause}[${startIndex}...${endIndex}]{"documentId":_id,"documentType":_type,...$__handle}`, countQuery = `count(*${filterClause})`, t11 = `{"data":${dataQuery},"count":${countQuery}}`;
|
|
867
|
+
let t12;
|
|
868
|
+
$[23] !== instance.config ? (t12 = pick(instance.config, "projectId", "dataset", "perspective"), $[23] = instance.config, $[24] = t12) : t12 = $[24];
|
|
869
|
+
let t13;
|
|
870
|
+
$[25] !== options ? (t13 = pick(options, "projectId", "dataset", "perspective"), $[25] = options, $[26] = t13) : t13 = $[26];
|
|
871
|
+
let t14;
|
|
872
|
+
$[27] !== t12 || $[28] !== t13 ? (t14 = {
|
|
873
|
+
...t12,
|
|
874
|
+
...t13
|
|
875
|
+
}, $[27] = t12, $[28] = t13, $[29] = t14) : t14 = $[29];
|
|
876
|
+
let t15;
|
|
877
|
+
$[30] !== documentTypes || $[31] !== params || $[32] !== t14 ? (t15 = {
|
|
878
|
+
...params,
|
|
879
|
+
__types: documentTypes,
|
|
880
|
+
__handle: t14
|
|
881
|
+
}, $[30] = documentTypes, $[31] = params, $[32] = t14, $[33] = t15) : t15 = $[33];
|
|
882
|
+
let t16;
|
|
883
|
+
$[34] !== options || $[35] !== t11 || $[36] !== t15 ? (t16 = {
|
|
884
|
+
...options,
|
|
885
|
+
query: t11,
|
|
886
|
+
params: t15
|
|
887
|
+
}, $[34] = options, $[35] = t11, $[36] = t15, $[37] = t16) : t16 = $[37];
|
|
888
|
+
const {
|
|
889
|
+
data: t17,
|
|
890
|
+
isPending
|
|
891
|
+
} = useQuery(t16), {
|
|
892
|
+
data,
|
|
893
|
+
count
|
|
894
|
+
} = t17, totalPages = Math.ceil(count / pageSize), currentPage = pageIndex + 1;
|
|
895
|
+
let t18;
|
|
896
|
+
$[38] === Symbol.for("react.memo_cache_sentinel") ? (t18 = () => setPageIndex(0), $[38] = t18) : t18 = $[38];
|
|
897
|
+
const firstPage = t18;
|
|
898
|
+
let t19;
|
|
899
|
+
$[39] === Symbol.for("react.memo_cache_sentinel") ? (t19 = () => setPageIndex(_temp4), $[39] = t19) : t19 = $[39];
|
|
900
|
+
const previousPage = t19;
|
|
901
|
+
let t20;
|
|
902
|
+
$[40] !== totalPages ? (t20 = () => setPageIndex((prev_0) => Math.min(prev_0 + 1, totalPages - 1)), $[40] = totalPages, $[41] = t20) : t20 = $[41];
|
|
903
|
+
const nextPage = t20;
|
|
904
|
+
let t21;
|
|
905
|
+
$[42] !== totalPages ? (t21 = () => setPageIndex(totalPages - 1), $[42] = totalPages, $[43] = t21) : t21 = $[43];
|
|
906
|
+
const lastPage = t21;
|
|
907
|
+
let t22;
|
|
908
|
+
$[44] !== totalPages ? (t22 = (pageNumber) => {
|
|
909
|
+
pageNumber < 1 || pageNumber > totalPages || setPageIndex(pageNumber - 1);
|
|
910
|
+
}, $[44] = totalPages, $[45] = t22) : t22 = $[45];
|
|
911
|
+
const goToPage = t22, hasFirstPage = pageIndex > 0, hasPreviousPage = pageIndex > 0, hasNextPage = pageIndex < totalPages - 1, hasLastPage = pageIndex < totalPages - 1;
|
|
912
|
+
let t23;
|
|
913
|
+
return $[46] !== count || $[47] !== currentPage || $[48] !== data || $[49] !== endIndex || $[50] !== goToPage || $[51] !== hasFirstPage || $[52] !== hasLastPage || $[53] !== hasNextPage || $[54] !== hasPreviousPage || $[55] !== isPending || $[56] !== lastPage || $[57] !== nextPage || $[58] !== pageSize || $[59] !== startIndex || $[60] !== totalPages ? (t23 = {
|
|
914
|
+
data,
|
|
915
|
+
isPending,
|
|
916
|
+
pageSize,
|
|
917
|
+
currentPage,
|
|
918
|
+
totalPages,
|
|
919
|
+
startIndex,
|
|
920
|
+
endIndex,
|
|
921
|
+
count,
|
|
922
|
+
firstPage,
|
|
923
|
+
hasFirstPage,
|
|
924
|
+
previousPage,
|
|
925
|
+
hasPreviousPage,
|
|
926
|
+
nextPage,
|
|
927
|
+
hasNextPage,
|
|
928
|
+
lastPage,
|
|
929
|
+
hasLastPage,
|
|
930
|
+
goToPage
|
|
931
|
+
}, $[46] = count, $[47] = currentPage, $[48] = data, $[49] = endIndex, $[50] = goToPage, $[51] = hasFirstPage, $[52] = hasLastPage, $[53] = hasNextPage, $[54] = hasPreviousPage, $[55] = isPending, $[56] = lastPage, $[57] = nextPage, $[58] = pageSize, $[59] = startIndex, $[60] = totalPages, $[61] = t23) : t23 = $[61], t23;
|
|
932
|
+
}
|
|
933
|
+
function _temp4(prev) {
|
|
934
|
+
return Math.max(prev - 1, 0);
|
|
935
|
+
}
|
|
936
|
+
function _temp3(ordering) {
|
|
937
|
+
return [ordering.field, ordering.direction.toLowerCase()].map(_temp2).filter(Boolean).join(" ");
|
|
938
|
+
}
|
|
939
|
+
function _temp2(str) {
|
|
940
|
+
return str.trim();
|
|
941
|
+
}
|
|
942
|
+
function _temp(i) {
|
|
943
|
+
return typeof i == "string";
|
|
944
|
+
}
|
|
945
|
+
function usePreview(t0) {
|
|
946
|
+
const $ = c(13);
|
|
947
|
+
let docHandle, ref;
|
|
948
|
+
$[0] !== t0 ? ({
|
|
949
|
+
ref,
|
|
950
|
+
...docHandle
|
|
951
|
+
} = t0, $[0] = t0, $[1] = docHandle, $[2] = ref) : (docHandle = $[1], ref = $[2]);
|
|
952
|
+
const instance = useSanityInstance();
|
|
953
|
+
let t1;
|
|
954
|
+
$[3] !== docHandle || $[4] !== instance ? (t1 = getPreviewState(instance, docHandle), $[3] = docHandle, $[4] = instance, $[5] = t1) : t1 = $[5];
|
|
955
|
+
const stateSource = t1;
|
|
956
|
+
let t2;
|
|
957
|
+
$[6] !== ref || $[7] !== stateSource ? (t2 = (onStoreChanged) => {
|
|
958
|
+
const subscription = new Observable((observer) => {
|
|
959
|
+
if (typeof IntersectionObserver > "u" || typeof HTMLElement > "u") {
|
|
960
|
+
observer.next(!0);
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
const intersectionObserver = new IntersectionObserver((t32) => {
|
|
964
|
+
const [entry] = t32;
|
|
965
|
+
return observer.next(entry.isIntersecting);
|
|
966
|
+
}, {
|
|
967
|
+
rootMargin: "0px",
|
|
968
|
+
threshold: 0
|
|
969
|
+
});
|
|
970
|
+
return ref?.current && ref.current instanceof HTMLElement ? intersectionObserver.observe(ref.current) : observer.next(!0), () => intersectionObserver.disconnect();
|
|
971
|
+
}).pipe(startWith(!1), distinctUntilChanged(), switchMap((isVisible) => isVisible ? new Observable((obs) => stateSource.subscribe(() => obs.next())) : EMPTY)).subscribe({
|
|
972
|
+
next: onStoreChanged
|
|
973
|
+
});
|
|
974
|
+
return () => subscription.unsubscribe();
|
|
975
|
+
}, $[6] = ref, $[7] = stateSource, $[8] = t2) : t2 = $[8];
|
|
976
|
+
const subscribe = t2;
|
|
977
|
+
let t3;
|
|
978
|
+
return $[9] !== docHandle || $[10] !== instance || $[11] !== stateSource ? (t3 = () => {
|
|
979
|
+
const currentState = stateSource.getCurrent();
|
|
980
|
+
if (currentState.data === null)
|
|
981
|
+
throw resolvePreview(instance, docHandle);
|
|
982
|
+
return currentState;
|
|
983
|
+
}, $[9] = docHandle, $[10] = instance, $[11] = stateSource, $[12] = t3) : t3 = $[12], useSyncExternalStore(subscribe, t3);
|
|
984
|
+
}
|
|
985
|
+
function useProjection(t0) {
|
|
986
|
+
const $ = c(12);
|
|
987
|
+
let docHandle, projection, ref;
|
|
988
|
+
$[0] !== t0 ? ({
|
|
989
|
+
ref,
|
|
990
|
+
projection,
|
|
991
|
+
...docHandle
|
|
992
|
+
} = t0, $[0] = t0, $[1] = docHandle, $[2] = projection, $[3] = ref) : (docHandle = $[1], projection = $[2], ref = $[3]);
|
|
993
|
+
const instance = useSanityInstance();
|
|
994
|
+
let stateSource, t1;
|
|
995
|
+
if ($[4] !== docHandle || $[5] !== instance || $[6] !== projection ? (stateSource = getProjectionState(instance, {
|
|
996
|
+
...docHandle,
|
|
997
|
+
projection
|
|
998
|
+
}), t1 = stateSource.getCurrent()?.data, $[4] = docHandle, $[5] = instance, $[6] = projection, $[7] = stateSource, $[8] = t1) : (stateSource = $[7], t1 = $[8]), t1 === null)
|
|
999
|
+
throw resolveProjection(instance, {
|
|
1000
|
+
...docHandle,
|
|
1001
|
+
projection
|
|
1002
|
+
});
|
|
1003
|
+
let t2;
|
|
1004
|
+
return $[9] !== ref || $[10] !== stateSource ? (t2 = (onStoreChanged) => {
|
|
1005
|
+
const subscription = new Observable((observer) => {
|
|
1006
|
+
if (typeof IntersectionObserver > "u" || typeof HTMLElement > "u") {
|
|
1007
|
+
observer.next(!0);
|
|
1008
|
+
return;
|
|
1009
|
+
}
|
|
1010
|
+
const intersectionObserver = new IntersectionObserver((t3) => {
|
|
1011
|
+
const [entry] = t3;
|
|
1012
|
+
return observer.next(entry.isIntersecting);
|
|
1013
|
+
}, {
|
|
1014
|
+
rootMargin: "0px",
|
|
1015
|
+
threshold: 0
|
|
1016
|
+
});
|
|
1017
|
+
return ref?.current && ref.current instanceof HTMLElement ? intersectionObserver.observe(ref.current) : observer.next(!0), () => intersectionObserver.disconnect();
|
|
1018
|
+
}).pipe(startWith(!1), distinctUntilChanged(), switchMap((isVisible) => isVisible ? new Observable((obs) => stateSource.subscribe(() => obs.next())) : EMPTY)).subscribe({
|
|
1019
|
+
next: onStoreChanged
|
|
1020
|
+
});
|
|
1021
|
+
return () => subscription.unsubscribe();
|
|
1022
|
+
}, $[9] = ref, $[10] = stateSource, $[11] = t2) : t2 = $[11], useSyncExternalStore(t2, stateSource.getCurrent);
|
|
1023
|
+
}
|
|
1024
|
+
const useProject = createStateSourceHook({
|
|
1025
|
+
// remove `undefined` since we're suspending when that is the case
|
|
1026
|
+
getState: getProjectState,
|
|
1027
|
+
shouldSuspend: (instance, projectHandle) => getProjectState(instance, projectHandle).getCurrent() === void 0,
|
|
1028
|
+
suspender: resolveProject,
|
|
1029
|
+
getConfig: identity
|
|
1030
|
+
}), useProjects = createStateSourceHook({
|
|
1031
|
+
// remove `undefined` since we're suspending when that is the case
|
|
1032
|
+
getState: getProjectsState,
|
|
1033
|
+
shouldSuspend: (instance) => getProjectsState(instance).getCurrent() === void 0,
|
|
1034
|
+
suspender: resolveProjects
|
|
1035
|
+
}), useActiveReleases = createStateSourceHook({
|
|
1036
|
+
getState: getActiveReleasesState,
|
|
1037
|
+
shouldSuspend: (instance) => getActiveReleasesState(instance).getCurrent() === void 0,
|
|
1038
|
+
suspender: (instance) => firstValueFrom(getActiveReleasesState(instance).observable.pipe(filter(Boolean)))
|
|
1039
|
+
}), usePerspective = createStateSourceHook({
|
|
1040
|
+
getState: getPerspectiveState,
|
|
1041
|
+
shouldSuspend: (instance, options) => getPerspectiveState(instance, options).getCurrent() === void 0,
|
|
1042
|
+
suspender: (instance, _options) => firstValueFrom(getActiveReleasesState(instance).observable.pipe(filter(Boolean)))
|
|
1043
|
+
});
|
|
1044
|
+
function useUsers(options) {
|
|
1045
|
+
const instance = useSanityInstance(options), [isPending, startTransition] = useTransition(), key = getUsersKey(instance, options), [deferredKey, setDeferredKey] = useState(key), deferred = useMemo(() => parseUsersKey(deferredKey), [deferredKey]), [ref, setRef] = useState(new AbortController());
|
|
1046
|
+
useEffect(() => {
|
|
1047
|
+
key !== deferredKey && startTransition(() => {
|
|
1048
|
+
ref.signal.aborted || (ref.abort(), setRef(new AbortController())), setDeferredKey(key);
|
|
1049
|
+
});
|
|
1050
|
+
}, [deferredKey, key, ref]);
|
|
1051
|
+
const {
|
|
1052
|
+
getCurrent,
|
|
1053
|
+
subscribe
|
|
1054
|
+
} = useMemo(() => getUsersState(instance, deferred), [instance, deferred]);
|
|
1055
|
+
if (getCurrent() === void 0)
|
|
1056
|
+
throw resolveUsers(instance, {
|
|
1057
|
+
...deferred,
|
|
1058
|
+
signal: ref.signal
|
|
1059
|
+
});
|
|
1060
|
+
const {
|
|
1061
|
+
data,
|
|
1062
|
+
hasMore
|
|
1063
|
+
} = useSyncExternalStore(subscribe, getCurrent), loadMore = useCallback(() => {
|
|
1064
|
+
loadMoreUsers(instance, options);
|
|
1065
|
+
}, [instance, options]);
|
|
1066
|
+
return {
|
|
1067
|
+
data,
|
|
1068
|
+
hasMore,
|
|
1069
|
+
isPending,
|
|
1070
|
+
loadMore
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
var version = "0.0.0-alpha.30";
|
|
1074
|
+
function getEnv(key) {
|
|
1075
|
+
if (typeof import.meta < "u" && import.meta.env)
|
|
1076
|
+
return import.meta.env[key];
|
|
1077
|
+
if (typeof process < "u" && process.env)
|
|
1078
|
+
return process.env[key];
|
|
1079
|
+
if (typeof window < "u" && window.ENV)
|
|
1080
|
+
return window.ENV?.[key];
|
|
2
1081
|
}
|
|
1082
|
+
const REACT_SDK_VERSION = getEnv("PKG_VERSION") || `${version}-development`;
|
|
3
1083
|
export {
|
|
4
|
-
|
|
1084
|
+
AuthBoundary,
|
|
1085
|
+
REACT_SDK_VERSION,
|
|
1086
|
+
ResourceProvider,
|
|
1087
|
+
SDKProvider,
|
|
1088
|
+
SanityApp,
|
|
1089
|
+
useActiveReleases,
|
|
1090
|
+
useApplyDocumentActions,
|
|
1091
|
+
useAuthState,
|
|
1092
|
+
useAuthToken,
|
|
1093
|
+
useClient,
|
|
1094
|
+
useCurrentUser,
|
|
1095
|
+
useDashboardOrganizationId,
|
|
1096
|
+
useDatasets,
|
|
1097
|
+
useDocument,
|
|
1098
|
+
useDocumentEvent,
|
|
1099
|
+
useDocumentPermissions,
|
|
1100
|
+
useDocumentSyncStatus,
|
|
1101
|
+
useDocuments,
|
|
1102
|
+
useEditDocument,
|
|
1103
|
+
useFrameConnection,
|
|
1104
|
+
useHandleAuthCallback,
|
|
1105
|
+
useLogOut,
|
|
1106
|
+
useLoginUrl,
|
|
1107
|
+
useManageFavorite,
|
|
1108
|
+
useNavigateToStudioDocument,
|
|
1109
|
+
usePaginatedDocuments,
|
|
1110
|
+
usePerspective,
|
|
1111
|
+
usePreview,
|
|
1112
|
+
useProject,
|
|
1113
|
+
useProjection,
|
|
1114
|
+
useProjects,
|
|
1115
|
+
useQuery,
|
|
1116
|
+
useRecordDocumentHistoryEvent,
|
|
1117
|
+
useSanityInstance,
|
|
1118
|
+
useStudioWorkspacesByProjectIdDataset,
|
|
1119
|
+
useUsers,
|
|
1120
|
+
useVerifyOrgProjects,
|
|
1121
|
+
useWindowConnection
|
|
5
1122
|
};
|
|
6
1123
|
//# sourceMappingURL=index.js.map
|