@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,130 @@
|
|
|
1
|
+
import { type FormEvent, useEffect, useId, useState } from "react";
|
|
2
|
+
import { type Redirect, api } from "./api.ts";
|
|
3
|
+
import { CheckboxWidget } from "./fields.tsx";
|
|
4
|
+
import { TrashIcon } from "./icons.tsx";
|
|
5
|
+
import { Fieldset } from "./Sidebar.tsx";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The site's redirects, in Site Settings: old addresses that send visitors and search engines to new ones. A page
|
|
9
|
+
* added from a template gets one by itself when its address changes; these are the rest (a removed page, a short
|
|
10
|
+
* link). They answer on the server; a static build has none.
|
|
11
|
+
*/
|
|
12
|
+
export function RedirectsSettings() {
|
|
13
|
+
const id = useId();
|
|
14
|
+
const [redirects, setRedirects] = useState<Redirect[] | null>(null);
|
|
15
|
+
const [from, setFrom] = useState("");
|
|
16
|
+
const [to, setTo] = useState("");
|
|
17
|
+
const [temporary, setTemporary] = useState(false);
|
|
18
|
+
const [error, setError] = useState("");
|
|
19
|
+
const [busy, setBusy] = useState(false);
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
api.redirects().then(
|
|
23
|
+
(loaded) => setRedirects(loaded.redirects),
|
|
24
|
+
(failure: unknown) => setError(failure instanceof Error ? failure.message : String(failure)),
|
|
25
|
+
);
|
|
26
|
+
}, []);
|
|
27
|
+
|
|
28
|
+
async function save(next: Redirect[]): Promise<boolean> {
|
|
29
|
+
setBusy(true);
|
|
30
|
+
setError("");
|
|
31
|
+
try {
|
|
32
|
+
setRedirects((await api.setRedirects(next)).redirects);
|
|
33
|
+
return true;
|
|
34
|
+
} catch (failure) {
|
|
35
|
+
setError(failure instanceof Error ? failure.message : String(failure));
|
|
36
|
+
return false;
|
|
37
|
+
} finally {
|
|
38
|
+
setBusy(false);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function add(event: FormEvent): Promise<void> {
|
|
43
|
+
event.preventDefault();
|
|
44
|
+
if (!redirects) return;
|
|
45
|
+
const redirect: Redirect = { from: from.trim(), to: to.trim(), ...(temporary && { temporary: true }) };
|
|
46
|
+
if (await save([...redirects, redirect])) {
|
|
47
|
+
setFrom("");
|
|
48
|
+
setTo("");
|
|
49
|
+
setTemporary(false);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<Fieldset title="Redirects">
|
|
55
|
+
<p className="field-description">
|
|
56
|
+
Old addresses that send visitors, and search engines, to new ones. A page added from a template gets its own
|
|
57
|
+
when you change its address.
|
|
58
|
+
</p>
|
|
59
|
+
{redirects && redirects.length > 0 && (
|
|
60
|
+
<ul className="brim-redirects">
|
|
61
|
+
{redirects.map((redirect) => (
|
|
62
|
+
<li key={redirect.from} className="brim-redirects__row">
|
|
63
|
+
<span className="brim-redirects__addresses">
|
|
64
|
+
<code>{redirect.from}</code>
|
|
65
|
+
<span aria-hidden="true">→</span>
|
|
66
|
+
<code>{redirect.to}</code>
|
|
67
|
+
{redirect.temporary && <span className="cb-badge">302</span>}
|
|
68
|
+
</span>
|
|
69
|
+
<button
|
|
70
|
+
type="button"
|
|
71
|
+
className="brim-toolbar-btn brim-toolbar-btn--icon"
|
|
72
|
+
aria-label={`Remove the redirect from ${redirect.from}`}
|
|
73
|
+
title="Remove redirect"
|
|
74
|
+
disabled={busy}
|
|
75
|
+
onClick={() => void save(redirects.filter((candidate) => candidate !== redirect))}
|
|
76
|
+
>
|
|
77
|
+
<TrashIcon />
|
|
78
|
+
</button>
|
|
79
|
+
</li>
|
|
80
|
+
))}
|
|
81
|
+
</ul>
|
|
82
|
+
)}
|
|
83
|
+
{redirects && redirects.length === 0 && <p className="brim-sidebar-note">No redirects yet.</p>}
|
|
84
|
+
<form className="brim-redirects__new" onSubmit={(event) => void add(event)}>
|
|
85
|
+
<div className="field-group">
|
|
86
|
+
<label className="field-label" htmlFor={`${id}-from`}>
|
|
87
|
+
Old address
|
|
88
|
+
</label>
|
|
89
|
+
<input
|
|
90
|
+
id={`${id}-from`}
|
|
91
|
+
className="field-input"
|
|
92
|
+
placeholder="/old-page"
|
|
93
|
+
value={from}
|
|
94
|
+
required
|
|
95
|
+
onChange={(event) => setFrom(event.target.value)}
|
|
96
|
+
/>
|
|
97
|
+
</div>
|
|
98
|
+
<div className="field-group">
|
|
99
|
+
<label className="field-label" htmlFor={`${id}-to`}>
|
|
100
|
+
Goes to
|
|
101
|
+
</label>
|
|
102
|
+
<input
|
|
103
|
+
id={`${id}-to`}
|
|
104
|
+
className="field-input"
|
|
105
|
+
placeholder="/new-page or https://…"
|
|
106
|
+
value={to}
|
|
107
|
+
required
|
|
108
|
+
onChange={(event) => setTo(event.target.value)}
|
|
109
|
+
/>
|
|
110
|
+
</div>
|
|
111
|
+
<CheckboxWidget
|
|
112
|
+
label="Temporary (302)"
|
|
113
|
+
description="Search engines keep listing the old address. Leave it off for a page that moved for good."
|
|
114
|
+
checked={temporary}
|
|
115
|
+
onChange={setTemporary}
|
|
116
|
+
/>
|
|
117
|
+
<div className="field-group">
|
|
118
|
+
<button type="submit" className="url-browse-btn" disabled={busy || !redirects}>
|
|
119
|
+
Add redirect
|
|
120
|
+
</button>
|
|
121
|
+
</div>
|
|
122
|
+
</form>
|
|
123
|
+
{error && (
|
|
124
|
+
<p className="field-error" role="alert">
|
|
125
|
+
{error}
|
|
126
|
+
</p>
|
|
127
|
+
)}
|
|
128
|
+
</Fieldset>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import type { KeyboardEvent, PointerEvent } from "react";
|
|
2
|
+
|
|
3
|
+
/** The narrowest and widest the side panel can be dragged to; the page always keeps `PAGE_ROOM` beside it. */
|
|
4
|
+
const SIDEBAR_MIN = 260;
|
|
5
|
+
const SIDEBAR_MAX = 800;
|
|
6
|
+
const PAGE_ROOM = 360;
|
|
7
|
+
/** The narrowest the page preview can be dragged to: a small phone. */
|
|
8
|
+
const FRAME_MIN = 320;
|
|
9
|
+
/** One press of an arrow key on a handle. */
|
|
10
|
+
const KEY_STEP = 16;
|
|
11
|
+
const SIDEBAR_KEY = "brim-editor-sidebar-width";
|
|
12
|
+
|
|
13
|
+
/** The side panel's width the owner chose last time, in this browser; `null` for the editor's own. */
|
|
14
|
+
export function storedSidebarWidth(): number | null {
|
|
15
|
+
try {
|
|
16
|
+
const width = Number(localStorage.getItem(SIDEBAR_KEY));
|
|
17
|
+
return Number.isFinite(width) && width >= SIDEBAR_MIN ? width : null;
|
|
18
|
+
} catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function storeSidebarWidth(width: number | null): void {
|
|
24
|
+
try {
|
|
25
|
+
if (width === null) localStorage.removeItem(SIDEBAR_KEY);
|
|
26
|
+
else localStorage.setItem(SIDEBAR_KEY, String(Math.round(width)));
|
|
27
|
+
} catch {
|
|
28
|
+
// Without storage the width lasts until the editor is closed.
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const clamp = (value: number, min: number, max: number): number => Math.min(Math.max(value, min), Math.max(min, max));
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Follows the pointer from a press on a handle until it is let go, telling how far it moved. The page in the frame
|
|
36
|
+
* would take the pointer as it passes over it: while dragging, frames ignore it (`data-brim-resizing`).
|
|
37
|
+
*/
|
|
38
|
+
function drag(event: PointerEvent<HTMLElement>, onMove: (dx: number) => void, onEnd?: () => void): void {
|
|
39
|
+
if (event.button !== 0) return;
|
|
40
|
+
event.preventDefault();
|
|
41
|
+
const handle = event.currentTarget;
|
|
42
|
+
const startX = event.clientX;
|
|
43
|
+
const root = document.documentElement;
|
|
44
|
+
handle.setPointerCapture(event.pointerId);
|
|
45
|
+
root.dataset.brimResizing = "";
|
|
46
|
+
const move = (moved: globalThis.PointerEvent): void => onMove(moved.clientX - startX);
|
|
47
|
+
const end = (): void => {
|
|
48
|
+
handle.removeEventListener("pointermove", move);
|
|
49
|
+
handle.removeEventListener("pointerup", end);
|
|
50
|
+
handle.removeEventListener("pointercancel", end);
|
|
51
|
+
delete root.dataset.brimResizing;
|
|
52
|
+
onEnd?.();
|
|
53
|
+
};
|
|
54
|
+
handle.addEventListener("pointermove", move);
|
|
55
|
+
handle.addEventListener("pointerup", end);
|
|
56
|
+
handle.addEventListener("pointercancel", end);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The edge between the page and the side panel: dragged, it makes the panel wider or narrower, and the width is
|
|
61
|
+
* kept in this browser for next time. A double click, or Home, gives the panel its own width back.
|
|
62
|
+
*/
|
|
63
|
+
export function SidebarHandle({
|
|
64
|
+
workspace,
|
|
65
|
+
width,
|
|
66
|
+
onWidth,
|
|
67
|
+
}: {
|
|
68
|
+
/** The page and the panel side by side; the panel is the `.brim-sidebar` in it. */
|
|
69
|
+
workspace: HTMLElement | null;
|
|
70
|
+
width: number | null;
|
|
71
|
+
onWidth: (width: number | null) => void;
|
|
72
|
+
}) {
|
|
73
|
+
const panelWidth = (): number => workspace?.querySelector<HTMLElement>(".brim-sidebar")?.offsetWidth ?? 0;
|
|
74
|
+
const limit = (next: number): number =>
|
|
75
|
+
clamp(next, SIDEBAR_MIN, Math.min(SIDEBAR_MAX, (workspace?.clientWidth ?? Infinity) - PAGE_ROOM));
|
|
76
|
+
const choose = (next: number | null): void => {
|
|
77
|
+
const chosen = next === null ? null : limit(next);
|
|
78
|
+
onWidth(chosen);
|
|
79
|
+
storeSidebarWidth(chosen);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<div
|
|
84
|
+
className="brim-sidebar-handle"
|
|
85
|
+
role="separator"
|
|
86
|
+
aria-orientation="vertical"
|
|
87
|
+
aria-label="Side panel width: drag, or use the arrow keys"
|
|
88
|
+
aria-valuenow={Math.round(width ?? panelWidth())}
|
|
89
|
+
aria-valuemin={SIDEBAR_MIN}
|
|
90
|
+
aria-valuemax={SIDEBAR_MAX}
|
|
91
|
+
tabIndex={0}
|
|
92
|
+
title="Drag to make the side panel wider or narrower; double-click for its own width"
|
|
93
|
+
onPointerDown={(event) => {
|
|
94
|
+
const start = panelWidth();
|
|
95
|
+
let last = start;
|
|
96
|
+
drag(
|
|
97
|
+
event,
|
|
98
|
+
(dx) => {
|
|
99
|
+
// The panel is on the right: moving left widens it.
|
|
100
|
+
last = limit(start - dx);
|
|
101
|
+
onWidth(last);
|
|
102
|
+
},
|
|
103
|
+
() => storeSidebarWidth(last),
|
|
104
|
+
);
|
|
105
|
+
}}
|
|
106
|
+
onDoubleClick={() => choose(null)}
|
|
107
|
+
onKeyDown={(event: KeyboardEvent) => {
|
|
108
|
+
if (event.key === "ArrowLeft") choose(panelWidth() + KEY_STEP);
|
|
109
|
+
else if (event.key === "ArrowRight") choose(panelWidth() - KEY_STEP);
|
|
110
|
+
else if (event.key === "Home") choose(null);
|
|
111
|
+
else return;
|
|
112
|
+
event.preventDefault();
|
|
113
|
+
}}
|
|
114
|
+
/>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Handles on both sides of the page preview: dragged, they make the page narrower or wider around its middle, to see
|
|
120
|
+
* it at any width between a phone and the whole window. `null` is the width the chosen device gives it.
|
|
121
|
+
*/
|
|
122
|
+
export function FrameHandles({
|
|
123
|
+
canvas,
|
|
124
|
+
frame,
|
|
125
|
+
width,
|
|
126
|
+
dragging,
|
|
127
|
+
onWidth,
|
|
128
|
+
onDragging,
|
|
129
|
+
}: {
|
|
130
|
+
/** The area the preview sits in, which bounds how wide it can get. */
|
|
131
|
+
canvas: HTMLElement | null;
|
|
132
|
+
frame: HTMLElement | null;
|
|
133
|
+
width: number | null;
|
|
134
|
+
dragging: boolean;
|
|
135
|
+
onWidth: (width: number | null) => void;
|
|
136
|
+
onDragging: (dragging: boolean) => void;
|
|
137
|
+
}) {
|
|
138
|
+
const room = (): number => {
|
|
139
|
+
if (!canvas) return Infinity;
|
|
140
|
+
const style = getComputedStyle(canvas);
|
|
141
|
+
return canvas.clientWidth - Number.parseFloat(style.paddingLeft) - Number.parseFloat(style.paddingRight);
|
|
142
|
+
};
|
|
143
|
+
// As wide as the canvas allows is no chosen width at all: the device's own (the whole width on a desktop).
|
|
144
|
+
const choose = (next: number): void => {
|
|
145
|
+
const max = room();
|
|
146
|
+
onWidth(next >= max - 1 ? null : clamp(Math.round(next), FRAME_MIN, max));
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const handle = (side: "left" | "right") => (
|
|
150
|
+
<div
|
|
151
|
+
key={side}
|
|
152
|
+
className="brim-frame-handle"
|
|
153
|
+
data-side={side}
|
|
154
|
+
role="separator"
|
|
155
|
+
aria-orientation="vertical"
|
|
156
|
+
aria-label="Page width: drag, or use the arrow keys"
|
|
157
|
+
aria-valuenow={Math.round(width ?? frame?.offsetWidth ?? 0)}
|
|
158
|
+
aria-valuemin={FRAME_MIN}
|
|
159
|
+
tabIndex={0}
|
|
160
|
+
title="Drag to see the page narrower or wider; double-click for the device's own width"
|
|
161
|
+
onPointerDown={(event) => {
|
|
162
|
+
const start = frame?.offsetWidth ?? 0;
|
|
163
|
+
onDragging(true);
|
|
164
|
+
// The page stays centred, so it grows by both sides: twice what the pointer moved.
|
|
165
|
+
drag(
|
|
166
|
+
event,
|
|
167
|
+
(dx) => choose(start + (side === "right" ? dx : -dx) * 2),
|
|
168
|
+
() => onDragging(false),
|
|
169
|
+
);
|
|
170
|
+
}}
|
|
171
|
+
onDoubleClick={() => onWidth(null)}
|
|
172
|
+
onKeyDown={(event: KeyboardEvent) => {
|
|
173
|
+
const current = frame?.offsetWidth ?? 0;
|
|
174
|
+
const wider = side === "right" ? "ArrowRight" : "ArrowLeft";
|
|
175
|
+
const narrower = side === "right" ? "ArrowLeft" : "ArrowRight";
|
|
176
|
+
if (event.key === wider) choose(current + KEY_STEP * 2);
|
|
177
|
+
else if (event.key === narrower) choose(current - KEY_STEP * 2);
|
|
178
|
+
else if (event.key === "Home") onWidth(null);
|
|
179
|
+
else return;
|
|
180
|
+
event.preventDefault();
|
|
181
|
+
}}
|
|
182
|
+
>
|
|
183
|
+
<span className="brim-frame-handle__grip" />
|
|
184
|
+
</div>
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
const shown = width ?? (dragging ? frame?.offsetWidth : undefined);
|
|
188
|
+
return (
|
|
189
|
+
<>
|
|
190
|
+
{handle("left")}
|
|
191
|
+
{handle("right")}
|
|
192
|
+
{shown !== undefined && (
|
|
193
|
+
<div className="brim-frame-size" data-dragging={dragging ? "" : undefined}>
|
|
194
|
+
<span>{Math.round(shown)} px</span>
|
|
195
|
+
{width !== null && !dragging && (
|
|
196
|
+
<button type="button" onClick={() => onWidth(null)} title="Back to the device's own width">
|
|
197
|
+
Reset
|
|
198
|
+
</button>
|
|
199
|
+
)}
|
|
200
|
+
</div>
|
|
201
|
+
)}
|
|
202
|
+
</>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { ChevronDownIcon, CloseIcon } from "./icons.tsx";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The settings column on the right, always there beside the page: the selected element's settings, or the page's.
|
|
6
|
+
* A panel that can be left has a close button.
|
|
7
|
+
*/
|
|
8
|
+
export function Sidebar({
|
|
9
|
+
title,
|
|
10
|
+
onClose,
|
|
11
|
+
children,
|
|
12
|
+
}: {
|
|
13
|
+
title: string;
|
|
14
|
+
onClose?: (() => void) | undefined;
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
}) {
|
|
17
|
+
return (
|
|
18
|
+
// Focusable by the editor itself (F6 from the page), so the keyboard reaches the settings of what is selected.
|
|
19
|
+
<aside className="brim-sidebar" aria-label={title} tabIndex={-1}>
|
|
20
|
+
<header className="brim-sidebar-header">
|
|
21
|
+
<h2 className="brim-sidebar-title">{title}</h2>
|
|
22
|
+
{onClose && (
|
|
23
|
+
<button type="button" className="brim-sidebar-close-btn" aria-label="Close" title="Close" onClick={onClose}>
|
|
24
|
+
<CloseIcon />
|
|
25
|
+
</button>
|
|
26
|
+
)}
|
|
27
|
+
</header>
|
|
28
|
+
<div className="brim-sidebar-content">{children}</div>
|
|
29
|
+
</aside>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* One collapsible group of settings. Fieldsets in the same sidebar share a name,
|
|
35
|
+
* so opening one closes the others, as the browser's own exclusive accordion does.
|
|
36
|
+
*/
|
|
37
|
+
export function Fieldset({ title, open = false, children }: { title: string; open?: boolean; children: ReactNode }) {
|
|
38
|
+
return (
|
|
39
|
+
<details className="schema-fieldset" name="brim-sidebar-fieldsets" open={open}>
|
|
40
|
+
<summary className="fieldset-title">
|
|
41
|
+
<span className="fieldset-title-text">{title}</span>
|
|
42
|
+
<span className="fieldset-chevron">
|
|
43
|
+
<ChevronDownIcon />
|
|
44
|
+
</span>
|
|
45
|
+
</summary>
|
|
46
|
+
<div className="fieldset-fields">
|
|
47
|
+
<div className="fieldset-fields-inner">{children}</div>
|
|
48
|
+
</div>
|
|
49
|
+
</details>
|
|
50
|
+
);
|
|
51
|
+
}
|