ferst-core 0.10.1 → 0.10.3
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/bin/check-pages.mjs +79 -0
- package/bin/cms-config.mjs +1 -1
- package/cms/config.template.yml +6 -43
- package/components/CookieBanner.astro +3 -1
- package/lib/draft-links.ts +65 -0
- package/lib/preview-frame.ts +19 -0
- package/lib/siteSettings.ts +15 -9
- package/package.json +2 -1
- package/cms/theme-preview.js +0 -108
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Ferst page allowance guard (myai4-webdev #119): a release never puts more pages on the live
|
|
3
|
+
// site than the site's plan publishes. The platform writes the plan's allowance into
|
|
4
|
+
// ferst-site.json (`pages`: a number, or null/absent for no limit); a page is published unless
|
|
5
|
+
// it says `"draft": true`. Home counts; the "page not found" page (`404`) never does.
|
|
6
|
+
// Run by the site's `guard` check on a release: `ferst-check-pages [siteRoot]` (defaults to .).
|
|
7
|
+
import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from 'node:fs';
|
|
8
|
+
import { join, relative } from 'node:path';
|
|
9
|
+
import { pathToFileURL } from 'node:url';
|
|
10
|
+
|
|
11
|
+
const PAGES_DIR = 'src/content/pages';
|
|
12
|
+
const NOT_FOUND = '404';
|
|
13
|
+
|
|
14
|
+
function* walk(dir) {
|
|
15
|
+
for (const name of readdirSync(dir)) {
|
|
16
|
+
const p = join(dir, name);
|
|
17
|
+
if (statSync(p).isDirectory()) yield* walk(p);
|
|
18
|
+
else if (name.endsWith('.json')) yield p;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function readJson(path) {
|
|
23
|
+
try {
|
|
24
|
+
return JSON.parse(readFileSync(path, 'utf8'));
|
|
25
|
+
} catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The plan's allowance and the published pages (their slugs, sorted); `over` is how many too
|
|
31
|
+
* many are published (0 when within the plan or there's no limit). Pure apart from reading. */
|
|
32
|
+
export function checkPages(root = '.') {
|
|
33
|
+
const meta = readJson(join(root, 'ferst-site.json'));
|
|
34
|
+
const allowance = meta && typeof meta.pages === 'number' ? meta.pages : null;
|
|
35
|
+
const dir = join(root, PAGES_DIR);
|
|
36
|
+
const published = [];
|
|
37
|
+
if (existsSync(dir)) {
|
|
38
|
+
for (const file of walk(dir)) {
|
|
39
|
+
const slug = relative(dir, file).replace(/\\/g, '/').replace(/\.json$/, '');
|
|
40
|
+
if (slug === NOT_FOUND) continue;
|
|
41
|
+
const data = readJson(file);
|
|
42
|
+
// A page that can't be read counts as published: the build reports the broken file.
|
|
43
|
+
if (data && data.draft === true) continue;
|
|
44
|
+
published.push(slug);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
published.sort();
|
|
48
|
+
const over = allowance == null ? 0 : Math.max(0, published.length - allowance);
|
|
49
|
+
return { allowance, published, over };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function main() {
|
|
53
|
+
const r = checkPages(process.argv[2] ?? '.');
|
|
54
|
+
if (r.allowance == null) {
|
|
55
|
+
console.log(`ferst-check-pages: ${r.published.length} pages published; the plan has no page limit.`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (r.over > 0) {
|
|
59
|
+
console.error(`::error::The plan publishes ${r.allowance} pages, and this release would publish ${r.published.length}:`);
|
|
60
|
+
for (const p of r.published) console.error(` ${p === 'index' ? 'index (home)' : p}`);
|
|
61
|
+
console.error(`Make ${r.over} of them a draft ("draft": true), or the site's owner chooses a bigger plan in the portal.`);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
console.log(`ferst-check-pages: ${r.published.length} of ${r.allowance} pages published.`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** True when run as a CLI, also through npm's `node_modules/.bin` symlink (see check-thin.mjs:
|
|
68
|
+
* it has to compare THIS file's URL, so it can't be shared). */
|
|
69
|
+
function isDirectInvocation(argv1) {
|
|
70
|
+
if (!argv1) return false;
|
|
71
|
+
if (import.meta.url === pathToFileURL(argv1).href) return true;
|
|
72
|
+
try {
|
|
73
|
+
return import.meta.url === pathToFileURL(realpathSync(argv1)).href;
|
|
74
|
+
} catch {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (isDirectInvocation(process.argv[1])) main();
|
package/bin/cms-config.mjs
CHANGED
|
@@ -70,7 +70,7 @@ const MANAGED_OWNER = 'myai4webdev';
|
|
|
70
70
|
|
|
71
71
|
/** The Pages collection's description on each plan. */
|
|
72
72
|
const PAGES_DESCRIPTION = {
|
|
73
|
-
basic: "See each page and request a change — our team makes it and sends it back for you to check. You don't edit the page layout here.",
|
|
73
|
+
basic: "See each page and request a change — our team makes it and sends it back for you to check. You don't edit the page layout here. To add a new page, or publish one, use the Pages tab in your Ferst portal.",
|
|
74
74
|
free: "You're on the free plan: you look after this site yourself and change its pages in your own repository. Asking the Ferst team to make changes for you comes with the Basic plan.",
|
|
75
75
|
};
|
|
76
76
|
|
package/cms/config.template.yml
CHANGED
|
@@ -20,49 +20,8 @@ collections:
|
|
|
20
20
|
- name: settings
|
|
21
21
|
label: Site settings
|
|
22
22
|
files:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
file: src/content/themeSettings/index.json
|
|
26
|
-
icon: palette
|
|
27
|
-
description: "Edit your brand in the Theme Studio, where you preview changes live before publishing — open portal.ferst.co.uk, choose this site, then the Design tab. The fields here still work as a fallback."
|
|
28
|
-
fields:
|
|
29
|
-
- { name: brand, label: Brand colour, widget: color, default: '#0E4D4A', hint: Buttons, links, icons, highlights. }
|
|
30
|
-
- { name: ink, label: Ink colour, widget: color, default: '#0C2123', hint: Headings and body text. }
|
|
31
|
-
- { name: surface, label: Surface colour, widget: color, default: '#FFFFFF', hint: Page background. }
|
|
32
|
-
- name: fonts
|
|
33
|
-
label: Typography
|
|
34
|
-
widget: object
|
|
35
|
-
collapsed: false
|
|
36
|
-
fields:
|
|
37
|
-
- name: heading
|
|
38
|
-
label: Heading font
|
|
39
|
-
widget: select
|
|
40
|
-
required: false
|
|
41
|
-
default: ''
|
|
42
|
-
options: &fonts
|
|
43
|
-
- { label: 'Default (theme)', value: '' }
|
|
44
|
-
- { label: 'Poppins', value: 'Poppins, system-ui, sans-serif' }
|
|
45
|
-
- { label: 'Inter', value: 'Inter, system-ui, sans-serif' }
|
|
46
|
-
- { label: 'Playfair Display', value: "'Playfair Display', Georgia, serif" }
|
|
47
|
-
- { label: 'Georgia', value: "Georgia, 'Times New Roman', serif" }
|
|
48
|
-
- { label: 'System', value: 'system-ui, sans-serif' }
|
|
49
|
-
- { name: body, label: Body font, widget: select, required: false, default: '', options: *fonts }
|
|
50
|
-
- { name: display, label: Display font, widget: select, required: false, default: '', options: *fonts }
|
|
51
|
-
- { name: corners, label: Corners, widget: select, default: rounded, options: [{ label: Sharp, value: sharp }, { label: Rounded, value: rounded }, { label: Soft, value: soft }] }
|
|
52
|
-
- { name: elevation, label: Elevation, widget: select, default: raised, options: [{ label: Raised, value: raised }, { label: Flat, value: flat }] }
|
|
53
|
-
- { name: stroke, label: Card stroke, widget: select, default: 'on', options: [{ label: 'On', value: 'on' }, { label: 'Off', value: 'off' }] }
|
|
54
|
-
- { name: fields, label: Input fields, widget: select, default: boxed, options: [{ label: Boxed, value: boxed }, { label: Filled, value: filled }, { label: Underline, value: underline }] }
|
|
55
|
-
- { name: darkDepth, label: Dark depth, widget: number, value_type: float, min: 0.14, max: 0.34, step: 0.01, default: 0.21 }
|
|
56
|
-
- { name: darkChroma, label: Dark colour intensity, widget: number, value_type: float, min: 0, max: 0.15, step: 0.01, default: 0.05 }
|
|
57
|
-
- name: darkOverrides
|
|
58
|
-
label: Dark colour overrides (optional)
|
|
59
|
-
widget: object
|
|
60
|
-
collapsed: true
|
|
61
|
-
fields:
|
|
62
|
-
- { name: ground, label: Ground, widget: string, required: false }
|
|
63
|
-
- { name: text, label: Text, widget: string, required: false }
|
|
64
|
-
- { name: accent, label: Accent, widget: string, required: false }
|
|
65
|
-
|
|
23
|
+
# No design tokens pane: a site's look is set in the portal, on its Design tab, for every
|
|
24
|
+
# site and branch (myai4-webdev #119). The themeSettings file is the portal's to write.
|
|
66
25
|
- name: identity
|
|
67
26
|
label: Identity & contact
|
|
68
27
|
file: src/content/siteSettings/index.json
|
|
@@ -240,6 +199,10 @@ collections:
|
|
|
240
199
|
extension: json
|
|
241
200
|
format: json
|
|
242
201
|
icon: description
|
|
202
|
+
# Pages are added, published and made drafts on the portal's Pages tab, within the site's
|
|
203
|
+
# plan (myai4-webdev #119): the CMS shows each page, for its people to request changes.
|
|
204
|
+
create: false
|
|
205
|
+
delete: false
|
|
243
206
|
nested: { depth: 3, summary: "{{title}}" }
|
|
244
207
|
summary: "{{title}}"
|
|
245
208
|
identifier_field: title
|
|
@@ -29,9 +29,11 @@ const { policyHref = '/cookie-policy/' } = Astro.props;
|
|
|
29
29
|
|
|
30
30
|
<script>
|
|
31
31
|
import { isDecided, setConsent } from '../lib/consent-client';
|
|
32
|
+
import { inPreviewFrame } from '../lib/preview-frame';
|
|
32
33
|
|
|
33
34
|
const banner = document.getElementById('cookie-banner');
|
|
34
|
-
|
|
35
|
+
// A preview in the portal isn't a visit: the banner stays out of its way (lib/preview-frame).
|
|
36
|
+
if (banner && !isDecided() && !inPreviewFrame()) {
|
|
35
37
|
banner.hidden = false;
|
|
36
38
|
// Next frame so the entry transition runs.
|
|
37
39
|
requestAnimationFrame(() => banner.classList.add('visible'));
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A page can be a draft (`draft: true`): kept in the repo, but not on the site. A menu link to
|
|
3
|
+
* a draft would lead to "page not found", so the menu leaves those links out, and publishing
|
|
4
|
+
* the page brings its link back without anyone editing the menu (myai4-webdev #119).
|
|
5
|
+
*
|
|
6
|
+
* Pure, so it is unit-tested without an Astro content context; `lib/siteSettings` applies it.
|
|
7
|
+
*/
|
|
8
|
+
import type { NavGroup, NavLink } from '../content/schemas';
|
|
9
|
+
|
|
10
|
+
export interface Navigation {
|
|
11
|
+
primary: NavLink[];
|
|
12
|
+
footer: NavLink[];
|
|
13
|
+
footerGroups: Array<{ heading: string; links: NavLink[] }>;
|
|
14
|
+
dropdown?: NavGroup;
|
|
15
|
+
cta: { label: string; href: string } | null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** The address of a `pages` entry: `index` is home (`/`), any other id is `/<id>`. */
|
|
19
|
+
function addressOf(id: string): string {
|
|
20
|
+
return id === 'index' ? '/' : `/${id}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The addresses of the draft pages (no trailing slash; home is `/`). */
|
|
24
|
+
export function draftAddresses(pages: Array<{ id: string; data: { draft?: boolean } }>): Set<string> {
|
|
25
|
+
return new Set(pages.filter((p) => p.data.draft === true).map((p) => addressOf(p.id)));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A link's address on this site, normalised to compare with draftAddresses; null when it
|
|
29
|
+
* leads off the site (another domain, mailto:, tel:, an in-page #anchor). */
|
|
30
|
+
function siteAddress(href: string): string | null {
|
|
31
|
+
if (!href.startsWith('/') || href.startsWith('//')) return null;
|
|
32
|
+
const path = href.split(/[?#]/)[0];
|
|
33
|
+
return path.length > 1 ? path.replace(/\/+$/, '') : '/';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The navigation with every link to a draft page left out. */
|
|
37
|
+
export function hideDraftLinks<N extends Navigation>(nav: N, drafts: Set<string>): N {
|
|
38
|
+
if (!drafts.size) return nav;
|
|
39
|
+
const live = (href: string) => {
|
|
40
|
+
const a = siteAddress(href);
|
|
41
|
+
return a === null || !drafts.has(a);
|
|
42
|
+
};
|
|
43
|
+
const keep = (links: NavLink[]) => links.filter((l) => live(l.href));
|
|
44
|
+
|
|
45
|
+
let dropdown = nav.dropdown;
|
|
46
|
+
if (dropdown) {
|
|
47
|
+
const items = dropdown.items.filter((i) => live(i.href));
|
|
48
|
+
if (live(dropdown.href)) dropdown = { ...dropdown, items };
|
|
49
|
+
else dropdown = items.length ? { ...dropdown, href: items[0].href, items } : undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let cta = nav.cta;
|
|
53
|
+
if (cta && !live(cta.href)) cta = live('/contact/') ? { label: 'Contact', href: '/contact/' } : null;
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
...nav,
|
|
57
|
+
primary: keep(nav.primary),
|
|
58
|
+
footer: keep(nav.footer),
|
|
59
|
+
footerGroups: nav.footerGroups
|
|
60
|
+
.map((g) => ({ ...g, links: keep(g.links) }))
|
|
61
|
+
.filter((g) => g.links.length > 0),
|
|
62
|
+
dropdown,
|
|
63
|
+
cta,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Is this page being shown as a preview inside the portal (Make it yours, the Design tab)? It is
|
|
3
|
+
* when it's framed and was opened with `?preview` or is already in a preview session (links
|
|
4
|
+
* clicked inside the frame drop the query). The live theme listener and the cookie banner both ask:
|
|
5
|
+
* the banner stays out of the way of a preview, where nobody is visiting the site.
|
|
6
|
+
*/
|
|
7
|
+
export function inPreviewFrame(win: Pick<Window, 'parent' | 'location' | 'sessionStorage'> = window): boolean {
|
|
8
|
+
try {
|
|
9
|
+
if (win.parent === (win as unknown)) return false;
|
|
10
|
+
} catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
if (new URLSearchParams(win.location.search).has('preview')) return true;
|
|
14
|
+
try {
|
|
15
|
+
return win.sessionStorage.getItem('ferst-preview-on') === '1';
|
|
16
|
+
} catch {
|
|
17
|
+
return false; // sessionStorage blocked: only the ?preview query counts
|
|
18
|
+
}
|
|
19
|
+
}
|
package/lib/siteSettings.ts
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
* `schema.parse()` does. We re-parse each entry through its own schema so nested
|
|
12
12
|
* defaults are fully populated, including when a file is missing.
|
|
13
13
|
*/
|
|
14
|
-
import { getEntry } from 'astro:content';
|
|
14
|
+
import { getCollection, getEntry } from 'astro:content';
|
|
15
|
+
import { draftAddresses, hideDraftLinks } from './draft-links';
|
|
15
16
|
import {
|
|
16
17
|
footerSettingsSchema,
|
|
17
18
|
logoSettingsSchema,
|
|
@@ -37,24 +38,29 @@ let cached: LoadedSiteSettings | null = null;
|
|
|
37
38
|
export async function loadSiteSettings(): Promise<LoadedSiteSettings> {
|
|
38
39
|
if (cached) return cached;
|
|
39
40
|
|
|
40
|
-
const [siteSettingsEntry, logoEntry, navbarEntry, footerEntry, themeEntry] = await Promise.all([
|
|
41
|
+
const [siteSettingsEntry, logoEntry, navbarEntry, footerEntry, themeEntry, pageEntries] = await Promise.all([
|
|
41
42
|
getEntry('siteSettings', 'index'),
|
|
42
43
|
getEntry('logoSettings', 'index'),
|
|
43
44
|
getEntry('navbarSettings', 'index'),
|
|
44
45
|
getEntry('footerSettings', 'index'),
|
|
45
46
|
getEntry('themeSettings', 'index'),
|
|
47
|
+
// Draft pages aren't on the site, so the menu leaves out links to them (lib/draft-links).
|
|
48
|
+
getCollection('pages').catch(() => []),
|
|
46
49
|
]);
|
|
47
50
|
|
|
48
51
|
cached = {
|
|
49
52
|
...siteSettingsSchema.parse(siteSettingsEntry?.data ?? {}),
|
|
50
53
|
...logoSettingsSchema.parse(logoEntry?.data ?? {}),
|
|
51
|
-
navigation:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
navigation: hideDraftLinks(
|
|
55
|
+
{
|
|
56
|
+
primary: navbarSettingsSchema.parse(navbarEntry?.data ?? {}).primary,
|
|
57
|
+
footer: footerSettingsSchema.parse(footerEntry?.data ?? {}).footer,
|
|
58
|
+
footerGroups: footerSettingsSchema.parse(footerEntry?.data ?? {}).groups,
|
|
59
|
+
dropdown: navbarSettingsSchema.parse(navbarEntry?.data ?? {}).dropdown,
|
|
60
|
+
cta: navbarSettingsSchema.parse(navbarEntry?.data ?? {}).cta,
|
|
61
|
+
},
|
|
62
|
+
draftAddresses(pageEntries as Array<{ id: string; data: { draft?: boolean } }>),
|
|
63
|
+
),
|
|
58
64
|
theme: themeSettingsSchema.parse(themeEntry?.data ?? {}),
|
|
59
65
|
};
|
|
60
66
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ferst-core",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Ferst Core — the shared, brand-agnostic client-site system: Astro components, layouts, content schemas, the layered config resolver, and a neutral styling architecture that every client overrides.",
|
|
6
6
|
"license": "BUSL-1.1",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
],
|
|
51
51
|
"bin": {
|
|
52
52
|
"ferst-check-thin": "bin/check-thin.mjs",
|
|
53
|
+
"ferst-check-pages": "bin/check-pages.mjs",
|
|
53
54
|
"ferst-set-cms-branch": "bin/set-cms-branch.mjs",
|
|
54
55
|
"ferst-cms-config": "bin/cms-config.mjs",
|
|
55
56
|
"ferst-update": "bin/ferst-update.mjs",
|
package/cms/theme-preview.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CMS design-tokens live preview (PDLC Phase 1 / WS4) — SPIKE artifact.
|
|
3
|
-
*
|
|
4
|
-
* Registers a Sveltia/Decap preview template for the `theme` file collection that
|
|
5
|
-
* embeds an iframe of the live site (?preview=1) and pushes the editor's CURRENT
|
|
6
|
-
* (unsaved) token values to it over postMessage — same-origin, since /admin and
|
|
7
|
-
* the site share the client domain. Re-themes live via ferst-core's site-side
|
|
8
|
-
* listener (lib/theme-preview.ts). Save is the CMS's existing git-proxy write.
|
|
9
|
-
*
|
|
10
|
-
* STATUS: unverified against the deployed Sveltia (pre-1.0; docs warn of Decap
|
|
11
|
-
* preview-template compat gaps). It is fully GUARDED — if the API isn't present or
|
|
12
|
-
* differs, it logs once and no-ops, so it can never break the CMS. The portal
|
|
13
|
-
* Theme Studio is the guaranteed token surface until the dev spike confirms this.
|
|
14
|
-
*
|
|
15
|
-
* Include from a client's public/admin/index.html AFTER the Sveltia bundle:
|
|
16
|
-
* <script src="/ferst/theme-preview.js"></script> (copied from ferst-core/cms)
|
|
17
|
-
*/
|
|
18
|
-
(function () {
|
|
19
|
-
'use strict';
|
|
20
|
-
|
|
21
|
-
var MSG = { theme: 'ferst:preview:theme', ready: 'ferst:preview:ready' };
|
|
22
|
-
// Match the CMS theme collection's fields (config.yml `theme` file).
|
|
23
|
-
var FIELDS = ['brand', 'ink', 'surface', 'corners', 'elevation', 'stroke', 'fields', 'darkDepth', 'darkChroma'];
|
|
24
|
-
|
|
25
|
-
function log(msg) {
|
|
26
|
-
try {
|
|
27
|
-
console.info('[ferst theme-preview] ' + msg);
|
|
28
|
-
} catch (_) {}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Read the live entry into a themeSettings-shaped draft (Immutable Map API).
|
|
32
|
-
function draftFromEntry(entry) {
|
|
33
|
-
var get = function (k) {
|
|
34
|
-
try {
|
|
35
|
-
return entry && entry.getIn ? entry.getIn(['data', k]) : undefined;
|
|
36
|
-
} catch (_) {
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
var fonts = get('fonts') || {};
|
|
41
|
-
var ov = get('darkOverrides') || {};
|
|
42
|
-
var pick = function (o, k) {
|
|
43
|
-
return o && typeof o.get === 'function' ? o.get(k) : o ? o[k] : '';
|
|
44
|
-
};
|
|
45
|
-
return {
|
|
46
|
-
brand: get('brand') || '',
|
|
47
|
-
ink: get('ink') || '',
|
|
48
|
-
surface: get('surface') || '',
|
|
49
|
-
fonts: { heading: pick(fonts, 'heading') || '', body: pick(fonts, 'body') || '', display: pick(fonts, 'display') || '' },
|
|
50
|
-
corners: get('corners') || 'rounded',
|
|
51
|
-
elevation: get('elevation') || 'raised',
|
|
52
|
-
stroke: get('stroke') || 'on',
|
|
53
|
-
fields: get('fields') || 'boxed',
|
|
54
|
-
darkDepth: typeof get('darkDepth') === 'number' ? get('darkDepth') : 0.21,
|
|
55
|
-
darkChroma: typeof get('darkChroma') === 'number' ? get('darkChroma') : 0.05,
|
|
56
|
-
darkOverrides: { ground: pick(ov, 'ground') || '', text: pick(ov, 'text') || '', accent: pick(ov, 'accent') || '' },
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function register(CMS, React) {
|
|
61
|
-
var Preview = function (props) {
|
|
62
|
-
// Keep one iframe of the live site in the preview pane; push the draft on
|
|
63
|
-
// every render (Sveltia re-renders as the editor types) and on ready.
|
|
64
|
-
var doc = props.document || document;
|
|
65
|
-
var frame = doc.getElementById('ferst-preview-frame');
|
|
66
|
-
if (!frame) {
|
|
67
|
-
frame = doc.createElement('iframe');
|
|
68
|
-
frame.id = 'ferst-preview-frame';
|
|
69
|
-
frame.src = '/?preview=1';
|
|
70
|
-
frame.style.cssText = 'width:100%;height:100%;min-height:80vh;border:0';
|
|
71
|
-
(doc.body || doc.documentElement).appendChild(frame);
|
|
72
|
-
(props.window || window).addEventListener('message', function (e) {
|
|
73
|
-
if (e && e.data && e.data.type === MSG.ready) postDraft();
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
function postDraft() {
|
|
77
|
-
try {
|
|
78
|
-
frame.contentWindow.postMessage({ type: MSG.theme, theme: draftFromEntry(props.entry) }, window.location.origin);
|
|
79
|
-
} catch (_) {}
|
|
80
|
-
}
|
|
81
|
-
postDraft();
|
|
82
|
-
// Render nothing of our own into React's tree — we own the iframe directly.
|
|
83
|
-
return React && React.createElement ? React.createElement('div', { style: { display: 'none' } }) : null;
|
|
84
|
-
};
|
|
85
|
-
CMS.registerPreviewTemplate('theme', Preview);
|
|
86
|
-
log('registered live preview for the theme collection');
|
|
87
|
-
void FIELDS; // documents the fields this mirrors
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
var tries = 0;
|
|
91
|
-
(function wait() {
|
|
92
|
-
var CMS = window.CMS;
|
|
93
|
-
var React = window.React || window.h || (CMS && CMS.React);
|
|
94
|
-
if (CMS && typeof CMS.registerPreviewTemplate === 'function') {
|
|
95
|
-
try {
|
|
96
|
-
register(CMS, React);
|
|
97
|
-
} catch (err) {
|
|
98
|
-
log('registerPreviewTemplate failed — in-pane preview disabled (use the portal Theme Studio). ' + (err && err.message));
|
|
99
|
-
}
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
if (tries++ < 40) {
|
|
103
|
-
setTimeout(wait, 250); // CMS loads async as an ES module
|
|
104
|
-
} else {
|
|
105
|
-
log('CMS.registerPreviewTemplate not found — in-pane preview unavailable in this CMS build.');
|
|
106
|
-
}
|
|
107
|
-
})();
|
|
108
|
-
})();
|