opacacms 0.1.12 → 0.1.13

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 (217) hide show
  1. package/dist/admin/index.js +0 -4
  2. package/dist/admin/webcomponent.d.ts +0 -1
  3. package/dist/admin/webcomponent.js +0 -4
  4. package/dist/admin.css +1 -0
  5. package/package.json +8 -2
  6. package/bun.lock +0 -34
  7. package/dist/admin/index.css +0 -47
  8. package/dist/admin/webcomponent.css +0 -47
  9. package/global.d.ts +0 -11
  10. package/src/admin/api-client.ts +0 -63
  11. package/src/admin/auth-client.ts +0 -40
  12. package/src/admin/custom-field.ts +0 -179
  13. package/src/admin/index.ts +0 -15
  14. package/src/admin/react.tsx +0 -72
  15. package/src/admin/router.ts +0 -9
  16. package/src/admin/stores/admin-queries.ts +0 -121
  17. package/src/admin/stores/auth.ts +0 -61
  18. package/src/admin/stores/column-visibility.ts +0 -67
  19. package/src/admin/stores/config.ts +0 -15
  20. package/src/admin/stores/media.ts +0 -95
  21. package/src/admin/stores/query.ts +0 -13
  22. package/src/admin/stores/ui.ts +0 -29
  23. package/src/admin/ui/admin-client.tsx +0 -283
  24. package/src/admin/ui/admin-layout.tsx +0 -276
  25. package/src/admin/ui/components/ColumnVisibilityToggle.tsx +0 -141
  26. package/src/admin/ui/components/DataDetailSheet.tsx +0 -141
  27. package/src/admin/ui/components/DataDetailView.tsx +0 -175
  28. package/src/admin/ui/components/Table.tsx +0 -67
  29. package/src/admin/ui/components/fields/ArrayField.tsx +0 -166
  30. package/src/admin/ui/components/fields/BlocksField.tsx +0 -202
  31. package/src/admin/ui/components/fields/BooleanField.tsx +0 -50
  32. package/src/admin/ui/components/fields/CollapsibleField.tsx +0 -75
  33. package/src/admin/ui/components/fields/DateField.tsx +0 -45
  34. package/src/admin/ui/components/fields/FileField.tsx +0 -322
  35. package/src/admin/ui/components/fields/GroupField.tsx +0 -50
  36. package/src/admin/ui/components/fields/JoinField.tsx +0 -23
  37. package/src/admin/ui/components/fields/NumberField.tsx +0 -46
  38. package/src/admin/ui/components/fields/RadioField.tsx +0 -62
  39. package/src/admin/ui/components/fields/RelationshipField.tsx +0 -278
  40. package/src/admin/ui/components/fields/RowField.tsx +0 -40
  41. package/src/admin/ui/components/fields/SelectField.tsx +0 -59
  42. package/src/admin/ui/components/fields/TabsField.tsx +0 -101
  43. package/src/admin/ui/components/fields/TextAreaField.tsx +0 -54
  44. package/src/admin/ui/components/fields/TextField.tsx +0 -49
  45. package/src/admin/ui/components/fields/VirtualField.tsx +0 -53
  46. package/src/admin/ui/components/fields/index.tsx +0 -371
  47. package/src/admin/ui/components/fields/richtext-editor/index.tsx +0 -211
  48. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageComponent.tsx +0 -142
  49. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageNode.tsx +0 -95
  50. package/src/admin/ui/components/fields/richtext-editor/plugins/ComponentPickerPlugin.tsx +0 -226
  51. package/src/admin/ui/components/fields/richtext-editor/plugins/EditableSyncPlugin.tsx +0 -16
  52. package/src/admin/ui/components/fields/richtext-editor/plugins/NotionToolbarPlugin.tsx +0 -184
  53. package/src/admin/ui/components/fields/richtext-editor/plugins/SimpleToolbarPlugin.tsx +0 -240
  54. package/src/admin/ui/components/fields/richtext-editor/plugins/ValueSyncPlugin.tsx +0 -40
  55. package/src/admin/ui/components/fields/utils.ts +0 -1
  56. package/src/admin/ui/components/link.tsx +0 -41
  57. package/src/admin/ui/components/media/AssetManagerModal.tsx +0 -334
  58. package/src/admin/ui/components/toast.tsx +0 -72
  59. package/src/admin/ui/components/ui/accordion.tsx +0 -51
  60. package/src/admin/ui/components/ui/alert-dialog.tsx +0 -98
  61. package/src/admin/ui/components/ui/blocks.tsx +0 -32
  62. package/src/admin/ui/components/ui/breadcrumbs.tsx +0 -59
  63. package/src/admin/ui/components/ui/button.tsx +0 -26
  64. package/src/admin/ui/components/ui/collapsible.tsx +0 -124
  65. package/src/admin/ui/components/ui/dialog.tsx +0 -79
  66. package/src/admin/ui/components/ui/group.tsx +0 -20
  67. package/src/admin/ui/components/ui/index.ts +0 -17
  68. package/src/admin/ui/components/ui/input.tsx +0 -12
  69. package/src/admin/ui/components/ui/join.tsx +0 -53
  70. package/src/admin/ui/components/ui/label.tsx +0 -11
  71. package/src/admin/ui/components/ui/radio-group.tsx +0 -75
  72. package/src/admin/ui/components/ui/relationship-detail-sheet.tsx +0 -122
  73. package/src/admin/ui/components/ui/relationship.tsx +0 -58
  74. package/src/admin/ui/components/ui/scroll-area.tsx +0 -19
  75. package/src/admin/ui/components/ui/select.tsx +0 -187
  76. package/src/admin/ui/components/ui/separator.tsx +0 -21
  77. package/src/admin/ui/components/ui/sheet.tsx +0 -106
  78. package/src/admin/ui/components/ui/tabs.tsx +0 -116
  79. package/src/admin/ui/components/ui/utils.ts +0 -3
  80. package/src/admin/ui/hooks/use-debounce.ts +0 -15
  81. package/src/admin/ui/styles/_locale-switcher.scss +0 -33
  82. package/src/admin/ui/styles/accordion.scss +0 -60
  83. package/src/admin/ui/styles/animations.scss +0 -41
  84. package/src/admin/ui/styles/asset-manager.scss +0 -547
  85. package/src/admin/ui/styles/badge.scss +0 -13
  86. package/src/admin/ui/styles/base.scss +0 -22
  87. package/src/admin/ui/styles/button.scss +0 -161
  88. package/src/admin/ui/styles/card.scss +0 -13
  89. package/src/admin/ui/styles/collapsible.scss +0 -75
  90. package/src/admin/ui/styles/data-detail.scss +0 -92
  91. package/src/admin/ui/styles/dialog.scss +0 -102
  92. package/src/admin/ui/styles/empty-state.scss +0 -22
  93. package/src/admin/ui/styles/group.scss +0 -19
  94. package/src/admin/ui/styles/index.scss +0 -33
  95. package/src/admin/ui/styles/input.scss +0 -80
  96. package/src/admin/ui/styles/label.scss +0 -12
  97. package/src/admin/ui/styles/layout.scss +0 -56
  98. package/src/admin/ui/styles/lexical.scss +0 -469
  99. package/src/admin/ui/styles/loading.scss +0 -102
  100. package/src/admin/ui/styles/media-registry.scss +0 -597
  101. package/src/admin/ui/styles/pagination.scss +0 -20
  102. package/src/admin/ui/styles/radio-group.scss +0 -66
  103. package/src/admin/ui/styles/row.scss +0 -17
  104. package/src/admin/ui/styles/scrollbar.scss +0 -36
  105. package/src/admin/ui/styles/select.scss +0 -121
  106. package/src/admin/ui/styles/separator.scss +0 -14
  107. package/src/admin/ui/styles/sheet.scss +0 -152
  108. package/src/admin/ui/styles/sidebar.scss +0 -148
  109. package/src/admin/ui/styles/switch.scss +0 -59
  110. package/src/admin/ui/styles/table.scss +0 -207
  111. package/src/admin/ui/styles/tabs.scss +0 -62
  112. package/src/admin/ui/styles/toast.scss +0 -45
  113. package/src/admin/ui/styles/variables.scss +0 -24
  114. package/src/admin/ui/views/collection-list-view.tsx +0 -720
  115. package/src/admin/ui/views/dashboard-view.tsx +0 -263
  116. package/src/admin/ui/views/document-edit-view.tsx +0 -384
  117. package/src/admin/ui/views/global-edit-view.tsx +0 -226
  118. package/src/admin/ui/views/init-view.tsx +0 -182
  119. package/src/admin/ui/views/login-view.tsx +0 -123
  120. package/src/admin/ui/views/media-registry-view.tsx +0 -1104
  121. package/src/admin/ui/views/settings-view.tsx +0 -729
  122. package/src/admin/webcomponent.tsx +0 -15
  123. package/src/auth/index.ts +0 -194
  124. package/src/auth/migrations.ts +0 -87
  125. package/src/auth/premissions.ts +0 -46
  126. package/src/cli/commands/generate-types.ts +0 -116
  127. package/src/cli/commands/init.ts +0 -95
  128. package/src/cli/commands/migrate-commands.ts +0 -160
  129. package/src/cli/commands/seed-command.ts +0 -11
  130. package/src/cli/d1-mock.ts +0 -101
  131. package/src/cli/index.test.ts +0 -84
  132. package/src/cli/index.ts +0 -183
  133. package/src/cli/r2-mock.ts +0 -217
  134. package/src/cli/seeding.ts +0 -409
  135. package/src/client.ts +0 -181
  136. package/src/config-utils.ts +0 -102
  137. package/src/config.ts +0 -49
  138. package/src/db/adapter.ts +0 -53
  139. package/src/db/better-sqlite.ts +0 -657
  140. package/src/db/bun-sqlite.ts +0 -666
  141. package/src/db/d1.ts +0 -721
  142. package/src/db/index.ts +0 -10
  143. package/src/db/kysely/data-mapper.ts +0 -142
  144. package/src/db/kysely/field-mapper.ts +0 -149
  145. package/src/db/kysely/migration-generator.ts +0 -223
  146. package/src/db/kysely/query-builder.ts +0 -92
  147. package/src/db/kysely/schema-builder.ts +0 -439
  148. package/src/db/kysely/sql-utils.ts +0 -13
  149. package/src/db/postgres.ts +0 -631
  150. package/src/db/sqlite.ts +0 -670
  151. package/src/db/system-schema.ts +0 -121
  152. package/src/index.ts +0 -13
  153. package/src/runtimes/README.md +0 -59
  154. package/src/runtimes/bun.ts +0 -49
  155. package/src/runtimes/cloudflare-workers.ts +0 -38
  156. package/src/runtimes/next.ts +0 -26
  157. package/src/runtimes/node.ts +0 -52
  158. package/src/schema/collection.ts +0 -184
  159. package/src/schema/fields/base.ts +0 -164
  160. package/src/schema/fields/index.ts +0 -427
  161. package/src/schema/global.ts +0 -145
  162. package/src/schema/index.ts +0 -4
  163. package/src/schema/infer.ts +0 -72
  164. package/src/server/admin-router.ts +0 -20
  165. package/src/server/admin.ts +0 -142
  166. package/src/server/assets.ts +0 -306
  167. package/src/server/collection-router.ts +0 -55
  168. package/src/server/handlers.ts +0 -722
  169. package/src/server/middlewares/admin.ts +0 -27
  170. package/src/server/middlewares/auth.ts +0 -89
  171. package/src/server/middlewares/context.ts +0 -17
  172. package/src/server/middlewares/cors.ts +0 -24
  173. package/src/server/middlewares/database-init.ts +0 -74
  174. package/src/server/middlewares/rate-limit.ts +0 -77
  175. package/src/server/router.ts +0 -47
  176. package/src/server/setup-middlewares.ts +0 -58
  177. package/src/server/system-router.ts +0 -35
  178. package/src/server.ts +0 -9
  179. package/src/storage/adapters/cloudflare-r2.ts +0 -136
  180. package/src/storage/adapters/local.ts +0 -146
  181. package/src/storage/adapters/s3.ts +0 -186
  182. package/src/storage/errors.ts +0 -46
  183. package/src/storage/index.ts +0 -5
  184. package/src/storage/types.ts +0 -39
  185. package/src/types.ts +0 -577
  186. package/src/utils/lexical.ts +0 -37
  187. package/src/utils/logger.ts +0 -73
  188. package/src/validation.ts +0 -429
  189. package/src/validator.ts +0 -179
  190. package/test/admin-custom-field.test.ts +0 -162
  191. package/test/admin-react-field.test.tsx +0 -134
  192. package/test/api-features.test.ts +0 -78
  193. package/test/api.test.ts +0 -178
  194. package/test/auth.test.ts +0 -62
  195. package/test/cli-integration.test.ts +0 -148
  196. package/test/cli.test.ts +0 -25
  197. package/test/db/postgres.test.ts +0 -95
  198. package/test/db/sqlite-filter.test.ts +0 -53
  199. package/test/db/sqlite.test.ts +0 -82
  200. package/test/engine-features.test.ts +0 -79
  201. package/test/globals.test.ts +0 -74
  202. package/test/integration-tmp/db-app/opacacms.config.ts +0 -15
  203. package/test/integration-tmp/my-sqlite-app/opacacms.config.ts +0 -25
  204. package/test/integration-tmp/my-test-app/index.ts +0 -8
  205. package/test/integration-tmp/my-test-app/opacacms.config.ts +0 -16
  206. package/test/integration-tmp/my-test-app/package.json +0 -12
  207. package/test/populate.test.ts +0 -79
  208. package/test/runtimes.test.ts +0 -43
  209. package/test/schema-builder.test.ts +0 -107
  210. package/test/schema-features.test.ts +0 -63
  211. package/test/seeding.test.ts +0 -68
  212. package/test/storage/local.test.ts +0 -72
  213. package/test/storage/s3.test.ts +0 -60
  214. package/test/structural-data.test.ts +0 -100
  215. package/test/test-setup.ts +0 -11
  216. package/test/validation.test.ts +0 -162
  217. package/tsconfig.json +0 -42
@@ -1,720 +0,0 @@
1
- import { useStore } from "@nanostores/react";
2
- import {
3
- ArrowDownAZ,
4
- ArrowUpZA,
5
- ChevronLeft,
6
- ChevronRight,
7
- Edit2,
8
- Inbox,
9
- Loader2,
10
- Image as LucideImage,
11
- Plus,
12
- Search,
13
- } from "lucide-react";
14
- import { useEffect, useMemo, useState } from "react";
15
- import type { SerializableCollection } from "../../../types";
16
- import { lexicalToPlainText } from "../../../utils/lexical";
17
- import { api, getCurrentBaseURL } from "../../api-client";
18
- import { $collectionData, $collectionQuery } from "../../stores/admin-queries";
19
- import { $columnVisibility, initColumnVisibility } from "../../stores/column-visibility";
20
- import { $config } from "../../stores/config";
21
- import type { ToastType } from "../../stores/ui";
22
- import { notify } from "../../stores/ui";
23
- import { ColumnVisibilityToggle } from "../components/ColumnVisibilityToggle";
24
- import { DataDetailSheet } from "../components/DataDetailSheet";
25
- import { Link } from "../components/link";
26
- import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "../components/Table";
27
- import { RelationshipDetailSheet } from "../components/ui/relationship-detail-sheet";
28
- import { useDebounce } from "../hooks/use-debounce";
29
-
30
- function toSnakeCase(str: string): string {
31
- return str
32
- .replace(/([A-Z])/g, "_$1")
33
- .toLowerCase()
34
- .replace(/^_/, "");
35
- }
36
-
37
- function formatTableDate(date: string | number | Date | undefined | null, includeTime = false) {
38
- if (!date) return "-";
39
- const d = new Date(date);
40
- if (Number.isNaN(d.getTime())) return String(date);
41
- return includeTime ? d.toLocaleString() : d.toLocaleDateString();
42
- }
43
-
44
- export interface CollectionListViewProps {
45
- collection: SerializableCollection;
46
- }
47
-
48
- export function CollectionListView({ collection }: CollectionListViewProps) {
49
- const [page, setPage] = useState(1);
50
- const [limit, setLimit] = useState(10);
51
- const [sort, setSort] = useState<string>("");
52
- const [search, setSearch] = useState("");
53
- const [activeView, setActiveView] = useState<number | null>(null);
54
- const [inspection, setInspection] = useState<{
55
- open: boolean;
56
- title: string;
57
- data: any;
58
- field?: string;
59
- docId?: string | number;
60
- }>({ open: false, title: "", data: null });
61
-
62
- const [detailView, setDetailView] = useState<{
63
- open: boolean;
64
- relationTo: string;
65
- id: string | number;
66
- }>({ open: false, relationTo: "", id: "" });
67
- const debouncedSearch = useDebounce(search, 400);
68
-
69
- const visibility = useStore($columnVisibility);
70
-
71
- // All named fields (flattened)
72
- const allNamedFields = useMemo(
73
- () => collection.fields.filter((f) => f.name),
74
- [collection.fields],
75
- );
76
-
77
- // Initialize defaults once per collection
78
- useEffect(() => {
79
- const defaultCols =
80
- typeof collection.admin === "object" ? collection.admin?.defaultColumns : undefined;
81
- initColumnVisibility(collection.slug, allNamedFields, defaultCols);
82
- }, [
83
- collection.slug,
84
- allNamedFields,
85
- typeof collection.admin === "object" ? collection.admin?.defaultColumns : undefined,
86
- ]);
87
-
88
- // Derive visible fields from store
89
- const visibleFields = useMemo(() => {
90
- const visibleFieldNames = visibility[collection.slug];
91
- return visibleFieldNames
92
- ? allNamedFields.filter((f) => visibleFieldNames.includes(f.name as string))
93
- : allNamedFields;
94
- }, [visibility, collection.slug, allNamedFields]);
95
-
96
- // Update query atom when params change
97
- useEffect(() => {
98
- const defaultSearchField =
99
- typeof collection.admin === "object" && collection.admin !== null
100
- ? collection.admin.useAsTitle
101
- : undefined;
102
-
103
- const searchField =
104
- defaultSearchField ||
105
- allNamedFields.find((f) => f.name === "title" || f.name === "name" || f.name === "slug")
106
- ?.name ||
107
- "id";
108
-
109
- const populate = collection.fields
110
- .filter((f) => f.type === "relationship" && (f as any).displayField)
111
- .map((f) => f.name)
112
- .join(",");
113
-
114
- $collectionQuery.set({
115
- slug: collection.apiPath || collection.slug,
116
- page,
117
- limit,
118
- sort,
119
- search: debouncedSearch,
120
- searchField,
121
- filter:
122
- activeView !== null && typeof collection.admin === "object"
123
- ? collection.admin?.views?.[activeView]?.filter
124
- : undefined,
125
- populate: populate || undefined,
126
- });
127
- }, [
128
- collection.slug,
129
- collection.apiPath,
130
- collection.admin,
131
- allNamedFields,
132
- page,
133
- limit,
134
- sort,
135
- debouncedSearch,
136
- activeView,
137
- ]);
138
-
139
- const { data, loading } = useStore($collectionData);
140
-
141
- const handleSort = (fieldName: string) => {
142
- if (sort === fieldName) {
143
- setSort(`-${fieldName}`); // toggle to desc
144
- } else if (sort === `-${fieldName}`) {
145
- setSort(""); // remove sort
146
- } else {
147
- setSort(fieldName); // asc
148
- }
149
- setPage(1); // reset to first page on sort change
150
- };
151
-
152
- const handleQuickEditSave = async (updatedData: any) => {
153
- if (!inspection.field || !inspection.docId) return;
154
-
155
- try {
156
- const payload = { [inspection.field]: updatedData };
157
- await api
158
- .patch(`api/${(collection.apiPath || collection.slug) as string}/${inspection.docId}`, {
159
- json: payload,
160
- })
161
- .json();
162
-
163
- // Trigger a re-fetch of the collection data
164
- const currentQuery = $collectionQuery.get();
165
- if (currentQuery) {
166
- $collectionQuery.set({
167
- ...currentQuery,
168
- slug: currentQuery.slug as string, // Ensure slug is string
169
- });
170
- }
171
- notify("Document updated successfully", "success");
172
- setInspection({ ...inspection, open: false });
173
- } catch (e) {
174
- console.error(e);
175
- notify("Failed to update document", "error");
176
- }
177
- };
178
-
179
- const getSortIcon = (fieldName: string) => {
180
- if (sort === fieldName) {
181
- return <ArrowDownAZ size={14} style={{ marginLeft: "4px", opacity: 0.7 }} />;
182
- }
183
- if (sort === `-${fieldName}`) {
184
- return <ArrowUpZA size={14} style={{ marginLeft: "4px", opacity: 0.7 }} />;
185
- }
186
- return null;
187
- };
188
-
189
- const docs = data?.docs || [];
190
-
191
- const createdAtField = useMemo(() => {
192
- if (typeof collection.timestamps === "object" && collection.timestamps?.createdAt) {
193
- return toSnakeCase(collection.timestamps.createdAt);
194
- }
195
- return "created_at";
196
- }, [collection.timestamps]);
197
-
198
- return (
199
- <div className={`opaca-view-container ${loading ? "loading" : ""}`}>
200
- <div className="opaca-header">
201
- <div>
202
- <div style={{ display: "flex", alignItems: "center", gap: "0.75rem" }}>
203
- <h1 className="opaca-title">
204
- {collection.label ||
205
- (collection.slug.startsWith("_")
206
- ? collection.slug
207
- .replace(/^_+/, "")
208
- .replace(/_/g, " ")
209
- .replace(/\b\w/g, (c) => c.toUpperCase())
210
- : collection.slug.charAt(0).toUpperCase() + collection.slug.slice(1))}
211
- </h1>
212
- {data && (
213
- <span className="opaca-badge">
214
- {data.totalDocs} {data.totalDocs === 1 ? "document" : "documents"}
215
- </span>
216
- )}
217
- </div>
218
- <p className="opaca-subtitle">Manage your {collection.slug} entries.</p>
219
- </div>
220
-
221
- <div style={{ display: "flex", gap: "0.75rem", alignItems: "center" }}>
222
- <div style={{ position: "relative", width: "240px" }}>
223
- <Search
224
- size={16}
225
- style={{
226
- position: "absolute",
227
- left: "10px",
228
- top: "50%",
229
- transform: "translateY(-50%)",
230
- color: "var(--opaca-text-muted)",
231
- }}
232
- />
233
- <input
234
- type="text"
235
- className="opaca-input"
236
- placeholder="Search documents..."
237
- value={search}
238
- onChange={(e) => {
239
- setSearch(e.target.value);
240
- setPage(1);
241
- }}
242
- style={{ paddingLeft: "36px" }}
243
- />
244
- </div>
245
- <ColumnVisibilityToggle slug={collection.slug} fields={allNamedFields} />
246
- <Link
247
- href={`/admin/collections/${collection.slug}/create`}
248
- className="opaca-btn opaca-btn-primary"
249
- style={{ textDecoration: "none" }}
250
- >
251
- <Plus size={18} />
252
- Create New
253
- </Link>
254
- </div>
255
- </div>
256
-
257
- {typeof collection.admin === "object" &&
258
- collection.admin?.views &&
259
- collection.admin.views.length > 0 && (
260
- <div
261
- style={{
262
- display: "flex",
263
- gap: "0.5rem",
264
- marginBottom: "1.25rem",
265
- overflowX: "auto",
266
- paddingBottom: "0.5rem",
267
- }}
268
- >
269
- <button
270
- type="button"
271
- className={`opaca-btn ${activeView === null ? "opaca-btn-primary" : "opaca-btn-outline"}`}
272
- onClick={() => {
273
- setActiveView(null);
274
- setPage(1);
275
- }}
276
- style={{ padding: "0.4rem 1rem", fontSize: "0.875rem" }}
277
- >
278
- All
279
- </button>
280
- {collection.admin.views.map((view, idx) => (
281
- <button
282
- key={view.name}
283
- type="button"
284
- className={`opaca-btn ${activeView === idx ? "opaca-btn-primary" : "opaca-btn-outline"}`}
285
- onClick={() => {
286
- setActiveView(idx);
287
- setPage(1);
288
- }}
289
- style={{ padding: "0.4rem 1rem", fontSize: "0.875rem" }}
290
- >
291
- {view.name}
292
- </button>
293
- ))}
294
- </div>
295
- )}
296
-
297
- <div className="opaca-table-container">
298
- {loading && (
299
- <div className="opaca-loading-overlay">
300
- <Loader2 size={24} className="opaca-spin" />
301
- </div>
302
- )}
303
-
304
- <DataDetailSheet
305
- open={inspection.open}
306
- onOpenChange={(open) => setInspection({ ...inspection, open })}
307
- title={inspection.title}
308
- data={inspection.data}
309
- onSave={handleQuickEditSave}
310
- field={inspection.field}
311
- />
312
-
313
- {docs.length > 0 ? (
314
- <>
315
- <Table>
316
- <TableHeader>
317
- <TableRow>
318
- {visibleFields.map((field) => (
319
- <TableHead
320
- key={field.name}
321
- onClick={() => handleSort(field.name as string)}
322
- style={{ cursor: "pointer", userSelect: "none" }}
323
- >
324
- <div style={{ display: "flex", alignItems: "center" }}>
325
- {field.label || field.name}
326
- {getSortIcon(field.name as string)}
327
- </div>
328
- </TableHead>
329
- ))}
330
- {collection.timestamps && (
331
- <TableHead
332
- onClick={() => handleSort("createdAt")}
333
- style={{ cursor: "pointer", userSelect: "none" }}
334
- >
335
- <div style={{ display: "flex", alignItems: "center" }}>
336
- Created At
337
- {getSortIcon("createdAt")}
338
- </div>
339
- </TableHead>
340
- )}
341
- <TableHead style={{ width: "50px" }}></TableHead>
342
- </TableRow>
343
- </TableHeader>
344
- <TableBody>
345
- {docs.map((doc: Record<string, unknown>) => (
346
- <TableRow key={doc.id as string | number}>
347
- {visibleFields.map((field) => {
348
- const value = doc[field.name as string];
349
- return (
350
- <TableCell
351
- key={field.name as string}
352
- className={
353
- ["richtext", "json", "group", "relationship"].includes(field.type)
354
- ? "opaca-cell-interactive"
355
- : ""
356
- }
357
- onClick={(e) => {
358
- if (!["richtext", "json", "group", "relationship"].includes(field.type))
359
- return;
360
- e.stopPropagation();
361
- setInspection({
362
- open: true,
363
- title: field.label || field.name || "Details",
364
- data: value,
365
- field: field.name as string,
366
- docId: doc.id as string | number,
367
- });
368
- }}
369
- >
370
- {field.type === "boolean" ? (
371
- value ? (
372
- <span
373
- className="opaca-badge"
374
- style={{ color: "var(--opaca-success)" }}
375
- >
376
- Yes
377
- </span>
378
- ) : (
379
- <span
380
- className="opaca-badge"
381
- style={{ color: "var(--opaca-text-dim)" }}
382
- >
383
- No
384
- </span>
385
- )
386
- ) : collection.slug === "_opaca_assets" && field.name === "filename" ? (
387
- <div
388
- style={{
389
- display: "flex",
390
- alignItems: "center",
391
- gap: "0.75rem",
392
- }}
393
- >
394
- <div
395
- style={{
396
- width: "32px",
397
- height: "32px",
398
- borderRadius: "6px",
399
- background: "var(--opaca-surface)",
400
- overflow: "hidden",
401
- display: "flex",
402
- alignItems: "center",
403
- justifyContent: "center",
404
- border: "1px solid var(--opaca-border)",
405
- }}
406
- >
407
- {(() => {
408
- const mime = String(doc.mimeType || doc.mime_type);
409
- return mime.startsWith("image/") ? (
410
- <img
411
- src={`${getCurrentBaseURL()}/api/${collection.apiPath || collection.slug}/${doc.id}/view`}
412
- style={{
413
- width: "100%",
414
- height: "100%",
415
- objectFit: "cover",
416
- }}
417
- alt=""
418
- />
419
- ) : (
420
- <LucideImage size={14} style={{ opacity: 0.5 }} />
421
- );
422
- })()}
423
- </div>
424
- <span style={{ fontWeight: 500 }}>{String(value ?? "-")}</span>
425
- </div>
426
- ) : field.type === "blocks" && Array.isArray(value) ? (
427
- <button
428
- type="button"
429
- onClick={(e) => {
430
- e.stopPropagation();
431
- setInspection({
432
- open: true,
433
- title: field.label || field.name || "Blocks",
434
- data: value,
435
- field: field.name as string,
436
- docId: doc.id as string | number,
437
- });
438
- }}
439
- className="opaca-badge opaca-badge-interactive"
440
- style={{ color: "var(--opaca-text-dim)" }}
441
- >
442
- {value.length} block
443
- {value.length !== 1 ? "s" : ""}
444
- </button>
445
- ) : field.type === "relationship" ? (
446
- <div
447
- style={{
448
- display: "flex",
449
- alignItems: "center",
450
- gap: "0.5rem",
451
- }}
452
- >
453
- {(() => {
454
- const firstItemItem = Array.isArray(value) ? value[0] : value;
455
- if (
456
- firstItemItem &&
457
- typeof firstItemItem === "object" &&
458
- (firstItemItem as any).filename
459
- ) {
460
- return (
461
- <div
462
- style={{
463
- width: "24px",
464
- height: "24px",
465
- borderRadius: "4px",
466
- overflow: "hidden",
467
- border: "1px solid var(--opaca-border)",
468
- flexShrink: 0,
469
- }}
470
- >
471
- <img
472
- src={`${getCurrentBaseURL()}/api/_opaca_assets/${(firstItemItem as any).id}/view`}
473
- style={{
474
- width: "100%",
475
- height: "100%",
476
- objectFit: "cover",
477
- }}
478
- alt=""
479
- />
480
- </div>
481
- );
482
- }
483
- return null;
484
- })()}
485
- {(() => {
486
- const firstItem = Array.isArray(value) ? value[0] : value;
487
- return (
488
- <button
489
- type="button"
490
- className="opaca-badge opaca-badge-interactive"
491
- style={{ color: "var(--opaca-text-dim)" }}
492
- onClick={(e) => {
493
- e.stopPropagation();
494
- const id =
495
- (firstItem as any)?.id ||
496
- (typeof firstItem === "string" ? firstItem : "");
497
- if (id) {
498
- setDetailView({
499
- open: true,
500
- relationTo: field.relationTo || "",
501
- id,
502
- });
503
- }
504
- }}
505
- >
506
- {field.hasMany && Array.isArray(value)
507
- ? `${value.length} item${value.length !== 1 ? "s" : ""}`
508
- : typeof firstItem === "object" && firstItem !== null
509
- ? (firstItem as any)[(field as any).displayField || "id"] ||
510
- (firstItem as any).id ||
511
- "[Object]"
512
- : String(value ?? "-")}
513
- </button>
514
- );
515
- })()}
516
- </div>
517
- ) : field.type === "group" &&
518
- typeof value === "object" &&
519
- value !== null ? (
520
- <span
521
- className="opaca-badge"
522
- style={{
523
- background: "rgba(255, 255, 255, 0.05)",
524
- border: "1px solid var(--opaca-border)",
525
- color: "var(--opaca-text-dim)",
526
- }}
527
- >
528
- {`{ ${Object.keys(value).length} keys }`}
529
- </span>
530
- ) : field.type === "json" &&
531
- typeof value === "object" &&
532
- value !== null ? (
533
- <span
534
- style={{
535
- color: "var(--opaca-text-dim)",
536
- fontFamily: "monospace",
537
- fontSize: "0.85em",
538
- }}
539
- >
540
- {JSON.stringify(value).slice(0, 30)}
541
- {JSON.stringify(value).length > 30 ? "..." : ""}
542
- </span>
543
- ) : field.type === "date" ? (
544
- <span
545
- style={{
546
- color: "var(--opaca-text)",
547
- opacity: 0.9,
548
- }}
549
- >
550
- {formatTableDate(value as string)}
551
- </span>
552
- ) : typeof value === "object" && value !== null ? (
553
- <span
554
- className="opaca-badge"
555
- style={{
556
- background: "rgba(255, 255, 255, 0.05)",
557
- border: "1px solid var(--opaca-border)",
558
- color: "var(--opaca-text-dim)",
559
- }}
560
- >
561
- [Object]
562
- </span>
563
- ) : (
564
- <span
565
- style={{
566
- color: "var(--opaca-text)",
567
- opacity: 0.9,
568
- }}
569
- >
570
- {field.type === "richtext"
571
- ? lexicalToPlainText(value as string).slice(0, 30) +
572
- (lexicalToPlainText(value as string).length > 30 ? "..." : "")
573
- : typeof value === "string" && value.length > 30
574
- ? `${value.slice(0, 30)}...`
575
- : String(value ?? "-")}
576
- </span>
577
- )}
578
- </TableCell>
579
- );
580
- })}
581
- {collection.timestamps && (
582
- <TableCell
583
- style={{
584
- color: "var(--opaca-text-muted)",
585
- fontSize: "12px",
586
- }}
587
- >
588
- {formatTableDate(doc[createdAtField] as any, true)}
589
- </TableCell>
590
- )}
591
- <TableCell>
592
- <Link
593
- href={`/admin/collections/${collection.slug}/${doc.id}`}
594
- className="opaca-btn opaca-btn-outline"
595
- style={{ padding: "0.4rem" }}
596
- title="Edit Document"
597
- >
598
- <Edit2 size={14} />
599
- </Link>
600
- </TableCell>
601
- </TableRow>
602
- ))}
603
- </TableBody>
604
- </Table>
605
-
606
- {data && (
607
- <div
608
- className="opaca-pagination"
609
- style={{
610
- display: "flex",
611
- justifyContent: "space-between",
612
- alignItems: "center",
613
- marginTop: "1rem",
614
- }}
615
- >
616
- <div
617
- className="opaca-pagination-info"
618
- style={{
619
- color: "var(--opaca-text-muted)",
620
- fontSize: "0.875rem",
621
- }}
622
- >
623
- Showing {(data.page - 1) * data.limit + 1} to{" "}
624
- {Math.min(data.page * data.limit, data.totalDocs)} of {data.totalDocs} documents
625
- </div>
626
-
627
- <div
628
- style={{
629
- display: "flex",
630
- alignItems: "center",
631
- gap: "1.5rem",
632
- }}
633
- >
634
- <div
635
- style={{
636
- display: "flex",
637
- alignItems: "center",
638
- gap: "0.5rem",
639
- }}
640
- >
641
- <span
642
- style={{
643
- fontSize: "0.875rem",
644
- color: "var(--opaca-text-muted)",
645
- }}
646
- >
647
- Rows per page:
648
- </span>
649
- <select
650
- value={limit}
651
- onChange={(e) => {
652
- setLimit(Number(e.target.value));
653
- setPage(1);
654
- }}
655
- className="opaca-input"
656
- style={{
657
- padding: "0.25rem 0.5rem",
658
- height: "auto",
659
- width: "auto",
660
- }}
661
- >
662
- <option value="10">10</option>
663
- <option value="25">25</option>
664
- <option value="50">50</option>
665
- <option value="100">100</option>
666
- </select>
667
- </div>
668
-
669
- <div
670
- className="opaca-pagination-actions"
671
- style={{ display: "flex", gap: "0.5rem" }}
672
- >
673
- <button
674
- type="button"
675
- className="opaca-btn opaca-btn-outline"
676
- disabled={!data.hasPrevPage || loading}
677
- onClick={() => setPage(page - 1)}
678
- style={{ padding: "0.4rem" }}
679
- >
680
- <ChevronLeft size={16} />
681
- </button>
682
- <button
683
- type="button"
684
- className="opaca-btn opaca-btn-outline"
685
- disabled={!data.hasNextPage || loading}
686
- onClick={() => setPage(page + 1)}
687
- style={{ padding: "0.4rem" }}
688
- >
689
- <ChevronRight size={16} />
690
- </button>
691
- </div>
692
- </div>
693
- </div>
694
- )}
695
- </>
696
- ) : !loading ? (
697
- <div className="opaca-empty">
698
- <div className="opaca-empty-icon">
699
- <Inbox size={32} />
700
- </div>
701
- <h3 style={{ fontSize: "1.125rem", fontWeight: "600" }}>No documents found</h3>
702
- <p className="opaca-subtitle" style={{ maxWidth: "300px" }}>
703
- This collection is currently empty. Start by creating your first document.
704
- </p>
705
- <Link
706
- href={`/admin/collections/${collection.slug}/create`}
707
- className="opaca-btn opaca-btn-primary"
708
- style={{ textDecoration: "none", marginTop: "0.5rem" }}
709
- >
710
- <Plus size={18} />
711
- Create First {collection.label || collection.slug}
712
- </Link>
713
- </div>
714
- ) : (
715
- <div style={{ height: "200px" }} /> /* Placeholder while loading empty state */
716
- )}
717
- </div>
718
- </div>
719
- );
720
- }