domma-cms 1.55.1 → 1.57.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/CHANGELOG.md +10 -0
- package/admin/css/admin.css +1 -1
- package/admin/js/app.js +5 -5
- package/admin/js/lib/admin-assistant.js +1 -1
- package/admin/js/lib/admin-portal-arrange.js +1 -0
- package/admin/js/lib/admin-portal.js +1 -0
- package/admin/js/lib/sidebar-renderer.js +6 -6
- package/admin/js/lib/topbar-notifications.js +7 -7
- package/admin/js/templates/docs/usage-launchers.html +1 -1
- package/admin/js/templates/docs/usage-users-roles.html +8 -0
- package/admin/js/templates/settings.html +1 -1
- package/docs/DommaFeatures.md +4 -1
- package/docs/remy-character.md +16 -0
- package/package.json +1 -1
- package/public/images/characters/remy-poses.png +0 -0
- package/public/js/builder-character.mjs +1 -1
- package/public/js/character-view.mjs +1 -1
- package/public/js/characters.mjs +1 -1
- package/public/js/launcher-chat.mjs +1 -1
- package/public/js/launchers.mjs +2 -2
- package/server/routes/api/auth.js +9 -2
- package/server/services/adminPortal.js +72 -0
- package/server/services/launchers.js +1 -1
- package/server/services/plugins.js +15 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{fillGreeting as Ce,launcherChatAccentCss as Ae}from"/public/js/launcher-settings.mjs?v=20261111-knowledge-switch";import{CHARACTERS as Ne,characterId as ae,normaliseCharacterSettings as G,chatCharacterState as $e}from"./characters.mjs?v=20261111-
|
|
1
|
+
import{fillGreeting as Ce,launcherChatAccentCss as Ae}from"/public/js/launcher-settings.mjs?v=20261111-knowledge-switch";import{CHARACTERS as Ne,characterId as ae,normaliseCharacterSettings as G,chatCharacterState as $e}from"./characters.mjs?v=20261111-remy-character";import{mountCharacter as we}from"./character-view.mjs?v=20261111-remy-character";const De={waiting:3e3,open:3e3,bot:9e3,message:2e4},Be=6e3,He="/public/css/launcher-chat.css?v=20261111-remy-character",se=()=>document.documentElement.classList.contains("dm-reduced-motion")||!!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;function Oe(){if(document.querySelector("link[data-dm-chat-css]"))return;const t=document.createElement("link");t.rel="stylesheet",t.href=He,t.dataset.dmChatCss="",document.head.appendChild(t)}const ne={get:t=>{try{return globalThis.S?.get?.(t)??null}catch{return null}},set:(t,d)=>{try{globalThis.S?.set?.(t,d)}catch{}},remove:t=>{try{globalThis.S?.remove?globalThis.S.remove(t):globalThis.S?.set?.(t,null)}catch{}}};async function Y(t,d,o,n){const f=n?{"X-Chat-Token":n}:{};let i;try{i=t==="GET"?await H.get(d,{headers:f}):await H.post(d,o,{headers:f})}catch(l){const w=l?.data||l?.response?.data;throw new Error(w?.error||"The chat could not be reached. Check your connection and try again.")}if(i&&i.error)throw new Error(i.error);return i}const Me=(t,d="time")=>{if(d==="none")return"";const o=t?new Date(t):null;if(!o||Number.isNaN(o.getTime()))return"";const n=o.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});return d!=="datetime"?n:`${new Date().toDateString()===o.toDateString()?"Today":o.toLocaleDateString([],{day:"numeric",month:"short"})}, ${n}`},re=t=>(String(t||"").trim().match(/[\p{L}\p{N}]/u)?.[0]||"?").toUpperCase();function Pe(t,d=!1,o="",n="time"){const f=Array.isArray(t.suggestions)&&t.suggestions.length?[...t.suggestions.map(l=>({key:`${t.n}-${l.i}`,n:t.n,i:l.i,label:l.label})),{key:`${t.n}-none`,n:t.n,i:-1,label:"None of these"}]:[],i=t.from==="visitor"?"You":t.name||(t.from==="system"?"":"The team");return{key:`m${t.n}`,n:t.n,from:t.from,fresh:d,cls:M.observable(`dm-chat-msg dm-chat-msg--${t.from}`),name:i,initial:re(i),avatar:t.from==="bot"?o:"",text:typeof t.text=="string"?t.text:"",html:typeof t.html=="string"?t.html:"",links:(Array.isArray(t.links)?t.links:[]).map(l=>{const w=/^https?:/i.test(l.url);return{url:l.url,label:l.label,target:w?"_blank":"_self",rel:w?"noopener noreferrer":""}}),choices:f,starters:[],time:Me(t.at,n)}}function _e(t){const d=o=>o?`${o.from}|${o.name}`:"";return t.forEach((o,n)=>{const f=l=>l&&l.from!=="system"&&d(l)===d(o),i=[`dm-chat-msg dm-chat-msg--${o.from}`];o.from!=="system"&&f(t[n-1])&&i.push("is-cont"),o.from!=="system"&&f(t[n+1])&&i.push("has-next"),o.fresh&&i.push("is-new"),o.cls.value=i.join(" ")}),t}const qe=`
|
|
2
2
|
<div class="dm-chat" data-bind-class="rootClass.value">
|
|
3
3
|
<div class="dm-chat-character" hidden>
|
|
4
4
|
<span class="dm-chat-character-stage"></span>
|
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=20261111-knowledge-switch";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=20261111-
|
|
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=20261111-knowledge-switch";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=20261111-remy-character";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",".admin-assistant-trigger"].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>
|
|
@@ -9,4 +9,4 @@ import{LAUNCHER_LIMITS as C,launcherChatBox as mt,launcherModalBox as pt,launche
|
|
|
9
9
|
<button type="button" class="dm-launcher-chat-close" data-on-click="close" aria-label="Close"><span data-icon="x" aria-hidden="true"></span></button>
|
|
10
10
|
</div>
|
|
11
11
|
<div class="dm-launcher-chat-body"></div>
|
|
12
|
-
<p class="dm-launcher-note" data-bind-hidden="!note.value" data-bind-text="note.value"></p>`;function Mt(i){const c=i.getBoundingClientRect();return getComputedStyle(i).opacity!=="0"||i.offsetParent!==null?c:{top:Math.min(c.top,i.offsetTop),left:Math.min(c.left,i.offsetLeft),right:Math.max(c.right,i.offsetLeft+i.offsetWidth),bottom:Math.max(c.bottom,i.offsetTop+i.offsetHeight)}}function nt(i){window.Domma?.icons?.scan&&window.Domma.icons.scan(i)}function ot(i,{fill:c}){const r=document.createElement("iframe");if(r.className="dm-launcher-frame"+(c?" is-fill":""),r.title=i.action.title,r.src=`/_launcher/${encodeURIComponent(i.id)}`,r.setAttribute("loading","eager"),!c){let u=null;r.addEventListener("load",()=>{const H=r.contentDocument;if(!H?.body)return;const S=H.querySelector(".site-content")||H.body,R=()=>{r.style.height=`${Math.ceil(S.getBoundingClientRect().height)}px`};R(),u?.disconnect(),u=new ResizeObserver(R),u.observe(S)})}return r}export function mountLaunchers(i){if(!Array.isArray(i)||!i.length||document.querySelector(".dm-launchers"))return null;const c=M.observable(matchMedia(J).matches),r=document.createElement("div");r.className="dm-launchers";const u=i.map(t=>{const n=o=>o&&t.phone?.override?{...t,...t.phone}:t,e=t.triggerStyle==="icon-text",a=o=>{const v=n(o),x={"--launcher-size":`${v.size}px`,"--launcher-radius":`${e?999:Math.min(t.radius,Math.floor(v.size/2))}px`,"--launcher-glyph":`${Math.round(v.size*20/52)}px`};return t.colours.background&&(x["--launcher-bg"]=t.colours.background),t.colours.text&&(x["--launcher-fg"]=t.colours.text),x},d=M.observable(-9999),m=M.observable(-9999);return{id:t.id,label:t.label,icon:t.icon,pill:e,launcher:t,look:n,left:d,top:m,cls:["dm-launcher--"+t.action.type,e?"dm-launcher--pill":"",t.class].filter(Boolean).join(" "),style:M.computed(()=>({...a(c.value),left:`${d.value}px`,top:`${m.value}px`})),expanded:M.observable("false"),hidden:M.computed(()=>t.disc===!1||t.devices==="desktop"&&c.value||t.devices==="phone"&&!c.value)}});r.innerHTML='<div class="dm-launchers-list" data-each="rows.value key=id"></div>',r.firstElementChild.innerHTML=wt;const H=M.applyBindings({rows:M.observable(u)},r);document.body.appendChild(r),nt(r);const S=t=>r.querySelector(`.dm-launcher[data-id="${CSS.escape(t)}"]`),R=[];for(const t of u){const n=t.launcher.chat;if(!n?.bot||!n.character||n.characterOptions?.enabled===!1||n.characterOptions?.launchers===!1)continue;const e=S(t.id);if(!e)continue;e.classList.add("dm-character-disc");const a=e.querySelector(".dm-launcher-label"),d=gt(e,{id:n.character,portrait:!0,animated:!1});a&&e.appendChild(a),R.push(d)}const at={TL:"right",ML:"right",BL:"right",TR:"left",MR:"left",BR:"left",TC:"bottom",BC:"top"},B=new Map;for(const t of u){const n=t.launcher.tooltip,e=S(t.id);if(!(!n||!e||typeof E.tooltip!="function"))try{B.set(t.id,E.tooltip(e,{content:n,position:at[t.launcher.position]||"top",trigger:"hover focus",className:"dm-launcher-tip"}))}catch{}}function D(){const t=document.documentElement.clientWidth,n=window.innerHeight,e=[...document.querySelectorAll(Q)].filter(a=>!r.contains(a)&&getComputedStyle(a).position==="fixed"&&getComputedStyle(a).display!=="none").map(Mt);for(const a of u){const d=S(a.id);if(!d||d.hidden)continue;const m=a.look(c.peek()),o=d.offsetWidth,v=d.offsetHeight,x=ft(m.position,{w:o,h:v,vw:t,vh:n,offsetX:m.offsetX,offsetY:m.offsetY}),T=vt(m.position,x,{w:o,h:v},e),z=Math.max(0,Math.min(t-o,T.left)),_=Math.max(0,Math.min(n-v,T.top));a.left.value=z,a.top.value=_,e.push({left:z,top:_,right:z+o,bottom:_+v})}}let q=0;const A=()=>{cancelAnimationFrame(q),q=requestAnimationFrame(D)},K=new MutationObserver(t=>{t.some(n=>[...n.addedNodes].some(e=>e.nodeType===1&&e.matches?.(Q)))&&A()});K.observe(document.body,{childList:!0});const P=matchMedia(J),U=()=>{c.value=P.matches,A()};P.addEventListener?.("change",U),window.addEventListener("resize",A),window.addEventListener("load",A,{once:!0}),D();let g=null;const it=M.effect(()=>{const t=u.some(n=>n.expanded.value==="true"&&(n.launcher.action.type!=="chat"||c.value));document.documentElement.classList.toggle("dm-launcher-covering",t)});function Y(){const t=g;g=null,t&&(t.row.expanded.value="false",t.close())}function ct(t){const n=t.launcher,e=pt(n.action),a=E.modal({title:n.action.title,size:e.width,content:ot(n,{fill:!!e.height}),className:"dm-launcher-modal",bodyClass:"dm-launcher-modal-body",buttons:[],animation:et()?!1:"fade",onClosed:()=>{g?.row===t&&(g=null,t.expanded.value="false"),setTimeout(()=>{try{a.destroy()}catch{}},0)}});return a.element?.classList.add("dm-launcher-modal",`dm-launcher-modal--${n.action.size}`),a.element?.style.setProperty("--launcher-modal-w",e.width),e.height&&(a.element?.classList.add("dm-launcher-modal--fixed"),a.element?.style.setProperty("--launcher-modal-h",e.height)),a.open(),()=>{try{a.close()}catch{}}}function st(t){const n=t.launcher,e=E.slideover({title:yt(n.action.title),position:n.action.side,size:c.peek()?"full":tt[n.action.width]||tt.md,content:ot(n,{fill:!0}),bodyClass:"dm-launcher-so-body",animation:!et(),onClosed:()=>{g?.row===t&&(g=null,t.expanded.value="false"),setTimeout(()=>{try{e.destroy?.()}catch{}e.element?.remove()},0)}});return e.element?.classList.add("dm-launcher-so"),e.open(),()=>{try{e.close()}catch{}}}function rt(t,n){const e=t.launcher,a=S(t.id),d=a&&!a.hidden?a:null,m=d||(n?.isConnected?n:null),o=document.createElement("div");o.className="dm-launcher-chat",o.setAttribute("role","dialog"),o.setAttribute("aria-label",e.action.title),o.innerHTML=xt;const v=M.observable("");let x=null,T=!1;const z=()=>{if(!T){T=!0;try{x?.destroy?.()}catch{}_.dispose?.(),o.remove(),document.removeEventListener("keydown",G),window.removeEventListener("resize",O),g?.row===t&&(g=null,t.expanded.value="false"),(m?.isConnected?m:null)?.focus()}},_=M.applyBindings({title:e.action.title,note:v,close:z},o),G=l=>{l.key!=="Escape"||l.defaultPrevented||!o.contains(document.activeElement)||(l.preventDefault(),z())},O=()=>{if(c.peek()){o.classList.add("is-full"),o.removeAttribute("style");return}o.classList.remove("is-full");const l=document.documentElement.clientWidth,s=window.innerHeight,N=e.chat?.resizable!==!1&&bt(e.id)||mt(e.chat||{}),y=Math.min(Math.max(C.chatWidth[0],Number(N.width)),C.chatWidth[1],l-24),w=Math.min(Math.max(C.chatHeight[0],Number(N.height)),C.chatHeight[1],s-24),p=L=>Math.max(12,Math.min(l-y-12,L)),h=L=>Math.max(12,Math.min(s-w-12,L));let b,k;if(!d){b=p(e.position[1]==="L"?24:l-y-24),k=h(s-w-24),Object.assign(o.style,{left:`${b}px`,top:`${k}px`,width:`${y}px`,height:`${w}px`});return}const f=d.getBoundingClientRect(),$=f.left+f.width/2>l/2;e.position[0]==="M"?(b=p($?f.left-y-12:f.right+12),k=h(f.top+f.height/2-w/2)):(b=p($?f.right-y:f.left),k=e.position[0]==="T"?h(f.bottom+12):h(f.top-w-12)),Object.assign(o.style,{left:`${b}px`,top:`${k}px`,width:`${y}px`,height:`${w}px`})};if(document.body.appendChild(o),O(),e.chat?.resizable!==!1){const l=document.createElement("div");l.className="dm-launcher-chat-grip",l.setAttribute("role","separator"),l.setAttribute("aria-label","Resize the chat"),l.title="Drag to resize",o.appendChild(l);let s=null;const N=p=>{if(!s)return;const h=document.documentElement.clientWidth,b=window.innerHeight,k=(p.clientX-s.x)*(s.fromLeft?-1:1),f=(p.clientY-s.y)*(s.fromTop?-1:1),$=Math.round(Math.min(Math.max(C.chatWidth[0],s.w+k),C.chatWidth[1],h-24)),L=Math.round(Math.min(Math.max(C.chatHeight[0],s.h+f),C.chatHeight[1],b-24)),ht=s.fromLeft?s.right-$:s.left,ut=s.fromTop?s.bottom-L:s.top;Object.assign(o.style,{width:`${$}px`,height:`${L}px`,left:`${Math.max(12,Math.min(h-$-12,ht))}px`,top:`${Math.max(12,Math.min(b-L-12,ut))}px`}),s.size={width:$,height:L}},y=()=>{s&&(s.size&&Z(e.id,s.size),s=null,o.classList.remove("is-resizing"),window.removeEventListener("pointermove",N),window.removeEventListener("pointerup",y))},w=()=>{const[p,h]=String(e.position||"BR");l.dataset.corner=`${p==="T"?"b":"t"}${h==="L"?"r":"l"}`};w(),l.addEventListener("pointerdown",p=>{if(c.peek())return;p.preventDefault();const h=o.getBoundingClientRect(),b=l.dataset.corner;s={x:p.clientX,y:p.clientY,w:h.width,h:h.height,left:h.left,top:h.top,right:h.right,bottom:h.bottom,fromLeft:b[1]==="l",fromTop:b[0]==="t"},o.classList.add("is-resizing"),window.addEventListener("pointermove",N),window.addEventListener("pointerup",y)}),l.addEventListener("dblclick",()=>{Z(e.id,null),O(),w()})}nt(o),document.addEventListener("keydown",G),window.addEventListener("resize",O);const dt=o.querySelector(".dm-launcher-chat-body");return import("/public/js/launcher-chat.mjs?v=20261111-knowledge-switch").then(l=>{if(!T){if(typeof l.mountChat!="function")throw new Error("no mountChat");x=l.mountChat(dt,{launcherId:e.id,title:e.action.title,chat:e.chat||{}})}}).catch(()=>{T||(v.value="Chat is unavailable right now. Please try again later.")}),o.querySelector(".dm-launcher-chat-close")?.focus(),z}function I(t,n=null){const e=u.find(o=>o.id===t);if(!e)return;const a=g?.row===e;if(Y(),a)return;e.expanded.value="true";try{B.get(e.id)?.close()}catch{}const d=e.launcher.action.type,m=d==="chat"?rt(e,n):d==="slideover"?st(e):ct(e);g={row:e,close:m}}const j=t=>{const n=t.target.closest(".dm-launcher");n&&I(n.dataset.id)};r.addEventListener("click",j);const F=/^#launcher-([a-z0-9][a-z0-9-]{0,39})$/,lt=t=>{const n=t.closest("[data-launcher]");if(n)return{el:n,id:n.dataset.launcher};const e=t.closest("a[href]"),a=e&&F.exec(e.getAttribute("href")||"");return a?{el:e,id:a[1]}:null},X=t=>{if(t.button>0||t.metaKey||t.ctrlKey||t.shiftKey||t.altKey||r.contains(t.target))return;const n=t.target instanceof Element?lt(t.target):null;!n||!u.some(e=>e.id===n.id)||(t.preventDefault(),I(n.id,n.el))};document.addEventListener("click",X);const W=F.exec(location.hash);return W&&u.some(t=>t.id===W[1])&&(history.replaceState(history.state,"",location.pathname+location.search),setTimeout(()=>I(W[1]),0)),{place:D,launch:I,destroy(){Y(),it?.(),document.documentElement.classList.remove("dm-launcher-covering"),R.forEach(t=>t.destroy());for(const t of B.values())try{t.destroy()}catch{}B.clear(),cancelAnimationFrame(q),K.disconnect(),P.removeEventListener?.("change",U),window.removeEventListener("resize",A),window.removeEventListener("load",A),r.removeEventListener("click",j),document.removeEventListener("click",X),H?.dispose?.(),r.remove()}}}typeof window<"u"&&Array.isArray(window.__CMS_LAUNCHERS__)&&window.M&&window.E&&(window.DommaLaunchers=mountLaunchers(window.__CMS_LAUNCHERS__));
|
|
12
|
+
<p class="dm-launcher-note" data-bind-hidden="!note.value" data-bind-text="note.value"></p>`;function Mt(i){const c=i.getBoundingClientRect();return getComputedStyle(i).opacity!=="0"||i.offsetParent!==null?c:{top:Math.min(c.top,i.offsetTop),left:Math.min(c.left,i.offsetLeft),right:Math.max(c.right,i.offsetLeft+i.offsetWidth),bottom:Math.max(c.bottom,i.offsetTop+i.offsetHeight)}}function nt(i){window.Domma?.icons?.scan&&window.Domma.icons.scan(i)}function ot(i,{fill:c}){const r=document.createElement("iframe");if(r.className="dm-launcher-frame"+(c?" is-fill":""),r.title=i.action.title,r.src=`/_launcher/${encodeURIComponent(i.id)}`,r.setAttribute("loading","eager"),!c){let u=null;r.addEventListener("load",()=>{const H=r.contentDocument;if(!H?.body)return;const S=H.querySelector(".site-content")||H.body,R=()=>{r.style.height=`${Math.ceil(S.getBoundingClientRect().height)}px`};R(),u?.disconnect(),u=new ResizeObserver(R),u.observe(S)})}return r}export function mountLaunchers(i){if(!Array.isArray(i)||!i.length||document.querySelector(".dm-launchers"))return null;const c=M.observable(matchMedia(J).matches),r=document.createElement("div");r.className="dm-launchers";const u=i.map(t=>{const n=o=>o&&t.phone?.override?{...t,...t.phone}:t,e=t.triggerStyle==="icon-text",a=o=>{const v=n(o),x={"--launcher-size":`${v.size}px`,"--launcher-radius":`${e?999:Math.min(t.radius,Math.floor(v.size/2))}px`,"--launcher-glyph":`${Math.round(v.size*20/52)}px`};return t.colours.background&&(x["--launcher-bg"]=t.colours.background),t.colours.text&&(x["--launcher-fg"]=t.colours.text),x},d=M.observable(-9999),m=M.observable(-9999);return{id:t.id,label:t.label,icon:t.icon,pill:e,launcher:t,look:n,left:d,top:m,cls:["dm-launcher--"+t.action.type,e?"dm-launcher--pill":"",t.class].filter(Boolean).join(" "),style:M.computed(()=>({...a(c.value),left:`${d.value}px`,top:`${m.value}px`})),expanded:M.observable("false"),hidden:M.computed(()=>t.disc===!1||t.devices==="desktop"&&c.value||t.devices==="phone"&&!c.value)}});r.innerHTML='<div class="dm-launchers-list" data-each="rows.value key=id"></div>',r.firstElementChild.innerHTML=wt;const H=M.applyBindings({rows:M.observable(u)},r);document.body.appendChild(r),nt(r);const S=t=>r.querySelector(`.dm-launcher[data-id="${CSS.escape(t)}"]`),R=[];for(const t of u){const n=t.launcher.chat;if(!n?.bot||!n.character||n.characterOptions?.enabled===!1||n.characterOptions?.launchers===!1)continue;const e=S(t.id);if(!e)continue;e.classList.add("dm-character-disc");const a=e.querySelector(".dm-launcher-label"),d=gt(e,{id:n.character,portrait:!0,animated:!1});a&&e.appendChild(a),R.push(d)}const at={TL:"right",ML:"right",BL:"right",TR:"left",MR:"left",BR:"left",TC:"bottom",BC:"top"},B=new Map;for(const t of u){const n=t.launcher.tooltip,e=S(t.id);if(!(!n||!e||typeof E.tooltip!="function"))try{B.set(t.id,E.tooltip(e,{content:n,position:at[t.launcher.position]||"top",trigger:"hover focus",className:"dm-launcher-tip"}))}catch{}}function D(){const t=document.documentElement.clientWidth,n=window.innerHeight,e=[...document.querySelectorAll(Q)].filter(a=>!r.contains(a)&&getComputedStyle(a).position==="fixed"&&getComputedStyle(a).display!=="none").map(Mt);for(const a of u){const d=S(a.id);if(!d||d.hidden)continue;const m=a.look(c.peek()),o=d.offsetWidth,v=d.offsetHeight,x=ft(m.position,{w:o,h:v,vw:t,vh:n,offsetX:m.offsetX,offsetY:m.offsetY}),T=vt(m.position,x,{w:o,h:v},e),z=Math.max(0,Math.min(t-o,T.left)),_=Math.max(0,Math.min(n-v,T.top));a.left.value=z,a.top.value=_,e.push({left:z,top:_,right:z+o,bottom:_+v})}}let q=0;const A=()=>{cancelAnimationFrame(q),q=requestAnimationFrame(D)},K=new MutationObserver(t=>{t.some(n=>[...n.addedNodes].some(e=>e.nodeType===1&&e.matches?.(Q)))&&A()});K.observe(document.body,{childList:!0});const P=matchMedia(J),U=()=>{c.value=P.matches,A()};P.addEventListener?.("change",U),window.addEventListener("resize",A),window.addEventListener("load",A,{once:!0}),D();let g=null;const it=M.effect(()=>{const t=u.some(n=>n.expanded.value==="true"&&(n.launcher.action.type!=="chat"||c.value));document.documentElement.classList.toggle("dm-launcher-covering",t)});function Y(){const t=g;g=null,t&&(t.row.expanded.value="false",t.close())}function ct(t){const n=t.launcher,e=pt(n.action),a=E.modal({title:n.action.title,size:e.width,content:ot(n,{fill:!!e.height}),className:"dm-launcher-modal",bodyClass:"dm-launcher-modal-body",buttons:[],animation:et()?!1:"fade",onClosed:()=>{g?.row===t&&(g=null,t.expanded.value="false"),setTimeout(()=>{try{a.destroy()}catch{}},0)}});return a.element?.classList.add("dm-launcher-modal",`dm-launcher-modal--${n.action.size}`),a.element?.style.setProperty("--launcher-modal-w",e.width),e.height&&(a.element?.classList.add("dm-launcher-modal--fixed"),a.element?.style.setProperty("--launcher-modal-h",e.height)),a.open(),()=>{try{a.close()}catch{}}}function st(t){const n=t.launcher,e=E.slideover({title:yt(n.action.title),position:n.action.side,size:c.peek()?"full":tt[n.action.width]||tt.md,content:ot(n,{fill:!0}),bodyClass:"dm-launcher-so-body",animation:!et(),onClosed:()=>{g?.row===t&&(g=null,t.expanded.value="false"),setTimeout(()=>{try{e.destroy?.()}catch{}e.element?.remove()},0)}});return e.element?.classList.add("dm-launcher-so"),e.open(),()=>{try{e.close()}catch{}}}function rt(t,n){const e=t.launcher,a=S(t.id),d=a&&!a.hidden?a:null,m=d||(n?.isConnected?n:null),o=document.createElement("div");o.className="dm-launcher-chat",o.setAttribute("role","dialog"),o.setAttribute("aria-label",e.action.title),o.innerHTML=xt;const v=M.observable("");let x=null,T=!1;const z=()=>{if(!T){T=!0;try{x?.destroy?.()}catch{}_.dispose?.(),o.remove(),document.removeEventListener("keydown",G),window.removeEventListener("resize",O),g?.row===t&&(g=null,t.expanded.value="false"),(m?.isConnected?m:null)?.focus()}},_=M.applyBindings({title:e.action.title,note:v,close:z},o),G=l=>{l.key!=="Escape"||l.defaultPrevented||!o.contains(document.activeElement)||(l.preventDefault(),z())},O=()=>{if(c.peek()){o.classList.add("is-full"),o.removeAttribute("style");return}o.classList.remove("is-full");const l=document.documentElement.clientWidth,s=window.innerHeight,N=e.chat?.resizable!==!1&&bt(e.id)||mt(e.chat||{}),y=Math.min(Math.max(C.chatWidth[0],Number(N.width)),C.chatWidth[1],l-24),w=Math.min(Math.max(C.chatHeight[0],Number(N.height)),C.chatHeight[1],s-24),p=L=>Math.max(12,Math.min(l-y-12,L)),h=L=>Math.max(12,Math.min(s-w-12,L));let b,k;if(!d){b=p(e.position[1]==="L"?24:l-y-24),k=h(s-w-24),Object.assign(o.style,{left:`${b}px`,top:`${k}px`,width:`${y}px`,height:`${w}px`});return}const f=d.getBoundingClientRect(),$=f.left+f.width/2>l/2;e.position[0]==="M"?(b=p($?f.left-y-12:f.right+12),k=h(f.top+f.height/2-w/2)):(b=p($?f.right-y:f.left),k=e.position[0]==="T"?h(f.bottom+12):h(f.top-w-12)),Object.assign(o.style,{left:`${b}px`,top:`${k}px`,width:`${y}px`,height:`${w}px`})};if(document.body.appendChild(o),O(),e.chat?.resizable!==!1){const l=document.createElement("div");l.className="dm-launcher-chat-grip",l.setAttribute("role","separator"),l.setAttribute("aria-label","Resize the chat"),l.title="Drag to resize",o.appendChild(l);let s=null;const N=p=>{if(!s)return;const h=document.documentElement.clientWidth,b=window.innerHeight,k=(p.clientX-s.x)*(s.fromLeft?-1:1),f=(p.clientY-s.y)*(s.fromTop?-1:1),$=Math.round(Math.min(Math.max(C.chatWidth[0],s.w+k),C.chatWidth[1],h-24)),L=Math.round(Math.min(Math.max(C.chatHeight[0],s.h+f),C.chatHeight[1],b-24)),ht=s.fromLeft?s.right-$:s.left,ut=s.fromTop?s.bottom-L:s.top;Object.assign(o.style,{width:`${$}px`,height:`${L}px`,left:`${Math.max(12,Math.min(h-$-12,ht))}px`,top:`${Math.max(12,Math.min(b-L-12,ut))}px`}),s.size={width:$,height:L}},y=()=>{s&&(s.size&&Z(e.id,s.size),s=null,o.classList.remove("is-resizing"),window.removeEventListener("pointermove",N),window.removeEventListener("pointerup",y))},w=()=>{const[p,h]=String(e.position||"BR");l.dataset.corner=`${p==="T"?"b":"t"}${h==="L"?"r":"l"}`};w(),l.addEventListener("pointerdown",p=>{if(c.peek())return;p.preventDefault();const h=o.getBoundingClientRect(),b=l.dataset.corner;s={x:p.clientX,y:p.clientY,w:h.width,h:h.height,left:h.left,top:h.top,right:h.right,bottom:h.bottom,fromLeft:b[1]==="l",fromTop:b[0]==="t"},o.classList.add("is-resizing"),window.addEventListener("pointermove",N),window.addEventListener("pointerup",y)}),l.addEventListener("dblclick",()=>{Z(e.id,null),O(),w()})}nt(o),document.addEventListener("keydown",G),window.addEventListener("resize",O);const dt=o.querySelector(".dm-launcher-chat-body");return import("/public/js/launcher-chat.mjs?v=20261111-remy-character").then(l=>{if(!T){if(typeof l.mountChat!="function")throw new Error("no mountChat");x=l.mountChat(dt,{launcherId:e.id,title:e.action.title,chat:e.chat||{}})}}).catch(()=>{T||(v.value="Chat is unavailable right now. Please try again later.")}),o.querySelector(".dm-launcher-chat-close")?.focus(),z}function I(t,n=null){const e=u.find(o=>o.id===t);if(!e)return;const a=g?.row===e;if(Y(),a)return;e.expanded.value="true";try{B.get(e.id)?.close()}catch{}const d=e.launcher.action.type,m=d==="chat"?rt(e,n):d==="slideover"?st(e):ct(e);g={row:e,close:m}}const j=t=>{const n=t.target.closest(".dm-launcher");n&&I(n.dataset.id)};r.addEventListener("click",j);const F=/^#launcher-([a-z0-9][a-z0-9-]{0,39})$/,lt=t=>{const n=t.closest("[data-launcher]");if(n)return{el:n,id:n.dataset.launcher};const e=t.closest("a[href]"),a=e&&F.exec(e.getAttribute("href")||"");return a?{el:e,id:a[1]}:null},X=t=>{if(t.button>0||t.metaKey||t.ctrlKey||t.shiftKey||t.altKey||r.contains(t.target))return;const n=t.target instanceof Element?lt(t.target):null;!n||!u.some(e=>e.id===n.id)||(t.preventDefault(),I(n.id,n.el))};document.addEventListener("click",X);const W=F.exec(location.hash);return W&&u.some(t=>t.id===W[1])&&(history.replaceState(history.state,"",location.pathname+location.search),setTimeout(()=>I(W[1]),0)),{place:D,launch:I,destroy(){Y(),it?.(),document.documentElement.classList.remove("dm-launcher-covering"),R.forEach(t=>t.destroy());for(const t of B.values())try{t.destroy()}catch{}B.clear(),cancelAnimationFrame(q),K.disconnect(),P.removeEventListener?.("change",U),window.removeEventListener("resize",A),window.removeEventListener("load",A),r.removeEventListener("click",j),document.removeEventListener("click",X),H?.dispose?.(),r.remove()}}}typeof window<"u"&&Array.isArray(window.__CMS_LAUNCHERS__)&&window.M&&window.E&&(window.DommaLaunchers=mountLaunchers(window.__CMS_LAUNCHERS__));
|
|
@@ -27,6 +27,8 @@ import {getMenu} from '../../services/menus.js';
|
|
|
27
27
|
import {resolveAdminHome} from '../../services/adminHome.js';
|
|
28
28
|
import {adminAccessFor} from '../../services/adminAccess.js';
|
|
29
29
|
import {adminBrandFor} from '../../services/adminBrand.js';
|
|
30
|
+
import {seesNotificationsScreen} from '../../services/adminPortal.js';
|
|
31
|
+
import {getAdminPortal} from '../../services/plugins.js';
|
|
30
32
|
import {authenticate, checkVisibility} from '../../middleware/auth.js';
|
|
31
33
|
import {getRoleLevel} from '../../services/roles.js';
|
|
32
34
|
import {getEffectiveRegistry, GROUP_ORDER} from '../../services/permissionRegistry.js';
|
|
@@ -238,7 +240,7 @@ export async function authRoutes(fastify) {
|
|
|
238
240
|
// grants on the union, so the sidebar must hide on the union too.
|
|
239
241
|
// adminScope: null = the whole admin; otherwise {home, allow} - the
|
|
240
242
|
// screens this user's roles confine them to (see roles.getAdminScope).
|
|
241
|
-
const {permissions, adminScope} = adminAccessFor(request.user);
|
|
243
|
+
const {roles, permissions, adminScope} = adminAccessFor(request.user);
|
|
242
244
|
// adminHome: the screen `#/` opens for this user - see services/adminHome.js.
|
|
243
245
|
// The menu is read only when a site home has to be checked against it.
|
|
244
246
|
let adminHome = await resolveAdminHome({
|
|
@@ -253,8 +255,13 @@ export async function authRoutes(fastify) {
|
|
|
253
255
|
if (!adminScope && isDashboardPro() && (await readPrefs(request.user)).home) adminHome = '/dashboards';
|
|
254
256
|
// adminBrand: the admin's name and mark for the top bar, sidebar header and tab title.
|
|
255
257
|
// A confined user is shown none of the admin's chrome (versions included) - see admin-scope.js.
|
|
258
|
+
// adminPortal: a confined user's Tool draws the top bar and names the admin (services/adminPortal.js).
|
|
259
|
+
const adminPortal = adminScope ? await getAdminPortal(adminScope).catch(() => null) : null;
|
|
260
|
+
const adminBrand = adminBrandFor(getConfig('site'));
|
|
261
|
+
if (adminPortal) adminBrand.title = adminPortal.title;
|
|
262
|
+
// notificationsScreen: the site's own Notifications screen is for admins; everyone else has the bell.
|
|
256
263
|
return {permissions, adminScope, adminHome, ...(!adminScope && {versions: frameworkVersions()}),
|
|
257
|
-
adminBrand:
|
|
264
|
+
adminBrand, adminPortal, notificationsScreen: seesNotificationsScreen(roles)};
|
|
258
265
|
});
|
|
259
266
|
|
|
260
267
|
// GET /api/auth/permissions-registry - returns the full permissions registry,
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Tool's portal - how the admin looks to a user whose roles confine them to
|
|
3
|
+
* that one Tool (a Job Board candidate, company or agency).
|
|
4
|
+
*
|
|
5
|
+
* A plugin opts in with `admin.portal` in its plugin.json:
|
|
6
|
+
*
|
|
7
|
+
* "portal": {"title": "Job Board", "nav": "/api/plugins/job-board/portal-nav"}
|
|
8
|
+
*
|
|
9
|
+
* For a confined user whose home is one of that plugin's admin routes, the
|
|
10
|
+
* admin then drops the side menu, names itself `title` (top bar, tab title),
|
|
11
|
+
* and draws the top bar's menus from `nav`: a GET under the plugin's own API
|
|
12
|
+
* answering `{items: [{text, url, icon?, count?, label?, tone?}]}` for the
|
|
13
|
+
* signed-in user. The plugin decides who sees which section and what each
|
|
14
|
+
* count is; core only draws them (admin/js/lib/admin-portal.js).
|
|
15
|
+
*
|
|
16
|
+
* Pure: plugins.js getAdminPortal() feeds it the manifests.
|
|
17
|
+
*
|
|
18
|
+
* @module server/services/adminPortal
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const squash = (v) => (typeof v === 'string' ? v.replace(/[ \t\n\f\r]+/g, ' ').trim() : '');
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A manifest's portal, cleaned, or null when it declares none (or only junk).
|
|
25
|
+
* `nav` must be a path under the plugin's own API - a portal can never point
|
|
26
|
+
* the admin's requests anywhere else.
|
|
27
|
+
*
|
|
28
|
+
* @param {object} manifest - plugin.json
|
|
29
|
+
* @returns {{plugin: string, title: string, nav: string|null, paths: string[]}|null}
|
|
30
|
+
*/
|
|
31
|
+
export function portalOf(manifest) {
|
|
32
|
+
const p = manifest?.admin?.portal;
|
|
33
|
+
if (!p || typeof p !== 'object' || Array.isArray(p) || typeof manifest.name !== 'string') return null;
|
|
34
|
+
const title = squash(p.title).slice(0, 60);
|
|
35
|
+
const prefix = `/api/plugins/${manifest.name}/`;
|
|
36
|
+
const nav = typeof p.nav === 'string' && p.nav.startsWith(prefix) && /^\/api\/plugins\/[a-z0-9-]+\/[a-z0-9/_-]+$/i.test(p.nav)
|
|
37
|
+
? p.nav : null;
|
|
38
|
+
if (!title && !nav) return null;
|
|
39
|
+
const paths = (manifest.admin.routes || []).map(r => r?.path).filter(s => typeof s === 'string' && s.startsWith('/'));
|
|
40
|
+
return {plugin: manifest.name, title: title || squash(manifest.displayName) || manifest.name, nav, paths};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The portal for a confined user: the first plugin with a portal that owns
|
|
45
|
+
* the scope's home screen. Null for a user the admin does not confine.
|
|
46
|
+
*
|
|
47
|
+
* @param {{home: string, allow: string[]}|null} scope - roles.getAdminScope()
|
|
48
|
+
* @param {object[]} manifests - the loaded, enabled plugins' manifests
|
|
49
|
+
* @returns {{plugin: string, title: string, nav: string|null, home: string}|null}
|
|
50
|
+
*/
|
|
51
|
+
export function adminPortalFor(scope, manifests = []) {
|
|
52
|
+
const home = typeof scope?.home === 'string' ? scope.home.split('?')[0] : '';
|
|
53
|
+
if (!home) return null;
|
|
54
|
+
for (const manifest of manifests) {
|
|
55
|
+
const portal = portalOf(manifest);
|
|
56
|
+
if (portal && portal.paths.includes(home)) return {plugin: portal.plugin, title: portal.title, nav: portal.nav, home};
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Notifications' own screen (#/system/notifications - every severity, the
|
|
63
|
+
* site's maintenance and update messages) is for the site's administrators:
|
|
64
|
+
* the roles a notification with no audience goes to (services/notify.js
|
|
65
|
+
* AUDIENCES.admins). Everyone else has the bell, which lists their own.
|
|
66
|
+
*
|
|
67
|
+
* @param {string[]} roles - every role the user holds (getEffectiveRoles)
|
|
68
|
+
* @returns {boolean}
|
|
69
|
+
*/
|
|
70
|
+
export function seesNotificationsScreen(roles = []) {
|
|
71
|
+
return roles.includes('super-admin') || roles.includes('admin');
|
|
72
|
+
}
|
|
@@ -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 = '20261111-
|
|
29
|
+
export const LAUNCHERS_ASSET_V = '20261111-remy-character';
|
|
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() {
|
|
@@ -53,6 +53,7 @@ import * as defaultUsersService from './users.js';
|
|
|
53
53
|
import {registerLoginCheck, registerPasswordCheck} from './authChecks.js';
|
|
54
54
|
import {invalidateTags as cacheInvalidateTags} from './cache/index.js';
|
|
55
55
|
import {CORE_TOOLS, getToolStates, toolOpenAt, unmetRequirements} from './tools.js';
|
|
56
|
+
import {adminPortalFor} from './adminPortal.js';
|
|
56
57
|
|
|
57
58
|
const PLUGINS_DIR = path.resolve('plugins');
|
|
58
59
|
|
|
@@ -1382,6 +1383,20 @@ export function viewSection(manifest, viewName) {
|
|
|
1382
1383
|
return text && text !== (manifest.displayName || manifest.name) ? text : '';
|
|
1383
1384
|
}
|
|
1384
1385
|
|
|
1386
|
+
/**
|
|
1387
|
+
* The portal a confined user sees (services/adminPortal.js): the enabled,
|
|
1388
|
+
* loaded plugin whose `admin.portal` owns the scope's home screen, or null.
|
|
1389
|
+
*
|
|
1390
|
+
* @param {{home: string, allow: string[]}|null} scope
|
|
1391
|
+
*/
|
|
1392
|
+
export async function getAdminPortal(scope) {
|
|
1393
|
+
if (!scope?.home) return null;
|
|
1394
|
+
const states = getPluginStates();
|
|
1395
|
+
const manifests = (await discoverPlugins()).filter(m => (states[m.name]?.enabled || CORE_PLUGINS.has(m.name))
|
|
1396
|
+
&& m.admin && !_blockedPlugins.has(m.name));
|
|
1397
|
+
return adminPortalFor(scope, manifests);
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1385
1400
|
/**
|
|
1386
1401
|
* @param {object} [viewer] request.user - a staff-only Tool (services/tools.js) is on for a staff session only
|
|
1387
1402
|
*/
|