bearminion 1.19.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,16 @@
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
+
3
14
  ## 1.19.0
4
15
 
5
16
  ### 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
@@ -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 };
@@ -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) {
package/dist/hosted.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { _ as CollectionOptions, n as ImageConvertOptions, t as EditorContext, v as collection, y as ContentStore } from "./editor-context-DzRwKENi.js";
2
2
  import { i as StoreKeyError, n as githubStore, r as StoreError, t as GithubStoreOptions } from "./github-store-DsLCe5MR.js";
3
3
  import { g as ContentModel, n as PageRules, t as Page } from "./page-BGSTL63-.js";
4
+ import { r as ThemePreviewSource } from "./preview-DFLna-Be.js";
4
5
  //#region src/api.d.ts
5
6
  interface HandleMeta {
6
7
  /**
@@ -147,12 +148,21 @@ interface HostedEditorConfig extends ContentModel {
147
148
  /** The clock, in milliseconds. For tests. */
148
149
  now?: () => number;
149
150
  }
151
+ interface HostedHandleOptions {
152
+ /**
153
+ * The theme's preview renderer (the default export of `src/lib/render-preview.ts`), or a function that loads it.
154
+ * With it the editor redraws a draft as it changes: a section just added, a layout switched, the header and footer.
155
+ * Without it the preview endpoints answer 501 and such changes show after Save and a reload.
156
+ * `bearminionHostedEditor` passes it by itself.
157
+ */
158
+ preview?: ThemePreviewSource;
159
+ }
150
160
  interface HostedEditor {
151
161
  /**
152
162
  * Answers `/__bearminion/auth/*` (sign-in) and `/__bearminion/api/*` (the editor API, signed-in people only).
153
163
  * Returns `null` for any other path, so the site's own routes carry on.
154
164
  */
155
- handle(request: Request): Promise<Response | null>;
165
+ handle(request: Request, options?: HostedHandleOptions): Promise<Response | null>;
156
166
  /**
157
167
  * Passes a page the site rendered through, adding the editor overlay when the request comes from a signed-in
158
168
  * person. Anyone else gets the page untouched. A page with the overlay is marked `private, no-store`, so no cache
@@ -186,6 +196,8 @@ interface HostedMiddlewareOptions {
186
196
  * live content and the overlay.
187
197
  */
188
198
  signIn?: 'required' | 'optional';
199
+ /** The theme's preview renderer, for the editor's live preview. See `HostedHandleOptions.preview`. */
200
+ preview?: ThemePreviewSource;
189
201
  }
190
202
  interface HostedMiddlewareContext {
191
203
  request: Request;
package/dist/hosted.js CHANGED
@@ -1,11 +1,11 @@
1
- import { D as ContentReadError, O as ContentValidationError, c as resolveCollections, g as pageKey, h as SITE_KEY, t as collection, v as StoreError, y as StoreKeyError } from "./collections-BbL4_4jt.js";
1
+ import { C as previewRenderers, O as ContentReadError, c as resolveCollections, g as pageKey, h as SITE_KEY, k as ContentValidationError, t as collection, 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, c as withoutOrphanSections, n as createPageSchema, r as createTolerantPageSchema, s as slugSchema } from "./page-wlcQJAA-.js";
4
4
  import { n as createMigrator } from "./migrate-b408EaLp.js";
5
5
  import { i as resolveMaxImageBytes, r as resolveConvert } from "./upload-rules-Cao9uY5K.js";
6
- import { f as DEFAULT_VIDEO_BYTE_LIMIT, n as missingImageSvg, r as handleEditorRequest, t as githubStore } from "./github-store-D3LEUhcM.js";
6
+ import { f as DEFAULT_VIDEO_BYTE_LIMIT, n as missingImageSvg, r as handleEditorRequest, t as githubStore } from "./github-store-Dt_YuOPD.js";
7
7
  import { S as isAssetPath } from "./draft-store-DBEfw_Gq.js";
8
- import { n as AUTH_PREFIX, r as createHostedAuth, t as createHostedMiddleware } from "./hosted-middleware-CedN9WNM.js";
8
+ import { n as AUTH_PREFIX, r as createHostedAuth, t as createHostedMiddleware } from "./hosted-middleware-CsROahka.js";
9
9
  //#region src/hosted-context.ts
10
10
  /** The context for `handleEditorRequest`. */
11
11
  function createHostedContext(options) {
@@ -199,7 +199,16 @@ function createHostedEditor(config) {
199
199
  content: createStoreContent(config, store)
200
200
  };
201
201
  }
202
- async function handle(request) {
202
+ const renderers = /* @__PURE__ */ new WeakMap();
203
+ function renderersFor(source) {
204
+ let found = renderers.get(source);
205
+ if (!found) {
206
+ found = previewRenderers(source);
207
+ renderers.set(source, found);
208
+ }
209
+ return found;
210
+ }
211
+ async function handle(request, options = {}) {
203
212
  const signIn = await auth.handle(request);
204
213
  if (signIn) return signIn;
205
214
  const pathname = new URL(request.url).pathname.replace(/\/+$/, "");
@@ -240,7 +249,7 @@ function createHostedEditor(config) {
240
249
  ...config.migrations ? { migrations: config.migrations } : {},
241
250
  ...config.schemaVersion === void 0 ? {} : { schemaVersion: config.schemaVersion },
242
251
  store: storeFor(found.session.token)
243
- }));
252
+ }), options.preview ? renderersFor(options.preview) : {});
244
253
  if (response && found.cookie) response.headers.append("set-cookie", found.cookie);
245
254
  return response;
246
255
  }
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import { _ as CollectionOptions, a as CommitRequest, c as HistoryEntry, d as Sav
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
3
  import { $ as mergeJsonLd, $t as tones, A as SectionDefinition, At as MAX_NAV_DEPTH, B as FieldIcons, Bt as toneSchema, C as ContentMigration, Ct as siteConsentSchema, D as SCHEMA_VERSION_KEY, Dt as ButtonStyle, E as DocumentKind, Et as themeSchema, F as defineWireframe, Ft as imageSchema, G as SiteJsonLdIds, Gt as EnumOption, H as ShowWhen, Ht as withEmphasis, I as wireKinds, It as linkSchema, J as generateSiteJsonLd, Jt as StringOption, K as SiteJsonLdSource, Kt as NumberOption, L as wireframeIssues, Lt as richTextSchema, M as WireKind, Mt as Text, N as WireRect, Nt as Tone, O as createMigrator, Ot as Image, P as Wireframe, Pt as htmlIdSchema, Q as jsonLdWarnings, Qt as toneOption, R as OptionalContent, Rt as textMarkSchema, S as defineTheme, St as siteAnalyticsSchema, T as ContentVersioning, Tt as themeColorsSchema, U as JsonLdBlock, Ut as BooleanOption, V as ShowCondition, Vt as trackingIdSchema, W as JsonLdResult, Wt as CountRule, X as isPlaceholderSiteUrl, Xt as motionOption, Y as hasJsonLdId, Yt as buttonStyles, Z as jsonLdSchema, Zt as themeModes, _ as SectionRegistry, _t as SiteSeo, a as createPageSchema, at as DEFAULT_MAX_HEADER_ACTIONS, b as ThemeFont, bt as brandLogoSchema, c as withoutOrphanSections, ct as FooterConfig, d as SectionOf, dt as Site, en as variantOption, et as parseJsonLdInput, f as anchorSchema, ft as SiteAnalytics, g as ContentModel, gt as SiteOf, h as API_PREFIX, ht as SiteDefinition, i as Seo, it as DEFAULT_MAX_FOOTER_COLUMNS, j as defineSection, jt as RichText, k as SectionConfig, kt as Link, l as BaseSection, lt as Header, m as sectionIdSchema, mt as SiteConsent, nt as upsertJsonLd, o as isSystemPage, ot as Footer, p as createSectionSchema, pt as SiteConfig, q as formatJsonLd, qt as Option, r as SYSTEM_PAGES, rt as BRAND_LOGO_HEIGHT, s as seoSchema, st as FooterColumn, t as Page, tt as siteJsonLdIds, u as PropsOf, ut as HeaderConfig, v as ThemeConfig, vt as SiteWith, w as ContentMigrator, wt as siteSeoSchema, x as defaultTheme, xt as defineSite, y as ThemeDefinition, yt as Theme, z as FieldChoices, zt as textSchema } from "./page-BGSTL63-.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
+ import { i as defineThemePreview, n as ThemePreview, t as SitePreviewHtml } from "./preview-DFLna-Be.js";
5
6
  //#region src/errors.d.ts
6
7
  /** One schema problem, addressed by a dot path such as `sections.0.props.heading`. */
7
8
  interface ContentIssue {
@@ -33,44 +34,6 @@ export declare const DEFAULT_IMAGE_POSITION: ImagePosition;
33
34
  export declare function isImageFit(value: unknown): value is ImageFit;
34
35
  export declare function isImagePosition(value: unknown): value is ImagePosition;
35
36
  //#endregion
36
- //#region src/preview.d.ts
37
- /** The header and footer of a draft site, as HTML. */
38
- interface SitePreviewHtml {
39
- header: string;
40
- footer: string;
41
- }
42
- /**
43
- * How a theme renders drafts for the editor's live preview. The editor calls it from the dev server;
44
- * it never reads or writes content files.
45
- */
46
- interface ThemePreview<TModel extends ContentModel = ContentModel> {
47
- /** The draft page's sections as HTML, which replaces `main#content`. Orphaned sections are already left out. */
48
- page(input: {
49
- sections: SectionOf<TModel['sections']>[];
50
- motion: boolean;
51
- }): Promise<string>;
52
- /**
53
- * The draft site's header and footer as HTML, so brand, layout and links update without a reload.
54
- * Optional: without it, header and footer changes appear after you save and reload.
55
- */
56
- site?(input: {
57
- site: SiteOf<TModel['site']>;
58
- pathname: string;
59
- }): Promise<SitePreviewHtml>;
60
- }
61
- /**
62
- * Declare a theme's preview renderer. Default-export it from the module named by `previewModule`
63
- * (default `/src/lib/render-preview.ts`). The model type ties the inputs to your section registry and site:
64
- *
65
- * ```ts
66
- * export default defineThemePreview<typeof contentModel>({
67
- * async page({ sections, motion }) { ... },
68
- * async site({ site, pathname }) { ... },
69
- * })
70
- * ```
71
- */
72
- export declare function defineThemePreview<TModel extends ContentModel = ContentModel>(preview: ThemePreview<TModel>): ThemePreview<TModel>;
73
- //#endregion
74
37
  //#region src/media-source.d.ts
75
38
  /**
76
39
  * What a Media section's video link points at. YouTube and Vimeo links become privacy-friendly embeds
@@ -204,4 +167,4 @@ interface ContrastCheck {
204
167
  /** Text pairs a visitor reads: text on its background, label on the accent fill, link on its background. */
205
168
  export declare function contrastChecks(colors: ThemeColors | undefined): ContrastCheck[];
206
169
  //#endregion
207
- export { API_PREFIX, type ApiIssue, type ApiProblem, BRAND_LOGO_HEIGHT, type BaseSection, type BooleanOption, type ButtonStyle, type ChangedFile, type CollectionOptions, type CommitRequest, type CommitResult, type ConsentCopy, type ConsentReopen, type ConsentText, type ConsentTextKey, type ContentIssue, type ContentMigration, type ContentMigrator, type ContentModel, type ContentVersioning, type ContrastCheck, type CountRule, type CreatePageRequest, DEFAULT_MAX_FOOTER_COLUMNS, DEFAULT_MAX_HEADER_ACTIONS, type DocumentKind, type EnumOption, type FieldChoices, type FieldIcons, type FontMark, type Footer, type FooterColumn, type FooterConfig, type FormFieldErrors, type FormResult, type FormSubmission, type GitInfo, HONEYPOT_FIELD, type Header, type HeaderConfig, type HistoryEntry, type Image, type ImageFit, type ImagePosition, type JsonLdBlock, type JsonLdResult, type Link, MAX_NAV_DEPTH, type MediaSource, type NumberOption, type Option, type OptionalContent, type Page, type PageListItem, type PropsOf, type RichText, SCHEMA_VERSION_KEY, SYSTEM_PAGES, type SaveRequest, type SaveResponse, type SectionConfig, type SectionDefinition, type SectionOf, type SectionRegistry, type Seo, type ShowCondition, type ShowWhen, type Site, type SiteAnalytics, type SiteConfig, type SiteConsent, type SiteDefinition, type SiteJsonLdIds, type SiteJsonLdSource, type SiteOf, type SitePreview, type SitePreviewHtml, type SiteSeo, type SiteWith, type StringOption, TURNSTILE_FIELD, type Text, type TextMark, type TextRun, type Theme, type ThemeColors, type ThemeConfig, type ThemeDefinition, type ThemeFont, type ThemePreview, type Tone, type UploadedImage, type UploadedVideo, type WeightMark, type WireKind, type WireRect, type Wireframe, anchorSchema, applyTextMark, brandLogoSchema, buttonStyles, collection, createMigrator, createPageSchema, createSectionSchema, defaultTheme, defineSection, defineSite, defineTheme, defineWireframe, fontMarks, formatJsonLd, generateSiteJsonLd, hasJsonLdId, htmlIdSchema, imageSchema, isPlaceholderSiteUrl, isSystemPage, jsonLdSchema, jsonLdWarnings, linkSchema, markClass, marksFromEmphasis, mergeJsonLd, motionOption, parseJsonLdInput, reconcileMarks, renderMarkedHtml, richTextSchema, sectionIdSchema, seoSchema, siteAnalyticsSchema, siteConsentSchema, siteJsonLdIds, siteSeoSchema, splitMarkedText, textMarkSchema, textSchema, themeColorsSchema, themeModes, themeSchema, toneOption, toneSchema, tones, trackingIdSchema, upsertJsonLd, variantOption, weightMarks, wireKinds, wireframeIssues, withEmphasis, withoutOrphanSections };
170
+ export { API_PREFIX, type ApiIssue, type ApiProblem, BRAND_LOGO_HEIGHT, type BaseSection, type BooleanOption, type ButtonStyle, type ChangedFile, type CollectionOptions, type CommitRequest, type CommitResult, type ConsentCopy, type ConsentReopen, type ConsentText, type ConsentTextKey, type ContentIssue, type ContentMigration, type ContentMigrator, type ContentModel, type ContentVersioning, type ContrastCheck, type CountRule, type CreatePageRequest, DEFAULT_MAX_FOOTER_COLUMNS, DEFAULT_MAX_HEADER_ACTIONS, type DocumentKind, type EnumOption, type FieldChoices, type FieldIcons, type FontMark, type Footer, type FooterColumn, type FooterConfig, type FormFieldErrors, type FormResult, type FormSubmission, type GitInfo, HONEYPOT_FIELD, type Header, type HeaderConfig, type HistoryEntry, type Image, type ImageFit, type ImagePosition, type JsonLdBlock, type JsonLdResult, type Link, MAX_NAV_DEPTH, type MediaSource, type NumberOption, type Option, type OptionalContent, type Page, type PageListItem, type PropsOf, type RichText, SCHEMA_VERSION_KEY, SYSTEM_PAGES, type SaveRequest, type SaveResponse, type SectionConfig, type SectionDefinition, type SectionOf, type SectionRegistry, type Seo, type ShowCondition, type ShowWhen, type Site, type SiteAnalytics, type SiteConfig, type SiteConsent, type SiteDefinition, type SiteJsonLdIds, type SiteJsonLdSource, type SiteOf, type SitePreview, type SitePreviewHtml, type SiteSeo, type SiteWith, type StringOption, TURNSTILE_FIELD, type Text, type TextMark, type TextRun, type Theme, type ThemeColors, type ThemeConfig, type ThemeDefinition, type ThemeFont, type ThemePreview, type Tone, type UploadedImage, type UploadedVideo, type WeightMark, type WireKind, type WireRect, type Wireframe, anchorSchema, applyTextMark, brandLogoSchema, buttonStyles, collection, createMigrator, createPageSchema, createSectionSchema, defaultTheme, defineSection, defineSite, defineTheme, defineThemePreview, defineWireframe, fontMarks, formatJsonLd, generateSiteJsonLd, hasJsonLdId, htmlIdSchema, imageSchema, isPlaceholderSiteUrl, isSystemPage, jsonLdSchema, jsonLdWarnings, linkSchema, markClass, marksFromEmphasis, mergeJsonLd, motionOption, parseJsonLdInput, reconcileMarks, renderMarkedHtml, richTextSchema, sectionIdSchema, seoSchema, siteAnalyticsSchema, siteConsentSchema, siteJsonLdIds, siteSeoSchema, splitMarkedText, textMarkSchema, textSchema, themeColorsSchema, themeModes, themeSchema, toneOption, toneSchema, tones, trackingIdSchema, upsertJsonLd, variantOption, weightMarks, wireKinds, wireframeIssues, withEmphasis, withoutOrphanSections };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { C as enumFields, D as ContentReadError, E as ContentError, O as ContentValidationError, T as schemaProps, k as formatContentIssues, t as collection, x as defineThemePreview } from "./collections-BbL4_4jt.js";
1
+ import { A as formatContentIssues, D as ContentError, E as schemaProps, O as ContentReadError, k as ContentValidationError, t as collection, w as enumFields, x as defineThemePreview } from "./collections-Bm3RWg2K.js";
2
2
  import { n as defineTheme, t as defaultTheme } from "./theme-BvqJ8UnS.js";
3
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";
@@ -0,0 +1,42 @@
1
+ import { d as SectionOf, g as ContentModel, gt as SiteOf } from "./page-BGSTL63-.js";
2
+ //#region src/preview.d.ts
3
+ /** The header and footer of a draft site, as HTML. */
4
+ interface SitePreviewHtml {
5
+ header: string;
6
+ footer: string;
7
+ }
8
+ /**
9
+ * How a theme renders drafts for the editor's live preview. The editor calls it from the dev server;
10
+ * it never reads or writes content files.
11
+ */
12
+ interface ThemePreview<TModel extends ContentModel = ContentModel> {
13
+ /** The draft page's sections as HTML, which replaces `main#content`. Orphaned sections are already left out. */
14
+ page(input: {
15
+ sections: SectionOf<TModel['sections']>[];
16
+ motion: boolean;
17
+ }): Promise<string>;
18
+ /**
19
+ * The draft site's header and footer as HTML, so brand, layout and links update without a reload.
20
+ * Optional: without it, header and footer changes appear after you save and reload.
21
+ */
22
+ site?(input: {
23
+ site: SiteOf<TModel['site']>;
24
+ pathname: string;
25
+ }): Promise<SitePreviewHtml>;
26
+ }
27
+ /**
28
+ * Declare a theme's preview renderer. Default-export it from the module named by `previewModule`
29
+ * (default `/src/lib/render-preview.ts`). The model type ties the inputs to your section registry and site:
30
+ *
31
+ * ```ts
32
+ * export default defineThemePreview<typeof contentModel>({
33
+ * async page({ sections, motion }) { ... },
34
+ * async site({ site, pathname }) { ... },
35
+ * })
36
+ * ```
37
+ */
38
+ declare function defineThemePreview<TModel extends ContentModel = ContentModel>(preview: ThemePreview<TModel>): ThemePreview<TModel>;
39
+ /** A theme's preview, or a function that loads it on first use (so a server only pays for it when someone edits). */
40
+ type ThemePreviewSource = ThemePreview | (() => ThemePreview | Promise<ThemePreview>);
41
+ //#endregion
42
+ export { defineThemePreview as i, ThemePreview as n, ThemePreviewSource as r, SitePreviewHtml as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bearminion",
3
- "version": "1.19.0",
3
+ "version": "1.20.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",
@@ -3,7 +3,7 @@ import type { Site } from '../components/organisms/site-definition'
3
3
  import type { Page } from '../components/sections/definitions'
4
4
  import SectionList from '../components/sections/SectionList.astro'
5
5
  import Base from '../layouts/Base.astro'
6
- import { getPages, getSite } from '../lib/content'
6
+ import { getPage, getPages, getSite } from '../lib/content'
7
7
 
8
8
  export async function getStaticPaths() {
9
9
  const site = await getSite()
@@ -31,6 +31,11 @@ if (live) {
31
31
  site = (await live.content.getSite()) as Site
32
32
  page = (await live.content.getPage(Astro.params.slug ?? 'index')) as Page | undefined
33
33
  if (!page) return Astro.rewrite('/404')
34
+ } else if (!page) {
35
+ // A server build has no props: a visitor to a hosted editor with `signIn: 'optional'` gets the build's content.
36
+ site = await getSite()
37
+ page = await getPage(Astro.params.slug ?? 'index')
38
+ if (!page || page.slug === '404') return Astro.rewrite('/404')
34
39
  }
35
40
  if (!site || !page) throw new Error(`No content for ${Astro.url.pathname}.`)
36
41
  ---
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "template": "default",
4
- "version": "1.19.0",
4
+ "version": "1.20.0",
5
5
  "files": {
6
6
  "src/components/atoms/Button.astro": {
7
7
  "hash": "7be42b3dc3a3b59bec169de32a9d801904689e2705473d1945724658dc799043",
@@ -356,9 +356,10 @@
356
356
  ]
357
357
  },
358
358
  "src/pages/[...slug].astro": {
359
- "hash": "08bf1ac4b4a8a9961045f91e74a22aa2ec3b622998ebfa1f167ab39039bbf467",
359
+ "hash": "dfe279b2d84767700c0fbbbb85077c3f8f7334671adc25c633ae2fb1802ac28f",
360
360
  "history": [
361
- "c1f491e544eead7313f31a8e1c630776b5ec7ab886f61cf04fbd66eeed69fa28"
361
+ "c1f491e544eead7313f31a8e1c630776b5ec7ab886f61cf04fbd66eeed69fa28",
362
+ "08bf1ac4b4a8a9961045f91e74a22aa2ec3b622998ebfa1f167ab39039bbf467"
362
363
  ]
363
364
  }
364
365
  },