@sanity/sdk-react 2.9.0 → 2.10.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/dist/index.d.ts +92 -26
- package/dist/index.js +304 -193
- package/dist/index.js.map +1 -1
- package/package.json +9 -11
- package/src/_exports/sdk-react.ts +4 -0
- package/src/components/SDKProvider.tsx +36 -8
- package/src/components/SanityApp.tsx +2 -2
- package/src/components/auth/AuthBoundary.tsx +8 -1
- package/src/components/auth/DashboardAccessRequest.tsx +37 -0
- package/src/components/auth/LoginError.test.tsx +191 -5
- package/src/components/auth/LoginError.tsx +100 -56
- package/src/components/errors/ChunkLoadError.test.tsx +59 -0
- package/src/components/errors/ChunkLoadError.tsx +56 -0
- package/src/components/errors/chunkReloadStorage.ts +57 -0
- package/src/context/ResourceProvider.tsx +5 -4
- package/src/context/ResourcesContext.tsx +7 -0
- package/src/context/SanityInstanceProvider.test.tsx +100 -0
- package/src/context/SanityInstanceProvider.tsx +71 -0
- package/src/hooks/auth/useVerifyOrgProjects.tsx +13 -6
- package/src/hooks/dashboard/useDispatchIntent.test.ts +6 -6
- package/src/hooks/dashboard/useDispatchIntent.ts +6 -6
- package/src/hooks/dashboard/utils/useResourceIdFromDocumentHandle.test.ts +15 -15
- package/src/hooks/dashboard/utils/useResourceIdFromDocumentHandle.ts +13 -13
- package/src/hooks/document/useApplyDocumentActions.test.ts +10 -10
- package/src/hooks/document/useApplyDocumentActions.ts +17 -17
- package/src/hooks/document/useDocument.ts +5 -5
- package/src/hooks/document/useDocumentEvent.ts +4 -4
- package/src/hooks/document/useDocumentPermissions.test.tsx +10 -10
- package/src/hooks/document/useDocumentPermissions.ts +8 -8
- package/src/hooks/document/useDocumentSyncStatus.ts +2 -2
- package/src/hooks/document/useEditDocument.ts +2 -2
- package/src/hooks/documents/useDocuments.ts +9 -6
- package/src/hooks/helpers/useNormalizedResourceOptions.ts +131 -0
- package/src/hooks/helpers/useTrackHookUsage.ts +2 -2
- package/src/hooks/paginatedDocuments/usePaginatedDocuments.ts +9 -8
- package/src/hooks/presence/usePresence.test.tsx +56 -9
- package/src/hooks/presence/usePresence.ts +23 -4
- package/src/hooks/preview/useDocumentPreview.tsx +8 -7
- package/src/hooks/projection/useDocumentProjection.ts +6 -6
- package/src/hooks/query/useQuery.ts +10 -9
- package/src/hooks/releases/useActiveReleases.ts +10 -10
- package/src/hooks/releases/usePerspective.ts +9 -9
- package/src/context/SourcesContext.tsx +0 -7
- package/src/hooks/helpers/useNormalizedSourceOptions.ts +0 -107
package/dist/index.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
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, getCorsErrorProjectId, createSanityInstance, agentGenerate, agentTransform, agentTranslate, agentPrompt, agentPatch, getTokenState, getCurrentUserState, getDashboardOrganizationId, getClientState, getOrCreateController, getOrCreateChannel, releaseChannel,
|
|
4
|
+
import { getAuthState, getNodeState, getIsInDashboardState, isStudioConfig, setAuthToken, AuthStateType, getLoginUrlState, observeOrganizationVerificationState, handleAuthCallback, logout, isProjectUserNotFoundClientError, getClientErrorApiDescription, getClientErrorApiBody, isImportError, getCorsErrorProjectId, createSanityInstance, agentGenerate, agentTransform, agentTranslate, agentPrompt, agentPatch, getTokenState, getCurrentUserState, getDashboardOrganizationId, getClientState, getOrCreateController, getOrCreateChannel, releaseChannel, isDatasetResource, isMediaLibraryResource, isCanvasResource, getFavoritesState, resolveFavoritesState, resolveDatasets, getDatasetsState, applyDocumentActions, resolveDocument, getDocumentState, subscribeDocumentEvents, getPermissionsState, getDocumentSyncStatus, editDocument, getQueryKey, parseQueryKey, getQueryState, resolveQuery, createGroqSearchFilter, getPresence, getProjectionState, resolveProjection, transformProjectionToPreview, PREVIEW_PROJECTION, resolveProject, getProjectState, resolveProjects, getProjectsState, getActiveReleasesState, getPerspectiveState, getUsersKey, parseUsersKey, getUsersState, resolveUsers, loadMoreUsers } from "@sanity/sdk";
|
|
5
5
|
export * from "@sanity/sdk";
|
|
6
|
-
import { createContext, useContext, useSyncExternalStore, useRef, useEffect, useState,
|
|
6
|
+
import { createContext, useContext, useSyncExternalStore, useRef, useEffect, useState, Suspense, useMemo, StrictMode, useCallback, useInsertionEffect, useTransition } from "react";
|
|
7
7
|
import { 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";
|
|
10
10
|
import { initTelemetry, trackHookMounted } from "@sanity/sdk/_internal";
|
|
11
11
|
import { createRoot } from "react-dom/client";
|
|
12
|
-
import { pick } from "lodash-es";
|
|
13
12
|
const SanityInstanceContext = createContext(null), useSanityInstance = (config) => {
|
|
14
13
|
const $ = c(3), instance = useContext(SanityInstanceContext);
|
|
15
14
|
if (!instance)
|
|
@@ -67,7 +66,7 @@ function useWindowConnection(t0) {
|
|
|
67
66
|
const [type, handler] = t42, messageUnsubscribe = node.on(type, handler);
|
|
68
67
|
messageUnsubscribe && messageUnsubscribers.current.push(messageUnsubscribe);
|
|
69
68
|
}), () => {
|
|
70
|
-
messageUnsubscribers.current.forEach(_temp$
|
|
69
|
+
messageUnsubscribers.current.forEach(_temp$9), messageUnsubscribers.current = [];
|
|
71
70
|
}), $[4] = node, $[5] = onMessage, $[6] = t3) : t3 = $[6];
|
|
72
71
|
let t4;
|
|
73
72
|
$[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);
|
|
@@ -85,7 +84,7 @@ function useWindowConnection(t0) {
|
|
|
85
84
|
fetch
|
|
86
85
|
}, $[16] = fetch, $[17] = sendMessage, $[18] = t7) : t7 = $[18], t7;
|
|
87
86
|
}
|
|
88
|
-
function _temp$
|
|
87
|
+
function _temp$9(unsubscribe) {
|
|
89
88
|
return unsubscribe();
|
|
90
89
|
}
|
|
91
90
|
const DEFAULT_RESPONSE_TIMEOUT = 1e4;
|
|
@@ -115,7 +114,7 @@ function DashboardTokenRefresh(t0) {
|
|
|
115
114
|
if (clearRefreshTimeout(), res.token) {
|
|
116
115
|
setAuthToken(instance, res.token);
|
|
117
116
|
const errorContainer = document.getElementById("__sanityError");
|
|
118
|
-
errorContainer && Array.from(errorContainer.getElementsByTagName("div")).some(_temp$
|
|
117
|
+
errorContainer && Array.from(errorContainer.getElementsByTagName("div")).some(_temp$8) && errorContainer.remove();
|
|
119
118
|
}
|
|
120
119
|
isTokenRefreshInProgress.current = !1;
|
|
121
120
|
} catch {
|
|
@@ -136,7 +135,7 @@ function DashboardTokenRefresh(t0) {
|
|
|
136
135
|
let t7;
|
|
137
136
|
return $[11] !== authState || $[12] !== requestNewToken ? (t7 = [authState, requestNewToken], $[11] = authState, $[12] = requestNewToken, $[13] = t7) : t7 = $[13], useEffect(t6, t7), children;
|
|
138
137
|
}
|
|
139
|
-
function _temp$
|
|
138
|
+
function _temp$8(div) {
|
|
140
139
|
return div.textContent?.includes("Uncaught error: Unauthorized - A valid session is required for this endpoint");
|
|
141
140
|
}
|
|
142
141
|
const ComlinkTokenRefreshProvider = (t0) => {
|
|
@@ -163,20 +162,41 @@ function useLoginUrl() {
|
|
|
163
162
|
return useSyncExternalStore(subscribe, getCurrent);
|
|
164
163
|
}
|
|
165
164
|
function useVerifyOrgProjects(t0, projectIds) {
|
|
166
|
-
const $ = c(
|
|
165
|
+
const $ = c(5), disabled = t0 === void 0 ? !1 : t0, instance = useSanityInstance(), [error, setError] = useState(null), isInactive = disabled || !projectIds || projectIds.length === 0, [prevInactive, setPrevInactive] = useState(isInactive);
|
|
166
|
+
prevInactive !== isInactive && (setPrevInactive(isInactive), isInactive && setError(null));
|
|
167
167
|
let t1, t2;
|
|
168
|
-
return $[0] !==
|
|
169
|
-
if (
|
|
170
|
-
error !== null && setError(null);
|
|
168
|
+
return $[0] !== instance || $[1] !== isInactive || $[2] !== projectIds ? (t1 = () => {
|
|
169
|
+
if (isInactive)
|
|
171
170
|
return;
|
|
172
|
-
}
|
|
173
171
|
const subscription = observeOrganizationVerificationState(instance, projectIds).subscribe((result) => {
|
|
174
172
|
setError(result.error);
|
|
175
173
|
});
|
|
176
174
|
return () => {
|
|
177
175
|
subscription.unsubscribe();
|
|
178
176
|
};
|
|
179
|
-
}, t2 = [instance,
|
|
177
|
+
}, t2 = [instance, isInactive, projectIds], $[0] = instance, $[1] = isInactive, $[2] = projectIds, $[3] = t1, $[4] = t2) : (t1 = $[3], t2 = $[4]), useEffect(t1, t2), error;
|
|
178
|
+
}
|
|
179
|
+
const CHUNK_RELOAD_STORAGE_KEY = "__sanity_sdk_chunk_reload_attempted";
|
|
180
|
+
function readChunkReloadFlag() {
|
|
181
|
+
try {
|
|
182
|
+
return typeof window > "u" || typeof window.sessionStorage > "u" ? !1 : window.sessionStorage.getItem(CHUNK_RELOAD_STORAGE_KEY) !== null;
|
|
183
|
+
} catch {
|
|
184
|
+
return !1;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function setChunkReloadFlag() {
|
|
188
|
+
try {
|
|
189
|
+
if (typeof window > "u" || typeof window.sessionStorage > "u") return;
|
|
190
|
+
window.sessionStorage.setItem(CHUNK_RELOAD_STORAGE_KEY, "1");
|
|
191
|
+
} catch {
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function clearChunkReloadFlag() {
|
|
195
|
+
try {
|
|
196
|
+
if (typeof window > "u" || typeof window.sessionStorage > "u") return;
|
|
197
|
+
window.sessionStorage.removeItem(CHUNK_RELOAD_STORAGE_KEY);
|
|
198
|
+
} catch {
|
|
199
|
+
}
|
|
180
200
|
}
|
|
181
201
|
const FONT_SANS_SERIF = "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Helvetica, Arial, system-ui, sans-serif", FONT_MONOSPACE = "-apple-system-ui-monospace, 'SF Mono', Menlo, Monaco, Consolas, monospace", styles = {
|
|
182
202
|
container: {
|
|
@@ -233,6 +253,31 @@ function Error$1(t0) {
|
|
|
233
253
|
t4
|
|
234
254
|
] }), $[8] = t1, $[9] = t2, $[10] = t3, $[11] = t4, $[12] = t5) : t5 = $[12], t5;
|
|
235
255
|
}
|
|
256
|
+
function reload() {
|
|
257
|
+
try {
|
|
258
|
+
window.location.reload();
|
|
259
|
+
} catch {
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function ChunkLoadError(_props) {
|
|
263
|
+
const $ = c(4);
|
|
264
|
+
let t0;
|
|
265
|
+
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = readChunkReloadFlag(), $[0] = t0) : t0 = $[0];
|
|
266
|
+
const alreadyAttempted = t0;
|
|
267
|
+
let t1, t2;
|
|
268
|
+
if ($[1] === Symbol.for("react.memo_cache_sentinel") ? (t1 = () => {
|
|
269
|
+
alreadyAttempted || (setChunkReloadFlag(), reload());
|
|
270
|
+
}, t2 = [alreadyAttempted], $[1] = t1, $[2] = t2) : (t1 = $[1], t2 = $[2]), useEffect(t1, t2), !alreadyAttempted)
|
|
271
|
+
return null;
|
|
272
|
+
let t3;
|
|
273
|
+
return $[3] === 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: {
|
|
274
|
+
text: "Reload page",
|
|
275
|
+
onClick: _temp$7
|
|
276
|
+
} }), $[3] = t3) : t3 = $[3], t3;
|
|
277
|
+
}
|
|
278
|
+
function _temp$7() {
|
|
279
|
+
clearChunkReloadFlag(), reload();
|
|
280
|
+
}
|
|
236
281
|
function CorsErrorComponent(t0) {
|
|
237
282
|
const $ = c(6), {
|
|
238
283
|
projectId,
|
|
@@ -298,60 +343,93 @@ function _temp$6(replacementLocation) {
|
|
|
298
343
|
replacementLocation && history.replaceState(null, "", replacementLocation);
|
|
299
344
|
}
|
|
300
345
|
const useLogOut = createCallbackHook(logout);
|
|
346
|
+
function DashboardAccessRequest(t0) {
|
|
347
|
+
const $ = c(5), {
|
|
348
|
+
projectId
|
|
349
|
+
} = t0;
|
|
350
|
+
let t1;
|
|
351
|
+
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = {
|
|
352
|
+
name: SDK_NODE_NAME,
|
|
353
|
+
connectTo: SDK_CHANNEL_NAME
|
|
354
|
+
}, $[0] = t1) : t1 = $[0];
|
|
355
|
+
const {
|
|
356
|
+
fetch
|
|
357
|
+
} = useWindowConnection(t1);
|
|
358
|
+
let t2, t3;
|
|
359
|
+
return $[1] !== fetch || $[2] !== projectId ? (t2 = () => {
|
|
360
|
+
fetch("dashboard/v1/auth/access/request", {
|
|
361
|
+
resourceType: "project",
|
|
362
|
+
resourceId: projectId
|
|
363
|
+
});
|
|
364
|
+
}, t3 = [fetch, projectId], $[1] = fetch, $[2] = projectId, $[3] = t2, $[4] = t3) : (t2 = $[3], t3 = $[4]), useEffect(t2, t3), null;
|
|
365
|
+
}
|
|
301
366
|
function LoginError(t0) {
|
|
302
|
-
const $ = c(
|
|
367
|
+
const $ = c(30), {
|
|
303
368
|
error,
|
|
304
369
|
resetErrorBoundary
|
|
305
370
|
} = t0;
|
|
306
371
|
if (!(error instanceof AuthError || error instanceof ConfigurationError || error instanceof ClientError))
|
|
307
372
|
throw error;
|
|
308
|
-
const logout2 = useLogOut(), authState = useAuthState(), {
|
|
373
|
+
const logout2 = useLogOut(), authState = useAuthState(), instance = useSanityInstance(), {
|
|
309
374
|
config: t1
|
|
310
|
-
} =
|
|
375
|
+
} = instance, {
|
|
311
376
|
projectId
|
|
312
|
-
} = t1,
|
|
377
|
+
} = t1, clientError = error instanceof ClientError ? error : error instanceof AuthError && error.cause instanceof ClientError ? error.cause : null;
|
|
313
378
|
let t2;
|
|
314
|
-
$[0]
|
|
315
|
-
|
|
316
|
-
connectTo: SDK_CHANNEL_NAME
|
|
317
|
-
}, $[0] = t2) : t2 = $[0];
|
|
318
|
-
const {
|
|
319
|
-
fetch
|
|
320
|
-
} = useWindowConnection(t2);
|
|
379
|
+
$[0] !== instance ? (t2 = getIsInDashboardState(instance).getCurrent(), $[0] = instance, $[1] = t2) : t2 = $[1];
|
|
380
|
+
const isInDashboard = t2;
|
|
321
381
|
let t3;
|
|
322
|
-
$[
|
|
323
|
-
|
|
324
|
-
}, $[1] = logout2, $[2] = resetErrorBoundary, $[3] = t3) : t3 = $[3];
|
|
325
|
-
const handleRetry = t3;
|
|
382
|
+
$[2] !== clientError ? (t3 = !!clientError && clientError.statusCode === 401 && isProjectUserNotFoundClientError(clientError), $[2] = clientError, $[3] = t3) : t3 = $[3];
|
|
383
|
+
const isProjectUserNotFound = t3, dashboardAccessProjectId = isProjectUserNotFound && projectId && isInDashboard ? projectId : null;
|
|
326
384
|
let t4;
|
|
327
|
-
$[4] !==
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
385
|
+
$[4] !== logout2 || $[5] !== resetErrorBoundary ? (t4 = async () => {
|
|
386
|
+
await logout2(), resetErrorBoundary();
|
|
387
|
+
}, $[4] = logout2, $[5] = resetErrorBoundary, $[6] = t4) : t4 = $[6];
|
|
388
|
+
const handleRetry = t4;
|
|
389
|
+
let t5, message = "Please try again or contact support if the problem persists.", retry = !0;
|
|
390
|
+
if (clientError) {
|
|
391
|
+
if (clientError.statusCode === 401)
|
|
392
|
+
if (isProjectUserNotFound) {
|
|
393
|
+
let t62;
|
|
394
|
+
$[7] !== clientError ? (t62 = getClientErrorApiDescription(clientError), $[7] = clientError, $[8] = t62) : t62 = $[8];
|
|
395
|
+
const description = t62;
|
|
396
|
+
description && (message = description), retry = !1;
|
|
397
|
+
} else
|
|
398
|
+
isInDashboard || (message = "Signing you out and returning to login...", retry = !0);
|
|
399
|
+
else if (clientError.statusCode === 404) {
|
|
400
|
+
const errorMessage = getClientErrorApiBody(clientError)?.message || "";
|
|
401
|
+
message = errorMessage.startsWith("Session with sid") && errorMessage.endsWith("not found") ? "The session ID is invalid or expired." : "The login link is invalid or expired. Please try again.", retry = !0;
|
|
342
402
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
let
|
|
346
|
-
$[
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
$[
|
|
403
|
+
}
|
|
404
|
+
authState.type !== AuthStateType.ERROR && error instanceof ConfigurationError && (message = error.message, retry = !0);
|
|
405
|
+
let t6;
|
|
406
|
+
$[9] !== message || $[10] !== retry ? (t6 = {
|
|
407
|
+
authErrorMessage: message,
|
|
408
|
+
showRetryCta: retry
|
|
409
|
+
}, $[9] = message, $[10] = retry, $[11] = t6) : t6 = $[11], t5 = t6;
|
|
410
|
+
const {
|
|
411
|
+
authErrorMessage,
|
|
412
|
+
showRetryCta
|
|
413
|
+
} = t5, hasAutoLoggedOutRef = useRef(!1);
|
|
414
|
+
let t7, t8;
|
|
415
|
+
$[12] !== clientError || $[13] !== handleRetry || $[14] !== isInDashboard || $[15] !== isProjectUserNotFound ? (t7 = () => {
|
|
416
|
+
clientError && clientError.statusCode === 401 && !isProjectUserNotFound && !isInDashboard && !hasAutoLoggedOutRef.current && (hasAutoLoggedOutRef.current = !0, handleRetry());
|
|
417
|
+
}, t8 = [clientError, handleRetry, isInDashboard, isProjectUserNotFound], $[12] = clientError, $[13] = handleRetry, $[14] = isInDashboard, $[15] = isProjectUserNotFound, $[16] = t7, $[17] = t8) : (t7 = $[16], t8 = $[17]), useEffect(t7, t8);
|
|
418
|
+
let t9;
|
|
419
|
+
$[18] !== dashboardAccessProjectId ? (t9 = dashboardAccessProjectId && /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(DashboardAccessRequest, { projectId: dashboardAccessProjectId }) }), $[18] = dashboardAccessProjectId, $[19] = t9) : t9 = $[19];
|
|
420
|
+
const t10 = error instanceof ConfigurationError ? "Configuration Error" : "Authentication Error";
|
|
421
|
+
let t11;
|
|
422
|
+
$[20] !== handleRetry || $[21] !== showRetryCta ? (t11 = showRetryCta ? {
|
|
350
423
|
text: "Retry",
|
|
351
424
|
onClick: handleRetry
|
|
352
|
-
} : void 0, $[
|
|
353
|
-
let
|
|
354
|
-
|
|
425
|
+
} : void 0, $[20] = handleRetry, $[21] = showRetryCta, $[22] = t11) : t11 = $[22];
|
|
426
|
+
let t12;
|
|
427
|
+
$[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];
|
|
428
|
+
let t13;
|
|
429
|
+
return $[27] !== t12 || $[28] !== t9 ? (t13 = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
430
|
+
t9,
|
|
431
|
+
t12
|
|
432
|
+
] }), $[27] = t12, $[28] = t9, $[29] = t13) : t13 = $[29], t13;
|
|
355
433
|
}
|
|
356
434
|
if (isInIframe() && !document.querySelector("[data-sanity-core]")) {
|
|
357
435
|
const parsedUrl = new URL(window.location.href), mode = new URLSearchParams(parsedUrl.hash.slice(1)).get("mode"), script = document.createElement("script");
|
|
@@ -367,7 +445,7 @@ function AuthBoundary(t0) {
|
|
|
367
445
|
const LoginErrorComponent = t1 === void 0 ? LoginError : t1;
|
|
368
446
|
let t2, t3;
|
|
369
447
|
$[3] !== LoginErrorComponent ? (t3 = function(fallbackProps) {
|
|
370
|
-
return fallbackProps.error instanceof CorsOriginError ? /* @__PURE__ */ jsx(CorsErrorComponent, { ...fallbackProps, projectId: getCorsErrorProjectId(fallbackProps.error) }) : /* @__PURE__ */ jsx(LoginErrorComponent, { ...fallbackProps });
|
|
448
|
+
return isImportError(fallbackProps.error) ? /* @__PURE__ */ jsx(ChunkLoadError, { ...fallbackProps }) : fallbackProps.error instanceof CorsOriginError ? /* @__PURE__ */ jsx(CorsErrorComponent, { ...fallbackProps, projectId: getCorsErrorProjectId(fallbackProps.error) }) : /* @__PURE__ */ jsx(LoginErrorComponent, { ...fallbackProps });
|
|
371
449
|
}, $[3] = LoginErrorComponent, $[4] = t3) : t3 = $[4], t2 = t3;
|
|
372
450
|
const FallbackComponent = t2;
|
|
373
451
|
let t4;
|
|
@@ -413,6 +491,17 @@ function AuthSwitch(t0) {
|
|
|
413
491
|
}
|
|
414
492
|
const SDKStudioContext = createContext(null);
|
|
415
493
|
SDKStudioContext.displayName = "SDKStudioContext";
|
|
494
|
+
function SanityInstanceProvider(t0) {
|
|
495
|
+
const $ = c(6), {
|
|
496
|
+
instance,
|
|
497
|
+
fallback,
|
|
498
|
+
children
|
|
499
|
+
} = t0;
|
|
500
|
+
let t1;
|
|
501
|
+
$[0] !== children || $[1] !== fallback ? (t1 = /* @__PURE__ */ jsx(Suspense, { fallback, children }), $[0] = children, $[1] = fallback, $[2] = t1) : t1 = $[2];
|
|
502
|
+
let t2;
|
|
503
|
+
return $[3] !== instance || $[4] !== t1 ? (t2 = /* @__PURE__ */ jsx(SanityInstanceContext.Provider, { value: instance, children: t1 }), $[3] = instance, $[4] = t1, $[5] = t2) : t2 = $[5], t2;
|
|
504
|
+
}
|
|
416
505
|
const DEFAULT_FALLBACK = /* @__PURE__ */ jsx(Fragment, { children: "Warning: No fallback provided. Please supply a fallback prop to ensure proper Suspense handling." });
|
|
417
506
|
function ResourceProvider({
|
|
418
507
|
children,
|
|
@@ -431,11 +520,19 @@ function ResourceProvider({
|
|
|
431
520
|
instance.isDisposed() || instance.dispose();
|
|
432
521
|
}, 0)
|
|
433
522
|
};
|
|
434
|
-
}), [instance]), /* @__PURE__ */ jsx(
|
|
523
|
+
}), [instance]), /* @__PURE__ */ jsx(SanityInstanceProvider, { instance, fallback: fallback ?? DEFAULT_FALLBACK, children });
|
|
524
|
+
}
|
|
525
|
+
const ResourcesContext = createContext({});
|
|
526
|
+
function ResetChunkReloadFlagOnMount() {
|
|
527
|
+
const $ = c(1);
|
|
528
|
+
let t0;
|
|
529
|
+
return $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = [], $[0] = t0) : t0 = $[0], useEffect(_temp$5, t0), null;
|
|
530
|
+
}
|
|
531
|
+
function _temp$5() {
|
|
532
|
+
clearChunkReloadFlag();
|
|
435
533
|
}
|
|
436
|
-
const SourcesContext = createContext({});
|
|
437
534
|
function SDKProvider(t0) {
|
|
438
|
-
const $ = c(
|
|
535
|
+
const $ = c(20);
|
|
439
536
|
let children, config, fallback, props;
|
|
440
537
|
$[0] !== t0 ? ({
|
|
441
538
|
children,
|
|
@@ -446,25 +543,37 @@ function SDKProvider(t0) {
|
|
|
446
543
|
let t1;
|
|
447
544
|
$[5] !== config ? (t1 = Array.isArray(config) ? config : [config], $[5] = config, $[6] = t1) : t1 = $[6];
|
|
448
545
|
let configs, t2;
|
|
449
|
-
$[7] !== t1 ? (configs = t1.slice().reverse(), t2 = configs.map(
|
|
546
|
+
$[7] !== t1 ? (configs = t1.slice().reverse(), t2 = configs.map(_temp2$1).filter(_temp3$1), $[7] = t1, $[8] = configs, $[9] = t2) : (configs = $[8], t2 = $[9]);
|
|
450
547
|
const projectIds = t2;
|
|
451
548
|
let t3, t4;
|
|
452
|
-
$[10] !== props.
|
|
453
|
-
const
|
|
549
|
+
$[10] !== props.resources ? (t4 = props.resources ?? {}, $[10] = props.resources, $[11] = t4) : t4 = $[11], t3 = t4;
|
|
550
|
+
const resourcesValue = t3;
|
|
454
551
|
let t5;
|
|
455
|
-
if ($[12] !== children || $[13] !== configs || $[14] !== fallback || $[15] !== projectIds || $[16] !== props || $[17] !==
|
|
456
|
-
const createNestedProviders = (index) => index >= configs.length ? /* @__PURE__ */ jsx(AuthBoundary, { ...props, projectIds, children: /* @__PURE__ */ jsx(
|
|
457
|
-
|
|
552
|
+
if ($[12] !== children || $[13] !== configs || $[14] !== fallback || $[15] !== projectIds || $[16] !== props || $[17] !== resourcesValue) {
|
|
553
|
+
const createNestedProviders = (index) => index >= configs.length ? /* @__PURE__ */ jsx(AuthBoundary, { ...props, projectIds, children: /* @__PURE__ */ jsx(ResourcesContext.Provider, { value: resourcesValue, children }) }) : /* @__PURE__ */ jsx(ResourceProvider, { ...configs[index], fallback, children: createNestedProviders(index + 1) });
|
|
554
|
+
let t6;
|
|
555
|
+
$[19] === Symbol.for("react.memo_cache_sentinel") ? (t6 = /* @__PURE__ */ jsx(ResetChunkReloadFlagOnMount, {}), $[19] = t6) : t6 = $[19], t5 = /* @__PURE__ */ jsxs(ErrorBoundary, { FallbackComponent: ChunkAwareFallback, children: [
|
|
556
|
+
t6,
|
|
557
|
+
createNestedProviders(0)
|
|
558
|
+
] }), $[12] = children, $[13] = configs, $[14] = fallback, $[15] = projectIds, $[16] = props, $[17] = resourcesValue, $[18] = t5;
|
|
458
559
|
} else
|
|
459
560
|
t5 = $[18];
|
|
460
561
|
return t5;
|
|
461
562
|
}
|
|
462
|
-
function
|
|
563
|
+
function _temp3$1(id) {
|
|
463
564
|
return !!id;
|
|
464
565
|
}
|
|
465
|
-
function
|
|
566
|
+
function _temp2$1(c2) {
|
|
466
567
|
return c2.projectId;
|
|
467
568
|
}
|
|
569
|
+
function ChunkAwareFallback(fallbackProps) {
|
|
570
|
+
const $ = c(2);
|
|
571
|
+
if (isImportError(fallbackProps.error)) {
|
|
572
|
+
let t0;
|
|
573
|
+
return $[0] !== fallbackProps ? (t0 = /* @__PURE__ */ jsx(ChunkLoadError, { ...fallbackProps }), $[0] = fallbackProps, $[1] = t0) : t0 = $[1], t0;
|
|
574
|
+
}
|
|
575
|
+
throw fallbackProps.error;
|
|
576
|
+
}
|
|
468
577
|
const REDIRECT_URL = "https://sanity.io/welcome";
|
|
469
578
|
function deriveConfigFromWorkspace(workspace) {
|
|
470
579
|
return {
|
|
@@ -658,36 +767,39 @@ function useDashboardNavigate(navigateFn) {
|
|
|
658
767
|
}
|
|
659
768
|
}, $[0] = navigateFn, $[1] = t0) : t0 = $[1], useWindowConnection(t0);
|
|
660
769
|
}
|
|
661
|
-
function
|
|
770
|
+
function normalizeResourceOptions(options, resources) {
|
|
662
771
|
const {
|
|
772
|
+
resourceName,
|
|
663
773
|
sourceName,
|
|
774
|
+
source,
|
|
664
775
|
...rest
|
|
665
|
-
} = options;
|
|
666
|
-
if (!
|
|
667
|
-
return
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
776
|
+
} = options, effectiveResourceName = resourceName ?? sourceName, effectiveResource = options.resource ?? source;
|
|
777
|
+
if (!effectiveResourceName && !effectiveResource)
|
|
778
|
+
return rest;
|
|
779
|
+
const hasNameKey = Object.hasOwn(options, "resourceName") || Object.hasOwn(options, "sourceName"), hasResourceKey = Object.hasOwn(options, "resource") || Object.hasOwn(options, "source");
|
|
780
|
+
if (hasNameKey && hasResourceKey)
|
|
781
|
+
throw new Error(`Resource name ${JSON.stringify(effectiveResourceName)} and resource ${JSON.stringify(effectiveResource)} cannot be used together.`);
|
|
782
|
+
let resolvedResource;
|
|
783
|
+
if (effectiveResource && (resolvedResource = effectiveResource), effectiveResourceName && !Object.hasOwn(resources, effectiveResourceName))
|
|
784
|
+
throw new Error(`There's no resource named ${JSON.stringify(effectiveResourceName)} in context. Please use <ResourceProvider>.`);
|
|
785
|
+
return effectiveResourceName && resources[effectiveResourceName] && (resolvedResource = resources[effectiveResourceName]), {
|
|
674
786
|
...rest,
|
|
675
|
-
|
|
787
|
+
resource: resolvedResource
|
|
676
788
|
};
|
|
677
789
|
}
|
|
678
|
-
function
|
|
679
|
-
const $ = c(3),
|
|
790
|
+
function useNormalizedResourceOptions(options) {
|
|
791
|
+
const $ = c(3), resources = useContext(ResourcesContext);
|
|
680
792
|
let t0;
|
|
681
|
-
return $[0] !== options || $[1] !==
|
|
793
|
+
return $[0] !== options || $[1] !== resources ? (t0 = normalizeResourceOptions(options, resources), $[0] = options, $[1] = resources, $[2] = t0) : t0 = $[2], t0;
|
|
682
794
|
}
|
|
683
795
|
function useResourceIdFromDocumentHandle(documentHandle) {
|
|
684
|
-
const $ = c(3), options =
|
|
796
|
+
const $ = c(3), options = useNormalizedResourceOptions(documentHandle), {
|
|
685
797
|
projectId,
|
|
686
798
|
dataset,
|
|
687
|
-
|
|
799
|
+
resource
|
|
688
800
|
} = options;
|
|
689
801
|
let resourceId = "", resourceType;
|
|
690
|
-
projectId && dataset && (resourceId = `${projectId}.${dataset}`),
|
|
802
|
+
projectId && dataset && (resourceId = `${projectId}.${dataset}`), resource && (isDatasetResource(resource) ? (resourceId = `${resource.projectId}.${resource.dataset}`, resourceType = void 0) : isMediaLibraryResource(resource) ? (resourceId = resource.mediaLibraryId, resourceType = "media-library") : isCanvasResource(resource) && (resourceId = resource.canvasId, resourceType = "canvas"));
|
|
691
803
|
let t0;
|
|
692
804
|
return $[0] !== resourceId || $[1] !== resourceType ? (t0 = {
|
|
693
805
|
id: resourceId,
|
|
@@ -712,7 +824,7 @@ function useDispatchIntent(params) {
|
|
|
712
824
|
if (!action && !intentId)
|
|
713
825
|
throw new Error("useDispatchIntent: Either `action` or `intentId` must be provided.");
|
|
714
826
|
if (action && intentId && console.warn("useDispatchIntent: Both `action` and `intentId` were provided. Using `intentId` and ignoring `action`."), !resource.id)
|
|
715
|
-
throw new Error("useDispatchIntent: Unable to determine resource. Either `
|
|
827
|
+
throw new Error("useDispatchIntent: Unable to determine resource. Either `resource`, `resourceName`, or both `projectId` and `dataset` must be provided in documentHandle.");
|
|
716
828
|
const message = {
|
|
717
829
|
type: "dashboard/v1/events/intents/dispatch-intent",
|
|
718
830
|
data: {
|
|
@@ -1001,25 +1113,25 @@ const useDatasets = createStateSourceHook({
|
|
|
1001
1113
|
suspender: resolveDatasets,
|
|
1002
1114
|
getConfig: identity
|
|
1003
1115
|
}), useApplyDocumentActions = () => {
|
|
1004
|
-
const $ = c(3), instance = useSanityInstance(),
|
|
1116
|
+
const $ = c(3), instance = useSanityInstance(), resources = useContext(ResourcesContext);
|
|
1005
1117
|
let t0;
|
|
1006
|
-
return $[0] !== instance || $[1] !==
|
|
1007
|
-
const actions = Array.isArray(actionOrActions) ? actionOrActions : [actionOrActions], normalizedOptions = options ?
|
|
1008
|
-
let projectId, dataset,
|
|
1118
|
+
return $[0] !== instance || $[1] !== resources ? (t0 = (actionOrActions, options) => {
|
|
1119
|
+
const actions = Array.isArray(actionOrActions) ? actionOrActions : [actionOrActions], normalizedOptions = options ? normalizeResourceOptions(options, resources) : void 0;
|
|
1120
|
+
let projectId, dataset, resource;
|
|
1009
1121
|
for (const action of actions) {
|
|
1010
1122
|
if (action.projectId) {
|
|
1011
|
-
if (
|
|
1012
|
-
throw new Error(`Mismatches between projectId/dataset options and
|
|
1123
|
+
if (resource)
|
|
1124
|
+
throw new Error(`Mismatches between projectId/dataset options and resource in actions. Found projectId "${action.projectId}" and dataset "${action.dataset}" but expected resource "${resource}".`);
|
|
1013
1125
|
if (projectId || (projectId = action.projectId), action.projectId !== projectId)
|
|
1014
1126
|
throw new Error(`Mismatched project IDs found in actions. All actions must belong to the same project. Found "${action.projectId}" but expected "${projectId}".`);
|
|
1015
1127
|
if (action.dataset && (dataset || (dataset = action.dataset), action.dataset !== dataset))
|
|
1016
1128
|
throw new Error(`Mismatched datasets found in actions. All actions must belong to the same dataset. Found "${action.dataset}" but expected "${dataset}".`);
|
|
1017
1129
|
}
|
|
1018
|
-
if (action.
|
|
1019
|
-
if (
|
|
1020
|
-
throw new Error(`Mismatched
|
|
1130
|
+
if (action.resource) {
|
|
1131
|
+
if (resource || (resource = action.resource), action.resource !== resource)
|
|
1132
|
+
throw new Error(`Mismatched resources found in actions. All actions must belong to the same resource. Found "${action.resource}" but expected "${resource}".`);
|
|
1021
1133
|
if (projectId || dataset)
|
|
1022
|
-
throw new Error(`Mismatches between projectId/dataset options and
|
|
1134
|
+
throw new Error(`Mismatches between projectId/dataset options and resource in actions. Found "${action.resource}" but expected project "${projectId}" and dataset "${dataset}".`);
|
|
1023
1135
|
}
|
|
1024
1136
|
}
|
|
1025
1137
|
if (projectId || dataset) {
|
|
@@ -1035,20 +1147,20 @@ const useDatasets = createStateSourceHook({
|
|
|
1035
1147
|
Please ensure there is a ResourceProvider component with a matching configuration in the component hierarchy.`);
|
|
1036
1148
|
return applyDocumentActions(actualInstance, {
|
|
1037
1149
|
actions,
|
|
1038
|
-
|
|
1150
|
+
resource,
|
|
1039
1151
|
...normalizedOptions
|
|
1040
1152
|
});
|
|
1041
1153
|
}
|
|
1042
1154
|
return applyDocumentActions(instance, {
|
|
1043
1155
|
actions,
|
|
1044
|
-
|
|
1156
|
+
resource,
|
|
1045
1157
|
...normalizedOptions
|
|
1046
1158
|
});
|
|
1047
|
-
}, $[0] = instance, $[1] =
|
|
1159
|
+
}, $[0] = instance, $[1] = resources, $[2] = t0) : t0 = $[2], t0;
|
|
1048
1160
|
};
|
|
1049
1161
|
function useTrackHookUsage(hookName) {
|
|
1050
|
-
const instance = useSanityInstance(), tracked = useRef(
|
|
1051
|
-
tracked.current
|
|
1162
|
+
const instance = useSanityInstance(), tracked = useRef(null);
|
|
1163
|
+
tracked.current === null && (tracked.current = !0, trackHookMounted(instance, hookName));
|
|
1052
1164
|
}
|
|
1053
1165
|
function trackHookUsage(instance, hookName) {
|
|
1054
1166
|
trackHookMounted(instance, hookName);
|
|
@@ -1073,13 +1185,13 @@ const useDocumentValue = createStateSourceHook({
|
|
|
1073
1185
|
return useHook;
|
|
1074
1186
|
}, useDocument = wrapHookWithData((options) => {
|
|
1075
1187
|
useTrackHookUsage("useDocument");
|
|
1076
|
-
const normalizedOptions =
|
|
1188
|
+
const normalizedOptions = useNormalizedResourceOptions(options);
|
|
1077
1189
|
return useDocumentValue(normalizedOptions);
|
|
1078
1190
|
});
|
|
1079
1191
|
function useDocumentEvent(options) {
|
|
1080
1192
|
const $ = c(10);
|
|
1081
1193
|
useTrackHookUsage("useDocumentEvent");
|
|
1082
|
-
const normalizedOptions =
|
|
1194
|
+
const normalizedOptions = useNormalizedResourceOptions(options);
|
|
1083
1195
|
let datasetHandle, onEvent;
|
|
1084
1196
|
$[0] !== normalizedOptions ? ({
|
|
1085
1197
|
onEvent,
|
|
@@ -1094,37 +1206,37 @@ function useDocumentEvent(options) {
|
|
|
1094
1206
|
$[5] === Symbol.for("react.memo_cache_sentinel") ? (t1 = (documentEvent) => ref.current(documentEvent), $[5] = t1) : t1 = $[5];
|
|
1095
1207
|
const stableHandler = t1, instance = useSanityInstance(datasetHandle);
|
|
1096
1208
|
let t2, t3;
|
|
1097
|
-
$[6] !== datasetHandle.
|
|
1209
|
+
$[6] !== datasetHandle.resource || $[7] !== instance ? (t2 = () => subscribeDocumentEvents(instance, {
|
|
1098
1210
|
eventHandler: stableHandler,
|
|
1099
|
-
|
|
1100
|
-
}), t3 = [instance, datasetHandle.
|
|
1211
|
+
resource: datasetHandle.resource
|
|
1212
|
+
}), t3 = [instance, datasetHandle.resource, stableHandler], $[6] = datasetHandle.resource, $[7] = instance, $[8] = t2, $[9] = t3) : (t2 = $[8], t3 = $[9]), useEffect(t2, t3);
|
|
1101
1213
|
}
|
|
1102
1214
|
function useDocumentPermissions(actionOrActions) {
|
|
1103
1215
|
const $ = c(15);
|
|
1104
1216
|
let t0, t1;
|
|
1105
1217
|
$[0] !== actionOrActions ? (t1 = Array.isArray(actionOrActions) ? actionOrActions : [actionOrActions], $[0] = actionOrActions, $[1] = t1) : t1 = $[1], t0 = t1;
|
|
1106
1218
|
const actions = t0;
|
|
1107
|
-
let projectId, dataset,
|
|
1108
|
-
if ($[2] !== actions || $[3] !== dataset || $[4] !== projectId || $[5] !==
|
|
1219
|
+
let projectId, dataset, resource;
|
|
1220
|
+
if ($[2] !== actions || $[3] !== dataset || $[4] !== projectId || $[5] !== resource) {
|
|
1109
1221
|
for (const action of actions) {
|
|
1110
1222
|
if (action.projectId) {
|
|
1111
|
-
if (
|
|
1112
|
-
throw new Error(`Mismatches between projectId/dataset options and
|
|
1223
|
+
if (resource)
|
|
1224
|
+
throw new Error(`Mismatches between projectId/dataset options and resource in actions. Found projectId "${action.projectId}" and dataset "${action.dataset}" but expected resource "${resource}".`);
|
|
1113
1225
|
if (projectId || (projectId = action.projectId), action.projectId !== projectId)
|
|
1114
1226
|
throw new Error(`Mismatched project IDs found in actions. All actions must belong to the same project. Found "${action.projectId}" but expected "${projectId}".`);
|
|
1115
1227
|
if (action.dataset && (dataset || (dataset = action.dataset), action.dataset !== dataset))
|
|
1116
1228
|
throw new Error(`Mismatched datasets found in actions. All actions must belong to the same dataset. Found "${action.dataset}" but expected "${dataset}".`);
|
|
1117
1229
|
}
|
|
1118
|
-
if (action.
|
|
1119
|
-
if (
|
|
1120
|
-
throw new Error(`Mismatched
|
|
1230
|
+
if (action.resource) {
|
|
1231
|
+
if (resource || (resource = action.resource), action.resource !== resource)
|
|
1232
|
+
throw new Error(`Mismatched resources found in actions. All actions must belong to the same resource. Found "${action.resource}" but expected "${resource}".`);
|
|
1121
1233
|
if (projectId || dataset)
|
|
1122
|
-
throw new Error(`Mismatches between projectId/dataset options and
|
|
1234
|
+
throw new Error(`Mismatches between projectId/dataset options and resource in actions. Found "${action.resource}" but expected project "${projectId}" and dataset "${dataset}".`);
|
|
1123
1235
|
}
|
|
1124
1236
|
}
|
|
1125
|
-
$[2] = actions, $[3] = dataset, $[4] = projectId, $[5] =
|
|
1237
|
+
$[2] = actions, $[3] = dataset, $[4] = projectId, $[5] = resource, $[6] = projectId, $[7] = dataset, $[8] = resource;
|
|
1126
1238
|
} else
|
|
1127
|
-
projectId = $[6], dataset = $[7],
|
|
1239
|
+
projectId = $[6], dataset = $[7], resource = $[8];
|
|
1128
1240
|
let t2;
|
|
1129
1241
|
$[9] !== dataset || $[10] !== projectId ? (t2 = {
|
|
1130
1242
|
projectId,
|
|
@@ -1156,7 +1268,7 @@ const useDocumentSyncStatusValue = createStateSourceHook({
|
|
|
1156
1268
|
suspender: (instance, doc) => resolveDocument(instance, doc),
|
|
1157
1269
|
getConfig: identity
|
|
1158
1270
|
}), useDocumentSyncStatus = (options) => {
|
|
1159
|
-
const normalizedOptions =
|
|
1271
|
+
const normalizedOptions = useNormalizedResourceOptions(options);
|
|
1160
1272
|
return useDocumentSyncStatusValue(normalizedOptions);
|
|
1161
1273
|
}, ignoredKeys = ["_id", "_type", "_createdAt", "_updatedAt", "_rev"];
|
|
1162
1274
|
function useEditDocument(t0) {
|
|
@@ -1168,7 +1280,7 @@ function useEditDocument(t0) {
|
|
|
1168
1280
|
} = t0, $[0] = t0, $[1] = doc, $[2] = path) : (doc = $[1], path = $[2]);
|
|
1169
1281
|
const instance = useSanityInstance(doc);
|
|
1170
1282
|
trackHookUsage(instance, "useEditDocument");
|
|
1171
|
-
const normalizedDoc =
|
|
1283
|
+
const normalizedDoc = useNormalizedResourceOptions(doc), apply = useApplyDocumentActions();
|
|
1172
1284
|
if (getDocumentState(instance, normalizedDoc).getCurrent() === void 0)
|
|
1173
1285
|
throw resolveDocument(instance, normalizedDoc);
|
|
1174
1286
|
let t1;
|
|
@@ -1210,7 +1322,7 @@ function _temp$1(key) {
|
|
|
1210
1322
|
function useQuery(options) {
|
|
1211
1323
|
const instance = useSanityInstance(options);
|
|
1212
1324
|
trackHookUsage(instance, "useQuery");
|
|
1213
|
-
const normalized =
|
|
1325
|
+
const normalized = useNormalizedResourceOptions(options), [isPending, startTransition] = useTransition(), queryKey = getQueryKey(normalized), [deferredQueryKey, setDeferredQueryKey] = useState(queryKey), ref = useRef(new AbortController());
|
|
1214
1326
|
useEffect(() => {
|
|
1215
1327
|
queryKey !== deferredQueryKey && startTransition(() => {
|
|
1216
1328
|
ref && !ref.current.signal.aborted && (ref.current.abort(), ref.current = new AbortController()), setDeferredQueryKey(queryKey);
|
|
@@ -1255,10 +1367,8 @@ function useDocuments({
|
|
|
1255
1367
|
batchSize,
|
|
1256
1368
|
types: documentTypes,
|
|
1257
1369
|
...options
|
|
1258
|
-
});
|
|
1259
|
-
|
|
1260
|
-
setLimit(batchSize);
|
|
1261
|
-
}, [key, batchSize]);
|
|
1370
|
+
}), [prevKey, setPrevKey] = useState(key);
|
|
1371
|
+
prevKey !== key && (setPrevKey(key), setLimit(batchSize));
|
|
1262
1372
|
const filterClause = useMemo(() => {
|
|
1263
1373
|
const conditions = [], trimmedSearch = search?.trim();
|
|
1264
1374
|
if (trimmedSearch) {
|
|
@@ -1277,9 +1387,11 @@ function useDocuments({
|
|
|
1277
1387
|
query: `{"count":${countQuery},"data":${dataQuery}}`,
|
|
1278
1388
|
params: {
|
|
1279
1389
|
...params,
|
|
1390
|
+
// these are passed back to the user as part of each document handle
|
|
1280
1391
|
__handle: {
|
|
1281
|
-
|
|
1282
|
-
|
|
1392
|
+
projectId: options.projectId ?? instance.config.projectId,
|
|
1393
|
+
dataset: options.dataset ?? instance.config.dataset,
|
|
1394
|
+
perspective: options.perspective ?? instance.config.perspective
|
|
1283
1395
|
},
|
|
1284
1396
|
__types: documentTypes
|
|
1285
1397
|
}
|
|
@@ -1295,7 +1407,7 @@ function useDocuments({
|
|
|
1295
1407
|
}), [count, data, hasMore, isPending, loadMore]);
|
|
1296
1408
|
}
|
|
1297
1409
|
function usePaginatedDocuments(t0) {
|
|
1298
|
-
const $ = c(
|
|
1410
|
+
const $ = c(56);
|
|
1299
1411
|
let documentType, options, orderings, search, t1, t2, t3;
|
|
1300
1412
|
$[0] !== t0 ? ({
|
|
1301
1413
|
documentType,
|
|
@@ -1320,74 +1432,66 @@ function usePaginatedDocuments(t0) {
|
|
|
1320
1432
|
orderings,
|
|
1321
1433
|
pageSize
|
|
1322
1434
|
}), $[10] = filter2, $[11] = orderings, $[12] = pageSize, $[13] = params, $[14] = search, $[15] = t5) : t5 = $[15];
|
|
1323
|
-
const key = t5;
|
|
1435
|
+
const key = t5, [prevKey, setPrevKey] = useState(key);
|
|
1436
|
+
prevKey !== key && (setPrevKey(key), setPageIndex(0));
|
|
1437
|
+
const startIndex = pageIndex * pageSize, endIndex = (pageIndex + 1) * pageSize;
|
|
1324
1438
|
let t6;
|
|
1325
|
-
$[16]
|
|
1326
|
-
setPageIndex(0);
|
|
1327
|
-
}, $[16] = t6) : t6 = $[16];
|
|
1439
|
+
$[16] !== documentType ? (t6 = Array.isArray(documentType) ? documentType : [documentType], $[16] = documentType, $[17] = t6) : t6 = $[17];
|
|
1328
1440
|
let t7;
|
|
1329
|
-
$[
|
|
1330
|
-
const
|
|
1441
|
+
$[18] !== t6 ? (t7 = t6.filter(_temp), $[18] = t6, $[19] = t7) : t7 = $[19];
|
|
1442
|
+
const documentTypes = t7;
|
|
1331
1443
|
let t8;
|
|
1332
|
-
$[19] !== documentType ? (t8 = Array.isArray(documentType) ? documentType : [documentType], $[19] = documentType, $[20] = t8) : t8 = $[20];
|
|
1333
|
-
let t9;
|
|
1334
|
-
$[21] !== t8 ? (t9 = t8.filter(_temp), $[21] = t8, $[22] = t9) : t9 = $[22];
|
|
1335
|
-
const documentTypes = t9;
|
|
1336
|
-
let t10;
|
|
1337
1444
|
const conditions = [], trimmedSearch = search?.trim();
|
|
1338
1445
|
if (trimmedSearch) {
|
|
1339
1446
|
const searchFilter = createGroqSearchFilter(trimmedSearch);
|
|
1340
1447
|
searchFilter && conditions.push(searchFilter);
|
|
1341
1448
|
}
|
|
1342
|
-
documentTypes?.length && conditions.push("(_type in $__types)"), filter2 && conditions.push(`(${filter2})`),
|
|
1343
|
-
const filterClause =
|
|
1344
|
-
let t12;
|
|
1345
|
-
$[23] !== instance.config ? (t12 = pick(instance.config, "projectId", "dataset", "perspective"), $[23] = instance.config, $[24] = t12) : t12 = $[24];
|
|
1449
|
+
documentTypes?.length && conditions.push("(_type in $__types)"), filter2 && conditions.push(`(${filter2})`), t8 = conditions.length ? `[${conditions.join(" && ")}]` : "";
|
|
1450
|
+
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}}`, t10 = options.projectId ?? instance.config.projectId, t11 = options.dataset ?? instance.config.dataset, t12 = options.perspective ?? instance.config.perspective;
|
|
1346
1451
|
let t13;
|
|
1347
|
-
$[
|
|
1452
|
+
$[20] !== t10 || $[21] !== t11 || $[22] !== t12 ? (t13 = {
|
|
1453
|
+
projectId: t10,
|
|
1454
|
+
dataset: t11,
|
|
1455
|
+
perspective: t12
|
|
1456
|
+
}, $[20] = t10, $[21] = t11, $[22] = t12, $[23] = t13) : t13 = $[23];
|
|
1348
1457
|
let t14;
|
|
1349
|
-
$[
|
|
1350
|
-
...t12,
|
|
1351
|
-
...t13
|
|
1352
|
-
}, $[27] = t12, $[28] = t13, $[29] = t14) : t14 = $[29];
|
|
1353
|
-
let t15;
|
|
1354
|
-
$[30] !== documentTypes || $[31] !== params || $[32] !== t14 ? (t15 = {
|
|
1458
|
+
$[24] !== documentTypes || $[25] !== params || $[26] !== t13 ? (t14 = {
|
|
1355
1459
|
...params,
|
|
1356
1460
|
__types: documentTypes,
|
|
1357
|
-
__handle:
|
|
1358
|
-
}, $[
|
|
1359
|
-
let
|
|
1360
|
-
$[
|
|
1461
|
+
__handle: t13
|
|
1462
|
+
}, $[24] = documentTypes, $[25] = params, $[26] = t13, $[27] = t14) : t14 = $[27];
|
|
1463
|
+
let t15;
|
|
1464
|
+
$[28] !== options || $[29] !== t14 || $[30] !== t9 ? (t15 = {
|
|
1361
1465
|
...options,
|
|
1362
|
-
query:
|
|
1363
|
-
params:
|
|
1364
|
-
}, $[
|
|
1466
|
+
query: t9,
|
|
1467
|
+
params: t14
|
|
1468
|
+
}, $[28] = options, $[29] = t14, $[30] = t9, $[31] = t15) : t15 = $[31];
|
|
1365
1469
|
const {
|
|
1366
|
-
data:
|
|
1470
|
+
data: t16,
|
|
1367
1471
|
isPending
|
|
1368
|
-
} = useQuery(
|
|
1472
|
+
} = useQuery(t15), {
|
|
1369
1473
|
data,
|
|
1370
1474
|
count
|
|
1371
|
-
} =
|
|
1475
|
+
} = t16, totalPages = Math.ceil(count / pageSize), currentPage = pageIndex + 1;
|
|
1476
|
+
let t17;
|
|
1477
|
+
$[32] === Symbol.for("react.memo_cache_sentinel") ? (t17 = () => setPageIndex(0), $[32] = t17) : t17 = $[32];
|
|
1478
|
+
const firstPage = t17;
|
|
1372
1479
|
let t18;
|
|
1373
|
-
$[
|
|
1374
|
-
const
|
|
1480
|
+
$[33] === Symbol.for("react.memo_cache_sentinel") ? (t18 = () => setPageIndex(_temp4), $[33] = t18) : t18 = $[33];
|
|
1481
|
+
const previousPage = t18;
|
|
1375
1482
|
let t19;
|
|
1376
|
-
$[
|
|
1377
|
-
const
|
|
1483
|
+
$[34] !== totalPages ? (t19 = () => setPageIndex((prev_0) => Math.min(prev_0 + 1, totalPages - 1)), $[34] = totalPages, $[35] = t19) : t19 = $[35];
|
|
1484
|
+
const nextPage = t19;
|
|
1378
1485
|
let t20;
|
|
1379
|
-
$[
|
|
1380
|
-
const
|
|
1486
|
+
$[36] !== totalPages ? (t20 = () => setPageIndex(totalPages - 1), $[36] = totalPages, $[37] = t20) : t20 = $[37];
|
|
1487
|
+
const lastPage = t20;
|
|
1381
1488
|
let t21;
|
|
1382
|
-
$[
|
|
1383
|
-
const lastPage = t21;
|
|
1384
|
-
let t22;
|
|
1385
|
-
$[44] !== totalPages ? (t22 = (pageNumber) => {
|
|
1489
|
+
$[38] !== totalPages ? (t21 = (pageNumber) => {
|
|
1386
1490
|
pageNumber < 1 || pageNumber > totalPages || setPageIndex(pageNumber - 1);
|
|
1387
|
-
}, $[
|
|
1388
|
-
const goToPage =
|
|
1389
|
-
let
|
|
1390
|
-
return $[
|
|
1491
|
+
}, $[38] = totalPages, $[39] = t21) : t21 = $[39];
|
|
1492
|
+
const goToPage = t21, hasFirstPage = pageIndex > 0, hasPreviousPage = pageIndex > 0, hasNextPage = pageIndex < totalPages - 1, hasLastPage = pageIndex < totalPages - 1;
|
|
1493
|
+
let t22;
|
|
1494
|
+
return $[40] !== count || $[41] !== currentPage || $[42] !== data || $[43] !== endIndex || $[44] !== goToPage || $[45] !== hasFirstPage || $[46] !== hasLastPage || $[47] !== hasNextPage || $[48] !== hasPreviousPage || $[49] !== isPending || $[50] !== lastPage || $[51] !== nextPage || $[52] !== pageSize || $[53] !== startIndex || $[54] !== totalPages ? (t22 = {
|
|
1391
1495
|
data,
|
|
1392
1496
|
isPending,
|
|
1393
1497
|
pageSize,
|
|
@@ -1405,7 +1509,7 @@ function usePaginatedDocuments(t0) {
|
|
|
1405
1509
|
lastPage,
|
|
1406
1510
|
hasLastPage,
|
|
1407
1511
|
goToPage
|
|
1408
|
-
}, $[
|
|
1512
|
+
}, $[40] = count, $[41] = currentPage, $[42] = data, $[43] = endIndex, $[44] = goToPage, $[45] = hasFirstPage, $[46] = hasLastPage, $[47] = hasNextPage, $[48] = hasPreviousPage, $[49] = isPending, $[50] = lastPage, $[51] = nextPage, $[52] = pageSize, $[53] = startIndex, $[54] = totalPages, $[55] = t22) : t22 = $[55], t22;
|
|
1409
1513
|
}
|
|
1410
1514
|
function _temp4(prev) {
|
|
1411
1515
|
return Math.max(prev - 1, 0);
|
|
@@ -1419,24 +1523,30 @@ function _temp2(str) {
|
|
|
1419
1523
|
function _temp(i) {
|
|
1420
1524
|
return typeof i == "string";
|
|
1421
1525
|
}
|
|
1422
|
-
function usePresence() {
|
|
1423
|
-
const $ = c(
|
|
1526
|
+
function usePresence(t0) {
|
|
1527
|
+
const $ = c(14);
|
|
1528
|
+
let t1;
|
|
1529
|
+
$[0] !== t0 ? (t1 = t0 === void 0 ? {} : t0, $[0] = t0, $[1] = t1) : t1 = $[1];
|
|
1530
|
+
const normalizedOptions = useNormalizedResourceOptions(t1);
|
|
1531
|
+
if (normalizedOptions.resource && isMediaLibraryResource(normalizedOptions.resource))
|
|
1532
|
+
throw new Error("usePresence() does not support media library resources. Presence tracking requires a canvas or dataset resource.");
|
|
1533
|
+
const sanityInstance = useSanityInstance();
|
|
1424
1534
|
trackHookUsage(sanityInstance, "usePresence");
|
|
1425
|
-
let
|
|
1426
|
-
$[
|
|
1427
|
-
const source =
|
|
1428
|
-
let
|
|
1429
|
-
$[
|
|
1430
|
-
const subscribe =
|
|
1431
|
-
let
|
|
1432
|
-
$[
|
|
1433
|
-
const locations = useSyncExternalStore(subscribe,
|
|
1434
|
-
let
|
|
1435
|
-
$[
|
|
1436
|
-
let
|
|
1437
|
-
return $[
|
|
1438
|
-
locations:
|
|
1439
|
-
}, $[
|
|
1535
|
+
let t2, t3;
|
|
1536
|
+
$[2] !== normalizedOptions || $[3] !== sanityInstance ? (t3 = getPresence(sanityInstance, normalizedOptions), $[2] = normalizedOptions, $[3] = sanityInstance, $[4] = t3) : t3 = $[4], t2 = t3;
|
|
1537
|
+
const source = t2;
|
|
1538
|
+
let t4;
|
|
1539
|
+
$[5] !== source ? (t4 = (callback) => source.subscribe(callback), $[5] = source, $[6] = t4) : t4 = $[6];
|
|
1540
|
+
const subscribe = t4;
|
|
1541
|
+
let t5, t6;
|
|
1542
|
+
$[7] !== source ? (t5 = () => source.getCurrent(), t6 = () => source.getCurrent(), $[7] = source, $[8] = t5, $[9] = t6) : (t5 = $[8], t6 = $[9]);
|
|
1543
|
+
const locations = useSyncExternalStore(subscribe, t5, t6);
|
|
1544
|
+
let t7;
|
|
1545
|
+
$[10] !== locations ? (t7 = locations || [], $[10] = locations, $[11] = t7) : t7 = $[11];
|
|
1546
|
+
let t8;
|
|
1547
|
+
return $[12] !== t7 ? (t8 = {
|
|
1548
|
+
locations: t7
|
|
1549
|
+
}, $[12] = t7, $[13] = t8) : t8 = $[13], t8;
|
|
1440
1550
|
}
|
|
1441
1551
|
function useDocumentProjection({
|
|
1442
1552
|
ref,
|
|
@@ -1445,7 +1555,7 @@ function useDocumentProjection({
|
|
|
1445
1555
|
}) {
|
|
1446
1556
|
const instance = useSanityInstance(docHandle);
|
|
1447
1557
|
trackHookUsage(instance, "useDocumentProjection");
|
|
1448
|
-
const normalizedProjection = useMemo(() => projection.trim(), [projection]), normalizedDocHandle =
|
|
1558
|
+
const normalizedProjection = useMemo(() => projection.trim(), [projection]), normalizedDocHandle = useNormalizedResourceOptions(docHandle), stateSource = useMemo(() => getProjectionState(instance, {
|
|
1449
1559
|
...normalizedDocHandle,
|
|
1450
1560
|
projection: normalizedProjection
|
|
1451
1561
|
}), [instance, normalizedDocHandle, normalizedProjection]);
|
|
@@ -1481,7 +1591,7 @@ function useDocumentPreview(t0) {
|
|
|
1481
1591
|
} = t0, $[0] = t0, $[1] = docHandle, $[2] = ref) : (docHandle = $[1], ref = $[2]);
|
|
1482
1592
|
const instance = useSanityInstance(docHandle);
|
|
1483
1593
|
trackHookUsage(instance, "useDocumentPreview");
|
|
1484
|
-
const normalizedDocHandle =
|
|
1594
|
+
const normalizedDocHandle = useNormalizedResourceOptions(docHandle);
|
|
1485
1595
|
let t1;
|
|
1486
1596
|
$[3] !== normalizedDocHandle || $[4] !== ref ? (t1 = {
|
|
1487
1597
|
...normalizedDocHandle,
|
|
@@ -1490,7 +1600,7 @@ function useDocumentPreview(t0) {
|
|
|
1490
1600
|
}, $[3] = normalizedDocHandle, $[4] = ref, $[5] = t1) : t1 = $[5];
|
|
1491
1601
|
const projectionResult = useDocumentProjection(t1);
|
|
1492
1602
|
let t2, t3;
|
|
1493
|
-
$[6] !== instance || $[7] !== normalizedDocHandle.
|
|
1603
|
+
$[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;
|
|
1494
1604
|
const previewValue = t2;
|
|
1495
1605
|
let t4;
|
|
1496
1606
|
return $[10] !== previewValue || $[11] !== projectionResult.isPending ? (t4 = {
|
|
@@ -1516,7 +1626,7 @@ const useProject = createStateSourceHook({
|
|
|
1516
1626
|
const $ = c(2);
|
|
1517
1627
|
let t0;
|
|
1518
1628
|
$[0] !== options ? (t0 = options ?? {}, $[0] = options, $[1] = t0) : t0 = $[1];
|
|
1519
|
-
const normalizedOptions =
|
|
1629
|
+
const normalizedOptions = useNormalizedResourceOptions(t0);
|
|
1520
1630
|
return useActiveReleasesValue(normalizedOptions);
|
|
1521
1631
|
}, usePerspectiveValue = createStateSourceHook({
|
|
1522
1632
|
getState: getPerspectiveState,
|
|
@@ -1526,7 +1636,7 @@ const useProject = createStateSourceHook({
|
|
|
1526
1636
|
const $ = c(2);
|
|
1527
1637
|
let t0;
|
|
1528
1638
|
$[0] !== options ? (t0 = options ?? {}, $[0] = options, $[1] = t0) : t0 = $[1];
|
|
1529
|
-
const normalizedOptions =
|
|
1639
|
+
const normalizedOptions = useNormalizedResourceOptions(t0);
|
|
1530
1640
|
return usePerspectiveValue(normalizedOptions);
|
|
1531
1641
|
};
|
|
1532
1642
|
function useUser(options) {
|
|
@@ -1583,7 +1693,7 @@ function useUsers(options) {
|
|
|
1583
1693
|
loadMore
|
|
1584
1694
|
};
|
|
1585
1695
|
}
|
|
1586
|
-
var version = "2.
|
|
1696
|
+
var version = "2.10.0";
|
|
1587
1697
|
function getEnv(key) {
|
|
1588
1698
|
if (typeof import.meta < "u" && import.meta.env)
|
|
1589
1699
|
return import.meta.env[key];
|
|
@@ -1601,6 +1711,7 @@ export {
|
|
|
1601
1711
|
SDKProvider,
|
|
1602
1712
|
SDKStudioContext,
|
|
1603
1713
|
SanityApp,
|
|
1714
|
+
SanityInstanceProvider,
|
|
1604
1715
|
renderSanityApp,
|
|
1605
1716
|
useActiveReleases,
|
|
1606
1717
|
useAgentGenerate,
|