@forgewp/compiler 0.4.2 → 0.4.4

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 (144) hide show
  1. package/README.md +70 -3
  2. package/bin/add.js +30 -15
  3. package/bin/analyze.js +66 -1
  4. package/bin/cli.js +149 -70
  5. package/bin/doctor.js +21 -12
  6. package/bin/export.js +69 -20
  7. package/bin/fresh.js +6 -1
  8. package/bin/i18n-extract.js +3 -10
  9. package/bin/i18n-translate.js +15 -24
  10. package/bin/make-block.js +24 -0
  11. package/bin/make-editable.js +166 -0
  12. package/bin/make-form.js +131 -0
  13. package/bin/make-island.js +11 -0
  14. package/bin/make-loop.js +147 -0
  15. package/bin/make-mail.js +27 -0
  16. package/bin/make-page.js +83 -0
  17. package/bin/make-post-type.js +68 -29
  18. package/bin/make-sandbox.js +609 -0
  19. package/bin/make-section.js +221 -0
  20. package/bin/make-shell.js +375 -0
  21. package/bin/repair.js +14 -26
  22. package/bin/seed.js +119 -0
  23. package/bin/sync-routes.js +107 -85
  24. package/lib/adapters/html-adapter.js +13 -3
  25. package/lib/adapters/stub-adapter.js +10 -2
  26. package/lib/add-component.js +153 -92
  27. package/lib/asset-loader.js +333 -1
  28. package/lib/assets/asset-graph.js +432 -0
  29. package/lib/assets/asset-pipeline.js +125 -0
  30. package/lib/assets/diagnostics-report.js +345 -0
  31. package/lib/assets/external-fetcher.js +173 -0
  32. package/lib/assets/font-orchestrator.js +348 -0
  33. package/lib/assets/font-usage-scanner.js +242 -0
  34. package/lib/assets/image-optimizer.js +229 -0
  35. package/lib/assets/index.js +51 -0
  36. package/lib/assets/preload-generator.js +70 -0
  37. package/lib/assets/public-url.js +153 -0
  38. package/lib/block-authoring-help.js +11 -0
  39. package/lib/blocks/ast-parser.js +67 -0
  40. package/lib/blocks/discover-blocks.js +146 -0
  41. package/lib/blocks/editor-scope.js +733 -0
  42. package/lib/blocks/editor-transpiler.js +1229 -0
  43. package/lib/blocks/index.js +2838 -0
  44. package/lib/blocks/php-transpiler.js +4928 -0
  45. package/lib/blocks/scanner.js +1487 -0
  46. package/lib/blocks/shared-utils.js +290 -0
  47. package/lib/blocks/source-sanitize.js +1449 -0
  48. package/lib/blueprints.js +77 -5
  49. package/lib/build-assets.js +38 -33
  50. package/lib/collect-page-template-routes.js +102 -0
  51. package/lib/collect-static-routes.js +175 -0
  52. package/lib/diagnostics.js +58 -33
  53. package/lib/export-theme.js +84 -5
  54. package/lib/extract-template-content.js +90 -0
  55. package/lib/forms-preview.js +42 -0
  56. package/lib/functions/cpt-routing.js +69 -0
  57. package/lib/functions/forms.js +2461 -0
  58. package/lib/functions/hydration-enqueuer.js +400 -0
  59. package/lib/functions/index.js +1623 -0
  60. package/lib/functions/load-menus.js +112 -0
  61. package/lib/functions/load-translations.js +148 -0
  62. package/lib/functions/rest-endpoints.js +2923 -0
  63. package/lib/functions/routing.js +765 -0
  64. package/lib/functions/seed-mock-data.js +392 -0
  65. package/lib/functions/seed-products.js +481 -0
  66. package/lib/functions/settings-page.js +273 -0
  67. package/lib/functions/theme-setup.js +494 -0
  68. package/lib/generate-theme.js +2076 -303
  69. package/lib/hydration/editable-schemas.js +332 -0
  70. package/lib/hydration/enter-hidden-initial.js +65 -0
  71. package/lib/hydration/form-schemas.js +227 -0
  72. package/lib/hydration/index.js +12 -0
  73. package/lib/hydration/is-interactive.js +951 -0
  74. package/lib/hydration/island-split.js +1231 -0
  75. package/lib/hydration/islands-scanner.js +599 -0
  76. package/lib/hydration/resolve-island-chunk.js +103 -0
  77. package/lib/hydration/resolve-island-component.js +52 -0
  78. package/lib/hydration/rollup-inputs.js +81 -0
  79. package/lib/hydration/root-class-extractor.js +220 -0
  80. package/lib/hydration/scan-app-providers.js +154 -0
  81. package/lib/hydration/static-lint.js +382 -0
  82. package/lib/hydration/transform.js +257 -0
  83. package/lib/hydration/uses-block-area.js +49 -0
  84. package/lib/hydration/utils.js +119 -0
  85. package/lib/i18n/translation-cache.js +141 -0
  86. package/lib/icon-registry.js +72 -0
  87. package/lib/index.d.ts +324 -8
  88. package/lib/index.js +3 -2
  89. package/lib/load-config.js +338 -144
  90. package/lib/mail-templates.js +37 -0
  91. package/lib/markup-processor.js +483 -92
  92. package/lib/node-runtime.js +7 -0
  93. package/lib/page-config-plugin.js +84 -0
  94. package/lib/php-builders.js +383 -42
  95. package/lib/react-adapter.js +1053 -246
  96. package/lib/registration-metadata.js +11 -0
  97. package/lib/render-theme.mts +1410 -543
  98. package/lib/route-layout.js +76 -0
  99. package/lib/template-discovery.js +58 -0
  100. package/lib/theme-compatibility.js +32 -0
  101. package/lib/validate-export.js +51 -2
  102. package/lib/validate.js +27 -5
  103. package/lib/virtual-plugin.js +319 -0
  104. package/lib/walkthrough.md +26 -0
  105. package/package.json +17 -5
  106. package/templates/PresetsStyle.tsx +1 -1
  107. package/templates/auth/cms/email-logs.json +9 -0
  108. package/templates/auth/cms/menus.json +11 -0
  109. package/templates/auth/cms/mock-data.json +123 -0
  110. package/templates/auth/cms/roles.json +7 -0
  111. package/templates/auth/cms/sessions.json +1 -0
  112. package/templates/auth/cms/site-settings.json +28 -0
  113. package/templates/auth/cms/translations.json +4 -0
  114. package/templates/auth/cms/users.json +46 -0
  115. package/templates/auth/components/dashboard-view-wrapper.tsx +168 -0
  116. package/templates/auth/components/forgot-password-form-wrapper.tsx +141 -0
  117. package/templates/auth/components/login-form-wrapper.tsx +300 -0
  118. package/templates/auth/components/reset-password-form-wrapper.tsx +190 -0
  119. package/templates/auth/components/signup-form-wrapper.tsx +257 -0
  120. package/templates/auth/components/verify-email-view-wrapper.tsx +265 -0
  121. package/templates/auth/pages/DashboardPage.tsx +12 -0
  122. package/templates/auth/pages/ForgotPasswordPage.tsx +11 -0
  123. package/templates/auth/pages/LoginPage.tsx +11 -0
  124. package/templates/auth/pages/ResetPasswordPage.tsx +11 -0
  125. package/templates/auth/pages/SignUpPage.tsx +11 -0
  126. package/templates/auth/pages/VerifyEmailPage.tsx +11 -0
  127. package/templates/auth/ui/button.tsx +57 -0
  128. package/templates/auth/ui/card.tsx +76 -0
  129. package/templates/auth/ui/field.tsx +242 -0
  130. package/templates/auth/ui/input.tsx +22 -0
  131. package/templates/auth/ui/label.tsx +24 -0
  132. package/templates/auth/ui/separator.tsx +31 -0
  133. package/templates/forgewp-config.ts +70 -3
  134. package/templates/menus.json +12 -10
  135. package/templates/mock-data.json +122 -433
  136. package/templates/products.json +5 -0
  137. package/templates/roles.json +7 -0
  138. package/templates/sessions.json +1 -0
  139. package/templates/users.json +38 -0
  140. package/templates/wordpress.tsx +1835 -1297
  141. package/bin/make-template.js +0 -145
  142. package/lib/block-compiler.js +0 -552
  143. package/lib/functions-builder.js +0 -2044
  144. package/lib/hydration-scanner.js +0 -821
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forgewp/compiler",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "Compile ForgeWP React themes into installable WordPress themes",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -25,21 +25,33 @@
25
25
  "define-config.d.ts"
26
26
  ],
27
27
  "engines": {
28
- "node": ">=18"
28
+ "node": "^22.18.0 || >=24.11.0"
29
29
  },
30
30
  "dependencies": {
31
+ "@babel/parser": "^8.0.4",
32
+ "@babel/traverse": "^8.0.4",
33
+ "@babel/types": "^8.0.4",
31
34
  "archiver": "^7.0.1",
32
35
  "jiti": "^2.6.1",
33
36
  "picocolors": "^1.1.1",
34
37
  "react-helmet-async": "^3.0.0",
35
- "@forgewp/ui": "0.4.2"
38
+ "select2": "^4.1.0",
39
+ "sharp": "^0.35.3",
40
+ "@forgewp/ui": "0.4.4"
36
41
  },
37
42
  "devDependencies": {
38
- "@types/node": "^22.19.19"
43
+ "@types/node": "^22.19.19",
44
+ "react": "19.2.6",
45
+ "react-dom": "19.2.6",
46
+ "vitest": "^4.1.10"
39
47
  },
40
48
  "scripts": {
49
+ "test": "vitest run",
41
50
  "test:export-fixture": "node test/export-fixture/run-export-fixture.js",
51
+ "test:auth-transpilation": "node test/auth-transpilation.js",
42
52
  "test:adapter-runtime": "node test/adapter-loader.js",
43
- "test:adapter-types": "pnpm exec tsc --noEmit -p tsconfig.test.json"
53
+ "test:adapter-types": "pnpm exec tsc --noEmit -p tsconfig.test.json",
54
+ "test:public-api": "vitest run --configLoader runner test/functions/public-api-types.test.js",
55
+ "test:node-runtime": "node test/node-runtime-smoke.mjs"
44
56
  }
45
57
  }
@@ -43,7 +43,7 @@ export function PresetsStyle() {
43
43
  const fontsHtml = googleFonts.length > 0
44
44
  ? `<link rel="preconnect" href="https://fonts.googleapis.com">
45
45
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
46
- <link href="https://fonts.googleapis.com/css2?family=&{googleFonts.map(f => encodeURIComponent(f)).join("&family=")}&display=swap" rel="stylesheet">`
46
+ <link href="https://fonts.googleapis.com/css2?family=${googleFonts.map((f: string) => encodeURIComponent(f)).join("&family=")}&display=swap" rel="stylesheet">`
47
47
  : "";
48
48
 
49
49
  const devCss = `
@@ -0,0 +1,9 @@
1
+ [
2
+ {
3
+ "to": "user@forgewp.local",
4
+ "subject": "Verify your ForgeWP Account",
5
+ "message": "Welcome to ForgeWP! Click this link to verify your email address:\n\nhttp://localhost:5173/verify-email?userId=2&token=mock-verification-m5ofls68",
6
+ "verification_url": "http://localhost:5173/verify-email?userId=2&token=mock-verification-m5ofls68",
7
+ "timestamp": "2026-06-28T16:14:50.908Z"
8
+ }
9
+ ]
@@ -0,0 +1,11 @@
1
+ {
2
+ "_comment": "⚡ ForgeWP Navigation Menus — Edit this file to add/remove links in local dev.",
3
+ "primary": [
4
+ { "title": "Hotelvergleiche", "url": "/hotelvergleiche" },
5
+ { "title": "Hotels", "url": "/hotels" },
6
+ { "title": "Über uns", "url": "/about" }
7
+ ],
8
+ "utility": [
9
+ { "title": "Kontakt", "url": "/contact" }
10
+ ]
11
+ }
@@ -0,0 +1,123 @@
1
+ {
2
+ "post": [
3
+ {
4
+ "id": 1,
5
+ "title": "Welcome to ForgeWP: The Headless Revolution",
6
+ "excerpt": "Discover how ForgeWP bridges standard WordPress themes with blistering fast React architectures.",
7
+ "content": "<p>This is the first mock post. In local dev, you can modify <code>cms/mock-data.json</code> to test layout content changes.</p>",
8
+ "date": "2026-05-10T09:00:00Z",
9
+ "author": "Antigravity",
10
+ "featuredImage": {
11
+ "id": 101,
12
+ "url": "https://picsum.photos/seed/forgewp/1200/630",
13
+ "alt": "ForgeWP Logo and Brand Artwork",
14
+ "title": "ForgeWP Logo",
15
+ "caption": "A high-fidelity minimalist logo graphic.",
16
+ "width": 1200,
17
+ "height": 630,
18
+ "sizes": {
19
+ "thumbnail": { "url": "https://picsum.photos/seed/forgewp/150/150", "width": 150, "height": 150 },
20
+ "medium": { "url": "https://picsum.photos/seed/forgewp/300/300", "width": 300, "height": 300 },
21
+ "large": { "url": "https://picsum.photos/seed/forgewp/1024/768", "width": 1024, "height": 768 }
22
+ }
23
+ },
24
+ "customFields": { "read_time": "5" },
25
+ "_terms": {
26
+ "category": [
27
+ { "id": 1, "slug": "tutorials", "name": "Tutorials" },
28
+ { "id": 2, "slug": "framework", "name": "Framework" }
29
+ ],
30
+ "post_tag": [
31
+ { "id": 10, "slug": "react", "name": "React" },
32
+ { "id": 11, "slug": "wordpress", "name": "WordPress" }
33
+ ]
34
+ }
35
+ },
36
+ {
37
+ "id": 2,
38
+ "title": "Unlocking Brutalist Web Design Aesthetics",
39
+ "excerpt": "A deep dive into high-contrast grids, sharp corners, and premium flat shadows in modern interfaces.",
40
+ "content": "<p>This is the second mock post. Style these grids using beautiful Tailwind utilities.</p>",
41
+ "date": "2026-05-12T14:30:00Z",
42
+ "author": "DeepMind Partner",
43
+ "featuredImage": "https://picsum.photos/seed/brutalist/1200/630",
44
+ "customFields": { "read_time": "8" },
45
+ "_terms": {
46
+ "category": [
47
+ { "id": 3, "slug": "design", "name": "Design" },
48
+ { "id": 4, "slug": "css", "name": "CSS" }
49
+ ],
50
+ "post_tag": [
51
+ { "id": 12, "slug": "brutalism", "name": "Brutalism" },
52
+ { "id": 13, "slug": "tailwind", "name": "Tailwind" }
53
+ ]
54
+ }
55
+ }
56
+ ],
57
+ "project": [
58
+ {
59
+ "id": 1,
60
+ "title": "ForgeWP Scaffolding Platform",
61
+ "excerpt": "Building a custom compiler framework to transpile React elements into standard PHP themes.",
62
+ "content": "<p>Detailed description of the ForgeWP compiler pipeline project.</p>",
63
+ "date": "2026-05-15T12:00:00Z",
64
+ "author": "Lead Architect",
65
+ "featuredImage": "https://picsum.photos/seed/platform/1200/630",
66
+ "customFields": {
67
+ "client_name": "El Dorado",
68
+ "project_budget": "45000",
69
+ "status": "active"
70
+ },
71
+ "_terms": {
72
+ "project_type": [{ "id": 20, "slug": "open-source", "name": "Open Source" }],
73
+ "technology": [{ "id": 30, "slug": "react", "name": "React" }]
74
+ }
75
+ },
76
+ {
77
+ "id": 2,
78
+ "title": "Brutalist Starter Theme",
79
+ "excerpt": "A clean, responsive, and robust high-contrast interface leveraging Tailwind CSS v4.",
80
+ "content": "<p>A brutalist theme showcasing raw black borders and vivid accent colors.</p>",
81
+ "date": "2026-05-16T16:00:00Z",
82
+ "author": "Theme Engineer",
83
+ "featuredImage": "https://picsum.photos/seed/starter/1200/630",
84
+ "customFields": {
85
+ "client_name": "ForgeWP Community",
86
+ "project_budget": "0",
87
+ "status": "completed"
88
+ },
89
+ "_terms": {
90
+ "project_type": [{ "id": 20, "slug": "open-source", "name": "Open Source" }],
91
+ "technology": [{ "id": 32, "slug": "tailwind", "name": "Tailwind CSS" }]
92
+ }
93
+ }
94
+ ],
95
+ "attachment": [
96
+ {
97
+ "id": 101,
98
+ "url": "https://picsum.photos/seed/forgewp/1200/630",
99
+ "alt": "ForgeWP Logo and Brand Artwork",
100
+ "title": "ForgeWP Logo",
101
+ "caption": "A high-fidelity minimalist logo graphic.",
102
+ "width": 1200,
103
+ "height": 630,
104
+ "sizes": {
105
+ "thumbnail": { "url": "https://picsum.photos/seed/forgewp/150/150", "width": 150, "height": 150 },
106
+ "medium": { "url": "https://picsum.photos/seed/forgewp/300/300", "width": 300, "height": 300 },
107
+ "large": { "url": "https://picsum.photos/seed/forgewp/1024/768", "width": 1024, "height": 768 }
108
+ }
109
+ },
110
+ {
111
+ "id": 102,
112
+ "url": "https://picsum.photos/seed/layout/1200/800",
113
+ "alt": "Brutalist Layout Preview",
114
+ "title": "Layout Preview",
115
+ "width": 1200,
116
+ "height": 800,
117
+ "sizes": {
118
+ "thumbnail": { "url": "https://picsum.photos/seed/layout/150/150", "width": 150, "height": 150 },
119
+ "medium": { "url": "https://picsum.photos/seed/layout/300/300", "width": 300, "height": 300 }
120
+ }
121
+ }
122
+ ]
123
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "administrator": ["manage_options", "edit_theme_options", "edit_posts", "edit_others_posts", "publish_posts", "read"],
3
+ "editor": ["edit_posts", "edit_others_posts", "publish_posts", "read"],
4
+ "author": ["edit_posts", "publish_posts", "read"],
5
+ "subscriber": ["read"],
6
+ "customer": ["read"]
7
+ }
@@ -0,0 +1 @@
1
+ []
@@ -0,0 +1,28 @@
1
+ {
2
+ "options": {
3
+ "blogname": "ForgeWP Starter",
4
+ "blogdescription": "A clean default canvas for building block-themes with ForgeWP.",
5
+ "admin_email": "admin@forgewp.local",
6
+ "posts_per_page": "10",
7
+ "blogurl": "http://forgewp.local",
8
+ "home": "http://forgewp.local",
9
+ "siteurl": "http://forgewp.local",
10
+ "users_can_register": "0",
11
+ "contact_phone": "+1 (555) 019-9000",
12
+ "contact_email": "admin@forgewp.local",
13
+ "social_facebook": "https://facebook.com",
14
+ "social_instagram": "https://instagram.com",
15
+ "social_twitter": "https://twitter.com",
16
+ "social_youtube": "",
17
+ "social_tiktok": "",
18
+ "social_linkedin": "",
19
+ "social_pinterest": "",
20
+ "editor_note": "ForgeWP Canvas"
21
+ },
22
+ "theme_mods": {
23
+ "custom_logo": "",
24
+ "header_textcolor": "#0f172a",
25
+ "footer_text": "© 2026 Hotelchecker24. All rights reserved.",
26
+ "nav_menu_locations": {}
27
+ }
28
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "en": {},
3
+ "de": {}
4
+ }
@@ -0,0 +1,46 @@
1
+ [
2
+ {
3
+ "id": 1,
4
+ "username": "admin",
5
+ "email": "admin@forgewp.local",
6
+ "displayName": "Concrete Designer",
7
+ "roles": [
8
+ "administrator"
9
+ ],
10
+ "avatarUrl": "https://picsum.photos/seed/avatar1/150/150",
11
+ "emailVerified": true
12
+ },
13
+ {
14
+ "id": 2,
15
+ "username": "subscriber",
16
+ "email": "user@forgewp.local",
17
+ "displayName": "Sub Concrete",
18
+ "roles": [
19
+ "subscriber"
20
+ ],
21
+ "avatarUrl": "https://picsum.photos/seed/avatar2/150/150",
22
+ "emailVerified": true
23
+ },
24
+ {
25
+ "id": 3,
26
+ "username": "editor",
27
+ "email": "editor@forgewp.local",
28
+ "displayName": "Concrete Editor",
29
+ "roles": [
30
+ "editor"
31
+ ],
32
+ "avatarUrl": "https://picsum.photos/seed/avatar3/150/150",
33
+ "emailVerified": true
34
+ },
35
+ {
36
+ "id": 4,
37
+ "username": "customer",
38
+ "email": "customer@forgewp.local",
39
+ "displayName": "Concrete Customer",
40
+ "roles": [
41
+ "customer"
42
+ ],
43
+ "avatarUrl": "https://picsum.photos/seed/avatar4/150/150",
44
+ "emailVerified": true
45
+ }
46
+ ]
@@ -0,0 +1,168 @@
1
+ import * as React from 'react';
2
+ import { useWpUser, useWpAuth } from '@forgewp/auth';
3
+ import { LogOut, User, Mail, Shield, CheckCircle2, XCircle, Code, Key } from 'lucide-react';
4
+
5
+ export default function DashboardViewWrapper() {
6
+ const user = useWpUser();
7
+ const { logout, initializing } = useWpAuth();
8
+ const [showRawJson, setShowRawJson] = React.useState(false);
9
+
10
+ if (initializing || !user) {
11
+ return (
12
+ <div className='min-h-screen bg-[#fafafa] flex items-center justify-center font-sans'>
13
+ <div className='flex flex-col items-center gap-4'>
14
+ <div className='w-12 h-12 border-4 border-primary border-t-transparent rounded-full animate-spin'></div>
15
+ <p className='text-slate-500 font-mono text-sm'>
16
+ Loading your account...
17
+ </p>
18
+ </div>
19
+ </div>
20
+ );
21
+ }
22
+
23
+ const capabilities = user.capabilities || [];
24
+
25
+ return (
26
+ <main className='min-h-screen bg-[#fafafa] text-slate-900 font-sans py-12 px-6 flex items-center justify-center'>
27
+ <div className='w-full max-w-2xl bg-white border border-slate-200/80 shadow-xs p-8 sm:p-12 relative'>
28
+
29
+ {/* Header Profile Info */}
30
+ <div className='flex flex-col items-center text-center pb-8 border-b border-slate-100'>
31
+ <div className='relative mb-4'>
32
+ <img
33
+ src={user.avatarUrl || `https://picsum.photos/seed/${user.username}/150/150`}
34
+ alt={user.displayName}
35
+ className='w-24 h-24 rounded-full border-4 border-slate-100 object-cover shadow-xs'
36
+ />
37
+ <div className='absolute bottom-0 right-0 bg-primary border-2 border-white p-1.5 rounded-full text-white shadow-md'>
38
+ <User className='w-3.5 h-3.5' />
39
+ </div>
40
+ </div>
41
+ <h1 className='text-2xl font-heading font-black tracking-tight uppercase text-slate-900'>
42
+ {user.displayName}
43
+ </h1>
44
+ <p className='text-slate-400 font-mono text-xs mt-0.5'>
45
+ @{user.username}
46
+ </p>
47
+
48
+ <div className='flex flex-wrap justify-center gap-1.5 mt-3'>
49
+ {user.roles.map((role) => (
50
+ <span
51
+ key={role}
52
+ className='bg-primary/5 text-primary border border-primary/10 text-[10px] font-mono font-bold uppercase tracking-wider px-2 py-0.5 rounded-sm'
53
+ >
54
+ {role}
55
+ </span>
56
+ ))}
57
+ </div>
58
+ </div>
59
+
60
+ {/* Detailed Account Grid */}
61
+ <div className='py-8 border-b border-slate-100 grid grid-cols-1 sm:grid-cols-2 gap-6'>
62
+ <div className='flex items-start gap-3'>
63
+ <Shield className='w-4.5 h-4.5 text-slate-400 shrink-0 mt-0.5' />
64
+ <div>
65
+ <p className='text-[10px] font-mono font-bold uppercase text-slate-400 tracking-wider'>
66
+ User ID (WordPress)
67
+ </p>
68
+ <p className='text-sm font-mono text-slate-700 font-semibold mt-0.5'>
69
+ #{user.id}
70
+ </p>
71
+ </div>
72
+ </div>
73
+
74
+ <div className='flex items-start gap-3'>
75
+ <Mail className='w-4.5 h-4.5 text-slate-400 shrink-0 mt-0.5' />
76
+ <div className='overflow-hidden'>
77
+ <p className='text-[10px] font-mono font-bold uppercase text-slate-400 tracking-wider'>
78
+ Email Address
79
+ </p>
80
+ <p className='text-sm font-semibold text-slate-700 truncate mt-0.5'>
81
+ {user.email}
82
+ </p>
83
+ </div>
84
+ </div>
85
+
86
+ <div className='flex items-start gap-3'>
87
+ {user.emailVerified ? (
88
+ <CheckCircle2 className='w-4.5 h-4.5 text-emerald-500 shrink-0 mt-0.5' />
89
+ ) : (
90
+ <XCircle className='w-4.5 h-4.5 text-amber-500 shrink-0 mt-0.5' />
91
+ )}
92
+ <div>
93
+ <p className='text-[10px] font-mono font-bold uppercase text-slate-400 tracking-wider'>
94
+ Verification Status
95
+ </p>
96
+ <p className={`text-sm font-semibold mt-0.5 ${user.emailVerified ? 'text-emerald-600' : 'text-amber-600'}`}>
97
+ {user.emailVerified ? 'Verified Account' : 'Unverified Account'}
98
+ </p>
99
+ </div>
100
+ </div>
101
+
102
+ <div className='flex items-start gap-3'>
103
+ <Key className='w-4.5 h-4.5 text-slate-400 shrink-0 mt-0.5' />
104
+ <div>
105
+ <p className='text-[10px] font-mono font-bold uppercase text-slate-400 tracking-wider'>
106
+ Session State
107
+ </p>
108
+ <p className='text-sm font-semibold text-slate-700 mt-0.5'>
109
+ Active
110
+ </p>
111
+ </div>
112
+ </div>
113
+ </div>
114
+
115
+ {/* Capabilities Section */}
116
+ {capabilities.length > 0 && (
117
+ <div className='py-8 border-b border-slate-100'>
118
+ <h2 className='text-xs font-mono font-bold uppercase text-slate-400 tracking-wider mb-3'>
119
+ Granted Session Capabilities
120
+ </h2>
121
+ <div className='flex flex-wrap gap-1.5'>
122
+ {capabilities.map((cap) => (
123
+ <span
124
+ key={cap}
125
+ className='bg-slate-50 border border-slate-150 text-slate-600 font-mono text-[11px] px-2.5 py-1 rounded-sm'
126
+ >
127
+ {cap}
128
+ </span>
129
+ ))}
130
+ </div>
131
+ </div>
132
+ )}
133
+
134
+ {/* Toggleable Raw User JSON explorer */}
135
+ <div className='py-8'>
136
+ <button
137
+ onClick={() => setShowRawJson(!showRawJson)}
138
+ className='flex items-center gap-2 text-slate-500 hover:text-slate-900 text-xs font-mono font-bold uppercase tracking-wider cursor-pointer'
139
+ >
140
+ <Code className='w-4 h-4' />
141
+ {showRawJson ? 'Hide Raw User Object' : 'Show Raw User Object'}
142
+ </button>
143
+
144
+ {showRawJson && (
145
+ <div className='mt-4 bg-slate-50 border border-slate-200 p-4 font-mono text-xs text-slate-600 overflow-x-auto max-h-60 rounded-none leading-relaxed'>
146
+ <pre>{JSON.stringify(user, null, 2)}</pre>
147
+ </div>
148
+ )}
149
+ </div>
150
+
151
+ {/* Footer actions */}
152
+ <div className='pt-6 border-t border-slate-100 flex flex-col sm:flex-row gap-4 items-center justify-between'>
153
+ <p className='text-[11px] text-slate-400 font-mono'>
154
+ Note: Avatars are fetched natively via Gravatar in production.
155
+ </p>
156
+ <button
157
+ onClick={() => logout()}
158
+ className='group inline-flex items-center justify-center bg-white text-slate-900 border border-slate-200 hover:bg-red-50 hover:text-red-600 hover:border-red-200 font-mono font-bold text-xs uppercase tracking-widest px-5 py-3 transition-all duration-200 rounded-none cursor-pointer w-full sm:w-auto'
159
+ >
160
+ <LogOut className='w-4 h-4 mr-2 group-hover:-translate-x-0.5 transition-transform' />
161
+ Log Out
162
+ </button>
163
+ </div>
164
+
165
+ </div>
166
+ </main>
167
+ );
168
+ }
@@ -0,0 +1,141 @@
1
+ import * as React from 'react';
2
+ import { useWpAuth, useWpUser } from '@forgewp/auth';
3
+ import { useWpPageLink, useLocation } from '@forgewp/react';
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 user = useWpUser();
24
+ const [_, setLocation] = useLocation();
25
+ const [emailOrUsername, setEmailOrUsername] = React.useState('');
26
+ const loginUrl = useWpPageLink('login-page', '/login');
27
+ const dashboardUrl = useWpPageLink('account-page', '/account');
28
+ const [success, setSuccess] = React.useState(false);
29
+ const [localError, setLocalError] = React.useState<string | null>(null);
30
+ const [submitting, setSubmitting] = React.useState(false);
31
+
32
+ React.useEffect(() => {
33
+ if (user) {
34
+ setLocation(dashboardUrl);
35
+ }
36
+ }, [user, setLocation, dashboardUrl]);
37
+
38
+ const handleSubmit = async (e: React.FormEvent) => {
39
+ e.preventDefault();
40
+ setLocalError(null);
41
+ const input = emailOrUsername.trim();
42
+ if (!input) {
43
+ setLocalError('Please enter your username or email address.');
44
+ return;
45
+ }
46
+
47
+ setSubmitting(true);
48
+ try {
49
+ const ok = await forgotPassword(input);
50
+ if (ok) {
51
+ setSuccess(true);
52
+ }
53
+ } catch (err: any) {
54
+ setLocalError(err.message || 'An unexpected error occurred.');
55
+ } finally {
56
+ setSubmitting(false);
57
+ }
58
+ };
59
+
60
+ if (initializing) {
61
+ return (
62
+ <div className='flex flex-col items-center justify-center p-8 min-h-[300px]'>
63
+ <div className='w-12 h-12 border-4 border-primary border-t-transparent rounded-full animate-spin'></div>
64
+ <p className='text-slate-500 font-mono text-sm mt-4'>
65
+ Checking session...
66
+ </p>
67
+ </div>
68
+ );
69
+ }
70
+
71
+ return (
72
+ <Card>
73
+ <CardHeader>
74
+ <CardTitle>{success ? 'Check Your Email' : 'Forgot Password?'}</CardTitle>
75
+ <CardDescription>
76
+ {success
77
+ ? "If the account exists, we have sent a reset password link."
78
+ : "Enter your username or email address below and we'll send you a link to reset your password."}
79
+ </CardDescription>
80
+ </CardHeader>
81
+
82
+ <CardContent className="px-8 py-4">
83
+ {success ? (
84
+ <div className="text-zinc-600 text-sm leading-relaxed text-center">
85
+ <p className="mb-4">
86
+ We have sent instructions to reset your password.
87
+ </p>
88
+ <div className="bg-zinc-50 border border-zinc-100 rounded-lg p-3 text-xs text-zinc-500 text-left font-mono mb-4">
89
+ <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.
90
+ </div>
91
+ <button
92
+ onClick={() => setSuccess(false)}
93
+ className="text-primary hover:underline text-sm font-medium cursor-pointer"
94
+ >
95
+ Didn&apos;t receive the email? Try again
96
+ </button>
97
+ </div>
98
+ ) : (
99
+ <form onSubmit={handleSubmit}>
100
+ <FieldGroup>
101
+ {(localError || error) && (
102
+ <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">
103
+ <AlertTriangleIcon className="h-4 w-4 shrink-0 mt-0.5" />
104
+ <span>{localError || error}</span>
105
+ </div>
106
+ )}
107
+ <Field>
108
+ <FieldLabel htmlFor="emailOrUsername">Username or Email Address</FieldLabel>
109
+ <Input
110
+ id="emailOrUsername"
111
+ type="text"
112
+ placeholder="Enter username or email"
113
+ value={emailOrUsername}
114
+ onChange={(e) => setEmailOrUsername(e.target.value)}
115
+ disabled={submitting}
116
+ required
117
+ />
118
+ </Field>
119
+ <Field>
120
+ <Button type="submit" disabled={submitting} className="w-full cursor-pointer">
121
+ {submitting ? 'Sending link...' : 'Send Reset Link'}
122
+ </Button>
123
+ </Field>
124
+ </FieldGroup>
125
+ </form>
126
+ )}
127
+ </CardContent>
128
+
129
+ <CardFooter className="px-8 pb-8 pt-4 flex flex-col gap-2">
130
+ <Button
131
+ variant="outline"
132
+ className="w-full cursor-pointer hover:bg-zinc-50 border-zinc-200 flex items-center justify-center gap-2"
133
+ onClick={() => setLocation(loginUrl)}
134
+ >
135
+ <ArrowLeftIcon className="h-4 w-4" />
136
+ Return to Sign In
137
+ </Button>
138
+ </CardFooter>
139
+ </Card>
140
+ );
141
+ }