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