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
package/global.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import "hono";
2
- import type { OpacaConfig, User } from "./src/types";
3
- import type { Auth } from "./src/auth/index";
4
-
5
- declare module "hono" {
6
- interface ContextVariableMap {
7
- config: OpacaConfig;
8
- auth: Auth;
9
- user: User;
10
- }
11
- }
@@ -1,63 +0,0 @@
1
- import ky from "ky";
2
-
3
- let client: typeof ky | null = null;
4
- let currentBaseURL: string | null = null;
5
-
6
- export const configureAPI = (serverUrl: string) => {
7
- if (!serverUrl || !serverUrl.startsWith("http")) return;
8
- const url = serverUrl;
9
- const baseURL = url.replace(/\/$/, "");
10
- if (client && currentBaseURL === baseURL) return;
11
-
12
- currentBaseURL = baseURL;
13
- client = ky.create({
14
- prefixUrl: baseURL,
15
- credentials: "include",
16
- retry: 0,
17
- hooks: {
18
- afterResponse: [
19
- async (_request, _options, response) => {
20
- if (response.status === 401 || response.status === 403) {
21
- // Se o auth handler do backend falhar globalmente em qualquer requisição da API (sessão morreu/expirada)
22
- // Lançamos a revalidação da store local para despachar o usuário pra tela de login.
23
- try {
24
- const { $session } = await import("./stores/auth");
25
- const { notify } = await import("./stores/ui");
26
- $session.set(null);
27
- notify("Session expired. Please log in again.", "error");
28
- } catch (e) {}
29
- }
30
- },
31
- ],
32
- },
33
- });
34
- };
35
-
36
- export const getCurrentBaseURL = () => {
37
- if (!currentBaseURL) {
38
- throw new Error("API client not configured. Did you provide a valid serverUrl?");
39
- }
40
- return currentBaseURL as string;
41
- };
42
-
43
- /**
44
- * A proxy for ky that allows us to configure the baseURL late
45
- * (e.g. after we have the serverURL from props).
46
- * @param prop: string
47
- */
48
- export const api = new Proxy({} as typeof ky, {
49
- get(_, prop) {
50
- if (!client) {
51
- // No auto-fallback for web components.
52
- throw new Error("API client not configured. Did you provide a valid serverUrl?");
53
- }
54
-
55
- if (!client) throw new Error("API client not configured");
56
-
57
- const c = client;
58
- if (c) {
59
- return c[prop as keyof typeof ky];
60
- }
61
- return undefined;
62
- },
63
- });
@@ -1,40 +0,0 @@
1
- import { createAuthClient } from "better-auth/client";
2
- import { adminClient } from "better-auth/client/plugins";
3
- import { logger } from "@/utils/logger";
4
-
5
- let client: ReturnType<typeof createAuthClient> | null = null;
6
- let currentURL: string | null = null;
7
-
8
- export const configureAuth = (serverUrl: string) => {
9
- if (!serverUrl || !serverUrl.startsWith("http")) return;
10
- const url = serverUrl;
11
- const baseURL = url.replace(/\/$/, "") + "/api/auth";
12
- if (client && currentURL === baseURL) return;
13
-
14
- currentURL = baseURL;
15
- client = createAuthClient({
16
- baseURL,
17
- autoRefresh: true,
18
- fetchOptions: {
19
- credentials: "include",
20
- },
21
- plugins: [adminClient()],
22
- });
23
- };
24
-
25
- /**
26
- * A proxy for the authClient that allows us to configure it late
27
- * (e.g. after we have the user's config with serverURL).
28
- */
29
- export const authClient = new Proxy({} as ReturnType<typeof createAuthClient>, {
30
- get(_, prop) {
31
- if (!client) {
32
- // No auto-fallback to origin for web components.
33
- // AdminClient will call configureAuth when it has the correct prop.
34
- throw new Error("Auth client not configured. Did you provide a valid serverUrl?");
35
- }
36
- return (client as ReturnType<typeof createAuthClient>)[
37
- prop as keyof ReturnType<typeof createAuthClient>
38
- ];
39
- },
40
- });
@@ -1,179 +0,0 @@
1
- export interface CustomFieldProps<TValue = any, TConfig = Record<string, any>> {
2
- /** The current value of the field from the CMS database */
3
- value: TValue;
4
- /** The full schema configuration of the field */
5
- fieldConfig: TConfig;
6
- /** Whether the field is currently disabled by access control */
7
- disabled: boolean;
8
- /** Whether the field is currently read-only by access control */
9
- readOnly: boolean;
10
- /** A validation error message from the CMS, if any */
11
- error?: string;
12
- /** The current full state of the parent form or row */
13
- parentData?: Record<string, unknown>;
14
- /** Callback to notify the CMS that the data has changed */
15
- onChange: (value: TValue) => void;
16
- }
17
-
18
- export interface CustomFieldAdapter {
19
- /**
20
- * Called exactly once when the field is inserted into the CMS Admin UI.
21
- * Use this to render your React root, Vue app, or Vanilla DOM nodes.
22
- *
23
- * @param container The DOM element acting as the wrapper for your component.
24
- * @param props The initial properties (value, config, onChange) from the CMS.
25
- */
26
- mount: (container: HTMLElement, props: CustomFieldProps) => void;
27
-
28
- /**
29
- * Called whenever the CMS pushes new data to the field (e.g. form resets,
30
- * external value changes).
31
- *
32
- * @param container The same DOM element wrapper.
33
- * @param props The updated properties.
34
- */
35
- update?: (container: HTMLElement, props: CustomFieldProps) => void;
36
-
37
- /**
38
- * Called exactly once when the field is removed from the DOM (e.g., navigating away).
39
- * Use this to unmount your React root or Vue app to prevent memory leaks.
40
- *
41
- * @param container The same DOM element wrapper.
42
- */
43
- unmount?: (container: HTMLElement) => void;
44
- }
45
-
46
- /**
47
- * A built-in utility to register framework-agnostic Custom Web Components for the OpacaCMS Admin UI.
48
- *
49
- * It acts as an adapter, translating the Web Component lifecycle (`connectedCallback`, `disconnectedCallback`,
50
- * property setters) into a simple `mount` / `update` / `unmount` paradigm that can easily wrap React, Vue, Angular,
51
- * or plain Javascript applications.
52
- *
53
- * @example
54
- * ```tsx
55
- * import { defineCustomField } from 'opacacms/admin';
56
- * import { createRoot } from 'react-dom/client';
57
- *
58
- * defineCustomField('my-react-picker', {
59
- * mount: (container, props) => {
60
- * (container as any)._root = createRoot(container);
61
- * (container as any)._root.render(<MyPicker {...props} />);
62
- * },
63
- * update: (container, props) => {
64
- * (container as any)._root.render(<MyPicker {...props} />);
65
- * },
66
- * unmount: (container) => {
67
- * (container as any)._root.unmount();
68
- * }
69
- * });
70
- * ```
71
- *
72
- * @param tagName The tag name to register in the browser (e.g., `opaca-color-picker`). Must contain a hyphen.
73
- * @param adapter The adapter containing `mount`, optional `update`, and optional `unmount` lifecycle methods.
74
- */
75
- export function defineCustomField(tagName: string, adapter: CustomFieldAdapter) {
76
- if (typeof window === "undefined") return;
77
-
78
- if (customElements.get(tagName)) {
79
- console.warn(`[OpacaCMS] Custom field tag "${tagName}" is already defined.`);
80
- return;
81
- }
82
-
83
- class OpacaCustomFieldElement extends HTMLElement {
84
- private _value: any;
85
- private _fieldConfig: any;
86
- private _error?: string;
87
- private _parentData?: Record<string, unknown>;
88
- private _isMounted = false;
89
-
90
- // Helper to abstract the complex CustomEvent away from the user's DX
91
- private handleChange = (newValue: any) => {
92
- this.dispatchEvent(
93
- new CustomEvent("opacachange", {
94
- detail: { value: newValue },
95
- bubbles: true,
96
- composed: true,
97
- }),
98
- );
99
- };
100
-
101
- private getProps(): CustomFieldProps {
102
- return {
103
- value: this._value,
104
- fieldConfig: this._fieldConfig,
105
- disabled: this.getAttribute("data-disabled") === "true",
106
- readOnly: this.getAttribute("data-readonly") === "true",
107
- error: this._error,
108
- parentData: this._parentData,
109
- onChange: this.handleChange,
110
- };
111
- }
112
-
113
- set error(err: string | undefined) {
114
- if (this._error !== err) {
115
- this._error = err;
116
- if (this._isMounted && adapter.update) {
117
- adapter.update(this, this.getProps());
118
- }
119
- }
120
- }
121
-
122
- get error() {
123
- return this._error;
124
- }
125
-
126
- set parentData(data: Record<string, unknown> | undefined) {
127
- this._parentData = data;
128
- if (this._isMounted && adapter.update) {
129
- adapter.update(this, this.getProps());
130
- }
131
- }
132
-
133
- get parentData() {
134
- return this._parentData;
135
- }
136
-
137
- set value(val: any) {
138
- const oldValue = this._value;
139
- this._value = val;
140
- // Only call update if the value actually changed and the component is mounted
141
- if (this._isMounted && adapter.update && oldValue !== val) {
142
- adapter.update(this, this.getProps());
143
- }
144
- }
145
-
146
- get value() {
147
- return this._value;
148
- }
149
-
150
- set fieldConfig(config: any) {
151
- this._fieldConfig = config;
152
- if (this._isMounted && adapter.update) {
153
- adapter.update(this, this.getProps());
154
- }
155
- }
156
-
157
- get fieldConfig() {
158
- return this._fieldConfig;
159
- }
160
-
161
- connectedCallback() {
162
- if (!this._isMounted) {
163
- adapter.mount(this, this.getProps());
164
- this._isMounted = true;
165
- }
166
- }
167
-
168
- disconnectedCallback() {
169
- if (this._isMounted) {
170
- if (adapter.unmount) {
171
- adapter.unmount(this);
172
- }
173
- this._isMounted = false;
174
- }
175
- }
176
- }
177
-
178
- customElements.define(tagName, OpacaCustomFieldElement);
179
- }
@@ -1,15 +0,0 @@
1
- export {
2
- type CustomFieldAdapter,
3
- type CustomFieldProps,
4
- defineCustomField,
5
- } from "./custom-field";
6
- export { defineReactField } from "./react";
7
- export * from "./router";
8
- export * from "./stores/config";
9
- export * from "./stores/query";
10
- export * from "./stores/ui";
11
- export { AdminClient } from "./ui/admin-client";
12
- export { AdminLayout } from "./ui/admin-layout";
13
- export { Breadcrumbs } from "./ui/components/ui/breadcrumbs";
14
- export { Link } from "./ui/components/link";
15
- export { Toast, ToastContainer } from "./ui/components/toast";
@@ -1,72 +0,0 @@
1
- import React from 'react';
2
- import { createRoot, type Root } from 'react-dom/client';
3
- import { type CustomFieldProps, defineCustomField } from './custom-field';
4
-
5
- /**
6
- * A helper utility to quickly register a React component as an OpacaCMS Custom Field.
7
- *
8
- * This function abstracts away the boilerplate of converting a React component into a Custom Element,
9
- * managing the `createRoot` mounting process, and properly passing down props (`value`, `error`, `onChange`, etc.).
10
- *
11
- * @example
12
- * ```tsx
13
- * import { defineReactField } from 'opacacms/admin/react';
14
- *
15
- * const MyPicker = ({ value, onChange, error }) => (
16
- * <div>
17
- * <input value={value || ''} onChange={e => onChange(e.target.value)} />
18
- * {error && <span style={{ color: 'red' }}>{error}</span>}
19
- * </div>
20
- * );
21
- *
22
- * defineReactField('my-react-picker', MyPicker);
23
- * ```
24
- *
25
- * @param tagName The custom element tag name (must contain a hyphen, e.g., 'opaca-custom-picker').
26
- * @param Component The React functional or class component to render.
27
- */
28
- interface OpacaContainer extends HTMLElement {
29
- _opacaReactRoot?: Root;
30
- }
31
-
32
- export function defineReactField<TValue = any, TConfig = Record<string, any>>(
33
- tagName: string,
34
- Component: React.ComponentType<CustomFieldProps<TValue, TConfig>>,
35
- ) {
36
- defineCustomField(tagName, {
37
- mount: (container, props) => {
38
- const el = container as OpacaContainer;
39
- const root = createRoot(el);
40
- el._opacaReactRoot = root;
41
- root.render(
42
- React.createElement(
43
- Component,
44
- props as CustomFieldProps<TValue, TConfig>,
45
- ),
46
- );
47
- },
48
- update: (container, props) => {
49
- const el = container as OpacaContainer;
50
- const root = el._opacaReactRoot;
51
- if (root) {
52
- root.render(
53
- React.createElement(
54
- Component,
55
- props as CustomFieldProps<TValue, TConfig>,
56
- ),
57
- );
58
- }
59
- },
60
- unmount: (container) => {
61
- const el = container as OpacaContainer;
62
- const root = el._opacaReactRoot;
63
- if (root) {
64
- // Schedule unmount to avoid synchronous React 18+ unmount warnings during DOM teardown
65
- setTimeout(() => {
66
- root.unmount();
67
- delete el._opacaReactRoot;
68
- }, 0);
69
- }
70
- },
71
- });
72
- }
@@ -1,9 +0,0 @@
1
- import { createRouter } from "@nanostores/router";
2
-
3
- export const $router = createRouter({
4
- dashboard: "/admin",
5
- collections: "/admin/collections/:slug",
6
- document: "/admin/collections/:slug/:id",
7
- globals: "/admin/globals/:slug",
8
- settings: "/admin/settings",
9
- });
@@ -1,121 +0,0 @@
1
- import { atom, computed } from "nanostores";
2
- import type { PaginatedResult } from "../../types";
3
- import { api } from "../api-client";
4
- import { createFetcherStore, createMutatorStore } from "./query";
5
-
6
- // --- Collection List ---
7
- export interface CollectionQueryParams {
8
- slug: string;
9
- page?: number;
10
- limit?: number;
11
- sort?: string;
12
- search?: string;
13
- searchField?: string;
14
- filter?: Record<string, unknown>;
15
- populate?: string;
16
- }
17
-
18
- export const $collectionQuery = atom<CollectionQueryParams | null>(null);
19
-
20
- const $collectionUrl = computed($collectionQuery, (params) => {
21
- if (!params) return null;
22
-
23
- const searchParams = new URLSearchParams();
24
- if (params.page) searchParams.set("page", params.page.toString());
25
- if (params.limit) searchParams.set("limit", params.limit.toString());
26
- if (params.sort) searchParams.set("sort", params.sort);
27
-
28
- if (params.filter) {
29
- for (const [key, value] of Object.entries(params.filter)) {
30
- if (typeof value === "object" && value !== null) {
31
- // Handle nested filter operators like { status: { equals: 'draft' } }
32
- for (const [op, val] of Object.entries(value)) {
33
- searchParams.set(`${key}[${op}]`, String(val));
34
- }
35
- } else {
36
- searchParams.set(`${key}[equals]`, String(value));
37
- }
38
- }
39
- }
40
-
41
- if (params.search && params.searchField) {
42
- searchParams.set(`${params.searchField}[like]`, `%${params.search}%`);
43
- } else if (params.search) {
44
- searchParams.set("search", params.search);
45
- }
46
-
47
- if (params.populate) {
48
- searchParams.set("populate", params.populate);
49
- }
50
-
51
- const query = searchParams.toString();
52
- return `api/${params.slug}${query ? `?${query}` : ""}`;
53
- });
54
-
55
- export const $collectionData = createFetcherStore<PaginatedResult<Record<string, unknown>>>([
56
- $collectionUrl,
57
- ]);
58
-
59
- // --- Document Edit ---
60
- export interface DocumentQueryParams {
61
- slug: string;
62
- id: string;
63
- }
64
-
65
- export const $documentQuery = atom<DocumentQueryParams | null>(null);
66
-
67
- const $documentUrl = computed($documentQuery, (params) => {
68
- if (!params) return null;
69
- return `api/${params.slug}/${params.id}`;
70
- });
71
-
72
- export const $documentData = createFetcherStore<Record<string, unknown>>([$documentUrl]);
73
-
74
- export interface SaveDocumentParams {
75
- slug: string;
76
- id: string;
77
- body: Record<string, unknown>;
78
- }
79
-
80
- export const $saveDocument = createMutatorStore<SaveDocumentParams, Record<string, unknown>>(
81
- async ({ data, revalidate }) => {
82
- const { slug, id, body } = data;
83
- const method = id === "create" ? "post" : "patch";
84
- const url = `api/${slug}${id === "create" ? "" : `/${id}`}`;
85
-
86
- const res = await api[method](url, { json: body }).json<Record<string, unknown>>();
87
-
88
- // Revalidate the list and the document
89
- revalidate(`api/${slug}`);
90
- revalidate(`api/${slug}/${id}`);
91
-
92
- return res;
93
- },
94
- );
95
-
96
- // --- Global Edit ---
97
- export const $globalQuery = atom<string | null>(null);
98
-
99
- const $globalUrl = computed($globalQuery, (slug) => {
100
- if (!slug) return null;
101
- return `api/globals/${slug}`;
102
- });
103
-
104
- export const $globalData = createFetcherStore<Record<string, unknown>>([$globalUrl]);
105
-
106
- export interface SaveGlobalParams {
107
- slug: string;
108
- body: Record<string, unknown>;
109
- }
110
-
111
- export const $saveGlobal = createMutatorStore<SaveGlobalParams, Record<string, unknown>>(
112
- async ({ data, revalidate }) => {
113
- const { slug, body } = data;
114
- const res = await api
115
- .patch(`api/globals/${slug}`, { json: body })
116
- .json<Record<string, unknown>>();
117
-
118
- revalidate(`api/globals/${slug}`);
119
- return res;
120
- },
121
- );
@@ -1,61 +0,0 @@
1
- import { atom, computed } from "nanostores";
2
- import { authClient } from "../auth-client";
3
- import { notify } from "./ui";
4
-
5
- export const $session = atom<any>(null);
6
- export const $isAuthPending = atom(true);
7
-
8
- export const $user = computed($session, (session) => session?.user ?? null);
9
- export const $isAuthenticated = computed($session, (session) => !!session);
10
-
11
- // Synchronize session
12
- export async function syncSession() {
13
- $isAuthPending.set(true);
14
- try {
15
- const res = await authClient.getSession();
16
- $session.set(res.data);
17
- } catch (err) {
18
- console.error("[OpacaCMS] Failed to sync session:", err);
19
- } finally {
20
- $isAuthPending.set(false);
21
- }
22
- }
23
-
24
- export async function login(data: Record<string, string>) {
25
- $isAuthPending.set(true);
26
- try {
27
- const res = await authClient.signIn.email({
28
- email: data.email as string,
29
- password: data.password as string,
30
- });
31
-
32
- if (res.error) {
33
- throw new Error(res.error.message || "Invalid credentials");
34
- }
35
-
36
- // Force re-fetch the session from the server immediately after successful sign-in
37
- // so the Nano Store reacts and the AdminClient flips from LoginView to DashboardView.
38
- await syncSession();
39
-
40
- notify("Logged in successfully", "success");
41
- return res;
42
- } catch (error) {
43
- notify(error instanceof Error ? error.message : "Login failed", "error");
44
- throw error;
45
- } finally {
46
- $isAuthPending.set(false);
47
- }
48
- }
49
-
50
- export async function logout() {
51
- $isAuthPending.set(true);
52
- try {
53
- await authClient.signOut();
54
- $session.set(null);
55
- notify("Logged out successfully");
56
- } catch {
57
- notify("Logout failed", "error");
58
- } finally {
59
- $isAuthPending.set(false);
60
- }
61
- }
@@ -1,67 +0,0 @@
1
- import { persistentAtom } from "@nanostores/persistent";
2
-
3
- /**
4
- * Stores column visibility preferences per collection.
5
- * Key: collection slug
6
- * Value: JSON string of string[] containing visible field names
7
- */
8
- export const $columnVisibility = persistentAtom<Record<string, string[]>>(
9
- "opaca-column-visibility",
10
- {},
11
- {
12
- encode: JSON.stringify,
13
- decode: JSON.parse,
14
- },
15
- );
16
-
17
- /**
18
- * Toggle visibility of a column in a collection
19
- */
20
- export function toggleColumnVisibility(slug: string, fieldName: string) {
21
- const current = $columnVisibility.get();
22
- const visibleColumns = current[slug] || [];
23
-
24
- const nextVisibleColumns = visibleColumns.includes(fieldName)
25
- ? visibleColumns.filter((col) => col !== fieldName)
26
- : [...visibleColumns, fieldName];
27
-
28
- $columnVisibility.set({
29
- ...current,
30
- [slug]: nextVisibleColumns,
31
- });
32
- }
33
-
34
- /**
35
- * Set visible columns for a collection
36
- */
37
- export function setVisibleColumns(slug: string, columns: string[]) {
38
- const current = $columnVisibility.get();
39
- $columnVisibility.set({
40
- ...current,
41
- [slug]: columns,
42
- });
43
- }
44
-
45
- /**
46
- * Initialize column visibility for a collection if not already set.
47
- * Uses defaultColumns from config or all available named fields.
48
- */
49
- export function initColumnVisibility(
50
- slug: string,
51
- fields: { name?: string }[],
52
- defaultColumns?: string[],
53
- ) {
54
- const current = $columnVisibility.get();
55
- if (current[slug]) return; // Already initialized
56
-
57
- // If defaultColumns is provided, use it. Otherwise use all named fields.
58
- const initialColumns =
59
- defaultColumns && defaultColumns.length > 0
60
- ? defaultColumns
61
- : fields.filter((f) => f.name).map((f) => f.name!);
62
-
63
- $columnVisibility.set({
64
- ...current,
65
- [slug]: initialColumns,
66
- });
67
- }
@@ -1,15 +0,0 @@
1
- import { atom } from "nanostores";
2
- import type { SerializableConfig } from "../../types";
3
-
4
- export const $config = atom<SerializableConfig | null>(null);
5
- export const $needsInit = atom<boolean>(false);
6
- export const $isFetchingConfig = atom<boolean>(false);
7
- export const $hasMetadataError = atom<boolean>(false);
8
-
9
- export function setConfig(config: SerializableConfig | null) {
10
- $config.set(config);
11
- }
12
-
13
- export function setNeedsInit(needs: boolean) {
14
- $needsInit.set(needs);
15
- }