domma-cms 1.59.0 → 1.60.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/admin/js/app.js CHANGED
@@ -1,4 +1,4 @@
1
- import{wireNotificationMenu as it}from"./lib/topbar-notifications.js";import{installSmoothCarets as ot}from"./lib/smooth-caret.js";import{viewLoaders as st}from"./views/index.js";import{createLazyViews as nt}from"./lib/lazy-views.js";import{withPluginChrome as q}from"./lib/plugin-chrome.js";import{api as r,getUser as V,isAuthenticated as p,logout as rt,sendToLogin as lt}from"./api.js";import{claimDrafts as ct}from"./lib/draft-owner.js";import{isAuthScreen as y,loginHashFor as mt}from"./lib/login-arrange.js";import{installHttpInterceptor as pt}from"./http-interceptor.js";import{installResizableSlideovers as dt}from"./lib/slideover-resizable.js";import{installActivityThrobber as ut}from"./lib/activity-throbber.js";import{installUpdateNotice as ht,renderCmsVersion as wt}from"./lib/update-notice.js";import{renderFrameworkVersions as z,wireAccountMenu as gt}from"./lib/topbar-account.js";import{refreshTopbarProject as _}from"./lib/topbar-project.js";import{CONFINED_CLASS as ft,isConfined as vt,isPathAllowed as bt,redirectFor as Ct}from"./lib/admin-scope.js";import{deliverDesktop as St,desktopActive as G,notificationSettings as J}from"./lib/desktop-notify.js";import{deliverChatToasts as Mt}from"./lib/chat-toast.js";import{avatarUrl as Dt,installAccountAvatar as yt}from"./lib/avatar.js";import{installCalculator as Et}from"./lib/calculator.js";import{installAdminAssistant as Nt}from"./lib/admin-assistant.js";import{installAdminLaunchers as Pt}from"./lib/admin-launchers.js";import{takeOverviewPass as At,withDashboardStrip as Y}from"./lib/dashboards-strip.js";import{installHotkeys as jt}from"./lib/hotkeys-ui.js";import{applyAdminBrand as Q}from"./lib/admin-brand.js";import{installRouterCatchUp as kt}from"./lib/router-catch-up.js";import{installSidebarDrawer as Rt}from"./lib/sidebar-drawer.js";$(()=>{ot(document),pt(),Et(),Nt(),Pt(),ht(),ut(),dt(),Rt(),(async()=>{const{applyAdminTheme:t,refreshAdminTheme:i}=await import("./lib/admin-theme.js");p()?await i(r,{init:!0}):t({dommaTheme:"charcoal-dark"},{init:!0})})();let c=null,f=null,m="/",v=!1,w=null,d=null,u=!0;function N(t){if(j[t])return E.toast(`${j[t]} is switched off on this site.`,{type:"info"}),"/";const[i,e]=t.split("?"),a=new URLSearchParams(e||"").get("tab");if(i==="/settings"&&["favicon","pageNavigation","breadcrumbs","motion","search"].includes(a))return`/appearance?tab=${a}`;if(t.split("?")[0]==="/my-dashboard")return"/dashboards";const o=A[t]||Ct(c,t);return o||(!u&&i==="/system/notifications"?c?.home||"/":(t.split("?")[0]||"/")==="/"&&m&&m!=="/"&&!At()?A[m]||m:null)}function P(){document.body.classList.toggle(ft,vt(c))}const A={},j={};R.use(async(t,i,e)=>{if(y(t.path))return e();if(!p()){lt();return}const a=N(t.path);if(a){R.navigate(a);return}e()});async function b(){try{const t=await r.get("/auth/permissions");c=t.adminScope||null,P(),f=t.adminBrand||null,Q(f),m=t.adminHome||"/",z(t.versions||{});const i=t.permissions||[];return v=bt(c,"/settings")&&i.some(e=>e==="settings"||e.startsWith("settings.")),w=i.some(e=>e==="notifications"||e.startsWith("notifications.")),d=t.adminPortal||null,u=t.notificationsScreen!==!1,i}catch{return c=null,P(),m="/",f||Q(null),v=!1,w=null,d=null,u=!0,[]}}document.addEventListener("dm:admin-home-changed",()=>{b()});let k=null,I=!1;document.addEventListener("dm:sidebar-rebuild",()=>{if(_(r),k){I=!0;return}k=(async()=>{do{I=!1;try{await T(await b())}catch{}}while(I)})().finally(()=>{k=null})});async function T(t){const{applyAdminPortal:i}=await import("./lib/admin-portal.js");if(await i(d),d)return;const{renderAdminSidebar:e}=await import("./lib/sidebar-renderer.js");await e({mount:"#admin-sidebar",permissions:t,adminScope:c,brand:f,notificationsScreen:u})}M.subscribe("router:afterChange",({to:t})=>{y(t.path)&&(g&&(clearInterval(g),g=null),c=null,P(),m="/",v=!1,w=null,u=!0,d&&(d=null,import("./lib/admin-portal.js").then(i=>i.applyAdminPortal(null))))});const X=[{path:"/",view:"dashboard",title:"Dashboard - Domma CMS"},{path:"/dashboards",view:"dashboards",title:"Dashboards - Domma CMS"},{path:"/my-dashboard",view:"dashboards",title:"Dashboards - Domma CMS"},{path:"/pages",view:"pages",title:"Pages - Domma CMS"},{path:"/pages/new",view:"pageEditor",title:"New Page - Domma CMS"},{path:"/pages/edit/*",view:"pageEditor",title:"Edit Page - Domma CMS"},{path:"/media",view:"media",title:"Media - Domma CMS"},{path:"/menus",view:"menus",title:"Menus - Domma CMS"},{path:"/context-menus",view:"contextMenus",title:"Context Menus - Domma CMS"},{path:"/context-menus/new",view:"contextMenuEditor",title:"New Context Menu - Domma CMS"},{path:"/context-menus/edit/:slug",view:"contextMenuEditor",title:"Edit Context Menu - Domma CMS"},{path:"/launchers",view:"launchers",title:"Launchers - Domma CMS"},{path:"/menus/new",view:"menuEditor",title:"New Menu - Domma CMS"},{path:"/menus/edit/:slug",view:"menuEditor",title:"Edit Menu - Domma CMS"},{path:"/menu-locations",view:"menuLocations",title:"Menu Locations - Domma CMS"},{path:"/navigation",view:"menusRedirect",title:"Menus - Domma CMS"},{path:"/layouts",view:"layouts",title:"Layouts - Domma CMS"},{path:"/appearance",view:"appearance",title:"Appearance - Domma CMS"},{path:"/footer",view:"footer",title:"Footer - Domma CMS"},{path:"/settings",view:"settings",title:"Settings - Domma CMS"},{path:"/theme",view:"theme",title:"Theme - Domma CMS"},{path:"/users",view:"users",title:"Users - Domma CMS"},{path:"/users/new",view:"userEditor",title:"New User - Domma CMS"},{path:"/users/edit/:id",view:"userEditor",title:"Edit User - Domma CMS"},{path:"/plugins",view:"plugins",title:"Plugins - Domma CMS"},{path:"/plugins/code/:name",view:"pluginCode",title:"Plugin Code - Domma CMS"},{path:"/documentation",view:"documentation",title:"Usage - Domma CMS"},{path:"/tutorials",view:"tutorials",title:"Tutorials - Domma CMS"},{path:"/tutorials/crud",view:"tutorialCrud",title:"Building a CRUD App - Domma CMS"},{path:"/tutorials/editor",view:"tutorialEditor",title:"The Editor - Domma CMS"},{path:"/tutorials/plugin",view:"tutorialPlugin",title:"Writing a Tool - Domma CMS"},{path:"/tutorials/forms",view:"tutorialForms",title:"Form Follow-Up - Domma CMS"},{path:"/docs/components",view:"componentsReference",title:"Components Reference - Domma CMS"},{path:"/docs/components-howto",view:"componentsHowto",title:"Components How-To - Domma CMS"},{path:"/docs/components-walkthrough",view:"componentsWalkthrough",title:"Components Walkthrough - Domma CMS"},{path:"/docs/components-rules",view:"componentsRules",title:"Components Rules - Domma CMS"},{path:"/docs/usage/pages",view:"usagePages",title:"Pages - Usage - Domma CMS"},{path:"/docs/usage/media",view:"usageMedia",title:"Media - Usage - Domma CMS"},{path:"/docs/usage/navigation",view:"usageNavigation",title:"Navigation - Usage - Domma CMS"},{path:"/docs/usage/dconfig",view:"usageDconfig",title:"DConfig - Usage - Domma CMS"},{path:"/docs/usage/shortcodes",view:"usageShortcodes",title:"Shortcodes - Usage - Domma CMS"},{path:"/docs/usage/site-settings",view:"usageSiteSettings",title:"Site Settings - Usage - Domma CMS"},{path:"/docs/usage/plugins",view:"usagePlugins",title:"Plugins - Usage - Domma CMS"},{path:"/docs/usage/users-roles",view:"usageUsersRoles",title:"Users & Roles - Usage - Domma CMS"},{path:"/docs/usage/views",view:"usageViews",title:"Views - Usage - Domma CMS"},{path:"/docs/usage/actions",view:"usageActions",title:"Actions - Usage - Domma CMS"},{path:"/docs/usage/cta-shortcode",view:"usageCtaShortcode",title:"CTA Shortcode - Usage - Domma CMS"},{path:"/docs/usage/editions",view:"usageEditions",title:"Editions & Licences - Usage - Domma CMS"},{path:"/docs/usage/collections",view:"usageCollections",title:"Collections & Forms - Usage - Domma CMS"},{path:"/docs/usage/blocks",view:"usageBlocks",title:"Blocks - Usage - Domma CMS"},{path:"/docs/usage/tools",view:"usageTools",title:"Built-in Tools - Usage - Domma CMS"},{path:"/docs/usage/dashboard",view:"usageDashboard",title:"Dashboard - Usage - Domma CMS"},{path:"/docs/usage/search-engines",view:"usageSearchEngines",title:"Search Engines & AI - Usage - Domma CMS"},{path:"/docs/usage/launchers",view:"usageLaunchers",title:"Launchers - Usage - Domma CMS"},{path:"/docs/usage/chat",view:"usageChat",title:"Chat & Knowledge - Usage - Domma CMS"},{path:"/docs/plugins",view:"pluginGuides",title:"Plugin Guides - Domma CMS"},{path:"/docs/plugins/*",view:"pluginGuide",title:"Plugin Guide - Domma CMS"},{path:"/docs/api/authentication",view:"apiRefAuthentication",title:"Authentication - API - Domma CMS"},{path:"/docs/api/pages",view:"apiRefPages",title:"Pages - API - Domma CMS"},{path:"/docs/api/settings",view:"apiRefSettings",title:"Settings - API - Domma CMS"},{path:"/docs/api/layouts",view:"apiRefLayouts",title:"Layouts - API - Domma CMS"},{path:"/docs/api/navigation",view:"apiRefNavigation",title:"Navigation - API - Domma CMS"},{path:"/docs/api/media",view:"apiRefMedia",title:"Media - API - Domma CMS"},{path:"/docs/api/users",view:"apiRefUsers",title:"Users - API - Domma CMS"},{path:"/docs/api/plugins",view:"apiRefPlugins",title:"Plugins - API - Domma CMS"},{path:"/docs/api/collections",view:"apiRefCollections",title:"Collections - API - Domma CMS"},{path:"/docs/api/views",view:"apiRefViews",title:"Views API - Domma CMS"},{path:"/docs/api/actions",view:"apiRefActions",title:"Actions API - Domma CMS"},{path:"/docs/api/forms",view:"apiRefForms",title:"Forms API - Domma CMS"},{path:"/docs/api/scaffold",view:"apiRefScaffold",title:"Scaffold API - Domma CMS"},{path:"/docs/api/external",view:"apiRefExternal",title:"External API & Tokens - Domma CMS"},{path:"/docs/api/content",view:"apiRefContent",title:"Content API - Domma CMS"},{path:"/docs/api/builder",view:"apiRefBuilder",title:"API Builder - Domma CMS"},{path:"/api-reference",view:"apiReference",title:"API Reference - Domma CMS"},{path:"/collections",view:"collections",title:"Collections - Domma CMS"},{path:"/collections/new",view:"collectionEditor",title:"New Collection - Domma CMS"},{path:"/collections/edit/:slug",view:"collectionEditor",title:"Edit Collection - Domma CMS"},{path:"/collections/:slug/entries",view:"collectionEntries",title:"Entries - Domma CMS"},{path:"/forms",view:"forms",title:"Forms - Domma CMS"},{path:"/forms/new",view:"formEditor",title:"New Form - Domma CMS"},{path:"/forms/edit/:slug",view:"formEditor",title:"Edit Form - Domma CMS"},{path:"/forms/:slug/submissions",view:"formSubmissions",title:"Submissions - Domma CMS"},{path:"/views",view:"viewsList",title:"Views - Domma CMS"},{path:"/views/new",view:"viewEditor",title:"New View - Domma CMS"},{path:"/views/edit/:slug",view:"viewEditor",title:"Edit View - Domma CMS"},{path:"/views/:slug/preview",view:"viewPreview",title:"View Preview - Domma CMS"},{path:"/actions",view:"actionsList",title:"Actions - Domma CMS"},{path:"/actions/new",view:"actionEditor",title:"New Action - Domma CMS"},{path:"/actions/edit/:slug",view:"actionEditor",title:"Edit Action - Domma CMS"},{path:"/pro/docs",view:"proDocs",title:"Pro Documentation - Domma CMS"},{path:"/blocks",view:"blocks",title:"Blocks - Domma CMS"},{path:"/blocks/new",view:"pageEditor",title:"New Block - Domma CMS"},{path:"/blocks/edit/:name",view:"pageEditor",title:"Edit Block - Domma CMS"},{path:"/components",view:"components",title:"Components - Domma CMS"},{path:"/components/new",view:"pageEditor",title:"New Component - Domma CMS"},{path:"/components/edit/:name",view:"pageEditor",title:"Edit Component - Domma CMS"},{path:"/my-profile",view:"myProfile",title:"My Profile - Domma CMS"},{path:"/roles",view:"roles",title:"Roles & Permissions - Domma CMS"},{path:"/roles/edit/:id",view:"roleEditor",title:"Edit Role - Domma CMS"},{path:"/effects",view:"effects",title:"Effects - Domma CMS"},{path:"/search",view:"search",title:"Search - Domma CMS"},{path:"/content-api",view:"contentApi",title:"Content API - Domma CMS"},{path:"/launchers/chats",view:"chats",title:"Chats - Domma CMS"},{path:"/launchers/chats/:id",view:"chats",title:"Chats - Domma CMS"},{path:"/launchers/knowledge",view:"chatKnowledge",title:"Chat Knowledge - Domma CMS"},{path:"/notes",view:"notes",title:"Notes - Domma CMS"},{path:"/todo",view:"todo",title:"Todo - Domma CMS"},{path:"/calculator",view:"calculator",title:"Calculator - Domma CMS"},{path:"/analytics",view:"analytics",title:"Analytics - Domma CMS"},{path:"/seo",view:"seo",title:"SEO - Domma CMS"},{path:"/seo/:tab",view:"seo",title:"SEO - Domma CMS"},{path:"/wordpress-import",view:"wordpressImport",title:"Import a site - Domma CMS"},{path:"/contacts",view:"contacts",title:"Contacts - Domma CMS"},{path:"/calls/new",view:"callNew",title:"Call now - Domma CMS"},{path:"/system/notifications",view:"notifications",title:"Notifications - Domma CMS"},{path:"/api-tokens",view:"apiTokens",title:"API Tokens - Domma CMS"},{path:"/api-endpoints",view:"apiEndpoints",title:"API Builder - Domma CMS"},{path:"/api-endpoints/new",view:"apiEndpointEditor",title:"New API Endpoint - Domma CMS"},{path:"/api-endpoints/edit/:id",view:"apiEndpointEditor",title:"Edit API Endpoint - Domma CMS"},{path:"/projects",view:"projects",title:"Projects - Domma CMS"},{path:"/projects/new",view:"projects",title:"New Project - Domma CMS"},{path:"/projects/edit/:slug",view:"projects",title:"Edit Project - Domma CMS"},{path:"/projects/:slug/settings",view:"projectSettings",title:"Project settings - Domma CMS"},{path:"/projects/:slug/pages",view:"pages",title:"Project pages - Domma CMS"},{path:"/projects/:slug/collections",view:"collections",title:"Project collections - Domma CMS"},{path:"/projects/:slug/forms",view:"forms",title:"Project forms - Domma CMS"},{path:"/projects/:slug/actions",view:"actionsList",title:"Project actions - Domma CMS"},{path:"/projects/:slug/menus",view:"menus",title:"Project menus - Domma CMS"},{path:"/projects/:slug/blocks",view:"blocks",title:"Project blocks - Domma CMS"},{path:"/projects/:slug/components",view:"components",title:"Project components - Domma CMS"},{path:"/projects/:slug/views",view:"viewsList",title:"Project views - Domma CMS"},{path:"/projects/:slug/roles",view:"roles",title:"Project roles - Domma CMS"},{path:"/projects/:slug/users",view:"users",title:"Project users - Domma CMS"},{path:"/projects/:slug/apis",view:"apiEndpoints",title:"Project APIs - Domma CMS"},{path:"/projects/:slug",view:"projectDetail",title:"Project - Domma CMS"},{path:"/login",view:"login",title:"Sign in - Domma CMS",onEnter:()=>{$("#admin-sidebar").hide(),$("#admin-topbar").hide()}},{path:"/reset-password",view:"login",title:"Reset Password - Domma CMS",onEnter:()=>{$("#admin-sidebar").hide(),$("#admin-topbar").hide()}}];M.subscribe("router:afterChange",async({to:t,from:i})=>{if(!y(t.path)){if($("#admin-sidebar").show(),$("#admin-topbar").show(),y(i?.path)){$("#topbar-user-name").remove(),import("./lib/admin-theme.js").then(o=>o.refreshAdminTheme(r)),await x();const e=await b(),a=N(t.path);if(a&&R.navigate(a),T(e),J.read().signInToasts)try{const o=await r.system.notifications.list().catch(()=>[]),n=(Array.isArray(o)?o:[]).filter(s=>s.unread&&["warning","critical"].includes(s.data?.severity)).slice(0,3);for(const s of n){const l=h(s.data?.title||""),O=h((s.data?.body||"").slice(0,120));E.toast(`${l} - ${O}`,{type:s.data?.severity==="critical"?"error":"warning",duration:0})}}catch{}}K()}}),M.subscribe("router:afterChange",()=>{setTimeout(()=>{$(".btn-primary, .btn-danger").length&&Domma.effects.reveal(".btn-primary, .btn-danger",{animation:"fade",stagger:40,duration:300})},50)});const Z=["#field-project","#menu-project","#collection-project","#endpoint-project","#action-project","#view-project","#block-project","#component-project","#role-project",'[name="project"]','[name="ownedByProject"]'];function tt(t){return/^\/(pages|menus|context-menus|collections|forms|actions|views|blocks|components|users|roles|api-endpoints)\/(new|edit\/)/.test(t)}M.subscribe("router:afterChange",({to:t})=>{const i=t?String(t.path).split("?")[0]:"";if(!t||!tt(i))return;const a=new URLSearchParams(location.hash.split("?")[1]||"").get("project");if(!a||!/\/new$/.test(i))return;let o=0;const n=60,s=1500,l=()=>{o+=n;for(const O of Z){const D=document.querySelector(O);if(!D)continue;if(Array.from(D.options||[]).find(at=>at.value===a)){D.value=a,D.dispatchEvent(new Event("change",{bubbles:!0}));return}}o<s&&setTimeout(l,n)};setTimeout(l,n)});const W="cms_card_states",U=S.get(W)||{};M.subscribe("router:afterChange",()=>{setTimeout(()=>{$("#view-container .card-collapsible").each(function(){const t=$(this).find(".card-header h2, .card-header h3").first().text().trim();t&&U[t]==="collapsed"&&$(this).addClass("card-collapsed")})},200)}),$("#view-container").on("click",".card-collapsible .card-header",function(t){if($(t.target).closest("button, a").length)return;const i=$(this).closest(".card");i.toggleClass("card-collapsed");const e=$(this).find("h2, h3").first().text().trim();e&&(U[e]=i.hasClass("card-collapsed")?"collapsed":"open",S.set(W,U))}),jt(),document.addEventListener("keydown",t=>{if(!(t.ctrlKey||t.metaKey)||t.key!=="s"||window.location.hash.startsWith("#/login")||window.location.hash.startsWith("#/reset-password"))return;const i=document.querySelector("#view-container .view-header button.btn-primary");i&&(t.preventDefault(),i.click())});const C=nt(),H=C.views,et={notes:{displayName:"Notes",icon:"edit-3"},todo:{displayName:"Todo",icon:"check-square"},calculator:{displayName:"Calculator",icon:"calculator"},analytics:{displayName:"Analytics",icon:"chart-bar"},seo:{displayName:"SEO",icon:"search"},wordpressImport:{displayName:"Import a site",icon:"download"},contacts:{displayName:"Contacts",icon:"users"},projects:{displayName:"Projects",icon:"folder"},pages:{displayName:"Pages",icon:"file-text"},media:{displayName:"Media",icon:"image"},menus:{displayName:"Site menus",icon:"menu"},contextMenus:{displayName:"Context Menus",icon:"menu"},launchers:{displayName:"Launchers",icon:"rocket"},theme:{displayName:"Theme",icon:"droplet"},collections:{displayName:"Collections",icon:"database"},forms:{displayName:"Forms",icon:"layout"},viewsList:{displayName:"Views",icon:"eye"},actionsList:{displayName:"Actions",icon:"zap"},apiEndpoints:{displayName:"API Builder",icon:"code"},blocks:{displayName:"Blocks",icon:"box"},components:{displayName:"Components",icon:"component"},notifications:{displayName:"Notifications",icon:"bell"},roles:{displayName:"Roles",icon:"shield"},users:{displayName:"Users",icon:"users"},appearance:{displayName:"Appearance",icon:"layout"},footer:{displayName:"Footer",icon:"panel-bottom"},settings:{displayName:"Site Settings",icon:"settings"},effects:{displayName:"Effects",icon:"sparkles"},layouts:{displayName:"Layouts",icon:"layout"},plugins:{displayName:"Marketplace",icon:"store"},myProfile:{displayName:"My Profile",icon:"user"},apiTokens:{displayName:"API Tokens",icon:"key"},search:{displayName:"Search",icon:"search"},contentApi:{displayName:"Content API",icon:"file-text"},chats:{displayName:"Chats",icon:"message-circle"},dashboard:{displayName:"Dashboard",icon:"home"},dashboards:{displayName:"Dashboards",icon:"home"},pageEditor:{displayName:"Pages",section:"Edit",icon:"file-text"},menuEditor:{displayName:"Site menus",section:"Edit",icon:"menu"},menuLocations:{displayName:"Site menus",section:"Locations",icon:"map-pin"},contextMenuEditor:{displayName:"Context Menus",section:"Edit",icon:"menu"},collectionEditor:{displayName:"Collections",section:"Edit",icon:"database"},collectionEntries:{displayName:"Collections",section:"Entries",icon:"database"},formEditor:{displayName:"Forms",section:"Edit",icon:"layout"},formSubmissions:{displayName:"Forms",section:"Submissions",icon:"inbox"},viewEditor:{displayName:"Views",section:"Edit",icon:"eye"},viewPreview:{displayName:"Views",section:"Preview",icon:"eye"},actionEditor:{displayName:"Actions",section:"Edit",icon:"zap"},apiEndpointEditor:{displayName:"API Builder",section:"Edit",icon:"code"},roleEditor:{displayName:"Roles",section:"Edit",icon:"shield"},userEditor:{displayName:"Users",section:"Edit",icon:"users"},projectDetail:{displayName:"Projects",section:"Overview",icon:"folder"},projectSettings:{displayName:"Projects",section:"Settings",icon:"folder"},pluginCode:{displayName:"Marketplace",section:"Code",icon:"code"},chatKnowledge:{displayName:"Chats",section:"Knowledge",icon:"book-open"}};for(const[t,i]of Object.entries(st))C.register(t,async()=>{let e=await i();const a=et[t];return a&&(e=q(e,{plugin:t,licence:"Built in",...a})),t==="dashboard"?Y(e):e});R.use(async(t,i,e)=>{try{await C.load(t.view)}catch(a){console.error("[admin] Screen failed to load",a),H[t.view]={template:'<p role="alert">This screen could not load. Reload the page to try again.</p>'}}e()});const L=[...X];async function x(){if(p())try{const t=await r.plugins.adminConfig(),i=new Set(L.map(e=>e.path));for(const e of t.routes||[])i.has(e.path)||L.push(e);for(const[e,a]of Object.entries(t.views||{})){const o=(t.meta||{})[e];C.register(e,async()=>{const s=(await import(`/plugins/${a.entry}`))[a.exportName];if(!s)throw new Error(`Missing plugin screen: ${e}`);const l=q(s,o);return e==="dashboard"?Y(l):l},JSON.stringify([a,o]))}for(const[e,{route:a}]of Object.entries(t.takeovers||{}))a&&(A[`/${e}`]=a);t.mediaPicker&&(globalThis[Symbol.for("domma.media-picker")]=t.mediaPicker);for(const[e,{enabled:a,displayName:o}]of Object.entries(t.tools||{}))a===!1&&(j[`/${e}`]=o);for(const{id:e,href:a}of t.css||[])if(!document.getElementById(e)){const o=document.createElement("link");o.id=e,o.rel="stylesheet",o.href=a,document.head.appendChild(o)}}catch{}}function K(){const t=V();if(!t)return;if($("#topbar-user-name").length){_(r);return}const e={"super-admin":"Super Admin",admin:"Admin",user:"User"}[t.role]||t.role,a=Dt(t);$("#topbar-user").get(0).innerHTML=`
1
+ import{wireNotificationMenu as ct}from"./lib/topbar-notifications.js";import{installSmoothCarets as pt}from"./lib/smooth-caret.js";import{viewLoaders as mt}from"./views/index.js";import{createLazyViews as dt}from"./lib/lazy-views.js";import{withPluginChrome as J}from"./lib/plugin-chrome.js";import{api as r,getUser as W,isAuthenticated as m,logout as ut,sendToLogin as ht}from"./api.js";import{claimDrafts as wt}from"./lib/draft-owner.js";import{isAuthScreen as P,loginHashFor as gt}from"./lib/login-arrange.js";import{installHttpInterceptor as ft}from"./http-interceptor.js";import{installResizableSlideovers as vt}from"./lib/slideover-resizable.js";import{installActivityThrobber as bt}from"./lib/activity-throbber.js";import{installUpdateNotice as Ct,renderCmsVersion as St}from"./lib/update-notice.js";import{renderFrameworkVersions as Y,wireAccountMenu as Mt}from"./lib/topbar-account.js";import{refreshTopbarProject as H}from"./lib/topbar-project.js";import{CONFINED_CLASS as yt,isConfined as Dt,isPathAllowed as N,redirectFor as At}from"./lib/admin-scope.js";import{deliverDesktop as Et,desktopActive as Q,notificationSettings as X}from"./lib/desktop-notify.js";import{chatToastsOpen as Pt,closeChatToasts as Nt,deliverChatToasts as kt,settleChatToasts as jt}from"./lib/chat-toast.js";import{aiAssistReroute as Rt,launcherChatsFor as It}from"./lib/ai-assist.js";import{onPresence as Tt,setAvailable as Z,startPresence as Lt,stopPresence as tt}from"./lib/chat-presence.js";import{avatarUrl as Ut,installAccountAvatar as $t}from"./lib/avatar.js";import{installCalculator as xt}from"./lib/calculator.js";import{installAdminAssistant as Bt}from"./lib/admin-assistant.js";import{installAdminLaunchers as Ft}from"./lib/admin-launchers.js";import{takeOverviewPass as Ot,withDashboardStrip as et}from"./lib/dashboards-strip.js";import{installHotkeys as Vt}from"./lib/hotkeys-ui.js";import{applyAdminBrand as at}from"./lib/admin-brand.js";import{installRouterCatchUp as _t}from"./lib/router-catch-up.js";import{installSidebarDrawer as Kt}from"./lib/sidebar-drawer.js";$(()=>{pt(document),ft(),xt(),Bt(),Ft(),Ct(),bt(),vt(),Kt(),(async()=>{const{applyAdminTheme:t,refreshAdminTheme:o}=await import("./lib/admin-theme.js");m()?await o(r,{init:!0}):t({dommaTheme:"charcoal-dark"},{init:!0})})();let l=null,f=null,p="/",v=!1,w=null,d=null,u=!0,b=!1,C=null;function k(t){if(T[t])return E.toast(`${T[t]} is switched off on this site.`,{type:"info"}),"/";const[o,e]=t.split("?"),a=new URLSearchParams(e||"").get("tab");if(o==="/settings"&&["favicon","pageNavigation","breadcrumbs","motion","search"].includes(a))return`/appearance?tab=${a}`;if(t.split("?")[0]==="/my-dashboard")return"/dashboards";const i=Rt(t,C);if(i&&N(l,i.split("?")[0]))return i;const s=It(t);if(s&&!N(l,o)&&N(l,s.split("?")[0]))return s;const n=I[t]||At(l,t);return n||(!u&&o==="/system/notifications"?l?.home||"/":(t.split("?")[0]||"/")==="/"&&p&&p!=="/"&&!Ot()?I[p]||p:null)}function j(){document.body.classList.toggle(yt,Dt(l))}const I={},T={};R.use(async(t,o,e)=>{if(P(t.path))return e();if(!m()){ht();return}const a=k(t.path);if(a){R.navigate(a);return}e()});async function y(){try{const t=await r.get("/auth/permissions");l=t.adminScope||null,j(),f=t.adminBrand||null,at(f),p=t.adminHome||"/",Y(t.versions||{});const o=t.permissions||[];return v=N(l,"/settings")&&o.some(e=>e==="settings"||e.startsWith("settings.")),w=o.some(e=>e==="notifications"||e.startsWith("notifications.")),d=t.adminPortal||null,u=t.notificationsScreen!==!1,b=o.includes("chats")||o.includes("chats.reply"),o}catch{return l=null,j(),p="/",f||at(null),v=!1,w=null,d=null,u=!0,b=!1,[]}}document.addEventListener("dm:admin-home-changed",()=>{y()});let L=null,U=!1;document.addEventListener("dm:sidebar-rebuild",()=>{if(H(r),L){U=!0;return}L=(async()=>{do{U=!1;try{await x(await y())}catch{}}while(U)})().finally(()=>{L=null})});async function x(t){const{applyAdminPortal:o}=await import("./lib/admin-portal.js");if(await o(d),d)return;const{renderAdminSidebar:e}=await import("./lib/sidebar-renderer.js");await e({mount:"#admin-sidebar",permissions:t,adminScope:l,brand:f,notificationsScreen:u})}M.subscribe("router:afterChange",({to:t})=>{P(t.path)&&(g&&(clearInterval(g),g=null),l=null,j(),p="/",v=!1,w=null,u=!0,b=!1,d&&(d=null,import("./lib/admin-portal.js").then(o=>o.applyAdminPortal(null))))});const it=[{path:"/",view:"dashboard",title:"Dashboard - Domma CMS"},{path:"/dashboards",view:"dashboards",title:"Dashboards - Domma CMS"},{path:"/my-dashboard",view:"dashboards",title:"Dashboards - Domma CMS"},{path:"/pages",view:"pages",title:"Pages - Domma CMS"},{path:"/pages/new",view:"pageEditor",title:"New Page - Domma CMS"},{path:"/pages/edit/*",view:"pageEditor",title:"Edit Page - Domma CMS"},{path:"/media",view:"media",title:"Media - Domma CMS"},{path:"/menus",view:"menus",title:"Menus - Domma CMS"},{path:"/context-menus",view:"contextMenus",title:"Context Menus - Domma CMS"},{path:"/context-menus/new",view:"contextMenuEditor",title:"New Context Menu - Domma CMS"},{path:"/context-menus/edit/:slug",view:"contextMenuEditor",title:"Edit Context Menu - Domma CMS"},{path:"/launchers",view:"launchers",title:"Launchers - Domma CMS"},{path:"/menus/new",view:"menuEditor",title:"New Menu - Domma CMS"},{path:"/menus/edit/:slug",view:"menuEditor",title:"Edit Menu - Domma CMS"},{path:"/menu-locations",view:"menuLocations",title:"Menu Locations - Domma CMS"},{path:"/navigation",view:"menusRedirect",title:"Menus - Domma CMS"},{path:"/layouts",view:"layouts",title:"Layouts - Domma CMS"},{path:"/appearance",view:"appearance",title:"Appearance - Domma CMS"},{path:"/footer",view:"footer",title:"Footer - Domma CMS"},{path:"/settings",view:"settings",title:"Settings - Domma CMS"},{path:"/theme",view:"theme",title:"Theme - Domma CMS"},{path:"/users",view:"users",title:"Users - Domma CMS"},{path:"/users/new",view:"userEditor",title:"New User - Domma CMS"},{path:"/users/edit/:id",view:"userEditor",title:"Edit User - Domma CMS"},{path:"/plugins",view:"plugins",title:"Plugins - Domma CMS"},{path:"/plugins/code/:name",view:"pluginCode",title:"Plugin Code - Domma CMS"},{path:"/documentation",view:"documentation",title:"Usage - Domma CMS"},{path:"/tutorials",view:"tutorials",title:"Tutorials - Domma CMS"},{path:"/tutorials/crud",view:"tutorialCrud",title:"Building a CRUD App - Domma CMS"},{path:"/tutorials/editor",view:"tutorialEditor",title:"The Editor - Domma CMS"},{path:"/tutorials/plugin",view:"tutorialPlugin",title:"Writing a Tool - Domma CMS"},{path:"/tutorials/forms",view:"tutorialForms",title:"Form Follow-Up - Domma CMS"},{path:"/docs/components",view:"componentsReference",title:"Components Reference - Domma CMS"},{path:"/docs/components-howto",view:"componentsHowto",title:"Components How-To - Domma CMS"},{path:"/docs/components-walkthrough",view:"componentsWalkthrough",title:"Components Walkthrough - Domma CMS"},{path:"/docs/components-rules",view:"componentsRules",title:"Components Rules - Domma CMS"},{path:"/docs/usage/pages",view:"usagePages",title:"Pages - Usage - Domma CMS"},{path:"/docs/usage/media",view:"usageMedia",title:"Media - Usage - Domma CMS"},{path:"/docs/usage/navigation",view:"usageNavigation",title:"Navigation - Usage - Domma CMS"},{path:"/docs/usage/dconfig",view:"usageDconfig",title:"DConfig - Usage - Domma CMS"},{path:"/docs/usage/shortcodes",view:"usageShortcodes",title:"Shortcodes - Usage - Domma CMS"},{path:"/docs/usage/site-settings",view:"usageSiteSettings",title:"Site Settings - Usage - Domma CMS"},{path:"/docs/usage/plugins",view:"usagePlugins",title:"Plugins - Usage - Domma CMS"},{path:"/docs/usage/users-roles",view:"usageUsersRoles",title:"Users & Roles - Usage - Domma CMS"},{path:"/docs/usage/views",view:"usageViews",title:"Views - Usage - Domma CMS"},{path:"/docs/usage/actions",view:"usageActions",title:"Actions - Usage - Domma CMS"},{path:"/docs/usage/cta-shortcode",view:"usageCtaShortcode",title:"CTA Shortcode - Usage - Domma CMS"},{path:"/docs/usage/editions",view:"usageEditions",title:"Editions & Licences - Usage - Domma CMS"},{path:"/docs/usage/collections",view:"usageCollections",title:"Collections & Forms - Usage - Domma CMS"},{path:"/docs/usage/blocks",view:"usageBlocks",title:"Blocks - Usage - Domma CMS"},{path:"/docs/usage/tools",view:"usageTools",title:"Built-in Tools - Usage - Domma CMS"},{path:"/docs/usage/dashboard",view:"usageDashboard",title:"Dashboard - Usage - Domma CMS"},{path:"/docs/usage/search-engines",view:"usageSearchEngines",title:"Search Engines & AI - Usage - Domma CMS"},{path:"/docs/usage/launchers",view:"usageLaunchers",title:"Launchers - Usage - Domma CMS"},{path:"/docs/usage/chat",view:"usageChat",title:"Chat & Knowledge - Usage - Domma CMS"},{path:"/docs/plugins",view:"pluginGuides",title:"Plugin Guides - Domma CMS"},{path:"/docs/plugins/*",view:"pluginGuide",title:"Plugin Guide - Domma CMS"},{path:"/docs/api/authentication",view:"apiRefAuthentication",title:"Authentication - API - Domma CMS"},{path:"/docs/api/pages",view:"apiRefPages",title:"Pages - API - Domma CMS"},{path:"/docs/api/settings",view:"apiRefSettings",title:"Settings - API - Domma CMS"},{path:"/docs/api/layouts",view:"apiRefLayouts",title:"Layouts - API - Domma CMS"},{path:"/docs/api/navigation",view:"apiRefNavigation",title:"Navigation - API - Domma CMS"},{path:"/docs/api/media",view:"apiRefMedia",title:"Media - API - Domma CMS"},{path:"/docs/api/users",view:"apiRefUsers",title:"Users - API - Domma CMS"},{path:"/docs/api/plugins",view:"apiRefPlugins",title:"Plugins - API - Domma CMS"},{path:"/docs/api/collections",view:"apiRefCollections",title:"Collections - API - Domma CMS"},{path:"/docs/api/views",view:"apiRefViews",title:"Views API - Domma CMS"},{path:"/docs/api/actions",view:"apiRefActions",title:"Actions API - Domma CMS"},{path:"/docs/api/forms",view:"apiRefForms",title:"Forms API - Domma CMS"},{path:"/docs/api/scaffold",view:"apiRefScaffold",title:"Scaffold API - Domma CMS"},{path:"/docs/api/external",view:"apiRefExternal",title:"External API & Tokens - Domma CMS"},{path:"/docs/api/content",view:"apiRefContent",title:"Content API - Domma CMS"},{path:"/docs/api/builder",view:"apiRefBuilder",title:"API Builder - Domma CMS"},{path:"/api-reference",view:"apiReference",title:"API Reference - Domma CMS"},{path:"/collections",view:"collections",title:"Collections - Domma CMS"},{path:"/collections/new",view:"collectionEditor",title:"New Collection - Domma CMS"},{path:"/collections/edit/:slug",view:"collectionEditor",title:"Edit Collection - Domma CMS"},{path:"/collections/:slug/entries",view:"collectionEntries",title:"Entries - Domma CMS"},{path:"/forms",view:"forms",title:"Forms - Domma CMS"},{path:"/forms/new",view:"formEditor",title:"New Form - Domma CMS"},{path:"/forms/edit/:slug",view:"formEditor",title:"Edit Form - Domma CMS"},{path:"/forms/:slug/submissions",view:"formSubmissions",title:"Submissions - Domma CMS"},{path:"/views",view:"viewsList",title:"Views - Domma CMS"},{path:"/views/new",view:"viewEditor",title:"New View - Domma CMS"},{path:"/views/edit/:slug",view:"viewEditor",title:"Edit View - Domma CMS"},{path:"/views/:slug/preview",view:"viewPreview",title:"View Preview - Domma CMS"},{path:"/actions",view:"actionsList",title:"Actions - Domma CMS"},{path:"/actions/new",view:"actionEditor",title:"New Action - Domma CMS"},{path:"/actions/edit/:slug",view:"actionEditor",title:"Edit Action - Domma CMS"},{path:"/pro/docs",view:"proDocs",title:"Pro Documentation - Domma CMS"},{path:"/blocks",view:"blocks",title:"Blocks - Domma CMS"},{path:"/blocks/new",view:"pageEditor",title:"New Block - Domma CMS"},{path:"/blocks/edit/:name",view:"pageEditor",title:"Edit Block - Domma CMS"},{path:"/components",view:"components",title:"Components - Domma CMS"},{path:"/components/new",view:"pageEditor",title:"New Component - Domma CMS"},{path:"/components/edit/:name",view:"pageEditor",title:"Edit Component - Domma CMS"},{path:"/my-profile",view:"myProfile",title:"My Profile - Domma CMS"},{path:"/roles",view:"roles",title:"Roles & Permissions - Domma CMS"},{path:"/roles/edit/:id",view:"roleEditor",title:"Edit Role - Domma CMS"},{path:"/effects",view:"effects",title:"Effects - Domma CMS"},{path:"/search",view:"search",title:"Search - Domma CMS"},{path:"/content-api",view:"contentApi",title:"Content API - Domma CMS"},{path:"/launchers/chats",view:"chats",title:"Chats - Domma CMS"},{path:"/launchers/chats/:id",view:"chats",title:"Chats - Domma CMS"},{path:"/launchers/knowledge",view:"chatKnowledge",title:"Chat Knowledge - Domma CMS"},{path:"/ai-assist",view:"aiAssistChats",title:"AI Assist - Domma CMS"},{path:"/ai-assist/chats",view:"aiAssistChats",title:"AI Assist - Domma CMS"},{path:"/ai-assist/chats/:id",view:"aiAssistChats",title:"AI Assist - Domma CMS"},{path:"/ai-assist/knowledge",view:"aiAssistKnowledge",title:"AI Assist Knowledge - Domma CMS"},{path:"/ai-assist/settings",view:"aiAssistSettings",title:"AI Assist Settings - Domma CMS"},{path:"/notes",view:"notes",title:"Notes - Domma CMS"},{path:"/todo",view:"todo",title:"Todo - Domma CMS"},{path:"/calculator",view:"calculator",title:"Calculator - Domma CMS"},{path:"/analytics",view:"analytics",title:"Analytics - Domma CMS"},{path:"/seo",view:"seo",title:"SEO - Domma CMS"},{path:"/seo/:tab",view:"seo",title:"SEO - Domma CMS"},{path:"/wordpress-import",view:"wordpressImport",title:"Import a site - Domma CMS"},{path:"/contacts",view:"contacts",title:"Contacts - Domma CMS"},{path:"/calls/new",view:"callNew",title:"Call now - Domma CMS"},{path:"/system/notifications",view:"notifications",title:"Notifications - Domma CMS"},{path:"/api-tokens",view:"apiTokens",title:"API Tokens - Domma CMS"},{path:"/api-endpoints",view:"apiEndpoints",title:"API Builder - Domma CMS"},{path:"/api-endpoints/new",view:"apiEndpointEditor",title:"New API Endpoint - Domma CMS"},{path:"/api-endpoints/edit/:id",view:"apiEndpointEditor",title:"Edit API Endpoint - Domma CMS"},{path:"/projects",view:"projects",title:"Projects - Domma CMS"},{path:"/projects/new",view:"projects",title:"New Project - Domma CMS"},{path:"/projects/edit/:slug",view:"projects",title:"Edit Project - Domma CMS"},{path:"/projects/:slug/settings",view:"projectSettings",title:"Project settings - Domma CMS"},{path:"/projects/:slug/pages",view:"pages",title:"Project pages - Domma CMS"},{path:"/projects/:slug/collections",view:"collections",title:"Project collections - Domma CMS"},{path:"/projects/:slug/forms",view:"forms",title:"Project forms - Domma CMS"},{path:"/projects/:slug/actions",view:"actionsList",title:"Project actions - Domma CMS"},{path:"/projects/:slug/menus",view:"menus",title:"Project menus - Domma CMS"},{path:"/projects/:slug/blocks",view:"blocks",title:"Project blocks - Domma CMS"},{path:"/projects/:slug/components",view:"components",title:"Project components - Domma CMS"},{path:"/projects/:slug/views",view:"viewsList",title:"Project views - Domma CMS"},{path:"/projects/:slug/roles",view:"roles",title:"Project roles - Domma CMS"},{path:"/projects/:slug/users",view:"users",title:"Project users - Domma CMS"},{path:"/projects/:slug/apis",view:"apiEndpoints",title:"Project APIs - Domma CMS"},{path:"/projects/:slug",view:"projectDetail",title:"Project - Domma CMS"},{path:"/login",view:"login",title:"Sign in - Domma CMS",onEnter:()=>{$("#admin-sidebar").hide(),$("#admin-topbar").hide(),tt(),Nt()}},{path:"/reset-password",view:"login",title:"Reset Password - Domma CMS",onEnter:()=>{$("#admin-sidebar").hide(),$("#admin-topbar").hide()}}];M.subscribe("router:afterChange",async({to:t,from:o})=>{if(!P(t.path)){if($("#admin-sidebar").show(),$("#admin-topbar").show(),P(o?.path)){$("#topbar-user-name").remove(),import("./lib/admin-theme.js").then(i=>i.refreshAdminTheme(r)),await O();const e=await y(),a=k(t.path);if(a&&R.navigate(a),x(e),X.read().signInToasts)try{const i=await r.system.notifications.list().catch(()=>[]),s=(Array.isArray(i)?i:[]).filter(n=>n.unread&&["warning","critical"].includes(n.data?.severity)).slice(0,3);for(const n of s){const c=h(n.data?.title||""),K=h((n.data?.body||"").slice(0,120));E.toast(`${c} - ${K}`,{type:n.data?.severity==="critical"?"error":"warning",duration:0})}}catch{}}G()}}),M.subscribe("router:afterChange",()=>{setTimeout(()=>{$(".btn-primary, .btn-danger").length&&Domma.effects.reveal(".btn-primary, .btn-danger",{animation:"fade",stagger:40,duration:300})},50)});const ot=["#field-project","#menu-project","#collection-project","#endpoint-project","#action-project","#view-project","#block-project","#component-project","#role-project",'[name="project"]','[name="ownedByProject"]'];function st(t){return/^\/(pages|menus|context-menus|collections|forms|actions|views|blocks|components|users|roles|api-endpoints)\/(new|edit\/)/.test(t)}M.subscribe("router:afterChange",({to:t})=>{const o=t?String(t.path).split("?")[0]:"";if(!t||!st(o))return;const a=new URLSearchParams(location.hash.split("?")[1]||"").get("project");if(!a||!/\/new$/.test(o))return;let i=0;const s=60,n=1500,c=()=>{i+=s;for(const K of ot){const A=document.querySelector(K);if(!A)continue;if(Array.from(A.options||[]).find(lt=>lt.value===a)){A.value=a,A.dispatchEvent(new Event("change",{bubbles:!0}));return}}i<n&&setTimeout(c,s)};setTimeout(c,s)});const q="cms_card_states",B=S.get(q)||{};M.subscribe("router:afterChange",()=>{setTimeout(()=>{$("#view-container .card-collapsible").each(function(){const t=$(this).find(".card-header h2, .card-header h3").first().text().trim();t&&B[t]==="collapsed"&&$(this).addClass("card-collapsed")})},200)}),$("#view-container").on("click",".card-collapsible .card-header",function(t){if($(t.target).closest("button, a").length)return;const o=$(this).closest(".card");o.toggleClass("card-collapsed");const e=$(this).find("h2, h3").first().text().trim();e&&(B[e]=o.hasClass("card-collapsed")?"collapsed":"open",S.set(q,B))}),Vt(),document.addEventListener("keydown",t=>{if(!(t.ctrlKey||t.metaKey)||t.key!=="s"||window.location.hash.startsWith("#/login")||window.location.hash.startsWith("#/reset-password"))return;const o=document.querySelector("#view-container .view-header button.btn-primary");o&&(t.preventDefault(),o.click())});const D=dt(),z=D.views,nt={notes:{displayName:"Notes",icon:"edit-3"},todo:{displayName:"Todo",icon:"check-square"},calculator:{displayName:"Calculator",icon:"calculator"},analytics:{displayName:"Analytics",icon:"chart-bar"},seo:{displayName:"SEO",icon:"search"},wordpressImport:{displayName:"Import a site",icon:"download"},contacts:{displayName:"Contacts",icon:"users"},projects:{displayName:"Projects",icon:"folder"},pages:{displayName:"Pages",icon:"file-text"},media:{displayName:"Media",icon:"image"},menus:{displayName:"Site menus",icon:"menu"},contextMenus:{displayName:"Context Menus",icon:"menu"},launchers:{displayName:"Launchers",icon:"rocket"},theme:{displayName:"Theme",icon:"droplet"},collections:{displayName:"Collections",icon:"database"},forms:{displayName:"Forms",icon:"layout"},viewsList:{displayName:"Views",icon:"eye"},actionsList:{displayName:"Actions",icon:"zap"},apiEndpoints:{displayName:"API Builder",icon:"code"},blocks:{displayName:"Blocks",icon:"box"},components:{displayName:"Components",icon:"component"},notifications:{displayName:"Notifications",icon:"bell"},roles:{displayName:"Roles",icon:"shield"},users:{displayName:"Users",icon:"users"},appearance:{displayName:"Appearance",icon:"layout"},footer:{displayName:"Footer",icon:"panel-bottom"},settings:{displayName:"Site Settings",icon:"settings"},effects:{displayName:"Effects",icon:"sparkles"},layouts:{displayName:"Layouts",icon:"layout"},plugins:{displayName:"Marketplace",icon:"store"},myProfile:{displayName:"My Profile",icon:"user"},apiTokens:{displayName:"API Tokens",icon:"key"},search:{displayName:"Search",icon:"search"},contentApi:{displayName:"Content API",icon:"file-text"},chats:{displayName:"Chats",icon:"message-circle"},dashboard:{displayName:"Dashboard",icon:"home"},dashboards:{displayName:"Dashboards",icon:"home"},pageEditor:{displayName:"Pages",section:"Edit",icon:"file-text"},menuEditor:{displayName:"Site menus",section:"Edit",icon:"menu"},menuLocations:{displayName:"Site menus",section:"Locations",icon:"map-pin"},contextMenuEditor:{displayName:"Context Menus",section:"Edit",icon:"menu"},collectionEditor:{displayName:"Collections",section:"Edit",icon:"database"},collectionEntries:{displayName:"Collections",section:"Entries",icon:"database"},formEditor:{displayName:"Forms",section:"Edit",icon:"layout"},formSubmissions:{displayName:"Forms",section:"Submissions",icon:"inbox"},viewEditor:{displayName:"Views",section:"Edit",icon:"eye"},viewPreview:{displayName:"Views",section:"Preview",icon:"eye"},actionEditor:{displayName:"Actions",section:"Edit",icon:"zap"},apiEndpointEditor:{displayName:"API Builder",section:"Edit",icon:"code"},roleEditor:{displayName:"Roles",section:"Edit",icon:"shield"},userEditor:{displayName:"Users",section:"Edit",icon:"users"},projectDetail:{displayName:"Projects",section:"Overview",icon:"folder"},projectSettings:{displayName:"Projects",section:"Settings",icon:"folder"},pluginCode:{displayName:"Marketplace",section:"Code",icon:"code"},chatKnowledge:{displayName:"Chats",section:"Knowledge",icon:"book-open"},aiAssistChats:{displayName:"AI Assist",section:"Chats",icon:"sparkles",licence:"Pro"},aiAssistKnowledge:{displayName:"AI Assist",section:"Knowledge",icon:"sparkles",licence:"Pro"},aiAssistSettings:{displayName:"AI Assist",section:"Settings",icon:"sparkles",licence:"Pro"}};for(const[t,o]of Object.entries(mt))D.register(t,async()=>{let e=await o();const a=nt[t];return a&&(e=J(e,{plugin:t,licence:"Built in",...a})),t==="dashboard"?et(e):e});R.use(async(t,o,e)=>{try{await D.load(t.view)}catch(a){console.error("[admin] Screen failed to load",a),z[t.view]={template:'<p role="alert">This screen could not load. Reload the page to try again.</p>'}}e()});const F=[...it];async function O(){if(m()){C=await r.get("/ai-assist").catch(()=>C);try{const t=await r.plugins.adminConfig(),o=new Set(F.map(e=>e.path));for(const e of t.routes||[])o.has(e.path)||F.push(e);for(const[e,a]of Object.entries(t.views||{})){const i=(t.meta||{})[e];D.register(e,async()=>{const n=(await import(`/plugins/${a.entry}`))[a.exportName];if(!n)throw new Error(`Missing plugin screen: ${e}`);const c=J(n,i);return e==="dashboard"?et(c):c},JSON.stringify([a,i]))}for(const[e,{route:a}]of Object.entries(t.takeovers||{}))a&&(I[`/${e}`]=a);t.mediaPicker&&(globalThis[Symbol.for("domma.media-picker")]=t.mediaPicker);for(const[e,{enabled:a,displayName:i}]of Object.entries(t.tools||{}))a===!1&&(T[`/${e}`]=i);for(const{id:e,href:a}of t.css||[])if(!document.getElementById(e)){const i=document.createElement("link");i.id=e,i.rel="stylesheet",i.href=a,document.head.appendChild(i)}}catch{}}}function G(){const t=W();if(!t)return;if($("#topbar-user-name").length){H(r);return}const e={"super-admin":"Super Admin",admin:"Admin",user:"User"}[t.role]||t.role,a=Ut(t);$("#topbar-user").get(0).innerHTML=`
2
2
  <a id="topbar-project" class="topbar-action-link topbar-project" hidden>
3
3
  <span data-icon="folder"></span>
4
4
  <span id="topbar-project-name" class="topbar-project-name"></span>
@@ -27,6 +27,10 @@ import{wireNotificationMenu as it}from"./lib/topbar-notifications.js";import{ins
27
27
  <label class="topbar-sidebar-choice"><input type="checkbox" id="topbar-show-sidebar"> Show side admin menu</label>
28
28
  </div>
29
29
  </div>
30
+ <button type="button" id="topbar-presence" class="topbar-action-link topbar-presence" aria-pressed="false" hidden
31
+ data-tooltip="Available for chats: visitors who ask for a person are put through to you" data-tooltip-placement="bottom">
32
+ <span class="topbar-presence-dot" aria-hidden="true"></span><span class="topbar-action-label topbar-presence-label">Away</span>
33
+ </button>
30
34
  <div id="topbar-account" class="topbar-account">
31
35
  <button type="button" class="topbar-action-link" aria-label="Account menu" aria-expanded="false" aria-controls="topbar-account-menu">
32
36
  <span id="topbar-account-avatar" class="topbar-account-avatar" aria-hidden="true"></span><span class="topbar-action-label">Account</span><span data-icon="chevron-down"></span>
@@ -37,6 +41,7 @@ import{wireNotificationMenu as it}from"./lib/topbar-notifications.js";import{ins
37
41
  <span id="topbar-user-name" class="topbar-user-name">${h(t.name)}</span>
38
42
  <span class="topbar-role-badge topbar-role-badge--${h(t.role)}">${h(e)}</span>
39
43
  </div>
44
+ <label class="topbar-sidebar-choice topbar-available-choice" hidden><input type="checkbox" id="topbar-available" class="form-switch"> Available for chats</label>
40
45
  <a href="#/my-profile" class="topbar-action-link" data-tooltip="My Profile" data-tooltip-placement="bottom">
41
46
  <span data-icon="user"></span>
42
47
  <span>My Profile</span>
@@ -51,4 +56,4 @@ import{wireNotificationMenu as it}from"./lib/topbar-notifications.js";import{ins
51
56
  </a>
52
57
  </div>
53
58
  </div>
54
- `;const o=$("#topbar-settings").get(0);o&&(o.hidden=!v),$("#topbar-logout-btn").on("click",n=>{n.preventDefault(),rt()}),Domma.icons.scan("#admin-topbar"),E.tooltip("#topbar-actions [data-tooltip]",{placement:"bottom"}),gt(t),it({refreshBadge:F,canRead:()=>w!==!1,own:()=>!u}),yt(t),z(),wt(),_(r),F(),g||(g=setInterval(F,3e4))}function h(t){return String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}let g=null,B=null;async function F(){if(!(!p()||w===!1))try{const{count:t}=await r.system.notifications.unreadCount(),i=$("#topbar-bell-badge");t>0?i.text(t>99?"99+":String(t)).removeAttr("hidden"):i.attr("hidden","").text("");const e=J.read().chatToasts&&t>0&&(B===null||t>B);if(B=t,t>0&&(G()||e)){const a=await r.system.notifications.list().catch(()=>[]);G()&&St(a),e&&Mt(a)}}catch{}}(async()=>{if(!p()&&!window.location.hash.startsWith("#/reset-password"))window.location.hash.startsWith("#/login")||(window.location.hash=mt(window.location.hash));else{ct(V()?.id);const a=V(),[o]=await Promise.all([a?b():Promise.resolve([]),x()]);if(a){const n=(window.location.hash||"#/").slice(1)||"/",s=N(n);s&&(window.location.hash=`#${s}`),T(o).catch(l=>console.error("[admin] Sidebar failed to load",l)),K()}}const t=R._extractParams.bind(R);R._extractParams=function(a,o){const n=o.indexOf("?");if(n!==-1&&(o=o.slice(0,n)),a.endsWith("/*")){const s=a.slice(0,-2);return o.startsWith(s+"/")?{}:null}return t(a,o)};const i=R._renderNotFound.bind(R);let e="";R._renderNotFound=async function(a){return p()&&e!==a&&(e=a,await x(),R._matchRoute(a).route)?(e="",R._handleRouteChange()):(e="",p()&&$("#admin-sidebar").get(0)?.style.display==="none"?(E.toast("That link goes nowhere - here is your home page.",{type:"warning"}),R.navigate("/")):i(a))},kt(R),R.init({container:"#view-container",routes:L,views:H,default:"/",transitions:{enter:"fadeIn",leave:"fadeOut",duration:150}})})()});
59
+ `;const i=$("#topbar-settings").get(0);i&&(i.hidden=!v),$("#topbar-logout-btn").on("click",s=>{s.preventDefault(),tt({leaving:!0}),ut()}),Domma.icons.scan("#admin-topbar"),E.tooltip("#topbar-actions [data-tooltip]",{placement:"bottom"}),Mt(t),ct({refreshBadge:_,canRead:()=>w!==!1,own:()=>!u}),$t(t),rt(t),Y(),St(),H(r),_(),g||(g=setInterval(_,3e4))}function rt(t){const o=b&&C?.chats!==!1;Lt({userId:t.id,canReply:o,post:i=>r.post("/chats/presence",i)});const e=document.getElementById("topbar-presence"),a=document.getElementById("topbar-available");!e||!a||e.dataset.wired||(e.dataset.wired="1",e.addEventListener("click",()=>Z(e.getAttribute("aria-pressed")!=="true")),a.addEventListener("change",()=>Z(a.checked)),Tt(({available:i,canReply:s})=>{e.hidden=!s,a.closest("label").hidden=!s,e.setAttribute("aria-pressed",String(i)),e.classList.toggle("is-available",i),e.setAttribute("aria-label",i?"Available for chats - switch to away":"Away from chats - switch to available"),e.querySelector(".topbar-presence-label").textContent=i?"Available":"Away",a.checked=i}))}function h(t){return String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}let g=null,V=null;async function _(){if(!(!m()||w===!1))try{const{count:t}=await r.system.notifications.unreadCount(),o=$("#topbar-bell-badge");t>0?o.text(t>99?"99+":String(t)).removeAttr("hidden"):o.attr("hidden","").text("");const e=X.read().chatToasts&&t>0&&(V===null||t>V);V=t;const a=Pt();if(t>0&&(Q()||e)||a){const i=await r.system.notifications.list().catch(()=>null);if(!i)return;t>0&&Q()&&Et(i),e&&kt(i),a&&jt(i)}}catch{}}(async()=>{if(!m()&&!window.location.hash.startsWith("#/reset-password"))window.location.hash.startsWith("#/login")||(window.location.hash=gt(window.location.hash));else{wt(W()?.id);const a=W(),[i]=await Promise.all([a?y():Promise.resolve([]),O()]);if(a){const s=(window.location.hash||"#/").slice(1)||"/",n=k(s);n&&(window.location.hash=`#${n}`),x(i).catch(c=>console.error("[admin] Sidebar failed to load",c)),G()}}const t=R._extractParams.bind(R);R._extractParams=function(a,i){const s=i.indexOf("?");if(s!==-1&&(i=i.slice(0,s)),a.endsWith("/*")){const n=a.slice(0,-2);return i.startsWith(n+"/")?{}:null}return t(a,i)};const o=R._renderNotFound.bind(R);let e="";R._renderNotFound=async function(a){return m()&&e!==a&&(e=a,await O(),R._matchRoute(a).route)?(e="",R._handleRouteChange()):(e="",m()&&$("#admin-sidebar").get(0)?.style.display==="none"?(E.toast("That link goes nowhere - here is your home page.",{type:"warning"}),R.navigate("/")):o(a))},_t(R),R.init({container:"#view-container",routes:F,views:z,default:"/",transitions:{enter:"fadeIn",leave:"fadeOut",duration:150}})})()});
@@ -0,0 +1 @@
1
+ export const LIMITS=Object.freeze({context:4e3,rules:2e3,name:40,adminContext:4e3,adminRules:2e3});const a=(e,t="")=>typeof e=="string"?e:t;export function formFromSettings(e={}){const t=e.assistant||{},n=e.adminAssistant||{};return{aiContext:a(t.context),aiRules:a(t.rules),adminEnabled:n.enabled===!0,adminName:a(n.name,"Della")||"Della",adminCharacter:a(n.character,"della"),adminContext:a(n.context),adminRules:a(n.rules)}}export function payloadFromForm(e){const t=n=>a(n).trim();return{assistant:{context:t(e.aiContext),rules:t(e.aiRules)},adminAssistant:{enabled:e.adminEnabled===!0,name:t(e.adminName)||"Della",character:t(e.adminCharacter),context:t(e.adminContext),rules:t(e.adminRules)}}}export function snapshot(e){return JSON.stringify(payloadFromForm(e))}export function checkForm(e){const t=payloadFromForm(e);return t.assistant.context.length>LIMITS.context?`About the business is limited to ${LIMITS.context} characters.`:t.assistant.rules.length>LIMITS.rules?`Rules are limited to ${LIMITS.rules} characters.`:t.adminAssistant.name.length>LIMITS.name?`The assistant's name is limited to ${LIMITS.name} characters.`:t.adminAssistant.context.length>LIMITS.adminContext?`Admin assistant context is limited to ${LIMITS.adminContext} characters.`:t.adminAssistant.rules.length>LIMITS.adminRules?`Admin assistant rules are limited to ${LIMITS.adminRules} characters.`:""}export function characterOptions(e={}){return[{value:"",label:"No character"},...Object.values(e).map(t=>({value:t.id,label:t.name}))]}
@@ -0,0 +1 @@
1
+ export const AI_ASSIST_BASE="/ai-assist",LAUNCHER_BASE="/launchers",AI_ASSIST_TABS=Object.freeze([{key:"chats",label:"Chats",icon:"message-circle",chats:!0},{key:"knowledge",label:"Knowledge",icon:"book-open",chats:!0},{key:"settings",label:"Settings",icon:"settings",chats:!1}]);export function aiAssistReroute(e,t){if(!t||typeof e!="string")return null;const[n,o]=e.split("?"),a=o?`?${o}`:"",s=t.chats!==!1,r=n.match(/^\/(launchers|ai-assist)(?:\/(chats|knowledge|settings))?(\/[^/]+)?\/?$/);if(!r)return null;const[,c,i,l=""]=r;return c==="launchers"?!i||i==="settings"?null:t.on?`${AI_ASSIST_BASE}/${i}${l}${a}`:null:t.on?i?!s&&i!=="settings"?`${AI_ASSIST_BASE}/settings`:null:`${AI_ASSIST_BASE}/${s?"chats":"settings"}`:s&&(i==="chats"||i==="knowledge")?`${LAUNCHER_BASE}/${i}${l}${a}`:s?`${LAUNCHER_BASE}/chats`:"/"}export function launcherChatsFor(e){const t=String(e||"").match(/^\/ai-assist\/(chats|knowledge)(\/[^/?]+)?\/?(\?.*)?$/);return t?`${LAUNCHER_BASE}/${t[1]}${t[2]||""}${t[3]||""}`:null}export function chatsBaseFor(e){return/^#\/ai-assist\b/.test(String(e||""))?`#${AI_ASSIST_BASE}`:`#${LAUNCHER_BASE}`}export function aiAssistTabs(e,{chats:t=!0}={}){return AI_ASSIST_TABS.filter(n=>t||!n.chats).map(n=>({...n,href:`#${AI_ASSIST_BASE}/${n.key}`,active:n.key===e}))}export function mountAiAssistTabs(e,t,n={}){if(!e||chatsBaseFor(location.hash)!==`#${AI_ASSIST_BASE}`)return null;const o=e.querySelector(".dm-plugin-body")||e;o.querySelector(":scope > .ai-assist-tabs")?.remove();const a=document.createElement("nav");a.className="ai-assist-tabs",a.setAttribute("aria-label","AI Assist");for(const s of aiAssistTabs(t,n)){const r=document.createElement("a");r.className=`ai-assist-tab${s.active?" is-active":""}`,r.href=s.href,s.active&&r.setAttribute("aria-current","page");const c=document.createElement("span");c.dataset.icon=s.icon,c.dataset.iconSize="14",c.setAttribute("aria-hidden","true"),r.append(c,document.createTextNode(` ${s.label}`)),a.append(r)}return o.prepend(a),globalThis.I?.scan?.(a),a}
@@ -0,0 +1 @@
1
+ export const CHECK_IN_MS=3e4,presenceKey=a=>`chats.available.${a||"anonymous"}`;let e={userId:null,canReply:!1,available:!1,post:null,timer:0};const l=new Set;function c(a){try{return S.get(presenceKey(a))===!0}catch{return!1}}function u(a,t){try{S.set(presenceKey(a),t===!0)}catch{}}function i(){if(!e.canReply)return;const a=c(e.userId);a!==e.available&&(e.available=a,n())}async function r(){if(!(!e.canReply||!e.post)){i();try{await e.post({available:e.available})}catch{}}}function o(){i()}export function startPresence({userId:a,canReply:t,post:s}){if(stopPresence(),e={userId:a,canReply:t===!0,available:t===!0&&c(a),post:s,timer:0},!e.canReply){n();return}r(),e.timer=setInterval(r,3e4),globalThis.addEventListener?.("storage",o),n()}export function stopPresence({leaving:a=!1}={}){if(a&&e.canReply&&e.post)try{e.post({leaving:!0})?.catch?.(()=>{})}catch{}e.timer&&clearInterval(e.timer),globalThis.removeEventListener?.("storage",o),e={userId:null,canReply:!1,available:!1,post:null,timer:0},n()}export const canTakeChats=()=>e.canReply,isAvailable=()=>e.available;export function setAvailable(a){if(!e.canReply)return;const t=a===!0;t!==e.available&&(e.available=t,u(e.userId,t),r(),n())}export function onPresence(a){return l.add(a),a({available:e.available,canReply:e.canReply}),()=>l.delete(a)}function n(){for(const a of[...l])try{a({available:e.available,canReply:e.canReply})}catch{}}
@@ -1,2 +1,2 @@
1
- import{chatToastsDue as u,rememberSeen as h}from"./notifications-arrange.js";const c="notifications.chatToastSeen",d="#/launchers/chats";function f(){try{const t=S.get(c);return Array.isArray(t)?t:null}catch{return null}}function y(t){try{S.set(c,t)}catch{}}export function deliverChatToasts(t,{enabled:s=!0}={}){const r=f(),o=s?u(t,{seen:r}):[];for(const e of o){const n=e.data||{},a=n.source==="core:chat"&&n.severity==="warning",l=String(n.body||"").split(`
2
- `).filter(Boolean)[0]||"";E.toast(l.slice(0,200),{title:String(n.title||"Visitor chat"),type:a?"warning":"info",duration:a?0:15e3,closable:!0,actions:[{label:"Open Chats",primary:!0,closeOnClick:!0,onClick:()=>{location.hash=d}}]})}const i=(t||[]).filter(e=>e?.unread&&String(e.data?.source||"").startsWith("core:chat")).map(e=>e.id);return y(h(r||[],i)),o.length}
1
+ import{chatToastsDue as g,chatToastSticks as k,chatToastsSettled as m,rememberSeen as C,safeLink as u}from"./notifications-arrange.js";const d="notifications.chatToastSeen",T="#/launchers/chats",s=new Map;function A(){try{const t=S.get(d);return Array.isArray(t)?t:null}catch{return null}}function b(t){try{S.set(d,t)}catch{}}export const chatToastsOpen=()=>s.size>0;export function deliverChatToasts(t,{enabled:c=!0}={}){const n=A(),a=c?g(t,{seen:n}):[];for(const e of a){const o=e.data||{},r=k(e),p=o.source==="core:chat"&&o.severity==="warning",i=/^#\//.test(u(o.link))?u(o.link):T,y=String(o.body||"").split(`
2
+ `).filter(Boolean)[0]||"",l=String(e.id),h=E.toast(y.slice(0,200),{title:String(o.title||"Visitor chat"),type:p?"warning":"info",duration:r?0:15e3,closable:!0,className:r?"dm-chat-toast is-sticky":"dm-chat-toast",actions:[{label:/ai-assist/.test(i)?"Open in AI Assist":"Open Chats",primary:!0,closeOnClick:!0,onClick:()=>{location.hash=i}}],onClose:()=>{s.delete(l)}});r&&h&&s.set(l,h)}const f=(t||[]).filter(e=>e?.unread&&String(e.data?.source||"").startsWith("core:chat")).map(e=>e.id);return b(C(n||[],f)),a.length}export function settleChatToasts(t){const c=m([...s.keys()],t);for(const n of c){const a=s.get(n);s.delete(n);try{a?.close?.()}catch{}}return c.length}export function closeChatToasts(){for(const t of s.values())try{t?.close?.()}catch{}s.clear()}
@@ -1 +1 @@
1
- import{fmtDate as s}from"./dates.js";export const SEVERITIES=["critical","warning","info","success"],FILTERS=["all","new",...SEVERITIES],SEVERITY_TONE={critical:"danger",warning:"warn",success:"ok",info:"info"};const c=(t,e,n=`${e}s`)=>`${t} ${t===1?e:n}`;export function severityOf(t){const e=t?.data?.severity;return SEVERITIES.includes(e)?e:"info"}export function ago(t,e=Date.now()){const n=new Date(t).getTime();if(!Number.isFinite(n))return"";const r=Math.max(0,Math.round((e-n)/1e3));return r<60?"just now":r<3600?`${Math.round(r/60)} min ago`:r<86400?`${c(Math.round(r/3600),"hour")} ago`:r<86400*14?`${c(Math.round(r/86400),"day")} ago`:s(n)}export function arrangeNotifications(t,{filter:e="all",query:n=""}={}){const r=String(n).trim().toLowerCase();return[...t||[]].filter(i=>e==="all"?!0:e==="new"?i.isNew:severityOf(i)===e).filter(i=>!r||[i.data?.title,i.data?.body,i.data?.link].some(o=>String(o||"").toLowerCase().includes(r))).sort((i,o)=>String(o.data?.createdAt||"").localeCompare(String(i.data?.createdAt||"")))}export function filterCounts(t){const e={all:0,new:0,critical:0,warning:0,info:0,success:0};for(const n of t||[])e.all++,n.isNew&&e.new++,e[severityOf(n)]++;return e}export function safeLink(t){const e=String(t||"").trim();return/^https?:\/\/\S+$/i.test(e)||/^#\/\S*$/.test(e)?e:""}export function sourceLabel(t={}){return t.source==="manager"?"from the manager":t.source==="sample"?"sample":t.sourceLabel?String(t.sourceLabel):t.source?String(t.source).startsWith("core:")?"System":String(t.source).split(":")[0]:""}export function notificationRow(t,{now:e=Date.now(),expanded:n=""}={}){const r=t?.data||{},i=severityOf(t),o=String(r.body||""),a=o.replace(/\s+/g," ").trim();return{id:String(t.id),title:String(r.title||"(no title)"),severity:i,severityLabel:i[0].toUpperCase()+i.slice(1),tone:SEVERITY_TONE[i],meta:[r.createdAt?ago(r.createdAt,e):"",sourceLabel(r),/^https?:\/\//i.test(String(r.link||""))?"has a link":"",r.expiresAt&&Date.parse(r.expiresAt)>e?`until ${s(r.expiresAt)}`:""].filter(Boolean).join(" \xB7 "),preview:a.length>140?`${a.slice(0,139)}\u2026`:a,body:o,link:safeLink(r.link),linkTarget:/^#\//.test(safeLink(r.link))?"_self":"_blank",linkText:/^#\//.test(safeLink(r.link))?"Go there \u2192":"Open link \u2197",isNew:!!t.isNew,unread:!!t.unread,open:n===String(t.id),rowCls:[t.unread?"is-unread":"",n===String(t.id)?"is-open":"",`is-${i}`].filter(Boolean).join(" ")}}const l={boot:"at start-up","15m":"every 15 minutes",hourly:"hourly",daily:"daily at 08:00"};export function sourceRow(t,e=Date.now()){const n=t.every?`${l[t.every]||t.every}${t.atBoot&&t.every!=="boot"?" and at start-up":""}`:"as it happens";return{id:String(t.id),label:String(t.label||t.id),description:String(t.description||""),meta:[t.ownerLabel||t.owner,n,t.lastRun?`last run ${ago(t.lastRun,e)}`:""].filter(Boolean).join(" \xB7 "),enabled:!!t.enabled,audience:t.audience||"super-admin",every:t.every||"",lastError:t.lastError?`Last run failed: ${t.lastError}`:""}}export const DESKTOP_LEVELS=["all","warning","critical"],DEFAULT_SETTINGS=Object.freeze({desktop:!1,desktopLevel:"all",signInToasts:!0,chatToasts:!0});export function normaliseSettings(t){const e=t&&typeof t=="object"?t:{},n=DEFAULT_SETTINGS;return{desktop:typeof e.desktop=="boolean"?e.desktop:n.desktop,desktopLevel:DESKTOP_LEVELS.includes(e.desktopLevel)?e.desktopLevel:n.desktopLevel,signInToasts:typeof e.signInToasts=="boolean"?e.signInToasts:n.signInToasts,chatToasts:typeof e.chatToasts=="boolean"?e.chatToasts:n.chatToasts}}export function meetsLevel(t,e="all"){return e==="critical"?t==="critical":e==="warning"?t==="critical"||t==="warning":!0}export function desktopWorthy(t,{seen:e=[],level:n="all",max:r=3}={}){const i=new Set((e||[]).map(String));return[...t||[]].filter(o=>o&&o.unread&&!i.has(String(o.id))&&meetsLevel(severityOf(o),n)).sort((o,a)=>String(o.data?.createdAt||"").localeCompare(String(a.data?.createdAt||""))).slice(-r)}export const CHAT_SOURCES=Object.freeze(["core:chat","core:chat-started","core:chat-declined"]),CHAT_TOAST_RECENT_MS=10*6e4;export function chatToastsDue(t,{seen:e=null,now:n=Date.now(),max:r=3}={}){const i=new Set((e||[]).map(String));return[...t||[]].filter(o=>o&&o.unread&&CHAT_SOURCES.includes(o.data?.source)&&!i.has(String(o.id))).filter(o=>e||n-Date.parse(o.data?.createdAt||0)<CHAT_TOAST_RECENT_MS).sort((o,a)=>String(o.data?.createdAt||"").localeCompare(String(a.data?.createdAt||""))).slice(-r)}export function rememberSeen(t,e,n=200){const r=[...(t||[]).map(String)];for(const i of e||[])r.includes(String(i))||r.push(String(i));return r.slice(-n)}export function desktopPayload(t){const e=t?.data||{},n=severityOf(t),r=String(e.body||"").replace(/\s+/g," ").trim();return{title:String(e.title||"Notification").slice(0,120),options:{body:r.length>240?`${r.slice(0,239)}\u2026`:r,tag:`dcms-notification-${t?.id}`,requireInteraction:n==="critical"}}}
1
+ import{fmtDate as s}from"./dates.js";export const SEVERITIES=["critical","warning","info","success"],FILTERS=["all","new",...SEVERITIES],SEVERITY_TONE={critical:"danger",warning:"warn",success:"ok",info:"info"};const c=(t,e,n=`${e}s`)=>`${t} ${t===1?e:n}`;export function severityOf(t){const e=t?.data?.severity;return SEVERITIES.includes(e)?e:"info"}export function ago(t,e=Date.now()){const n=new Date(t).getTime();if(!Number.isFinite(n))return"";const r=Math.max(0,Math.round((e-n)/1e3));return r<60?"just now":r<3600?`${Math.round(r/60)} min ago`:r<86400?`${c(Math.round(r/3600),"hour")} ago`:r<86400*14?`${c(Math.round(r/86400),"day")} ago`:s(n)}export function arrangeNotifications(t,{filter:e="all",query:n=""}={}){const r=String(n).trim().toLowerCase();return[...t||[]].filter(i=>e==="all"?!0:e==="new"?i.isNew:severityOf(i)===e).filter(i=>!r||[i.data?.title,i.data?.body,i.data?.link].some(o=>String(o||"").toLowerCase().includes(r))).sort((i,o)=>String(o.data?.createdAt||"").localeCompare(String(i.data?.createdAt||"")))}export function filterCounts(t){const e={all:0,new:0,critical:0,warning:0,info:0,success:0};for(const n of t||[])e.all++,n.isNew&&e.new++,e[severityOf(n)]++;return e}export function safeLink(t){const e=String(t||"").trim();return/^https?:\/\/\S+$/i.test(e)||/^#\/\S*$/.test(e)?e:""}export function sourceLabel(t={}){return t.source==="manager"?"from the manager":t.source==="sample"?"sample":t.sourceLabel?String(t.sourceLabel):t.source?String(t.source).startsWith("core:")?"System":String(t.source).split(":")[0]:""}export function notificationRow(t,{now:e=Date.now(),expanded:n=""}={}){const r=t?.data||{},i=severityOf(t),o=String(r.body||""),a=o.replace(/\s+/g," ").trim();return{id:String(t.id),title:String(r.title||"(no title)"),severity:i,severityLabel:i[0].toUpperCase()+i.slice(1),tone:SEVERITY_TONE[i],meta:[r.createdAt?ago(r.createdAt,e):"",sourceLabel(r),/^https?:\/\//i.test(String(r.link||""))?"has a link":"",r.expiresAt&&Date.parse(r.expiresAt)>e?`until ${s(r.expiresAt)}`:""].filter(Boolean).join(" \xB7 "),preview:a.length>140?`${a.slice(0,139)}\u2026`:a,body:o,link:safeLink(r.link),linkTarget:/^#\//.test(safeLink(r.link))?"_self":"_blank",linkText:/^#\//.test(safeLink(r.link))?"Go there \u2192":"Open link \u2197",isNew:!!t.isNew,unread:!!t.unread,open:n===String(t.id),rowCls:[t.unread?"is-unread":"",n===String(t.id)?"is-open":"",`is-${i}`].filter(Boolean).join(" ")}}const l={boot:"at start-up","15m":"every 15 minutes",hourly:"hourly",daily:"daily at 08:00"};export function sourceRow(t,e=Date.now()){const n=t.every?`${l[t.every]||t.every}${t.atBoot&&t.every!=="boot"?" and at start-up":""}`:"as it happens";return{id:String(t.id),label:String(t.label||t.id),description:String(t.description||""),meta:[t.ownerLabel||t.owner,n,t.lastRun?`last run ${ago(t.lastRun,e)}`:""].filter(Boolean).join(" \xB7 "),enabled:!!t.enabled,audience:t.audience||"super-admin",every:t.every||"",lastError:t.lastError?`Last run failed: ${t.lastError}`:""}}export const DESKTOP_LEVELS=["all","warning","critical"],DEFAULT_SETTINGS=Object.freeze({desktop:!1,desktopLevel:"all",signInToasts:!0,chatToasts:!0});export function normaliseSettings(t){const e=t&&typeof t=="object"?t:{},n=DEFAULT_SETTINGS;return{desktop:typeof e.desktop=="boolean"?e.desktop:n.desktop,desktopLevel:DESKTOP_LEVELS.includes(e.desktopLevel)?e.desktopLevel:n.desktopLevel,signInToasts:typeof e.signInToasts=="boolean"?e.signInToasts:n.signInToasts,chatToasts:typeof e.chatToasts=="boolean"?e.chatToasts:n.chatToasts}}export function meetsLevel(t,e="all"){return e==="critical"?t==="critical":e==="warning"?t==="critical"||t==="warning":!0}export function desktopWorthy(t,{seen:e=[],level:n="all",max:r=3}={}){const i=new Set((e||[]).map(String));return[...t||[]].filter(o=>o&&o.unread&&!i.has(String(o.id))&&meetsLevel(severityOf(o),n)).sort((o,a)=>String(o.data?.createdAt||"").localeCompare(String(a.data?.createdAt||""))).slice(-r)}export const CHAT_SOURCES=Object.freeze(["core:chat","core:chat-started","core:chat-declined"]),CHAT_TOAST_RECENT_MS=10*6e4;export function chatToastsDue(t,{seen:e=null,now:n=Date.now(),max:r=3}={}){const i=new Set((e||[]).map(String));return[...t||[]].filter(o=>o&&o.unread&&CHAT_SOURCES.includes(o.data?.source)&&!i.has(String(o.id))).filter(o=>e||n-Date.parse(o.data?.createdAt||0)<CHAT_TOAST_RECENT_MS).sort((o,a)=>String(o.data?.createdAt||"").localeCompare(String(a.data?.createdAt||""))).slice(-r)}export function chatToastSticks(t){const e=t?.data||{};return e.source==="core:chat-started"||e.source==="core:chat"&&e.severity==="warning"}export function chatToastsSettled(t,e){const n=new Set((e||[]).filter(r=>r?.unread).map(r=>String(r.id)));return(t||[]).map(String).filter(r=>!n.has(r))}export function rememberSeen(t,e,n=200){const r=[...(t||[]).map(String)];for(const i of e||[])r.includes(String(i))||r.push(String(i));return r.slice(-n)}export function desktopPayload(t){const e=t?.data||{},n=severityOf(t),r=String(e.body||"").replace(/\s+/g," ").trim();return{title:String(e.title||"Notification").slice(0,120),options:{body:r.length>240?`${r.slice(0,239)}\u2026`:r,tag:`dcms-notification-${t?.id}`,requireInteraction:n==="critical"}}}
@@ -1,3 +1,3 @@
1
- export const TAB_FIELDS={general:["title","tagline","siteUrl","adminHome","spacerSize","bodyClass","aiContext","aiRules","adminAssistantEnabled","adminAssistantName","adminAssistantCharacter","adminAssistantContext","adminAssistantRules","charactersEnabled","charactersAnimated","charactersLaunchers","charactersChats","charactersBuilders","charactersDot","charactersDaisy"],branding:["brandEnabled","brandText","brandLogo","brandIcon","brandUrl","adminBrandEnabled","adminBrandTitle","adminBrandLogo","adminBrandLogoDark","adminBrandIcon"],favicon:["favicon"],footer:["footerCopyright","footerLayout","footerBlurb","footerBlocks","footerClass","footerSocialClass","footerLook","footerCtaText","footerCtaHighlight","footerCtaUrl","footerCtaSub","footerWatermark","footerStatus","footerFacts","footerTagline","footerEmail","footerAddress","footerGradFrom","footerGradTo","socialTwitter","socialFacebook","socialInstagram","socialLinkedin","socialGithub","socialYoutube"],email:["smtpHost","smtpPort","smtpUser","smtpPass","smtpSecure","smtpInsecureTLS","smtpFromAddress","smtpFromName"],pageNavigation:["bttEnabled","bttSmooth","bttLabel","bttThreshold","bttPosition","bttOffset","bttBottomOffset","gtbEnabled","gtbSmooth","gtbLabel","gtbThreshold","gtbPosition","gtbOffset","gtbBottomOffset"],cookies:["ccEnabled","ccMessage","ccAcceptAll","ccRejectAll","ccCustomize","ccSavePrefs","ccPrivacyText","ccPrivacyUrl","ccCookieText","ccCookieUrl","ccPosition","ccLayout","ccTheme","ccShowFunctional","ccShowAnalytics","ccShowMarketing","ccVersion","ccSettingsLink","ccSettingsLinkText"],breadcrumbs:["bcEnabled","bcHomeLabel","bcPosition","bcOffsetX","bcOffsetY"],motion:["mtEnabled","mtLabel","mtDefault","mtControl","mtPlacement","mtTriggerStyle","mtPosition","mtOffsetX","mtOffsetY","mtIconSize","mtIconRadius","mtClass"]},SECRET_FIELDS=["smtpPass"],BREADCRUMB_POSITIONS=["TL","TR","BL","BR"],MOTION_PLACEMENTS=["footer","floating","navbar"],MOTION_LABEL="Reduce motion";const b=["system","off","on"],c=(t,a,r,o)=>{const n=Number.parseInt(t,10);return Number.isFinite(n)?Math.min(o,Math.max(r,n)):a};export function motionFromSettings(t={}){const a=t.motion&&typeof t.motion=="object"?t.motion:{},r=t.footer||{},o=m=>a[m]!==void 0&&a[m]!==null,n=o("default")?a.default:r.motionDefault,s=o("control")?a.control:r.motionControl,l=c(a.iconSize,52,32,96);return{mtEnabled:(o("enabled")?a.enabled:r.showMotionToggle)!==!1,mtLabel:typeof a.label=="string"&&a.label.trim()?a.label.trim():MOTION_LABEL,mtDefault:b.includes(n)?n:"system",mtControl:s==="checkbox"?"checkbox":"switch",mtPlacement:MOTION_PLACEMENTS.includes(a.placement)?a.placement:"footer",mtTriggerStyle:a.triggerStyle==="icon-text"?"icon-text":"icon",mtPosition:BREADCRUMB_POSITIONS.includes(a.position)?a.position:"BL",mtOffsetX:e(c(a.offsetX,32,0,500)),mtOffsetY:e(c(a.offsetY,32,0,500)),mtIconSize:e(l),mtIconRadius:e(c(a.iconRadius,26,0,Math.floor(l/2))),mtClass:e(a.class)}}export function motionFromForm(t){const a=c(t.mtIconSize,52,32,96);return{enabled:t.mtEnabled===!0,default:b.includes(t.mtDefault)?t.mtDefault:"system",placement:MOTION_PLACEMENTS.includes(t.mtPlacement)?t.mtPlacement:"footer",control:t.mtControl==="checkbox"?"checkbox":"switch",triggerStyle:t.mtTriggerStyle==="icon-text"?"icon-text":"icon",label:e(t.mtLabel).trim().replace(/\s+/g," ").slice(0,40)||MOTION_LABEL,position:BREADCRUMB_POSITIONS.includes(t.mtPosition)?t.mtPosition:"BL",offsetX:c(t.mtOffsetX,32,0,500),offsetY:c(t.mtOffsetY,32,0,500),iconSize:a,iconRadius:c(t.mtIconRadius,26,0,Math.floor(a/2)),class:e(t.mtClass).trim()}}export function footerBlockNames(t){return[...new Set(String(t??"").split(/[\s,]+/).map(a=>a.trim().toLowerCase()).filter(Boolean))]}export function gaIdError(t){const a=e(t).trim();return!a||/^G-[A-Z0-9]{4,20}$/i.test(a)?"":"A measurement ID looks like G-XXXXXXXXXX (Google Analytics > Admin > Data streams)."}export const FOOTER_LAYOUTS=["auto","columns","row"],FOOTER_LOOKS=["","showcase"],FOOTER_FACTS_MAX=4;const h=/^(\/|#|https?:\/\/|mailto:)/,p=/^#[0-9a-f]{6}$/i;export function footerShowcaseErrors(t){const a=[],r=e(t.footerCtaUrl).trim();r&&!h.test(r)&&a.push("The footer call to action link must start with /, #, https:// or mailto: (Footer tool).");for(const[o,n]of[["from",t.footerGradFrom],["to",t.footerGradTo]]){const s=e(n).trim();s&&!p.test(s)&&a.push(`The footer gradient "${o}" colour must look like #f26b3a (Footer tool).`)}return a}const e=(t,a="")=>t==null?a:String(t),i=(t,a)=>{const r=Number.parseInt(t,10);return Number.isFinite(r)?r:a};export function homeValue(t){return/^\/[A-Za-z0-9\-_/]*$/.test(t||"")&&String(t).replace(/\/+$/,"")||"/"}export function formFromSettings(t={}){const a=t.backToTop||{},r=t.goToBottom||{},o=t.cookieConsent||{},n=t.breadcrumbs||{};return{title:e(t.title),tagline:e(t.tagline),siteUrl:e(t.baseUrl),adminHome:homeValue(t.adminHome),spacerSize:e(t.layoutOptions?.spacerSize??40),bodyClass:e(t.bodyClass),aiContext:e(t.assistant?.context),aiRules:e(t.assistant?.rules),adminAssistantEnabled:t.adminAssistant?.enabled===!0,adminAssistantName:e(t.adminAssistant?.name,"Della"),adminAssistantCharacter:e(t.adminAssistant?.character,"della"),adminAssistantContext:e(t.adminAssistant?.context),adminAssistantRules:e(t.adminAssistant?.rules),charactersEnabled:t.characters?.enabled!==!1,charactersAnimated:t.characters?.animated!==!1,charactersLaunchers:t.characters?.launchers!==!1,charactersChats:t.characters?.chats!==!1,charactersBuilders:t.characters?.builders!==!1,charactersDot:t.characters?.dot!==!1,charactersDaisy:t.characters?.daisy!==!1,brandEnabled:t.brand?.enabled!==!1,brandText:e(t.brand?.text),brandLogo:e(t.brand?.logo),brandIcon:e(t.brand?.icon),brandUrl:e(t.brand?.url,"/"),favicon:e(t.favicon),adminBrandEnabled:t.adminBrand?.enabled!==!1,adminBrandTitle:e(t.adminBrand?.title),adminBrandLogo:e(t.adminBrand?.logo),adminBrandLogoDark:e(t.adminBrand?.logoDark),adminBrandIcon:e(t.adminBrand?.icon),footerCopyright:e(t.footer?.copyright),footerLayout:FOOTER_LAYOUTS.includes(t.footer?.layout)?t.footer.layout:"auto",footerBlurb:e(t.footer?.blurb),footerBlocks:Array.isArray(t.footer?.blocks)?t.footer.blocks.filter(s=>typeof s=="string").join(", "):"",footerClass:e(t.footer?.class),footerSocialClass:e(t.footer?.socialClass),footerLook:FOOTER_LOOKS.includes(t.footer?.look)?t.footer.look:"",footerCtaText:e(t.footer?.cta?.text),footerCtaHighlight:e(t.footer?.cta?.highlight),footerCtaUrl:e(t.footer?.cta?.url),footerCtaSub:e(t.footer?.cta?.sub),footerWatermark:e(t.footer?.watermark),footerStatus:e(t.footer?.status),footerFacts:Array.isArray(t.footer?.facts)?t.footer.facts.filter(s=>typeof s=="string").join(`
2
- `):"",footerTagline:e(t.footer?.tagline),footerEmail:e(t.footer?.email),footerAddress:e(t.footer?.address),footerGradFrom:e(t.footer?.gradient?.from),footerGradTo:e(t.footer?.gradient?.to),socialTwitter:e(t.social?.twitter),socialFacebook:e(t.social?.facebook),socialInstagram:e(t.social?.instagram),socialLinkedin:e(t.social?.linkedin),socialGithub:e(t.social?.github),socialYoutube:e(t.social?.youtube),smtpHost:e(t.smtp?.host),smtpPort:e(t.smtp?.port||587),smtpUser:e(t.smtp?.user),smtpPass:"",smtpSecure:t.smtp?.secure===!0,smtpInsecureTLS:t.smtp?.allowInsecureTLS===!0,smtpFromAddress:e(t.smtp?.fromAddress),smtpFromName:e(t.smtp?.fromName),bttEnabled:a.enabled!==!1,bttSmooth:a.smooth!==!1,bttLabel:e(a.label),bttThreshold:e(a.scrollThreshold??300),bttPosition:e(a.position,"bottom-right"),bttOffset:e(a.offset??32),bttBottomOffset:e(a.bottomOffset??a.offset??32),gtbEnabled:r.enabled===!0,gtbSmooth:r.smooth!==!1,gtbLabel:e(r.label),gtbThreshold:e(r.scrollThreshold??300),gtbPosition:e(r.position,"bottom-right"),gtbOffset:e(r.offset??32),gtbBottomOffset:e(r.bottomOffset??r.offset??32),ccEnabled:o.enabled!==!1,ccMessage:e(o.message),ccAcceptAll:e(o.acceptAllText,"Accept All"),ccRejectAll:e(o.rejectAllText,"Reject All"),ccCustomize:e(o.customizeText,"Customize"),ccSavePrefs:e(o.savePreferencesText,"Save Preferences"),ccPrivacyText:e(o.privacyPolicyText,"Privacy Policy"),ccPrivacyUrl:e(o.privacyPolicyUrl),ccCookieText:e(o.cookiePolicyText,"Cookie Policy"),ccCookieUrl:e(o.cookiePolicyUrl),ccPosition:e(o.position,"bottom"),ccLayout:e(o.layout,"bar"),ccTheme:e(o.theme,"dark"),ccShowFunctional:o.showFunctional!==!1,ccShowAnalytics:o.showAnalytics!==!1,ccShowMarketing:o.showMarketing!==!1,ccVersion:e(o.consentVersion,"1.0"),ccSettingsLink:o.showSettingsLink!==!1,ccSettingsLinkText:e(o.settingsLinkText,"Cookie settings"),bcEnabled:n.enabled===!0,bcHomeLabel:e(n.homeLabel,"Home"),bcPosition:BREADCRUMB_POSITIONS.includes(n.position)?n.position:"TL",bcOffsetX:e(n.offsetX??8),bcOffsetY:e(n.offsetY??8),...motionFromSettings(t)}}export function payloadFromForm(t,a={},{adminHomeReady:r=!0}={}){const o=s=>e(s).trim(),n=motionFromForm(t);return{title:o(t.title),tagline:o(t.tagline),baseUrl:o(t.siteUrl).replace(/\/+$/,""),...r&&{adminHome:o(t.adminHome)||"/"},layoutOptions:{spacerSize:i(t.spacerSize,40)||40},bodyClass:o(t.bodyClass),assistant:{context:o(t.aiContext),rules:o(t.aiRules)},adminAssistant:{enabled:t.adminAssistantEnabled===!0,name:o(t.adminAssistantName)||"Della",character:o(t.adminAssistantCharacter),context:o(t.adminAssistantContext),rules:o(t.adminAssistantRules)},characters:{enabled:t.charactersEnabled!==!1,animated:t.charactersAnimated!==!1,launchers:t.charactersLaunchers!==!1,chats:t.charactersChats!==!1,builders:t.charactersBuilders!==!1,dot:t.charactersDot!==!1,daisy:t.charactersDaisy!==!1},brand:{...a.brand,enabled:t.brandEnabled!==!1,text:o(t.brandText),logo:o(t.brandLogo),icon:o(t.brandIcon),url:o(t.brandUrl)||"/"},favicon:o(t.favicon),adminBrand:{...a.adminBrand,enabled:t.adminBrandEnabled!==!1,title:o(t.adminBrandTitle),logo:o(t.adminBrandLogo),logoDark:o(t.adminBrandLogoDark),icon:o(t.adminBrandIcon)},footer:{copyright:o(t.footerCopyright),layout:FOOTER_LAYOUTS.includes(t.footerLayout)?t.footerLayout:"auto",blurb:o(t.footerBlurb),blocks:footerBlockNames(t.footerBlocks),links:a.footer?.links||[],showMotionToggle:n.enabled,motionDefault:n.default,motionControl:n.control,class:o(t.footerClass),socialClass:o(t.footerSocialClass),look:FOOTER_LOOKS.includes(t.footerLook)?t.footerLook:"",cta:{text:o(t.footerCtaText),highlight:o(t.footerCtaHighlight),url:o(t.footerCtaUrl),sub:o(t.footerCtaSub)},watermark:o(t.footerWatermark),status:o(t.footerStatus),facts:String(t.footerFacts??"").split(`
3
- `).map(s=>s.trim()).filter(Boolean).slice(0,FOOTER_FACTS_MAX),tagline:o(t.footerTagline),email:o(t.footerEmail),address:o(t.footerAddress),gradient:{from:o(t.footerGradFrom),to:o(t.footerGradTo)}},social:{twitter:o(t.socialTwitter),facebook:o(t.socialFacebook),instagram:o(t.socialInstagram),linkedin:o(t.socialLinkedin),github:o(t.socialGithub),youtube:o(t.socialYoutube)},smtp:{host:o(t.smtpHost),port:i(t.smtpPort,587)||587,user:o(t.smtpUser),pass:e(t.smtpPass),secure:t.smtpSecure===!0,allowInsecureTLS:t.smtpInsecureTLS===!0,fromAddress:o(t.smtpFromAddress),fromName:o(t.smtpFromName)},backToTop:{enabled:t.bttEnabled===!0,scrollThreshold:i(t.bttThreshold,300),position:e(t.bttPosition)||"bottom-right",offset:i(t.bttOffset,32),bottomOffset:i(t.bttBottomOffset,32),label:o(t.bttLabel),smooth:t.bttSmooth===!0},goToBottom:{enabled:t.gtbEnabled===!0,scrollThreshold:i(t.gtbThreshold,300),position:e(t.gtbPosition)||"bottom-right",offset:i(t.gtbOffset,32),bottomOffset:i(t.gtbBottomOffset,32),label:o(t.gtbLabel),smooth:t.gtbSmooth===!0},cookieConsent:{enabled:t.ccEnabled===!0,message:o(t.ccMessage),acceptAllText:o(t.ccAcceptAll),rejectAllText:o(t.ccRejectAll),customizeText:o(t.ccCustomize),savePreferencesText:o(t.ccSavePrefs),privacyPolicyText:o(t.ccPrivacyText),privacyPolicyUrl:o(t.ccPrivacyUrl),cookiePolicyText:o(t.ccCookieText),cookiePolicyUrl:o(t.ccCookieUrl),position:e(t.ccPosition)||"bottom",layout:e(t.ccLayout)||"bar",theme:e(t.ccTheme)||"dark",showFunctional:t.ccShowFunctional===!0,showAnalytics:t.ccShowAnalytics===!0,showMarketing:t.ccShowMarketing===!0,consentVersion:o(t.ccVersion)||"1.0",showSettingsLink:t.ccSettingsLink===!0,settingsLinkText:o(t.ccSettingsLinkText)||"Cookie settings"},breadcrumbs:{enabled:t.bcEnabled===!0,homeLabel:o(t.bcHomeLabel)||"Home",position:BREADCRUMB_POSITIONS.includes(t.bcPosition)?t.bcPosition:"TL",offsetX:i(t.bcOffsetX,8),offsetY:i(t.bcOffsetY,8)},motion:n}}export function siteUrlError(t){const a=e(t).trim().replace(/\/+$/,"");return a?/^https?:\/\//i.test(a)?/^https?:\/\/([a-z0-9.\-]+|\[[0-9a-f:.]+\])(:\d{1,5})?$/i.test(a)?"":"Just the address, like https://example.com - no page path after it.":"Start with https:// (or http://).":""}const d=t=>typeof t=="boolean"?t:e(t);export function snapshot(t){return JSON.stringify(Object.keys(t).sort().map(a=>[a,d(t[a])]))}export function changedTabs(t,a){const r=[];for(const[o,n]of Object.entries(TAB_FIELDS))n.some(s=>d(t[s])!==d(a[s]))&&r.push(o);return r}export function draftOf(t){return Object.fromEntries(Object.entries(t).filter(([a])=>!SECRET_FIELDS.includes(a)))}const g={footerMotionToggle:"mtEnabled",footerMotionDefault:"mtDefault",footerMotionControl:"mtControl"};export function formFromDraft(t,a={}){const r={...a};for(const[n,s]of Object.entries(g))n in r&&!(s in r)&&(r[s]=r[n]),delete r[n];const o={...t};for(const[n,s]of Object.entries(r))n in o&&!SECRET_FIELDS.includes(n)&&(o[n]=s);return o}export function settingsProblems(t,a={}){const r=[];return e(t.smtpHost).trim()?e(t.smtpFromAddress).trim()||r.push({tone:"warn",tab:"email",text:"No From address - mail has no sender and many servers refuse it."}):r.push({tone:"danger",tab:"email",text:"No SMTP host - mail goes to a throwaway test inbox and reaches no one (password resets, form notifications)."}),(t.ccEnabled===!0||e(a.googleAnalytics?.measurementId).trim())&&!e(t.ccPrivacyUrl).trim()&&r.push({tone:"warn",tab:"cookies",text:"The cookie banner is on but links to no privacy policy."}),r}export function describeCacheKey(t){const a=/^page:(.*?):m\d+:role([^:]*):/.exec(String(t||""));return a?{path:a[1]||"/",role:a[2]||"anon",page:!0}:{path:String(t||""),role:"",page:!1}}export function expiresIn(t,a=Date.now()){if(t==null)return"no expiry";const r=t-a;return r<=0?"expired":r<6e4?`${Math.round(r/1e3)}s`:r<36e5?`${Math.round(r/6e4)}m`:`${Math.round(r/36e5)}h`}export function footerForm(t={}){const a=formFromSettings(t);return Object.fromEntries(TAB_FIELDS.footer.map(r=>[r,a[r]]))}export function footerPayload(t){const{footer:a,social:r}=payloadFromForm(t);return delete a.links,delete a.showMotionToggle,delete a.motionDefault,delete a.motionControl,{footer:a,social:r}}export function siteSettingsForm(t={}){return Object.fromEntries(Object.entries(formFromSettings(t)).filter(([a])=>!TAB_FIELDS.footer.includes(a)&&!u.includes(a)))}export function siteSettingsPayload(...t){const{footer:a,social:r,favicon:o,backToTop:n,goToBottom:s,breadcrumbs:l,motion:m,...f}=payloadFromForm(...t);return f}export const APPEARANCE_TABS=["favicon","pageNavigation","breadcrumbs","motion","search"];const u=APPEARANCE_TABS.flatMap(t=>TAB_FIELDS[t]||[]);export function appearanceForm(t={}){const a=formFromSettings(t);return Object.fromEntries(u.map(r=>[r,a[r]]))}export function appearancePayload(t){const{favicon:a,backToTop:r,goToBottom:o,breadcrumbs:n,motion:s}=payloadFromForm(t);return{favicon:a,backToTop:r,goToBottom:o,breadcrumbs:n,motion:s}}
1
+ export const TAB_FIELDS={general:["title","tagline","siteUrl","adminHome","spacerSize","bodyClass","charactersEnabled","charactersAnimated","charactersLaunchers","charactersChats","charactersBuilders","charactersDot","charactersDaisy"],branding:["brandEnabled","brandText","brandLogo","brandIcon","brandUrl","adminBrandEnabled","adminBrandTitle","adminBrandLogo","adminBrandLogoDark","adminBrandIcon"],favicon:["favicon"],footer:["footerCopyright","footerLayout","footerBlurb","footerBlocks","footerClass","footerSocialClass","footerLook","footerCtaText","footerCtaHighlight","footerCtaUrl","footerCtaSub","footerWatermark","footerStatus","footerFacts","footerTagline","footerEmail","footerAddress","footerGradFrom","footerGradTo","socialTwitter","socialFacebook","socialInstagram","socialLinkedin","socialGithub","socialYoutube"],email:["smtpHost","smtpPort","smtpUser","smtpPass","smtpSecure","smtpInsecureTLS","smtpFromAddress","smtpFromName"],pageNavigation:["bttEnabled","bttSmooth","bttLabel","bttThreshold","bttPosition","bttOffset","bttBottomOffset","gtbEnabled","gtbSmooth","gtbLabel","gtbThreshold","gtbPosition","gtbOffset","gtbBottomOffset"],cookies:["ccEnabled","ccMessage","ccAcceptAll","ccRejectAll","ccCustomize","ccSavePrefs","ccPrivacyText","ccPrivacyUrl","ccCookieText","ccCookieUrl","ccPosition","ccLayout","ccTheme","ccShowFunctional","ccShowAnalytics","ccShowMarketing","ccVersion","ccSettingsLink","ccSettingsLinkText"],breadcrumbs:["bcEnabled","bcHomeLabel","bcPosition","bcOffsetX","bcOffsetY"],motion:["mtEnabled","mtLabel","mtDefault","mtControl","mtPlacement","mtTriggerStyle","mtPosition","mtOffsetX","mtOffsetY","mtIconSize","mtIconRadius","mtClass"]},SECRET_FIELDS=["smtpPass"],BREADCRUMB_POSITIONS=["TL","TR","BL","BR"],MOTION_PLACEMENTS=["footer","floating","navbar"],MOTION_LABEL="Reduce motion";const b=["system","off","on"],i=(t,r,a,o)=>{const n=Number.parseInt(t,10);return Number.isFinite(n)?Math.min(o,Math.max(a,n)):r};export function motionFromSettings(t={}){const r=t.motion&&typeof t.motion=="object"?t.motion:{},a=t.footer||{},o=m=>r[m]!==void 0&&r[m]!==null,n=o("default")?r.default:a.motionDefault,s=o("control")?r.control:a.motionControl,l=i(r.iconSize,52,32,96);return{mtEnabled:(o("enabled")?r.enabled:a.showMotionToggle)!==!1,mtLabel:typeof r.label=="string"&&r.label.trim()?r.label.trim():MOTION_LABEL,mtDefault:b.includes(n)?n:"system",mtControl:s==="checkbox"?"checkbox":"switch",mtPlacement:MOTION_PLACEMENTS.includes(r.placement)?r.placement:"footer",mtTriggerStyle:r.triggerStyle==="icon-text"?"icon-text":"icon",mtPosition:BREADCRUMB_POSITIONS.includes(r.position)?r.position:"BL",mtOffsetX:e(i(r.offsetX,32,0,500)),mtOffsetY:e(i(r.offsetY,32,0,500)),mtIconSize:e(l),mtIconRadius:e(i(r.iconRadius,26,0,Math.floor(l/2))),mtClass:e(r.class)}}export function motionFromForm(t){const r=i(t.mtIconSize,52,32,96);return{enabled:t.mtEnabled===!0,default:b.includes(t.mtDefault)?t.mtDefault:"system",placement:MOTION_PLACEMENTS.includes(t.mtPlacement)?t.mtPlacement:"footer",control:t.mtControl==="checkbox"?"checkbox":"switch",triggerStyle:t.mtTriggerStyle==="icon-text"?"icon-text":"icon",label:e(t.mtLabel).trim().replace(/\s+/g," ").slice(0,40)||MOTION_LABEL,position:BREADCRUMB_POSITIONS.includes(t.mtPosition)?t.mtPosition:"BL",offsetX:i(t.mtOffsetX,32,0,500),offsetY:i(t.mtOffsetY,32,0,500),iconSize:r,iconRadius:i(t.mtIconRadius,26,0,Math.floor(r/2)),class:e(t.mtClass).trim()}}export function footerBlockNames(t){return[...new Set(String(t??"").split(/[\s,]+/).map(r=>r.trim().toLowerCase()).filter(Boolean))]}export function gaIdError(t){const r=e(t).trim();return!r||/^G-[A-Z0-9]{4,20}$/i.test(r)?"":"A measurement ID looks like G-XXXXXXXXXX (Google Analytics > Admin > Data streams)."}export const FOOTER_LAYOUTS=["auto","columns","row"],FOOTER_LOOKS=["","showcase"],FOOTER_FACTS_MAX=4;const h=/^(\/|#|https?:\/\/|mailto:)/,p=/^#[0-9a-f]{6}$/i;export function footerShowcaseErrors(t){const r=[],a=e(t.footerCtaUrl).trim();a&&!h.test(a)&&r.push("The footer call to action link must start with /, #, https:// or mailto: (Footer tool).");for(const[o,n]of[["from",t.footerGradFrom],["to",t.footerGradTo]]){const s=e(n).trim();s&&!p.test(s)&&r.push(`The footer gradient "${o}" colour must look like #f26b3a (Footer tool).`)}return r}const e=(t,r="")=>t==null?r:String(t),c=(t,r)=>{const a=Number.parseInt(t,10);return Number.isFinite(a)?a:r};export function homeValue(t){return/^\/[A-Za-z0-9\-_/]*$/.test(t||"")&&String(t).replace(/\/+$/,"")||"/"}export function formFromSettings(t={}){const r=t.backToTop||{},a=t.goToBottom||{},o=t.cookieConsent||{},n=t.breadcrumbs||{};return{title:e(t.title),tagline:e(t.tagline),siteUrl:e(t.baseUrl),adminHome:homeValue(t.adminHome),spacerSize:e(t.layoutOptions?.spacerSize??40),bodyClass:e(t.bodyClass),charactersEnabled:t.characters?.enabled!==!1,charactersAnimated:t.characters?.animated!==!1,charactersLaunchers:t.characters?.launchers!==!1,charactersChats:t.characters?.chats!==!1,charactersBuilders:t.characters?.builders!==!1,charactersDot:t.characters?.dot!==!1,charactersDaisy:t.characters?.daisy!==!1,brandEnabled:t.brand?.enabled!==!1,brandText:e(t.brand?.text),brandLogo:e(t.brand?.logo),brandIcon:e(t.brand?.icon),brandUrl:e(t.brand?.url,"/"),favicon:e(t.favicon),adminBrandEnabled:t.adminBrand?.enabled!==!1,adminBrandTitle:e(t.adminBrand?.title),adminBrandLogo:e(t.adminBrand?.logo),adminBrandLogoDark:e(t.adminBrand?.logoDark),adminBrandIcon:e(t.adminBrand?.icon),footerCopyright:e(t.footer?.copyright),footerLayout:FOOTER_LAYOUTS.includes(t.footer?.layout)?t.footer.layout:"auto",footerBlurb:e(t.footer?.blurb),footerBlocks:Array.isArray(t.footer?.blocks)?t.footer.blocks.filter(s=>typeof s=="string").join(", "):"",footerClass:e(t.footer?.class),footerSocialClass:e(t.footer?.socialClass),footerLook:FOOTER_LOOKS.includes(t.footer?.look)?t.footer.look:"",footerCtaText:e(t.footer?.cta?.text),footerCtaHighlight:e(t.footer?.cta?.highlight),footerCtaUrl:e(t.footer?.cta?.url),footerCtaSub:e(t.footer?.cta?.sub),footerWatermark:e(t.footer?.watermark),footerStatus:e(t.footer?.status),footerFacts:Array.isArray(t.footer?.facts)?t.footer.facts.filter(s=>typeof s=="string").join(`
2
+ `):"",footerTagline:e(t.footer?.tagline),footerEmail:e(t.footer?.email),footerAddress:e(t.footer?.address),footerGradFrom:e(t.footer?.gradient?.from),footerGradTo:e(t.footer?.gradient?.to),socialTwitter:e(t.social?.twitter),socialFacebook:e(t.social?.facebook),socialInstagram:e(t.social?.instagram),socialLinkedin:e(t.social?.linkedin),socialGithub:e(t.social?.github),socialYoutube:e(t.social?.youtube),smtpHost:e(t.smtp?.host),smtpPort:e(t.smtp?.port||587),smtpUser:e(t.smtp?.user),smtpPass:"",smtpSecure:t.smtp?.secure===!0,smtpInsecureTLS:t.smtp?.allowInsecureTLS===!0,smtpFromAddress:e(t.smtp?.fromAddress),smtpFromName:e(t.smtp?.fromName),bttEnabled:r.enabled!==!1,bttSmooth:r.smooth!==!1,bttLabel:e(r.label),bttThreshold:e(r.scrollThreshold??300),bttPosition:e(r.position,"bottom-right"),bttOffset:e(r.offset??32),bttBottomOffset:e(r.bottomOffset??r.offset??32),gtbEnabled:a.enabled===!0,gtbSmooth:a.smooth!==!1,gtbLabel:e(a.label),gtbThreshold:e(a.scrollThreshold??300),gtbPosition:e(a.position,"bottom-right"),gtbOffset:e(a.offset??32),gtbBottomOffset:e(a.bottomOffset??a.offset??32),ccEnabled:o.enabled!==!1,ccMessage:e(o.message),ccAcceptAll:e(o.acceptAllText,"Accept All"),ccRejectAll:e(o.rejectAllText,"Reject All"),ccCustomize:e(o.customizeText,"Customize"),ccSavePrefs:e(o.savePreferencesText,"Save Preferences"),ccPrivacyText:e(o.privacyPolicyText,"Privacy Policy"),ccPrivacyUrl:e(o.privacyPolicyUrl),ccCookieText:e(o.cookiePolicyText,"Cookie Policy"),ccCookieUrl:e(o.cookiePolicyUrl),ccPosition:e(o.position,"bottom"),ccLayout:e(o.layout,"bar"),ccTheme:e(o.theme,"dark"),ccShowFunctional:o.showFunctional!==!1,ccShowAnalytics:o.showAnalytics!==!1,ccShowMarketing:o.showMarketing!==!1,ccVersion:e(o.consentVersion,"1.0"),ccSettingsLink:o.showSettingsLink!==!1,ccSettingsLinkText:e(o.settingsLinkText,"Cookie settings"),bcEnabled:n.enabled===!0,bcHomeLabel:e(n.homeLabel,"Home"),bcPosition:BREADCRUMB_POSITIONS.includes(n.position)?n.position:"TL",bcOffsetX:e(n.offsetX??8),bcOffsetY:e(n.offsetY??8),...motionFromSettings(t)}}export function payloadFromForm(t,r={},{adminHomeReady:a=!0}={}){const o=s=>e(s).trim(),n=motionFromForm(t);return{title:o(t.title),tagline:o(t.tagline),baseUrl:o(t.siteUrl).replace(/\/+$/,""),...a&&{adminHome:o(t.adminHome)||"/"},layoutOptions:{spacerSize:c(t.spacerSize,40)||40},bodyClass:o(t.bodyClass),characters:{enabled:t.charactersEnabled!==!1,animated:t.charactersAnimated!==!1,launchers:t.charactersLaunchers!==!1,chats:t.charactersChats!==!1,builders:t.charactersBuilders!==!1,dot:t.charactersDot!==!1,daisy:t.charactersDaisy!==!1},brand:{...r.brand,enabled:t.brandEnabled!==!1,text:o(t.brandText),logo:o(t.brandLogo),icon:o(t.brandIcon),url:o(t.brandUrl)||"/"},favicon:o(t.favicon),adminBrand:{...r.adminBrand,enabled:t.adminBrandEnabled!==!1,title:o(t.adminBrandTitle),logo:o(t.adminBrandLogo),logoDark:o(t.adminBrandLogoDark),icon:o(t.adminBrandIcon)},footer:{copyright:o(t.footerCopyright),layout:FOOTER_LAYOUTS.includes(t.footerLayout)?t.footerLayout:"auto",blurb:o(t.footerBlurb),blocks:footerBlockNames(t.footerBlocks),links:r.footer?.links||[],showMotionToggle:n.enabled,motionDefault:n.default,motionControl:n.control,class:o(t.footerClass),socialClass:o(t.footerSocialClass),look:FOOTER_LOOKS.includes(t.footerLook)?t.footerLook:"",cta:{text:o(t.footerCtaText),highlight:o(t.footerCtaHighlight),url:o(t.footerCtaUrl),sub:o(t.footerCtaSub)},watermark:o(t.footerWatermark),status:o(t.footerStatus),facts:String(t.footerFacts??"").split(`
3
+ `).map(s=>s.trim()).filter(Boolean).slice(0,FOOTER_FACTS_MAX),tagline:o(t.footerTagline),email:o(t.footerEmail),address:o(t.footerAddress),gradient:{from:o(t.footerGradFrom),to:o(t.footerGradTo)}},social:{twitter:o(t.socialTwitter),facebook:o(t.socialFacebook),instagram:o(t.socialInstagram),linkedin:o(t.socialLinkedin),github:o(t.socialGithub),youtube:o(t.socialYoutube)},smtp:{host:o(t.smtpHost),port:c(t.smtpPort,587)||587,user:o(t.smtpUser),pass:e(t.smtpPass),secure:t.smtpSecure===!0,allowInsecureTLS:t.smtpInsecureTLS===!0,fromAddress:o(t.smtpFromAddress),fromName:o(t.smtpFromName)},backToTop:{enabled:t.bttEnabled===!0,scrollThreshold:c(t.bttThreshold,300),position:e(t.bttPosition)||"bottom-right",offset:c(t.bttOffset,32),bottomOffset:c(t.bttBottomOffset,32),label:o(t.bttLabel),smooth:t.bttSmooth===!0},goToBottom:{enabled:t.gtbEnabled===!0,scrollThreshold:c(t.gtbThreshold,300),position:e(t.gtbPosition)||"bottom-right",offset:c(t.gtbOffset,32),bottomOffset:c(t.gtbBottomOffset,32),label:o(t.gtbLabel),smooth:t.gtbSmooth===!0},cookieConsent:{enabled:t.ccEnabled===!0,message:o(t.ccMessage),acceptAllText:o(t.ccAcceptAll),rejectAllText:o(t.ccRejectAll),customizeText:o(t.ccCustomize),savePreferencesText:o(t.ccSavePrefs),privacyPolicyText:o(t.ccPrivacyText),privacyPolicyUrl:o(t.ccPrivacyUrl),cookiePolicyText:o(t.ccCookieText),cookiePolicyUrl:o(t.ccCookieUrl),position:e(t.ccPosition)||"bottom",layout:e(t.ccLayout)||"bar",theme:e(t.ccTheme)||"dark",showFunctional:t.ccShowFunctional===!0,showAnalytics:t.ccShowAnalytics===!0,showMarketing:t.ccShowMarketing===!0,consentVersion:o(t.ccVersion)||"1.0",showSettingsLink:t.ccSettingsLink===!0,settingsLinkText:o(t.ccSettingsLinkText)||"Cookie settings"},breadcrumbs:{enabled:t.bcEnabled===!0,homeLabel:o(t.bcHomeLabel)||"Home",position:BREADCRUMB_POSITIONS.includes(t.bcPosition)?t.bcPosition:"TL",offsetX:c(t.bcOffsetX,8),offsetY:c(t.bcOffsetY,8)},motion:n}}export function siteUrlError(t){const r=e(t).trim().replace(/\/+$/,"");return r?/^https?:\/\//i.test(r)?/^https?:\/\/([a-z0-9.\-]+|\[[0-9a-f:.]+\])(:\d{1,5})?$/i.test(r)?"":"Just the address, like https://example.com - no page path after it.":"Start with https:// (or http://).":""}const d=t=>typeof t=="boolean"?t:e(t);export function snapshot(t){return JSON.stringify(Object.keys(t).sort().map(r=>[r,d(t[r])]))}export function changedTabs(t,r){const a=[];for(const[o,n]of Object.entries(TAB_FIELDS))n.some(s=>d(t[s])!==d(r[s]))&&a.push(o);return a}export function draftOf(t){return Object.fromEntries(Object.entries(t).filter(([r])=>!SECRET_FIELDS.includes(r)))}const g={footerMotionToggle:"mtEnabled",footerMotionDefault:"mtDefault",footerMotionControl:"mtControl"};export function formFromDraft(t,r={}){const a={...r};for(const[n,s]of Object.entries(g))n in a&&!(s in a)&&(a[s]=a[n]),delete a[n];const o={...t};for(const[n,s]of Object.entries(a))n in o&&!SECRET_FIELDS.includes(n)&&(o[n]=s);return o}export function settingsProblems(t,r={}){const a=[];return e(t.smtpHost).trim()?e(t.smtpFromAddress).trim()||a.push({tone:"warn",tab:"email",text:"No From address - mail has no sender and many servers refuse it."}):a.push({tone:"danger",tab:"email",text:"No SMTP host - mail goes to a throwaway test inbox and reaches no one (password resets, form notifications)."}),(t.ccEnabled===!0||e(r.googleAnalytics?.measurementId).trim())&&!e(t.ccPrivacyUrl).trim()&&a.push({tone:"warn",tab:"cookies",text:"The cookie banner is on but links to no privacy policy."}),a}export function describeCacheKey(t){const r=/^page:(.*?):m\d+:role([^:]*):/.exec(String(t||""));return r?{path:r[1]||"/",role:r[2]||"anon",page:!0}:{path:String(t||""),role:"",page:!1}}export function expiresIn(t,r=Date.now()){if(t==null)return"no expiry";const a=t-r;return a<=0?"expired":a<6e4?`${Math.round(a/1e3)}s`:a<36e5?`${Math.round(a/6e4)}m`:`${Math.round(a/36e5)}h`}export function footerForm(t={}){const r=formFromSettings(t);return Object.fromEntries(TAB_FIELDS.footer.map(a=>[a,r[a]]))}export function footerPayload(t){const{footer:r,social:a}=payloadFromForm(t);return delete r.links,delete r.showMotionToggle,delete r.motionDefault,delete r.motionControl,{footer:r,social:a}}export function siteSettingsForm(t={}){return Object.fromEntries(Object.entries(formFromSettings(t)).filter(([r])=>!TAB_FIELDS.footer.includes(r)&&!u.includes(r)))}export function siteSettingsPayload(...t){const{footer:r,social:a,favicon:o,backToTop:n,goToBottom:s,breadcrumbs:l,motion:m,...f}=payloadFromForm(...t);return f}export const APPEARANCE_TABS=["favicon","pageNavigation","breadcrumbs","motion","search"];const u=APPEARANCE_TABS.flatMap(t=>TAB_FIELDS[t]||[]);export function appearanceForm(t={}){const r=formFromSettings(t);return Object.fromEntries(u.map(a=>[a,r[a]]))}export function appearancePayload(t){const{favicon:r,backToTop:a,goToBottom:o,breadcrumbs:n,motion:s}=payloadFromForm(t);return{favicon:r,backToTop:a,goToBottom:o,breadcrumbs:n,motion:s}}
@@ -0,0 +1,80 @@
1
+ <!-- AI Assist › Settings. Bound with M.applyBindings - see admin/js/views/ai-assist-settings.js.
2
+ No page heading: the banner above is the heading; Save is a banner action and the unsaved bar. -->
3
+ <div class="aia">
4
+ <div class="aia-note dm-loading-slot" data-bind-hidden="!loading.value">Loading…</div>
5
+
6
+ <p class="aia-alert is-dirty" hidden data-bind-hidden="!dirty.value">
7
+ <span data-icon="edit-3" data-icon-size="16"></span>
8
+ <span>Unsaved changes - Save (Ctrl+S) to apply them.</span>
9
+ <span class="aia-spacer"></span>
10
+ <button type="button" class="btn btn-sm btn-ghost" data-on-click="discard">Discard</button>
11
+ <button type="button" class="btn btn-sm btn-primary" data-on-click="save" data-bind-disabled="saving.value || !canEdit">Save</button></p>
12
+ <p class="aia-alert" hidden data-bind-hidden="!problem.value">
13
+ <span data-icon="alert-triangle" data-icon-size="16"></span><span data-bind-text="problem.value"></span></p>
14
+ <p class="aia-alert" hidden data-bind-hidden="canEdit">
15
+ <span data-icon="lock" data-icon-size="16"></span><span>You can read these settings; changing them needs the Site Settings update permission.</span></p>
16
+
17
+ <div class="aia-body" hidden data-bind-hidden="loading.value">
18
+ <section class="card aia-card">
19
+ <h3 class="aia-title"><span data-icon="message-circle" data-icon-size="16" aria-hidden="true"></span> What AI answers know
20
+ <span data-help-title="What AI answers know"
21
+ data-help="What every AI answer on the site knows and the rules it keeps - your chat bot (Della, or the character you chose) when she answers a question your Knowledge does not cover, and the admin assistant. A chat launcher can add its own on top in Launchers. What you write here is sent to Claude, Anthropic's AI, with each question."></span></h3>
22
+ <label class="form-label" for="aia-context">About the business
23
+ <span data-help="Plain facts in your own words: what you do, where, your hours and prices if you want them given, how you like to sound. The AI answers only from this and the chat Knowledge, and says it does not know rather than guess."></span></label>
24
+ <textarea id="aia-context" class="form-input" rows="6" maxlength="4000" data-bind-disabled="!canEdit"
25
+ placeholder="We are a family plumbing firm in Leeds, open 8am to 6pm on weekdays. We fit and service boilers..." data-model="aiContext.value"></textarea>
26
+ <small class="aia-count" data-bind-text="contextCount.value"></small>
27
+ <label class="form-label" for="aia-rules">Rules
28
+ <span data-help="One per line: what an answer must never do or say. For example: Never quote a price. Do not give medical advice. Do not discuss other companies. A launcher's own rules add to these; they cannot lift one."></span></label>
29
+ <textarea id="aia-rules" class="form-input" rows="4" maxlength="2000" data-bind-disabled="!canEdit"
30
+ placeholder="Never quote a price - offer a free quote instead." data-model="aiRules.value"></textarea>
31
+ <small class="aia-count" data-bind-text="rulesCount.value"></small>
32
+ </section>
33
+
34
+ <section class="card aia-card">
35
+ <h3 class="aia-title"><span data-icon="sparkles" data-icon-size="16" aria-hidden="true"></span> Admin assistant</h3>
36
+ <label class="aia-switch"><input type="checkbox" class="form-switch" data-model="adminEnabled.value" data-bind-disabled="!canEdit">
37
+ Show the AI assistant inside the admin</label>
38
+ <p class="text-muted">A help and drafting panel for signed-in users. It follows their access to Tools and cannot save, publish or send.</p>
39
+ <div class="aia-grid" data-bind-hidden="!adminEnabled.value">
40
+ <div><label class="form-label" for="aia-admin-name">Assistant name</label>
41
+ <input id="aia-admin-name" class="form-input" maxlength="40" data-model="adminName.value" data-bind-disabled="!canEdit"></div>
42
+ <div><label class="form-label" for="aia-admin-character">Character artwork</label>
43
+ <select id="aia-admin-character" class="form-select" data-model="adminCharacter.value" data-bind-disabled="!canEdit"></select></div>
44
+ <div class="aia-wide"><label class="form-label" for="aia-admin-context">Admin assistant context
45
+ <span data-help="Anything the admin assistant should know that visitors' answers should not - how your team works, where things are kept."></span></label>
46
+ <textarea id="aia-admin-context" class="form-input" rows="3" maxlength="4000" data-model="adminContext.value" data-bind-disabled="!canEdit"></textarea></div>
47
+ <div class="aia-wide"><label class="form-label" for="aia-admin-rules">Admin assistant rules</label>
48
+ <textarea id="aia-admin-rules" class="form-input" rows="3" maxlength="2000" data-model="adminRules.value" data-bind-disabled="!canEdit"></textarea></div>
49
+ </div>
50
+ </section>
51
+
52
+ <section class="card aia-card" data-bind-hidden="!chatsOn">
53
+ <h3 class="aia-title"><span data-icon="sliders" data-icon-size="16" aria-hidden="true"></span> Chats</h3>
54
+ <p class="text-muted">How sure the bot must be before it answers, how long chats are kept and how staff names show are under the cog on the Chats tab.
55
+ Character artwork for launchers, chat windows and builders is in Site Settings.</p>
56
+ <div class="aia-links">
57
+ <a class="btn btn-sm btn-outline" href="#/ai-assist/chats?settings=1"><span data-icon="settings" data-icon-size="14"></span> Chat settings</a>
58
+ <a class="btn btn-sm btn-ghost" href="#/ai-assist/knowledge"><span data-icon="book-open" data-icon-size="14"></span> Knowledge</a>
59
+ <a class="btn btn-sm btn-ghost" href="#/launchers"><span data-icon="rocket" data-icon-size="14"></span> Launchers</a>
60
+ </div>
61
+ </section>
62
+ </div>
63
+ </div>
64
+ <style>
65
+ .aia { display: grid; gap: 1rem; max-width: 900px; }
66
+ .aia-body { display: grid; gap: 1rem; }
67
+ .aia [hidden] { display: none !important; }
68
+ .aia-note { margin: 0; color: var(--dm-text-muted); font-size: var(--dm-text-sm); }
69
+ .aia-alert { margin: 0; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding: .6rem .8rem; border-radius: var(--dm-radius-md);
70
+ background: color-mix(in srgb, var(--dm-warning) 12%, transparent); }
71
+ .aia-alert.is-dirty { background: color-mix(in srgb, var(--dm-primary) 12%, transparent); }
72
+ .aia-spacer { flex: 1; }
73
+ .aia-card { padding: 1rem 1.25rem; display: grid; gap: .5rem; }
74
+ .aia-title { margin: 0 0 .25rem; font-size: 1rem; display: flex; align-items: center; gap: .4rem; }
75
+ .aia-count { justify-self: end; color: var(--dm-text-muted); font-size: var(--dm-text-xs, .75rem); margin-top: -.25rem; }
76
+ .aia-switch { display: flex; align-items: center; gap: .5rem; cursor: pointer; }
77
+ .aia-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .75rem 1rem; }
78
+ .aia-wide { grid-column: 1 / -1; }
79
+ .aia-links { display: flex; flex-wrap: wrap; gap: .5rem; }
80
+ </style>
@@ -29,7 +29,7 @@
29
29
  <span data-bind-text="availText.value"></span>
30
30
  </label>
31
31
  <span data-help-title="Available for chats"
32
- data-help="While this is on and this screen is open, visitors who ask for a person are put through to you. Leave the screen (or switch this off) and, once nobody else is available, the bot asks visitors for their name and email instead, so nobody is left waiting."></span>
32
+ data-help="While this is on, visitors who ask for a person are put through to you - from any admin screen, not only this one, and a pop-up takes you to the chat. It is the same switch as the dot beside Account at the top of the admin, and it is remembered in this browser. Switch it off (or close the admin) and, once nobody else is available, the bot asks visitors for their name and email instead, so nobody is left waiting."></span>
33
33
  <a class="btn btn-sm btn-outline" href="#/launchers/knowledge" title="What the bot knows">
34
34
  <span data-icon="book-open" data-icon-size="14"></span> Knowledge
35
35
  </a>
@@ -69,18 +69,28 @@
69
69
  about something else, such as a help chat in the admin.</p>
70
70
 
71
71
  <h3>Answering visitors: Chats</h3>
72
- <p><strong>Content &gt; Chats</strong> is the inbox. Its sidebar badge counts the chats that need you: a visitor
72
+ <p>On a site with <strong>AI Assist</strong> (Pro), every chat is answered in <strong>AI Assist</strong> (Tools &gt;
73
+ Communication): its <strong>Chats</strong>, <strong>Knowledge</strong> and <strong>Settings</strong> tabs. Launchers stay
74
+ launchers - a chat launcher only hands its chats over. Without AI Assist the same inbox is <strong>Content &gt;
75
+ Chats</strong>, and old links to either lead to whichever the site has.</p>
76
+ <p>The inbox Its sidebar badge counts the chats that need you: a visitor
73
77
  <strong>Waiting</strong> for a person (a live dot; red after five minutes), a <strong>Message left</strong> when
74
78
  nobody was available, and chats with new messages since your reply. Waiting chats are listed first, the longest
75
79
  wait at the top.</p>
76
80
  <ul>
77
- <li><strong>Available for chats</strong> - on while this screen is open. That is what tells the bot someone can
78
- take a chat. Leave the screen or switch it off and, when nobody else is available, visitors are asked for
79
- their details instead. Admins get a notification when a visitor starts a chat, asks for a person or leaves a
81
+ <li><strong>Available for chats</strong> - the dot beside <strong>Account</strong> at the top of the admin (click it),
82
+ the switch at the top of the Account menu, and the switch on the inbox are one switch. While it is on, from any
83
+ admin screen, the bot knows someone can take a chat; it is remembered for your account in this browser and starts
84
+ off. Switch it off (or close the admin for more than a minute or so) and, when nobody else is available,
85
+ visitors are asked for their details instead. Only people who can reply to chats have it; staff who can read
86
+ chats see how many of you are available. Admins get a notification when a visitor starts a chat, asks for a person or leaves a
80
87
  message, and when the AI turns a question down. Each can be switched off, or sent to other people, in
81
88
  <strong>Notifications</strong> settings (Visitor chat started, Visitor chat, Chat question turned down).
82
- While the admin is open, each also pops up as a message with an <strong>Open Chats</strong> button, within
83
- 30 seconds; turn <strong>Chat pop-ups</strong> off in the Notifications settings cog for this browser.</li>
89
+ While the admin is open, each also pops up as a message with a button to the chat (<strong>Open in AI
90
+ Assist</strong>, or <strong>Open Chats</strong>), within 30 seconds. A chat starting and a visitor waiting for a
91
+ person stay on screen until someone jumps in: they close themselves in every admin once anyone replies, the
92
+ chat ends, or you read the notification. Turn <strong>Chat pop-ups</strong> off in the Notifications settings
93
+ cog for this browser.</li>
84
94
  <li>Click a chat to read it; type a reply and press <kbd>Ctrl</kbd>+<kbd>Enter</kbd> (or Send). Once you reply,
85
95
  the bot stays quiet in that chat. You can also reply to a chat the bot is handling.</li>
86
96
  <li>Right-click a chat (or its ⋮) to <strong>email the visitor</strong>, copy their address, open the page they
@@ -98,7 +108,7 @@
98
108
  know" and the offer of a person). What Claude is given with each question:</p>
99
109
  <ul>
100
110
  <li>your enabled Knowledge entries;</li>
101
- <li><strong>Site Settings &gt; General &gt; AI assistant</strong>: <strong>About the business</strong> (plain facts in
111
+ <li><strong>AI Assist &gt; Settings</strong>: <strong>About the business</strong> (plain facts in
102
112
  your words - what you do, where, hours, how you like to sound) and <strong>Rules</strong> (one per line: what an
103
113
  answer must never do or say, such as "Never quote a price");</li>
104
114
  <li>the launcher's own <strong>What the AI should know</strong> and <strong>Rules</strong> (Launchers, the chat
@@ -71,34 +71,14 @@
71
71
  </div>
72
72
  </div>
73
73
  </div>
74
- <div class="stx-card dm-settings-section">
75
- <div class="stx-card-title dm-section--info dm-settings-section-title"><span data-icon="message-circle" data-icon-size="16" aria-hidden="true"></span>AI assistant
76
- <span data-help-title="AI assistant" data-help="What the site's AI answers know and the rules they keep - today that is Della, the chat bot in a chat launcher, when she answers a question your Knowledge does not cover. Each chat launcher can add its own on top in Launchers. What you write here is sent to Claude (Anthropic) with each question, so leave out anything private."></span></div>
77
- <div class="stx-grid">
78
- <div class="stx-wide">
79
- <label class="form-label" for="stx-ai-context">About the business
80
- <span data-help="Plain facts in your own words: what you do, where, your hours and prices if you want them given, how you like to sound. The AI answers only from this and the chat Knowledge, and says it does not know rather than guess."></span></label>
81
- <textarea id="stx-ai-context" class="form-input" rows="5" maxlength="4000"
82
- placeholder="We are a family plumbing firm in Leeds, open 8am to 6pm on weekdays. We fit and service boilers..." data-model="aiContext.value"></textarea>
83
- </div>
84
- <div class="stx-wide">
85
- <label class="form-label" for="stx-ai-rules">Rules
86
- <span data-help="One per line: what an answer must never do or say. For example: Never quote a price. Do not give medical advice. Do not discuss other companies. A launcher's own rules add to these; they cannot lift one."></span></label>
87
- <textarea id="stx-ai-rules" class="form-input" rows="3" maxlength="2000"
88
- placeholder="Never quote a price - offer a free quote instead." data-model="aiRules.value"></textarea>
89
- </div>
90
- </div>
91
- </div>
92
- <div class="stx-card dm-settings-section">
93
- <div class="stx-card-title dm-settings-section-title"><span data-icon="sparkles" data-icon-size="16" aria-hidden="true"></span>Admin assistant</div>
94
- <div class="stx-setting"><label class="form-label" for="stx-admin-assistant">Enable AI assistant inside admin</label><input id="stx-admin-assistant" type="checkbox" class="form-switch" data-model="adminAssistantEnabled.value"></div>
95
- <p class="text-muted">A shared help and drafting panel for signed-in users. It follows their tool access and cannot save, publish or send. Uses the site's existing AI service and allowance.</p>
96
- <div class="stx-grid" data-bind-hidden="!adminAssistantEnabled.value">
97
- <div><label class="form-label" for="stx-admin-assistant-name">Assistant name</label><input id="stx-admin-assistant-name" class="form-input" maxlength="40" data-model="adminAssistantName.value"></div>
98
- <div><label class="form-label" for="stx-admin-assistant-character">Character artwork</label><select id="stx-admin-assistant-character" class="form-select" data-model="adminAssistantCharacter.value"><option value="">No character</option><option value="della">Della</option><option value="dash">Dash</option><option value="remy">Remy</option><option value="dot">Dot</option><option value="daisy">Daisy</option></select></div>
99
- <div class="stx-wide"><label class="form-label" for="stx-admin-assistant-context">Admin assistant context</label><textarea id="stx-admin-assistant-context" class="form-input" rows="3" maxlength="4000" data-model="adminAssistantContext.value"></textarea></div>
100
- <div class="stx-wide"><label class="form-label" for="stx-admin-assistant-rules">Admin assistant rules</label><textarea id="stx-admin-assistant-rules" class="form-input" rows="3" maxlength="2000" data-model="adminAssistantRules.value"></textarea></div>
74
+ <div class="stx-card stx-moved dm-settings-section">
75
+ <span data-icon="sparkles"></span>
76
+ <div class="stx-moved-text">
77
+ <strong>AI answers and the admin assistant</strong>
78
+ <small data-bind-hidden="!aiAssistOn.value">What AI answers know, the rules they keep and the admin assistant live in AI Assist › Settings.</small>
79
+ <small data-bind-hidden="aiAssistOn.value">AI answers in chats and the admin assistant come with AI Assist, in the Pro plan.</small>
101
80
  </div>
81
+ <a href="#/ai-assist/settings" class="btn btn-sm btn-ghost" data-bind-hidden="!aiAssistOn.value">Open AI Assist</a>
102
82
  </div>
103
83
  <div class="stx-card dm-settings-section">
104
84
  <div class="stx-card-title dm-settings-section-title"><span data-icon="smile" data-icon-size="16" aria-hidden="true"></span>Builders and Bots</div>
@@ -0,0 +1 @@
1
+ import{apiRequest as l}from"../api.js";import{addBannerAction as z}from"../lib/plugin-chrome.js";import{helpPopovers as G}from"../lib/help-popover.js";import{SHAPES as Q,whileLoading as X}from"../lib/loading.js";import{mountAiAssistTabs as x}from"../lib/ai-assist.js";import{characterOptions as Z,checkForm as P,formFromSettings as T,LIMITS as K,payloadFromForm as N,snapshot as k}from"../lib/ai-assist-settings-arrange.js";import{CHARACTERS as _}from"../../../public/js/characters.mjs";const C=/^\/ai-assist\/settings(\?.*)?$/;let n=null,U=!1;function ee(){U||!window.R?.use||(U=!0,R.use((r,i,o)=>!(C.test(i?.path||"")&&!C.test(r?.path||""))||!n?.dirty()?o():E.confirm("You have unsaved AI Assist settings. Leave anyway?").then(c=>{c?o():history.replaceState(null,"","#/ai-assist/settings")})),M.subscribe("router:afterChange",({to:r}={})=>{if(n&&!C.test(r?.path||"")){const i=n;n=null,i.dispose()}}))}export const aiAssistSettingsView={templateUrl:"/admin/js/templates/ai-assist-settings.html",async onMount(r){if(ee(),n){const e=n;n=null,e.dispose()}const i=[],o=e=>(i.push(e),e);let p=!1;const c=r.get(0),a=c.querySelector(".aia")||c,m=()=>!p&&a.isConnected;x(c,"settings",{chats:!0});const O=M.observable(!0);let u={},f=[],v={chats:!0};try{[u,f,v]=await X(a.querySelector(".dm-loading-slot"),Promise.all([l("/settings"),l("/auth/permissions").then(e=>e.permissions||[]).catch(()=>[]),l("/ai-assist").catch(()=>({chats:!0}))]),Q.rows)}catch(e){if(!m())return;a.querySelector(".dm-loading-slot").textContent=`Could not load the settings: ${e.message||e}`;return}if(!m())return;const h=f.includes("settings")||f.includes("settings.update");v?.chats===!1&&x(c,"settings",{chats:!1});const g=M.observable(T(u)),A=g.peek(),s=Object.fromEntries(Object.entries(A).map(([e,t])=>[e,M.observable(t)])),y=()=>Object.fromEntries(Object.entries(s).map(([e,t])=>[e,t.peek()])),j=()=>Object.fromEntries(Object.entries(s).map(([e,t])=>[e,t.value])),L=M.observable(k(A)),d=M.observable(!1),b=M.computed(()=>k(j())!==L.value),B=M.computed(()=>P(j())),D=M.computed(()=>`${s.aiContext.value.length} / ${K.context}`),H=M.computed(()=>`${s.aiRules.value.length} / ${K.rules}`),F=a.querySelector("#aia-admin-character");for(const e of Z(_))F.append(new Option(e.label,e.value));F.value=s.adminCharacter.peek();async function w(){if(d.peek()||!h)return;const e=P(y());if(e){E.toast(e,{type:"error"});return}d.value=!0;try{await l("/settings",{method:"PUT",body:JSON.stringify(N(y()))});const t=await l("/settings").catch(()=>({...u,...N(y())}));if(!m())return;u=t;const S=T(t);for(const[W,Y]of Object.entries(S))s[W].value=Y;g.value=S,L.value=k(S),window.dispatchEvent(new Event("admin-assistant:settings")),E.toast("AI Assist settings saved",{type:"success"})}catch(t){E.toast(`Not saved: ${t.message||t}`,{type:"error"})}finally{d.value=!1}}function V(){for(const[e,t]of Object.entries(g.peek()))s[e].value=t}O.value=!1;const J=M.applyBindings({...s,loading:O,dirty:b,saving:d,problem:B,contextCount:D,rulesCount:H,canEdit:h,chatsOn:v?.chats!==!1},a,{methods:{save:()=>w(),discard:()=>V()}});o(()=>J.dispose()),o(G(a,{position:"bottom"})),h&&z(r,{id:"ai-assist-save",icon:"save",title:"Save (Ctrl+S)",onClick:()=>w()});const $=e=>{!(e.ctrlKey||e.metaKey)||e.key!=="s"||(e.preventDefault(),e.stopImmediatePropagation(),w())};document.addEventListener("keydown",$,!0),o(()=>document.removeEventListener("keydown",$,!0));const q=e=>{b.peek()&&(e.preventDefault(),e.returnValue="")};window.addEventListener("beforeunload",q),o(()=>window.removeEventListener("beforeunload",q)),n={dirty:()=>b.peek(),dispose(){p=!0,i.splice(0).reverse().forEach(e=>{try{e()}catch{}})}},I.scan(a)}};