@csg-org/block-text 0.0.7-alpha.3 → 0.0.7-alpha.4

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.
@@ -0,0 +1,110 @@
1
+ import React from 'react';
2
+ import { z } from 'zod';
3
+
4
+ declare const TextPropsSchema: z.ZodObject<{
5
+ style: z.ZodNullable<z.ZodOptional<z.ZodObject<{
6
+ color: z.ZodOptional<z.ZodNullable<z.ZodString>>;
7
+ backgroundColor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8
+ fontSize: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
9
+ fontFamily: z.ZodOptional<z.ZodNullable<z.ZodEnum<["MODERN_SANS", "BOOK_SANS", "ORGANIC_SANS", "GEOMETRIC_SANS", "HEAVY_SANS", "ROUNDED_SANS", "MODERN_SERIF", "BOOK_SERIF", "MONOSPACE"]>>>;
10
+ fontWeight: z.ZodNullable<z.ZodOptional<z.ZodEnum<["bold", "normal"]>>>;
11
+ textAlign: z.ZodNullable<z.ZodOptional<z.ZodEnum<["left", "center", "right"]>>>;
12
+ padding: z.ZodNullable<z.ZodOptional<z.ZodObject<{
13
+ top: z.ZodNumber;
14
+ bottom: z.ZodNumber;
15
+ right: z.ZodNumber;
16
+ left: z.ZodNumber;
17
+ }, "strip", z.ZodTypeAny, {
18
+ top: number;
19
+ bottom: number;
20
+ right: number;
21
+ left: number;
22
+ }, {
23
+ top: number;
24
+ bottom: number;
25
+ right: number;
26
+ left: number;
27
+ }>>>;
28
+ }, "strip", z.ZodTypeAny, {
29
+ color?: string | null | undefined;
30
+ backgroundColor?: string | null | undefined;
31
+ fontSize?: number | null | undefined;
32
+ fontFamily?: "MODERN_SANS" | "BOOK_SANS" | "ORGANIC_SANS" | "GEOMETRIC_SANS" | "HEAVY_SANS" | "ROUNDED_SANS" | "MODERN_SERIF" | "BOOK_SERIF" | "MONOSPACE" | null | undefined;
33
+ fontWeight?: "bold" | "normal" | null | undefined;
34
+ textAlign?: "right" | "left" | "center" | null | undefined;
35
+ padding?: {
36
+ top: number;
37
+ bottom: number;
38
+ right: number;
39
+ left: number;
40
+ } | null | undefined;
41
+ }, {
42
+ color?: string | null | undefined;
43
+ backgroundColor?: string | null | undefined;
44
+ fontSize?: number | null | undefined;
45
+ fontFamily?: "MODERN_SANS" | "BOOK_SANS" | "ORGANIC_SANS" | "GEOMETRIC_SANS" | "HEAVY_SANS" | "ROUNDED_SANS" | "MODERN_SERIF" | "BOOK_SERIF" | "MONOSPACE" | null | undefined;
46
+ fontWeight?: "bold" | "normal" | null | undefined;
47
+ textAlign?: "right" | "left" | "center" | null | undefined;
48
+ padding?: {
49
+ top: number;
50
+ bottom: number;
51
+ right: number;
52
+ left: number;
53
+ } | null | undefined;
54
+ }>>>;
55
+ props: z.ZodNullable<z.ZodOptional<z.ZodObject<{
56
+ markdown: z.ZodNullable<z.ZodOptional<z.ZodBoolean>>;
57
+ text: z.ZodNullable<z.ZodOptional<z.ZodString>>;
58
+ }, "strip", z.ZodTypeAny, {
59
+ markdown?: boolean | null | undefined;
60
+ text?: string | null | undefined;
61
+ }, {
62
+ markdown?: boolean | null | undefined;
63
+ text?: string | null | undefined;
64
+ }>>>;
65
+ }, "strip", z.ZodTypeAny, {
66
+ style?: {
67
+ color?: string | null | undefined;
68
+ backgroundColor?: string | null | undefined;
69
+ fontSize?: number | null | undefined;
70
+ fontFamily?: "MODERN_SANS" | "BOOK_SANS" | "ORGANIC_SANS" | "GEOMETRIC_SANS" | "HEAVY_SANS" | "ROUNDED_SANS" | "MODERN_SERIF" | "BOOK_SERIF" | "MONOSPACE" | null | undefined;
71
+ fontWeight?: "bold" | "normal" | null | undefined;
72
+ textAlign?: "right" | "left" | "center" | null | undefined;
73
+ padding?: {
74
+ top: number;
75
+ bottom: number;
76
+ right: number;
77
+ left: number;
78
+ } | null | undefined;
79
+ } | null | undefined;
80
+ props?: {
81
+ markdown?: boolean | null | undefined;
82
+ text?: string | null | undefined;
83
+ } | null | undefined;
84
+ }, {
85
+ style?: {
86
+ color?: string | null | undefined;
87
+ backgroundColor?: string | null | undefined;
88
+ fontSize?: number | null | undefined;
89
+ fontFamily?: "MODERN_SANS" | "BOOK_SANS" | "ORGANIC_SANS" | "GEOMETRIC_SANS" | "HEAVY_SANS" | "ROUNDED_SANS" | "MODERN_SERIF" | "BOOK_SERIF" | "MONOSPACE" | null | undefined;
90
+ fontWeight?: "bold" | "normal" | null | undefined;
91
+ textAlign?: "right" | "left" | "center" | null | undefined;
92
+ padding?: {
93
+ top: number;
94
+ bottom: number;
95
+ right: number;
96
+ left: number;
97
+ } | null | undefined;
98
+ } | null | undefined;
99
+ props?: {
100
+ markdown?: boolean | null | undefined;
101
+ text?: string | null | undefined;
102
+ } | null | undefined;
103
+ }>;
104
+ type TextProps = z.infer<typeof TextPropsSchema>;
105
+ declare const TextPropsDefaults: {
106
+ text: string;
107
+ };
108
+ declare function Text({ style, props }: TextProps): React.JSX.Element;
109
+
110
+ export { Text, type TextProps, TextPropsDefaults, TextPropsSchema };
@@ -0,0 +1,110 @@
1
+ import React from 'react';
2
+ import { z } from 'zod';
3
+
4
+ declare const TextPropsSchema: z.ZodObject<{
5
+ style: z.ZodNullable<z.ZodOptional<z.ZodObject<{
6
+ color: z.ZodOptional<z.ZodNullable<z.ZodString>>;
7
+ backgroundColor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8
+ fontSize: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
9
+ fontFamily: z.ZodOptional<z.ZodNullable<z.ZodEnum<["MODERN_SANS", "BOOK_SANS", "ORGANIC_SANS", "GEOMETRIC_SANS", "HEAVY_SANS", "ROUNDED_SANS", "MODERN_SERIF", "BOOK_SERIF", "MONOSPACE"]>>>;
10
+ fontWeight: z.ZodNullable<z.ZodOptional<z.ZodEnum<["bold", "normal"]>>>;
11
+ textAlign: z.ZodNullable<z.ZodOptional<z.ZodEnum<["left", "center", "right"]>>>;
12
+ padding: z.ZodNullable<z.ZodOptional<z.ZodObject<{
13
+ top: z.ZodNumber;
14
+ bottom: z.ZodNumber;
15
+ right: z.ZodNumber;
16
+ left: z.ZodNumber;
17
+ }, "strip", z.ZodTypeAny, {
18
+ top: number;
19
+ bottom: number;
20
+ right: number;
21
+ left: number;
22
+ }, {
23
+ top: number;
24
+ bottom: number;
25
+ right: number;
26
+ left: number;
27
+ }>>>;
28
+ }, "strip", z.ZodTypeAny, {
29
+ color?: string | null | undefined;
30
+ backgroundColor?: string | null | undefined;
31
+ fontSize?: number | null | undefined;
32
+ fontFamily?: "MODERN_SANS" | "BOOK_SANS" | "ORGANIC_SANS" | "GEOMETRIC_SANS" | "HEAVY_SANS" | "ROUNDED_SANS" | "MODERN_SERIF" | "BOOK_SERIF" | "MONOSPACE" | null | undefined;
33
+ fontWeight?: "bold" | "normal" | null | undefined;
34
+ textAlign?: "right" | "left" | "center" | null | undefined;
35
+ padding?: {
36
+ top: number;
37
+ bottom: number;
38
+ right: number;
39
+ left: number;
40
+ } | null | undefined;
41
+ }, {
42
+ color?: string | null | undefined;
43
+ backgroundColor?: string | null | undefined;
44
+ fontSize?: number | null | undefined;
45
+ fontFamily?: "MODERN_SANS" | "BOOK_SANS" | "ORGANIC_SANS" | "GEOMETRIC_SANS" | "HEAVY_SANS" | "ROUNDED_SANS" | "MODERN_SERIF" | "BOOK_SERIF" | "MONOSPACE" | null | undefined;
46
+ fontWeight?: "bold" | "normal" | null | undefined;
47
+ textAlign?: "right" | "left" | "center" | null | undefined;
48
+ padding?: {
49
+ top: number;
50
+ bottom: number;
51
+ right: number;
52
+ left: number;
53
+ } | null | undefined;
54
+ }>>>;
55
+ props: z.ZodNullable<z.ZodOptional<z.ZodObject<{
56
+ markdown: z.ZodNullable<z.ZodOptional<z.ZodBoolean>>;
57
+ text: z.ZodNullable<z.ZodOptional<z.ZodString>>;
58
+ }, "strip", z.ZodTypeAny, {
59
+ markdown?: boolean | null | undefined;
60
+ text?: string | null | undefined;
61
+ }, {
62
+ markdown?: boolean | null | undefined;
63
+ text?: string | null | undefined;
64
+ }>>>;
65
+ }, "strip", z.ZodTypeAny, {
66
+ style?: {
67
+ color?: string | null | undefined;
68
+ backgroundColor?: string | null | undefined;
69
+ fontSize?: number | null | undefined;
70
+ fontFamily?: "MODERN_SANS" | "BOOK_SANS" | "ORGANIC_SANS" | "GEOMETRIC_SANS" | "HEAVY_SANS" | "ROUNDED_SANS" | "MODERN_SERIF" | "BOOK_SERIF" | "MONOSPACE" | null | undefined;
71
+ fontWeight?: "bold" | "normal" | null | undefined;
72
+ textAlign?: "right" | "left" | "center" | null | undefined;
73
+ padding?: {
74
+ top: number;
75
+ bottom: number;
76
+ right: number;
77
+ left: number;
78
+ } | null | undefined;
79
+ } | null | undefined;
80
+ props?: {
81
+ markdown?: boolean | null | undefined;
82
+ text?: string | null | undefined;
83
+ } | null | undefined;
84
+ }, {
85
+ style?: {
86
+ color?: string | null | undefined;
87
+ backgroundColor?: string | null | undefined;
88
+ fontSize?: number | null | undefined;
89
+ fontFamily?: "MODERN_SANS" | "BOOK_SANS" | "ORGANIC_SANS" | "GEOMETRIC_SANS" | "HEAVY_SANS" | "ROUNDED_SANS" | "MODERN_SERIF" | "BOOK_SERIF" | "MONOSPACE" | null | undefined;
90
+ fontWeight?: "bold" | "normal" | null | undefined;
91
+ textAlign?: "right" | "left" | "center" | null | undefined;
92
+ padding?: {
93
+ top: number;
94
+ bottom: number;
95
+ right: number;
96
+ left: number;
97
+ } | null | undefined;
98
+ } | null | undefined;
99
+ props?: {
100
+ markdown?: boolean | null | undefined;
101
+ text?: string | null | undefined;
102
+ } | null | undefined;
103
+ }>;
104
+ type TextProps = z.infer<typeof TextPropsSchema>;
105
+ declare const TextPropsDefaults: {
106
+ text: string;
107
+ };
108
+ declare function Text({ style, props }: TextProps): React.JSX.Element;
109
+
110
+ export { Text, type TextProps, TextPropsDefaults, TextPropsSchema };
package/dist/index.js ADDED
@@ -0,0 +1,257 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
37
+ var __export = (target, all) => {
38
+ for (var name in all)
39
+ __defProp(target, name, { get: all[name], enumerable: true });
40
+ };
41
+ var __copyProps = (to, from, except, desc) => {
42
+ if (from && typeof from === "object" || typeof from === "function") {
43
+ for (let key of __getOwnPropNames(from))
44
+ if (!__hasOwnProp.call(to, key) && key !== except)
45
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
46
+ }
47
+ return to;
48
+ };
49
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
50
+ // If the importer is in node compatibility mode or this is not an ESM
51
+ // file that has been converted to a CommonJS file using a Babel-
52
+ // compatible transform (i.e. "__esModule" has not been set), then set
53
+ // "default" to the CommonJS "module.exports" for node compatibility.
54
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
55
+ mod
56
+ ));
57
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
58
+
59
+ // src/index.tsx
60
+ var index_exports = {};
61
+ __export(index_exports, {
62
+ Text: () => Text,
63
+ TextPropsDefaults: () => TextPropsDefaults,
64
+ TextPropsSchema: () => TextPropsSchema
65
+ });
66
+ module.exports = __toCommonJS(index_exports);
67
+ var import_react2 = __toESM(require("react"));
68
+ var import_zod = require("zod");
69
+
70
+ // src/EmailMarkdown.tsx
71
+ var import_sanitize_html = __toESM(require("sanitize-html"));
72
+ var import_marked = require("marked");
73
+ var import_react = __toESM(require("react"));
74
+ var ALLOWED_TAGS = [
75
+ "a",
76
+ "article",
77
+ "b",
78
+ "blockquote",
79
+ "br",
80
+ "caption",
81
+ "code",
82
+ "del",
83
+ "details",
84
+ "div",
85
+ "em",
86
+ "h1",
87
+ "h2",
88
+ "h3",
89
+ "h4",
90
+ "h5",
91
+ "h6",
92
+ "hr",
93
+ "i",
94
+ "img",
95
+ "ins",
96
+ "kbd",
97
+ "li",
98
+ "main",
99
+ "ol",
100
+ "p",
101
+ "pre",
102
+ "section",
103
+ "span",
104
+ "strong",
105
+ "sub",
106
+ "summary",
107
+ "sup",
108
+ "table",
109
+ "tbody",
110
+ "td",
111
+ "th",
112
+ "thead",
113
+ "tr",
114
+ "u",
115
+ "ul"
116
+ ];
117
+ var GENERIC_ALLOWED_ATTRIBUTES = ["style", "title"];
118
+ function sanitizer(html) {
119
+ return (0, import_sanitize_html.default)(html, {
120
+ allowedTags: ALLOWED_TAGS,
121
+ allowedAttributes: __spreadProps(__spreadValues({}, ALLOWED_TAGS.reduce(
122
+ (res, tag) => {
123
+ res[tag] = [...GENERIC_ALLOWED_ATTRIBUTES];
124
+ return res;
125
+ },
126
+ {}
127
+ )), {
128
+ img: ["src", "srcset", "alt", "width", "height", ...GENERIC_ALLOWED_ATTRIBUTES],
129
+ table: ["width", ...GENERIC_ALLOWED_ATTRIBUTES],
130
+ td: ["align", "width", ...GENERIC_ALLOWED_ATTRIBUTES],
131
+ th: ["align", "width", ...GENERIC_ALLOWED_ATTRIBUTES],
132
+ a: ["href", "target", ...GENERIC_ALLOWED_ATTRIBUTES],
133
+ ol: ["start", ...GENERIC_ALLOWED_ATTRIBUTES],
134
+ ul: ["start", ...GENERIC_ALLOWED_ATTRIBUTES]
135
+ })
136
+ });
137
+ }
138
+ var CustomRenderer = class extends import_marked.Renderer {
139
+ table(header, body) {
140
+ return `<table width="100%">
141
+ <thead>
142
+ ${header}</thead>
143
+ <tbody>
144
+ ${body}</tbody>
145
+ </table>`;
146
+ }
147
+ link(href, title, text) {
148
+ if (!title) {
149
+ return `<a href="${href}" target="_blank">${text}</a>`;
150
+ }
151
+ return `<a href="${href}" title="${title}" target="_blank">${text}</a>`;
152
+ }
153
+ };
154
+ function renderMarkdownString(str) {
155
+ const html = import_marked.marked.parse(str, {
156
+ async: false,
157
+ breaks: true,
158
+ gfm: true,
159
+ pedantic: false,
160
+ silent: false,
161
+ renderer: new CustomRenderer()
162
+ });
163
+ if (typeof html !== "string") {
164
+ throw new Error("marked.parse did not return a string");
165
+ }
166
+ return sanitizer(html);
167
+ }
168
+ function EmailMarkdown(_a) {
169
+ var _b = _a, { markdown } = _b, props = __objRest(_b, ["markdown"]);
170
+ const data = (0, import_react.useMemo)(() => renderMarkdownString(markdown), [markdown]);
171
+ return /* @__PURE__ */ import_react.default.createElement("div", __spreadProps(__spreadValues({}, props), { dangerouslySetInnerHTML: { __html: data } }));
172
+ }
173
+
174
+ // src/index.tsx
175
+ var FONT_FAMILY_SCHEMA = import_zod.z.enum([
176
+ "MODERN_SANS",
177
+ "BOOK_SANS",
178
+ "ORGANIC_SANS",
179
+ "GEOMETRIC_SANS",
180
+ "HEAVY_SANS",
181
+ "ROUNDED_SANS",
182
+ "MODERN_SERIF",
183
+ "BOOK_SERIF",
184
+ "MONOSPACE"
185
+ ]).nullable().optional();
186
+ function getFontFamily(fontFamily) {
187
+ switch (fontFamily) {
188
+ case "MODERN_SANS":
189
+ return '"Helvetica Neue", "Arial Nova", "Nimbus Sans", Arial, sans-serif';
190
+ case "BOOK_SANS":
191
+ return 'Optima, Candara, "Noto Sans", source-sans-pro, sans-serif';
192
+ case "ORGANIC_SANS":
193
+ return 'Seravek, "Gill Sans Nova", Ubuntu, Calibri, "DejaVu Sans", source-sans-pro, sans-serif';
194
+ case "GEOMETRIC_SANS":
195
+ return 'Avenir, "Avenir Next LT Pro", Montserrat, Corbel, "URW Gothic", source-sans-pro, sans-serif';
196
+ case "HEAVY_SANS":
197
+ return 'Bahnschrift, "DIN Alternate", "Franklin Gothic Medium", "Nimbus Sans Narrow", sans-serif-condensed, sans-serif';
198
+ case "ROUNDED_SANS":
199
+ return 'ui-rounded, "Hiragino Maru Gothic ProN", Quicksand, Comfortaa, Manjari, "Arial Rounded MT Bold", Calibri, source-sans-pro, sans-serif';
200
+ case "MODERN_SERIF":
201
+ return 'Charter, "Bitstream Charter", "Sitka Text", Cambria, serif';
202
+ case "BOOK_SERIF":
203
+ return '"Iowan Old Style", "Palatino Linotype", "URW Palladio L", P052, serif';
204
+ case "MONOSPACE":
205
+ return '"Nimbus Mono PS", "Courier New", "Cutive Mono", monospace';
206
+ }
207
+ return void 0;
208
+ }
209
+ var COLOR_SCHEMA = import_zod.z.string().regex(/^#[0-9a-fA-F]{6}$/).nullable().optional();
210
+ var PADDING_SCHEMA = import_zod.z.object({
211
+ top: import_zod.z.number(),
212
+ bottom: import_zod.z.number(),
213
+ right: import_zod.z.number(),
214
+ left: import_zod.z.number()
215
+ }).optional().nullable();
216
+ var getPadding = (padding) => padding ? `${padding.top}px ${padding.right}px ${padding.bottom}px ${padding.left}px` : void 0;
217
+ var TextPropsSchema = import_zod.z.object({
218
+ style: import_zod.z.object({
219
+ color: COLOR_SCHEMA,
220
+ backgroundColor: COLOR_SCHEMA,
221
+ fontSize: import_zod.z.number().gte(0).optional().nullable(),
222
+ fontFamily: FONT_FAMILY_SCHEMA,
223
+ fontWeight: import_zod.z.enum(["bold", "normal"]).optional().nullable(),
224
+ textAlign: import_zod.z.enum(["left", "center", "right"]).optional().nullable(),
225
+ padding: PADDING_SCHEMA
226
+ }).optional().nullable(),
227
+ props: import_zod.z.object({
228
+ markdown: import_zod.z.boolean().optional().nullable(),
229
+ text: import_zod.z.string().optional().nullable()
230
+ }).optional().nullable()
231
+ });
232
+ var TextPropsDefaults = {
233
+ text: ""
234
+ };
235
+ function Text({ style, props }) {
236
+ var _a, _b, _c, _d, _e, _f;
237
+ const wStyle = {
238
+ color: (_a = style == null ? void 0 : style.color) != null ? _a : void 0,
239
+ backgroundColor: (_b = style == null ? void 0 : style.backgroundColor) != null ? _b : void 0,
240
+ fontSize: (_c = style == null ? void 0 : style.fontSize) != null ? _c : void 0,
241
+ fontFamily: getFontFamily(style == null ? void 0 : style.fontFamily),
242
+ fontWeight: (_d = style == null ? void 0 : style.fontWeight) != null ? _d : void 0,
243
+ textAlign: (_e = style == null ? void 0 : style.textAlign) != null ? _e : void 0,
244
+ padding: getPadding(style == null ? void 0 : style.padding)
245
+ };
246
+ const text = (_f = props == null ? void 0 : props.text) != null ? _f : TextPropsDefaults.text;
247
+ if (props == null ? void 0 : props.markdown) {
248
+ return /* @__PURE__ */ import_react2.default.createElement(EmailMarkdown, { style: wStyle, markdown: text });
249
+ }
250
+ return /* @__PURE__ */ import_react2.default.createElement("div", { style: wStyle }, text);
251
+ }
252
+ // Annotate the CommonJS export names for ESM import in node:
253
+ 0 && (module.exports = {
254
+ Text,
255
+ TextPropsDefaults,
256
+ TextPropsSchema
257
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,223 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+
33
+ // src/index.tsx
34
+ import React2 from "react";
35
+ import { z } from "zod";
36
+
37
+ // src/EmailMarkdown.tsx
38
+ import sanitizeHtml from "sanitize-html";
39
+ import { marked, Renderer } from "marked";
40
+ import React, { useMemo } from "react";
41
+ var ALLOWED_TAGS = [
42
+ "a",
43
+ "article",
44
+ "b",
45
+ "blockquote",
46
+ "br",
47
+ "caption",
48
+ "code",
49
+ "del",
50
+ "details",
51
+ "div",
52
+ "em",
53
+ "h1",
54
+ "h2",
55
+ "h3",
56
+ "h4",
57
+ "h5",
58
+ "h6",
59
+ "hr",
60
+ "i",
61
+ "img",
62
+ "ins",
63
+ "kbd",
64
+ "li",
65
+ "main",
66
+ "ol",
67
+ "p",
68
+ "pre",
69
+ "section",
70
+ "span",
71
+ "strong",
72
+ "sub",
73
+ "summary",
74
+ "sup",
75
+ "table",
76
+ "tbody",
77
+ "td",
78
+ "th",
79
+ "thead",
80
+ "tr",
81
+ "u",
82
+ "ul"
83
+ ];
84
+ var GENERIC_ALLOWED_ATTRIBUTES = ["style", "title"];
85
+ function sanitizer(html) {
86
+ return sanitizeHtml(html, {
87
+ allowedTags: ALLOWED_TAGS,
88
+ allowedAttributes: __spreadProps(__spreadValues({}, ALLOWED_TAGS.reduce(
89
+ (res, tag) => {
90
+ res[tag] = [...GENERIC_ALLOWED_ATTRIBUTES];
91
+ return res;
92
+ },
93
+ {}
94
+ )), {
95
+ img: ["src", "srcset", "alt", "width", "height", ...GENERIC_ALLOWED_ATTRIBUTES],
96
+ table: ["width", ...GENERIC_ALLOWED_ATTRIBUTES],
97
+ td: ["align", "width", ...GENERIC_ALLOWED_ATTRIBUTES],
98
+ th: ["align", "width", ...GENERIC_ALLOWED_ATTRIBUTES],
99
+ a: ["href", "target", ...GENERIC_ALLOWED_ATTRIBUTES],
100
+ ol: ["start", ...GENERIC_ALLOWED_ATTRIBUTES],
101
+ ul: ["start", ...GENERIC_ALLOWED_ATTRIBUTES]
102
+ })
103
+ });
104
+ }
105
+ var CustomRenderer = class extends Renderer {
106
+ table(header, body) {
107
+ return `<table width="100%">
108
+ <thead>
109
+ ${header}</thead>
110
+ <tbody>
111
+ ${body}</tbody>
112
+ </table>`;
113
+ }
114
+ link(href, title, text) {
115
+ if (!title) {
116
+ return `<a href="${href}" target="_blank">${text}</a>`;
117
+ }
118
+ return `<a href="${href}" title="${title}" target="_blank">${text}</a>`;
119
+ }
120
+ };
121
+ function renderMarkdownString(str) {
122
+ const html = marked.parse(str, {
123
+ async: false,
124
+ breaks: true,
125
+ gfm: true,
126
+ pedantic: false,
127
+ silent: false,
128
+ renderer: new CustomRenderer()
129
+ });
130
+ if (typeof html !== "string") {
131
+ throw new Error("marked.parse did not return a string");
132
+ }
133
+ return sanitizer(html);
134
+ }
135
+ function EmailMarkdown(_a) {
136
+ var _b = _a, { markdown } = _b, props = __objRest(_b, ["markdown"]);
137
+ const data = useMemo(() => renderMarkdownString(markdown), [markdown]);
138
+ return /* @__PURE__ */ React.createElement("div", __spreadProps(__spreadValues({}, props), { dangerouslySetInnerHTML: { __html: data } }));
139
+ }
140
+
141
+ // src/index.tsx
142
+ var FONT_FAMILY_SCHEMA = z.enum([
143
+ "MODERN_SANS",
144
+ "BOOK_SANS",
145
+ "ORGANIC_SANS",
146
+ "GEOMETRIC_SANS",
147
+ "HEAVY_SANS",
148
+ "ROUNDED_SANS",
149
+ "MODERN_SERIF",
150
+ "BOOK_SERIF",
151
+ "MONOSPACE"
152
+ ]).nullable().optional();
153
+ function getFontFamily(fontFamily) {
154
+ switch (fontFamily) {
155
+ case "MODERN_SANS":
156
+ return '"Helvetica Neue", "Arial Nova", "Nimbus Sans", Arial, sans-serif';
157
+ case "BOOK_SANS":
158
+ return 'Optima, Candara, "Noto Sans", source-sans-pro, sans-serif';
159
+ case "ORGANIC_SANS":
160
+ return 'Seravek, "Gill Sans Nova", Ubuntu, Calibri, "DejaVu Sans", source-sans-pro, sans-serif';
161
+ case "GEOMETRIC_SANS":
162
+ return 'Avenir, "Avenir Next LT Pro", Montserrat, Corbel, "URW Gothic", source-sans-pro, sans-serif';
163
+ case "HEAVY_SANS":
164
+ return 'Bahnschrift, "DIN Alternate", "Franklin Gothic Medium", "Nimbus Sans Narrow", sans-serif-condensed, sans-serif';
165
+ case "ROUNDED_SANS":
166
+ return 'ui-rounded, "Hiragino Maru Gothic ProN", Quicksand, Comfortaa, Manjari, "Arial Rounded MT Bold", Calibri, source-sans-pro, sans-serif';
167
+ case "MODERN_SERIF":
168
+ return 'Charter, "Bitstream Charter", "Sitka Text", Cambria, serif';
169
+ case "BOOK_SERIF":
170
+ return '"Iowan Old Style", "Palatino Linotype", "URW Palladio L", P052, serif';
171
+ case "MONOSPACE":
172
+ return '"Nimbus Mono PS", "Courier New", "Cutive Mono", monospace';
173
+ }
174
+ return void 0;
175
+ }
176
+ var COLOR_SCHEMA = z.string().regex(/^#[0-9a-fA-F]{6}$/).nullable().optional();
177
+ var PADDING_SCHEMA = z.object({
178
+ top: z.number(),
179
+ bottom: z.number(),
180
+ right: z.number(),
181
+ left: z.number()
182
+ }).optional().nullable();
183
+ var getPadding = (padding) => padding ? `${padding.top}px ${padding.right}px ${padding.bottom}px ${padding.left}px` : void 0;
184
+ var TextPropsSchema = z.object({
185
+ style: z.object({
186
+ color: COLOR_SCHEMA,
187
+ backgroundColor: COLOR_SCHEMA,
188
+ fontSize: z.number().gte(0).optional().nullable(),
189
+ fontFamily: FONT_FAMILY_SCHEMA,
190
+ fontWeight: z.enum(["bold", "normal"]).optional().nullable(),
191
+ textAlign: z.enum(["left", "center", "right"]).optional().nullable(),
192
+ padding: PADDING_SCHEMA
193
+ }).optional().nullable(),
194
+ props: z.object({
195
+ markdown: z.boolean().optional().nullable(),
196
+ text: z.string().optional().nullable()
197
+ }).optional().nullable()
198
+ });
199
+ var TextPropsDefaults = {
200
+ text: ""
201
+ };
202
+ function Text({ style, props }) {
203
+ var _a, _b, _c, _d, _e, _f;
204
+ const wStyle = {
205
+ color: (_a = style == null ? void 0 : style.color) != null ? _a : void 0,
206
+ backgroundColor: (_b = style == null ? void 0 : style.backgroundColor) != null ? _b : void 0,
207
+ fontSize: (_c = style == null ? void 0 : style.fontSize) != null ? _c : void 0,
208
+ fontFamily: getFontFamily(style == null ? void 0 : style.fontFamily),
209
+ fontWeight: (_d = style == null ? void 0 : style.fontWeight) != null ? _d : void 0,
210
+ textAlign: (_e = style == null ? void 0 : style.textAlign) != null ? _e : void 0,
211
+ padding: getPadding(style == null ? void 0 : style.padding)
212
+ };
213
+ const text = (_f = props == null ? void 0 : props.text) != null ? _f : TextPropsDefaults.text;
214
+ if (props == null ? void 0 : props.markdown) {
215
+ return /* @__PURE__ */ React2.createElement(EmailMarkdown, { style: wStyle, markdown: text });
216
+ }
217
+ return /* @__PURE__ */ React2.createElement("div", { style: wStyle }, text);
218
+ }
219
+ export {
220
+ Text,
221
+ TextPropsDefaults,
222
+ TextPropsSchema
223
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@csg-org/block-text",
3
- "version": "0.0.7-alpha.3",
3
+ "version": "0.0.7-alpha.4",
4
4
  "description": "@csg-org/document compatible Text component",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",