@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.cjs +71 -0
- package/dist/canvas.cjs.map +1 -1
- package/dist/canvas.js +71 -0
- package/dist/canvas.js.map +1 -1
- package/package.json +1 -1
package/dist/canvas.cjs
CHANGED
|
@@ -4200,6 +4200,8 @@ function fixPluginTypes(editor) {
|
|
|
4200
4200
|
editor.Components.addType(type.id, {
|
|
4201
4201
|
...type.id === "mj-column" && { view: groupedColumnView(view) },
|
|
4202
4202
|
...type.id === "mj-group" && { view: redrawnGroupView(view) },
|
|
4203
|
+
...type.id === "mj-social" && { view: stackedSocialGroupView(view) },
|
|
4204
|
+
...type.id === "mj-social-element" && { view: socialIconView(view) },
|
|
4203
4205
|
model: {
|
|
4204
4206
|
defaults: {
|
|
4205
4207
|
"style-default": {},
|
|
@@ -4258,6 +4260,75 @@ function redrawnGroupView(base) {
|
|
|
4258
4260
|
}
|
|
4259
4261
|
};
|
|
4260
4262
|
}
|
|
4263
|
+
function socialLayout(mode, align) {
|
|
4264
|
+
if (mode !== "vertical") {
|
|
4265
|
+
return {
|
|
4266
|
+
icon: { display: "inline-table", gridColumn: "", gridTemplateColumns: "", alignItems: "" },
|
|
4267
|
+
column: { display: "", gridTemplateColumns: "", justifyContent: "" }
|
|
4268
|
+
};
|
|
4269
|
+
}
|
|
4270
|
+
const side = align === "left" ? "start" : align === "right" ? "end" : "center";
|
|
4271
|
+
return {
|
|
4272
|
+
icon: {
|
|
4273
|
+
display: "grid",
|
|
4274
|
+
gridColumn: "1 / -1",
|
|
4275
|
+
gridTemplateColumns: "subgrid",
|
|
4276
|
+
alignItems: "center"
|
|
4277
|
+
},
|
|
4278
|
+
column: { display: "grid", gridTemplateColumns: "auto auto", justifyContent: side }
|
|
4279
|
+
};
|
|
4280
|
+
}
|
|
4281
|
+
var groupLayout = (group) => {
|
|
4282
|
+
const attributes = group?.getAttributes() ?? {};
|
|
4283
|
+
return socialLayout(attributes.mode, attributes.align);
|
|
4284
|
+
};
|
|
4285
|
+
function stackedSocialGroupView(base) {
|
|
4286
|
+
return {
|
|
4287
|
+
render() {
|
|
4288
|
+
const drawn = base.render.call(this);
|
|
4289
|
+
Object.assign(this.getChildrenContainer().style, groupLayout(this.model).column);
|
|
4290
|
+
return drawn;
|
|
4291
|
+
}
|
|
4292
|
+
};
|
|
4293
|
+
}
|
|
4294
|
+
function socialLabel(icon) {
|
|
4295
|
+
const row = icon.querySelector("tr");
|
|
4296
|
+
const cell = Array.from(row?.cells ?? []).find((td) => !td.querySelector("table"));
|
|
4297
|
+
return cell?.firstElementChild ?? null;
|
|
4298
|
+
}
|
|
4299
|
+
function socialIconView(base) {
|
|
4300
|
+
return {
|
|
4301
|
+
// The label decides whether MJML draws a label cell, so a change to it redraws the icon.
|
|
4302
|
+
init() {
|
|
4303
|
+
base.init.call(this);
|
|
4304
|
+
this.listenTo(this.model.components(), "add remove", this.render);
|
|
4305
|
+
},
|
|
4306
|
+
// A change to the group's attributes redraws its icons, so each lays out the cell as well.
|
|
4307
|
+
render() {
|
|
4308
|
+
const drawn = base.render.call(this);
|
|
4309
|
+
const { icon, column } = groupLayout(this.model.parent());
|
|
4310
|
+
Object.assign(this.el.style, icon);
|
|
4311
|
+
if (icon.display === "grid") {
|
|
4312
|
+
for (const part of this.el.querySelectorAll(
|
|
4313
|
+
":scope > tbody, :scope > tbody > tr"
|
|
4314
|
+
)) {
|
|
4315
|
+
part.style.display = "contents";
|
|
4316
|
+
}
|
|
4317
|
+
}
|
|
4318
|
+
if (this.el.parentElement) Object.assign(this.el.parentElement.style, column);
|
|
4319
|
+
return drawn;
|
|
4320
|
+
},
|
|
4321
|
+
// With its label, so MJML draws the label's cell, and on the side `icon-position` says.
|
|
4322
|
+
getInnerMjmlTemplate() {
|
|
4323
|
+
const { start, end } = base.getInnerMjmlTemplate.call(this);
|
|
4324
|
+
return { start: `${start}${this.model.getInnerHTML()}`, end };
|
|
4325
|
+
},
|
|
4326
|
+
// The label's components are drawn in that cell; the plugin's container is the `<img>`.
|
|
4327
|
+
getChildrenContainer() {
|
|
4328
|
+
return socialLabel(this.el) ?? base.getChildrenContainer.call(this);
|
|
4329
|
+
}
|
|
4330
|
+
};
|
|
4331
|
+
}
|
|
4261
4332
|
|
|
4262
4333
|
// src/components/editor/EmailEditor.tsx
|
|
4263
4334
|
var import_jsx_runtime17 = require("react/jsx-runtime");
|