@bettercms-ai/next 0.34.0 → 0.36.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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/field.tsx","../src/image.tsx","../src/button.tsx"],"sourcesContent":["/**\n * <BcmsField> — tag an entry field's rendered value with its identity so the\n * BetterCMS visual editor can bind click-to-edit deterministically (mirrors\n * Sanity's `data-sanity` / BaseHub's `data-basehub`). Entry-backed templates\n * hand-render field values (`f.title`, `f.body.html`), so the field `path` is\n * declared here by the author — the delivery payload carries no source-map.\n *\n * Server-safe (no hooks): renders in a Next Server Component. When the child is ONE\n * DOM element (`<h1>`, `<p>`), the attributes go on that element and nothing is added to\n * the page: `.hero > h1` and every animation target stay what the author wrote. Text,\n * several children, or a component (which may not pass unknown props on) are wrapped in a\n * `display:contents` span as before; pass `as` to carry the attributes on a real wrapper.\n * Twin: BcmsField.astro in @bettercms-ai/astro.\n *\n * `path` follows the editor grammar: `title` · `hero.title` · `columns[0].links[2].href`\n * (dotted keys and any number of `[n]` indices). For images, put the attributes on the\n * `<img>` itself (`kind=\"image\"` reflection patches `.src`), not on a wrapper:\n * <img src={imageValueUrl(f.cover, { w: 1200 })} data-bcms-field=\"cover\" data-bcms-kind=\"image\" />\n * `imageValueUrl` (re-exported from this package) applies the value's per-placement `crop` and\n * `focal`; `.url` alone would drop them. For a cover-fit box add\n * `style={{ objectPosition: imageValueObjectPosition(f.cover) ?? undefined }}`.\n */\nimport { Children, cloneElement, isValidElement, type ElementType, type ReactElement, type ReactNode } from \"react\";\n\nexport interface BcmsFieldProps {\n /** Field path in the editor grammar, e.g. `title` or `facts[2].label`. */\n path: string;\n /** Kind hint the editor's reflection branches on. Omit for plain text/number. */\n kind?: \"richtext\" | \"image\";\n /** Wrapper element. Without it: no wrapper around a single DOM element, a `display:contents` span around anything else. */\n as?: ElementType;\n children: ReactNode;\n}\n\nexport function BcmsField({ path, kind, as, children }: BcmsFieldProps) {\n const Tag = as ?? \"span\";\n const only = as ? [] : Children.toArray(children);\n const sole = only.length === 1 && isValidElement(only[0]) && typeof only[0].type === \"string\" ? (only[0] as ReactElement<Record<string, unknown>>) : null;\n // An element that already declares a field keeps its own address: wrapped, as before.\n if (sole && sole.props[\"data-bcms-field\"] === undefined && sole.props[\"data-bcms-layout-field\"] === undefined) {\n return cloneElement(sole, { \"data-bcms-field\": path, \"data-bcms-kind\": kind });\n }\n return (\n <Tag\n data-bcms-field={path}\n data-bcms-kind={kind}\n style={as ? undefined : { display: \"contents\" }}\n >\n {children}\n </Tag>\n );\n}\n","/**\n * <BcmsImage> — render an image field as one responsive `<img>` on the BetterCMS media transform\n * endpoint, declared so the visual editor binds it and a publish writes the new picture into it.\n * The same markup as the Astro SDK's <BcmsImage>.\n *\n * <BcmsImage path=\"hero.image\" src={page.hero.image} sizes=\"(min-width: 800px) 50vw, 100vw\" />\n *\n * `src` is an image VALUE (`{ url, altText, width?, focal?, crop? }`), a media url or an asset id.\n * The value's per-placement crop and focal point ride every url, and the focal point is also the\n * `object-position` (inert without `object-fit`). With `sizes` and no `width` the srcset is a WIDTH\n * ladder, never wider than the picture; with a pixel `width` it is 1x/2x. The value's `altText` is\n * the alt unless `alt` says otherwise. Any other prop reaches the `<img>` as written.\n *\n * A plain `<img>`, deliberately: `next/image` refuses a remote host the app has not allow-listed,\n * so an editor's replacement would break the build. Server-safe (no hooks).\n */\nimport imageUrlBuilder, {\n focalInCrop,\n normalizeImageCrop,\n normalizeImageFocal,\n objectPosition,\n type ImageFit,\n type ImageFormat,\n type ImageSource,\n} from \"@bettercms-ai/image-url\";\nimport type { CSSProperties, ImgHTMLAttributes } from \"react\";\n\n/** What delivery adds to an image value beside its url: the facts this component reads. */\ntype ImageFacts = { altText?: string | null; alt?: string | null; width?: number | null; height?: number | null; focalX?: number | null; focalY?: number | null };\n\nexport interface BcmsImageProps extends Omit<ImgHTMLAttributes<HTMLImageElement>, \"src\" | \"srcSet\" | \"width\" | \"height\"> {\n src: ImageSource | (Exclude<ImageSource, string> & ImageFacts);\n /** The field this image renders, in the editor grammar (`cover`, `hero.image`). */\n path?: string;\n width?: number;\n height?: number;\n format?: ImageFormat;\n quality?: number;\n fit?: ImageFit;\n /** Focal point override, 0–1. Normally omitted: the value and the asset carry their own. */\n focalX?: number | null;\n focalY?: number | null;\n /** Media host for a `src` that is only an asset id. Defaults to the platform's. */\n baseUrl?: string;\n}\n\n/** The widths a `sizes` image offers: phone to desktop, and never an upscale of the picture. */\nconst LADDER = [480, 768, 1080, 1440, 1920];\n\nconst num = (v: unknown): number | undefined => (typeof v === \"number\" && Number.isFinite(v) ? v : undefined);\n\nexport function BcmsImage({\n src,\n path,\n alt,\n width,\n height,\n format = \"webp\",\n quality,\n fit,\n sizes,\n loading = \"lazy\",\n focalX,\n focalY,\n baseUrl,\n style,\n ...rest\n}: BcmsImageProps) {\n // An explicit prop wins; then the value's own `focal`; then the asset's focalX/focalY. The last\n // two are SOURCE-relative, so with a crop they are re-expressed inside it.\n const asset = (typeof src === \"object\" && src !== null ? src : {}) as Record<string, unknown>;\n const explicit = focalX != null || focalY != null;\n const stored =\n normalizeImageFocal(asset.focal) ??\n (num(asset.focalX) != null || num(asset.focalY) != null ? { x: num(asset.focalX) ?? 0.5, y: num(asset.focalY) ?? 0.5 } : null);\n const inWindow = stored ? focalInCrop(stored, normalizeImageCrop(asset.crop)) : null;\n const fx = explicit ? focalX : inWindow?.x;\n const fy = explicit ? focalY : inWindow?.y;\n const hasFocal = fx != null || fy != null;\n\n const builder = imageUrlBuilder({ baseUrl });\n const make = () => {\n let b = builder(src);\n if (width) b = b.width(width);\n if (height) b = b.height(height);\n if (format) b = b.format(format);\n if (quality) b = b.quality(quality);\n if (fit) b = b.fit(fit);\n if (hasFocal) b = b.focal(fx ?? 0.5, fy ?? 0.5);\n return b;\n };\n const src1x = make().url();\n const own = num(asset.width);\n const ladder = own ? [...new Set([...LADDER.filter((w) => w < own), Math.min(own, LADDER[LADDER.length - 1]!)])] : LADDER;\n const srcSet =\n sizes && !width ? ladder.map((w) => `${make().width(w).url()} ${w}w`).join(\", \") : `${src1x} 1x, ${make().dpr(2).url()} 2x`;\n // A pixel width is the author's size for THIS image, so it also goes on as a style (a site rule\n // like `img { width: 100% }` beats a bare attribute), capped at the column it sits in.\n const merged: CSSProperties = {\n ...(width ? { width: `${width}px`, maxWidth: \"100%\", height: \"auto\" } : {}),\n ...(hasFocal ? { objectPosition: objectPosition({ x: fx, y: fy }) } : {}),\n ...style,\n };\n\n return (\n <img\n src={src1x}\n srcSet={srcSet}\n alt={alt ?? (typeof asset.altText === \"string\" ? asset.altText : typeof asset.alt === \"string\" ? asset.alt : \"\")}\n data-bcms-field={path}\n data-bcms-kind={path ? \"image\" : undefined}\n width={width}\n height={height}\n sizes={sizes}\n loading={loading}\n style={Object.keys(merged).length > 0 ? merged : undefined}\n {...rest}\n />\n );\n}\n","/**\n * <BcmsButton> — render a `button` field ({ label, href, variant?, size?, arrow?, icon?,\n * newTab?, fullWidth? }) as one editable button, with the hooks the BetterCMS visual editor repaints and\n * in-place publishing writes. The same markup as the Astro SDK's <BcmsButton>:\n *\n * <a data-bcms-button=\"<path>\" data-variant data-size [data-full-width] href [target rel] data-bcms-props=\"<path>.href|url|href\">\n * [<svg class=\"bcms-btn-icon\">]<span data-bcms-field=\"<path>.label\">Label</span>[<svg class=\"bcms-btn-arrow\">]\n * </a>\n *\n * A value with `action: \"code\"` (no href: the site's script handles the click) renders the same\n * children in `<button type=\"button\" data-bcms-button=\"<path>\" data-variant data-size>`.\n *\n * Style it by `data-variant` and `data-size` in your own CSS. A full-width button also carries\n * `display:flex;width:100%;justify-content:center` inline, so it stretches with no rule of yours.\n * Server-safe (no hooks).\n *\n * <BcmsButton path=\"hero.cta\" value={page.hero.cta} className=\"btn\" />\n */\nimport { formatPropsAttribute, readButtonValue } from \"@bettercms-ai/types\";\nimport { Icon } from \"@bettercms-ai/icons/map\";\n\n/** A full-width button stretches across its column, label centred: the hosted renderer's `bcms-btn-full`. */\nconst FULL_WIDTH_STYLE = { display: \"flex\", width: \"100%\", justifyContent: \"center\" } as const;\n\nexport interface BcmsButtonProps {\n /** The field path in the editor grammar, e.g. `cta` or `hero.cta`. */\n path: string;\n /** The stored value. Missing keys render as the defaults (Primary, medium, no arrow, no icon). */\n value: unknown;\n className?: string;\n}\n\nexport function BcmsButton({ path, value, className }: BcmsButtonProps) {\n const b = readButtonValue(value);\n if (!b.label) return null;\n const content = (\n <>\n {/* Direct children of the root, as the editor and in-place publishing find them. */}\n {b.icon && <Icon symbol={b.icon} className=\"bcms-btn-icon\" aria-hidden focusable=\"false\" />}\n <span data-bcms-field={`${path}.label`} data-bcms-kind=\"text\">\n {b.label}\n </span>\n {b.arrow && <Icon symbol=\"arrow-right\" className=\"bcms-btn-arrow\" aria-hidden focusable=\"false\" />}\n </>\n );\n // `action: \"code\"`: your own handler owns the click (delegate on `[data-bcms-button]`), so no href.\n if (b.action === \"code\") {\n return (\n <button type=\"button\" className={className} data-bcms-button={path} data-variant={b.variant} data-size={b.size} {...(b.fullWidth ? { \"data-full-width\": \"\", style: FULL_WIDTH_STYLE } : {})}>\n {content}\n </button>\n );\n }\n return (\n <a\n className={className}\n href={b.href || \"#\"}\n data-bcms-button={path}\n data-variant={b.variant}\n data-size={b.size}\n {...(b.fullWidth ? { \"data-full-width\": \"\", style: FULL_WIDTH_STYLE } : {})}\n data-bcms-props={formatPropsAttribute([{ address: `${path}.href`, kind: \"url\", attr: \"href\" }])}\n {...(b.newTab ? { target: \"_blank\", rel: \"noopener noreferrer\" } : {})}\n >\n {content}\n </a>\n );\n}\n"],"mappings":";AAsBA,SAAS,UAAU,cAAc,sBAA2E;AAqBxG;AATG,SAAS,UAAU,EAAE,MAAM,MAAM,IAAI,SAAS,GAAmB;AACtE,QAAM,MAAM,MAAM;AAClB,QAAM,OAAO,KAAK,CAAC,IAAI,SAAS,QAAQ,QAAQ;AAChD,QAAM,OAAO,KAAK,WAAW,KAAK,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AAA,MAClB,gBAAc,EAAE;AAAA,MAChB,aAAW,EAAE;AAAA,MACZ,GAAI,EAAE,YAAY,EAAE,mBAAmB,IAAI,OAAO,iBAAiB,IAAI,CAAC;AAAA,MACzE,mBAAiB,qBAAqB,CAAC,EAAE,SAAS,GAAG,IAAI,SAAS,MAAM,OAAO,MAAM,OAAO,CAAC,CAAC;AAAA,MAC7F,GAAI,EAAE,SAAS,EAAE,QAAQ,UAAU,KAAK,sBAAsB,IAAI,CAAC;AAAA,MAEnE;AAAA;AAAA,EACH;AAEJ;","names":["jsx","jsx"]}
1
+ {"version":3,"sources":["../src/field.tsx","../src/image.tsx","../src/button.tsx","../src/field-attrs.ts","../src/section-root.ts"],"sourcesContent":["/**\n * <BcmsField> — tag an entry field's rendered value with its identity so the\n * BetterCMS visual editor can bind click-to-edit deterministically (mirrors\n * Sanity's `data-sanity` / BaseHub's `data-basehub`). Entry-backed templates\n * hand-render field values (`f.title`, `f.body.html`), so the field `path` is\n * declared here by the author — the delivery payload carries no source-map.\n *\n * Server-safe (no hooks): renders in a Next Server Component. When the child is ONE\n * DOM element (`<h1>`, `<p>`), the attributes go on that element and nothing is added to\n * the page: `.hero > h1` and every animation target stay what the author wrote. Text,\n * several children, or a component (which may not pass unknown props on) are wrapped in a\n * `display:contents` span as before; pass `as` to carry the attributes on a real wrapper.\n * Twin: BcmsField.astro in @bettercms-ai/astro.\n *\n * `path` follows the editor grammar: `title` · `hero.title` · `columns[0].links[2].href`\n * (dotted keys and any number of `[n]` indices). For images, put the attributes on the\n * `<img>` itself (`kind=\"image\"` reflection patches `.src`), not on a wrapper:\n * <img src={imageValueUrl(f.cover, { w: 1200 })} data-bcms-field=\"cover\" data-bcms-kind=\"image\" />\n * `imageValueUrl` (re-exported from this package) applies the value's per-placement `crop` and\n * `focal`; `.url` alone would drop them. For a cover-fit box add\n * `style={{ objectPosition: imageValueObjectPosition(f.cover) ?? undefined }}`.\n */\nimport { Children, cloneElement, isValidElement, type ElementType, type ReactElement, type ReactNode } from \"react\";\n\nexport interface BcmsFieldProps {\n /** Field path in the editor grammar, e.g. `title` or `facts[2].label`. */\n path: string;\n /** Kind hint the editor's reflection branches on. Omit for plain text/number. */\n kind?: \"richtext\" | \"image\";\n /** Wrapper element. Without it: no wrapper around a single DOM element, a `display:contents` span around anything else. */\n as?: ElementType;\n children: ReactNode;\n}\n\nexport function BcmsField({ path, kind, as, children }: BcmsFieldProps) {\n const Tag = as ?? \"span\";\n const only = as ? [] : Children.toArray(children);\n const sole = only.length === 1 && isValidElement(only[0]) && typeof only[0].type === \"string\" ? (only[0] as ReactElement<Record<string, unknown>>) : null;\n // An element that already declares a field keeps its own address: wrapped, as before.\n if (sole && sole.props[\"data-bcms-field\"] === undefined && sole.props[\"data-bcms-layout-field\"] === undefined) {\n return cloneElement(sole, { \"data-bcms-field\": path, \"data-bcms-kind\": kind });\n }\n return (\n <Tag\n data-bcms-field={path}\n data-bcms-kind={kind}\n style={as ? undefined : { display: \"contents\" }}\n >\n {children}\n </Tag>\n );\n}\n","/**\n * <BcmsImage> — render an image field as one responsive `<img>` on the BetterCMS media transform\n * endpoint, declared so the visual editor binds it and a publish writes the new picture into it.\n * The same markup as the Astro SDK's <BcmsImage>.\n *\n * <BcmsImage path=\"hero.image\" src={page.hero.image} sizes=\"(min-width: 800px) 50vw, 100vw\" />\n *\n * `src` is an image VALUE (`{ url, altText, width?, focal?, crop? }`), a media url or an asset id.\n * The value's per-placement crop and focal point ride every url, and the focal point is also the\n * `object-position` (inert without `object-fit`). With `sizes` and no `width` the srcset is a WIDTH\n * ladder, never wider than the picture; with a pixel `width` it is 1x/2x. The value's `altText` is\n * the alt unless `alt` says otherwise. Any other prop reaches the `<img>` as written.\n *\n * A plain `<img>`, deliberately: `next/image` refuses a remote host the app has not allow-listed,\n * so an editor's replacement would break the build. Server-safe (no hooks).\n */\nimport type { ImageFit, ImageFormat, ImageSource } from \"@bettercms-ai/image-url\";\nimport { imageCore } from \"@bettercms-ai/sdk/bindings\";\nimport type { CSSProperties, ImgHTMLAttributes } from \"react\";\n\n/** What delivery adds to an image value beside its url: the facts this component reads. */\ntype ImageFacts = { altText?: string | null; alt?: string | null; width?: number | null; height?: number | null; focalX?: number | null; focalY?: number | null };\n\nexport interface BcmsImageProps extends Omit<ImgHTMLAttributes<HTMLImageElement>, \"src\" | \"srcSet\" | \"width\" | \"height\"> {\n src: ImageSource | (Exclude<ImageSource, string> & ImageFacts);\n /** The field this image renders, in the editor grammar (`cover`, `hero.image`). */\n path?: string;\n width?: number;\n height?: number;\n format?: ImageFormat;\n quality?: number;\n fit?: ImageFit;\n /** Focal point override, 0–1. Normally omitted: the value and the asset carry their own. */\n focalX?: number | null;\n focalY?: number | null;\n /** Media host for a `src` that is only an asset id. Defaults to the platform's. */\n baseUrl?: string;\n}\n\n/** The widths a `sizes` image offers: phone to desktop, and never an upscale of the picture. */\nexport function BcmsImage({\n src,\n path,\n alt,\n width,\n height,\n format = \"webp\",\n quality,\n fit,\n sizes,\n loading = \"lazy\",\n focalX,\n focalY,\n baseUrl,\n style,\n ...rest\n}: BcmsImageProps) {\n const { src: src1x, srcset: srcSet, alt: resolvedAlt, css } = imageCore(src, { alt, width, height, format, quality, fit, sizes, focalX, focalY, baseUrl });\n const merged: CSSProperties = { ...css, ...style };\n\n return (\n <img\n src={src1x}\n srcSet={srcSet}\n alt={resolvedAlt}\n data-bcms-field={path}\n data-bcms-kind={path ? \"image\" : undefined}\n width={width}\n height={height}\n sizes={sizes}\n loading={loading}\n style={Object.keys(merged).length > 0 ? merged : undefined}\n {...rest}\n />\n );\n}\n","/**\n * <BcmsButton> — render a `button` field ({ label, href, variant?, size?, arrow?, icon?,\n * newTab?, fullWidth? }) as one editable button, with the hooks the BetterCMS visual editor repaints and\n * in-place publishing writes. The same markup as the Astro SDK's <BcmsButton>:\n *\n * <a data-bcms-button=\"<path>\" data-variant data-size [data-full-width] href [target rel] data-bcms-props=\"<path>.href|url|href\">\n * [<svg class=\"bcms-btn-icon\">]<span data-bcms-field=\"<path>.label\">Label</span>[<svg class=\"bcms-btn-arrow\">]\n * </a>\n *\n * A value with `action: \"code\"` (no href: the site's script handles the click) renders the same\n * children in `<button type=\"button\" data-bcms-button=\"<path>\" data-variant data-size>`.\n *\n * Style it by `data-variant` and `data-size` in your own CSS. A full-width button also carries\n * `display:flex;width:100%;justify-content:center` inline, so it stretches with no rule of yours.\n * Server-safe (no hooks).\n *\n * <BcmsButton path=\"hero.cta\" value={page.hero.cta} className=\"btn\" />\n */\nimport { formatPropsAttribute, readButtonValue } from \"@bettercms-ai/types\";\nimport { Icon } from \"@bettercms-ai/icons/map\";\n\n/** A full-width button stretches across its column, label centred: the hosted renderer's `bcms-btn-full`. */\nconst FULL_WIDTH_STYLE = { display: \"flex\", width: \"100%\", justifyContent: \"center\" } as const;\n\nexport interface BcmsButtonProps {\n /** The field path in the editor grammar, e.g. `cta` or `hero.cta`. */\n path: string;\n /** The stored value. Missing keys render as the defaults (Primary, medium, no arrow, no icon). */\n value: unknown;\n className?: string;\n}\n\nexport function BcmsButton({ path, value, className }: BcmsButtonProps) {\n const b = readButtonValue(value);\n if (!b.label) return null;\n const content = (\n <>\n {/* Direct children of the root, as the editor and in-place publishing find them. */}\n {b.icon && <Icon symbol={b.icon} className=\"bcms-btn-icon\" aria-hidden focusable=\"false\" />}\n <span data-bcms-field={`${path}.label`} data-bcms-kind=\"text\">\n {b.label}\n </span>\n {b.arrow && <Icon symbol=\"arrow-right\" className=\"bcms-btn-arrow\" aria-hidden focusable=\"false\" />}\n </>\n );\n // `action: \"code\"`: your own handler owns the click (delegate on `[data-bcms-button]`), so no href.\n if (b.action === \"code\") {\n return (\n <button type=\"button\" className={className} data-bcms-button={path} data-variant={b.variant} data-size={b.size} {...(b.fullWidth ? { \"data-full-width\": \"\", style: FULL_WIDTH_STYLE } : {})}>\n {content}\n </button>\n );\n }\n return (\n <a\n className={className}\n href={b.href || \"#\"}\n data-bcms-button={path}\n data-variant={b.variant}\n data-size={b.size}\n {...(b.fullWidth ? { \"data-full-width\": \"\", style: FULL_WIDTH_STYLE } : {})}\n data-bcms-props={formatPropsAttribute([{ address: `${path}.href`, kind: \"url\", attr: \"href\" }])}\n {...(b.newTab ? { target: \"_blank\", rel: \"noopener noreferrer\" } : {})}\n >\n {content}\n </a>\n );\n}\n","/**\n * C3 — `fieldAttrs(path, fieldStyles)`: the props a site's OWN element spreads to bind a PAGE FIELD\n * and apply that field's stored style, so the BetterCMS editor offers its width and spacing handles\n * and its Align / Size / Weight controls.\n *\n * const page = await client.getPage(\"home\");\n * <h1 className=\"title\" {...fieldAttrs(\"hero-title\", page?.fieldStyles)}>{entry.data[\"hero-title\"]}</h1>\n *\n * `data-bcms-style` is the site's promise that \"this element's inline style is\n * `fieldStyleToCss(fieldStyles[path])`\"; the editor offers a field's handles only where it is\n * present. Present even when the field has no style (then there is no `style` prop at all).\n * Twin: `fieldAttrs` in @bettercms-ai/astro (a CSS string there).\n */\nimport type { CSSProperties } from \"react\";\nimport { fieldStyleToCss, type FieldStyle, type FieldStyles } from \"@bettercms-ai/types\";\n\nexport interface FieldAttrs {\n \"data-bcms-field\": string;\n /** The marker's revision: \"2\" promises `size` (zoom) too. Section roots keep \"\". */\n \"data-bcms-style\": \"2\";\n /** `fieldStyleToCss(fieldStyles[path])`; absent when the field has no style. */\n style?: CSSProperties;\n}\n\n/** The stored style for `path`, by OWN key only — a path like `constructor` never reads the prototype. */\nexport function fieldStyleOf(path: string, fieldStyles: FieldStyles | Record<string, unknown> | null | undefined): FieldStyle | undefined {\n if (!fieldStyles || typeof fieldStyles !== \"object\" || !Object.prototype.hasOwnProperty.call(fieldStyles, path)) return undefined;\n const style = (fieldStyles as Record<string, unknown>)[path];\n return style && typeof style === \"object\" ? (style as FieldStyle) : undefined;\n}\n\nexport function fieldAttrs(path: string, fieldStyles?: FieldStyles | Record<string, unknown> | null): FieldAttrs {\n const css = fieldStyleToCss(fieldStyleOf(path, fieldStyles));\n return { \"data-bcms-field\": path, \"data-bcms-style\": \"2\", ...(css ? { style: css as CSSProperties } : {}) };\n}\n\n/**\n * P7 — `entryAttrs(entry)` and `entryField(entry, path)`: the attributes a site's OWN card spreads to\n * declare a collection ENTRY, so the editor binds it without guessing from the rendered text.\n *\n * <article {...entryAttrs(post)}><h3 {...entryField(post, \"title\")}>{post.fields.title}</h3></article>\n *\n * The field address is ABSOLUTE (`entry:<id>:<path>`). With a `transform` the value is shown\n * changed (a date formatted, text truncated), so it is declared as `data-bcms-entry-from`: the\n * editor knows where it is but cannot re-render it. Twin: same helpers in @bettercms-ai/astro.\n */\nexport type EntryRef = { id?: string } | string;\nexport type EntryTransform = \"format\" | \"truncate\" | \"rendition\" | \"route\";\n/** One key is present: `data-bcms-entry-field`, or `data-bcms-entry-from` when transformed; none without an id. */\nexport interface EntryFieldAttrs {\n \"data-bcms-entry-field\"?: string;\n \"data-bcms-entry-from\"?: string;\n}\n\nfunction entryIdOf(entry: EntryRef): string | null {\n const id = typeof entry === \"string\" ? entry : entry?.id;\n return typeof id === \"string\" && id.trim() !== \"\" ? id : null;\n}\n\n/** An entry with no id (a snapshot written before ids were kept) renders unbound, never fails the build. */\nexport function entryAttrs(entry: EntryRef): { \"data-bcms-entry\"?: string } {\n const id = entryIdOf(entry);\n return id ? { \"data-bcms-entry\": id } : {};\n}\n\nexport function entryField(entry: EntryRef, path: string, opts?: { transform?: EntryTransform }): EntryFieldAttrs {\n const id = entryIdOf(entry);\n if (typeof path !== \"string\" || path.trim() === \"\") throw new Error(`entryField: no field path given for entry ${id ?? \"(no id)\"}`);\n if (!id) return {};\n const address = `entry:${id}:${path}`;\n return opts?.transform ? { \"data-bcms-entry-from\": `${address}|${opts.transform}` } : { \"data-bcms-entry-field\": address };\n}\n","/**\n * C3/C4 — `sectionRootAttrs(block)`: the props a site's OWN section root spreads so the\n * BetterCMS editor offers that section's spacing and style handles.\n *\n * <section className=\"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. The marker is present even when the style is EMPTY (then there is no\n * `style` prop at all): an unstyled section is the one an author is about to give its first\n * spacing edit. Twin: `sectionRootAttrs` in @bettercms-ai/astro (style as a string there).\n */\nimport type { CSSProperties } from \"react\";\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)`; absent when the block has no style. */\n style?: CSSProperties;\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: css as CSSProperties } : {}),\n };\n}\n\nexport interface SectionColumnAttrs {\n \"data-bcms-column\": \"\";\n /** `blockStyleToColumnCss(block.style)`; absent when the section has no column. */\n style?: CSSProperties;\n}\n\n/**\n * C3 — `sectionColumnAttrs(block)`: the props a site's own INNER container spreads so the section's\n * content WIDTH ships (`style.contentWidth`, placed by `contentAlign`). The column BetterCMS draws as\n * `.bcms-block-inner`, never on the root (its background stays full-bleed); `data-bcms-column` is the\n * site's promise that this box's inline style is that column. Twin: @bettercms-ai/astro.\n */\nexport function sectionColumnAttrs(block: SectionRootBlock | null | undefined): SectionColumnAttrs {\n const css = blockStyleToColumnCss((block?.style ?? undefined) as BlockStyle | undefined);\n return { \"data-bcms-column\": \"\", ...(css ? { style: css as CSSProperties } : {}) };\n}\n"],"mappings":";AAsBA,SAAS,UAAU,cAAc,sBAA2E;AAqBxG;AATG,SAAS,UAAU,EAAE,MAAM,MAAM,IAAI,SAAS,GAAmB;AACtE,QAAM,MAAM,MAAM;AAClB,QAAM,OAAO,KAAK,CAAC,IAAI,SAAS,QAAQ,QAAQ;AAChD,QAAM,OAAO,KAAK,WAAW,KAAK,eAAe,KAAK,CAAC,CAAC,KAAK,OAAO,KAAK,CAAC,EAAE,SAAS,WAAY,KAAK,CAAC,IAA8C;AAErJ,MAAI,QAAQ,KAAK,MAAM,iBAAiB,MAAM,UAAa,KAAK,MAAM,wBAAwB,MAAM,QAAW;AAC7G,WAAO,aAAa,MAAM,EAAE,mBAAmB,MAAM,kBAAkB,KAAK,CAAC;AAAA,EAC/E;AACA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,mBAAiB;AAAA,MACjB,kBAAgB;AAAA,MAChB,OAAO,KAAK,SAAY,EAAE,SAAS,WAAW;AAAA,MAE7C;AAAA;AAAA,EACH;AAEJ;;;AClCA,SAAS,iBAAiB;AA4CtB,gBAAAA,YAAA;AArBG,SAAS,UAAU;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAmB;AACjB,QAAM,EAAE,KAAK,OAAO,QAAQ,QAAQ,KAAK,aAAa,IAAI,IAAI,UAAU,KAAK,EAAE,KAAK,OAAO,QAAQ,QAAQ,SAAS,KAAK,OAAO,QAAQ,QAAQ,QAAQ,CAAC;AACzJ,QAAM,SAAwB,EAAE,GAAG,KAAK,GAAG,MAAM;AAEjD,SACE,gBAAAA;AAAA,IAAC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AAG,OAAO,IAAI,KAAK,SAAS,GAAG,IAAI,EAAE,yBAAyB,QAAQ;AAC3H;;;ACzDA,SAAS,uBAAuB,iBAAiB,kBAAmC;AAgB7E,SAAS,iBAAiB,OAA8D;AAC7F,QAAM,MAAM,gBAAiB,OAAO,SAAS,MAAoC;AACjF,QAAM,KAAK,OAAO,OAAO,OAAO,YAAY,MAAM,OAAO,KAAK,MAAM,KAAK;AACzE,QAAM,OAAO,WAAW,OAAO,KAAK;AACpC,SAAO;AAAA,IACL,GAAI,OAAO,SAAY,EAAE,mBAAmB,GAAG,IAAI,CAAC;AAAA,IACpD,mBAAmB;AAAA,IACnB,GAAI,OAAO,EAAE,kBAAkB,KAAK,IAAI,CAAC;AAAA,IACzC,GAAI,MAAM,EAAE,OAAO,IAAqB,IAAI,CAAC;AAAA,EAC/C;AACF;AAcO,SAAS,mBAAmB,OAAgE;AACjG,QAAM,MAAM,sBAAuB,OAAO,SAAS,MAAoC;AACvF,SAAO,EAAE,oBAAoB,IAAI,GAAI,MAAM,EAAE,OAAO,IAAqB,IAAI,CAAC,EAAG;AACnF;","names":["jsx","jsx"]}
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ import { ImageSource, ImageFormat, ImageFit } from '@bettercms-ai/image-url';
8
8
  export { ImageCrop, ImageFit, ImageFocal, ImageFormat, ImageSource, ImageUrlBuilder, ImageValueUrlOptions, imageUrl, default as imageUrlBuilder, imageValueObjectPosition, imageValueUrl } from '@bettercms-ai/image-url';
9
9
  import { DeliveryForm as DeliveryForm$1 } from '@bettercms-ai/sdk/read';
10
10
  import * as react_jsx_runtime from 'react/jsx-runtime';
11
+ import { BcmsChangeEvent } from '@bettercms-ai/sdk/live';
11
12
 
12
13
  /**
13
14
  * Public types for @bettercms-ai/next.
@@ -54,6 +55,11 @@ interface BetterCMSConfig {
54
55
  * `content:read:draft` `apiKey`. A branch that is not open answers 404.
55
56
  */
56
57
  branch?: string;
58
+ /**
59
+ * `signBranchRead(branch, BCMS_BRANCH_SECRET)`; `getBranchPreview()` fills both on BetterCMS
60
+ * hosting. A signed read sends no `apiKey` and is never cached.
61
+ */
62
+ branchSignature?: string;
57
63
  /** Delivery API base. Default: `https://api.bettercms.ai/api/v1/delivery`. */
58
64
  baseUrl?: string;
59
65
  /** Preview API base. Default: derived from `baseUrl` (`/delivery` → `/preview`). */
@@ -460,6 +466,20 @@ declare function getPreviewToken(): Promise<string | null>;
460
466
  * Branch reads need a `content:read:draft` key (`apiKey`).
461
467
  */
462
468
  declare function getPreviewBranch(): Promise<string | null>;
469
+ /**
470
+ * On a server BetterCMS hosts, the content branch a branch preview (`<branch>--<site>`) shows, with
471
+ * the read signed by `BCMS_BRANCH_SECRET`; null on the live site and off BetterCMS hosting (only
472
+ * hosting has that secret). No draft key needed, and none is sent with a signed read:
473
+ *
474
+ * const cms = createBetterCMS({ ...(await getBranchPreview()) });
475
+ *
476
+ * The preview vhost names the branch after checking the visitor may see it, and the live vhost
477
+ * blanks the header, so a visitor can never set it.
478
+ */
479
+ declare function getBranchPreview(): Promise<{
480
+ branch: string;
481
+ branchSignature: string;
482
+ } | null>;
463
483
  /**
464
484
  * `<BcmsDraftMarker />` — put it in the root layout. In draft mode it stamps
465
485
  * `<html data-bcms-draft="1">`, which is the ONLY thing the BetterCMS canvas trusts as proof
@@ -806,27 +826,9 @@ interface BcmsImageProps extends Omit<ImgHTMLAttributes<HTMLImageElement>, "src"
806
826
  /** Media host for a `src` that is only an asset id. Defaults to the platform's. */
807
827
  baseUrl?: string;
808
828
  }
829
+ /** The widths a `sizes` image offers: phone to desktop, and never an upscale of the picture. */
809
830
  declare function BcmsImage({ src, path, alt, width, height, format, quality, fit, sizes, loading, focalX, focalY, baseUrl, style, ...rest }: BcmsImageProps): react_jsx_runtime.JSX.Element;
810
831
 
811
- /** A `change` frame off the live stream. */
812
- interface BcmsChangeEvent<T = unknown> {
813
- type: "entry" | "page";
814
- slug: string;
815
- reason: "publish" | "unpublish" | "draft";
816
- /** Cache tags, `bcms:{ws}:all` + `bcms:{ws}:{type}:{slug}`. */
817
- tags: string[];
818
- projectId: string | null;
819
- /** When the change was committed. */
820
- at: string;
821
- /** When the server flushed this frame — `at`→`sentAt` is its own cost. */
822
- sentAt?: string;
823
- /**
824
- * The finished delivery payload. Absent on `unpublish`, and when the server
825
- * could not hydrate it (over quota, deleted, larger than the frame cap) — in
826
- * which case the client has to refetch, which is what it always used to do.
827
- */
828
- doc?: T;
829
- }
830
832
  interface BcmsLiveProps {
831
833
  /** Live SSE URL, e.g. from `defineBetterCMSLive().liveSrc`. */
832
834
  src: string;
@@ -842,10 +844,6 @@ interface BcmsLiveProps {
842
844
  onChange?: (event: BcmsChangeEvent) => void;
843
845
  }
844
846
 
845
- /**
846
- * defineBetterCMSLive — build the live SSE URL for `<BcmsLive>` from your config.
847
- * Server-safe (no React); pass the returned `liveSrc` to the client component.
848
- */
849
847
  interface BetterCMSLiveConfig {
850
848
  /** Backend base, e.g. `https://api.bettercms.ai`. */
851
849
  apiUrl: string;
@@ -889,4 +887,4 @@ interface VisualEditingProps {
889
887
  studioUrl?: string;
890
888
  }
891
889
 
892
- export { type BcmsBlocksProps, BcmsButton, type BcmsButtonProps, BcmsDraftMarker, BcmsEmbedScripts, BcmsField, type BcmsFieldProps, type BcmsFormProps, BcmsImage, type BcmsImageProps, type BcmsLiveProps, type BcmsSectionProps, type BcmsSectionsProps, type BetterCMSConfig, type BetterCMSEntry, BetterCMSError, type BetterCMSLiveConfig, type BetterCMSNext, type BetterCMSPage, type ContentSnapshot, type ContentSource, DEFAULT_SNAPSHOT_FILE, type DraftModeRouteConfig, type EntryFieldAttrs, type EntryList, type EntryRef, type EntryTransform, type FieldAttrs, type GetEntryOptions, type ListEntriesOptions, type LlmsModel, type LlmsModelField, type LlmsTxtOptions, type LlmsTxtRouteConfig, PREVIEW_TOKEN_COOKIE, type ReadOptions, type RevalidateRouteConfig, SNAPSHOT_VERSION, type SectionColumnAttrs, type SectionRootAttrs, type SectionRootBlock, type SectionRootProps, type SectionsData, type SectionsRead, type SnapshotForms, type SnapshotPage, type VisualEditingProps, buildMetadata, buildSnapshot, createBetterCMS, createDisableDraftRoute, createDraftModeRoute, createRevalidateRoute, defineBetterCMSLive, entryAttrs, entryField, fetchModels, fieldAttrs, fieldStyleOf, generateLlmsTxt, getComponent, getContent, getForm, getPage, getPreviewBranch, getPreviewToken, isDraftEnabled, llmsTxtRoute, parseSnapshot, readComponents, readForms, readPages, readSnapshot, sectionColumnAttrs, sectionRootAttrs, sectionsFor, sectionsServerSideProps, sectionsStaticProps, serializeSnapshot, writeSnapshot };
890
+ export { type BcmsBlocksProps, BcmsButton, type BcmsButtonProps, BcmsDraftMarker, BcmsEmbedScripts, BcmsField, type BcmsFieldProps, type BcmsFormProps, BcmsImage, type BcmsImageProps, type BcmsLiveProps, type BcmsSectionProps, type BcmsSectionsProps, type BetterCMSConfig, type BetterCMSEntry, BetterCMSError, type BetterCMSLiveConfig, type BetterCMSNext, type BetterCMSPage, type ContentSnapshot, type ContentSource, DEFAULT_SNAPSHOT_FILE, type DraftModeRouteConfig, type EntryFieldAttrs, type EntryList, type EntryRef, type EntryTransform, type FieldAttrs, type GetEntryOptions, type ListEntriesOptions, type LlmsModel, type LlmsModelField, type LlmsTxtOptions, type LlmsTxtRouteConfig, PREVIEW_TOKEN_COOKIE, type ReadOptions, type RevalidateRouteConfig, SNAPSHOT_VERSION, type SectionColumnAttrs, type SectionRootAttrs, type SectionRootBlock, type SectionRootProps, type SectionsData, type SectionsRead, type SnapshotForms, type SnapshotPage, type VisualEditingProps, buildMetadata, buildSnapshot, createBetterCMS, createDisableDraftRoute, createDraftModeRoute, createRevalidateRoute, defineBetterCMSLive, entryAttrs, entryField, fetchModels, fieldAttrs, fieldStyleOf, generateLlmsTxt, getBranchPreview, getComponent, getContent, getForm, getPage, getPreviewBranch, getPreviewToken, isDraftEnabled, llmsTxtRoute, parseSnapshot, readComponents, readForms, readPages, readSnapshot, sectionColumnAttrs, sectionRootAttrs, sectionsFor, sectionsServerSideProps, sectionsStaticProps, serializeSnapshot, writeSnapshot };
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { readFileSync } from "fs";
3
3
  import { resolve } from "path";
4
4
  import { resolveBcmsConfig } from "@bettercms-ai/sdk/config";
5
+ import { BRANCH_SIGNATURE_HEADER } from "@bettercms-ai/sdk/draft";
5
6
 
6
7
  // src/types.ts
7
8
  var BetterCMSError = class extends Error {
@@ -67,14 +68,16 @@ function createBetterCMS(options = {}) {
67
68
  const baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
68
69
  const previewBaseUrl = (config.previewBaseUrl ?? baseUrl.replace(/\/delivery$/, "/preview")).replace(/\/+$/, "");
69
70
  const defaultRevalidate = config.revalidate ?? DEFAULT_REVALIDATE;
71
+ const signedBranch = !!(config.branch && config.branch !== "main" && config.branchSignature);
70
72
  function headers() {
71
73
  const h = { Accept: "application/json" };
72
- if (config.apiKey) h["Authorization"] = `Bearer ${config.apiKey}`;
74
+ if (signedBranch) h[BRANCH_SIGNATURE_HEADER] = config.branchSignature;
75
+ else if (config.apiKey) h["Authorization"] = `Bearer ${config.apiKey}`;
73
76
  return h;
74
77
  }
75
78
  function cacheInit(revalidate, tags, forceNoStore = false) {
76
79
  const rv = revalidate ?? defaultRevalidate;
77
- if (forceNoStore) return { headers: headers(), cache: "no-store" };
80
+ if (forceNoStore || signedBranch) return { headers: headers(), cache: "no-store" };
78
81
  if (rv === false) {
79
82
  return tags?.length ? { headers: headers(), next: { revalidate: false, tags } } : { headers: headers(), cache: "no-store" };
80
83
  }
@@ -541,7 +544,7 @@ async function fetchModels(opts) {
541
544
 
542
545
  // src/preview.ts
543
546
  import { Fragment, createElement } from "react";
544
- import { decodeTokenBranch } from "@bettercms-ai/sdk/draft";
547
+ import { decodeTokenBranch, signBranchRead } from "@bettercms-ai/sdk/draft";
545
548
  async function isDraftEnabled() {
546
549
  const { draftMode } = await import("next/headers");
547
550
  const dm = await draftMode();
@@ -556,6 +559,13 @@ async function getPreviewBranch() {
556
559
  if (!await isDraftEnabled()) return null;
557
560
  return decodeTokenBranch(await getPreviewToken());
558
561
  }
562
+ async function getBranchPreview() {
563
+ const { headers } = await import("next/headers");
564
+ const branch = (await headers()).get("x-branch-id")?.trim();
565
+ const secret = typeof process !== "undefined" ? process.env.BCMS_BRANCH_SECRET : void 0;
566
+ if (!branch || !secret) return null;
567
+ return { branch, branchSignature: await signBranchRead(branch, secret) };
568
+ }
559
569
  async function BcmsDraftMarker() {
560
570
  const generator = createElement("meta", { name: "generator", content: "BetterCMS" });
561
571
  if (!await isDraftEnabled()) return generator;
@@ -756,15 +766,8 @@ function BcmsButton({ path, value, className }) {
756
766
  }
757
767
 
758
768
  // src/image.tsx
759
- import imageUrlBuilder, {
760
- focalInCrop,
761
- normalizeImageCrop,
762
- normalizeImageFocal,
763
- objectPosition
764
- } from "@bettercms-ai/image-url";
769
+ import { imageCore } from "@bettercms-ai/sdk/bindings";
765
770
  import { jsx as jsx3 } from "react/jsx-runtime";
766
- var LADDER = [480, 768, 1080, 1440, 1920];
767
- var num = (v) => typeof v === "number" && Number.isFinite(v) ? v : void 0;
768
771
  function BcmsImage({
769
772
  src,
770
773
  path,
@@ -782,39 +785,14 @@ function BcmsImage({
782
785
  style,
783
786
  ...rest
784
787
  }) {
785
- const asset = typeof src === "object" && src !== null ? src : {};
786
- const explicit = focalX != null || focalY != null;
787
- const stored = normalizeImageFocal(asset.focal) ?? (num(asset.focalX) != null || num(asset.focalY) != null ? { x: num(asset.focalX) ?? 0.5, y: num(asset.focalY) ?? 0.5 } : null);
788
- const inWindow = stored ? focalInCrop(stored, normalizeImageCrop(asset.crop)) : null;
789
- const fx = explicit ? focalX : inWindow?.x;
790
- const fy = explicit ? focalY : inWindow?.y;
791
- const hasFocal = fx != null || fy != null;
792
- const builder = imageUrlBuilder({ baseUrl });
793
- const make = () => {
794
- let b = builder(src);
795
- if (width) b = b.width(width);
796
- if (height) b = b.height(height);
797
- if (format) b = b.format(format);
798
- if (quality) b = b.quality(quality);
799
- if (fit) b = b.fit(fit);
800
- if (hasFocal) b = b.focal(fx ?? 0.5, fy ?? 0.5);
801
- return b;
802
- };
803
- const src1x = make().url();
804
- const own = num(asset.width);
805
- const ladder = own ? [.../* @__PURE__ */ new Set([...LADDER.filter((w) => w < own), Math.min(own, LADDER[LADDER.length - 1])])] : LADDER;
806
- const srcSet = sizes && !width ? ladder.map((w) => `${make().width(w).url()} ${w}w`).join(", ") : `${src1x} 1x, ${make().dpr(2).url()} 2x`;
807
- const merged = {
808
- ...width ? { width: `${width}px`, maxWidth: "100%", height: "auto" } : {},
809
- ...hasFocal ? { objectPosition: objectPosition({ x: fx, y: fy }) } : {},
810
- ...style
811
- };
788
+ const { src: src1x, srcset: srcSet, alt: resolvedAlt, css } = imageCore(src, { alt, width, height, format, quality, fit, sizes, focalX, focalY, baseUrl });
789
+ const merged = { ...css, ...style };
812
790
  return /* @__PURE__ */ jsx3(
813
791
  "img",
814
792
  {
815
793
  src: src1x,
816
794
  srcSet,
817
- alt: alt ?? (typeof asset.altText === "string" ? asset.altText : typeof asset.alt === "string" ? asset.alt : ""),
795
+ alt: resolvedAlt,
818
796
  "data-bcms-field": path,
819
797
  "data-bcms-kind": path ? "image" : void 0,
820
798
  width,
@@ -828,13 +806,9 @@ function BcmsImage({
828
806
  }
829
807
 
830
808
  // src/live-config.ts
809
+ import { liveSrc } from "@bettercms-ai/sdk/live";
831
810
  function defineBetterCMSLive(config) {
832
- const base = config.apiUrl.replace(/\/+$/, "");
833
- const q = new URLSearchParams({ key: config.apiKey });
834
- if (config.depth !== void 0) q.set("depth", String(config.depth));
835
- if (config.drafts) q.set("drafts", "1");
836
- const liveSrc = `${base}/api/v1/delivery/${config.workspace}/live?${q}`;
837
- return { liveSrc };
811
+ return { liveSrc: liveSrc(config) };
838
812
  }
839
813
 
840
814
  // src/revalidate-route.ts
@@ -901,6 +875,7 @@ export {
901
875
  fieldAttrs,
902
876
  fieldStyleOf,
903
877
  generateLlmsTxt,
878
+ getBranchPreview,
904
879
  getComponent,
905
880
  getContent,
906
881
  getForm,