@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,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small client for the tus resumable upload protocol (https://tus.io, version 1.0.0): one request creates
|
|
3
|
+
* the upload, then the file goes up in pieces. Only one piece is ever read from the file at a time, so a
|
|
4
|
+
* video of a few gigabytes never sits in memory.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** Where and how to upload, as a video host hands it out. */
|
|
8
|
+
export interface TusTarget {
|
|
9
|
+
endpoint: string;
|
|
10
|
+
/** Sent with every request: the host's own way of knowing the upload is allowed. */
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
/** Sent once, as `Upload-Metadata`, when the upload is created. */
|
|
13
|
+
metadata?: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface TusOptions {
|
|
17
|
+
/** Bytes per request. Progress is reported after each one. */
|
|
18
|
+
chunkSize?: number;
|
|
19
|
+
/** Aborting it stops the upload; the returned promise rejects with the signal's reason. */
|
|
20
|
+
signal?: AbortSignal;
|
|
21
|
+
onProgress?: (sentBytes: number, totalBytes: number) => void;
|
|
22
|
+
/** How often one piece is tried again after the connection or the server failed. */
|
|
23
|
+
retries?: number;
|
|
24
|
+
retryDelayMs?: number;
|
|
25
|
+
fetch?: typeof fetch;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class TusError extends Error {}
|
|
29
|
+
|
|
30
|
+
const VERSION = "1.0.0";
|
|
31
|
+
const DEFAULT_CHUNK_SIZE = 8 * 1024 * 1024;
|
|
32
|
+
|
|
33
|
+
/** `Upload-Metadata`: `key base64(value)` pairs, separated by commas. */
|
|
34
|
+
export function encodeMetadata(metadata: Record<string, string>): string {
|
|
35
|
+
return Object.entries(metadata)
|
|
36
|
+
.map(([key, value]) => {
|
|
37
|
+
const bytes = new TextEncoder().encode(String(value));
|
|
38
|
+
let binary = "";
|
|
39
|
+
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
40
|
+
return `${key} ${btoa(binary)}`;
|
|
41
|
+
})
|
|
42
|
+
.join(",");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Uploads `file` and resolves to the address of the finished upload. */
|
|
46
|
+
export async function tusUpload(file: Blob, target: TusTarget, options: TusOptions = {}): Promise<string> {
|
|
47
|
+
const send = options.fetch ?? fetch;
|
|
48
|
+
const chunkSize = options.chunkSize ?? DEFAULT_CHUNK_SIZE;
|
|
49
|
+
const retries = options.retries ?? 3;
|
|
50
|
+
const retryDelayMs = options.retryDelayMs ?? 1500;
|
|
51
|
+
const { signal } = options;
|
|
52
|
+
const common = { ...target.headers, "Tus-Resumable": VERSION };
|
|
53
|
+
const request = (url: string, init: RequestInit): Promise<Response> =>
|
|
54
|
+
send(url, { ...init, ...(signal && { signal }) });
|
|
55
|
+
|
|
56
|
+
const metadata = encodeMetadata(target.metadata ?? {});
|
|
57
|
+
const created = await request(target.endpoint, {
|
|
58
|
+
method: "POST",
|
|
59
|
+
headers: { ...common, "Upload-Length": String(file.size), ...(metadata && { "Upload-Metadata": metadata }) },
|
|
60
|
+
});
|
|
61
|
+
const location = created.headers.get("location");
|
|
62
|
+
if (created.status !== 201 || !location) {
|
|
63
|
+
throw new TusError(await failure(created, "The video host did not accept the upload."));
|
|
64
|
+
}
|
|
65
|
+
const uploadUrl = new URL(location, target.endpoint).href;
|
|
66
|
+
|
|
67
|
+
/** Where the server says the upload is, after a piece may or may not have arrived. */
|
|
68
|
+
async function serverOffset(): Promise<number> {
|
|
69
|
+
const head = await request(uploadUrl, { method: "HEAD", headers: common });
|
|
70
|
+
const offset = Number(head.headers.get("upload-offset"));
|
|
71
|
+
if (!head.ok || !Number.isSafeInteger(offset)) throw new TusError("The upload was lost. Start it again.");
|
|
72
|
+
return offset;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let offset = 0;
|
|
76
|
+
let attempt = 0;
|
|
77
|
+
options.onProgress?.(0, file.size);
|
|
78
|
+
while (offset < file.size) {
|
|
79
|
+
const piece = file.slice(offset, offset + chunkSize);
|
|
80
|
+
try {
|
|
81
|
+
const response = await request(uploadUrl, {
|
|
82
|
+
method: "PATCH",
|
|
83
|
+
headers: { ...common, "Upload-Offset": String(offset), "Content-Type": "application/offset+octet-stream" },
|
|
84
|
+
body: piece,
|
|
85
|
+
});
|
|
86
|
+
if (response.status >= 500 || response.status === 409 || response.status === 423) {
|
|
87
|
+
throw new RetryableError(await failure(response, "The upload was interrupted."));
|
|
88
|
+
}
|
|
89
|
+
if (!response.ok) throw new TusError(await failure(response, "The video host refused the upload."));
|
|
90
|
+
// A host that does not let the page read the header still took the whole piece.
|
|
91
|
+
const reported = Number(response.headers.get("upload-offset") ?? Number.NaN);
|
|
92
|
+
offset = Number.isSafeInteger(reported) && reported > offset ? reported : offset + piece.size;
|
|
93
|
+
attempt = 0;
|
|
94
|
+
options.onProgress?.(Math.min(offset, file.size), file.size);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if (signal?.aborted || error instanceof TusError) throw error;
|
|
97
|
+
// The connection dropped or the server stumbled: ask where it got to and go on from there.
|
|
98
|
+
if (++attempt > retries) {
|
|
99
|
+
throw new TusError(
|
|
100
|
+
error instanceof RetryableError ? error.message : "The connection was lost during the upload.",
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
await wait(retryDelayMs * attempt, signal);
|
|
104
|
+
// If even that cannot be asked, the same piece is tried again.
|
|
105
|
+
offset = await serverOffset().catch((lost) => {
|
|
106
|
+
if (signal?.aborted) throw lost;
|
|
107
|
+
return offset;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return uploadUrl;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
class RetryableError extends Error {}
|
|
115
|
+
|
|
116
|
+
/** What a refused request says about itself, when it says anything a person can read. */
|
|
117
|
+
async function failure(response: Response, fallback: string): Promise<string> {
|
|
118
|
+
const text = (await response.text().catch(() => "")).trim();
|
|
119
|
+
try {
|
|
120
|
+
const answer = JSON.parse(text) as { error?: unknown; message?: unknown };
|
|
121
|
+
const said = answer.error ?? answer.message;
|
|
122
|
+
if (typeof said === "string" && said) return said;
|
|
123
|
+
} catch {
|
|
124
|
+
// Not JSON: tus servers answer in plain text.
|
|
125
|
+
}
|
|
126
|
+
return text && text.length < 200 && !text.startsWith("<") ? text : fallback;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function wait(ms: number, signal: AbortSignal | undefined): Promise<void> {
|
|
130
|
+
return new Promise((resolve, reject) => {
|
|
131
|
+
const timer = setTimeout(resolve, ms);
|
|
132
|
+
signal?.addEventListener("abort", () => {
|
|
133
|
+
clearTimeout(timer);
|
|
134
|
+
reject(signal.reason);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { flushSync } from "react-dom";
|
|
3
|
+
|
|
4
|
+
export interface Rect {
|
|
5
|
+
top: number;
|
|
6
|
+
left: number;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function measure(element: HTMLElement): Rect {
|
|
12
|
+
const { top, left, width, height } = element.getBoundingClientRect();
|
|
13
|
+
return { top, left, width, height };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Position of an element inside the page frame, kept current while the page scrolls,
|
|
18
|
+
* resizes or changes. The frame is not scaled, so these are also overlay coordinates.
|
|
19
|
+
*/
|
|
20
|
+
export function useRect(element: HTMLElement | null): Rect | null {
|
|
21
|
+
const [rect, setRect] = useState<Rect | null>(null);
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (!element?.isConnected) return setRect(null);
|
|
25
|
+
const view = element.ownerDocument.defaultView;
|
|
26
|
+
if (!view) return setRect(null);
|
|
27
|
+
|
|
28
|
+
const update = (): void => setRect(element.isConnected ? measure(element) : null);
|
|
29
|
+
update();
|
|
30
|
+
|
|
31
|
+
const resizes = new view.ResizeObserver(update);
|
|
32
|
+
resizes.observe(element);
|
|
33
|
+
resizes.observe(element.ownerDocument.documentElement);
|
|
34
|
+
const mutations = new view.MutationObserver(update);
|
|
35
|
+
mutations.observe(element.ownerDocument.body, { childList: true, subtree: true, characterData: true });
|
|
36
|
+
// Drawn in the same frame as the scroll, not at React's next turn, so the toolbar keeps up with the page.
|
|
37
|
+
const scrolled = (): void => flushSync(update);
|
|
38
|
+
view.addEventListener("scroll", scrolled, { passive: true });
|
|
39
|
+
view.addEventListener("resize", update);
|
|
40
|
+
|
|
41
|
+
return () => {
|
|
42
|
+
resizes.disconnect();
|
|
43
|
+
mutations.disconnect();
|
|
44
|
+
view.removeEventListener("scroll", scrolled);
|
|
45
|
+
view.removeEventListener("resize", update);
|
|
46
|
+
};
|
|
47
|
+
}, [element]);
|
|
48
|
+
|
|
49
|
+
return rect;
|
|
50
|
+
}
|