@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.cjs CHANGED
@@ -4191,6 +4191,7 @@ var COLUMN_CHILDREN = /* @__PURE__ */ new Set([
4191
4191
  "mj-table",
4192
4192
  "mj-text"
4193
4193
  ]);
4194
+ var HEAD_CSS = '[data-gjs-type="mj-head"] { display: none !important; }';
4194
4195
  function fixPluginTypes(editor) {
4195
4196
  addTableType(editor);
4196
4197
  for (const type of editor.Components.getTypes()) {
@@ -4200,6 +4201,8 @@ function fixPluginTypes(editor) {
4200
4201
  editor.Components.addType(type.id, {
4201
4202
  ...type.id === "mj-column" && { view: groupedColumnView(view) },
4202
4203
  ...type.id === "mj-group" && { view: redrawnGroupView(view) },
4204
+ ...type.id === "mj-social" && { view: stackedSocialGroupView(view) },
4205
+ ...type.id === "mj-social-element" && { view: socialIconView(view) },
4203
4206
  model: {
4204
4207
  defaults: {
4205
4208
  "style-default": {},
@@ -4258,6 +4261,75 @@ function redrawnGroupView(base) {
4258
4261
  }
4259
4262
  };
4260
4263
  }
4264
+ function socialLayout(mode, align) {
4265
+ if (mode !== "vertical") {
4266
+ return {
4267
+ icon: { display: "inline-table", gridColumn: "", gridTemplateColumns: "", alignItems: "" },
4268
+ column: { display: "", gridTemplateColumns: "", justifyContent: "" }
4269
+ };
4270
+ }
4271
+ const side = align === "left" ? "start" : align === "right" ? "end" : "center";
4272
+ return {
4273
+ icon: {
4274
+ display: "grid",
4275
+ gridColumn: "1 / -1",
4276
+ gridTemplateColumns: "subgrid",
4277
+ alignItems: "center"
4278
+ },
4279
+ column: { display: "grid", gridTemplateColumns: "auto auto", justifyContent: side }
4280
+ };
4281
+ }
4282
+ var groupLayout = (group) => {
4283
+ const attributes = group?.getAttributes() ?? {};
4284
+ return socialLayout(attributes.mode, attributes.align);
4285
+ };
4286
+ function stackedSocialGroupView(base) {
4287
+ return {
4288
+ render() {
4289
+ const drawn = base.render.call(this);
4290
+ Object.assign(this.getChildrenContainer().style, groupLayout(this.model).column);
4291
+ return drawn;
4292
+ }
4293
+ };
4294
+ }
4295
+ function socialLabel(icon) {
4296
+ const row = icon.querySelector("tr");
4297
+ const cell = Array.from(row?.cells ?? []).find((td) => !td.querySelector("table"));
4298
+ return cell?.firstElementChild ?? null;
4299
+ }
4300
+ function socialIconView(base) {
4301
+ return {
4302
+ // The label decides whether MJML draws a label cell, so a change to it redraws the icon.
4303
+ init() {
4304
+ base.init.call(this);
4305
+ this.listenTo(this.model.components(), "add remove", this.render);
4306
+ },
4307
+ // A change to the group's attributes redraws its icons, so each lays out the cell as well.
4308
+ render() {
4309
+ const drawn = base.render.call(this);
4310
+ const { icon, column } = groupLayout(this.model.parent());
4311
+ Object.assign(this.el.style, icon);
4312
+ if (icon.display === "grid") {
4313
+ for (const part of this.el.querySelectorAll(
4314
+ ":scope > tbody, :scope > tbody > tr"
4315
+ )) {
4316
+ part.style.display = "contents";
4317
+ }
4318
+ }
4319
+ if (this.el.parentElement) Object.assign(this.el.parentElement.style, column);
4320
+ return drawn;
4321
+ },
4322
+ // With its label, so MJML draws the label's cell, and on the side `icon-position` says.
4323
+ getInnerMjmlTemplate() {
4324
+ const { start, end } = base.getInnerMjmlTemplate.call(this);
4325
+ return { start: `${start}${this.model.getInnerHTML()}`, end };
4326
+ },
4327
+ // The label's components are drawn in that cell; the plugin's container is the `<img>`.
4328
+ getChildrenContainer() {
4329
+ return socialLabel(this.el) ?? base.getChildrenContainer.call(this);
4330
+ }
4331
+ };
4332
+ }
4261
4333
 
4262
4334
  // src/components/editor/EmailEditor.tsx
4263
4335
  var import_jsx_runtime17 = require("react/jsx-runtime");
@@ -4760,7 +4832,7 @@ function EmailEditor({
4760
4832
  // privacy policy. Nothing we show uses it: GrapesJS draws its toolbar and layer icons
4761
4833
  // as SVG, and its icon-font panels and style manager are not rendered here.
4762
4834
  cssIcons: "",
4763
- canvasCss: CANVAS_CSS,
4835
+ canvasCss: CANVAS_CSS + HEAD_CSS,
4764
4836
  fromElement: false,
4765
4837
  panels: { defaults: [] },
4766
4838
  blockManager: { appendTo: "#gjs-blocks" },