domma-cms 1.27.3 → 1.28.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 (62) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/CLAUDE.md +2 -2
  3. package/admin/js/app.js +4 -4
  4. package/admin/js/lib/chats-arrange.js +2 -0
  5. package/admin/js/lib/launchers-arrange.js +2 -0
  6. package/admin/js/lib/menu-item-help.js +1 -1
  7. package/admin/js/lib/page-image-hosts.js +2 -2
  8. package/admin/js/lib/shortcode-form.js +6 -6
  9. package/admin/js/lib/shortcode-registry.js +1 -1
  10. package/admin/js/templates/chat-knowledge.html +96 -0
  11. package/admin/js/templates/chats.html +146 -0
  12. package/admin/js/templates/docs/usage-chat.html +96 -0
  13. package/admin/js/templates/docs/usage-launchers.html +83 -0
  14. package/admin/js/templates/docs/usage-media.html +14 -0
  15. package/admin/js/templates/docs/usage-navigation.html +3 -0
  16. package/admin/js/templates/docs/usage-shortcodes.html +8 -0
  17. package/admin/js/templates/documentation.html +8 -0
  18. package/admin/js/templates/launchers.html +105 -0
  19. package/admin/js/views/chat-knowledge.js +60 -0
  20. package/admin/js/views/chats.js +53 -0
  21. package/admin/js/views/doc-pages.js +1 -1
  22. package/admin/js/views/index.js +1 -1
  23. package/admin/js/views/launchers.js +230 -0
  24. package/admin/js/views/menu-editor.js +22 -22
  25. package/admin/js/views/page-editor.js +10 -10
  26. package/docs/DommaFeatures.md +30 -0
  27. package/docs/markdown-shortcodes.md +69 -16
  28. package/package.json +1 -1
  29. package/public/css/image-zoom.css +1 -0
  30. package/public/css/launcher-chat.css +1 -0
  31. package/public/css/launchers.css +1 -0
  32. package/public/css/site.css +1 -1
  33. package/public/js/image-zoom.mjs +30 -0
  34. package/public/js/launcher-chat.mjs +47 -0
  35. package/public/js/launcher-settings.mjs +2 -0
  36. package/public/js/launchers.mjs +12 -0
  37. package/public/js/motion-control.mjs +1 -1
  38. package/public/js/site.js +1 -1
  39. package/server/routes/api/chat.js +203 -0
  40. package/server/routes/api/chats.js +235 -0
  41. package/server/routes/api/launchers.js +50 -0
  42. package/server/routes/launcher-public.js +96 -0
  43. package/server/server.js +33 -0
  44. package/server/services/adapterRegistry.js +4 -4
  45. package/server/services/adapters/FileAdapter.js +18 -0
  46. package/server/services/adapters/MongoAdapter.js +14 -0
  47. package/server/services/chat/conversation.js +458 -0
  48. package/server/services/chat/launcher-bridge.js +73 -0
  49. package/server/services/chat/matcher.js +324 -0
  50. package/server/services/chat/settings.js +118 -0
  51. package/server/services/chat/store.js +532 -0
  52. package/server/services/collectionAccess.js +16 -0
  53. package/server/services/docs.js +2 -0
  54. package/server/services/launchers.js +172 -0
  55. package/server/services/markdown.js +175 -4
  56. package/server/services/number-fields-migration.js +4 -0
  57. package/server/services/permissionRegistry.js +12 -0
  58. package/server/services/presetCollections.js +75 -2
  59. package/server/services/renderer.js +86 -18
  60. package/server/services/roles.js +1 -1
  61. package/server/services/tools.js +1 -0
  62. package/server/templates/page.html +4 -2
@@ -17,6 +17,7 @@ import {resolveContextMenusForPage} from './contextMenus.js';
17
17
  import {buildCustomThemeStyleTag, buildOverrideStyleTag, getThemeTokenMap, listThemeIds, loadThemeConfig, resolveThemeClasses} from './themeSettings.js';
18
18
  import {getSearchSettings} from './search.js';
19
19
  import {motionSettingsOf} from './motionSettings.js';
20
+ import {LAUNCHERS_ASSET_V, buildLauncherAssets} from './launchers.js';
20
21
  import {isToolEnabled} from './tools.js';
21
22
  import {consentSettingsFor, measurementIdOf} from './googleAnalytics.js';
22
23
  import {fmtDateTime} from './dates.js';
@@ -156,6 +157,20 @@ function buildAnalyticsTag() {
156
157
  * @returns {{headTag: string, bodyTag: string}} Empty strings when nothing needs it
157
158
  */
158
159
  /** A value for a double-quoted HTML attribute. */
160
+ /**
161
+ * The [image zoom] view's module, for a page that has a zoomable picture
162
+ * (markdown.js renderImage marks them `data-dm-zoom`) - none otherwise.
163
+ * Both render paths need it.
164
+ *
165
+ * @param {...string} parts - the page's html, its footer blocks
166
+ * @returns {string}
167
+ */
168
+ export function imageZoomModule(...parts) {
169
+ return parts.some(p => typeof p === 'string' && p.includes('data-dm-zoom'))
170
+ ? '<script src="/public/js/image-zoom.mjs?v=20261031-image-zoom-keys" type="module"></script>'
171
+ : '';
172
+ }
173
+
159
174
  function escapeAttrValue(v) {
160
175
  return String(v).replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
161
176
  }
@@ -313,6 +328,38 @@ function filterHiddenNavItems(nav) {
313
328
  return {...nav, items};
314
329
  }
315
330
 
331
+ /**
332
+ * The Reduce motion settings inside a launcher's panel: the site's default
333
+ * still decides whether the body moves (page.html's bootstrap reads the stored
334
+ * choice the same way), but the control itself is the page's around it.
335
+ */
336
+ function embedMotionAssets(site) {
337
+ return {siteFields: {motion: {...motionSettingsOf(site), enabled: false}}, headTag: ''};
338
+ }
339
+
340
+ /**
341
+ * Inside a launcher's panel: a page that fits its frame, and links that leave
342
+ * it. A link to another address opens in the page around the panel (a link
343
+ * that opens a new window keeps doing so); one to a spot on this page stays.
344
+ */
345
+ const EMBED_HEAD_TAG = `<link rel="stylesheet" href="/public/css/launchers.css?v=${LAUNCHERS_ASSET_V}">`;
346
+ const EMBED_BODY_TAG = `<script>
347
+ document.addEventListener('click', function (e) {
348
+ var a = e.target.closest && e.target.closest('a[href]');
349
+ if (!a || e.defaultPrevented || a.target || e.button !== 0 || e.ctrlKey || e.metaKey || e.shiftKey) return;
350
+ var url = new URL(a.href, location.href);
351
+ if (url.origin === location.origin && url.pathname === location.pathname && url.hash) return;
352
+ if (window.top === window) return;
353
+ e.preventDefault();
354
+ window.top.location.href = url.href;
355
+ });
356
+ // A form that posts the ordinary way (one with an action of its own) answers in the page around the panel.
357
+ document.addEventListener('submit', function (e) {
358
+ var f = e.target;
359
+ if (window.top !== window && f && f.getAttribute && f.getAttribute('action') && !f.target) f.target = '_top';
360
+ }, true);
361
+ </script>`;
362
+
316
363
  /**
317
364
  * Build the overlay menus for a page: every menu bound to the `overlay` slot
318
365
  * whose binding matches, each drawn by the same builder the `[menu]` shortcode
@@ -353,9 +400,14 @@ async function buildOverlayMenus(menuCtx, user) {
353
400
  * by the editor's full-page preview, which has no banner.
354
401
  * @param {Set<string>} [opts.cacheTags] - Receives the cache tags of what the shell
355
402
  * drew beyond the page body (the footer blocks' shortcodes), for the caller's cache entry.
403
+ * @param {boolean} [opts.embed] - The page drawn inside a launcher's panel (routes/launcher-public.js):
404
+ * the body alone - no navbar, footer, sidebar or breadcrumbs, and none of the page's own floating
405
+ * controls (search, reduce motion, theme switcher, back to top, overlay menus, launchers), no
406
+ * analytics and no plugin body-end widgets. Links leave the panel for the page around it.
356
407
  * @returns {Promise<string>}
357
408
  */
358
409
  export async function renderPage(page, opts = {}) {
410
+ const embed = opts.embed === true;
359
411
  // Page context for menu bindings - a menu bound to this URL or this page's
360
412
  // project takes its slot over. `resolvedProject` is stamped by the content
361
413
  // service; fall back to resolving it here for callers that skip that path.
@@ -426,20 +478,26 @@ export async function renderPage(page, opts = {}) {
426
478
  }
427
479
  : (await readLegacyNavBackup()) || {brand: site.brand || {}, items: []};
428
480
 
429
- const preset = presets[page.layout] || presets['default'] || {};
430
- const pageContents = resolveContents(preset, page, readContentsOverride(page.html));
481
+ // Inside a launcher's panel the layout is the body alone, whatever the page asks for.
482
+ const preset = embed
483
+ ? {navbar: false, footer: false, sidebar: false, width: 'normal'}
484
+ : (presets[page.layout] || presets['default'] || {});
485
+ const pageContents = embed
486
+ ? {...resolveContents(preset, page, readContentsOverride(page.html)), hidden: true}
487
+ : resolveContents(preset, page, readContentsOverride(page.html));
431
488
 
432
489
  // Per-page `width:` frontmatter overrides the preset's width when valid.
433
490
  const pageWidth = VALID_LAYOUT_WIDTHS.has(page.width) ? page.width : null;
434
491
  const layoutWidth = pageWidth || (VALID_LAYOUT_WIDTHS.has(preset.width) ? preset.width : 'normal');
435
492
  // A vertical navbar docks as a side rail, so the body needs its gutter from
436
493
  // the first paint - stamping the class client-side would shift the layout.
437
- const verticalNavClass = railBodyClass(navigation);
494
+ const verticalNavClass = embed ? '' : railBodyClass(navigation);
438
495
  const navbarClass = (navigation.orientation === 'vertical' && navigation.position !== 'floating')
439
496
  ? `dm-nav-vertical dm-nav-vertical-${navigation.side === 'right' ? 'right' : 'left'}`
440
497
  : '';
441
498
  // Site Settings > Appearance > Body CSS classes - the designer's own, on every page.
442
- const layoutBodyClass = ['dm-layout-' + layoutWidth, preset.class || '', verticalNavClass, ...cssClasses(site.bodyClass)].filter(Boolean).join(' ');
499
+ const layoutBodyClass = ['dm-layout-' + layoutWidth, preset.class || '', verticalNavClass, ...cssClasses(site.bodyClass),
500
+ embed ? 'dm-launcher-embed' : ''].filter(Boolean).join(' ');
443
501
  const pageBodyStyleParts = [];
444
502
  const BG_COLOR_SAFE = /^[a-zA-Z0-9#(),.\s%/-]+$/;
445
503
  if (preset.bgColor && BG_COLOR_SAFE.test(preset.bgColor)) pageBodyStyleParts.push(`background-color:${preset.bgColor}`);
@@ -469,11 +527,14 @@ export async function renderPage(page, opts = {}) {
469
527
  ? `window.__CMS_DCONFIG__ = ${dconfigJson};`
470
528
  : '';
471
529
 
472
- const breadcrumbsHtml = buildBreadcrumbsHtml(page, site);
530
+ const breadcrumbsHtml = embed ? '' : buildBreadcrumbsHtml(page, site);
473
531
 
474
532
  const themeView = await buildThemeView(page);
475
- const searchAssets = buildSearchAssets();
533
+ const searchAssets = embed ? {headTag: '', bodyTag: ''} : buildSearchAssets();
534
+ // Inside a launcher's panel the page's own Reduce motion control is the page around it.
476
535
  const motionAssets = buildMotionAssets(site);
536
+ if (embed) Object.assign(motionAssets, embedMotionAssets(site));
537
+ const launcherAssets = embed ? {headTag: '', bodyTag: ''} : buildLauncherAssets(page.urlPath || '/', opts.user || null);
477
538
  const footerBlocksHtml = preset.footer !== false ? await buildFooterBlocks(site, {user: opts.user || null, urlPath: menuCtx.urlPath, project: menuCtx.project, tags: opts.cacheTags}) : '';
478
539
  const switcherAssets = buildThemeSwitcherAssets(themeView.cfg, {
479
540
  html: `${page.html || ''}${overlayMenus}${footerBlocksHtml}`,
@@ -517,7 +578,7 @@ export async function renderPage(page, opts = {}) {
517
578
  // page view on every re-render - recorded under the srcdoc document's path,
518
579
  // which is not a page at all - and draft or share-link previews inflate the
519
580
  // counts for something nobody has published.
520
- const noTrack = !!opts.preview || opts.noTrack === true;
581
+ const noTrack = !!opts.preview || opts.noTrack === true || embed;
521
582
 
522
583
  /*
523
584
  * Authored context menus. Resolved server-side so a visitor only receives
@@ -575,6 +636,7 @@ export async function renderPage(page, opts = {}) {
575
636
  footerScript: footerJson ? `window.__CMS_FOOTER__ = ${footerJson};` : '',
576
637
  ctxMenusScript: ctxMenusScript,
577
638
  ctxMenusModule: ctxMenusModule,
639
+ imageZoomModule: imageZoomModule(page.html, overlayMenus, footerBlocksHtml),
578
640
  // Every `<` escaped, not only `</script>`: a label holding `<!--<script` would
579
641
  // otherwise put the parser in script-data-escaped state and swallow the page.
580
642
  siteJson: JSON.stringify(Object.assign(
@@ -589,9 +651,9 @@ export async function renderPage(page, opts = {}) {
589
651
  : site.footer,
590
652
  social: site.social || null
591
653
  },
592
- site.backToTop?.enabled ? { backToTop: site.backToTop } : {},
593
- site.goToBottom?.enabled ? { goToBottom: site.goToBottom } : {},
594
- consentAssets.siteFields,
654
+ site.backToTop?.enabled && !embed ? { backToTop: site.backToTop } : {},
655
+ site.goToBottom?.enabled && !embed ? { goToBottom: site.goToBottom } : {},
656
+ embed ? {} : consentAssets.siteFields,
595
657
  motionAssets.siteFields,
596
658
  autoTheme ? {autoTheme} : {}
597
659
  )).replace(/</g, '\\u003c'),
@@ -599,7 +661,8 @@ export async function renderPage(page, opts = {}) {
599
661
  // Theme overrides land BEFORE content/custom.css: the overrides are
600
662
  // generated, custom.css is hand-written, and the hand-written one stays
601
663
  // the last word.
602
- headInjectLate: [injection.headLate, searchAssets.headTag, motionAssets.headTag, switcherAssets.headTag, themeView.customThemeStyleTag, themeView.overrideStyleTag, customCssTag, navbarStyleTag]
664
+ headInjectLate: [injection.headLate, searchAssets.headTag, motionAssets.headTag, embed ? '' : switcherAssets.headTag,
665
+ launcherAssets.headTag, embed ? EMBED_HEAD_TAG : '', themeView.customThemeStyleTag, themeView.overrideStyleTag, customCssTag, navbarStyleTag]
603
666
  .filter(Boolean).join('\n'),
604
667
  bodyEndInject: [
605
668
  // Draft banner - first, so it is the topmost fixed element and a
@@ -609,13 +672,15 @@ export async function renderPage(page, opts = {}) {
609
672
  // Overlay menus - bound to the `overlay` slot and pinned by their own
610
673
  // float config, so they belong at the end of the body, clear of the
611
674
  // content flow.
612
- overlayMenus,
613
- injection.bodyEnd,
675
+ embed ? '' : overlayMenus,
676
+ embed ? '' : injection.bodyEnd,
614
677
  searchAssets.bodyTag,
615
- switcherAssets.bodyTag,
616
- buildAnalyticsTag(),
617
- (site.backToTop?.enabled || site.goToBottom?.enabled) ? '<script src="/public/js/btt.js?v=20261022-page-navigation" defer></script>' : '',
618
- consentAssets.bodyTag,
678
+ embed ? '' : switcherAssets.bodyTag,
679
+ embed ? '' : buildAnalyticsTag(),
680
+ (!embed && (site.backToTop?.enabled || site.goToBottom?.enabled)) ? '<script src="/public/js/btt.js?v=20261022-page-navigation" defer></script>' : '',
681
+ embed ? '' : consentAssets.bodyTag,
682
+ launcherAssets.bodyTag,
683
+ embed ? EMBED_BODY_TAG : '',
619
684
  (page.usedComponents || [])
620
685
  .map(n => `<script type="module" src="/api/components/${n}.js"></script>`)
621
686
  .join('\n')
@@ -1272,6 +1337,7 @@ export async function renderBlogPage(templatePath, data = {}, seoMeta = {}) {
1272
1337
  const themeView = await buildThemeView({});
1273
1338
  const searchAssets = buildSearchAssets();
1274
1339
  const motionAssets = buildMotionAssets(site);
1340
+ const launcherAssets = buildLauncherAssets(seoMeta.urlPath || '/', user);
1275
1341
  const footerBlocksHtml = await buildFooterBlocks(site, {user, urlPath: seoMeta.urlPath || '/', project: menuCtx.project ?? null});
1276
1342
  const switcherAssets = buildThemeSwitcherAssets(themeView.cfg, {
1277
1343
  html: `${renderedFragment || ''}${overlayMenus}${footerBlocksHtml}`,
@@ -1360,6 +1426,7 @@ export async function renderBlogPage(templatePath, data = {}, seoMeta = {}) {
1360
1426
  footerScript: footerJson ? `window.__CMS_FOOTER__ = ${footerJson};` : '',
1361
1427
  ctxMenusScript: ctxMenusScript,
1362
1428
  ctxMenusModule: ctxMenusModule,
1429
+ imageZoomModule: imageZoomModule(renderedFragment, overlayMenus, footerBlocksHtml),
1363
1430
  // Every `<` escaped, as on the page path above.
1364
1431
  siteJson: JSON.stringify({
1365
1432
  title: site.title,
@@ -1378,7 +1445,7 @@ export async function renderBlogPage(templatePath, data = {}, seoMeta = {}) {
1378
1445
  // Theme overrides land BEFORE content/custom.css: the overrides are
1379
1446
  // generated, custom.css is hand-written, and the hand-written one stays
1380
1447
  // the last word.
1381
- headInjectLate: [bare ? '' : injection.headLate, searchAssets.headTag, motionAssets.headTag, switcherAssets.headTag, themeView.customThemeStyleTag, themeView.overrideStyleTag, customCssTag, navbarStyleTag]
1448
+ headInjectLate: [bare ? '' : injection.headLate, searchAssets.headTag, motionAssets.headTag, switcherAssets.headTag, launcherAssets.headTag, themeView.customThemeStyleTag, themeView.overrideStyleTag, customCssTag, navbarStyleTag]
1382
1449
  .filter(Boolean).join('\n'),
1383
1450
  bodyEndInject: [
1384
1451
  overlayMenus,
@@ -1387,6 +1454,7 @@ export async function renderBlogPage(templatePath, data = {}, seoMeta = {}) {
1387
1454
  switcherAssets.bodyTag,
1388
1455
  bare ? '' : buildAnalyticsTag(),
1389
1456
  bare ? '' : consentAssets.bodyTag,
1457
+ launcherAssets.bodyTag,
1390
1458
  (seoMeta.usedComponents || [])
1391
1459
  .map(n => `<script type="module" src="/api/components/${n}.js"></script>`)
1392
1460
  .join('\n')
@@ -477,7 +477,7 @@ export async function grantPermissionOnce(roleName, permission, source) {
477
477
  * a later removal in System > Roles sticks. `contacts.manageGroups` is granted
478
478
  * the same way, separately (server.js).
479
479
  */
480
- export const ADMIN_TOOL_GRANTS = ['notes', 'todo', 'contacts', 'analytics', 'seo', 'calculator', 'import.wordpress'];
480
+ export const ADMIN_TOOL_GRANTS = ['notes', 'todo', 'contacts', 'analytics', 'seo', 'calculator', 'import.wordpress', 'chats'];
481
481
 
482
482
  /**
483
483
  * Grant the seeded `admin` role the built-in Tool permissions - once each.
@@ -63,6 +63,7 @@ export const CORE_TOOLS = Object.freeze([
63
63
  {name: 'todo', displayName: 'Todo', icon: 'check-square', description: 'To-do lists with due dates and reminders.'},
64
64
  {name: 'calculator', displayName: 'Calculator', icon: 'calculator', description: 'Basic and scientific calculations, on a page or in a floating panel.'},
65
65
  {name: 'analytics', displayName: 'Analytics', icon: 'chart-bar', description: 'Page views and visitors, counted on this server.'},
66
+ {name: 'launchers', displayName: 'Launchers', icon: 'message-circle', description: 'Discs pinned to the page that open a page, a form or a chat - in a modal or a slideover.'},
66
67
  {name: 'seo', displayName: 'SEO', icon: 'search', description: 'How the site looks to search engines: an audit of every page, redirects, the sitemap and robots.txt.'},
67
68
  {name: 'wordpress-import', displayName: 'Import from WordPress', icon: 'download', description: 'Bring a WordPress site across: pages, posts, media, menus, comments, WooCommerce products and redirects from the old addresses.'}
68
69
  ]);
@@ -25,7 +25,7 @@
25
25
  <link rel="stylesheet" href="/dist/domma/themes/domma-themes.css">
26
26
 
27
27
  <!-- Site CSS -->
28
- <link rel="stylesheet" href="/public/css/site.css?v=20261030-card-image">
28
+ <link rel="stylesheet" href="/public/css/site.css?v=20261031-image-shortcode">
29
29
  <link rel="stylesheet" href="/public/css/forms.css?v=20261031-forms-reduce-motion">
30
30
  <!-- Menu item hover / current-page effects. Loaded after site.css so a
31
31
  menu's own highlight wins over the blanket link styling there. -->
@@ -188,9 +188,11 @@
188
188
  <script src="/public/js/form-logic-engine.js?v=20261031-forms-reduce-motion" defer></script>
189
189
 
190
190
  <!-- Site initialisation -->
191
- <script src="/public/js/site.js?v=20261031-form-entrance" type="module"></script>
191
+ <script src="/public/js/site.js?v=20261031-launchers-goto" type="module"></script>
192
192
  <script src="/public/js/collection-context.js?v=20261010-utf8-payloads" type="module"></script>
193
193
  {{ctxMenusModule}}
194
+ <!-- [image zoom] pictures' full-size view - only on a page that has one -->
195
+ {{imageZoomModule}}
194
196
 
195
197
  <!-- Floating menu panels: collapse to a hamburger, drag to move, resize.
196
198
  Loaded here rather than from site.js so server-rendered overlays and