@mjml-agent-editor/editor 0.5.1 → 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/dist/canvas.js CHANGED
@@ -3311,6 +3311,8 @@ function fixPluginTypes(editor) {
3311
3311
  editor.Components.addType(type.id, {
3312
3312
  ...type.id === "mj-column" && { view: groupedColumnView(view) },
3313
3313
  ...type.id === "mj-group" && { view: redrawnGroupView(view) },
3314
+ ...type.id === "mj-social" && { view: stackedSocialGroupView(view) },
3315
+ ...type.id === "mj-social-element" && { view: socialIconView(view) },
3314
3316
  model: {
3315
3317
  defaults: {
3316
3318
  "style-default": {},
@@ -3369,6 +3371,75 @@ function redrawnGroupView(base) {
3369
3371
  }
3370
3372
  };
3371
3373
  }
3374
+ function socialLayout(mode, align) {
3375
+ if (mode !== "vertical") {
3376
+ return {
3377
+ icon: { display: "inline-table", gridColumn: "", gridTemplateColumns: "", alignItems: "" },
3378
+ column: { display: "", gridTemplateColumns: "", justifyContent: "" }
3379
+ };
3380
+ }
3381
+ const side = align === "left" ? "start" : align === "right" ? "end" : "center";
3382
+ return {
3383
+ icon: {
3384
+ display: "grid",
3385
+ gridColumn: "1 / -1",
3386
+ gridTemplateColumns: "subgrid",
3387
+ alignItems: "center"
3388
+ },
3389
+ column: { display: "grid", gridTemplateColumns: "auto auto", justifyContent: side }
3390
+ };
3391
+ }
3392
+ var groupLayout = (group) => {
3393
+ const attributes = group?.getAttributes() ?? {};
3394
+ return socialLayout(attributes.mode, attributes.align);
3395
+ };
3396
+ function stackedSocialGroupView(base) {
3397
+ return {
3398
+ render() {
3399
+ const drawn = base.render.call(this);
3400
+ Object.assign(this.getChildrenContainer().style, groupLayout(this.model).column);
3401
+ return drawn;
3402
+ }
3403
+ };
3404
+ }
3405
+ function socialLabel(icon) {
3406
+ const row = icon.querySelector("tr");
3407
+ const cell = Array.from(row?.cells ?? []).find((td) => !td.querySelector("table"));
3408
+ return cell?.firstElementChild ?? null;
3409
+ }
3410
+ function socialIconView(base) {
3411
+ return {
3412
+ // The label decides whether MJML draws a label cell, so a change to it redraws the icon.
3413
+ init() {
3414
+ base.init.call(this);
3415
+ this.listenTo(this.model.components(), "add remove", this.render);
3416
+ },
3417
+ // A change to the group's attributes redraws its icons, so each lays out the cell as well.
3418
+ render() {
3419
+ const drawn = base.render.call(this);
3420
+ const { icon, column } = groupLayout(this.model.parent());
3421
+ Object.assign(this.el.style, icon);
3422
+ if (icon.display === "grid") {
3423
+ for (const part of this.el.querySelectorAll(
3424
+ ":scope > tbody, :scope > tbody > tr"
3425
+ )) {
3426
+ part.style.display = "contents";
3427
+ }
3428
+ }
3429
+ if (this.el.parentElement) Object.assign(this.el.parentElement.style, column);
3430
+ return drawn;
3431
+ },
3432
+ // With its label, so MJML draws the label's cell, and on the side `icon-position` says.
3433
+ getInnerMjmlTemplate() {
3434
+ const { start, end } = base.getInnerMjmlTemplate.call(this);
3435
+ return { start: `${start}${this.model.getInnerHTML()}`, end };
3436
+ },
3437
+ // The label's components are drawn in that cell; the plugin's container is the `<img>`.
3438
+ getChildrenContainer() {
3439
+ return socialLabel(this.el) ?? base.getChildrenContainer.call(this);
3440
+ }
3441
+ };
3442
+ }
3372
3443
 
3373
3444
  // src/components/editor/EmailEditor.tsx
3374
3445
  import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";