@sanity/sdk-react 2.14.1 → 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.
Files changed (32) hide show
  1. package/README.md +40 -30
  2. package/dist/index.d.ts +512 -335
  3. package/dist/index.js +540 -332
  4. package/dist/index.js.map +1 -1
  5. package/package.json +37 -39
  6. package/src/_exports/sdk-react.ts +1 -0
  7. package/src/components/SDKProvider.test.tsx +135 -22
  8. package/src/components/SDKProvider.tsx +54 -17
  9. package/src/components/SanityApp.tsx +29 -0
  10. package/src/components/auth/AuthBoundary.recovery.test.tsx +86 -0
  11. package/src/components/auth/AuthBoundary.tsx +11 -1
  12. package/src/context/OrganizationResourcesProvider.test.tsx +189 -0
  13. package/src/context/OrganizationResourcesProvider.tsx +111 -0
  14. package/src/context/ProjectContext.ts +15 -0
  15. package/src/context/ResourceProvider.test.tsx +57 -1
  16. package/src/context/ResourceProvider.tsx +30 -9
  17. package/src/hooks/datasets/useDatasets.test.tsx +116 -0
  18. package/src/hooks/datasets/useDatasets.ts +20 -8
  19. package/src/hooks/document/useApplyDocumentActions.ts +1 -1
  20. package/src/hooks/document/useCreateDocument.test.tsx +83 -0
  21. package/src/hooks/document/useCreateDocument.ts +117 -0
  22. package/src/hooks/document/useDocument.ts +2 -2
  23. package/src/hooks/helpers/useResolvedProjectId.test.tsx +59 -0
  24. package/src/hooks/helpers/useResolvedProjectId.ts +35 -0
  25. package/src/hooks/projects/useProject.test.tsx +114 -0
  26. package/src/hooks/projects/useProject.ts +17 -7
  27. package/src/hooks/users/useUsers.test.tsx +101 -2
  28. package/src/hooks/users/useUsers.ts +35 -3
  29. package/src/utils/resolveOrgResources.test.ts +111 -0
  30. package/src/utils/resolveOrgResources.ts +69 -0
  31. package/src/hooks/datasets/useDatasets.test.ts +0 -80
  32. 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, createSanityInstance, isDatasetResource, agentGenerate, agentPatch, agentPrompt, agentTransform, agentTranslate, getTokenState, getCurrentUserState, getDashboardOrganizationId, getClientState, getOrCreateController, getOrCreateChannel, releaseChannel, isMediaLibraryResource, isCanvasResource, getFavoritesState, resolveFavoritesState, resolveDatasets, getDatasetsState, applyDocumentActions, 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";
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$8), messageUnsubscribers.current = [];
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$8(unsubscribe) {
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$7) && errorContainer.remove();
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$7(div) {
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 t2;
144
- return $[0] !== children ? (t2 = /* @__PURE__ */ jsx(DashboardTokenRefresh, { children }), $[0] = children, $[1] = t2) : t2 = $[1], t2;
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, t1;
151
- $[0] !== instance ? (t1 = getLoginUrlState(instance), $[0] = instance, $[1] = t1) : t1 = $[1], t0 = t1;
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$6
266
+ onClick: _temp$7
270
267
  } }), $[3] = t3) : t3 = $[3], t3;
271
268
  }
272
- function _temp$6() {
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
- const t2 = `https://sanity.io/manage/project/${projectId}/api`;
282
- let t3;
283
- if ($[0] !== t2) {
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
- t3 = $[1];
288
- t1 = t3;
282
+ t1 = $[1];
289
283
  const corsUrl = t1;
290
- let t4;
291
- return $[2] !== corsUrl || $[3] !== error || $[4] !== projectId ? (t4 = /* @__PURE__ */ jsx(Error$1, { heading: "Before you continue\u2026", ...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] = t4) : t4 = $[5], t4;
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$5);
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$5(replacementLocation) {
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 t5, message = "Please try again or contact support if the problem persists.", retry = !0;
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 t62;
388
- $[7] !== clientError ? (t62 = getClientErrorApiDescription(clientError), $[7] = clientError, $[8] = t62) : t62 = $[8];
389
- const description = t62;
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,56 +390,58 @@ function LoginError(t0) {
396
390
  }
397
391
  }
398
392
  authState.type !== AuthStateType.ERROR && error instanceof ConfigurationError && (message = error.message, retry = !0);
399
- let t6;
400
- $[9] !== message || $[10] !== retry ? (t6 = {
393
+ let t5;
394
+ $[9] !== message || $[10] !== retry ? (t5 = {
401
395
  authErrorMessage: message,
402
396
  showRetryCta: retry
403
- }, $[9] = message, $[10] = retry, $[11] = t6) : t6 = $[11], t5 = t6;
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 t7, t8;
409
- $[12] !== clientError || $[13] !== handleRetry || $[14] !== isInDashboard || $[15] !== isProjectUserNotFound ? (t7 = () => {
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
- }, t8 = [clientError, handleRetry, isInDashboard, isProjectUserNotFound], $[12] = clientError, $[13] = handleRetry, $[14] = isInDashboard, $[15] = isProjectUserNotFound, $[16] = t7, $[17] = t8) : (t7 = $[16], t8 = $[17]), useEffect(t7, t8);
412
- let t9;
413
- $[18] !== dashboardAccessProjectId ? (t9 = dashboardAccessProjectId && /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(DashboardAccessRequest, { projectId: dashboardAccessProjectId }) }), $[18] = dashboardAccessProjectId, $[19] = t9) : t9 = $[19];
414
- const t10 = error instanceof ConfigurationError ? "Configuration Error" : "Authentication Error";
415
- let t11;
416
- $[20] !== handleRetry || $[21] !== showRetryCta ? (t11 = 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] = t11) : t11 = $[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
- $[23] !== authErrorMessage || $[24] !== t10 || $[25] !== t11 ? (t12 = /* @__PURE__ */ jsx(Error$1, { heading: t10, description: authErrorMessage, cta: t11 }), $[23] = authErrorMessage, $[24] = t10, $[25] = t11, $[26] = t12) : t12 = $[26];
422
- let t13;
423
- return $[27] !== t12 || $[28] !== t9 ? (t13 = /* @__PURE__ */ jsxs(Fragment, { children: [
424
- t9,
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");
430
424
  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);
431
425
  }
432
426
  function AuthBoundary(t0) {
433
- const $ = c(10);
427
+ const $ = c(13);
434
428
  let props, t1;
435
429
  $[0] !== t0 ? ({
436
430
  LoginErrorComponent: t1,
437
431
  ...props
438
432
  } = t0, $[0] = t0, $[1] = props, $[2] = t1) : (props = $[1], t1 = $[2]);
439
- const LoginErrorComponent = t1 === void 0 ? LoginError : t1;
440
- let t2, t3;
441
- $[3] !== LoginErrorComponent ? (t3 = function(fallbackProps) {
433
+ const LoginErrorComponent = t1 === void 0 ? LoginError : t1, authState = useAuthState(), sessionResetKey = authState.type === AuthStateType.LOGGED_IN ? authState.token : authState.type;
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] = t3) : t3 = $[4], t2 = t3;
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
- $[5] !== props ? (t4 = /* @__PURE__ */ jsx(AuthSwitch, { ...props }), $[5] = props, $[6] = t4) : t4 = $[6];
442
+ $[7] !== props ? (t4 = /* @__PURE__ */ jsx(AuthSwitch, { ...props }), $[7] = props, $[8] = t4) : t4 = $[8];
447
443
  let t5;
448
- return $[7] !== FallbackComponent || $[8] !== t4 ? (t5 = /* @__PURE__ */ jsx(ComlinkTokenRefreshProvider, { children: /* @__PURE__ */ jsx(ErrorBoundary, { FallbackComponent, children: t4 }) }), $[7] = FallbackComponent, $[8] = t4, $[9] = t5) : t5 = $[9], t5;
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;
449
445
  }
450
446
  function AuthSwitch(t0) {
451
447
  const $ = c(16);
@@ -485,7 +481,95 @@ function AuthSwitch(t0) {
485
481
  }
486
482
  const SDKStudioContext = createContext(null);
487
483
  SDKStudioContext.displayName = "SDKStudioContext";
488
- const DEFAULT_RESOURCE_NAME = "default", ResourceContext = createContext(void 0), PerspectiveContext = createContext(void 0);
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);
489
573
  function SanityInstanceProvider(t0) {
490
574
  const $ = c(6), {
491
575
  instance,
@@ -499,7 +583,7 @@ function SanityInstanceProvider(t0) {
499
583
  }
500
584
  const DEFAULT_FALLBACK = /* @__PURE__ */ jsx(Fragment, { children: "Warning: No fallback provided. Please supply a fallback prop to ensure proper Suspense handling." });
501
585
  function ResourceProvider(t0) {
502
- const $ = c(29);
586
+ const $ = c(35);
503
587
  let children, config, fallback, resource;
504
588
  $[0] !== t0 ? ({
505
589
  children,
@@ -507,7 +591,7 @@ function ResourceProvider(t0) {
507
591
  resource,
508
592
  ...config
509
593
  } = t0, $[0] = t0, $[1] = children, $[2] = config, $[3] = fallback, $[4] = resource) : (children = $[1], config = $[2], fallback = $[3], resource = $[4]);
510
- const parentPerspective = useContext(PerspectiveContext), parentResource = useContext(ResourceContext), parentInstance = useContext(SanityInstanceContext), {
594
+ const parentPerspective = useContext(PerspectiveContext), parentResource = useContext(ResourceContext), parentInstance = useContext(SanityInstanceContext), parentProjectId = useContext(ProjectContext), {
511
595
  projectId,
512
596
  dataset,
513
597
  perspective
@@ -525,96 +609,137 @@ function ResourceProvider(t0) {
525
609
  }, $[8] = dataset, $[9] = projectId, $[10] = t32) : t32 = $[10], t2 = t32;
526
610
  break bb0;
527
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
+ }
528
620
  t2 = void 0;
529
621
  }
530
622
  const configResource = t2;
531
623
  let t3;
532
- t3 = resource ?? configResource ?? parentResource;
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
+ }
533
639
  const effectiveResource = t3;
534
- let t4, t5;
535
- $[11] !== effectiveResource || $[12] !== instance ? (t4 = () => {
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 = () => {
536
651
  effectiveResource && isDatasetResource(effectiveResource) && initTelemetry(instance, effectiveResource.projectId);
537
- }, t5 = [instance, effectiveResource], $[11] = effectiveResource, $[12] = instance, $[13] = t4, $[14] = t5) : (t4 = $[13], t5 = $[14]), useEffect(t4, t5);
652
+ }, t6 = [instance, effectiveResource], $[14] = effectiveResource, $[15] = instance, $[16] = t5, $[17] = t6) : (t5 = $[16], t6 = $[17]), useEffect(t5, t6);
538
653
  const disposal = useRef(null);
539
- let t6, t7;
540
- $[15] !== instance || $[16] !== parentInstance ? (t6 = () => (disposal.current !== null && instance === disposal.current.instance && (clearTimeout(disposal.current.timeoutId), disposal.current = null), () => {
654
+ let t7, t8;
655
+ $[18] !== instance || $[19] !== parentInstance ? (t7 = () => (disposal.current !== null && instance === disposal.current.instance && (clearTimeout(disposal.current.timeoutId), disposal.current = null), () => {
541
656
  disposal.current = {
542
657
  instance,
543
658
  timeoutId: setTimeout(() => {
544
659
  !instance.isDisposed() && instance !== parentInstance && instance.dispose();
545
660
  }, 0)
546
661
  };
547
- }), t7 = [instance, parentInstance], $[15] = instance, $[16] = parentInstance, $[17] = t6, $[18] = t7) : (t6 = $[17], t7 = $[18]), useEffect(t6, t7);
548
- const t8 = fallback ?? DEFAULT_FALLBACK, t9 = perspective ?? parentPerspective;
549
- let t10;
550
- $[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;
551
664
  let t11;
552
- $[22] !== effectiveResource || $[23] !== t10 ? (t11 = /* @__PURE__ */ jsx(ResourceContext.Provider, { value: effectiveResource, children: t10 }), $[22] = effectiveResource, $[23] = t10, $[24] = t11) : t11 = $[24];
665
+ $[22] !== children || $[23] !== t10 ? (t11 = /* @__PURE__ */ jsx(PerspectiveContext.Provider, { value: t10, children }), $[22] = children, $[23] = t10, $[24] = t11) : t11 = $[24];
553
666
  let t12;
554
- return $[25] !== instance || $[26] !== t11 || $[27] !== t8 ? (t12 = /* @__PURE__ */ jsx(SanityInstanceProvider, { instance, fallback: t8, children: t11 }), $[25] = instance, $[26] = t11, $[27] = t8, $[28] = t12) : t12 = $[28], t12;
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;
555
672
  }
556
- const ResourcesContext = createContext({});
557
673
  function ResetChunkReloadFlagOnMount() {
558
674
  const $ = c(1);
559
675
  let t0;
560
- return $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = [], $[0] = t0) : t0 = $[0], useEffect(_temp$4, t0), null;
676
+ return $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = [], $[0] = t0) : t0 = $[0], useEffect(_temp$5, t0), null;
561
677
  }
562
- function _temp$4() {
678
+ function _temp$5() {
563
679
  clearChunkReloadFlag();
564
680
  }
565
681
  function SDKProvider(t0) {
566
- const $ = c(29);
567
- let children, config, fallback, props;
682
+ const $ = c(36);
683
+ let children, config, fallback, inferMediaLibraryAndCanvas, props;
568
684
  $[0] !== t0 ? ({
569
685
  children,
570
686
  config,
571
687
  fallback,
688
+ inferMediaLibraryAndCanvas,
572
689
  ...props
573
- } = t0, $[0] = t0, $[1] = children, $[2] = config, $[3] = fallback, $[4] = props) : (children = $[1], config = $[2], fallback = $[3], props = $[4]);
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;
574
692
  let t1;
575
- $[5] !== config ? (t1 = Array.isArray(config) ? config : [config], $[5] = config, $[6] = t1) : t1 = $[6];
576
- const allConfigs = t1, resolvedConfig = allConfigs[0];
577
- let t2;
578
- $[7] !== allConfigs ? (t2 = allConfigs.map(_temp2$1).filter(_temp3$1), $[7] = allConfigs, $[8] = t2) : t2 = $[8];
579
- const projectIds = t2, singleConfig = Array.isArray(config) ? null : config, defaultProjectId = singleConfig?.projectId, defaultDataset = singleConfig?.dataset;
580
- let t3;
581
693
  bb0: {
582
- let t42;
583
- $[9] !== props.resources ? (t42 = props.resources ?? {}, $[9] = props.resources, $[10] = t42) : t42 = $[10];
584
- const explicit = t42;
694
+ let t22;
695
+ $[6] !== props.resources ? (t22 = props.resources ?? {}, $[6] = props.resources, $[7] = t22) : t22 = $[7];
696
+ const explicit = t22;
585
697
  if (defaultProjectId && defaultDataset && !Object.hasOwn(explicit, DEFAULT_RESOURCE_NAME)) {
586
- let t52;
587
- $[11] !== defaultDataset || $[12] !== defaultProjectId ? (t52 = {
698
+ let t32;
699
+ $[8] !== defaultDataset || $[9] !== defaultProjectId ? (t32 = {
588
700
  projectId: defaultProjectId,
589
701
  dataset: defaultDataset
590
- }, $[11] = defaultDataset, $[12] = defaultProjectId, $[13] = t52) : t52 = $[13];
591
- let t62;
592
- $[14] !== explicit || $[15] !== t52 ? (t62 = {
593
- [DEFAULT_RESOURCE_NAME]: t52,
702
+ }, $[8] = defaultDataset, $[9] = defaultProjectId, $[10] = t32) : t32 = $[10];
703
+ let t42;
704
+ $[11] !== explicit || $[12] !== t32 ? (t42 = {
705
+ [DEFAULT_RESOURCE_NAME]: t32,
594
706
  ...explicit
595
- }, $[14] = explicit, $[15] = t52, $[16] = t62) : t62 = $[16], t3 = t62;
707
+ }, $[11] = explicit, $[12] = t32, $[13] = t42) : t42 = $[13], t1 = t42;
596
708
  break bb0;
597
709
  }
598
- t3 = explicit;
710
+ t1 = explicit;
599
711
  }
600
- const resourcesValue = t3;
601
- let t4;
602
- $[17] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t4 = /* @__PURE__ */ jsx(ResetChunkReloadFlagOnMount, {}), $[17] = t4) : t4 = $[17];
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];
603
725
  let t5;
604
- $[18] !== children || $[19] !== resourcesValue ? (t5 = /* @__PURE__ */ jsx(ResourcesContext.Provider, { value: resourcesValue, children }), $[18] = children, $[19] = resourcesValue, $[20] = t5) : t5 = $[20];
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];
605
727
  let t6;
606
- $[21] !== projectIds || $[22] !== props || $[23] !== t5 ? (t6 = /* @__PURE__ */ jsx(AuthBoundary, { ...props, projectIds, children: t5 }), $[21] = projectIds, $[22] = props, $[23] = t5, $[24] = t6) : t6 = $[24];
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];
607
729
  let t7;
608
- return $[25] !== fallback || $[26] !== resolvedConfig || $[27] !== t6 ? (t7 = /* @__PURE__ */ jsxs(ErrorBoundary, { FallbackComponent: ChunkAwareFallback, children: [
609
- t4,
610
- /* @__PURE__ */ jsx(ResourceProvider, { ...resolvedConfig, fallback, children: t6 })
611
- ] }), $[25] = fallback, $[26] = resolvedConfig, $[27] = t6, $[28] = t7) : t7 = $[28], t7;
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;
612
734
  }
613
- function _temp3$1(id) {
735
+ function _temp4(id) {
614
736
  return !!id;
615
737
  }
616
- function _temp2$1(c2) {
617
- return c2.projectId;
738
+ function _temp3$1(configObj) {
739
+ return configObj.projectId;
740
+ }
741
+ function _temp2$1(resource) {
742
+ return resource.projectId;
618
743
  }
619
744
  function ChunkAwareFallback(fallbackProps) {
620
745
  const $ = c(2);
@@ -666,12 +791,12 @@ function SanityApp(t0) {
666
791
  $[8] !== configProp || $[9] !== resolvedConfig || $[10] !== studioWorkspace ? (t2 = () => {
667
792
  let timeout;
668
793
  const primaryConfig = Array.isArray(resolvedConfig) ? resolvedConfig[0] : resolvedConfig, shouldRedirectWithoutConfig = configProp === void 0 && !studioWorkspace && !primaryConfig;
669
- return !isInIframe() && !isLocalUrl(window) && (shouldRedirectWithoutConfig || primaryConfig && !isStudioConfig(primaryConfig)) && (timeout = setTimeout(_temp$3, 1e3)), () => clearTimeout(timeout);
794
+ return !isInIframe() && !isLocalUrl(window) && (shouldRedirectWithoutConfig || primaryConfig && !isStudioConfig(primaryConfig)) && (timeout = setTimeout(_temp$4, 1e3)), () => clearTimeout(timeout);
670
795
  }, t3 = [configProp, resolvedConfig, studioWorkspace], $[8] = configProp, $[9] = resolvedConfig, $[10] = studioWorkspace, $[11] = t2, $[12] = t3) : (t2 = $[11], t3 = $[12]), useEffect(t2, t3);
671
796
  let t4;
672
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;
673
798
  }
674
- function _temp$3() {
799
+ function _temp$4() {
675
800
  console.warn("Redirecting to core", REDIRECT_URL), window.location.replace(REDIRECT_URL);
676
801
  }
677
802
  function renderSanityApp(rootElement, namedSources, options, children) {
@@ -842,18 +967,7 @@ function useAgentResourceContext(options) {
842
967
  updateContext();
843
968
  }, t3 = [updateContext], $[6] = updateContext, $[7] = t2, $[8] = t3) : (t2 = $[7], t3 = $[8]), useEffect(t2, t3);
844
969
  }
845
- const useAuthToken = createStateSourceHook(getTokenState), useCurrentUser = createStateSourceHook(getCurrentUserState);
846
- function useDashboardOrganizationId() {
847
- const $ = c(2), instance = useSanityInstance();
848
- let t0, t1;
849
- $[0] !== instance ? (t1 = getDashboardOrganizationId(instance), $[0] = instance, $[1] = t1) : t1 = $[1], t0 = t1;
850
- const {
851
- subscribe,
852
- getCurrent
853
- } = t0;
854
- return useSyncExternalStore(subscribe, getCurrent);
855
- }
856
- const useClient = createStateSourceHook({
970
+ const useAuthToken = createStateSourceHook(getTokenState), useCurrentUser = createStateSourceHook(getCurrentUserState), useClient = createStateSourceHook({
857
971
  getState: (instance, options) => {
858
972
  if (!options || typeof options != "object")
859
973
  throw new Error('useClient() requires a configuration object with at least an "apiVersion" property. Example: useClient({ apiVersion: "2024-11-12" })');
@@ -885,7 +999,7 @@ function useFrameConnection(options) {
885
999
  const [type, handler] = t22, unsubscribe = channel.on(type, handler);
886
1000
  messageUnsubscribers.push(unsubscribe);
887
1001
  }), () => {
888
- messageUnsubscribers.forEach(_temp$2), releaseChannel(instance, name), channelRef.current = null, controllerRef.current = null;
1002
+ messageUnsubscribers.forEach(_temp$3), releaseChannel(instance, name), channelRef.current = null, controllerRef.current = null;
889
1003
  };
890
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);
891
1005
  let t2;
@@ -907,7 +1021,7 @@ function useFrameConnection(options) {
907
1021
  sendMessage
908
1022
  }, $[11] = t4) : t4 = $[11], t4;
909
1023
  }
910
- function _temp$2(unsub) {
1024
+ function _temp$3(unsub) {
911
1025
  return unsub();
912
1026
  }
913
1027
  function useResource() {
@@ -1236,15 +1350,31 @@ function useWindowTitle(viewTitle) {
1236
1350
  };
1237
1351
  }, t4 = [viewTitle, appTitle], $[4] = appTitle, $[5] = viewTitle, $[6] = t3, $[7] = t4) : (t3 = $[6], t4 = $[7]), useEffect(t3, t4);
1238
1352
  }
1239
- const useDatasets = createStateSourceHook({
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({
1240
1364
  getState: getDatasetsState,
1241
1365
  shouldSuspend: (instance, projectHandle) => (
1242
1366
  // remove `undefined` since we're suspending when that is the case
1243
1367
  getDatasetsState(instance, projectHandle).getCurrent() === void 0
1244
1368
  ),
1245
- suspender: resolveDatasets,
1246
- getConfig: identity
1247
- });
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
+ };
1248
1378
  function useApplyActions() {
1249
1379
  const $ = c(4), instance = useSanityInstance(), resources = useContext(ResourcesContext), effectiveContextResource = useEffectiveContextResource();
1250
1380
  let t0;
@@ -1275,6 +1405,19 @@ function useTrackHookUsage(hookName) {
1275
1405
  function trackHookUsage(instance, hookName) {
1276
1406
  trackHookMounted(instance, hookName);
1277
1407
  }
1408
+ function useCreateDocument(options) {
1409
+ const $ = c(3), instance = useSanityInstance();
1410
+ trackHookUsage(instance, "useCreateDocument");
1411
+ const apply = useApplyDocumentActions();
1412
+ let t0;
1413
+ return $[0] !== apply || $[1] !== options ? (t0 = async (initialValue, overrides) => {
1414
+ const documentId = overrides?.documentId ?? options.documentId ?? crypto.randomUUID(), handle = {
1415
+ ...options,
1416
+ documentId
1417
+ };
1418
+ return await apply(createDocument(handle, initialValue)), handle;
1419
+ }, $[0] = apply, $[1] = options, $[2] = t0) : t0 = $[2], t0;
1420
+ }
1278
1421
  const useDocumentValue = createStateSourceHook({
1279
1422
  // Pass options directly to getDocumentState
1280
1423
  getState: (instance, options) => getDocumentState(instance, options),
@@ -1325,39 +1468,58 @@ const noopSubscribe = () => () => {
1325
1468
  }, returnUndefined = () => {
1326
1469
  };
1327
1470
  function useDocumentPermissions(actionOrActions) {
1328
- const instance = useSanityInstance();
1471
+ const $ = c(13), instance = useSanityInstance();
1329
1472
  trackHookUsage(instance, "useDocumentPermissions");
1330
- 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 {
1331
1499
  actions: normalizedActions,
1332
1500
  resource: actionResource,
1333
1501
  error: validationError
1334
- } = useMemo(() => {
1335
- const normalized = Array.isArray(actionOrActions) ? actionOrActions.map((action) => normalizeResourceOptions(action, resources, effectiveContextResource)) : [normalizeResourceOptions(actionOrActions, resources, effectiveContextResource)];
1336
- let resource;
1337
- for (const action_0 of normalized)
1338
- if (action_0.resource && (resource || (resource = action_0.resource), !isDeepEqual(action_0.resource, resource)))
1339
- return {
1340
- actions: normalized,
1341
- resource,
1342
- 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)}".`)
1343
- };
1344
- return {
1345
- actions: normalized,
1346
- resource,
1347
- error: void 0
1348
- };
1349
- }, [actionOrActions, resources, effectiveContextResource]), effectiveResource = actionResource ?? effectiveContextResource, permissionsOptions = useMemo(() => effectiveResource ? {
1502
+ } = t0, effectiveResource = actionResource ?? effectiveContextResource;
1503
+ let t1;
1504
+ $[7] !== effectiveResource || $[8] !== normalizedActions ? (t1 = effectiveResource ? {
1350
1505
  resource: effectiveResource,
1351
- // `Omit<>` on `DocumentAction` loses the discriminant; runtime values are still actions.
1352
1506
  actions: normalizedActions
1353
- } : void 0, [effectiveResource, normalizedActions]), stateSource = useMemo(() => permissionsOptions ? getPermissionsState(instance, permissionsOptions) : void 0, [permissionsOptions, instance]), isDocumentReady = useCallback(() => stateSource !== void 0 && stateSource.getCurrent() !== void 0, [stateSource]), result = useSyncExternalStore(stateSource?.subscribe ?? noopSubscribe, stateSource?.getCurrent ?? returnUndefined);
1354
- if (validationError) throw validationError;
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;
1355
1514
  if (!effectiveResource)
1356
1515
  throw new Error("No resource found. Provide a resource via the action handle or wrap with a resource context.");
1357
1516
  if (!isDocumentReady())
1358
- throw firstValueFrom(stateSource.observable.pipe(filter((permissions) => permissions !== void 0)));
1517
+ throw firstValueFrom(stateSource.observable.pipe(filter(_temp$2)));
1359
1518
  return result;
1360
1519
  }
1520
+ function _temp$2(permissions) {
1521
+ return permissions !== void 0;
1522
+ }
1361
1523
  const useDocumentSyncStatusValue = createStateSourceHook({
1362
1524
  getState: getDocumentSyncStatus,
1363
1525
  shouldSuspend: (instance, doc) => getDocumentSyncStatus(instance, doc).getCurrent() === void 0,
@@ -1445,17 +1607,28 @@ function useQuery(options) {
1445
1607
  }), [data, isPending]);
1446
1608
  }
1447
1609
  const DEFAULT_BATCH_SIZE = 25;
1448
- function useDocuments({
1449
- batchSize = DEFAULT_BATCH_SIZE,
1450
- params,
1451
- search,
1452
- filter: filter2,
1453
- orderings,
1454
- documentType,
1455
- ...rawOptions
1456
- }) {
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;
1457
1623
  useTrackHookUsage("useDocuments");
1458
- const options = useNormalizedResourceOptions(rawOptions), [limit, setLimit] = useState(batchSize), documentTypes = useMemo(() => (Array.isArray(documentType) ? documentType : [documentType]).filter((i) => typeof i == "string"), [documentType]), key = JSON.stringify({
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({
1459
1632
  filter: filter2,
1460
1633
  search,
1461
1634
  params,
@@ -1463,45 +1636,74 @@ function useDocuments({
1463
1636
  batchSize,
1464
1637
  types: documentTypes,
1465
1638
  ...options
1466
- }), [prevKey, setPrevKey] = useState(key);
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);
1467
1641
  prevKey !== key && (setPrevKey(key), setLimit(batchSize));
1468
- const filterClause = useMemo(() => {
1469
- const conditions = [], trimmedSearch = search?.trim();
1642
+ let conditions;
1643
+ if ($[20] !== documentTypes?.length || $[21] !== filter2 || $[22] !== search) {
1644
+ conditions = [];
1645
+ const trimmedSearch = search?.trim();
1470
1646
  if (trimmedSearch) {
1471
1647
  const searchFilter = createGroqSearchFilter(trimmedSearch);
1472
1648
  searchFilter && conditions.push(searchFilter);
1473
1649
  }
1474
- return documentTypes?.length && conditions.push("(_type in $__types)"), filter2 && conditions.push(`(${filter2})`), conditions.length ? `[${conditions.join(" && ")}]` : "";
1475
- }, [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})`, {
1476
- data: {
1477
- count,
1478
- data
1479
- },
1480
- isPending
1481
- } = useQuery({
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 = {
1482
1674
  ...options,
1483
- query: `{"count":${countQuery},"data":${dataQuery}}`,
1484
- params: {
1485
- ...params,
1486
- // these are passed back to the user as part of each document handle
1487
- __handle: {
1488
- // keep projectId/dataset for backward compat until v4; resource is added
1489
- // intentionally so that hook consumers can resolve the correct resource
1490
- ...options.resource && isDatasetResource(options.resource) ? pickProperties(options.resource, ["projectId", "dataset"]) : {},
1491
- ...pickProperties(options, ["perspective", "resource"])
1492
- },
1493
- __types: documentTypes
1494
- }
1495
- }), 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 = () => {
1496
1687
  setLimit((prev) => Math.min(prev + batchSize, count));
1497
- }, [count, batchSize]);
1498
- return useMemo(() => ({
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 = {
1499
1692
  data,
1500
1693
  hasMore,
1501
1694
  count,
1502
1695
  isPending,
1503
1696
  loadMore
1504
- }), [count, data, hasMore, isPending, loadMore]);
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";
1505
1707
  }
1506
1708
  const useOrganization = createStateSourceHook({
1507
1709
  getState: getOrganizationState,
@@ -1512,96 +1714,55 @@ const useOrganization = createStateSourceHook({
1512
1714
  shouldSuspend: (instance, ...params) => getOrganizationsState(instance, ...params).getCurrent() === void 0,
1513
1715
  suspender: resolveOrganizations
1514
1716
  });
1515
- function usePaginatedDocuments(t0) {
1516
- const $ = c(60);
1517
- let documentType, orderings, rawOptions, search, t1, t2, t3;
1518
- $[0] !== t0 ? ({
1519
- documentType,
1520
- filter: t1,
1521
- pageSize: t2,
1522
- params: t3,
1523
- orderings,
1524
- search,
1525
- ...rawOptions
1526
- } = 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]);
1527
- const filter2 = t1 === void 0 ? "" : t1, pageSize = t2 === void 0 ? 25 : t2;
1528
- let t4;
1529
- $[8] !== t3 ? (t4 = t3 === void 0 ? {} : t3, $[8] = t3, $[9] = t4) : t4 = $[9];
1530
- const params = t4;
1717
+ function usePaginatedDocuments({
1718
+ documentType,
1719
+ filter: filter2 = "",
1720
+ pageSize = 25,
1721
+ params = {},
1722
+ orderings,
1723
+ search,
1724
+ ...rawOptions
1725
+ }) {
1531
1726
  useTrackHookUsage("usePaginatedDocuments");
1532
- const options = useNormalizedResourceOptions(rawOptions), [pageIndex, setPageIndex] = useState(0);
1533
- let t5;
1534
- $[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({
1535
1728
  filter: filter2,
1536
1729
  search,
1537
1730
  params,
1538
1731
  orderings,
1539
1732
  pageSize,
1540
1733
  ...options
1541
- }), $[10] = filter2, $[11] = options, $[12] = orderings, $[13] = pageSize, $[14] = params, $[15] = search, $[16] = t5) : t5 = $[16];
1542
- const key = t5, [prevKey, setPrevKey] = useState(key);
1734
+ }), [prevKey, setPrevKey] = useState(key);
1543
1735
  prevKey !== key && (setPrevKey(key), setPageIndex(0));
1544
- const startIndex = pageIndex * pageSize, endIndex = (pageIndex + 1) * pageSize;
1545
- let t6;
1546
- $[17] !== documentType ? (t6 = Array.isArray(documentType) ? documentType : [documentType], $[17] = documentType, $[18] = t6) : t6 = $[18];
1547
- let t7;
1548
- $[19] !== t6 ? (t7 = t6.filter(_temp), $[19] = t6, $[20] = t7) : t7 = $[20];
1549
- const documentTypes = t7;
1550
- let t8;
1551
- const conditions = [], trimmedSearch = search?.trim();
1552
- if (trimmedSearch) {
1553
- const searchFilter = createGroqSearchFilter(trimmedSearch);
1554
- searchFilter && conditions.push(searchFilter);
1555
- }
1556
- documentTypes?.length && conditions.push("(_type in $__types)"), filter2 && conditions.push(`(${filter2})`), t8 = conditions.length ? `[${conditions.join(" && ")}]` : "";
1557
- 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}}`;
1558
- let t10;
1559
- $[21] !== options.resource ? (t10 = options.resource && isDatasetResource(options.resource) ? pickProperties(options.resource, ["projectId", "dataset"]) : {}, $[21] = options.resource, $[22] = t10) : t10 = $[22];
1560
- let t11;
1561
- $[23] !== options ? (t11 = pickProperties(options, ["perspective", "resource"]), $[23] = options, $[24] = t11) : t11 = $[24];
1562
- let t12;
1563
- $[25] !== t10 || $[26] !== t11 ? (t12 = {
1564
- ...t10,
1565
- ...t11
1566
- }, $[25] = t10, $[26] = t11, $[27] = t12) : t12 = $[27];
1567
- let t13;
1568
- $[28] !== documentTypes || $[29] !== params || $[30] !== t12 ? (t13 = {
1569
- ...params,
1570
- __types: documentTypes,
1571
- __handle: t12
1572
- }, $[28] = documentTypes, $[29] = params, $[30] = t12, $[31] = t13) : t13 = $[31];
1573
- let t14;
1574
- $[32] !== options || $[33] !== t13 || $[34] !== t9 ? (t14 = {
1575
- ...options,
1576
- query: t9,
1577
- params: t13
1578
- }, $[32] = options, $[33] = t13, $[34] = t9, $[35] = t14) : t14 = $[35];
1579
- const {
1580
- 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
+ },
1581
1748
  isPending
1582
- } = useQuery(t14), {
1583
- data,
1584
- count
1585
- } = t15, totalPages = Math.ceil(count / pageSize), currentPage = pageIndex + 1;
1586
- let t16;
1587
- $[36] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t16 = () => setPageIndex(0), $[36] = t16) : t16 = $[36];
1588
- const firstPage = t16;
1589
- let t17;
1590
- $[37] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t17 = () => setPageIndex(_temp4), $[37] = t17) : t17 = $[37];
1591
- const previousPage = t17;
1592
- let t18;
1593
- $[38] !== totalPages ? (t18 = () => setPageIndex((prev_0) => Math.min(prev_0 + 1, totalPages - 1)), $[38] = totalPages, $[39] = t18) : t18 = $[39];
1594
- const nextPage = t18;
1595
- let t19;
1596
- $[40] !== totalPages ? (t19 = () => setPageIndex(totalPages - 1), $[40] = totalPages, $[41] = t19) : t19 = $[41];
1597
- const lastPage = t19;
1598
- let t20;
1599
- $[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) => {
1600
1763
  pageNumber < 1 || pageNumber > totalPages || setPageIndex(pageNumber - 1);
1601
- }, $[42] = totalPages, $[43] = t20) : t20 = $[43];
1602
- const goToPage = t20, hasFirstPage = pageIndex > 0, hasPreviousPage = pageIndex > 0, hasNextPage = pageIndex < totalPages - 1, hasLastPage = pageIndex < totalPages - 1;
1603
- let t21;
1604
- 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 {
1605
1766
  data,
1606
1767
  isPending,
1607
1768
  pageSize,
@@ -1619,19 +1780,7 @@ function usePaginatedDocuments(t0) {
1619
1780
  lastPage,
1620
1781
  hasLastPage,
1621
1782
  goToPage
1622
- }, $[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, $[59] = t21) : t21 = $[59], t21;
1623
- }
1624
- function _temp4(prev) {
1625
- return Math.max(prev - 1, 0);
1626
- }
1627
- function _temp3(ordering) {
1628
- return [ordering.field, ordering.direction.toLowerCase()].map(_temp2).filter(Boolean).join(" ");
1629
- }
1630
- function _temp2(str) {
1631
- return str.trim();
1632
- }
1633
- function _temp(i) {
1634
- return typeof i == "string";
1783
+ };
1635
1784
  }
1636
1785
  function usePresence(t0) {
1637
1786
  const $ = c(14);
@@ -1642,45 +1791,57 @@ function usePresence(t0) {
1642
1791
  throw new Error("usePresence() does not support media library resources. Presence tracking requires a canvas or dataset resource.");
1643
1792
  const sanityInstance = useSanityInstance();
1644
1793
  trackHookUsage(sanityInstance, "usePresence");
1645
- let t2, t3;
1646
- $[2] !== normalizedOptions || $[3] !== sanityInstance ? (t3 = getPresence(sanityInstance, normalizedOptions), $[2] = normalizedOptions, $[3] = sanityInstance, $[4] = t3) : t3 = $[4], t2 = t3;
1794
+ let t2;
1795
+ $[2] !== normalizedOptions || $[3] !== sanityInstance ? (t2 = getPresence(sanityInstance, normalizedOptions), $[2] = normalizedOptions, $[3] = sanityInstance, $[4] = t2) : t2 = $[4];
1647
1796
  const source = t2;
1648
- let t4;
1649
- $[5] !== source ? (t4 = (callback) => source.subscribe(callback), $[5] = source, $[6] = t4) : t4 = $[6];
1650
- const subscribe = t4;
1651
- let t5, t6;
1652
- $[7] !== source ? (t5 = () => source.getCurrent(), t6 = () => source.getCurrent(), $[7] = source, $[8] = t5, $[9] = t6) : (t5 = $[8], t6 = $[9]);
1653
- const locations = useSyncExternalStore(subscribe, t5, t6);
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];
1654
1805
  let t7;
1655
- $[10] !== locations ? (t7 = locations || [], $[10] = locations, $[11] = t7) : t7 = $[11];
1656
- let t8;
1657
- return $[12] !== t7 ? (t8 = {
1658
- locations: t7
1659
- }, $[12] = t7, $[13] = t8) : t8 = $[13], t8;
1660
- }
1661
- function useDocumentProjection({
1662
- ref,
1663
- projection,
1664
- ...docHandle
1665
- }) {
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]);
1666
1818
  const instance = useSanityInstance();
1667
1819
  trackHookUsage(instance, "useDocumentProjection");
1668
- const normalizedProjection = useMemo(() => projection.trim(), [projection]), normalizedDocHandle = useNormalizedResourceOptions(docHandle), stateSource = useMemo(() => getProjectionState(instance, {
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, {
1669
1825
  ...normalizedDocHandle,
1670
1826
  projection: normalizedProjection
1671
- }), [instance, normalizedDocHandle, normalizedProjection]);
1827
+ }), $[6] = instance, $[7] = normalizedDocHandle, $[8] = normalizedProjection, $[9] = t2) : t2 = $[9];
1828
+ const stateSource = t2;
1672
1829
  if (stateSource.getCurrent()?.data === null)
1673
1830
  throw resolveProjection(instance, {
1674
1831
  ...normalizedDocHandle,
1675
1832
  projection: normalizedProjection
1676
1833
  });
1677
- const subscribe = useCallback((onStoreChanged) => {
1834
+ let t3;
1835
+ return $[10] !== ref || $[11] !== stateSource ? (t3 = (onStoreChanged) => {
1678
1836
  const subscription = new Observable((observer) => {
1679
1837
  if (typeof IntersectionObserver > "u" || typeof HTMLElement > "u") {
1680
1838
  observer.next(!0);
1681
1839
  return;
1682
1840
  }
1683
- const intersectionObserver = new IntersectionObserver(([entry]) => observer.next(entry.isIntersecting), {
1841
+ const intersectionObserver = new IntersectionObserver((t4) => {
1842
+ const [entry] = t4;
1843
+ return observer.next(entry.isIntersecting);
1844
+ }, {
1684
1845
  rootMargin: "0px",
1685
1846
  threshold: 0
1686
1847
  });
@@ -1689,8 +1850,7 @@ function useDocumentProjection({
1689
1850
  next: onStoreChanged
1690
1851
  });
1691
1852
  return () => subscription.unsubscribe();
1692
- }, [stateSource, ref]);
1693
- return useSyncExternalStore(subscribe, stateSource.getCurrent);
1853
+ }, $[10] = ref, $[11] = stateSource, $[12] = t3) : t3 = $[12], useSyncExternalStore(t3, stateSource.getCurrent);
1694
1854
  }
1695
1855
  function useDocumentPreview(t0) {
1696
1856
  const $ = c(13);
@@ -1709,21 +1869,26 @@ function useDocumentPreview(t0) {
1709
1869
  ref
1710
1870
  }, $[3] = normalizedDocHandle, $[4] = ref, $[5] = t1) : t1 = $[5];
1711
1871
  const projectionResult = useDocumentProjection(t1);
1712
- let t2, t3;
1713
- $[6] !== instance || $[7] !== normalizedDocHandle.resource || $[8] !== projectionResult.data ? (t3 = transformProjectionToPreview(instance, projectionResult.data, normalizedDocHandle.resource), $[6] = instance, $[7] = normalizedDocHandle.resource, $[8] = projectionResult.data, $[9] = t3) : t3 = $[9], t2 = t3;
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];
1714
1874
  const previewValue = t2;
1715
- let t4;
1716
- return $[10] !== previewValue || $[11] !== projectionResult.isPending ? (t4 = {
1875
+ let t3;
1876
+ return $[10] !== previewValue || $[11] !== projectionResult.isPending ? (t3 = {
1717
1877
  data: previewValue,
1718
1878
  isPending: projectionResult.isPending
1719
- }, $[10] = previewValue, $[11] = projectionResult.isPending, $[12] = t4) : t4 = $[12], t4;
1879
+ }, $[10] = previewValue, $[11] = projectionResult.isPending, $[12] = t3) : t3 = $[12], t3;
1720
1880
  }
1721
- const useProject = createStateSourceHook({
1881
+ const useProjectBase = createStateSourceHook({
1722
1882
  getState: getProjectState,
1723
1883
  shouldSuspend: (instance, ...params) => getProjectState(instance, ...params).getCurrent() === void 0,
1724
- suspender: resolveProject,
1725
- getConfig: identity
1726
- }), useProjects = createStateSourceHook({
1884
+ suspender: resolveProject
1885
+ }), useProject = (options) => {
1886
+ const projectId = useResolvedProjectId(options);
1887
+ return useProjectBase(projectId ? {
1888
+ ...options,
1889
+ projectId
1890
+ } : options);
1891
+ }, useProjects = createStateSourceHook({
1727
1892
  getState: getProjectsState,
1728
1893
  shouldSuspend: (instance, ...params) => getProjectsState(instance, ...params).getCurrent() === void 0,
1729
1894
  suspender: resolveProjects
@@ -1764,41 +1929,79 @@ function usePerspective(perspectiveHandle) {
1764
1929
  return usePerspectiveValue(normalizedOptions);
1765
1930
  }
1766
1931
  function useUser(options) {
1767
- const instance = useSanityInstance();
1932
+ const $ = c(17), instance = useSanityInstance();
1768
1933
  trackHookUsage(instance, "useUser");
1769
- const [isPending, startTransition] = useTransition(), key = getUsersKey(instance, options), [deferredKey, setDeferredKey] = useState(key), deferred = useMemo(() => parseUsersKey(deferredKey), [deferredKey]), [ref, setRef] = useState(new AbortController());
1770
- useEffect(() => {
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 = () => {
1771
1946
  key !== deferredKey && startTransition(() => {
1772
1947
  ref.signal.aborted || (ref.abort(), setRef(new AbortController())), setDeferredKey(key);
1773
1948
  });
1774
- }, [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];
1775
1953
  const {
1776
1954
  getCurrent,
1777
1955
  subscribe
1778
- } = useMemo(() => getUsersState(instance, deferred), [instance, deferred]);
1956
+ } = t6;
1779
1957
  if (getCurrent() === void 0)
1780
1958
  throw resolveUsers(instance, {
1781
1959
  ...deferred,
1782
1960
  signal: ref.signal
1783
1961
  });
1784
- return {
1785
- data: useSyncExternalStore(subscribe, getCurrent)?.data[0],
1962
+ const data = useSyncExternalStore(subscribe, getCurrent)?.data[0];
1963
+ let t7;
1964
+ return $[14] !== data || $[15] !== isPending ? (t7 = {
1965
+ data,
1786
1966
  isPending
1787
- };
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;
1788
1976
  }
1789
1977
  function useUsers(options) {
1790
- const instance = useSanityInstance();
1978
+ const $ = c(25), instance = useSanityInstance();
1791
1979
  trackHookUsage(instance, "useUsers");
1792
- const [isPending, startTransition] = useTransition(), key = getUsersKey(instance, options), [deferredKey, setDeferredKey] = useState(key), deferred = useMemo(() => parseUsersKey(deferredKey), [deferredKey]), [ref, setRef] = useState(new AbortController());
1793
- useEffect(() => {
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 = () => {
1794
1995
  key !== deferredKey && startTransition(() => {
1795
1996
  ref.signal.aborted || (ref.abort(), setRef(new AbortController())), setDeferredKey(key);
1796
1997
  });
1797
- }, [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];
1798
2001
  const {
1799
2002
  getCurrent,
1800
2003
  subscribe
1801
- } = useMemo(() => getUsersState(instance, deferred), [instance, deferred]);
2004
+ } = t6;
1802
2005
  if (getCurrent() === void 0)
1803
2006
  throw resolveUsers(instance, {
1804
2007
  ...deferred,
@@ -1807,17 +2010,21 @@ function useUsers(options) {
1807
2010
  const {
1808
2011
  data,
1809
2012
  hasMore
1810
- } = useSyncExternalStore(subscribe, getCurrent), loadMore = useCallback(() => {
1811
- loadMoreUsers(instance, options);
1812
- }, [instance, options]);
1813
- return {
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 = {
1814
2021
  data,
1815
2022
  hasMore,
1816
2023
  isPending,
1817
2024
  loadMore
1818
- };
2025
+ }, $[20] = data, $[21] = hasMore, $[22] = isPending, $[23] = loadMore, $[24] = t8) : t8 = $[24], t8;
1819
2026
  }
1820
- var version = "2.14.1";
2027
+ var version = "2.16.0";
1821
2028
  function getEnv(key) {
1822
2029
  if (typeof import.meta < "u" && import.meta.env)
1823
2030
  return import.meta.env[key];
@@ -1850,6 +2057,7 @@ export {
1850
2057
  useAuthState,
1851
2058
  useAuthToken,
1852
2059
  useClient,
2060
+ useCreateDocument,
1853
2061
  useCurrentUser,
1854
2062
  useDashboardNavigate,
1855
2063
  useDashboardOrganizationId,