@bettercms-ai/ui 0.14.0 → 0.15.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/index.js +31 -17
- package/dist/index.js.map +1 -1
- package/dist/renderer.d.ts +10 -2
- package/dist/renderer.js +31 -17
- package/dist/renderer.js.map +1 -1
- package/dist/resolve.d.ts +4 -3
- package/dist/resolve.js +13 -2
- package/dist/resolve.js.map +1 -1
- package/package.json +2 -2
package/dist/renderer.d.ts
CHANGED
|
@@ -8,14 +8,22 @@ interface BlockRendererProps {
|
|
|
8
8
|
renderBlock?: (block: ContentBlock) => React.ReactNode;
|
|
9
9
|
/** Emit visual-editor field bindings. Default-off keeps published consumers clean. */
|
|
10
10
|
annotate?: boolean;
|
|
11
|
+
/** The instant block windows are read against. Internal: `BlocksRenderer` passes it when annotating. */
|
|
12
|
+
stampAt?: Date;
|
|
11
13
|
}
|
|
12
|
-
declare function BlockRenderer({ block, className, renderBlock, annotate, }: BlockRendererProps): react_jsx_runtime.JSX.Element;
|
|
14
|
+
declare function BlockRenderer({ block, className, renderBlock, annotate, stampAt, }: BlockRendererProps): react_jsx_runtime.JSX.Element;
|
|
13
15
|
interface BlocksRendererProps {
|
|
14
16
|
blocks: ContentBlock[];
|
|
15
17
|
className?: string;
|
|
16
18
|
renderBlock?: (block: ContentBlock) => React.ReactNode;
|
|
17
19
|
annotate?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The instant block windows (`block.window`) are read against. Defaults to the render time.
|
|
22
|
+
* A block outside its window is not rendered, at any depth; with `annotate` it is rendered and
|
|
23
|
+
* marked `data-bcms-window="pending|expired"` instead.
|
|
24
|
+
*/
|
|
25
|
+
now?: Date;
|
|
18
26
|
}
|
|
19
|
-
declare function BlocksRenderer({ blocks, className, renderBlock, annotate, }: BlocksRendererProps): react_jsx_runtime.JSX.Element | null;
|
|
27
|
+
declare function BlocksRenderer({ blocks: all, className, renderBlock, annotate, now, }: BlocksRendererProps): react_jsx_runtime.JSX.Element | null;
|
|
20
28
|
|
|
21
29
|
export { BlockRenderer, BlocksRenderer };
|
package/dist/renderer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
// src/renderer.tsx
|
|
4
|
-
import { splitButtonStyle } from "@bettercms-ai/types";
|
|
4
|
+
import { RESPONSIVE_CSS, hideOnAttr, splitButtonStyle, usesHideOn, visibleBlocks, windowState } from "@bettercms-ai/types";
|
|
5
5
|
|
|
6
6
|
// src/blocks/Heading.tsx
|
|
7
7
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -975,6 +975,12 @@ function styleOf(block) {
|
|
|
975
975
|
const { placement, paint } = splitButtonStyle(block.style);
|
|
976
976
|
return { wrapper: blockStyleToReactStyle(placement), paint: paint ? { style: paint } : {} };
|
|
977
977
|
}
|
|
978
|
+
function withHide(block, wrapperStyle, el, stampAt) {
|
|
979
|
+
const hide = hideOnAttr(block.style);
|
|
980
|
+
const state = stampAt ? windowState(block, stampAt) : "live";
|
|
981
|
+
if (!wrapperStyle && !hide && state === "live") return el;
|
|
982
|
+
return /* @__PURE__ */ jsx15("div", { style: wrapperStyle, ...hide ? { "data-bcms-hide": hide } : {}, ...state === "live" ? {} : { "data-bcms-window": state }, children: el });
|
|
983
|
+
}
|
|
978
984
|
function bindingProps(block, annotate) {
|
|
979
985
|
if (!annotate || !block.id) return {};
|
|
980
986
|
switch (block.type) {
|
|
@@ -990,7 +996,7 @@ function bindingProps(block, annotate) {
|
|
|
990
996
|
return {};
|
|
991
997
|
}
|
|
992
998
|
}
|
|
993
|
-
function resolveBlock(block, className, annotate = false) {
|
|
999
|
+
function resolveBlock(block, className, annotate = false, stampAt) {
|
|
994
1000
|
const entry = BLOCK_REGISTRY[block.type];
|
|
995
1001
|
if (!entry) {
|
|
996
1002
|
return /* @__PURE__ */ jsxs11(
|
|
@@ -1007,13 +1013,14 @@ function resolveBlock(block, className, annotate = false) {
|
|
|
1007
1013
|
const Component = entry.component;
|
|
1008
1014
|
const { wrapper: blockStyle, paint } = styleOf(block);
|
|
1009
1015
|
const el = /* @__PURE__ */ jsx15(Component, { ...block.props, ...paint, className, ...bindingProps(block, annotate) });
|
|
1010
|
-
return
|
|
1016
|
+
return withHide(block, blockStyle, el, stampAt);
|
|
1011
1017
|
}
|
|
1012
1018
|
function BlockRenderer({
|
|
1013
1019
|
block,
|
|
1014
1020
|
className = "",
|
|
1015
1021
|
renderBlock,
|
|
1016
|
-
annotate = false
|
|
1022
|
+
annotate = false,
|
|
1023
|
+
stampAt
|
|
1017
1024
|
}) {
|
|
1018
1025
|
const entry = BLOCK_REGISTRY[block.type];
|
|
1019
1026
|
if (!entry) {
|
|
@@ -1029,7 +1036,7 @@ function BlockRenderer({
|
|
|
1029
1036
|
);
|
|
1030
1037
|
}
|
|
1031
1038
|
const Component = entry.component;
|
|
1032
|
-
const containerProps = CONTAINER_TYPES.has(block.type) ? { renderBlock: renderBlock ?? ((child) => resolveBlock(child, void 0, annotate)) } : {};
|
|
1039
|
+
const containerProps = CONTAINER_TYPES.has(block.type) ? { renderBlock: renderBlock ?? ((child) => resolveBlock(child, void 0, annotate, stampAt)) } : {};
|
|
1033
1040
|
const { wrapper: blockStyle, paint } = styleOf(block);
|
|
1034
1041
|
const el = /* @__PURE__ */ jsx15(
|
|
1035
1042
|
Component,
|
|
@@ -1041,24 +1048,31 @@ function BlockRenderer({
|
|
|
1041
1048
|
...bindingProps(block, annotate)
|
|
1042
1049
|
}
|
|
1043
1050
|
);
|
|
1044
|
-
return
|
|
1051
|
+
return withHide(block, blockStyle, el, stampAt);
|
|
1045
1052
|
}
|
|
1046
1053
|
function BlocksRenderer({
|
|
1047
|
-
blocks,
|
|
1054
|
+
blocks: all,
|
|
1048
1055
|
className = "",
|
|
1049
1056
|
renderBlock,
|
|
1050
|
-
annotate = false
|
|
1057
|
+
annotate = false,
|
|
1058
|
+
now
|
|
1051
1059
|
}) {
|
|
1060
|
+
const at = now ?? /* @__PURE__ */ new Date();
|
|
1061
|
+
const blocks = annotate ? all : visibleBlocks(all, at);
|
|
1052
1062
|
if (blocks.length === 0) return null;
|
|
1053
|
-
return /* @__PURE__ */
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1063
|
+
return /* @__PURE__ */ jsxs11("div", { className, children: [
|
|
1064
|
+
usesHideOn(blocks) && /* @__PURE__ */ jsx15("style", { dangerouslySetInnerHTML: { __html: RESPONSIVE_CSS } }),
|
|
1065
|
+
blocks.map((block) => /* @__PURE__ */ jsx15(
|
|
1066
|
+
BlockRenderer,
|
|
1067
|
+
{
|
|
1068
|
+
block,
|
|
1069
|
+
renderBlock,
|
|
1070
|
+
annotate,
|
|
1071
|
+
stampAt: annotate ? at : void 0
|
|
1072
|
+
},
|
|
1073
|
+
block.id
|
|
1074
|
+
))
|
|
1075
|
+
] });
|
|
1062
1076
|
}
|
|
1063
1077
|
export {
|
|
1064
1078
|
BlockRenderer,
|