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