@sanity/sdk-react 0.0.0-rc.3 → 0.0.0-rc.4

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 (71) hide show
  1. package/dist/index.d.ts +600 -3548
  2. package/dist/index.js +422 -474
  3. package/dist/index.js.map +1 -1
  4. package/package.json +16 -14
  5. package/src/_exports/index.ts +5 -6
  6. package/src/components/SDKProvider.test.tsx +78 -54
  7. package/src/components/SDKProvider.tsx +31 -26
  8. package/src/components/SanityApp.test.tsx +121 -15
  9. package/src/components/SanityApp.tsx +26 -15
  10. package/src/components/auth/AuthBoundary.test.tsx +32 -14
  11. package/src/components/auth/AuthBoundary.tsx +53 -23
  12. package/src/components/auth/LoginCallback.test.tsx +19 -6
  13. package/src/components/auth/LoginCallback.tsx +2 -11
  14. package/src/components/auth/LoginError.test.tsx +12 -4
  15. package/src/components/auth/LoginError.tsx +13 -21
  16. package/src/components/auth/LoginFooter.test.tsx +7 -3
  17. package/src/context/ResourceProvider.test.tsx +157 -0
  18. package/src/context/ResourceProvider.tsx +111 -0
  19. package/src/context/SanityInstanceContext.ts +1 -1
  20. package/src/hooks/auth/useLoginUrl.tsx +14 -0
  21. package/src/hooks/client/useClient.ts +2 -1
  22. package/src/hooks/comlink/useManageFavorite.test.ts +16 -8
  23. package/src/hooks/comlink/useManageFavorite.ts +45 -14
  24. package/src/hooks/comlink/useRecordDocumentHistoryEvent.test.ts +8 -4
  25. package/src/hooks/comlink/useRecordDocumentHistoryEvent.ts +18 -9
  26. package/src/hooks/context/useSanityInstance.test.tsx +157 -15
  27. package/src/hooks/context/useSanityInstance.ts +66 -26
  28. package/src/hooks/dashboard/useNavigateToStudioDocument.test.ts +13 -31
  29. package/src/hooks/dashboard/useNavigateToStudioDocument.ts +12 -15
  30. package/src/hooks/dashboard/{useStudioWorkspacesByResourceId.test.tsx → useStudioWorkspacesByProjectIdDataset.test.tsx} +13 -13
  31. package/src/hooks/dashboard/{useStudioWorkspacesByResourceId.ts → useStudioWorkspacesByProjectIdDataset.ts} +10 -9
  32. package/src/hooks/datasets/useDatasets.ts +15 -4
  33. package/src/hooks/document/useApplyDocumentActions.test.ts +4 -9
  34. package/src/hooks/document/useApplyDocumentActions.ts +6 -31
  35. package/src/hooks/document/useDocument.test.ts +2 -2
  36. package/src/hooks/document/useDocument.ts +40 -19
  37. package/src/hooks/document/useDocumentEvent.test.ts +2 -3
  38. package/src/hooks/document/useDocumentEvent.ts +7 -11
  39. package/src/hooks/document/useDocumentPermissions.test.ts +204 -0
  40. package/src/hooks/document/useDocumentPermissions.ts +31 -23
  41. package/src/hooks/document/useDocumentSyncStatus.ts +5 -4
  42. package/src/hooks/document/useEditDocument.test.ts +2 -3
  43. package/src/hooks/document/useEditDocument.ts +43 -29
  44. package/src/hooks/documents/useDocuments.test.tsx +30 -3
  45. package/src/hooks/documents/useDocuments.ts +29 -12
  46. package/src/hooks/helpers/createCallbackHook.test.tsx +2 -2
  47. package/src/hooks/helpers/createCallbackHook.tsx +2 -3
  48. package/src/hooks/helpers/createStateSourceHook.test.tsx +1 -1
  49. package/src/hooks/helpers/createStateSourceHook.tsx +5 -8
  50. package/src/hooks/paginatedDocuments/usePaginatedDocuments.test.tsx +43 -18
  51. package/src/hooks/paginatedDocuments/usePaginatedDocuments.ts +44 -54
  52. package/src/hooks/preview/usePreview.test.tsx +66 -7
  53. package/src/hooks/preview/usePreview.tsx +17 -12
  54. package/src/hooks/projection/useProjection.test.tsx +68 -3
  55. package/src/hooks/projection/useProjection.ts +21 -24
  56. package/src/hooks/projects/useProject.ts +7 -4
  57. package/src/hooks/query/useQuery.ts +32 -14
  58. package/src/hooks/users/useUsers.test.tsx +330 -0
  59. package/src/hooks/users/useUsers.ts +65 -52
  60. package/src/components/Login/LoginLinks.test.tsx +0 -90
  61. package/src/components/Login/LoginLinks.tsx +0 -58
  62. package/src/components/auth/Login.test.tsx +0 -27
  63. package/src/components/auth/Login.tsx +0 -39
  64. package/src/components/auth/LoginLayout.test.tsx +0 -19
  65. package/src/components/auth/LoginLayout.tsx +0 -69
  66. package/src/components/auth/authTestHelpers.tsx +0 -11
  67. package/src/context/SanityProvider.test.tsx +0 -25
  68. package/src/context/SanityProvider.tsx +0 -50
  69. package/src/hooks/auth/useLoginUrls.test.tsx +0 -68
  70. package/src/hooks/auth/useLoginUrls.tsx +0 -52
  71. package/src/hooks/users/useUsers.test.ts +0 -163
package/dist/index.js CHANGED
@@ -1,52 +1,50 @@
1
- import { jsxs, jsx, Fragment as Fragment$1 } from "react/jsx-runtime";
1
+ import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
2
  import { c } from "react/compiler-runtime";
3
- import { getAuthState, getLoginUrlsState, fetchLoginUrls, handleAuthCallback, logout, AuthStateType, createSanityInstance, getTokenState, getCurrentUserState, getDashboardOrganizationId, getClientState, getOrCreateController, getOrCreateChannel, releaseChannel, getOrCreateNode, releaseNode, resolveDatasets, getDatasetsState, applyDocumentActions, getResourceId, resolveDocument, getDocumentState, subscribeDocumentEvents, getPermissionsState, getDocumentSyncStatus, editDocument, getQueryKey, parseQueryKey, getQueryState, resolveQuery, getPreviewState, resolvePreview, getProjectionState, resolveProjection, resolveProject, getProjectState, resolveProjects, getProjectsState, createUsersStore } from "@sanity/sdk";
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";
4
+ export * from "@sanity/sdk";
5
+ import { createContext, use, useSyncExternalStore, useEffect, useRef, Suspense, useState, useInsertionEffect, useTransition, useMemo, useCallback } from "react";
4
6
  import { ErrorBoundary } from "react-error-boundary";
5
- import { createContext, useContext, useSyncExternalStore, useMemo, Fragment, Suspense, useEffect, useRef, useState, useInsertionEffect, useTransition } from "react";
6
- import { SanityLogo } from "@sanity/logos";
7
+ import { identity, firstValueFrom, filter, Observable, startWith, distinctUntilChanged, switchMap, EMPTY } from "rxjs";
7
8
  import { SDK_CHANNEL_NAME, SDK_NODE_NAME } from "@sanity/message-protocol";
8
- import { firstValueFrom, filter, Observable, startWith, distinctUntilChanged, switchMap, EMPTY } from "rxjs";
9
- const SanityInstanceContext = createContext(null), useSanityInstance = (resourceId) => {
10
- const $ = c(5), sanityInstance = useContext(SanityInstanceContext);
11
- if (!sanityInstance)
12
- throw new Error("useSanityInstance must be called from within the SanityProvider");
13
- if (sanityInstance.length === 0)
14
- throw new Error("No Sanity instances found");
15
- if (sanityInstance.length === 1 || !resourceId)
16
- return sanityInstance[0];
17
- if (!resourceId)
18
- throw new Error("resourceId is required when there are multiple Sanity instances");
19
- let t0;
20
- if ($[0] !== resourceId || $[1] !== sanityInstance) {
21
- let t1;
22
- $[3] !== resourceId ? (t1 = (inst) => inst.identity.resourceId === resourceId, $[3] = resourceId, $[4] = t1) : t1 = $[4], t0 = sanityInstance.find(t1), $[0] = resourceId, $[1] = sanityInstance, $[2] = t0;
23
- } else
24
- t0 = $[2];
25
- const instance = t0;
9
+ import { pick } from "lodash-es";
10
+ const SanityInstanceContext = createContext(null), useSanityInstance = (config) => {
11
+ const instance = use(SanityInstanceContext);
26
12
  if (!instance)
27
- throw new Error(`Sanity instance with resourceId ${resourceId} not found`);
28
- return instance;
13
+ throw new Error(`SanityInstance context not found. ${config ? `Requested config: ${JSON.stringify(config, null, 2)}. ` : ""}Please ensure that your component is wrapped in a <ResourceProvider> or a <SanityApp>.`);
14
+ if (!config) return instance;
15
+ const match = instance.match(config);
16
+ if (!match)
17
+ throw new Error(`Could not find a matching Sanity instance for the requested configuration: ${JSON.stringify(config, null, 2)}.
18
+ Please ensure there is a <ResourceProvider> with a matching configuration in the component hierarchy.`);
19
+ return match;
29
20
  };
30
21
  function createStateSourceHook(options) {
31
- const getState = typeof options == "function" ? options : options.getState, getResourceId2 = "getResourceId" in options ? options.getResourceId : void 0, suspense = "shouldSuspend" in options && "suspender" in options ? options : void 0;
22
+ const getState = typeof options == "function" ? options : options.getState, getConfig = "getConfig" in options ? options.getConfig : void 0, suspense = "shouldSuspend" in options && "suspender" in options ? options : void 0;
32
23
  function useHook(...t0) {
33
24
  const $ = c(5), params = t0;
34
- let resourceId;
35
- if (getResourceId2) {
36
- let t12;
37
- $[0] !== params ? (t12 = getResourceId2(...params), $[0] = params, $[1] = t12) : t12 = $[1], resourceId = t12;
38
- }
39
- const instance = useSanityInstance(resourceId);
25
+ let t1;
26
+ $[0] !== params ? (t1 = getConfig?.(...params), $[0] = params, $[1] = t1) : t1 = $[1];
27
+ const instance = useSanityInstance(t1);
40
28
  if (suspense?.suspender && suspense?.shouldSuspend?.(instance, ...params))
41
29
  throw suspense.suspender(instance, ...params);
42
- let t1;
43
- $[2] !== instance || $[3] !== params ? (t1 = getState(instance, ...params), $[2] = instance, $[3] = params, $[4] = t1) : t1 = $[4];
44
- const state = t1;
30
+ let t2;
31
+ $[2] !== instance || $[3] !== params ? (t2 = getState(instance, ...params), $[2] = instance, $[3] = params, $[4] = t2) : t2 = $[4];
32
+ const state = t2;
45
33
  return useSyncExternalStore(state.subscribe, state.getCurrent);
46
34
  }
47
35
  return useHook;
48
36
  }
49
37
  const useAuthState = createStateSourceHook(getAuthState);
38
+ function useLoginUrl() {
39
+ const $ = c(2), instance = useSanityInstance();
40
+ let t0, t1;
41
+ $[0] !== instance ? (t1 = getLoginUrlState(instance), $[0] = instance, $[1] = t1) : t1 = $[1], t0 = t1;
42
+ const {
43
+ subscribe,
44
+ getCurrent
45
+ } = t0;
46
+ return useSyncExternalStore(subscribe, getCurrent);
47
+ }
50
48
  function isInIframe() {
51
49
  return typeof window < "u" && window.self !== window.top;
52
50
  }
@@ -59,123 +57,31 @@ class AuthError extends Error {
59
57
  typeof error == "object" && error && "message" in error && typeof error.message == "string" ? super(error.message) : super(), this.cause = error;
60
58
  }
61
59
  }
62
- function useLoginUrls() {
63
- const instance = useSanityInstance(), {
64
- subscribe,
65
- getCurrent
66
- } = useMemo(() => getLoginUrlsState(instance), [instance]);
67
- if (!getCurrent()) throw fetchLoginUrls(instance);
68
- return useSyncExternalStore(subscribe, getCurrent);
69
- }
70
- const LINKS = [{
71
- url: "https://slack.sanity.io/",
72
- i18nKey: "workspaces.community-title",
73
- title: "Community"
74
- }, {
75
- url: "https://www.sanity.io/docs",
76
- i18nKey: "workspaces.docs-title",
77
- title: "Docs"
78
- }, {
79
- url: "https://www.sanity.io/legal/privacy",
80
- i18nKey: "workspaces.privacy-title",
81
- title: "Privacy"
82
- }, {
83
- url: "https://www.sanity.io",
84
- i18nKey: "workspaces.sanity-io-title",
85
- title: "sanity.io"
86
- }];
87
- function LoginFooter() {
88
- const $ = c(2);
89
- let t0;
90
- $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = /* @__PURE__ */ jsx(SanityLogo, { className: "sc-login-footer__logo" }), $[0] = t0) : t0 = $[0];
91
- let t1;
92
- return $[1] === Symbol.for("react.memo_cache_sentinel") ? (t1 = /* @__PURE__ */ jsxs("div", { className: "sc-login-footer", children: [
93
- t0,
94
- /* @__PURE__ */ jsx("ul", { className: "sc-login-footer__links", children: LINKS.map(_temp$a) })
95
- ] }), $[1] = t1) : t1 = $[1], t1;
96
- }
97
- function _temp$a(link) {
98
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx("li", { className: "sc-login-footer__link", children: /* @__PURE__ */ jsx("a", { href: link.url, target: "_blank", rel: "noopener noreferrer", children: link.title }) }) }, link.title);
99
- }
100
- function LoginLayout({
101
- children,
102
- footer = /* @__PURE__ */ jsx(LoginFooter, {}),
103
- header
104
- }) {
105
- return /* @__PURE__ */ jsx("div", { className: "sc-login-layout", children: /* @__PURE__ */ jsxs("div", { className: "sc-login-layout__container", children: [
106
- /* @__PURE__ */ jsxs("div", { className: "sc-login-layout__card", children: [
107
- header && /* @__PURE__ */ jsx("div", { className: "sc-login-layout__card-header", children: header }),
108
- children && /* @__PURE__ */ jsx("div", { className: "sc-login-layout__card-body", children })
109
- ] }),
110
- footer
111
- ] }) });
112
- }
113
- function Login(t0) {
114
- const $ = c(5), {
115
- header,
116
- footer
117
- } = t0;
118
- let t1;
119
- $[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = /* @__PURE__ */ jsx("h1", { className: "sc-login__title", children: "Choose login provider" }), $[0] = t1) : t1 = $[0];
120
- let t2;
121
- $[1] === Symbol.for("react.memo_cache_sentinel") ? (t2 = /* @__PURE__ */ jsxs("div", { className: "sc-login", children: [
122
- t1,
123
- /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx("div", { className: "sc-login__loading", children: "Loading\u2026" }), children: /* @__PURE__ */ jsx(Providers, {}) })
124
- ] }), $[1] = t2) : t2 = $[1];
125
- let t3;
126
- return $[2] !== footer || $[3] !== header ? (t3 = /* @__PURE__ */ jsx(LoginLayout, { header, footer, children: t2 }), $[2] = footer, $[3] = header, $[4] = t3) : t3 = $[4], t3;
127
- }
128
- function Providers() {
129
- const $ = c(4), loginUrls = useLoginUrls();
130
- let t0;
131
- $[0] !== loginUrls ? (t0 = loginUrls.map(_temp$9), $[0] = loginUrls, $[1] = t0) : t0 = $[1];
132
- let t1;
133
- return $[2] !== t0 ? (t1 = /* @__PURE__ */ jsx("div", { className: "sc-login-providers", children: t0 }), $[2] = t0, $[3] = t1) : t1 = $[3], t1;
134
- }
135
- function _temp$9(t0) {
136
- const {
137
- title,
138
- url
139
- } = t0;
140
- return /* @__PURE__ */ jsx("a", { href: url, children: title }, url);
141
- }
142
- function createCallbackHook(callback, resourceId) {
60
+ function createCallbackHook(callback) {
143
61
  function useHook() {
144
- const $ = c(2), instance = useSanityInstance(resourceId);
62
+ const $ = c(2), instance = useSanityInstance();
145
63
  let t0;
146
64
  return $[0] !== instance ? (t0 = (...t1) => callback(instance, ...t1), $[0] = instance, $[1] = t0) : t0 = $[1], t0;
147
65
  }
148
66
  return useHook;
149
67
  }
150
68
  const useHandleAuthCallback = createCallbackHook(handleAuthCallback);
151
- function LoginCallback(t0) {
152
- const $ = c(7), {
153
- header,
154
- footer
155
- } = t0, handleAuthCallback2 = useHandleAuthCallback();
156
- let t1, t2;
157
- $[0] !== handleAuthCallback2 ? (t1 = () => {
69
+ function LoginCallback() {
70
+ const $ = c(3), handleAuthCallback2 = useHandleAuthCallback();
71
+ let t0, t1;
72
+ return $[0] !== handleAuthCallback2 ? (t0 = () => {
158
73
  const url = new URL(location.href);
159
- handleAuthCallback2(url.toString()).then(_temp$8);
160
- }, t2 = [handleAuthCallback2], $[0] = handleAuthCallback2, $[1] = t1, $[2] = t2) : (t1 = $[1], t2 = $[2]), useEffect(t1, t2);
161
- let t3;
162
- $[3] === Symbol.for("react.memo_cache_sentinel") ? (t3 = /* @__PURE__ */ jsxs("div", { className: "sc-login-callback", children: [
163
- /* @__PURE__ */ jsx("h1", { className: "sc-login-callback__title", children: "Logging you in\u2026" }),
164
- /* @__PURE__ */ jsx("div", { className: "sc-login-callback__loading", children: "Loading\u2026" })
165
- ] }), $[3] = t3) : t3 = $[3];
166
- let t4;
167
- return $[4] !== footer || $[5] !== header ? (t4 = /* @__PURE__ */ jsx(LoginLayout, { header, footer, children: t3 }), $[4] = footer, $[5] = header, $[6] = t4) : t4 = $[6], t4;
74
+ handleAuthCallback2(url.toString()).then(_temp$7);
75
+ }, t1 = [handleAuthCallback2], $[0] = handleAuthCallback2, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), useEffect(t0, t1), null;
168
76
  }
169
- function _temp$8(replacementLocation) {
77
+ function _temp$7(replacementLocation) {
170
78
  replacementLocation && history.replaceState(null, "", replacementLocation);
171
79
  }
172
80
  const useLogOut = createCallbackHook(logout);
173
81
  function LoginError(t0) {
174
- const $ = c(10), {
82
+ const $ = c(6), {
175
83
  error,
176
- resetErrorBoundary,
177
- header,
178
- footer
84
+ resetErrorBoundary
179
85
  } = t0;
180
86
  if (!(error instanceof AuthError))
181
87
  throw error;
@@ -191,108 +97,122 @@ function LoginError(t0) {
191
97
  /* @__PURE__ */ jsx("p", { className: "sc-login-error__description", children: "Please try again or contact support if the problem persists." })
192
98
  ] }), $[3] = t2) : t2 = $[3];
193
99
  let t3;
194
- $[4] !== handleRetry ? (t3 = /* @__PURE__ */ jsxs("div", { className: "sc-login-error", children: [
100
+ return $[4] !== handleRetry ? (t3 = /* @__PURE__ */ jsxs("div", { className: "sc-login-error", children: [
195
101
  t2,
196
102
  /* @__PURE__ */ jsx("button", { className: "sc-login-error__button", onClick: handleRetry, children: "Retry" })
197
- ] }), $[4] = handleRetry, $[5] = t3) : t3 = $[5];
198
- let t4;
199
- return $[6] !== footer || $[7] !== header || $[8] !== t3 ? (t4 = /* @__PURE__ */ jsx(LoginLayout, { header, footer, children: t3 }), $[6] = footer, $[7] = header, $[8] = t3, $[9] = t4) : t4 = $[9], t4;
103
+ ] }), $[4] = handleRetry, $[5] = t3) : t3 = $[5], t3;
200
104
  }
201
105
  if (isInIframe()) {
202
106
  const parsedUrl = new URL(window.location.href), mode = new URLSearchParams(parsedUrl.hash.slice(1)).get("mode"), script = document.createElement("script");
203
107
  script.src = mode === "core-ui--staging" ? "https://core.sanity-cdn.work/bridge.js" : "https://core.sanity-cdn.com/bridge.js", script.type = "module", script.async = !0, document.head.appendChild(script);
204
108
  }
205
109
  function AuthBoundary(t0) {
206
- const $ = c(12);
110
+ const $ = c(10);
207
111
  let props, t1;
208
112
  $[0] !== t0 ? ({
209
113
  LoginErrorComponent: t1,
210
114
  ...props
211
115
  } = t0, $[0] = t0, $[1] = props, $[2] = t1) : (props = $[1], t1 = $[2]);
212
- const LoginErrorComponent = t1 === void 0 ? LoginError : t1, {
213
- header,
214
- footer
215
- } = props;
116
+ const LoginErrorComponent = t1 === void 0 ? LoginError : t1;
216
117
  let t2, t3;
217
- $[3] !== LoginErrorComponent || $[4] !== footer || $[5] !== header ? (t3 = function(fallbackProps) {
218
- return /* @__PURE__ */ jsx(LoginErrorComponent, { ...fallbackProps, header, footer });
219
- }, $[3] = LoginErrorComponent, $[4] = footer, $[5] = header, $[6] = t3) : t3 = $[6], t2 = t3;
118
+ $[3] !== LoginErrorComponent ? (t3 = function(fallbackProps) {
119
+ return /* @__PURE__ */ jsx(LoginErrorComponent, { ...fallbackProps });
120
+ }, $[3] = LoginErrorComponent, $[4] = t3) : t3 = $[4], t2 = t3;
220
121
  const FallbackComponent = t2;
221
122
  let t4;
222
- $[7] !== props ? (t4 = /* @__PURE__ */ jsx(AuthSwitch, { ...props }), $[7] = props, $[8] = t4) : t4 = $[8];
123
+ $[5] !== props ? (t4 = /* @__PURE__ */ jsx(AuthSwitch, { ...props }), $[5] = props, $[6] = t4) : t4 = $[6];
223
124
  let t5;
224
- return $[9] !== FallbackComponent || $[10] !== t4 ? (t5 = /* @__PURE__ */ jsx(ErrorBoundary, { FallbackComponent, children: t4 }), $[9] = FallbackComponent, $[10] = t4, $[11] = t5) : t5 = $[11], t5;
125
+ return $[7] !== FallbackComponent || $[8] !== t4 ? (t5 = /* @__PURE__ */ jsx(ErrorBoundary, { FallbackComponent, children: t4 }), $[7] = FallbackComponent, $[8] = t4, $[9] = t5) : t5 = $[9], t5;
225
126
  }
226
127
  function AuthSwitch(t0) {
227
128
  const $ = c(11);
228
- let children, props, t1, t2;
129
+ let children, props, t1;
229
130
  $[0] !== t0 ? ({
230
- LoginComponent: t1,
231
- CallbackComponent: t2,
131
+ CallbackComponent: t1,
232
132
  children,
233
133
  ...props
234
- } = t0, $[0] = t0, $[1] = children, $[2] = props, $[3] = t1, $[4] = t2) : (children = $[1], props = $[2], t1 = $[3], t2 = $[4]);
235
- const LoginComponent = t1 === void 0 ? Login : t1, CallbackComponent = t2 === void 0 ? LoginCallback : t2, authState = useAuthState();
236
- switch (authState.type) {
134
+ } = t0, $[0] = t0, $[1] = children, $[2] = props, $[3] = t1) : (children = $[1], props = $[2], t1 = $[3]);
135
+ const CallbackComponent = t1 === void 0 ? LoginCallback : t1, authState = useAuthState(), isLoggedOut = authState.type === AuthStateType.LOGGED_OUT && !authState.isDestroyingSession, loginUrl = useLoginUrl();
136
+ let t2, t3;
137
+ switch ($[4] !== isLoggedOut || $[5] !== loginUrl ? (t2 = () => {
138
+ isLoggedOut && (window.location.href = loginUrl);
139
+ }, t3 = [isLoggedOut, loginUrl], $[4] = isLoggedOut, $[5] = loginUrl, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]), useEffect(t2, t3), authState.type) {
237
140
  case AuthStateType.ERROR:
238
141
  throw new AuthError(authState.error);
239
142
  case AuthStateType.LOGGING_IN: {
240
- let t3;
241
- return $[5] !== CallbackComponent || $[6] !== props ? (t3 = /* @__PURE__ */ jsx(CallbackComponent, { ...props }), $[5] = CallbackComponent, $[6] = props, $[7] = t3) : t3 = $[7], t3;
143
+ let t4;
144
+ return $[8] !== CallbackComponent || $[9] !== props ? (t4 = /* @__PURE__ */ jsx(CallbackComponent, { ...props }), $[8] = CallbackComponent, $[9] = props, $[10] = t4) : t4 = $[10], t4;
242
145
  }
243
146
  case AuthStateType.LOGGED_IN:
244
147
  return children;
245
- default: {
246
- let t3;
247
- return $[8] !== LoginComponent || $[9] !== props ? (t3 = /* @__PURE__ */ jsx(LoginComponent, { ...props }), $[8] = LoginComponent, $[9] = props, $[10] = t3) : t3 = $[10], t3;
248
- }
148
+ case AuthStateType.LOGGED_OUT:
149
+ return null;
150
+ default:
151
+ throw new Error(`Invalid auth state: ${authState.type}`);
249
152
  }
250
153
  }
251
- const SanityProvider = (t0) => {
252
- const $ = c(3), {
253
- children,
254
- sanityInstances
255
- } = t0;
256
- let t1;
257
- return $[0] !== children || $[1] !== sanityInstances ? (t1 = /* @__PURE__ */ jsx(SanityInstanceContext.Provider, { value: sanityInstances, children }), $[0] = children, $[1] = sanityInstances, $[2] = t1) : t1 = $[2], t1;
258
- }, DEFAULT_FALLBACK = /* @__PURE__ */ jsx(Fragment$1, { children: "Warning: No fallback provided. Please supply a fallback prop to ensure proper Suspense handling." });
259
- function SDKProvider(t0) {
260
- const $ = c(10), {
154
+ const DEFAULT_FALLBACK = /* @__PURE__ */ jsx(Fragment, { children: "Warning: No fallback provided. Please supply a fallback prop to ensure proper Suspense handling." });
155
+ function ResourceProvider(t0) {
156
+ const $ = c(16);
157
+ let children, config, fallback;
158
+ $[0] !== t0 ? ({
261
159
  children,
262
- sanityConfigs,
263
- fallback
264
- } = t0;
160
+ fallback,
161
+ ...config
162
+ } = t0, $[0] = t0, $[1] = children, $[2] = config, $[3] = fallback) : (children = $[1], config = $[2], fallback = $[3]);
163
+ const parent = use(SanityInstanceContext);
265
164
  let t1, t2;
266
- $[0] !== sanityConfigs ? (t2 = sanityConfigs.map(_temp$7), $[0] = sanityConfigs, $[1] = t2) : t2 = $[1], t1 = t2;
267
- const sanityInstances = t1, t3 = fallback ?? DEFAULT_FALLBACK;
268
- let t4;
269
- $[2] !== children ? (t4 = /* @__PURE__ */ jsx(AuthBoundary, { children }), $[2] = children, $[3] = t4) : t4 = $[3];
270
- let t5;
271
- $[4] !== t3 || $[5] !== t4 ? (t5 = /* @__PURE__ */ jsx(Suspense, { fallback: t3, children: t4 }), $[4] = t3, $[5] = t4, $[6] = t5) : t5 = $[6];
165
+ $[4] !== config || $[5] !== parent ? (t2 = parent ? parent.createChild(config) : createSanityInstance(config), $[4] = config, $[5] = parent, $[6] = t2) : t2 = $[6], t1 = t2;
166
+ const instance = t1, disposal = useRef(null);
167
+ let t3, t4;
168
+ $[7] !== instance ? (t3 = () => (disposal.current !== null && instance === disposal.current.instance && (clearTimeout(disposal.current.timeoutId), disposal.current = null), () => {
169
+ disposal.current = {
170
+ instance,
171
+ timeoutId: setTimeout(() => {
172
+ instance.isDisposed() || instance.dispose();
173
+ }, 0)
174
+ };
175
+ }), t4 = [instance], $[7] = instance, $[8] = t3, $[9] = t4) : (t3 = $[8], t4 = $[9]), useEffect(t3, t4);
176
+ const t5 = fallback ?? DEFAULT_FALLBACK;
272
177
  let t6;
273
- return $[7] !== sanityInstances || $[8] !== t5 ? (t6 = /* @__PURE__ */ jsx(SanityProvider, { sanityInstances, children: t5 }), $[7] = sanityInstances, $[8] = t5, $[9] = t6) : t6 = $[9], t6;
178
+ $[10] !== children || $[11] !== t5 ? (t6 = /* @__PURE__ */ jsx(Suspense, { fallback: t5, children }), $[10] = children, $[11] = t5, $[12] = t6) : t6 = $[12];
179
+ let t7;
180
+ return $[13] !== instance || $[14] !== t6 ? (t7 = /* @__PURE__ */ jsx(SanityInstanceContext.Provider, { value: instance, children: t6 }), $[13] = instance, $[14] = t6, $[15] = t7) : t7 = $[15], t7;
274
181
  }
275
- function _temp$7(sanityConfig) {
276
- return createSanityInstance(sanityConfig);
182
+ function SDKProvider({
183
+ children,
184
+ config,
185
+ fallback,
186
+ ...props
187
+ }) {
188
+ 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) });
189
+ return createNestedProviders(0);
277
190
  }
278
- const CORE_URL = "https://core.sanity.io";
191
+ const REDIRECT_URL = "https://sanity.io/welcome";
279
192
  function SanityApp(t0) {
280
- const $ = c(6), {
281
- sanityConfigs,
193
+ const $ = c(15);
194
+ let children, config, fallback, props, sanityConfigs;
195
+ $[0] !== t0 ? ({
282
196
  children,
283
- fallback
284
- } = t0;
197
+ fallback,
198
+ config,
199
+ sanityConfigs,
200
+ ...props
201
+ } = t0, $[0] = t0, $[1] = children, $[2] = config, $[3] = fallback, $[4] = props, $[5] = sanityConfigs) : (children = $[1], config = $[2], fallback = $[3], props = $[4], sanityConfigs = $[5]);
285
202
  let t1;
286
- $[0] !== sanityConfigs ? (t1 = [sanityConfigs], $[0] = sanityConfigs, $[1] = t1) : t1 = $[1], useEffect(_temp2$3, t1);
203
+ $[6] !== config || $[7] !== sanityConfigs ? (t1 = config ?? sanityConfigs ?? [], $[6] = config, $[7] = sanityConfigs, $[8] = t1) : t1 = $[8];
204
+ const configs = t1;
287
205
  let t2;
288
- return $[2] !== children || $[3] !== fallback || $[4] !== sanityConfigs ? (t2 = /* @__PURE__ */ jsx(SDKProvider, { sanityConfigs, fallback, children }), $[2] = children, $[3] = fallback, $[4] = sanityConfigs, $[5] = t2) : t2 = $[5], t2;
206
+ $[9] === Symbol.for("react.memo_cache_sentinel") ? (t2 = [], $[9] = t2) : t2 = $[9], useEffect(_temp2$2, t2);
207
+ let t3;
208
+ 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;
289
209
  }
290
- function _temp2$3() {
210
+ function _temp2$2() {
291
211
  let timeout;
292
212
  return !isInIframe() && !isLocalUrl(window) && (timeout = setTimeout(_temp$6, 1e3)), () => clearTimeout(timeout);
293
213
  }
294
214
  function _temp$6() {
295
- console.warn("Redirecting to core", CORE_URL), window.location.replace(CORE_URL);
215
+ console.warn("Redirecting to core", REDIRECT_URL), window.location.replace(REDIRECT_URL);
296
216
  }
297
217
  const useAuthToken = createStateSourceHook(getTokenState), useCurrentUser = createStateSourceHook(getCurrentUserState);
298
218
  function useDashboardOrganizationId() {
@@ -307,7 +227,7 @@ function useDashboardOrganizationId() {
307
227
  }
308
228
  const useClient = createStateSourceHook({
309
229
  getState: getClientState,
310
- getResourceId: (e) => e.resourceId
230
+ getConfig: identity
311
231
  });
312
232
  function useFrameConnection(options) {
313
233
  const $ = c(12), {
@@ -405,12 +325,15 @@ function _temp$4(unsubscribe) {
405
325
  return unsubscribe();
406
326
  }
407
327
  function useManageFavorite(t0) {
408
- const $ = c(16), {
328
+ const $ = c(23), {
409
329
  documentId,
410
330
  documentType,
411
- resourceId,
412
- resourceType
413
- } = t0, [isFavorited, setIsFavorited] = useState(!1), [status, setStatus] = useState("idle");
331
+ projectId: paramProjectId,
332
+ dataset: paramDataset,
333
+ resourceId: paramResourceId,
334
+ resourceType,
335
+ schemaName
336
+ } = t0, [isFavorited, setIsFavorited] = useState(!1), [status, setStatus] = useState("idle"), [resourceId, setResourceId] = useState(paramResourceId || "");
414
337
  let t1;
415
338
  $[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = {
416
339
  name: SDK_NODE_NAME,
@@ -419,53 +342,70 @@ function useManageFavorite(t0) {
419
342
  }, $[0] = t1) : t1 = $[0];
420
343
  const {
421
344
  sendMessage
422
- } = useWindowConnection(t1);
423
- if (resourceType !== "studio" && !resourceId)
424
- throw new Error("resourceId is required for media-library and canvas resources");
425
- let t2;
426
- $[1] !== documentId || $[2] !== documentType || $[3] !== resourceId || $[4] !== resourceType || $[5] !== sendMessage ? (t2 = (action, setFavoriteState) => {
345
+ } = useWindowConnection(t1), instance = useSanityInstance(), {
346
+ config
347
+ } = instance, instanceProjectId = config?.projectId, instanceDataset = config?.dataset, projectId = paramProjectId ?? instanceProjectId, dataset = paramDataset ?? instanceDataset;
348
+ if (resourceType === "studio" && (!projectId || !dataset))
349
+ throw new Error("projectId and dataset are required for studio resources");
350
+ let t2, t3;
351
+ $[1] !== dataset || $[2] !== paramResourceId || $[3] !== projectId || $[4] !== resourceType ? (t2 = () => {
352
+ if (resourceType === "studio" && !paramResourceId)
353
+ setResourceId(`${projectId}.${dataset}`);
354
+ else if (paramResourceId)
355
+ setResourceId(paramResourceId);
356
+ else
357
+ throw new Error("resourceId is required for media-library and canvas resources");
358
+ }, t3 = [resourceType, paramResourceId, projectId, dataset], $[1] = dataset, $[2] = paramResourceId, $[3] = projectId, $[4] = resourceType, $[5] = t2, $[6] = t3) : (t2 = $[5], t3 = $[6]), useEffect(t2, t3);
359
+ let t4;
360
+ $[7] !== documentId || $[8] !== documentType || $[9] !== resourceId || $[10] !== resourceType || $[11] !== schemaName || $[12] !== sendMessage ? (t4 = (action, setFavoriteState) => {
427
361
  if (!(!documentId || !documentType || !resourceType))
428
362
  try {
429
363
  const message = {
430
364
  type: "dashboard/v1/events/favorite/mutate",
431
365
  data: {
432
366
  eventType: action,
433
- documentId,
434
- documentType,
435
- resourceType,
436
- resourceId
367
+ document: {
368
+ id: documentId,
369
+ type: documentType,
370
+ resource: {
371
+ id: resourceId,
372
+ type: resourceType,
373
+ schemaName
374
+ }
375
+ }
437
376
  },
438
377
  response: {
439
378
  success: !0
440
379
  }
441
380
  };
442
381
  sendMessage(message.type, message.data), setIsFavorited(setFavoriteState);
443
- } catch (t32) {
444
- const err = t32, error = err instanceof Error ? err : new Error("Failed to update favorite status");
382
+ } catch (t52) {
383
+ const err = t52, error = err instanceof Error ? err : new Error("Failed to update favorite status");
445
384
  throw console.error(`Failed to ${action === "added" ? "favorite" : "unfavorite"} document:`, error), error;
446
385
  }
447
- }, $[1] = documentId, $[2] = documentType, $[3] = resourceId, $[4] = resourceType, $[5] = sendMessage, $[6] = t2) : t2 = $[6];
448
- const handleFavoriteAction = t2;
449
- let t3;
450
- $[7] !== handleFavoriteAction ? (t3 = () => handleFavoriteAction("added", !0), $[7] = handleFavoriteAction, $[8] = t3) : t3 = $[8];
451
- const favorite = t3;
452
- let t4;
453
- $[9] !== handleFavoriteAction ? (t4 = () => handleFavoriteAction("removed", !1), $[9] = handleFavoriteAction, $[10] = t4) : t4 = $[10];
454
- const unfavorite = t4, t5 = status === "connected";
386
+ }, $[7] = documentId, $[8] = documentType, $[9] = resourceId, $[10] = resourceType, $[11] = schemaName, $[12] = sendMessage, $[13] = t4) : t4 = $[13];
387
+ const handleFavoriteAction = t4;
388
+ let t5;
389
+ $[14] !== handleFavoriteAction ? (t5 = () => handleFavoriteAction("added", !0), $[14] = handleFavoriteAction, $[15] = t5) : t5 = $[15];
390
+ const favorite = t5;
455
391
  let t6;
456
- return $[11] !== favorite || $[12] !== isFavorited || $[13] !== t5 || $[14] !== unfavorite ? (t6 = {
392
+ $[16] !== handleFavoriteAction ? (t6 = () => handleFavoriteAction("removed", !1), $[16] = handleFavoriteAction, $[17] = t6) : t6 = $[17];
393
+ const unfavorite = t6, t7 = status === "connected";
394
+ let t8;
395
+ return $[18] !== favorite || $[19] !== isFavorited || $[20] !== t7 || $[21] !== unfavorite ? (t8 = {
457
396
  favorite,
458
397
  unfavorite,
459
398
  isFavorited,
460
- isConnected: t5
461
- }, $[11] = favorite, $[12] = isFavorited, $[13] = t5, $[14] = unfavorite, $[15] = t6) : t6 = $[15], t6;
399
+ isConnected: t7
400
+ }, $[18] = favorite, $[19] = isFavorited, $[20] = t7, $[21] = unfavorite, $[22] = t8) : t8 = $[22], t8;
462
401
  }
463
402
  function useRecordDocumentHistoryEvent(t0) {
464
- const $ = c(10), {
403
+ const $ = c(11), {
465
404
  documentId,
466
405
  documentType,
467
406
  resourceType,
468
- resourceId
407
+ resourceId,
408
+ schemaName
469
409
  } = t0, [status, setStatus] = useState("idle");
470
410
  let t1;
471
411
  $[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = {
@@ -479,16 +419,21 @@ function useRecordDocumentHistoryEvent(t0) {
479
419
  if (resourceType !== "studio" && !resourceId)
480
420
  throw new Error("resourceId is required for media-library and canvas resources");
481
421
  let t2;
482
- $[1] !== documentId || $[2] !== documentType || $[3] !== resourceId || $[4] !== resourceType || $[5] !== sendMessage ? (t2 = (eventType) => {
422
+ $[1] !== documentId || $[2] !== documentType || $[3] !== resourceId || $[4] !== resourceType || $[5] !== schemaName || $[6] !== sendMessage ? (t2 = (eventType) => {
483
423
  try {
484
424
  const message = {
485
425
  type: "dashboard/v1/events/history",
486
426
  data: {
487
427
  eventType,
488
- documentId,
489
- documentType,
490
- resourceType,
491
- resourceId
428
+ document: {
429
+ id: documentId,
430
+ type: documentType,
431
+ resource: {
432
+ id: resourceId,
433
+ type: resourceType,
434
+ schemaName
435
+ }
436
+ }
492
437
  }
493
438
  };
494
439
  sendMessage(message.type, message.data);
@@ -496,19 +441,19 @@ function useRecordDocumentHistoryEvent(t0) {
496
441
  const error = t32;
497
442
  throw console.error("Failed to record history event:", error), error;
498
443
  }
499
- }, $[1] = documentId, $[2] = documentType, $[3] = resourceId, $[4] = resourceType, $[5] = sendMessage, $[6] = t2) : t2 = $[6];
444
+ }, $[1] = documentId, $[2] = documentType, $[3] = resourceId, $[4] = resourceType, $[5] = schemaName, $[6] = sendMessage, $[7] = t2) : t2 = $[7];
500
445
  const recordEvent = t2, t3 = status === "connected";
501
446
  let t4;
502
- return $[7] !== recordEvent || $[8] !== t3 ? (t4 = {
447
+ return $[8] !== recordEvent || $[9] !== t3 ? (t4 = {
503
448
  recordEvent,
504
449
  isConnected: t3
505
- }, $[7] = recordEvent, $[8] = t3, $[9] = t4) : t4 = $[9], t4;
450
+ }, $[8] = recordEvent, $[9] = t3, $[10] = t4) : t4 = $[10], t4;
506
451
  }
507
- function useStudioWorkspacesByResourceId() {
452
+ function useStudioWorkspacesByProjectIdDataset() {
508
453
  const $ = c(10);
509
454
  let t0;
510
455
  $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = {}, $[0] = t0) : t0 = $[0];
511
- const [workspacesByResourceId, setWorkspacesByResourceId] = useState(t0), [status, setStatus] = useState("idle"), [error, setError] = useState(null);
456
+ const [workspacesByProjectIdAndDataset, setWorkspacesByProjectIdAndDataset] = useState(t0), [status, setStatus] = useState("idle"), [error, setError] = useState(null);
512
457
  let t1;
513
458
  $[1] === Symbol.for("react.memo_cache_sentinel") ? (t1 = {
514
459
  name: SDK_NODE_NAME,
@@ -532,7 +477,7 @@ function useStudioWorkspacesByResourceId() {
532
477
  const key = `${resource.projectId}:${workspace.dataset}`;
533
478
  workspaceMap[key] || (workspaceMap[key] = []), workspaceMap[key].push(workspace);
534
479
  });
535
- }), setWorkspacesByResourceId(workspaceMap), setError(null);
480
+ }), setWorkspacesByProjectIdAndDataset(workspaceMap), setError(null);
536
481
  } catch (t42) {
537
482
  const err = t42;
538
483
  if (err instanceof Error) {
@@ -548,17 +493,17 @@ function useStudioWorkspacesByResourceId() {
548
493
  }, t3 = [fetch, status], $[2] = fetch, $[3] = status, $[4] = t2, $[5] = t3) : (t2 = $[4], t3 = $[5]), useEffect(t2, t3);
549
494
  const t4 = status === "connected";
550
495
  let t5;
551
- return $[6] !== error || $[7] !== t4 || $[8] !== workspacesByResourceId ? (t5 = {
552
- workspacesByResourceId,
496
+ return $[6] !== error || $[7] !== t4 || $[8] !== workspacesByProjectIdAndDataset ? (t5 = {
497
+ workspacesByProjectIdAndDataset,
553
498
  error,
554
499
  isConnected: t4
555
- }, $[6] = error, $[7] = t4, $[8] = workspacesByResourceId, $[9] = t5) : t5 = $[9], t5;
500
+ }, $[6] = error, $[7] = t4, $[8] = workspacesByProjectIdAndDataset, $[9] = t5) : t5 = $[9], t5;
556
501
  }
557
502
  function useNavigateToStudioDocument(documentHandle) {
558
503
  const $ = c(10), {
559
- workspacesByResourceId,
504
+ workspacesByProjectIdAndDataset,
560
505
  isConnected: workspacesConnected
561
- } = useStudioWorkspacesByResourceId(), [status, setStatus] = useState("idle");
506
+ } = useStudioWorkspacesByProjectIdDataset(), [status, setStatus] = useState("idle");
562
507
  let t0;
563
508
  $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = {
564
509
  name: SDK_NODE_NAME,
@@ -569,28 +514,29 @@ function useNavigateToStudioDocument(documentHandle) {
569
514
  sendMessage
570
515
  } = useWindowConnection(t0);
571
516
  let t1;
572
- $[1] !== documentHandle || $[2] !== sendMessage || $[3] !== status || $[4] !== workspacesByResourceId || $[5] !== workspacesConnected ? (t1 = () => {
573
- if (!workspacesConnected || status !== "connected" || !documentHandle.resourceId)
574
- return;
575
- const [, projectAndDataset] = documentHandle.resourceId.split(":"), [projectId, dataset] = projectAndDataset.split(".");
576
- if (!projectId || !dataset)
517
+ $[1] !== documentHandle || $[2] !== sendMessage || $[3] !== status || $[4] !== workspacesByProjectIdAndDataset || $[5] !== workspacesConnected ? (t1 = () => {
518
+ const {
519
+ projectId,
520
+ dataset
521
+ } = documentHandle;
522
+ if (!workspacesConnected || status !== "connected" || !projectId || !dataset)
577
523
  return;
578
- const workspaces = workspacesByResourceId[`${projectId}:${dataset}`];
524
+ const workspaces = workspacesByProjectIdAndDataset[`${projectId}:${dataset}`];
579
525
  if (!workspaces?.length) {
580
- console.warn("No workspace found for document", documentHandle.resourceId);
526
+ console.warn(`No workspace found for document with projectId: ${projectId} and dataset: ${dataset}`);
581
527
  return;
582
528
  }
583
- workspaces.length > 1 && (console.warn("Multiple workspaces found for document", documentHandle.resourceId), console.warn("Using the first one", workspaces[0]));
529
+ workspaces.length > 1 && (console.warn("Multiple workspaces found for document", documentHandle), console.warn("Using the first one", workspaces[0]));
584
530
  const message = {
585
531
  type: "dashboard/v1/bridge/navigate-to-resource",
586
532
  data: {
587
533
  resourceId: workspaces[0]._ref,
588
534
  resourceType: "studio",
589
- path: `/intent/edit/id=${documentHandle._id};type=${documentHandle._type}`
535
+ path: `/intent/edit/id=${documentHandle.documentId};type=${documentHandle.documentType}`
590
536
  }
591
537
  };
592
538
  sendMessage(message.type, message.data);
593
- }, $[1] = documentHandle, $[2] = sendMessage, $[3] = status, $[4] = workspacesByResourceId, $[5] = workspacesConnected, $[6] = t1) : t1 = $[6];
539
+ }, $[1] = documentHandle, $[2] = sendMessage, $[3] = status, $[4] = workspacesByProjectIdAndDataset, $[5] = workspacesConnected, $[6] = t1) : t1 = $[6];
594
540
  const navigateToStudioDocument = t1, t2 = workspacesConnected && status === "connected";
595
541
  let t3;
596
542
  return $[7] !== navigateToStudioDocument || $[8] !== t2 ? (t3 = {
@@ -599,126 +545,132 @@ function useNavigateToStudioDocument(documentHandle) {
599
545
  }, $[7] = navigateToStudioDocument, $[8] = t2, $[9] = t3) : t3 = $[9], t3;
600
546
  }
601
547
  const useDatasets = createStateSourceHook({
602
- // remove `undefined` since we're suspending when that is the case
603
548
  getState: getDatasetsState,
604
- shouldSuspend: (instance) => getDatasetsState(instance).getCurrent() === void 0,
605
- suspender: resolveDatasets
606
- });
607
- function useApplyDocumentActions(resourceId) {
608
- return _useApplyDocumentActions(resourceId)();
609
- }
610
- const _useApplyDocumentActions = (resourceId) => createCallbackHook(applyDocumentActions, resourceId);
549
+ shouldSuspend: (instance, projectHandle) => (
550
+ // remove `undefined` since we're suspending when that is the case
551
+ getDatasetsState(instance, projectHandle).getCurrent() === void 0
552
+ ),
553
+ suspender: resolveDatasets,
554
+ getConfig: (projectHandle) => projectHandle
555
+ }), useApplyDocumentActions = createCallbackHook(applyDocumentActions);
611
556
  function useDocument(doc, path) {
612
557
  return _useDocument(doc, path);
613
558
  }
614
559
  const _useDocument = createStateSourceHook({
615
560
  getState: getDocumentState,
616
- shouldSuspend: (instance, doc) => getDocumentState(instance, doc._id).getCurrent() === void 0,
561
+ shouldSuspend: (instance, doc) => getDocumentState(instance, doc).getCurrent() === void 0,
617
562
  suspender: resolveDocument,
618
- getResourceId: (doc) => getResourceId(doc.resourceId)
563
+ getConfig: identity
619
564
  });
620
- function useDocumentEvent(handler, doc) {
621
- const $ = c(8), ref = useRef(handler);
565
+ function useDocumentEvent(handler, dataset) {
566
+ const $ = c(6), ref = useRef(handler);
622
567
  let t0;
623
568
  $[0] !== handler ? (t0 = () => {
624
569
  ref.current = handler;
625
570
  }, $[0] = handler, $[1] = t0) : t0 = $[1], useInsertionEffect(t0);
626
571
  let t1;
627
572
  $[2] === Symbol.for("react.memo_cache_sentinel") ? (t1 = (documentEvent) => ref.current(documentEvent), $[2] = t1) : t1 = $[2];
628
- const stableHandler = t1;
629
- let t2;
630
- $[3] !== doc.resourceId ? (t2 = getResourceId(doc.resourceId), $[3] = doc.resourceId, $[4] = t2) : t2 = $[4];
631
- const instance = useSanityInstance(t2);
632
- let t3, t4;
633
- $[5] !== instance ? (t3 = () => subscribeDocumentEvents(instance, stableHandler), t4 = [instance, stableHandler], $[5] = instance, $[6] = t3, $[7] = t4) : (t3 = $[6], t4 = $[7]), useEffect(t3, t4);
573
+ const stableHandler = t1, instance = useSanityInstance(dataset);
574
+ let t2, t3;
575
+ $[3] !== instance ? (t2 = () => subscribeDocumentEvents(instance, stableHandler), t3 = [instance, stableHandler], $[3] = instance, $[4] = t2, $[5] = t3) : (t2 = $[4], t3 = $[5]), useEffect(t2, t3);
634
576
  }
635
- function useDocumentPermissions(actions) {
636
- const $ = c(5);
637
- if (Array.isArray(actions)) {
638
- const resourceIds = actions.map(_temp$3);
639
- if (new Set(resourceIds).size !== 1)
640
- throw new Error("All actions must have the same resourceId");
641
- }
577
+ function useDocumentPermissions(actionOrActions) {
578
+ const $ = c(13);
642
579
  let t0;
643
- $[0] !== actions ? (t0 = Array.isArray(actions) ? getResourceId(actions[0].resourceId) : getResourceId(actions.resourceId), $[0] = actions, $[1] = t0) : t0 = $[1];
644
- const instance = useSanityInstance(t0);
645
- if (getPermissionsState(instance, actions).getCurrent() === void 0)
646
- throw firstValueFrom(getPermissionsState(instance, actions).observable.pipe(filter(_temp2$2)));
647
- let t1, t2;
648
- $[2] !== actions || $[3] !== instance ? (t2 = getPermissionsState(instance, actions), $[2] = actions, $[3] = instance, $[4] = t2) : t2 = $[4], t1 = t2;
580
+ $[0] !== actionOrActions ? (t0 = Array.isArray(actionOrActions) ? actionOrActions : [actionOrActions], $[0] = actionOrActions, $[1] = t0) : t0 = $[1];
581
+ const actions = t0;
582
+ let projectId, dataset;
583
+ if ($[2] !== actions || $[3] !== dataset || $[4] !== projectId) {
584
+ for (const action of actions)
585
+ if (action.projectId) {
586
+ if (projectId || (projectId = action.projectId), action.projectId !== projectId)
587
+ throw new Error(`Mismatched project IDs found in actions. All actions must belong to the same project. Found "${action.projectId}" but expected "${projectId}".`);
588
+ if (action.dataset && (dataset || (dataset = action.dataset), action.dataset !== dataset))
589
+ throw new Error(`Mismatched datasets found in actions. All actions must belong to the same dataset. Found "${action.dataset}" but expected "${dataset}".`);
590
+ }
591
+ $[2] = actions, $[3] = dataset, $[4] = projectId, $[5] = projectId, $[6] = dataset;
592
+ } else
593
+ projectId = $[5], dataset = $[6];
594
+ let t1;
595
+ $[7] !== dataset || $[8] !== projectId ? (t1 = {
596
+ projectId,
597
+ dataset
598
+ }, $[7] = dataset, $[8] = projectId, $[9] = t1) : t1 = $[9];
599
+ const instance = useSanityInstance(t1);
600
+ if (getPermissionsState(instance, actionOrActions).getCurrent() === void 0)
601
+ throw firstValueFrom(getPermissionsState(instance, actionOrActions).observable.pipe(filter(_temp$3)));
602
+ let t2, t3;
603
+ $[10] !== actionOrActions || $[11] !== instance ? (t3 = getPermissionsState(instance, actionOrActions), $[10] = actionOrActions, $[11] = instance, $[12] = t3) : t3 = $[12], t2 = t3;
649
604
  const {
650
605
  subscribe,
651
606
  getCurrent
652
- } = t1;
607
+ } = t2;
653
608
  return useSyncExternalStore(subscribe, getCurrent);
654
609
  }
655
- function _temp2$2(result) {
610
+ function _temp$3(result) {
656
611
  return result !== void 0;
657
612
  }
658
- function _temp$3(action) {
659
- return action.resourceId;
660
- }
661
613
  const useDocumentSyncStatus = createStateSourceHook(getDocumentSyncStatus), ignoredKeys = ["_id", "_type", "_createdAt", "_updatedAt", "_rev"];
662
- function useEditDocument(doc, path) {
663
- const $ = c(8);
614
+ function useEditDocument(docHandle, path) {
615
+ const $ = c(5), instance = useSanityInstance(docHandle), apply = useApplyDocumentActions();
616
+ if (getDocumentState(instance, docHandle).getCurrent() === void 0)
617
+ throw resolveDocument(instance, docHandle);
664
618
  let t0;
665
- $[0] !== doc.resourceId ? (t0 = getResourceId(doc.resourceId), $[0] = doc.resourceId, $[1] = t0) : t0 = $[1];
666
- const resourceId = t0, documentId = doc._id, instance = useSanityInstance(resourceId), apply = useApplyDocumentActions(resourceId);
667
- if (getDocumentState(instance, documentId).getCurrent() === void 0)
668
- throw resolveDocument(instance, documentId);
669
- let t1;
670
- return $[2] !== apply || $[3] !== doc || $[4] !== documentId || $[5] !== instance || $[6] !== path ? (t1 = (updater) => {
619
+ return $[0] !== apply || $[1] !== docHandle || $[2] !== instance || $[3] !== path ? (t0 = (updater) => {
671
620
  if (path) {
672
- const nextValue = typeof updater == "function" ? updater(getDocumentState(instance, documentId, path).getCurrent()) : updater;
673
- return apply(editDocument(doc, {
621
+ const nextValue = typeof updater == "function" ? updater(getDocumentState(instance, docHandle, path).getCurrent()) : updater;
622
+ return apply(editDocument(docHandle, {
674
623
  set: {
675
624
  [path]: nextValue
676
625
  }
677
626
  }));
678
627
  }
679
- const current = getDocumentState(instance, documentId).getCurrent(), nextValue_0 = typeof updater == "function" ? updater(current) : updater;
628
+ const current = getDocumentState(instance, docHandle).getCurrent(), nextValue_0 = typeof updater == "function" ? updater(current) : updater;
680
629
  if (typeof nextValue_0 != "object" || !nextValue_0)
681
630
  throw new Error("No path was provided to `useEditDocument` and the value provided was not a document object.");
682
631
  const editActions = Object.keys({
683
632
  ...current,
684
633
  ...nextValue_0
685
- }).filter(_temp$2).filter((key_0) => current?.[key_0] !== nextValue_0[key_0]).map((key_1) => key_1 in nextValue_0 ? editDocument(doc, {
634
+ }).filter(_temp$2).filter((key_0) => current?.[key_0] !== nextValue_0[key_0]).map((key_1) => key_1 in nextValue_0 ? editDocument(docHandle, {
686
635
  set: {
687
636
  [key_1]: nextValue_0[key_1]
688
637
  }
689
- }) : editDocument(doc, {
638
+ }) : editDocument(docHandle, {
690
639
  unset: [key_1]
691
640
  }));
692
641
  return apply(editActions);
693
- }, $[2] = apply, $[3] = doc, $[4] = documentId, $[5] = instance, $[6] = path, $[7] = t1) : t1 = $[7], t1;
642
+ }, $[0] = apply, $[1] = docHandle, $[2] = instance, $[3] = path, $[4] = t0) : t0 = $[4], t0;
694
643
  }
695
644
  function _temp$2(key) {
696
645
  return !ignoredKeys.includes(key);
697
646
  }
698
647
  function useQuery(query, options) {
699
- const instance = useSanityInstance(options?.resourceId), [isPending, startTransition] = useTransition(), queryKey = getQueryKey(query, options), [deferredQueryKey, setDeferredQueryKey] = useState(queryKey), deferred = useMemo(() => parseQueryKey(deferredQueryKey), [deferredQueryKey]), [ref, setRef] = useState(new AbortController());
648
+ const instance = useSanityInstance(options), [isPending, startTransition] = useTransition(), queryKey = getQueryKey(query, options), [deferredQueryKey, setDeferredQueryKey] = useState(queryKey), deferred = useMemo(() => parseQueryKey(deferredQueryKey), [deferredQueryKey]), ref = useRef(new AbortController());
700
649
  useEffect(() => {
701
650
  queryKey !== deferredQueryKey && startTransition(() => {
702
- ref && !ref.signal.aborted && (ref.abort(), setRef(new AbortController())), setDeferredQueryKey(queryKey);
651
+ ref && !ref.current.signal.aborted && (ref.current.abort(), ref.current = new AbortController()), setDeferredQueryKey(queryKey);
703
652
  });
704
- }, [deferredQueryKey, queryKey, ref]);
653
+ }, [deferredQueryKey, queryKey]);
705
654
  const {
706
655
  getCurrent,
707
656
  subscribe
708
657
  } = useMemo(() => getQueryState(instance, deferred.query, deferred.options), [instance, deferred]);
709
- if (getCurrent() === void 0)
658
+ if (getCurrent() === void 0) {
659
+ const currentSignal = ref.current.signal;
710
660
  throw resolveQuery(instance, deferred.query, {
711
661
  ...deferred.options,
712
- signal: ref.signal
662
+ signal: currentSignal
713
663
  });
714
- return {
715
- data: useSyncExternalStore(subscribe, getCurrent),
664
+ }
665
+ const data = useSyncExternalStore(subscribe, getCurrent);
666
+ return useMemo(() => ({
667
+ data,
716
668
  isPending
717
- };
669
+ }), [data, isPending]);
718
670
  }
719
671
  const DEFAULT_BATCH_SIZE = 25, DEFAULT_PERSPECTIVE$1 = "drafts";
720
672
  function useDocuments(t0) {
721
- const $ = c(31);
673
+ const $ = c(36);
722
674
  let filter2, options, orderings, params, search, t1;
723
675
  $[0] !== t0 ? ({
724
676
  batchSize: t1,
@@ -728,7 +680,7 @@ function useDocuments(t0) {
728
680
  orderings,
729
681
  ...options
730
682
  } = 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]);
731
- const batchSize = t1 === void 0 ? DEFAULT_BATCH_SIZE : t1, perspective = options.perspective ?? DEFAULT_PERSPECTIVE$1, [limit, setLimit] = useState(batchSize);
683
+ const batchSize = t1 === void 0 ? DEFAULT_BATCH_SIZE : t1, instance = useSanityInstance(options), perspective = options.perspective ?? DEFAULT_PERSPECTIVE$1, [limit, setLimit] = useState(batchSize);
732
684
  let t2;
733
685
  $[7] !== batchSize || $[8] !== filter2 || $[9] !== orderings || $[10] !== params || $[11] !== search ? (t2 = JSON.stringify({
734
686
  filter: filter2,
@@ -745,35 +697,46 @@ function useDocuments(t0) {
745
697
  let t4;
746
698
  $[15] !== batchSize || $[16] !== key ? (t4 = [key, batchSize], $[15] = batchSize, $[16] = key, $[17] = t4) : t4 = $[17], useEffect(t3, t4);
747
699
  let t5;
748
- const conditions = [];
749
- search?.trim() && conditions.push(`[@] match text::query("${search.trim()}")`), filter2 && conditions.push(`(${filter2})`), t5 = conditions.length ? `[${conditions.join(" && ")}]` : "";
750
- const filterClause = t5, orderClause = orderings ? `| order(${orderings.map(_temp2$1).join(",")})` : "", dataQuery = `*${filterClause}${orderClause}[0...${limit}]{_id,_type}`, countQuery = `count(*${filterClause})`;
700
+ const conditions = [], trimmedSearch = search?.trim();
701
+ if (trimmedSearch) {
702
+ const searchFilter = createGroqSearchFilter(trimmedSearch);
703
+ searchFilter && conditions.push(searchFilter);
704
+ }
705
+ filter2 && conditions.push(`(${filter2})`), t5 = conditions.length ? `[${conditions.join(" && ")}]` : "";
706
+ const filterClause = t5, orderClause = orderings ? `| order(${orderings.map(_temp2$1).join(",")})` : "", dataQuery = `*${filterClause}${orderClause}[0...${limit}]{"documentId":_id,"documentType":_type,...$__dataset}`, countQuery = `count(*${filterClause})`;
751
707
  let t6;
752
- $[18] !== options || $[19] !== params || $[20] !== perspective ? (t6 = {
708
+ $[18] !== instance.config ? (t6 = pick(instance.config, "projectId", "dataset"), $[18] = instance.config, $[19] = t6) : t6 = $[19];
709
+ let t7;
710
+ $[20] !== params || $[21] !== t6 ? (t7 = {
711
+ ...params,
712
+ __dataset: t6
713
+ }, $[20] = params, $[21] = t6, $[22] = t7) : t7 = $[22];
714
+ let t8;
715
+ $[23] !== options || $[24] !== perspective || $[25] !== t7 ? (t8 = {
753
716
  ...options,
754
- params,
717
+ params: t7,
755
718
  perspective
756
- }, $[18] = options, $[19] = params, $[20] = perspective, $[21] = t6) : t6 = $[21];
719
+ }, $[23] = options, $[24] = perspective, $[25] = t7, $[26] = t8) : t8 = $[26];
757
720
  const {
758
- data: t7,
721
+ data: t9,
759
722
  isPending
760
- } = useQuery(`{"count":${countQuery},"data":${dataQuery}}`, t6), {
723
+ } = useQuery(`{"count":${countQuery},"data":${dataQuery}}`, t8), {
761
724
  count,
762
725
  data
763
- } = t7, hasMore = data.length < count;
764
- let t8;
765
- $[22] !== batchSize || $[23] !== count ? (t8 = () => {
726
+ } = t9, hasMore = data.length < count;
727
+ let t10;
728
+ $[27] !== batchSize || $[28] !== count ? (t10 = () => {
766
729
  setLimit((prev) => Math.min(prev + batchSize, count));
767
- }, $[22] = batchSize, $[23] = count, $[24] = t8) : t8 = $[24];
768
- const loadMore = t8;
769
- let t9, t10;
770
- return $[25] !== count || $[26] !== data || $[27] !== hasMore || $[28] !== isPending || $[29] !== loadMore ? (t10 = {
730
+ }, $[27] = batchSize, $[28] = count, $[29] = t10) : t10 = $[29];
731
+ const loadMore = t10;
732
+ let t11, t12;
733
+ return $[30] !== count || $[31] !== data || $[32] !== hasMore || $[33] !== isPending || $[34] !== loadMore ? (t12 = {
771
734
  data,
772
735
  hasMore,
773
736
  count,
774
737
  isPending,
775
738
  loadMore
776
- }, $[25] = count, $[26] = data, $[27] = hasMore, $[28] = isPending, $[29] = loadMore, $[30] = t10) : t10 = $[30], t9 = t10, t9;
739
+ }, $[30] = count, $[31] = data, $[32] = hasMore, $[33] = isPending, $[34] = loadMore, $[35] = t12) : t12 = $[35], t11 = t12, t11;
777
740
  }
778
741
  function _temp2$1(ordering) {
779
742
  return [ordering.field, ordering.direction.toLowerCase()].map(_temp$1).filter(Boolean).join(" ");
@@ -783,74 +746,83 @@ function _temp$1(str) {
783
746
  }
784
747
  const DEFAULT_PERSPECTIVE = "drafts";
785
748
  function usePaginatedDocuments(t0) {
786
- const $ = c(48);
787
- let t1;
788
- $[0] !== t0 ? (t1 = t0 === void 0 ? {} : t0, $[0] = t0, $[1] = t1) : t1 = $[1];
789
- let options, orderings, search, t2, t3, t4;
790
- $[2] !== t1 ? ({
791
- filter: t2,
792
- pageSize: t3,
793
- params: t4,
749
+ const $ = c(51);
750
+ let options, orderings, search, t1, t2, t3;
751
+ $[0] !== t0 ? ({
752
+ filter: t1,
753
+ pageSize: t2,
754
+ params: t3,
794
755
  orderings,
795
756
  search,
796
757
  ...options
797
- } = t1, $[2] = t1, $[3] = options, $[4] = orderings, $[5] = search, $[6] = t2, $[7] = t3, $[8] = t4) : (options = $[3], orderings = $[4], search = $[5], t2 = $[6], t3 = $[7], t4 = $[8]);
798
- const filter2 = t2 === void 0 ? "" : t2, pageSize = t3 === void 0 ? 25 : t3;
758
+ } = 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]);
759
+ const filter2 = t1 === void 0 ? "" : t1, pageSize = t2 === void 0 ? 25 : t2;
760
+ let t4;
761
+ $[7] !== t3 ? (t4 = t3 === void 0 ? {} : t3, $[7] = t3, $[8] = t4) : t4 = $[8];
762
+ const params = t4, instance = useSanityInstance(options), [pageIndex, setPageIndex] = useState(0);
799
763
  let t5;
800
- $[9] !== t4 ? (t5 = t4 === void 0 ? {} : t4, $[9] = t4, $[10] = t5) : t5 = $[10];
801
- const params = t5, [pageIndex, setPageIndex] = useState(0);
802
- let t6;
803
- $[11] !== filter2 || $[12] !== orderings || $[13] !== pageSize || $[14] !== params || $[15] !== search ? (t6 = JSON.stringify({
764
+ $[9] !== filter2 || $[10] !== orderings || $[11] !== pageSize || $[12] !== params || $[13] !== search ? (t5 = JSON.stringify({
804
765
  filter: filter2,
805
766
  search,
806
767
  params,
807
768
  orderings,
808
769
  pageSize
809
- }), $[11] = filter2, $[12] = orderings, $[13] = pageSize, $[14] = params, $[15] = search, $[16] = t6) : t6 = $[16];
810
- const key = t6;
811
- let t7;
812
- $[17] === Symbol.for("react.memo_cache_sentinel") ? (t7 = () => {
770
+ }), $[9] = filter2, $[10] = orderings, $[11] = pageSize, $[12] = params, $[13] = search, $[14] = t5) : t5 = $[14];
771
+ const key = t5;
772
+ let t6;
773
+ $[15] === Symbol.for("react.memo_cache_sentinel") ? (t6 = () => {
813
774
  setPageIndex(0);
814
- }, $[17] = t7) : t7 = $[17];
815
- let t8;
816
- $[18] !== key ? (t8 = [key], $[18] = key, $[19] = t8) : t8 = $[19], useEffect(t7, t8);
775
+ }, $[15] = t6) : t6 = $[15];
776
+ let t7;
777
+ $[16] !== key ? (t7 = [key], $[16] = key, $[17] = t7) : t7 = $[17], useEffect(t6, t7);
817
778
  const startIndex = pageIndex * pageSize, endIndex = (pageIndex + 1) * pageSize, perspective = options.perspective ?? DEFAULT_PERSPECTIVE;
779
+ let t8;
780
+ const conditions = [], trimmedSearch = search?.trim();
781
+ if (trimmedSearch) {
782
+ const searchFilter = createGroqSearchFilter(trimmedSearch);
783
+ searchFilter && conditions.push(searchFilter);
784
+ }
785
+ filter2 && conditions.push(`(${filter2})`), t8 = conditions.length ? `[${conditions.join(" && ")}]` : "";
786
+ const filterClause = t8, orderClause = orderings ? `| order(${orderings.map(_temp2).join(",")})` : "", dataQuery = `*${filterClause}${orderClause}[${startIndex}...${endIndex}]{"documentId":_id,"documentType":_type,...$__dataset}`, countQuery = `count(*${filterClause})`;
818
787
  let t9;
819
- const conditions = [];
820
- search?.trim() && conditions.push(`[@] match text::query("${search.trim()}")`), filter2 && conditions.push(`(${filter2})`), t9 = conditions.length ? `[${conditions.join(" && ")}]` : "";
821
- const filterClause = t9, orderClause = orderings ? `| order(${orderings.map(_temp2).join(",")})` : "", dataQuery = `*${filterClause}${orderClause}[${startIndex}...${endIndex}]{_id,_type}`, countQuery = `count(*${filterClause})`;
788
+ $[18] !== instance.config ? (t9 = pick(instance.config, "projectId", "dataset"), $[18] = instance.config, $[19] = t9) : t9 = $[19];
822
789
  let t10;
823
- $[20] !== options || $[21] !== params || $[22] !== perspective ? (t10 = {
790
+ $[20] !== params || $[21] !== t9 ? (t10 = {
791
+ ...params,
792
+ __dataset: t9
793
+ }, $[20] = params, $[21] = t9, $[22] = t10) : t10 = $[22];
794
+ let t11;
795
+ $[23] !== options || $[24] !== perspective || $[25] !== t10 ? (t11 = {
824
796
  ...options,
825
797
  perspective,
826
- params
827
- }, $[20] = options, $[21] = params, $[22] = perspective, $[23] = t10) : t10 = $[23];
798
+ params: t10
799
+ }, $[23] = options, $[24] = perspective, $[25] = t10, $[26] = t11) : t11 = $[26];
828
800
  const {
829
- data: t11,
801
+ data: t12,
830
802
  isPending
831
- } = useQuery(`{"data":${dataQuery},"count":${countQuery}}`, t10), {
803
+ } = useQuery(`{"data":${dataQuery},"count":${countQuery}}`, t11), {
832
804
  data,
833
805
  count
834
- } = t11, totalPages = Math.ceil(count / pageSize), currentPage = pageIndex + 1;
835
- let t12;
836
- $[24] === Symbol.for("react.memo_cache_sentinel") ? (t12 = () => setPageIndex(0), $[24] = t12) : t12 = $[24];
837
- const firstPage = t12;
806
+ } = t12, totalPages = Math.ceil(count / pageSize), currentPage = pageIndex + 1;
838
807
  let t13;
839
- $[25] === Symbol.for("react.memo_cache_sentinel") ? (t13 = () => setPageIndex(_temp3), $[25] = t13) : t13 = $[25];
840
- const previousPage = t13;
808
+ $[27] === Symbol.for("react.memo_cache_sentinel") ? (t13 = () => setPageIndex(0), $[27] = t13) : t13 = $[27];
809
+ const firstPage = t13;
841
810
  let t14;
842
- $[26] !== totalPages ? (t14 = () => setPageIndex((prev_0) => Math.min(prev_0 + 1, totalPages - 1)), $[26] = totalPages, $[27] = t14) : t14 = $[27];
843
- const nextPage = t14;
811
+ $[28] === Symbol.for("react.memo_cache_sentinel") ? (t14 = () => setPageIndex(_temp3), $[28] = t14) : t14 = $[28];
812
+ const previousPage = t14;
844
813
  let t15;
845
- $[28] !== totalPages ? (t15 = () => setPageIndex(totalPages - 1), $[28] = totalPages, $[29] = t15) : t15 = $[29];
846
- const lastPage = t15;
814
+ $[29] !== totalPages ? (t15 = () => setPageIndex((prev_0) => Math.min(prev_0 + 1, totalPages - 1)), $[29] = totalPages, $[30] = t15) : t15 = $[30];
815
+ const nextPage = t15;
847
816
  let t16;
848
- $[30] !== totalPages ? (t16 = (pageNumber) => {
817
+ $[31] !== totalPages ? (t16 = () => setPageIndex(totalPages - 1), $[31] = totalPages, $[32] = t16) : t16 = $[32];
818
+ const lastPage = t16;
819
+ let t17;
820
+ $[33] !== totalPages ? (t17 = (pageNumber) => {
849
821
  pageNumber < 1 || pageNumber > totalPages || setPageIndex(pageNumber - 1);
850
- }, $[30] = totalPages, $[31] = t16) : t16 = $[31];
851
- const goToPage = t16, hasFirstPage = pageIndex > 0, hasPreviousPage = pageIndex > 0, hasNextPage = pageIndex < totalPages - 1, hasLastPage = pageIndex < totalPages - 1;
852
- let t17, t18;
853
- return $[32] !== count || $[33] !== currentPage || $[34] !== data || $[35] !== endIndex || $[36] !== goToPage || $[37] !== hasFirstPage || $[38] !== hasLastPage || $[39] !== hasNextPage || $[40] !== hasPreviousPage || $[41] !== isPending || $[42] !== lastPage || $[43] !== nextPage || $[44] !== pageSize || $[45] !== startIndex || $[46] !== totalPages ? (t18 = {
822
+ }, $[33] = totalPages, $[34] = t17) : t17 = $[34];
823
+ const goToPage = t17, hasFirstPage = pageIndex > 0, hasPreviousPage = pageIndex > 0, hasNextPage = pageIndex < totalPages - 1, hasLastPage = pageIndex < totalPages - 1;
824
+ let t18;
825
+ 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 = {
854
826
  data,
855
827
  isPending,
856
828
  pageSize,
@@ -868,7 +840,7 @@ function usePaginatedDocuments(t0) {
868
840
  lastPage,
869
841
  hasLastPage,
870
842
  goToPage
871
- }, $[32] = count, $[33] = currentPage, $[34] = data, $[35] = endIndex, $[36] = goToPage, $[37] = hasFirstPage, $[38] = hasLastPage, $[39] = hasNextPage, $[40] = hasPreviousPage, $[41] = isPending, $[42] = lastPage, $[43] = nextPage, $[44] = pageSize, $[45] = startIndex, $[46] = totalPages, $[47] = t18) : t18 = $[47], t17 = t18, t17;
843
+ }, $[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;
872
844
  }
873
845
  function _temp3(prev) {
874
846
  return Math.max(prev - 1, 0);
@@ -880,150 +852,126 @@ function _temp(str) {
880
852
  return str.trim();
881
853
  }
882
854
  function usePreview(t0) {
883
- const $ = c(12), {
884
- document: t1,
885
- ref
886
- } = t0, {
887
- _id,
888
- _type
889
- } = t1, instance = useSanityInstance();
890
- let t2, t3;
891
- $[0] !== _id || $[1] !== _type || $[2] !== instance ? (t3 = getPreviewState(instance, {
892
- document: {
893
- _id,
894
- _type
895
- }
896
- }), $[0] = _id, $[1] = _type, $[2] = instance, $[3] = t3) : t3 = $[3], t2 = t3;
897
- const stateSource = t2;
898
- let t4;
899
- $[4] !== ref || $[5] !== stateSource ? (t4 = (onStoreChanged) => {
855
+ const $ = c(13);
856
+ let docHandle, ref;
857
+ $[0] !== t0 ? ({
858
+ ref,
859
+ ...docHandle
860
+ } = t0, $[0] = t0, $[1] = docHandle, $[2] = ref) : (docHandle = $[1], ref = $[2]);
861
+ const instance = useSanityInstance();
862
+ let t1;
863
+ $[3] !== docHandle || $[4] !== instance ? (t1 = getPreviewState(instance, docHandle), $[3] = docHandle, $[4] = instance, $[5] = t1) : t1 = $[5];
864
+ const stateSource = t1;
865
+ let t2;
866
+ $[6] !== ref || $[7] !== stateSource ? (t2 = (onStoreChanged) => {
900
867
  const subscription = new Observable((observer) => {
901
- if (typeof IntersectionObserver > "u" || typeof HTMLElement > "u")
868
+ if (typeof IntersectionObserver > "u" || typeof HTMLElement > "u") {
869
+ observer.next(!0);
902
870
  return;
903
- const intersectionObserver = new IntersectionObserver((t52) => {
904
- const [entry] = t52;
871
+ }
872
+ const intersectionObserver = new IntersectionObserver((t32) => {
873
+ const [entry] = t32;
905
874
  return observer.next(entry.isIntersecting);
906
875
  }, {
907
876
  rootMargin: "0px",
908
877
  threshold: 0
909
878
  });
910
- return ref?.current && ref.current instanceof HTMLElement && intersectionObserver.observe(ref.current), () => intersectionObserver.disconnect();
879
+ return ref?.current && ref.current instanceof HTMLElement ? intersectionObserver.observe(ref.current) : observer.next(!0), () => intersectionObserver.disconnect();
911
880
  }).pipe(startWith(!1), distinctUntilChanged(), switchMap((isVisible) => isVisible ? new Observable((obs) => stateSource.subscribe(() => obs.next())) : EMPTY)).subscribe({
912
881
  next: onStoreChanged
913
882
  });
914
883
  return () => subscription.unsubscribe();
915
- }, $[4] = ref, $[5] = stateSource, $[6] = t4) : t4 = $[6];
916
- const subscribe = t4;
917
- let t5;
918
- return $[7] !== _id || $[8] !== _type || $[9] !== instance || $[10] !== stateSource ? (t5 = () => {
884
+ }, $[6] = ref, $[7] = stateSource, $[8] = t2) : t2 = $[8];
885
+ const subscribe = t2;
886
+ let t3;
887
+ return $[9] !== docHandle || $[10] !== instance || $[11] !== stateSource ? (t3 = () => {
919
888
  const currentState = stateSource.getCurrent();
920
889
  if (currentState.data === null)
921
- throw resolvePreview(instance, {
922
- document: {
923
- _id,
924
- _type
925
- }
926
- });
890
+ throw resolvePreview(instance, docHandle);
927
891
  return currentState;
928
- }, $[7] = _id, $[8] = _type, $[9] = instance, $[10] = stateSource, $[11] = t5) : t5 = $[11], useSyncExternalStore(subscribe, t5);
892
+ }, $[9] = docHandle, $[10] = instance, $[11] = stateSource, $[12] = t3) : t3 = $[12], useSyncExternalStore(subscribe, t3);
929
893
  }
930
894
  function useProjection(t0) {
931
- const $ = c(14), {
932
- document: t1,
895
+ const $ = c(12);
896
+ let docHandle, projection, ref;
897
+ $[0] !== t0 ? ({
898
+ ref,
933
899
  projection,
934
- ref
935
- } = t0, {
936
- _id,
937
- _type
938
- } = t1, instance = useSanityInstance();
939
- let t2, t3;
940
- $[0] !== _id || $[1] !== _type || $[2] !== instance || $[3] !== projection ? (t3 = getProjectionState(instance, {
941
- document: {
942
- _id,
943
- _type
944
- },
900
+ ...docHandle
901
+ } = t0, $[0] = t0, $[1] = docHandle, $[2] = projection, $[3] = ref) : (docHandle = $[1], projection = $[2], ref = $[3]);
902
+ const instance = useSanityInstance();
903
+ let stateSource, t1;
904
+ if ($[4] !== docHandle || $[5] !== instance || $[6] !== projection ? (stateSource = getProjectionState(instance, {
905
+ ...docHandle,
945
906
  projection
946
- }), $[0] = _id, $[1] = _type, $[2] = instance, $[3] = projection, $[4] = t3) : t3 = $[4], t2 = t3;
947
- const stateSource = t2;
948
- let t4;
949
- $[5] !== ref || $[6] !== stateSource ? (t4 = (onStoreChanged) => {
907
+ }), t1 = stateSource.getCurrent(), $[4] = docHandle, $[5] = instance, $[6] = projection, $[7] = stateSource, $[8] = t1) : (stateSource = $[7], t1 = $[8]), t1.data === null)
908
+ throw resolveProjection(instance, {
909
+ ...docHandle,
910
+ projection
911
+ });
912
+ let t2;
913
+ return $[9] !== ref || $[10] !== stateSource ? (t2 = (onStoreChanged) => {
950
914
  const subscription = new Observable((observer) => {
951
- if (typeof IntersectionObserver > "u" || typeof HTMLElement > "u")
915
+ if (typeof IntersectionObserver > "u" || typeof HTMLElement > "u") {
916
+ observer.next(!0);
952
917
  return;
953
- const intersectionObserver = new IntersectionObserver((t52) => {
954
- const [entry] = t52;
918
+ }
919
+ const intersectionObserver = new IntersectionObserver((t3) => {
920
+ const [entry] = t3;
955
921
  return observer.next(entry.isIntersecting);
956
922
  }, {
957
923
  rootMargin: "0px",
958
924
  threshold: 0
959
925
  });
960
- return ref?.current && ref.current instanceof HTMLElement && intersectionObserver.observe(ref.current), () => intersectionObserver.disconnect();
926
+ return ref?.current && ref.current instanceof HTMLElement ? intersectionObserver.observe(ref.current) : observer.next(!0), () => intersectionObserver.disconnect();
961
927
  }).pipe(startWith(!1), distinctUntilChanged(), switchMap((isVisible) => isVisible ? new Observable((obs) => stateSource.subscribe(() => obs.next())) : EMPTY)).subscribe({
962
928
  next: onStoreChanged
963
929
  });
964
930
  return () => subscription.unsubscribe();
965
- }, $[5] = ref, $[6] = stateSource, $[7] = t4) : t4 = $[7];
966
- const subscribe = t4;
967
- let t5;
968
- return $[8] !== _id || $[9] !== _type || $[10] !== instance || $[11] !== projection || $[12] !== stateSource ? (t5 = () => {
969
- const currentState = stateSource.getCurrent();
970
- if (currentState.data === null)
971
- throw resolveProjection(instance, {
972
- document: {
973
- _id,
974
- _type
975
- },
976
- projection
977
- });
978
- return currentState;
979
- }, $[8] = _id, $[9] = _type, $[10] = instance, $[11] = projection, $[12] = stateSource, $[13] = t5) : t5 = $[13], useSyncExternalStore(subscribe, t5);
931
+ }, $[9] = ref, $[10] = stateSource, $[11] = t2) : t2 = $[11], useSyncExternalStore(t2, stateSource.getCurrent);
980
932
  }
981
933
  const useProject = createStateSourceHook({
982
934
  // remove `undefined` since we're suspending when that is the case
983
935
  getState: getProjectState,
984
- shouldSuspend: (instance, projectId) => getProjectState(instance, projectId).getCurrent() === void 0,
985
- suspender: resolveProject
936
+ shouldSuspend: (instance, projectHandle) => getProjectState(instance, projectHandle).getCurrent() === void 0,
937
+ suspender: resolveProject,
938
+ getConfig: identity
986
939
  }), useProjects = createStateSourceHook({
987
940
  // remove `undefined` since we're suspending when that is the case
988
941
  getState: getProjectsState,
989
942
  shouldSuspend: (instance) => getProjectsState(instance).getCurrent() === void 0,
990
943
  suspender: resolveProjects
991
944
  });
992
- function useUsers(params) {
993
- const $ = c(15), instance = useSanityInstance(params.resourceId);
994
- let t0;
995
- $[0] !== instance ? (t0 = () => createUsersStore(instance), $[0] = instance, $[1] = t0) : t0 = $[1];
996
- const [store] = useState(t0);
997
- let t1, t2;
998
- $[2] !== params.resourceId || $[3] !== params.resourceType || $[4] !== store ? (t1 = () => {
999
- store.setOptions({
1000
- resourceType: params.resourceType,
1001
- resourceId: params.resourceId
945
+ function useUsers(options) {
946
+ 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());
947
+ useEffect(() => {
948
+ key !== deferredKey && startTransition(() => {
949
+ ref.signal.aborted || (ref.abort(), setRef(new AbortController())), setDeferredKey(key);
1002
950
  });
1003
- }, t2 = [params.resourceType, params.resourceId, store], $[2] = params.resourceId, $[3] = params.resourceType, $[4] = store, $[5] = t1, $[6] = t2) : (t1 = $[5], t2 = $[6]), useEffect(t1, t2);
1004
- let t3;
1005
- $[7] !== store ? (t3 = (onStoreChanged) => {
1006
- store.getState().getCurrent().initialFetchCompleted === !1 && store.resolveUsers();
1007
- const unsubscribe = store.getState().subscribe(onStoreChanged);
1008
- return () => {
1009
- unsubscribe(), store.dispose();
1010
- };
1011
- }, $[7] = store, $[8] = t3) : t3 = $[8];
1012
- const subscribe = t3;
1013
- let t4;
1014
- $[9] !== store ? (t4 = () => store.getState().getCurrent(), $[9] = store, $[10] = t4) : t4 = $[10];
1015
- const getSnapshot = t4, {
1016
- users,
951
+ }, [deferredKey, key, ref]);
952
+ const {
953
+ getCurrent,
954
+ subscribe
955
+ } = useMemo(() => getUsersState(instance, deferred), [instance, deferred]);
956
+ if (getCurrent() === void 0)
957
+ throw resolveUsers(instance, {
958
+ ...deferred,
959
+ signal: ref.signal
960
+ });
961
+ const {
962
+ data,
1017
963
  hasMore
1018
- } = useSyncExternalStore(subscribe, getSnapshot) || {};
1019
- let t5;
1020
- return $[11] !== hasMore || $[12] !== store.loadMore || $[13] !== users ? (t5 = {
1021
- users,
964
+ } = useSyncExternalStore(subscribe, getCurrent), loadMore = useCallback(() => {
965
+ loadMoreUsers(instance, options);
966
+ }, [instance, options]);
967
+ return {
968
+ data,
1022
969
  hasMore,
1023
- loadMore: store.loadMore
1024
- }, $[11] = hasMore, $[12] = store.loadMore, $[13] = users, $[14] = t5) : t5 = $[14], t5;
970
+ isPending,
971
+ loadMore
972
+ };
1025
973
  }
1026
- var version = "0.0.0-rc.3";
974
+ var version = "0.0.0-rc.4";
1027
975
  function getEnv(key) {
1028
976
  if (typeof import.meta < "u" && import.meta.env)
1029
977
  return import.meta.env[key];
@@ -1036,9 +984,9 @@ const REACT_SDK_VERSION = getEnv("PKG_VERSION") || `${version}-development`;
1036
984
  export {
1037
985
  AuthBoundary,
1038
986
  REACT_SDK_VERSION,
987
+ ResourceProvider,
1039
988
  SDKProvider,
1040
989
  SanityApp,
1041
- SanityProvider,
1042
990
  useApplyDocumentActions,
1043
991
  useAuthState,
1044
992
  useAuthToken,
@@ -1055,7 +1003,7 @@ export {
1055
1003
  useFrameConnection,
1056
1004
  useHandleAuthCallback,
1057
1005
  useLogOut,
1058
- useLoginUrls,
1006
+ useLoginUrl,
1059
1007
  useManageFavorite,
1060
1008
  useNavigateToStudioDocument,
1061
1009
  usePaginatedDocuments,
@@ -1066,7 +1014,7 @@ export {
1066
1014
  useQuery,
1067
1015
  useRecordDocumentHistoryEvent,
1068
1016
  useSanityInstance,
1069
- useStudioWorkspacesByResourceId,
1017
+ useStudioWorkspacesByProjectIdDataset,
1070
1018
  useUsers,
1071
1019
  useWindowConnection
1072
1020
  };