@sanity/sdk-react 0.0.0-rc.6 → 0.0.0-rc.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +5 -57
  2. package/dist/index.d.ts +998 -437
  3. package/dist/index.js +324 -258
  4. package/dist/index.js.map +1 -1
  5. package/package.json +16 -15
  6. package/src/_exports/sdk-react.ts +4 -1
  7. package/src/components/SDKProvider.tsx +6 -1
  8. package/src/components/SanityApp.test.tsx +29 -47
  9. package/src/components/SanityApp.tsx +12 -11
  10. package/src/components/auth/AuthBoundary.test.tsx +177 -7
  11. package/src/components/auth/AuthBoundary.tsx +31 -1
  12. package/src/components/auth/ConfigurationError.ts +22 -0
  13. package/src/components/auth/LoginError.tsx +9 -3
  14. package/src/hooks/auth/useVerifyOrgProjects.test.tsx +136 -0
  15. package/src/hooks/auth/useVerifyOrgProjects.tsx +48 -0
  16. package/src/hooks/client/useClient.ts +3 -3
  17. package/src/hooks/comlink/useManageFavorite.test.ts +276 -27
  18. package/src/hooks/comlink/useManageFavorite.ts +102 -51
  19. package/src/hooks/comlink/useWindowConnection.ts +3 -2
  20. package/src/hooks/document/useApplyDocumentActions.ts +105 -31
  21. package/src/hooks/document/useDocument.test.ts +41 -4
  22. package/src/hooks/document/useDocument.ts +198 -114
  23. package/src/hooks/document/useDocumentEvent.test.ts +5 -5
  24. package/src/hooks/document/useDocumentEvent.ts +67 -23
  25. package/src/hooks/document/useDocumentPermissions.ts +47 -8
  26. package/src/hooks/document/useDocumentSyncStatus.test.ts +12 -5
  27. package/src/hooks/document/useDocumentSyncStatus.ts +41 -14
  28. package/src/hooks/document/useEditDocument.test.ts +24 -6
  29. package/src/hooks/document/useEditDocument.ts +238 -133
  30. package/src/hooks/documents/useDocuments.test.tsx +1 -1
  31. package/src/hooks/documents/useDocuments.ts +153 -44
  32. package/src/hooks/paginatedDocuments/usePaginatedDocuments.test.tsx +1 -1
  33. package/src/hooks/paginatedDocuments/usePaginatedDocuments.ts +120 -47
  34. package/src/hooks/projection/useProjection.ts +134 -46
  35. package/src/hooks/query/useQuery.test.tsx +4 -4
  36. package/src/hooks/query/useQuery.ts +115 -43
  37. package/src/hooks/releases/useActiveReleases.test.tsx +84 -0
  38. package/src/hooks/releases/useActiveReleases.ts +39 -0
  39. package/src/hooks/releases/usePerspective.test.tsx +120 -0
  40. package/src/hooks/releases/usePerspective.ts +49 -0
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
2
  import { c } from "react-compiler-runtime";
3
- import { getAuthState, getLoginUrlState, handleAuthCallback, logout, AuthStateType, createSanityInstance, getTokenState, getCurrentUserState, getDashboardOrganizationId, getClientState, getOrCreateController, getOrCreateChannel, releaseChannel, getOrCreateNode, releaseNode, resolveDatasets, getDatasetsState, applyDocumentActions, resolveDocument, getDocumentState, subscribeDocumentEvents, getPermissionsState, getDocumentSyncStatus, editDocument, getQueryKey, parseQueryKey, getQueryState, resolveQuery, createGroqSearchFilter, getPreviewState, resolvePreview, getProjectionState, resolveProjection, resolveProject, getProjectState, resolveProjects, getProjectsState, getUsersKey, parseUsersKey, getUsersState, resolveUsers, loadMoreUsers } from "@sanity/sdk";
3
+ import { getAuthState, getLoginUrlState, observeOrganizationVerificationState, handleAuthCallback, logout, AuthStateType, createSanityInstance, getTokenState, getCurrentUserState, getDashboardOrganizationId, getClientState, getOrCreateController, getOrCreateChannel, releaseChannel, getOrCreateNode, releaseNode, getFavoritesState, resolveFavoritesState, resolveDatasets, getDatasetsState, applyDocumentActions, resolveDocument, getDocumentState, subscribeDocumentEvents, getPermissionsState, getDocumentSyncStatus, editDocument, getQueryKey, parseQueryKey, getQueryState, resolveQuery, createGroqSearchFilter, getPreviewState, resolvePreview, getProjectionState, resolveProjection, resolveProject, getProjectState, resolveProjects, getProjectsState, getActiveReleasesState, getPerspectiveState, getUsersKey, parseUsersKey, getUsersState, resolveUsers, loadMoreUsers } from "@sanity/sdk";
4
4
  export * from "@sanity/sdk";
5
- import { createContext, useContext, useSyncExternalStore, useEffect, useState, useRef, Suspense, useInsertionEffect, useTransition, useMemo, useCallback } from "react";
5
+ import { createContext, useContext, useSyncExternalStore, useState, useEffect, useRef, Suspense, useMemo, useCallback, useInsertionEffect, useTransition } from "react";
6
6
  import { ErrorBoundary } from "react-error-boundary";
7
7
  import { ClientError } from "@sanity/client";
8
8
  import { identity, firstValueFrom, filter, Observable, startWith, distinctUntilChanged, switchMap, EMPTY } from "rxjs";
@@ -49,6 +49,22 @@ function useLoginUrl() {
49
49
  } = t0;
50
50
  return useSyncExternalStore(subscribe, getCurrent);
51
51
  }
52
+ function useVerifyOrgProjects(t0, projectIds) {
53
+ const $ = c(6), disabled = t0 === void 0 ? !1 : t0, instance = useSanityInstance(), [error, setError] = useState(null);
54
+ let t1, t2;
55
+ return $[0] !== disabled || $[1] !== error || $[2] !== instance || $[3] !== projectIds ? (t1 = () => {
56
+ if (disabled || !projectIds || projectIds.length === 0) {
57
+ error !== null && setError(null);
58
+ return;
59
+ }
60
+ const subscription = observeOrganizationVerificationState(instance, projectIds).subscribe((result) => {
61
+ setError(result.error);
62
+ });
63
+ return () => {
64
+ subscription.unsubscribe();
65
+ };
66
+ }, t2 = [instance, disabled, error, projectIds], $[0] = disabled, $[1] = error, $[2] = instance, $[3] = projectIds, $[4] = t1, $[5] = t2) : (t1 = $[4], t2 = $[5]), useEffect(t1, t2), error;
67
+ }
52
68
  function isInIframe() {
53
69
  return typeof window < "u" && window.self !== window.top;
54
70
  }
@@ -61,6 +77,11 @@ class AuthError extends Error {
61
77
  typeof error == "object" && error && "message" in error && typeof error.message == "string" ? super(error.message) : super(), this.cause = error;
62
78
  }
63
79
  }
80
+ class ConfigurationError extends Error {
81
+ constructor(error) {
82
+ typeof error == "object" && error && "message" in error && typeof error.message == "string" ? super(error.message) : super(), this.cause = error;
83
+ }
84
+ }
64
85
  function createCallbackHook(callback) {
65
86
  function useHook() {
66
87
  const $ = c(2), instance = useSanityInstance();
@@ -75,19 +96,19 @@ function LoginCallback() {
75
96
  let t0, t1;
76
97
  return $[0] !== handleAuthCallback2 ? (t0 = () => {
77
98
  const url = new URL(location.href);
78
- handleAuthCallback2(url.toString()).then(_temp$7);
99
+ handleAuthCallback2(url.toString()).then(_temp$6);
79
100
  }, t1 = [handleAuthCallback2], $[0] = handleAuthCallback2, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), useEffect(t0, t1), null;
80
101
  }
81
- function _temp$7(replacementLocation) {
102
+ function _temp$6(replacementLocation) {
82
103
  replacementLocation && history.replaceState(null, "", replacementLocation);
83
104
  }
84
105
  const useLogOut = createCallbackHook(logout);
85
106
  function LoginError(t0) {
86
- const $ = c(18), {
107
+ const $ = c(24), {
87
108
  error,
88
109
  resetErrorBoundary
89
110
  } = t0;
90
- if (!(error instanceof AuthError))
111
+ if (!(error instanceof AuthError || error instanceof ConfigurationError))
91
112
  throw error;
92
113
  const logout2 = useLogOut(), authState = useAuthState(), [authErrorMessage, setAuthErrorMessage] = useState("Please try again or contact support if the problem persists.");
93
114
  let t1;
@@ -96,7 +117,7 @@ function LoginError(t0) {
96
117
  }, $[0] = logout2, $[1] = resetErrorBoundary, $[2] = t1) : t1 = $[2];
97
118
  const handleRetry = t1;
98
119
  let t2;
99
- $[3] !== authState.error || $[4] !== authState.type || $[5] !== handleRetry ? (t2 = () => {
120
+ $[3] !== authState.error || $[4] !== authState.type || $[5] !== error || $[6] !== handleRetry ? (t2 = () => {
100
121
  if (authState.type === AuthStateType.ERROR && authState.error instanceof ClientError) {
101
122
  if (authState.error.statusCode === 401)
102
123
  handleRetry();
@@ -105,23 +126,27 @@ function LoginError(t0) {
105
126
  errorMessage.startsWith("Session with sid") && errorMessage.endsWith("not found") ? setAuthErrorMessage("The session ID is invalid or expired.") : setAuthErrorMessage("The login link is invalid or expired. Please try again.");
106
127
  }
107
128
  }
108
- }, $[3] = authState.error, $[4] = authState.type, $[5] = handleRetry, $[6] = t2) : t2 = $[6];
129
+ authState.type !== AuthStateType.ERROR && error instanceof ConfigurationError && setAuthErrorMessage(error.message);
130
+ }, $[3] = authState.error, $[4] = authState.type, $[5] = error, $[6] = handleRetry, $[7] = t2) : t2 = $[7];
109
131
  let t3;
110
- $[7] !== authState || $[8] !== handleRetry ? (t3 = [authState, handleRetry], $[7] = authState, $[8] = handleRetry, $[9] = t3) : t3 = $[9], useEffect(t2, t3);
111
- let t4;
112
- $[10] === Symbol.for("react.memo_cache_sentinel") ? (t4 = /* @__PURE__ */ jsx("h2", { className: "sc-login-error__title", children: "Authentication Error" }), $[10] = t4) : t4 = $[10];
132
+ $[8] !== authState || $[9] !== error || $[10] !== handleRetry ? (t3 = [authState, handleRetry, error], $[8] = authState, $[9] = error, $[10] = handleRetry, $[11] = t3) : t3 = $[11], useEffect(t2, t3);
133
+ const t4 = error instanceof AuthError ? "Authentication Error" : "Configuration Error";
113
134
  let t5;
114
- $[11] !== authErrorMessage ? (t5 = /* @__PURE__ */ jsxs("div", { className: "sc-login-error__content", children: [
115
- t4,
116
- /* @__PURE__ */ jsx("p", { className: "sc-login-error__description", children: authErrorMessage })
117
- ] }), $[11] = authErrorMessage, $[12] = t5) : t5 = $[12];
135
+ $[12] !== t4 ? (t5 = /* @__PURE__ */ jsx("h2", { className: "sc-login-error__title", children: t4 }), $[12] = t4, $[13] = t5) : t5 = $[13];
118
136
  let t6;
119
- $[13] !== handleRetry ? (t6 = /* @__PURE__ */ jsx("button", { className: "sc-login-error__button", onClick: handleRetry, children: "Retry" }), $[13] = handleRetry, $[14] = t6) : t6 = $[14];
137
+ $[14] !== authErrorMessage ? (t6 = /* @__PURE__ */ jsx("p", { className: "sc-login-error__description", children: authErrorMessage }), $[14] = authErrorMessage, $[15] = t6) : t6 = $[15];
120
138
  let t7;
121
- return $[15] !== t5 || $[16] !== t6 ? (t7 = /* @__PURE__ */ jsxs("div", { className: "sc-login-error", children: [
139
+ $[16] !== t5 || $[17] !== t6 ? (t7 = /* @__PURE__ */ jsxs("div", { className: "sc-login-error__content", children: [
122
140
  t5,
123
141
  t6
124
- ] }), $[15] = t5, $[16] = t6, $[17] = t7) : t7 = $[17], t7;
142
+ ] }), $[16] = t5, $[17] = t6, $[18] = t7) : t7 = $[18];
143
+ let t8;
144
+ $[19] !== handleRetry ? (t8 = /* @__PURE__ */ jsx("button", { className: "sc-login-error__button", onClick: handleRetry, children: "Retry" }), $[19] = handleRetry, $[20] = t8) : t8 = $[20];
145
+ let t9;
146
+ return $[21] !== t7 || $[22] !== t8 ? (t9 = /* @__PURE__ */ jsxs("div", { className: "sc-login-error", children: [
147
+ t7,
148
+ t8
149
+ ] }), $[21] = t7, $[22] = t8, $[23] = t9) : t9 = $[23], t9;
125
150
  }
126
151
  if (isInIframe() && !document.querySelector("[data-sanity-core]")) {
127
152
  const parsedUrl = new URL(window.location.href), mode = new URLSearchParams(parsedUrl.hash.slice(1)).get("mode"), script = document.createElement("script");
@@ -146,23 +171,29 @@ function AuthBoundary(t0) {
146
171
  return $[7] !== FallbackComponent || $[8] !== t4 ? (t5 = /* @__PURE__ */ jsx(ErrorBoundary, { FallbackComponent, children: t4 }), $[7] = FallbackComponent, $[8] = t4, $[9] = t5) : t5 = $[9], t5;
147
172
  }
148
173
  function AuthSwitch(t0) {
149
- const $ = c(11);
150
- let children, props, t1;
174
+ const $ = c(13);
175
+ let children, projectIds, props, t1, t2;
151
176
  $[0] !== t0 ? ({
152
177
  CallbackComponent: t1,
153
178
  children,
179
+ verifyOrganization: t2,
180
+ projectIds,
154
181
  ...props
155
- } = t0, $[0] = t0, $[1] = children, $[2] = props, $[3] = t1) : (children = $[1], props = $[2], t1 = $[3]);
156
- const CallbackComponent = t1 === void 0 ? LoginCallback : t1, authState = useAuthState(), isLoggedOut = authState.type === AuthStateType.LOGGED_OUT && !authState.isDestroyingSession, loginUrl = useLoginUrl();
157
- let t2, t3;
158
- switch ($[4] !== isLoggedOut || $[5] !== loginUrl ? (t2 = () => {
182
+ } = t0, $[0] = t0, $[1] = children, $[2] = projectIds, $[3] = props, $[4] = t1, $[5] = t2) : (children = $[1], projectIds = $[2], props = $[3], t1 = $[4], t2 = $[5]);
183
+ const CallbackComponent = t1 === void 0 ? LoginCallback : t1, verifyOrganization = t2 === void 0 ? !0 : t2, authState = useAuthState(), orgError = useVerifyOrgProjects(!verifyOrganization, projectIds), isLoggedOut = authState.type === AuthStateType.LOGGED_OUT && !authState.isDestroyingSession, loginUrl = useLoginUrl();
184
+ let t3, t4;
185
+ if ($[6] !== isLoggedOut || $[7] !== loginUrl ? (t3 = () => {
159
186
  isLoggedOut && !isInIframe() && (window.location.href = loginUrl);
160
- }, t3 = [isLoggedOut, loginUrl], $[4] = isLoggedOut, $[5] = loginUrl, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]), useEffect(t2, t3), authState.type) {
187
+ }, t4 = [isLoggedOut, loginUrl], $[6] = isLoggedOut, $[7] = loginUrl, $[8] = t3, $[9] = t4) : (t3 = $[8], t4 = $[9]), useEffect(t3, t4), verifyOrganization && orgError)
188
+ throw new ConfigurationError({
189
+ message: orgError
190
+ });
191
+ switch (authState.type) {
161
192
  case AuthStateType.ERROR:
162
193
  throw new AuthError(authState.error);
163
194
  case AuthStateType.LOGGING_IN: {
164
- let t4;
165
- return $[8] !== CallbackComponent || $[9] !== props ? (t4 = /* @__PURE__ */ jsx(CallbackComponent, { ...props }), $[8] = CallbackComponent, $[9] = props, $[10] = t4) : t4 = $[10], t4;
195
+ let t5;
196
+ return $[10] !== CallbackComponent || $[11] !== props ? (t5 = /* @__PURE__ */ jsx(CallbackComponent, { ...props }), $[10] = CallbackComponent, $[11] = props, $[12] = t5) : t5 = $[12], t5;
166
197
  }
167
198
  case AuthStateType.LOGGED_IN:
168
199
  return children;
@@ -206,33 +237,32 @@ function SDKProvider({
206
237
  fallback,
207
238
  ...props
208
239
  }) {
209
- const configs = (Array.isArray(config) ? config : [config]).slice().reverse(), createNestedProviders = (index) => index >= configs.length ? /* @__PURE__ */ jsx(AuthBoundary, { ...props, children }) : /* @__PURE__ */ jsx(ResourceProvider, { ...configs[index], fallback, children: createNestedProviders(index + 1) });
240
+ const configs = (Array.isArray(config) ? config : [config]).slice().reverse(), projectIds = configs.map((c2) => c2.projectId).filter((id) => !!id), createNestedProviders = (index) => index >= configs.length ? /* @__PURE__ */ jsx(AuthBoundary, { ...props, projectIds, children }) : /* @__PURE__ */ jsx(ResourceProvider, { ...configs[index], fallback, children: createNestedProviders(index + 1) });
210
241
  return createNestedProviders(0);
211
242
  }
212
243
  const REDIRECT_URL = "https://sanity.io/welcome";
213
244
  function SanityApp(t0) {
214
- const $ = c(15);
215
- let children, config, fallback, props, sanityConfigs;
245
+ const $ = c(13);
246
+ let children, fallback, props, t1;
216
247
  $[0] !== t0 ? ({
217
248
  children,
218
249
  fallback,
219
- config,
220
- sanityConfigs,
250
+ config: t1,
221
251
  ...props
222
- } = t0, $[0] = t0, $[1] = children, $[2] = config, $[3] = fallback, $[4] = props, $[5] = sanityConfigs) : (children = $[1], config = $[2], fallback = $[3], props = $[4], sanityConfigs = $[5]);
223
- let t1;
224
- $[6] !== config || $[7] !== sanityConfigs ? (t1 = config ?? sanityConfigs ?? [], $[6] = config, $[7] = sanityConfigs, $[8] = t1) : t1 = $[8];
225
- const configs = t1;
252
+ } = t0, $[0] = t0, $[1] = children, $[2] = fallback, $[3] = props, $[4] = t1) : (children = $[1], fallback = $[2], props = $[3], t1 = $[4]);
226
253
  let t2;
227
- $[9] === Symbol.for("react.memo_cache_sentinel") ? (t2 = [], $[9] = t2) : t2 = $[9], useEffect(_temp2$2, t2);
254
+ $[5] !== t1 ? (t2 = t1 === void 0 ? [] : t1, $[5] = t1, $[6] = t2) : t2 = $[6];
255
+ const config = t2;
228
256
  let t3;
229
- return $[10] !== children || $[11] !== configs || $[12] !== fallback || $[13] !== props ? (t3 = /* @__PURE__ */ jsx(SDKProvider, { ...props, fallback, config: configs, children }), $[10] = children, $[11] = configs, $[12] = fallback, $[13] = props, $[14] = t3) : t3 = $[14], t3;
257
+ $[7] === Symbol.for("react.memo_cache_sentinel") ? (t3 = [], $[7] = t3) : t3 = $[7], useEffect(_temp2$1, t3);
258
+ let t4;
259
+ return $[8] !== children || $[9] !== config || $[10] !== fallback || $[11] !== props ? (t4 = /* @__PURE__ */ jsx(SDKProvider, { ...props, fallback, config, children }), $[8] = children, $[9] = config, $[10] = fallback, $[11] = props, $[12] = t4) : t4 = $[12], t4;
230
260
  }
231
- function _temp2$2() {
261
+ function _temp2$1() {
232
262
  let timeout;
233
- return !isInIframe() && !isLocalUrl(window) && (timeout = setTimeout(_temp$6, 1e3)), () => clearTimeout(timeout);
263
+ return !isInIframe() && !isLocalUrl(window) && (timeout = setTimeout(_temp$5, 1e3)), () => clearTimeout(timeout);
234
264
  }
235
- function _temp$6() {
265
+ function _temp$5() {
236
266
  console.warn("Redirecting to core", REDIRECT_URL), window.location.replace(REDIRECT_URL);
237
267
  }
238
268
  const useAuthToken = createStateSourceHook(getTokenState), useCurrentUser = createStateSourceHook(getCurrentUserState);
@@ -274,7 +304,7 @@ function useFrameConnection(options) {
274
304
  const [type, handler] = t22, unsubscribe = channel.on(type, handler);
275
305
  messageUnsubscribers.push(unsubscribe);
276
306
  }), () => {
277
- messageUnsubscribers.forEach(_temp$5), releaseChannel(instance, name), channelRef.current = null, controllerRef.current = null;
307
+ messageUnsubscribers.forEach(_temp$4), releaseChannel(instance, name), channelRef.current = null, controllerRef.current = null;
278
308
  };
279
309
  }, t1 = [targetOrigin, name, connectTo, heartbeat, onMessage, instance, onStatus], $[0] = connectTo, $[1] = heartbeat, $[2] = instance, $[3] = name, $[4] = onMessage, $[5] = onStatus, $[6] = targetOrigin, $[7] = t0, $[8] = t1) : (t0 = $[7], t1 = $[8]), useEffect(t0, t1);
280
310
  let t2;
@@ -296,7 +326,7 @@ function useFrameConnection(options) {
296
326
  sendMessage
297
327
  }, $[11] = t4) : t4 = $[11], t4;
298
328
  }
299
- function _temp$5(unsub) {
329
+ function _temp$4(unsub) {
300
330
  return unsub();
301
331
  }
302
332
  function useWindowConnection(t0) {
@@ -323,7 +353,7 @@ function useWindowConnection(t0) {
323
353
  const [type, handler] = t42, messageUnsubscribe = node.on(type, handler);
324
354
  messageUnsubscribers.current.push(messageUnsubscribe);
325
355
  }), () => {
326
- statusUnsubscribe(), messageUnsubscribers.current.forEach(_temp$4), messageUnsubscribers.current = [], releaseNode(instance, name), nodeRef.current = null;
356
+ statusUnsubscribe(), messageUnsubscribers.current.forEach(_temp$3), messageUnsubscribers.current = [], releaseNode(instance, name), nodeRef.current = null;
327
357
  };
328
358
  }, t3 = [instance, name, connectTo, onMessage, onStatus], $[1] = connectTo, $[2] = instance, $[3] = name, $[4] = onMessage, $[5] = onStatus, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]), useEffect(t2, t3);
329
359
  let t4;
@@ -334,7 +364,11 @@ function useWindowConnection(t0) {
334
364
  }, $[8] = t4) : t4 = $[8];
335
365
  const sendMessage = t4;
336
366
  let t5;
337
- $[9] === Symbol.for("react.memo_cache_sentinel") ? (t5 = (type_1, data_0, fetchOptions) => nodeRef.current?.fetch(type_1, data_0, fetchOptions ?? {}), $[9] = t5) : t5 = $[9];
367
+ $[9] === Symbol.for("react.memo_cache_sentinel") ? (t5 = (type_1, data_0, fetchOptions) => {
368
+ if (!nodeRef.current)
369
+ throw new Error("Cannot fetch before connection is established");
370
+ return nodeRef.current?.fetch(type_1, data_0, fetchOptions ?? {});
371
+ }, $[9] = t5) : t5 = $[9];
338
372
  const fetch = t5;
339
373
  let t6;
340
374
  return $[10] === Symbol.for("react.memo_cache_sentinel") ? (t6 = {
@@ -342,83 +376,81 @@ function useWindowConnection(t0) {
342
376
  fetch
343
377
  }, $[10] = t6) : t6 = $[10], t6;
344
378
  }
345
- function _temp$4(unsubscribe) {
379
+ function _temp$3(unsubscribe) {
346
380
  return unsubscribe();
347
381
  }
348
- function useManageFavorite(t0) {
349
- const $ = c(23), {
350
- documentId,
351
- documentType,
352
- projectId: paramProjectId,
353
- dataset: paramDataset,
354
- resourceId: paramResourceId,
355
- resourceType,
356
- schemaName
357
- } = t0, [isFavorited, setIsFavorited] = useState(!1), [status, setStatus] = useState("idle"), [resourceId, setResourceId] = useState(paramResourceId || "");
358
- let t1;
359
- $[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = {
382
+ function useManageFavorite({
383
+ documentId,
384
+ documentType,
385
+ projectId: paramProjectId,
386
+ dataset: paramDataset,
387
+ resourceId: paramResourceId,
388
+ resourceType,
389
+ schemaName
390
+ }) {
391
+ const [status, setStatus] = useState("idle"), {
392
+ fetch
393
+ } = useWindowConnection({
360
394
  name: SDK_NODE_NAME,
361
395
  connectTo: SDK_CHANNEL_NAME,
362
396
  onStatus: setStatus
363
- }, $[0] = t1) : t1 = $[0];
364
- const {
365
- sendMessage
366
- } = useWindowConnection(t1), instance = useSanityInstance(), {
397
+ }), instance = useSanityInstance(), {
367
398
  config
368
399
  } = instance, instanceProjectId = config?.projectId, instanceDataset = config?.dataset, projectId = paramProjectId ?? instanceProjectId, dataset = paramDataset ?? instanceDataset;
369
400
  if (resourceType === "studio" && (!projectId || !dataset))
370
401
  throw new Error("projectId and dataset are required for studio resources");
371
- let t2, t3;
372
- $[1] !== dataset || $[2] !== paramResourceId || $[3] !== projectId || $[4] !== resourceType ? (t2 = () => {
373
- if (resourceType === "studio" && !paramResourceId)
374
- setResourceId(`${projectId}.${dataset}`);
375
- else if (paramResourceId)
376
- setResourceId(paramResourceId);
377
- else
378
- throw new Error("resourceId is required for media-library and canvas resources");
379
- }, t3 = [resourceType, paramResourceId, projectId, dataset], $[1] = dataset, $[2] = paramResourceId, $[3] = projectId, $[4] = resourceType, $[5] = t2, $[6] = t3) : (t2 = $[5], t3 = $[6]), useEffect(t2, t3);
380
- let t4;
381
- $[7] !== documentId || $[8] !== documentType || $[9] !== resourceId || $[10] !== resourceType || $[11] !== schemaName || $[12] !== sendMessage ? (t4 = (action, setFavoriteState) => {
382
- if (!(!documentId || !documentType || !resourceType))
402
+ const resourceId = resourceType === "studio" && !paramResourceId ? `${projectId}.${dataset}` : paramResourceId;
403
+ if (!resourceId)
404
+ throw new Error("resourceId is required for media-library and canvas resources");
405
+ const context = useMemo(() => ({
406
+ documentId,
407
+ documentType,
408
+ resourceId,
409
+ resourceType,
410
+ schemaName
411
+ }), [documentId, documentType, resourceId, resourceType, schemaName]), favoriteState = getFavoritesState(instance, context), state = useSyncExternalStore(favoriteState.subscribe, favoriteState.getCurrent), isFavorited = state?.isFavorited ?? !1, handleFavoriteAction = useCallback(async (action) => {
412
+ if (!(status !== "connected" || !fetch || !documentId || !documentType || !resourceType))
383
413
  try {
384
- const message = {
385
- type: "dashboard/v1/events/favorite/mutate",
386
- data: {
387
- eventType: action,
388
- document: {
389
- id: documentId,
390
- type: documentType,
391
- resource: {
392
- id: resourceId,
393
- type: resourceType,
414
+ const payload = {
415
+ eventType: action,
416
+ document: {
417
+ id: documentId,
418
+ type: documentType,
419
+ resource: {
420
+ id: resourceId,
421
+ type: resourceType,
422
+ ...schemaName ? {
394
423
  schemaName
395
- }
424
+ } : {}
396
425
  }
397
- },
398
- response: {
399
- success: !0
400
426
  }
401
427
  };
402
- sendMessage(message.type, message.data), setIsFavorited(setFavoriteState);
403
- } catch (t52) {
404
- const err = t52, error = err instanceof Error ? err : new Error("Failed to update favorite status");
405
- throw console.error(`Failed to ${action === "added" ? "favorite" : "unfavorite"} document:`, error), error;
428
+ (await fetch("dashboard/v1/events/favorite/mutate", payload)).success && await resolveFavoritesState(instance, context);
429
+ } catch (err) {
430
+ throw console.error(`Failed to ${action === "added" ? "favorite" : "unfavorite"} document:`, err), err;
406
431
  }
407
- }, $[7] = documentId, $[8] = documentType, $[9] = resourceId, $[10] = resourceType, $[11] = schemaName, $[12] = sendMessage, $[13] = t4) : t4 = $[13];
408
- const handleFavoriteAction = t4;
409
- let t5;
410
- $[14] !== handleFavoriteAction ? (t5 = () => handleFavoriteAction("added", !0), $[14] = handleFavoriteAction, $[15] = t5) : t5 = $[15];
411
- const favorite = t5;
412
- let t6;
413
- $[16] !== handleFavoriteAction ? (t6 = () => handleFavoriteAction("removed", !1), $[16] = handleFavoriteAction, $[17] = t6) : t6 = $[17];
414
- const unfavorite = t6, t7 = status === "connected";
415
- let t8;
416
- return $[18] !== favorite || $[19] !== isFavorited || $[20] !== t7 || $[21] !== unfavorite ? (t8 = {
432
+ }, [fetch, documentId, documentType, resourceId, resourceType, schemaName, instance, context, status]), favorite = useCallback(() => handleFavoriteAction("added"), [handleFavoriteAction]), unfavorite = useCallback(() => handleFavoriteAction("removed"), [handleFavoriteAction]);
433
+ if (!state)
434
+ try {
435
+ throw resolveFavoritesState(instance, context);
436
+ } catch (err_0) {
437
+ if (err_0 instanceof Error && err_0.message === "Favorites service connection timeout")
438
+ return {
439
+ favorite: async () => {
440
+ },
441
+ unfavorite: async () => {
442
+ },
443
+ isFavorited: !1,
444
+ isConnected: !1
445
+ };
446
+ throw err_0;
447
+ }
448
+ return {
417
449
  favorite,
418
450
  unfavorite,
419
451
  isFavorited,
420
- isConnected: t7
421
- }, $[18] = favorite, $[19] = isFavorited, $[20] = t7, $[21] = unfavorite, $[22] = t8) : t8 = $[22], t8;
452
+ isConnected: status === "connected"
453
+ };
422
454
  }
423
455
  function useRecordDocumentHistoryEvent(t0) {
424
456
  const $ = c(11), {
@@ -588,27 +620,35 @@ const useDatasets = createStateSourceHook({
588
620
  ),
589
621
  suspender: resolveDatasets,
590
622
  getConfig: identity
591
- }), useApplyDocumentActions = createCallbackHook(applyDocumentActions);
592
- function useDocument(doc, path) {
593
- return _useDocument(doc, path);
594
- }
595
- const _useDocument = createStateSourceHook({
596
- getState: getDocumentState,
597
- shouldSuspend: (instance, doc) => getDocumentState(instance, doc).getCurrent() === void 0,
598
- suspender: resolveDocument,
623
+ }), useApplyDocumentActions = createCallbackHook(applyDocumentActions), useDocument = createStateSourceHook({
624
+ // Pass options directly to getDocumentState
625
+ getState: (instance, options) => getDocumentState(instance, options),
626
+ // Pass options directly to getDocumentState for checking current value
627
+ shouldSuspend: (instance, {
628
+ path: _path,
629
+ ...options
630
+ }) => getDocumentState(instance, options).getCurrent() === void 0,
631
+ // Extract handle part for resolveDocument
632
+ suspender: (instance, options) => resolveDocument(instance, options),
599
633
  getConfig: identity
600
634
  });
601
- function useDocumentEvent(handler, dataset) {
602
- const $ = c(6), ref = useRef(handler);
635
+ function useDocumentEvent(options) {
636
+ const $ = c(9);
637
+ let datasetHandle, onEvent;
638
+ $[0] !== options ? ({
639
+ onEvent,
640
+ ...datasetHandle
641
+ } = options, $[0] = options, $[1] = datasetHandle, $[2] = onEvent) : (datasetHandle = $[1], onEvent = $[2]);
642
+ const ref = useRef(onEvent);
603
643
  let t0;
604
- $[0] !== handler ? (t0 = () => {
605
- ref.current = handler;
606
- }, $[0] = handler, $[1] = t0) : t0 = $[1], useInsertionEffect(t0);
644
+ $[3] !== onEvent ? (t0 = () => {
645
+ ref.current = onEvent;
646
+ }, $[3] = onEvent, $[4] = t0) : t0 = $[4], useInsertionEffect(t0);
607
647
  let t1;
608
- $[2] === Symbol.for("react.memo_cache_sentinel") ? (t1 = (documentEvent) => ref.current(documentEvent), $[2] = t1) : t1 = $[2];
609
- const stableHandler = t1, instance = useSanityInstance(dataset);
648
+ $[5] === Symbol.for("react.memo_cache_sentinel") ? (t1 = (documentEvent) => ref.current(documentEvent), $[5] = t1) : t1 = $[5];
649
+ const stableHandler = t1, instance = useSanityInstance(datasetHandle);
610
650
  let t2, t3;
611
- $[3] !== instance ? (t2 = () => subscribeDocumentEvents(instance, stableHandler), t3 = [instance, stableHandler], $[3] = instance, $[4] = t2, $[5] = t3) : (t2 = $[4], t3 = $[5]), useEffect(t2, t3);
651
+ $[6] !== instance ? (t2 = () => subscribeDocumentEvents(instance, stableHandler), t3 = [instance, stableHandler], $[6] = instance, $[7] = t2, $[8] = t3) : (t2 = $[7], t3 = $[8]), useEffect(t2, t3);
612
652
  }
613
653
  function useDocumentPermissions(actionOrActions) {
614
654
  const $ = c(13);
@@ -634,7 +674,7 @@ function useDocumentPermissions(actionOrActions) {
634
674
  }, $[7] = dataset, $[8] = projectId, $[9] = t1) : t1 = $[9];
635
675
  const instance = useSanityInstance(t1);
636
676
  if (getPermissionsState(instance, actionOrActions).getCurrent() === void 0)
637
- throw firstValueFrom(getPermissionsState(instance, actionOrActions).observable.pipe(filter(_temp$3)));
677
+ throw firstValueFrom(getPermissionsState(instance, actionOrActions).observable.pipe(filter(_temp$2)));
638
678
  let t2, t3;
639
679
  $[10] !== actionOrActions || $[11] !== instance ? (t3 = getPermissionsState(instance, actionOrActions), $[10] = actionOrActions, $[11] = instance, $[12] = t3) : t3 = $[12], t2 = t3;
640
680
  const {
@@ -643,45 +683,63 @@ function useDocumentPermissions(actionOrActions) {
643
683
  } = t2;
644
684
  return useSyncExternalStore(subscribe, getCurrent);
645
685
  }
646
- function _temp$3(result) {
686
+ function _temp$2(result) {
647
687
  return result !== void 0;
648
688
  }
649
- const useDocumentSyncStatus = createStateSourceHook(getDocumentSyncStatus), ignoredKeys = ["_id", "_type", "_createdAt", "_updatedAt", "_rev"];
650
- function useEditDocument(docHandle, path) {
651
- const $ = c(5), instance = useSanityInstance(docHandle), apply = useApplyDocumentActions();
652
- if (getDocumentState(instance, docHandle).getCurrent() === void 0)
653
- throw resolveDocument(instance, docHandle);
654
- let t0;
655
- return $[0] !== apply || $[1] !== docHandle || $[2] !== instance || $[3] !== path ? (t0 = (updater) => {
656
- if (path) {
657
- const nextValue = typeof updater == "function" ? updater(getDocumentState(instance, docHandle, path).getCurrent()) : updater;
658
- return apply(editDocument(docHandle, {
689
+ const useDocumentSyncStatus = createStateSourceHook({
690
+ getState: getDocumentSyncStatus,
691
+ shouldSuspend: (instance, doc) => getDocumentSyncStatus(instance, doc).getCurrent() === void 0,
692
+ suspender: (instance, doc) => resolveDocument(instance, doc),
693
+ getConfig: identity
694
+ }), ignoredKeys = ["_id", "_type", "_createdAt", "_updatedAt", "_rev"];
695
+ function useEditDocument(t0) {
696
+ const $ = c(8);
697
+ let doc, path;
698
+ $[0] !== t0 ? ({
699
+ path,
700
+ ...doc
701
+ } = t0, $[0] = t0, $[1] = doc, $[2] = path) : (doc = $[1], path = $[2]);
702
+ const instance = useSanityInstance(doc), apply = useApplyDocumentActions();
703
+ if (getDocumentState(instance, doc).getCurrent() === void 0)
704
+ throw resolveDocument(instance, doc);
705
+ let t1;
706
+ return $[3] !== apply || $[4] !== doc || $[5] !== instance || $[6] !== path ? (t1 = (updater) => {
707
+ const currentPath = path;
708
+ if (currentPath) {
709
+ const currentValue = getDocumentState(instance, {
710
+ ...doc,
711
+ path
712
+ }).getCurrent(), nextValue = typeof updater == "function" ? updater(currentValue) : updater;
713
+ return apply(editDocument(doc, {
659
714
  set: {
660
- [path]: nextValue
715
+ [currentPath]: nextValue
661
716
  }
662
717
  }));
663
718
  }
664
- const current = getDocumentState(instance, docHandle).getCurrent(), nextValue_0 = typeof updater == "function" ? updater(current) : updater;
719
+ const current = getDocumentState(instance, {
720
+ ...doc,
721
+ path
722
+ }).getCurrent(), nextValue_0 = typeof updater == "function" ? updater(current) : updater;
665
723
  if (typeof nextValue_0 != "object" || !nextValue_0)
666
724
  throw new Error("No path was provided to `useEditDocument` and the value provided was not a document object.");
667
725
  const editActions = Object.keys({
668
726
  ...current,
669
727
  ...nextValue_0
670
- }).filter(_temp$2).filter((key_0) => current?.[key_0] !== nextValue_0[key_0]).map((key_1) => key_1 in nextValue_0 ? editDocument(docHandle, {
728
+ }).filter(_temp$1).filter((key_0) => current?.[key_0] !== nextValue_0[key_0]).map((key_1) => key_1 in nextValue_0 ? editDocument(doc, {
671
729
  set: {
672
730
  [key_1]: nextValue_0[key_1]
673
731
  }
674
- }) : editDocument(docHandle, {
732
+ }) : editDocument(doc, {
675
733
  unset: [key_1]
676
734
  }));
677
735
  return apply(editActions);
678
- }, $[0] = apply, $[1] = docHandle, $[2] = instance, $[3] = path, $[4] = t0) : t0 = $[4], t0;
736
+ }, $[3] = apply, $[4] = doc, $[5] = instance, $[6] = path, $[7] = t1) : t1 = $[7], t1;
679
737
  }
680
- function _temp$2(key) {
738
+ function _temp$1(key) {
681
739
  return !ignoredKeys.includes(key);
682
740
  }
683
- function useQuery(query, options) {
684
- const instance = useSanityInstance(options), [isPending, startTransition] = useTransition(), queryKey = getQueryKey(query, options), [deferredQueryKey, setDeferredQueryKey] = useState(queryKey), deferred = useMemo(() => parseQueryKey(deferredQueryKey), [deferredQueryKey]), ref = useRef(new AbortController());
741
+ function useQuery(options) {
742
+ const instance = useSanityInstance(options), [isPending, startTransition] = useTransition(), queryKey = getQueryKey(options), [deferredQueryKey, setDeferredQueryKey] = useState(queryKey), deferred = useMemo(() => parseQueryKey(deferredQueryKey), [deferredQueryKey]), ref = useRef(new AbortController());
685
743
  useEffect(() => {
686
744
  queryKey !== deferredQueryKey && startTransition(() => {
687
745
  ref && !ref.current.signal.aborted && (ref.current.abort(), ref.current = new AbortController()), setDeferredQueryKey(queryKey);
@@ -690,11 +748,11 @@ function useQuery(query, options) {
690
748
  const {
691
749
  getCurrent,
692
750
  subscribe
693
- } = useMemo(() => getQueryState(instance, deferred.query, deferred.options), [instance, deferred]);
751
+ } = useMemo(() => getQueryState(instance, deferred), [instance, deferred]);
694
752
  if (getCurrent() === void 0) {
695
753
  const currentSignal = ref.current.signal;
696
- throw resolveQuery(instance, deferred.query, {
697
- ...deferred.options,
754
+ throw resolveQuery(instance, {
755
+ ...deferred,
698
756
  signal: currentSignal
699
757
  });
700
758
  }
@@ -704,161 +762,155 @@ function useQuery(query, options) {
704
762
  isPending
705
763
  }), [data, isPending]);
706
764
  }
707
- const DEFAULT_BATCH_SIZE = 25, DEFAULT_PERSPECTIVE$1 = "drafts";
708
- function useDocuments(t0) {
709
- const $ = c(36);
710
- let filter2, options, orderings, params, search, t1;
711
- $[0] !== t0 ? ({
712
- batchSize: t1,
713
- params,
714
- search,
715
- filter: filter2,
716
- orderings,
717
- ...options
718
- } = t0, $[0] = t0, $[1] = filter2, $[2] = options, $[3] = orderings, $[4] = params, $[5] = search, $[6] = t1) : (filter2 = $[1], options = $[2], orderings = $[3], params = $[4], search = $[5], t1 = $[6]);
719
- const batchSize = t1 === void 0 ? DEFAULT_BATCH_SIZE : t1, instance = useSanityInstance(options), perspective = options.perspective ?? DEFAULT_PERSPECTIVE$1, [limit, setLimit] = useState(batchSize);
720
- let t2;
721
- $[7] !== batchSize || $[8] !== filter2 || $[9] !== orderings || $[10] !== params || $[11] !== search ? (t2 = JSON.stringify({
765
+ const DEFAULT_BATCH_SIZE = 25;
766
+ function useDocuments({
767
+ batchSize = DEFAULT_BATCH_SIZE,
768
+ params,
769
+ search,
770
+ filter: filter2,
771
+ orderings,
772
+ documentType,
773
+ ...options
774
+ }) {
775
+ const instance = useSanityInstance(options), [limit, setLimit] = useState(batchSize), documentTypes = useMemo(() => (Array.isArray(documentType) ? documentType : [documentType]).filter((i) => typeof i == "string"), [documentType]), key = JSON.stringify({
722
776
  filter: filter2,
723
777
  search,
724
778
  params,
725
779
  orderings,
726
- batchSize
727
- }), $[7] = batchSize, $[8] = filter2, $[9] = orderings, $[10] = params, $[11] = search, $[12] = t2) : t2 = $[12];
728
- const key = t2;
729
- let t3;
730
- $[13] !== batchSize ? (t3 = () => {
780
+ batchSize,
781
+ types: documentTypes,
782
+ ...options
783
+ });
784
+ useEffect(() => {
731
785
  setLimit(batchSize);
732
- }, $[13] = batchSize, $[14] = t3) : t3 = $[14];
733
- let t4;
734
- $[15] !== batchSize || $[16] !== key ? (t4 = [key, batchSize], $[15] = batchSize, $[16] = key, $[17] = t4) : t4 = $[17], useEffect(t3, t4);
735
- let t5;
736
- const conditions = [], trimmedSearch = search?.trim();
737
- if (trimmedSearch) {
738
- const searchFilter = createGroqSearchFilter(trimmedSearch);
739
- searchFilter && conditions.push(searchFilter);
740
- }
741
- filter2 && conditions.push(`(${filter2})`), t5 = conditions.length ? `[${conditions.join(" && ")}]` : "";
742
- const filterClause = t5, orderClause = orderings ? `| order(${orderings.map(_temp2$1).join(",")})` : "", dataQuery = `*${filterClause}${orderClause}[0...${limit}]{"documentId":_id,"documentType":_type,...$__dataset}`, countQuery = `count(*${filterClause})`;
743
- let t6;
744
- $[18] !== instance.config ? (t6 = pick(instance.config, "projectId", "dataset"), $[18] = instance.config, $[19] = t6) : t6 = $[19];
745
- let t7;
746
- $[20] !== params || $[21] !== t6 ? (t7 = {
747
- ...params,
748
- __dataset: t6
749
- }, $[20] = params, $[21] = t6, $[22] = t7) : t7 = $[22];
750
- let t8;
751
- $[23] !== options || $[24] !== perspective || $[25] !== t7 ? (t8 = {
752
- ...options,
753
- params: t7,
754
- perspective
755
- }, $[23] = options, $[24] = perspective, $[25] = t7, $[26] = t8) : t8 = $[26];
756
- const {
757
- data: t9,
786
+ }, [key, batchSize]);
787
+ const filterClause = useMemo(() => {
788
+ const conditions = [], trimmedSearch = search?.trim();
789
+ if (trimmedSearch) {
790
+ const searchFilter = createGroqSearchFilter(trimmedSearch);
791
+ searchFilter && conditions.push(searchFilter);
792
+ }
793
+ return documentTypes?.length && conditions.push("(_type in $__types)"), filter2 && conditions.push(`(${filter2})`), conditions.length ? `[${conditions.join(" && ")}]` : "";
794
+ }, [filter2, search, documentTypes]), orderClause = orderings ? `| order(${orderings.map((ordering) => [ordering.field, ordering.direction.toLowerCase()].map((str) => str.trim()).filter(Boolean).join(" ")).join(",")})` : "", dataQuery = `*${filterClause}${orderClause}[0...${limit}]{"documentId":_id,"documentType":_type,...$__handle}`, countQuery = `count(*${filterClause})`, {
795
+ data: {
796
+ count,
797
+ data
798
+ },
758
799
  isPending
759
- } = useQuery(`{"count":${countQuery},"data":${dataQuery}}`, t8), {
760
- count,
761
- data
762
- } = t9, hasMore = data.length < count;
763
- let t10;
764
- $[27] !== batchSize || $[28] !== count ? (t10 = () => {
800
+ } = useQuery({
801
+ ...options,
802
+ query: `{"count":${countQuery},"data":${dataQuery}}`,
803
+ params: {
804
+ ...params,
805
+ __handle: {
806
+ ...pick(instance.config, "projectId", "dataset", "perspective"),
807
+ ...pick(options, "projectId", "dataset", "perspective")
808
+ },
809
+ __types: documentTypes
810
+ }
811
+ }), hasMore = data.length < count, loadMore = useCallback(() => {
765
812
  setLimit((prev) => Math.min(prev + batchSize, count));
766
- }, $[27] = batchSize, $[28] = count, $[29] = t10) : t10 = $[29];
767
- const loadMore = t10;
768
- let t11, t12;
769
- return $[30] !== count || $[31] !== data || $[32] !== hasMore || $[33] !== isPending || $[34] !== loadMore ? (t12 = {
813
+ }, [count, batchSize]);
814
+ return useMemo(() => ({
770
815
  data,
771
816
  hasMore,
772
817
  count,
773
818
  isPending,
774
819
  loadMore
775
- }, $[30] = count, $[31] = data, $[32] = hasMore, $[33] = isPending, $[34] = loadMore, $[35] = t12) : t12 = $[35], t11 = t12, t11;
820
+ }), [count, data, hasMore, isPending, loadMore]);
776
821
  }
777
- function _temp2$1(ordering) {
778
- return [ordering.field, ordering.direction.toLowerCase()].map(_temp$1).filter(Boolean).join(" ");
779
- }
780
- function _temp$1(str) {
781
- return str.trim();
782
- }
783
- const DEFAULT_PERSPECTIVE = "drafts";
784
822
  function usePaginatedDocuments(t0) {
785
- const $ = c(51);
786
- let options, orderings, search, t1, t2, t3;
823
+ const $ = c(62);
824
+ let documentType, options, orderings, search, t1, t2, t3;
787
825
  $[0] !== t0 ? ({
826
+ documentType,
788
827
  filter: t1,
789
828
  pageSize: t2,
790
829
  params: t3,
791
830
  orderings,
792
831
  search,
793
832
  ...options
794
- } = t0, $[0] = t0, $[1] = options, $[2] = orderings, $[3] = search, $[4] = t1, $[5] = t2, $[6] = t3) : (options = $[1], orderings = $[2], search = $[3], t1 = $[4], t2 = $[5], t3 = $[6]);
833
+ } = t0, $[0] = t0, $[1] = documentType, $[2] = options, $[3] = orderings, $[4] = search, $[5] = t1, $[6] = t2, $[7] = t3) : (documentType = $[1], options = $[2], orderings = $[3], search = $[4], t1 = $[5], t2 = $[6], t3 = $[7]);
795
834
  const filter2 = t1 === void 0 ? "" : t1, pageSize = t2 === void 0 ? 25 : t2;
796
835
  let t4;
797
- $[7] !== t3 ? (t4 = t3 === void 0 ? {} : t3, $[7] = t3, $[8] = t4) : t4 = $[8];
836
+ $[8] !== t3 ? (t4 = t3 === void 0 ? {} : t3, $[8] = t3, $[9] = t4) : t4 = $[9];
798
837
  const params = t4, instance = useSanityInstance(options), [pageIndex, setPageIndex] = useState(0);
799
838
  let t5;
800
- $[9] !== filter2 || $[10] !== orderings || $[11] !== pageSize || $[12] !== params || $[13] !== search ? (t5 = JSON.stringify({
839
+ $[10] !== filter2 || $[11] !== orderings || $[12] !== pageSize || $[13] !== params || $[14] !== search ? (t5 = JSON.stringify({
801
840
  filter: filter2,
802
841
  search,
803
842
  params,
804
843
  orderings,
805
844
  pageSize
806
- }), $[9] = filter2, $[10] = orderings, $[11] = pageSize, $[12] = params, $[13] = search, $[14] = t5) : t5 = $[14];
845
+ }), $[10] = filter2, $[11] = orderings, $[12] = pageSize, $[13] = params, $[14] = search, $[15] = t5) : t5 = $[15];
807
846
  const key = t5;
808
847
  let t6;
809
- $[15] === Symbol.for("react.memo_cache_sentinel") ? (t6 = () => {
848
+ $[16] === Symbol.for("react.memo_cache_sentinel") ? (t6 = () => {
810
849
  setPageIndex(0);
811
- }, $[15] = t6) : t6 = $[15];
850
+ }, $[16] = t6) : t6 = $[16];
812
851
  let t7;
813
- $[16] !== key ? (t7 = [key], $[16] = key, $[17] = t7) : t7 = $[17], useEffect(t6, t7);
814
- const startIndex = pageIndex * pageSize, endIndex = (pageIndex + 1) * pageSize, perspective = options.perspective ?? DEFAULT_PERSPECTIVE;
852
+ $[17] !== key ? (t7 = [key], $[17] = key, $[18] = t7) : t7 = $[18], useEffect(t6, t7);
853
+ const startIndex = pageIndex * pageSize, endIndex = (pageIndex + 1) * pageSize;
815
854
  let t8;
855
+ $[19] !== documentType ? (t8 = Array.isArray(documentType) ? documentType : [documentType], $[19] = documentType, $[20] = t8) : t8 = $[20];
856
+ let t9;
857
+ $[21] !== t8 ? (t9 = t8.filter(_temp), $[21] = t8, $[22] = t9) : t9 = $[22];
858
+ const documentTypes = t9;
859
+ let t10;
816
860
  const conditions = [], trimmedSearch = search?.trim();
817
861
  if (trimmedSearch) {
818
862
  const searchFilter = createGroqSearchFilter(trimmedSearch);
819
863
  searchFilter && conditions.push(searchFilter);
820
864
  }
821
- filter2 && conditions.push(`(${filter2})`), t8 = conditions.length ? `[${conditions.join(" && ")}]` : "";
822
- const filterClause = t8, orderClause = orderings ? `| order(${orderings.map(_temp2).join(",")})` : "", dataQuery = `*${filterClause}${orderClause}[${startIndex}...${endIndex}]{"documentId":_id,"documentType":_type,...$__dataset}`, countQuery = `count(*${filterClause})`;
823
- let t9;
824
- $[18] !== instance.config ? (t9 = pick(instance.config, "projectId", "dataset"), $[18] = instance.config, $[19] = t9) : t9 = $[19];
825
- let t10;
826
- $[20] !== params || $[21] !== t9 ? (t10 = {
865
+ documentTypes?.length && conditions.push("(_type in $__types)"), filter2 && conditions.push(`(${filter2})`), t10 = conditions.length ? `[${conditions.join(" && ")}]` : "";
866
+ const filterClause = t10, orderClause = orderings ? `| order(${orderings.map(_temp3).join(",")})` : "", dataQuery = `*${filterClause}${orderClause}[${startIndex}...${endIndex}]{"documentId":_id,"documentType":_type,...$__handle}`, countQuery = `count(*${filterClause})`, t11 = `{"data":${dataQuery},"count":${countQuery}}`;
867
+ let t12;
868
+ $[23] !== instance.config ? (t12 = pick(instance.config, "projectId", "dataset", "perspective"), $[23] = instance.config, $[24] = t12) : t12 = $[24];
869
+ let t13;
870
+ $[25] !== options ? (t13 = pick(options, "projectId", "dataset", "perspective"), $[25] = options, $[26] = t13) : t13 = $[26];
871
+ let t14;
872
+ $[27] !== t12 || $[28] !== t13 ? (t14 = {
873
+ ...t12,
874
+ ...t13
875
+ }, $[27] = t12, $[28] = t13, $[29] = t14) : t14 = $[29];
876
+ let t15;
877
+ $[30] !== documentTypes || $[31] !== params || $[32] !== t14 ? (t15 = {
827
878
  ...params,
828
- __dataset: t9
829
- }, $[20] = params, $[21] = t9, $[22] = t10) : t10 = $[22];
830
- let t11;
831
- $[23] !== options || $[24] !== perspective || $[25] !== t10 ? (t11 = {
879
+ __types: documentTypes,
880
+ __handle: t14
881
+ }, $[30] = documentTypes, $[31] = params, $[32] = t14, $[33] = t15) : t15 = $[33];
882
+ let t16;
883
+ $[34] !== options || $[35] !== t11 || $[36] !== t15 ? (t16 = {
832
884
  ...options,
833
- perspective,
834
- params: t10
835
- }, $[23] = options, $[24] = perspective, $[25] = t10, $[26] = t11) : t11 = $[26];
885
+ query: t11,
886
+ params: t15
887
+ }, $[34] = options, $[35] = t11, $[36] = t15, $[37] = t16) : t16 = $[37];
836
888
  const {
837
- data: t12,
889
+ data: t17,
838
890
  isPending
839
- } = useQuery(`{"data":${dataQuery},"count":${countQuery}}`, t11), {
891
+ } = useQuery(t16), {
840
892
  data,
841
893
  count
842
- } = t12, totalPages = Math.ceil(count / pageSize), currentPage = pageIndex + 1;
843
- let t13;
844
- $[27] === Symbol.for("react.memo_cache_sentinel") ? (t13 = () => setPageIndex(0), $[27] = t13) : t13 = $[27];
845
- const firstPage = t13;
846
- let t14;
847
- $[28] === Symbol.for("react.memo_cache_sentinel") ? (t14 = () => setPageIndex(_temp3), $[28] = t14) : t14 = $[28];
848
- const previousPage = t14;
849
- let t15;
850
- $[29] !== totalPages ? (t15 = () => setPageIndex((prev_0) => Math.min(prev_0 + 1, totalPages - 1)), $[29] = totalPages, $[30] = t15) : t15 = $[30];
851
- const nextPage = t15;
852
- let t16;
853
- $[31] !== totalPages ? (t16 = () => setPageIndex(totalPages - 1), $[31] = totalPages, $[32] = t16) : t16 = $[32];
854
- const lastPage = t16;
855
- let t17;
856
- $[33] !== totalPages ? (t17 = (pageNumber) => {
857
- pageNumber < 1 || pageNumber > totalPages || setPageIndex(pageNumber - 1);
858
- }, $[33] = totalPages, $[34] = t17) : t17 = $[34];
859
- const goToPage = t17, hasFirstPage = pageIndex > 0, hasPreviousPage = pageIndex > 0, hasNextPage = pageIndex < totalPages - 1, hasLastPage = pageIndex < totalPages - 1;
894
+ } = t17, totalPages = Math.ceil(count / pageSize), currentPage = pageIndex + 1;
860
895
  let t18;
861
- return $[35] !== count || $[36] !== currentPage || $[37] !== data || $[38] !== endIndex || $[39] !== goToPage || $[40] !== hasFirstPage || $[41] !== hasLastPage || $[42] !== hasNextPage || $[43] !== hasPreviousPage || $[44] !== isPending || $[45] !== lastPage || $[46] !== nextPage || $[47] !== pageSize || $[48] !== startIndex || $[49] !== totalPages ? (t18 = {
896
+ $[38] === Symbol.for("react.memo_cache_sentinel") ? (t18 = () => setPageIndex(0), $[38] = t18) : t18 = $[38];
897
+ const firstPage = t18;
898
+ let t19;
899
+ $[39] === Symbol.for("react.memo_cache_sentinel") ? (t19 = () => setPageIndex(_temp4), $[39] = t19) : t19 = $[39];
900
+ const previousPage = t19;
901
+ let t20;
902
+ $[40] !== totalPages ? (t20 = () => setPageIndex((prev_0) => Math.min(prev_0 + 1, totalPages - 1)), $[40] = totalPages, $[41] = t20) : t20 = $[41];
903
+ const nextPage = t20;
904
+ let t21;
905
+ $[42] !== totalPages ? (t21 = () => setPageIndex(totalPages - 1), $[42] = totalPages, $[43] = t21) : t21 = $[43];
906
+ const lastPage = t21;
907
+ let t22;
908
+ $[44] !== totalPages ? (t22 = (pageNumber) => {
909
+ pageNumber < 1 || pageNumber > totalPages || setPageIndex(pageNumber - 1);
910
+ }, $[44] = totalPages, $[45] = t22) : t22 = $[45];
911
+ const goToPage = t22, hasFirstPage = pageIndex > 0, hasPreviousPage = pageIndex > 0, hasNextPage = pageIndex < totalPages - 1, hasLastPage = pageIndex < totalPages - 1;
912
+ let t23;
913
+ return $[46] !== count || $[47] !== currentPage || $[48] !== data || $[49] !== endIndex || $[50] !== goToPage || $[51] !== hasFirstPage || $[52] !== hasLastPage || $[53] !== hasNextPage || $[54] !== hasPreviousPage || $[55] !== isPending || $[56] !== lastPage || $[57] !== nextPage || $[58] !== pageSize || $[59] !== startIndex || $[60] !== totalPages ? (t23 = {
862
914
  data,
863
915
  isPending,
864
916
  pageSize,
@@ -876,17 +928,20 @@ function usePaginatedDocuments(t0) {
876
928
  lastPage,
877
929
  hasLastPage,
878
930
  goToPage
879
- }, $[35] = count, $[36] = currentPage, $[37] = data, $[38] = endIndex, $[39] = goToPage, $[40] = hasFirstPage, $[41] = hasLastPage, $[42] = hasNextPage, $[43] = hasPreviousPage, $[44] = isPending, $[45] = lastPage, $[46] = nextPage, $[47] = pageSize, $[48] = startIndex, $[49] = totalPages, $[50] = t18) : t18 = $[50], t18;
931
+ }, $[46] = count, $[47] = currentPage, $[48] = data, $[49] = endIndex, $[50] = goToPage, $[51] = hasFirstPage, $[52] = hasLastPage, $[53] = hasNextPage, $[54] = hasPreviousPage, $[55] = isPending, $[56] = lastPage, $[57] = nextPage, $[58] = pageSize, $[59] = startIndex, $[60] = totalPages, $[61] = t23) : t23 = $[61], t23;
880
932
  }
881
- function _temp3(prev) {
933
+ function _temp4(prev) {
882
934
  return Math.max(prev - 1, 0);
883
935
  }
884
- function _temp2(ordering) {
885
- return [ordering.field, ordering.direction.toLowerCase()].map(_temp).filter(Boolean).join(" ");
936
+ function _temp3(ordering) {
937
+ return [ordering.field, ordering.direction.toLowerCase()].map(_temp2).filter(Boolean).join(" ");
886
938
  }
887
- function _temp(str) {
939
+ function _temp2(str) {
888
940
  return str.trim();
889
941
  }
942
+ function _temp(i) {
943
+ return typeof i == "string";
944
+ }
890
945
  function usePreview(t0) {
891
946
  const $ = c(13);
892
947
  let docHandle, ref;
@@ -940,7 +995,7 @@ function useProjection(t0) {
940
995
  if ($[4] !== docHandle || $[5] !== instance || $[6] !== projection ? (stateSource = getProjectionState(instance, {
941
996
  ...docHandle,
942
997
  projection
943
- }), t1 = stateSource.getCurrent(), $[4] = docHandle, $[5] = instance, $[6] = projection, $[7] = stateSource, $[8] = t1) : (stateSource = $[7], t1 = $[8]), t1.data === null)
998
+ }), t1 = stateSource.getCurrent()?.data, $[4] = docHandle, $[5] = instance, $[6] = projection, $[7] = stateSource, $[8] = t1) : (stateSource = $[7], t1 = $[8]), t1 === null)
944
999
  throw resolveProjection(instance, {
945
1000
  ...docHandle,
946
1001
  projection
@@ -977,6 +1032,14 @@ const useProject = createStateSourceHook({
977
1032
  getState: getProjectsState,
978
1033
  shouldSuspend: (instance) => getProjectsState(instance).getCurrent() === void 0,
979
1034
  suspender: resolveProjects
1035
+ }), useActiveReleases = createStateSourceHook({
1036
+ getState: getActiveReleasesState,
1037
+ shouldSuspend: (instance) => getActiveReleasesState(instance).getCurrent() === void 0,
1038
+ suspender: (instance) => firstValueFrom(getActiveReleasesState(instance).observable.pipe(filter(Boolean)))
1039
+ }), usePerspective = createStateSourceHook({
1040
+ getState: getPerspectiveState,
1041
+ shouldSuspend: (instance, options) => getPerspectiveState(instance, options).getCurrent() === void 0,
1042
+ suspender: (instance, _options) => firstValueFrom(getActiveReleasesState(instance).observable.pipe(filter(Boolean)))
980
1043
  });
981
1044
  function useUsers(options) {
982
1045
  const instance = useSanityInstance(options), [isPending, startTransition] = useTransition(), key = getUsersKey(instance, options), [deferredKey, setDeferredKey] = useState(key), deferred = useMemo(() => parseUsersKey(deferredKey), [deferredKey]), [ref, setRef] = useState(new AbortController());
@@ -1007,7 +1070,7 @@ function useUsers(options) {
1007
1070
  loadMore
1008
1071
  };
1009
1072
  }
1010
- var version = "0.0.0-rc.6";
1073
+ var version = "0.0.0-rc.8";
1011
1074
  function getEnv(key) {
1012
1075
  if (typeof import.meta < "u" && import.meta.env)
1013
1076
  return import.meta.env[key];
@@ -1023,6 +1086,7 @@ export {
1023
1086
  ResourceProvider,
1024
1087
  SDKProvider,
1025
1088
  SanityApp,
1089
+ useActiveReleases,
1026
1090
  useApplyDocumentActions,
1027
1091
  useAuthState,
1028
1092
  useAuthToken,
@@ -1043,6 +1107,7 @@ export {
1043
1107
  useManageFavorite,
1044
1108
  useNavigateToStudioDocument,
1045
1109
  usePaginatedDocuments,
1110
+ usePerspective,
1046
1111
  usePreview,
1047
1112
  useProject,
1048
1113
  useProjection,
@@ -1052,6 +1117,7 @@ export {
1052
1117
  useSanityInstance,
1053
1118
  useStudioWorkspacesByProjectIdDataset,
1054
1119
  useUsers,
1120
+ useVerifyOrgProjects,
1055
1121
  useWindowConnection
1056
1122
  };
1057
1123
  //# sourceMappingURL=index.js.map