@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
@@ -37,8 +37,13 @@ export function usePartForm({ part, env, files }: Props) {
37
37
  // The file as it was loaded or last saved, and its fields as they are now.
38
38
  // A file that is not there yet (the first block with shared texts) is made by the first save.
39
39
  const [base, setBase] = useState(() => files.find((f) => f.path === path) ?? { path, oid: '', text: '{}\n' });
40
- const valuesOf = (text: string) => {
40
+ // The file's data, as the form has it now when it was written before the fields changed (Part.upgrade).
41
+ const dataOf = (text: string) => {
41
42
  const data = JSON.parse(text) as Record<string, any>;
43
+ return part.upgrade ? (part.upgrade(data) as Record<string, any>) : data;
44
+ };
45
+ const valuesOf = (text: string) => {
46
+ const data = dataOf(text);
42
47
  const own = (at ? data[at] : data) ?? {};
43
48
  return Object.fromEntries(fields.map((f) => [f.name, own[f.name] ?? part.defaults?.[f.name] ?? '']));
44
49
  };
@@ -57,7 +62,7 @@ export function usePartForm({ part, env, files }: Props) {
57
62
  async function save() {
58
63
  if (wrongField.stop(problemAt(fields, values))) return;
59
64
  // The file with these fields changed, written like the others (DataForm.tsx).
60
- const data = JSON.parse(base.text) as Record<string, any>;
65
+ const data = dataOf(base.text);
61
66
  // Written as the fields write them (a number in pairs …); an emptied field is taken out.
62
67
  // Kept in their place in the file.
63
68
  const target = at ? (data[at] ??= {}) : data;
@@ -1,6 +1,6 @@
1
1
  // "Udseende" › "Header" (#appearance/header): what is in the header on every page, on one screen laid out as a page's form
2
2
  // (SettingsSections.tsx): a preview of the header as the form has it, on a phone and a computer (partPreview.tsx), over the
3
- // sections Main menu (menu.json), Mobile menu (mobile-menu.json), Action button and Menu button (header.json). "Gem
3
+ // sections Main menu (menu.json), Mobile menu (mobile-menu.json), Call to action and Menu button (header.json). "Gem
4
4
  // ændringer" saves each changed file in its own commit (useDataFiles.ts). Exposes HeaderSettings (default). Uses
5
5
  // DataFileFields.tsx, fields.tsx, blocks.ts (BlockData), headerPreview.mjs and headerTheme.tsx.
6
6
  import { useMemo, type ReactNode } from 'react';
@@ -26,7 +26,7 @@ const parts: DataFilePart[] = Object.values(FILES).flatMap((id) => {
26
26
  });
27
27
  const at = (id: string) => parts.findIndex((p) => p.collection.id === id);
28
28
 
29
- // The sections, each with the file it is of: a menu is one; header.json's group (the action button) is one, and its other
29
+ // The sections, each with the file it is of: a menu is one; header.json's group (the call to action) is one, and its other
30
30
  // fields (the menu button's side) are "Menu button".
31
31
  type Place = { id: string; label: string; file: number; field?: string };
32
32
  const places: Place[] = parts.flatMap(({ collection, dataFile }, file): Place[] => {
@@ -61,13 +61,13 @@ export default function HeaderSettings({ env }: { env: Env }) {
61
61
  layout.steer(id);
62
62
  });
63
63
  const context: FieldContext = { relations: env.relations, lists: env.lists, testimonials: env.testimonials, site: env.site };
64
- // What the theme draws the header's button from (headerThemeOf): the same site data, as the block cards have it.
64
+ // What the theme draws the header's call to action from (headerThemeOf): the same site data, as the block cards have it.
65
65
  const data: BlockData = { lists: env.lists, testimonials: env.testimonials, relations: env.relations, site: env.site };
66
66
 
67
67
  // What the form changes, put into a copy of the site's front page each time it changes.
68
68
  const swap = useMemo(() => {
69
69
  const draft = headerDraft(shapeOf(form.initial), shapeOf(form.values));
70
- return (doc: Document) => swapHeader(doc, draft, headerThemeOf(draft.button, data));
70
+ return (doc: Document) => swapHeader(doc, draft, headerThemeOf(draft.cta, data));
71
71
  }, [form.initial, form.values]);
72
72
 
73
73
  const fieldsOf = ({ file, field }: Place): ReactNode => {
package/src/Library.tsx CHANGED
@@ -130,6 +130,7 @@ const countOf = (c: Collection, files: RepoFile[]): number =>
130
130
  export function partOf(id: string, files: RepoFile[]): { label: string; href: string; count: number | null } {
131
131
  const { parts } = t.common;
132
132
  if (id === 'company') return { label: parts.company, href: '#company', count: null };
133
+ if (id === 'logo') return { label: parts.brand, href: '#company/logo', count: null };
133
134
  if (id === 'header') return { label: parts.header, href: '#appearance/header', count: null };
134
135
  if (id === 'footer') return { label: parts.footer, href: '#appearance/footer', count: null };
135
136
  if (id === 'lists') return { label: parts.lists, href: '#lists', count: listsShown(files).length };
@@ -144,12 +145,12 @@ export function partOf(id: string, files: RepoFile[]): { label: string; href: st
144
145
  if (seoPart) return { label: seoPart.label, href: `#seo/${id}`, count: null };
145
146
  // The screens under "Udseende" (Theme): the ones the editor has, then the site's own (appearance).
146
147
  const appearanceLabel = {
148
+ 'theme-store': parts.themeStore,
147
149
  themes: parts.themes,
148
150
  'icon-packs': parts.iconPacks,
149
151
  motion: parts.motion,
150
152
  'side-column': parts.sideColumn,
151
153
  colors: parts.colors,
152
- logo: parts.brand,
153
154
  parts: parts.editorParts,
154
155
  }[id];
155
156
  const appearancePart = appearanceLabel ?? appearance.find((p) => p.id === id)?.label;
@@ -198,7 +199,7 @@ export function Start({ builtAt, files, env }: { builtAt: Date | null; files: Re
198
199
  );
199
200
  }
200
201
 
201
- // "Virksomheden": its parts (CompanyForm.tsx), each on a screen of its own; or one of them with parts
202
+ // "Virksomheden": its screen has "Logo og ikon" (BrandForm.tsx, #company/logo) first, then its parts (CompanyForm.tsx), each on a screen of its own; or one of them with parts
202
203
  // of its own ("Betaling"), and the settings of the apps installed of its kinds (Part.apps: MobilePay), going back to
203
204
  // "Virksomheden".
204
205
  export function Company({ part, files }: { part?: Part; files: RepoFile[] }) {
@@ -211,20 +212,29 @@ export function Company({ part, files }: { part?: Part; files: RepoFile[] }) {
211
212
  back={{ href: '#company', label: t.common.parts.company }}
212
213
  />
213
214
  );
214
- return <Parts title={t.common.parts.company} route="company" parts={companyParts} />;
215
+ return (
216
+ <Parts
217
+ title={t.common.parts.company}
218
+ route="company"
219
+ parts={[{ id: 'logo', label: t.common.parts.brand, icon: icons.logo }, ...companyParts]}
220
+ />
221
+ );
215
222
  }
216
223
 
217
- // "Udseende": first "Temaer" (Themes), with the theme the site is built with at the end of its row (or, after a swap,
218
- // until the site is built with the new one, that one), "Ikonpakker" (IconPacks), with the pack chosen, "Bevægelse"
219
- // (MotionSchemes), with the scheme chosen, and "Sidekolonne" (SideColumn.tsx), with the block chosen; then how the
220
- // site looks, the colours (Colors.tsx), the logo and icon (BrandForm.tsx), the header with its menus and its preview
221
- // (HeaderSettings.tsx), the footer with its preview (FooterSettings.tsx) and the site's own parts there (appearance in packages/editor/defaults/editor.ts: "Standardsider", a
224
+ // Appearance: first "Theme store" (the store's themes, ThemeStoreScreen.tsx), then the header with its menus and its preview
225
+ // (HeaderSettings.tsx) and the footer with its preview (FooterSettings.tsx), then "Temaer" (Themes), with the theme the site
226
+ // is built with at the end of its row (or, after a swap, until the site is built with the new one, that one), "Ikonpakker"
227
+ // (IconPacks), with the pack chosen, "Bevægelse" (MotionSchemes), with the scheme chosen, "Sidekolonne" (SideColumn.tsx),
228
+ // with the block chosen, and the colours (Colors.tsx); then the site's own parts there (appearance in packages/editor/defaults/editor.ts: "Standardsider", a
222
229
  // screen of its own, CompanyForm.tsx, going back here), and how the editor and the blocks look, their parts ("Dele", PartsHome), each on a
223
- // screen of its own, with the icons the site gives them.
230
+ // screen of its own, with the icons the site gives them. The logo and icon (BrandForm.tsx) are under "Virksomheden" (Company).
224
231
  // The blocks that can be put in are under "Blokke" ("Blokindstillinger", BlockSettings.tsx).
225
232
  export function Theme({ files }: { files: RepoFile[] }) {
226
233
  const chosen = themes.find((x) => x.id === chosenTheme(files)) ?? theme;
227
234
  const parts: Part[] = [
235
+ { id: 'theme-store', label: t.common.parts.themeStore, icon: icons['theme-store'] },
236
+ { id: 'header', label: t.common.parts.header, icon: icons.header },
237
+ { id: 'footer', label: t.common.parts.footer, icon: icons.footer },
228
238
  { id: 'themes', label: t.common.parts.themes, icon: icons.themes, detail: chosen.name },
229
239
  {
230
240
  id: 'icon-packs',
@@ -240,9 +250,6 @@ export function Theme({ files }: { files: RepoFile[] }) {
240
250
  detail: sideChoicesOf(files).find((x) => x.type === sideSettingOf(files))?.label ?? t.library.sideNone,
241
251
  },
242
252
  { id: 'colors', label: t.common.parts.colors, icon: icons.colors, trailing: <ThemeColors files={files} /> },
243
- { id: 'logo', label: t.common.parts.brand, icon: icons.logo },
244
- { id: 'header', label: t.common.parts.header, icon: icons.header },
245
- { id: 'footer', label: t.common.parts.footer, icon: icons.footer },
246
253
  ...appearance,
247
254
  { id: 'parts', label: t.common.parts.editorParts, icon: icons.parts },
248
255
  ];
@@ -259,7 +266,7 @@ function ThemeColors({ files }: { files: RepoFile[] }) {
259
266
  );
260
267
  }
261
268
 
262
- const backToAppearance = { href: '#appearance', label: t.common.parts.appearance };
269
+ export const backToAppearance = { href: '#appearance', label: t.common.parts.appearance };
263
270
  const backToThemes = { href: '#appearance/themes', label: t.common.parts.themes };
264
271
 
265
272
  /** Under a theme's name: whether the site is built with it ("I brug") or is changing to it ("Skifter hertil"). */
@@ -0,0 +1,165 @@
1
+ // A list of links (Field.links: social media's profiles): each a row with its network's icon and name, known by its
2
+ // address (networkOf in site/social.mjs; for one not known its host and a globe), and the address under it; the arrows
3
+ // at its end move it up and down. A tap opens the bottom sheet where its address is changed or the link removed, and
4
+ // the FAB adds one in the same sheet. An address typed without https:// is given it; the same address twice is not
5
+ // let in. What is changed here is saved with the form (CompanyForm.tsx). Exposes LinkList (the list) and networkIcons
6
+ // (the icon of each network known, by its id). Uses the rows, the sheet and the FAB of ui.tsx and CreateFab.tsx, the
7
+ // arrows of MoveButtons.tsx, and the address logic of linkAddress.mjs.
8
+ import { useEffect, useRef, useState, type ReactNode } from 'react';
9
+ import { FacebookLogo, Globe, LinkedinLogo, PinterestLogo, Trash, XLogo, type Icon } from '@phosphor-icons/react';
10
+ import { networkOf, type NetworkId } from '../site/social.mjs';
11
+ import { nameOf, problemOf, shownAddress, typedLink } from './linkAddress.mjs';
12
+ import { CreateFab } from './CreateFab';
13
+ import { MoveButtons } from './MoveButtons';
14
+ import { movedList } from './moveItem.mjs';
15
+ import type { Field } from './schema';
16
+ import { BottomSheet, Button, EmptyNote, Label, ListItem, listClass, SheetBody, SheetTitle, TextField } from './ui';
17
+ import { t } from './i18n';
18
+
19
+ /** The icon of each network known (NETWORKS in site/social.mjs), as the share buttons have them; any other link has the
20
+ * globe. */
21
+ export const networkIcons: Record<NetworkId, Icon> = {
22
+ facebook: FacebookLogo,
23
+ x: XLogo,
24
+ linkedin: LinkedinLogo,
25
+ pinterest: PinterestLogo,
26
+ };
27
+
28
+ type Link = { url?: string } & Record<string, unknown>;
29
+
30
+ const iconOf = (url: string): Icon => {
31
+ const network = networkOf(url);
32
+ return network ? networkIcons[network.id] : Globe;
33
+ };
34
+ /** `hint`: what is under the list's name (hintOf in fields.tsx). `wrong`: the item whose address keeps the form from
35
+ * being saved (WrongField), its number and when it was found, so its sheet opens again on the next try. */
36
+ export function LinkList({
37
+ field,
38
+ value,
39
+ onChange,
40
+ hint,
41
+ wrong,
42
+ }: {
43
+ field: Field;
44
+ value: Link[];
45
+ onChange: (v: Link[]) => void;
46
+ hint?: ReactNode;
47
+ wrong?: { index: number; at: number } | null;
48
+ }) {
49
+ const address = field.fields?.find((f) => f.name === 'url');
50
+ const dialog = useRef<HTMLDialogElement>(null);
51
+ // The link open in the sheet: its place in the list (null: a new one) and its address as typed.
52
+ const [editing, setEditing] = useState<{ index: number | null; typed: string } | null>(null);
53
+ const [problem, setProblem] = useState('');
54
+ const open = (index: number | null) => {
55
+ setEditing({ index, typed: index === null ? '' : String(value[index]?.url ?? '') });
56
+ setProblem('');
57
+ dialog.current?.showModal();
58
+ };
59
+ const close = () => dialog.current?.close();
60
+ // A link that keeps the form from being saved is opened in the sheet, with what is wrong.
61
+ useEffect(() => {
62
+ if (!wrong || !value[wrong.index]) return;
63
+ open(wrong.index);
64
+ setProblem(problemWith(String(value[wrong.index].url ?? '')) ?? '');
65
+ }, [wrong?.at]);
66
+
67
+ // What is wrong with an address: none, not one, or one already in the list (but for the link itself).
68
+ const problemWith = (url: string, index: number | null = null) =>
69
+ problemOf(
70
+ url,
71
+ index,
72
+ value.map((l) => l.url),
73
+ { pattern: address?.pattern, noAddress: t.forms.links.noAddress, twice: t.forms.links.twice },
74
+ );
75
+
76
+ function done() {
77
+ if (!editing) return;
78
+ const url = typedLink(editing.typed);
79
+ const wrongWith = problemWith(url, editing.index);
80
+ if (wrongWith) return setProblem(wrongWith);
81
+ if (editing.index === null) onChange([...value, { url }]);
82
+ else onChange(value.map((l, i) => (i === editing.index ? { ...l, url } : l)));
83
+ close();
84
+ }
85
+
86
+ const remove = (index: number) => {
87
+ onChange(value.filter((_, i) => i !== index));
88
+ close();
89
+ };
90
+ const move = (i: number, to: number) => onChange(movedList(value, i, to));
91
+
92
+ const typed = editing ? typedLink(editing.typed) : '';
93
+ const network = typed ? networkOf(typed) : null;
94
+ return (
95
+ <div>
96
+ <Label hint={hint}>{field.label}</Label>
97
+ <ul className={listClass}>
98
+ {value.length ? (
99
+ value.map((link, i) => {
100
+ const url = String(link.url ?? '');
101
+ return (
102
+ <ListItem
103
+ key={i}
104
+ icon={iconOf(url)}
105
+ headline={nameOf(url) || t.forms.empty}
106
+ supporting={shownAddress(url)}
107
+ truncate
108
+ onClick={() => open(i)}
109
+ actions={
110
+ value.length > 1 && (
111
+ <span className="flex shrink-0 pr-1.5">
112
+ <MoveButtons index={i} length={value.length} onMove={(to) => move(i, to)} />
113
+ </span>
114
+ )
115
+ }
116
+ />
117
+ );
118
+ })
119
+ ) : (
120
+ <EmptyNote item>{t.forms.links.none}</EmptyNote>
121
+ )}
122
+ </ul>
123
+ <BottomSheet
124
+ ref={dialog}
125
+ onClose={(e) => e.target === e.currentTarget && setEditing(null)}
126
+ onClick={(e) => e.target === dialog.current && close()}
127
+ >
128
+ <SheetTitle title={editing?.index == null ? t.forms.links.add : nameOf(String(value[editing.index]?.url ?? ''))} onClose={close} />
129
+ {editing && (
130
+ <SheetBody
131
+ onSubmit={(e) => {
132
+ e.preventDefault();
133
+ done();
134
+ }}
135
+ >
136
+ <div>
137
+ <TextField
138
+ id="link-url"
139
+ label={address?.label ?? t.forms.links.address}
140
+ hint={network ? t.forms.links.found(network.name) : t.forms.links.hint}
141
+ problem={problem || undefined}
142
+ value={editing.typed}
143
+ inputMode="url"
144
+ autoComplete="off"
145
+ autoCapitalize="off"
146
+ spellCheck={false}
147
+ onChange={(e) => {
148
+ setEditing({ ...editing, typed: e.target.value });
149
+ setProblem('');
150
+ }}
151
+ />
152
+ </div>
153
+ <Button type="submit">{editing.index === null ? t.forms.links.addButton : t.forms.links.done}</Button>
154
+ {editing.index !== null && (
155
+ <Button kind="outlined" icon={Trash} onClick={() => remove(editing.index!)}>
156
+ {t.forms.links.remove}
157
+ </Button>
158
+ )}
159
+ </SheetBody>
160
+ )}
161
+ </BottomSheet>
162
+ <CreateFab label={t.forms.links.add} onClick={() => open(null)} />
163
+ </div>
164
+ );
165
+ }
package/src/MainMenu.tsx CHANGED
@@ -2,19 +2,21 @@
2
2
  // sections; a section opens its list, under a back row, with the open screen marked and its fold-out folded out. Apps lists
3
3
  // Appstore and a row per app installed. From medium and wider the first level is also the collapsed navigation rail
4
4
  // (MainRailItem), whose sections open the drawer at their list. The drawer's header is the signed-in user (AccountRow), a link
5
- // to the account. Exposes MainMenu. The tree and the open place are lib/menu.mjs
5
+ // to the account. In the modal drawer a section's list is a step in the history (levelStep.mjs): the phone's back gesture
6
+ // goes from it to the first level. Exposes MainMenu. The tree and the open place are lib/menu.mjs
6
7
  // (menuTree, currentPlace); it only wires them to the drawer.
7
8
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
8
9
  import { config, header } from '@site/editor';
9
10
  import { currentPlace, menuTree } from '../lib/menu.mjs';
10
11
  import { STORE_ROUTE } from './store';
11
12
  import { collectionOf } from './schema';
12
- import { apps, collections, groups, icons, lists, partScreens } from './site';
13
+ import { apps, collections, companyParts, groups, icons, lists, partScreens } from './site';
13
14
  import { partOf } from './Library';
14
15
  import { AccountRow } from './AccountRow';
15
16
  import { childrenOf } from './menuChildren';
16
17
  import { t } from './i18n';
17
18
  import { useMenuOpen } from './menuOpen';
19
+ import { levelStep } from './levelStep.mjs';
18
20
  import {
19
21
  MainDrawer,
20
22
  MainDrawerBack,
@@ -25,6 +27,7 @@ import {
25
27
  MainDrawerSubitem,
26
28
  MainRailItem,
27
29
  MainRailSectionItem,
30
+ useMenuLayout,
28
31
  } from './ui';
29
32
  import type { RepoFile, Viewer } from './github';
30
33
 
@@ -76,6 +79,19 @@ export function MainMenu({ route, files, user }: { route: string; files: RepoFil
76
79
  setShown(null);
77
80
  return true;
78
81
  }, []);
82
+ // A section's list in the modal drawer: the back gesture goes to the first level (levelStep.mjs), not to the screen before.
83
+ const modal = useMenuLayout().expanded !== 'standard';
84
+ const step = useRef<ReturnType<typeof levelStep> | null>(null);
85
+ useEffect(() => {
86
+ step.current = levelStep(window);
87
+ return () => step.current?.stop();
88
+ }, []);
89
+ useEffect(() => {
90
+ step.current?.set(modal && open && shown !== null, () => {
91
+ setFocus('top');
92
+ setShown(null);
93
+ });
94
+ }, [modal, open, shown]);
79
95
  // Every level stays in the page (the screen check finds the screens from the links); the ones not shown are `hidden`.
80
96
  const sections = tree.filter((entry) => entry.href === undefined);
81
97
  return (
@@ -125,8 +141,12 @@ export function MainMenu({ route, files, user }: { route: string; files: RepoFil
125
141
  {section.items.map(({ id, label, href, count, children }) => {
126
142
  const here = place.section === section.id && place.item === id;
127
143
  const shownCount = files ? count : null;
128
- // An app's row has the app's icon (an installed app is a row of Apps, lib/menu.mjs).
129
- const icon = (section.id === 'apps' && apps.find((a) => a.id === id)?.icon) || icons[id];
144
+ // An app's row has the app's icon (an installed app is a row of Apps, lib/menu.mjs), a part of the business its
145
+ // own (a part is a row of Business).
146
+ const icon =
147
+ (section.id === 'apps' && apps.find((a) => a.id === id)?.icon) ||
148
+ (section.id === 'company' && companyParts.find((p) => p.id === id)?.icon) ||
149
+ icons[id];
130
150
  return children ? (
131
151
  <MainDrawerFold key={id} href={href} icon={icon} label={label} count={shownCount} selected={here && !place.child} open={here}>
132
152
  {children.map((child) => (
@@ -0,0 +1,15 @@
1
+ // The arrows that move a list's row up and down: two icon buttons, the first disabled at the top and the last at the
2
+ // bottom. Exposes MoveButtons. Uses IconButton of ui.tsx; the move itself is movedList (moveItem.mjs).
3
+ import { ArrowDown, ArrowUp } from '@phosphor-icons/react';
4
+ import { t } from './i18n';
5
+ import { IconButton } from './ui';
6
+
7
+ /** `index`: the row's place in the list of `length` rows; `onMove`: moves the row to the place given. */
8
+ export function MoveButtons({ index, length, onMove }: { index: number; length: number; onMove: (to: number) => void }) {
9
+ return (
10
+ <>
11
+ <IconButton icon={ArrowUp} label={t.common.moveUp} disabled={index === 0} onClick={() => onMove(index - 1)} />
12
+ <IconButton icon={ArrowDown} label={t.common.moveDown} disabled={index === length - 1} onClick={() => onMove(index + 1)} />
13
+ </>
14
+ );
15
+ }
@@ -0,0 +1,67 @@
1
+ // The search row of a store screen (apps or themes): search field, sort, filter dialog and a chip for each filter picked.
2
+ // Exposes StoreSearchRow and useStateFilter (the installed / not installed filter); uses SearchRow, Filters, InputChip (ui.tsx), storeSort.tsx.
3
+ import type { ComponentProps } from 'react';
4
+ import { Filters, InputChip, SearchRow, useKept } from './ui';
5
+ import { sortChoice, type Sort } from './storeSort';
6
+ import { t } from './i18n';
7
+
8
+ type Group = ComponentProps<typeof Filters>['groups'][number];
9
+ export type StoreChip = { key: string; label: string; clear: () => void };
10
+
11
+ /** The filter by whether it is installed, kept in this browser (under `prefix`): its value, its group for the filter dialog and its chip. */
12
+ export function useStateFilter(prefix: string) {
13
+ const [state, setState] = useKept<'' | 'installed' | 'notInstalled'>(`${prefix}-status`, '');
14
+ const group: Group = {
15
+ title: t.apps.stateFilter,
16
+ value: state,
17
+ options: [
18
+ { value: '', label: t.apps.allStates },
19
+ { value: 'installed', label: t.apps.installed },
20
+ { value: 'notInstalled', label: t.apps.notInstalled },
21
+ ],
22
+ onChange: (v: string) => setState(v as typeof state),
23
+ };
24
+ const chip: StoreChip | '' = state && { key: 'state', label: t.apps[state], clear: () => setState('') };
25
+ return { state, group, chip };
26
+ }
27
+
28
+ export function StoreSearchRow({
29
+ query,
30
+ onQuery,
31
+ label,
32
+ sort,
33
+ pickSort,
34
+ groups,
35
+ chips,
36
+ }: {
37
+ query: string;
38
+ onQuery: (next: string) => void;
39
+ label: string;
40
+ sort: Sort;
41
+ pickSort: (next: Sort) => void;
42
+ groups: Group[];
43
+ chips: (StoreChip | '' | false)[];
44
+ }) {
45
+ const shown = chips.filter((c) => !!c);
46
+ return (
47
+ <>
48
+ <SearchRow
49
+ value={query}
50
+ onChange={onQuery}
51
+ label={label}
52
+ sort={sortChoice(sort, pickSort)}
53
+ filter={<Filters title={t.library.filter} selected={shown.length > 0} groups={groups} />}
54
+ className="mb-6"
55
+ />
56
+ {shown.length > 0 && (
57
+ <div className="-mt-2 mb-6 flex flex-wrap gap-2">
58
+ {shown.map((c) => (
59
+ <InputChip key={c.key} removeLabel={t.library.removeFilter(c.label)} onRemove={c.clear}>
60
+ {c.label}
61
+ </InputChip>
62
+ ))}
63
+ </div>
64
+ )}
65
+ </>
66
+ );
67
+ }
@@ -0,0 +1,67 @@
1
+ // What a store screen (apps or themes) shows around its list: StoreRound (draws it again after connecting), StoreNotice (connect, loading or failed note) and StoreFooter (the connected row).
2
+ // Exposes StoreRound, useStoreKey, useStoreConnected, StoreNotice, StoreFooter; uses StoreConnectNotice, StoreConnectedRow, storeConnection.ts and env.store.connected.
3
+ import { Fragment, useEffect, useState, type ReactNode } from 'react';
4
+ import { EmptyNote } from './ui';
5
+ import type { Env } from './App';
6
+ import { StoreConnectNotice } from './StoreConnectNotice';
7
+ import { StoreConnectedRow } from './StoreConnectedRow';
8
+ import { connection, type StoreConnection } from './storeConnection';
9
+ import { t } from './i18n';
10
+
11
+ /** Connecting or disconnecting draws the screen again from the start, so the catalogs and the key are asked again. */
12
+ export function StoreRound({ children }: { children: (again: () => void) => ReactNode }) {
13
+ const [round, setRound] = useState(0);
14
+ return <Fragment key={round}>{children(() => setRound((r) => r + 1))}</Fragment>;
15
+ }
16
+
17
+ /** The store key's state (storeConnection.ts); null while it is read. */
18
+ export function useStoreKey(): StoreConnection | null {
19
+ const [key, setKey] = useState<StoreConnection | null>(null);
20
+ useEffect(() => {
21
+ connection().then(setKey, () => {});
22
+ }, []);
23
+ return key;
24
+ }
25
+
26
+ /** Whether the site's Worker has a store key (store.ts storeConnected): null while it is not known; a catalog that could
27
+ * not be read counts as connected (the list says it failed). */
28
+ export function useStoreConnected(env: Env): boolean | null {
29
+ const [connected, setConnected] = useState<boolean | null>(null);
30
+ useEffect(() => {
31
+ let on = true;
32
+ env.store.connected().then(
33
+ (yes) => on && setConnected(yes),
34
+ () => on && setConnected(true),
35
+ );
36
+ return () => {
37
+ on = false;
38
+ };
39
+ }, []);
40
+ return connected;
41
+ }
42
+
43
+ /** The note above a store list: connect to the store, loading, or failed; nothing when the list is read. `read`: the
44
+ * catalog of the list. */
45
+ export function StoreNotice({
46
+ connected,
47
+ read,
48
+ mayChange,
49
+ again,
50
+ }: {
51
+ connected: boolean | null;
52
+ read: unknown;
53
+ mayChange: boolean;
54
+ again: () => void;
55
+ }) {
56
+ if (connected === false) return <StoreConnectNotice mayChange={mayChange} onConnected={again} />;
57
+ if (read === null || connected === null) return <EmptyNote busy>{t.apps.loadingStore}</EmptyNote>;
58
+ if (read === 'failed') return <EmptyNote>{t.apps.storeFailed}</EmptyNote>;
59
+ return null;
60
+ }
61
+
62
+ /** The row at the end of a store list that says the site is connected, with its button to disconnect. */
63
+ export function StoreFooter({ keyInfo, again }: { keyInfo: StoreConnection | null; again: () => void }) {
64
+ return keyInfo?.connected && keyInfo.by === 'button' && keyInfo.mayChange ? (
65
+ <StoreConnectedRow site={keyInfo.site} onDisconnected={again} />
66
+ ) : null;
67
+ }