@sqrzro/ui 4.0.0-alpha.64 → 4.0.0-alpha.65

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.
@@ -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 getMailConfig from '../utility/get-mail-config';
4
+ import { setMailConfig } from '../utility/mail-config';
5
5
  const HALF = 2;
6
6
  async function Mail({ children, logo, styles, title, }) {
7
- const mailConfig = getMailConfig({ styles });
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: `
@@ -1,12 +1,13 @@
1
1
  'use server';
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import getMailConfig from '../utility/get-mail-config';
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: {
@@ -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
- function getMailConfig(overrides) {
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
- return deepMerge(DEFAULT_STYLES, object, overrides || {});
31
+ global.set('mail', deepMerge(DEFAULT_STYLES, object, overrides || {}));
29
32
  }
30
33
  catch (err) {
31
- return deepMerge(DEFAULT_STYLES, overrides || {});
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.64",
4
+ "version": "4.0.0-alpha.65",
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/utility": "^4.0.0-alpha.19",
61
- "@sqrzro/addons": "^4.0.0-alpha.10"
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",
@@ -1,4 +0,0 @@
1
- import type { DeepPartial } from '@sqrzro/utility';
2
- import type { MailConfigObject } from './interfaces';
3
- declare function getMailConfig(overrides?: DeepPartial<MailConfigObject>): MailConfigObject;
4
- export default getMailConfig;