mail-editor-pancake 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/README.md +52 -52
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Simple Mail Editor
2
2
 
3
- 面向运营的轻量邮件可视化编辑器(产品名 **Simple Mail**)。聚焦邮件场景,用**严格扁平化的组件树** + **MJML 输出引擎**,解决 GrapesJS 在邮件场景下「任意嵌套拖拽混乱文本组件消失」的痛点。
3
+ **Simple Mail** 是面向运营与开发的轻量邮件可视化编辑器。文档模型固定为四层(Doc Section ColumnBlock),导出链路为 JSON MJML → HTML,可嵌入 React、Vue 或任意前端项目。
4
4
 
5
5
  ```text
6
6
  Doc → Section → Column → Block // 仅四层,Block 不可再嵌套子组件
@@ -9,7 +9,7 @@ Doc → Section → Column → Block // 仅四层,Block 不可再嵌套子
9
9
 
10
10
  ## 目录
11
11
 
12
- - [命名与 npm 包](#命名与-npm-包)
12
+ - [npm 包](#npm-包)
13
13
  - [特性](#特性)
14
14
  - [仓库结构](#仓库结构)
15
15
  - [开发与构建](#开发与构建)
@@ -26,7 +26,7 @@ Doc → Section → Column → Block // 仅四层,Block 不可再嵌套子
26
26
  - [图片资源 `imageAssets`](#图片资源-imageassets)
27
27
  - [框架集成示例](#框架集成示例)
28
28
  - [自定义组件](#自定义组件)
29
- - [宿主集成注意](#宿主集成注意)
29
+ - [集成说明](#集成说明)
30
30
  - [操作手册](#操作手册)
31
31
  - [设计与代码模式](#设计与代码模式)
32
32
  - [数据模型速览](#数据模型速览)
@@ -36,26 +36,18 @@ Doc → Section → Column → Block // 仅四层,Block 不可再嵌套子
36
36
 
37
37
  ---
38
38
 
39
- ## 命名与 npm 包
39
+ ## npm 包
40
40
 
41
- 三层名称各司其职,**不必强行统一成一个字符串**:
41
+ 安装与业务代码中的 import 使用下列 **scoped 包名**:
42
42
 
43
- | 层级 | 名称 | 说明 |
44
- |------|------|------|
45
- | 仓库目录 | `simple-mail` | Git 路径、内部日志前缀(`[simple-mail]`)、剪贴板 kind(`simple-mail/doc`)、引擎标识等 |
46
- | 对外子包 | `@simple-mail/core`、`@simple-mail/blocks` | **业务代码应使用的 import 名**;发布到 npm 的主包 |
47
- | Monorepo 根 | `mail-editor-pancake` | 无 scope 的 `simple-mail` 在 npm 已被占用时的根包名;适合 `pnpm link` 整仓,**不作为对外 API 文档的安装名** |
43
+ | 包名 | 内容 |
44
+ |------|------|
45
+ | `@simple-mail/core` | 编辑器引擎、`MailEditor`、类型与工具函数;样式入口 `@simple-mail/core/style.css` |
46
+ | `@simple-mail/blocks` | 内置组件与示例自定义块(`builtinBlocks`、`allBlocks`) |
48
47
 
49
- ```text
50
- simple-mail/ # 仓库根(package.json name: mail-editor-pancake)
51
- ├── packages/
52
- │ ├── core/ → @simple-mail/core
53
- │ └── blocks/ → @simple-mail/blocks
54
- └── playground/
55
- └── vanilla/ → @simple-mail/playground-vanilla(本地演示,不发布)
56
- ```
48
+ 本仓库在 Git 中目录名为 `simple-mail`;npm 上 monorepo 根包名为 `mail-editor-pancake`(因无 scope 的 `simple-mail` 已被占用)。**集成时请只安装并 import `@simple-mail/*`**,不要依赖 `mail-editor-pancake/packages/...` 这类深路径。
57
49
 
58
- **推荐写法(npm link 后统一用 scope):**
50
+ 本地 link 整仓开发时,依赖名可能为 `mail-editor-pancake`,但代码中仍应写 `@simple-mail/core` 等,并在构建工具里配置 alias(见 [安装与集成](#安装与集成))。
59
51
 
60
52
  ```ts
61
53
  import { MailEditor } from '@simple-mail/core';
@@ -63,7 +55,14 @@ import '@simple-mail/core/style.css';
63
55
  import { allBlocks } from '@simple-mail/blocks';
64
56
  ```
65
57
 
66
- 不推荐长期依赖 `mail-editor-pancake/packages/core` 深路径;若宿主已 link 根包,请在 Vite alias 中把 `@simple-mail/*` 指到 `node_modules/mail-editor-pancake/packages/*`(见 [安装与集成](#安装与集成))。
58
+ 仓库目录结构:
59
+
60
+ ```text
61
+ simple-mail/
62
+ ├── packages/core/ → @simple-mail/core
63
+ ├── packages/blocks/ → @simple-mail/blocks
64
+ └── playground/vanilla/ 演示项目(不随 npm 发布)
65
+ ```
67
66
 
68
67
  ---
69
68
 
@@ -83,7 +82,7 @@ import { allBlocks } from '@simple-mail/blocks';
83
82
  - **仅搭正文**:`ui.hideMailMeta` 隐藏主题、Preheader 与顶栏「邮件设置」
84
83
  - **清空 / 重置**:`presetDoc` 与 `initialDoc` 分离
85
84
  - **变量系统**:`setVariables`;`kind: link | image`;顶栏 `{{ }}` 弹层
86
- - **动态变量节**(可选):`Section.attrs.dynamicVariantKey`,导出时整节替换为 `{{key}}`,由宿主填充(券包等)
85
+ - **动态变量节**(可选):`Section.attrs.dynamicVariantKey`,导出时整节替换为 `{{key}}`,由业务侧注入最终 HTML(如券包区块)
87
86
  - **点空白取消选中**:`clearSelectionOnCanvasMargin`
88
87
  - 包体:核心 + MJML + CodeMirror + 富文本,gzip ≈ 580–590KB(主要来自 `mjml-browser`)
89
88
 
@@ -118,20 +117,21 @@ pnpm lint # biome check
118
117
  pnpm --filter @simple-mail/playground-vanilla build
119
118
  ```
120
119
 
121
- 修改 `packages/core` 源码后,在 monorepo 根执行 **`pnpm build`**(或 `pnpm --filter @simple-mail/core build`),再让宿主重新加载,避免 link 场景下 `dist` 与源码不一致。
120
+ 若你正在本地修改本仓库源码,请在 monorepo 根执行 `pnpm build` 后再刷新引用方项目,以保证 `dist` 与类型声明一致。
122
121
 
123
122
  ---
124
123
 
125
124
  ## 安装与集成
126
125
 
127
- ### 从 npm 安装(推荐)
126
+ ### 从 npm 安装
128
127
 
129
128
  ```bash
130
129
  pnpm add @simple-mail/core @simple-mail/blocks
131
- # 与 core 同版本传递依赖,宿主需能解析到:
132
130
  pnpm add codemirror mjml-browser sortablejs
133
131
  ```
134
132
 
133
+ `@simple-mail/core` 依赖 CodeMirror、MJML 与 SortableJS,请在项目中一并安装,以便打包工具能正确解析。
134
+
135
135
  ```ts
136
136
  import { MailEditor } from '@simple-mail/core';
137
137
  import '@simple-mail/core/style.css';
@@ -141,9 +141,9 @@ import { builtinBlocks, allBlocks } from '@simple-mail/blocks';
141
141
  - 仅需内置块时用 `builtinBlocks`;需要 Logo/页脚等示例时用 `allBlocks`,或与业务 `defineBlock` 合并。
142
142
  - `@simple-mail/blocks` 依赖 `@simple-mail/core`,版本宜对齐。
143
143
 
144
- ### 本地 link 整仓(monorepo 开发)
144
+ ### 本地 link(参与本仓库开发时)
145
145
 
146
- 宿主 `package.json`:
146
+ 在你的项目 `package.json` 中 link 本仓库根包,并安装与 core 相同的运行时依赖:
147
147
 
148
148
  ```json
149
149
  {
@@ -159,7 +159,7 @@ import { builtinBlocks, allBlocks } from '@simple-mail/blocks';
159
159
  }
160
160
  ```
161
161
 
162
- **业务 import 仍使用 `@simple-mail/*`**,在 Vite alias link 后的子包路径,并排除预构建缓存:
162
+ import 路径仍使用 `@simple-mail/*`。以 Vite 为例,将 alias 指向 `node_modules/mail-editor-pancake/packages` 下对应子包,并将这些包排除在依赖预构建之外:
163
163
 
164
164
  ```ts
165
165
  // vite.config.ts 示意
@@ -171,7 +171,7 @@ export default defineConfig({
171
171
  '@simple-mail/core': path.join(mailEditorPkgRoot, 'core'),
172
172
  '@simple-mail/core/style.css': path.join(mailEditorPkgRoot, 'core/dist/style.css'),
173
173
  '@simple-mail/blocks': path.join(mailEditorPkgRoot, 'blocks'),
174
- // link dist 内嵌套解析 codemirror / mjml-browser / sortablejs,常需指向宿主 node_modules
174
+ // link 时建议将 codemirror / mjml-browser / sortablejs 解析到你项目中的安装路径
175
175
  codemirror: path.dirname(require.resolve('codemirror/package.json')),
176
176
  'mjml-browser': path.dirname(require.resolve('mjml-browser/package.json')),
177
177
  sortablejs: path.dirname(require.resolve('sortablejs/package.json')),
@@ -183,7 +183,7 @@ export default defineConfig({
183
183
  });
184
184
  ```
185
185
 
186
- 仍出现「拖拽/组合拖入与源码不符」时:先 `pnpm build`(编辑器仓),再删除宿主 `node_modules/.vite` 并重启 dev。
186
+ 若界面行为与最新源码不一致:先在编辑器仓库执行 `pnpm build`,再删除你项目中的 `node_modules/.vite` 并重启开发服务器。
187
187
 
188
188
  ### 发布
189
189
 
@@ -194,7 +194,7 @@ export default defineConfig({
194
194
  | `@simple-mail/core` | 引擎 + 样式 `style.css` |
195
195
  | `@simple-mail/blocks` | 内置与示例块定义 |
196
196
 
197
- 根包 `mail-editor-pancake` 用于占位与 link,**文档与对外示例以 `@simple-mail/*` 为准**。发布前请在各子包目录执行 build,并保证 `files` `dist`。
197
+ npm 上仅发布 `@simple-mail/core` 与 `@simple-mail/blocks`。根包 `mail-editor-pancake` 仅用于 monorepo 与本地 link。发布前需在各子包执行 build,且 `package.json` 的 `files` 包含 `dist`。
198
198
 
199
199
  ---
200
200
 
@@ -222,7 +222,7 @@ const editor = new MailEditor({
222
222
  const { mjml, html } = editor.export({ withSampleVariables: true });
223
223
  ```
224
224
 
225
- 构造后建议注入业务变量(避免只写在 `initialDoc.variables` 里后被空数组覆盖):
225
+ 构造后请用 `setVariables` 注入业务变量列表。若只写在 `initialDoc.variables` 中,后续 `setValue` 恢复文档时可能被空数组覆盖。
226
226
 
227
227
  ```ts
228
228
  editor.setVariables([
@@ -286,7 +286,7 @@ editor.setTheme('dark');
286
286
  editor.getTheme();
287
287
  ```
288
288
 
289
- 根节点 `data-sm-theme`;可在宿主侧覆盖 `.sm-root` CSS 变量。
289
+ 根节点带有 `data-sm-theme`。可在你的应用中通过覆盖 `.sm-root` 上的 CSS 变量调整配色。
290
290
 
291
291
  | 方式 | 说明 |
292
292
  |------|------|
@@ -310,7 +310,7 @@ editor.getTheme();
310
310
  | `hideTopbarFullscreen?` | 隐藏全屏按钮 |
311
311
  | `hideTopbarClearCanvas?` / `hideTopbarResetContent?` | 隐藏清空 / 重置 |
312
312
  | `hideTopbarDocClipboard?` | 隐藏「复制设计稿」「导入设计稿」 |
313
- | `hideTopbarInsertVariable?` | 隐藏顶栏「插入变量」(由宿主提供时) |
313
+ | `hideTopbarInsertVariable?` | 隐藏顶栏「插入变量」(改由应用内其他入口插入时) |
314
314
  | `topbarCompact?` | 顶栏默认仅图标(窄屏/嵌入) |
315
315
  | `topbarLabels?` | `auto`(默认)\| `never` \| `always`;与 `topbarCompact` 配合 |
316
316
  | `topbarCompactMinWidth?` | `topbarLabels: auto` 时展示文案的最小宽度 px,默认 1200 |
@@ -369,7 +369,7 @@ interface Variable {
369
369
 
370
370
  优先级:内联编辑光标 → 聚焦的 input/textarea → 选中 Block 主文本字段 → 末尾新建 text 块。
371
371
 
372
- ### 宿主工具函数
372
+ ### 配套工具函数
373
373
 
374
374
  ```ts
375
375
  import {
@@ -382,26 +382,26 @@ import {
382
382
  } from '@simple-mail/core';
383
383
  ```
384
384
 
385
- `buildBodyVariableInsert` 仍可用,新代码请用 `buildBodyVariableKeyInsert` / `buildBodyVariableElementInsert`。
385
+ `buildBodyVariableInsert` 为兼容保留;插入正文时优先使用 `buildBodyVariableKeyInsert` `buildBodyVariableElementInsert`。
386
386
 
387
- ### 入口分工(建议)
387
+ ### 变量插入入口
388
388
 
389
389
  | 场景 | 入口 |
390
390
  |------|------|
391
- | 发件主题、Preheader | **宿主页**插入变量 |
392
- | 正文 | **编辑器顶栏** `{{ }}`(`hideTopbarInsertVariable` 时可关掉) |
391
+ | 发件主题、Preheader 等表单字段 | 应用内表单旁的插入控件 |
392
+ | 邮件正文 | 编辑器顶栏 `{{ }}`(可通过 `hideTopbarInsertVariable` 关闭) |
393
393
 
394
394
  ---
395
395
 
396
396
  ## 动态变量节(dynamicVariant)
397
397
 
398
- 用于「整节内容由宿主按 key 替换」的场景(如券包 `couponGroup`)。Section 设置 `attrs.dynamicVariantKey` 后,导出 HTML/MJML 时该节正文替换为 `{{key}}`;具体 HTML 由宿主写入。
398
+ 适用于「整节 HTML 由业务系统按 key 渲染」的场景。为 Section 设置 `attrs.dynamicVariantKey` 后,导出时该节正文变为 `{{key}}` 占位符,实际内容由你的服务端或前端在发送前写入。
399
399
 
400
- - 编辑器 UI 默认关闭;宿主设 `ui.enableDynamicVariantKey: true` 后,右栏可编辑 key,画布显示标识。
401
- - 左栏 `expandPaletteDrop` 可返回 `{ blocks, sectionAttrs: { dynamicVariantKey: '…' } }` 一次拖入动态节。
402
- - 已写入文档的 key **不依赖** UI 开关,导出仍生效。
400
+ - 右栏编辑入口默认关闭;设置 `ui.enableDynamicVariantKey: true` 后可在界面中配置 key,画布会显示节标识。
401
+ - 左栏组合块可通过 `expandPaletteDrop` 返回 `{ blocks, sectionAttrs: { dynamicVariantKey: '…' } }` 一次创建动态节。
402
+ - 文档中已保存的 key 在导出时始终生效,与 UI 开关无关。
403
403
 
404
- 宿主可从 core 导入:
404
+ 相关 API(自 `@simple-mail/core` 导出):
405
405
 
406
406
  ```ts
407
407
  import {
@@ -415,7 +415,7 @@ import {
415
415
  } from '@simple-mail/core';
416
416
  ```
417
417
 
418
- `Section.attrs.meta` 为宿主扩展袋,编辑器不解释,随 `EmailDoc` 序列化。
418
+ `Section.attrs.meta` 为任意 JSON 扩展字段,编辑器不参与渲染,仅随 `EmailDoc` 一并序列化保存。
419
419
 
420
420
  ---
421
421
 
@@ -445,7 +445,7 @@ import {
445
445
 
446
446
  ## 图片资源 `imageAssets`
447
447
 
448
- 编辑器只存 URL;落地由宿主实现。
448
+ 编辑器仅在文档中保存图片 URL;上传、图库与存储由你的应用实现。
449
449
 
450
450
  | 字段 | 作用 |
451
451
  |------|------|
@@ -602,13 +602,13 @@ expandPaletteDrop?: (createBlock) => Block[] | { blocks: Block[]; sectionAttrs?:
602
602
 
603
603
  ---
604
604
 
605
- ## 宿主集成注意
605
+ ## 集成说明
606
606
 
607
- 1. core 源码后 **`pnpm build`**,再刷新宿主。
608
- 2. **Vue**:`blocks` `markRaw`。
609
- 3. **Vite link**:`optimizeDeps.exclude` `@simple-mail/core`、`@simple-mail/blocks`;配置 alias codemirror/mjml/sortablejs 解析。
610
- 4. **import 路径**:统一 `@simple-mail/*`,避免长期依赖 `mail-editor-pancake/packages/...`。
611
- 5. 宿主需安装与 core 一致的 **codemirror、mjml-browser、sortablejs**(link 时尤甚)。
607
+ - **依赖版本**:安装 `@simple-mail/core` 时,请同时安装 `codemirror`、`mjml-browser`、`sortablejs`,版本与 core 的 `peerDependencies` / 文档示例保持一致。
608
+ - **import 路径**:统一使用 `@simple-mail/core`、`@simple-mail/blocks`,不要使用 `mail-editor-pancake/packages/...`。
609
+ - **Vue 3**:将 `blocks` 数组中的每个 `BlockDefinition` `markRaw` 包裹后再传入,否则 `expandPaletteDrop` 等函数可能失效。
610
+ - **Vite + 本地 link**:在 `optimizeDeps.exclude` 中加入 `@simple-mail/core`、`@simple-mail/blocks`;按需配置 alias 与上述运行时依赖的解析路径。
611
+ - **本地开发本仓库**:修改 `packages/core` 后执行 `pnpm build`,再在引用项目中刷新;异常时清除 `.vite` 缓存后重启 dev server。
612
612
 
613
613
  ---
614
614
 
@@ -692,7 +692,7 @@ interface Block {
692
692
  | 取舍点 | 选择 | 原因 |
693
693
  |--------|------|------|
694
694
  | 画布 HTML | 轻量预览 DOM | iframe 内 Sortable 难控;真实效果靠 MJML |
695
- | 嵌套 | 严格四层 | 避免 GrapesJS 式邮件翻车 |
695
+ | 嵌套 | 严格四层 | 限制结构深度,减少邮件排版与拖拽异常 |
696
696
  | 输出 | MJML 优先 | Outlook/Gmail 兼容;可预留 table 引擎 |
697
697
  | 文档级源码回写 | 只读 | MJML→doc 反推风险大 |
698
698
  | 状态 | immutable + history | 核心零 UI 框架依赖 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mail-editor-pancake",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "private": false,
5
5
  "description": "面向运营的轻量邮件可视化编辑器",
6
6
  "devDependencies": {