domma-cms 1.16.2 → 1.18.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/admin/js/lib/admin-theme.js +1 -1
  3. package/admin/js/lib/editor-type.js +1 -1
  4. package/admin/js/lib/effects-builder.js +1 -1
  5. package/admin/js/lib/menu-editor-arrange.js +2 -2
  6. package/admin/js/lib/scribe-composer.js +1 -1
  7. package/admin/js/lib/scribe-model.js +1 -1
  8. package/admin/js/lib/shortcode-preview.js +1 -1
  9. package/admin/js/lib/shortcode-registry.js +3 -3
  10. package/admin/js/lib/theme-settings-arrange.js +1 -1
  11. package/admin/js/templates/docs/usage-navigation.html +7 -0
  12. package/admin/js/templates/menu-editor.html +9 -0
  13. package/admin/js/templates/theme.html +64 -1
  14. package/admin/js/views/menu-editor.js +10 -10
  15. package/admin/js/views/page-editor.js +9 -9
  16. package/docs/DommaFeatures.md +2 -2
  17. package/docs/screenshots/editor-font-families-mobile.png +0 -0
  18. package/docs/screenshots/theme-font-families.png +0 -0
  19. package/docs/typography.md +44 -0
  20. package/package.json +1 -1
  21. package/plugins/_lib/admin/mail/fonts.js +5 -0
  22. package/public/css/menu-cards.css +1 -1
  23. package/public/js/effects.js +1 -1
  24. package/public/js/font-families.mjs +1 -0
  25. package/public/js/menu-cards.mjs +4 -4
  26. package/public/js/menu-look.mjs +1 -1
  27. package/public/js/scribe-style.mjs +1 -1
  28. package/public/js/site.js +1 -1
  29. package/public/js/text-style.mjs +1 -1
  30. package/server/routes/api/theme.js +2 -1
  31. package/server/services/menus.js +1 -1
  32. package/server/services/renderer.js +41 -54
  33. package/server/services/themeSettings.js +7 -0
  34. package/server/templates/page.html +3 -3
@@ -109,7 +109,7 @@
109
109
  <div class="thx-grid">
110
110
  <div>
111
111
  <label class="form-label" for="thx-font">Font family
112
- <span data-help="Public site body text. The dyslexia-friendly group uses wider letterforms and spacing."></span></label>
112
+ <span data-help="Choose the public site typeface. Poppins, Montserrat and Urbanist load from Google Fonts when selected. Cera Pro and Euclid require the licensed stylesheet configured below. This does not change the admin or your editor preference. The dyslexia-friendly group uses wider letterforms and spacing."></span></label>
113
113
  <select id="thx-font" class="form-select" data-model="fontFamily.value">
114
114
  <optgroup label="Sans-serif">
115
115
  <option value="Roboto">Roboto (default)</option>
@@ -117,7 +117,10 @@
117
117
  <option value="Open Sans">Open Sans</option>
118
118
  <option value="Lato">Lato</option>
119
119
  <option value="Nunito">Nunito</option>
120
+ <option value="Nunito Sans">Nunito Sans</option>
121
+ <option value="Mulish">Mulish</option>
120
122
  <option value="Poppins">Poppins</option>
123
+ <option value="Urbanist">Urbanist</option>
121
124
  <option value="Source Sans 3">Source Sans 3</option>
122
125
  <option value="Montserrat">Montserrat</option>
123
126
  <option value="Raleway">Raleway</option>
@@ -135,11 +138,70 @@
135
138
  <option value="Atkinson Hyperlegible">Atkinson Hyperlegible</option>
136
139
  <option value="Andika">Andika</option>
137
140
  </optgroup>
141
+ <optgroup label="Licensed webfonts (stylesheet required)">
142
+ <option value="Cera Pro">Cera Pro</option>
143
+ <option value="Euclid Circular A">Euclid Circular A</option>
144
+ <option value="Euclid Circular B">Euclid Circular B</option>
145
+ <option value="Euclid Flex">Euclid Flex</option>
146
+ <option value="Euclid Square">Euclid Square</option>
147
+ <option value="Euclid Triangle">Euclid Triangle</option>
148
+ </optgroup>
149
+ <optgroup label="System">
150
+ <option value="system-ui">System UI (no web font)</option>
151
+ </optgroup>
152
+ </select>
153
+ </div>
154
+ <div>
155
+ <label class="form-label" for="thx-admin-font">Admin font family
156
+ <span data-help-title="Admin font family" data-help="The typeface used throughout the admin interface, including navigation, controls and Tools. This is separate from the public site font and the page editor lettering preference. Poppins, Montserrat and Urbanist load from Google Fonts when selected. Cera Pro and Euclid need the licensed stylesheet below. Leave Theme default selected to keep the existing admin typography."></span></label>
157
+ <select id="thx-admin-font" class="form-select" data-model="adminFontFamily.value">
158
+ <option value="">Theme default</option>
159
+ <optgroup label="Sans-serif">
160
+ <option value="Roboto">Roboto</option>
161
+ <option value="Inter">Inter</option>
162
+ <option value="Open Sans">Open Sans</option>
163
+ <option value="Lato">Lato</option>
164
+ <option value="Nunito">Nunito</option>
165
+ <option value="Nunito Sans">Nunito Sans</option>
166
+ <option value="Mulish">Mulish</option>
167
+ <option value="Poppins">Poppins</option>
168
+ <option value="Urbanist">Urbanist</option>
169
+ <option value="Source Sans 3">Source Sans 3</option>
170
+ <option value="Montserrat">Montserrat</option>
171
+ <option value="Raleway">Raleway</option>
172
+ <option value="DM Sans">DM Sans</option>
173
+ <option value="Work Sans">Work Sans</option>
174
+ </optgroup>
175
+ <optgroup label="Serif">
176
+ <option value="Merriweather">Merriweather</option>
177
+ <option value="Playfair Display">Playfair Display</option>
178
+ <option value="Lora">Lora</option>
179
+ <option value="Roboto Slab">Roboto Slab</option>
180
+ </optgroup>
181
+ <optgroup label="Dyslexia-friendly">
182
+ <option value="Lexend">Lexend</option>
183
+ <option value="Atkinson Hyperlegible">Atkinson Hyperlegible</option>
184
+ <option value="Andika">Andika</option>
185
+ </optgroup>
186
+ <optgroup label="Licensed webfonts (stylesheet required)">
187
+ <option value="Cera Pro">Cera Pro</option>
188
+ <option value="Euclid Circular A">Euclid Circular A</option>
189
+ <option value="Euclid Circular B">Euclid Circular B</option>
190
+ <option value="Euclid Flex">Euclid Flex</option>
191
+ <option value="Euclid Square">Euclid Square</option>
192
+ <option value="Euclid Triangle">Euclid Triangle</option>
193
+ </optgroup>
138
194
  <optgroup label="System">
139
195
  <option value="system-ui">System UI (no web font)</option>
140
196
  </optgroup>
141
197
  </select>
142
198
  </div>
199
+ <div class="thx-wide">
200
+ <label class="form-label" for="thx-font-stylesheet">Licensed font stylesheet
201
+ <span data-help-title="Licensed font stylesheet" data-help="The local CSS file declaring your licensed Cera Pro or Euclid webfonts with @font-face, for example /public/fonts/brand.css. Store its WOFF2 files under /public/fonts/ too, using relative URLs in the stylesheet. These site-owned files survive CMS updates and are never bundled into the public npm package. The stylesheet is shared by the public site, admin and editor. Without the actual font files, the browser uses the normal readable fallback. Google Fonts choices do not need this field."></span></label>
202
+ <input id="thx-font-stylesheet" type="text" class="form-input" placeholder="/public/fonts/brand.css" data-model="fontStylesheet.value" autocomplete="off" spellcheck="false">
203
+ <small class="thx-note">Cera Pro and Euclid require your own webfont files. Poppins, Montserrat and Urbanist are ready to use.</small>
204
+ </div>
143
205
  <div>
144
206
  <label class="form-label" for="thx-size">Font size
145
207
  <span data-help="The root font size. Every rem value on the site scales with it."></span></label>
@@ -197,6 +259,7 @@
197
259
  .thx-card-title { display: flex; align-items: center; gap: .35rem; font-weight: 600; }
198
260
  .thx-card-title .btn { display: inline-flex; align-items: center; gap: .3rem; }
199
261
  .thx-spacer { flex: 1; }
262
+ .thx-wide { grid-column: 1 / -1; }
200
263
  .thx-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem 1rem; }
201
264
  .thx-grid-3 { grid-template-columns: 2fr 1fr 1fr; }
202
265
  .thx .form-label, .thx-form .form-label { display: flex; align-items: center; gap: .3rem; }
@@ -1,10 +1,10 @@
1
- import{api as P}from"../api.js";import{colourToCss as Et,HIGHLIGHT_HOVER as ut,HIGHLIGHT_ACTIVE as pt,HIGHLIGHT_HOVER_LABELS as mt,HIGHLIGHT_ACTIVE_LABELS as ht,cssClassProblems as ft,normaliseCssClasses as At,ENTRANCE_ANIMATIONS as ot,ENTRANCE_ANIMATION_LABELS as Ct}from"/public/js/menu-decor.mjs?v=20261014-menu-entrance";import{openIconPicker as $t}from"../lib/card-builder.js";import{normalisePanel as Lt,DESCRIPTION_MAX as Tt}from"/public/js/menu-look.mjs?v=20261029-bar-shapes";import{sortableMenuRows as _t}from"../lib/menu-drag.js";import{placeTools as Ht,ensureLockedTools as It,isLockedUrl as Nt,groupKeyFor as Ot,slugify as Rt,GROUP_ICON as Bt,TOOLS_FOLDER_KEY as Pt}from"../lib/sidebar-grouping.js";import{flatten as gt,nest as Dt,uid as Xe}from"../lib/menu-rows.js";import{addBannerAction as at}from"../lib/plugin-chrome.js";import{helpPopovers as st}from"../lib/help-popover.js";import{MENU_ITEM_HELP as jt}from"../lib/menu-item-help.js";import{onceClosed as Ft,openMenuAt as lt,sidebarCount as Mt}from"../lib/tool-kit.js";import{addChild as zt,bindingFrom as Ut,duplicateRow as Wt,indentRow as Kt,insertBelow as qt,isStructural as ve,menuFromForm as Gt,menuProblems as Vt,moveRow as vt,outdentRow as Yt,siblingsOf as Xt,snapshot as Je}from"../lib/menu-editor-arrange.js";import{fmtDateTime as Jt}from"../lib/dates.js";const Qt=760,Zt="admin-sidebar",en=/^\/menus\/(new|edit\/[^?#]+)(\?.*)?$/;function x(n){return String(n||"").replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;")}const De=n=>String(n??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");function tn(n,u){let l=0,r=u.find(s=>s.id===n);for(;r&&r.parentId;)l++,r=u.find(s=>s.id===r.parentId);return l}function bt(n){const u=new Set,l=new Set,r=s=>{for(const y of n.filter(T=>T.parentId===s))!y.type&&Nt(y.url)&&!l.has(y.url)&&(l.add(y.url),u.add(y.id)),r(y.id)};return r(null),u}const Qe='<button type="button" class="btn btn-sm btn-ghost mex-kebab" aria-label="Actions" title="Actions (right-click, or Shift+F10)">\u22EE</button>';function nn(n,u,l=!1){const r=l?bt(u):new Set,s=[];function y(T){for(const p of u.filter(G=>G.parentId===T)){const $=`style="margin-left:${tn(p.id,u)*28}px"`;if(p.type==="separator"){s.push(`
2
- <div class="menu-tree-row menu-tree-row--separator" data-id="${p.id}" tabindex="0" ${$}>
1
+ import{api as P}from"../api.js";import{colourToCss as Et,HIGHLIGHT_HOVER as ut,HIGHLIGHT_ACTIVE as pt,HIGHLIGHT_HOVER_LABELS as mt,HIGHLIGHT_ACTIVE_LABELS as ht,cssClassProblems as ft,normaliseCssClasses as At,ENTRANCE_ANIMATIONS as ot,ENTRANCE_ANIMATION_LABELS as Ct}from"/public/js/menu-decor.mjs?v=20261014-menu-entrance";import{openIconPicker as Lt}from"../lib/card-builder.js";import{normalisePanel as $t,DESCRIPTION_MAX as Tt}from"/public/js/menu-look.mjs?v=20261029-bar-fit";import{sortableMenuRows as _t}from"../lib/menu-drag.js";import{placeTools as Ht,ensureLockedTools as It,isLockedUrl as Nt,groupKeyFor as Ot,slugify as Rt,GROUP_ICON as Bt,TOOLS_FOLDER_KEY as Pt}from"../lib/sidebar-grouping.js";import{flatten as gt,nest as Dt,uid as Xe}from"../lib/menu-rows.js";import{addBannerAction as at}from"../lib/plugin-chrome.js";import{helpPopovers as st}from"../lib/help-popover.js";import{MENU_ITEM_HELP as jt}from"../lib/menu-item-help.js";import{onceClosed as Mt,openMenuAt as lt,sidebarCount as Ft}from"../lib/tool-kit.js";import{addChild as zt,bindingFrom as Ut,duplicateRow as Wt,indentRow as Kt,insertBelow as qt,isStructural as ve,menuFromForm as Gt,menuProblems as Vt,moveRow as vt,outdentRow as Yt,siblingsOf as Xt,snapshot as Je}from"../lib/menu-editor-arrange.js";import{fmtDateTime as Jt}from"../lib/dates.js";const Qt=760,Zt="admin-sidebar",en=/^\/menus\/(new|edit\/[^?#]+)(\?.*)?$/;function x(n){return String(n||"").replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;")}const De=n=>String(n??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");function tn(n,u){let l=0,r=u.find(s=>s.id===n);for(;r&&r.parentId;)l++,r=u.find(s=>s.id===r.parentId);return l}function bt(n){const u=new Set,l=new Set,r=s=>{for(const y of n.filter(T=>T.parentId===s))!y.type&&Nt(y.url)&&!l.has(y.url)&&(l.add(y.url),u.add(y.id)),r(y.id)};return r(null),u}const Qe='<button type="button" class="btn btn-sm btn-ghost mex-kebab" aria-label="Actions" title="Actions (right-click, or Shift+F10)">\u22EE</button>';function nn(n,u,l=!1){const r=l?bt(u):new Set,s=[];function y(T){for(const p of u.filter(G=>G.parentId===T)){const L=`style="margin-left:${tn(p.id,u)*28}px"`;if(p.type==="separator"){s.push(`
2
+ <div class="menu-tree-row menu-tree-row--separator" data-id="${p.id}" tabindex="0" ${L}>
3
3
  <span class="menu-tree-grip" data-icon="grip-vertical" data-icon-size="18" title="Drag to move"></span>
4
4
  <span class="me-sep-line"><span class="me-sep-label">Separator</span></span>
5
5
  ${Qe}
6
6
  </div>`);continue}if(p.type==="spacer"){const be=["xs","sm","md","lg","xl","flex"].map(ae=>`<option value="${ae}"${(p.size||"md")===ae?" selected":""}>${ae==="flex"?"flexible":ae}</option>`).join("");s.push(`
7
- <div class="menu-tree-row menu-tree-row--spacer" data-id="${p.id}" tabindex="0" ${$}>
7
+ <div class="menu-tree-row menu-tree-row--spacer" data-id="${p.id}" tabindex="0" ${L}>
8
8
  <span class="menu-tree-grip" data-icon="grip-vertical" data-icon-size="18" title="Drag to move"></span>
9
9
  <span class="me-spacer-line">
10
10
  <span class="me-spacer-label">Spacer</span>
@@ -13,21 +13,21 @@ import{api as P}from"../api.js";import{colourToCss as Et,HIGHLIGHT_HOVER as ut,H
13
13
  </span>
14
14
  ${Qe}
15
15
  </div>`);continue}if(p.type==="theme-switcher"){s.push(`
16
- <div class="menu-tree-row menu-tree-row--switcher" data-id="${p.id}" tabindex="0" ${$}>
16
+ <div class="menu-tree-row menu-tree-row--switcher" data-id="${p.id}" tabindex="0" ${L}>
17
17
  <span class="menu-tree-grip" data-icon="grip-vertical" data-icon-size="18" title="Drag to move"></span>
18
18
  <span class="me-sep-line"><span class="me-sep-label"><span data-icon="palette"></span> Theme switcher - the themes chosen under Theme &gt; Theme switcher</span></span>
19
19
  ${Qe}
20
20
  </div>`);continue}const V=p.badge&&(p.badge.text||p.badge.countFrom)?`<span class="dm-menu-badge">${x(String(p.badge.text||"#"))}</span>`:"",_=p.tool,f=_&&(_.persisted||p.touched),re=_?_.orphan?' <span class="badge badge-secondary me-tool-badge" title="A placeholder for a Tool that is not enabled - it returns here when it is">Not enabled</span>':` <span class="badge badge-secondary me-tool-badge" title="${f?"A Tool, placed here by this menu":"A Tool in its default place - move or edit it to place it here"}">${x(_.source||"Tool")}${f?"":" \xB7 default"}</span>`:"",ne=r.has(p.id),ce=Et(p.colour),oe=ce?` style="color:${x(ce)}"`:"",de=ne?'<button type="button" class="btn btn-sm btn-ghost" disabled title="Always shown - it can be moved, not hidden" aria-label="Always shown"><span data-icon="lock"></span></button>':`<button type="button" class="btn btn-sm btn-ghost me-hidden ${p.hidden?"active":""}" title="${p.hidden?"Hidden - click to show":"Hide"}" aria-label="${p.hidden?"Show":"Hide"}" aria-pressed="${p.hidden?"true":"false"}"><span data-icon="${p.hidden?"eye-off":"eye"}"></span></button>`;s.push(`
21
- <div class="menu-tree-row menu-tree-row--slim${p.hidden?" menu-tree-row--hidden":""}${_?" menu-tree-row--tool":""}${_&&!f?" menu-tree-row--default":""}" data-id="${p.id}" tabindex="0" ${$}>
21
+ <div class="menu-tree-row menu-tree-row--slim${p.hidden?" menu-tree-row--hidden":""}${_?" menu-tree-row--tool":""}${_&&!f?" menu-tree-row--default":""}" data-id="${p.id}" tabindex="0" ${L}>
22
22
  <span class="menu-tree-grip" data-icon="grip-vertical" data-icon-size="18" title="Drag to move"></span>
23
23
  <span class="me-row-label${!p.text&&!_?" mex-untitled":""}"${oe}>${x(p.text||_?.label||"(no label - click to add one)")}${V}${re}</span>
24
24
  <span class="me-row-url">${x(p.url||"")}</span>
25
25
  ${de}
26
26
  <button type="button" class="btn btn-sm btn-ghost me-edit" title="Edit" aria-label="Edit"><span data-icon="edit"></span></button>
27
27
  ${Qe}
28
- </div>`),y(p.id)}}y(null),n._disposeMenuHelp?.(),n.innerHTML=s.join("")||'<p class="mex-note">No items yet - Add item, or right-click an item for more.</p>',n._disposeMenuHelp=st(n),I.scan(n)}function b(n,u={},...l){const r=document.createElement(n);Object.assign(r,u);for(const s of l)s!=null&&r.append(s);return r}function w(n,u,l){const r=b("label",{className:"form-field"},b("span",{className:"form-label",textContent:n}),u),s=jt[n];if(s){const y=b("span");y.dataset.help=s+(l?" "+l:""),y.dataset.helpTitle=n,r.querySelector(".form-label").append(" ",y)}return l&&r.append(b("small",{className:"form-hint",textContent:l,style:"display:block;font-size:.78em;opacity:.7;margin-top:.25rem;line-height:1.35"})),r}function on(n,u){const l=[["","- Everyone -"],["public","Public - anyone, incl. logged-out"],...(u||[]).map(s=>[s.name,`${s.label||s.name} and above`]),...(u||[]).filter(s=>s.level!==0).map(s=>[`=${s.name}`,`${s.label||s.name} only`]),["private","Private - super-admin only"]];n&&!l.some(([s])=>s===n)&&l.push([n,`${n} (custom)`]);const r=K(l,n||"");return r.name="visibility",r}function K(n,u){const l=b("select",{className:"form-select"});return n.forEach(([r,s])=>l.add(new Option(s,r))),l.value=u??"",l}function je(n,u){const l=typeof u=="string"&&u.startsWith("#"),r=K([["","- none -"],["primary","primary"],["success","success"],["danger","danger"],["warning","warning"],["info","info"],["neutral","neutral"],["__custom__","Custom\u2026"]],l?"__custom__":u||""),s=b("input",{type:"color",className:"form-input me-colour-hex",value:l?u:"#000000"});s.style.display=l?"":"none",r.addEventListener("change",()=>{s.style.display=r.value==="__custom__"?"":"none"});const y=w(n,r);return y.append(s),y._read=()=>r.value==="__custom__"?s.value:r.value,y}function an(n,u){const l=b("input",{className:"form-input me-icon",name:"icon",value:u||""}),r=b("span",{className:"me-icon-preview"});u&&r.setAttribute("data-icon",u);const s=b("button",{type:"button",className:"btn btn-sm btn-ghost",textContent:"Browse\u2026"}),y=T=>{T?r.setAttribute("data-icon",T):r.removeAttribute("data-icon"),Domma.icons.scan(r.parentNode||r)};return s.addEventListener("click",()=>$t(T=>{l.value=T,y(T)})),l.addEventListener("input",()=>y(l.value.trim())),w(n,b("div",{className:"me-icon-field"},l,s,r))}function te(...n){return b("div",{className:"me-field-grid"},...n)}async function sn(n,u,l,r,s,{cards:y=!0}={}){const T=n.text||n.tool?.label||"",p=m=>b("h4",{className:"me-form-section",textContent:m}),G=w("Label",b("input",{className:"form-input",name:"text",value:n.text||""}),"The text shown for this item."),$=b("input",{className:"form-input",name:"url",value:n.url||""}),V=w("URL",$,n.tool||n.locked?"A Tool's address is its identity, so it cannot be changed here.":"Where it links. Must start with /, #, https://, or mailto: . Leave blank for a parent that only groups sub-items.");(n.tool||n.locked)&&($.readOnly=!0);const _=an("Icon",n.icon||""),f=on(n.visibility||"",r),re=w("Visibility",f,n.locked?"Always in the sidebar for everyone who may use it, so it cannot be restricted here.":'Who can see this item. "Role and above" shows it to that role and anyone more senior; "Role only" shows it to holders of that role alone (and the super-admin). Blank = everyone.');n.locked&&(f.disabled=!0);const ne=K([["","- no permission gate -"],...(u||[]).map(m=>[m.key,m.label||m.key])],n.permission||"");ne.name="permission";const ce=w("Permission",ne,n.tool||n.locked?"A Tool is guarded by its own permission, which always applies.":"Hide unless the viewer holds this specific permission. Independent of Visibility - both must pass.");(n.tool||n.locked)&&(ne.disabled=!0);const oe=w("Badge text",b("input",{className:"form-input",name:"badgeText",value:n.badge?.text||""})),de=K([["","- none -"],...(l||[]).map(m=>[m.slug,m.title||m.slug])],n.badge?.countFrom||"");de.name="badgeCount";const be=w("Badge count from",de,"Show a live count of this collection\u2019s entries as the badge."),ae=je("Badge colour",n.badge?.variant||""),ye=K([["link","Link"],["pill","Pill"]],n.pill?"pill":"link");ye.name="renderAs";const D=w("Render as",ye,"Pill draws the item as a rounded chip. Pill styling applies to top-level navbar items."),$e=w("Pill style",K([["filled","Filled"],["outline","Outline"]],n.pill?.style||"filled"));$e.querySelector("select").name="pillStyle";const Le=je("Pill colour",n.pill?.variant||""),h=b("div",{className:"me-pill-wrap"},te($e,Le));h.style.display=n.pill?"":"none",ye.addEventListener("change",()=>{h.style.display=ye.value==="pill"?"":"none"});const j=je("Text colour",n.colour||""),ue=K([["","- use the menu default -"],...ut.map(m=>[m,mt[m]||m])],n.highlight?.hover||"");ue.name="hlHover";const Fe=w("Hover effect",ue,"Overrides the menu-wide hover effect for this item only."),Te=K([["","- use the menu default -"],...pt.map(m=>[m,ht[m]||m])],n.highlight?.active||"");Te.name="hlActive";const U=w("When selected",Te,"How this item is marked when it points at the page being viewed."),L=je("Highlight colour",n.highlight?.accent||""),ke=b("input",{className:"form-input",name:"class",value:n.class||"",placeholder:"nav-cta push-right",autocomplete:"off",spellcheck:!1}),N=w("CSS classes",ke,"Your own class names, separated by spaces, added to this item's <li> - target the link with .your-class > a. Style them in Custom CSS."),Y=b("small",{className:"text-danger",style:"display:none;margin-top:.25rem"});N.append(Y);const pe=b("textarea",{className:"form-input",name:"description",rows:2,maxLength:Tt,value:n.description||"",placeholder:"Answers every new lead in under a minute."}),me=w("Description",pe,"One short line under the label, shown when the menu's dropdowns are Cards."),_e=je("Tile colour",n.tile||""),He=b("input",{type:"checkbox",name:"chip",checked:!!n.chip,style:"width:auto;margin:0"}),Ie=b("label",{className:"form-field",style:"display:flex;gap:.5rem;align-items:center;font-weight:400"},He,b("span",{textContent:"Show as a small chip in the card's footer strip"})),we=b("span");we.dataset.helpTitle="Show as a small chip",we.dataset.help="Place this sub-item in the compact chip strip at the bottom of its parent Cards dropdown instead of the main entries. Its label and destination remain the same. The parent card can provide a Chip strip label. This applies to sub-items in Cards dropdowns, rather than top-level navbar links.",Ie.append(we);const F=n.parentId==null,C=n.panel||{},O=(m,X,J,A=80)=>b("input",{className:"form-input",name:m,value:X||"",placeholder:J,maxLength:A}),Me=w("Card heading",O("panelHeading",C.heading,"The crew - six agents, one job each"),"Small capitals over the entries."),ze=w("Link text",O("panelLinkText",C.link?.text,"Meet the crew",60)),Ue=w("Link URL",O("panelLinkUrl",C.link?.url,"/crew",500)),Ne=K([["","Automatic"],["1","1"],["2","2"],["3","3"],["4","4"]],C.columns?String(C.columns):"");Ne.name="panelColumns";const Ze=w("Columns",Ne),et=w("Chip strip label",O("panelChipsLabel",C.chipsLabel,"Add to your crew",60),'Words before the chips - tick "Show as a small chip" on the sub-items that belong there.'),he=K([["","- no side box -"],["dark","Dark"],["light","Light"],["accent","Theme colour"]],C.feature?C.feature.tone||"dark":"");he.name="featureTone";const We=w("Side box",he,"A box down the right of the card - a call to action or a short list."),Ke=w("Box small heading",O("featureEyebrow",C.feature?.eyebrow,"Free - 20 minutes",60)),qe=w("Box title",O("featureTitle",C.feature?.title,"See it live")),t=w("Box points",b("textarea",{className:"form-input",name:"featurePoints",rows:3,value:(C.feature?.points||[]).join(`
29
- `),placeholder:"One per line, up to six"})),Se=w("Button text",O("featureBtnText",C.feature?.button?.text,"Book a demo",60)),Oe=w("Button URL",O("featureBtnUrl",C.feature?.button?.url,"/book",500)),fe=b("div",{},te(Ke,qe),t,te(Se,Oe));fe.style.display=he.value?"":"none",he.addEventListener("change",()=>{fe.style.display=he.value?"":"none"});const tt=y?[p("Card dropdown"),b("small",{className:"form-hint",style:"display:block;opacity:.7;margin-bottom:.4rem",textContent:"Used when the menu's Dropdown style is Cards (Behaviour tab)."}),me,te(_e,F?null:Ie),...F?[Me,te(ze,Ue),te(Ze,et),We,fe]:[]]:[],se=b("button",{className:"btn btn-primary",textContent:"Apply",title:"Apply to the item (Ctrl+Enter) - Save the menu to keep it"}),W=b("div",{className:"me-item-form"},p("Link"),G,V,_,p("Access"),te(re,ce),p("Badge"),te(oe,ae),be,p("Appearance"),D,h,j,p("Highlighting"),te(Fe,U),L,...tt,p("Styling"),N,se),B=E.slideover({title:T?`Edit ${De(T)}`:"Edit menu item",size:"lg",position:"right"});B.element.appendChild(W);const Ge=()=>JSON.stringify([...W.querySelectorAll("input, select, textarea")].map(m=>m.type==="checkbox"?m.checked:m.value)),Ve=Ge();let xe=!1,ge=!1;const Re=st(W,{position:"bottom"});Ft(B,Re);const Ee=B.close.bind(B);B.close=async m=>{if(!xe&&m!==!0&&Ge()!==Ve){if(ge)return;ge=!0;const X=await E.confirm("Discard the changes to this item?");if(ge=!1,!X)return}return xe=!0,Ee()},W.addEventListener("keydown",m=>{(m.ctrlKey||m.metaKey)&&m.key==="Enter"&&(m.preventDefault(),se.click())}),B.open();const Be=B.element.closest(".dm-slideover")||B.element.querySelector(".dm-slideover")||B.element;Be.style.setProperty("width",Qt+"px","important"),Be.style.setProperty("max-width","95vw","important"),Domma.icons.scan(W);const g=m=>W.querySelector(`[name="${m}"]`)?.value||"";se.addEventListener("click",()=>{const m=ft(g("class"));if(m.length){Y.textContent=m.join("; "),Y.style.display="block",ke.focus();return}n.class=At(g("class")),n.text=g("text"),n.icon=g("icon"),n.locked||(n.visibility=g("visibility")),!n.tool&&!n.locked?(n.url=g("url"),n.permission=g("permission")):n.touched=!0;const X=g("badgeText"),J=g("badgeCount"),A=ae._read();if(n.badge=X||J?{...X&&{text:X},...J&&{countFrom:J},...A&&{variant:A}}:null,g("renderAs")==="pill"){const Q=Le._read();n.pill={style:g("pillStyle")||"filled",...Q&&{variant:Q}}}else n.pill=null;n.colour=j._read();const le=g("hlHover"),Ae=g("hlActive"),Ce=L._read();if(n.highlight=le||Ae||Ce?{...le&&{hover:le},...Ae&&{active:Ae},...Ce&&{accent:Ce}}:null,y&&(n.description=g("description").trim(),n.tile=_e._read(),n.chip=!F&&He.checked,F)){const Q=g("featureTone");n.panel=Lt({heading:g("panelHeading"),link:{text:g("panelLinkText"),url:g("panelLinkUrl")},columns:g("panelColumns"),chipsLabel:g("panelChipsLabel"),feature:Q?{tone:Q,eyebrow:g("featureEyebrow"),title:g("featureTitle"),points:g("featurePoints").split(`
30
- `),button:{text:g("featureBtnText"),url:g("featureBtnUrl")}}:null})}xe=!0,B.close(!0),s()})}let q=null,yt=!1;function ln(){yt||!window.R?.use||(yt=!0,R.use((n,u,l)=>{const r=u?.path||"";return!(en.test(r)&&(n?.path||"")!==r)||!q?.dirty()?l():E.confirm(`You have unsaved changes to the menu "${De(q.name())}". Leave anyway? They are kept as a draft for your next visit.`).then(y=>{y?l():history.replaceState(null,"",`#${r}`)})}),M.subscribe("router:afterChange",({to:n}={})=>{if(q&&(n?.path||"")!==q.path){const u=q;q=null,u.dispose()}}))}function kt(n,u){const l=n.querySelector(".dm-plugin-banner-name"),r=l?.querySelector(".dm-plugin-banner-sep");if(!(!l||!r)){for(;r.nextSibling;)r.nextSibling.remove();l.appendChild(document.createTextNode(u))}}export const menuEditorView={templateUrl:"/admin/js/templates/menu-editor.html",async onMount(n){if(ln(),q){const e=q;q=null,e.dispose()}const u=[],l=e=>(u.push(e),e);let r=!1;const s=n.get(0).querySelector(".mex")||n.get(0),y=()=>!r&&s.isConnected,T=location.hash.replace(/^#/,""),p=location.hash.match(/^#\/menus\/edit\/([^?#]+)/),G=p?decodeURIComponent(p[1]):null,$=!G,V=`menu-editor.draft.${G||"new"}`,_=E.loader(n.get(0),{type:"dots"});let f,re,ne,ce,oe,de,be;try{if($)f={slug:"",name:"",description:"",items:[]};else try{f=await P.menus.get(G)}catch(e){E.toast(`Failed to load menu: ${e.message||e}`,{type:"error"}),location.hash="#/menus";return}[re,ne,ce,oe,de,be]=await Promise.all([P.projects.list().catch(()=>[]),H.get("/api/auth/permissions-registry").catch(()=>({resources:[]})),P.collections.list().catch(()=>[]),P.get("/collections/roles/entries?limit=100").catch(()=>null),P.menuLocations.registry().catch(()=>[]),P.pages.list().catch(()=>[])])}finally{_.destroy()}if(!s.isConnected)return;const ye=(Array.isArray(oe)?oe:oe?.entries||[]).map(e=>({name:e.data?.name,label:e.data?.label,level:e.data?.level??99})).filter(e=>e.name).sort((e,o)=>o.level-e.level),D=!$&&G===Zt;let $e=[];if(D&&($e=await H.get("/api/sidebar/registered-items").catch(()=>(E.toast("Could not load the Tools - they are not shown, and saving keeps their places as they are.",{type:"warning",duration:8e3}),[])),!s.isConnected))return;const Le=e=>gt(D?It(Ht(e||[],$e,{forEditor:!0}),{leaveInHiddenFolders:!0}):e);let h=Le(f.items);const j=M.observable(!1),ue=M.observable(!1),Fe=M.observable(""),Te=M.observable(0);let U="";const L=s.querySelector("#me-items-list");l(()=>L._disposeMenuHelp?.());function ke(){nn(L,h,D),Te.value=h.filter(e=>!ve(e)).length}const N=()=>{ke(),Z()},Y=()=>D?bt(h):new Set,pe=e=>h.find(o=>o.id===e);function me(e){requestAnimationFrame(()=>L.querySelector(`.menu-tree-row[data-id="${CSS.escape(e)}"]`)?.focus())}function _e(e){const o=v=>h.find(i=>!i.type&&!i.url&&!i.tool&&(i.key||"").toLowerCase()===v)||h.find(i=>!i.type&&!i.url&&!i.tool&&!i.key&&(i.text||"").toLowerCase()===v);let a=o(String(e.tool.folder||"").toLowerCase())||o(Pt);const c=String(e.tool.group||"").trim();if(a&&c){const v=Ot(a.key||Rt(a.text),c),i=d=>d!==e&&!d.type&&!d.url&&!d.tool;let k=h.find(d=>i(d)&&(d.key||"").toLowerCase()===v)||h.find(d=>i(d)&&d.parentId===a.id&&(!d.key||d.key.toLowerCase()===v)&&(d.text||"").toLowerCase()===c.toLowerCase());k||([k]=gt([{text:c,key:v,icon:Bt,synthesised:!0}],a.id),h.push(k)),a=k}e.parentId=a?a.id:null,h.splice(h.indexOf(e),1),h.push(e),Object.assign(e,{text:e.tool.defaults.text,icon:e.tool.defaults.icon,visibility:"",hidden:!1,badge:null,pill:null,colour:"",highlight:null,touched:!1}),e.tool={...e.tool,persisted:!1}}const He=e=>!Y().has(e.id)&&!(e.tool&&!e.tool.orphan);async function Ie(e){const o=pe(e);if(!o||!He(o))return;const a=d=>{let ee=d;for(;ee;){if(ee.id===e)return!0;ee=h.find(z=>z.id===ee.parentId)}return!1},c=h.filter(d=>d.id!==e&&a(d));if(c.length&&!await E.confirm(`Remove "${De(o.text||o.type||"this item")}" and the ${c.length} item${c.length===1?"":"s"} beneath it?`))return;const v=Y(),i=c.filter(d=>d.tool),k=c.filter(d=>!d.tool&&v.has(d.id));h=h.filter(d=>!a(d)||i.includes(d)||k.includes(d));for(const d of k)d.parentId=o.parentId??null;for(const d of i)d.tool.orphan?d.parentId=o.parentId??null:_e(d);N()}function we(e){const o=pe(e);!o||ve(o)||Y().has(e)||(o.hidden=!o.hidden,o.touched=!0,N())}function F(e){const o=pe(e);!o||ve(o)||(o.locked=D&&Y().has(o.id),sn(o,ne.resources||[],ce,ye,()=>{N(),me(e)},{cards:!D}))}function C(e){const o={id:Xe(),parentId:null,...e==="separator"||e==="theme-switcher"?{type:e}:e==="spacer"?{type:e,size:"md"}:{text:"",url:"/",icon:"",visibility:"",permission:"",hidden:!1,bundled:!1}};h.push(o),N(),ve(o)?me(o.id):F(o.id)}const O=e=>o=>{e(o)&&(N(),me(o))},Me=O(e=>vt(h,e,-1)),ze=O(e=>vt(h,e,1)),Ue=O(e=>Kt(h,e)),Ne=O(e=>Yt(h,e));function Ze(e){const o=pe(e);if(!o)return[];const a=ve(o),c=Y().has(e),v=Xt(h,e),i=v.findIndex(z=>z.id===e),k=o.tool,d=k&&(k.persisted||o.touched),ee=z=>()=>{const Pe=qt(h,e,z,Xe());N(),Pe&&!ve(Pe)?F(Pe.id):Pe&&me(Pe.id)};return[{header:a?{separator:"Separator",spacer:"Spacer","theme-switcher":"Theme switcher"}[o.type]:o.text||k?.label||"(untitled)"},...a?[]:[{label:"Edit\u2026",icon:"edit",action:()=>F(e)}],{type:"divider"},{label:"Add item below",icon:"plus",action:ee("item")},{label:"Add sub-item",icon:"corner-down-right",disabled:a,action:()=>{const z=zt(h,e,Xe());N(),z&&F(z.id)}},{label:"Add separator below",icon:"minus",action:ee("separator")},{label:"Add spacer below",icon:"move",action:ee("spacer")},...D?[]:[{label:"Add theme switcher below",icon:"palette",action:ee("theme-switcher")}],{type:"divider"},{label:"Move up",icon:"arrow-up",shortcut:"Alt+\u2191",disabled:i<=0,action:()=>Me(e)},{label:"Move down",icon:"arrow-down",shortcut:"Alt+\u2193",disabled:i<0||i>=v.length-1,action:()=>ze(e)},{label:"Indent",icon:"chevron-right",shortcut:"Alt+\u2192",disabled:i<=0||ve(v[i-1]),action:()=>Ue(e)},{label:"Outdent",icon:"chevron-left",shortcut:"Alt+\u2190",disabled:o.parentId==null,action:()=>Ne(e)},{type:"divider"},...a?[]:[{label:o.hidden?"Show":"Hide",icon:o.hidden?"eye":"eye-off",disabled:c,action:()=>we(e)}],{label:"Duplicate",icon:"copy",disabled:!!k,action:()=>{const z=Wt(h,e,Xe);N(),z&&me(z.id)}},...k&&!k.orphan&&d?[{label:"Back to its default place",icon:"rotate-ccw",action:()=>{_e(o),N()}}]:[],{label:c?"Remove - always in the sidebar":k&&!k.orphan?"Remove - a Tool is hidden, not removed":"Remove\u2026",icon:"trash",danger:!0,disabled:!He(o),action:()=>Ie(e)}]}const et=E.contextMenu(L,{cursor:"glyph",match:".menu-tree-row",inherit:!1,density:"compact",items:e=>Ze(e.dataset.id)});l(()=>et?.destroy?.());const he=_t(L,()=>h,N,{items:".menu-tree-row",handle:".menu-tree-grip"});l(()=>he?.destroy());const We=e=>{const o=e.target.closest(".menu-tree-row");if(!o)return;const a=o.dataset.id;if(e.target.closest(".mex-kebab")){lt(e.target.closest(".mex-kebab"));return}if(e.target.closest(".me-hidden")){we(a);return}if(e.target.closest(".me-edit")){F(a);return}e.target.closest("select, .menu-tree-grip, button")||F(a)},Ke=e=>{const o=e.target.closest(".menu-tree-row");if(!o||e.target!==o){o&&e.key==="F10"&&e.shiftKey&&(e.preventDefault(),lt(o));return}const a=o.dataset.id;if(e.key==="F10"&&e.shiftKey)e.preventDefault(),lt(o);else if(e.key==="Enter")e.preventDefault(),F(a);else if(e.key==="Delete")e.preventDefault(),Ie(a);else if(e.altKey&&e.key==="ArrowUp")e.preventDefault(),Me(a);else if(e.altKey&&e.key==="ArrowDown")e.preventDefault(),ze(a);else if(e.altKey&&e.key==="ArrowRight")e.preventDefault(),Ue(a);else if(e.altKey&&e.key==="ArrowLeft")e.preventDefault(),Ne(a);else if(e.key==="ArrowDown"||e.key==="ArrowUp"){const c=[...L.querySelectorAll(".menu-tree-row")],v=c.indexOf(o)+(e.key==="ArrowDown"?1:-1);c[v]&&(e.preventDefault(),c[v].focus())}},qe=e=>{if(!e.target.matches(".me-spacer-size"))return;const o=pe(e.target.closest(".menu-tree-row")?.dataset.id);o&&(o.size=e.target.value,Z())};L.addEventListener("click",We),L.addEventListener("keydown",Ke),L.addEventListener("change",qe),l(()=>{L.removeEventListener("click",We),L.removeEventListener("keydown",Ke),L.removeEventListener("change",qe)});const t=e=>n.find(e),Se=t("#me-float-accent"),Oe=t("#me-float-accent-hex"),fe=()=>{Oe.get(0).style.display=Se.val()==="__custom__"?"":"none"},tt=()=>Se.val()==="__custom__"?Oe.val():Se.val(),se=t("#me-highlight-accent"),W=t("#me-highlight-accent-hex"),B=()=>{W.get(0).style.display=se.val()==="__custom__"?"":"none"},Ge=()=>se.val()==="__custom__"?W.val():se.val(),Ve=()=>{const e=!!(t("#me-entrance-enabled").get(0)||{}).checked;t(".dm-entrance-field").each(function(){this.style.display=e?"":"none"});const o=t("#me-position").val()==="floating";t(".dm-float-field").each(function(){this.style.display=o?"":"none"}),o&&fe();const a=t("#me-orientation").val()==="vertical";t(".dm-vertical-field").each(function(){this.style.display=a?"":"none"}),t(".dm-dock-rail-field").each(function(){this.style.display=a&&!o?"":"none"}),t(".dm-dock-bar-field").each(function(){this.style.display=!a&&!o?"":"none"});const c=!!(t("#me-dock-collapsible").get(0)||{}).checked,v=!!(t("#me-dock-autohide").get(0)||{}).checked;t(".dm-dock-collapsed-field").each(function(){this.style.display=c&&!v?"":"none"});const i=!!(t("#me-float-collapsible").get(0)||{}).checked;t(".dm-float-collapsed-field").each(function(){this.style.display=o&&i?"":"none"});const k=!a&&!D;t(".dm-look-field").each(function(){this.style.display=k?"":"none"});const d=k&&t("#me-look-dropdown").val()==="cards";t(".dm-look-cards-field").each(function(){this.style.display=d?"":"none"})},xe=(e,o,a,c)=>{const v=t(e).get(0);v&&(v.innerHTML="",v.add(new Option(c,"")),o.forEach(i=>v.add(new Option(a[i]||i,i))))};xe("#me-highlight-hover",ut,mt,"- theme default -"),xe("#me-highlight-active",pt,ht,"- theme default -");{const e=t("#me-entrance-animation").get(0);e&&(e.innerHTML="",ot.forEach(o=>e.add(new Option(Ct[o]||o,o))))}const ge=t("#me-bind-slot"),Re=t("#me-bind-projects"),Ee=t("#me-bind-pages");ge.html('<option value="">- not bound -</option>'+(de||[]).map(e=>`<option value="${x(e.slot)}">${x(e.label||e.slot)} (${x(e.slot)})</option>`).join("")),Re.html(re.map(e=>`<option value="${x(e.slug)}">${x(e.name||e.slug)}</option>`).join("")),t("#me-bind-page-pick").html('<option value="">- pick a page -</option>'+be.map(e=>{const o=e.urlPath||e.url||"";return o?`<option value="${x(o)}">${x(e.title||o)} - ${x(o)}</option>`:""}).join(""));const Be=()=>Ut({slot:ge.val(),projects:Array.from(Re.get(0).selectedOptions).map(e=>e.value),pagesText:Ee.val()});function g(){const e=Be(),o=t("#me-bind-summary");if(!e){o.html('<span class="text-muted">Not bound - this menu renders only where it is mapped or placed by a shortcode.</span>');return}const a=[];e.projects.length&&a.push(`pages in ${e.projects.map(i=>`<code>${x(i)}</code>`).join(", ")}`),e.pages.length&&a.push(`pages matching ${e.pages.map(i=>`<code>${x(i)}</code>`).join(", ")}`);const c=e.pages.filter(i=>!/^\/[^\s?#*]*(\/\*)?$|^\/\*$/.test(i)),v=c.length?`<div class="text-danger" style="margin-top:.4rem">Not valid page patterns: ${c.map(i=>`<code>${x(i)}</code>`).join(", ")}</div>`:"";o.html(a.length?`Takes over the <code>${x(e.slot)}</code> slot on ${a.join(" and ")}.${v}`:`<span class="text-warning">Slot <code>${x(e.slot)}</code> selected but no project or page chosen - the binding will never match.</span>`)}const{getProjectFromHash:m}=await import("../lib/project-context.js");if(!y())return;const X=$?m():null;t("#me-project").html('<option value="">- none -</option>'+re.map(e=>`<option value="${x(e.slug)}">${x(e.name||e.slug)}</option>`).join(""));function J(e){h=Le(e.items),t("#me-variant").val(e.variant||""),t("#me-position").val(e.position||"");const o=t("#me-appearOnHover").get(0);o&&(o.checked=e.appearOnHover===!0),t("#me-float-anchor").val(e.float?.anchor||"TL"),t("#me-float-offsetX").val(e.float?.offsetX??""),t("#me-float-offsetY").val(e.float?.offsetY??""),t("#me-float-width").val(e.float?.width??""),t("#me-float-radius").val(e.float?.radius??""),t("#me-float-shadow").val(e.float?.shadow||""),t("#me-float-opacity").val(e.float?.opacity??""),t("#me-float-title").val(e.float?.title||"");for(const[i,k]of[["#me-float-collapsible",e.float?.collapsible],["#me-float-collapsed",e.float?.collapsed],["#me-float-movable",e.float?.movable],["#me-float-resizable",e.float?.resizable]]){const d=t(i).get(0);d&&(d.checked=k===!0)}const a=e.float?.accent||"";Se.val(a.startsWith("#")?"__custom__":a),a.startsWith("#")&&Oe.val(a),fe(),t("#me-orientation").val(e.orientation||""),t("#me-align").val(e.align||""),t("#me-mobile-hamburger").get(0).checked=e.mobile?.hamburgerOnly===!0,t("#me-mobile-brand").get(0).checked=e.mobile?.hideBrand===!0,t("#me-look-bar").val(e.look?.bar||""),t("#me-look-brand").val(e.look?.brand||""),t("#me-look-strip").val(e.look?.strip||""),t("#me-look-dropdown").val(e.look?.dropdown||""),t("#me-look-tiles").val(e.look?.tiles||""),t("#me-look-morph").get(0).checked=e.look?.morph===!0,t("#me-look-shrink").get(0).checked=e.look?.shrink===!0,t("#me-side").val(e.side||"left"),t("#me-dock-width").val(e.dock?.width??"");for(const i of["collapsible","collapsed","autohide","hideOnScroll"]){const k=t(`#me-dock-${i}`).get(0);k&&(k.checked=e.dock?.[i]===!0)}t("#me-class").val(e.class||""),t("#me-highlight-hover").val(e.highlight?.hover||""),t("#me-highlight-active").val(e.highlight?.active||"");const c=e.highlight?.accent||"";se.val(c.startsWith("#")?"__custom__":c),c.startsWith("#")&&W.val(c),B();{const i=t("#me-entrance-enabled").get(0);i&&(i.checked=e.entrance?.enabled===!0)}t("#me-entrance-animation").val(ot.includes(e.entrance?.animation)?e.entrance.animation:ot[0]),t("#me-entrance-stagger").val(e.entrance?.stagger??""),t("#me-entrance-duration").val(e.entrance?.duration??""),t("#me-fontFamily").val(e.style?.fontFamily||""),t("#me-fontSize").val(e.style?.fontSize||""),t("#me-fontWeight").val(e.style?.fontWeight||""),t("#me-letterSpacing").val(e.style?.letterSpacing||""),t("#me-iconSize").val(e.style?.iconSize||""),ge.val(e.binding?.slot||"");const v=new Set(e.binding?.projects||[]);Array.from(Re.get(0).options).forEach(i=>{i.selected=v.has(i.value)}),Ee.val((e.binding?.pages||[]).join(`
31
- `)),t("#me-slug").val(e.slug||""),t("#me-name").val(e.name||""),t("#me-description").val(e.description||""),t("#me-project").val(e.meta?.project||X||""),Ve(),g(),ke()}const A=e=>!!(t(e).get(0)||{}).checked;function le(){const e={variant:t("#me-variant").val(),position:t("#me-position").val(),appearOnHover:A("#me-appearOnHover"),floatAnchor:t("#me-float-anchor").val(),floatOffsetX:t("#me-float-offsetX").val(),floatOffsetY:t("#me-float-offsetY").val(),floatWidth:t("#me-float-width").val(),floatRadius:t("#me-float-radius").val(),floatShadow:t("#me-float-shadow").val(),floatAccent:tt(),floatOpacity:t("#me-float-opacity").val(),floatTitle:t("#me-float-title").val(),floatCollapsible:A("#me-float-collapsible"),floatCollapsed:A("#me-float-collapsed"),floatMovable:A("#me-float-movable"),floatResizable:A("#me-float-resizable"),highlightHover:t("#me-highlight-hover").val(),highlightActive:t("#me-highlight-active").val(),highlightAccent:Ge(),class:t("#me-class").val(),entranceEnabled:A("#me-entrance-enabled"),entranceAnimation:t("#me-entrance-animation").val(),entranceStagger:t("#me-entrance-stagger").val(),entranceDuration:t("#me-entrance-duration").val(),orientation:t("#me-orientation").val(),align:t("#me-align").val(),side:t("#me-side").val(),fontFamily:t("#me-fontFamily").val(),fontSize:t("#me-fontSize").val(),fontWeight:t("#me-fontWeight").val(),letterSpacing:t("#me-letterSpacing").val(),iconSize:t("#me-iconSize").val(),dockWidth:t("#me-dock-width").val(),dockCollapsible:A("#me-dock-collapsible"),dockCollapsed:A("#me-dock-collapsed"),dockAutohide:A("#me-dock-autohide"),mobileHamburgerOnly:A("#me-mobile-hamburger"),mobileHideBrand:A("#me-mobile-brand"),lookBar:t("#me-look-bar").val(),lookDropdown:t("#me-look-dropdown").val(),lookBrand:t("#me-look-brand").val(),lookStrip:t("#me-look-strip").val(),lookTiles:t("#me-look-tiles").val(),lookMorph:A("#me-look-morph"),lookShrink:A("#me-look-shrink"),dockHideOnScroll:A("#me-dock-hideOnScroll")},o={slug:t("#me-slug").val(),name:t("#me-name").val(),description:t("#me-description").val(),project:t("#me-project").val()};return Gt(e,o,Be(),Dt(h),f.meta||{})}const Ae=e=>[...Vt(e),...ft(e.class).map(o=>`CSS classes: ${o} (Behaviour tab).`)];let Ce=!1,Q=null;function Z(){if(!U)return;const e=le();Q=e,j.value=Je(e)!==U,Fe.value=j.peek()||Ce?Ae(e).join(" "):""}const Ye=e=>{e.target.closest("#me-items-list")||(e.target.matches("#me-position, #me-orientation, #me-look-dropdown, #me-float-collapsible, #me-dock-collapsible, #me-dock-autohide, #me-entrance-enabled")&&Ve(),e.target.matches("#me-float-accent")&&fe(),e.target.matches("#me-highlight-accent")&&B(),e.target.closest("#me-binding")&&g(),Z())};s.addEventListener("input",Ye),s.addEventListener("change",Ye),l(()=>{s.removeEventListener("input",Ye),s.removeEventListener("change",Ye)}),t("#me-bind-page-add").on("click",()=>{const e=t("#me-bind-page-pick").val();if(!e)return;const o=Ee.val().split(`
28
+ </div>`),y(p.id)}}y(null),n._disposeMenuHelp?.(),n.innerHTML=s.join("")||'<p class="mex-note">No items yet - Add item, or right-click an item for more.</p>',n._disposeMenuHelp=st(n),I.scan(n)}function b(n,u={},...l){const r=document.createElement(n);Object.assign(r,u);for(const s of l)s!=null&&r.append(s);return r}function w(n,u,l){const r=b("label",{className:"form-field"},b("span",{className:"form-label",textContent:n}),u),s=jt[n];if(s){const y=b("span");y.dataset.help=s+(l?" "+l:""),y.dataset.helpTitle=n,r.querySelector(".form-label").append(" ",y)}return l&&r.append(b("small",{className:"form-hint",textContent:l,style:"display:block;font-size:.78em;opacity:.7;margin-top:.25rem;line-height:1.35"})),r}function on(n,u){const l=[["","- Everyone -"],["public","Public - anyone, incl. logged-out"],...(u||[]).map(s=>[s.name,`${s.label||s.name} and above`]),...(u||[]).filter(s=>s.level!==0).map(s=>[`=${s.name}`,`${s.label||s.name} only`]),["private","Private - super-admin only"]];n&&!l.some(([s])=>s===n)&&l.push([n,`${n} (custom)`]);const r=K(l,n||"");return r.name="visibility",r}function K(n,u){const l=b("select",{className:"form-select"});return n.forEach(([r,s])=>l.add(new Option(s,r))),l.value=u??"",l}function je(n,u){const l=typeof u=="string"&&u.startsWith("#"),r=K([["","- none -"],["primary","primary"],["success","success"],["danger","danger"],["warning","warning"],["info","info"],["neutral","neutral"],["__custom__","Custom\u2026"]],l?"__custom__":u||""),s=b("input",{type:"color",className:"form-input me-colour-hex",value:l?u:"#000000"});s.style.display=l?"":"none",r.addEventListener("change",()=>{s.style.display=r.value==="__custom__"?"":"none"});const y=w(n,r);return y.append(s),y._read=()=>r.value==="__custom__"?s.value:r.value,y}function an(n,u){const l=b("input",{className:"form-input me-icon",name:"icon",value:u||""}),r=b("span",{className:"me-icon-preview"});u&&r.setAttribute("data-icon",u);const s=b("button",{type:"button",className:"btn btn-sm btn-ghost",textContent:"Browse\u2026"}),y=T=>{T?r.setAttribute("data-icon",T):r.removeAttribute("data-icon"),Domma.icons.scan(r.parentNode||r)};return s.addEventListener("click",()=>Lt(T=>{l.value=T,y(T)})),l.addEventListener("input",()=>y(l.value.trim())),w(n,b("div",{className:"me-icon-field"},l,s,r))}function te(...n){return b("div",{className:"me-field-grid"},...n)}async function sn(n,u,l,r,s,{cards:y=!0}={}){const T=n.text||n.tool?.label||"",p=m=>b("h4",{className:"me-form-section",textContent:m}),G=w("Label",b("input",{className:"form-input",name:"text",value:n.text||""}),"The text shown for this item."),L=b("input",{className:"form-input",name:"url",value:n.url||""}),V=w("URL",L,n.tool||n.locked?"A Tool's address is its identity, so it cannot be changed here.":"Where it links. Must start with /, #, https://, or mailto: . Leave blank for a parent that only groups sub-items.");(n.tool||n.locked)&&(L.readOnly=!0);const _=an("Icon",n.icon||""),f=on(n.visibility||"",r),re=w("Visibility",f,n.locked?"Always in the sidebar for everyone who may use it, so it cannot be restricted here.":'Who can see this item. "Role and above" shows it to that role and anyone more senior; "Role only" shows it to holders of that role alone (and the super-admin). Blank = everyone.');n.locked&&(f.disabled=!0);const ne=K([["","- no permission gate -"],...(u||[]).map(m=>[m.key,m.label||m.key])],n.permission||"");ne.name="permission";const ce=w("Permission",ne,n.tool||n.locked?"A Tool is guarded by its own permission, which always applies.":"Hide unless the viewer holds this specific permission. Independent of Visibility - both must pass.");(n.tool||n.locked)&&(ne.disabled=!0);const oe=w("Badge text",b("input",{className:"form-input",name:"badgeText",value:n.badge?.text||""})),de=K([["","- none -"],...(l||[]).map(m=>[m.slug,m.title||m.slug])],n.badge?.countFrom||"");de.name="badgeCount";const be=w("Badge count from",de,"Show a live count of this collection\u2019s entries as the badge."),ae=je("Badge colour",n.badge?.variant||""),ye=K([["link","Link"],["pill","Pill"]],n.pill?"pill":"link");ye.name="renderAs";const D=w("Render as",ye,"Pill draws the item as a rounded chip. Pill styling applies to top-level navbar items."),Le=w("Pill style",K([["filled","Filled"],["outline","Outline"]],n.pill?.style||"filled"));Le.querySelector("select").name="pillStyle";const $e=je("Pill colour",n.pill?.variant||""),h=b("div",{className:"me-pill-wrap"},te(Le,$e));h.style.display=n.pill?"":"none",ye.addEventListener("change",()=>{h.style.display=ye.value==="pill"?"":"none"});const j=je("Text colour",n.colour||""),ue=K([["","- use the menu default -"],...ut.map(m=>[m,mt[m]||m])],n.highlight?.hover||"");ue.name="hlHover";const Me=w("Hover effect",ue,"Overrides the menu-wide hover effect for this item only."),Te=K([["","- use the menu default -"],...pt.map(m=>[m,ht[m]||m])],n.highlight?.active||"");Te.name="hlActive";const U=w("When selected",Te,"How this item is marked when it points at the page being viewed."),$=je("Highlight colour",n.highlight?.accent||""),ke=b("input",{className:"form-input",name:"class",value:n.class||"",placeholder:"nav-cta push-right",autocomplete:"off",spellcheck:!1}),N=w("CSS classes",ke,"Your own class names, separated by spaces, added to this item's <li> - target the link with .your-class > a. Style them in Custom CSS."),Y=b("small",{className:"text-danger",style:"display:none;margin-top:.25rem"});N.append(Y);const pe=b("textarea",{className:"form-input",name:"description",rows:2,maxLength:Tt,value:n.description||"",placeholder:"Answers every new lead in under a minute."}),me=w("Description",pe,"One short line under the label, shown when the menu's dropdowns are Cards."),_e=je("Tile colour",n.tile||""),He=b("input",{type:"checkbox",name:"chip",checked:!!n.chip,style:"width:auto;margin:0"}),Ie=b("label",{className:"form-field",style:"display:flex;gap:.5rem;align-items:center;font-weight:400"},He,b("span",{textContent:"Show as a small chip in the card's footer strip"})),we=b("span");we.dataset.helpTitle="Show as a small chip",we.dataset.help="Place this sub-item in the compact chip strip at the bottom of its parent Cards dropdown instead of the main entries. Its label and destination remain the same. The parent card can provide a Chip strip label. This applies to sub-items in Cards dropdowns, rather than top-level navbar links.",Ie.append(we);const F=n.parentId==null,C=n.panel||{},O=(m,X,J,A=80)=>b("input",{className:"form-input",name:m,value:X||"",placeholder:J,maxLength:A}),Fe=w("Card heading",O("panelHeading",C.heading,"The crew - six agents, one job each"),"Small capitals over the entries."),ze=w("Link text",O("panelLinkText",C.link?.text,"Meet the crew",60)),Ue=w("Link URL",O("panelLinkUrl",C.link?.url,"/crew",500)),Ne=K([["","Automatic"],["1","1"],["2","2"],["3","3"],["4","4"]],C.columns?String(C.columns):"");Ne.name="panelColumns";const Ze=w("Columns",Ne),et=w("Chip strip label",O("panelChipsLabel",C.chipsLabel,"Add to your crew",60),'Words before the chips - tick "Show as a small chip" on the sub-items that belong there.'),he=K([["","- no side box -"],["dark","Dark"],["light","Light"],["accent","Theme colour"]],C.feature?C.feature.tone||"dark":"");he.name="featureTone";const We=w("Side box",he,"A box down the right of the card - a call to action or a short list."),Ke=w("Box small heading",O("featureEyebrow",C.feature?.eyebrow,"Free - 20 minutes",60)),qe=w("Box title",O("featureTitle",C.feature?.title,"See it live")),t=w("Box points",b("textarea",{className:"form-input",name:"featurePoints",rows:3,value:(C.feature?.points||[]).join(`
29
+ `),placeholder:"One per line, up to six"})),Se=w("Button text",O("featureBtnText",C.feature?.button?.text,"Book a demo",60)),Oe=w("Button URL",O("featureBtnUrl",C.feature?.button?.url,"/book",500)),fe=b("div",{},te(Ke,qe),t,te(Se,Oe));fe.style.display=he.value?"":"none",he.addEventListener("change",()=>{fe.style.display=he.value?"":"none"});const tt=y?[p("Card dropdown"),b("small",{className:"form-hint",style:"display:block;opacity:.7;margin-bottom:.4rem",textContent:"Used when the menu's Dropdown style is Cards (Behaviour tab)."}),me,te(_e,F?null:Ie),...F?[Fe,te(ze,Ue),te(Ze,et),We,fe]:[]]:[],se=b("button",{className:"btn btn-primary",textContent:"Apply",title:"Apply to the item (Ctrl+Enter) - Save the menu to keep it"}),W=b("div",{className:"me-item-form"},p("Link"),G,V,_,p("Access"),te(re,ce),p("Badge"),te(oe,ae),be,p("Appearance"),D,h,j,p("Highlighting"),te(Me,U),$,...tt,p("Styling"),N,se),B=E.slideover({title:T?`Edit ${De(T)}`:"Edit menu item",size:"lg",position:"right"});B.element.appendChild(W);const Ge=()=>JSON.stringify([...W.querySelectorAll("input, select, textarea")].map(m=>m.type==="checkbox"?m.checked:m.value)),Ve=Ge();let xe=!1,ge=!1;const Re=st(W,{position:"bottom"});Mt(B,Re);const Ee=B.close.bind(B);B.close=async m=>{if(!xe&&m!==!0&&Ge()!==Ve){if(ge)return;ge=!0;const X=await E.confirm("Discard the changes to this item?");if(ge=!1,!X)return}return xe=!0,Ee()},W.addEventListener("keydown",m=>{(m.ctrlKey||m.metaKey)&&m.key==="Enter"&&(m.preventDefault(),se.click())}),B.open();const Be=B.element.closest(".dm-slideover")||B.element.querySelector(".dm-slideover")||B.element;Be.style.setProperty("width",Qt+"px","important"),Be.style.setProperty("max-width","95vw","important"),Domma.icons.scan(W);const g=m=>W.querySelector(`[name="${m}"]`)?.value||"";se.addEventListener("click",()=>{const m=ft(g("class"));if(m.length){Y.textContent=m.join("; "),Y.style.display="block",ke.focus();return}n.class=At(g("class")),n.text=g("text"),n.icon=g("icon"),n.locked||(n.visibility=g("visibility")),!n.tool&&!n.locked?(n.url=g("url"),n.permission=g("permission")):n.touched=!0;const X=g("badgeText"),J=g("badgeCount"),A=ae._read();if(n.badge=X||J?{...X&&{text:X},...J&&{countFrom:J},...A&&{variant:A}}:null,g("renderAs")==="pill"){const Q=$e._read();n.pill={style:g("pillStyle")||"filled",...Q&&{variant:Q}}}else n.pill=null;n.colour=j._read();const le=g("hlHover"),Ae=g("hlActive"),Ce=$._read();if(n.highlight=le||Ae||Ce?{...le&&{hover:le},...Ae&&{active:Ae},...Ce&&{accent:Ce}}:null,y&&(n.description=g("description").trim(),n.tile=_e._read(),n.chip=!F&&He.checked,F)){const Q=g("featureTone");n.panel=$t({heading:g("panelHeading"),link:{text:g("panelLinkText"),url:g("panelLinkUrl")},columns:g("panelColumns"),chipsLabel:g("panelChipsLabel"),feature:Q?{tone:Q,eyebrow:g("featureEyebrow"),title:g("featureTitle"),points:g("featurePoints").split(`
30
+ `),button:{text:g("featureBtnText"),url:g("featureBtnUrl")}}:null})}xe=!0,B.close(!0),s()})}let q=null,yt=!1;function ln(){yt||!window.R?.use||(yt=!0,R.use((n,u,l)=>{const r=u?.path||"";return!(en.test(r)&&(n?.path||"")!==r)||!q?.dirty()?l():E.confirm(`You have unsaved changes to the menu "${De(q.name())}". Leave anyway? They are kept as a draft for your next visit.`).then(y=>{y?l():history.replaceState(null,"",`#${r}`)})}),M.subscribe("router:afterChange",({to:n}={})=>{if(q&&(n?.path||"")!==q.path){const u=q;q=null,u.dispose()}}))}function kt(n,u){const l=n.querySelector(".dm-plugin-banner-name"),r=l?.querySelector(".dm-plugin-banner-sep");if(!(!l||!r)){for(;r.nextSibling;)r.nextSibling.remove();l.appendChild(document.createTextNode(u))}}export const menuEditorView={templateUrl:"/admin/js/templates/menu-editor.html",async onMount(n){if(ln(),q){const e=q;q=null,e.dispose()}const u=[],l=e=>(u.push(e),e);let r=!1;const s=n.get(0).querySelector(".mex")||n.get(0),y=()=>!r&&s.isConnected,T=location.hash.replace(/^#/,""),p=location.hash.match(/^#\/menus\/edit\/([^?#]+)/),G=p?decodeURIComponent(p[1]):null,L=!G,V=`menu-editor.draft.${G||"new"}`,_=E.loader(n.get(0),{type:"dots"});let f,re,ne,ce,oe,de,be;try{if(L)f={slug:"",name:"",description:"",items:[]};else try{f=await P.menus.get(G)}catch(e){E.toast(`Failed to load menu: ${e.message||e}`,{type:"error"}),location.hash="#/menus";return}[re,ne,ce,oe,de,be]=await Promise.all([P.projects.list().catch(()=>[]),H.get("/api/auth/permissions-registry").catch(()=>({resources:[]})),P.collections.list().catch(()=>[]),P.get("/collections/roles/entries?limit=100").catch(()=>null),P.menuLocations.registry().catch(()=>[]),P.pages.list().catch(()=>[])])}finally{_.destroy()}if(!s.isConnected)return;const ye=(Array.isArray(oe)?oe:oe?.entries||[]).map(e=>({name:e.data?.name,label:e.data?.label,level:e.data?.level??99})).filter(e=>e.name).sort((e,o)=>o.level-e.level),D=!L&&G===Zt;let Le=[];if(D&&(Le=await H.get("/api/sidebar/registered-items").catch(()=>(E.toast("Could not load the Tools - they are not shown, and saving keeps their places as they are.",{type:"warning",duration:8e3}),[])),!s.isConnected))return;const $e=e=>gt(D?It(Ht(e||[],Le,{forEditor:!0}),{leaveInHiddenFolders:!0}):e);let h=$e(f.items);const j=M.observable(!1),ue=M.observable(!1),Me=M.observable(""),Te=M.observable(0);let U="";const $=s.querySelector("#me-items-list");l(()=>$._disposeMenuHelp?.());function ke(){nn($,h,D),Te.value=h.filter(e=>!ve(e)).length}const N=()=>{ke(),Z()},Y=()=>D?bt(h):new Set,pe=e=>h.find(o=>o.id===e);function me(e){requestAnimationFrame(()=>$.querySelector(`.menu-tree-row[data-id="${CSS.escape(e)}"]`)?.focus())}function _e(e){const o=v=>h.find(i=>!i.type&&!i.url&&!i.tool&&(i.key||"").toLowerCase()===v)||h.find(i=>!i.type&&!i.url&&!i.tool&&!i.key&&(i.text||"").toLowerCase()===v);let a=o(String(e.tool.folder||"").toLowerCase())||o(Pt);const c=String(e.tool.group||"").trim();if(a&&c){const v=Ot(a.key||Rt(a.text),c),i=d=>d!==e&&!d.type&&!d.url&&!d.tool;let k=h.find(d=>i(d)&&(d.key||"").toLowerCase()===v)||h.find(d=>i(d)&&d.parentId===a.id&&(!d.key||d.key.toLowerCase()===v)&&(d.text||"").toLowerCase()===c.toLowerCase());k||([k]=gt([{text:c,key:v,icon:Bt,synthesised:!0}],a.id),h.push(k)),a=k}e.parentId=a?a.id:null,h.splice(h.indexOf(e),1),h.push(e),Object.assign(e,{text:e.tool.defaults.text,icon:e.tool.defaults.icon,visibility:"",hidden:!1,badge:null,pill:null,colour:"",highlight:null,touched:!1}),e.tool={...e.tool,persisted:!1}}const He=e=>!Y().has(e.id)&&!(e.tool&&!e.tool.orphan);async function Ie(e){const o=pe(e);if(!o||!He(o))return;const a=d=>{let ee=d;for(;ee;){if(ee.id===e)return!0;ee=h.find(z=>z.id===ee.parentId)}return!1},c=h.filter(d=>d.id!==e&&a(d));if(c.length&&!await E.confirm(`Remove "${De(o.text||o.type||"this item")}" and the ${c.length} item${c.length===1?"":"s"} beneath it?`))return;const v=Y(),i=c.filter(d=>d.tool),k=c.filter(d=>!d.tool&&v.has(d.id));h=h.filter(d=>!a(d)||i.includes(d)||k.includes(d));for(const d of k)d.parentId=o.parentId??null;for(const d of i)d.tool.orphan?d.parentId=o.parentId??null:_e(d);N()}function we(e){const o=pe(e);!o||ve(o)||Y().has(e)||(o.hidden=!o.hidden,o.touched=!0,N())}function F(e){const o=pe(e);!o||ve(o)||(o.locked=D&&Y().has(o.id),sn(o,ne.resources||[],ce,ye,()=>{N(),me(e)},{cards:!D}))}function C(e){const o={id:Xe(),parentId:null,...e==="separator"||e==="theme-switcher"?{type:e}:e==="spacer"?{type:e,size:"md"}:{text:"",url:"/",icon:"",visibility:"",permission:"",hidden:!1,bundled:!1}};h.push(o),N(),ve(o)?me(o.id):F(o.id)}const O=e=>o=>{e(o)&&(N(),me(o))},Fe=O(e=>vt(h,e,-1)),ze=O(e=>vt(h,e,1)),Ue=O(e=>Kt(h,e)),Ne=O(e=>Yt(h,e));function Ze(e){const o=pe(e);if(!o)return[];const a=ve(o),c=Y().has(e),v=Xt(h,e),i=v.findIndex(z=>z.id===e),k=o.tool,d=k&&(k.persisted||o.touched),ee=z=>()=>{const Pe=qt(h,e,z,Xe());N(),Pe&&!ve(Pe)?F(Pe.id):Pe&&me(Pe.id)};return[{header:a?{separator:"Separator",spacer:"Spacer","theme-switcher":"Theme switcher"}[o.type]:o.text||k?.label||"(untitled)"},...a?[]:[{label:"Edit\u2026",icon:"edit",action:()=>F(e)}],{type:"divider"},{label:"Add item below",icon:"plus",action:ee("item")},{label:"Add sub-item",icon:"corner-down-right",disabled:a,action:()=>{const z=zt(h,e,Xe());N(),z&&F(z.id)}},{label:"Add separator below",icon:"minus",action:ee("separator")},{label:"Add spacer below",icon:"move",action:ee("spacer")},...D?[]:[{label:"Add theme switcher below",icon:"palette",action:ee("theme-switcher")}],{type:"divider"},{label:"Move up",icon:"arrow-up",shortcut:"Alt+\u2191",disabled:i<=0,action:()=>Fe(e)},{label:"Move down",icon:"arrow-down",shortcut:"Alt+\u2193",disabled:i<0||i>=v.length-1,action:()=>ze(e)},{label:"Indent",icon:"chevron-right",shortcut:"Alt+\u2192",disabled:i<=0||ve(v[i-1]),action:()=>Ue(e)},{label:"Outdent",icon:"chevron-left",shortcut:"Alt+\u2190",disabled:o.parentId==null,action:()=>Ne(e)},{type:"divider"},...a?[]:[{label:o.hidden?"Show":"Hide",icon:o.hidden?"eye":"eye-off",disabled:c,action:()=>we(e)}],{label:"Duplicate",icon:"copy",disabled:!!k,action:()=>{const z=Wt(h,e,Xe);N(),z&&me(z.id)}},...k&&!k.orphan&&d?[{label:"Back to its default place",icon:"rotate-ccw",action:()=>{_e(o),N()}}]:[],{label:c?"Remove - always in the sidebar":k&&!k.orphan?"Remove - a Tool is hidden, not removed":"Remove\u2026",icon:"trash",danger:!0,disabled:!He(o),action:()=>Ie(e)}]}const et=E.contextMenu($,{cursor:"glyph",match:".menu-tree-row",inherit:!1,density:"compact",items:e=>Ze(e.dataset.id)});l(()=>et?.destroy?.());const he=_t($,()=>h,N,{items:".menu-tree-row",handle:".menu-tree-grip"});l(()=>he?.destroy());const We=e=>{const o=e.target.closest(".menu-tree-row");if(!o)return;const a=o.dataset.id;if(e.target.closest(".mex-kebab")){lt(e.target.closest(".mex-kebab"));return}if(e.target.closest(".me-hidden")){we(a);return}if(e.target.closest(".me-edit")){F(a);return}e.target.closest("select, .menu-tree-grip, button")||F(a)},Ke=e=>{const o=e.target.closest(".menu-tree-row");if(!o||e.target!==o){o&&e.key==="F10"&&e.shiftKey&&(e.preventDefault(),lt(o));return}const a=o.dataset.id;if(e.key==="F10"&&e.shiftKey)e.preventDefault(),lt(o);else if(e.key==="Enter")e.preventDefault(),F(a);else if(e.key==="Delete")e.preventDefault(),Ie(a);else if(e.altKey&&e.key==="ArrowUp")e.preventDefault(),Fe(a);else if(e.altKey&&e.key==="ArrowDown")e.preventDefault(),ze(a);else if(e.altKey&&e.key==="ArrowRight")e.preventDefault(),Ue(a);else if(e.altKey&&e.key==="ArrowLeft")e.preventDefault(),Ne(a);else if(e.key==="ArrowDown"||e.key==="ArrowUp"){const c=[...$.querySelectorAll(".menu-tree-row")],v=c.indexOf(o)+(e.key==="ArrowDown"?1:-1);c[v]&&(e.preventDefault(),c[v].focus())}},qe=e=>{if(!e.target.matches(".me-spacer-size"))return;const o=pe(e.target.closest(".menu-tree-row")?.dataset.id);o&&(o.size=e.target.value,Z())};$.addEventListener("click",We),$.addEventListener("keydown",Ke),$.addEventListener("change",qe),l(()=>{$.removeEventListener("click",We),$.removeEventListener("keydown",Ke),$.removeEventListener("change",qe)});const t=e=>n.find(e),Se=t("#me-float-accent"),Oe=t("#me-float-accent-hex"),fe=()=>{Oe.get(0).style.display=Se.val()==="__custom__"?"":"none"},tt=()=>Se.val()==="__custom__"?Oe.val():Se.val(),se=t("#me-highlight-accent"),W=t("#me-highlight-accent-hex"),B=()=>{W.get(0).style.display=se.val()==="__custom__"?"":"none"},Ge=()=>se.val()==="__custom__"?W.val():se.val(),Ve=()=>{const e=!!(t("#me-entrance-enabled").get(0)||{}).checked;t(".dm-entrance-field").each(function(){this.style.display=e?"":"none"});const o=t("#me-position").val()==="floating";t(".dm-float-field").each(function(){this.style.display=o?"":"none"}),o&&fe();const a=t("#me-orientation").val()==="vertical";t(".dm-vertical-field").each(function(){this.style.display=a?"":"none"}),t(".dm-dock-rail-field").each(function(){this.style.display=a&&!o?"":"none"}),t(".dm-dock-bar-field").each(function(){this.style.display=!a&&!o?"":"none"});const c=!!(t("#me-dock-collapsible").get(0)||{}).checked,v=!!(t("#me-dock-autohide").get(0)||{}).checked;t(".dm-dock-collapsed-field").each(function(){this.style.display=c&&!v?"":"none"});const i=!!(t("#me-float-collapsible").get(0)||{}).checked;t(".dm-float-collapsed-field").each(function(){this.style.display=o&&i?"":"none"});const k=!a&&!D;t(".dm-look-field").each(function(){this.style.display=k?"":"none"});const d=k&&t("#me-look-dropdown").val()==="cards";t(".dm-look-cards-field").each(function(){this.style.display=d?"":"none"})},xe=(e,o,a,c)=>{const v=t(e).get(0);v&&(v.innerHTML="",v.add(new Option(c,"")),o.forEach(i=>v.add(new Option(a[i]||i,i))))};xe("#me-highlight-hover",ut,mt,"- theme default -"),xe("#me-highlight-active",pt,ht,"- theme default -");{const e=t("#me-entrance-animation").get(0);e&&(e.innerHTML="",ot.forEach(o=>e.add(new Option(Ct[o]||o,o))))}const ge=t("#me-bind-slot"),Re=t("#me-bind-projects"),Ee=t("#me-bind-pages");ge.get(0).innerHTML='<option value="">- not bound -</option>'+(de||[]).map(e=>`<option value="${x(e.slot)}">${x(e.label||e.slot)} (${x(e.slot)})</option>`).join(""),Re.get(0).innerHTML=re.map(e=>`<option value="${x(e.slug)}">${x(e.name||e.slug)}</option>`).join(""),t("#me-bind-page-pick").get(0).innerHTML='<option value="">- pick a page -</option>'+be.map(e=>{const o=e.urlPath||e.url||"";return o?`<option value="${x(o)}">${x(e.title||o)} - ${x(o)}</option>`:""}).join("");const Be=()=>Ut({slot:ge.val(),projects:Array.from(Re.get(0).selectedOptions).map(e=>e.value),pagesText:Ee.val()});function g(){const e=Be(),o=t("#me-bind-summary");if(!e){o.html('<span class="text-muted">Not bound - this menu renders only where it is mapped or placed by a shortcode.</span>');return}const a=[];e.projects.length&&a.push(`pages in ${e.projects.map(i=>`<code>${x(i)}</code>`).join(", ")}`),e.pages.length&&a.push(`pages matching ${e.pages.map(i=>`<code>${x(i)}</code>`).join(", ")}`);const c=e.pages.filter(i=>!/^\/[^\s?#*]*(\/\*)?$|^\/\*$/.test(i)),v=c.length?`<div class="text-danger" style="margin-top:.4rem">Not valid page patterns: ${c.map(i=>`<code>${x(i)}</code>`).join(", ")}</div>`:"";o.html(a.length?`Takes over the <code>${x(e.slot)}</code> slot on ${a.join(" and ")}.${v}`:`<span class="text-warning">Slot <code>${x(e.slot)}</code> selected but no project or page chosen - the binding will never match.</span>`)}const{getProjectFromHash:m}=await import("../lib/project-context.js");if(!y())return;const X=L?m():null;t("#me-project").get(0).innerHTML='<option value="">- none -</option>'+re.map(e=>`<option value="${x(e.slug)}">${x(e.name||e.slug)}</option>`).join("");function J(e){h=$e(e.items),t("#me-variant").val(e.variant||""),t("#me-position").val(e.position||"");const o=t("#me-appearOnHover").get(0);o&&(o.checked=e.appearOnHover===!0),t("#me-float-anchor").val(e.float?.anchor||"TL"),t("#me-float-offsetX").val(e.float?.offsetX??""),t("#me-float-offsetY").val(e.float?.offsetY??""),t("#me-float-width").val(e.float?.width??""),t("#me-float-radius").val(e.float?.radius??""),t("#me-float-shadow").val(e.float?.shadow||""),t("#me-float-opacity").val(e.float?.opacity??""),t("#me-float-title").val(e.float?.title||"");for(const[i,k]of[["#me-float-collapsible",e.float?.collapsible],["#me-float-collapsed",e.float?.collapsed],["#me-float-movable",e.float?.movable],["#me-float-resizable",e.float?.resizable]]){const d=t(i).get(0);d&&(d.checked=k===!0)}const a=e.float?.accent||"";Se.val(a.startsWith("#")?"__custom__":a),a.startsWith("#")&&Oe.val(a),fe(),t("#me-orientation").val(e.orientation||""),t("#me-align").val(e.align||""),t("#me-mobile-hamburger").get(0).checked=e.mobile?.hamburgerOnly===!0,t("#me-mobile-brand").get(0).checked=e.mobile?.hideBrand===!0,t("#me-look-bar").val(e.look?.bar||""),t("#me-look-brand").val(e.look?.brand||""),t("#me-look-strip").val(e.look?.strip||""),t("#me-look-icons").val(e.look?.icons||""),t("#me-look-dropdown").val(e.look?.dropdown||""),t("#me-look-tiles").val(e.look?.tiles||""),t("#me-look-morph").get(0).checked=e.look?.morph===!0,t("#me-look-shrink").get(0).checked=e.look?.shrink===!0,t("#me-side").val(e.side||"left"),t("#me-dock-width").val(e.dock?.width??"");for(const i of["collapsible","collapsed","autohide","hideOnScroll"]){const k=t(`#me-dock-${i}`).get(0);k&&(k.checked=e.dock?.[i]===!0)}t("#me-class").val(e.class||""),t("#me-highlight-hover").val(e.highlight?.hover||""),t("#me-highlight-active").val(e.highlight?.active||"");const c=e.highlight?.accent||"";se.val(c.startsWith("#")?"__custom__":c),c.startsWith("#")&&W.val(c),B();{const i=t("#me-entrance-enabled").get(0);i&&(i.checked=e.entrance?.enabled===!0)}t("#me-entrance-animation").val(ot.includes(e.entrance?.animation)?e.entrance.animation:ot[0]),t("#me-entrance-stagger").val(e.entrance?.stagger??""),t("#me-entrance-duration").val(e.entrance?.duration??""),t("#me-fontFamily").val(e.style?.fontFamily||""),t("#me-fontSize").val(e.style?.fontSize||""),t("#me-fontWeight").val(e.style?.fontWeight||""),t("#me-letterSpacing").val(e.style?.letterSpacing||""),t("#me-iconSize").val(e.style?.iconSize||""),ge.val(e.binding?.slot||"");const v=new Set(e.binding?.projects||[]);Array.from(Re.get(0).options).forEach(i=>{i.selected=v.has(i.value)}),Ee.val((e.binding?.pages||[]).join(`
31
+ `)),t("#me-slug").val(e.slug||""),t("#me-name").val(e.name||""),t("#me-description").val(e.description||""),t("#me-project").val(e.meta?.project||X||""),Ve(),g(),ke()}const A=e=>!!(t(e).get(0)||{}).checked;function le(){const e={variant:t("#me-variant").val(),position:t("#me-position").val(),appearOnHover:A("#me-appearOnHover"),floatAnchor:t("#me-float-anchor").val(),floatOffsetX:t("#me-float-offsetX").val(),floatOffsetY:t("#me-float-offsetY").val(),floatWidth:t("#me-float-width").val(),floatRadius:t("#me-float-radius").val(),floatShadow:t("#me-float-shadow").val(),floatAccent:tt(),floatOpacity:t("#me-float-opacity").val(),floatTitle:t("#me-float-title").val(),floatCollapsible:A("#me-float-collapsible"),floatCollapsed:A("#me-float-collapsed"),floatMovable:A("#me-float-movable"),floatResizable:A("#me-float-resizable"),highlightHover:t("#me-highlight-hover").val(),highlightActive:t("#me-highlight-active").val(),highlightAccent:Ge(),class:t("#me-class").val(),entranceEnabled:A("#me-entrance-enabled"),entranceAnimation:t("#me-entrance-animation").val(),entranceStagger:t("#me-entrance-stagger").val(),entranceDuration:t("#me-entrance-duration").val(),orientation:t("#me-orientation").val(),align:t("#me-align").val(),side:t("#me-side").val(),fontFamily:t("#me-fontFamily").val(),fontSize:t("#me-fontSize").val(),fontWeight:t("#me-fontWeight").val(),letterSpacing:t("#me-letterSpacing").val(),iconSize:t("#me-iconSize").val(),dockWidth:t("#me-dock-width").val(),dockCollapsible:A("#me-dock-collapsible"),dockCollapsed:A("#me-dock-collapsed"),dockAutohide:A("#me-dock-autohide"),mobileHamburgerOnly:A("#me-mobile-hamburger"),mobileHideBrand:A("#me-mobile-brand"),lookBar:t("#me-look-bar").val(),lookDropdown:t("#me-look-dropdown").val(),lookBrand:t("#me-look-brand").val(),lookStrip:t("#me-look-strip").val(),lookIcons:t("#me-look-icons").val(),lookTiles:t("#me-look-tiles").val(),lookMorph:A("#me-look-morph"),lookShrink:A("#me-look-shrink"),dockHideOnScroll:A("#me-dock-hideOnScroll")},o={slug:t("#me-slug").val(),name:t("#me-name").val(),description:t("#me-description").val(),project:t("#me-project").val()};return Gt(e,o,Be(),Dt(h),f.meta||{})}const Ae=e=>[...Vt(e),...ft(e.class).map(o=>`CSS classes: ${o} (Behaviour tab).`)];let Ce=!1,Q=null;function Z(){if(!U)return;const e=le();Q=e,j.value=Je(e)!==U,Me.value=j.peek()||Ce?Ae(e).join(" "):""}const Ye=e=>{e.target.closest("#me-items-list")||(e.target.matches("#me-position, #me-orientation, #me-look-dropdown, #me-float-collapsible, #me-dock-collapsible, #me-dock-autohide, #me-entrance-enabled")&&Ve(),e.target.matches("#me-float-accent")&&fe(),e.target.matches("#me-highlight-accent")&&B(),e.target.closest("#me-binding")&&g(),Z())};s.addEventListener("input",Ye),s.addEventListener("change",Ye),l(()=>{s.removeEventListener("input",Ye),s.removeEventListener("change",Ye)}),t("#me-bind-page-add").on("click",()=>{const e=t("#me-bind-page-pick").val();if(!e)return;const o=Ee.val().split(`
32
32
  `).map(a=>a.trim()).filter(Boolean);o.includes(e)||o.push(e),Ee.val(o.join(`
33
- `)),g(),Z()}),J(f),U=Je(le()),Z();const it=()=>{try{S.remove?S.remove(V):S.set(V,null)}catch{}};async function nt(){if(ue.peek())return;const e=le(),o=Ae(e);if(o.length){Ce=!0,Z(),E.toast(o.join(" "),{type:"warning",duration:7e3});return}ue.value=!0;let a=null;try{if($)await P.menus.create(e);else if(e.slug!==f.slug){await P.menus.create(e);const c=await P.menuLocations.get();let v=!1;for(const[i,k]of Object.entries(c))k===f.slug&&(c[i]=e.slug,v=!0);v&&await P.menuLocations.save(c),await P.menus.remove(f.slug)}else{const c=await wt(e);if(!c)return;a=c.revision}if(U=Je(e),j.value=!1,it(),Mt("#/menus"),E.toast("Saved.",{type:"success"}),$||e.slug!==f.slug)location.hash="#/menus/edit/"+encodeURIComponent(e.slug);else{f={...f,...e,revision:a};for(const c of h)c.tool&&c.touched&&(c.tool={...c.tool,persisted:!0});ke(),U=Je(le()),Z(),kt(n.get(0),e.name||e.slug)}if(D)try{document.dispatchEvent(new CustomEvent("dm:sidebar-rebuild"))}catch{}}catch(c){E.toast(`Save failed: ${c.message||c}`,{type:"error"})}finally{ue.value=!1}}async function wt(e){try{return await P.menus.update(f.slug,{...e,revision:f.revision})}catch(a){if(a.status!==409)throw a}if(await E.confirm(`The menu "${De(f.name||f.slug)}" was changed somewhere else after you opened it - in another tab, by someone else, or on the server. Saving now would undo those changes.<br><br><strong>OK</strong> saves yours over them. <strong>Cancel</strong> loads the latest version, and offers your changes back as a draft.`))return P.menus.update(f.slug,e);try{S.set(V,{menu:e,base:U,at:new Date().toISOString()})}catch{}return j.value=!1,location.reload(),null}async function St(){!j.peek()||!await E.confirm("Throw away the changes you have not saved?")||(J(f),Z())}E.tabs(t("#me-tabs").get(0));const xt=M.applyBindings({dirty:j,saving:ue,problems:Fe,itemCount:Te},s,{methods:{save:()=>nt(),discard:()=>St(),addItem:()=>C("item"),addSeparator:()=>C("separator"),addSpacer:()=>C("spacer"),addSwitcher:()=>C("theme-switcher")}});l(()=>xt.dispose()),l(st(s,{position:"bottom"})),D&&t("#me-add-switcher").hide(),kt(n.get(0),$?"New menu":f.name||f.slug),at(n,{id:"menu-editor-back",icon:"arrow-left",title:"All menus",onClick:()=>{location.hash="#/menus"}}),at(n,{id:"menu-editor-locations",icon:"map-pin",title:"Menu locations",onClick:()=>{location.hash="#/menu-locations"}}),at(n,{id:"menu-editor-save",icon:"save",title:"Save (Ctrl+S)",onClick:()=>nt()});const rt=e=>{if(!(!(e.ctrlKey||e.metaKey)||e.key!=="s")){if(e.preventDefault(),e.stopImmediatePropagation(),document.querySelector(".me-item-form")?.offsetParent){E.toast("Apply the item first (Ctrl+Enter), then Save.",{type:"info"});return}nt()}};document.addEventListener("keydown",rt,!0),l(()=>document.removeEventListener("keydown",rt,!0));const ct=()=>{if(!(!j.peek()||!Q))try{S.set(V,{menu:Q,base:U,at:new Date().toISOString()})}catch{}},dt=e=>{j.peek()&&(ct(),e.preventDefault(),e.returnValue="")};window.addEventListener("beforeunload",dt),l(()=>window.removeEventListener("beforeunload",dt)),q={path:T,dirty:()=>j.peek(),name:()=>t("#me-name").val()||f.name||f.slug||"new menu",dispose(){r=!0,ct(),u.splice(0).reverse().forEach(e=>{try{e()}catch{}})}},I.scan(s);let ie=null;try{ie=S.get(V)}catch{}if(ie?.menu){it();const e=ie.base&&ie.base!==U,o=ie.at?` (${Jt(ie.at)})`:"",a=$?"the new menu you started":`the menu "${De(f.name||f.slug)}"`,c=e?`You left unsaved changes to ${a}${o}, but the saved menu has changed since. Restore your version anyway?`:`You left unsaved changes to ${a}${o}. Restore them?`;await E.confirm(c)&&y()&&(J({...ie.menu,meta:{...f.meta||{},...ie.menu.meta||{}}}),Z())}}};
33
+ `)),g(),Z()}),J(f),U=Je(le()),Z();const it=()=>{try{S.remove?S.remove(V):S.set(V,null)}catch{}};async function nt(){if(ue.peek())return;const e=le(),o=Ae(e);if(o.length){Ce=!0,Z(),E.toast(o.join(" "),{type:"warning",duration:7e3});return}ue.value=!0;let a=null;try{if(L)await P.menus.create(e);else if(e.slug!==f.slug){await P.menus.create(e);const c=await P.menuLocations.get();let v=!1;for(const[i,k]of Object.entries(c))k===f.slug&&(c[i]=e.slug,v=!0);v&&await P.menuLocations.save(c),await P.menus.remove(f.slug)}else{const c=await wt(e);if(!c)return;a=c.revision}if(U=Je(e),j.value=!1,it(),Ft("#/menus"),E.toast("Saved.",{type:"success"}),L||e.slug!==f.slug)location.hash="#/menus/edit/"+encodeURIComponent(e.slug);else{f={...f,...e,revision:a};for(const c of h)c.tool&&c.touched&&(c.tool={...c.tool,persisted:!0});ke(),U=Je(le()),Z(),kt(n.get(0),e.name||e.slug)}if(D)try{document.dispatchEvent(new CustomEvent("dm:sidebar-rebuild"))}catch{}}catch(c){E.toast(`Save failed: ${c.message||c}`,{type:"error"})}finally{ue.value=!1}}async function wt(e){try{return await P.menus.update(f.slug,{...e,revision:f.revision})}catch(a){if(a.status!==409)throw a}if(await E.confirm(`The menu "${De(f.name||f.slug)}" was changed somewhere else after you opened it - in another tab, by someone else, or on the server. Saving now would undo those changes.<br><br><strong>OK</strong> saves yours over them. <strong>Cancel</strong> loads the latest version, and offers your changes back as a draft.`))return P.menus.update(f.slug,e);try{S.set(V,{menu:e,base:U,at:new Date().toISOString()})}catch{}return j.value=!1,location.reload(),null}async function St(){!j.peek()||!await E.confirm("Throw away the changes you have not saved?")||(J(f),Z())}E.tabs(t("#me-tabs").get(0));const xt=M.applyBindings({dirty:j,saving:ue,problems:Me,itemCount:Te},s,{methods:{save:()=>nt(),discard:()=>St(),addItem:()=>C("item"),addSeparator:()=>C("separator"),addSpacer:()=>C("spacer"),addSwitcher:()=>C("theme-switcher")}});l(()=>xt.dispose()),l(st(s,{position:"bottom"})),D&&t("#me-add-switcher").hide(),kt(n.get(0),L?"New menu":f.name||f.slug),at(n,{id:"menu-editor-back",icon:"arrow-left",title:"All menus",onClick:()=>{location.hash="#/menus"}}),at(n,{id:"menu-editor-locations",icon:"map-pin",title:"Menu locations",onClick:()=>{location.hash="#/menu-locations"}}),at(n,{id:"menu-editor-save",icon:"save",title:"Save (Ctrl+S)",onClick:()=>nt()});const rt=e=>{if(!(!(e.ctrlKey||e.metaKey)||e.key!=="s")){if(e.preventDefault(),e.stopImmediatePropagation(),document.querySelector(".me-item-form")?.offsetParent){E.toast("Apply the item first (Ctrl+Enter), then Save.",{type:"info"});return}nt()}};document.addEventListener("keydown",rt,!0),l(()=>document.removeEventListener("keydown",rt,!0));const ct=()=>{if(!(!j.peek()||!Q))try{S.set(V,{menu:Q,base:U,at:new Date().toISOString()})}catch{}},dt=e=>{j.peek()&&(ct(),e.preventDefault(),e.returnValue="")};window.addEventListener("beforeunload",dt),l(()=>window.removeEventListener("beforeunload",dt)),q={path:T,dirty:()=>j.peek(),name:()=>t("#me-name").val()||f.name||f.slug||"new menu",dispose(){r=!0,ct(),u.splice(0).reverse().forEach(e=>{try{e()}catch{}})}},I.scan(s);let ie=null;try{ie=S.get(V)}catch{}if(ie?.menu){it();const e=ie.base&&ie.base!==U,o=ie.at?` (${Jt(ie.at)})`:"",a=L?"the new menu you started":`the menu "${De(f.name||f.slug)}"`,c=e?`You left unsaved changes to ${a}${o}, but the saved menu has changed since. Restore your version anyway?`:`You left unsaved changes to ${a}${o}. Restore them?`;await E.confirm(c)&&y()&&(J({...ie.menu,meta:{...f.meta||{},...ie.menu.meta||{}}}),Z())}}};