Files
validation-lab-site/public/admin/preview.js
T
Keith 7bac903809
deploy / build-and-publish (push) Successful in 40s
Pricing flow: model picker first, then model-specific price ranges
- Q0 'Which pricing model would you prefer?' (monthly / annual / per
  project radios) gates the four PSM questions; picking a model reveals
  question 1 and swaps each question's ranges to that model's set
  (switching model clears previous answers)
- ranges: monthly and per-project unchanged (€0/10/25/50/100+); annual
  €0/50/150/300/500 (tops at €500 per Keith's gut - to be tested)
- questions reworded model-neutral ('At what price...' instead of
  'monthly price')
- analytics: price-model-<model> for the picker, price-<model>-<question>-<option>
  per answer; Zoho payload gains price_model plus the usual question=option
  pairs
- CMS config: price_models list (key/label/options) + price_model_question;
  price_groups simplified to key/heading; preview mirrors the flow
2026-11-22 13:14:40 +01:00

204 lines
11 KiB
JavaScript

// Custom preview template for Sveltia CMS: mirrors the site's
// Site.astro layout so the preview pane shows what the published page
// will look like (hero banner, pilot banner, cards, price checklist,
// journey, capability checklist), instead of Sveltia's generic field dump.
//
// Runs in the browser as-is: the CMS bundle exposes the globals `CMS`
// and `html` (HTM, bound to the CMS's React copy). Markup elements can
// carry data-key-path so click-to-highlight keeps working — clicking
// a section in the preview focuses that field in the edit pane.
const css = `
:root { --ink:#16213a; --muted:#5b6478; --accent:#3a55d9; --accent-soft:#eef1fd; --line:#e3e7f2; --bg:#fbfcfe; }
* { box-sizing:border-box; }
body { margin:0; font-family:ui-sans-serif,system-ui,-apple-system,'Segoe UI',sans-serif; color:var(--ink); background:var(--bg); line-height:1.65; }
.pv-nav { display:flex; gap:0.75rem; align-items:center; padding:0.9rem 1.5rem; border-bottom:1px solid var(--line); background:#fff; color:var(--muted); font-size:0.85rem; }
.pv-nav strong { color:var(--ink); display:flex; gap:0.45rem; align-items:center; }
main { max-width:58rem; margin:0 auto; padding:0 1.25rem 3rem; }
.pv-hero { position:relative; overflow:hidden; margin:0 -1.25rem; padding:3rem 1.25rem 2.6rem;
background:radial-gradient(42rem 20rem at 85% -10%, rgba(135,87,216,0.12), transparent 60%),
linear-gradient(180deg, var(--accent-soft), var(--bg)); border-bottom:1px solid var(--line); }
.pv-hero h1 { font-size:2.2rem; line-height:1.15; margin:0 0 1rem; letter-spacing:-0.02em; max-width:42rem; }
.pv-hero p { font-size:1.1rem; color:var(--muted); max-width:42rem; margin:0; }
.pv-cta { margin-top:1.4rem; display:flex; gap:0.6rem; flex-wrap:wrap; }
.pv-cta span { background:var(--accent); color:#fff; border-radius:0.5rem; padding:0.55rem 1rem; font-weight:600; font-size:0.95rem; }
.pv-cta span.sec { background:#fff; color:var(--accent); border:1px solid var(--accent); }
h2 { font-size:1.35rem; margin:2.2rem 0 0.8rem; letter-spacing:-0.01em; }
.pv-cards { margin-top:1rem; display:grid; gap:1rem; grid-template-columns:repeat(auto-fit,minmax(14rem,1fr)); }
.pv-card { background:#fff; border:1px solid var(--line); border-radius:0.7rem; padding:1rem 1.1rem; }
.pv-card strong { display:block; margin-bottom:0.4rem; }
.pv-card small { color:var(--muted); font-size:0.93rem; line-height:1.5; }
.pv-card .pv-link { display:inline-block; margin-top:0.6rem; color:var(--accent); font-size:0.9rem; font-weight:600; }
.pv-pilot { margin:1.4rem 0 0; padding:0.8rem 1.1rem; background:var(--accent); color:#fff; border-radius:0.55rem; }
.pv-pilot strong { text-transform:uppercase; letter-spacing:0.06em; font-size:0.75rem; }
.pv-pilot p { margin:0.2rem 0 0; font-size:0.95rem; }
.pv-price { display:flex; gap:0.6rem; align-items:center; background:#fff; border:1px solid var(--line); border-radius:0.45rem; padding:0.45rem 0.6rem; margin-bottom:0.35rem; }
.pv-price .tick { width:0.95rem; height:0.95rem; border:2px solid var(--accent); border-radius:50%; flex:none; }
.pv-price strong { font-size:0.95rem; }
fieldset.pv-pricegroup, .pv-pricegroup { border:0; margin:1.1rem 0 0; padding:0; }
.pv-pricegroup legend { font-weight:600; font-size:1rem; margin-bottom:0.4rem; color:var(--ink); }
.pv-modelq { font-weight:600; margin:1.4rem 0 0.4rem; }
.pv-models { display:flex; gap:0.5rem; flex-wrap:wrap; }
.pv-journey ol { list-style:none; padding:0; margin:0.5rem 0 0; display:grid; gap:0.55rem; }
.pv-journey li { padding:0.55rem 0.9rem; background:#fff; border:1px solid var(--line); border-inline-start:3px solid var(--accent); border-radius:0.45rem; color:var(--muted); font-size:0.95rem; }
.pv-journey li b { color:var(--ink); }
.pv-cap { display:flex; gap:0.8rem; align-items:flex-start; background:var(--accent-soft); border:1px solid var(--line); border-radius:0.7rem; padding:0.85rem 1rem; margin-bottom:0.6rem; }
.pv-cap .tick { width:1.05rem; height:1.05rem; border:2px solid var(--accent); border-radius:0.3rem; flex:none; margin-top:0.2rem; }
.pv-cap strong { display:block; }
.pv-cap small { color:var(--muted); }
.pv-request { display:inline-block; background:var(--accent); color:#fff; border-radius:0.5rem; padding:0.55rem 1rem; font-weight:600; font-size:0.95rem; margin-top:0.6rem; }
.pv-body { margin-top:1.6rem; }
.pv-body h1, .pv-body h2, .pv-body h3 { margin-top:1.5rem; }
.pv-body img { max-width:100%; height:auto; border-radius:0.5rem; }
.pv-body ul { padding-inline-start:1.5rem; }
.pv-body blockquote { margin:1.2rem 0; padding:0.4rem 1rem; border-inline-start:3px solid var(--accent); color:var(--muted); }
.pv-empty { color:var(--muted); font-size:0.9rem; padding:1rem; text-align:center; }
`;
const items = (widgets) =>
(Array.isArray(widgets) ? widgets : []).map((w) => w.getIn(["data"]));
const PagePreview = ({ entry, widgetFor, widgetsFor }) => {
const d = (key) => entry.getIn(["data", key]);
const valueProps = items(widgetsFor("value_props"));
const journey = items(widgetsFor("journey"));
const caps = items(widgetsFor("capabilities"));
const priceGroups = items(widgetsFor("price_groups"));
const priceModels = items(widgetsFor("price_models"));
const hasHero = d("hero_headline") || d("hero_sub");
return html`
<div>
<div class="pv-nav">
<strong>
<svg width="18" height="18" viewBox="0 0 32 32" aria-hidden="true">
<defs>
<linearGradient id="pv-mark" x1="0" y1="0" x2="1" y2="1">
<stop offset="0" stop-color="#3a55d9" />
<stop offset="1" stop-color="#8757d8" />
</linearGradient>
</defs>
<rect width="32" height="32" rx="8" fill="url(#pv-mark)" />
<path
d="M8.5 20.5c1.4-9.6 6.6-10.7 7-10.7 2.3 0-1.6 8.6 1.2 8.6 1.7 0 3.9-4.5 6.8-6.9"
fill="none" stroke="#fff" stroke-width="2.4" stroke-linecap="round"
/>
</svg>
Validation Lab — preview
</strong>
</div>
<main>
${hasHero &&
html`
<section class="pv-hero">
<h1 data-key-path="hero_headline" tabindex="0">${d("hero_headline")}</h1>
${d("hero_sub") &&
html`<p data-key-path="hero_sub" tabindex="0">${d("hero_sub")}</p>`}
${(d("cta_founders") || d("cta_hubs")) &&
html`
<p class="pv-cta">
${d("cta_founders") && html`<span data-key-path="cta_founders">${d("cta_founders")}</span>`}
${d("cta_hubs") && html`<span class="sec" data-key-path="cta_hubs">${d("cta_hubs")}</span>`}
</p>
`}
</section>
`}
${d("pilot_text") &&
html`<aside class="pv-pilot" data-key-path="pilot_text" tabindex="0">
${d("pilot_label") && html`<strong>${d("pilot_label")}</strong>`}
<p>${d("pilot_text")}</p>
</aside>`}
${valueProps.length > 0 &&
html`
<section>
<h2>${d("value_props_title") || "Cards"}</h2>
<div class="pv-cards">
${valueProps.map((v, i) =>
html`<div class="pv-card" data-key-path={`value_props.${i}.heading`} tabindex="0">
<strong>${v.get("heading")}</strong>
<small>${v.get("text")}</small>
${v.get("link") && html`<span class="pv-link">→</span>`}
</div>`,
)}
</div>
</section>
`}
${(priceGroups.length > 0 && priceModels.length > 0) &&
html`
<section>
<h2>${d("price_title")}</h2>
${d("price_note") &&
html`<p data-key-path="price_note" tabindex="0">${d("price_note")}</p>`}
<p class="pv-modelq">${d("price_model_question")}</p>
<div class="pv-models">
${priceModels.map((m, i) =>
html`<span class="pv-price" data-key-path={"price_models." + i + ".label"} tabindex="0">
<span class="tick"></span>
<strong>${m.get("label")}</strong>
</span>`,
)}
</div>
${priceGroups.map((g, i) => {
const firstModel = priceModels[0];
const opts = firstModel ? Array.from(firstModel.get("options") || []) : [];
return html`<fieldset class="pv-pricegroup" data-key-path={"price_groups." + i + ".heading"} tabindex="0">
<legend>${g.get("heading")}</legend>
${opts.map((o, j) =>
html`<span class="pv-price" data-key-path={`price_groups.${i}.heading`} tabindex="0">
<span class="tick"></span>
<strong>${o.get("label")}</strong>
</span>`,
)}
</fieldset>`;
})}
</section>
`}
${journey.length > 0 &&
html`
<section class="pv-journey">
<h2>${d("journey_title") || "The journey"}</h2>
${d("journey_note") &&
html`<p data-key-path="journey_note" tabindex="0">${d("journey_note")}</p>`}
<ol>
${journey.map((s, i) =>
html`<li data-key-path={`journey.${i}.title`} tabindex="0">
<b>${s.get("title")}</b>${s.get("text") ? html` — ${s.get("text")}` : null}
</li>`,
)}
</ol>
</section>
`}
${caps.length > 0 &&
html`
<section>
<h2>${d("capabilities_title")}</h2>
${d("capabilities_note") &&
html`<p data-key-path="capabilities_note" tabindex="0">${d("capabilities_note")}</p>`}
${caps.map((c, i) =>
html`<div class="pv-cap" data-key-path={`capabilities.${i}.heading`} tabindex="0">
<span class="tick"></span>
<span>
<strong>${c.get("heading")}</strong>
<small>${c.get("text")}</small>
</span>
</div>`,
)}
${d("capabilities_cta") && html`<span class="pv-request">${d("capabilities_cta")}</span>`}
</section>
`}
<div class="pv-body" data-key-path="body">${widgetFor("body")}</div>
${(!hasHero &&
valueProps.length === 0 &&
journey.length === 0 &&
caps.length === 0 &&
priceGroups.length === 0 && priceModels.length === 0 &&
!d("pilot_text")) &&
html`<p class="pv-empty">No structured sections — the preview shows the body only.</p>`}
</main>
</div>
`;
};
CMS.registerPreviewStyle(css, { raw: true });
CMS.registerPreviewTemplate("pages", PagePreview);