domma-cms 0.36.1 → 0.36.2
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/admin/css/admin.css +1 -1
- package/admin/css/dashboard.css +1 -1
- package/admin/js/lib/card-builder.js +1 -1
- package/admin/js/lib/effects-builder.js +2 -2
- package/admin/js/lib/embed-builder.js +1 -1
- package/admin/js/lib/markdown-toolbar.js +2 -2
- package/admin/js/lib/project-quick-create.js +2 -2
- package/admin/js/lib/scribe-composer.js +3 -3
- package/admin/js/lib/shortcode-context-menu.js +6 -6
- package/admin/js/lib/shortcode-modal.js +1 -1
- package/admin/js/lib/sidebar-renderer.js +2 -2
- package/admin/js/lib/timeline-builder.js +2 -2
- package/admin/js/templates/api-endpoint-editor.html +2 -2
- package/admin/js/templates/block-editor.html +1 -1
- package/admin/js/templates/component-editor.html +4 -4
- package/admin/js/templates/docs/api-actions.html +11 -11
- package/admin/js/templates/docs/api-authentication.html +11 -11
- package/admin/js/templates/docs/api-collections.html +11 -11
- package/admin/js/templates/docs/api-layouts.html +11 -11
- package/admin/js/templates/docs/api-media.html +11 -11
- package/admin/js/templates/docs/api-navigation.html +11 -11
- package/admin/js/templates/docs/api-pages.html +11 -11
- package/admin/js/templates/docs/api-plugins.html +11 -11
- package/admin/js/templates/docs/api-settings.html +11 -11
- package/admin/js/templates/docs/api-users.html +11 -11
- package/admin/js/templates/docs/api-views.html +11 -11
- package/admin/js/templates/form-editor.html +4 -4
- package/admin/js/templates/form-submissions.html +1 -1
- package/admin/js/templates/navigation.html +3 -3
- package/admin/js/templates/notifications.html +1 -1
- package/admin/js/templates/page-editor.html +3 -3
- package/admin/js/templates/project-detail.html +19 -19
- package/admin/js/templates/settings.html +6 -6
- package/admin/js/views/action-editor.js +1 -1
- package/admin/js/views/api-endpoint-editor.js +3 -3
- package/admin/js/views/collection-editor.js +2 -2
- package/admin/js/views/collection-entries.js +1 -1
- package/admin/js/views/component-editor.js +3 -3
- package/admin/js/views/form-editor.js +3 -3
- package/admin/js/views/form-submissions.js +1 -1
- package/admin/js/views/page-editor.js +4 -4
- package/admin/js/views/project-detail.js +1 -1
- package/admin/js/views/settings.js +2 -2
- package/package.json +1 -1
- package/public/css/forms.css +1 -1
- package/public/css/site.css +1 -1
- package/public/js/menu-decor.mjs +1 -1
- package/public/js/site.js +1 -1
|
@@ -6,7 +6,7 @@ function le(){I.register("bold",{viewBox:"0 0 24 24",path:"M7 5H14a3 3 0 0 1 0 6
|
|
|
6
6
|
`,i),r=o===-1?t.value.length:o+1;t.setSelectionRange(s,r),document.execCommand("copy"),t.setSelectionRange(i,i),E.toast("Line copied",{type:"info",duration:1200})}})}export function insertLine(t,e){const d=t.selectionStart,i=t.value,s=i.lastIndexOf(`
|
|
7
7
|
`,d-1)+1,o=i.indexOf(`
|
|
8
8
|
`,s);i.substring(s,o===-1?i.length:o).startsWith(e)?(replaceRange(t,s,s+e.length,""),t.setSelectionRange(Math.max(s,d-e.length),Math.max(s,d-e.length))):(replaceRange(t,s,s,e),t.setSelectionRange(d+e.length,d+e.length))}const Z=["activity","airpods","airport","alert-circle","alert-warning","ambulance","angry","annoyed","apartment","arch","archive","arrow-down","arrow-down-left","arrow-down-right","arrow-left","arrow-right","arrow-up","arrow-up-left","arrow-up-right","astonished","at-sign","attachment","award","badge","ban","bandage","bank","banknote","barbell","barcode","barn","baseball","basketball","battery","battery-charging","bauble","bell","bell-off","bells","bicycle","bitcoin","blood-drop","blush","bold","bone","book","book-closed","book-open","bookmark","bookmark-filled","bowling","box","boxing-glove","brain","bridge","briefcase","building","bus","cabin","cake","calculator","calendar","camera","camera-off","candy-cane","capsule","car","cart","cart-add","cash","cast","castle","chart-area","chart-bar","chart-bar-horizontal","chart-candlestick","chart-line","chart-pie","chat","chat-alt","check","check-circle","check-circle-filled","check-square","chevron-down","chevron-left","chevron-right","chevron-up","chevrons-down","chevrons-left","chevrons-right","chevrons-up","church","circle","circle-filled","clear-format","clipboard","clipboard-check","clipboard-list","clock","close","cloud","cloud-download","cloud-drizzle","cloud-lightning","cloud-off","cloud-rain","cloud-sun","cloud-upload","code","code-block","code-inline","cog","coins","columns","comment","compass","component","confused","cool","copy","corner-down-left","corner-down-right","corner-up-left","corner-up-right","court","cpu","credit-card","crown","crutch","cry","currency-dollar","currency-euro","currency-pound","cycling","database","dead","desktop","disappointed","dna","document","document-add","document-check","document-remove","document-text","dollar-sign","dome","dot","dots-horizontal","dots-vertical","download","droplet","droplets","dumbbell","edit","embed","emoji-happy","emoji-sad","euro-sign","exclamation","expand","expressionless","external-link","eye","eye-medical","eye-off","factory","fast-forward","feather","file-code","file-text","file-zip","fill","film","filter","fire","first-aid","fishing","flag","fog","folder","folder-add","folder-minus","folder-open","folder-plus","folder-remove","football","fortress","fuel","gamepad","garage","gauge","gift","git-branch","github","globe","golf","grid","grin","growth","hard-drive","hash","haze","heading-1","heading-2","heading-3","headphones","heart","heart-eyes","heart-filled","heart-pulse","heartbeat","help-circle","holly","home","hospital","hotel","house","image","image-add","images","inbox","indent","info","info-filled","investment","invoice","italic","joy","joystick","key","kettlebell","keyboard","laptop","laugh","layers","layout","library","lighthouse","lightning","link","link-2","link-add","linkedin","list","list-bullet","list-numbered","loader","loading","lock","log-in","log-out","lungs","mail","mail-open","map","map-pin","mask","maximize","medal","medical-cross","menu","menu-alt","message-circle","message-square","mic","mic-off","microscope","minimize","minus","minus-circle","minus-square","monitor","monument","moon","moon-star","more-horizontal","more-vertical","mosque","motorcycle","mountain","mouse","mouse-pointer","move","museum","music","nerd","neutral","notification","obelisk","office","outdent","package","palette","panel-bottom","panel-left","panel-right","panel-top","paperclip","parking","pause","pause-filled","percent","phone","phone-call","phone-incoming","phone-off","phone-outgoing","piggy-bank","pill","pill-bottle","pin","play","play-circle","play-filled","plug","plus","plus-circle","plus-square","podium","pound-sign","printer","pulse","pyramid","qrcode","question","quote","racket","radio","rage","rain","rainbow","receipt","redo","refresh","refresh-cw","reindeer","rewind","road","rotate-ccw","rotate-cw","router","rss","running","sad","safe","save","scale","scale-weight","school","search","send","server","settings","share","share-2","share-alt","shield","shield-alert","shield-check","shield-x","shipping","shocked","shopping-bag","shrink","sick","sidebar-left","sidebar-right","silly","skate","ski","skip-back","skip-forward","skyscraper","sleepy","sleigh","sliders","smartphone","smartwatch","smile","snow","snowflake","snowman","sob","soccer","sort","sparkles","speaker","spinner","square","stadium","star","star-decoration","star-eyes","star-filled","stethoscope","stop","stop-filled","stopwatch","store","strikethrough","sun","sunrise","sunset","surfboard","surprised","swimming","sync","syringe","tablet","tablet-smartphone","tag","tags","target","taxi","temple","tennis","tent","terminal","test-tube","text-center","text-left","text-right","thermometer","thermometer-medical","thermometer-sun","thinking","thumb-down","thumb-up","tongue","tool","tooth","tower","train-station","trash","tree","trending-down","trending-neutral","trending-up","trophy","truck","tv","tv-minimal","twitter","type","umbrella","underline","undo","university","unlink","unlock","upload","usb","user","user-add","user-check","user-group","user-plus","user-remove","users","vaccine","van","vault","video","video-off","volleyball","volume","volume-down","volume-mute","volume-off","volume-up","wallet","warehouse","warning","warning-filled","watch","webcam","wheelchair","whistle","wifi","wifi-off","wind","windmill","wink","wreath","x","x-circle","x-circle-filled","yoga","youtube","zany","zap"];function se(t,e,d){const i=document.querySelector(".editor-spacer-picker");if(i){i.remove();return}const s=document.createElement("div");s.className="editor-spacer-picker";const o=document.createElement("div");o.className="editor-spacer-picker-label",o.textContent="Spacer height",s.appendChild(o);const r=document.createElement("div");r.className="editor-spacer-picker-row";const l=document.createElement("input");l.type="range",l.className="editor-spacer-slider",l.min="4",l.max="200",l.step="4",l.value=d;const m=document.createElement("span");m.className="editor-spacer-slider-value",m.textContent=d+"px",l.addEventListener("input",function(){m.textContent=this.value+"px"}),r.appendChild(l),r.appendChild(m),s.appendChild(r);const p=document.createElement("button");p.type="button",p.className="btn btn-primary btn-sm editor-spacer-insert-btn",p.textContent="Insert",s.appendChild(p);function f(v){!s.contains(v.target)&&v.target!==e&&(s.remove(),document.removeEventListener("click",f,!0))}p.addEventListener("click",function(){s.remove(),document.removeEventListener("click",f,!0),insertAtCursor(t,`[spacer size="${l.value}" /]
|
|
9
|
-
`)});const n=e.getBoundingClientRect(),c=e.closest(".editor-toolbar").getBoundingClientRect();s.style.top=n.bottom-c.top+4+"px";const a=n.left-c.left;s.style.left=Math.min(a,c.width-240-8)+"px",e.closest(".editor-toolbar").appendChild(s),setTimeout(function(){document.addEventListener("click",f,!0)},0)}function ce(t,e){const d=document.querySelector(".editor-icon-picker");if(d){d.remove();return}const i=document.createElement("div");i.className="editor-icon-picker";const s=document.createElement("input");s.type="text",s.className="form-input editor-icon-picker-search",s.placeholder="Search icons\u2026",i.appendChild(s);const o=document.createElement("div");o.className="editor-icon-picker-size-row";const r=document.createElement("label");r.textContent="Size (px)";const l=document.createElement("input");l.type="number",l.className="form-input editor-icon-picker-size",l.placeholder="default",l.min="8",l.max="256",o.appendChild(r),o.appendChild(l),i.appendChild(o);const m=document.createElement("div");m.className="editor-icon-picker-grid",i.appendChild(m);function p(w){!i.contains(w.target)&&w.target!==e&&(i.remove(),document.removeEventListener("click",p,!0))}function f(w){m.textContent="";const x=w?Z.filter(S=>S.includes(w.toLowerCase())):Z;if(x.length===0){const S=document.createElement("div");S.className="editor-icon-picker-empty",S.textContent="No icons found",m.appendChild(S);return}x.forEach(function(S){const M=document.createElement("button");M.type="button",M.className="editor-icon-picker-item";const k=document.createElement("span");k.setAttribute("data-icon",S);const h=document.createElement("span");h.textContent=S,M.appendChild(k),M.appendChild(h),M.addEventListener("click",function(){i.remove(),document.removeEventListener("click",p,!0);const C=l.value.trim(),L=C?`[icon name="${S}" size="${C}" /]`:`[icon name="${S}" /]`;insertAtCursor(t,L)}),m.appendChild(M)}),Domma.icons.scan(m)}f(""),s.addEventListener("input",function(){f(this.value.trim())});const n=e.getBoundingClientRect(),c=e.closest(".editor-toolbar").getBoundingClientRect();i.style.top=n.bottom-c.top+4+"px";const a=n.left-c.left,v=320,y=c.width;i.style.left=Math.min(a,y-v-8)+"px",e.closest(".editor-toolbar").appendChild(i),requestAnimationFrame(function(){s.focus()}),setTimeout(function(){document.addEventListener("click",p,!0)},0)}function ae(t,e,d,i){const s=document.querySelector(".editor-toolbar-dropdown");if(s){s.remove();return}const o=document.createElement("div");o.className="editor-toolbar-dropdown",d.forEach(function(f){const n=document.createElement("button");if(n.type="button",n.className="editor-toolbar-dropdown-item",f.icon){const a=document.createElement("span");a.setAttribute("data-icon",f.icon),n.appendChild(a)}const c=document.createElement("span");c.textContent=f.label,n.appendChild(c),n.addEventListener("click",function(){o.remove(),document.removeEventListener("click",p,!0),J(f.action,t,e,i)}),o.appendChild(n)});const r=e.getBoundingClientRect(),l=e.closest(".editor-toolbar").getBoundingClientRect();o.style.top=r.bottom-l.top+4+"px";const m=r.left-l.left;o.style.left=Math.min(m,l.width-180-8)+"px",e.closest(".editor-toolbar").appendChild(o),Domma.icons.scan(o);function p(f){!o.contains(f.target)&&f.target!==e&&(o.remove(),document.removeEventListener("click",p,!0))}setTimeout(function(){document.addEventListener("click",p,!0)},0)}function J(t,e,d,i){const{spacerDefault:s,handlers:o}=i;if(typeof t=="function")t(e);else if(t==="block")if(o.block)o.block(e);else{const r=e.selectionStart;replaceRange(e,r,r,'[block template="" /]'),e.setSelectionRange(r+17,r+17)}else if(t==="component")o.component?o.component(e):de(e);else if(t==="button")if(o.button)o.button(e);else{const r=e.selectionStart,l=e.selectionEnd,p=`[button href="" variant="primary"]${e.value.substring(r,l)||"Click me"}[/button]`;replaceRange(e,r,l,p),e.setSelectionRange(r+14,r+14)}else if(t==="linksc")if(o.linksc)o.linksc(e);else{const r=e.selectionStart,l=e.selectionEnd,p=`[link href=""]${e.value.substring(r,l)||"Link text"}[/link]`;replaceRange(e,r,l,p),e.setSelectionRange(r+12,r+12)}else if(t==="colourpick"){const r=e.selectionStart;document.getElementById("dm-colour-overlay")?.remove();const l=document.createElement("div");l.id="dm-colour-overlay",l.style.cssText="position:fixed;inset:0;z-index:9999;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.5);";const m=document.createElement("div");m.style.cssText="background:var(--dm-surface,#1e1e2e);border:1px solid var(--dm-border,#3a3a5c);border-radius:12px;padding:1.75rem 2rem;display:flex;flex-direction:column;align-items:center;gap:1.25rem;min-width:260px;box-shadow:
|
|
9
|
+
`)});const n=e.getBoundingClientRect(),c=e.closest(".editor-toolbar").getBoundingClientRect();s.style.top=n.bottom-c.top+4+"px";const a=n.left-c.left;s.style.left=Math.min(a,c.width-240-8)+"px",e.closest(".editor-toolbar").appendChild(s),setTimeout(function(){document.addEventListener("click",f,!0)},0)}function ce(t,e){const d=document.querySelector(".editor-icon-picker");if(d){d.remove();return}const i=document.createElement("div");i.className="editor-icon-picker";const s=document.createElement("input");s.type="text",s.className="form-input editor-icon-picker-search",s.placeholder="Search icons\u2026",i.appendChild(s);const o=document.createElement("div");o.className="editor-icon-picker-size-row";const r=document.createElement("label");r.textContent="Size (px)";const l=document.createElement("input");l.type="number",l.className="form-input editor-icon-picker-size",l.placeholder="default",l.min="8",l.max="256",o.appendChild(r),o.appendChild(l),i.appendChild(o);const m=document.createElement("div");m.className="editor-icon-picker-grid",i.appendChild(m);function p(w){!i.contains(w.target)&&w.target!==e&&(i.remove(),document.removeEventListener("click",p,!0))}function f(w){m.textContent="";const x=w?Z.filter(S=>S.includes(w.toLowerCase())):Z;if(x.length===0){const S=document.createElement("div");S.className="editor-icon-picker-empty",S.textContent="No icons found",m.appendChild(S);return}x.forEach(function(S){const M=document.createElement("button");M.type="button",M.className="editor-icon-picker-item";const k=document.createElement("span");k.setAttribute("data-icon",S);const h=document.createElement("span");h.textContent=S,M.appendChild(k),M.appendChild(h),M.addEventListener("click",function(){i.remove(),document.removeEventListener("click",p,!0);const C=l.value.trim(),L=C?`[icon name="${S}" size="${C}" /]`:`[icon name="${S}" /]`;insertAtCursor(t,L)}),m.appendChild(M)}),Domma.icons.scan(m)}f(""),s.addEventListener("input",function(){f(this.value.trim())});const n=e.getBoundingClientRect(),c=e.closest(".editor-toolbar").getBoundingClientRect();i.style.top=n.bottom-c.top+4+"px";const a=n.left-c.left,v=320,y=c.width;i.style.left=Math.min(a,y-v-8)+"px",e.closest(".editor-toolbar").appendChild(i),requestAnimationFrame(function(){s.focus()}),setTimeout(function(){document.addEventListener("click",p,!0)},0)}function ae(t,e,d,i){const s=document.querySelector(".editor-toolbar-dropdown");if(s){s.remove();return}const o=document.createElement("div");o.className="editor-toolbar-dropdown",d.forEach(function(f){const n=document.createElement("button");if(n.type="button",n.className="editor-toolbar-dropdown-item",f.icon){const a=document.createElement("span");a.setAttribute("data-icon",f.icon),n.appendChild(a)}const c=document.createElement("span");c.textContent=f.label,n.appendChild(c),n.addEventListener("click",function(){o.remove(),document.removeEventListener("click",p,!0),J(f.action,t,e,i)}),o.appendChild(n)});const r=e.getBoundingClientRect(),l=e.closest(".editor-toolbar").getBoundingClientRect();o.style.top=r.bottom-l.top+4+"px";const m=r.left-l.left;o.style.left=Math.min(m,l.width-180-8)+"px",e.closest(".editor-toolbar").appendChild(o),Domma.icons.scan(o);function p(f){!o.contains(f.target)&&f.target!==e&&(o.remove(),document.removeEventListener("click",p,!0))}setTimeout(function(){document.addEventListener("click",p,!0)},0)}function J(t,e,d,i){const{spacerDefault:s,handlers:o}=i;if(typeof t=="function")t(e);else if(t==="block")if(o.block)o.block(e);else{const r=e.selectionStart;replaceRange(e,r,r,'[block template="" /]'),e.setSelectionRange(r+17,r+17)}else if(t==="component")o.component?o.component(e):de(e);else if(t==="button")if(o.button)o.button(e);else{const r=e.selectionStart,l=e.selectionEnd,p=`[button href="" variant="primary"]${e.value.substring(r,l)||"Click me"}[/button]`;replaceRange(e,r,l,p),e.setSelectionRange(r+14,r+14)}else if(t==="linksc")if(o.linksc)o.linksc(e);else{const r=e.selectionStart,l=e.selectionEnd,p=`[link href=""]${e.value.substring(r,l)||"Link text"}[/link]`;replaceRange(e,r,l,p),e.setSelectionRange(r+12,r+12)}else if(t==="colourpick"){const r=e.selectionStart;document.getElementById("dm-colour-overlay")?.remove();const l=document.createElement("div");l.id="dm-colour-overlay",l.style.cssText="position:fixed;inset:0;z-index:9999;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.5);";const m=document.createElement("div");m.style.cssText="background:var(--dm-surface,#1e1e2e);border:1px solid var(--dm-border,#3a3a5c);border-radius:12px;padding:1.75rem 2rem;display:flex;flex-direction:column;align-items:center;gap:1.25rem;min-width:260px;box-shadow:var(--dm-shadow-lg);";const p=document.createElement("p");p.textContent="Colour Picker",p.style.cssText="margin:0;font-weight:700;font-size:1rem;letter-spacing:.02em;";const f=document.createElement("input");f.type="color",f.value="#000000",f.style.cssText="width:160px;height:110px;cursor:pointer;border:none;background:none;padding:0;border-radius:6px;overflow:hidden;";const n=document.createElement("div");n.style.cssText="display:flex;align-items:center;gap:.5rem;";const c=document.createElement("input");c.type="text",c.value="#000000",c.className="form-input",c.style.cssText="font-family:monospace;width:100px;text-transform:uppercase;letter-spacing:.05em;";const a=document.createElement("button");a.type="button",a.className="btn btn-ghost btn-sm",a.textContent="Copy";const v=document.createElement("button");v.type="button",v.className="btn btn-primary btn-sm",v.textContent="Insert";const y=()=>l.remove();f.addEventListener("input",()=>{c.value=f.value}),c.addEventListener("input",()=>{/^#[0-9a-f]{6}$/i.test(c.value)&&(f.value=c.value)}),a.addEventListener("click",()=>{const w=document.createElement("input");w.value=c.value,document.body.appendChild(w),w.select(),document.execCommand("copy"),w.remove(),a.textContent="Copied!",setTimeout(()=>{a.textContent="Copy"},1500)}),v.addEventListener("click",()=>{e.selectionStart=e.selectionEnd=r,insertAtCursor(e,c.value),y()}),l.addEventListener("click",w=>{w.target===l&&y()}),n.appendChild(c),n.appendChild(a),n.appendChild(v),m.appendChild(p),m.appendChild(f),m.appendChild(n),l.appendChild(m),document.body.appendChild(l)}else if(t==="link")o.link&&o.link(e);else if(t==="image")o.image&&o.image(e);else if(t==="card")if(o.card)o.card(e);else{const r=e.selectionStart,l=e.selectionEnd,p=`[card title="Card Title"]
|
|
10
10
|
${e.value.substring(r,l)||"Content here"}
|
|
11
11
|
[/card]`;replaceRange(e,r,l,p),e.setSelectionRange(r+13,r+23)}else if(t==="hero")if(o.hero)o.hero(e);else{const r=e.selectionStart,l=e.selectionEnd,p=`[hero title="Hero Title" tagline="A short tagline" size="lg"]
|
|
12
12
|
${e.value.substring(r,l)||"Optional body content here."}
|
|
@@ -41,6 +41,6 @@ Describe this event.
|
|
|
41
41
|
[item title="Item 1"]Content here.[/item]
|
|
42
42
|
[item title="Item 2"]Content here.[/item]
|
|
43
43
|
[/accordion]
|
|
44
|
-
`)}else if(t==="text"){let n=function(b,u){const g=document.createElement("div"),z=document.createElement("label");return z.style.cssText=p,z.textContent=b,g.appendChild(z),g.appendChild(u),g},c=function(b){const u=document.createElement("select");return u.style.cssText=f,[["","\u2014 default \u2014"],...b].forEach(([g,z])=>{const O=document.createElement("option");O.value=g,O.textContent=z,u.appendChild(O)}),u},a=function(b,u){const g=document.createElement("input");return g.type="text",g.placeholder=b||"",g.value=u||"",g.style.cssText=f,g},v=function(b){const u=document.createElement("label");u.style.cssText="display:flex;align-items:center;gap:.5rem;cursor:pointer;";const g=document.createElement("input");g.type="checkbox";const z=document.createElement("span");return z.style.cssText="font-size:.85em;color:var(--dm-text,#eee);",z.textContent=b,u.appendChild(g),u.appendChild(z),{wrap:u,cb:g}},y=function(b,u){const g=document.createElement("div");return g.style.cssText="display:grid;grid-template-columns:1fr 1fr;gap:.5rem;",g.appendChild(b),g.appendChild(u),g},w=function(b){const u=document.createElement("div");return u.style.cssText="border-top:1px solid var(--dm-border,#333);padding-top:.5rem;margin-top:.1rem;font-size:.65rem;font-weight:700;color:var(--dm-text-muted,#aaa);text-transform:uppercase;letter-spacing:.08em;",u.textContent=b,u},_=function(){const b=[];M.value&&b.push(`font-size:${ee[M.value]||M.value}`);const u=parseFloat(k.value);!isNaN(u)&&u>0&&b.push(`font-size:${u}pt`),L.checked?b.push("font-weight:700"):h.value&&b.push(`font-weight:${te[h.value]||h.value}`),T.checked&&b.push("font-style:italic");const g=B.value.trim();g&&b.push(`color:${Y[g]||g}`),j.value&&b.push(`font-family:${oe[j.value]}`),W.value&&b.push(`text-transform:${ie[W.value]}`),P.value&&b.push(`text-decoration:${re[P.value]}`),A.value&&b.push(`letter-spacing:${ne[A.value]}`),H.value&&(b.push("display:block"),b.push(`text-align:${H.value}`)),D.value.trim()&&b.push(D.value.trim()),q.style.cssText=b.join(";"),q.textContent=S.value||"Preview text"};const r=e.selectionStart,l=e.selectionEnd,m=e.value.substring(r,l)||"",p="display:block;font-size:.7rem;font-weight:600;color:var(--dm-text-muted,#aaa);text-transform:uppercase;letter-spacing:.05em;",f="width:100%;padding:.4rem .6rem;background:var(--dm-input-bg,#1a1a1a);border:1px solid var(--dm-border,#333);border-radius:4px;color:var(--dm-text,#eee);font-size:.9em;",x=document.createElement("div");x.style.cssText="padding:1rem;display:flex;flex-direction:column;gap:.6rem;overflow-y:auto;max-height:75vh;";const S=a("Text to style\u2026",m);x.appendChild(n("Content",S)),x.appendChild(w("Typography"));const M=c([["xs","xs \u2014 0.75rem"],["sm","sm \u2014 0.875rem"],["base","base \u2014 1rem"],["lg","lg \u2014 1.125rem"],["xl","xl \u2014 1.25rem"],["2xl","2xl \u2014 1.5rem"],["3xl","3xl \u2014 1.875rem"],["4xl","4xl \u2014 2.25rem"]]),k=a("pt value (overrides Size)");x.appendChild(y(n("Size",M),n("Point Size (pt)",k)));const h=c([["thin","Thin (100)"],["light","Light (300)"],["normal","Normal (400)"],["medium","Medium (500)"],["semibold","Semibold (600)"],["bold","Bold (700)"],["extrabold","Extrabold (800)"],["black","Black (900)"]]),{wrap:C,cb:L}=v("Bold (overrides Weight)"),{wrap:N,cb:T}=v("Italic"),R=document.createElement("div");R.style.cssText="display:flex;flex-direction:column;gap:.4rem;justify-content:flex-end;",R.appendChild(C),R.appendChild(N),x.appendChild(y(n("Weight",h),R)),x.appendChild(w("Appearance"));const B=a("e.g. primary, #ff0000"),j=c([["Georgia","Georgia (serif)"],["Arial","Arial (sans-serif)"],["Verdana","Verdana (sans-serif)"],["Courier New","Courier New (mono)"],["Times New Roman","Times New Roman (serif)"],["Trebuchet MS","Trebuchet MS"]]);x.appendChild(y(n("Colour",B),n("Font",j))),x.appendChild(w("Formatting"));const W=c([["upper","Uppercase"],["lower","Lowercase"],["capitalize","Capitalise"],["none","None"]]),P=c([["underline","Underline"],["line-through","Line-through"],["none","None"]]);x.appendChild(y(n("Transform",W),n("Decoration",P)));const A=c([["tight","Tight"],["normal","Normal"],["wide","Wide"],["wider","Wider"]]),H=c([["left","Left"],["center","Centre"],["right","Right"],["justify","Justify"]]);x.appendChild(y(n("Spacing",A),n("Align",H))),x.appendChild(w("Advanced"));const D=a("e.g. margin-top:1rem;display:block");x.appendChild(n("Style",D));const F=a("CSS class(es)"),G=a("ID");x.appendChild(y(n("Class",F),n("ID",G)));const K=document.createElement("div");K.style.cssText="padding:.75rem;background:var(--dm-
|
|
44
|
+
`)}else if(t==="text"){let n=function(b,u){const g=document.createElement("div"),z=document.createElement("label");return z.style.cssText=p,z.textContent=b,g.appendChild(z),g.appendChild(u),g},c=function(b){const u=document.createElement("select");return u.style.cssText=f,[["","\u2014 default \u2014"],...b].forEach(([g,z])=>{const O=document.createElement("option");O.value=g,O.textContent=z,u.appendChild(O)}),u},a=function(b,u){const g=document.createElement("input");return g.type="text",g.placeholder=b||"",g.value=u||"",g.style.cssText=f,g},v=function(b){const u=document.createElement("label");u.style.cssText="display:flex;align-items:center;gap:.5rem;cursor:pointer;";const g=document.createElement("input");g.type="checkbox";const z=document.createElement("span");return z.style.cssText="font-size:.85em;color:var(--dm-text,#eee);",z.textContent=b,u.appendChild(g),u.appendChild(z),{wrap:u,cb:g}},y=function(b,u){const g=document.createElement("div");return g.style.cssText="display:grid;grid-template-columns:1fr 1fr;gap:.5rem;",g.appendChild(b),g.appendChild(u),g},w=function(b){const u=document.createElement("div");return u.style.cssText="border-top:1px solid var(--dm-border,#333);padding-top:.5rem;margin-top:.1rem;font-size:.65rem;font-weight:700;color:var(--dm-text-muted,#aaa);text-transform:uppercase;letter-spacing:.08em;",u.textContent=b,u},_=function(){const b=[];M.value&&b.push(`font-size:${ee[M.value]||M.value}`);const u=parseFloat(k.value);!isNaN(u)&&u>0&&b.push(`font-size:${u}pt`),L.checked?b.push("font-weight:700"):h.value&&b.push(`font-weight:${te[h.value]||h.value}`),T.checked&&b.push("font-style:italic");const g=B.value.trim();g&&b.push(`color:${Y[g]||g}`),j.value&&b.push(`font-family:${oe[j.value]}`),W.value&&b.push(`text-transform:${ie[W.value]}`),P.value&&b.push(`text-decoration:${re[P.value]}`),A.value&&b.push(`letter-spacing:${ne[A.value]}`),H.value&&(b.push("display:block"),b.push(`text-align:${H.value}`)),D.value.trim()&&b.push(D.value.trim()),q.style.cssText=b.join(";"),q.textContent=S.value||"Preview text"};const r=e.selectionStart,l=e.selectionEnd,m=e.value.substring(r,l)||"",p="display:block;font-size:.7rem;font-weight:600;color:var(--dm-text-muted,#aaa);text-transform:uppercase;letter-spacing:.05em;",f="width:100%;padding:.4rem .6rem;background:var(--dm-input-bg,#1a1a1a);border:1px solid var(--dm-border,#333);border-radius:4px;color:var(--dm-text,#eee);font-size:.9em;",x=document.createElement("div");x.style.cssText="padding:1rem;display:flex;flex-direction:column;gap:.6rem;overflow-y:auto;max-height:75vh;";const S=a("Text to style\u2026",m);x.appendChild(n("Content",S)),x.appendChild(w("Typography"));const M=c([["xs","xs \u2014 0.75rem"],["sm","sm \u2014 0.875rem"],["base","base \u2014 1rem"],["lg","lg \u2014 1.125rem"],["xl","xl \u2014 1.25rem"],["2xl","2xl \u2014 1.5rem"],["3xl","3xl \u2014 1.875rem"],["4xl","4xl \u2014 2.25rem"]]),k=a("pt value (overrides Size)");x.appendChild(y(n("Size",M),n("Point Size (pt)",k)));const h=c([["thin","Thin (100)"],["light","Light (300)"],["normal","Normal (400)"],["medium","Medium (500)"],["semibold","Semibold (600)"],["bold","Bold (700)"],["extrabold","Extrabold (800)"],["black","Black (900)"]]),{wrap:C,cb:L}=v("Bold (overrides Weight)"),{wrap:N,cb:T}=v("Italic"),R=document.createElement("div");R.style.cssText="display:flex;flex-direction:column;gap:.4rem;justify-content:flex-end;",R.appendChild(C),R.appendChild(N),x.appendChild(y(n("Weight",h),R)),x.appendChild(w("Appearance"));const B=a("e.g. primary, #ff0000"),j=c([["Georgia","Georgia (serif)"],["Arial","Arial (sans-serif)"],["Verdana","Verdana (sans-serif)"],["Courier New","Courier New (mono)"],["Times New Roman","Times New Roman (serif)"],["Trebuchet MS","Trebuchet MS"]]);x.appendChild(y(n("Colour",B),n("Font",j))),x.appendChild(w("Formatting"));const W=c([["upper","Uppercase"],["lower","Lowercase"],["capitalize","Capitalise"],["none","None"]]),P=c([["underline","Underline"],["line-through","Line-through"],["none","None"]]);x.appendChild(y(n("Transform",W),n("Decoration",P)));const A=c([["tight","Tight"],["normal","Normal"],["wide","Wide"],["wider","Wider"]]),H=c([["left","Left"],["center","Centre"],["right","Right"],["justify","Justify"]]);x.appendChild(y(n("Spacing",A),n("Align",H))),x.appendChild(w("Advanced"));const D=a("e.g. margin-top:1rem;display:block");x.appendChild(n("Style",D));const F=a("CSS class(es)"),G=a("ID");x.appendChild(y(n("Class",F),n("ID",G)));const K=document.createElement("div");K.style.cssText="padding:.75rem;background:var(--dm-background-alt,#111);border-radius:4px;min-height:2.5rem;display:flex;align-items:center;";const q=document.createElement("span");q.textContent=m||"Preview text",K.appendChild(q),x.appendChild(n("Preview",K));const Y={primary:"var(--dm-primary)",secondary:"var(--dm-secondary)",muted:"var(--dm-text-muted)",danger:"var(--dm-danger)",success:"var(--dm-success)",warning:"var(--dm-warning)",info:"var(--dm-info)"},ee={xs:".75rem",sm:".875rem",base:"1rem",lg:"1.125rem",xl:"1.25rem","2xl":"1.5rem","3xl":"1.875rem","4xl":"2.25rem"},te={thin:"100",light:"300",normal:"400",medium:"500",semibold:"600",bold:"700",extrabold:"800",black:"900"},ne={tight:"-0.05em",normal:"0em",wide:"0.05em",wider:"0.1em"},oe={Georgia:"Georgia,serif",Arial:"Arial,sans-serif",Verdana:"Verdana,sans-serif","Courier New":"'Courier New',monospace","Times New Roman":"'Times New Roman',serif","Trebuchet MS":"'Trebuchet MS',sans-serif"},ie={upper:"uppercase",lower:"lowercase",capitalize:"capitalize",none:"none"},re={underline:"underline","line-through":"line-through",none:"none"};L.addEventListener("change",()=>{h.disabled=L.checked,L.checked&&(h.value=""),_()}),[M,h,j,W,P,A,H].forEach(b=>{b.addEventListener("change",_)}),[B,S,D,k].forEach(b=>{b.addEventListener("input",_)}),T.addEventListener("change",_);const V=document.createElement("button");V.type="button",V.className="btn btn-primary",V.textContent="Insert",x.appendChild(V);const U=E.slideover({title:"Style Text",size:"md",position:"right",content:x});U.open(),V.addEventListener("click",()=>{const b=S.value;if(!b.trim())return;const u=[];M.value&&u.push(`size="${M.value}"`);const g=parseFloat(k.value);!isNaN(g)&&g>0&&u.push(`point-size="${g}"`),L.checked?u.push("bold"):h.value&&u.push(`weight="${h.value}"`),T.checked&&u.push("italic"),B.value.trim()&&u.push(`color="${B.value.trim()}"`),j.value&&u.push(`font="${j.value}"`),W.value&&u.push(`transform="${W.value}"`),P.value&&u.push(`decoration="${P.value}"`),A.value&&u.push(`spacing="${A.value}"`),H.value&&u.push(`align="${H.value}"`),D.value.trim()&&u.push(`style="${D.value.trim().replace(/"/g,""")}"`),F.value.trim()&&u.push(`class="${F.value.trim()}"`),G.value.trim()&&u.push(`id="${G.value.trim()}"`);const O=`[text${u.length?" "+u.join(" "):""}]${b}[/text]`;U.close(),insertAtCursor(e,O)})}else t==="help"?o.help&&o.help(e):t==="tutorial"&&o.tutorial&&o.tutorial(e)}const Q=[{icon:"bold",title:"Bold (Ctrl+B)",action:t=>wrapSelection(t,"**","**")},{icon:"italic",title:"Italic (Ctrl+I)",action:t=>wrapSelection(t,"_","_")},{icon:"strikethrough",title:"Strikethrough",action:t=>wrapSelection(t,"~~","~~")},"|",{type:"dropdown",icon:"heading-1",title:"Headings",items:[{label:"Heading 1",icon:"heading-1",action:t=>insertLine(t,"# ")},{label:"Heading 2",icon:"heading-2",action:t=>insertLine(t,"## ")},{label:"Heading 3",icon:"heading-3",action:t=>insertLine(t,"### ")}]},"|",{icon:"list-bullet",title:"Bullet list",action:t=>insertLine(t,"- ")},{icon:"list-numbered",title:"Numbered list",action:t=>insertLine(t,"1. ")},"|",{type:"dropdown",icon:"quote",title:"Paragraph",items:[{label:"Blockquote",icon:"quote",action:t=>insertLine(t,"> ")},{label:"Horizontal rule",icon:"minus-circle",action:t=>insertAtCursor(t,`
|
|
45
45
|
---
|
|
46
46
|
`)}]},"|",{type:"dropdown",icon:"code-inline",title:"Code",items:[{label:"Inline code",icon:"code-inline",action:t=>wrapSelection(t,"`","`")},{label:"Code block",icon:"code-block",action:t=>wrapSelection(t,"\n```\n","\n```\n")}]},"|",{type:"dropdown",icon:"plus-circle",title:"Insert",items:[{label:"Accordion",icon:"accordion-insert",action:"accordion"},{label:"Banner",icon:"banner-insert",action:"banner"},{label:"Badge",icon:"badge",action:"badge"},{label:"Block",icon:"layout",action:"block"},{label:"Button",icon:"btn-insert",action:"button"},{label:"Card",icon:"card",action:"card"},{label:"Carousel",icon:"carousel-insert",action:"carousel"},{label:"Colour Picker",icon:"colour-picker",action:"colourpick"},{label:"Collection",icon:"database",action:"collection"},{label:"Component",icon:"component",action:"component"},{label:"CTA Button",icon:"mouse-pointer",action:"cta"},{label:"Embed",icon:"video",action:"embed"},{label:"Form",icon:"file-text",action:"form"},{label:"Grid",icon:"columns",action:"grid"},{label:"Hero",icon:"hero",action:"hero"},{label:"Icon",icon:"icon-pick",action:"iconpick"},{label:"Image",icon:"image-add",action:"image"},{label:"Link",icon:"link-shortcode",action:"linksc"},{label:"List Group",icon:"list",action:"listgroup"},{label:"Scribe",icon:"scribe-insert",action:"scribe"},{label:"Spacer",icon:"spacer-insert",action:"spacerpick"},{label:"Tabs",icon:"layout-list",action:"tabs"},{label:"Text",icon:"text-style",action:"text"},{label:"Timeline",icon:"activity",action:"timeline"},{label:"View",icon:"eye",action:"view"}]},"|",{icon:"sparkles",title:"Effects",action:"effects"},{icon:"book-open",title:"CRUD tutorial",action:"tutorial"},{icon:"help-circle",title:"Editor help",action:"help"}];export function createToolbar(t,e,d={}){le();const i={link:null,image:null,card:null,grid:null,help:null,tutorial:null,effects:null,collection:null,view:null,cta:null,form:null,button:null,linksc:null,tabs:null,accordion:null,carousel:null,hero:null,banner:null},s=d.spacerDefault??40,o=t.get(0),r=e.get(0);r.textContent="",Q.forEach((n,c)=>{if(n==="|"){const a=document.createElement("span");a.className="editor-toolbar-sep",r.appendChild(a)}else{const a=document.createElement("button");a.className=n.type==="dropdown"?"editor-toolbar-btn editor-toolbar-dropdown-trigger":"editor-toolbar-btn",a.setAttribute("data-tooltip",n.title),a.setAttribute("data-idx",String(c)),a.type="button";const v=document.createElement("span");if(v.setAttribute("data-icon",n.icon),a.appendChild(v),n.type==="dropdown"){const y=document.createElement("span");y.className="editor-toolbar-caret",y.textContent="\u25BE",a.appendChild(y)}r.appendChild(a)}});const l=document.createElement("div");l.className="editor-toolbar-right",[{mode:"split",icon:"columns",label:"Split view",active:!0},{mode:"write",icon:"file-text",label:"Write only",active:!1},{mode:"preview",icon:"eye",label:"Preview only",active:!1}].forEach(n=>{const c=document.createElement("button");c.className="editor-view-btn"+(n.active?" active":""),c.setAttribute("data-mode",n.mode),c.setAttribute("data-tooltip",n.label),c.type="button";const a=document.createElement("span");a.setAttribute("data-icon",n.icon),c.appendChild(a),l.appendChild(c)});const m=document.createElement("span");m.className="editor-toolbar-sep",l.appendChild(m);const p=document.createElement("button");p.id="fullscreen-btn",p.className="editor-toolbar-btn",p.setAttribute("data-tooltip","Toggle fullscreen"),p.type="button";const f=document.createElement("span");return f.setAttribute("data-icon","expand"),p.appendChild(f),l.appendChild(p),r.appendChild(l),Domma.icons.scan(),r.querySelectorAll("[data-tooltip]").forEach(n=>{E.tooltip(n,{content:n.getAttribute("data-tooltip"),position:"top"})}),e.on("click",".editor-toolbar-btn[data-idx]",function(){const n=parseInt($(this).data("idx"),10),c=Q[n];if(!c||c==="|")return;const a=e.get(0).querySelector(`[data-idx="${n}"]`),v={spacerDefault:s,handlers:i};c.type==="dropdown"?ae(o,a,c.items,v):J(c.action,o,a,v)}),attachEditorKeybindings(o),o.addEventListener("keydown",n=>{const c=n.key.toLowerCase();(n.ctrlKey||n.metaKey)&&(c==="b"?(n.preventDefault(),wrapSelection(o,"**","**")):c==="i"?(n.preventDefault(),wrapSelection(o,"_","_")):c==="k"&&(n.preventDefault(),i.link&&i.link(o)))}),{$toolbar:e,onLink(n){i.link=n},onImage(n){i.image=n},onCard(n){i.card=n},onGrid(n){i.grid=n},onHelp(n){i.help=n},onTutorial(n){i.tutorial=n},onEffects(n){i.effects=n},onCollection(n){i.collection=n},onBlock(n){i.block=n},onView(n){i.view=n},onCta(n){i.cta=n},onForm(n){i.form=n},onButton(n){i.button=n},onLinkShortcode(n){i.linksc=n},onTabs(n){i.tabs=n},onCarousel(n){i.carousel=n},onAccordion(n){i.accordion=n},onHero(n){i.hero=n},onBanner(n){i.banner=n},onListGroup(n){i.listgroup=n},onScribe(n){i.scribe=n},onTimeline(n){i.timeline=n}}}async function de(t){const{api:e}=await import("../api.js");let d;try{d=await e.components.list()}catch(k){E.toast(k.message||"Failed to load components.",{type:"error"});return}if(!d?.length){E.toast("No components yet. Create one in Data \u2192 Components first.",{type:"info"});return}const i=E.slideover({title:"Insert Component",size:"lg",position:"right"}),s=document.createElement("div");s.style.cssText="display:flex;flex-direction:column;gap:1rem;padding:.75rem;min-height:100%;";const o=document.createElement("div");o.style.cssText="font-size:.72rem;letter-spacing:.05em;text-transform:uppercase;color:var(--dm-text-muted,#888);",o.textContent="Gallery";const r=document.createElement("div");r.style.cssText="display:grid;grid-template-columns:repeat(auto-fill,minmax(140px,1fr));gap:.5rem;";const l=document.createElement("div");l.style.cssText="font-size:.72rem;letter-spacing:.05em;text-transform:uppercase;color:var(--dm-text-muted,#888);",l.textContent="Props";const m=document.createElement("div");m.style.cssText="padding:.6rem;border:1px solid var(--dm-border,rgba(255,255,255,.08));border-radius:4px;min-height:40px;",m.textContent="Select a component from the gallery above.";const p=document.createElement("div");p.style.cssText="font-size:.72rem;letter-spacing:.05em;text-transform:uppercase;color:var(--dm-text-muted,#888);",p.textContent="Preview";const f=document.createElement("iframe");f.src="/admin/preview/component-preview.html",f.style.cssText="width:100%;min-height:180px;border:1px solid var(--dm-border,rgba(255,255,255,.08));border-radius:4px;background:#fff;";const n=document.createElement("div");n.style.cssText="display:flex;justify-content:flex-end;gap:.5rem;margin-top:auto;padding-top:.75rem;border-top:1px solid var(--dm-border,rgba(255,255,255,.08));";const c=document.createElement("button");c.className="btn btn-ghost",c.textContent="Cancel";const a=document.createElement("button");a.className="btn btn-primary",a.textContent="Insert",a.disabled=!0,n.appendChild(c),n.appendChild(a),s.appendChild(o),s.appendChild(r),s.appendChild(l),s.appendChild(m),s.appendChild(p),s.appendChild(f),s.appendChild(n),i.setContent(s),i.open();let v=null,y={};function w(){r.replaceChildren();for(const k of d){const h=document.createElement("button");h.type="button",h.className="btn btn-ghost",h.style.cssText="display:flex;flex-direction:column;align-items:flex-start;gap:.25rem;padding:.6rem;border:1px solid var(--dm-border,rgba(255,255,255,.08));border-radius:4px;text-align:left;";const C=document.createElement("strong");C.style.cssText="font-size:.9rem;",C.textContent=k.name;const L=document.createElement("span");L.style.cssText="font-size:.72rem;color:var(--dm-text-muted,#888);",L.textContent=`${Object.keys(k.props||{}).length} prop(s)`,h.appendChild(C),h.appendChild(L),h.addEventListener("click",()=>x(k)),r.appendChild(h)}}function x(k){v=k,y={};for(const[h,C]of Object.entries(k.props||{}))y[h]=C.default!==void 0?C.default:"";a.disabled=!1,S(),M()}function S(){m.replaceChildren();const k=Object.entries(v.props||{});if(k.length===0){const h=document.createElement("p");h.className="text-muted",h.style.margin="0",h.textContent="This component takes no props.",m.appendChild(h);return}for(const[h,C]of k){const L=document.createElement("div");L.style.cssText="display:flex;align-items:center;gap:.5rem;margin-bottom:.4rem;";const N=document.createElement("label");N.style.cssText="font-size:.8rem;min-width:120px;color:var(--dm-text-muted,#aaa);",N.textContent=C.label||h,L.appendChild(N);const T=pe(C);ue(T,C,y[h]),T.addEventListener("input",()=>{y[h]=X(T,C),f.contentWindow?.postMessage({type:"update",payload:{props:y}},"*")}),T.addEventListener("change",()=>{y[h]=X(T,C),f.contentWindow?.postMessage({type:"update",payload:{props:y}},"*")}),L.appendChild(T),m.appendChild(L)}}async function M(){if(v)try{const k=await fetch(`/api/components/${encodeURIComponent(v.name)}.js`);if(!k.ok)throw new Error(`Failed to load component (${k.status})`);const h=await k.text();f.contentWindow?.postMessage({type:"remount",payload:{compiledJs:h,tagName:`dm-${v.name}`,props:y}},"*")}catch(k){E.toast(k.message||"Failed to load preview.",{type:"error"})}}c.addEventListener("click",()=>i.close()),a.addEventListener("click",()=>{if(!v)return;const k=t.selectionStart,h=t.selectionEnd,C=Object.entries(y).map(([N,T])=>{const R=N.replace(/([A-Z])/g,"-$1").toLowerCase(),B=String(T??"").replace(/"/g,""");return`${R}="${B}"`}).join(" "),L=`[component name="${v.name}"${C?" "+C:""} /]`;replaceRange(t,k,h,L),i.close()}),w()}function pe(t){let e;return t.type==="number"?(e=document.createElement("input"),e.type="number",e.className="form-input form-input--sm"):t.type==="boolean"?(e=document.createElement("input"),e.type="checkbox",e.className="form-check"):t.type==="array"||t.type==="object"?(e=document.createElement("textarea"),e.rows=2,e.className="form-input form-input--sm",e.style.fontFamily="var(--dm-font-mono, monospace)"):(e=document.createElement("input"),e.type="text",e.className="form-input form-input--sm"),e.style.flex="1",e}function X(t,e){if(e.type==="number")return t.value===""?null:Number(t.value);if(e.type==="boolean")return!!t.checked;if(e.type==="array"||e.type==="object")try{return JSON.parse(t.value||"null")}catch{return null}return t.value}function ue(t,e,d){e.type==="boolean"?t.checked=!!d:e.type==="array"||e.type==="object"?t.value=JSON.stringify(d??null):t.value=d??""}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{api as g}from"../api.js";const C={pages:"Page",collections:"Collection",menus:"Menu",blocks:"Block"};export const INLINE_TYPES=Object.keys(C);function d(n){return String(n||"").toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function L(n){return String(n??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function l(n,t=""){const e=document.createElement("input");return e.type="text",e.className="form-input",e.placeholder=n,e.value=t,e}function T(n,t,e){const r=document.createElement("div");r.style.cssText="display:flex;flex-direction:column;gap:.35rem;";const a=document.createElement("label");if(a.className="form-label",a.textContent=n,r.appendChild(a),r.appendChild(t),e){const o=document.createElement("small");o.style.cssText="color:var(--text-muted,#888);font-size:.78rem;",o.textContent=e,r.appendChild(o)}return r}function x(n,t){const e=document.createElement("button");return e.type="button",e.className=t,e.textContent=n,e}function v(n,t,e=""){let r=!1;t.addEventListener("input",()=>{r=!0}),n.addEventListener("input",()=>{r||(t.value=e+d(n.value))})}const k={pages(n){const t=l("e.g. Squad List"),e=(n.rootUrl||"").replace(/\/+$/,""),r=l(e?`${e}/squad-list`:"/squad-list");return v(t,r,e+"/"),{rows:[["Title",t,"Shown as the page heading and in the pages list."],["URL path",r,e?`Keeping it under ${e}/ files the page in this project automatically.`:"Where the page lives, e.g. /squad-list."]],async submit(){const a=t.value.trim();if(!a)throw new Error("Title is required.");let o=r.value.trim()||"/"+d(a);return o.startsWith("/")||(o="/"+o),await g.pages.create({urlPath:o,frontmatter:{title:a,project:n.slug},body:""}),{editorHash:"#/pages/edit"+o,label:a}}}},collections(n){const t=l("e.g. Players"),e=l("players");return v(t,e),{rows:[["Title",t,"Display name for the collection."],["Slug",e,"Used in URLs and the API. Lowercase letters, numbers and hyphens."]],note:"Creates an empty collection tagged to this project \u2014 add fields in the editor.",async submit(){const r=t.value.trim();if(!r)throw new Error("Title is required.");const a=d(e.value||r);if(!a)throw new Error("A valid slug is required.");return await g.collections.create({title:r,slug:a,fields:[],meta:{project:n.slug}}),{editorHash:"#/collections/edit/"+encodeURIComponent(a),label:r}}}},menus(n){const t=l("e.g. Tournament Nav"),e=l("tournament-nav");return v(t,e),{rows:[["Name",t,"Display name for the menu."],["Slug",e,'Referenced by [menu slug="\u2026"] and menu locations.']],note:"Creates an empty menu tagged to this project \u2014 add items in the editor.",async submit(){const r=t.value.trim();if(!r)throw new Error("Name is required.");const a=d(e.value||r);if(!a)throw new Error("A valid slug is required.");return await g.menus.create({slug:a,name:r,items:[],meta:{project:n.slug}}),{editorHash:"#/menus/edit/"+encodeURIComponent(a),label:r}}}},blocks(n){const t=l("e.g. score-banner");return{rows:[["Name",t,'Lowercase letters, numbers and hyphens. Embed with [block name="\u2026"].']],note:"Creates a placeholder block tagged to this project \u2014 edit its HTML in the editor.",async submit(){const e=d(t.value);if(!e||!/^[a-z0-9][a-z0-9-]*$/.test(e))throw new Error("Name must be lowercase letters, numbers and hyphens.");return await g.blocks.put(e,{content:`<!-- ${e} -->
|
|
2
|
-
`,meta:{project:n.slug}}),{editorHash:"#/blocks/edit/"+encodeURIComponent(e),label:e}}}}};export function openQuickCreate({type:n,project:t,onCreated:e}){const r=k[n];if(!r)return;const a=r(t),o=C[n],f=E.slideover({title:`New ${o}`,size:"lg",position:"right"}),i=document.createElement("div");i.style.cssText="display:flex;flex-direction:column;gap:1rem;padding:1.25rem;";const h=document.createElement("p");if(h.style.cssText="margin:0;color:var(--text-muted,#888);font-size:.9rem;",h.innerHTML=`Filed under <strong>${L(t.name||t.slug)}</strong>.`,i.appendChild(h),a.rows.forEach(([s,c,w])=>i.appendChild(T(s,c,w))),a.note){const s=document.createElement("p");s.style.cssText="margin:0;color:var(--text-muted,#888);font-size:.82rem;",s.textContent=a.note,i.appendChild(s)}const u=document.createElement("div");u.style.cssText="display:flex;gap:.5rem;flex-wrap:wrap;padding-top:.75rem;border-top:1px solid var(--border
|
|
1
|
+
import{api as g}from"../api.js";const C={pages:"Page",collections:"Collection",menus:"Menu",blocks:"Block"};export const INLINE_TYPES=Object.keys(C);function d(n){return String(n||"").toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function L(n){return String(n??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function l(n,t=""){const e=document.createElement("input");return e.type="text",e.className="form-input",e.placeholder=n,e.value=t,e}function T(n,t,e){const r=document.createElement("div");r.style.cssText="display:flex;flex-direction:column;gap:.35rem;";const a=document.createElement("label");if(a.className="form-label",a.textContent=n,r.appendChild(a),r.appendChild(t),e){const o=document.createElement("small");o.style.cssText="color:var(--dm-text-muted,#888);font-size:.78rem;",o.textContent=e,r.appendChild(o)}return r}function x(n,t){const e=document.createElement("button");return e.type="button",e.className=t,e.textContent=n,e}function v(n,t,e=""){let r=!1;t.addEventListener("input",()=>{r=!0}),n.addEventListener("input",()=>{r||(t.value=e+d(n.value))})}const k={pages(n){const t=l("e.g. Squad List"),e=(n.rootUrl||"").replace(/\/+$/,""),r=l(e?`${e}/squad-list`:"/squad-list");return v(t,r,e+"/"),{rows:[["Title",t,"Shown as the page heading and in the pages list."],["URL path",r,e?`Keeping it under ${e}/ files the page in this project automatically.`:"Where the page lives, e.g. /squad-list."]],async submit(){const a=t.value.trim();if(!a)throw new Error("Title is required.");let o=r.value.trim()||"/"+d(a);return o.startsWith("/")||(o="/"+o),await g.pages.create({urlPath:o,frontmatter:{title:a,project:n.slug},body:""}),{editorHash:"#/pages/edit"+o,label:a}}}},collections(n){const t=l("e.g. Players"),e=l("players");return v(t,e),{rows:[["Title",t,"Display name for the collection."],["Slug",e,"Used in URLs and the API. Lowercase letters, numbers and hyphens."]],note:"Creates an empty collection tagged to this project \u2014 add fields in the editor.",async submit(){const r=t.value.trim();if(!r)throw new Error("Title is required.");const a=d(e.value||r);if(!a)throw new Error("A valid slug is required.");return await g.collections.create({title:r,slug:a,fields:[],meta:{project:n.slug}}),{editorHash:"#/collections/edit/"+encodeURIComponent(a),label:r}}}},menus(n){const t=l("e.g. Tournament Nav"),e=l("tournament-nav");return v(t,e),{rows:[["Name",t,"Display name for the menu."],["Slug",e,'Referenced by [menu slug="\u2026"] and menu locations.']],note:"Creates an empty menu tagged to this project \u2014 add items in the editor.",async submit(){const r=t.value.trim();if(!r)throw new Error("Name is required.");const a=d(e.value||r);if(!a)throw new Error("A valid slug is required.");return await g.menus.create({slug:a,name:r,items:[],meta:{project:n.slug}}),{editorHash:"#/menus/edit/"+encodeURIComponent(a),label:r}}}},blocks(n){const t=l("e.g. score-banner");return{rows:[["Name",t,'Lowercase letters, numbers and hyphens. Embed with [block name="\u2026"].']],note:"Creates a placeholder block tagged to this project \u2014 edit its HTML in the editor.",async submit(){const e=d(t.value);if(!e||!/^[a-z0-9][a-z0-9-]*$/.test(e))throw new Error("Name must be lowercase letters, numbers and hyphens.");return await g.blocks.put(e,{content:`<!-- ${e} -->
|
|
2
|
+
`,meta:{project:n.slug}}),{editorHash:"#/blocks/edit/"+encodeURIComponent(e),label:e}}}}};export function openQuickCreate({type:n,project:t,onCreated:e}){const r=k[n];if(!r)return;const a=r(t),o=C[n],f=E.slideover({title:`New ${o}`,size:"lg",position:"right"}),i=document.createElement("div");i.style.cssText="display:flex;flex-direction:column;gap:1rem;padding:1.25rem;";const h=document.createElement("p");if(h.style.cssText="margin:0;color:var(--dm-text-muted,#888);font-size:.9rem;",h.innerHTML=`Filed under <strong>${L(t.name||t.slug)}</strong>.`,i.appendChild(h),a.rows.forEach(([s,c,w])=>i.appendChild(T(s,c,w))),a.note){const s=document.createElement("p");s.style.cssText="margin:0;color:var(--dm-text-muted,#888);font-size:.82rem;",s.textContent=a.note,i.appendChild(s)}const u=document.createElement("div");u.style.cssText="display:flex;gap:.5rem;flex-wrap:wrap;padding-top:.75rem;border-top:1px solid var(--dm-border,rgba(255,255,255,.1));";const m=x("Create","btn btn-primary"),p=x("Create & edit","btn btn-secondary");u.appendChild(m),u.appendChild(p),i.appendChild(u);let b=!1;async function y(s){if(!b){b=!0,m.disabled=p.disabled=!0;try{const{editorHash:c,label:w}=await a.submit();E.toast(`${o} \u201C${w}\u201D created.`,{type:"success"}),f.close(),typeof e=="function"&&await e(),s&&c&&(location.hash=c)}catch(c){E.toast(c?.message||`Failed to create ${o.toLowerCase()}.`,{type:"error"}),b=!1,m.disabled=p.disabled=!1}}}m.addEventListener("click",()=>y(!1)),p.addEventListener("click",()=>y(!0)),i.addEventListener("keydown",s=>{s.key==="Enter"&&s.target.tagName==="INPUT"&&(s.preventDefault(),y(!1))}),f.setContent(i),f.open(),setTimeout(()=>{const s=i.querySelector("input");s&&s.focus()},60)}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{insertAtCursor as se}from"./markdown-toolbar.js";const le=20,V={render:{label:"Render",icon:"edit-3",color:"#3b82f6"},wait:{label:"Wait",icon:"clock",color:"#f59e0b"},undo:{label:"Undo",icon:"corner-up-left",color:"#a855f7"},redraw:{label:"Redraw",icon:"refresh-cw",color:"#22c55e"}},T="padding:.4rem .6rem;background:var(--dm-input-bg,#1a1a1a);border:1px solid var(--dm-border,#333);border-radius:4px;color:var(--dm-text,#eee);font-size:.9em;box-sizing:border-box;width:100%;",ce="display:block;font-size:.7rem;font-weight:600;color:var(--dm-text-muted,#aaa);text-transform:uppercase;letter-spacing:.05em;margin-bottom:.25rem;",de="display:flex;align-items:center;gap:.5rem;cursor:pointer;font-size:.85em;";export function openScribeComposer(n){const r=ae(),e=[];let o=null;const u=E.slideover({title:"Scribe Composer",size:"lg",position:"right"});be();const b=document.createElement("div");b.className="scribe-composer",b.style.cssText="display:flex;flex-direction:column;height:100%;";const y=document.createElement("div");y.style.cssText="padding:1rem 1.25rem;border-bottom:1px solid var(--dm-border,#333);background:var(--dm-surface-subtle,#0f0f17);";const g=document.createElement("div");g.style.cssText="min-height:3.5rem;padding:.85rem 1rem;background:var(--dm-surface,#1a1a1a);border:1px dashed var(--dm-border,#333);border-radius:6px;font-size:1.25rem;line-height:1.5;overflow-wrap:anywhere;",y.appendChild(g);const w=document.createElement("div");w.style.cssText="display:flex;gap:.5rem;margin-top:.75rem;align-items:center;";const $=ee("rotate-cw","Replay"),B=ee("code","Show code"),k=document.createElement("span");k.style.cssText="font-size:.8em;color:var(--dm-text-muted,#aaa);flex:1;text-align:right;margin-right:.5rem;",w.appendChild($),w.appendChild(k),w.appendChild(B),y.appendChild(w);const p=document.createElement("pre");p.style.cssText="display:none;margin:.75rem 0 0;padding:.6rem .75rem;background:var(--dm-surface,#0a0a0a);border:1px solid var(--dm-border,#333);border-radius:4px;font-family:monospace;font-size:.78em;white-space:pre-wrap;word-break:break-all;color:var(--dm-text-muted,#bbb);max-height:200px;overflow:auto;",y.appendChild(p),B.addEventListener("click",()=>{const t=p.style.display!=="none";p.style.display=t?"none":"block"}),$.addEventListener("click",()=>X()),b.appendChild(y);const R=document.createElement("div");R.style.cssText="display:flex;flex:1;min-height:0;overflow:hidden;";const F=ue(r,()=>{v(),x()});R.appendChild(F.el);const M=document.createElement("main");M.style.cssText="flex:1;overflow-y:auto;padding:1rem 1.25rem;display:flex;flex-direction:column;";const W=document.createElement("h4");W.textContent="Actions",W.style.cssText="margin:0 0 .75rem;font-size:.75rem;font-weight:700;text-transform:uppercase;letter-spacing:.08em;color:var(--dm-text-muted,#aaa);",M.appendChild(W);const z=document.createElement("div");z.style.cssText="display:flex;flex-direction:column;gap:.6rem;",M.appendChild(z);const H=document.createElement("div");H.style.cssText="display:flex;gap:.4rem;margin-top:.9rem;flex-wrap:wrap;",Object.entries(V).forEach(([t,s])=>{const l=document.createElement("button");l.type="button",l.style.cssText=`padding:.4rem .8rem;background:transparent;border:1px dashed ${s.color}66;border-radius:4px;color:${s.color};cursor:pointer;font-size:.85em;display:inline-flex;align-items:center;gap:.35rem;`;const a=document.createElement("span");a.setAttribute("data-icon",s.icon),l.appendChild(a),l.appendChild(document.createTextNode(` + ${s.label}`)),l.addEventListener("click",()=>{v(),r.actions.push(ie(t)),j(),x()}),H.appendChild(l)}),M.appendChild(H),R.appendChild(M),b.appendChild(R);const L=document.createElement("div");L.style.cssText="display:flex;padding:.75rem 1rem;border-top:1px solid var(--dm-border,#333);background:var(--dm-surface-subtle,#0f0f17);gap:.5rem;align-items:center;";const S=document.createElement("button");S.type="button",S.className="btn btn-ghost btn-sm",S.textContent="Undo (Ctrl+Z)",S.addEventListener("click",()=>J()),L.appendChild(S);const U=document.createElement("span");U.style.cssText="font-size:.75em;color:var(--dm-text-muted,#aaa);",L.appendChild(U);const G=document.createElement("div");G.style.flex="1",L.appendChild(G);const A=document.createElement("button");A.type="button",A.className="btn btn-ghost",A.textContent="Cancel",A.addEventListener("click",()=>u.close()),L.appendChild(A);const D=document.createElement("button");D.type="button",D.className="btn btn-primary",D.textContent="Insert Scribe",D.addEventListener("click",()=>{se(n,Q()),u.close()}),L.appendChild(D),b.appendChild(L),u.setContent(b),b.addEventListener("keydown",t=>{const s=(t.key||"").toLowerCase();(t.ctrlKey||t.metaKey)&&s==="z"&&!t.shiftKey&&e.length>0&&(t.preventDefault(),t.stopPropagation(),J())}),j(),x(),P(),requestAnimationFrame(()=>{Domma.icons.scan()}),u.open();function v(){e.push(JSON.stringify(r)),e.length>le&&e.shift(),P()}function J(){if(e.length===0){E.toast("Nothing to undo",{type:"info",duration:700});return}const t=JSON.parse(e.pop());Object.assign(r.globals,t.globals),r.actions.length=0,t.actions.forEach(s=>r.actions.push(s)),F.sync(),j(),x(),P(),E.toast("Undone",{type:"info",duration:500})}function P(){U.textContent=e.length===0?"":`${e.length} step${e.length===1?"":"s"} stored`,S.disabled=e.length===0,S.style.opacity=e.length===0?".4":"1"}function x(t=150){clearTimeout(o),o=setTimeout(X,t)}function X(){te(g),g.style.color="",g.style.fontStyle="",p.textContent=Q();const t=r.actions.filter(c=>c.type==="render"||c.type==="redraw"?(c.text||"").length>0:!0);if(t.length===0){g.textContent="(add an action to preview)",g.style.color="var(--dm-text-muted,#666)",g.style.fontStyle="italic",k.textContent="";return}const s=document.createElement("span");s.className="dm-fx-scribe",g.appendChild(s);const l=r.globals,a={speed:l.speed,deleteSpeed:l.deleteSpeed,cursor:l.cursor,cursorType:l.cursorType,loop:l.loop,loopDelay:l.loopDelay,pauseOnHover:l.pauseOnHover,actions:pe(t)};l.cursorChar&&(a.cursorChar=l.cursorChar);try{E.scribe(s,a),k.textContent=`${t.length} action${t.length===1?"":"s"}`}catch{k.textContent="Preview error"}}function j(){if(te(z),r.actions.length===0){const t=document.createElement("p");t.textContent="No actions yet \u2014 add one from the buttons below.",t.style.cssText="font-size:.85em;color:var(--dm-text-muted,#888);font-style:italic;margin:.5rem 0;",z.appendChild(t);return}r.actions.forEach((t,s)=>{z.appendChild(oe(t,s))}),requestAnimationFrame(()=>Domma.icons.scan())}function oe(t,s){const l=V[t.type],a=document.createElement("div");a.style.cssText=`border:1px solid var(--dm-border,#333);border-left:3px solid ${l.color};border-radius:4px;padding:.6rem .75rem;background:var(--dm-surface,#15151a);`;const c=document.createElement("div");c.style.cssText="display:flex;align-items:center;gap:.5rem;margin-bottom:.5rem;";const N=document.createElement("span");N.style.cssText=`display:inline-flex;align-items:center;gap:.3rem;font-size:.72rem;font-weight:700;color:${l.color};text-transform:uppercase;letter-spacing:.06em;`;const d=document.createElement("span");d.setAttribute("data-icon",l.icon),N.appendChild(d),N.appendChild(document.createTextNode(l.label)),c.appendChild(N);const f=document.createElement("span");f.textContent=`#${s+1}`,f.style.cssText="font-size:.7rem;color:var(--dm-text-muted,#888);",c.appendChild(f);const m=document.createElement("div");m.style.flex="1",c.appendChild(m);const i=q("chevron-up","Move up");s===0&&(i.disabled=!0,i.style.opacity=".3"),i.addEventListener("click",()=>Z(s,-1)),c.appendChild(i);const h=q("chevron-down","Move down");s===r.actions.length-1&&(h.disabled=!0,h.style.opacity=".3"),h.addEventListener("click",()=>Z(s,1)),c.appendChild(h);const C=q("x","Remove");return C.addEventListener("click",()=>{v(),r.actions.splice(s,1),j(),x()}),c.appendChild(C),a.appendChild(c),a.appendChild(re(t)),a}function Z(t,s){const l=t+s;if(l<0||l>=r.actions.length)return;v();const[a]=r.actions.splice(t,1);r.actions.splice(l,0,a),j(),x()}function re(t){const s=document.createElement("div");if(s.style.cssText="display:flex;flex-direction:column;gap:.5rem;",t.type==="render"||t.type==="redraw"){const d=document.createElement("textarea");d.value=t.text||"",d.placeholder=t.type==="redraw"?"New text \u2014 clears everything first, then types this":"Text to type out",d.rows=2,d.style.cssText=T+"resize:vertical;font-family:inherit;min-height:2.2rem;";let f=d.value;d.addEventListener("input",()=>{t.text=d.value,x()}),d.addEventListener("blur",()=>{d.value!==f&&(v(),f=d.value)}),s.appendChild(d);const m=document.createElement("div");m.style.cssText="display:flex;align-items:center;gap:.5rem;font-size:.8em;";const i=document.createElement("label");i.textContent="Effect:",i.style.color="var(--dm-text-muted,#aaa)";const h=document.createElement("select");return h.style.cssText=T+"width:auto;padding:.25rem .4rem;",["none","fade","bounce","glow"].forEach(C=>{const _=document.createElement("option");_.value=C,_.textContent=C.charAt(0).toUpperCase()+C.slice(1),h.appendChild(_)}),h.value=t.effect||"none",h.addEventListener("change",()=>{v(),t.effect=h.value,x()}),m.appendChild(i),m.appendChild(h),s.appendChild(m),s}if(t.type==="wait"){const d=document.createElement("div");d.style.cssText="display:flex;gap:.4rem;align-items:center;";const f=document.createElement("input");f.type="number",f.min="0",f.value=String(t.duration??1e3),f.style.cssText=T+"flex:1;",f.addEventListener("input",()=>{const i=parseInt(f.value,10);!Number.isNaN(i)&&i>=0&&(t.duration=i,x())}),f.addEventListener("blur",()=>v()),d.appendChild(f);const m=document.createElement("select");return m.style.cssText=T+"width:auto;",[["ms","ms"],["s","seconds"]].forEach(([i,h])=>{const C=document.createElement("option");C.value=i,C.textContent=h,m.appendChild(C)}),m.value=t.unit||"ms",m.addEventListener("change",()=>{v(),t.unit=m.value,x()}),d.appendChild(m),s.appendChild(d),s}const l=document.createElement("div");l.style.cssText="display:flex;gap:.75rem;align-items:center;flex-wrap:wrap;font-size:.85em;";const a=document.createElement("input");a.type="number",a.min="1",a.value=String(t.count||5),a.style.cssText=T+"width:5rem;",a.addEventListener("input",()=>{const d=parseInt(a.value,10);!Number.isNaN(d)&&d>0&&(t.count=d,x())}),a.addEventListener("blur",()=>v());const c=`undo-mode-${Math.random().toString(36).slice(2)}`;return[["last","Last render"],["all","All text"],["count","Exactly N chars"]].forEach(([d,f])=>{const m=document.createElement("label");m.style.cssText="display:inline-flex;align-items:center;gap:.3rem;cursor:pointer;";const i=document.createElement("input");i.type="radio",i.name=c,i.value=d,i.checked=(t.mode||"last")===d,i.addEventListener("change",()=>{i.checked&&(v(),t.mode=d,a.style.display=d==="count"?"":"none",x())}),m.appendChild(i),m.appendChild(document.createTextNode(f)),l.appendChild(m),d==="count"&&(l.appendChild(a),a.style.display=(t.mode||"last")==="count"?"":"none")}),s.appendChild(l),s}function Q(){const t=r.globals,s=[];t.speed!==50&&s.push(`speed="${t.speed}"`),t.deleteSpeed!==30&&s.push(`delete-speed="${t.deleteSpeed}"`),t.cursor?(t.cursorType!=="caret"&&s.push(`cursor-type="${t.cursorType}"`),t.cursorChar&&s.push(`cursor-char="${he(t.cursorChar)}"`)):s.push('cursor="false"'),t.loop&&(s.push('loop="true"'),t.loopDelay!==1e3&&s.push(`loop-delay="${t.loopDelay}"`)),t.pauseOnHover&&s.push('pause-on-hover="true"');const l=s.length?" "+s.join(" "):"",a=r.actions.map(c=>c.type==="render"?`[render${c.effect&&c.effect!=="none"?` effect="${c.effect}"`:""}]${c.text||""}[/render]`:c.type==="redraw"?`[redraw${c.effect&&c.effect!=="none"?` effect="${c.effect}"`:""}]${c.text||""}[/redraw]`:c.type==="wait"?`[wait]${c.duration}${c.unit==="s"?"s":""}[/wait]`:c.mode==="all"?'[undo all="true" /]':c.mode==="count"?`[undo count="${c.count}" /]`:"[undo /]");return`[scribe${l}]
|
|
2
|
-
${
|
|
1
|
+
import{insertAtCursor as se}from"./markdown-toolbar.js";const le=20,V={render:{label:"Render",icon:"edit-3",color:"var(--dm-info,#3b82f6)"},wait:{label:"Wait",icon:"clock",color:"var(--dm-warning,#f59e0b)"},undo:{label:"Undo",icon:"corner-up-left",color:"var(--dm-secondary,#a855f7)"},redraw:{label:"Redraw",icon:"refresh-cw",color:"var(--dm-success,#22c55e)"}},T="padding:.4rem .6rem;background:var(--dm-input-bg,#1a1a1a);border:1px solid var(--dm-border,#333);border-radius:4px;color:var(--dm-text,#eee);font-size:.9em;box-sizing:border-box;width:100%;",ce="display:block;font-size:.7rem;font-weight:600;color:var(--dm-text-muted,#aaa);text-transform:uppercase;letter-spacing:.05em;margin-bottom:.25rem;",ae="display:flex;align-items:center;gap:.5rem;cursor:pointer;font-size:.85em;";export function openScribeComposer(n){const r=de(),e=[];let o=null;const u=E.slideover({title:"Scribe Composer",size:"lg",position:"right"});be();const b=document.createElement("div");b.className="scribe-composer",b.style.cssText="display:flex;flex-direction:column;height:100%;";const y=document.createElement("div");y.style.cssText="padding:1rem 1.25rem;border-bottom:1px solid var(--dm-border,#333);background:var(--dm-background-alt,#0f0f17);";const g=document.createElement("div");g.style.cssText="min-height:3.5rem;padding:.85rem 1rem;background:var(--dm-surface,#1a1a1a);border:1px dashed var(--dm-border,#333);border-radius:6px;font-size:1.25rem;line-height:1.5;overflow-wrap:anywhere;",y.appendChild(g);const w=document.createElement("div");w.style.cssText="display:flex;gap:.5rem;margin-top:.75rem;align-items:center;";const $=ee("rotate-cw","Replay"),B=ee("code","Show code"),k=document.createElement("span");k.style.cssText="font-size:.8em;color:var(--dm-text-muted,#aaa);flex:1;text-align:right;margin-right:.5rem;",w.appendChild($),w.appendChild(k),w.appendChild(B),y.appendChild(w);const p=document.createElement("pre");p.style.cssText="display:none;margin:.75rem 0 0;padding:.6rem .75rem;background:var(--dm-surface,#0a0a0a);border:1px solid var(--dm-border,#333);border-radius:4px;font-family:monospace;font-size:.78em;white-space:pre-wrap;word-break:break-all;color:var(--dm-text-muted,#bbb);max-height:200px;overflow:auto;",y.appendChild(p),B.addEventListener("click",()=>{const t=p.style.display!=="none";p.style.display=t?"none":"block"}),$.addEventListener("click",()=>X()),b.appendChild(y);const R=document.createElement("div");R.style.cssText="display:flex;flex:1;min-height:0;overflow:hidden;";const F=ue(r,()=>{v(),x()});R.appendChild(F.el);const M=document.createElement("main");M.style.cssText="flex:1;overflow-y:auto;padding:1rem 1.25rem;display:flex;flex-direction:column;";const W=document.createElement("h4");W.textContent="Actions",W.style.cssText="margin:0 0 .75rem;font-size:.75rem;font-weight:700;text-transform:uppercase;letter-spacing:.08em;color:var(--dm-text-muted,#aaa);",M.appendChild(W);const z=document.createElement("div");z.style.cssText="display:flex;flex-direction:column;gap:.6rem;",M.appendChild(z);const H=document.createElement("div");H.style.cssText="display:flex;gap:.4rem;margin-top:.9rem;flex-wrap:wrap;",Object.entries(V).forEach(([t,s])=>{const l=document.createElement("button");l.type="button",l.style.cssText=`padding:.4rem .8rem;background:transparent;border:1px dashed color-mix(in srgb, ${s.color} 40%, transparent);border-radius:4px;color:${s.color};cursor:pointer;font-size:.85em;display:inline-flex;align-items:center;gap:.35rem;`;const d=document.createElement("span");d.setAttribute("data-icon",s.icon),l.appendChild(d),l.appendChild(document.createTextNode(` + ${s.label}`)),l.addEventListener("click",()=>{v(),r.actions.push(ie(t)),j(),x()}),H.appendChild(l)}),M.appendChild(H),R.appendChild(M),b.appendChild(R);const L=document.createElement("div");L.style.cssText="display:flex;padding:.75rem 1rem;border-top:1px solid var(--dm-border,#333);background:var(--dm-background-alt,#0f0f17);gap:.5rem;align-items:center;";const S=document.createElement("button");S.type="button",S.className="btn btn-ghost btn-sm",S.textContent="Undo (Ctrl+Z)",S.addEventListener("click",()=>J()),L.appendChild(S);const U=document.createElement("span");U.style.cssText="font-size:.75em;color:var(--dm-text-muted,#aaa);",L.appendChild(U);const G=document.createElement("div");G.style.flex="1",L.appendChild(G);const A=document.createElement("button");A.type="button",A.className="btn btn-ghost",A.textContent="Cancel",A.addEventListener("click",()=>u.close()),L.appendChild(A);const D=document.createElement("button");D.type="button",D.className="btn btn-primary",D.textContent="Insert Scribe",D.addEventListener("click",()=>{se(n,Q()),u.close()}),L.appendChild(D),b.appendChild(L),u.setContent(b),b.addEventListener("keydown",t=>{const s=(t.key||"").toLowerCase();(t.ctrlKey||t.metaKey)&&s==="z"&&!t.shiftKey&&e.length>0&&(t.preventDefault(),t.stopPropagation(),J())}),j(),x(),P(),requestAnimationFrame(()=>{Domma.icons.scan()}),u.open();function v(){e.push(JSON.stringify(r)),e.length>le&&e.shift(),P()}function J(){if(e.length===0){E.toast("Nothing to undo",{type:"info",duration:700});return}const t=JSON.parse(e.pop());Object.assign(r.globals,t.globals),r.actions.length=0,t.actions.forEach(s=>r.actions.push(s)),F.sync(),j(),x(),P(),E.toast("Undone",{type:"info",duration:500})}function P(){U.textContent=e.length===0?"":`${e.length} step${e.length===1?"":"s"} stored`,S.disabled=e.length===0,S.style.opacity=e.length===0?".4":"1"}function x(t=150){clearTimeout(o),o=setTimeout(X,t)}function X(){te(g),g.style.color="",g.style.fontStyle="",p.textContent=Q();const t=r.actions.filter(c=>c.type==="render"||c.type==="redraw"?(c.text||"").length>0:!0);if(t.length===0){g.textContent="(add an action to preview)",g.style.color="var(--dm-text-muted,#666)",g.style.fontStyle="italic",k.textContent="";return}const s=document.createElement("span");s.className="dm-fx-scribe",g.appendChild(s);const l=r.globals,d={speed:l.speed,deleteSpeed:l.deleteSpeed,cursor:l.cursor,cursorType:l.cursorType,loop:l.loop,loopDelay:l.loopDelay,pauseOnHover:l.pauseOnHover,actions:pe(t)};l.cursorChar&&(d.cursorChar=l.cursorChar);try{E.scribe(s,d),k.textContent=`${t.length} action${t.length===1?"":"s"}`}catch{k.textContent="Preview error"}}function j(){if(te(z),r.actions.length===0){const t=document.createElement("p");t.textContent="No actions yet \u2014 add one from the buttons below.",t.style.cssText="font-size:.85em;color:var(--dm-text-muted,#888);font-style:italic;margin:.5rem 0;",z.appendChild(t);return}r.actions.forEach((t,s)=>{z.appendChild(oe(t,s))}),requestAnimationFrame(()=>Domma.icons.scan())}function oe(t,s){const l=V[t.type],d=document.createElement("div");d.style.cssText=`border:1px solid var(--dm-border,#333);border-left:3px solid ${l.color};border-radius:4px;padding:.6rem .75rem;background:var(--dm-surface,#15151a);`;const c=document.createElement("div");c.style.cssText="display:flex;align-items:center;gap:.5rem;margin-bottom:.5rem;";const N=document.createElement("span");N.style.cssText=`display:inline-flex;align-items:center;gap:.3rem;font-size:.72rem;font-weight:700;color:${l.color};text-transform:uppercase;letter-spacing:.06em;`;const a=document.createElement("span");a.setAttribute("data-icon",l.icon),N.appendChild(a),N.appendChild(document.createTextNode(l.label)),c.appendChild(N);const f=document.createElement("span");f.textContent=`#${s+1}`,f.style.cssText="font-size:.7rem;color:var(--dm-text-muted,#888);",c.appendChild(f);const m=document.createElement("div");m.style.flex="1",c.appendChild(m);const i=q("chevron-up","Move up");s===0&&(i.disabled=!0,i.style.opacity=".3"),i.addEventListener("click",()=>Z(s,-1)),c.appendChild(i);const h=q("chevron-down","Move down");s===r.actions.length-1&&(h.disabled=!0,h.style.opacity=".3"),h.addEventListener("click",()=>Z(s,1)),c.appendChild(h);const C=q("x","Remove");return C.addEventListener("click",()=>{v(),r.actions.splice(s,1),j(),x()}),c.appendChild(C),d.appendChild(c),d.appendChild(re(t)),d}function Z(t,s){const l=t+s;if(l<0||l>=r.actions.length)return;v();const[d]=r.actions.splice(t,1);r.actions.splice(l,0,d),j(),x()}function re(t){const s=document.createElement("div");if(s.style.cssText="display:flex;flex-direction:column;gap:.5rem;",t.type==="render"||t.type==="redraw"){const a=document.createElement("textarea");a.value=t.text||"",a.placeholder=t.type==="redraw"?"New text \u2014 clears everything first, then types this":"Text to type out",a.rows=2,a.style.cssText=T+"resize:vertical;font-family:inherit;min-height:2.2rem;";let f=a.value;a.addEventListener("input",()=>{t.text=a.value,x()}),a.addEventListener("blur",()=>{a.value!==f&&(v(),f=a.value)}),s.appendChild(a);const m=document.createElement("div");m.style.cssText="display:flex;align-items:center;gap:.5rem;font-size:.8em;";const i=document.createElement("label");i.textContent="Effect:",i.style.color="var(--dm-text-muted,#aaa)";const h=document.createElement("select");return h.style.cssText=T+"width:auto;padding:.25rem .4rem;",["none","fade","bounce","glow"].forEach(C=>{const _=document.createElement("option");_.value=C,_.textContent=C.charAt(0).toUpperCase()+C.slice(1),h.appendChild(_)}),h.value=t.effect||"none",h.addEventListener("change",()=>{v(),t.effect=h.value,x()}),m.appendChild(i),m.appendChild(h),s.appendChild(m),s}if(t.type==="wait"){const a=document.createElement("div");a.style.cssText="display:flex;gap:.4rem;align-items:center;";const f=document.createElement("input");f.type="number",f.min="0",f.value=String(t.duration??1e3),f.style.cssText=T+"flex:1;",f.addEventListener("input",()=>{const i=parseInt(f.value,10);!Number.isNaN(i)&&i>=0&&(t.duration=i,x())}),f.addEventListener("blur",()=>v()),a.appendChild(f);const m=document.createElement("select");return m.style.cssText=T+"width:auto;",[["ms","ms"],["s","seconds"]].forEach(([i,h])=>{const C=document.createElement("option");C.value=i,C.textContent=h,m.appendChild(C)}),m.value=t.unit||"ms",m.addEventListener("change",()=>{v(),t.unit=m.value,x()}),a.appendChild(m),s.appendChild(a),s}const l=document.createElement("div");l.style.cssText="display:flex;gap:.75rem;align-items:center;flex-wrap:wrap;font-size:.85em;";const d=document.createElement("input");d.type="number",d.min="1",d.value=String(t.count||5),d.style.cssText=T+"width:5rem;",d.addEventListener("input",()=>{const a=parseInt(d.value,10);!Number.isNaN(a)&&a>0&&(t.count=a,x())}),d.addEventListener("blur",()=>v());const c=`undo-mode-${Math.random().toString(36).slice(2)}`;return[["last","Last render"],["all","All text"],["count","Exactly N chars"]].forEach(([a,f])=>{const m=document.createElement("label");m.style.cssText="display:inline-flex;align-items:center;gap:.3rem;cursor:pointer;";const i=document.createElement("input");i.type="radio",i.name=c,i.value=a,i.checked=(t.mode||"last")===a,i.addEventListener("change",()=>{i.checked&&(v(),t.mode=a,d.style.display=a==="count"?"":"none",x())}),m.appendChild(i),m.appendChild(document.createTextNode(f)),l.appendChild(m),a==="count"&&(l.appendChild(d),d.style.display=(t.mode||"last")==="count"?"":"none")}),s.appendChild(l),s}function Q(){const t=r.globals,s=[];t.speed!==50&&s.push(`speed="${t.speed}"`),t.deleteSpeed!==30&&s.push(`delete-speed="${t.deleteSpeed}"`),t.cursor?(t.cursorType!=="caret"&&s.push(`cursor-type="${t.cursorType}"`),t.cursorChar&&s.push(`cursor-char="${he(t.cursorChar)}"`)):s.push('cursor="false"'),t.loop&&(s.push('loop="true"'),t.loopDelay!==1e3&&s.push(`loop-delay="${t.loopDelay}"`)),t.pauseOnHover&&s.push('pause-on-hover="true"');const l=s.length?" "+s.join(" "):"",d=r.actions.map(c=>c.type==="render"?`[render${c.effect&&c.effect!=="none"?` effect="${c.effect}"`:""}]${c.text||""}[/render]`:c.type==="redraw"?`[redraw${c.effect&&c.effect!=="none"?` effect="${c.effect}"`:""}]${c.text||""}[/redraw]`:c.type==="wait"?`[wait]${c.duration}${c.unit==="s"?"s":""}[/wait]`:c.mode==="all"?'[undo all="true" /]':c.mode==="count"?`[undo count="${c.count}" /]`:"[undo /]");return`[scribe${l}]
|
|
2
|
+
${d.join(`
|
|
3
3
|
`)}
|
|
4
|
-
[/scribe]`}}function
|
|
4
|
+
[/scribe]`}}function de(){return{globals:{speed:50,deleteSpeed:30,cursor:!0,cursorType:"caret",cursorChar:"",loop:!1,loopDelay:1e3,pauseOnHover:!1},actions:[{type:"render",text:"We build things that matter.",effect:"none"},{type:"wait",duration:1500,unit:"ms"},{type:"redraw",text:"We create solutions that last.",effect:"none"},{type:"wait",duration:1500,unit:"ms"}]}}function ie(n){switch(n){case"render":return{type:"render",text:"",effect:"none"};case"wait":return{type:"wait",duration:1e3,unit:"ms"};case"undo":return{type:"undo",mode:"last",count:5};case"redraw":return{type:"redraw",text:"",effect:"none"}}return{type:"render",text:"",effect:"none"}}function pe(n){const r=[];return n.forEach(e=>{if(e.type==="render"){const o={render:e.text||""};e.effect&&e.effect!=="none"&&(o.effect=e.effect),r.push(o)}else if(e.type==="redraw"){r.push({undoRender:"all"});const o={render:e.text||""};e.effect&&e.effect!=="none"&&(o.effect=e.effect),r.push(o)}else e.type==="wait"?r.push({wait:e.unit==="s"?(e.duration||0)*1e3:e.duration||0}):e.type==="undo"&&(e.mode==="all"?r.push({undoRender:"all"}):e.mode==="count"?r.push({undoRender:e.count}):r.push({undoRender:!0}))}),r}function ue(n,r){const e=document.createElement("aside");e.style.cssText="width:240px;flex-shrink:0;padding:1rem 1.25rem;border-right:1px solid var(--dm-border,#333);overflow-y:auto;display:flex;flex-direction:column;gap:.75rem;background:var(--dm-background-alt,#0c0c12);";const o=document.createElement("h4");o.textContent="Global settings",o.style.cssText="margin:0 0 .25rem;font-size:.75rem;font-weight:700;text-transform:uppercase;letter-spacing:.08em;color:var(--dm-text-muted,#aaa);",e.appendChild(o);const u=K(n.globals.speed,p=>{n.globals.speed=p,r()}),b=K(n.globals.deleteSpeed,p=>{n.globals.deleteSpeed=p,r()}),y=Y(n.globals.cursor,p=>{n.globals.cursor=p,r()},"Show cursor"),g=fe([["caret","Caret (|)"],["block","Block (\u2588)"],["underline","Underline (_)"]],n.globals.cursorType,p=>{n.globals.cursorType=p,r()}),w=me(n.globals.cursorChar,"\u258C (optional override)",p=>{n.globals.cursorChar=p,r()}),$=Y(n.globals.loop,p=>{n.globals.loop=p,r()},"Loop forever"),B=K(n.globals.loopDelay,p=>{n.globals.loopDelay=p,r()},0),k=Y(n.globals.pauseOnHover,p=>{n.globals.pauseOnHover=p,r()},"Pause on hover");return e.appendChild(O("Speed (ms / char)",u)),e.appendChild(O("Delete speed (ms / char)",b)),e.appendChild(y.wrap),e.appendChild(O("Cursor style",g)),e.appendChild(O("Custom cursor char",w)),e.appendChild($.wrap),e.appendChild(O("Loop delay (ms)",B)),e.appendChild(k.wrap),{el:e,sync(){u.value=String(n.globals.speed),b.value=String(n.globals.deleteSpeed),y.input.checked=n.globals.cursor,g.value=n.globals.cursorType,w.value=n.globals.cursorChar,$.input.checked=n.globals.loop,B.value=String(n.globals.loopDelay),k.input.checked=n.globals.pauseOnHover}}}function O(n,r){const e=document.createElement("div"),o=document.createElement("label");return o.style.cssText=ce,o.textContent=n,e.appendChild(o),e.appendChild(r),e}function K(n,r,e=1){const o=document.createElement("input");return o.type="number",o.min=String(e),o.value=String(n),o.style.cssText=T,o.addEventListener("input",()=>{const u=parseInt(o.value,10);!Number.isNaN(u)&&u>=e&&r(u)}),o}function me(n,r,e){const o=document.createElement("input");return o.type="text",o.value=n,o.placeholder=r,o.style.cssText=T,o.addEventListener("input",()=>e(o.value)),o}function fe(n,r,e){const o=document.createElement("select");return o.style.cssText=T,n.forEach(([u,b])=>{const y=document.createElement("option");y.value=u,y.textContent=b,o.appendChild(y)}),o.value=r,o.addEventListener("change",()=>e(o.value)),o}function Y(n,r,e){const o=document.createElement("label");o.style.cssText=ae;const u=document.createElement("input");return u.type="checkbox",u.checked=n,u.addEventListener("change",()=>r(u.checked)),o.appendChild(u),o.appendChild(document.createTextNode(e)),{wrap:o,input:u}}function ee(n,r){const e=document.createElement("button");e.type="button",e.className="btn btn-ghost btn-sm",e.style.cssText="display:inline-flex;align-items:center;gap:.35rem;";const o=document.createElement("span");return o.setAttribute("data-icon",n),e.appendChild(o),e.appendChild(document.createTextNode(r)),e}function q(n,r){const e=document.createElement("button");e.type="button",e.title=r,e.style.cssText="padding:.25rem .4rem;background:transparent;border:1px solid var(--dm-border,#333);border-radius:3px;color:var(--dm-text-muted,#aaa);cursor:pointer;display:inline-flex;align-items:center;";const o=document.createElement("span");return o.setAttribute("data-icon",n),e.appendChild(o),e}function te(n){for(;n.firstChild;)n.removeChild(n.firstChild)}function he(n){return String(n).replace(/&/g,"&").replace(/"/g,""")}let ne=!1;function be(){ne||(ne=!0,I.register("edit-3",{viewBox:"0 0 24 24",paths:["M12 20h9","M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5z"],stroke:"currentColor",fill:"none",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),I.register("clock",{viewBox:"0 0 24 24",paths:["M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10z","M12 6v6l4 2"],stroke:"currentColor",fill:"none",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),I.register("corner-up-left",{viewBox:"0 0 24 24",paths:["M9 14 4 9l5-5","M20 20v-7a4 4 0 0 0-4-4H4"],stroke:"currentColor",fill:"none",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),I.register("refresh-cw",{viewBox:"0 0 24 24",paths:["M23 4v6h-6","M1 20v-6h6","M3.51 9a9 9 0 0 1 14.85-3.36L23 10","M20.49 15a9 9 0 0 1-14.85 3.36L1 14"],stroke:"currentColor",fill:"none",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),I.register("rotate-cw",{viewBox:"0 0 24 24",paths:["M23 4v6h-6","M20.49 15a9 9 0 1 1-2.12-9.36L23 10"],stroke:"currentColor",fill:"none",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),I.register("code",{viewBox:"0 0 24 24",paths:["M16 18l6-6-6-6","M8 6l-6 6 6 6"],stroke:"currentColor",fill:"none",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),I.register("chevron-up",{viewBox:"0 0 24 24",path:"M18 15l-6-6-6 6",stroke:"currentColor",fill:"none",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),I.register("chevron-down",{viewBox:"0 0 24 24",path:"M6 9l6 6 6-6",stroke:"currentColor",fill:"none",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),I.register("x",{viewBox:"0 0 24 24",paths:["M18 6L6 18","M6 6l12 12"],stroke:"currentColor",fill:"none",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}))}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import{SHORTCODES as f}from"./shortcode-registry.js";import{EFFECTS as p}from"./effect-defs.js";import{findEnclosingShortcode as k,setAttr as
|
|
1
|
+
import{SHORTCODES as f}from"./shortcode-registry.js";import{EFFECTS as p}from"./effect-defs.js";import{findEnclosingShortcode as k,setAttr as g,setAttrs as R,effectAttrKeys as M}from"./shortcode-tags.js";import{insertAtCursor as C,replaceRange as A}from"./markdown-toolbar.js";const N=f.map(e=>({name:e.name,selfClosing:!!e.selfClosing})),D=new Map(f.map(e=>[e.name,e])),P=["Layout","Content","Components","Data","Media","Effects"],Y=new Map(p.map(e=>[e.name,e])),j=p.map(e=>({name:e.name,selfClosing:!!e.selfClosing})),z=[...N,...j],y=new Set(["card","hero","banner","col","button"]);let a=null;const w="position:fixed;z-index:10000;min-width:210px;max-height:70vh;overflow-y:auto;background:var(--dm-surface,#1c1c30);border:1px solid var(--dm-border,#2a2a40);border-radius:6px;box-shadow:var(--dm-shadow-lg);padding:.3rem;font-size:.83rem;color:var(--dm-text,#e5e5e5);",d="display:flex;align-items:center;gap:.5rem;width:100%;text-align:left;padding:.35rem .55rem;border:none;background:transparent;color:inherit;border-radius:4px;cursor:pointer;font-size:.83rem;",F="padding:.3rem .55rem;color:var(--dm-text-muted,#8a8a9a);font-size:.68rem;text-transform:uppercase;letter-spacing:.06em;",O="flex:1;min-width:0;padding:.2rem .4rem;background:var(--dm-input-bg,#12121e);border:1px solid var(--dm-border,#333);border-radius:3px;color:var(--dm-text,#eee);font-size:.8rem;",W="height:1px;background:var(--dm-border,#2a2a40);margin:.3rem .2rem;";function m(e){return e.addEventListener("mouseenter",()=>{e.style.background="var(--dm-primary,#4338ca)",e.style.color="var(--dm-primary-text,#fff)"}),e.addEventListener("mouseleave",()=>{e.style.background="transparent",e.style.color="inherit"}),e}export function attachContextMenu(e){e.addEventListener("contextmenu",t=>{t.preventDefault(),u();const n=k(e,z);H(e,n,t.clientX,t.clientY)})}function u(){a&&(v(),a.root.remove(),document.removeEventListener("mousedown",_,!0),document.removeEventListener("keydown",T,!0),window.removeEventListener("scroll",u,!0),a=null)}const _=e=>{a&&!a.root.contains(e.target)&&!(a.submenu&&a.submenu.contains(e.target))&&u()},T=e=>{e.key==="Escape"&&u()};function H(e,t,n,o){const s=document.createElement("div");s.className="dm-sc-menu",s.style.cssText=w,a={root:s,textarea:e,span:t,submenu:null};const c=t&&(D.get(t.name)||Y.get(t.name)),i=t&&y.has(t.name)?p.filter(l=>l.name in t.attrs):[];c&&K(s,c);for(const l of i)Q(s,l);(c||i.length)&&s.appendChild(B()),s.appendChild(E("Add effect\u2026",()=>Z())),s.appendChild(E("Insert\u2026",()=>ee()));const r=e.selectionStart!==e.selectionEnd;(t||r)&&s.appendChild(E(r?"Wrap selection in\u2026":"Wrap in\u2026",()=>te())),document.body.appendChild(s),$(s,n,o),document.addEventListener("mousedown",_,!0),document.addEventListener("keydown",T,!0),window.addEventListener("scroll",u,!0),window.I&&I.scan(s)}function B(){const e=document.createElement("div");return e.style.cssText=W,e}function h(e){const t=document.createElement("div");return t.style.cssText=F,t.textContent=e,t}function K(e,t){e.appendChild(h(`${t.label} options`));for(const n of t.attrs||[])e.appendChild(S(n))}function S(e,t=e.name){const n=a.span.attrs[t];switch(e.type){case"checkbox":return G(e,t,U(n,e.default));case"select":return J(e,t,n);case"colour":return q(e,t,n);default:return X(e,t,n)}}function b(e,t){a.span=g(a.textarea,a.span,e,t)}function U(e,t){return e==null?!!t:!(e===!1||e==="false"||e==="0")}function V(e,t){return t===!!e.default?null:t?"true":"false"}function G(e,t,n){const o=m(document.createElement("label"));o.style.cssText=d;const s=document.createElement("input");return s.type="checkbox",s.checked=n,s.addEventListener("change",()=>b(t,V(e,s.checked))),o.appendChild(s),o.appendChild(document.createTextNode(e.label)),o}function X(e,t,n){const o=document.createElement("div");o.style.cssText=d+"cursor:default;";const s=document.createElement("span");s.textContent=e.label,s.style.cssText="white-space:nowrap;color:var(--dm-text-muted,#9a9aac);";const c=document.createElement("input");c.type=e.type==="number"?"number":"text",c.value=n===!0||n==null?"":n,e.default!=null&&e.default!==""&&(c.placeholder=String(e.default)),c.style.cssText=O;let i=null;return c.addEventListener("input",()=>{clearTimeout(i),i=setTimeout(()=>b(t,c.value.trim()),180)}),c.addEventListener("mousedown",r=>r.stopPropagation()),o.appendChild(s),o.appendChild(c),o}function q(e,t,n){const o=document.createElement("div");o.style.cssText=d+"cursor:default;";const s=document.createElement("span");s.textContent=e.label,s.style.flex="1";const c=document.createElement("input");return c.type="color",typeof n=="string"&&/^#/.test(n)?c.value=n:typeof e.default=="string"&&/^#/.test(e.default)&&(c.value=e.default),c.addEventListener("input",()=>b(t,c.value)),o.appendChild(s),o.appendChild(c),o}function J(e,t,n){const o=n==null||n===!0?e.default??"":n;return E(`${e.label}${o!==""?`: ${o}`:""}`,()=>{const s=x();for(const[c,i]of e.options||[]){const r=m(document.createElement("button"));r.type="button",r.style.cssText=d,r.textContent=i,c===o&&(r.style.fontWeight="700"),r.addEventListener("click",()=>{b(t,c),v()}),s.appendChild(r)}return s})}function Q(e,t){e.appendChild(h(`Effect: ${t.label}`));for(const o of t.attrs||[])e.appendChild(S(o,`${t.name}-${o.name}`));const n=m(document.createElement("button"));n.type="button",n.style.cssText=d,n.textContent="\u2715 Remove effect",n.addEventListener("click",()=>{const o={};for(const s of M(a.span.attrs,t.name))o[s]=null;R(a.textarea,a.span,o),u()}),e.appendChild(n)}function Z(){const e=x(),t=a.span,n=t&&y.has(t.name)?t.name:null;for(const o of[...new Set(p.map(s=>s.category))]){const s=p.filter(c=>c.category===o);if(s.length){e.appendChild(h(o));for(const c of s){const i=n&&(c.hosts||[]).includes(n)&&!(c.name in t.attrs),r=m(document.createElement("button"));if(r.type="button",r.style.cssText=d+"justify-content:space-between;",r.appendChild(document.createTextNode(c.label)),i){const l=document.createElement("span");l.textContent=`inject \u2192 [${n}]`,l.style.cssText="opacity:.6;font-size:.7rem;",r.appendChild(l)}r.addEventListener("click",()=>{if(i)g(a.textarea,a.span,c.name,!0);else{const l=c.selfClosing?`[${c.name} /]`:`[${c.name}]
|
|
2
2
|
Content
|
|
3
|
-
[/${
|
|
3
|
+
[/${c.name}]`;C(a.textarea,l)}u()}),e.appendChild(r)}}}return e}function E(e,t){const n=m(document.createElement("button"));n.type="button",n.style.cssText=d+"justify-content:space-between;",n.appendChild(document.createTextNode(e));const o=document.createElement("span");return o.textContent="\u25B8",o.style.opacity=".6",n.appendChild(o),n.addEventListener("mouseenter",()=>L(n,t)),n.addEventListener("click",s=>{s.stopPropagation(),L(n,t)}),n}function x(){const e=document.createElement("div");return e.className="dm-sc-submenu",e.style.cssText=w,e}function L(e,t){v();const n=t();a.submenu=n,document.body.appendChild(n);const o=e.getBoundingClientRect();$(n,o.right+2,o.top,o.left-2),window.I&&I.scan(n)}function v(){a&&a.submenu&&(a.submenu.remove(),a.submenu=null)}function ee(){const e=x();for(const t of P){const n=f.filter(o=>o.category===t&&!o.child);if(n.length){e.appendChild(h(t));for(const o of n){const s=m(document.createElement("button"));s.type="button",s.style.cssText=d,s.textContent=o.label,s.addEventListener("click",()=>{C(a.textarea,o.template||`[${o.name} /]`),u()}),e.appendChild(s)}}}return e}function te(){const e=x(),t=f.filter(n=>n.wrappable||n.container);for(const n of t){const o=m(document.createElement("button"));o.type="button",o.style.cssText=d,o.textContent=n.label,o.addEventListener("click",()=>{ne(n),u()}),e.appendChild(o)}return e}function ne(e){const t=a.textarea,n=t.selectionStart,o=t.selectionEnd,s=t.value.slice(n,o)||"Content";let c;e.name==="grid"?c=`[grid cols="2"]
|
|
4
4
|
[col]
|
|
5
|
-
${
|
|
5
|
+
${s}
|
|
6
6
|
[/col]
|
|
7
|
-
[/grid]`:
|
|
8
|
-
${
|
|
9
|
-
[/${e.name}]`,A(t,n,o,
|
|
7
|
+
[/grid]`:c=`[${e.name}]
|
|
8
|
+
${s}
|
|
9
|
+
[/${e.name}]`,A(t,n,o,c)}function $(e,t,n,o){e.style.left="0px",e.style.top="0px";const s=e.getBoundingClientRect();let c=t;t+s.width>window.innerWidth-8&&(c=o!=null?o-s.width:t-s.width);let i=n;n+s.height>window.innerHeight-8&&(i=Math.max(8,window.innerHeight-s.height-8)),e.style.left=`${Math.max(8,c)}px`,e.style.top=`${Math.max(8,i)}px`}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{openIconPicker as d}from"./card-builder.js";const s="display:block;font-size:.7rem;font-weight:600;color:var(--dm-text-muted,#aaa);text-transform:uppercase;letter-spacing:.05em;margin-bottom:.25rem;",a="width:100%;padding:.4rem .6rem;background:var(--dm-input-bg,#1a1a1a);border:1px solid var(--dm-border,#333);border-radius:4px;color:var(--dm-text,#eee);font-size:.9em;box-sizing:border-box;";export function makeField(r,t){const e=document.createElement("div"),n=document.createElement("label");return n.style.cssText=s,n.textContent=r,e.appendChild(n),e.appendChild(t),e}export function makeSelect(r){const t=document.createElement("select");return t.style.cssText=a,r.forEach(([e,n])=>{const o=document.createElement("option");o.value=e,o.textContent=n,t.appendChild(o)}),t}export function makeTextInput(r="",t=""){const e=document.createElement("input");return e.type="text",e.placeholder=r,e.value=t,e.style.cssText=a,e}export function makeCheckbox(r){const t=document.createElement("label");t.style.cssText="display:flex;align-items:center;gap:.5rem;cursor:pointer;";const e=document.createElement("input");e.type="checkbox";const n=document.createElement("span");return n.style.cssText="font-size:.85em;color:var(--dm-text,#eee);",n.textContent=r,t.appendChild(e),t.appendChild(n),t}export function makeIconInput(r="",t=""){const e=document.createElement("div");e.style.cssText="display:flex;gap:.35rem;";const n=makeTextInput(r,t);n.style.flex="1";const o=document.createElement("button");return o.type="button",o.title="Browse icons",o.textContent="\u229E",o.style.cssText="padding:.35rem .55rem;background:transparent;border:1px solid var(--dm-border,#333);border-radius:4px;color:var(--dm-text-muted,#aaa);cursor:pointer;font-size:.85em;flex-shrink:0;",o.addEventListener("click",()=>d(c=>{n.value=c,n.dispatchEvent(new Event("input",{bubbles:!0}))})),e.appendChild(n),e.appendChild(o),{el:e,input:n}}export function makeLivePreview(){const r=document.createElement("pre");return r.style.cssText="background:var(--dm-
|
|
1
|
+
import{openIconPicker as d}from"./card-builder.js";const s="display:block;font-size:.7rem;font-weight:600;color:var(--dm-text-muted,#aaa);text-transform:uppercase;letter-spacing:.05em;margin-bottom:.25rem;",a="width:100%;padding:.4rem .6rem;background:var(--dm-input-bg,#1a1a1a);border:1px solid var(--dm-border,#333);border-radius:4px;color:var(--dm-text,#eee);font-size:.9em;box-sizing:border-box;";export function makeField(r,t){const e=document.createElement("div"),n=document.createElement("label");return n.style.cssText=s,n.textContent=r,e.appendChild(n),e.appendChild(t),e}export function makeSelect(r){const t=document.createElement("select");return t.style.cssText=a,r.forEach(([e,n])=>{const o=document.createElement("option");o.value=e,o.textContent=n,t.appendChild(o)}),t}export function makeTextInput(r="",t=""){const e=document.createElement("input");return e.type="text",e.placeholder=r,e.value=t,e.style.cssText=a,e}export function makeCheckbox(r){const t=document.createElement("label");t.style.cssText="display:flex;align-items:center;gap:.5rem;cursor:pointer;";const e=document.createElement("input");e.type="checkbox";const n=document.createElement("span");return n.style.cssText="font-size:.85em;color:var(--dm-text,#eee);",n.textContent=r,t.appendChild(e),t.appendChild(n),t}export function makeIconInput(r="",t=""){const e=document.createElement("div");e.style.cssText="display:flex;gap:.35rem;";const n=makeTextInput(r,t);n.style.flex="1";const o=document.createElement("button");return o.type="button",o.title="Browse icons",o.textContent="\u229E",o.style.cssText="padding:.35rem .55rem;background:transparent;border:1px solid var(--dm-border,#333);border-radius:4px;color:var(--dm-text-muted,#aaa);cursor:pointer;font-size:.85em;flex-shrink:0;",o.addEventListener("click",()=>d(c=>{n.value=c,n.dispatchEvent(new Event("input",{bubbles:!0}))})),e.appendChild(n),e.appendChild(o),{el:e,input:n}}export function makeLivePreview(){const r=document.createElement("pre");return r.style.cssText="background:var(--dm-background-alt,#111);border:1px solid var(--dm-border,#333);border-radius:4px;padding:.5rem .75rem;font-size:.75em;color:var(--dm-text-muted,#aaa);white-space:pre-wrap;word-break:break-all;margin:0;max-height:120px;overflow:auto;",r.textContent="",{el:r,update(t){r.textContent=t}}}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{api as c}from"../api.js";import{colourToCss as F}from"/public/js/menu-decor.mjs";import{groupPluginItems as W,stripItemByUrl as D,insertFoldersBeforeSystem as _,pruneEmptySynthesisedFolders as K,MANAGE_PLUGINS_URL as X}from"./sidebar-grouping.js";function h(e){return String(e??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}const G=[{text:"Dashboard",url:"#/",icon:"home"},{text:"Menus",url:"#/menus",icon:"menu"}];function B(e,i){return i?!e||!e.length?!1:e.includes(i)?!0:["read","create","update","delete"].some(t=>e.includes(`${i}.${t}`)):!0}function I(e,i){const t=[];for(const n of e){if(n.hidden||n.permission&&!B(i,n.permission))continue;const s=Array.isArray(n.items)&&n.items.length?I(n.items,i):[];t.push({...n,items:s})}return t}function O(e,i){if(!i||!i.length)return e;const t=(n,s)=>{for(const l of n){if((l.text||"").toLowerCase()===s.toLowerCase())return l;if(Array.isArray(l.items)){const
|
|
1
|
+
import{api as c}from"../api.js";import{colourToCss as F}from"/public/js/menu-decor.mjs";import{groupPluginItems as W,stripItemByUrl as D,insertFoldersBeforeSystem as _,pruneEmptySynthesisedFolders as K,MANAGE_PLUGINS_URL as X}from"./sidebar-grouping.js";function h(e){return String(e??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}const G=[{text:"Dashboard",url:"#/",icon:"home"},{text:"Menus",url:"#/menus",icon:"menu"}];function B(e,i){return i?!e||!e.length?!1:e.includes(i)?!0:["read","create","update","delete"].some(t=>e.includes(`${i}.${t}`)):!0}function I(e,i){const t=[];for(const n of e){if(n.hidden||n.permission&&!B(i,n.permission))continue;const s=Array.isArray(n.items)&&n.items.length?I(n.items,i):[];t.push({...n,items:s})}return t}function O(e,i){if(!i||!i.length)return e;const t=(n,s)=>{for(const l of n){if((l.text||"").toLowerCase()===s.toLowerCase())return l;if(Array.isArray(l.items)){const a=t(l.items,s);if(a)return a}}return null};for(const n of i)if(n.parent){const s=t(e,n.parent);s?(s.items=Array.isArray(s.items)?s.items:[],s.items.push(n.item)):e.push(n.item)}else e.push(n.item);return e}async function V(e){if(!B(e,"projects"))return[];let i=[];try{i=await c.projects.list()}catch{return[]}const t={};await Promise.all(i.map(async s=>{try{const l=await c.projects.artefacts(s.slug);t[s.slug]=l}catch{t[s.slug]={}}}));const n=[{key:"pages",text:"Pages",icon:"file-text",path:"/pages"},{key:"collections",text:"Collections",icon:"database",path:"/collections"},{key:"forms",text:"Forms",icon:"layout",path:"/forms"},{key:"actions",text:"Actions",icon:"zap",path:"/actions"},{key:"menus",text:"Menus",icon:"menu",path:"/menus"},{key:"blocks",text:"Blocks",icon:"box",path:"/blocks"},{key:"components",text:"Components",icon:"component",path:"/components"},{key:"views",text:"Views",icon:"eye",path:"/views"},{key:"roles",text:"Roles",icon:"shield",path:"/roles"},{key:"users",text:"Users",icon:"users",path:"/users"},{key:"apis",text:"APIs",icon:"code",path:"/apis"}];return i.map(s=>{const a="#/projects/"+encodeURIComponent(s.slug),g=t[s.slug]||{},d=[{text:"Overview",url:a,icon:s.icon||"folder"}];for(const m of n){const y=g[m.key],p=Array.isArray(y)?y.length:0;p<=0||d.push({text:`${m.text} (${p})`,url:a+m.path,icon:m.icon})}d.push({text:"Settings",url:a+"/settings",icon:"settings"});const u=s.enabled===!1;return{text:s.name||s.slug,icon:s.icon||"folder",items:d,...u&&{colour:"neutral",badge:{text:"off"}}}})}function Y(e,i){for(const t of e)if((t.text||"").toLowerCase()==="projects"){t.items=Array.isArray(t.items)?t.items.slice():[],t.items.push(...i);return}}function J(e,i){if(!e.url||!i)return"";const t=i[e.url];return t==null||t<=0?"":`<span class="sidebar-badge">${h(String(t))}</span>`}function Q(e){const i=(e.text||"").replace(/\s*\(\d+\)\s*$/,"").toLowerCase().replace(/\s+/g,"-"),t=(e.url||"").match(/^#\/projects\/([^/]+)/);return`sidebar.expanded.${t?`project-${decodeURIComponent(t[1])}.`:""}${i}`}function z(e,i){if(e&&e.type==="separator")return'<hr class="sidebar-divider">';const t=e.icon?`<span data-icon="${h(e.icon)}"></span>`:"",n=h(e.text||""),s=e.url?h(e.url):"",l=Array.isArray(e.items)&&e.items.length>0,a=e.colour?F(e.colour):"",g=a?` style="color:${h(a)}"`:"";let d="";if(e.badge&&e.badge.text!=null&&e.badge.text!==""){const u=e.badge.variant?F(e.badge.variant):"";d=`<span class="dm-menu-badge"${u?` style="background:${h(u)};color:var(--dm-text-inverse,#fff)"`:""}>${h(String(e.badge.text))}</span>`}if(l){const u=Q(e),m=S.get(u)!==!1,y=e.items.map(p=>z(p,i)).join("");return`<details data-state-key="${h(u)}"${m?" open":""}>
|
|
2
2
|
<summary${g}>${t} <span class="sidebar-text">${n}</span>${d}</summary>
|
|
3
3
|
<div class="sidebar-children">${y}</div>
|
|
4
|
-
</details>`}return`<a href="${s}" class="sidebar-link" data-url="${s}"${g}>${t} <span class="sidebar-text">${n}</span>${J(e,i)}${d}</a>`}async function Z(){const e=p=>p.then(b=>Array.isArray(b)?b.length:Array.isArray(b?.entries)?b.entries.length:0).catch(()=>0),[i,t,n,s,l,
|
|
4
|
+
</details>`}return`<a href="${s}" class="sidebar-link" data-url="${s}"${g}>${t} <span class="sidebar-text">${n}</span>${J(e,i)}${d}</a>`}async function Z(){const e=p=>p.then(b=>Array.isArray(b)?b.length:Array.isArray(b?.entries)?b.entries.length:0).catch(()=>0),[i,t,n,s,l,a,g,d,u,m,y]=await Promise.all([e(c.pages.list()),e(c.media.list()),e(c.collections.list()),e(c.forms.list()),e(c.views.list()),e(c.actions.list()),e(c.blocks.list()),e(c.components.list()),e(c.users.list()),e(c.plugins.list()),c.system?.notifications?.unreadCount?.().then(p=>p?.count??0).catch(()=>0)??Promise.resolve(0)]);return{"#/pages":i,"#/media":t,"#/collections":n,"#/forms":s,"#/views":l,"#/actions":a,"#/blocks":g,"#/components":d,"#/users":u,"#/plugins":m,"#/system/notifications":y}}async function ee(){try{const e=await c.settings.get();return e?.adminBrand?.title||e?.title||"Admin"}catch{return"Admin"}}export async function renderAdminSidebar({mount:e,permissions:i}){const t=$(e).get(0);if(!t)return;let n,s=null,l=null,a=null;try{const r=await c.menus.get("admin-sidebar");n=Array.isArray(r?.items)?r.items:null,s=r?.variant||null,l=r?.position||null,a=r?.style||null}catch{n=null}(!n||!n.length)&&(console.warn("[admin-sidebar] No admin-sidebar menu found; using fallback tree"),n=G.slice());let g=[];try{g=await H.get("/api/sidebar/registered-items")||[]}catch{}n=D(n,X);const{toolsFolder:d,pluginsFolder:u,parented:m}=W(g);n=O(n,m),n=_(n,[d,u]);const y=await V(i);y.length&&Y(n,y),n=I(n,i),n=K(n);const[p,b]=await Promise.all([Z().catch(()=>({})),ee()]),R=s?` dm-admin-sidebar--${h(s)}`:"";function w(r,f="px"){if(r==null)return r;const o=String(r).trim();return/^\d+(\.\d+)?$/.test(o)?`${o}${f}`:o}let C="";if(a){const r=[];a.fontFamily&&r.push(`font-family: ${a.fontFamily}, sans-serif`),a.fontSize&&r.push(`font-size: ${w(a.fontSize)}`),a.fontWeight&&r.push(`font-weight: ${a.fontWeight}`),a.letterSpacing&&r.push(`letter-spacing: ${w(a.letterSpacing,"em")}`);const f=[];if(r.length&&f.push(`#admin-sidebar .dm-admin-sidebar, #admin-sidebar .dm-admin-sidebar .sidebar-link, #admin-sidebar .dm-admin-sidebar summary, #admin-sidebar .dm-admin-sidebar .sidebar-text { ${r.join("; ")} }`),a.iconSize){const o=w(a.iconSize);f.push(`#admin-sidebar .dm-admin-sidebar [data-icon], #admin-sidebar .dm-admin-sidebar [data-icon] svg { width: ${o} !important; height: ${o} !important; }`)}f.length&&(C=`<style data-admin-sidebar-style>${f.join(" ")}</style>`)}const N=`<div class="dm-admin-sidebar-header"><span data-icon="layout"></span> ${h(b)}</div>`,U=`${C}<nav class="dm-admin-sidebar${R}">${N}${n.map(r=>z(r,p)).join("")}</nav>`,j=document.createRange();j.selectNodeContents(t);const q=j.createContextualFragment(U);t.replaceChildren(q),Domma.icons.scan(t);const x=Number.parseInt(S.get("sidebar.width"),10);Number.isFinite(x)&&x>=180&&x<=480&&(t.style.width=x+"px");const v=document.createElement("div");v.className="dm-admin-sidebar-handle",v.setAttribute("aria-label","Resize sidebar"),t.appendChild(v),t.querySelectorAll("details").forEach(r=>{r.addEventListener("toggle",function(){const f=this.getAttribute("data-state-key");f&&S.set(f,this.open);const o=this.querySelector(":scope > .sidebar-children");if(o)if(this.open){const k=o.scrollHeight;o.style.maxHeight="0",requestAnimationFrame(()=>{o.style.maxHeight=k+"px",o.addEventListener("transitionend",function T(){o.style.maxHeight="none",o.removeEventListener("transitionend",T)})})}else{const k=o.scrollHeight;o.style.maxHeight=k+"px",requestAnimationFrame(()=>{o.style.maxHeight="0"})}})});let A=!1,P=0,E=0;v.addEventListener("mousedown",r=>{A=!0,P=r.clientX,E=t.getBoundingClientRect().width,document.body.style.cursor="col-resize",document.body.style.userSelect="none",r.preventDefault()}),document.addEventListener("mousemove",r=>{if(!A)return;const f=Math.max(180,Math.min(480,E+(r.clientX-P)));t.style.width=f+"px"}),document.addEventListener("mouseup",()=>{A&&(A=!1,document.body.style.cursor="",document.body.style.userSelect="",S.set("sidebar.width",parseInt(t.style.width,10)))});function L(){const r=location.hash||"#/";$(t).find(".sidebar-link").removeClass("active"),$(t).find(`.sidebar-link[data-url="${r}"]`).addClass("active")}L(),M.subscribe("router:afterChange",L)}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{openIconPicker as Q}from"./card-builder.js";import{safeSetHTML as X}from"./safe-html.js";function R(e){const t={};for(const[,i,l,o]of e.matchAll(/([\w-]+)=(?:"([^"]*)"|'([^']*)')/g))t[i]=l??o??"";const n=e.replace(/([\w-]+)=(?:"[^"]*"|'[^']*')/g,i=>" ".repeat(i.length));for(const[,i]of n.matchAll(/\b([\w-]+)\b/g))i in t||(t[i]=!0);return t}function h(e){return String(e).replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}const Z=new Set(["layout","theme","mode","id","class"]),ee=new Set(["title","date","status","icon"]),te=new Set(["slug","display","layout","theme","mode","title-field","date-field","status-field","icon-field","body-field","limit"]),P=["vertical","centred","horizontal"],M=["minimal","corporate","modern"],ne=["","planned","in-progress","completed","blocked"];let
|
|
1
|
+
import{openIconPicker as Q}from"./card-builder.js";import{safeSetHTML as X}from"./safe-html.js";function R(e){const t={};for(const[,i,l,o]of e.matchAll(/([\w-]+)=(?:"([^"]*)"|'([^']*)')/g))t[i]=l??o??"";const n=e.replace(/([\w-]+)=(?:"[^"]*"|'[^']*')/g,i=>" ".repeat(i.length));for(const[,i]of n.matchAll(/\b([\w-]+)\b/g))i in t||(t[i]=!0);return t}function h(e){return String(e).replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}const Z=new Set(["layout","theme","mode","id","class"]),ee=new Set(["title","date","status","icon"]),te=new Set(["slug","display","layout","theme","mode","title-field","date-field","status-field","icon-field","body-field","limit"]),P=["vertical","centred","horizontal"],M=["minimal","corporate","modern"],ne=["","planned","in-progress","completed","blocked"];let k=null,a=null,y=null,F=null,T=null,$=null,q=0;export const TimelineBuilder={open(e,t={}){if(k)return;y=e,F=t,a=O(),T=null;const n=parseTimelineAtCursor(e.value,e.selectionStart);n.found&&(T=n.range,a=n.state),de()},close(){z()}};function O(){const e=new Date().toISOString().slice(0,10);return{mode:"static",layout:"vertical",theme:"minimal",roadmap:!1,id:"",className:"",extras:{},events:[{title:"First Event",date:e,status:"completed",icon:"",body:"Describe this event.",extras:{}},{title:"Second Event",date:"",status:"planned",icon:"",body:"Describe this event.",extras:{}}],collection:{slug:"",titleField:"",dateField:"",statusField:"",iconField:"",bodyField:"",limit:""}}}export function parseTimelineAtCursor(e,t){let n=null;const i=/\[timeline([^\]]*)\]([\s\S]*?)\[\/timeline\]/gi;for(const s of e.matchAll(i)){const c=s.index,u=c+s[0].length;t>=c&&t<=u&&(!n||u-c<n.range.end-n.range.start)&&(n={kind:"static",range:{start:c,end:u},attrStr:s[1],body:s[2]})}const l=/\[collection([^\]]*?)\/\]/gi;for(const s of e.matchAll(l)){const c=s.index,u=c+s[0].length;if(t<c||t>u)continue;const w=R(s[1]);w.display==="timeline"&&(!n||u-c<n.range.end-n.range.start)&&(n={kind:"collection",range:{start:c,end:u},attrs:w})}if(!n)return{found:!1};if(n.kind==="static"){const s=R(n.attrStr),c={};Object.keys(s).forEach(g=>{!Z.has(g)&&s[g]!==!0&&(c[g]=s[g])});const u=[],w=/\[event([^\]]*)\]([\s\S]*?)\[\/event\]/gi;for(const g of n.body.matchAll(w)){const C=R(g[1]),p={};Object.keys(C).forEach(v=>{!ee.has(v)&&C[v]!==!0&&(p[v]=C[v])}),u.push({title:C.title||"",date:C.date||"",status:C.status||"",icon:C.icon||"",body:g[2].trim(),extras:p})}return{found:!0,range:n.range,state:{mode:"static",layout:P.includes(s.layout)?s.layout:"vertical",theme:M.includes(s.theme)?s.theme:"minimal",roadmap:s.mode==="roadmap",id:s.id||"",className:s.class||"",extras:c,events:u.length?u:O().events,collection:O().collection}}}const o=n.attrs,m={};return Object.keys(o).forEach(s=>{!te.has(s)&&o[s]!==!0&&(m[s]=o[s])}),{found:!0,range:n.range,state:{mode:"collection",layout:P.includes(o.layout)?o.layout:"vertical",theme:M.includes(o.theme)?o.theme:"minimal",roadmap:o.mode==="roadmap",id:"",className:"",extras:m,events:O().events,collection:{slug:o.slug||"",titleField:o["title-field"]||"",dateField:o["date-field"]||"",statusField:o["status-field"]||"",iconField:o["icon-field"]||"",bodyField:o["body-field"]||"",limit:o.limit||""}}}}function U(){return a.mode==="collection"?oe():ie()}function ie(){const e=a,t=[];e.layout!=="vertical"&&t.push(`layout="${h(e.layout)}"`),e.theme!=="minimal"&&t.push(`theme="${h(e.theme)}"`),e.roadmap&&t.push('mode="roadmap"'),e.id&&t.push(`id="${h(e.id)}"`),e.className&&t.push(`class="${h(e.className)}"`),Object.entries(e.extras).forEach(([l,o])=>t.push(`${l}="${h(o)}"`));const n=t.length?" "+t.join(" "):"",i=e.events.map(l=>{const o=[];return l.title&&o.push(`title="${h(l.title)}"`),l.date&&o.push(`date="${h(l.date)}"`),l.status&&o.push(`status="${h(l.status)}"`),l.icon&&o.push(`icon="${h(l.icon)}"`),Object.entries(l.extras||{}).forEach(([s,c])=>o.push(`${s}="${h(c)}"`)),`[event${o.length?" "+o.join(" "):""}]
|
|
2
2
|
${(l.body||"").trim()}
|
|
3
3
|
[/event]`}).join(`
|
|
4
4
|
`);return`[timeline${n}]
|
|
5
5
|
${i}
|
|
6
|
-
[/timeline]`}function oe(){const e=a,t=e.collection,n=[`slug="${h(t.slug)}"`,'display="timeline"'];return e.layout!=="vertical"&&n.push(`layout="${h(e.layout)}"`),e.theme!=="minimal"&&n.push(`theme="${h(e.theme)}"`),e.roadmap&&n.push('mode="roadmap"'),t.titleField&&n.push(`title-field="${h(t.titleField)}"`),t.dateField&&n.push(`date-field="${h(t.dateField)}"`),t.statusField&&n.push(`status-field="${h(t.statusField)}"`),t.iconField&&n.push(`icon-field="${h(t.iconField)}"`),t.bodyField&&n.push(`body-field="${h(t.bodyField)}"`),t.limit&&n.push(`limit="${h(t.limit)}"`),Object.entries(e.extras).forEach(([i,l])=>n.push(`${i}="${h(l)}"`)),`[collection ${n.join(" ")} /]`}function z(){$&&(clearTimeout($),$=null),F&&(F.remove(),F=null,a=null,k=null)}function le(){const e=U();if(k){const{start:t,end:n}=k;C.value=C.value.slice(0,t)+e+C.value.slice(n),C.selectionStart=C.selectionEnd=t+e.length}else{const t=C.selectionStart,n=C.selectionEnd;C.value=C.value.slice(0,t)+e+C.value.slice(n),C.selectionStart=C.selectionEnd=t+e.length}C.dispatchEvent(new Event("input",{bubbles:!0})),C.focus(),z()}function d(e,t=""){const n=document.createElement(e);return t&&(n.style.cssText=t),n}const L="padding:7px 10px;border-radius:7px;border:1px solid var(--dm-border,#334155);background:var(--dm-surface,#0f172a);color:var(--dm-text,#e2e8f0);font-size:12px;font-family:inherit;width:100%",j="font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:.07em;color:var(--dm-text-muted,#475569)";function S(e,t){const n=d("div","display:flex;flex-direction:column;gap:5px"),i=d("div",j);return i.textContent=e,n.appendChild(i),n.appendChild(t),n}function H(){return d("div","height:1px;background:var(--dm-border,#334155);margin:2px 0")}function de(){F=d("div","position:fixed;inset:0;background:rgba(0,0,0,.6);display:flex;align-items:center;justify-content:center;z-index:9999;padding:24px;isolation:isolate");const e=d("div","background:var(--dm-surface,#1e293b);border:1px solid var(--dm-border,#334155);border-radius:14px;width:100%;max-width:960px;max-height:90vh;display:flex;flex-direction:column;box-shadow:0 24px 64px rgba(0,0,0,.6);overflow:hidden"),t=d("div","display:flex;align-items:center;justify-content:space-between;padding:14px 20px;border-bottom:1px solid var(--dm-border,#334155);flex-shrink:0"),n=d("span","font-weight:700;color:var(--dm-text,#f1f5f9);font-size:14px");n.textContent=k?"Edit Timeline":"Insert Timeline";const i=d("button","background:var(--dm-border,#334155);border:none;color:var(--dm-text-muted,#94a3b8);border-radius:6px;width:26px;height:26px;cursor:pointer;font-size:14px");i.textContent="\u2715",i.addEventListener("click",z),t.appendChild(n),t.appendChild(i);const l=d("div","display:grid;grid-template-columns:340px 1fr;flex:1;overflow:hidden");l.appendChild(ae()),l.appendChild(me());const o=d("div","display:flex;justify-content:flex-end;gap:10px;padding:12px 20px;border-top:1px solid var(--dm-border,#334155);flex-shrink:0"),f=d("button","padding:8px 18px;border-radius:8px;border:none;background:var(--dm-border,#334155);color:var(--dm-text-muted,#94a3b8);font-size:12px;font-weight:700;cursor:pointer");f.textContent="Cancel",f.addEventListener("click",z);const s=d("button","padding:8px 18px;border-radius:8px;border:none;background:#6366f1;color:#fff;font-size:12px;font-weight:700;cursor:pointer");s.textContent=k?"Save Timeline":"Insert Timeline",s.addEventListener("click",le),o.appendChild(f),o.appendChild(s),e.appendChild(t),e.appendChild(l),e.appendChild(o),F.appendChild(e),F.addEventListener("click",c=>{c.target===F&&z()}),document.body.appendChild(F),x()}function ae(){const e=d("div","padding:18px;border-right:1px solid var(--dm-border,#334155);display:flex;flex-direction:column;gap:14px;overflow-y:auto");e.appendChild(re()),e.appendChild(H()),e.appendChild(S("Layout",V("layout",P.map(i=>[i,G(i)])))),e.appendChild(S("Theme",V("theme",M.map(i=>[i,G(i)])))),e.appendChild(S("Mode",se())),e.appendChild(H());const t=d("div","display:flex;flex-direction:column;gap:12px");t.id="tb-static",t.appendChild(ce()),e.appendChild(t);const n=d("div","display:flex;flex-direction:column;gap:12px");return n.id="tb-collection",n.appendChild(fe()),e.appendChild(n),K(),e}function re(){const e=d("div","display:flex;gap:6px"),t=(n,i)=>{const l=d("button"),o=()=>{const f=a.mode===n;l.style.cssText=`flex:1;padding:8px 10px;border-radius:8px;border:1px solid;font-size:12px;font-weight:700;cursor:pointer;${f?"border-color:#6366f1;background:#1e1b4b;color:#a5b4fc":"border-color:var(--dm-border,#334155);background:var(--dm-surface,#0f172a);color:var(--dm-text-muted,#94a3b8)"}`};return l.type="button",l.textContent=i,o(),l.addEventListener("click",()=>{a.mode=n,e.querySelectorAll("button").forEach(f=>f._paint&&f._paint()),K(),x()}),l._paint=o,l};return e.appendChild(t("static","Static")),e.appendChild(t("collection","From Collection")),e}function K(){const e=document.getElementById("tb-static"),t=document.getElementById("tb-collection");e&&(e.style.display=a.mode==="static"?"":"none"),t&&(t.style.display=a.mode==="collection"?"":"none")}function V(e,t){const n=d("select",L+";cursor:pointer");return t.forEach(([i,l])=>{const o=document.createElement("option");o.value=i,o.textContent=l,i===a[e]&&(o.selected=!0),n.appendChild(o)}),n.addEventListener("change",()=>{a[e]=n.value,x()}),n}function se(){const e=d("label","display:flex;align-items:center;gap:.5rem;cursor:pointer;font-size:12px;color:var(--dm-text,#e2e8f0)"),t=document.createElement("input");return t.type="checkbox",t.checked=!!a.roadmap,t.addEventListener("change",()=>{a.roadmap=t.checked,x()}),e.appendChild(t),e.appendChild(document.createTextNode("Roadmap mode")),e}function ce(){const e=d("div","display:flex;flex-direction:column;gap:8px"),t=d("div","display:flex;align-items:center;justify-content:space-between"),n=d("div",j);n.textContent="Events";const i=d("button","padding:4px 10px;border-radius:6px;border:1px dashed var(--dm-border,#334155);background:transparent;color:var(--dm-text-muted,#94a3b8);font-size:11px;cursor:pointer");i.type="button",i.textContent="+ Add event",i.addEventListener("click",()=>{a.events.push({title:"New Event",date:"",status:"",icon:"",body:"",extras:{}}),N(),x()}),t.appendChild(n),t.appendChild(i),e.appendChild(t);const l=d("div","display:flex;flex-direction:column;gap:8px");return l.id="tb-events",e.appendChild(l),N(l),e}function N(e){const t=e||document.getElementById("tb-events");if(t){for(;t.firstChild;)t.removeChild(t.firstChild);a.events.forEach((n,i)=>t.appendChild(pe(n,i)))}}function pe(e,t){const n=d("div","border:1px solid var(--dm-border,#334155);border-radius:8px;padding:10px;background:var(--dm-surface-subtle,#0b1120);display:flex;flex-direction:column;gap:8px");n.draggable=!0,n.dataset.idx=String(t);const i=d("div","display:flex;align-items:center;gap:6px"),l=d("span","cursor:grab;color:var(--dm-text-muted,#475569);font-size:14px;user-select:none;padding:0 4px");l.textContent="\u2261",l.title="Drag to reorder",i.appendChild(l);const o=d("div","flex:1;font-size:12px;color:var(--dm-text,#e2e8f0);font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis");o.textContent=e.title||"(untitled event)",i.appendChild(o);const f=(r,m,b,E)=>{const _=d("button",`padding:2px 6px;border-radius:5px;border:1px solid var(--dm-border,#334155);background:transparent;color:var(--dm-text-muted,#94a3b8);font-size:11px;cursor:${E?"not-allowed":"pointer"};opacity:${E?"0.4":"1"}`);return _.type="button",_.title=m,_.textContent=r,E||_.addEventListener("click",b),_};i.appendChild(f("\u2191","Move up",()=>Y(t,-1),t===0)),i.appendChild(f("\u2193","Move down",()=>Y(t,1),t===a.events.length-1)),i.appendChild(f("\u2715","Delete",()=>ue(t),a.events.length<=1)),n.appendChild(i);const s=W(e.title,"Event title",r=>{e.title=r,o.textContent=r||"(untitled event)",x()});n.appendChild(A("Title",s));const c=d("div","display:grid;grid-template-columns:1fr 1fr;gap:6px"),u=document.createElement("input");u.type="date",u.value=e.date||"",u.style.cssText=L,u.addEventListener("input",()=>{e.date=u.value,x()}),c.appendChild(A("Date",u));const w=document.createElement("select");w.style.cssText=L+";cursor:pointer",ne.forEach(r=>{const m=document.createElement("option");m.value=r,m.textContent=r===""?"\u2014 none \u2014":G(r),r===e.status&&(m.selected=!0),w.appendChild(m)}),w.addEventListener("change",()=>{e.status=w.value,x()}),c.appendChild(A("Status",w)),n.appendChild(c);const g=d("div","display:flex;gap:6px"),y=W(e.icon,"e.g. rocket",r=>{e.icon=r,x()});y.style.flex="1";const p=d("button","padding:0 10px;background:var(--dm-border,#334155);border:none;color:var(--dm-text-muted,#94a3b8);border-radius:7px;font-size:12px;cursor:pointer;flex-shrink:0");p.type="button",p.title="Browse icons",p.textContent="\u2605",p.addEventListener("click",()=>Q(r=>{e.icon=r,y.value=r,x()})),g.appendChild(y),g.appendChild(p),n.appendChild(A("Icon",g));const v=document.createElement("textarea");return v.value=e.body||"",v.rows=2,v.style.cssText=L+";resize:vertical;min-height:48px;line-height:1.5",v.addEventListener("input",()=>{e.body=v.value,x()}),n.appendChild(A("Body (Markdown)",v)),n.addEventListener("dragstart",r=>{r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",String(t)),n.style.opacity="0.5"}),n.addEventListener("dragend",()=>{n.style.opacity=""}),n.addEventListener("dragover",r=>{r.preventDefault(),r.dataTransfer.dropEffect="move",n.style.borderColor="#6366f1"}),n.addEventListener("dragleave",()=>{n.style.borderColor="var(--dm-border,#334155)"}),n.addEventListener("drop",r=>{r.preventDefault(),n.style.borderColor="var(--dm-border,#334155)";const m=parseInt(r.dataTransfer.getData("text/plain"),10);if(Number.isNaN(m)||m===t)return;const[b]=a.events.splice(m,1);a.events.splice(t,0,b),N(),x()}),n}function Y(e,t){const n=e+t;if(n<0||n>=a.events.length)return;const[i]=a.events.splice(e,1);a.events.splice(n,0,i),N(),x()}function ue(e){a.events.length<=1||(a.events.splice(e,1),N(),x())}function W(e,t,n){const i=document.createElement("input");return i.type="text",i.value=e||"",i.placeholder=t||"",i.style.cssText=L,i.addEventListener("input",()=>n(i.value)),i}function A(e,t){const n=d("div","display:flex;flex-direction:column;gap:4px"),i=d("div","font-size:10px;font-weight:600;color:var(--dm-text-muted,#64748b);letter-spacing:.04em");return i.textContent=e,n.appendChild(i),n.appendChild(t),n}function fe(){const e=d("div","display:flex;flex-direction:column;gap:10px"),t=d("select",L+";cursor:pointer"),n=document.createElement("option");n.value="",n.textContent="Loading collections\u2026",t.appendChild(n),e.appendChild(S("Collection",t));const i=B("titleField"),l=B("dateField"),o=B("statusField"),f=B("iconField"),s=B("bodyField");e.appendChild(S("Title field",i));const c=d("div","display:grid;grid-template-columns:1fr 1fr;gap:8px");c.appendChild(S("Date field",l)),c.appendChild(S("Status field",o)),e.appendChild(c),e.appendChild(S("Icon field",f)),e.appendChild(S("Body field",s));const u=W(a.collection.limit,"All",p=>{a.collection.limit=p,x()});u.type="number",u.min="1",e.appendChild(S("Limit (optional)",u));const w=d("div","font-size:11px;color:var(--dm-text-muted,#64748b);line-height:1.4");w.textContent="Picks entries in their default collection order. Set date, status, and icon fields to drive visual cues on the page.",e.appendChild(w);const g=p=>{[i,l,o,f,s].forEach(b=>{for(;b.firstChild;)b.removeChild(b.firstChild);const E=document.createElement("option");E.value="",E.textContent="\u2014 none \u2014",b.appendChild(E),p.forEach(_=>{const D=document.createElement("option");D.value=_.name,D.textContent=_.label||_.name,b.appendChild(D)})});const r=new Set(p.map(b=>b.name)),m=(b,E)=>{a.collection[b]&&r.has(a.collection[b])||(a.collection[b]=r.has(E)?E:"")};m("titleField","title"),m("dateField","date"),m("statusField","status"),m("iconField","icon"),m("bodyField","description"),i.value=a.collection.titleField,l.value=a.collection.dateField,o.value=a.collection.statusField,f.value=a.collection.iconField,s.value=a.collection.bodyField},y=async p=>{if(!p){g([]);return}try{const v=T.onGetCollection?await T.onGetCollection(p):null,r=v&&v.fields||[];g(r)}catch{g([])}};return t.addEventListener("change",()=>{a.collection.slug=t.value,y(t.value).then(x)}),(async()=>{let p=[];try{p=T.onListCollections?await T.onListCollections():[]}catch{p=[]}for(;t.firstChild;)t.removeChild(t.firstChild);if(!p.length){const r=document.createElement("option");r.value="",r.textContent="No collections available",t.appendChild(r),g([]);return}p.forEach(r=>{const m=document.createElement("option");m.value=r.slug,m.textContent=r.title||r.slug,t.appendChild(m)});const v=a.collection.slug;v&&p.some(r=>r.slug===v)?t.value=v:(a.collection.slug=p[0].slug,t.value=p[0].slug),await y(t.value),x()})(),e}function B(e){const t=d("select",L+";cursor:pointer"),n=document.createElement("option");return n.value="",n.textContent="\u2014 none \u2014",t.appendChild(n),t.addEventListener("change",()=>{a.collection[e]=t.value,x()}),t}function me(){const e=d("div","padding:20px;background:var(--dm-surface,#0f172a);display:flex;flex-direction:column;gap:14px;overflow-y:auto"),t=d("div",j);t.textContent="Live Preview";const n=d("div","flex:1;min-height:160px;background:var(--dm-surface-subtle,#fff);border-radius:10px;padding:16px;color:#0f172a");n.id="tb-preview-area";const i=d("div",j+";margin-bottom:4px");i.textContent="Shortcode";const l=d("pre","background:var(--dm-surface-subtle,#1e293b);border:1px solid var(--dm-border,#334155);border-radius:8px;padding:10px 14px;font-family:monospace;font-size:11px;color:var(--dm-primary,#a5b4fc);line-height:1.6;white-space:pre-wrap;word-break:break-word;max-height:160px;overflow:auto;margin:0");return l.id="tb-snippet",e.appendChild(t),e.appendChild(n),e.appendChild(i),e.appendChild(l),e}function x(){const e=document.getElementById("tb-snippet");e&&(e.textContent=U()),he()}function he(){$&&clearTimeout($),$=setTimeout(ve,300)}async function ve(){const e=document.getElementById("tb-preview-area");if(!e)return;const t=U(),n=++q;xe(e);try{const i=T.onPreview?await T.onPreview(t):null;if(n!==q)return;if(!i||typeof i.html!="string"){J(e);return}X(e,i.html),typeof I<"u"&&I.scan&&I.scan(e)}catch{if(n!==q)return;J(e)}}function xe(e){if(!e.dataset.loaded){for(;e.firstChild;)e.removeChild(e.firstChild);const t=d("div","color:var(--dm-text-muted,#94a3b8);font-size:12px");t.textContent="Rendering preview\u2026",e.appendChild(t),e.dataset.loaded="1"}}function J(e){for(;e.firstChild;)e.removeChild(e.firstChild);const t=d("div","color:var(--dm-text-muted,#94a3b8);font-size:12px;font-style:italic");t.textContent="Preview unavailable",e.appendChild(t)}function G(e){return e.charAt(0).toUpperCase()+e.slice(1)}
|
|
6
|
+
[/timeline]`}function oe(){const e=a,t=e.collection,n=[`slug="${h(t.slug)}"`,'display="timeline"'];return e.layout!=="vertical"&&n.push(`layout="${h(e.layout)}"`),e.theme!=="minimal"&&n.push(`theme="${h(e.theme)}"`),e.roadmap&&n.push('mode="roadmap"'),t.titleField&&n.push(`title-field="${h(t.titleField)}"`),t.dateField&&n.push(`date-field="${h(t.dateField)}"`),t.statusField&&n.push(`status-field="${h(t.statusField)}"`),t.iconField&&n.push(`icon-field="${h(t.iconField)}"`),t.bodyField&&n.push(`body-field="${h(t.bodyField)}"`),t.limit&&n.push(`limit="${h(t.limit)}"`),Object.entries(e.extras).forEach(([i,l])=>n.push(`${i}="${h(l)}"`)),`[collection ${n.join(" ")} /]`}function z(){$&&(clearTimeout($),$=null),k&&(k.remove(),k=null,a=null,T=null)}function le(){const e=U();if(T){const{start:t,end:n}=T;y.value=y.value.slice(0,t)+e+y.value.slice(n),y.selectionStart=y.selectionEnd=t+e.length}else{const t=y.selectionStart,n=y.selectionEnd;y.value=y.value.slice(0,t)+e+y.value.slice(n),y.selectionStart=y.selectionEnd=t+e.length}y.dispatchEvent(new Event("input",{bubbles:!0})),y.focus(),z()}function d(e,t=""){const n=document.createElement(e);return t&&(n.style.cssText=t),n}const L="padding:7px 10px;border-radius:7px;border:1px solid var(--dm-border,#334155);background:var(--dm-surface,#0f172a);color:var(--dm-text,#e2e8f0);font-size:12px;font-family:inherit;width:100%",j="font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:.07em;color:var(--dm-text-muted,#475569)";function S(e,t){const n=d("div","display:flex;flex-direction:column;gap:5px"),i=d("div",j);return i.textContent=e,n.appendChild(i),n.appendChild(t),n}function H(){return d("div","height:1px;background:var(--dm-border,#334155);margin:2px 0")}function de(){k=d("div","position:fixed;inset:0;background:rgba(0,0,0,.6);display:flex;align-items:center;justify-content:center;z-index:9999;padding:24px;isolation:isolate");const e=d("div","background:var(--dm-surface,#1e293b);border:1px solid var(--dm-border,#334155);border-radius:14px;width:100%;max-width:960px;max-height:90vh;display:flex;flex-direction:column;box-shadow:var(--dm-shadow-lg);overflow:hidden"),t=d("div","display:flex;align-items:center;justify-content:space-between;padding:14px 20px;border-bottom:1px solid var(--dm-border,#334155);flex-shrink:0"),n=d("span","font-weight:700;color:var(--dm-text,#f1f5f9);font-size:14px");n.textContent=T?"Edit Timeline":"Insert Timeline";const i=d("button","background:var(--dm-border,#334155);border:none;color:var(--dm-text-muted,#94a3b8);border-radius:6px;width:26px;height:26px;cursor:pointer;font-size:14px");i.textContent="\u2715",i.addEventListener("click",z),t.appendChild(n),t.appendChild(i);const l=d("div","display:grid;grid-template-columns:340px 1fr;flex:1;overflow:hidden");l.appendChild(ae()),l.appendChild(fe());const o=d("div","display:flex;justify-content:flex-end;gap:10px;padding:12px 20px;border-top:1px solid var(--dm-border,#334155);flex-shrink:0"),m=d("button","padding:8px 18px;border-radius:8px;border:none;background:var(--dm-border,#334155);color:var(--dm-text-muted,#94a3b8);font-size:12px;font-weight:700;cursor:pointer");m.textContent="Cancel",m.addEventListener("click",z);const s=d("button","padding:8px 18px;border-radius:8px;border:none;background:var(--dm-primary,#6366f1);color:var(--dm-primary-text,#fff);font-size:12px;font-weight:700;cursor:pointer");s.textContent=T?"Save Timeline":"Insert Timeline",s.addEventListener("click",le),o.appendChild(m),o.appendChild(s),e.appendChild(t),e.appendChild(l),e.appendChild(o),k.appendChild(e),k.addEventListener("click",c=>{c.target===k&&z()}),document.body.appendChild(k),x()}function ae(){const e=d("div","padding:18px;border-right:1px solid var(--dm-border,#334155);display:flex;flex-direction:column;gap:14px;overflow-y:auto");e.appendChild(re()),e.appendChild(H()),e.appendChild(S("Layout",V("layout",P.map(i=>[i,G(i)])))),e.appendChild(S("Theme",V("theme",M.map(i=>[i,G(i)])))),e.appendChild(S("Mode",se())),e.appendChild(H());const t=d("div","display:flex;flex-direction:column;gap:12px");t.id="tb-static",t.appendChild(ce()),e.appendChild(t);const n=d("div","display:flex;flex-direction:column;gap:12px");return n.id="tb-collection",n.appendChild(me()),e.appendChild(n),K(),e}function re(){const e=d("div","display:flex;gap:6px"),t=(n,i)=>{const l=d("button"),o=()=>{const m=a.mode===n;l.style.cssText=`flex:1;padding:8px 10px;border-radius:8px;border:1px solid;font-size:12px;font-weight:700;cursor:pointer;${m?"border-color:var(--dm-primary,#6366f1);background:color-mix(in srgb, var(--dm-primary,#6366f1) 15%, transparent);color:var(--dm-primary,#a5b4fc)":"border-color:var(--dm-border,#334155);background:var(--dm-surface,#0f172a);color:var(--dm-text-muted,#94a3b8)"}`};return l.type="button",l.textContent=i,o(),l.addEventListener("click",()=>{a.mode=n,e.querySelectorAll("button").forEach(m=>m._paint&&m._paint()),K(),x()}),l._paint=o,l};return e.appendChild(t("static","Static")),e.appendChild(t("collection","From Collection")),e}function K(){const e=document.getElementById("tb-static"),t=document.getElementById("tb-collection");e&&(e.style.display=a.mode==="static"?"":"none"),t&&(t.style.display=a.mode==="collection"?"":"none")}function V(e,t){const n=d("select",L+";cursor:pointer");return t.forEach(([i,l])=>{const o=document.createElement("option");o.value=i,o.textContent=l,i===a[e]&&(o.selected=!0),n.appendChild(o)}),n.addEventListener("change",()=>{a[e]=n.value,x()}),n}function se(){const e=d("label","display:flex;align-items:center;gap:.5rem;cursor:pointer;font-size:12px;color:var(--dm-text,#e2e8f0)"),t=document.createElement("input");return t.type="checkbox",t.checked=!!a.roadmap,t.addEventListener("change",()=>{a.roadmap=t.checked,x()}),e.appendChild(t),e.appendChild(document.createTextNode("Roadmap mode")),e}function ce(){const e=d("div","display:flex;flex-direction:column;gap:8px"),t=d("div","display:flex;align-items:center;justify-content:space-between"),n=d("div",j);n.textContent="Events";const i=d("button","padding:4px 10px;border-radius:6px;border:1px dashed var(--dm-border,#334155);background:transparent;color:var(--dm-text-muted,#94a3b8);font-size:11px;cursor:pointer");i.type="button",i.textContent="+ Add event",i.addEventListener("click",()=>{a.events.push({title:"New Event",date:"",status:"",icon:"",body:"",extras:{}}),N(),x()}),t.appendChild(n),t.appendChild(i),e.appendChild(t);const l=d("div","display:flex;flex-direction:column;gap:8px");return l.id="tb-events",e.appendChild(l),N(l),e}function N(e){const t=e||document.getElementById("tb-events");if(t){for(;t.firstChild;)t.removeChild(t.firstChild);a.events.forEach((n,i)=>t.appendChild(pe(n,i)))}}function pe(e,t){const n=d("div","border:1px solid var(--dm-border,#334155);border-radius:8px;padding:10px;background:var(--dm-background-alt,#0b1120);display:flex;flex-direction:column;gap:8px");n.draggable=!0,n.dataset.idx=String(t);const i=d("div","display:flex;align-items:center;gap:6px"),l=d("span","cursor:grab;color:var(--dm-text-muted,#475569);font-size:14px;user-select:none;padding:0 4px");l.textContent="\u2261",l.title="Drag to reorder",i.appendChild(l);const o=d("div","flex:1;font-size:12px;color:var(--dm-text,#e2e8f0);font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis");o.textContent=e.title||"(untitled event)",i.appendChild(o);const m=(r,f,b,E)=>{const _=d("button",`padding:2px 6px;border-radius:5px;border:1px solid var(--dm-border,#334155);background:transparent;color:var(--dm-text-muted,#94a3b8);font-size:11px;cursor:${E?"not-allowed":"pointer"};opacity:${E?"0.4":"1"}`);return _.type="button",_.title=f,_.textContent=r,E||_.addEventListener("click",b),_};i.appendChild(m("\u2191","Move up",()=>Y(t,-1),t===0)),i.appendChild(m("\u2193","Move down",()=>Y(t,1),t===a.events.length-1)),i.appendChild(m("\u2715","Delete",()=>ue(t),a.events.length<=1)),n.appendChild(i);const s=W(e.title,"Event title",r=>{e.title=r,o.textContent=r||"(untitled event)",x()});n.appendChild(A("Title",s));const c=d("div","display:grid;grid-template-columns:1fr 1fr;gap:6px"),u=document.createElement("input");u.type="date",u.value=e.date||"",u.style.cssText=L,u.addEventListener("input",()=>{e.date=u.value,x()}),c.appendChild(A("Date",u));const w=document.createElement("select");w.style.cssText=L+";cursor:pointer",ne.forEach(r=>{const f=document.createElement("option");f.value=r,f.textContent=r===""?"\u2014 none \u2014":G(r),r===e.status&&(f.selected=!0),w.appendChild(f)}),w.addEventListener("change",()=>{e.status=w.value,x()}),c.appendChild(A("Status",w)),n.appendChild(c);const g=d("div","display:flex;gap:6px"),C=W(e.icon,"e.g. rocket",r=>{e.icon=r,x()});C.style.flex="1";const p=d("button","padding:0 10px;background:var(--dm-border,#334155);border:none;color:var(--dm-text-muted,#94a3b8);border-radius:7px;font-size:12px;cursor:pointer;flex-shrink:0");p.type="button",p.title="Browse icons",p.textContent="\u2605",p.addEventListener("click",()=>Q(r=>{e.icon=r,C.value=r,x()})),g.appendChild(C),g.appendChild(p),n.appendChild(A("Icon",g));const v=document.createElement("textarea");return v.value=e.body||"",v.rows=2,v.style.cssText=L+";resize:vertical;min-height:48px;line-height:1.5",v.addEventListener("input",()=>{e.body=v.value,x()}),n.appendChild(A("Body (Markdown)",v)),n.addEventListener("dragstart",r=>{r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",String(t)),n.style.opacity="0.5"}),n.addEventListener("dragend",()=>{n.style.opacity=""}),n.addEventListener("dragover",r=>{r.preventDefault(),r.dataTransfer.dropEffect="move",n.style.borderColor="var(--dm-primary,#6366f1)"}),n.addEventListener("dragleave",()=>{n.style.borderColor="var(--dm-border,#334155)"}),n.addEventListener("drop",r=>{r.preventDefault(),n.style.borderColor="var(--dm-border,#334155)";const f=parseInt(r.dataTransfer.getData("text/plain"),10);if(Number.isNaN(f)||f===t)return;const[b]=a.events.splice(f,1);a.events.splice(t,0,b),N(),x()}),n}function Y(e,t){const n=e+t;if(n<0||n>=a.events.length)return;const[i]=a.events.splice(e,1);a.events.splice(n,0,i),N(),x()}function ue(e){a.events.length<=1||(a.events.splice(e,1),N(),x())}function W(e,t,n){const i=document.createElement("input");return i.type="text",i.value=e||"",i.placeholder=t||"",i.style.cssText=L,i.addEventListener("input",()=>n(i.value)),i}function A(e,t){const n=d("div","display:flex;flex-direction:column;gap:4px"),i=d("div","font-size:10px;font-weight:600;color:var(--dm-text-muted,#64748b);letter-spacing:.04em");return i.textContent=e,n.appendChild(i),n.appendChild(t),n}function me(){const e=d("div","display:flex;flex-direction:column;gap:10px"),t=d("select",L+";cursor:pointer"),n=document.createElement("option");n.value="",n.textContent="Loading collections\u2026",t.appendChild(n),e.appendChild(S("Collection",t));const i=B("titleField"),l=B("dateField"),o=B("statusField"),m=B("iconField"),s=B("bodyField");e.appendChild(S("Title field",i));const c=d("div","display:grid;grid-template-columns:1fr 1fr;gap:8px");c.appendChild(S("Date field",l)),c.appendChild(S("Status field",o)),e.appendChild(c),e.appendChild(S("Icon field",m)),e.appendChild(S("Body field",s));const u=W(a.collection.limit,"All",p=>{a.collection.limit=p,x()});u.type="number",u.min="1",e.appendChild(S("Limit (optional)",u));const w=d("div","font-size:11px;color:var(--dm-text-muted,#64748b);line-height:1.4");w.textContent="Picks entries in their default collection order. Set date, status, and icon fields to drive visual cues on the page.",e.appendChild(w);const g=p=>{[i,l,o,m,s].forEach(b=>{for(;b.firstChild;)b.removeChild(b.firstChild);const E=document.createElement("option");E.value="",E.textContent="\u2014 none \u2014",b.appendChild(E),p.forEach(_=>{const D=document.createElement("option");D.value=_.name,D.textContent=_.label||_.name,b.appendChild(D)})});const r=new Set(p.map(b=>b.name)),f=(b,E)=>{a.collection[b]&&r.has(a.collection[b])||(a.collection[b]=r.has(E)?E:"")};f("titleField","title"),f("dateField","date"),f("statusField","status"),f("iconField","icon"),f("bodyField","description"),i.value=a.collection.titleField,l.value=a.collection.dateField,o.value=a.collection.statusField,m.value=a.collection.iconField,s.value=a.collection.bodyField},C=async p=>{if(!p){g([]);return}try{const v=F.onGetCollection?await F.onGetCollection(p):null,r=v&&v.fields||[];g(r)}catch{g([])}};return t.addEventListener("change",()=>{a.collection.slug=t.value,C(t.value).then(x)}),(async()=>{let p=[];try{p=F.onListCollections?await F.onListCollections():[]}catch{p=[]}for(;t.firstChild;)t.removeChild(t.firstChild);if(!p.length){const r=document.createElement("option");r.value="",r.textContent="No collections available",t.appendChild(r),g([]);return}p.forEach(r=>{const f=document.createElement("option");f.value=r.slug,f.textContent=r.title||r.slug,t.appendChild(f)});const v=a.collection.slug;v&&p.some(r=>r.slug===v)?t.value=v:(a.collection.slug=p[0].slug,t.value=p[0].slug),await C(t.value),x()})(),e}function B(e){const t=d("select",L+";cursor:pointer"),n=document.createElement("option");return n.value="",n.textContent="\u2014 none \u2014",t.appendChild(n),t.addEventListener("change",()=>{a.collection[e]=t.value,x()}),t}function fe(){const e=d("div","padding:20px;background:var(--dm-surface,#0f172a);display:flex;flex-direction:column;gap:14px;overflow-y:auto"),t=d("div",j);t.textContent="Live Preview";const n=d("div","flex:1;min-height:160px;background:var(--dm-background-alt,#fff);border-radius:10px;padding:16px;color:var(--dm-text,#0f172a)");n.id="tb-preview-area";const i=d("div",j+";margin-bottom:4px");i.textContent="Shortcode";const l=d("pre","background:var(--dm-background-alt,#1e293b);border:1px solid var(--dm-border,#334155);border-radius:8px;padding:10px 14px;font-family:monospace;font-size:11px;color:var(--dm-primary,#a5b4fc);line-height:1.6;white-space:pre-wrap;word-break:break-word;max-height:160px;overflow:auto;margin:0");return l.id="tb-snippet",e.appendChild(t),e.appendChild(n),e.appendChild(i),e.appendChild(l),e}function x(){const e=document.getElementById("tb-snippet");e&&(e.textContent=U()),he()}function he(){$&&clearTimeout($),$=setTimeout(ve,300)}async function ve(){const e=document.getElementById("tb-preview-area");if(!e)return;const t=U(),n=++q;xe(e);try{const i=F.onPreview?await F.onPreview(t):null;if(n!==q)return;if(!i||typeof i.html!="string"){J(e);return}X(e,i.html),typeof I<"u"&&I.scan&&I.scan(e)}catch{if(n!==q)return;J(e)}}function xe(e){if(!e.dataset.loaded){for(;e.firstChild;)e.removeChild(e.firstChild);const t=d("div","color:var(--dm-text-muted,#94a3b8);font-size:12px");t.textContent="Rendering preview\u2026",e.appendChild(t),e.dataset.loaded="1"}}function J(e){for(;e.firstChild;)e.removeChild(e.firstChild);const t=d("div","color:var(--dm-text-muted,#94a3b8);font-size:12px;font-style:italic");t.textContent="Preview unavailable",e.appendChild(t)}function G(e){return e.charAt(0).toUpperCase()+e.slice(1)}
|
|
@@ -144,7 +144,7 @@
|
|
|
144
144
|
|
|
145
145
|
<div class="ep-results-col">
|
|
146
146
|
<div class="card" id="tryit-results-placeholder">
|
|
147
|
-
<div class="card-body" style="text-align:center;color:var(--
|
|
147
|
+
<div class="card-body" style="text-align:center;color:var(--dm-text-muted,#8a94a6);padding:2rem 1rem;">
|
|
148
148
|
<div data-icon="zap" style="font-size:1.5rem;opacity:.5;"></div>
|
|
149
149
|
<p style="margin:.5rem 0 0;font-size:.9rem;">Send a request to see the response here.</p>
|
|
150
150
|
</div>
|
|
@@ -158,7 +158,7 @@
|
|
|
158
158
|
</div>
|
|
159
159
|
</div>
|
|
160
160
|
<div class="card-body" style="padding-top:.5rem;">
|
|
161
|
-
<div id="tryit-json" style="max-height:460px;overflow:auto;font-family:var(--font-mono,ui-monospace,monospace);font-size:.8rem;line-height:1.5;padding:.6rem;"></div>
|
|
161
|
+
<div id="tryit-json" style="max-height:460px;overflow:auto;font-family:var(--dm-font-mono,ui-monospace,monospace);font-size:.8rem;line-height:1.5;padding:.6rem;"></div>
|
|
162
162
|
<pre id="tryit-body" style="display:none;max-height:460px;overflow:auto;font-size:.8rem;padding:.6rem;margin:0;white-space:pre-wrap;word-break:break-word;"></pre>
|
|
163
163
|
</div>
|
|
164
164
|
</div>
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
<div id="block-sample-data" style="
|
|
111
111
|
border-bottom:1px solid var(--dm-border,rgba(255,255,255,.08));
|
|
112
112
|
padding:.6rem .75rem;
|
|
113
|
-
background:var(--dm-
|
|
113
|
+
background:var(--dm-background-alt,rgba(0,0,0,.1));
|
|
114
114
|
flex-shrink:0;">
|
|
115
115
|
<p class="text-muted" style="font-size:.8rem;margin:0;">
|
|
116
116
|
Write some template HTML to populate sample data fields.
|