domma-cms 1.21.0 → 1.22.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 +7 -0
- package/admin/css/site-settings.css +1 -0
- package/admin/js/app.js +3 -3
- package/admin/js/lib/context-menu-action-help.js +1 -1
- package/admin/js/lib/effects-builder.js +2 -2
- package/admin/js/lib/favicon-generator.js +1 -1
- package/admin/js/lib/font-picker.js +22 -0
- package/admin/js/lib/scribe-composer.js +1 -1
- package/admin/js/lib/shortcode-form.js +3 -3
- package/admin/js/lib/site-search-section.js +1 -1
- package/admin/js/lib/site-settings-arrange.js +3 -3
- package/admin/js/templates/appearance.html +243 -0
- package/admin/js/templates/docs/usage-site-settings.html +11 -22
- package/admin/js/templates/footer.html +145 -0
- package/admin/js/templates/search.html +14 -15
- package/admin/js/templates/settings.html +5 -436
- package/admin/js/views/appearance.js +1 -0
- package/admin/js/views/footer.js +1 -0
- package/admin/js/views/index.js +1 -1
- package/admin/js/views/page-editor.js +10 -10
- package/admin/js/views/search.js +2 -2
- package/admin/js/views/settings.js +3 -3
- package/admin/js/views/theme.js +4 -4
- package/docs/screenshots/font-picker-desktop.png +0 -0
- package/docs/screenshots/font-picker-mobile.png +0 -0
- package/package.json +1 -1
- package/server/server.js +5 -2
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import{api as
|
|
1
|
+
import{api as B,apiRequest as k}from"../api.js";import{placeTools as Le}from"../lib/sidebar-grouping.js";import{addBannerAction as me}from"../lib/plugin-chrome.js";import{helpPopovers as Re}from"../lib/help-popover.js";import{openMenuAt as G,sidebarCount as fe}from"../lib/tool-kit.js";import{changedTabs as Ie,describeCacheKey as J,draftOf as Ae,expiresIn as Pe,formFromDraft as $e,siteSettingsForm as Be,homeValue as De,siteSettingsPayload as He,siteUrlError as he,settingsProblems as je,snapshot as ve,TAB_FIELDS as qe}from"../lib/site-settings-arrange.js";import{pickMedia as Ue}from"../lib/media-picker.js";import{makeIconInput as _e}from"../lib/shortcode-modal.js";import{fmtDateTime as Ke}from"../lib/dates.js";const Q=/^\/settings(\?.*)?$/,be="#/settings",g="settings.draft",Fe=`
|
|
2
2
|
<div class="stx-problem">
|
|
3
3
|
<span class="stx-chip" data-bind-class="tone === 'danger' ? 'is-bad' : 'is-warn'">{{label}}</span>
|
|
4
4
|
<span>{{text}}</span>
|
|
5
5
|
<button type="button" class="btn btn-sm btn-ghost" data-go="{{tab}}">Go there</button>
|
|
6
|
-
</div>`,
|
|
6
|
+
</div>`,ze=`
|
|
7
7
|
<div class="stx-row" data-id="{{id}}" tabindex="0">
|
|
8
8
|
<span class="stx-main"><strong>{{path}}</strong><small>{{meta}}</small></span>
|
|
9
9
|
<span class="stx-chip">{{expires}}</span>
|
|
10
10
|
<button type="button" class="stx-kebab" aria-label="Actions for {{path}}" title="Actions">\u22EE</button>
|
|
11
|
-
</div>`,j=["general","branding","favicon","footer","email","pageNavigation","cookies","breadcrumbs","motion","cache","search"];async function Xe(c,d){const[o,k]=await Promise.all([H.get("/api/sidebar/menu").catch(()=>({items:[]})),H.get("/api/sidebar/registered-items").catch(()=>[])]),n=new Map([["/","Dashboard (built in)"]]),i=(l,m)=>{for(const r of l||[]){if(!r||r.hidden||r.restricted)continue;const p=typeof r.url=="string"?r.url:"";p.startsWith("#/")&&p.length>2&&!n.has(p.slice(1))&&n.set(p.slice(1),`${m?`${m} \u203A `:""}${r.text||p}`),i(r.items,r.url?m:r.text||m)}};i(Ae(o?.items||[],k||[]),""),n.has(d)||n.set(d,`${d} (not in the sidebar)`),c.replaceChildren();for(const[l,m]of n){const r=document.createElement("option");r.value=l,r.textContent=m,c.appendChild(r)}}let h=null,ke=!1;function Ze(){ke||!window.R?.use||(ke=!0,R.use((c,d,o)=>!(X.test(d?.path||"")&&!X.test(c?.path||""))||!h?.dirty()?o():E.confirm("You have unsaved settings. Leave anyway? They are kept as a draft for your next visit (not the SMTP password).").then(n=>{n?o():history.replaceState(null,"","#/settings")})),M.subscribe("router:afterChange",({to:c}={})=>{if(h&&!X.test(c?.path||"")){const d=h;h=null,d.dispose()}}))}export const settingsView={templateUrl:"/admin/js/templates/settings.html",async onMount(c){if(Ze(),h){const e=h;h=null,e.dispose()}const d=[],o=e=>(d.push(e),e);let k=!1;const n=c.get(0).querySelector(".stx")||c.get(0),i=()=>!k&&n.isConnected;let l=null;const m=E.loader(c.get(0),{type:"dots"});let r;try{r=await D.settings.get()}catch(e){m.destroy(),E.toast(`Could not load the settings: ${e.message||e}`,{type:"error"});return}if(m.destroy(),!n.isConnected)return;const p=M.observable(r||{}),Z=Ue(r||{}),s={};for(const[e,t]of Object.entries(Z))s[e]=M.observable(t);const q=()=>Object.fromEntries(Object.keys(s).map(e=>[e,s[e].value])),ee=()=>Object.fromEntries(Object.keys(s).map(e=>[e,s[e].peek()])),b=M.observable(Z),C=M.computed(()=>Q(b.value)),T=M.computed(()=>Q(q())!==C.value),y=M.observable(!1),L=M.observable(""),te=M.observable(!1);D.plugins.policy().then(e=>{i()&&(te.value=e?.signedOnly===!1)}).catch(()=>{});const U=M.observable(!1),ae=M.computed(()=>{const e=new Set(Be(q(),b.value));return Object.fromEntries(Object.keys(ze).map(t=>[t,e.has(t)]))}),F=M.observable([]);o(M.effect(()=>{F.value=Ke(q(),p.value).map(e=>({...e,label:e.tone==="danger"?"Mail":"Check"}))}));const se=M.observable(""),O=M.observable(!1),P=M.observable(""),A=M.observable(""),f=M.observable(null),_=M.observable([]),K=M.observable(""),z=M.observable(!0),N=M.observable(""),ne=M.observable([]);o(M.effect(()=>{const e=K.value.trim().toLowerCase(),t=Date.now();ne.value=[..._.value].reverse().filter(a=>!e||String(a.key).toLowerCase().includes(e)||(a.tags||[]).some(u=>String(u).toLowerCase().includes(e))).map(a=>{const u=J(a.key);return{id:a.key,path:u.path,meta:[u.page?`as ${u.role}`:"not a page",(a.tags||[]).join(", ")].filter(Boolean).join(" \xB7 "),expires:He(a.expiresAt,t)}})}));const oe=Ve(s.favicon,s.brandLogo,i),Se={...oe.data,...s,saving:y,dirty:T,tabs:ae,problems:F,testTo:se,testing:O,testResult:P,testTone:A,cacheQuery:K,cacheLoading:z,cacheError:N,cacheRows:ne,errorText:L,problemsText:M.computed(()=>F.value.length?"yes":""),siteUrlError:M.computed(()=>ge(s.siteUrl.value)),noSmtp:M.computed(()=>!String(s.smtpHost.value||"").trim()),mtSizeText:M.computed(()=>`${s.mtIconSize.value} px`),mtRadiusText:M.computed(()=>`${s.mtIconRadius.value} px`),mayAllowInsecureTLS:te,dirtyEmail:M.computed(()=>ae.value.email),cacheOn:M.computed(()=>f.value?.enabled===!0),cacheState:M.computed(()=>{const e=f.value;return e?e.enabled?`On (${e.driver})`:"Off":"Status unknown"}),cacheSize:M.computed(()=>{const e=f.value;return e?.enabled&&e.size!==null&&e.size!==void 0?`${e.size}${e.maxItems?` of ${e.maxItems}`:""} entries`:""}),cacheHits:M.computed(()=>{const e=f.value?.hitRate;return e==null?"":`${Math.round(e*100)}% served from the cache`}),cacheToggleText:M.computed(()=>f.value?.enabled?"Turn off":"Turn on"),cacheEmpty:M.computed(()=>K.value.trim()?"Nothing matches.":f.value?.enabled?"The cache is empty - pages are cached as visitors open them.":"The cache is off.")};async function V(){if(y.peek())return;const e=ee(),t=b.peek();if(l?.dirty()&&Q(e)===C.peek()){y.value=!0;try{await l.save()}finally{y.value=!1}return}const a=ge(e.siteUrl);if(a){E.toast(`Site URL: ${a}`,{type:"error"});return}const u=je(e)[0];if(u){E.toast(u,{type:"error"});return}y.value=!0,L.value="";const Ie=String(e.title).trim()!==String(t.title).trim();try{await D.settings.save(_e(e,p.peek(),{adminHomeReady:U.peek()}));const B=await D.settings.get().catch(()=>null);if(!i())return;B&&(p.value=B);const Pe={...e,smtpPass:""};s.smtpPass.value="",b.value=Pe;try{S.remove?S.remove(w):S.set(w,null)}catch{}document.dispatchEvent(new CustomEvent("dm:admin-home-changed")),(Ie||["adminBrandEnabled","adminBrandTitle","adminBrandLogo","adminBrandIcon"].some(ve=>e[ve]!==t[ve]))&&document.dispatchEvent(new CustomEvent("dm:sidebar-rebuild")),ye(we),E.toast("Settings saved.",{type:"success"}),l?.dirty()&&await l.save()}catch(B){L.value=B.message||"Could not save the settings.",E.toast("Settings not saved - see the message at the top.",{type:"error"})}finally{y.value=!1}}async function Ee(){await E.confirm("Throw away your unsaved settings?")&&(re(b.peek()),l?.discard(),L.value="")}function re(e){for(const[t,a]of Object.entries(e))s[t]&&(s[t].value=a)}async function Me(){if(!O.peek()){O.value=!0,A.value="",P.value="Sending\u2026";try{const e=await x("/settings/test-email",{method:"POST",body:JSON.stringify({to:se.peek().trim()||void 0})});if(!i())return;P.value=e?.message||"Test email sent.",A.value="is-ok"}catch(e){if(!i())return;P.value=e.message||"Could not send the test email.",A.value="is-bad"}finally{O.value=!1}}}async function $(){z.value=!0;try{const[e,t]=await Promise.all([x("/cache/status").catch(()=>null),x("/cache/keys")]);if(!i())return;f.value=e,_.value=Array.isArray(t?.entries)?t.entries:[],N.value=""}catch(e){if(!i())return;N.value=`Could not read the cache: ${e.message||e}`}finally{z.value=!1}}async function xe(){if(await E.confirm("Clear the whole response cache? The next visitor to each page renders it afresh.")){try{await x("/cache/clear",{method:"POST"}),E.toast("Cache cleared.",{type:"success"})}catch(e){E.toast(e.message||"Could not clear the cache.",{type:"error"})}i()&&await $()}}async function Ce(){const e=f.peek()?.enabled===!0;if(!(e&&!await E.confirm("Turn the response cache off? Every visit will render its page afresh until it is turned back on. The choice is saved (config/cache.json)."))){try{f.value=await x("/cache/toggle",{method:"POST",body:JSON.stringify({enabled:!e})}),E.toast(e?"Cache turned off.":"Cache turned on.",{type:"success"}),ye(we)}catch(t){E.toast(t.message||"Could not change the cache.",{type:"error"})}i()&&await $()}}const ie=e=>_.peek().find(t=>t.key===e);function Te(e){const t=ie(e);if(!t)return[];const a=J(t.key);return[{header:a.path},{label:"Open the page",icon:"external-link",disabled:!a.page,action:()=>window.open(a.path,"_blank","noopener")},{label:"Copy key",icon:"copy",action:async()=>{try{await navigator.clipboard.writeText(t.key),E.toast("Key copied.",{type:"success"})}catch{E.toast("Could not copy - your browser blocked the clipboard.",{type:"warning"})}}},...a.page?[{label:"Copy address",icon:"link",action:async()=>{try{await navigator.clipboard.writeText(new URL(a.path,location.origin).href),E.toast("Address copied.",{type:"success"})}catch{E.toast("Could not copy - your browser blocked the clipboard.",{type:"warning"})}}}]:[]]}n.querySelector(".stx-problems").innerHTML=Je;const g=n.querySelector(".stx-list");g.innerHTML=Qe;const W=E.tabs(n.querySelector(".stx-tabs"),{tabSelector:".tab-item",panelSelector:".tab-panel"}),ce=new URLSearchParams(location.hash.split("?")[1]||"").get("tab");j.includes(ce)&&W.activate(j.indexOf(ce));const Re=M.applyBindings(Se,n,{methods:{...oe.methods,save:V,discard:Ee,sendTest:Me,refreshCache:$,clearCache:xe,toggleCache:Ce,pickBrandImage:async e=>{const t=await Ne({title:"Choose a branding image",current:s[e].peek()});t&&i()&&(s[e].value=t)},clearBrandImage:e=>{s[e].value=""},corner:e=>{s.bcPosition.value=e},motionCorner:e=>{s.mtPosition.value=e},motionPlacement:e=>{s.mtPlacement.value=e},goTab:e=>{const t=j.indexOf(e);t>=0&&W.activate(t)}}}),le=n.querySelector("#stx-mt-radius");o(M.effect(()=>{const e=Math.floor((Number.parseInt(s.mtIconSize.value,10)||52)/2);le.max=String(e);const t=Number.parseInt(s.mtIconRadius.peek(),10)||0;t>e?s.mtIconRadius.value=String(e):le.value=String(t)})),o(()=>Re.dispose());for(const e of n.querySelectorAll("[data-brand-icon]")){const t=e.dataset.brandIcon,a=We("Choose an icon",s[t].peek());a.input.id=`stx-${t}`,a.input.classList.add("form-input");const u=()=>{s[t].value=a.input.value};a.input.addEventListener("input",u),o(()=>a.input.removeEventListener("input",u)),o(M.effect(()=>{a.input.value=s[t].value})),e.appendChild(a.el)}o($e(n,{position:"bottom"}));const Le=e=>{const t=e.target.closest("[data-go]");if(!t)return;const a=j.indexOf(t.dataset.go);a>=0&&W.activate(a)};n.querySelector(".stx-problems").addEventListener("click",Le);const Y=n.querySelector("#stx-admin-home");Xe(Y,Fe(s.adminHome.peek())).then(()=>{i()&&(Y.value=s.adminHome.peek(),U.value=!0)}).catch(()=>{});const Oe=E.contextMenu(g,{cursor:"glyph",match:".stx-row",inherit:!1,density:"compact",items:e=>Te(e.dataset.id)});o(()=>Oe?.destroy?.());const ue=e=>{const t=ie(e.dataset.id),a=t&&J(t.key);a?.page?window.open(a.path,"_blank","noopener"):G(e)},de=e=>{const t=e.target.closest(".stx-row");if(!t)return;const a=e.target.closest(".stx-kebab");if(a){G(a);return}ue(t)},me=e=>{const t=e.target.closest(".stx-row");t&&(e.key==="F10"&&e.shiftKey?(e.preventDefault(),G(t)):e.key==="Enter"&&e.target===t&&ue(t))};g.addEventListener("click",de),g.addEventListener("keydown",me),o(()=>{g.removeEventListener("click",de),g.removeEventListener("keydown",me)}),be(c,{id:"settings-view-site",icon:"external-link",title:"View site",onClick:()=>window.open("/","_blank","noopener")}),be(c,{id:"settings-save",icon:"save",title:"Save (Ctrl+S)",onClick:()=>V()});const pe=e=>{!(e.ctrlKey||e.metaKey)||e.key!=="s"||(e.preventDefault(),e.stopImmediatePropagation(),V())};document.addEventListener("keydown",pe,!0),o(()=>document.removeEventListener("keydown",pe,!0));const fe=()=>{if(T.peek())try{S.set(w,{form:De(ee()),base:C.peek(),at:new Date().toISOString()})}catch{}},he=e=>{T.peek()&&(fe(),e.preventDefault(),e.returnValue="")};window.addEventListener("beforeunload",he),o(()=>window.removeEventListener("beforeunload",he)),h={dirty:()=>T.peek()||!!l?.dirty(),dispose(){k=!0,fe(),d.splice(0).reverse().forEach(e=>{try{e()}catch{}})}},I.scan(n),$();let v=null;try{v=S.get(w)}catch{}if(v?.form){try{S.remove?S.remove(w):S.set(w,null)}catch{}const e=v.base&&v.base!==C.peek(),t=v.at?` (${Ye(v.at)})`:"",a=e?`You left unsaved settings${t}, but the saved settings have changed since. Restore your version anyway?`:`You left unsaved settings${t}. Restore them?`;await E.confirm(a)&&i()&&(re(qe(b.peek(),v.form)),U.peek()&&(Y.value=s.adminHome.peek()))}i()&&(l=Ge(n),o(()=>l.dispose()))}};
|
|
11
|
+
</div>`,D=["general","branding","email","cookies","cache"];async function Ne(c,l){const[r,w]=await Promise.all([H.get("/api/sidebar/menu").catch(()=>({items:[]})),H.get("/api/sidebar/registered-items").catch(()=>[])]),n=new Map([["/","Dashboard (built in)"]]),i=(v,u)=>{for(const o of v||[]){if(!o||o.hidden||o.restricted)continue;const m=typeof o.url=="string"?o.url:"";m.startsWith("#/")&&m.length>2&&!n.has(m.slice(1))&&n.set(m.slice(1),`${u?`${u} \u203A `:""}${o.text||m}`),i(o.items,o.url?u:o.text||u)}};i(Le(r?.items||[],w||[]),""),n.has(l)||n.set(l,`${l} (not in the sidebar)`),c.replaceChildren();for(const[v,u]of n){const o=document.createElement("option");o.value=v,o.textContent=u,c.appendChild(o)}}let f=null,ye=!1;function Ve(){ye||!window.R?.use||(ye=!0,R.use((c,l,r)=>!(Q.test(l?.path||"")&&!Q.test(c?.path||""))||!f?.dirty()?r():E.confirm("You have unsaved settings. Leave anyway? They are kept as a draft for your next visit (not the SMTP password).").then(n=>{n?r():history.replaceState(null,"","#/settings")})),M.subscribe("router:afterChange",({to:c}={})=>{if(f&&!Q.test(c?.path||"")){const l=f;f=null,l.dispose()}}))}export const settingsView={templateUrl:"/admin/js/templates/settings.html",async onMount(c){if(Ve(),f){const e=f;f=null,e.dispose()}const l=[],r=e=>(l.push(e),e);let w=!1;const n=c.get(0).querySelector(".stx")||c.get(0),i=()=>!w&&n.isConnected,v=E.loader(c.get(0),{type:"dots"});let u;try{u=await B.settings.get()}catch(e){v.destroy(),E.toast(`Could not load the settings: ${e.message||e}`,{type:"error"});return}if(v.destroy(),!n.isConnected)return;const o=M.observable(u||{}),m=Be(u||{}),a={};for(const[e,t]of Object.entries(m))a[e]=M.observable(t);const j=()=>Object.fromEntries(Object.keys(a).map(e=>[e,a[e].value])),X=()=>Object.fromEntries(Object.keys(a).map(e=>[e,a[e].peek()])),b=M.observable(m),q=M.computed(()=>ve(b.value)),C=M.computed(()=>ve(j())!==q.value),x=M.observable(!1),T=M.observable(""),Z=M.observable(!1);B.plugins.policy().then(e=>{i()&&(Z.value=e?.signedOnly===!1)}).catch(()=>{});const U=M.observable(!1),ee=M.computed(()=>{const e=new Set(Ie(j(),b.value));return Object.fromEntries(Object.keys(qe).map(t=>[t,e.has(t)]))}),_=M.observable([]);r(M.effect(()=>{_.value=je(j(),o.value).map(e=>({...e,label:e.tone==="danger"?"Mail":"Check"}))}));const te=M.observable(""),O=M.observable(!1),L=M.observable(""),A=M.observable(""),p=M.observable(null),K=M.observable([]),F=M.observable(""),z=M.observable(!0),N=M.observable(""),se=M.observable([]);r(M.effect(()=>{const e=F.value.trim().toLowerCase(),t=Date.now();se.value=[...K.value].reverse().filter(s=>!e||String(s.key).toLowerCase().includes(e)||(s.tags||[]).some(d=>String(d).toLowerCase().includes(e))).map(s=>{const d=J(s.key);return{id:s.key,path:d.path,meta:[d.page?`as ${d.role}`:"not a page",(s.tags||[]).join(", ")].filter(Boolean).join(" \xB7 "),expires:Pe(s.expiresAt,t)}})}));const ge={...a,saving:x,dirty:C,tabs:ee,problems:_,testTo:te,testing:O,testResult:L,testTone:A,cacheQuery:F,cacheLoading:z,cacheError:N,cacheRows:se,errorText:T,problemsText:M.computed(()=>_.value.length?"yes":""),siteUrlError:M.computed(()=>he(a.siteUrl.value)),noSmtp:M.computed(()=>!String(a.smtpHost.value||"").trim()),mayAllowInsecureTLS:Z,dirtyEmail:M.computed(()=>ee.value.email),cacheOn:M.computed(()=>p.value?.enabled===!0),cacheState:M.computed(()=>{const e=p.value;return e?e.enabled?`On (${e.driver})`:"Off":"Status unknown"}),cacheSize:M.computed(()=>{const e=p.value;return e?.enabled&&e.size!==null&&e.size!==void 0?`${e.size}${e.maxItems?` of ${e.maxItems}`:""} entries`:""}),cacheHits:M.computed(()=>{const e=p.value?.hitRate;return e==null?"":`${Math.round(e*100)}% served from the cache`}),cacheToggleText:M.computed(()=>p.value?.enabled?"Turn off":"Turn on"),cacheEmpty:M.computed(()=>F.value.trim()?"Nothing matches.":p.value?.enabled?"The cache is empty - pages are cached as visitors open them.":"The cache is off.")};async function V(){if(x.peek())return;const e=X(),t=b.peek(),s=he(e.siteUrl);if(s){E.toast(`Site URL: ${s}`,{type:"error"});return}x.value=!0,T.value="";const d=String(e.title).trim()!==String(t.title).trim();try{await B.settings.save(He(e,o.peek(),{adminHomeReady:U.peek()}));const $=await B.settings.get().catch(()=>null);if(!i())return;$&&(o.value=$);const Oe={...e,smtpPass:""};a.smtpPass.value="",b.value=Oe;try{S.remove?S.remove(g):S.set(g,null)}catch{}document.dispatchEvent(new CustomEvent("dm:admin-home-changed")),(d||["adminBrandEnabled","adminBrandTitle","adminBrandLogo","adminBrandIcon"].some(pe=>e[pe]!==t[pe]))&&document.dispatchEvent(new CustomEvent("dm:sidebar-rebuild")),fe(be),E.toast("Settings saved.",{type:"success"})}catch($){T.value=$.message||"Could not save the settings.",E.toast("Settings not saved - see the message at the top.",{type:"error"})}finally{x.value=!1}}async function we(){await E.confirm("Throw away your unsaved settings?")&&(ae(b.peek()),T.value="")}function ae(e){for(const[t,s]of Object.entries(e))a[t]&&(a[t].value=s)}async function ke(){if(!O.peek()){O.value=!0,A.value="",L.value="Sending\u2026";try{const e=await k("/settings/test-email",{method:"POST",body:JSON.stringify({to:te.peek().trim()||void 0})});if(!i())return;L.value=e?.message||"Test email sent.",A.value="is-ok"}catch(e){if(!i())return;L.value=e.message||"Could not send the test email.",A.value="is-bad"}finally{O.value=!1}}}async function P(){z.value=!0;try{const[e,t]=await Promise.all([k("/cache/status").catch(()=>null),k("/cache/keys")]);if(!i())return;p.value=e,K.value=Array.isArray(t?.entries)?t.entries:[],N.value=""}catch(e){if(!i())return;N.value=`Could not read the cache: ${e.message||e}`}finally{z.value=!1}}async function Ee(){if(await E.confirm("Clear the whole response cache? The next visitor to each page renders it afresh.")){try{await k("/cache/clear",{method:"POST"}),E.toast("Cache cleared.",{type:"success"})}catch(e){E.toast(e.message||"Could not clear the cache.",{type:"error"})}i()&&await P()}}async function Se(){const e=p.peek()?.enabled===!0;if(!(e&&!await E.confirm("Turn the response cache off? Every visit will render its page afresh until it is turned back on. The choice is saved (config/cache.json)."))){try{p.value=await k("/cache/toggle",{method:"POST",body:JSON.stringify({enabled:!e})}),E.toast(e?"Cache turned off.":"Cache turned on.",{type:"success"}),fe(be)}catch(t){E.toast(t.message||"Could not change the cache.",{type:"error"})}i()&&await P()}}const ne=e=>K.peek().find(t=>t.key===e);function Me(e){const t=ne(e);if(!t)return[];const s=J(t.key);return[{header:s.path},{label:"Open the page",icon:"external-link",disabled:!s.page,action:()=>window.open(s.path,"_blank","noopener")},{label:"Copy key",icon:"copy",action:async()=>{try{await navigator.clipboard.writeText(t.key),E.toast("Key copied.",{type:"success"})}catch{E.toast("Could not copy - your browser blocked the clipboard.",{type:"warning"})}}},...s.page?[{label:"Copy address",icon:"link",action:async()=>{try{await navigator.clipboard.writeText(new URL(s.path,location.origin).href),E.toast("Address copied.",{type:"success"})}catch{E.toast("Could not copy - your browser blocked the clipboard.",{type:"warning"})}}}]:[]]}n.querySelector(".stx-problems").innerHTML=Fe;const y=n.querySelector(".stx-list");y.innerHTML=ze;const W=E.tabs(n.querySelector(".stx-tabs"),{tabSelector:".tab-item",panelSelector:".tab-panel"}),oe=new URLSearchParams(location.hash.split("?")[1]||"").get("tab");D.includes(oe)&&W.activate(D.indexOf(oe));const Ce=M.applyBindings(ge,n,{methods:{save:V,discard:we,sendTest:ke,refreshCache:P,clearCache:Ee,toggleCache:Se,pickBrandImage:async e=>{const t=await Ue({title:"Choose a branding image",current:a[e].peek()});t&&i()&&(a[e].value=t)},clearBrandImage:e=>{a[e].value=""},goTab:e=>{const t=D.indexOf(e);t>=0&&W.activate(t)}}});r(()=>Ce.dispose());for(const e of n.querySelectorAll("[data-brand-icon]")){const t=e.dataset.brandIcon,s=_e("Choose an icon",a[t].peek());s.input.id=`stx-${t}`,s.input.classList.add("form-input");const d=()=>{a[t].value=s.input.value};s.input.addEventListener("input",d),r(()=>s.input.removeEventListener("input",d)),r(M.effect(()=>{s.input.value=a[t].value})),e.appendChild(s.el)}r(Re(n,{position:"bottom"}));const xe=e=>{const t=e.target.closest("[data-go]");if(!t)return;const s=D.indexOf(t.dataset.go);s>=0&&W.activate(s)};n.querySelector(".stx-problems").addEventListener("click",xe);const Y=n.querySelector("#stx-admin-home");Ne(Y,De(a.adminHome.peek())).then(()=>{i()&&(Y.value=a.adminHome.peek(),U.value=!0)}).catch(()=>{});const Te=E.contextMenu(y,{cursor:"glyph",match:".stx-row",inherit:!1,density:"compact",items:e=>Me(e.dataset.id)});r(()=>Te?.destroy?.());const re=e=>{const t=ne(e.dataset.id),s=t&&J(t.key);s?.page?window.open(s.path,"_blank","noopener"):G(e)},ie=e=>{const t=e.target.closest(".stx-row");if(!t)return;const s=e.target.closest(".stx-kebab");if(s){G(s);return}re(t)},ce=e=>{const t=e.target.closest(".stx-row");t&&(e.key==="F10"&&e.shiftKey?(e.preventDefault(),G(t)):e.key==="Enter"&&e.target===t&&re(t))};y.addEventListener("click",ie),y.addEventListener("keydown",ce),r(()=>{y.removeEventListener("click",ie),y.removeEventListener("keydown",ce)}),me(c,{id:"settings-view-site",icon:"external-link",title:"View site",onClick:()=>window.open("/","_blank","noopener")}),me(c,{id:"settings-save",icon:"save",title:"Save (Ctrl+S)",onClick:()=>V()});const le=e=>{!(e.ctrlKey||e.metaKey)||e.key!=="s"||(e.preventDefault(),e.stopImmediatePropagation(),V())};document.addEventListener("keydown",le,!0),r(()=>document.removeEventListener("keydown",le,!0));const ue=()=>{if(C.peek())try{S.set(g,{form:Ae(X()),base:q.peek(),at:new Date().toISOString()})}catch{}},de=e=>{C.peek()&&(ue(),e.preventDefault(),e.returnValue="")};window.addEventListener("beforeunload",de),r(()=>window.removeEventListener("beforeunload",de)),f={dirty:()=>C.peek(),dispose(){w=!0,ue(),l.splice(0).reverse().forEach(e=>{try{e()}catch{}})}},I.scan(n),P();let h=null;try{h=S.get(g)}catch{}if(h?.form){try{S.remove?S.remove(g):S.set(g,null)}catch{}const e=h.base&&h.base!==q.peek(),t=h.at?` (${Ke(h.at)})`:"",s=e?`You left unsaved settings${t}, but the saved settings have changed since. Restore your version anyway?`:`You left unsaved settings${t}. Restore them?`;await E.confirm(s)&&i()&&(ae($e(b.peek(),h.form)),U.peek()&&(Y.value=a.adminHome.peek()))}}};
|
package/admin/js/views/theme.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import{api as
|
|
1
|
+
import{api as w}from"../api.js";import{enhanceFontSelect as Ie}from"../lib/font-picker.js";import{applyAdminTheme as ht,refreshAdminTheme as Ke}from"../lib/admin-theme.js";import{addBannerAction as ze}from"../lib/plugin-chrome.js";import{helpPopovers as Be}from"../lib/help-popover.js";import{onceClosed as ut,openMenuAt as _e,sidebarCount as pt}from"../lib/tool-kit.js";import{populateThemeSelect as He}from"../lib/themes.js";import{cloneOverride as G,dayOrNight as ft,formFromConfig as Q,knownThemeIds as vt,moveItem as Ue,overrideRow as bt,payloadFromForm as X,snapshot as pe,swatchColour as Ve,themeDiff as yt,themeLabel as kt,themeProblems as gt}from"../lib/theme-settings-arrange.js";import{fmtDateTime as xt}from"../lib/dates.js";const fe=/^\/theme(\?.*)?$/,wt="#/theme",D="theme.draft",Et=[{value:"#site-navbar",label:"Navigation bar"},{value:"#site-footer",label:"Footer"},{value:".site-content",label:"Page content area"},{value:".page-body",label:"Page body (inside the container)"},{value:".site-sidebar",label:"Sidebar"},{value:".card",label:"Every card"},{value:".cms-form-embed",label:"Embedded forms"},{value:".cms-collection",label:"Collection displays"}],St=`
|
|
2
2
|
<div class="thx-row" data-id="{{id}}" tabindex="0" data-bind-class="off && 'is-off'">
|
|
3
3
|
<span class="thx-main"><strong>{{name}}</strong><small>{{meta}}</small></span>
|
|
4
4
|
<span class="thx-chip is-danger" data-bind-hidden="!missing" title="Its theme no longer exists">Theme gone</span>
|
|
5
5
|
<span class="thx-chip is-warn" data-bind-hidden="!empty" title="No theme, token or CSS - it changes nothing">Empty</span>
|
|
6
6
|
<span class="thx-chip" data-bind-hidden="!off">Off</span>
|
|
7
7
|
<button type="button" class="thx-kebab" aria-label="Actions for {{name}}" title="Actions">\u22EE</button>
|
|
8
|
-
</div>`,ve=h=>String(h??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");function
|
|
8
|
+
</div>`,ve=h=>String(h??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");function Tt(h){const y=document.createElement("template");return y.innerHTML=h.trim(),y.content.firstElementChild}let T=null,Ye=!1;function Ct(){Ye||!window.R?.use||(Ye=!0,R.use((h,y,c)=>!(fe.test(y?.path||"")&&!fe.test(h?.path||""))||!T?.dirty()?c():E.confirm("You have unsaved theme changes. Leave anyway? They are kept as a draft for your next visit.").then(p=>{p?c():history.replaceState(null,"","#/theme")})),M.subscribe("router:afterChange",({to:h}={})=>{if(T&&!fe.test(h?.path||"")){const y=T;T=null,y.dispose()}}))}export const themeView={templateUrl:"/admin/js/templates/theme.html",async onMount(h){if(Ct(),T){const e=T;T=null,e.dispose()}const y=[],c=e=>(y.push(e),e);let Z=!1;const p=h.get(0).querySelector(".thx")||h.get(0),O=()=>!Z&&p.isConnected,be=E.loader(h.get(0),{type:"dots"});let j,L;try{[j,L]=await Promise.all([w.theme.get(),w.theme.catalog().catch(()=>({themes:[],tokens:[],custom:[]}))])}catch(e){be.destroy(),E.toast(`Could not load the theme settings: ${e.message||e}`,{type:"error"});return}if(be.destroy(),!p.isConnected)return;const ee=L.tokens||[],P=Array.isArray(L.custom)?L.custom:[],ye=vt(L),f=M.observable(j),A=Q(j),n={};for(const[e,t]of Object.entries(A))n[e]=M.observable(t);const ke=()=>Object.fromEntries(Object.keys(n).map(e=>[e,n[e].value])),te=()=>Object.fromEntries(Object.keys(n).map(e=>[e,n[e].peek()])),F=M.observable(pe(A,j)),K=M.observable(!1),z=M.observable([]),oe=M.observable("(nothing yet)"),ne=M.observable(!1),Je=M.computed(()=>pe(ke(),f.value)),B=M.computed(()=>Je.value!==F.value),ge=M.computed(()=>gt(ke(),ye)),xe=M.observable([]);c(M.effect(()=>{xe.value=n.overrides.value.map((e,t)=>bt(e,t,{custom:P,known:ye}))}));const _=e=>kt(e,P),We={...n,saving:K,rows:xe,cssText:oe,cssError:ne,dirty:B,errorsText:M.computed(()=>z.value.join(" \xB7 ")),problemsText:M.computed(()=>ge.value.length?`${ge.value.map(e=>`${e.where}: "${e.id}"`).join(", ")} - no longer available, so its base theme shows. Pick another.`:""),liveSite:M.computed(()=>{const e=f.value;if(e.autoTheme?.enabled){const t=ft(e.autoTheme)==="day"?"day":"night";return`Site: ${_(e.autoTheme.dayTheme)} by day, ${_(e.autoTheme.nightTheme)} by night (${t} now)`}return`Site: ${_(e.theme||"charcoal-dark")}`}),liveAdmin:M.computed(()=>`Admin: ${_(f.value.adminTheme||"charcoal-dark")}`),liveOverrides:M.computed(()=>{const e=f.value.overrides||[],t=e.filter(o=>o.enabled!==!1).length;return e.length?`${t} override${t===1?"":"s"} on`:""}),liveSwitcher:M.computed(()=>f.value.switcher?.enabled?"Theme switcher on":"")};function we(e){if(!P.length)return;const t=document.createElement("optgroup");t.label="Custom themes";for(const o of P){const s=document.createElement("option");s.value=o.id,s.textContent=`${o.label} (on ${o.baseTheme})`,t.appendChild(s)}e.appendChild(t)}function Ee(e,t){if(t&&![...e.options].some(o=>o.value===t)){const o=document.createElement("option");o.value=t,o.textContent=`${t} (not available)`,e.appendChild(o)}}const H=(e,t,o)=>{const s=p.querySelector(e);return He(s,o),we(s),Ee(s,t),s};H("#thx-site",A.theme),H("#thx-admin",A.adminTheme,{includeAdmin:!0}),H("#thx-day",A.dayTheme),H("#thx-night",A.nightTheme);let ae=0;async function Ge(e){const t=++ae;try{const o=await w.theme.admin(e);if(t!==ae||!O())return;ht(o)}catch{}}let Se=!0;c(M.effect(()=>{const e=n.adminTheme.value||"charcoal-dark";if(Se){Se=!1;return}Ge(e)})),c(()=>{ae++,(n.adminTheme.peek()||"charcoal-dark")!==(f.peek().adminTheme||"charcoal-dark")&&Ke(w)});let se=null,re=0;async function U(){const e=++re;try{const t=await w.theme.compile(X(te(),f.peek()));if(e!==re||!O())return;oe.value=t.css?.trim()||"(no overrides - nothing is injected)",ne.value=!1}catch(t){if(e!==re||!O())return;oe.value=t.message||String(t),ne.value=!0}}c(M.effect(()=>{n.overrides.value,clearTimeout(se),se=setTimeout(U,400)})),c(()=>clearTimeout(se));async function le(){if(!K.peek()){K.value=!0,z.value=[];try{const e=await w.theme.save(X(te(),f.peek()));if(!O())return;f.value=e;const t=Q(e);for(const[o,s]of Object.entries(t))n[o].value=s;F.value=pe(t,e);try{S.remove?S.remove(D):S.set(D,null)}catch{}await Ke(w),pt(wt),E.toast("Theme saved.",{type:"success"}),U()}catch(e){z.value=e.validation||[e.message||"Could not save the theme."],E.toast("Theme not saved - see the message at the top.",{type:"error"})}finally{K.value=!1}}}async function Qe(){if(!await E.confirm("Throw away your unsaved theme changes?"))return;const e=Q(f.peek());for(const[t,o]of Object.entries(e))n[t].value=o;z.value=[]}const Te=e=>n.overrides.peek().find(t=>t.id===e),C=e=>{n.overrides.value=e},ie=(e,t)=>C(n.overrides.peek().map(o=>o.id===e?t:o)),Xe=e=>n.overrides.peek().findIndex(t=>t.id===e),ce=new Map;async function Ce(e){if(!e)return null;if(ce.has(e))return ce.get(e);const o=(await w.theme.themeTokens(e).catch(()=>null))?.tokens||null;return ce.set(e,o),o}const Ze=()=>(n.autoEnabled.peek()?n.dayTheme.peek():n.theme.peek())||"charcoal-dark",V=new Set;function Y(e){const t=e?Te(e):G({});if(!t)return;const o=!e,s=G(t),i={label:M.observable(s.label),scope:M.observable(s.scope),enabled:M.observable(s.enabled),theme:M.observable(s.theme),css:M.observable(s.css),tokenErr:M.observable("")},d=E.slideover({title:o?"New override":`Override: ${ve(t.label||t.scope||"untitled")}`,size:"md",position:"right"}),v=Tt(`
|
|
9
9
|
<div class="thx-form">
|
|
10
10
|
<div class="thx-grid">
|
|
11
11
|
<div>
|
|
@@ -22,7 +22,7 @@ import{api as x}from"../api.js";import{applyAdminTheme as dt,refreshAdminTheme a
|
|
|
22
22
|
<label class="form-label" for="thx-o-scope">Target selector
|
|
23
23
|
<span data-help-title="Target selector" data-help="The region to re-theme - a CSS selector. Everything inside it follows. Pick a common region from the list or type your own (#site-navbar, .card, .page-body \u2026)."></span></label>
|
|
24
24
|
<input id="thx-o-scope" type="text" class="form-input font-mono" list="thx-scope-options" placeholder="#site-navbar" data-model="scope.value">
|
|
25
|
-
<datalist id="thx-scope-options">${
|
|
25
|
+
<datalist id="thx-scope-options">${Et.map(a=>`<option value="${a.value}" label="${a.label}"></option>`).join("")}</datalist>
|
|
26
26
|
</div>
|
|
27
27
|
<div>
|
|
28
28
|
<label class="form-label" for="thx-o-theme">Adopt a theme here
|
|
@@ -52,4 +52,4 @@ import{api as x}from"../api.js";import{applyAdminTheme as dt,refreshAdminTheme a
|
|
|
52
52
|
<button type="button" class="btn btn-sm btn-primary" data-on-click="done">
|
|
53
53
|
<span data-icon="check" data-icon-size="13"></span> ${o?"Add":"Done"}</button>
|
|
54
54
|
</div>
|
|
55
|
-
</div>`),de=v.querySelector("#thx-o-theme");
|
|
55
|
+
</div>`),de=v.querySelector("#thx-o-theme");He(de,{includeDefault:!0,defaultLabel:"Keep the site theme"}),we(de),Ee(de,s.theme);const nt=v.querySelector("#thx-token-names");for(const a of ee){const l=document.createElement("option");l.value=a,nt.appendChild(l)}const me=v.querySelector(".thx-toks");function De(a="",l=""){const b=document.createElement("div");b.className="thx-tok";const r=document.createElement("input");r.type="text",r.className="form-input font-mono thx-tok-name",r.placeholder="--dm-primary",r.setAttribute("list","thx-token-names"),r.value=a,r.setAttribute("aria-label","Token");const u=document.createElement("input");u.type="text",u.className="form-input thx-tok-value",u.placeholder="#0096c7",u.value=l,u.setAttribute("aria-label","Value");const k=document.createElement("input");k.type="color",k.title="Pick a colour";const g=Ve(l);/^#[0-9a-f]{6}$/i.test(g)&&(k.value=g),k.addEventListener("input",()=>{u.value=k.value});const x=document.createElement("button");return x.type="button",x.className="btn btn-sm btn-ghost",x.textContent="\xD7",x.title="Remove this token",x.addEventListener("click",()=>b.remove()),b.append(r,u,k,x),b}for(const[a,l]of Object.entries(s.tokens))me.appendChild(De(a,l));function Le(){const a={},l=[];return me.querySelectorAll(".thx-tok").forEach(b=>{const r=b.querySelector(".thx-tok-name").value.trim(),u=b.querySelector(".thx-tok-value").value.trim();!r||!u||(ee.length&&!ee.includes(r)&&l.push(r),a[r]=u)}),{tokens:a,bad:l}}const Re=()=>({...s,label:i.label.peek(),scope:i.scope.peek(),enabled:i.enabled.peek(),theme:i.theme.peek(),css:i.css.peek(),tokens:Le().tokens}),at=JSON.stringify(X({overrides:[s]}).overrides),st=()=>JSON.stringify(X({overrides:[Re()]}).overrides)!==at,he=v.querySelector(".thx-diff-host");let je=0;async function rt(){const a=++je;he.replaceChildren();const l=i.theme.peek();if(!l)return;const b=Ze(),r=document.createElement("div");if(r.className="thx-diff",r.style.marginTop=".5rem",l===b){const m=document.createElement("p");m.textContent="That is already the site theme, so this changes nothing on its own. Set a token below instead.",r.appendChild(m),he.appendChild(r);return}const[u,k]=await Promise.all([Ce(b),Ce(l)]);if(a!==je||!u||!k)return;const g=yt(u,k),x=document.createElement("p");if(x.textContent=`Changes ${g.changed} of ${g.total} tokens here.`,r.appendChild(x),g.keepsFill){const m=document.createElement("p");m.className="is-warn",m.textContent="Both themes use the same surface colour, so this region keeps the fill it has now. Set --dm-card-bg (a card) or --dm-surface (most other regions) below to change it.",r.appendChild(m)}const W=document.createElement("div");W.className="thx-diff-list";const Fe=m=>{const q=document.createElement("span");return q.className="thx-sw",q.style.background=Ve(m)||"transparent",q};for(const m of g.shown){const q=document.createElement("span");q.append(Fe(m.from),document.createTextNode(`${m.name} `),Fe(m.to)),W.appendChild(q)}if(g.more){const m=document.createElement("span");m.textContent=`+${g.more} more`,W.appendChild(m)}r.appendChild(W),he.appendChild(r)}const lt=M.effect(()=>{i.theme.value,rt()});let J=!1,ue=!1;const Pe={addToken:()=>{const a=De();me.appendChild(a),a.querySelector("input").focus()},cancel:()=>d.close(),async remove(){await E.confirm(`Remove the override "${ve(t.label||t.scope||"untitled")}"? It goes when you save.`)&&(C(n.overrides.peek().filter(a=>a.id!==t.id)),J=!0,d.close())},done(){const{bad:a}=Le();if(a.length){i.tokenErr.value=`Not a token this Domma defines: ${a.join(", ")}. Pick one from the list.`;return}const l=Re();o?C([...n.overrides.peek(),l]):ie(t.id,l),J=!0,d.close()}};d.element.appendChild(v);const it=Be(v),ct=M.applyBindings(i,v,{methods:Pe}),dt=a=>{(a.ctrlKey||a.metaKey)&&a.key==="Enter"&&(a.preventDefault(),Pe.done())};v.addEventListener("keydown",dt),V.add(d),ut(d,()=>{lt(),ct.dispose(),it(),V.delete(d)});const mt=d.close.bind(d);d.close=async a=>{if(!J&&a!==!0&&st()){if(ue)return;ue=!0;const l=await E.confirm("Discard your changes to this override?");if(ue=!1,!l)return}return J=!0,mt()},I.scan(v),d.open(),v.querySelector(o?"#thx-o-scope":"#thx-o-label")?.focus()}function et(e){const t=Te(e);if(!t)return[];const o=Xe(e),s=n.overrides.peek().length;return[{header:t.label||t.scope||`Override ${o+1}`},{label:"Edit\u2026",icon:"edit",action:()=>Y(e)},t.enabled?{label:"Switch off",icon:"pause",action:()=>ie(e,{...t,enabled:!1})}:{label:"Switch on",icon:"play",action:()=>ie(e,{...t,enabled:!0})},{label:"Duplicate",icon:"copy",action:()=>{const i=G({...t,id:"",label:t.label?`${t.label} copy`:""}),d=[...n.overrides.peek()];d.splice(o+1,0,i),C(d)}},{type:"divider"},{label:"Move up",icon:"arrow-up",disabled:o<=0,action:()=>C(Ue(n.overrides.peek(),o,-1))},{label:"Move down",icon:"arrow-down",disabled:o>=s-1,action:()=>C(Ue(n.overrides.peek(),o,1))},{type:"divider"},{label:"Remove\u2026",icon:"trash",danger:!0,action:async()=>{await E.confirm(`Remove the override "${ve(t.label||t.scope||"untitled")}"? It goes when you save.`)&&C(n.overrides.peek().filter(i=>i.id!==e))}}]}const N=p.querySelector(".thx-list");N.innerHTML=St,E.tabs(p.querySelector(".thx-tabs"),{tabSelector:".tab-item",panelSelector:".tab-panel"});const tt=M.applyBindings(We,p,{methods:{save:le,discard:Qe,refreshCss:U,addOverride:()=>Y(null)}});c(()=>tt.dispose());const Me=[Ie(p.querySelector("#thx-font"),{label:"Font family",stylesheet:()=>n.fontStylesheet.peek()}),Ie(p.querySelector("#thx-admin-font"),{label:"Admin font family",stylesheet:()=>n.fontStylesheet.peek()})];c(()=>Me.forEach(e=>e.destroy())),c(M.effect(()=>{n.fontFamily.value,n.adminFontFamily.value,n.fontStylesheet.value,queueMicrotask(()=>{O()&&Me.forEach(e=>e.refresh())})})),c(Be(p,{position:"bottom"}));const ot=E.contextMenu(N,{cursor:"glyph",match:".thx-row",inherit:!1,density:"compact",items:e=>et(e.dataset.id)});c(()=>ot?.destroy?.());const $e=e=>{const t=e.target.closest(".thx-row");if(t){if(e.target.closest(".thx-kebab")){_e(e.target.closest(".thx-kebab"));return}Y(t.dataset.id)}},Oe=e=>{const t=e.target.closest(".thx-row");t&&(e.key==="F10"&&e.shiftKey?(e.preventDefault(),_e(t)):e.key==="Enter"&&e.target===t&&Y(t.dataset.id))};N.addEventListener("click",$e),N.addEventListener("keydown",Oe),c(()=>{N.removeEventListener("click",$e),N.removeEventListener("keydown",Oe)}),ze(h,{id:"theme-view-site",icon:"external-link",title:"View site",onClick:()=>window.open("/","_blank","noopener")}),ze(h,{id:"theme-save",icon:"save",title:"Save (Ctrl+S)",onClick:()=>le()});const Ae=e=>{!(e.ctrlKey||e.metaKey)||e.key!=="s"||V.size||(e.preventDefault(),e.stopImmediatePropagation(),le())};document.addEventListener("keydown",Ae,!0),c(()=>document.removeEventListener("keydown",Ae,!0));const Ne=()=>{if(B.peek())try{S.set(D,{form:te(),base:F.peek(),at:new Date().toISOString()})}catch{}},qe=e=>{B.peek()&&(Ne(),e.preventDefault(),e.returnValue="")};window.addEventListener("beforeunload",qe),c(()=>window.removeEventListener("beforeunload",qe)),T={dirty:()=>B.peek(),dispose(){Z=!0,Ne(),[...V].forEach(e=>{try{e.close(!0)}catch{}}),y.splice(0).reverse().forEach(e=>{try{e()}catch{}})}},I.scan(p),U();let $=null;try{$=S.get(D)}catch{}if($?.form){try{S.remove?S.remove(D):S.set(D,null)}catch{}const e=$.base&&$.base!==F.peek(),t=$.at?` (${xt($.at)})`:"",o=e?`You left unsaved theme changes${t}, but the saved settings have changed since. Restore your version anyway?`:`You left unsaved theme changes${t}. Restore them?`;if(await E.confirm(o)&&O()){const s={...Q(f.peek()),...$.form};s.overrides=(s.overrides||[]).map(i=>G(i));for(const[i,d]of Object.entries(s))n[i]&&(n[i].value=d)}}}};
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
package/server/server.js
CHANGED
|
@@ -646,7 +646,7 @@ await app.register(relatedRoutes, {prefix: '/api/related'});
|
|
|
646
646
|
//
|
|
647
647
|
// `permission` is what hides each one from a role that cannot use it; the
|
|
648
648
|
// renderer filters on it.
|
|
649
|
-
const {registerSidebarItem} = await import('./services/hooks.js');
|
|
649
|
+
const {registerSidebarItem, hideSidebarUrl} = await import('./services/hooks.js');
|
|
650
650
|
// `countUrl` is the badge: the sidebar fetches it and shows {count, label, tone}
|
|
651
651
|
// (see fetchCounts in admin/js/lib/sidebar-renderer.js).
|
|
652
652
|
// A built-in Tool switched off gets no entry (its switch restarts the site) - unless it is
|
|
@@ -697,12 +697,15 @@ registerSidebarItem({folder: 'content', item: {source: 'Built in', text: 'Compon
|
|
|
697
697
|
registerSidebarItem({folder: 'system', item: {source: 'Built in', text: 'Notifications', url: '#/system/notifications', icon: 'bell', permission: 'notifications', countUrl: '/api/system/notifications/_count'}});
|
|
698
698
|
registerSidebarItem({folder: 'system', item: {source: 'Built in', text: 'Roles', url: '#/roles', icon: 'shield', permission: 'plugins', countUrl: '/api/roles/_count', inventory: true}});
|
|
699
699
|
registerSidebarItem({folder: 'system', item: {source: 'Built in', text: 'Users', url: '#/users', icon: 'users', permission: 'users', countUrl: '/api/users/_count', inventory: true}});
|
|
700
|
+
registerSidebarItem({folder: 'content', item: {source: 'Built in', text: 'Appearance', url: '#/appearance', icon: 'layout', permission: 'settings'}});
|
|
701
|
+
registerSidebarItem({folder: 'content', item: {source: 'Built in', text: 'Footer', url: '#/footer', icon: 'panel-bottom', permission: 'settings'}});
|
|
700
702
|
registerSidebarItem({folder: 'system', item: {source: 'Built in', text: 'Site Settings', url: '#/settings', icon: 'settings', permission: 'settings', countUrl: '/api/settings/_count'}});
|
|
701
703
|
registerSidebarItem({folder: 'system', item: {source: 'Built in', text: 'Effects', url: '#/effects', icon: 'sparkles', permission: 'settings', countUrl: '/api/effects/_count', inventory: true}});
|
|
702
704
|
registerSidebarItem({folder: 'system', item: {source: 'Built in', text: 'Layouts', url: '#/layouts', icon: 'layout', permission: 'layouts', countUrl: '/api/layouts/_count'}});
|
|
703
705
|
registerSidebarItem({folder: 'system', item: {source: 'Built in', text: 'Plugins', url: '#/plugins', icon: 'package', permission: 'plugins', countUrl: '/api/plugins/_count', inventory: true}});
|
|
704
706
|
registerSidebarItem({folder: 'system', item: {source: 'Built in', text: 'API Tokens', url: '#/api-tokens', icon: 'key', permission: 'api-tokens', countUrl: '/api/api-tokens/_count'}});
|
|
705
|
-
|
|
707
|
+
// Search now lives in Appearance; keep its route for existing bookmarks.
|
|
708
|
+
hideSidebarUrl('#/search');
|
|
706
709
|
registerSidebarItem({folder: 'content', item: {source: 'Built in', text: 'Content API', url: '#/content-api', icon: 'file-text', permission: 'settings', countUrl: '/api/content-api/_count', inventory: true}});
|
|
707
710
|
// Documentation pages added after the sidebar menu was seeded (0.93.1). The menu is
|
|
708
711
|
// seeded once, so new pages reach existing sites only by registering here. The two
|