@bettercms-ai/astro 0.2.1 → 0.4.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.
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* with `columns` recursing via Astro.self and `form` resolving from the `forms`
|
|
6
6
|
* prop. Class names mirror the server-side renderer.
|
|
7
7
|
*/
|
|
8
|
-
import type { ContentBlock } from "@
|
|
9
|
-
import type { DeliveryForm } from "@
|
|
8
|
+
import type { ContentBlock } from "@bettercms-ai/types";
|
|
9
|
+
import type { DeliveryForm } from "@bettercms-ai/sdk";
|
|
10
10
|
import BcmsImage from "./BcmsImage.astro";
|
|
11
11
|
import BcmsForm from "./BcmsForm.astro";
|
|
12
12
|
|
|
@@ -30,22 +30,27 @@ const anyProps = (b: ContentBlock) => (b as { props?: Record<string, any> }).pro
|
|
|
30
30
|
switch (block.type) {
|
|
31
31
|
case "heading": {
|
|
32
32
|
const Tag = `h${clamp(Number(p.level) || 2, 1, 6)}` as keyof HTMLElementTagNameMap;
|
|
33
|
-
return <Tag>{p.text}</Tag>;
|
|
33
|
+
return <Tag data-bcms-field={`${block.id}__text`}>{p.text}</Tag>;
|
|
34
34
|
}
|
|
35
35
|
case "text":
|
|
36
|
-
return <div class="bcms-text" set:html={p.html ?? ""} />;
|
|
37
|
-
case "image":
|
|
36
|
+
return <div class="bcms-text" data-bcms-field={`${block.id}__html`} data-bcms-kind="richtext" set:html={p.html ?? ""} />;
|
|
37
|
+
case "image": {
|
|
38
|
+
// Matches the Next adapter: the image block is click-to-select on the Visual Editor
|
|
39
|
+
// canvas like heading/text/button, rather than dock-only. `kind="image"` means select
|
|
40
|
+
// + live src reflection, never contentEditable.
|
|
41
|
+
const bind = { "data-bcms-field": `${block.id}__src`, "data-bcms-kind": "image" };
|
|
38
42
|
return p.caption ? (
|
|
39
43
|
<figure>
|
|
40
|
-
<BcmsImage src={p.src} alt={p.alt ?? ""} width={p.width} height={p.height} />
|
|
44
|
+
<BcmsImage src={p.src} alt={p.alt ?? ""} width={p.width} height={p.height} {...bind} />
|
|
41
45
|
<figcaption>{p.caption}</figcaption>
|
|
42
46
|
</figure>
|
|
43
47
|
) : (
|
|
44
|
-
<BcmsImage src={p.src} alt={p.alt ?? ""} width={p.width} height={p.height} />
|
|
48
|
+
<BcmsImage src={p.src} alt={p.alt ?? ""} width={p.width} height={p.height} {...bind} />
|
|
45
49
|
);
|
|
50
|
+
}
|
|
46
51
|
case "button":
|
|
47
52
|
return (
|
|
48
|
-
<a class={`bcms-btn bcms-btn-${p.variant === "secondary" ? "secondary" : "primary"}`} href={p.href ?? "#"}>
|
|
53
|
+
<a class={`bcms-btn bcms-btn-${p.variant === "secondary" ? "secondary" : "primary"}`} href={p.href ?? "#"} data-bcms-field={`${block.id}__text`}>
|
|
49
54
|
{p.text}
|
|
50
55
|
</a>
|
|
51
56
|
);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* <BcmsField> — tag an entry field's rendered value with its identity so the
|
|
4
|
+
* BetterCMS visual editor can bind click-to-edit deterministically (mirrors
|
|
5
|
+
* Sanity's `data-sanity` / BaseHub's `data-basehub`). Entry-backed templates
|
|
6
|
+
* hand-render field values (`f.title`, `f.body.html`), so the field `path` is
|
|
7
|
+
* declared here by the author — the delivery payload carries no source-map.
|
|
8
|
+
*
|
|
9
|
+
* By default wraps the slot in a `display:contents` span, invisible to
|
|
10
|
+
* layout/GSAP; pass `as` to carry the attributes on a real element instead.
|
|
11
|
+
*
|
|
12
|
+
* `path` follows the editor grammar: `title` · `hero.title` · `facts[2].label`
|
|
13
|
+
* (dotted keys, at most one array index). For images, put the attributes on the
|
|
14
|
+
* `<img>` itself (`kind="image"` reflection patches `.src`), not on a wrapper:
|
|
15
|
+
* <img src={f.cover.url} data-bcms-field="cover" data-bcms-kind="image" />
|
|
16
|
+
*/
|
|
17
|
+
interface Props {
|
|
18
|
+
/** Field path in the editor grammar, e.g. `title` or `facts[2].label`. */
|
|
19
|
+
path: string;
|
|
20
|
+
/** Kind hint the editor's reflection branches on. Omit for plain text/number. */
|
|
21
|
+
kind?: "richtext" | "image";
|
|
22
|
+
/** Wrapper element. Defaults to a `display:contents` span. */
|
|
23
|
+
as?: string;
|
|
24
|
+
}
|
|
25
|
+
const { path, kind, as } = Astro.props;
|
|
26
|
+
const Tag = (as ?? "span") as keyof HTMLElementTagNameMap;
|
|
27
|
+
---
|
|
28
|
+
<Tag data-bcms-field={path} data-bcms-kind={kind} style={as ? undefined : "display:contents"}>
|
|
29
|
+
<slot />
|
|
30
|
+
</Tag>
|
|
@@ -21,6 +21,8 @@ interface Props {
|
|
|
21
21
|
sizes?: string;
|
|
22
22
|
loading?: "lazy" | "eager";
|
|
23
23
|
class?: string;
|
|
24
|
+
/** Any other attribute (e.g. `data-bcms-field`) is forwarded to the <img>. */
|
|
25
|
+
[attr: string]: unknown;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
const {
|
|
@@ -34,6 +36,7 @@ const {
|
|
|
34
36
|
sizes,
|
|
35
37
|
loading = "lazy",
|
|
36
38
|
class: className,
|
|
39
|
+
...rest
|
|
37
40
|
} = Astro.props;
|
|
38
41
|
|
|
39
42
|
const builder = imageUrlBuilder({ baseUrl: config.mediaUrl });
|
|
@@ -60,4 +63,5 @@ const src2x = make().dpr(2).url();
|
|
|
60
63
|
sizes={sizes}
|
|
61
64
|
loading={loading}
|
|
62
65
|
class={className}
|
|
66
|
+
{...rest}
|
|
63
67
|
/>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bettercms-ai/astro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"./draft-enable": "./dist/routes/draft-enable.js",
|
|
27
27
|
"./draft-disable": "./dist/routes/draft-disable.js",
|
|
28
28
|
"./components/BcmsBlocks.astro": "./components/BcmsBlocks.astro",
|
|
29
|
+
"./components/BcmsField.astro": "./components/BcmsField.astro",
|
|
29
30
|
"./components/BcmsForm.astro": "./components/BcmsForm.astro",
|
|
30
31
|
"./components/BcmsSearch.astro": "./components/BcmsSearch.astro",
|
|
31
32
|
"./components/BcmsImage.astro": "./components/BcmsImage.astro",
|