@sanity/sdk-react 0.0.0-alpha.8 → 0.0.0-chore-react-18-compat.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.
Files changed (100) hide show
  1. package/README.md +33 -126
  2. package/dist/index.d.ts +4811 -2
  3. package/dist/index.js +1069 -2
  4. package/dist/index.js.map +1 -1
  5. package/package.json +23 -45
  6. package/src/_exports/index.ts +66 -10
  7. package/src/components/Login/LoginLinks.test.tsx +90 -0
  8. package/src/components/Login/LoginLinks.tsx +58 -0
  9. package/src/components/SDKProvider.test.tsx +79 -0
  10. package/src/components/SDKProvider.tsx +42 -0
  11. package/src/components/SanityApp.test.tsx +104 -2
  12. package/src/components/SanityApp.tsx +54 -17
  13. package/src/components/auth/AuthBoundary.test.tsx +4 -4
  14. package/src/components/auth/AuthBoundary.tsx +13 -3
  15. package/src/components/auth/Login.test.tsx +1 -1
  16. package/src/components/auth/Login.tsx +11 -26
  17. package/src/components/auth/LoginCallback.test.tsx +3 -3
  18. package/src/components/auth/LoginCallback.tsx +8 -11
  19. package/src/components/auth/LoginError.tsx +12 -8
  20. package/src/components/auth/LoginFooter.tsx +13 -20
  21. package/src/components/auth/LoginLayout.tsx +8 -9
  22. package/src/components/auth/authTestHelpers.tsx +1 -8
  23. package/src/components/utils.ts +22 -0
  24. package/src/context/SanityInstanceContext.ts +4 -0
  25. package/src/context/SanityProvider.test.tsx +1 -1
  26. package/src/context/SanityProvider.tsx +10 -8
  27. package/src/hooks/_synchronous-groq-js.mjs +4 -0
  28. package/src/hooks/auth/useAuthState.tsx +0 -2
  29. package/src/hooks/auth/useCurrentUser.tsx +27 -20
  30. package/src/hooks/auth/useDashboardOrganizationId.test.tsx +42 -0
  31. package/src/hooks/auth/useDashboardOrganizationId.tsx +29 -0
  32. package/src/hooks/auth/useHandleAuthCallback.test.tsx +16 -0
  33. package/src/hooks/auth/{useHandleCallback.tsx → useHandleAuthCallback.tsx} +6 -6
  34. package/src/hooks/auth/useLogOut.test.tsx +2 -2
  35. package/src/hooks/client/useClient.ts +9 -30
  36. package/src/hooks/comlink/useFrameConnection.test.tsx +55 -10
  37. package/src/hooks/comlink/useFrameConnection.ts +39 -43
  38. package/src/hooks/comlink/useManageFavorite.test.ts +111 -0
  39. package/src/hooks/comlink/useManageFavorite.ts +130 -0
  40. package/src/hooks/comlink/useRecordDocumentHistoryEvent.test.ts +81 -0
  41. package/src/hooks/comlink/useRecordDocumentHistoryEvent.ts +106 -0
  42. package/src/hooks/comlink/useWindowConnection.test.ts +53 -12
  43. package/src/hooks/comlink/useWindowConnection.ts +69 -29
  44. package/src/hooks/context/useSanityInstance.test.tsx +1 -1
  45. package/src/hooks/context/useSanityInstance.ts +21 -5
  46. package/src/hooks/dashboard/useNavigateToStudioDocument.test.ts +178 -0
  47. package/src/hooks/dashboard/useNavigateToStudioDocument.ts +123 -0
  48. package/src/hooks/dashboard/useStudioWorkspacesByResourceId.test.tsx +278 -0
  49. package/src/hooks/dashboard/useStudioWorkspacesByResourceId.ts +92 -0
  50. package/src/hooks/datasets/useDatasets.ts +40 -0
  51. package/src/hooks/document/useApplyDocumentActions.test.ts +25 -0
  52. package/src/hooks/document/useApplyDocumentActions.ts +75 -0
  53. package/src/hooks/document/useDocument.test.ts +81 -0
  54. package/src/hooks/document/useDocument.ts +107 -0
  55. package/src/hooks/document/useDocumentEvent.test.ts +63 -0
  56. package/src/hooks/document/useDocumentEvent.ts +54 -0
  57. package/src/hooks/document/useDocumentPermissions.ts +84 -0
  58. package/src/hooks/document/useDocumentSyncStatus.test.ts +16 -0
  59. package/src/hooks/document/useDocumentSyncStatus.ts +33 -0
  60. package/src/hooks/document/useEditDocument.test.ts +179 -0
  61. package/src/hooks/document/useEditDocument.ts +195 -0
  62. package/src/hooks/documents/useDocuments.test.tsx +152 -0
  63. package/src/hooks/documents/useDocuments.ts +174 -0
  64. package/src/hooks/helpers/createCallbackHook.tsx +3 -2
  65. package/src/hooks/helpers/createStateSourceHook.test.tsx +66 -0
  66. package/src/hooks/helpers/createStateSourceHook.tsx +29 -10
  67. package/src/hooks/paginatedDocuments/usePaginatedDocuments.test.tsx +259 -0
  68. package/src/hooks/paginatedDocuments/usePaginatedDocuments.ts +290 -0
  69. package/src/hooks/preview/usePreview.test.tsx +6 -6
  70. package/src/hooks/preview/usePreview.tsx +12 -9
  71. package/src/hooks/projection/useProjection.test.tsx +218 -0
  72. package/src/hooks/projection/useProjection.ts +147 -0
  73. package/src/hooks/projects/useProject.ts +48 -0
  74. package/src/hooks/projects/useProjects.ts +45 -0
  75. package/src/hooks/query/useQuery.test.tsx +188 -0
  76. package/src/hooks/query/useQuery.ts +103 -0
  77. package/src/hooks/users/useUsers.test.ts +163 -0
  78. package/src/hooks/users/useUsers.ts +107 -0
  79. package/src/utils/getEnv.ts +21 -0
  80. package/src/version.ts +8 -0
  81. package/dist/_chunks-es/context.js +0 -8
  82. package/dist/_chunks-es/context.js.map +0 -1
  83. package/dist/_chunks-es/useLogOut.js +0 -44
  84. package/dist/_chunks-es/useLogOut.js.map +0 -1
  85. package/dist/components.d.ts +0 -111
  86. package/dist/components.js +0 -153
  87. package/dist/components.js.map +0 -1
  88. package/dist/context.d.ts +0 -45
  89. package/dist/context.js +0 -5
  90. package/dist/context.js.map +0 -1
  91. package/dist/hooks.d.ts +0 -3485
  92. package/dist/hooks.js +0 -167
  93. package/dist/hooks.js.map +0 -1
  94. package/src/_exports/components.ts +0 -2
  95. package/src/_exports/context.ts +0 -2
  96. package/src/_exports/hooks.ts +0 -27
  97. package/src/hooks/auth/useHandleCallback.test.tsx +0 -16
  98. package/src/hooks/client/useClient.test.tsx +0 -130
  99. package/src/hooks/documentCollection/useDocuments.test.ts +0 -130
  100. package/src/hooks/documentCollection/useDocuments.ts +0 -135
@@ -1,153 +0,0 @@
1
- import { jsxs, jsx } from "react/jsx-runtime";
2
- import { AuthStateType, createSanityInstance } from "@sanity/sdk";
3
- import { Suspense, useEffect, useCallback, useMemo } from "react";
4
- import { ErrorBoundary } from "react-error-boundary";
5
- import { useLoginUrls, useHandleCallback, useLogOut, useAuthState } from "./_chunks-es/useLogOut.js";
6
- import { Box, Flex, Inline, Text, Container, Card, Heading, Spinner, Stack, Button } from "@sanity/ui";
7
- import { SanityLogo } from "@sanity/logos";
8
- import { SanityProvider } from "./_chunks-es/context.js";
9
- class AuthError extends Error {
10
- constructor(error) {
11
- typeof error == "object" && error && "message" in error && typeof error.message == "string" ? super(error.message) : super(), this.cause = error;
12
- }
13
- }
14
- const LINKS = [
15
- {
16
- url: "https://slack.sanity.io/",
17
- i18nKey: "workspaces.community-title",
18
- title: "Community"
19
- },
20
- {
21
- url: "https://www.sanity.io/docs",
22
- i18nKey: "workspaces.docs-title",
23
- title: "Docs"
24
- },
25
- {
26
- url: "https://www.sanity.io/legal/privacy",
27
- i18nKey: "workspaces.privacy-title",
28
- title: "Privacy"
29
- },
30
- {
31
- url: "https://www.sanity.io",
32
- i18nKey: "workspaces.sanity-io-title",
33
- title: "sanity.io"
34
- }
35
- ];
36
- function LoginFooter() {
37
- return /* @__PURE__ */ jsxs(Box, { children: [
38
- /* @__PURE__ */ jsx(Flex, { justify: "center", children: /* @__PURE__ */ jsx(SanityLogo, {}) }),
39
- /* @__PURE__ */ jsx(Flex, { justify: "center", children: /* @__PURE__ */ jsx(Inline, { space: 2, paddingY: 3, children: LINKS.map((link) => /* @__PURE__ */ jsx(Text, { size: 0, children: /* @__PURE__ */ jsx(
40
- "a",
41
- {
42
- href: link.url,
43
- target: "_blank",
44
- rel: "noopener noreferrer",
45
- style: { color: "inherit" },
46
- children: link.title
47
- }
48
- ) }, link.url)) }) })
49
- ] });
50
- }
51
- function LoginLayout({
52
- children,
53
- footer = /* @__PURE__ */ jsx(LoginFooter, {}),
54
- header
55
- }) {
56
- return /* @__PURE__ */ jsx(Container, { width: 0, children: /* @__PURE__ */ jsxs(Card, { shadow: 1, radius: 2, padding: 4, children: [
57
- header && header,
58
- children && children,
59
- footer
60
- ] }) });
61
- }
62
- function Login({ header, footer }) {
63
- return /* @__PURE__ */ jsxs(LoginLayout, { header, footer, children: [
64
- /* @__PURE__ */ jsx(Heading, { as: "h6", align: "center", children: "Choose login provider:" }),
65
- /* @__PURE__ */ jsx(
66
- Suspense,
67
- {
68
- fallback: /* @__PURE__ */ jsx(Box, { padding: 5, children: /* @__PURE__ */ jsx(Flex, { align: "center", justify: "center", children: /* @__PURE__ */ jsx(Spinner, {}) }) }),
69
- children: /* @__PURE__ */ jsx(Providers, {})
70
- }
71
- )
72
- ] });
73
- }
74
- function Providers() {
75
- const loginUrls = useLoginUrls();
76
- return /* @__PURE__ */ jsx(Stack, { space: 3, marginY: 5, children: loginUrls.map(({ title, url }) => /* @__PURE__ */ jsx(
77
- Button,
78
- {
79
- as: "a",
80
- href: url,
81
- mode: "ghost",
82
- text: title,
83
- textAlign: "center",
84
- fontSize: 2
85
- },
86
- url
87
- )) });
88
- }
89
- function LoginCallback({ header, footer }) {
90
- const handleCallback = useHandleCallback();
91
- return useEffect(() => {
92
- const url = new URL(location.href);
93
- handleCallback(url.toString()).then((replacementLocation) => {
94
- replacementLocation && history.replaceState(null, "", replacementLocation);
95
- });
96
- }, [handleCallback]), /* @__PURE__ */ jsxs(LoginLayout, { header, footer, children: [
97
- /* @__PURE__ */ jsx(Heading, { as: "h6", align: "center", children: "Logging you in\u2026" }),
98
- /* @__PURE__ */ jsx(Flex, { paddingY: 5, align: "center", justify: "center", children: /* @__PURE__ */ jsx(Spinner, {}) })
99
- ] });
100
- }
101
- function LoginError({
102
- error,
103
- resetErrorBoundary,
104
- header,
105
- footer
106
- }) {
107
- if (!(error instanceof AuthError)) throw error;
108
- const logout = useLogOut(), handleRetry = useCallback(async () => {
109
- await logout(), resetErrorBoundary();
110
- }, [logout, resetErrorBoundary]);
111
- return /* @__PURE__ */ jsx(LoginLayout, { header, footer, children: /* @__PURE__ */ jsxs(Stack, { space: 5, marginBottom: 5, children: [
112
- /* @__PURE__ */ jsx(Heading, { as: "h6", align: "center", children: "Authentication Error" }),
113
- /* @__PURE__ */ jsx(Text, { align: "center", children: "Please try again or contact support if the problem persists." }),
114
- /* @__PURE__ */ jsx(Button, { mode: "ghost", onClick: handleRetry, text: "Retry", fontSize: 2 })
115
- ] }) });
116
- }
117
- typeof window < "u" && window.self !== window.top && import("@sanity/os/bridge");
118
- function AuthBoundary({
119
- LoginErrorComponent = LoginError,
120
- ...props
121
- }) {
122
- const { header, footer } = props, FallbackComponent = useMemo(() => function(fallbackProps) {
123
- return /* @__PURE__ */ jsx(LoginErrorComponent, { ...fallbackProps, header, footer });
124
- }, [header, footer, LoginErrorComponent]);
125
- return /* @__PURE__ */ jsx(ErrorBoundary, { FallbackComponent, children: /* @__PURE__ */ jsx(AuthSwitch, { ...props }) });
126
- }
127
- function AuthSwitch({
128
- LoginComponent = Login,
129
- CallbackComponent = LoginCallback,
130
- children,
131
- ...props
132
- }) {
133
- const authState = useAuthState();
134
- switch (authState.type) {
135
- case AuthStateType.ERROR:
136
- throw new AuthError(authState.error);
137
- case AuthStateType.LOGGING_IN:
138
- return /* @__PURE__ */ jsx(CallbackComponent, { ...props });
139
- case AuthStateType.LOGGED_IN:
140
- return children;
141
- default:
142
- return /* @__PURE__ */ jsx(LoginComponent, { ...props });
143
- }
144
- }
145
- function SanityApp({ sanityConfig, children }) {
146
- const sanityInstance = createSanityInstance(sanityConfig);
147
- return /* @__PURE__ */ jsx(SanityProvider, { sanityInstance, children: /* @__PURE__ */ jsx(AuthBoundary, { children }) });
148
- }
149
- export {
150
- AuthBoundary,
151
- SanityApp
152
- };
153
- //# sourceMappingURL=components.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"components.js","sources":["../src/components/auth/AuthError.ts","../src/components/auth/LoginFooter.tsx","../src/components/auth/LoginLayout.tsx","../src/components/auth/Login.tsx","../src/components/auth/LoginCallback.tsx","../src/components/auth/LoginError.tsx","../src/components/auth/AuthBoundary.tsx","../src/components/SanityApp.tsx"],"sourcesContent":["/**\n * Error class for authentication-related errors. Wraps errors thrown during the\n * authentication flow.\n *\n * @remarks\n * This class provides a consistent error type for authentication failures while\n * preserving the original error as the cause. If the original error has a\n * message property, it will be used as the error message.\n *\n * @alpha\n */\nexport class AuthError extends Error {\n constructor(error: unknown) {\n if (\n typeof error === 'object' &&\n !!error &&\n 'message' in error &&\n typeof error.message === 'string'\n ) {\n super(error.message)\n } else {\n super()\n }\n\n this.cause = error\n }\n}\n","import {SanityLogo} from '@sanity/logos'\nimport {Box, Flex, Inline, Text} from '@sanity/ui'\n\nconst LINKS = [\n {\n url: 'https://slack.sanity.io/',\n i18nKey: 'workspaces.community-title',\n title: 'Community',\n },\n {\n url: 'https://www.sanity.io/docs',\n i18nKey: 'workspaces.docs-title',\n title: 'Docs',\n },\n {\n url: 'https://www.sanity.io/legal/privacy',\n i18nKey: 'workspaces.privacy-title',\n title: 'Privacy',\n },\n {\n url: 'https://www.sanity.io',\n i18nKey: 'workspaces.sanity-io-title',\n title: 'sanity.io',\n },\n]\n\n/**\n * Default footer component for login screens showing Sanity branding and legal\n * links.\n *\n * @alpha\n */\nexport function LoginFooter(): React.ReactNode {\n return (\n <Box>\n <Flex justify=\"center\">\n <SanityLogo />\n </Flex>\n\n <Flex justify=\"center\">\n <Inline space={2} paddingY={3}>\n {LINKS.map((link) => (\n <Text size={0} key={link.url}>\n <a\n href={link.url}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n style={{color: 'inherit'}}\n >\n {link.title}\n </a>\n </Text>\n ))}\n </Inline>\n </Flex>\n </Box>\n )\n}\n","import {Card, Container} from '@sanity/ui'\n\nimport {LoginFooter} from './LoginFooter'\n\n/**\n * @alpha\n * @internal\n */\nexport interface LoginLayoutProps {\n /** Optional header content rendered at top of card */\n header?: React.ReactNode\n\n /** Optional footer content rendered below card. Defaults to an internal login footer */\n footer?: React.ReactNode\n\n /** Main content rendered in card body */\n children?: React.ReactNode\n}\n\n/**\n * Layout component for login-related screens providing consistent styling and structure.\n * Renders content in a centered card with optional header and footer sections.\n *\n * Can be used to build custom login screens for the AuthBoundary component, including:\n * - Login provider selection (LoginComponent)\n * - OAuth callback handling (CallbackComponent)\n * - Error states (LoginErrorComponent)\n *\n * @example\n * ```tsx\n * // Custom login screen using the layout\n * function CustomLogin({header, footer}: LoginLayoutProps) {\n * return (\n * <LoginLayout\n * header={header}\n * footer={footer}\n * >\n * <CustomLoginContent />\n * </LoginLayout>\n * )\n * }\n *\n * // Use with AuthBoundary\n * <AuthBoundary\n * LoginComponent={CustomLogin}\n * header={<Logo />}\n * >\n * <ProtectedContent />\n * </AuthBoundary>\n * ```\n *\n * @alpha\n */\nexport function LoginLayout({\n children,\n footer = <LoginFooter />,\n header,\n}: LoginLayoutProps): React.ReactNode {\n return (\n <Container width={0}>\n <Card shadow={1} radius={2} padding={4}>\n {header && header}\n\n {children && children}\n\n {footer}\n </Card>\n </Container>\n )\n}\n","import {Box, Button, Flex, Heading, Spinner, Stack} from '@sanity/ui'\nimport {type JSX, Suspense} from 'react'\n\nimport {useLoginUrls} from '../../hooks/auth/useLoginUrls'\nimport {LoginLayout, type LoginLayoutProps} from './LoginLayout'\n\n/**\n * Login component that displays available authentication providers.\n * Renders a list of login options with a loading fallback while providers load.\n *\n * @alpha\n * @internal\n */\nexport function Login({header, footer}: LoginLayoutProps): JSX.Element {\n return (\n <LoginLayout header={header} footer={footer}>\n <Heading as=\"h6\" align=\"center\">\n Choose login provider:\n </Heading>\n\n <Suspense\n fallback={\n <Box padding={5}>\n <Flex align=\"center\" justify=\"center\">\n <Spinner />\n </Flex>\n </Box>\n }\n >\n <Providers />\n </Suspense>\n </LoginLayout>\n )\n}\n\nfunction Providers() {\n const loginUrls = useLoginUrls()\n\n return (\n <Stack space={3} marginY={5}>\n {loginUrls.map(({title, url}) => (\n <Button\n key={url}\n as=\"a\"\n href={url}\n mode=\"ghost\"\n text={title}\n textAlign=\"center\"\n fontSize={2}\n ></Button>\n ))}\n </Stack>\n )\n}\n","import {Flex, Heading, Spinner} from '@sanity/ui'\nimport {useEffect} from 'react'\n\nimport {useHandleCallback} from '../../hooks/auth/useHandleCallback'\nimport {LoginLayout, type LoginLayoutProps} from './LoginLayout'\n\n/**\n/**\n * Component shown during auth callback processing that handles login completion.\n * Automatically processes the auth callback when mounted and updates the URL\n * to remove callback parameters without triggering a page reload.\n *\n * @alpha\n */\nexport function LoginCallback({header, footer}: LoginLayoutProps): React.ReactNode {\n const handleCallback = useHandleCallback()\n\n useEffect(() => {\n const url = new URL(location.href)\n handleCallback(url.toString()).then((replacementLocation) => {\n if (replacementLocation) {\n // history API with `replaceState` is used to prevent a reload but still\n // remove the short-lived token from the URL\n history.replaceState(null, '', replacementLocation)\n }\n })\n }, [handleCallback])\n\n return (\n <LoginLayout header={header} footer={footer}>\n <Heading as=\"h6\" align=\"center\">\n Logging you in…\n </Heading>\n <Flex paddingY={5} align=\"center\" justify=\"center\">\n <Spinner />\n </Flex>\n </LoginLayout>\n )\n}\n","import {Button, Heading, Stack, Text} from '@sanity/ui'\nimport {useCallback} from 'react'\nimport {type FallbackProps} from 'react-error-boundary'\n\nimport {useLogOut} from '../../hooks/auth/useLogOut'\nimport {AuthError} from './AuthError'\nimport {LoginLayout, type LoginLayoutProps} from './LoginLayout'\n\n/**\n * @alpha\n */\nexport type LoginErrorProps = FallbackProps & LoginLayoutProps\n\n/**\n * Displays authentication error details and provides retry functionality.\n * Only handles {@link AuthError} instances - rethrows other error types.\n *\n * @alpha\n */\nexport function LoginError({\n error,\n resetErrorBoundary,\n header,\n footer,\n}: LoginErrorProps): React.ReactNode {\n if (!(error instanceof AuthError)) throw error\n const logout = useLogOut()\n\n const handleRetry = useCallback(async () => {\n await logout()\n resetErrorBoundary()\n }, [logout, resetErrorBoundary])\n\n return (\n <LoginLayout header={header} footer={footer}>\n <Stack space={5} marginBottom={5}>\n <Heading as=\"h6\" align=\"center\">\n Authentication Error\n </Heading>\n <Text align=\"center\">Please try again or contact support if the problem persists.</Text>\n <Button mode=\"ghost\" onClick={handleRetry} text=\"Retry\" fontSize={2} />\n </Stack>\n </LoginLayout>\n )\n}\n","import {AuthStateType} from '@sanity/sdk'\nimport {useMemo} from 'react'\nimport {ErrorBoundary, type FallbackProps} from 'react-error-boundary'\n\nimport {useAuthState} from '../../hooks/auth/useAuthState'\nimport {AuthError} from './AuthError'\nimport {Login} from './Login'\nimport {LoginCallback} from './LoginCallback'\nimport {LoginError, type LoginErrorProps} from './LoginError'\nimport {type LoginLayoutProps} from './LoginLayout'\n\n// Only import bridge if we're in an iframe. This assumes that the app is\n// running withing SanityOS if it is in an iframe.\nif (typeof window !== 'undefined' && window.self !== window.top) {\n import('@sanity/os/bridge')\n}\n\n/**\n * @internal\n */\ninterface AuthBoundaryProps extends LoginLayoutProps {\n /**\n * Custom component to render the login screen.\n * Receives all login layout props. Defaults to {@link Login}.\n */\n LoginComponent?: React.ComponentType<LoginLayoutProps>\n\n /**\n * Custom component to render during OAuth callback processing.\n * Receives all login layout props. Defaults to {@link LoginCallback}.\n */\n CallbackComponent?: React.ComponentType<LoginLayoutProps>\n\n /**\n * Custom component to render when authentication errors occur.\n * Receives login layout props and error boundary props. Defaults to\n * {@link LoginError}\n */\n LoginErrorComponent?: React.ComponentType<LoginErrorProps>\n}\n\n/**\n * A component that handles authentication flow and error boundaries for a\n * protected section of the application.\n *\n * @remarks\n * This component manages different authentication states and renders the\n * appropriate components based on that state.\n *\n * @example\n * ```tsx\n * function App() {\n * return (\n * <AuthBoundary header={<MyLogo />}>\n * <ProtectedContent />\n * </AuthBoundary>\n * )\n * }\n * ```\n *\n * @internal\n */\nexport function AuthBoundary({\n LoginErrorComponent = LoginError,\n ...props\n}: AuthBoundaryProps): React.ReactNode {\n const {header, footer} = props\n const FallbackComponent = useMemo(() => {\n return function LoginComponentWithLayoutProps(fallbackProps: FallbackProps) {\n return <LoginErrorComponent {...fallbackProps} header={header} footer={footer} />\n }\n }, [header, footer, LoginErrorComponent])\n\n return (\n <ErrorBoundary FallbackComponent={FallbackComponent}>\n <AuthSwitch {...props} />\n </ErrorBoundary>\n )\n}\n\ninterface AuthSwitchProps extends LoginLayoutProps {\n LoginComponent?: React.ComponentType<LoginLayoutProps>\n CallbackComponent?: React.ComponentType<LoginLayoutProps>\n}\n\nfunction AuthSwitch({\n LoginComponent = Login,\n CallbackComponent = LoginCallback,\n children,\n ...props\n}: AuthSwitchProps) {\n const authState = useAuthState()\n\n switch (authState.type) {\n case AuthStateType.ERROR: {\n throw new AuthError(authState.error)\n }\n case AuthStateType.LOGGING_IN: {\n return <CallbackComponent {...props} />\n }\n case AuthStateType.LOGGED_IN: {\n return children\n }\n default: {\n return <LoginComponent {...props} />\n }\n }\n}\n","import {createSanityInstance, type SanityConfig} from '@sanity/sdk'\nimport {type ReactElement} from 'react'\n\nimport {SanityProvider} from '../context/SanityProvider'\nimport {AuthBoundary} from './auth/AuthBoundary'\n\n/**\n * @public\n */\nexport interface SanityAppProps {\n sanityConfig: SanityConfig\n children: React.ReactNode\n}\n\n/**\n * @public\n *\n * The SanityApp component provides your Sanity application with access to your Sanity configuration,\n * as well as application context and state which is used by the Sanity React hooks. Your application\n * must be wrapped with the SanityApp component to function properly.\n *\n * @param props - Your Sanity configuration and the React children to render\n * @returns Your Sanity application, integrated with your Sanity configuration and application context\n *\n * @example\n * ```\n * import { SanityApp } from '@sanity/sdk-react\n *\n * import MyAppRoot from './Root'\n *\n * const mySanityConfig = {\n * procectId: 'my-project-id',\n * dataset: 'production',\n * }\n *\n * export default function MyApp() {\n * return (\n * <SanityApp sanityConfig={mySanityConfig}>\n * <MyAppRoot />\n * </SanityApp>\n * )\n * }\n * ```\n */\nexport function SanityApp({sanityConfig, children}: SanityAppProps): ReactElement {\n const sanityInstance = createSanityInstance(sanityConfig)\n\n return (\n <SanityProvider sanityInstance={sanityInstance}>\n <AuthBoundary>{children}</AuthBoundary>\n </SanityProvider>\n )\n}\n"],"names":[],"mappings":";;;;;;;;AAWO,MAAM,kBAAkB,MAAM;AAAA,EACnC,YAAY,OAAgB;AAExB,WAAO,S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ACX,YAAA,IAAI,UAAU,UAAU,KAAK;AAAA,IAErC,KAAK,cAAc;AACV,aAAA,oBAAC,mBAAmB,EAAA,GAAG,MAAO,CAAA;AAAA,IAEvC,KAAK,cAAc;AACV,aAAA;AAAA,IAET;AACS,aAAA,oBAAC,gBAAgB,EAAA,GAAG,MAAO,CAAA;AAAA,EAAA;AAGxC;AC/DO,SAAS,UAAU,EAAC,cAAc,YAAyC;AAC1E,QAAA,iBAAiB,qBAAqB,YAAY;AAExD,6BACG,gBAAe,EAAA,gBACd,UAAC,oBAAA,cAAA,EAAc,SAAS,CAAA,GAC1B;AAEJ;"}
package/dist/context.d.ts DELETED
@@ -1,45 +0,0 @@
1
- import {ReactElement} from 'react'
2
- import {SanityInstance} from '@sanity/sdk'
3
-
4
- /**
5
- * Top-level context provider that provides access to the Sanity configuration instance.
6
- * This must wrap any components making use of the Sanity SDK React hooks.
7
- * @remarks In most cases, SanityApp should be used rather than SanityProvider directly; SanityApp bundles both SanityProvider and an authentication layer.
8
- * @internal
9
- * @param props - Sanity project and dataset configuration
10
- * @returns Rendered component
11
- * @example
12
- * ```tsx
13
- * import {createSanityInstance} from '@sanity/sdk'
14
- * import {SanityProvider} from '@sanity/sdk-react'
15
- *
16
- * import MyAppRoot from './Root'
17
- *
18
- * const sanityInstance = createSanityInstance({
19
- * projectId: 'your-project-id',
20
- * dataset: 'production',
21
- * })
22
- *
23
- * export default function MyApp() {
24
- * return (
25
- * <SanityProvider sanityInstance={sanityInstance}>
26
- * <MyAppRoot />
27
- * </SanityProvider>
28
- * )
29
- * }
30
- * ```
31
- */
32
- export declare const SanityProvider: ({
33
- children,
34
- sanityInstance,
35
- }: SanityProviderProps) => ReactElement
36
-
37
- /**
38
- * @public
39
- */
40
- export declare interface SanityProviderProps {
41
- children: React.ReactNode
42
- sanityInstance: SanityInstance
43
- }
44
-
45
- export {}
package/dist/context.js DELETED
@@ -1,5 +0,0 @@
1
- import { SanityProvider } from "./_chunks-es/context.js";
2
- export {
3
- SanityProvider
4
- };
5
- //# sourceMappingURL=context.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}