domma-cms 0.13.7 → 0.14.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.
Files changed (35) hide show
  1. package/admin/css/admin.css +1 -1
  2. package/admin/js/api.js +1 -1
  3. package/admin/js/app.js +2 -2
  4. package/admin/js/config/sidebar-config.js +1 -1
  5. package/admin/js/lib/markdown-toolbar.js +24 -18
  6. package/admin/js/lib/scribe-composer.js +4 -0
  7. package/admin/js/lib/simple-editor.js +49 -0
  8. package/admin/js/templates/block-editor.html +76 -18
  9. package/admin/js/templates/blocks.html +18 -8
  10. package/admin/js/templates/component-editor.html +141 -0
  11. package/admin/js/templates/components.html +18 -0
  12. package/admin/js/views/block-editor-enhance.js +1 -0
  13. package/admin/js/views/block-editor.js +8 -8
  14. package/admin/js/views/blocks.js +11 -4
  15. package/admin/js/views/component-editor.js +28 -0
  16. package/admin/js/views/components.js +11 -0
  17. package/admin/js/views/index.js +1 -1
  18. package/admin/js/views/page-editor.js +6 -6
  19. package/admin/js/views/pages.js +5 -2
  20. package/config/site.json +1 -1
  21. package/package.json +2 -2
  22. package/public/css/site.css +1 -1
  23. package/server/routes/api/blocks.js +128 -60
  24. package/server/routes/api/components.js +115 -0
  25. package/server/routes/api/pages.js +135 -132
  26. package/server/routes/api/versions.js +16 -0
  27. package/server/server.js +6 -0
  28. package/server/services/blocks.js +387 -284
  29. package/server/services/components.js +653 -0
  30. package/server/services/content.js +334 -334
  31. package/server/services/hooks.js +28 -0
  32. package/server/services/markdown.js +2836 -2629
  33. package/server/services/permissionRegistry.js +13 -0
  34. package/server/services/renderer.js +10 -2
  35. package/server/services/versions.js +37 -0
@@ -48,6 +48,19 @@ export const REGISTRY = [
48
48
  {key: 'delete', label: 'Delete', description: 'Delete blocks'}
49
49
  ]
50
50
  },
51
+ {
52
+ key: 'components',
53
+ label: 'Components',
54
+ description: 'Manage reusable Domma components.',
55
+ icon: 'component',
56
+ group: 'Content',
57
+ actions: [
58
+ {key: 'read', label: 'View', description: 'View components'},
59
+ {key: 'create', label: 'Create', description: 'Create new components'},
60
+ {key: 'update', label: 'Edit', description: 'Edit existing components'},
61
+ {key: 'delete', label: 'Delete', description: 'Delete components'}
62
+ ]
63
+ },
51
64
  {
52
65
  key: 'navigation',
53
66
  label: 'Navigation',
@@ -157,7 +157,10 @@ export async function renderPage(page) {
157
157
  bodyEndInject: [
158
158
  injection.bodyEnd,
159
159
  site.backToTop?.enabled ? '<script src="/public/js/btt.js"></script>' : '',
160
- site.cookieConsent?.enabled ? '<script src="/public/js/cookie-consent.js"></script>' : ''
160
+ site.cookieConsent?.enabled ? '<script src="/public/js/cookie-consent.js"></script>' : '',
161
+ (page.usedComponents || [])
162
+ .map(n => `<script type="module" src="/api/components/${n}.js"></script>`)
163
+ .join('\n')
161
164
  ].filter(Boolean).join('\n'),
162
165
  dconfigScript,
163
166
  };
@@ -358,7 +361,12 @@ export async function renderBlogPage(templatePath, data = {}, seoMeta = {}) {
358
361
  }).replace(/<\/script>/gi, '<\\/script>'),
359
362
  headInject: [ogTags, injection.head, navbarFontLink].filter(Boolean).join('\n'),
360
363
  headInjectLate: [injection.headLate, customCssTag, navbarStyleTag].filter(Boolean).join('\n'),
361
- bodyEndInject: injection.bodyEnd || '',
364
+ bodyEndInject: [
365
+ injection.bodyEnd,
366
+ (page.usedComponents || [])
367
+ .map(n => `<script type="module" src="/api/components/${n}.js"></script>`)
368
+ .join('\n')
369
+ ].filter(Boolean).join('\n'),
362
370
  dconfigScript: ''
363
371
  };
364
372
 
@@ -157,6 +157,43 @@ export async function listVersions(urlPath) {
157
157
  return [...meta].sort((a, b) => b.createdAt.localeCompare(a.createdAt));
158
158
  }
159
159
 
160
+ /**
161
+ * Count versions for a page without loading their content.
162
+ * Returns 0 if the page has no versions directory.
163
+ *
164
+ * @param {string} urlPath
165
+ * @returns {Promise<number>}
166
+ */
167
+ export async function getVersionCount(urlPath) {
168
+ const dir = versionsDirForPath(urlPath);
169
+ const meta = await readMeta(dir);
170
+ return meta.length;
171
+ }
172
+
173
+ /**
174
+ * Prune a page's version history, retaining only the most recent `keep` entries
175
+ * (and any others your retention policy decides to preserve).
176
+ *
177
+ * @param {string} urlPath
178
+ * @param {{ keep?: number }} options
179
+ * @returns {Promise<{ deleted: number, kept: number }>}
180
+ */
181
+ export async function pruneVersions(urlPath, {keep = 5} = {}) {
182
+ const dir = versionsDirForPath(urlPath);
183
+ const meta = await readMeta(dir);
184
+
185
+ // Newest first — index 0 is the most recent snapshot
186
+ const sorted = [...meta].sort((a, b) => b.createdAt.localeCompare(a.createdAt));
187
+
188
+ // Manually-named snapshots are always preserved (deliberate restore points).
189
+ // Auto snapshots beyond the newest `keep` are deleted.
190
+ const expendable = sorted.filter(m => m.type !== 'manual');
191
+ const toDelete = expendable.slice(keep).map(m => m.filename);
192
+
193
+ if (toDelete.length) await deleteVersions(urlPath, toDelete);
194
+ return {deleted: toDelete.length, kept: sorted.length - toDelete.length};
195
+ }
196
+
160
197
  /**
161
198
  * Get the raw content of a specific version file plus its meta entry.
162
199
  *