@sanity/sdk-react 0.0.0-alpha.2 → 0.0.0-alpha.21

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 (116) hide show
  1. package/README.md +38 -67
  2. package/dist/index.d.ts +4811 -2
  3. package/dist/index.js +1069 -2
  4. package/dist/index.js.map +1 -1
  5. package/package.json +27 -58
  6. package/src/_exports/index.ts +66 -10
  7. package/src/components/Login/LoginLinks.test.tsx +4 -14
  8. package/src/components/Login/LoginLinks.tsx +16 -31
  9. package/src/components/SDKProvider.test.tsx +79 -0
  10. package/src/components/SDKProvider.tsx +42 -0
  11. package/src/components/SanityApp.test.tsx +156 -0
  12. package/src/components/SanityApp.tsx +90 -0
  13. package/src/components/auth/AuthBoundary.test.tsx +6 -19
  14. package/src/components/auth/AuthBoundary.tsx +20 -4
  15. package/src/components/auth/Login.test.tsx +2 -16
  16. package/src/components/auth/Login.tsx +11 -30
  17. package/src/components/auth/LoginCallback.test.tsx +5 -20
  18. package/src/components/auth/LoginCallback.tsx +9 -14
  19. package/src/components/auth/LoginError.test.tsx +2 -17
  20. package/src/components/auth/LoginError.tsx +11 -16
  21. package/src/components/auth/LoginFooter.test.tsx +2 -16
  22. package/src/components/auth/LoginFooter.tsx +8 -24
  23. package/src/components/auth/LoginLayout.test.tsx +2 -16
  24. package/src/components/auth/LoginLayout.tsx +8 -38
  25. package/src/components/auth/authTestHelpers.tsx +11 -0
  26. package/src/components/utils.ts +22 -0
  27. package/src/context/SanityInstanceContext.ts +4 -0
  28. package/src/{components/context → context}/SanityProvider.test.tsx +2 -2
  29. package/src/context/SanityProvider.tsx +50 -0
  30. package/src/hooks/_synchronous-groq-js.mjs +4 -0
  31. package/src/hooks/auth/useAuthState.tsx +4 -5
  32. package/src/hooks/auth/useAuthToken.tsx +1 -1
  33. package/src/hooks/auth/useCurrentUser.tsx +28 -4
  34. package/src/hooks/auth/useDashboardOrganizationId.test.tsx +42 -0
  35. package/src/hooks/auth/useDashboardOrganizationId.tsx +29 -0
  36. package/src/hooks/auth/useHandleAuthCallback.test.tsx +16 -0
  37. package/src/hooks/auth/{useHandleCallback.tsx → useHandleAuthCallback.tsx} +7 -6
  38. package/src/hooks/auth/useLogOut.test.tsx +2 -2
  39. package/src/hooks/auth/useLogOut.tsx +1 -1
  40. package/src/hooks/auth/useLoginUrls.tsx +1 -0
  41. package/src/hooks/client/useClient.ts +9 -30
  42. package/src/hooks/comlink/useFrameConnection.test.tsx +167 -0
  43. package/src/hooks/comlink/useFrameConnection.ts +107 -0
  44. package/src/hooks/comlink/useManageFavorite.test.ts +111 -0
  45. package/src/hooks/comlink/useManageFavorite.ts +130 -0
  46. package/src/hooks/comlink/useRecordDocumentHistoryEvent.test.ts +81 -0
  47. package/src/hooks/comlink/useRecordDocumentHistoryEvent.ts +106 -0
  48. package/src/hooks/comlink/useWindowConnection.test.ts +135 -0
  49. package/src/hooks/comlink/useWindowConnection.ts +122 -0
  50. package/src/hooks/context/useSanityInstance.test.tsx +2 -2
  51. package/src/hooks/context/useSanityInstance.ts +24 -8
  52. package/src/hooks/dashboard/useNavigateToStudioDocument.test.ts +178 -0
  53. package/src/hooks/dashboard/useNavigateToStudioDocument.ts +123 -0
  54. package/src/hooks/dashboard/useStudioWorkspacesByResourceId.test.tsx +278 -0
  55. package/src/hooks/dashboard/useStudioWorkspacesByResourceId.ts +92 -0
  56. package/src/hooks/datasets/useDatasets.ts +40 -0
  57. package/src/hooks/document/useApplyDocumentActions.test.ts +25 -0
  58. package/src/hooks/document/useApplyDocumentActions.ts +75 -0
  59. package/src/hooks/document/useDocument.test.ts +81 -0
  60. package/src/hooks/document/useDocument.ts +107 -0
  61. package/src/hooks/document/useDocumentEvent.test.ts +63 -0
  62. package/src/hooks/document/useDocumentEvent.ts +54 -0
  63. package/src/hooks/document/useDocumentPermissions.ts +84 -0
  64. package/src/hooks/document/useDocumentSyncStatus.test.ts +16 -0
  65. package/src/hooks/document/useDocumentSyncStatus.ts +33 -0
  66. package/src/hooks/document/useEditDocument.test.ts +179 -0
  67. package/src/hooks/document/useEditDocument.ts +195 -0
  68. package/src/hooks/documents/useDocuments.test.tsx +152 -0
  69. package/src/hooks/documents/useDocuments.ts +174 -0
  70. package/src/hooks/helpers/createCallbackHook.tsx +3 -2
  71. package/src/hooks/helpers/createStateSourceHook.test.tsx +66 -0
  72. package/src/hooks/helpers/createStateSourceHook.tsx +29 -10
  73. package/src/hooks/paginatedDocuments/usePaginatedDocuments.test.tsx +259 -0
  74. package/src/hooks/paginatedDocuments/usePaginatedDocuments.ts +290 -0
  75. package/src/hooks/preview/usePreview.test.tsx +19 -10
  76. package/src/hooks/preview/usePreview.tsx +67 -13
  77. package/src/hooks/projection/useProjection.test.tsx +218 -0
  78. package/src/hooks/projection/useProjection.ts +147 -0
  79. package/src/hooks/projects/useProject.ts +48 -0
  80. package/src/hooks/projects/useProjects.ts +45 -0
  81. package/src/hooks/query/useQuery.test.tsx +188 -0
  82. package/src/hooks/query/useQuery.ts +103 -0
  83. package/src/hooks/users/useUsers.test.ts +163 -0
  84. package/src/hooks/users/useUsers.ts +107 -0
  85. package/src/utils/getEnv.ts +21 -0
  86. package/src/version.ts +8 -0
  87. package/src/vite-env.d.ts +10 -0
  88. package/dist/_chunks-es/useLogOut.js +0 -44
  89. package/dist/_chunks-es/useLogOut.js.map +0 -1
  90. package/dist/assets/bundle-CcAyERuZ.css +0 -11
  91. package/dist/components.d.ts +0 -257
  92. package/dist/components.js +0 -316
  93. package/dist/components.js.map +0 -1
  94. package/dist/hooks.d.ts +0 -187
  95. package/dist/hooks.js +0 -81
  96. package/dist/hooks.js.map +0 -1
  97. package/src/_exports/components.ts +0 -13
  98. package/src/_exports/hooks.ts +0 -9
  99. package/src/components/DocumentGridLayout/DocumentGridLayout.stories.tsx +0 -113
  100. package/src/components/DocumentGridLayout/DocumentGridLayout.test.tsx +0 -42
  101. package/src/components/DocumentGridLayout/DocumentGridLayout.tsx +0 -21
  102. package/src/components/DocumentListLayout/DocumentListLayout.stories.tsx +0 -105
  103. package/src/components/DocumentListLayout/DocumentListLayout.test.tsx +0 -42
  104. package/src/components/DocumentListLayout/DocumentListLayout.tsx +0 -12
  105. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.md +0 -49
  106. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.stories.tsx +0 -39
  107. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.test.tsx +0 -30
  108. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.tsx +0 -171
  109. package/src/components/context/SanityProvider.tsx +0 -42
  110. package/src/css/css.config.js +0 -220
  111. package/src/css/paramour.css +0 -2347
  112. package/src/css/styles.css +0 -11
  113. package/src/hooks/auth/useHandleCallback.test.tsx +0 -16
  114. package/src/hooks/client/useClient.test.tsx +0 -130
  115. package/src/hooks/documentCollection/useDocuments.test.ts +0 -130
  116. package/src/hooks/documentCollection/useDocuments.ts +0 -87
package/dist/index.js CHANGED
@@ -1,6 +1,1073 @@
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, handleAuthCallback, logout, AuthStateType, createSanityInstance, getTokenState, getCurrentUserState, getDashboardOrganizationId, getClientState, getOrCreateController, getOrCreateChannel, releaseChannel, getOrCreateNode, releaseNode, resolveDatasets, getDatasetsState, applyDocumentActions, getResourceId, resolveDocument, getDocumentState, subscribeDocumentEvents, getPermissionsState, getDocumentSyncStatus, editDocument, getQueryKey, parseQueryKey, getQueryState, resolveQuery, getPreviewState, resolvePreview, getProjectionState, resolveProjection, resolveProject, getProjectState, resolveProjects, getProjectsState, createUsersStore } from "@sanity/sdk";
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 useHandleAuthCallback = createCallbackHook(handleAuthCallback);
151
+ function LoginCallback(t0) {
152
+ const $ = c(7), {
153
+ header,
154
+ footer
155
+ } = t0, handleAuthCallback2 = useHandleAuthCallback();
156
+ let t1, t2;
157
+ $[0] !== handleAuthCallback2 ? (t1 = () => {
158
+ const url = new URL(location.href);
159
+ handleAuthCallback2(url.toString()).then(_temp$8);
160
+ }, t2 = [handleAuthCallback2], $[0] = handleAuthCallback2, $[1] = t1, $[2] = t2) : (t1 = $[1], t2 = $[2]), useEffect(t1, t2);
161
+ let t3;
162
+ $[3] === Symbol.for("react.memo_cache_sentinel") ? (t3 = /* @__PURE__ */ jsxs("div", { className: "sc-login-callback", children: [
163
+ /* @__PURE__ */ jsx("h1", { className: "sc-login-callback__title", children: "Logging you in\u2026" }),
164
+ /* @__PURE__ */ jsx("div", { className: "sc-login-callback__loading", children: "Loading\u2026" })
165
+ ] }), $[3] = t3) : t3 = $[3];
166
+ let t4;
167
+ return $[4] !== footer || $[5] !== header ? (t4 = /* @__PURE__ */ jsx(LoginLayout, { header, footer, children: t3 }), $[4] = footer, $[5] = header, $[6] = t4) : t4 = $[6], t4;
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(16), {
409
+ documentId,
410
+ documentType,
411
+ resourceId,
412
+ resourceType
413
+ } = t0, [isFavorited, setIsFavorited] = useState(!1), [status, setStatus] = useState("idle");
414
+ let t1;
415
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = {
416
+ name: SDK_NODE_NAME,
417
+ connectTo: SDK_CHANNEL_NAME,
418
+ onStatus: setStatus
419
+ }, $[0] = t1) : t1 = $[0];
420
+ const {
421
+ sendMessage
422
+ } = useWindowConnection(t1);
423
+ if (resourceType !== "studio" && !resourceId)
424
+ throw new Error("resourceId is required for media-library and canvas resources");
425
+ let t2;
426
+ $[1] !== documentId || $[2] !== documentType || $[3] !== resourceId || $[4] !== resourceType || $[5] !== sendMessage ? (t2 = (action, setFavoriteState) => {
427
+ if (!(!documentId || !documentType || !resourceType))
428
+ try {
429
+ const message = {
430
+ type: "dashboard/v1/events/favorite/mutate",
431
+ data: {
432
+ eventType: action,
433
+ documentId,
434
+ documentType,
435
+ resourceType,
436
+ resourceId
437
+ },
438
+ response: {
439
+ success: !0
440
+ }
441
+ };
442
+ sendMessage(message.type, message.data), setIsFavorited(setFavoriteState);
443
+ } catch (t32) {
444
+ const err = t32, error = err instanceof Error ? err : new Error("Failed to update favorite status");
445
+ throw console.error(`Failed to ${action === "added" ? "favorite" : "unfavorite"} document:`, error), error;
446
+ }
447
+ }, $[1] = documentId, $[2] = documentType, $[3] = resourceId, $[4] = resourceType, $[5] = sendMessage, $[6] = t2) : t2 = $[6];
448
+ const handleFavoriteAction = t2;
449
+ let t3;
450
+ $[7] !== handleFavoriteAction ? (t3 = () => handleFavoriteAction("added", !0), $[7] = handleFavoriteAction, $[8] = t3) : t3 = $[8];
451
+ const favorite = t3;
452
+ let t4;
453
+ $[9] !== handleFavoriteAction ? (t4 = () => handleFavoriteAction("removed", !1), $[9] = handleFavoriteAction, $[10] = t4) : t4 = $[10];
454
+ const unfavorite = t4, t5 = status === "connected";
455
+ let t6;
456
+ return $[11] !== favorite || $[12] !== isFavorited || $[13] !== t5 || $[14] !== unfavorite ? (t6 = {
457
+ favorite,
458
+ unfavorite,
459
+ isFavorited,
460
+ isConnected: t5
461
+ }, $[11] = favorite, $[12] = isFavorited, $[13] = t5, $[14] = unfavorite, $[15] = t6) : t6 = $[15], t6;
462
+ }
463
+ function useRecordDocumentHistoryEvent(t0) {
464
+ const $ = c(10), {
465
+ documentId,
466
+ documentType,
467
+ resourceType,
468
+ resourceId
469
+ } = t0, [status, setStatus] = useState("idle");
470
+ let t1;
471
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = {
472
+ name: SDK_NODE_NAME,
473
+ connectTo: SDK_CHANNEL_NAME,
474
+ onStatus: setStatus
475
+ }, $[0] = t1) : t1 = $[0];
476
+ const {
477
+ sendMessage
478
+ } = useWindowConnection(t1);
479
+ if (resourceType !== "studio" && !resourceId)
480
+ throw new Error("resourceId is required for media-library and canvas resources");
481
+ let t2;
482
+ $[1] !== documentId || $[2] !== documentType || $[3] !== resourceId || $[4] !== resourceType || $[5] !== sendMessage ? (t2 = (eventType) => {
483
+ try {
484
+ const message = {
485
+ type: "dashboard/v1/events/history",
486
+ data: {
487
+ eventType,
488
+ documentId,
489
+ documentType,
490
+ resourceType,
491
+ resourceId
492
+ }
493
+ };
494
+ sendMessage(message.type, message.data);
495
+ } catch (t32) {
496
+ const error = t32;
497
+ throw console.error("Failed to record history event:", error), error;
498
+ }
499
+ }, $[1] = documentId, $[2] = documentType, $[3] = resourceId, $[4] = resourceType, $[5] = sendMessage, $[6] = t2) : t2 = $[6];
500
+ const recordEvent = t2, t3 = status === "connected";
501
+ let t4;
502
+ return $[7] !== recordEvent || $[8] !== t3 ? (t4 = {
503
+ recordEvent,
504
+ isConnected: t3
505
+ }, $[7] = recordEvent, $[8] = t3, $[9] = t4) : t4 = $[9], t4;
506
+ }
507
+ function useStudioWorkspacesByResourceId() {
508
+ const $ = c(10);
509
+ let t0;
510
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = {}, $[0] = t0) : t0 = $[0];
511
+ const [workspacesByResourceId, setWorkspacesByResourceId] = useState(t0), [status, setStatus] = useState("idle"), [error, setError] = useState(null);
512
+ let t1;
513
+ $[1] === Symbol.for("react.memo_cache_sentinel") ? (t1 = {
514
+ name: SDK_NODE_NAME,
515
+ connectTo: SDK_CHANNEL_NAME,
516
+ onStatus: setStatus
517
+ }, $[1] = t1) : t1 = $[1];
518
+ const {
519
+ fetch
520
+ } = useWindowConnection(t1);
521
+ let t2, t3;
522
+ $[2] !== fetch || $[3] !== status ? (t2 = () => {
523
+ if (!fetch || status !== "connected")
524
+ return;
525
+ const fetchWorkspaces = async function(signal) {
526
+ try {
527
+ const data = await fetch("dashboard/v1/bridge/context", void 0, {
528
+ signal
529
+ }), workspaceMap = {};
530
+ data.context.availableResources.forEach((resource) => {
531
+ !resource.projectId || !resource.workspaces?.length || resource.workspaces.forEach((workspace) => {
532
+ const key = `${resource.projectId}:${workspace.dataset}`;
533
+ workspaceMap[key] || (workspaceMap[key] = []), workspaceMap[key].push(workspace);
534
+ });
535
+ }), setWorkspacesByResourceId(workspaceMap), setError(null);
536
+ } catch (t42) {
537
+ const err = t42;
538
+ if (err instanceof Error) {
539
+ if (err.name === "AbortError")
540
+ return;
541
+ setError("Failed to fetch workspaces");
542
+ }
543
+ }
544
+ }, controller = new AbortController();
545
+ return fetchWorkspaces(controller.signal), () => {
546
+ controller.abort();
547
+ };
548
+ }, t3 = [fetch, status], $[2] = fetch, $[3] = status, $[4] = t2, $[5] = t3) : (t2 = $[4], t3 = $[5]), useEffect(t2, t3);
549
+ const t4 = status === "connected";
550
+ let t5;
551
+ return $[6] !== error || $[7] !== t4 || $[8] !== workspacesByResourceId ? (t5 = {
552
+ workspacesByResourceId,
553
+ error,
554
+ isConnected: t4
555
+ }, $[6] = error, $[7] = t4, $[8] = workspacesByResourceId, $[9] = t5) : t5 = $[9], t5;
556
+ }
557
+ function useNavigateToStudioDocument(documentHandle) {
558
+ const $ = c(10), {
559
+ workspacesByResourceId,
560
+ isConnected: workspacesConnected
561
+ } = useStudioWorkspacesByResourceId(), [status, setStatus] = useState("idle");
562
+ let t0;
563
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = {
564
+ name: SDK_NODE_NAME,
565
+ connectTo: SDK_CHANNEL_NAME,
566
+ onStatus: setStatus
567
+ }, $[0] = t0) : t0 = $[0];
568
+ const {
569
+ sendMessage
570
+ } = useWindowConnection(t0);
571
+ let t1;
572
+ $[1] !== documentHandle || $[2] !== sendMessage || $[3] !== status || $[4] !== workspacesByResourceId || $[5] !== workspacesConnected ? (t1 = () => {
573
+ if (!workspacesConnected || status !== "connected" || !documentHandle.resourceId)
574
+ return;
575
+ const [, projectAndDataset] = documentHandle.resourceId.split(":"), [projectId, dataset] = projectAndDataset.split(".");
576
+ if (!projectId || !dataset)
577
+ return;
578
+ const workspaces = workspacesByResourceId[`${projectId}:${dataset}`];
579
+ if (!workspaces?.length) {
580
+ console.warn("No workspace found for document", documentHandle.resourceId);
581
+ return;
582
+ }
583
+ workspaces.length > 1 && (console.warn("Multiple workspaces found for document", documentHandle.resourceId), console.warn("Using the first one", workspaces[0]));
584
+ const message = {
585
+ type: "dashboard/v1/bridge/navigate-to-resource",
586
+ data: {
587
+ resourceId: workspaces[0]._ref,
588
+ resourceType: "studio",
589
+ path: `/intent/edit/id=${documentHandle._id};type=${documentHandle._type}`
590
+ }
591
+ };
592
+ sendMessage(message.type, message.data);
593
+ }, $[1] = documentHandle, $[2] = sendMessage, $[3] = status, $[4] = workspacesByResourceId, $[5] = workspacesConnected, $[6] = t1) : t1 = $[6];
594
+ const navigateToStudioDocument = t1, t2 = workspacesConnected && status === "connected";
595
+ let t3;
596
+ return $[7] !== navigateToStudioDocument || $[8] !== t2 ? (t3 = {
597
+ navigateToStudioDocument,
598
+ isConnected: t2
599
+ }, $[7] = navigateToStudioDocument, $[8] = t2, $[9] = t3) : t3 = $[9], t3;
600
+ }
601
+ const useDatasets = createStateSourceHook({
602
+ // remove `undefined` since we're suspending when that is the case
603
+ getState: getDatasetsState,
604
+ shouldSuspend: (instance) => getDatasetsState(instance).getCurrent() === void 0,
605
+ suspender: resolveDatasets
606
+ });
607
+ function useApplyDocumentActions(resourceId) {
608
+ return _useApplyDocumentActions(resourceId)();
609
+ }
610
+ const _useApplyDocumentActions = (resourceId) => createCallbackHook(applyDocumentActions, resourceId);
611
+ function useDocument(doc, path) {
612
+ return _useDocument(doc, path);
613
+ }
614
+ const _useDocument = createStateSourceHook({
615
+ getState: getDocumentState,
616
+ shouldSuspend: (instance, doc) => getDocumentState(instance, doc._id).getCurrent() === void 0,
617
+ suspender: resolveDocument,
618
+ getResourceId: (doc) => getResourceId(doc.resourceId)
619
+ });
620
+ function useDocumentEvent(handler, doc) {
621
+ const $ = c(8), ref = useRef(handler);
622
+ let t0;
623
+ $[0] !== handler ? (t0 = () => {
624
+ ref.current = handler;
625
+ }, $[0] = handler, $[1] = t0) : t0 = $[1], useInsertionEffect(t0);
626
+ let t1;
627
+ $[2] === Symbol.for("react.memo_cache_sentinel") ? (t1 = (documentEvent) => ref.current(documentEvent), $[2] = t1) : t1 = $[2];
628
+ const stableHandler = t1;
629
+ let t2;
630
+ $[3] !== doc.resourceId ? (t2 = getResourceId(doc.resourceId), $[3] = doc.resourceId, $[4] = t2) : t2 = $[4];
631
+ const instance = useSanityInstance(t2);
632
+ let t3, t4;
633
+ $[5] !== instance ? (t3 = () => subscribeDocumentEvents(instance, stableHandler), t4 = [instance, stableHandler], $[5] = instance, $[6] = t3, $[7] = t4) : (t3 = $[6], t4 = $[7]), useEffect(t3, t4);
634
+ }
635
+ function useDocumentPermissions(actions) {
636
+ const $ = c(5);
637
+ if (Array.isArray(actions)) {
638
+ const resourceIds = actions.map(_temp$3);
639
+ if (new Set(resourceIds).size !== 1)
640
+ throw new Error("All actions must have the same resourceId");
641
+ }
642
+ let t0;
643
+ $[0] !== actions ? (t0 = Array.isArray(actions) ? getResourceId(actions[0].resourceId) : getResourceId(actions.resourceId), $[0] = actions, $[1] = t0) : t0 = $[1];
644
+ const instance = useSanityInstance(t0);
645
+ if (getPermissionsState(instance, actions).getCurrent() === void 0)
646
+ throw firstValueFrom(getPermissionsState(instance, actions).observable.pipe(filter(_temp2$2)));
647
+ let t1, t2;
648
+ $[2] !== actions || $[3] !== instance ? (t2 = getPermissionsState(instance, actions), $[2] = actions, $[3] = instance, $[4] = t2) : t2 = $[4], t1 = t2;
649
+ const {
650
+ subscribe,
651
+ getCurrent
652
+ } = t1;
653
+ return useSyncExternalStore(subscribe, getCurrent);
654
+ }
655
+ function _temp2$2(result) {
656
+ return result !== void 0;
657
+ }
658
+ function _temp$3(action) {
659
+ return action.resourceId;
660
+ }
661
+ const useDocumentSyncStatus = createStateSourceHook(getDocumentSyncStatus), ignoredKeys = ["_id", "_type", "_createdAt", "_updatedAt", "_rev"];
662
+ function useEditDocument(doc, path) {
663
+ const $ = c(8);
664
+ let t0;
665
+ $[0] !== doc.resourceId ? (t0 = getResourceId(doc.resourceId), $[0] = doc.resourceId, $[1] = t0) : t0 = $[1];
666
+ const resourceId = t0, documentId = doc._id, instance = useSanityInstance(resourceId), apply = useApplyDocumentActions(resourceId);
667
+ if (getDocumentState(instance, documentId).getCurrent() === void 0)
668
+ throw resolveDocument(instance, documentId);
669
+ let t1;
670
+ return $[2] !== apply || $[3] !== doc || $[4] !== documentId || $[5] !== instance || $[6] !== path ? (t1 = (updater) => {
671
+ if (path) {
672
+ const nextValue = typeof updater == "function" ? updater(getDocumentState(instance, documentId, path).getCurrent()) : updater;
673
+ return apply(editDocument(doc, {
674
+ set: {
675
+ [path]: nextValue
676
+ }
677
+ }));
678
+ }
679
+ const current = getDocumentState(instance, documentId).getCurrent(), nextValue_0 = typeof updater == "function" ? updater(current) : updater;
680
+ if (typeof nextValue_0 != "object" || !nextValue_0)
681
+ throw new Error("No path was provided to `useEditDocument` and the value provided was not a document object.");
682
+ const editActions = Object.keys({
683
+ ...current,
684
+ ...nextValue_0
685
+ }).filter(_temp$2).filter((key_0) => current?.[key_0] !== nextValue_0[key_0]).map((key_1) => key_1 in nextValue_0 ? editDocument(doc, {
686
+ set: {
687
+ [key_1]: nextValue_0[key_1]
688
+ }
689
+ }) : editDocument(doc, {
690
+ unset: [key_1]
691
+ }));
692
+ return apply(editActions);
693
+ }, $[2] = apply, $[3] = doc, $[4] = documentId, $[5] = instance, $[6] = path, $[7] = t1) : t1 = $[7], t1;
694
+ }
695
+ function _temp$2(key) {
696
+ return !ignoredKeys.includes(key);
697
+ }
698
+ function useQuery(query, options) {
699
+ const instance = useSanityInstance(options?.resourceId), [isPending, startTransition] = useTransition(), queryKey = getQueryKey(query, options), [deferredQueryKey, setDeferredQueryKey] = useState(queryKey), deferred = useMemo(() => parseQueryKey(deferredQueryKey), [deferredQueryKey]), [ref, setRef] = useState(new AbortController());
700
+ useEffect(() => {
701
+ queryKey !== deferredQueryKey && startTransition(() => {
702
+ ref && !ref.signal.aborted && (ref.abort(), setRef(new AbortController())), setDeferredQueryKey(queryKey);
703
+ });
704
+ }, [deferredQueryKey, queryKey, ref]);
705
+ const {
706
+ getCurrent,
707
+ subscribe
708
+ } = useMemo(() => getQueryState(instance, deferred.query, deferred.options), [instance, deferred]);
709
+ if (getCurrent() === void 0)
710
+ throw resolveQuery(instance, deferred.query, {
711
+ ...deferred.options,
712
+ signal: ref.signal
713
+ });
714
+ return {
715
+ data: useSyncExternalStore(subscribe, getCurrent),
716
+ isPending
717
+ };
718
+ }
719
+ const DEFAULT_BATCH_SIZE = 25, DEFAULT_PERSPECTIVE$1 = "drafts";
720
+ function useDocuments(t0) {
721
+ const $ = c(31);
722
+ let filter2, options, orderings, params, search, t1;
723
+ $[0] !== t0 ? ({
724
+ batchSize: t1,
725
+ params,
726
+ search,
727
+ filter: filter2,
728
+ orderings,
729
+ ...options
730
+ } = t0, $[0] = t0, $[1] = filter2, $[2] = options, $[3] = orderings, $[4] = params, $[5] = search, $[6] = t1) : (filter2 = $[1], options = $[2], orderings = $[3], params = $[4], search = $[5], t1 = $[6]);
731
+ const batchSize = t1 === void 0 ? DEFAULT_BATCH_SIZE : t1, perspective = options.perspective ?? DEFAULT_PERSPECTIVE$1, [limit, setLimit] = useState(batchSize);
732
+ let t2;
733
+ $[7] !== batchSize || $[8] !== filter2 || $[9] !== orderings || $[10] !== params || $[11] !== search ? (t2 = JSON.stringify({
734
+ filter: filter2,
735
+ search,
736
+ params,
737
+ orderings,
738
+ batchSize
739
+ }), $[7] = batchSize, $[8] = filter2, $[9] = orderings, $[10] = params, $[11] = search, $[12] = t2) : t2 = $[12];
740
+ const key = t2;
741
+ let t3;
742
+ $[13] !== batchSize ? (t3 = () => {
743
+ setLimit(batchSize);
744
+ }, $[13] = batchSize, $[14] = t3) : t3 = $[14];
745
+ let t4;
746
+ $[15] !== batchSize || $[16] !== key ? (t4 = [key, batchSize], $[15] = batchSize, $[16] = key, $[17] = t4) : t4 = $[17], useEffect(t3, t4);
747
+ let t5;
748
+ const conditions = [];
749
+ search?.trim() && conditions.push(`[@] match text::query("${search.trim()}")`), filter2 && conditions.push(`(${filter2})`), t5 = conditions.length ? `[${conditions.join(" && ")}]` : "";
750
+ const filterClause = t5, orderClause = orderings ? `| order(${orderings.map(_temp2$1).join(",")})` : "", dataQuery = `*${filterClause}${orderClause}[0...${limit}]{_id,_type}`, countQuery = `count(*${filterClause})`;
751
+ let t6;
752
+ $[18] !== options || $[19] !== params || $[20] !== perspective ? (t6 = {
753
+ ...options,
754
+ params,
755
+ perspective
756
+ }, $[18] = options, $[19] = params, $[20] = perspective, $[21] = t6) : t6 = $[21];
757
+ const {
758
+ data: t7,
759
+ isPending
760
+ } = useQuery(`{"count":${countQuery},"data":${dataQuery}}`, t6), {
761
+ count,
762
+ data
763
+ } = t7, hasMore = data.length < count;
764
+ let t8;
765
+ $[22] !== batchSize || $[23] !== count ? (t8 = () => {
766
+ setLimit((prev) => Math.min(prev + batchSize, count));
767
+ }, $[22] = batchSize, $[23] = count, $[24] = t8) : t8 = $[24];
768
+ const loadMore = t8;
769
+ let t9, t10;
770
+ return $[25] !== count || $[26] !== data || $[27] !== hasMore || $[28] !== isPending || $[29] !== loadMore ? (t10 = {
771
+ data,
772
+ hasMore,
773
+ count,
774
+ isPending,
775
+ loadMore
776
+ }, $[25] = count, $[26] = data, $[27] = hasMore, $[28] = isPending, $[29] = loadMore, $[30] = t10) : t10 = $[30], t9 = t10, t9;
777
+ }
778
+ function _temp2$1(ordering) {
779
+ return [ordering.field, ordering.direction.toLowerCase()].map(_temp$1).filter(Boolean).join(" ");
780
+ }
781
+ function _temp$1(str) {
782
+ return str.trim();
783
+ }
784
+ const DEFAULT_PERSPECTIVE = "drafts";
785
+ function usePaginatedDocuments(t0) {
786
+ const $ = c(48);
787
+ let t1;
788
+ $[0] !== t0 ? (t1 = t0 === void 0 ? {} : t0, $[0] = t0, $[1] = t1) : t1 = $[1];
789
+ let options, orderings, search, t2, t3, t4;
790
+ $[2] !== t1 ? ({
791
+ filter: t2,
792
+ pageSize: t3,
793
+ params: t4,
794
+ orderings,
795
+ search,
796
+ ...options
797
+ } = t1, $[2] = t1, $[3] = options, $[4] = orderings, $[5] = search, $[6] = t2, $[7] = t3, $[8] = t4) : (options = $[3], orderings = $[4], search = $[5], t2 = $[6], t3 = $[7], t4 = $[8]);
798
+ const filter2 = t2 === void 0 ? "" : t2, pageSize = t3 === void 0 ? 25 : t3;
799
+ let t5;
800
+ $[9] !== t4 ? (t5 = t4 === void 0 ? {} : t4, $[9] = t4, $[10] = t5) : t5 = $[10];
801
+ const params = t5, [pageIndex, setPageIndex] = useState(0);
802
+ let t6;
803
+ $[11] !== filter2 || $[12] !== orderings || $[13] !== pageSize || $[14] !== params || $[15] !== search ? (t6 = JSON.stringify({
804
+ filter: filter2,
805
+ search,
806
+ params,
807
+ orderings,
808
+ pageSize
809
+ }), $[11] = filter2, $[12] = orderings, $[13] = pageSize, $[14] = params, $[15] = search, $[16] = t6) : t6 = $[16];
810
+ const key = t6;
811
+ let t7;
812
+ $[17] === Symbol.for("react.memo_cache_sentinel") ? (t7 = () => {
813
+ setPageIndex(0);
814
+ }, $[17] = t7) : t7 = $[17];
815
+ let t8;
816
+ $[18] !== key ? (t8 = [key], $[18] = key, $[19] = t8) : t8 = $[19], useEffect(t7, t8);
817
+ const startIndex = pageIndex * pageSize, endIndex = (pageIndex + 1) * pageSize, perspective = options.perspective ?? DEFAULT_PERSPECTIVE;
818
+ let t9;
819
+ const conditions = [];
820
+ search?.trim() && conditions.push(`[@] match text::query("${search.trim()}")`), filter2 && conditions.push(`(${filter2})`), t9 = conditions.length ? `[${conditions.join(" && ")}]` : "";
821
+ const filterClause = t9, orderClause = orderings ? `| order(${orderings.map(_temp2).join(",")})` : "", dataQuery = `*${filterClause}${orderClause}[${startIndex}...${endIndex}]{_id,_type}`, countQuery = `count(*${filterClause})`;
822
+ let t10;
823
+ $[20] !== options || $[21] !== params || $[22] !== perspective ? (t10 = {
824
+ ...options,
825
+ perspective,
826
+ params
827
+ }, $[20] = options, $[21] = params, $[22] = perspective, $[23] = t10) : t10 = $[23];
828
+ const {
829
+ data: t11,
830
+ isPending
831
+ } = useQuery(`{"data":${dataQuery},"count":${countQuery}}`, t10), {
832
+ data,
833
+ count
834
+ } = t11, totalPages = Math.ceil(count / pageSize), currentPage = pageIndex + 1;
835
+ let t12;
836
+ $[24] === Symbol.for("react.memo_cache_sentinel") ? (t12 = () => setPageIndex(0), $[24] = t12) : t12 = $[24];
837
+ const firstPage = t12;
838
+ let t13;
839
+ $[25] === Symbol.for("react.memo_cache_sentinel") ? (t13 = () => setPageIndex(_temp3), $[25] = t13) : t13 = $[25];
840
+ const previousPage = t13;
841
+ let t14;
842
+ $[26] !== totalPages ? (t14 = () => setPageIndex((prev_0) => Math.min(prev_0 + 1, totalPages - 1)), $[26] = totalPages, $[27] = t14) : t14 = $[27];
843
+ const nextPage = t14;
844
+ let t15;
845
+ $[28] !== totalPages ? (t15 = () => setPageIndex(totalPages - 1), $[28] = totalPages, $[29] = t15) : t15 = $[29];
846
+ const lastPage = t15;
847
+ let t16;
848
+ $[30] !== totalPages ? (t16 = (pageNumber) => {
849
+ pageNumber < 1 || pageNumber > totalPages || setPageIndex(pageNumber - 1);
850
+ }, $[30] = totalPages, $[31] = t16) : t16 = $[31];
851
+ const goToPage = t16, hasFirstPage = pageIndex > 0, hasPreviousPage = pageIndex > 0, hasNextPage = pageIndex < totalPages - 1, hasLastPage = pageIndex < totalPages - 1;
852
+ let t17, t18;
853
+ return $[32] !== count || $[33] !== currentPage || $[34] !== data || $[35] !== endIndex || $[36] !== goToPage || $[37] !== hasFirstPage || $[38] !== hasLastPage || $[39] !== hasNextPage || $[40] !== hasPreviousPage || $[41] !== isPending || $[42] !== lastPage || $[43] !== nextPage || $[44] !== pageSize || $[45] !== startIndex || $[46] !== totalPages ? (t18 = {
854
+ data,
855
+ isPending,
856
+ pageSize,
857
+ currentPage,
858
+ totalPages,
859
+ startIndex,
860
+ endIndex,
861
+ count,
862
+ firstPage,
863
+ hasFirstPage,
864
+ previousPage,
865
+ hasPreviousPage,
866
+ nextPage,
867
+ hasNextPage,
868
+ lastPage,
869
+ hasLastPage,
870
+ goToPage
871
+ }, $[32] = count, $[33] = currentPage, $[34] = data, $[35] = endIndex, $[36] = goToPage, $[37] = hasFirstPage, $[38] = hasLastPage, $[39] = hasNextPage, $[40] = hasPreviousPage, $[41] = isPending, $[42] = lastPage, $[43] = nextPage, $[44] = pageSize, $[45] = startIndex, $[46] = totalPages, $[47] = t18) : t18 = $[47], t17 = t18, t17;
872
+ }
873
+ function _temp3(prev) {
874
+ return Math.max(prev - 1, 0);
875
+ }
876
+ function _temp2(ordering) {
877
+ return [ordering.field, ordering.direction.toLowerCase()].map(_temp).filter(Boolean).join(" ");
878
+ }
879
+ function _temp(str) {
880
+ return str.trim();
881
+ }
882
+ function usePreview(t0) {
883
+ const $ = c(12), {
884
+ document: t1,
885
+ ref
886
+ } = t0, {
887
+ _id,
888
+ _type
889
+ } = t1, instance = useSanityInstance();
890
+ let t2, t3;
891
+ $[0] !== _id || $[1] !== _type || $[2] !== instance ? (t3 = getPreviewState(instance, {
892
+ document: {
893
+ _id,
894
+ _type
895
+ }
896
+ }), $[0] = _id, $[1] = _type, $[2] = instance, $[3] = t3) : t3 = $[3], t2 = t3;
897
+ const stateSource = t2;
898
+ let t4;
899
+ $[4] !== ref || $[5] !== stateSource ? (t4 = (onStoreChanged) => {
900
+ const subscription = new Observable((observer) => {
901
+ if (typeof IntersectionObserver > "u" || typeof HTMLElement > "u")
902
+ return;
903
+ const intersectionObserver = new IntersectionObserver((t52) => {
904
+ const [entry] = t52;
905
+ return observer.next(entry.isIntersecting);
906
+ }, {
907
+ rootMargin: "0px",
908
+ threshold: 0
909
+ });
910
+ return ref?.current && ref.current instanceof HTMLElement && intersectionObserver.observe(ref.current), () => intersectionObserver.disconnect();
911
+ }).pipe(startWith(!1), distinctUntilChanged(), switchMap((isVisible) => isVisible ? new Observable((obs) => stateSource.subscribe(() => obs.next())) : EMPTY)).subscribe({
912
+ next: onStoreChanged
913
+ });
914
+ return () => subscription.unsubscribe();
915
+ }, $[4] = ref, $[5] = stateSource, $[6] = t4) : t4 = $[6];
916
+ const subscribe = t4;
917
+ let t5;
918
+ return $[7] !== _id || $[8] !== _type || $[9] !== instance || $[10] !== stateSource ? (t5 = () => {
919
+ const currentState = stateSource.getCurrent();
920
+ if (currentState.data === null)
921
+ throw resolvePreview(instance, {
922
+ document: {
923
+ _id,
924
+ _type
925
+ }
926
+ });
927
+ return currentState;
928
+ }, $[7] = _id, $[8] = _type, $[9] = instance, $[10] = stateSource, $[11] = t5) : t5 = $[11], useSyncExternalStore(subscribe, t5);
929
+ }
930
+ function useProjection(t0) {
931
+ const $ = c(14), {
932
+ document: t1,
933
+ projection,
934
+ ref
935
+ } = t0, {
936
+ _id,
937
+ _type
938
+ } = t1, instance = useSanityInstance();
939
+ let t2, t3;
940
+ $[0] !== _id || $[1] !== _type || $[2] !== instance || $[3] !== projection ? (t3 = getProjectionState(instance, {
941
+ document: {
942
+ _id,
943
+ _type
944
+ },
945
+ projection
946
+ }), $[0] = _id, $[1] = _type, $[2] = instance, $[3] = projection, $[4] = t3) : t3 = $[4], t2 = t3;
947
+ const stateSource = t2;
948
+ let t4;
949
+ $[5] !== ref || $[6] !== stateSource ? (t4 = (onStoreChanged) => {
950
+ const subscription = new Observable((observer) => {
951
+ if (typeof IntersectionObserver > "u" || typeof HTMLElement > "u")
952
+ return;
953
+ const intersectionObserver = new IntersectionObserver((t52) => {
954
+ const [entry] = t52;
955
+ return observer.next(entry.isIntersecting);
956
+ }, {
957
+ rootMargin: "0px",
958
+ threshold: 0
959
+ });
960
+ return ref?.current && ref.current instanceof HTMLElement && intersectionObserver.observe(ref.current), () => intersectionObserver.disconnect();
961
+ }).pipe(startWith(!1), distinctUntilChanged(), switchMap((isVisible) => isVisible ? new Observable((obs) => stateSource.subscribe(() => obs.next())) : EMPTY)).subscribe({
962
+ next: onStoreChanged
963
+ });
964
+ return () => subscription.unsubscribe();
965
+ }, $[5] = ref, $[6] = stateSource, $[7] = t4) : t4 = $[7];
966
+ const subscribe = t4;
967
+ let t5;
968
+ return $[8] !== _id || $[9] !== _type || $[10] !== instance || $[11] !== projection || $[12] !== stateSource ? (t5 = () => {
969
+ const currentState = stateSource.getCurrent();
970
+ if (currentState.data === null)
971
+ throw resolveProjection(instance, {
972
+ document: {
973
+ _id,
974
+ _type
975
+ },
976
+ projection
977
+ });
978
+ return currentState;
979
+ }, $[8] = _id, $[9] = _type, $[10] = instance, $[11] = projection, $[12] = stateSource, $[13] = t5) : t5 = $[13], useSyncExternalStore(subscribe, t5);
980
+ }
981
+ const useProject = createStateSourceHook({
982
+ // remove `undefined` since we're suspending when that is the case
983
+ getState: getProjectState,
984
+ shouldSuspend: (instance, projectId) => getProjectState(instance, projectId).getCurrent() === void 0,
985
+ suspender: resolveProject
986
+ }), useProjects = createStateSourceHook({
987
+ // remove `undefined` since we're suspending when that is the case
988
+ getState: getProjectsState,
989
+ shouldSuspend: (instance) => getProjectsState(instance).getCurrent() === void 0,
990
+ suspender: resolveProjects
991
+ });
992
+ function useUsers(params) {
993
+ const $ = c(15), instance = useSanityInstance(params.resourceId);
994
+ let t0;
995
+ $[0] !== instance ? (t0 = () => createUsersStore(instance), $[0] = instance, $[1] = t0) : t0 = $[1];
996
+ const [store] = useState(t0);
997
+ let t1, t2;
998
+ $[2] !== params.resourceId || $[3] !== params.resourceType || $[4] !== store ? (t1 = () => {
999
+ store.setOptions({
1000
+ resourceType: params.resourceType,
1001
+ resourceId: params.resourceId
1002
+ });
1003
+ }, t2 = [params.resourceType, params.resourceId, store], $[2] = params.resourceId, $[3] = params.resourceType, $[4] = store, $[5] = t1, $[6] = t2) : (t1 = $[5], t2 = $[6]), useEffect(t1, t2);
1004
+ let t3;
1005
+ $[7] !== store ? (t3 = (onStoreChanged) => {
1006
+ store.getState().getCurrent().initialFetchCompleted === !1 && store.resolveUsers();
1007
+ const unsubscribe = store.getState().subscribe(onStoreChanged);
1008
+ return () => {
1009
+ unsubscribe(), store.dispose();
1010
+ };
1011
+ }, $[7] = store, $[8] = t3) : t3 = $[8];
1012
+ const subscribe = t3;
1013
+ let t4;
1014
+ $[9] !== store ? (t4 = () => store.getState().getCurrent(), $[9] = store, $[10] = t4) : t4 = $[10];
1015
+ const getSnapshot = t4, {
1016
+ users,
1017
+ hasMore
1018
+ } = useSyncExternalStore(subscribe, getSnapshot) || {};
1019
+ let t5;
1020
+ return $[11] !== hasMore || $[12] !== store.loadMore || $[13] !== users ? (t5 = {
1021
+ users,
1022
+ hasMore,
1023
+ loadMore: store.loadMore
1024
+ }, $[11] = hasMore, $[12] = store.loadMore, $[13] = users, $[14] = t5) : t5 = $[14], t5;
1025
+ }
1026
+ var version = "0.0.0-alpha.21";
1027
+ function getEnv(key) {
1028
+ if (typeof import.meta < "u" && import.meta.env)
1029
+ return import.meta.env[key];
1030
+ if (typeof process < "u" && process.env)
1031
+ return process.env[key];
1032
+ if (typeof window < "u" && window.ENV)
1033
+ return window.ENV?.[key];
2
1034
  }
1035
+ const REACT_SDK_VERSION = getEnv("PKG_VERSION") || `${version}-development`;
3
1036
  export {
4
- main
1037
+ AuthBoundary,
1038
+ REACT_SDK_VERSION,
1039
+ SDKProvider,
1040
+ SanityApp,
1041
+ SanityProvider,
1042
+ useApplyDocumentActions,
1043
+ useAuthState,
1044
+ useAuthToken,
1045
+ useClient,
1046
+ useCurrentUser,
1047
+ useDashboardOrganizationId,
1048
+ useDatasets,
1049
+ useDocument,
1050
+ useDocumentEvent,
1051
+ useDocumentPermissions,
1052
+ useDocumentSyncStatus,
1053
+ useDocuments,
1054
+ useEditDocument,
1055
+ useFrameConnection,
1056
+ useHandleAuthCallback,
1057
+ useLogOut,
1058
+ useLoginUrls,
1059
+ useManageFavorite,
1060
+ useNavigateToStudioDocument,
1061
+ usePaginatedDocuments,
1062
+ usePreview,
1063
+ useProject,
1064
+ useProjection,
1065
+ useProjects,
1066
+ useQuery,
1067
+ useRecordDocumentHistoryEvent,
1068
+ useSanityInstance,
1069
+ useStudioWorkspacesByResourceId,
1070
+ useUsers,
1071
+ useWindowConnection
5
1072
  };
6
1073
  //# sourceMappingURL=index.js.map