@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 +47 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +48 -9
- package/dist/index.js.map +1 -1
- package/package.json +10 -2
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ButtonDefaults, DividerDefaults, HeadingDefaults, HtmlDefaults, ImageDefaults, MenuDefaults, ParagraphDefaults, SocialDefaults, TableDefaults, VideoDefaults, BodyDefaults, RowDefaults, ColumnDefaults, ButtonExporters, DividerExporters, HeadingExporters, HtmlExporters, ImageExporters, MenuExporters, ParagraphExporters, SocialExporters, TableExporters, VideoExporters, schemaVersion as schemaVersion$1, RowExporters, ColumnExporters, BodyExporters, heads } from '@unlayer/exporters';
|
|
1
|
+
import { ButtonDefaults, DividerDefaults, HeadingDefaults, HtmlDefaults, ImageDefaults, MenuDefaults, ParagraphDefaults, SocialDefaults, TableDefaults, VideoDefaults, BodyDefaults, RowDefaults, ColumnDefaults, ButtonExporters, DividerExporters, HeadingExporters, HtmlExporters, ImageExporters, MenuExporters, ParagraphExporters, SocialExporters, TableExporters, VideoExporters, schemaVersion as schemaVersion$1, RowExporters, ContentExporters, ColumnExporters, BodyExporters, heads } from '@unlayer/exporters';
|
|
2
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
3
|
import React, { useMemo, useContext, createContext } from 'react';
|
|
4
4
|
import ReactDOMServer, { renderToStaticMarkup } from 'react-dom/server';
|
|
@@ -904,13 +904,23 @@ ${widths.map(({ value, className }) => ` .no-stack .u-col-${className} { width:
|
|
|
904
904
|
}`;
|
|
905
905
|
return baseCSS + "\n" + columnCSS + "\n" + responsiveCSS;
|
|
906
906
|
}
|
|
907
|
+
function toContentWidthPx(bodyValues, fallback = 500) {
|
|
908
|
+
const raw = bodyValues?.contentWidth;
|
|
909
|
+
if (typeof raw === "number" && Number.isFinite(raw)) return raw;
|
|
910
|
+
if (typeof raw === "string") {
|
|
911
|
+
const n = parseInt(raw, 10);
|
|
912
|
+
if (Number.isFinite(n)) return n;
|
|
913
|
+
}
|
|
914
|
+
return fallback;
|
|
915
|
+
}
|
|
907
916
|
function renderRowToHtml(innerHTML, values, bodyValues, mode, cells, collection = "rows") {
|
|
908
917
|
const rowExporter = RowExporters[mode] || RowExporters.web;
|
|
909
918
|
const html = rowExporter(innerHTML, values, bodyValues, {
|
|
910
919
|
collection,
|
|
911
920
|
variant: mode
|
|
912
921
|
});
|
|
913
|
-
const
|
|
922
|
+
const contentWidth = toContentWidthPx(bodyValues);
|
|
923
|
+
const css = generateGridCSS(cells, mode, contentWidth);
|
|
914
924
|
return css ? `<style>${css}</style>${html}` : html;
|
|
915
925
|
}
|
|
916
926
|
function processChildren(children, cells, bodyValues, rowValues, mode, _config) {
|
|
@@ -1008,11 +1018,16 @@ var Row = (props) => {
|
|
|
1008
1018
|
};
|
|
1009
1019
|
Row.displayName = "Row";
|
|
1010
1020
|
var Row_default = Row;
|
|
1021
|
+
var DEFAULT_CONTAINER_PADDING = "10px";
|
|
1011
1022
|
var DEFAULT_VALUES12 = COLUMN_DEFAULTS;
|
|
1012
1023
|
function renderColumnToHtml(innerHTML, values, index, cells, bodyValues, rowValues, mode) {
|
|
1013
1024
|
const columnExporter = ColumnExporters[mode] || ColumnExporters.web;
|
|
1014
1025
|
return columnExporter(innerHTML, values, index, cells, bodyValues, rowValues);
|
|
1015
1026
|
}
|
|
1027
|
+
function renderContentToHtml(innerHTML, values, bodyValues, mode) {
|
|
1028
|
+
const contentExporter = ContentExporters[mode] || ContentExporters.web;
|
|
1029
|
+
return contentExporter(innerHTML, values, bodyValues, {});
|
|
1030
|
+
}
|
|
1016
1031
|
var Column = (props) => {
|
|
1017
1032
|
const {
|
|
1018
1033
|
children,
|
|
@@ -1055,10 +1070,22 @@ var Column = (props) => {
|
|
|
1055
1070
|
if (rendered && typeof rendered === "object" && rendered.props && rendered.props.dangerouslySetInnerHTML) {
|
|
1056
1071
|
const componentHTML = rendered.props.dangerouslySetInnerHTML.__html;
|
|
1057
1072
|
const componentType = child.type;
|
|
1058
|
-
const componentName = componentType?.displayName || componentType?.name || "component";
|
|
1059
|
-
const
|
|
1060
|
-
const containerPadding =
|
|
1061
|
-
|
|
1073
|
+
const componentName = (componentType?.displayName || componentType?.name || "component").toLowerCase();
|
|
1074
|
+
const childProps = child.props;
|
|
1075
|
+
const containerPadding = childProps.containerPadding ?? childProps.values?.containerPadding ?? DEFAULT_CONTAINER_PADDING;
|
|
1076
|
+
const contentValues = {
|
|
1077
|
+
containerPadding,
|
|
1078
|
+
_meta: {
|
|
1079
|
+
htmlID: `u_content_${componentName}_${childIndex + 1}`,
|
|
1080
|
+
htmlClassNames: `u_content_${componentName}`
|
|
1081
|
+
}
|
|
1082
|
+
};
|
|
1083
|
+
innerHTML += renderContentToHtml(
|
|
1084
|
+
componentHTML,
|
|
1085
|
+
contentValues,
|
|
1086
|
+
bodyValues,
|
|
1087
|
+
mode
|
|
1088
|
+
);
|
|
1062
1089
|
} else if (rendered) {
|
|
1063
1090
|
const name = child.type?.displayName || child.type?.name || "Unknown";
|
|
1064
1091
|
console.warn(
|
|
@@ -1120,7 +1147,13 @@ function renderBodyToHtml(innerHTML, values, mode, previewText) {
|
|
|
1120
1147
|
}
|
|
1121
1148
|
}
|
|
1122
1149
|
const bodyExporter = BodyExporters[mode] || BodyExporters.web;
|
|
1123
|
-
const raw = mode === "document" ? bodyExporter(finalInnerHtml, values, { type: "" }) :
|
|
1150
|
+
const raw = mode === "document" ? bodyExporter(finalInnerHtml, values, { type: "" }) : mode === "email" ? (
|
|
1151
|
+
// The email body exporter reads body context (contentWidth,
|
|
1152
|
+
// contentAlign) from the `bodyValues` field of its 3rd argument.
|
|
1153
|
+
// Passing `values` directly left it undefined, so the Outlook (MSO)
|
|
1154
|
+
// table fell back to 600px regardless of contentWidth.
|
|
1155
|
+
bodyExporter(finalInnerHtml, values, { bodyValues: values })
|
|
1156
|
+
) : bodyExporter(finalInnerHtml, values, values);
|
|
1124
1157
|
return raw.replace("min-height: 100vh; ", "").replace("min-height: 100vh;", "");
|
|
1125
1158
|
}
|
|
1126
1159
|
var Body = (props) => {
|
|
@@ -1128,7 +1161,10 @@ var Body = (props) => {
|
|
|
1128
1161
|
const resolvedConfig = { ...DEFAULT_CONFIG, ...configProp };
|
|
1129
1162
|
const mode = modeProp ?? resolvedConfig.mode ?? "web";
|
|
1130
1163
|
const _config = { ...resolvedConfig, mode };
|
|
1131
|
-
const values =
|
|
1164
|
+
const values = mergeValues(
|
|
1165
|
+
DEFAULT_VALUES13,
|
|
1166
|
+
mapSemanticProps(semanticProps, DEFAULT_VALUES13, "Body")
|
|
1167
|
+
);
|
|
1132
1168
|
const valuesWithMeta = {
|
|
1133
1169
|
...values,
|
|
1134
1170
|
_meta: {
|
|
@@ -1141,7 +1177,10 @@ var Body = (props) => {
|
|
|
1141
1177
|
if (children) {
|
|
1142
1178
|
enrichedChildren = React.Children.map(children, (child) => {
|
|
1143
1179
|
if (React.isValidElement(child)) {
|
|
1144
|
-
return React.cloneElement(child, {
|
|
1180
|
+
return React.cloneElement(child, {
|
|
1181
|
+
_config,
|
|
1182
|
+
bodyValues: values
|
|
1183
|
+
});
|
|
1145
1184
|
}
|
|
1146
1185
|
return child;
|
|
1147
1186
|
});
|