@swisper.ai/web-chat-ui 0.5.0 → 0.5.1
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/components/html-viewer/html-viewer.stories.d.ts +6 -0
- package/dist/components/html-viewer/html-viewer.stories.d.ts.map +1 -1
- package/dist/components/html-viewer/utils.d.ts.map +1 -1
- package/dist/index.es.js +469 -468
- package/dist/index.es.js.map +1 -1
- package/package.json +1 -1
- package/src/components/html-viewer/__stories__/transactional-email.html +154 -0
- package/src/components/html-viewer/html-viewer.json +1 -0
- package/src/components/html-viewer/html-viewer.stories.tsx +27 -0
- package/src/components/html-viewer/utils.ts +8 -1
package/package.json
CHANGED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
6
|
+
<title>Simple Transactional Email</title>
|
|
7
|
+
<style media="all" type="text/css">
|
|
8
|
+
@media all {
|
|
9
|
+
.btn-primary table td:hover {
|
|
10
|
+
background-color: #ec0867 !important;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.btn-primary a:hover {
|
|
14
|
+
background-color: #ec0867 !important;
|
|
15
|
+
border-color: #ec0867 !important;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
@media only screen and (max-width: 640px) {
|
|
19
|
+
.main p,
|
|
20
|
+
.main td,
|
|
21
|
+
.main span {
|
|
22
|
+
font-size: 16px !important;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.wrapper {
|
|
26
|
+
padding: 8px !important;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.content {
|
|
30
|
+
padding: 0 !important;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.container {
|
|
34
|
+
padding: 0 !important;
|
|
35
|
+
padding-top: 8px !important;
|
|
36
|
+
width: 100% !important;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.main {
|
|
40
|
+
border-left-width: 0 !important;
|
|
41
|
+
border-radius: 0 !important;
|
|
42
|
+
border-right-width: 0 !important;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.btn table {
|
|
46
|
+
max-width: 100% !important;
|
|
47
|
+
width: 100% !important;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.btn a {
|
|
51
|
+
font-size: 16px !important;
|
|
52
|
+
max-width: 100% !important;
|
|
53
|
+
width: 100% !important;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
@media all {
|
|
57
|
+
.ExternalClass {
|
|
58
|
+
width: 100%;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.ExternalClass,
|
|
62
|
+
.ExternalClass p,
|
|
63
|
+
.ExternalClass span,
|
|
64
|
+
.ExternalClass font,
|
|
65
|
+
.ExternalClass td,
|
|
66
|
+
.ExternalClass div {
|
|
67
|
+
line-height: 100%;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.apple-link a {
|
|
71
|
+
color: inherit !important;
|
|
72
|
+
font-family: inherit !important;
|
|
73
|
+
font-size: inherit !important;
|
|
74
|
+
font-weight: inherit !important;
|
|
75
|
+
line-height: inherit !important;
|
|
76
|
+
text-decoration: none !important;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
#MessageViewBody a {
|
|
80
|
+
color: inherit;
|
|
81
|
+
text-decoration: none;
|
|
82
|
+
font-size: inherit;
|
|
83
|
+
font-family: inherit;
|
|
84
|
+
font-weight: inherit;
|
|
85
|
+
line-height: inherit;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
</style>
|
|
89
|
+
</head>
|
|
90
|
+
<body style="font-family: Helvetica, sans-serif; -webkit-font-smoothing: antialiased; font-size: 16px; line-height: 1.3; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; background-color: #f4f5f6; margin: 0; padding: 0;">
|
|
91
|
+
<table role="presentation" border="0" cellpadding="0" cellspacing="0" class="body" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background-color: #f4f5f6; width: 100%;" width="100%" bgcolor="#f4f5f6">
|
|
92
|
+
<tr>
|
|
93
|
+
<td style="font-family: Helvetica, sans-serif; font-size: 16px; vertical-align: top;" valign="top"> </td>
|
|
94
|
+
<td class="container" style="font-family: Helvetica, sans-serif; font-size: 16px; vertical-align: top; max-width: 600px; padding: 0; padding-top: 24px; width: 600px; margin: 0 auto;" width="600" valign="top">
|
|
95
|
+
<div class="content" style="box-sizing: border-box; display: block; margin: 0 auto; max-width: 600px; padding: 0;">
|
|
96
|
+
|
|
97
|
+
<!-- START CENTERED WHITE CONTAINER -->
|
|
98
|
+
<span class="preheader" style="color: transparent; display: none; height: 0; max-height: 0; max-width: 0; opacity: 0; overflow: hidden; mso-hide: all; visibility: hidden; width: 0;">This is preheader text. Some clients will show this text as a preview.</span>
|
|
99
|
+
<table role="presentation" border="0" cellpadding="0" cellspacing="0" class="main" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background: #ffffff; border: 1px solid #eaebed; border-radius: 16px; width: 100%;" width="100%">
|
|
100
|
+
|
|
101
|
+
<!-- START MAIN CONTENT AREA -->
|
|
102
|
+
<tr>
|
|
103
|
+
<td class="wrapper" style="font-family: Helvetica, sans-serif; font-size: 16px; vertical-align: top; box-sizing: border-box; padding: 24px;" valign="top">
|
|
104
|
+
<p style="font-family: Helvetica, sans-serif; font-size: 16px; font-weight: normal; margin: 0; margin-bottom: 16px;">Hi there</p>
|
|
105
|
+
<p style="font-family: Helvetica, sans-serif; font-size: 16px; font-weight: normal; margin: 0; margin-bottom: 16px;">Sometimes you just want to send a simple HTML email with a simple design and clear call to action. This is it.</p>
|
|
106
|
+
<table role="presentation" border="0" cellpadding="0" cellspacing="0" class="btn btn-primary" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; box-sizing: border-box; width: 100%; min-width: 100%;" width="100%">
|
|
107
|
+
<tbody>
|
|
108
|
+
<tr>
|
|
109
|
+
<td align="left" style="font-family: Helvetica, sans-serif; font-size: 16px; vertical-align: top; padding-bottom: 16px;" valign="top">
|
|
110
|
+
<table role="presentation" border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: auto;">
|
|
111
|
+
<tbody>
|
|
112
|
+
<tr>
|
|
113
|
+
<td style="font-family: Helvetica, sans-serif; font-size: 16px; vertical-align: top; border-radius: 4px; text-align: center; background-color: #0867ec;" valign="top" align="center" bgcolor="#0867ec"> <a href="http://htmlemail.io" target="_blank" style="border: solid 2px #0867ec; border-radius: 4px; box-sizing: border-box; cursor: pointer; display: inline-block; font-size: 16px; font-weight: bold; margin: 0; padding: 12px 24px; text-decoration: none; text-transform: capitalize; background-color: #0867ec; border-color: #0867ec; color: #ffffff;">Call To Action</a> </td>
|
|
114
|
+
</tr>
|
|
115
|
+
</tbody>
|
|
116
|
+
</table>
|
|
117
|
+
</td>
|
|
118
|
+
</tr>
|
|
119
|
+
</tbody>
|
|
120
|
+
</table>
|
|
121
|
+
<p style="font-family: Helvetica, sans-serif; font-size: 16px; font-weight: normal; margin: 0; margin-bottom: 16px;">This is a really simple email template. It's sole purpose is to get the recipient to click the button with no distractions.</p>
|
|
122
|
+
<p style="font-family: Helvetica, sans-serif; font-size: 16px; font-weight: normal; margin: 0; margin-bottom: 16px;">Good luck! Hope it works.</p>
|
|
123
|
+
</td>
|
|
124
|
+
</tr>
|
|
125
|
+
|
|
126
|
+
<!-- END MAIN CONTENT AREA -->
|
|
127
|
+
</table>
|
|
128
|
+
|
|
129
|
+
<!-- START FOOTER -->
|
|
130
|
+
<div class="footer" style="clear: both; padding-top: 24px; text-align: center; width: 100%;">
|
|
131
|
+
<table role="presentation" border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;" width="100%">
|
|
132
|
+
<tr>
|
|
133
|
+
<td class="content-block" style="font-family: Helvetica, sans-serif; vertical-align: top; color: #9a9ea6; font-size: 16px; text-align: center;" valign="top" align="center">
|
|
134
|
+
<span class="apple-link" style="color: #9a9ea6; font-size: 16px; text-align: center;">Company Inc, 7-11 Commercial Ct, Belfast BT1 2NB</span>
|
|
135
|
+
<br> Don't like these emails? <a href="http://htmlemail.io/blog" style="text-decoration: underline; color: #9a9ea6; font-size: 16px; text-align: center;">Unsubscribe</a>.
|
|
136
|
+
</td>
|
|
137
|
+
</tr>
|
|
138
|
+
<tr>
|
|
139
|
+
<td class="content-block powered-by" style="font-family: Helvetica, sans-serif; vertical-align: top; color: #9a9ea6; font-size: 16px; text-align: center;" valign="top" align="center">
|
|
140
|
+
Powered by <a href="http://htmlemail.io" style="color: #9a9ea6; font-size: 16px; text-align: center; text-decoration: none;">HTMLemail.io</a>
|
|
141
|
+
</td>
|
|
142
|
+
</tr>
|
|
143
|
+
</table>
|
|
144
|
+
</div>
|
|
145
|
+
|
|
146
|
+
<!-- END FOOTER -->
|
|
147
|
+
|
|
148
|
+
<!-- END CENTERED WHITE CONTAINER --></div>
|
|
149
|
+
</td>
|
|
150
|
+
<td style="font-family: Helvetica, sans-serif; font-size: 16px; vertical-align: top;" valign="top"> </td>
|
|
151
|
+
</tr>
|
|
152
|
+
</table>
|
|
153
|
+
</body>
|
|
154
|
+
</html>
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"width, height and noWrap attributes are removed from every element except img, so fixed-size markup such as <table width=\"600\"> fits its container; pass them in sanitizeSchema.attributes to keep them",
|
|
42
42
|
"img keeps width and height as its aspect ratio; the root caps images (max-w-full, h-auto) and tables (max-w-full) at its width and wraps long words anywhere, even when a custom renderer draws them",
|
|
43
43
|
"Scripts, event-handler attributes, style attributes and javascript: URLs are removed by the default schema",
|
|
44
|
+
"A whole document (e.g. an email template) can be passed: html, head and body are unwrapped, and style and title are removed with their text so CSS never shows as content",
|
|
44
45
|
"components is merged over the defaults (a, p, ul, ol, li, strong, b, em, i, code); every other allowed tag renders as a plain element",
|
|
45
46
|
"The default a renders ui/link with target=\"_blank\" and rel=\"noopener noreferrer\", and stops click and mousedown propagation so a clickable parent does not react",
|
|
46
47
|
"Default block elements (p, ul, ol) have no top margin when first and an 8px top margin otherwise",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
2
|
import { expect } from 'storybook/test';
|
|
3
3
|
|
|
4
|
+
import TRANSACTIONAL_EMAIL_HTML from './__stories__/transactional-email.html?raw';
|
|
4
5
|
import { HtmlViewer } from './html-viewer';
|
|
5
6
|
import type { HtmlViewerComponents } from './types';
|
|
6
7
|
|
|
@@ -116,3 +117,29 @@ export const FixedSizeHtml: Story = {
|
|
|
116
117
|
await expect(table!.getBoundingClientRect().width).toBeLessThanOrEqual(root!.clientWidth);
|
|
117
118
|
},
|
|
118
119
|
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* A whole email document (`<!doctype>`, `<head>` with `<title>` and `<style>`, nested layout
|
|
123
|
+
* tables, inline styles, comments) in a 320px container. `<title>` and `<style>` are removed with
|
|
124
|
+
* their text, inline styles and comments are dropped, and the layout tables fit.
|
|
125
|
+
*/
|
|
126
|
+
export const ComplexEmail: Story = {
|
|
127
|
+
args: {
|
|
128
|
+
html: TRANSACTIONAL_EMAIL_HTML,
|
|
129
|
+
},
|
|
130
|
+
decorators: [
|
|
131
|
+
(Story) => (
|
|
132
|
+
<div className="w-80 border border-dashed border-border-primary">
|
|
133
|
+
<Story />
|
|
134
|
+
</div>
|
|
135
|
+
),
|
|
136
|
+
],
|
|
137
|
+
play: async ({ canvasElement }) => {
|
|
138
|
+
const root = canvasElement.querySelector<HTMLElement>('[data-slot="html-viewer"]');
|
|
139
|
+
|
|
140
|
+
await expect(root?.textContent).not.toContain('Simple Transactional Email');
|
|
141
|
+
await expect(root?.textContent).not.toContain('@media');
|
|
142
|
+
await expect(canvasElement.querySelector('style, title, [style]')).toBeNull();
|
|
143
|
+
await expect(root!.scrollWidth).toBeLessThanOrEqual(root!.clientWidth);
|
|
144
|
+
},
|
|
145
|
+
};
|
|
@@ -12,13 +12,20 @@ const defaultAttributes = Object.fromEntries(
|
|
|
12
12
|
]),
|
|
13
13
|
);
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Elements removed with their content. A whole document (e.g. an email template) parsed as a
|
|
17
|
+
* fragment keeps `<title>` and `<style>`; unwrapped, their text would render as visible content.
|
|
18
|
+
*/
|
|
19
|
+
const STRIPPED_TAG_NAMES = ['style', 'title'];
|
|
20
|
+
|
|
15
21
|
/**
|
|
16
22
|
* `rehype-sanitize`'s default schema without `width`, `height` and `noWrap`, which it allows on
|
|
17
23
|
* every element. `img` keeps `width` and `height` as its aspect ratio; the viewer caps images with
|
|
18
|
-
* `max-w-full h-auto`, so they never overflow.
|
|
24
|
+
* `max-w-full h-auto`, so they never overflow. `style` and `title` are removed with their content.
|
|
19
25
|
*/
|
|
20
26
|
const BASE_SCHEMA: HtmlViewerSanitizeSchema = {
|
|
21
27
|
...defaultSchema,
|
|
28
|
+
strip: [...(defaultSchema.strip ?? []), ...STRIPPED_TAG_NAMES],
|
|
22
29
|
attributes: {
|
|
23
30
|
...defaultAttributes,
|
|
24
31
|
img: [...(defaultAttributes.img ?? []), 'width', 'height'],
|