opacacms 0.1.0 → 0.1.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 (247) hide show
  1. package/dist/admin/index.js +49 -0
  2. package/dist/{chunk-2zm8cy1w.js → admin/webcomponent.js} +116 -168
  3. package/dist/{chunk-6dhs73zq.js → chunk-2yz1nsxs.js} +1 -1
  4. package/dist/chunk-fa5mg0hr.js +96 -0
  5. package/dist/{chunk-kwp83w8b.js → chunk-m09hahe2.js} +7 -7
  6. package/dist/{chunk-hmhcense.js → chunk-ry15hke8.js} +253 -4
  7. package/dist/chunk-vtvqfhgy.js +2442 -0
  8. package/dist/{chunk-f3nvxn63.js → chunk-y8hc6nm4.js} +1 -1
  9. package/dist/{src/cli → cli}/index.js +10 -10
  10. package/dist/{src/client.js → client.js} +2 -2
  11. package/dist/{src/db → db}/bun-sqlite.js +10 -10
  12. package/dist/{src/db → db}/d1.js +8 -8
  13. package/dist/db/index.d.ts +2 -0
  14. package/dist/db/index.js +7 -0
  15. package/dist/db/migration.d.ts +39 -0
  16. package/dist/{src/db → db}/postgres.js +10 -10
  17. package/dist/{src/db → db}/sqlite.js +8 -8
  18. package/dist/index.d.ts +0 -2
  19. package/dist/index.js +13 -0
  20. package/dist/{src/runtimes → runtimes}/bun.js +5 -6
  21. package/dist/{src/runtimes → runtimes}/cloudflare-workers.js +5 -6
  22. package/dist/{src/runtimes → runtimes}/next.js +5 -6
  23. package/dist/{src/runtimes → runtimes}/node.js +5 -6
  24. package/dist/{src/server.js → server.js} +7 -8
  25. package/dist/storage/index.d.ts +0 -3
  26. package/dist/storage/index.js +35 -0
  27. package/dist/types.d.ts +5 -2
  28. package/package.json +161 -39
  29. package/bun.lock +0 -34
  30. package/dist/api.d.ts +0 -6
  31. package/dist/chunk-8gkhn1d4.js +0 -309
  32. package/dist/chunk-dy5t83hr.js +0 -261
  33. package/dist/src/admin/index.js +0 -176
  34. package/dist/src/admin/webcomponent.js +0 -19
  35. package/dist/src/api.js +0 -27
  36. package/dist/src/index.js +0 -20
  37. package/dist/src/storage/index.js +0 -355
  38. package/global.d.ts +0 -11
  39. package/src/admin/api-client.ts +0 -63
  40. package/src/admin/auth-client.ts +0 -40
  41. package/src/admin/custom-field.ts +0 -179
  42. package/src/admin/index.ts +0 -15
  43. package/src/admin/react.tsx +0 -72
  44. package/src/admin/router.ts +0 -9
  45. package/src/admin/stores/admin-queries.ts +0 -121
  46. package/src/admin/stores/auth.ts +0 -61
  47. package/src/admin/stores/column-visibility.ts +0 -67
  48. package/src/admin/stores/config.ts +0 -15
  49. package/src/admin/stores/media.ts +0 -95
  50. package/src/admin/stores/query.ts +0 -13
  51. package/src/admin/stores/ui.ts +0 -29
  52. package/src/admin/ui/admin-client.tsx +0 -283
  53. package/src/admin/ui/admin-layout.tsx +0 -276
  54. package/src/admin/ui/components/ColumnVisibilityToggle.tsx +0 -141
  55. package/src/admin/ui/components/DataDetailSheet.tsx +0 -141
  56. package/src/admin/ui/components/DataDetailView.tsx +0 -175
  57. package/src/admin/ui/components/Table.tsx +0 -67
  58. package/src/admin/ui/components/fields/ArrayField.tsx +0 -166
  59. package/src/admin/ui/components/fields/BlocksField.tsx +0 -202
  60. package/src/admin/ui/components/fields/BooleanField.tsx +0 -50
  61. package/src/admin/ui/components/fields/CollapsibleField.tsx +0 -75
  62. package/src/admin/ui/components/fields/DateField.tsx +0 -45
  63. package/src/admin/ui/components/fields/FileField.tsx +0 -322
  64. package/src/admin/ui/components/fields/GroupField.tsx +0 -50
  65. package/src/admin/ui/components/fields/JoinField.tsx +0 -23
  66. package/src/admin/ui/components/fields/NumberField.tsx +0 -46
  67. package/src/admin/ui/components/fields/RadioField.tsx +0 -62
  68. package/src/admin/ui/components/fields/RelationshipField.tsx +0 -278
  69. package/src/admin/ui/components/fields/RowField.tsx +0 -40
  70. package/src/admin/ui/components/fields/SelectField.tsx +0 -59
  71. package/src/admin/ui/components/fields/TabsField.tsx +0 -101
  72. package/src/admin/ui/components/fields/TextAreaField.tsx +0 -54
  73. package/src/admin/ui/components/fields/TextField.tsx +0 -49
  74. package/src/admin/ui/components/fields/VirtualField.tsx +0 -53
  75. package/src/admin/ui/components/fields/index.tsx +0 -371
  76. package/src/admin/ui/components/fields/richtext-editor/index.tsx +0 -211
  77. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageComponent.tsx +0 -142
  78. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageNode.tsx +0 -95
  79. package/src/admin/ui/components/fields/richtext-editor/plugins/ComponentPickerPlugin.tsx +0 -226
  80. package/src/admin/ui/components/fields/richtext-editor/plugins/EditableSyncPlugin.tsx +0 -16
  81. package/src/admin/ui/components/fields/richtext-editor/plugins/NotionToolbarPlugin.tsx +0 -184
  82. package/src/admin/ui/components/fields/richtext-editor/plugins/SimpleToolbarPlugin.tsx +0 -240
  83. package/src/admin/ui/components/fields/richtext-editor/plugins/ValueSyncPlugin.tsx +0 -40
  84. package/src/admin/ui/components/fields/utils.ts +0 -1
  85. package/src/admin/ui/components/link.tsx +0 -41
  86. package/src/admin/ui/components/media/AssetManagerModal.tsx +0 -334
  87. package/src/admin/ui/components/toast.tsx +0 -72
  88. package/src/admin/ui/components/ui/accordion.tsx +0 -51
  89. package/src/admin/ui/components/ui/alert-dialog.tsx +0 -98
  90. package/src/admin/ui/components/ui/blocks.tsx +0 -32
  91. package/src/admin/ui/components/ui/breadcrumbs.tsx +0 -59
  92. package/src/admin/ui/components/ui/button.tsx +0 -26
  93. package/src/admin/ui/components/ui/collapsible.tsx +0 -124
  94. package/src/admin/ui/components/ui/dialog.tsx +0 -79
  95. package/src/admin/ui/components/ui/group.tsx +0 -20
  96. package/src/admin/ui/components/ui/index.ts +0 -17
  97. package/src/admin/ui/components/ui/input.tsx +0 -12
  98. package/src/admin/ui/components/ui/join.tsx +0 -53
  99. package/src/admin/ui/components/ui/label.tsx +0 -11
  100. package/src/admin/ui/components/ui/radio-group.tsx +0 -75
  101. package/src/admin/ui/components/ui/relationship-detail-sheet.tsx +0 -122
  102. package/src/admin/ui/components/ui/relationship.tsx +0 -58
  103. package/src/admin/ui/components/ui/scroll-area.tsx +0 -19
  104. package/src/admin/ui/components/ui/select.tsx +0 -187
  105. package/src/admin/ui/components/ui/separator.tsx +0 -21
  106. package/src/admin/ui/components/ui/sheet.tsx +0 -106
  107. package/src/admin/ui/components/ui/tabs.tsx +0 -116
  108. package/src/admin/ui/components/ui/utils.ts +0 -3
  109. package/src/admin/ui/hooks/use-debounce.ts +0 -15
  110. package/src/admin/ui/styles/_locale-switcher.scss +0 -33
  111. package/src/admin/ui/styles/accordion.scss +0 -60
  112. package/src/admin/ui/styles/animations.scss +0 -41
  113. package/src/admin/ui/styles/asset-manager.scss +0 -547
  114. package/src/admin/ui/styles/badge.scss +0 -13
  115. package/src/admin/ui/styles/base.scss +0 -22
  116. package/src/admin/ui/styles/button.scss +0 -161
  117. package/src/admin/ui/styles/card.scss +0 -13
  118. package/src/admin/ui/styles/collapsible.scss +0 -75
  119. package/src/admin/ui/styles/data-detail.scss +0 -92
  120. package/src/admin/ui/styles/dialog.scss +0 -102
  121. package/src/admin/ui/styles/empty-state.scss +0 -22
  122. package/src/admin/ui/styles/group.scss +0 -19
  123. package/src/admin/ui/styles/index.scss +0 -33
  124. package/src/admin/ui/styles/input.scss +0 -80
  125. package/src/admin/ui/styles/label.scss +0 -12
  126. package/src/admin/ui/styles/layout.scss +0 -56
  127. package/src/admin/ui/styles/lexical.scss +0 -469
  128. package/src/admin/ui/styles/loading.scss +0 -102
  129. package/src/admin/ui/styles/media-registry.scss +0 -597
  130. package/src/admin/ui/styles/pagination.scss +0 -20
  131. package/src/admin/ui/styles/radio-group.scss +0 -66
  132. package/src/admin/ui/styles/row.scss +0 -17
  133. package/src/admin/ui/styles/scrollbar.scss +0 -36
  134. package/src/admin/ui/styles/select.scss +0 -121
  135. package/src/admin/ui/styles/separator.scss +0 -14
  136. package/src/admin/ui/styles/sheet.scss +0 -152
  137. package/src/admin/ui/styles/sidebar.scss +0 -148
  138. package/src/admin/ui/styles/switch.scss +0 -59
  139. package/src/admin/ui/styles/table.scss +0 -207
  140. package/src/admin/ui/styles/tabs.scss +0 -62
  141. package/src/admin/ui/styles/toast.scss +0 -45
  142. package/src/admin/ui/styles/variables.scss +0 -24
  143. package/src/admin/ui/views/collection-list-view.tsx +0 -720
  144. package/src/admin/ui/views/dashboard-view.tsx +0 -263
  145. package/src/admin/ui/views/document-edit-view.tsx +0 -384
  146. package/src/admin/ui/views/global-edit-view.tsx +0 -226
  147. package/src/admin/ui/views/init-view.tsx +0 -182
  148. package/src/admin/ui/views/login-view.tsx +0 -123
  149. package/src/admin/ui/views/media-registry-view.tsx +0 -1104
  150. package/src/admin/ui/views/settings-view.tsx +0 -729
  151. package/src/admin/webcomponent.tsx +0 -15
  152. package/src/api.ts +0 -9
  153. package/src/auth/index.ts +0 -194
  154. package/src/auth/migrations.ts +0 -87
  155. package/src/auth/premissions.ts +0 -46
  156. package/src/cli/commands/generate-types.ts +0 -116
  157. package/src/cli/commands/init.ts +0 -95
  158. package/src/cli/commands/migrate-commands.ts +0 -160
  159. package/src/cli/commands/seed-command.ts +0 -11
  160. package/src/cli/d1-mock.ts +0 -101
  161. package/src/cli/index.test.ts +0 -84
  162. package/src/cli/index.ts +0 -183
  163. package/src/cli/r2-mock.ts +0 -217
  164. package/src/cli/seeding.ts +0 -405
  165. package/src/client.ts +0 -181
  166. package/src/config-utils.ts +0 -102
  167. package/src/config.ts +0 -49
  168. package/src/db/adapter.ts +0 -53
  169. package/src/db/better-sqlite.ts +0 -630
  170. package/src/db/bun-sqlite.ts +0 -646
  171. package/src/db/d1.ts +0 -711
  172. package/src/db/kysely/data-mapper.ts +0 -142
  173. package/src/db/kysely/field-mapper.ts +0 -148
  174. package/src/db/kysely/migration-generator.ts +0 -223
  175. package/src/db/kysely/query-builder.ts +0 -92
  176. package/src/db/kysely/schema-builder.ts +0 -439
  177. package/src/db/kysely/sql-utils.ts +0 -13
  178. package/src/db/postgres.ts +0 -621
  179. package/src/db/sqlite.ts +0 -658
  180. package/src/db/system-schema.ts +0 -121
  181. package/src/index.ts +0 -13
  182. package/src/runtimes/README.md +0 -59
  183. package/src/runtimes/bun.ts +0 -49
  184. package/src/runtimes/cloudflare-workers.ts +0 -38
  185. package/src/runtimes/next.ts +0 -26
  186. package/src/runtimes/node.ts +0 -52
  187. package/src/schema/collection.ts +0 -184
  188. package/src/schema/fields/base.ts +0 -164
  189. package/src/schema/fields/index.ts +0 -427
  190. package/src/schema/global.ts +0 -145
  191. package/src/schema/index.ts +0 -4
  192. package/src/schema/infer.ts +0 -72
  193. package/src/server/admin-router.ts +0 -20
  194. package/src/server/admin.ts +0 -142
  195. package/src/server/assets.ts +0 -306
  196. package/src/server/collection-router.ts +0 -55
  197. package/src/server/handlers.ts +0 -722
  198. package/src/server/middlewares/admin.ts +0 -27
  199. package/src/server/middlewares/auth.ts +0 -89
  200. package/src/server/middlewares/context.ts +0 -17
  201. package/src/server/middlewares/cors.ts +0 -24
  202. package/src/server/middlewares/database-init.ts +0 -74
  203. package/src/server/middlewares/rate-limit.ts +0 -71
  204. package/src/server/router.ts +0 -47
  205. package/src/server/setup-middlewares.ts +0 -58
  206. package/src/server/system-router.ts +0 -35
  207. package/src/server.ts +0 -9
  208. package/src/storage/adapters/cloudflare-r2.ts +0 -136
  209. package/src/storage/adapters/local.ts +0 -146
  210. package/src/storage/adapters/s3.ts +0 -186
  211. package/src/storage/errors.ts +0 -46
  212. package/src/storage/index.ts +0 -5
  213. package/src/storage/types.ts +0 -39
  214. package/src/types.ts +0 -577
  215. package/src/utils/lexical.ts +0 -37
  216. package/src/utils/logger.ts +0 -73
  217. package/src/validation.ts +0 -429
  218. package/src/validator.ts +0 -179
  219. package/test/admin-custom-field.test.ts +0 -162
  220. package/test/admin-react-field.test.tsx +0 -134
  221. package/test/api-features.test.ts +0 -78
  222. package/test/api.test.ts +0 -178
  223. package/test/auth.test.ts +0 -62
  224. package/test/cli-integration.test.ts +0 -146
  225. package/test/cli.test.ts +0 -25
  226. package/test/db/postgres.test.ts +0 -95
  227. package/test/db/sqlite-filter.test.ts +0 -53
  228. package/test/db/sqlite.test.ts +0 -82
  229. package/test/engine-features.test.ts +0 -79
  230. package/test/globals.test.ts +0 -74
  231. package/test/integration-tmp/db-app/opacacms.config.ts +0 -15
  232. package/test/integration-tmp/my-sqlite-app/opacacms.config.ts +0 -25
  233. package/test/integration-tmp/my-test-app/index.ts +0 -8
  234. package/test/integration-tmp/my-test-app/opacacms.config.ts +0 -16
  235. package/test/integration-tmp/my-test-app/package.json +0 -12
  236. package/test/populate.test.ts +0 -79
  237. package/test/runtimes.test.ts +0 -43
  238. package/test/schema-builder.test.ts +0 -107
  239. package/test/schema-features.test.ts +0 -63
  240. package/test/seeding.test.ts +0 -68
  241. package/test/storage/local.test.ts +0 -72
  242. package/test/storage/s3.test.ts +0 -60
  243. package/test/structural-data.test.ts +0 -100
  244. package/test/test-setup.ts +0 -11
  245. package/test/validation.test.ts +0 -162
  246. package/tsconfig.json +0 -42
  247. /package/dist/{src/admin/index.css → admin/webcomponent.css} +0 -0
@@ -1,226 +0,0 @@
1
- import { useStore } from "@nanostores/react";
2
- import { AlertCircle, Loader2, Save } from "lucide-react";
3
- import { useEffect, useState } from "react";
4
- import { $globalData, $globalQuery, $saveGlobal } from "../../stores/admin-queries";
5
- import type { ToastType } from "../../stores/ui";
6
- import { notify } from "../../stores/ui";
7
- import { FieldRenderer } from "../components/fields";
8
-
9
- export interface GlobalEditViewProps {
10
- global: {
11
- slug: string;
12
- label?: string;
13
- fields: {
14
- name?: string;
15
- label?: string;
16
- type: string;
17
- defaultValue?: unknown;
18
- required?: boolean;
19
- options?: {
20
- defaultMode?: "simple" | "notion";
21
- [key: string]: unknown;
22
- };
23
- }[];
24
- };
25
- onBack: () => void;
26
- }
27
-
28
- export function GlobalEditView({ global }: GlobalEditViewProps) {
29
- const [formData, setFormData] = useState<Record<string, unknown>>({});
30
- const [initialData, setInitialData] = useState<Record<string, unknown>>({});
31
- const [errorStatus, setErrorStatus] = useState<string | null>(null);
32
-
33
- const { data: storeData, loading, error: storeError } = useStore($globalData);
34
- const { mutate: doSave, loading: saving } = useStore($saveGlobal);
35
-
36
- const isDirty = JSON.stringify(formData) !== JSON.stringify(initialData);
37
-
38
- // Set the query slug when component mounts or slug changes
39
- useEffect(() => {
40
- $globalQuery.set(global.slug);
41
- }, [global.slug]);
42
-
43
- // Sync store data to form fields
44
- useEffect(() => {
45
- if (storeData) {
46
- const cleanData = { ...storeData };
47
- delete (cleanData as any).id;
48
- delete (cleanData as any)["createdAt"];
49
- delete (cleanData as any)["updatedAt"];
50
-
51
- // Initialize defaults if they are missing
52
- const defaults: Record<string, unknown> = { ...cleanData };
53
- if (Object.keys(cleanData).length === 0) {
54
- global.fields.forEach((f) => {
55
- if (!f.name) return; // Skip layout fields without names
56
- if (f.defaultValue !== undefined) {
57
- defaults[f.name] = f.defaultValue;
58
- } else if (f.type === "boolean") {
59
- defaults[f.name] = false;
60
- } else if (f.type === "number") {
61
- defaults[f.name] = 0;
62
- } else if (
63
- f.type === "array" ||
64
- f.type === "blocks" ||
65
- (f.type === "relationship" && (f as any).hasMany)
66
- ) {
67
- defaults[f.name] = [];
68
- } else {
69
- defaults[f.name] = "";
70
- }
71
- });
72
- }
73
-
74
- setFormData(defaults);
75
- setInitialData(defaults);
76
- setErrorStatus(null);
77
- }
78
- }, [storeData, global.fields]);
79
-
80
- // Handle errors from store or local
81
- useEffect(() => {
82
- if (storeError) {
83
- setErrorStatus("Failed to load global document.");
84
- notify("Error loading global document", "error");
85
- }
86
- }, [storeError]);
87
-
88
- const handleSubmit = async (e?: React.FormEvent) => {
89
- if (e) e.preventDefault();
90
- setErrorStatus(null);
91
-
92
- try {
93
- await doSave({ slug: global.slug, body: formData });
94
- notify("Changes saved successfully", "success");
95
- setInitialData(formData); // Reset dirty state
96
- } catch (err: unknown) {
97
- console.error(err);
98
- setErrorStatus(err instanceof Error ? err.message : "Failed to save document.");
99
- notify("Failed to save changes", "error");
100
- }
101
- };
102
-
103
- if (loading) {
104
- return (
105
- <div
106
- style={{
107
- display: "flex",
108
- alignItems: "center",
109
- gap: "0.75rem",
110
- marginTop: "2rem",
111
- padding: "0 2.5rem",
112
- }}
113
- >
114
- <Loader2 size={18} className="opaca-spin" />
115
- <span className="opaca-subtitle">Loading settings...</span>
116
- </div>
117
- );
118
- }
119
-
120
- return (
121
- <div className="opaca-admin-form">
122
- <div className="opaca-header">
123
- <div style={{ display: "flex", alignItems: "center", gap: "1rem" }}>
124
- <div>
125
- <h1 className="opaca-title">
126
- {global.label || global.slug.charAt(0).toUpperCase() + global.slug.slice(1)}
127
- </h1>
128
- <p className="opaca-subtitle">Manage global settings.</p>
129
- </div>
130
- </div>
131
- <div style={{ display: "flex", gap: "0.75rem" }}>
132
- <button
133
- type="button"
134
- onClick={() => handleSubmit()}
135
- disabled={saving}
136
- className="opaca-btn opaca-btn-primary"
137
- style={{ position: "relative" }}
138
- title="Save Changes"
139
- >
140
- {saving ? <Loader2 size={18} className="opaca-spin" /> : <Save size={18} />}
141
- Save
142
- {isDirty && !saving && (
143
- <span
144
- style={{
145
- position: "absolute",
146
- top: "-4px",
147
- right: "-4px",
148
- width: "10px",
149
- height: "10px",
150
- borderRadius: "50%",
151
- background: "var(--opaca-warning)",
152
- border: "2px solid var(--opaca-card-bg)",
153
- boxShadow: "0 1px 2px rgba(0,0,0,0.2)",
154
- }}
155
- title="Unsaved changes"
156
- />
157
- )}
158
- </button>
159
- </div>
160
- </div>
161
-
162
- {errorStatus && (
163
- <div
164
- style={{
165
- padding: "1rem",
166
- backgroundColor: "rgba(239, 68, 68, 0.1)",
167
- border: "1px solid var(--opaca-error)",
168
- color: "var(--opaca-error)",
169
- borderRadius: "var(--opaca-radius)",
170
- marginBottom: "2rem",
171
- display: "flex",
172
- alignItems: "center",
173
- gap: "0.75rem",
174
- fontSize: "0.875rem",
175
- }}
176
- >
177
- <AlertCircle size={18} />
178
- {errorStatus}
179
- </div>
180
- )}
181
-
182
- <div className="opaca-card" style={{ padding: "2.5rem" }}>
183
- <form id="opaca-doc-form" onSubmit={handleSubmit}>
184
- <div style={{ display: "grid", gap: "2rem" }}>
185
- {global.fields.map((field, index) => {
186
- const name = field.name;
187
-
188
- // Layout fields without a name
189
- if (!name) {
190
- return (
191
- <FieldRenderer
192
- key={field.name || index}
193
- field={field}
194
- value={undefined}
195
- onChange={(subName, val) => {
196
- if (typeof subName === "string") {
197
- setFormData({ ...formData, [subName]: val });
198
- } else {
199
- // Handle cases where onChange(val) is called (shouldn't happen with layout fields usually)
200
- Object.assign(formData, val);
201
- setFormData({ ...formData });
202
- }
203
- }}
204
- parentData={formData}
205
- />
206
- );
207
- }
208
-
209
- return (
210
- <FieldRenderer
211
- key={name}
212
- field={field}
213
- value={formData[name]}
214
- onChange={(val) => {
215
- setFormData({ ...formData, [name]: val });
216
- }}
217
- parentData={formData}
218
- />
219
- );
220
- })}
221
- </div>
222
- </form>
223
- </div>
224
- </div>
225
- );
226
- }
@@ -1,182 +0,0 @@
1
- import { AlertCircle, Loader2, Lock, ShieldCheck, User } from "lucide-react";
2
- import { type FormEvent, useState } from "react";
3
- import { authClient } from "../../auth-client";
4
-
5
- export interface InitViewProps {
6
- onSuccess: () => void;
7
- }
8
-
9
- export function InitView({ onSuccess }: InitViewProps) {
10
- const [email, setEmail] = useState("");
11
- const [password, setPassword] = useState("");
12
- const [confirmPassword, setConfirmPassword] = useState("");
13
- const [loading, setLoading] = useState(false);
14
- const [error, setError] = useState<string | null>(null);
15
-
16
- const handleSubmit = async (e: FormEvent) => {
17
- e.preventDefault();
18
- setLoading(true);
19
- setError(null);
20
-
21
- if (password !== confirmPassword) {
22
- setError("Passwords do not match");
23
- setLoading(false);
24
- return;
25
- }
26
-
27
- try {
28
- const res = await authClient.signUp.email({
29
- email,
30
- password,
31
- name: "Admin",
32
- });
33
-
34
- if (res.error) {
35
- throw new Error(res.error.message || "Failed to create admin user");
36
- }
37
-
38
- onSuccess();
39
- } catch (err: unknown) {
40
- console.error(err);
41
- setError(err instanceof Error ? err.message : "Initialization failed");
42
- } finally {
43
- setLoading(false);
44
- }
45
- };
46
-
47
- return (
48
- <div className="opaca-login-container">
49
- <div className="opaca-login-card">
50
- <div className="opaca-login-header">
51
- <div className="opaca-login-logo">
52
- <ShieldCheck size={24} color="white" />
53
- </div>
54
- <h1 className="opaca-title">Welcome to OpacaCMS</h1>
55
- <p className="opaca-subtitle">Create the first administrator account to get started.</p>
56
- </div>
57
-
58
- {error && (
59
- <div className="opaca-login-error">
60
- <AlertCircle size={14} />
61
- {error}
62
- </div>
63
- )}
64
-
65
- <form onSubmit={handleSubmit}>
66
- <div className="opaca-form-group">
67
- <label htmlFor="init-email" className="opaca-label">
68
- Admin Email
69
- </label>
70
- <div style={{ position: "relative" }}>
71
- <User
72
- size={14}
73
- style={{
74
- position: "absolute",
75
- left: "0.75rem",
76
- top: "50%",
77
- transform: "translateY(-50%)",
78
- color: "var(--opaca-text-dim)",
79
- }}
80
- />
81
- <input
82
- id="init-email"
83
- type="email"
84
- className="opaca-input"
85
- style={{ paddingLeft: "2.25rem" }}
86
- placeholder="admin@example.com"
87
- value={email}
88
- onChange={(e) => setEmail((e.target as HTMLInputElement).value)}
89
- required
90
- />
91
- </div>
92
- </div>
93
-
94
- <div className="opaca-form-group">
95
- <label htmlFor="init-password" className="opaca-label">
96
- Password
97
- </label>
98
- <div style={{ position: "relative" }}>
99
- <Lock
100
- size={14}
101
- style={{
102
- position: "absolute",
103
- left: "0.75rem",
104
- top: "50%",
105
- transform: "translateY(-50%)",
106
- color: "var(--opaca-text-dim)",
107
- }}
108
- />
109
- <input
110
- id="init-password"
111
- type="password"
112
- className="opaca-input"
113
- style={{ paddingLeft: "2.25rem" }}
114
- placeholder="••••••••"
115
- value={password}
116
- onChange={(e) => setPassword((e.target as HTMLInputElement).value)}
117
- required
118
- minLength={8}
119
- />
120
- </div>
121
- </div>
122
-
123
- <div className="opaca-form-group">
124
- <label htmlFor="init-confirm" className="opaca-label">
125
- Confirm Password
126
- </label>
127
- <div style={{ position: "relative" }}>
128
- <Lock
129
- size={14}
130
- style={{
131
- position: "absolute",
132
- left: "0.75rem",
133
- top: "50%",
134
- transform: "translateY(-50%)",
135
- color: "var(--opaca-text-dim)",
136
- }}
137
- />
138
- <input
139
- id="init-confirm"
140
- type="password"
141
- className="opaca-input"
142
- style={{ paddingLeft: "2.25rem" }}
143
- placeholder="••••••••"
144
- value={confirmPassword}
145
- onChange={(e) => setConfirmPassword((e.target as HTMLInputElement).value)}
146
- required
147
- minLength={8}
148
- />
149
- </div>
150
- </div>
151
-
152
- <button
153
- type="submit"
154
- className="opaca-btn opaca-btn-primary"
155
- style={{ width: "100%", marginTop: "0.5rem" }}
156
- disabled={loading}
157
- >
158
- {loading ? (
159
- <>
160
- <Loader2 className="opaca-spin" size={14} />
161
- Initializing...
162
- </>
163
- ) : (
164
- "Create Admin Account"
165
- )}
166
- </button>
167
- </form>
168
-
169
- <p
170
- className="opaca-subtitle"
171
- style={{
172
- fontSize: "0.6875rem",
173
- textAlign: "center",
174
- marginTop: "1.25rem",
175
- }}
176
- >
177
- This account will have full access to manage OpacaCMS.
178
- </p>
179
- </div>
180
- </div>
181
- );
182
- }
@@ -1,123 +0,0 @@
1
- import { AlertCircle, Loader2, Lock, User } from "lucide-react";
2
- import React, { type FormEvent, useState } from "react";
3
-
4
- export interface LoginViewProps {
5
- onLogin: (data: Record<string, string>) => Promise<void>;
6
- }
7
-
8
- export function LoginView({ onLogin }: LoginViewProps) {
9
- const [email, setEmail] = useState("");
10
- const [password, setPassword] = useState("");
11
- const [loading, setLoading] = useState(false);
12
- const [error, setError] = useState<string | null>(null);
13
-
14
- const handleSubmit = async (e: FormEvent) => {
15
- e.preventDefault();
16
- setLoading(true);
17
- setError(null);
18
-
19
- try {
20
- await onLogin({ email, password });
21
- } catch (err: unknown) {
22
- console.error(err);
23
- setError(err instanceof Error ? err.message : "Invalid email or password");
24
- } finally {
25
- setLoading(false);
26
- }
27
- };
28
-
29
- return (
30
- <div className="opaca-login-container">
31
- <div className="opaca-login-card">
32
- <div style={{ textAlign: "center", marginBottom: "1.5rem" }}>
33
- <div className="opaca-logo-circle" style={{ margin: "0 auto 1rem" }}>
34
- <Lock size={22} />
35
- </div>
36
- <h1 className="opaca-title">Admin Login</h1>
37
- <p className="opaca-subtitle">Authenticate to access the dashboard</p>
38
- </div>
39
-
40
- {error && (
41
- <div className="opaca-login-error">
42
- <AlertCircle size={14} />
43
- {error}
44
- </div>
45
- )}
46
-
47
- <form onSubmit={handleSubmit}>
48
- <div className="opaca-form-group">
49
- <label htmlFor="login-email" className="opaca-label">
50
- Email
51
- </label>
52
- <div style={{ position: "relative" }}>
53
- <User
54
- size={14}
55
- style={{
56
- position: "absolute",
57
- left: "0.75rem",
58
- top: "50%",
59
- transform: "translateY(-50%)",
60
- color: "var(--opaca-text-dim)",
61
- }}
62
- />
63
- <input
64
- id="login-email"
65
- type="email"
66
- className="opaca-input"
67
- style={{ paddingLeft: "2.25rem" }}
68
- placeholder="admin@example.com"
69
- value={email}
70
- onChange={(e) => setEmail((e.target as HTMLInputElement).value)}
71
- required
72
- />
73
- </div>
74
- </div>
75
-
76
- <div className="opaca-form-group">
77
- <label htmlFor="login-password" className="opaca-label">
78
- Password
79
- </label>
80
- <div style={{ position: "relative" }}>
81
- <Lock
82
- size={14}
83
- style={{
84
- position: "absolute",
85
- left: "0.75rem",
86
- top: "50%",
87
- transform: "translateY(-50%)",
88
- color: "var(--opaca-text-dim)",
89
- }}
90
- />
91
- <input
92
- id="login-password"
93
- type="password"
94
- className="opaca-input"
95
- style={{ paddingLeft: "2.25rem" }}
96
- placeholder="••••••••"
97
- value={password}
98
- onChange={(e) => setPassword((e.target as HTMLInputElement).value)}
99
- required
100
- />
101
- </div>
102
- </div>
103
-
104
- <button
105
- type="submit"
106
- className="opaca-btn opaca-btn-primary"
107
- style={{ width: "100%", marginTop: "0.5rem" }}
108
- disabled={loading}
109
- >
110
- {loading ? (
111
- <>
112
- <Loader2 size={14} className="opaca-spin" />
113
- Logging in...
114
- </>
115
- ) : (
116
- "Sign In"
117
- )}
118
- </button>
119
- </form>
120
- </div>
121
- </div>
122
- );
123
- }