@sanity/sdk-react 2.1.2 → 2.2.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
@@ -2107,30 +2107,38 @@ declare type UseProject = {
2107
2107
  */
2108
2108
  export declare const useProject: UseProject
2109
2109
 
2110
- declare type UseProjects = {
2111
- /**
2112
- *
2113
- * Returns metadata for each project you have access to.
2114
- *
2115
- * @category Projects
2116
- * @returns An array of metadata (minus the projects’ members) for each project
2117
- * @example
2118
- * ```tsx
2119
- * const projects = useProjects()
2120
- *
2121
- * return (
2122
- * <select>
2123
- * {projects.map((project) => (
2124
- * <option key={project.id}>{project.displayName}</option>
2125
- * ))}
2126
- * </select>
2127
- * )
2128
- * ```
2129
- */
2130
- (): ProjectWithoutMembers[]
2131
- }
2110
+ /**
2111
+ * @public
2112
+ * @category Types
2113
+ */
2114
+ declare type UseProjects = <TIncludeMembers extends boolean = false>(options?: {
2115
+ organizationId?: string
2116
+ includeMembers?: TIncludeMembers
2117
+ }) => TIncludeMembers extends true ? SanityProject_2[] : ProjectWithoutMembers[]
2132
2118
 
2133
2119
  /**
2120
+ * Returns metadata for each project you have access to.
2121
+ *
2122
+ * @category Projects
2123
+ * @param options - Configuration options
2124
+ * @returns An array of project metadata. If includeMembers is true, returns full SanityProject objects. Otherwise, returns ProjectWithoutMembers objects.
2125
+ * @example
2126
+ * ```tsx
2127
+ * const projects = useProjects()
2128
+ *
2129
+ * return (
2130
+ * <select>
2131
+ * {projects.map((project) => (
2132
+ * <option key={project.id}>{project.displayName}</option>
2133
+ * ))}
2134
+ * </select>
2135
+ * )
2136
+ * ```
2137
+ * @example
2138
+ * ```tsx
2139
+ * const projectsWithMembers = useProjects({ includeMembers: true })
2140
+ * const projectsWithoutMembers = useProjects({ includeMembers: false })
2141
+ * ```
2134
2142
  * @public
2135
2143
  * @function
2136
2144
  */
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import { pick } from "lodash-es";
11
11
  const SanityInstanceContext = createContext(null), useSanityInstance = (config) => {
12
12
  const $ = c(3), instance = useContext(SanityInstanceContext);
13
13
  if (!instance)
14
- 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>.`);
14
+ 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 component.`);
15
15
  if (!config)
16
16
  return instance;
17
17
  let t0;
@@ -19,7 +19,7 @@ const SanityInstanceContext = createContext(null), useSanityInstance = (config)
19
19
  const match = t0;
20
20
  if (!match)
21
21
  throw new Error(`Could not find a matching Sanity instance for the requested configuration: ${JSON.stringify(config, null, 2)}.
22
- Please ensure there is a <ResourceProvider> with a matching configuration in the component hierarchy.`);
22
+ Please ensure there is a ResourceProvider component with a matching configuration in the component hierarchy.`);
23
23
  return match;
24
24
  };
25
25
  function createStateSourceHook(options) {
@@ -1017,7 +1017,7 @@ function useDocumentPreview(t0) {
1017
1017
  ref,
1018
1018
  ...docHandle
1019
1019
  } = t0, $[0] = t0, $[1] = docHandle, $[2] = ref) : (docHandle = $[1], ref = $[2]);
1020
- const instance = useSanityInstance();
1020
+ const instance = useSanityInstance(docHandle);
1021
1021
  let t1;
1022
1022
  $[3] !== docHandle || $[4] !== instance ? (t1 = getPreviewState(instance, docHandle), $[3] = docHandle, $[4] = instance, $[5] = t1) : t1 = $[5];
1023
1023
  const stateSource = t1;
@@ -1058,7 +1058,7 @@ function useDocumentProjection(t0) {
1058
1058
  projection,
1059
1059
  ...docHandle
1060
1060
  } = t0, $[0] = t0, $[1] = docHandle, $[2] = projection, $[3] = ref) : (docHandle = $[1], projection = $[2], ref = $[3]);
1061
- const instance = useSanityInstance();
1061
+ const instance = useSanityInstance(docHandle);
1062
1062
  let stateSource, t1;
1063
1063
  if ($[4] !== docHandle || $[5] !== instance || $[6] !== projection ? (stateSource = getProjectionState(instance, {
1064
1064
  ...docHandle,
@@ -1096,9 +1096,8 @@ const useProject = createStateSourceHook({
1096
1096
  suspender: resolveProject,
1097
1097
  getConfig: identity
1098
1098
  }), useProjects = createStateSourceHook({
1099
- // remove `undefined` since we're suspending when that is the case
1100
1099
  getState: getProjectsState,
1101
- shouldSuspend: (instance) => getProjectsState(instance).getCurrent() === void 0,
1100
+ shouldSuspend: (instance, options) => getProjectsState(instance, options).getCurrent() === void 0,
1102
1101
  suspender: resolveProjects
1103
1102
  }), useActiveReleases = createStateSourceHook({
1104
1103
  getState: getActiveReleasesState,
@@ -1159,7 +1158,7 @@ function useUsers(options) {
1159
1158
  loadMore
1160
1159
  };
1161
1160
  }
1162
- var version = "2.1.2";
1161
+ var version = "2.2.0";
1163
1162
  function getEnv(key) {
1164
1163
  if (typeof import.meta < "u" && import.meta.env)
1165
1164
  return import.meta.env[key];