opacacms 0.1.1 → 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 (212) hide show
  1. package/package.json +36 -1
  2. package/bun.lock +0 -34
  3. package/global.d.ts +0 -11
  4. package/src/admin/api-client.ts +0 -63
  5. package/src/admin/auth-client.ts +0 -40
  6. package/src/admin/custom-field.ts +0 -179
  7. package/src/admin/index.ts +0 -15
  8. package/src/admin/react.tsx +0 -72
  9. package/src/admin/router.ts +0 -9
  10. package/src/admin/stores/admin-queries.ts +0 -121
  11. package/src/admin/stores/auth.ts +0 -61
  12. package/src/admin/stores/column-visibility.ts +0 -67
  13. package/src/admin/stores/config.ts +0 -15
  14. package/src/admin/stores/media.ts +0 -95
  15. package/src/admin/stores/query.ts +0 -13
  16. package/src/admin/stores/ui.ts +0 -29
  17. package/src/admin/ui/admin-client.tsx +0 -283
  18. package/src/admin/ui/admin-layout.tsx +0 -276
  19. package/src/admin/ui/components/ColumnVisibilityToggle.tsx +0 -141
  20. package/src/admin/ui/components/DataDetailSheet.tsx +0 -141
  21. package/src/admin/ui/components/DataDetailView.tsx +0 -175
  22. package/src/admin/ui/components/Table.tsx +0 -67
  23. package/src/admin/ui/components/fields/ArrayField.tsx +0 -166
  24. package/src/admin/ui/components/fields/BlocksField.tsx +0 -202
  25. package/src/admin/ui/components/fields/BooleanField.tsx +0 -50
  26. package/src/admin/ui/components/fields/CollapsibleField.tsx +0 -75
  27. package/src/admin/ui/components/fields/DateField.tsx +0 -45
  28. package/src/admin/ui/components/fields/FileField.tsx +0 -322
  29. package/src/admin/ui/components/fields/GroupField.tsx +0 -50
  30. package/src/admin/ui/components/fields/JoinField.tsx +0 -23
  31. package/src/admin/ui/components/fields/NumberField.tsx +0 -46
  32. package/src/admin/ui/components/fields/RadioField.tsx +0 -62
  33. package/src/admin/ui/components/fields/RelationshipField.tsx +0 -278
  34. package/src/admin/ui/components/fields/RowField.tsx +0 -40
  35. package/src/admin/ui/components/fields/SelectField.tsx +0 -59
  36. package/src/admin/ui/components/fields/TabsField.tsx +0 -101
  37. package/src/admin/ui/components/fields/TextAreaField.tsx +0 -54
  38. package/src/admin/ui/components/fields/TextField.tsx +0 -49
  39. package/src/admin/ui/components/fields/VirtualField.tsx +0 -53
  40. package/src/admin/ui/components/fields/index.tsx +0 -371
  41. package/src/admin/ui/components/fields/richtext-editor/index.tsx +0 -211
  42. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageComponent.tsx +0 -142
  43. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageNode.tsx +0 -95
  44. package/src/admin/ui/components/fields/richtext-editor/plugins/ComponentPickerPlugin.tsx +0 -226
  45. package/src/admin/ui/components/fields/richtext-editor/plugins/EditableSyncPlugin.tsx +0 -16
  46. package/src/admin/ui/components/fields/richtext-editor/plugins/NotionToolbarPlugin.tsx +0 -184
  47. package/src/admin/ui/components/fields/richtext-editor/plugins/SimpleToolbarPlugin.tsx +0 -240
  48. package/src/admin/ui/components/fields/richtext-editor/plugins/ValueSyncPlugin.tsx +0 -40
  49. package/src/admin/ui/components/fields/utils.ts +0 -1
  50. package/src/admin/ui/components/link.tsx +0 -41
  51. package/src/admin/ui/components/media/AssetManagerModal.tsx +0 -334
  52. package/src/admin/ui/components/toast.tsx +0 -72
  53. package/src/admin/ui/components/ui/accordion.tsx +0 -51
  54. package/src/admin/ui/components/ui/alert-dialog.tsx +0 -98
  55. package/src/admin/ui/components/ui/blocks.tsx +0 -32
  56. package/src/admin/ui/components/ui/breadcrumbs.tsx +0 -59
  57. package/src/admin/ui/components/ui/button.tsx +0 -26
  58. package/src/admin/ui/components/ui/collapsible.tsx +0 -124
  59. package/src/admin/ui/components/ui/dialog.tsx +0 -79
  60. package/src/admin/ui/components/ui/group.tsx +0 -20
  61. package/src/admin/ui/components/ui/index.ts +0 -17
  62. package/src/admin/ui/components/ui/input.tsx +0 -12
  63. package/src/admin/ui/components/ui/join.tsx +0 -53
  64. package/src/admin/ui/components/ui/label.tsx +0 -11
  65. package/src/admin/ui/components/ui/radio-group.tsx +0 -75
  66. package/src/admin/ui/components/ui/relationship-detail-sheet.tsx +0 -122
  67. package/src/admin/ui/components/ui/relationship.tsx +0 -58
  68. package/src/admin/ui/components/ui/scroll-area.tsx +0 -19
  69. package/src/admin/ui/components/ui/select.tsx +0 -187
  70. package/src/admin/ui/components/ui/separator.tsx +0 -21
  71. package/src/admin/ui/components/ui/sheet.tsx +0 -106
  72. package/src/admin/ui/components/ui/tabs.tsx +0 -116
  73. package/src/admin/ui/components/ui/utils.ts +0 -3
  74. package/src/admin/ui/hooks/use-debounce.ts +0 -15
  75. package/src/admin/ui/styles/_locale-switcher.scss +0 -33
  76. package/src/admin/ui/styles/accordion.scss +0 -60
  77. package/src/admin/ui/styles/animations.scss +0 -41
  78. package/src/admin/ui/styles/asset-manager.scss +0 -547
  79. package/src/admin/ui/styles/badge.scss +0 -13
  80. package/src/admin/ui/styles/base.scss +0 -22
  81. package/src/admin/ui/styles/button.scss +0 -161
  82. package/src/admin/ui/styles/card.scss +0 -13
  83. package/src/admin/ui/styles/collapsible.scss +0 -75
  84. package/src/admin/ui/styles/data-detail.scss +0 -92
  85. package/src/admin/ui/styles/dialog.scss +0 -102
  86. package/src/admin/ui/styles/empty-state.scss +0 -22
  87. package/src/admin/ui/styles/group.scss +0 -19
  88. package/src/admin/ui/styles/index.scss +0 -33
  89. package/src/admin/ui/styles/input.scss +0 -80
  90. package/src/admin/ui/styles/label.scss +0 -12
  91. package/src/admin/ui/styles/layout.scss +0 -56
  92. package/src/admin/ui/styles/lexical.scss +0 -469
  93. package/src/admin/ui/styles/loading.scss +0 -102
  94. package/src/admin/ui/styles/media-registry.scss +0 -597
  95. package/src/admin/ui/styles/pagination.scss +0 -20
  96. package/src/admin/ui/styles/radio-group.scss +0 -66
  97. package/src/admin/ui/styles/row.scss +0 -17
  98. package/src/admin/ui/styles/scrollbar.scss +0 -36
  99. package/src/admin/ui/styles/select.scss +0 -121
  100. package/src/admin/ui/styles/separator.scss +0 -14
  101. package/src/admin/ui/styles/sheet.scss +0 -152
  102. package/src/admin/ui/styles/sidebar.scss +0 -148
  103. package/src/admin/ui/styles/switch.scss +0 -59
  104. package/src/admin/ui/styles/table.scss +0 -207
  105. package/src/admin/ui/styles/tabs.scss +0 -62
  106. package/src/admin/ui/styles/toast.scss +0 -45
  107. package/src/admin/ui/styles/variables.scss +0 -24
  108. package/src/admin/ui/views/collection-list-view.tsx +0 -720
  109. package/src/admin/ui/views/dashboard-view.tsx +0 -263
  110. package/src/admin/ui/views/document-edit-view.tsx +0 -384
  111. package/src/admin/ui/views/global-edit-view.tsx +0 -226
  112. package/src/admin/ui/views/init-view.tsx +0 -182
  113. package/src/admin/ui/views/login-view.tsx +0 -123
  114. package/src/admin/ui/views/media-registry-view.tsx +0 -1104
  115. package/src/admin/ui/views/settings-view.tsx +0 -729
  116. package/src/admin/webcomponent.tsx +0 -15
  117. package/src/auth/index.ts +0 -194
  118. package/src/auth/migrations.ts +0 -87
  119. package/src/auth/premissions.ts +0 -46
  120. package/src/cli/commands/generate-types.ts +0 -116
  121. package/src/cli/commands/init.ts +0 -95
  122. package/src/cli/commands/migrate-commands.ts +0 -160
  123. package/src/cli/commands/seed-command.ts +0 -11
  124. package/src/cli/d1-mock.ts +0 -101
  125. package/src/cli/index.test.ts +0 -84
  126. package/src/cli/index.ts +0 -183
  127. package/src/cli/r2-mock.ts +0 -217
  128. package/src/cli/seeding.ts +0 -409
  129. package/src/client.ts +0 -181
  130. package/src/config-utils.ts +0 -102
  131. package/src/config.ts +0 -49
  132. package/src/db/adapter.ts +0 -53
  133. package/src/db/better-sqlite.ts +0 -630
  134. package/src/db/bun-sqlite.ts +0 -646
  135. package/src/db/d1.ts +0 -711
  136. package/src/db/index.ts +0 -2
  137. package/src/db/kysely/data-mapper.ts +0 -142
  138. package/src/db/kysely/field-mapper.ts +0 -148
  139. package/src/db/kysely/migration-generator.ts +0 -223
  140. package/src/db/kysely/query-builder.ts +0 -92
  141. package/src/db/kysely/schema-builder.ts +0 -439
  142. package/src/db/kysely/sql-utils.ts +0 -13
  143. package/src/db/migration.ts +0 -40
  144. package/src/db/postgres.ts +0 -621
  145. package/src/db/sqlite.ts +0 -658
  146. package/src/db/system-schema.ts +0 -121
  147. package/src/index.ts +0 -11
  148. package/src/runtimes/README.md +0 -59
  149. package/src/runtimes/bun.ts +0 -49
  150. package/src/runtimes/cloudflare-workers.ts +0 -38
  151. package/src/runtimes/next.ts +0 -26
  152. package/src/runtimes/node.ts +0 -52
  153. package/src/schema/collection.ts +0 -184
  154. package/src/schema/fields/base.ts +0 -164
  155. package/src/schema/fields/index.ts +0 -427
  156. package/src/schema/global.ts +0 -145
  157. package/src/schema/index.ts +0 -4
  158. package/src/schema/infer.ts +0 -72
  159. package/src/server/admin-router.ts +0 -20
  160. package/src/server/admin.ts +0 -142
  161. package/src/server/assets.ts +0 -306
  162. package/src/server/collection-router.ts +0 -55
  163. package/src/server/handlers.ts +0 -722
  164. package/src/server/middlewares/admin.ts +0 -27
  165. package/src/server/middlewares/auth.ts +0 -89
  166. package/src/server/middlewares/context.ts +0 -17
  167. package/src/server/middlewares/cors.ts +0 -24
  168. package/src/server/middlewares/database-init.ts +0 -74
  169. package/src/server/middlewares/rate-limit.ts +0 -71
  170. package/src/server/router.ts +0 -47
  171. package/src/server/setup-middlewares.ts +0 -58
  172. package/src/server/system-router.ts +0 -35
  173. package/src/server.ts +0 -9
  174. package/src/storage/adapters/cloudflare-r2.ts +0 -136
  175. package/src/storage/adapters/local.ts +0 -146
  176. package/src/storage/adapters/s3.ts +0 -186
  177. package/src/storage/errors.ts +0 -46
  178. package/src/storage/index.ts +0 -6
  179. package/src/storage/types.ts +0 -39
  180. package/src/types.ts +0 -605
  181. package/src/utils/lexical.ts +0 -37
  182. package/src/utils/logger.ts +0 -73
  183. package/src/validation.ts +0 -429
  184. package/src/validator.ts +0 -179
  185. package/test/admin-custom-field.test.ts +0 -162
  186. package/test/admin-react-field.test.tsx +0 -134
  187. package/test/api-features.test.ts +0 -78
  188. package/test/api.test.ts +0 -178
  189. package/test/auth.test.ts +0 -62
  190. package/test/cli-integration.test.ts +0 -148
  191. package/test/cli.test.ts +0 -25
  192. package/test/db/postgres.test.ts +0 -95
  193. package/test/db/sqlite-filter.test.ts +0 -53
  194. package/test/db/sqlite.test.ts +0 -82
  195. package/test/engine-features.test.ts +0 -79
  196. package/test/globals.test.ts +0 -74
  197. package/test/integration-tmp/db-app/opacacms.config.ts +0 -15
  198. package/test/integration-tmp/my-sqlite-app/opacacms.config.ts +0 -25
  199. package/test/integration-tmp/my-test-app/index.ts +0 -8
  200. package/test/integration-tmp/my-test-app/opacacms.config.ts +0 -16
  201. package/test/integration-tmp/my-test-app/package.json +0 -12
  202. package/test/populate.test.ts +0 -79
  203. package/test/runtimes.test.ts +0 -43
  204. package/test/schema-builder.test.ts +0 -107
  205. package/test/schema-features.test.ts +0 -63
  206. package/test/seeding.test.ts +0 -68
  207. package/test/storage/local.test.ts +0 -72
  208. package/test/storage/s3.test.ts +0 -60
  209. package/test/structural-data.test.ts +0 -100
  210. package/test/test-setup.ts +0 -11
  211. package/test/validation.test.ts +0 -162
  212. package/tsconfig.json +0 -42
@@ -1,67 +0,0 @@
1
- import { persistentAtom } from "@nanostores/persistent";
2
-
3
- /**
4
- * Stores column visibility preferences per collection.
5
- * Key: collection slug
6
- * Value: JSON string of string[] containing visible field names
7
- */
8
- export const $columnVisibility = persistentAtom<Record<string, string[]>>(
9
- "opaca-column-visibility",
10
- {},
11
- {
12
- encode: JSON.stringify,
13
- decode: JSON.parse,
14
- },
15
- );
16
-
17
- /**
18
- * Toggle visibility of a column in a collection
19
- */
20
- export function toggleColumnVisibility(slug: string, fieldName: string) {
21
- const current = $columnVisibility.get();
22
- const visibleColumns = current[slug] || [];
23
-
24
- const nextVisibleColumns = visibleColumns.includes(fieldName)
25
- ? visibleColumns.filter((col) => col !== fieldName)
26
- : [...visibleColumns, fieldName];
27
-
28
- $columnVisibility.set({
29
- ...current,
30
- [slug]: nextVisibleColumns,
31
- });
32
- }
33
-
34
- /**
35
- * Set visible columns for a collection
36
- */
37
- export function setVisibleColumns(slug: string, columns: string[]) {
38
- const current = $columnVisibility.get();
39
- $columnVisibility.set({
40
- ...current,
41
- [slug]: columns,
42
- });
43
- }
44
-
45
- /**
46
- * Initialize column visibility for a collection if not already set.
47
- * Uses defaultColumns from config or all available named fields.
48
- */
49
- export function initColumnVisibility(
50
- slug: string,
51
- fields: { name?: string }[],
52
- defaultColumns?: string[],
53
- ) {
54
- const current = $columnVisibility.get();
55
- if (current[slug]) return; // Already initialized
56
-
57
- // If defaultColumns is provided, use it. Otherwise use all named fields.
58
- const initialColumns =
59
- defaultColumns && defaultColumns.length > 0
60
- ? defaultColumns
61
- : fields.filter((f) => f.name).map((f) => f.name!);
62
-
63
- $columnVisibility.set({
64
- ...current,
65
- [slug]: initialColumns,
66
- });
67
- }
@@ -1,15 +0,0 @@
1
- import { atom } from "nanostores";
2
- import type { SerializableConfig } from "../../types";
3
-
4
- export const $config = atom<SerializableConfig | null>(null);
5
- export const $needsInit = atom<boolean>(false);
6
- export const $isFetchingConfig = atom<boolean>(false);
7
- export const $hasMetadataError = atom<boolean>(false);
8
-
9
- export function setConfig(config: SerializableConfig | null) {
10
- $config.set(config);
11
- }
12
-
13
- export function setNeedsInit(needs: boolean) {
14
- $needsInit.set(needs);
15
- }
@@ -1,95 +0,0 @@
1
- import { persistentAtom } from "@nanostores/persistent";
2
- import { atom, computed } from "nanostores";
3
- import { api } from "../api-client";
4
- import { createFetcherStore } from "./query";
5
-
6
- export interface AssetDoc {
7
- id: string;
8
- key: string;
9
- filename: string;
10
- originalFilename: string;
11
- original_filename?: string;
12
- mimeType: string;
13
- mime_type?: string;
14
- filesize: number;
15
- bucket: string;
16
- folder: string | null;
17
- altText: string | null;
18
- alt_text?: string | null;
19
- caption: string | null;
20
- createdAt: string;
21
- updatedAt: string;
22
- created_at?: string;
23
- updated_at?: string;
24
- url?: string;
25
- thumbnailUrl?: string;
26
- }
27
-
28
- export interface AssetRegistryData {
29
- docs: AssetDoc[];
30
- folders: { name: string; buckets: string[] }[];
31
- totalDocs: number;
32
- limit: number;
33
- page: number;
34
- totalPages: number;
35
- }
36
-
37
- // Persistent Preferences
38
- export const $mediaViewMode = persistentAtom<"grid" | "list">("opaca-media-view-mode", "grid");
39
- export const $mediaSelectedBucket = persistentAtom<string>("opaca-media-selected-bucket", "all");
40
- export const $bucketColors = persistentAtom<Record<string, string>>(
41
- "opaca-bucket-colors",
42
- {},
43
- {
44
- encode: JSON.stringify,
45
- decode: JSON.parse,
46
- },
47
- );
48
-
49
- // Ephemeral UI State
50
- export const $mediaCurrentFolder = atom<string>("");
51
- export const $mediaSearch = atom<string>("");
52
- export const $mediaPage = atom<number>(1);
53
-
54
- // Reactive fetcher based on state
55
- export const $assets = createFetcherStore<AssetRegistryData>(
56
- ["api/__system/assets", $mediaSelectedBucket, $mediaCurrentFolder, $mediaSearch, $mediaPage],
57
- {
58
- fetcher: (base, bucket, folder, search, page) => {
59
- const params = new URLSearchParams({
60
- bucket: String(bucket),
61
- folder: String(folder),
62
- search: String(search),
63
- page: String(page),
64
- limit: "20",
65
- });
66
- return api.get(`${base}?${params.toString()}`).json();
67
- },
68
- },
69
- );
70
-
71
- // Actions
72
- export const setMediaBucket = (bucket: string) => {
73
- $mediaSelectedBucket.set(bucket);
74
- $mediaCurrentFolder.set(""); // Reset folder when bucket changes to avoid cross-bucket path issues
75
- $mediaPage.set(1); // Reset page on filter change
76
- };
77
-
78
- export const setMediaFolder = (folder: string) => {
79
- $mediaCurrentFolder.set(folder);
80
- $mediaPage.set(1);
81
- };
82
-
83
- export const setMediaSearch = (search: string) => {
84
- $mediaSearch.set(search);
85
- $mediaPage.set(1);
86
- };
87
-
88
- export const setMediaPage = (page: number) => {
89
- $mediaPage.set(page);
90
- };
91
-
92
- export const setBucketColor = (bucket: string, color: string) => {
93
- const current = $bucketColors.get();
94
- $bucketColors.set({ ...current, [bucket]: color });
95
- };
@@ -1,13 +0,0 @@
1
- import { nanoquery } from "@nanostores/query";
2
- import { api } from "../api-client";
3
-
4
- export const [
5
- createFetcherStore,
6
- createMutatorStore,
7
- { invalidateKeys, revalidateKeys, mutateCache },
8
- ] = nanoquery({
9
- fetcher: (...keys) => {
10
- const url = keys.join("");
11
- return api.get(url).json();
12
- },
13
- });
@@ -1,29 +0,0 @@
1
- import { persistentAtom } from "@nanostores/persistent";
2
- import { atom } from "nanostores";
3
-
4
- export interface ToastItem {
5
- id: string;
6
- message: string;
7
- type: "success" | "error" | "info";
8
- }
9
-
10
- export type ToastType = ToastItem["type"];
11
-
12
- export const $toasts = atom<ToastItem[]>([]);
13
- export const $isSidebarCollapsed = persistentAtom<boolean>("opaca-sidebar-collapsed", false, {
14
- encode: JSON.stringify,
15
- decode: JSON.parse,
16
- });
17
-
18
- export function toggleSidebar() {
19
- $isSidebarCollapsed.set(!$isSidebarCollapsed.get());
20
- }
21
-
22
- export function notify(message: string, type: ToastItem["type"] = "success") {
23
- const id = Math.random().toString(36).substring(2, 9);
24
- $toasts.set([...$toasts.get(), { id, message, type }]);
25
- }
26
-
27
- export function clearToast(id: string) {
28
- $toasts.set($toasts.get().filter((t) => t.id !== id));
29
- }
@@ -1,283 +0,0 @@
1
- import { useStore } from '@nanostores/react';
2
- import { Loader2 } from 'lucide-react';
3
- import { useCallback, useEffect, useState } from 'react';
4
- import type { SerializableCollection, SerializableConfig } from '../../types';
5
- import { api, configureAPI } from '../api-client';
6
- import { configureAuth } from '../auth-client';
7
- import { $router } from '../router';
8
- import {
9
- $isAuthPending,
10
- $session,
11
- login,
12
- logout,
13
- syncSession,
14
- } from '../stores/auth';
15
- import { $config, $needsInit, setConfig, setNeedsInit } from '../stores/config';
16
- import { $toasts, clearToast, notify } from '../stores/ui';
17
- import { AdminLayout } from './admin-layout';
18
- import { type BreadcrumbItem, Breadcrumbs } from './components/ui/breadcrumbs';
19
- import { ToastContainer } from './components/toast';
20
- import { CollectionListView } from './views/collection-list-view';
21
- // Generic Views
22
- import { DashboardView } from './views/dashboard-view';
23
- import { DocumentEditView } from './views/document-edit-view';
24
- import { GlobalEditView } from './views/global-edit-view';
25
- import { InitView } from './views/init-view';
26
- import { LoginView } from './views/login-view';
27
- import { MediaRegistryView } from './views/media-registry-view';
28
- import { SettingsView } from './views/settings-view';
29
-
30
- export interface AdminClientProps {
31
- config: SerializableConfig | null;
32
- serverUrl: string;
33
- initialNeedsInit?: boolean;
34
- }
35
-
36
- export function AdminClient({
37
- config: initialConfig,
38
- serverUrl,
39
- initialNeedsInit,
40
- }: AdminClientProps) {
41
- const [isInitializing, setIsInitializing] = useState(true);
42
-
43
- // Sync initial props to stores and configure clients
44
- useEffect(() => {
45
- if (!serverUrl || !serverUrl.startsWith('http')) return;
46
-
47
- configureAPI(serverUrl);
48
- configureAuth(serverUrl);
49
- syncSession();
50
-
51
- const init = async () => {
52
- try {
53
- // 1. Check setup status first (Independent check)
54
- try {
55
- if (initialNeedsInit !== undefined) {
56
- setNeedsInit(initialNeedsInit);
57
- } else {
58
- const setup = await api
59
- .get('api/__admin/setup')
60
- .json<{ initialized: boolean }>();
61
- console.log('[OpacaCMS] Setup status:', setup.initialized);
62
- setNeedsInit(!setup.initialized);
63
- }
64
- } catch (setupErr) {
65
- console.warn('[OpacaCMS] Failed to check setup status:', setupErr);
66
- }
67
-
68
- // 2. Fetch metadata
69
- try {
70
- if (initialConfig) {
71
- setConfig(initialConfig);
72
- } else {
73
- const metadata = await api
74
- .get('api/__admin/metadata')
75
- .json<SerializableConfig>();
76
- setConfig(metadata);
77
- }
78
- } catch (metaErr) {
79
- console.warn(
80
- '[OpacaCMS] Metadata fetch failed (expected if not logged in):',
81
- metaErr,
82
- );
83
- }
84
- } catch (err) {
85
- console.error('[OpacaCMS] Unexpected initialization error:', err);
86
- } finally {
87
- setIsInitializing(false);
88
- }
89
- };
90
-
91
- init();
92
- }, [initialConfig, initialNeedsInit, serverUrl]);
93
-
94
- const config = useStore($config);
95
- const needsInit = useStore($needsInit);
96
- const toasts = useStore($toasts);
97
- const page = useStore($router);
98
- const session = useStore($session);
99
- const isPending = useStore($isAuthPending);
100
-
101
- const handleLogin = async (data: Record<string, string>) => {
102
- await login(data);
103
- };
104
-
105
- const handleLogout = async () => {
106
- await logout();
107
- };
108
-
109
- const onDocumentBack = useCallback((slug: string) => {
110
- $router.open(`/admin/collections/${slug}`);
111
- }, []);
112
-
113
- if (!serverUrl || !serverUrl.startsWith('http')) {
114
- return (
115
- <div className="opaca-admin">
116
- <div className="opaca-loading-screen">
117
- <div
118
- style={{ display: 'flex', alignItems: 'center', gap: '0.75rem' }}
119
- >
120
- <Loader2 size={24} className="opaca-spin" />
121
- <span style={{ fontWeight: 500 }}>
122
- Waiting for server configuration...
123
- </span>
124
- </div>
125
- </div>
126
- </div>
127
- );
128
- }
129
-
130
- if (needsInit) {
131
- return (
132
- <div className="opaca-admin">
133
- <InitView
134
- onSuccess={() => {
135
- setNeedsInit(false);
136
- notify('Welcome! System initialized successfully');
137
- }}
138
- />
139
- </div>
140
- );
141
- }
142
-
143
- if (!isPending && !session) {
144
- return (
145
- <div className="opaca-admin">
146
- <LoginView onLogin={handleLogin} />
147
- </div>
148
- );
149
- }
150
-
151
- if (isInitializing || isPending || !config) {
152
- return (
153
- <div className="opaca-admin">
154
- <div className="opaca-loading-screen">
155
- <div
156
- style={{ display: 'flex', alignItems: 'center', gap: '0.75rem' }}
157
- >
158
- <svg
159
- className="opaca-spin"
160
- width="24"
161
- height="24"
162
- viewBox="0 0 24 24"
163
- fill="none"
164
- xmlns="http://www.w3.org/2000/svg"
165
- >
166
- <title>Loading</title>
167
- <path
168
- d="M12 2V6M12 18V22M6 12H2M22 12H18M18.36 5.64L15.53 8.47M8.47 15.53L5.64 18.36M18.36 18.36L15.53 15.53M8.47 8.47L5.64 5.64"
169
- stroke="currentColor"
170
- strokeWidth="2"
171
- strokeLinecap="round"
172
- />
173
- </svg>
174
- <span style={{ fontWeight: 500 }}>Loading OpacaCMS...</span>
175
- </div>
176
- </div>
177
- </div>
178
- );
179
- }
180
-
181
- // Build breadcrumbs based on route
182
- const breadcrumbs: BreadcrumbItem[] = [];
183
- if (page) {
184
- if (page.route === 'collections') {
185
- breadcrumbs.push({ label: 'Collections' });
186
- const slug = page.params.slug;
187
- const col = config.collections.find((c) => c.slug === slug);
188
- breadcrumbs.push({
189
- label: col?.label || slug.charAt(0).toUpperCase() + slug.slice(1),
190
- });
191
- } else if (page.route === 'document') {
192
- breadcrumbs.push({ label: 'Collections' });
193
- const slug = page.params.slug;
194
- const col = config.collections.find((c) => c.slug === slug);
195
- breadcrumbs.push({
196
- label: col?.label || slug.charAt(0).toUpperCase() + slug.slice(1),
197
- href: `/admin/collections/${slug}`,
198
- });
199
- breadcrumbs.push({
200
- label: page.params.id === 'create' ? 'Create' : 'Edit',
201
- });
202
- } else if (page.route === 'globals') {
203
- breadcrumbs.push({ label: 'Globals' });
204
- const slug = page.params.slug;
205
- breadcrumbs.push({ label: slug.charAt(0).toUpperCase() + slug.slice(1) });
206
- } else if (page.route === 'settings') {
207
- breadcrumbs.push({ label: 'Settings' });
208
- }
209
- }
210
-
211
- const renderView = () => {
212
- if (!page || page.route === 'dashboard') {
213
- return <DashboardView config={config} user={session?.user} />;
214
- }
215
-
216
- if (page.route === 'collections') {
217
- const slug = page.params.slug;
218
- const collection = config.collections.find(
219
- (c: SerializableCollection) => c.slug === slug,
220
- );
221
- if (!collection) return <div>Not Found</div>;
222
-
223
- // `_opaca_assets` is always treated as the media registry view, regardless of apiPath
224
- if (collection.slug === '_opaca_assets') {
225
- return <MediaRegistryView collection={collection} config={config} />;
226
- }
227
-
228
- return <CollectionListView collection={collection} />;
229
- }
230
-
231
- if (page.route === 'document') {
232
- const { slug, id } = page.params;
233
- const collection = config.collections.find(
234
- (c: SerializableCollection) => c.slug === slug,
235
- );
236
- if (!collection) return <div>Not Found</div>;
237
- return (
238
- <DocumentEditView
239
- collection={collection}
240
- id={id}
241
- onBack={() => onDocumentBack(slug)}
242
- />
243
- );
244
- }
245
-
246
- if (page.route === 'globals') {
247
- const slug = page.params.slug;
248
- const globalConfig = config.globals?.find((g) => g.slug === slug);
249
- if (!globalConfig) return <div>Not Found</div>;
250
- return (
251
- <GlobalEditView
252
- global={globalConfig}
253
- onBack={() => $router.open('/admin')}
254
- />
255
- );
256
- }
257
-
258
- if (page.route === 'settings') {
259
- return <SettingsView config={config} />;
260
- }
261
-
262
- return <div>404</div>;
263
- };
264
-
265
- return (
266
- <>
267
- <AdminLayout config={config} user={session?.user} onLogout={handleLogout}>
268
- <div
269
- style={{
270
- maxWidth: '70vw',
271
- margin: '0 auto',
272
- width: '100%',
273
- paddingBottom: '4rem',
274
- }}
275
- >
276
- {breadcrumbs.length > 0 && <Breadcrumbs items={breadcrumbs} />}
277
- {renderView()}
278
- </div>
279
- </AdminLayout>
280
- <ToastContainer toasts={toasts} onClear={clearToast} />
281
- </>
282
- );
283
- }