@bettercms-ai/astro 0.16.0 → 0.18.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.
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* actually contains that block (mirrors render-page.ts's `ctx.flags` gating).
|
|
27
27
|
*/
|
|
28
28
|
import type { ContentBlock } from "@bettercms-ai/types";
|
|
29
|
-
import { blockStyleToCss, componentInstanceAddresses } from "@bettercms-ai/types";
|
|
29
|
+
import { blockStyleToCss, buttonIconOf, buttonIconSvg, buttonVariantOf, componentInstanceAddresses, withButtonLookProps } from "@bettercms-ai/types";
|
|
30
30
|
import { bind, bindProps } from "../dist/bindings.js";
|
|
31
31
|
import type { DeliveryComponent, DeliveryForm } from "@bettercms-ai/sdk";
|
|
32
32
|
import { applyOverrides } from "@bettercms-ai/ui/resolve";
|
|
@@ -123,7 +123,8 @@ function resolveComponent(
|
|
|
123
123
|
if (depth >= MAX_COMPONENT_DEPTH || seen.includes(def.id)) return null;
|
|
124
124
|
const resolved = applyOverrides<ContentBlock>(
|
|
125
125
|
def.blockJson,
|
|
126
|
-
|
|
126
|
+
// A Button's instance may override its look too.
|
|
127
|
+
withButtonLookProps(def),
|
|
127
128
|
(p.overrides as Record<string, unknown>) ?? {},
|
|
128
129
|
);
|
|
129
130
|
// `props` comes back too: the caller needs the DECLARATION (which block each prop drives) to
|
|
@@ -313,13 +314,16 @@ const pass = { forms, components, turnstileSiteKey, nested: true, fieldAddresses
|
|
|
313
314
|
case "button":
|
|
314
315
|
return (
|
|
315
316
|
<a
|
|
316
|
-
class={`bcms-btn bcms-btn-${p.variant
|
|
317
|
+
class={`bcms-btn bcms-btn-${buttonVariantOf(p.variant)}${p.size === "sm" || p.size === "lg" ? ` bcms-btn-${p.size}` : ""}${p.fullWidth === true ? " bcms-btn-full" : ""}`}
|
|
317
318
|
href={p.href ?? "#"}
|
|
319
|
+
{...(p.newTab === true ? { target: "_blank", rel: "noopener noreferrer" } : {})}
|
|
318
320
|
{...bind(block.id, "text", "text", bctx)}
|
|
319
321
|
{...bindProps(block.id, [{ prop: "href", kind: "url", attr: "href", present: p.href != null }], bctx)}
|
|
320
322
|
{...blockAttrs}
|
|
321
323
|
>
|
|
324
|
+
{buttonIconOf(p.icon) && <Fragment set:html={buttonIconSvg(buttonIconOf(p.icon)!, "bcms-btn-icon")} />}
|
|
322
325
|
{p.text}
|
|
326
|
+
{p.arrow === true && <Fragment set:html={buttonIconSvg("arrow-right", "bcms-btn-arrow")} />}
|
|
323
327
|
</a>
|
|
324
328
|
);
|
|
325
329
|
case "spacer":
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* <BcmsButton> — render a `button` field ({ label, href, variant?, size?, arrow?, icon?,
|
|
4
|
+
* newTab? }) as one editable button, the way the BetterCMS visual editor and in-place publishing
|
|
5
|
+
* expect to find it:
|
|
6
|
+
*
|
|
7
|
+
* <a data-bcms-button="<path>" data-variant data-size href [target rel] data-bcms-props="<path>.href|url|href">
|
|
8
|
+
* [<svg class="bcms-btn-icon">]<span data-bcms-field="<path>.label">Label</span>[<svg class="bcms-btn-arrow">]
|
|
9
|
+
* </a>
|
|
10
|
+
*
|
|
11
|
+
* Style it by `data-variant` (primary · secondary · tertiary · brand · dark · light · outline ·
|
|
12
|
+
* link) and `data-size` (sm · md · lg) in your own CSS: the editor repaints those attributes as the
|
|
13
|
+
* author picks, and publishing writes them into the live page, so your stylesheet decides what a
|
|
14
|
+
* look looks like. `class` is passed through untouched.
|
|
15
|
+
*
|
|
16
|
+
* <BcmsButton path="hero.cta" value={page.hero.cta} class="btn" />
|
|
17
|
+
*/
|
|
18
|
+
import { formatPropsAttribute, readButtonValue, buttonIconSvg } from "@bettercms-ai/types";
|
|
19
|
+
|
|
20
|
+
interface Props {
|
|
21
|
+
/** The field path in the editor grammar, e.g. `cta` or `hero.cta`. */
|
|
22
|
+
path: string;
|
|
23
|
+
/** The stored value. Missing keys render as the defaults (Primary, medium, no arrow, no icon). */
|
|
24
|
+
value: unknown;
|
|
25
|
+
class?: string;
|
|
26
|
+
}
|
|
27
|
+
const { path, value, class: className } = Astro.props;
|
|
28
|
+
const b = readButtonValue(value);
|
|
29
|
+
---
|
|
30
|
+
{b.label && (
|
|
31
|
+
<a
|
|
32
|
+
class={className}
|
|
33
|
+
href={b.href || "#"}
|
|
34
|
+
data-bcms-button={path}
|
|
35
|
+
data-variant={b.variant}
|
|
36
|
+
data-size={b.size}
|
|
37
|
+
data-bcms-props={formatPropsAttribute([{ address: `${path}.href`, kind: "url", attr: "href" }])}
|
|
38
|
+
{...(b.newTab ? { target: "_blank", rel: "noopener noreferrer" } : {})}
|
|
39
|
+
>
|
|
40
|
+
{b.icon && <Fragment set:html={buttonIconSvg(b.icon, "bcms-btn-icon")} />}
|
|
41
|
+
<span data-bcms-field={`${path}.label`} data-bcms-kind="text">{b.label}</span>
|
|
42
|
+
{b.arrow && <Fragment set:html={buttonIconSvg("arrow-right", "bcms-btn-arrow")} />}
|
|
43
|
+
</a>
|
|
44
|
+
)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bettercms-ai/astro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.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",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"./components/BcmsBlocks.astro": "./components/BcmsBlocks.astro",
|
|
34
34
|
"./components/BcmsLiveBlocks.astro": "./components/BcmsLiveBlocks.astro",
|
|
35
35
|
"./components/BcmsField.astro": "./components/BcmsField.astro",
|
|
36
|
+
"./components/BcmsButton.astro": "./components/BcmsButton.astro",
|
|
36
37
|
"./components/BcmsForm.astro": "./components/BcmsForm.astro",
|
|
37
38
|
"./components/BcmsSearch.astro": "./components/BcmsSearch.astro",
|
|
38
39
|
"./components/BcmsImage.astro": "./components/BcmsImage.astro",
|
|
@@ -54,11 +55,11 @@
|
|
|
54
55
|
},
|
|
55
56
|
"dependencies": {
|
|
56
57
|
"@bettercms-ai/image-url": "^0.3.0",
|
|
57
|
-
"@bettercms-ai/next": "^0.
|
|
58
|
+
"@bettercms-ai/next": "^0.17.0",
|
|
58
59
|
"@bettercms-ai/richtext": "^0.7.0",
|
|
59
60
|
"@bettercms-ai/sdk": "^1.24.0",
|
|
60
|
-
"@bettercms-ai/types": "^1.
|
|
61
|
-
"@bettercms-ai/ui": "^0.
|
|
61
|
+
"@bettercms-ai/types": "^1.27.0",
|
|
62
|
+
"@bettercms-ai/ui": "^0.12.0",
|
|
62
63
|
"libphonenumber-js": "^1.13.13"
|
|
63
64
|
},
|
|
64
65
|
"peerDependencies": {
|