@sanity/sdk-react 0.0.0-alpha.26 → 0.0.0-alpha.28

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.
@@ -1,7 +1,7 @@
1
1
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
- import { c as c$3 } from "react/compiler-runtime";
2
+ import { c as c$3 } from "react-compiler-runtime";
3
3
  import { getAuthState, getLoginUrlState, handleAuthCallback, logout, AuthStateType, createSanityInstance, getTokenState, getCurrentUserState, getDashboardOrganizationId, getClientState, getOrCreateController, getOrCreateChannel, releaseChannel, getOrCreateNode, releaseNode, resolveDatasets, getDatasetsState, applyDocumentActions, resolveDocument, getDocumentState, subscribeDocumentEvents, getPermissionsState, getDocumentSyncStatus, editDocument, getQueryKey, parseQueryKey, getQueryState, resolveQuery, createGroqSearchFilter, getPreviewState, resolvePreview, getProjectionState, resolveProjection, resolveProject, getProjectState, resolveProjects, getProjectsState, getUsersKey, parseUsersKey, getUsersState, resolveUsers, loadMoreUsers } from "@sanity/sdk";
4
- import { createContext, use, useSyncExternalStore, useEffect, useState, useRef, Suspense, useInsertionEffect, useTransition, useMemo, useCallback } from "react";
4
+ import { createContext, useContext, useSyncExternalStore, useEffect, useState, useRef, Suspense, useInsertionEffect, useTransition, useMemo, useCallback } from "react";
5
5
  import { ErrorBoundary } from "react-error-boundary";
6
6
  import require$$0, { Readable } from "stream";
7
7
  import require$$1 from "zlib";
@@ -36,11 +36,14 @@ function _mergeNamespaces(n2, m2) {
36
36
  }), Object.freeze(n2);
37
37
  }
38
38
  const SanityInstanceContext = createContext(null), useSanityInstance = (config) => {
39
- const instance = use(SanityInstanceContext);
39
+ const $ = c$3(3), instance = useContext(SanityInstanceContext);
40
40
  if (!instance)
41
41
  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>.`);
42
- if (!config) return instance;
43
- const match = instance.match(config);
42
+ if (!config)
43
+ return instance;
44
+ let t0;
45
+ $[0] !== config || $[1] !== instance ? (t0 = instance.match(config), $[0] = config, $[1] = instance, $[2] = t0) : t0 = $[2];
46
+ const match = t0;
44
47
  if (!match)
45
48
  throw new Error(`Could not find a matching Sanity instance for the requested configuration: ${JSON.stringify(config, null, 2)}.
46
49
  Please ensure there is a <ResourceProvider> with a matching configuration in the component hierarchy.`);
@@ -4954,7 +4957,7 @@ function ResourceProvider(t0) {
4954
4957
  fallback,
4955
4958
  ...config
4956
4959
  } = t0, $[0] = t0, $[1] = children, $[2] = config, $[3] = fallback) : (children = $[1], config = $[2], fallback = $[3]);
4957
- const parent = use(SanityInstanceContext);
4960
+ const parent = useContext(SanityInstanceContext);
4958
4961
  let t1, t2;
4959
4962
  $[4] !== config || $[5] !== parent ? (t2 = parent ? parent.createChild(config) : createSanityInstance(config), $[4] = config, $[5] = parent, $[6] = t2) : t2 = $[6], t1 = t2;
4960
4963
  const instance = t1, disposal = useRef(null);
@@ -5265,13 +5268,17 @@ function useStudioWorkspacesByProjectIdDataset() {
5265
5268
  try {
5266
5269
  const data = await fetch2("dashboard/v1/bridge/context", void 0, {
5267
5270
  signal
5268
- }), workspaceMap = {};
5271
+ }), workspaceMap = {}, noProjectIdAndDataset = [];
5269
5272
  data.context.availableResources.forEach((resource) => {
5270
- !resource.projectId || !resource.workspaces?.length || resource.workspaces.forEach((workspace) => {
5271
- const key = `${resource.projectId}:${workspace.dataset}`;
5272
- workspaceMap[key] || (workspaceMap[key] = []), workspaceMap[key].push(workspace);
5273
- });
5274
- }), setWorkspacesByProjectIdAndDataset(workspaceMap), setError(null);
5273
+ if (resource.type !== "studio")
5274
+ return;
5275
+ if (!resource.projectId || !resource.dataset) {
5276
+ noProjectIdAndDataset.push(resource);
5277
+ return;
5278
+ }
5279
+ const key = `${resource.projectId}:${resource.dataset}`;
5280
+ workspaceMap[key] || (workspaceMap[key] = []), workspaceMap[key].push(resource);
5281
+ }), noProjectIdAndDataset.length > 0 && (workspaceMap["NO_PROJECT_ID:NO_DATASET"] = noProjectIdAndDataset), setWorkspacesByProjectIdAndDataset(workspaceMap), setError(null);
5275
5282
  } catch (t42) {
5276
5283
  const err = t42;
5277
5284
  if (err instanceof Error) {
@@ -5293,8 +5300,8 @@ function useStudioWorkspacesByProjectIdDataset() {
5293
5300
  isConnected: t4
5294
5301
  }, $[6] = error, $[7] = t4, $[8] = workspacesByProjectIdAndDataset, $[9] = t5) : t5 = $[9], t5;
5295
5302
  }
5296
- function useNavigateToStudioDocument(documentHandle) {
5297
- const $ = c$3(10), {
5303
+ function useNavigateToStudioDocument(documentHandle, preferredStudioUrl) {
5304
+ const $ = c$3(11), {
5298
5305
  workspacesByProjectIdAndDataset,
5299
5306
  isConnected: workspacesConnected
5300
5307
  } = useStudioWorkspacesByProjectIdDataset(), [status, setStatus] = useState("idle");
@@ -5308,35 +5315,46 @@ function useNavigateToStudioDocument(documentHandle) {
5308
5315
  sendMessage
5309
5316
  } = useWindowConnection(t0);
5310
5317
  let t1;
5311
- $[1] !== documentHandle || $[2] !== sendMessage || $[3] !== status || $[4] !== workspacesByProjectIdAndDataset || $[5] !== workspacesConnected ? (t1 = () => {
5318
+ $[1] !== documentHandle || $[2] !== preferredStudioUrl || $[3] !== sendMessage || $[4] !== status || $[5] !== workspacesByProjectIdAndDataset || $[6] !== workspacesConnected ? (t1 = () => {
5312
5319
  const {
5313
5320
  projectId: projectId2,
5314
5321
  dataset: dataset2
5315
5322
  } = documentHandle;
5316
- if (!workspacesConnected || status !== "connected" || !projectId2 || !dataset2)
5323
+ if (!workspacesConnected || status !== "connected") {
5324
+ console.warn("Not connected to Dashboard");
5317
5325
  return;
5318
- const workspaces = workspacesByProjectIdAndDataset[`${projectId2}:${dataset2}`];
5319
- if (!workspaces?.length) {
5320
- console.warn(`No workspace found for document with projectId: ${projectId2} and dataset: ${dataset2}`);
5326
+ }
5327
+ if (!projectId2 || !dataset2) {
5328
+ console.warn("Project ID and dataset are required to navigate to a studio document");
5329
+ return;
5330
+ }
5331
+ let workspace;
5332
+ if (preferredStudioUrl)
5333
+ workspace = [...workspacesByProjectIdAndDataset[`${projectId2}:${dataset2}`] || [], ...workspacesByProjectIdAndDataset["NO_PROJECT_ID:NO_DATASET"] || []].find((w2) => w2.url === preferredStudioUrl);
5334
+ else {
5335
+ const workspaces = workspacesByProjectIdAndDataset[`${projectId2}:${dataset2}`];
5336
+ workspaces?.length > 1 && (console.warn("Multiple workspaces found for document and no preferred studio url", documentHandle), console.warn("Using the first one", workspaces[0])), workspace = workspaces?.[0];
5337
+ }
5338
+ if (!workspace) {
5339
+ console.warn(`No workspace found for document with projectId: ${projectId2} and dataset: ${dataset2}${preferredStudioUrl ? ` or with preferred studio url: ${preferredStudioUrl}` : ""}`);
5321
5340
  return;
5322
5341
  }
5323
- workspaces.length > 1 && (console.warn("Multiple workspaces found for document", documentHandle), console.warn("Using the first one", workspaces[0]));
5324
5342
  const message = {
5325
5343
  type: "dashboard/v1/bridge/navigate-to-resource",
5326
5344
  data: {
5327
- resourceId: workspaces[0]._ref,
5345
+ resourceId: workspace.id,
5328
5346
  resourceType: "studio",
5329
5347
  path: `/intent/edit/id=${documentHandle.documentId};type=${documentHandle.documentType}`
5330
5348
  }
5331
5349
  };
5332
5350
  sendMessage(message.type, message.data);
5333
- }, $[1] = documentHandle, $[2] = sendMessage, $[3] = status, $[4] = workspacesByProjectIdAndDataset, $[5] = workspacesConnected, $[6] = t1) : t1 = $[6];
5351
+ }, $[1] = documentHandle, $[2] = preferredStudioUrl, $[3] = sendMessage, $[4] = status, $[5] = workspacesByProjectIdAndDataset, $[6] = workspacesConnected, $[7] = t1) : t1 = $[7];
5334
5352
  const navigateToStudioDocument = t1, t2 = workspacesConnected && status === "connected";
5335
5353
  let t3;
5336
- return $[7] !== navigateToStudioDocument || $[8] !== t2 ? (t3 = {
5354
+ return $[8] !== navigateToStudioDocument || $[9] !== t2 ? (t3 = {
5337
5355
  navigateToStudioDocument,
5338
5356
  isConnected: t2
5339
- }, $[7] = navigateToStudioDocument, $[8] = t2, $[9] = t3) : t3 = $[9], t3;
5357
+ }, $[8] = navigateToStudioDocument, $[9] = t2, $[10] = t3) : t3 = $[10], t3;
5340
5358
  }
5341
5359
  const useDatasets = createStateSourceHook({
5342
5360
  getState: getDatasetsState,
@@ -5765,7 +5783,7 @@ function useUsers(options) {
5765
5783
  loadMore
5766
5784
  };
5767
5785
  }
5768
- var version = "0.0.0-alpha.26";
5786
+ var version = "0.0.0-alpha.28";
5769
5787
  function getEnv(key) {
5770
5788
  if (typeof import.meta < "u" && import.meta.env)
5771
5789
  return import.meta.env[key];