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,276 +0,0 @@
1
- import { useStore } from "@nanostores/react";
2
- import * as LucideIcons from "lucide-react";
3
- import {
4
- ChevronLeft,
5
- ChevronRight,
6
- Database,
7
- Globe,
8
- Image,
9
- LayoutDashboard,
10
- LogOut,
11
- Settings,
12
- } from "lucide-react";
13
- import type React from "react";
14
- import type { SerializableConfig } from "../../types";
15
- import { $router } from "../router";
16
- import { $isSidebarCollapsed, toggleSidebar } from "../stores/ui";
17
- import { Link } from "./components/link";
18
- import { Accordion, ScrollArea, Separator } from "./components/ui";
19
- import "./styles/index.scss";
20
-
21
- export interface AdminLayoutProps {
22
- children: React.ReactNode;
23
- config: SerializableConfig;
24
- user?: {
25
- name: string;
26
- email: string;
27
- image?: string | null;
28
- } | null;
29
- onLogout?: () => void;
30
- }
31
-
32
- export function AdminLayout({ children, config, user, onLogout }: AdminLayoutProps) {
33
- const isCollapsed = useStore($isSidebarCollapsed);
34
- const page = useStore($router);
35
- const currentPath = page?.path || "/admin";
36
-
37
- return (
38
- <div className="opaca-admin">
39
- <aside className={`opaca-sidebar ${isCollapsed ? "collapsed" : ""}`}>
40
- <button
41
- type="button"
42
- className="opaca-sidebar-toggle"
43
- onClick={toggleSidebar}
44
- title={isCollapsed ? "Expand Sidebar" : "Collapse Sidebar"}
45
- >
46
- {isCollapsed ? <ChevronRight size={14} /> : <ChevronLeft size={14} />}
47
- </button>
48
-
49
- <div className="opaca-sidebar-inner">
50
- <div className="opaca-logo" title={config.appName || "OpacaCMS"}>
51
- {isCollapsed ? (
52
- <div className="opaca-logo-mini">
53
- {(config.appName || "OpacaCMS").charAt(0).toUpperCase()}
54
- </div>
55
- ) : (
56
- config.appName || "OpacaCMS"
57
- )}
58
- </div>
59
-
60
- <nav className="opaca-nav">
61
- <Link
62
- href="/admin"
63
- className={`opaca-nav-item ${currentPath === "/admin" ? "active" : ""}`}
64
- title="Dashboard"
65
- >
66
- <LayoutDashboard size={16} />
67
- <span className="opaca-nav-label">Dashboard</span>
68
- </Link>
69
-
70
- {(() => {
71
- const allCollections = config.collections
72
- .filter((col) => !col.hidden)
73
- .sort((a, b) => (a.admin === b.admin ? 0 : a.admin ? -1 : 1));
74
-
75
- const userCollections = allCollections.filter((col) => !col.slug.startsWith("_"));
76
- const systemCollections = allCollections.filter((col) => col.slug.startsWith("_"));
77
-
78
- const renderCollection = (col: any) => {
79
- const href = `/admin/collections/${col.slug}`;
80
- const colLabel =
81
- col.label ||
82
- col.slug
83
- .replace(/^_+/, "")
84
- .replace(/_/g, " ")
85
- .replace(/\b\w/g, (c: string) => c.toUpperCase());
86
- const isMedia = col.slug === "_opaca_assets";
87
- const IconComponent =
88
- col.icon && col.icon in LucideIcons
89
- ? (LucideIcons as any)[col.icon]
90
- : isMedia
91
- ? Image
92
- : Database;
93
-
94
- return (
95
- <Link
96
- key={col.slug}
97
- href={href}
98
- className={`opaca-nav-item ${currentPath.includes(href) ? "active" : ""}`}
99
- title={colLabel}
100
- >
101
- <IconComponent size={16} />
102
- <span className="opaca-nav-label">{colLabel}</span>
103
- {col.admin && !isCollapsed && (
104
- <div
105
- style={{
106
- width: "4px",
107
- height: "4px",
108
- borderRadius: "50%",
109
- backgroundColor: "var(--opaca-accent)",
110
- marginLeft: "auto",
111
- opacity: 0.8,
112
- }}
113
- title="Universal Collection"
114
- />
115
- )}
116
- </Link>
117
- );
118
- };
119
-
120
- return (
121
- <ScrollArea className="opaca-nav-scroll" style={{ flex: 1 }}>
122
- {userCollections.length > 0 && (
123
- <Accordion title="Collections" isCollapsed={isCollapsed}>
124
- {userCollections.map(renderCollection)}
125
- </Accordion>
126
- )}
127
-
128
- {userCollections.length > 0 && systemCollections.length > 0 && (
129
- <div style={{ margin: "0.75rem 0.75rem" }}>
130
- <Separator />
131
- </div>
132
- )}
133
-
134
- {systemCollections.length > 0 && (
135
- <Accordion title="System Collections" isCollapsed={isCollapsed}>
136
- {systemCollections.map(renderCollection)}
137
- </Accordion>
138
- )}
139
-
140
- {config.globals && config.globals.length > 0 && (
141
- <Accordion title="Globals" isCollapsed={isCollapsed}>
142
- {config.globals.map((g) => {
143
- const href = `/admin/globals/${g.slug}`;
144
- const label = g.label || g.slug.charAt(0).toUpperCase() + g.slug.slice(1);
145
- const IconComponent =
146
- g.icon && g.icon in LucideIcons ? (LucideIcons as any)[g.icon] : Globe;
147
- return (
148
- <Link
149
- key={g.slug}
150
- href={href}
151
- className={`opaca-nav-item ${currentPath === href ? "active" : ""}`}
152
- title={label}
153
- >
154
- <IconComponent size={16} />
155
- <span className="opaca-nav-label">{label}</span>
156
- </Link>
157
- );
158
- })}
159
- </Accordion>
160
- )}
161
- </ScrollArea>
162
- );
163
- })()}
164
- </nav>
165
-
166
- <div className="opaca-nav-footer">
167
- {user && (
168
- <div
169
- className="opaca-user-profile"
170
- style={{
171
- padding: "0.75rem",
172
- borderBottom: "1px solid var(--opaca-border)",
173
- marginBottom: "0.5rem",
174
- display: "flex",
175
- alignItems: "center",
176
- gap: "0.75rem",
177
- justifyContent: isCollapsed ? "center" : "flex-start",
178
- }}
179
- title={`${user.name} (${user.email})`}
180
- >
181
- {user.image ? (
182
- <img
183
- src={user.image}
184
- alt={user.name}
185
- style={{
186
- width: "32px",
187
- height: "32px",
188
- borderRadius: "50%",
189
- objectFit: "cover",
190
- }}
191
- />
192
- ) : (
193
- <div
194
- style={{
195
- width: "32px",
196
- height: "32px",
197
- minWidth: "32px",
198
- borderRadius: "50%",
199
- background: "var(--opaca-accent)",
200
- color: "white",
201
- display: "flex",
202
- alignItems: "center",
203
- justifyContent: "center",
204
- fontSize: "0.75rem",
205
- fontWeight: "600",
206
- }}
207
- >
208
- {user.name.charAt(0).toUpperCase()}
209
- </div>
210
- )}
211
- {!isCollapsed && (
212
- <div style={{ overflow: "hidden" }}>
213
- <div
214
- style={{
215
- fontSize: "0.8125rem",
216
- fontWeight: "500",
217
- whiteSpace: "nowrap",
218
- overflow: "hidden",
219
- textOverflow: "ellipsis",
220
- }}
221
- >
222
- {user.name}
223
- </div>
224
- <div
225
- style={{
226
- fontSize: "0.6875rem",
227
- color: "var(--opaca-text-dim)",
228
- whiteSpace: "nowrap",
229
- overflow: "hidden",
230
- textOverflow: "ellipsis",
231
- }}
232
- >
233
- {user.email}
234
- </div>
235
- </div>
236
- )}
237
- </div>
238
- )}
239
-
240
- <Link
241
- href="/admin/settings"
242
- className={`opaca-nav-item ${currentPath === "/admin/settings" ? "active" : ""}`}
243
- title="Settings"
244
- >
245
- <Settings size={16} />
246
- <span className="opaca-nav-label">Settings</span>
247
- </Link>
248
- <button
249
- type="button"
250
- onClick={onLogout}
251
- className="opaca-nav-item"
252
- title="Logout"
253
- style={{
254
- width: "100%",
255
- background: "none",
256
- border: "none",
257
- cursor: "pointer",
258
- textAlign: "left",
259
- fontFamily: "inherit",
260
- fontSize: "inherit",
261
- color: "var(--opaca-error)",
262
- }}
263
- >
264
- <LogOut size={16} />
265
- <span className="opaca-nav-label">Logout</span>
266
- </button>
267
- </div>
268
- </div>
269
- </aside>
270
-
271
- <main className="opaca-content">
272
- <div className="opaca-content-inner">{children}</div>
273
- </main>
274
- </div>
275
- );
276
- }
@@ -1,141 +0,0 @@
1
- import { useStore } from "@nanostores/react";
2
- import { Check, ChevronDown, Settings2 } from "lucide-react";
3
- import type React from "react";
4
- import { useEffect, useRef, useState } from "react";
5
- import { $columnVisibility, toggleColumnVisibility } from "../../stores/column-visibility";
6
-
7
- interface ColumnVisibilityToggleProps {
8
- slug: string;
9
- fields: { name?: string; label?: string }[];
10
- }
11
-
12
- export const ColumnVisibilityToggle: React.FC<ColumnVisibilityToggleProps> = ({ slug, fields }) => {
13
- const [isOpen, setIsOpen] = useState(false);
14
- const dropdownRef = useRef<HTMLDivElement>(null);
15
- const visibility = useStore($columnVisibility);
16
-
17
- const visibleColumns = visibility[slug] || [];
18
- const selectableFields = fields.filter((f) => f.name);
19
-
20
- // Close dropdown when clicking outside
21
- useEffect(() => {
22
- const handleClickOutside = (event: MouseEvent) => {
23
- if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {
24
- setIsOpen(false);
25
- }
26
- };
27
- document.addEventListener("mousedown", handleClickOutside);
28
- return () => document.removeEventListener("mousedown", handleClickOutside);
29
- }, []);
30
-
31
- return (
32
- <div className="opaca-column-toggle" ref={dropdownRef} style={{ position: "relative" }}>
33
- <button
34
- type="button"
35
- onClick={() => setIsOpen(!isOpen)}
36
- className="opaca-btn opaca-btn-outline"
37
- style={{
38
- display: "flex",
39
- alignItems: "center",
40
- gap: "0.5rem",
41
- padding: "0.5rem 0.75rem",
42
- fontSize: "0.875rem",
43
- }}
44
- >
45
- <Settings2 size={16} />
46
- Columns
47
- <ChevronDown
48
- size={14}
49
- style={{
50
- opacity: 0.5,
51
- transform: isOpen ? "rotate(180deg)" : "none",
52
- transition: "transform 0.2s",
53
- }}
54
- />
55
- </button>
56
-
57
- {isOpen && (
58
- <div
59
- className="opaca-card shadow-lg"
60
- style={{
61
- position: "absolute",
62
- top: "calc(100% + 0.5rem)",
63
- right: 0,
64
- zIndex: 100,
65
- minWidth: "200px",
66
- padding: "0.5rem",
67
- maxHeight: "300px",
68
- overflowY: "auto",
69
- border: "1px solid var(--opaca-border)",
70
- backgroundColor: "var(--opaca-card-bg)",
71
- borderRadius: "var(--opaca-radius)",
72
- }}
73
- >
74
- <div
75
- style={{
76
- padding: "0.5rem",
77
- fontSize: "0.75rem",
78
- fontWeight: 600,
79
- color: "var(--opaca-text-dim)",
80
- borderBottom: "1px solid var(--opaca-border)",
81
- marginBottom: "0.25rem",
82
- }}
83
- >
84
- Toggle Columns
85
- </div>
86
- {selectableFields.map((field) => {
87
- const isVisible = visibleColumns.includes(field.name!);
88
- return (
89
- <button
90
- key={field.name}
91
- type="button"
92
- onClick={() => toggleColumnVisibility(slug, field.name!)}
93
- style={{
94
- width: "100%",
95
- display: "flex",
96
- alignItems: "center",
97
- gap: "0.75rem",
98
- padding: "0.5rem 0.75rem",
99
- fontSize: "0.875rem",
100
- textAlign: "left",
101
- background: "none",
102
- border: "none",
103
- color: isVisible ? "var(--opaca-text)" : "var(--opaca-text-dim)",
104
- cursor: "pointer",
105
- borderRadius: "calc(var(--opaca-radius) - 4px)",
106
- transition: "background 0.2s",
107
- }}
108
- className="hover-bg"
109
- >
110
- <div
111
- style={{
112
- width: "16px",
113
- height: "16px",
114
- display: "flex",
115
- alignItems: "center",
116
- justifyContent: "center",
117
- border: isVisible
118
- ? "1px solid var(--opaca-primary)"
119
- : "1px solid var(--opaca-border)",
120
- backgroundColor: isVisible ? "var(--opaca-primary)" : "transparent",
121
- borderRadius: "4px",
122
- color: "white",
123
- }}
124
- >
125
- {isVisible && <Check size={12} strokeWidth={3} />}
126
- </div>
127
- <span style={{ flex: 1 }}>{field.label || field.name}</span>
128
- </button>
129
- );
130
- })}
131
- </div>
132
- )}
133
-
134
- <style>{`
135
- .hover-bg:hover {
136
- background-color: var(--opaca-panel-bg) !important;
137
- }
138
- `}</style>
139
- </div>
140
- );
141
- };
@@ -1,141 +0,0 @@
1
- import { Edit2, Save, X } from "lucide-react";
2
- import type React from "react";
3
- import { useEffect, useState } from "react";
4
- import { DataDetailView } from "./DataDetailView";
5
- import { Button } from "./ui/button";
6
- import { ScrollArea } from "./ui/scroll-area";
7
- import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from "./ui/sheet";
8
- import "../styles/data-detail.scss";
9
-
10
- interface DataDetailSheetProps {
11
- open: boolean;
12
- onOpenChange: (open: boolean) => void;
13
- title: string;
14
- description?: string;
15
- data: any;
16
- onSave?: (updatedData: any) => void;
17
- field?: string;
18
- }
19
-
20
- import { useStore } from "@nanostores/react";
21
- import { $config } from "../../stores/config";
22
-
23
- export const DataDetailSheet: React.FC<DataDetailSheetProps> = ({
24
- open,
25
- onOpenChange,
26
- title,
27
- description,
28
- data: initialData,
29
- onSave,
30
- field,
31
- }) => {
32
- const [isEditing, setIsEditing] = useState(false);
33
- const [data, setData] = useState(initialData);
34
-
35
- const config = useStore($config) as any;
36
- const i18nConfig = config?.i18n;
37
-
38
- const [activeLocale, setActiveLocale] = useState(i18nConfig?.defaultLocale || "default");
39
-
40
- useEffect(() => {
41
- setData(initialData);
42
- setIsEditing(false);
43
- if (i18nConfig) {
44
- setActiveLocale(i18nConfig.defaultLocale);
45
- }
46
- }, [initialData, open, i18nConfig]);
47
-
48
- const handleSave = () => {
49
- if (onSave) {
50
- onSave(data);
51
- }
52
- setIsEditing(false);
53
- };
54
-
55
- return (
56
- <Sheet open={open} onOpenChange={onOpenChange}>
57
- <SheetContent onClose={() => onOpenChange(false)} className="opaca-data-detail-sheet">
58
- <div style={{ display: "flex", flexDirection: "column", height: "100%" }}>
59
- <SheetHeader>
60
- <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
61
- <div>
62
- <SheetTitle>{title}</SheetTitle>
63
- {description && <SheetDescription>{description}</SheetDescription>}
64
- </div>
65
- {onSave && (
66
- <div style={{ display: "flex", gap: "0.5rem", alignItems: "center" }}>
67
- {isEditing && i18nConfig && i18nConfig.locales.length > 0 && (
68
- <div
69
- style={{
70
- display: "flex",
71
- borderRight: "1px solid var(--border)",
72
- paddingRight: "0.5rem",
73
- marginRight: "0.5rem",
74
- gap: "0.25rem",
75
- }}
76
- >
77
- {i18nConfig.locales.map((locale: string) => (
78
- <Button
79
- key={locale}
80
- variant={activeLocale === locale ? "default" : "outline"}
81
- size="sm"
82
- onClick={() => setActiveLocale(locale)}
83
- style={{ height: "32px", fontSize: "12px" }}
84
- >
85
- {locale.toUpperCase()}
86
- </Button>
87
- ))}
88
- </div>
89
- )}
90
- {!isEditing ? (
91
- <Button
92
- variant="outline"
93
- size="sm"
94
- onClick={() => setIsEditing(true)}
95
- style={{ height: "32px", gap: "4px" }}
96
- >
97
- <Edit2 size={14} />
98
- Edit
99
- </Button>
100
- ) : (
101
- <>
102
- <Button
103
- variant="ghost"
104
- size="sm"
105
- onClick={() => {
106
- setData(initialData);
107
- setIsEditing(false);
108
- }}
109
- style={{ height: "32px", gap: "4px" }}
110
- >
111
- <X size={14} />
112
- Cancel
113
- </Button>
114
- <Button
115
- variant="default"
116
- size="sm"
117
- onClick={handleSave}
118
- style={{ height: "32px", gap: "4px" }}
119
- >
120
- <Save size={14} />
121
- Save
122
- </Button>
123
- </>
124
- )}
125
- </div>
126
- )}
127
- </div>
128
- </SheetHeader>
129
-
130
- <div style={{ flex: 1, minHeight: 0, marginTop: "1.5rem" }}>
131
- <ScrollArea style={{ height: "100%" }}>
132
- <div style={{ paddingRight: "1rem", paddingBottom: "2rem" }}>
133
- <DataDetailView data={data} isEditing={isEditing} onChange={setData} />
134
- </div>
135
- </ScrollArea>
136
- </div>
137
- </div>
138
- </SheetContent>
139
- </Sheet>
140
- );
141
- };