domma-cms 1.27.3 → 1.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/CLAUDE.md +2 -2
- package/admin/js/app.js +4 -4
- package/admin/js/lib/chats-arrange.js +2 -0
- package/admin/js/lib/launchers-arrange.js +2 -0
- package/admin/js/lib/menu-item-help.js +1 -1
- package/admin/js/lib/page-image-hosts.js +2 -2
- package/admin/js/lib/shortcode-form.js +6 -6
- package/admin/js/lib/shortcode-registry.js +1 -1
- package/admin/js/templates/chat-knowledge.html +96 -0
- package/admin/js/templates/chats.html +146 -0
- package/admin/js/templates/docs/usage-chat.html +96 -0
- package/admin/js/templates/docs/usage-launchers.html +83 -0
- package/admin/js/templates/docs/usage-media.html +14 -0
- package/admin/js/templates/docs/usage-navigation.html +3 -0
- package/admin/js/templates/docs/usage-shortcodes.html +8 -0
- package/admin/js/templates/documentation.html +8 -0
- package/admin/js/templates/launchers.html +105 -0
- package/admin/js/views/chat-knowledge.js +60 -0
- package/admin/js/views/chats.js +53 -0
- package/admin/js/views/doc-pages.js +1 -1
- package/admin/js/views/index.js +1 -1
- package/admin/js/views/launchers.js +230 -0
- package/admin/js/views/menu-editor.js +22 -22
- package/admin/js/views/page-editor.js +10 -10
- package/docs/DommaFeatures.md +30 -0
- package/docs/markdown-shortcodes.md +69 -16
- package/package.json +1 -1
- package/public/css/image-zoom.css +1 -0
- package/public/css/launcher-chat.css +1 -0
- package/public/css/launchers.css +1 -0
- package/public/css/site.css +1 -1
- package/public/js/image-zoom.mjs +30 -0
- package/public/js/launcher-chat.mjs +47 -0
- package/public/js/launcher-settings.mjs +2 -0
- package/public/js/launchers.mjs +12 -0
- package/public/js/motion-control.mjs +1 -1
- package/public/js/site.js +1 -1
- package/server/routes/api/chat.js +203 -0
- package/server/routes/api/chats.js +235 -0
- package/server/routes/api/launchers.js +50 -0
- package/server/routes/launcher-public.js +96 -0
- package/server/server.js +33 -0
- package/server/services/adapterRegistry.js +4 -4
- package/server/services/adapters/FileAdapter.js +18 -0
- package/server/services/adapters/MongoAdapter.js +14 -0
- package/server/services/chat/conversation.js +458 -0
- package/server/services/chat/launcher-bridge.js +73 -0
- package/server/services/chat/matcher.js +324 -0
- package/server/services/chat/settings.js +118 -0
- package/server/services/chat/store.js +532 -0
- package/server/services/collectionAccess.js +16 -0
- package/server/services/docs.js +2 -0
- package/server/services/launchers.js +172 -0
- package/server/services/markdown.js +175 -4
- package/server/services/number-fields-migration.js +4 -0
- package/server/services/permissionRegistry.js +12 -0
- package/server/services/presetCollections.js +75 -2
- package/server/services/renderer.js +86 -18
- package/server/services/roles.js +1 -1
- package/server/services/tools.js +1 -0
- package/server/templates/page.html +4 -2
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import{apiRequest as ce}from"../api.js";import{helpPopovers as W}from"../lib/help-popover.js";import{onceClosed as de,openMenuAt as H,viewLifetime as ue}from"../lib/tool-kit.js";import{arrangeKnowledge as pe,describeTest as F,linksToRows as ke,mayDo as be,rowsToLinks as Y}from"../lib/chats-arrange.js";const he=/^#\/launchers\/knowledge\b/,c=(f,l="GET",g)=>ce(f,{method:l,...g!==void 0?{body:JSON.stringify(g)}:{}});function ve(f){const l=document.createElement("template");return l.innerHTML=f.trim(),l.content.firstElementChild}const me=`
|
|
2
|
+
<article class="ck-card" data-id="{{id}}" tabindex="0" data-bind-class="off && 'is-off'">
|
|
3
|
+
<h3 class="ck-q">{{question}}</h3>
|
|
4
|
+
<p class="ck-a">{{preview}}</p>
|
|
5
|
+
<div class="ck-meta"><span>{{meta}}</span><span>{{waysText}}</span>
|
|
6
|
+
<span class="ck-chip ck-chip--warn" data-bind-hidden="!sample">Example</span><span class="ck-chip" data-bind-hidden="!off">Off</span></div>
|
|
7
|
+
<button type="button" class="ck-kebab" aria-label="Entry actions" title="Actions">\u22EE</button>
|
|
8
|
+
</article>`,ye=`
|
|
9
|
+
<article class="ck-card ck-uq" data-id="{{id}}" tabindex="0">
|
|
10
|
+
<h3 class="ck-q">{{text}}</h3>
|
|
11
|
+
<div class="ck-meta"><span>{{asked}}</span><span>{{bestText}}</span></div>
|
|
12
|
+
<button type="button" class="ck-kebab" aria-label="Question actions" title="Actions">\u22EE</button>
|
|
13
|
+
</article>`,k=ue(he);export const chatKnowledgeView={templateUrl:"/admin/js/templates/chat-knowledge.html",async onMount(f){k.reset();const l=f.get(0);let g=!1;k.add(()=>{g=!0});const v=()=>!g&&l.isConnected,X=await c("/auth/permissions").then(t=>t.permissions||[]).catch(()=>[]);if(!v())return;const p=be(X,"chats","manage"),i=M.observable([]),b=M.observable([]),q=M.observable(/[?&]tab=unanswered/.test(location.hash)?"unanswered":"knowledge"),x=M.observable(""),z=M.observable("question"),T=M.observable(!0),S=M.observable(""),$=M.observable(""),L=M.observable(""),O=M.observable([]);k.add(M.effect(()=>{O.value=pe(i.value,{query:x.value,sort:z.value}).map(t=>({...t,waysText:t.ways?`${t.ways} other way${t.ways===1?"":"s"} of asking`:""}))}));const U=M.observable([]);k.add(M.effect(()=>{const t=x.value.trim().toLowerCase();U.value=b.value.filter(e=>!t||e.text.toLowerCase().includes(t)).map(e=>({id:e.id,text:e.text,asked:`asked ${e.count} time${e.count===1?"":"s"}${e.lastAt?`, last ${D(e.lastAt).fromNow()}`:""}`,bestText:e.best?`closest: ${e.best}`:"nothing close"}))}));const Z={tab:q,query:x,sort:z,loading:T,loadError:S,tryText:$,tryOut:L,entries:O,questions:U,canManage:p,knowledgeCount:M.computed(()=>String(i.value.length)),unansweredCount:M.computed(()=>String(b.value.length)),sampleNote:M.computed(()=>{const t=i.value.filter(e=>e.sample).length;return t?`${t} example entr${t===1?"y was":"ies were"} added to show how this works. Change them, or remove them.`:""}),emptyText:M.computed(()=>T.value||S.value?"":q.value==="knowledge"?O.value.length?"":x.value.trim()?"No entries match.":"The bot knows nothing yet. Add an entry, or turn an unanswered question into one.":U.value.length?"":x.value.trim()?"No questions match.":"Nothing unanswered. Questions the bot cannot answer appear here.")};l.querySelector(".ck-items").innerHTML=me,l.querySelector(".ck-qs").innerHTML=ye;const _=W(l,{position:"bottom"});k.add(_);async function A(){try{const[t,e]=await Promise.all([c("/chats/knowledge"),c("/chats/unanswered")]);if(!v())return;i.value=t.items||[],b.value=e.items||[],S.value=""}catch{v()&&(S.value="Could not load the Knowledge.")}finally{v()&&(T.value=!1)}}async function ee(t,e){try{const a=await c(`/chats/knowledge/${encodeURIComponent(t)}`,"PUT",{enabled:e});i.value=i.peek().map(o=>o.id===t?a:o),E.toast(e?"Entry switched on":"Entry switched off - the bot will not use it",{type:"success"})}catch(a){E.toast(a?.message||"Could not change the entry",{type:"error"})}}async function te(t){if(await E.confirm("Delete this entry? The bot stops using it at once."))try{await c(`/chats/knowledge/${encodeURIComponent(t)}`,"DELETE"),i.value=i.peek().filter(e=>e.id!==t),E.toast("Entry deleted",{type:"success"})}catch(e){E.toast(e?.message||"Could not delete the entry",{type:"error"})}}async function K(t,e=!1){try{e?await c(`/chats/unanswered/${encodeURIComponent(t)}`,"DELETE"):await c(`/chats/unanswered/${encodeURIComponent(t)}/done`,"POST",{done:!0}),b.value=b.peek().filter(a=>a.id!==t)}catch(a){E.toast(a?.message||"Could not change the list",{type:"error"})}}let m=null;function y(t,{fromUnanswered:e=null,question:a=""}={}){if(!p)return;if(m){m.so.close();return}const o=!t,d=E.slideover({title:o?"New Knowledge entry":"Edit entry",size:"md",position:"right"});m={so:d};const r=ve(`
|
|
14
|
+
<div class="ck-panel">
|
|
15
|
+
<div>
|
|
16
|
+
<label class="form-label" for="ck-ed-q">Question</label>
|
|
17
|
+
<input id="ck-ed-q" type="text" class="form-input" maxlength="300" data-model="question.value" placeholder="What are your opening hours?">
|
|
18
|
+
</div>
|
|
19
|
+
<div>
|
|
20
|
+
<label class="form-label" for="ck-ed-alt">Other ways of asking
|
|
21
|
+
<span data-help-title="Other ways of asking" data-help="One per line. The bot compares a visitor's words with the question and each of these, so put in the words people really use - 'when do you shut', 'are you open sundays'. Spelling, plurals and common words like 'cost' and 'price' are matched for you."></span>
|
|
22
|
+
</label>
|
|
23
|
+
<textarea id="ck-ed-alt" class="form-input" rows="4" data-model="alternatives.value"></textarea>
|
|
24
|
+
</div>
|
|
25
|
+
<div>
|
|
26
|
+
<label class="form-label" for="ck-ed-kw">Keywords
|
|
27
|
+
<span data-help="Comma separated. A keyword makes this entry a little more likely when a visitor uses it; on its own it never makes the bot answer."></span>
|
|
28
|
+
</label>
|
|
29
|
+
<input id="ck-ed-kw" type="text" class="form-input" maxlength="500" data-model="keywords.value" placeholder="hours, open, closed">
|
|
30
|
+
</div>
|
|
31
|
+
<div>
|
|
32
|
+
<label class="form-label" for="ck-ed-ans">Answer
|
|
33
|
+
<span data-help="What the bot says. Markdown works: **bold**, *italic*, lists and [links](/contact). Keep it short - visitors read it in a small panel."></span>
|
|
34
|
+
</label>
|
|
35
|
+
<textarea id="ck-ed-ans" class="form-input" rows="6" maxlength="4000" data-model="answer.value"></textarea>
|
|
36
|
+
</div>
|
|
37
|
+
<div>
|
|
38
|
+
<label class="form-label">Buttons under the answer
|
|
39
|
+
<span data-help="Up to five links shown as buttons: a page on this site (/contact), a web address, mailto: or tel:."></span>
|
|
40
|
+
</label>
|
|
41
|
+
<div class="ck-links" data-each="links.value key=key"></div>
|
|
42
|
+
<button type="button" class="btn btn-xs btn-ghost" data-on-click="addLink" data-bind-hidden="links.value.length >= 5">
|
|
43
|
+
<span data-icon="plus" data-icon-size="12"></span> Add a button</button>
|
|
44
|
+
</div>
|
|
45
|
+
<label style="display:flex;align-items:center;gap:.5rem;margin:0">
|
|
46
|
+
<input type="checkbox" class="form-switch" data-model="enabled.value"> The bot uses this entry
|
|
47
|
+
</label>
|
|
48
|
+
<p class="text-muted" style="margin:0;font-size:var(--dm-text-sm)" data-bind-text="tested.value" data-bind-hidden="!tested.value"></p>
|
|
49
|
+
<div class="ck-panel-actions">
|
|
50
|
+
<button type="button" class="btn btn-sm btn-ghost" data-on-click="test" title="Ask the bot the question as it stands">Try it</button>
|
|
51
|
+
<span class="spacer"></span>
|
|
52
|
+
<button type="button" class="btn btn-sm btn-ghost" data-on-click="cancel">Cancel</button>
|
|
53
|
+
<button type="button" class="btn btn-sm btn-primary" data-on-click="save" data-bind-disabled="saving.value">
|
|
54
|
+
<span data-icon="save" data-icon-size="13"></span> Save</button>
|
|
55
|
+
</div>
|
|
56
|
+
</div>`),u={question:t?.question||a||"",alternatives:t?.alternatives||"",keywords:t?.keywords||"",answer:t?.answer||"",enabled:t?t.enabled:!0,links:JSON.stringify(t?.links||[])},n={question:M.observable(u.question),alternatives:M.observable(u.alternatives),keywords:M.observable(u.keywords),answer:M.observable(u.answer),enabled:M.observable(u.enabled),links:M.observable(ke(t?.links)),saving:M.observable(!1),tested:M.observable("")},J=()=>n.question.peek()!==u.question||n.alternatives.peek()!==u.alternatives||n.keywords.peek()!==u.keywords||n.answer.peek()!==u.answer||n.enabled.peek()!==u.enabled||JSON.stringify(Y(C()))!==u.links;r.querySelector(".ck-links").innerHTML=`<div class="ck-link-row" data-key="{{key}}">
|
|
57
|
+
<input type="text" class="form-input ck-link-label" placeholder="Label" maxlength="60" value="{{label}}" aria-label="Button label">
|
|
58
|
+
<input type="text" class="form-input ck-link-url" placeholder="/contact or https://\u2026" maxlength="500" value="{{url}}" aria-label="Button link">
|
|
59
|
+
<button type="button" class="btn btn-xs btn-ghost ck-link-x" aria-label="Remove this button" style="opacity:.6"><span data-icon="x" data-icon-size="12"></span></button></div>`;const C=()=>[...r.querySelectorAll(".ck-link-row")].map(s=>({key:s.dataset.key,label:s.querySelector(".ck-link-label").value,url:s.querySelector(".ck-link-url").value})),j=async()=>{if(n.saving.peek())return;n.saving.value=!0;const s={question:n.question.peek(),alternatives:n.alternatives.peek(),keywords:n.keywords.peek(),answer:n.answer.peek(),enabled:n.enabled.peek(),links:Y(C()),...e&&{fromUnanswered:e}};try{const h=o?await c("/chats/knowledge","POST",s):await c(`/chats/knowledge/${encodeURIComponent(t.id)}`,"PUT",s);if(!v())return;i.value=o?[...i.peek(),h]:i.peek().map(w=>w.id===h.id?h:w),e&&(b.value=b.peek().filter(w=>w.id!==e)),E.toast(o?"Entry added - the bot uses it now":"Entry saved",{type:"success"}),B=!0,d.close()}catch(h){E.toast(h?.message||"Could not save the entry",{type:"error"})}finally{n.saving.value=!1}};let B=!1;d.element.appendChild(r);const oe=M.applyBindings(n,r,{methods:{save:j,cancel:()=>d.close(),addLink:()=>{n.links.value=[...C(),{key:`l${Date.now()}`,label:"",url:""}],I.scan(r)},test:async()=>{try{const s=await c("/chats/knowledge/test","POST",{text:n.question.peek()});n.tested.value=`Asked "${n.question.peek()}": ${F(s)}${o||n.answer.peek()!==u.answer?" (Unsaved changes are not in the test yet.)":""}`}catch{n.tested.value="Could not ask the bot."}}}});r.addEventListener("click",s=>{const h=s.target.closest(".ck-link-x");if(!h)return;const w=h.closest(".ck-link-row").dataset.key;n.links.value=C().filter(re=>re.key!==w)}),r.addEventListener("keydown",s=>{(s.ctrlKey||s.metaKey)&&s.key==="Enter"&&(s.preventDefault(),j())});const le=W(r);de(d,()=>{oe.dispose(),le(),window.removeEventListener("beforeunload",G),m?.so===d&&(m=null)});const ie=d.close;d.close=async(...s)=>!B&&!k.leaving&&J()&&!await E.confirm("Discard the changes to this entry?")?!1:ie(...s);const G=s=>{!B&&J()&&(s.preventDefault(),s.returnValue="")};window.addEventListener("beforeunload",G),I.scan(r),d.open(),setTimeout(()=>r.querySelector(n.question.peek()?"#ck-ed-ans":"#ck-ed-q")?.focus(),60)}k.add(()=>m?.so.close());function N(t=$.peek()){const e=String(t||"").trim();e&&($.value=e,c("/chats/knowledge/test","POST",{text:e}).then(a=>{v()&&(L.value=`"${e}": ${F(a)}`)}).catch(()=>{v()&&(L.value="Could not ask the bot.")}),l.querySelector(".ck-try")?.scrollIntoView({block:"nearest"}))}const ae=M.applyBindings(Z,l,{methods:{retry:()=>{T.value=!0,A()},showKnowledge:()=>{q.value="knowledge"},showUnanswered:()=>{q.value="unanswered"},create:()=>y(null),tryIt:()=>(N(),!1),removeExamples:async()=>{if(await E.confirm("Remove the example entries? Entries you have edited are kept."))try{const t=await c("/chats/knowledge/remove-examples","POST",{});E.toast(`${t.removed} example${t.removed===1?"":"s"} removed`,{type:"success"}),A()}catch(t){E.toast(t?.message||"Could not remove them",{type:"error"})}}}});k.add(()=>ae.dispose());const Q=t=>i.peek().find(e=>e.id===t),R=l.querySelector(".ck-list"),P=l.querySelector(".ck-unanswered"),ne=E.contextMenu(R,{cursor:"glyph",match:".ck-card",inherit:!1,density:"compact",items:t=>{const e=Q(t.dataset.id);return e?[{label:p?"Edit":"View",icon:"edit",action:()=>y(e),disabled:!p},{label:"Try its question",icon:"message-circle",action:()=>N(e.question)},...p?[{label:e.enabled?"Switch off":"Switch on",icon:e.enabled?"eye-off":"eye",action:()=>ee(e.id,!e.enabled)},{type:"divider"},{label:"Delete",icon:"trash",danger:!0,action:()=>te(e.id)}]:[]]:[]}});k.add(()=>ne?.destroy?.());const se=E.contextMenu(P,{cursor:"glyph",match:".ck-card",inherit:!1,density:"compact",items:t=>{const e=b.peek().find(o=>o.id===t.dataset.id);if(!e)return[];const a=e.best?i.peek().find(o=>o.question===e.best):null;return[{label:"Make an entry",icon:"plus",disabled:!p,action:()=>y(null,{question:e.text,fromUnanswered:e.id})},...a?[{label:`Add to "${a.question.slice(0,40)}"`,icon:"corner-down-right",disabled:!p,action:async()=>{try{const o=[a.alternatives,e.text].filter(Boolean).join(`
|
|
60
|
+
`),d=await c(`/chats/knowledge/${encodeURIComponent(a.id)}`,"PUT",{alternatives:o});i.value=i.peek().map(r=>r.id===d.id?d:r),await K(e.id),E.toast("Added as another way of asking",{type:"success"})}catch(o){E.toast(o?.message||"Could not add it",{type:"error"})}}}]:[],{label:"Try it",icon:"message-circle",action:()=>N(e.text)},{type:"divider"},{label:"Dismiss",icon:"check",disabled:!p,action:()=>K(e.id)},{label:"Delete",icon:"trash",danger:!0,disabled:!p,action:()=>K(e.id,!0)}]}});k.add(()=>se?.destroy?.()),R.addEventListener("click",t=>{const e=t.target.closest(".ck-card");if(e){if(t.target.closest(".ck-kebab")){H(e);return}y(Q(e.dataset.id))}}),P.addEventListener("click",t=>{const e=t.target.closest(".ck-card");if(!e)return;if(t.target.closest(".ck-kebab")){H(e);return}const a=b.peek().find(o=>o.id===e.dataset.id);a&&p?y(null,{question:a.text,fromUnanswered:a.id}):a&&H(e)});for(const t of[R,P])t.addEventListener("keydown",e=>{const a=e.target.closest?.(".ck-card");a&&e.key==="Enter"&&e.target===a&&a.click()});const V=t=>{t.ctrlKey||t.metaKey||t.altKey||t.target.closest?.("input, textarea, select, [contenteditable], .dm-slideover")||(t.key==="/"?(t.preventDefault(),l.querySelector(".ck-search input")?.focus()):(t.key==="n"||t.key==="N")&&p&&(t.preventDefault(),y(null)))};document.addEventListener("keydown",V),k.add(()=>document.removeEventListener("keydown",V)),I.scan(l),await A()}};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import{apiRequest as be}from"../api.js";import{addBannerAction as ge}from"../lib/plugin-chrome.js";import{helpPopovers as ae}from"../lib/help-popover.js";import{onceClosed as we,openMenuAt as se,sidebarCount as O,viewLifetime as ke}from"../lib/tool-kit.js";import{arrangeChats as Me,mayDo as ne,STATUS as Ee,threadRow as Te}from"../lib/chats-arrange.js";const Ce=/^#\/launchers\/chats\b/,oe=5e3,le=3e3,xe=3e4,re="chats.drafts",h=(c,n="GET",g)=>be(c,{method:n,...g!==void 0?{body:JSON.stringify(g)}:{}});function Se(c){const n=document.createElement("template");return n.innerHTML=c.trim(),n.content.firstElementChild}const Ne=()=>{try{const c=S.get(re);return c&&typeof c=="object"?c:{}}catch{return{}}},ce=c=>{try{S.set(re,c)}catch{}},De=`
|
|
2
|
+
<div class="chat-row" data-id="{{id}}" tabindex="0" role="button" data-bind-class="$root.openId.value === id && 'is-open'">
|
|
3
|
+
<span class="chat-row-who">{{who}}</span>
|
|
4
|
+
<span data-bind-class="chipClass">{{chip}}</span>
|
|
5
|
+
<span class="chat-row-line">{{line}}</span>
|
|
6
|
+
<span class="chat-row-meta">{{meta}}</span>
|
|
7
|
+
<span class="chat-row-unread" aria-label="unread">{{unreadText}}</span>
|
|
8
|
+
<button type="button" class="chat-row-kebab" aria-label="Chat actions" title="Actions">\u22EE</button>
|
|
9
|
+
</div>`,He=`
|
|
10
|
+
<div data-bind-class="cls">
|
|
11
|
+
<span class="chat-msg-who">{{who}} \xB7 {{time}}</span>
|
|
12
|
+
<div class="chat-msg-text">{{text}}</div>
|
|
13
|
+
<span class="chat-msg-note">{{note}}</span>
|
|
14
|
+
</div>`,l=ke(Ce);export const chatsView={templateUrl:"/admin/js/templates/chats.html",async onMount(c){l.reset();const n=c.get(0);let g=!1;l.add(()=>{g=!0});const r=()=>!g&&n.isConnected,z=await h("/auth/permissions").then(e=>e.permissions||[]).catch(()=>[]);if(!r())return;const v=ne(z,"chats","reply"),G=ne(z,"chats","manage"),d=M.observable([]),K=M.observable(""),w=M.observable("active"),p=M.observable(!0),k=M.observable(""),s=M.observable(location.hash.match(/^#\/launchers\/chats\/([A-Za-z0-9_-]+)/)?.[1]||""),i=M.observable(null),T=M.observable([]),m=M.observable(""),H=M.observable(!1),C=M.observable(!1),V=M.observable([]),W=M.observable({installed:!0,count:1});let x=0,J=!1;const U=M.observable([]);l.add(M.effect(()=>{U.value=Me(d.value,{query:K.value})}));const ie={query:K,view:w,loading:p,loadError:k,rows:U,openId:s,thread:T,reply:m,available:C,canReply:v,isEmpty:M.computed(()=>!p.value&&!k.value&&U.value.length===0),emptyText:M.computed(()=>K.value.trim()?"No chats match.":w.value==="active"?"No chats right now. They appear here as visitors start them.":"No ended chats."),countText:M.computed(()=>{if(p.value)return"";const e=d.value.filter(a=>a.status==="waiting").length,t=d.value.length;return`${t} chat${t===1?"":"s"}${e?` \xB7 ${e} waiting`:""}`}),availText:M.computed(()=>{const e=V.value;return C.value?e.length>1?`Available (${e.length} of you)`:"Available for chats":e.length?`Not available \xB7 ${e.length} other${e.length===1?"":"s"} available`:"Not available"}),noLauncherNote:M.computed(()=>{const e=W.value;return e.installed&&!e.count?"No chat launcher is switched on yet, so visitors cannot start a chat. Add a launcher with the Chat action in Launchers.":""}),head:M.computed(()=>{const e=i.value;if(!e)return{who:"",chip:"",chipClass:"chat-chip",email:"",mailto:"",meta:""};const t=Ee[e.status]||{label:e.status,tone:"muted"},a=e.startedAt?`started ${D(e.startedAt).fromNow()}`:"";return{who:e.name||"Visitor",chip:t.label,chipClass:`chat-chip chat-chip--${t.tone}`,email:e.email,mailto:e.email?`mailto:${e.email}`:"",meta:[e.page?`on ${e.page}`:"",a].filter(Boolean).join(" \xB7 ")}}),canWrite:M.computed(()=>v&&!!i.value&&i.value.status!=="closed"),canSend:M.computed(()=>v&&!H.value&&m.value.trim().length>0&&!!i.value&&i.value.status!=="closed"),replyHint:M.computed(()=>i.value?.status==="closed"?"This chat has ended.":i.value?.status==="message"?"Reply here (they see it if they come back) - or email them.":"Type a reply\u2026 (Ctrl+Enter sends)")};let y=Ne();l.add(M.effect(()=>{const e=s.peek(),t=m.value;e&&(t?y[e]=t:delete y[e],ce(y))}));const Y=e=>{m.peek().trim()&&(e.preventDefault(),e.returnValue="")};window.addEventListener("beforeunload",Y),l.add(()=>window.removeEventListener("beforeunload",Y)),n.querySelector(".chats-list").innerHTML=De,n.querySelector(".chats-msgs").innerHTML=He;const j=n.querySelector(".chats-list"),N=n.querySelector(".chats-messages"),de=ae(n,{position:"bottom"});l.add(de);let $=0,L=0,Z=0;l.add(()=>{clearTimeout($),clearTimeout(L),clearInterval(Z)});async function f(){clearTimeout($);try{const e=await h(`/chats?view=${w.peek()}`);if(!r())return;d.value=e.items||[],V.value=e.available||[],W.value=e.launchers||{installed:!0,count:1},k.value=""}catch{if(!r())return;p.peek()&&(k.value="Could not load the chats.")}finally{r()&&(p.value=!1,$=setTimeout(Q(f),oe))}}const Q=e=>()=>{if(document.hidden){$=setTimeout(Q(e),oe);return}e()};async function R(e=!1){clearTimeout(L);const t=s.peek();if(t){e&&(x=0,T.value=[]);try{const a=await h(`/chats/${encodeURIComponent(t)}?after=${x}`);if(!r()||s.peek()!==t)return;i.value=a.chat;const o=(a.messages||[]).filter(u=>u.n>x);if(o.length){const u=N.scrollHeight-N.scrollTop-N.clientHeight<80;x=Math.max(x,...o.map(_=>_.n)),T.value=[...T.peek(),...o.map(Te)],(e||u)&&requestAnimationFrame(()=>{N.scrollTop=N.scrollHeight}),O("#/launchers/chats")}d.value=d.peek().map(u=>u.id===t?{...u,...a.chat}:u)}catch(a){if(!r()||s.peek()!==t)return;if(/not found/i.test(a?.message||"")){E.toast("That chat no longer exists",{type:"warning"}),P();return}}r()&&s.peek()===t&&(L=setTimeout(()=>R(),document.hidden?le*4:le))}}function A(e){!e||s.peek()===e||(s.value=e,i.value=d.peek().find(t=>t.id===e)||null,m.value=y[e]||"",history.replaceState(null,"",`#/launchers/chats/${e}`),R(!0))}function P(){clearTimeout(L),s.value="",i.value=null,T.value=[],m.value="",history.replaceState(null,"","#/launchers/chats")}async function X(){const e=s.peek(),t=m.peek().trim();if(!(!e||!t||H.peek())){H.value=!0;try{if(await h(`/chats/${encodeURIComponent(e)}/reply`,"POST",{text:t}),!r())return;m.value="",await R(),f(),O("#/launchers/chats")}catch(a){E.toast(a?.message||"The reply was not sent",{type:"error"})}finally{r()&&(H.value=!1)}}}async function ue(e){try{await h(`/chats/${encodeURIComponent(e)}/close`,"POST",{}),E.toast("Chat ended",{type:"success"}),s.peek()===e&&R(),f(),O("#/launchers/chats")}catch(t){E.toast(t?.message||"Could not end the chat",{type:"error"})}}async function he(e){if(!(!await E.confirm("Delete this chat and all its messages? This cannot be undone.")||!r()))try{await h(`/chats/${encodeURIComponent(e)}`,"DELETE"),delete y[e],ce(y),s.peek()===e&&P(),d.value=d.peek().filter(a=>a.id!==e),O("#/launchers/chats"),E.toast("Chat deleted",{type:"success"})}catch(a){E.toast(a?.message||"Could not delete the chat",{type:"error"})}}async function q(e=!1){if(v)try{const t=await h("/chats/presence","POST",e?{leaving:!0}:{available:C.peek()});!e&&r()&&typeof t?.online=="number"&&f()}catch{}}v&&(C.value=!0,q(),Z=setInterval(()=>q(),xe),l.add(M.effect(()=>{if(C.value,!J){J=!0;return}q()})),l.add(()=>q(!0)));const pe=M.applyBindings(ie,n,{methods:{retry:()=>{p.value=!0,k.value="",f()},showActive:()=>{w.value="active",p.value=!0,f()},showClosed:()=>{w.value="closed",p.value=!0,f()},sendReply:()=>(X(),!1),back:()=>P()}});l.add(()=>pe.dispose()),n.querySelector(".chats-reply textarea")?.addEventListener("keydown",e=>{(e.ctrlKey||e.metaKey)&&e.key==="Enter"&&(e.preventDefault(),X())});const ee=e=>{const t=d.peek().find(a=>a.id===e)||(i.peek()?.id===e?i.peek():null);return t?[{label:"Open",icon:"message-circle",action:()=>A(e)},...t.email?[{label:"Email the visitor",icon:"mail",action:()=>{location.href=`mailto:${t.email}`}},{label:"Copy email address",icon:"copy",action:()=>navigator.clipboard?.writeText(t.email).then(()=>E.toast("Copied",{type:"success"})).catch(()=>{})}]:[],...t.page?[{label:"Open the page they were on",icon:"external-link",action:()=>window.open(t.page,"_blank","noopener")}]:[],...v&&t.status!=="closed"?[{type:"divider"},{label:"End chat",icon:"x-circle",action:()=>ue(e)}]:[],...G?[{type:"divider"},{label:"Delete",icon:"trash",danger:!0,action:()=>he(e)}]:[]]:[]},me=E.contextMenu(j,{cursor:"glyph",match:".chat-row",inherit:!1,density:"compact",items:e=>ee(e.dataset.id)});l.add(()=>me?.destroy?.());const F=n.querySelector(".chats-head-kebab"),fe=E.contextMenu(F,{cursor:"glyph",inherit:!1,density:"compact",items:()=>ee(s.peek())});l.add(()=>fe?.destroy?.()),F.addEventListener("click",()=>se(F)),j.addEventListener("click",e=>{const t=e.target.closest(".chat-row");if(t){if(e.target.closest(".chat-row-kebab")){se(t);return}A(t.dataset.id)}}),j.addEventListener("keydown",e=>{const t=e.target.closest?.(".chat-row");t&&(e.key==="Enter"||e.key===" ")&&e.target===t&&(e.preventDefault(),A(t.dataset.id))});let b=null;async function ve(){if(b)return;let e;try{e=(await h("/chats/settings")).settings}catch{E.toast("Could not read the chat settings",{type:"error"});return}if(!r()||b)return;const t=E.slideover({title:"Chat settings",size:"sm",position:"right"});b=t;const a=Se(`
|
|
15
|
+
<div class="chats-settings" style="display:flex;flex-direction:column;gap:1rem;padding:.25rem">
|
|
16
|
+
<div>
|
|
17
|
+
<label class="form-label" for="chat-set-conf">How sure the bot must be
|
|
18
|
+
<span data-help-title="Confidence" data-help="Strict answers only close matches and offers choices more often. Relaxed answers more, and is wrong more often. Try a few questions in Knowledge > Try the bot after changing this."></span>
|
|
19
|
+
</label>
|
|
20
|
+
<select id="chat-set-conf" class="form-input" data-model="confidence.value" data-bind-disabled="!canManage">
|
|
21
|
+
<option value="strict">Strict</option>
|
|
22
|
+
<option value="balanced">Balanced</option>
|
|
23
|
+
<option value="relaxed">Relaxed</option>
|
|
24
|
+
</select>
|
|
25
|
+
</div>
|
|
26
|
+
<div>
|
|
27
|
+
<label class="form-label" for="chat-set-name">How visitors see your name
|
|
28
|
+
<span data-help="Your first name, your full name, or just 'The team' for everyone."></span>
|
|
29
|
+
</label>
|
|
30
|
+
<select id="chat-set-name" class="form-input" data-model="staffName.value" data-bind-disabled="!canManage">
|
|
31
|
+
<option value="first">First name</option>
|
|
32
|
+
<option value="full">Full name</option>
|
|
33
|
+
<option value="team">The team</option>
|
|
34
|
+
</select>
|
|
35
|
+
</div>
|
|
36
|
+
<div>
|
|
37
|
+
<label class="form-label" for="chat-set-keep">Keep ended chats for (days)
|
|
38
|
+
<span data-help="Ended chats and their messages are deleted after this many days (7 to 730). Messages left for the team are kept until someone ends them."></span>
|
|
39
|
+
</label>
|
|
40
|
+
<input id="chat-set-keep" type="number" min="7" max="730" class="form-input" data-model="retentionDays.value" data-bind-disabled="!canManage">
|
|
41
|
+
</div>
|
|
42
|
+
<div>
|
|
43
|
+
<label class="form-label" for="chat-set-cap">New chats the site takes an hour
|
|
44
|
+
<span data-help="A ceiling for the whole site (10 to 10,000), so a flood of fake chats cannot fill your inbox or storage. Past it, visitors are asked to try again later. Each visitor can also start at most 6 chats an hour."></span>
|
|
45
|
+
</label>
|
|
46
|
+
<input id="chat-set-cap" type="number" min="10" max="10000" class="form-input" data-model="maxNewChatsPerHour.value" data-bind-disabled="!canManage">
|
|
47
|
+
</div>
|
|
48
|
+
<p class="text-muted" style="margin:0;font-size:var(--dm-text-sm)" data-bind-hidden="canManage">Only people who can manage Chats can change these.</p>
|
|
49
|
+
<div style="display:flex;gap:.5rem;justify-content:flex-end">
|
|
50
|
+
<button type="button" class="btn btn-sm btn-ghost" data-on-click="cancel">Cancel</button>
|
|
51
|
+
<button type="button" class="btn btn-sm btn-primary" data-on-click="save" data-bind-hidden="!canManage" data-bind-disabled="!dirty.value">Save</button>
|
|
52
|
+
</div>
|
|
53
|
+
</div>`),o={canManage:G,confidence:M.observable(e.confidence),staffName:M.observable(e.staffName),retentionDays:M.observable(String(e.retentionDays)),maxNewChatsPerHour:M.observable(String(e.maxNewChatsPerHour))};o.dirty=M.computed(()=>o.confidence.value!==e.confidence||o.staffName.value!==e.staffName||Number(o.retentionDays.value)!==e.retentionDays||Number(o.maxNewChatsPerHour.value)!==e.maxNewChatsPerHour),t.element.appendChild(a);const u=ae(a),_=M.applyBindings(o,a,{methods:{cancel:()=>t.close(),save:async()=>{try{e=(await h("/chats/settings","PUT",{confidence:o.confidence.peek(),staffName:o.staffName.peek(),retentionDays:Number(o.retentionDays.peek()),maxNewChatsPerHour:Number(o.maxNewChatsPerHour.peek())})).settings,E.toast("Chat settings saved",{type:"success"}),t.close()}catch(B){E.toast(B?.message||"Could not save",{type:"error"})}}}});we(t,()=>{_.dispose(),u(),b===t&&(b=null)});const ye=t.close;t.close=async(...B)=>o.dirty.peek()&&!l.leaving&&!await E.confirm("Discard your changes to the chat settings?")?!1:ye(...B),t.open()}l.add(()=>b?.close()),ge(c,{id:"chats-settings",icon:"settings",title:"Chat settings",onClick:ve});const te=e=>{e.ctrlKey||e.metaKey||e.altKey||e.target.closest?.("input, textarea, select, [contenteditable], .dm-slideover")||(e.key==="/"&&(e.preventDefault(),n.querySelector(".chats-search input")?.focus()),e.key==="Escape"&&s.peek()&&P())};if(document.addEventListener("keydown",te),l.add(()=>document.removeEventListener("keydown",te)),I.scan(n),await f(),r()&&s.peek()){const e=s.peek();s.value="",A(e)}}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{mountScaffolder as i}from"../lib/crud-tutorial.js";function t(o,s){return{templateUrl:`/admin/js/templates/docs/${o}.html`,async onMount(e){typeof s=="function"&&s(e),Domma.icons.scan(),Domma.syntax.scan()}}}export const docViews={tutorialCrud:t("tutorial-crud",o=>{const s=o.find("#tutorial-scaffolder-mount").get(0);s&&i(s,null,null)}),tutorialPlugin:t("tutorial-plugin"),tutorialEditor:t("tutorial-editor"),tutorialForms:t("tutorial-forms"),componentsReference:t("components-reference"),componentsHowto:t("components-howto"),componentsWalkthrough:t("components-walkthrough"),componentsRules:t("components-rules")};const a=["pages","media","navigation","dconfig","shortcodes","site-settings","plugins","users-roles","views","actions","cta-shortcode","editions","collections","blocks","tools","dashboard","search-engines"],c=["authentication","pages","settings","layouts","navigation","media","users","plugins","collections","views","actions","forms","scaffold","external","content","builder"],n=o=>o.split("-").map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join("");for(const o of a)docViews["usage"+n(o)]=t(`usage-${o}`);for(const o of c)docViews["apiRef"+n(o)]=t(`api-${o}`);
|
|
1
|
+
import{mountScaffolder as i}from"../lib/crud-tutorial.js";function t(o,s){return{templateUrl:`/admin/js/templates/docs/${o}.html`,async onMount(e){typeof s=="function"&&s(e),Domma.icons.scan(),Domma.syntax.scan()}}}export const docViews={tutorialCrud:t("tutorial-crud",o=>{const s=o.find("#tutorial-scaffolder-mount").get(0);s&&i(s,null,null)}),tutorialPlugin:t("tutorial-plugin"),tutorialEditor:t("tutorial-editor"),tutorialForms:t("tutorial-forms"),componentsReference:t("components-reference"),componentsHowto:t("components-howto"),componentsWalkthrough:t("components-walkthrough"),componentsRules:t("components-rules")};const a=["pages","media","navigation","dconfig","shortcodes","site-settings","plugins","users-roles","views","actions","cta-shortcode","editions","collections","blocks","tools","dashboard","search-engines","launchers","chat"],c=["authentication","pages","settings","layouts","navigation","media","users","plugins","collections","views","actions","forms","scaffold","external","content","builder"],n=o=>o.split("-").map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join("");for(const o of a)docViews["usage"+n(o)]=t(`usage-${o}`);for(const o of c)docViews["apiRef"+n(o)]=t(`api-${o}`);
|
package/admin/js/views/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const i={templateUrl:"",async onMount(){location.hash="#/menus"}};export const viewLoaders={projects:()=>import("./projects.js").then(e=>e.projectsView),projectDetail:()=>import("./project-detail.js").then(e=>e.projectDetailView),projectSettings:()=>import("./project-settings.js").then(e=>e.projectSettingsView),apiTokens:()=>import("./api-tokens.js").then(e=>e.apiTokensView),apiEndpoints:()=>import("./api-endpoints.js").then(e=>e.apiEndpointsView),apiEndpointEditor:()=>import("./api-endpoint-editor.js").then(e=>e.apiEndpointEditorView),dashboard:()=>import("./dashboard.js").then(e=>e.dashboardView),dashboards:()=>import("./dashboards.js").then(e=>e.dashboardsView),pages:()=>import("./pages.js").then(e=>e.pagesView),pageEditor:()=>import("./page-editor.js").then(e=>e.pageEditorView),appearance:()=>import("./appearance.js").then(e=>e.appearanceView),footer:()=>import("./footer.js").then(e=>e.footerView),settings:()=>import("./settings.js").then(e=>e.settingsView),theme:()=>import("./theme.js").then(e=>e.themeView),layouts:()=>import("./layouts.js").then(e=>e.layoutsView),media:()=>import("./media.js").then(e=>e.mediaView),login:()=>import("./login.js").then(e=>e.loginView),users:()=>import("./users.js").then(e=>e.usersView),userEditor:()=>import("./user-editor.js").then(e=>e.userEditorView),plugins:()=>import("./plugins.js").then(e=>e.pluginsView),pluginCode:()=>import("./plugin-code.js").then(e=>e.pluginCodeView),documentation:()=>import("./documentation.js").then(e=>e.documentationView),tutorials:()=>import("./tutorials.js").then(e=>e.tutorialsView),apiReference:()=>import("./api-reference.js").then(e=>e.apiReferenceView),collections:()=>import("./collections.js").then(e=>e.collectionsView),collectionEditor:()=>import("./collection-editor.js").then(e=>e.collectionEditorView),collectionEntries:()=>import("./collection-entries.js").then(e=>e.collectionEntriesView),forms:()=>import("./forms.js").then(e=>e.formsView),formEditor:()=>import("./form-editor.js").then(e=>e.formEditorView),formSubmissions:()=>import("./form-submissions.js").then(e=>e.formSubmissionsView),viewsList:()=>import("./views-list.js").then(e=>e.viewsListView),viewEditor:()=>import("./view-editor.js").then(e=>e.viewEditorView),viewPreview:()=>import("./view-preview.js").then(e=>e.viewPreviewView),actionsList:()=>import("./actions-list.js").then(e=>e.actionsListView),actionEditor:()=>import("./action-editor.js").then(e=>e.actionEditorView),proDocs:()=>import("./pro-docs.js").then(e=>e.proDocsView),blocks:()=>import("./blocks.js").then(e=>e.blocksView),components:()=>import("./components.js").then(e=>e.componentsView),myProfile:()=>import("./my-profile.js").then(e=>e.myProfileView),roles:()=>import("./roles.js").then(e=>e.rolesView),roleEditor:()=>import("./role-editor.js").then(e=>e.roleEditorView),effects:()=>import("./effects.js").then(e=>e.effectsView),search:()=>import("./search.js").then(e=>e.searchView),contentApi:()=>import("./content-api.js").then(e=>e.contentApiView),notes:()=>import("./notes.js").then(e=>e.notesView),todo:()=>import("./todo.js").then(e=>e.todoView),calculator:()=>import("../lib/calculator.js").then(e=>e.calculatorView),analytics:()=>import("./analytics.js").then(e=>e.analyticsView),seo:()=>import("./seo.js").then(e=>e.seoView),wordpressImport:()=>import("./wordpress-import.js").then(e=>e.wordpressImportView),contacts:()=>import("./contacts.js").then(e=>e.contactsView),callNew:()=>import("./call-new.js").then(e=>e.callNewView),notifications:()=>import("./notifications.js").then(e=>e.notificationsView),menus:()=>import("./menus.js").then(e=>e.menusView),contextMenus:()=>import("./context-menus.js").then(e=>e.contextMenusView),contextMenuEditor:()=>import("./context-menu-editor.js").then(e=>e.contextMenuEditorView),menuEditor:()=>import("./menu-editor.js").then(e=>e.menuEditorView),menuLocations:()=>import("./menu-locations.js").then(e=>e.menuLocationsView),menusRedirect:async()=>i,pluginGuides:()=>import("./plugin-guides.js").then(e=>e.pluginGuidesView),pluginGuide:()=>import("./plugin-guides.js").then(e=>e.pluginGuideView)};for(const e of["tutorialCrud","tutorialPlugin","tutorialEditor","tutorialForms","componentsReference","componentsHowto","componentsWalkthrough","componentsRules","usagePages","usageMedia","usageNavigation","usageDconfig","usageShortcodes","usageSiteSettings","usagePlugins","usageUsersRoles","usageViews","usageActions","usageCtaShortcode","usageEditions","usageCollections","usageBlocks","usageTools","usageDashboard","usageSearchEngines","apiRefAuthentication","apiRefPages","apiRefSettings","apiRefLayouts","apiRefNavigation","apiRefMedia","apiRefUsers","apiRefPlugins","apiRefCollections","apiRefViews","apiRefActions","apiRefForms","apiRefScaffold","apiRefExternal","apiRefContent","apiRefBuilder"])viewLoaders[e]=()=>import("./doc-pages.js").then(t=>t.docViews[e]);
|
|
1
|
+
const i={templateUrl:"",async onMount(){location.hash="#/menus"}};export const viewLoaders={projects:()=>import("./projects.js").then(e=>e.projectsView),projectDetail:()=>import("./project-detail.js").then(e=>e.projectDetailView),projectSettings:()=>import("./project-settings.js").then(e=>e.projectSettingsView),apiTokens:()=>import("./api-tokens.js").then(e=>e.apiTokensView),apiEndpoints:()=>import("./api-endpoints.js").then(e=>e.apiEndpointsView),apiEndpointEditor:()=>import("./api-endpoint-editor.js").then(e=>e.apiEndpointEditorView),dashboard:()=>import("./dashboard.js").then(e=>e.dashboardView),dashboards:()=>import("./dashboards.js").then(e=>e.dashboardsView),pages:()=>import("./pages.js").then(e=>e.pagesView),pageEditor:()=>import("./page-editor.js").then(e=>e.pageEditorView),appearance:()=>import("./appearance.js").then(e=>e.appearanceView),footer:()=>import("./footer.js").then(e=>e.footerView),settings:()=>import("./settings.js").then(e=>e.settingsView),theme:()=>import("./theme.js").then(e=>e.themeView),layouts:()=>import("./layouts.js").then(e=>e.layoutsView),media:()=>import("./media.js").then(e=>e.mediaView),login:()=>import("./login.js").then(e=>e.loginView),users:()=>import("./users.js").then(e=>e.usersView),userEditor:()=>import("./user-editor.js").then(e=>e.userEditorView),plugins:()=>import("./plugins.js").then(e=>e.pluginsView),pluginCode:()=>import("./plugin-code.js").then(e=>e.pluginCodeView),documentation:()=>import("./documentation.js").then(e=>e.documentationView),tutorials:()=>import("./tutorials.js").then(e=>e.tutorialsView),apiReference:()=>import("./api-reference.js").then(e=>e.apiReferenceView),collections:()=>import("./collections.js").then(e=>e.collectionsView),collectionEditor:()=>import("./collection-editor.js").then(e=>e.collectionEditorView),collectionEntries:()=>import("./collection-entries.js").then(e=>e.collectionEntriesView),forms:()=>import("./forms.js").then(e=>e.formsView),formEditor:()=>import("./form-editor.js").then(e=>e.formEditorView),formSubmissions:()=>import("./form-submissions.js").then(e=>e.formSubmissionsView),viewsList:()=>import("./views-list.js").then(e=>e.viewsListView),viewEditor:()=>import("./view-editor.js").then(e=>e.viewEditorView),viewPreview:()=>import("./view-preview.js").then(e=>e.viewPreviewView),actionsList:()=>import("./actions-list.js").then(e=>e.actionsListView),actionEditor:()=>import("./action-editor.js").then(e=>e.actionEditorView),proDocs:()=>import("./pro-docs.js").then(e=>e.proDocsView),blocks:()=>import("./blocks.js").then(e=>e.blocksView),components:()=>import("./components.js").then(e=>e.componentsView),myProfile:()=>import("./my-profile.js").then(e=>e.myProfileView),roles:()=>import("./roles.js").then(e=>e.rolesView),roleEditor:()=>import("./role-editor.js").then(e=>e.roleEditorView),effects:()=>import("./effects.js").then(e=>e.effectsView),search:()=>import("./search.js").then(e=>e.searchView),contentApi:()=>import("./content-api.js").then(e=>e.contentApiView),notes:()=>import("./notes.js").then(e=>e.notesView),chats:()=>import("./chats.js").then(e=>e.chatsView),chatKnowledge:()=>import("./chat-knowledge.js").then(e=>e.chatKnowledgeView),todo:()=>import("./todo.js").then(e=>e.todoView),calculator:()=>import("../lib/calculator.js").then(e=>e.calculatorView),analytics:()=>import("./analytics.js").then(e=>e.analyticsView),seo:()=>import("./seo.js").then(e=>e.seoView),wordpressImport:()=>import("./wordpress-import.js").then(e=>e.wordpressImportView),contacts:()=>import("./contacts.js").then(e=>e.contactsView),callNew:()=>import("./call-new.js").then(e=>e.callNewView),notifications:()=>import("./notifications.js").then(e=>e.notificationsView),menus:()=>import("./menus.js").then(e=>e.menusView),contextMenus:()=>import("./context-menus.js").then(e=>e.contextMenusView),launchers:()=>import("./launchers.js").then(e=>e.launchersView),contextMenuEditor:()=>import("./context-menu-editor.js").then(e=>e.contextMenuEditorView),menuEditor:()=>import("./menu-editor.js").then(e=>e.menuEditorView),menuLocations:()=>import("./menu-locations.js").then(e=>e.menuLocationsView),menusRedirect:async()=>i,pluginGuides:()=>import("./plugin-guides.js").then(e=>e.pluginGuidesView),pluginGuide:()=>import("./plugin-guides.js").then(e=>e.pluginGuideView)};for(const e of["tutorialCrud","tutorialPlugin","tutorialEditor","tutorialForms","componentsReference","componentsHowto","componentsWalkthrough","componentsRules","usagePages","usageMedia","usageNavigation","usageDconfig","usageShortcodes","usageSiteSettings","usagePlugins","usageUsersRoles","usageViews","usageActions","usageCtaShortcode","usageEditions","usageCollections","usageBlocks","usageTools","usageDashboard","usageSearchEngines","usageLaunchers","usageChat","apiRefAuthentication","apiRefPages","apiRefSettings","apiRefLayouts","apiRefNavigation","apiRefMedia","apiRefUsers","apiRefPlugins","apiRefCollections","apiRefViews","apiRefActions","apiRefForms","apiRefScaffold","apiRefExternal","apiRefContent","apiRefBuilder"])viewLoaders[e]=()=>import("./doc-pages.js").then(t=>t.docViews[e]);
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import{apiRequest as V,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 Ve,openMenuAt as Se,sidebarCount as Ee,viewLifetime as Je}from"../lib/tool-kit.js";import{rowPlaceKeeper as Ge}from"../lib/menu-drag.js";import{FILTERS as Qe,LAUNCHER_POSITION_LABEL as Ce,arrangeLaunchers as Ze,blankLauncher as ea,checkLauncherForm as aa,countLaunchers as ta,duplicateLauncher as la,formFromLauncher as na,launcherFromForm as sa,launcherRow as oa,moveItem as ia,previewSpot as da}from"../lib/launchers-arrange.js";import{LAUNCHER_LIMITS as u,LAUNCHER_TOKENS as J,launcherColourCss as Me,launcherHref as G}from"../../../public/js/launcher-settings.mjs";const $e=/^#\/launchers\/?(\?.*)?$/,Te="#/launchers",Q="launchers.filter",R="launchers.draft",ra=`
|
|
2
|
+
<div class="lnx-row" data-id="{{id}}" tabindex="0" data-bind-class="rowCls">
|
|
3
|
+
<span class="lnx-grip" title="Drag to reorder" aria-hidden="true"><span data-icon="menu" data-icon-size="14"></span></span>
|
|
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>
|
|
5
|
+
<span class="lnx-main"><strong>{{name}}</strong><small>{{meta}}</small></span>
|
|
6
|
+
<span class="lnx-chips">
|
|
7
|
+
<span class="lnx-chip is-danger" data-bind-hidden="!problem || off" data-bind-text="problem"></span>
|
|
8
|
+
<span class="lnx-chip" data-bind-hidden="on">Off</span>
|
|
9
|
+
</span>
|
|
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
|
+
<button type="button" class="lnx-kebab" aria-label="Actions for {{name}}" title="Actions">\u22EE</button>
|
|
12
|
+
</div>`,h={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"]],background:[["","Theme (primary)"],...J.map(s=>[s,s.charAt(0).toUpperCase()+s.slice(1)]),["custom","Custom hex\u2026"]],foreground:[["","Theme (reads on the background)"],...J.map(s=>[s,s.charAt(0).toUpperCase()+s.slice(1)]),["custom","Custom hex\u2026"]]},ca=["TL","TC","TR","ML","","MR","BL","BC","BR"],f=s=>s.map(([d,T])=>`<option value="${d}">${T}</option>`).join(""),Oe=s=>ca.map(d=>d?`<button type="button" data-pos="${d}" data-bind-class="${s}.value === '${d}' && 'is-on'" title="${Ce[d]}" aria-label="${Ce[d]}">${d}</button>`:'<button type="button" class="lnx-corner-mid" tabindex="-1" aria-hidden="true"></button>').join(""),pa=`
|
|
13
|
+
<div class="lnx-form">
|
|
14
|
+
<div class="lnx-section">
|
|
15
|
+
<h6><span data-icon="message-circle" data-icon-size="14"></span> The disc</h6>
|
|
16
|
+
<div class="lnx-grid2">
|
|
17
|
+
<div class="lnx-field">
|
|
18
|
+
<label class="form-label" for="lnx-f-name">Name <span data-help="Only you see this - it names the launcher in this list."></span></label>
|
|
19
|
+
<input id="lnx-f-name" class="form-input" maxlength="${u.nameMax}" data-model="name.value">
|
|
20
|
+
<small class="lnx-err" data-bind-hidden="!err.value.name" data-bind-text="err.value.name"></small>
|
|
21
|
+
</div>
|
|
22
|
+
<div class="lnx-field">
|
|
23
|
+
<label class="form-label" for="lnx-f-label">Label <span data-help="What the disc says: read out to screen readers, and written on the pill when the style is Pill."></span></label>
|
|
24
|
+
<input id="lnx-f-label" class="form-input" maxlength="${u.labelMax}" data-model="label.value">
|
|
25
|
+
<small class="lnx-err" data-bind-hidden="!err.value.label" data-bind-text="err.value.label"></small>
|
|
26
|
+
</div>
|
|
27
|
+
<div class="lnx-field">
|
|
28
|
+
<label class="form-label" for="lnx-f-tipmode">Tooltip <span data-help="Shown when a visitor hovers over the disc or tabs to it. The label gives a pill no tooltip - it already shows its label."></span></label>
|
|
29
|
+
<select id="lnx-f-tipmode" class="form-input" data-model="tooltipMode.value">${f(h.tooltipMode)}</select>
|
|
30
|
+
</div>
|
|
31
|
+
<div class="lnx-field" data-bind-hidden="tooltipMode.value !== 'custom'">
|
|
32
|
+
<label class="form-label" for="lnx-f-tip">Tooltip words</label>
|
|
33
|
+
<input id="lnx-f-tip" class="form-input" maxlength="${u.tooltipMax}" placeholder="e.g. Questions? Ask us here" data-model="tooltip.value">
|
|
34
|
+
</div>
|
|
35
|
+
<div class="lnx-field">
|
|
36
|
+
<label class="form-label" for="lnx-f-icon">Icon <span data-help="A Domma icon name - press the grid button to browse them."></span></label>
|
|
37
|
+
<div class="lnx-inline">
|
|
38
|
+
<input id="lnx-f-icon" class="form-input" maxlength="${u.iconMax}" data-model="icon.value">
|
|
39
|
+
<button type="button" class="lnx-icon-btn lnx-pick-icon" title="Browse icons"><span data-icon="grid" data-icon-size="14"></span></button>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
<div class="lnx-field">
|
|
43
|
+
<label class="form-label" for="lnx-f-style">Style <span data-help="A round disc with just the icon, or a pill with the icon and the label."></span></label>
|
|
44
|
+
<select id="lnx-f-style" class="form-input" data-model="triggerStyle.value">${f(h.triggerStyle)}</select>
|
|
45
|
+
</div>
|
|
46
|
+
<div class="lnx-field">
|
|
47
|
+
<label class="form-label" for="lnx-f-bg">Background <span data-help="One of the theme's colours - so it follows light, dark and custom themes - or your own hex colour."></span></label>
|
|
48
|
+
<select id="lnx-f-bg" class="form-input" data-model="bgChoice.value">${f(h.background)}</select>
|
|
49
|
+
<input class="form-input" placeholder="#3366ff" data-model="bgHex.value" data-bind-hidden="bgChoice.value !== 'custom'" aria-label="Background hex colour">
|
|
50
|
+
<small class="lnx-err" data-bind-hidden="!err.value.background" data-bind-text="err.value.background"></small>
|
|
51
|
+
</div>
|
|
52
|
+
<div class="lnx-field">
|
|
53
|
+
<label class="form-label" for="lnx-f-fg">Icon and text colour <span data-help="Theme picks the colour that reads on the theme's primary colour."></span></label>
|
|
54
|
+
<select id="lnx-f-fg" class="form-input" data-model="fgChoice.value">${f(h.foreground)}</select>
|
|
55
|
+
<input class="form-input" placeholder="#ffffff" data-model="fgHex.value" data-bind-hidden="fgChoice.value !== 'custom'" aria-label="Icon and text hex colour">
|
|
56
|
+
<small class="lnx-err" data-bind-hidden="!err.value.text" data-bind-text="err.value.text"></small>
|
|
57
|
+
</div>
|
|
58
|
+
<div class="lnx-field">
|
|
59
|
+
<label class="form-label" for="lnx-f-cls">CSS classes <span data-help="Your own class names on the disc, for Custom CSS. Letters, digits, - and _ only."></span></label>
|
|
60
|
+
<input id="lnx-f-cls" class="form-input" placeholder="my-launcher" data-model="cls.value">
|
|
61
|
+
</div>
|
|
62
|
+
<label class="lnx-check"><input type="checkbox" class="form-switch" data-model="enabled.value"> Switched on
|
|
63
|
+
<span data-help="Off keeps the launcher here but takes it off every page."></span></label>
|
|
64
|
+
<label class="lnx-check"><input type="checkbox" class="form-switch" data-model="showDisc.value"> Show a disc on the page
|
|
65
|
+
<span data-help="Off: no disc - it opens only from a link to it, such as a menu or sub-menu item, or a button in a page. Its Where and for whom settings still apply."></span></label>
|
|
66
|
+
<div class="lnx-field" style="grid-column: 1 / -1">
|
|
67
|
+
<label class="form-label" for="lnx-f-link">Link to open it <span data-help="Use this as the URL of a menu or sub-menu item (Content > Menus has a Launcher list that fills it in), a button or any link in a page. On a page where this launcher does not show, the link does nothing."></span></label>
|
|
68
|
+
<div class="lnx-inline">
|
|
69
|
+
<input id="lnx-f-link" class="form-input" readonly data-bind-value="linkText" data-bind-disabled="!linkHref">
|
|
70
|
+
<button type="button" class="lnx-icon-btn lnx-copy-link" title="Copy the link" aria-label="Copy the link" data-bind-disabled="!linkHref"><span data-icon="copy" data-icon-size="14"></span></button>
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
|
|
76
|
+
<div class="lnx-section">
|
|
77
|
+
<h6><span data-icon="external-link" data-icon-size="14"></span> What it opens</h6>
|
|
78
|
+
<div class="lnx-field">
|
|
79
|
+
<label class="form-label" for="lnx-f-type">Opens <span data-help-title="Opens" data-help="Modal: a page (on its own, no navbar or footer), a form or a block in a box over the page. Slideover: the same in a panel from the side. Chat: a chat panel by the disc (full screen on phones) - the bot answers from your Knowledge first, then your team."></span></label>
|
|
80
|
+
<select id="lnx-f-type" class="form-input" data-model="actionType.value">${f(h.actionType)}</select>
|
|
81
|
+
</div>
|
|
82
|
+
<div class="lnx-grid2" data-bind-hidden="actionType.value === 'chat'">
|
|
83
|
+
<div class="lnx-field">
|
|
84
|
+
<label class="form-label" for="lnx-f-kind">Show <span data-help="A page shows its body only. A form or block is drawn as it would be on a page."></span></label>
|
|
85
|
+
<select id="lnx-f-kind" class="form-input" data-model="kind.value">${f(h.kind)}</select>
|
|
86
|
+
</div>
|
|
87
|
+
<div class="lnx-field" data-bind-hidden="kind.value !== 'page'">
|
|
88
|
+
<label class="form-label" for="lnx-f-page">Page <span data-help="The page's address. Its own visibility still applies: a members-only page opens for members only, and a draft never opens."></span></label>
|
|
89
|
+
<div class="lnx-inline">
|
|
90
|
+
<input id="lnx-f-page" class="form-input" placeholder="/about" data-model="refPage.value">
|
|
91
|
+
<button type="button" class="lnx-icon-btn lnx-pick-page" title="Choose a page"><span data-icon="file-text" data-icon-size="14"></span></button>
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
<div class="lnx-field" data-bind-hidden="kind.value !== 'form'">
|
|
95
|
+
<label class="form-label" for="lnx-f-form">Form <span data-help="One of your forms (Data > Forms). Visitors fill it in inside the panel; it sends exactly as it does on a page."></span></label>
|
|
96
|
+
<select id="lnx-f-form" class="form-input lnx-form-select" data-model="refForm.value"></select>
|
|
97
|
+
</div>
|
|
98
|
+
<div class="lnx-field" data-bind-hidden="kind.value !== 'block'">
|
|
99
|
+
<label class="form-label" for="lnx-f-block">Block <span data-help="One of your blocks (Content > Blocks), drawn with its defaults."></span></label>
|
|
100
|
+
<select id="lnx-f-block" class="form-input lnx-block-select" data-model="refBlock.value"></select>
|
|
101
|
+
</div>
|
|
102
|
+
<small class="lnx-err" data-bind-hidden="!err.value.ref" data-bind-text="err.value.ref"></small>
|
|
103
|
+
<small class="lnx-warn" data-bind-hidden="err.value.ref || !warn.value.ref" data-bind-text="warn.value.ref"></small>
|
|
104
|
+
</div>
|
|
105
|
+
<div class="lnx-grid2">
|
|
106
|
+
<div class="lnx-field">
|
|
107
|
+
<label class="form-label" for="lnx-f-title">Title <span data-help="The heading of the modal, slideover or chat. Empty uses the label."></span></label>
|
|
108
|
+
<input id="lnx-f-title" class="form-input" maxlength="${u.titleMax}" data-model="title.value">
|
|
109
|
+
</div>
|
|
110
|
+
<div class="lnx-field" data-bind-hidden="actionType.value !== 'modal'">
|
|
111
|
+
<label class="form-label" for="lnx-f-size">Modal width <span data-help="Never wider than the window: a phone always gets nearly its full width. Full screen fills the whole window, height too."></span></label>
|
|
112
|
+
<select id="lnx-f-size" class="form-input" data-model="modalSize.value">${f(h.modalSize)}</select>
|
|
113
|
+
</div>
|
|
114
|
+
<div class="lnx-field" data-bind-hidden="actionType.value !== 'modal' || modalSize.value !== 'custom'">
|
|
115
|
+
<label class="form-label" for="lnx-f-cw">Custom width</label>
|
|
116
|
+
<div class="lnx-unit"><input id="lnx-f-cw" type="number" class="form-input" data-model="customWidth.value"
|
|
117
|
+
data-bind-min="widthUnit.value === '%' ? ${u.widthPct[0]} : ${u.widthPx[0]}" data-bind-max="widthUnit.value === '%' ? ${u.widthPct[1]} : ${u.widthPx[1]}">
|
|
118
|
+
<select class="form-input" data-model="widthUnit.value" aria-label="Width unit">${f(h.widthUnit)}</select></div>
|
|
119
|
+
</div>
|
|
120
|
+
<div class="lnx-field" data-bind-hidden="actionType.value !== 'modal' || modalSize.value === 'screen'">
|
|
121
|
+
<label class="form-label" for="lnx-f-height">Modal height <span data-help="Fit the page grows and shrinks with the page, up to most of the window. A fixed height keeps the modal that tall; a longer page scrolls inside it."></span></label>
|
|
122
|
+
<select id="lnx-f-height" class="form-input" data-model="modalHeight.value">${f(h.modalHeight)}</select>
|
|
123
|
+
</div>
|
|
124
|
+
<div class="lnx-field" data-bind-hidden="actionType.value !== 'modal' || modalSize.value === 'screen' || modalHeight.value !== 'custom'">
|
|
125
|
+
<label class="form-label" for="lnx-f-ch">Custom height</label>
|
|
126
|
+
<div class="lnx-unit"><input id="lnx-f-ch" type="number" class="form-input" data-model="customHeight.value"
|
|
127
|
+
data-bind-min="heightUnit.value === 'px' ? ${u.heightPx[0]} : ${u.heightVh[0]}" data-bind-max="heightUnit.value === 'px' ? ${u.heightPx[1]} : ${u.heightVh[1]}">
|
|
128
|
+
<select class="form-input" data-model="heightUnit.value" aria-label="Height unit">${f(h.heightUnit)}</select></div>
|
|
129
|
+
</div>
|
|
130
|
+
<div class="lnx-field" data-bind-hidden="actionType.value !== 'slideover'">
|
|
131
|
+
<label class="form-label" for="lnx-f-side">Slides in from <span data-help="On a phone a slideover fills the screen whatever its width."></span></label>
|
|
132
|
+
<select id="lnx-f-side" class="form-input" data-model="side.value">${f(h.side)}</select>
|
|
133
|
+
</div>
|
|
134
|
+
<div class="lnx-field" data-bind-hidden="actionType.value !== 'slideover'">
|
|
135
|
+
<label class="form-label" for="lnx-f-width">Width</label>
|
|
136
|
+
<select id="lnx-f-width" class="form-input" data-model="width.value">${f(h.width)}</select>
|
|
137
|
+
</div>
|
|
138
|
+
</div>
|
|
139
|
+
<div class="lnx-grid2" data-bind-hidden="actionType.value !== 'chat'">
|
|
140
|
+
<div class="lnx-field" style="grid-column: 1 / -1">
|
|
141
|
+
<label class="form-label" for="lnx-f-greeting">Greeting <span data-help="The first message a visitor sees when the chat opens."></span></label>
|
|
142
|
+
<textarea id="lnx-f-greeting" class="form-input" rows="2" maxlength="${u.greetingMax}" data-model="greeting.value"></textarea>
|
|
143
|
+
</div>
|
|
144
|
+
<div class="lnx-field">
|
|
145
|
+
<label class="form-label" for="lnx-f-botname">Bot's name <span data-help="Shown on the bot's answers."></span></label>
|
|
146
|
+
<input id="lnx-f-botname" class="form-input" maxlength="${u.botNameMax}" data-model="botName.value">
|
|
147
|
+
</div>
|
|
148
|
+
<div class="lnx-field">
|
|
149
|
+
<label class="form-label" for="lnx-f-ask">Ask for name and email <span data-help="When the chat asks a visitor for their name and email so your team can reply later."></span></label>
|
|
150
|
+
<select id="lnx-f-ask" class="form-input" data-model="askDetails.value">${f(h.askDetails)}</select>
|
|
151
|
+
</div>
|
|
152
|
+
<label class="lnx-check"><input type="checkbox" class="form-switch" data-model="bot.value"> Bot answers first
|
|
153
|
+
<span data-help="The bot answers from your Knowledge entries. It offers choices when it is not sure, and hands over to your team when it has no answer."></span></label>
|
|
154
|
+
<label class="lnx-check"><input type="checkbox" class="form-switch" data-model="staff.value"> Your team can answer
|
|
155
|
+
<span data-help="Conversations reach the Chats inbox so your team can reply live. Off: the bot only, and a visitor can still leave their details."></span></label>
|
|
156
|
+
</div>
|
|
157
|
+
</div>
|
|
158
|
+
|
|
159
|
+
<div class="lnx-section">
|
|
160
|
+
<h6><span data-icon="move" data-icon-size="14"></span> Where it sits</h6>
|
|
161
|
+
<div class="lnx-place">
|
|
162
|
+
<div class="lnx-field">
|
|
163
|
+
<span class="form-label">Spot <span data-help="Pick a corner, the middle of an edge, or the top or bottom centre. It steps clear of other discs there - Search, Back to top, Reduce motion and your other launchers."></span></span>
|
|
164
|
+
<div class="lnx-corners lnx-corners-main" role="group" aria-label="Spot">${Oe("position")}</div>
|
|
165
|
+
</div>
|
|
166
|
+
<div class="lnx-previews">
|
|
167
|
+
<div><div class="lnx-preview"><span class="lnx-preview-bar"></span><span class="lnx-preview-disc" data-bind-style="previewStyle.value"><span data-icon="message-circle" class="lnx-preview-icon"></span><span data-bind-hidden="triggerStyle.value !== 'icon-text'" data-bind-text="label.value"></span></span></div><small>Desktop</small></div>
|
|
168
|
+
<div><div class="lnx-preview is-phone"><span class="lnx-preview-bar"></span><span class="lnx-preview-disc" data-bind-style="phonePreviewStyle.value"><span data-icon="message-circle" class="lnx-preview-icon"></span></span></div><small>Phone</small></div>
|
|
169
|
+
</div>
|
|
170
|
+
</div>
|
|
171
|
+
<div class="lnx-grid2">
|
|
172
|
+
<div class="lnx-field"><label class="form-label">From the side <span data-help="How far in from the left or right edge, in pixels. For a centred spot it nudges the disc right."></span></label>
|
|
173
|
+
<div class="lnx-range"><input type="range" min="0" max="200" data-model="offsetX.value" aria-label="From the side"><output data-bind-text="offsetX.value"></output></div></div>
|
|
174
|
+
<div class="lnx-field"><label class="form-label">From the top or bottom <span data-help="How far in from the top or bottom edge, in pixels. For a middle spot it nudges the disc down."></span></label>
|
|
175
|
+
<div class="lnx-range"><input type="range" min="0" max="300" data-model="offsetY.value" aria-label="From the top or bottom"><output data-bind-text="offsetY.value"></output></div></div>
|
|
176
|
+
<div class="lnx-field"><label class="form-label">Size <span data-help="The disc's width and height. 44px or more is easy to tap."></span></label>
|
|
177
|
+
<div class="lnx-range"><input type="range" min="${u.sizeMin}" max="${u.sizeMax}" data-model="size.value" aria-label="Size"><output data-bind-text="size.value"></output></div></div>
|
|
178
|
+
<div class="lnx-field" data-bind-hidden="triggerStyle.value === 'icon-text'"><label class="form-label">Roundness <span data-help="0 is a square; half the size is a circle."></span></label>
|
|
179
|
+
<div class="lnx-range"><input type="range" min="0" data-bind-max="maxRadius.value" data-model="radius.value" aria-label="Roundness"><output data-bind-text="radius.value"></output></div></div>
|
|
180
|
+
<div class="lnx-field">
|
|
181
|
+
<label class="form-label" for="lnx-f-devices">Shows on <span data-help="Phones are screens up to 640px wide."></span></label>
|
|
182
|
+
<select id="lnx-f-devices" class="form-input" data-model="devices.value">${f(h.devices)}</select>
|
|
183
|
+
</div>
|
|
184
|
+
<label class="lnx-check" data-bind-hidden="devices.value === 'desktop'"><input type="checkbox" class="form-switch" data-model="phoneOverride.value"> Its own spot on phones
|
|
185
|
+
<span data-help="A different spot, distance and size on phones - for instance, out of the way of a phone's bottom bar."></span></label>
|
|
186
|
+
</div>
|
|
187
|
+
<div class="lnx-place" data-bind-hidden="!phoneOverride.value || devices.value === 'desktop'">
|
|
188
|
+
<div class="lnx-field">
|
|
189
|
+
<span class="form-label">Spot on phones</span>
|
|
190
|
+
<div class="lnx-corners lnx-corners-phone" role="group" aria-label="Spot on phones">${Oe("phonePosition")}</div>
|
|
191
|
+
</div>
|
|
192
|
+
<div class="lnx-grid2" style="flex:1">
|
|
193
|
+
<div class="lnx-field"><label class="form-label">From the side</label>
|
|
194
|
+
<div class="lnx-range"><input type="range" min="0" max="120" data-model="phoneOffsetX.value" aria-label="From the side on phones"><output data-bind-text="phoneOffsetX.value"></output></div></div>
|
|
195
|
+
<div class="lnx-field"><label class="form-label">From the top or bottom</label>
|
|
196
|
+
<div class="lnx-range"><input type="range" min="0" max="200" data-model="phoneOffsetY.value" aria-label="From the top or bottom on phones"><output data-bind-text="phoneOffsetY.value"></output></div></div>
|
|
197
|
+
<div class="lnx-field"><label class="form-label">Size</label>
|
|
198
|
+
<div class="lnx-range"><input type="range" min="${u.sizeMin}" max="${u.sizeMax}" data-model="phoneSize.value" aria-label="Size on phones"><output data-bind-text="phoneSize.value"></output></div></div>
|
|
199
|
+
</div>
|
|
200
|
+
</div>
|
|
201
|
+
</div>
|
|
202
|
+
|
|
203
|
+
<div class="lnx-section">
|
|
204
|
+
<h6><span data-icon="eye" data-icon-size="14"></span> Where and for whom</h6>
|
|
205
|
+
<div class="lnx-grid2">
|
|
206
|
+
<div class="lnx-field">
|
|
207
|
+
<label class="form-label" for="lnx-f-pages">Pages <span data-help="Every page, only the pages listed, or every page but those."></span></label>
|
|
208
|
+
<select id="lnx-f-pages" class="form-input" data-model="pagesMode.value">${f(h.pagesMode)}</select>
|
|
209
|
+
</div>
|
|
210
|
+
<div class="lnx-field">
|
|
211
|
+
<label class="form-label" for="lnx-f-aud">Who sees it <span data-help="Signed-in: only people signed in to this site. Signed-out: only visitors who are not."></span></label>
|
|
212
|
+
<select id="lnx-f-aud" class="form-input" data-model="audience.value">${f(h.audience)}</select>
|
|
213
|
+
</div>
|
|
214
|
+
</div>
|
|
215
|
+
<div class="lnx-field" data-bind-hidden="pagesMode.value === 'all'">
|
|
216
|
+
<label class="form-label" for="lnx-f-paths">Page addresses <span data-help-title="Page addresses" data-help="One per line. /about is that page only. * matches anything: /blog/* is the blog and everything under it, /shop/*/reviews any product's reviews, /* every page."></span></label>
|
|
217
|
+
<textarea id="lnx-f-paths" class="form-input" rows="3" placeholder="/blog/* /contact" data-model="paths.value"></textarea>
|
|
218
|
+
<small class="lnx-err" data-bind-hidden="!err.value.paths" data-bind-text="err.value.paths"></small>
|
|
219
|
+
<small class="lnx-warn" data-bind-hidden="err.value.paths || !warn.value.paths" data-bind-text="warn.value.paths"></small>
|
|
220
|
+
</div>
|
|
221
|
+
</div>
|
|
222
|
+
|
|
223
|
+
<div class="lnx-actions">
|
|
224
|
+
<small class="lnx-hint">Ctrl+Enter saves.</small>
|
|
225
|
+
<span class="lnx-spacer"></span>
|
|
226
|
+
<button type="button" class="btn btn-sm btn-ghost" data-on-click="cancel">Cancel</button>
|
|
227
|
+
<button type="button" class="btn btn-sm btn-primary" data-on-click="save" data-bind-disabled="cannot.value">
|
|
228
|
+
<span data-icon="check" data-icon-size="13"></span> <span data-bind-text="saveText"></span></button>
|
|
229
|
+
</div>
|
|
230
|
+
</div>`,Z=s=>String(s??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");function ua(s){const d=document.createElement("template");return d.innerHTML=s.trim(),d.content.firstElementChild}const U=s=>s?J.includes(s)?s:"custom":"",x=Je($e),ee={list:()=>V("/launchers/items",{method:"GET"}),save:s=>V("/launchers/items",{method:"PUT",body:JSON.stringify({launchers:s})}),patch:(s,d)=>V(`/launchers/items/${encodeURIComponent(s)}`,{method:"PATCH",body:JSON.stringify(d)})};export const launchersView={templateUrl:"/admin/js/templates/launchers.html",async onMount(s){x.reset();const d=s.get(0).querySelector(".lnx")||s.get(0),T=()=>d.isConnected&&$e.test(location.hash),r=M.observable([]),ae=M.observable(!0),H=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),D=M.observable("");x.add(M.effect(()=>{const a=$.value;try{S.set(Q,a)}catch{}}));const W=M.observable([]);x.add(M.effect(()=>{W.value=Ze(r.value,{filter:$.value,query:D.value}).map(oa)}));const Le=M.computed(()=>ta(r.value)),ze=M.computed(()=>r.value.length?"No launchers match.":"No launchers yet - New launcher in the banner makes one."),le=M.computed(()=>r.value.length>1&&($.value!=="all"||!!D.value.trim())),O=a=>r.peek().find(t=>t.id===a);let N=null;const Ne=async()=>{if(N)return N;const[a,t]=await Promise.all([ye.forms.list().catch(()=>[]),ye.blocks.list().catch(()=>[])]);return N={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}))},N};async function Pe(){try{const a=await ee.list();if(!T())return;r.value=Array.isArray(a?.launchers)?a.launchers:[],H.value="",B.value=!0}catch(a){const t=String(a?.message||a);/switched off/i.test(t)?B.value=!1:H.value=`Could not load the launchers: ${t}`}finally{ae.value=!1}}async function P(a,t){try{const l=await ee.save(a);return T()&&(r.value=l.launchers),Ee(Te),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});r.value=r.peek().map(c=>c.id===a.id?l.launcher:c),Ee(Te),E.toast(`"${a.name}" ${t?"switched on":"switched off"}.`,{type:"success",duration:2e3})}catch(l){E.toast(`Not changed: ${l.message||l}`,{type:"error"}),r.value=[...r.peek()]}}async function Ae(a){const t=r.peek(),l=t.findIndex(i=>i.id===a.id),c=la(a,t);await P([...t.slice(0,l+1),c,...t.slice(l+1)],`Duplicated as "${c.name}" - switched off until you are ready.`)}async function Fe(a){await E.confirm(`Delete the launcher "${Z(a.name)}"? It goes from every page. This cannot be undone.`)&&await P(r.peek().filter(t=>t.id!==a.id),"Launcher deleted.")}function Re(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 Ie(a){const t=O(a);return t?[{header:t.name},{label:"Edit",icon:"edit",action:()=>L(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:()=>Re(t)},{type:"divider"},{label:"Duplicate",icon:"copy",action:()=>Ae(t)},{type:"divider"},{label:"Delete\u2026",icon:"trash",danger:!0,action:()=>Fe(t)}]:[]}let w=null;const j=new Set;function Ue(a,t,l){const c=a.close.bind(a);let i=!1,b=!1;return a.close=async p=>{if(!i&&p!==!0&&t()){if(b)return;b=!0;const z=await E.confirm(l);if(b=!1,!z)return}return i=!0,c()},()=>{i=!0}}async function L(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 c=!l,i=na(l||ea(r.peek())),b={...i,refPage:i.kind==="page"?i.ref:"",refForm:i.kind==="form"?i.ref:"",refBlock:i.kind==="block"?i.ref:"",bgChoice:U(i.background),bgHex:U(i.background)==="custom"?i.background:"",fgChoice:U(i.text),fgHex:U(i.text)==="custom"?i.text:"",...t||{}};delete b.ref,delete b.background,delete b.text;const p=Object.fromEntries(Object.entries(b).map(([e,o])=>[e,M.observable(o)])),z=()=>Object.fromEntries(Object.keys(p).map(e=>[e,p[e].peek()])),de=e=>JSON.stringify(Object.fromEntries(Object.entries(e).map(([o,n])=>[o,typeof n=="boolean"?n:String(n??"")]))),De=de(b),re=()=>de(z())!==De||!!t,ce=e=>{const o=e.actionType==="chat"?"page":e.kind;return{...e,kind:o,ref:o==="form"?e.refForm:o==="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}},Y=()=>ce(Object.fromEntries(Object.keys(p).map(e=>[e,p[e].value]))),K=M.computed(()=>aa(Y())),A=M.observable(!1),pe=(e,o)=>{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)},o?{vw:120,vh:220,scale:.5,phone:!0}:{vw:320,vh:200,scale:.5}),m=e.triggerStyle==="icon-text"&&!o;return{left:`${n.left}px`,top:`${n.top}px`,height:`${n.size}px`,width:m?"auto":`${n.size}px`,padding:m?"0 6px":"0","border-radius":m?"999px":`${Math.round(Math.min(Number(e.radius),Number(e.size)/2)/Number(e.size)*100)}%`,"--lnx-bg":Me(e.background)||"var(--dm-primary)","--lnx-fg":Me(e.text)||"var(--dm-primary-text)"}},ue={...p,saving:A,err:M.computed(()=>K.value.errors),warn:M.computed(()=>K.value.warnings),cannot:M.computed(()=>A.value||Object.keys(K.value.errors).length>0),maxRadius:M.computed(()=>Math.floor(Number(p.size.value)/2)),previewStyle:M.computed(()=>pe(Y(),!1)),phonePreviewStyle:M.computed(()=>pe(Y(),!0)),saveText:c?"Create launcher":"Save",linkHref:c?"":G(l.id),linkText:c?"Create the launcher first - then it has a link":G(l.id)},We=M.effect(()=>{const e=Math.floor(Number(p.size.value)/2);Number(p.radius.peek())>e&&(p.radius.value=e)}),he=(e,o,n)=>{let m=e.peek();return M.effect(()=>{const C=e.value;C!==m&&(m=C,o.value=n(C))})},qe=he(p.widthUnit,p.customWidth,e=>e==="%"?90:900),je=he(p.heightUnit,p.customHeight,e=>e==="px"?600:70),k=E.slideover({title:c?"New launcher":`Edit ${Z(l.name)}`,size:"lg",position:"right"}),v=ua(pa),fe=await Ne().catch(()=>({forms:[],blocks:[]})),me=(e,o,n)=>{const m=document.createElement("option");m.value="",m.textContent=o.length?"Choose\u2026":"None yet",e.appendChild(m);const C=n&&!o.some(F=>F.value===n)?[...o,{value:n,text:`${n} (missing)`}]:o;for(const F of C){const X=document.createElement("option");X.value=F.value,X.textContent=F.text,e.appendChild(X)}};me(v.querySelector(".lnx-form-select"),fe.forms,b.refForm),me(v.querySelector(".lnx-block-select"),fe.blocks,b.refBlock);let be=()=>{};async function ve(){if(!ue.cannot.peek()){A.value=!0;try{const e=sa(ce(z()),l?.id||""),o=r.peek(),n=c?[...o,e]:o.map(C=>C.id===l.id?e:C);if(!await P(n,c?`Created "${e.name}".`:"Saved."))return;be(),k.close()}finally{A.value=!1}}}k.element.appendChild(v);const Ye=ke(v),_e=M.applyBindings(ue,v,{methods:{save:ve,cancel:()=>k.close()}}),Ke=e=>{(e.ctrlKey||e.metaKey)&&e.key==="Enter"&&(e.preventDefault(),ve())};v.addEventListener("keydown",Ke);const xe=async e=>{const o=e.target.closest(".lnx-corners button[data-pos]");if(o){const n=o.closest(".lnx-corners-phone")?"phonePosition":"position";p[n].value=o.dataset.pos;return}if(e.target.closest(".lnx-pick-icon")){const{openIconPicker:n}=await import("../lib/card-builder.js");n(m=>{p.icon.value=m});return}if(e.target.closest(".lnx-copy-link")&&!c){let n=!1;try{n=await _.copyToClipboard(G(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-page")){const{openPagePicker:n}=await import("../lib/page-picker.js");n(m=>{p.refPage.value=m})}};v.addEventListener("click",xe);const Xe=M.effect(()=>{const e=p.icon.value;v.querySelectorAll(".lnx-preview-disc").forEach(o=>{const n=document.createElement("span");n.setAttribute("data-icon",e||"message-circle"),n.className="lnx-preview-icon",o.querySelector(".lnx-preview-icon")?.replaceWith(n),I.scan(o)})}),ge={id:l?.id??null,dirty:re,values:z};w=ge,j.add(k),Ve(k,()=>{_e.dispose(),Ye(),We?.(),qe?.(),je?.(),Xe?.(),v.removeEventListener("click",xe),j.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=d.querySelector(".lnx-list");g.innerHTML=ra;const He=M.applyBindings({launchers:r,loading:ae,loadError:H,toolOn:B,filter:$,query:D,rows:W,counts:Le,emptyText:ze,dragNote:le},d,{methods:{showAll:()=>{$.value="all"},showOn:()=>{$.value="on"},showOff:()=>{$.value="off"}}});x.add(()=>He.dispose()),x.add(ke(d,{position:"bottom"})),x.add(M.effect(()=>{W.value,requestAnimationFrame(()=>{d.isConnected&&I.scan(g)})}));const Be=E.contextMenu(g,{cursor:"glyph",match:".lnx-row",inherit:!1,density:"compact",items:a=>Ie(a.dataset.id)});x.add(()=>Be?.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}L(t.dataset.id)},se=a=>{const t=a.target.closest(".lnx-toggle"),l=t?.closest(".lnx-row"),c=l&&O(l.dataset.id);c&&q(c,t.checked)},oe=a=>{const t=a.target.closest(".lnx-row");t&&(a.key==="F10"&&a.shiftKey?(a.preventDefault(),Se(t)):a.key==="Enter"&&a.target===t&&L(t.dataset.id))};if(g.addEventListener("click",ne),g.addEventListener("change",se),g.addEventListener("keydown",oe),x.add(()=>{g.removeEventListener("click",ne),g.removeEventListener("change",se),g.removeEventListener("keydown",oe)}),typeof E.sortable=="function"){const a=Ge(),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:c,to:i})=>{if(a.restore(l),le.peek()){E.toast("Clear the search and show All to reorder.",{type:"info"}),r.value=[...r.peek()];return}const b=ia(r.peek(),c,i);r.value=b,P(b)}});x.add(()=>t.destroy())}we(s,{id:"launchers-new",icon:"plus",title:"New launcher",onClick:()=>L()}),we(s,{id:"launchers-chats",icon:"message-square",title:"Chats - the conversations from chat launchers",onClick:()=>{location.hash="#/launchers/chats"}});const ie=a=>{w?.dirty()&&(a.preventDefault(),a.returnValue="")};if(window.addEventListener("beforeunload",ie),x.add(()=>window.removeEventListener("beforeunload",ie)),x.add(()=>{if(w?.dirty())try{S.set(R,{id:w.id,values:w.values(),at:new Date().toISOString()})}catch{}[...j].forEach(a=>{try{a.close(!0)}catch{}})}),I.scan(d),await Pe(),!T())return;let y=null;try{y=S.get(R)}catch{}if(y?.values){try{S.remove?S.remove(R):S.set(R,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?`)&&T()&&L(y.id&&O(y.id)?y.id:null,y.values)}}};
|