@sanity/sdk-react 2.15.0 → 2.16.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/README.md +22 -1
- package/dist/index.d.ts +55 -2
- package/dist/index.js +524 -332
- package/dist/index.js.map +1 -1
- package/package.json +16 -16
- package/src/components/SDKProvider.test.tsx +135 -22
- package/src/components/SDKProvider.tsx +54 -17
- package/src/components/SanityApp.tsx +29 -0
- package/src/context/OrganizationResourcesProvider.test.tsx +189 -0
- package/src/context/OrganizationResourcesProvider.tsx +111 -0
- package/src/context/ProjectContext.ts +15 -0
- package/src/context/ResourceProvider.test.tsx +57 -1
- package/src/context/ResourceProvider.tsx +30 -9
- package/src/hooks/datasets/useDatasets.test.tsx +116 -0
- package/src/hooks/datasets/useDatasets.ts +20 -8
- package/src/hooks/document/useApplyDocumentActions.ts +1 -1
- package/src/hooks/document/useDocument.ts +2 -2
- package/src/hooks/helpers/useResolvedProjectId.test.tsx +59 -0
- package/src/hooks/helpers/useResolvedProjectId.ts +35 -0
- package/src/hooks/projects/useProject.test.tsx +114 -0
- package/src/hooks/projects/useProject.ts +17 -7
- package/src/hooks/users/useUsers.test.tsx +101 -2
- package/src/hooks/users/useUsers.ts +35 -3
- package/src/utils/resolveOrgResources.test.ts +111 -0
- package/src/utils/resolveOrgResources.ts +69 -0
- package/src/hooks/datasets/useDatasets.test.ts +0 -80
- package/src/hooks/projects/useProject.test.ts +0 -80
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { c } from "react-compiler-runtime";
|
|
3
3
|
import { ClientError, CorsOriginError } from "@sanity/client";
|
|
4
|
-
import { getAuthState, getNodeState, getIsInDashboardState, isStudioConfig, setAuthToken, AuthStateType, getLoginUrlState, observeOrganizationVerificationState, handleAuthCallback, logout, isProjectUserNotFoundClientError, getClientErrorApiDescription, getClientErrorApiBody, isImportError, getCorsErrorProjectId,
|
|
4
|
+
import { getAuthState, getNodeState, getIsInDashboardState, isStudioConfig, setAuthToken, AuthStateType, getLoginUrlState, observeOrganizationVerificationState, handleAuthCallback, logout, isProjectUserNotFoundClientError, getClientErrorApiDescription, getClientErrorApiBody, isImportError, getCorsErrorProjectId, getDashboardOrganizationId, getClientState, isDatasetResource, createSanityInstance, agentGenerate, agentPatch, agentPrompt, agentTransform, agentTranslate, getTokenState, getCurrentUserState, getOrCreateController, getOrCreateChannel, releaseChannel, isMediaLibraryResource, isCanvasResource, getFavoritesState, resolveFavoritesState, resolveDatasets, getDatasetsState, applyDocumentActions, createDocument, resolveDocument, getDocumentState, subscribeDocumentEvents, getPermissionsState, getDocumentSyncStatus, editDocument, getQueryKey, parseQueryKey, getQueryState, resolveQuery, createGroqSearchFilter, resolveOrganization, getOrganizationState, resolveOrganizations, getOrganizationsState, getPresence, getProjectionState, resolveProjection, transformProjectionToPreview, PREVIEW_PROJECTION, resolveProject, getProjectState, resolveProjects, getProjectsState, getActiveReleasesState, getAllReleasesState, getPerspectiveState, getUsersKey, parseUsersKey, getUsersState, resolveUsers, loadMoreUsers } from "@sanity/sdk";
|
|
5
5
|
export * from "@sanity/sdk";
|
|
6
|
-
import { createContext, useContext, useSyncExternalStore, useRef, useEffect, useState, Suspense, StrictMode, useCallback, useMemo, useInsertionEffect, useTransition } from "react";
|
|
6
|
+
import { createContext, useContext, useSyncExternalStore, useRef, useEffect, useState, Suspense, use, StrictMode, useCallback, useMemo, useInsertionEffect, useTransition } from "react";
|
|
7
7
|
import { getErrorMessage, ErrorBoundary } from "react-error-boundary";
|
|
8
8
|
import { SDK_CHANNEL_NAME, SDK_NODE_NAME } from "@sanity/message-protocol";
|
|
9
9
|
import { firstValueFrom, filter, identity, Observable, startWith, distinctUntilChanged, switchMap, EMPTY } from "rxjs";
|
|
@@ -60,7 +60,7 @@ function useWindowConnection(t0) {
|
|
|
60
60
|
const [type, handler] = t42, messageUnsubscribe = node.on(type, handler);
|
|
61
61
|
messageUnsubscribe && messageUnsubscribers.current.push(messageUnsubscribe);
|
|
62
62
|
}), () => {
|
|
63
|
-
messageUnsubscribers.current.forEach(_temp$
|
|
63
|
+
messageUnsubscribers.current.forEach(_temp$9), messageUnsubscribers.current = [];
|
|
64
64
|
}), $[4] = node, $[5] = onMessage, $[6] = t3) : t3 = $[6];
|
|
65
65
|
let t4;
|
|
66
66
|
$[7] !== instance || $[8] !== name || $[9] !== node || $[10] !== onMessage ? (t4 = [instance, name, onMessage, node], $[7] = instance, $[8] = name, $[9] = node, $[10] = onMessage, $[11] = t4) : t4 = $[11], useEffect(t3, t4);
|
|
@@ -78,7 +78,7 @@ function useWindowConnection(t0) {
|
|
|
78
78
|
fetch
|
|
79
79
|
}, $[16] = fetch, $[17] = sendMessage, $[18] = t7) : t7 = $[18], t7;
|
|
80
80
|
}
|
|
81
|
-
function _temp$
|
|
81
|
+
function _temp$9(unsubscribe) {
|
|
82
82
|
return unsubscribe();
|
|
83
83
|
}
|
|
84
84
|
const DEFAULT_RESPONSE_TIMEOUT = 1e4;
|
|
@@ -108,7 +108,7 @@ function DashboardTokenRefresh(t0) {
|
|
|
108
108
|
if (clearRefreshTimeout(), res.token) {
|
|
109
109
|
setAuthToken(instance, res.token);
|
|
110
110
|
const errorContainer = document.getElementById("__sanityError");
|
|
111
|
-
errorContainer && Array.from(errorContainer.getElementsByTagName("div")).some(_temp$
|
|
111
|
+
errorContainer && Array.from(errorContainer.getElementsByTagName("div")).some(_temp$8) && errorContainer.remove();
|
|
112
112
|
}
|
|
113
113
|
isTokenRefreshInProgress.current = !1;
|
|
114
114
|
} catch {
|
|
@@ -129,26 +129,23 @@ function DashboardTokenRefresh(t0) {
|
|
|
129
129
|
let t7;
|
|
130
130
|
return $[11] !== authState || $[12] !== requestNewToken ? (t7 = [authState, requestNewToken], $[11] = authState, $[12] = requestNewToken, $[13] = t7) : t7 = $[13], useEffect(t6, t7), children;
|
|
131
131
|
}
|
|
132
|
-
function _temp$
|
|
132
|
+
function _temp$8(div) {
|
|
133
133
|
return div.textContent?.includes("Uncaught error: Unauthorized - A valid session is required for this endpoint");
|
|
134
134
|
}
|
|
135
135
|
const ComlinkTokenRefreshProvider = (t0) => {
|
|
136
136
|
const $ = c(2), {
|
|
137
137
|
children
|
|
138
|
-
} = t0, instance = useSanityInstance();
|
|
139
|
-
let t1;
|
|
140
|
-
t1 = getIsInDashboardState(instance).getCurrent();
|
|
141
|
-
const isInDashboard = t1, isStudio = isStudioConfig(instance.config);
|
|
138
|
+
} = t0, instance = useSanityInstance(), isInDashboard = getIsInDashboardState(instance).getCurrent(), isStudio = isStudioConfig(instance.config);
|
|
142
139
|
if (isInDashboard && !isStudio) {
|
|
143
|
-
let
|
|
144
|
-
return $[0] !== children ? (
|
|
140
|
+
let t1;
|
|
141
|
+
return $[0] !== children ? (t1 = /* @__PURE__ */ jsx(DashboardTokenRefresh, { children }), $[0] = children, $[1] = t1) : t1 = $[1], t1;
|
|
145
142
|
}
|
|
146
143
|
return children;
|
|
147
144
|
};
|
|
148
145
|
function useLoginUrl() {
|
|
149
146
|
const $ = c(2), instance = useSanityInstance();
|
|
150
|
-
let t0
|
|
151
|
-
$[0] !== instance ? (
|
|
147
|
+
let t0;
|
|
148
|
+
$[0] !== instance ? (t0 = getLoginUrlState(instance), $[0] = instance, $[1] = t0) : t0 = $[1];
|
|
152
149
|
const {
|
|
153
150
|
subscribe,
|
|
154
151
|
getCurrent
|
|
@@ -266,10 +263,10 @@ function ChunkLoadError(_props) {
|
|
|
266
263
|
let t3;
|
|
267
264
|
return $[3] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = /* @__PURE__ */ jsx(Error$1, { heading: "A new version is available", description: "The page tried to load an asset that no longer exists. Reload to continue with the latest version.", cta: {
|
|
268
265
|
text: "Reload page",
|
|
269
|
-
onClick: _temp$
|
|
266
|
+
onClick: _temp$7
|
|
270
267
|
} }), $[3] = t3) : t3 = $[3], t3;
|
|
271
268
|
}
|
|
272
|
-
function _temp$
|
|
269
|
+
function _temp$7() {
|
|
273
270
|
clearChunkReloadFlag(), reload();
|
|
274
271
|
}
|
|
275
272
|
function CorsErrorComponent(t0) {
|
|
@@ -278,17 +275,14 @@ function CorsErrorComponent(t0) {
|
|
|
278
275
|
error
|
|
279
276
|
} = t0, origin = window.location.origin;
|
|
280
277
|
let t1;
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
const url = new URL(t2);
|
|
285
|
-
url.searchParams.set("cors", "add"), url.searchParams.set("origin", origin), url.searchParams.set("credentials", "include"), t3 = url.toString(), $[0] = t2, $[1] = t3;
|
|
278
|
+
if ($[0] !== projectId) {
|
|
279
|
+
const url = new URL(`https://sanity.io/manage/project/${projectId}/api`);
|
|
280
|
+
url.searchParams.set("cors", "add"), url.searchParams.set("origin", origin), url.searchParams.set("credentials", "include"), t1 = url.toString(), $[0] = projectId, $[1] = t1;
|
|
286
281
|
} else
|
|
287
|
-
|
|
288
|
-
t1 = t3;
|
|
282
|
+
t1 = $[1];
|
|
289
283
|
const corsUrl = t1;
|
|
290
|
-
let
|
|
291
|
-
return $[2] !== corsUrl || $[3] !== error || $[4] !== projectId ? (
|
|
284
|
+
let t2;
|
|
285
|
+
return $[2] !== corsUrl || $[3] !== error || $[4] !== projectId ? (t2 = /* @__PURE__ */ jsx(Error$1, { heading: "Before you continue\u2026", ...projectId ? {
|
|
292
286
|
description: "To access your content, you need to <strong>add the following URL as a CORS origin</strong> to your Sanity project.",
|
|
293
287
|
code: origin,
|
|
294
288
|
cta: {
|
|
@@ -297,7 +291,7 @@ function CorsErrorComponent(t0) {
|
|
|
297
291
|
}
|
|
298
292
|
} : {
|
|
299
293
|
description: getErrorMessage(error)
|
|
300
|
-
} }), $[2] = corsUrl, $[3] = error, $[4] = projectId, $[5] =
|
|
294
|
+
} }), $[2] = corsUrl, $[3] = error, $[4] = projectId, $[5] = t2) : t2 = $[5], t2;
|
|
301
295
|
}
|
|
302
296
|
function isInIframe() {
|
|
303
297
|
return typeof window < "u" && window.self !== window.top;
|
|
@@ -330,10 +324,10 @@ function LoginCallback() {
|
|
|
330
324
|
let t0, t1;
|
|
331
325
|
return $[0] !== handleAuthCallback2 ? (t0 = () => {
|
|
332
326
|
const url = new URL(location.href);
|
|
333
|
-
handleAuthCallback2(url.toString()).then(_temp$
|
|
327
|
+
handleAuthCallback2(url.toString()).then(_temp$6);
|
|
334
328
|
}, t1 = [handleAuthCallback2], $[0] = handleAuthCallback2, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), useEffect(t0, t1), null;
|
|
335
329
|
}
|
|
336
|
-
function _temp$
|
|
330
|
+
function _temp$6(replacementLocation) {
|
|
337
331
|
replacementLocation && history.replaceState(null, "", replacementLocation);
|
|
338
332
|
}
|
|
339
333
|
const useLogOut = createCallbackHook(logout);
|
|
@@ -380,13 +374,13 @@ function LoginError(t0) {
|
|
|
380
374
|
await logout2(), resetErrorBoundary();
|
|
381
375
|
}, $[4] = logout2, $[5] = resetErrorBoundary, $[6] = t4) : t4 = $[6];
|
|
382
376
|
const handleRetry = t4;
|
|
383
|
-
let
|
|
377
|
+
let message = "Please try again or contact support if the problem persists.", retry = !0;
|
|
384
378
|
if (clientError) {
|
|
385
379
|
if (clientError.statusCode === 401)
|
|
386
380
|
if (isProjectUserNotFound) {
|
|
387
|
-
let
|
|
388
|
-
$[7] !== clientError ? (
|
|
389
|
-
const description =
|
|
381
|
+
let t52;
|
|
382
|
+
$[7] !== clientError ? (t52 = getClientErrorApiDescription(clientError), $[7] = clientError, $[8] = t52) : t52 = $[8];
|
|
383
|
+
const description = t52;
|
|
390
384
|
description && (message = description), retry = !1;
|
|
391
385
|
} else
|
|
392
386
|
isInDashboard || (message = "Signing you out and returning to login...", retry = !0);
|
|
@@ -396,34 +390,34 @@ function LoginError(t0) {
|
|
|
396
390
|
}
|
|
397
391
|
}
|
|
398
392
|
authState.type !== AuthStateType.ERROR && error instanceof ConfigurationError && (message = error.message, retry = !0);
|
|
399
|
-
let
|
|
400
|
-
$[9] !== message || $[10] !== retry ? (
|
|
393
|
+
let t5;
|
|
394
|
+
$[9] !== message || $[10] !== retry ? (t5 = {
|
|
401
395
|
authErrorMessage: message,
|
|
402
396
|
showRetryCta: retry
|
|
403
|
-
}, $[9] = message, $[10] = retry, $[11] =
|
|
397
|
+
}, $[9] = message, $[10] = retry, $[11] = t5) : t5 = $[11];
|
|
404
398
|
const {
|
|
405
399
|
authErrorMessage,
|
|
406
400
|
showRetryCta
|
|
407
401
|
} = t5, hasAutoLoggedOutRef = useRef(!1);
|
|
408
|
-
let
|
|
409
|
-
$[12] !== clientError || $[13] !== handleRetry || $[14] !== isInDashboard || $[15] !== isProjectUserNotFound ? (
|
|
402
|
+
let t6, t7;
|
|
403
|
+
$[12] !== clientError || $[13] !== handleRetry || $[14] !== isInDashboard || $[15] !== isProjectUserNotFound ? (t6 = () => {
|
|
410
404
|
clientError && clientError.statusCode === 401 && !isProjectUserNotFound && !isInDashboard && !hasAutoLoggedOutRef.current && (hasAutoLoggedOutRef.current = !0, handleRetry());
|
|
411
|
-
},
|
|
412
|
-
let
|
|
413
|
-
$[18] !== dashboardAccessProjectId ? (
|
|
414
|
-
const
|
|
415
|
-
let
|
|
416
|
-
$[20] !== handleRetry || $[21] !== showRetryCta ? (
|
|
405
|
+
}, t7 = [clientError, handleRetry, isInDashboard, isProjectUserNotFound], $[12] = clientError, $[13] = handleRetry, $[14] = isInDashboard, $[15] = isProjectUserNotFound, $[16] = t6, $[17] = t7) : (t6 = $[16], t7 = $[17]), useEffect(t6, t7);
|
|
406
|
+
let t8;
|
|
407
|
+
$[18] !== dashboardAccessProjectId ? (t8 = dashboardAccessProjectId && /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(DashboardAccessRequest, { projectId: dashboardAccessProjectId }) }), $[18] = dashboardAccessProjectId, $[19] = t8) : t8 = $[19];
|
|
408
|
+
const t9 = error instanceof ConfigurationError ? "Configuration Error" : "Authentication Error";
|
|
409
|
+
let t10;
|
|
410
|
+
$[20] !== handleRetry || $[21] !== showRetryCta ? (t10 = showRetryCta ? {
|
|
417
411
|
text: "Retry",
|
|
418
412
|
onClick: handleRetry
|
|
419
|
-
} : void 0, $[20] = handleRetry, $[21] = showRetryCta, $[22] =
|
|
413
|
+
} : void 0, $[20] = handleRetry, $[21] = showRetryCta, $[22] = t10) : t10 = $[22];
|
|
414
|
+
let t11;
|
|
415
|
+
$[23] !== authErrorMessage || $[24] !== t10 || $[25] !== t9 ? (t11 = /* @__PURE__ */ jsx(Error$1, { heading: t9, description: authErrorMessage, cta: t10 }), $[23] = authErrorMessage, $[24] = t10, $[25] = t9, $[26] = t11) : t11 = $[26];
|
|
420
416
|
let t12;
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
t12
|
|
426
|
-
] }), $[27] = t12, $[28] = t9, $[29] = t13) : t13 = $[29], t13;
|
|
417
|
+
return $[27] !== t11 || $[28] !== t8 ? (t12 = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
418
|
+
t8,
|
|
419
|
+
t11
|
|
420
|
+
] }), $[27] = t11, $[28] = t8, $[29] = t12) : t12 = $[29], t12;
|
|
427
421
|
}
|
|
428
422
|
if (isInIframe() && !document.querySelector("[data-sanity-core]")) {
|
|
429
423
|
const parsedUrl = new URL(window.location.href), mode = new URLSearchParams(parsedUrl.hash.slice(1)).get("mode"), script = document.createElement("script");
|
|
@@ -437,17 +431,17 @@ function AuthBoundary(t0) {
|
|
|
437
431
|
...props
|
|
438
432
|
} = t0, $[0] = t0, $[1] = props, $[2] = t1) : (props = $[1], t1 = $[2]);
|
|
439
433
|
const LoginErrorComponent = t1 === void 0 ? LoginError : t1, authState = useAuthState(), sessionResetKey = authState.type === AuthStateType.LOGGED_IN ? authState.token : authState.type;
|
|
440
|
-
let t2
|
|
441
|
-
$[3] !== LoginErrorComponent ? (
|
|
434
|
+
let t2;
|
|
435
|
+
$[3] !== LoginErrorComponent ? (t2 = function(fallbackProps) {
|
|
442
436
|
return isImportError(fallbackProps.error) ? /* @__PURE__ */ jsx(ChunkLoadError, { ...fallbackProps }) : fallbackProps.error instanceof CorsOriginError ? /* @__PURE__ */ jsx(CorsErrorComponent, { ...fallbackProps, projectId: getCorsErrorProjectId(fallbackProps.error) }) : /* @__PURE__ */ jsx(LoginErrorComponent, { ...fallbackProps });
|
|
443
|
-
}, $[3] = LoginErrorComponent, $[4] =
|
|
437
|
+
}, $[3] = LoginErrorComponent, $[4] = t2) : t2 = $[4];
|
|
444
438
|
const FallbackComponent = t2;
|
|
439
|
+
let t3;
|
|
440
|
+
$[5] !== sessionResetKey ? (t3 = [sessionResetKey], $[5] = sessionResetKey, $[6] = t3) : t3 = $[6];
|
|
445
441
|
let t4;
|
|
446
|
-
$[
|
|
442
|
+
$[7] !== props ? (t4 = /* @__PURE__ */ jsx(AuthSwitch, { ...props }), $[7] = props, $[8] = t4) : t4 = $[8];
|
|
447
443
|
let t5;
|
|
448
|
-
$[
|
|
449
|
-
let t6;
|
|
450
|
-
return $[9] !== FallbackComponent || $[10] !== t4 || $[11] !== t5 ? (t6 = /* @__PURE__ */ jsx(ComlinkTokenRefreshProvider, { children: /* @__PURE__ */ jsx(ErrorBoundary, { FallbackComponent, resetKeys: t4, children: t5 }) }), $[9] = FallbackComponent, $[10] = t4, $[11] = t5, $[12] = t6) : t6 = $[12], t6;
|
|
444
|
+
return $[9] !== FallbackComponent || $[10] !== t3 || $[11] !== t4 ? (t5 = /* @__PURE__ */ jsx(ComlinkTokenRefreshProvider, { children: /* @__PURE__ */ jsx(ErrorBoundary, { FallbackComponent, resetKeys: t3, children: t4 }) }), $[9] = FallbackComponent, $[10] = t3, $[11] = t4, $[12] = t5) : t5 = $[12], t5;
|
|
451
445
|
}
|
|
452
446
|
function AuthSwitch(t0) {
|
|
453
447
|
const $ = c(16);
|
|
@@ -487,7 +481,95 @@ function AuthSwitch(t0) {
|
|
|
487
481
|
}
|
|
488
482
|
const SDKStudioContext = createContext(null);
|
|
489
483
|
SDKStudioContext.displayName = "SDKStudioContext";
|
|
490
|
-
const DEFAULT_RESOURCE_NAME = "default"
|
|
484
|
+
const DEFAULT_RESOURCE_NAME = "default";
|
|
485
|
+
function useDashboardOrganizationId() {
|
|
486
|
+
const $ = c(2), instance = useSanityInstance();
|
|
487
|
+
let t0;
|
|
488
|
+
$[0] !== instance ? (t0 = getDashboardOrganizationId(instance), $[0] = instance, $[1] = t0) : t0 = $[1];
|
|
489
|
+
const {
|
|
490
|
+
subscribe,
|
|
491
|
+
getCurrent
|
|
492
|
+
} = t0;
|
|
493
|
+
return useSyncExternalStore(subscribe, getCurrent);
|
|
494
|
+
}
|
|
495
|
+
const API_VERSION = "v2026-07-09";
|
|
496
|
+
function getFirstResourceId(result) {
|
|
497
|
+
if (result.status === "fulfilled")
|
|
498
|
+
return result.value.data?.[0]?.id;
|
|
499
|
+
}
|
|
500
|
+
async function resolveOrgResources(instance, organizationId) {
|
|
501
|
+
const client = await firstValueFrom(getClientState(instance, {
|
|
502
|
+
apiVersion: API_VERSION,
|
|
503
|
+
scope: "global"
|
|
504
|
+
}).observable), [mediaLibrariesResult, canvasesResult] = await Promise.allSettled([client.request({
|
|
505
|
+
uri: "/media-libraries",
|
|
506
|
+
query: {
|
|
507
|
+
organizationId
|
|
508
|
+
},
|
|
509
|
+
tag: "org-resources.media-libraries"
|
|
510
|
+
}), client.request({
|
|
511
|
+
uri: "/canvases",
|
|
512
|
+
query: {
|
|
513
|
+
organizationId
|
|
514
|
+
},
|
|
515
|
+
tag: "org-resources.canvases"
|
|
516
|
+
})]), mediaLibraryId = getFirstResourceId(mediaLibrariesResult), canvasId = getFirstResourceId(canvasesResult);
|
|
517
|
+
return {
|
|
518
|
+
mediaLibrary: mediaLibraryId ? {
|
|
519
|
+
mediaLibraryId
|
|
520
|
+
} : void 0,
|
|
521
|
+
canvas: canvasId ? {
|
|
522
|
+
canvasId
|
|
523
|
+
} : void 0
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
const ResourcesContext = createContext({}), DEFAULT_MEDIA_LIBRARY_RESOURCE_NAME = "media-library", DEFAULT_CANVAS_RESOURCE_NAME = "canvas", inferredResourceCache = /* @__PURE__ */ new WeakMap();
|
|
527
|
+
function getOrgResourcePromises(instance, organizationId) {
|
|
528
|
+
let promises = inferredResourceCache.get(instance);
|
|
529
|
+
if (!promises) {
|
|
530
|
+
const basePromise = resolveOrgResources(instance, organizationId).then((result) => result, (error) => (console.warn("[sanity/sdk] Failed to infer org resources:", error), {
|
|
531
|
+
mediaLibrary: void 0,
|
|
532
|
+
canvas: void 0
|
|
533
|
+
}));
|
|
534
|
+
promises = /* @__PURE__ */ new Map([[DEFAULT_MEDIA_LIBRARY_RESOURCE_NAME, basePromise.then((r) => r.mediaLibrary)], [DEFAULT_CANVAS_RESOURCE_NAME, basePromise.then((r) => r.canvas)]]), inferredResourceCache.set(instance, promises);
|
|
535
|
+
}
|
|
536
|
+
return promises;
|
|
537
|
+
}
|
|
538
|
+
function InferredResourcesProvider(t0) {
|
|
539
|
+
const $ = c(9), {
|
|
540
|
+
instance,
|
|
541
|
+
orgId,
|
|
542
|
+
explicitResources,
|
|
543
|
+
children
|
|
544
|
+
} = t0, promises = getOrgResourcePromises(instance, orgId), ml = use(promises.get(DEFAULT_MEDIA_LIBRARY_RESOURCE_NAME)), canvas = use(promises.get(DEFAULT_CANVAS_RESOURCE_NAME));
|
|
545
|
+
let inferred;
|
|
546
|
+
$[0] !== canvas || $[1] !== ml ? (inferred = {}, ml !== void 0 && (inferred[DEFAULT_MEDIA_LIBRARY_RESOURCE_NAME] = ml), canvas !== void 0 && (inferred[DEFAULT_CANVAS_RESOURCE_NAME] = canvas), $[0] = canvas, $[1] = ml, $[2] = inferred) : inferred = $[2];
|
|
547
|
+
let t1;
|
|
548
|
+
$[3] !== explicitResources || $[4] !== inferred ? (t1 = {
|
|
549
|
+
...inferred,
|
|
550
|
+
...explicitResources
|
|
551
|
+
}, $[3] = explicitResources, $[4] = inferred, $[5] = t1) : t1 = $[5];
|
|
552
|
+
const resources = t1;
|
|
553
|
+
let t2;
|
|
554
|
+
return $[6] !== children || $[7] !== resources ? (t2 = /* @__PURE__ */ jsx(ResourcesContext.Provider, { value: resources, children }), $[6] = children, $[7] = resources, $[8] = t2) : t2 = $[8], t2;
|
|
555
|
+
}
|
|
556
|
+
function OrganizationResourcesProvider(t0) {
|
|
557
|
+
const $ = c(10), {
|
|
558
|
+
resources: t1,
|
|
559
|
+
inferMediaLibraryAndCanvas,
|
|
560
|
+
children
|
|
561
|
+
} = t0;
|
|
562
|
+
let t2;
|
|
563
|
+
$[0] !== t1 ? (t2 = t1 === void 0 ? {} : t1, $[0] = t1, $[1] = t2) : t2 = $[1];
|
|
564
|
+
const explicitResources = t2, instance = useSanityInstance(), orgId = useDashboardOrganizationId();
|
|
565
|
+
if (!inferMediaLibraryAndCanvas || !orgId) {
|
|
566
|
+
let t32;
|
|
567
|
+
return $[2] !== children || $[3] !== explicitResources ? (t32 = /* @__PURE__ */ jsx(ResourcesContext.Provider, { value: explicitResources, children }), $[2] = children, $[3] = explicitResources, $[4] = t32) : t32 = $[4], t32;
|
|
568
|
+
}
|
|
569
|
+
let t3;
|
|
570
|
+
return $[5] !== children || $[6] !== explicitResources || $[7] !== instance || $[8] !== orgId ? (t3 = /* @__PURE__ */ jsx(InferredResourcesProvider, { instance, orgId, explicitResources, children }), $[5] = children, $[6] = explicitResources, $[7] = instance, $[8] = orgId, $[9] = t3) : t3 = $[9], t3;
|
|
571
|
+
}
|
|
572
|
+
const ResourceContext = createContext(void 0), PerspectiveContext = createContext(void 0), ProjectContext = createContext(void 0);
|
|
491
573
|
function SanityInstanceProvider(t0) {
|
|
492
574
|
const $ = c(6), {
|
|
493
575
|
instance,
|
|
@@ -501,7 +583,7 @@ function SanityInstanceProvider(t0) {
|
|
|
501
583
|
}
|
|
502
584
|
const DEFAULT_FALLBACK = /* @__PURE__ */ jsx(Fragment, { children: "Warning: No fallback provided. Please supply a fallback prop to ensure proper Suspense handling." });
|
|
503
585
|
function ResourceProvider(t0) {
|
|
504
|
-
const $ = c(
|
|
586
|
+
const $ = c(35);
|
|
505
587
|
let children, config, fallback, resource;
|
|
506
588
|
$[0] !== t0 ? ({
|
|
507
589
|
children,
|
|
@@ -509,7 +591,7 @@ function ResourceProvider(t0) {
|
|
|
509
591
|
resource,
|
|
510
592
|
...config
|
|
511
593
|
} = t0, $[0] = t0, $[1] = children, $[2] = config, $[3] = fallback, $[4] = resource) : (children = $[1], config = $[2], fallback = $[3], resource = $[4]);
|
|
512
|
-
const parentPerspective = useContext(PerspectiveContext), parentResource = useContext(ResourceContext), parentInstance = useContext(SanityInstanceContext), {
|
|
594
|
+
const parentPerspective = useContext(PerspectiveContext), parentResource = useContext(ResourceContext), parentInstance = useContext(SanityInstanceContext), parentProjectId = useContext(ProjectContext), {
|
|
513
595
|
projectId,
|
|
514
596
|
dataset,
|
|
515
597
|
perspective
|
|
@@ -527,96 +609,137 @@ function ResourceProvider(t0) {
|
|
|
527
609
|
}, $[8] = dataset, $[9] = projectId, $[10] = t32) : t32 = $[10], t2 = t32;
|
|
528
610
|
break bb0;
|
|
529
611
|
}
|
|
612
|
+
if (dataset && parentProjectId) {
|
|
613
|
+
let t32;
|
|
614
|
+
$[11] !== dataset || $[12] !== parentProjectId ? (t32 = {
|
|
615
|
+
projectId: parentProjectId,
|
|
616
|
+
dataset
|
|
617
|
+
}, $[11] = dataset, $[12] = parentProjectId, $[13] = t32) : t32 = $[13], t2 = t32;
|
|
618
|
+
break bb0;
|
|
619
|
+
}
|
|
530
620
|
t2 = void 0;
|
|
531
621
|
}
|
|
532
622
|
const configResource = t2;
|
|
533
623
|
let t3;
|
|
534
|
-
|
|
624
|
+
bb1: {
|
|
625
|
+
if (resource) {
|
|
626
|
+
t3 = resource;
|
|
627
|
+
break bb1;
|
|
628
|
+
}
|
|
629
|
+
if (configResource) {
|
|
630
|
+
t3 = configResource;
|
|
631
|
+
break bb1;
|
|
632
|
+
}
|
|
633
|
+
if (projectId) {
|
|
634
|
+
t3 = void 0;
|
|
635
|
+
break bb1;
|
|
636
|
+
}
|
|
637
|
+
t3 = parentResource;
|
|
638
|
+
}
|
|
535
639
|
const effectiveResource = t3;
|
|
536
|
-
let t4
|
|
537
|
-
|
|
640
|
+
let t4;
|
|
641
|
+
bb2: {
|
|
642
|
+
if (effectiveResource && isDatasetResource(effectiveResource)) {
|
|
643
|
+
t4 = effectiveResource.projectId;
|
|
644
|
+
break bb2;
|
|
645
|
+
}
|
|
646
|
+
t4 = projectId ?? parentProjectId;
|
|
647
|
+
}
|
|
648
|
+
const effectiveProjectId = t4;
|
|
649
|
+
let t5, t6;
|
|
650
|
+
$[14] !== effectiveResource || $[15] !== instance ? (t5 = () => {
|
|
538
651
|
effectiveResource && isDatasetResource(effectiveResource) && initTelemetry(instance, effectiveResource.projectId);
|
|
539
|
-
},
|
|
652
|
+
}, t6 = [instance, effectiveResource], $[14] = effectiveResource, $[15] = instance, $[16] = t5, $[17] = t6) : (t5 = $[16], t6 = $[17]), useEffect(t5, t6);
|
|
540
653
|
const disposal = useRef(null);
|
|
541
|
-
let
|
|
542
|
-
$[
|
|
654
|
+
let t7, t8;
|
|
655
|
+
$[18] !== instance || $[19] !== parentInstance ? (t7 = () => (disposal.current !== null && instance === disposal.current.instance && (clearTimeout(disposal.current.timeoutId), disposal.current = null), () => {
|
|
543
656
|
disposal.current = {
|
|
544
657
|
instance,
|
|
545
658
|
timeoutId: setTimeout(() => {
|
|
546
659
|
!instance.isDisposed() && instance !== parentInstance && instance.dispose();
|
|
547
660
|
}, 0)
|
|
548
661
|
};
|
|
549
|
-
}),
|
|
550
|
-
const
|
|
551
|
-
let t10;
|
|
552
|
-
$[19] !== children || $[20] !== t9 ? (t10 = /* @__PURE__ */ jsx(PerspectiveContext.Provider, { value: t9, children }), $[19] = children, $[20] = t9, $[21] = t10) : t10 = $[21];
|
|
662
|
+
}), t8 = [instance, parentInstance], $[18] = instance, $[19] = parentInstance, $[20] = t7, $[21] = t8) : (t7 = $[20], t8 = $[21]), useEffect(t7, t8);
|
|
663
|
+
const t9 = fallback ?? DEFAULT_FALLBACK, t10 = perspective ?? parentPerspective;
|
|
553
664
|
let t11;
|
|
554
|
-
$[22] !==
|
|
665
|
+
$[22] !== children || $[23] !== t10 ? (t11 = /* @__PURE__ */ jsx(PerspectiveContext.Provider, { value: t10, children }), $[22] = children, $[23] = t10, $[24] = t11) : t11 = $[24];
|
|
555
666
|
let t12;
|
|
556
|
-
|
|
667
|
+
$[25] !== effectiveProjectId || $[26] !== t11 ? (t12 = /* @__PURE__ */ jsx(ProjectContext.Provider, { value: effectiveProjectId, children: t11 }), $[25] = effectiveProjectId, $[26] = t11, $[27] = t12) : t12 = $[27];
|
|
668
|
+
let t13;
|
|
669
|
+
$[28] !== effectiveResource || $[29] !== t12 ? (t13 = /* @__PURE__ */ jsx(ResourceContext.Provider, { value: effectiveResource, children: t12 }), $[28] = effectiveResource, $[29] = t12, $[30] = t13) : t13 = $[30];
|
|
670
|
+
let t14;
|
|
671
|
+
return $[31] !== instance || $[32] !== t13 || $[33] !== t9 ? (t14 = /* @__PURE__ */ jsx(SanityInstanceProvider, { instance, fallback: t9, children: t13 }), $[31] = instance, $[32] = t13, $[33] = t9, $[34] = t14) : t14 = $[34], t14;
|
|
557
672
|
}
|
|
558
|
-
const ResourcesContext = createContext({});
|
|
559
673
|
function ResetChunkReloadFlagOnMount() {
|
|
560
674
|
const $ = c(1);
|
|
561
675
|
let t0;
|
|
562
|
-
return $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = [], $[0] = t0) : t0 = $[0], useEffect(_temp$
|
|
676
|
+
return $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = [], $[0] = t0) : t0 = $[0], useEffect(_temp$5, t0), null;
|
|
563
677
|
}
|
|
564
|
-
function _temp$
|
|
678
|
+
function _temp$5() {
|
|
565
679
|
clearChunkReloadFlag();
|
|
566
680
|
}
|
|
567
681
|
function SDKProvider(t0) {
|
|
568
|
-
const $ = c(
|
|
569
|
-
let children, config, fallback, props;
|
|
682
|
+
const $ = c(36);
|
|
683
|
+
let children, config, fallback, inferMediaLibraryAndCanvas, props;
|
|
570
684
|
$[0] !== t0 ? ({
|
|
571
685
|
children,
|
|
572
686
|
config,
|
|
573
687
|
fallback,
|
|
688
|
+
inferMediaLibraryAndCanvas,
|
|
574
689
|
...props
|
|
575
|
-
} = t0, $[0] = t0, $[1] = children, $[2] = config, $[3] = fallback, $[4] = props) : (children = $[1], config = $[2], fallback = $[3],
|
|
690
|
+
} = t0, $[0] = t0, $[1] = children, $[2] = config, $[3] = fallback, $[4] = inferMediaLibraryAndCanvas, $[5] = props) : (children = $[1], config = $[2], fallback = $[3], inferMediaLibraryAndCanvas = $[4], props = $[5]);
|
|
691
|
+
const defaultConfig = Array.isArray(config) ? config[0] : config, defaultProjectId = defaultConfig?.projectId, defaultDataset = defaultConfig?.dataset;
|
|
576
692
|
let t1;
|
|
577
|
-
$[5] !== config ? (t1 = Array.isArray(config) ? config : [config], $[5] = config, $[6] = t1) : t1 = $[6];
|
|
578
|
-
const allConfigs = t1, resolvedConfig = allConfigs[0];
|
|
579
|
-
let t2;
|
|
580
|
-
$[7] !== allConfigs ? (t2 = allConfigs.map(_temp2$1).filter(_temp3$1), $[7] = allConfigs, $[8] = t2) : t2 = $[8];
|
|
581
|
-
const projectIds = t2, singleConfig = Array.isArray(config) ? null : config, defaultProjectId = singleConfig?.projectId, defaultDataset = singleConfig?.dataset;
|
|
582
|
-
let t3;
|
|
583
693
|
bb0: {
|
|
584
|
-
let
|
|
585
|
-
$[
|
|
586
|
-
const explicit =
|
|
694
|
+
let t22;
|
|
695
|
+
$[6] !== props.resources ? (t22 = props.resources ?? {}, $[6] = props.resources, $[7] = t22) : t22 = $[7];
|
|
696
|
+
const explicit = t22;
|
|
587
697
|
if (defaultProjectId && defaultDataset && !Object.hasOwn(explicit, DEFAULT_RESOURCE_NAME)) {
|
|
588
|
-
let
|
|
589
|
-
$[
|
|
698
|
+
let t32;
|
|
699
|
+
$[8] !== defaultDataset || $[9] !== defaultProjectId ? (t32 = {
|
|
590
700
|
projectId: defaultProjectId,
|
|
591
701
|
dataset: defaultDataset
|
|
592
|
-
}, $[
|
|
593
|
-
let
|
|
594
|
-
$[
|
|
595
|
-
[DEFAULT_RESOURCE_NAME]:
|
|
702
|
+
}, $[8] = defaultDataset, $[9] = defaultProjectId, $[10] = t32) : t32 = $[10];
|
|
703
|
+
let t42;
|
|
704
|
+
$[11] !== explicit || $[12] !== t32 ? (t42 = {
|
|
705
|
+
[DEFAULT_RESOURCE_NAME]: t32,
|
|
596
706
|
...explicit
|
|
597
|
-
}, $[
|
|
707
|
+
}, $[11] = explicit, $[12] = t32, $[13] = t42) : t42 = $[13], t1 = t42;
|
|
598
708
|
break bb0;
|
|
599
709
|
}
|
|
600
|
-
|
|
710
|
+
t1 = explicit;
|
|
601
711
|
}
|
|
602
|
-
const resourcesValue =
|
|
603
|
-
let
|
|
604
|
-
$[
|
|
712
|
+
const resourcesValue = t1;
|
|
713
|
+
let t2;
|
|
714
|
+
if ($[14] !== config || $[15] !== resourcesValue) {
|
|
715
|
+
let t32;
|
|
716
|
+
$[17] !== resourcesValue ? (t32 = Object.values(resourcesValue).filter(isDatasetResource).map(_temp2$1), $[17] = resourcesValue, $[18] = t32) : t32 = $[18];
|
|
717
|
+
let t42;
|
|
718
|
+
$[19] !== config || $[20] !== t32 ? (t42 = new Set([...t32, ...(Array.isArray(config) ? config : [config]).map(_temp3$1)].filter(_temp4)), $[19] = config, $[20] = t32, $[21] = t42) : t42 = $[21], t2 = Array.from(t42), $[14] = config, $[15] = resourcesValue, $[16] = t2;
|
|
719
|
+
} else
|
|
720
|
+
t2 = $[16];
|
|
721
|
+
const projectIds = t2;
|
|
722
|
+
let t3;
|
|
723
|
+
$[22] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = /* @__PURE__ */ jsx(ResetChunkReloadFlagOnMount, {}), $[22] = t3) : t3 = $[22];
|
|
724
|
+
const t4 = resourcesValue[DEFAULT_RESOURCE_NAME];
|
|
605
725
|
let t5;
|
|
606
|
-
$[
|
|
726
|
+
$[23] !== children || $[24] !== inferMediaLibraryAndCanvas || $[25] !== resourcesValue ? (t5 = /* @__PURE__ */ jsx(OrganizationResourcesProvider, { resources: resourcesValue, inferMediaLibraryAndCanvas, children }), $[23] = children, $[24] = inferMediaLibraryAndCanvas, $[25] = resourcesValue, $[26] = t5) : t5 = $[26];
|
|
607
727
|
let t6;
|
|
608
|
-
$[
|
|
728
|
+
$[27] !== projectIds || $[28] !== props || $[29] !== t5 ? (t6 = /* @__PURE__ */ jsx(AuthBoundary, { ...props, projectIds, children: t5 }), $[27] = projectIds, $[28] = props, $[29] = t5, $[30] = t6) : t6 = $[30];
|
|
609
729
|
let t7;
|
|
610
|
-
return $[
|
|
611
|
-
|
|
612
|
-
/* @__PURE__ */ jsx(ResourceProvider, { ...
|
|
613
|
-
] }), $[
|
|
730
|
+
return $[31] !== defaultConfig || $[32] !== fallback || $[33] !== t4 || $[34] !== t6 ? (t7 = /* @__PURE__ */ jsxs(ErrorBoundary, { FallbackComponent: ChunkAwareFallback, children: [
|
|
731
|
+
t3,
|
|
732
|
+
/* @__PURE__ */ jsx(ResourceProvider, { ...defaultConfig, resource: t4, fallback, children: t6 })
|
|
733
|
+
] }), $[31] = defaultConfig, $[32] = fallback, $[33] = t4, $[34] = t6, $[35] = t7) : t7 = $[35], t7;
|
|
614
734
|
}
|
|
615
|
-
function
|
|
735
|
+
function _temp4(id) {
|
|
616
736
|
return !!id;
|
|
617
737
|
}
|
|
618
|
-
function
|
|
619
|
-
return
|
|
738
|
+
function _temp3$1(configObj) {
|
|
739
|
+
return configObj.projectId;
|
|
740
|
+
}
|
|
741
|
+
function _temp2$1(resource) {
|
|
742
|
+
return resource.projectId;
|
|
620
743
|
}
|
|
621
744
|
function ChunkAwareFallback(fallbackProps) {
|
|
622
745
|
const $ = c(2);
|
|
@@ -668,12 +791,12 @@ function SanityApp(t0) {
|
|
|
668
791
|
$[8] !== configProp || $[9] !== resolvedConfig || $[10] !== studioWorkspace ? (t2 = () => {
|
|
669
792
|
let timeout;
|
|
670
793
|
const primaryConfig = Array.isArray(resolvedConfig) ? resolvedConfig[0] : resolvedConfig, shouldRedirectWithoutConfig = configProp === void 0 && !studioWorkspace && !primaryConfig;
|
|
671
|
-
return !isInIframe() && !isLocalUrl(window) && (shouldRedirectWithoutConfig || primaryConfig && !isStudioConfig(primaryConfig)) && (timeout = setTimeout(_temp$
|
|
794
|
+
return !isInIframe() && !isLocalUrl(window) && (shouldRedirectWithoutConfig || primaryConfig && !isStudioConfig(primaryConfig)) && (timeout = setTimeout(_temp$4, 1e3)), () => clearTimeout(timeout);
|
|
672
795
|
}, t3 = [configProp, resolvedConfig, studioWorkspace], $[8] = configProp, $[9] = resolvedConfig, $[10] = studioWorkspace, $[11] = t2, $[12] = t3) : (t2 = $[11], t3 = $[12]), useEffect(t2, t3);
|
|
673
796
|
let t4;
|
|
674
797
|
return $[13] !== children || $[14] !== fallback || $[15] !== props || $[16] !== resolvedConfig ? (t4 = /* @__PURE__ */ jsx(SDKProvider, { ...props, fallback, config: resolvedConfig, children }), $[13] = children, $[14] = fallback, $[15] = props, $[16] = resolvedConfig, $[17] = t4) : t4 = $[17], t4;
|
|
675
798
|
}
|
|
676
|
-
function _temp$
|
|
799
|
+
function _temp$4() {
|
|
677
800
|
console.warn("Redirecting to core", REDIRECT_URL), window.location.replace(REDIRECT_URL);
|
|
678
801
|
}
|
|
679
802
|
function renderSanityApp(rootElement, namedSources, options, children) {
|
|
@@ -844,18 +967,7 @@ function useAgentResourceContext(options) {
|
|
|
844
967
|
updateContext();
|
|
845
968
|
}, t3 = [updateContext], $[6] = updateContext, $[7] = t2, $[8] = t3) : (t2 = $[7], t3 = $[8]), useEffect(t2, t3);
|
|
846
969
|
}
|
|
847
|
-
const useAuthToken = createStateSourceHook(getTokenState), useCurrentUser = createStateSourceHook(getCurrentUserState)
|
|
848
|
-
function useDashboardOrganizationId() {
|
|
849
|
-
const $ = c(2), instance = useSanityInstance();
|
|
850
|
-
let t0, t1;
|
|
851
|
-
$[0] !== instance ? (t1 = getDashboardOrganizationId(instance), $[0] = instance, $[1] = t1) : t1 = $[1], t0 = t1;
|
|
852
|
-
const {
|
|
853
|
-
subscribe,
|
|
854
|
-
getCurrent
|
|
855
|
-
} = t0;
|
|
856
|
-
return useSyncExternalStore(subscribe, getCurrent);
|
|
857
|
-
}
|
|
858
|
-
const useClient = createStateSourceHook({
|
|
970
|
+
const useAuthToken = createStateSourceHook(getTokenState), useCurrentUser = createStateSourceHook(getCurrentUserState), useClient = createStateSourceHook({
|
|
859
971
|
getState: (instance, options) => {
|
|
860
972
|
if (!options || typeof options != "object")
|
|
861
973
|
throw new Error('useClient() requires a configuration object with at least an "apiVersion" property. Example: useClient({ apiVersion: "2024-11-12" })');
|
|
@@ -887,7 +999,7 @@ function useFrameConnection(options) {
|
|
|
887
999
|
const [type, handler] = t22, unsubscribe = channel.on(type, handler);
|
|
888
1000
|
messageUnsubscribers.push(unsubscribe);
|
|
889
1001
|
}), () => {
|
|
890
|
-
messageUnsubscribers.forEach(_temp$
|
|
1002
|
+
messageUnsubscribers.forEach(_temp$3), releaseChannel(instance, name), channelRef.current = null, controllerRef.current = null;
|
|
891
1003
|
};
|
|
892
1004
|
}, 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);
|
|
893
1005
|
let t2;
|
|
@@ -909,7 +1021,7 @@ function useFrameConnection(options) {
|
|
|
909
1021
|
sendMessage
|
|
910
1022
|
}, $[11] = t4) : t4 = $[11], t4;
|
|
911
1023
|
}
|
|
912
|
-
function _temp$
|
|
1024
|
+
function _temp$3(unsub) {
|
|
913
1025
|
return unsub();
|
|
914
1026
|
}
|
|
915
1027
|
function useResource() {
|
|
@@ -1238,15 +1350,31 @@ function useWindowTitle(viewTitle) {
|
|
|
1238
1350
|
};
|
|
1239
1351
|
}, t4 = [viewTitle, appTitle], $[4] = appTitle, $[5] = viewTitle, $[6] = t3, $[7] = t4) : (t3 = $[6], t4 = $[7]), useEffect(t3, t4);
|
|
1240
1352
|
}
|
|
1241
|
-
|
|
1353
|
+
function useResolvedProjectId(options) {
|
|
1354
|
+
const $ = c(6);
|
|
1355
|
+
let t0;
|
|
1356
|
+
$[0] !== options ? (t0 = options ?? {}, $[0] = options, $[1] = t0) : t0 = $[1];
|
|
1357
|
+
const {
|
|
1358
|
+
resource
|
|
1359
|
+
} = useNormalizedResourceOptions(t0), contextProjectId = useContext(ProjectContext);
|
|
1360
|
+
let t1;
|
|
1361
|
+
return $[2] !== contextProjectId || $[3] !== options?.projectId || $[4] !== resource ? (t1 = options?.projectId ?? contextProjectId ?? (resource && isDatasetResource(resource) ? resource.projectId : void 0), $[2] = contextProjectId, $[3] = options?.projectId, $[4] = resource, $[5] = t1) : t1 = $[5], t1;
|
|
1362
|
+
}
|
|
1363
|
+
const useDatasetsBase = createStateSourceHook({
|
|
1242
1364
|
getState: getDatasetsState,
|
|
1243
1365
|
shouldSuspend: (instance, projectHandle) => (
|
|
1244
1366
|
// remove `undefined` since we're suspending when that is the case
|
|
1245
1367
|
getDatasetsState(instance, projectHandle).getCurrent() === void 0
|
|
1246
1368
|
),
|
|
1247
|
-
suspender: resolveDatasets
|
|
1248
|
-
|
|
1249
|
-
|
|
1369
|
+
suspender: resolveDatasets
|
|
1370
|
+
}), useDatasets = (options) => {
|
|
1371
|
+
const $ = c(3), projectId = useResolvedProjectId(options);
|
|
1372
|
+
let t0;
|
|
1373
|
+
return $[0] !== options || $[1] !== projectId ? (t0 = projectId ? {
|
|
1374
|
+
...options,
|
|
1375
|
+
projectId
|
|
1376
|
+
} : options, $[0] = options, $[1] = projectId, $[2] = t0) : t0 = $[2], useDatasetsBase(t0);
|
|
1377
|
+
};
|
|
1250
1378
|
function useApplyActions() {
|
|
1251
1379
|
const $ = c(4), instance = useSanityInstance(), resources = useContext(ResourcesContext), effectiveContextResource = useEffectiveContextResource();
|
|
1252
1380
|
let t0;
|
|
@@ -1340,39 +1468,58 @@ const noopSubscribe = () => () => {
|
|
|
1340
1468
|
}, returnUndefined = () => {
|
|
1341
1469
|
};
|
|
1342
1470
|
function useDocumentPermissions(actionOrActions) {
|
|
1343
|
-
const instance = useSanityInstance();
|
|
1471
|
+
const $ = c(13), instance = useSanityInstance();
|
|
1344
1472
|
trackHookUsage(instance, "useDocumentPermissions");
|
|
1345
|
-
const effectiveContextResource = useEffectiveContextResource(), resources = useContext(ResourcesContext)
|
|
1473
|
+
const effectiveContextResource = useEffectiveContextResource(), resources = useContext(ResourcesContext);
|
|
1474
|
+
let t0;
|
|
1475
|
+
if ($[0] !== actionOrActions || $[1] !== effectiveContextResource || $[2] !== resources) {
|
|
1476
|
+
bb0: {
|
|
1477
|
+
const normalized = Array.isArray(actionOrActions) ? actionOrActions.map((action) => normalizeResourceOptions(action, resources, effectiveContextResource)) : [normalizeResourceOptions(actionOrActions, resources, effectiveContextResource)];
|
|
1478
|
+
let resource;
|
|
1479
|
+
for (const action_0 of normalized)
|
|
1480
|
+
if (action_0.resource && (resource || (resource = action_0.resource), !isDeepEqual(action_0.resource, resource))) {
|
|
1481
|
+
t0 = {
|
|
1482
|
+
actions: normalized,
|
|
1483
|
+
resource,
|
|
1484
|
+
error: new Error(`Mismatched resources found in actions. All actions must belong to the same resource. Found "${JSON.stringify(action_0.resource)}" but expected "${JSON.stringify(resource)}".`)
|
|
1485
|
+
};
|
|
1486
|
+
break bb0;
|
|
1487
|
+
}
|
|
1488
|
+
let t12;
|
|
1489
|
+
$[4] !== normalized || $[5] !== resource ? (t12 = {
|
|
1490
|
+
actions: normalized,
|
|
1491
|
+
resource,
|
|
1492
|
+
error: void 0
|
|
1493
|
+
}, $[4] = normalized, $[5] = resource, $[6] = t12) : t12 = $[6], t0 = t12;
|
|
1494
|
+
}
|
|
1495
|
+
$[0] = actionOrActions, $[1] = effectiveContextResource, $[2] = resources, $[3] = t0;
|
|
1496
|
+
} else
|
|
1497
|
+
t0 = $[3];
|
|
1498
|
+
const {
|
|
1346
1499
|
actions: normalizedActions,
|
|
1347
1500
|
resource: actionResource,
|
|
1348
1501
|
error: validationError
|
|
1349
|
-
} =
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
for (const action_0 of normalized)
|
|
1353
|
-
if (action_0.resource && (resource || (resource = action_0.resource), !isDeepEqual(action_0.resource, resource)))
|
|
1354
|
-
return {
|
|
1355
|
-
actions: normalized,
|
|
1356
|
-
resource,
|
|
1357
|
-
error: new Error(`Mismatched resources found in actions. All actions must belong to the same resource. Found "${JSON.stringify(action_0.resource)}" but expected "${JSON.stringify(resource)}".`)
|
|
1358
|
-
};
|
|
1359
|
-
return {
|
|
1360
|
-
actions: normalized,
|
|
1361
|
-
resource,
|
|
1362
|
-
error: void 0
|
|
1363
|
-
};
|
|
1364
|
-
}, [actionOrActions, resources, effectiveContextResource]), effectiveResource = actionResource ?? effectiveContextResource, permissionsOptions = useMemo(() => effectiveResource ? {
|
|
1502
|
+
} = t0, effectiveResource = actionResource ?? effectiveContextResource;
|
|
1503
|
+
let t1;
|
|
1504
|
+
$[7] !== effectiveResource || $[8] !== normalizedActions ? (t1 = effectiveResource ? {
|
|
1365
1505
|
resource: effectiveResource,
|
|
1366
|
-
// `Omit<>` on `DocumentAction` loses the discriminant; runtime values are still actions.
|
|
1367
1506
|
actions: normalizedActions
|
|
1368
|
-
} : void 0, [
|
|
1369
|
-
|
|
1507
|
+
} : void 0, $[7] = effectiveResource, $[8] = normalizedActions, $[9] = t1) : t1 = $[9];
|
|
1508
|
+
const permissionsOptions = t1;
|
|
1509
|
+
let t2;
|
|
1510
|
+
$[10] !== instance || $[11] !== permissionsOptions ? (t2 = permissionsOptions ? getPermissionsState(instance, permissionsOptions) : void 0, $[10] = instance, $[11] = permissionsOptions, $[12] = t2) : t2 = $[12];
|
|
1511
|
+
const stateSource = t2, isDocumentReady = () => stateSource !== void 0 && stateSource.getCurrent() !== void 0, result = useSyncExternalStore(stateSource?.subscribe ?? noopSubscribe, stateSource?.getCurrent ?? returnUndefined);
|
|
1512
|
+
if (validationError)
|
|
1513
|
+
throw validationError;
|
|
1370
1514
|
if (!effectiveResource)
|
|
1371
1515
|
throw new Error("No resource found. Provide a resource via the action handle or wrap with a resource context.");
|
|
1372
1516
|
if (!isDocumentReady())
|
|
1373
|
-
throw firstValueFrom(stateSource.observable.pipe(filter(
|
|
1517
|
+
throw firstValueFrom(stateSource.observable.pipe(filter(_temp$2)));
|
|
1374
1518
|
return result;
|
|
1375
1519
|
}
|
|
1520
|
+
function _temp$2(permissions) {
|
|
1521
|
+
return permissions !== void 0;
|
|
1522
|
+
}
|
|
1376
1523
|
const useDocumentSyncStatusValue = createStateSourceHook({
|
|
1377
1524
|
getState: getDocumentSyncStatus,
|
|
1378
1525
|
shouldSuspend: (instance, doc) => getDocumentSyncStatus(instance, doc).getCurrent() === void 0,
|
|
@@ -1460,17 +1607,28 @@ function useQuery(options) {
|
|
|
1460
1607
|
}), [data, isPending]);
|
|
1461
1608
|
}
|
|
1462
1609
|
const DEFAULT_BATCH_SIZE = 25;
|
|
1463
|
-
function useDocuments({
|
|
1464
|
-
|
|
1465
|
-
params,
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1610
|
+
function useDocuments(t0) {
|
|
1611
|
+
const $ = c(50);
|
|
1612
|
+
let documentType, filter2, orderings, params, rawOptions, search, t1;
|
|
1613
|
+
$[0] !== t0 ? ({
|
|
1614
|
+
batchSize: t1,
|
|
1615
|
+
params,
|
|
1616
|
+
search,
|
|
1617
|
+
filter: filter2,
|
|
1618
|
+
orderings,
|
|
1619
|
+
documentType,
|
|
1620
|
+
...rawOptions
|
|
1621
|
+
} = t0, $[0] = t0, $[1] = documentType, $[2] = filter2, $[3] = orderings, $[4] = params, $[5] = rawOptions, $[6] = search, $[7] = t1) : (documentType = $[1], filter2 = $[2], orderings = $[3], params = $[4], rawOptions = $[5], search = $[6], t1 = $[7]);
|
|
1622
|
+
const batchSize = t1 === void 0 ? DEFAULT_BATCH_SIZE : t1;
|
|
1472
1623
|
useTrackHookUsage("useDocuments");
|
|
1473
|
-
const options = useNormalizedResourceOptions(rawOptions), [limit, setLimit] = useState(batchSize)
|
|
1624
|
+
const options = useNormalizedResourceOptions(rawOptions), [limit, setLimit] = useState(batchSize);
|
|
1625
|
+
let t2;
|
|
1626
|
+
$[8] !== documentType ? (t2 = Array.isArray(documentType) ? documentType : [documentType], $[8] = documentType, $[9] = t2) : t2 = $[9];
|
|
1627
|
+
let t3;
|
|
1628
|
+
$[10] !== t2 ? (t3 = t2.filter(_temp), $[10] = t2, $[11] = t3) : t3 = $[11];
|
|
1629
|
+
const documentTypes = t3;
|
|
1630
|
+
let t4;
|
|
1631
|
+
$[12] !== batchSize || $[13] !== documentTypes || $[14] !== filter2 || $[15] !== options || $[16] !== orderings || $[17] !== params || $[18] !== search ? (t4 = JSON.stringify({
|
|
1474
1632
|
filter: filter2,
|
|
1475
1633
|
search,
|
|
1476
1634
|
params,
|
|
@@ -1478,45 +1636,74 @@ function useDocuments({
|
|
|
1478
1636
|
batchSize,
|
|
1479
1637
|
types: documentTypes,
|
|
1480
1638
|
...options
|
|
1481
|
-
}), [
|
|
1639
|
+
}), $[12] = batchSize, $[13] = documentTypes, $[14] = filter2, $[15] = options, $[16] = orderings, $[17] = params, $[18] = search, $[19] = t4) : t4 = $[19];
|
|
1640
|
+
const key = t4, [prevKey, setPrevKey] = useState(key);
|
|
1482
1641
|
prevKey !== key && (setPrevKey(key), setLimit(batchSize));
|
|
1483
|
-
|
|
1484
|
-
|
|
1642
|
+
let conditions;
|
|
1643
|
+
if ($[20] !== documentTypes?.length || $[21] !== filter2 || $[22] !== search) {
|
|
1644
|
+
conditions = [];
|
|
1645
|
+
const trimmedSearch = search?.trim();
|
|
1485
1646
|
if (trimmedSearch) {
|
|
1486
1647
|
const searchFilter = createGroqSearchFilter(trimmedSearch);
|
|
1487
1648
|
searchFilter && conditions.push(searchFilter);
|
|
1488
1649
|
}
|
|
1489
|
-
|
|
1490
|
-
}
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1650
|
+
documentTypes?.length && conditions.push("(_type in $__types)"), filter2 && conditions.push(`(${filter2})`), $[20] = documentTypes?.length, $[21] = filter2, $[22] = search, $[23] = conditions;
|
|
1651
|
+
} else
|
|
1652
|
+
conditions = $[23];
|
|
1653
|
+
const filterClause = conditions.length ? `[${conditions.join(" && ")}]` : "";
|
|
1654
|
+
let t5;
|
|
1655
|
+
$[24] !== orderings ? (t5 = orderings ? `| order(${orderings.map(_temp3).join(",")})` : "", $[24] = orderings, $[25] = t5) : t5 = $[25];
|
|
1656
|
+
const dataQuery = `*${filterClause}${t5}[0...${limit}]{"documentId":_id,"documentType":_type,...$__handle}`, t6 = `{"count":${`count(*${filterClause})`},"data":${dataQuery}}`;
|
|
1657
|
+
let t7;
|
|
1658
|
+
$[26] !== options.resource ? (t7 = options.resource && isDatasetResource(options.resource) ? pickProperties(options.resource, ["projectId", "dataset"]) : {}, $[26] = options.resource, $[27] = t7) : t7 = $[27];
|
|
1659
|
+
let t8;
|
|
1660
|
+
$[28] !== options ? (t8 = pickProperties(options, ["perspective", "resource"]), $[28] = options, $[29] = t8) : t8 = $[29];
|
|
1661
|
+
let t9;
|
|
1662
|
+
$[30] !== t7 || $[31] !== t8 ? (t9 = {
|
|
1663
|
+
...t7,
|
|
1664
|
+
...t8
|
|
1665
|
+
}, $[30] = t7, $[31] = t8, $[32] = t9) : t9 = $[32];
|
|
1666
|
+
let t10;
|
|
1667
|
+
$[33] !== documentTypes || $[34] !== params || $[35] !== t9 ? (t10 = {
|
|
1668
|
+
...params,
|
|
1669
|
+
__handle: t9,
|
|
1670
|
+
__types: documentTypes
|
|
1671
|
+
}, $[33] = documentTypes, $[34] = params, $[35] = t9, $[36] = t10) : t10 = $[36];
|
|
1672
|
+
let t11;
|
|
1673
|
+
$[37] !== options || $[38] !== t10 || $[39] !== t6 ? (t11 = {
|
|
1497
1674
|
...options,
|
|
1498
|
-
query:
|
|
1499
|
-
params:
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
}), hasMore = data.length < count, loadMore = useCallback(() => {
|
|
1675
|
+
query: t6,
|
|
1676
|
+
params: t10
|
|
1677
|
+
}, $[37] = options, $[38] = t10, $[39] = t6, $[40] = t11) : t11 = $[40];
|
|
1678
|
+
const {
|
|
1679
|
+
data: t12,
|
|
1680
|
+
isPending
|
|
1681
|
+
} = useQuery(t11), {
|
|
1682
|
+
count,
|
|
1683
|
+
data
|
|
1684
|
+
} = t12, hasMore = data.length < count;
|
|
1685
|
+
let t13;
|
|
1686
|
+
$[41] !== batchSize || $[42] !== count ? (t13 = () => {
|
|
1511
1687
|
setLimit((prev) => Math.min(prev + batchSize, count));
|
|
1512
|
-
}, [count,
|
|
1513
|
-
|
|
1688
|
+
}, $[41] = batchSize, $[42] = count, $[43] = t13) : t13 = $[43];
|
|
1689
|
+
const loadMore = t13;
|
|
1690
|
+
let t14;
|
|
1691
|
+
return $[44] !== count || $[45] !== data || $[46] !== hasMore || $[47] !== isPending || $[48] !== loadMore ? (t14 = {
|
|
1514
1692
|
data,
|
|
1515
1693
|
hasMore,
|
|
1516
1694
|
count,
|
|
1517
1695
|
isPending,
|
|
1518
1696
|
loadMore
|
|
1519
|
-
}
|
|
1697
|
+
}, $[44] = count, $[45] = data, $[46] = hasMore, $[47] = isPending, $[48] = loadMore, $[49] = t14) : t14 = $[49], t14;
|
|
1698
|
+
}
|
|
1699
|
+
function _temp3(ordering) {
|
|
1700
|
+
return [ordering.field, ordering.direction.toLowerCase()].map(_temp2).filter(Boolean).join(" ");
|
|
1701
|
+
}
|
|
1702
|
+
function _temp2(str) {
|
|
1703
|
+
return str.trim();
|
|
1704
|
+
}
|
|
1705
|
+
function _temp(i) {
|
|
1706
|
+
return typeof i == "string";
|
|
1520
1707
|
}
|
|
1521
1708
|
const useOrganization = createStateSourceHook({
|
|
1522
1709
|
getState: getOrganizationState,
|
|
@@ -1527,96 +1714,55 @@ const useOrganization = createStateSourceHook({
|
|
|
1527
1714
|
shouldSuspend: (instance, ...params) => getOrganizationsState(instance, ...params).getCurrent() === void 0,
|
|
1528
1715
|
suspender: resolveOrganizations
|
|
1529
1716
|
});
|
|
1530
|
-
function usePaginatedDocuments(
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
search,
|
|
1540
|
-
...rawOptions
|
|
1541
|
-
} = t0, $[0] = t0, $[1] = documentType, $[2] = orderings, $[3] = rawOptions, $[4] = search, $[5] = t1, $[6] = t2, $[7] = t3) : (documentType = $[1], orderings = $[2], rawOptions = $[3], search = $[4], t1 = $[5], t2 = $[6], t3 = $[7]);
|
|
1542
|
-
const filter2 = t1 === void 0 ? "" : t1, pageSize = t2 === void 0 ? 25 : t2;
|
|
1543
|
-
let t4;
|
|
1544
|
-
$[8] !== t3 ? (t4 = t3 === void 0 ? {} : t3, $[8] = t3, $[9] = t4) : t4 = $[9];
|
|
1545
|
-
const params = t4;
|
|
1717
|
+
function usePaginatedDocuments({
|
|
1718
|
+
documentType,
|
|
1719
|
+
filter: filter2 = "",
|
|
1720
|
+
pageSize = 25,
|
|
1721
|
+
params = {},
|
|
1722
|
+
orderings,
|
|
1723
|
+
search,
|
|
1724
|
+
...rawOptions
|
|
1725
|
+
}) {
|
|
1546
1726
|
useTrackHookUsage("usePaginatedDocuments");
|
|
1547
|
-
const options = useNormalizedResourceOptions(rawOptions), [pageIndex, setPageIndex] = useState(0)
|
|
1548
|
-
let t5;
|
|
1549
|
-
$[10] !== filter2 || $[11] !== options || $[12] !== orderings || $[13] !== pageSize || $[14] !== params || $[15] !== search ? (t5 = JSON.stringify({
|
|
1727
|
+
const options = useNormalizedResourceOptions(rawOptions), [pageIndex, setPageIndex] = useState(0), key = JSON.stringify({
|
|
1550
1728
|
filter: filter2,
|
|
1551
1729
|
search,
|
|
1552
1730
|
params,
|
|
1553
1731
|
orderings,
|
|
1554
1732
|
pageSize,
|
|
1555
1733
|
...options
|
|
1556
|
-
}),
|
|
1557
|
-
const key = t5, [prevKey, setPrevKey] = useState(key);
|
|
1734
|
+
}), [prevKey, setPrevKey] = useState(key);
|
|
1558
1735
|
prevKey !== key && (setPrevKey(key), setPageIndex(0));
|
|
1559
|
-
const startIndex = pageIndex * pageSize, endIndex = (pageIndex + 1) * pageSize
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
documentTypes?.length && conditions.push("(_type in $__types)"), filter2 && conditions.push(`(${filter2})`), t8 = conditions.length ? `[${conditions.join(" && ")}]` : "";
|
|
1572
|
-
const filterClause = t8, orderClause = orderings ? `| order(${orderings.map(_temp3).join(",")})` : "", dataQuery = `*${filterClause}${orderClause}[${startIndex}...${endIndex}]{"documentId":_id,"documentType":_type,...$__handle}`, countQuery = `count(*${filterClause})`, t9 = `{"data":${dataQuery},"count":${countQuery}}`;
|
|
1573
|
-
let t10;
|
|
1574
|
-
$[21] !== options.resource ? (t10 = options.resource && isDatasetResource(options.resource) ? pickProperties(options.resource, ["projectId", "dataset"]) : {}, $[21] = options.resource, $[22] = t10) : t10 = $[22];
|
|
1575
|
-
let t11;
|
|
1576
|
-
$[23] !== options ? (t11 = pickProperties(options, ["perspective", "resource"]), $[23] = options, $[24] = t11) : t11 = $[24];
|
|
1577
|
-
let t12;
|
|
1578
|
-
$[25] !== t10 || $[26] !== t11 ? (t12 = {
|
|
1579
|
-
...t10,
|
|
1580
|
-
...t11
|
|
1581
|
-
}, $[25] = t10, $[26] = t11, $[27] = t12) : t12 = $[27];
|
|
1582
|
-
let t13;
|
|
1583
|
-
$[28] !== documentTypes || $[29] !== params || $[30] !== t12 ? (t13 = {
|
|
1584
|
-
...params,
|
|
1585
|
-
__types: documentTypes,
|
|
1586
|
-
__handle: t12
|
|
1587
|
-
}, $[28] = documentTypes, $[29] = params, $[30] = t12, $[31] = t13) : t13 = $[31];
|
|
1588
|
-
let t14;
|
|
1589
|
-
$[32] !== options || $[33] !== t13 || $[34] !== t9 ? (t14 = {
|
|
1590
|
-
...options,
|
|
1591
|
-
query: t9,
|
|
1592
|
-
params: t13
|
|
1593
|
-
}, $[32] = options, $[33] = t13, $[34] = t9, $[35] = t14) : t14 = $[35];
|
|
1594
|
-
const {
|
|
1595
|
-
data: t15,
|
|
1736
|
+
const startIndex = pageIndex * pageSize, endIndex = (pageIndex + 1) * pageSize, documentTypes = (Array.isArray(documentType) ? documentType : [documentType]).filter((i) => typeof i == "string"), filterClause = useMemo(() => {
|
|
1737
|
+
const conditions = [], trimmedSearch = search?.trim();
|
|
1738
|
+
if (trimmedSearch) {
|
|
1739
|
+
const searchFilter = createGroqSearchFilter(trimmedSearch);
|
|
1740
|
+
searchFilter && conditions.push(searchFilter);
|
|
1741
|
+
}
|
|
1742
|
+
return documentTypes?.length && conditions.push("(_type in $__types)"), filter2 && conditions.push(`(${filter2})`), conditions.length ? `[${conditions.join(" && ")}]` : "";
|
|
1743
|
+
}, [filter2, search, documentTypes?.length]), orderClause = orderings ? `| order(${orderings.map((ordering) => [ordering.field, ordering.direction.toLowerCase()].map((str) => str.trim()).filter(Boolean).join(" ")).join(",")})` : "", dataQuery = `*${filterClause}${orderClause}[${startIndex}...${endIndex}]{"documentId":_id,"documentType":_type,...$__handle}`, countQuery = `count(*${filterClause})`, {
|
|
1744
|
+
data: {
|
|
1745
|
+
data,
|
|
1746
|
+
count
|
|
1747
|
+
},
|
|
1596
1748
|
isPending
|
|
1597
|
-
} = useQuery(
|
|
1598
|
-
|
|
1599
|
-
count
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
$[40] !== totalPages ? (t19 = () => setPageIndex(totalPages - 1), $[40] = totalPages, $[41] = t19) : t19 = $[41];
|
|
1612
|
-
const lastPage = t19;
|
|
1613
|
-
let t20;
|
|
1614
|
-
$[42] !== totalPages ? (t20 = (pageNumber) => {
|
|
1749
|
+
} = useQuery({
|
|
1750
|
+
...options,
|
|
1751
|
+
query: `{"data":${dataQuery},"count":${countQuery}}`,
|
|
1752
|
+
params: {
|
|
1753
|
+
...params,
|
|
1754
|
+
__types: documentTypes,
|
|
1755
|
+
__handle: {
|
|
1756
|
+
// keep projectId/dataset for backward compat until v4; resource is added
|
|
1757
|
+
// intentionally so that hook consumers can resolve the correct resource
|
|
1758
|
+
...options.resource && isDatasetResource(options.resource) ? pickProperties(options.resource, ["projectId", "dataset"]) : {},
|
|
1759
|
+
...pickProperties(options, ["perspective", "resource"])
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
}), totalPages = Math.ceil(count / pageSize), currentPage = pageIndex + 1, firstPage = useCallback(() => setPageIndex(0), []), previousPage = useCallback(() => setPageIndex((prev) => Math.max(prev - 1, 0)), []), nextPage = useCallback(() => setPageIndex((prev_0) => Math.min(prev_0 + 1, totalPages - 1)), [totalPages]), lastPage = useCallback(() => setPageIndex(totalPages - 1), [totalPages]), goToPage = useCallback((pageNumber) => {
|
|
1615
1763
|
pageNumber < 1 || pageNumber > totalPages || setPageIndex(pageNumber - 1);
|
|
1616
|
-
},
|
|
1617
|
-
|
|
1618
|
-
let t21;
|
|
1619
|
-
return $[44] !== count || $[45] !== currentPage || $[46] !== data || $[47] !== endIndex || $[48] !== goToPage || $[49] !== hasFirstPage || $[50] !== hasLastPage || $[51] !== hasNextPage || $[52] !== hasPreviousPage || $[53] !== isPending || $[54] !== lastPage || $[55] !== nextPage || $[56] !== pageSize || $[57] !== startIndex || $[58] !== totalPages ? (t21 = {
|
|
1764
|
+
}, [totalPages]), hasFirstPage = pageIndex > 0, hasPreviousPage = pageIndex > 0, hasNextPage = pageIndex < totalPages - 1, hasLastPage = pageIndex < totalPages - 1;
|
|
1765
|
+
return {
|
|
1620
1766
|
data,
|
|
1621
1767
|
isPending,
|
|
1622
1768
|
pageSize,
|
|
@@ -1634,19 +1780,7 @@ function usePaginatedDocuments(t0) {
|
|
|
1634
1780
|
lastPage,
|
|
1635
1781
|
hasLastPage,
|
|
1636
1782
|
goToPage
|
|
1637
|
-
}
|
|
1638
|
-
}
|
|
1639
|
-
function _temp4(prev) {
|
|
1640
|
-
return Math.max(prev - 1, 0);
|
|
1641
|
-
}
|
|
1642
|
-
function _temp3(ordering) {
|
|
1643
|
-
return [ordering.field, ordering.direction.toLowerCase()].map(_temp2).filter(Boolean).join(" ");
|
|
1644
|
-
}
|
|
1645
|
-
function _temp2(str) {
|
|
1646
|
-
return str.trim();
|
|
1647
|
-
}
|
|
1648
|
-
function _temp(i) {
|
|
1649
|
-
return typeof i == "string";
|
|
1783
|
+
};
|
|
1650
1784
|
}
|
|
1651
1785
|
function usePresence(t0) {
|
|
1652
1786
|
const $ = c(14);
|
|
@@ -1657,45 +1791,57 @@ function usePresence(t0) {
|
|
|
1657
1791
|
throw new Error("usePresence() does not support media library resources. Presence tracking requires a canvas or dataset resource.");
|
|
1658
1792
|
const sanityInstance = useSanityInstance();
|
|
1659
1793
|
trackHookUsage(sanityInstance, "usePresence");
|
|
1660
|
-
let t2
|
|
1661
|
-
$[2] !== normalizedOptions || $[3] !== sanityInstance ? (
|
|
1794
|
+
let t2;
|
|
1795
|
+
$[2] !== normalizedOptions || $[3] !== sanityInstance ? (t2 = getPresence(sanityInstance, normalizedOptions), $[2] = normalizedOptions, $[3] = sanityInstance, $[4] = t2) : t2 = $[4];
|
|
1662
1796
|
const source = t2;
|
|
1663
|
-
let
|
|
1664
|
-
$[5] !== source ? (
|
|
1665
|
-
const subscribe =
|
|
1666
|
-
let
|
|
1667
|
-
$[7] !== source ? (
|
|
1668
|
-
const locations = useSyncExternalStore(subscribe,
|
|
1797
|
+
let t3;
|
|
1798
|
+
$[5] !== source ? (t3 = (callback) => source.subscribe(callback), $[5] = source, $[6] = t3) : t3 = $[6];
|
|
1799
|
+
const subscribe = t3;
|
|
1800
|
+
let t4, t5;
|
|
1801
|
+
$[7] !== source ? (t4 = () => source.getCurrent(), t5 = () => source.getCurrent(), $[7] = source, $[8] = t4, $[9] = t5) : (t4 = $[8], t5 = $[9]);
|
|
1802
|
+
const locations = useSyncExternalStore(subscribe, t4, t5);
|
|
1803
|
+
let t6;
|
|
1804
|
+
$[10] !== locations ? (t6 = locations || [], $[10] = locations, $[11] = t6) : t6 = $[11];
|
|
1669
1805
|
let t7;
|
|
1670
|
-
$[
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1806
|
+
return $[12] !== t6 ? (t7 = {
|
|
1807
|
+
locations: t6
|
|
1808
|
+
}, $[12] = t6, $[13] = t7) : t7 = $[13], t7;
|
|
1809
|
+
}
|
|
1810
|
+
function useDocumentProjection(t0) {
|
|
1811
|
+
const $ = c(13);
|
|
1812
|
+
let docHandle, projection, ref;
|
|
1813
|
+
$[0] !== t0 ? ({
|
|
1814
|
+
ref,
|
|
1815
|
+
projection,
|
|
1816
|
+
...docHandle
|
|
1817
|
+
} = t0, $[0] = t0, $[1] = docHandle, $[2] = projection, $[3] = ref) : (docHandle = $[1], projection = $[2], ref = $[3]);
|
|
1681
1818
|
const instance = useSanityInstance();
|
|
1682
1819
|
trackHookUsage(instance, "useDocumentProjection");
|
|
1683
|
-
|
|
1820
|
+
let t1;
|
|
1821
|
+
$[4] !== projection ? (t1 = projection.trim(), $[4] = projection, $[5] = t1) : t1 = $[5];
|
|
1822
|
+
const normalizedProjection = t1, normalizedDocHandle = useNormalizedResourceOptions(docHandle);
|
|
1823
|
+
let t2;
|
|
1824
|
+
$[6] !== instance || $[7] !== normalizedDocHandle || $[8] !== normalizedProjection ? (t2 = getProjectionState(instance, {
|
|
1684
1825
|
...normalizedDocHandle,
|
|
1685
1826
|
projection: normalizedProjection
|
|
1686
|
-
}), [instance, normalizedDocHandle, normalizedProjection]);
|
|
1827
|
+
}), $[6] = instance, $[7] = normalizedDocHandle, $[8] = normalizedProjection, $[9] = t2) : t2 = $[9];
|
|
1828
|
+
const stateSource = t2;
|
|
1687
1829
|
if (stateSource.getCurrent()?.data === null)
|
|
1688
1830
|
throw resolveProjection(instance, {
|
|
1689
1831
|
...normalizedDocHandle,
|
|
1690
1832
|
projection: normalizedProjection
|
|
1691
1833
|
});
|
|
1692
|
-
|
|
1834
|
+
let t3;
|
|
1835
|
+
return $[10] !== ref || $[11] !== stateSource ? (t3 = (onStoreChanged) => {
|
|
1693
1836
|
const subscription = new Observable((observer) => {
|
|
1694
1837
|
if (typeof IntersectionObserver > "u" || typeof HTMLElement > "u") {
|
|
1695
1838
|
observer.next(!0);
|
|
1696
1839
|
return;
|
|
1697
1840
|
}
|
|
1698
|
-
const intersectionObserver = new IntersectionObserver((
|
|
1841
|
+
const intersectionObserver = new IntersectionObserver((t4) => {
|
|
1842
|
+
const [entry] = t4;
|
|
1843
|
+
return observer.next(entry.isIntersecting);
|
|
1844
|
+
}, {
|
|
1699
1845
|
rootMargin: "0px",
|
|
1700
1846
|
threshold: 0
|
|
1701
1847
|
});
|
|
@@ -1704,8 +1850,7 @@ function useDocumentProjection({
|
|
|
1704
1850
|
next: onStoreChanged
|
|
1705
1851
|
});
|
|
1706
1852
|
return () => subscription.unsubscribe();
|
|
1707
|
-
}, [stateSource,
|
|
1708
|
-
return useSyncExternalStore(subscribe, stateSource.getCurrent);
|
|
1853
|
+
}, $[10] = ref, $[11] = stateSource, $[12] = t3) : t3 = $[12], useSyncExternalStore(t3, stateSource.getCurrent);
|
|
1709
1854
|
}
|
|
1710
1855
|
function useDocumentPreview(t0) {
|
|
1711
1856
|
const $ = c(13);
|
|
@@ -1724,21 +1869,26 @@ function useDocumentPreview(t0) {
|
|
|
1724
1869
|
ref
|
|
1725
1870
|
}, $[3] = normalizedDocHandle, $[4] = ref, $[5] = t1) : t1 = $[5];
|
|
1726
1871
|
const projectionResult = useDocumentProjection(t1);
|
|
1727
|
-
let t2
|
|
1728
|
-
$[6] !== instance || $[7] !== normalizedDocHandle.resource || $[8] !== projectionResult.data ? (
|
|
1872
|
+
let t2;
|
|
1873
|
+
$[6] !== instance || $[7] !== normalizedDocHandle.resource || $[8] !== projectionResult.data ? (t2 = transformProjectionToPreview(instance, projectionResult.data, normalizedDocHandle.resource), $[6] = instance, $[7] = normalizedDocHandle.resource, $[8] = projectionResult.data, $[9] = t2) : t2 = $[9];
|
|
1729
1874
|
const previewValue = t2;
|
|
1730
|
-
let
|
|
1731
|
-
return $[10] !== previewValue || $[11] !== projectionResult.isPending ? (
|
|
1875
|
+
let t3;
|
|
1876
|
+
return $[10] !== previewValue || $[11] !== projectionResult.isPending ? (t3 = {
|
|
1732
1877
|
data: previewValue,
|
|
1733
1878
|
isPending: projectionResult.isPending
|
|
1734
|
-
}, $[10] = previewValue, $[11] = projectionResult.isPending, $[12] =
|
|
1879
|
+
}, $[10] = previewValue, $[11] = projectionResult.isPending, $[12] = t3) : t3 = $[12], t3;
|
|
1735
1880
|
}
|
|
1736
|
-
const
|
|
1881
|
+
const useProjectBase = createStateSourceHook({
|
|
1737
1882
|
getState: getProjectState,
|
|
1738
1883
|
shouldSuspend: (instance, ...params) => getProjectState(instance, ...params).getCurrent() === void 0,
|
|
1739
|
-
suspender: resolveProject
|
|
1740
|
-
|
|
1741
|
-
|
|
1884
|
+
suspender: resolveProject
|
|
1885
|
+
}), useProject = (options) => {
|
|
1886
|
+
const projectId = useResolvedProjectId(options);
|
|
1887
|
+
return useProjectBase(projectId ? {
|
|
1888
|
+
...options,
|
|
1889
|
+
projectId
|
|
1890
|
+
} : options);
|
|
1891
|
+
}, useProjects = createStateSourceHook({
|
|
1742
1892
|
getState: getProjectsState,
|
|
1743
1893
|
shouldSuspend: (instance, ...params) => getProjectsState(instance, ...params).getCurrent() === void 0,
|
|
1744
1894
|
suspender: resolveProjects
|
|
@@ -1779,41 +1929,79 @@ function usePerspective(perspectiveHandle) {
|
|
|
1779
1929
|
return usePerspectiveValue(normalizedOptions);
|
|
1780
1930
|
}
|
|
1781
1931
|
function useUser(options) {
|
|
1782
|
-
const instance = useSanityInstance();
|
|
1932
|
+
const $ = c(17), instance = useSanityInstance();
|
|
1783
1933
|
trackHookUsage(instance, "useUser");
|
|
1784
|
-
const [isPending, startTransition] = useTransition()
|
|
1785
|
-
|
|
1934
|
+
const [isPending, startTransition] = useTransition();
|
|
1935
|
+
let t0;
|
|
1936
|
+
$[0] !== instance || $[1] !== options ? (t0 = getUsersKey(instance, options), $[0] = instance, $[1] = options, $[2] = t0) : t0 = $[2];
|
|
1937
|
+
const key = t0, [deferredKey, setDeferredKey] = useState(key);
|
|
1938
|
+
let t1;
|
|
1939
|
+
$[3] !== deferredKey ? (t1 = parseUsersKey(deferredKey), $[3] = deferredKey, $[4] = t1) : t1 = $[4];
|
|
1940
|
+
const deferred = t1;
|
|
1941
|
+
let t2;
|
|
1942
|
+
$[5] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = new AbortController(), $[5] = t2) : t2 = $[5];
|
|
1943
|
+
const [ref, setRef] = useState(t2);
|
|
1944
|
+
let t3, t4;
|
|
1945
|
+
$[6] !== deferredKey || $[7] !== key || $[8] !== ref ? (t3 = () => {
|
|
1786
1946
|
key !== deferredKey && startTransition(() => {
|
|
1787
1947
|
ref.signal.aborted || (ref.abort(), setRef(new AbortController())), setDeferredKey(key);
|
|
1788
1948
|
});
|
|
1789
|
-
}, [deferredKey, key, ref]);
|
|
1949
|
+
}, t4 = [deferredKey, key, ref], $[6] = deferredKey, $[7] = key, $[8] = ref, $[9] = t3, $[10] = t4) : (t3 = $[9], t4 = $[10]), useEffect(t3, t4);
|
|
1950
|
+
const t5 = deferred;
|
|
1951
|
+
let t6;
|
|
1952
|
+
$[11] !== instance || $[12] !== t5 ? (t6 = getUsersState(instance, t5), $[11] = instance, $[12] = t5, $[13] = t6) : t6 = $[13];
|
|
1790
1953
|
const {
|
|
1791
1954
|
getCurrent,
|
|
1792
1955
|
subscribe
|
|
1793
|
-
} =
|
|
1956
|
+
} = t6;
|
|
1794
1957
|
if (getCurrent() === void 0)
|
|
1795
1958
|
throw resolveUsers(instance, {
|
|
1796
1959
|
...deferred,
|
|
1797
1960
|
signal: ref.signal
|
|
1798
1961
|
});
|
|
1799
|
-
|
|
1800
|
-
|
|
1962
|
+
const data = useSyncExternalStore(subscribe, getCurrent)?.data[0];
|
|
1963
|
+
let t7;
|
|
1964
|
+
return $[14] !== data || $[15] !== isPending ? (t7 = {
|
|
1965
|
+
data,
|
|
1801
1966
|
isPending
|
|
1802
|
-
};
|
|
1967
|
+
}, $[14] = data, $[15] = isPending, $[16] = t7) : t7 = $[16], t7;
|
|
1968
|
+
}
|
|
1969
|
+
function withResolvedProjectId(options, projectId) {
|
|
1970
|
+
return projectId ? options ? options.resourceType === "organization" || options.organizationId || options.projectId ? options : {
|
|
1971
|
+
...options,
|
|
1972
|
+
projectId
|
|
1973
|
+
} : {
|
|
1974
|
+
projectId
|
|
1975
|
+
} : options;
|
|
1803
1976
|
}
|
|
1804
1977
|
function useUsers(options) {
|
|
1805
|
-
const instance = useSanityInstance();
|
|
1978
|
+
const $ = c(25), instance = useSanityInstance();
|
|
1806
1979
|
trackHookUsage(instance, "useUsers");
|
|
1807
|
-
const [isPending, startTransition] = useTransition(),
|
|
1808
|
-
|
|
1980
|
+
const [isPending, startTransition] = useTransition(), resolvedProjectId = useResolvedProjectId(options);
|
|
1981
|
+
let t0;
|
|
1982
|
+
$[0] !== options || $[1] !== resolvedProjectId ? (t0 = withResolvedProjectId(options, resolvedProjectId), $[0] = options, $[1] = resolvedProjectId, $[2] = t0) : t0 = $[2];
|
|
1983
|
+
const effectiveOptions = t0;
|
|
1984
|
+
let t1;
|
|
1985
|
+
$[3] !== effectiveOptions || $[4] !== instance ? (t1 = getUsersKey(instance, effectiveOptions), $[3] = effectiveOptions, $[4] = instance, $[5] = t1) : t1 = $[5];
|
|
1986
|
+
const key = t1, [deferredKey, setDeferredKey] = useState(key);
|
|
1987
|
+
let t2;
|
|
1988
|
+
$[6] !== deferredKey ? (t2 = parseUsersKey(deferredKey), $[6] = deferredKey, $[7] = t2) : t2 = $[7];
|
|
1989
|
+
const deferred = t2;
|
|
1990
|
+
let t3;
|
|
1991
|
+
$[8] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = new AbortController(), $[8] = t3) : t3 = $[8];
|
|
1992
|
+
const [ref, setRef] = useState(t3);
|
|
1993
|
+
let t4, t5;
|
|
1994
|
+
$[9] !== deferredKey || $[10] !== key || $[11] !== ref ? (t4 = () => {
|
|
1809
1995
|
key !== deferredKey && startTransition(() => {
|
|
1810
1996
|
ref.signal.aborted || (ref.abort(), setRef(new AbortController())), setDeferredKey(key);
|
|
1811
1997
|
});
|
|
1812
|
-
}, [deferredKey, key, ref]);
|
|
1998
|
+
}, t5 = [deferredKey, key, ref], $[9] = deferredKey, $[10] = key, $[11] = ref, $[12] = t4, $[13] = t5) : (t4 = $[12], t5 = $[13]), useEffect(t4, t5);
|
|
1999
|
+
let t6;
|
|
2000
|
+
$[14] !== deferred || $[15] !== instance ? (t6 = getUsersState(instance, deferred), $[14] = deferred, $[15] = instance, $[16] = t6) : t6 = $[16];
|
|
1813
2001
|
const {
|
|
1814
2002
|
getCurrent,
|
|
1815
2003
|
subscribe
|
|
1816
|
-
} =
|
|
2004
|
+
} = t6;
|
|
1817
2005
|
if (getCurrent() === void 0)
|
|
1818
2006
|
throw resolveUsers(instance, {
|
|
1819
2007
|
...deferred,
|
|
@@ -1822,17 +2010,21 @@ function useUsers(options) {
|
|
|
1822
2010
|
const {
|
|
1823
2011
|
data,
|
|
1824
2012
|
hasMore
|
|
1825
|
-
} = useSyncExternalStore(subscribe, getCurrent)
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
2013
|
+
} = useSyncExternalStore(subscribe, getCurrent);
|
|
2014
|
+
let t7;
|
|
2015
|
+
$[17] !== effectiveOptions || $[18] !== instance ? (t7 = () => {
|
|
2016
|
+
loadMoreUsers(instance, effectiveOptions);
|
|
2017
|
+
}, $[17] = effectiveOptions, $[18] = instance, $[19] = t7) : t7 = $[19];
|
|
2018
|
+
const loadMore = t7;
|
|
2019
|
+
let t8;
|
|
2020
|
+
return $[20] !== data || $[21] !== hasMore || $[22] !== isPending || $[23] !== loadMore ? (t8 = {
|
|
1829
2021
|
data,
|
|
1830
2022
|
hasMore,
|
|
1831
2023
|
isPending,
|
|
1832
2024
|
loadMore
|
|
1833
|
-
};
|
|
2025
|
+
}, $[20] = data, $[21] = hasMore, $[22] = isPending, $[23] = loadMore, $[24] = t8) : t8 = $[24], t8;
|
|
1834
2026
|
}
|
|
1835
|
-
var version = "2.
|
|
2027
|
+
var version = "2.16.0";
|
|
1836
2028
|
function getEnv(key) {
|
|
1837
2029
|
if (typeof import.meta < "u" && import.meta.env)
|
|
1838
2030
|
return import.meta.env[key];
|