domma-cms 0.50.0 → 0.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +6 -0
- package/admin/css/admin.css +1 -1
- package/admin/js/api.js +1 -1
- package/admin/js/templates/page-editor.html +26 -1
- package/admin/js/views/page-editor.js +25 -25
- package/package.json +1 -1
- package/server/routes/api/pages.js +85 -1
- package/server/routes/public.js +56 -0
- package/server/services/content.js +27 -0
- package/server/services/previewLinks.js +215 -0
- package/server/services/renderer.js +69 -31
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import{api as
|
|
1
|
+
import{api as k}from"../api.js";import{CardBuilder as Me}from"../lib/card-builder.js";import{TimelineBuilder as Re}from"../lib/timeline-builder.js";import{attachEditorKeybindings as Ie,createToolbar as He,insertAtCursor as $e}from"../lib/markdown-toolbar.js";import{EffectsBuilder as qe}from"../lib/effects-builder.js";import{attachContextMenu as Ue}from"../lib/shortcode-context-menu.js";import{registerCustomInserters as Oe}from"../lib/shortcode-insert.js";import{populateThemeSelect as Ve}from"../lib/themes.js";import{createFoldingManager as We}from"../lib/editor-folding.js";import{openScribeComposer as Ge}from"../lib/scribe-composer.js";import{openCrudTutorial as Ye}from"../lib/crud-tutorial.js";function _e(){const e=E.slideover({title:"Editor Reference",size:"md",position:"right"}),P="background:var(--dm-background-alt,#1a1a2e);padding:.2rem .4rem;border-radius:3px;font-size:.85em;font-family:monospace;",f="margin:1rem 0 .5rem;font-size:1rem;";function r(d){const l=document.createElement("code");return l.style.cssText=P,l.textContent=d,l}function g(d){const l=document.createElement("h3");return l.style.cssText=f,l.textContent=d,l}const X=document.createElement("div");X.style.cssText="padding:1rem;";const Q=document.createElement("div");Q.className="tabs";const ee=document.createElement("div");ee.className="tab-list",["Basics","Layout","Components","Data","Advanced"].forEach((d,l)=>{const n=document.createElement("button");n.className="tab-item"+(l===0?" active":""),n.textContent=d,ee.appendChild(n)});const c=document.createElement("div");c.className="tab-content";const V="display:flex;flex-direction:column;gap:1rem;",H=document.createElement("div");H.className="tab-panel active",H.style.cssText=V;const q=document.createElement("div");q.className="tab-panel",q.style.cssText=V;const N=document.createElement("div");N.className="tab-panel",N.style.cssText=V;const F=document.createElement("div");F.className="tab-panel",F.style.cssText=V;const _=document.createElement("div");_.className="tab-panel",_.style.cssText=V,c.appendChild(H),c.appendChild(q),c.appendChild(N),c.appendChild(F),c.appendChild(_),Q.appendChild(ee),Q.appendChild(c),X.appendChild(Q);const G=document.createElement("div");G.appendChild(g("Markdown Basics"));const B=document.createElement("table");B.style.cssText="width:100%;border-collapse:collapse;font-size:.9em;";const s=document.createElement("thead"),v=document.createElement("tr");["Syntax","Result"].forEach(d=>{const l=document.createElement("th");l.style.cssText="text-align:left;padding:.4rem .5rem;border-bottom:1px solid var(--dm-border,#333);",l.textContent=d,v.appendChild(l)}),s.appendChild(v),B.appendChild(s);const M=document.createElement("tbody");[["**bold**","bold (rendered bold)"],["_italic_","italic (rendered italic)"],["## Heading","Heading (h2)"],["[text](url)","Link"],["","Image"],["- item","Bullet list"],["`code`","Inline code"],["---","Divider"]].forEach(([d,l])=>{const n=document.createElement("tr"),a=document.createElement("td");a.style.cssText="padding:.35rem .5rem;vertical-align:top;",a.appendChild(r(d));const o=document.createElement("td");o.style.cssText="padding:.35rem .5rem;vertical-align:top;color:var(--dm-text-muted,#aaa);font-size:.85em;",o.textContent=l,n.appendChild(a),n.appendChild(o),M.appendChild(n)}),B.appendChild(M),G.appendChild(B),H.appendChild(G);const w=document.createElement("div");w.appendChild(g("Grid & Columns"));function m(d){const l=document.createElement("p");return l.style.cssText="margin:.3rem 0 .6rem;font-size:.82em;color:var(--dm-text-muted,#aaa);",l.textContent=d,l}function i(d,l,n){const a=document.createElement("p");a.style.cssText="margin:.75rem 0 .25rem;font-size:.85em;font-weight:600;",a.textContent=d;const o=document.createElement("div");o.style.cssText="position:relative;";const ye=document.createElement("pre");ye.style.cssText=P+"display:block;padding:.5rem 2rem .5rem .75rem;white-space:pre;overflow-x:auto;margin:0;",ye.textContent=l;const Z=document.createElement("button");Z.type="button",Z.title="Copy code",Z.style.cssText="position:absolute;top:.3rem;right:.3rem;background:none;border:none;cursor:pointer;opacity:.45;padding:.15rem;line-height:1;color:inherit;",Z.addEventListener("mouseenter",()=>{Z.style.opacity="1"}),Z.addEventListener("mouseleave",()=>{Z.style.opacity=".45"});const Ne=document.createElement("span");Ne.setAttribute("data-icon","copy"),Z.appendChild(Ne),Z.addEventListener("click",()=>{const we=document.createElement("textarea");we.value=l,we.style.cssText="position:fixed;opacity:0;",document.body.appendChild(we),we.select(),document.execCommand("copy"),we.remove(),E.toast("Copied!",{type:"success",duration:1200})}),o.appendChild(ye),o.appendChild(Z);const xe=document.createDocumentFragment();return xe.appendChild(a),xe.appendChild(o),n&&xe.appendChild(m(n)),xe}const C=document.createElement("table");C.style.cssText="width:100%;border-collapse:collapse;font-size:.85em;margin-bottom:.5rem;",[['cols="N"',"[grid] only","Number of columns (1-12)"],['gap="N"',"[grid], [row]","Gap between columns/rows (1-6)"],['span="N"',"[col] only","How many columns this cell spans"],['fullwidth="true"',"[grid] only","Break out of page container to span full viewport"],['class="x"',"all","Add extra CSS classes"]].forEach(([d,l,n])=>{const a=document.createElement("tr");[d,l,n].forEach((o,ye)=>{const Z=document.createElement("td");Z.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;",ye===0?Z.appendChild(r(d)):(Z.style.color="var(--dm-text-muted,#aaa)",Z.textContent=o),a.appendChild(Z)}),C.appendChild(a)}),w.appendChild(C),w.appendChild(i("Equal columns",`[grid cols="3" gap="4"]
|
|
2
2
|
[col]One[/col]
|
|
3
3
|
[col]Two[/col]
|
|
4
4
|
[col]Three[/col]
|
|
5
|
-
[/grid]`,"cols sets the track count; each [col] fills one track.")),
|
|
5
|
+
[/grid]`,"cols sets the track count; each [col] fills one track.")),w.appendChild(i("Column spanning (12-col base)",`[grid cols="12" gap="3"]
|
|
6
6
|
[col span="8"]Main content[/col]
|
|
7
7
|
[col span="4"]Sidebar[/col]
|
|
8
|
-
[/grid]`,"span values must add up to cols. Common splits: 8/4, 6/6, 9/3.")),
|
|
8
|
+
[/grid]`,"span values must add up to cols. Common splits: 8/4, 6/6, 9/3.")),w.appendChild(i("Row (flexbox, equal-width)",`[row gap="4"]
|
|
9
9
|
[col]Left[/col]
|
|
10
10
|
[col]Right[/col]
|
|
11
|
-
[/row]`,"Use [row] when you want equal-width columns without specifying a count.")),
|
|
11
|
+
[/row]`,"Use [row] when you want equal-width columns without specifying a count.")),w.appendChild(i("Row with staggered reveal",`[row reveal reveal-mode="stagger" reveal-animation="slide-up" reveal-duration="400" reveal-stagger="60" reveal-delay="0" reveal-direction="ltr"]
|
|
12
12
|
[col]First[/col]
|
|
13
13
|
[col]Second[/col]
|
|
14
14
|
[col]Third[/col]
|
|
15
|
-
[/row]`,'Columns reveal one by one as the row scrolls into view. reveal-direction="rtl" reverses the order. Animations: slide-up, slide-down, slide-left, slide-right, fade, zoom, flip.')),
|
|
15
|
+
[/row]`,'Columns reveal one by one as the row scrolls into view. reveal-direction="rtl" reverses the order. Animations: slide-up, slide-down, slide-left, slide-right, fade, zoom, flip.')),w.appendChild(i("Card in a grid",`[grid cols="3" gap="4"]
|
|
16
16
|
[col]
|
|
17
17
|
[card title="One"]Content[/card]
|
|
18
18
|
[/col]
|
|
@@ -22,21 +22,21 @@ import{api as A}from"../api.js";import{CardBuilder as Me}from"../lib/card-builde
|
|
|
22
22
|
[col]
|
|
23
23
|
[card title="Three"]Content[/card]
|
|
24
24
|
[/col]
|
|
25
|
-
[/grid]`,null)),
|
|
25
|
+
[/grid]`,null)),q.appendChild(w);const U=document.createElement("div");U.appendChild(g("Cards")),U.appendChild(i("Basic card",`[card title="Optional Title"]
|
|
26
26
|
Markdown **works** here.
|
|
27
|
-
[/card]`,"Omit title for a card with no header.")),
|
|
27
|
+
[/card]`,"Omit title for a card with no header.")),U.appendChild(i("Icon - inline (default)",`[card title="Feature" icon="star"]
|
|
28
28
|
Icon sits left of the title in a flex row.
|
|
29
|
-
[/card]`,"icon accepts any Domma icon name. Default layout when icon is set.")),
|
|
29
|
+
[/card]`,"icon accepts any Domma icon name. Default layout when icon is set.")),U.appendChild(i("Icon - stacked (centred)",`[card title="Feature" icon="star" icon-layout="stacked" hover]
|
|
30
30
|
Icon is centred above the title. Great for feature tiles.
|
|
31
|
-
[/card]`,'icon-layout="stacked" centres the icon above the title. Combine with hover for a lift effect.')),
|
|
31
|
+
[/card]`,'icon-layout="stacked" centres the icon above the title. Combine with hover for a lift effect.')),U.appendChild(i("Icon with subtitle",`[card title="Feature" subtitle="Tagline here" icon="star" icon-layout="stacked"]
|
|
32
32
|
Body content.
|
|
33
|
-
[/card]`,"subtitle adds a secondary line beneath the title in both layouts.")),
|
|
33
|
+
[/card]`,"subtitle adds a secondary line beneath the title in both layouts.")),U.appendChild(i("Collapsible card",`[card title="Click to expand" collapsible="true"]
|
|
34
34
|
Hidden by default.
|
|
35
|
-
[/card]`,null)),
|
|
35
|
+
[/card]`,null)),U.appendChild(i("Full attribute reference",`[card title="Title" subtitle="Sub" icon="star" icon-layout="stacked"
|
|
36
36
|
variant="primary" hover footer="Footer text"
|
|
37
37
|
collapsible="true" class="extra" id="my-card"]
|
|
38
38
|
Body content.
|
|
39
|
-
[/card]`,'All attributes are optional. variant accepts "primary". icon-layout accepts "inline" (default) or "stacked".')),
|
|
39
|
+
[/card]`,'All attributes are optional. variant accepts "primary". icon-layout accepts "inline" (default) or "stacked".')),U.appendChild(i("Rich header / footer sub-tags",`[card]
|
|
40
40
|
[header]
|
|
41
41
|
### Custom Title with **bold** and [a link](/about)
|
|
42
42
|
[/header]
|
|
@@ -46,47 +46,47 @@ Body content here.
|
|
|
46
46
|
[footer]
|
|
47
47
|
[Read more](/about) | [icon name="arrow-right" /]
|
|
48
48
|
[/footer]
|
|
49
|
-
[/card]`,"Use [header] and [footer] sub-tags for Markdown-rendered header/footer regions. Sub-tags override the title/subtitle/icon and footer attributes when both are present.")),
|
|
49
|
+
[/card]`,"Use [header] and [footer] sub-tags for Markdown-rendered header/footer regions. Sub-tags override the title/subtitle/icon and footer attributes when both are present.")),N.appendChild(U);const ne=document.createElement("div");ne.appendChild(g("Badge")),ne.appendChild(m("Inline badge/label elements. Self-closing renders an empty coloured dot."));const re=document.createElement("table");re.style.cssText="width:100%;border-collapse:collapse;font-size:.85em;margin-bottom:.5rem;",[['variant="..."',"primary (default), secondary, success, danger, warning, info, light, dark"],["pill","Flag: rounded pill shape (.badge-pill)"],["outline","Flag: outlined style (.badge-outline)"],['size="small|large"',"Reduced or enlarged badge"]].forEach(([d,l])=>{const n=document.createElement("tr"),a=document.createElement("td");a.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;",a.appendChild(r(d));const o=document.createElement("td");o.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;color:var(--dm-text-muted,#aaa);",o.textContent=l,n.appendChild(a),n.appendChild(o),re.appendChild(n)}),ne.appendChild(re),ne.appendChild(i("Basic badge",'[badge variant="success"]New[/badge]',null)),ne.appendChild(i("Pill outline badge",'[badge variant="danger" outline pill]Deprecated[/badge]',null)),N.appendChild(ne);const h=document.createElement("div");h.appendChild(g("Button")),h.appendChild(m("Renders a styled anchor as a Domma button. Use the Insert \u2192 Button toolbar item for a guided dialog."));const x=document.createElement("table");x.style.cssText="width:100%;border-collapse:collapse;font-size:.85em;margin-bottom:.5rem;",[['href="..."',"Link destination (required)"],['label="..."',"Button text (self-closing form)"],['variant="..."',"primary (default), secondary, success, danger, warning, info, outline, ghost, link, outline-*"],['size="sm|lg"',"Button size modifier"],['icon="..."',"Domma icon name before the label"],['icon-after="..."',"Domma icon name after the label"],['target="..."','Link target, e.g. "_blank"'],['class="..."',"Extra CSS classes"],['id="..."',"Element id"]].forEach(([d,l])=>{const n=document.createElement("tr"),a=document.createElement("td");a.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;",a.appendChild(r(d));const o=document.createElement("td");o.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;color:var(--dm-text-muted,#aaa);",o.textContent=l,n.appendChild(a),n.appendChild(o),x.appendChild(n)}),h.appendChild(x),h.appendChild(i("Primary button",'[button href="/contact" variant="primary"]Get in touch[/button]',null)),h.appendChild(i("Self-closing with icon",'[button href="/download" variant="success" icon="download" size="sm" label="Download" /]',null)),h.appendChild(i("Opens in new tab",'[button href="https://example.com" variant="outline" target="_blank"]Visit site[/button]',null)),N.appendChild(h);const W=document.createElement("div");W.appendChild(g("Link (shortcode)")),W.appendChild(m("Renders a plain anchor with optional icon, target, and class. Use Insert \u2192 Link for a guided dialog. For simple inline links, standard Markdown [text](url) is fine."));const ae=document.createElement("table");ae.style.cssText="width:100%;border-collapse:collapse;font-size:.85em;margin-bottom:.5rem;",[['href="..."',"Link destination (required)"],['label="..."',"Link text (self-closing form)"],['target="..."','Link target, e.g. "_blank"'],['class="..."',"CSS classes on the <a>"],['icon="..."',"Domma icon name before the text"],['icon-after="..."',"Domma icon name after the text"],['id="..."',"Element id"]].forEach(([d,l])=>{const n=document.createElement("tr"),a=document.createElement("td");a.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;",a.appendChild(r(d));const o=document.createElement("td");o.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;color:var(--dm-text-muted,#aaa);",o.textContent=l,n.appendChild(a),n.appendChild(o),ae.appendChild(n)}),W.appendChild(ae),W.appendChild(i("External link in new tab",'[link href="https://example.com" target="_blank" icon-after="external-link"]Visit site[/link]',null)),W.appendChild(i("Self-closing with icon",'[link href="/about" icon="arrow-right" label="About us" /]',null)),N.appendChild(W);const oe=document.createElement("div");oe.appendChild(g("Spacer")),oe.appendChild(m("Self-closing shortcode that inserts a fixed-height blank gap."));const Y=document.createElement("table");Y.style.cssText="width:100%;border-collapse:collapse;font-size:.85em;margin-bottom:.5rem;",[['size="N"',"Height in px (default: 8)"],['class="..."',"Extra CSS class on the spacer div"]].forEach(([d,l])=>{const n=document.createElement("tr"),a=document.createElement("td");a.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;",a.appendChild(r(d));const o=document.createElement("td");o.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;color:var(--dm-text-muted,#aaa);",o.textContent=l,n.appendChild(a),n.appendChild(o),Y.appendChild(n)}),oe.appendChild(Y),oe.appendChild(i("32px gap",'[spacer size="32" /]',null)),q.appendChild(oe);const ie=document.createElement("div");ie.appendChild(g("Icon")),ie.appendChild(m("Self-closing shortcode that renders any Domma icon inline."));const j=document.createElement("table");j.style.cssText="width:100%;border-collapse:collapse;font-size:.85em;margin-bottom:.5rem;",[['name="..."',"Domma icon name (required). Also accepted as src=."],['size="N"',"Width and height in px"],['color="..."',"CSS colour applied via style"],['class="..."',"Extra CSS classes"]].forEach(([d,l])=>{const n=document.createElement("tr"),a=document.createElement("td");a.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;",a.appendChild(r(d));const o=document.createElement("td");o.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;color:var(--dm-text-muted,#aaa);",o.textContent=l,n.appendChild(a),n.appendChild(o),j.appendChild(n)}),ie.appendChild(j),ie.appendChild(i("Coloured icon",'[icon name="star" size="24" color="#f5a623" /]',null)),N.appendChild(ie);const le=document.createElement("div");le.appendChild(g("Center")),le.appendChild(m("Wraps content in a centred div. Works with any content including cards, grids, and text.")),le.appendChild(i("Example","[center]Centred content here[/center]",'Accepts an optional class="..." attribute for extra styling.')),q.appendChild(le);const J=document.createElement("div");J.appendChild(g("Hero")),J.appendChild(m("Full-width hero sections - no plugin required. Uses Domma's built-in Hero CSS component."));const T=document.createElement("table");T.style.cssText="width:100%;border-collapse:collapse;font-size:.85em;margin-bottom:.5rem;",[['title="..."',"Heading text"],['tagline="..."',"Subtitle text"],['size="sm|lg|full"',"Height variant (default: normal)"],['variant="dark|primary|gradient-blue|gradient-purple|gradient-sunset|gradient-ocean"',"Colour / gradient preset"],['image="url"',"Background image URL (adds cover mode)"],['overlay="light|dark|darker|gradient|gradient-reverse"',"Image overlay style"],['align="center|left"',"Content alignment (default: center)"],['fullwidth="true"',"Break out of the page container to span full viewport width"],['bg="..."',"Background colour CSS value"],["twinkle","Flag: adds particle overlay (requires Effects plugin)"],['twinkle-count="N"',"Number of particles"],['twinkle-colour="..."',"Particle colour CSS value"],["blobs","Flag: adds ambient blob background"],['blobs-type="..."',"Blob animation type (default: float-blobs)"],['class="..."',"Extra CSS classes"],['id="..."',"Element id"]].forEach(([d,l])=>{const n=document.createElement("tr"),a=document.createElement("td");a.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;",a.appendChild(r(d));const o=document.createElement("td");o.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;color:var(--dm-text-muted,#aaa);",o.textContent=l,n.appendChild(a),n.appendChild(o),T.appendChild(n)}),J.appendChild(T),J.appendChild(i("Basic hero",'[hero title="Welcome" tagline="Build something great"][/hero]',null)),J.appendChild(i("Gradient with body content",`[hero title="Get Started" tagline="Everything you need." size="lg" variant="gradient-blue" align="center"]
|
|
50
50
|
Some introductory **Markdown** content here.
|
|
51
|
-
[/hero]`,null)),
|
|
51
|
+
[/hero]`,null)),J.appendChild(i("Background image with overlay",'[hero title="Our Story" image="/media/hero.jpg" overlay="dark" size="full"][/hero]',"Combine image + overlay for text legibility over photos.")),q.appendChild(J);const z=document.createElement("div");z.appendChild(g("Interactive Components")),z.appendChild(m("Tabs, accordion, carousel, and countdown - no plugin required.")),z.appendChild(i("Tabs",`[tabs]
|
|
52
52
|
[tab title="First"]Content **A**[/tab]
|
|
53
53
|
[tab title="Second"]Content **B**[/tab]
|
|
54
|
-
[/tabs]`,'Add style="pills" for pill-style navigation.')),
|
|
54
|
+
[/tabs]`,'Add style="pills" for pill-style navigation.')),z.appendChild(i("Accordion",`[accordion]
|
|
55
55
|
[item title="Question 1"]Answer here.[/item]
|
|
56
56
|
[item title="Question 2"]Answer here.[/item]
|
|
57
|
-
[/accordion]`,'Add multiple="true" to allow several panels open at once.')),
|
|
57
|
+
[/accordion]`,'Add multiple="true" to allow several panels open at once.')),z.appendChild(i("Accordion - collection-bound",'[collection slug="faq" display="accordion" title-field="title" body-field="description" /]',"Renders collection entries as accordion items. Use Insert \u2192 Accordion for a guided dialog.")),z.appendChild(i("Carousel",`[carousel autoplay="true" interval="5000"]
|
|
58
58
|
[slide title="Slide 1"]Description[/slide]
|
|
59
59
|
[slide image="/media/photo.jpg" title="Slide 2"]Caption[/slide]
|
|
60
|
-
[/carousel]`,'animation="slide|fade|crossfade" (default slide). Use Insert \u2192 Carousel for a guided dialog.')),
|
|
60
|
+
[/carousel]`,'animation="slide|fade|crossfade" (default slide). Use Insert \u2192 Carousel for a guided dialog.')),z.appendChild(i("Carousel - fade / crossfade",`[carousel animation="crossfade" animation-duration="800" animation-easing="ease-in-out" autoplay="true"]
|
|
61
61
|
[slide image="/media/one.jpg" title="One"][/slide]
|
|
62
62
|
[slide image="/media/two.jpg" title="Two"][/slide]
|
|
63
|
-
[/carousel]`,"fade swaps opacity per slide; crossfade overlaps the two. animation-easing accepts any CSS timing function (ease, linear, cubic-bezier(...)).")),
|
|
63
|
+
[/carousel]`,"fade swaps opacity per slide; crossfade overlaps the two. animation-easing accepts any CSS timing function (ease, linear, cubic-bezier(...)).")),z.appendChild(i("Countdown (to date)",'[countdown to="2026-12-31" format="DD:HH:mm:ss" /]',null)),z.appendChild(i("Countdown (duration)",'[countdown duration="300" format="mm:ss" /]',"duration is in seconds. format options: mm:ss \xB7 HH:mm:ss \xB7 DD:HH:mm:ss")),N.appendChild(z);const te=document.createElement("div");te.appendChild(g("Timeline")),te.appendChild(m("Renders a Domma Progression component with event items."));const se=document.createElement("table");se.style.cssText="width:100%;border-collapse:collapse;font-size:.85em;margin-bottom:.5rem;",[['layout="vertical|centred|horizontal"',"[timeline] - layout orientation (default: vertical)"],['theme="minimal|corporate|modern"',"[timeline] - visual theme (default: minimal)"],['mode="timeline|roadmap"',"[timeline] - display mode (default: timeline)"],['class="..."',"[timeline] - extra CSS classes"],['id="..."',"[timeline] - element id"],['title="..."',"[event] - event heading"],['date="..."',"[event] - display date string"],['status="planned|in-progress|completed|blocked"',"[event] - progress status"],['icon="..."',"[event] - Domma icon name"]].forEach(([d,l])=>{const n=document.createElement("tr"),a=document.createElement("td");a.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;",a.appendChild(r(d));const o=document.createElement("td");o.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;color:var(--dm-text-muted,#aaa);",o.textContent=l,n.appendChild(a),n.appendChild(o),se.appendChild(n)}),te.appendChild(se),te.appendChild(i("Vertical timeline",`[timeline layout="vertical" theme="modern"]
|
|
64
64
|
[event title="Kickoff" date="Jan 2025" status="completed" icon="flag"]
|
|
65
65
|
Project launched.
|
|
66
66
|
[/event]
|
|
67
67
|
[event title="Beta" date="Jun 2025" status="in-progress" icon="rocket"]
|
|
68
68
|
In active development.
|
|
69
69
|
[/event]
|
|
70
|
-
[/timeline]`,null)),
|
|
70
|
+
[/timeline]`,null)),N.appendChild(te);const ce=document.createElement("div");ce.appendChild(g("Embedding a Form"));const ge=document.createElement("table");ge.style.cssText="width:100%;border-collapse:collapse;font-size:.85em;margin-bottom:.5rem;",[['name="..."',"Form slug (required). Also accepted as slug=."],['class="..."',"Extra CSS classes on the wrapper div"],['id="..."',"id attribute on the wrapper div"]].forEach(([d,l])=>{const n=document.createElement("tr"),a=document.createElement("td");a.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;",a.appendChild(r(d));const o=document.createElement("td");o.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;color:var(--dm-text-muted,#aaa);",o.textContent=l,n.appendChild(a),n.appendChild(o),ge.appendChild(n)}),ce.appendChild(ge),ce.appendChild(i("Basic",'[form name="contact" /]',"Forms are managed under Forms in the sidebar.")),ce.appendChild(i("With wrapper styling",'[form name="newsletter" class="mt-4" id="newsletter-form" /]',null)),F.appendChild(ce);const t=document.createElement("div");t.appendChild(g("Displaying a Collection"));const p=document.createElement("pre");p.style.cssText=P+"display:block;padding:.5rem .75rem;white-space:pre;overflow-x:auto;",p.textContent='[collection slug="enquiries" display="table" /]',t.appendChild(p);const b=[["slug","Required. The collection slug."],["display","table (default), cards, or list."],["fields","Comma-separated field keys to show. Defaults to all."],["limit","Maximum number of entries to display."],["sort","Field key to sort by."],["order","asc or desc (default asc)."],["title-field","Field used as the card/list title (cards + list)."],["columns","Grid columns for cards display (2-4, default 3)."],["search","true/false - enable search in table mode (default true)."],["sortable","true/false - enable column sorting in table mode (default true)."],["exportable","true/false - show CSV export button in table mode (default false)."],["page-size","Rows per page in table mode (default 25)."],["empty","Text shown when there are no entries."],["cta","Action slug: enables per-entry CTA buttons."],["cta-label",'CTA button label (default: "Run").'],["cta-icon","CTA button icon name."],["cta-style","CTA button variant (default: primary)."],["cta-confirm","CTA confirmation prompt text."],["class","Extra CSS classes on the wrapper div."],["id","id attribute on the wrapper div."]],y=document.createElement("table");y.style.cssText="width:100%;border-collapse:collapse;font-size:.85em;margin-bottom:.5rem;",b.forEach(([d,l])=>{const n=document.createElement("tr"),a=document.createElement("td");a.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;width:35%;",a.appendChild(r(d));const o=document.createElement("td");o.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;color:var(--dm-text-muted,#aaa);",o.textContent=l,n.appendChild(a),n.appendChild(o),y.appendChild(n)}),t.appendChild(y),t.appendChild(m("Table display uses Domma Table - search, sort, pagination, column selector, and CSV export are all built in. Cards and lists are static.")),F.appendChild(t);const u=document.createElement("div");u.appendChild(g("View - Pro")),u.appendChild(m("Renders a Collection with full filtering, pagination, and display options. Requires a Pro MongoDB collection."));const A=document.createElement("table");A.style.cssText="width:100%;border-collapse:collapse;font-size:.85em;margin-bottom:.5rem;",[["slug","Required. The collection slug."],["display","table (default), cards, or list."],["limit","Maximum number of entries to display."],["fields","Comma-separated field keys to show."],["title-field","Field used as the card/list title."],["columns","Grid columns for cards display (2-4, default 3)."],["empty","Text shown when there are no entries."],["class","Extra CSS classes on the wrapper div."],["id","id attribute on the wrapper div."]].forEach(([d,l])=>{const n=document.createElement("tr"),a=document.createElement("td");a.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;width:35%;",a.appendChild(r(d));const o=document.createElement("td");o.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;color:var(--dm-text-muted,#aaa);",o.textContent=l,n.appendChild(a),n.appendChild(o),A.appendChild(n)}),u.appendChild(A),u.appendChild(i("Table display",'[view slug="products" display="table" limit="50" /]',null)),u.appendChild(i("Cards display",'[view slug="team" display="cards" columns="3" title-field="name" /]',null)),F.appendChild(u);const L=document.createElement("div");L.appendChild(g("CTA - Pro")),L.appendChild(m("Renders an action button that triggers a Pro Action against an entry. Requires the Pro Actions feature."));const de=document.createElement("table");de.style.cssText="width:100%;border-collapse:collapse;font-size:.85em;margin-bottom:.5rem;",[["action","Required. The action slug."],["entry","Required. The entry id to act on."],["style","Button variant (default: primary)."],["icon","Domma icon name for the button."],["size","Button size (sm, lg)."],["confirm","Confirmation prompt text before running."],["label","Self-closing only: button label text."]].forEach(([d,l])=>{const n=document.createElement("tr"),a=document.createElement("td");a.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;width:35%;",a.appendChild(r(d));const o=document.createElement("td");o.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;color:var(--dm-text-muted,#aaa);",o.textContent=l,n.appendChild(a),n.appendChild(o),de.appendChild(n)}),L.appendChild(de),L.appendChild(i("Wrapping form",'[cta action="approve" entry="abc123" style="success" confirm="Approve this entry?"]Approve[/cta]',null)),L.appendChild(i("Self-closing",'[cta action="archive" entry="abc123" icon="archive" label="Archive" /]',null)),F.appendChild(L);const K=document.createElement("div");K.appendChild(g("Effects")),K.appendChild(m("Shortcodes for scroll-triggered animations, counters, typewriter text, and more. Requires the Domma Effects plugin."));const ve=[['[reveal animation="fade"]...[/reveal]',"Fade/slide/zoom on scroll"],["[breathe]...[/breathe]","Continuous gentle scale loop"],["[pulse]...[/pulse]","Repeating scale pulse"],["[shake]...[/shake]","One-shot shake"],['[scribe speed="50"]...[/scribe]',"Typewriter - simple mode (text typed letter by letter)"],['[scribe loop="true"][render]Text[/render][wait]1500[/wait][undo /][/scribe]',"Typewriter - script mode (sequenced render/wait/undo actions)"],["[scramble]...[/scramble]","Character-scramble reveal"],['[counter to="100" /]',"Animated number counter (self-closing)"],["[ripple]...[/ripple]","Click-triggered ripple"],['[twinkle count="50"]...[/twinkle]',"Particle/star overlay"],['[animate type="fade-in-up"]...[/animate]',"CSS-only animation (no plugin needed)"],['[ambient type="aurora"]...[/ambient]',"CSS-only animated background"],['[firework type="burst" colour="rainbow" /]',"CSS firework (self-closing)"],["[fireworks]...[/fireworks]","Fireworks display container"],['[celebrate theme="auto" /]',"Seasonal canvas celebration (auto-detects date)"],["[christmas /]","Christmas - snowflakes, trees, snowmen, sleigh"],["[halloween /]","Halloween - pumpkins, ghosts, bats, spiders"],["[st-patricks /]","St Patrick's Day - shamrocks, coins, rainbows, leprechaun"],["[valentines /]","Valentine's Day - hearts, roses"],["[guy-fawkes /]","Guy Fawkes - fireworks, sparkles"],["[st-andrews /]","St Andrew's Day - heather, thistles"],["[st-davids /]","St David's Day - daffodils, dragons"],["[st-georges /]","St George's Day - roses, flags"]],he=document.createElement("table");he.style.cssText="width:100%;border-collapse:collapse;font-size:.85em;margin-bottom:.5rem;",ve.forEach(([d,l])=>{const n=document.createElement("tr"),a=document.createElement("td");a.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;",a.appendChild(r(d));const o=document.createElement("td");o.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;color:var(--dm-text-muted,#aaa);",o.textContent=l,n.appendChild(a),n.appendChild(o),he.appendChild(n)}),K.appendChild(he),K.appendChild(i("Scribe script - looping multi-phrase typewriter",`[scribe loop="true" loop-delay="2000" delete-speed="20"]
|
|
71
71
|
[render]We build things that matter.[/render]
|
|
72
72
|
[wait]1200[/wait]
|
|
73
73
|
[undo all="true" /]
|
|
74
74
|
[render]We design for humans.[/render]
|
|
75
75
|
[wait]1200[/wait]
|
|
76
76
|
[undo all="true" /]
|
|
77
|
-
[/scribe]`,'Use [render]...[/render] to type text, [wait]Ms[/wait] to pause, and [undo /] to delete. loop="true" replays the sequence. Only [render], [wait], and [undo] shortcodes are parsed - plain text between actions is ignored.')),
|
|
77
|
+
[/scribe]`,'Use [render]...[/render] to type text, [wait]Ms[/wait] to pause, and [undo /] to delete. loop="true" replays the sequence. Only [render], [wait], and [undo] shortcodes are parsed - plain text between actions is ignored.')),K.appendChild(i("Christmas",'[christmas intensity="medium" snowmen="off" trees="off" wreaths="off" northStars="off" sleigh="off" train="off" elf="off" robin="off" firework="off" /]',"intensity: light | medium | heavy. Count-based (off disables entirely): snowmen, trees, wreaths, northStars. Probability-based specials (off prevents spawning): sleigh, train, elf, robin, firework. Snowflakes always fall.")),K.appendChild(i("Halloween",'[halloween intensity="medium" gravestones="off" jackOLanterns="off" spiders="off" scarecrows="off" twinklingStars="off" /]',"intensity: light | medium | heavy. Decoration toggles (off disables): gravestones, jackOLanterns, spiders, scarecrows, twinklingStars. Particles: bats, ghosts, pumpkins (always on). Fixed decorations: haunted-house, cauldron (always present).")),K.appendChild(i("St Patrick's Day",'[st-patricks intensity="medium" pots="off" twinklingStars="off" /]',"intensity: light | medium | heavy. Decoration toggles (off disables): pots (pots of gold), twinklingStars. Particles: shamrocks, clover petals, gold coins, sparkles (always on). Fixed decorations: rainbow, harp, moon. Leprechaun appears randomly - more likely at higher intensity.")),K.appendChild(i("Valentine's Day",'[valentines intensity="medium" garlands="off" butterflies="off" /]',"intensity: light | medium | heavy. Decoration toggles (off disables): garlands (heart garlands), butterflies. Particles: hearts, rose petals, sparkles, lips (always on). Fixed decorations: envelopes (always present). Cupid appears randomly - more likely at higher intensity.")),K.appendChild(i("Guy Fawkes Night",'[guy-fawkes intensity="medium" bonfires="off" /]',"intensity: light | medium | heavy. Decoration toggles (off disables): bonfires. Particles: embers, fireworks, sparks, rockets, bursts, trails (always on). Fixed decorations: guy-effigy, catherine-wheel, roman-candle, sparkler-bundle, moon. Starts at 25% particle density and builds up gradually.")),K.appendChild(i("St Andrew's Day",'[st-andrews intensity="medium" thistles="off" twinklingStars="off" /]',"intensity: light | medium | heavy. Decoration toggles (off disables): thistles, twinklingStars. Particles: heather petals, saltire sparkles (always on). Fixed decorations: bagpiper, saltire-flag, tartan-pattern, highland-scene (always present). Bagpiper probability increases with intensity.")),K.appendChild(i("St David's Day",'[st-davids intensity="medium" daffodilFields="off" twinklingStars="off" /]',"intensity: light | medium | heavy. Decoration toggles (off disables): daffodilFields, twinklingStars. Particles: daffodil petals, spring sparkles (always on). Fixed decorations: welsh-dragon, harp, leek-bundle, flag (always present). Flying dragon appears randomly - more likely at higher intensity.")),K.appendChild(i("St George's Day",'[st-georges intensity="medium" roses="off" twinklingStars="off" /]',"intensity: light | medium | heavy. Decoration toggles (off disables): roses (English roses), twinklingStars. Particles: rose petals, Tudor roses, oak leaves, sparkles (always on). Fixed decorations: st-georges-cross, dragon, shield, castle (always present). Knight appears randomly - more likely at higher intensity.")),K.appendChild(m("Enable the Domma Effects plugin to activate these shortcodes on your site.")),_.appendChild(K);const me=document.createElement("div");me.appendChild(g("Tables")),me.appendChild(m("Wrap a standard Markdown (GFM) table with Domma CSS classes and responsive horizontal scrolling."));const fe=document.createElement("table");fe.style.cssText="width:100%;border-collapse:collapse;font-size:.85em;margin-bottom:.5rem;",[['striped="true"',"Alternate row background (.table-striped)"],['bordered="true"',"Borders on all cells (.table-bordered)"],['compact="true"',"Reduced cell padding (.table-compact)"],['caption="..."',"Caption text above the table"],['class="..."',"Extra CSS classes appended to .table"],['id="..."',"id attribute on the <table> element"]].forEach(([d,l])=>{const n=document.createElement("tr"),a=document.createElement("td");a.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;",a.appendChild(r(d));const o=document.createElement("td");o.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;color:var(--dm-text-muted,#aaa);",o.textContent=l,n.appendChild(a),n.appendChild(o),fe.appendChild(n)}),me.appendChild(fe),me.appendChild(i("Striped + bordered table",`[table striped="true" bordered="true" caption="Product Pricing"]
|
|
78
78
|
| Product | Price |
|
|
79
79
|
| ------- | ----: |
|
|
80
80
|
| Widget | $9.99 |
|
|
81
81
|
| Gadget | $14.99 |
|
|
82
|
-
[/table]`,"The inner content must be a valid GFM Markdown table. The shortcode adds Domma CSS classes and wraps in a responsive scroll container.")),
|
|
82
|
+
[/table]`,"The inner content must be a valid GFM Markdown table. The shortcode adds Domma CSS classes and wraps in a responsive scroll container.")),N.appendChild(me);const O=document.createElement("div");O.appendChild(g("Slideover")),O.appendChild(m("A trigger button that opens a slide-in panel with Markdown content. No plugin required."));const Ce=document.createElement("table");Ce.style.cssText="width:100%;border-collapse:collapse;font-size:.85em;margin-bottom:.5rem;",[['title="..."',"Panel header text"],['trigger="..."','Button label (default: "Open")'],['size="sm|md|lg"',"Panel width (default: md)"],['position="right|left"',"Slide direction (default: right)"]].forEach(([d,l])=>{const n=document.createElement("tr"),a=document.createElement("td");a.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;",a.appendChild(r(d));const o=document.createElement("td");o.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;color:var(--dm-text-muted,#aaa);",o.textContent=l,n.appendChild(a),n.appendChild(o),Ce.appendChild(n)}),O.appendChild(Ce),O.appendChild(i("Example",`[slideover title="More Info" trigger="Read more" size="md"]
|
|
83
83
|
## Details
|
|
84
84
|
Markdown content here.
|
|
85
|
-
[/slideover]`,"Nested [card] and [grid] shortcodes work inside the slideover body.")),
|
|
85
|
+
[/slideover]`,"Nested [card] and [grid] shortcodes work inside the slideover body.")),N.appendChild(O);const ue=document.createElement("div");ue.appendChild(g("DConfig - Declarative Behaviour")),ue.appendChild(m("Define click handlers and class toggles without writing JavaScript. Use the DConfig section above or embed inline with [dconfig]...[/dconfig] in the content body. Inline shortcodes win on selector conflict.")),ue.appendChild(i("Toggle a class on click",'{ "#my-btn": { "events": { "click": { "target": "#panel", "toggleClass": "hidden" } } } }','Selector keys use standard CSS selectors. "target" is optional - defaults to the element itself.')),ue.appendChild(i("Inline shortcode syntax",`[dconfig]
|
|
86
86
|
{ "#my-btn": { "events": { "click": { "target": "#panel", "toggleClass": "hidden" } } } }
|
|
87
|
-
[/dconfig]`,null)),J.appendChild(ue);const fe=document.createElement("div");fe.appendChild(g("CSS Editor")),fe.appendChild(c("The toolbar's </> button (left of the Split View icon) swaps the left pane between Markdown and Custom CSS. Edits are saved together with the page - one Save, one toast."));const ke=document.createElement("table");ke.style.cssText="width:100%;border-collapse:collapse;font-size:.85em;margin-bottom:.5rem;",[["</> button","Toggle between Markdown editor and Custom CSS editor"],["Split / Write / Preview","Standard view mode buttons to the right of </>"],["Save","Saves both page content and CSS in a single operation"]].forEach(([l,d])=>{const n=document.createElement("tr"),a=document.createElement("td");a.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;",a.appendChild(s(l));const o=document.createElement("td");o.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;color:var(--dm-text-muted,#aaa);",o.textContent=d,n.appendChild(a),n.appendChild(o),ke.appendChild(n)}),fe.appendChild(ke),J.appendChild(fe);const Te=document.createElement("div");Te.appendChild(g("Colour Picker")),Te.appendChild(c("Insert \u2192 Colour Picker opens a centred colour picker. Pick a colour, then use Copy to copy the hex code to the clipboard or Insert to drop it at the cursor. Click outside the panel to dismiss.")),J.appendChild(Te);const Se=document.createElement("div");Se.appendChild(g("Keyboard Shortcuts"));const De=document.createElement("table");De.style.cssText="width:100%;border-collapse:collapse;font-size:.85em;margin-bottom:.5rem;",[["Ctrl + B","Bold selected text"],["Ctrl + I","Italic selected text"],["Ctrl + K","Insert link dialog"],["Tab","Indent 2 spaces at cursor"],["Shift + Tab","Dedent 2 spaces on current line"],["Ctrl + X","Cut current line (no selection) or cut selection"],["Ctrl + C","Copy current line (no selection) or copy selection"],["Ctrl + V","Paste from clipboard"],["Ctrl + Z","Undo"],["Ctrl + Y","Redo"]].forEach(([l,d])=>{const n=document.createElement("tr"),a=document.createElement("td");a.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;white-space:nowrap;",a.appendChild(s(l));const o=document.createElement("td");o.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;color:var(--dm-text-muted,#aaa);",o.textContent=d,n.appendChild(a),n.appendChild(o),De.appendChild(n)}),Se.appendChild(De),ne.appendChild(Se);const be=document.createElement("div");be.appendChild(g("Tips"));const Ae=document.createElement("table");Ae.style.cssText="width:100%;border-collapse:collapse;font-size:.85em;margin-bottom:.5rem;",[['class="text-center"',"Centre text and inline elements on any shortcode"],['class="mx-auto"',"Centre a block element horizontally"],["[center]...[/center]","Shorthand wrapper for centred content"]].forEach(([l,d])=>{const n=document.createElement("tr"),a=document.createElement("td");a.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;",a.appendChild(s(l));const o=document.createElement("td");o.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;color:var(--dm-text-muted,#aaa);",o.textContent=d,n.appendChild(a),n.appendChild(o),Ae.appendChild(n)}),be.appendChild(Ae),be.appendChild(c("Most shortcodes accept a class attribute for custom styling.")),ne.appendChild(be),e.setContent(te),e.open(),E.tabs(ae),I.scan(te)}function Ye(e,P){const L=e.find("#history-tab").get(0),s=e.find("#version-list").get(0),g=e.find("#version-compare").get(0),te=e.find("#version-compare-old").get(0),ae=e.find("#version-compare-new").get(0),se=e.find("#version-compare-label").get(0),p=e.find("#version-compare-back-btn").get(0),X=e.find("#version-restore-btn").get(0),ne=e.find("#history-save-named-btn").get(0),G=e.find("#history-delete-selected-btn").get(0);let z=!1,W=null;function J(){s.style.display="",g.style.display="none",W=null}function ce(){s.style.display="none",g.style.display=""}async function H(){s.textContent="";const f=document.createElement("p");f.style.color="var(--dm-text-muted)",f.textContent="Loading\u2026",s.appendChild(f);let x;try{x=(await A.versions.list(P)).versions||[]}catch(u){s.textContent="";const b=document.createElement("p");b.style.color="var(--dm-danger,#e55)",b.textContent="Failed to load versions: "+u.message,s.appendChild(b);return}if(s.textContent="",G.style.display="none",!x.length){const u=document.createElement("p");u.style.color="var(--dm-text-muted)",u.textContent="No versions saved yet. Versions are created automatically on each save.",s.appendChild(u);return}const q=document.createElement("table");q.style.cssText="width:100%;border-collapse:collapse;font-size:.875rem;";const y=document.createElement("thead"),c=document.createElement("tr"),i=document.createElement("th");i.style.cssText="padding:.5rem .75rem;width:2rem;border-bottom:1px solid var(--dm-border);";const w=document.createElement("input");w.type="checkbox",w.setAttribute("aria-label","Select all versions"),i.appendChild(w),c.appendChild(i),["Date","Author","Type","Label","Actions"].forEach(u=>{const b=document.createElement("th");b.style.cssText="text-align:left;padding:.5rem .75rem;border-bottom:1px solid var(--dm-border);font-size:.8rem;color:var(--dm-text-muted);",b.textContent=u,c.appendChild(b)}),y.appendChild(c),q.appendChild(y);const N=[];function Q(){const u=N.some(B=>B.checked),b=N.length>0&&N.every(B=>B.checked);G.style.display=u?"":"none",w.checked=b,w.indeterminate=u&&!b}w.addEventListener("change",()=>{N.forEach(u=>{u.checked=w.checked}),Q()});const oe=document.createElement("tbody");x.forEach(u=>{const b=document.createElement("tr");b.style.borderBottom="1px solid var(--dm-border)";const B=document.createElement("td");B.style.padding=".5rem .75rem";const Y=document.createElement("input");Y.type="checkbox",Y.value=u.filename,Y.addEventListener("change",Q),B.appendChild(Y),N.push(Y);const K=document.createElement("td");K.style.padding=".5rem .75rem",K.textContent=D(u.createdAt).format("D MMM YYYY, HH:mm");const M=document.createElement("td");M.style.padding=".5rem .75rem",M.textContent=u.author||"-";const Z=document.createElement("td");Z.style.padding=".5rem .75rem";const U=document.createElement("span");U.className="badge badge-"+(u.type==="manual"?"primary":"secondary"),U.style.cssText="font-size:.75rem;padding:.2rem .5rem;border-radius:4px;",U.textContent=u.type,Z.appendChild(U);const ee=document.createElement("td");ee.style.cssText="padding:.5rem .75rem;color:var(--dm-text-muted);",ee.textContent=u.label||"-";const V=document.createElement("td");V.style.padding=".5rem .75rem";const v=document.createElement("button");v.className="btn btn-ghost btn-xs",v.style.marginRight=".4rem",v.title="Compare",v.innerHTML='<span data-icon="columns"></span>',v.addEventListener("click",async()=>{try{const _=await A.versions.get(P,u.filename);te.textContent=_.content,ae.textContent=e.find("#markdown-editor").get(0).value,se.textContent=D(u.createdAt).format("D MMM YYYY, HH:mm")+(u.label?` - ${u.label}`:""),W=u.filename,ce()}catch(_){E.toast("Failed to load version: "+_.message,{type:"error"})}});const k=document.createElement("button");k.className="btn btn-ghost btn-xs",k.style.color="var(--dm-danger,#e55)",k.title="Delete",k.innerHTML='<span data-icon="trash"></span>',k.addEventListener("click",async()=>{if(await E.confirm("Delete this version? This cannot be undone."))try{await A.versions.delete(P,u.filename),E.toast("Version deleted.",{type:"success"}),await H()}catch(_){E.toast("Failed to delete: "+_.message,{type:"error"})}}),V.appendChild(v),V.appendChild(k),b.appendChild(B),b.appendChild(K),b.appendChild(M),b.appendChild(Z),b.appendChild(ee),b.appendChild(V),oe.appendChild(b)}),q.appendChild(oe),s.appendChild(q),I.scan(s)}L.addEventListener("click",async()=>{z||(z=!0,await H())}),p.addEventListener("click",()=>{J()}),X.addEventListener("click",async()=>{if(!(!W||!await E.confirm("Restore this version? The current page content will be overwritten (a pre-restore snapshot will be saved automatically).")))try{await A.versions.restore(P,W),E.toast("Page restored. Reloading editor\u2026",{type:"success"}),R.navigate("/pages"),setTimeout(()=>R.navigate(`/pages/edit${P}`),300)}catch(f){E.toast("Restore failed: "+f.message,{type:"error"})}}),G.addEventListener("click",async()=>{const f=[...s.querySelectorAll("tbody input[type=checkbox]:checked")].map(x=>x.value);if(!(!f.length||!await E.confirm(`Delete ${f.length} version${f.length>1?"s":""}? This cannot be undone.`)))try{await A.versions.bulkDelete(P,f),E.toast(`${f.length} version${f.length>1?"s":""} deleted.`,{type:"success"}),await H()}catch(x){E.toast("Delete failed: "+x.message,{type:"error"})}}),ne.addEventListener("click",()=>{const f=E.slideover({title:"Save Named Version",size:"sm",position:"right"}),x=document.createElement("div");x.style.padding="1rem";const q=document.createElement("label");q.className="form-label",q.textContent="Version Label";const y=document.createElement("input");y.type="text",y.className="form-input",y.placeholder="e.g. Initial design, Before restructure",y.style.marginBottom=".75rem";const c=document.createElement("button");c.className="btn btn-primary",c.textContent="Save Version",c.addEventListener("click",async()=>{const i=y.value.trim();try{await A.versions.create(P,i||null),E.toast("Named version saved.",{type:"success"}),f.close(),z=!1,L.classList.contains("active")&&(z=!0,await H())}catch(w){E.toast("Failed to save version: "+w.message,{type:"error"})}}),x.appendChild(q),x.appendChild(y),x.appendChild(c),f.element.appendChild(x),f.open(),setTimeout(()=>y.focus(),100)})}let re=!1,Ce=null,ze=!1;function Je(e){return e.split(`
|
|
87
|
+
[/dconfig]`,null)),_.appendChild(ue);const be=document.createElement("div");be.appendChild(g("CSS Editor")),be.appendChild(m("The toolbar's </> button (left of the Split View icon) swaps the left pane between Markdown and Custom CSS. Edits are saved together with the page - one Save, one toast."));const Te=document.createElement("table");Te.style.cssText="width:100%;border-collapse:collapse;font-size:.85em;margin-bottom:.5rem;",[["</> button","Toggle between Markdown editor and Custom CSS editor"],["Split / Write / Preview","Standard view mode buttons to the right of </>"],["Save","Saves both page content and CSS in a single operation"]].forEach(([d,l])=>{const n=document.createElement("tr"),a=document.createElement("td");a.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;",a.appendChild(r(d));const o=document.createElement("td");o.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;color:var(--dm-text-muted,#aaa);",o.textContent=l,n.appendChild(a),n.appendChild(o),Te.appendChild(n)}),be.appendChild(Te),_.appendChild(be);const Se=document.createElement("div");Se.appendChild(g("Colour Picker")),Se.appendChild(m("Insert \u2192 Colour Picker opens a centred colour picker. Pick a colour, then use Copy to copy the hex code to the clipboard or Insert to drop it at the cursor. Click outside the panel to dismiss.")),_.appendChild(Se);const De=document.createElement("div");De.appendChild(g("Keyboard Shortcuts"));const Le=document.createElement("table");Le.style.cssText="width:100%;border-collapse:collapse;font-size:.85em;margin-bottom:.5rem;",[["Ctrl + B","Bold selected text"],["Ctrl + I","Italic selected text"],["Ctrl + K","Insert link dialog"],["Tab","Indent 2 spaces at cursor"],["Shift + Tab","Dedent 2 spaces on current line"],["Ctrl + X","Cut current line (no selection) or cut selection"],["Ctrl + C","Copy current line (no selection) or copy selection"],["Ctrl + V","Paste from clipboard"],["Ctrl + Z","Undo"],["Ctrl + Y","Redo"]].forEach(([d,l])=>{const n=document.createElement("tr"),a=document.createElement("td");a.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;white-space:nowrap;",a.appendChild(r(d));const o=document.createElement("td");o.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;color:var(--dm-text-muted,#aaa);",o.textContent=l,n.appendChild(a),n.appendChild(o),Le.appendChild(n)}),De.appendChild(Le),H.appendChild(De);const Ee=document.createElement("div");Ee.appendChild(g("Tips"));const Ae=document.createElement("table");Ae.style.cssText="width:100%;border-collapse:collapse;font-size:.85em;margin-bottom:.5rem;",[['class="text-center"',"Centre text and inline elements on any shortcode"],['class="mx-auto"',"Centre a block element horizontally"],["[center]...[/center]","Shorthand wrapper for centred content"]].forEach(([d,l])=>{const n=document.createElement("tr"),a=document.createElement("td");a.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;",a.appendChild(r(d));const o=document.createElement("td");o.style.cssText="padding:.3rem .4rem;border-bottom:1px solid var(--dm-border,#333);vertical-align:top;color:var(--dm-text-muted,#aaa);",o.textContent=l,n.appendChild(a),n.appendChild(o),Ae.appendChild(n)}),Ee.appendChild(Ae),Ee.appendChild(m("Most shortcodes accept a class attribute for custom styling.")),H.appendChild(Ee),e.setContent(X),e.open(),E.tabs(Q),I.scan(X)}function je(e,P){const f=e.find("#history-tab").get(0),r=e.find("#version-list").get(0),g=e.find("#version-compare").get(0),X=e.find("#version-compare-old").get(0),Q=e.find("#version-compare-new").get(0),ee=e.find("#version-compare-label").get(0),c=e.find("#version-compare-back-btn").get(0),V=e.find("#version-restore-btn").get(0),H=e.find("#history-save-named-btn").get(0),q=e.find("#history-delete-selected-btn").get(0);let N=!1,F=null;function _(){r.style.display="",g.style.display="none",F=null}function G(){r.style.display="none",g.style.display=""}async function B(){r.textContent="";const s=document.createElement("p");s.style.color="var(--dm-text-muted)",s.textContent="Loading\u2026",r.appendChild(s);let v;try{v=(await k.versions.list(P)).versions||[]}catch(h){r.textContent="";const x=document.createElement("p");x.style.color="var(--dm-danger,#e55)",x.textContent="Failed to load versions: "+h.message,r.appendChild(x);return}if(r.textContent="",q.style.display="none",!v.length){const h=document.createElement("p");h.style.color="var(--dm-text-muted)",h.textContent="No versions saved yet. Versions are created automatically on each save.",r.appendChild(h);return}const M=document.createElement("table");M.style.cssText="width:100%;border-collapse:collapse;font-size:.875rem;";const w=document.createElement("thead"),m=document.createElement("tr"),i=document.createElement("th");i.style.cssText="padding:.5rem .75rem;width:2rem;border-bottom:1px solid var(--dm-border);";const C=document.createElement("input");C.type="checkbox",C.setAttribute("aria-label","Select all versions"),i.appendChild(C),m.appendChild(i),["Date","Author","Type","Label","Actions"].forEach(h=>{const x=document.createElement("th");x.style.cssText="text-align:left;padding:.5rem .75rem;border-bottom:1px solid var(--dm-border);font-size:.8rem;color:var(--dm-text-muted);",x.textContent=h,m.appendChild(x)}),w.appendChild(m),M.appendChild(w);const U=[];function ne(){const h=U.some(W=>W.checked),x=U.length>0&&U.every(W=>W.checked);q.style.display=h?"":"none",C.checked=x,C.indeterminate=h&&!x}C.addEventListener("change",()=>{U.forEach(h=>{h.checked=C.checked}),ne()});const re=document.createElement("tbody");v.forEach(h=>{const x=document.createElement("tr");x.style.borderBottom="1px solid var(--dm-border)";const W=document.createElement("td");W.style.padding=".5rem .75rem";const ae=document.createElement("input");ae.type="checkbox",ae.value=h.filename,ae.addEventListener("change",ne),W.appendChild(ae),U.push(ae);const oe=document.createElement("td");oe.style.padding=".5rem .75rem",oe.textContent=D(h.createdAt).format("D MMM YYYY, HH:mm");const Y=document.createElement("td");Y.style.padding=".5rem .75rem",Y.textContent=h.author||"-";const ie=document.createElement("td");ie.style.padding=".5rem .75rem";const j=document.createElement("span");j.className="badge badge-"+(h.type==="manual"?"primary":"secondary"),j.style.cssText="font-size:.75rem;padding:.2rem .5rem;border-radius:4px;",j.textContent=h.type,ie.appendChild(j);const le=document.createElement("td");le.style.cssText="padding:.5rem .75rem;color:var(--dm-text-muted);",le.textContent=h.label||"-";const J=document.createElement("td");J.style.padding=".5rem .75rem";const T=document.createElement("button");T.className="btn btn-ghost btn-xs",T.style.marginRight=".4rem",T.title="Compare",T.innerHTML='<span data-icon="columns"></span>',T.addEventListener("click",async()=>{try{const te=await k.versions.get(P,h.filename);X.textContent=te.content,Q.textContent=e.find("#markdown-editor").get(0).value,ee.textContent=D(h.createdAt).format("D MMM YYYY, HH:mm")+(h.label?` - ${h.label}`:""),F=h.filename,G()}catch(te){E.toast("Failed to load version: "+te.message,{type:"error"})}});const z=document.createElement("button");z.className="btn btn-ghost btn-xs",z.style.color="var(--dm-danger,#e55)",z.title="Delete",z.innerHTML='<span data-icon="trash"></span>',z.addEventListener("click",async()=>{if(await E.confirm("Delete this version? This cannot be undone."))try{await k.versions.delete(P,h.filename),E.toast("Version deleted.",{type:"success"}),await B()}catch(te){E.toast("Failed to delete: "+te.message,{type:"error"})}}),J.appendChild(T),J.appendChild(z),x.appendChild(W),x.appendChild(oe),x.appendChild(Y),x.appendChild(ie),x.appendChild(le),x.appendChild(J),re.appendChild(x)}),M.appendChild(re),r.appendChild(M),I.scan(r)}f.addEventListener("click",async()=>{N||(N=!0,await B())}),c.addEventListener("click",()=>{_()}),V.addEventListener("click",async()=>{if(!(!F||!await E.confirm("Restore this version? The current page content will be overwritten (a pre-restore snapshot will be saved automatically).")))try{await k.versions.restore(P,F),E.toast("Page restored. Reloading editor\u2026",{type:"success"}),R.navigate("/pages"),setTimeout(()=>R.navigate(`/pages/edit${P}`),300)}catch(s){E.toast("Restore failed: "+s.message,{type:"error"})}}),q.addEventListener("click",async()=>{const s=[...r.querySelectorAll("tbody input[type=checkbox]:checked")].map(v=>v.value);if(!(!s.length||!await E.confirm(`Delete ${s.length} version${s.length>1?"s":""}? This cannot be undone.`)))try{await k.versions.bulkDelete(P,s),E.toast(`${s.length} version${s.length>1?"s":""} deleted.`,{type:"success"}),await B()}catch(v){E.toast("Delete failed: "+v.message,{type:"error"})}}),H.addEventListener("click",()=>{const s=E.slideover({title:"Save Named Version",size:"sm",position:"right"}),v=document.createElement("div");v.style.padding="1rem";const M=document.createElement("label");M.className="form-label",M.textContent="Version Label";const w=document.createElement("input");w.type="text",w.className="form-input",w.placeholder="e.g. Initial design, Before restructure",w.style.marginBottom=".75rem";const m=document.createElement("button");m.className="btn btn-primary",m.textContent="Save Version",m.addEventListener("click",async()=>{const i=w.value.trim();try{await k.versions.create(P,i||null),E.toast("Named version saved.",{type:"success"}),s.close(),N=!1,f.classList.contains("active")&&(N=!0,await B())}catch(C){E.toast("Failed to save version: "+C.message,{type:"error"})}}),v.appendChild(M),v.appendChild(w),v.appendChild(m),s.element.appendChild(v),s.open(),setTimeout(()=>w.focus(),100)})}function Je(e){try{return D(e).format("D MMM YYYY, HH:mm")}catch{return new Date(e).toLocaleString()}}async function Ke(e){const P=E.slideover({title:"Share preview link",size:"md",position:"right"}),f=document.createElement("div");f.style.padding="1rem";const r=document.createElement("p");r.className="form-hint",r.style.marginTop="0",r.textContent="Anyone with the link can view this page even while it is unpublished, without signing in. The link works for this page only, expires on its own, and can be revoked at any time.",f.appendChild(r);const g=document.createElement("label");g.className="form-label",g.textContent="Expires after";const X=document.createElement("select");X.className="form-select",[["1h","1 hour"],["24h","24 hours"],["7d","7 days"],["30d","30 days"]].forEach(([G,B])=>{const s=document.createElement("option");s.value=G,s.textContent=B,G==="7d"&&(s.selected=!0),X.appendChild(s)});const Q=document.createElement("label");Q.className="form-label",Q.style.marginTop=".75rem",Q.textContent="Note (optional)";const ee=document.createElement("input");ee.type="text",ee.className="form-input",ee.placeholder="e.g. For the client sign-off";const c=document.createElement("button");c.className="btn btn-primary",c.style.marginTop=".75rem",c.textContent="Create link";const V=document.createElement("div");V.style.marginTop=".75rem",V.style.display="none";const H=document.createElement("input");H.type="text",H.className="form-input",H.readOnly=!0,H.style.marginBottom=".4rem";const q=document.createElement("button");q.className="btn btn-secondary btn-sm",q.textContent="Copy link",q.addEventListener("click",async()=>{try{await navigator.clipboard.writeText(H.value),E.toast("Link copied to clipboard.",{type:"success"})}catch{H.select(),E.toast("Press Ctrl+C to copy the selected link.",{type:"info"})}}),V.appendChild(H),V.appendChild(q),f.appendChild(g),f.appendChild(X),f.appendChild(Q),f.appendChild(ee),f.appendChild(c),f.appendChild(V);const N=document.createElement("h4");N.style.cssText="margin:1.5rem 0 .5rem;font-size:.9rem;",N.textContent="Active links",f.appendChild(N);const F=document.createElement("div");f.appendChild(F);const _=async()=>{F.textContent="";let G=[];try{G=await k.pages.previewLinks.list(e)}catch(s){const v=document.createElement("p");v.className="form-hint",v.textContent="Could not load existing links: "+(s.message||"unknown error"),F.appendChild(v);return}const B=G.filter(s=>!s.revokedAt&&!s.expired);if(!B.length){const s=document.createElement("p");s.className="form-hint",s.textContent="No active links for this page.",F.appendChild(s);return}B.forEach(s=>{const v=document.createElement("div");v.style.cssText="display:flex;align-items:center;gap:.6rem;padding:.5rem 0;border-bottom:1px solid var(--dm-border-light);";const M=document.createElement("div");M.style.cssText="flex:1 1 auto;min-width:0;font-size:.82rem;";const w=document.createElement("div");w.style.fontWeight="600",w.textContent=s.label||"Untitled link";const m=document.createElement("div");m.style.opacity=".7";const i=s.useCount===1?"1 view":`${s.useCount||0} views`;m.textContent=`Expires ${Je(s.expiresAt)} - ${i}`,M.appendChild(w),M.appendChild(m);const C=document.createElement("button");C.className="btn btn-ghost btn-sm",C.textContent="Revoke",C.addEventListener("click",async()=>{if(await E.confirm("Revoke this link? Anyone holding it loses access immediately."))try{await k.pages.previewLinks.revoke(s.id),E.toast("Link revoked.",{type:"success"}),await _()}catch(ne){E.toast("Could not revoke: "+(ne.message||"unknown error"),{type:"error"})}}),v.appendChild(M),v.appendChild(C),F.appendChild(v)})};c.addEventListener("click",async()=>{c.disabled=!0,c.textContent="Creating\u2026";try{const G=await k.pages.previewLinks.create(e,X.value,ee.value.trim());H.value=G.url,V.style.display="",ee.value="",E.toast("Share link created.",{type:"success"}),await _(),H.select()}catch(G){E.toast("Could not create link: "+(G.message||"unknown error"),{type:"error"})}finally{c.disabled=!1,c.textContent="Create link"}}),P.element.appendChild(f),P.open(),await _()}let pe=!1,ke=null,ze=!1;function Ze(e){return e.split(`
|
|
88
88
|
`).map(P=>P.trimEnd()).join(`
|
|
89
89
|
`).replace(/\n{3,}/g,`
|
|
90
90
|
|
|
91
|
-
`)}const Pe="editor_prefs";function
|
|
92
|
-
`);for(;i.firstChild;)i.removeChild(i.firstChild);r.forEach((m,C)=>{const h=document.createElement("span");h.className="editor-line-number-row";const T=document.createElement("span");T.className="fold-toggle fold-toggle--empty";const F=document.createElement("span");F.className="editor-line-num",F.textContent=String(C+1),h.appendChild(T),h.appendChild(F),i.appendChild(h)}),i.scrollTop=t.scrollTop}{const t=e.find("#css-editor").get(0);t&&t.addEventListener("scroll",()=>{i.scrollTop=t.scrollTop})}const Q=()=>{w.refresh(),i.scrollTop=c.scrollTop};c.addEventListener("input",Q),c.addEventListener("scroll",()=>{i.scrollTop=c.scrollTop});let oe=null;const u=()=>{clearTimeout(oe),oe=setTimeout(async()=>{const t=w.getUnfoldedContent();try{const{html:r}=await A.pages.preview(t);f.html(r,{safe:!1}),I.scan(f.get(0)),f.get(0).querySelectorAll(".tabs").forEach(m=>Domma.elements.tabs(m))}catch{window.marked&&f.html(marked.parse(t))}},400)},b=He(H,e.find("#editor-toolbar"),{spacerDefault:ne});$e(H.get(0));let B=!1,Y="split",K=null;const M=document.createElement("button");M.className="editor-view-btn",M.type="button";const Z=document.createElement("span");Z.setAttribute("data-icon","css-code"),M.appendChild(Z);const U=document.createElement("button");U.className="editor-view-btn",U.type="button";const ee=document.createElement("span");ee.setAttribute("data-icon","code"),U.appendChild(ee);let V=!1;const v=document.createElement("button");v.className="editor-view-btn",v.type="button",v.innerHTML='<span data-icon="chevrons-down" data-icon-size="10" style="display:inline-flex;align-items:center;vertical-align:middle;"></span>',v.style.cssText="font-size:9px;letter-spacing:-1px;";const k=e.find(".editor-toolbar-right").get(0);k.prepend(v),k.prepend(U),k.prepend(M),I.scan(M),I.scan(U),I.scan(v),E.tooltip(M,{content:"Edit Custom CSS",position:"top"}),E.tooltip(U,{content:"Format Markdown",position:"top"}),E.tooltip(v,{content:"Fold / unfold all shortcodes",position:"top"}),U.addEventListener("click",()=>{const t=H.get(0),r=t.selectionStart,m=Je(w.getUnfoldedContent());w.unfoldAll(),y=!0,t.value=m,y=!1,t.selectionStart=t.selectionEnd=Math.min(r,m.length),t.dispatchEvent(new Event("input")),w.refresh(),E.toast("Markdown formatted.",{type:"success"})}),v.addEventListener("click",()=>{V?(w.unfoldAll(),v.innerHTML='<span data-icon="chevrons-down" data-icon-size="10" style="display:inline-flex;align-items:center;vertical-align:middle;"></span>',I.scan(v),v.classList.remove("active")):(w.foldAll(),v.innerHTML='<span data-icon="chevrons-right" data-icon-size="10" style="display:inline-flex;align-items:center;vertical-align:middle;"></span>',I.scan(v),v.classList.add("active")),V=!V});const _=document.createElement("span");_.className="editor-toolbar-sep",k.insertBefore(_,k.children[3]),M.addEventListener("click",()=>{B=!B;const t=e.find("#markdown-editor"),r=e.find("#css-editor"),m=e.find("#editor-body");if(B){const C=e.find(".editor-view-btn[data-mode].active").get(0);Y=C?C.getAttribute("data-mode"):"split",e.find(".editor-view-btn[data-mode]").removeClass("active"),e.find('.editor-view-btn[data-mode="split"]').addClass("active"),m.removeClass("editor-mode-write editor-mode-preview").addClass("editor-mode-split"),t.hide(),r.show(),x||(r.val(q),x=!0,Ie(r.get(0))),N(),M.classList.add("active")}else e.find(".editor-view-btn[data-mode]").removeClass("active"),e.find(`.editor-view-btn[data-mode="${Y}"]`).addClass("active"),m.removeClass("editor-mode-split editor-mode-write editor-mode-preview").addClass(`editor-mode-${Y}`),r.hide(),t.show(),w.refresh(),M.classList.remove("active")});const ie=Ne();ie.viewMode&&ie.viewMode!=="split"&&(e.find(".editor-view-btn[data-mode]").removeClass("active"),e.find(`.editor-view-btn[data-mode="${ie.viewMode}"]`).addClass("active"),e.find("#editor-body").removeClass("editor-mode-split editor-mode-write editor-mode-preview").addClass(`editor-mode-${ie.viewMode}`)),ie.fullscreen&&e.find(".editor-card").addClass("editor-fullscreen"),e.find("#css-editor").on("input",()=>{N(),clearTimeout(K),K=setTimeout(()=>{let t=document.getElementById("preview-custom-css");t||(t=document.createElement("style"),t.id="preview-custom-css",f.get(0).parentNode.insertBefore(t,f.get(0))),t.textContent=e.find("#css-editor").val()},400)}),Ve({image:async t=>{const r=(await A.media.list().catch(()=>[])).filter(h=>/\.(png|jpe?g|gif|webp|svg)$/i.test(h.name)),m=document.createElement("div");if(m.className="media-picker-grid",r.length)r.forEach(h=>{const T=document.createElement("div");T.className="media-picker-item",T.dataset.url=h.url;const F=document.createElement("img");F.src=h.url,F.alt=h.name;const le=document.createElement("span");le.textContent=h.name,T.appendChild(F),T.appendChild(le),m.appendChild(T)});else{const h=document.createElement("p");h.className="text-muted p-3",h.textContent="No images uploaded yet.",m.appendChild(h)}const C=E.slideover({title:"Insert Image",size:"lg",position:"right",content:m});$(C.element).on("click",".media-picker-item",function(){const h=$(this).data("url"),T=$(this).find("span").text();qe(t,``),C.close(),t.dispatchEvent(new Event("input",{bubbles:!0}))}),C.open()},scribe:t=>We(t),card:t=>Me.open(t,{onMediaBrowse:()=>A.media.list().catch(()=>[])}),timeline:t=>Re.open(t,{onPreview:async r=>{try{return await A.pages.preview(r)}catch{return null}},onListCollections:()=>A.collections.list().catch(()=>[]),onGetCollection:r=>A.collections.get(r).catch(()=>null)})}),b.onEffects(t=>Ue.open(t)),b.onHelp(()=>{je()}),b.onTutorial(t=>{_e(t)}),e.find(".editor-view-btn").on("click",function(){const t=$(this).data("mode");t&&(e.find(".editor-view-btn").removeClass("active"),$(this).addClass("active"),e.find("#editor-body").removeClass("editor-mode-split editor-mode-write editor-mode-preview").addClass(`editor-mode-${t}`),Be("viewMode",t))}),e.find("#fullscreen-btn").on("click",function(){e.find(".editor-card").toggleClass("editor-fullscreen"),Be("fullscreen",e.find(".editor-card").hasClass("editor-fullscreen"))}),re=!1,e.find("#quick-switch").prop("disabled",!1),Ce&&window.removeEventListener("beforeunload",Ce),Ce=t=>{re&&t.preventDefault()},window.addEventListener("beforeunload",Ce),ze||(ze=!0,R.use((t,r,m)=>{const C=window.location.hash.startsWith("#/pages/edit")||window.location.hash==="#/pages/new";return!re||!C?m():E.confirm("You have unsaved changes. Leave this page?").then(h=>{h&&(re=!1,m())})})),H.on("input",()=>{y||(re=!0,e.find("#quick-switch").prop("disabled",!0),u())});const de=e.find("#editor-meta-tabs").get(0);de&&(de.addEventListener("input",()=>{re=!0,e.find("#quick-switch").prop("disabled",!0)}),de.addEventListener("change",t=>{t.target.id!=="quick-switch"&&(re=!0,e.find("#quick-switch").prop("disabled",!0))})),u(),e.find("#save-btn").on("click",async()=>{const t=e.find("#page-url-path").val().trim();if(!t){E.toast("URL path is required.",{type:"warning"});return}const r=e.find("#field-dconfig").val().trim();let m=null;if(r)try{m=JSON.parse(r)}catch{E.toast("DConfig JSON is invalid. Please check the format before saving.",{type:"warning"});return}const C={title:e.find("#field-title").val().trim()||"Untitled",description:e.find("#field-description").val().trim(),layout:e.find("#field-layout").val(),status:e.find("#field-status").val(),sortOrder:parseInt(e.find("#field-sort-order").val(),10)||99,showInNav:e.find("#field-show-in-nav").is(":checked"),sidebar:e.find("#field-sidebar").is(":checked"),...e.find("#field-show-breadcrumbs").is(":checked")?{}:{breadcrumbs:!1},...e.find("#field-bundled").is(":checked")?{bundled:!0}:{},tags:J?J.getValue():[],category:e.find("#field-category").val().trim()||null,visibility:e.find("#field-visibility").val()||"public",project:e.find("#field-project").val()||"",seo:{title:e.find("#field-seo-title").val().trim(),description:e.find("#field-seo-desc").val().trim()},dconfig:m,...e.find("#field-theme").val()?{theme:e.find("#field-theme").val()}:{}};try{e.find("#save-btn").prop("disabled",!0).text("Saving\u2026");const h=w.getUnfoldedContent();if(s){const T={frontmatter:C,body:h};t!==L&&(T.newUrlPath=t),await A.pages.update(L,T),x&&await A.settings.saveCustomCss(e.find("#css-editor").val()),E.toast(x?"Page and CSS saved.":"Page saved successfully.",{type:"success"}),re=!1,e.find("#quick-switch").prop("disabled",!1),t!==L&&R.navigate(`/pages/edit${t}`)}else await A.pages.create({urlPath:t,frontmatter:C,body:h}),x&&await A.settings.saveCustomCss(e.find("#css-editor").val()),E.toast(x?"Page and CSS saved.":"Page saved successfully.",{type:"success"}),re=!1,R.navigate("/pages")}catch(h){E.toast(`Save failed: ${h.message||"Unknown error"}`,{type:"error"})}finally{e.find("#save-btn").prop("disabled",!1).text("Save")}}),e.find("#cancel-btn").on("click",()=>R.navigate("/pages")),Domma.icons.scan()}};
|
|
91
|
+
`)}const Pe="editor_prefs";function Fe(){return S.get(Pe)||{viewMode:"split",fullscreen:!1}}function Be(e,P){const f=Fe();f[e]=P,S.set(Pe,f)}export const pageEditorView={templateUrl:"/admin/js/templates/page-editor.html",async onMount(e){const P=window.location.hash.match(/#\/pages\/edit(\/.*)/),f=P?P[1]:null,r=!!f,g=E.loader(e.get(0),{type:"dots"}),X=[k.layouts.get().catch(()=>({})),k.settings.get().catch(()=>({}))];r&&(X.push(k.pages.get(f).catch(()=>null)),X.push(k.pages.list().catch(()=>[])));const[Q,ee,c,V]=await Promise.all(X);g.destroy(),Ve(e.find("#field-theme").get(0),{includeDefault:!0});const H=ee?.layoutOptions?.spacerSize??40;if(r&&!c){E.toast("Page not found.",{type:"error"}),R.navigate("/pages");return}e.find("#editor-title").text(r?`Edit Page - ${c.title||f}`:"New Page"),r&&e.find("#page-url-path").val(f),c&&(e.find("#field-title").val(c.title||""),e.find("#field-description").val(c.description||""),e.find("#field-status").val(c.status||"draft"),e.find("#field-sort-order").val(c.sortOrder??99),e.find("#field-show-in-nav").prop("checked",!!c.showInNav),e.find("#field-sidebar").prop("checked",!!c.sidebar),e.find("#field-show-breadcrumbs").prop("checked",c.breadcrumbs!==!1),e.find("#field-bundled").prop("checked",!!c.bundled),e.find("#field-category").val(c.category||""),e.find("#field-visibility").val(c.visibility||"public"),e.find("#field-theme").val(c.theme||""),e.find("#field-seo-title").val(c.seo?.title||""),e.find("#field-seo-desc").val(c.seo?.description||""),c.dconfig&&e.find("#field-dconfig").val(JSON.stringify(c.dconfig,null,2)));{const t=e.find("#field-project").get(0);if(t){const p=await k.projects.list().catch(()=>[]);p.forEach(y=>{const u=document.createElement("option");u.value=y.slug,u.textContent=y.name||y.slug,t.appendChild(u)});let b="";if(!r){const{getProjectFromHash:y}=await import("../lib/project-context.js");b=y()||""}if(!b&&c)if(c.project===null)b="";else if(typeof c.project=="string"&&c.project)b=c.project;else{const y=r?f:"";if(y){let u="",A=-1;for(const L of p)L.rootUrl&&(y===L.rootUrl||y.startsWith(L.rootUrl+"/"))&&L.rootUrl.length>A&&(u=L.slug,A=L.rootUrl.length);b=u}}t.value=b}}const q=e.find("#quick-switch");r&&Array.isArray(V)&&V.length&&([...V].sort((t,p)=>(t.title||t.urlPath).localeCompare(p.title||p.urlPath)).forEach(t=>{const p=document.createElement("option");p.value=t.urlPath,p.textContent=`${t.title||"Untitled"} (${t.urlPath})`,t.urlPath===f&&(p.selected=!0),q.get(0).appendChild(p)}),q.css("display",""),q.on("change",function(){const t=this.value;t&&R.navigate("/pages/edit"+t)}));const N=await k.pages.tags().catch(()=>[]),F=e.find("#field-tags").get(0),_=F?E.pillbox(F,{data:N,value:c?.tags||[],creatable:!0,searchable:!0,placeholder:"Add tag\u2026"}):null,G=e.find("#field-layout").empty();if(Object.entries(Q).forEach(([t,p])=>{const b=(c?.layout||"default")===t?"selected":"";G.append(`<option value="${t}" ${b}>${p.label||t}</option>`)}),r){const t=e.find("#view-page-btn").get(0);t.href=f,t.style.display="";const p=e.find("#history-tab").get(0);p.style.display=""}e.find("#live-preview-tab").get(0).style.display="",E.tabs(e.find("#editor-meta-tabs").get(0)),r&&je(e,f);const B=e.find("#markdown-editor"),s=e.find("#markdown-preview");c&&B.val(c.content||"");let v=!1,M="";k.settings.getCustomCss().then(({css:t})=>{if(M=t||"",!M)return;const p=document.createElement("style");p.id="preview-custom-css",p.textContent=M,s.get(0).parentNode.insertBefore(p,s.get(0))}).catch(()=>{});let w=!1;const m=B.get(0),i=document.createElement("div");i.className="editor-line-numbers editor-line-numbers--foldable",m.parentElement.insertBefore(i,m);const C=We(m,i,{onFoldChange:()=>{}});C.setGuard(t=>{w=t});function U(){const t=e.find("#css-editor").get(0);if(!t)return;const p=t.value.split(`
|
|
92
|
+
`);for(;i.firstChild;)i.removeChild(i.firstChild);p.forEach((b,y)=>{const u=document.createElement("span");u.className="editor-line-number-row";const A=document.createElement("span");A.className="fold-toggle fold-toggle--empty";const L=document.createElement("span");L.className="editor-line-num",L.textContent=String(y+1),u.appendChild(A),u.appendChild(L),i.appendChild(u)}),i.scrollTop=t.scrollTop}{const t=e.find("#css-editor").get(0);t&&t.addEventListener("scroll",()=>{i.scrollTop=t.scrollTop})}const ne=()=>{C.refresh(),i.scrollTop=m.scrollTop};m.addEventListener("input",ne),m.addEventListener("scroll",()=>{i.scrollTop=m.scrollTop});let re=null;const h=()=>{clearTimeout(re),re=setTimeout(async()=>{const t=C.getUnfoldedContent();try{const{html:p}=await k.pages.preview(t);s.html(p,{safe:!1}),I.scan(s.get(0)),s.get(0).querySelectorAll(".tabs").forEach(b=>Domma.elements.tabs(b))}catch{window.marked&&s.html(marked.parse(t))}},400)},x=He(B,e.find("#editor-toolbar"),{spacerDefault:H});Ue(B.get(0));let W=!1,ae="split",oe=null;const Y=document.createElement("button");Y.className="editor-view-btn",Y.type="button";const ie=document.createElement("span");ie.setAttribute("data-icon","css-code"),Y.appendChild(ie);const j=document.createElement("button");j.className="editor-view-btn",j.type="button";const le=document.createElement("span");le.setAttribute("data-icon","code"),j.appendChild(le);let J=!1;const T=document.createElement("button");T.className="editor-view-btn",T.type="button",T.innerHTML='<span data-icon="chevrons-down" data-icon-size="10" style="display:inline-flex;align-items:center;vertical-align:middle;"></span>',T.style.cssText="font-size:9px;letter-spacing:-1px;";const z=e.find(".editor-toolbar-right").get(0);z.prepend(T),z.prepend(j),z.prepend(Y),I.scan(Y),I.scan(j),I.scan(T),E.tooltip(Y,{content:"Edit Custom CSS",position:"top"}),E.tooltip(j,{content:"Format Markdown",position:"top"}),E.tooltip(T,{content:"Fold / unfold all shortcodes",position:"top"}),j.addEventListener("click",()=>{const t=B.get(0),p=t.selectionStart,b=Ze(C.getUnfoldedContent());C.unfoldAll(),w=!0,t.value=b,w=!1,t.selectionStart=t.selectionEnd=Math.min(p,b.length),t.dispatchEvent(new Event("input")),C.refresh(),E.toast("Markdown formatted.",{type:"success"})}),T.addEventListener("click",()=>{J?(C.unfoldAll(),T.innerHTML='<span data-icon="chevrons-down" data-icon-size="10" style="display:inline-flex;align-items:center;vertical-align:middle;"></span>',I.scan(T),T.classList.remove("active")):(C.foldAll(),T.innerHTML='<span data-icon="chevrons-right" data-icon-size="10" style="display:inline-flex;align-items:center;vertical-align:middle;"></span>',I.scan(T),T.classList.add("active")),J=!J});const te=document.createElement("span");te.className="editor-toolbar-sep",z.insertBefore(te,z.children[3]),Y.addEventListener("click",()=>{W=!W;const t=e.find("#markdown-editor"),p=e.find("#css-editor"),b=e.find("#editor-body");if(W){const y=e.find(".editor-view-btn[data-mode].active").get(0);ae=y?y.getAttribute("data-mode"):"split",e.find(".editor-view-btn[data-mode]").removeClass("active"),e.find('.editor-view-btn[data-mode="split"]').addClass("active"),b.removeClass("editor-mode-write editor-mode-preview").addClass("editor-mode-split"),t.hide(),p.show(),v||(p.val(M),v=!0,Ie(p.get(0))),U(),Y.classList.add("active")}else e.find(".editor-view-btn[data-mode]").removeClass("active"),e.find(`.editor-view-btn[data-mode="${ae}"]`).addClass("active"),b.removeClass("editor-mode-split editor-mode-write editor-mode-preview").addClass(`editor-mode-${ae}`),p.hide(),t.show(),C.refresh(),Y.classList.remove("active")});const se=Fe();se.viewMode&&se.viewMode!=="split"&&(e.find(".editor-view-btn[data-mode]").removeClass("active"),e.find(`.editor-view-btn[data-mode="${se.viewMode}"]`).addClass("active"),e.find("#editor-body").removeClass("editor-mode-split editor-mode-write editor-mode-preview").addClass(`editor-mode-${se.viewMode}`)),se.fullscreen&&e.find(".editor-card").addClass("editor-fullscreen"),e.find("#css-editor").on("input",()=>{U(),clearTimeout(oe),oe=setTimeout(()=>{let t=document.getElementById("preview-custom-css");t||(t=document.createElement("style"),t.id="preview-custom-css",s.get(0).parentNode.insertBefore(t,s.get(0))),t.textContent=e.find("#css-editor").val()},400)}),Oe({image:async t=>{const p=(await k.media.list().catch(()=>[])).filter(u=>/\.(png|jpe?g|gif|webp|svg)$/i.test(u.name)),b=document.createElement("div");if(b.className="media-picker-grid",p.length)p.forEach(u=>{const A=document.createElement("div");A.className="media-picker-item",A.dataset.url=u.url;const L=document.createElement("img");L.src=u.url,L.alt=u.name;const de=document.createElement("span");de.textContent=u.name,A.appendChild(L),A.appendChild(de),b.appendChild(A)});else{const u=document.createElement("p");u.className="text-muted p-3",u.textContent="No images uploaded yet.",b.appendChild(u)}const y=E.slideover({title:"Insert Image",size:"lg",position:"right",content:b});$(y.element).on("click",".media-picker-item",function(){const u=$(this).data("url"),A=$(this).find("span").text();$e(t,``),y.close(),t.dispatchEvent(new Event("input",{bubbles:!0}))}),y.open()},scribe:t=>Ge(t),card:t=>Me.open(t,{onMediaBrowse:()=>k.media.list().catch(()=>[])}),timeline:t=>Re.open(t,{onPreview:async p=>{try{return await k.pages.preview(p)}catch{return null}},onListCollections:()=>k.collections.list().catch(()=>[]),onGetCollection:p=>k.collections.get(p).catch(()=>null)})}),x.onEffects(t=>qe.open(t)),x.onHelp(()=>{_e()}),x.onTutorial(t=>{Ye(t)}),e.find(".editor-view-btn").on("click",function(){const t=$(this).data("mode");t&&(e.find(".editor-view-btn").removeClass("active"),$(this).addClass("active"),e.find("#editor-body").removeClass("editor-mode-split editor-mode-write editor-mode-preview").addClass(`editor-mode-${t}`),Be("viewMode",t))}),e.find("#fullscreen-btn").on("click",function(){e.find(".editor-card").toggleClass("editor-fullscreen"),Be("fullscreen",e.find(".editor-card").hasClass("editor-fullscreen"))}),pe=!1,e.find("#quick-switch").prop("disabled",!1),ke&&window.removeEventListener("beforeunload",ke),ke=t=>{pe&&t.preventDefault()},window.addEventListener("beforeunload",ke),ze||(ze=!0,R.use((t,p,b)=>{const y=window.location.hash.startsWith("#/pages/edit")||window.location.hash==="#/pages/new";return!pe||!y?b():E.confirm("You have unsaved changes. Leave this page?").then(u=>{u&&(pe=!1,b())})})),B.on("input",()=>{w||(pe=!0,e.find("#quick-switch").prop("disabled",!0),h())});const ce=e.find("#editor-meta-tabs").get(0);ce&&(ce.addEventListener("input",()=>{pe=!0,e.find("#quick-switch").prop("disabled",!0)}),ce.addEventListener("change",t=>{t.target.id!=="quick-switch"&&(pe=!0,e.find("#quick-switch").prop("disabled",!0))})),h();const ge=t=>({title:e.find("#field-title").val().trim()||"Untitled",description:e.find("#field-description").val().trim(),layout:e.find("#field-layout").val(),status:e.find("#field-status").val(),sortOrder:parseInt(e.find("#field-sort-order").val(),10)||99,showInNav:e.find("#field-show-in-nav").is(":checked"),sidebar:e.find("#field-sidebar").is(":checked"),...e.find("#field-show-breadcrumbs").is(":checked")?{}:{breadcrumbs:!1},...e.find("#field-bundled").is(":checked")?{bundled:!0}:{},tags:_?_.getValue():[],category:e.find("#field-category").val().trim()||null,visibility:e.find("#field-visibility").val()||"public",project:e.find("#field-project").val()||"",seo:{title:e.find("#field-seo-title").val().trim(),description:e.find("#field-seo-desc").val().trim()},dconfig:t,...e.find("#field-theme").val()?{theme:e.find("#field-theme").val()}:{}});(()=>{const t=e.find("#live-preview-frame").get(0),p=e.find("#live-preview-status").get(0),b=e.find("#live-preview-stage").get(0);if(!t)return;let y=null,u=!0,A=!1,L=!1;const de=O=>{p&&(p.textContent=O)},K=()=>{const O=(e.find("#field-dconfig").val()||"").trim();if(!O)return null;try{return JSON.parse(O)}catch{return null}},ve=async()=>{if(!L){L=!0,de("Rendering\u2026");try{const O=(e.find("#page-url-path").val()||"").trim()||f||"/",{html:Ce}=await k.pages.previewFull(O,ge(K()),C.getUnfoldedContent());let ue=0;try{ue=t.contentWindow.scrollY||0}catch{}t.addEventListener("load",function be(){t.removeEventListener("load",be);try{t.contentWindow.scrollTo(0,ue)}catch{}},{once:!0}),t.srcdoc=Ce,u=!1,de("Showing unsaved changes")}catch(O){de("Preview failed - "+(O&&O.message?O.message:"unknown error"))}finally{L=!1}}},he=()=>{u=!0,A&&(clearTimeout(y),y=setTimeout(ve,600))},me=e.find("#live-preview-tab").get(0);me&&me.addEventListener("click",()=>{A=!0,u&&ve()}),e.find("#editor-meta-tabs .tab-item").each(function(){this.id!=="live-preview-tab"&&this.addEventListener("click",()=>{A=!1})}),m.addEventListener("input",he);const fe=e.find("#editor-meta-tabs").get(0);fe&&(fe.addEventListener("input",he),fe.addEventListener("change",he)),e.find("#live-preview-refresh").on("click",()=>ve()),e.find(".live-preview-width").on("click",function(){const O=this.getAttribute("data-width");e.find(".live-preview-width").removeClass("active"),$(this).addClass("active"),O==="full"?t.removeAttribute("data-width"):t.setAttribute("data-width",O),b&&(b.scrollTop=0)})})(),e.find("#share-preview-btn").on("click",async()=>{if(!r){E.toast("Save the page first - a share link needs a page to point at.",{type:"warning"});return}await Ke(f)}),e.find("#save-btn").on("click",async()=>{const t=e.find("#page-url-path").val().trim();if(!t){E.toast("URL path is required.",{type:"warning"});return}const p=e.find("#field-dconfig").val().trim();let b=null;if(p)try{b=JSON.parse(p)}catch{E.toast("DConfig JSON is invalid. Please check the format before saving.",{type:"warning"});return}const y=ge(b);try{e.find("#save-btn").prop("disabled",!0).text("Saving\u2026");const u=C.getUnfoldedContent();if(r){const A={frontmatter:y,body:u};t!==f&&(A.newUrlPath=t),await k.pages.update(f,A),v&&await k.settings.saveCustomCss(e.find("#css-editor").val()),E.toast(v?"Page and CSS saved.":"Page saved successfully.",{type:"success"}),pe=!1,e.find("#quick-switch").prop("disabled",!1),t!==f&&R.navigate(`/pages/edit${t}`)}else await k.pages.create({urlPath:t,frontmatter:y,body:u}),v&&await k.settings.saveCustomCss(e.find("#css-editor").val()),E.toast(v?"Page and CSS saved.":"Page saved successfully.",{type:"success"}),pe=!1,R.navigate("/pages")}catch(u){E.toast(`Save failed: ${u.message||"Unknown error"}`,{type:"error"})}finally{e.find("#save-btn").prop("disabled",!1).text("Save")}}),e.find("#cancel-btn").on("click",()=>R.navigate("/pages")),Domma.icons.scan()}};
|
package/package.json
CHANGED
|
@@ -5,9 +5,21 @@
|
|
|
5
5
|
* POST /api/pages - create page
|
|
6
6
|
* PUT /api/pages/* - update page
|
|
7
7
|
* DELETE /api/pages/* - delete page
|
|
8
|
+
* POST /api/pages/preview - render markdown body to HTML (no page shell)
|
|
9
|
+
* POST /api/pages/preview/full - render UNSAVED frontmatter+body as a complete page
|
|
10
|
+
* GET /api/pages/preview-links - list share links (optionally ?urlPath=)
|
|
11
|
+
* POST /api/pages/preview-links - mint a share link for one page
|
|
12
|
+
* DELETE /api/pages/preview-links/:id - revoke a share link
|
|
8
13
|
*/
|
|
9
|
-
import {createPage, deletePage, getPage, listPages, renamePage, updatePage} from '../../services/content.js';
|
|
14
|
+
import {buildPreviewPage, createPage, deletePage, getPage, listPages, renamePage, updatePage} from '../../services/content.js';
|
|
10
15
|
import {parseMarkdown} from '../../services/markdown.js';
|
|
16
|
+
import {renderPage} from '../../services/renderer.js';
|
|
17
|
+
import {
|
|
18
|
+
createPreviewLink,
|
|
19
|
+
deletePreviewLinksForPage,
|
|
20
|
+
listPreviewLinks,
|
|
21
|
+
revokePreviewLink
|
|
22
|
+
} from '../../services/previewLinks.js';
|
|
11
23
|
import {getVersionCount} from '../../services/versions.js';
|
|
12
24
|
import {authenticate, requirePermission} from '../../middleware/auth.js';
|
|
13
25
|
import {getConfig, saveConfig} from '../../config.js';
|
|
@@ -26,6 +38,73 @@ export async function pagesRoutes(fastify) {
|
|
|
26
38
|
return {html};
|
|
27
39
|
});
|
|
28
40
|
|
|
41
|
+
// Full-page preview of UNSAVED editor state.
|
|
42
|
+
//
|
|
43
|
+
// The body-only route above answers "did my shortcodes parse". This one
|
|
44
|
+
// answers "is the page right" - it runs the same parseMarkdown and
|
|
45
|
+
// renderPage the public site runs on save, so layout, navbar, footer,
|
|
46
|
+
// theme, menus, dconfig and custom CSS are all exactly what shipping
|
|
47
|
+
// would produce. No draft banner: the editor is already telling the user
|
|
48
|
+
// what they are looking at.
|
|
49
|
+
fastify.post('/pages/preview/full', canRead, async (request, reply) => {
|
|
50
|
+
const {frontmatter = {}, body = '', urlPath = '/'} = request.body || {};
|
|
51
|
+
if (typeof body !== 'string') return reply.status(400).send({error: 'body must be a string'});
|
|
52
|
+
if (typeof urlPath !== 'string' || !urlPath.startsWith('/')) {
|
|
53
|
+
return reply.status(400).send({error: 'urlPath must begin with /'});
|
|
54
|
+
}
|
|
55
|
+
if (frontmatter === null || typeof frontmatter !== 'object' || Array.isArray(frontmatter)) {
|
|
56
|
+
return reply.status(400).send({error: 'frontmatter must be an object'});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const page = await buildPreviewPage(urlPath, frontmatter, body, {user: request.user || null});
|
|
60
|
+
const html = await renderPage(page, {
|
|
61
|
+
baseUrl: `${request.protocol}://${request.host}`,
|
|
62
|
+
user: request.user || null
|
|
63
|
+
});
|
|
64
|
+
return {html};
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// --- Share links --------------------------------------------------------
|
|
68
|
+
// Minting is gated on `pages.update`, not `pages.read`: handing an
|
|
69
|
+
// unauthenticated stranger a URL that renders unpublished content is an act
|
|
70
|
+
// of publishing, however narrow, and should sit with the people who could
|
|
71
|
+
// publish the page outright.
|
|
72
|
+
|
|
73
|
+
fastify.get('/pages/preview-links', canRead, async (request) => {
|
|
74
|
+
const {urlPath} = request.query || {};
|
|
75
|
+
return {links: await listPreviewLinks(urlPath || undefined)};
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
fastify.post('/pages/preview-links', canUpdate, async (request, reply) => {
|
|
79
|
+
const {urlPath, expiresIn, label} = request.body || {};
|
|
80
|
+
if (!urlPath || typeof urlPath !== 'string' || !urlPath.startsWith('/')) {
|
|
81
|
+
return reply.status(400).send({error: 'urlPath must begin with /'});
|
|
82
|
+
}
|
|
83
|
+
// Refuse to mint for a page that does not exist - otherwise a typo
|
|
84
|
+
// produces a link that 404s for the recipient and looks like a bug.
|
|
85
|
+
if (!(await getPage(urlPath))) {
|
|
86
|
+
return reply.status(404).send({error: 'Page not found'});
|
|
87
|
+
}
|
|
88
|
+
const link = await createPreviewLink({
|
|
89
|
+
urlPath,
|
|
90
|
+
jwt: fastify.jwt,
|
|
91
|
+
label,
|
|
92
|
+
expiresIn,
|
|
93
|
+
createdBy: request.user?.id || null,
|
|
94
|
+
createdByName: request.user?.name || ''
|
|
95
|
+
});
|
|
96
|
+
return reply.status(201).send({
|
|
97
|
+
...link,
|
|
98
|
+
url: `${request.protocol}://${request.host}/_preview?token=${encodeURIComponent(link.token)}`
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
fastify.delete('/pages/preview-links/:id', canUpdate, async (request, reply) => {
|
|
103
|
+
const ok = await revokePreviewLink(request.params.id);
|
|
104
|
+
if (!ok) return reply.status(404).send({error: 'Link not found'});
|
|
105
|
+
return {success: true};
|
|
106
|
+
});
|
|
107
|
+
|
|
29
108
|
// Aggregate unique tags from all pages - must be registered before the wildcard /pages/* route
|
|
30
109
|
fastify.get('/pages/tags', canRead, async (request, reply) => {
|
|
31
110
|
const pages = await listPages();
|
|
@@ -105,6 +184,9 @@ export async function pagesRoutes(fastify) {
|
|
|
105
184
|
|
|
106
185
|
await renamePage(urlPath, newUrlPath);
|
|
107
186
|
await rewriteNavLinks(urlPath, newUrlPath);
|
|
187
|
+
// Links name the old path in their signed payload, so they cannot
|
|
188
|
+
// follow the move - drop them rather than leave them 404ing.
|
|
189
|
+
await deletePreviewLinksForPage(urlPath);
|
|
108
190
|
|
|
109
191
|
const page = await updatePage(newUrlPath, frontmatter || {}, body, {author: request.user.username});
|
|
110
192
|
return page;
|
|
@@ -121,6 +203,8 @@ export async function pagesRoutes(fastify) {
|
|
|
121
203
|
if (!existing) return reply.status(404).send({ error: 'Page not found' });
|
|
122
204
|
|
|
123
205
|
await deletePage(urlPath);
|
|
206
|
+
// A share link must not outlive the page it pointed at.
|
|
207
|
+
await deletePreviewLinksForPage(urlPath);
|
|
124
208
|
return { success: true };
|
|
125
209
|
});
|
|
126
210
|
}
|