@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/MarkdownEditor.tsx
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// blocks (src/apps/<app>/blocks/) can be put in the text with a button; each is a card with the block as it looks
|
|
4
4
|
// on the site, which opens a menu (Ret, hide on the site, move, Fjern), with a free line kept between
|
|
5
5
|
// two cards to write in. A fixed page's sections are such a text too (SectionsField.tsx), so both look
|
|
6
|
-
// and work the same.
|
|
6
|
+
// and work the same. The last tool, "Section settings", opens the section's sheet (BlockDialog.tsx).
|
|
7
7
|
import {
|
|
8
8
|
forwardRef,
|
|
9
9
|
Fragment as ReactFragment,
|
|
@@ -43,7 +43,6 @@ import {
|
|
|
43
43
|
LinkSimple,
|
|
44
44
|
ListBullets,
|
|
45
45
|
ListNumbers,
|
|
46
|
-
Palette,
|
|
47
46
|
Plus,
|
|
48
47
|
Quotes,
|
|
49
48
|
TextAa,
|
|
@@ -62,6 +61,7 @@ import { SECTION_COLORS } from '../lib/section-marker.mjs';
|
|
|
62
61
|
import { sectionHeading, setSectionColor } from './sectionState.mjs';
|
|
63
62
|
import { sectionFrame } from './sectionFrame';
|
|
64
63
|
import { IMAGE, type BlockAsk } from './BlockDialog';
|
|
64
|
+
import SectionSettingsIcon from './SectionSettingsIcon';
|
|
65
65
|
import { askLink } from './LinkSheet';
|
|
66
66
|
import { Menu, MenuItem, Toolbar, ToolbarButton } from './ui';
|
|
67
67
|
import { shownAt } from './images';
|
|
@@ -865,12 +865,6 @@ export default forwardRef<MarkdownHandle, Props>(function MarkdownEditor(
|
|
|
865
865
|
colorsAt?.setAttribute('aria-expanded', 'true');
|
|
866
866
|
return () => colorsAt?.setAttribute('aria-expanded', 'false');
|
|
867
867
|
}, [colorsAt]);
|
|
868
|
-
// The button for the colour of a section, while its menu is open.
|
|
869
|
-
const [sectionAt, setSectionAt] = useState<HTMLElement | null>(null);
|
|
870
|
-
useEffect(() => {
|
|
871
|
-
sectionAt?.setAttribute('aria-expanded', 'true');
|
|
872
|
-
return () => sectionAt?.setAttribute('aria-expanded', 'false');
|
|
873
|
-
}, [sectionAt]);
|
|
874
868
|
// The previews of the blocks, drawn again when what they show from elsewhere changes: the lists,
|
|
875
869
|
// the testimonials, the rest of the site, the page's address or a fixed page's other fields.
|
|
876
870
|
const cards = useRef(new Set<() => void>());
|
|
@@ -1025,10 +1019,14 @@ export default forwardRef<MarkdownHandle, Props>(function MarkdownEditor(
|
|
|
1025
1019
|
editor.current?.action((ctx) => paint(ctx.get(editorViewCtx), name));
|
|
1026
1020
|
}
|
|
1027
1021
|
|
|
1028
|
-
|
|
1022
|
+
// The sheet with the settings of the section the cursor is in (its colour), then the colour set.
|
|
1023
|
+
async function sectionSettings() {
|
|
1024
|
+
const current = SECTION_COLORS.find((name) => active.includes(`section-${name}`)) ?? null;
|
|
1025
|
+
const answered = await (blocks ?? sheetProp)?.section(current);
|
|
1026
|
+
if (!answered) return;
|
|
1029
1027
|
editor.current?.action((ctx) => {
|
|
1030
1028
|
const view = ctx.get(editorViewCtx);
|
|
1031
|
-
setSectionColor(view,
|
|
1029
|
+
setSectionColor(view, answered.color);
|
|
1032
1030
|
view.focus();
|
|
1033
1031
|
});
|
|
1034
1032
|
}
|
|
@@ -1101,16 +1099,6 @@ export default forwardRef<MarkdownHandle, Props>(function MarkdownEditor(
|
|
|
1101
1099
|
{ label: t.text.bulletList, icon: ListBullets, action: () => setKind('bullet'), on: 'bullet' },
|
|
1102
1100
|
{ label: t.text.orderedList, icon: ListNumbers, action: () => setKind('ordered'), on: 'ordered' },
|
|
1103
1101
|
{ label: t.text.quote, icon: Quotes, action: () => setKind('quote'), on: 'quote' },
|
|
1104
|
-
// The colour of the section the cursor's H2 starts (not a fixed page's text, whose H2s are its sections' names; the front page has it).
|
|
1105
|
-
...(framed && active.includes('section')
|
|
1106
|
-
? [
|
|
1107
|
-
{
|
|
1108
|
-
label: t.text.sectionColor,
|
|
1109
|
-
icon: Palette,
|
|
1110
|
-
action: (e: ReactMouseEvent<HTMLButtonElement>) => setSectionAt(sectionAt ? null : e.currentTarget),
|
|
1111
|
-
},
|
|
1112
|
-
]
|
|
1113
|
-
: []),
|
|
1114
1102
|
// A picture and the blocks are put in with "+" (a sheet with them all); without blocks (a blog
|
|
1115
1103
|
// post) a picture has its own button.
|
|
1116
1104
|
...(blocks
|
|
@@ -1120,11 +1108,16 @@ export default forwardRef<MarkdownHandle, Props>(function MarkdownEditor(
|
|
|
1120
1108
|
: []),
|
|
1121
1109
|
{ label: t.text.undo, icon: ArrowUUpLeft, action: () => run(undoCommand) },
|
|
1122
1110
|
{ label: t.text.redo, icon: ArrowUUpRight, action: () => run(redoCommand) },
|
|
1111
|
+
// The settings of the section the cursor's H2 starts (not a fixed page's text, whose H2s are its sections' names; the front page has it).
|
|
1112
|
+
...(framed && active.includes('section') && (blocks ?? sheetProp)
|
|
1113
|
+
? [{ label: t.text.sectionSettings, icon: SectionSettingsIcon, action: sectionSettings }]
|
|
1114
|
+
: []),
|
|
1123
1115
|
];
|
|
1124
1116
|
|
|
1125
1117
|
// When the toolbar is too short for all its buttons, the kinds of text (H1, H2, H3, T, the bulleted and
|
|
1126
1118
|
// the numbered list and the quote) are one button: the one where the cursor is, with an arrow, and
|
|
1127
1119
|
// the others under it.
|
|
1120
|
+
const hasSettings = tools.some((item) => item.icon === SectionSettingsIcon);
|
|
1128
1121
|
const kinds = tools.filter((t) => ['h1', 'h2', 'h3', 'text', 'bullet', 'ordered', 'quote'].includes(t.on ?? ''));
|
|
1129
1122
|
const kind = kinds.find((t) => active.includes(t.on!));
|
|
1130
1123
|
const shown = kind ?? kinds.find((t) => t.on === 'text')!;
|
|
@@ -1135,18 +1128,18 @@ export default forwardRef<MarkdownHandle, Props>(function MarkdownEditor(
|
|
|
1135
1128
|
const bar = toolbar.current!;
|
|
1136
1129
|
// A button is 2.5rem, with 0.125rem between them and 0.375rem around them, and each of the lines
|
|
1137
1130
|
// between the groups 0.5rem (the classes below).
|
|
1138
|
-
const fits = () => setNarrow(bar.clientWidth < tools.length * 42 + 10 + 3 * 10);
|
|
1131
|
+
const fits = () => setNarrow(bar.clientWidth < tools.length * 42 + 10 + (3 + (hasSettings ? 1 : 0)) * 10);
|
|
1139
1132
|
const watch = new ResizeObserver(fits);
|
|
1140
1133
|
watch.observe(bar);
|
|
1141
1134
|
return () => watch.disconnect();
|
|
1142
|
-
}, [tools.length]);
|
|
1135
|
+
}, [tools.length, hasSettings]);
|
|
1143
1136
|
const tool = ({ label, icon, action, on }: (typeof tools)[number]) => (
|
|
1144
1137
|
<ToolbarButton key={label} icon={icon} label={label} selected={on ? active.includes(on) : undefined} onClick={action} />
|
|
1145
1138
|
);
|
|
1146
1139
|
|
|
1147
1140
|
// The lines between the marks on the text, the kinds of text, "+" (or "Billede") and "Fortryd".
|
|
1148
1141
|
const lineBefore = (item: (typeof tools)[number]) =>
|
|
1149
|
-
item === kinds[0] || item.icon === Plus || item.icon === Image || item.icon === ArrowUUpLeft;
|
|
1142
|
+
item === kinds[0] || item.icon === Plus || item.icon === Image || item.icon === ArrowUUpLeft || item.icon === SectionSettingsIcon;
|
|
1150
1143
|
// A button of the toolbar; when it is too short, the kinds of text are one button (at the first), with a menu.
|
|
1151
1144
|
const button = (item: (typeof tools)[number]) =>
|
|
1152
1145
|
!narrow || !kinds.includes(item) ? (
|
|
@@ -1164,13 +1157,13 @@ export default forwardRef<MarkdownHandle, Props>(function MarkdownEditor(
|
|
|
1164
1157
|
|
|
1165
1158
|
return (
|
|
1166
1159
|
<div className="rounded-panel border border-line bg-surface">
|
|
1167
|
-
{/* Stays at the top while scrolling through the text, a little under the app's top bar (Screen.tsx,
|
|
1160
|
+
{/* A bar with round corners and room all round it, inside the text's box. Stays at the top while scrolling through the text, a little under the app's top bar (Screen.tsx,
|
|
1168
1161
|
4rem and its line); on a phone one row that scrolls sideways. The buttons are centred, but
|
|
1169
1162
|
start at the left edge when they do not fit (safe), so none is out of reach. */}
|
|
1170
1163
|
<Toolbar
|
|
1171
1164
|
ref={toolbar}
|
|
1172
1165
|
label={t.text.tools}
|
|
1173
|
-
className="editor-tools sticky top-[calc(
|
|
1166
|
+
className="editor-tools sticky top-[calc(5rem+1px+env(safe-area-inset-top))] z-10 m-2 justify-center-safe overflow-x-auto rounded-panel border border-line medium:flex-wrap"
|
|
1174
1167
|
>
|
|
1175
1168
|
{tools.map((tool) => (
|
|
1176
1169
|
<ReactFragment key={tool.label}>
|
|
@@ -1191,17 +1184,6 @@ export default forwardRef<MarkdownHandle, Props>(function MarkdownEditor(
|
|
|
1191
1184
|
<span className="text-ink">{t.text.noColor}</span>
|
|
1192
1185
|
</MenuItem>
|
|
1193
1186
|
</Menu>
|
|
1194
|
-
{/* The theme's three colours for a section (section-marker.mjs), and "Ingen"; the one it has is marked. */}
|
|
1195
|
-
<Menu anchor={sectionAt} label={t.text.sectionColor} onClose={() => setSectionAt(null)}>
|
|
1196
|
-
<MenuItem icon={Palette} selected={!active.some((a) => a.startsWith('section-'))} onClick={() => sectionColor(null)}>
|
|
1197
|
-
{t.text.sectionColors.none}
|
|
1198
|
-
</MenuItem>
|
|
1199
|
-
{SECTION_COLORS.map((name) => (
|
|
1200
|
-
<MenuItem key={name} icon={Palette} selected={active.includes(`section-${name}`)} onClick={() => sectionColor(name)}>
|
|
1201
|
-
{t.text.sectionColors[name as keyof typeof t.text.sectionColors]}
|
|
1202
|
-
</MenuItem>
|
|
1203
|
-
))}
|
|
1204
|
-
</Menu>
|
|
1205
1187
|
<Menu anchor={kindsAt} label={t.text.kind} onClose={() => setKindsAt(null)}>
|
|
1206
1188
|
{kinds.map(({ label, icon, action, on }) => (
|
|
1207
1189
|
<MenuItem key={label} icon={icon} selected={active.includes(on!)} onClick={action as () => void}>
|
package/src/Media.tsx
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// saved with the tick: the file moves, the pages that use it get the new address in the same commit,
|
|
10
10
|
// and the old address sends on to it (addresses.ts). "+" uploads a new file, saved at once. The same
|
|
11
11
|
// pictures (not the other files) are the gallery a picture is chosen from in the forms (useMediaPicker).
|
|
12
|
+
// The buttons that run (add, rename, delete, upload new) show the loading indicator while they do.
|
|
12
13
|
// The funnel in Filer also filters by a tag (fileTagFilter.mjs; only tags some file has).
|
|
13
14
|
// The clock in the top bar, "Slettede filer", opens the files that were deleted (Deleted.tsx).
|
|
14
15
|
import { useEffect, useMemo, useRef, useState, type ReactElement } from 'react';
|
|
@@ -395,6 +396,7 @@ export function useMediaPicker(media: RepoFile[], pictures: Uploads): [() => Pro
|
|
|
395
396
|
kind="outlined"
|
|
396
397
|
|
|
397
398
|
icon={UploadSimple}
|
|
399
|
+
busy={pictures.uploading}
|
|
398
400
|
onClick={async () => {
|
|
399
401
|
const added = await pictures.upload();
|
|
400
402
|
if (added) done(publicPath(added.path));
|
|
@@ -634,6 +636,7 @@ export default function Media({ files, env, open }: { files: RepoFile[]; env: En
|
|
|
634
636
|
icon={Check}
|
|
635
637
|
label={t.media.saveName}
|
|
636
638
|
kind="filled"
|
|
639
|
+
busy={renaming}
|
|
637
640
|
disabled={renaming || name === stemOf(src) || !slugify(name) || slugify(name) === stemOf(src)}
|
|
638
641
|
/>
|
|
639
642
|
</>
|
|
@@ -666,8 +669,8 @@ export default function Media({ files, env, open }: { files: RepoFile[]; env: En
|
|
|
666
669
|
</div>
|
|
667
670
|
<MediaTags key={src} src={src} files={files} env={env} />
|
|
668
671
|
{code && !used.has(src) && (
|
|
669
|
-
<Button kind="outlined" icon={Trash} disabled={deleting} onClick={() => remove(src)}>
|
|
670
|
-
{
|
|
672
|
+
<Button kind="outlined" icon={Trash} busy={deleting} disabled={deleting} onClick={() => remove(src)}>
|
|
673
|
+
{t.media.kinds[kindOf(src)].delete}
|
|
671
674
|
</Button>
|
|
672
675
|
)}
|
|
673
676
|
</>
|
|
@@ -686,7 +689,7 @@ export default function Media({ files, env, open }: { files: RepoFile[]; env: En
|
|
|
686
689
|
|
|
687
690
|
onClick={() => (location.hash = 'slettet/filer')}
|
|
688
691
|
/>
|
|
689
|
-
<IconButton icon={Plus} label={t.media.add} disabled={adding} onClick={add} />
|
|
692
|
+
<IconButton icon={Plus} label={t.media.add} busy={adding} disabled={adding} onClick={add} />
|
|
690
693
|
</>
|
|
691
694
|
}
|
|
692
695
|
>
|
package/src/Redirects.tsx
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// it off the list. One that has become a page or sends on since is not shown. Over each list, as over
|
|
12
12
|
// the lists under "Indhold", the search, the order (kept in this browser; by address under the first
|
|
13
13
|
// letter) and, over the redirects, the funnel that shows only those to one page or post, picked as a
|
|
14
|
-
// chip.
|
|
14
|
+
// chip. The Save and Delete buttons show the loading indicator while their save runs (Forget does not).
|
|
15
15
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
16
16
|
import { ArrowRight, ArrowsDownUp, Funnel, LinkBreak, Plus, Signpost, Trash, X } from '@phosphor-icons/react';
|
|
17
17
|
import { addressOf, escape, REDIRECTS } from './addresses';
|
|
@@ -144,14 +144,16 @@ export default function Redirects({ env, tab }: { env: Env; tab?: Tab }) {
|
|
|
144
144
|
|
|
145
145
|
const dialog = useRef<HTMLDialogElement>(null);
|
|
146
146
|
const [editing, setEditing] = useState<Editing | null>(null);
|
|
147
|
-
|
|
147
|
+
// Which store is running (null: none). Only the button that started it shows busy; all three stay disabled.
|
|
148
|
+
const [running, setRunning] = useState<'save' | 'delete' | null>(null);
|
|
149
|
+
const saving = running !== null;
|
|
148
150
|
const open = (e: Editing) => {
|
|
149
151
|
setEditing(e);
|
|
150
152
|
dialog.current?.showModal();
|
|
151
153
|
};
|
|
152
154
|
|
|
153
155
|
// Saves the redirects as they are after a change, in one commit, none through another.
|
|
154
|
-
async function store(next: AllRedirects, message: string, change: string): Promise<boolean> {
|
|
156
|
+
async function store(next: AllRedirects, message: string, change: string, kind: 'save' | 'delete'): Promise<boolean> {
|
|
155
157
|
const flat = flatten(next);
|
|
156
158
|
if (typeof flat === 'string') {
|
|
157
159
|
env.notify({ text: flat, error: true });
|
|
@@ -159,7 +161,7 @@ export default function Redirects({ env, tab }: { env: Env; tab?: Tab }) {
|
|
|
159
161
|
}
|
|
160
162
|
const changes = changesOf(flat, files!);
|
|
161
163
|
if (!changes.length) return true;
|
|
162
|
-
|
|
164
|
+
setRunning(kind);
|
|
163
165
|
env.notify({ text: t.common.saving });
|
|
164
166
|
try {
|
|
165
167
|
const oids = await env.commit(message, changes, change);
|
|
@@ -174,7 +176,7 @@ export default function Redirects({ env, tab }: { env: Env; tab?: Tab }) {
|
|
|
174
176
|
env.notify({ text: t.common.notSaved((e as Error).message), error: true, kind: 'failed' });
|
|
175
177
|
return false;
|
|
176
178
|
} finally {
|
|
177
|
-
|
|
179
|
+
setRunning(null);
|
|
178
180
|
}
|
|
179
181
|
}
|
|
180
182
|
|
|
@@ -218,6 +220,7 @@ export default function Redirects({ env, tab }: { env: Env; tab?: Tab }) {
|
|
|
218
220
|
setRedirect(all, from, to),
|
|
219
221
|
editing.isNew ? siteT.redirects.commit.add(from, to) : siteT.redirects.commit.change(from, to),
|
|
220
222
|
t.app.changes[editing.isNew ? 'added' : 'edited'](t.app.changes.redirect(from)),
|
|
223
|
+
'save',
|
|
221
224
|
);
|
|
222
225
|
if (!done) return;
|
|
223
226
|
// Sent on: no longer an address that does not exist.
|
|
@@ -234,7 +237,7 @@ export default function Redirects({ env, tab }: { env: Env; tab?: Tab }) {
|
|
|
234
237
|
const flat = flatten(all);
|
|
235
238
|
if (typeof flat === 'string') return env.notify({ text: flat, error: true });
|
|
236
239
|
const change = t.app.changes.deleted(t.app.changes.redirect(from));
|
|
237
|
-
if (await store(setRedirect(flat, from, null), siteT.redirects.commit.delete(from), change)) dialog.current?.close();
|
|
240
|
+
if (await store(setRedirect(flat, from, null), siteT.redirects.commit.delete(from), change, 'delete')) dialog.current?.close();
|
|
238
241
|
}
|
|
239
242
|
|
|
240
243
|
async function drop(path: string) {
|
|
@@ -430,8 +433,8 @@ export default function Redirects({ env, tab }: { env: Env; tab?: Tab }) {
|
|
|
430
433
|
onChange={(e) => setEditing({ ...editing, to: e.target.value })}
|
|
431
434
|
/>
|
|
432
435
|
</div>
|
|
433
|
-
<Button type="submit" disabled={saving}>
|
|
434
|
-
{
|
|
436
|
+
<Button type="submit" busy={running === 'save'} disabled={saving}>
|
|
437
|
+
{m ? t.redirects.missing.sendOn : t.common.save}
|
|
435
438
|
</Button>
|
|
436
439
|
{m && (
|
|
437
440
|
<Button kind="outlined" icon={X} disabled={saving} onClick={() => drop(m.path)}>
|
|
@@ -439,7 +442,7 @@ export default function Redirects({ env, tab }: { env: Env; tab?: Tab }) {
|
|
|
439
442
|
</Button>
|
|
440
443
|
)}
|
|
441
444
|
{!editing.isNew && (
|
|
442
|
-
<Button kind="outlined" icon={Trash} disabled={saving} onClick={() => remove(editing.from)}>
|
|
445
|
+
<Button kind="outlined" icon={Trash} busy={running === 'delete'} disabled={saving} onClick={() => remove(editing.from)}>
|
|
443
446
|
{t.redirects.deleteRedirect}
|
|
444
447
|
</Button>
|
|
445
448
|
)}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// The settings of a section in the sheet of BlockDialog.tsx: its colour, "None" and the theme's three (section-marker.mjs),
|
|
2
|
+
// the one it has marked. Exposes the default SectionSettings; uses Option (ui.tsx), SECTION_COLORS.
|
|
3
|
+
import { Option } from './ui';
|
|
4
|
+
import { SECTION_COLORS } from '../lib/section-marker.mjs';
|
|
5
|
+
import { t } from './i18n';
|
|
6
|
+
|
|
7
|
+
/** color: the section's colour, '' for none. */
|
|
8
|
+
export default function SectionSettings({ color, onChange }: { color: string; onChange: (color: string) => void }) {
|
|
9
|
+
return (
|
|
10
|
+
<div role="group" aria-label={t.text.sectionColor}>
|
|
11
|
+
<Option selected={!color} onClick={() => onChange('')}>
|
|
12
|
+
{t.text.sectionColors.none}
|
|
13
|
+
</Option>
|
|
14
|
+
{SECTION_COLORS.map((name) => (
|
|
15
|
+
<Option key={name} selected={color === name} onClick={() => onChange(name)}>
|
|
16
|
+
{t.text.sectionColors[name as keyof typeof t.text.sectionColors]}
|
|
17
|
+
</Option>
|
|
18
|
+
))}
|
|
19
|
+
</div>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// The icon of the "Section settings" tool: Material Symbols' calendar_view_day (Outlined), drawn by Svg (icon.tsx).
|
|
2
|
+
// Exposes the default SectionSettingsIcon, which takes the size and class the toolbar's buttons give an icon.
|
|
3
|
+
import type { Icon } from '@phosphor-icons/react';
|
|
4
|
+
import { Svg } from './icon';
|
|
5
|
+
|
|
6
|
+
const SectionSettingsIcon = (({ size = 20, className }: { size?: number | string; className?: string }) => (
|
|
7
|
+
<Svg name="calendar_view_day" size={Number(size)} className={className} />
|
|
8
|
+
)) as unknown as Icon;
|
|
9
|
+
|
|
10
|
+
export default SectionSettingsIcon;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// The layout of a settings screen with several parts (Appearance › Header, Appearance › Footer), as the page form's
|
|
2
|
+
// (EntryForm.tsx): `top` (the preview) over the sections, each folding in and out under its heading (FoldSection), with
|
|
3
|
+
// their "on this page" list at the window's end edge on large and wider screens (FormColumns, SectionPane, SectionList).
|
|
4
|
+
// The first is open from the start. On a phone (compact) only one is open at a time, an accordion: opening one folds the
|
|
5
|
+
// others; wider they open and fold each on its own, as a page's. Exposes useSettingsSections and SettingsSections. Uses
|
|
6
|
+
// formSections.ts and ui.tsx.
|
|
7
|
+
import type { ReactNode } from 'react';
|
|
8
|
+
import { FoldSection, FormColumns, type NavigationItem, SectionList, SectionPane, useAtLeast } from './ui';
|
|
9
|
+
import { useFormSections } from './formSections';
|
|
10
|
+
import { t } from './i18n';
|
|
11
|
+
|
|
12
|
+
/** A section of the screen: its id, its heading (its name in the list) and its fields. */
|
|
13
|
+
export type SettingsSection = NavigationItem & { content: ReactNode };
|
|
14
|
+
|
|
15
|
+
/** The sections' state, made by the screen, so a field that keeps it from being saved can open its section (`unfold`) and
|
|
16
|
+
* mark it in the list (`steer`) before it is scrolled to. */
|
|
17
|
+
export function useSettingsSections(sections: NavigationItem[]) {
|
|
18
|
+
const single = !useAtLeast('medium');
|
|
19
|
+
return useFormSections<string>(
|
|
20
|
+
sections,
|
|
21
|
+
sections.slice(0, 1).map((s) => s.id),
|
|
22
|
+
single,
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function SettingsSections({
|
|
27
|
+
title,
|
|
28
|
+
top,
|
|
29
|
+
sections,
|
|
30
|
+
state,
|
|
31
|
+
}: {
|
|
32
|
+
/** The screen's name, over the sections list. */
|
|
33
|
+
title: string;
|
|
34
|
+
top?: ReactNode;
|
|
35
|
+
sections: SettingsSection[];
|
|
36
|
+
state: ReturnType<typeof useSettingsSections>;
|
|
37
|
+
}) {
|
|
38
|
+
return (
|
|
39
|
+
<FormColumns
|
|
40
|
+
main={
|
|
41
|
+
<>
|
|
42
|
+
{top}
|
|
43
|
+
{sections.map((s) => (
|
|
44
|
+
<FoldSection key={s.id} {...state.sectionProps(s.id)}>
|
|
45
|
+
{s.content}
|
|
46
|
+
</FoldSection>
|
|
47
|
+
))}
|
|
48
|
+
</>
|
|
49
|
+
}
|
|
50
|
+
pane={
|
|
51
|
+
<SectionPane caption={t.forms.sections.title} title={title}>
|
|
52
|
+
<SectionList title={t.forms.sections.title} items={sections} value={state.section} onChange={state.pick} />
|
|
53
|
+
</SectionPane>
|
|
54
|
+
}
|
|
55
|
+
/>
|
|
56
|
+
);
|
|
57
|
+
}
|
package/src/ThemeStore.tsx
CHANGED
|
@@ -5,11 +5,13 @@
|
|
|
5
5
|
// it); and on the page of one installed from the store (ThemePage in Library.tsx) "Opdater til …" and "Afinstaller"
|
|
6
6
|
// (ThemeStoreButtons). Installing copies its folder into the site's themes (config.themes/<id>/, with its store.json),
|
|
7
7
|
// updating copies the newer version over it and uninstalling deletes it, each saved at once in its own commit
|
|
8
|
-
// (themeChanges)
|
|
9
|
-
// the site is changing to and the standard theme
|
|
8
|
+
// (themeChanges), the button pressed showing the loading indicator while it runs; the site's next build has it, and
|
|
9
|
+
// only then can it be chosen ("Brug temaet"). The theme in use, the one the site is changing to and the standard theme
|
|
10
|
+
// cannot be uninstalled.
|
|
10
11
|
import { useEffect, useState } from 'react';
|
|
11
12
|
import { Check, Smiley } from '@phosphor-icons/react';
|
|
12
13
|
import Screen from './Screen';
|
|
14
|
+
import { busyFor } from './busyAction.mjs';
|
|
13
15
|
import { Button, EmptyNote, Group, GroupTitle, ImageCarousel, SupportingText, ListItem } from './ui';
|
|
14
16
|
import { ConflictError, type RepoFile } from './github';
|
|
15
17
|
import type { Env } from './App';
|
|
@@ -106,19 +108,24 @@ const themeOfPack = (files: RepoFile[]) => iconPacks.find((x) => x.id === chosen
|
|
|
106
108
|
const canUninstall = (id: string, files: RepoFile[]) =>
|
|
107
109
|
id !== STANDARD_THEME && id !== theme.id && id !== chosenTheme(files) && id !== themeOfPack(files);
|
|
108
110
|
|
|
111
|
+
type ThemeAction = 'install' | 'update' | 'uninstall';
|
|
112
|
+
|
|
109
113
|
/** Installing, updating and uninstalling a theme from the store, each saved at once in its own commit (themeChanges).
|
|
110
114
|
* Each says true when it was saved. */
|
|
111
115
|
function useThemeActions(env: Env) {
|
|
112
|
-
|
|
116
|
+
// Which action runs, on which theme (busyAction.mjs shows only the pressed button).
|
|
117
|
+
const [running, setRunning] = useState<{ id: string; action: ThemeAction; asking: boolean } | null>(null);
|
|
118
|
+
const saving = !!running;
|
|
113
119
|
const recordOf = (x: ShownTheme): StoreRecord => ({ version: x.version, ref: x.version, files: x.files });
|
|
114
120
|
|
|
115
121
|
async function change(
|
|
116
122
|
id: string,
|
|
123
|
+
action: ThemeAction,
|
|
117
124
|
text: { busy: string; done: string; commit: string; change: string },
|
|
118
125
|
next: () => Promise<Parameters<typeof themeChanges>[2]>,
|
|
119
126
|
go: (current: RepoFile[]) => Promise<boolean> = async () => true,
|
|
120
127
|
): Promise<boolean> {
|
|
121
|
-
|
|
128
|
+
setRunning({ id, action, asking: false });
|
|
122
129
|
env.notify({ text: text.busy });
|
|
123
130
|
try {
|
|
124
131
|
const [current, wanted] = await Promise.all([env.folder(themeFolder(id)), next()]);
|
|
@@ -126,6 +133,9 @@ function useThemeActions(env: Env) {
|
|
|
126
133
|
env.notify(null);
|
|
127
134
|
return false;
|
|
128
135
|
}
|
|
136
|
+
// `go` cleared the message (and its dialog stopped the button being busy): saving goes on.
|
|
137
|
+
setRunning({ id, action, asking: false });
|
|
138
|
+
env.notify({ text: text.busy });
|
|
129
139
|
await env.commit(text.commit, themeChanges(id, current, wanted), text.change);
|
|
130
140
|
env.notify({ text: text.done, kind: 'saved' });
|
|
131
141
|
return true;
|
|
@@ -133,15 +143,17 @@ function useThemeActions(env: Env) {
|
|
|
133
143
|
env.notify({ text: e instanceof ConflictError ? e.message : t.common.notSaved((e as Error).message), error: true, kind: 'failed' });
|
|
134
144
|
return false;
|
|
135
145
|
} finally {
|
|
136
|
-
|
|
146
|
+
setRunning(null);
|
|
137
147
|
}
|
|
138
148
|
}
|
|
139
149
|
|
|
140
150
|
return {
|
|
141
151
|
saving,
|
|
152
|
+
busy: (id: string, action: ThemeAction) => busyFor(running, id, action),
|
|
142
153
|
async install(x: ShownTheme) {
|
|
143
154
|
const done = await change(
|
|
144
155
|
x.id,
|
|
156
|
+
'install',
|
|
145
157
|
{
|
|
146
158
|
busy: t.apps.installing,
|
|
147
159
|
done: t.library.themeInstalled(x.name),
|
|
@@ -156,6 +168,7 @@ function useThemeActions(env: Env) {
|
|
|
156
168
|
async update(x: ShownTheme, record: StoreRecord) {
|
|
157
169
|
const done = await change(
|
|
158
170
|
x.id,
|
|
171
|
+
'update',
|
|
159
172
|
{
|
|
160
173
|
busy: t.apps.updating,
|
|
161
174
|
done: t.library.themeUpdated(x.name, x.version),
|
|
@@ -171,6 +184,7 @@ function useThemeActions(env: Env) {
|
|
|
171
184
|
env.notify({ text: t.library.themeDropsIconPack(x.name, pack.name), error: true });
|
|
172
185
|
return false;
|
|
173
186
|
}
|
|
187
|
+
setRunning({ id: x.id, action: 'update', asking: true });
|
|
174
188
|
return askUpdate(
|
|
175
189
|
x.name,
|
|
176
190
|
record.version,
|
|
@@ -187,6 +201,7 @@ function useThemeActions(env: Env) {
|
|
|
187
201
|
if (!(await ask(t.library.askUninstallTheme(name), t.apps.uninstall))) return false;
|
|
188
202
|
const done = await change(
|
|
189
203
|
id,
|
|
204
|
+
'uninstall',
|
|
190
205
|
{
|
|
191
206
|
busy: t.apps.uninstalling,
|
|
192
207
|
done: t.library.themeUninstalled(name),
|
|
@@ -277,7 +292,11 @@ export function StoreThemePage({ id, env }: { id: string; env: Env }) {
|
|
|
277
292
|
</div>
|
|
278
293
|
{!pending && (
|
|
279
294
|
<div className="mb-8">
|
|
280
|
-
<Button
|
|
295
|
+
<Button
|
|
296
|
+
disabled={actions.saving}
|
|
297
|
+
busy={actions.busy(of.id, 'install')}
|
|
298
|
+
onClick={async () => (await actions.install(of)) && redraw((n) => n + 1)}
|
|
299
|
+
>
|
|
281
300
|
{t.apps.install}
|
|
282
301
|
</Button>
|
|
283
302
|
</div>
|
|
@@ -314,8 +333,8 @@ export function StoreThemePage({ id, env }: { id: string; env: Env }) {
|
|
|
314
333
|
<div>
|
|
315
334
|
<Button
|
|
316
335
|
kind="outlined"
|
|
317
|
-
|
|
318
336
|
disabled={actions.saving}
|
|
337
|
+
busy={actions.busy(of.id, 'uninstall')}
|
|
319
338
|
onClick={async () => (await actions.uninstall(of.id, of.name)) && redraw((n) => n + 1)}
|
|
320
339
|
>
|
|
321
340
|
{t.apps.uninstall}
|
|
@@ -344,7 +363,7 @@ export function ThemeStoreButtons({ of, env, files, top }: { of: ThemeInfo; env:
|
|
|
344
363
|
if (top)
|
|
345
364
|
return update ? (
|
|
346
365
|
<div className="mb-8">
|
|
347
|
-
<Button disabled={actions.saving} onClick={() => actions.update(update, of.store!)}>
|
|
366
|
+
<Button disabled={actions.saving} busy={actions.busy(of.id, 'update')} onClick={() => actions.update(update, of.store!)}>
|
|
348
367
|
{t.apps.update(update.version)}
|
|
349
368
|
</Button>
|
|
350
369
|
</div>
|
|
@@ -354,8 +373,8 @@ export function ThemeStoreButtons({ of, env, files, top }: { of: ThemeInfo; env:
|
|
|
354
373
|
<div>
|
|
355
374
|
<Button
|
|
356
375
|
kind="outlined"
|
|
357
|
-
|
|
358
376
|
disabled={actions.saving || !free}
|
|
377
|
+
busy={actions.busy(of.id, 'uninstall')}
|
|
359
378
|
onClick={async () => (await actions.uninstall(of.id, of.name)) && redraw((n) => n + 1)}
|
|
360
379
|
>
|
|
361
380
|
{t.apps.uninstall}
|
package/src/Versions.tsx
CHANGED
|
@@ -6,19 +6,7 @@
|
|
|
6
6
|
// version, in a new commit, so nothing is lost and every version can always be found here again.
|
|
7
7
|
import { Component, Fragment, useEffect, useRef, useState, type ReactNode } from 'react';
|
|
8
8
|
import { ClockCounterClockwise } from '@phosphor-icons/react';
|
|
9
|
-
import {
|
|
10
|
-
Button,
|
|
11
|
-
EmptyNote,
|
|
12
|
-
IconButton,
|
|
13
|
-
listClass,
|
|
14
|
-
Notice,
|
|
15
|
-
LoadingIndicator,
|
|
16
|
-
BottomSheet,
|
|
17
|
-
SheetTitle,
|
|
18
|
-
SheetBody,
|
|
19
|
-
ProblemNote,
|
|
20
|
-
ListItem,
|
|
21
|
-
} from './ui';
|
|
9
|
+
import { Button, EmptyNote, IconButton, listClass, Notice, BottomSheet, SheetTitle, SheetBody, ProblemNote, ListItem } from './ui';
|
|
22
10
|
import { mayLeave } from './FormFrame';
|
|
23
11
|
import { when } from './when';
|
|
24
12
|
import type { Env } from './App';
|
|
@@ -138,8 +126,8 @@ function VersionRows({ list, onPick }: { list: ReturnType<typeof useVersionList>
|
|
|
138
126
|
</ul>
|
|
139
127
|
)}
|
|
140
128
|
{more && (
|
|
141
|
-
<Button kind="outlined"
|
|
142
|
-
{
|
|
129
|
+
<Button kind="outlined" busy={loading} onClick={() => load(more)}>
|
|
130
|
+
{t.history.more}
|
|
143
131
|
</Button>
|
|
144
132
|
)}
|
|
145
133
|
</>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Which store action runs, for the buttons that show it: `running` is { id, action, asking } or null; `asking` is true
|
|
2
|
+
// while a dialog waits for the user. Exposes busyFor. No dependencies, so node can import it.
|
|
3
|
+
|
|
4
|
+
/** Whether the button of `action` ("install", "update" or "uninstall") on `id` shows the loading indicator: only the
|
|
5
|
+
* one pressed, and not while a dialog waits for the user. */
|
|
6
|
+
export function busyFor(running, id, action) {
|
|
7
|
+
return !!running && !running.asking && running.id === id && running.action === action;
|
|
8
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Tests for src/busyAction.mjs: only the pressed button is busy, and not while a dialog waits. Run: node --test
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import { busyFor } from './busyAction.mjs';
|
|
5
|
+
|
|
6
|
+
test('busyFor is true for the running action on its id only', () => {
|
|
7
|
+
const running = { id: 'a', action: 'install', asking: false };
|
|
8
|
+
assert.equal(busyFor(running, 'a', 'install'), true);
|
|
9
|
+
assert.equal(busyFor(running, 'a', 'update'), false);
|
|
10
|
+
assert.equal(busyFor(running, 'b', 'install'), false);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('busyFor is false when nothing runs or a dialog waits', () => {
|
|
14
|
+
assert.equal(busyFor(null, 'a', 'install'), false);
|
|
15
|
+
assert.equal(busyFor({ id: 'a', action: 'update', asking: true }, 'a', 'update'), false);
|
|
16
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// A JSON file in a form: its fields, its values in the form (from its text) and its data again (to save), the same for one
|
|
2
|
+
// file on its own screen (DataForm.tsx) and several on one (useDataFiles.ts, Appearance › Header). Exposes fieldsOf,
|
|
3
|
+
// listOnly, valuesOf, dataOf and dataFileIn. Uses check.ts (withDefaults, clean) and schema.ts.
|
|
4
|
+
import { entryData, type Collection, type DataFile, type Field } from './schema';
|
|
5
|
+
import { clean, withDefaults } from './check';
|
|
6
|
+
import type { RepoFile } from './github';
|
|
7
|
+
|
|
8
|
+
/** A single file's fields: its own ("Aktiveret") and, when it is a list (the menus), the list's field after them. */
|
|
9
|
+
export const fieldsOf = (dataFile: DataFile): Field[] => (dataFile.root ? [...dataFile.fields, dataFile.root] : dataFile.fields);
|
|
10
|
+
|
|
11
|
+
/** A file that is only a list, without fields of its own beside it (a menu with "Aktiveret" is not). */
|
|
12
|
+
export const listOnly = (dataFile?: DataFile) => !!dataFile?.root && !dataFile.fields.length;
|
|
13
|
+
|
|
14
|
+
/** A file's values in the form: its data (with the defaults of fields it has none for; an entry of a list as the list has
|
|
15
|
+
* it now, entryData), or a list under the field's name. */
|
|
16
|
+
export function valuesOf(text: string, fields: Field[], dataFile: DataFile | undefined, collection: Collection, files: RepoFile[]) {
|
|
17
|
+
if (listOnly(dataFile)) return { [dataFile!.root!.name]: JSON.parse(text) } as Record<string, unknown>;
|
|
18
|
+
return withDefaults(fields, collection.kind === 'folder' && !dataFile ? entryData(collection, text, files) : JSON.parse(text));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The values as they are saved (clean): a file that is only a list as the list itself. */
|
|
22
|
+
export function dataOf(fields: Field[], values: Record<string, unknown>, dataFile?: DataFile): unknown {
|
|
23
|
+
const data = clean(fields, values);
|
|
24
|
+
return listOnly(dataFile) ? data[dataFile!.root!.name] : data;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** A single file as the site has it; an optional one (the header's) that the site has not got yet as an empty one, which
|
|
28
|
+
* the first save makes. */
|
|
29
|
+
export const dataFileIn = (files: RepoFile[], dataFile: DataFile): RepoFile | undefined =>
|
|
30
|
+
files.find((f) => f.path === dataFile.file) ?? (dataFile.optional ? { path: dataFile.file, oid: '', text: '{}\n' } : undefined);
|