@sanity/sdk-react 2.8.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 +232 -47
- package/dist/index.js +468 -263
- package/dist/index.js.map +1 -1
- package/package.json +8 -10
- package/src/_exports/sdk-react.ts +5 -0
- package/src/components/SDKProvider.tsx +36 -8
- package/src/components/SanityApp.tsx +3 -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.test.tsx +7 -1
- package/src/context/ResourceProvider.tsx +11 -4
- package/src/context/ResourcesContext.tsx +7 -0
- package/src/context/SDKStudioContext.ts +6 -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 +8 -6
- package/src/hooks/dashboard/useDispatchIntent.ts +6 -6
- package/src/hooks/dashboard/useWindowTitle.test.ts +213 -0
- package/src/hooks/dashboard/useWindowTitle.ts +112 -0
- 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 +113 -10
- package/src/hooks/document/useApplyDocumentActions.ts +99 -3
- package/src/hooks/document/useDocument.ts +22 -6
- package/src/hooks/document/useDocumentEvent.test.tsx +3 -3
- package/src/hooks/document/useDocumentEvent.ts +10 -3
- package/src/hooks/document/useDocumentPermissions.test.tsx +86 -2
- package/src/hooks/document/useDocumentPermissions.ts +22 -0
- package/src/hooks/document/useDocumentSyncStatus.test.ts +13 -2
- package/src/hooks/document/useDocumentSyncStatus.ts +14 -5
- package/src/hooks/document/useEditDocument.ts +34 -8
- package/src/hooks/documents/useDocuments.ts +11 -6
- package/src/hooks/helpers/useNormalizedResourceOptions.ts +131 -0
- package/src/hooks/helpers/useTrackHookUsage.ts +37 -0
- package/src/hooks/paginatedDocuments/usePaginatedDocuments.ts +11 -8
- package/src/hooks/presence/usePresence.test.tsx +56 -9
- package/src/hooks/presence/usePresence.ts +25 -4
- package/src/hooks/preview/useDocumentPreview.test.tsx +84 -193
- package/src/hooks/preview/useDocumentPreview.tsx +40 -55
- package/src/hooks/projection/useDocumentProjection.ts +8 -6
- package/src/hooks/query/useQuery.ts +12 -9
- package/src/hooks/releases/useActiveReleases.ts +32 -13
- package/src/hooks/releases/usePerspective.ts +26 -14
- package/src/hooks/users/useUser.ts +2 -0
- package/src/hooks/users/useUsers.ts +2 -0
- package/src/context/SourcesContext.tsx +0 -7
- package/src/hooks/helpers/useNormalizedSourceOptions.ts +0 -85
package/dist/index.js
CHANGED
|
@@ -1,14 +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, Suspense, StrictMode, useCallback,
|
|
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
|
+
import { initTelemetry, trackHookMounted } from "@sanity/sdk/_internal";
|
|
10
11
|
import { createRoot } from "react-dom/client";
|
|
11
|
-
import { pick } from "lodash-es";
|
|
12
12
|
const SanityInstanceContext = createContext(null), useSanityInstance = (config) => {
|
|
13
13
|
const $ = c(3), instance = useContext(SanityInstanceContext);
|
|
14
14
|
if (!instance)
|
|
@@ -66,7 +66,7 @@ function useWindowConnection(t0) {
|
|
|
66
66
|
const [type, handler] = t42, messageUnsubscribe = node.on(type, handler);
|
|
67
67
|
messageUnsubscribe && messageUnsubscribers.current.push(messageUnsubscribe);
|
|
68
68
|
}), () => {
|
|
69
|
-
messageUnsubscribers.current.forEach(_temp$
|
|
69
|
+
messageUnsubscribers.current.forEach(_temp$9), messageUnsubscribers.current = [];
|
|
70
70
|
}), $[4] = node, $[5] = onMessage, $[6] = t3) : t3 = $[6];
|
|
71
71
|
let t4;
|
|
72
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);
|
|
@@ -84,7 +84,7 @@ function useWindowConnection(t0) {
|
|
|
84
84
|
fetch
|
|
85
85
|
}, $[16] = fetch, $[17] = sendMessage, $[18] = t7) : t7 = $[18], t7;
|
|
86
86
|
}
|
|
87
|
-
function _temp$
|
|
87
|
+
function _temp$9(unsubscribe) {
|
|
88
88
|
return unsubscribe();
|
|
89
89
|
}
|
|
90
90
|
const DEFAULT_RESPONSE_TIMEOUT = 1e4;
|
|
@@ -114,7 +114,7 @@ function DashboardTokenRefresh(t0) {
|
|
|
114
114
|
if (clearRefreshTimeout(), res.token) {
|
|
115
115
|
setAuthToken(instance, res.token);
|
|
116
116
|
const errorContainer = document.getElementById("__sanityError");
|
|
117
|
-
errorContainer && Array.from(errorContainer.getElementsByTagName("div")).some(_temp$
|
|
117
|
+
errorContainer && Array.from(errorContainer.getElementsByTagName("div")).some(_temp$8) && errorContainer.remove();
|
|
118
118
|
}
|
|
119
119
|
isTokenRefreshInProgress.current = !1;
|
|
120
120
|
} catch {
|
|
@@ -135,7 +135,7 @@ function DashboardTokenRefresh(t0) {
|
|
|
135
135
|
let t7;
|
|
136
136
|
return $[11] !== authState || $[12] !== requestNewToken ? (t7 = [authState, requestNewToken], $[11] = authState, $[12] = requestNewToken, $[13] = t7) : t7 = $[13], useEffect(t6, t7), children;
|
|
137
137
|
}
|
|
138
|
-
function _temp$
|
|
138
|
+
function _temp$8(div) {
|
|
139
139
|
return div.textContent?.includes("Uncaught error: Unauthorized - A valid session is required for this endpoint");
|
|
140
140
|
}
|
|
141
141
|
const ComlinkTokenRefreshProvider = (t0) => {
|
|
@@ -162,20 +162,41 @@ function useLoginUrl() {
|
|
|
162
162
|
return useSyncExternalStore(subscribe, getCurrent);
|
|
163
163
|
}
|
|
164
164
|
function useVerifyOrgProjects(t0, projectIds) {
|
|
165
|
-
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));
|
|
166
167
|
let t1, t2;
|
|
167
|
-
return $[0] !==
|
|
168
|
-
if (
|
|
169
|
-
error !== null && setError(null);
|
|
168
|
+
return $[0] !== instance || $[1] !== isInactive || $[2] !== projectIds ? (t1 = () => {
|
|
169
|
+
if (isInactive)
|
|
170
170
|
return;
|
|
171
|
-
}
|
|
172
171
|
const subscription = observeOrganizationVerificationState(instance, projectIds).subscribe((result) => {
|
|
173
172
|
setError(result.error);
|
|
174
173
|
});
|
|
175
174
|
return () => {
|
|
176
175
|
subscription.unsubscribe();
|
|
177
176
|
};
|
|
178
|
-
}, 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
|
+
}
|
|
179
200
|
}
|
|
180
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 = {
|
|
181
202
|
container: {
|
|
@@ -232,6 +253,31 @@ function Error$1(t0) {
|
|
|
232
253
|
t4
|
|
233
254
|
] }), $[8] = t1, $[9] = t2, $[10] = t3, $[11] = t4, $[12] = t5) : t5 = $[12], t5;
|
|
234
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
|
+
}
|
|
235
281
|
function CorsErrorComponent(t0) {
|
|
236
282
|
const $ = c(6), {
|
|
237
283
|
projectId,
|
|
@@ -297,60 +343,93 @@ function _temp$6(replacementLocation) {
|
|
|
297
343
|
replacementLocation && history.replaceState(null, "", replacementLocation);
|
|
298
344
|
}
|
|
299
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
|
+
}
|
|
300
366
|
function LoginError(t0) {
|
|
301
|
-
const $ = c(
|
|
367
|
+
const $ = c(30), {
|
|
302
368
|
error,
|
|
303
369
|
resetErrorBoundary
|
|
304
370
|
} = t0;
|
|
305
371
|
if (!(error instanceof AuthError || error instanceof ConfigurationError || error instanceof ClientError))
|
|
306
372
|
throw error;
|
|
307
|
-
const logout2 = useLogOut(), authState = useAuthState(), {
|
|
373
|
+
const logout2 = useLogOut(), authState = useAuthState(), instance = useSanityInstance(), {
|
|
308
374
|
config: t1
|
|
309
|
-
} =
|
|
375
|
+
} = instance, {
|
|
310
376
|
projectId
|
|
311
|
-
} = t1,
|
|
377
|
+
} = t1, clientError = error instanceof ClientError ? error : error instanceof AuthError && error.cause instanceof ClientError ? error.cause : null;
|
|
312
378
|
let t2;
|
|
313
|
-
$[0]
|
|
314
|
-
|
|
315
|
-
connectTo: SDK_CHANNEL_NAME
|
|
316
|
-
}, $[0] = t2) : t2 = $[0];
|
|
317
|
-
const {
|
|
318
|
-
fetch
|
|
319
|
-
} = useWindowConnection(t2);
|
|
379
|
+
$[0] !== instance ? (t2 = getIsInDashboardState(instance).getCurrent(), $[0] = instance, $[1] = t2) : t2 = $[1];
|
|
380
|
+
const isInDashboard = t2;
|
|
320
381
|
let t3;
|
|
321
|
-
$[
|
|
322
|
-
|
|
323
|
-
}, $[1] = logout2, $[2] = resetErrorBoundary, $[3] = t3) : t3 = $[3];
|
|
324
|
-
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;
|
|
325
384
|
let t4;
|
|
326
|
-
$[4] !==
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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;
|
|
341
402
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
let
|
|
345
|
-
$[
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
$[
|
|
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 ? {
|
|
349
423
|
text: "Retry",
|
|
350
424
|
onClick: handleRetry
|
|
351
|
-
} : void 0, $[
|
|
352
|
-
let
|
|
353
|
-
|
|
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;
|
|
354
433
|
}
|
|
355
434
|
if (isInIframe() && !document.querySelector("[data-sanity-core]")) {
|
|
356
435
|
const parsedUrl = new URL(window.location.href), mode = new URLSearchParams(parsedUrl.hash.slice(1)).get("mode"), script = document.createElement("script");
|
|
@@ -366,7 +445,7 @@ function AuthBoundary(t0) {
|
|
|
366
445
|
const LoginErrorComponent = t1 === void 0 ? LoginError : t1;
|
|
367
446
|
let t2, t3;
|
|
368
447
|
$[3] !== LoginErrorComponent ? (t3 = function(fallbackProps) {
|
|
369
|
-
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 });
|
|
370
449
|
}, $[3] = LoginErrorComponent, $[4] = t3) : t3 = $[4], t2 = t3;
|
|
371
450
|
const FallbackComponent = t2;
|
|
372
451
|
let t4;
|
|
@@ -412,37 +491,48 @@ function AuthSwitch(t0) {
|
|
|
412
491
|
}
|
|
413
492
|
const SDKStudioContext = createContext(null);
|
|
414
493
|
SDKStudioContext.displayName = "SDKStudioContext";
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
let children, config, fallback;
|
|
419
|
-
$[0] !== t0 ? ({
|
|
420
|
-
children,
|
|
494
|
+
function SanityInstanceProvider(t0) {
|
|
495
|
+
const $ = c(6), {
|
|
496
|
+
instance,
|
|
421
497
|
fallback,
|
|
422
|
-
|
|
423
|
-
} = t0
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
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
|
+
}
|
|
505
|
+
const DEFAULT_FALLBACK = /* @__PURE__ */ jsx(Fragment, { children: "Warning: No fallback provided. Please supply a fallback prop to ensure proper Suspense handling." });
|
|
506
|
+
function ResourceProvider({
|
|
507
|
+
children,
|
|
508
|
+
fallback,
|
|
509
|
+
...config
|
|
510
|
+
}) {
|
|
511
|
+
const parent = useContext(SanityInstanceContext), instance = useMemo(() => parent ? parent.createChild(config) : createSanityInstance(config), [config, parent]), projectId = config.projectId ?? "";
|
|
512
|
+
useMemo(() => {
|
|
513
|
+
projectId && !parent && initTelemetry(instance, projectId);
|
|
514
|
+
}, [instance, projectId, parent]);
|
|
515
|
+
const disposal = useRef(null);
|
|
516
|
+
return useEffect(() => (disposal.current !== null && instance === disposal.current.instance && (clearTimeout(disposal.current.timeoutId), disposal.current = null), () => {
|
|
430
517
|
disposal.current = {
|
|
431
518
|
instance,
|
|
432
519
|
timeoutId: setTimeout(() => {
|
|
433
520
|
instance.isDisposed() || instance.dispose();
|
|
434
521
|
}, 0)
|
|
435
522
|
};
|
|
436
|
-
}),
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
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();
|
|
442
533
|
}
|
|
443
|
-
const SourcesContext = createContext({});
|
|
444
534
|
function SDKProvider(t0) {
|
|
445
|
-
const $ = c(
|
|
535
|
+
const $ = c(20);
|
|
446
536
|
let children, config, fallback, props;
|
|
447
537
|
$[0] !== t0 ? ({
|
|
448
538
|
children,
|
|
@@ -453,31 +543,44 @@ function SDKProvider(t0) {
|
|
|
453
543
|
let t1;
|
|
454
544
|
$[5] !== config ? (t1 = Array.isArray(config) ? config : [config], $[5] = config, $[6] = t1) : t1 = $[6];
|
|
455
545
|
let configs, t2;
|
|
456
|
-
$[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]);
|
|
457
547
|
const projectIds = t2;
|
|
458
548
|
let t3, t4;
|
|
459
|
-
$[10] !== props.
|
|
460
|
-
const
|
|
549
|
+
$[10] !== props.resources ? (t4 = props.resources ?? {}, $[10] = props.resources, $[11] = t4) : t4 = $[11], t3 = t4;
|
|
550
|
+
const resourcesValue = t3;
|
|
461
551
|
let t5;
|
|
462
|
-
if ($[12] !== children || $[13] !== configs || $[14] !== fallback || $[15] !== projectIds || $[16] !== props || $[17] !==
|
|
463
|
-
const createNestedProviders = (index) => index >= configs.length ? /* @__PURE__ */ jsx(AuthBoundary, { ...props, projectIds, children: /* @__PURE__ */ jsx(
|
|
464
|
-
|
|
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;
|
|
465
559
|
} else
|
|
466
560
|
t5 = $[18];
|
|
467
561
|
return t5;
|
|
468
562
|
}
|
|
469
|
-
function
|
|
563
|
+
function _temp3$1(id) {
|
|
470
564
|
return !!id;
|
|
471
565
|
}
|
|
472
|
-
function
|
|
566
|
+
function _temp2$1(c2) {
|
|
473
567
|
return c2.projectId;
|
|
474
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
|
+
}
|
|
475
577
|
const REDIRECT_URL = "https://sanity.io/welcome";
|
|
476
578
|
function deriveConfigFromWorkspace(workspace) {
|
|
477
579
|
return {
|
|
478
580
|
projectId: workspace.projectId,
|
|
479
581
|
dataset: workspace.dataset,
|
|
480
582
|
studio: {
|
|
583
|
+
authenticated: workspace.authenticated,
|
|
481
584
|
auth: workspace.auth.token ? {
|
|
482
585
|
token: workspace.auth.token
|
|
483
586
|
} : void 0
|
|
@@ -664,33 +767,39 @@ function useDashboardNavigate(navigateFn) {
|
|
|
664
767
|
}
|
|
665
768
|
}, $[0] = navigateFn, $[1] = t0) : t0 = $[1], useWindowConnection(t0);
|
|
666
769
|
}
|
|
667
|
-
function
|
|
668
|
-
const
|
|
669
|
-
|
|
670
|
-
if ($[0] !== options ? ({
|
|
770
|
+
function normalizeResourceOptions(options, resources) {
|
|
771
|
+
const {
|
|
772
|
+
resourceName,
|
|
671
773
|
sourceName,
|
|
774
|
+
source,
|
|
672
775
|
...rest
|
|
673
|
-
} = options,
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
if (
|
|
678
|
-
throw new Error(`
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
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]), {
|
|
682
786
|
...rest,
|
|
683
|
-
|
|
684
|
-
}
|
|
787
|
+
resource: resolvedResource
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
function useNormalizedResourceOptions(options) {
|
|
791
|
+
const $ = c(3), resources = useContext(ResourcesContext);
|
|
792
|
+
let t0;
|
|
793
|
+
return $[0] !== options || $[1] !== resources ? (t0 = normalizeResourceOptions(options, resources), $[0] = options, $[1] = resources, $[2] = t0) : t0 = $[2], t0;
|
|
685
794
|
}
|
|
686
795
|
function useResourceIdFromDocumentHandle(documentHandle) {
|
|
687
|
-
const $ = c(3), options =
|
|
796
|
+
const $ = c(3), options = useNormalizedResourceOptions(documentHandle), {
|
|
688
797
|
projectId,
|
|
689
798
|
dataset,
|
|
690
|
-
|
|
799
|
+
resource
|
|
691
800
|
} = options;
|
|
692
801
|
let resourceId = "", resourceType;
|
|
693
|
-
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"));
|
|
694
803
|
let t0;
|
|
695
804
|
return $[0] !== resourceId || $[1] !== resourceType ? (t0 = {
|
|
696
805
|
id: resourceId,
|
|
@@ -715,7 +824,7 @@ function useDispatchIntent(params) {
|
|
|
715
824
|
if (!action && !intentId)
|
|
716
825
|
throw new Error("useDispatchIntent: Either `action` or `intentId` must be provided.");
|
|
717
826
|
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 `
|
|
827
|
+
throw new Error("useDispatchIntent: Unable to determine resource. Either `resource`, `resourceName`, or both `projectId` and `dataset` must be provided in documentHandle.");
|
|
719
828
|
const message = {
|
|
720
829
|
type: "dashboard/v1/events/intents/dispatch-intent",
|
|
721
830
|
data: {
|
|
@@ -951,6 +1060,50 @@ function useRecordDocumentHistoryEvent(t0) {
|
|
|
951
1060
|
recordEvent
|
|
952
1061
|
}, $[8] = recordEvent, $[9] = t3) : t3 = $[9], t3;
|
|
953
1062
|
}
|
|
1063
|
+
function resolveAppTitle(resource) {
|
|
1064
|
+
return resource.manifest?.title ?? resource.activeDeployment?.manifest?.title ?? resource.title;
|
|
1065
|
+
}
|
|
1066
|
+
function useWindowTitle(viewTitle) {
|
|
1067
|
+
const $ = c(8), [appTitle, setAppTitle] = useState(null);
|
|
1068
|
+
let t0;
|
|
1069
|
+
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = {
|
|
1070
|
+
name: SDK_NODE_NAME,
|
|
1071
|
+
connectTo: SDK_CHANNEL_NAME
|
|
1072
|
+
}, $[0] = t0) : t0 = $[0];
|
|
1073
|
+
const {
|
|
1074
|
+
fetch
|
|
1075
|
+
} = useWindowConnection(t0);
|
|
1076
|
+
let t1, t2;
|
|
1077
|
+
$[1] !== fetch ? (t1 = () => {
|
|
1078
|
+
if (!fetch)
|
|
1079
|
+
return;
|
|
1080
|
+
const controller = new AbortController();
|
|
1081
|
+
return (async function(signal) {
|
|
1082
|
+
try {
|
|
1083
|
+
const data = await fetch("dashboard/v1/context", void 0, {
|
|
1084
|
+
signal
|
|
1085
|
+
}), title = resolveAppTitle(data.context.resource);
|
|
1086
|
+
title && setAppTitle(title);
|
|
1087
|
+
} catch (t32) {
|
|
1088
|
+
const err = t32;
|
|
1089
|
+
if (err instanceof Error && err.name === "AbortError")
|
|
1090
|
+
return;
|
|
1091
|
+
console.error("Failed to fetch app title from dashboard context:", err);
|
|
1092
|
+
}
|
|
1093
|
+
})(controller.signal), () => {
|
|
1094
|
+
controller.abort();
|
|
1095
|
+
};
|
|
1096
|
+
}, t2 = [fetch], $[1] = fetch, $[2] = t1, $[3] = t2) : (t1 = $[2], t2 = $[3]), useEffect(t1, t2);
|
|
1097
|
+
let t3, t4;
|
|
1098
|
+
$[4] !== appTitle || $[5] !== viewTitle ? (t3 = () => {
|
|
1099
|
+
if (!appTitle)
|
|
1100
|
+
return;
|
|
1101
|
+
const previous = document.title;
|
|
1102
|
+
return document.title = viewTitle ? `${viewTitle} | ${appTitle}` : appTitle, () => {
|
|
1103
|
+
document.title = previous;
|
|
1104
|
+
};
|
|
1105
|
+
}, t4 = [viewTitle, appTitle], $[4] = appTitle, $[5] = viewTitle, $[6] = t3, $[7] = t4) : (t3 = $[6], t4 = $[7]), useEffect(t3, t4);
|
|
1106
|
+
}
|
|
954
1107
|
const useDatasets = createStateSourceHook({
|
|
955
1108
|
getState: getDatasetsState,
|
|
956
1109
|
shouldSuspend: (instance, projectHandle) => (
|
|
@@ -960,18 +1113,27 @@ const useDatasets = createStateSourceHook({
|
|
|
960
1113
|
suspender: resolveDatasets,
|
|
961
1114
|
getConfig: identity
|
|
962
1115
|
}), useApplyDocumentActions = () => {
|
|
963
|
-
const $ = c(
|
|
1116
|
+
const $ = c(3), instance = useSanityInstance(), resources = useContext(ResourcesContext);
|
|
964
1117
|
let t0;
|
|
965
|
-
return $[0] !== instance ? (t0 = (actionOrActions, options) => {
|
|
966
|
-
const actions = Array.isArray(actionOrActions) ? actionOrActions : [actionOrActions];
|
|
967
|
-
let projectId, dataset;
|
|
968
|
-
for (const action of actions)
|
|
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;
|
|
1121
|
+
for (const action of actions) {
|
|
969
1122
|
if (action.projectId) {
|
|
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}".`);
|
|
970
1125
|
if (projectId || (projectId = action.projectId), action.projectId !== projectId)
|
|
971
1126
|
throw new Error(`Mismatched project IDs found in actions. All actions must belong to the same project. Found "${action.projectId}" but expected "${projectId}".`);
|
|
972
1127
|
if (action.dataset && (dataset || (dataset = action.dataset), action.dataset !== dataset))
|
|
973
1128
|
throw new Error(`Mismatched datasets found in actions. All actions must belong to the same dataset. Found "${action.dataset}" but expected "${dataset}".`);
|
|
974
1129
|
}
|
|
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}".`);
|
|
1133
|
+
if (projectId || dataset)
|
|
1134
|
+
throw new Error(`Mismatches between projectId/dataset options and resource in actions. Found "${action.resource}" but expected project "${projectId}" and dataset "${dataset}".`);
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
975
1137
|
if (projectId || dataset) {
|
|
976
1138
|
const actualInstance = instance.match({
|
|
977
1139
|
projectId,
|
|
@@ -985,15 +1147,25 @@ const useDatasets = createStateSourceHook({
|
|
|
985
1147
|
Please ensure there is a ResourceProvider component with a matching configuration in the component hierarchy.`);
|
|
986
1148
|
return applyDocumentActions(actualInstance, {
|
|
987
1149
|
actions,
|
|
988
|
-
|
|
1150
|
+
resource,
|
|
1151
|
+
...normalizedOptions
|
|
989
1152
|
});
|
|
990
1153
|
}
|
|
991
1154
|
return applyDocumentActions(instance, {
|
|
992
1155
|
actions,
|
|
993
|
-
|
|
1156
|
+
resource,
|
|
1157
|
+
...normalizedOptions
|
|
994
1158
|
});
|
|
995
|
-
}, $[0] = instance, $[1] = t0) : t0 = $[
|
|
996
|
-
}
|
|
1159
|
+
}, $[0] = instance, $[1] = resources, $[2] = t0) : t0 = $[2], t0;
|
|
1160
|
+
};
|
|
1161
|
+
function useTrackHookUsage(hookName) {
|
|
1162
|
+
const instance = useSanityInstance(), tracked = useRef(null);
|
|
1163
|
+
tracked.current === null && (tracked.current = !0, trackHookMounted(instance, hookName));
|
|
1164
|
+
}
|
|
1165
|
+
function trackHookUsage(instance, hookName) {
|
|
1166
|
+
trackHookMounted(instance, hookName);
|
|
1167
|
+
}
|
|
1168
|
+
const useDocumentValue = createStateSourceHook({
|
|
997
1169
|
// Pass options directly to getDocumentState
|
|
998
1170
|
getState: (instance, options) => getDocumentState(instance, options),
|
|
999
1171
|
// Pass options directly to getDocumentState for checking current value
|
|
@@ -1011,14 +1183,20 @@ const useDatasets = createStateSourceHook({
|
|
|
1011
1183
|
};
|
|
1012
1184
|
}
|
|
1013
1185
|
return useHook;
|
|
1014
|
-
}, useDocument = wrapHookWithData(
|
|
1186
|
+
}, useDocument = wrapHookWithData((options) => {
|
|
1187
|
+
useTrackHookUsage("useDocument");
|
|
1188
|
+
const normalizedOptions = useNormalizedResourceOptions(options);
|
|
1189
|
+
return useDocumentValue(normalizedOptions);
|
|
1190
|
+
});
|
|
1015
1191
|
function useDocumentEvent(options) {
|
|
1016
|
-
const $ = c(
|
|
1192
|
+
const $ = c(10);
|
|
1193
|
+
useTrackHookUsage("useDocumentEvent");
|
|
1194
|
+
const normalizedOptions = useNormalizedResourceOptions(options);
|
|
1017
1195
|
let datasetHandle, onEvent;
|
|
1018
|
-
$[0] !==
|
|
1196
|
+
$[0] !== normalizedOptions ? ({
|
|
1019
1197
|
onEvent,
|
|
1020
1198
|
...datasetHandle
|
|
1021
|
-
} =
|
|
1199
|
+
} = normalizedOptions, $[0] = normalizedOptions, $[1] = datasetHandle, $[2] = onEvent) : (datasetHandle = $[1], onEvent = $[2]);
|
|
1022
1200
|
const ref = useRef(onEvent);
|
|
1023
1201
|
let t0;
|
|
1024
1202
|
$[3] !== onEvent ? (t0 = () => {
|
|
@@ -1028,41 +1206,53 @@ function useDocumentEvent(options) {
|
|
|
1028
1206
|
$[5] === Symbol.for("react.memo_cache_sentinel") ? (t1 = (documentEvent) => ref.current(documentEvent), $[5] = t1) : t1 = $[5];
|
|
1029
1207
|
const stableHandler = t1, instance = useSanityInstance(datasetHandle);
|
|
1030
1208
|
let t2, t3;
|
|
1031
|
-
$[6] !==
|
|
1209
|
+
$[6] !== datasetHandle.resource || $[7] !== instance ? (t2 = () => subscribeDocumentEvents(instance, {
|
|
1210
|
+
eventHandler: stableHandler,
|
|
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);
|
|
1032
1213
|
}
|
|
1033
1214
|
function useDocumentPermissions(actionOrActions) {
|
|
1034
|
-
const $ = c(
|
|
1215
|
+
const $ = c(15);
|
|
1035
1216
|
let t0, t1;
|
|
1036
1217
|
$[0] !== actionOrActions ? (t1 = Array.isArray(actionOrActions) ? actionOrActions : [actionOrActions], $[0] = actionOrActions, $[1] = t1) : t1 = $[1], t0 = t1;
|
|
1037
1218
|
const actions = t0;
|
|
1038
|
-
let projectId, dataset;
|
|
1039
|
-
if ($[2] !== actions || $[3] !== dataset || $[4] !== projectId) {
|
|
1040
|
-
for (const action of actions)
|
|
1219
|
+
let projectId, dataset, resource;
|
|
1220
|
+
if ($[2] !== actions || $[3] !== dataset || $[4] !== projectId || $[5] !== resource) {
|
|
1221
|
+
for (const action of actions) {
|
|
1041
1222
|
if (action.projectId) {
|
|
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}".`);
|
|
1042
1225
|
if (projectId || (projectId = action.projectId), action.projectId !== projectId)
|
|
1043
1226
|
throw new Error(`Mismatched project IDs found in actions. All actions must belong to the same project. Found "${action.projectId}" but expected "${projectId}".`);
|
|
1044
1227
|
if (action.dataset && (dataset || (dataset = action.dataset), action.dataset !== dataset))
|
|
1045
1228
|
throw new Error(`Mismatched datasets found in actions. All actions must belong to the same dataset. Found "${action.dataset}" but expected "${dataset}".`);
|
|
1046
1229
|
}
|
|
1047
|
-
|
|
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}".`);
|
|
1233
|
+
if (projectId || dataset)
|
|
1234
|
+
throw new Error(`Mismatches between projectId/dataset options and resource in actions. Found "${action.resource}" but expected project "${projectId}" and dataset "${dataset}".`);
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
$[2] = actions, $[3] = dataset, $[4] = projectId, $[5] = resource, $[6] = projectId, $[7] = dataset, $[8] = resource;
|
|
1048
1238
|
} else
|
|
1049
|
-
projectId = $[
|
|
1239
|
+
projectId = $[6], dataset = $[7], resource = $[8];
|
|
1050
1240
|
let t2;
|
|
1051
|
-
$[
|
|
1241
|
+
$[9] !== dataset || $[10] !== projectId ? (t2 = {
|
|
1052
1242
|
projectId,
|
|
1053
1243
|
dataset
|
|
1054
|
-
}, $[
|
|
1244
|
+
}, $[9] = dataset, $[10] = projectId, $[11] = t2) : t2 = $[11];
|
|
1055
1245
|
const instance = useSanityInstance(t2);
|
|
1056
|
-
if (getPermissionsState(instance, {
|
|
1246
|
+
if (trackHookUsage(instance, "useDocumentPermissions"), getPermissionsState(instance, {
|
|
1057
1247
|
actions
|
|
1058
1248
|
}).getCurrent() === void 0)
|
|
1059
1249
|
throw firstValueFrom(getPermissionsState(instance, {
|
|
1060
1250
|
actions
|
|
1061
1251
|
}).observable.pipe(filter(_temp$2)));
|
|
1062
1252
|
let t3, t4;
|
|
1063
|
-
$[
|
|
1253
|
+
$[12] !== actions || $[13] !== instance ? (t4 = getPermissionsState(instance, {
|
|
1064
1254
|
actions
|
|
1065
|
-
}), $[
|
|
1255
|
+
}), $[12] = actions, $[13] = instance, $[14] = t4) : t4 = $[14], t3 = t4;
|
|
1066
1256
|
const {
|
|
1067
1257
|
subscribe,
|
|
1068
1258
|
getCurrent
|
|
@@ -1072,12 +1262,15 @@ function useDocumentPermissions(actionOrActions) {
|
|
|
1072
1262
|
function _temp$2(result) {
|
|
1073
1263
|
return result !== void 0;
|
|
1074
1264
|
}
|
|
1075
|
-
const
|
|
1265
|
+
const useDocumentSyncStatusValue = createStateSourceHook({
|
|
1076
1266
|
getState: getDocumentSyncStatus,
|
|
1077
1267
|
shouldSuspend: (instance, doc) => getDocumentSyncStatus(instance, doc).getCurrent() === void 0,
|
|
1078
1268
|
suspender: (instance, doc) => resolveDocument(instance, doc),
|
|
1079
1269
|
getConfig: identity
|
|
1080
|
-
}),
|
|
1270
|
+
}), useDocumentSyncStatus = (options) => {
|
|
1271
|
+
const normalizedOptions = useNormalizedResourceOptions(options);
|
|
1272
|
+
return useDocumentSyncStatusValue(normalizedOptions);
|
|
1273
|
+
}, ignoredKeys = ["_id", "_type", "_createdAt", "_updatedAt", "_rev"];
|
|
1081
1274
|
function useEditDocument(t0) {
|
|
1082
1275
|
const $ = c(8);
|
|
1083
1276
|
let doc, path;
|
|
@@ -1085,25 +1278,27 @@ function useEditDocument(t0) {
|
|
|
1085
1278
|
path,
|
|
1086
1279
|
...doc
|
|
1087
1280
|
} = t0, $[0] = t0, $[1] = doc, $[2] = path) : (doc = $[1], path = $[2]);
|
|
1088
|
-
const instance = useSanityInstance(doc)
|
|
1089
|
-
|
|
1090
|
-
|
|
1281
|
+
const instance = useSanityInstance(doc);
|
|
1282
|
+
trackHookUsage(instance, "useEditDocument");
|
|
1283
|
+
const normalizedDoc = useNormalizedResourceOptions(doc), apply = useApplyDocumentActions();
|
|
1284
|
+
if (getDocumentState(instance, normalizedDoc).getCurrent() === void 0)
|
|
1285
|
+
throw resolveDocument(instance, normalizedDoc);
|
|
1091
1286
|
let t1;
|
|
1092
|
-
return $[3] !== apply || $[4] !==
|
|
1287
|
+
return $[3] !== apply || $[4] !== instance || $[5] !== normalizedDoc || $[6] !== path ? (t1 = (updater) => {
|
|
1093
1288
|
const currentPath = path;
|
|
1094
1289
|
if (currentPath) {
|
|
1095
1290
|
const currentValue = getDocumentState(instance, {
|
|
1096
|
-
...
|
|
1291
|
+
...normalizedDoc,
|
|
1097
1292
|
path
|
|
1098
1293
|
}).getCurrent(), nextValue = typeof updater == "function" ? updater(currentValue) : updater;
|
|
1099
|
-
return apply(editDocument(
|
|
1294
|
+
return apply(editDocument(normalizedDoc, {
|
|
1100
1295
|
set: {
|
|
1101
1296
|
[currentPath]: nextValue
|
|
1102
1297
|
}
|
|
1103
1298
|
}));
|
|
1104
1299
|
}
|
|
1105
1300
|
const current = getDocumentState(instance, {
|
|
1106
|
-
...
|
|
1301
|
+
...normalizedDoc,
|
|
1107
1302
|
path
|
|
1108
1303
|
}).getCurrent(), nextValue_0 = typeof updater == "function" ? updater(current) : updater;
|
|
1109
1304
|
if (typeof nextValue_0 != "object" || !nextValue_0)
|
|
@@ -1111,21 +1306,23 @@ function useEditDocument(t0) {
|
|
|
1111
1306
|
const editActions = Object.keys({
|
|
1112
1307
|
...current,
|
|
1113
1308
|
...nextValue_0
|
|
1114
|
-
}).filter(_temp$1).filter((key_0) => current?.[key_0] !== nextValue_0[key_0]).map((key_1) => key_1 in nextValue_0 ? editDocument(
|
|
1309
|
+
}).filter(_temp$1).filter((key_0) => current?.[key_0] !== nextValue_0[key_0]).map((key_1) => key_1 in nextValue_0 ? editDocument(normalizedDoc, {
|
|
1115
1310
|
set: {
|
|
1116
1311
|
[key_1]: nextValue_0[key_1]
|
|
1117
1312
|
}
|
|
1118
|
-
}) : editDocument(
|
|
1313
|
+
}) : editDocument(normalizedDoc, {
|
|
1119
1314
|
unset: [key_1]
|
|
1120
1315
|
}));
|
|
1121
1316
|
return apply(editActions);
|
|
1122
|
-
}, $[3] = apply, $[4] =
|
|
1317
|
+
}, $[3] = apply, $[4] = instance, $[5] = normalizedDoc, $[6] = path, $[7] = t1) : t1 = $[7], t1;
|
|
1123
1318
|
}
|
|
1124
1319
|
function _temp$1(key) {
|
|
1125
1320
|
return !ignoredKeys.includes(key);
|
|
1126
1321
|
}
|
|
1127
1322
|
function useQuery(options) {
|
|
1128
|
-
const instance = useSanityInstance(options)
|
|
1323
|
+
const instance = useSanityInstance(options);
|
|
1324
|
+
trackHookUsage(instance, "useQuery");
|
|
1325
|
+
const normalized = useNormalizedResourceOptions(options), [isPending, startTransition] = useTransition(), queryKey = getQueryKey(normalized), [deferredQueryKey, setDeferredQueryKey] = useState(queryKey), ref = useRef(new AbortController());
|
|
1129
1326
|
useEffect(() => {
|
|
1130
1327
|
queryKey !== deferredQueryKey && startTransition(() => {
|
|
1131
1328
|
ref && !ref.current.signal.aborted && (ref.current.abort(), ref.current = new AbortController()), setDeferredQueryKey(queryKey);
|
|
@@ -1161,6 +1358,7 @@ function useDocuments({
|
|
|
1161
1358
|
documentType,
|
|
1162
1359
|
...options
|
|
1163
1360
|
}) {
|
|
1361
|
+
useTrackHookUsage("useDocuments");
|
|
1164
1362
|
const instance = useSanityInstance(options), [limit, setLimit] = useState(batchSize), documentTypes = useMemo(() => (Array.isArray(documentType) ? documentType : [documentType]).filter((i) => typeof i == "string"), [documentType]), key = JSON.stringify({
|
|
1165
1363
|
filter: filter2,
|
|
1166
1364
|
search,
|
|
@@ -1169,10 +1367,8 @@ function useDocuments({
|
|
|
1169
1367
|
batchSize,
|
|
1170
1368
|
types: documentTypes,
|
|
1171
1369
|
...options
|
|
1172
|
-
});
|
|
1173
|
-
|
|
1174
|
-
setLimit(batchSize);
|
|
1175
|
-
}, [key, batchSize]);
|
|
1370
|
+
}), [prevKey, setPrevKey] = useState(key);
|
|
1371
|
+
prevKey !== key && (setPrevKey(key), setLimit(batchSize));
|
|
1176
1372
|
const filterClause = useMemo(() => {
|
|
1177
1373
|
const conditions = [], trimmedSearch = search?.trim();
|
|
1178
1374
|
if (trimmedSearch) {
|
|
@@ -1191,9 +1387,11 @@ function useDocuments({
|
|
|
1191
1387
|
query: `{"count":${countQuery},"data":${dataQuery}}`,
|
|
1192
1388
|
params: {
|
|
1193
1389
|
...params,
|
|
1390
|
+
// these are passed back to the user as part of each document handle
|
|
1194
1391
|
__handle: {
|
|
1195
|
-
|
|
1196
|
-
|
|
1392
|
+
projectId: options.projectId ?? instance.config.projectId,
|
|
1393
|
+
dataset: options.dataset ?? instance.config.dataset,
|
|
1394
|
+
perspective: options.perspective ?? instance.config.perspective
|
|
1197
1395
|
},
|
|
1198
1396
|
__types: documentTypes
|
|
1199
1397
|
}
|
|
@@ -1209,7 +1407,7 @@ function useDocuments({
|
|
|
1209
1407
|
}), [count, data, hasMore, isPending, loadMore]);
|
|
1210
1408
|
}
|
|
1211
1409
|
function usePaginatedDocuments(t0) {
|
|
1212
|
-
const $ = c(
|
|
1410
|
+
const $ = c(56);
|
|
1213
1411
|
let documentType, options, orderings, search, t1, t2, t3;
|
|
1214
1412
|
$[0] !== t0 ? ({
|
|
1215
1413
|
documentType,
|
|
@@ -1223,7 +1421,9 @@ function usePaginatedDocuments(t0) {
|
|
|
1223
1421
|
const filter2 = t1 === void 0 ? "" : t1, pageSize = t2 === void 0 ? 25 : t2;
|
|
1224
1422
|
let t4;
|
|
1225
1423
|
$[8] !== t3 ? (t4 = t3 === void 0 ? {} : t3, $[8] = t3, $[9] = t4) : t4 = $[9];
|
|
1226
|
-
const params = t4
|
|
1424
|
+
const params = t4;
|
|
1425
|
+
useTrackHookUsage("usePaginatedDocuments");
|
|
1426
|
+
const instance = useSanityInstance(options), [pageIndex, setPageIndex] = useState(0);
|
|
1227
1427
|
let t5;
|
|
1228
1428
|
$[10] !== filter2 || $[11] !== orderings || $[12] !== pageSize || $[13] !== params || $[14] !== search ? (t5 = JSON.stringify({
|
|
1229
1429
|
filter: filter2,
|
|
@@ -1232,74 +1432,66 @@ function usePaginatedDocuments(t0) {
|
|
|
1232
1432
|
orderings,
|
|
1233
1433
|
pageSize
|
|
1234
1434
|
}), $[10] = filter2, $[11] = orderings, $[12] = pageSize, $[13] = params, $[14] = search, $[15] = t5) : t5 = $[15];
|
|
1235
|
-
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;
|
|
1236
1438
|
let t6;
|
|
1237
|
-
$[16]
|
|
1238
|
-
setPageIndex(0);
|
|
1239
|
-
}, $[16] = t6) : t6 = $[16];
|
|
1439
|
+
$[16] !== documentType ? (t6 = Array.isArray(documentType) ? documentType : [documentType], $[16] = documentType, $[17] = t6) : t6 = $[17];
|
|
1240
1440
|
let t7;
|
|
1241
|
-
$[
|
|
1242
|
-
const
|
|
1441
|
+
$[18] !== t6 ? (t7 = t6.filter(_temp), $[18] = t6, $[19] = t7) : t7 = $[19];
|
|
1442
|
+
const documentTypes = t7;
|
|
1243
1443
|
let t8;
|
|
1244
|
-
$[19] !== documentType ? (t8 = Array.isArray(documentType) ? documentType : [documentType], $[19] = documentType, $[20] = t8) : t8 = $[20];
|
|
1245
|
-
let t9;
|
|
1246
|
-
$[21] !== t8 ? (t9 = t8.filter(_temp), $[21] = t8, $[22] = t9) : t9 = $[22];
|
|
1247
|
-
const documentTypes = t9;
|
|
1248
|
-
let t10;
|
|
1249
1444
|
const conditions = [], trimmedSearch = search?.trim();
|
|
1250
1445
|
if (trimmedSearch) {
|
|
1251
1446
|
const searchFilter = createGroqSearchFilter(trimmedSearch);
|
|
1252
1447
|
searchFilter && conditions.push(searchFilter);
|
|
1253
1448
|
}
|
|
1254
|
-
documentTypes?.length && conditions.push("(_type in $__types)"), filter2 && conditions.push(`(${filter2})`),
|
|
1255
|
-
const filterClause =
|
|
1256
|
-
let t12;
|
|
1257
|
-
$[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;
|
|
1258
1451
|
let t13;
|
|
1259
|
-
$[
|
|
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];
|
|
1260
1457
|
let t14;
|
|
1261
|
-
$[
|
|
1262
|
-
...t12,
|
|
1263
|
-
...t13
|
|
1264
|
-
}, $[27] = t12, $[28] = t13, $[29] = t14) : t14 = $[29];
|
|
1265
|
-
let t15;
|
|
1266
|
-
$[30] !== documentTypes || $[31] !== params || $[32] !== t14 ? (t15 = {
|
|
1458
|
+
$[24] !== documentTypes || $[25] !== params || $[26] !== t13 ? (t14 = {
|
|
1267
1459
|
...params,
|
|
1268
1460
|
__types: documentTypes,
|
|
1269
|
-
__handle:
|
|
1270
|
-
}, $[
|
|
1271
|
-
let
|
|
1272
|
-
$[
|
|
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 = {
|
|
1273
1465
|
...options,
|
|
1274
|
-
query:
|
|
1275
|
-
params:
|
|
1276
|
-
}, $[
|
|
1466
|
+
query: t9,
|
|
1467
|
+
params: t14
|
|
1468
|
+
}, $[28] = options, $[29] = t14, $[30] = t9, $[31] = t15) : t15 = $[31];
|
|
1277
1469
|
const {
|
|
1278
|
-
data:
|
|
1470
|
+
data: t16,
|
|
1279
1471
|
isPending
|
|
1280
|
-
} = useQuery(
|
|
1472
|
+
} = useQuery(t15), {
|
|
1281
1473
|
data,
|
|
1282
1474
|
count
|
|
1283
|
-
} =
|
|
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;
|
|
1284
1479
|
let t18;
|
|
1285
|
-
$[
|
|
1286
|
-
const
|
|
1480
|
+
$[33] === Symbol.for("react.memo_cache_sentinel") ? (t18 = () => setPageIndex(_temp4), $[33] = t18) : t18 = $[33];
|
|
1481
|
+
const previousPage = t18;
|
|
1287
1482
|
let t19;
|
|
1288
|
-
$[
|
|
1289
|
-
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;
|
|
1290
1485
|
let t20;
|
|
1291
|
-
$[
|
|
1292
|
-
const
|
|
1486
|
+
$[36] !== totalPages ? (t20 = () => setPageIndex(totalPages - 1), $[36] = totalPages, $[37] = t20) : t20 = $[37];
|
|
1487
|
+
const lastPage = t20;
|
|
1293
1488
|
let t21;
|
|
1294
|
-
$[
|
|
1295
|
-
const lastPage = t21;
|
|
1296
|
-
let t22;
|
|
1297
|
-
$[44] !== totalPages ? (t22 = (pageNumber) => {
|
|
1489
|
+
$[38] !== totalPages ? (t21 = (pageNumber) => {
|
|
1298
1490
|
pageNumber < 1 || pageNumber > totalPages || setPageIndex(pageNumber - 1);
|
|
1299
|
-
}, $[
|
|
1300
|
-
const goToPage =
|
|
1301
|
-
let
|
|
1302
|
-
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 = {
|
|
1303
1495
|
data,
|
|
1304
1496
|
isPending,
|
|
1305
1497
|
pageSize,
|
|
@@ -1317,7 +1509,7 @@ function usePaginatedDocuments(t0) {
|
|
|
1317
1509
|
lastPage,
|
|
1318
1510
|
hasLastPage,
|
|
1319
1511
|
goToPage
|
|
1320
|
-
}, $[
|
|
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;
|
|
1321
1513
|
}
|
|
1322
1514
|
function _temp4(prev) {
|
|
1323
1515
|
return Math.max(prev - 1, 0);
|
|
@@ -1331,70 +1523,39 @@ function _temp2(str) {
|
|
|
1331
1523
|
function _temp(i) {
|
|
1332
1524
|
return typeof i == "string";
|
|
1333
1525
|
}
|
|
1334
|
-
function usePresence() {
|
|
1335
|
-
const $ = c(
|
|
1336
|
-
let t0, t1;
|
|
1337
|
-
$[0] !== sanityInstance ? (t1 = getPresence(sanityInstance), $[0] = sanityInstance, $[1] = t1) : t1 = $[1], t0 = t1;
|
|
1338
|
-
const source = t0;
|
|
1339
|
-
let t2;
|
|
1340
|
-
$[2] !== source ? (t2 = (callback) => source.subscribe(callback), $[2] = source, $[3] = t2) : t2 = $[3];
|
|
1341
|
-
const subscribe = t2;
|
|
1342
|
-
let t3, t4;
|
|
1343
|
-
$[4] !== source ? (t3 = () => source.getCurrent(), t4 = () => source.getCurrent(), $[4] = source, $[5] = t3, $[6] = t4) : (t3 = $[5], t4 = $[6]);
|
|
1344
|
-
const locations = useSyncExternalStore(subscribe, t3, t4);
|
|
1345
|
-
let t5;
|
|
1346
|
-
$[7] !== locations ? (t5 = locations || [], $[7] = locations, $[8] = t5) : t5 = $[8];
|
|
1347
|
-
let t6;
|
|
1348
|
-
return $[9] !== t5 ? (t6 = {
|
|
1349
|
-
locations: t5
|
|
1350
|
-
}, $[9] = t5, $[10] = t6) : t6 = $[10], t6;
|
|
1351
|
-
}
|
|
1352
|
-
function useDocumentPreview(t0) {
|
|
1353
|
-
const $ = c(13);
|
|
1354
|
-
let docHandle, ref;
|
|
1355
|
-
$[0] !== t0 ? ({
|
|
1356
|
-
ref,
|
|
1357
|
-
...docHandle
|
|
1358
|
-
} = t0, $[0] = t0, $[1] = docHandle, $[2] = ref) : (docHandle = $[1], ref = $[2]);
|
|
1359
|
-
const instance = useSanityInstance(docHandle);
|
|
1526
|
+
function usePresence(t0) {
|
|
1527
|
+
const $ = c(14);
|
|
1360
1528
|
let t1;
|
|
1361
|
-
$[
|
|
1362
|
-
const
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
}, $[6] = ref, $[7] = stateSource, $[8] = t2) : t2 = $[8];
|
|
1383
|
-
const subscribe = t2;
|
|
1384
|
-
let t3;
|
|
1385
|
-
return $[9] !== docHandle || $[10] !== instance || $[11] !== stateSource ? (t3 = () => {
|
|
1386
|
-
const currentState = stateSource.getCurrent();
|
|
1387
|
-
if (currentState.data === null)
|
|
1388
|
-
throw resolvePreview(instance, docHandle);
|
|
1389
|
-
return currentState;
|
|
1390
|
-
}, $[9] = docHandle, $[10] = instance, $[11] = stateSource, $[12] = t3) : t3 = $[12], useSyncExternalStore(subscribe, t3);
|
|
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();
|
|
1534
|
+
trackHookUsage(sanityInstance, "usePresence");
|
|
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;
|
|
1391
1550
|
}
|
|
1392
1551
|
function useDocumentProjection({
|
|
1393
1552
|
ref,
|
|
1394
1553
|
projection,
|
|
1395
1554
|
...docHandle
|
|
1396
1555
|
}) {
|
|
1397
|
-
const instance = useSanityInstance(docHandle)
|
|
1556
|
+
const instance = useSanityInstance(docHandle);
|
|
1557
|
+
trackHookUsage(instance, "useDocumentProjection");
|
|
1558
|
+
const normalizedProjection = useMemo(() => projection.trim(), [projection]), normalizedDocHandle = useNormalizedResourceOptions(docHandle), stateSource = useMemo(() => getProjectionState(instance, {
|
|
1398
1559
|
...normalizedDocHandle,
|
|
1399
1560
|
projection: normalizedProjection
|
|
1400
1561
|
}), [instance, normalizedDocHandle, normalizedProjection]);
|
|
@@ -1421,6 +1582,32 @@ function useDocumentProjection({
|
|
|
1421
1582
|
}, [stateSource, ref]);
|
|
1422
1583
|
return useSyncExternalStore(subscribe, stateSource.getCurrent);
|
|
1423
1584
|
}
|
|
1585
|
+
function useDocumentPreview(t0) {
|
|
1586
|
+
const $ = c(13);
|
|
1587
|
+
let docHandle, ref;
|
|
1588
|
+
$[0] !== t0 ? ({
|
|
1589
|
+
ref,
|
|
1590
|
+
...docHandle
|
|
1591
|
+
} = t0, $[0] = t0, $[1] = docHandle, $[2] = ref) : (docHandle = $[1], ref = $[2]);
|
|
1592
|
+
const instance = useSanityInstance(docHandle);
|
|
1593
|
+
trackHookUsage(instance, "useDocumentPreview");
|
|
1594
|
+
const normalizedDocHandle = useNormalizedResourceOptions(docHandle);
|
|
1595
|
+
let t1;
|
|
1596
|
+
$[3] !== normalizedDocHandle || $[4] !== ref ? (t1 = {
|
|
1597
|
+
...normalizedDocHandle,
|
|
1598
|
+
projection: PREVIEW_PROJECTION,
|
|
1599
|
+
ref
|
|
1600
|
+
}, $[3] = normalizedDocHandle, $[4] = ref, $[5] = t1) : t1 = $[5];
|
|
1601
|
+
const projectionResult = useDocumentProjection(t1);
|
|
1602
|
+
let t2, t3;
|
|
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;
|
|
1604
|
+
const previewValue = t2;
|
|
1605
|
+
let t4;
|
|
1606
|
+
return $[10] !== previewValue || $[11] !== projectionResult.isPending ? (t4 = {
|
|
1607
|
+
data: previewValue,
|
|
1608
|
+
isPending: projectionResult.isPending
|
|
1609
|
+
}, $[10] = previewValue, $[11] = projectionResult.isPending, $[12] = t4) : t4 = $[12], t4;
|
|
1610
|
+
}
|
|
1424
1611
|
const useProject = createStateSourceHook({
|
|
1425
1612
|
// remove `undefined` since we're suspending when that is the case
|
|
1426
1613
|
getState: getProjectState,
|
|
@@ -1431,17 +1618,31 @@ const useProject = createStateSourceHook({
|
|
|
1431
1618
|
getState: getProjectsState,
|
|
1432
1619
|
shouldSuspend: (instance, options) => getProjectsState(instance, options).getCurrent() === void 0,
|
|
1433
1620
|
suspender: resolveProjects
|
|
1434
|
-
}),
|
|
1621
|
+
}), useActiveReleasesValue = createStateSourceHook({
|
|
1435
1622
|
getState: getActiveReleasesState,
|
|
1436
|
-
shouldSuspend: (instance) => getActiveReleasesState(instance).getCurrent() === void 0,
|
|
1437
|
-
suspender: (instance) => firstValueFrom(getActiveReleasesState(instance).observable.pipe(filter(Boolean)))
|
|
1438
|
-
}),
|
|
1623
|
+
shouldSuspend: (instance, options) => getActiveReleasesState(instance, options ?? {}).getCurrent() === void 0,
|
|
1624
|
+
suspender: (instance, options) => firstValueFrom(getActiveReleasesState(instance, options ?? {}).observable.pipe(filter(Boolean)))
|
|
1625
|
+
}), useActiveReleases = (options) => {
|
|
1626
|
+
const $ = c(2);
|
|
1627
|
+
let t0;
|
|
1628
|
+
$[0] !== options ? (t0 = options ?? {}, $[0] = options, $[1] = t0) : t0 = $[1];
|
|
1629
|
+
const normalizedOptions = useNormalizedResourceOptions(t0);
|
|
1630
|
+
return useActiveReleasesValue(normalizedOptions);
|
|
1631
|
+
}, usePerspectiveValue = createStateSourceHook({
|
|
1439
1632
|
getState: getPerspectiveState,
|
|
1440
1633
|
shouldSuspend: (instance, options) => getPerspectiveState(instance, options).getCurrent() === void 0,
|
|
1441
|
-
suspender: (instance, _options) => firstValueFrom(
|
|
1442
|
-
})
|
|
1634
|
+
suspender: (instance, _options) => firstValueFrom(getPerspectiveState(instance, _options ?? {}).observable.pipe(filter(Boolean)))
|
|
1635
|
+
}), usePerspective = (options) => {
|
|
1636
|
+
const $ = c(2);
|
|
1637
|
+
let t0;
|
|
1638
|
+
$[0] !== options ? (t0 = options ?? {}, $[0] = options, $[1] = t0) : t0 = $[1];
|
|
1639
|
+
const normalizedOptions = useNormalizedResourceOptions(t0);
|
|
1640
|
+
return usePerspectiveValue(normalizedOptions);
|
|
1641
|
+
};
|
|
1443
1642
|
function useUser(options) {
|
|
1444
|
-
const instance = useSanityInstance(options)
|
|
1643
|
+
const instance = useSanityInstance(options);
|
|
1644
|
+
trackHookUsage(instance, "useUser");
|
|
1645
|
+
const [isPending, startTransition] = useTransition(), key = getUsersKey(instance, options), [deferredKey, setDeferredKey] = useState(key), deferred = useMemo(() => parseUsersKey(deferredKey), [deferredKey]), [ref, setRef] = useState(new AbortController());
|
|
1445
1646
|
useEffect(() => {
|
|
1446
1647
|
key !== deferredKey && startTransition(() => {
|
|
1447
1648
|
ref.signal.aborted || (ref.abort(), setRef(new AbortController())), setDeferredKey(key);
|
|
@@ -1462,7 +1663,9 @@ function useUser(options) {
|
|
|
1462
1663
|
};
|
|
1463
1664
|
}
|
|
1464
1665
|
function useUsers(options) {
|
|
1465
|
-
const instance = useSanityInstance(options)
|
|
1666
|
+
const instance = useSanityInstance(options);
|
|
1667
|
+
trackHookUsage(instance, "useUsers");
|
|
1668
|
+
const [isPending, startTransition] = useTransition(), key = getUsersKey(instance, options), [deferredKey, setDeferredKey] = useState(key), deferred = useMemo(() => parseUsersKey(deferredKey), [deferredKey]), [ref, setRef] = useState(new AbortController());
|
|
1466
1669
|
useEffect(() => {
|
|
1467
1670
|
key !== deferredKey && startTransition(() => {
|
|
1468
1671
|
ref.signal.aborted || (ref.abort(), setRef(new AbortController())), setDeferredKey(key);
|
|
@@ -1490,7 +1693,7 @@ function useUsers(options) {
|
|
|
1490
1693
|
loadMore
|
|
1491
1694
|
};
|
|
1492
1695
|
}
|
|
1493
|
-
var version = "2.
|
|
1696
|
+
var version = "2.10.0";
|
|
1494
1697
|
function getEnv(key) {
|
|
1495
1698
|
if (typeof import.meta < "u" && import.meta.env)
|
|
1496
1699
|
return import.meta.env[key];
|
|
@@ -1508,6 +1711,7 @@ export {
|
|
|
1508
1711
|
SDKProvider,
|
|
1509
1712
|
SDKStudioContext,
|
|
1510
1713
|
SanityApp,
|
|
1714
|
+
SanityInstanceProvider,
|
|
1511
1715
|
renderSanityApp,
|
|
1512
1716
|
useActiveReleases,
|
|
1513
1717
|
useAgentGenerate,
|
|
@@ -1551,6 +1755,7 @@ export {
|
|
|
1551
1755
|
useUser,
|
|
1552
1756
|
useUsers,
|
|
1553
1757
|
useVerifyOrgProjects,
|
|
1554
|
-
useWindowConnection
|
|
1758
|
+
useWindowConnection,
|
|
1759
|
+
useWindowTitle
|
|
1555
1760
|
};
|
|
1556
1761
|
//# sourceMappingURL=index.js.map
|