@forgewp/compiler 0.4.1 → 0.4.3

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 (51) hide show
  1. package/README.md +11 -3
  2. package/bin/add.js +15 -6
  3. package/bin/analyze.js +66 -1
  4. package/bin/cli.js +20 -12
  5. package/bin/fresh.js +1 -1
  6. package/bin/make-block.js +11 -0
  7. package/bin/make-island.js +11 -0
  8. package/bin/{make-template.js → make-loop.js} +24 -19
  9. package/bin/make-page.js +83 -0
  10. package/bin/make-post-type.js +11 -0
  11. package/bin/make-sandbox.js +558 -0
  12. package/bin/sync-hooks.js +221 -0
  13. package/lib/adapters/html-adapter.js +8 -3
  14. package/lib/adapters/stub-adapter.js +6 -2
  15. package/lib/asset-loader.js +22 -0
  16. package/lib/blueprints.js +122 -1434
  17. package/lib/functions-builder.js +1172 -3
  18. package/lib/generate-theme.js +340 -23
  19. package/lib/hydration-scanner.js +170 -11
  20. package/lib/index.d.ts +38 -1
  21. package/lib/index.js +1 -1
  22. package/lib/load-config.js +98 -0
  23. package/lib/markup-processor.js +110 -0
  24. package/lib/page-config-plugin.js +40 -0
  25. package/lib/php-builders.js +4 -2
  26. package/lib/react-adapter.js +82 -23
  27. package/lib/render-theme.mts +115 -25
  28. package/lib/validate-export.js +49 -0
  29. package/package.json +4 -2
  30. package/templates/PresetsStyle.tsx +74 -0
  31. package/templates/SEO.tsx +109 -0
  32. package/templates/auth/components/dashboard-view-wrapper.tsx +168 -0
  33. package/templates/auth/components/forgot-password-form-wrapper.tsx +133 -0
  34. package/templates/auth/components/login-form-wrapper.tsx +203 -0
  35. package/templates/auth/components/reset-password-form-wrapper.tsx +182 -0
  36. package/templates/auth/components/signup-form-wrapper.tsx +257 -0
  37. package/templates/auth/components/verify-email-view-wrapper.tsx +265 -0
  38. package/templates/auth/pages/DashboardPage.tsx +15 -0
  39. package/templates/auth/pages/ForgotPasswordPage.tsx +14 -0
  40. package/templates/auth/pages/LoginPage.tsx +14 -0
  41. package/templates/auth/pages/ResetPasswordPage.tsx +14 -0
  42. package/templates/auth/pages/SignUpPage.tsx +14 -0
  43. package/templates/auth/pages/VerifyEmailPage.tsx +14 -0
  44. package/templates/forgewp-config.ts +110 -0
  45. package/templates/menus.json +11 -0
  46. package/templates/mock-data.json +123 -0
  47. package/templates/products.json +5 -0
  48. package/templates/roles.json +7 -0
  49. package/templates/sessions.json +1 -0
  50. package/templates/users.json +34 -0
  51. package/templates/wordpress.tsx +1390 -0
@@ -0,0 +1,133 @@
1
+ import * as React from 'react';
2
+ import { useWpAuth } from '@forgewp/auth';
3
+ import { useWpPageLink, useLocation } from '../.forgewp/wordpress';
4
+ import { Button } from '@/components/ui/button';
5
+ import {
6
+ Card,
7
+ CardContent,
8
+ CardDescription,
9
+ CardHeader,
10
+ CardTitle,
11
+ CardFooter,
12
+ } from '@/components/ui/card';
13
+ import {
14
+ Field,
15
+ FieldGroup,
16
+ FieldLabel,
17
+ } from '@/components/ui/field';
18
+ import { Input } from '@/components/ui/input';
19
+ import { AlertTriangleIcon, ArrowLeftIcon } from 'lucide-react';
20
+
21
+ export default function ForgotPasswordFormWrapper() {
22
+ const { forgotPassword, error, initializing } = useWpAuth();
23
+ const [_, setLocation] = useLocation();
24
+ const [emailOrUsername, setEmailOrUsername] = React.useState('');
25
+ const loginUrl = useWpPageLink('login-page', '/login');
26
+ const [success, setSuccess] = React.useState(false);
27
+ const [localError, setLocalError] = React.useState<string | null>(null);
28
+ const [submitting, setSubmitting] = React.useState(false);
29
+
30
+ const handleSubmit = async (e: React.FormEvent) => {
31
+ e.preventDefault();
32
+ setLocalError(null);
33
+ const input = emailOrUsername.trim();
34
+ if (!input) {
35
+ setLocalError('Please enter your username or email address.');
36
+ return;
37
+ }
38
+
39
+ setSubmitting(true);
40
+ try {
41
+ const ok = await forgotPassword(input);
42
+ if (ok) {
43
+ setSuccess(true);
44
+ }
45
+ } catch (err: any) {
46
+ setLocalError(err.message || 'An unexpected error occurred.');
47
+ } finally {
48
+ setSubmitting(false);
49
+ }
50
+ };
51
+
52
+ if (initializing) {
53
+ return (
54
+ <div className='flex flex-col items-center justify-center p-8 min-h-[300px]'>
55
+ <div className='w-12 h-12 border-4 border-primary border-t-transparent rounded-full animate-spin'></div>
56
+ <p className='text-slate-500 font-mono text-sm mt-4'>
57
+ Checking session...
58
+ </p>
59
+ </div>
60
+ );
61
+ }
62
+
63
+ return (
64
+ <Card>
65
+ <CardHeader>
66
+ <CardTitle>{success ? 'Check Your Email' : 'Forgot Password?'}</CardTitle>
67
+ <CardDescription>
68
+ {success
69
+ ? "If the account exists, we have sent a reset password link."
70
+ : "Enter your username or email address below and we'll send you a link to reset your password."}
71
+ </CardDescription>
72
+ </CardHeader>
73
+
74
+ <CardContent className="px-8 py-4">
75
+ {success ? (
76
+ <div className="text-zinc-600 text-sm leading-relaxed text-center">
77
+ <p className="mb-4">
78
+ We have sent instructions to reset your password.
79
+ </p>
80
+ <div className="bg-zinc-50 border border-zinc-100 rounded-lg p-3 text-xs text-zinc-500 text-left font-mono mb-4">
81
+ <strong>Dev Notice:</strong> Look for the simulated email in <code className="bg-zinc-200 px-1 rounded">cms/email-logs.json</code> to click the recovery link.
82
+ </div>
83
+ <button
84
+ onClick={() => setSuccess(false)}
85
+ className="text-primary hover:underline text-sm font-medium cursor-pointer"
86
+ >
87
+ Didn&apos;t receive the email? Try again
88
+ </button>
89
+ </div>
90
+ ) : (
91
+ <form onSubmit={handleSubmit}>
92
+ <FieldGroup>
93
+ {(localError || error) && (
94
+ <div className="bg-red-50 text-red-600 border border-red-200 text-sm p-3 rounded-md font-medium flex items-start gap-2">
95
+ <AlertTriangleIcon className="h-4 w-4 shrink-0 mt-0.5" />
96
+ <span>{localError || error}</span>
97
+ </div>
98
+ )}
99
+ <Field>
100
+ <FieldLabel htmlFor="emailOrUsername">Username or Email Address</FieldLabel>
101
+ <Input
102
+ id="emailOrUsername"
103
+ type="text"
104
+ placeholder="Enter username or email"
105
+ value={emailOrUsername}
106
+ onChange={(e) => setEmailOrUsername(e.target.value)}
107
+ disabled={submitting}
108
+ required
109
+ />
110
+ </Field>
111
+ <Field>
112
+ <Button type="submit" disabled={submitting} className="w-full cursor-pointer">
113
+ {submitting ? 'Sending link...' : 'Send Reset Link'}
114
+ </Button>
115
+ </Field>
116
+ </FieldGroup>
117
+ </form>
118
+ )}
119
+ </CardContent>
120
+
121
+ <CardFooter className="px-8 pb-8 pt-4 flex flex-col gap-2">
122
+ <Button
123
+ variant="outline"
124
+ className="w-full cursor-pointer hover:bg-zinc-50 border-zinc-200 flex items-center justify-center gap-2"
125
+ onClick={() => setLocation(loginUrl)}
126
+ >
127
+ <ArrowLeftIcon className="h-4 w-4" />
128
+ Return to Sign In
129
+ </Button>
130
+ </CardFooter>
131
+ </Card>
132
+ );
133
+ }
@@ -0,0 +1,203 @@
1
+ import * as React from 'react';
2
+ import { useWpAuth, useWpUser } from '@forgewp/auth';
3
+ import { useWpPageLink, useLocation } from '../.forgewp/wordpress';
4
+ import { cn } from '@/lib/utils';
5
+ import { Button } from '@/components/ui/button';
6
+ import {
7
+ Card,
8
+ CardContent,
9
+ CardDescription,
10
+ CardHeader,
11
+ CardTitle,
12
+ } from '@/components/ui/card';
13
+ import {
14
+ Field,
15
+ FieldGroup,
16
+ FieldLabel,
17
+ FieldDescription,
18
+ } from '@/components/ui/field';
19
+ import { Input } from '@/components/ui/input';
20
+ import { AlertTriangleIcon } from 'lucide-react';
21
+
22
+ export default function LoginFormWrapper({
23
+ className,
24
+ ...props
25
+ }: React.ComponentProps<'div'>) {
26
+ const { login, error, loginField, initializing, resendVerificationEmail } = useWpAuth();
27
+ const user = useWpUser();
28
+ const [_, setLocation] = useLocation();
29
+
30
+ const [username, setUsername] = React.useState('');
31
+ const [password, setPassword] = React.useState('');
32
+ const [localError, setLocalError] = React.useState<string | null>(null);
33
+ const [submitting, setSubmitting] = React.useState(false);
34
+
35
+ const [resendStatus, setResendStatus] = React.useState<'idle' | 'sending' | 'success' | 'failed'>('idle');
36
+ const [resendErrorMessage, setResendErrorMessage] = React.useState<string | null>(null);
37
+
38
+ const forgotPasswordUrl = useWpPageLink('forgot-password-page', '/forgot-password');
39
+ const signUpUrl = useWpPageLink('sign-up-page', '/signup');
40
+ const dashboardUrl = useWpPageLink('dashboard-page', '/dashboard');
41
+
42
+ React.useEffect(() => {
43
+ if (user) {
44
+ setLocation(dashboardUrl);
45
+ }
46
+ }, [user, setLocation, dashboardUrl]);
47
+
48
+ const handleResendVerification = async () => {
49
+ const input = username.trim();
50
+ if (!input) {
51
+ setResendErrorMessage('Please enter your username or email in the login field first.');
52
+ setResendStatus('failed');
53
+ return;
54
+ }
55
+
56
+ setResendStatus('sending');
57
+ setResendErrorMessage(null);
58
+ try {
59
+ const ok = await resendVerificationEmail(input);
60
+ if (ok) {
61
+ setResendStatus('success');
62
+ } else {
63
+ setResendStatus('failed');
64
+ setResendErrorMessage(error || 'Failed to resend verification email.');
65
+ }
66
+ } catch (err: any) {
67
+ setResendStatus('failed');
68
+ setResendErrorMessage(err.message || 'An unexpected error occurred.');
69
+ }
70
+ };
71
+
72
+ const handleSubmit = async (e: React.FormEvent) => {
73
+ e.preventDefault();
74
+ setLocalError(null);
75
+ setResendStatus('idle');
76
+ setResendErrorMessage(null);
77
+
78
+ const trimmedUsername = username.trim();
79
+ const trimmedPassword = password.trim();
80
+
81
+ if (!trimmedUsername || !trimmedPassword) {
82
+ setLocalError('Please enter both username/email and password.');
83
+ return;
84
+ }
85
+
86
+ setSubmitting(true);
87
+ try {
88
+ await login(trimmedUsername, trimmedPassword, dashboardUrl);
89
+ } catch (err: any) {
90
+ setLocalError(err.message || 'Login failed. Please try again.');
91
+ } finally {
92
+ setSubmitting(false);
93
+ }
94
+ };
95
+
96
+ if (initializing || user) {
97
+ return (
98
+ <div className='flex flex-col items-center justify-center p-8 min-h-[300px]'>
99
+ <div className='w-12 h-12 border-4 border-primary border-t-transparent rounded-full animate-spin'></div>
100
+ <p className='text-slate-500 font-mono text-sm mt-4'>
101
+ Checking session...
102
+ </p>
103
+ </div>
104
+ );
105
+ }
106
+
107
+ return (
108
+ <div
109
+ className={cn('flex flex-col gap-6', className)}
110
+ {...props}
111
+ >
112
+ <Card>
113
+ <CardHeader>
114
+ <CardTitle>Login to your account</CardTitle>
115
+ <CardDescription>
116
+ Enter your username or email below to login to your account
117
+ </CardDescription>
118
+ </CardHeader>
119
+ <CardContent>
120
+ <form onSubmit={handleSubmit}>
121
+ <FieldGroup>
122
+ {(localError || error) && (
123
+ <div className="bg-red-50 text-red-600 border border-red-200 text-sm p-3 rounded-md font-medium flex flex-col gap-2">
124
+ <div className="flex items-start gap-2">
125
+ <AlertTriangleIcon className="h-4 w-4 shrink-0 mt-0.5" />
126
+ <span>{localError || error}</span>
127
+ </div>
128
+ {((localError || error) as string).includes('not been verified yet') && (
129
+ <div className="mt-1 pt-2 border-t border-red-100 flex flex-col gap-2">
130
+ {resendStatus === 'success' ? (
131
+ <span className="text-green-600 text-xs font-semibold">
132
+ Verification email successfully resent!
133
+ </span>
134
+ ) : (
135
+ <button
136
+ type="button"
137
+ disabled={resendStatus === 'sending'}
138
+ onClick={handleResendVerification}
139
+ className="text-red-700 hover:underline text-xs font-semibold text-left cursor-pointer disabled:opacity-50"
140
+ >
141
+ {resendStatus === 'sending' ? 'Resending...' : "Didn't get the email? Click here to resend."}
142
+ </button>
143
+ )}
144
+ {resendStatus === 'failed' && resendErrorMessage && (
145
+ <span className="text-red-500 text-xs font-normal">
146
+ {resendErrorMessage}
147
+ </span>
148
+ )}
149
+ </div>
150
+ )}
151
+ </div>
152
+ )}
153
+ <Field>
154
+ <FieldLabel htmlFor='username'>
155
+ {loginField === 'usernameOnly' ? 'Username' : loginField === 'emailOnly' ? 'Email Address' : 'Username or Email'}
156
+ </FieldLabel>
157
+ <Input
158
+ id='username'
159
+ type='text'
160
+ placeholder={loginField === 'usernameOnly' ? 'username' : loginField === 'emailOnly' ? 'user@example.com' : 'admin / subscriber'}
161
+ value={username}
162
+ onChange={(e) => setUsername(e.target.value)}
163
+ disabled={submitting}
164
+ required
165
+ autoComplete="username"
166
+ />
167
+ </Field>
168
+ <Field>
169
+ <div className='flex items-center'>
170
+ <FieldLabel htmlFor='password'>Password</FieldLabel>
171
+ <a
172
+ href={forgotPasswordUrl}
173
+ className='ml-auto inline-block text-sm underline-offset-4 hover:underline'
174
+ >
175
+ Forgot your password?
176
+ </a>
177
+ </div>
178
+ <Input
179
+ id='password'
180
+ type='password'
181
+ placeholder='••••••••'
182
+ value={password}
183
+ onChange={(e) => setPassword(e.target.value)}
184
+ disabled={submitting}
185
+ required
186
+ autoComplete="current-password"
187
+ />
188
+ </Field>
189
+ <Field>
190
+ <Button type='submit' disabled={submitting} className="w-full cursor-pointer">
191
+ {submitting ? 'Logging in...' : 'Login'}
192
+ </Button>
193
+ <FieldDescription className='text-center'>
194
+ Don&apos;t have an account? <a href={signUpUrl} className="underline">Sign up</a>
195
+ </FieldDescription>
196
+ </Field>
197
+ </FieldGroup>
198
+ </form>
199
+ </CardContent>
200
+ </Card>
201
+ </div>
202
+ );
203
+ }
@@ -0,0 +1,182 @@
1
+ import * as React from 'react';
2
+ import { useWpAuth } from '@forgewp/auth';
3
+ import { useWpPageLink, useLocation } from '../.forgewp/wordpress';
4
+ import { Button } from '@/components/ui/button';
5
+ import {
6
+ Card,
7
+ CardContent,
8
+ CardDescription,
9
+ CardHeader,
10
+ CardTitle,
11
+ CardFooter,
12
+ } from '@/components/ui/card';
13
+ import {
14
+ Field,
15
+ FieldGroup,
16
+ FieldLabel,
17
+ } from '@/components/ui/field';
18
+ import { Input } from '@/components/ui/input';
19
+ import { AlertTriangleIcon, ArrowLeftIcon } from 'lucide-react';
20
+
21
+ export default function ResetPasswordFormWrapper() {
22
+ const { resetPassword, error, initializing } = useWpAuth();
23
+ const [_, setLocation] = useLocation();
24
+ const loginUrl = useWpPageLink('login-page', '/login');
25
+
26
+ const [key, setKey] = React.useState('');
27
+ const [login, setLogin] = React.useState('');
28
+ const [password, setPassword] = React.useState('');
29
+ const [confirmPassword, setConfirmPassword] = React.useState('');
30
+ const [success, setSuccess] = React.useState(false);
31
+ const [localError, setLocalError] = React.useState<string | null>(null);
32
+ const [missingParams, setMissingParams] = React.useState(false);
33
+ const [submitting, setSubmitting] = React.useState(false);
34
+
35
+ React.useEffect(() => {
36
+ const searchParams = new URLSearchParams(window.location.search);
37
+ const keyParam = searchParams.get('key');
38
+ const loginParam = searchParams.get('login');
39
+
40
+ if (!keyParam || !loginParam) {
41
+ setMissingParams(true);
42
+ } else {
43
+ setKey(keyParam);
44
+ setLogin(loginParam);
45
+ }
46
+ }, []);
47
+
48
+ const handleSubmit = async (e: React.FormEvent) => {
49
+ e.preventDefault();
50
+ setLocalError(null);
51
+
52
+ const trimmedPassword = password.trim();
53
+ const trimmedConfirmPassword = confirmPassword.trim();
54
+
55
+ if (!trimmedPassword) {
56
+ setLocalError('Please enter a new password.');
57
+ return;
58
+ }
59
+
60
+ if (trimmedPassword !== trimmedConfirmPassword) {
61
+ setLocalError('Passwords do not match.');
62
+ return;
63
+ }
64
+
65
+ if (trimmedPassword.length < 6) {
66
+ setLocalError('Password must be at least 6 characters long.');
67
+ return;
68
+ }
69
+
70
+ setSubmitting(true);
71
+ try {
72
+ const ok = await resetPassword(login, key, trimmedPassword);
73
+ if (ok) {
74
+ setSuccess(true);
75
+ setTimeout(() => {
76
+ setLocation(loginUrl);
77
+ }, 3000);
78
+ }
79
+ } catch (err: any) {
80
+ setLocalError(err.message || 'An unexpected error occurred.');
81
+ } finally {
82
+ setSubmitting(false);
83
+ }
84
+ };
85
+
86
+ if (initializing) {
87
+ return (
88
+ <div className='flex flex-col items-center justify-center p-8 min-h-[300px]'>
89
+ <div className='w-12 h-12 border-4 border-primary border-t-transparent rounded-full animate-spin'></div>
90
+ <p className='text-slate-500 font-mono text-sm mt-4'>
91
+ Checking session...
92
+ </p>
93
+ </div>
94
+ );
95
+ }
96
+
97
+ return (
98
+ <Card>
99
+ <CardHeader>
100
+ <CardTitle>
101
+ {success
102
+ ? 'Password Reset Complete'
103
+ : missingParams
104
+ ? 'Invalid Reset Link'
105
+ : 'Reset Your Password'}
106
+ </CardTitle>
107
+ <CardDescription>
108
+ {success
109
+ ? 'Your password has been successfully updated.'
110
+ : missingParams
111
+ ? 'This password reset link is invalid or incomplete.'
112
+ : `Choose a new secure password for ${login}.`}
113
+ </CardDescription>
114
+ </CardHeader>
115
+
116
+ <CardContent className="px-8 py-4">
117
+ {success ? (
118
+ <p className="text-green-600 font-medium text-center text-sm leading-relaxed">
119
+ Redirecting you to the sign in page in 3 seconds...
120
+ </p>
121
+ ) : missingParams ? (
122
+ <div className="text-zinc-600 text-sm leading-relaxed text-center">
123
+ <p className="mb-4">
124
+ The password reset link is missing required verification parameters. Please request a new link.
125
+ </p>
126
+ </div>
127
+ ) : (
128
+ <form onSubmit={handleSubmit}>
129
+ <FieldGroup>
130
+ {(localError || error) && (
131
+ <div className="bg-red-50 text-red-600 border border-red-200 text-sm p-3 rounded-md font-medium flex items-start gap-2">
132
+ <AlertTriangleIcon className="h-4 w-4 shrink-0 mt-0.5" />
133
+ <span>{localError || error}</span>
134
+ </div>
135
+ )}
136
+ <Field>
137
+ <FieldLabel htmlFor="password">New Password</FieldLabel>
138
+ <Input
139
+ id="password"
140
+ type="password"
141
+ placeholder="••••••••"
142
+ value={password}
143
+ onChange={(e) => setPassword(e.target.value)}
144
+ disabled={submitting}
145
+ required
146
+ />
147
+ </Field>
148
+ <Field>
149
+ <FieldLabel htmlFor="confirmPassword">Confirm Password</FieldLabel>
150
+ <Input
151
+ id="confirmPassword"
152
+ type="password"
153
+ placeholder="••••••••"
154
+ value={confirmPassword}
155
+ onChange={(e) => setConfirmPassword(e.target.value)}
156
+ disabled={submitting}
157
+ required
158
+ />
159
+ </Field>
160
+ <Field>
161
+ <Button type="submit" disabled={submitting} className="w-full cursor-pointer">
162
+ {submitting ? 'Resetting password...' : 'Update Password'}
163
+ </Button>
164
+ </Field>
165
+ </FieldGroup>
166
+ </form>
167
+ )}
168
+ </CardContent>
169
+
170
+ <CardFooter className="px-8 pb-8 pt-4 flex flex-col gap-2">
171
+ <Button
172
+ variant="outline"
173
+ className="w-full cursor-pointer hover:bg-zinc-50 border-zinc-200 flex items-center justify-center gap-2"
174
+ onClick={() => setLocation(loginUrl)}
175
+ >
176
+ <ArrowLeftIcon className="h-4 w-4" />
177
+ Return to Sign In
178
+ </Button>
179
+ </CardFooter>
180
+ </Card>
181
+ );
182
+ }