opacacms 0.1.0 → 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 (247) hide show
  1. package/dist/admin/index.js +49 -0
  2. package/dist/{chunk-2zm8cy1w.js → admin/webcomponent.js} +116 -168
  3. package/dist/{chunk-6dhs73zq.js → chunk-2yz1nsxs.js} +1 -1
  4. package/dist/chunk-fa5mg0hr.js +96 -0
  5. package/dist/{chunk-kwp83w8b.js → chunk-m09hahe2.js} +7 -7
  6. package/dist/{chunk-hmhcense.js → chunk-ry15hke8.js} +253 -4
  7. package/dist/chunk-vtvqfhgy.js +2442 -0
  8. package/dist/{chunk-f3nvxn63.js → chunk-y8hc6nm4.js} +1 -1
  9. package/dist/{src/cli → cli}/index.js +10 -10
  10. package/dist/{src/client.js → client.js} +2 -2
  11. package/dist/{src/db → db}/bun-sqlite.js +10 -10
  12. package/dist/{src/db → db}/d1.js +8 -8
  13. package/dist/db/index.d.ts +2 -0
  14. package/dist/db/index.js +7 -0
  15. package/dist/db/migration.d.ts +39 -0
  16. package/dist/{src/db → db}/postgres.js +10 -10
  17. package/dist/{src/db → db}/sqlite.js +8 -8
  18. package/dist/index.d.ts +0 -2
  19. package/dist/index.js +13 -0
  20. package/dist/{src/runtimes → runtimes}/bun.js +5 -6
  21. package/dist/{src/runtimes → runtimes}/cloudflare-workers.js +5 -6
  22. package/dist/{src/runtimes → runtimes}/next.js +5 -6
  23. package/dist/{src/runtimes → runtimes}/node.js +5 -6
  24. package/dist/{src/server.js → server.js} +7 -8
  25. package/dist/storage/index.d.ts +0 -3
  26. package/dist/storage/index.js +35 -0
  27. package/dist/types.d.ts +5 -2
  28. package/package.json +161 -39
  29. package/bun.lock +0 -34
  30. package/dist/api.d.ts +0 -6
  31. package/dist/chunk-8gkhn1d4.js +0 -309
  32. package/dist/chunk-dy5t83hr.js +0 -261
  33. package/dist/src/admin/index.js +0 -176
  34. package/dist/src/admin/webcomponent.js +0 -19
  35. package/dist/src/api.js +0 -27
  36. package/dist/src/index.js +0 -20
  37. package/dist/src/storage/index.js +0 -355
  38. package/global.d.ts +0 -11
  39. package/src/admin/api-client.ts +0 -63
  40. package/src/admin/auth-client.ts +0 -40
  41. package/src/admin/custom-field.ts +0 -179
  42. package/src/admin/index.ts +0 -15
  43. package/src/admin/react.tsx +0 -72
  44. package/src/admin/router.ts +0 -9
  45. package/src/admin/stores/admin-queries.ts +0 -121
  46. package/src/admin/stores/auth.ts +0 -61
  47. package/src/admin/stores/column-visibility.ts +0 -67
  48. package/src/admin/stores/config.ts +0 -15
  49. package/src/admin/stores/media.ts +0 -95
  50. package/src/admin/stores/query.ts +0 -13
  51. package/src/admin/stores/ui.ts +0 -29
  52. package/src/admin/ui/admin-client.tsx +0 -283
  53. package/src/admin/ui/admin-layout.tsx +0 -276
  54. package/src/admin/ui/components/ColumnVisibilityToggle.tsx +0 -141
  55. package/src/admin/ui/components/DataDetailSheet.tsx +0 -141
  56. package/src/admin/ui/components/DataDetailView.tsx +0 -175
  57. package/src/admin/ui/components/Table.tsx +0 -67
  58. package/src/admin/ui/components/fields/ArrayField.tsx +0 -166
  59. package/src/admin/ui/components/fields/BlocksField.tsx +0 -202
  60. package/src/admin/ui/components/fields/BooleanField.tsx +0 -50
  61. package/src/admin/ui/components/fields/CollapsibleField.tsx +0 -75
  62. package/src/admin/ui/components/fields/DateField.tsx +0 -45
  63. package/src/admin/ui/components/fields/FileField.tsx +0 -322
  64. package/src/admin/ui/components/fields/GroupField.tsx +0 -50
  65. package/src/admin/ui/components/fields/JoinField.tsx +0 -23
  66. package/src/admin/ui/components/fields/NumberField.tsx +0 -46
  67. package/src/admin/ui/components/fields/RadioField.tsx +0 -62
  68. package/src/admin/ui/components/fields/RelationshipField.tsx +0 -278
  69. package/src/admin/ui/components/fields/RowField.tsx +0 -40
  70. package/src/admin/ui/components/fields/SelectField.tsx +0 -59
  71. package/src/admin/ui/components/fields/TabsField.tsx +0 -101
  72. package/src/admin/ui/components/fields/TextAreaField.tsx +0 -54
  73. package/src/admin/ui/components/fields/TextField.tsx +0 -49
  74. package/src/admin/ui/components/fields/VirtualField.tsx +0 -53
  75. package/src/admin/ui/components/fields/index.tsx +0 -371
  76. package/src/admin/ui/components/fields/richtext-editor/index.tsx +0 -211
  77. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageComponent.tsx +0 -142
  78. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageNode.tsx +0 -95
  79. package/src/admin/ui/components/fields/richtext-editor/plugins/ComponentPickerPlugin.tsx +0 -226
  80. package/src/admin/ui/components/fields/richtext-editor/plugins/EditableSyncPlugin.tsx +0 -16
  81. package/src/admin/ui/components/fields/richtext-editor/plugins/NotionToolbarPlugin.tsx +0 -184
  82. package/src/admin/ui/components/fields/richtext-editor/plugins/SimpleToolbarPlugin.tsx +0 -240
  83. package/src/admin/ui/components/fields/richtext-editor/plugins/ValueSyncPlugin.tsx +0 -40
  84. package/src/admin/ui/components/fields/utils.ts +0 -1
  85. package/src/admin/ui/components/link.tsx +0 -41
  86. package/src/admin/ui/components/media/AssetManagerModal.tsx +0 -334
  87. package/src/admin/ui/components/toast.tsx +0 -72
  88. package/src/admin/ui/components/ui/accordion.tsx +0 -51
  89. package/src/admin/ui/components/ui/alert-dialog.tsx +0 -98
  90. package/src/admin/ui/components/ui/blocks.tsx +0 -32
  91. package/src/admin/ui/components/ui/breadcrumbs.tsx +0 -59
  92. package/src/admin/ui/components/ui/button.tsx +0 -26
  93. package/src/admin/ui/components/ui/collapsible.tsx +0 -124
  94. package/src/admin/ui/components/ui/dialog.tsx +0 -79
  95. package/src/admin/ui/components/ui/group.tsx +0 -20
  96. package/src/admin/ui/components/ui/index.ts +0 -17
  97. package/src/admin/ui/components/ui/input.tsx +0 -12
  98. package/src/admin/ui/components/ui/join.tsx +0 -53
  99. package/src/admin/ui/components/ui/label.tsx +0 -11
  100. package/src/admin/ui/components/ui/radio-group.tsx +0 -75
  101. package/src/admin/ui/components/ui/relationship-detail-sheet.tsx +0 -122
  102. package/src/admin/ui/components/ui/relationship.tsx +0 -58
  103. package/src/admin/ui/components/ui/scroll-area.tsx +0 -19
  104. package/src/admin/ui/components/ui/select.tsx +0 -187
  105. package/src/admin/ui/components/ui/separator.tsx +0 -21
  106. package/src/admin/ui/components/ui/sheet.tsx +0 -106
  107. package/src/admin/ui/components/ui/tabs.tsx +0 -116
  108. package/src/admin/ui/components/ui/utils.ts +0 -3
  109. package/src/admin/ui/hooks/use-debounce.ts +0 -15
  110. package/src/admin/ui/styles/_locale-switcher.scss +0 -33
  111. package/src/admin/ui/styles/accordion.scss +0 -60
  112. package/src/admin/ui/styles/animations.scss +0 -41
  113. package/src/admin/ui/styles/asset-manager.scss +0 -547
  114. package/src/admin/ui/styles/badge.scss +0 -13
  115. package/src/admin/ui/styles/base.scss +0 -22
  116. package/src/admin/ui/styles/button.scss +0 -161
  117. package/src/admin/ui/styles/card.scss +0 -13
  118. package/src/admin/ui/styles/collapsible.scss +0 -75
  119. package/src/admin/ui/styles/data-detail.scss +0 -92
  120. package/src/admin/ui/styles/dialog.scss +0 -102
  121. package/src/admin/ui/styles/empty-state.scss +0 -22
  122. package/src/admin/ui/styles/group.scss +0 -19
  123. package/src/admin/ui/styles/index.scss +0 -33
  124. package/src/admin/ui/styles/input.scss +0 -80
  125. package/src/admin/ui/styles/label.scss +0 -12
  126. package/src/admin/ui/styles/layout.scss +0 -56
  127. package/src/admin/ui/styles/lexical.scss +0 -469
  128. package/src/admin/ui/styles/loading.scss +0 -102
  129. package/src/admin/ui/styles/media-registry.scss +0 -597
  130. package/src/admin/ui/styles/pagination.scss +0 -20
  131. package/src/admin/ui/styles/radio-group.scss +0 -66
  132. package/src/admin/ui/styles/row.scss +0 -17
  133. package/src/admin/ui/styles/scrollbar.scss +0 -36
  134. package/src/admin/ui/styles/select.scss +0 -121
  135. package/src/admin/ui/styles/separator.scss +0 -14
  136. package/src/admin/ui/styles/sheet.scss +0 -152
  137. package/src/admin/ui/styles/sidebar.scss +0 -148
  138. package/src/admin/ui/styles/switch.scss +0 -59
  139. package/src/admin/ui/styles/table.scss +0 -207
  140. package/src/admin/ui/styles/tabs.scss +0 -62
  141. package/src/admin/ui/styles/toast.scss +0 -45
  142. package/src/admin/ui/styles/variables.scss +0 -24
  143. package/src/admin/ui/views/collection-list-view.tsx +0 -720
  144. package/src/admin/ui/views/dashboard-view.tsx +0 -263
  145. package/src/admin/ui/views/document-edit-view.tsx +0 -384
  146. package/src/admin/ui/views/global-edit-view.tsx +0 -226
  147. package/src/admin/ui/views/init-view.tsx +0 -182
  148. package/src/admin/ui/views/login-view.tsx +0 -123
  149. package/src/admin/ui/views/media-registry-view.tsx +0 -1104
  150. package/src/admin/ui/views/settings-view.tsx +0 -729
  151. package/src/admin/webcomponent.tsx +0 -15
  152. package/src/api.ts +0 -9
  153. package/src/auth/index.ts +0 -194
  154. package/src/auth/migrations.ts +0 -87
  155. package/src/auth/premissions.ts +0 -46
  156. package/src/cli/commands/generate-types.ts +0 -116
  157. package/src/cli/commands/init.ts +0 -95
  158. package/src/cli/commands/migrate-commands.ts +0 -160
  159. package/src/cli/commands/seed-command.ts +0 -11
  160. package/src/cli/d1-mock.ts +0 -101
  161. package/src/cli/index.test.ts +0 -84
  162. package/src/cli/index.ts +0 -183
  163. package/src/cli/r2-mock.ts +0 -217
  164. package/src/cli/seeding.ts +0 -405
  165. package/src/client.ts +0 -181
  166. package/src/config-utils.ts +0 -102
  167. package/src/config.ts +0 -49
  168. package/src/db/adapter.ts +0 -53
  169. package/src/db/better-sqlite.ts +0 -630
  170. package/src/db/bun-sqlite.ts +0 -646
  171. package/src/db/d1.ts +0 -711
  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 -658
  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 -71
  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 -146
  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
  247. /package/dist/{src/admin/index.css → admin/webcomponent.css} +0 -0
@@ -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
- }
@@ -1,95 +0,0 @@
1
- import { persistentAtom } from "@nanostores/persistent";
2
- import { atom, computed } from "nanostores";
3
- import { api } from "../api-client";
4
- import { createFetcherStore } from "./query";
5
-
6
- export interface AssetDoc {
7
- id: string;
8
- key: string;
9
- filename: string;
10
- originalFilename: string;
11
- original_filename?: string;
12
- mimeType: string;
13
- mime_type?: string;
14
- filesize: number;
15
- bucket: string;
16
- folder: string | null;
17
- altText: string | null;
18
- alt_text?: string | null;
19
- caption: string | null;
20
- createdAt: string;
21
- updatedAt: string;
22
- created_at?: string;
23
- updated_at?: string;
24
- url?: string;
25
- thumbnailUrl?: string;
26
- }
27
-
28
- export interface AssetRegistryData {
29
- docs: AssetDoc[];
30
- folders: { name: string; buckets: string[] }[];
31
- totalDocs: number;
32
- limit: number;
33
- page: number;
34
- totalPages: number;
35
- }
36
-
37
- // Persistent Preferences
38
- export const $mediaViewMode = persistentAtom<"grid" | "list">("opaca-media-view-mode", "grid");
39
- export const $mediaSelectedBucket = persistentAtom<string>("opaca-media-selected-bucket", "all");
40
- export const $bucketColors = persistentAtom<Record<string, string>>(
41
- "opaca-bucket-colors",
42
- {},
43
- {
44
- encode: JSON.stringify,
45
- decode: JSON.parse,
46
- },
47
- );
48
-
49
- // Ephemeral UI State
50
- export const $mediaCurrentFolder = atom<string>("");
51
- export const $mediaSearch = atom<string>("");
52
- export const $mediaPage = atom<number>(1);
53
-
54
- // Reactive fetcher based on state
55
- export const $assets = createFetcherStore<AssetRegistryData>(
56
- ["api/__system/assets", $mediaSelectedBucket, $mediaCurrentFolder, $mediaSearch, $mediaPage],
57
- {
58
- fetcher: (base, bucket, folder, search, page) => {
59
- const params = new URLSearchParams({
60
- bucket: String(bucket),
61
- folder: String(folder),
62
- search: String(search),
63
- page: String(page),
64
- limit: "20",
65
- });
66
- return api.get(`${base}?${params.toString()}`).json();
67
- },
68
- },
69
- );
70
-
71
- // Actions
72
- export const setMediaBucket = (bucket: string) => {
73
- $mediaSelectedBucket.set(bucket);
74
- $mediaCurrentFolder.set(""); // Reset folder when bucket changes to avoid cross-bucket path issues
75
- $mediaPage.set(1); // Reset page on filter change
76
- };
77
-
78
- export const setMediaFolder = (folder: string) => {
79
- $mediaCurrentFolder.set(folder);
80
- $mediaPage.set(1);
81
- };
82
-
83
- export const setMediaSearch = (search: string) => {
84
- $mediaSearch.set(search);
85
- $mediaPage.set(1);
86
- };
87
-
88
- export const setMediaPage = (page: number) => {
89
- $mediaPage.set(page);
90
- };
91
-
92
- export const setBucketColor = (bucket: string, color: string) => {
93
- const current = $bucketColors.get();
94
- $bucketColors.set({ ...current, [bucket]: color });
95
- };
@@ -1,13 +0,0 @@
1
- import { nanoquery } from "@nanostores/query";
2
- import { api } from "../api-client";
3
-
4
- export const [
5
- createFetcherStore,
6
- createMutatorStore,
7
- { invalidateKeys, revalidateKeys, mutateCache },
8
- ] = nanoquery({
9
- fetcher: (...keys) => {
10
- const url = keys.join("");
11
- return api.get(url).json();
12
- },
13
- });
@@ -1,29 +0,0 @@
1
- import { persistentAtom } from "@nanostores/persistent";
2
- import { atom } from "nanostores";
3
-
4
- export interface ToastItem {
5
- id: string;
6
- message: string;
7
- type: "success" | "error" | "info";
8
- }
9
-
10
- export type ToastType = ToastItem["type"];
11
-
12
- export const $toasts = atom<ToastItem[]>([]);
13
- export const $isSidebarCollapsed = persistentAtom<boolean>("opaca-sidebar-collapsed", false, {
14
- encode: JSON.stringify,
15
- decode: JSON.parse,
16
- });
17
-
18
- export function toggleSidebar() {
19
- $isSidebarCollapsed.set(!$isSidebarCollapsed.get());
20
- }
21
-
22
- export function notify(message: string, type: ToastItem["type"] = "success") {
23
- const id = Math.random().toString(36).substring(2, 9);
24
- $toasts.set([...$toasts.get(), { id, message, type }]);
25
- }
26
-
27
- export function clearToast(id: string) {
28
- $toasts.set($toasts.get().filter((t) => t.id !== id));
29
- }