@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,338 @@
|
|
|
1
|
+
import { type FormEvent, useEffect, useState } from "react";
|
|
2
|
+
import { type SiteInfo, type User, api, loadSiteInfo } from "./api.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `again` is the form shown over the editor when the session ran out while editing: the editor stays open behind it,
|
|
6
|
+
* so a sign-in with the host opens in another tab and the owner comes back here to go on.
|
|
7
|
+
*/
|
|
8
|
+
export function Login({
|
|
9
|
+
onSignedIn,
|
|
10
|
+
again = false,
|
|
11
|
+
resetToken,
|
|
12
|
+
}: {
|
|
13
|
+
onSignedIn: (user: User) => void;
|
|
14
|
+
again?: boolean;
|
|
15
|
+
/** The token of a "forgot password" link: the form asks for the new password. */
|
|
16
|
+
resetToken?: string | undefined;
|
|
17
|
+
}) {
|
|
18
|
+
const [email, setEmail] = useState("");
|
|
19
|
+
const [password, setPassword] = useState("");
|
|
20
|
+
const [error, setError] = useState("");
|
|
21
|
+
const [hostSignIn, setHostSignIn] = useState<SiteInfo["hostSignIn"]>(null);
|
|
22
|
+
/** Signing in, asking for a link to set a new password, or setting it from that link. */
|
|
23
|
+
const [mode, setMode] = useState<"sign-in" | "forgot" | "sent" | "reset">(resetToken ? "reset" : "sign-in");
|
|
24
|
+
const [notice, setNotice] = useState("");
|
|
25
|
+
const [busy, setBusy] = useState(false);
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
loadSiteInfo().then((info) => setHostSignIn(info.hostSignIn ?? null));
|
|
29
|
+
}, []);
|
|
30
|
+
|
|
31
|
+
async function submit(event: FormEvent): Promise<void> {
|
|
32
|
+
event.preventDefault();
|
|
33
|
+
setError("");
|
|
34
|
+
try {
|
|
35
|
+
onSignedIn((await api.signIn(email, password)).user);
|
|
36
|
+
} catch (failure) {
|
|
37
|
+
setError(failure instanceof Error ? failure.message : "Could not sign in.");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** After signing in with the host in another tab: the session it started is used here too. */
|
|
42
|
+
async function goOn(): Promise<void> {
|
|
43
|
+
setError("");
|
|
44
|
+
try {
|
|
45
|
+
onSignedIn((await api.session()).user);
|
|
46
|
+
} catch {
|
|
47
|
+
setError("Not signed in yet.");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function askForLink(event: FormEvent): Promise<void> {
|
|
52
|
+
event.preventDefault();
|
|
53
|
+
setError("");
|
|
54
|
+
setBusy(true);
|
|
55
|
+
try {
|
|
56
|
+
setNotice((await api.forgotPassword(email)).message);
|
|
57
|
+
setMode("sent");
|
|
58
|
+
} catch (failure) {
|
|
59
|
+
setError(failure instanceof Error ? failure.message : "Could not send the email.");
|
|
60
|
+
} finally {
|
|
61
|
+
setBusy(false);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function setNewPassword(event: FormEvent): Promise<void> {
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
setError("");
|
|
68
|
+
setBusy(true);
|
|
69
|
+
try {
|
|
70
|
+
const { user } = await api.resetPassword(resetToken ?? "", password);
|
|
71
|
+
// The link worked once: it leaves the address, so a reload or a shared screen does not show it.
|
|
72
|
+
history.replaceState(null, "", location.pathname + location.search);
|
|
73
|
+
onSignedIn(user);
|
|
74
|
+
} catch (failure) {
|
|
75
|
+
setError(failure instanceof Error ? failure.message : "Could not set the password.");
|
|
76
|
+
} finally {
|
|
77
|
+
setBusy(false);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (mode === "reset") {
|
|
82
|
+
return (
|
|
83
|
+
<form className="brim-login" onSubmit={setNewPassword}>
|
|
84
|
+
<h1>Set a new password</h1>
|
|
85
|
+
<p className="brim-login__note">It signs you out everywhere else.</p>
|
|
86
|
+
<div className="field-group">
|
|
87
|
+
<label className="field-label" htmlFor="brim-login-new-password">
|
|
88
|
+
New password
|
|
89
|
+
</label>
|
|
90
|
+
<input
|
|
91
|
+
id="brim-login-new-password"
|
|
92
|
+
className="field-input"
|
|
93
|
+
type="password"
|
|
94
|
+
autoComplete="new-password"
|
|
95
|
+
autoFocus
|
|
96
|
+
required
|
|
97
|
+
minLength={10}
|
|
98
|
+
value={password}
|
|
99
|
+
onChange={(event) => setPassword(event.target.value)}
|
|
100
|
+
/>
|
|
101
|
+
<p className="brim-login__hint">At least 10 characters.</p>
|
|
102
|
+
</div>
|
|
103
|
+
{error && (
|
|
104
|
+
<p className="brim-login__error" role="alert">
|
|
105
|
+
{error}
|
|
106
|
+
</p>
|
|
107
|
+
)}
|
|
108
|
+
<button type="submit" className="cb-new-btn" disabled={busy}>
|
|
109
|
+
Set password and sign in
|
|
110
|
+
</button>
|
|
111
|
+
<button type="button" className="brim-login__link" onClick={() => setMode("forgot")}>
|
|
112
|
+
Ask for a new link
|
|
113
|
+
</button>
|
|
114
|
+
</form>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (mode === "forgot" || mode === "sent") {
|
|
119
|
+
return (
|
|
120
|
+
<form className="brim-login" onSubmit={askForLink}>
|
|
121
|
+
<h1>Forgot your password?</h1>
|
|
122
|
+
{mode === "sent" ? (
|
|
123
|
+
<p className="brim-login__note" role="status">
|
|
124
|
+
{notice} It works for an hour. Check your spam folder if it does not arrive.
|
|
125
|
+
</p>
|
|
126
|
+
) : (
|
|
127
|
+
<p className="brim-login__note">Write your email: we send you a link to set a new password.</p>
|
|
128
|
+
)}
|
|
129
|
+
<div className="field-group">
|
|
130
|
+
<label className="field-label" htmlFor="brim-login-forgot-email">
|
|
131
|
+
Email
|
|
132
|
+
</label>
|
|
133
|
+
<input
|
|
134
|
+
id="brim-login-forgot-email"
|
|
135
|
+
className="field-input"
|
|
136
|
+
type="email"
|
|
137
|
+
autoComplete="username"
|
|
138
|
+
autoFocus
|
|
139
|
+
required
|
|
140
|
+
value={email}
|
|
141
|
+
onChange={(event) => setEmail(event.target.value)}
|
|
142
|
+
/>
|
|
143
|
+
</div>
|
|
144
|
+
{error && (
|
|
145
|
+
<p className="brim-login__error" role="alert">
|
|
146
|
+
{error}
|
|
147
|
+
</p>
|
|
148
|
+
)}
|
|
149
|
+
<button type="submit" className="cb-new-btn" disabled={busy}>
|
|
150
|
+
{mode === "sent" ? "Send again" : "Send the link"}
|
|
151
|
+
</button>
|
|
152
|
+
<button
|
|
153
|
+
type="button"
|
|
154
|
+
className="brim-login__link"
|
|
155
|
+
onClick={() => {
|
|
156
|
+
setError("");
|
|
157
|
+
setMode("sign-in");
|
|
158
|
+
}}
|
|
159
|
+
>
|
|
160
|
+
Back to sign in
|
|
161
|
+
</button>
|
|
162
|
+
</form>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return (
|
|
167
|
+
<form className="brim-login" onSubmit={submit}>
|
|
168
|
+
<h1>{again ? "Sign in again" : "Sign in to edit"}</h1>
|
|
169
|
+
{again && <p className="brim-login__note">You were signed out. Sign in to go on: nothing you changed is lost.</p>}
|
|
170
|
+
<div className="field-group">
|
|
171
|
+
<label className="field-label" htmlFor="brim-login-email">
|
|
172
|
+
Email
|
|
173
|
+
</label>
|
|
174
|
+
<input
|
|
175
|
+
id="brim-login-email"
|
|
176
|
+
className="field-input"
|
|
177
|
+
type="email"
|
|
178
|
+
autoComplete="username"
|
|
179
|
+
autoFocus
|
|
180
|
+
required
|
|
181
|
+
value={email}
|
|
182
|
+
onChange={(event) => setEmail(event.target.value)}
|
|
183
|
+
/>
|
|
184
|
+
</div>
|
|
185
|
+
<div className="field-group">
|
|
186
|
+
<label className="field-label" htmlFor="brim-login-password">
|
|
187
|
+
Password
|
|
188
|
+
</label>
|
|
189
|
+
<input
|
|
190
|
+
id="brim-login-password"
|
|
191
|
+
className="field-input"
|
|
192
|
+
type="password"
|
|
193
|
+
autoComplete="current-password"
|
|
194
|
+
required
|
|
195
|
+
value={password}
|
|
196
|
+
onChange={(event) => setPassword(event.target.value)}
|
|
197
|
+
/>
|
|
198
|
+
</div>
|
|
199
|
+
{error && (
|
|
200
|
+
<p className="brim-login__error" role="alert">
|
|
201
|
+
{error}
|
|
202
|
+
</p>
|
|
203
|
+
)}
|
|
204
|
+
<button type="submit" className="cb-new-btn">
|
|
205
|
+
Sign in
|
|
206
|
+
</button>
|
|
207
|
+
<button
|
|
208
|
+
type="button"
|
|
209
|
+
className="brim-login__link"
|
|
210
|
+
onClick={() => {
|
|
211
|
+
setError("");
|
|
212
|
+
setMode("forgot");
|
|
213
|
+
}}
|
|
214
|
+
>
|
|
215
|
+
Forgot password?
|
|
216
|
+
</button>
|
|
217
|
+
{hostSignIn && (
|
|
218
|
+
<>
|
|
219
|
+
<p className="brim-login__or">or</p>
|
|
220
|
+
{/* The host checks who this is and, when they may sign in here, sends them back signed in. */}
|
|
221
|
+
<a className="brim-login__host" href={hostSignIn.url} {...(again && { target: "_blank", rel: "noreferrer" })}>
|
|
222
|
+
Continue with {hostSignIn.name}
|
|
223
|
+
</a>
|
|
224
|
+
{again && (
|
|
225
|
+
<button type="button" className="brim-login__host brim-login__done" onClick={() => void goOn()}>
|
|
226
|
+
I signed in, go on
|
|
227
|
+
</button>
|
|
228
|
+
)}
|
|
229
|
+
</>
|
|
230
|
+
)}
|
|
231
|
+
</form>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Changing one's own password, from the editor's menu: the current one first, so a browser left signed in is not
|
|
237
|
+
* enough to take the account. Every other session and access token ends; this one goes on.
|
|
238
|
+
*/
|
|
239
|
+
export function ChangePassword({ onClose }: { onClose: () => void }) {
|
|
240
|
+
const [current, setCurrent] = useState("");
|
|
241
|
+
const [password, setPassword] = useState("");
|
|
242
|
+
const [error, setError] = useState("");
|
|
243
|
+
const [done, setDone] = useState(false);
|
|
244
|
+
const [busy, setBusy] = useState(false);
|
|
245
|
+
|
|
246
|
+
useEffect(() => {
|
|
247
|
+
const onKey = (event: KeyboardEvent) => {
|
|
248
|
+
if (event.key === "Escape" && !event.isComposing) onClose();
|
|
249
|
+
};
|
|
250
|
+
document.addEventListener("keydown", onKey);
|
|
251
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
252
|
+
}, [onClose]);
|
|
253
|
+
|
|
254
|
+
async function submit(event: FormEvent): Promise<void> {
|
|
255
|
+
event.preventDefault();
|
|
256
|
+
setError("");
|
|
257
|
+
setBusy(true);
|
|
258
|
+
try {
|
|
259
|
+
await api.changePassword(current, password);
|
|
260
|
+
setDone(true);
|
|
261
|
+
} catch (failure) {
|
|
262
|
+
setError(failure instanceof Error ? failure.message : "Could not change the password.");
|
|
263
|
+
} finally {
|
|
264
|
+
setBusy(false);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return (
|
|
269
|
+
<div
|
|
270
|
+
className="brim-signin-again"
|
|
271
|
+
role="dialog"
|
|
272
|
+
aria-modal="true"
|
|
273
|
+
aria-label="Change password"
|
|
274
|
+
onMouseDown={(event) => {
|
|
275
|
+
if (event.target === event.currentTarget) onClose();
|
|
276
|
+
}}
|
|
277
|
+
>
|
|
278
|
+
<form className="brim-login" onSubmit={submit}>
|
|
279
|
+
<h1>Change password</h1>
|
|
280
|
+
{done ? (
|
|
281
|
+
<>
|
|
282
|
+
<p className="brim-login__success" role="status">
|
|
283
|
+
Your password is changed. You are signed out everywhere else, and access tokens made before stop working.
|
|
284
|
+
</p>
|
|
285
|
+
<button type="button" className="cb-new-btn" onClick={onClose} autoFocus>
|
|
286
|
+
Done
|
|
287
|
+
</button>
|
|
288
|
+
</>
|
|
289
|
+
) : (
|
|
290
|
+
<>
|
|
291
|
+
<div className="field-group">
|
|
292
|
+
<label className="field-label" htmlFor="brim-current-password">
|
|
293
|
+
Current password
|
|
294
|
+
</label>
|
|
295
|
+
<input
|
|
296
|
+
id="brim-current-password"
|
|
297
|
+
className="field-input"
|
|
298
|
+
type="password"
|
|
299
|
+
autoComplete="current-password"
|
|
300
|
+
autoFocus
|
|
301
|
+
required
|
|
302
|
+
value={current}
|
|
303
|
+
onChange={(event) => setCurrent(event.target.value)}
|
|
304
|
+
/>
|
|
305
|
+
</div>
|
|
306
|
+
<div className="field-group">
|
|
307
|
+
<label className="field-label" htmlFor="brim-next-password">
|
|
308
|
+
New password
|
|
309
|
+
</label>
|
|
310
|
+
<input
|
|
311
|
+
id="brim-next-password"
|
|
312
|
+
className="field-input"
|
|
313
|
+
type="password"
|
|
314
|
+
autoComplete="new-password"
|
|
315
|
+
required
|
|
316
|
+
minLength={10}
|
|
317
|
+
value={password}
|
|
318
|
+
onChange={(event) => setPassword(event.target.value)}
|
|
319
|
+
/>
|
|
320
|
+
<p className="brim-login__hint">At least 10 characters. It signs you out everywhere else.</p>
|
|
321
|
+
</div>
|
|
322
|
+
{error && (
|
|
323
|
+
<p className="brim-login__error" role="alert">
|
|
324
|
+
{error}
|
|
325
|
+
</p>
|
|
326
|
+
)}
|
|
327
|
+
<button type="submit" className="cb-new-btn" disabled={busy}>
|
|
328
|
+
Change password
|
|
329
|
+
</button>
|
|
330
|
+
<button type="button" className="brim-login__link" onClick={onClose}>
|
|
331
|
+
Cancel
|
|
332
|
+
</button>
|
|
333
|
+
</>
|
|
334
|
+
)}
|
|
335
|
+
</form>
|
|
336
|
+
</div>
|
|
337
|
+
);
|
|
338
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type ReactNode, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { isComposing } from "./keys.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A toolbar button that opens a menu below it, or above it with `side="above"`. Closes on outside click, Escape, or
|
|
6
|
+
* after a choice.
|
|
7
|
+
*/
|
|
8
|
+
export function Menu({
|
|
9
|
+
label,
|
|
10
|
+
className,
|
|
11
|
+
align = "start",
|
|
12
|
+
side = "below",
|
|
13
|
+
trigger,
|
|
14
|
+
children,
|
|
15
|
+
}: {
|
|
16
|
+
label: string;
|
|
17
|
+
className: string;
|
|
18
|
+
align?: "start" | "end";
|
|
19
|
+
side?: "below" | "above";
|
|
20
|
+
trigger: ReactNode;
|
|
21
|
+
children: (close: () => void) => ReactNode;
|
|
22
|
+
}) {
|
|
23
|
+
const [open, setOpen] = useState(false);
|
|
24
|
+
const root = useRef<HTMLDivElement>(null);
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!open) return;
|
|
28
|
+
const onPointerDown = (event: PointerEvent): void => {
|
|
29
|
+
if (!root.current?.contains(event.target as Node)) setOpen(false);
|
|
30
|
+
};
|
|
31
|
+
const onKeyDown = (event: KeyboardEvent): void => {
|
|
32
|
+
if (event.key === "Escape" && !isComposing(event)) setOpen(false);
|
|
33
|
+
};
|
|
34
|
+
document.addEventListener("pointerdown", onPointerDown);
|
|
35
|
+
document.addEventListener("keydown", onKeyDown);
|
|
36
|
+
// A click inside the page frame never reaches this document.
|
|
37
|
+
window.addEventListener("blur", () => setOpen(false), { once: true });
|
|
38
|
+
return () => {
|
|
39
|
+
document.removeEventListener("pointerdown", onPointerDown);
|
|
40
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
41
|
+
};
|
|
42
|
+
}, [open]);
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<div className="brim-editor-menu-anchor" ref={root}>
|
|
46
|
+
<button
|
|
47
|
+
type="button"
|
|
48
|
+
className={className}
|
|
49
|
+
aria-label={label}
|
|
50
|
+
title={label}
|
|
51
|
+
aria-haspopup="menu"
|
|
52
|
+
aria-expanded={open}
|
|
53
|
+
onClick={() => setOpen(!open)}
|
|
54
|
+
>
|
|
55
|
+
{trigger}
|
|
56
|
+
</button>
|
|
57
|
+
{open && (
|
|
58
|
+
<div className="brim-editor-menu" data-align={align} data-side={side} role="menu">
|
|
59
|
+
{children(() => setOpen(false))}
|
|
60
|
+
</div>
|
|
61
|
+
)}
|
|
62
|
+
</div>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { type FormEvent, useEffect, useId, useState } from "react";
|
|
2
|
+
import {
|
|
3
|
+
type ContentType,
|
|
4
|
+
type Item,
|
|
5
|
+
type ItemDraft,
|
|
6
|
+
type SeoSettings,
|
|
7
|
+
type SiteIdentityInfo,
|
|
8
|
+
type SitePage,
|
|
9
|
+
loadSiteInfo,
|
|
10
|
+
} from "./api.ts";
|
|
11
|
+
import { CheckboxWidget, TextWidget } from "./fields.tsx";
|
|
12
|
+
import { ItemFields } from "./ItemForm.tsx";
|
|
13
|
+
import { Fieldset, Sidebar } from "./Sidebar.tsx";
|
|
14
|
+
import { ImageUploadWidget, MediaFolderContext } from "./widgets.tsx";
|
|
15
|
+
|
|
16
|
+
/** What the page's own code gives for its head; shown wherever the owner has set nothing. */
|
|
17
|
+
export interface OwnSeo {
|
|
18
|
+
title?: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
image?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The item whose page is open, which the page settings also let the owner change. */
|
|
24
|
+
export interface PageItem {
|
|
25
|
+
type: ContentType;
|
|
26
|
+
item: Item;
|
|
27
|
+
onChange: (draft: ItemDraft) => void;
|
|
28
|
+
/** Each keystroke in one of the item's text fields, before it is saved: the page shows it at once. */
|
|
29
|
+
onDraft?: ((field: string, value: unknown) => void) | undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Lengths search engines show in full: a longer title or description is cut short in the results. */
|
|
33
|
+
const TITLE_LENGTH = 60;
|
|
34
|
+
const DESCRIPTION_LENGTH = 155;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The current page's own settings: any page of the site, or the page of one content item, whose title, address
|
|
38
|
+
* and fields come first. The page's SEO title, description and preview image are what search engines and link
|
|
39
|
+
* previews show, previewed as they will look. Each change is saved as it is made.
|
|
40
|
+
*/
|
|
41
|
+
export function PageSettings({
|
|
42
|
+
page,
|
|
43
|
+
own,
|
|
44
|
+
item,
|
|
45
|
+
onChange,
|
|
46
|
+
onMove,
|
|
47
|
+
onClose,
|
|
48
|
+
}: {
|
|
49
|
+
page: SitePage;
|
|
50
|
+
/** Absent when the page's layout has no `<Seo>`: then nothing set here reaches the page. */
|
|
51
|
+
own: OwnSeo | undefined;
|
|
52
|
+
item?: PageItem | undefined;
|
|
53
|
+
onChange: (seo: SeoSettings) => void;
|
|
54
|
+
/** Moves a page added from a template to a new address; resolves to false when it could not. */
|
|
55
|
+
onMove: (to: string) => Promise<boolean>;
|
|
56
|
+
onClose?: (() => void) | undefined;
|
|
57
|
+
}) {
|
|
58
|
+
const { seo } = page;
|
|
59
|
+
const set = (change: SeoSettings): void => onChange({ ...seo, ...change });
|
|
60
|
+
const [identity, setIdentity] = useState<SiteIdentityInfo | undefined>();
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
void loadSiteInfo().then((info) => setIdentity(info.identity));
|
|
63
|
+
}, []);
|
|
64
|
+
// What is being typed, so the previews follow each keystroke before the field is saved.
|
|
65
|
+
const [draft, setDraft] = useState<SeoSettings>({});
|
|
66
|
+
useEffect(() => setDraft({}), [seo]);
|
|
67
|
+
const live = { ...seo, ...draft };
|
|
68
|
+
const typing = (field: keyof SeoSettings) => (value: string) =>
|
|
69
|
+
setDraft((current) => ({ ...current, [field]: value }));
|
|
70
|
+
|
|
71
|
+
const title = titleOf(live.title || own?.title, identity);
|
|
72
|
+
const description = live.description || own?.description || identity?.description || "";
|
|
73
|
+
const image = live.image || own?.image || identity?.image || "";
|
|
74
|
+
const shareTitle = live.shareTitle || title;
|
|
75
|
+
const shareDescription = live.shareDescription || description;
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<Sidebar title="Page Settings" onClose={onClose}>
|
|
79
|
+
{!own && (
|
|
80
|
+
<p className="brim-sidebar-note" role="note">
|
|
81
|
+
This page's layout does not use Brim's Seo component in its head, so what you set here is saved but not shown
|
|
82
|
+
on the page.
|
|
83
|
+
</p>
|
|
84
|
+
)}
|
|
85
|
+
{item && (
|
|
86
|
+
<MediaFolderContext.Provider value={{ key: `${item.type.key}/${item.item.id}`, label: item.item.title }}>
|
|
87
|
+
<Fieldset title={item.type.singular} open>
|
|
88
|
+
<ItemFields type={item.type} draft={item.item} onChange={item.onChange} onDraft={item.onDraft} />
|
|
89
|
+
</Fieldset>
|
|
90
|
+
</MediaFolderContext.Provider>
|
|
91
|
+
)}
|
|
92
|
+
<Fieldset title="Search results" open={!item}>
|
|
93
|
+
<SearchPreview path={page.path} title={title} description={description} hidden={live.noindex === true} />
|
|
94
|
+
<TextWidget
|
|
95
|
+
label="SEO title"
|
|
96
|
+
description="Shown in the browser tab, in search results and on shared links. Empty uses the page's own title."
|
|
97
|
+
placeholder={own?.title}
|
|
98
|
+
value={seo.title ?? ""}
|
|
99
|
+
limit={TITLE_LENGTH}
|
|
100
|
+
onDraft={typing("title")}
|
|
101
|
+
onChange={(value) => set({ title: value })}
|
|
102
|
+
/>
|
|
103
|
+
<TextWidget
|
|
104
|
+
label="SEO description"
|
|
105
|
+
description="The short text under the title in search results and on shared links."
|
|
106
|
+
placeholder={own?.description ?? identity?.description ?? undefined}
|
|
107
|
+
value={seo.description ?? ""}
|
|
108
|
+
multiline
|
|
109
|
+
limit={DESCRIPTION_LENGTH}
|
|
110
|
+
onDraft={typing("description")}
|
|
111
|
+
onChange={(value) => set({ description: value })}
|
|
112
|
+
/>
|
|
113
|
+
</Fieldset>
|
|
114
|
+
<Fieldset title="Shared links">
|
|
115
|
+
<SharePreview path={page.path} title={shareTitle} description={shareDescription} image={image} />
|
|
116
|
+
<ImageUploadWidget
|
|
117
|
+
label="Preview image"
|
|
118
|
+
description="Shown when the page is shared on social networks and in chats. Best at 1200 × 630."
|
|
119
|
+
value={seo.image ?? ""}
|
|
120
|
+
onChange={(value) => set({ image: value })}
|
|
121
|
+
/>
|
|
122
|
+
<TextWidget
|
|
123
|
+
label="Title on shared links"
|
|
124
|
+
description="When a shared link should say something else than the search result. Empty uses the SEO title."
|
|
125
|
+
placeholder={title}
|
|
126
|
+
value={seo.shareTitle ?? ""}
|
|
127
|
+
onDraft={typing("shareTitle")}
|
|
128
|
+
onChange={(value) => set({ shareTitle: value })}
|
|
129
|
+
/>
|
|
130
|
+
<TextWidget
|
|
131
|
+
label="Description on shared links"
|
|
132
|
+
placeholder={description}
|
|
133
|
+
value={seo.shareDescription ?? ""}
|
|
134
|
+
multiline
|
|
135
|
+
onDraft={typing("shareDescription")}
|
|
136
|
+
onChange={(value) => set({ shareDescription: value })}
|
|
137
|
+
/>
|
|
138
|
+
</Fieldset>
|
|
139
|
+
<Fieldset title="Settings">
|
|
140
|
+
{!item && page.template && <AddressField path={page.path} onMove={onMove} />}
|
|
141
|
+
{!item && !page.template && (
|
|
142
|
+
<div className="field-group">
|
|
143
|
+
<span className="field-label">Address</span>
|
|
144
|
+
<p className="field-description">Where this page lives on the site. It comes from the site's code.</p>
|
|
145
|
+
<code className="brim-page-address">{page.path}</code>
|
|
146
|
+
</div>
|
|
147
|
+
)}
|
|
148
|
+
<CheckboxWidget
|
|
149
|
+
label="Hide from search engines"
|
|
150
|
+
description="Search engines leave the page out of their results, and it leaves the sitemap."
|
|
151
|
+
checked={seo.noindex ?? false}
|
|
152
|
+
onChange={(noindex) => set({ noindex })}
|
|
153
|
+
/>
|
|
154
|
+
<CheckboxWidget
|
|
155
|
+
label="Don't follow this page's links"
|
|
156
|
+
description="Search engines don't follow the links on this page to other pages."
|
|
157
|
+
checked={seo.nofollow ?? false}
|
|
158
|
+
onChange={(nofollow) => set({ nofollow })}
|
|
159
|
+
/>
|
|
160
|
+
<TextWidget
|
|
161
|
+
label="Canonical address"
|
|
162
|
+
description="When the same content is at another address, the one search engines should list: a path of this site (/pricing) or a full address. Empty is this page."
|
|
163
|
+
placeholder={page.path}
|
|
164
|
+
value={seo.canonical ?? ""}
|
|
165
|
+
onChange={(value) => set({ canonical: value })}
|
|
166
|
+
/>
|
|
167
|
+
</Fieldset>
|
|
168
|
+
</Sidebar>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** The address of a page added from a template: changed here, the old one redirects to it. */
|
|
173
|
+
function AddressField({ path, onMove }: { path: string; onMove: (to: string) => Promise<boolean> }) {
|
|
174
|
+
const id = useId();
|
|
175
|
+
const [draft, setDraft] = useState(path);
|
|
176
|
+
const [busy, setBusy] = useState(false);
|
|
177
|
+
useEffect(() => setDraft(path), [path]);
|
|
178
|
+
|
|
179
|
+
async function submit(event: FormEvent): Promise<void> {
|
|
180
|
+
event.preventDefault();
|
|
181
|
+
setBusy(true);
|
|
182
|
+
if (!(await onMove(draft.trim()))) setDraft(path);
|
|
183
|
+
setBusy(false);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
<form className="field-group" onSubmit={(event) => void submit(event)}>
|
|
188
|
+
<label className="field-label" htmlFor={id}>
|
|
189
|
+
Address
|
|
190
|
+
</label>
|
|
191
|
+
<p className="field-description">
|
|
192
|
+
Where this page lives on the site. When it changes, the old address keeps working and leads here.
|
|
193
|
+
</p>
|
|
194
|
+
<div className="brim-inline-form">
|
|
195
|
+
<input id={id} className="field-input" value={draft} onChange={(event) => setDraft(event.target.value)} />
|
|
196
|
+
<button type="submit" className="url-browse-btn" disabled={busy || draft.trim() === path}>
|
|
197
|
+
Change
|
|
198
|
+
</button>
|
|
199
|
+
</div>
|
|
200
|
+
</form>
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** The page's title as `<Seo>` writes it: with the site's title template, or the site's name when it has none. */
|
|
205
|
+
function titleOf(own: string | undefined, identity: SiteIdentityInfo | undefined): string {
|
|
206
|
+
const title = own?.trim();
|
|
207
|
+
if (!title) return identity?.name ?? "";
|
|
208
|
+
if (!identity?.titleTemplate || title === identity.name) return title;
|
|
209
|
+
return identity.titleTemplate.replace("%s", title);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** How the page shows in a search engine's results: address, title and description, cut where they cut. */
|
|
213
|
+
function SearchPreview({
|
|
214
|
+
path,
|
|
215
|
+
title,
|
|
216
|
+
description,
|
|
217
|
+
hidden,
|
|
218
|
+
}: {
|
|
219
|
+
path: string;
|
|
220
|
+
title: string;
|
|
221
|
+
description: string;
|
|
222
|
+
hidden: boolean;
|
|
223
|
+
}) {
|
|
224
|
+
const crumbs = [location.host, ...path.split("/").filter(Boolean)].join(" › ");
|
|
225
|
+
return (
|
|
226
|
+
<figure className="brim-seo-preview" aria-label="Search result preview">
|
|
227
|
+
{hidden && <p className="brim-seo-preview__note">Hidden from search engines: this result won't show.</p>}
|
|
228
|
+
<div className="brim-search-result" data-hidden={hidden ? "" : undefined}>
|
|
229
|
+
<span className="brim-search-result__url">{crumbs}</span>
|
|
230
|
+
<span className="brim-search-result__title">{title || "Untitled page"}</span>
|
|
231
|
+
<span className="brim-search-result__description">
|
|
232
|
+
{description || "No description: search engines pick a passage of the page."}
|
|
233
|
+
</span>
|
|
234
|
+
</div>
|
|
235
|
+
</figure>
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** How a link to the page shows when shared in a chat or on a social network. */
|
|
240
|
+
function SharePreview({
|
|
241
|
+
path,
|
|
242
|
+
title,
|
|
243
|
+
description,
|
|
244
|
+
image,
|
|
245
|
+
}: {
|
|
246
|
+
path: string;
|
|
247
|
+
title: string;
|
|
248
|
+
description: string;
|
|
249
|
+
image: string;
|
|
250
|
+
}) {
|
|
251
|
+
return (
|
|
252
|
+
<figure className="brim-seo-preview" aria-label="Shared link preview">
|
|
253
|
+
<div className="brim-share-card">
|
|
254
|
+
{image ? (
|
|
255
|
+
<img className="brim-share-card__image" src={image} alt="" />
|
|
256
|
+
) : (
|
|
257
|
+
<div className="brim-share-card__image brim-share-card__image--empty">No preview image</div>
|
|
258
|
+
)}
|
|
259
|
+
<div className="brim-share-card__text">
|
|
260
|
+
<span className="brim-share-card__host">
|
|
261
|
+
{location.host}
|
|
262
|
+
{path === "/" ? "" : path}
|
|
263
|
+
</span>
|
|
264
|
+
<span className="brim-share-card__title">{title || "Untitled page"}</span>
|
|
265
|
+
{description && <span className="brim-share-card__description">{description}</span>}
|
|
266
|
+
</div>
|
|
267
|
+
</div>
|
|
268
|
+
</figure>
|
|
269
|
+
);
|
|
270
|
+
}
|