@bettercms-ai/astro 0.2.1 → 0.3.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,10 +30,10 @@ 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 ?? ""} />;
|
|
36
|
+
return <div class="bcms-text" data-bcms-field={`${block.id}__html`} data-bcms-kind="richtext" set:html={p.html ?? ""} />;
|
|
37
37
|
case "image":
|
|
38
38
|
return p.caption ? (
|
|
39
39
|
<figure>
|
|
@@ -45,7 +45,7 @@ const anyProps = (b: ContentBlock) => (b as { props?: Record<string, any> }).pro
|
|
|
45
45
|
);
|
|
46
46
|
case "button":
|
|
47
47
|
return (
|
|
48
|
-
<a class={`bcms-btn bcms-btn-${p.variant === "secondary" ? "secondary" : "primary"}`} href={p.href ?? "#"}>
|
|
48
|
+
<a class={`bcms-btn bcms-btn-${p.variant === "secondary" ? "secondary" : "primary"}`} href={p.href ?? "#"} data-bcms-field={`${block.id}__text`}>
|
|
49
49
|
{p.text}
|
|
50
50
|
</a>
|
|
51
51
|
);
|
|
@@ -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>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bettercms-ai/astro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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",
|