@bettercms-ai/next 0.24.0 → 0.26.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/README.md +40 -0
- package/dist/blocks.js +9 -1
- package/dist/blocks.js.map +1 -1
- package/dist/draft-bridge.js +9 -1
- package/dist/draft-bridge.js.map +1 -1
- package/dist/index.d.ts +114 -2
- package/dist/index.js +43 -7
- package/dist/index.js.map +1 -1
- package/dist/sections.d.ts +88 -0
- package/dist/sections.js +73 -0
- package/dist/sections.js.map +1 -0
- package/package.json +10 -5
package/dist/index.js
CHANGED
|
@@ -621,6 +621,33 @@ function getComponent(idOrSlug, path) {
|
|
|
621
621
|
);
|
|
622
622
|
}
|
|
623
623
|
|
|
624
|
+
// src/sections-read.ts
|
|
625
|
+
import { readPublishedContent } from "@bettercms-ai/sdk";
|
|
626
|
+
function pageRow(pages, page, read) {
|
|
627
|
+
const rows = (Array.isArray(pages) ? pages : []).filter((p) => p?.slug === page);
|
|
628
|
+
const template = rows.find((row) => row.template === true);
|
|
629
|
+
return read?.template ? template : rows.find((row) => row.template !== true) ?? rows[0];
|
|
630
|
+
}
|
|
631
|
+
function sectionsFor(page, read) {
|
|
632
|
+
const snapshot = readPublishedContent();
|
|
633
|
+
const row = pageRow(snapshot?.pages, page, read);
|
|
634
|
+
const blocks = row?.blocks ?? row?.blockJson;
|
|
635
|
+
return {
|
|
636
|
+
page,
|
|
637
|
+
blocks: Array.isArray(blocks) ? blocks : null,
|
|
638
|
+
components: Array.isArray(snapshot?.components) ? snapshot.components : [],
|
|
639
|
+
forms: Array.isArray(snapshot?.forms) ? snapshot.forms : []
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
function sectionsStaticProps(page, own, read) {
|
|
643
|
+
return async (context) => {
|
|
644
|
+
const answer = own ? await own(context) : { props: {} };
|
|
645
|
+
if (!answer || typeof answer !== "object" || !("props" in answer)) return answer;
|
|
646
|
+
return { ...answer, props: { ...await answer.props, bcmsSections: sectionsFor(page, read) } };
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
var sectionsServerSideProps = sectionsStaticProps;
|
|
650
|
+
|
|
624
651
|
// src/field.tsx
|
|
625
652
|
import { Children, cloneElement, isValidElement } from "react";
|
|
626
653
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -645,11 +672,20 @@ function BcmsField({ path, kind, as, children }) {
|
|
|
645
672
|
// src/button.tsx
|
|
646
673
|
import { formatPropsAttribute, readButtonValue } from "@bettercms-ai/types";
|
|
647
674
|
import { Icon } from "@bettercms-ai/icons/map";
|
|
648
|
-
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
675
|
+
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
676
|
+
var FULL_WIDTH_STYLE = { display: "flex", width: "100%", justifyContent: "center" };
|
|
649
677
|
function BcmsButton({ path, value, className }) {
|
|
650
678
|
const b = readButtonValue(value);
|
|
651
679
|
if (!b.label) return null;
|
|
652
|
-
|
|
680
|
+
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
681
|
+
b.icon && /* @__PURE__ */ jsx2(Icon, { symbol: b.icon, className: "bcms-btn-icon", "aria-hidden": true, focusable: "false" }),
|
|
682
|
+
/* @__PURE__ */ jsx2("span", { "data-bcms-field": `${path}.label`, "data-bcms-kind": "text", children: b.label }),
|
|
683
|
+
b.arrow && /* @__PURE__ */ jsx2(Icon, { symbol: "arrow-right", className: "bcms-btn-arrow", "aria-hidden": true, focusable: "false" })
|
|
684
|
+
] });
|
|
685
|
+
if (b.action === "code") {
|
|
686
|
+
return /* @__PURE__ */ jsx2("button", { type: "button", className, "data-bcms-button": path, "data-variant": b.variant, "data-size": b.size, ...b.fullWidth ? { "data-full-width": "", style: FULL_WIDTH_STYLE } : {}, children: content });
|
|
687
|
+
}
|
|
688
|
+
return /* @__PURE__ */ jsx2(
|
|
653
689
|
"a",
|
|
654
690
|
{
|
|
655
691
|
className,
|
|
@@ -657,13 +693,10 @@ function BcmsButton({ path, value, className }) {
|
|
|
657
693
|
"data-bcms-button": path,
|
|
658
694
|
"data-variant": b.variant,
|
|
659
695
|
"data-size": b.size,
|
|
696
|
+
...b.fullWidth ? { "data-full-width": "", style: FULL_WIDTH_STYLE } : {},
|
|
660
697
|
"data-bcms-props": formatPropsAttribute([{ address: `${path}.href`, kind: "url", attr: "href" }]),
|
|
661
698
|
...b.newTab ? { target: "_blank", rel: "noopener noreferrer" } : {},
|
|
662
|
-
children:
|
|
663
|
-
b.icon && /* @__PURE__ */ jsx2(Icon, { symbol: b.icon, className: "bcms-btn-icon", "aria-hidden": true, focusable: "false" }),
|
|
664
|
-
/* @__PURE__ */ jsx2("span", { "data-bcms-field": `${path}.label`, "data-bcms-kind": "text", children: b.label }),
|
|
665
|
-
b.arrow && /* @__PURE__ */ jsx2(Icon, { symbol: "arrow-right", className: "bcms-btn-arrow", "aria-hidden": true, focusable: "false" })
|
|
666
|
-
]
|
|
699
|
+
children: content
|
|
667
700
|
}
|
|
668
701
|
);
|
|
669
702
|
}
|
|
@@ -821,6 +854,9 @@ export {
|
|
|
821
854
|
resolveSeo2 as resolveSeo,
|
|
822
855
|
sectionColumnAttrs,
|
|
823
856
|
sectionRootAttrs,
|
|
857
|
+
sectionsFor,
|
|
858
|
+
sectionsServerSideProps,
|
|
859
|
+
sectionsStaticProps,
|
|
824
860
|
serializeSnapshot,
|
|
825
861
|
writeSnapshot
|
|
826
862
|
};
|