@brimsites/brimjs 0.0.0-stage → 1.0.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.
- package/LICENSE +110 -0
- package/README.md +22 -2
- package/bin/brim.js +5 -0
- package/dist/cli.js +3802 -0
- package/editor-dist/editor.css +1 -0
- package/editor-dist/editor.js +91 -0
- package/package.json +71 -3
- package/skills/brim-convert/SKILL.md +256 -0
- package/skills/brim-hosting/SKILL.md +221 -0
- package/src/astro-shim.d.ts +5 -0
- package/src/auth/accounts.ts +341 -0
- package/src/auth/password.ts +34 -0
- package/src/auth/permissions.ts +44 -0
- package/src/blocks/accordion/Accordion.astro +48 -0
- package/src/blocks/accordion/accordion.css +63 -0
- package/src/blocks/analytics/Analytics.astro +45 -0
- package/src/blocks/analytics/ConsentBanner.astro +41 -0
- package/src/blocks/analytics/analytics.client.ts +125 -0
- package/src/blocks/analytics/analytics.css +51 -0
- package/src/blocks/analytics/consent.ts +51 -0
- package/src/blocks/button/Button.astro +64 -0
- package/src/blocks/button/button.css +100 -0
- package/src/blocks/carousel/Carousel.astro +140 -0
- package/src/blocks/carousel/carousel.client.ts +153 -0
- package/src/blocks/carousel/carousel.css +181 -0
- package/src/blocks/data/icons.ts +285 -0
- package/src/blocks/data/image-shapes.ts +91 -0
- package/src/blocks/data/social-icons.ts +41 -0
- package/src/blocks/data/social-networks.ts +256 -0
- package/src/blocks/divider/Divider.astro +27 -0
- package/src/blocks/divider/divider.css +17 -0
- package/src/blocks/form/Captcha.astro +27 -0
- package/src/blocks/form/Form.astro +250 -0
- package/src/blocks/form/FormField.astro +138 -0
- package/src/blocks/form/Newsletter.astro +80 -0
- package/src/blocks/form/form.client.ts +339 -0
- package/src/blocks/form/form.css +271 -0
- package/src/blocks/gallery/ImageGallery.astro +126 -0
- package/src/blocks/gallery/gallery.css +43 -0
- package/src/blocks/gallery/lightbox.client.ts +178 -0
- package/src/blocks/gallery/lightbox.css +134 -0
- package/src/blocks/icon/Icon.astro +41 -0
- package/src/blocks/icon/icon.css +16 -0
- package/src/blocks/image/Image.astro +158 -0
- package/src/blocks/image/image.css +42 -0
- package/src/blocks/images.ts +64 -0
- package/src/blocks/in-editor.client.ts +8 -0
- package/src/blocks/listing/Listing.astro +288 -0
- package/src/blocks/listing/ListingCards.astro +48 -0
- package/src/blocks/listing/listing.css +136 -0
- package/src/blocks/listing/query.ts +363 -0
- package/src/blocks/map/Map.astro +75 -0
- package/src/blocks/map/map.css +32 -0
- package/src/blocks/schemas/accordion.ts +118 -0
- package/src/blocks/schemas/button.ts +78 -0
- package/src/blocks/schemas/carousel.ts +133 -0
- package/src/blocks/schemas/divider.ts +29 -0
- package/src/blocks/schemas/form-field-types.ts +29 -0
- package/src/blocks/schemas/form.ts +350 -0
- package/src/blocks/schemas/icon.ts +24 -0
- package/src/blocks/schemas/image-gallery.ts +54 -0
- package/src/blocks/schemas/image.ts +87 -0
- package/src/blocks/schemas/index.ts +33 -0
- package/src/blocks/schemas/listing.ts +14 -0
- package/src/blocks/schemas/map.ts +81 -0
- package/src/blocks/schemas/newsletter.ts +324 -0
- package/src/blocks/schemas/social-media.ts +348 -0
- package/src/blocks/schemas/text.ts +151 -0
- package/src/blocks/schemas/video.ts +57 -0
- package/src/blocks/search/Search.astro +147 -0
- package/src/blocks/search/search.css +69 -0
- package/src/blocks/search/state.ts +28 -0
- package/src/blocks/settings.ts +94 -0
- package/src/blocks/social/SocialMedia.astro +102 -0
- package/src/blocks/social/social-links.ts +16 -0
- package/src/blocks/social/social.css +31 -0
- package/src/blocks/theme.ts +35 -0
- package/src/blocks/types.ts +52 -0
- package/src/blocks/video/Video.astro +90 -0
- package/src/blocks/video/video-source.ts +77 -0
- package/src/blocks/video/video.client.ts +43 -0
- package/src/blocks/video/video.css +29 -0
- package/src/check.ts +1119 -0
- package/src/cli.ts +493 -0
- package/src/components/Blocks.astro +68 -0
- package/src/components/Field.astro +61 -0
- package/src/components/Footer.astro +36 -0
- package/src/components/Link.astro +18 -0
- package/src/components/MobileMenu.astro +77 -0
- package/src/components/Navbar.astro +42 -0
- package/src/components/RichText.astro +32 -0
- package/src/components/Seo.astro +202 -0
- package/src/components/Setting.astro +46 -0
- package/src/components/Shared.astro +17 -0
- package/src/components/Text.astro +91 -0
- package/src/components/blocks.css +86 -0
- package/src/components/index.ts +27 -0
- package/src/components/mobile-menu.client.ts +21 -0
- package/src/components/mobile-menu.css +52 -0
- package/src/components/text.css +48 -0
- package/src/config.ts +413 -0
- package/src/content/block-layout.ts +63 -0
- package/src/content/block-values.ts +48 -0
- package/src/content/content-check.ts +174 -0
- package/src/content/content-types.ts +408 -0
- package/src/content/drafts.ts +115 -0
- package/src/content/feed.ts +237 -0
- package/src/content/field-types.ts +107 -0
- package/src/content/history.ts +140 -0
- package/src/content/ids.ts +50 -0
- package/src/content/image-size.ts +212 -0
- package/src/content/image-sizes.ts +126 -0
- package/src/content/item-fields.ts +110 -0
- package/src/content/item-head.ts +126 -0
- package/src/content/item-image.ts +26 -0
- package/src/content/item-path.ts +122 -0
- package/src/content/items.ts +580 -0
- package/src/content/language-scopes.ts +40 -0
- package/src/content/media.ts +271 -0
- package/src/content/menus.ts +51 -0
- package/src/content/page-templates.ts +52 -0
- package/src/content/redirects.ts +112 -0
- package/src/content/references.ts +165 -0
- package/src/content/rich-text.ts +63 -0
- package/src/content/search.ts +167 -0
- package/src/content/seed.ts +229 -0
- package/src/content/site-settings.ts +111 -0
- package/src/content/sitemap.ts +143 -0
- package/src/content/store.ts +225 -0
- package/src/content/tags.ts +67 -0
- package/src/content/text-default.ts +139 -0
- package/src/content/types.ts +137 -0
- package/src/content/validate.ts +253 -0
- package/src/content/validation-error.ts +2 -0
- package/src/db/cached.ts +140 -0
- package/src/db/database.ts +15 -0
- package/src/db/libsql.ts +29 -0
- package/src/db/schema.ts +189 -0
- package/src/db/url.ts +44 -0
- package/src/editor/client/BlockSettings.tsx +1063 -0
- package/src/editor/client/Chrome.tsx +284 -0
- package/src/editor/client/ContentBrowser.tsx +1299 -0
- package/src/editor/client/Editor.tsx +1756 -0
- package/src/editor/client/HistoryPanel.tsx +114 -0
- package/src/editor/client/ImagesWidget.tsx +113 -0
- package/src/editor/client/Inspector.tsx +127 -0
- package/src/editor/client/ItemForm.tsx +535 -0
- package/src/editor/client/LinkWidget.tsx +440 -0
- package/src/editor/client/ListingPanel.tsx +99 -0
- package/src/editor/client/Login.tsx +338 -0
- package/src/editor/client/Menu.tsx +64 -0
- package/src/editor/client/PageSettings.tsx +270 -0
- package/src/editor/client/RedirectsSettings.tsx +130 -0
- package/src/editor/client/Resize.tsx +204 -0
- package/src/editor/client/Sidebar.tsx +51 -0
- package/src/editor/client/SiteMap.tsx +568 -0
- package/src/editor/client/SiteSettings.tsx +409 -0
- package/src/editor/client/TextTools.tsx +391 -0
- package/src/editor/client/Toolbar.tsx +449 -0
- package/src/editor/client/VideoUpload.tsx +251 -0
- package/src/editor/client/api.ts +417 -0
- package/src/editor/client/brand.ts +20 -0
- package/src/editor/client/connection.ts +98 -0
- package/src/editor/client/context.ts +19 -0
- package/src/editor/client/css.d.ts +2 -0
- package/src/editor/client/editor.css +4656 -0
- package/src/editor/client/fields.tsx +812 -0
- package/src/editor/client/icons.tsx +174 -0
- package/src/editor/client/keys.ts +15 -0
- package/src/editor/client/kinds.ts +289 -0
- package/src/editor/client/languages.ts +32 -0
- package/src/editor/client/main.tsx +100 -0
- package/src/editor/client/responses.ts +26 -0
- package/src/editor/client/rich-text.ts +326 -0
- package/src/editor/client/site-tree.ts +239 -0
- package/src/editor/client/theme.ts +55 -0
- package/src/editor/client/tsconfig.json +18 -0
- package/src/editor/client/tus.ts +137 -0
- package/src/editor/client/use-rect.ts +50 -0
- package/src/editor/client/widgets.tsx +1218 -0
- package/src/forms/captcha.ts +83 -0
- package/src/forms/define.ts +166 -0
- package/src/forms/fields.ts +197 -0
- package/src/forms/file-types.ts +108 -0
- package/src/forms/files.ts +216 -0
- package/src/forms/form-page.ts +9 -0
- package/src/forms/handler.ts +622 -0
- package/src/forms/spec.ts +89 -0
- package/src/forms/store.ts +96 -0
- package/src/forms/work.ts +50 -0
- package/src/icons/library.ts +144 -0
- package/src/icons/load.ts +63 -0
- package/src/index.ts +99 -0
- package/src/init.ts +257 -0
- package/src/integration.ts +469 -0
- package/src/mail/mailer.ts +197 -0
- package/src/mail/notify.ts +272 -0
- package/src/mail/settings.ts +173 -0
- package/src/mail/templates.ts +191 -0
- package/src/mcp/page-nodes.ts +209 -0
- package/src/mcp/server.ts +111 -0
- package/src/mcp/tools.ts +637 -0
- package/src/runtime/TemplatePage.astro +39 -0
- package/src/runtime/TemplatePageStatic.astro +13 -0
- package/src/runtime/admin-route.ts +80 -0
- package/src/runtime/connect.ts +53 -0
- package/src/runtime/content.ts +188 -0
- package/src/runtime/context.ts +131 -0
- package/src/runtime/form-files.ts +18 -0
- package/src/runtime/forms-route.ts +33 -0
- package/src/runtime/forms.ts +28 -0
- package/src/runtime/icons.ts +5 -0
- package/src/runtime/media.ts +175 -0
- package/src/runtime/middleware.ts +186 -0
- package/src/runtime/nav.ts +13 -0
- package/src/runtime/query-reads.ts +49 -0
- package/src/runtime/query-store.ts +16 -0
- package/src/runtime/request-state.ts +69 -0
- package/src/runtime/robots.ts +29 -0
- package/src/runtime/rss-static.ts +16 -0
- package/src/runtime/rss.ts +29 -0
- package/src/runtime/server.ts +29 -0
- package/src/runtime/sitemap.ts +34 -0
- package/src/runtime/template-paths.ts +34 -0
- package/src/runtime/uploads-route.ts +13 -0
- package/src/seed-cli.ts +253 -0
- package/src/server/auth.ts +31 -0
- package/src/server/fetch-image.ts +219 -0
- package/src/server/handler.ts +2106 -0
- package/src/server/http.ts +162 -0
- package/src/server/locales.ts +73 -0
- package/src/server/node.ts +57 -0
- package/src/server/query-params.ts +249 -0
- package/src/server/rate-limit.ts +72 -0
- package/src/server/video-host.ts +162 -0
- package/src/starter.ts +70 -0
- package/src/version.ts +4 -0
- package/src/virtual.d.ts +65 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
function icon(paths: ReactNode) {
|
|
4
|
+
return function Icon() {
|
|
5
|
+
return (
|
|
6
|
+
<svg
|
|
7
|
+
width="16"
|
|
8
|
+
height="16"
|
|
9
|
+
viewBox="0 0 24 24"
|
|
10
|
+
fill="none"
|
|
11
|
+
stroke="currentColor"
|
|
12
|
+
strokeWidth="1.8"
|
|
13
|
+
strokeLinecap="round"
|
|
14
|
+
strokeLinejoin="round"
|
|
15
|
+
aria-hidden="true"
|
|
16
|
+
>
|
|
17
|
+
{paths}
|
|
18
|
+
</svg>
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** A gear: the settings of a page or of the selected element. */
|
|
24
|
+
export const SettingsIcon = icon(
|
|
25
|
+
<>
|
|
26
|
+
<path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z" />
|
|
27
|
+
<circle cx="12" cy="12" r="3" />
|
|
28
|
+
</>,
|
|
29
|
+
);
|
|
30
|
+
export const ChevronUpIcon = icon(<path d="m18 15-6-6-6 6" />);
|
|
31
|
+
export const ChevronDownIcon = icon(<path d="m6 9 6 6 6-6" />);
|
|
32
|
+
export const CloseIcon = icon(<path d="M18 6 6 18M6 6l12 12" />);
|
|
33
|
+
export const ResetIcon = icon(
|
|
34
|
+
<>
|
|
35
|
+
<path d="M3 12a9 9 0 1 0 3-6.7L3 8" />
|
|
36
|
+
<path d="M3 3v5h5" />
|
|
37
|
+
</>,
|
|
38
|
+
);
|
|
39
|
+
/** A curved arrow back: undo the last change. */
|
|
40
|
+
export const UndoIcon = icon(
|
|
41
|
+
<>
|
|
42
|
+
<path d="M9 14 4 9l5-5" />
|
|
43
|
+
<path d="M4 9h10.5a5.5 5.5 0 0 1 0 11H11" />
|
|
44
|
+
</>,
|
|
45
|
+
);
|
|
46
|
+
/** A curved arrow forward: make the change undone again. */
|
|
47
|
+
export const RedoIcon = icon(
|
|
48
|
+
<>
|
|
49
|
+
<path d="m15 14 5-5-5-5" />
|
|
50
|
+
<path d="M20 9H9.5a5.5 5.5 0 0 0 0 11H13" />
|
|
51
|
+
</>,
|
|
52
|
+
);
|
|
53
|
+
export const MoreIcon = icon(
|
|
54
|
+
<>
|
|
55
|
+
<circle cx="5" cy="12" r="1" />
|
|
56
|
+
<circle cx="12" cy="12" r="1" />
|
|
57
|
+
<circle cx="19" cy="12" r="1" />
|
|
58
|
+
</>,
|
|
59
|
+
);
|
|
60
|
+
export const PageIcon = icon(
|
|
61
|
+
<>
|
|
62
|
+
<path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8Z" />
|
|
63
|
+
<path d="M14 3v5h5" />
|
|
64
|
+
</>,
|
|
65
|
+
);
|
|
66
|
+
export const DesktopIcon = icon(
|
|
67
|
+
<>
|
|
68
|
+
<rect x="2" y="4" width="20" height="13" rx="2" />
|
|
69
|
+
<path d="M8 21h8M12 17v4" />
|
|
70
|
+
</>,
|
|
71
|
+
);
|
|
72
|
+
export const TabletIcon = icon(
|
|
73
|
+
<>
|
|
74
|
+
<rect x="5" y="2" width="14" height="20" rx="2" />
|
|
75
|
+
<path d="M12 18h.01" />
|
|
76
|
+
</>,
|
|
77
|
+
);
|
|
78
|
+
export const MobileIcon = icon(
|
|
79
|
+
<>
|
|
80
|
+
<rect x="7" y="2" width="10" height="20" rx="2" />
|
|
81
|
+
<path d="M12 18h.01" />
|
|
82
|
+
</>,
|
|
83
|
+
);
|
|
84
|
+
export const BoldIcon = icon(<path d="M7 5h6a3.5 3.5 0 0 1 0 7H7zM7 12h7a3.5 3.5 0 0 1 0 7H7z" />);
|
|
85
|
+
export const ItalicIcon = icon(<path d="M19 4h-9M14 20H5M15 4 9 20" />);
|
|
86
|
+
export const UnderlineIcon = icon(<path d="M6 4v6a6 6 0 0 0 12 0V4M4 20h16" />);
|
|
87
|
+
export const LinkIcon = icon(
|
|
88
|
+
<>
|
|
89
|
+
<path d="M10 13a5 5 0 0 0 7.5.5l3-3a5 5 0 0 0-7-7l-1.7 1.7" />
|
|
90
|
+
<path d="M14 11a5 5 0 0 0-7.5-.5l-3 3a5 5 0 0 0 7 7l1.7-1.7" />
|
|
91
|
+
</>,
|
|
92
|
+
);
|
|
93
|
+
export const StrikeIcon = icon(<path d="M16 5H10a3 3 0 0 0-2.5 4.7M4 12h16M14 12a3.5 3.5 0 0 1 0 7H7" />);
|
|
94
|
+
export const SubscriptIcon = icon(
|
|
95
|
+
<path d="m4 6 8 10M12 6 4 16M20 20h-4c0-1.5.4-2 1.5-2.5S20 16.3 20 15.5a1.5 1.5 0 0 0-2.9-.5" />,
|
|
96
|
+
);
|
|
97
|
+
export const SuperscriptIcon = icon(
|
|
98
|
+
<path d="m4 9 8 10M12 9 4 19M20 10h-4c0-1.5.4-2 1.5-2.5S20 6.3 20 5.5a1.5 1.5 0 0 0-2.9-.5" />,
|
|
99
|
+
);
|
|
100
|
+
export const TextColorIcon = icon(<path d="M6 16 12 4l6 12M8.5 12h7M4 21h16" />);
|
|
101
|
+
export const HighlightIcon = icon(<path d="m9 11-5 5v4h4l5-5M14 6l4 4M13 7l4-4 4 4-4 4M4 21h16" />);
|
|
102
|
+
export const AlignLeftIcon = icon(<path d="M4 6h16M4 12h10M4 18h13" />);
|
|
103
|
+
export const AlignCenterIcon = icon(<path d="M4 6h16M7 12h10M5.5 18h13" />);
|
|
104
|
+
export const AlignRightIcon = icon(<path d="M4 6h16M10 12h10M7 18h13" />);
|
|
105
|
+
export const AlignJustifyIcon = icon(<path d="M4 6h16M4 12h16M4 18h16" />);
|
|
106
|
+
export const BulletListIcon = icon(<path d="M9 6h11M9 12h11M9 18h11M4.5 6h.01M4.5 12h.01M4.5 18h.01" />);
|
|
107
|
+
export const NumberedListIcon = icon(
|
|
108
|
+
<path d="M10 6h10M10 12h10M10 18h10M4 5l1.5-1v5M4 15.5c0-1 2.5-1 2.5.2 0 .8-2.5 1.8-2.5 3.3h2.5" />,
|
|
109
|
+
);
|
|
110
|
+
export const ClearFormatIcon = icon(<path d="M6 5h12M12 5 9 19M4 20 20 4" />);
|
|
111
|
+
export const EyeIcon = icon(
|
|
112
|
+
<>
|
|
113
|
+
<path d="M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7-10-7-10-7Z" />
|
|
114
|
+
<circle cx="12" cy="12" r="3" />
|
|
115
|
+
</>,
|
|
116
|
+
);
|
|
117
|
+
export const ChevronRightIcon = icon(<path d="m9 6 6 6-6 6" />);
|
|
118
|
+
export const ChevronLeftIcon = icon(<path d="m15 6-6 6 6 6" />);
|
|
119
|
+
export const CalendarIcon = icon(
|
|
120
|
+
<>
|
|
121
|
+
<rect x="3" y="5" width="18" height="16" rx="2" />
|
|
122
|
+
<path d="M3 10h18M8 3v4M16 3v4" />
|
|
123
|
+
</>,
|
|
124
|
+
);
|
|
125
|
+
export const ArrowLeftIcon = icon(<path d="M19 12H5M12 19l-7-7 7-7" />);
|
|
126
|
+
export const ArrowUpIcon = icon(<path d="M12 19V5M5 12l7-7 7 7" />);
|
|
127
|
+
export const ArrowDownIcon = icon(<path d="M12 5v14M19 12l-7 7-7-7" />);
|
|
128
|
+
export const HomeIcon = icon(
|
|
129
|
+
<>
|
|
130
|
+
<path d="M3 10.5 12 3l9 7.5V20a1 1 0 0 1-1 1h-5v-6H9v6H4a1 1 0 0 1-1-1Z" />
|
|
131
|
+
</>,
|
|
132
|
+
);
|
|
133
|
+
export const FolderIcon = icon(
|
|
134
|
+
<path d="M3 7a2 2 0 0 1 2-2h4l2 2.5h8a2 2 0 0 1 2 2V18a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z" />,
|
|
135
|
+
);
|
|
136
|
+
/** A page laid out in regions: the template every item of a type shares. */
|
|
137
|
+
export const TemplateIcon = icon(
|
|
138
|
+
<>
|
|
139
|
+
<rect x="3" y="4" width="18" height="16" rx="2" />
|
|
140
|
+
<path d="M3 9h18M9 9v11" />
|
|
141
|
+
</>,
|
|
142
|
+
);
|
|
143
|
+
export const SearchIcon = icon(
|
|
144
|
+
<>
|
|
145
|
+
<circle cx="11" cy="11" r="7" />
|
|
146
|
+
<path d="m20 20-3.5-3.5" />
|
|
147
|
+
</>,
|
|
148
|
+
);
|
|
149
|
+
export const PlusIcon = icon(<path d="M12 5v14M5 12h14" />);
|
|
150
|
+
export const PencilIcon = icon(<path d="M4 20h4L19 9l-4-4L4 16ZM14 6l4 4" />);
|
|
151
|
+
export const TrashIcon = icon(
|
|
152
|
+
<path d="M4 7h16M10 11v6M14 11v6M6 7l1 12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1l1-12M9 7V4h6v3" />,
|
|
153
|
+
);
|
|
154
|
+
export const TableViewIcon = icon(<path d="M4 6h16M4 12h16M4 18h16" />);
|
|
155
|
+
/** Six dots: a row that can be dragged to another place. */
|
|
156
|
+
export const DragIcon = icon(
|
|
157
|
+
<>
|
|
158
|
+
<circle cx="9" cy="6" r="1.2" />
|
|
159
|
+
<circle cx="15" cy="6" r="1.2" />
|
|
160
|
+
<circle cx="9" cy="12" r="1.2" />
|
|
161
|
+
<circle cx="15" cy="12" r="1.2" />
|
|
162
|
+
<circle cx="9" cy="18" r="1.2" />
|
|
163
|
+
<circle cx="15" cy="18" r="1.2" />
|
|
164
|
+
</>,
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
export const GridViewIcon = icon(
|
|
168
|
+
<>
|
|
169
|
+
<rect x="4" y="4" width="6.5" height="6.5" rx="1" />
|
|
170
|
+
<rect x="13.5" y="4" width="6.5" height="6.5" rx="1" />
|
|
171
|
+
<rect x="4" y="13.5" width="6.5" height="6.5" rx="1" />
|
|
172
|
+
<rect x="13.5" y="13.5" width="6.5" height="6.5" rx="1" />
|
|
173
|
+
</>,
|
|
174
|
+
);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** A key event as the page gives it, or as React wraps it. */
|
|
2
|
+
interface KeyLike {
|
|
3
|
+
isComposing?: boolean;
|
|
4
|
+
keyCode?: number;
|
|
5
|
+
nativeEvent?: { isComposing?: boolean };
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Whether the key belongs to an input method still composing a word (Japanese, Chinese, Korean): there Enter picks
|
|
10
|
+
* a candidate and Escape cancels it, so neither may send, save or close anything. Safari reports the key that ends
|
|
11
|
+
* the composition with keyCode 229 and `isComposing` already false.
|
|
12
|
+
*/
|
|
13
|
+
export function isComposing(event: KeyLike): boolean {
|
|
14
|
+
return Boolean(event.isComposing || event.nativeEvent?.isComposing || event.keyCode === 229);
|
|
15
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { blockDefinitions } from "../../blocks/schemas/index.ts";
|
|
2
|
+
import { text as textBlock } from "../../blocks/schemas/text.ts";
|
|
3
|
+
import type { BlockDefinition } from "../../blocks/types.ts";
|
|
4
|
+
import { alignOf, readText } from "./rich-text.ts";
|
|
5
|
+
|
|
6
|
+
/** Describes an editable value; the inspector's widgets are generated from it. */
|
|
7
|
+
export type Schema =
|
|
8
|
+
| { type: "text"; label: string; multiline?: boolean }
|
|
9
|
+
| { type: "url"; label: string }
|
|
10
|
+
| { type: "image"; label: string }
|
|
11
|
+
| { type: "select"; label: string; options: { value: string; label: string }[] }
|
|
12
|
+
| { type: "group"; label?: string; fields: Record<string, Schema> }
|
|
13
|
+
| { type: "list"; label: string; addLabel: string; item: Schema };
|
|
14
|
+
|
|
15
|
+
export type FormValue = Record<string, unknown>;
|
|
16
|
+
|
|
17
|
+
/** How one kind of node is presented and edited in the inspector. */
|
|
18
|
+
export interface NodeKind {
|
|
19
|
+
title: string;
|
|
20
|
+
schema(element: HTMLElement): Schema;
|
|
21
|
+
/** The value currently shown on the page. */
|
|
22
|
+
read(element: HTMLElement): FormValue;
|
|
23
|
+
/** Turns what the inspector holds into the value to save. */
|
|
24
|
+
toValue(form: FormValue): unknown;
|
|
25
|
+
/** Updates the page without a reload. Left out when the markup is written by the site author. */
|
|
26
|
+
apply?(element: HTMLElement, form: FormValue): void;
|
|
27
|
+
/** Set for blocks: the inspector then shows the sections of the block's own settings schema. */
|
|
28
|
+
block?: BlockDefinition;
|
|
29
|
+
/** Extra sections kept under the value's `options`, for a primitive that also has a block schema. */
|
|
30
|
+
options?: BlockDefinition;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const text = (label: string): Schema => ({ type: "text", label });
|
|
34
|
+
const navLink: Schema = { type: "group", fields: { label: text("Label"), href: { type: "url", label: "Link" } } };
|
|
35
|
+
const navLinks: Schema = { type: "list", label: "Links", addLabel: "Add link", item: navLink };
|
|
36
|
+
|
|
37
|
+
/** As deep as the server accepts sub-links (`MAX_NAV_DEPTH` in content/validate.ts). */
|
|
38
|
+
const NAV_DEPTH = 2;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The navbar's links: each with an optional picture and its own list of sub-links, down to `NAV_DEPTH`. Built from
|
|
42
|
+
* the same link, image and list widgets as everything else, so a sub-link is edited like any link.
|
|
43
|
+
*/
|
|
44
|
+
function navItems(depth: number, sources: Source[]): Schema {
|
|
45
|
+
return {
|
|
46
|
+
type: "list",
|
|
47
|
+
label: depth === 0 ? "Links" : "Sub-links",
|
|
48
|
+
addLabel: depth === 0 ? "Add link" : "Add sub-link",
|
|
49
|
+
item: {
|
|
50
|
+
type: "group",
|
|
51
|
+
fields: {
|
|
52
|
+
label: text("Label"),
|
|
53
|
+
href: { type: "url", label: "Link" },
|
|
54
|
+
image: { type: "image", label: "Picture (optional)" },
|
|
55
|
+
...(depth < NAV_DEPTH && sources.length > 0 && { from: fromChoice("Sub-links come from", sources) }),
|
|
56
|
+
...(depth < NAV_DEPTH && { children: navItems(depth + 1, sources) }),
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** A content type a menu can list, as the Navbar and Footer components offer them (`data-brim-nav-sources`). */
|
|
63
|
+
interface Source {
|
|
64
|
+
value: string;
|
|
65
|
+
label: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function sourcesOf(element: HTMLElement): Source[] {
|
|
69
|
+
try {
|
|
70
|
+
const parsed = JSON.parse(element.dataset.brimNavSources ?? "[]") as unknown;
|
|
71
|
+
return Array.isArray(parsed) ? (parsed as Source[]) : [];
|
|
72
|
+
} catch {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Written links, or a content type's items listed by themselves (a category added shows in the menu at once). */
|
|
78
|
+
function fromChoice(label: string, sources: Source[]): Schema {
|
|
79
|
+
return {
|
|
80
|
+
type: "select",
|
|
81
|
+
label,
|
|
82
|
+
options: [
|
|
83
|
+
{ value: "", label: "The links written below" },
|
|
84
|
+
...sources.map((source) => ({ value: source.value, label: `${source.label}, listed by themselves` })),
|
|
85
|
+
],
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
interface NavForm {
|
|
90
|
+
label?: unknown;
|
|
91
|
+
href?: unknown;
|
|
92
|
+
image?: Image;
|
|
93
|
+
children?: NavForm[];
|
|
94
|
+
from?: unknown;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* A link without a picture or sub-links is saved as a plain `{ label, href }`, as before groups existed. A link just
|
|
99
|
+
* added, with nothing typed yet, waits in the form: saved empty it would be refused for its missing address.
|
|
100
|
+
*/
|
|
101
|
+
function navValue(items: NavForm[]): unknown[] {
|
|
102
|
+
const typed = (value: unknown) => typeof value === "string" && value.trim() !== "";
|
|
103
|
+
return items
|
|
104
|
+
.filter((item) => typed(item.label) || typed(item.href) || (item.children ?? []).length > 0)
|
|
105
|
+
.map(({ label, href, image, children, from }) => {
|
|
106
|
+
const nested = navValue(children ?? []);
|
|
107
|
+
return {
|
|
108
|
+
label: label ?? "",
|
|
109
|
+
href: href ?? "",
|
|
110
|
+
...(image?.src ? { image } : {}),
|
|
111
|
+
...(nested.length > 0 ? { children: nested } : {}),
|
|
112
|
+
...(typed(from) ? { from } : {}),
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const brandFields: Record<string, Schema> = {
|
|
117
|
+
logoText: text("Logo text"),
|
|
118
|
+
logo: { type: "image", label: "Logo image" },
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const TEXT_ELEMENTS = [
|
|
122
|
+
{ value: "p", label: "Paragraph" },
|
|
123
|
+
{ value: "h1", label: "Heading 1" },
|
|
124
|
+
{ value: "h2", label: "Heading 2" },
|
|
125
|
+
{ value: "h3", label: "Heading 3" },
|
|
126
|
+
{ value: "h4", label: "Heading 4" },
|
|
127
|
+
{ value: "h5", label: "Heading 5" },
|
|
128
|
+
{ value: "h6", label: "Heading 6" },
|
|
129
|
+
{ value: "blockquote", label: "Quote" },
|
|
130
|
+
{ value: "span", label: "Inline text" },
|
|
131
|
+
{ value: "small", label: "Small print" },
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
const TEXT_ALIGNMENTS = [
|
|
135
|
+
{ value: "", label: "As the page sets it" },
|
|
136
|
+
{ value: "left", label: "Left" },
|
|
137
|
+
{ value: "center", label: "Center" },
|
|
138
|
+
{ value: "right", label: "Right" },
|
|
139
|
+
{ value: "justify", label: "Justify" },
|
|
140
|
+
];
|
|
141
|
+
|
|
142
|
+
interface Image {
|
|
143
|
+
src: string;
|
|
144
|
+
alt: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** An empty logo text or logo image means "none", not an empty value. */
|
|
148
|
+
function brand(form: FormValue): FormValue {
|
|
149
|
+
const logo = (form.logo ?? { src: "", alt: "" }) as Image;
|
|
150
|
+
return {
|
|
151
|
+
...(form.logoText ? { logoText: form.logoText } : {}),
|
|
152
|
+
...(logo.src ? { logo } : {}),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function storedValue(element: HTMLElement): FormValue {
|
|
157
|
+
return JSON.parse(element.dataset.brimValue ?? "{}") as FormValue;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** A link's label is editable only when it is plain text; richer content belongs to the site's code. */
|
|
161
|
+
function hasPlainLabel(element: HTMLElement): boolean {
|
|
162
|
+
return element.childElementCount === 0;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Blocks keep all their settings in one record, which the page hands to the editor as-is. */
|
|
166
|
+
function blockKind(definition: BlockDefinition): NodeKind {
|
|
167
|
+
return {
|
|
168
|
+
title: definition.label,
|
|
169
|
+
block: definition,
|
|
170
|
+
schema: () => ({ type: "group", fields: {} }),
|
|
171
|
+
read: storedValue,
|
|
172
|
+
toValue: (form) => form,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const primitiveKinds: Record<string, NodeKind> = {
|
|
177
|
+
text: {
|
|
178
|
+
title: "Text",
|
|
179
|
+
options: textBlock,
|
|
180
|
+
schema: () => ({
|
|
181
|
+
type: "group",
|
|
182
|
+
fields: {
|
|
183
|
+
as: { type: "select", label: "Element", options: TEXT_ELEMENTS },
|
|
184
|
+
align: { type: "select", label: "Alignment", options: TEXT_ALIGNMENTS },
|
|
185
|
+
},
|
|
186
|
+
}),
|
|
187
|
+
read: (element) => ({
|
|
188
|
+
as: element.tagName.toLowerCase(),
|
|
189
|
+
align: alignOf(element) ?? "",
|
|
190
|
+
options: storedValue(element).options ?? {},
|
|
191
|
+
}),
|
|
192
|
+
// Text content is saved by the in-place editor; the inspector changes the element and its presentation.
|
|
193
|
+
toValue: (form) => form,
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
richtext: {
|
|
197
|
+
title: "Rich text",
|
|
198
|
+
schema: () => ({ type: "group", fields: {} }),
|
|
199
|
+
read: () => ({}),
|
|
200
|
+
// Content is saved by the in-place editor; there is nothing else to set.
|
|
201
|
+
toValue: (form) => form,
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
blocks: {
|
|
205
|
+
title: "Blocks",
|
|
206
|
+
schema: () => ({ type: "group", fields: {} }),
|
|
207
|
+
read: () => ({}),
|
|
208
|
+
// A stack of blocks has nothing of its own to set: the + under it adds blocks to it.
|
|
209
|
+
toValue: (form) => form,
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
link: {
|
|
213
|
+
title: "Link",
|
|
214
|
+
schema: (element) => ({
|
|
215
|
+
type: "group",
|
|
216
|
+
fields: {
|
|
217
|
+
...(hasPlainLabel(element) && { label: text("Label") }),
|
|
218
|
+
href: { type: "url", label: "Link" },
|
|
219
|
+
},
|
|
220
|
+
}),
|
|
221
|
+
read: (element) => ({
|
|
222
|
+
href: element.getAttribute("href") ?? "",
|
|
223
|
+
...(hasPlainLabel(element) && { label: readText(element) }),
|
|
224
|
+
}),
|
|
225
|
+
toValue: (form) => form,
|
|
226
|
+
apply(element, form) {
|
|
227
|
+
element.setAttribute("href", String(form.href));
|
|
228
|
+
if (form.label !== undefined) element.textContent = String(form.label);
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
|
|
232
|
+
navbar: {
|
|
233
|
+
title: "Navigation",
|
|
234
|
+
schema: (element) => ({ type: "group", fields: { ...brandFields, items: navItems(0, sourcesOf(element)) } }),
|
|
235
|
+
read: storedValue,
|
|
236
|
+
toValue: (form) => ({ ...brand(form), items: navValue((form.items ?? []) as NavForm[]) }),
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
footer: {
|
|
240
|
+
title: "Footer",
|
|
241
|
+
schema: (element) => {
|
|
242
|
+
const sources = sourcesOf(element);
|
|
243
|
+
return {
|
|
244
|
+
type: "group",
|
|
245
|
+
fields: {
|
|
246
|
+
...brandFields,
|
|
247
|
+
groups: {
|
|
248
|
+
type: "list",
|
|
249
|
+
label: "Link groups",
|
|
250
|
+
addLabel: "Add group",
|
|
251
|
+
item: {
|
|
252
|
+
type: "group",
|
|
253
|
+
fields: {
|
|
254
|
+
title: text("Title"),
|
|
255
|
+
...(sources.length > 0 && { from: fromChoice("Links come from", sources) }),
|
|
256
|
+
items: navLinks,
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
},
|
|
263
|
+
read: storedValue,
|
|
264
|
+
toValue: (form) => ({
|
|
265
|
+
...brand(form),
|
|
266
|
+
groups: ((form.groups ?? []) as { title?: string; items?: unknown; from?: string }[]).map((group) => ({
|
|
267
|
+
...(group.title ? { title: group.title } : {}),
|
|
268
|
+
items: group.items ?? [],
|
|
269
|
+
...(group.from ? { from: group.from } : {}),
|
|
270
|
+
})),
|
|
271
|
+
}),
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
/** The `text` primitive wins over the block of the same name, which BrimCMS also had. */
|
|
276
|
+
export const nodeKinds: Record<string, NodeKind> = {
|
|
277
|
+
...Object.fromEntries(Object.entries(blockDefinitions).map(([type, definition]) => [type, blockKind(definition)])),
|
|
278
|
+
...primitiveKinds,
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
/** The starting value of a new list entry. */
|
|
282
|
+
export function emptyValue(schema: Schema): unknown {
|
|
283
|
+
if (schema.type === "group") {
|
|
284
|
+
return Object.fromEntries(Object.entries(schema.fields).map(([name, field]) => [name, emptyValue(field)]));
|
|
285
|
+
}
|
|
286
|
+
if (schema.type === "list") return [];
|
|
287
|
+
if (schema.type === "image") return { src: "", alt: "" };
|
|
288
|
+
return "";
|
|
289
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { localeOfPath, pathInLocale } from "../../server/locales.ts";
|
|
3
|
+
import { type SiteLocales, loadSiteInfo } from "./api.ts";
|
|
4
|
+
|
|
5
|
+
export { localeOfPath, pathInLocale };
|
|
6
|
+
|
|
7
|
+
/** The site's languages from its code; `null` until known and for a site with one language. */
|
|
8
|
+
export function useSiteLocales(): SiteLocales | null {
|
|
9
|
+
const [locales, setLocales] = useState<SiteLocales | null>(null);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
let current = true;
|
|
12
|
+
// A site that declares only its own language has nothing to switch to: no language menus at all.
|
|
13
|
+
void loadSiteInfo().then(
|
|
14
|
+
(info) => current && setLocales(info.locales && info.locales.locales.length > 1 ? info.locales : null),
|
|
15
|
+
);
|
|
16
|
+
return () => {
|
|
17
|
+
current = false;
|
|
18
|
+
};
|
|
19
|
+
}, []);
|
|
20
|
+
return locales;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** An item's language as a code: "" means the default one. */
|
|
24
|
+
export function itemLocale(item: { locale: string }, locales: SiteLocales): string {
|
|
25
|
+
return item.locale || locales.defaultLocale;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The item in every language it is written in, itself included, from the items of its type. */
|
|
29
|
+
export function translationsOf<T extends { id: string; translationOf: string | null }>(item: T, items: T[]): T[] {
|
|
30
|
+
const original = item.translationOf ?? item.id;
|
|
31
|
+
return items.filter((candidate) => (candidate.translationOf ?? candidate.id) === original);
|
|
32
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { useEffect, useState, useSyncExternalStore } from "react";
|
|
2
|
+
import { createRoot } from "react-dom/client";
|
|
3
|
+
import { type User, api, whenSignedOut } from "./api.ts";
|
|
4
|
+
import { connection } from "./connection.ts";
|
|
5
|
+
import { Editor } from "./Editor.tsx";
|
|
6
|
+
import { Login } from "./Login.tsx";
|
|
7
|
+
import "./editor.css";
|
|
8
|
+
import { startTheme } from "./theme.ts";
|
|
9
|
+
|
|
10
|
+
/** `undefined` while the session is being checked, `null` when nobody is signed in. */
|
|
11
|
+
type Session = User | null | undefined;
|
|
12
|
+
|
|
13
|
+
/** The token of a "forgot password" link, which carries it after `#` so it never reaches a server log. */
|
|
14
|
+
function resetTokenInAddress(): string | undefined {
|
|
15
|
+
const match = /^#reset=([\w-]+)$/.exec(location.hash);
|
|
16
|
+
return match?.[1];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function App() {
|
|
20
|
+
const [user, setUser] = useState<Session>(undefined);
|
|
21
|
+
const [resetToken, setResetToken] = useState(resetTokenInAddress);
|
|
22
|
+
/** Set while the session ran out in the middle of editing: signing in again lets the waiting requests go on. */
|
|
23
|
+
const [expired, setExpired] = useState<(() => void) | null>(null);
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
api.session().then(
|
|
27
|
+
({ user: current }) => setUser(current),
|
|
28
|
+
() => setUser(null),
|
|
29
|
+
);
|
|
30
|
+
}, []);
|
|
31
|
+
|
|
32
|
+
// The editor stays open behind the sign-in form, so nothing typed or changed is lost while signing in again.
|
|
33
|
+
const editing = Boolean(user);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!editing) return;
|
|
36
|
+
let waiting: Promise<void> | null = null;
|
|
37
|
+
whenSignedOut(() => {
|
|
38
|
+
waiting ??= new Promise<void>((resolve) =>
|
|
39
|
+
setExpired(() => () => {
|
|
40
|
+
waiting = null;
|
|
41
|
+
setExpired(null);
|
|
42
|
+
resolve();
|
|
43
|
+
}),
|
|
44
|
+
);
|
|
45
|
+
return waiting;
|
|
46
|
+
});
|
|
47
|
+
return () => whenSignedOut(null);
|
|
48
|
+
}, [editing]);
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<>
|
|
52
|
+
{/* A reset link opens its form even for someone signed in already (on another account, or still). */}
|
|
53
|
+
{resetToken && user !== undefined && (
|
|
54
|
+
<Login
|
|
55
|
+
resetToken={resetToken}
|
|
56
|
+
onSignedIn={(next) => {
|
|
57
|
+
setResetToken(undefined);
|
|
58
|
+
setUser(next);
|
|
59
|
+
}}
|
|
60
|
+
/>
|
|
61
|
+
)}
|
|
62
|
+
{!resetToken && user === null && <Login onSignedIn={setUser} />}
|
|
63
|
+
{!resetToken && user && <Editor user={user} onSignedOut={() => setUser(null)} />}
|
|
64
|
+
{!resetToken && user && expired && (
|
|
65
|
+
<div className="brim-signin-again" role="dialog" aria-modal="true" aria-label="Sign in again">
|
|
66
|
+
<Login
|
|
67
|
+
again
|
|
68
|
+
onSignedIn={(next) => {
|
|
69
|
+
setUser(next);
|
|
70
|
+
expired();
|
|
71
|
+
}}
|
|
72
|
+
/>
|
|
73
|
+
</div>
|
|
74
|
+
)}
|
|
75
|
+
<Reconnecting />
|
|
76
|
+
</>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Shown while a request waits for a server that is away (restarting, or stopped while nobody was editing). */
|
|
81
|
+
function Reconnecting() {
|
|
82
|
+
const away = useSyncExternalStore(connection.subscribe, connection.away);
|
|
83
|
+
if (!away) return null;
|
|
84
|
+
return (
|
|
85
|
+
<div className="brim-editor-reconnecting" role="status" aria-live="polite">
|
|
86
|
+
<span className="brim-editor-reconnecting-dot" aria-hidden="true" />
|
|
87
|
+
<span>
|
|
88
|
+
<strong>The editor is starting again.</strong> It was paused while idle. It carries on by itself in a few
|
|
89
|
+
seconds — nothing to reload.
|
|
90
|
+
</span>
|
|
91
|
+
</div>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The editor follows the system's light or dark appearance, unless the user picked one in the ⋯ menu. */
|
|
96
|
+
startTheme();
|
|
97
|
+
|
|
98
|
+
const root = document.getElementById("brim-editor");
|
|
99
|
+
if (!root) throw new Error("The editor page is missing its root element.");
|
|
100
|
+
createRoot(root).render(<App />);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { FormResponse } from "./api.ts";
|
|
2
|
+
|
|
3
|
+
/** One form, as the owner reads its responses: under its name, wherever on the site it was filled in. */
|
|
4
|
+
export interface FormSummary {
|
|
5
|
+
title: string;
|
|
6
|
+
count: number;
|
|
7
|
+
/** When its newest response came, ISO. */
|
|
8
|
+
latest: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The site's forms that have responses, newest first. A form is its name: the same form placed in a template (a
|
|
13
|
+
* product's order form) is sent from every item's page, and its responses are still one list.
|
|
14
|
+
*/
|
|
15
|
+
export function formsOf(responses: FormResponse[]): FormSummary[] {
|
|
16
|
+
const forms = new Map<string, FormSummary>();
|
|
17
|
+
for (const response of responses) {
|
|
18
|
+
const known = forms.get(response.title);
|
|
19
|
+
if (!known) forms.set(response.title, { title: response.title, count: 1, latest: response.createdAt });
|
|
20
|
+
else {
|
|
21
|
+
known.count += 1;
|
|
22
|
+
if (response.createdAt > known.latest) known.latest = response.createdAt;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return [...forms.values()].sort((a, b) => b.latest.localeCompare(a.latest));
|
|
26
|
+
}
|