opacacms 0.1.0
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.
- package/bun.lock +34 -0
- package/dist/admin/api-client.d.ts +8 -0
- package/dist/admin/auth-client.d.ts +940 -0
- package/dist/admin/custom-field.d.ts +71 -0
- package/dist/admin/index.d.ts +11 -0
- package/dist/admin/react.d.ts +3 -0
- package/dist/admin/router.d.ts +7 -0
- package/dist/admin/stores/admin-queries.d.ts +32 -0
- package/dist/admin/stores/auth.d.ts +33 -0
- package/dist/admin/stores/column-visibility.d.ts +21 -0
- package/dist/admin/stores/config.d.ts +7 -0
- package/dist/admin/stores/media.d.ts +44 -0
- package/dist/admin/stores/query.d.ts +4 -0
- package/dist/admin/stores/ui.d.ts +11 -0
- package/dist/admin/ui/admin-client.d.ts +7 -0
- package/dist/admin/ui/admin-layout.d.ts +14 -0
- package/dist/admin/ui/components/ColumnVisibilityToggle.d.ts +10 -0
- package/dist/admin/ui/components/DataDetailSheet.d.ts +13 -0
- package/dist/admin/ui/components/DataDetailView.d.ts +9 -0
- package/dist/admin/ui/components/Table.d.ts +10 -0
- package/dist/admin/ui/components/fields/ArrayField.d.ts +13 -0
- package/dist/admin/ui/components/fields/BlocksField.d.ts +17 -0
- package/dist/admin/ui/components/fields/BooleanField.d.ts +13 -0
- package/dist/admin/ui/components/fields/CollapsibleField.d.ts +16 -0
- package/dist/admin/ui/components/fields/DateField.d.ts +13 -0
- package/dist/admin/ui/components/fields/FileField.d.ts +23 -0
- package/dist/admin/ui/components/fields/GroupField.d.ts +13 -0
- package/dist/admin/ui/components/fields/JoinField.d.ts +15 -0
- package/dist/admin/ui/components/fields/NumberField.d.ts +14 -0
- package/dist/admin/ui/components/fields/RadioField.d.ts +17 -0
- package/dist/admin/ui/components/fields/RelationshipField.d.ts +16 -0
- package/dist/admin/ui/components/fields/RowField.d.ts +12 -0
- package/dist/admin/ui/components/fields/SelectField.d.ts +18 -0
- package/dist/admin/ui/components/fields/TabsField.d.ts +15 -0
- package/dist/admin/ui/components/fields/TextAreaField.d.ts +14 -0
- package/dist/admin/ui/components/fields/TextField.d.ts +14 -0
- package/dist/admin/ui/components/fields/VirtualField.d.ts +8 -0
- package/dist/admin/ui/components/fields/index.d.ts +28 -0
- package/dist/admin/ui/components/fields/richtext-editor/index.d.ts +10 -0
- package/dist/admin/ui/components/fields/richtext-editor/nodes/ImageComponent.d.ts +7 -0
- package/dist/admin/ui/components/fields/richtext-editor/nodes/ImageNode.d.ts +27 -0
- package/dist/admin/ui/components/fields/richtext-editor/plugins/ComponentPickerPlugin.d.ts +1 -0
- package/dist/admin/ui/components/fields/richtext-editor/plugins/EditableSyncPlugin.d.ts +5 -0
- package/dist/admin/ui/components/fields/richtext-editor/plugins/NotionToolbarPlugin.d.ts +1 -0
- package/dist/admin/ui/components/fields/richtext-editor/plugins/SimpleToolbarPlugin.d.ts +1 -0
- package/dist/admin/ui/components/fields/richtext-editor/plugins/ValueSyncPlugin.d.ts +5 -0
- package/dist/admin/ui/components/fields/utils.d.ts +1 -0
- package/dist/admin/ui/components/link.d.ts +8 -0
- package/dist/admin/ui/components/media/AssetManagerModal.d.ts +17 -0
- package/dist/admin/ui/components/toast.d.ts +10 -0
- package/dist/admin/ui/components/ui/accordion.d.ts +11 -0
- package/dist/admin/ui/components/ui/alert-dialog.d.ts +12 -0
- package/dist/admin/ui/components/ui/blocks.d.ts +5 -0
- package/dist/admin/ui/components/ui/breadcrumbs.d.ts +7 -0
- package/dist/admin/ui/components/ui/button.d.ts +7 -0
- package/dist/admin/ui/components/ui/collapsible.d.ts +16 -0
- package/dist/admin/ui/components/ui/dialog.d.ts +27 -0
- package/dist/admin/ui/components/ui/group.d.ts +6 -0
- package/dist/admin/ui/components/ui/index.d.ts +17 -0
- package/dist/admin/ui/components/ui/input.d.ts +5 -0
- package/dist/admin/ui/components/ui/join.d.ts +7 -0
- package/dist/admin/ui/components/ui/label.d.ts +3 -0
- package/dist/admin/ui/components/ui/radio-group.d.ts +13 -0
- package/dist/admin/ui/components/ui/relationship-detail-sheet.d.ts +9 -0
- package/dist/admin/ui/components/ui/relationship.d.ts +8 -0
- package/dist/admin/ui/components/ui/scroll-area.d.ts +7 -0
- package/dist/admin/ui/components/ui/select.d.ts +37 -0
- package/dist/admin/ui/components/ui/separator.d.ts +8 -0
- package/dist/admin/ui/components/ui/sheet.d.ts +28 -0
- package/dist/admin/ui/components/ui/tabs.d.ts +17 -0
- package/dist/admin/ui/components/ui/utils.d.ts +1 -0
- package/dist/admin/ui/hooks/use-debounce.d.ts +1 -0
- package/dist/admin/ui/views/collection-list-view.d.ts +5 -0
- package/dist/admin/ui/views/dashboard-view.d.ts +10 -0
- package/dist/admin/ui/views/document-edit-view.d.ts +7 -0
- package/dist/admin/ui/views/global-edit-view.d.ts +19 -0
- package/dist/admin/ui/views/init-view.d.ts +4 -0
- package/dist/admin/ui/views/login-view.d.ts +4 -0
- package/dist/admin/ui/views/media-registry-view.d.ts +7 -0
- package/dist/admin/ui/views/settings-view.d.ts +7 -0
- package/dist/admin/webcomponent.d.ts +1 -0
- package/dist/api.d.ts +6 -0
- package/dist/auth/index.d.ts +2107 -0
- package/dist/auth/migrations.d.ts +5 -0
- package/dist/auth/premissions.d.ts +6 -0
- package/dist/chunk-16vgcf3k.js +88 -0
- package/dist/chunk-2zm8cy1w.js +9482 -0
- package/dist/chunk-5gvbp2qa.js +167 -0
- package/dist/chunk-62ev8gnc.js +41 -0
- package/dist/chunk-6dhs73zq.js +126 -0
- package/dist/chunk-6ew02s0c.js +472 -0
- package/dist/chunk-7a9kn0np.js +116 -0
- package/dist/chunk-8gkhn1d4.js +309 -0
- package/dist/chunk-8sqjbsgt.js +42 -0
- package/dist/chunk-9kxpbcb1.js +85 -0
- package/dist/chunk-cvdd4eqh.js +110 -0
- package/dist/chunk-d3ffeqp9.js +87 -0
- package/dist/chunk-dy5t83hr.js +261 -0
- package/dist/chunk-f3nvxn63.js +17 -0
- package/dist/chunk-hmhcense.js +1352 -0
- package/dist/chunk-j4d50hrx.js +20 -0
- package/dist/chunk-jwjk85ze.js +15 -0
- package/dist/chunk-kwp83w8b.js +250 -0
- package/dist/chunk-s8mqwnm1.js +14 -0
- package/dist/chunk-srsac177.js +85 -0
- package/dist/chunk-v521d72w.js +10 -0
- package/dist/chunk-xa7rjsn2.js +20 -0
- package/dist/chunk-xg35h5a3.js +15 -0
- package/dist/chunk-ybbbqj63.js +130 -0
- package/dist/chunk-zvwb67nd.js +332 -0
- package/dist/cli/commands/generate-types.d.ts +1 -0
- package/dist/cli/commands/init.d.ts +1 -0
- package/dist/cli/commands/migrate-commands.d.ts +5 -0
- package/dist/cli/commands/seed-command.d.ts +2 -0
- package/dist/cli/d1-mock.d.ts +30 -0
- package/dist/cli/index.d.ts +5 -0
- package/dist/cli/index.test.d.ts +1 -0
- package/dist/cli/r2-mock.d.ts +46 -0
- package/dist/cli/seeding.d.ts +17 -0
- package/dist/client.d.ts +51 -0
- package/dist/config-utils.d.ts +6 -0
- package/dist/config.d.ts +10 -0
- package/dist/db/adapter.d.ts +34 -0
- package/dist/db/better-sqlite.d.ts +40 -0
- package/dist/db/bun-sqlite.d.ts +40 -0
- package/dist/db/d1.d.ts +42 -0
- package/dist/db/kysely/data-mapper.d.ts +6 -0
- package/dist/db/kysely/field-mapper.d.ts +22 -0
- package/dist/db/kysely/migration-generator.d.ts +9 -0
- package/dist/db/kysely/query-builder.d.ts +9 -0
- package/dist/db/kysely/schema-builder.d.ts +15 -0
- package/dist/db/kysely/sql-utils.d.ts +1 -0
- package/dist/db/postgres.d.ts +51 -0
- package/dist/db/sqlite.d.ts +41 -0
- package/dist/db/system-schema.d.ts +2 -0
- package/dist/index.d.ts +6 -0
- package/dist/runtimes/bun.d.ts +17 -0
- package/dist/runtimes/cloudflare-workers.d.ts +10 -0
- package/dist/runtimes/next.d.ts +16 -0
- package/dist/runtimes/node.d.ts +18 -0
- package/dist/schema/collection.d.ts +100 -0
- package/dist/schema/fields/base.d.ts +83 -0
- package/dist/schema/fields/index.d.ts +135 -0
- package/dist/schema/global.d.ts +82 -0
- package/dist/schema/index.d.ts +4 -0
- package/dist/schema/infer.d.ts +55 -0
- package/dist/server/admin-router.d.ts +9 -0
- package/dist/server/admin.d.ts +18 -0
- package/dist/server/assets.d.ts +47 -0
- package/dist/server/collection-router.d.ts +14 -0
- package/dist/server/handlers.d.ts +76 -0
- package/dist/server/middlewares/admin.d.ts +6 -0
- package/dist/server/middlewares/auth.d.ts +16 -0
- package/dist/server/middlewares/context.d.ts +9 -0
- package/dist/server/middlewares/cors.d.ts +3 -0
- package/dist/server/middlewares/database-init.d.ts +11 -0
- package/dist/server/middlewares/rate-limit.d.ts +3 -0
- package/dist/server/router.d.ts +7 -0
- package/dist/server/setup-middlewares.d.ts +17 -0
- package/dist/server/system-router.d.ts +9 -0
- package/dist/server.d.ts +6 -0
- package/dist/src/admin/index.css +47 -0
- package/dist/src/admin/index.js +176 -0
- package/dist/src/admin/webcomponent.js +19 -0
- package/dist/src/api.js +27 -0
- package/dist/src/cli/index.js +157 -0
- package/dist/src/client.js +9 -0
- package/dist/src/db/bun-sqlite.js +523 -0
- package/dist/src/db/d1.js +568 -0
- package/dist/src/db/postgres.js +520 -0
- package/dist/src/db/sqlite.js +534 -0
- package/dist/src/index.js +20 -0
- package/dist/src/runtimes/bun.js +36 -0
- package/dist/src/runtimes/cloudflare-workers.js +29 -0
- package/dist/src/runtimes/next.js +26 -0
- package/dist/src/runtimes/node.js +38 -0
- package/dist/src/server.js +27 -0
- package/dist/src/storage/index.js +355 -0
- package/dist/storage/adapters/cloudflare-r2.d.ts +6 -0
- package/dist/storage/adapters/local.d.ts +6 -0
- package/dist/storage/adapters/s3.d.ts +13 -0
- package/dist/storage/errors.d.ts +12 -0
- package/dist/storage/index.d.ts +5 -0
- package/dist/storage/types.d.ts +31 -0
- package/dist/types.d.ts +484 -0
- package/dist/utils/lexical.d.ts +5 -0
- package/dist/utils/logger.d.ts +35 -0
- package/dist/validation.d.ts +300 -0
- package/dist/validator.d.ts +9 -0
- package/global.d.ts +11 -0
- package/package.json +151 -0
- package/src/admin/api-client.ts +63 -0
- package/src/admin/auth-client.ts +40 -0
- package/src/admin/custom-field.ts +179 -0
- package/src/admin/index.ts +15 -0
- package/src/admin/react.tsx +72 -0
- package/src/admin/router.ts +9 -0
- package/src/admin/stores/admin-queries.ts +121 -0
- package/src/admin/stores/auth.ts +61 -0
- package/src/admin/stores/column-visibility.ts +67 -0
- package/src/admin/stores/config.ts +15 -0
- package/src/admin/stores/media.ts +95 -0
- package/src/admin/stores/query.ts +13 -0
- package/src/admin/stores/ui.ts +29 -0
- package/src/admin/ui/admin-client.tsx +283 -0
- package/src/admin/ui/admin-layout.tsx +276 -0
- package/src/admin/ui/components/ColumnVisibilityToggle.tsx +141 -0
- package/src/admin/ui/components/DataDetailSheet.tsx +141 -0
- package/src/admin/ui/components/DataDetailView.tsx +175 -0
- package/src/admin/ui/components/Table.tsx +67 -0
- package/src/admin/ui/components/fields/ArrayField.tsx +166 -0
- package/src/admin/ui/components/fields/BlocksField.tsx +202 -0
- package/src/admin/ui/components/fields/BooleanField.tsx +50 -0
- package/src/admin/ui/components/fields/CollapsibleField.tsx +75 -0
- package/src/admin/ui/components/fields/DateField.tsx +45 -0
- package/src/admin/ui/components/fields/FileField.tsx +322 -0
- package/src/admin/ui/components/fields/GroupField.tsx +50 -0
- package/src/admin/ui/components/fields/JoinField.tsx +23 -0
- package/src/admin/ui/components/fields/NumberField.tsx +46 -0
- package/src/admin/ui/components/fields/RadioField.tsx +62 -0
- package/src/admin/ui/components/fields/RelationshipField.tsx +278 -0
- package/src/admin/ui/components/fields/RowField.tsx +40 -0
- package/src/admin/ui/components/fields/SelectField.tsx +59 -0
- package/src/admin/ui/components/fields/TabsField.tsx +101 -0
- package/src/admin/ui/components/fields/TextAreaField.tsx +54 -0
- package/src/admin/ui/components/fields/TextField.tsx +49 -0
- package/src/admin/ui/components/fields/VirtualField.tsx +53 -0
- package/src/admin/ui/components/fields/index.tsx +371 -0
- package/src/admin/ui/components/fields/richtext-editor/index.tsx +211 -0
- package/src/admin/ui/components/fields/richtext-editor/nodes/ImageComponent.tsx +142 -0
- package/src/admin/ui/components/fields/richtext-editor/nodes/ImageNode.tsx +95 -0
- package/src/admin/ui/components/fields/richtext-editor/plugins/ComponentPickerPlugin.tsx +226 -0
- package/src/admin/ui/components/fields/richtext-editor/plugins/EditableSyncPlugin.tsx +16 -0
- package/src/admin/ui/components/fields/richtext-editor/plugins/NotionToolbarPlugin.tsx +184 -0
- package/src/admin/ui/components/fields/richtext-editor/plugins/SimpleToolbarPlugin.tsx +240 -0
- package/src/admin/ui/components/fields/richtext-editor/plugins/ValueSyncPlugin.tsx +40 -0
- package/src/admin/ui/components/fields/utils.ts +1 -0
- package/src/admin/ui/components/link.tsx +41 -0
- package/src/admin/ui/components/media/AssetManagerModal.tsx +334 -0
- package/src/admin/ui/components/toast.tsx +72 -0
- package/src/admin/ui/components/ui/accordion.tsx +51 -0
- package/src/admin/ui/components/ui/alert-dialog.tsx +98 -0
- package/src/admin/ui/components/ui/blocks.tsx +32 -0
- package/src/admin/ui/components/ui/breadcrumbs.tsx +59 -0
- package/src/admin/ui/components/ui/button.tsx +26 -0
- package/src/admin/ui/components/ui/collapsible.tsx +124 -0
- package/src/admin/ui/components/ui/dialog.tsx +79 -0
- package/src/admin/ui/components/ui/group.tsx +20 -0
- package/src/admin/ui/components/ui/index.ts +17 -0
- package/src/admin/ui/components/ui/input.tsx +12 -0
- package/src/admin/ui/components/ui/join.tsx +53 -0
- package/src/admin/ui/components/ui/label.tsx +11 -0
- package/src/admin/ui/components/ui/radio-group.tsx +75 -0
- package/src/admin/ui/components/ui/relationship-detail-sheet.tsx +122 -0
- package/src/admin/ui/components/ui/relationship.tsx +58 -0
- package/src/admin/ui/components/ui/scroll-area.tsx +19 -0
- package/src/admin/ui/components/ui/select.tsx +187 -0
- package/src/admin/ui/components/ui/separator.tsx +21 -0
- package/src/admin/ui/components/ui/sheet.tsx +106 -0
- package/src/admin/ui/components/ui/tabs.tsx +116 -0
- package/src/admin/ui/components/ui/utils.ts +3 -0
- package/src/admin/ui/hooks/use-debounce.ts +15 -0
- package/src/admin/ui/styles/_locale-switcher.scss +33 -0
- package/src/admin/ui/styles/accordion.scss +60 -0
- package/src/admin/ui/styles/animations.scss +41 -0
- package/src/admin/ui/styles/asset-manager.scss +547 -0
- package/src/admin/ui/styles/badge.scss +13 -0
- package/src/admin/ui/styles/base.scss +22 -0
- package/src/admin/ui/styles/button.scss +161 -0
- package/src/admin/ui/styles/card.scss +13 -0
- package/src/admin/ui/styles/collapsible.scss +75 -0
- package/src/admin/ui/styles/data-detail.scss +92 -0
- package/src/admin/ui/styles/dialog.scss +102 -0
- package/src/admin/ui/styles/empty-state.scss +22 -0
- package/src/admin/ui/styles/group.scss +19 -0
- package/src/admin/ui/styles/index.scss +33 -0
- package/src/admin/ui/styles/input.scss +80 -0
- package/src/admin/ui/styles/label.scss +12 -0
- package/src/admin/ui/styles/layout.scss +56 -0
- package/src/admin/ui/styles/lexical.scss +469 -0
- package/src/admin/ui/styles/loading.scss +102 -0
- package/src/admin/ui/styles/media-registry.scss +597 -0
- package/src/admin/ui/styles/pagination.scss +20 -0
- package/src/admin/ui/styles/radio-group.scss +66 -0
- package/src/admin/ui/styles/row.scss +17 -0
- package/src/admin/ui/styles/scrollbar.scss +36 -0
- package/src/admin/ui/styles/select.scss +121 -0
- package/src/admin/ui/styles/separator.scss +14 -0
- package/src/admin/ui/styles/sheet.scss +152 -0
- package/src/admin/ui/styles/sidebar.scss +148 -0
- package/src/admin/ui/styles/switch.scss +59 -0
- package/src/admin/ui/styles/table.scss +207 -0
- package/src/admin/ui/styles/tabs.scss +62 -0
- package/src/admin/ui/styles/toast.scss +45 -0
- package/src/admin/ui/styles/variables.scss +24 -0
- package/src/admin/ui/views/collection-list-view.tsx +720 -0
- package/src/admin/ui/views/dashboard-view.tsx +263 -0
- package/src/admin/ui/views/document-edit-view.tsx +384 -0
- package/src/admin/ui/views/global-edit-view.tsx +226 -0
- package/src/admin/ui/views/init-view.tsx +182 -0
- package/src/admin/ui/views/login-view.tsx +123 -0
- package/src/admin/ui/views/media-registry-view.tsx +1104 -0
- package/src/admin/ui/views/settings-view.tsx +729 -0
- package/src/admin/webcomponent.tsx +15 -0
- package/src/api.ts +9 -0
- package/src/auth/index.ts +194 -0
- package/src/auth/migrations.ts +87 -0
- package/src/auth/premissions.ts +46 -0
- package/src/cli/commands/generate-types.ts +116 -0
- package/src/cli/commands/init.ts +95 -0
- package/src/cli/commands/migrate-commands.ts +160 -0
- package/src/cli/commands/seed-command.ts +11 -0
- package/src/cli/d1-mock.ts +101 -0
- package/src/cli/index.test.ts +84 -0
- package/src/cli/index.ts +183 -0
- package/src/cli/r2-mock.ts +217 -0
- package/src/cli/seeding.ts +405 -0
- package/src/client.ts +181 -0
- package/src/config-utils.ts +102 -0
- package/src/config.ts +49 -0
- package/src/db/adapter.ts +53 -0
- package/src/db/better-sqlite.ts +630 -0
- package/src/db/bun-sqlite.ts +646 -0
- package/src/db/d1.ts +711 -0
- package/src/db/kysely/data-mapper.ts +142 -0
- package/src/db/kysely/field-mapper.ts +148 -0
- package/src/db/kysely/migration-generator.ts +223 -0
- package/src/db/kysely/query-builder.ts +92 -0
- package/src/db/kysely/schema-builder.ts +439 -0
- package/src/db/kysely/sql-utils.ts +13 -0
- package/src/db/postgres.ts +621 -0
- package/src/db/sqlite.ts +658 -0
- package/src/db/system-schema.ts +121 -0
- package/src/index.ts +13 -0
- package/src/runtimes/README.md +59 -0
- package/src/runtimes/bun.ts +49 -0
- package/src/runtimes/cloudflare-workers.ts +38 -0
- package/src/runtimes/next.ts +26 -0
- package/src/runtimes/node.ts +52 -0
- package/src/schema/collection.ts +184 -0
- package/src/schema/fields/base.ts +164 -0
- package/src/schema/fields/index.ts +427 -0
- package/src/schema/global.ts +145 -0
- package/src/schema/index.ts +4 -0
- package/src/schema/infer.ts +72 -0
- package/src/server/admin-router.ts +20 -0
- package/src/server/admin.ts +142 -0
- package/src/server/assets.ts +306 -0
- package/src/server/collection-router.ts +55 -0
- package/src/server/handlers.ts +722 -0
- package/src/server/middlewares/admin.ts +27 -0
- package/src/server/middlewares/auth.ts +89 -0
- package/src/server/middlewares/context.ts +17 -0
- package/src/server/middlewares/cors.ts +24 -0
- package/src/server/middlewares/database-init.ts +74 -0
- package/src/server/middlewares/rate-limit.ts +71 -0
- package/src/server/router.ts +47 -0
- package/src/server/setup-middlewares.ts +58 -0
- package/src/server/system-router.ts +35 -0
- package/src/server.ts +9 -0
- package/src/storage/adapters/cloudflare-r2.ts +136 -0
- package/src/storage/adapters/local.ts +146 -0
- package/src/storage/adapters/s3.ts +186 -0
- package/src/storage/errors.ts +46 -0
- package/src/storage/index.ts +5 -0
- package/src/storage/types.ts +39 -0
- package/src/types.ts +577 -0
- package/src/utils/lexical.ts +37 -0
- package/src/utils/logger.ts +73 -0
- package/src/validation.ts +429 -0
- package/src/validator.ts +179 -0
- package/test/admin-custom-field.test.ts +162 -0
- package/test/admin-react-field.test.tsx +134 -0
- package/test/api-features.test.ts +78 -0
- package/test/api.test.ts +178 -0
- package/test/auth.test.ts +62 -0
- package/test/cli-integration.test.ts +146 -0
- package/test/cli.test.ts +25 -0
- package/test/db/postgres.test.ts +95 -0
- package/test/db/sqlite-filter.test.ts +53 -0
- package/test/db/sqlite.test.ts +82 -0
- package/test/engine-features.test.ts +79 -0
- package/test/globals.test.ts +74 -0
- package/test/integration-tmp/db-app/opacacms.config.ts +15 -0
- package/test/integration-tmp/my-sqlite-app/opacacms.config.ts +25 -0
- package/test/integration-tmp/my-test-app/index.ts +8 -0
- package/test/integration-tmp/my-test-app/opacacms.config.ts +16 -0
- package/test/integration-tmp/my-test-app/package.json +12 -0
- package/test/populate.test.ts +79 -0
- package/test/runtimes.test.ts +43 -0
- package/test/schema-builder.test.ts +107 -0
- package/test/schema-features.test.ts +63 -0
- package/test/seeding.test.ts +68 -0
- package/test/storage/local.test.ts +72 -0
- package/test/storage/s3.test.ts +60 -0
- package/test/structural-data.test.ts +100 -0
- package/test/test-setup.ts +11 -0
- package/test/validation.test.ts +162 -0
- package/tsconfig.json +42 -0
|
@@ -0,0 +1,179 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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";
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
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
|
+
);
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
}
|