@sanity/sdk-react 0.0.0-alpha.9 → 0.0.0-rc.1

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 (94) hide show
  1. package/README.md +33 -126
  2. package/dist/index.d.ts +4742 -2
  3. package/dist/index.js +1054 -2
  4. package/dist/index.js.map +1 -1
  5. package/package.json +19 -43
  6. package/src/_exports/index.ts +66 -10
  7. package/src/components/Login/LoginLinks.test.tsx +90 -0
  8. package/src/components/Login/LoginLinks.tsx +58 -0
  9. package/src/components/SDKProvider.test.tsx +79 -0
  10. package/src/components/SDKProvider.tsx +42 -0
  11. package/src/components/SanityApp.test.tsx +104 -2
  12. package/src/components/SanityApp.tsx +54 -17
  13. package/src/components/auth/AuthBoundary.test.tsx +2 -2
  14. package/src/components/auth/AuthBoundary.tsx +13 -3
  15. package/src/components/auth/Login.test.tsx +1 -1
  16. package/src/components/auth/Login.tsx +11 -26
  17. package/src/components/auth/LoginCallback.tsx +4 -7
  18. package/src/components/auth/LoginError.tsx +12 -8
  19. package/src/components/auth/LoginFooter.tsx +13 -20
  20. package/src/components/auth/LoginLayout.tsx +8 -9
  21. package/src/components/auth/authTestHelpers.tsx +1 -8
  22. package/src/components/utils.ts +22 -0
  23. package/src/context/SanityInstanceContext.ts +4 -0
  24. package/src/context/SanityProvider.test.tsx +1 -1
  25. package/src/context/SanityProvider.tsx +10 -8
  26. package/src/hooks/_synchronous-groq-js.mjs +4 -0
  27. package/src/hooks/auth/useAuthState.tsx +0 -2
  28. package/src/hooks/auth/useCurrentUser.tsx +26 -20
  29. package/src/hooks/auth/useDashboardOrganizationId.test.tsx +42 -0
  30. package/src/hooks/auth/useDashboardOrganizationId.tsx +29 -0
  31. package/src/hooks/client/useClient.ts +8 -30
  32. package/src/hooks/comlink/useFrameConnection.test.tsx +55 -10
  33. package/src/hooks/comlink/useFrameConnection.ts +39 -43
  34. package/src/hooks/comlink/useManageFavorite.test.ts +106 -0
  35. package/src/hooks/comlink/useManageFavorite.ts +101 -0
  36. package/src/hooks/comlink/useRecordDocumentHistoryEvent.test.ts +77 -0
  37. package/src/hooks/comlink/useRecordDocumentHistoryEvent.ts +79 -0
  38. package/src/hooks/comlink/useWindowConnection.test.ts +53 -12
  39. package/src/hooks/comlink/useWindowConnection.ts +69 -29
  40. package/src/hooks/context/useSanityInstance.test.tsx +1 -1
  41. package/src/hooks/context/useSanityInstance.ts +21 -5
  42. package/src/hooks/dashboard/useNavigateToStudioDocument.ts +97 -0
  43. package/src/hooks/dashboard/useStudioWorkspacesByResourceId.test.tsx +274 -0
  44. package/src/hooks/dashboard/useStudioWorkspacesByResourceId.ts +91 -0
  45. package/src/hooks/datasets/useDatasets.ts +37 -0
  46. package/src/hooks/document/useApplyActions.test.ts +5 -4
  47. package/src/hooks/document/useApplyActions.ts +55 -5
  48. package/src/hooks/document/useDocument.test.ts +2 -2
  49. package/src/hooks/document/useDocument.ts +90 -21
  50. package/src/hooks/document/useDocumentEvent.test.ts +13 -3
  51. package/src/hooks/document/useDocumentEvent.ts +36 -4
  52. package/src/hooks/document/useDocumentSyncStatus.test.ts +1 -1
  53. package/src/hooks/document/useDocumentSyncStatus.ts +26 -2
  54. package/src/hooks/document/useEditDocument.test.ts +55 -10
  55. package/src/hooks/document/useEditDocument.ts +159 -31
  56. package/src/hooks/document/usePermissions.ts +82 -0
  57. package/src/hooks/helpers/createCallbackHook.tsx +3 -2
  58. package/src/hooks/helpers/createStateSourceHook.test.tsx +66 -0
  59. package/src/hooks/helpers/createStateSourceHook.tsx +29 -10
  60. package/src/hooks/infiniteList/useInfiniteList.test.tsx +152 -0
  61. package/src/hooks/infiniteList/useInfiniteList.ts +174 -0
  62. package/src/hooks/paginatedList/usePaginatedList.test.tsx +259 -0
  63. package/src/hooks/paginatedList/usePaginatedList.ts +290 -0
  64. package/src/hooks/preview/usePreview.test.tsx +6 -6
  65. package/src/hooks/preview/usePreview.tsx +12 -9
  66. package/src/hooks/projection/useProjection.test.tsx +218 -0
  67. package/src/hooks/projection/useProjection.ts +147 -0
  68. package/src/hooks/projects/useProject.ts +45 -0
  69. package/src/hooks/projects/useProjects.ts +41 -0
  70. package/src/hooks/query/useQuery.test.tsx +188 -0
  71. package/src/hooks/query/useQuery.ts +103 -0
  72. package/src/hooks/users/useUsers.test.ts +163 -0
  73. package/src/hooks/users/useUsers.ts +107 -0
  74. package/src/utils/getEnv.ts +21 -0
  75. package/src/version.ts +8 -0
  76. package/dist/_chunks-es/context.js +0 -8
  77. package/dist/_chunks-es/context.js.map +0 -1
  78. package/dist/_chunks-es/useLogOut.js +0 -45
  79. package/dist/_chunks-es/useLogOut.js.map +0 -1
  80. package/dist/components.d.ts +0 -111
  81. package/dist/components.js +0 -153
  82. package/dist/components.js.map +0 -1
  83. package/dist/context.d.ts +0 -45
  84. package/dist/context.js +0 -5
  85. package/dist/context.js.map +0 -1
  86. package/dist/hooks.d.ts +0 -3532
  87. package/dist/hooks.js +0 -218
  88. package/dist/hooks.js.map +0 -1
  89. package/src/_exports/components.ts +0 -2
  90. package/src/_exports/context.ts +0 -2
  91. package/src/_exports/hooks.ts +0 -32
  92. package/src/hooks/client/useClient.test.tsx +0 -130
  93. package/src/hooks/documentCollection/useDocuments.test.ts +0 -130
  94. package/src/hooks/documentCollection/useDocuments.ts +0 -135
package/dist/index.js CHANGED
@@ -1,6 +1,1058 @@
1
- function main() {
1
+ import { jsxs, jsx, Fragment as Fragment$1 } from "react/jsx-runtime";
2
+ import { c } from "react/compiler-runtime";
3
+ import { getAuthState, getLoginUrlsState, fetchLoginUrls, handleCallback, logout, AuthStateType, createSanityInstance, getTokenState, getCurrentUserState, getDashboardOrganizationId, getClientState, getOrCreateController, getOrCreateChannel, releaseChannel, getOrCreateNode, releaseNode, resolveDatasets, getDatasetsState, applyActions, getResourceId, resolveDocument, getDocumentState, subscribeDocumentEvents, getDocumentSyncStatus, editDocument, getPermissionsState, getQueryKey, parseQueryKey, getQueryState, resolveQuery, getPreviewState, resolvePreview, getProjectionState, resolveProjection, resolveProject, getProjectState, resolveProjects, getProjectsState, createUsersStore } from "@sanity/sdk";
4
+ 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 { 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;
26
+ if (!instance)
27
+ throw new Error(`Sanity instance with resourceId ${resourceId} not found`);
28
+ return instance;
29
+ };
30
+ 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;
32
+ function useHook(...t0) {
33
+ 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);
40
+ if (suspense?.suspender && suspense?.shouldSuspend?.(instance, ...params))
41
+ 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;
45
+ return useSyncExternalStore(state.subscribe, state.getCurrent);
46
+ }
47
+ return useHook;
48
+ }
49
+ const useAuthState = createStateSourceHook(getAuthState);
50
+ function isInIframe() {
51
+ return typeof window < "u" && window.self !== window.top;
52
+ }
53
+ function isLocalUrl(window2) {
54
+ const url = typeof window2 < "u" ? window2.location.href : "";
55
+ return url.startsWith("http://localhost") || url.startsWith("https://localhost") || url.startsWith("http://127.0.0.1") || url.startsWith("https://127.0.0.1");
56
+ }
57
+ class AuthError extends Error {
58
+ constructor(error) {
59
+ typeof error == "object" && error && "message" in error && typeof error.message == "string" ? super(error.message) : super(), this.cause = error;
60
+ }
61
+ }
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) {
143
+ function useHook() {
144
+ const $ = c(2), instance = useSanityInstance(resourceId);
145
+ let t0;
146
+ return $[0] !== instance ? (t0 = (...t1) => callback(instance, ...t1), $[0] = instance, $[1] = t0) : t0 = $[1], t0;
147
+ }
148
+ return useHook;
149
+ }
150
+ const useHandleCallback = createCallbackHook(handleCallback);
151
+ function LoginCallback(t0) {
152
+ const $ = c(7), {
153
+ header,
154
+ footer
155
+ } = t0, handleCallback2 = useHandleCallback();
156
+ let t1, t2;
157
+ $[0] !== handleCallback2 ? (t1 = () => {
158
+ const url = new URL(location.href);
159
+ handleCallback2(url.toString()).then(_temp$8);
160
+ }, t2 = [handleCallback2], $[0] = handleCallback2, $[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;
168
+ }
169
+ function _temp$8(replacementLocation) {
170
+ replacementLocation && history.replaceState(null, "", replacementLocation);
171
+ }
172
+ const useLogOut = createCallbackHook(logout);
173
+ function LoginError(t0) {
174
+ const $ = c(10), {
175
+ error,
176
+ resetErrorBoundary,
177
+ header,
178
+ footer
179
+ } = t0;
180
+ if (!(error instanceof AuthError))
181
+ throw error;
182
+ const logout2 = useLogOut();
183
+ let t1;
184
+ $[0] !== logout2 || $[1] !== resetErrorBoundary ? (t1 = async () => {
185
+ await logout2(), resetErrorBoundary();
186
+ }, $[0] = logout2, $[1] = resetErrorBoundary, $[2] = t1) : t1 = $[2];
187
+ const handleRetry = t1;
188
+ let t2;
189
+ $[3] === Symbol.for("react.memo_cache_sentinel") ? (t2 = /* @__PURE__ */ jsxs("div", { className: "sc-login-error__content", children: [
190
+ /* @__PURE__ */ jsx("h2", { className: "sc-login-error__title", children: "Authentication Error" }),
191
+ /* @__PURE__ */ jsx("p", { className: "sc-login-error__description", children: "Please try again or contact support if the problem persists." })
192
+ ] }), $[3] = t2) : t2 = $[3];
193
+ let t3;
194
+ $[4] !== handleRetry ? (t3 = /* @__PURE__ */ jsxs("div", { className: "sc-login-error", children: [
195
+ t2,
196
+ /* @__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;
200
+ }
201
+ if (isInIframe()) {
202
+ const parsedUrl = new URL(window.location.href), mode = new URLSearchParams(parsedUrl.hash.slice(1)).get("mode"), script = document.createElement("script");
203
+ 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
+ }
205
+ function AuthBoundary(t0) {
206
+ const $ = c(12);
207
+ let props, t1;
208
+ $[0] !== t0 ? ({
209
+ LoginErrorComponent: t1,
210
+ ...props
211
+ } = 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;
216
+ 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;
220
+ const FallbackComponent = t2;
221
+ let t4;
222
+ $[7] !== props ? (t4 = /* @__PURE__ */ jsx(AuthSwitch, { ...props }), $[7] = props, $[8] = t4) : t4 = $[8];
223
+ let t5;
224
+ return $[9] !== FallbackComponent || $[10] !== t4 ? (t5 = /* @__PURE__ */ jsx(ErrorBoundary, { FallbackComponent, children: t4 }), $[9] = FallbackComponent, $[10] = t4, $[11] = t5) : t5 = $[11], t5;
225
+ }
226
+ function AuthSwitch(t0) {
227
+ const $ = c(11);
228
+ let children, props, t1, t2;
229
+ $[0] !== t0 ? ({
230
+ LoginComponent: t1,
231
+ CallbackComponent: t2,
232
+ children,
233
+ ...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) {
237
+ case AuthStateType.ERROR:
238
+ throw new AuthError(authState.error);
239
+ 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;
242
+ }
243
+ case AuthStateType.LOGGED_IN:
244
+ 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
+ }
249
+ }
250
+ }
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), {
261
+ children,
262
+ sanityConfigs,
263
+ fallback
264
+ } = t0;
265
+ 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];
272
+ let t6;
273
+ return $[7] !== sanityInstances || $[8] !== t5 ? (t6 = /* @__PURE__ */ jsx(SanityProvider, { sanityInstances, children: t5 }), $[7] = sanityInstances, $[8] = t5, $[9] = t6) : t6 = $[9], t6;
274
+ }
275
+ function _temp$7(sanityConfig) {
276
+ return createSanityInstance(sanityConfig);
277
+ }
278
+ const CORE_URL = "https://core.sanity.io";
279
+ function SanityApp(t0) {
280
+ const $ = c(6), {
281
+ sanityConfigs,
282
+ children,
283
+ fallback
284
+ } = t0;
285
+ let t1;
286
+ $[0] !== sanityConfigs ? (t1 = [sanityConfigs], $[0] = sanityConfigs, $[1] = t1) : t1 = $[1], useEffect(_temp2$3, t1);
287
+ 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;
289
+ }
290
+ function _temp2$3() {
291
+ let timeout;
292
+ return !isInIframe() && !isLocalUrl(window) && (timeout = setTimeout(_temp$6, 1e3)), () => clearTimeout(timeout);
293
+ }
294
+ function _temp$6() {
295
+ console.warn("Redirecting to core", CORE_URL), window.location.replace(CORE_URL);
296
+ }
297
+ const useAuthToken = createStateSourceHook(getTokenState), useCurrentUser = createStateSourceHook(getCurrentUserState);
298
+ function useDashboardOrganizationId() {
299
+ const $ = c(2), instance = useSanityInstance();
300
+ let t0, t1;
301
+ $[0] !== instance ? (t1 = getDashboardOrganizationId(instance), $[0] = instance, $[1] = t1) : t1 = $[1], t0 = t1;
302
+ const {
303
+ subscribe,
304
+ getCurrent
305
+ } = t0;
306
+ return useSyncExternalStore(subscribe, getCurrent);
307
+ }
308
+ const useClient = createStateSourceHook({
309
+ getState: getClientState,
310
+ getResourceId: (e) => e.resourceId
311
+ });
312
+ function useFrameConnection(options) {
313
+ const $ = c(12), {
314
+ onMessage,
315
+ targetOrigin,
316
+ name,
317
+ connectTo,
318
+ heartbeat,
319
+ onStatus
320
+ } = options, instance = useSanityInstance(), controllerRef = useRef(null), channelRef = useRef(null);
321
+ let t0, t1;
322
+ $[0] !== connectTo || $[1] !== heartbeat || $[2] !== instance || $[3] !== name || $[4] !== onMessage || $[5] !== onStatus || $[6] !== targetOrigin ? (t0 = () => {
323
+ const controller = getOrCreateController(instance, targetOrigin), channel = getOrCreateChannel(instance, {
324
+ name,
325
+ connectTo,
326
+ heartbeat
327
+ });
328
+ controllerRef.current = controller, channelRef.current = channel, channel.onStatus((event) => {
329
+ onStatus?.(event.status);
330
+ });
331
+ const messageUnsubscribers = [];
332
+ return onMessage && Object.entries(onMessage).forEach((t22) => {
333
+ const [type, handler] = t22, unsubscribe = channel.on(type, handler);
334
+ messageUnsubscribers.push(unsubscribe);
335
+ }), () => {
336
+ messageUnsubscribers.forEach(_temp$5), releaseChannel(instance, name), channelRef.current = null, controllerRef.current = null;
337
+ };
338
+ }, 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);
339
+ let t2;
340
+ $[9] === Symbol.for("react.memo_cache_sentinel") ? (t2 = (frameWindow) => {
341
+ const removeTarget = controllerRef.current?.addTarget(frameWindow);
342
+ return () => {
343
+ removeTarget?.();
344
+ };
345
+ }, $[9] = t2) : t2 = $[9];
346
+ const connect = t2;
347
+ let t3;
348
+ $[10] === Symbol.for("react.memo_cache_sentinel") ? (t3 = (type_0, data) => {
349
+ channelRef.current?.post(type_0, data);
350
+ }, $[10] = t3) : t3 = $[10];
351
+ const sendMessage = t3;
352
+ let t4;
353
+ return $[11] === Symbol.for("react.memo_cache_sentinel") ? (t4 = {
354
+ connect,
355
+ sendMessage
356
+ }, $[11] = t4) : t4 = $[11], t4;
357
+ }
358
+ function _temp$5(unsub) {
359
+ return unsub();
360
+ }
361
+ function useWindowConnection(t0) {
362
+ const $ = c(11), {
363
+ name,
364
+ connectTo,
365
+ onMessage,
366
+ onStatus
367
+ } = t0, nodeRef = useRef(null);
368
+ let t1;
369
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = [], $[0] = t1) : t1 = $[0];
370
+ const messageUnsubscribers = useRef(t1), instance = useSanityInstance();
371
+ let t2, t3;
372
+ $[1] !== connectTo || $[2] !== instance || $[3] !== name || $[4] !== onMessage || $[5] !== onStatus ? (t2 = () => {
373
+ const node = getOrCreateNode(instance, {
374
+ name,
375
+ connectTo
376
+ });
377
+ nodeRef.current = node;
378
+ const statusUnsubscribe = node.onStatus((eventStatus) => {
379
+ onStatus?.(eventStatus);
380
+ });
381
+ return onMessage && Object.entries(onMessage).forEach((t42) => {
382
+ const [type, handler] = t42, messageUnsubscribe = node.on(type, handler);
383
+ messageUnsubscribers.current.push(messageUnsubscribe);
384
+ }), () => {
385
+ statusUnsubscribe(), messageUnsubscribers.current.forEach(_temp$4), messageUnsubscribers.current = [], releaseNode(instance, name), nodeRef.current = null;
386
+ };
387
+ }, 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);
388
+ let t4;
389
+ $[8] === Symbol.for("react.memo_cache_sentinel") ? (t4 = (type_0, data) => {
390
+ if (!nodeRef.current)
391
+ throw new Error("Cannot send message before connection is established");
392
+ nodeRef.current.post(type_0, data);
393
+ }, $[8] = t4) : t4 = $[8];
394
+ const sendMessage = t4;
395
+ let t5;
396
+ $[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];
397
+ const fetch = t5;
398
+ let t6;
399
+ return $[10] === Symbol.for("react.memo_cache_sentinel") ? (t6 = {
400
+ sendMessage,
401
+ fetch
402
+ }, $[10] = t6) : t6 = $[10], t6;
403
+ }
404
+ function _temp$4(unsubscribe) {
405
+ return unsubscribe();
406
+ }
407
+ function useManageFavorite(t0) {
408
+ const $ = c(14), {
409
+ _id,
410
+ _type
411
+ } = t0, [isFavorited, setIsFavorited] = useState(!1), [status, setStatus] = useState("idle");
412
+ let t1;
413
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = {
414
+ name: SDK_NODE_NAME,
415
+ connectTo: SDK_CHANNEL_NAME,
416
+ onStatus: setStatus
417
+ }, $[0] = t1) : t1 = $[0];
418
+ const {
419
+ sendMessage
420
+ } = useWindowConnection(t1);
421
+ let t2;
422
+ $[1] !== _id || $[2] !== _type || $[3] !== sendMessage ? (t2 = (action, setFavoriteState) => {
423
+ if (!(!_id || !_type))
424
+ try {
425
+ const message = {
426
+ type: "core/v1/events/favorite",
427
+ data: {
428
+ eventType: action,
429
+ documentId: _id,
430
+ documentType: _type
431
+ }
432
+ };
433
+ sendMessage(message.type, message.data), setIsFavorited(setFavoriteState);
434
+ } catch (t32) {
435
+ const err = t32, error = err instanceof Error ? err : new Error("Failed to update favorite status");
436
+ throw console.error(`Failed to ${action === "added" ? "favorite" : "unfavorite"} document:`, error), error;
437
+ }
438
+ }, $[1] = _id, $[2] = _type, $[3] = sendMessage, $[4] = t2) : t2 = $[4];
439
+ const handleFavoriteAction = t2;
440
+ let t3;
441
+ $[5] !== handleFavoriteAction ? (t3 = () => handleFavoriteAction("added", !0), $[5] = handleFavoriteAction, $[6] = t3) : t3 = $[6];
442
+ const favorite = t3;
443
+ let t4;
444
+ $[7] !== handleFavoriteAction ? (t4 = () => handleFavoriteAction("removed", !1), $[7] = handleFavoriteAction, $[8] = t4) : t4 = $[8];
445
+ const unfavorite = t4, t5 = status === "connected";
446
+ let t6;
447
+ return $[9] !== favorite || $[10] !== isFavorited || $[11] !== t5 || $[12] !== unfavorite ? (t6 = {
448
+ favorite,
449
+ unfavorite,
450
+ isFavorited,
451
+ isConnected: t5
452
+ }, $[9] = favorite, $[10] = isFavorited, $[11] = t5, $[12] = unfavorite, $[13] = t6) : t6 = $[13], t6;
453
+ }
454
+ function useRecordDocumentHistoryEvent(t0) {
455
+ const $ = c(8), {
456
+ _id,
457
+ _type
458
+ } = t0, [status, setStatus] = useState("idle");
459
+ let t1;
460
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = {
461
+ name: SDK_NODE_NAME,
462
+ connectTo: SDK_CHANNEL_NAME,
463
+ onStatus: setStatus
464
+ }, $[0] = t1) : t1 = $[0];
465
+ const {
466
+ sendMessage
467
+ } = useWindowConnection(t1);
468
+ let t2;
469
+ $[1] !== _id || $[2] !== _type || $[3] !== sendMessage ? (t2 = (eventType) => {
470
+ try {
471
+ const message = {
472
+ type: "core/v1/events/history",
473
+ data: {
474
+ eventType,
475
+ documentId: _id,
476
+ documentType: _type
477
+ }
478
+ };
479
+ sendMessage(message.type, message.data);
480
+ } catch (t32) {
481
+ const error = t32;
482
+ throw console.error("Failed to record history event:", error), error;
483
+ }
484
+ }, $[1] = _id, $[2] = _type, $[3] = sendMessage, $[4] = t2) : t2 = $[4];
485
+ const recordEvent = t2, t3 = status === "connected";
486
+ let t4;
487
+ return $[5] !== recordEvent || $[6] !== t3 ? (t4 = {
488
+ recordEvent,
489
+ isConnected: t3
490
+ }, $[5] = recordEvent, $[6] = t3, $[7] = t4) : t4 = $[7], t4;
491
+ }
492
+ function useStudioWorkspacesByResourceId() {
493
+ const $ = c(10);
494
+ let t0;
495
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = {}, $[0] = t0) : t0 = $[0];
496
+ const [workspacesByResourceId, setWorkspacesByResourceId] = useState(t0), [status, setStatus] = useState("idle"), [error, setError] = useState(null);
497
+ let t1;
498
+ $[1] === Symbol.for("react.memo_cache_sentinel") ? (t1 = {
499
+ name: "core/nodes/sdk",
500
+ connectTo: "core/channels/sdk",
501
+ onStatus: setStatus
502
+ }, $[1] = t1) : t1 = $[1];
503
+ const {
504
+ fetch
505
+ } = useWindowConnection(t1);
506
+ let t2, t3;
507
+ $[2] !== fetch || $[3] !== status ? (t2 = () => {
508
+ if (!fetch || status !== "connected")
509
+ return;
510
+ const fetchWorkspaces = async function(signal) {
511
+ try {
512
+ const data = await fetch("core/v1/bridge/context", void 0, {
513
+ signal
514
+ }), workspaceMap = {};
515
+ data.context.availableResources.forEach((resource) => {
516
+ !resource.projectId || !resource.workspaces?.length || resource.workspaces.forEach((workspace) => {
517
+ const key = `${resource.projectId}:${workspace.dataset}`;
518
+ workspaceMap[key] || (workspaceMap[key] = []), workspaceMap[key].push(workspace);
519
+ });
520
+ }), setWorkspacesByResourceId(workspaceMap), setError(null);
521
+ } catch (t42) {
522
+ const err = t42;
523
+ if (err instanceof Error) {
524
+ if (err.name === "AbortError")
525
+ return;
526
+ setError("Failed to fetch workspaces");
527
+ }
528
+ }
529
+ }, controller = new AbortController();
530
+ return fetchWorkspaces(controller.signal), () => {
531
+ controller.abort();
532
+ };
533
+ }, t3 = [fetch, status], $[2] = fetch, $[3] = status, $[4] = t2, $[5] = t3) : (t2 = $[4], t3 = $[5]), useEffect(t2, t3);
534
+ const t4 = status === "connected";
535
+ let t5;
536
+ return $[6] !== error || $[7] !== t4 || $[8] !== workspacesByResourceId ? (t5 = {
537
+ workspacesByResourceId,
538
+ error,
539
+ isConnected: t4
540
+ }, $[6] = error, $[7] = t4, $[8] = workspacesByResourceId, $[9] = t5) : t5 = $[9], t5;
541
+ }
542
+ function useNavigateToStudioDocument(documentHandle) {
543
+ const $ = c(10), {
544
+ workspacesByResourceId,
545
+ isConnected: workspacesConnected
546
+ } = useStudioWorkspacesByResourceId(), [status, setStatus] = useState("idle");
547
+ let t0;
548
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = {
549
+ name: "core/nodes/sdk",
550
+ connectTo: "core/channels/sdk",
551
+ onStatus: setStatus
552
+ }, $[0] = t0) : t0 = $[0];
553
+ const {
554
+ sendMessage
555
+ } = useWindowConnection(t0);
556
+ let t1;
557
+ $[1] !== documentHandle || $[2] !== sendMessage || $[3] !== status || $[4] !== workspacesByResourceId || $[5] !== workspacesConnected ? (t1 = () => {
558
+ if (!workspacesConnected || status !== "connected" || !documentHandle.resourceId)
559
+ return;
560
+ const [, projectAndDataset] = documentHandle.resourceId.split(":"), [projectId, dataset] = projectAndDataset.split(".");
561
+ if (!projectId || !dataset)
562
+ return;
563
+ const workspaces = workspacesByResourceId[`${projectId}:${dataset}`];
564
+ if (!workspaces?.length) {
565
+ console.warn("No workspace found for document", documentHandle.resourceId);
566
+ return;
567
+ }
568
+ workspaces.length > 1 && (console.warn("Multiple workspaces found for document", documentHandle.resourceId), console.warn("Using the first one", workspaces[0]));
569
+ const message = {
570
+ type: "core/v1/bridge/navigate-to-resource",
571
+ data: {
572
+ resourceId: workspaces[0]._ref,
573
+ resourceType: "studio",
574
+ path: `/intent/edit/id=${documentHandle._id};type=${documentHandle._type}`
575
+ }
576
+ };
577
+ sendMessage(message.type, message.data);
578
+ }, $[1] = documentHandle, $[2] = sendMessage, $[3] = status, $[4] = workspacesByResourceId, $[5] = workspacesConnected, $[6] = t1) : t1 = $[6];
579
+ const navigateToStudioDocument = t1, t2 = workspacesConnected && status === "connected";
580
+ let t3;
581
+ return $[7] !== navigateToStudioDocument || $[8] !== t2 ? (t3 = {
582
+ navigateToStudioDocument,
583
+ isConnected: t2
584
+ }, $[7] = navigateToStudioDocument, $[8] = t2, $[9] = t3) : t3 = $[9], t3;
585
+ }
586
+ const useDatasets = createStateSourceHook({
587
+ // remove `undefined` since we're suspending when that is the case
588
+ getState: getDatasetsState,
589
+ shouldSuspend: (instance) => getDatasetsState(instance).getCurrent() === void 0,
590
+ suspender: resolveDatasets
591
+ });
592
+ function useApplyActions(resourceId) {
593
+ return _useApplyActions(resourceId)();
594
+ }
595
+ const _useApplyActions = (resourceId) => createCallbackHook(applyActions, resourceId);
596
+ function useDocument(doc, path) {
597
+ return _useDocument(doc, path);
598
+ }
599
+ const _useDocument = createStateSourceHook({
600
+ getState: getDocumentState,
601
+ shouldSuspend: (instance, doc) => getDocumentState(instance, doc._id).getCurrent() === void 0,
602
+ suspender: resolveDocument,
603
+ getResourceId: (doc) => getResourceId(doc.resourceId)
604
+ });
605
+ function useDocumentEvent(handler, doc) {
606
+ const $ = c(8), ref = useRef(handler);
607
+ let t0;
608
+ $[0] !== handler ? (t0 = () => {
609
+ ref.current = handler;
610
+ }, $[0] = handler, $[1] = t0) : t0 = $[1], useInsertionEffect(t0);
611
+ let t1;
612
+ $[2] === Symbol.for("react.memo_cache_sentinel") ? (t1 = (documentEvent) => ref.current(documentEvent), $[2] = t1) : t1 = $[2];
613
+ const stableHandler = t1;
614
+ let t2;
615
+ $[3] !== doc.resourceId ? (t2 = getResourceId(doc.resourceId), $[3] = doc.resourceId, $[4] = t2) : t2 = $[4];
616
+ const instance = useSanityInstance(t2);
617
+ let t3, t4;
618
+ $[5] !== instance ? (t3 = () => subscribeDocumentEvents(instance, stableHandler), t4 = [instance, stableHandler], $[5] = instance, $[6] = t3, $[7] = t4) : (t3 = $[6], t4 = $[7]), useEffect(t3, t4);
619
+ }
620
+ const useDocumentSyncStatus = createStateSourceHook(getDocumentSyncStatus), ignoredKeys = ["_id", "_type", "_createdAt", "_updatedAt", "_rev"];
621
+ function useEditDocument(doc, path) {
622
+ const $ = c(8);
623
+ let t0;
624
+ $[0] !== doc.resourceId ? (t0 = getResourceId(doc.resourceId), $[0] = doc.resourceId, $[1] = t0) : t0 = $[1];
625
+ const resourceId = t0, documentId = doc._id, instance = useSanityInstance(resourceId), apply = useApplyActions(resourceId);
626
+ if (getDocumentState(instance, documentId).getCurrent() === void 0)
627
+ throw resolveDocument(instance, documentId);
628
+ let t1;
629
+ return $[2] !== apply || $[3] !== doc || $[4] !== documentId || $[5] !== instance || $[6] !== path ? (t1 = (updater) => {
630
+ if (path) {
631
+ const nextValue = typeof updater == "function" ? updater(getDocumentState(instance, documentId, path).getCurrent()) : updater;
632
+ return apply(editDocument(doc, {
633
+ set: {
634
+ [path]: nextValue
635
+ }
636
+ }));
637
+ }
638
+ const current = getDocumentState(instance, documentId).getCurrent(), nextValue_0 = typeof updater == "function" ? updater(current) : updater;
639
+ if (typeof nextValue_0 != "object" || !nextValue_0)
640
+ throw new Error("No path was provided to `useEditDocument` and the value provided was not a document object.");
641
+ const editActions = Object.keys({
642
+ ...current,
643
+ ...nextValue_0
644
+ }).filter(_temp$3).filter((key_0) => current?.[key_0] !== nextValue_0[key_0]).map((key_1) => key_1 in nextValue_0 ? editDocument(doc, {
645
+ set: {
646
+ [key_1]: nextValue_0[key_1]
647
+ }
648
+ }) : editDocument(doc, {
649
+ unset: [key_1]
650
+ }));
651
+ return apply(editActions);
652
+ }, $[2] = apply, $[3] = doc, $[4] = documentId, $[5] = instance, $[6] = path, $[7] = t1) : t1 = $[7], t1;
653
+ }
654
+ function _temp$3(key) {
655
+ return !ignoredKeys.includes(key);
656
+ }
657
+ function usePermissions(actions) {
658
+ const $ = c(5);
659
+ if (Array.isArray(actions)) {
660
+ const resourceIds = actions.map(_temp$2);
661
+ if (new Set(resourceIds).size !== 1)
662
+ throw new Error("All actions must have the same resourceId");
663
+ }
664
+ let t0;
665
+ $[0] !== actions ? (t0 = Array.isArray(actions) ? getResourceId(actions[0].resourceId) : getResourceId(actions.resourceId), $[0] = actions, $[1] = t0) : t0 = $[1];
666
+ const instance = useSanityInstance(t0);
667
+ if (getPermissionsState(instance, actions).getCurrent() === void 0)
668
+ throw firstValueFrom(getPermissionsState(instance, actions).observable.pipe(filter(_temp2$2)));
669
+ let t1, t2;
670
+ $[2] !== actions || $[3] !== instance ? (t2 = getPermissionsState(instance, actions), $[2] = actions, $[3] = instance, $[4] = t2) : t2 = $[4], t1 = t2;
671
+ const {
672
+ subscribe,
673
+ getCurrent
674
+ } = t1;
675
+ return useSyncExternalStore(subscribe, getCurrent);
676
+ }
677
+ function _temp2$2(result) {
678
+ return result !== void 0;
679
+ }
680
+ function _temp$2(action) {
681
+ return action.resourceId;
682
+ }
683
+ function useQuery(query, options) {
684
+ 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());
685
+ useEffect(() => {
686
+ queryKey !== deferredQueryKey && startTransition(() => {
687
+ ref && !ref.signal.aborted && (ref.abort(), setRef(new AbortController())), setDeferredQueryKey(queryKey);
688
+ });
689
+ }, [deferredQueryKey, queryKey, ref]);
690
+ const {
691
+ getCurrent,
692
+ subscribe
693
+ } = useMemo(() => getQueryState(instance, deferred.query, deferred.options), [instance, deferred]);
694
+ if (getCurrent() === void 0)
695
+ throw resolveQuery(instance, deferred.query, {
696
+ ...deferred.options,
697
+ signal: ref.signal
698
+ });
699
+ return {
700
+ data: useSyncExternalStore(subscribe, getCurrent),
701
+ isPending
702
+ };
703
+ }
704
+ const DEFAULT_BATCH_SIZE = 25, DEFAULT_PERSPECTIVE$1 = "drafts";
705
+ function useInfiniteList(t0) {
706
+ const $ = c(31);
707
+ let filter2, options, orderings, params, search, t1;
708
+ $[0] !== t0 ? ({
709
+ batchSize: t1,
710
+ params,
711
+ search,
712
+ filter: filter2,
713
+ orderings,
714
+ ...options
715
+ } = 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]);
716
+ const batchSize = t1 === void 0 ? DEFAULT_BATCH_SIZE : t1, perspective = options.perspective ?? DEFAULT_PERSPECTIVE$1, [limit, setLimit] = useState(batchSize);
717
+ let t2;
718
+ $[7] !== batchSize || $[8] !== filter2 || $[9] !== orderings || $[10] !== params || $[11] !== search ? (t2 = JSON.stringify({
719
+ filter: filter2,
720
+ search,
721
+ params,
722
+ orderings,
723
+ batchSize
724
+ }), $[7] = batchSize, $[8] = filter2, $[9] = orderings, $[10] = params, $[11] = search, $[12] = t2) : t2 = $[12];
725
+ const key = t2;
726
+ let t3;
727
+ $[13] !== batchSize ? (t3 = () => {
728
+ setLimit(batchSize);
729
+ }, $[13] = batchSize, $[14] = t3) : t3 = $[14];
730
+ let t4;
731
+ $[15] !== batchSize || $[16] !== key ? (t4 = [key, batchSize], $[15] = batchSize, $[16] = key, $[17] = t4) : t4 = $[17], useEffect(t3, t4);
732
+ let t5;
733
+ const conditions = [];
734
+ search?.trim() && conditions.push(`[@] match text::query("${search.trim()}")`), filter2 && conditions.push(`(${filter2})`), t5 = conditions.length ? `[${conditions.join(" && ")}]` : "";
735
+ const filterClause = t5, orderClause = orderings ? `| order(${orderings.map(_temp2$1).join(",")})` : "", dataQuery = `*${filterClause}${orderClause}[0...${limit}]{_id,_type}`, countQuery = `count(*${filterClause})`;
736
+ let t6;
737
+ $[18] !== options || $[19] !== params || $[20] !== perspective ? (t6 = {
738
+ ...options,
739
+ params,
740
+ perspective
741
+ }, $[18] = options, $[19] = params, $[20] = perspective, $[21] = t6) : t6 = $[21];
742
+ const {
743
+ data: t7,
744
+ isPending
745
+ } = useQuery(`{"count":${countQuery},"data":${dataQuery}}`, t6), {
746
+ count,
747
+ data
748
+ } = t7, hasMore = data.length < count;
749
+ let t8;
750
+ $[22] !== batchSize || $[23] !== count ? (t8 = () => {
751
+ setLimit((prev) => Math.min(prev + batchSize, count));
752
+ }, $[22] = batchSize, $[23] = count, $[24] = t8) : t8 = $[24];
753
+ const loadMore = t8;
754
+ let t9, t10;
755
+ return $[25] !== count || $[26] !== data || $[27] !== hasMore || $[28] !== isPending || $[29] !== loadMore ? (t10 = {
756
+ data,
757
+ hasMore,
758
+ count,
759
+ isPending,
760
+ loadMore
761
+ }, $[25] = count, $[26] = data, $[27] = hasMore, $[28] = isPending, $[29] = loadMore, $[30] = t10) : t10 = $[30], t9 = t10, t9;
762
+ }
763
+ function _temp2$1(ordering) {
764
+ return [ordering.field, ordering.direction.toLowerCase()].map(_temp$1).filter(Boolean).join(" ");
765
+ }
766
+ function _temp$1(str) {
767
+ return str.trim();
768
+ }
769
+ const DEFAULT_PERSPECTIVE = "drafts";
770
+ function usePaginatedList(t0) {
771
+ const $ = c(48);
772
+ let t1;
773
+ $[0] !== t0 ? (t1 = t0 === void 0 ? {} : t0, $[0] = t0, $[1] = t1) : t1 = $[1];
774
+ let options, orderings, search, t2, t3, t4;
775
+ $[2] !== t1 ? ({
776
+ filter: t2,
777
+ pageSize: t3,
778
+ params: t4,
779
+ orderings,
780
+ search,
781
+ ...options
782
+ } = 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]);
783
+ const filter2 = t2 === void 0 ? "" : t2, pageSize = t3 === void 0 ? 25 : t3;
784
+ let t5;
785
+ $[9] !== t4 ? (t5 = t4 === void 0 ? {} : t4, $[9] = t4, $[10] = t5) : t5 = $[10];
786
+ const params = t5, [pageIndex, setPageIndex] = useState(0);
787
+ let t6;
788
+ $[11] !== filter2 || $[12] !== orderings || $[13] !== pageSize || $[14] !== params || $[15] !== search ? (t6 = JSON.stringify({
789
+ filter: filter2,
790
+ search,
791
+ params,
792
+ orderings,
793
+ pageSize
794
+ }), $[11] = filter2, $[12] = orderings, $[13] = pageSize, $[14] = params, $[15] = search, $[16] = t6) : t6 = $[16];
795
+ const key = t6;
796
+ let t7;
797
+ $[17] === Symbol.for("react.memo_cache_sentinel") ? (t7 = () => {
798
+ setPageIndex(0);
799
+ }, $[17] = t7) : t7 = $[17];
800
+ let t8;
801
+ $[18] !== key ? (t8 = [key], $[18] = key, $[19] = t8) : t8 = $[19], useEffect(t7, t8);
802
+ const startIndex = pageIndex * pageSize, endIndex = (pageIndex + 1) * pageSize, perspective = options.perspective ?? DEFAULT_PERSPECTIVE;
803
+ let t9;
804
+ const conditions = [];
805
+ search?.trim() && conditions.push(`[@] match text::query("${search.trim()}")`), filter2 && conditions.push(`(${filter2})`), t9 = conditions.length ? `[${conditions.join(" && ")}]` : "";
806
+ const filterClause = t9, orderClause = orderings ? `| order(${orderings.map(_temp2).join(",")})` : "", dataQuery = `*${filterClause}${orderClause}[${startIndex}...${endIndex}]{_id,_type}`, countQuery = `count(*${filterClause})`;
807
+ let t10;
808
+ $[20] !== options || $[21] !== params || $[22] !== perspective ? (t10 = {
809
+ ...options,
810
+ perspective,
811
+ params
812
+ }, $[20] = options, $[21] = params, $[22] = perspective, $[23] = t10) : t10 = $[23];
813
+ const {
814
+ data: t11,
815
+ isPending
816
+ } = useQuery(`{"data":${dataQuery},"count":${countQuery}}`, t10), {
817
+ data,
818
+ count
819
+ } = t11, totalPages = Math.ceil(count / pageSize), currentPage = pageIndex + 1;
820
+ let t12;
821
+ $[24] === Symbol.for("react.memo_cache_sentinel") ? (t12 = () => setPageIndex(0), $[24] = t12) : t12 = $[24];
822
+ const firstPage = t12;
823
+ let t13;
824
+ $[25] === Symbol.for("react.memo_cache_sentinel") ? (t13 = () => setPageIndex(_temp3), $[25] = t13) : t13 = $[25];
825
+ const previousPage = t13;
826
+ let t14;
827
+ $[26] !== totalPages ? (t14 = () => setPageIndex((prev_0) => Math.min(prev_0 + 1, totalPages - 1)), $[26] = totalPages, $[27] = t14) : t14 = $[27];
828
+ const nextPage = t14;
829
+ let t15;
830
+ $[28] !== totalPages ? (t15 = () => setPageIndex(totalPages - 1), $[28] = totalPages, $[29] = t15) : t15 = $[29];
831
+ const lastPage = t15;
832
+ let t16;
833
+ $[30] !== totalPages ? (t16 = (pageNumber) => {
834
+ pageNumber < 1 || pageNumber > totalPages || setPageIndex(pageNumber - 1);
835
+ }, $[30] = totalPages, $[31] = t16) : t16 = $[31];
836
+ const goToPage = t16, hasFirstPage = pageIndex > 0, hasPreviousPage = pageIndex > 0, hasNextPage = pageIndex < totalPages - 1, hasLastPage = pageIndex < totalPages - 1;
837
+ let t17, t18;
838
+ 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 = {
839
+ data,
840
+ isPending,
841
+ pageSize,
842
+ currentPage,
843
+ totalPages,
844
+ startIndex,
845
+ endIndex,
846
+ count,
847
+ firstPage,
848
+ hasFirstPage,
849
+ previousPage,
850
+ hasPreviousPage,
851
+ nextPage,
852
+ hasNextPage,
853
+ lastPage,
854
+ hasLastPage,
855
+ goToPage
856
+ }, $[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;
857
+ }
858
+ function _temp3(prev) {
859
+ return Math.max(prev - 1, 0);
860
+ }
861
+ function _temp2(ordering) {
862
+ return [ordering.field, ordering.direction.toLowerCase()].map(_temp).filter(Boolean).join(" ");
863
+ }
864
+ function _temp(str) {
865
+ return str.trim();
866
+ }
867
+ function usePreview(t0) {
868
+ const $ = c(12), {
869
+ document: t1,
870
+ ref
871
+ } = t0, {
872
+ _id,
873
+ _type
874
+ } = t1, instance = useSanityInstance();
875
+ let t2, t3;
876
+ $[0] !== _id || $[1] !== _type || $[2] !== instance ? (t3 = getPreviewState(instance, {
877
+ document: {
878
+ _id,
879
+ _type
880
+ }
881
+ }), $[0] = _id, $[1] = _type, $[2] = instance, $[3] = t3) : t3 = $[3], t2 = t3;
882
+ const stateSource = t2;
883
+ let t4;
884
+ $[4] !== ref || $[5] !== stateSource ? (t4 = (onStoreChanged) => {
885
+ const subscription = new Observable((observer) => {
886
+ if (typeof IntersectionObserver > "u" || typeof HTMLElement > "u")
887
+ return;
888
+ const intersectionObserver = new IntersectionObserver((t52) => {
889
+ const [entry] = t52;
890
+ return observer.next(entry.isIntersecting);
891
+ }, {
892
+ rootMargin: "0px",
893
+ threshold: 0
894
+ });
895
+ return ref?.current && ref.current instanceof HTMLElement && intersectionObserver.observe(ref.current), () => intersectionObserver.disconnect();
896
+ }).pipe(startWith(!1), distinctUntilChanged(), switchMap((isVisible) => isVisible ? new Observable((obs) => stateSource.subscribe(() => obs.next())) : EMPTY)).subscribe({
897
+ next: onStoreChanged
898
+ });
899
+ return () => subscription.unsubscribe();
900
+ }, $[4] = ref, $[5] = stateSource, $[6] = t4) : t4 = $[6];
901
+ const subscribe = t4;
902
+ let t5;
903
+ return $[7] !== _id || $[8] !== _type || $[9] !== instance || $[10] !== stateSource ? (t5 = () => {
904
+ const currentState = stateSource.getCurrent();
905
+ if (currentState.data === null)
906
+ throw resolvePreview(instance, {
907
+ document: {
908
+ _id,
909
+ _type
910
+ }
911
+ });
912
+ return currentState;
913
+ }, $[7] = _id, $[8] = _type, $[9] = instance, $[10] = stateSource, $[11] = t5) : t5 = $[11], useSyncExternalStore(subscribe, t5);
914
+ }
915
+ function useProjection(t0) {
916
+ const $ = c(14), {
917
+ document: t1,
918
+ projection,
919
+ ref
920
+ } = t0, {
921
+ _id,
922
+ _type
923
+ } = t1, instance = useSanityInstance();
924
+ let t2, t3;
925
+ $[0] !== _id || $[1] !== _type || $[2] !== instance || $[3] !== projection ? (t3 = getProjectionState(instance, {
926
+ document: {
927
+ _id,
928
+ _type
929
+ },
930
+ projection
931
+ }), $[0] = _id, $[1] = _type, $[2] = instance, $[3] = projection, $[4] = t3) : t3 = $[4], t2 = t3;
932
+ const stateSource = t2;
933
+ let t4;
934
+ $[5] !== ref || $[6] !== stateSource ? (t4 = (onStoreChanged) => {
935
+ const subscription = new Observable((observer) => {
936
+ if (typeof IntersectionObserver > "u" || typeof HTMLElement > "u")
937
+ return;
938
+ const intersectionObserver = new IntersectionObserver((t52) => {
939
+ const [entry] = t52;
940
+ return observer.next(entry.isIntersecting);
941
+ }, {
942
+ rootMargin: "0px",
943
+ threshold: 0
944
+ });
945
+ return ref?.current && ref.current instanceof HTMLElement && intersectionObserver.observe(ref.current), () => intersectionObserver.disconnect();
946
+ }).pipe(startWith(!1), distinctUntilChanged(), switchMap((isVisible) => isVisible ? new Observable((obs) => stateSource.subscribe(() => obs.next())) : EMPTY)).subscribe({
947
+ next: onStoreChanged
948
+ });
949
+ return () => subscription.unsubscribe();
950
+ }, $[5] = ref, $[6] = stateSource, $[7] = t4) : t4 = $[7];
951
+ const subscribe = t4;
952
+ let t5;
953
+ return $[8] !== _id || $[9] !== _type || $[10] !== instance || $[11] !== projection || $[12] !== stateSource ? (t5 = () => {
954
+ const currentState = stateSource.getCurrent();
955
+ if (currentState.data === null)
956
+ throw resolveProjection(instance, {
957
+ document: {
958
+ _id,
959
+ _type
960
+ },
961
+ projection
962
+ });
963
+ return currentState;
964
+ }, $[8] = _id, $[9] = _type, $[10] = instance, $[11] = projection, $[12] = stateSource, $[13] = t5) : t5 = $[13], useSyncExternalStore(subscribe, t5);
965
+ }
966
+ const useProject = createStateSourceHook({
967
+ // remove `undefined` since we're suspending when that is the case
968
+ getState: getProjectState,
969
+ shouldSuspend: (instance, projectId) => getProjectState(instance, projectId).getCurrent() === void 0,
970
+ suspender: resolveProject
971
+ }), useProjects = createStateSourceHook({
972
+ // remove `undefined` since we're suspending when that is the case
973
+ getState: getProjectsState,
974
+ shouldSuspend: (instance) => getProjectsState(instance).getCurrent() === void 0,
975
+ suspender: resolveProjects
976
+ });
977
+ function useUsers(params) {
978
+ const $ = c(15), instance = useSanityInstance(params.resourceId);
979
+ let t0;
980
+ $[0] !== instance ? (t0 = () => createUsersStore(instance), $[0] = instance, $[1] = t0) : t0 = $[1];
981
+ const [store] = useState(t0);
982
+ let t1, t2;
983
+ $[2] !== params.resourceId || $[3] !== params.resourceType || $[4] !== store ? (t1 = () => {
984
+ store.setOptions({
985
+ resourceType: params.resourceType,
986
+ resourceId: params.resourceId
987
+ });
988
+ }, 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);
989
+ let t3;
990
+ $[7] !== store ? (t3 = (onStoreChanged) => {
991
+ store.getState().getCurrent().initialFetchCompleted === !1 && store.resolveUsers();
992
+ const unsubscribe = store.getState().subscribe(onStoreChanged);
993
+ return () => {
994
+ unsubscribe(), store.dispose();
995
+ };
996
+ }, $[7] = store, $[8] = t3) : t3 = $[8];
997
+ const subscribe = t3;
998
+ let t4;
999
+ $[9] !== store ? (t4 = () => store.getState().getCurrent(), $[9] = store, $[10] = t4) : t4 = $[10];
1000
+ const getSnapshot = t4, {
1001
+ users,
1002
+ hasMore
1003
+ } = useSyncExternalStore(subscribe, getSnapshot) || {};
1004
+ let t5;
1005
+ return $[11] !== hasMore || $[12] !== store.loadMore || $[13] !== users ? (t5 = {
1006
+ users,
1007
+ hasMore,
1008
+ loadMore: store.loadMore
1009
+ }, $[11] = hasMore, $[12] = store.loadMore, $[13] = users, $[14] = t5) : t5 = $[14], t5;
1010
+ }
1011
+ var version = "0.0.0-rc.1";
1012
+ function getEnv(key) {
1013
+ if (typeof import.meta < "u" && import.meta.env)
1014
+ return import.meta.env[key];
1015
+ if (typeof process < "u" && process.env)
1016
+ return process.env[key];
1017
+ if (typeof window < "u" && window.ENV)
1018
+ return window.ENV?.[key];
2
1019
  }
1020
+ const REACT_SDK_VERSION = getEnv("PKG_VERSION") || `${version}-development`;
3
1021
  export {
4
- main
1022
+ AuthBoundary,
1023
+ REACT_SDK_VERSION,
1024
+ SDKProvider,
1025
+ SanityApp,
1026
+ SanityProvider,
1027
+ useApplyActions,
1028
+ useAuthState,
1029
+ useAuthToken,
1030
+ useClient,
1031
+ useCurrentUser,
1032
+ useDashboardOrganizationId,
1033
+ useDatasets,
1034
+ useDocument,
1035
+ useDocumentEvent,
1036
+ useDocumentSyncStatus,
1037
+ useEditDocument,
1038
+ useFrameConnection,
1039
+ useHandleCallback,
1040
+ useInfiniteList,
1041
+ useLogOut,
1042
+ useLoginUrls,
1043
+ useManageFavorite,
1044
+ useNavigateToStudioDocument,
1045
+ usePaginatedList,
1046
+ usePermissions,
1047
+ usePreview,
1048
+ useProject,
1049
+ useProjection,
1050
+ useProjects,
1051
+ useQuery,
1052
+ useRecordDocumentHistoryEvent,
1053
+ useSanityInstance,
1054
+ useStudioWorkspacesByResourceId,
1055
+ useUsers,
1056
+ useWindowConnection
5
1057
  };
6
1058
  //# sourceMappingURL=index.js.map