mail-editor-pancake 0.2.1 → 0.2.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 CHANGED
@@ -76,7 +76,7 @@ simple-mail/
76
76
  - **MJML 管线**:内部 `EmailDoc` JSON → MJML → 邮件客户端可用 HTML
77
77
  - 双模式:设计态 + 源码态(文档级只读 MJML/HTML;组件级可锁定 `lockedMjml`)
78
78
  - 内置块:文本、HTML(raw)、图片、按钮、分隔线、间距、Hero、社交组,以及 1/2/3 列布局;示例自定义:Logo、单链社交、页脚
79
- - **图片字段**:手输 URL;可选上传(`uploadImage`)、内置图库(`imageGallery`)、自管图床(`pickImageFromGallery`)
79
+ - **图片字段**:手输 URL;可选上传(`uploadImage`)、内置图库(`imageGallery`)、自管图库(`pickImageFromGallery`)
80
80
  - 撤销/重做、键盘删除、复制 Section/Block;**复制/导入设计稿**(JSON 信封)
81
81
  - **界面主题**:浅色 / 深色 / 跟随系统;画布仍为白纸贴近成品
82
82
  - **品牌色**:`accentColor` / `setAccentColor`;可选顶栏拾色器
@@ -594,7 +594,7 @@ import {
594
594
  |------|------|
595
595
  | `uploadImage?(file, ctx)` | 右栏「上传」→ HTTPS URL |
596
596
  | `imageGallery?` | 内置图库弹层(`showGallery: true`) |
597
- | `pickImageFromGallery?(ctx)` | 自管图床;与 `imageGallery` 并存时**优先内置图库** |
597
+ | `pickImageFromGallery?(ctx)` | 自管图库;与 `imageGallery` 并存时**优先内置图库** |
598
598
  | `showUpload?` | 默认 `true`(有 `uploadImage` 时) |
599
599
  | `showGallery?` | 默认 `false` |
600
600
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mail-editor-pancake",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "private": false,
5
5
  "description": "面向运营的轻量邮件可视化编辑器",
6
6
  "devDependencies": {
@@ -9,6 +9,14 @@ export declare function annotateDynamicVariantHtmlAttributes(html: string, doc:
9
9
  */
10
10
  export declare function appendInlineToRichHtml(html: string, insert: string): string;
11
11
 
12
+ /**
13
+ * 资源动作权限的语义标识。宿主在 `ImageAssetPermissions.check` 中据此返回是否有权限:
14
+ * - `'upload'`:右栏「上传」按钮、图库弹层「上传」按钮(对应创建/上传权限)
15
+ * - `'addUrl'`:图库弹层「添加链接」按钮(对应创建权限)
16
+ * - `'delete'`:图库弹层缩略图删除按钮(对应删除权限)
17
+ */
18
+ export declare type AssetPermissionAction = 'upload' | 'addUrl' | 'delete';
19
+
12
20
  /**
13
21
  * Block 是注册表驱动的:所有内置/自定义组件都遵循同一个数据形状。
14
22
  * 渲染、属性面板、代码模式三方都从注册表读取该 type 的定义。
@@ -224,7 +232,7 @@ declare interface EditorOptions {
224
232
  */
225
233
  theme?: EditorTheme;
226
234
  /**
227
- * 可选。为 `type: 'image'` 提供上传 / 图床;`showUpload` 默认 true(有 uploadImage 时),`showGallery` 默认 false。
235
+ * 可选。为 `type: 'image'` 提供上传 / 图库;`showUpload` 默认 true(有 uploadImage 时),`showGallery` 默认 false。
228
236
  */
229
237
  imageAssets?: ImageAssetsHandlers;
230
238
  /** 右栏控件形态等可选 UI 偏好。 */
@@ -408,13 +416,34 @@ export declare interface GlobalStyles {
408
416
  /** HTML 块内容是否误含 MJML 标签(应只写 HTML,MJML 标签在 mj-raw 内不会被编译)。 */
409
417
  export declare function htmlContainsMjmlTags(html: string): boolean;
410
418
 
419
+ /**
420
+ * 图片资源动作的权限管控配置。未配置 `check` 时视为全部有权限(不做管控)。
421
+ */
422
+ export declare interface ImageAssetPermissions {
423
+ /**
424
+ * 权限校验:返回 `false` 表示该动作无权限。
425
+ * 未配置时视为全部有权限。
426
+ */
427
+ check?: (action: AssetPermissionAction) => boolean;
428
+ /**
429
+ * 无权限时的表现:
430
+ * - `'disable'`(默认):按钮置灰禁用,hover 提示无权限。
431
+ * - `'hide'`:直接隐藏对应按钮。
432
+ */
433
+ noPermissionMode?: 'disable' | 'hide';
434
+ /**
435
+ * 无权限禁用时 hover 提示文案;未配置或为空时使用编辑器默认文案(`common.noPermission`)。
436
+ */
437
+ noPermissionTip?: string;
438
+ }
439
+
411
440
  export declare interface ImageAssetsHandlers {
412
441
  /**
413
442
  * 用户点击右侧「上传」并选择本地文件。宿主完成上传后返回 **绝对 HTTPS URL**。
414
443
  */
415
444
  uploadImage?: (file: File, ctx: ImageFieldContext) => Promise<string>;
416
445
  /**
417
- * 完全自管图床:与内置 `imageGallery` 可并存;
446
+ * 完全自管图库:与内置 `imageGallery` 可并存;
418
447
  * **同时配置时优先使用内置 `imageGallery` 弹层**。
419
448
  */
420
449
  pickImageFromGallery?: (ctx: ImageFieldContext) => Promise<string | null>;
@@ -429,14 +458,19 @@ export declare interface ImageAssetsHandlers {
429
458
  */
430
459
  showUpload?: boolean;
431
460
  /**
432
- * 是否显示「图床」按钮。在配置了 `pickImageFromGallery` 或 `imageGallery` 时有效。
461
+ * 是否显示「图库」按钮。在配置了 `pickImageFromGallery` 或 `imageGallery` 时有效。
433
462
  * 默认 `false`;需显式设为 `true` 才展示入口。
434
463
  */
435
464
  showGallery?: boolean;
465
+ /**
466
+ * 资源动作权限管控。配置后,「上传 / 添加链接 / 删除」按钮将按 `check` 结果禁用或隐藏。
467
+ * 默认无权限时禁用并 hover 提示。右栏「上传」与图库弹层内按钮共用同一份配置。
468
+ */
469
+ permissions?: ImageAssetPermissions;
436
470
  }
437
471
 
438
472
  /**
439
- * 右侧「图片地址」类字段:宿主可选手输 URL、本地上传、内置图库弹层或完全自管图床回调。
473
+ * 右侧「图片地址」类字段:宿主可选手输 URL、本地上传、内置图库弹层或完全自管图库回调。
440
474
  * 编辑器最终只把 URL 写入 props。
441
475
  */
442
476
  export declare interface ImageFieldContext {
@@ -713,6 +747,11 @@ export declare interface OpenImageGalleryModalOptions {
713
747
  /** 挂载父节点,默认 `document.body` */
714
748
  parent?: HTMLElement;
715
749
  onClose?: () => void;
750
+ /**
751
+ * 资源动作权限管控。未配置或未提供 `check` 时弹层内按钮不做管控;
752
+ * 配置后「添加 / 上传 / 删除」按 `check` 结果禁用(默认)或隐藏,禁用时 hover 提示无权限。
753
+ */
754
+ permissions?: ImageAssetPermissions;
716
755
  }
717
756
 
718
757
  /** 左栏组合拖入:可附带新建 Section 的 attrs(如 meta 扩展袋) */
@@ -799,6 +838,22 @@ export declare function renderSectionBodyHtml(doc: EmailDoc, sectionId: string,
799
838
  */
800
839
  export declare function replaceVariables(text: string, vars: Variable[]): string;
801
840
 
841
+ /**
842
+ * 解析某个动作的权限状态。未配置 `permissions` 或 `check` 时视为有权限。
843
+ * @param defaultNoPermissionTip 编辑器默认的无权限提示文案(由调用方从 i18n 传入)
844
+ */
845
+ export declare function resolveAssetPermission(permissions: ImageAssetPermissions | undefined, action: AssetPermissionAction, defaultNoPermissionTip: string): ResolvedAssetPermission;
846
+
847
+ /** `resolveAssetPermission` 的结果。 */
848
+ export declare interface ResolvedAssetPermission {
849
+ /** `true` 表示有权限 */
850
+ allowed: boolean;
851
+ /** 无权限时的表现(仅在 `allowed === false` 时有意义) */
852
+ mode: 'disable' | 'hide';
853
+ /** 无权限禁用时的 hover 提示文案(仅在 `allowed === false` 且 `mode === 'disable'` 时有意义) */
854
+ tip: string;
855
+ }
856
+
802
857
  /** 锁定块在画布上的渲染结果:preview 为 WYSIWYG HTML,source 为无法解析时的源码回退。 */
803
858
  export declare function resolveLockedMjmlCanvasContent(lockedMjml: string, padding: BlockPaddingBox): {
804
859
  mode: 'preview';