@wordrhyme/shadcn-auth 1.0.61 → 2.0.2

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 (158) hide show
  1. package/README.md +154 -1
  2. package/dist/components/AuthCard.cjs +45 -0
  3. package/dist/components/AuthCard.d.cts +30 -0
  4. package/dist/components/AuthCard.d.ts +30 -0
  5. package/dist/components/AuthCard.js +42 -0
  6. package/dist/components/AuthForms.cjs +115 -0
  7. package/dist/components/AuthForms.d.cts +95 -0
  8. package/dist/components/AuthForms.d.ts +95 -0
  9. package/dist/components/AuthForms.js +112 -0
  10. package/dist/components/CompleteProfileForm.cjs +38 -0
  11. package/dist/components/CompleteProfileForm.d.cts +32 -0
  12. package/dist/components/CompleteProfileForm.d.ts +32 -0
  13. package/dist/components/CompleteProfileForm.js +36 -0
  14. package/dist/components/EmailOtpForm.cjs +181 -0
  15. package/dist/components/EmailOtpForm.d.cts +56 -0
  16. package/dist/components/EmailOtpForm.d.ts +56 -0
  17. package/dist/components/EmailOtpForm.js +176 -0
  18. package/dist/components/LegalNotice.cjs +37 -0
  19. package/dist/components/LegalNotice.d.cts +26 -0
  20. package/dist/components/LegalNotice.d.ts +26 -0
  21. package/dist/components/LegalNotice.js +35 -0
  22. package/dist/components/MagicLinkForm.cjs +119 -0
  23. package/dist/components/MagicLinkForm.d.cts +46 -0
  24. package/dist/components/MagicLinkForm.d.ts +46 -0
  25. package/dist/components/MagicLinkForm.js +115 -0
  26. package/dist/components/ProviderSignInButtons.cjs +65 -0
  27. package/dist/components/ProviderSignInButtons.d.cts +41 -0
  28. package/dist/components/ProviderSignInButtons.d.ts +41 -0
  29. package/dist/components/ProviderSignInButtons.js +62 -0
  30. package/dist/components/ResetPasswordForm.cjs +89 -0
  31. package/dist/components/ResetPasswordForm.d.cts +20 -0
  32. package/dist/components/ResetPasswordForm.d.ts +20 -0
  33. package/dist/components/ResetPasswordForm.js +85 -0
  34. package/dist/components/SignInForm.cjs +97 -0
  35. package/dist/components/SignInForm.d.cts +41 -0
  36. package/dist/components/SignInForm.d.ts +41 -0
  37. package/dist/components/SignInForm.js +93 -0
  38. package/dist/components/SignUpForm.cjs +123 -0
  39. package/dist/components/SignUpForm.d.cts +40 -0
  40. package/dist/components/SignUpForm.d.ts +40 -0
  41. package/dist/components/SignUpForm.js +119 -0
  42. package/dist/components/auth-pending/AuthButton.cjs +37 -0
  43. package/dist/components/auth-pending/AuthButton.d.cts +36 -0
  44. package/dist/components/auth-pending/AuthButton.d.ts +36 -0
  45. package/dist/components/auth-pending/AuthButton.js +34 -0
  46. package/dist/components/auth-pending/AuthPendingProvider.cjs +19 -0
  47. package/dist/components/auth-pending/AuthPendingProvider.d.cts +17 -0
  48. package/dist/components/auth-pending/AuthPendingProvider.d.ts +17 -0
  49. package/dist/components/auth-pending/AuthPendingProvider.js +17 -0
  50. package/dist/components/auth-pending/auth-pending-context.cjs +57 -0
  51. package/dist/components/auth-pending/auth-pending-context.d.cts +39 -0
  52. package/dist/components/auth-pending/auth-pending-context.d.ts +39 -0
  53. package/dist/components/auth-pending/auth-pending-context.js +52 -0
  54. package/dist/components/auth-pending/index.d.cts +3 -0
  55. package/dist/components/auth-pending/index.d.ts +3 -0
  56. package/dist/components/forms/AuthField.cjs +43 -0
  57. package/dist/components/forms/AuthField.d.cts +26 -0
  58. package/dist/components/forms/AuthField.d.ts +26 -0
  59. package/dist/components/forms/AuthField.js +40 -0
  60. package/dist/components/forms/CompleteProfileFields.cjs +63 -0
  61. package/dist/components/forms/CompleteProfileFields.d.cts +18 -0
  62. package/dist/components/forms/CompleteProfileFields.d.ts +18 -0
  63. package/dist/components/forms/CompleteProfileFields.js +60 -0
  64. package/dist/components/forms/EmailOtpCodeForm.cjs +78 -0
  65. package/dist/components/forms/EmailOtpCodeForm.d.cts +18 -0
  66. package/dist/components/forms/EmailOtpCodeForm.d.ts +18 -0
  67. package/dist/components/forms/EmailOtpCodeForm.js +75 -0
  68. package/dist/components/forms/EmailRequestForm.cjs +82 -0
  69. package/dist/components/forms/EmailRequestForm.d.cts +38 -0
  70. package/dist/components/forms/EmailRequestForm.d.ts +38 -0
  71. package/dist/components/forms/EmailRequestForm.js +79 -0
  72. package/dist/components/forms/SignInCredentialsForm.cjs +79 -0
  73. package/dist/components/forms/SignInCredentialsForm.d.cts +18 -0
  74. package/dist/components/forms/SignInCredentialsForm.d.ts +18 -0
  75. package/dist/components/forms/SignInCredentialsForm.js +76 -0
  76. package/dist/components/forms/SignUpCredentialsForm.cjs +130 -0
  77. package/dist/components/forms/SignUpCredentialsForm.d.cts +24 -0
  78. package/dist/components/forms/SignUpCredentialsForm.d.ts +24 -0
  79. package/dist/components/forms/SignUpCredentialsForm.js +126 -0
  80. package/dist/components/index.d.cts +25 -0
  81. package/dist/components/index.d.ts +25 -0
  82. package/dist/components/provider-icon/ProviderIcon.cjs +82 -0
  83. package/dist/components/provider-icon/ProviderIcon.d.cts +21 -0
  84. package/dist/components/provider-icon/ProviderIcon.d.ts +21 -0
  85. package/dist/components/provider-icon/ProviderIcon.js +79 -0
  86. package/dist/components/sign-in-methods/SignInMethodRow.cjs +55 -0
  87. package/dist/components/sign-in-methods/SignInMethodRow.d.cts +31 -0
  88. package/dist/components/sign-in-methods/SignInMethodRow.d.ts +31 -0
  89. package/dist/components/sign-in-methods/SignInMethodRow.js +50 -0
  90. package/dist/components/sign-in-methods/SignInMethods.cjs +45 -0
  91. package/dist/components/sign-in-methods/SignInMethods.d.cts +26 -0
  92. package/dist/components/sign-in-methods/SignInMethods.d.ts +26 -0
  93. package/dist/components/sign-in-methods/SignInMethods.js +43 -0
  94. package/dist/components/sign-in-methods/SignInMethodsList.cjs +69 -0
  95. package/dist/components/sign-in-methods/SignInMethodsList.d.cts +47 -0
  96. package/dist/components/sign-in-methods/SignInMethodsList.d.ts +47 -0
  97. package/dist/components/sign-in-methods/SignInMethodsList.js +65 -0
  98. package/dist/components/sign-in-methods/sign-in-methods-copy.cjs +13 -0
  99. package/dist/components/sign-in-methods/sign-in-methods-copy.d.cts +11 -0
  100. package/dist/components/sign-in-methods/sign-in-methods-copy.d.ts +11 -0
  101. package/dist/components/sign-in-methods/sign-in-methods-copy.js +12 -0
  102. package/dist/constants/auth-providers.cjs +33 -0
  103. package/dist/constants/auth-providers.d.cts +14 -0
  104. package/dist/constants/auth-providers.d.ts +14 -0
  105. package/dist/constants/auth-providers.js +31 -0
  106. package/dist/constants/validation.cjs +21 -0
  107. package/dist/constants/validation.d.cts +17 -0
  108. package/dist/constants/validation.d.ts +17 -0
  109. package/dist/constants/validation.js +18 -0
  110. package/dist/hooks/use-pending-action.cjs +37 -0
  111. package/dist/hooks/use-pending-action.d.cts +26 -0
  112. package/dist/hooks/use-pending-action.d.ts +26 -0
  113. package/dist/hooks/use-pending-action.js +35 -0
  114. package/dist/hooks/use-reset-on-page-restore.cjs +35 -0
  115. package/dist/hooks/use-reset-on-page-restore.d.cts +15 -0
  116. package/dist/hooks/use-reset-on-page-restore.d.ts +15 -0
  117. package/dist/hooks/use-reset-on-page-restore.js +33 -0
  118. package/dist/index.cjs +67 -7
  119. package/dist/index.d.cts +34 -6
  120. package/dist/index.d.ts +34 -6
  121. package/dist/index.js +33 -6
  122. package/dist/utils/build-sign-in-method-rows.cjs +25 -0
  123. package/dist/utils/build-sign-in-method-rows.d.cts +26 -0
  124. package/dist/utils/build-sign-in-method-rows.d.ts +26 -0
  125. package/dist/utils/build-sign-in-method-rows.js +24 -0
  126. package/dist/utils/until-navigation.cjs +22 -0
  127. package/dist/utils/until-navigation.d.cts +18 -0
  128. package/dist/utils/until-navigation.d.ts +18 -0
  129. package/dist/utils/until-navigation.js +21 -0
  130. package/dist/utils/validate-email.cjs +22 -0
  131. package/dist/utils/validate-email.d.cts +14 -0
  132. package/dist/utils/validate-email.d.ts +14 -0
  133. package/dist/utils/validate-email.js +21 -0
  134. package/dist/utils/validate-password.cjs +16 -0
  135. package/dist/utils/validate-password.d.cts +9 -0
  136. package/dist/utils/validate-password.d.ts +9 -0
  137. package/dist/utils/validate-password.js +16 -0
  138. package/package.json +15 -8
  139. package/dist/AuthForms.cjs +0 -47
  140. package/dist/AuthForms.d.cts +0 -23
  141. package/dist/AuthForms.d.ts +0 -23
  142. package/dist/AuthForms.js +0 -44
  143. package/dist/GoogleSignIn.cjs +0 -46
  144. package/dist/GoogleSignIn.d.cts +0 -10
  145. package/dist/GoogleSignIn.d.ts +0 -10
  146. package/dist/GoogleSignIn.js +0 -42
  147. package/dist/ResetPasswordForm.cjs +0 -106
  148. package/dist/ResetPasswordForm.d.cts +0 -17
  149. package/dist/ResetPasswordForm.d.ts +0 -17
  150. package/dist/ResetPasswordForm.js +0 -100
  151. package/dist/SignInForm.cjs +0 -164
  152. package/dist/SignInForm.d.cts +0 -21
  153. package/dist/SignInForm.d.ts +0 -21
  154. package/dist/SignInForm.js +0 -159
  155. package/dist/SignUpForm.cjs +0 -154
  156. package/dist/SignUpForm.d.cts +0 -19
  157. package/dist/SignUpForm.d.ts +0 -19
  158. package/dist/SignUpForm.js +0 -149
@@ -0,0 +1,57 @@
1
+ 'use client';
2
+
3
+
4
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
5
+ const require_use_pending_action = require('../../hooks/use-pending-action.cjs');
6
+ const require_use_reset_on_page_restore = require('../../hooks/use-reset-on-page-restore.cjs');
7
+ let react = require("react");
8
+ react = require_rolldown_runtime.__toESM(react);
9
+
10
+ //#region src/components/auth-pending/auth-pending-context.ts
11
+ /** Key for the button that submits the card's main form. */
12
+ const AUTH_SUBMIT_ACTION = "submit";
13
+ const AuthPendingContext = (0, react.createContext)(null);
14
+ /**
15
+ * Creates the pending scope for one auth card.
16
+ *
17
+ * Every button on a card shares one scope, which is what lets the pressed
18
+ * button spin while its neighbours only go disabled: a single `isLoading` flag
19
+ * can say that something is happening but not what, so driving spinners from it
20
+ * lights up every button at once.
21
+ *
22
+ * `isLoading` is the host's own flag. It disables the card but spins nothing,
23
+ * since the host cannot know which button the user pressed.
24
+ */
25
+ function useAuthPendingState(isLoading = false) {
26
+ const pending = require_use_pending_action.usePendingAction();
27
+ require_use_reset_on_page_restore.useResetOnPageRestore(pending.reset);
28
+ const { pendingKey, isPending, run } = pending;
29
+ return (0, react.useMemo)(() => ({
30
+ pendingKey,
31
+ isBusy: isLoading || isPending,
32
+ run
33
+ }), [
34
+ pendingKey,
35
+ isLoading,
36
+ isPending,
37
+ run
38
+ ]);
39
+ }
40
+ /**
41
+ * The pending scope this component sits in.
42
+ *
43
+ * Falls back to a scope of its own when there is no provider above, so a
44
+ * component exported from this package still behaves when a host drops it onto
45
+ * a page of their own rather than inside one of the auth cards.
46
+ */
47
+ function useAuthPending(isLoading = false) {
48
+ const inherited = (0, react.use)(AuthPendingContext);
49
+ const standalone = useAuthPendingState(isLoading);
50
+ return inherited ?? standalone;
51
+ }
52
+
53
+ //#endregion
54
+ exports.AUTH_SUBMIT_ACTION = AUTH_SUBMIT_ACTION;
55
+ exports.AuthPendingContext = AuthPendingContext;
56
+ exports.useAuthPending = useAuthPending;
57
+ exports.useAuthPendingState = useAuthPendingState;
@@ -0,0 +1,39 @@
1
+ import * as react0 from "react";
2
+
3
+ //#region src/components/auth-pending/auth-pending-context.d.ts
4
+ /** Key for the button that submits the card's main form. */
5
+ declare const AUTH_SUBMIT_ACTION = "submit";
6
+ interface AuthPendingValue {
7
+ /** Key of the button whose action is running, or `null` when none is. */
8
+ pendingKey: string | null;
9
+ /**
10
+ * Whether anything on the card is in flight — an action started here, or work
11
+ * the host reported through `isLoading`. The cue for disabling every control.
12
+ */
13
+ isBusy: boolean;
14
+ /** Starts `action`, marking `key` as the button that should spin meanwhile. */
15
+ run: (key: string, action: () => Promise<void>) => void;
16
+ }
17
+ declare const AuthPendingContext: react0.Context<AuthPendingValue | null>;
18
+ /**
19
+ * Creates the pending scope for one auth card.
20
+ *
21
+ * Every button on a card shares one scope, which is what lets the pressed
22
+ * button spin while its neighbours only go disabled: a single `isLoading` flag
23
+ * can say that something is happening but not what, so driving spinners from it
24
+ * lights up every button at once.
25
+ *
26
+ * `isLoading` is the host's own flag. It disables the card but spins nothing,
27
+ * since the host cannot know which button the user pressed.
28
+ */
29
+ declare function useAuthPendingState(isLoading?: boolean): AuthPendingValue;
30
+ /**
31
+ * The pending scope this component sits in.
32
+ *
33
+ * Falls back to a scope of its own when there is no provider above, so a
34
+ * component exported from this package still behaves when a host drops it onto
35
+ * a page of their own rather than inside one of the auth cards.
36
+ */
37
+ declare function useAuthPending(isLoading?: boolean): AuthPendingValue;
38
+ //#endregion
39
+ export { AUTH_SUBMIT_ACTION, AuthPendingContext, AuthPendingValue, useAuthPending, useAuthPendingState };
@@ -0,0 +1,39 @@
1
+ import * as react0 from "react";
2
+
3
+ //#region src/components/auth-pending/auth-pending-context.d.ts
4
+ /** Key for the button that submits the card's main form. */
5
+ declare const AUTH_SUBMIT_ACTION = "submit";
6
+ interface AuthPendingValue {
7
+ /** Key of the button whose action is running, or `null` when none is. */
8
+ pendingKey: string | null;
9
+ /**
10
+ * Whether anything on the card is in flight — an action started here, or work
11
+ * the host reported through `isLoading`. The cue for disabling every control.
12
+ */
13
+ isBusy: boolean;
14
+ /** Starts `action`, marking `key` as the button that should spin meanwhile. */
15
+ run: (key: string, action: () => Promise<void>) => void;
16
+ }
17
+ declare const AuthPendingContext: react0.Context<AuthPendingValue | null>;
18
+ /**
19
+ * Creates the pending scope for one auth card.
20
+ *
21
+ * Every button on a card shares one scope, which is what lets the pressed
22
+ * button spin while its neighbours only go disabled: a single `isLoading` flag
23
+ * can say that something is happening but not what, so driving spinners from it
24
+ * lights up every button at once.
25
+ *
26
+ * `isLoading` is the host's own flag. It disables the card but spins nothing,
27
+ * since the host cannot know which button the user pressed.
28
+ */
29
+ declare function useAuthPendingState(isLoading?: boolean): AuthPendingValue;
30
+ /**
31
+ * The pending scope this component sits in.
32
+ *
33
+ * Falls back to a scope of its own when there is no provider above, so a
34
+ * component exported from this package still behaves when a host drops it onto
35
+ * a page of their own rather than inside one of the auth cards.
36
+ */
37
+ declare function useAuthPending(isLoading?: boolean): AuthPendingValue;
38
+ //#endregion
39
+ export { AUTH_SUBMIT_ACTION, AuthPendingContext, AuthPendingValue, useAuthPending, useAuthPendingState };
@@ -0,0 +1,52 @@
1
+ 'use client';
2
+
3
+
4
+ import { usePendingAction } from "../../hooks/use-pending-action.js";
5
+ import { useResetOnPageRestore } from "../../hooks/use-reset-on-page-restore.js";
6
+ import { createContext, use, useMemo } from "react";
7
+
8
+ //#region src/components/auth-pending/auth-pending-context.ts
9
+ /** Key for the button that submits the card's main form. */
10
+ const AUTH_SUBMIT_ACTION = "submit";
11
+ const AuthPendingContext = createContext(null);
12
+ /**
13
+ * Creates the pending scope for one auth card.
14
+ *
15
+ * Every button on a card shares one scope, which is what lets the pressed
16
+ * button spin while its neighbours only go disabled: a single `isLoading` flag
17
+ * can say that something is happening but not what, so driving spinners from it
18
+ * lights up every button at once.
19
+ *
20
+ * `isLoading` is the host's own flag. It disables the card but spins nothing,
21
+ * since the host cannot know which button the user pressed.
22
+ */
23
+ function useAuthPendingState(isLoading = false) {
24
+ const pending = usePendingAction();
25
+ useResetOnPageRestore(pending.reset);
26
+ const { pendingKey, isPending, run } = pending;
27
+ return useMemo(() => ({
28
+ pendingKey,
29
+ isBusy: isLoading || isPending,
30
+ run
31
+ }), [
32
+ pendingKey,
33
+ isLoading,
34
+ isPending,
35
+ run
36
+ ]);
37
+ }
38
+ /**
39
+ * The pending scope this component sits in.
40
+ *
41
+ * Falls back to a scope of its own when there is no provider above, so a
42
+ * component exported from this package still behaves when a host drops it onto
43
+ * a page of their own rather than inside one of the auth cards.
44
+ */
45
+ function useAuthPending(isLoading = false) {
46
+ const inherited = use(AuthPendingContext);
47
+ const standalone = useAuthPendingState(isLoading);
48
+ return inherited ?? standalone;
49
+ }
50
+
51
+ //#endregion
52
+ export { AUTH_SUBMIT_ACTION, AuthPendingContext, useAuthPending, useAuthPendingState };
@@ -0,0 +1,3 @@
1
+ import { AUTH_SUBMIT_ACTION, AuthPendingContext, AuthPendingValue, useAuthPending, useAuthPendingState } from "./auth-pending-context.cjs";
2
+ import { AuthButton, AuthButtonProps } from "./AuthButton.cjs";
3
+ import { AuthPendingProvider, AuthPendingProviderProps } from "./AuthPendingProvider.cjs";
@@ -0,0 +1,3 @@
1
+ import { AUTH_SUBMIT_ACTION, AuthPendingContext, AuthPendingValue, useAuthPending, useAuthPendingState } from "./auth-pending-context.js";
2
+ import { AuthButton, AuthButtonProps } from "./AuthButton.js";
3
+ import { AuthPendingProvider, AuthPendingProviderProps } from "./AuthPendingProvider.js";
@@ -0,0 +1,43 @@
1
+ 'use client';
2
+
3
+
4
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
5
+ const require_auth_pending_context = require('../auth-pending/auth-pending-context.cjs');
6
+ let react_jsx_runtime = require("react/jsx-runtime");
7
+ react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
8
+ let __wordrhyme_shadcn = require("@wordrhyme/shadcn");
9
+ __wordrhyme_shadcn = require_rolldown_runtime.__toESM(__wordrhyme_shadcn);
10
+
11
+ //#region src/components/forms/AuthField.tsx
12
+ /**
13
+ * A labelled field on an auth card, with its validation message.
14
+ *
15
+ * Takes its disabled state from the card's pending scope, so no form has to
16
+ * remember to lock its inputs while something on the card is in flight.
17
+ */
18
+ function AuthField({ id, label, error = "", className = "",...inputProps }) {
19
+ const pending = require_auth_pending_context.useAuthPending();
20
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
21
+ className: "space-y-2",
22
+ children: [
23
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Label, {
24
+ htmlFor: id,
25
+ children: label
26
+ }),
27
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Input, {
28
+ id,
29
+ disabled: pending.isBusy,
30
+ className: `${className} ${error ? "border-destructive" : ""}`.trim(),
31
+ ...inputProps
32
+ }),
33
+ error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
34
+ className: "text-destructive text-sm",
35
+ role: "alert",
36
+ children: error
37
+ })
38
+ ]
39
+ });
40
+ }
41
+
42
+ //#endregion
43
+ exports.AuthField = AuthField;
@@ -0,0 +1,26 @@
1
+ import React from "react";
2
+ import * as react_jsx_runtime4 from "react/jsx-runtime";
3
+ import { Input } from "@wordrhyme/shadcn";
4
+
5
+ //#region src/components/forms/AuthField.d.ts
6
+ interface AuthFieldProps extends Omit<React.ComponentProps<typeof Input>, 'disabled'> {
7
+ id: string;
8
+ label: string;
9
+ /** Validation message for this field, or `''` while it is valid. */
10
+ error?: string;
11
+ }
12
+ /**
13
+ * A labelled field on an auth card, with its validation message.
14
+ *
15
+ * Takes its disabled state from the card's pending scope, so no form has to
16
+ * remember to lock its inputs while something on the card is in flight.
17
+ */
18
+ declare function AuthField({
19
+ id,
20
+ label,
21
+ error,
22
+ className,
23
+ ...inputProps
24
+ }: AuthFieldProps): react_jsx_runtime4.JSX.Element;
25
+ //#endregion
26
+ export { AuthField, AuthFieldProps };
@@ -0,0 +1,26 @@
1
+ import React from "react";
2
+ import * as react_jsx_runtime4 from "react/jsx-runtime";
3
+ import { Input } from "@wordrhyme/shadcn";
4
+
5
+ //#region src/components/forms/AuthField.d.ts
6
+ interface AuthFieldProps extends Omit<React.ComponentProps<typeof Input>, 'disabled'> {
7
+ id: string;
8
+ label: string;
9
+ /** Validation message for this field, or `''` while it is valid. */
10
+ error?: string;
11
+ }
12
+ /**
13
+ * A labelled field on an auth card, with its validation message.
14
+ *
15
+ * Takes its disabled state from the card's pending scope, so no form has to
16
+ * remember to lock its inputs while something on the card is in flight.
17
+ */
18
+ declare function AuthField({
19
+ id,
20
+ label,
21
+ error,
22
+ className,
23
+ ...inputProps
24
+ }: AuthFieldProps): react_jsx_runtime4.JSX.Element;
25
+ //#endregion
26
+ export { AuthField, AuthFieldProps };
@@ -0,0 +1,40 @@
1
+ 'use client';
2
+
3
+
4
+ import { useAuthPending } from "../auth-pending/auth-pending-context.js";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ import { Input, Label } from "@wordrhyme/shadcn";
7
+
8
+ //#region src/components/forms/AuthField.tsx
9
+ /**
10
+ * A labelled field on an auth card, with its validation message.
11
+ *
12
+ * Takes its disabled state from the card's pending scope, so no form has to
13
+ * remember to lock its inputs while something on the card is in flight.
14
+ */
15
+ function AuthField({ id, label, error = "", className = "",...inputProps }) {
16
+ const pending = useAuthPending();
17
+ return /* @__PURE__ */ jsxs("div", {
18
+ className: "space-y-2",
19
+ children: [
20
+ /* @__PURE__ */ jsx(Label, {
21
+ htmlFor: id,
22
+ children: label
23
+ }),
24
+ /* @__PURE__ */ jsx(Input, {
25
+ id,
26
+ disabled: pending.isBusy,
27
+ className: `${className} ${error ? "border-destructive" : ""}`.trim(),
28
+ ...inputProps
29
+ }),
30
+ error && /* @__PURE__ */ jsx("p", {
31
+ className: "text-destructive text-sm",
32
+ role: "alert",
33
+ children: error
34
+ })
35
+ ]
36
+ });
37
+ }
38
+
39
+ //#endregion
40
+ export { AuthField };
@@ -0,0 +1,63 @@
1
+ 'use client';
2
+
3
+
4
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
5
+ const require_auth_pending_context = require('../auth-pending/auth-pending-context.cjs');
6
+ const require_AuthButton = require('../auth-pending/AuthButton.cjs');
7
+ const require_AuthField = require('./AuthField.cjs');
8
+ let react = require("react");
9
+ react = require_rolldown_runtime.__toESM(react);
10
+ let react_jsx_runtime = require("react/jsx-runtime");
11
+ react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
12
+
13
+ //#region src/components/forms/CompleteProfileFields.tsx
14
+ /** The name field of the complete-profile card. */
15
+ function CompleteProfileFields({ onSubmit, maxDisplayNameLength, defaultName }) {
16
+ const [name, setName] = (0, react.useState)(defaultName ?? "");
17
+ const [nameError, setNameError] = (0, react.useState)("");
18
+ const pending = require_auth_pending_context.useAuthPending();
19
+ const isSubmitting = pending.pendingKey === require_auth_pending_context.AUTH_SUBMIT_ACTION;
20
+ const handleSubmit = (e) => {
21
+ e.preventDefault();
22
+ const trimmed = name.trim();
23
+ if (trimmed.length === 0) {
24
+ setNameError("Please enter your name");
25
+ return;
26
+ }
27
+ if (trimmed.length > maxDisplayNameLength) {
28
+ setNameError(`Your name must be ${maxDisplayNameLength} characters or fewer`);
29
+ return;
30
+ }
31
+ setNameError("");
32
+ pending.run(require_auth_pending_context.AUTH_SUBMIT_ACTION, async () => onSubmit(trimmed));
33
+ };
34
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("form", {
35
+ onSubmit: handleSubmit,
36
+ className: "space-y-4",
37
+ noValidate: true,
38
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AuthField.AuthField, {
39
+ id: "full_name",
40
+ label: "Full name",
41
+ name: "full_name",
42
+ type: "text",
43
+ autoComplete: "name",
44
+ autoFocus: true,
45
+ value: name,
46
+ onChange: (e) => {
47
+ setName(e.target.value);
48
+ if (nameError) setNameError("");
49
+ },
50
+ error: nameError,
51
+ maxLength: maxDisplayNameLength,
52
+ required: true
53
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AuthButton.AuthButton, {
54
+ type: "submit",
55
+ className: "mt-6 w-full",
56
+ actionKey: require_auth_pending_context.AUTH_SUBMIT_ACTION,
57
+ children: isSubmitting ? "Saving..." : "Continue"
58
+ })]
59
+ });
60
+ }
61
+
62
+ //#endregion
63
+ exports.CompleteProfileFields = CompleteProfileFields;
@@ -0,0 +1,18 @@
1
+ import * as react_jsx_runtime5 from "react/jsx-runtime";
2
+
3
+ //#region src/components/forms/CompleteProfileFields.d.ts
4
+ interface CompleteProfileFieldsProps {
5
+ onSubmit: (name: string) => Promise<void>;
6
+ /** The host's server-enforced display name limit. */
7
+ maxDisplayNameLength: number;
8
+ /** Prefill, when some provider supplied a partial name. */
9
+ defaultName?: string | null;
10
+ }
11
+ /** The name field of the complete-profile card. */
12
+ declare function CompleteProfileFields({
13
+ onSubmit,
14
+ maxDisplayNameLength,
15
+ defaultName
16
+ }: CompleteProfileFieldsProps): react_jsx_runtime5.JSX.Element;
17
+ //#endregion
18
+ export { CompleteProfileFields, CompleteProfileFieldsProps };
@@ -0,0 +1,18 @@
1
+ import * as react_jsx_runtime5 from "react/jsx-runtime";
2
+
3
+ //#region src/components/forms/CompleteProfileFields.d.ts
4
+ interface CompleteProfileFieldsProps {
5
+ onSubmit: (name: string) => Promise<void>;
6
+ /** The host's server-enforced display name limit. */
7
+ maxDisplayNameLength: number;
8
+ /** Prefill, when some provider supplied a partial name. */
9
+ defaultName?: string | null;
10
+ }
11
+ /** The name field of the complete-profile card. */
12
+ declare function CompleteProfileFields({
13
+ onSubmit,
14
+ maxDisplayNameLength,
15
+ defaultName
16
+ }: CompleteProfileFieldsProps): react_jsx_runtime5.JSX.Element;
17
+ //#endregion
18
+ export { CompleteProfileFields, CompleteProfileFieldsProps };
@@ -0,0 +1,60 @@
1
+ 'use client';
2
+
3
+
4
+ import { AUTH_SUBMIT_ACTION, useAuthPending } from "../auth-pending/auth-pending-context.js";
5
+ import { AuthButton } from "../auth-pending/AuthButton.js";
6
+ import { AuthField } from "./AuthField.js";
7
+ import { useState } from "react";
8
+ import { jsx, jsxs } from "react/jsx-runtime";
9
+
10
+ //#region src/components/forms/CompleteProfileFields.tsx
11
+ /** The name field of the complete-profile card. */
12
+ function CompleteProfileFields({ onSubmit, maxDisplayNameLength, defaultName }) {
13
+ const [name, setName] = useState(defaultName ?? "");
14
+ const [nameError, setNameError] = useState("");
15
+ const pending = useAuthPending();
16
+ const isSubmitting = pending.pendingKey === AUTH_SUBMIT_ACTION;
17
+ const handleSubmit = (e) => {
18
+ e.preventDefault();
19
+ const trimmed = name.trim();
20
+ if (trimmed.length === 0) {
21
+ setNameError("Please enter your name");
22
+ return;
23
+ }
24
+ if (trimmed.length > maxDisplayNameLength) {
25
+ setNameError(`Your name must be ${maxDisplayNameLength} characters or fewer`);
26
+ return;
27
+ }
28
+ setNameError("");
29
+ pending.run(AUTH_SUBMIT_ACTION, async () => onSubmit(trimmed));
30
+ };
31
+ return /* @__PURE__ */ jsxs("form", {
32
+ onSubmit: handleSubmit,
33
+ className: "space-y-4",
34
+ noValidate: true,
35
+ children: [/* @__PURE__ */ jsx(AuthField, {
36
+ id: "full_name",
37
+ label: "Full name",
38
+ name: "full_name",
39
+ type: "text",
40
+ autoComplete: "name",
41
+ autoFocus: true,
42
+ value: name,
43
+ onChange: (e) => {
44
+ setName(e.target.value);
45
+ if (nameError) setNameError("");
46
+ },
47
+ error: nameError,
48
+ maxLength: maxDisplayNameLength,
49
+ required: true
50
+ }), /* @__PURE__ */ jsx(AuthButton, {
51
+ type: "submit",
52
+ className: "mt-6 w-full",
53
+ actionKey: AUTH_SUBMIT_ACTION,
54
+ children: isSubmitting ? "Saving..." : "Continue"
55
+ })]
56
+ });
57
+ }
58
+
59
+ //#endregion
60
+ export { CompleteProfileFields };
@@ -0,0 +1,78 @@
1
+ 'use client';
2
+
3
+
4
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
5
+ const require_auth_pending_context = require('../auth-pending/auth-pending-context.cjs');
6
+ const require_AuthButton = require('../auth-pending/AuthButton.cjs');
7
+ const require_validation = require('../../constants/validation.cjs');
8
+ const require_AuthField = require('./AuthField.cjs');
9
+ let react = require("react");
10
+ react = require_rolldown_runtime.__toESM(react);
11
+ let react_jsx_runtime = require("react/jsx-runtime");
12
+ react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
13
+
14
+ //#region src/components/forms/EmailOtpCodeForm.tsx
15
+ const DIGITS_ONLY = /^\d+$/u;
16
+ const NON_DIGITS = /\D/gu;
17
+ /** The code-entry half of the emailed-code card. */
18
+ function EmailOtpCodeForm({ sentTo, onVerifyEmailOtp, expiryMinutes }) {
19
+ const [code, setCode] = (0, react.useState)("");
20
+ const [codeError, setCodeError] = (0, react.useState)("");
21
+ const pending = require_auth_pending_context.useAuthPending();
22
+ const isSubmitting = pending.pendingKey === require_auth_pending_context.AUTH_SUBMIT_ACTION;
23
+ const handleSubmit = (e) => {
24
+ e.preventDefault();
25
+ const trimmed = code.trim();
26
+ if (trimmed.length === 0) {
27
+ setCodeError("Enter the code from your email");
28
+ return;
29
+ }
30
+ if (trimmed.length !== require_validation.OTP_LENGTH || !DIGITS_ONLY.test(trimmed)) {
31
+ setCodeError(`The code is ${require_validation.OTP_LENGTH} digits`);
32
+ return;
33
+ }
34
+ setCodeError("");
35
+ pending.run(require_auth_pending_context.AUTH_SUBMIT_ACTION, async () => onVerifyEmailOtp(sentTo, trimmed));
36
+ };
37
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("form", {
38
+ onSubmit: handleSubmit,
39
+ className: "space-y-4",
40
+ noValidate: true,
41
+ children: [
42
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AuthField.AuthField, {
43
+ id: "email-otp-code",
44
+ label: "Sign-in code",
45
+ autoComplete: "one-time-code",
46
+ inputMode: "numeric",
47
+ autoFocus: true,
48
+ maxLength: require_validation.OTP_LENGTH,
49
+ placeholder: "0".repeat(require_validation.OTP_LENGTH),
50
+ value: code,
51
+ onChange: (e) => {
52
+ setCode(e.target.value.replace(NON_DIGITS, ""));
53
+ if (codeError) setCodeError("");
54
+ },
55
+ error: codeError,
56
+ required: true,
57
+ className: "text-center font-mono text-lg tracking-[0.4em]"
58
+ }),
59
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
60
+ className: "text-muted-foreground text-xs",
61
+ children: [
62
+ "The code works once and expires in ",
63
+ expiryMinutes,
64
+ " minutes. Check your spam folder if it does not arrive."
65
+ ]
66
+ }),
67
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AuthButton.AuthButton, {
68
+ type: "submit",
69
+ className: "w-full",
70
+ actionKey: require_auth_pending_context.AUTH_SUBMIT_ACTION,
71
+ children: isSubmitting ? "Signing in..." : "Sign in"
72
+ })
73
+ ]
74
+ });
75
+ }
76
+
77
+ //#endregion
78
+ exports.EmailOtpCodeForm = EmailOtpCodeForm;
@@ -0,0 +1,18 @@
1
+ import * as react_jsx_runtime6 from "react/jsx-runtime";
2
+
3
+ //#region src/components/forms/EmailOtpCodeForm.d.ts
4
+ interface EmailOtpCodeFormProps {
5
+ /** Address the code was sent to; submitted alongside the code. */
6
+ sentTo: string;
7
+ onVerifyEmailOtp: (email: string, code: string) => Promise<void>;
8
+ /** Stated code lifetime, in minutes, for the copy under the field. */
9
+ expiryMinutes: number;
10
+ }
11
+ /** The code-entry half of the emailed-code card. */
12
+ declare function EmailOtpCodeForm({
13
+ sentTo,
14
+ onVerifyEmailOtp,
15
+ expiryMinutes
16
+ }: EmailOtpCodeFormProps): react_jsx_runtime6.JSX.Element;
17
+ //#endregion
18
+ export { EmailOtpCodeForm, EmailOtpCodeFormProps };
@@ -0,0 +1,18 @@
1
+ import * as react_jsx_runtime6 from "react/jsx-runtime";
2
+
3
+ //#region src/components/forms/EmailOtpCodeForm.d.ts
4
+ interface EmailOtpCodeFormProps {
5
+ /** Address the code was sent to; submitted alongside the code. */
6
+ sentTo: string;
7
+ onVerifyEmailOtp: (email: string, code: string) => Promise<void>;
8
+ /** Stated code lifetime, in minutes, for the copy under the field. */
9
+ expiryMinutes: number;
10
+ }
11
+ /** The code-entry half of the emailed-code card. */
12
+ declare function EmailOtpCodeForm({
13
+ sentTo,
14
+ onVerifyEmailOtp,
15
+ expiryMinutes
16
+ }: EmailOtpCodeFormProps): react_jsx_runtime6.JSX.Element;
17
+ //#endregion
18
+ export { EmailOtpCodeForm, EmailOtpCodeFormProps };