@travetto/email-inky 5.0.0-rc.1 → 5.0.0-rc.11
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/jsx-runtime.ts +6 -8
- package/package.json +6 -6
- package/src/components.ts +2 -3
- package/src/render/common.ts +2 -3
- package/src/render/context.ts +2 -4
- package/src/render/html.ts +3 -4
- package/src/render/markdown.ts +2 -2
- package/src/render/renderer.ts +3 -4
package/jsx-runtime.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { castTo, Class } from '@travetto/runtime';
|
|
2
2
|
import { EmailTemplateModule, EmailTemplateLocation } from '@travetto/email';
|
|
3
3
|
|
|
4
4
|
export type JSXChild = JSXElement | number | bigint | boolean | object | string;
|
|
@@ -13,7 +13,7 @@ let id = 0;
|
|
|
13
13
|
|
|
14
14
|
/** Simple JSX Element */
|
|
15
15
|
export interface JSXElement<
|
|
16
|
-
T extends string |
|
|
16
|
+
T extends string | Class | JSXComponentFunction<P> = string | Class | JSXComponentFunction,
|
|
17
17
|
P extends {} = {},
|
|
18
18
|
> {
|
|
19
19
|
[JSXRuntimeTag]?: { id: number };
|
|
@@ -57,23 +57,21 @@ declare global {
|
|
|
57
57
|
|
|
58
58
|
let createFrag: Function | undefined = undefined;
|
|
59
59
|
|
|
60
|
-
export function createElement<T extends string |
|
|
60
|
+
export function createElement<T extends string | Class | JSXComponentFunction<P>, P extends {}>(
|
|
61
61
|
type: T, props: P & JSXProps
|
|
62
62
|
): JSXElement<T, P> {
|
|
63
|
-
|
|
64
|
-
type = (type === createFrag ? JSXFragmentType : type) as T;
|
|
63
|
+
type = castTo(type === createFrag ? JSXFragmentType : type);
|
|
65
64
|
return { [JSXRuntimeTag]: { id: (id += 1) }, type, key: '', props };
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
export function createRootElement<T extends string |
|
|
67
|
+
export function createRootElement<T extends string | Class | JSXComponentFunction<P>, P extends {}>(
|
|
69
68
|
type: T, props: P & JSXProps
|
|
70
69
|
): JSXElement<T, P> {
|
|
71
70
|
const res = createElement(type, props);
|
|
72
71
|
|
|
73
72
|
Object.assign(res, {
|
|
74
73
|
prepare(loc: EmailTemplateLocation): Promise<EmailTemplateModule> {
|
|
75
|
-
|
|
76
|
-
return import('@travetto/email-inky/src/wrapper').then(v => v.prepare(res as JSXElement, loc));
|
|
74
|
+
return import('@travetto/email-inky/src/wrapper').then(v => v.prepare(castTo(res), loc));
|
|
77
75
|
}
|
|
78
76
|
});
|
|
79
77
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/email-inky",
|
|
3
|
-
"version": "5.0.0-rc.
|
|
3
|
+
"version": "5.0.0-rc.11",
|
|
4
4
|
"description": "Email Inky templating module",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"email",
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
"directory": "module/email-inky"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@travetto/
|
|
31
|
-
"@travetto/
|
|
32
|
-
"@travetto/
|
|
33
|
-
"@travetto/
|
|
30
|
+
"@travetto/config": "^5.0.0-rc.11",
|
|
31
|
+
"@travetto/di": "^5.0.0-rc.10",
|
|
32
|
+
"@travetto/email": "^5.0.0-rc.11",
|
|
33
|
+
"@travetto/runtime": "^5.0.0-rc.10",
|
|
34
34
|
"foundation-emails": "^2.4.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@travetto/email-compiler": "^5.0.0-rc.
|
|
37
|
+
"@travetto/email-compiler": "^5.0.0-rc.11"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@travetto/cli": {
|
package/src/components.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSXElement, JSXComponentFunction as CompFn } from '@travetto/email-inky/jsx-runtime';
|
|
2
|
-
import { TypedObject } from '@travetto/
|
|
2
|
+
import { TypedObject } from '@travetto/runtime';
|
|
3
3
|
|
|
4
4
|
const EMPTY: JSXElement = { type: '', key: '', props: {} };
|
|
5
5
|
|
|
@@ -49,8 +49,7 @@ export type JSXElements = { [K in keyof C]: JSXElementByFn<K>; };
|
|
|
49
49
|
|
|
50
50
|
export const EMPTY_ELEMENT = EMPTY;
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
const invertedC = new Map<Function, string>(TypedObject.entries(c).map(p => [p[1], p[0]] as [CompFn, string]));
|
|
52
|
+
const invertedC = new Map<Function, string>(TypedObject.entries(c).map(p => [p[1], p[0]] as const));
|
|
54
53
|
|
|
55
54
|
export function getComponentName(fn: Function | string): string {
|
|
56
55
|
if (typeof fn === 'string') {
|
package/src/render/common.ts
CHANGED
|
@@ -42,9 +42,8 @@ export const classStr = (existing: string | undefined, ...toAdd: string[]): stri
|
|
|
42
42
|
return out.join(' ');
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
export const combinePropsToStr = (allowedProps: Set<string>, props: Record<string, unknown>, addClasses: string[] = []): string => {
|
|
46
|
-
|
|
47
|
-
const out = { ...props, className: classStr(props.className as string, ...addClasses) };
|
|
45
|
+
export const combinePropsToStr = (allowedProps: Set<string>, props: { className?: string } & Record<string, unknown>, addClasses: string[] = []): string => {
|
|
46
|
+
const out = { ...props, className: classStr(props.className, ...addClasses) };
|
|
48
47
|
return Object.entries(out)
|
|
49
48
|
.filter(([k, v]) => allowedProps.has(k) && v !== undefined && v !== null && v !== '')
|
|
50
49
|
.map(([k, v]) => [k === 'className' ? 'class' : k, v])
|
package/src/render/context.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createElement } from '@travetto/email-inky/jsx-runtime';
|
|
2
|
-
import { FileLoader } from '@travetto/
|
|
2
|
+
import { castTo, FileLoader } from '@travetto/runtime';
|
|
3
3
|
import { EmailTemplateLocation, EmailResourceLoader } from '@travetto/email';
|
|
4
4
|
|
|
5
5
|
import { JSXElementByFn, c } from '../components';
|
|
@@ -25,8 +25,6 @@ export class RenderContext implements RenderContextInit {
|
|
|
25
25
|
* Create a new element from a given JSX factory
|
|
26
26
|
*/
|
|
27
27
|
createElement<K extends keyof typeof c>(name: K, props: JSXElementByFn<K>['props']): JSXElementByFn<K> {
|
|
28
|
-
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
30
|
-
return createElement(c[name], props) as JSXElementByFn<K>;
|
|
28
|
+
return castTo(createElement(castTo<Record<string, string>>(c)[name], props));
|
|
31
29
|
}
|
|
32
30
|
}
|
package/src/render/html.ts
CHANGED
|
@@ -89,10 +89,9 @@ export const Html: RenderProvider<RenderContext> = {
|
|
|
89
89
|
const colCount = sibs.length || 1;
|
|
90
90
|
|
|
91
91
|
if (parent) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
pProps.columnVisited = true;
|
|
92
|
+
const elParent: (typeof parent) & { columnVisited?: boolean } = parent;
|
|
93
|
+
if (!elParent.columnVisited) {
|
|
94
|
+
elParent.columnVisited = true;
|
|
96
95
|
if (sibs.length) {
|
|
97
96
|
sibs[0].props.className = classStr(sibs[0].props.className ?? '', 'first');
|
|
98
97
|
sibs[sibs.length - 1].props.className = classStr(sibs[sibs.length - 1].props.className ?? '', 'last');
|
package/src/render/markdown.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { JSXElement } from '@travetto/email-inky/jsx-runtime';
|
|
2
2
|
import { RenderProvider, RenderState } from '../types';
|
|
3
3
|
import { RenderContext } from './context';
|
|
4
|
+
import { castTo } from '@travetto/runtime';
|
|
4
5
|
|
|
5
6
|
const visit = ({ recurse }: RenderState<JSXElement, RenderContext>): Promise<string> => recurse();
|
|
6
7
|
const ignore = async ({ recurse: _ }: RenderState<JSXElement, RenderContext>): Promise<string> => '';
|
|
@@ -42,8 +43,7 @@ export const Markdown: RenderProvider<RenderContext> = {
|
|
|
42
43
|
h2: async ({ recurse }) => `\n## ${await recurse()}\n\n`,
|
|
43
44
|
h3: async ({ recurse }) => `\n### ${await recurse()}\n\n`,
|
|
44
45
|
h4: async ({ recurse }) => `\n#### ${await recurse()}\n\n`,
|
|
45
|
-
|
|
46
|
-
a: async ({ recurse, props }) => `\n[${await recurse()}](${(props as { href: string }).href})\n`,
|
|
46
|
+
a: async ({ recurse, props }) => `\n[${await recurse()}](${(castTo<{ href: string }>(props)).href})\n`,
|
|
47
47
|
Button: async ({ recurse, props }) => `\n[${await recurse()}](${props.href})\n`,
|
|
48
48
|
|
|
49
49
|
InkyTemplate: visit,
|
package/src/render/renderer.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { isJSXElement, JSXElement, createFragment, JSXFragmentType, JSXChild } f
|
|
|
3
3
|
import { EMPTY_ELEMENT, getComponentName, JSXElementByFn, c } from '../components';
|
|
4
4
|
import { RenderProvider, RenderState } from '../types';
|
|
5
5
|
import { RenderContext, RenderContextInit } from './context';
|
|
6
|
+
import { castTo } from '@travetto/runtime';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Inky Renderer
|
|
@@ -28,8 +29,7 @@ export class InkyRenderer {
|
|
|
28
29
|
let final: JSXElement = node;
|
|
29
30
|
// Render simple element if needed
|
|
30
31
|
if (typeof node.type === 'function' && node.type !== JSXFragmentType) {
|
|
31
|
-
|
|
32
|
-
const out = node.type(node.props);
|
|
32
|
+
const out = castTo<Function>(node.type)(node.props);
|
|
33
33
|
final = out !== EMPTY_ELEMENT ? out : final;
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -70,8 +70,7 @@ export class InkyRenderer {
|
|
|
70
70
|
// @ts-expect-error
|
|
71
71
|
): RenderState<JSXElementByFn<K>, RenderContext> {
|
|
72
72
|
const el = ctx.createElement(key, props);
|
|
73
|
-
|
|
74
|
-
const newStack = [...state.stack, el] as JSXElement[];
|
|
73
|
+
const newStack: JSXElement[] = castTo([...state.stack, el]);
|
|
75
74
|
return { ...state, el, props: el.props, recurse: () => this.#render(ctx, renderer, el.props.children ?? [], newStack) };
|
|
76
75
|
}
|
|
77
76
|
|