@ory/elements-react 1.0.0-next.9 → 1.0.0-rc.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 (78) hide show
  1. package/CHANGELOG.md +515 -0
  2. package/DEVELOPMENT.md +94 -0
  3. package/LICENSE +201 -0
  4. package/README.md +359 -32
  5. package/babel.config.js +10 -0
  6. package/dist/client/config.d.mts +21 -0
  7. package/dist/client/config.d.ts +21 -0
  8. package/dist/client/config.js +77 -0
  9. package/dist/client/config.js.map +1 -0
  10. package/dist/client/config.mjs +51 -0
  11. package/dist/client/config.mjs.map +1 -0
  12. package/dist/client/frontendClient.d.mts +10 -0
  13. package/dist/client/frontendClient.d.ts +10 -0
  14. package/dist/client/frontendClient.js +75 -0
  15. package/dist/client/frontendClient.js.map +1 -0
  16. package/dist/client/frontendClient.mjs +54 -0
  17. package/dist/client/frontendClient.mjs.map +1 -0
  18. package/dist/client/index.d.mts +5 -0
  19. package/dist/client/index.d.ts +5 -0
  20. package/dist/client/index.js +33 -0
  21. package/dist/client/index.js.map +1 -0
  22. package/dist/client/index.mjs +10 -0
  23. package/dist/client/index.mjs.map +1 -0
  24. package/dist/client/session-provider.d.mts +62 -0
  25. package/dist/client/session-provider.d.ts +62 -0
  26. package/dist/client/session-provider.js +96 -0
  27. package/dist/client/session-provider.js.map +1 -0
  28. package/dist/client/session-provider.mjs +71 -0
  29. package/dist/client/session-provider.mjs.map +1 -0
  30. package/dist/client/useSession.d.mts +32 -0
  31. package/dist/client/useSession.d.ts +32 -0
  32. package/dist/client/useSession.js +37 -0
  33. package/dist/client/useSession.js.map +1 -0
  34. package/dist/client/useSession.mjs +13 -0
  35. package/dist/client/useSession.mjs.map +1 -0
  36. package/dist/index.d.mts +478 -1872
  37. package/dist/index.d.ts +478 -1872
  38. package/dist/index.js +3995 -2564
  39. package/dist/index.js.map +1 -1
  40. package/dist/index.mjs +3992 -2551
  41. package/dist/index.mjs.map +1 -1
  42. package/dist/theme/default/index.css +976 -304
  43. package/dist/theme/default/index.css.map +1 -1
  44. package/dist/theme/default/index.d.mts +54 -15
  45. package/dist/theme/default/index.d.ts +54 -15
  46. package/dist/theme/default/index.js +5483 -926
  47. package/dist/theme/default/index.js.map +1 -1
  48. package/dist/theme/default/index.mjs +5569 -909
  49. package/dist/theme/default/index.mjs.map +1 -1
  50. package/dist/theme/default/tailwind/defaults.d.mts +737 -0
  51. package/dist/theme/default/tailwind/defaults.d.ts +737 -0
  52. package/dist/theme/default/tailwind/defaults.js +219 -0
  53. package/dist/theme/default/tailwind/defaults.js.map +1 -0
  54. package/dist/theme/default/tailwind/defaults.mjs +196 -0
  55. package/dist/theme/default/tailwind/defaults.mjs.map +1 -0
  56. package/package.json +39 -14
  57. package/tailwind/defaults.ts +34 -0
  58. package/tailwind/generated/README.md +2 -0
  59. package/tailwind/generated/default-variables.css +216 -0
  60. package/tailwind/generated/variables-processed.json +161 -0
  61. package/tsconfig.json +10 -9
  62. package/tsconfig.runtime.json +4 -0
  63. package/.eslintrc.js +0 -61
  64. package/.vscode/i18n-ally-reviews.yml +0 -3
  65. package/.vscode/settings.json +0 -4
  66. package/api-report/elements-react-theme.api.json +0 -1260
  67. package/api-report/elements-react-theme.api.md +0 -128
  68. package/api-report/elements-react.api.json +0 -4262
  69. package/api-report/elements-react.api.md +0 -393
  70. package/api-report/temp/elements-react-theme.api.md +0 -130
  71. package/api-report/temp/elements-react.api.md +0 -328
  72. package/config/api-extractor-core.json +0 -457
  73. package/config/api-extractor-theme.json +0 -463
  74. package/jest.config.ts +0 -16
  75. package/postcss.config.ts +0 -6
  76. package/tailwind.config.ts +0 -54
  77. package/tsconfig.spec.json +0 -20
  78. package/variables-processed.json +0 -193
@@ -0,0 +1,71 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { createContext, useCallback, useEffect, useRef, useState } from "react";
4
+ import { frontendClient } from "./frontendClient";
5
+ const SessionContext = createContext({
6
+ session: null,
7
+ isLoading: false,
8
+ initialized: false,
9
+ error: void 0,
10
+ refetch: async () => {
11
+ }
12
+ });
13
+ function SessionProvider({
14
+ session: initialSession,
15
+ children,
16
+ baseUrl
17
+ }) {
18
+ const initialized = useRef(!!initialSession);
19
+ const [isLoading, setLoading] = useState(false);
20
+ const [sessionState, setSessionState] = useState(
21
+ () => {
22
+ if (initialSession) {
23
+ return {
24
+ session: initialSession,
25
+ state: initialSession.active ? "authenticated" : "unauthenticated"
26
+ };
27
+ }
28
+ return void 0;
29
+ }
30
+ );
31
+ const fetchSession = useCallback(async () => {
32
+ try {
33
+ setLoading(true);
34
+ const session = await frontendClient({
35
+ forceBaseUrl: baseUrl
36
+ }).toSession();
37
+ setSessionState({
38
+ session,
39
+ state: session.active ? "authenticated" : "unauthenticated"
40
+ });
41
+ } catch (error) {
42
+ setSessionState({ state: "error", error });
43
+ } finally {
44
+ setLoading(false);
45
+ }
46
+ }, [baseUrl]);
47
+ useEffect(() => {
48
+ if (!initialized.current) {
49
+ initialized.current = true;
50
+ void fetchSession();
51
+ }
52
+ }, [fetchSession]);
53
+ return /* @__PURE__ */ jsx(
54
+ SessionContext.Provider,
55
+ {
56
+ value: {
57
+ error: (sessionState == null ? void 0 : sessionState.state) === "error" ? sessionState.error : void 0,
58
+ session: (sessionState == null ? void 0 : sessionState.state) === "authenticated" ? sessionState.session : null,
59
+ isLoading,
60
+ initialized: initialized.current,
61
+ refetch: fetchSession
62
+ },
63
+ children
64
+ }
65
+ );
66
+ }
67
+ export {
68
+ SessionContext,
69
+ SessionProvider
70
+ };
71
+ //# sourceMappingURL=session-provider.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/client/session-provider.tsx"],"sourcesContent":["// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\n\n\"use client\"\nimport { Session } from \"@ory/client-fetch\"\nimport { createContext, useCallback, useEffect, useRef, useState } from \"react\"\nimport { frontendClient } from \"./frontendClient\"\n\ntype SessionState =\n | {\n session: Session\n state: \"authenticated\"\n }\n | {\n state: \"unauthenticated\"\n }\n | {\n state: \"error\"\n error: Error\n }\n\nexport type SessionContextData = {\n /**\n * Whether the session is currently being loaded\n */\n isLoading: boolean\n /**\n * Whether the session is being loaded for the first time\n * Never true, if a session was passed to the provider\n */\n initialized: boolean\n /**\n * The current session or null if the user is not authenticated or an error occurred,\n * when fetching the session\n */\n session: Session | null\n /**\n * The error that occurred when fetching the session if any\n */\n error: Error | undefined\n /**\n * Refetches the session\n */\n refetch: () => Promise<void>\n}\n\nexport const SessionContext = createContext<SessionContextData>({\n session: null,\n isLoading: false,\n initialized: false,\n error: undefined,\n refetch: async () => {},\n})\n\nexport type SessionProviderProps = {\n session?: Session | null\n baseUrl?: string\n} & React.PropsWithChildren\n\n/**\n * A provider that fetches the session from the Ory Network and provides it to the children.\n *\n * To use this provider, wrap your application in it:\n *\n * ```tsx\n * import { SessionProvider } from \"@ory/elements-react\"\n *\n * export default function App() {\n * return (\n * <SessionProvider>\n * <MyApp />\n * </SessionProvider>\n * )\n * }\n * ```\n *\n * If you have a session from the server, you can pass it to the provider:\n *\n * ```tsx\n * <SessionProvider session={serverSession}>\n * ```\n *\n * @see {@link useSession}\n * @param props - The provider props\n */\nexport function SessionProvider({\n session: initialSession,\n children,\n baseUrl,\n}: SessionProviderProps) {\n const initialized = useRef(!!initialSession)\n const [isLoading, setLoading] = useState(false)\n const [sessionState, setSessionState] = useState<SessionState | undefined>(\n () => {\n if (initialSession) {\n return {\n session: initialSession,\n state: initialSession.active ? \"authenticated\" : \"unauthenticated\",\n }\n }\n\n return undefined\n },\n )\n\n const fetchSession = useCallback(async () => {\n try {\n setLoading(true)\n const session = await frontendClient({\n forceBaseUrl: baseUrl,\n }).toSession()\n\n setSessionState({\n session,\n state: session.active ? \"authenticated\" : \"unauthenticated\",\n })\n } catch (error) {\n setSessionState({ state: \"error\", error: error as Error })\n } finally {\n setLoading(false)\n }\n }, [baseUrl])\n\n useEffect(() => {\n if (!initialized.current) {\n initialized.current = true\n void fetchSession()\n }\n }, [fetchSession])\n\n return (\n <SessionContext.Provider\n value={{\n error: sessionState?.state === \"error\" ? sessionState.error : undefined,\n session:\n sessionState?.state === \"authenticated\" ? sessionState.session : null,\n isLoading,\n initialized: initialized.current,\n refetch: fetchSession,\n }}\n >\n {children}\n </SessionContext.Provider>\n )\n}\n"],"mappings":";AAmII;AA9HJ,SAAS,eAAe,aAAa,WAAW,QAAQ,gBAAgB;AACxE,SAAS,sBAAsB;AAwCxB,MAAM,iBAAiB,cAAkC;AAAA,EAC9D,SAAS;AAAA,EACT,WAAW;AAAA,EACX,aAAa;AAAA,EACb,OAAO;AAAA,EACP,SAAS,YAAY;AAAA,EAAC;AACxB,CAAC;AAiCM,SAAS,gBAAgB;AAAA,EAC9B,SAAS;AAAA,EACT;AAAA,EACA;AACF,GAAyB;AACvB,QAAM,cAAc,OAAO,CAAC,CAAC,cAAc;AAC3C,QAAM,CAAC,WAAW,UAAU,IAAI,SAAS,KAAK;AAC9C,QAAM,CAAC,cAAc,eAAe,IAAI;AAAA,IACtC,MAAM;AACJ,UAAI,gBAAgB;AAClB,eAAO;AAAA,UACL,SAAS;AAAA,UACT,OAAO,eAAe,SAAS,kBAAkB;AAAA,QACnD;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAEA,QAAM,eAAe,YAAY,YAAY;AAC3C,QAAI;AACF,iBAAW,IAAI;AACf,YAAM,UAAU,MAAM,eAAe;AAAA,QACnC,cAAc;AAAA,MAChB,CAAC,EAAE,UAAU;AAEb,sBAAgB;AAAA,QACd;AAAA,QACA,OAAO,QAAQ,SAAS,kBAAkB;AAAA,MAC5C,CAAC;AAAA,IACH,SAAS,OAAO;AACd,sBAAgB,EAAE,OAAO,SAAS,MAAsB,CAAC;AAAA,IAC3D,UAAE;AACA,iBAAW,KAAK;AAAA,IAClB;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AAEZ,YAAU,MAAM;AACd,QAAI,CAAC,YAAY,SAAS;AACxB,kBAAY,UAAU;AACtB,WAAK,aAAa;AAAA,IACpB;AAAA,EACF,GAAG,CAAC,YAAY,CAAC;AAEjB,SACE;AAAA,IAAC,eAAe;AAAA,IAAf;AAAA,MACC,OAAO;AAAA,QACL,QAAO,6CAAc,WAAU,UAAU,aAAa,QAAQ;AAAA,QAC9D,UACE,6CAAc,WAAU,kBAAkB,aAAa,UAAU;AAAA,QACnE;AAAA,QACA,aAAa,YAAY;AAAA,QACzB,SAAS;AAAA,MACX;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;","names":[]}
@@ -0,0 +1,32 @@
1
+ import { SessionContextData } from './session-provider.mjs';
2
+ import 'react/jsx-runtime';
3
+ import 'react';
4
+ import '@ory/client-fetch';
5
+
6
+ /**
7
+ * A hook to get the current session from the Ory Network.
8
+ *
9
+ * Usage:
10
+ * ```ts
11
+ * const session = useSession()
12
+ *
13
+ * if (session.state == "loading") {
14
+ * return <div>Loading...</div>
15
+ * }
16
+ *
17
+ * if (session.state == "authenticated") {
18
+ * return <div>Session: {session.session.id}</div>
19
+ * }
20
+ * ```
21
+ *
22
+ * :::note
23
+ * This is a client-side hook and must be used within a React component.
24
+ * On the server, you can use the getServerSession function from `@ory/nextjs`
25
+ * and hydrate SessionProvider with the session.
26
+ * :::
27
+ *
28
+ * @returns The current session, and error or loading state.
29
+ */
30
+ declare function useSession(): SessionContextData;
31
+
32
+ export { useSession };
@@ -0,0 +1,32 @@
1
+ import { SessionContextData } from './session-provider.js';
2
+ import 'react/jsx-runtime';
3
+ import 'react';
4
+ import '@ory/client-fetch';
5
+
6
+ /**
7
+ * A hook to get the current session from the Ory Network.
8
+ *
9
+ * Usage:
10
+ * ```ts
11
+ * const session = useSession()
12
+ *
13
+ * if (session.state == "loading") {
14
+ * return <div>Loading...</div>
15
+ * }
16
+ *
17
+ * if (session.state == "authenticated") {
18
+ * return <div>Session: {session.session.id}</div>
19
+ * }
20
+ * ```
21
+ *
22
+ * :::note
23
+ * This is a client-side hook and must be used within a React component.
24
+ * On the server, you can use the getServerSession function from `@ory/nextjs`
25
+ * and hydrate SessionProvider with the session.
26
+ * :::
27
+ *
28
+ * @returns The current session, and error or loading state.
29
+ */
30
+ declare function useSession(): SessionContextData;
31
+
32
+ export { useSession };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var useSession_exports = {};
21
+ __export(useSession_exports, {
22
+ useSession: () => useSession
23
+ });
24
+ module.exports = __toCommonJS(useSession_exports);
25
+ var import_react = require("react");
26
+ var import_session_provider = require("./session-provider");
27
+ function useSession() {
28
+ if (!import_session_provider.SessionContext) {
29
+ throw new Error("[Ory/Elements] useSession must be used on the client");
30
+ }
31
+ return (0, import_react.useContext)(import_session_provider.SessionContext);
32
+ }
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ useSession
36
+ });
37
+ //# sourceMappingURL=useSession.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/client/useSession.ts"],"sourcesContent":["// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\n\"use client\"\n\nimport { useContext } from \"react\"\nimport { SessionContext } from \"./session-provider\"\n\n/**\n * A hook to get the current session from the Ory Network.\n *\n * Usage:\n * ```ts\n * const session = useSession()\n *\n * if (session.state == \"loading\") {\n * return <div>Loading...</div>\n * }\n *\n * if (session.state == \"authenticated\") {\n * return <div>Session: {session.session.id}</div>\n * }\n * ```\n *\n * :::note\n * This is a client-side hook and must be used within a React component.\n * On the server, you can use the getServerSession function from `@ory/nextjs`\n * and hydrate SessionProvider with the session.\n * :::\n *\n * @returns The current session, and error or loading state.\n */\n\nexport function useSession() {\n if (!SessionContext) {\n throw new Error(\"[Ory/Elements] useSession must be used on the client\")\n }\n return useContext(SessionContext)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,mBAA2B;AAC3B,8BAA+B;AA2BxB,SAAS,aAAa;AAC3B,MAAI,CAAC,wCAAgB;AACnB,UAAM,IAAI,MAAM,sDAAsD;AAAA,EACxE;AACA,aAAO,yBAAW,sCAAc;AAClC;","names":[]}
@@ -0,0 +1,13 @@
1
+ "use client";
2
+ import { useContext } from "react";
3
+ import { SessionContext } from "./session-provider";
4
+ function useSession() {
5
+ if (!SessionContext) {
6
+ throw new Error("[Ory/Elements] useSession must be used on the client");
7
+ }
8
+ return useContext(SessionContext);
9
+ }
10
+ export {
11
+ useSession
12
+ };
13
+ //# sourceMappingURL=useSession.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/client/useSession.ts"],"sourcesContent":["// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\n\"use client\"\n\nimport { useContext } from \"react\"\nimport { SessionContext } from \"./session-provider\"\n\n/**\n * A hook to get the current session from the Ory Network.\n *\n * Usage:\n * ```ts\n * const session = useSession()\n *\n * if (session.state == \"loading\") {\n * return <div>Loading...</div>\n * }\n *\n * if (session.state == \"authenticated\") {\n * return <div>Session: {session.session.id}</div>\n * }\n * ```\n *\n * :::note\n * This is a client-side hook and must be used within a React component.\n * On the server, you can use the getServerSession function from `@ory/nextjs`\n * and hydrate SessionProvider with the session.\n * :::\n *\n * @returns The current session, and error or loading state.\n */\n\nexport function useSession() {\n if (!SessionContext) {\n throw new Error(\"[Ory/Elements] useSession must be used on the client\")\n }\n return useContext(SessionContext)\n}\n"],"mappings":";AAIA,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AA2BxB,SAAS,aAAa;AAC3B,MAAI,CAAC,gBAAgB;AACnB,UAAM,IAAI,MAAM,sDAAsD;AAAA,EACxE;AACA,SAAO,WAAW,cAAc;AAClC;","names":[]}