@parathantl/react-email-editor 0.1.7 → 0.1.9

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/dist/index.cjs CHANGED
@@ -3078,9 +3078,8 @@ var editor_default = {
3078
3078
 
3079
3079
  // src/components/Toolbar/Toolbar.tsx
3080
3080
  var import_jsx_runtime4 = require("react/jsx-runtime");
3081
- var Toolbar = import_react15.default.memo(function Toolbar2({ sidebarOpen, propertiesOpen, onToggleSidebar, onToggleProperties }) {
3081
+ var Toolbar = import_react15.default.memo(function Toolbar2({ sidebarOpen, propertiesOpen, onToggleSidebar, onToggleProperties, toolbarActions }) {
3082
3082
  const { template, activeTab } = useTemplateContext();
3083
- const { canUndo, canRedo } = useHistoryContext();
3084
3083
  const dispatch = useEditorDispatch();
3085
3084
  const fileInputRef = (0, import_react15.useRef)(null);
3086
3085
  const [exportOpen, setExportOpen] = (0, import_react15.useState)(false);
@@ -3098,12 +3097,6 @@ var Toolbar = import_react15.default.memo(function Toolbar2({ sidebarOpen, prope
3098
3097
  },
3099
3098
  [dispatch]
3100
3099
  );
3101
- const handleUndo = (0, import_react15.useCallback)(() => {
3102
- dispatch({ type: "UNDO" });
3103
- }, [dispatch]);
3104
- const handleRedo = (0, import_react15.useCallback)(() => {
3105
- dispatch({ type: "REDO" });
3106
- }, [dispatch]);
3107
3100
  const handleExportMJML = (0, import_react15.useCallback)(() => {
3108
3101
  const mjml = generateMJML(templateRef.current);
3109
3102
  const blob = new Blob([mjml], { type: "text/xml" });
@@ -3171,30 +3164,6 @@ var Toolbar = import_react15.default.memo(function Toolbar2({ sidebarOpen, prope
3171
3164
  [dispatch]
3172
3165
  );
3173
3166
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: `ee-toolbar ${toolbar_default.toolbar}`, role: "toolbar", "aria-label": "Editor toolbar", children: [
3174
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: `ee-toolbar-history ${toolbar_default.toolbarGroup}`, role: "group", "aria-label": "History", children: [
3175
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
3176
- "button",
3177
- {
3178
- className: `ee-toolbar-undo ${toolbar_default.toolbarBtn}`,
3179
- onClick: handleUndo,
3180
- disabled: !canUndo,
3181
- title: "Undo (Ctrl+Z)",
3182
- "aria-label": "Undo",
3183
- children: "Undo"
3184
- }
3185
- ),
3186
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
3187
- "button",
3188
- {
3189
- className: `ee-toolbar-redo ${toolbar_default.toolbarBtn}`,
3190
- onClick: handleRedo,
3191
- disabled: !canRedo,
3192
- title: "Redo (Ctrl+Shift+Z)",
3193
- "aria-label": "Redo",
3194
- children: "Redo"
3195
- }
3196
- )
3197
- ] }),
3198
3167
  /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: editor_default.panelToggle, children: [
3199
3168
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
3200
3169
  "button",
@@ -3264,6 +3233,7 @@ var Toolbar = import_react15.default.memo(function Toolbar2({ sidebarOpen, prope
3264
3233
  ] })
3265
3234
  ] })
3266
3235
  ] }),
3236
+ toolbarActions && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: `ee-toolbar-actions ${toolbar_default.toolbarGroup}`, children: toolbarActions }),
3267
3237
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
3268
3238
  "input",
3269
3239
  {
@@ -25176,12 +25146,12 @@ function preventBlur(e) {
25176
25146
  }
25177
25147
  e.preventDefault();
25178
25148
  }
25179
- function RichTextToolbar({ editor }) {
25149
+ function RichTextToolbar({ editor, defaultFontFamily, defaultFontSize }) {
25180
25150
  if (!editor) return null;
25181
25151
  return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: `ee-richtext-toolbar ${toolbar_default.richTextToolbar}`, onMouseDown: preventBlur, children: [
25182
25152
  /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: `ee-richtext-group ${toolbar_default.richTextGroup}`, children: [
25183
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(FontFamilySelect, { editor }),
25184
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(FontSizeSelect, { editor })
25153
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(FontFamilySelect, { editor, defaultFontFamily }),
25154
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(FontSizeSelect, { editor, defaultFontSize })
25185
25155
  ] }),
25186
25156
  /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: `ee-richtext-group ${toolbar_default.richTextGroup}`, children: [
25187
25157
  /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Tooltip, { label: "Bold", shortcut: "Ctrl+B", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
@@ -25364,9 +25334,10 @@ function RichTextToolbar({ editor }) {
25364
25334
  ] })
25365
25335
  ] });
25366
25336
  }
25367
- function FontFamilySelect({ editor }) {
25337
+ function FontFamilySelect({ editor, defaultFontFamily }) {
25368
25338
  const { fontFamilies } = useEditorFonts();
25369
- const currentFont = editor.getAttributes("textStyle").fontFamily || "";
25339
+ const inlineFont = editor.getAttributes("textStyle").fontFamily || "";
25340
+ const currentFont = inlineFont || defaultFontFamily || "";
25370
25341
  const fonts = fontFamilies.slice();
25371
25342
  if (currentFont && !fonts.some((f) => f.toLowerCase() === currentFont.toLowerCase())) {
25372
25343
  fonts.push(currentFont);
@@ -25392,9 +25363,10 @@ function FontFamilySelect({ editor }) {
25392
25363
  }
25393
25364
  );
25394
25365
  }
25395
- function FontSizeSelect({ editor }) {
25366
+ function FontSizeSelect({ editor, defaultFontSize }) {
25396
25367
  const { fontSizes } = useEditorFonts();
25397
- const currentSize = editor.getAttributes("textStyle").fontSize || "";
25368
+ const inlineSize = editor.getAttributes("textStyle").fontSize || "";
25369
+ const currentSize = inlineSize || defaultFontSize || "";
25398
25370
  const sizes = fontSizes.slice();
25399
25371
  if (currentSize && !sizes.includes(currentSize)) {
25400
25372
  sizes.push(currentSize);
@@ -25823,7 +25795,14 @@ var TextBlockInner = function TextBlock({ block }) {
25823
25795
  backgroundColor: p.backgroundColor && p.backgroundColor !== "transparent" ? p.backgroundColor : void 0
25824
25796
  }), [p.fontFamily, p.fontSize, p.color, p.lineHeight, p.padding, p.fontWeight, p.textTransform, p.letterSpacing, p.backgroundColor]);
25825
25797
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: `ee-block-text ${blocks_default.textBlock}`, ref: wrapperRef, children: [
25826
- isFocused && editorInstance && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: blocks_default.textBlockToolbar, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(RichTextToolbar, { editor: editorInstance }) }),
25798
+ isFocused && editorInstance && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: blocks_default.textBlockToolbar, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
25799
+ RichTextToolbar,
25800
+ {
25801
+ editor: editorInstance,
25802
+ defaultFontFamily: p.fontFamily,
25803
+ defaultFontSize: p.fontSize
25804
+ }
25805
+ ) }),
25827
25806
  /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { style: wrapperStyle, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
25828
25807
  TipTapEditor,
25829
25808
  {
@@ -27537,6 +27516,12 @@ var import_react40 = __toESM(require("react"));
27537
27516
 
27538
27517
  // src/styles/canvas.module.css
27539
27518
  var canvas_default = {
27519
+ "canvasArea": "canvasArea",
27520
+ "canvasHeader": "canvasHeader",
27521
+ "canvasHeaderCenter": "canvasHeaderCenter",
27522
+ "canvasHeaderGroup": "canvasHeaderGroup",
27523
+ "canvasHeaderBtn": "canvasHeaderBtn",
27524
+ "canvasHeaderBtnActive": "canvasHeaderBtnActive",
27540
27525
  "canvasWrapper": "canvasWrapper",
27541
27526
  "canvasBody": "canvasBody",
27542
27527
  "canvasBodyDragOver": "canvasBodyDragOver",
@@ -28078,10 +28063,13 @@ var SectionDropZone = import_react43.default.memo(function SectionDropZone2({ in
28078
28063
 
28079
28064
  // src/components/Canvas/Canvas.tsx
28080
28065
  var import_jsx_runtime32 = require("react/jsx-runtime");
28066
+ var MOBILE_WIDTH = 375;
28081
28067
  var Canvas = import_react44.default.memo(function Canvas2() {
28082
28068
  const { template } = useTemplateContext();
28069
+ const { canUndo, canRedo } = useHistoryContext();
28083
28070
  const dispatch = useEditorDispatch();
28084
28071
  const [isDragOver, setIsDragOver] = (0, import_react44.useState)(false);
28072
+ const [previewMode, setPreviewMode] = (0, import_react44.useState)("desktop");
28085
28073
  const handleAddSection = (0, import_react44.useCallback)(() => {
28086
28074
  dispatch({ type: "ADD_SECTION", payload: { section: createSection() } });
28087
28075
  }, [dispatch]);
@@ -28119,30 +28107,89 @@ var Canvas = import_react44.default.memo(function Canvas2() {
28119
28107
  },
28120
28108
  [dispatch]
28121
28109
  );
28122
- return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("div", { className: `ee-canvas-wrapper ${canvas_default.canvasWrapper}`, onClick: handleCanvasClick, role: "main", "aria-label": "Email canvas", children: /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(
28123
- "div",
28124
- {
28125
- className: `ee-canvas-body ${canvas_default.canvasBody} ${isDragOver ? canvas_default.canvasBodyDragOver : ""}`,
28126
- style: {
28127
- width: template.globalStyles.width,
28128
- backgroundColor: template.globalStyles.backgroundColor,
28129
- fontFamily: template.globalStyles.fontFamily
28130
- },
28131
- onClick: (e) => e.stopPropagation(),
28132
- onDragOver: handleBodyDragOver,
28133
- onDragLeave: handleBodyDragLeave,
28134
- onDrop: handleBodyDrop,
28135
- "aria-label": "Email content area",
28136
- children: [
28137
- template.sections.map((section, index) => /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(import_react44.default.Fragment, { children: [
28138
- /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(SectionDropZone, { index }),
28139
- /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(Section, { section })
28140
- ] }, section.id)),
28141
- template.sections.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(SectionDropZone, { index: template.sections.length }),
28142
- /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("button", { className: `ee-add-section ${canvas_default.addSectionBtn}`, onClick: handleAddSection, "aria-label": "Add new section", children: "+ Add Section" })
28143
- ]
28144
- }
28145
- ) });
28110
+ const handleUndo = (0, import_react44.useCallback)(() => {
28111
+ dispatch({ type: "UNDO" });
28112
+ }, [dispatch]);
28113
+ const handleRedo = (0, import_react44.useCallback)(() => {
28114
+ dispatch({ type: "REDO" });
28115
+ }, [dispatch]);
28116
+ const canvasWidth = previewMode === "mobile" ? MOBILE_WIDTH : template.globalStyles.width;
28117
+ return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)("div", { className: `ee-canvas-area ${canvas_default.canvasArea}`, children: [
28118
+ /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)("div", { className: `ee-canvas-header ${canvas_default.canvasHeader}`, children: [
28119
+ /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("div", { className: `ee-canvas-header-center ${canvas_default.canvasHeaderCenter}`, children: /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)("div", { className: `ee-canvas-view-toggle ${canvas_default.canvasHeaderGroup}`, role: "group", "aria-label": "Preview size", children: [
28120
+ /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
28121
+ "button",
28122
+ {
28123
+ className: `ee-canvas-view-desktop ${canvas_default.canvasHeaderBtn} ${previewMode === "desktop" ? `ee-canvas-view--active ${canvas_default.canvasHeaderBtnActive}` : ""}`,
28124
+ onClick: () => setPreviewMode("desktop"),
28125
+ "aria-pressed": previewMode === "desktop",
28126
+ "aria-label": "Desktop view",
28127
+ title: `Desktop (${template.globalStyles.width}px)`,
28128
+ children: "\u{1F5A5}"
28129
+ }
28130
+ ),
28131
+ /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
28132
+ "button",
28133
+ {
28134
+ className: `ee-canvas-view-mobile ${canvas_default.canvasHeaderBtn} ${previewMode === "mobile" ? `ee-canvas-view--active ${canvas_default.canvasHeaderBtnActive}` : ""}`,
28135
+ onClick: () => setPreviewMode("mobile"),
28136
+ "aria-pressed": previewMode === "mobile",
28137
+ "aria-label": "Mobile view",
28138
+ title: "Mobile (375px)",
28139
+ children: "\u{1F4F1}"
28140
+ }
28141
+ )
28142
+ ] }) }),
28143
+ /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)("div", { className: `ee-canvas-history ${canvas_default.canvasHeaderGroup}`, role: "group", "aria-label": "History", children: [
28144
+ /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
28145
+ "button",
28146
+ {
28147
+ className: `ee-canvas-undo ${canvas_default.canvasHeaderBtn}`,
28148
+ onClick: handleUndo,
28149
+ disabled: !canUndo,
28150
+ title: "Undo (Ctrl+Z)",
28151
+ "aria-label": "Undo",
28152
+ children: "\u21A9"
28153
+ }
28154
+ ),
28155
+ /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
28156
+ "button",
28157
+ {
28158
+ className: `ee-canvas-redo ${canvas_default.canvasHeaderBtn}`,
28159
+ onClick: handleRedo,
28160
+ disabled: !canRedo,
28161
+ title: "Redo (Ctrl+Shift+Z)",
28162
+ "aria-label": "Redo",
28163
+ children: "\u21AA"
28164
+ }
28165
+ )
28166
+ ] })
28167
+ ] }),
28168
+ /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("div", { className: `ee-canvas-wrapper ${canvas_default.canvasWrapper}`, onClick: handleCanvasClick, role: "main", "aria-label": "Email canvas", children: /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(
28169
+ "div",
28170
+ {
28171
+ className: `ee-canvas-body ${canvas_default.canvasBody} ${isDragOver ? canvas_default.canvasBodyDragOver : ""}`,
28172
+ style: {
28173
+ width: canvasWidth,
28174
+ backgroundColor: template.globalStyles.backgroundColor,
28175
+ fontFamily: template.globalStyles.fontFamily
28176
+ },
28177
+ onClick: (e) => e.stopPropagation(),
28178
+ onDragOver: handleBodyDragOver,
28179
+ onDragLeave: handleBodyDragLeave,
28180
+ onDrop: handleBodyDrop,
28181
+ "aria-label": "Email content area",
28182
+ children: [
28183
+ template.sections.map((section, index) => /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(import_react44.default.Fragment, { children: [
28184
+ /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(SectionDropZone, { index }),
28185
+ /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(Section, { section })
28186
+ ] }, section.id)),
28187
+ template.sections.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(SectionDropZone, { index: template.sections.length }),
28188
+ /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("button", { className: `ee-add-section ${canvas_default.addSectionBtn}`, onClick: handleAddSection, "aria-label": "Add new section", children: "+ Add Section" })
28189
+ ]
28190
+ }
28191
+ ) })
28192
+ ] });
28146
28193
  });
28147
28194
 
28148
28195
  // src/components/Properties/SectionProperties.tsx
@@ -29826,7 +29873,8 @@ var EditorInner = (0, import_react61.forwardRef)(function EditorInner2(props, re
29826
29873
  sidebarOpen,
29827
29874
  propertiesOpen,
29828
29875
  onToggleSidebar: toggleSidebar,
29829
- onToggleProperties: toggleProperties
29876
+ onToggleProperties: toggleProperties,
29877
+ toolbarActions: props.toolbarActions
29830
29878
  }
29831
29879
  ),
29832
29880
  /* @__PURE__ */ (0, import_jsx_runtime58.jsxs)("div", { className: editor_default.editorBody, children: [