@unlayer/react-elements 0.1.8 → 0.1.9

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.cjs CHANGED
@@ -911,13 +911,23 @@ ${widths.map(({ value, className }) => ` .no-stack .u-col-${className} { width:
911
911
  }`;
912
912
  return baseCSS + "\n" + columnCSS + "\n" + responsiveCSS;
913
913
  }
914
+ function toContentWidthPx(bodyValues, fallback = 500) {
915
+ const raw = bodyValues?.contentWidth;
916
+ if (typeof raw === "number" && Number.isFinite(raw)) return raw;
917
+ if (typeof raw === "string") {
918
+ const n = parseInt(raw, 10);
919
+ if (Number.isFinite(n)) return n;
920
+ }
921
+ return fallback;
922
+ }
914
923
  function renderRowToHtml(innerHTML, values, bodyValues, mode, cells, collection = "rows") {
915
924
  const rowExporter = exporters.RowExporters[mode] || exporters.RowExporters.web;
916
925
  const html = rowExporter(innerHTML, values, bodyValues, {
917
926
  collection,
918
927
  variant: mode
919
928
  });
920
- const css = generateGridCSS(cells, mode);
929
+ const contentWidth = toContentWidthPx(bodyValues);
930
+ const css = generateGridCSS(cells, mode, contentWidth);
921
931
  return css ? `<style>${css}</style>${html}` : html;
922
932
  }
923
933
  function processChildren(children, cells, bodyValues, rowValues, mode, _config) {
@@ -1015,11 +1025,16 @@ var Row = (props) => {
1015
1025
  };
1016
1026
  Row.displayName = "Row";
1017
1027
  var Row_default = Row;
1028
+ var DEFAULT_CONTAINER_PADDING = "10px";
1018
1029
  var DEFAULT_VALUES12 = COLUMN_DEFAULTS;
1019
1030
  function renderColumnToHtml(innerHTML, values, index, cells, bodyValues, rowValues, mode) {
1020
1031
  const columnExporter = exporters.ColumnExporters[mode] || exporters.ColumnExporters.web;
1021
1032
  return columnExporter(innerHTML, values, index, cells, bodyValues, rowValues);
1022
1033
  }
1034
+ function renderContentToHtml(innerHTML, values, bodyValues, mode) {
1035
+ const contentExporter = exporters.ContentExporters[mode] || exporters.ContentExporters.web;
1036
+ return contentExporter(innerHTML, values, bodyValues, {});
1037
+ }
1023
1038
  var Column = (props) => {
1024
1039
  const {
1025
1040
  children,
@@ -1062,10 +1077,22 @@ var Column = (props) => {
1062
1077
  if (rendered && typeof rendered === "object" && rendered.props && rendered.props.dangerouslySetInnerHTML) {
1063
1078
  const componentHTML = rendered.props.dangerouslySetInnerHTML.__html;
1064
1079
  const componentType = child.type;
1065
- const componentName = componentType?.displayName || componentType?.name || "component";
1066
- const componentProps = child.props;
1067
- const containerPadding = componentProps.values?.containerPadding || DEFAULT_VALUES12.padding || "10px";
1068
- innerHTML += `<div id="u_content_${componentName.toLowerCase()}_${childIndex + 1}" class="u_content_${componentName.toLowerCase()}" style="padding: ${containerPadding};">${componentHTML}</div>`;
1080
+ const componentName = (componentType?.displayName || componentType?.name || "component").toLowerCase();
1081
+ const childProps = child.props;
1082
+ const containerPadding = childProps.containerPadding ?? childProps.values?.containerPadding ?? DEFAULT_CONTAINER_PADDING;
1083
+ const contentValues = {
1084
+ containerPadding,
1085
+ _meta: {
1086
+ htmlID: `u_content_${componentName}_${childIndex + 1}`,
1087
+ htmlClassNames: `u_content_${componentName}`
1088
+ }
1089
+ };
1090
+ innerHTML += renderContentToHtml(
1091
+ componentHTML,
1092
+ contentValues,
1093
+ bodyValues,
1094
+ mode
1095
+ );
1069
1096
  } else if (rendered) {
1070
1097
  const name = child.type?.displayName || child.type?.name || "Unknown";
1071
1098
  console.warn(
@@ -1127,7 +1154,13 @@ function renderBodyToHtml(innerHTML, values, mode, previewText) {
1127
1154
  }
1128
1155
  }
1129
1156
  const bodyExporter = exporters.BodyExporters[mode] || exporters.BodyExporters.web;
1130
- const raw = mode === "document" ? bodyExporter(finalInnerHtml, values, { type: "" }) : bodyExporter(finalInnerHtml, values, values);
1157
+ const raw = mode === "document" ? bodyExporter(finalInnerHtml, values, { type: "" }) : mode === "email" ? (
1158
+ // The email body exporter reads body context (contentWidth,
1159
+ // contentAlign) from the `bodyValues` field of its 3rd argument.
1160
+ // Passing `values` directly left it undefined, so the Outlook (MSO)
1161
+ // table fell back to 600px regardless of contentWidth.
1162
+ bodyExporter(finalInnerHtml, values, { bodyValues: values })
1163
+ ) : bodyExporter(finalInnerHtml, values, values);
1131
1164
  return raw.replace("min-height: 100vh; ", "").replace("min-height: 100vh;", "");
1132
1165
  }
1133
1166
  var Body = (props) => {
@@ -1135,7 +1168,10 @@ var Body = (props) => {
1135
1168
  const resolvedConfig = { ...DEFAULT_CONFIG, ...configProp };
1136
1169
  const mode = modeProp ?? resolvedConfig.mode ?? "web";
1137
1170
  const _config = { ...resolvedConfig, mode };
1138
- const values = mapSemanticProps(semanticProps, DEFAULT_VALUES13, "Body");
1171
+ const values = mergeValues(
1172
+ DEFAULT_VALUES13,
1173
+ mapSemanticProps(semanticProps, DEFAULT_VALUES13, "Body")
1174
+ );
1139
1175
  const valuesWithMeta = {
1140
1176
  ...values,
1141
1177
  _meta: {
@@ -1148,7 +1184,10 @@ var Body = (props) => {
1148
1184
  if (children) {
1149
1185
  enrichedChildren = React__default.default.Children.map(children, (child) => {
1150
1186
  if (React__default.default.isValidElement(child)) {
1151
- return React__default.default.cloneElement(child, { _config });
1187
+ return React__default.default.cloneElement(child, {
1188
+ _config,
1189
+ bodyValues: values
1190
+ });
1152
1191
  }
1153
1192
  return child;
1154
1193
  });