@morphemecms/cms 0.13.0-next-20261106213045 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/defaults/collections.ts +39 -52
  3. package/defaults/company.ts +5 -1
  4. package/defaults/editor.ts +27 -14
  5. package/defaults/i18n/da-DK/collections.ts +11 -8
  6. package/defaults/i18n/da-DK/editor.ts +1 -1
  7. package/defaults/i18n/da-DK/rules.ts +1 -0
  8. package/defaults/rules.ts +13 -1
  9. package/lib/focusTrap.d.mts +20 -0
  10. package/lib/focusTrap.mjs +28 -0
  11. package/lib/focusTrap.test.mjs +41 -0
  12. package/lib/folderChanges.mjs +1 -1
  13. package/lib/licenses.d.mts +1 -1
  14. package/lib/licenses.imports.test.mjs +33 -0
  15. package/lib/licenses.mjs +7 -4
  16. package/lib/menu.mjs +9 -4
  17. package/lib/menu.test.mjs +45 -18
  18. package/lib/storeEntries.d.mts +0 -1
  19. package/lib/storeEntries.mjs +2 -4
  20. package/lib/storeEntries.test.mjs +1 -6
  21. package/package.json +1 -1
  22. package/scripts/starter-gitattributes.test.mjs +22 -0
  23. package/site/header.d.mts +2 -1
  24. package/site/header.mjs +7 -4
  25. package/site/header.test.mjs +8 -2
  26. package/site/social.d.mts +65 -8
  27. package/site/social.mjs +132 -14
  28. package/site/social.test.mjs +109 -5
  29. package/src/App.tsx +29 -7
  30. package/src/AppList.tsx +46 -200
  31. package/src/BrandForm.tsx +2 -2
  32. package/src/CompanyForm.tsx +7 -2
  33. package/src/HeaderSettings.tsx +4 -4
  34. package/src/Library.tsx +20 -13
  35. package/src/LinkList.tsx +165 -0
  36. package/src/MainMenu.tsx +24 -4
  37. package/src/MoveButtons.tsx +15 -0
  38. package/src/StoreSearchRow.tsx +67 -0
  39. package/src/StoreStatus.tsx +67 -0
  40. package/src/ThemeStore.tsx +16 -37
  41. package/src/ThemeStoreScreen.tsx +62 -0
  42. package/src/checkSite.ts +3 -2
  43. package/src/cmsNotice.d.mts +7 -0
  44. package/src/cmsNotice.mjs +11 -0
  45. package/src/cmsNotice.test.mjs +50 -0
  46. package/src/fields.tsx +38 -13
  47. package/src/headerPreview.d.mts +14 -4
  48. package/src/headerPreview.mjs +10 -8
  49. package/src/headerPreview.test.mjs +12 -4
  50. package/src/headerTheme.tsx +19 -26
  51. package/src/i18n/da-DK/common.ts +1 -0
  52. package/src/i18n/da-DK/forms.ts +12 -0
  53. package/src/i18n/en-US/common.ts +2 -0
  54. package/src/i18n/en-US/forms.ts +15 -0
  55. package/src/levelStep.d.mts +10 -0
  56. package/src/levelStep.mjs +66 -0
  57. package/src/levelStep.test.mjs +119 -0
  58. package/src/linkAddress.d.mts +21 -0
  59. package/src/linkAddress.mjs +50 -0
  60. package/src/linkAddress.test.mjs +57 -0
  61. package/src/moveItem.d.mts +9 -0
  62. package/src/moveItem.mjs +17 -0
  63. package/src/moveItem.test.mjs +16 -0
  64. package/src/movedRoutes.mjs +8 -3
  65. package/src/movedRoutes.test.mjs +11 -2
  66. package/src/schema.ts +11 -0
  67. package/src/site.ts +1 -0
  68. package/src/store.ts +5 -33
  69. package/src/storeSort.tsx +39 -0
  70. package/src/themeFilter.d.mts +17 -0
  71. package/src/themeFilter.mjs +16 -0
  72. package/src/themeFilter.test.mjs +24 -0
  73. package/src/themeUi.ts +1 -0
  74. package/src/ui.tsx +2 -1
  75. package/starter/.gitattributes +2 -0
  76. package/starter/package.json +1 -1
  77. package/starter/src/data/social.json +1 -7
  78. package/theme/blocks/buttons/Buttons.tsx +12 -2
  79. package/theme/components/Header.astro +21 -31
  80. package/theme/components/HeaderCta.tsx +21 -0
  81. package/theme/components/HeaderPhoneButton.tsx +28 -0
  82. package/theme/components/MobileMenu.tsx +56 -43
  83. package/theme/components/headerParts.ts +5 -4
  84. package/theme/styles/global.css +22 -5
  85. package/theme/styles/ui.css +110 -7
  86. package/theme/ui/NavigationDrawer.tsx +6 -1
  87. package/src/legacyMove.test.mjs +0 -137
  88. package/src/legacyMove.ts +0 -131
@@ -1,5 +1,5 @@
1
- // The themes in the app store (store.ts): their tab in "Appstore" (#settings/appstore/themes, StoreThemes), all themes, those
2
- // in the store and those installed, with the same search, order and status filter as the apps; the page of one that
1
+ // The themes in the app store (store.ts): "Theme store" (#appearance/theme-store, ThemeStoreScreen.tsx, first under Appearance), all themes, those
2
+ // in the store and those installed, with the same search, order and status filter as the apps ("Appstore" only has apps); the page of one that
3
3
  // is not installed (#appearance/themes/<id>, StoreThemePage), drawn from the catalog as a theme's page (its picture,
4
4
  // name, version, who made it, "Installer", its pictures of a site in it, what it is and gives the site, and who made
5
5
  // it); and on the page of one installed from the store (ThemePage in Library.tsx) "Opdater til …" and "Afinstaller"
@@ -21,8 +21,6 @@ import { iconPacks, packOfTheme } from './iconPacks';
21
21
  import { theme, themes, type ThemeInfo } from './themes';
22
22
  import {
23
23
  changedFiles,
24
- legacyOf,
25
- moveChanges,
26
24
  newer,
27
25
  notesSince,
28
26
  STANDARD_THEME,
@@ -65,12 +63,8 @@ export function useThemeCatalog(env: Env): ShownTheme[] | null | 'failed' {
65
63
  // version updated to, until the site's build has it (and the editor reloads with it, deploy.ts keepCurrent).
66
64
  const changed = new Map<string, string>();
67
65
 
68
- const themeHere = (id: string) => (changed.has(id) ? changed.get(id) !== 'uninstalled' : themes.some((x) => x.id === id));
69
-
70
- /** Whether a theme is in the site now: installed and not uninstalled since, or installed since; or, with its `legacy` id,
71
- * a copy under that old id from the store (legacyOf). */
72
- export const themeInstalled = (id: string, legacy?: string) =>
73
- themeHere(id) || (!!legacy && legacyOf({ legacy }, themes) !== null && themeHere(legacy));
66
+ /** Whether a theme is in the site now: installed and not uninstalled since, or installed since. */
67
+ export const themeInstalled = (id: string) => (changed.has(id) ? changed.get(id) !== 'uninstalled' : themes.some((x) => x.id === id));
74
68
 
75
69
  /** A theme installed from the store that the site's build does not have yet. */
76
70
  export const themePending = (id: string) => changed.get(id) === 'installed' && !themes.some((x) => x.id === id);
@@ -80,7 +74,7 @@ const versionOf = (x: ThemeInfo) => (changed.has(x.id) && changed.get(x.id) !==
80
74
 
81
75
  /** The newer version of a theme from the store, when the store has one. */
82
76
  export const themeUpdateOf = (x: ThemeInfo, catalog: ShownTheme[] | null | 'failed') => {
83
- const found = x.store && Array.isArray(catalog) ? catalog.find((c) => c.id === x.id || c.legacy === x.id) : undefined;
77
+ const found = x.store && Array.isArray(catalog) ? catalog.find((c) => c.id === x.id) : undefined;
84
78
  return found && newer(found.version, versionOf(x)) ? found : undefined;
85
79
  };
86
80
 
@@ -130,13 +124,11 @@ function useThemeActions(env: Env) {
130
124
  text: { busy: string; done: string; commit: string; change: string },
131
125
  next: () => Promise<Parameters<typeof themeChanges>[2]>,
132
126
  go: (current: RepoFile[]) => Promise<boolean> = async () => true,
133
- // The id the theme is installed under, when it is a legacy copy that moves to `id` (moveChanges).
134
- legacy: string | null = null,
135
127
  ): Promise<boolean> {
136
128
  setRunning({ id, action, asking: false });
137
129
  env.notify({ text: text.busy });
138
130
  try {
139
- const [current, wanted] = await Promise.all([env.folder(themeFolder(legacy ?? id)), next()]);
131
+ const [current, wanted] = await Promise.all([env.folder(themeFolder(id)), next()]);
140
132
  if (!(await go(current))) {
141
133
  env.notify(null);
142
134
  return false;
@@ -144,11 +136,7 @@ function useThemeActions(env: Env) {
144
136
  // `go` cleared the message (and its dialog stopped the button being busy): saving goes on.
145
137
  setRunning({ id, action, asking: false });
146
138
  env.notify({ text: text.busy });
147
- await env.commit(
148
- text.commit,
149
- legacy && wanted ? moveChanges({ id }, legacy, wanted, current, env.files) : themeChanges(id, current, wanted),
150
- text.change,
151
- );
139
+ await env.commit(text.commit, themeChanges(id, current, wanted), text.change);
152
140
  env.notify({ text: text.done, kind: 'saved' });
153
141
  return true;
154
142
  } catch (e) {
@@ -177,7 +165,7 @@ function useThemeActions(env: Env) {
177
165
  if (done) changed.set(x.id, 'installed');
178
166
  return done;
179
167
  },
180
- async update(x: ShownTheme, record: StoreRecord, legacy: string | null = null) {
168
+ async update(x: ShownTheme, record: StoreRecord) {
181
169
  const done = await change(
182
170
  x.id,
183
171
  'update',
@@ -202,15 +190,11 @@ function useThemeActions(env: Env) {
202
190
  record.version,
203
191
  x.version,
204
192
  notesSince(x.releaseNotes, record.version, x.version),
205
- changedFiles(x.id, record, current, themeFolder(legacy ?? x.id)),
193
+ changedFiles(x.id, record, current, themeFolder(x.id)),
206
194
  );
207
195
  },
208
- legacy,
209
196
  );
210
- if (done && legacy) {
211
- changed.set(x.id, 'installed');
212
- changed.set(legacy, 'uninstalled');
213
- } else if (done) changed.set(x.id, x.version);
197
+ if (done) changed.set(x.id, x.version);
214
198
  return done;
215
199
  },
216
200
  async uninstall(id: string, name: string) {
@@ -237,12 +221,11 @@ function useThemeActions(env: Env) {
237
221
  export function allThemes(catalog: ShownTheme[] | null | 'failed') {
238
222
  const store = Array.isArray(catalog) ? catalog : [];
239
223
  return [
240
- ...store.map((x) => ({ id: x.id, legacy: x.legacy, name: x.name, author: x.author, version: x.version, icon: x.icon, words: x.words })),
224
+ ...store.map((x) => ({ id: x.id, name: x.name, author: x.author, version: x.version, icon: x.icon, words: x.words })),
241
225
  ...themes
242
- .filter((x) => !store.some((s) => s.id === x.id || s.legacy === x.id))
226
+ .filter((x) => !store.some((s) => s.id === x.id))
243
227
  .map((x) => ({
244
228
  id: x.id,
245
- legacy: undefined as string | undefined,
246
229
  name: x.name,
247
230
  author: x.author,
248
231
  version: x.version,
@@ -254,7 +237,7 @@ export function allThemes(catalog: ShownTheme[] | null | 'failed') {
254
237
  ];
255
238
  }
256
239
 
257
- /** A theme's row in "Appstore" and on a developer's page: its picture, its name, its version and who made it, and
240
+ /** A theme's row in "Theme store" and on a developer's page: its picture, its name, its version and who made it, and
258
241
  * whether it is installed, opening its page. */
259
242
  export function ThemeRow({ of }: { of: ReturnType<typeof allThemes>[number] }) {
260
243
  return (
@@ -264,7 +247,7 @@ export function ThemeRow({ of }: { of: ReturnType<typeof allThemes>[number] }) {
264
247
  headline={of.name}
265
248
  supporting={t.library.themeByline(of.version, of.author)}
266
249
  truncate
267
- count={themeInstalled(of.id, of.legacy) && (themePending(of.id) ? t.apps.pending : t.apps.installed)}
250
+ count={themeInstalled(of.id) && (themePending(of.id) ? t.apps.pending : t.apps.installed)}
268
251
  arrow
269
252
  />
270
253
  );
@@ -296,7 +279,7 @@ export function StoreThemePage({ id, env }: { id: string; env: Env }) {
296
279
  const shotName = (key: string) => t.library.themeShots[key] ?? of?.name ?? '';
297
280
 
298
281
  return (
299
- <Screen title={of?.name ?? t.common.parts.themes} wide back={{ href: `#${STORE_THEMES}`, label: t.apps.find }}>
282
+ <Screen title={of?.name ?? t.common.parts.themes} wide back={{ href: `#${STORE_THEMES}`, label: t.common.parts.themeStore }}>
300
283
  {of ? (
301
284
  <>
302
285
  <div className="mb-8 flex items-center gap-4 px-4">
@@ -380,11 +363,7 @@ export function ThemeStoreButtons({ of, env, files, top }: { of: ThemeInfo; env:
380
363
  if (top)
381
364
  return update ? (
382
365
  <div className="mb-8">
383
- <Button
384
- disabled={actions.saving}
385
- busy={actions.busy(update.id, 'update')}
386
- onClick={() => actions.update(update, of.store!, legacyOf(update, themes))}
387
- >
366
+ <Button disabled={actions.saving} busy={actions.busy(of.id, 'update')} onClick={() => actions.update(update, of.store!)}>
388
367
  {t.apps.update(update.version)}
389
368
  </Button>
390
369
  </div>
@@ -0,0 +1,62 @@
1
+ // "Theme store" (#appearance/theme-store, first under Appearance): the store's themes and those installed, with search, order and filter.
2
+ // Exposes ThemeStoreScreen; uses ThemeStore.tsx (allThemes, ThemeRow, useThemeCatalog), StoreSearchRow, StoreStatus and storeSort.
3
+ import Screen from './Screen';
4
+ import { Group, useKept } from './ui';
5
+ import type { Env } from './App';
6
+ import { StoreFooter, StoreNotice, StoreRound, useStoreConnected, useStoreKey } from './StoreStatus';
7
+ import { StoreSearchRow, useStateFilter } from './StoreSearchRow';
8
+ import { useSort } from './storeSort';
9
+ import { byText } from './schema';
10
+ import { headed, letterOf } from './Sheet';
11
+ import { allThemes, ThemeRow, themeInstalled, useThemeCatalog } from './ThemeStore';
12
+ import { backToAppearance } from './Library';
13
+ import { filterThemes } from './themeFilter.mjs';
14
+ import { t } from './i18n';
15
+
16
+ /** "Theme store" (#appearance/theme-store, first under Appearance): all themes, those in the store and those installed, each
17
+ * with its version and who made it, opening its page. With search (by name, who made it and the words it is found by),
18
+ * the order and the filter by whether it is installed, picked one as a chip. */
19
+ export function ThemeStoreScreen({ env }: { env: Env }) {
20
+ return <StoreRound>{(again) => <ThemeStoreList env={env} again={again} />}</StoreRound>;
21
+ }
22
+
23
+ function ThemeStoreList({ env, again }: { env: Env; again: () => void }) {
24
+ const key = useStoreKey();
25
+ const catalog = useThemeCatalog(env);
26
+ const connected = useStoreConnected(env);
27
+ const [query, setQuery] = useKept('theme-store-search', '');
28
+ const [sort, pickSort] = useSort();
29
+ const stateFilter = useStateFilter('theme-store');
30
+
31
+ const groups = headed(
32
+ filterThemes(allThemes(catalog), { query, state: stateFilter.state, sort, installed: themeInstalled, compare: byText }),
33
+ (x) => letterOf(x.name),
34
+ );
35
+
36
+ return (
37
+ <Screen title={t.common.parts.themeStore} wide back={backToAppearance}>
38
+ <StoreSearchRow
39
+ query={query}
40
+ onQuery={setQuery}
41
+ label={t.library.searchThemes}
42
+ sort={sort}
43
+ pickSort={pickSort}
44
+ groups={[stateFilter.group]}
45
+ chips={[stateFilter.chip]}
46
+ />
47
+ <StoreNotice connected={connected} read={catalog} mayChange={key?.mayChange ?? false} again={again} />
48
+ {catalog === null ? null : !groups.length ? (
49
+ <p className="mb-8 px-1 text-muted">{t.common.noMatch}</p>
50
+ ) : (
51
+ groups.map((g) => (
52
+ <Group key={g.key ?? 'all'} title={g.key ?? undefined}>
53
+ {g.items.map((x) => (
54
+ <ThemeRow key={x.id} of={x} />
55
+ ))}
56
+ </Group>
57
+ ))
58
+ )}
59
+ <StoreFooter keyInfo={key} again={again} />
60
+ </Screen>
61
+ );
62
+ }
package/src/checkSite.ts CHANGED
@@ -70,7 +70,8 @@ export function problemsOf(files: SiteFile[]): { problems: string[]; files: numb
70
70
  root?: string,
71
71
  defaults?: Record<string, unknown>,
72
72
  values?: Record<string, unknown>,
73
- // An entry of a list as the list has it now (FolderCollection.upgrade: a contact bar is an action bar).
73
+ // An entry of a list as the list has it now (FolderCollection.upgrade: a contact bar is an action bar), or a part's
74
+ // file as its form has it now (Part.upgrade: social.json's profiles as a list).
74
75
  upgrade?: (value: Record<string, unknown>) => Record<string, unknown>,
75
76
  ) => {
76
77
  const file = byPath.get(path);
@@ -107,7 +108,7 @@ export function problemsOf(files: SiteFile[]): { problems: string[]; files: numb
107
108
  ...seoParts,
108
109
  ...writtenBlockParts,
109
110
  ] as Part[])
110
- if (part.file && part.fields) data(part.file, part.fields, part.at, undefined, part.defaults);
111
+ if (part.file && part.fields) data(part.file, part.fields, part.at, undefined, part.defaults, undefined, part.upgrade);
111
112
  // The blocks turned off under "Blokindstillinger" (BlockSettings.tsx): a list of their types.
112
113
  data(config.blockSettings, [
113
114
  { name: 'off', label: t.app.blocksOff, type: 'list', field: { name: 'type', label: t.app.block, type: 'string' } },
@@ -0,0 +1,7 @@
1
+ /** @returns {{ id: string, key: 'notifyDone' | 'notifyUndone' | 'notifyStuck', version: string, error: boolean } | null} */
2
+ export function cmsNotice(update: any): {
3
+ id: string;
4
+ key: "notifyDone" | "notifyUndone" | "notifyStuck";
5
+ version: string;
6
+ error: boolean;
7
+ } | null;
@@ -0,0 +1,11 @@
1
+ // The notice for the CMS's newest update from npm: maps the state to a key and version for the notifications list.
2
+ // Exports cmsNotice; no dependencies.
3
+ /** @returns {{ id: string, key: 'notifyDone' | 'notifyUndone' | 'notifyStuck', version: string, error: boolean } | null} */
4
+ export function cmsNotice(update) {
5
+ if (!update || !update.commit || !update.to) return null;
6
+ if (update.state === 'waiting' || update.state === 'undoing') return null;
7
+ if (update.state === 'done') return { id: `${update.commit}:done`, key: 'notifyDone', version: update.to, error: false };
8
+ if (update.state === 'undone') return { id: `${update.commit}:undone`, key: 'notifyUndone', version: update.to, error: true };
9
+ if (update.state === 'stuck') return { id: `${update.commit}:stuck`, key: 'notifyStuck', version: update.to, error: true };
10
+ return null;
11
+ }
@@ -0,0 +1,50 @@
1
+ // Tests for src/cmsNotice.mjs: the notice for the CMS's newest update from npm. Run: node --test
2
+ import { test } from 'node:test';
3
+ import assert from 'node:assert/strict';
4
+ import { cmsNotice } from './cmsNotice.mjs';
5
+
6
+ test('returns null for null or undefined', () => {
7
+ assert.equal(cmsNotice(null), null);
8
+ assert.equal(cmsNotice(undefined), null);
9
+ });
10
+
11
+ test('returns null when commit or to is missing', () => {
12
+ assert.equal(cmsNotice({ to: '0.2.0' }), null);
13
+ assert.equal(cmsNotice({ commit: 'abc' }), null);
14
+ });
15
+
16
+ test('returns null for waiting or undoing state', () => {
17
+ assert.equal(cmsNotice({ commit: 'abc', to: '0.2.0', state: 'waiting' }), null);
18
+ assert.equal(cmsNotice({ commit: 'abc', to: '0.2.0', state: 'undoing' }), null);
19
+ });
20
+
21
+ test('returns notice for done state', () => {
22
+ assert.deepEqual(cmsNotice({ commit: 'abc', to: '0.2.0', state: 'done' }), {
23
+ id: 'abc:done',
24
+ key: 'notifyDone',
25
+ version: '0.2.0',
26
+ error: false,
27
+ });
28
+ });
29
+
30
+ test('returns notice for undone state', () => {
31
+ assert.deepEqual(cmsNotice({ commit: 'abc', to: '0.2.0', state: 'undone' }), {
32
+ id: 'abc:undone',
33
+ key: 'notifyUndone',
34
+ version: '0.2.0',
35
+ error: true,
36
+ });
37
+ });
38
+
39
+ test('returns notice for stuck state', () => {
40
+ assert.deepEqual(cmsNotice({ commit: 'abc', to: '0.2.0', state: 'stuck' }), {
41
+ id: 'abc:stuck',
42
+ key: 'notifyStuck',
43
+ version: '0.2.0',
44
+ error: true,
45
+ });
46
+ });
47
+
48
+ test('returns null for any other state', () => {
49
+ assert.equal(cmsNotice({ commit: 'abc', to: '0.2.0', state: 'unknown' }), null);
50
+ });
package/src/fields.tsx CHANGED
@@ -2,8 +2,8 @@
2
2
  // (object) hold other fields, so the deep front page is the same code as a price. A list of blocks
3
3
  // (a fixed page's sections) is a list whose items each have a `type` that gives their fields; it is
4
4
  // edited as a text with the sections as cards in it (SectionsField.tsx).
5
- import { createContext, useContext, useEffect, useId, useMemo, useRef, useState, type ReactNode } from 'react';
6
- import { ArrowDown, ArrowUp, CaretDown, PencilSimple, Plus, Trash } from '@phosphor-icons/react';
5
+ import { createContext, Fragment, useContext, useEffect, useId, useMemo, useRef, useState, type ReactNode } from 'react';
6
+ import { CaretDown, PencilSimple, Plus, Trash } from '@phosphor-icons/react';
7
7
  import {
8
8
  ArrowLink,
9
9
  Button,
@@ -51,6 +51,9 @@ import SectionsField from './SectionsField';
51
51
  import { leaveTo } from './FormFrame';
52
52
  import { shownAt } from './images';
53
53
  import { addressOf } from './addresses';
54
+ import { LinkList } from './LinkList';
55
+ import { MoveButtons } from './MoveButtons';
56
+ import { movedList } from './moveItem.mjs';
54
57
  import { clean, inPairs, inUse, newItem, phoneParts, phoneText, problemAt, problemOf, type Around, type Problem } from './check';
55
58
  import { Icon } from './icon';
56
59
  import { t } from './i18n';
@@ -254,6 +257,7 @@ function FieldControl({ field, value, onChange }: Props) {
254
257
  </FieldGroup>
255
258
  );
256
259
  case 'list':
260
+ if (field.links) return <Links field={field} value={value} onChange={onChange} />;
257
261
  return <ListInput field={field} value={(value ?? []) as unknown[]} onChange={onChange} />;
258
262
  case 'blocks':
259
263
  return <SectionsField field={field} value={(value ?? []) as Item[]} onChange={onChange} />;
@@ -535,7 +539,15 @@ export function FieldList({
535
539
  {fields
536
540
  .filter((f) => inUse(f, fields, value, around))
537
541
  .map((f) => (
538
- <FieldInput key={f.name} field={f} value={value[f.name]} onChange={(v) => onChange({ ...value, [f.name]: v })} />
542
+ <Fragment key={f.name}>
543
+ {/* A heading over it and those after it (Field.heading), in the form only. */}
544
+ {f.heading && (
545
+ <div className="pt-2">
546
+ <Label hint={f.heading.hint}>{f.heading.label}</Label>
547
+ </div>
548
+ )}
549
+ <FieldInput field={f} value={value[f.name]} onChange={(v) => onChange({ ...value, [f.name]: v })} />
550
+ </Fragment>
539
551
  ))}
540
552
  </AroundHere.Provider>
541
553
  );
@@ -673,6 +685,25 @@ const summaryOf = (field: Field, item: unknown) =>
673
685
  .map((name) => String((item as Item)?.[name] ?? '').trim())
674
686
  .find(Boolean) ?? '';
675
687
 
688
+ // A list of links (Field.links: LinkList.tsx), with the link whose address keeps the form from being saved (WrongField).
689
+ function Links({ field, value, onChange }: Props) {
690
+ const path = useContext(PathHere);
691
+ const wrong = useContext(WrongField);
692
+ const index = wrong?.path.startsWith(`${path}.`) ? Number(wrong.path.slice(path.length + 1).split('.')[0]) : NaN;
693
+ return (
694
+ <LinkList
695
+ field={field}
696
+ value={(value ?? []) as Record<string, unknown>[]}
697
+ onChange={(v) => {
698
+ if (Number.isInteger(index)) wrong?.clear();
699
+ onChange(v);
700
+ }}
701
+ hint={hintOf(field)}
702
+ wrong={Number.isInteger(index) ? { index, at: wrong!.at } : null}
703
+ />
704
+ );
705
+ }
706
+
676
707
  // A list of items, each opened to its fields. `add={false}` leaves out "Tilføj …" below it, for a
677
708
  // list that is added to with "+" in the top bar: an item added at the end, here or there, is opened
678
709
  // and scrolled to. (The menu has its own, MenuList.)
@@ -706,9 +737,7 @@ export function ListInput({
706
737
  length.current = value.length;
707
738
  }, [value.length]);
708
739
  const move = (i: number, to: number) => {
709
- const next = [...value];
710
- [next[i], next[to]] = [next[to], next[i]];
711
- onChange(next);
740
+ onChange(movedList(value, i, to));
712
741
  if (open === i) setOpen(to);
713
742
  };
714
743
  const remove = async (i: number) => {
@@ -736,8 +765,7 @@ export function ListInput({
736
765
  onToggle={() => setOpen(open === i ? null : i)}
737
766
  tools={
738
767
  <>
739
- <IconButton icon={ArrowUp} label={t.common.moveUp} disabled={i === 0} onClick={() => move(i, i - 1)} />
740
- <IconButton icon={ArrowDown} label={t.common.moveDown} disabled={i === value.length - 1} onClick={() => move(i, i + 1)} />
768
+ <MoveButtons index={i} length={value.length} onMove={(to) => move(i, to)} />
741
769
  <IconButton icon={Trash} label={t.common.remove} onClick={() => remove(i)} />
742
770
  </>
743
771
  }
@@ -845,9 +873,7 @@ export function MenuList({
845
873
  close();
846
874
  };
847
875
  const move = (i: number, to: number) => {
848
- const next = [...value];
849
- [next[i], next[to]] = [next[to], next[i]];
850
- onChange(next);
876
+ onChange(movedList(value, i, to));
851
877
  if (open === i) setOpen(to);
852
878
  else if (open === to) setOpen(i);
853
879
  };
@@ -875,8 +901,7 @@ export function MenuList({
875
901
  actions={
876
902
  <span className="flex shrink-0 pr-1.5">
877
903
  <IconButton icon={PencilSimple} label={t.forms.editOne(nameOf(item))} onClick={() => edit(i)} />
878
- <IconButton icon={ArrowUp} label={t.common.moveUp} disabled={i === 0} onClick={() => move(i, i - 1)} />
879
- <IconButton icon={ArrowDown} label={t.common.moveDown} disabled={i === value.length - 1} onClick={() => move(i, i + 1)} />
904
+ <MoveButtons index={i} length={value.length} onMove={(to) => move(i, to)} />
880
905
  {sub && (
881
906
  <IconButton
882
907
  icon={CaretDown}
@@ -26,17 +26,27 @@ export type HeaderValues = {
26
26
  };
27
27
  /**
28
28
  * What the form changes in the header; undefined leaves it as it is on the site. `nav` null: the menu is off (no items,
29
- * no menu button); `mobileNav` empty: no bar; `button` null: the phone icon.
29
+ * no menu button); `mobileNav` empty: no bar; `cta`: the call to action, when its button or phone number changed
30
+ * (`button` null: no button).
31
+ */
32
+ export type HeaderCta = {
33
+ button: Button | null;
34
+ phone: boolean;
35
+ };
36
+ /**
37
+ * What the form changes in the header; undefined leaves it as it is on the site. `nav` null: the menu is off (no items,
38
+ * no menu button); `mobileNav` empty: no bar; `cta`: the call to action, when its button or phone number changed
39
+ * (`button` null: no button).
30
40
  */
31
41
  export type HeaderDraft = {
32
42
  nav?: NavItem[] | null;
33
43
  mobileNav?: NavLink[];
34
44
  menuSide?: "start" | "end";
35
- button?: Button | null;
45
+ cta?: HeaderCta;
36
46
  };
37
47
  /**
38
- * How the theme draws what the page may not have: the menu button's classes on each side, the button's place as HTML
39
- * (when `button` changed; with data-editor="header-cta"), an empty bar of "Mobilmenu" with one tab (for a page without
48
+ * How the theme draws what the page may not have: the menu button's classes on each side, the call to action as HTML
49
+ * (when `cta` changed; with data-editor="header-cta"), an empty bar of "Mobilmenu" with one tab (for a page without
40
50
  * one), the name of an item's sub-pages button, and the page's address (for the open page's item).
41
51
  */
42
52
  export type HeaderTheme = {
@@ -1,7 +1,7 @@
1
1
  // The editor's preview of the header (HeaderSettings.tsx): what the header's settings in the form change (headerDraft),
2
2
  // and those changes put into the site's page (swapHeader), in the parts Header.astro and MobileNav.astro mark with
3
3
  // data-editor: the menu's items (header-nav), the menu button (header-menu) and its side, the bar of "Mobilmenu"
4
- // (mobile-nav) and the button's place (header-cta). Exposes headerDraft and swapHeader. Uses site/header.mjs; a DOM (the
4
+ // (mobile-nav) and the call to action (header-cta: the phone number and the button). Exposes headerDraft and swapHeader. Uses site/header.mjs; a DOM (the
5
5
  // browser's, jsdom in the tests), no React: what the theme's components draw comes in as HTML.
6
6
  import { headerOf, sortedNav } from '../site/header.mjs';
7
7
 
@@ -16,8 +16,10 @@ import { headerOf, sortedNav } from '../site/header.mjs';
16
16
 
17
17
  /**
18
18
  * What the form changes in the header; undefined leaves it as it is on the site. `nav` null: the menu is off (no items,
19
- * no menu button); `mobileNav` empty: no bar; `button` null: the phone icon.
20
- * @typedef {{ nav?: NavItem[] | null, mobileNav?: NavLink[], menuSide?: 'start' | 'end', button?: Button | null }} HeaderDraft
19
+ * no menu button); `mobileNav` empty: no bar; `cta`: the call to action, when its button or phone number changed
20
+ * (`button` null: no button).
21
+ * @typedef {{ button: Button | null, phone: boolean }} HeaderCta
22
+ * @typedef {{ nav?: NavItem[] | null, mobileNav?: NavLink[], menuSide?: 'start' | 'end', cta?: HeaderCta }} HeaderDraft
21
23
  */
22
24
 
23
25
  // As site/site.ts reads the files: the menu's items unless it is off, the bar's links while it is on.
@@ -48,13 +50,13 @@ export function headerDraft(saved, now) {
48
50
  if (!same(mobileNav, mobileBefore)) draft.mobileNav = mobileNav;
49
51
  const [header, before] = [headerOf(now.header), headerOf(saved.header)];
50
52
  if (header.menuSide !== before.menuSide) draft.menuSide = header.menuSide;
51
- if (!same(header.button, before.button)) draft.button = header.button;
53
+ if (!same(header.button, before.button) || header.phone !== before.phone) draft.cta = { button: header.button, phone: header.phone };
52
54
  return draft;
53
55
  }
54
56
 
55
57
  /**
56
- * How the theme draws what the page may not have: the menu button's classes on each side, the button's place as HTML
57
- * (when `button` changed; with data-editor="header-cta"), an empty bar of "Mobilmenu" with one tab (for a page without
58
+ * How the theme draws what the page may not have: the menu button's classes on each side, the call to action as HTML
59
+ * (when `cta` changed; with data-editor="header-cta"), an empty bar of "Mobilmenu" with one tab (for a page without
58
60
  * one), the name of an item's sub-pages button, and the page's address (for the open page's item).
59
61
  * @typedef {{ menuClass: Record<'start' | 'end', string>, cta?: string, mobileNav: string, subpagesOf: (label: string) => string, current: string }} HeaderTheme
60
62
  */
@@ -158,8 +160,8 @@ export function swapHeader(doc, draft, theme) {
158
160
  menu?.remove();
159
161
  } else if (draft.nav && nav) drawNav(nav, draft.nav, theme);
160
162
  if (draft.mobileNav) drawMobileNav(doc, draft.mobileNav, theme);
161
- if (draft.button !== undefined && theme.cta !== undefined) part(doc, 'header-cta')?.replaceWith(fromHtml(doc, theme.cta));
162
- // The menu button first in the header's row, or last (after the button's place).
163
+ if (draft.cta && theme.cta !== undefined) part(doc, 'header-cta')?.replaceWith(fromHtml(doc, theme.cta));
164
+ // The menu button first in the header's row, or last (after the call to action).
163
165
  if (draft.menuSide && menu?.isConnected && menu.parentElement) {
164
166
  menu.className = theme.menuClass[draft.menuSide];
165
167
  if (draft.menuSide === 'start') menu.parentElement.prepend(menu);
@@ -88,8 +88,16 @@ test('headerDraft: "Mobilmenu" turned off is an empty bar, turned on its links',
88
88
 
89
89
  test('headerDraft: the button and the menu button at the end', () => {
90
90
  const header = { button: { enabled: true, label: 'Book', to: 'booking' }, menuSide: 'end' };
91
- assert.deepEqual(headerDraft(SAVED, withChange({ header })), { menuSide: 'end', button: { label: 'Book', to: 'booking' } });
92
- assert.deepEqual(headerDraft(withChange({ header }), SAVED), { menuSide: 'start', button: null });
91
+ assert.deepEqual(headerDraft(SAVED, withChange({ header })), {
92
+ menuSide: 'end',
93
+ cta: { button: { label: 'Book', to: 'booking' }, phone: true },
94
+ });
95
+ assert.deepEqual(headerDraft(withChange({ header }), SAVED), { menuSide: 'start', cta: { button: null, phone: true } });
96
+ });
97
+
98
+ test('headerDraft: the phone number turned off', () => {
99
+ const header = { button: { enabled: false, phone: false } };
100
+ assert.deepEqual(headerDraft(SAVED, withChange({ header })), { cta: { button: null, phone: false } });
93
101
  });
94
102
 
95
103
  test('swapHeader: an empty draft leaves the page as it is', () => {
@@ -162,10 +170,10 @@ test('swapHeader: the bar of "Mobilmenu" drawn again, removed, and put in when t
162
170
  assert.equal(bar.querySelector('a').getAttribute('aria-current'), 'page');
163
171
  });
164
172
 
165
- test('swapHeader: the button in place of the phone icon', () => {
173
+ test('swapHeader: the call to action with the button', () => {
166
174
  const doc = page();
167
175
  const cta = '<div data-editor="header-cta" class="cta"><a href="/booking/">Book</a></div>';
168
- swapHeader(doc, { button: { label: 'Book', to: 'booking' } }, { ...THEME, cta });
176
+ swapHeader(doc, { cta: { button: { label: 'Book', to: 'booking' }, phone: false } }, { ...THEME, cta });
169
177
  assert.equal(part(doc, 'header-cta').className, 'cta');
170
178
  assert.equal(part(doc, 'header-cta').textContent, 'Book');
171
179
  assert.equal(doc.querySelectorAll('[data-editor="header-cta"]').length, 1);
@@ -1,34 +1,27 @@
1
1
  // How the theme draws the parts of the header that its settings put in, as HTML for the editor's preview of the header
2
- // (headerPreview.mjs HeaderTheme): the button or the phone icon in the button's place, an empty bar of "Mobilmenu", the
3
- // menu button's classes on each side. Exposes headerThemeOf. Uses the theme's Buttons, IconButton, Tabs and headerParts.ts.
4
- import Buttons from '@theme/blocks/buttons/Buttons';
5
- import IconButton from '@theme/ui/IconButton';
2
+ // (headerPreview.mjs HeaderTheme): the call to action (the phone number and the button, HeaderCta.tsx), an empty bar of
3
+ // "Mobilmenu", the menu button's classes on each side. Exposes headerThemeOf. Uses the theme's HeaderCta, Tabs and
4
+ // headerParts.ts.
5
+ import HeaderCta from '@theme/components/HeaderCta';
6
6
  import { tabClass } from '@theme/ui/Tabs';
7
- import { headerCtaClass, headerEdge, headerMenuClass, mobileNavClass, mobileNavListClass } from '@theme/components/headerParts';
7
+ import { headerMenuClass, mobileNavClass, mobileNavListClass } from '@theme/components/headerParts';
8
8
  import { buttonsOf } from './standard/buttons/view';
9
- import type { Button } from './standard/buttons/fields';
10
9
  import type { BlockData } from './blocks';
11
10
  import { htmlOf } from './pagePreview';
12
11
  import { siteT } from './i18n';
13
- import type { HeaderTheme } from './headerPreview.mjs';
12
+ import type { HeaderCta as Cta, HeaderTheme } from './headerPreview.mjs';
14
13
 
15
- // As Header.astro draws the button's place: the button (filled) from the medium window size up, else the phone icon.
16
- function ctaOf(button: Button | null, data: BlockData) {
17
- if (button) {
18
- return (
19
- <div data-editor="header-cta" className={headerCtaClass}>
20
- <Buttons buttons={buttonsOf([{ ...button, kind: 'filled' }], data)} />
21
- </div>
22
- );
23
- }
24
- const { phone } = data.site.contact;
14
+ // As Header.astro draws the call to action: the button (filled) and the site's phone number, each when it is on. The
15
+ // number's link is its tel: one at every size (the site's leads to the contact page on a computer): the preview's links
16
+ // are only drawn.
17
+ function ctaOf({ button, phone }: Cta, data: BlockData) {
18
+ const number = data.site.contact.phone;
25
19
  return (
26
- <IconButton
27
- href={`tel:${phone.replace(/\s/g, '')}`}
28
- icon="phone"
29
- label={`${data.site.labels.call} ${phone}`}
30
- className={headerEdge.end}
31
- data-editor="header-cta"
20
+ <HeaderCta
21
+ button={button ? buttonsOf([{ ...button, kind: 'filled' }], data)[0] : undefined}
22
+ phone={
23
+ phone && number ? { number, href: `tel:${number.replace(/\s/g, '')}`, label: `${data.site.labels.call} ${number}` } : undefined
24
+ }
32
25
  />
33
26
  );
34
27
  }
@@ -45,12 +38,12 @@ const mobileNavHtml = () =>
45
38
  </nav>,
46
39
  );
47
40
 
48
- /** The theme's parts for the preview; `button`: the header's button as the form has it (headerOf), when it changed. The
41
+ /** The theme's parts for the preview; `cta`: the call to action as the form has it (headerOf), when it changed. The
49
42
  * HTML is drawn here, when the preview draws the page, not while the form is drawn. */
50
- export function headerThemeOf(button: Button | null | undefined, data: BlockData): HeaderTheme {
43
+ export function headerThemeOf(cta: Cta | undefined, data: BlockData): HeaderTheme {
51
44
  return {
52
45
  menuClass: { start: headerMenuClass('start'), end: headerMenuClass('end') },
53
- cta: button === undefined ? undefined : htmlOf(ctaOf(button, data)),
46
+ cta: cta === undefined ? undefined : htmlOf(ctaOf(cta, data)),
54
47
  mobileNav: mobileNavHtml(),
55
48
  subpagesOf: siteT.theme.subpagesOf,
56
49
  current: '/',
@@ -96,6 +96,7 @@ export const common: Messages['common'] = {
96
96
  media: 'Filer',
97
97
  appearance: 'Udseende',
98
98
  themes: 'Temaer',
99
+ themeStore: 'Temastore',
99
100
  iconPacks: 'Ikonpakker',
100
101
  motion: 'Bevægelse',
101
102
  sideColumn: 'Sidekolonne',
@@ -10,6 +10,18 @@ export const forms: Messages['forms'] = {
10
10
  seo: 'Søgemaskiner',
11
11
  share: 'Sociale medier',
12
12
  sharePreview: 'Sådan ser et link til siden ud, når det deles',
13
+ links: {
14
+ add: 'Tilføj link',
15
+ none: 'Ingen links endnu. Tilføj et med knappen +.',
16
+ address: 'Adresse',
17
+ hint: 'Indsæt adressen på en profil, fx https://www.facebook.com/…',
18
+ found: (network) => `Profil på ${network}`,
19
+ addButton: 'Tilføj',
20
+ done: 'Færdig',
21
+ remove: 'Fjern link',
22
+ noAddress: 'Skriv en adresse',
23
+ twice: 'Linket er allerede på listen',
24
+ },
13
25
  searchPreview: {
14
26
  on: 'Google-resultat på',
15
27
  mobile: 'Mobil',
@@ -112,6 +112,8 @@ export const common = {
112
112
  appearance: 'Appearance',
113
113
  /** The themes installed (#appearance/themes, Library.tsx Themes), the first row under "Udseende". */
114
114
  themes: 'Themes',
115
+ /** The store's themes, to install and update them (#appearance/theme-store, ThemeStoreScreen.tsx), the first row under Appearance. */
116
+ themeStore: 'Theme store',
115
117
  /** The icon packs installed, to choose the one the site draws its icons with (#appearance/icon-packs, IconPacks). */
116
118
  iconPacks: 'Icon packs',
117
119
  /** How the site moves, Material 3's motion schemes (#appearance/motion, MotionSchemes in Library.tsx). */