@mjml-agent-editor/editor 0.5.0 → 0.5.1

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
@@ -4047,7 +4047,9 @@ function registerBlocks(editor, blocks, category, media) {
4047
4047
  category,
4048
4048
  media: block.media ?? media,
4049
4049
  content: withClosedTags(block.mjml),
4050
- attributes: tileAttributes(block.id)
4050
+ attributes: tileAttributes(block.id),
4051
+ // Selected once dropped, as grapesjs-mjml's own blocks are, so its Settings open.
4052
+ select: true
4051
4053
  });
4052
4054
  }
4053
4055
  }
@@ -4090,6 +4092,15 @@ function builtinBlock(labels) {
4090
4092
  }
4091
4093
  var CANVAS_CSS = 'img:not([src]), img[src=""] { min-height: 120px; background: #f4f4f5; outline: 1px dashed #a1a1aa; outline-offset: -1px; }';
4092
4094
 
4095
+ // src/components/editor/settings-follow.ts
4096
+ function clickShowsSettings(selected, target) {
4097
+ return !!selected && !!target && selected.contains(target);
4098
+ }
4099
+ function dropShowsSettings(added, selected) {
4100
+ const first = Array.isArray(added) ? added[0] : added;
4101
+ return first !== void 0 && first === selected;
4102
+ }
4103
+
4093
4104
  // src/components/editor/table-type.ts
4094
4105
  var import_core3 = require("@mjml-agent-editor/core");
4095
4106
  var DROPPED = "script, style, link, iframe, frame, object, embed, applet, base, meta, animate, set, svg, math, template";
@@ -4372,7 +4383,6 @@ function EmailEditor({
4372
4383
  requestAnimationFrame(() => blockSearchRef.current?.focus());
4373
4384
  };
4374
4385
  const [composeTarget, setComposeTarget] = (0, import_react10.useState)(null);
4375
- const selectionSource = (0, import_react10.useRef)("other");
4376
4386
  const editorRef = (0, import_react10.useRef)(null);
4377
4387
  const { running: turnRunning, locked: readOnly, setLocked } = useAgentTurn();
4378
4388
  const readOnlyRef = (0, import_react10.useRef)(false);
@@ -4528,23 +4538,24 @@ function EmailEditor({
4528
4538
  decorate(c);
4529
4539
  });
4530
4540
  editor.on("load", () => {
4531
- const body = editor.Canvas.getBody();
4532
- body?.addEventListener(
4533
- "mousedown",
4534
- () => {
4535
- selectionSource.current = "canvas";
4536
- },
4537
- true
4541
+ editor.Canvas.getBody()?.addEventListener(
4542
+ "click",
4543
+ (e) => setTimeout(() => {
4544
+ if (clickShowsSettings(editor.getSelected()?.getEl(), e.target)) {
4545
+ setSidebarView("settings");
4546
+ }
4547
+ })
4538
4548
  );
4539
4549
  editor.Canvas.getDocument()?.addEventListener("keydown", onBlockSearchKey);
4540
4550
  showBodyInLayers();
4541
4551
  });
4542
4552
  editor.on("component:selected", (c) => {
4543
4553
  keepStructureOpen();
4544
- if (selectionSource.current === "canvas") setSidebarView("settings");
4545
- selectionSource.current = "other";
4546
4554
  buildCrumbs(c);
4547
4555
  });
4556
+ editor.on("block:drag:stop", (added) => {
4557
+ if (dropShowsSettings(added, editor.getSelected())) setSidebarView("settings");
4558
+ });
4548
4559
  editor.on("component:deselected", () => {
4549
4560
  buildCrumbs(editor.getSelected());
4550
4561
  });
@@ -4811,7 +4822,6 @@ function EmailEditor({
4811
4822
  {
4812
4823
  view: sidebarView,
4813
4824
  onViewChange: setSidebarView,
4814
- markLayersSource: () => selectionSource.current = "layers",
4815
4825
  blockSearchRef
4816
4826
  }
4817
4827
  ),
@@ -4855,7 +4865,6 @@ function EmailEditor({
4855
4865
  function LeftSidebar({
4856
4866
  view,
4857
4867
  onViewChange,
4858
- markLayersSource,
4859
4868
  blockSearchRef
4860
4869
  }) {
4861
4870
  const editor = (0, import_react9.useEditorMaybe)();
@@ -4963,36 +4972,29 @@ function LeftSidebar({
4963
4972
  ] })
4964
4973
  }
4965
4974
  ) }),
4966
- /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
4967
- "div",
4968
- {
4969
- className: cn("flex min-h-0 flex-1 flex-col", view !== "layers" && "hidden"),
4970
- onMouseDownCapture: markLayersSource,
4971
- children: [
4972
- /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("label", { className: "flex items-center justify-between gap-2 border-b border-panel-border px-3 py-2 text-xs text-panel-muted-fg", children: [
4973
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { children: labels.expandAll }),
4974
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
4975
- Switch,
4976
- {
4977
- checked: layersExpanded,
4978
- onCheckedChange: toggleLayers,
4979
- className: "data-[state=checked]:bg-brand data-[state=unchecked]:bg-panel-border"
4980
- }
4981
- )
4982
- ] }),
4983
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
4984
- "div",
4985
- {
4986
- id: "gjs-layers",
4987
- className: "min-h-0 flex-1 overflow-y-auto",
4988
- onDoubleClickCapture: (e) => {
4989
- if (e.target.closest("[data-name]")) e.stopPropagation();
4990
- }
4991
- }
4992
- )
4993
- ]
4994
- }
4995
- )
4975
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: cn("flex min-h-0 flex-1 flex-col", view !== "layers" && "hidden"), children: [
4976
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("label", { className: "flex items-center justify-between gap-2 border-b border-panel-border px-3 py-2 text-xs text-panel-muted-fg", children: [
4977
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { children: labels.expandAll }),
4978
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
4979
+ Switch,
4980
+ {
4981
+ checked: layersExpanded,
4982
+ onCheckedChange: toggleLayers,
4983
+ className: "data-[state=checked]:bg-brand data-[state=unchecked]:bg-panel-border"
4984
+ }
4985
+ )
4986
+ ] }),
4987
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
4988
+ "div",
4989
+ {
4990
+ id: "gjs-layers",
4991
+ className: "min-h-0 flex-1 overflow-y-auto",
4992
+ onDoubleClickCapture: (e) => {
4993
+ if (e.target.closest("[data-name]")) e.stopPropagation();
4994
+ }
4995
+ }
4996
+ )
4997
+ ] })
4996
4998
  ] });
4997
4999
  }
4998
5000
  function Breadcrumb({