@bettercms-ai/astro 0.25.0 → 0.27.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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sections.ts","../src/bindings.ts","../src/runtime.ts","../src/section-root.ts"],"sourcesContent":["/**\n * What `<BcmsSections>` (components/BcmsSections.astro) is made of, kept as a `.ts` module so it is\n * testable without an Astro compiler: where the page's block list comes from, and how a block's\n * stamp lands on the root of the section the page's own code rendered.\n *\n * The order itself is `planSections` in @bettercms-ai/types, shared with @bettercms-ai/next.\n */\nimport { readPublishedContent } from \"@bettercms-ai/sdk\";\nimport type { ContentBlock } from \"@bettercms-ai/types\";\nimport { stampSoleElement, tagEnd } from \"./bindings.js\";\nimport { decodeTokenSlug } from \"./runtime.js\";\nimport { sectionRootAttrs } from \"./section-root.js\";\n\nexport { sectionRootAttrs };\n\n/** The attribute every root `<BcmsSections>` stamps carries: which page's list placed it. */\nexport const SECTIONS_ATTR = \"data-bcms-sections\";\n/** On the box around a section that is not one element. @see stampSectionRoot */\nexport const SECTION_BOX_ATTR = \"data-bcms-box\";\n\n/**\n * The inline style of a section's box: `display:contents` while the block has no style, and a real\n * box (`flow-root`, unless the style sets a display of its own) carrying it once it has.\n */\nexport const sectionBoxStyle = (style: string | undefined): string =>\n !style ? \"display:contents\" : /(?:^|;)display:/.test(style) ? style : `display:flow-root;${style}`;\n\n/** The comments around the rendered list: where the SDK-drawn sections of `page` start and end. */\nexport const sectionsStart = (page: string): string => `<!--bcms-sections:start page=\"${page.replace(/[^\\w./-]/g, \"\")}\"-->`;\nexport const SECTIONS_END = \"<!--bcms-sections:end-->\";\n\ntype Snapshot = { apiUrl?: string | null; pages?: unknown[]; components?: unknown[]; forms?: unknown[] };\n\n/**\n * The published snapshot's view of one page: its blocks (null when the page is not there), and what draws them.\n *\n * A collection page and the listing page beside it share a slug (`blog`), and the snapshot marks\n * the collection's (`template`). `template` reads that one, whose list is its item template's\n * (`[slug].astro` draws it on every entry); a plain read takes a page of its own route, and falls\n * back to the only row there is. Twin: `sectionsFor` in @bettercms-ai/next.\n */\nexport function publishedSections(page: string, template = false): { blocks: ContentBlock[] | null; components: unknown[]; forms: unknown[]; apiUrl: string | null } {\n const snapshot = readPublishedContent() as Snapshot | null;\n const rows = (Array.isArray(snapshot?.pages) ? snapshot.pages : []).filter((p) => (p as { slug?: unknown } | null)?.slug === page) as { template?: unknown; blocks?: unknown; blockJson?: unknown }[];\n const collection = rows.find((r) => r.template === true);\n const row = template ? collection : (rows.find((r) => r.template !== true) ?? rows[0]);\n const blocks = row?.blocks ?? row?.blockJson;\n return {\n blocks: Array.isArray(blocks) ? (blocks as ContentBlock[]) : null,\n components: Array.isArray(snapshot?.components) ? snapshot.components : [],\n forms: Array.isArray(snapshot?.forms) ? snapshot.forms : [],\n apiUrl: typeof snapshot?.apiUrl === \"string\" ? snapshot.apiUrl : null,\n };\n}\n\n/** The API a draft read goes to: the server's runtime env first (hosting injects it), then the build's. */\nexport function sectionsApiUrl(fallback: string | null): string | null {\n const fromProcess = typeof process !== \"undefined\" ? process.env?.PUBLIC_BCMS_API_URL : undefined;\n if (fromProcess) return fromProcess;\n try {\n return (import.meta.env?.PUBLIC_BCMS_API_URL as string | undefined) ?? fallback;\n } catch {\n return fallback;\n }\n}\n\n/**\n * The DRAFT block list of `page`, when this request is the Visual Editor's draft render of it.\n *\n * The editor enters draft mode with a PAGE preview token (the middleware puts it on\n * `Astro.locals.bcms`); the public preview endpoint that validated it returns that page's draft\n * blocks. The token names ONE page, so any other page renders published. Null on any failure: the\n * page then renders its published structure, never an error.\n */\nexport async function draftSections(page: string, token: string, apiUrl: string | null): Promise<ContentBlock[] | null> {\n if (!apiUrl || decodeTokenSlug(token) !== page) return null;\n try {\n const res = await fetch(`${apiUrl.replace(/\\/+$/, \"\")}/api/v1/preview/${encodeURIComponent(page)}?token=${encodeURIComponent(token)}`, {\n signal: AbortSignal.timeout(5000),\n });\n if (!res.ok) return null;\n const blocks = ((await res.json()) as { data?: { blockJson?: unknown } })?.data?.blockJson;\n return Array.isArray(blocks) ? (blocks as ContentBlock[]) : null;\n } catch {\n return null;\n }\n}\n\nconst escapeAttr = (value: string): string => value.replace(/&/g, \"&amp;\").replace(/\"/g, \"&quot;\");\n\n/**\n * A rendered slot with its block's stamp on the section's OWN root.\n *\n * One element: the attributes are spliced into its start tag and nothing else moves, so\n * `main > section`, `:first-child` and every animation target stay what the author wrote. Its own\n * `style` is kept and the block's declarations follow it, the order the in-place painter writes.\n * A root that already stamps a block is the site's own work and is left as it is.\n *\n * Anything else (text, several roots, a framework island) has no root to stamp, so a box of ours\n * carries the stamp. With no style on the block it is `display:contents`: it draws nothing, and the\n * page lays out as written. A box that draws nothing cannot show a padding, so a block WITH a\n * style gets `display:flow-root` and the style on it (@see sectionBoxStyle). It is marked\n * `data-bcms-style` like any root, and `data-bcms-box` tells the in-place painter to make the same\n * switch when the first style is published between builds.\n *\n * THE ONE LIMIT: a styled box is one block box. In a flex or grid parent its children are then one\n * item instead of several, and their margins stop collapsing with the neighbours'. A section with\n * one root element has no box and no such limit.\n */\nexport function stampSectionRoot(html: string, block: { id?: string | null; style?: unknown }, page: string): string {\n const attrs = sectionRootAttrs(block as Parameters<typeof sectionRootAttrs>[0]);\n const id = attrs[\"data-bcms-block\"];\n if (id === undefined) return html;\n if (stampSoleElement(html, {}) === null) {\n if (html.trim() === \"\") return html;\n const hide = attrs[\"data-bcms-hide\"];\n return (\n `<div style=\"${escapeAttr(sectionBoxStyle(attrs.style))}\" data-bcms-block=\"${escapeAttr(id)}\" data-bcms-style=\"\"` +\n `${hide ? ` data-bcms-hide=\"${escapeAttr(hide)}\"` : \"\"} ${SECTION_BOX_ATTR}=\"\" ${SECTIONS_ATTR}=\"${escapeAttr(page)}\">${html}</div>`\n );\n }\n const start = html.search(/\\S/);\n const end = tagEnd(html, start);\n let tag = html.slice(start, end);\n if (/\\sdata-bcms-block[\\s=>/]/.test(`${tag}>`)) return html;\n const selfClosed = tag.endsWith(\"/\");\n if (selfClosed) tag = tag.slice(0, -1);\n tag = tag.replace(/\\s+$/, \"\");\n let style = attrs.style;\n const own = /\\sstyle\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)')/.exec(tag);\n if (own && style) {\n // The site's declarations first, the block's after: a later declaration wins, as the painter\n // orders them. Written where the site's own attribute stood, as React's `cloneElement` does.\n const merged = `${(own[1] ?? own[2] ?? \"\").replace(/[;\\s]+$/, \"\")};${style}`;\n tag = `${tag.slice(0, own.index)} style=\"${escapeAttr(merged)}\"${tag.slice(own.index + own[0].length)}`;\n style = undefined;\n }\n const added = Object.entries({ ...attrs, style, [SECTIONS_ATTR]: page })\n .filter((entry): entry is [string, string] => entry[1] !== undefined)\n .map(([name, value]) => ` ${name}=\"${escapeAttr(value)}\"`)\n .join(\"\");\n return html.slice(0, start) + tag + added + (selfClosed ? \" /\" : \"\") + html.slice(end);\n}\n","/**\n * Visual Editor addresses for the Astro renderer.\n *\n * Identical contract to `@bettercms-ai/next`'s `bindings.ts`, and the SAME reason for existing:\n * inside a component instance the definition's block ids address nothing, because they are\n * shared by every instance of it. Stamping them produces an orphan on one placement and a\n * duplicate that drops BOTH on two.\n *\n * Kept as a `.ts` module rather than inlined in the `.astro` frontmatter so the logic is\n * testable without an Astro compiler, and so the two SDKs cannot drift from each other by\n * having one file edited and not the other.\n */\nimport type { BindingKind } from \"@bettercms-ai/types\";\nimport { formatPropsAttribute } from \"@bettercms-ai/types\";\n\nexport interface BindingCtx {\n /** Present only inside a component instance, where it is AUTHORITATIVE. */\n fieldAddresses?: Map<string, string>;\n}\n\n/** The address a write lands on, or null when none exists. */\nexport function addressFor(id: string | undefined, prop: string, ctx: BindingCtx): string | null {\n if (!id) return null;\n const key = `${id}__${prop}`;\n if (ctx.fieldAddresses) return ctx.fieldAddresses.get(key) ?? null;\n return key;\n}\n\n/**\n * Attributes for a value rendered as this element's own content. Astro omits `undefined`\n * attributes, so an empty object spreads to nothing.\n */\nexport function bind(\n id: string | undefined,\n prop: string,\n kind: BindingKind,\n ctx: BindingCtx,\n): Record<string, string> {\n const address = addressFor(id, prop, ctx);\n return address ? { \"data-bcms-field\": address, \"data-bcms-kind\": kind } : {};\n}\n\n/**\n * Attributes for values that live in an ATTRIBUTE of this element. `data-bcms-field` addresses\n * one element and an element cannot hold two, so these ride `data-bcms-props`:\n * `<address>|<kind>|<domAttribute>`, semicolon separated.\n *\n * An entry whose value is absent is dropped — `setFieldPath` refuses to create a final key, so\n * the address would be a write the editor rejects.\n */\nexport function bindProps(\n id: string | undefined,\n entries: readonly { prop: string; kind: BindingKind; attr: string; present: boolean }[],\n ctx: BindingCtx,\n): Record<string, string> {\n const resolved = entries.flatMap(({ prop, kind, attr, present }) => {\n if (!present) return [];\n const address = addressFor(id, prop, ctx);\n return address ? [{ address, kind, attr }] : [];\n });\n return resolved.length ? { \"data-bcms-props\": formatPropsAttribute(resolved) } : {};\n}\n\nconst VOID_TAGS = new Set([\"area\", \"base\", \"br\", \"col\", \"embed\", \"hr\", \"img\", \"input\", \"link\", \"meta\", \"source\", \"track\", \"wbr\"]);\nconst RAW_TEXT_TAGS = new Set([\"script\", \"style\", \"textarea\", \"title\"]);\n\n/** Where the tag opened at `from` (`<`) ends, quotes respected; -1 when it never does. */\nexport function tagEnd(html: string, from: number): number {\n let quote = \"\";\n for (let i = from; i < html.length; i++) {\n const c = html[i]!;\n if (quote) {\n if (c === quote) quote = \"\";\n } else if (c === '\"' || c === \"'\") quote = c;\n else if (c === \">\") return i;\n }\n return -1;\n}\n\n/**\n * `<BcmsField>`'s child, when it is ONE element: the same markup with the binding attributes on\n * that element's own tag. Null when the rendered slot is anything else (text, several elements,\n * an element that already declares a field, a framework island), and the caller wraps as before.\n *\n * Why not always wrap: the wrapper is a `<span>` between the author's parent and the author's\n * element. `.hero > h1`, `gsap.utils.toArray(\".hero > *\")` and `:first-child` all stop matching,\n * and an animation that targeted the heading targets nothing. With the attributes on the element\n * itself the page's DOM is exactly the one the author wrote.\n *\n * A scan, not a parser: it only has to find where the first element ends. Anything it is not\n * sure of answers null, which is the old behaviour.\n */\nexport function stampSoleElement(html: string, attrs: Record<string, string | undefined>): string | null {\n const start = html.search(/\\S/);\n const open = /^<([a-zA-Z][\\w:-]*)/.exec(html.slice(start));\n if (start < 0 || !open) return null;\n const tag = open[1]!.toLowerCase();\n const openEnd = tagEnd(html, start);\n // A custom element is a framework's own wrapper (`astro-island`): not the author's element.\n if (openEnd < 0 || tag.includes(\"-\") || /\\sdata-bcms-(?:layout-)?field[\\s=>/]/.test(html.slice(start, openEnd + 1))) return null;\n let i = openEnd + 1;\n if (!VOID_TAGS.has(tag) && html[openEnd - 1] !== \"/\") {\n let depth = 1;\n let raw = RAW_TEXT_TAGS.has(tag) ? tag : \"\";\n while (depth > 0) {\n const lt = html.indexOf(\"<\", i);\n if (lt < 0) return null;\n if (raw) {\n const close = html.toLowerCase().indexOf(`</${raw}`, i);\n if (close < 0) return null;\n i = tagEnd(html, close) + 1;\n if (i === 0) return null;\n raw = \"\";\n depth--;\n continue;\n }\n if (html.startsWith(\"<!--\", lt)) {\n const end = html.indexOf(\"-->\", lt + 4);\n if (end < 0) return null;\n i = end + 3;\n continue;\n }\n const end = tagEnd(html, lt);\n if (end < 0) return null;\n const name = /^<\\/?([a-zA-Z][\\w:-]*)/.exec(html.slice(lt, end + 1))?.[1]?.toLowerCase();\n if (name && html[lt + 1] === \"/\") depth--;\n else if (name && !VOID_TAGS.has(name) && html[end - 1] !== \"/\") {\n depth++;\n if (RAW_TEXT_TAGS.has(name)) raw = name;\n }\n i = end + 1;\n }\n }\n if (html.slice(i).trim() !== \"\") return null;\n const escape = (value: string) => value.replace(/&/g, \"&amp;\").replace(/\"/g, \"&quot;\");\n const added = Object.entries(attrs)\n .filter((entry): entry is [string, string] => entry[1] !== undefined)\n .map(([name, value]) => ` ${name}=\"${escape(value)}\"`)\n .join(\"\");\n // Last on the tag, where React's `cloneElement` puts them: the two lanes emit the same bytes.\n const selfClosed = html[openEnd - 1] === \"/\";\n const at = selfClosed ? openEnd - 1 : openEnd;\n return html.slice(0, at).replace(/\\s+$/, \"\") + added + (selfClosed ? \" \" : \"\") + html.slice(at);\n}\n","/**\n * Runtime for @bettercms-ai/astro — the code the `bettercms:client` virtual\n * module binds to. Provides a published client, per-request draft client\n * selection, typed loaders, and signed-cookie helpers for draft mode.\n *\n * Read-only; no I/O at import time. Safe in Node and edge runtimes (uses Web\n * Crypto + global fetch only).\n */\nimport { createClient, type BetterCMSReadClient } from \"@bettercms-ai/sdk\";\nimport type {\n DeliveredLayout,\n DeliveryComponent,\n DeliveryEntry,\n DeliveryList,\n DeliveryPage,\n} from \"@bettercms-ai/types\";\n\nexport interface RuntimeConfig {\n apiUrl: string;\n workspace: string;\n projectId?: string;\n /** Server-only delivery key (a `content:read:draft` key for drafts). */\n apiKey?: string;\n /**\n * Collapse identical delivery GETs for the life of the process. Set by the integration\n * when Astro's `command === \"build\"` — a static build renders every route from one\n * published dataset, so a repeat read cannot legitimately differ.\n *\n * Never set for `dev` or SSR, where each request must see current content.\n */\n buildCache?: boolean;\n}\n\n/** Per-request draft state, set on `Astro.locals.bcms` by the middleware. */\nexport interface BcmsLocals {\n draft: boolean;\n token?: string;\n}\n\ninterface HasLocals {\n locals: { bcms?: BcmsLocals };\n}\n\nexport interface BetterCMSRuntime {\n /** Published-perspective client (use for SSG / non-draft reads). */\n client: BetterCMSReadClient;\n /** Pick the right client for a request (draft client when draft mode is on). */\n getClient(astro?: HasLocals): BetterCMSReadClient;\n loadEntry<T = Record<string, unknown>>(\n astro: HasLocals,\n slug: string,\n opts?: Parameters<BetterCMSReadClient[\"getEntry\"]>[1],\n ): Promise<DeliveryEntry<T>>;\n loadEntries<T = Record<string, unknown>>(\n astro: HasLocals,\n opts?: Parameters<BetterCMSReadClient[\"listEntries\"]>[0],\n ): Promise<DeliveryList<DeliveryEntry<T>>>;\n loadPage(astro: HasLocals, slug: string): Promise<DeliveryPage | null>;\n /** Component definitions for `<BcmsBlocks components={…}>` — draft-side in draft mode. */\n loadComponents(astro: HasLocals): Promise<DeliveryComponent[]>;\n loadLayout(astro: HasLocals): Promise<DeliveredLayout | null>;\n loadForms(\n astro: HasLocals,\n opts?: Parameters<BetterCMSReadClient[\"listForms\"]>[0],\n ): Promise<Awaited<ReturnType<BetterCMSReadClient[\"listForms\"]>>>;\n}\n\nexport function createRuntime(config: RuntimeConfig): BetterCMSRuntime {\n const { buildCache, ...clientConfig } = config;\n // One client for the whole build, so the cache below is shared across every route\n // rather than rebuilt per render.\n const published = createClient({ ...clientConfig, perspective: \"published\", cache: buildCache });\n\n const getClient = (astro?: HasLocals): BetterCMSReadClient => {\n const bcms = astro?.locals?.bcms;\n if (bcms?.draft) {\n // Explicitly uncached: a draft read exists to show the edit that just happened.\n return createClient({\n ...clientConfig,\n perspective: \"drafts\",\n previewToken: bcms.token,\n cache: false,\n });\n }\n return published;\n };\n\n return {\n client: published,\n getClient,\n loadEntry: (astro, slug, opts) => getClient(astro).getEntry(slug, opts),\n loadEntries: (astro, opts) => getClient(astro).listEntries(opts),\n loadPage: (astro, slug) => getClient(astro).getPage(slug),\n loadComponents: (astro) => getClient(astro).listComponents(),\n loadLayout: (astro) => getClient(astro).getLayout(),\n loadForms: (astro, opts) => getClient(astro).listForms(opts),\n };\n}\n\n/**\n * Build the live SSE URL for `<BcmsLive>`. The key is a query param because\n * browser EventSource cannot send headers — use a content:read key.\n *\n * `depth` sets the hydration depth of the document the stream pushes (default 1,\n * matching the delivery API). `drafts` streams autosaves so a preview surface\n * repaints as the editor types — it needs a `content:read:draft` key, and the\n * server ignores the flag for any other key rather than failing the connection.\n * Never enable it on a public site.\n */\nexport function liveSrc(opts: {\n apiUrl: string;\n workspace: string;\n apiKey: string;\n depth?: 0 | 1 | 2;\n drafts?: boolean;\n}): string {\n const base = opts.apiUrl.replace(/\\/+$/, \"\");\n const q = new URLSearchParams({ key: opts.apiKey });\n if (opts.depth !== undefined) q.set(\"depth\", String(opts.depth));\n if (opts.drafts) q.set(\"drafts\", \"1\");\n return `${base}/api/v1/delivery/${opts.workspace}/live?${q}`;\n}\n\n/**\n * The published content snapshot, read at request time on a server BetterCMS hosts (it rewrites the\n * file on every publish) and from `bcms-content.json` at build time. Read content through this —\n * never `import` bcms-content.json or `import.meta.glob` it: a bundled copy is frozen at build, and\n * the platform has to rebuild the whole site for every publish to change it.\n */\nexport { readPublishedContent, publishedEntry, type PublishedContent } from \"@bettercms-ai/sdk\";\n\n// ── Signed-cookie helpers (HMAC-SHA256, base64url) ──────────────────────────\n\nconst enc = new TextEncoder();\n\nfunction base64url(bytes: ArrayBuffer): string {\n const b = btoa(String.fromCharCode(...new Uint8Array(bytes)));\n return b.replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\n\nasync function hmac(value: string, secret: string): Promise<string> {\n const key = await crypto.subtle.importKey(\n \"raw\",\n enc.encode(secret),\n { name: \"HMAC\", hash: \"SHA-256\" },\n false,\n [\"sign\"],\n );\n return base64url(await crypto.subtle.sign(\"HMAC\", key, enc.encode(value)));\n}\n\n/** Sign a value as `value.sig` for tamper-evident cookie storage. */\nexport async function signValue(value: string, secret: string): Promise<string> {\n return `${value}.${await hmac(value, secret)}`;\n}\n\n/** Verify a signed value, returning the original value or null if tampered. */\nexport async function verifyValue(signed: string, secret: string): Promise<string | null> {\n const idx = signed.lastIndexOf(\".\");\n if (idx < 0) return null;\n const value = signed.slice(0, idx);\n const sig = signed.slice(idx + 1);\n const expected = await hmac(value, secret);\n // Constant-time-ish compare via length + char accumulation.\n if (sig.length !== expected.length) return null;\n let diff = 0;\n for (let i = 0; i < sig.length; i++) diff |= sig.charCodeAt(i) ^ expected.charCodeAt(i);\n return diff === 0 ? value : null;\n}\n\n/**\n * The draft-cookie signing secret, `process.env` FIRST.\n *\n * Vite may INLINE `import.meta.env.BCMS_DRAFT_SECRET` at build time, and the value present\n * when the customer's site is built is not the value the hosting container is given at start\n * — BetterCMS derives it per project and injects it as a real env var. Reading the runtime\n * env first is what makes managed hosting work without asking anyone to rebuild. The\n * `import.meta.env` read stays as the fallback for `astro dev` and for adapters with no\n * `process` (guarded, since touching `import.meta.env` outside Vite throws).\n */\nexport function draftSecret(): string | undefined {\n const fromProcess =\n typeof process !== \"undefined\" ? (process.env?.BCMS_DRAFT_SECRET as string | undefined) : undefined;\n if (fromProcess) return fromProcess;\n try {\n return import.meta.env?.BCMS_DRAFT_SECRET as string | undefined;\n } catch {\n return undefined;\n }\n}\n\n/** Only same-origin relative paths. Blocks \"//evil.com\", \"https://evil.com\", etc. */\nexport function safeRedirectPath(to: string): string {\n return to.startsWith(\"/\") && !to.startsWith(\"//\") ? to : \"/\";\n}\n\n/** Decode a preview-token JWT payload (UNVERIFIED) to read its `entrySlug`. */\nexport function decodeTokenSlug(token: string): string | null {\n try {\n const part = token.split(\".\")[1];\n if (!part) return null;\n const json = JSON.parse(\n atob(part.replace(/-/g, \"+\").replace(/_/g, \"/\")),\n ) as { entrySlug?: string };\n return json.entrySlug ?? null;\n } catch {\n return null;\n }\n}\n","/**\n * C3/C4 — `sectionRootAttrs(block)`: the attributes a site's OWN section root spreads so the\n * BetterCMS editor offers that section's spacing and style handles.\n *\n * <section class=\"hero\" {...sectionRootAttrs(block)}>…</section>\n *\n * The editor shows those handles on a site-rendered page only when EVERY root the site stamps\n * with `data-bcms-block` also carries `data-bcms-style`, which is the site's promise that \"this\n * root's inline style is `blockStyleToCss(block.style)`\" — the same declarations `<BcmsBlocks>`\n * puts on its own wrapper. A root that stamps the block without applying its style would get a\n * capsule that paints the canvas and never ships, so the marker must travel with the style.\n *\n * The marker is present even when the style is EMPTY (then there is no `style` attribute at all):\n * an unstyled section is exactly the one an author is about to give its first spacing edit.\n */\nimport { blockStyleToColumnCss, blockStyleToCss, hideOnAttr, type BlockStyle } from \"@bettercms-ai/types\";\n\nexport interface SectionRootBlock {\n id?: string | null;\n style?: BlockStyle | Record<string, unknown> | null;\n}\n\nexport interface SectionRootAttrs {\n \"data-bcms-block\"?: string;\n \"data-bcms-style\": \"\";\n /** `\"mobile tablet\"` when `style.hideOn` hides it there; the site ships `RESPONSIVE_CSS` for it. */\n \"data-bcms-hide\"?: string;\n /** `blockStyleToCss(block.style)` as a CSS string; absent when the block has no style. */\n style?: string;\n}\n\n/** `paddingTop` → `padding-top`, joined the way `<BcmsBlocks>` writes its wrapper's attribute. */\nfunction cssText(css: Record<string, string | number>): string {\n return Object.entries(css)\n .map(([k, v]) => `${k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`)}:${v}`)\n .join(\";\");\n}\n\nexport function sectionRootAttrs(block: SectionRootBlock | null | undefined): SectionRootAttrs {\n const css = blockStyleToCss((block?.style ?? undefined) as BlockStyle | undefined);\n const id = typeof block?.id === \"string\" && block.id !== \"\" ? block.id : undefined;\n const hide = hideOnAttr(block?.style);\n return {\n ...(id !== undefined ? { \"data-bcms-block\": id } : {}),\n \"data-bcms-style\": \"\",\n ...(hide ? { \"data-bcms-hide\": hide } : {}),\n ...(css ? { style: cssText(css) } : {}),\n };\n}\n\nexport interface SectionColumnAttrs {\n \"data-bcms-column\": \"\";\n /** `blockStyleToColumnCss(block.style)` as a CSS string; absent when the section has no column. */\n style?: string;\n}\n\n/**\n * C3 — `sectionColumnAttrs(block)`: the attributes a site's own INNER container spreads so the\n * section's content WIDTH (`style.contentWidth`, placed by `contentAlign`) ships.\n *\n * <section {...sectionRootAttrs(block)}>\n * <div class=\"container\" {...sectionColumnAttrs(block)}>…</div>\n * </section>\n *\n * The width is the column BetterCMS draws as `.bcms-block-inner` inside the section's styled box —\n * never on the root itself, whose background must stay full-bleed. `data-bcms-column` is the\n * site's promise that this box's inline style is the column; the editor offers the width handle\n * on a site-rendered page only where every styled root holds one. Max-width plus left/right\n * margins, so the container keeps its own vertical margins and, with no column, its own width.\n */\nexport function sectionColumnAttrs(block: SectionRootBlock | null | undefined): SectionColumnAttrs {\n const css = blockStyleToColumnCss((block?.style ?? undefined) as Bl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IAAI,QAAQ,WAAW,EAAE,CAAC,IAAI,KAAK;AAC1E,UAAM,GAAG,IAAI,MAAM,GAAG,IAAI,KAAK,CAAC,WAAW,WAAW,MAAM,CAAC,IAAI,IAAI,MAAM,IAAI,QAAQ,IAAI,CAAC,EAAE,MAAM,CAAC;AACrG,YAAQ;AAAA,EACV;AACA,QAAM,QAAQ,OAAO,QAAQ,EAAE,GAAG,OAAO,OAAO,CAAC,aAAa,GAAG,KAAK,CAAC,EACpE,OAAO,CAAC,UAAqC,MAAM,CAAC,MAAM,MAAS,EACnE,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,IAAI,IAAI,KAAK,WAAW,KAAK,CAAC,GAAG,EACxD,KAAK,EAAE;AACV,SAAO,KAAK,MAAM,GAAG,KAAK,IAAI,MAAM,SAAS,aAAa,OAAO,MAAM,KAAK,MAAM,GAAG;AACvF;","names":["readPublishedContent","end","readPublishedContent"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bettercms-ai/astro",
3
- "version": "0.25.0",
3
+ "version": "0.27.0",
4
4
  "type": "module",
5
5
  "description": "The BetterCMS adapter for Astro — a `bettercms()` integration, a `bettercms:client` virtual module, typed content loaders, draft preview, and native .astro rendering components.",
6
6
  "main": "./dist/index.js",
@@ -28,9 +28,15 @@
28
28
  "import": "./dist/middleware-entry.js",
29
29
  "default": "./dist/middleware-entry.js"
30
30
  },
31
+ "./public-config": {
32
+ "types": "./dist/public-config.d.ts",
33
+ "import": "./dist/public-config.js",
34
+ "default": "./dist/public-config.js"
35
+ },
31
36
  "./draft-enable": "./dist/routes/draft-enable.js",
32
37
  "./draft-disable": "./dist/routes/draft-disable.js",
33
38
  "./components/BcmsBlocks.astro": "./components/BcmsBlocks.astro",
39
+ "./components/BcmsSections.astro": "./components/BcmsSections.astro",
34
40
  "./components/BcmsLiveBlocks.astro": "./components/BcmsLiveBlocks.astro",
35
41
  "./components/BcmsField.astro": "./components/BcmsField.astro",
36
42
  "./components/BcmsButton.astro": "./components/BcmsButton.astro",
@@ -55,11 +61,11 @@
55
61
  },
56
62
  "dependencies": {
57
63
  "@bettercms-ai/image-url": "^0.4.0",
58
- "@bettercms-ai/next": "^0.24.0",
59
- "@bettercms-ai/richtext": "^0.8.1",
64
+ "@bettercms-ai/next": "^0.26.0",
65
+ "@bettercms-ai/richtext": "^0.8.2",
60
66
  "@bettercms-ai/sdk": "^1.29.0",
61
- "@bettercms-ai/types": "^1.41.0",
62
- "@bettercms-ai/ui": "^0.15.1",
67
+ "@bettercms-ai/types": "^1.43.0",
68
+ "@bettercms-ai/ui": "^0.16.0",
63
69
  "libphonenumber-js": "^1.13.13"
64
70
  },
65
71
  "peerDependencies": {