@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 CHANGED
@@ -958,7 +958,7 @@ var BLOCK_REGISTRY = {
958
958
  var BLOCK_TYPES = Object.keys(BLOCK_REGISTRY);
959
959
 
960
960
  // src/renderer.tsx
961
- import { splitButtonStyle } from "@bettercms-ai/types";
961
+ import { RESPONSIVE_CSS, hideOnAttr, splitButtonStyle, usesHideOn, visibleBlocks, windowState } from "@bettercms-ai/types";
962
962
 
963
963
  // src/blockStyle.ts
964
964
  import { blockStyleToCss } from "@bettercms-ai/types";
@@ -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 blockStyle ? /* @__PURE__ */ jsx15("div", { style: blockStyle, children: el }) : el;
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 blockStyle ? /* @__PURE__ */ jsx15("div", { style: blockStyle, children: el }) : el;
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__ */ jsx15("div", { className, children: blocks.map((block) => /* @__PURE__ */ jsx15(
1054
- BlockRenderer,
1055
- {
1056
- block,
1057
- renderBlock,
1058
- annotate
1059
- },
1060
- block.id
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
  BLOCK_REGISTRY,