@sqrzro/ui 4.0.0-alpha.64 → 4.0.0-alpha.66
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/mail/Mail/index.d.ts +1 -1
- package/dist/mail/Mail/index.js +12 -10
- package/dist/mail/MailButton/index.js +2 -1
- package/dist/mail/utility/convert-to-datauri.js +23 -2
- package/dist/mail/utility/mail-config.d.ts +4 -0
- package/dist/mail/utility/{get-mail-config.js → mail-config.js} +12 -4
- package/package.json +3 -3
- package/dist/mail/utility/get-mail-config.d.ts +0 -4
|
@@ -2,7 +2,7 @@ import { DeepPartial } from '@sqrzro/utility';
|
|
|
2
2
|
import { MailConfigObject } from '../utility/interfaces';
|
|
3
3
|
export interface MailProps extends DeepPartial<MailConfigObject> {
|
|
4
4
|
children: React.ReactNode;
|
|
5
|
-
title
|
|
5
|
+
title?: string;
|
|
6
6
|
}
|
|
7
7
|
declare function Mail({ children, logo, styles, title, }: Readonly<MailProps>): Promise<React.ReactElement>;
|
|
8
8
|
export default Mail;
|
package/dist/mail/Mail/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use server';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { Fragment } from 'react';
|
|
4
|
-
import
|
|
4
|
+
import { setMailConfig } from '../utility/mail-config';
|
|
5
5
|
const HALF = 2;
|
|
6
6
|
async function Mail({ children, logo, styles, title, }) {
|
|
7
|
-
const mailConfig =
|
|
7
|
+
const mailConfig = setMailConfig({ styles });
|
|
8
8
|
const logoData = await (await import('../utility/convert-to-datauri')).default(logo ?? mailConfig.logo ?? '');
|
|
9
9
|
return (_jsxs("html", { lang: "en", children: [_jsxs("head", { children: [_jsx("meta", { charSet: "utf-8" }), _jsx("style", { dangerouslySetInnerHTML: {
|
|
10
10
|
__html: `
|
|
@@ -64,14 +64,16 @@ async function Mail({ children, logo, styles, title, }) {
|
|
|
64
64
|
}, width: mailConfig.styles.panel.padding }), _jsx("td", { style: {
|
|
65
65
|
backgroundColor: mailConfig.styles.panel.backgroundColor,
|
|
66
66
|
}, children: _jsx("table", { border: 0, cellPadding: 0, cellSpacing: 0, width: "100%", children: _jsxs("tbody", { children: [logoData ? (_jsxs(Fragment, { children: [_jsx("tr", { children: _jsx("td", { children: _jsx("table", { border: 0, cellPadding: 0, cellSpacing: 0, width: 240, children: _jsx("tbody", { children: _jsx("tr", { children: _jsx("td", { children: _jsx("img", { alt: "Logo", src: logoData, width: 240 }) }) }) }) }) }) }), _jsx("tr", { children: _jsx("td", { height: mailConfig.styles.panel
|
|
67
|
-
.padding }) })] })) : null, _jsx("tr", { children: _jsx("td", { style: {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
.padding }) })] })) : null, title ? (_jsxs(Fragment, { children: [_jsx("tr", { children: _jsx("td", { style: {
|
|
68
|
+
color: mailConfig.styles
|
|
69
|
+
.title.color,
|
|
70
|
+
fontSize: mailConfig.styles
|
|
71
|
+
.title.fontSize,
|
|
72
|
+
fontWeight: mailConfig.styles
|
|
73
|
+
.title
|
|
74
|
+
.fontWeight,
|
|
75
|
+
}, children: title }) }), _jsx("tr", { children: _jsx("td", { height: mailConfig.styles.panel
|
|
76
|
+
.padding }) })] })) : null, _jsx("tr", { children: _jsx("td", { children: children }) })] }) }) }), _jsx("td", { className: "padding", style: {
|
|
75
77
|
backgroundColor: mailConfig.styles.panel.backgroundColor,
|
|
76
78
|
}, width: mailConfig.styles.panel.padding })] }), _jsxs("tr", { children: [_jsx("td", { className: "padding", height: mailConfig.styles.panel.padding, style: {
|
|
77
79
|
backgroundColor: mailConfig.styles.panel.backgroundColor,
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use server';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import getMailConfig from '../utility/
|
|
3
|
+
import { getMailConfig } from '../utility/mail-config';
|
|
4
4
|
function calculateWidth(text) {
|
|
5
5
|
const characterWidth = 8;
|
|
6
6
|
const padding = 50;
|
|
7
7
|
return text.length * characterWidth + padding;
|
|
8
8
|
}
|
|
9
9
|
async function MailButton({ children, href, styles, }) {
|
|
10
|
+
console.log('MailButton', { children, href, styles });
|
|
10
11
|
const mailConfig = getMailConfig({ styles });
|
|
11
12
|
const calculatedWidth = calculateWidth(children);
|
|
12
13
|
return (_jsx("div", { dangerouslySetInnerHTML: {
|
|
@@ -1,11 +1,32 @@
|
|
|
1
1
|
'use server';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
+
function isURL(value) {
|
|
5
|
+
try {
|
|
6
|
+
const url = new URL(value);
|
|
7
|
+
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
async function read(fileName) {
|
|
14
|
+
if (isURL(fileName)) {
|
|
15
|
+
const response = await fetch(fileName);
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
throw new Error(`Failed to fetch ${fileName}: ${response.status}`);
|
|
18
|
+
}
|
|
19
|
+
return Buffer.from(await response.arrayBuffer());
|
|
20
|
+
}
|
|
21
|
+
return fs.readFileSync(fileName);
|
|
22
|
+
}
|
|
4
23
|
async function convertToDataURI(fileName) {
|
|
5
24
|
try {
|
|
6
|
-
const filePath = path.
|
|
25
|
+
const filePath = path.isAbsolute(fileName) || isURL(fileName)
|
|
26
|
+
? fileName
|
|
27
|
+
: path.join(process.cwd(), fileName);
|
|
7
28
|
const mimeType = 'image/' + path.extname(filePath).slice(1);
|
|
8
|
-
const imageData =
|
|
29
|
+
const imageData = await read(filePath);
|
|
9
30
|
const base64Image = Buffer.from(imageData).toString('base64');
|
|
10
31
|
return Promise.resolve(`data:${mimeType};base64,${base64Image}`);
|
|
11
32
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DeepPartial } from '@sqrzro/utility';
|
|
2
|
+
import type { MailConfigObject } from './interfaces';
|
|
3
|
+
export declare function setMailConfig(overrides?: DeepPartial<MailConfigObject>): MailConfigObject;
|
|
4
|
+
export declare function getMailConfig(overrides?: DeepPartial<MailConfigObject>): MailConfigObject;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { deepMerge } from '@sqrzro/utility';
|
|
2
|
+
import { cache } from 'react';
|
|
2
3
|
const DEFAULT_STYLES = {
|
|
3
4
|
styles: {
|
|
4
5
|
button: {
|
|
@@ -21,14 +22,21 @@ const DEFAULT_STYLES = {
|
|
|
21
22
|
},
|
|
22
23
|
},
|
|
23
24
|
};
|
|
24
|
-
|
|
25
|
+
const context = cache(() => new Map());
|
|
26
|
+
const global = context();
|
|
27
|
+
export function setMailConfig(overrides) {
|
|
25
28
|
const string = process.env.MAIL_CONFIG || '{}';
|
|
26
29
|
try {
|
|
27
30
|
const object = JSON.parse(string);
|
|
28
|
-
|
|
31
|
+
global.set('mail', deepMerge(DEFAULT_STYLES, object, overrides || {}));
|
|
29
32
|
}
|
|
30
33
|
catch (err) {
|
|
31
|
-
|
|
34
|
+
global.set('mail', deepMerge(DEFAULT_STYLES, overrides || {}));
|
|
32
35
|
}
|
|
36
|
+
return global.get('mail');
|
|
37
|
+
}
|
|
38
|
+
export function getMailConfig(overrides) {
|
|
39
|
+
return global.has('mail')
|
|
40
|
+
? deepMerge(DEFAULT_STYLES, global.get('mail'), overrides || {})
|
|
41
|
+
: deepMerge(DEFAULT_STYLES, overrides || {});
|
|
33
42
|
}
|
|
34
|
-
export default getMailConfig;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqrzro/ui",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.0-alpha.
|
|
4
|
+
"version": "4.0.0-alpha.66",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "ISC",
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
"react-dom": "^19.2.4",
|
|
58
58
|
"tailwind-merge": "^3.5.0",
|
|
59
59
|
"use-deep-compare-effect": "^1.8.1",
|
|
60
|
-
"@sqrzro/
|
|
61
|
-
"@sqrzro/
|
|
60
|
+
"@sqrzro/addons": "^4.0.0-alpha.10",
|
|
61
|
+
"@sqrzro/utility": "^4.0.0-alpha.19"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@storybook/addon-a11y": "^10.3.1",
|