monto-email-core 0.0.3 → 0.0.5

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.
@@ -38,6 +38,7 @@ export declare const ReaderBlockSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"ty
38
38
  } | null | undefined;
39
39
  }>>>;
40
40
  props: z.ZodNullable<z.ZodOptional<z.ZodObject<{
41
+ columnsCount: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
41
42
  columns: z.ZodArray<z.ZodObject<{
42
43
  childrenIds: z.ZodArray<z.ZodString, "many">;
43
44
  }, "strip", z.ZodTypeAny, {
@@ -45,24 +46,23 @@ export declare const ReaderBlockSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"ty
45
46
  }, {
46
47
  childrenIds: string[];
47
48
  }>, "many">;
48
- fixedWidths: z.ZodNullable<z.ZodOptional<z.ZodTuple<[z.ZodOptional<z.ZodNullable<z.ZodNumber>>, z.ZodOptional<z.ZodNullable<z.ZodNumber>>, z.ZodOptional<z.ZodNullable<z.ZodNumber>>], null>>>;
49
- columnsCount: z.ZodNullable<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<2>, z.ZodLiteral<3>]>>>;
49
+ fixedWidths: z.ZodNullable<z.ZodOptional<z.ZodTuple<[z.ZodOptional<z.ZodNullable<z.ZodNumber>>, z.ZodOptional<z.ZodNullable<z.ZodNumber>>, z.ZodOptional<z.ZodNullable<z.ZodNumber>>, z.ZodOptional<z.ZodNullable<z.ZodNumber>>], null>>>;
50
50
  columnsGap: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
51
51
  contentAlignment: z.ZodNullable<z.ZodOptional<z.ZodEnum<["top", "middle", "bottom"]>>>;
52
52
  }, "strip", z.ZodTypeAny, {
53
53
  columns: {
54
54
  childrenIds: string[];
55
55
  }[];
56
- fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
57
- columnsCount?: 2 | 3 | null | undefined;
56
+ columnsCount?: number | null | undefined;
57
+ fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
58
58
  columnsGap?: number | null | undefined;
59
59
  contentAlignment?: "top" | "middle" | "bottom" | null | undefined;
60
60
  }, {
61
61
  columns: {
62
62
  childrenIds: string[];
63
63
  }[];
64
- fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
65
- columnsCount?: 2 | 3 | null | undefined;
64
+ columnsCount?: number | null | undefined;
65
+ fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
66
66
  columnsGap?: number | null | undefined;
67
67
  contentAlignment?: "top" | "middle" | "bottom" | null | undefined;
68
68
  }>>>;
@@ -80,8 +80,8 @@ export declare const ReaderBlockSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"ty
80
80
  columns: {
81
81
  childrenIds: string[];
82
82
  }[];
83
- fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
84
- columnsCount?: 2 | 3 | null | undefined;
83
+ columnsCount?: number | null | undefined;
84
+ fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
85
85
  columnsGap?: number | null | undefined;
86
86
  contentAlignment?: "top" | "middle" | "bottom" | null | undefined;
87
87
  } | null | undefined;
@@ -99,8 +99,8 @@ export declare const ReaderBlockSchema: z.ZodEffects<z.ZodDiscriminatedUnion<"ty
99
99
  columns: {
100
100
  childrenIds: string[];
101
101
  }[];
102
- fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
103
- columnsCount?: 2 | 3 | null | undefined;
102
+ columnsCount?: number | null | undefined;
103
+ fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
104
104
  columnsGap?: number | null | undefined;
105
105
  contentAlignment?: "top" | "middle" | "bottom" | null | undefined;
106
106
  } | null | undefined;
@@ -1052,6 +1052,7 @@ export declare const ReaderDocumentSchema: z.ZodRecord<z.ZodString, z.ZodEffects
1052
1052
  } | null | undefined;
1053
1053
  }>>>;
1054
1054
  props: z.ZodNullable<z.ZodOptional<z.ZodObject<{
1055
+ columnsCount: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
1055
1056
  columns: z.ZodArray<z.ZodObject<{
1056
1057
  childrenIds: z.ZodArray<z.ZodString, "many">;
1057
1058
  }, "strip", z.ZodTypeAny, {
@@ -1059,24 +1060,23 @@ export declare const ReaderDocumentSchema: z.ZodRecord<z.ZodString, z.ZodEffects
1059
1060
  }, {
1060
1061
  childrenIds: string[];
1061
1062
  }>, "many">;
1062
- fixedWidths: z.ZodNullable<z.ZodOptional<z.ZodTuple<[z.ZodOptional<z.ZodNullable<z.ZodNumber>>, z.ZodOptional<z.ZodNullable<z.ZodNumber>>, z.ZodOptional<z.ZodNullable<z.ZodNumber>>], null>>>;
1063
- columnsCount: z.ZodNullable<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<2>, z.ZodLiteral<3>]>>>;
1063
+ fixedWidths: z.ZodNullable<z.ZodOptional<z.ZodTuple<[z.ZodOptional<z.ZodNullable<z.ZodNumber>>, z.ZodOptional<z.ZodNullable<z.ZodNumber>>, z.ZodOptional<z.ZodNullable<z.ZodNumber>>, z.ZodOptional<z.ZodNullable<z.ZodNumber>>], null>>>;
1064
1064
  columnsGap: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
1065
1065
  contentAlignment: z.ZodNullable<z.ZodOptional<z.ZodEnum<["top", "middle", "bottom"]>>>;
1066
1066
  }, "strip", z.ZodTypeAny, {
1067
1067
  columns: {
1068
1068
  childrenIds: string[];
1069
1069
  }[];
1070
- fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
1071
- columnsCount?: 2 | 3 | null | undefined;
1070
+ columnsCount?: number | null | undefined;
1071
+ fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
1072
1072
  columnsGap?: number | null | undefined;
1073
1073
  contentAlignment?: "top" | "middle" | "bottom" | null | undefined;
1074
1074
  }, {
1075
1075
  columns: {
1076
1076
  childrenIds: string[];
1077
1077
  }[];
1078
- fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
1079
- columnsCount?: 2 | 3 | null | undefined;
1078
+ columnsCount?: number | null | undefined;
1079
+ fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
1080
1080
  columnsGap?: number | null | undefined;
1081
1081
  contentAlignment?: "top" | "middle" | "bottom" | null | undefined;
1082
1082
  }>>>;
@@ -1094,8 +1094,8 @@ export declare const ReaderDocumentSchema: z.ZodRecord<z.ZodString, z.ZodEffects
1094
1094
  columns: {
1095
1095
  childrenIds: string[];
1096
1096
  }[];
1097
- fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
1098
- columnsCount?: 2 | 3 | null | undefined;
1097
+ columnsCount?: number | null | undefined;
1098
+ fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
1099
1099
  columnsGap?: number | null | undefined;
1100
1100
  contentAlignment?: "top" | "middle" | "bottom" | null | undefined;
1101
1101
  } | null | undefined;
@@ -1113,8 +1113,8 @@ export declare const ReaderDocumentSchema: z.ZodRecord<z.ZodString, z.ZodEffects
1113
1113
  columns: {
1114
1114
  childrenIds: string[];
1115
1115
  }[];
1116
- fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
1117
- columnsCount?: 2 | 3 | null | undefined;
1116
+ columnsCount?: number | null | undefined;
1117
+ fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
1118
1118
  columnsGap?: number | null | undefined;
1119
1119
  contentAlignment?: "top" | "middle" | "bottom" | null | undefined;
1120
1120
  } | null | undefined;
@@ -36,6 +36,7 @@ declare const ColumnsContainerPropsSchema: z.ZodObject<{
36
36
  } | null | undefined;
37
37
  }>>>;
38
38
  props: z.ZodNullable<z.ZodOptional<z.ZodObject<{
39
+ columnsCount: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
39
40
  columns: z.ZodArray<z.ZodObject<{
40
41
  childrenIds: z.ZodArray<z.ZodString, "many">;
41
42
  }, "strip", z.ZodTypeAny, {
@@ -43,24 +44,23 @@ declare const ColumnsContainerPropsSchema: z.ZodObject<{
43
44
  }, {
44
45
  childrenIds: string[];
45
46
  }>, "many">;
46
- fixedWidths: z.ZodNullable<z.ZodOptional<z.ZodTuple<[z.ZodOptional<z.ZodNullable<z.ZodNumber>>, z.ZodOptional<z.ZodNullable<z.ZodNumber>>, z.ZodOptional<z.ZodNullable<z.ZodNumber>>], null>>>;
47
- columnsCount: z.ZodNullable<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<2>, z.ZodLiteral<3>]>>>;
47
+ fixedWidths: z.ZodNullable<z.ZodOptional<z.ZodTuple<[z.ZodOptional<z.ZodNullable<z.ZodNumber>>, z.ZodOptional<z.ZodNullable<z.ZodNumber>>, z.ZodOptional<z.ZodNullable<z.ZodNumber>>, z.ZodOptional<z.ZodNullable<z.ZodNumber>>], null>>>;
48
48
  columnsGap: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
49
49
  contentAlignment: z.ZodNullable<z.ZodOptional<z.ZodEnum<["top", "middle", "bottom"]>>>;
50
50
  }, "strip", z.ZodTypeAny, {
51
51
  columns: {
52
52
  childrenIds: string[];
53
53
  }[];
54
- fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
55
- columnsCount?: 2 | 3 | null | undefined;
54
+ columnsCount?: number | null | undefined;
55
+ fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
56
56
  columnsGap?: number | null | undefined;
57
57
  contentAlignment?: "top" | "middle" | "bottom" | null | undefined;
58
58
  }, {
59
59
  columns: {
60
60
  childrenIds: string[];
61
61
  }[];
62
- fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
63
- columnsCount?: 2 | 3 | null | undefined;
62
+ columnsCount?: number | null | undefined;
63
+ fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
64
64
  columnsGap?: number | null | undefined;
65
65
  contentAlignment?: "top" | "middle" | "bottom" | null | undefined;
66
66
  }>>>;
@@ -78,8 +78,8 @@ declare const ColumnsContainerPropsSchema: z.ZodObject<{
78
78
  columns: {
79
79
  childrenIds: string[];
80
80
  }[];
81
- fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
82
- columnsCount?: 2 | 3 | null | undefined;
81
+ columnsCount?: number | null | undefined;
82
+ fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
83
83
  columnsGap?: number | null | undefined;
84
84
  contentAlignment?: "top" | "middle" | "bottom" | null | undefined;
85
85
  } | null | undefined;
@@ -97,8 +97,8 @@ declare const ColumnsContainerPropsSchema: z.ZodObject<{
97
97
  columns: {
98
98
  childrenIds: string[];
99
99
  }[];
100
- fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
101
- columnsCount?: 2 | 3 | null | undefined;
100
+ columnsCount?: number | null | undefined;
101
+ fixedWidths?: [number | null | undefined, number | null | undefined, number | null | undefined, number | null | undefined] | null | undefined;
102
102
  columnsGap?: number | null | undefined;
103
103
  contentAlignment?: "top" | "middle" | "bottom" | null | undefined;
104
104
  } | null | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"ColumnsContainerPropsSchema.d.ts","sourceRoot":"","sources":["../../../src/blocks/ColumnsContainer/ColumnsContainerPropsSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,QAAA,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAW/B,CAAC;AAEH,eAAe,2BAA2B,CAAC;AAC3C,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC"}
1
+ {"version":3,"file":"ColumnsContainerPropsSchema.d.ts","sourceRoot":"","sources":["../../../src/blocks/ColumnsContainer/ColumnsContainerPropsSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,QAAA,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmB/B,CAAC;AAEH,eAAe,2BAA2B,CAAC;AAC3C,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC"}
@@ -4,7 +4,15 @@ const BasePropsShape = BaseColumnsContainerPropsSchema.shape.props.unwrap().unwr
4
4
  const ColumnsContainerPropsSchema = z.object({
5
5
  style: BaseColumnsContainerPropsSchema.shape.style,
6
6
  props: z
7
- .object(Object.assign(Object.assign({}, BasePropsShape), { columns: z.array(z.object({ childrenIds: z.array(z.string()) })) }))
7
+ .object(Object.assign(Object.assign({}, BasePropsShape), { columnsCount: z.number().min(1).max(4).optional().nullable(), columns: z.array(z.object({ childrenIds: z.array(z.string()) })).min(1).max(4), fixedWidths: z
8
+ .tuple([
9
+ z.number().nullable().optional(),
10
+ z.number().nullable().optional(),
11
+ z.number().nullable().optional(),
12
+ z.number().nullable().optional(),
13
+ ])
14
+ .optional()
15
+ .nullable() }))
8
16
  .optional()
9
17
  .nullable(),
10
18
  });
@@ -1 +1 @@
1
- {"version":3,"file":"ColumnsContainerReader.d.ts","sourceRoot":"","sources":["../../../src/blocks/ColumnsContainer/ColumnsContainerReader.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,qBAAqB,qBAQrF"}
1
+ {"version":3,"file":"ColumnsContainerReader.d.ts","sourceRoot":"","sources":["../../../src/blocks/ColumnsContainer/ColumnsContainerReader.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,qBAAqB,qBA+FrF"}
@@ -13,10 +13,61 @@ import React from 'react';
13
13
  import { ColumnsContainer as BaseColumnsContainer } from '@usewaypoint/block-columns-container';
14
14
  import { ReaderBlock } from '../../Reader/core';
15
15
  export default function ColumnsContainerReader({ style, props }) {
16
- const _a = props !== null && props !== void 0 ? props : {}, { columns } = _a, restProps = __rest(_a, ["columns"]);
16
+ var _a, _b, _c;
17
+ const _d = props !== null && props !== void 0 ? props : {}, { columns, columnsCount } = _d, restProps = __rest(_d, ["columns", "columnsCount"]);
18
+ const count = columnsCount !== null && columnsCount !== void 0 ? columnsCount : ((_a = columns === null || columns === void 0 ? void 0 : columns.length) !== null && _a !== void 0 ? _a : 3);
17
19
  let cols = undefined;
18
20
  if (columns) {
19
21
  cols = columns.map((col) => col.childrenIds.map((childId) => React.createElement(ReaderBlock, { key: childId, id: childId })));
20
22
  }
21
- return React.createElement(BaseColumnsContainer, { props: restProps, columns: cols, style: style });
23
+ // BaseColumnsContainer 只支持 2 3 列,对于 1 4 列,我们需要自定义渲染
24
+ if (count === 1 || count === 4) {
25
+ const columnsGap = (restProps && 'columnsGap' in restProps) ? (_b = restProps.columnsGap) !== null && _b !== void 0 ? _b : 0 : 0;
26
+ const contentAlignment = (restProps && 'contentAlignment' in restProps) ? (_c = restProps.contentAlignment) !== null && _c !== void 0 ? _c : 'middle' : 'middle';
27
+ const fixedWidths = (restProps && 'fixedWidths' in restProps) ? restProps.fixedWidths : undefined;
28
+ // 计算列宽
29
+ const getColumnWidth = (index) => {
30
+ if (fixedWidths && fixedWidths[index] !== null && fixedWidths[index] !== undefined) {
31
+ return `${fixedWidths[index]}%`;
32
+ }
33
+ return count === 1 ? '100%' : '25%';
34
+ };
35
+ // 对于HTML邮件,使用table布局
36
+ const paddingStyle = (style === null || style === void 0 ? void 0 : style.padding)
37
+ ? {
38
+ paddingTop: `${style.padding.top}px`,
39
+ paddingRight: `${style.padding.right}px`,
40
+ paddingBottom: `${style.padding.bottom}px`,
41
+ paddingLeft: `${style.padding.left}px`,
42
+ }
43
+ : {};
44
+ const backgroundColorStyle = (style === null || style === void 0 ? void 0 : style.backgroundColor)
45
+ ? { backgroundColor: style.backgroundColor }
46
+ : {};
47
+ return (React.createElement("table", { role: "presentation", cellSpacing: "0", cellPadding: "0", border: 0, width: "100%", style: Object.assign(Object.assign({ width: '100%' }, paddingStyle), backgroundColorStyle) },
48
+ React.createElement("tbody", null,
49
+ React.createElement("tr", null, cols === null || cols === void 0 ? void 0 : cols.map((col, index) => (React.createElement("td", { key: index, width: getColumnWidth(index), style: {
50
+ width: getColumnWidth(index),
51
+ verticalAlign: contentAlignment === 'top' ? 'top' : contentAlignment === 'bottom' ? 'bottom' : 'middle',
52
+ paddingLeft: index > 0 ? `${columnsGap / 2}px` : '0',
53
+ paddingRight: index < (count - 1) ? `${columnsGap / 2}px` : '0',
54
+ } }, col)))))));
55
+ }
56
+ // 对于 2 或 3 列,使用 BaseColumnsContainer
57
+ // 需要过滤掉 fixedWidths 的第4个元素(如果存在)
58
+ let baseFixedWidths = undefined;
59
+ if (restProps && 'fixedWidths' in restProps && restProps.fixedWidths) {
60
+ baseFixedWidths = [restProps.fixedWidths[0], restProps.fixedWidths[1], restProps.fixedWidths[2]];
61
+ }
62
+ // 创建不包含 fixedWidths 的 baseProps
63
+ const baseProps = Object.assign(Object.assign({}, (restProps && typeof restProps === 'object' ? restProps : {})), { columnsCount: count });
64
+ // 如果有 fixedWidths,只取前3个元素
65
+ if (baseFixedWidths !== undefined) {
66
+ baseProps.fixedWidths = baseFixedWidths;
67
+ }
68
+ else if (restProps && 'fixedWidths' in restProps) {
69
+ // 如果原 fixedWidths 是 null 或 undefined,也传递 null
70
+ baseProps.fixedWidths = null;
71
+ }
72
+ return React.createElement(BaseColumnsContainer, { props: baseProps, columns: cols, style: style });
22
73
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monto-email-core",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "React component to render email messages",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",