@dextinity/mail-react 10.0.1 → 10.1.0-canary-20260820064356
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.
|
@@ -6,8 +6,9 @@ export interface RichTextBlockData {
|
|
|
6
6
|
draftContent: unknown;
|
|
7
7
|
}
|
|
8
8
|
export type RichTextBlockProps = PropsWithData<RichTextBlockData>;
|
|
9
|
+
export type RichTextListKind = "unordered" | "ordered";
|
|
9
10
|
/**
|
|
10
|
-
* Styling for all draft blocks of one type,
|
|
11
|
+
* Styling and list kind for all draft blocks of one type, on top of the base theme text styles.
|
|
11
12
|
*
|
|
12
13
|
* Style props accept plain values only. For responsive styling, use a theme
|
|
13
14
|
* variant, or set a `className` and register responsive CSS via `registerStyles`.
|
|
@@ -20,6 +21,8 @@ export type RichTextBlockTypeProps = Omit<TextStyles, "bottomSpacing"> & {
|
|
|
20
21
|
*/
|
|
21
22
|
variant?: VariantName;
|
|
22
23
|
className?: string;
|
|
24
|
+
/** Renders every draft block of this type as a list of this kind. */
|
|
25
|
+
list?: RichTextListKind;
|
|
23
26
|
};
|
|
24
27
|
/**
|
|
25
28
|
* Resolves the href of one link block type from the link block's props.
|
|
@@ -37,10 +40,11 @@ export type RichTextInlineRenderer = (children: ReactNode, options: {
|
|
|
37
40
|
}) => ReactNode;
|
|
38
41
|
export interface CreateRichTextBlockOptions<TLinkTypes extends Record<string, unknown> = Record<string, unknown>> {
|
|
39
42
|
/**
|
|
40
|
-
* Maps draft block types (e.g. `"header-one"`, `"paragraph-standard"`) to
|
|
41
|
-
*
|
|
43
|
+
* Maps draft block types (e.g. `"header-one"`, `"paragraph-standard"`) to how
|
|
44
|
+
* they render.
|
|
42
45
|
*
|
|
43
|
-
* Unmapped block types render with the base theme text styles
|
|
46
|
+
* Unmapped block types render as paragraphs with the base theme text styles,
|
|
47
|
+
* apart from `unordered-list-item` and `ordered-list-item`.
|
|
44
48
|
*/
|
|
45
49
|
blockTypes?: Record<string, RichTextBlockTypeProps>;
|
|
46
50
|
/**
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ComponentType, PropsWithChildren } from "react";
|
|
2
2
|
import type { Renderers } from "redraft";
|
|
3
3
|
import type { RichTextBlockTypeProps, RichTextInlineRenderer, RichTextLinkHrefResolver } from "./common.js";
|
|
4
|
-
|
|
4
|
+
type BlockTypeTextProps = Omit<RichTextBlockTypeProps, "list">;
|
|
5
|
+
export type BlockTextProps = PropsWithChildren<BlockTypeTextProps & {
|
|
5
6
|
/** Whether the theme's spacing below the text applies — set for every draft block except the last. */
|
|
6
7
|
bottomSpacing: boolean;
|
|
7
8
|
}>;
|
|
@@ -56,23 +56,21 @@ function createListBlockRenderFn({ ordered, blockTextComponent: BlockText, block
|
|
|
56
56
|
return (_jsx(BlockText, { bottomSpacing: false, ...blockTypeProps, children: _jsx(RichTextList, { ordered: ordered, variant: blockTypeProps.variant, bottomSpacing: !keys.includes(lastBlockKey), depth: depth, items: items }) }, key));
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
|
-
const
|
|
59
|
+
const builtInListKinds = {
|
|
60
|
+
"unordered-list-item": "unordered",
|
|
61
|
+
"ordered-list-item": "ordered",
|
|
62
|
+
};
|
|
60
63
|
export function createRichTextRenderers({ blockTypes, linkTypes, inline, blockTextComponent, lastBlockKey, }) {
|
|
61
64
|
const blocks = {};
|
|
62
65
|
// "unstyled" is redraft's blockFallback: registering it makes every block type the caller did not configure render with base theme styles.
|
|
63
|
-
for (const blockType of new Set(["unstyled", ...Object.keys(blockTypes)])) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
blocks[blockType] =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
ordered: listBlockType === "ordered-list-item",
|
|
72
|
-
blockTextComponent,
|
|
73
|
-
blockTypeProps: blockTypes[listBlockType] ?? {},
|
|
74
|
-
lastBlockKey,
|
|
75
|
-
});
|
|
66
|
+
for (const blockType of new Set(["unstyled", ...Object.keys(builtInListKinds), ...Object.keys(blockTypes)])) {
|
|
67
|
+
// `list` selects the renderer; the text component must not receive it.
|
|
68
|
+
const { list, ...blockTypeProps } = blockTypes[blockType] ?? {};
|
|
69
|
+
const listKind = list ?? builtInListKinds[blockType];
|
|
70
|
+
blocks[blockType] =
|
|
71
|
+
listKind === undefined
|
|
72
|
+
? createTextBlockRenderFn({ blockTextComponent, blockTypeProps, lastBlockKey })
|
|
73
|
+
: createListBlockRenderFn({ ordered: listKind === "ordered", blockTextComponent, blockTypeProps, lastBlockKey });
|
|
76
74
|
}
|
|
77
75
|
return {
|
|
78
76
|
inline: { ...inlineStyleRenderers, ...inline },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dextinity/mail-react",
|
|
3
|
-
"version": "10.0
|
|
3
|
+
"version": "10.1.0-canary-20260820064356",
|
|
4
4
|
"description": "Utilities for building HTML emails with React",
|
|
5
5
|
"license": "BSD-2-Clause",
|
|
6
6
|
"type": "module",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"typescript": "^5.9.3",
|
|
49
49
|
"vite": "^7.3.1",
|
|
50
50
|
"vitest": "^4.1.8",
|
|
51
|
-
"@dextinity/cli": "10.0
|
|
52
|
-
"@dextinity/eslint-config": "10.0
|
|
51
|
+
"@dextinity/cli": "10.1.0-canary-20260820064356",
|
|
52
|
+
"@dextinity/eslint-config": "10.1.0-canary-20260820064356"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"react": "^17.0.0 || ^18.0.0 || ^19.0.0",
|