opacacms 0.2.1 → 0.3.1

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 (185) hide show
  1. package/README.md +31 -22
  2. package/dist/admin/auth-client.d.ts +39 -39
  3. package/dist/admin/index.d.ts +2 -2
  4. package/dist/admin/index.js +15 -10520
  5. package/dist/admin/plugin-client.d.ts +65 -0
  6. package/dist/admin/react.d.ts +2 -2
  7. package/dist/admin/react.js +34 -4
  8. package/dist/admin/stores/ui.d.ts +19 -4
  9. package/dist/admin/ui/components/PluginSettingsForm.d.ts +2 -2
  10. package/dist/admin/ui/components/custom-alert.d.ts +7 -0
  11. package/dist/admin/ui/components/{DetailSheet.d.ts → detail-sheet.d.ts} +1 -2
  12. package/dist/admin/ui/components/fields/FieldLabel.d.ts +1 -1
  13. package/dist/admin/ui/components/fields/RelationshipField.d.ts +1 -1
  14. package/dist/admin/ui/components/media/AssetManagerModal.d.ts +2 -2
  15. package/dist/admin/ui/components/plugin-iframe.d.ts +7 -0
  16. package/dist/admin/ui/components/ui/accordion.d.ts +17 -7
  17. package/dist/admin/ui/components/ui/alert-dialog.d.ts +16 -12
  18. package/dist/admin/ui/components/ui/button.d.ts +11 -7
  19. package/dist/admin/ui/components/ui/relationship.d.ts +1 -1
  20. package/dist/admin/ui/components/ui/sheet.d.ts +14 -27
  21. package/dist/admin/ui/components/ui/tooltip.d.ts +7 -0
  22. package/dist/admin/ui/components/versions-sheet.d.ts +4 -5
  23. package/dist/admin/ui/views/collection-list-view.d.ts +1 -1
  24. package/dist/admin/ui/views/dashboard-view.d.ts +1 -1
  25. package/dist/admin/ui/views/media-registry-view.d.ts +3 -3
  26. package/dist/admin/ui/views/settings-view.d.ts +2 -2
  27. package/dist/admin/vue.js +27 -4
  28. package/dist/admin/webcomponent.js +66 -16
  29. package/dist/admin.css +1 -1
  30. package/dist/auth/index.d.ts +43 -43
  31. package/dist/{chunk-7y1nbmw6.js → chunk-1bd7fz7n.js} +32 -2
  32. package/dist/chunk-1qm0m8r8.js +413 -0
  33. package/dist/chunk-2k3ysje3.js +31 -0
  34. package/dist/{chunk-jdfw4v3r.js → chunk-3j9zjfmn.js} +95 -30
  35. package/dist/{chunk-byq8g0rd.js → chunk-48ywpd0a.js} +16 -22
  36. package/dist/{chunk-tfnaf41w.js → chunk-5422w4eq.js} +41 -25
  37. package/dist/chunk-56n342hs.js +95 -0
  38. package/dist/chunk-5b8r0v8c.js +47 -0
  39. package/dist/chunk-63yg00vx.js +263 -0
  40. package/dist/{chunk-8sqjbsgt.js → chunk-6bywt602.js} +26 -1
  41. package/dist/{chunk-v9z61v3g.js → chunk-6qs0g65f.js} +43 -3
  42. package/dist/chunk-7rr5p01g.js +581 -0
  43. package/dist/{chunk-2es275xs.js → chunk-941zxavt.js} +867 -322
  44. package/dist/{chunk-51z3x7kq.js → chunk-a3qae86h.js} +1 -1
  45. package/dist/{chunk-3rdhbedb.js → chunk-adq2b75c.js} +2 -2
  46. package/dist/chunk-d0tb1xjw.js +93 -0
  47. package/dist/chunk-d7cgd6vn.js +318 -0
  48. package/dist/{chunk-6d1vdfwa.js → chunk-e0g6gn7n.js} +54 -75
  49. package/dist/chunk-ec4jhybj.js +1137 -0
  50. package/dist/chunk-fatyf6f7.js +221 -0
  51. package/dist/{chunk-526a3gqx.js → chunk-fnsf1dfm.js} +1 -1
  52. package/dist/chunk-g9bxb6h0.js +205 -0
  53. package/dist/chunk-gyaf5kgf.js +10 -0
  54. package/dist/{chunk-9kxpbcb1.js → chunk-h6dhexzr.js} +16 -7
  55. package/dist/{chunk-dykn5hr6.js → chunk-j8js1y0h.js} +31 -74
  56. package/dist/{chunk-t0zg026p.js → chunk-jq1drsen.js} +12 -1
  57. package/dist/{chunk-b3kr8w41.js → chunk-m24yqkeq.js} +38 -26
  58. package/dist/chunk-m5ems3hh.js +410 -0
  59. package/dist/{chunk-8scgdznr.js → chunk-m83ybzf8.js} +15 -18
  60. package/dist/chunk-majsbncm.js +98 -0
  61. package/dist/chunk-mp2gt9yh.js +237 -0
  62. package/dist/chunk-n1twhqmf.js +54 -0
  63. package/dist/{chunk-bygjkgrx.js → chunk-naqcqj8n.js} +57 -80
  64. package/dist/chunk-q5sb5dcr.js +15 -0
  65. package/dist/{chunk-06ks4ggh.js → chunk-qhdsjek6.js} +49 -89
  66. package/dist/{chunk-n133qpsm.js → chunk-qsh2nqz3.js} +50 -81
  67. package/dist/chunk-r0ms5tk1.js +76 -0
  68. package/dist/chunk-rwqwsanx.js +75 -0
  69. package/dist/chunk-sqsfk9p4.js +700 -0
  70. package/dist/{chunk-5gvbp2qa.js → chunk-x7bnzswh.js} +25 -18
  71. package/dist/cli/commands/dev.d.ts +8 -0
  72. package/dist/cli/commands/doctor.d.ts +8 -0
  73. package/dist/cli/commands/generate.d.ts +26 -0
  74. package/dist/cli/commands/init.d.ts +13 -1
  75. package/dist/cli/commands/migrate.d.ts +33 -0
  76. package/dist/cli/commands/plugin.d.ts +13 -0
  77. package/dist/cli/commands/seed.d.ts +21 -0
  78. package/dist/cli/{commands/migrate-commands.d.ts → core/migrations/migrate-logic.d.ts} +2 -2
  79. package/dist/cli/core/migrations/schema-diff-engine.d.ts +12 -0
  80. package/dist/cli/core/migrations/schema-diff.d.ts +11 -0
  81. package/dist/cli/{seeding.d.ts → core/seeding/auto-seed.d.ts} +7 -4
  82. package/dist/cli/core/seeding/seed-logic.d.ts +2 -0
  83. package/dist/cli/index.d.ts +4 -0
  84. package/dist/cli/index.js +6 -170
  85. package/dist/client/RichText.d.ts +5 -0
  86. package/dist/client/rich-text-utils.d.ts +5 -0
  87. package/dist/client.js +3 -2
  88. package/dist/config.d.ts +3 -3
  89. package/dist/db/better-sqlite.d.ts +2 -3
  90. package/dist/db/better-sqlite.js +6 -5
  91. package/dist/db/bun-sqlite.d.ts +2 -3
  92. package/dist/db/bun-sqlite.js +6 -5
  93. package/dist/db/d1.d.ts +13 -7
  94. package/dist/db/d1.js +6 -5
  95. package/dist/db/index.d.ts +2 -2
  96. package/dist/db/index.js +10 -12
  97. package/dist/db/kysely/factory.d.ts +29 -0
  98. package/dist/db/kysely/plugins/audit-logging.d.ts +48 -0
  99. package/dist/db/kysely/plugins/auto-timestamps.d.ts +38 -0
  100. package/dist/db/kysely/plugins/cursor-pagination.d.ts +42 -0
  101. package/dist/db/kysely/plugins/deadlock-handler.d.ts +47 -0
  102. package/dist/db/kysely/plugins/draft-swapper.d.ts +33 -0
  103. package/dist/db/kysely/plugins/field-masking.d.ts +45 -0
  104. package/dist/db/kysely/plugins/fts-normalizer.d.ts +38 -0
  105. package/dist/db/kysely/plugins/i18n-fallback.d.ts +48 -0
  106. package/dist/db/kysely/plugins/id-generation.d.ts +42 -0
  107. package/dist/db/kysely/plugins/index.d.ts +16 -0
  108. package/dist/db/kysely/plugins/json-flattener.d.ts +38 -0
  109. package/dist/db/kysely/plugins/relationship-preloading.d.ts +39 -0
  110. package/dist/db/kysely/plugins/slug-generation.d.ts +37 -0
  111. package/dist/db/kysely/plugins/soft-delete.d.ts +42 -0
  112. package/dist/db/kysely/plugins/tree-resolver.d.ts +39 -0
  113. package/dist/db/kysely/plugins/virtual-field-resolver.d.ts +54 -0
  114. package/dist/db/kysely/plugins/zod-coercion.d.ts +34 -0
  115. package/dist/db/kysely/snapshot/snapshot-manager.d.ts +18 -0
  116. package/dist/db/postgres.d.ts +2 -2
  117. package/dist/db/postgres.js +6 -5
  118. package/dist/db/sqlite.d.ts +2 -3
  119. package/dist/db/sqlite.js +6 -5
  120. package/dist/index.d.ts +3 -0
  121. package/dist/index.js +161 -7
  122. package/dist/runtimes/bun.js +9 -6
  123. package/dist/runtimes/cloudflare-workers.d.ts +3 -1
  124. package/dist/runtimes/cloudflare-workers.js +36 -7
  125. package/dist/runtimes/next.js +8 -5
  126. package/dist/runtimes/node.js +9 -6
  127. package/dist/schema/collection.d.ts +116 -70
  128. package/dist/schema/compiler.d.ts +6 -0
  129. package/dist/schema/global.d.ts +38 -71
  130. package/dist/schema/index.d.ts +5 -4
  131. package/dist/schema/index.js +35 -550
  132. package/dist/schema/zod.d.ts +564 -0
  133. package/dist/server/admin-router.d.ts +1 -1
  134. package/dist/server/collection-router.d.ts +1 -1
  135. package/dist/server/graphql.d.ts +6 -0
  136. package/dist/server/handlers.d.ts +25 -7
  137. package/dist/server/middlewares/auth.d.ts +1 -1
  138. package/dist/server/plugins-loader.d.ts +1 -1
  139. package/dist/server/router.d.ts +2 -2
  140. package/dist/server/routers/admin.d.ts +1 -1
  141. package/dist/server/routers/auth.d.ts +1 -1
  142. package/dist/server/routers/collections.d.ts +4 -1
  143. package/dist/server/routers/plugins.d.ts +2 -2
  144. package/dist/server/setup-middlewares.d.ts +1 -1
  145. package/dist/server/system-router.d.ts +1 -1
  146. package/dist/server.js +11 -6
  147. package/dist/storage/adapters/cloudflare-r2.d.ts +11 -2
  148. package/dist/storage/index.js +5 -5
  149. package/dist/types.d.ts +253 -42
  150. package/dist/utils/context.d.ts +14 -0
  151. package/dist/utils/logger.d.ts +2 -0
  152. package/dist/utils/string.d.ts +10 -0
  153. package/dist/utils/webhooks-engine.d.ts +24 -0
  154. package/dist/validation.d.ts +67 -1
  155. package/dist/validator.d.ts +1 -0
  156. package/package.json +50 -11
  157. package/src/cli/index.ts +117 -0
  158. package/dist/chunk-6qq3ne6b.js +0 -288
  159. package/dist/chunk-6v1fw7q7.js +0 -126
  160. package/dist/chunk-7a9kn0np.js +0 -116
  161. package/dist/chunk-bexcv7xe.js +0 -36
  162. package/dist/chunk-d3ffeqp9.js +0 -87
  163. package/dist/chunk-fj19qccp.js +0 -78
  164. package/dist/chunk-g1jb60xd.js +0 -17
  165. package/dist/chunk-j53pz21t.js +0 -20
  166. package/dist/chunk-mkn49zmy.js +0 -102
  167. package/dist/chunk-r39em4yj.js +0 -29
  168. package/dist/chunk-rsf0tpy1.js +0 -8
  169. package/dist/chunk-srsac177.js +0 -85
  170. package/dist/chunk-twpvxfce.js +0 -64
  171. package/dist/chunk-ywm4t2gm.js +0 -19
  172. package/dist/cli/commands/plugin-sync.d.ts +0 -1
  173. package/dist/cli/commands/seed-command.d.ts +0 -2
  174. package/dist/plugins/ui-bridge.d.ts +0 -12
  175. package/dist/schema/fields/base.d.ts +0 -84
  176. package/dist/schema/fields/index.d.ts +0 -147
  177. package/dist/schema/infer.d.ts +0 -55
  178. /package/dist/admin/ui/components/{ColumnVisibilityToggle.d.ts → column-visibility-toggle.d.ts} +0 -0
  179. /package/dist/admin/ui/components/{DataDetailView.d.ts → data-detail-view.d.ts} +0 -0
  180. /package/dist/cli/{d1-mock.d.ts → core/mocks/d1-mock.d.ts} +0 -0
  181. /package/dist/cli/{r2-mock.d.ts → core/mocks/r2-mock.d.ts} +0 -0
  182. /package/dist/cli/{commands → core/plugins}/plugin-build.d.ts +0 -0
  183. /package/dist/cli/{commands → core/plugins}/plugin-init.d.ts +0 -0
  184. /package/dist/cli/{commands → core/types}/generate-types.d.ts +0 -0
  185. /package/dist/{schema/fields/validation.test.d.ts → cli/seeding.test.d.ts} +0 -0
@@ -0,0 +1,39 @@
1
+ import type { KyselyPlugin, PluginTransformQueryArgs, PluginTransformResultArgs, QueryResult, RootOperationNode } from "kysely";
2
+ /**
3
+ * Configuration for the TreeResolverPlugin.
4
+ */
5
+ export interface TreeResolverPluginConfig {
6
+ /** The column used to identify the parent (e.g. 'parent_id'). */
7
+ parentColumn?: string;
8
+ /** The children property name in the resulting JSON (e.g. 'children'). */
9
+ childrenProperty?: string;
10
+ }
11
+ /**
12
+ * Kysely plugin for handling hierarchical data structures (Adjacency List).
13
+ *
14
+ * Many CMS collections (like Categories, Menus, or Comments) have a tree structure.
15
+ * Fetching and formatting these hierarchies in pure SQL can be complex.
16
+ *
17
+ * This plugin:
18
+ * 1. Can inject Recursive CTEs (WITH RECURSIVE) for deep tree fetching.
19
+ * 2. Automatically transforms flat database rows into a nested JSON tree.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * const db = new Kysely<Database>({
24
+ * dialect,
25
+ * plugins: [new TreeResolverPlugin({ parentColumn: 'parent_id', childrenProperty: 'subcategories' })]
26
+ * });
27
+ *
28
+ * const categories = await db.selectFrom('categories').selectAll().execute();
29
+ * // categories will be nested: [{ id: 1, name: 'Root', subcategories: [{ id: 2, name: 'Child' }] }]
30
+ * ```
31
+ */
32
+ export declare class TreeResolverPlugin implements KyselyPlugin {
33
+ private parentColumn;
34
+ private childrenProperty;
35
+ constructor(config: TreeResolverPluginConfig);
36
+ transformQuery(args: PluginTransformQueryArgs): RootOperationNode;
37
+ transformResult(args: PluginTransformResultArgs): Promise<QueryResult<any>>;
38
+ private buildTree;
39
+ }
@@ -0,0 +1,54 @@
1
+ import type { KyselyPlugin, PluginTransformQueryArgs, PluginTransformResultArgs, QueryResult, RootOperationNode } from "kysely";
2
+ import type { ApiKey, Collection, Global, Session, User } from "../../../types";
3
+ /**
4
+ * Configuration for the VirtualFieldResolverPlugin.
5
+ */
6
+ export interface VirtualFieldResolverPluginConfig {
7
+ /** The list of CMS collections. */
8
+ collections: Collection[];
9
+ /** The list of CMS globals. */
10
+ globals?: Global[];
11
+ /** The current request context (Hono context or similar). */
12
+ req?: any;
13
+ /** The current authenticated user. */
14
+ user?: User;
15
+ /** The current session. */
16
+ session?: Session;
17
+ /** The API key used for the request, if any. */
18
+ apiKey?: ApiKey;
19
+ }
20
+ /**
21
+ * Kysely plugin that automatically executes resolver functions for virtual fields.
22
+ *
23
+ * Virtual fields are properties that don't exist in the database but are computed
24
+ * on-the-fly when a document is retrieved.
25
+ *
26
+ * This plugin:
27
+ * 1. Identifies virtual fields from the CMS schema.
28
+ * 2. After a query is executed, iterates through the result rows.
29
+ * 3. Calls the `resolve()` function for each virtual field in parallel.
30
+ * 4. Appends the resolved values to the result objects.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * // Field definition in schema:
35
+ * z.text().cms({
36
+ * virtual: true,
37
+ * resolve: ({ data }) => `${data.firstName} ${data.lastName}`
38
+ * })
39
+ *
40
+ * // Plugin usage:
41
+ * const db = new Kysely<Database>({
42
+ * dialect,
43
+ * plugins: [new VirtualFieldResolverPlugin({ collections, user, session })]
44
+ * });
45
+ * ```
46
+ */
47
+ export declare class VirtualFieldResolverPlugin implements KyselyPlugin {
48
+ private resolvers;
49
+ private config;
50
+ constructor(config: VirtualFieldResolverPluginConfig);
51
+ private parseConfig;
52
+ transformQuery(args: PluginTransformQueryArgs): RootOperationNode;
53
+ transformResult(args: PluginTransformResultArgs): Promise<QueryResult<any>>;
54
+ }
@@ -0,0 +1,34 @@
1
+ import type { KyselyPlugin, PluginTransformQueryArgs, PluginTransformResultArgs, QueryResult, RootOperationNode } from "kysely";
2
+ import type { ZodSchema } from "zod";
3
+ /**
4
+ * Configuration for the ZodCoercionPlugin.
5
+ */
6
+ export interface ZodCoercionPluginConfig {
7
+ /** Map of table names to their corresponding Zod schemas. */
8
+ schemas: Record<string, ZodSchema>;
9
+ }
10
+ /**
11
+ * Kysely plugin that provides strict result validation and type coercion using Zod.
12
+ *
13
+ * Databases (especially SQLite) often return data in formats that don't match
14
+ * the application's types (e.g., booleans as 0/1, or complex objects as strings).
15
+ *
16
+ * This plugin:
17
+ * 1. Takes a map of Zod schemas for each table.
18
+ * 2. After a query is executed, it runs each row through the matching Zod schema.
19
+ * 3. Automatically coerces types (like string-to-object or number-to-boolean).
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * const db = new Kysely<Database>({
24
+ * dialect,
25
+ * plugins: [new ZodCoercionPlugin({ schemas: { posts: postSchema } })]
26
+ * });
27
+ * ```
28
+ */
29
+ export declare class ZodCoercionPlugin implements KyselyPlugin {
30
+ private schemas;
31
+ constructor(config: ZodCoercionPluginConfig);
32
+ transformQuery(args: PluginTransformQueryArgs): RootOperationNode;
33
+ transformResult(args: PluginTransformResultArgs): Promise<QueryResult<any>>;
34
+ }
@@ -0,0 +1,18 @@
1
+ import type { Collection, Global } from "../../../types";
2
+ export interface ColumnSnapshot {
3
+ name: string;
4
+ type: string;
5
+ required: boolean;
6
+ unique: boolean;
7
+ defaultValue?: any;
8
+ }
9
+ export interface TableSnapshot {
10
+ name: string;
11
+ columns: Record<string, ColumnSnapshot>;
12
+ }
13
+ export interface SchemaSnapshot {
14
+ tables: Record<string, TableSnapshot>;
15
+ }
16
+ export declare function createSchemaSnapshot(collections: Collection[], globals: Global[], dialect: "postgres" | "sqlite" | "d1"): SchemaSnapshot;
17
+ export declare function saveSnapshot(migrationDir: string, snapshotName: string, snapshot: SchemaSnapshot): void;
18
+ export declare function loadLastSnapshot(migrationDir: string): SchemaSnapshot | null;
@@ -1,7 +1,7 @@
1
- import { Kysely } from "kysely";
1
+ import { type Kysely } from "kysely";
2
2
  import type postgres from "postgres";
3
- import type { Collection, FindOptions, Global, PaginatedResult } from "../types";
4
3
  import { BaseDatabaseAdapter } from "../db/adapter";
4
+ import type { Collection, FindOptions, Global, PaginatedResult } from "../types";
5
5
  export interface PostgresConfig {
6
6
  url?: string;
7
7
  host?: string;
@@ -1,13 +1,14 @@
1
1
  import {
2
2
  PostgresAdapter,
3
3
  createPostgresAdapter
4
- } from "../chunk-tfnaf41w.js";
5
- import"../chunk-dykn5hr6.js";
4
+ } from "../chunk-5422w4eq.js";
5
+ import"../chunk-j8js1y0h.js";
6
6
  import"../chunk-s8mqwnm1.js";
7
+ import"../chunk-q5sb5dcr.js";
7
8
  import"../chunk-qxt9vge8.js";
8
- import"../chunk-v9z61v3g.js";
9
- import"../chunk-t0zg026p.js";
10
- import"../chunk-8sqjbsgt.js";
9
+ import"../chunk-jq1drsen.js";
10
+ import"../chunk-6qs0g65f.js";
11
+ import"../chunk-6bywt602.js";
11
12
  export {
12
13
  createPostgresAdapter,
13
14
  PostgresAdapter
@@ -1,6 +1,6 @@
1
- import { Kysely } from "kysely";
2
- import type { Collection, FindOptions, Global, PaginatedResult } from "../types";
1
+ import { type Kysely } from "kysely";
3
2
  import { BaseDatabaseAdapter } from "../db/adapter";
3
+ import type { Collection, FindOptions, Global, PaginatedResult } from "../types";
4
4
  export declare class SQLiteAdapter extends BaseDatabaseAdapter {
5
5
  private path;
6
6
  name: string;
@@ -21,7 +21,6 @@ export declare class SQLiteAdapter extends BaseDatabaseAdapter {
21
21
  connect(): Promise<void>;
22
22
  disconnect(): Promise<void>;
23
23
  unsafe(query: string, params?: any[]): Promise<unknown>;
24
- private coerceData;
25
24
  count(collection: string, query?: Record<string, unknown>): Promise<number>;
26
25
  create<T extends object>(collection: string, data: Partial<T>): Promise<T>;
27
26
  findOne<T extends object>(collection: string, query: Record<string, unknown>, tx?: any): Promise<T | null>;
package/dist/db/sqlite.js CHANGED
@@ -1,13 +1,14 @@
1
1
  import {
2
2
  SQLiteAdapter,
3
3
  createSQLiteAdapter
4
- } from "../chunk-6d1vdfwa.js";
5
- import"../chunk-dykn5hr6.js";
4
+ } from "../chunk-e0g6gn7n.js";
5
+ import"../chunk-j8js1y0h.js";
6
6
  import"../chunk-s8mqwnm1.js";
7
+ import"../chunk-q5sb5dcr.js";
7
8
  import"../chunk-qxt9vge8.js";
8
- import"../chunk-v9z61v3g.js";
9
- import"../chunk-t0zg026p.js";
10
- import"../chunk-8sqjbsgt.js";
9
+ import"../chunk-jq1drsen.js";
10
+ import"../chunk-6qs0g65f.js";
11
+ import"../chunk-6bywt602.js";
11
12
  export {
12
13
  createSQLiteAdapter,
13
14
  SQLiteAdapter
package/dist/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  export * from "./auth";
2
2
  export * from "./client";
3
+ export * from "./client/RichText";
4
+ export * from "./client/rich-text-utils";
3
5
  export * from "./config";
4
6
  export * from "./config-utils";
7
+ export * from "./schema";
5
8
  export * from "./types";
6
9
  export type { AdminConfig, CollectionHooks, FieldType, } from "./validation";
package/dist/index.js CHANGED
@@ -1,21 +1,175 @@
1
1
  import {
2
2
  OpacaError,
3
3
  createClient
4
- } from "./chunk-d3ffeqp9.js";
4
+ } from "./chunk-g9bxb6h0.js";
5
+ import {
6
+ defineCollection,
7
+ defineGlobal
8
+ } from "./chunk-n1twhqmf.js";
5
9
  import {
6
10
  defineConfig
7
- } from "./chunk-7y1nbmw6.js";
11
+ } from "./chunk-1bd7fz7n.js";
8
12
  import {
9
13
  createAuth,
10
14
  sanitizeConfig
11
- } from "./chunk-b3kr8w41.js";
12
- import"./chunk-v9z61v3g.js";
13
- import"./chunk-t0zg026p.js";
14
- import"./chunk-8sqjbsgt.js";
15
+ } from "./chunk-m24yqkeq.js";
16
+ import"./chunk-5b8r0v8c.js";
17
+ import {
18
+ $ZodArray,
19
+ $ZodBoolean,
20
+ $ZodDate,
21
+ $ZodDefault,
22
+ $ZodDiscriminatedUnion,
23
+ $ZodEnum,
24
+ $ZodNullable,
25
+ $ZodNumber,
26
+ $ZodObject,
27
+ $ZodOptional,
28
+ $ZodString,
29
+ z,
30
+ zodToOpacaFields
31
+ } from "./chunk-m5ems3hh.js";
32
+ import"./chunk-jq1drsen.js";
33
+ import"./chunk-6qs0g65f.js";
34
+ import"./chunk-6bywt602.js";
35
+ // src/client/RichText.tsx
36
+ import { CodeNode } from "@lexical/code";
37
+ import { AutoLinkNode, LinkNode } from "@lexical/link";
38
+ import { ListItemNode, ListNode } from "@lexical/list";
39
+ import { LexicalComposer } from "@lexical/react/LexicalComposer";
40
+ import { ContentEditable } from "@lexical/react/LexicalContentEditable";
41
+ import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
42
+ import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
43
+ import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin";
44
+ import { ListPlugin } from "@lexical/react/LexicalListPlugin";
45
+ import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
46
+ import { HeadingNode, QuoteNode } from "@lexical/rich-text";
47
+ import { useMemo } from "react";
48
+ import { jsxDEV } from "react/jsx-dev-runtime";
49
+ "use client";
50
+ var theme = {
51
+ ltr: "ltr",
52
+ rtl: "rtl",
53
+ placeholder: "opaca-rich-text-placeholder",
54
+ paragraph: "opaca-rich-text-p",
55
+ quote: "opaca-rich-text-quote",
56
+ heading: {
57
+ h1: "opaca-rich-text-h1",
58
+ h2: "opaca-rich-text-h2",
59
+ h3: "opaca-rich-text-h3"
60
+ },
61
+ list: {
62
+ ol: "opaca-rich-text-ol",
63
+ ul: "opaca-rich-text-ul",
64
+ listitem: "opaca-rich-text-li"
65
+ },
66
+ link: "opaca-rich-text-link",
67
+ text: {
68
+ bold: "opaca-rich-text-bold",
69
+ italic: "opaca-rich-text-italic",
70
+ underline: "opaca-rich-text-underline",
71
+ strikethrough: "opaca-rich-text-strikethrough",
72
+ code: "opaca-rich-text-code"
73
+ }
74
+ };
75
+ function RichText({ content, className }) {
76
+ const initialConfig = useMemo(() => {
77
+ let editorState = content;
78
+ if (typeof content === "string" && content.startsWith("{")) {
79
+ try {
80
+ editorState = content;
81
+ } catch (e) {
82
+ editorState = undefined;
83
+ }
84
+ } else if (typeof content === "object" && content !== null) {
85
+ editorState = JSON.stringify(content);
86
+ }
87
+ return {
88
+ namespace: "OpacaRichTextRenderer",
89
+ theme,
90
+ editable: false,
91
+ nodes: [HeadingNode, ListNode, ListItemNode, QuoteNode, CodeNode, LinkNode, AutoLinkNode],
92
+ onError: (error) => {
93
+ console.error("RichText Renderer Error:", error);
94
+ },
95
+ editorState
96
+ };
97
+ }, [content]);
98
+ if (!content)
99
+ return null;
100
+ return /* @__PURE__ */ jsxDEV("div", {
101
+ className: `opaca-rich-text-renderer ${className || ""}`,
102
+ children: /* @__PURE__ */ jsxDEV(LexicalComposer, {
103
+ initialConfig,
104
+ children: [
105
+ /* @__PURE__ */ jsxDEV(RichTextPlugin, {
106
+ contentEditable: /* @__PURE__ */ jsxDEV(ContentEditable, {
107
+ className: "opaca-rich-text-content"
108
+ }, undefined, false, undefined, this),
109
+ placeholder: null,
110
+ ErrorBoundary: LexicalErrorBoundary
111
+ }, undefined, false, undefined, this),
112
+ /* @__PURE__ */ jsxDEV(ListPlugin, {}, undefined, false, undefined, this),
113
+ /* @__PURE__ */ jsxDEV(LinkPlugin, {}, undefined, false, undefined, this),
114
+ /* @__PURE__ */ jsxDEV(HistoryPlugin, {}, undefined, false, undefined, this)
115
+ ]
116
+ }, undefined, true, undefined, this)
117
+ }, undefined, false, undefined, this);
118
+ }
119
+ // src/client/rich-text-utils.ts
120
+ function getRichTextText(content) {
121
+ if (!content)
122
+ return "";
123
+ if (typeof content === "string") {
124
+ if (content.startsWith("{") && content.includes('"root"')) {
125
+ try {
126
+ return getRichTextText(JSON.parse(content));
127
+ } catch {
128
+ return content;
129
+ }
130
+ }
131
+ return content;
132
+ }
133
+ if (content.root) {
134
+ return extractLexicalNodes(content.root.children);
135
+ }
136
+ if (Array.isArray(content)) {
137
+ return extractLexicalNodes(content);
138
+ }
139
+ return "";
140
+ }
141
+ function extractLexicalNodes(nodes) {
142
+ if (!nodes || !Array.isArray(nodes))
143
+ return "";
144
+ return nodes.map((node) => {
145
+ if (node.text)
146
+ return node.text;
147
+ if (node.children)
148
+ return extractLexicalNodes(node.children);
149
+ return "";
150
+ }).join(" ").replace(/\s+/g, " ").trim();
151
+ }
15
152
  export {
153
+ zodToOpacaFields,
154
+ z,
16
155
  sanitizeConfig,
156
+ getRichTextText,
157
+ defineGlobal,
17
158
  defineConfig,
159
+ defineCollection,
18
160
  createClient,
19
161
  createAuth,
20
- OpacaError
162
+ RichText,
163
+ OpacaError,
164
+ $ZodString,
165
+ $ZodOptional,
166
+ $ZodObject,
167
+ $ZodNumber,
168
+ $ZodNullable,
169
+ $ZodEnum,
170
+ $ZodDiscriminatedUnion,
171
+ $ZodDefault,
172
+ $ZodDate,
173
+ $ZodBoolean,
174
+ $ZodArray
21
175
  };
@@ -1,14 +1,17 @@
1
1
  import {
2
2
  loadPluginSettings
3
- } from "../chunk-51z3x7kq.js";
3
+ } from "../chunk-a3qae86h.js";
4
4
  import {
5
5
  createAPIRouter
6
- } from "../chunk-2es275xs.js";
7
- import"../chunk-b3kr8w41.js";
6
+ } from "../chunk-941zxavt.js";
7
+ import"../chunk-m24yqkeq.js";
8
+ import"../chunk-5b8r0v8c.js";
9
+ import"../chunk-m5ems3hh.js";
10
+ import"../chunk-q5sb5dcr.js";
8
11
  import"../chunk-qxt9vge8.js";
9
- import"../chunk-v9z61v3g.js";
10
- import"../chunk-t0zg026p.js";
11
- import"../chunk-8sqjbsgt.js";
12
+ import"../chunk-jq1drsen.js";
13
+ import"../chunk-6qs0g65f.js";
14
+ import"../chunk-6bywt602.js";
12
15
 
13
16
  // src/runtimes/bun.ts
14
17
  import { Hono } from "hono";
@@ -7,4 +7,6 @@ import type { OpacaConfig } from "../types";
7
7
  * @param configOrFactory - Either the OpacaCMS configuration object or a function that returns it.
8
8
  * @returns An object with a standard `fetch` method signature.
9
9
  */
10
- export declare function createCloudflareWorkersHandler(configOrFactory: OpacaConfig | ((env: any, request: Request) => OpacaConfig | Promise<OpacaConfig>)): Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
10
+ export declare function createCloudflareWorkersHandler(configOrFactory: OpacaConfig | ((env: any, request: Request) => OpacaConfig | Promise<OpacaConfig>), options?: {
11
+ enableAdmin?: boolean;
12
+ }): Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
@@ -1,27 +1,56 @@
1
1
  import {
2
2
  createAPIRouter
3
- } from "../chunk-2es275xs.js";
4
- import"../chunk-b3kr8w41.js";
3
+ } from "../chunk-941zxavt.js";
4
+ import"../chunk-m24yqkeq.js";
5
+ import"../chunk-5b8r0v8c.js";
6
+ import"../chunk-m5ems3hh.js";
7
+ import"../chunk-q5sb5dcr.js";
5
8
  import"../chunk-qxt9vge8.js";
6
- import"../chunk-v9z61v3g.js";
7
- import"../chunk-t0zg026p.js";
8
- import"../chunk-8sqjbsgt.js";
9
+ import"../chunk-jq1drsen.js";
10
+ import"../chunk-6qs0g65f.js";
11
+ import"../chunk-6bywt602.js";
9
12
 
10
13
  // src/runtimes/cloudflare-workers.ts
11
14
  import { Hono } from "hono";
12
15
  var cachedApp;
13
- function createCloudflareWorkersHandler(configOrFactory) {
16
+ function createCloudflareWorkersHandler(configOrFactory, options) {
14
17
  const app = new Hono;
15
18
  app.use("/api/*", async (c, next) => {
16
19
  if (cachedApp)
17
20
  return cachedApp.fetch(c.req.raw, c.env, c.executionCtx);
18
21
  const config = typeof configOrFactory === "function" ? await configOrFactory(c.env, c.req.raw) : configOrFactory;
19
- const apiRouter = createAPIRouter(config);
22
+ const apiRouter = createAPIRouter(config, {}, c.env);
20
23
  const innerApp = new Hono;
21
24
  innerApp.route("/", apiRouter);
22
25
  cachedApp = innerApp;
23
26
  return cachedApp.fetch(c.req.raw, c.env, c.executionCtx);
24
27
  });
28
+ if (options?.enableAdmin) {
29
+ app.get("/admin*", (c) => {
30
+ return c.html(`
31
+ <!DOCTYPE html>
32
+ <html lang="en">
33
+ <head>
34
+ <meta charset="UTF-8">
35
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
36
+ <title>OpacaCMS Admin WebComponent</title>
37
+ <style>
38
+ body { margin: 0; font-family: sans-serif; }
39
+ </style>
40
+ <link rel="stylesheet" href="/admin.css">
41
+ </head>
42
+ <body>
43
+ <opaca-admin
44
+ server-url="${new URL(c.req.url).origin}"
45
+ ></opaca-admin>
46
+
47
+ <!-- Using local bundle served via Wrangler Assets -->
48
+ <script type="module" src="/webcomponent.js"></script>
49
+ </body>
50
+ </html>
51
+ `);
52
+ });
53
+ }
25
54
  return app;
26
55
  }
27
56
  export {
@@ -1,11 +1,14 @@
1
1
  import {
2
2
  createAPIRouter
3
- } from "../chunk-2es275xs.js";
4
- import"../chunk-b3kr8w41.js";
3
+ } from "../chunk-941zxavt.js";
4
+ import"../chunk-m24yqkeq.js";
5
+ import"../chunk-5b8r0v8c.js";
6
+ import"../chunk-m5ems3hh.js";
7
+ import"../chunk-q5sb5dcr.js";
5
8
  import"../chunk-qxt9vge8.js";
6
- import"../chunk-v9z61v3g.js";
7
- import"../chunk-t0zg026p.js";
8
- import"../chunk-8sqjbsgt.js";
9
+ import"../chunk-jq1drsen.js";
10
+ import"../chunk-6qs0g65f.js";
11
+ import"../chunk-6bywt602.js";
9
12
 
10
13
  // src/runtimes/next.ts
11
14
  import { handle } from "hono/vercel";
@@ -1,14 +1,17 @@
1
1
  import {
2
2
  loadPluginSettings
3
- } from "../chunk-51z3x7kq.js";
3
+ } from "../chunk-a3qae86h.js";
4
4
  import {
5
5
  createAPIRouter
6
- } from "../chunk-2es275xs.js";
7
- import"../chunk-b3kr8w41.js";
6
+ } from "../chunk-941zxavt.js";
7
+ import"../chunk-m24yqkeq.js";
8
+ import"../chunk-5b8r0v8c.js";
9
+ import"../chunk-m5ems3hh.js";
10
+ import"../chunk-q5sb5dcr.js";
8
11
  import"../chunk-qxt9vge8.js";
9
- import"../chunk-v9z61v3g.js";
10
- import"../chunk-t0zg026p.js";
11
- import"../chunk-8sqjbsgt.js";
12
+ import"../chunk-jq1drsen.js";
13
+ import"../chunk-6qs0g65f.js";
14
+ import"../chunk-6bywt602.js";
12
15
 
13
16
  // src/runtimes/node.ts
14
17
  import { serve } from "@hono/node-server";