@morphemecms/cms 0.9.0-next-20261105115842 → 0.9.1
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/CHANGELOG.md +24 -1
- package/defaults/collections.ts +112 -58
- package/defaults/company.ts +1 -1
- package/defaults/editor.ts +2 -2
- package/defaults/texts.ts +14 -5
- package/demo/src/content/pages/app-store.md +0 -1
- package/demo/src/content/pages/blocks.md +0 -1
- package/icons/lucide/arrows-horizontal.svg +1 -0
- package/icons/lucide/columns-plus-left.svg +1 -0
- package/icons/lucide/columns-plus-right.svg +1 -0
- package/icons/lucide/file.svg +1 -0
- package/icons/material-symbols/arrows-horizontal.svg +1 -0
- package/icons/material-symbols/columns-plus-left.svg +1 -0
- package/icons/material-symbols/columns-plus-right.svg +1 -0
- package/icons/material-symbols/file.svg +1 -0
- package/icons/phosphor/arrows-horizontal.svg +1 -0
- package/icons/phosphor/columns-plus-left.svg +1 -0
- package/icons/phosphor/columns-plus-right.svg +1 -0
- package/icons/phosphor/file.svg +1 -0
- package/lib/fold-open.d.mts +2 -0
- package/lib/fold-open.mjs +22 -0
- package/lib/fold-open.test.mjs +24 -0
- package/lib/menu.test.mjs +16 -3
- package/lib/page-template.d.mts +54 -0
- package/lib/page-template.mjs +126 -0
- package/lib/page-template.test.mjs +129 -0
- package/lib/side-block.d.mts +2 -16
- package/lib/side-block.mjs +12 -30
- package/lib/side-block.test.mjs +13 -30
- package/package.json +1 -1
- package/scripts/check-side.mjs +49 -22
- package/scripts/editor-roundtrip.mjs +15 -6
- package/scripts/fixtures/side/side-full.md +8 -0
- package/scripts/fixtures/side/side-left.md +8 -0
- package/scripts/fixtures/side/side-none.md +7 -0
- package/scripts/fixtures/side/side-right.md +8 -0
- package/scripts/fixtures/side/side-single.md +8 -0
- package/scripts/side-width.mjs +29 -0
- package/scripts/side-width.test.mjs +30 -0
- package/site/content.config.ts +3 -4
- package/site/header.d.mts +21 -0
- package/site/header.mjs +35 -0
- package/site/header.test.mjs +59 -0
- package/site/icons.d.mts +16 -0
- package/site/icons.mjs +8 -0
- package/site/site.ts +9 -4
- package/site/templates.ts +7 -0
- package/site/theme.mjs +3 -0
- package/site/tracking.client.ts +4 -4
- package/src/App.tsx +12 -24
- package/src/AppList.tsx +36 -14
- package/src/AppSettingsTab.tsx +5 -3
- package/src/BlockDialog.tsx +50 -5
- package/src/DataFileFields.tsx +35 -0
- package/src/DataForm.tsx +16 -38
- package/src/Deleted.tsx +7 -3
- package/src/EntryForm.tsx +41 -88
- package/src/FooterSettings.tsx +76 -0
- package/src/FormFrame.tsx +2 -1
- package/src/HeaderSettings.tsx +100 -0
- package/src/Library.tsx +26 -14
- package/src/MarkdownEditor.tsx +18 -36
- package/src/Media.tsx +6 -3
- package/src/Redirects.tsx +12 -9
- package/src/SectionSettings.tsx +21 -0
- package/src/SectionSettingsIcon.tsx +10 -0
- package/src/SettingsSections.tsx +57 -0
- package/src/ThemeStore.tsx +28 -9
- package/src/Versions.tsx +3 -15
- package/src/busyAction.d.mts +3 -0
- package/src/busyAction.mjs +8 -0
- package/src/busyAction.test.mjs +16 -0
- package/src/dataFileValues.ts +30 -0
- package/src/editor.css +42 -3
- package/src/fields.tsx +29 -10
- package/src/footerPreview.d.mts +46 -0
- package/src/footerPreview.mjs +84 -0
- package/src/footerPreview.test.mjs +100 -0
- package/src/formSections.ts +100 -0
- package/src/frontmatter.mjs +1 -1
- package/src/frontmatter.test.mjs +11 -11
- package/src/headerPreview.d.mts +48 -0
- package/src/headerPreview.mjs +168 -0
- package/src/headerPreview.test.mjs +183 -0
- package/src/headerTheme.tsx +58 -0
- package/src/i18n/da-DK/common.ts +1 -0
- package/src/i18n/da-DK/library.ts +2 -0
- package/src/i18n/da-DK/preview.ts +2 -0
- package/src/i18n/da-DK/text.ts +1 -0
- package/src/i18n/en-US/common.ts +1 -0
- package/src/i18n/en-US/library.ts +4 -0
- package/src/i18n/en-US/preview.ts +3 -0
- package/src/i18n/en-US/text.ts +2 -1
- package/src/images.ts +7 -2
- package/src/menuChildren.ts +1 -3
- package/src/movedRoutes.d.mts +3 -0
- package/src/movedRoutes.mjs +35 -0
- package/src/movedRoutes.test.mjs +22 -0
- package/src/pagePreview.tsx +40 -29
- package/src/partPreview.tsx +59 -0
- package/src/schema.ts +7 -1
- package/src/sheetPlacement.d.mts +3 -0
- package/src/sheetPlacement.mjs +9 -0
- package/src/sheetPlacement.test.mjs +23 -0
- package/src/standard/views.ts +3 -3
- package/src/templateField.ts +28 -0
- package/src/themes.ts +3 -0
- package/src/ui.tsx +35 -8
- package/src/useDataFiles.ts +94 -0
- package/starter/package.json +1 -1
- package/theme/components/Footer.astro +14 -7
- package/theme/components/Header.astro +58 -33
- package/theme/components/MobileNav.astro +5 -4
- package/theme/components/RelatedPosts.astro +1 -1
- package/theme/components/headerParts.ts +17 -0
- package/theme/layouts/PageLayout.astro +20 -16
- package/theme/styles/base.css +6 -5
- package/theme/styles/blocks.css +8 -12
- package/theme/styles/components.css +8 -1
- package/theme/styles/global.css +5 -9
- package/theme/styles/ui.css +111 -5
- package/theme/theme.json +1 -0
- package/theme/ui/BusyContent.tsx +16 -0
- package/theme/ui/Button.tsx +25 -5
- package/theme/ui/IconButton.tsx +17 -4
- package/scripts/fixtures/side/side-off.md +0 -8
- package/scripts/fixtures/side/side-plain.md +0 -7
- package/scripts/fixtures/side/side-wide.md +0 -8
package/src/pagePreview.tsx
CHANGED
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
// (Astro's pipeline, with the HTML written in it), and its blocks are drawn as in the editor
|
|
11
11
|
// (registry.tsx preview), with the site's classes; a coloured section is a panel as on the site (lib/text-sections.mjs).
|
|
12
12
|
//
|
|
13
|
+
// Exposes pageDocument, usePagePreview and PageDraft, and for the preview of a part every page has (partPreview.tsx) siteShell,
|
|
14
|
+
// documentHtml, htmlOf and PREVIEW_WIDTH.
|
|
15
|
+
//
|
|
13
16
|
// The page is shown in a frame without scripts (sandbox), so nothing of the site runs on the editor's
|
|
14
17
|
// address, where its login is kept, and its links lead nowhere. A new page or post is shown in the
|
|
15
18
|
// page of another one. As on the site but for this: a changed text has the pictures themselves (not
|
|
@@ -56,9 +59,8 @@ export type PageDraft = {
|
|
|
56
59
|
// but those that read the site's files.
|
|
57
60
|
const markdownHtml = async (markdown: string) => String(await processor.process(markdown));
|
|
58
61
|
|
|
59
|
-
|
|
60
|
-
function
|
|
61
|
-
const drawn: ReactNode = drawBlock(type, props, data);
|
|
62
|
+
/** What React draws (a block, a part of the header drawn with the theme's components), as HTML. */
|
|
63
|
+
export function htmlOf(drawn: ReactNode) {
|
|
62
64
|
if (!drawn) return '';
|
|
63
65
|
const box = document.createElement('div');
|
|
64
66
|
const root = createRoot(box);
|
|
@@ -68,6 +70,9 @@ function blockHtml(type: string, props: Record<string, unknown>, data: BlockData
|
|
|
68
70
|
return html;
|
|
69
71
|
}
|
|
70
72
|
|
|
73
|
+
// A block drawn as in the editor, as HTML.
|
|
74
|
+
const blockHtml = (type: string, props: Record<string, unknown>, data: BlockData) => htmlOf(drawBlock(type, props, data));
|
|
75
|
+
|
|
71
76
|
// A picture made ready in this visit, which the site does not have yet (images.ts shownAt), in the
|
|
72
77
|
// page itself.
|
|
73
78
|
async function inline(src: string) {
|
|
@@ -89,25 +94,34 @@ async function sitePage(address: string) {
|
|
|
89
94
|
return new DOMParser().parseFromString(await res.text(), 'text/html');
|
|
90
95
|
}
|
|
91
96
|
|
|
97
|
+
/** The first of the site's pages (their addresses) that has a part (`has`, a selector), without its scripts and with its own
|
|
98
|
+
* addresses as on the site, for a frame (PageFrame); a link in it opens nothing (target, and no popups in the frame).
|
|
99
|
+
* Also for the preview of a part on every page (partPreview.tsx). */
|
|
100
|
+
export async function siteShell(addresses: string | string[], has: string): Promise<Document> {
|
|
101
|
+
for (const address of [addresses].flat()) {
|
|
102
|
+
const doc = await sitePage(address);
|
|
103
|
+
if (!doc.querySelector(has)) continue;
|
|
104
|
+
doc.querySelectorAll('script').forEach((s) => s.remove());
|
|
105
|
+
const base = doc.createElement('base');
|
|
106
|
+
base.href = new URL(address, location.href).href;
|
|
107
|
+
base.target = '_blank';
|
|
108
|
+
doc.head.prepend(base);
|
|
109
|
+
return doc;
|
|
110
|
+
}
|
|
111
|
+
throw new Error(t.preview.notHere);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** A page made ready (siteShell) as HTML for a frame, with the pictures made ready in this visit in it. */
|
|
115
|
+
export async function documentHtml(doc: Document): Promise<string> {
|
|
116
|
+
await Promise.all(
|
|
117
|
+
[...doc.querySelectorAll('img')].map(async (img) => img.setAttribute('src', await inline(img.getAttribute('src') ?? ''))),
|
|
118
|
+
);
|
|
119
|
+
return `<!doctype html>\n${doc.documentElement.outerHTML}`;
|
|
120
|
+
}
|
|
121
|
+
|
|
92
122
|
/** The page with the draft in it, as HTML for a frame (PageFrame). */
|
|
93
123
|
export async function pageDocument(draft: PageDraft): Promise<string> {
|
|
94
|
-
|
|
95
|
-
let shell = '';
|
|
96
|
-
for (const address of [draft.shell].flat()) {
|
|
97
|
-
const page = await sitePage(address);
|
|
98
|
-
if (page.querySelector('[data-editor="text"]')) {
|
|
99
|
-
doc = page;
|
|
100
|
-
shell = address;
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (!doc) throw new Error(t.preview.notHere);
|
|
105
|
-
doc.querySelectorAll('script').forEach((s) => s.remove());
|
|
106
|
-
// Its own addresses as on the site; a link opens nothing (target, and no popups in the frame).
|
|
107
|
-
const base = doc.createElement('base');
|
|
108
|
-
base.href = new URL(shell, location.href).href;
|
|
109
|
-
base.target = '_blank';
|
|
110
|
-
doc.head.prepend(base);
|
|
124
|
+
const doc = await siteShell(draft.shell, '[data-editor="text"]');
|
|
111
125
|
|
|
112
126
|
const heading = doc.querySelector('[data-editor="heading"]');
|
|
113
127
|
if (heading && draft.headingHtml) heading.innerHTML = draft.headingHtml;
|
|
@@ -166,17 +180,14 @@ export async function pageDocument(draft: PageDraft): Promise<string> {
|
|
|
166
180
|
})
|
|
167
181
|
.join('');
|
|
168
182
|
}
|
|
169
|
-
|
|
170
|
-
await Promise.all(
|
|
171
|
-
[...doc.querySelectorAll('img')].map(async (img) => img.setAttribute('src', await inline(img.getAttribute('src') ?? ''))),
|
|
172
|
-
);
|
|
173
|
-
return `<!doctype html>\n${doc.documentElement.outerHTML}`;
|
|
183
|
+
return documentHtml(doc);
|
|
174
184
|
}
|
|
175
185
|
|
|
176
|
-
// The
|
|
177
|
-
// layout is seen; compact at a common phone's.
|
|
186
|
+
// The sizes the page is shown at: Material 3's breakpoints.
|
|
178
187
|
const SIZES: Breakpoint[] = ['compact', 'medium', 'expanded', 'large', 'extraLarge'];
|
|
179
|
-
|
|
188
|
+
/** The width of the page at each size: the narrowest window it has, so its tightest layout is seen; compact at a common
|
|
189
|
+
* phone's. Also the preview of a part (partPreview.tsx). */
|
|
190
|
+
export const PREVIEW_WIDTH: Record<Breakpoint, number> = { ...BREAKPOINTS, compact: 390 };
|
|
180
191
|
|
|
181
192
|
/** The sheet with the preview, and how to open it with a draft (made when it opens). */
|
|
182
193
|
export function usePagePreview(): [(draft: () => PageDraft | null) => void, ReactNode] {
|
|
@@ -218,7 +229,7 @@ export function usePagePreview(): [(draft: () => PageDraft | null) => void, Reac
|
|
|
218
229
|
/>
|
|
219
230
|
</div>
|
|
220
231
|
{html ? (
|
|
221
|
-
<PageFrame html={html} width={
|
|
232
|
+
<PageFrame html={html} width={PREVIEW_WIDTH[size]} title={t.preview.title} />
|
|
222
233
|
) : (
|
|
223
234
|
<p className="px-5 text-muted">{problem || t.preview.making}</p>
|
|
224
235
|
)}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// The preview of a part every page has (the header: HeaderSettings.tsx; the footer next) as the form has it now, at once
|
|
2
|
+
// and without saving: the site's front page with only that part changed (`swap`, on a copy of the page each time the form
|
|
3
|
+
// changes), on a phone and on a computer (lib/breakpoints.mjs), each frame cut to the part (PageFrame `part`). Exposes
|
|
4
|
+
// PartPreview. Uses pagePreview.tsx (siteShell, documentHtml, PREVIEW_WIDTH) and ui.tsx.
|
|
5
|
+
import { useEffect, useState } from 'react';
|
|
6
|
+
import { siteShell, documentHtml, PREVIEW_WIDTH } from './pagePreview';
|
|
7
|
+
import { EmptyNote, FieldGroup, FormField, PageFrame } from './ui';
|
|
8
|
+
import { t } from './i18n';
|
|
9
|
+
|
|
10
|
+
// A pause after the last change before the page is drawn again, so typing does not draw it at every key.
|
|
11
|
+
const SETTLE = 250;
|
|
12
|
+
|
|
13
|
+
/** `part`: its data-editor name on the site's pages ("header"); `swap`: puts what the form changes into a copy of the
|
|
14
|
+
* page (a new function when the form changes). */
|
|
15
|
+
export function PartPreview({ part, swap }: { part: string; swap: (doc: Document) => void }) {
|
|
16
|
+
const selector = `[data-editor="${part}"]`;
|
|
17
|
+
const [shell, setShell] = useState<Document | null>(null);
|
|
18
|
+
const [html, setHtml] = useState<string | null>(null);
|
|
19
|
+
const [problem, setProblem] = useState('');
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
siteShell('/', selector).then(setShell, (e) => setProblem(t.preview.failed((e as Error).message)));
|
|
23
|
+
}, [selector]);
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (!shell) return;
|
|
27
|
+
let stopped = false;
|
|
28
|
+
const timer = setTimeout(() => {
|
|
29
|
+
const doc = shell.cloneNode(true) as Document;
|
|
30
|
+
try {
|
|
31
|
+
swap(doc);
|
|
32
|
+
} catch (e) {
|
|
33
|
+
return setProblem(t.preview.failed((e as Error).message));
|
|
34
|
+
}
|
|
35
|
+
documentHtml(doc).then((page) => !stopped && setHtml(page));
|
|
36
|
+
}, SETTLE);
|
|
37
|
+
return () => {
|
|
38
|
+
stopped = true;
|
|
39
|
+
clearTimeout(timer);
|
|
40
|
+
};
|
|
41
|
+
}, [shell, swap]);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<FieldGroup label={t.preview.title}>
|
|
45
|
+
{html ? (
|
|
46
|
+
<>
|
|
47
|
+
<FormField label={t.preview.phone}>
|
|
48
|
+
<PageFrame html={html} width={PREVIEW_WIDTH.compact} title={t.preview.phone} part={selector} />
|
|
49
|
+
</FormField>
|
|
50
|
+
<FormField label={t.preview.computer}>
|
|
51
|
+
<PageFrame html={html} width={PREVIEW_WIDTH.large} title={t.preview.computer} part={selector} />
|
|
52
|
+
</FormField>
|
|
53
|
+
</>
|
|
54
|
+
) : (
|
|
55
|
+
<EmptyNote busy={!problem}>{problem || t.preview.making}</EmptyNote>
|
|
56
|
+
)}
|
|
57
|
+
</FieldGroup>
|
|
58
|
+
);
|
|
59
|
+
}
|
package/src/schema.ts
CHANGED
|
@@ -63,6 +63,10 @@ export type Field = {
|
|
|
63
63
|
* chosen, in place of the field's own (the status of a page: what each one means). `onPage`: offered only while
|
|
64
64
|
* that relation has a choice on the page being edited (a button that opens a promotion); chosen, it is still shown. */
|
|
65
65
|
options?: { label: string; value: string; icon?: Icon; hint?: string; onPage?: Relation }[];
|
|
66
|
+
/** select: the options come from the theme in use. 'templates': a page's templates, the theme's "templates" (lib/page-template.mjs); the
|
|
67
|
+
* field shows those of its options the theme offers (templateFieldOf in templateField.ts), its default is the theme's first, which
|
|
68
|
+
* is written as no key, and it is hidden while at most one is left. */
|
|
69
|
+
offered?: 'templates';
|
|
66
70
|
/** select: the options are icons (their names, `icons`), shown as the icons to tap (fields.tsx). */
|
|
67
71
|
icons?: boolean;
|
|
68
72
|
/** select: the options side by side in a bar, the chosen one raised (SegmentedButton in ui.tsx), for two or
|
|
@@ -106,7 +110,7 @@ export type Field = {
|
|
|
106
110
|
only?: { field: string; is: string[] };
|
|
107
111
|
/** boolean: shown as a switch, with what it says when on and when off. */
|
|
108
112
|
toggle?: [string, string];
|
|
109
|
-
/** Its value changes how the page is laid out (
|
|
113
|
+
/** Its value changes how the page is laid out (its template): "Forhåndsvis" shows a page whose value
|
|
110
114
|
* is changed in another page saved with the same value (EntryForm.tsx). */
|
|
111
115
|
layout?: boolean;
|
|
112
116
|
/** blocks: a list where each item has a `type`, one of these, which gives its fields. */
|
|
@@ -288,6 +292,8 @@ export type DataFile = {
|
|
|
288
292
|
root?: Field;
|
|
289
293
|
/** A fixed page called by its label, not its H1 (the front page). */
|
|
290
294
|
byLabel?: boolean;
|
|
295
|
+
/** The site may have no such file: its screen opens on an empty one, and the first save makes the file (the header). */
|
|
296
|
+
optional?: boolean;
|
|
291
297
|
};
|
|
292
298
|
|
|
293
299
|
/** A fixed page's name in the editor: its H1 (`heading`), as the page has it now; the front page
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Where a step of the block sheet (BlockDialog.tsx) is shown: in a side panel at the window's end edge on a large screen
|
|
2
|
+
// for the fields of a block and the section settings, else in the dialog (the choice of block always is).
|
|
3
|
+
// Exposes inPanel(step, large); no dependencies.
|
|
4
|
+
|
|
5
|
+
/** Whether a step ('choose', 'fields', 'section' or none) is shown in the side panel; large: the window is at least
|
|
6
|
+
* the `large` breakpoint. */
|
|
7
|
+
export function inPanel(step, large) {
|
|
8
|
+
return !!large && (step === 'fields' || step === 'section');
|
|
9
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Tests for sheetPlacement.mjs: which steps of the block sheet are shown in the side panel.
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import { inPanel } from './sheetPlacement.mjs';
|
|
5
|
+
|
|
6
|
+
test('the fields and the section settings are in the panel on a large screen', () => {
|
|
7
|
+
assert.equal(inPanel('fields', true), true);
|
|
8
|
+
assert.equal(inPanel('section', true), true);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test('the choice of block is always a dialog', () => {
|
|
12
|
+
assert.equal(inPanel('choose', true), false);
|
|
13
|
+
assert.equal(inPanel('choose', false), false);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('below large everything is a dialog', () => {
|
|
17
|
+
assert.equal(inPanel('fields', false), false);
|
|
18
|
+
assert.equal(inPanel('section', false), false);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('a closed sheet is not in the panel', () => {
|
|
22
|
+
assert.equal(inPanel(undefined, true), false);
|
|
23
|
+
});
|
package/src/standard/views.ts
CHANGED
|
@@ -25,10 +25,10 @@ export const blockLoads: Record<string, Contract<any>> = {
|
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
/** The block type drawn in a column beside the text of a page, or null: the one src/data/side.json chooses, when its
|
|
28
|
-
* load.ts says `beside
|
|
28
|
+
* load.ts says `beside` and the page's template has a sidebar (lib/side-block.mjs). The theme's page layout
|
|
29
29
|
* (PageLayout.astro) draws it with Block.astro, given the page's text as `html`. */
|
|
30
|
-
export const sideBlock = (
|
|
31
|
-
sideBlockOf(
|
|
30
|
+
export const sideBlock = (template: string): string | null =>
|
|
31
|
+
sideBlockOf(template, sideSetting, (type) => blockLoads[type]?.beside === true);
|
|
32
32
|
|
|
33
33
|
// A block's tag in the text, at its very end (blocks.mjs writes it so).
|
|
34
34
|
const END = /<div data-block="([\w-]+)"(?: data-props="[^"]*")?\s*><\/div>\s*$/;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// The page form's field of the templates the chosen theme offers (Field.offered: 'templates'): which templates the theme
|
|
2
|
+
// offers, which of them the form shows, and what the form shows as chosen. Exposes offeredTemplatesOf, templateFieldOf, shownTemplate.
|
|
3
|
+
// Uses chosenTheme (ThemeStore.tsx), themes.ts, sideSettingOf (SideColumn.tsx) and lib/page-template.mjs.
|
|
4
|
+
import type { RepoFile } from './github';
|
|
5
|
+
import type { Field } from './schema';
|
|
6
|
+
import { chosenTheme } from './ThemeStore';
|
|
7
|
+
import { sideSettingOf } from './SideColumn';
|
|
8
|
+
import { themes } from './themes';
|
|
9
|
+
import { templateChoices, templateOf, templatesOf } from '../lib/page-template.mjs';
|
|
10
|
+
|
|
11
|
+
/** The templates the theme chosen (src/data/theme.json) offers, the first the default. */
|
|
12
|
+
export const offeredTemplatesOf = (files: RepoFile[]): string[] =>
|
|
13
|
+
templatesOf(themes.find((x) => x.id === chosenTheme(files)) ?? null) as string[];
|
|
14
|
+
|
|
15
|
+
/** The field with only the options the form can offer: those of the theme, without the sidebar ones while no block is
|
|
16
|
+
* chosen for the column (Appearance › Side column). Null when the field has no `offered` or at most one is left. */
|
|
17
|
+
export function templateFieldOf(field: Field, files: RepoFile[]): Field | null {
|
|
18
|
+
if (field.offered !== 'templates') return null;
|
|
19
|
+
const choices: string[] = templateChoices(offeredTemplatesOf(files), sideSettingOf(files) !== null);
|
|
20
|
+
return choices.length > 1 ? { ...field, options: field.options?.filter((o) => choices.includes(o.value)) } : null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** What the form shows as chosen: the value if the field offers it, else its first option (the theme's default). */
|
|
24
|
+
export const shownTemplate = (field: Field, value: unknown): string =>
|
|
25
|
+
templateOf(
|
|
26
|
+
{ template: value },
|
|
27
|
+
(field.options ?? []).map((o) => o.value),
|
|
28
|
+
);
|
package/src/themes.ts
CHANGED
|
@@ -25,6 +25,8 @@ export type ThemeInfo = {
|
|
|
25
25
|
icons?: string;
|
|
26
26
|
/** How it moves while the owner has chosen none ("motion" in its theme.json: a scheme of lib/motion.ts). */
|
|
27
27
|
motion?: string;
|
|
28
|
+
/** The page templates it offers, the first the default ("templates" in its theme.json: ids of lib/page-template.mjs). */
|
|
29
|
+
templates?: string[];
|
|
28
30
|
/** What it looks like, in a sentence or two, by the editor's language ("da-DK"), on its page. */
|
|
29
31
|
description?: Record<string, string>;
|
|
30
32
|
/** What it gives the site, a few short points by the editor's language, on its page. */
|
|
@@ -79,6 +81,7 @@ export const themes: ThemeInfo[] = Object.entries(manifests)
|
|
|
79
81
|
thirdParty: m.thirdParty,
|
|
80
82
|
...(m.icons ? { icons: m.icons } : {}),
|
|
81
83
|
...(m.motion ? { motion: m.motion } : {}),
|
|
84
|
+
...(m.templates ? { templates: m.templates } : {}),
|
|
82
85
|
description: m.description,
|
|
83
86
|
highlights: m.highlights,
|
|
84
87
|
screenshots: screenshotsOf(idOf(path)),
|
package/src/ui.tsx
CHANGED
|
@@ -135,6 +135,8 @@ type ButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'type'> & {
|
|
|
135
135
|
size?: ButtonSize;
|
|
136
136
|
/** Before the text. */
|
|
137
137
|
icon?: Icon;
|
|
138
|
+
/** Its action runs: disabled, and after a moment a loading indicator. */
|
|
139
|
+
busy?: boolean;
|
|
138
140
|
type?: 'button' | 'submit';
|
|
139
141
|
};
|
|
140
142
|
|
|
@@ -171,6 +173,8 @@ type IconButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children'
|
|
|
171
173
|
kind?: IconButtonKind;
|
|
172
174
|
selected?: boolean;
|
|
173
175
|
badge?: number | boolean;
|
|
176
|
+
/** Its action runs: disabled, and after a moment a loading indicator. */
|
|
177
|
+
busy?: boolean;
|
|
174
178
|
type?: 'button' | 'submit';
|
|
175
179
|
};
|
|
176
180
|
|
|
@@ -3207,28 +3211,36 @@ export function Dialog({ ref, className, children, ...rest }: DialogHTMLAttribut
|
|
|
3207
3211
|
|
|
3208
3212
|
/** The sheet from the bottom (a dialog in the middle on a computer): the theme's bottom sheet, as high as what is in
|
|
3209
3213
|
* it, on a <dialog> (`ref`; opened with showModal), with a SheetTitle and SheetBody, SheetList or SheetActions in it.
|
|
3210
|
-
* `full`: as high as the screen, and wider on a computer, with a whole page in it (the preview, PageFrame).
|
|
3214
|
+
* `full`: as high as the screen, and wider on a computer, with a whole page in it (the preview, PageFrame).
|
|
3215
|
+
* `panel`: the theme's modal side sheet (data-wide="side-sheet") at the window's end edge under the top bar, half the space
|
|
3216
|
+
* beside the start panel (.editor-side-panel in editor.css); the rest of the page stays in view, inert as under a dialog. */
|
|
3211
3217
|
export function BottomSheet({
|
|
3212
3218
|
ref,
|
|
3213
3219
|
full,
|
|
3220
|
+
panel,
|
|
3214
3221
|
className,
|
|
3215
3222
|
children,
|
|
3216
3223
|
...rest
|
|
3217
|
-
}: DialogHTMLAttributes<HTMLDialogElement> & { ref?: Ref<HTMLDialogElement>; full?: boolean }) {
|
|
3224
|
+
}: DialogHTMLAttributes<HTMLDialogElement> & { ref?: Ref<HTMLDialogElement>; full?: boolean; panel?: boolean }) {
|
|
3218
3225
|
const sheet = full ? siteBottomSheetFullClass : siteBottomSheetFitClass;
|
|
3219
3226
|
return (
|
|
3220
|
-
<dialog ref={ref} className={[sheet, 'editor-sheet', className].filter(Boolean).join(' ')} {...rest}>
|
|
3221
|
-
<div className={siteBottomSheetContainerClass()}
|
|
3227
|
+
<dialog ref={ref} className={[sheet, 'editor-sheet', panel && 'editor-side-panel', className].filter(Boolean).join(' ')} {...rest}>
|
|
3228
|
+
<div className={siteBottomSheetContainerClass()} data-wide={panel ? 'side-sheet' : undefined}>
|
|
3229
|
+
{children}
|
|
3230
|
+
</div>
|
|
3222
3231
|
</dialog>
|
|
3223
3232
|
);
|
|
3224
3233
|
}
|
|
3225
3234
|
|
|
3226
3235
|
/** A web page in a frame, in a full BottomSheet (the preview of a page): `html` is the whole page, drawn as
|
|
3227
3236
|
* wide as `width` (one of Material 3's window sizes) and made smaller to fit, scrolled in the frame. Nothing
|
|
3228
|
-
* in it runs (no scripts), and its links lead nowhere.
|
|
3229
|
-
|
|
3237
|
+
* in it runs (no scripts), and its links lead nowhere. With `part` (a selector: the header) only that part of the page is
|
|
3238
|
+
* shown, as high as it is (measured when the page is in the frame), in the frame's own place: Appearance › Header. */
|
|
3239
|
+
export function PageFrame({ html, width, title, part }: { html: string; width: number; title: string; part?: string }) {
|
|
3230
3240
|
const box = useRef<HTMLDivElement>(null);
|
|
3231
3241
|
const [size, setSize] = useState({ width: 0, height: 0 });
|
|
3242
|
+
// Where the part is in the page (px of the page), once it is in the frame.
|
|
3243
|
+
const [cut, setCut] = useState<{ top: number; height: number } | null>(null);
|
|
3232
3244
|
useEffect(() => {
|
|
3233
3245
|
const el = box.current;
|
|
3234
3246
|
if (!el) return;
|
|
@@ -3237,15 +3249,30 @@ export function PageFrame({ html, width, title }: { html: string; width: number;
|
|
|
3237
3249
|
return () => watch.disconnect();
|
|
3238
3250
|
}, []);
|
|
3239
3251
|
const scale = size.width ? Math.min(1, size.width / width) : 1;
|
|
3252
|
+
const measure = (frame: HTMLIFrameElement) => {
|
|
3253
|
+
const doc = frame.contentDocument;
|
|
3254
|
+
const el = part && doc?.querySelector(part);
|
|
3255
|
+
if (!doc || !el) return;
|
|
3256
|
+
// Only the part is shown: the page does not scroll in its frame.
|
|
3257
|
+
doc.documentElement.style.overflow = 'hidden';
|
|
3258
|
+
const r = el.getBoundingClientRect();
|
|
3259
|
+
setCut({ top: r.top, height: r.height });
|
|
3260
|
+
};
|
|
3261
|
+
const height = part ? (cut ? cut.top + cut.height : width) : size.height / scale;
|
|
3240
3262
|
return (
|
|
3241
|
-
<div
|
|
3263
|
+
<div
|
|
3264
|
+
ref={box}
|
|
3265
|
+
className="relative min-h-0 flex-1 overflow-hidden border-t border-line bg-line/40"
|
|
3266
|
+
style={part ? { height: (cut?.height ?? 0) * scale } : undefined}
|
|
3267
|
+
>
|
|
3242
3268
|
{size.width > 0 && (
|
|
3243
3269
|
<iframe
|
|
3244
3270
|
title={title}
|
|
3245
3271
|
srcDoc={html}
|
|
3246
3272
|
sandbox="allow-same-origin"
|
|
3247
3273
|
className="absolute top-0 left-1/2 origin-top border-0 bg-white"
|
|
3248
|
-
style={{ width, height:
|
|
3274
|
+
style={{ width, height, top: -(cut?.top ?? 0) * scale, transform: `translateX(-50%) scale(${scale})` }}
|
|
3275
|
+
onLoad={part ? (e) => measure(e.currentTarget) : undefined}
|
|
3249
3276
|
/>
|
|
3250
3277
|
)}
|
|
3251
3278
|
</div>
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Several single data files edited on one screen (Appearance › Header: the two menus and header.json): each one's values
|
|
2
|
+
// in the form and as they were saved, a change to them, whether any is changed, the field that keeps one from being saved,
|
|
3
|
+
// and "Gem ændringer", which saves each changed file in its own commit, as SideColumn.tsx saves its file. Exposes
|
|
4
|
+
// useDataFiles. Uses dataFileValues.ts, check.ts (problemAt), fields.tsx (useWrongField) and Env (App.tsx).
|
|
5
|
+
import { useMemo, useState } from 'react';
|
|
6
|
+
import type { DataFile, FilesCollection } from './schema';
|
|
7
|
+
import { ConflictError, type RepoFile } from './github';
|
|
8
|
+
import { problemAt } from './check';
|
|
9
|
+
import { useWrongField, type Wrong } from './fields';
|
|
10
|
+
import { dataFileIn, dataOf, fieldsOf, valuesOf } from './dataFileValues';
|
|
11
|
+
import { asWritten } from './site';
|
|
12
|
+
import { changesText, lower, savedText } from './deploy';
|
|
13
|
+
import type { Env } from './App';
|
|
14
|
+
import { siteT, t } from './i18n';
|
|
15
|
+
|
|
16
|
+
/** A file on the screen: its collection and the file. */
|
|
17
|
+
export type DataFilePart = { collection: FilesCollection; dataFile: DataFile };
|
|
18
|
+
|
|
19
|
+
type Values = Record<string, unknown>;
|
|
20
|
+
|
|
21
|
+
/** `onWrong`: a file's field keeps it from being saved (its place in `parts`, the field's path), before it is marked: so
|
|
22
|
+
* the screen can open what the field is in. */
|
|
23
|
+
export function useDataFiles(env: Env, parts: DataFilePart[], onWrong?: (i: number, path: string) => void) {
|
|
24
|
+
const { notify } = env;
|
|
25
|
+
// The files as last saved (or loaded); an optional one the site has not got yet is empty (dataFileIn).
|
|
26
|
+
const [bases, setBases] = useState<RepoFile[]>(() =>
|
|
27
|
+
parts.map((p) => dataFileIn(env.files, p.dataFile) ?? { path: p.dataFile.file, oid: '', text: '{}\n' }),
|
|
28
|
+
);
|
|
29
|
+
const read = (i: number, text: string) => valuesOf(text, fieldsOf(parts[i].dataFile), parts[i].dataFile, parts[i].collection, env.files);
|
|
30
|
+
const initial = useMemo(() => bases.map((b, i) => read(i, b.text)), [bases]);
|
|
31
|
+
const [values, setValues] = useState<Values[]>(initial);
|
|
32
|
+
const [saving, setSaving] = useState(false);
|
|
33
|
+
// The field that keeps a file from being saved, marked in that file's fields only (the menus have the same paths).
|
|
34
|
+
const wrongField = useWrongField((text) => notify({ text, error: true }));
|
|
35
|
+
const [wrongIn, setWrongIn] = useState(-1);
|
|
36
|
+
const changed = values.flatMap((v, i) => (JSON.stringify(v) !== JSON.stringify(initial[i]) ? [i] : []));
|
|
37
|
+
|
|
38
|
+
async function save() {
|
|
39
|
+
// Every changed file is right before any is saved.
|
|
40
|
+
for (const i of changed) {
|
|
41
|
+
const problem = problemAt(fieldsOf(parts[i].dataFile), values[i]);
|
|
42
|
+
if (problem) {
|
|
43
|
+
setWrongIn(i);
|
|
44
|
+
onWrong?.(i, problem.path);
|
|
45
|
+
wrongField.stop(problem);
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const texts = changed
|
|
50
|
+
.map((i) => ({ i, text: `${JSON.stringify(dataOf(fieldsOf(parts[i].dataFile), values[i], parts[i].dataFile), null, 2)}\n` }))
|
|
51
|
+
.filter(({ i, text }) => text !== bases[i].text);
|
|
52
|
+
if (!texts.length) {
|
|
53
|
+
notify({ text: t.forms.nothingToSave });
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
setSaving(true);
|
|
57
|
+
notify({ text: t.common.saving });
|
|
58
|
+
const done: string[] = [];
|
|
59
|
+
try {
|
|
60
|
+
for (const { i, text } of texts) {
|
|
61
|
+
const { dataFile } = parts[i];
|
|
62
|
+
const path = bases[i].path;
|
|
63
|
+
const change = t.app.changes.edited(lower(dataFile.label));
|
|
64
|
+
const message = siteT.forms.commit.edit(asWritten(dataFile).label.toLowerCase());
|
|
65
|
+
const oids = await env.commit(message, [{ path, content: text, oid: bases[i].oid || null }], change);
|
|
66
|
+
const saved = { path, oid: oids[path], text };
|
|
67
|
+
setBases((all) => all.map((b, j) => (j === i ? saved : b)));
|
|
68
|
+
setValues((all) => all.map((v, j) => (j === i ? read(i, text) : v)));
|
|
69
|
+
env.onSaved(saved);
|
|
70
|
+
done.push(change);
|
|
71
|
+
}
|
|
72
|
+
notify({ text: savedText(changesText(done)), kind: 'saved' });
|
|
73
|
+
return true;
|
|
74
|
+
} catch (e) {
|
|
75
|
+
notify({ text: e instanceof ConflictError ? e.message : t.common.notSaved((e as Error).message), error: true, kind: 'failed' });
|
|
76
|
+
return false;
|
|
77
|
+
} finally {
|
|
78
|
+
setSaving(false);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
/** Each file's values in the form, and as they were saved (in the same form, for what the preview changes). */
|
|
84
|
+
values,
|
|
85
|
+
initial,
|
|
86
|
+
/** Sets one file's values (by its place in `parts`). */
|
|
87
|
+
set: (i: number, v: Values) => setValues((all) => all.map((x, j) => (j === i ? v : x))),
|
|
88
|
+
dirty: changed.length > 0,
|
|
89
|
+
saving,
|
|
90
|
+
save,
|
|
91
|
+
/** The field marked in a file's fields (WrongField), or null. */
|
|
92
|
+
wrong: (i: number): Wrong | null => (wrongIn === i ? wrongField.field : null),
|
|
93
|
+
};
|
|
94
|
+
}
|
package/starter/package.json
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@material-symbols/svg-400": "0.48.2",
|
|
33
33
|
"@material/material-color-utilities": "^0.3.0",
|
|
34
34
|
"@milkdown/kit": "^7.22.3",
|
|
35
|
-
"@morphemecms/cms": "0.
|
|
35
|
+
"@morphemecms/cms": "0.9.1",
|
|
36
36
|
"@phosphor-icons/core": "^2.1.1",
|
|
37
37
|
"@phosphor-icons/react": "^2.1.10",
|
|
38
38
|
"@tailwindcss/typography": "^0.5.20",
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
---
|
|
2
2
|
// The footer in Material: a surface container with extra-large corners at the top, the business as a headline, how to
|
|
3
|
-
// reach it as a list with leading icons, the practical links (footer.json,
|
|
3
|
+
// reach it as a list with leading icons, the practical links (footer.json, Appearance › Footer in the editor) or
|
|
4
4
|
// what a page puts in the slot `footer-column` instead (a blog post's related posts), and at the bottom the cookie
|
|
5
|
-
// settings and light or dark as text buttons.
|
|
5
|
+
// settings and light or dark as text buttons. data-editor marks the footer and the parts its form changes (the editor's
|
|
6
|
+
// preview of Appearance › Footer, src/footerPreview.mjs).
|
|
6
7
|
import Icon from '@theme/components/Icon.astro';
|
|
7
8
|
import Container from '@theme/components/Container.astro';
|
|
8
9
|
import LogoMark from '@theme/components/LogoMark.astro';
|
|
@@ -20,15 +21,19 @@ const contactLinks = [
|
|
|
20
21
|
];
|
|
21
22
|
---
|
|
22
23
|
|
|
23
|
-
<footer class="md-footer">
|
|
24
|
+
<footer class="md-footer" data-editor="footer">
|
|
24
25
|
<Container as="div" class="grid gap-10 py-12 expanded:grid-cols-12 medium:py-16">
|
|
25
26
|
<div class="expanded:col-span-5">
|
|
26
27
|
<LogoMark class="block h-12 w-11 bg-accent" />
|
|
27
28
|
<p class="md-footer-name">{site.name}</p>
|
|
28
|
-
<p class="md-footer-text"
|
|
29
|
+
<p class="md-footer-text" data-editor="footer-text">
|
|
30
|
+
{footer.text}
|
|
31
|
+
</p>
|
|
29
32
|
</div>
|
|
30
33
|
<div class="expanded:col-span-4">
|
|
31
|
-
<p class="md-footer-heading"
|
|
34
|
+
<p class="md-footer-heading" data-editor="footer-contact-heading">
|
|
35
|
+
{footer.contactHeading}
|
|
36
|
+
</p>
|
|
32
37
|
<ul class="md-footer-list">
|
|
33
38
|
{contactLinks.map((c) => (
|
|
34
39
|
<li>
|
|
@@ -49,8 +54,10 @@ const contactLinks = [
|
|
|
49
54
|
</div>
|
|
50
55
|
<div class="md-footer-column expanded:col-span-3">
|
|
51
56
|
<slot name="footer-column">
|
|
52
|
-
<p class="md-footer-heading"
|
|
53
|
-
|
|
57
|
+
<p class="md-footer-heading" data-editor="footer-links-heading">
|
|
58
|
+
{footer.linksHeading}
|
|
59
|
+
</p>
|
|
60
|
+
<ul class="md-footer-list" data-editor="footer-links">
|
|
54
61
|
{footer.links.map((l) => (
|
|
55
62
|
<li>
|
|
56
63
|
<a href={l.href} class="md-footer-item">
|