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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/README.md +33 -126
  2. package/dist/index.d.ts +4641 -2
  3. package/dist/index.js +960 -2
  4. package/dist/index.js.map +1 -1
  5. package/package.json +17 -41
  6. package/src/_exports/index.ts +58 -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/client/useClient.ts +8 -30
  30. package/src/hooks/comlink/useFrameConnection.test.tsx +45 -10
  31. package/src/hooks/comlink/useFrameConnection.ts +24 -5
  32. package/src/hooks/comlink/useManageFavorite.test.ts +106 -0
  33. package/src/hooks/comlink/useManageFavorite.ts +98 -0
  34. package/src/hooks/comlink/useRecordDocumentHistoryEvent.test.ts +77 -0
  35. package/src/hooks/comlink/useRecordDocumentHistoryEvent.ts +75 -0
  36. package/src/hooks/comlink/useWindowConnection.test.ts +43 -12
  37. package/src/hooks/comlink/useWindowConnection.ts +13 -1
  38. package/src/hooks/context/useSanityInstance.test.tsx +1 -1
  39. package/src/hooks/context/useSanityInstance.ts +21 -5
  40. package/src/hooks/datasets/useDatasets.ts +37 -0
  41. package/src/hooks/document/useApplyActions.test.ts +5 -4
  42. package/src/hooks/document/useApplyActions.ts +55 -5
  43. package/src/hooks/document/useDocument.test.ts +2 -2
  44. package/src/hooks/document/useDocument.ts +90 -21
  45. package/src/hooks/document/useDocumentEvent.test.ts +13 -3
  46. package/src/hooks/document/useDocumentEvent.ts +36 -4
  47. package/src/hooks/document/useDocumentSyncStatus.test.ts +1 -1
  48. package/src/hooks/document/useDocumentSyncStatus.ts +26 -2
  49. package/src/hooks/document/useEditDocument.test.ts +55 -10
  50. package/src/hooks/document/useEditDocument.ts +159 -31
  51. package/src/hooks/document/usePermissions.ts +82 -0
  52. package/src/hooks/helpers/createCallbackHook.tsx +3 -2
  53. package/src/hooks/helpers/createStateSourceHook.test.tsx +66 -0
  54. package/src/hooks/helpers/createStateSourceHook.tsx +29 -10
  55. package/src/hooks/infiniteList/useInfiniteList.test.tsx +152 -0
  56. package/src/hooks/infiniteList/useInfiniteList.ts +174 -0
  57. package/src/hooks/paginatedList/usePaginatedList.test.tsx +259 -0
  58. package/src/hooks/paginatedList/usePaginatedList.ts +290 -0
  59. package/src/hooks/preview/usePreview.tsx +7 -4
  60. package/src/hooks/projection/useProjection.test.tsx +218 -0
  61. package/src/hooks/projection/useProjection.ts +135 -0
  62. package/src/hooks/projects/useProject.ts +45 -0
  63. package/src/hooks/projects/useProjects.ts +41 -0
  64. package/src/hooks/query/useQuery.test.tsx +188 -0
  65. package/src/hooks/query/useQuery.ts +103 -0
  66. package/src/hooks/users/useUsers.test.ts +163 -0
  67. package/src/hooks/users/useUsers.ts +107 -0
  68. package/src/utils/getEnv.ts +21 -0
  69. package/src/version.ts +8 -0
  70. package/dist/_chunks-es/context.js +0 -8
  71. package/dist/_chunks-es/context.js.map +0 -1
  72. package/dist/_chunks-es/useLogOut.js +0 -45
  73. package/dist/_chunks-es/useLogOut.js.map +0 -1
  74. package/dist/components.d.ts +0 -111
  75. package/dist/components.js +0 -153
  76. package/dist/components.js.map +0 -1
  77. package/dist/context.d.ts +0 -45
  78. package/dist/context.js +0 -5
  79. package/dist/context.js.map +0 -1
  80. package/dist/hooks.d.ts +0 -3532
  81. package/dist/hooks.js +0 -218
  82. package/dist/hooks.js.map +0 -1
  83. package/src/_exports/components.ts +0 -2
  84. package/src/_exports/context.ts +0 -2
  85. package/src/_exports/hooks.ts +0 -32
  86. package/src/hooks/client/useClient.test.tsx +0 -130
  87. package/src/hooks/documentCollection/useDocuments.test.ts +0 -130
  88. package/src/hooks/documentCollection/useDocuments.ts +0 -135
package/dist/index.js CHANGED
@@ -1,6 +1,964 @@
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, 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, useState, useRef, 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), useClient = createStateSourceHook({
298
+ getState: getClientState,
299
+ getResourceId: (e) => e.resourceId
300
+ });
301
+ function useFrameConnection(options) {
302
+ const $ = c(27), {
303
+ onMessage,
304
+ targetOrigin,
305
+ name,
306
+ connectTo,
307
+ heartbeat
308
+ } = options, instance = useSanityInstance(), [status, setStatus] = useState("idle");
309
+ let t0, t1;
310
+ $[0] !== instance || $[1] !== targetOrigin ? (t1 = getOrCreateController(instance, targetOrigin), $[0] = instance, $[1] = targetOrigin, $[2] = t1) : t1 = $[2], t0 = t1;
311
+ const controller = t0;
312
+ let t2, t3;
313
+ $[3] !== connectTo || $[4] !== heartbeat || $[5] !== instance || $[6] !== name ? (t3 = getOrCreateChannel(instance, {
314
+ name,
315
+ connectTo,
316
+ heartbeat
317
+ }), $[3] = connectTo, $[4] = heartbeat, $[5] = instance, $[6] = name, $[7] = t3) : t3 = $[7], t2 = t3;
318
+ const channel = t2;
319
+ let t4, t5;
320
+ $[8] !== channel ? (t4 = () => channel ? channel.onStatus((event) => {
321
+ setStatus(event.status);
322
+ }) : void 0, t5 = [channel], $[8] = channel, $[9] = t4, $[10] = t5) : (t4 = $[9], t5 = $[10]), useEffect(t4, t5);
323
+ let t6, t7;
324
+ $[11] !== channel || $[12] !== onMessage ? (t6 = () => {
325
+ if (!channel || !onMessage)
326
+ return;
327
+ const unsubscribers = [];
328
+ return Object.entries(onMessage).forEach((t82) => {
329
+ const [type, handler] = t82, unsubscribe_0 = channel.on(type, handler);
330
+ unsubscribers.push(unsubscribe_0);
331
+ }), () => {
332
+ unsubscribers.forEach(_temp$5);
333
+ };
334
+ }, t7 = [channel, onMessage], $[11] = channel, $[12] = onMessage, $[13] = t6, $[14] = t7) : (t6 = $[13], t7 = $[14]), useEffect(t6, t7);
335
+ let t8;
336
+ $[15] !== controller ? (t8 = (frameWindow) => {
337
+ const removeTarget = controller?.addTarget(frameWindow);
338
+ return () => {
339
+ removeTarget?.();
340
+ };
341
+ }, $[15] = controller, $[16] = t8) : t8 = $[16];
342
+ const connect = t8;
343
+ let t9;
344
+ $[17] !== channel ? (t9 = (type_0, data) => {
345
+ channel?.post(type_0, data);
346
+ }, $[17] = channel, $[18] = t9) : t9 = $[18];
347
+ const sendMessage = t9;
348
+ let t10, t11;
349
+ $[19] !== instance || $[20] !== name ? (t10 = () => () => {
350
+ releaseChannel(instance, name);
351
+ }, t11 = [name, instance], $[19] = instance, $[20] = name, $[21] = t10, $[22] = t11) : (t10 = $[21], t11 = $[22]), useEffect(t10, t11);
352
+ let t12;
353
+ return $[23] !== connect || $[24] !== sendMessage || $[25] !== status ? (t12 = {
354
+ connect,
355
+ sendMessage,
356
+ status
357
+ }, $[23] = connect, $[24] = sendMessage, $[25] = status, $[26] = t12) : t12 = $[26], t12;
358
+ }
359
+ function _temp$5(unsub) {
360
+ return unsub();
361
+ }
362
+ function useWindowConnection(options) {
363
+ const $ = c(23), {
364
+ name,
365
+ onMessage,
366
+ connectTo
367
+ } = options, instance = useSanityInstance(), [status, setStatus] = useState("idle");
368
+ let t0, t1;
369
+ $[0] !== connectTo || $[1] !== instance || $[2] !== name ? (t1 = getOrCreateNode(instance, {
370
+ name,
371
+ connectTo
372
+ }), $[0] = connectTo, $[1] = instance, $[2] = name, $[3] = t1) : t1 = $[3], t0 = t1;
373
+ const node = t0;
374
+ let t2;
375
+ $[4] !== node ? (t2 = () => node.onStatus((newStatus) => {
376
+ setStatus(newStatus);
377
+ }), $[4] = node, $[5] = t2) : t2 = $[5];
378
+ let t3;
379
+ $[6] !== instance || $[7] !== name || $[8] !== node ? (t3 = [node, instance, name], $[6] = instance, $[7] = name, $[8] = node, $[9] = t3) : t3 = $[9], useEffect(t2, t3);
380
+ let t4, t5;
381
+ $[10] !== node || $[11] !== onMessage ? (t4 = () => {
382
+ if (!onMessage)
383
+ return;
384
+ const unsubscribers = [];
385
+ return Object.entries(onMessage).forEach((t62) => {
386
+ const [type, handler] = t62, unsubscribe_0 = node.on(type, handler);
387
+ unsubscribers.push(unsubscribe_0);
388
+ }), () => {
389
+ unsubscribers.forEach(_temp$4);
390
+ };
391
+ }, t5 = [node, onMessage], $[10] = node, $[11] = onMessage, $[12] = t4, $[13] = t5) : (t4 = $[12], t5 = $[13]), useEffect(t4, t5);
392
+ let t6;
393
+ $[14] !== node ? (t6 = (type_0, data) => {
394
+ node?.post(type_0, data);
395
+ }, $[14] = node, $[15] = t6) : t6 = $[15];
396
+ const sendMessage = t6;
397
+ let t7, t8;
398
+ $[16] !== instance || $[17] !== name ? (t7 = () => () => {
399
+ releaseNode(instance, name);
400
+ }, t8 = [instance, name], $[16] = instance, $[17] = name, $[18] = t7, $[19] = t8) : (t7 = $[18], t8 = $[19]), useEffect(t7, t8);
401
+ let t9;
402
+ return $[20] !== sendMessage || $[21] !== status ? (t9 = {
403
+ sendMessage,
404
+ status
405
+ }, $[20] = sendMessage, $[21] = status, $[22] = t9) : t9 = $[22], t9;
406
+ }
407
+ function _temp$4(unsub) {
408
+ return unsub();
409
+ }
410
+ function useManageFavorite(t0) {
411
+ const $ = c(14), {
412
+ _id,
413
+ _type
414
+ } = t0, [isFavorited, setIsFavorited] = useState(!1);
415
+ let t1;
416
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = {
417
+ name: SDK_NODE_NAME,
418
+ connectTo: SDK_CHANNEL_NAME
419
+ }, $[0] = t1) : t1 = $[0];
420
+ const {
421
+ sendMessage,
422
+ status
423
+ } = useWindowConnection(t1);
424
+ let t2;
425
+ $[1] !== _id || $[2] !== _type || $[3] !== sendMessage ? (t2 = (action, setFavoriteState) => {
426
+ if (!(!_id || !_type))
427
+ try {
428
+ const message = {
429
+ type: "core/v1/events/favorite",
430
+ data: {
431
+ eventType: action,
432
+ documentId: _id,
433
+ documentType: _type
434
+ }
435
+ };
436
+ sendMessage(message.type, message.data), setIsFavorited(setFavoriteState);
437
+ } catch (t32) {
438
+ const err = t32, error = err instanceof Error ? err : new Error("Failed to update favorite status");
439
+ throw console.error(`Failed to ${action === "added" ? "favorite" : "unfavorite"} document:`, error), error;
440
+ }
441
+ }, $[1] = _id, $[2] = _type, $[3] = sendMessage, $[4] = t2) : t2 = $[4];
442
+ const handleFavoriteAction = t2;
443
+ let t3;
444
+ $[5] !== handleFavoriteAction ? (t3 = () => handleFavoriteAction("added", !0), $[5] = handleFavoriteAction, $[6] = t3) : t3 = $[6];
445
+ const favorite = t3;
446
+ let t4;
447
+ $[7] !== handleFavoriteAction ? (t4 = () => handleFavoriteAction("removed", !1), $[7] = handleFavoriteAction, $[8] = t4) : t4 = $[8];
448
+ const unfavorite = t4, t5 = status === "connected";
449
+ let t6;
450
+ return $[9] !== favorite || $[10] !== isFavorited || $[11] !== t5 || $[12] !== unfavorite ? (t6 = {
451
+ favorite,
452
+ unfavorite,
453
+ isFavorited,
454
+ isConnected: t5
455
+ }, $[9] = favorite, $[10] = isFavorited, $[11] = t5, $[12] = unfavorite, $[13] = t6) : t6 = $[13], t6;
456
+ }
457
+ function useRecordDocumentHistoryEvent(t0) {
458
+ const $ = c(8), {
459
+ _id,
460
+ _type
461
+ } = t0;
462
+ let t1;
463
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = {
464
+ name: SDK_NODE_NAME,
465
+ connectTo: SDK_CHANNEL_NAME
466
+ }, $[0] = t1) : t1 = $[0];
467
+ const {
468
+ sendMessage,
469
+ status
470
+ } = useWindowConnection(t1);
471
+ let t2;
472
+ $[1] !== _id || $[2] !== _type || $[3] !== sendMessage ? (t2 = (eventType) => {
473
+ try {
474
+ const message = {
475
+ type: "core/v1/events/history",
476
+ data: {
477
+ eventType,
478
+ documentId: _id,
479
+ documentType: _type
480
+ }
481
+ };
482
+ sendMessage(message.type, message.data);
483
+ } catch (t32) {
484
+ const error = t32;
485
+ throw console.error("Failed to record history event:", error), error;
486
+ }
487
+ }, $[1] = _id, $[2] = _type, $[3] = sendMessage, $[4] = t2) : t2 = $[4];
488
+ const recordEvent = t2, t3 = status === "connected";
489
+ let t4;
490
+ return $[5] !== recordEvent || $[6] !== t3 ? (t4 = {
491
+ recordEvent,
492
+ isConnected: t3
493
+ }, $[5] = recordEvent, $[6] = t3, $[7] = t4) : t4 = $[7], t4;
494
+ }
495
+ const useDatasets = createStateSourceHook({
496
+ // remove `undefined` since we're suspending when that is the case
497
+ getState: getDatasetsState,
498
+ shouldSuspend: (instance) => getDatasetsState(instance).getCurrent() === void 0,
499
+ suspender: resolveDatasets
500
+ });
501
+ function useApplyActions(resourceId) {
502
+ return _useApplyActions(resourceId)();
503
+ }
504
+ const _useApplyActions = (resourceId) => createCallbackHook(applyActions, resourceId);
505
+ function useDocument(doc, path) {
506
+ return _useDocument(doc, path);
507
+ }
508
+ const _useDocument = createStateSourceHook({
509
+ getState: getDocumentState,
510
+ shouldSuspend: (instance, doc) => getDocumentState(instance, doc._id).getCurrent() === void 0,
511
+ suspender: resolveDocument,
512
+ getResourceId: (doc) => getResourceId(doc.resourceId)
513
+ });
514
+ function useDocumentEvent(handler, doc) {
515
+ const $ = c(8), ref = useRef(handler);
516
+ let t0;
517
+ $[0] !== handler ? (t0 = () => {
518
+ ref.current = handler;
519
+ }, $[0] = handler, $[1] = t0) : t0 = $[1], useInsertionEffect(t0);
520
+ let t1;
521
+ $[2] === Symbol.for("react.memo_cache_sentinel") ? (t1 = (documentEvent) => ref.current(documentEvent), $[2] = t1) : t1 = $[2];
522
+ const stableHandler = t1;
523
+ let t2;
524
+ $[3] !== doc.resourceId ? (t2 = getResourceId(doc.resourceId), $[3] = doc.resourceId, $[4] = t2) : t2 = $[4];
525
+ const instance = useSanityInstance(t2);
526
+ let t3, t4;
527
+ $[5] !== instance ? (t3 = () => subscribeDocumentEvents(instance, stableHandler), t4 = [instance, stableHandler], $[5] = instance, $[6] = t3, $[7] = t4) : (t3 = $[6], t4 = $[7]), useEffect(t3, t4);
528
+ }
529
+ const useDocumentSyncStatus = createStateSourceHook(getDocumentSyncStatus), ignoredKeys = ["_id", "_type", "_createdAt", "_updatedAt", "_rev"];
530
+ function useEditDocument(doc, path) {
531
+ const $ = c(8);
532
+ let t0;
533
+ $[0] !== doc.resourceId ? (t0 = getResourceId(doc.resourceId), $[0] = doc.resourceId, $[1] = t0) : t0 = $[1];
534
+ const resourceId = t0, documentId = doc._id, instance = useSanityInstance(resourceId), apply = useApplyActions(resourceId);
535
+ if (getDocumentState(instance, documentId).getCurrent() === void 0)
536
+ throw resolveDocument(instance, documentId);
537
+ let t1;
538
+ return $[2] !== apply || $[3] !== doc || $[4] !== documentId || $[5] !== instance || $[6] !== path ? (t1 = (updater) => {
539
+ if (path) {
540
+ const nextValue = typeof updater == "function" ? updater(getDocumentState(instance, documentId, path).getCurrent()) : updater;
541
+ return apply(editDocument(doc, {
542
+ set: {
543
+ [path]: nextValue
544
+ }
545
+ }));
546
+ }
547
+ const current = getDocumentState(instance, documentId).getCurrent(), nextValue_0 = typeof updater == "function" ? updater(current) : updater;
548
+ if (typeof nextValue_0 != "object" || !nextValue_0)
549
+ throw new Error("No path was provided to `useEditDocument` and the value provided was not a document object.");
550
+ const editActions = Object.keys({
551
+ ...current,
552
+ ...nextValue_0
553
+ }).filter(_temp$3).filter((key_0) => current?.[key_0] !== nextValue_0[key_0]).map((key_1) => key_1 in nextValue_0 ? editDocument(doc, {
554
+ set: {
555
+ [key_1]: nextValue_0[key_1]
556
+ }
557
+ }) : editDocument(doc, {
558
+ unset: [key_1]
559
+ }));
560
+ return apply(editActions);
561
+ }, $[2] = apply, $[3] = doc, $[4] = documentId, $[5] = instance, $[6] = path, $[7] = t1) : t1 = $[7], t1;
562
+ }
563
+ function _temp$3(key) {
564
+ return !ignoredKeys.includes(key);
565
+ }
566
+ function usePermissions(actions) {
567
+ const $ = c(5);
568
+ if (Array.isArray(actions)) {
569
+ const resourceIds = actions.map(_temp$2);
570
+ if (new Set(resourceIds).size !== 1)
571
+ throw new Error("All actions must have the same resourceId");
572
+ }
573
+ let t0;
574
+ $[0] !== actions ? (t0 = Array.isArray(actions) ? getResourceId(actions[0].resourceId) : getResourceId(actions.resourceId), $[0] = actions, $[1] = t0) : t0 = $[1];
575
+ const instance = useSanityInstance(t0);
576
+ if (getPermissionsState(instance, actions).getCurrent() === void 0)
577
+ throw firstValueFrom(getPermissionsState(instance, actions).observable.pipe(filter(_temp2$2)));
578
+ let t1, t2;
579
+ $[2] !== actions || $[3] !== instance ? (t2 = getPermissionsState(instance, actions), $[2] = actions, $[3] = instance, $[4] = t2) : t2 = $[4], t1 = t2;
580
+ const {
581
+ subscribe,
582
+ getCurrent
583
+ } = t1;
584
+ return useSyncExternalStore(subscribe, getCurrent);
585
+ }
586
+ function _temp2$2(result) {
587
+ return result !== void 0;
588
+ }
589
+ function _temp$2(action) {
590
+ return action.resourceId;
591
+ }
592
+ function useQuery(query, options) {
593
+ 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());
594
+ useEffect(() => {
595
+ queryKey !== deferredQueryKey && startTransition(() => {
596
+ ref && !ref.signal.aborted && (ref.abort(), setRef(new AbortController())), setDeferredQueryKey(queryKey);
597
+ });
598
+ }, [deferredQueryKey, queryKey, ref]);
599
+ const {
600
+ getCurrent,
601
+ subscribe
602
+ } = useMemo(() => getQueryState(instance, deferred.query, deferred.options), [instance, deferred]);
603
+ if (getCurrent() === void 0)
604
+ throw resolveQuery(instance, deferred.query, {
605
+ ...deferred.options,
606
+ signal: ref.signal
607
+ });
608
+ return {
609
+ data: useSyncExternalStore(subscribe, getCurrent),
610
+ isPending
611
+ };
612
+ }
613
+ const DEFAULT_BATCH_SIZE = 25, DEFAULT_PERSPECTIVE$1 = "drafts";
614
+ function useInfiniteList(t0) {
615
+ const $ = c(31);
616
+ let filter2, options, orderings, params, search, t1;
617
+ $[0] !== t0 ? ({
618
+ batchSize: t1,
619
+ params,
620
+ search,
621
+ filter: filter2,
622
+ orderings,
623
+ ...options
624
+ } = 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]);
625
+ const batchSize = t1 === void 0 ? DEFAULT_BATCH_SIZE : t1, perspective = options.perspective ?? DEFAULT_PERSPECTIVE$1, [limit, setLimit] = useState(batchSize);
626
+ let t2;
627
+ $[7] !== batchSize || $[8] !== filter2 || $[9] !== orderings || $[10] !== params || $[11] !== search ? (t2 = JSON.stringify({
628
+ filter: filter2,
629
+ search,
630
+ params,
631
+ orderings,
632
+ batchSize
633
+ }), $[7] = batchSize, $[8] = filter2, $[9] = orderings, $[10] = params, $[11] = search, $[12] = t2) : t2 = $[12];
634
+ const key = t2;
635
+ let t3;
636
+ $[13] !== batchSize ? (t3 = () => {
637
+ setLimit(batchSize);
638
+ }, $[13] = batchSize, $[14] = t3) : t3 = $[14];
639
+ let t4;
640
+ $[15] !== batchSize || $[16] !== key ? (t4 = [key, batchSize], $[15] = batchSize, $[16] = key, $[17] = t4) : t4 = $[17], useEffect(t3, t4);
641
+ let t5;
642
+ const conditions = [];
643
+ search?.trim() && conditions.push(`[@] match text::query("${search.trim()}")`), filter2 && conditions.push(`(${filter2})`), t5 = conditions.length ? `[${conditions.join(" && ")}]` : "";
644
+ const filterClause = t5, orderClause = orderings ? `| order(${orderings.map(_temp2$1).join(",")})` : "", dataQuery = `*${filterClause}${orderClause}[0...${limit}]{_id,_type}`, countQuery = `count(*${filterClause})`;
645
+ let t6;
646
+ $[18] !== options || $[19] !== params || $[20] !== perspective ? (t6 = {
647
+ ...options,
648
+ params,
649
+ perspective
650
+ }, $[18] = options, $[19] = params, $[20] = perspective, $[21] = t6) : t6 = $[21];
651
+ const {
652
+ data: t7,
653
+ isPending
654
+ } = useQuery(`{"count":${countQuery},"data":${dataQuery}}`, t6), {
655
+ count,
656
+ data
657
+ } = t7, hasMore = data.length < count;
658
+ let t8;
659
+ $[22] !== batchSize || $[23] !== count ? (t8 = () => {
660
+ setLimit((prev) => Math.min(prev + batchSize, count));
661
+ }, $[22] = batchSize, $[23] = count, $[24] = t8) : t8 = $[24];
662
+ const loadMore = t8;
663
+ let t9, t10;
664
+ return $[25] !== count || $[26] !== data || $[27] !== hasMore || $[28] !== isPending || $[29] !== loadMore ? (t10 = {
665
+ data,
666
+ hasMore,
667
+ count,
668
+ isPending,
669
+ loadMore
670
+ }, $[25] = count, $[26] = data, $[27] = hasMore, $[28] = isPending, $[29] = loadMore, $[30] = t10) : t10 = $[30], t9 = t10, t9;
671
+ }
672
+ function _temp2$1(ordering) {
673
+ return [ordering.field, ordering.direction.toLowerCase()].map(_temp$1).filter(Boolean).join(" ");
674
+ }
675
+ function _temp$1(str) {
676
+ return str.trim();
677
+ }
678
+ const DEFAULT_PERSPECTIVE = "drafts";
679
+ function usePaginatedList(t0) {
680
+ const $ = c(48);
681
+ let t1;
682
+ $[0] !== t0 ? (t1 = t0 === void 0 ? {} : t0, $[0] = t0, $[1] = t1) : t1 = $[1];
683
+ let options, orderings, search, t2, t3, t4;
684
+ $[2] !== t1 ? ({
685
+ filter: t2,
686
+ pageSize: t3,
687
+ params: t4,
688
+ orderings,
689
+ search,
690
+ ...options
691
+ } = 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]);
692
+ const filter2 = t2 === void 0 ? "" : t2, pageSize = t3 === void 0 ? 25 : t3;
693
+ let t5;
694
+ $[9] !== t4 ? (t5 = t4 === void 0 ? {} : t4, $[9] = t4, $[10] = t5) : t5 = $[10];
695
+ const params = t5, [pageIndex, setPageIndex] = useState(0);
696
+ let t6;
697
+ $[11] !== filter2 || $[12] !== orderings || $[13] !== pageSize || $[14] !== params || $[15] !== search ? (t6 = JSON.stringify({
698
+ filter: filter2,
699
+ search,
700
+ params,
701
+ orderings,
702
+ pageSize
703
+ }), $[11] = filter2, $[12] = orderings, $[13] = pageSize, $[14] = params, $[15] = search, $[16] = t6) : t6 = $[16];
704
+ const key = t6;
705
+ let t7;
706
+ $[17] === Symbol.for("react.memo_cache_sentinel") ? (t7 = () => {
707
+ setPageIndex(0);
708
+ }, $[17] = t7) : t7 = $[17];
709
+ let t8;
710
+ $[18] !== key ? (t8 = [key], $[18] = key, $[19] = t8) : t8 = $[19], useEffect(t7, t8);
711
+ const startIndex = pageIndex * pageSize, endIndex = (pageIndex + 1) * pageSize, perspective = options.perspective ?? DEFAULT_PERSPECTIVE;
712
+ let t9;
713
+ const conditions = [];
714
+ search?.trim() && conditions.push(`[@] match text::query("${search.trim()}")`), filter2 && conditions.push(`(${filter2})`), t9 = conditions.length ? `[${conditions.join(" && ")}]` : "";
715
+ const filterClause = t9, orderClause = orderings ? `| order(${orderings.map(_temp2).join(",")})` : "", dataQuery = `*${filterClause}${orderClause}[${startIndex}...${endIndex}]{_id,_type}`, countQuery = `count(*${filterClause})`;
716
+ let t10;
717
+ $[20] !== options || $[21] !== params || $[22] !== perspective ? (t10 = {
718
+ ...options,
719
+ perspective,
720
+ params
721
+ }, $[20] = options, $[21] = params, $[22] = perspective, $[23] = t10) : t10 = $[23];
722
+ const {
723
+ data: t11,
724
+ isPending
725
+ } = useQuery(`{"data":${dataQuery},"count":${countQuery}}`, t10), {
726
+ data,
727
+ count
728
+ } = t11, totalPages = Math.ceil(count / pageSize), currentPage = pageIndex + 1;
729
+ let t12;
730
+ $[24] === Symbol.for("react.memo_cache_sentinel") ? (t12 = () => setPageIndex(0), $[24] = t12) : t12 = $[24];
731
+ const firstPage = t12;
732
+ let t13;
733
+ $[25] === Symbol.for("react.memo_cache_sentinel") ? (t13 = () => setPageIndex(_temp3), $[25] = t13) : t13 = $[25];
734
+ const previousPage = t13;
735
+ let t14;
736
+ $[26] !== totalPages ? (t14 = () => setPageIndex((prev_0) => Math.min(prev_0 + 1, totalPages - 1)), $[26] = totalPages, $[27] = t14) : t14 = $[27];
737
+ const nextPage = t14;
738
+ let t15;
739
+ $[28] !== totalPages ? (t15 = () => setPageIndex(totalPages - 1), $[28] = totalPages, $[29] = t15) : t15 = $[29];
740
+ const lastPage = t15;
741
+ let t16;
742
+ $[30] !== totalPages ? (t16 = (pageNumber) => {
743
+ pageNumber < 1 || pageNumber > totalPages || setPageIndex(pageNumber - 1);
744
+ }, $[30] = totalPages, $[31] = t16) : t16 = $[31];
745
+ const goToPage = t16, hasFirstPage = pageIndex > 0, hasPreviousPage = pageIndex > 0, hasNextPage = pageIndex < totalPages - 1, hasLastPage = pageIndex < totalPages - 1;
746
+ let t17, t18;
747
+ 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 = {
748
+ data,
749
+ isPending,
750
+ pageSize,
751
+ currentPage,
752
+ totalPages,
753
+ startIndex,
754
+ endIndex,
755
+ count,
756
+ firstPage,
757
+ hasFirstPage,
758
+ previousPage,
759
+ hasPreviousPage,
760
+ nextPage,
761
+ hasNextPage,
762
+ lastPage,
763
+ hasLastPage,
764
+ goToPage
765
+ }, $[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;
766
+ }
767
+ function _temp3(prev) {
768
+ return Math.max(prev - 1, 0);
769
+ }
770
+ function _temp2(ordering) {
771
+ return [ordering.field, ordering.direction.toLowerCase()].map(_temp).filter(Boolean).join(" ");
772
+ }
773
+ function _temp(str) {
774
+ return str.trim();
775
+ }
776
+ function usePreview(t0) {
777
+ const $ = c(12), {
778
+ document: t1,
779
+ ref
780
+ } = t0, {
781
+ _id,
782
+ _type
783
+ } = t1, instance = useSanityInstance();
784
+ let t2, t3;
785
+ $[0] !== _id || $[1] !== _type || $[2] !== instance ? (t3 = getPreviewState(instance, {
786
+ document: {
787
+ _id,
788
+ _type
789
+ }
790
+ }), $[0] = _id, $[1] = _type, $[2] = instance, $[3] = t3) : t3 = $[3], t2 = t3;
791
+ const stateSource = t2;
792
+ let t4;
793
+ $[4] !== ref || $[5] !== stateSource ? (t4 = (onStoreChanged) => {
794
+ const subscription = new Observable((observer) => {
795
+ if (typeof IntersectionObserver > "u" || typeof HTMLElement > "u")
796
+ return;
797
+ const intersectionObserver = new IntersectionObserver((t52) => {
798
+ const [entry] = t52;
799
+ return observer.next(entry.isIntersecting);
800
+ }, {
801
+ rootMargin: "0px",
802
+ threshold: 0
803
+ });
804
+ return ref?.current && ref.current instanceof HTMLElement && intersectionObserver.observe(ref.current), () => intersectionObserver.disconnect();
805
+ }).pipe(startWith(!1), distinctUntilChanged(), switchMap((isVisible) => isVisible ? new Observable((obs) => stateSource.subscribe(() => obs.next())) : EMPTY)).subscribe({
806
+ next: onStoreChanged
807
+ });
808
+ return () => subscription.unsubscribe();
809
+ }, $[4] = ref, $[5] = stateSource, $[6] = t4) : t4 = $[6];
810
+ const subscribe = t4;
811
+ let t5;
812
+ return $[7] !== _id || $[8] !== _type || $[9] !== instance || $[10] !== stateSource ? (t5 = () => {
813
+ const currentState = stateSource.getCurrent();
814
+ if (currentState.results === null)
815
+ throw resolvePreview(instance, {
816
+ document: {
817
+ _id,
818
+ _type
819
+ }
820
+ });
821
+ return currentState;
822
+ }, $[7] = _id, $[8] = _type, $[9] = instance, $[10] = stateSource, $[11] = t5) : t5 = $[11], useSyncExternalStore(subscribe, t5);
823
+ }
824
+ function useProjection(t0) {
825
+ const $ = c(14), {
826
+ document: t1,
827
+ projection,
828
+ ref
829
+ } = t0, {
830
+ _id,
831
+ _type
832
+ } = t1, instance = useSanityInstance();
833
+ let t2, t3;
834
+ $[0] !== _id || $[1] !== _type || $[2] !== instance || $[3] !== projection ? (t3 = getProjectionState(instance, {
835
+ document: {
836
+ _id,
837
+ _type
838
+ },
839
+ projection
840
+ }), $[0] = _id, $[1] = _type, $[2] = instance, $[3] = projection, $[4] = t3) : t3 = $[4], t2 = t3;
841
+ const stateSource = t2;
842
+ let t4;
843
+ $[5] !== ref || $[6] !== stateSource ? (t4 = (onStoreChanged) => {
844
+ const subscription = new Observable((observer) => {
845
+ if (typeof IntersectionObserver > "u" || typeof HTMLElement > "u")
846
+ return;
847
+ const intersectionObserver = new IntersectionObserver((t52) => {
848
+ const [entry] = t52;
849
+ return observer.next(entry.isIntersecting);
850
+ }, {
851
+ rootMargin: "0px",
852
+ threshold: 0
853
+ });
854
+ return ref?.current && ref.current instanceof HTMLElement && intersectionObserver.observe(ref.current), () => intersectionObserver.disconnect();
855
+ }).pipe(startWith(!1), distinctUntilChanged(), switchMap((isVisible) => isVisible ? new Observable((obs) => stateSource.subscribe(() => obs.next())) : EMPTY)).subscribe({
856
+ next: onStoreChanged
857
+ });
858
+ return () => subscription.unsubscribe();
859
+ }, $[5] = ref, $[6] = stateSource, $[7] = t4) : t4 = $[7];
860
+ const subscribe = t4;
861
+ let t5;
862
+ return $[8] !== _id || $[9] !== _type || $[10] !== instance || $[11] !== projection || $[12] !== stateSource ? (t5 = () => {
863
+ const currentState = stateSource.getCurrent();
864
+ if (currentState.results === null)
865
+ throw resolveProjection(instance, {
866
+ document: {
867
+ _id,
868
+ _type
869
+ },
870
+ projection
871
+ });
872
+ return currentState;
873
+ }, $[8] = _id, $[9] = _type, $[10] = instance, $[11] = projection, $[12] = stateSource, $[13] = t5) : t5 = $[13], useSyncExternalStore(subscribe, t5);
874
+ }
875
+ const useProject = createStateSourceHook({
876
+ // remove `undefined` since we're suspending when that is the case
877
+ getState: getProjectState,
878
+ shouldSuspend: (instance, projectId) => getProjectState(instance, projectId).getCurrent() === void 0,
879
+ suspender: resolveProject
880
+ }), useProjects = createStateSourceHook({
881
+ // remove `undefined` since we're suspending when that is the case
882
+ getState: getProjectsState,
883
+ shouldSuspend: (instance) => getProjectsState(instance).getCurrent() === void 0,
884
+ suspender: resolveProjects
885
+ });
886
+ function useUsers(params) {
887
+ const $ = c(15), instance = useSanityInstance(params.resourceId);
888
+ let t0;
889
+ $[0] !== instance ? (t0 = () => createUsersStore(instance), $[0] = instance, $[1] = t0) : t0 = $[1];
890
+ const [store] = useState(t0);
891
+ let t1, t2;
892
+ $[2] !== params.resourceId || $[3] !== params.resourceType || $[4] !== store ? (t1 = () => {
893
+ store.setOptions({
894
+ resourceType: params.resourceType,
895
+ resourceId: params.resourceId
896
+ });
897
+ }, 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);
898
+ let t3;
899
+ $[7] !== store ? (t3 = (onStoreChanged) => {
900
+ store.getState().getCurrent().initialFetchCompleted === !1 && store.resolveUsers();
901
+ const unsubscribe = store.getState().subscribe(onStoreChanged);
902
+ return () => {
903
+ unsubscribe(), store.dispose();
904
+ };
905
+ }, $[7] = store, $[8] = t3) : t3 = $[8];
906
+ const subscribe = t3;
907
+ let t4;
908
+ $[9] !== store ? (t4 = () => store.getState().getCurrent(), $[9] = store, $[10] = t4) : t4 = $[10];
909
+ const getSnapshot = t4, {
910
+ users,
911
+ hasMore
912
+ } = useSyncExternalStore(subscribe, getSnapshot) || {};
913
+ let t5;
914
+ return $[11] !== hasMore || $[12] !== store.loadMore || $[13] !== users ? (t5 = {
915
+ users,
916
+ hasMore,
917
+ loadMore: store.loadMore
918
+ }, $[11] = hasMore, $[12] = store.loadMore, $[13] = users, $[14] = t5) : t5 = $[14], t5;
919
+ }
920
+ var version = "0.0.0-rc.0";
921
+ function getEnv(key) {
922
+ if (typeof import.meta < "u" && import.meta.env)
923
+ return import.meta.env[key];
924
+ if (typeof process < "u" && process.env)
925
+ return process.env[key];
926
+ if (typeof window < "u" && window.ENV)
927
+ return window.ENV?.[key];
2
928
  }
929
+ const REACT_SDK_VERSION = getEnv("PKG_VERSION") || `${version}-development`;
3
930
  export {
4
- main
931
+ AuthBoundary,
932
+ REACT_SDK_VERSION,
933
+ SDKProvider,
934
+ SanityApp,
935
+ SanityProvider,
936
+ useApplyActions,
937
+ useAuthState,
938
+ useAuthToken,
939
+ useClient,
940
+ useCurrentUser,
941
+ useDatasets,
942
+ useDocument,
943
+ useDocumentEvent,
944
+ useDocumentSyncStatus,
945
+ useEditDocument,
946
+ useFrameConnection,
947
+ useHandleCallback,
948
+ useInfiniteList,
949
+ useLogOut,
950
+ useLoginUrls,
951
+ useManageFavorite,
952
+ usePaginatedList,
953
+ usePermissions,
954
+ usePreview,
955
+ useProject,
956
+ useProjection,
957
+ useProjects,
958
+ useQuery,
959
+ useRecordDocumentHistoryEvent,
960
+ useSanityInstance,
961
+ useUsers,
962
+ useWindowConnection
5
963
  };
6
964
  //# sourceMappingURL=index.js.map