@mjml-agent-editor/editor 0.5.1 → 0.5.3

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/canvas.js CHANGED
@@ -3302,6 +3302,7 @@ var COLUMN_CHILDREN = /* @__PURE__ */ new Set([
3302
3302
  "mj-table",
3303
3303
  "mj-text"
3304
3304
  ]);
3305
+ var HEAD_CSS = '[data-gjs-type="mj-head"] { display: none !important; }';
3305
3306
  function fixPluginTypes(editor) {
3306
3307
  addTableType(editor);
3307
3308
  for (const type of editor.Components.getTypes()) {
@@ -3311,6 +3312,8 @@ function fixPluginTypes(editor) {
3311
3312
  editor.Components.addType(type.id, {
3312
3313
  ...type.id === "mj-column" && { view: groupedColumnView(view) },
3313
3314
  ...type.id === "mj-group" && { view: redrawnGroupView(view) },
3315
+ ...type.id === "mj-social" && { view: stackedSocialGroupView(view) },
3316
+ ...type.id === "mj-social-element" && { view: socialIconView(view) },
3314
3317
  model: {
3315
3318
  defaults: {
3316
3319
  "style-default": {},
@@ -3369,6 +3372,75 @@ function redrawnGroupView(base) {
3369
3372
  }
3370
3373
  };
3371
3374
  }
3375
+ function socialLayout(mode, align) {
3376
+ if (mode !== "vertical") {
3377
+ return {
3378
+ icon: { display: "inline-table", gridColumn: "", gridTemplateColumns: "", alignItems: "" },
3379
+ column: { display: "", gridTemplateColumns: "", justifyContent: "" }
3380
+ };
3381
+ }
3382
+ const side = align === "left" ? "start" : align === "right" ? "end" : "center";
3383
+ return {
3384
+ icon: {
3385
+ display: "grid",
3386
+ gridColumn: "1 / -1",
3387
+ gridTemplateColumns: "subgrid",
3388
+ alignItems: "center"
3389
+ },
3390
+ column: { display: "grid", gridTemplateColumns: "auto auto", justifyContent: side }
3391
+ };
3392
+ }
3393
+ var groupLayout = (group) => {
3394
+ const attributes = group?.getAttributes() ?? {};
3395
+ return socialLayout(attributes.mode, attributes.align);
3396
+ };
3397
+ function stackedSocialGroupView(base) {
3398
+ return {
3399
+ render() {
3400
+ const drawn = base.render.call(this);
3401
+ Object.assign(this.getChildrenContainer().style, groupLayout(this.model).column);
3402
+ return drawn;
3403
+ }
3404
+ };
3405
+ }
3406
+ function socialLabel(icon) {
3407
+ const row = icon.querySelector("tr");
3408
+ const cell = Array.from(row?.cells ?? []).find((td) => !td.querySelector("table"));
3409
+ return cell?.firstElementChild ?? null;
3410
+ }
3411
+ function socialIconView(base) {
3412
+ return {
3413
+ // The label decides whether MJML draws a label cell, so a change to it redraws the icon.
3414
+ init() {
3415
+ base.init.call(this);
3416
+ this.listenTo(this.model.components(), "add remove", this.render);
3417
+ },
3418
+ // A change to the group's attributes redraws its icons, so each lays out the cell as well.
3419
+ render() {
3420
+ const drawn = base.render.call(this);
3421
+ const { icon, column } = groupLayout(this.model.parent());
3422
+ Object.assign(this.el.style, icon);
3423
+ if (icon.display === "grid") {
3424
+ for (const part of this.el.querySelectorAll(
3425
+ ":scope > tbody, :scope > tbody > tr"
3426
+ )) {
3427
+ part.style.display = "contents";
3428
+ }
3429
+ }
3430
+ if (this.el.parentElement) Object.assign(this.el.parentElement.style, column);
3431
+ return drawn;
3432
+ },
3433
+ // With its label, so MJML draws the label's cell, and on the side `icon-position` says.
3434
+ getInnerMjmlTemplate() {
3435
+ const { start, end } = base.getInnerMjmlTemplate.call(this);
3436
+ return { start: `${start}${this.model.getInnerHTML()}`, end };
3437
+ },
3438
+ // The label's components are drawn in that cell; the plugin's container is the `<img>`.
3439
+ getChildrenContainer() {
3440
+ return socialLabel(this.el) ?? base.getChildrenContainer.call(this);
3441
+ }
3442
+ };
3443
+ }
3372
3444
 
3373
3445
  // src/components/editor/EmailEditor.tsx
3374
3446
  import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
@@ -3871,7 +3943,7 @@ function EmailEditor({
3871
3943
  // privacy policy. Nothing we show uses it: GrapesJS draws its toolbar and layer icons
3872
3944
  // as SVG, and its icon-font panels and style manager are not rendered here.
3873
3945
  cssIcons: "",
3874
- canvasCss: CANVAS_CSS,
3946
+ canvasCss: CANVAS_CSS + HEAD_CSS,
3875
3947
  fromElement: false,
3876
3948
  panels: { defaults: [] },
3877
3949
  blockManager: { appendTo: "#gjs-blocks" },