opacacms 0.1.11 → 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 (246) hide show
  1. package/dist/admin/index.js +9464 -21
  2. package/dist/admin/webcomponent.d.ts +1 -1
  3. package/dist/admin/webcomponent.js +9620 -6
  4. package/dist/admin.css +1 -0
  5. package/dist/{chunk-6dhs73zq.js → chunk-0am1m47g.js} +1 -1
  6. package/dist/{chunk-0nf7fe26.js → chunk-0d9aqz6z.js} +1 -1
  7. package/dist/{chunk-cvdd4eqh.js → chunk-2kyhqvhc.js} +5 -1
  8. package/dist/{chunk-gjjcc4hm.js → chunk-2z8wxx9g.js} +21 -6
  9. package/dist/{chunk-xg35h5a3.js → chunk-7fyepksb.js} +1 -1
  10. package/dist/{chunk-njytmdb4.js → chunk-pxh5encs.js} +34 -24
  11. package/dist/{chunk-n8aekdnr.js → chunk-qkn1ykrj.js} +33 -23
  12. package/dist/{chunk-kwp83w8b.js → chunk-wmvjvn7b.js} +4 -4
  13. package/dist/{chunk-qrt22f6e.js → chunk-wq314kkx.js} +35 -25
  14. package/dist/{chunk-eqtsfyjf.js → chunk-x2ejaftz.js} +52 -28
  15. package/dist/{chunk-6ew02s0c.js → chunk-xtwc125q.js} +18 -18
  16. package/dist/cli/index.js +5 -5
  17. package/dist/db/better-sqlite.d.ts +1 -0
  18. package/dist/db/better-sqlite.js +3 -3
  19. package/dist/db/bun-sqlite.d.ts +1 -0
  20. package/dist/db/bun-sqlite.js +3 -3
  21. package/dist/db/d1.js +3 -3
  22. package/dist/db/index.d.ts +3 -0
  23. package/dist/db/index.js +17 -13
  24. package/dist/db/postgres.js +3 -3
  25. package/dist/db/sqlite.js +3 -3
  26. package/dist/runtimes/bun.js +2 -2
  27. package/dist/runtimes/cloudflare-workers.js +2 -2
  28. package/dist/runtimes/next.js +2 -2
  29. package/dist/runtimes/node.js +2 -2
  30. package/dist/server.js +2 -2
  31. package/package.json +8 -2
  32. package/bun.lock +0 -34
  33. package/dist/admin/index.css +0 -47
  34. package/dist/api.d.ts +0 -6
  35. package/dist/api.js +0 -27
  36. package/dist/chunk-2zm8cy1w.js +0 -9482
  37. package/global.d.ts +0 -11
  38. package/src/admin/api-client.ts +0 -63
  39. package/src/admin/auth-client.ts +0 -40
  40. package/src/admin/custom-field.ts +0 -179
  41. package/src/admin/index.ts +0 -15
  42. package/src/admin/react.tsx +0 -72
  43. package/src/admin/router.ts +0 -9
  44. package/src/admin/stores/admin-queries.ts +0 -121
  45. package/src/admin/stores/auth.ts +0 -61
  46. package/src/admin/stores/column-visibility.ts +0 -67
  47. package/src/admin/stores/config.ts +0 -15
  48. package/src/admin/stores/media.ts +0 -95
  49. package/src/admin/stores/query.ts +0 -13
  50. package/src/admin/stores/ui.ts +0 -29
  51. package/src/admin/ui/admin-client.tsx +0 -283
  52. package/src/admin/ui/admin-layout.tsx +0 -276
  53. package/src/admin/ui/components/ColumnVisibilityToggle.tsx +0 -141
  54. package/src/admin/ui/components/DataDetailSheet.tsx +0 -141
  55. package/src/admin/ui/components/DataDetailView.tsx +0 -175
  56. package/src/admin/ui/components/Table.tsx +0 -67
  57. package/src/admin/ui/components/fields/ArrayField.tsx +0 -166
  58. package/src/admin/ui/components/fields/BlocksField.tsx +0 -202
  59. package/src/admin/ui/components/fields/BooleanField.tsx +0 -50
  60. package/src/admin/ui/components/fields/CollapsibleField.tsx +0 -75
  61. package/src/admin/ui/components/fields/DateField.tsx +0 -45
  62. package/src/admin/ui/components/fields/FileField.tsx +0 -322
  63. package/src/admin/ui/components/fields/GroupField.tsx +0 -50
  64. package/src/admin/ui/components/fields/JoinField.tsx +0 -23
  65. package/src/admin/ui/components/fields/NumberField.tsx +0 -46
  66. package/src/admin/ui/components/fields/RadioField.tsx +0 -62
  67. package/src/admin/ui/components/fields/RelationshipField.tsx +0 -278
  68. package/src/admin/ui/components/fields/RowField.tsx +0 -40
  69. package/src/admin/ui/components/fields/SelectField.tsx +0 -59
  70. package/src/admin/ui/components/fields/TabsField.tsx +0 -101
  71. package/src/admin/ui/components/fields/TextAreaField.tsx +0 -54
  72. package/src/admin/ui/components/fields/TextField.tsx +0 -49
  73. package/src/admin/ui/components/fields/VirtualField.tsx +0 -53
  74. package/src/admin/ui/components/fields/index.tsx +0 -371
  75. package/src/admin/ui/components/fields/richtext-editor/index.tsx +0 -211
  76. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageComponent.tsx +0 -142
  77. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageNode.tsx +0 -95
  78. package/src/admin/ui/components/fields/richtext-editor/plugins/ComponentPickerPlugin.tsx +0 -226
  79. package/src/admin/ui/components/fields/richtext-editor/plugins/EditableSyncPlugin.tsx +0 -16
  80. package/src/admin/ui/components/fields/richtext-editor/plugins/NotionToolbarPlugin.tsx +0 -184
  81. package/src/admin/ui/components/fields/richtext-editor/plugins/SimpleToolbarPlugin.tsx +0 -240
  82. package/src/admin/ui/components/fields/richtext-editor/plugins/ValueSyncPlugin.tsx +0 -40
  83. package/src/admin/ui/components/fields/utils.ts +0 -1
  84. package/src/admin/ui/components/link.tsx +0 -41
  85. package/src/admin/ui/components/media/AssetManagerModal.tsx +0 -334
  86. package/src/admin/ui/components/toast.tsx +0 -72
  87. package/src/admin/ui/components/ui/accordion.tsx +0 -51
  88. package/src/admin/ui/components/ui/alert-dialog.tsx +0 -98
  89. package/src/admin/ui/components/ui/blocks.tsx +0 -32
  90. package/src/admin/ui/components/ui/breadcrumbs.tsx +0 -59
  91. package/src/admin/ui/components/ui/button.tsx +0 -26
  92. package/src/admin/ui/components/ui/collapsible.tsx +0 -124
  93. package/src/admin/ui/components/ui/dialog.tsx +0 -79
  94. package/src/admin/ui/components/ui/group.tsx +0 -20
  95. package/src/admin/ui/components/ui/index.ts +0 -17
  96. package/src/admin/ui/components/ui/input.tsx +0 -12
  97. package/src/admin/ui/components/ui/join.tsx +0 -53
  98. package/src/admin/ui/components/ui/label.tsx +0 -11
  99. package/src/admin/ui/components/ui/radio-group.tsx +0 -75
  100. package/src/admin/ui/components/ui/relationship-detail-sheet.tsx +0 -122
  101. package/src/admin/ui/components/ui/relationship.tsx +0 -58
  102. package/src/admin/ui/components/ui/scroll-area.tsx +0 -19
  103. package/src/admin/ui/components/ui/select.tsx +0 -187
  104. package/src/admin/ui/components/ui/separator.tsx +0 -21
  105. package/src/admin/ui/components/ui/sheet.tsx +0 -106
  106. package/src/admin/ui/components/ui/tabs.tsx +0 -116
  107. package/src/admin/ui/components/ui/utils.ts +0 -3
  108. package/src/admin/ui/hooks/use-debounce.ts +0 -15
  109. package/src/admin/ui/styles/_locale-switcher.scss +0 -33
  110. package/src/admin/ui/styles/accordion.scss +0 -60
  111. package/src/admin/ui/styles/animations.scss +0 -41
  112. package/src/admin/ui/styles/asset-manager.scss +0 -547
  113. package/src/admin/ui/styles/badge.scss +0 -13
  114. package/src/admin/ui/styles/base.scss +0 -22
  115. package/src/admin/ui/styles/button.scss +0 -161
  116. package/src/admin/ui/styles/card.scss +0 -13
  117. package/src/admin/ui/styles/collapsible.scss +0 -75
  118. package/src/admin/ui/styles/data-detail.scss +0 -92
  119. package/src/admin/ui/styles/dialog.scss +0 -102
  120. package/src/admin/ui/styles/empty-state.scss +0 -22
  121. package/src/admin/ui/styles/group.scss +0 -19
  122. package/src/admin/ui/styles/index.scss +0 -33
  123. package/src/admin/ui/styles/input.scss +0 -80
  124. package/src/admin/ui/styles/label.scss +0 -12
  125. package/src/admin/ui/styles/layout.scss +0 -56
  126. package/src/admin/ui/styles/lexical.scss +0 -469
  127. package/src/admin/ui/styles/loading.scss +0 -102
  128. package/src/admin/ui/styles/media-registry.scss +0 -597
  129. package/src/admin/ui/styles/pagination.scss +0 -20
  130. package/src/admin/ui/styles/radio-group.scss +0 -66
  131. package/src/admin/ui/styles/row.scss +0 -17
  132. package/src/admin/ui/styles/scrollbar.scss +0 -36
  133. package/src/admin/ui/styles/select.scss +0 -121
  134. package/src/admin/ui/styles/separator.scss +0 -14
  135. package/src/admin/ui/styles/sheet.scss +0 -152
  136. package/src/admin/ui/styles/sidebar.scss +0 -148
  137. package/src/admin/ui/styles/switch.scss +0 -59
  138. package/src/admin/ui/styles/table.scss +0 -207
  139. package/src/admin/ui/styles/tabs.scss +0 -62
  140. package/src/admin/ui/styles/toast.scss +0 -45
  141. package/src/admin/ui/styles/variables.scss +0 -24
  142. package/src/admin/ui/views/collection-list-view.tsx +0 -720
  143. package/src/admin/ui/views/dashboard-view.tsx +0 -263
  144. package/src/admin/ui/views/document-edit-view.tsx +0 -384
  145. package/src/admin/ui/views/global-edit-view.tsx +0 -226
  146. package/src/admin/ui/views/init-view.tsx +0 -182
  147. package/src/admin/ui/views/login-view.tsx +0 -123
  148. package/src/admin/ui/views/media-registry-view.tsx +0 -1104
  149. package/src/admin/ui/views/settings-view.tsx +0 -729
  150. package/src/admin/webcomponent.tsx +0 -15
  151. package/src/api.ts +0 -9
  152. package/src/auth/index.ts +0 -194
  153. package/src/auth/migrations.ts +0 -87
  154. package/src/auth/premissions.ts +0 -46
  155. package/src/cli/commands/generate-types.ts +0 -116
  156. package/src/cli/commands/init.ts +0 -95
  157. package/src/cli/commands/migrate-commands.ts +0 -160
  158. package/src/cli/commands/seed-command.ts +0 -11
  159. package/src/cli/d1-mock.ts +0 -101
  160. package/src/cli/index.test.ts +0 -84
  161. package/src/cli/index.ts +0 -183
  162. package/src/cli/r2-mock.ts +0 -217
  163. package/src/cli/seeding.ts +0 -409
  164. package/src/client.ts +0 -181
  165. package/src/config-utils.ts +0 -102
  166. package/src/config.ts +0 -49
  167. package/src/db/adapter.ts +0 -53
  168. package/src/db/better-sqlite.ts +0 -632
  169. package/src/db/bun-sqlite.ts +0 -646
  170. package/src/db/d1.ts +0 -711
  171. package/src/db/index.ts +0 -6
  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 -660
  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 -77
  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 -148
  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
@@ -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
- }