@sanity/sdk-react 2.6.0 → 2.8.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 +68 -0
- package/dist/index.d.ts +544 -20
- package/dist/index.js +118 -72
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/_exports/sdk-react.ts +1 -0
- package/src/components/SanityApp.test.tsx +72 -2
- package/src/components/SanityApp.tsx +52 -10
- package/src/components/auth/AuthBoundary.test.tsx +3 -0
- package/src/components/auth/AuthBoundary.tsx +5 -5
- package/src/components/auth/LoginError.test.tsx +5 -0
- package/src/components/auth/LoginError.tsx +22 -1
- package/src/context/ComlinkTokenRefresh.test.tsx +2 -2
- package/src/context/ComlinkTokenRefresh.tsx +3 -2
- package/src/context/SDKStudioContext.test.tsx +126 -0
- package/src/context/SDKStudioContext.ts +65 -0
- package/src/hooks/agent/agentActions.ts +436 -21
- package/src/hooks/dashboard/useDispatchIntent.test.ts +5 -5
- package/src/hooks/dashboard/useDispatchIntent.ts +5 -5
- package/src/hooks/dashboard/utils/useResourceIdFromDocumentHandle.test.ts +2 -3
- package/src/hooks/dashboard/utils/useResourceIdFromDocumentHandle.ts +3 -3
- package/src/hooks/helpers/useNormalizedSourceOptions.ts +85 -0
- package/src/hooks/projection/useDocumentProjection.ts +15 -4
- package/src/hooks/query/useQuery.ts +23 -17
- package/src/hooks/context/useSource.tsx +0 -34
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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, setAuthToken, AuthStateType, getLoginUrlState, observeOrganizationVerificationState, handleAuthCallback, logout, isProjectUserNotFoundClientError, getClientErrorApiDescription, getClientErrorApiBody, getCorsErrorProjectId, createSanityInstance, agentGenerate, agentTransform, agentTranslate, agentPrompt, agentPatch, getTokenState, getCurrentUserState, getDashboardOrganizationId, getClientState, getOrCreateController, getOrCreateChannel, releaseChannel, isDatasetSource, isMediaLibrarySource, isCanvasSource, getFavoritesState, resolveFavoritesState, resolveDatasets, getDatasetsState, applyDocumentActions, resolveDocument, getDocumentState, subscribeDocumentEvents, getPermissionsState, getDocumentSyncStatus, editDocument, getQueryKey, parseQueryKey, getQueryState, resolveQuery, createGroqSearchFilter, getPresence, getPreviewState, resolvePreview, getProjectionState, resolveProjection, resolveProject, getProjectState, resolveProjects, getProjectsState, getActiveReleasesState, getPerspectiveState, getUsersKey, parseUsersKey, getUsersState, resolveUsers, loadMoreUsers } from "@sanity/sdk";
|
|
4
|
+
import { getAuthState, getNodeState, getIsInDashboardState, isStudioConfig, setAuthToken, AuthStateType, getLoginUrlState, observeOrganizationVerificationState, handleAuthCallback, logout, isProjectUserNotFoundClientError, getClientErrorApiDescription, getClientErrorApiBody, getCorsErrorProjectId, createSanityInstance, agentGenerate, agentTransform, agentTranslate, agentPrompt, agentPatch, getTokenState, getCurrentUserState, getDashboardOrganizationId, getClientState, getOrCreateController, getOrCreateChannel, releaseChannel, isDatasetSource, isMediaLibrarySource, isCanvasSource, getFavoritesState, resolveFavoritesState, resolveDatasets, getDatasetsState, applyDocumentActions, resolveDocument, getDocumentState, subscribeDocumentEvents, getPermissionsState, getDocumentSyncStatus, editDocument, getQueryKey, parseQueryKey, getQueryState, resolveQuery, createGroqSearchFilter, getPresence, getPreviewState, resolvePreview, getProjectionState, resolveProjection, resolveProject, getProjectState, resolveProjects, getProjectsState, getActiveReleasesState, getPerspectiveState, getUsersKey, parseUsersKey, getUsersState, resolveUsers, loadMoreUsers } from "@sanity/sdk";
|
|
5
5
|
export * from "@sanity/sdk";
|
|
6
6
|
import { createContext, useContext, useSyncExternalStore, useRef, useEffect, useState, Suspense, StrictMode, useCallback, useMemo, useInsertionEffect, useTransition } from "react";
|
|
7
7
|
import { ErrorBoundary } from "react-error-boundary";
|
|
@@ -144,8 +144,8 @@ const ComlinkTokenRefreshProvider = (t0) => {
|
|
|
144
144
|
} = t0, instance = useSanityInstance();
|
|
145
145
|
let t1;
|
|
146
146
|
t1 = getIsInDashboardState(instance).getCurrent();
|
|
147
|
-
const isInDashboard = t1,
|
|
148
|
-
if (isInDashboard && !
|
|
147
|
+
const isInDashboard = t1, isStudio = isStudioConfig(instance.config);
|
|
148
|
+
if (isInDashboard && !isStudio) {
|
|
149
149
|
let t2;
|
|
150
150
|
return $[0] !== children ? (t2 = /* @__PURE__ */ jsx(DashboardTokenRefresh, { children }), $[0] = children, $[1] = t2) : t2 = $[1], t2;
|
|
151
151
|
}
|
|
@@ -298,25 +298,40 @@ function _temp$6(replacementLocation) {
|
|
|
298
298
|
}
|
|
299
299
|
const useLogOut = createCallbackHook(logout);
|
|
300
300
|
function LoginError(t0) {
|
|
301
|
-
const $ = c(
|
|
301
|
+
const $ = c(23), {
|
|
302
302
|
error,
|
|
303
303
|
resetErrorBoundary
|
|
304
304
|
} = t0;
|
|
305
305
|
if (!(error instanceof AuthError || error instanceof ConfigurationError || error instanceof ClientError))
|
|
306
306
|
throw error;
|
|
307
|
-
const logout2 = useLogOut(), authState = useAuthState(),
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
}
|
|
312
|
-
const handleRetry = t1;
|
|
307
|
+
const logout2 = useLogOut(), authState = useAuthState(), {
|
|
308
|
+
config: t1
|
|
309
|
+
} = useSanityInstance(), {
|
|
310
|
+
projectId
|
|
311
|
+
} = t1, [authErrorMessage, setAuthErrorMessage] = useState("Please try again or contact support if the problem persists."), [showRetryCta, setShowRetryCta] = useState(!0);
|
|
313
312
|
let t2;
|
|
314
|
-
$[
|
|
313
|
+
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t2 = {
|
|
314
|
+
name: SDK_NODE_NAME,
|
|
315
|
+
connectTo: SDK_CHANNEL_NAME
|
|
316
|
+
}, $[0] = t2) : t2 = $[0];
|
|
317
|
+
const {
|
|
318
|
+
fetch
|
|
319
|
+
} = useWindowConnection(t2);
|
|
320
|
+
let t3;
|
|
321
|
+
$[1] !== logout2 || $[2] !== resetErrorBoundary ? (t3 = async () => {
|
|
322
|
+
await logout2(), resetErrorBoundary();
|
|
323
|
+
}, $[1] = logout2, $[2] = resetErrorBoundary, $[3] = t3) : t3 = $[3];
|
|
324
|
+
const handleRetry = t3;
|
|
325
|
+
let t4;
|
|
326
|
+
$[4] !== authState.type || $[5] !== error || $[6] !== fetch || $[7] !== handleRetry || $[8] !== projectId ? (t4 = () => {
|
|
315
327
|
if (error instanceof ClientError) {
|
|
316
328
|
if (error.statusCode === 401)
|
|
317
329
|
if (isProjectUserNotFoundClientError(error)) {
|
|
318
330
|
const description = getClientErrorApiDescription(error);
|
|
319
|
-
description && setAuthErrorMessage(description), setShowRetryCta(!1)
|
|
331
|
+
description && setAuthErrorMessage(description), setShowRetryCta(!1), fetch("dashboard/v1/auth/access/request", {
|
|
332
|
+
resourceType: "project",
|
|
333
|
+
resourceId: projectId
|
|
334
|
+
});
|
|
320
335
|
} else
|
|
321
336
|
setShowRetryCta(!0), handleRetry();
|
|
322
337
|
else if (error.statusCode === 404) {
|
|
@@ -325,17 +340,17 @@ function LoginError(t0) {
|
|
|
325
340
|
}
|
|
326
341
|
}
|
|
327
342
|
authState.type !== AuthStateType.ERROR && error instanceof ConfigurationError && (setAuthErrorMessage(error.message), setShowRetryCta(!0));
|
|
328
|
-
}, $[
|
|
329
|
-
let t3;
|
|
330
|
-
$[7] !== authState || $[8] !== error || $[9] !== handleRetry ? (t3 = [authState, handleRetry, error], $[7] = authState, $[8] = error, $[9] = handleRetry, $[10] = t3) : t3 = $[10], useEffect(t2, t3);
|
|
331
|
-
const t4 = error instanceof AuthError ? "Authentication Error" : "Configuration Error";
|
|
343
|
+
}, $[4] = authState.type, $[5] = error, $[6] = fetch, $[7] = handleRetry, $[8] = projectId, $[9] = t4) : t4 = $[9];
|
|
332
344
|
let t5;
|
|
333
|
-
$[11] !==
|
|
345
|
+
$[10] !== authState || $[11] !== error || $[12] !== fetch || $[13] !== handleRetry || $[14] !== projectId ? (t5 = [authState, handleRetry, error, fetch, projectId], $[10] = authState, $[11] = error, $[12] = fetch, $[13] = handleRetry, $[14] = projectId, $[15] = t5) : t5 = $[15], useEffect(t4, t5);
|
|
346
|
+
const t6 = error instanceof AuthError ? "Authentication Error" : "Configuration Error";
|
|
347
|
+
let t7;
|
|
348
|
+
$[16] !== handleRetry || $[17] !== showRetryCta ? (t7 = showRetryCta ? {
|
|
334
349
|
text: "Retry",
|
|
335
350
|
onClick: handleRetry
|
|
336
|
-
} : void 0, $[
|
|
337
|
-
let
|
|
338
|
-
return $[
|
|
351
|
+
} : void 0, $[16] = handleRetry, $[17] = showRetryCta, $[18] = t7) : t7 = $[18];
|
|
352
|
+
let t8;
|
|
353
|
+
return $[19] !== authErrorMessage || $[20] !== t6 || $[21] !== t7 ? (t8 = /* @__PURE__ */ jsx(Error$1, { heading: t6, description: authErrorMessage, cta: t7 }), $[19] = authErrorMessage, $[20] = t6, $[21] = t7, $[22] = t8) : t8 = $[22], t8;
|
|
339
354
|
}
|
|
340
355
|
if (isInIframe() && !document.querySelector("[data-sanity-core]")) {
|
|
341
356
|
const parsedUrl = new URL(window.location.href), mode = new URLSearchParams(parsedUrl.hash.slice(1)).get("mode"), script = document.createElement("script");
|
|
@@ -360,7 +375,7 @@ function AuthBoundary(t0) {
|
|
|
360
375
|
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;
|
|
361
376
|
}
|
|
362
377
|
function AuthSwitch(t0) {
|
|
363
|
-
const $ = c(
|
|
378
|
+
const $ = c(16);
|
|
364
379
|
let children, projectIds, props, t1, t2;
|
|
365
380
|
$[0] !== t0 ? ({
|
|
366
381
|
CallbackComponent: t1,
|
|
@@ -369,11 +384,14 @@ function AuthSwitch(t0) {
|
|
|
369
384
|
projectIds,
|
|
370
385
|
...props
|
|
371
386
|
} = t0, $[0] = t0, $[1] = children, $[2] = projectIds, $[3] = props, $[4] = t1, $[5] = t2) : (children = $[1], projectIds = $[2], props = $[3], t1 = $[4], t2 = $[5]);
|
|
372
|
-
const CallbackComponent = t1 === void 0 ? LoginCallback : t1, verifyOrganization = t2 === void 0 ? !0 : t2, authState = useAuthState(),
|
|
373
|
-
let t3
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
387
|
+
const CallbackComponent = t1 === void 0 ? LoginCallback : t1, verifyOrganization = t2 === void 0 ? !0 : t2, authState = useAuthState(), instance = useSanityInstance();
|
|
388
|
+
let t3;
|
|
389
|
+
$[6] !== instance.config ? (t3 = isStudioConfig(instance.config), $[6] = instance.config, $[7] = t3) : t3 = $[7];
|
|
390
|
+
const isStudio = t3, disableVerifyOrg = !verifyOrganization || isStudio || authState.type !== AuthStateType.LOGGED_IN, orgError = useVerifyOrgProjects(disableVerifyOrg, projectIds), isLoggedOut = authState.type === AuthStateType.LOGGED_OUT && !authState.isDestroyingSession, loginUrl = useLoginUrl();
|
|
391
|
+
let t4, t5;
|
|
392
|
+
if ($[8] !== isLoggedOut || $[9] !== isStudio || $[10] !== loginUrl ? (t4 = () => {
|
|
393
|
+
isLoggedOut && !isInIframe() && !isStudio && (window.location.href = loginUrl);
|
|
394
|
+
}, t5 = [isLoggedOut, loginUrl, isStudio], $[8] = isLoggedOut, $[9] = isStudio, $[10] = loginUrl, $[11] = t4, $[12] = t5) : (t4 = $[11], t5 = $[12]), useEffect(t4, t5), verifyOrganization && orgError)
|
|
377
395
|
throw new ConfigurationError({
|
|
378
396
|
message: orgError
|
|
379
397
|
});
|
|
@@ -381,8 +399,8 @@ function AuthSwitch(t0) {
|
|
|
381
399
|
case AuthStateType.ERROR:
|
|
382
400
|
throw new AuthError(authState.error);
|
|
383
401
|
case AuthStateType.LOGGING_IN: {
|
|
384
|
-
let
|
|
385
|
-
return $[
|
|
402
|
+
let t6;
|
|
403
|
+
return $[13] !== CallbackComponent || $[14] !== props ? (t6 = /* @__PURE__ */ jsx(CallbackComponent, { ...props }), $[13] = CallbackComponent, $[14] = props, $[15] = t6) : t6 = $[15], t6;
|
|
386
404
|
}
|
|
387
405
|
case AuthStateType.LOGGED_IN:
|
|
388
406
|
return children;
|
|
@@ -392,6 +410,8 @@ function AuthSwitch(t0) {
|
|
|
392
410
|
throw new Error(`Invalid auth state: ${authState.type}`);
|
|
393
411
|
}
|
|
394
412
|
}
|
|
413
|
+
const SDKStudioContext = createContext(null);
|
|
414
|
+
SDKStudioContext.displayName = "SDKStudioContext";
|
|
395
415
|
const DEFAULT_FALLBACK = /* @__PURE__ */ jsx(Fragment, { children: "Warning: No fallback provided. Please supply a fallback prop to ensure proper Suspense handling." });
|
|
396
416
|
function ResourceProvider(t0) {
|
|
397
417
|
const $ = c(16);
|
|
@@ -453,26 +473,50 @@ function _temp$5(c2) {
|
|
|
453
473
|
return c2.projectId;
|
|
454
474
|
}
|
|
455
475
|
const REDIRECT_URL = "https://sanity.io/welcome";
|
|
476
|
+
function deriveConfigFromWorkspace(workspace) {
|
|
477
|
+
return {
|
|
478
|
+
projectId: workspace.projectId,
|
|
479
|
+
dataset: workspace.dataset,
|
|
480
|
+
studio: {
|
|
481
|
+
auth: workspace.auth.token ? {
|
|
482
|
+
token: workspace.auth.token
|
|
483
|
+
} : void 0
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
}
|
|
456
487
|
function SanityApp(t0) {
|
|
457
|
-
const $ = c(
|
|
458
|
-
let children, fallback, props
|
|
488
|
+
const $ = c(18);
|
|
489
|
+
let children, configProp, fallback, props;
|
|
459
490
|
$[0] !== t0 ? ({
|
|
460
491
|
children,
|
|
461
492
|
fallback,
|
|
462
|
-
config:
|
|
493
|
+
config: configProp,
|
|
463
494
|
...props
|
|
464
|
-
} = t0, $[0] = t0, $[1] = children, $[2] =
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
495
|
+
} = t0, $[0] = t0, $[1] = children, $[2] = configProp, $[3] = fallback, $[4] = props) : (children = $[1], configProp = $[2], fallback = $[3], props = $[4]);
|
|
496
|
+
const studioWorkspace = useContext(SDKStudioContext);
|
|
497
|
+
let t1;
|
|
498
|
+
bb0: {
|
|
499
|
+
if (configProp) {
|
|
500
|
+
t1 = configProp;
|
|
501
|
+
break bb0;
|
|
502
|
+
}
|
|
503
|
+
if (studioWorkspace) {
|
|
504
|
+
let t23;
|
|
505
|
+
$[5] !== studioWorkspace ? (t23 = deriveConfigFromWorkspace(studioWorkspace), $[5] = studioWorkspace, $[6] = t23) : t23 = $[6], t1 = t23;
|
|
506
|
+
break bb0;
|
|
507
|
+
}
|
|
508
|
+
let t22;
|
|
509
|
+
$[7] === Symbol.for("react.memo_cache_sentinel") ? (t22 = [], $[7] = t22) : t22 = $[7], t1 = t22;
|
|
510
|
+
}
|
|
511
|
+
const resolvedConfig = t1;
|
|
512
|
+
let t2, t3;
|
|
513
|
+
$[8] !== configProp || $[9] !== resolvedConfig || $[10] !== studioWorkspace ? (t2 = () => {
|
|
470
514
|
let timeout;
|
|
471
|
-
const primaryConfig = Array.isArray(
|
|
472
|
-
return !isInIframe() && !isLocalUrl(window) && !primaryConfig
|
|
473
|
-
},
|
|
474
|
-
let
|
|
475
|
-
return $[
|
|
515
|
+
const primaryConfig = Array.isArray(resolvedConfig) ? resolvedConfig[0] : resolvedConfig, shouldRedirectWithoutConfig = configProp === void 0 && !studioWorkspace && !primaryConfig;
|
|
516
|
+
return !isInIframe() && !isLocalUrl(window) && (shouldRedirectWithoutConfig || primaryConfig && !isStudioConfig(primaryConfig)) && (timeout = setTimeout(_temp$4, 1e3)), () => clearTimeout(timeout);
|
|
517
|
+
}, t3 = [configProp, resolvedConfig, studioWorkspace], $[8] = configProp, $[9] = resolvedConfig, $[10] = studioWorkspace, $[11] = t2, $[12] = t3) : (t2 = $[11], t3 = $[12]), useEffect(t2, t3);
|
|
518
|
+
let t4;
|
|
519
|
+
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;
|
|
476
520
|
}
|
|
477
521
|
function _temp$4() {
|
|
478
522
|
console.warn("Redirecting to core", REDIRECT_URL), window.location.replace(REDIRECT_URL);
|
|
@@ -620,21 +664,31 @@ function useDashboardNavigate(navigateFn) {
|
|
|
620
664
|
}
|
|
621
665
|
}, $[0] = navigateFn, $[1] = t0) : t0 = $[1], useWindowConnection(t0);
|
|
622
666
|
}
|
|
623
|
-
function
|
|
667
|
+
function useNormalizedSourceOptions(options) {
|
|
668
|
+
const $ = c(6);
|
|
669
|
+
let rest, sourceName;
|
|
670
|
+
if ($[0] !== options ? ({
|
|
671
|
+
sourceName,
|
|
672
|
+
...rest
|
|
673
|
+
} = options, $[0] = options, $[1] = rest, $[2] = sourceName) : (rest = $[1], sourceName = $[2]), sourceName && Object.hasOwn(options, "source"))
|
|
674
|
+
throw new Error(`Source name ${JSON.stringify(sourceName)} and source ${JSON.stringify(options.source)} cannot be used together.`);
|
|
624
675
|
const sources = useContext(SourcesContext);
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
676
|
+
let resolvedSource;
|
|
677
|
+
if (options.source && (resolvedSource = options.source), sourceName && !Object.hasOwn(sources, sourceName))
|
|
678
|
+
throw new Error(`There's no source named ${JSON.stringify(sourceName)} in context. Please use <SourceProvider>.`);
|
|
679
|
+
sourceName && sources[sourceName] && (resolvedSource = sources[sourceName]);
|
|
680
|
+
let t0;
|
|
681
|
+
return $[3] !== resolvedSource || $[4] !== rest ? (t0 = {
|
|
682
|
+
...rest,
|
|
683
|
+
source: resolvedSource
|
|
684
|
+
}, $[3] = resolvedSource, $[4] = rest, $[5] = t0) : t0 = $[5], t0;
|
|
632
685
|
}
|
|
633
686
|
function useResourceIdFromDocumentHandle(documentHandle) {
|
|
634
|
-
const $ = c(3),
|
|
687
|
+
const $ = c(3), options = useNormalizedSourceOptions(documentHandle), {
|
|
635
688
|
projectId,
|
|
636
|
-
dataset
|
|
637
|
-
|
|
689
|
+
dataset,
|
|
690
|
+
source
|
|
691
|
+
} = options;
|
|
638
692
|
let resourceId = "", resourceType;
|
|
639
693
|
projectId && dataset && (resourceId = `${projectId}.${dataset}`), source && (isDatasetSource(source) ? (resourceId = `${source.projectId}.${source.dataset}`, resourceType = void 0) : isMediaLibrarySource(source) ? (resourceId = source.mediaLibraryId, resourceType = "media-library") : isCanvasSource(source) && (resourceId = source.canvasId, resourceType = "canvas"));
|
|
640
694
|
let t0;
|
|
@@ -660,13 +714,8 @@ function useDispatchIntent(params) {
|
|
|
660
714
|
try {
|
|
661
715
|
if (!action && !intentId)
|
|
662
716
|
throw new Error("useDispatchIntent: Either `action` or `intentId` must be provided.");
|
|
663
|
-
|
|
664
|
-
projectId
|
|
665
|
-
dataset,
|
|
666
|
-
sourceName
|
|
667
|
-
} = documentHandle;
|
|
668
|
-
if (action && intentId && console.warn("useDispatchIntent: Both `action` and `intentId` were provided. Using `intentId` and ignoring `action`."), !sourceName && (!projectId || !dataset))
|
|
669
|
-
throw new Error("useDispatchIntent: Either `sourceName` or both `projectId` and `dataset` must be provided in documentHandle.");
|
|
717
|
+
if (action && intentId && console.warn("useDispatchIntent: Both `action` and `intentId` were provided. Using `intentId` and ignoring `action`."), !resource.id)
|
|
718
|
+
throw new Error("useDispatchIntent: Unable to determine resource. Either `source`, `sourceName`, or both `projectId` and `dataset` must be provided in documentHandle.");
|
|
670
719
|
const message = {
|
|
671
720
|
type: "dashboard/v1/events/intents/dispatch-intent",
|
|
672
721
|
data: {
|
|
@@ -1076,7 +1125,7 @@ function _temp$1(key) {
|
|
|
1076
1125
|
return !ignoredKeys.includes(key);
|
|
1077
1126
|
}
|
|
1078
1127
|
function useQuery(options) {
|
|
1079
|
-
const instance = useSanityInstance(options),
|
|
1128
|
+
const instance = useSanityInstance(options), normalized = useNormalizedSourceOptions(options), [isPending, startTransition] = useTransition(), queryKey = getQueryKey(normalized), [deferredQueryKey, setDeferredQueryKey] = useState(queryKey), ref = useRef(new AbortController());
|
|
1080
1129
|
useEffect(() => {
|
|
1081
1130
|
queryKey !== deferredQueryKey && startTransition(() => {
|
|
1082
1131
|
ref && !ref.current.signal.aborted && (ref.current.abort(), ref.current = new AbortController()), setDeferredQueryKey(queryKey);
|
|
@@ -1087,16 +1136,12 @@ function useQuery(options) {
|
|
|
1087
1136
|
subscribe
|
|
1088
1137
|
} = useMemo(() => {
|
|
1089
1138
|
const deferred = parseQueryKey(deferredQueryKey);
|
|
1090
|
-
return getQueryState(instance,
|
|
1091
|
-
|
|
1092
|
-
source
|
|
1093
|
-
});
|
|
1094
|
-
}, [instance, deferredQueryKey, source]);
|
|
1139
|
+
return getQueryState(instance, deferred);
|
|
1140
|
+
}, [instance, deferredQueryKey]);
|
|
1095
1141
|
if (getCurrent() === void 0) {
|
|
1096
1142
|
const currentSignal = ref.current.signal, deferred_0 = parseQueryKey(deferredQueryKey);
|
|
1097
1143
|
throw resolveQuery(instance, {
|
|
1098
1144
|
...deferred_0,
|
|
1099
|
-
source,
|
|
1100
1145
|
signal: currentSignal
|
|
1101
1146
|
});
|
|
1102
1147
|
}
|
|
@@ -1349,13 +1394,13 @@ function useDocumentProjection({
|
|
|
1349
1394
|
projection,
|
|
1350
1395
|
...docHandle
|
|
1351
1396
|
}) {
|
|
1352
|
-
const instance = useSanityInstance(docHandle), normalizedProjection = useMemo(() => projection.trim(), [projection]), stateSource = useMemo(() => getProjectionState(instance, {
|
|
1353
|
-
...
|
|
1397
|
+
const instance = useSanityInstance(docHandle), normalizedProjection = useMemo(() => projection.trim(), [projection]), normalizedDocHandle = useNormalizedSourceOptions(docHandle), stateSource = useMemo(() => getProjectionState(instance, {
|
|
1398
|
+
...normalizedDocHandle,
|
|
1354
1399
|
projection: normalizedProjection
|
|
1355
|
-
}), [instance,
|
|
1400
|
+
}), [instance, normalizedDocHandle, normalizedProjection]);
|
|
1356
1401
|
if (stateSource.getCurrent()?.data === null)
|
|
1357
1402
|
throw resolveProjection(instance, {
|
|
1358
|
-
...
|
|
1403
|
+
...normalizedDocHandle,
|
|
1359
1404
|
projection: normalizedProjection
|
|
1360
1405
|
});
|
|
1361
1406
|
const subscribe = useCallback((onStoreChanged) => {
|
|
@@ -1445,7 +1490,7 @@ function useUsers(options) {
|
|
|
1445
1490
|
loadMore
|
|
1446
1491
|
};
|
|
1447
1492
|
}
|
|
1448
|
-
var version = "2.
|
|
1493
|
+
var version = "2.8.0";
|
|
1449
1494
|
function getEnv(key) {
|
|
1450
1495
|
if (typeof import.meta < "u" && import.meta.env)
|
|
1451
1496
|
return import.meta.env[key];
|
|
@@ -1461,6 +1506,7 @@ export {
|
|
|
1461
1506
|
REACT_SDK_VERSION,
|
|
1462
1507
|
ResourceProvider,
|
|
1463
1508
|
SDKProvider,
|
|
1509
|
+
SDKStudioContext,
|
|
1464
1510
|
SanityApp,
|
|
1465
1511
|
renderSanityApp,
|
|
1466
1512
|
useActiveReleases,
|