@standhigher/react-email-editor 0.4.3 → 0.5.2
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/README.md +5 -8
- package/README.zh-CN.md +5 -8
- package/dist/index.d.ts +44 -17
- package/dist/index.js +581 -263
- package/dist/styles.css +44 -0
- package/docs/advanced-examples.md +5 -1
- package/docs/advanced-examples.zh-CN.md +5 -1
- package/docs/api.md +23 -11
- package/docs/api.zh-CN.md +23 -11
- package/docs/changelog.md +60 -0
- package/docs/changelog.zh-CN.md +60 -0
- package/docs/custom-blocks.md +3 -3
- package/docs/custom-blocks.zh-CN.md +3 -3
- package/docs/release.md +4 -4
- package/docs/release.zh-CN.md +4 -4
- package/docs/template-engines.md +81 -0
- package/docs/template-engines.zh-CN.md +81 -0
- package/package.json +6 -11
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ Drag content onto a canvas, style your email, preview it, then save editable JSO
|
|
|
15
15
|
Requires React 18 and React DOM 18. Ships ESM and TypeScript declarations.
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
|
|
18
|
+
npm install @standhigher/react-email-editor
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
```tsx
|
|
@@ -28,15 +28,13 @@ export function EmailPage() {
|
|
|
28
28
|
}
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
With Next.js App Router, add `"use client"` to the integration component and import CSS from an allowed global stylesheet entry. Your app implements persistence, resource uploads and email delivery.
|
|
32
|
-
|
|
33
31
|
## Run locally
|
|
34
32
|
|
|
35
|
-
Use Node.js 24 LTS (`.nvmrc`; at least 22.18 for the complete test suite)
|
|
33
|
+
Use Node.js 24 LTS (`.nvmrc`; at least 22.18 for the complete test suite):
|
|
36
34
|
|
|
37
35
|
```bash
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
npm install
|
|
37
|
+
npm run dev
|
|
40
38
|
```
|
|
41
39
|
|
|
42
40
|
Open [http://localhost:5173](http://localhost:5173); reuse an existing server when available. See [development and local linking](https://github.com/standhigher/react-email-editor/blob/main/docs/api.md#development-and-local-linking) for build and validation commands.
|
|
@@ -45,9 +43,8 @@ Open [http://localhost:5173](http://localhost:5173); reuse an existing server wh
|
|
|
45
43
|
|
|
46
44
|
- [API reference](https://github.com/standhigher/react-email-editor/blob/main/docs/api.md): every public export, parameter, default and type.
|
|
47
45
|
- [Basic examples](https://github.com/standhigher/react-email-editor/blob/main/docs/basic-examples.md): initial content, saving/loading, body styles, variables and preview.
|
|
46
|
+
- [Template preview and custom engines](https://github.com/standhigher/react-email-editor/blob/main/docs/template-engines.md).
|
|
48
47
|
- [Advanced examples](https://github.com/standhigher/react-email-editor/blob/main/docs/advanced-examples.md): validated saving, multiple instances, custom blocks, multiple editing regions, resource adapters and standalone export.
|
|
49
48
|
- [Custom block guide](https://github.com/standhigher/react-email-editor/blob/main/docs/custom-blocks.md): detailed controls, plugins and rendering helpers.
|
|
50
49
|
- [Release guide](https://github.com/standhigher/react-email-editor/blob/main/docs/release.md): package checks and manual npm publishing.
|
|
51
50
|
- [Changelog](https://github.com/standhigher/react-email-editor/blob/main/docs/changelog.md).
|
|
52
|
-
|
|
53
|
-
The document format is under development. Only `version: 4` is supported, without automatic migration of older documents.
|
package/README.zh-CN.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
需要 React 18 和 React DOM 18;包提供 ESM 和 TypeScript 类型。
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
|
|
18
|
+
npm install @standhigher/react-email-editor
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
```tsx
|
|
@@ -28,15 +28,13 @@ export function EmailPage() {
|
|
|
28
28
|
}
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
Next.js App Router 的接入组件需声明 `"use client"`;样式在应用允许的全局样式入口引入。保存、上传资源与发送邮件由你的应用实现。
|
|
32
|
-
|
|
33
31
|
## 本地启动
|
|
34
32
|
|
|
35
|
-
推荐 Node.js 24 LTS(`.nvmrc`;完整测试最低需要 22.18
|
|
33
|
+
推荐 Node.js 24 LTS(`.nvmrc`;完整测试最低需要 22.18):
|
|
36
34
|
|
|
37
35
|
```bash
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
npm install
|
|
37
|
+
npm run dev
|
|
40
38
|
```
|
|
41
39
|
|
|
42
40
|
打开 [http://localhost:5173](http://localhost:5173),已有服务时优先复用。构建与校验命令见 [API 文档的开发说明](https://github.com/standhigher/react-email-editor/blob/main/docs/api.zh-CN.md#开发与本地联调)。
|
|
@@ -45,9 +43,8 @@ pnpm dev
|
|
|
45
43
|
|
|
46
44
|
- [API 参考](https://github.com/standhigher/react-email-editor/blob/main/docs/api.zh-CN.md):所有公共导出、参数、默认值与类型。
|
|
47
45
|
- [基础场景](https://github.com/standhigher/react-email-editor/blob/main/docs/basic-examples.zh-CN.md):初始内容、保存恢复、主体样式、变量及预览。
|
|
46
|
+
- [模板预览与自定义引擎](https://github.com/standhigher/react-email-editor/blob/main/docs/template-engines.zh-CN.md)。
|
|
48
47
|
- [复杂场景](https://github.com/standhigher/react-email-editor/blob/main/docs/advanced-examples.zh-CN.md):校验后保存、多实例、自定义区块、多区域编辑、资源适配与独立导出。
|
|
49
48
|
- [自定义区块指南](https://github.com/standhigher/react-email-editor/blob/main/docs/custom-blocks.zh-CN.md):控件、插件和渲染工具的完整说明。
|
|
50
49
|
- [发布指南](https://github.com/standhigher/react-email-editor/blob/main/docs/release.zh-CN.md):发布包校验与本地手动发布。
|
|
51
50
|
- [更新记录](https://github.com/standhigher/react-email-editor/blob/main/docs/changelog.zh-CN.md)。
|
|
52
|
-
|
|
53
|
-
文档格式仍处于开发阶段,当前只支持 `version: 4`,不自动迁移旧版文档。
|
package/dist/index.d.ts
CHANGED
|
@@ -37,10 +37,6 @@ declare const LINK_DECORATIONS: {
|
|
|
37
37
|
/** Link decoration: underline or none. */
|
|
38
38
|
type LinkDecoration = (typeof LINK_DECORATIONS)[keyof typeof LINK_DECORATIONS];
|
|
39
39
|
|
|
40
|
-
declare const DOCUMENT_VERSION: 4;
|
|
41
|
-
declare const FONT_FAMILIES: readonly ControlOption[];
|
|
42
|
-
declare const DEFAULT_EMAIL_BODY: EmailBodySettings;
|
|
43
|
-
|
|
44
40
|
/** Email body layout and inherited defaults. */
|
|
45
41
|
interface EmailBodySettings {
|
|
46
42
|
/** Default text color. */
|
|
@@ -49,7 +45,7 @@ interface EmailBodySettings {
|
|
|
49
45
|
backgroundColor: string;
|
|
50
46
|
/** Maximum content width in px, normalized to an integer from 320 to 900. */
|
|
51
47
|
contentWidth: number;
|
|
52
|
-
/**
|
|
48
|
+
/** CSS font stack; empty uses the internal default Arial, Helvetica, sans-serif. */
|
|
53
49
|
fontFamily: string;
|
|
54
50
|
/** Default font weight: normal or bold. */
|
|
55
51
|
fontWeight: FontWeight;
|
|
@@ -68,10 +64,10 @@ interface EmailBodySettings {
|
|
|
68
64
|
/** Content border color. */
|
|
69
65
|
borderColor: string;
|
|
70
66
|
}
|
|
71
|
-
/** Persistable email document
|
|
67
|
+
/** Persistable email document, accepted according to its structure. */
|
|
72
68
|
interface EmailDocument {
|
|
73
|
-
/** Format
|
|
74
|
-
version:
|
|
69
|
+
/** Format identifier; new documents use DOCUMENT_VERSION (4), without version-based rejection. */
|
|
70
|
+
version: number;
|
|
75
71
|
/** Optional subject, separate from exported HTML content. */
|
|
76
72
|
subject?: string;
|
|
77
73
|
/** Complete body layout and style settings. */
|
|
@@ -276,16 +272,31 @@ interface Variable {
|
|
|
276
272
|
value?: string;
|
|
277
273
|
}
|
|
278
274
|
|
|
279
|
-
/**
|
|
275
|
+
/** Preview values; document data should contain structured-cloneable values. */
|
|
280
276
|
interface TemplateData {
|
|
281
|
-
/** Template key mapped to a scalar, object or array. */
|
|
282
277
|
[key: string]: unknown;
|
|
283
278
|
}
|
|
284
|
-
/**
|
|
285
|
-
|
|
279
|
+
/** Optional diagnostic returned by a consumer's template validator. */
|
|
280
|
+
interface TemplateValidationIssue {
|
|
281
|
+
message: string;
|
|
282
|
+
/** Zero-based character offset in the original template. */
|
|
283
|
+
offset?: number;
|
|
284
|
+
}
|
|
285
|
+
/** Synchronous template adapter; owns expression semantics and HTML escaping. */
|
|
286
|
+
interface TemplateEngine {
|
|
287
|
+
/** Receives the complete template and detached data; errors propagate. */
|
|
288
|
+
render: (template: string, data: TemplateData) => string;
|
|
289
|
+
/** Optional, explicitly invoked; never blocks saving or rendering automatically. */
|
|
290
|
+
validate?: (template: string) => TemplateValidationIssue[];
|
|
291
|
+
}
|
|
292
|
+
/** Shared engine selection for standalone rendering and validation. */
|
|
293
|
+
interface TemplateEngineOptions {
|
|
294
|
+
/** Defaults to the built-in basic engine. */
|
|
295
|
+
templateEngine?: TemplateEngine;
|
|
296
|
+
}
|
|
286
297
|
|
|
287
298
|
/** Complete document HTML export options. */
|
|
288
|
-
interface DocumentHtmlOptions {
|
|
299
|
+
interface DocumentHtmlOptions extends TemplateEngineOptions {
|
|
289
300
|
/** Resolve templates for preview; default false. */
|
|
290
301
|
resolveHtmlTemplates?: boolean;
|
|
291
302
|
/** Exact inserted tokens and optional preview values, default []. */
|
|
@@ -439,7 +450,7 @@ interface BlockPluginOptions<Schema extends ControlSchema, Type extends string>
|
|
|
439
450
|
type: Type;
|
|
440
451
|
/** Nonempty library title. */
|
|
441
452
|
title: string;
|
|
442
|
-
/** Library icon or string. */
|
|
453
|
+
/** Library React icon or HTML string; defaults to the first character of the trimmed title. */
|
|
443
454
|
icon?: ReactNode | string;
|
|
444
455
|
/** Library description. */
|
|
445
456
|
description?: string;
|
|
@@ -498,6 +509,8 @@ interface ValidationIssue {
|
|
|
498
509
|
}
|
|
499
510
|
/** Block registration and image resource adapter options. */
|
|
500
511
|
interface UseEmailEditorConfigOptions {
|
|
512
|
+
/** Shared synchronous template adapter; defaults to the basic engine. */
|
|
513
|
+
templateEngine?: TemplateEngine;
|
|
501
514
|
/** Plugins created by defineBlock, default []. */
|
|
502
515
|
plugins?: BlockPlugin[];
|
|
503
516
|
/** All by default; false hides all; arrays filter/order; hidden nodes still render. */
|
|
@@ -507,6 +520,8 @@ interface UseEmailEditorConfigOptions {
|
|
|
507
520
|
}
|
|
508
521
|
/** Shared configuration for editing, creation and standalone export. */
|
|
509
522
|
interface EmailEditorConfig {
|
|
523
|
+
/** Normalized engine used by canvas, preview and resolved HTML export. */
|
|
524
|
+
readonly templateEngine: TemplateEngine;
|
|
510
525
|
/** All registered definitions including hidden builtins. */
|
|
511
526
|
readonly definitions: readonly BlockPlugin[];
|
|
512
527
|
/** Insertable blocks in display order. */
|
|
@@ -638,6 +653,10 @@ declare const DEFAULT_BLOCKS: BlockPlugin[];
|
|
|
638
653
|
declare function resolveEmailBody(body?: Partial<EmailBodySettings> | null): EmailBodySettings;
|
|
639
654
|
declare function createEmailDocument(blocks?: EmailBlockNode[]): EmailDocument;
|
|
640
655
|
|
|
656
|
+
declare const DOCUMENT_VERSION: 4;
|
|
657
|
+
declare const FONT_FAMILIES: readonly ControlOption[];
|
|
658
|
+
declare const DEFAULT_EMAIL_BODY: EmailBodySettings;
|
|
659
|
+
|
|
641
660
|
declare function createBlockNode(type: string, definitions?: readonly BlockDefinition[]): EmailBlockNode | null;
|
|
642
661
|
|
|
643
662
|
declare const DIMENSION_CONTROLS: {
|
|
@@ -677,12 +696,12 @@ declare function createDecorationControls(overrides?: StyleControlOverrideMap<De
|
|
|
677
696
|
declare function createTypographyControls(overrides?: StyleControlOverrideMap<TypographyControlName>): Record<TypographyControlName, StyleControlConfig>;
|
|
678
697
|
|
|
679
698
|
/** Single-block rendering options; must be an object. */
|
|
680
|
-
interface BlockRenderOptions {
|
|
699
|
+
interface BlockRenderOptions extends TemplateEngineOptions {
|
|
681
700
|
/** Resolve templates, default false; single-block rendering does not auto-merge variables. */
|
|
682
701
|
resolveHtmlTemplate?: boolean;
|
|
683
702
|
/** Explicit preview data; defaults to node defaultData. */
|
|
684
703
|
templateData?: TemplateData;
|
|
685
|
-
/** Exact token dot normalization
|
|
704
|
+
/** Exact token dot normalization before export or preview; merge preview data explicitly. */
|
|
686
705
|
variables?: Variable[];
|
|
687
706
|
/** Body defaults; defaults to DEFAULT_EMAIL_BODY. */
|
|
688
707
|
body?: EmailBodySettings;
|
|
@@ -694,6 +713,14 @@ declare function renderBlockContent(node: EmailBlockNode, definitions?: readonly
|
|
|
694
713
|
declare function renderBlock(node: EmailBlockNode, definitions?: readonly BlockDefinition[], mode?: RenderMode, body?: EmailBodySettings): string;
|
|
695
714
|
declare function blockToHtml(node: EmailBlockNode, definitions?: readonly BlockDefinition[], mode?: RenderMode, options?: BlockRenderOptions): string;
|
|
696
715
|
|
|
716
|
+
/** Resolve a preview with one engine; stored source is never modified. */
|
|
717
|
+
declare function renderTemplatePreview(template: string, data?: TemplateData, options?: TemplateEngineOptions): string;
|
|
718
|
+
/** Undefined means the selected engine does not provide validation; [] means valid. */
|
|
719
|
+
declare function validateTemplate(template: string, options?: TemplateEngineOptions): TemplateValidationIssue[] | undefined;
|
|
720
|
+
|
|
721
|
+
/** Basic paths and control statements; unsupported input is preserved in full. */
|
|
722
|
+
declare const defaultTemplateEngine: TemplateEngine;
|
|
723
|
+
|
|
697
724
|
declare function buildRenderContext(node: EmailBlockNode, mode: RenderMode, body?: EmailBodySettings, definition?: BlockDefinition | undefined): BlockRenderContext;
|
|
698
725
|
|
|
699
726
|
declare function getBlockDefinition(type: string, definitions?: readonly BlockDefinition[]): BlockDefinition | undefined;
|
|
@@ -861,4 +888,4 @@ interface ControlEditorProps {
|
|
|
861
888
|
/** Reuse declared controls, image pickers and validation inside a plugin inspector. */
|
|
862
889
|
declare function ControlEditor({ control }: ControlEditorProps): react.JSX.Element;
|
|
863
890
|
|
|
864
|
-
export { BLOCK_TYPES, BORDER_STYLES, type BlockInspectorSection, type BlockPlugin, type BlockPluginOptions, type BlockRenderContext, type BlockRenderOptions, type BorderStyle, type BuiltinBlockType, Button, CheckboxControl, ColorControl, type ControlComponentProps, type ControlDefinition, ControlEditor, type ControlEditorProps, type ControlKind, type ControlOption, type ControlOptions, type ControlSchema, type ControlValues, DEFAULT_BLOCKS, DEFAULT_EMAIL_BODY, DOCUMENT_VERSION, type DecorationControlName, type DimensionControlName, type DocumentHtmlOptions, EditableRichText, type EditableRichTextProps, type EmailBlockNode, type EmailBlockStyle, type EmailBodySettings, EmailControls, type EmailDecorationStyle, type EmailDocument, EmailEditor, type EmailEditorConfig, type EmailEditorData, type EmailEditorInstance, type EmailEditorProps, type EmailEditorState, type EmailElementStyle, type EmailMarkup, type EmailSpacingStyle, type EmailTools, type EmailTypographyStyle, FONT_FAMILIES, FONT_WEIGHTS, type FontWeight, HORIZONTAL_ALIGNS, type HorizontalAlign, type ImagePickerContext, LINK_DECORATIONS, type LinkDecoration, type PluginEditorProps, type PluginRenderContext, RangeControl, type RenderMode, RichText, type RichTextProfile, STYLE_GROUPS, SelectControl, type StyleControlConfig, type StyleControlType, type StyleGroup, TEXT_ALIGNS, type TemplateData, type TextAlign, TextInput, type TypographyControlName, type UseEmailEditorConfigOptions, type UseEmailEditorOptions, type ValidationIssue, type Variable, blockToHtml, buildRenderContext, createBlockNode, createDecorationControls, createDimensionControls, createEmailDocument, createTypographyControls, defineBlock, documentToHtml, generateId, getBlockDefinition, mergeTemplateData, renderBlock, renderBlockContent, renderTemplatePreview, resolveEmailBody, useEmailEditor, useEmailEditorConfig, useEmailEditorState, variablesToTemplateData };
|
|
891
|
+
export { BLOCK_TYPES, BORDER_STYLES, type BlockInspectorSection, type BlockPlugin, type BlockPluginOptions, type BlockRenderContext, type BlockRenderOptions, type BorderStyle, type BuiltinBlockType, Button, CheckboxControl, ColorControl, type ControlComponentProps, type ControlDefinition, ControlEditor, type ControlEditorProps, type ControlKind, type ControlOption, type ControlOptions, type ControlSchema, type ControlValues, DEFAULT_BLOCKS, DEFAULT_EMAIL_BODY, DOCUMENT_VERSION, type DecorationControlName, type DimensionControlName, type DocumentHtmlOptions, EditableRichText, type EditableRichTextProps, type EmailBlockNode, type EmailBlockStyle, type EmailBodySettings, EmailControls, type EmailDecorationStyle, type EmailDocument, EmailEditor, type EmailEditorConfig, type EmailEditorData, type EmailEditorInstance, type EmailEditorProps, type EmailEditorState, type EmailElementStyle, type EmailMarkup, type EmailSpacingStyle, type EmailTools, type EmailTypographyStyle, FONT_FAMILIES, FONT_WEIGHTS, type FontWeight, HORIZONTAL_ALIGNS, type HorizontalAlign, type ImagePickerContext, LINK_DECORATIONS, type LinkDecoration, type PluginEditorProps, type PluginRenderContext, RangeControl, type RenderMode, RichText, type RichTextProfile, STYLE_GROUPS, SelectControl, type StyleControlConfig, type StyleControlType, type StyleGroup, TEXT_ALIGNS, type TemplateData, type TemplateEngine, type TemplateEngineOptions, type TemplateValidationIssue, type TextAlign, TextInput, type TypographyControlName, type UseEmailEditorConfigOptions, type UseEmailEditorOptions, type ValidationIssue, type Variable, blockToHtml, buildRenderContext, createBlockNode, createDecorationControls, createDimensionControls, createEmailDocument, createTypographyControls, defaultTemplateEngine, defineBlock, documentToHtml, generateId, getBlockDefinition, mergeTemplateData, renderBlock, renderBlockContent, renderTemplatePreview, resolveEmailBody, useEmailEditor, useEmailEditorConfig, useEmailEditorState, validateTemplate, variablesToTemplateData };
|