bearminion 1.10.1 → 1.12.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/CHANGELOG.md +16 -0
- package/dist/astro.d.ts +2 -2
- package/dist/astro.js +38 -14
- package/dist/cli.js +1 -1
- package/dist/content.d.ts +1 -1
- package/dist/content.js +2 -2
- package/dist/{forms-dev-CaxRmLhl.js → forms-dev-CEab55ss.js} +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/{options-4HWVEj9O.d.ts → options-WI_ztZTj.d.ts} +42 -1
- package/dist/{page-CA4iyFDS.d.ts → page-CwbIDegI.d.ts} +10 -1
- package/dist/{page-X-WnOu7-.js → page-wlcQJAA-.js} +17 -1
- package/dist/{preview-B_88I5Jm.js → preview-ImEm3T8k.js} +1 -1
- package/dist/{reload-DA07O8cA.js → reload-BIIa7pej.js} +1 -1
- package/dist/{security-DOvoYZuQ.js → security-FLvgc2jD.js} +5 -5
- package/dist/{theme-Dv7_7B56.js → theme-BvqJ8UnS.js} +1 -1
- package/dist/ui/mount.js +177 -22
- package/dist/upload-rules-Cao9uY5K.js +36 -0
- package/package.json +1 -1
- package/registry/default/registry.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# bearminion
|
|
2
2
|
|
|
3
|
+
## 1.12.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 1435da5: `bearminion({ pages: { rename: false, delete: false } })` locks page operations for sites whose addresses carry search ranking or are the target of redirects. Both default to `true`, so nothing changes unless you set them. A locked operation is refused by the API with `409` `operation_locked`, whoever asks: the rename route, the delete route, set-home, and a save that changes a slug (making another page the home page counts as a rename, because the old home page moves to a new address). The editor makes the slug read-only, disables the Home page switch and hides Delete. `GET /schema` reports the rules as `pageRules`.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 1435da5: The New page form makes the slug from the title as you type it, until you edit the slug by hand, and numbers it when a page with that slug exists (`about-2`). Changing a title afterwards never changes the slug. A failed create now shows the server's reason in the form instead of doing nothing. `slugifyAnchor` writes accented letters as the plain letter (`ą` is `a`, `ł` is `l`, `ß` is `ss`) instead of turning them into hyphens, so `Łódź` is `lodz` and not `o-dz`; this also fixes section anchors suggested from non-ASCII headings.
|
|
12
|
+
|
|
13
|
+
## 1.11.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- a5d09d9: Upload rules for images. `maxImageBytes` sets the largest image the editor accepts (default 5 MB, as before); the editor now checks it in the browser and names the file size and the limit before anything is uploaded. `imageConvert: { to: 'webp', maxWidth, quality }` makes the editor scale and re-encode images as WebP in the browser before they are uploaded, which keeps large phone photos out of the repository and drops their metadata. It is off by default, an image that would come out larger is kept as it is, and GIFs are never converted. `GET /images` also returns the rules as `limits`.
|
|
18
|
+
|
|
3
19
|
## 1.10.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/astro.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import { a as StoreKeyError, c as createFileStore, i as FileStoreOptions, n as EditorContext, o as StoreOperation, r as ContentStore, s as UploadStore, t as BearminionOptions } from "./options-
|
|
1
|
+
import { A as ContentModel, X as SiteOf, Xt as ContentMigrator, Y as SiteDefinition, d as SectionOf, j as SectionRegistry, t as Page } from "./page-CwbIDegI.js";
|
|
2
|
+
import { a as StoreKeyError, c as createFileStore, i as FileStoreOptions, n as EditorContext, o as StoreOperation, r as ContentStore, s as UploadStore, t as BearminionOptions } from "./options-WI_ztZTj.js";
|
|
3
3
|
import { AstroIntegration } from "astro";
|
|
4
4
|
//#region src/integration.d.ts
|
|
5
5
|
interface BearminionIntegration extends AstroIntegration {
|
package/dist/astro.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { a as imageFields, c as ContentReadError, l as ContentValidationError, r as loadThemePreview, t as PreviewUnavailableError } from "./preview-
|
|
2
|
-
import { t as defaultTheme } from "./theme-
|
|
3
|
-
import {
|
|
1
|
+
import { a as imageFields, c as ContentReadError, l as ContentValidationError, r as loadThemePreview, t as PreviewUnavailableError } from "./preview-ImEm3T8k.js";
|
|
2
|
+
import { t as defaultTheme } from "./theme-BvqJ8UnS.js";
|
|
3
|
+
import { a as resolvePageRules, c as withoutOrphanSections, d as isOrphanSection, i as isSystemPage, n as createPageSchema$1, r as createTolerantPageSchema } from "./page-wlcQJAA-.js";
|
|
4
4
|
import { a as DEFAULT_UPLOADS_DIR, i as DEFAULT_CONTENT_DIR, n as createMigrator, o as DEFAULT_VIDEOS_DIR, r as API_PREFIX, t as SCHEMA_VERSION_KEY } from "./migrate-b408EaLp.js";
|
|
5
|
-
import {
|
|
6
|
-
import { a as
|
|
5
|
+
import { i as resolveMaxImageBytes, n as formatBytes, r as resolveConvert } from "./upload-rules-Cao9uY5K.js";
|
|
6
|
+
import { a as isLocalRequest, c as resolveInside, i as isInside, n as JSON_BODY_LIMIT, o as readSlug, r as asDirectory, s as resolveDir, t as IMAGE_BYTE_LIMIT } from "./security-FLvgc2jD.js";
|
|
7
|
+
import { a as resolveFormsConfig, n as formFile, r as formsAreLive, t as createFormsMiddleware } from "./forms-dev-CEab55ss.js";
|
|
7
8
|
import { S as isAssetPath, b as describeSiteRef, c as projectId, v as assetRefs, y as describePageRef } from "./draft-store-1Y4-sn45.js";
|
|
8
|
-
import { n as contentReloadPlugin, r as dropEarlyReloadAfterSave } from "./reload-
|
|
9
|
+
import { n as contentReloadPlugin, r as dropEarlyReloadAfterSave } from "./reload-BIIa7pej.js";
|
|
9
10
|
import { i as syncSections, r as staleSectionsMessage } from "./sections-manifest-CO9QfJPG.js";
|
|
10
11
|
import { z } from "zod";
|
|
11
12
|
import fs from "node:fs";
|
|
@@ -295,8 +296,12 @@ async function deleteImage(uploadsDir, filename) {
|
|
|
295
296
|
return false;
|
|
296
297
|
}
|
|
297
298
|
}
|
|
298
|
-
function imageTooLarge(size) {
|
|
299
|
-
return size >
|
|
299
|
+
function imageTooLarge(size, maxBytes = IMAGE_BYTE_LIMIT) {
|
|
300
|
+
return size > maxBytes;
|
|
301
|
+
}
|
|
302
|
+
/** The largest request body an image upload may have: the file plus room for the multipart boundaries. */
|
|
303
|
+
function imageBodyLimit(maxBytes) {
|
|
304
|
+
return maxBytes + 262144;
|
|
300
305
|
}
|
|
301
306
|
function safeStem(originalName) {
|
|
302
307
|
return path.win32.basename(path.basename(originalName)).replace(/\.[^.]+$/, "").normalize("NFKD").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 48) || "image";
|
|
@@ -439,6 +444,9 @@ function resolveEditorContext(options, rootInput) {
|
|
|
439
444
|
uploadsDir,
|
|
440
445
|
videosDir,
|
|
441
446
|
maxVideoBytes: options?.maxVideoBytes ?? 52428800,
|
|
447
|
+
maxImageBytes: resolveMaxImageBytes(options?.maxImageBytes),
|
|
448
|
+
pageRules: resolvePageRules(options?.pages),
|
|
449
|
+
imageConvert: resolveConvert(options?.imageConvert),
|
|
442
450
|
sections: options.sections,
|
|
443
451
|
site: options.site,
|
|
444
452
|
theme: options.theme ?? defaultTheme,
|
|
@@ -853,6 +861,7 @@ async function getSchema(context) {
|
|
|
853
861
|
fieldImages,
|
|
854
862
|
showWhen,
|
|
855
863
|
sectionForms,
|
|
864
|
+
pageRules: context.pageRules,
|
|
856
865
|
sectionDefaults,
|
|
857
866
|
sectionLabels,
|
|
858
867
|
sectionDescriptions,
|
|
@@ -1008,6 +1017,7 @@ async function planPageSave(context, input) {
|
|
|
1008
1017
|
removals: [],
|
|
1009
1018
|
after
|
|
1010
1019
|
};
|
|
1020
|
+
if (!context.pageRules.rename) return { response: locked("rename") };
|
|
1011
1021
|
if (from === "index") return { response: problem(409, "conflict", "The home page slug stays index. Set another page as home to move it.") };
|
|
1012
1022
|
if (isSystemPage(from) || isSystemPage(target)) return { response: problem(409, "reserved_slug", "System pages cannot be renamed, and no page can take their slug.") };
|
|
1013
1023
|
if (target !== "index") {
|
|
@@ -1136,7 +1146,11 @@ async function createPage(request, context) {
|
|
|
1136
1146
|
await writeDocuments(context, [[key, validated.data]]);
|
|
1137
1147
|
return json(201, validated.data);
|
|
1138
1148
|
}
|
|
1149
|
+
function locked(operation) {
|
|
1150
|
+
return problem(409, "operation_locked", `${operation === "rename" ? "Renaming pages" : "Deleting pages"} is turned off for this site (pages.${operation} in the bearminion() options).`);
|
|
1151
|
+
}
|
|
1139
1152
|
async function deletePage(context, slug) {
|
|
1153
|
+
if (!context.pageRules.delete) return locked("delete");
|
|
1140
1154
|
if (slug === "index") return problem(409, "conflict", "Refusing to delete the index page.");
|
|
1141
1155
|
if (isSystemPage(slug)) return problem(409, "reserved_slug", `"${slug}" is a system page and cannot be deleted.`);
|
|
1142
1156
|
const loaded = await loadStoredPages(context);
|
|
@@ -1158,6 +1172,7 @@ async function setHome(request, context, slug) {
|
|
|
1158
1172
|
if (body.response) return body.response;
|
|
1159
1173
|
const parsed = setHomeSchema.safeParse(body.value);
|
|
1160
1174
|
if (!parsed.success) return validation(fieldIssues(parsed.error));
|
|
1175
|
+
if (!context.pageRules.rename) return locked("rename");
|
|
1161
1176
|
if (slug === "index") return problem(409, "conflict", "That page is already the home page.");
|
|
1162
1177
|
if (isSystemPage(slug)) return problem(409, "reserved_slug", `"${slug}" is a system page and cannot be the home page.`);
|
|
1163
1178
|
const loaded = await loadStoredPages(context);
|
|
@@ -1200,6 +1215,7 @@ async function renamePage(request, context, slug) {
|
|
|
1200
1215
|
const parsed = renameSchema.safeParse(body.value);
|
|
1201
1216
|
if (!parsed.success) return validation(fieldIssues(parsed.error));
|
|
1202
1217
|
const nextSlug = parsed.data.slug;
|
|
1218
|
+
if (!context.pageRules.rename) return locked("rename");
|
|
1203
1219
|
if (nextSlug === slug) return problem(400, "invalid_slug", "The new slug is the same as the current slug.");
|
|
1204
1220
|
if (slug === "index") return problem(409, "conflict", "Refusing to rename the index page.");
|
|
1205
1221
|
if (isSystemPage(slug) || isSystemPage(nextSlug)) return problem(409, "reserved_slug", "System pages cannot be renamed, and no page can take their slug.");
|
|
@@ -1262,7 +1278,14 @@ async function postSitePreview(request, context, meta) {
|
|
|
1262
1278
|
}
|
|
1263
1279
|
}
|
|
1264
1280
|
async function getImages(context) {
|
|
1265
|
-
|
|
1281
|
+
const limits = {
|
|
1282
|
+
maxBytes: context.maxImageBytes,
|
|
1283
|
+
convert: context.imageConvert
|
|
1284
|
+
};
|
|
1285
|
+
return json(200, {
|
|
1286
|
+
images: await context.store.uploads.list(),
|
|
1287
|
+
limits
|
|
1288
|
+
});
|
|
1266
1289
|
}
|
|
1267
1290
|
function decodeSegment(segment) {
|
|
1268
1291
|
try {
|
|
@@ -1397,8 +1420,9 @@ async function postVideo(request, context) {
|
|
|
1397
1420
|
}
|
|
1398
1421
|
}
|
|
1399
1422
|
async function postImage(request, context) {
|
|
1423
|
+
const tooLarge = () => problem(413, "too_large", `Images must be ${formatBytes(context.maxImageBytes)} or smaller.`);
|
|
1400
1424
|
const length = contentLength(request);
|
|
1401
|
-
if (length !== null && length >
|
|
1425
|
+
if (length !== null && length > imageBodyLimit(context.maxImageBytes)) return tooLarge();
|
|
1402
1426
|
if (!(request.headers.get("content-type") ?? "").toLowerCase().includes("multipart/form-data")) return problem(415, "unsupported_media_type", "Upload the image as multipart/form-data.");
|
|
1403
1427
|
let form;
|
|
1404
1428
|
try {
|
|
@@ -1408,9 +1432,9 @@ async function postImage(request, context) {
|
|
|
1408
1432
|
}
|
|
1409
1433
|
const entry = form.get("file");
|
|
1410
1434
|
if (!(entry instanceof File)) return problem(400, "invalid_upload", "Expected a multipart file field named \"file\".");
|
|
1411
|
-
if (imageTooLarge(entry.size)) return
|
|
1435
|
+
if (imageTooLarge(entry.size, context.maxImageBytes)) return tooLarge();
|
|
1412
1436
|
const bytes = new Uint8Array(await entry.arrayBuffer());
|
|
1413
|
-
if (imageTooLarge(bytes.byteLength)) return
|
|
1437
|
+
if (imageTooLarge(bytes.byteLength, context.maxImageBytes)) return tooLarge();
|
|
1414
1438
|
const declared = kindFromMime(entry.type);
|
|
1415
1439
|
const sniffed = sniffImage(bytes);
|
|
1416
1440
|
if (declared === null || sniffed === null || declared !== sniffed) return problem(415, "unsupported_media_type", "Upload a png, jpeg, webp, gif, or avif file whose contents match the declared type.");
|
|
@@ -1698,8 +1722,8 @@ async function dispatch(req, res, context, rawUrl, hooks) {
|
|
|
1698
1722
|
const method = (req.method ?? "GET").toUpperCase();
|
|
1699
1723
|
const multipart = (headers.get("content-type") ?? "").toLowerCase().includes("multipart/form-data");
|
|
1700
1724
|
const videoUpload = multipart && stripTrailingSlash(rawUrl.split("?")[0] ?? "") === `/__bearminion/api/videos`;
|
|
1701
|
-
const limit = videoUpload ? videoBodyLimit(context.maxVideoBytes) : multipart ?
|
|
1702
|
-
const tooLargeMessage = videoUpload ? "Upload exceeds the video size limit." : multipart ?
|
|
1725
|
+
const limit = videoUpload ? videoBodyLimit(context.maxVideoBytes) : multipart ? imageBodyLimit(context.maxImageBytes) : JSON_BODY_LIMIT;
|
|
1726
|
+
const tooLargeMessage = videoUpload ? "Upload exceeds the video size limit." : multipart ? `Upload exceeds the ${formatBytes(context.maxImageBytes)} image limit.` : "JSON body exceeds 1MB.";
|
|
1703
1727
|
const advertised = Number(headers.get("content-length") ?? "");
|
|
1704
1728
|
if (Number.isFinite(advertised) && advertised > limit) {
|
|
1705
1729
|
await send(res, jsonProblem(413, "too_large", tooLargeMessage));
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { i as readDotEnv } from "./forms-dev-
|
|
2
|
+
import { i as readDotEnv } from "./forms-dev-CEab55ss.js";
|
|
3
3
|
import { i as syncSections, r as staleSectionsMessage, t as SectionsError } from "./sections-manifest-CO9QfJPG.js";
|
|
4
4
|
import { i as writeLock, n as readLock, r as recordFiles, t as hashContent } from "./hash-BeBymBO1.js";
|
|
5
5
|
import fs from "node:fs";
|
package/dist/content.d.ts
CHANGED
package/dist/content.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { n as createPageSchema, r as createTolerantPageSchema } from "./page-
|
|
1
|
+
import { n as createPageSchema, r as createTolerantPageSchema } from "./page-wlcQJAA-.js";
|
|
2
2
|
import { n as createMigrator } from "./migrate-b408EaLp.js";
|
|
3
|
-
import { t as CONTENT_COLLECTIONS_MARKER } from "./reload-
|
|
3
|
+
import { t as CONTENT_COLLECTIONS_MARKER } from "./reload-BIIa7pej.js";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { pathToFileURL } from "node:url";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as Theme, $t as SCHEMA_VERSION_KEY, A as ContentModel, At as wireKinds, B as Footer, Bt as motionOption, C as jsonLdSchema, Ct as SectionConfig, D as siteJsonLdIds, Dt as WireRect, E as parseJsonLdInput, Et as WireKind, F as defaultTheme, Ft as EnumOption, G as Site, Gt as FieldChoices, H as FooterConfig, Ht as toneOption, I as defineTheme, It as NumberOption, J as SiteConsent, Jt as ShowWhen, K as SiteAnalytics, Kt as FieldIcons, L as BRAND_LOGO_HEIGHT, Lt as Option, M as ThemeConfig, Mt as OptionalContent, N as ThemeDefinition, Nt as BooleanOption, O as upsertJsonLd, Ot as Wireframe, P as ThemeFont, Pt as CountRule, Q as SiteWith, Qt as DocumentKind, R as DEFAULT_MAX_FOOTER_COLUMNS, Rt as StringOption, S as isPlaceholderSiteUrl, St as withEmphasis, T as mergeJsonLd, Tt as defineSection, U as Header, Ut as tones, V as FooterColumn, Vt as themeModes, W as HeaderConfig, Wt as variantOption, X as SiteOf, Xt as ContentMigrator, Y as SiteDefinition, Yt as ContentMigration, Z as SiteSeo, Zt as ContentVersioning, _ as SiteJsonLdIds, _t as richTextSchema, a as createPageSchema, at as themeColorsSchema, b as generateSiteJsonLd, bt as toneSchema, c as withoutOrphanSections, ct as Image, d as SectionOf, dt as RichText, en as createMigrator, et as brandLogoSchema, f as anchorSchema, ft as Text, g as JsonLdResult, gt as linkSchema, h as JsonLdBlock, ht as imageSchema, i as Seo, it as siteSeoSchema, j as SectionRegistry, jt as wireframeIssues, k as API_PREFIX, kt as defineWireframe, l as BaseSection, lt as Link, m as sectionIdSchema, mt as htmlIdSchema, nt as siteAnalyticsSchema, o as isSystemPage, ot as themeSchema, p as createSectionSchema, pt as Tone, q as SiteConfig, qt as ShowCondition, r as SYSTEM_PAGES, rt as siteConsentSchema, s as seoSchema, st as ButtonStyle, t as Page, tt as defineSite, u as PropsOf, ut as MAX_NAV_DEPTH, v as SiteJsonLdSource, vt as textMarkSchema, w as jsonLdWarnings, wt as SectionDefinition, x as hasJsonLdId, xt as trackingIdSchema, y as formatJsonLd, yt as textSchema, z as DEFAULT_MAX_HEADER_ACTIONS, zt as buttonStyles } from "./page-CwbIDegI.js";
|
|
2
2
|
import { _ as renderMarkedHtml, a as WeightMark, f as markClass, g as reconcileMarks, i as TextRun, l as fontMarks, m as marksFromEmphasis, o as applyTextMark, r as TextMark, t as FontMark, v as splitMarkedText, y as weightMarks } from "./marks-BzLa48Y9.js";
|
|
3
|
-
import "./options-
|
|
3
|
+
import "./options-WI_ztZTj.js";
|
|
4
4
|
import { a as TURNSTILE_FIELD, i as HONEYPOT_FIELD, n as FormResult, r as FormSubmission, t as FormFieldErrors } from "./form-contract-BURSJP3Y.js";
|
|
5
5
|
//#region src/errors.d.ts
|
|
6
6
|
/** One schema problem, addressed by a dot path such as `sections.0.props.heading`. */
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { c as ContentReadError, i as enumFields, l as ContentValidationError, n as defineThemePreview, o as schemaProps, s as ContentError, u as formatContentIssues } from "./preview-
|
|
2
|
-
import { n as defineTheme, t as defaultTheme } from "./theme-
|
|
3
|
-
import { A as
|
|
1
|
+
import { c as ContentReadError, i as enumFields, l as ContentValidationError, n as defineThemePreview, o as schemaProps, s as ContentError, u as formatContentIssues } from "./preview-ImEm3T8k.js";
|
|
2
|
+
import { n as defineTheme, t as defaultTheme } from "./theme-BvqJ8UnS.js";
|
|
3
|
+
import { A as textMarkSchema, B as isImagePosition, C as upsertJsonLd, D as imageSchema, E as htmlIdSchema, F as DEFAULT_IMAGE_FIT, G as toneOption, H as buttonStyles, I as DEFAULT_IMAGE_POSITION, K as tones, L as IMAGE_FITS, M as toneSchema, N as trackingIdSchema, O as linkSchema, P as withEmphasis, R as IMAGE_POSITIONS, S as siteJsonLdIds, T as addMarkIssues, U as motionOption, W as themeModes, _ as isPlaceholderSiteUrl, b as mergeJsonLd, c as withoutOrphanSections, f as sectionIdSchema, g as hasJsonLdId, h as generateSiteJsonLd, i as isSystemPage, j as textSchema, k as richTextSchema, l as anchorSchema, m as formatJsonLd, n as createPageSchema, o as seoSchema, p as walkLinkIds, q as variantOption, t as SYSTEM_PAGES, u as createSectionSchema, v as jsonLdSchema, w as MAX_NAV_DEPTH, x as parseJsonLdInput, y as jsonLdWarnings, z as isImageFit } from "./page-wlcQJAA-.js";
|
|
4
4
|
import { d as reconcileMarks, f as renderMarkedHtml, i as fontMarks, l as marksFromEmphasis, m as weightMarks, p as splitMarkedText, s as markClass, t as applyTextMark } from "./marks-DPBilumg.js";
|
|
5
5
|
import { n as createMigrator, r as API_PREFIX, t as SCHEMA_VERSION_KEY } from "./migrate-b408EaLp.js";
|
|
6
6
|
import { n as TURNSTILE_FIELD, t as HONEYPOT_FIELD } from "./form-contract-CIDTNab-.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as ContentModel, N as ThemeDefinition, Xt as ContentMigrator, Y as SiteDefinition, j as SectionRegistry, n as PageRules } from "./page-CwbIDegI.js";
|
|
2
2
|
//#region src/images.d.ts
|
|
3
3
|
type ImageKind = 'png' | 'jpeg' | 'webp' | 'gif' | 'avif';
|
|
4
4
|
interface SavedImage {
|
|
@@ -102,6 +102,25 @@ interface FileStoreOptions {
|
|
|
102
102
|
/** The content store for a local project: content as JSON files, uploads in a folder. */
|
|
103
103
|
declare function createFileStore({ root, contentDir, uploadsDir, videosDir }: FileStoreOptions): ContentStore;
|
|
104
104
|
//#endregion
|
|
105
|
+
//#region src/upload-rules.d.ts
|
|
106
|
+
/** Re-encode uploads in the browser before they are sent. */
|
|
107
|
+
interface ImageConvertOptions {
|
|
108
|
+
to: 'webp';
|
|
109
|
+
/** Wider images are scaled down to this width, never up. Default: no width cap. */
|
|
110
|
+
maxWidth?: number;
|
|
111
|
+
/** WebP quality, 0.1 to 1. Default 0.82. */
|
|
112
|
+
quality?: number;
|
|
113
|
+
}
|
|
114
|
+
/** What the browser needs to know before it sends a file. */
|
|
115
|
+
interface UploadRules {
|
|
116
|
+
maxBytes: number;
|
|
117
|
+
convert: {
|
|
118
|
+
to: 'webp';
|
|
119
|
+
maxWidth: number | null;
|
|
120
|
+
quality: number;
|
|
121
|
+
} | null;
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
105
124
|
//#region src/options.d.ts
|
|
106
125
|
interface BearminionOptions extends ContentModel {
|
|
107
126
|
/** Directory that contains `site.json` and `pages/`. Default `content`. */
|
|
@@ -112,6 +131,24 @@ interface BearminionOptions extends ContentModel {
|
|
|
112
131
|
videosDir?: string;
|
|
113
132
|
/** Largest video the editor accepts, in bytes. Default 50 MB. */
|
|
114
133
|
maxVideoBytes?: number;
|
|
134
|
+
/**
|
|
135
|
+
* Largest image the editor accepts, in bytes. Default 5 MB. The editor checks it in the browser before it uploads,
|
|
136
|
+
* and the server checks it again.
|
|
137
|
+
*/
|
|
138
|
+
maxImageBytes?: number;
|
|
139
|
+
/**
|
|
140
|
+
* Re-encode images in the browser before they are uploaded, so phone photos stay out of the repository:
|
|
141
|
+
* `{ to: 'webp', maxWidth: 2400, quality: 0.82 }`. Animated GIFs are never converted, and an image that would come
|
|
142
|
+
* out larger is kept as it is. Default: off, images are uploaded as they are.
|
|
143
|
+
*/
|
|
144
|
+
imageConvert?: false | ImageConvertOptions;
|
|
145
|
+
/**
|
|
146
|
+
* Which page operations the editor allows: `{ rename: false, delete: false }` for a site whose addresses must not
|
|
147
|
+
* change (they carry search ranking or are the target of redirects). Both default to true. A locked operation is
|
|
148
|
+
* refused by the API as well as hidden in the editor. `rename: false` also blocks making another page the home page,
|
|
149
|
+
* because that moves the old home page to a new address.
|
|
150
|
+
*/
|
|
151
|
+
pages?: Partial<PageRules>;
|
|
115
152
|
/**
|
|
116
153
|
* Vite module id loaded by the dev server to render a draft page.
|
|
117
154
|
* Default `/src/lib/render-preview.ts`. Preview never writes to disk.
|
|
@@ -151,6 +188,10 @@ interface EditorContext {
|
|
|
151
188
|
uploadsDir: string;
|
|
152
189
|
videosDir: string;
|
|
153
190
|
maxVideoBytes: number;
|
|
191
|
+
maxImageBytes: number;
|
|
192
|
+
pageRules: PageRules;
|
|
193
|
+
/** `imageConvert`, validated and with its defaults filled in. `null` when conversion is off. */
|
|
194
|
+
imageConvert: UploadRules['convert'];
|
|
154
195
|
sections: SectionRegistry;
|
|
155
196
|
site: SiteDefinition;
|
|
156
197
|
theme: ThemeDefinition;
|
|
@@ -1374,6 +1374,15 @@ declare const seoSchema: z.ZodObject<{
|
|
|
1374
1374
|
* and refuses to create, delete, rename or promote them to the home page.
|
|
1375
1375
|
*/
|
|
1376
1376
|
declare const SYSTEM_PAGES: readonly ["404"];
|
|
1377
|
+
/**
|
|
1378
|
+
* Which page operations the editor allows. Both default to true. A locked operation is refused by the API, whoever
|
|
1379
|
+
* asks (the editor, a script, an assistant), and its controls are hidden in the editor.
|
|
1380
|
+
*/
|
|
1381
|
+
interface PageRules {
|
|
1382
|
+
/** Change a page's slug, including making another page the home page (that moves two pages to new addresses). */
|
|
1383
|
+
rename: boolean;
|
|
1384
|
+
delete: boolean;
|
|
1385
|
+
}
|
|
1377
1386
|
declare function isSystemPage(slug: string): boolean;
|
|
1378
1387
|
/** Validates a page document: its own fields, and every section against the registry. Cached per registry. */
|
|
1379
1388
|
declare function createPageSchema<TRegistry extends SectionRegistry>(registry: TRegistry): z.ZodType<Page<SectionOf<TRegistry>>>;
|
|
@@ -1393,4 +1402,4 @@ declare function withoutOrphanSections<TPage extends {
|
|
|
1393
1402
|
sections: readonly unknown[];
|
|
1394
1403
|
}>(page: TPage, registry: SectionRegistry): TPage;
|
|
1395
1404
|
//#endregion
|
|
1396
|
-
export {
|
|
1405
|
+
export { Theme as $, SCHEMA_VERSION_KEY as $t, ContentModel as A, wireKinds as At, Footer as B, motionOption as Bt, jsonLdSchema as C, SectionConfig as Ct, siteJsonLdIds as D, WireRect as Dt, parseJsonLdInput as E, WireKind as Et, defaultTheme as F, EnumOption as Ft, Site as G, FieldChoices as Gt, FooterConfig as H, toneOption as Ht, defineTheme as I, NumberOption as It, SiteConsent as J, ShowWhen as Jt, SiteAnalytics as K, FieldIcons as Kt, BRAND_LOGO_HEIGHT as L, Option as Lt, ThemeConfig as M, OptionalContent as Mt, ThemeDefinition as N, BooleanOption as Nt, upsertJsonLd as O, Wireframe as Ot, ThemeFont as P, CountRule as Pt, SiteWith as Q, DocumentKind as Qt, DEFAULT_MAX_FOOTER_COLUMNS as R, StringOption as Rt, isPlaceholderSiteUrl as S, withEmphasis as St, mergeJsonLd as T, defineSection as Tt, Header as U, tones as Ut, FooterColumn as V, themeModes as Vt, HeaderConfig as W, variantOption as Wt, SiteOf as X, ContentMigrator as Xt, SiteDefinition as Y, ContentMigration as Yt, SiteSeo as Z, ContentVersioning as Zt, SiteJsonLdIds as _, richTextSchema as _t, createPageSchema as a, themeColorsSchema as at, generateSiteJsonLd as b, toneSchema as bt, withoutOrphanSections as c, Image as ct, SectionOf as d, RichText as dt, createMigrator as en, brandLogoSchema as et, anchorSchema as f, Text as ft, JsonLdResult as g, linkSchema as gt, JsonLdBlock as h, imageSchema as ht, Seo as i, siteSeoSchema as it, SectionRegistry as j, wireframeIssues as jt, API_PREFIX as k, defineWireframe as kt, BaseSection as l, Link as lt, sectionIdSchema as m, htmlIdSchema as mt, PageRules as n, siteAnalyticsSchema as nt, isSystemPage as o, themeSchema as ot, createSectionSchema as p, Tone as pt, SiteConfig as q, ShowCondition as qt, SYSTEM_PAGES as r, siteConsentSchema as rt, seoSchema as s, ButtonStyle as st, Page as t, defineSite as tt, PropsOf as u, MAX_NAV_DEPTH as ut, SiteJsonLdSource as v, textMarkSchema as vt, jsonLdWarnings as w, SectionDefinition as wt, hasJsonLdId as x, trackingIdSchema as xt, formatJsonLd as y, textSchema as yt, DEFAULT_MAX_HEADER_ACTIONS as z, buttonStyles as zt };
|
|
@@ -503,6 +503,22 @@ const seoSchema = z.object({
|
|
|
503
503
|
* and refuses to create, delete, rename or promote them to the home page.
|
|
504
504
|
*/
|
|
505
505
|
const SYSTEM_PAGES = ["404"];
|
|
506
|
+
const DEFAULT_PAGE_RULES = {
|
|
507
|
+
rename: true,
|
|
508
|
+
delete: true
|
|
509
|
+
};
|
|
510
|
+
/** Check the `pages` option and fill in its defaults. */
|
|
511
|
+
function resolvePageRules(input) {
|
|
512
|
+
if (input === void 0) return DEFAULT_PAGE_RULES;
|
|
513
|
+
for (const [key, value] of Object.entries(input)) {
|
|
514
|
+
if (key !== "rename" && key !== "delete") throw new Error(`bearminion(): unknown option pages.${key}. Use pages.rename or pages.delete.`);
|
|
515
|
+
if (typeof value !== "boolean") throw new Error(`bearminion(): pages.${key} must be true or false.`);
|
|
516
|
+
}
|
|
517
|
+
return {
|
|
518
|
+
rename: input.rename ?? true,
|
|
519
|
+
delete: input.delete ?? true
|
|
520
|
+
};
|
|
521
|
+
}
|
|
506
522
|
function isSystemPage(slug) {
|
|
507
523
|
return SYSTEM_PAGES.includes(slug);
|
|
508
524
|
}
|
|
@@ -547,4 +563,4 @@ function withoutOrphanSections(page, registry) {
|
|
|
547
563
|
};
|
|
548
564
|
}
|
|
549
565
|
//#endregion
|
|
550
|
-
export {
|
|
566
|
+
export { textMarkSchema as A, isImagePosition as B, upsertJsonLd as C, imageSchema as D, htmlIdSchema as E, DEFAULT_IMAGE_FIT as F, toneOption as G, buttonStyles as H, DEFAULT_IMAGE_POSITION as I, tones as K, IMAGE_FITS as L, toneSchema as M, trackingIdSchema as N, linkSchema as O, withEmphasis as P, IMAGE_POSITIONS as R, siteJsonLdIds as S, addMarkIssues as T, motionOption as U, withImageLayout as V, themeModes as W, isPlaceholderSiteUrl as _, resolvePageRules as a, mergeJsonLd as b, withoutOrphanSections as c, isOrphanSection as d, sectionIdSchema as f, hasJsonLdId as g, generateSiteJsonLd as h, isSystemPage as i, textSchema as j, richTextSchema as k, anchorSchema as l, formatJsonLd as m, createPageSchema as n, seoSchema as o, walkLinkIds as p, variantOption as q, createTolerantPageSchema as r, slugSchema as s, SYSTEM_PAGES as t, createSectionSchema as u, jsonLdSchema as v, MAX_NAV_DEPTH as w, parseJsonLdInput as x, jsonLdWarnings as y, isImageFit as z };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { s as slugSchema } from "./page-wlcQJAA-.js";
|
|
2
|
+
import { t as DEFAULT_IMAGE_BYTE_LIMIT } from "./upload-rules-Cao9uY5K.js";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { fileURLToPath } from "node:url";
|
|
4
5
|
//#region src/security.ts
|
|
5
6
|
const JSON_BODY_LIMIT = 1048576;
|
|
6
|
-
const IMAGE_BYTE_LIMIT =
|
|
7
|
-
|
|
8
|
-
const MULTIPART_BODY_LIMIT = 5505024;
|
|
7
|
+
const IMAGE_BYTE_LIMIT = DEFAULT_IMAGE_BYTE_LIMIT;
|
|
8
|
+
IMAGE_BYTE_LIMIT + 262144;
|
|
9
9
|
const LOCAL_HOSTS = /* @__PURE__ */ new Set([
|
|
10
10
|
"localhost",
|
|
11
11
|
"127.0.0.1",
|
|
@@ -90,4 +90,4 @@ function readSlug(segment) {
|
|
|
90
90
|
return parsed.success ? parsed.data : null;
|
|
91
91
|
}
|
|
92
92
|
//#endregion
|
|
93
|
-
export {
|
|
93
|
+
export { isLocalRequest as a, resolveInside as c, isInside as i, JSON_BODY_LIMIT as n, readSlug as o, asDirectory as r, resolveDir as s, IMAGE_BYTE_LIMIT as t };
|
package/dist/ui/mount.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { a as sectionFieldKey, i as isPropShown, t as defaultTheme } from "../theme-
|
|
2
|
-
import { B as
|
|
1
|
+
import { a as sectionFieldKey, i as isPropShown, t as defaultTheme } from "../theme-BvqJ8UnS.js";
|
|
2
|
+
import { B as isImagePosition, C as upsertJsonLd, F as DEFAULT_IMAGE_FIT, I as DEFAULT_IMAGE_POSITION, L as IMAGE_FITS, R as IMAGE_POSITIONS, V as withImageLayout, _ as isPlaceholderSiteUrl, h as generateSiteJsonLd, i as isSystemPage, m as formatJsonLd, x as parseJsonLdInput, y as jsonLdWarnings, z as isImageFit } from "../page-wlcQJAA-.js";
|
|
3
3
|
import { d as reconcileMarks, f as renderMarkedHtml, i as fontMarks, l as marksFromEmphasis, t as applyTextMark } from "../marks-DPBilumg.js";
|
|
4
4
|
import { _ as consentCopy, b as parseMediaSource, c as hasThemeColors, d as tokenToHex, f as CONSENT_COPY, h as CONSENT_LIMITS, i as contrastChecks, n as HEX_COLOR, o as derivePalette, r as OVERRIDE_TOKENS, s as hasOverrides, t as DEFAULT_BRAND, u as themeCss, v as consentTextIssues } from "../theme-colors-CHROGZkI.js";
|
|
5
|
+
import { n as formatBytes, t as DEFAULT_IMAGE_BYTE_LIMIT } from "../upload-rules-Cao9uY5K.js";
|
|
5
6
|
import { _ as writeSaveNotice, a as localDraftStorage, d as removeDraft, f as savedNoticeFor, g as writeDraftRecord, h as sweepExpiredDrafts, i as isForeignSave, l as readDraftRecord, m as siteSavedKey, n as draftBannerText, o as pageDraftKey, p as siteDraftKey, r as hashText, s as pageSavedKey, t as assessStoredDraft, u as reloadDecision, x as draftImageUsages } from "../draft-store-1Y4-sn45.js";
|
|
6
7
|
import { a as richLinkAt, c as updateRichLink, i as renderRichText, n as isSafeHref, o as sanitizeRichHtml, r as markdownFromHtml, s as stripPlainRich } from "../rich-text-70hddxMC.js";
|
|
7
8
|
import { Component, Fragment, createContext, isValidElement, options, render } from "preact";
|
|
@@ -947,8 +948,32 @@ function navHeight(link) {
|
|
|
947
948
|
for (const child of children) max = Math.max(max, 1 + navHeight(child));
|
|
948
949
|
return max;
|
|
949
950
|
}
|
|
951
|
+
/** Letters that do not decompose into a base letter and an accent, with the plain letters they are written as. */
|
|
952
|
+
const PLAIN_LETTERS = {
|
|
953
|
+
ł: "l",
|
|
954
|
+
đ: "d",
|
|
955
|
+
ø: "o",
|
|
956
|
+
ð: "d",
|
|
957
|
+
þ: "th",
|
|
958
|
+
ß: "ss",
|
|
959
|
+
æ: "ae",
|
|
960
|
+
œ: "oe",
|
|
961
|
+
ı: "i"
|
|
962
|
+
};
|
|
963
|
+
/**
|
|
964
|
+
* A lowercase ASCII slug: accents are dropped (`ą` is `a`, `é` is `e`), letters with no accent form are written plainly
|
|
965
|
+
* (`ł` is `l`, `ß` is `ss`), and every other run of characters becomes one hyphen.
|
|
966
|
+
*/
|
|
950
967
|
function slugifyAnchor(value) {
|
|
951
|
-
return value.toLowerCase().normalize("NFKD").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
968
|
+
return value.toLowerCase().normalize("NFKD").replace(/\p{M}+/gu, "").replace(/[łđøðþßæœı]/g, (letter) => PLAIN_LETTERS[letter] ?? letter).replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* The slug to offer for a new page titled `title`: the title as a slug, made unique among `taken`. Empty when the
|
|
972
|
+
* title has no letters or digits, so the editor does not offer a slug that says nothing.
|
|
973
|
+
*/
|
|
974
|
+
function suggestPageSlug(title, taken) {
|
|
975
|
+
const stem = slugifyAnchor(title);
|
|
976
|
+
return stem === "" ? "" : uniqueAnchor(stem, taken);
|
|
952
977
|
}
|
|
953
978
|
function uniqueAnchor(base, taken) {
|
|
954
979
|
const stem = slugifyAnchor(base) || "section";
|
|
@@ -15435,6 +15460,110 @@ function createSectionActions(doc, ui, edits) {
|
|
|
15435
15460
|
};
|
|
15436
15461
|
}
|
|
15437
15462
|
//#endregion
|
|
15463
|
+
//#region src/ui/prepare-image.ts
|
|
15464
|
+
/** Still images the browser can decode and re-encode. GIFs may be animated, so they are never converted. */
|
|
15465
|
+
const CONVERTIBLE = /* @__PURE__ */ new Set([
|
|
15466
|
+
"image/png",
|
|
15467
|
+
"image/jpeg",
|
|
15468
|
+
"image/webp",
|
|
15469
|
+
"image/avif"
|
|
15470
|
+
]);
|
|
15471
|
+
let current = {
|
|
15472
|
+
maxBytes: DEFAULT_IMAGE_BYTE_LIMIT,
|
|
15473
|
+
convert: null
|
|
15474
|
+
};
|
|
15475
|
+
/** The rules the dev server reported. Until they arrive the defaults apply, and the server checks again anyway. */
|
|
15476
|
+
function setUploadRules(rules) {
|
|
15477
|
+
current = rules;
|
|
15478
|
+
}
|
|
15479
|
+
function getUploadRules() {
|
|
15480
|
+
return current;
|
|
15481
|
+
}
|
|
15482
|
+
function tooLarge(file, rules, converted) {
|
|
15483
|
+
const hint = converted ? "" : " Use a smaller image.";
|
|
15484
|
+
return {
|
|
15485
|
+
ok: false,
|
|
15486
|
+
error: `${file.name} is ${formatBytes(file.size)}. Images must be ${formatBytes(rules.maxBytes)} or smaller.${hint}`
|
|
15487
|
+
};
|
|
15488
|
+
}
|
|
15489
|
+
function webpName(original) {
|
|
15490
|
+
return `${original.replace(/\.[^.]+$/, "") || "image"}.webp`;
|
|
15491
|
+
}
|
|
15492
|
+
/**
|
|
15493
|
+
* Apply the site's upload rules to a file before it is sent: scale and re-encode it when conversion is on, keep the
|
|
15494
|
+
* original when conversion would not help, and refuse a file that is still over the size limit. The server enforces
|
|
15495
|
+
* the limit again; this check only saves the round trip and gives a clear message.
|
|
15496
|
+
*/
|
|
15497
|
+
async function prepareImage(file, rules, codec = browserCodec) {
|
|
15498
|
+
const keep = () => file.size > rules.maxBytes ? tooLarge(file, rules, false) : {
|
|
15499
|
+
ok: true,
|
|
15500
|
+
file
|
|
15501
|
+
};
|
|
15502
|
+
if (rules.convert === null || !CONVERTIBLE.has(file.type)) return keep();
|
|
15503
|
+
let converted;
|
|
15504
|
+
try {
|
|
15505
|
+
converted = await codec.toWebp(file, {
|
|
15506
|
+
maxWidth: rules.convert.maxWidth,
|
|
15507
|
+
quality: rules.convert.quality
|
|
15508
|
+
});
|
|
15509
|
+
} catch {
|
|
15510
|
+
converted = null;
|
|
15511
|
+
}
|
|
15512
|
+
if (converted === null || converted.blob.type !== "image/webp") return keep();
|
|
15513
|
+
if (!converted.resized && converted.blob.size >= file.size) return keep();
|
|
15514
|
+
const result = new File([converted.blob], webpName(file.name), {
|
|
15515
|
+
type: "image/webp",
|
|
15516
|
+
lastModified: file.lastModified
|
|
15517
|
+
});
|
|
15518
|
+
return result.size > rules.maxBytes ? tooLarge(result, rules, true) : {
|
|
15519
|
+
ok: true,
|
|
15520
|
+
file: result
|
|
15521
|
+
};
|
|
15522
|
+
}
|
|
15523
|
+
async function encodeWebp(bitmap, width, height, quality) {
|
|
15524
|
+
if (typeof OffscreenCanvas === "function") {
|
|
15525
|
+
const canvas = new OffscreenCanvas(width, height);
|
|
15526
|
+
const context = canvas.getContext("2d");
|
|
15527
|
+
if (context === null) return null;
|
|
15528
|
+
context.imageSmoothingQuality = "high";
|
|
15529
|
+
context.drawImage(bitmap, 0, 0, width, height);
|
|
15530
|
+
return canvas.convertToBlob({
|
|
15531
|
+
type: "image/webp",
|
|
15532
|
+
quality
|
|
15533
|
+
});
|
|
15534
|
+
}
|
|
15535
|
+
const canvas = document.createElement("canvas");
|
|
15536
|
+
canvas.width = width;
|
|
15537
|
+
canvas.height = height;
|
|
15538
|
+
const context = canvas.getContext("2d");
|
|
15539
|
+
if (context === null) return null;
|
|
15540
|
+
context.imageSmoothingQuality = "high";
|
|
15541
|
+
context.drawImage(bitmap, 0, 0, width, height);
|
|
15542
|
+
return new Promise((resolve) => canvas.toBlob(resolve, "image/webp", quality));
|
|
15543
|
+
}
|
|
15544
|
+
/** The real codec. `from-image` applies the photo's EXIF rotation; re-encoding drops the metadata, GPS included. */
|
|
15545
|
+
const browserCodec = { async toWebp(file, { maxWidth, quality }) {
|
|
15546
|
+
if (typeof createImageBitmap !== "function") return null;
|
|
15547
|
+
let bitmap;
|
|
15548
|
+
try {
|
|
15549
|
+
bitmap = await createImageBitmap(file, { imageOrientation: "from-image" });
|
|
15550
|
+
} catch {
|
|
15551
|
+
return null;
|
|
15552
|
+
}
|
|
15553
|
+
try {
|
|
15554
|
+
const capped = maxWidth !== null && bitmap.width > maxWidth ? maxWidth : null;
|
|
15555
|
+
const width = capped ?? bitmap.width;
|
|
15556
|
+
const height = Math.max(1, Math.round(bitmap.height * (width / bitmap.width)));
|
|
15557
|
+
const blob = await encodeWebp(bitmap, width, height, quality);
|
|
15558
|
+
return blob === null ? null : {
|
|
15559
|
+
blob,
|
|
15560
|
+
resized: capped !== null
|
|
15561
|
+
};
|
|
15562
|
+
} finally {
|
|
15563
|
+
bitmap.close();
|
|
15564
|
+
}
|
|
15565
|
+
} };
|
|
15566
|
+
//#endregion
|
|
15438
15567
|
//#region src/ui/state/session.ts
|
|
15439
15568
|
/** How long a save waits for the first load before giving up. */
|
|
15440
15569
|
const READY_TIMEOUT_MS = 8e3;
|
|
@@ -15485,7 +15614,10 @@ function createSession(doc, ui, edits, drafts) {
|
|
|
15485
15614
|
if (typeof projectId === "string" && projectId !== "") doc.projectId.value = projectId;
|
|
15486
15615
|
}
|
|
15487
15616
|
if (listRes.ok) doc.pages.value = listRes.value.pages;
|
|
15488
|
-
if (imageRes.ok)
|
|
15617
|
+
if (imageRes.ok) {
|
|
15618
|
+
doc.images.value = imageRes.value.images;
|
|
15619
|
+
if (imageRes.value.limits) setUploadRules(imageRes.value.limits);
|
|
15620
|
+
}
|
|
15489
15621
|
if (nextSite) {
|
|
15490
15622
|
doc.site.value = nextSite;
|
|
15491
15623
|
doc.savedSiteJson.value = savedSiteJson;
|
|
@@ -17054,7 +17186,9 @@ function ImageField({ label, path, value, images, withAlt = true, layout = true,
|
|
|
17054
17186
|
});
|
|
17055
17187
|
}
|
|
17056
17188
|
async function uploadFile(file) {
|
|
17057
|
-
const
|
|
17189
|
+
const prepared = await prepareImage(file, getUploadRules());
|
|
17190
|
+
if (!prepared.ok) return { error: prepared.error };
|
|
17191
|
+
const result = await uploadImage(prepared.file);
|
|
17058
17192
|
if (!result.ok) return { error: result.status === 0 ? "Upload failed." : result.message };
|
|
17059
17193
|
return { image: result.value };
|
|
17060
17194
|
}
|
|
@@ -17237,9 +17371,9 @@ function ImagePickerModal({ src, images, onPick, onUploaded, onDeleted, onClose
|
|
|
17237
17371
|
class: "bm-slot-title",
|
|
17238
17372
|
children: busy ? "Uploading…" : "Drag an image here"
|
|
17239
17373
|
}),
|
|
17240
|
-
/* @__PURE__ */
|
|
17374
|
+
/* @__PURE__ */ jsxs("span", {
|
|
17241
17375
|
class: "bm-slot-hint",
|
|
17242
|
-
children: "or click to browse · png, jpeg, webp, gif, avif · up to
|
|
17376
|
+
children: ["or click to browse · png, jpeg, webp, gif, avif · up to ", formatBytes(getUploadRules().maxBytes)]
|
|
17243
17377
|
}),
|
|
17244
17378
|
/* @__PURE__ */ jsx("input", {
|
|
17245
17379
|
class: "bm-visually-hidden",
|
|
@@ -22303,7 +22437,7 @@ function SeoCard({ page, siteName, siteUrl, siteOgImage, system, onEdit }) {
|
|
|
22303
22437
|
}
|
|
22304
22438
|
//#endregion
|
|
22305
22439
|
//#region src/ui/forms/page-form.tsx
|
|
22306
|
-
function PageForm({ page, labels, siteName, siteUrl, siteOgImage, selectedId, onChange, savedSlug, onHomeChange, onEditSeo, onSelectSection, onMoveSection, onReorderSections, onDuplicateSection, onRemoveSection, onAddSection }) {
|
|
22440
|
+
function PageForm({ page, labels, siteName, siteUrl, siteOgImage, selectedId, onChange, savedSlug, canRename, onHomeChange, onEditSeo, onSelectSection, onMoveSection, onReorderSections, onDuplicateSection, onRemoveSection, onAddSection }) {
|
|
22307
22441
|
const [sectionDrag, setSectionDrag] = useState(null);
|
|
22308
22442
|
const isHome = page.slug === "index";
|
|
22309
22443
|
const isSystem = isSystemPage(page.slug);
|
|
@@ -22333,9 +22467,9 @@ function PageForm({ page, labels, siteName, siteUrl, siteOgImage, selectedId, on
|
|
|
22333
22467
|
...page,
|
|
22334
22468
|
slug: value
|
|
22335
22469
|
}),
|
|
22336
|
-
disabled: isHome || isSystem,
|
|
22337
|
-
mono: isHome || isSystem,
|
|
22338
|
-
hint: isHome ? "The home page is served at / and keeps the slug index." : isSystem ? "A system page: the site serves it for unknown addresses, so its slug is fixed and it stays out of search results." : void 0
|
|
22470
|
+
disabled: isHome || isSystem || !canRename,
|
|
22471
|
+
mono: isHome || isSystem || !canRename,
|
|
22472
|
+
hint: isHome ? "The home page is served at / and keeps the slug index." : isSystem ? "A system page: the site serves it for unknown addresses, so its slug is fixed and it stays out of search results." : canRename ? void 0 : "Renaming pages is turned off for this site, so this address stays as it is."
|
|
22339
22473
|
}),
|
|
22340
22474
|
!isSystem && /* @__PURE__ */ jsxs("label", {
|
|
22341
22475
|
class: "bm-switch-row",
|
|
@@ -22345,14 +22479,14 @@ function PageForm({ page, labels, siteName, siteUrl, siteOgImage, selectedId, on
|
|
|
22345
22479
|
class: "bm-switch-title",
|
|
22346
22480
|
children: ["Home page", /* @__PURE__ */ jsx(Info, {
|
|
22347
22481
|
label: "About Home page",
|
|
22348
|
-
text: savedHome ? "Set another page as home to move this one." : isHome ? "Becomes the home page when you save." : "Serve this page at / instead of its own URL."
|
|
22482
|
+
text: !canRename ? "Renaming pages is turned off for this site, and making a page home moves the old home page to a new address." : savedHome ? "Set another page as home to move this one." : isHome ? "Becomes the home page when you save." : "Serve this page at / instead of its own URL."
|
|
22349
22483
|
})]
|
|
22350
22484
|
})
|
|
22351
22485
|
}), /* @__PURE__ */ jsx("input", {
|
|
22352
22486
|
type: "checkbox",
|
|
22353
22487
|
role: "switch",
|
|
22354
22488
|
checked: isHome,
|
|
22355
|
-
disabled: savedHome,
|
|
22489
|
+
disabled: savedHome || !canRename,
|
|
22356
22490
|
onChange: (event) => onHomeChange(event.currentTarget.checked)
|
|
22357
22491
|
})]
|
|
22358
22492
|
})
|
|
@@ -22541,9 +22675,13 @@ function PageForm({ page, labels, siteName, siteUrl, siteOgImage, selectedId, on
|
|
|
22541
22675
|
}
|
|
22542
22676
|
//#endregion
|
|
22543
22677
|
//#region src/ui/forms/pages-form.tsx
|
|
22544
|
-
function PagesForm({ pages, labels, current, homeSlug, onCreated, onNavigate }) {
|
|
22545
|
-
const
|
|
22678
|
+
function PagesForm({ pages, labels, current, homeSlug, canDelete, onCreated, onNavigate }) {
|
|
22679
|
+
const taken = new Set(pages.map((item) => item.slug));
|
|
22546
22680
|
const [title, setTitle] = useState("Notes");
|
|
22681
|
+
const [slug, setSlug] = useState(() => suggestPageSlug("Notes", taken));
|
|
22682
|
+
/** True once the slug was typed by hand: from then on the title no longer changes it. */
|
|
22683
|
+
const [slugTyped, setSlugTyped] = useState(false);
|
|
22684
|
+
const [error, setError] = useState("");
|
|
22547
22685
|
const [template, setTemplate] = useState("hero");
|
|
22548
22686
|
const [creating, setCreating] = useState(false);
|
|
22549
22687
|
return /* @__PURE__ */ jsxs("div", {
|
|
@@ -22601,7 +22739,7 @@ function PagesForm({ pages, labels, current, homeSlug, onCreated, onNavigate })
|
|
|
22601
22739
|
class: "bm-badge bm-badge-on",
|
|
22602
22740
|
children: "editing"
|
|
22603
22741
|
}),
|
|
22604
|
-
item.slug !== "index" && item.slug !== current && !item.system && /* @__PURE__ */ jsx("button", {
|
|
22742
|
+
canDelete && item.slug !== "index" && item.slug !== current && !item.system && /* @__PURE__ */ jsx("button", {
|
|
22605
22743
|
type: "button",
|
|
22606
22744
|
class: "bm-icon-btn bm-danger",
|
|
22607
22745
|
"aria-label": `Delete ${item.title}`,
|
|
@@ -22620,15 +22758,23 @@ function PagesForm({ pages, labels, current, homeSlug, onCreated, onNavigate })
|
|
|
22620
22758
|
creating && /* @__PURE__ */ jsxs("div", {
|
|
22621
22759
|
class: "bm-card",
|
|
22622
22760
|
children: [
|
|
22623
|
-
/* @__PURE__ */ jsx(Field, {
|
|
22624
|
-
label: "New slug",
|
|
22625
|
-
value: slug,
|
|
22626
|
-
onChange: setSlug
|
|
22627
|
-
}),
|
|
22628
22761
|
/* @__PURE__ */ jsx(Field, {
|
|
22629
22762
|
label: "New title",
|
|
22630
22763
|
value: title,
|
|
22631
|
-
onChange:
|
|
22764
|
+
onChange: (value) => {
|
|
22765
|
+
setTitle(value);
|
|
22766
|
+
if (!slugTyped) setSlug(suggestPageSlug(value, taken));
|
|
22767
|
+
}
|
|
22768
|
+
}),
|
|
22769
|
+
/* @__PURE__ */ jsx(Field, {
|
|
22770
|
+
label: "New slug",
|
|
22771
|
+
value: slug,
|
|
22772
|
+
mono: true,
|
|
22773
|
+
hint: "The page address. Made from the title until you change it, and the title never changes it afterwards.",
|
|
22774
|
+
onChange: (value) => {
|
|
22775
|
+
setSlug(value);
|
|
22776
|
+
setSlugTyped(true);
|
|
22777
|
+
}
|
|
22632
22778
|
}),
|
|
22633
22779
|
/* @__PURE__ */ jsxs("label", {
|
|
22634
22780
|
class: "bm-label",
|
|
@@ -22644,16 +22790,23 @@ function PagesForm({ pages, labels, current, homeSlug, onCreated, onNavigate })
|
|
|
22644
22790
|
/* @__PURE__ */ jsx("button", {
|
|
22645
22791
|
type: "button",
|
|
22646
22792
|
class: "bm-primary",
|
|
22793
|
+
disabled: slug === "",
|
|
22647
22794
|
onClick: () => {
|
|
22795
|
+
setError("");
|
|
22648
22796
|
createPage({
|
|
22649
22797
|
slug,
|
|
22650
22798
|
title,
|
|
22651
22799
|
template
|
|
22652
22800
|
}).then((result) => {
|
|
22653
22801
|
if (result.ok) onNavigate(pageHref(slug));
|
|
22802
|
+
else setError(result.status === 0 ? "Could not create the page." : result.message);
|
|
22654
22803
|
});
|
|
22655
22804
|
},
|
|
22656
22805
|
children: "Create page"
|
|
22806
|
+
}),
|
|
22807
|
+
error && /* @__PURE__ */ jsx("p", {
|
|
22808
|
+
class: "bm-error",
|
|
22809
|
+
children: error
|
|
22657
22810
|
})
|
|
22658
22811
|
]
|
|
22659
22812
|
})
|
|
@@ -23068,6 +23221,7 @@ function PagesPanel({ catalog }) {
|
|
|
23068
23221
|
labels: catalog.sectionLabels,
|
|
23069
23222
|
current: savedSlug,
|
|
23070
23223
|
homeSlug: page && page.slug === "index" ? savedSlug : "index",
|
|
23224
|
+
canDelete: catalog.pageRules?.delete !== false,
|
|
23071
23225
|
onCreated: () => void session.load(doc.savedSlug.peek()),
|
|
23072
23226
|
onNavigate: session.requestLeave
|
|
23073
23227
|
}), page && /* @__PURE__ */ jsx(PageForm, {
|
|
@@ -23079,6 +23233,7 @@ function PagesPanel({ catalog }) {
|
|
|
23079
23233
|
selectedId: ui.selectedId.value,
|
|
23080
23234
|
onChange: (next) => edits.updatePage(next),
|
|
23081
23235
|
savedSlug,
|
|
23236
|
+
canRename: catalog.pageRules?.rename !== false,
|
|
23082
23237
|
onHomeChange: session.setHome,
|
|
23083
23238
|
onEditSeo: () => {
|
|
23084
23239
|
ui.dialog.value = { kind: "seo" };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/upload-rules.ts
|
|
2
|
+
/**
|
|
3
|
+
* Image upload rules shared by the dev server and the editor in the browser. No Node imports: the browser bundle
|
|
4
|
+
* uses it too.
|
|
5
|
+
*/
|
|
6
|
+
/** The default largest image the editor accepts: 5 MB. */
|
|
7
|
+
const DEFAULT_IMAGE_BYTE_LIMIT = 5242880;
|
|
8
|
+
const DEFAULT_CONVERT_QUALITY = .82;
|
|
9
|
+
const MAX_CONVERT_WIDTH = 16384;
|
|
10
|
+
/** Check `imageConvert` and fill in its defaults. `false` and `undefined` mean no conversion. */
|
|
11
|
+
function resolveConvert(input) {
|
|
12
|
+
if (input === void 0 || input === false) return null;
|
|
13
|
+
if (input.to !== "webp") throw new Error(`bearminion(): imageConvert.to must be "webp", got "${String(input.to)}".`);
|
|
14
|
+
const { maxWidth, quality = DEFAULT_CONVERT_QUALITY } = input;
|
|
15
|
+
if (maxWidth !== void 0 && (!Number.isInteger(maxWidth) || maxWidth < 16 || maxWidth > 16384)) throw new Error(`bearminion(): imageConvert.maxWidth must be a whole number from 16 to ${MAX_CONVERT_WIDTH}.`);
|
|
16
|
+
if (!Number.isFinite(quality) || quality < .1 || quality > 1) throw new Error("bearminion(): imageConvert.quality must be a number from 0.1 to 1.");
|
|
17
|
+
return {
|
|
18
|
+
to: "webp",
|
|
19
|
+
maxWidth: maxWidth ?? null,
|
|
20
|
+
quality
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** Check `maxImageBytes`. */
|
|
24
|
+
function resolveMaxImageBytes(input) {
|
|
25
|
+
if (input === void 0) return DEFAULT_IMAGE_BYTE_LIMIT;
|
|
26
|
+
if (!Number.isInteger(input) || input < 1024) throw new Error("bearminion(): maxImageBytes must be a whole number of bytes, at least 1024.");
|
|
27
|
+
return input;
|
|
28
|
+
}
|
|
29
|
+
/** "4.2 MB", "310 KB", "512 B". */
|
|
30
|
+
function formatBytes(bytes) {
|
|
31
|
+
if (bytes >= 1048576) return `${(bytes / 1048576).toFixed(1).replace(/\.0$/, "")} MB`;
|
|
32
|
+
if (bytes >= 1024) return `${Math.round(bytes / 1024)} KB`;
|
|
33
|
+
return `${bytes} B`;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { resolveMaxImageBytes as i, formatBytes as n, resolveConvert as r, DEFAULT_IMAGE_BYTE_LIMIT as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bearminion",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "A git-based CMS for Astro with no database and no server: JSON content in your repo, edited by clicking on the page during astro dev.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jakub Lange",
|