bearminion 1.18.0 → 1.20.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 CHANGED
@@ -1,5 +1,25 @@
1
1
  # bearminion
2
2
 
3
+ ## 1.20.0
4
+
5
+ ### Minor Changes
6
+
7
+ - c6dad44: The hosted editor has live preview, and its guide is a page of its own.
8
+
9
+ - **Live preview online.** A section just added, a layout switched and header or footer changes are now redrawn at once in the hosted editor, as in `astro dev`. Before, the preview endpoints answered 501 there and such changes showed only after Save and a reload. `bearminionHostedEditor` wires the theme's `src/lib/render-preview.ts` by itself (new option `previewModule`, a path or `false`); outside Astro, pass it as `editor.handle(request, { preview })`. Sites already on the hosted editor get it by updating `bearminion` and redeploying the editor project.
10
+ - **`signIn: 'optional'` no longer answers 500 to visitors.** The starter's `[...slug].astro` reads the build's content when a server build has no props. Existing sites: `npx bearminion@latest add hosted` updates the file.
11
+ - **Docs.** New page [Edit online](https://docs.bearminion.com/hosted-editor/): what the hosted editor is, who may edit (whoever may push to the repository), the setup in five steps, pull request mode, and its limits.
12
+ - **No longer experimental on Vercel.** The hosted editor and `githubStore` are tested end to end on real Vercel deployments with a real GitHub App. Cloudflare Workers has run only in the local Workers runtime and stays experimental.
13
+
14
+ ## 1.19.0
15
+
16
+ ### Minor Changes
17
+
18
+ - 3713ac3: The starter footer shows a "Powered by BearMinion" link to bearminion.com, and the Footer tab can switch it off.
19
+
20
+ - New `poweredBy` option in `defineSite({ footer })` (default false). When a theme enables it, the Footer tab gets a **Powered by BearMinion** switch and `site.json` accepts `footer.poweredBy`. The link is shown unless the value is `false`.
21
+ - The starter adds `atoms/PoweredBy.astro` and renders it in the bottom row of every footer variant. Existing sites are not changed: copy `Footer.astro` and `PoweredBy.astro` (`npx bearminion status` lists them as outdated) and add `poweredBy: true` to `site-definition.ts` to get it.
22
+
3
23
  ## 1.18.0
4
24
 
5
25
  ### Minor Changes
package/README.md CHANGED
@@ -39,7 +39,9 @@ It asks for the site's name and web address. Open the address `npm run dev` prin
39
39
  - **Images**: upload, choose how they fill their frame and which part stays in view
40
40
  - **Colors**: pick three, and the editor builds a full light and dark palette that stays readable
41
41
 
42
- Content is plain JSON in your project, validated on every save and kept in your git history. The editor only runs during `astro dev`; the published site is static HTML with nothing from the editor in it.
42
+ Content is plain JSON in your project, validated on every save and kept in your git history. The editor runs during `astro dev`; the published site is static HTML with nothing from the editor in it.
43
+
44
+ **Editing online is opt-in.** `npx bearminion add hosted` sets up a second deployment where people sign in with GitHub and edit in the browser. Whoever may push to the repository may edit, and every save is a commit under their name. See [Edit online](https://docs.bearminion.com/hosted-editor/).
43
45
 
44
46
  <p align="center">
45
47
  <img src="https://raw.githubusercontent.com/langehelp-software/bearminion/main/.github/assets/design.png" alt="The Design tab: color mode, brand, neutral and link colors, and a preview of every section tone in light and dark mode" width="100%" />
package/dist/astro.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { _ as CollectionOptions, b as StoreOperation, n as ImageConvertOptions, t as EditorContext, x as UploadStore, y as ContentStore } from "./editor-context-ESJwMFpS.js";
2
- import { i as StoreKeyError, n as githubStore, r as StoreError, t as GithubStoreOptions } from "./github-store-CDQNvoKQ.js";
3
- import { _ as SectionRegistry, d as SectionOf, g as ContentModel, gt as SiteOf, ht as SiteDefinition, n as PageRules, t as Page, w as ContentMigrator } from "./page-D1pdneYm.js";
1
+ import { _ as CollectionOptions, b as StoreOperation, n as ImageConvertOptions, t as EditorContext, x as UploadStore, y as ContentStore } from "./editor-context-DzRwKENi.js";
2
+ import { i as StoreKeyError, n as githubStore, r as StoreError, t as GithubStoreOptions } from "./github-store-DsLCe5MR.js";
3
+ import { _ as SectionRegistry, d as SectionOf, g as ContentModel, gt as SiteOf, ht as SiteDefinition, n as PageRules, t as Page, w as ContentMigrator } from "./page-BGSTL63-.js";
4
4
  import { AstroIntegration } from "astro";
5
5
  //#region src/store.d.ts
6
6
  interface FileStoreOptions {
@@ -129,6 +129,13 @@ interface HostedEditorIntegrationOptions {
129
129
  module: string;
130
130
  /** `required` (default): the whole deployment is the editor, so visitors are sent to sign in. See `createHostedMiddleware`. */
131
131
  signIn?: 'required' | 'optional';
132
+ /**
133
+ * The theme's preview renderer, relative to the project root: the module that default-exports `defineThemePreview`.
134
+ * Default `src/lib/render-preview.ts` when the file exists. It is what lets the editor redraw a draft as it changes
135
+ * (a section just added, a layout switched, the header and footer). `false` leaves it out: such changes then show
136
+ * after Save and a reload.
137
+ */
138
+ previewModule?: string | false;
132
139
  }
133
140
  /**
134
141
  * Turns an Astro project into the hosted editor: server rendering, the sign-in middleware, and pages that draw from the
package/dist/astro.js CHANGED
@@ -1,4 +1,4 @@
1
- import { D as ContentReadError, O as ContentValidationError, S as loadThemePreview, _ as parseKey, b as PreviewUnavailableError, c as resolveCollections, v as StoreError, y as StoreKeyError } from "./collections-BbL4_4jt.js";
1
+ import { O as ContentReadError, S as loadThemePreview, _ as parseKey, b as PreviewUnavailableError, c as resolveCollections, k as ContentValidationError, v as StoreError, y as StoreKeyError } from "./collections-Bm3RWg2K.js";
2
2
  import { t as defaultTheme } from "./theme-BvqJ8UnS.js";
3
3
  import { a as resolvePageRules, n as createPageSchema, 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, t as SCHEMA_VERSION_KEY } from "./migrate-b408EaLp.js";
@@ -6,7 +6,7 @@ import { i as resolveMaxImageBytes, n as formatBytes, r as resolveConvert } from
6
6
  import { n as isLocalRequest, t as JSON_BODY_LIMIT } from "./request-guards-BcSUj8Gc.js";
7
7
  import { i as resolveInside, n as isInside, r as resolveDir, t as asDirectory } from "./security-CBiOYdVE.js";
8
8
  import { a as resolveFormsConfig, n as formFile, r as formsAreLive, t as createFormsMiddleware } from "./forms-dev-CzUHR7oS.js";
9
- import { a as isHistoryId, c as imageBodyLimit, d as stableStringify, i as historyId, l as IMAGE_EXTENSION, n as missingImageSvg, o as COMMIT_MESSAGE_LIMIT, p as videoBodyLimit, r as handleEditorRequest, s as GitError, t as githubStore, u as uploadStem } from "./github-store-D3LEUhcM.js";
9
+ import { a as isHistoryId, c as imageBodyLimit, d as stableStringify, i as historyId, l as IMAGE_EXTENSION, n as missingImageSvg, o as COMMIT_MESSAGE_LIMIT, p as videoBodyLimit, r as handleEditorRequest, s as GitError, t as githubStore, u as uploadStem } from "./github-store-Dt_YuOPD.js";
10
10
  import { S as isAssetPath } from "./draft-store-DBEfw_Gq.js";
11
11
  import { n as contentReloadPlugin, r as dropEarlyReloadAfterSave } from "./reload-BzVw721A.js";
12
12
  import { i as syncSections, r as staleSectionsMessage } from "./sections-manifest-CO9QfJPG.js";
@@ -969,6 +969,15 @@ function staleTemplateProblems(root) {
969
969
  //#region src/hosted-integration.ts
970
970
  const VIRTUAL_ID = "virtual:bearminion/editor";
971
971
  const RESOLVED_ID = `\0${VIRTUAL_ID}`;
972
+ const DEFAULT_PREVIEW_MODULE = "src/lib/render-preview.ts";
973
+ /** The absolute path of the preview module, or `null` when the site has none. A module named by hand must exist. */
974
+ function resolvePreviewModule(root, option) {
975
+ if (option === false) return null;
976
+ const file = path.resolve(root, option ?? DEFAULT_PREVIEW_MODULE);
977
+ if (fs.existsSync(file)) return file;
978
+ if (option === void 0) return null;
979
+ throw new Error(`bearminionHostedEditor: previewModule ${JSON.stringify(option)} does not exist (looked for ${file}).`);
980
+ }
972
981
  /**
973
982
  * Turns an Astro project into the hosted editor: server rendering, the sign-in middleware, and pages that draw from the
974
983
  * repository's current content (`Astro.locals.bearminion`). Add it to the editor deployment's build only: the public
@@ -984,6 +993,8 @@ function bearminionHostedEditor(options) {
984
993
  if (!config.adapter) throw new Error("bearminionHostedEditor renders on a server, so the project needs an adapter (for example @astrojs/cloudflare or @astrojs/vercel). Add it to the editor build only.");
985
994
  const root = fileURLToPath(config.root);
986
995
  const editorModule = path.resolve(root, options.module);
996
+ const previewModule = resolvePreviewModule(root, options.previewModule);
997
+ if (!previewModule && options.previewModule === void 0) logger.warn(`No ${DEFAULT_PREVIEW_MODULE}, so the editor has no live preview: a section just added shows after Save and a reload. Name the module with \`previewModule\`, or pass \`previewModule: false\` to silence this.`);
987
998
  const stale = staleTemplateProblems(root);
988
999
  if (stale.length > 0) logger.warn(`This site's files are older than the editor needs:\n${stale.map((problem) => ` - ${problem}`).join("\n")}\nHow to bring them up to date: ${TEMPLATE_DOCS}`);
989
1000
  updateConfig({
@@ -994,7 +1005,12 @@ function bearminionHostedEditor(options) {
994
1005
  plugins: [{
995
1006
  name: "bearminion:hosted-editor-module",
996
1007
  resolveId: (id) => id === VIRTUAL_ID ? RESOLVED_ID : null,
997
- load: (id) => id === RESOLVED_ID ? `export { default as editor } from ${JSON.stringify(editorModule)}\nexport const signIn = ${JSON.stringify(signIn)}\n` : null
1008
+ load: (id) => id === RESOLVED_ID ? [
1009
+ `export { default as editor } from ${JSON.stringify(editorModule)}`,
1010
+ `export const signIn = ${JSON.stringify(signIn)}`,
1011
+ previewModule ? `export const preview = () => import(${JSON.stringify(previewModule)}).then((module) => module.default)` : "export const preview = undefined",
1012
+ ""
1013
+ ].join("\n") : null
998
1014
  }]
999
1015
  }
1000
1016
  });
@@ -127,6 +127,41 @@ async function loadThemePreview(environment, previewModule) {
127
127
  if (!preview || typeof preview.page !== "function") throw new Error(`${previewModule} must default-export defineThemePreview({ page, site? }).`);
128
128
  return preview;
129
129
  }
130
+ /**
131
+ * The two renderers the editor API calls, from a theme's preview. For a server that holds the theme's components in
132
+ * its own bundle (the hosted editor); the dev server loads the module through Vite instead.
133
+ */
134
+ function previewRenderers(source) {
135
+ let loading;
136
+ const load = () => {
137
+ loading ??= Promise.resolve(typeof source === "function" ? source() : source).then((preview) => {
138
+ if (!preview || typeof preview.page !== "function") throw new Error("The preview module must default-export defineThemePreview({ page, site? }).");
139
+ return preview;
140
+ });
141
+ loading.catch(() => {
142
+ loading = void 0;
143
+ });
144
+ return loading;
145
+ };
146
+ return {
147
+ async renderPreview(page, motion) {
148
+ const preview = await load();
149
+ const sections = typeof page === "object" && page !== null && "sections" in page && Array.isArray(page.sections) ? page.sections : [];
150
+ return preview.page({
151
+ sections,
152
+ motion
153
+ });
154
+ },
155
+ async renderSitePreview(site, pathname) {
156
+ const preview = await load();
157
+ if (!preview.site) throw new PreviewUnavailableError("The theme preview does not define `site`, so header and footer have no live preview.");
158
+ return preview.site({
159
+ site,
160
+ pathname
161
+ });
162
+ }
163
+ };
164
+ }
130
165
  //#endregion
131
166
  //#region src/entry-blocks.ts
132
167
  const EDITABLE = /* @__PURE__ */ new Set([
@@ -732,4 +767,4 @@ async function renameEntry(store, collection, slug, next) {
732
767
  };
733
768
  }
734
769
  //#endregion
735
- export { enumFields as C, ContentReadError as D, ContentError as E, ContentValidationError as O, loadThemePreview as S, schemaProps as T, parseKey as _, listEntries as a, PreviewUnavailableError as b, resolveCollections as c, validateEditorPage as d, validatePage as f, pageKey as g, SITE_KEY as h, fieldDefinitions as i, formatContentIssues as k, updateEntry as l, PAGES_DIR as m, createEntry as n, readEntry as o, validateSite as p, deleteEntry as r, renameEntry as s, collection as t, fieldIssues as u, StoreError as v, imageFields as w, defineThemePreview as x, StoreKeyError as y };
770
+ export { formatContentIssues as A, previewRenderers as C, ContentError as D, schemaProps as E, ContentReadError as O, loadThemePreview as S, imageFields as T, parseKey as _, listEntries as a, PreviewUnavailableError as b, resolveCollections as c, validateEditorPage as d, validatePage as f, pageKey as g, SITE_KEY as h, fieldDefinitions as i, ContentValidationError as k, updateEntry as l, PAGES_DIR as m, createEntry as n, readEntry as o, validateSite as p, deleteEntry as r, renameEntry as s, collection as t, fieldIssues as u, StoreError as v, enumFields as w, defineThemePreview as x, StoreKeyError as y };
package/dist/content.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { d as SectionOf, g as ContentModel, t as Page } from "./page-D1pdneYm.js";
1
+ import { d as SectionOf, g as ContentModel, t as Page } from "./page-BGSTL63-.js";
2
2
  import { z } from "zod";
3
3
  //#region src/content.d.ts
4
4
  export interface ContentCollectionsOptions {
@@ -1,4 +1,4 @@
1
- import { _ as SectionRegistry, ht as SiteDefinition, n as PageRules, w as ContentMigrator, y as ThemeDefinition } from "./page-D1pdneYm.js";
1
+ import { _ as SectionRegistry, ht as SiteDefinition, n as PageRules, w as ContentMigrator, y as ThemeDefinition } from "./page-BGSTL63-.js";
2
2
  import { ZodType, z } from "zod";
3
3
  //#region src/upload-names.d.ts
4
4
  type ImageKind = 'png' | 'jpeg' | 'webp' | 'gif' | 'avif';
@@ -1,4 +1,4 @@
1
- import { y as ContentStore } from "./editor-context-ESJwMFpS.js";
1
+ import { y as ContentStore } from "./editor-context-DzRwKENi.js";
2
2
  //#region src/store-error.d.ts
3
3
  /** A key that is empty, has an empty or dot segment, or leaves its base directory. */
4
4
  declare class StoreKeyError extends Error {
@@ -1,4 +1,4 @@
1
- import { D as ContentReadError, O as ContentValidationError, _ as parseKey, a as listEntries, b as PreviewUnavailableError, d as validateEditorPage, f as validatePage, g as pageKey, h as SITE_KEY, i as fieldDefinitions, l as updateEntry, m as PAGES_DIR, n as createEntry, o as readEntry, p as validateSite, r as deleteEntry, s as renameEntry, u as fieldIssues, v as StoreError, w as imageFields, y as StoreKeyError } from "./collections-BbL4_4jt.js";
1
+ import { O as ContentReadError, T as imageFields, _ as parseKey, a as listEntries, b as PreviewUnavailableError, d as validateEditorPage, f as validatePage, g as pageKey, h as SITE_KEY, i as fieldDefinitions, k as ContentValidationError, l as updateEntry, m as PAGES_DIR, n as createEntry, o as readEntry, p as validateSite, r as deleteEntry, s as renameEntry, u as fieldIssues, v as StoreError, y as StoreKeyError } from "./collections-Bm3RWg2K.js";
2
2
  import { c as withoutOrphanSections, d as isOrphanSection, i as isSystemPage } from "./page-wlcQJAA-.js";
3
3
  import { r as API_PREFIX, t as SCHEMA_VERSION_KEY } from "./migrate-b408EaLp.js";
4
4
  import { n as formatBytes, t as DEFAULT_IMAGE_BYTE_LIMIT } from "./upload-rules-Cao9uY5K.js";
@@ -849,7 +849,7 @@ const previewBodySchema = z.object({
849
849
  motion: z.boolean().optional()
850
850
  }).strict();
851
851
  async function postPreview(request, context, meta) {
852
- if (!meta.renderPreview) return problem(501, "preview_unavailable", "Live preview is only available while astro dev is running.");
852
+ if (!meta.renderPreview) return problem(501, "preview_unavailable", "Live preview is not available here: no theme preview renderer is wired in.");
853
853
  const body = await readJsonBody(request);
854
854
  if (body.response) return body.response;
855
855
  const payload = previewBodySchema.safeParse(body.value);
@@ -1,9 +1,12 @@
1
- import { t as createHostedMiddleware } from "./hosted-middleware-CedN9WNM.js";
2
- import { editor, signIn } from "virtual:bearminion/editor";
1
+ import { t as createHostedMiddleware } from "./hosted-middleware-CsROahka.js";
2
+ import { editor, preview, signIn } from "virtual:bearminion/editor";
3
3
  //#region src/hosted-astro.ts
4
4
  let ready;
5
5
  const onRequest = async (context, next) => {
6
- ready ??= Promise.resolve(typeof editor === "function" ? editor(context) : editor).then((built) => createHostedMiddleware(built, { signIn }));
6
+ ready ??= Promise.resolve(typeof editor === "function" ? editor(context) : editor).then((built) => createHostedMiddleware(built, {
7
+ signIn,
8
+ ...preview ? { preview } : {}
9
+ }));
7
10
  try {
8
11
  return await (await ready)(context, next);
9
12
  } catch (error) {
@@ -349,8 +349,9 @@ function failedPage(error) {
349
349
  }
350
350
  function createHostedMiddleware(editor, options = {}) {
351
351
  const required = options.signIn !== "optional";
352
+ const handleOptions = options.preview ? { preview: options.preview } : {};
352
353
  return async ({ request, locals }, next) => {
353
- const handled = await editor.handle(request);
354
+ const handled = await editor.handle(request, handleOptions);
354
355
  if (handled) return handled;
355
356
  const scope = await editor.scope(request);
356
357
  if (!scope) {