@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,284 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
import { ArrowDownIcon, ArrowUpIcon, ChevronUpIcon, LinkIcon, PlusIcon, TrashIcon } from "./icons.tsx";
|
|
3
|
+
import { nodeKinds } from "./kinds.ts";
|
|
4
|
+
import { Menu } from "./Menu.tsx";
|
|
5
|
+
import { type TextKind, TextTools } from "./TextTools.tsx";
|
|
6
|
+
import { type Rect, useRect } from "./use-rect.ts";
|
|
7
|
+
|
|
8
|
+
const TOOLBAR_GAP = 44;
|
|
9
|
+
const EDGE = 8;
|
|
10
|
+
/** Half the + button (`.brim-inserter__button`), which is centred on the edge it adds after. */
|
|
11
|
+
const INSERTER_RADIUS = 14;
|
|
12
|
+
|
|
13
|
+
export function nodeLabel(element: HTMLElement): string {
|
|
14
|
+
// An element showing an item's picked value is named after the field (Date, Year, Category…).
|
|
15
|
+
const title = element.dataset.brimLabel ?? nodeKinds[element.dataset.brimKind ?? ""]?.title ?? "Element";
|
|
16
|
+
if (element.dataset.brimScope === "site") return `${title} · Shared across site`;
|
|
17
|
+
if (element.dataset.brimScope === "template" && element.dataset.brimItem === undefined) return `${title} · Template`;
|
|
18
|
+
return title;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The item field the selected element shows: the toolbar says so, since a change made on the page or in the page
|
|
23
|
+
* settings changes both.
|
|
24
|
+
*/
|
|
25
|
+
export interface Binding {
|
|
26
|
+
/** `Project · Summary` */
|
|
27
|
+
label: string;
|
|
28
|
+
/** The sentence shown on hover. */
|
|
29
|
+
note: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Why the selected element cannot be changed in this mode, and the button that switches to the mode where it can.
|
|
34
|
+
* An element only the site's code can change has no button.
|
|
35
|
+
*/
|
|
36
|
+
export interface Lock {
|
|
37
|
+
hint: string;
|
|
38
|
+
action?: string;
|
|
39
|
+
onAction?: () => void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* What can be done on a stack of blocks, or on one block of it: the + adds a block after it, the element's toolbar
|
|
44
|
+
* moves or deletes it. Moves and delete are set on a block only.
|
|
45
|
+
*/
|
|
46
|
+
export interface StackActions {
|
|
47
|
+
types: { type: string; label: string }[];
|
|
48
|
+
/** Adds a block after the selected one, or at the end of the stack. */
|
|
49
|
+
onAdd: (type: string) => void;
|
|
50
|
+
/** Each is absent where there is no room to move. */
|
|
51
|
+
onMoveUp?: (() => void) | undefined;
|
|
52
|
+
onMoveDown?: (() => void) | undefined;
|
|
53
|
+
onDelete?: (() => void) | undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Marks the element's outline on the page itself (`data-brim-outline`, styled by the editor's page style), so it
|
|
58
|
+
* moves with the page as it scrolls, with no delay, also on a sticky or fixed element. Drawn over the frame from
|
|
59
|
+
* outside, it could only follow each scroll event a frame later.
|
|
60
|
+
*/
|
|
61
|
+
function usePageOutline(element: HTMLElement | null, state: "hover" | "selected"): void {
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (!element) return;
|
|
64
|
+
element.setAttribute("data-brim-outline", state);
|
|
65
|
+
return () => {
|
|
66
|
+
if (element.getAttribute("data-brim-outline") === state) element.removeAttribute("data-brim-outline");
|
|
67
|
+
};
|
|
68
|
+
}, [element, state]);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Outlines, the hover label and the element toolbar of the page being edited. */
|
|
72
|
+
export function Chrome({
|
|
73
|
+
hovered,
|
|
74
|
+
selected,
|
|
75
|
+
editing,
|
|
76
|
+
formatting,
|
|
77
|
+
locked,
|
|
78
|
+
binding,
|
|
79
|
+
stack,
|
|
80
|
+
inserters,
|
|
81
|
+
onTextElement,
|
|
82
|
+
onSelectParent,
|
|
83
|
+
}: {
|
|
84
|
+
hovered: HTMLElement | null;
|
|
85
|
+
selected: HTMLElement | null;
|
|
86
|
+
/** The text element being edited in place, if any. */
|
|
87
|
+
editing: HTMLElement | null;
|
|
88
|
+
/** Whether the text being edited takes formatting; a plain text field of an item does not. */
|
|
89
|
+
formatting: boolean;
|
|
90
|
+
/** Set when the selected element belongs to the other mode: the toolbar then only says so. */
|
|
91
|
+
locked: Lock | undefined;
|
|
92
|
+
/** Set when the selected element shows a field of the item. */
|
|
93
|
+
binding?: Binding | undefined;
|
|
94
|
+
/** Set when the selected element is a stack of blocks or one of its blocks: its moves and delete. */
|
|
95
|
+
stack: StackActions | undefined;
|
|
96
|
+
/** Where a + adds a block: under each stack of blocks, or under its selected block. */
|
|
97
|
+
inserters: { anchor: HTMLElement; actions: StackActions }[];
|
|
98
|
+
onTextElement: (tag: string) => void;
|
|
99
|
+
/** Absent when the selected node has no editable parent. */
|
|
100
|
+
onSelectParent: (() => void) | undefined;
|
|
101
|
+
}) {
|
|
102
|
+
const shownHover = hovered !== selected && !editing ? hovered : null;
|
|
103
|
+
const hoverRect = useRect(shownHover);
|
|
104
|
+
const selectedRect = useRect(selected);
|
|
105
|
+
usePageOutline(shownHover, "hover");
|
|
106
|
+
usePageOutline(selected, "selected");
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<div className="brim-chrome">
|
|
110
|
+
{inserters.map(({ anchor, actions }) => (
|
|
111
|
+
<Inserter key={anchor.dataset.brimNode} anchor={anchor} actions={actions} />
|
|
112
|
+
))}
|
|
113
|
+
{hovered && hoverRect && (
|
|
114
|
+
<>
|
|
115
|
+
<div
|
|
116
|
+
className="brim-hover-label"
|
|
117
|
+
style={{ top: Math.max(EDGE, hoverRect.top - 26), left: Math.max(EDGE, hoverRect.left) }}
|
|
118
|
+
>
|
|
119
|
+
{nodeLabel(hovered)}
|
|
120
|
+
</div>
|
|
121
|
+
</>
|
|
122
|
+
)}
|
|
123
|
+
{selected && selectedRect && (
|
|
124
|
+
<>
|
|
125
|
+
<ElementToolbar rect={selectedRect} label={nodeLabel(selected)}>
|
|
126
|
+
{binding && (
|
|
127
|
+
<span className="brim-element__toolbar-binding" title={binding.note} aria-label={binding.note}>
|
|
128
|
+
<LinkIcon />
|
|
129
|
+
{binding.label}
|
|
130
|
+
</span>
|
|
131
|
+
)}
|
|
132
|
+
{locked && (
|
|
133
|
+
<>
|
|
134
|
+
<span className="brim-element__toolbar-hint">{locked.hint}</span>
|
|
135
|
+
{locked.action && (
|
|
136
|
+
<button
|
|
137
|
+
type="button"
|
|
138
|
+
className="brim-element__toolbar-btn brim-element__toolbar-btn--label"
|
|
139
|
+
onClick={locked.onAction}
|
|
140
|
+
>
|
|
141
|
+
{locked.action}
|
|
142
|
+
</button>
|
|
143
|
+
)}
|
|
144
|
+
</>
|
|
145
|
+
)}
|
|
146
|
+
{editing && formatting && (
|
|
147
|
+
<TextTools element={editing} kind={editing.dataset.brimKind as TextKind} onElement={onTextElement} />
|
|
148
|
+
)}
|
|
149
|
+
{!locked && stack && (
|
|
150
|
+
<>
|
|
151
|
+
{stack.onMoveUp && (
|
|
152
|
+
<button
|
|
153
|
+
type="button"
|
|
154
|
+
className="brim-element__toolbar-btn"
|
|
155
|
+
title="Move up"
|
|
156
|
+
aria-label="Move up"
|
|
157
|
+
onClick={stack.onMoveUp}
|
|
158
|
+
>
|
|
159
|
+
<ArrowUpIcon />
|
|
160
|
+
</button>
|
|
161
|
+
)}
|
|
162
|
+
{stack.onMoveDown && (
|
|
163
|
+
<button
|
|
164
|
+
type="button"
|
|
165
|
+
className="brim-element__toolbar-btn"
|
|
166
|
+
title="Move down"
|
|
167
|
+
aria-label="Move down"
|
|
168
|
+
onClick={stack.onMoveDown}
|
|
169
|
+
>
|
|
170
|
+
<ArrowDownIcon />
|
|
171
|
+
</button>
|
|
172
|
+
)}
|
|
173
|
+
{stack.onDelete && (
|
|
174
|
+
<button
|
|
175
|
+
type="button"
|
|
176
|
+
className="brim-element__toolbar-btn"
|
|
177
|
+
title="Delete block"
|
|
178
|
+
aria-label="Delete block"
|
|
179
|
+
onClick={stack.onDelete}
|
|
180
|
+
>
|
|
181
|
+
<TrashIcon />
|
|
182
|
+
</button>
|
|
183
|
+
)}
|
|
184
|
+
</>
|
|
185
|
+
)}
|
|
186
|
+
{!locked && onSelectParent && (
|
|
187
|
+
<button
|
|
188
|
+
type="button"
|
|
189
|
+
className="brim-element__toolbar-btn"
|
|
190
|
+
title="Select parent"
|
|
191
|
+
aria-label="Select parent"
|
|
192
|
+
onClick={onSelectParent}
|
|
193
|
+
>
|
|
194
|
+
<ChevronUpIcon />
|
|
195
|
+
</button>
|
|
196
|
+
)}
|
|
197
|
+
</ElementToolbar>
|
|
198
|
+
</>
|
|
199
|
+
)}
|
|
200
|
+
</div>
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* A round + on the bottom edge of a stack of blocks or of one block, offering the blocks to add there. It shows only
|
|
206
|
+
* while the whole button is inside the frame: drawn past the frame's edge it would make the canvas scroll, and the
|
|
207
|
+
* scrollbar narrows the page, which moves the edge, which takes the scrollbar away again, over and over.
|
|
208
|
+
*/
|
|
209
|
+
function Inserter({ anchor, actions }: { anchor: HTMLElement; actions: StackActions }) {
|
|
210
|
+
const rect = useRect(anchor);
|
|
211
|
+
if (!rect) return null;
|
|
212
|
+
const edge = rect.top + rect.height;
|
|
213
|
+
const frameHeight = anchor.ownerDocument.documentElement.clientHeight;
|
|
214
|
+
if (edge - INSERTER_RADIUS < 0 || edge + INSERTER_RADIUS > frameHeight) return null;
|
|
215
|
+
return (
|
|
216
|
+
<div className="brim-inserter" style={{ top: edge, left: rect.left + rect.width / 2 }}>
|
|
217
|
+
<Menu
|
|
218
|
+
label="Add a block"
|
|
219
|
+
className="brim-inserter__button"
|
|
220
|
+
trigger={<PlusIcon />}
|
|
221
|
+
// Low on the page, the list opens upwards, so it stays inside the frame too.
|
|
222
|
+
side={edge > frameHeight / 2 ? "above" : "below"}
|
|
223
|
+
>
|
|
224
|
+
{(close) =>
|
|
225
|
+
actions.types.map(({ type, label }) => (
|
|
226
|
+
<button
|
|
227
|
+
key={type}
|
|
228
|
+
type="button"
|
|
229
|
+
role="menuitem"
|
|
230
|
+
className="brim-editor-menu__item"
|
|
231
|
+
onClick={() => {
|
|
232
|
+
close();
|
|
233
|
+
actions.onAdd(type);
|
|
234
|
+
}}
|
|
235
|
+
>
|
|
236
|
+
{label}
|
|
237
|
+
</button>
|
|
238
|
+
))
|
|
239
|
+
}
|
|
240
|
+
</Menu>
|
|
241
|
+
</div>
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Sits just above the element, kept inside the frame: at its top edge when the element is scrolled up out of
|
|
247
|
+
* sight, at its bottom edge when it is below. Past the frame it would make the canvas scroll.
|
|
248
|
+
*/
|
|
249
|
+
function ElementToolbar({ rect, label, children }: { rect: Rect; label: string; children: React.ReactNode }) {
|
|
250
|
+
const toolbar = useRef<HTMLDivElement>(null);
|
|
251
|
+
const [left, setLeft] = useState(rect.left);
|
|
252
|
+
/** On a narrow screen the bar wraps onto more rows: it then sits higher, so it does not cover the element. */
|
|
253
|
+
const [height, setHeight] = useState(TOOLBAR_GAP);
|
|
254
|
+
/** The lowest the bar can sit and still be inside the frame. */
|
|
255
|
+
const [lowest, setLowest] = useState(Number.POSITIVE_INFINITY);
|
|
256
|
+
|
|
257
|
+
useLayoutEffect(() => {
|
|
258
|
+
const bar = toolbar.current;
|
|
259
|
+
const area = bar?.parentElement;
|
|
260
|
+
if (!bar || !area) return;
|
|
261
|
+
setLeft(Math.max(EDGE, Math.min(rect.left, area.clientWidth - bar.offsetWidth - EDGE)));
|
|
262
|
+
setHeight(Math.max(TOOLBAR_GAP, bar.offsetHeight + 6));
|
|
263
|
+
setLowest(area.clientHeight - bar.offsetHeight - EDGE);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
return (
|
|
267
|
+
<div
|
|
268
|
+
ref={toolbar}
|
|
269
|
+
className="brim-element__toolbar-cluster"
|
|
270
|
+
style={{ top: Math.max(EDGE, Math.min(rect.top - height, lowest)), left }}
|
|
271
|
+
>
|
|
272
|
+
<div
|
|
273
|
+
className="brim-element__toolbar brim-element__toolbar--visible"
|
|
274
|
+
role="toolbar"
|
|
275
|
+
aria-label={`${label} actions`}
|
|
276
|
+
>
|
|
277
|
+
<span className="brim-element__toolbar-scope" title={label}>
|
|
278
|
+
{label}
|
|
279
|
+
</span>
|
|
280
|
+
{children}
|
|
281
|
+
</div>
|
|
282
|
+
</div>
|
|
283
|
+
);
|
|
284
|
+
}
|