@sanity/sdk-react 2.0.0 → 2.0.2
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 +1 -1
- package/dist/index.d.ts +22 -5
- package/dist/index.js +140 -78
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/_exports/sdk-react.ts +1 -0
- package/src/components/auth/AuthBoundary.test.tsx +30 -19
- package/src/components/auth/AuthBoundary.tsx +6 -3
- package/src/components/auth/LoginError.tsx +13 -5
- package/src/context/ComlinkTokenRefresh.test.tsx +221 -0
- package/src/context/ComlinkTokenRefresh.tsx +140 -0
- package/src/hooks/preview/useDocumentPreview.tsx +13 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<a href="https://sanity.io">
|
|
3
|
-
<img src="https://cdn.sanity.io/images/3do82whm/next/
|
|
3
|
+
<img src="https://cdn.sanity.io/images/3do82whm/next/d6cf401d52c33b7a5a354a14ab7de94dea2f0c02-192x192.svg" />
|
|
4
4
|
</a>
|
|
5
5
|
<h1 align="center">Sanity App SDK (React)</h1>
|
|
6
6
|
</p>
|
package/dist/index.d.ts
CHANGED
|
@@ -21,7 +21,9 @@ import {PathChangeMessage} from '@sanity/message-protocol'
|
|
|
21
21
|
import {PerspectiveHandle} from '@sanity/sdk'
|
|
22
22
|
import {PreviewValue} from '@sanity/sdk'
|
|
23
23
|
import {ProjectHandle} from '@sanity/sdk'
|
|
24
|
+
import {PropsWithChildren} from 'react'
|
|
24
25
|
import {QueryOptions} from '@sanity/sdk'
|
|
26
|
+
import {default as React_2} from 'react'
|
|
25
27
|
import {ReactElement} from 'react'
|
|
26
28
|
import {ReactNode} from 'react'
|
|
27
29
|
import {ReleaseDocument} from '@sanity/sdk'
|
|
@@ -118,6 +120,13 @@ export declare interface AuthBoundaryProps {
|
|
|
118
120
|
*/
|
|
119
121
|
export declare type ComlinkStatus = 'idle' | 'handshaking' | 'connected' | 'disconnected'
|
|
120
122
|
|
|
123
|
+
/**
|
|
124
|
+
* This provider is used to provide the Comlink token refresh feature.
|
|
125
|
+
* It is used to automatically request a new token on 401 error if enabled.
|
|
126
|
+
* @public
|
|
127
|
+
*/
|
|
128
|
+
export declare const ComlinkTokenRefreshProvider: React_2.FC<PropsWithChildren>
|
|
129
|
+
|
|
121
130
|
declare interface DashboardResource {
|
|
122
131
|
id: string
|
|
123
132
|
name: string
|
|
@@ -1244,14 +1253,22 @@ export declare function useDocumentPermissions(
|
|
|
1244
1253
|
/**
|
|
1245
1254
|
* @public
|
|
1246
1255
|
*
|
|
1247
|
-
*
|
|
1256
|
+
* Attempts to infer preview values of a document (specified via a `DocumentHandle`),
|
|
1248
1257
|
* including the document’s `title`, `subtitle`, `media`, and `status`. These values are live and will update in realtime.
|
|
1249
1258
|
* To reduce unnecessary network requests for resolving the preview values, an optional `ref` can be passed to the hook so that preview
|
|
1250
1259
|
* resolution will only occur if the `ref` is intersecting the current viewport.
|
|
1251
1260
|
*
|
|
1261
|
+
* See remarks below for futher information.
|
|
1262
|
+
*
|
|
1263
|
+
* @remarks
|
|
1264
|
+
* Values returned by this hook may not be as expected. It is currently unable to read preview values as defined in your schema;
|
|
1265
|
+
* instead, it attempts to infer these preview values by checking against a basic set of potential fields on your document.
|
|
1266
|
+
* We are anticipating being able to significantly improve this hook’s functionality and output in a future release.
|
|
1267
|
+
* For now, we recommend using {@link useDocumentProjection} for rendering individual document fields (or projections of those fields).
|
|
1268
|
+
*
|
|
1252
1269
|
* @category Documents
|
|
1253
|
-
* @param options - The document handle for the document you want to
|
|
1254
|
-
* @returns The
|
|
1270
|
+
* @param options - The document handle for the document you want to infer preview values for, and an optional ref
|
|
1271
|
+
* @returns The inferred values for the given document and a boolean to indicate whether the resolution is pending
|
|
1255
1272
|
*
|
|
1256
1273
|
* @example Combining with useDocuments to render a collection of document previews
|
|
1257
1274
|
* ```
|
|
@@ -1307,9 +1324,9 @@ export declare interface useDocumentPreviewOptions extends DocumentHandle {
|
|
|
1307
1324
|
* @category Types
|
|
1308
1325
|
*/
|
|
1309
1326
|
export declare interface useDocumentPreviewResults {
|
|
1310
|
-
/** The results of
|
|
1327
|
+
/** The results of inferring the document’s preview values */
|
|
1311
1328
|
data: PreviewValue
|
|
1312
|
-
/** True when preview values are being refreshed */
|
|
1329
|
+
/** True when inferred preview values are being refreshed */
|
|
1313
1330
|
isPending: boolean
|
|
1314
1331
|
}
|
|
1315
1332
|
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { c } from "react-compiler-runtime";
|
|
3
|
-
import { getAuthState, getLoginUrlState, observeOrganizationVerificationState, handleAuthCallback, logout,
|
|
3
|
+
import { getAuthState, getNodeState, getIsInDashboardState, setAuthToken, AuthStateType, getLoginUrlState, observeOrganizationVerificationState, handleAuthCallback, logout, createSanityInstance, getTokenState, getCurrentUserState, getDashboardOrganizationId, getClientState, getOrCreateController, getOrCreateChannel, releaseChannel, 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, useRef, useEffect, useState, Suspense, useMemo, useCallback, useInsertionEffect, useTransition } from "react";
|
|
6
6
|
import { ErrorBoundary } from "react-error-boundary";
|
|
7
|
-
import { ClientError } from "@sanity/client";
|
|
8
|
-
import { identity, firstValueFrom, filter, Observable, startWith, distinctUntilChanged, switchMap, EMPTY } from "rxjs";
|
|
9
7
|
import { SDK_CHANNEL_NAME, SDK_NODE_NAME } from "@sanity/message-protocol";
|
|
8
|
+
import { firstValueFrom, filter, identity, Observable, startWith, distinctUntilChanged, switchMap, EMPTY } from "rxjs";
|
|
9
|
+
import { ClientError } from "@sanity/client";
|
|
10
10
|
import { pick } from "lodash-es";
|
|
11
11
|
const SanityInstanceContext = createContext(null), useSanityInstance = (config) => {
|
|
12
12
|
const $ = c(3), instance = useContext(SanityInstanceContext);
|
|
@@ -38,7 +38,116 @@ function createStateSourceHook(options) {
|
|
|
38
38
|
}
|
|
39
39
|
return useHook;
|
|
40
40
|
}
|
|
41
|
-
const useAuthState = createStateSourceHook(getAuthState)
|
|
41
|
+
const useAuthState = createStateSourceHook(getAuthState), useNodeState = createStateSourceHook({
|
|
42
|
+
getState: getNodeState,
|
|
43
|
+
shouldSuspend: (instance, nodeInput) => getNodeState(instance, nodeInput).getCurrent() === void 0,
|
|
44
|
+
suspender: (instance, nodeInput) => firstValueFrom(getNodeState(instance, nodeInput).observable.pipe(filter(Boolean)))
|
|
45
|
+
});
|
|
46
|
+
function useWindowConnection(t0) {
|
|
47
|
+
const $ = c(19), {
|
|
48
|
+
name,
|
|
49
|
+
connectTo,
|
|
50
|
+
onMessage
|
|
51
|
+
} = t0;
|
|
52
|
+
let t1;
|
|
53
|
+
$[0] !== connectTo || $[1] !== name ? (t1 = {
|
|
54
|
+
name,
|
|
55
|
+
connectTo
|
|
56
|
+
}, $[0] = connectTo, $[1] = name, $[2] = t1) : t1 = $[2];
|
|
57
|
+
const {
|
|
58
|
+
node
|
|
59
|
+
} = useNodeState(t1);
|
|
60
|
+
let t2;
|
|
61
|
+
$[3] === Symbol.for("react.memo_cache_sentinel") ? (t2 = [], $[3] = t2) : t2 = $[3];
|
|
62
|
+
const messageUnsubscribers = useRef(t2), instance = useSanityInstance();
|
|
63
|
+
let t3;
|
|
64
|
+
$[4] !== node || $[5] !== onMessage ? (t3 = () => (onMessage && Object.entries(onMessage).forEach((t42) => {
|
|
65
|
+
const [type, handler] = t42, messageUnsubscribe = node.on(type, handler);
|
|
66
|
+
messageUnsubscribe && messageUnsubscribers.current.push(messageUnsubscribe);
|
|
67
|
+
}), () => {
|
|
68
|
+
messageUnsubscribers.current.forEach(_temp$7), messageUnsubscribers.current = [];
|
|
69
|
+
}), $[4] = node, $[5] = onMessage, $[6] = t3) : t3 = $[6];
|
|
70
|
+
let t4;
|
|
71
|
+
$[7] !== instance || $[8] !== name || $[9] !== node || $[10] !== onMessage ? (t4 = [instance, name, onMessage, node], $[7] = instance, $[8] = name, $[9] = node, $[10] = onMessage, $[11] = t4) : t4 = $[11], useEffect(t3, t4);
|
|
72
|
+
let t5;
|
|
73
|
+
$[12] !== node ? (t5 = (type_0, data) => {
|
|
74
|
+
node.post(type_0, data);
|
|
75
|
+
}, $[12] = node, $[13] = t5) : t5 = $[13];
|
|
76
|
+
const sendMessage = t5;
|
|
77
|
+
let t6;
|
|
78
|
+
$[14] !== node ? (t6 = (type_1, data_0, fetchOptions) => node.fetch(type_1, data_0, fetchOptions ?? {}), $[14] = node, $[15] = t6) : t6 = $[15];
|
|
79
|
+
const fetch = t6;
|
|
80
|
+
let t7;
|
|
81
|
+
return $[16] !== fetch || $[17] !== sendMessage ? (t7 = {
|
|
82
|
+
sendMessage,
|
|
83
|
+
fetch
|
|
84
|
+
}, $[16] = fetch, $[17] = sendMessage, $[18] = t7) : t7 = $[18], t7;
|
|
85
|
+
}
|
|
86
|
+
function _temp$7(unsubscribe) {
|
|
87
|
+
return unsubscribe();
|
|
88
|
+
}
|
|
89
|
+
const DEFAULT_RESPONSE_TIMEOUT = 1e4;
|
|
90
|
+
function DashboardTokenRefresh(t0) {
|
|
91
|
+
const $ = c(14), {
|
|
92
|
+
children
|
|
93
|
+
} = t0, instance = useSanityInstance(), isTokenRefreshInProgress = useRef(!1), timeoutRef = useRef(null), processed401ErrorRef = useRef(null), authState = useAuthState();
|
|
94
|
+
let t1;
|
|
95
|
+
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = () => {
|
|
96
|
+
timeoutRef.current && (clearTimeout(timeoutRef.current), timeoutRef.current = null);
|
|
97
|
+
}, $[0] = t1) : t1 = $[0];
|
|
98
|
+
const clearRefreshTimeout = t1;
|
|
99
|
+
let t2;
|
|
100
|
+
$[1] === Symbol.for("react.memo_cache_sentinel") ? (t2 = {
|
|
101
|
+
name: SDK_NODE_NAME,
|
|
102
|
+
connectTo: SDK_CHANNEL_NAME
|
|
103
|
+
}, $[1] = t2) : t2 = $[1];
|
|
104
|
+
const windowConnection = useWindowConnection(t2);
|
|
105
|
+
let t3;
|
|
106
|
+
$[2] !== instance || $[3] !== windowConnection ? (t3 = async () => {
|
|
107
|
+
if (!isTokenRefreshInProgress.current) {
|
|
108
|
+
isTokenRefreshInProgress.current = !0, clearRefreshTimeout(), timeoutRef.current = setTimeout(() => {
|
|
109
|
+
isTokenRefreshInProgress.current && (isTokenRefreshInProgress.current = !1), timeoutRef.current = null;
|
|
110
|
+
}, DEFAULT_RESPONSE_TIMEOUT);
|
|
111
|
+
try {
|
|
112
|
+
const res = await windowConnection.fetch("dashboard/v1/auth/tokens/create");
|
|
113
|
+
if (clearRefreshTimeout(), res.token) {
|
|
114
|
+
setAuthToken(instance, res.token);
|
|
115
|
+
const errorContainer = document.getElementById("__sanityError");
|
|
116
|
+
errorContainer && Array.from(errorContainer.getElementsByTagName("div")).some(_temp$6) && errorContainer.remove();
|
|
117
|
+
}
|
|
118
|
+
isTokenRefreshInProgress.current = !1;
|
|
119
|
+
} catch {
|
|
120
|
+
isTokenRefreshInProgress.current = !1, clearRefreshTimeout();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}, $[2] = instance, $[3] = windowConnection, $[4] = t3) : t3 = $[4];
|
|
124
|
+
const requestNewToken = t3;
|
|
125
|
+
let t4, t5;
|
|
126
|
+
$[5] === Symbol.for("react.memo_cache_sentinel") ? (t4 = () => () => {
|
|
127
|
+
clearRefreshTimeout();
|
|
128
|
+
}, t5 = [clearRefreshTimeout], $[5] = t4, $[6] = t5) : (t4 = $[5], t5 = $[6]), useEffect(t4, t5);
|
|
129
|
+
let t6;
|
|
130
|
+
$[7] !== authState.error || $[8] !== authState.type || $[9] !== requestNewToken ? (t6 = () => {
|
|
131
|
+
const has401Error = authState.type === AuthStateType.ERROR && authState.error && authState.error?.statusCode === 401 && !isTokenRefreshInProgress.current && processed401ErrorRef.current !== authState.error, isLoggedOut = authState.type === AuthStateType.LOGGED_OUT && !isTokenRefreshInProgress.current;
|
|
132
|
+
has401Error || isLoggedOut ? (processed401ErrorRef.current = authState.type === AuthStateType.ERROR ? authState.error : void 0, requestNewToken()) : (authState.type !== AuthStateType.ERROR || processed401ErrorRef.current !== (authState.type === AuthStateType.ERROR ? authState.error : void 0)) && (processed401ErrorRef.current = null);
|
|
133
|
+
}, $[7] = authState.error, $[8] = authState.type, $[9] = requestNewToken, $[10] = t6) : t6 = $[10];
|
|
134
|
+
let t7;
|
|
135
|
+
return $[11] !== authState || $[12] !== requestNewToken ? (t7 = [authState, requestNewToken], $[11] = authState, $[12] = requestNewToken, $[13] = t7) : t7 = $[13], useEffect(t6, t7), children;
|
|
136
|
+
}
|
|
137
|
+
function _temp$6(div) {
|
|
138
|
+
return div.textContent?.includes("Uncaught error: Unauthorized - A valid session is required for this endpoint");
|
|
139
|
+
}
|
|
140
|
+
const ComlinkTokenRefreshProvider = (t0) => {
|
|
141
|
+
const $ = c(2), {
|
|
142
|
+
children
|
|
143
|
+
} = t0, instance = useSanityInstance();
|
|
144
|
+
let t1;
|
|
145
|
+
if (t1 = getIsInDashboardState(instance).getCurrent(), t1) {
|
|
146
|
+
let t2;
|
|
147
|
+
return $[0] !== children ? (t2 = /* @__PURE__ */ jsx(DashboardTokenRefresh, { children }), $[0] = children, $[1] = t2) : t2 = $[1], t2;
|
|
148
|
+
}
|
|
149
|
+
return children;
|
|
150
|
+
};
|
|
42
151
|
function useLoginUrl() {
|
|
43
152
|
const $ = c(2), instance = useSanityInstance();
|
|
44
153
|
let t0, t1;
|
|
@@ -96,19 +205,19 @@ function LoginCallback() {
|
|
|
96
205
|
let t0, t1;
|
|
97
206
|
return $[0] !== handleAuthCallback2 ? (t0 = () => {
|
|
98
207
|
const url = new URL(location.href);
|
|
99
|
-
handleAuthCallback2(url.toString()).then(_temp$
|
|
208
|
+
handleAuthCallback2(url.toString()).then(_temp$5);
|
|
100
209
|
}, t1 = [handleAuthCallback2], $[0] = handleAuthCallback2, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), useEffect(t0, t1), null;
|
|
101
210
|
}
|
|
102
|
-
function _temp$
|
|
211
|
+
function _temp$5(replacementLocation) {
|
|
103
212
|
replacementLocation && history.replaceState(null, "", replacementLocation);
|
|
104
213
|
}
|
|
105
214
|
const useLogOut = createCallbackHook(logout);
|
|
106
215
|
function LoginError(t0) {
|
|
107
|
-
const $ = c(
|
|
216
|
+
const $ = c(23), {
|
|
108
217
|
error,
|
|
109
218
|
resetErrorBoundary
|
|
110
219
|
} = t0;
|
|
111
|
-
if (!(error instanceof AuthError || error instanceof ConfigurationError))
|
|
220
|
+
if (!(error instanceof AuthError || error instanceof ConfigurationError || error instanceof ClientError))
|
|
112
221
|
throw error;
|
|
113
222
|
const logout2 = useLogOut(), authState = useAuthState(), [authErrorMessage, setAuthErrorMessage] = useState("Please try again or contact support if the problem persists.");
|
|
114
223
|
let t1;
|
|
@@ -117,36 +226,36 @@ function LoginError(t0) {
|
|
|
117
226
|
}, $[0] = logout2, $[1] = resetErrorBoundary, $[2] = t1) : t1 = $[2];
|
|
118
227
|
const handleRetry = t1;
|
|
119
228
|
let t2;
|
|
120
|
-
$[3] !== authState.
|
|
121
|
-
if (
|
|
122
|
-
if (
|
|
229
|
+
$[3] !== authState.type || $[4] !== error || $[5] !== handleRetry ? (t2 = () => {
|
|
230
|
+
if (error instanceof ClientError) {
|
|
231
|
+
if (error.statusCode === 401)
|
|
123
232
|
handleRetry();
|
|
124
|
-
else if (
|
|
125
|
-
const errorMessage =
|
|
233
|
+
else if (error.statusCode === 404) {
|
|
234
|
+
const errorMessage = error.response.body.message || "";
|
|
126
235
|
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.");
|
|
127
236
|
}
|
|
128
237
|
}
|
|
129
238
|
authState.type !== AuthStateType.ERROR && error instanceof ConfigurationError && setAuthErrorMessage(error.message);
|
|
130
|
-
}, $[3] = authState.
|
|
239
|
+
}, $[3] = authState.type, $[4] = error, $[5] = handleRetry, $[6] = t2) : t2 = $[6];
|
|
131
240
|
let t3;
|
|
132
|
-
$[
|
|
241
|
+
$[7] !== authState || $[8] !== error || $[9] !== handleRetry ? (t3 = [authState, handleRetry, error], $[7] = authState, $[8] = error, $[9] = handleRetry, $[10] = t3) : t3 = $[10], useEffect(t2, t3);
|
|
133
242
|
const t4 = error instanceof AuthError ? "Authentication Error" : "Configuration Error";
|
|
134
243
|
let t5;
|
|
135
|
-
$[
|
|
244
|
+
$[11] !== t4 ? (t5 = /* @__PURE__ */ jsx("h2", { className: "sc-login-error__title", children: t4 }), $[11] = t4, $[12] = t5) : t5 = $[12];
|
|
136
245
|
let t6;
|
|
137
|
-
$[
|
|
246
|
+
$[13] !== authErrorMessage ? (t6 = /* @__PURE__ */ jsx("p", { className: "sc-login-error__description", children: authErrorMessage }), $[13] = authErrorMessage, $[14] = t6) : t6 = $[14];
|
|
138
247
|
let t7;
|
|
139
|
-
$[
|
|
248
|
+
$[15] !== t5 || $[16] !== t6 ? (t7 = /* @__PURE__ */ jsxs("div", { className: "sc-login-error__content", children: [
|
|
140
249
|
t5,
|
|
141
250
|
t6
|
|
142
|
-
] }), $[
|
|
251
|
+
] }), $[15] = t5, $[16] = t6, $[17] = t7) : t7 = $[17];
|
|
143
252
|
let t8;
|
|
144
|
-
$[
|
|
253
|
+
$[18] !== handleRetry ? (t8 = /* @__PURE__ */ jsx("button", { className: "sc-login-error__button", onClick: handleRetry, children: "Retry" }), $[18] = handleRetry, $[19] = t8) : t8 = $[19];
|
|
145
254
|
let t9;
|
|
146
|
-
return $[
|
|
255
|
+
return $[20] !== t7 || $[21] !== t8 ? (t9 = /* @__PURE__ */ jsxs("div", { className: "sc-login-error", children: [
|
|
147
256
|
t7,
|
|
148
257
|
t8
|
|
149
|
-
] }), $[
|
|
258
|
+
] }), $[20] = t7, $[21] = t8, $[22] = t9) : t9 = $[22], t9;
|
|
150
259
|
}
|
|
151
260
|
if (isInIframe() && !document.querySelector("[data-sanity-core]")) {
|
|
152
261
|
const parsedUrl = new URL(window.location.href), mode = new URLSearchParams(parsedUrl.hash.slice(1)).get("mode"), script = document.createElement("script");
|
|
@@ -168,7 +277,7 @@ function AuthBoundary(t0) {
|
|
|
168
277
|
let t4;
|
|
169
278
|
$[5] !== props ? (t4 = /* @__PURE__ */ jsx(AuthSwitch, { ...props }), $[5] = props, $[6] = t4) : t4 = $[6];
|
|
170
279
|
let t5;
|
|
171
|
-
return $[7] !== FallbackComponent || $[8] !== t4 ? (t5 = /* @__PURE__ */ jsx(ErrorBoundary, { FallbackComponent, children: t4 }), $[7] = FallbackComponent, $[8] = t4, $[9] = t5) : t5 = $[9], t5;
|
|
280
|
+
return $[7] !== FallbackComponent || $[8] !== t4 ? (t5 = /* @__PURE__ */ jsx(ComlinkTokenRefreshProvider, { children: /* @__PURE__ */ jsx(ErrorBoundary, { FallbackComponent, children: t4 }) }), $[7] = FallbackComponent, $[8] = t4, $[9] = t5) : t5 = $[9], t5;
|
|
172
281
|
}
|
|
173
282
|
function AuthSwitch(t0) {
|
|
174
283
|
const $ = c(13);
|
|
@@ -260,9 +369,9 @@ function SanityApp(t0) {
|
|
|
260
369
|
}
|
|
261
370
|
function _temp2$1() {
|
|
262
371
|
let timeout;
|
|
263
|
-
return !isInIframe() && !isLocalUrl(window) && (timeout = setTimeout(_temp$
|
|
372
|
+
return !isInIframe() && !isLocalUrl(window) && (timeout = setTimeout(_temp$4, 1e3)), () => clearTimeout(timeout);
|
|
264
373
|
}
|
|
265
|
-
function _temp$
|
|
374
|
+
function _temp$4() {
|
|
266
375
|
console.warn("Redirecting to core", REDIRECT_URL), window.location.replace(REDIRECT_URL);
|
|
267
376
|
}
|
|
268
377
|
const useAuthToken = createStateSourceHook(getTokenState), useCurrentUser = createStateSourceHook(getCurrentUserState);
|
|
@@ -304,7 +413,7 @@ function useFrameConnection(options) {
|
|
|
304
413
|
const [type, handler] = t22, unsubscribe = channel.on(type, handler);
|
|
305
414
|
messageUnsubscribers.push(unsubscribe);
|
|
306
415
|
}), () => {
|
|
307
|
-
messageUnsubscribers.forEach(_temp$
|
|
416
|
+
messageUnsubscribers.forEach(_temp$3), releaseChannel(instance, name), channelRef.current = null, controllerRef.current = null;
|
|
308
417
|
};
|
|
309
418
|
}, 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);
|
|
310
419
|
let t2;
|
|
@@ -326,57 +435,9 @@ function useFrameConnection(options) {
|
|
|
326
435
|
sendMessage
|
|
327
436
|
}, $[11] = t4) : t4 = $[11], t4;
|
|
328
437
|
}
|
|
329
|
-
function _temp$
|
|
438
|
+
function _temp$3(unsub) {
|
|
330
439
|
return unsub();
|
|
331
440
|
}
|
|
332
|
-
const useNodeState = createStateSourceHook({
|
|
333
|
-
getState: getNodeState,
|
|
334
|
-
shouldSuspend: (instance, nodeInput) => getNodeState(instance, nodeInput).getCurrent() === void 0,
|
|
335
|
-
suspender: (instance, nodeInput) => firstValueFrom(getNodeState(instance, nodeInput).observable.pipe(filter(Boolean)))
|
|
336
|
-
});
|
|
337
|
-
function useWindowConnection(t0) {
|
|
338
|
-
const $ = c(19), {
|
|
339
|
-
name,
|
|
340
|
-
connectTo,
|
|
341
|
-
onMessage
|
|
342
|
-
} = t0;
|
|
343
|
-
let t1;
|
|
344
|
-
$[0] !== connectTo || $[1] !== name ? (t1 = {
|
|
345
|
-
name,
|
|
346
|
-
connectTo
|
|
347
|
-
}, $[0] = connectTo, $[1] = name, $[2] = t1) : t1 = $[2];
|
|
348
|
-
const {
|
|
349
|
-
node
|
|
350
|
-
} = useNodeState(t1);
|
|
351
|
-
let t2;
|
|
352
|
-
$[3] === Symbol.for("react.memo_cache_sentinel") ? (t2 = [], $[3] = t2) : t2 = $[3];
|
|
353
|
-
const messageUnsubscribers = useRef(t2), instance = useSanityInstance();
|
|
354
|
-
let t3;
|
|
355
|
-
$[4] !== node || $[5] !== onMessage ? (t3 = () => (onMessage && Object.entries(onMessage).forEach((t42) => {
|
|
356
|
-
const [type, handler] = t42, messageUnsubscribe = node.on(type, handler);
|
|
357
|
-
messageUnsubscribe && messageUnsubscribers.current.push(messageUnsubscribe);
|
|
358
|
-
}), () => {
|
|
359
|
-
messageUnsubscribers.current.forEach(_temp$3), messageUnsubscribers.current = [];
|
|
360
|
-
}), $[4] = node, $[5] = onMessage, $[6] = t3) : t3 = $[6];
|
|
361
|
-
let t4;
|
|
362
|
-
$[7] !== instance || $[8] !== name || $[9] !== node || $[10] !== onMessage ? (t4 = [instance, name, onMessage, node], $[7] = instance, $[8] = name, $[9] = node, $[10] = onMessage, $[11] = t4) : t4 = $[11], useEffect(t3, t4);
|
|
363
|
-
let t5;
|
|
364
|
-
$[12] !== node ? (t5 = (type_0, data) => {
|
|
365
|
-
node.post(type_0, data);
|
|
366
|
-
}, $[12] = node, $[13] = t5) : t5 = $[13];
|
|
367
|
-
const sendMessage = t5;
|
|
368
|
-
let t6;
|
|
369
|
-
$[14] !== node ? (t6 = (type_1, data_0, fetchOptions) => node.fetch(type_1, data_0, fetchOptions ?? {}), $[14] = node, $[15] = t6) : t6 = $[15];
|
|
370
|
-
const fetch = t6;
|
|
371
|
-
let t7;
|
|
372
|
-
return $[16] !== fetch || $[17] !== sendMessage ? (t7 = {
|
|
373
|
-
sendMessage,
|
|
374
|
-
fetch
|
|
375
|
-
}, $[16] = fetch, $[17] = sendMessage, $[18] = t7) : t7 = $[18], t7;
|
|
376
|
-
}
|
|
377
|
-
function _temp$3(unsubscribe) {
|
|
378
|
-
return unsubscribe();
|
|
379
|
-
}
|
|
380
441
|
function useDashboardNavigate(navigateFn) {
|
|
381
442
|
const $ = c(2);
|
|
382
443
|
let t0;
|
|
@@ -1059,7 +1120,7 @@ function useUsers(options) {
|
|
|
1059
1120
|
loadMore
|
|
1060
1121
|
};
|
|
1061
1122
|
}
|
|
1062
|
-
var version = "2.0.
|
|
1123
|
+
var version = "2.0.2";
|
|
1063
1124
|
function getEnv(key) {
|
|
1064
1125
|
if (typeof import.meta < "u" && import.meta.env)
|
|
1065
1126
|
return import.meta.env[key];
|
|
@@ -1071,6 +1132,7 @@ function getEnv(key) {
|
|
|
1071
1132
|
const REACT_SDK_VERSION = getEnv("PKG_VERSION") || `${version}-development`;
|
|
1072
1133
|
export {
|
|
1073
1134
|
AuthBoundary,
|
|
1135
|
+
ComlinkTokenRefreshProvider,
|
|
1074
1136
|
REACT_SDK_VERSION,
|
|
1075
1137
|
ResourceProvider,
|
|
1076
1138
|
SDKProvider,
|