@bettercms-ai/next 0.35.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.
- package/dist/elements.d.ts +56 -2
- package/dist/elements.js +56 -37
- package/dist/elements.js.map +1 -1
- package/dist/index.d.ts +2 -23
- package/dist/index.js +6 -42
- package/dist/index.js.map +1 -1
- package/dist/live.d.ts +4 -20
- package/dist/live.js +2 -39
- package/dist/live.js.map +1 -1
- package/dist/section-root-_bk8G5ry.d.ts +44 -0
- package/dist/sections.d.ts +2 -24
- package/dist/visual-editing.js +2 -9
- package/dist/visual-editing.js.map +1 -1
- package/package.json +2 -2
package/dist/elements.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { ElementType, ReactNode, ImgHTMLAttributes } from 'react';
|
|
2
|
+
import { ElementType, ReactNode, ImgHTMLAttributes, CSSProperties } from 'react';
|
|
3
3
|
import { ImageSource, ImageFormat, ImageFit } from '@bettercms-ai/image-url';
|
|
4
|
+
import { FieldStyles, FieldStyle } from '@bettercms-ai/types';
|
|
5
|
+
export { S as SectionColumnAttrs, a as SectionRootAttrs, b as SectionRootBlock, s as sectionColumnAttrs, c as sectionRootAttrs } from './section-root-_bk8G5ry.js';
|
|
4
6
|
|
|
5
7
|
interface BcmsFieldProps {
|
|
6
8
|
/** Field path in the editor grammar, e.g. `title` or `facts[2].label`. */
|
|
@@ -37,6 +39,7 @@ interface BcmsImageProps extends Omit<ImgHTMLAttributes<HTMLImageElement>, "src"
|
|
|
37
39
|
/** Media host for a `src` that is only an asset id. Defaults to the platform's. */
|
|
38
40
|
baseUrl?: string;
|
|
39
41
|
}
|
|
42
|
+
/** The widths a `sizes` image offers: phone to desktop, and never an upscale of the picture. */
|
|
40
43
|
declare function BcmsImage({ src, path, alt, width, height, format, quality, fit, sizes, loading, focalX, focalY, baseUrl, style, ...rest }: BcmsImageProps): react_jsx_runtime.JSX.Element;
|
|
41
44
|
|
|
42
45
|
interface BcmsButtonProps {
|
|
@@ -48,4 +51,55 @@ interface BcmsButtonProps {
|
|
|
48
51
|
}
|
|
49
52
|
declare function BcmsButton({ path, value, className }: BcmsButtonProps): react_jsx_runtime.JSX.Element | null;
|
|
50
53
|
|
|
51
|
-
|
|
54
|
+
/**
|
|
55
|
+
* C3 — `fieldAttrs(path, fieldStyles)`: the props a site's OWN element spreads to bind a PAGE FIELD
|
|
56
|
+
* and apply that field's stored style, so the BetterCMS editor offers its width and spacing handles
|
|
57
|
+
* and its Align / Size / Weight controls.
|
|
58
|
+
*
|
|
59
|
+
* const page = await client.getPage("home");
|
|
60
|
+
* <h1 className="title" {...fieldAttrs("hero-title", page?.fieldStyles)}>{entry.data["hero-title"]}</h1>
|
|
61
|
+
*
|
|
62
|
+
* `data-bcms-style` is the site's promise that "this element's inline style is
|
|
63
|
+
* `fieldStyleToCss(fieldStyles[path])`"; the editor offers a field's handles only where it is
|
|
64
|
+
* present. Present even when the field has no style (then there is no `style` prop at all).
|
|
65
|
+
* Twin: `fieldAttrs` in @bettercms-ai/astro (a CSS string there).
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
interface FieldAttrs {
|
|
69
|
+
"data-bcms-field": string;
|
|
70
|
+
/** The marker's revision: "2" promises `size` (zoom) too. Section roots keep "". */
|
|
71
|
+
"data-bcms-style": "2";
|
|
72
|
+
/** `fieldStyleToCss(fieldStyles[path])`; absent when the field has no style. */
|
|
73
|
+
style?: CSSProperties;
|
|
74
|
+
}
|
|
75
|
+
/** The stored style for `path`, by OWN key only — a path like `constructor` never reads the prototype. */
|
|
76
|
+
declare function fieldStyleOf(path: string, fieldStyles: FieldStyles | Record<string, unknown> | null | undefined): FieldStyle | undefined;
|
|
77
|
+
declare function fieldAttrs(path: string, fieldStyles?: FieldStyles | Record<string, unknown> | null): FieldAttrs;
|
|
78
|
+
/**
|
|
79
|
+
* P7 — `entryAttrs(entry)` and `entryField(entry, path)`: the attributes a site's OWN card spreads to
|
|
80
|
+
* declare a collection ENTRY, so the editor binds it without guessing from the rendered text.
|
|
81
|
+
*
|
|
82
|
+
* <article {...entryAttrs(post)}><h3 {...entryField(post, "title")}>{post.fields.title}</h3></article>
|
|
83
|
+
*
|
|
84
|
+
* The field address is ABSOLUTE (`entry:<id>:<path>`). With a `transform` the value is shown
|
|
85
|
+
* changed (a date formatted, text truncated), so it is declared as `data-bcms-entry-from`: the
|
|
86
|
+
* editor knows where it is but cannot re-render it. Twin: same helpers in @bettercms-ai/astro.
|
|
87
|
+
*/
|
|
88
|
+
type EntryRef = {
|
|
89
|
+
id?: string;
|
|
90
|
+
} | string;
|
|
91
|
+
type EntryTransform = "format" | "truncate" | "rendition" | "route";
|
|
92
|
+
/** One key is present: `data-bcms-entry-field`, or `data-bcms-entry-from` when transformed; none without an id. */
|
|
93
|
+
interface EntryFieldAttrs {
|
|
94
|
+
"data-bcms-entry-field"?: string;
|
|
95
|
+
"data-bcms-entry-from"?: string;
|
|
96
|
+
}
|
|
97
|
+
/** An entry with no id (a snapshot written before ids were kept) renders unbound, never fails the build. */
|
|
98
|
+
declare function entryAttrs(entry: EntryRef): {
|
|
99
|
+
"data-bcms-entry"?: string;
|
|
100
|
+
};
|
|
101
|
+
declare function entryField(entry: EntryRef, path: string, opts?: {
|
|
102
|
+
transform?: EntryTransform;
|
|
103
|
+
}): EntryFieldAttrs;
|
|
104
|
+
|
|
105
|
+
export { BcmsButton, type BcmsButtonProps, BcmsField, type BcmsFieldProps, BcmsImage, type BcmsImageProps, type EntryFieldAttrs, type EntryRef, type EntryTransform, type FieldAttrs, entryAttrs, entryField, fieldAttrs, fieldStyleOf };
|
package/dist/elements.js
CHANGED
|
@@ -20,15 +20,8 @@ function BcmsField({ path, kind, as, children }) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
// src/image.tsx
|
|
23
|
-
import
|
|
24
|
-
focalInCrop,
|
|
25
|
-
normalizeImageCrop,
|
|
26
|
-
normalizeImageFocal,
|
|
27
|
-
objectPosition
|
|
28
|
-
} from "@bettercms-ai/image-url";
|
|
23
|
+
import { imageCore } from "@bettercms-ai/sdk/bindings";
|
|
29
24
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
30
|
-
var LADDER = [480, 768, 1080, 1440, 1920];
|
|
31
|
-
var num = (v) => typeof v === "number" && Number.isFinite(v) ? v : void 0;
|
|
32
25
|
function BcmsImage({
|
|
33
26
|
src,
|
|
34
27
|
path,
|
|
@@ -46,39 +39,14 @@ function BcmsImage({
|
|
|
46
39
|
style,
|
|
47
40
|
...rest
|
|
48
41
|
}) {
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
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);
|
|
52
|
-
const inWindow = stored ? focalInCrop(stored, normalizeImageCrop(asset.crop)) : null;
|
|
53
|
-
const fx = explicit ? focalX : inWindow?.x;
|
|
54
|
-
const fy = explicit ? focalY : inWindow?.y;
|
|
55
|
-
const hasFocal = fx != null || fy != null;
|
|
56
|
-
const builder = imageUrlBuilder({ baseUrl });
|
|
57
|
-
const make = () => {
|
|
58
|
-
let b = builder(src);
|
|
59
|
-
if (width) b = b.width(width);
|
|
60
|
-
if (height) b = b.height(height);
|
|
61
|
-
if (format) b = b.format(format);
|
|
62
|
-
if (quality) b = b.quality(quality);
|
|
63
|
-
if (fit) b = b.fit(fit);
|
|
64
|
-
if (hasFocal) b = b.focal(fx ?? 0.5, fy ?? 0.5);
|
|
65
|
-
return b;
|
|
66
|
-
};
|
|
67
|
-
const src1x = make().url();
|
|
68
|
-
const own = num(asset.width);
|
|
69
|
-
const ladder = own ? [.../* @__PURE__ */ new Set([...LADDER.filter((w) => w < own), Math.min(own, LADDER[LADDER.length - 1])])] : LADDER;
|
|
70
|
-
const srcSet = sizes && !width ? ladder.map((w) => `${make().width(w).url()} ${w}w`).join(", ") : `${src1x} 1x, ${make().dpr(2).url()} 2x`;
|
|
71
|
-
const merged = {
|
|
72
|
-
...width ? { width: `${width}px`, maxWidth: "100%", height: "auto" } : {},
|
|
73
|
-
...hasFocal ? { objectPosition: objectPosition({ x: fx, y: fy }) } : {},
|
|
74
|
-
...style
|
|
75
|
-
};
|
|
42
|
+
const { src: src1x, srcset: srcSet, alt: resolvedAlt, css } = imageCore(src, { alt, width, height, format, quality, fit, sizes, focalX, focalY, baseUrl });
|
|
43
|
+
const merged = { ...css, ...style };
|
|
76
44
|
return /* @__PURE__ */ jsx2(
|
|
77
45
|
"img",
|
|
78
46
|
{
|
|
79
47
|
src: src1x,
|
|
80
48
|
srcSet,
|
|
81
|
-
alt:
|
|
49
|
+
alt: resolvedAlt,
|
|
82
50
|
"data-bcms-field": path,
|
|
83
51
|
"data-bcms-kind": path ? "image" : void 0,
|
|
84
52
|
width,
|
|
@@ -122,9 +90,60 @@ function BcmsButton({ path, value, className }) {
|
|
|
122
90
|
}
|
|
123
91
|
);
|
|
124
92
|
}
|
|
93
|
+
|
|
94
|
+
// src/field-attrs.ts
|
|
95
|
+
import { fieldStyleToCss } from "@bettercms-ai/types";
|
|
96
|
+
function fieldStyleOf(path, fieldStyles) {
|
|
97
|
+
if (!fieldStyles || typeof fieldStyles !== "object" || !Object.prototype.hasOwnProperty.call(fieldStyles, path)) return void 0;
|
|
98
|
+
const style = fieldStyles[path];
|
|
99
|
+
return style && typeof style === "object" ? style : void 0;
|
|
100
|
+
}
|
|
101
|
+
function fieldAttrs(path, fieldStyles) {
|
|
102
|
+
const css = fieldStyleToCss(fieldStyleOf(path, fieldStyles));
|
|
103
|
+
return { "data-bcms-field": path, "data-bcms-style": "2", ...css ? { style: css } : {} };
|
|
104
|
+
}
|
|
105
|
+
function entryIdOf(entry) {
|
|
106
|
+
const id = typeof entry === "string" ? entry : entry?.id;
|
|
107
|
+
return typeof id === "string" && id.trim() !== "" ? id : null;
|
|
108
|
+
}
|
|
109
|
+
function entryAttrs(entry) {
|
|
110
|
+
const id = entryIdOf(entry);
|
|
111
|
+
return id ? { "data-bcms-entry": id } : {};
|
|
112
|
+
}
|
|
113
|
+
function entryField(entry, path, opts) {
|
|
114
|
+
const id = entryIdOf(entry);
|
|
115
|
+
if (typeof path !== "string" || path.trim() === "") throw new Error(`entryField: no field path given for entry ${id ?? "(no id)"}`);
|
|
116
|
+
if (!id) return {};
|
|
117
|
+
const address = `entry:${id}:${path}`;
|
|
118
|
+
return opts?.transform ? { "data-bcms-entry-from": `${address}|${opts.transform}` } : { "data-bcms-entry-field": address };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/section-root.ts
|
|
122
|
+
import { blockStyleToColumnCss, blockStyleToCss, hideOnAttr } from "@bettercms-ai/types";
|
|
123
|
+
function sectionRootAttrs(block) {
|
|
124
|
+
const css = blockStyleToCss(block?.style ?? void 0);
|
|
125
|
+
const id = typeof block?.id === "string" && block.id !== "" ? block.id : void 0;
|
|
126
|
+
const hide = hideOnAttr(block?.style);
|
|
127
|
+
return {
|
|
128
|
+
...id !== void 0 ? { "data-bcms-block": id } : {},
|
|
129
|
+
"data-bcms-style": "",
|
|
130
|
+
...hide ? { "data-bcms-hide": hide } : {},
|
|
131
|
+
...css ? { style: css } : {}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function sectionColumnAttrs(block) {
|
|
135
|
+
const css = blockStyleToColumnCss(block?.style ?? void 0);
|
|
136
|
+
return { "data-bcms-column": "", ...css ? { style: css } : {} };
|
|
137
|
+
}
|
|
125
138
|
export {
|
|
126
139
|
BcmsButton,
|
|
127
140
|
BcmsField,
|
|
128
|
-
BcmsImage
|
|
141
|
+
BcmsImage,
|
|
142
|
+
entryAttrs,
|
|
143
|
+
entryField,
|
|
144
|
+
fieldAttrs,
|
|
145
|
+
fieldStyleOf,
|
|
146
|
+
sectionColumnAttrs,
|
|
147
|
+
sectionRootAttrs
|
|
129
148
|
};
|
|
130
149
|
//# sourceMappingURL=elements.js.map
|
package/dist/elements.js.map
CHANGED
|
@@ -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,eAAe,KAAK,CAAC,CAAC,KAAK,OAAO,KAAK,CAAC,EAAE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,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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,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.
|
|
@@ -825,27 +826,9 @@ interface BcmsImageProps extends Omit<ImgHTMLAttributes<HTMLImageElement>, "src"
|
|
|
825
826
|
/** Media host for a `src` that is only an asset id. Defaults to the platform's. */
|
|
826
827
|
baseUrl?: string;
|
|
827
828
|
}
|
|
829
|
+
/** The widths a `sizes` image offers: phone to desktop, and never an upscale of the picture. */
|
|
828
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;
|
|
829
831
|
|
|
830
|
-
/** A `change` frame off the live stream. */
|
|
831
|
-
interface BcmsChangeEvent<T = unknown> {
|
|
832
|
-
type: "entry" | "page";
|
|
833
|
-
slug: string;
|
|
834
|
-
reason: "publish" | "unpublish" | "draft";
|
|
835
|
-
/** Cache tags, `bcms:{ws}:all` + `bcms:{ws}:{type}:{slug}`. */
|
|
836
|
-
tags: string[];
|
|
837
|
-
projectId: string | null;
|
|
838
|
-
/** When the change was committed. */
|
|
839
|
-
at: string;
|
|
840
|
-
/** When the server flushed this frame — `at`→`sentAt` is its own cost. */
|
|
841
|
-
sentAt?: string;
|
|
842
|
-
/**
|
|
843
|
-
* The finished delivery payload. Absent on `unpublish`, and when the server
|
|
844
|
-
* could not hydrate it (over quota, deleted, larger than the frame cap) — in
|
|
845
|
-
* which case the client has to refetch, which is what it always used to do.
|
|
846
|
-
*/
|
|
847
|
-
doc?: T;
|
|
848
|
-
}
|
|
849
832
|
interface BcmsLiveProps {
|
|
850
833
|
/** Live SSE URL, e.g. from `defineBetterCMSLive().liveSrc`. */
|
|
851
834
|
src: string;
|
|
@@ -861,10 +844,6 @@ interface BcmsLiveProps {
|
|
|
861
844
|
onChange?: (event: BcmsChangeEvent) => void;
|
|
862
845
|
}
|
|
863
846
|
|
|
864
|
-
/**
|
|
865
|
-
* defineBetterCMSLive — build the live SSE URL for `<BcmsLive>` from your config.
|
|
866
|
-
* Server-safe (no React); pass the returned `liveSrc` to the client component.
|
|
867
|
-
*/
|
|
868
847
|
interface BetterCMSLiveConfig {
|
|
869
848
|
/** Backend base, e.g. `https://api.bettercms.ai`. */
|
|
870
849
|
apiUrl: string;
|
package/dist/index.js
CHANGED
|
@@ -766,15 +766,8 @@ function BcmsButton({ path, value, className }) {
|
|
|
766
766
|
}
|
|
767
767
|
|
|
768
768
|
// src/image.tsx
|
|
769
|
-
import
|
|
770
|
-
focalInCrop,
|
|
771
|
-
normalizeImageCrop,
|
|
772
|
-
normalizeImageFocal,
|
|
773
|
-
objectPosition
|
|
774
|
-
} from "@bettercms-ai/image-url";
|
|
769
|
+
import { imageCore } from "@bettercms-ai/sdk/bindings";
|
|
775
770
|
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
776
|
-
var LADDER = [480, 768, 1080, 1440, 1920];
|
|
777
|
-
var num = (v) => typeof v === "number" && Number.isFinite(v) ? v : void 0;
|
|
778
771
|
function BcmsImage({
|
|
779
772
|
src,
|
|
780
773
|
path,
|
|
@@ -792,39 +785,14 @@ function BcmsImage({
|
|
|
792
785
|
style,
|
|
793
786
|
...rest
|
|
794
787
|
}) {
|
|
795
|
-
const
|
|
796
|
-
const
|
|
797
|
-
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);
|
|
798
|
-
const inWindow = stored ? focalInCrop(stored, normalizeImageCrop(asset.crop)) : null;
|
|
799
|
-
const fx = explicit ? focalX : inWindow?.x;
|
|
800
|
-
const fy = explicit ? focalY : inWindow?.y;
|
|
801
|
-
const hasFocal = fx != null || fy != null;
|
|
802
|
-
const builder = imageUrlBuilder({ baseUrl });
|
|
803
|
-
const make = () => {
|
|
804
|
-
let b = builder(src);
|
|
805
|
-
if (width) b = b.width(width);
|
|
806
|
-
if (height) b = b.height(height);
|
|
807
|
-
if (format) b = b.format(format);
|
|
808
|
-
if (quality) b = b.quality(quality);
|
|
809
|
-
if (fit) b = b.fit(fit);
|
|
810
|
-
if (hasFocal) b = b.focal(fx ?? 0.5, fy ?? 0.5);
|
|
811
|
-
return b;
|
|
812
|
-
};
|
|
813
|
-
const src1x = make().url();
|
|
814
|
-
const own = num(asset.width);
|
|
815
|
-
const ladder = own ? [.../* @__PURE__ */ new Set([...LADDER.filter((w) => w < own), Math.min(own, LADDER[LADDER.length - 1])])] : LADDER;
|
|
816
|
-
const srcSet = sizes && !width ? ladder.map((w) => `${make().width(w).url()} ${w}w`).join(", ") : `${src1x} 1x, ${make().dpr(2).url()} 2x`;
|
|
817
|
-
const merged = {
|
|
818
|
-
...width ? { width: `${width}px`, maxWidth: "100%", height: "auto" } : {},
|
|
819
|
-
...hasFocal ? { objectPosition: objectPosition({ x: fx, y: fy }) } : {},
|
|
820
|
-
...style
|
|
821
|
-
};
|
|
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 };
|
|
822
790
|
return /* @__PURE__ */ jsx3(
|
|
823
791
|
"img",
|
|
824
792
|
{
|
|
825
793
|
src: src1x,
|
|
826
794
|
srcSet,
|
|
827
|
-
alt:
|
|
795
|
+
alt: resolvedAlt,
|
|
828
796
|
"data-bcms-field": path,
|
|
829
797
|
"data-bcms-kind": path ? "image" : void 0,
|
|
830
798
|
width,
|
|
@@ -838,13 +806,9 @@ function BcmsImage({
|
|
|
838
806
|
}
|
|
839
807
|
|
|
840
808
|
// src/live-config.ts
|
|
809
|
+
import { liveSrc } from "@bettercms-ai/sdk/live";
|
|
841
810
|
function defineBetterCMSLive(config) {
|
|
842
|
-
|
|
843
|
-
const q = new URLSearchParams({ key: config.apiKey });
|
|
844
|
-
if (config.depth !== void 0) q.set("depth", String(config.depth));
|
|
845
|
-
if (config.drafts) q.set("drafts", "1");
|
|
846
|
-
const liveSrc = `${base}/api/v1/delivery/${config.workspace}/live?${q}`;
|
|
847
|
-
return { liveSrc };
|
|
811
|
+
return { liveSrc: liveSrc(config) };
|
|
848
812
|
}
|
|
849
813
|
|
|
850
814
|
// src/revalidate-route.ts
|