@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,6 +1,6 @@
1
1
  import { strict as assert } from 'node:assert';
2
2
  import { test } from 'node:test';
3
- import { socialOf, shareLinks, sameAsOf } from './social.mjs';
3
+ import { socialOf, shareLinks, sameAsOf, networkOf, upgradeSocial, addressKey, twiceIn } from './social.mjs';
4
4
 
5
5
  test('no file', () => {
6
6
  assert.deepEqual(socialOf(undefined), { profiles: [], share: ['facebook', 'x', 'linkedin', 'pinterest', 'copy-link'] });
@@ -11,18 +11,74 @@ test('empty object', () => {
11
11
  });
12
12
 
13
13
  test('empty profiles are dropped', () => {
14
- assert.deepEqual(socialOf({ facebook: '', x: ' ', linkedin: ' https://linkedin.com/in/a ' }).profiles, [
14
+ assert.deepEqual(socialOf({ profiles: [{ url: '' }, { url: ' ' }, { url: ' https://linkedin.com/in/a ' }, {}] }).profiles, [
15
15
  { id: 'linkedin', url: 'https://linkedin.com/in/a' },
16
16
  ]);
17
17
  });
18
18
 
19
- test('profiles keep a fixed order', () => {
19
+ test('profiles keep their order, and one not known has no network', () => {
20
20
  assert.deepEqual(
21
- socialOf({ pinterest: 'https://p', facebook: 'https://f' }).profiles.map((p) => p.id),
22
- ['facebook', 'pinterest'],
21
+ socialOf({ profiles: [{ url: 'https://www.pinterest.dk/a' }, { url: 'https://example.com/a' }, { url: 'https://fb.com/a' }] }).profiles,
22
+ [
23
+ { id: 'pinterest', url: 'https://www.pinterest.dk/a' },
24
+ { id: null, url: 'https://example.com/a' },
25
+ { id: 'facebook', url: 'https://fb.com/a' },
26
+ ],
23
27
  );
24
28
  });
25
29
 
30
+ test('a file from before the list: its keys are read as links', () => {
31
+ assert.deepEqual(
32
+ socialOf({ facebook: '', x: ' ', pinterest: 'https://pinterest.com/p', linkedin: ' https://linkedin.com/in/a ' }).profiles,
33
+ [
34
+ { id: 'linkedin', url: 'https://linkedin.com/in/a' },
35
+ { id: 'pinterest', url: 'https://pinterest.com/p' },
36
+ ],
37
+ );
38
+ });
39
+
40
+ test('networkOf knows a network by its host', () => {
41
+ const id = (url) => networkOf(url)?.id ?? null;
42
+ assert.equal(id('https://www.facebook.com/acme'), 'facebook');
43
+ assert.equal(id('https://fb.me/acme'), 'facebook');
44
+ assert.equal(id('https://twitter.com/acme'), 'x');
45
+ assert.equal(id('https://X.com/acme'), 'x');
46
+ assert.equal(id('https://dk.linkedin.com/company/acme'), 'linkedin');
47
+ assert.equal(id('https://pinterest.co.uk/acme'), 'pinterest');
48
+ assert.equal(id('https://www.pinterest.dk/acme'), 'pinterest');
49
+ });
50
+
51
+ test('networkOf: a network a post cannot be shared on is not known (yet)', () => {
52
+ assert.equal(networkOf('https://www.instagram.com/acme'), null);
53
+ assert.equal(networkOf('https://www.youtube.com/@acme'), null);
54
+ });
55
+
56
+ test('networkOf: a host that only looks like one, or no address', () => {
57
+ assert.equal(networkOf('https://notfacebook.com/a'), null);
58
+ assert.equal(networkOf('https://facebook.com.evil.dk/a'), null);
59
+ assert.equal(networkOf('https://example.com'), null);
60
+ assert.equal(networkOf('facebook'), null);
61
+ assert.equal(networkOf(''), null);
62
+ });
63
+
64
+ test('upgradeSocial makes the old keys a list where the first was', () => {
65
+ const old = { facebook: 'https://f', instagram: '', x: 'https://x', shareFacebook: true, shareX: false };
66
+ const now = upgradeSocial(old);
67
+ assert.deepEqual(now, { profiles: [{ url: 'https://f' }, { url: 'https://x' }], shareFacebook: true, shareX: false });
68
+ assert.deepEqual(Object.keys(now), ['profiles', 'shareFacebook', 'shareX']);
69
+ });
70
+
71
+ test('upgradeSocial keeps a list and adds the old keys after it', () => {
72
+ assert.deepEqual(upgradeSocial({ profiles: [{ url: 'https://a' }], tiktok: 'https://t' }), {
73
+ profiles: [{ url: 'https://a' }, { url: 'https://t' }],
74
+ });
75
+ });
76
+
77
+ test('upgradeSocial gives back a file without the old keys as it is', () => {
78
+ const now = { profiles: [{ url: 'https://a' }], shareX: true };
79
+ assert.equal(upgradeSocial(now), now);
80
+ });
81
+
26
82
  test('a switch turns a button off', () => {
27
83
  assert.deepEqual(socialOf({ shareX: false }).share, ['facebook', 'linkedin', 'pinterest', 'copy-link']);
28
84
  });
@@ -78,3 +134,51 @@ test('sameAs keeps the order', () => {
78
134
  ['https://f', 'https://x'],
79
135
  );
80
136
  });
137
+
138
+ test('addressKey ignores the case of the host and a slash at the end', () => {
139
+ assert.equal(addressKey('https://WWW.Facebook.com/Acme/'), addressKey('https://www.facebook.com/Acme'));
140
+ assert.equal(addressKey('https://a.dk/'), addressKey('https://a.dk'));
141
+ assert.notEqual(addressKey('https://a.dk/Acme'), addressKey('https://a.dk/acme'));
142
+ assert.equal(addressKey(' nonsense/ '), 'nonsense');
143
+ });
144
+
145
+ test('upgradeSocial does not add an address the list has', () => {
146
+ const A = 'https://facebook.com/acme';
147
+ assert.deepEqual(upgradeSocial({ profiles: [{ url: A }], facebook: A }).profiles, [{ url: A }]);
148
+ assert.deepEqual(upgradeSocial({ profiles: [{ url: A }], facebook: 'https://FACEBOOK.com/acme/' }).profiles, [{ url: A }]);
149
+ });
150
+
151
+ test('upgradeSocial adds an address of the keys once', () => {
152
+ assert.deepEqual(upgradeSocial({ facebook: 'https://a.dk/x', x: 'https://a.dk/x/' }).profiles, [{ url: 'https://a.dk/x' }]);
153
+ });
154
+
155
+ test('twiceIn gives the addresses a list has more than once', () => {
156
+ assert.deepEqual(twiceIn([{ url: 'https://a.dk/x' }, { url: 'https://b.dk' }, { url: 'https://A.dk/x/' }]), ['https://A.dk/x/']);
157
+ assert.deepEqual(twiceIn([{ url: 'https://a.dk' }, { url: 'https://b.dk' }, { url: '' }, { url: '' }, {}]), []);
158
+ assert.deepEqual(twiceIn([]), []);
159
+ });
160
+
161
+ test('networkOf knows Pinterest on its own domains only', () => {
162
+ for (const host of ['pinterest.com', 'pinterest.dk', 'www.pinterest.co.uk', 'dk.pinterest.com', 'pinterest.com.au']) {
163
+ assert.equal(networkOf(`https://${host}/a`)?.id, 'pinterest', host);
164
+ }
165
+ for (const host of ['pinterest.evil.com', 'pinterest.evil.co.uk', 'notpinterest.com', 'pinterest.com.evil.com', 'pinterest.dk.evil.io']) {
166
+ assert.equal(networkOf(`https://${host}/a`), null, host);
167
+ }
168
+ });
169
+
170
+ test('socialOf keeps only https:// addresses', () => {
171
+ assert.deepEqual(
172
+ socialOf({
173
+ profiles: [
174
+ { url: 'javascript:alert(1)' },
175
+ { url: 'http://a.dk' },
176
+ { url: 'ftp://a.dk' },
177
+ { url: 'a.dk' },
178
+ { url: ' HTTPS://b.dk/x ' },
179
+ ],
180
+ }).profiles,
181
+ [{ id: null, url: 'HTTPS://b.dk/x' }],
182
+ );
183
+ assert.deepEqual(socialOf({ facebook: 'http://facebook.com/a' }).profiles, []);
184
+ });
package/src/App.tsx CHANGED
@@ -4,11 +4,12 @@
4
4
  // list/<id> the list of a part, e.g. list/priser, and list/<id>/<app> a tab an installed app adds to it
5
5
  // (AppDefinition.tabs): list/cookies/cookiescanner
6
6
  // lists the short lists (the testimonials, the apps' lists)
7
- // settings/appstore the app store, its apps, and settings/appstore/themes its themes (AppList.tsx StorePage); the
7
+ // settings/appstore the app store, its apps (AppList.tsx StorePage); the
8
8
  // other settings are screens of their own, in the drawer's last section (MainMenu.tsx)
9
9
  // new/<id> a new entry, new/<id>/<kind> one of a kind (a pop-up: standard, or an app's)
10
10
  // company the business, and company/<part> its parts: contact, payment; and
11
11
  // company/payment/<part> its own parts: mobilepay, bank
12
+ // company/logo the logo and icon (BrandForm.tsx), the first part of the business (Library.tsx Company)
12
13
  // <screen> a screen with parts of the site's own (partScreens), and <screen>/<part> its parts:
13
14
  // privacy/cookie-banner, privacy/privacy-pages, or one of the editor's own screens (Part.opens):
14
15
  // privacy/consents the visitors' answers in the cookie banner (Consents.tsx); and the settings of the apps installed with
@@ -18,14 +19,14 @@
18
19
  // (Redirects.tsx): seo/redirects/all the redirects, and seo/redirects/not-found
19
20
  // the addresses visitors came to that do not exist; seo/rating the SEO rating of every page and
20
21
  // post (SeoScores.tsx); and seo/<part> the site's own (seoParts)
21
- // appearance how the site looks (Library.tsx Theme): appearance/themes the themes installed (Themes) and appearance/themes/<theme>
22
+ // appearance how the site looks (Library.tsx Theme): appearance/theme-store the store's themes (ThemeStoreScreen.tsx), appearance/themes the themes installed (Themes) and appearance/themes/<theme>
22
23
  // a theme's page, with the button that swaps to it (ThemePage), appearance/icon-packs the icon packs (IconPacks),
23
24
  // appearance/motion how it moves (MotionSchemes), appearance/side-column the block beside the pages' text (SideColumn),
24
25
  // appearance/header the header's menus and settings with its preview (HeaderSettings.tsx; once at header),
25
26
  // appearance/footer the footer's texts and links with its preview (FooterSettings.tsx; once at src/data/footer.json),
26
27
  // appearance/colors the colours (Colors.tsx;
27
- // appearance/colors/fallback-colors the site's own while an app changes the pages'), appearance/logo the logo
28
- // and icon (BrandForm.tsx), appearance/parts the parts (Library.tsx PartsHome): appearance/parts/editor the editor's, every
28
+ // appearance/colors/fallback-colors the site's own while an app changes the pages'),
29
+ // appearance/parts the parts (Library.tsx PartsHome): appearance/parts/editor the editor's, every
29
30
  // one in every state (Parts.tsx), appearance/parts/ui the theme's UI components, appearance/parts/blocks the
30
31
  // blocks, the standard ones and the apps', and appearance/parts/list/<list> each kind of a list of kinds
31
32
  // ("Promovering"), its own and the apps' (BlockParts.tsx), and appearance/parts/values the
@@ -100,6 +101,7 @@ import Advanced, { ADVANCED_ROUTE } from './Advanced';
100
101
  import CmsPage, { CMS_ROUTE } from './CmsPage';
101
102
  import Licenses, { LICENSES_ROUTE, LicensePage } from './Licenses';
102
103
  import { StoreThemePage } from './ThemeStore';
104
+ import { ThemeStoreScreen } from './ThemeStoreScreen';
103
105
  import {
104
106
  AppPage,
105
107
  AppScreenPage,
@@ -176,6 +178,7 @@ import { appType, clearNotifications, isOn, remember, signOff, stopServerWait, s
176
178
  import Notifications from './Notifications';
177
179
  import { openNotifications } from './notificationsOpen';
178
180
  import { EditorOwn, InEditor } from './standard/view';
181
+ import { cmsNotice } from './cmsNotice.mjs';
179
182
  import './editor.css';
180
183
 
181
184
  // What the forms and lists need from the app.
@@ -648,6 +651,25 @@ function Editor() {
648
651
  return () => clearInterval(timer);
649
652
  }, [signedIn, notifying]);
650
653
 
654
+ // The CMS's own update from npm (worker/cms-update.js): asked when the editor opens and every 15 minutes; its outcome
655
+ // comes once under "Notifikationer"; the Worker already sent it to the phone.
656
+ useEffect(() => {
657
+ if (!signedIn) return;
658
+ const ask = () =>
659
+ fetch('/api/cms', { cache: 'no-store' })
660
+ .then((res) => (res.ok ? res.json() : null))
661
+ .then((status) => {
662
+ const n = cmsNotice(status?.update);
663
+ if (!n || told('updates', n.id) || !isOn('updates')) return;
664
+ const text = t.cms[n.key](n.version);
665
+ remember({ text, type: 'updates', error: n.error, link: { text: t.common.parts.morpheme, href: `#${CMS_ROUTE}` } }, false);
666
+ })
667
+ .catch(() => {});
668
+ ask();
669
+ const timer = setInterval(ask, 15 * 60_000);
670
+ return () => clearInterval(timer);
671
+ }, [signedIn]);
672
+
651
673
  // Signed out, or not yet known with nothing from this browser to show: the sign-in (while the Worker is asked, the
652
674
  // icon and the name alone).
653
675
  if (signedIn === false || (signedIn === null && !files)) {
@@ -760,15 +782,15 @@ function Page({ route, files, env, user, builtAt, onLogout }: PageProps) {
760
782
  // The colours, or the site's own on a page of the same form while an app changes the pages' (FALLBACK_ROUTE).
761
783
  if (route === 'appearance/colors' || route === FALLBACK_ROUTE)
762
784
  return <Colors env={env} files={files} fallback={route === FALLBACK_ROUTE} />;
763
- if (route === 'appearance/logo') return <BrandForm env={env} />;
785
+ if (route === 'company/logo') return <BrandForm env={env} />;
764
786
  if (route === 'block-settings') return <BlockSettings env={env} files={files} />;
765
787
  if (route === ADVANCED_ROUTE) return <Advanced env={env} />;
766
788
  if (route === CMS_ROUTE) return <CmsPage />;
767
789
  if (route === LICENSES_ROUTE) return <Licenses />;
768
790
  if (route.startsWith(`${LICENSES_ROUTE}/`)) return <LicensePage key={route} id={route.slice(LICENSES_ROUTE.length + 1)} />;
769
791
  if (route === 'apps') return <Apps env={env} files={files} />;
770
- if (route === STORE_ROUTE) return <StorePage env={env} files={files} tab="apps" />;
771
- if (route === STORE_THEMES) return <StorePage env={env} files={files} tab="themes" />;
792
+ if (route === STORE_ROUTE) return <StorePage env={env} files={files} />;
793
+ if (route === STORE_THEMES) return <ThemeStoreScreen env={env} />;
772
794
  if (route.startsWith(`${DEVELOPER_ROUTE}/`))
773
795
  return <DeveloperPage key={route} slug={route.slice(DEVELOPER_ROUTE.length + 1)} env={env} files={files} />;
774
796
  // An app in the site (its own, or one from the store while it is installed) has its page, with the tabs Settings
package/src/AppList.tsx CHANGED
@@ -3,7 +3,8 @@
3
3
  // that it has a newer version, with search (by name, who made it and what it does), the order (A–Å, Å–A, kept in this
4
4
  // browser) and headings by the first letter, as the lists under "Indhold" have. "Indstillinger" › "Appstore"
5
5
  // (#settings/appstore): all apps, those in the app store (store.ts) and the site's own, installed or not, with search (by name, what they
6
- // do, who made them and the words they are found by), the same order and a funnel by category. An app's page
6
+ // do, who made them and the words they are found by), the same order and a funnel by category (only apps: the themes are in "Theme store", ThemeStoreScreen.tsx; the search row and the
7
+ // store notices both screens share are StoreSearchRow.tsx, StoreStatus.tsx and storeSort.tsx). An app's page
7
8
  // (#apps/<app>) is the same for every app and without examples: its name, who made it, whether it is installed, its
8
9
  // version (from the store) and what it does, "Installer" (or "Opdater til …"); installed, it has two tabs: "Indstillinger"
9
10
  // (#apps/<app>: its settings form, saved with "Gem ændringer" in their file, config.apps.settings, also on the screen
@@ -23,22 +24,9 @@
23
24
  // use (one of its blocks on a page, an entry of its kind or in its list) cannot be uninstalled, as a block on a page
24
25
  // cannot be turned off; its page says where it is used, so uninstalling never changes the site.
25
26
  import { useEffect, useState, type ReactNode } from 'react';
26
- import { ArrowsDownUp, Gear, Info, PuzzlePiece, Swatches, UserCircle, type Icon } from '@phosphor-icons/react';
27
+ import { Gear, Info, UserCircle, type Icon } from '@phosphor-icons/react';
27
28
  import Screen from './Screen';
28
- import {
29
- Button,
30
- InputChip,
31
- Choice,
32
- EmptyNote,
33
- Filters,
34
- Group,
35
- LeadingIcon,
36
- SupportingText,
37
- SearchRow,
38
- useKept,
39
- ListItem,
40
- type TabChoice,
41
- } from './ui';
29
+ import { Button, EmptyNote, Group, LeadingIcon, SupportingText, SearchRow, useKept, ListItem, type TabChoice } from './ui';
42
30
  import { pagesWith } from './BlockSettings';
43
31
  import { ConflictError, type Change, type RepoFile } from './github';
44
32
  import { cookieChanges, inCookieList } from './cookieList';
@@ -49,11 +37,6 @@ import { AnyIcon } from './icon';
49
37
  import {
50
38
  appCategories,
51
39
  appChanges,
52
- appliedTo,
53
- installedHere,
54
- legacyOf,
55
- mergeChanges,
56
- moveChanges,
57
40
  appFolder,
58
41
  breaking,
59
42
  changedFiles,
@@ -62,24 +45,23 @@ import {
62
45
  DEVELOPER_ROUTE,
63
46
  newer,
64
47
  STORE_ROUTE,
65
- STORE_THEMES,
66
48
  type AppCategory,
67
49
  type AppCookie,
68
50
  type ShownApp,
69
51
  type StoreAdd,
70
52
  type StoreRecord,
71
53
  } from './store';
72
- import { apps, apps as siteApps, siteBlocks } from './registry';
54
+ import { apps, siteBlocks } from './registry';
73
55
  import { asWritten, backFrom, collections, companyParts, partScreens } from './site';
74
56
  import { byText, slugify, type Part } from './schema';
75
57
  import { headed, letterOf } from './Sheet';
76
58
  import { config } from '@site/editor';
77
- import { allThemes, ThemeRow, themeInstalled, useThemeCatalog } from './ThemeStore';
59
+ import { allThemes, ThemeRow, useThemeCatalog } from './ThemeStore';
78
60
  import { siteT, siteText, t } from './i18n';
79
61
  import { OwnerLicenses, StoreLicenseRows } from './Licenses';
80
- import { StoreConnectNotice } from './StoreConnectNotice';
81
- import { StoreConnectedRow } from './StoreConnectedRow';
82
- import { connection, type StoreConnection } from './storeConnection';
62
+ import { StoreFooter, StoreNotice, StoreRound, useStoreConnected, useStoreKey } from './StoreStatus';
63
+ import { StoreSearchRow, useStateFilter } from './StoreSearchRow';
64
+ import { sortChoice, useSort } from './storeSort';
83
65
  import { told } from './notificationData';
84
66
  import { kindAndName } from './deploy';
85
67
  import AppInfoTab from './AppInfoTab';
@@ -203,39 +185,6 @@ export function kindsOf(app: SiteApp) {
203
185
 
204
186
  const statusOf = (installed: boolean) => (installed ? t.apps.installed : t.apps.notInstalled);
205
187
 
206
- type Sort = 'az' | 'za';
207
- const SORTS: Sort[] = ['az', 'za'];
208
- // The order picked last time, in this browser (the same for the apps and the store).
209
- const SORT_KEY = 'editor-sort-apps';
210
-
211
- /** The order of a list of apps, A–Å or Å–A, kept in this browser. */
212
- function useSort(): [Sort, (next: Sort) => void] {
213
- const [sort, setSort] = useState<Sort>(() => {
214
- try {
215
- const saved = localStorage.getItem(SORT_KEY);
216
- if (SORTS.some((s) => s === saved)) return saved as Sort;
217
- } catch {}
218
- return 'az';
219
- });
220
- function pickSort(next: Sort) {
221
- setSort(next);
222
- try {
223
- localStorage.setItem(SORT_KEY, next);
224
- } catch {}
225
- }
226
- return [sort, pickSort];
227
- }
228
-
229
- const sortChoice = (sort: Sort, pickSort: (next: Sort) => void) => (
230
- <Choice
231
- title={t.library.sort}
232
- icon={ArrowsDownUp}
233
- value={sort}
234
- options={SORTS.map((value) => ({ value, label: t.library.sorts[value] }))}
235
- onChange={pickSort}
236
- />
237
- );
238
-
239
188
  /** The store's catalog (store.ts) for a screen: null while it is read, 'failed' when it could not be; `skip`: not read
240
189
  * (the page of one of the site's own apps). */
241
190
  function useCatalog(env: Env, skip = false): ShownApp[] | null | 'failed' {
@@ -254,23 +203,6 @@ function useCatalog(env: Env, skip = false): ShownApp[] | null | 'failed' {
254
203
  return catalog;
255
204
  }
256
205
 
257
- /** Whether the site's Worker has a store key (store.ts storeConnected): null while it is not known; a catalog that could
258
- * not be read counts as connected (the list says it failed). */
259
- function useStoreConnected(env: Env): boolean | null {
260
- const [connected, setConnected] = useState<boolean | null>(null);
261
- useEffect(() => {
262
- let on = true;
263
- env.store.connected().then(
264
- (yes) => on && setConnected(yes),
265
- () => on && setConnected(true),
266
- );
267
- return () => {
268
- on = false;
269
- };
270
- }, []);
271
- return connected;
272
- }
273
-
274
206
  // The apps updated while the editor is open, by their id, to their version: their page and the list say so until the
275
207
  // site's build has it (and the editor reloads with it, deploy.ts keepCurrent).
276
208
  const updated = new Map<string, string>();
@@ -278,7 +210,7 @@ const versionOf = (app: SiteApp) => updated.get(app.id) ?? app.store?.version ??
278
210
 
279
211
  /** The newer version of an app from the store, when the store has one. */
280
212
  const updateOf = (app: SiteApp, catalog: ShownApp[] | null | 'failed') => {
281
- const found = app.store && Array.isArray(catalog) ? catalog.find((a) => a.id === app.id || a.legacy === app.id) : undefined;
213
+ const found = app.store && Array.isArray(catalog) ? catalog.find((a) => a.id === app.id) : undefined;
282
214
  return found && newer(found.version, versionOf(app)) ? found : undefined;
283
215
  };
284
216
 
@@ -462,33 +394,23 @@ export function DeveloperRow({ name }: { name: string }) {
462
394
  );
463
395
  }
464
396
 
465
- /** "Appstore" (#settings/appstore, under "Indstillinger"): in a tab of its own each in the top app bar, all apps,
466
- * those in the app store and the site's own, each with what it does and whether it is installed, and all themes
467
- * (#settings/appstore/themes, ThemeStore.tsx), those in the store
468
- * and those installed, each with its version and who made it; each opening its page. With search (by name, what it
469
- * does, who made it and the words it is found by, in both languages), the order and the filters by category (apps)
470
- * and by whether it is installed, each picked one as a chip. */
471
- export function StorePage(props: { env: Env; files: RepoFile[]; tab: 'apps' | 'themes' }) {
472
- // Connecting or disconnecting draws the screen again from the start, so the catalogs and the key are asked again.
473
- const [round, setRound] = useState(0);
474
- return <StoreScreen key={round} {...props} again={() => setRound((r) => r + 1)} />;
397
+ /** "Appstore" (#settings/appstore, under "Indstillinger"): all apps, those in the app store and the site's own, each
398
+ * with what it does and whether it is installed, opening its page (the themes are in "Theme store", ThemeStore.tsx).
399
+ * With search (by name, what it does, who made it and the words it is found by, in both languages), the order and the
400
+ * filters by category and by whether it is installed, each picked one as a chip. */
401
+ export function StorePage({ env, files }: { env: Env; files: RepoFile[] }) {
402
+ return <StoreRound>{(again) => <StoreScreen env={env} files={files} again={again} />}</StoreRound>;
475
403
  }
476
404
 
477
- function StoreScreen({ env, files, tab, again }: { env: Env; files: RepoFile[]; tab: 'apps' | 'themes'; again: () => void }) {
405
+ function StoreScreen({ env, files, again }: { env: Env; files: RepoFile[]; again: () => void }) {
478
406
  const installed = installedApps(files);
479
- const [key, setKey] = useState<StoreConnection | null>(null);
480
- useEffect(() => {
481
- connection().then(setKey, () => {});
482
- }, []);
407
+ const key = useStoreKey();
483
408
  const catalog = useCatalog(env);
484
- const themeCatalog = useThemeCatalog(env);
485
409
  const connected = useStoreConnected(env);
486
410
  const [query, setQuery] = useKept('store-search', '');
487
411
  const [sort, pickSort] = useSort();
488
412
  const [category, setCategory] = useKept<AppCategory | ''>('store-category', '');
489
- const [state, setState] = useKept<'' | 'installed' | 'notInstalled'>('store-status', '');
490
- const apps = tab === 'apps';
491
- const read = apps ? catalog : themeCatalog;
413
+ const stateFilter = useStateFilter('store');
492
414
 
493
415
  const words = query.toLowerCase().split(/\s+/).filter(Boolean);
494
416
  const order = (a: string, b: string) => (sort === 'za' ? -1 : 1) * byText(a, b);
@@ -496,92 +418,34 @@ function StoreScreen({ env, files, tab, again }: { env: Env; files: RepoFile[];
496
418
  allApps(catalog)
497
419
  .filter((a) => words.every((w) => a.words.includes(w)))
498
420
  .filter((a) => !category || a.category === category)
499
- .filter((a) => !state || installedHere(a, installed, siteApps) === (state === 'installed'))
421
+ .filter((a) => !stateFilter.state || installed.includes(a.id) === (stateFilter.state === 'installed'))
500
422
  .sort((a, b) => order(a.label, b.label)),
501
423
  (a) => letterOf(a.label),
502
424
  );
503
- const themeGroups = headed(
504
- allThemes(themeCatalog)
505
- .filter((x) => words.every((w) => x.words.includes(w)))
506
- .filter((x) => !state || themeInstalled(x.id) === (state === 'installed'))
507
- .sort((a, b) => order(a.name, b.name)),
508
- (x) => letterOf(x.name),
509
- );
510
- const filters = [
511
- ...(apps
512
- ? [
513
- {
514
- title: t.apps.categoryFilter,
515
- value: category,
516
- options: [
517
- { value: '', label: t.apps.allCategories },
518
- ...appCategories.map((value) => ({ value, label: t.apps.categories[value] })),
519
- ],
520
- onChange: (v: string) => setCategory(v as AppCategory | ''),
521
- },
522
- ]
523
- : []),
524
- {
525
- title: t.apps.stateFilter,
526
- value: state,
527
- options: [
528
- { value: '', label: t.apps.allStates },
529
- { value: 'installed', label: t.apps.installed },
530
- { value: 'notInstalled', label: t.apps.notInstalled },
531
- ],
532
- onChange: (v: string) => setState(v as typeof state),
533
- },
534
- ];
535
- // Each filter picked, as a chip that removes it.
536
- const chips = [
537
- apps && category && { key: 'category', label: t.apps.categories[category], clear: () => setCategory('') },
538
- state && { key: 'state', label: t.apps[state], clear: () => setState('') },
539
- ].filter((c) => !!c);
540
- const empty = apps ? !appGroups.length : !themeGroups.length;
425
+ const categoryGroup = {
426
+ title: t.apps.categoryFilter,
427
+ value: category,
428
+ options: [{ value: '', label: t.apps.allCategories }, ...appCategories.map((value) => ({ value, label: t.apps.categories[value] }))],
429
+ onChange: (v: string) => setCategory(v as AppCategory | ''),
430
+ };
431
+ const categoryChip = category && { key: 'category', label: t.apps.categories[category], clear: () => setCategory('') };
541
432
 
542
433
  return (
543
- <Screen
544
- title={t.apps.find}
545
- wide
546
- back={backFrom('appstore')}
547
- tabs={{
548
- label: t.apps.find,
549
- value: tab,
550
- options: [
551
- { value: 'apps', label: t.common.parts.apps, icon: PuzzlePiece },
552
- { value: 'themes', label: t.common.parts.themes, icon: Swatches },
553
- ],
554
- onChange: (v) => (location.hash = v === 'apps' ? STORE_ROUTE : STORE_THEMES),
555
- }}
556
- >
557
- <SearchRow
558
- value={query}
559
- onChange={setQuery}
560
- label={apps ? t.apps.searchStore : t.library.searchThemes}
561
- sort={sortChoice(sort, pickSort)}
562
- filter={<Filters title={t.library.filter} selected={chips.length > 0} groups={filters} />}
563
- className="mb-6"
434
+ <Screen title={t.apps.find} wide back={backFrom('appstore')}>
435
+ <StoreSearchRow
436
+ query={query}
437
+ onQuery={setQuery}
438
+ label={t.apps.searchStore}
439
+ sort={sort}
440
+ pickSort={pickSort}
441
+ groups={[categoryGroup, stateFilter.group]}
442
+ chips={[categoryChip, stateFilter.chip]}
564
443
  />
565
- {chips.length > 0 && (
566
- <div className="-mt-2 mb-6 flex flex-wrap gap-2">
567
- {chips.map((c) => (
568
- <InputChip key={c.key} removeLabel={t.library.removeFilter(c.label)} onRemove={c.clear}>
569
- {c.label}
570
- </InputChip>
571
- ))}
572
- </div>
573
- )}
574
444
  {/* The site's own are shown also when the store cannot be read. */}
575
- {connected === false ? (
576
- <StoreConnectNotice mayChange={key?.mayChange ?? false} onConnected={again} />
577
- ) : read === null || connected === null ? (
578
- <EmptyNote busy>{t.apps.loadingStore}</EmptyNote>
579
- ) : read === 'failed' ? (
580
- <EmptyNote>{t.apps.storeFailed}</EmptyNote>
581
- ) : null}
582
- {read === null ? null : empty ? (
445
+ <StoreNotice connected={connected} read={catalog} mayChange={key?.mayChange ?? false} again={again} />
446
+ {catalog === null ? null : !appGroups.length ? (
583
447
  <p className="mb-8 px-1 text-muted">{t.common.noMatch}</p>
584
- ) : apps ? (
448
+ ) : (
585
449
  appGroups.map((g) => (
586
450
  <Group key={g.key ?? 'all'} title={g.key ?? undefined}>
587
451
  {g.items.map((a) => (
@@ -589,16 +453,8 @@ function StoreScreen({ env, files, tab, again }: { env: Env; files: RepoFile[];
589
453
  ))}
590
454
  </Group>
591
455
  ))
592
- ) : (
593
- themeGroups.map((g) => (
594
- <Group key={g.key ?? 'all'} title={g.key ?? undefined}>
595
- {g.items.map((x) => (
596
- <ThemeRow key={x.id} of={x} />
597
- ))}
598
- </Group>
599
- ))
600
456
  )}
601
- {key?.connected && key.by === 'button' && key.mayChange && <StoreConnectedRow site={key.site} onDisconnected={again} />}
457
+ <StoreFooter keyInfo={key} again={again} />
602
458
  </Screen>
603
459
  );
604
460
  }
@@ -697,13 +553,11 @@ function useStoreActions(env: Env, files: RepoFile[]) {
697
553
  next: () => Promise<Parameters<typeof appChanges>[2]>,
698
554
  // Whether to go on, with the app's files in the site now (an update asks, when some were changed).
699
555
  go: (current: RepoFile[]) => Promise<boolean> = async () => true,
700
- // The id the app is installed under, when it is a legacy copy that moves to `id` (moveChanges).
701
- legacy: string | null = null,
702
556
  ): Promise<boolean> {
703
557
  setRunning({ id, action, asking: false });
704
558
  env.notify({ text: text.busy });
705
559
  try {
706
- const [current, wanted] = await Promise.all([env.folder(appFolder(legacy ?? id)), next()]);
560
+ const [current, wanted] = await Promise.all([env.folder(appFolder(id)), next()]);
707
561
  if (!(await go(current))) {
708
562
  env.notify(null);
709
563
  return false;
@@ -711,11 +565,8 @@ function useStoreActions(env: Env, files: RepoFile[]) {
711
565
  // `go` cleared the message (and its dialog stopped the button being busy): saving goes on.
712
566
  setRunning({ id, action, asking: false });
713
567
  env.notify({ text: text.busy });
714
- const moved = legacy && wanted ? moveChanges({ id }, legacy, wanted, current, files) : null;
715
- // The cookie list as the move leaves it (the legacy id rewritten), then the new release's cookies on it: one set of changes.
716
- const cookies = cookieChanges(id, wanted ? cookiesIn(wanted.files) : null, moved ? appliedTo(files, moved) : files);
717
- const changes = moved ? mergeChanges(moved, cookies) : [...appChanges(id, current, wanted, installed, file), ...cookies];
718
- await saveApp(env, text.commit, text.change, changes, file);
568
+ const cookies = cookieChanges(id, wanted ? cookiesIn(wanted.files) : null, files);
569
+ await saveApp(env, text.commit, text.change, [...appChanges(id, current, wanted, installed, file), ...cookies], file);
719
570
  env.notify({ text: text.done, kind: text.kind ?? 'saved' });
720
571
  return true;
721
572
  } catch (e) {
@@ -741,7 +592,7 @@ function useStoreActions(env: Env, files: RepoFile[]) {
741
592
  },
742
593
  async () => ({ files: await env.store.files(app), record: recordOf(app) }),
743
594
  ),
744
- async update(app: ShownApp, record: StoreRecord, legacy: string | null = null) {
595
+ async update(app: ShownApp, record: StoreRecord) {
745
596
  const done = await change(
746
597
  app.id,
747
598
  'update',
@@ -761,10 +612,9 @@ function useStoreActions(env: Env, files: RepoFile[]) {
761
612
  record.version,
762
613
  app.version,
763
614
  notesSince(app.releaseNotes, record.version, app.version),
764
- changedFiles(app.id, record, current, appFolder(legacy ?? app.id)),
615
+ changedFiles(app.id, record, current),
765
616
  );
766
617
  },
767
- legacy,
768
618
  );
769
619
  if (done) updated.set(app.id, app.version);
770
620
  return done;
@@ -1058,11 +908,7 @@ function AppContent({ app, env, files, tab, fields }: AppProps & { tab: AppTab;
1058
908
  {(!on || (update && app.store)) && (
1059
909
  <div className="mb-8">
1060
910
  {on ? (
1061
- <Button
1062
- disabled={saving}
1063
- busy={store.busy(update!.id, 'update')}
1064
- onClick={() => store.update(update!, app.store!, legacyOf(update!, apps))}
1065
- >
911
+ <Button disabled={saving} busy={store.busy(app.id, 'update')} onClick={() => store.update(update!, app.store!)}>
1066
912
  {t.apps.update(update!.version)}
1067
913
  </Button>
1068
914
  ) : (
package/src/BrandForm.tsx CHANGED
@@ -1,4 +1,4 @@
1
- // "Udseende" › "Logo og ikon" (#appearance/logo): a new logo (the mark by the site's name) and a new icon (the browser
1
+ // "Virksomheden" › "Logo og ikon" (#company/logo): a new logo (the mark by the site's name) and a new icon (the browser
2
2
  // tab, Google and the editor's app icon), made from a picture the owner picks (brand.ts), in the site's colours
3
3
  // ("Farver"). Both are saved together in one commit with "Gem ændringer".
4
4
  import { useEffect, useState } from 'react';
@@ -120,7 +120,7 @@ export default function BrandForm({ env }: { env: Env }) {
120
120
  return (
121
121
  <FormFrame
122
122
  title={t.common.parts.brand}
123
- back={{ href: '#appearance', label: t.common.parts.appearance }}
123
+ back={{ href: '#company', label: t.common.parts.company }}
124
124
  dirty={dirty}
125
125
  saving={saving || drawing}
126
126
  onSave={save}