@sanity/sdk-react 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1253,14 +1253,22 @@ export declare function useDocumentPermissions(
1253
1253
  /**
1254
1254
  * @public
1255
1255
  *
1256
- * Returns the preview values of a document (specified via a `DocumentHandle`),
1256
+ * Attempts to infer preview values of a document (specified via a `DocumentHandle`),
1257
1257
  * including the document’s `title`, `subtitle`, `media`, and `status`. These values are live and will update in realtime.
1258
1258
  * To reduce unnecessary network requests for resolving the preview values, an optional `ref` can be passed to the hook so that preview
1259
1259
  * resolution will only occur if the `ref` is intersecting the current viewport.
1260
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
+ *
1261
1269
  * @category Documents
1262
- * @param options - The document handle for the document you want to resolve preview values for, and an optional ref
1263
- * @returns The preview values for the given document and a boolean to indicate whether the resolution is pending
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
1264
1272
  *
1265
1273
  * @example Combining with useDocuments to render a collection of document previews
1266
1274
  * ```
@@ -1316,9 +1324,9 @@ export declare interface useDocumentPreviewOptions extends DocumentHandle {
1316
1324
  * @category Types
1317
1325
  */
1318
1326
  export declare interface useDocumentPreviewResults {
1319
- /** The results of resolving the document’s preview values */
1327
+ /** The results of inferring the document’s preview values */
1320
1328
  data: PreviewValue
1321
- /** True when preview values are being refreshed */
1329
+ /** True when inferred preview values are being refreshed */
1322
1330
  isPending: boolean
1323
1331
  }
1324
1332
 
package/dist/index.js CHANGED
@@ -65,7 +65,7 @@ function useWindowConnection(t0) {
65
65
  const [type, handler] = t42, messageUnsubscribe = node.on(type, handler);
66
66
  messageUnsubscribe && messageUnsubscribers.current.push(messageUnsubscribe);
67
67
  }), () => {
68
- messageUnsubscribers.current.forEach(_temp$6), messageUnsubscribers.current = [];
68
+ messageUnsubscribers.current.forEach(_temp$7), messageUnsubscribers.current = [];
69
69
  }), $[4] = node, $[5] = onMessage, $[6] = t3) : t3 = $[6];
70
70
  let t4;
71
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);
@@ -83,7 +83,7 @@ function useWindowConnection(t0) {
83
83
  fetch
84
84
  }, $[16] = fetch, $[17] = sendMessage, $[18] = t7) : t7 = $[18], t7;
85
85
  }
86
- function _temp$6(unsubscribe) {
86
+ function _temp$7(unsubscribe) {
87
87
  return unsubscribe();
88
88
  }
89
89
  const DEFAULT_RESPONSE_TIMEOUT = 1e4;
@@ -110,7 +110,12 @@ function DashboardTokenRefresh(t0) {
110
110
  }, DEFAULT_RESPONSE_TIMEOUT);
111
111
  try {
112
112
  const res = await windowConnection.fetch("dashboard/v1/auth/tokens/create");
113
- clearRefreshTimeout(), res.token && setAuthToken(instance, res.token), isTokenRefreshInProgress.current = !1;
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;
114
119
  } catch {
115
120
  isTokenRefreshInProgress.current = !1, clearRefreshTimeout();
116
121
  }
@@ -129,6 +134,9 @@ function DashboardTokenRefresh(t0) {
129
134
  let t7;
130
135
  return $[11] !== authState || $[12] !== requestNewToken ? (t7 = [authState, requestNewToken], $[11] = authState, $[12] = requestNewToken, $[13] = t7) : t7 = $[13], useEffect(t6, t7), children;
131
136
  }
137
+ function _temp$6(div) {
138
+ return div.textContent?.includes("Uncaught error: Unauthorized - A valid session is required for this endpoint");
139
+ }
132
140
  const ComlinkTokenRefreshProvider = (t0) => {
133
141
  const $ = c(2), {
134
142
  children
@@ -1112,7 +1120,7 @@ function useUsers(options) {
1112
1120
  loadMore
1113
1121
  };
1114
1122
  }
1115
- var version = "2.0.1";
1123
+ var version = "2.1.0";
1116
1124
  function getEnv(key) {
1117
1125
  if (typeof import.meta < "u" && import.meta.env)
1118
1126
  return import.meta.env[key];