@brightsideoy/kama 1.0.0-alpha.2 → 1.0.0-alpha.20

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 (125) hide show
  1. package/bin/cli.js +604 -364
  2. package/content/definitions/block-kama-forms.yaml +5 -0
  3. package/content/definitions/blocks/button.yaml +15 -5
  4. package/content/definitions/blocks/node-list.yaml +75 -0
  5. package/content/definitions/field-sets/channel-base.yaml +7 -0
  6. package/content/definitions/nodes/article.yaml +17 -1
  7. package/content/definitions/taxonomies/categories.yaml +5 -2
  8. package/content/definitions/taxonomies/tags.yaml +5 -2
  9. package/content/forms/contact.yaml +44 -0
  10. package/content/forms/subscription.yaml +32 -0
  11. package/dist/assets/AssetEditor-D5j7pwcK.css +1 -0
  12. package/dist/assets/AssetEditor-Dt1zCR7_.js +1 -0
  13. package/dist/assets/CmsBadge-BNsgxyyB.css +1 -0
  14. package/dist/assets/CmsBadge-D0Ob9qPU.js +1 -0
  15. package/dist/assets/CmsButton-BQ85-YXn.css +1 -0
  16. package/dist/assets/CmsButton-CbOfxvjr.js +1 -0
  17. package/dist/assets/CmsDataRow--H4iI_u_.js +1 -0
  18. package/dist/assets/CmsDataRow-CYNxfVaZ.css +1 -0
  19. package/dist/assets/CmsHelp-BO_vWABq.css +1 -0
  20. package/dist/assets/CmsHelp-DyPJLGGi.js +1 -0
  21. package/dist/assets/CmsImagePreview-CujwG8r_.css +1 -0
  22. package/dist/assets/CmsImagePreview-DuHPBzml.js +1 -0
  23. package/dist/assets/CmsPaneResizer-B62ZqsnE.js +1 -0
  24. package/dist/assets/CmsPaneResizer-Dkidd4pI.css +1 -0
  25. package/dist/assets/CmsPublisher-CugEqTD8.css +1 -0
  26. package/dist/assets/CmsPublisher-DNLwjirk.js +3 -0
  27. package/dist/assets/CmsUserCenter-Ac0GywlR.css +1 -0
  28. package/dist/assets/CmsUserCenter-D3XDzKDC.js +1 -0
  29. package/dist/assets/EditorSplitPreview-BzKh4wFB.css +1 -0
  30. package/dist/assets/EditorSplitPreview-Cp2x0O_P.js +1 -0
  31. package/dist/assets/NodeContextMenu-BYeWzmQ5.css +1 -0
  32. package/dist/assets/NodeContextMenu-C_HWBGeb.js +1 -0
  33. package/dist/assets/NodeEditor-CiXQKXK1.js +147 -0
  34. package/dist/assets/NodeEditor-pZI3gu4a.css +1 -0
  35. package/dist/assets/StatusPill-CbeW5SMT.js +1 -0
  36. package/dist/assets/StatusPill-Dlm6uvGe.css +1 -0
  37. package/dist/assets/TrashWorkspace-DgIg1v6t.js +1 -0
  38. package/dist/assets/TrashWorkspace-DtMgxg13.css +1 -0
  39. package/dist/assets/_plugin-vue_export-helper-CQxWhVtr.js +5 -0
  40. package/dist/assets/circle-check-A-QeFqt3.js +1 -0
  41. package/dist/assets/database-hg5SqKLG.js +1 -0
  42. package/dist/assets/folder-tree-BWYot72H.js +1 -0
  43. package/dist/assets/globe-BraoljaN.js +1 -0
  44. package/dist/assets/history-pqIbKK9u.js +1 -0
  45. package/dist/assets/index-DQ6_RmCI.js +14 -0
  46. package/dist/assets/index-DcKiaRjI.css +1 -0
  47. package/dist/assets/layers-B6RgfpPR.js +1 -0
  48. package/dist/assets/loader-circle-BoUkhDjq.js +1 -0
  49. package/dist/assets/monitor-CrpvInqG.js +1 -0
  50. package/dist/assets/panel-left-close-CVFakVaA.js +1 -0
  51. package/dist/assets/plus-FQRsZBoJ.js +1 -0
  52. package/dist/assets/rotate-ccw-CWE4pOjs.js +1 -0
  53. package/dist/assets/save-Ctv8vW9H.js +1 -0
  54. package/dist/assets/schema-helpers-DvficKko.js +1 -0
  55. package/dist/assets/send-F-mJeL54.js +1 -0
  56. package/dist/assets/smartphone-EPce6VdP.js +1 -0
  57. package/dist/assets/trash-2-CAUF1KtI.js +1 -0
  58. package/dist/assets/useLocalStorage-C805uplI.js +1 -0
  59. package/dist/assets/useNodes-D2-VxsxR.js +1 -0
  60. package/dist/assets/user-IFlT6mYq.js +1 -0
  61. package/dist/build-seed.js +495 -0
  62. package/dist/{dist-Dy7-HUEG.js → dist-D_Q1y4Kh.js} +2314 -1180
  63. package/dist/index.html +34 -2
  64. package/dist/index.js +2298 -1158
  65. package/dist/schema-compiler.js +5 -5
  66. package/documentation/EXTENSIONS.md +204 -0
  67. package/extension-registry.js +5 -0
  68. package/package.json +9 -2
  69. package/schema.sql +34 -1
  70. package/templates/astro-starter/old_src/components/blocks/BlockRenderer.astro +143 -0
  71. package/templates/astro-starter/old_src/components/blocks/ColumnLayout.astro +67 -0
  72. package/templates/astro-starter/old_src/components/blocks/HeaderImage.astro +126 -0
  73. package/templates/astro-starter/old_src/components/blocks/Hero.astro +218 -0
  74. package/templates/astro-starter/old_src/components/blocks/HtmlBlock.astro +25 -0
  75. package/templates/astro-starter/old_src/components/blocks/ImageBlock.astro +91 -0
  76. package/templates/astro-starter/old_src/components/blocks/NodeList.astro +274 -0
  77. package/templates/astro-starter/old_src/components/blocks/TextBlock.astro +15 -0
  78. package/templates/astro-starter/old_src/components/global/Breadcrumb.astro +108 -0
  79. package/templates/astro-starter/old_src/components/global/Footer.astro +50 -0
  80. package/templates/astro-starter/old_src/components/global/Header.astro +171 -0
  81. package/templates/astro-starter/old_src/components/global/MetaHead.astro +266 -0
  82. package/templates/astro-starter/old_src/components/global/NavigationMenu.astro +413 -0
  83. package/templates/astro-starter/old_src/components/ui/KamaImage.astro +180 -0
  84. package/templates/astro-starter/old_src/layouts/SkeletonLayout.astro +56 -0
  85. package/templates/astro-starter/old_src/layouts/StandardLayout.astro +63 -0
  86. package/templates/astro-starter/old_src/lib/cms.ts +219 -0
  87. package/templates/astro-starter/old_src/lib/media/kama-image-service.ts +67 -0
  88. package/templates/astro-starter/old_src/lib/media/media-proxy.ts +148 -0
  89. package/templates/astro-starter/old_src/lib/media/media-url.ts +112 -0
  90. package/templates/astro-starter/old_src/middleware.ts +536 -0
  91. package/templates/astro-starter/old_src/pages/404.astro +46 -0
  92. package/templates/astro-starter/old_src/pages/[...slug].astro +311 -0
  93. package/templates/astro-starter/old_src/pages/api/load-nodes.ts +68 -0
  94. package/templates/astro-starter/old_src/pages/api/partials/node-cards.astro +101 -0
  95. package/templates/astro-starter/old_src/pages/llms-full.txt.ts +171 -0
  96. package/templates/astro-starter/old_src/pages/llms.txt.ts +113 -0
  97. package/templates/astro-starter/old_src/pages/media/[...path].ts +14 -0
  98. package/templates/astro-starter/old_src/pages/partials/footer.astro +69 -0
  99. package/templates/astro-starter/old_src/pages/partials/nav.astro +141 -0
  100. package/templates/astro-starter/old_src/styles/standard-theme.css +157 -0
  101. package/templates/astro-starter/old_src/utils/tiptap.ts +113 -0
  102. package/templates/astro-starter/src/components/blocks/BlockRenderer.astro +9 -0
  103. package/templates/astro-starter/src/components/blocks/Form.astro +143 -0
  104. package/templates/astro-starter/src/components/blocks/HeaderImage.astro +6 -12
  105. package/templates/astro-starter/src/components/blocks/ImageBlock.astro +5 -6
  106. package/templates/astro-starter/src/components/blocks/NodeList.astro +274 -0
  107. package/templates/astro-starter/src/components/global/Breadcrumb.astro +50 -9
  108. package/templates/astro-starter/src/components/global/Footer.astro +7 -46
  109. package/templates/astro-starter/src/components/global/Header.astro +10 -16
  110. package/templates/astro-starter/src/components/global/NavigationMenu.astro +57 -46
  111. package/templates/astro-starter/src/components/ui/KamaImage.astro +13 -5
  112. package/templates/astro-starter/src/layouts/StandardLayout.astro +4 -3
  113. package/templates/astro-starter/src/lib/cms.ts +33 -11
  114. package/templates/astro-starter/src/lib/media/kama-image-service.ts +15 -4
  115. package/templates/astro-starter/src/lib/media/media-proxy.ts +22 -3
  116. package/templates/astro-starter/src/lib/media/media-url.ts +17 -3
  117. package/templates/astro-starter/src/middleware.ts +158 -100
  118. package/templates/astro-starter/src/pages/[...slug].astro +77 -3
  119. package/templates/astro-starter/src/pages/api/load-nodes.ts +68 -0
  120. package/templates/astro-starter/src/pages/api/partials/node-cards.astro +101 -0
  121. package/templates/kama-worker/index.js +38 -15
  122. package/templates/kama-worker/server.js +13 -5
  123. package/templates/kama-worker/setup-local-db.mjs +17 -0
  124. package/dist/assets/index-F2rfUymo.css +0 -1
  125. package/dist/assets/index-lXxH3VFK.js +0 -164
@@ -30,19 +30,19 @@ async function f() {
30
30
  if (n(f)) l = (await import(t(f).href)).compileDefinitions;
31
31
  else if (n(p)) l = (await import(t(p).href)).compileDefinitions;
32
32
  else try {
33
- l = (await import("./dist-Dy7-HUEG.js")).compileDefinitions;
33
+ l = (await import("./dist-D_Q1y4Kh.js")).compileDefinitions;
34
34
  } catch (e) {
35
- console.error("❌ Could not resolve Kama Schema Engine:", e), process.exit(1);
35
+ console.error("\x1B[31m ✖\x1B[0m \x1B[31mCould not resolve Kama Schema Engine:\x1B[0m", e), process.exit(1);
36
36
  }
37
- l || (console.error("❌ compileDefinitions function missing from resolved module"), process.exit(1));
37
+ l || (console.error("\x1B[31m ✖\x1B[0m \x1B[31mcompileDefinitions function missing from resolved module\x1B[0m"), process.exit(1));
38
38
  let m = l(), h = Object.keys(m?.nodes || {}).length, g = Object.keys(m?.blocks || {}).length, _ = Object.keys(m?.taxonomies || {}).length, v = `// AUTO-GENERATED BUNDLE - DO NOT EDIT
39
39
  const defs = ${JSON.stringify(m, null, 2)};
40
40
  export const BUNDLED_DEFINITIONS = defs;
41
41
  export default defs;
42
42
  `;
43
- a(c, v, "utf-8"), console.log(`✅ Schema securely compiled using engine.ts to ${c} (${h} nodes, ${g} blocks, ${_} taxonomies)`);
43
+ a(c, v, "utf-8"), console.log(`\x1b[32m ✓\x1b[0m \x1b[2mSchemas bundled (${h} nodes, ${g} blocks, ${_} taxonomies)\x1b[0m`);
44
44
  }
45
45
  f().catch((e) => {
46
- console.error("❌ Schema Compiler Runtime Error:", e), process.exit(1);
46
+ console.error("\x1B[31m ✖\x1B[0m \x1B[31mSchema Compiler Runtime Error:\x1B[0m", e), process.exit(1);
47
47
  });
48
48
  //#endregion
@@ -0,0 +1,204 @@
1
+ # KAMA CMS — Extension Development Guide
2
+
3
+ KAMA features a **Drop-In Extension Architecture**. Extensions are built using native TypeScript, Vue, and YAML, and are automatically discovered, registered, and compiled into the Cloudflare Worker and Vite SPA at build time.
4
+
5
+ This guarantees zero core bloat, perfect native performance, and a completely isolated development environment.
6
+
7
+ ## 1. How It Works (The Auto-Discovery Pipeline)
8
+
9
+ Extensions live in the `extensions/` directory at the root of your workspace.
10
+
11
+ When you run `npm run dev` or `npm run build:schema`, the KAMA CLI automatically:
12
+
13
+ 1. Scans the `extensions/` folder.
14
+ 2. Generates an `extension-registry.js` file.
15
+ 3. Injects your Database tables into the SQLite/D1 initialization sequence.
16
+ 4. Mounts your Hono API routes securely behind KAMA's authentication.
17
+ 5. Injects your Vue `.vue` components into the SPA routing and sidebars.
18
+ 6. Merges your extension's `.yaml` schemas natively into the core bundle.
19
+
20
+ ---
21
+
22
+ ## 2. Directory Structure
23
+
24
+ A standard extension uses the following structure:
25
+
26
+ kama-workspace/
27
+ ├─ extensions/
28
+ │ └─ forms/ <-- Your Extension Folder
29
+ │ ├─ index.ts <-- The Manifest (Exports UI, DB, and Routes)
30
+ │ ├─ api/
31
+ │ │ ├─ admin.ts <-- Hono routes for the Admin UI
32
+ │ │ └─ public.ts <-- Hono routes for the Public API
33
+ │ ├─ ui/
34
+ │ │ ├─ SidebarPane.vue <-- Custom Left Drawer Vue Component
35
+ │ │ └─ Dashboard.vue <-- Custom Main Workspace Vue Component
36
+ │ └─ content/ <-- 🎯 Schema folder matching Core
37
+ │ └─ blocks/
38
+ │ └─ form-block.yaml <-- YAML Schemas (Auto-merged into KAMA)
39
+
40
+ ---
41
+
42
+ ## 3. The Extension Manifest (`index.ts`)
43
+
44
+ Every extension must export a default object serving as the contract between your code and the KAMA core.
45
+
46
+ // extensions/forms/index.ts
47
+ import { adminFormsRouter } from "./api/admin.js";
48
+ import { publicFormsRouter } from "./api/public.js";
49
+
50
+ export default {
51
+ id: "kama-forms",
52
+ name: "Form Builder",
53
+
54
+ // 🎯 1. DATABASE HOOKS
55
+ // KAMA will automatically CREATE TABLE IF NOT EXISTS on boot.
56
+ db: {
57
+ tables: {
58
+ kama_forms_table: ` id INTEGER PRIMARY KEY AUTOINCREMENT,
59
+ form_id TEXT NOT NULL,
60
+ payload_json TEXT NOT NULL,
61
+ createdAt TEXT DEFAULT CURRENT_TIMESTAMP
62
+ `,
63
+ },
64
+ },
65
+
66
+ // 🎯 2. API ROUTING HOOKS
67
+ // Handled natively by Hono. KAMA injects c.env.DB automatically.
68
+ routes: {
69
+ public: publicFormsRouter, // Mounted at: /api/ext/kama-forms/_
70
+ admin: adminFormsRouter, // Mounted at: /api/admin/ext/kama-forms/_
71
+ },
72
+
73
+ // 🎯 3. FRONTEND UI HOOKS
74
+ ui: {
75
+ sidebar: [
76
+ {
77
+ id: "forms-nav",
78
+ label: "Forms",
79
+ icon: "Inbox", // Uses KAMA's global icon resolver
80
+ sidebarViewId: "forms-sidebar", // 🎯 Renders in the left drawer panel
81
+ viewId: "forms-dashboard", // 🎯 Renders in the main workspace canvas
82
+ },
83
+ ],
84
+
85
+ // Map your view IDs to your Vue component chunks
86
+ views: [
87
+ { id: "forms-sidebar", url: "/api/ext/kama-forms/ui-pane.js" },
88
+ { id: "forms-dashboard", url: "/api/ext/kama-forms/ui.js" }
89
+ ],
90
+
91
+ },
92
+ };
93
+
94
+ ---
95
+
96
+ ## 4. API Routing (`api/admin.ts`)
97
+
98
+ Extension APIs are built using standard Hono syntax.
99
+
100
+ **Important:** Your extension routes do not need to connect to the database manually. KAMA intercepts the request and injects the active database connection directly into the request context.
101
+
102
+ // extensions/forms/api/admin.ts
103
+ import { Hono } from "hono";
104
+ export const adminFormsRouter = new Hono();
105
+
106
+ adminFormsRouter.get("/submissions", async (c) => {
107
+ // Access the core database connection
108
+ const db = (c as any).env?.DB;
109
+ const formId = c.req.query("formId");
110
+
111
+ const stmt = db.prepare("SELECT \* FROM kama_forms_table WHERE form_id = ? ORDER BY createdAt DESC");
112
+ const results = typeof stmt.all === "function" ? await stmt.bind(formId).all() : [];
113
+
114
+ return c.json({ submissions: results?.results || results || [] });
115
+ });
116
+
117
+ ---
118
+
119
+ ## 5. Frontend UI & Cross-Component Communication
120
+
121
+ KAMA enforces strict decoupling. Extensions shouldn't mutate core routing states directly. Instead, KAMA provides generic Event Buses and State Stores.
122
+
123
+ ### Triggering Workspace Navigation
124
+
125
+ If a user clicks an item in your left `SidebarPane.vue` and you want to open your main `Dashboard.vue` in the primary workspace, dispatch a standard custom event. Core KAMA listens to this universally:
126
+
127
+ // Inside extensions/forms/ui/SidebarPane.vue
128
+ const openWorkspaceView = () => {
129
+ window.dispatchEvent(new CustomEvent('cms-open-extension-view', {
130
+ detail: { viewId: 'forms-dashboard' }
131
+ }));
132
+ };
133
+
134
+ ### Passing State Between Extension Components
135
+
136
+ To pass data (like a selected Form ID) from your Sidebar to your Dashboard, use the global `window.Kama` SDK:
137
+
138
+ **Setting State & Emitting Events (Sidebar):**
139
+
140
+ // Set state synchronously
141
+ (window as any).Kama?.state?.set('kama-forms', 'activeFormId', 'contact-form');
142
+
143
+ // Notify other components live
144
+ (window as any).Kama?.events?.emit('kama-forms:select-form', { formId: 'contact-form' });
145
+
146
+ **Listening for State (Dashboard):**
147
+
148
+ // Read initial state on mount
149
+ const initialId = (window as any).Kama?.state?.get('kama-forms', 'activeFormId');
150
+
151
+ // Listen for live changes
152
+ (window as any).Kama?.events?.on('kama-forms:select-form', (payload) => {
153
+ console.log("Form Selected:", payload.formId);
154
+ });
155
+
156
+ ---
157
+
158
+ ## 6. Extension YAML Schemas (`content/`)
159
+
160
+ Extensions can bundle their own content schemas (Nodes, Blocks, Taxonomies). Place them in your extension's `content/` folder (e.g., `extensions/forms/content/blocks/form.yaml`).
161
+
162
+ Run `npm run build:schema` to compile them automatically into KAMA.
163
+
164
+ ### 🎯 NEW: Dynamic API Dropdowns (`optionsEndpoint`)
165
+
166
+ KAMA's frontend features Universal Async Field fetching. You can define a `select` or `pills` field that dynamically pulls its options from your extension's API endpoint!
167
+
168
+ **Example YAML Block Definition:**
169
+
170
+ # extensions/forms/content/blocks/form-block.yaml
171
+
172
+ id: form
173
+ label: Dynamic Form
174
+ description: Embeds a form definition into the page.
175
+ category: Interactive
176
+ icon: ClipboardList
177
+
178
+ # You can inherit standard KAMA fieldsets!
179
+
180
+ fieldSets:
181
+
182
+ - access
183
+
184
+ fields:
185
+
186
+ # This dropdown populates automatically via your API!
187
+
188
+ formId:
189
+ label: Select Form
190
+ type: select
191
+ required: true
192
+ optionsEndpoint: /api/admin/ext/kama-forms/forms
193
+ optionsValueKey: id # Maps to the option value
194
+ optionsLabelKey: title # Maps to the visible label
195
+
196
+ ---
197
+
198
+ ## 7. Caching and Extension Updates
199
+
200
+ Because KAMA caches HTML at the Edge (Cloudflare CDN) and inside Worker KV:
201
+
202
+ If your extension API modifies public-facing content (e.g., approving a review, updating inventory), your extension's Hono router must manually trigger KAMA's cache purger to drop the cached Edge pages.
203
+
204
+ _(Note: KAMA's `EdgeCacheManager` is currently scoped to the core, so for now, extensions should rely on KAMA's internal APIs or direct node updates if immediate Edge Purging is required)._
@@ -0,0 +1,5 @@
1
+ import kamaForms from './extensions/kama-forms/index.ts';
2
+
3
+ export const activeExtensions = [
4
+ kamaForms
5
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightsideoy/kama",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.20",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -8,7 +8,9 @@
8
8
  ".": {
9
9
  "types": "./dist/index.d.ts",
10
10
  "import": "./dist/index.js"
11
- }
11
+ },
12
+ "./schema.sql": "./schema.sql",
13
+ "./package.json": "./package.json"
12
14
  },
13
15
  "bin": {
14
16
  "kama": "bin/cli.js",
@@ -22,6 +24,8 @@
22
24
  "bundle:definitions": "node bin/cli.js bundle",
23
25
  "build:schema": "tsx scripts/build-schema.ts",
24
26
  "build:seed": "tsx scripts/build-seed.ts",
27
+ "seed": "npm run seed:local",
28
+ "seed:local": "tsx scripts/build-seed.ts && sqlite3 kama.db < seed.sql",
25
29
  "build:server": "vite build",
26
30
  "build:ui": "vite build --config vite.config.ui.ts",
27
31
  "build": "npm run bundle:definitions && npm run build:schema && npm run build:server && npm run build:ui",
@@ -33,6 +37,7 @@
33
37
  "access": "public"
34
38
  },
35
39
  "dependencies": {
40
+ "@clack/prompts": "^1.8.1",
36
41
  "@heroicons/vue": "^2.2.0",
37
42
  "@hono/node-server": "^2.1.1",
38
43
  "@hono/swagger-ui": "^0.6.1",
@@ -49,6 +54,7 @@
49
54
  "@tiptap/vue-3": "^3.30.0",
50
55
  "drizzle-orm": "^0.45.2",
51
56
  "hono": "^4.13.2",
57
+ "js-yaml": "^5.5.0",
52
58
  "locale-codes": "^1.3.1",
53
59
  "lru-cache": "^11.5.2",
54
60
  "lucide-vue-next": "^1.0.0",
@@ -63,6 +69,7 @@
63
69
  "@iconify-json/heroicons": "^1.2.3",
64
70
  "@iconify-json/lucide": "^1.2.123",
65
71
  "@libsql/client": "^0.14.0",
72
+ "@types/js-yaml": "^4.0.9",
66
73
  "@types/node": "^26.2.0",
67
74
  "@types/sharp": "^0.31.1",
68
75
  "@types/yaml": "^1.9.6",
package/schema.sql CHANGED
@@ -13,7 +13,7 @@ CREATE TABLE IF NOT EXISTS "content_schemas" (
13
13
 
14
14
  CREATE TABLE IF NOT EXISTS "users" (
15
15
  id TEXT PRIMARY KEY,
16
- email TEXT UNIQUE NOT NULL,
16
+ email UNIQUE NOT NULL,
17
17
  name TEXT NOT NULL,
18
18
  globalRole TEXT DEFAULT 'editor',
19
19
  createdAt TEXT DEFAULT CURRENT_TIMESTAMP,
@@ -92,6 +92,8 @@ CREATE TABLE IF NOT EXISTS "content_nodes" (
92
92
  language TEXT,
93
93
  isHidden INTEGER NOT NULL DEFAULT 0,
94
94
  status TEXT DEFAULT 'draft',
95
+ startShowingAt TEXT,
96
+ stopShowingAt TEXT,
95
97
  hasUnpublishedChanges INTEGER DEFAULT 0,
96
98
  disabledRegionsJson TEXT DEFAULT '{}',
97
99
  dataJson TEXT,
@@ -201,6 +203,32 @@ CREATE TABLE IF NOT EXISTS "node_terms" (
201
203
  FOREIGN KEY (termId) REFERENCES taxonomy_terms(id) ON DELETE CASCADE
202
204
  );
203
205
 
206
+ CREATE TABLE IF NOT EXISTS "node_relations" (
207
+ sourceNodeId INTEGER NOT NULL,
208
+ targetNodeId INTEGER NOT NULL,
209
+ fieldKey TEXT NOT NULL,
210
+ sortOrder INTEGER DEFAULT 0,
211
+ PRIMARY KEY (sourceNodeId, targetNodeId, fieldKey),
212
+ FOREIGN KEY (sourceNodeId) REFERENCES content_nodes(id) ON DELETE CASCADE,
213
+ FOREIGN KEY (targetNodeId) REFERENCES content_nodes(id) ON DELETE CASCADE
214
+ );
215
+
216
+ CREATE TABLE IF NOT EXISTS "node_routes" (
217
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
218
+ path TEXT NOT NULL,
219
+ channelId INTEGER NOT NULL,
220
+ nodeId INTEGER,
221
+ treeId INTEGER,
222
+ isCanonical INTEGER DEFAULT 1,
223
+ redirectUrl TEXT,
224
+ createdAt TEXT DEFAULT CURRENT_TIMESTAMP,
225
+ updatedAt TEXT DEFAULT CURRENT_TIMESTAMP,
226
+ FOREIGN KEY (channelId) REFERENCES channels(id) ON DELETE CASCADE,
227
+ FOREIGN KEY (nodeId) REFERENCES content_nodes(id) ON DELETE CASCADE,
228
+ FOREIGN KEY (treeId) REFERENCES trees(id) ON DELETE CASCADE,
229
+ UNIQUE(path, channelId)
230
+ );
231
+
204
232
  CREATE INDEX IF NOT EXISTS idx_tree_nodes_tree_parent ON tree_nodes(treeId, parentId);
205
233
  CREATE INDEX IF NOT EXISTS idx_tree_nodes_contentId ON tree_nodes(contentId);
206
234
  CREATE INDEX IF NOT EXISTS idx_content_nodes_slug_status ON content_nodes(slug, status);
@@ -233,3 +261,8 @@ CREATE INDEX IF NOT EXISTS idx_node_terms_node ON node_terms(nodeId);
233
261
  CREATE INDEX IF NOT EXISTS idx_node_terms_term ON node_terms(termId);
234
262
  CREATE INDEX IF NOT EXISTS idx_node_terms_node_term ON node_terms(nodeId, termId);
235
263
  CREATE INDEX IF NOT EXISTS idx_node_terms_term_node ON node_terms(termId, nodeId);
264
+ CREATE INDEX IF NOT EXISTS idx_node_relations_source ON node_relations(sourceNodeId);
265
+ CREATE INDEX IF NOT EXISTS idx_node_relations_target ON node_relations(targetNodeId);
266
+ CREATE INDEX IF NOT EXISTS idx_node_routes_lookup ON node_routes(path, channelId);
267
+ CREATE INDEX IF NOT EXISTS idx_node_routes_node ON node_routes(nodeId);
268
+ CREATE INDEX IF NOT EXISTS idx_content_nodes_public_feed ON content_nodes(contentType, isHidden, status, startShowingAt, stopShowingAt, updatedAt DESC);
@@ -0,0 +1,143 @@
1
+ ---
2
+ // src/components/blocks/BlockRenderer.astro
3
+
4
+ import ImageBlock from "@/components/blocks/ImageBlock.astro";
5
+ import HeaderImage from "@/components/blocks/HeaderImage.astro";
6
+ import ColumnLayout from "@/components/blocks/ColumnLayout.astro";
7
+ import HtmlBlock from "@/components/blocks/HtmlBlock.astro";
8
+ import NodeList from "@/components/blocks/NodeList.astro"; // 🎯 NEW IMPORT
9
+ import { extractHtml } from "@/utils/tiptap";
10
+
11
+ interface Block {
12
+ instanceId: number;
13
+ blockId?: string;
14
+ componentId: string;
15
+ data: Record<string, any>;
16
+ }
17
+
18
+ interface Props {
19
+ blocks?: Block[];
20
+ contentMap?: Record<string, any[]>;
21
+ region?: string;
22
+ }
23
+
24
+ const { blocks = [], contentMap = {}, region = "main" } = Astro.props;
25
+ const safeBlocks = Array.isArray(blocks) ? blocks : [];
26
+
27
+ const visibleBlocks = safeBlocks.filter(b => {
28
+ if (!b || (!b.data && !b.componentId?.includes("column"))) return false;
29
+
30
+ const blockData = b.data || {};
31
+ if (
32
+ blockData.hidden === true ||
33
+ blockData.hidden === 1 ||
34
+ String(blockData.hidden) === "true"
35
+ ) {
36
+ return false;
37
+ }
38
+
39
+ const now = new Date();
40
+ if (blockData.startShowingAt) {
41
+ const start = new Date(blockData.startShowingAt);
42
+ if (!isNaN(start.getTime()) && now < start) return false;
43
+ }
44
+ if (blockData.stopShowingAt) {
45
+ const stop = new Date(blockData.stopShowingAt);
46
+ if (!isNaN(stop.getTime()) && now > stop) return false;
47
+ }
48
+
49
+ return true;
50
+ });
51
+ ---
52
+
53
+ {
54
+ visibleBlocks.map((block, index) => {
55
+ const data = block.data || {};
56
+ const blockId = block.blockId || data.blockId || "";
57
+ const componentId = (block.componentId || "").toLowerCase();
58
+
59
+ // Check for any column layout ending in column or two-column
60
+ if (componentId.includes("column")) {
61
+ return <ColumnLayout blockId={blockId} contentMap={contentMap} />;
62
+ }
63
+
64
+ switch (componentId) {
65
+ // 🎯 ADDED NODE LIST CASES
66
+ case "node-list":
67
+ case "nodelist":
68
+ case "article-list":
69
+ case "content-feed": {
70
+ return <NodeList data={data} />;
71
+ }
72
+
73
+ case "header":
74
+ case "headline":
75
+ case "header-block":
76
+ case "header_block": {
77
+ const headline = extractHtml(data.headline || data.title);
78
+ const subhead = extractHtml(data.subhead || data.body);
79
+ return (
80
+ <header class="cms-block cms-block-header">
81
+ {headline && <Fragment set:html={headline} />}
82
+ {subhead && <Fragment set:html={subhead} />}
83
+ </header>
84
+ );
85
+ }
86
+
87
+ case "text":
88
+ case "text-block":
89
+ case "text_block": {
90
+ const bodyText = extractHtml(data.body || data.text || data.content);
91
+ return (
92
+ <div class="cms-block cms-block-text">
93
+ <Fragment set:html={bodyText} />
94
+ </div>
95
+ );
96
+ }
97
+
98
+ case "html":
99
+ case "html-block":
100
+ case "html_block":
101
+ case "raw-html": {
102
+ return <HtmlBlock data={data} />;
103
+ }
104
+
105
+ case "header-image":
106
+ case "header_image": {
107
+ return (
108
+ <HeaderImage data={data} region={region} isFirst={index === 0} />
109
+ );
110
+ }
111
+
112
+ case "image":
113
+ case "image-block":
114
+ case "image_block":
115
+ case "single_image":
116
+ case "single-image": {
117
+ return <ImageBlock data={data} region={region} isFirst={index === 0} />;
118
+ }
119
+
120
+ default:
121
+ return import.meta.env.DEV ? (
122
+ <div class="unhandled-block">
123
+ <p>Unhandled component: {block.componentId}</p>
124
+ </div>
125
+ ) : null;
126
+ }
127
+ })
128
+ }
129
+
130
+ <style>
131
+ .cms-block {
132
+ margin-bottom: 1.5rem;
133
+ }
134
+
135
+ .unhandled-block {
136
+ padding: 12px 16px;
137
+ border: 1px dashed #cbd5e1;
138
+ background: #f8fafc;
139
+ color: #64748b;
140
+ font-size: 13px;
141
+ margin-bottom: 1.5rem;
142
+ }
143
+ </style>
@@ -0,0 +1,67 @@
1
+ ---
2
+ // src/components/blocks/ColumnLayout.astro
3
+
4
+ import BlockRenderer from "@/components/blocks/BlockRenderer.astro";
5
+
6
+ interface Props {
7
+ blockId: string;
8
+ contentMap: Record<string, any[]>;
9
+ }
10
+
11
+ const { blockId, contentMap } = Astro.props;
12
+
13
+ const order = ["left", "middle", "right", "col1", "col2", "col3", "col4"];
14
+
15
+ // 1. Find all sub-regions belonging to this specific layout instance
16
+ const regionKeys = Object.keys(contentMap).filter(
17
+ key => blockId && key.startsWith(`${blockId}_`),
18
+ );
19
+
20
+ // 2. Sort keys logically (left -> middle -> right or col1 -> col2 -> col3)
21
+ const sortedKeys = regionKeys.sort((a, b) => {
22
+ const suffixA = a.replace(`${blockId}_`, "");
23
+ const suffixB = b.replace(`${blockId}_`, "");
24
+ const idxA = order.indexOf(suffixA);
25
+ const idxB = order.indexOf(suffixB);
26
+
27
+ if (idxA === -1 && idxB === -1) return a.localeCompare(b);
28
+ if (idxA === -1) return 1;
29
+ if (idxB === -1) return -1;
30
+ return idxA - idxB;
31
+ });
32
+
33
+ const columnCount = Math.max(sortedKeys.length, 1);
34
+ ---
35
+
36
+ <div class="cms-column-layout" style={`--col-count: ${columnCount}`}>
37
+ {
38
+ sortedKeys.map(key => {
39
+ const columnBlocks = contentMap[key] || [];
40
+ return (
41
+ <div class="column">
42
+ <!-- 🎯 Passes region={key} down to BlockRenderer -->
43
+ <BlockRenderer
44
+ blocks={columnBlocks}
45
+ contentMap={contentMap}
46
+ region={key}
47
+ />
48
+ </div>
49
+ );
50
+ })
51
+ }
52
+ </div>
53
+
54
+ <style>
55
+ .cms-column-layout {
56
+ display: grid;
57
+ gap: 2rem;
58
+ margin-bottom: 1.5rem;
59
+ grid-template-columns: 1fr;
60
+ }
61
+
62
+ @media (min-width: 768px) {
63
+ .cms-column-layout {
64
+ grid-template-columns: repeat(var(--col-count, 1), 1fr);
65
+ }
66
+ }
67
+ </style>
@@ -0,0 +1,126 @@
1
+ ---
2
+ // src/components/blocks/HeaderImage.astro
3
+
4
+ import KamaImage from "@/components/ui/KamaImage.astro";
5
+
6
+ interface Props {
7
+ data: {
8
+ image?: any;
9
+ image_meta?: any;
10
+ width?: number | string;
11
+ height?: number | string;
12
+ };
13
+ region?: string;
14
+ isFirst?: boolean;
15
+ }
16
+
17
+ const { data, region = "main", isFirst = false } = Astro.props;
18
+
19
+ const img = data?.image;
20
+
21
+ if (!img) {
22
+ return null;
23
+ }
24
+
25
+ /**
26
+ * Determine if this image is likely to be the Largest Contentful Paint.
27
+ */
28
+ const isLcp = region === "header" || (region === "main" && isFirst);
29
+
30
+ /**
31
+ * Determine grid column count from the region name.
32
+ */
33
+ let columnCount = 1;
34
+
35
+ if (region.includes("_")) {
36
+ columnCount = 2;
37
+
38
+ if (region.includes("_middle") || region.includes("_col3")) {
39
+ columnCount = 3;
40
+ }
41
+
42
+ if (region.includes("_col4")) {
43
+ columnCount = 4;
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Default single-column layout (aligned to backend CDN buckets).
49
+ */
50
+ let maxWidth = "1352";
51
+ let targetColumnWidth = 1352;
52
+
53
+ // 1-col: 1x/2x desktop and retina buckets
54
+ let optimizedWidths = [768, 1352, 1920, 2560];
55
+ let sizes = "(max-width: 1399px) calc(100vw - 48px), 1352px";
56
+
57
+ /**
58
+ * Two-column layout.
59
+ */
60
+ if (columnCount === 2) {
61
+ maxWidth = "660";
62
+ targetColumnWidth = 660;
63
+
64
+ optimizedWidths = [640, 768, 1024, 1352];
65
+ sizes =
66
+ "(max-width: 767px) calc(100vw - 48px), " +
67
+ "(max-width: 1399px) calc((100vw - 80px) / 2), " +
68
+ "660px";
69
+ }
70
+
71
+ /**
72
+ * Three-column layout.
73
+ */
74
+ else if (columnCount === 3) {
75
+ maxWidth = "429";
76
+ targetColumnWidth = 429;
77
+
78
+ optimizedWidths = [320, 640, 768, 1024];
79
+ sizes =
80
+ "(max-width: 767px) calc(100vw - 48px), " +
81
+ "(max-width: 1399px) calc((100vw - 112px) / 3), " +
82
+ "429px";
83
+ }
84
+
85
+ /**
86
+ * Four-column layout.
87
+ */
88
+ else if (columnCount === 4) {
89
+ maxWidth = "314";
90
+ targetColumnWidth = 314;
91
+
92
+ optimizedWidths = [320, 640, 768];
93
+ sizes =
94
+ "(max-width: 767px) calc(100vw - 48px), " +
95
+ "(max-width: 1399px) calc((100vw - 144px) / 4), " +
96
+ "314px";
97
+ }
98
+ ---
99
+
100
+ <div class="cms-block cms-block-header-image" style={`--max-w: ${maxWidth}px;`}>
101
+ <KamaImage
102
+ image={img}
103
+ sizes={sizes}
104
+ desktopWidths={optimizedWidths}
105
+ idealWidth={targetColumnWidth}
106
+ class="responsive-header-image"
107
+ loading={isLcp ? "eager" : "lazy"}
108
+ fetchpriority={isLcp ? "high" : "auto"}
109
+ />
110
+ </div>
111
+
112
+ <style>
113
+ .cms-block-header-image {
114
+ width: 100%;
115
+ max-width: var(--max-w, 1352px);
116
+ margin: 0 auto 1.5rem auto;
117
+ }
118
+
119
+ :global(.responsive-header-image) {
120
+ width: 100%;
121
+ height: auto;
122
+ display: block;
123
+ border-radius: var(--cms-radius-md, 0.5rem);
124
+ max-width: 100%;
125
+ }
126
+ </style>