@vtex-email/react 0.1.0 → 0.3.0
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/dsl/attributes.d.ts +13 -11
- package/dist/dsl/attributes.d.ts.map +1 -1
- package/dist/dsl/blocks.d.ts +61 -3
- package/dist/dsl/blocks.d.ts.map +1 -1
- package/dist/dsl/vtex.d.ts +9 -2
- package/dist/dsl/vtex.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +207 -62
- package/package.json +3 -3
package/dist/dsl/attributes.d.ts
CHANGED
|
@@ -2,24 +2,26 @@ import type { DynamicAttribute } from '@vtex-email/core';
|
|
|
2
2
|
import type { ReactNode } from 'react';
|
|
3
3
|
import { type Session } from '../compile/session';
|
|
4
4
|
import { type Expression } from './expr';
|
|
5
|
-
export
|
|
5
|
+
export type AttributeValue = string | Expression | ReadonlyArray<string | Expression>;
|
|
6
|
+
export declare function attributeToken(name: DynamicAttribute, value: AttributeValue): string;
|
|
6
7
|
export declare function rejectClassExpression(className: string | Expression | undefined, session: Session): string | undefined;
|
|
7
8
|
export declare function DynamicLink({ href, title, children, className, }: {
|
|
8
|
-
href:
|
|
9
|
-
title?:
|
|
9
|
+
href: AttributeValue;
|
|
10
|
+
title?: AttributeValue;
|
|
10
11
|
children?: ReactNode;
|
|
11
12
|
className?: string | Expression;
|
|
12
13
|
}): import("react/jsx-runtime").JSX.Element;
|
|
13
|
-
export declare function DynamicImg({ src, alt, title, width, height, }: {
|
|
14
|
-
src:
|
|
15
|
-
alt:
|
|
16
|
-
title?:
|
|
17
|
-
width
|
|
18
|
-
height
|
|
14
|
+
export declare function DynamicImg({ src, alt, title, width, height, style, }: {
|
|
15
|
+
src: AttributeValue;
|
|
16
|
+
alt: AttributeValue;
|
|
17
|
+
title?: AttributeValue;
|
|
18
|
+
width?: number | `${number}`;
|
|
19
|
+
height?: number | `${number}`;
|
|
20
|
+
style?: React.CSSProperties;
|
|
19
21
|
}): import("react/jsx-runtime").JSX.Element;
|
|
20
22
|
export declare function DynamicButton({ href, title, children, className, }: {
|
|
21
|
-
href:
|
|
22
|
-
title?:
|
|
23
|
+
href: AttributeValue;
|
|
24
|
+
title?: AttributeValue;
|
|
23
25
|
children?: ReactNode;
|
|
24
26
|
className?: string | Expression;
|
|
25
27
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../src/dsl/attributes.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../src/dsl/attributes.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAgB,MAAM,kBAAkB,CAAA;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAKtC,OAAO,EAAkC,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAA;AACjF,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,QAAQ,CAAA;AAGtD,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,UAAU,GAAG,aAAa,CAAC,MAAM,GAAG,UAAU,CAAC,CAAA;AAmCrF,wBAAgB,cAAc,CAAC,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,cAAc,GAAG,MAAM,CAuDpF;AAED,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,EAC1C,OAAO,EAAE,OAAO,GACf,MAAM,GAAG,SAAS,CAMpB;AAED,wBAAgB,WAAW,CAAC,EAC1B,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,SAAS,GACV,EAAE;IACD,IAAI,EAAE,cAAc,CAAA;IACpB,KAAK,CAAC,EAAE,cAAc,CAAA;IACtB,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;CAChC,2CAWA;AAED,wBAAgB,UAAU,CAAC,EACzB,GAAG,EACH,GAAG,EACH,KAAK,EACL,KAAK,EACL,MAAM,EACN,KAAK,GACN,EAAE;IACD,GAAG,EAAE,cAAc,CAAA;IACnB,GAAG,EAAE,cAAc,CAAA;IACnB,KAAK,CAAC,EAAE,cAAc,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,GAAG,GAAG,MAAM,EAAE,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,GAAG,GAAG,MAAM,EAAE,CAAA;IAC7B,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;CAC5B,2CAWA;AAED,wBAAgB,aAAa,CAAC,EAC5B,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,SAAS,GACV,EAAE;IACD,IAAI,EAAE,cAAc,CAAA;IACpB,KAAK,CAAC,EAAE,cAAc,CAAA;IACtB,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;CAChC,2CAWA"}
|
package/dist/dsl/blocks.d.ts
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
import type { BlockName } from '@vtex-email/core';
|
|
1
|
+
import type { BlockName, SiteArgument, SiteHash } from '@vtex-email/core';
|
|
2
2
|
import { type ReactElement, type ReactNode } from 'react';
|
|
3
|
+
import { type Expression } from './expr';
|
|
4
|
+
/** Compiler-owned host for block regions. Authors never see or forward this. */
|
|
5
|
+
export declare const BLOCK_HOST = "vtx-anchor";
|
|
3
6
|
export declare function stamp(children: ReactNode, token: string): ReactElement;
|
|
4
|
-
export declare function openRegion(path: string, block: BlockName, hasElse: boolean
|
|
7
|
+
export declare function openRegion(path: string, block: BlockName, hasElse: boolean, extras?: {
|
|
8
|
+
args?: readonly SiteArgument[];
|
|
9
|
+
hash?: SiteHash;
|
|
10
|
+
}): {
|
|
5
11
|
openId: string;
|
|
6
12
|
elseId: string | null;
|
|
7
13
|
};
|
|
8
|
-
export declare function blockRegion(path: string, block: BlockName, children: ReactNode, fallback: ReactNode | undefined
|
|
14
|
+
export declare function blockRegion(path: string, block: BlockName, children: ReactNode, fallback: ReactNode | undefined, extras?: {
|
|
15
|
+
args?: readonly SiteArgument[];
|
|
16
|
+
hash?: SiteHash;
|
|
17
|
+
}): ReactNode;
|
|
9
18
|
export declare function Each({ path, children, fallback }: {
|
|
10
19
|
path: string;
|
|
11
20
|
children: ReactNode;
|
|
@@ -21,4 +30,53 @@ export declare function Unless({ path, children, fallback }: {
|
|
|
21
30
|
children: ReactNode;
|
|
22
31
|
fallback?: ReactNode;
|
|
23
32
|
}): ReactNode;
|
|
33
|
+
type ComparisonOperator = '==' | '===' | '!=' | '<' | '<=' | '>' | '>=';
|
|
34
|
+
export declare function IfCond({ path, operator, value, right, children, fallback, }: {
|
|
35
|
+
path: string;
|
|
36
|
+
operator: ComparisonOperator;
|
|
37
|
+
value?: string | number | boolean | null;
|
|
38
|
+
right?: Expression | string | number | boolean | null;
|
|
39
|
+
children: ReactNode;
|
|
40
|
+
fallback?: ReactNode;
|
|
41
|
+
}): ReactNode;
|
|
42
|
+
export declare function HasSubStr({ path, value, search, children, fallback, }: {
|
|
43
|
+
path: string;
|
|
44
|
+
value?: string;
|
|
45
|
+
search?: Expression | string;
|
|
46
|
+
children: ReactNode;
|
|
47
|
+
fallback?: ReactNode;
|
|
48
|
+
}): ReactNode;
|
|
49
|
+
export declare function Eq({ path, value, right, children, fallback, }: {
|
|
50
|
+
path: string;
|
|
51
|
+
value?: string | number | boolean | null;
|
|
52
|
+
right?: Expression | string | number | boolean | null;
|
|
53
|
+
children: ReactNode;
|
|
54
|
+
fallback?: ReactNode;
|
|
55
|
+
}): ReactNode;
|
|
56
|
+
export declare function Group({ path, by, children, fallback, }: {
|
|
57
|
+
path: string;
|
|
58
|
+
by: string;
|
|
59
|
+
children: ReactNode;
|
|
60
|
+
fallback?: ReactNode;
|
|
61
|
+
}): ReactNode;
|
|
62
|
+
export declare function With({ path, children, fallback }: {
|
|
63
|
+
path: string;
|
|
64
|
+
children: ReactNode;
|
|
65
|
+
fallback?: ReactNode;
|
|
66
|
+
}): ReactNode;
|
|
67
|
+
type MathOperator = '+' | '-' | '*' | '/' | '%';
|
|
68
|
+
export declare function Math({ path, left, operator, right, form, children, }: {
|
|
69
|
+
path?: string;
|
|
70
|
+
left?: Expression | string | number;
|
|
71
|
+
operator: MathOperator;
|
|
72
|
+
right: Expression | string | number;
|
|
73
|
+
form?: 'inline' | 'block';
|
|
74
|
+
children?: ReactNode;
|
|
75
|
+
}): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined;
|
|
76
|
+
export declare function RichShippingData({ path, children, fallback, }: {
|
|
77
|
+
path: string;
|
|
78
|
+
children: ReactNode;
|
|
79
|
+
fallback?: ReactNode;
|
|
80
|
+
}): ReactNode;
|
|
81
|
+
export type { Expression };
|
|
24
82
|
//# sourceMappingURL=blocks.d.ts.map
|
package/dist/dsl/blocks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../src/dsl/blocks.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAc,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../src/dsl/blocks.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAc,YAAY,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAErF,OAAO,EAAiB,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAGxE,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,QAAQ,CAAA;AAI9C,gFAAgF;A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F,QAAQ,EACR,QAAQ,GACT,EAAE;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,SAAS,CAAA;IACnB,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB,aAQA;AAED,wBAAgB,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,aAE7G;AAED,KAAK,YAAY,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;AAE/C,wBAAgB,IAAI,CAAC,EACnB,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,KAAK,EACL,IAAe,EACf,QAAQ,GACT,EAAE;IACD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,CAAA;IACnC,QAAQ,EAAE,YAAY,CAAA;IACtB,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,CAAA;IACnC,IAAI,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAA;IACzB,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB,2TAeA;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,IAAI,EACJ,QAAQ,EACR,QAAQ,GACT,EAAE;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,SAAS,CAAA;IACnB,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB,aAEA;AAED,YAAY,EAAE,UAAU,EAAE,CAAA"}
|
package/dist/dsl/vtex.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DynamicButton, DynamicImg, DynamicLink } from './attributes';
|
|
2
|
-
import { Each, If, Unless } from './blocks';
|
|
2
|
+
import { Each, Eq, Group, HasSubStr, If, IfCond, Math, RichShippingData, Unless, With } from './blocks';
|
|
3
3
|
import { expr } from './expr';
|
|
4
4
|
import { Trans } from './trans';
|
|
5
5
|
import { Helper, Value } from './values';
|
|
@@ -7,11 +7,18 @@ export declare const Vtex: {
|
|
|
7
7
|
Each: typeof Each;
|
|
8
8
|
If: typeof If;
|
|
9
9
|
Unless: typeof Unless;
|
|
10
|
+
IfCond: typeof IfCond;
|
|
11
|
+
HasSubStr: typeof HasSubStr;
|
|
12
|
+
Group: typeof Group;
|
|
13
|
+
Eq: typeof Eq;
|
|
14
|
+
With: typeof With;
|
|
15
|
+
Math: typeof Math;
|
|
16
|
+
RichShippingData: typeof RichShippingData;
|
|
10
17
|
Value: typeof Value;
|
|
11
18
|
Helper: typeof Helper;
|
|
12
19
|
Link: typeof DynamicLink;
|
|
13
20
|
Img: typeof DynamicImg;
|
|
14
21
|
Button: typeof DynamicButton;
|
|
15
22
|
};
|
|
16
|
-
export { Each, expr, Helper, If, Trans, Unless, Value };
|
|
23
|
+
export { Each, Eq, expr, Group, HasSubStr, Helper, If, IfCond, Math, RichShippingData, Trans, Unless, Value, With };
|
|
17
24
|
//# sourceMappingURL=vtex.d.ts.map
|
package/dist/dsl/vtex.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vtex.d.ts","sourceRoot":"","sources":["../../src/dsl/vtex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AACrE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"vtex.d.ts","sourceRoot":"","sources":["../../src/dsl/vtex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AACrE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AACvG,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAExC,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;CAgBhB,CAAA;AAED,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ export { Email } from './adapter/email';
|
|
|
2
2
|
export { diagnoseStyles } from './adapter/style-diagnostics';
|
|
3
3
|
export { compileEmail, type BuildManifest, type CompiledArtifact, type CompileEmailInput, type CompileEmailResult, } from './compile/compile-email';
|
|
4
4
|
export { isExpression, type Expression } from './dsl/expr';
|
|
5
|
-
export { Each, expr, Helper, If, Trans, Unless, Value, Vtex } from './dsl/vtex';
|
|
5
|
+
export { Each, Eq, expr, Group, HasSubStr, Helper, If, IfCond, Math, RichShippingData, Trans, Unless, Value, Vtex, With, } from './dsl/vtex';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,EACL,YAAY,EACZ,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,GACxB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,YAAY,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAA;AAC1D,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,EACL,YAAY,EACZ,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,GACxB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,YAAY,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAA;AAC1D,OAAO,EACL,IAAI,EACJ,EAAE,EACF,IAAI,EACJ,KAAK,EACL,SAAS,EACT,MAAM,EACN,EAAE,EACF,MAAM,EACN,IAAI,EACJ,gBAAgB,EAChB,KAAK,EACL,MAAM,EACN,KAAK,EACL,IAAI,EACJ,IAAI,GACL,MAAM,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -248,12 +248,52 @@ function assertStaticUrl(value, session) {
|
|
|
248
248
|
dslFailure(session, "HBS001", `URL scheme is not allowed: ${url.protocol}`);
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
|
+
function readCompositePart(part, session) {
|
|
252
|
+
if (typeof part === "string") {
|
|
253
|
+
if (part.includes('"') || part.includes("\n") || part.includes("\r")) {
|
|
254
|
+
dslFailure(session, "HBS001", "Composite attribute literals cannot contain quotes or newlines.");
|
|
255
|
+
}
|
|
256
|
+
return { kind: "literal", emitted: part };
|
|
257
|
+
}
|
|
258
|
+
if (!isExpression(part)) {
|
|
259
|
+
dslFailure(session, "DSL002", "A dynamic attribute requires expr.path or expr.literal.");
|
|
260
|
+
}
|
|
261
|
+
if (part.kind === "literal") {
|
|
262
|
+
const text = part.value === null || typeof part.value === "boolean" ? String(part.value) : String(part.value);
|
|
263
|
+
if (text.includes('"') || text.includes("\n") || text.includes("\r")) {
|
|
264
|
+
dslFailure(session, "HBS001", "Composite attribute literals cannot contain quotes or newlines.");
|
|
265
|
+
}
|
|
266
|
+
return { kind: "literal", emitted: text };
|
|
267
|
+
}
|
|
268
|
+
const resolved = resolvePath(part.value, session);
|
|
269
|
+
return { kind: "path", emitted: resolved.emitted, path: resolved };
|
|
270
|
+
}
|
|
251
271
|
function attributeToken(name, value) {
|
|
252
272
|
const session = getSession();
|
|
253
273
|
if (typeof value === "string") {
|
|
254
274
|
if (name === "href" || name === "src") assertStaticUrl(value, session);
|
|
255
275
|
return value;
|
|
256
276
|
}
|
|
277
|
+
if (Array.isArray(value)) {
|
|
278
|
+
if (value.length === 0) dslFailure(session, "DSL002", "A composite attribute requires at least one part.");
|
|
279
|
+
const parts = value.map((part) => readCompositePart(part, session));
|
|
280
|
+
const hasPath = parts.some((part) => part.kind === "path");
|
|
281
|
+
if (!hasPath && (name === "href" || name === "src")) {
|
|
282
|
+
assertStaticUrl(parts.map((part) => part.emitted).join(""), session);
|
|
283
|
+
}
|
|
284
|
+
const detail = parts.map((part) => part.emitted).join("");
|
|
285
|
+
const token2 = addMarker(
|
|
286
|
+
session,
|
|
287
|
+
{ kind: "attr", path: name, detail },
|
|
288
|
+
{
|
|
289
|
+
kind: "attr",
|
|
290
|
+
attribute: name,
|
|
291
|
+
replacement: ""
|
|
292
|
+
}
|
|
293
|
+
);
|
|
294
|
+
addSite(session, token2, { kind: "attr", attribute: name, args: parts });
|
|
295
|
+
return token2;
|
|
296
|
+
}
|
|
257
297
|
if (!isExpression(value)) {
|
|
258
298
|
dslFailure(session, "DSL002", "A dynamic attribute requires expr.path or expr.literal.");
|
|
259
299
|
}
|
|
@@ -313,7 +353,8 @@ function DynamicImg({
|
|
|
313
353
|
alt,
|
|
314
354
|
title,
|
|
315
355
|
width,
|
|
316
|
-
height
|
|
356
|
+
height,
|
|
357
|
+
style
|
|
317
358
|
}) {
|
|
318
359
|
return /* @__PURE__ */ jsx2(
|
|
319
360
|
EmailImg,
|
|
@@ -321,6 +362,7 @@ function DynamicImg({
|
|
|
321
362
|
alt: attributeToken("alt", alt),
|
|
322
363
|
height,
|
|
323
364
|
src: attributeToken("src", src),
|
|
365
|
+
style,
|
|
324
366
|
title: title === void 0 ? void 0 : attributeToken("title", title),
|
|
325
367
|
width
|
|
326
368
|
}
|
|
@@ -345,65 +387,7 @@ function DynamicButton({
|
|
|
345
387
|
}
|
|
346
388
|
|
|
347
389
|
// src/dsl/blocks.tsx
|
|
348
|
-
import {
|
|
349
|
-
import { Fragment as Fragment2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
350
|
-
function stamp(children, token) {
|
|
351
|
-
const session = getSession();
|
|
352
|
-
let only;
|
|
353
|
-
try {
|
|
354
|
-
const child = Children.only(children);
|
|
355
|
-
if (!isValidElement(child) || child.type === Fragment) throw new Error("not an element");
|
|
356
|
-
only = child;
|
|
357
|
-
} catch (error) {
|
|
358
|
-
if (error instanceof Error && error.name === "CompileAborted") throw error;
|
|
359
|
-
dslFailure(session, "DSL002", "Each DSL block requires a single root element.");
|
|
360
|
-
}
|
|
361
|
-
return cloneElement(only, { "data-anchor": token });
|
|
362
|
-
}
|
|
363
|
-
function openRegion(path, block, hasElse) {
|
|
364
|
-
const session = getSession();
|
|
365
|
-
const resolved = resolvePath(path, session);
|
|
366
|
-
const marker = {
|
|
367
|
-
kind: "open",
|
|
368
|
-
open: "",
|
|
369
|
-
close: "",
|
|
370
|
-
elseId: null
|
|
371
|
-
};
|
|
372
|
-
const openId = addMarker(session, { kind: "open", path: resolved.emitted, detail: block }, marker);
|
|
373
|
-
addSite(session, openId, { kind: "block", block, path: resolved });
|
|
374
|
-
if (!hasElse) return { openId, elseId: null };
|
|
375
|
-
const elseId = addMarker(
|
|
376
|
-
session,
|
|
377
|
-
{ kind: "else", path: resolved.emitted, detail: `${block}:else` },
|
|
378
|
-
{
|
|
379
|
-
kind: "else",
|
|
380
|
-
openId
|
|
381
|
-
}
|
|
382
|
-
);
|
|
383
|
-
marker.elseId = elseId;
|
|
384
|
-
return { openId, elseId };
|
|
385
|
-
}
|
|
386
|
-
function blockRegion(path, block, children, fallback) {
|
|
387
|
-
const region = openRegion(path, block, fallback !== void 0);
|
|
388
|
-
const thenNode = stamp(children, region.openId);
|
|
389
|
-
if (!region.elseId || fallback === void 0) return thenNode;
|
|
390
|
-
return /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
391
|
-
thenNode,
|
|
392
|
-
stamp(fallback, region.elseId)
|
|
393
|
-
] });
|
|
394
|
-
}
|
|
395
|
-
function Each({ path, children, fallback }) {
|
|
396
|
-
return blockRegion(path, "each", children, fallback);
|
|
397
|
-
}
|
|
398
|
-
function If({ path, children, fallback }) {
|
|
399
|
-
return blockRegion(path, "if", children, fallback);
|
|
400
|
-
}
|
|
401
|
-
function Unless({ path, children, fallback }) {
|
|
402
|
-
return blockRegion(path, "unless", children, fallback);
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
// src/dsl/trans.tsx
|
|
406
|
-
import { parseMessage } from "@vtex-email/core";
|
|
390
|
+
import { createElement as createElement2 } from "react";
|
|
407
391
|
|
|
408
392
|
// src/dsl/values.tsx
|
|
409
393
|
import { emitLiteral as emitLiteral3 } from "@vtex-email/core";
|
|
@@ -454,8 +438,155 @@ function Helper({ name, args }) {
|
|
|
454
438
|
return /* @__PURE__ */ jsx3("span", { "data-anchor": token, children: "\u200B" });
|
|
455
439
|
}
|
|
456
440
|
|
|
441
|
+
// src/dsl/blocks.tsx
|
|
442
|
+
import { Fragment, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
443
|
+
var BLOCK_HOST = "vtx-anchor";
|
|
444
|
+
function stamp(children, token) {
|
|
445
|
+
return createElement2(BLOCK_HOST, { "data-anchor": token }, children);
|
|
446
|
+
}
|
|
447
|
+
function openRegion(path, block, hasElse, extras = {}) {
|
|
448
|
+
const session = getSession();
|
|
449
|
+
const resolved = resolvePath(path, session);
|
|
450
|
+
const marker = {
|
|
451
|
+
kind: "open",
|
|
452
|
+
open: "",
|
|
453
|
+
close: "",
|
|
454
|
+
elseId: null
|
|
455
|
+
};
|
|
456
|
+
const openId = addMarker(session, { kind: "open", path: resolved.emitted, detail: block }, marker);
|
|
457
|
+
addSite(session, openId, {
|
|
458
|
+
kind: "block",
|
|
459
|
+
block,
|
|
460
|
+
path: resolved,
|
|
461
|
+
...extras.args ? { args: extras.args } : {},
|
|
462
|
+
...extras.hash ? { hash: extras.hash } : {}
|
|
463
|
+
});
|
|
464
|
+
if (!hasElse) return { openId, elseId: null };
|
|
465
|
+
const elseId = addMarker(
|
|
466
|
+
session,
|
|
467
|
+
{ kind: "else", path: resolved.emitted, detail: `${block}:else` },
|
|
468
|
+
{
|
|
469
|
+
kind: "else",
|
|
470
|
+
openId
|
|
471
|
+
}
|
|
472
|
+
);
|
|
473
|
+
marker.elseId = elseId;
|
|
474
|
+
return { openId, elseId };
|
|
475
|
+
}
|
|
476
|
+
function blockRegion(path, block, children, fallback, extras = {}) {
|
|
477
|
+
const region = openRegion(path, block, fallback !== void 0, extras);
|
|
478
|
+
const thenNode = stamp(children, region.openId);
|
|
479
|
+
if (!region.elseId || fallback === void 0) return thenNode;
|
|
480
|
+
return /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
481
|
+
thenNode,
|
|
482
|
+
stamp(fallback, region.elseId)
|
|
483
|
+
] });
|
|
484
|
+
}
|
|
485
|
+
function Each({ path, children, fallback }) {
|
|
486
|
+
return blockRegion(path, "each", children, fallback);
|
|
487
|
+
}
|
|
488
|
+
function If({ path, children, fallback }) {
|
|
489
|
+
return blockRegion(path, "if", children, fallback);
|
|
490
|
+
}
|
|
491
|
+
function Unless({ path, children, fallback }) {
|
|
492
|
+
return blockRegion(path, "unless", children, fallback);
|
|
493
|
+
}
|
|
494
|
+
function asExpression(value, session) {
|
|
495
|
+
if (value === void 0) dslFailure(session, "HBS002", "A comparison operand is required.");
|
|
496
|
+
if (typeof value === "object" && value !== null && "kind" in value) return value;
|
|
497
|
+
return expr.literal(value);
|
|
498
|
+
}
|
|
499
|
+
function IfCond({
|
|
500
|
+
path,
|
|
501
|
+
operator,
|
|
502
|
+
value,
|
|
503
|
+
right,
|
|
504
|
+
children,
|
|
505
|
+
fallback
|
|
506
|
+
}) {
|
|
507
|
+
const session = getSession();
|
|
508
|
+
const operand = right !== void 0 ? asExpression(right, session) : asExpression(value, session);
|
|
509
|
+
return blockRegion(path, "ifCond", children, fallback, {
|
|
510
|
+
args: [readArgument(expr.literal(operator), session), readArgument(operand, session)]
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
function HasSubStr({
|
|
514
|
+
path,
|
|
515
|
+
value,
|
|
516
|
+
search,
|
|
517
|
+
children,
|
|
518
|
+
fallback
|
|
519
|
+
}) {
|
|
520
|
+
const session = getSession();
|
|
521
|
+
const operand = search !== void 0 ? asExpression(search, session) : asExpression(value, session);
|
|
522
|
+
return blockRegion(path, "hasSubStr", children, fallback, {
|
|
523
|
+
args: [readArgument(operand, session)]
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
function Eq({
|
|
527
|
+
path,
|
|
528
|
+
value,
|
|
529
|
+
right,
|
|
530
|
+
children,
|
|
531
|
+
fallback
|
|
532
|
+
}) {
|
|
533
|
+
const session = getSession();
|
|
534
|
+
const operand = right !== void 0 ? asExpression(right, session) : asExpression(value, session);
|
|
535
|
+
return blockRegion(path, "eq", children, fallback, {
|
|
536
|
+
args: [readArgument(operand, session)]
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
function Group({
|
|
540
|
+
path,
|
|
541
|
+
by,
|
|
542
|
+
children,
|
|
543
|
+
fallback
|
|
544
|
+
}) {
|
|
545
|
+
const session = getSession();
|
|
546
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(by)) {
|
|
547
|
+
dslFailure(session, "HBS002", "Group by must be an identifier.");
|
|
548
|
+
}
|
|
549
|
+
return blockRegion(path, "group", children, fallback, {
|
|
550
|
+
hash: { by: readArgument(expr.literal(by), session) }
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
function With({ path, children, fallback }) {
|
|
554
|
+
return blockRegion(path, "with", children, fallback);
|
|
555
|
+
}
|
|
556
|
+
function Math({
|
|
557
|
+
path,
|
|
558
|
+
left,
|
|
559
|
+
operator,
|
|
560
|
+
right,
|
|
561
|
+
form = "inline",
|
|
562
|
+
children
|
|
563
|
+
}) {
|
|
564
|
+
const session = getSession();
|
|
565
|
+
const rightArg = asExpression(right, session);
|
|
566
|
+
if (form === "block") {
|
|
567
|
+
let leftPath = path ?? null;
|
|
568
|
+
if (!leftPath && typeof left === "string") leftPath = left;
|
|
569
|
+
if (!leftPath && left && typeof left === "object" && left.kind === "path") leftPath = left.value;
|
|
570
|
+
if (!leftPath) dslFailure(session, "HBS002", "Block math requires a left path.");
|
|
571
|
+
return blockRegion(leftPath, "math", children ?? /* @__PURE__ */ jsx4("span", { children: "\u200B" }), void 0, {
|
|
572
|
+
args: [readArgument(expr.literal(operator), session), readArgument(rightArg, session)]
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
const leftArg = left !== void 0 ? asExpression(left, session) : path ? expr.path(path) : null;
|
|
576
|
+
if (!leftArg) dslFailure(session, "HBS002", "Inline math requires a left operand.");
|
|
577
|
+
return /* @__PURE__ */ jsx4(Helper, { args: [leftArg, expr.literal(operator), rightArg], name: "math" });
|
|
578
|
+
}
|
|
579
|
+
function RichShippingData({
|
|
580
|
+
path,
|
|
581
|
+
children,
|
|
582
|
+
fallback
|
|
583
|
+
}) {
|
|
584
|
+
return blockRegion(path, "richShippingData", children, fallback);
|
|
585
|
+
}
|
|
586
|
+
|
|
457
587
|
// src/dsl/trans.tsx
|
|
458
|
-
import {
|
|
588
|
+
import { parseMessage } from "@vtex-email/core";
|
|
589
|
+
import { Fragment as Fragment2, jsx as jsx5 } from "react/jsx-runtime";
|
|
459
590
|
function Trans({ id, values }) {
|
|
460
591
|
const session = getSession();
|
|
461
592
|
const text = session.catalog[id];
|
|
@@ -471,7 +602,7 @@ function Trans({ id, values }) {
|
|
|
471
602
|
if (provided.join("\0") !== expected.join("\0")) {
|
|
472
603
|
dslFailure(session, "I18N001", `Placeholders for ${id} do not match the catalog.`, { locale: session.locale });
|
|
473
604
|
}
|
|
474
|
-
return /* @__PURE__ */
|
|
605
|
+
return /* @__PURE__ */ jsx5(Fragment2, { children: parsed.parts.map((part) => {
|
|
475
606
|
if (part.type === "text") return part.value;
|
|
476
607
|
const value = values?.[part.name];
|
|
477
608
|
if (!value) {
|
|
@@ -487,6 +618,13 @@ var Vtex = {
|
|
|
487
618
|
Each,
|
|
488
619
|
If,
|
|
489
620
|
Unless,
|
|
621
|
+
IfCond,
|
|
622
|
+
HasSubStr,
|
|
623
|
+
Group,
|
|
624
|
+
Eq,
|
|
625
|
+
With,
|
|
626
|
+
Math,
|
|
627
|
+
RichShippingData,
|
|
490
628
|
Value,
|
|
491
629
|
Helper,
|
|
492
630
|
Link: DynamicLink,
|
|
@@ -496,12 +634,19 @@ var Vtex = {
|
|
|
496
634
|
export {
|
|
497
635
|
Each,
|
|
498
636
|
Email,
|
|
637
|
+
Eq,
|
|
638
|
+
Group,
|
|
639
|
+
HasSubStr,
|
|
499
640
|
Helper,
|
|
500
641
|
If,
|
|
642
|
+
IfCond,
|
|
643
|
+
Math,
|
|
644
|
+
RichShippingData,
|
|
501
645
|
Trans,
|
|
502
646
|
Unless,
|
|
503
647
|
Value,
|
|
504
648
|
Vtex,
|
|
649
|
+
With,
|
|
505
650
|
compileEmail,
|
|
506
651
|
diagnoseStyles,
|
|
507
652
|
expr,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtex-email/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/marcelotk15/vtex-react-email.git"
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@react-email/components": "1.0.12",
|
|
22
|
-
"@vtex-email/core": "0.
|
|
22
|
+
"@vtex-email/core": "0.3.0",
|
|
23
23
|
"react": "19.3.0",
|
|
24
24
|
"react-dom": "19.3.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@vtex-email/vtex": "0.
|
|
27
|
+
"@vtex-email/vtex": "0.3.0",
|
|
28
28
|
"zod": "4.6.5"
|
|
29
29
|
}
|
|
30
30
|
}
|