@sanity/sdk-react 2.4.0 → 2.5.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/README.md +575 -4
- package/dist/index.d.ts +50 -0
- package/dist/index.js +101 -14
- package/dist/index.js.map +1 -1
- package/package.json +9 -8
- package/src/_exports/sdk-react.ts +4 -0
- package/src/hooks/agent/useAgentResourceContext.test.tsx +245 -0
- package/src/hooks/agent/useAgentResourceContext.ts +106 -0
- package/src/hooks/dashboard/useDispatchIntent.test.ts +1 -4
- package/src/hooks/document/useApplyDocumentActions.test.ts +124 -9
- package/src/hooks/document/useApplyDocumentActions.ts +44 -4
- package/src/hooks/document/useDocumentPermissions.test.tsx +3 -3
- package/src/hooks/document/useDocumentPermissions.ts +9 -6
- package/src/hooks/releases/usePerspective.test.tsx +1 -0
- package/src/hooks/releases/usePerspective.ts +1 -1
|
@@ -84,7 +84,10 @@ import {useSanityInstance} from '../context/useSanityInstance'
|
|
|
84
84
|
export function useDocumentPermissions(
|
|
85
85
|
actionOrActions: DocumentAction | DocumentAction[],
|
|
86
86
|
): DocumentPermissionsResult {
|
|
87
|
-
const actions =
|
|
87
|
+
const actions = useMemo(
|
|
88
|
+
() => (Array.isArray(actionOrActions) ? actionOrActions : [actionOrActions]),
|
|
89
|
+
[actionOrActions],
|
|
90
|
+
)
|
|
88
91
|
// if actions is an array, we need to check that all actions belong to the same project and dataset
|
|
89
92
|
let projectId
|
|
90
93
|
let dataset
|
|
@@ -111,20 +114,20 @@ export function useDocumentPermissions(
|
|
|
111
114
|
|
|
112
115
|
const instance = useSanityInstance({projectId, dataset})
|
|
113
116
|
const isDocumentReady = useCallback(
|
|
114
|
-
() => getPermissionsState(instance,
|
|
115
|
-
[
|
|
117
|
+
() => getPermissionsState(instance, {actions}).getCurrent() !== undefined,
|
|
118
|
+
[actions, instance],
|
|
116
119
|
)
|
|
117
120
|
if (!isDocumentReady()) {
|
|
118
121
|
throw firstValueFrom(
|
|
119
|
-
getPermissionsState(instance,
|
|
122
|
+
getPermissionsState(instance, {actions}).observable.pipe(
|
|
120
123
|
filter((result) => result !== undefined),
|
|
121
124
|
),
|
|
122
125
|
)
|
|
123
126
|
}
|
|
124
127
|
|
|
125
128
|
const {subscribe, getCurrent} = useMemo(
|
|
126
|
-
() => getPermissionsState(instance,
|
|
127
|
-
[
|
|
129
|
+
() => getPermissionsState(instance, {actions}),
|
|
130
|
+
[actions, instance],
|
|
128
131
|
)
|
|
129
132
|
|
|
130
133
|
return useSyncExternalStore(subscribe, getCurrent) as DocumentPermissionsResult
|
|
@@ -43,7 +43,7 @@ export const usePerspective: UsePerspective = createStateSourceHook({
|
|
|
43
43
|
instance: SanityInstance,
|
|
44
44
|
perspectiveHandle?: PerspectiveHandle,
|
|
45
45
|
) => StateSource<string | string[]>,
|
|
46
|
-
shouldSuspend: (instance: SanityInstance, options
|
|
46
|
+
shouldSuspend: (instance: SanityInstance, options: PerspectiveHandle): boolean =>
|
|
47
47
|
getPerspectiveState(instance, options).getCurrent() === undefined,
|
|
48
48
|
suspender: (instance: SanityInstance, _options?: PerspectiveHandle) =>
|
|
49
49
|
firstValueFrom(getActiveReleasesState(instance).observable.pipe(filter(Boolean))),
|