@sanity/sdk-react 0.0.0-alpha.3 → 0.0.0-alpha.31

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.
Files changed (131) hide show
  1. package/README.md +6 -100
  2. package/dist/index.d.ts +2390 -2
  3. package/dist/index.js +1119 -2
  4. package/dist/index.js.map +1 -1
  5. package/package.json +35 -49
  6. package/src/_exports/index.ts +2 -10
  7. package/src/_exports/sdk-react.ts +73 -0
  8. package/src/components/SDKProvider.test.tsx +103 -0
  9. package/src/components/SDKProvider.tsx +52 -0
  10. package/src/components/SanityApp.test.tsx +244 -0
  11. package/src/components/SanityApp.tsx +106 -0
  12. package/src/components/auth/AuthBoundary.test.tsx +204 -29
  13. package/src/components/auth/AuthBoundary.tsx +96 -19
  14. package/src/components/auth/ConfigurationError.ts +22 -0
  15. package/src/components/auth/LoginCallback.test.tsx +22 -24
  16. package/src/components/auth/LoginCallback.tsx +6 -16
  17. package/src/components/auth/LoginError.test.tsx +11 -18
  18. package/src/components/auth/LoginError.tsx +43 -25
  19. package/src/components/utils.ts +22 -0
  20. package/src/context/ResourceProvider.test.tsx +157 -0
  21. package/src/context/ResourceProvider.tsx +111 -0
  22. package/src/context/SanityInstanceContext.ts +4 -0
  23. package/src/hooks/_synchronous-groq-js.mjs +4 -0
  24. package/src/hooks/auth/useAuthState.tsx +4 -5
  25. package/src/hooks/auth/useAuthToken.tsx +1 -1
  26. package/src/hooks/auth/useCurrentUser.tsx +28 -4
  27. package/src/hooks/auth/useDashboardOrganizationId.test.tsx +42 -0
  28. package/src/hooks/auth/useDashboardOrganizationId.tsx +30 -0
  29. package/src/hooks/auth/useHandleAuthCallback.test.tsx +16 -0
  30. package/src/hooks/auth/{useHandleCallback.tsx → useHandleAuthCallback.tsx} +7 -6
  31. package/src/hooks/auth/useLogOut.test.tsx +2 -2
  32. package/src/hooks/auth/useLogOut.tsx +1 -1
  33. package/src/hooks/auth/useLoginUrl.tsx +14 -0
  34. package/src/hooks/auth/useVerifyOrgProjects.test.tsx +136 -0
  35. package/src/hooks/auth/useVerifyOrgProjects.tsx +48 -0
  36. package/src/hooks/client/useClient.ts +13 -33
  37. package/src/hooks/comlink/useFrameConnection.test.tsx +167 -0
  38. package/src/hooks/comlink/useFrameConnection.ts +107 -0
  39. package/src/hooks/comlink/useManageFavorite.test.ts +368 -0
  40. package/src/hooks/comlink/useManageFavorite.ts +210 -0
  41. package/src/hooks/comlink/useRecordDocumentHistoryEvent.test.ts +85 -0
  42. package/src/hooks/comlink/useRecordDocumentHistoryEvent.ts +115 -0
  43. package/src/hooks/comlink/useWindowConnection.test.ts +135 -0
  44. package/src/hooks/comlink/useWindowConnection.ts +123 -0
  45. package/src/hooks/context/useSanityInstance.test.tsx +157 -15
  46. package/src/hooks/context/useSanityInstance.ts +68 -11
  47. package/src/hooks/dashboard/useNavigateToStudioDocument.test.ts +276 -0
  48. package/src/hooks/dashboard/useNavigateToStudioDocument.ts +139 -0
  49. package/src/hooks/dashboard/useStudioWorkspacesByProjectIdDataset.test.tsx +291 -0
  50. package/src/hooks/dashboard/useStudioWorkspacesByProjectIdDataset.ts +101 -0
  51. package/src/hooks/datasets/useDatasets.test.ts +80 -0
  52. package/src/hooks/datasets/useDatasets.ts +52 -0
  53. package/src/hooks/document/useApplyDocumentActions.test.ts +20 -0
  54. package/src/hooks/document/useApplyDocumentActions.ts +124 -0
  55. package/src/hooks/document/useDocument.test.ts +118 -0
  56. package/src/hooks/document/useDocument.ts +212 -0
  57. package/src/hooks/document/useDocumentEvent.test.ts +62 -0
  58. package/src/hooks/document/useDocumentEvent.ts +94 -0
  59. package/src/hooks/document/useDocumentPermissions.test.ts +204 -0
  60. package/src/hooks/document/useDocumentPermissions.ts +131 -0
  61. package/src/hooks/document/useDocumentSyncStatus.test.ts +23 -0
  62. package/src/hooks/document/useDocumentSyncStatus.ts +61 -0
  63. package/src/hooks/document/useEditDocument.test.ts +196 -0
  64. package/src/hooks/document/useEditDocument.ts +314 -0
  65. package/src/hooks/documents/useDocuments.test.tsx +179 -0
  66. package/src/hooks/documents/useDocuments.ts +300 -0
  67. package/src/hooks/helpers/createCallbackHook.test.tsx +2 -2
  68. package/src/hooks/helpers/createCallbackHook.tsx +1 -1
  69. package/src/hooks/helpers/createStateSourceHook.test.tsx +67 -1
  70. package/src/hooks/helpers/createStateSourceHook.tsx +27 -11
  71. package/src/hooks/paginatedDocuments/usePaginatedDocuments.test.tsx +284 -0
  72. package/src/hooks/paginatedDocuments/usePaginatedDocuments.ts +353 -0
  73. package/src/hooks/preview/usePreview.test.tsx +85 -17
  74. package/src/hooks/preview/usePreview.tsx +81 -22
  75. package/src/hooks/projection/useProjection.test.tsx +283 -0
  76. package/src/hooks/projection/useProjection.ts +232 -0
  77. package/src/hooks/projects/useProject.test.ts +80 -0
  78. package/src/hooks/projects/useProject.ts +51 -0
  79. package/src/hooks/projects/useProjects.test.ts +77 -0
  80. package/src/hooks/projects/useProjects.ts +45 -0
  81. package/src/hooks/query/useQuery.test.tsx +188 -0
  82. package/src/hooks/query/useQuery.ts +193 -0
  83. package/src/hooks/releases/useActiveReleases.test.tsx +84 -0
  84. package/src/hooks/releases/useActiveReleases.ts +39 -0
  85. package/src/hooks/releases/usePerspective.test.tsx +120 -0
  86. package/src/hooks/releases/usePerspective.ts +49 -0
  87. package/src/hooks/users/useUsers.test.tsx +330 -0
  88. package/src/hooks/users/useUsers.ts +120 -0
  89. package/src/utils/getEnv.ts +21 -0
  90. package/src/version.ts +8 -0
  91. package/src/vite-env.d.ts +10 -0
  92. package/dist/_chunks-es/useLogOut.js +0 -44
  93. package/dist/_chunks-es/useLogOut.js.map +0 -1
  94. package/dist/assets/bundle-CcAyERuZ.css +0 -11
  95. package/dist/components.d.ts +0 -259
  96. package/dist/components.js +0 -301
  97. package/dist/components.js.map +0 -1
  98. package/dist/hooks.d.ts +0 -186
  99. package/dist/hooks.js +0 -81
  100. package/dist/hooks.js.map +0 -1
  101. package/src/_exports/components.ts +0 -13
  102. package/src/_exports/hooks.ts +0 -9
  103. package/src/components/DocumentGridLayout/DocumentGridLayout.stories.tsx +0 -113
  104. package/src/components/DocumentGridLayout/DocumentGridLayout.test.tsx +0 -42
  105. package/src/components/DocumentGridLayout/DocumentGridLayout.tsx +0 -21
  106. package/src/components/DocumentListLayout/DocumentListLayout.stories.tsx +0 -105
  107. package/src/components/DocumentListLayout/DocumentListLayout.test.tsx +0 -42
  108. package/src/components/DocumentListLayout/DocumentListLayout.tsx +0 -12
  109. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.md +0 -49
  110. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.stories.tsx +0 -39
  111. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.test.tsx +0 -30
  112. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.tsx +0 -171
  113. package/src/components/Login/LoginLinks.test.tsx +0 -100
  114. package/src/components/Login/LoginLinks.tsx +0 -73
  115. package/src/components/auth/Login.test.tsx +0 -41
  116. package/src/components/auth/Login.tsx +0 -45
  117. package/src/components/auth/LoginFooter.test.tsx +0 -29
  118. package/src/components/auth/LoginFooter.tsx +0 -65
  119. package/src/components/auth/LoginLayout.test.tsx +0 -33
  120. package/src/components/auth/LoginLayout.tsx +0 -81
  121. package/src/components/context/SanityProvider.test.tsx +0 -25
  122. package/src/components/context/SanityProvider.tsx +0 -42
  123. package/src/css/css.config.js +0 -220
  124. package/src/css/paramour.css +0 -2347
  125. package/src/css/styles.css +0 -11
  126. package/src/hooks/auth/useHandleCallback.test.tsx +0 -16
  127. package/src/hooks/auth/useLoginUrls.test.tsx +0 -68
  128. package/src/hooks/auth/useLoginUrls.tsx +0 -51
  129. package/src/hooks/client/useClient.test.tsx +0 -130
  130. package/src/hooks/documentCollection/useDocuments.test.ts +0 -130
  131. package/src/hooks/documentCollection/useDocuments.ts +0 -87
package/dist/hooks.d.ts DELETED
@@ -1,186 +0,0 @@
1
- import {AuthProvider} from '@sanity/sdk'
2
- import {AuthState} from '@sanity/sdk'
3
- import {CurrentUser} from '@sanity/types'
4
- import {DocumentHandle} from '@sanity/sdk'
5
- import {DocumentListOptions} from '@sanity/sdk'
6
- import {PreviewValue} from '@sanity/sdk'
7
- import type {SanityInstance} from '@sanity/sdk'
8
-
9
- /**
10
- * A React hook that subscribes to authentication state changes.
11
- *
12
- * This hook provides access to the current authentication state type from the Sanity auth store.
13
- * It automatically re-renders the component when the authentication state changes.
14
- *
15
- * @remarks
16
- * The hook uses `useSyncExternalStore` to safely subscribe to auth state changes
17
- * and ensure consistency between server and client rendering.
18
- *
19
- * @returns The current authentication state type
20
- *
21
- * @example
22
- * ```tsx
23
- * function AuthStatus() {
24
- * const authState = useAuthState()
25
- * return <div>Current auth state: {authState}</div>
26
- * }
27
- * ```
28
- *
29
- * @public
30
- */
31
- export declare const useAuthState: () => AuthState
32
-
33
- /**
34
- * Hook to get the currently logged in user
35
- * @public
36
- * @returns The current user or null if not authenticated
37
- */
38
- export declare const useAuthToken: () => string | null
39
-
40
- /**
41
- * Hook to get the currently logged in user
42
- * @public
43
- * @returns The current user or null if not authenticated
44
- */
45
- export declare const useCurrentUser: () => CurrentUser | null
46
-
47
- /**
48
- * @public
49
- */
50
- export declare interface UseDocuments {
51
- loadMore: () => void
52
- results: DocumentHandle[]
53
- isPending: boolean
54
- hasMore: boolean
55
- count: number
56
- }
57
-
58
- /**
59
- * Hook to get the list of documents for specified options
60
- *
61
- * @public
62
- *
63
- * @param options - options for the document list
64
- * @returns result of the document list and function to load more
65
- */
66
- export declare function useDocuments(options?: DocumentListOptions): UseDocuments
67
-
68
- /**
69
- * A React hook that returns a function for handling authentication callbacks.
70
- *
71
- * @remarks
72
- * This hook provides access to the authentication store's callback handler,
73
- * which processes auth redirects by extracting the session ID and fetching the
74
- * authentication token. If fetching the long-lived token is successful,
75
- * `handleCallback` will return a Promise that resolves a new location that
76
- * removes the short-lived token from the URL. Use this in combination with
77
- * `history.replaceState` or your own router's `replace` function to update the
78
- * current location without triggering a reload.
79
- *
80
- * @example
81
- * ```tsx
82
- * function AuthCallback() {
83
- * const handleCallback = useHandleCallback()
84
- * const router = useRouter() // Example router
85
- *
86
- * useEffect(() => {
87
- * async function processCallback() {
88
- * // Handle the callback and get the cleaned URL
89
- * const newUrl = await handleCallback(window.location.href)
90
- *
91
- * if (newUrl) {
92
- * // Replace URL without triggering navigation
93
- * router.replace(newUrl, {shallow: true})
94
- * }
95
- * }
96
- *
97
- * processCallback().catch(console.error)
98
- * }, [handleCallback, router])
99
- *
100
- * return <div>Completing login...</div>
101
- * }
102
- * ```
103
- *
104
- * @returns A callback handler function that processes OAuth redirects
105
- * @public
106
- */
107
- export declare const useHandleCallback: () => (
108
- locationHref?: string | undefined,
109
- ) => Promise<string | false>
110
-
111
- /**
112
- * A React hook that retrieves the available authentication provider URLs for login.
113
- *
114
- * @remarks
115
- * This hook fetches the login URLs from the Sanity auth store when the component mounts.
116
- * Each provider object contains information about an authentication method, including its URL.
117
- * The hook will suspend if the login URLs have not yet loaded.
118
- *
119
- * @example
120
- * ```tsx
121
- * // LoginProviders component that uses the hook
122
- * function LoginProviders() {
123
- * const providers = useLoginUrls()
124
- *
125
- * return (
126
- * <div>
127
- * {providers.map((provider) => (
128
- * <a key={provider.name} href={provider.url}>
129
- * Login with {provider.title}
130
- * </a>
131
- * ))}
132
- * </div>
133
- * )
134
- * }
135
- *
136
- * // Parent component with Suspense boundary
137
- * function LoginPage() {
138
- * return (
139
- * <Suspense fallback={<div>Loading authentication providers...</div>}>
140
- * <LoginProviders />
141
- * </Suspense>
142
- * )
143
- * }
144
- * ```
145
- *
146
- * @returns An array of {@link AuthProvider} objects containing login URLs and provider information
147
- * @public
148
- */
149
- export declare function useLoginUrls(): AuthProvider[]
150
-
151
- /**
152
- * Hook to log out of the current session
153
- * @public
154
- * @returns A function to log out of the current session
155
- */
156
- export declare const useLogOut: () => () => Promise<void>
157
-
158
- /**
159
- * @alpha
160
- */
161
- export declare function usePreview({
162
- document: {_id, _type},
163
- ref,
164
- }: UsePreviewOptions): [PreviewValue, boolean]
165
-
166
- /**
167
- * @alpha
168
- */
169
- export declare interface UsePreviewOptions {
170
- document: DocumentHandle
171
- ref: HTMLElement | null
172
- }
173
-
174
- /**
175
- * Hook that provides the current Sanity instance from the context.
176
- * This must be called from within a `SanityProvider` component.
177
- * @public
178
- * @returns the current Sanity instance
179
- * @example
180
- * ```tsx
181
- * const instance = useSanityInstance()
182
- * ```
183
- */
184
- export declare const useSanityInstance: () => SanityInstance
185
-
186
- export {}
package/dist/hooks.js DELETED
@@ -1,81 +0,0 @@
1
- import { createStateSourceHook, useSanityInstance } from "./_chunks-es/useLogOut.js";
2
- import { useAuthState, useHandleCallback, useLogOut, useLoginUrls } from "./_chunks-es/useLogOut.js";
3
- import { getTokenState, getCurrentUserState, createDocumentListStore, getPreviewState, resolvePreview } from "@sanity/sdk";
4
- import { useState, useEffect, useCallback, useSyncExternalStore, useMemo } from "react";
5
- import { Observable, startWith, distinctUntilChanged, switchMap, EMPTY } from "rxjs";
6
- const useAuthToken = createStateSourceHook(getTokenState), useCurrentUser = createStateSourceHook(getCurrentUserState), STABLE_EMPTY = {
7
- results: [],
8
- isPending: !1,
9
- hasMore: !1,
10
- count: 0
11
- };
12
- function useDocuments(options = {}) {
13
- const instance = useSanityInstance(), [ref] = useState(() => ({
14
- storeInstance: null,
15
- getCurrent: () => STABLE_EMPTY,
16
- initialOptions: options
17
- })), serializedOptions = JSON.stringify(options);
18
- useEffect(() => {
19
- ref.storeInstance?.setOptions(JSON.parse(serializedOptions));
20
- }, [ref, serializedOptions]);
21
- const subscribe = useCallback(
22
- (onStoreChanged) => {
23
- ref.storeInstance = createDocumentListStore(instance), ref.storeInstance.setOptions(ref.initialOptions);
24
- const state2 = ref.storeInstance.getState();
25
- ref.getCurrent = state2.getCurrent;
26
- const unsubscribe = state2.subscribe(onStoreChanged);
27
- return () => {
28
- unsubscribe(), ref.storeInstance?.dispose();
29
- };
30
- },
31
- [instance, ref]
32
- ), getSnapshot = useCallback(() => ref.getCurrent(), [ref]), state = useSyncExternalStore(subscribe, getSnapshot);
33
- return { loadMore: useCallback(() => {
34
- ref.storeInstance?.loadMore();
35
- }, [ref]), ...state };
36
- }
37
- function usePreview({
38
- document: { _id, _type },
39
- ref
40
- }) {
41
- const instance = useSanityInstance(), stateSource = useMemo(
42
- () => getPreviewState(instance, { document: { _id, _type } }),
43
- [instance, _id, _type]
44
- ), subscribe = useCallback(
45
- (onStoreChanged) => {
46
- const subscription = new Observable((observer) => {
47
- if (typeof IntersectionObserver > "u") return;
48
- const intersectionObserver = new IntersectionObserver(
49
- ([entry]) => observer.next(entry.isIntersecting),
50
- { rootMargin: "0px", threshold: 0 }
51
- );
52
- return ref && intersectionObserver.observe(ref), () => intersectionObserver.disconnect();
53
- }).pipe(
54
- startWith(!1),
55
- distinctUntilChanged(),
56
- switchMap(
57
- (isVisible) => isVisible ? new Observable((obs) => stateSource.subscribe(() => obs.next())) : EMPTY
58
- )
59
- ).subscribe({ next: onStoreChanged });
60
- return () => subscription.unsubscribe();
61
- },
62
- [stateSource, ref]
63
- ), getSnapshot = useCallback(() => {
64
- const previewTuple = stateSource.getCurrent();
65
- if (!previewTuple[0]) throw resolvePreview(instance, { document: { _id, _type } });
66
- return previewTuple;
67
- }, [_id, _type, instance, stateSource]);
68
- return useSyncExternalStore(subscribe, getSnapshot);
69
- }
70
- export {
71
- useAuthState,
72
- useAuthToken,
73
- useCurrentUser,
74
- useDocuments,
75
- useHandleCallback,
76
- useLogOut,
77
- useLoginUrls,
78
- usePreview,
79
- useSanityInstance
80
- };
81
- //# sourceMappingURL=hooks.js.map
package/dist/hooks.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"hooks.js","sources":["../src/hooks/auth/useAuthToken.tsx","../src/hooks/auth/useCurrentUser.tsx","../src/hooks/documentCollection/useDocuments.ts","../src/hooks/preview/usePreview.tsx"],"sourcesContent":["import {getTokenState} from '@sanity/sdk'\n\nimport {createStateSourceHook} from '../helpers/createStateSourceHook'\n\n/**\n * Hook to get the currently logged in user\n * @public\n * @returns The current user or null if not authenticated\n */\nexport const useAuthToken = createStateSourceHook(getTokenState)\n","import {getCurrentUserState} from '@sanity/sdk'\n\nimport {createStateSourceHook} from '../helpers/createStateSourceHook'\n\n/**\n * Hook to get the currently logged in user\n * @public\n * @returns The current user or null if not authenticated\n */\nexport const useCurrentUser = createStateSourceHook(getCurrentUserState)\n","import {createDocumentListStore, type DocumentHandle, type DocumentListOptions} from '@sanity/sdk'\nimport {useCallback, useEffect, useState, useSyncExternalStore} from 'react'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\n/**\n * @public\n */\nexport interface UseDocuments {\n loadMore: () => void\n results: DocumentHandle[]\n isPending: boolean\n hasMore: boolean\n count: number\n}\n\ntype DocumentListStore = ReturnType<typeof createDocumentListStore>\ntype DocumentListState = ReturnType<DocumentListStore['getState']>['getCurrent']\nconst STABLE_EMPTY = {\n results: [],\n isPending: false,\n hasMore: false,\n count: 0,\n}\n\n/**\n * Hook to get the list of documents for specified options\n *\n * @public\n *\n * @param options - options for the document list\n * @returns result of the document list and function to load more\n */\nexport function useDocuments(options: DocumentListOptions = {}): UseDocuments {\n const instance = useSanityInstance()\n\n // NOTE: useState is used because it guaranteed to return a stable reference\n // across renders\n const [ref] = useState<{\n storeInstance: DocumentListStore | null\n getCurrent: DocumentListState\n initialOptions: DocumentListOptions\n }>(() => ({\n storeInstance: null,\n getCurrent: () => STABLE_EMPTY,\n initialOptions: options,\n }))\n\n // serialize options to ensure it only calls `setOptions` when the values\n // themselves changes (in cases where devs put config inline)\n const serializedOptions = JSON.stringify(options)\n useEffect(() => {\n ref.storeInstance?.setOptions(JSON.parse(serializedOptions))\n }, [ref, serializedOptions])\n\n const subscribe = useCallback(\n (onStoreChanged: () => void) => {\n // to match the lifecycle of `useSyncExternalState`, we create the store\n // instance after subscribe and mutate the ref to connect everything\n ref.storeInstance = createDocumentListStore(instance)\n ref.storeInstance.setOptions(ref.initialOptions)\n const state = ref.storeInstance.getState()\n ref.getCurrent = state.getCurrent\n const unsubscribe = state.subscribe(onStoreChanged)\n\n return () => {\n // unsubscribe to clean up the state subscriptions\n unsubscribe()\n // dispose of the instance\n ref.storeInstance?.dispose()\n }\n },\n [instance, ref],\n )\n\n const getSnapshot = useCallback(() => {\n return ref.getCurrent()\n }, [ref])\n\n const state = useSyncExternalStore(subscribe, getSnapshot)\n\n const loadMore = useCallback(() => {\n ref.storeInstance?.loadMore()\n }, [ref])\n\n return {loadMore, ...state}\n}\n","import {type DocumentHandle, getPreviewState, type PreviewValue, resolvePreview} from '@sanity/sdk'\nimport {useCallback, useMemo, useSyncExternalStore} from 'react'\nimport {distinctUntilChanged, EMPTY, Observable, startWith, switchMap} from 'rxjs'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\n/**\n * @alpha\n */\nexport interface UsePreviewOptions {\n document: DocumentHandle\n ref: HTMLElement | null\n}\n\n/**\n * @alpha\n */\nexport function usePreview({\n document: {_id, _type},\n ref,\n}: UsePreviewOptions): [PreviewValue, boolean] {\n const instance = useSanityInstance()\n\n const stateSource = useMemo(\n () => getPreviewState(instance, {document: {_id, _type}}),\n [instance, _id, _type],\n )\n\n // Create subscribe function for useSyncExternalStore\n const subscribe = useCallback(\n (onStoreChanged: () => void) => {\n const subscription = new Observable<boolean>((observer) => {\n // for environments that don't have an intersection observer\n if (typeof IntersectionObserver === 'undefined') return\n\n const intersectionObserver = new IntersectionObserver(\n ([entry]) => observer.next(entry.isIntersecting),\n {rootMargin: '0px', threshold: 0},\n )\n if (ref) intersectionObserver.observe(ref)\n return () => intersectionObserver.disconnect()\n })\n .pipe(\n startWith(false),\n distinctUntilChanged(),\n switchMap((isVisible) =>\n isVisible\n ? new Observable<void>((obs) => {\n return stateSource.subscribe(() => obs.next())\n })\n : EMPTY,\n ),\n )\n .subscribe({next: onStoreChanged})\n\n return () => subscription.unsubscribe()\n },\n [stateSource, ref],\n )\n\n // Create getSnapshot function to return current state\n const getSnapshot = useCallback(() => {\n const previewTuple = stateSource.getCurrent()\n if (!previewTuple[0]) throw resolvePreview(instance, {document: {_id, _type}})\n return previewTuple as [PreviewValue, boolean]\n }, [_id, _type, instance, stateSource])\n\n return useSyncExternalStore(subscribe, getSnapshot)\n}\n"],"names":["state"],"mappings":";;;;;AASa,MAAA,eAAe,sBAAsB,aAAa,GCAlD,iBAAiB,sBAAsB,mBAAmB,GCSjE,eAAe;AAAA,EACnB,SAAS,CAAC;AAAA,EACV,WAAW;AAAA,EACX,SAAS;AAAA,EACT,OAAO;AACT;AAUgB,SAAA,aAAa,UAA+B,IAAkB;AAC5E,QAAM,WAAW,kBAAkB,GAI7B,CAAC,GAAG,IAAI,SAIX,OAAO;AAAA,IACR,eAAe;AAAA,IACf,YAAY,MAAM;AAAA,IAClB,gBAAgB;AAAA,EAChB,EAAA,GAII,oBAAoB,KAAK,UAAU,OAAO;AAChD,YAAU,MAAM;AACd,QAAI,eAAe,WAAW,KAAK,MAAM,iBAAiB,CAAC;AAAA,EAAA,GAC1D,CAAC,KAAK,iBAAiB,CAAC;AAE3B,QAAM,YAAY;AAAA,IAChB,CAAC,mBAA+B;AAG1B,UAAA,gBAAgB,wBAAwB,QAAQ,GACpD,IAAI,cAAc,WAAW,IAAI,cAAc;AACzCA,YAAAA,SAAQ,IAAI,cAAc,SAAS;AACzC,UAAI,aAAaA,OAAM;AACjB,YAAA,cAAcA,OAAM,UAAU,cAAc;AAElD,aAAO,MAAM;AAEC,uBAEZ,IAAI,eAAe,QAAQ;AAAA,MAC7B;AAAA,IACF;AAAA,IACA,CAAC,UAAU,GAAG;AAAA,EAGV,GAAA,cAAc,YAAY,MACvB,IAAI,WAAW,GACrB,CAAC,GAAG,CAAC,GAEF,QAAQ,qBAAqB,WAAW,WAAW;AAMlD,SAAA,EAAC,UAJS,YAAY,MAAM;AACjC,QAAI,eAAe,SAAS;AAAA,KAC3B,CAAC,GAAG,CAAC,GAEU,GAAG,MAAK;AAC5B;ACrEO,SAAS,WAAW;AAAA,EACzB,UAAU,EAAC,KAAK,MAAK;AAAA,EACrB;AACF,GAA+C;AACvC,QAAA,WAAW,qBAEX,cAAc;AAAA,IAClB,MAAM,gBAAgB,UAAU,EAAC,UAAU,EAAC,KAAK,MAAK,GAAE;AAAA,IACxD,CAAC,UAAU,KAAK,KAAK;AAAA,KAIjB,YAAY;AAAA,IAChB,CAAC,mBAA+B;AAC9B,YAAM,eAAe,IAAI,WAAoB,CAAC,aAAa;AAErD,YAAA,OAAO,uBAAyB,IAAa;AAEjD,cAAM,uBAAuB,IAAI;AAAA,UAC/B,CAAC,CAAC,KAAK,MAAM,SAAS,KAAK,MAAM,cAAc;AAAA,UAC/C,EAAC,YAAY,OAAO,WAAW,EAAC;AAAA,QAClC;AACA,eAAI,OAAK,qBAAqB,QAAQ,GAAG,GAClC,MAAM,qBAAqB,WAAW;AAAA,MAC9C,CAAA,EACE;AAAA,QACC,UAAU,EAAK;AAAA,QACf,qBAAqB;AAAA,QACrB;AAAA,UAAU,CAAC,cACT,YACI,IAAI,WAAiB,CAAC,QACb,YAAY,UAAU,MAAM,IAAI,KAAK,CAAC,CAC9C,IACD;AAAA,QAAA;AAAA,MAGP,EAAA,UAAU,EAAC,MAAM,gBAAe;AAE5B,aAAA,MAAM,aAAa,YAAY;AAAA,IACxC;AAAA,IACA,CAAC,aAAa,GAAG;AAAA,EAAA,GAIb,cAAc,YAAY,MAAM;AAC9B,UAAA,eAAe,YAAY,WAAW;AAC5C,QAAI,CAAC,aAAa,CAAC,EAAS,OAAA,eAAe,UAAU,EAAC,UAAU,EAAC,KAAK,SAAO;AACtE,WAAA;AAAA,KACN,CAAC,KAAK,OAAO,UAAU,WAAW,CAAC;AAE/B,SAAA,qBAAqB,WAAW,WAAW;AACpD;"}
@@ -1,13 +0,0 @@
1
- export {AuthBoundary, type AuthBoundaryProps} from '../components/auth/AuthBoundary'
2
- export {AuthError} from '../components/auth/AuthError'
3
- export {Login} from '../components/auth/Login'
4
- export {LoginCallback} from '../components/auth/LoginCallback'
5
- export {LoginError, type LoginErrorProps} from '../components/auth/LoginError'
6
- export {LoginLayout, type LoginLayoutProps} from '../components/auth/LoginLayout'
7
- export type {SanityProviderProps} from '../components/context/SanityProvider'
8
- export {SanityProvider} from '../components/context/SanityProvider'
9
- export {DocumentGridLayout} from '../components/DocumentGridLayout/DocumentGridLayout'
10
- export {DocumentListLayout} from '../components/DocumentListLayout/DocumentListLayout'
11
- export {DocumentPreviewLayout} from '../components/DocumentPreviewLayout/DocumentPreviewLayout'
12
- export {type DocumentPreviewLayoutProps} from '../components/DocumentPreviewLayout/DocumentPreviewLayout'
13
- export {LoginLinks} from '../components/Login/LoginLinks'
@@ -1,9 +0,0 @@
1
- export {useAuthState} from '../hooks/auth/useAuthState'
2
- export {useAuthToken} from '../hooks/auth/useAuthToken'
3
- export {useCurrentUser} from '../hooks/auth/useCurrentUser'
4
- export {useHandleCallback} from '../hooks/auth/useHandleCallback'
5
- export {useLoginUrls} from '../hooks/auth/useLoginUrls'
6
- export {useLogOut} from '../hooks/auth/useLogOut'
7
- export {useSanityInstance} from '../hooks/context/useSanityInstance'
8
- export {type UseDocuments, useDocuments} from '../hooks/documentCollection/useDocuments'
9
- export {usePreview, type UsePreviewOptions} from '../hooks/preview/usePreview'
@@ -1,113 +0,0 @@
1
- import {type Meta, type StoryObj} from '@storybook/react'
2
-
3
- import {DocumentPreviewLayout} from '../DocumentPreviewLayout/DocumentPreviewLayout.tsx'
4
- import {DocumentGridLayout} from './DocumentGridLayout.tsx'
5
-
6
- const meta: Meta<typeof DocumentGridLayout> = {
7
- title: 'DocumentGridLayout',
8
- component: DocumentGridLayout,
9
- }
10
-
11
- export default meta
12
- type Story = StoryObj<typeof meta>
13
-
14
- const mockDocs = [
15
- {id: '1', title: 'Just a title', url: '#', docType: 'article', status: 'published'},
16
- {
17
- id: '2',
18
- title: 'A title, but also',
19
- subtitle: 'A subtitle',
20
- docType: 'article',
21
- status: 'draft',
22
- media: {
23
- type: 'image-asset',
24
- url: 'https://picsum.photos/75/75',
25
- },
26
- },
27
- {
28
- id: '3',
29
- title: 'Hello World',
30
- subtitle: 'What a nice list I get to live in',
31
- docType: 'image',
32
- status: 'published',
33
- media: {
34
- type: 'image-asset',
35
- url: 'https://picsum.photos/80/80',
36
- },
37
- },
38
- {
39
- id: '4',
40
- title: 'I’ve been selected',
41
- subtitle: 'I feel special',
42
- selected: true,
43
- docType: 'video',
44
- status: 'draft',
45
- media: {
46
- type: 'image-asset',
47
- url: 'https://picsum.photos/100/100',
48
- },
49
- },
50
- {
51
- id: '5',
52
- title: 'A very long title that at some point might get truncated if it goes for long enough',
53
- subtitle:
54
- 'Along with a subtitle that is quite long as well, in order to demonstrate the truncation of its text',
55
- docType: 'audio',
56
- status: 'published',
57
- media: {
58
- type: 'image-asset',
59
- url: 'https://picsum.photos/75/75',
60
- },
61
- },
62
- {
63
- id: '6',
64
- title: 'Hello World',
65
- subtitle: 'What a nice list I get to live in',
66
- docType: 'pdf',
67
- status: 'published',
68
- media: {
69
- type: 'image-asset',
70
- url: 'https://picsum.photos/75/75',
71
- },
72
- },
73
- {id: '7', title: 'Just a title', url: '#', docType: 'note', status: 'published,'},
74
- {
75
- id: '8',
76
- title: 'A title, but also',
77
- subtitle: 'A subtitle',
78
- docType: 'document',
79
- status: 'draft',
80
- },
81
- {
82
- id: '9',
83
- title: 'Hello World',
84
- subtitle: 'What a nice list I get to live in',
85
- docType: 'biography',
86
- status: 'published',
87
- media: {
88
- type: 'image-asset',
89
- url: 'https://picsum.photos/200/200',
90
- },
91
- },
92
- ]
93
-
94
- export const Default: Story = {
95
- render: () => {
96
- return (
97
- <DocumentGridLayout>
98
- {mockDocs.map((doc) => (
99
- <li key={doc.id}>
100
- <DocumentPreviewLayout
101
- title={doc.title}
102
- subtitle={doc.subtitle}
103
- media={doc.media}
104
- selected={doc.selected}
105
- docType={doc.docType}
106
- status={doc.status}
107
- />
108
- </li>
109
- ))}
110
- </DocumentGridLayout>
111
- )
112
- },
113
- }
@@ -1,42 +0,0 @@
1
- import {describe, expect, it} from 'vitest'
2
-
3
- import {render, screen} from '../../../test/test-utils.tsx'
4
- import {DocumentGridLayout} from './DocumentGridLayout.tsx'
5
-
6
- describe('DocumentGridLayout', () => {
7
- const mockDocuments = [
8
- {
9
- id: '1',
10
- title: 'Test Document 1',
11
- subtitle: 'Subtitle 1',
12
- docType: 'post',
13
- status: 'published',
14
- url: '/doc/1',
15
- },
16
- {
17
- id: '2',
18
- title: 'Test Document 2',
19
- subtitle: 'Subtitle 2',
20
- docType: 'page',
21
- status: 'draft',
22
- url: '/doc/2',
23
- },
24
- ]
25
-
26
- it('renders the expected content', () => {
27
- render(
28
- <DocumentGridLayout>
29
- {mockDocuments.map((doc) => (
30
- <li key={doc.id}>{doc.title}</li>
31
- ))}
32
- </DocumentGridLayout>,
33
- )
34
- const list = screen.getByRole('list')
35
- expect(list.tagName).toBe('OL')
36
- expect(list.classList).toContain('DocumentGridLayout')
37
-
38
- const items = screen.getAllByRole('listitem')
39
- expect(items[0]).toContainHTML('Test Document 1')
40
- expect(items[1]).toContainHTML('Test Document 2')
41
- })
42
- })
@@ -1,21 +0,0 @@
1
- import '../../css/styles.css'
2
-
3
- import type {PropsWithChildren, ReactElement} from 'react'
4
-
5
- /**
6
- * @public
7
- */
8
- export const DocumentGridLayout = (props: PropsWithChildren): ReactElement => {
9
- return (
10
- <>
11
- <style>{`
12
- .DocumentGridLayout {
13
- grid-template-columns: repeat(auto-fit, minmax(38ch, 1fr));
14
- }
15
- `}</style>
16
- <ol className="DocumentGridLayout list-none grid">{props.children}</ol>
17
- </>
18
- )
19
- }
20
-
21
- DocumentGridLayout.displayName = 'DocumentGridLayout'
@@ -1,105 +0,0 @@
1
- import {type Meta, type StoryObj} from '@storybook/react'
2
-
3
- import {DocumentPreviewLayout} from '../DocumentPreviewLayout/DocumentPreviewLayout.tsx'
4
- import {DocumentListLayout} from './DocumentListLayout.tsx'
5
-
6
- const meta: Meta<typeof DocumentListLayout> = {
7
- title: 'DocumentListLayout',
8
- component: DocumentListLayout,
9
- }
10
-
11
- export default meta
12
- type Story = StoryObj<typeof meta>
13
-
14
- const mockDocs = [
15
- {id: '1', title: 'Just a title', url: '#', docType: 'article', status: 'published'},
16
- {
17
- id: '2',
18
- title: 'A title, but also',
19
- subtitle: 'A subtitle',
20
- docType: 'article',
21
- status: 'draft',
22
- media: {
23
- type: 'image-asset',
24
- url: 'https://picsum.photos/75/75',
25
- },
26
- },
27
- {
28
- id: '3',
29
- title: 'Hello World',
30
- subtitle: 'What a nice list I get to live in',
31
- docType: 'image',
32
- status: 'published',
33
- media: {
34
- type: 'image-asset',
35
- url: 'https://picsum.photos/100/100',
36
- },
37
- },
38
- {
39
- id: '4',
40
- title: 'I’ve been selected',
41
- subtitle: 'I feel special',
42
- selected: true,
43
- docType: 'video',
44
- status: 'draft',
45
- },
46
- {
47
- id: '5',
48
- title: 'A very long title that at some point might get truncated if it goes for long enough',
49
- subtitle:
50
- 'Along with a subtitle that is quite long as well, in order to demonstrate the truncation of its text',
51
- docType: 'audio',
52
- status: 'published',
53
- },
54
- {
55
- id: '6',
56
- title: 'Hello World',
57
- subtitle: 'What a nice list I get to live in',
58
- docType: 'pdf',
59
- status: 'published',
60
- media: {
61
- type: 'image-asset',
62
- url: 'https://picsum.photos/80/80',
63
- },
64
- },
65
- {id: '7', title: 'Just a title', url: '#', docType: 'note', status: 'published,'},
66
- {
67
- id: '8',
68
- title: 'A title, but also',
69
- subtitle: 'A subtitle',
70
- docType: 'document',
71
- status: 'draft',
72
- },
73
- {
74
- id: '9',
75
- title: 'Hello World',
76
- subtitle: 'What a nice list I get to live in',
77
- docType: 'biography',
78
- status: 'published',
79
- media: {
80
- type: 'image-asset',
81
- url: 'https://picsum.photos/200/200',
82
- },
83
- },
84
- ]
85
-
86
- export const Default: Story = {
87
- render: () => {
88
- return (
89
- <DocumentListLayout>
90
- {mockDocs.map((doc) => (
91
- <li key={doc.id}>
92
- <DocumentPreviewLayout
93
- title={doc.title}
94
- subtitle={doc.subtitle}
95
- media={doc.media}
96
- selected={doc.selected}
97
- docType={doc.docType}
98
- status={doc.status}
99
- />
100
- </li>
101
- ))}
102
- </DocumentListLayout>
103
- )
104
- },
105
- }
@@ -1,42 +0,0 @@
1
- import {describe, expect, it} from 'vitest'
2
-
3
- import {render, screen} from '../../../test/test-utils.tsx'
4
- import {DocumentListLayout} from './DocumentListLayout.tsx'
5
-
6
- describe('DocumentListLayout', () => {
7
- const mockDocuments = [
8
- {
9
- id: '1',
10
- title: 'Test Document 1',
11
- subtitle: 'Subtitle 1',
12
- docType: 'post',
13
- status: 'published',
14
- url: '/doc/1',
15
- },
16
- {
17
- id: '2',
18
- title: 'Test Document 2',
19
- subtitle: 'Subtitle 2',
20
- docType: 'page',
21
- status: 'draft',
22
- url: '/doc/2',
23
- },
24
- ]
25
-
26
- it('renders the expected content', () => {
27
- render(
28
- <DocumentListLayout>
29
- {mockDocuments.map((doc) => (
30
- <li key={doc.id}>{doc.title}</li>
31
- ))}
32
- </DocumentListLayout>,
33
- )
34
- const list = screen.getByRole('list')
35
- expect(list.tagName).toBe('OL')
36
- expect(list.classList).toContain('DocumentListLayout')
37
-
38
- const items = screen.getAllByRole('listitem')
39
- expect(items[0]).toContainHTML('Test Document 1')
40
- expect(items[1]).toContainHTML('Test Document 2')
41
- })
42
- })
@@ -1,12 +0,0 @@
1
- import '../../css/styles.css'
2
-
3
- import type {PropsWithChildren, ReactElement} from 'react'
4
-
5
- /**
6
- * @public
7
- */
8
- export const DocumentListLayout = (props: PropsWithChildren): ReactElement => {
9
- return <ol className="DocumentListLayout list-none">{props.children}</ol>
10
- }
11
-
12
- DocumentListLayout.displayName = 'DocumentListLayout'