domma-cms 1.53.0 → 1.53.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/admin/js/lib/launchers-arrange.js +2 -2
- package/admin/js/views/launchers.js +7 -3
- package/docs/DommaFeatures.md +1 -1
- package/package.json +1 -1
- package/public/js/characters.mjs +1 -1
- package/public/js/launcher-settings.mjs +2 -2
- package/public/js/launchers.mjs +1 -1
- package/server/services/chat/settings.js +1 -0
- package/server/services/launchers.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.53.1] - 2026-11-10
|
|
4
|
+
|
|
5
|
+
- A chat launcher that uses Della can give her another name for that chat (**Call her**, under Use Della; `chat.characterName`, up to 40 characters). The name is shown on her answers and used by the AI, with Della's artwork - Dash on the jobs board. Empty keeps her own name.
|
|
6
|
+
|
|
3
7
|
## [1.53.0] - 2026-11-10
|
|
4
8
|
|
|
5
9
|
- Add an opt-in AI assistant inside admin, enabled through Site Settings, for tool help and copyable drafts. Conversations are separate from visitor chats and clear on account changes. Plugins can supply static, permission-scoped guidance and assistant identities. Requires the matching Manager AI mode update.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import{LAUNCHER_DEFAULTS as b,LAUNCHER_LIMITS as r,LAUNCHER_POSITION_LABEL as u,launcherColourCss as p,launcherReady as x,launcherSpot as f,launcherAvatar as y,normaliseLauncher as l,normaliseLauncherPath as g}from"../../../public/js/launcher-settings.mjs";export const FILTERS=["all","on","off"];const m={modal:"Modal",slideover:"Slideover",chat:"Chat"},w={page:"page",form:"form",block:"block"};export function describeAction(e){const t=e.action;return t.type==="chat"?`Chat${e.chat.bot?" (bot first)":""}`:t.ref?`${m[t.type]}: ${t.kind==="page"?t.ref:`${w[t.kind]} ${t.ref}`}`:`${m[t.type]}: nothing chosen yet`}export function describeWhere(e){const t=e.pages.paths.length,o=e.pages.mode==="all"?"every page":e.pages.mode==="only"?t?`${t} page rule${t===1?"":"s"}`:"no pages":`every page but ${t} rule${t===1?"":"s"}`,a=e.audience==="signed-in"?", signed-in only":e.audience==="signed-out"?", signed-out only":"",n=e.devices==="desktop"?", desktop only":e.devices==="phone"?", phones only":"";return`${o}${a}${n}`}export function launcherProblem(e){return x(e)?e.pages.mode==="only"&&!e.pages.paths.length?"Shows on no pages":"":"Choose what it opens"}export function launcherRow(e){const t=launcherProblem(e),o=e.triggerStyle==="icon-text",a=p(e.colours.background)||"var(--dm-primary)",n=p(e.colours.text)||"var(--dm-primary-text)";return{id:e.id,name:e.name,meta:`${e.showDisc?u[e.position]:"No disc - opened from links"} \xB7 ${describeAction(e)} \xB7 ${describeWhere(e)}`,label:e.label,icon:e.icon,pill:o,off:!e.enabled,on:e.enabled,problem:t,rowCls:[e.enabled?"":"is-off",t&&e.enabled?"is-warn":""].filter(Boolean).join(" "),discStyle:{"--lnx-bg":a,"--lnx-fg":n,"border-radius":o?"999px":`${Math.round(e.radius/e.size*100)}%`}}}export function arrangeLaunchers(e,{filter:t="all",query:o=""}={}){const a=String(o||"").trim().toLowerCase();return e.filter(n=>t==="on"?n.enabled:t==="off"?!n.enabled:!0).filter(n=>!a||[n.name,n.label,n.action.ref,n.action.title].some(i=>String(i||"").toLowerCase().includes(a)))}export function countLaunchers(e){const t=e.filter(o=>o.enabled).length;return{all:e.length,on:t,off:e.length-t}}export function moveItem(e,t,o){const a=[...e];if(t<0||t>=a.length||o<0||o>=a.length||t===o)return a;const[n]=a.splice(t,1);return a.splice(o,0,n),a}export function blankLauncher(e=[]){const t=new Set(e.map(a=>a.name));let o="New launcher";for(let a=2;t.has(o);a++)o=`New launcher ${a}`;return l({name:o})}export function duplicateLauncher(e,t=[]){const o=new Set(t.map(n=>n.name));let a=`${e.name} (copy)`.slice(0,r.nameMax);for(let n=2;o.has(a);n++)a=`${e.name} (copy ${n})`.slice(0,r.nameMax);return l({...structuredClone(e),id:"",name:a,enabled:!1})}export function formFromLauncher(e){const t=l(e);return{enabled:t.enabled,showDisc:t.showDisc,name:t.name,label:t.label,tooltipMode:t.tooltipMode,tooltip:t.tooltip,icon:t.icon,triggerStyle:t.triggerStyle,position:t.position,offsetX:t.offsetX,offsetY:t.offsetY,size:t.size,radius:t.radius,devices:t.devices,phoneOverride:t.phone.override,phonePosition:t.phone.position,phoneOffsetX:t.phone.offsetX,phoneOffsetY:t.phone.offsetY,phoneSize:t.phone.size,background:t.colours.background,text:t.colours.text,cls:t.class,pagesMode:t.pages.mode,paths:t.pages.paths.join(`
|
|
2
|
-
`),audience:t.audience,actionType:t.action.type,kind:t.action.kind,ref:t.action.ref,title:t.action.title,modalSize:t.action.size,side:t.action.side,width:t.action.width,customWidth:t.action.customWidth,widthUnit:t.action.widthUnit,modalHeight:t.action.height,customHeight:t.action.customHeight,heightUnit:t.action.heightUnit,useDella:t.chat.character==="della",greeting:t.chat.greeting,botName:t.chat.botName,bot:t.chat.bot,staff:t.chat.staff,askDetails:t.chat.askDetails,ai:t.chat.ai,aiUseSite:t.chat.aiUseSite,aiContext:t.chat.aiContext,aiRules:t.chat.aiRules,accent:t.chat.accent,accentText:t.chat.accentText,avatar:t.chat.avatar,chatSize:t.chat.size,chatWidth:t.chat.width,chatHeight:t.chat.height,chatResizable:t.chat.resizable,starters:t.chat.starters.join(`
|
|
3
|
-
`),aiMaxPerChat:t.chat.aiMaxPerChat,personButton:t.chat.personButton,keepOwn:t.chat.keepDays>0,keepDays:t.chat.keepDays||90,times:t.chat.times}}export function launcherFromForm(e,t=""){return l({id:t,enabled:e.enabled,showDisc:e.showDisc,name:e.name,label:e.label,tooltipMode:e.tooltipMode,tooltip:e.tooltip,icon:e.icon,triggerStyle:e.triggerStyle,position:e.position,offsetX:e.offsetX,offsetY:e.offsetY,size:e.size,radius:e.radius,devices:e.devices,phone:{override:e.phoneOverride,position:e.phonePosition,offsetX:e.phoneOffsetX,offsetY:e.phoneOffsetY,size:e.phoneSize},colours:{background:e.background,text:e.text},class:e.cls,pages:{mode:e.pagesMode,paths:String(e.paths||"").split(/\n+/)},audience:e.audience,action:{type:e.actionType,kind:e.kind,ref:e.ref,title:e.title,size:e.modalSize,side:e.side,width:e.width,customWidth:e.customWidth,widthUnit:e.widthUnit,height:e.modalHeight,customHeight:e.customHeight,heightUnit:e.heightUnit},chat:{character:e.useDella?"della":"",greeting:e.greeting,botName:e.botName,bot:e.bot,staff:e.staff,askDetails:e.askDetails,ai:e.ai,aiUseSite:e.aiUseSite,aiContext:e.aiContext,aiRules:e.aiRules,accent:e.accent,accentText:e.accentText,avatar:e.avatar,size:e.chatSize,width:e.chatWidth,height:e.chatHeight,resizable:e.chatResizable,starters:String(e.starters||"").split(`
|
|
2
|
+
`),audience:t.audience,actionType:t.action.type,kind:t.action.kind,ref:t.action.ref,title:t.action.title,modalSize:t.action.size,side:t.action.side,width:t.action.width,customWidth:t.action.customWidth,widthUnit:t.action.widthUnit,modalHeight:t.action.height,customHeight:t.action.customHeight,heightUnit:t.action.heightUnit,useDella:t.chat.character==="della",characterName:t.chat.characterName||"",greeting:t.chat.greeting,botName:t.chat.botName,bot:t.chat.bot,staff:t.chat.staff,askDetails:t.chat.askDetails,ai:t.chat.ai,aiUseSite:t.chat.aiUseSite,aiContext:t.chat.aiContext,aiRules:t.chat.aiRules,accent:t.chat.accent,accentText:t.chat.accentText,avatar:t.chat.avatar,chatSize:t.chat.size,chatWidth:t.chat.width,chatHeight:t.chat.height,chatResizable:t.chat.resizable,starters:t.chat.starters.join(`
|
|
3
|
+
`),aiMaxPerChat:t.chat.aiMaxPerChat,personButton:t.chat.personButton,keepOwn:t.chat.keepDays>0,keepDays:t.chat.keepDays||90,times:t.chat.times}}export function launcherFromForm(e,t=""){return l({id:t,enabled:e.enabled,showDisc:e.showDisc,name:e.name,label:e.label,tooltipMode:e.tooltipMode,tooltip:e.tooltip,icon:e.icon,triggerStyle:e.triggerStyle,position:e.position,offsetX:e.offsetX,offsetY:e.offsetY,size:e.size,radius:e.radius,devices:e.devices,phone:{override:e.phoneOverride,position:e.phonePosition,offsetX:e.phoneOffsetX,offsetY:e.phoneOffsetY,size:e.phoneSize},colours:{background:e.background,text:e.text},class:e.cls,pages:{mode:e.pagesMode,paths:String(e.paths||"").split(/\n+/)},audience:e.audience,action:{type:e.actionType,kind:e.kind,ref:e.ref,title:e.title,size:e.modalSize,side:e.side,width:e.width,customWidth:e.customWidth,widthUnit:e.widthUnit,height:e.modalHeight,customHeight:e.customHeight,heightUnit:e.heightUnit},chat:{character:e.useDella?"della":"",characterName:String(e.characterName||"").trim(),greeting:e.greeting,botName:e.botName,bot:e.bot,staff:e.staff,askDetails:e.askDetails,ai:e.ai,aiUseSite:e.aiUseSite,aiContext:e.aiContext,aiRules:e.aiRules,accent:e.accent,accentText:e.accentText,avatar:e.avatar,size:e.chatSize,width:e.chatWidth,height:e.chatHeight,resizable:e.chatResizable,starters:String(e.starters||"").split(`
|
|
4
4
|
`),aiMaxPerChat:e.aiMaxPerChat,personButton:e.personButton,keepDays:e.keepOwn?e.keepDays:0,times:e.times}})}export function checkLauncherForm(e){const t={},o={};if(String(e.name||"").trim()||(t.name="Give it a name - only you see it."),String(e.label||"").trim()||(t.label="Visitors need words for it: they are read out, and shown on a pill."),e.actionType!=="chat"){const i=String(e.ref||"").trim();i?e.kind==="page"&&(!g(i)||i.includes("*"))?t.ref="A page address starts with / - e.g. /about.":e.kind!=="page"&&!/^[a-z0-9][a-z0-9_-]*$/i.test(i)&&(t.ref="Choose one from the list."):o.ref="Nothing chosen yet - the launcher stays off the page until it opens something."}const a=String(e.paths||"").split(/\n+/).map(i=>i.trim()).filter(Boolean),n=a.filter(i=>!g(i));n.length?t.paths=`Not an address: ${n.slice(0,3).join(", ")}`:a.length>r.pathsMax?t.paths=`At most ${r.pathsMax} rules.`:e.pagesMode==="only"&&!a.length&&(o.paths="With no pages listed it shows nowhere.");for(const i of["background","text","accent","accentText"]){const s=String(e[i]||"").trim();s&&!p(s)&&(t[i]="A theme colour, or a hex colour such as #3366ff.")}if(e.actionType==="chat"){const i=String(e.starters||"").split(`
|
|
5
5
|
`).map(s=>s.trim()).filter(Boolean);if(i.length>r.startersMax?t.starters=`At most ${r.startersMax} questions.`:i.some(s=>s.length>r.starterMax)&&(t.starters=`Keep each to ${r.starterMax} characters.`),e.keepOwn&&!(Number(e.keepDays)>=1&&Number(e.keepDays)<=730)&&(t.keepDays="Between 1 and 730 days."),e.chatSize==="custom"){const[s,c]=r.chatWidth,[h,d]=r.chatHeight;Number(e.chatWidth)>=s&&Number(e.chatWidth)<=c||(t.chatWidth=`Between ${s} and ${c} pixels.`),Number(e.chatHeight)>=h&&Number(e.chatHeight)<=d||(t.chatHeight=`Between ${h} and ${d} pixels.`)}}return e.actionType==="chat"&&String(e.avatar||"").trim()&&!y(e.avatar)&&(t.avatar="Choose a picture from Media (an address on this site)."),{errors:t,warnings:o}}export function previewSpot(e,{vw:t=320,vh:o=200,scale:a=.5,phone:n=!1}={}){const i=n&&e.phoneOverride,s=Math.max(10,Math.round((i?e.phoneSize:e.size)*a)),c=e.triggerStyle==="icon-text"?Math.round(s*2.4):s,h=f(i?e.phonePosition:e.position,{w:c,h:s,vw:t,vh:o,offsetX:Math.round((i?e.phoneOffsetX:e.offsetX)*a),offsetY:Math.round((i?e.phoneOffsetY:e.offsetY)*a)});return{left:Math.max(0,Math.min(t-c,h.left)),top:Math.max(0,Math.min(o-s,h.top)),size:s,w:c}}export{b as LAUNCHER_DEFAULTS,u as LAUNCHER_POSITION_LABEL};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{apiRequest as
|
|
1
|
+
import{apiRequest as G,api as ye}from"../api.js";import{addBannerAction as we}from"../lib/plugin-chrome.js";import{helpPopovers as ke}from"../lib/help-popover.js";import{onceClosed as Ge,openMenuAt as Se,sidebarCount as Ce,viewLifetime as Ve}from"../lib/tool-kit.js";import{rowPlaceKeeper as Je}from"../lib/menu-drag.js";import{FILTERS as Qe,LAUNCHER_POSITION_LABEL as Te,arrangeLaunchers as Ze,blankLauncher as ea,checkLauncherForm as aa,countLaunchers as ta,duplicateLauncher as la,formFromLauncher as na,launcherFromForm as sa,launcherRow as ia,moveItem as oa,previewSpot as da}from"../lib/launchers-arrange.js";import{LAUNCHER_LIMITS as s,LAUNCHER_TOKENS as V,launcherChatAccentCss as ra,launcherColourCss as $e,launcherHref as J}from"../../../public/js/launcher-settings.mjs";const Me=/^#\/launchers\/?(\?.*)?$/,Ee="#/launchers",Q="launchers.filter",U="launchers.draft",ca=`
|
|
2
2
|
<div class="lnx-row" data-id="{{id}}" tabindex="0" data-bind-class="rowCls">
|
|
3
3
|
<span class="lnx-grip" title="Drag to reorder" aria-hidden="true"><span data-icon="menu" data-icon-size="14"></span></span>
|
|
4
4
|
<span class="lnx-disc" data-bind-class="pill && 'is-pill'" data-bind-style="discStyle" aria-hidden="true"><span data-icon="{{icon}}"></span><span data-bind-hidden="!pill">{{label}}</span></span>
|
|
@@ -9,7 +9,7 @@ import{apiRequest as V,api as ye}from"../api.js";import{addBannerAction as we}fr
|
|
|
9
9
|
</span>
|
|
10
10
|
<label class="lnx-switch" title="On or off"><input type="checkbox" class="form-switch lnx-toggle" data-bind-checked="on" aria-label="{{name}} on or off"></label>
|
|
11
11
|
<button type="button" class="lnx-kebab" aria-label="Actions for {{name}}" title="Actions">\u22EE</button>
|
|
12
|
-
</div>`,c={triggerStyle:[["icon","Disc - icon only"],["icon-text","Pill - icon and label"]],tooltipMode:[["label","The label"],["custom","Words of its own"],["off","None"]],actionType:[["modal","A page, form or block, in a modal"],["slideover","A page, form or block, in a slideover"],["chat","A chat"]],kind:[["page","Page"],["form","Form"],["block","Block"]],modalSize:[["xs","Extra small (320px)"],["sm","Small (400px)"],["md","Medium (600px)"],["lg","Large (800px)"],["xl","Extra large (1140px)"],["xxl","Huge (1400px)"],["full","Nearly full width (90%)"],["screen","Full screen"],["custom","Custom\u2026"]],modalHeight:[["auto","Fit the page"],["sm","Short (40% of the window)"],["md","Medium (60%)"],["lg","Tall (80%)"],["full","Nearly full height (90%)"],["custom","Custom\u2026"]],widthUnit:[["px","px"],["%","% of window"]],heightUnit:[["vh","% of window"],["px","px"]],side:[["right","Right"],["left","Left"]],width:[["sm","Narrow (360px)"],["md","Medium (480px)"],["lg","Wide (640px)"],["xl","Extra wide (860px)"]],devices:[["all","Phones and desktops"],["desktop","Desktops only"],["phone","Phones only"]],pagesMode:[["all","Every page"],["only","Only these pages"],["except","Every page except these"]],audience:[["everyone","Everyone"],["signed-in","Signed-in people only"],["signed-out","Signed-out visitors only"]],askDetails:[["offline","When nobody is there to answer"],["always","Before the chat starts"],["never","Never"]],times:[["time","The time (09:42)"],["datetime","The date and time (10 Nov, 09:42)"],["none","Nothing"]],personButton:[["below","A button under the conversation"],["header","An icon in the chat heading"]],chatSize:[["sm","Small (340 x 500)"],["md","Medium (400 x 600)"],["lg","Large (480 x 720)"],["custom","Custom\u2026"]],background:[["","Theme (primary)"],...
|
|
12
|
+
</div>`,c={triggerStyle:[["icon","Disc - icon only"],["icon-text","Pill - icon and label"]],tooltipMode:[["label","The label"],["custom","Words of its own"],["off","None"]],actionType:[["modal","A page, form or block, in a modal"],["slideover","A page, form or block, in a slideover"],["chat","A chat"]],kind:[["page","Page"],["form","Form"],["block","Block"]],modalSize:[["xs","Extra small (320px)"],["sm","Small (400px)"],["md","Medium (600px)"],["lg","Large (800px)"],["xl","Extra large (1140px)"],["xxl","Huge (1400px)"],["full","Nearly full width (90%)"],["screen","Full screen"],["custom","Custom\u2026"]],modalHeight:[["auto","Fit the page"],["sm","Short (40% of the window)"],["md","Medium (60%)"],["lg","Tall (80%)"],["full","Nearly full height (90%)"],["custom","Custom\u2026"]],widthUnit:[["px","px"],["%","% of window"]],heightUnit:[["vh","% of window"],["px","px"]],side:[["right","Right"],["left","Left"]],width:[["sm","Narrow (360px)"],["md","Medium (480px)"],["lg","Wide (640px)"],["xl","Extra wide (860px)"]],devices:[["all","Phones and desktops"],["desktop","Desktops only"],["phone","Phones only"]],pagesMode:[["all","Every page"],["only","Only these pages"],["except","Every page except these"]],audience:[["everyone","Everyone"],["signed-in","Signed-in people only"],["signed-out","Signed-out visitors only"]],askDetails:[["offline","When nobody is there to answer"],["always","Before the chat starts"],["never","Never"]],times:[["time","The time (09:42)"],["datetime","The date and time (10 Nov, 09:42)"],["none","Nothing"]],personButton:[["below","A button under the conversation"],["header","An icon in the chat heading"]],chatSize:[["sm","Small (340 x 500)"],["md","Medium (400 x 600)"],["lg","Large (480 x 720)"],["custom","Custom\u2026"]],background:[["","Theme (primary)"],...V.map(i=>[i,i.charAt(0).toUpperCase()+i.slice(1)]),["custom","Custom hex\u2026"]],foreground:[["","Theme (reads on the background)"],...V.map(i=>[i,i.charAt(0).toUpperCase()+i.slice(1)]),["custom","Custom hex\u2026"]]},ha=["TL","TC","TR","ML","","MR","BL","BC","BR"],h=i=>i.map(([p,A])=>`<option value="${p}">${A}</option>`).join(""),Ae=i=>ha.map(p=>p?`<button type="button" data-pos="${p}" data-bind-class="${i}.value === '${p}' && 'is-on'" title="${Te[p]}" aria-label="${Te[p]}">${p}</button>`:'<button type="button" class="lnx-corner-mid" tabindex="-1" aria-hidden="true"></button>').join(""),pa=`
|
|
13
13
|
<div class="lnx-form">
|
|
14
14
|
<div class="lnx-section">
|
|
15
15
|
<h6><span data-icon="message-circle" data-icon-size="14"></span> The disc</h6>
|
|
@@ -140,6 +140,10 @@ import{apiRequest as V,api as ye}from"../api.js";import{addBannerAction as we}fr
|
|
|
140
140
|
<div class="lnx-field" style="grid-column: 1 / -1">
|
|
141
141
|
<label class="lnx-check"><input id="lnx-f-della" type="checkbox" class="form-switch" data-model="useDella.value"> Use Della</label>
|
|
142
142
|
<small>Use Della's name, portrait and animated character. Site Settings controls visibility and motion. Your custom name and picture are kept when this is switched off.</small>
|
|
143
|
+
<div data-bind-hidden="!useDella.value">
|
|
144
|
+
<label class="form-label" for="lnx-f-charname">Call her <span data-help-title="Call her" data-help="Leave empty and she is Della. Give her another name for this chat - Dash on a jobs board, say - and that name is shown and used in her answers, with Della's artwork."></span></label>
|
|
145
|
+
<input id="lnx-f-charname" class="form-input" maxlength="${s.botNameMax}" placeholder="Della" data-model="characterName.value">
|
|
146
|
+
</div>
|
|
143
147
|
<label class="form-label" for="lnx-f-greeting">Greeting <span data-help-title="Greeting" data-help="The first message a visitor sees when the chat opens. Words in braces are filled in from the visitor's own clock: {greeting} (Good morning / afternoon / evening), {timeofday} (morning / afternoon / evening), {day} (Monday...), {date} (10 November), {time} (09:42), {botname} and {site}. For example: {greeting}! I'm {botname} - how can I help this {timeofday}?"></span></label>
|
|
144
148
|
<textarea id="lnx-f-greeting" class="form-input" rows="2" maxlength="${s.greetingMax}" data-model="greeting.value"></textarea>
|
|
145
149
|
</div>
|
|
@@ -301,4 +305,4 @@ import{apiRequest as V,api as ye}from"../api.js";import{addBannerAction as we}fr
|
|
|
301
305
|
<button type="button" class="btn btn-sm btn-primary" data-on-click="save" data-bind-disabled="cannot.value">
|
|
302
306
|
<span data-icon="check" data-icon-size="13"></span> <span data-bind-text="saveText"></span></button>
|
|
303
307
|
</div>
|
|
304
|
-
</div>`,Z=i=>String(i??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");function ua(i){const p=document.createElement("template");return p.innerHTML=i.trim(),p.content.firstElementChild}const T=i=>i?G.includes(i)?i:"custom":"",x=Ge(Me),ee={list:()=>V("/launchers/items",{method:"GET"}),save:i=>V("/launchers/items",{method:"PUT",body:JSON.stringify({launchers:i})}),patch:(i,p)=>V(`/launchers/items/${encodeURIComponent(i)}`,{method:"PATCH",body:JSON.stringify(p)})};export const launchersView={templateUrl:"/admin/js/templates/launchers.html",async onMount(i){x.reset();const p=i.get(0).querySelector(".lnx")||i.get(0),A=()=>p.isConnected&&Me.test(location.hash),u=M.observable([]),ae=M.observable(!0),F=M.observable(""),B=M.observable(!0);let te="all";try{te=Qe.includes(S.get(Q))?S.get(Q):"all"}catch{}const $=M.observable(te),W=M.observable("");x.add(M.effect(()=>{const a=$.value;try{S.set(Q,a)}catch{}}));const K=M.observable([]);x.add(M.effect(()=>{K.value=Ze(u.value,{filter:$.value,query:W.value}).map(ia)}));const Oe=M.computed(()=>ta(u.value)),ze=M.computed(()=>u.value.length?"No launchers match.":"No launchers yet - New launcher in the banner makes one."),le=M.computed(()=>u.value.length>1&&($.value!=="all"||!!W.value.trim())),O=a=>u.peek().find(t=>t.id===a);let L=null;const Ne=async()=>{if(L)return L;const[a,t]=await Promise.all([ye.forms.list().catch(()=>[]),ye.blocks.list().catch(()=>[])]);return L={forms:(Array.isArray(a)?a:[]).map(l=>({value:l.slug,text:l.title?`${l.title} (${l.slug})`:l.slug})),blocks:(Array.isArray(t)?t:[]).map(l=>({value:l.name,text:l.description?`${l.name} - ${l.description}`:l.name}))},L};async function Le(){try{const a=await ee.list();if(!A())return;u.value=Array.isArray(a?.launchers)?a.launchers:[],F.value="",B.value=!0}catch(a){const t=String(a?.message||a);/switched off/i.test(t)?B.value=!1:F.value=`Could not load the launchers: ${t}`}finally{ae.value=!1}}async function P(a,t){try{const l=await ee.save(a);return A()&&(u.value=l.launchers),Ce(Ee),t&&E.toast(t,{type:"success"}),l.launchers}catch(l){return E.toast(`Not saved: ${l.message||l}`,{type:"error"}),null}}async function q(a,t){try{const l=await ee.patch(a.id,{enabled:t});u.value=u.peek().map(m=>m.id===a.id?l.launcher:m),Ce(Ee),E.toast(`"${a.name}" ${t?"switched on":"switched off"}.`,{type:"success",duration:2e3})}catch(l){E.toast(`Not changed: ${l.message||l}`,{type:"error"}),u.value=[...u.peek()]}}async function Pe(a){const t=u.peek(),l=t.findIndex(o=>o.id===a.id),m=la(a,t);await P([...t.slice(0,l+1),m,...t.slice(l+1)],`Duplicated as "${m.name}" - switched off until you are ready.`)}async function Ie(a){await E.confirm(`Delete the launcher "${Z(a.name)}"? It goes from every page. This cannot be undone.`)&&await P(u.peek().filter(t=>t.id!==a.id),"Launcher deleted.")}function He(a){if(a.action.type==="chat"){E.toast("A chat has nothing to open on its own - see it on any page it shows on.",{type:"info"});return}if(!a.action.ref){E.toast("Choose what it opens first.",{type:"warning"});return}window.open(`/_launcher/${encodeURIComponent(a.id)}`,"_blank","noopener")}function Re(a){const t=O(a);return t?[{header:t.name},{label:"Edit",icon:"edit",action:()=>z(t.id)},t.enabled?{label:"Switch off",icon:"pause",action:()=>q(t,!1)}:{label:"Switch on",icon:"play",action:()=>q(t,!0)},{label:"Open what it shows",icon:"external-link",action:()=>He(t)},{type:"divider"},{label:"Duplicate",icon:"copy",action:()=>Pe(t)},{type:"divider"},{label:"Delete\u2026",icon:"trash",danger:!0,action:()=>Ie(t)}]:[]}let w=null;const Y=new Set;function Ue(a,t,l){const m=a.close.bind(a);let o=!1,b=!1;return a.close=async r=>{if(!o&&r!==!0&&t()){if(b)return;b=!0;const N=await E.confirm(l);if(b=!1,!N)return}return o=!0,m()},()=>{o=!0}}async function z(a=null,t=null){const l=a?O(a):null;if(a&&!l){E.toast("That launcher is no longer there.",{type:"warning"});return}if(w){E.toast("Finish the launcher you have open first.",{type:"info"});return}const m=!l,o=na(l||ea(u.peek())),b={...o,refPage:o.kind==="page"?o.ref:"",refForm:o.kind==="form"?o.ref:"",refBlock:o.kind==="block"?o.ref:"",bgChoice:T(o.background),bgHex:T(o.background)==="custom"?o.background:"",fgChoice:T(o.text),fgHex:T(o.text)==="custom"?o.text:"",accentChoice:T(o.accent),accentHex:T(o.accent)==="custom"?o.accent:"",accentTextChoice:T(o.accentText),accentTextHex:T(o.accentText)==="custom"?o.accentText:"",...t||{}};delete b.ref,delete b.background,delete b.text,delete b.accent,delete b.accentText;const r=Object.fromEntries(Object.entries(b).map(([e,d])=>[e,M.observable(d)])),N=()=>Object.fromEntries(Object.keys(r).map(e=>[e,r[e].peek()])),de=e=>JSON.stringify(Object.fromEntries(Object.entries(e).map(([d,n])=>[d,typeof n=="boolean"?n:String(n??"")]))),Be=de(b),re=()=>de(N())!==Be||!!t,ce=e=>{const d=e.actionType==="chat"?"page":e.kind;return{...e,kind:d,ref:d==="form"?e.refForm:d==="block"?e.refBlock:String(e.refPage||"").trim(),background:e.bgChoice==="custom"?String(e.bgHex||"").trim():e.bgChoice,text:e.fgChoice==="custom"?String(e.fgHex||"").trim():e.fgChoice,accent:e.accentChoice==="custom"?String(e.accentHex||"").trim():e.accentChoice,accentText:e.accentTextChoice==="custom"?String(e.accentTextHex||"").trim():e.accentTextChoice}},H=()=>ce(Object.fromEntries(Object.keys(r).map(e=>[e,r[e].value]))),j=M.computed(()=>aa(H())),R=M.observable(!1),he=(e,d)=>{const n=da({...e,size:Number(e.size),offsetX:Number(e.offsetX),offsetY:Number(e.offsetY),phoneSize:Number(e.phoneSize),phoneOffsetX:Number(e.phoneOffsetX),phoneOffsetY:Number(e.phoneOffsetY)},d?{vw:120,vh:220,scale:.5,phone:!0}:{vw:320,vh:200,scale:.5}),f=e.triggerStyle==="icon-text"&&!d;return{left:`${n.left}px`,top:`${n.top}px`,height:`${n.size}px`,width:f?"auto":`${n.size}px`,padding:f?"0 6px":"0","border-radius":f?"999px":`${Math.round(Math.min(Number(e.radius),Number(e.size)/2)/Number(e.size)*100)}%`,"--lnx-bg":$e(e.background)||"var(--dm-primary)","--lnx-fg":$e(e.text)||"var(--dm-primary-text)"}},pe={...r,saving:R,err:M.computed(()=>j.value.errors),warn:M.computed(()=>j.value.warnings),cannot:M.computed(()=>R.value||Object.keys(j.value.errors).length>0),maxRadius:M.computed(()=>Math.floor(Number(r.size.value)/2)),previewStyle:M.computed(()=>he(H(),!1)),phonePreviewStyle:M.computed(()=>he(H(),!0)),botInitial:M.computed(()=>(String(r.botName.value||"").trim()[0]||"?").toUpperCase()),avatarPreview:M.computed(()=>{const e=ra(H());return{background:e.accent||"var(--dm-primary)",color:e.accentText||"var(--dm-primary-text, #fff)"}}),saveText:m?"Create launcher":"Save",linkHref:m?"":J(l.id),linkText:m?"Create the launcher first - then it has a link":J(l.id)},We=M.effect(()=>{const e=Math.floor(Number(r.size.value)/2);Number(r.radius.peek())>e&&(r.radius.value=e)}),ue=(e,d,n)=>{let f=e.peek();return M.effect(()=>{const C=e.value;C!==f&&(f=C,d.value=n(C))})},Ke=ue(r.widthUnit,r.customWidth,e=>e==="%"?90:900),qe=ue(r.heightUnit,r.customHeight,e=>e==="px"?600:70),k=E.slideover({title:m?"New launcher":`Edit ${Z(l.name)}`,size:"lg",position:"right"}),v=ua(pa),me=await Ne().catch(()=>({forms:[],blocks:[]})),fe=(e,d,n)=>{const f=document.createElement("option");f.value="",f.textContent=d.length?"Choose\u2026":"None yet",e.appendChild(f);const C=n&&!d.some(U=>U.value===n)?[...d,{value:n,text:`${n} (missing)`}]:d;for(const U of C){const X=document.createElement("option");X.value=U.value,X.textContent=U.text,e.appendChild(X)}};fe(v.querySelector(".lnx-form-select"),me.forms,b.refForm),fe(v.querySelector(".lnx-block-select"),me.blocks,b.refBlock);let be=()=>{};async function ve(){if(!pe.cannot.peek()){R.value=!0;try{const e=sa(ce(N()),l?.id||""),d=u.peek(),n=m?[...d,e]:d.map(C=>C.id===l.id?e:C);if(!await P(n,m?`Created "${e.name}".`:"Saved."))return;be(),k.close()}finally{R.value=!1}}}k.element.appendChild(v);const Ye=ke(v),je=M.applyBindings(pe,v,{methods:{save:ve,cancel:()=>k.close()}}),_e=e=>{(e.ctrlKey||e.metaKey)&&e.key==="Enter"&&(e.preventDefault(),ve())};v.addEventListener("keydown",_e);const xe=async e=>{const d=e.target.closest(".lnx-corners button[data-pos]");if(d){const n=d.closest(".lnx-corners-phone")?"phonePosition":"position";r[n].value=d.dataset.pos;return}if(e.target.closest(".lnx-pick-icon")){const{openIconPicker:n}=await import("../lib/card-builder.js");n(f=>{r.icon.value=f});return}if(e.target.closest(".lnx-copy-link")&&!m){let n=!1;try{n=await _.copyToClipboard(J(l.id))!==!1}catch{}E.toast(n?"Link copied.":"Could not copy - select the link and copy it.",{type:n?"success":"warning"});return}if(e.target.closest(".lnx-pick-avatar")){const{pickMedia:n}=await import("../lib/media-picker.js"),f=await n({title:"Choose the bot's picture",current:r.avatar.peek()});f&&(r.avatar.value=String(f).replace(/^https?:\/\/[^/]+/i,""));return}if(e.target.closest(".lnx-clear-avatar")){r.avatar.value="";return}if(e.target.closest(".lnx-pick-page")){const{openPagePicker:n}=await import("../lib/page-picker.js");n(f=>{r.refPage.value=f})}};v.addEventListener("click",xe);const Xe=M.effect(()=>{const e=r.icon.value;v.querySelectorAll(".lnx-preview-disc").forEach(d=>{const n=document.createElement("span");n.setAttribute("data-icon",e||"message-circle"),n.className="lnx-preview-icon",d.querySelector(".lnx-preview-icon")?.replaceWith(n),I.scan(d)})}),ge={id:l?.id??null,dirty:re,values:N};w=ge,Y.add(k),Ve(k,()=>{je.dispose(),Ye(),We?.(),Ke?.(),qe?.(),Xe?.(),v.removeEventListener("click",xe),Y.delete(k),w===ge&&(w=null)}),be=Ue(k,re,"Discard the changes you have not saved?"),I.scan(v),k.open(),v.querySelector("#lnx-f-name")?.focus()}const g=p.querySelector(".lnx-list");g.innerHTML=ca;const De=M.applyBindings({launchers:u,loading:ae,loadError:F,toolOn:B,filter:$,query:W,rows:K,counts:Oe,emptyText:ze,dragNote:le},p,{methods:{showAll:()=>{$.value="all"},showOn:()=>{$.value="on"},showOff:()=>{$.value="off"}}});x.add(()=>De.dispose()),x.add(ke(p,{position:"bottom"})),x.add(M.effect(()=>{K.value,requestAnimationFrame(()=>{p.isConnected&&I.scan(g)})}));const Fe=E.contextMenu(g,{cursor:"glyph",match:".lnx-row",inherit:!1,density:"compact",items:a=>Re(a.dataset.id)});x.add(()=>Fe?.destroy?.());const ne=a=>{const t=a.target.closest(".lnx-row");if(!t||a.target.closest(".lnx-switch"))return;const l=a.target.closest(".lnx-kebab");if(l){Se(l);return}z(t.dataset.id)},se=a=>{const t=a.target.closest(".lnx-toggle"),l=t?.closest(".lnx-row"),m=l&&O(l.dataset.id);m&&q(m,t.checked)},ie=a=>{const t=a.target.closest(".lnx-row");t&&(a.key==="F10"&&a.shiftKey?(a.preventDefault(),Se(t)):a.key==="Enter"&&a.target===t&&z(t.dataset.id))};if(g.addEventListener("click",ne),g.addEventListener("change",se),g.addEventListener("keydown",ie),x.add(()=>{g.removeEventListener("click",ne),g.removeEventListener("change",se),g.removeEventListener("keydown",ie)}),typeof E.sortable=="function"){const a=Je(),t=E.sortable(g,{items:".lnx-row",handle:".lnx-grip",key:null,keyboard:!1,onStart:a.start,onEnd:({item:l})=>a.restore(l),onSort:({item:l,from:m,to:o})=>{if(a.restore(l),le.peek()){E.toast("Clear the search and show All to reorder.",{type:"info"}),u.value=[...u.peek()];return}const b=oa(u.peek(),m,o);u.value=b,P(b)}});x.add(()=>t.destroy())}we(i,{id:"launchers-new",icon:"plus",title:"New launcher",onClick:()=>z()}),we(i,{id:"launchers-chats",icon:"message-square",title:"Chats - the conversations from chat launchers",onClick:()=>{location.hash="#/launchers/chats"}});const oe=a=>{w?.dirty()&&(a.preventDefault(),a.returnValue="")};if(window.addEventListener("beforeunload",oe),x.add(()=>window.removeEventListener("beforeunload",oe)),x.add(()=>{if(w?.dirty())try{S.set(D,{id:w.id,values:w.values(),at:new Date().toISOString()})}catch{}[...Y].forEach(a=>{try{a.close(!0)}catch{}})}),I.scan(p),await Le(),!A())return;let y=null;try{y=S.get(D)}catch{}if(y?.values){try{S.remove?S.remove(D):S.set(D,null)}catch{}const a=y.id&&O(y.id)?`your changes to "${Z(O(y.id).name)}"`:"the new launcher you started";await E.confirm(`You left ${a} unsaved. Pick up where you left off?`)&&A()&&z(y.id&&O(y.id)?y.id:null,y.values)}}};
|
|
308
|
+
</div>`,Z=i=>String(i??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");function ua(i){const p=document.createElement("template");return p.innerHTML=i.trim(),p.content.firstElementChild}const T=i=>i?V.includes(i)?i:"custom":"",x=Ve(Me),ee={list:()=>G("/launchers/items",{method:"GET"}),save:i=>G("/launchers/items",{method:"PUT",body:JSON.stringify({launchers:i})}),patch:(i,p)=>G(`/launchers/items/${encodeURIComponent(i)}`,{method:"PATCH",body:JSON.stringify(p)})};export const launchersView={templateUrl:"/admin/js/templates/launchers.html",async onMount(i){x.reset();const p=i.get(0).querySelector(".lnx")||i.get(0),A=()=>p.isConnected&&Me.test(location.hash),u=M.observable([]),ae=M.observable(!0),F=M.observable(""),B=M.observable(!0);let te="all";try{te=Qe.includes(S.get(Q))?S.get(Q):"all"}catch{}const $=M.observable(te),W=M.observable("");x.add(M.effect(()=>{const a=$.value;try{S.set(Q,a)}catch{}}));const K=M.observable([]);x.add(M.effect(()=>{K.value=Ze(u.value,{filter:$.value,query:W.value}).map(ia)}));const Oe=M.computed(()=>ta(u.value)),ze=M.computed(()=>u.value.length?"No launchers match.":"No launchers yet - New launcher in the banner makes one."),le=M.computed(()=>u.value.length>1&&($.value!=="all"||!!W.value.trim())),O=a=>u.peek().find(t=>t.id===a);let L=null;const Ne=async()=>{if(L)return L;const[a,t]=await Promise.all([ye.forms.list().catch(()=>[]),ye.blocks.list().catch(()=>[])]);return L={forms:(Array.isArray(a)?a:[]).map(l=>({value:l.slug,text:l.title?`${l.title} (${l.slug})`:l.slug})),blocks:(Array.isArray(t)?t:[]).map(l=>({value:l.name,text:l.description?`${l.name} - ${l.description}`:l.name}))},L};async function Le(){try{const a=await ee.list();if(!A())return;u.value=Array.isArray(a?.launchers)?a.launchers:[],F.value="",B.value=!0}catch(a){const t=String(a?.message||a);/switched off/i.test(t)?B.value=!1:F.value=`Could not load the launchers: ${t}`}finally{ae.value=!1}}async function P(a,t){try{const l=await ee.save(a);return A()&&(u.value=l.launchers),Ce(Ee),t&&E.toast(t,{type:"success"}),l.launchers}catch(l){return E.toast(`Not saved: ${l.message||l}`,{type:"error"}),null}}async function q(a,t){try{const l=await ee.patch(a.id,{enabled:t});u.value=u.peek().map(m=>m.id===a.id?l.launcher:m),Ce(Ee),E.toast(`"${a.name}" ${t?"switched on":"switched off"}.`,{type:"success",duration:2e3})}catch(l){E.toast(`Not changed: ${l.message||l}`,{type:"error"}),u.value=[...u.peek()]}}async function Pe(a){const t=u.peek(),l=t.findIndex(o=>o.id===a.id),m=la(a,t);await P([...t.slice(0,l+1),m,...t.slice(l+1)],`Duplicated as "${m.name}" - switched off until you are ready.`)}async function Ie(a){await E.confirm(`Delete the launcher "${Z(a.name)}"? It goes from every page. This cannot be undone.`)&&await P(u.peek().filter(t=>t.id!==a.id),"Launcher deleted.")}function He(a){if(a.action.type==="chat"){E.toast("A chat has nothing to open on its own - see it on any page it shows on.",{type:"info"});return}if(!a.action.ref){E.toast("Choose what it opens first.",{type:"warning"});return}window.open(`/_launcher/${encodeURIComponent(a.id)}`,"_blank","noopener")}function De(a){const t=O(a);return t?[{header:t.name},{label:"Edit",icon:"edit",action:()=>z(t.id)},t.enabled?{label:"Switch off",icon:"pause",action:()=>q(t,!1)}:{label:"Switch on",icon:"play",action:()=>q(t,!0)},{label:"Open what it shows",icon:"external-link",action:()=>He(t)},{type:"divider"},{label:"Duplicate",icon:"copy",action:()=>Pe(t)},{type:"divider"},{label:"Delete\u2026",icon:"trash",danger:!0,action:()=>Ie(t)}]:[]}let w=null;const j=new Set;function Re(a,t,l){const m=a.close.bind(a);let o=!1,b=!1;return a.close=async r=>{if(!o&&r!==!0&&t()){if(b)return;b=!0;const N=await E.confirm(l);if(b=!1,!N)return}return o=!0,m()},()=>{o=!0}}async function z(a=null,t=null){const l=a?O(a):null;if(a&&!l){E.toast("That launcher is no longer there.",{type:"warning"});return}if(w){E.toast("Finish the launcher you have open first.",{type:"info"});return}const m=!l,o=na(l||ea(u.peek())),b={...o,refPage:o.kind==="page"?o.ref:"",refForm:o.kind==="form"?o.ref:"",refBlock:o.kind==="block"?o.ref:"",bgChoice:T(o.background),bgHex:T(o.background)==="custom"?o.background:"",fgChoice:T(o.text),fgHex:T(o.text)==="custom"?o.text:"",accentChoice:T(o.accent),accentHex:T(o.accent)==="custom"?o.accent:"",accentTextChoice:T(o.accentText),accentTextHex:T(o.accentText)==="custom"?o.accentText:"",...t||{}};delete b.ref,delete b.background,delete b.text,delete b.accent,delete b.accentText;const r=Object.fromEntries(Object.entries(b).map(([e,d])=>[e,M.observable(d)])),N=()=>Object.fromEntries(Object.keys(r).map(e=>[e,r[e].peek()])),de=e=>JSON.stringify(Object.fromEntries(Object.entries(e).map(([d,n])=>[d,typeof n=="boolean"?n:String(n??"")]))),Be=de(b),re=()=>de(N())!==Be||!!t,ce=e=>{const d=e.actionType==="chat"?"page":e.kind;return{...e,kind:d,ref:d==="form"?e.refForm:d==="block"?e.refBlock:String(e.refPage||"").trim(),background:e.bgChoice==="custom"?String(e.bgHex||"").trim():e.bgChoice,text:e.fgChoice==="custom"?String(e.fgHex||"").trim():e.fgChoice,accent:e.accentChoice==="custom"?String(e.accentHex||"").trim():e.accentChoice,accentText:e.accentTextChoice==="custom"?String(e.accentTextHex||"").trim():e.accentTextChoice}},H=()=>ce(Object.fromEntries(Object.keys(r).map(e=>[e,r[e].value]))),Y=M.computed(()=>aa(H())),D=M.observable(!1),he=(e,d)=>{const n=da({...e,size:Number(e.size),offsetX:Number(e.offsetX),offsetY:Number(e.offsetY),phoneSize:Number(e.phoneSize),phoneOffsetX:Number(e.phoneOffsetX),phoneOffsetY:Number(e.phoneOffsetY)},d?{vw:120,vh:220,scale:.5,phone:!0}:{vw:320,vh:200,scale:.5}),f=e.triggerStyle==="icon-text"&&!d;return{left:`${n.left}px`,top:`${n.top}px`,height:`${n.size}px`,width:f?"auto":`${n.size}px`,padding:f?"0 6px":"0","border-radius":f?"999px":`${Math.round(Math.min(Number(e.radius),Number(e.size)/2)/Number(e.size)*100)}%`,"--lnx-bg":$e(e.background)||"var(--dm-primary)","--lnx-fg":$e(e.text)||"var(--dm-primary-text)"}},pe={...r,saving:D,err:M.computed(()=>Y.value.errors),warn:M.computed(()=>Y.value.warnings),cannot:M.computed(()=>D.value||Object.keys(Y.value.errors).length>0),maxRadius:M.computed(()=>Math.floor(Number(r.size.value)/2)),previewStyle:M.computed(()=>he(H(),!1)),phonePreviewStyle:M.computed(()=>he(H(),!0)),botInitial:M.computed(()=>(String(r.botName.value||"").trim()[0]||"?").toUpperCase()),avatarPreview:M.computed(()=>{const e=ra(H());return{background:e.accent||"var(--dm-primary)",color:e.accentText||"var(--dm-primary-text, #fff)"}}),saveText:m?"Create launcher":"Save",linkHref:m?"":J(l.id),linkText:m?"Create the launcher first - then it has a link":J(l.id)},We=M.effect(()=>{const e=Math.floor(Number(r.size.value)/2);Number(r.radius.peek())>e&&(r.radius.value=e)}),ue=(e,d,n)=>{let f=e.peek();return M.effect(()=>{const C=e.value;C!==f&&(f=C,d.value=n(C))})},Ke=ue(r.widthUnit,r.customWidth,e=>e==="%"?90:900),qe=ue(r.heightUnit,r.customHeight,e=>e==="px"?600:70),k=E.slideover({title:m?"New launcher":`Edit ${Z(l.name)}`,size:"lg",position:"right"}),v=ua(pa),me=await Ne().catch(()=>({forms:[],blocks:[]})),fe=(e,d,n)=>{const f=document.createElement("option");f.value="",f.textContent=d.length?"Choose\u2026":"None yet",e.appendChild(f);const C=n&&!d.some(R=>R.value===n)?[...d,{value:n,text:`${n} (missing)`}]:d;for(const R of C){const X=document.createElement("option");X.value=R.value,X.textContent=R.text,e.appendChild(X)}};fe(v.querySelector(".lnx-form-select"),me.forms,b.refForm),fe(v.querySelector(".lnx-block-select"),me.blocks,b.refBlock);let be=()=>{};async function ve(){if(!pe.cannot.peek()){D.value=!0;try{const e=sa(ce(N()),l?.id||""),d=u.peek(),n=m?[...d,e]:d.map(C=>C.id===l.id?e:C);if(!await P(n,m?`Created "${e.name}".`:"Saved."))return;be(),k.close()}finally{D.value=!1}}}k.element.appendChild(v);const je=ke(v),Ye=M.applyBindings(pe,v,{methods:{save:ve,cancel:()=>k.close()}}),_e=e=>{(e.ctrlKey||e.metaKey)&&e.key==="Enter"&&(e.preventDefault(),ve())};v.addEventListener("keydown",_e);const xe=async e=>{const d=e.target.closest(".lnx-corners button[data-pos]");if(d){const n=d.closest(".lnx-corners-phone")?"phonePosition":"position";r[n].value=d.dataset.pos;return}if(e.target.closest(".lnx-pick-icon")){const{openIconPicker:n}=await import("../lib/card-builder.js");n(f=>{r.icon.value=f});return}if(e.target.closest(".lnx-copy-link")&&!m){let n=!1;try{n=await _.copyToClipboard(J(l.id))!==!1}catch{}E.toast(n?"Link copied.":"Could not copy - select the link and copy it.",{type:n?"success":"warning"});return}if(e.target.closest(".lnx-pick-avatar")){const{pickMedia:n}=await import("../lib/media-picker.js"),f=await n({title:"Choose the bot's picture",current:r.avatar.peek()});f&&(r.avatar.value=String(f).replace(/^https?:\/\/[^/]+/i,""));return}if(e.target.closest(".lnx-clear-avatar")){r.avatar.value="";return}if(e.target.closest(".lnx-pick-page")){const{openPagePicker:n}=await import("../lib/page-picker.js");n(f=>{r.refPage.value=f})}};v.addEventListener("click",xe);const Xe=M.effect(()=>{const e=r.icon.value;v.querySelectorAll(".lnx-preview-disc").forEach(d=>{const n=document.createElement("span");n.setAttribute("data-icon",e||"message-circle"),n.className="lnx-preview-icon",d.querySelector(".lnx-preview-icon")?.replaceWith(n),I.scan(d)})}),ge={id:l?.id??null,dirty:re,values:N};w=ge,j.add(k),Ge(k,()=>{Ye.dispose(),je(),We?.(),Ke?.(),qe?.(),Xe?.(),v.removeEventListener("click",xe),j.delete(k),w===ge&&(w=null)}),be=Re(k,re,"Discard the changes you have not saved?"),I.scan(v),k.open(),v.querySelector("#lnx-f-name")?.focus()}const g=p.querySelector(".lnx-list");g.innerHTML=ca;const Ue=M.applyBindings({launchers:u,loading:ae,loadError:F,toolOn:B,filter:$,query:W,rows:K,counts:Oe,emptyText:ze,dragNote:le},p,{methods:{showAll:()=>{$.value="all"},showOn:()=>{$.value="on"},showOff:()=>{$.value="off"}}});x.add(()=>Ue.dispose()),x.add(ke(p,{position:"bottom"})),x.add(M.effect(()=>{K.value,requestAnimationFrame(()=>{p.isConnected&&I.scan(g)})}));const Fe=E.contextMenu(g,{cursor:"glyph",match:".lnx-row",inherit:!1,density:"compact",items:a=>De(a.dataset.id)});x.add(()=>Fe?.destroy?.());const ne=a=>{const t=a.target.closest(".lnx-row");if(!t||a.target.closest(".lnx-switch"))return;const l=a.target.closest(".lnx-kebab");if(l){Se(l);return}z(t.dataset.id)},se=a=>{const t=a.target.closest(".lnx-toggle"),l=t?.closest(".lnx-row"),m=l&&O(l.dataset.id);m&&q(m,t.checked)},ie=a=>{const t=a.target.closest(".lnx-row");t&&(a.key==="F10"&&a.shiftKey?(a.preventDefault(),Se(t)):a.key==="Enter"&&a.target===t&&z(t.dataset.id))};if(g.addEventListener("click",ne),g.addEventListener("change",se),g.addEventListener("keydown",ie),x.add(()=>{g.removeEventListener("click",ne),g.removeEventListener("change",se),g.removeEventListener("keydown",ie)}),typeof E.sortable=="function"){const a=Je(),t=E.sortable(g,{items:".lnx-row",handle:".lnx-grip",key:null,keyboard:!1,onStart:a.start,onEnd:({item:l})=>a.restore(l),onSort:({item:l,from:m,to:o})=>{if(a.restore(l),le.peek()){E.toast("Clear the search and show All to reorder.",{type:"info"}),u.value=[...u.peek()];return}const b=oa(u.peek(),m,o);u.value=b,P(b)}});x.add(()=>t.destroy())}we(i,{id:"launchers-new",icon:"plus",title:"New launcher",onClick:()=>z()}),we(i,{id:"launchers-chats",icon:"message-square",title:"Chats - the conversations from chat launchers",onClick:()=>{location.hash="#/launchers/chats"}});const oe=a=>{w?.dirty()&&(a.preventDefault(),a.returnValue="")};if(window.addEventListener("beforeunload",oe),x.add(()=>window.removeEventListener("beforeunload",oe)),x.add(()=>{if(w?.dirty())try{S.set(U,{id:w.id,values:w.values(),at:new Date().toISOString()})}catch{}[...j].forEach(a=>{try{a.close(!0)}catch{}})}),I.scan(p),await Le(),!A())return;let y=null;try{y=S.get(U)}catch{}if(y?.values){try{S.remove?S.remove(U):S.set(U,null)}catch{}const a=y.id&&O(y.id)?`your changes to "${Z(O(y.id).name)}"`:"the new launcher you started";await E.confirm(`You left ${a} unsaved. Pick up where you left off?`)&&A()&&z(y.id&&O(y.id)?y.id:null,y.values)}}};
|
package/docs/DommaFeatures.md
CHANGED
|
@@ -1240,7 +1240,7 @@ The four Tools below were plugins until 0.67.0 and are now part of the CMS. They
|
|
|
1240
1240
|
- Hand-over: with staff available (the Chats screen open and Available on - memory presence, 75s) the chat goes to `waiting` and staff are notified (source `core:chat`, admins); with nobody available the visitor leaves name and email (`message`) unless the launcher says never; `askDetails: always` asks before putting them through. A staff reply makes it `open` and the bot stays quiet. Hourly tidy-up closes quiet chats (bot 2h, waiting/open 24h) and deletes ended ones after `retentionDays` (90) - bot-only chats with no details after 7 days - with their messages and any orphan messages, one write per collection (adapters' `removeMany`). Chats in memory are an LRU of 2000; unknown tokens are remembered for a minute. A Launchers module that is missing refuses every chat.
|
|
1241
1241
|
- Admin: **Content > Chats** (`#/launchers/chats`, `#/launchers/chats/:id`) - the inbox, waiting first, the live thread (3s poll), replies with per-chat drafts, end/delete/email in a context menu, Available switch, settings cog; sidebar badge `/api/chats/_count` (live while someone waits, red after 5 minutes). **Chats > Knowledge** (`#/launchers/knowledge`) - entries with an editor slideover (question, other ways of asking, keywords, Markdown answer, up to five buttons, on/off), Try the bot with scores, and the Unanswered list (Make an entry, add to the closest entry, dismiss). Visitor panel `public/js/launcher-chat.mjs` `mountChat(container, {launcherId, title, chat})` + `public/css/launcher-chat.css`, domma-reactive.
|
|
1242
1242
|
- Permission `chats` (`read`, `reply`, `manage`) in the Tools group; Admin is granted it once. All of it is behind the Launchers switch.
|
|
1243
|
-
- Della's AI answers (unreleased; Pro plan, hosted sites): when the matcher says `none`, `services/chat/ai.js` `aiAnswer()` asks the Manager (`MANAGER_URL` + `FLEET_TOKEN`, `POST /api/fleet/launcher-chat`; on dcm the in-process registry `Symbol.for('domma.launcher-chat')`) with the site's name, `assistantBrief()` (site.json `assistant.context`/`rules` from Site Settings > General > AI assistant, plus the launcher's `chat.aiContext`/`aiRules`), the enabled non-sample Knowledge (most used first, 16,000 characters), the last 10 visitor/bot messages and the question. A non-empty answer is stored as a bot message with `ai: true` (`misses` reset); empty or refused falls back to the usual "do not know". The question is still logged as unanswered. A 403 (no licence) backs off 10 minutes, a 429 (month used) 30 minutes, anything else 1 minute. Per launcher `chat.ai` (default on), `chat.aiUseSite` (default on; off = the launcher's own context only - the site's rules always apply), `chat.aiMaxPerChat` (20; `aiCount` on the session); the default bot name is now Della. `aiContext`/`aiRules` never reach the page (`publicLauncher`). `/api/chat/config` says `ai` so the panel can say Della is an AI assistant. Manager side: `plugins/site-manager/services/launcherChatRoutes.js` (fleet token, the `ai-site-builder` licence, 2,000 answers per site per month counting "do not know", 4 at once) and `tools/launcher-chat` (Claude Haiku 5.5, low effort; fixed cached system prompt, then the owner's context and rules as a second system block; the visitor's words only in the user message; `LAUNCHER_CHAT_ANTHROPIC_KEY` read by the job alone).
|
|
1243
|
+
- Della's AI answers (unreleased; Pro plan, hosted sites): when the matcher says `none`, `services/chat/ai.js` `aiAnswer()` asks the Manager (`MANAGER_URL` + `FLEET_TOKEN`, `POST /api/fleet/launcher-chat`; on dcm the in-process registry `Symbol.for('domma.launcher-chat')`) with the site's name, `assistantBrief()` (site.json `assistant.context`/`rules` from Site Settings > General > AI assistant, plus the launcher's `chat.aiContext`/`aiRules`), the enabled non-sample Knowledge (most used first, 16,000 characters), the last 10 visitor/bot messages and the question. A non-empty answer is stored as a bot message with `ai: true` (`misses` reset); empty or refused falls back to the usual "do not know". The question is still logged as unanswered. A 403 (no licence) backs off 10 minutes, a 429 (month used) 30 minutes, anything else 1 minute. Per launcher `chat.ai` (default on), `chat.aiUseSite` (default on; off = the launcher's own context only - the site's rules always apply), `chat.aiMaxPerChat` (20; `aiCount` on the session); the default bot name is now Della. A character's chat is called by the character's name, or by `chat.characterName` when set (admin: **Call her** under Use Della) - `characterChat()` in `public/js/characters.mjs` - so Della can be "Dash" on one launcher with her own artwork. `aiContext`/`aiRules` never reach the page (`publicLauncher`). `/api/chat/config` says `ai` so the panel can say Della is an AI assistant. Manager side: `plugins/site-manager/services/launcherChatRoutes.js` (fleet token, the `ai-site-builder` licence, 2,000 answers per site per month counting "do not know", 4 at once) and `tools/launcher-chat` (Claude Haiku 5.5, low effort; fixed cached system prompt, then the owner's context and rules as a second system block; the visitor's words only in the user message; `LAUNCHER_CHAT_ANTHROPIC_KEY` read by the job alone).
|
|
1244
1244
|
- Saved chats (unreleased): preset `chat-saved` (in `CHAT_PRESET_SLUGS`, `chats.manage` through the generic API, kept out of site repos) - a copy of a chat with `note`, `outcome` (to look at / looking into it / done), visitor, page, dates, who saved it, `transcript` (plain text) and `messages`. `POST /api/chats/:id/save` (reply), `GET /api/chats/saved` and `/saved/:sid` (read), `PUT /saved/:sid` (reply; note, outcome), `DELETE /saved/:sid` (manage); at most 2,000 per site. Chats inbox: a **Saved** tab, the context-menu item **Save for a closer look…**, and an outcome/note bar on an open saved chat (`services/chat/saved.js`, `arrangeSaved()`).
|
|
1245
1245
|
- Visitor panel look (unreleased): bot and staff avatars, runs of messages grouped (name on the first, avatar on the last), gradient visitor bubbles, soft chips for links and choices, a rounded composer with the send button inside, messages easing in (still for reduced motion), and in a launcher panel the bot's avatar (with a dot while someone answers) and the status under the title. Panel 400 x 600. Per-chat branding: `chat.accent` / `chat.accentText` (a theme token or hex, `launcherColour`) and `chat.avatar` (a site address only, `launcherAvatar()`), in the page's chat block and `/api/chat/config`; the panel sets `--chat-accent` / `--chat-accent-text` on itself (`launcherChatAccentCss()`: a hex accent with no text colour gets black or white by contrast, a token its `--dm-<token>-text`), and the bot's picture replaces its initial in the heading, the typing row and its messages.
|
|
1246
1246
|
- Chat window and extras (unreleased): `chat.size` sm/md/lg/custom + `width`/`height` (`launcherChatBox()`; desktop only, clamped 300-720 x 380-900 and to the window), `chat.resizable` (a grip in the corner opposite the disc; size kept per launcher in the browser, `launcher-chat-size:<id>`, double-click resets), `chat.starters` (up to 4 buttons under the greeting; a tap within 1.7s of opening waits out the anti-bot window), `chat.personButton` below/header (an icon with a tooltip before the close button), greeting placeholders `{greeting}` `{timeofday}` `{day}` `{date}` `{time}` `{botname}` `{site}`, `chat.times` time/datetime/none on each message (`fillGreeting()`, the visitor's clock, text only), and `chat.keepDays` (0 = the site's `retentionDays`; the hourly tidy-up reads each launcher's).
|
package/package.json
CHANGED
package/public/js/characters.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CHARACTERS=Object.freeze({dot:Object.freeze({id:"dot",name:"Dot",artwork:"/public/images/characters/dot-poses.png"}),daisy:Object.freeze({id:"daisy",name:"Daisy",artwork:"/public/images/characters/daisy-poses.png"}),della:Object.freeze({id:"della",name:"Della",artwork:"/public/images/characters/della-poses.png"})});export function characterId(e){return typeof e=="string"&&Object.hasOwn(CHARACTERS,e)?e:""}export function normaliseCharacterSettings(e){const r=e&&typeof e=="object"&&!Array.isArray(e)?e:{};return{enabled:r.enabled!==!1,animated:r.animated!==!1,launchers:r.launchers!==!1,chats:r.chats!==!1,builders:r.builders!==!1,dot:r.dot!==!1,daisy:r.daisy!==!1}}export function builderCharacterState({working:e=!1,busy:r=!1,error:
|
|
1
|
+
export const CHARACTERS=Object.freeze({dot:Object.freeze({id:"dot",name:"Dot",artwork:"/public/images/characters/dot-poses.png"}),daisy:Object.freeze({id:"daisy",name:"Daisy",artwork:"/public/images/characters/daisy-poses.png"}),della:Object.freeze({id:"della",name:"Della",artwork:"/public/images/characters/della-poses.png"})});export function characterId(e){return typeof e=="string"&&Object.hasOwn(CHARACTERS,e)?e:""}export function normaliseCharacterSettings(e){const r=e&&typeof e=="object"&&!Array.isArray(e)?e:{};return{enabled:r.enabled!==!1,animated:r.animated!==!1,launchers:r.launchers!==!1,chats:r.chats!==!1,builders:r.builders!==!1,dot:r.dot!==!1,daisy:r.daisy!==!1}}export function builderCharacterState({working:e=!1,busy:r=!1,error:t="",status:a="",hasContent:n=!1}={}){return t||["waiting","failed","stopped"].includes(a)?"help":e||a==="building"?"working":r?"thinking":["ready","released"].includes(a)?"success":n||a==="review"?"ready":"greeting"}export function characterChat(e={},r){const t=characterId(e.character),a=typeof e.characterName=="string"?e.characterName.replace(/[\u0000-\u001f\u007f]/g," ").trim().slice(0,40):"";return{...e,character:t,...t?{botName:a||CHARACTERS[t].name}:{},characterOptions:normaliseCharacterSettings(r)}}export function chatCharacterState({busy:e=!1,error:r="",ended:t=!1,status:a="none",askDetails:n=!1,replied:i=!1}={}){return r||n?"help":e?"thinking":t||a==="message"?"success":i?"ready":"greeting"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{cssClasses as M}from"./css-classes.mjs";import{characterId as b}from"./characters.mjs";export const LAUNCHER_POSITIONS=["TL","TC","TR","ML","MR","BL","BC","BR"],LAUNCHER_POSITION_LABEL={TL:"Top left",TC:"Top centre",TR:"Top right",ML:"Middle left",MR:"Middle right",BL:"Bottom left",BC:"Bottom centre",BR:"Bottom right"},LAUNCHER_TRIGGER_STYLES=["icon","icon-text"],LAUNCHER_TOOLTIP_MODES=["label","custom","off"],LAUNCHER_DEVICES=["all","desktop","phone"],LAUNCHER_AUDIENCES=["everyone","signed-in","signed-out"],LAUNCHER_PAGE_MODES=["all","only","except"],LAUNCHER_ACTIONS=["modal","slideover","chat"],LAUNCHER_MODAL_KINDS=["page","form","block"],LAUNCHER_SLIDEOVER_KINDS=["page","form","block"],LAUNCHER_MODAL_SIZES=["xs","sm","md","lg","xl","xxl","full","screen","custom"],LAUNCHER_MODAL_HEIGHTS=["auto","sm","md","lg","full","custom"],LAUNCHER_WIDTH_UNITS=["px","%"],LAUNCHER_HEIGHT_UNITS=["px","vh"],LAUNCHER_MODAL_WIDTH_CSS=Object.freeze({xs:"320px",sm:"400px",md:"600px",lg:"800px",xl:"1140px",xxl:"1400px",full:"90vw"}),LAUNCHER_MODAL_HEIGHT_CSS=Object.freeze({sm:"40vh",md:"60vh",lg:"80vh",full:"90vh"}),LAUNCHER_SLIDEOVER_WIDTHS=["sm","md","lg","xl"],LAUNCHER_SIDES=["left","right"],LAUNCHER_ASK_DETAILS=["offline","always","never"],LAUNCHER_TOKENS=["primary","secondary","success","danger","warning","info","surface","text","background"],LAUNCHER_LIMITS=Object.freeze({nameMax:60,labelMax:40,tooltipMax:120,titleMax:80,iconMax:40,idMax:40,sizeMin:32,sizeMax:96,offsetMax:500,pathsMax:50,pathMax:200,greetingMax:300,botNameMax:40,aiContextMax:4e3,aiRulesMax:2e3,avatarMax:300,chatWidth:[300,720],chatHeight:[380,900],startersMax:4,starterMax:80,aiMaxPerChat:[0,100],keepDays:[0,730],widthPx:[240,2400],widthPct:[20,100],heightPx:[160,2e3],heightVh:[20,100]}),LAUNCHER_DEFAULTS=Object.freeze({enabled:!0,showDisc:!0,name:"New launcher",label:"Open",tooltipMode:"label",tooltip:"",icon:"message-circle",triggerStyle:"icon",position:"BR",offsetX:32,offsetY:32,size:52,radius:26,devices:"all",phone:Object.freeze({override:!1,position:"BR",offsetX:16,offsetY:16,size:48}),colours:Object.freeze({background:"",text:""}),class:"",pages:Object.freeze({mode:"all",paths:Object.freeze([])}),audience:"everyone",action:Object.freeze({type:"modal",kind:"page",ref:"",title:"",size:"lg",side:"right",width:"md",customWidth:900,widthUnit:"px",height:"auto",customHeight:70,heightUnit:"vh"}),chat:Object.freeze({greeting:"Hi! How can we help?",botName:"Della",bot:!0,staff:!0,askDetails:"offline",ai:!0,aiUseSite:!0,aiContext:"",aiRules:"",accent:"",accentText:"",avatar:"",character:"",size:"md",width:400,height:600,resizable:!0,starters:Object.freeze([]),aiMaxPerChat:20,personButton:"below",keepDays:0,times:"time"})});const c=(e,t,i)=>t.includes(e)?e:i;function f(e,t,i,o){const r=typeof e=="number"?e:typeof e=="string"&&e.trim()?Number(e):NaN;return Number.isFinite(r)?Math.min(o,Math.max(i,Math.round(r))):Math.min(o,Math.max(i,t))}function l(e,t,i=""){return typeof e!="string"?i:e.replace(/[\u0000-\u001f\u007f]/g," ").trim().replace(/\s+/g," ").slice(0,t)||i}const d=e=>e&&typeof e=="object"&&!Array.isArray(e)?e:{};export const LAUNCHER_ID_RE=/^[a-z0-9][a-z0-9-]{0,39}$/;const y=/^[a-z0-9][a-z0-9-]{0,39}$/,R=/^\/[A-Za-z0-9._~\-/]*$/,C=/^[a-z0-9][a-z0-9_-]{0,99}$/i;export function launcherColour(e){if(typeof e!="string")return"";const t=e.trim().toLowerCase();return LAUNCHER_TOKENS.includes(t)||/^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/.test(t)?t:""}export function launcherColourCss(e){const t=launcherColour(e);return t?LAUNCHER_TOKENS.includes(t)?`var(--dm-${t})`:t:""}export function normaliseLauncherPath(e){if(typeof e!="string")return"";let t=e.trim().split(/[?#]/)[0].replace(/\s+/g,"");return!t||(t.startsWith("/")||(t="/"+t),t=t.replace(/\/{2,}/g,"/"),t.length>1&&(t=t.replace(/\/+$/,"")),t.length>LAUNCHER_LIMITS.pathMax||!/^\/[A-Za-z0-9._~\-/*]*$/.test(t))?"":t}export function launcherPathMatches(e,t){const i=normaliseLauncherPath(e||"/")||"/",o=normaliseLauncherPath(t);return o?o.endsWith("/*")&&i===(o.slice(0,-2)||"/")?!0:new RegExp("^"+o.split("*").map(n=>n.replace(/[.+?^${}()|[\]\\]/g,"\\$&")).join(".*")+"$","i").test(i):!1}export function launcherShowsOn(e,t,i){if(!e||e.enabled===!1||e.audience==="signed-in"&&!i||e.audience==="signed-out"&&i)return!1;const o=e.pages.paths.some(r=>launcherPathMatches(t,r));return e.pages.mode==="only"?o:e.pages.mode==="except"?!o:!0}function E(e,t){const i=d(e);return{override:i.override===!0,position:c(i.position,LAUNCHER_POSITIONS,LAUNCHER_DEFAULTS.phone.position),offsetX:f(i.offsetX,LAUNCHER_DEFAULTS.phone.offsetX,0,LAUNCHER_LIMITS.offsetMax),offsetY:f(i.offsetY,LAUNCHER_DEFAULTS.phone.offsetY,0,LAUNCHER_LIMITS.offsetMax),size:f(i.size,Math.min(t,LAUNCHER_DEFAULTS.phone.size),LAUNCHER_LIMITS.sizeMin,LAUNCHER_LIMITS.sizeMax)}}function L(e){const t=d(e),i=c(t.type,LAUNCHER_ACTIONS,LAUNCHER_DEFAULTS.action.type),o=i==="modal"?LAUNCHER_MODAL_KINDS:LAUNCHER_SLIDEOVER_KINDS,r=i==="chat"?"page":c(t.kind,o,"page");let n=typeof t.ref=="string"?t.ref.trim():"";r==="page"?(n=n?normaliseLauncherPath(n):"",n.includes("*")&&(n="")):C.test(n)||(n=""),i==="chat"&&(n="");const a=LAUNCHER_DEFAULTS.action,h=c(t.widthUnit,LAUNCHER_WIDTH_UNITS,a.widthUnit),s=c(t.heightUnit,LAUNCHER_HEIGHT_UNITS,a.heightUnit);return{type:i,kind:r,ref:n,title:l(t.title,LAUNCHER_LIMITS.titleMax),size:c(t.size,LAUNCHER_MODAL_SIZES,a.size),side:c(t.side,LAUNCHER_SIDES,a.side),width:c(t.width,LAUNCHER_SLIDEOVER_WIDTHS,a.width),customWidth:f(t.customWidth,h==="%"?90:a.customWidth,...h==="%"?LAUNCHER_LIMITS.widthPct:LAUNCHER_LIMITS.widthPx),widthUnit:h,height:c(t.height,LAUNCHER_MODAL_HEIGHTS,a.height),customHeight:f(t.customHeight,s==="px"?600:a.customHeight,...s==="px"?LAUNCHER_LIMITS.heightPx:LAUNCHER_LIMITS.heightVh),heightUnit:s}}export function launcherModalBox(e){const t=e||LAUNCHER_DEFAULTS.action;if(t.size==="screen")return{width:"100vw",height:"100vh",screen:!0};const i=t.size==="custom"?t.widthUnit==="%"?`${t.customWidth}vw`:`${t.customWidth}px`:LAUNCHER_MODAL_WIDTH_CSS[t.size]||LAUNCHER_MODAL_WIDTH_CSS.lg,o=t.height==="custom"?`${t.customHeight}${t.heightUnit==="px"?"px":"vh"}`:LAUNCHER_MODAL_HEIGHT_CSS[t.height]||"";return{width:i,height:o,screen:!1}}export function normaliseLauncherChat(e){const t=d(e),i=LAUNCHER_DEFAULTS.chat;return{greeting:typeof t.greeting=="string"?t.greeting.replace(/\r\n?/g,`
|
|
2
|
-
`).replace(/[\u0000-\u0009\u000b-\u001f\u007f]/g," ").trim().slice(0,LAUNCHER_LIMITS.greetingMax):i.greeting,botName:l(t.botName,LAUNCHER_LIMITS.botNameMax,i.botName),bot:t.bot!==!1,staff:t.staff!==!1,askDetails:c(t.askDetails,LAUNCHER_ASK_DETAILS,i.askDetails),ai:t.ai!==!1,aiUseSite:t.aiUseSite!==!1,aiContext:m(t.aiContext,LAUNCHER_LIMITS.aiContextMax),aiRules:m(t.aiRules,LAUNCHER_LIMITS.aiRulesMax),accent:launcherColour(t.accent),accentText:launcherColour(t.accentText),avatar:launcherAvatar(t.avatar),character:b(t.character),size:c(t.size,LAUNCHER_CHAT_SIZES,i.size),width:f(t.width,i.width,...LAUNCHER_LIMITS.chatWidth),height:f(t.height,i.height,...LAUNCHER_LIMITS.chatHeight),resizable:t.resizable!==!1,starters:(Array.isArray(t.starters)?t.starters:typeof t.starters=="string"?t.starters.split(`
|
|
1
|
+
import{cssClasses as M}from"./css-classes.mjs";import{characterId as b}from"./characters.mjs";export const LAUNCHER_POSITIONS=["TL","TC","TR","ML","MR","BL","BC","BR"],LAUNCHER_POSITION_LABEL={TL:"Top left",TC:"Top centre",TR:"Top right",ML:"Middle left",MR:"Middle right",BL:"Bottom left",BC:"Bottom centre",BR:"Bottom right"},LAUNCHER_TRIGGER_STYLES=["icon","icon-text"],LAUNCHER_TOOLTIP_MODES=["label","custom","off"],LAUNCHER_DEVICES=["all","desktop","phone"],LAUNCHER_AUDIENCES=["everyone","signed-in","signed-out"],LAUNCHER_PAGE_MODES=["all","only","except"],LAUNCHER_ACTIONS=["modal","slideover","chat"],LAUNCHER_MODAL_KINDS=["page","form","block"],LAUNCHER_SLIDEOVER_KINDS=["page","form","block"],LAUNCHER_MODAL_SIZES=["xs","sm","md","lg","xl","xxl","full","screen","custom"],LAUNCHER_MODAL_HEIGHTS=["auto","sm","md","lg","full","custom"],LAUNCHER_WIDTH_UNITS=["px","%"],LAUNCHER_HEIGHT_UNITS=["px","vh"],LAUNCHER_MODAL_WIDTH_CSS=Object.freeze({xs:"320px",sm:"400px",md:"600px",lg:"800px",xl:"1140px",xxl:"1400px",full:"90vw"}),LAUNCHER_MODAL_HEIGHT_CSS=Object.freeze({sm:"40vh",md:"60vh",lg:"80vh",full:"90vh"}),LAUNCHER_SLIDEOVER_WIDTHS=["sm","md","lg","xl"],LAUNCHER_SIDES=["left","right"],LAUNCHER_ASK_DETAILS=["offline","always","never"],LAUNCHER_TOKENS=["primary","secondary","success","danger","warning","info","surface","text","background"],LAUNCHER_LIMITS=Object.freeze({nameMax:60,labelMax:40,tooltipMax:120,titleMax:80,iconMax:40,idMax:40,sizeMin:32,sizeMax:96,offsetMax:500,pathsMax:50,pathMax:200,greetingMax:300,botNameMax:40,aiContextMax:4e3,aiRulesMax:2e3,avatarMax:300,chatWidth:[300,720],chatHeight:[380,900],startersMax:4,starterMax:80,aiMaxPerChat:[0,100],keepDays:[0,730],widthPx:[240,2400],widthPct:[20,100],heightPx:[160,2e3],heightVh:[20,100]}),LAUNCHER_DEFAULTS=Object.freeze({enabled:!0,showDisc:!0,name:"New launcher",label:"Open",tooltipMode:"label",tooltip:"",icon:"message-circle",triggerStyle:"icon",position:"BR",offsetX:32,offsetY:32,size:52,radius:26,devices:"all",phone:Object.freeze({override:!1,position:"BR",offsetX:16,offsetY:16,size:48}),colours:Object.freeze({background:"",text:""}),class:"",pages:Object.freeze({mode:"all",paths:Object.freeze([])}),audience:"everyone",action:Object.freeze({type:"modal",kind:"page",ref:"",title:"",size:"lg",side:"right",width:"md",customWidth:900,widthUnit:"px",height:"auto",customHeight:70,heightUnit:"vh"}),chat:Object.freeze({greeting:"Hi! How can we help?",botName:"Della",bot:!0,staff:!0,askDetails:"offline",ai:!0,aiUseSite:!0,aiContext:"",aiRules:"",accent:"",accentText:"",avatar:"",character:"",characterName:"",size:"md",width:400,height:600,resizable:!0,starters:Object.freeze([]),aiMaxPerChat:20,personButton:"below",keepDays:0,times:"time"})});const c=(e,t,i)=>t.includes(e)?e:i;function f(e,t,i,o){const r=typeof e=="number"?e:typeof e=="string"&&e.trim()?Number(e):NaN;return Number.isFinite(r)?Math.min(o,Math.max(i,Math.round(r))):Math.min(o,Math.max(i,t))}function l(e,t,i=""){return typeof e!="string"?i:e.replace(/[\u0000-\u001f\u007f]/g," ").trim().replace(/\s+/g," ").slice(0,t)||i}const d=e=>e&&typeof e=="object"&&!Array.isArray(e)?e:{};export const LAUNCHER_ID_RE=/^[a-z0-9][a-z0-9-]{0,39}$/;const y=/^[a-z0-9][a-z0-9-]{0,39}$/,R=/^\/[A-Za-z0-9._~\-/]*$/,C=/^[a-z0-9][a-z0-9_-]{0,99}$/i;export function launcherColour(e){if(typeof e!="string")return"";const t=e.trim().toLowerCase();return LAUNCHER_TOKENS.includes(t)||/^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/.test(t)?t:""}export function launcherColourCss(e){const t=launcherColour(e);return t?LAUNCHER_TOKENS.includes(t)?`var(--dm-${t})`:t:""}export function normaliseLauncherPath(e){if(typeof e!="string")return"";let t=e.trim().split(/[?#]/)[0].replace(/\s+/g,"");return!t||(t.startsWith("/")||(t="/"+t),t=t.replace(/\/{2,}/g,"/"),t.length>1&&(t=t.replace(/\/+$/,"")),t.length>LAUNCHER_LIMITS.pathMax||!/^\/[A-Za-z0-9._~\-/*]*$/.test(t))?"":t}export function launcherPathMatches(e,t){const i=normaliseLauncherPath(e||"/")||"/",o=normaliseLauncherPath(t);return o?o.endsWith("/*")&&i===(o.slice(0,-2)||"/")?!0:new RegExp("^"+o.split("*").map(n=>n.replace(/[.+?^${}()|[\]\\]/g,"\\$&")).join(".*")+"$","i").test(i):!1}export function launcherShowsOn(e,t,i){if(!e||e.enabled===!1||e.audience==="signed-in"&&!i||e.audience==="signed-out"&&i)return!1;const o=e.pages.paths.some(r=>launcherPathMatches(t,r));return e.pages.mode==="only"?o:e.pages.mode==="except"?!o:!0}function E(e,t){const i=d(e);return{override:i.override===!0,position:c(i.position,LAUNCHER_POSITIONS,LAUNCHER_DEFAULTS.phone.position),offsetX:f(i.offsetX,LAUNCHER_DEFAULTS.phone.offsetX,0,LAUNCHER_LIMITS.offsetMax),offsetY:f(i.offsetY,LAUNCHER_DEFAULTS.phone.offsetY,0,LAUNCHER_LIMITS.offsetMax),size:f(i.size,Math.min(t,LAUNCHER_DEFAULTS.phone.size),LAUNCHER_LIMITS.sizeMin,LAUNCHER_LIMITS.sizeMax)}}function L(e){const t=d(e),i=c(t.type,LAUNCHER_ACTIONS,LAUNCHER_DEFAULTS.action.type),o=i==="modal"?LAUNCHER_MODAL_KINDS:LAUNCHER_SLIDEOVER_KINDS,r=i==="chat"?"page":c(t.kind,o,"page");let n=typeof t.ref=="string"?t.ref.trim():"";r==="page"?(n=n?normaliseLauncherPath(n):"",n.includes("*")&&(n="")):C.test(n)||(n=""),i==="chat"&&(n="");const a=LAUNCHER_DEFAULTS.action,h=c(t.widthUnit,LAUNCHER_WIDTH_UNITS,a.widthUnit),s=c(t.heightUnit,LAUNCHER_HEIGHT_UNITS,a.heightUnit);return{type:i,kind:r,ref:n,title:l(t.title,LAUNCHER_LIMITS.titleMax),size:c(t.size,LAUNCHER_MODAL_SIZES,a.size),side:c(t.side,LAUNCHER_SIDES,a.side),width:c(t.width,LAUNCHER_SLIDEOVER_WIDTHS,a.width),customWidth:f(t.customWidth,h==="%"?90:a.customWidth,...h==="%"?LAUNCHER_LIMITS.widthPct:LAUNCHER_LIMITS.widthPx),widthUnit:h,height:c(t.height,LAUNCHER_MODAL_HEIGHTS,a.height),customHeight:f(t.customHeight,s==="px"?600:a.customHeight,...s==="px"?LAUNCHER_LIMITS.heightPx:LAUNCHER_LIMITS.heightVh),heightUnit:s}}export function launcherModalBox(e){const t=e||LAUNCHER_DEFAULTS.action;if(t.size==="screen")return{width:"100vw",height:"100vh",screen:!0};const i=t.size==="custom"?t.widthUnit==="%"?`${t.customWidth}vw`:`${t.customWidth}px`:LAUNCHER_MODAL_WIDTH_CSS[t.size]||LAUNCHER_MODAL_WIDTH_CSS.lg,o=t.height==="custom"?`${t.customHeight}${t.heightUnit==="px"?"px":"vh"}`:LAUNCHER_MODAL_HEIGHT_CSS[t.height]||"";return{width:i,height:o,screen:!1}}export function normaliseLauncherChat(e){const t=d(e),i=LAUNCHER_DEFAULTS.chat;return{greeting:typeof t.greeting=="string"?t.greeting.replace(/\r\n?/g,`
|
|
2
|
+
`).replace(/[\u0000-\u0009\u000b-\u001f\u007f]/g," ").trim().slice(0,LAUNCHER_LIMITS.greetingMax):i.greeting,botName:l(t.botName,LAUNCHER_LIMITS.botNameMax,i.botName),bot:t.bot!==!1,staff:t.staff!==!1,askDetails:c(t.askDetails,LAUNCHER_ASK_DETAILS,i.askDetails),ai:t.ai!==!1,aiUseSite:t.aiUseSite!==!1,aiContext:m(t.aiContext,LAUNCHER_LIMITS.aiContextMax),aiRules:m(t.aiRules,LAUNCHER_LIMITS.aiRulesMax),accent:launcherColour(t.accent),accentText:launcherColour(t.accentText),avatar:launcherAvatar(t.avatar),character:b(t.character),characterName:l(t.characterName,LAUNCHER_LIMITS.botNameMax,""),size:c(t.size,LAUNCHER_CHAT_SIZES,i.size),width:f(t.width,i.width,...LAUNCHER_LIMITS.chatWidth),height:f(t.height,i.height,...LAUNCHER_LIMITS.chatHeight),resizable:t.resizable!==!1,starters:(Array.isArray(t.starters)?t.starters:typeof t.starters=="string"?t.starters.split(`
|
|
3
3
|
`):[]).map(r=>l(r,LAUNCHER_LIMITS.starterMax)).filter(Boolean).slice(0,LAUNCHER_LIMITS.startersMax),aiMaxPerChat:f(t.aiMaxPerChat,i.aiMaxPerChat,...LAUNCHER_LIMITS.aiMaxPerChat),personButton:c(t.personButton,LAUNCHER_PERSON_BUTTON,i.personButton),keepDays:f(t.keepDays,i.keepDays,...LAUNCHER_LIMITS.keepDays),times:c(t.times,LAUNCHER_CHAT_TIMES,i.times)}}export const LAUNCHER_PERSON_BUTTON=["below","header"],LAUNCHER_CHAT_TIMES=["time","datetime","none"],GREETING_PLACEHOLDERS=["greeting","timeofday","day","date","time","botname","site"];export function fillGreeting(e,{now:t=new Date,botName:i="",site:o=""}={}){const r=t.getHours(),n=r<12?"morning":r<18?"afternoon":"evening",a={greeting:`Good ${n}`,timeofday:n,day:t.toLocaleDateString("en-GB",{weekday:"long"}),date:t.toLocaleDateString("en-GB",{day:"numeric",month:"long"}),time:t.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit"}),botname:i,site:o};return String(e??"").replace(/\{\s*([a-z]+)\s*\}/gi,(h,s)=>{const u=a[s.toLowerCase()];return u===void 0?h:u})}export const LAUNCHER_CHAT_SIZES=["sm","md","lg","custom"];const x={sm:[340,500],md:[400,600],lg:[480,720]};export function launcherChatBox(e={}){if(e.size==="custom")return{width:f(e.width,400,...LAUNCHER_LIMITS.chatWidth),height:f(e.height,600,...LAUNCHER_LIMITS.chatHeight)};const[t,i]=x[e.size]||x.md;return{width:t,height:i}}export function launcherAvatar(e){if(typeof e!="string")return"";const t=e.trim();return!t||t.length>LAUNCHER_LIMITS.avatarMax||t.startsWith("//")?"":/^\/[A-Za-z0-9._~\-/%]+$/.test(t)?t:""}export function launcherChatAccentCss(e={}){const t=launcherColourCss(e.accent);if(!t)return{accent:"",accentText:""};let i=launcherColourCss(e.accentText);if(!i){const o=launcherColour(e.accent);if(o.startsWith("#")){const r=o.length<=5?o.slice(1,4).split("").map(s=>s+s).join(""):o.slice(1,7),[n,a,h]=[0,2,4].map(s=>parseInt(r.slice(s,s+2),16)/255).map(s=>s<=.03928?s/12.92:((s+.055)/1.055)**2.4);i=.2126*n+.7152*a+.0722*h>.179?"#111111":"#ffffff"}else i=o==="primary"?"var(--dm-primary-text, #fff)":`var(--dm-${o}-text, #fff)`}return{accent:t,accentText:i}}function m(e,t){return typeof e=="string"?e.replace(/\r\n?/g,`
|
|
4
4
|
`).replace(/[\u0000-\u0009\u000b-\u001f\u007f]/g," ").replace(/\n{3,}/g,`
|
|
5
5
|
|
package/public/js/launchers.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{LAUNCHER_LIMITS as C,launcherChatBox as mt,launcherModalBox as pt,launcherSpot as ft,launcherStack as vt}from"/public/js/launcher-settings.mjs?v=20261110-
|
|
1
|
+
import{LAUNCHER_LIMITS as C,launcherChatBox as mt,launcherModalBox as pt,launcherSpot as ft,launcherStack as vt}from"/public/js/launcher-settings.mjs?v=20261110-character-name";const V=i=>`launcher-chat-size:${i}`,bt=i=>{try{const c=globalThis.S?.get?.(V(i));return c&&Number(c.width)&&Number(c.height)?c:null}catch{return null}},Z=(i,c)=>{try{globalThis.S?.set?.(V(i),c)}catch{}};import{mountCharacter as gt}from"./character-view.mjs?v=20261110-builder-characters";const J="(max-width: 640px)",Q=[".site-search-floating-trigger","#back-to-top-btn","#go-to-bottom-btn",".dm-theme-switcher:not(.dm-ts-inline)","nav.dm-breadcrumbs",".dm-motion-fab"].join(","),tt={sm:"360px",md:"480px",lg:"640px",xl:"860px"},yt=i=>String(i??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),et=()=>document.documentElement.classList.contains("dm-reduced-motion")||matchMedia("(prefers-reduced-motion: reduce)").matches,wt=`
|
|
2
2
|
<button type="button" class="dm-launcher" data-id="{{id}}" data-bind-class="cls" data-bind-style="style.value"
|
|
3
3
|
data-bind-aria-expanded="expanded.value" data-bind-hidden="hidden.value" aria-haspopup="dialog" aria-label="{{label}}">
|
|
4
4
|
<span class="dm-launcher-icon" data-icon="{{icon}}" aria-hidden="true"></span>
|
|
@@ -97,6 +97,7 @@ export function normaliseLauncherChat(raw) {
|
|
|
97
97
|
accentText: launcherColour(r.accentText),
|
|
98
98
|
avatar: launcherAvatar(r.avatar),
|
|
99
99
|
character: storedChat(r).character,
|
|
100
|
+
characterName: clip(r.characterName, BOT_NAME_MAX, ''),
|
|
100
101
|
aiMaxPerChat: Number.isFinite(Number(r.aiMaxPerChat)) && String(r.aiMaxPerChat ?? '').trim() !== ''
|
|
101
102
|
? Math.min(100, Math.max(0, Math.round(Number(r.aiMaxPerChat)))) : LAUNCHER_CHAT_DEFAULTS.aiMaxPerChat,
|
|
102
103
|
starters: storedChat(r).starters,
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
export const LAUNCHERS_CACHE_TAG = 'site';
|
|
27
27
|
|
|
28
28
|
/** Bumped by hand when launchers.mjs or launchers.css changes - the updater replaces public/ wholesale. */
|
|
29
|
-
export const LAUNCHERS_ASSET_V = '20261110-
|
|
29
|
+
export const LAUNCHERS_ASSET_V = '20261110-character-name';
|
|
30
30
|
|
|
31
31
|
/** @returns {object[]} the stored launchers, normalised, in order; none when the file is missing or broken */
|
|
32
32
|
export function getLaunchers() {
|