@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.js CHANGED
@@ -3158,7 +3158,9 @@ function registerBlocks(editor, blocks, category, media) {
3158
3158
  category,
3159
3159
  media: block.media ?? media,
3160
3160
  content: withClosedTags(block.mjml),
3161
- attributes: tileAttributes(block.id)
3161
+ attributes: tileAttributes(block.id),
3162
+ // Selected once dropped, as grapesjs-mjml's own blocks are, so its Settings open.
3163
+ select: true
3162
3164
  });
3163
3165
  }
3164
3166
  }
@@ -3201,6 +3203,15 @@ function builtinBlock(labels) {
3201
3203
  }
3202
3204
  var CANVAS_CSS = 'img:not([src]), img[src=""] { min-height: 120px; background: #f4f4f5; outline: 1px dashed #a1a1aa; outline-offset: -1px; }';
3203
3205
 
3206
+ // src/components/editor/settings-follow.ts
3207
+ function clickShowsSettings(selected, target) {
3208
+ return !!selected && !!target && selected.contains(target);
3209
+ }
3210
+ function dropShowsSettings(added, selected) {
3211
+ const first = Array.isArray(added) ? added[0] : added;
3212
+ return first !== void 0 && first === selected;
3213
+ }
3214
+
3204
3215
  // src/components/editor/table-type.ts
3205
3216
  import { isSafeLink as isSafeLink2 } from "@mjml-agent-editor/core";
3206
3217
  var DROPPED = "script, style, link, iframe, frame, object, embed, applet, base, meta, animate, set, svg, math, template";
@@ -3483,7 +3494,6 @@ function EmailEditor({
3483
3494
  requestAnimationFrame(() => blockSearchRef.current?.focus());
3484
3495
  };
3485
3496
  const [composeTarget, setComposeTarget] = useState5(null);
3486
- const selectionSource = useRef5("other");
3487
3497
  const editorRef = useRef5(null);
3488
3498
  const { running: turnRunning, locked: readOnly, setLocked } = useAgentTurn();
3489
3499
  const readOnlyRef = useRef5(false);
@@ -3639,23 +3649,24 @@ function EmailEditor({
3639
3649
  decorate(c);
3640
3650
  });
3641
3651
  editor.on("load", () => {
3642
- const body = editor.Canvas.getBody();
3643
- body?.addEventListener(
3644
- "mousedown",
3645
- () => {
3646
- selectionSource.current = "canvas";
3647
- },
3648
- true
3652
+ editor.Canvas.getBody()?.addEventListener(
3653
+ "click",
3654
+ (e) => setTimeout(() => {
3655
+ if (clickShowsSettings(editor.getSelected()?.getEl(), e.target)) {
3656
+ setSidebarView("settings");
3657
+ }
3658
+ })
3649
3659
  );
3650
3660
  editor.Canvas.getDocument()?.addEventListener("keydown", onBlockSearchKey);
3651
3661
  showBodyInLayers();
3652
3662
  });
3653
3663
  editor.on("component:selected", (c) => {
3654
3664
  keepStructureOpen();
3655
- if (selectionSource.current === "canvas") setSidebarView("settings");
3656
- selectionSource.current = "other";
3657
3665
  buildCrumbs(c);
3658
3666
  });
3667
+ editor.on("block:drag:stop", (added) => {
3668
+ if (dropShowsSettings(added, editor.getSelected())) setSidebarView("settings");
3669
+ });
3659
3670
  editor.on("component:deselected", () => {
3660
3671
  buildCrumbs(editor.getSelected());
3661
3672
  });
@@ -3922,7 +3933,6 @@ function EmailEditor({
3922
3933
  {
3923
3934
  view: sidebarView,
3924
3935
  onViewChange: setSidebarView,
3925
- markLayersSource: () => selectionSource.current = "layers",
3926
3936
  blockSearchRef
3927
3937
  }
3928
3938
  ),
@@ -3966,7 +3976,6 @@ function EmailEditor({
3966
3976
  function LeftSidebar({
3967
3977
  view,
3968
3978
  onViewChange,
3969
- markLayersSource,
3970
3979
  blockSearchRef
3971
3980
  }) {
3972
3981
  const editor = useEditorMaybe2();
@@ -4074,36 +4083,29 @@ function LeftSidebar({
4074
4083
  ] })
4075
4084
  }
4076
4085
  ) }),
4077
- /* @__PURE__ */ jsxs7(
4078
- "div",
4079
- {
4080
- className: cn("flex min-h-0 flex-1 flex-col", view !== "layers" && "hidden"),
4081
- onMouseDownCapture: markLayersSource,
4082
- children: [
4083
- /* @__PURE__ */ jsxs7("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: [
4084
- /* @__PURE__ */ jsx8("span", { children: labels.expandAll }),
4085
- /* @__PURE__ */ jsx8(
4086
- Switch,
4087
- {
4088
- checked: layersExpanded,
4089
- onCheckedChange: toggleLayers,
4090
- className: "data-[state=checked]:bg-brand data-[state=unchecked]:bg-panel-border"
4091
- }
4092
- )
4093
- ] }),
4094
- /* @__PURE__ */ jsx8(
4095
- "div",
4096
- {
4097
- id: "gjs-layers",
4098
- className: "min-h-0 flex-1 overflow-y-auto",
4099
- onDoubleClickCapture: (e) => {
4100
- if (e.target.closest("[data-name]")) e.stopPropagation();
4101
- }
4102
- }
4103
- )
4104
- ]
4105
- }
4106
- )
4086
+ /* @__PURE__ */ jsxs7("div", { className: cn("flex min-h-0 flex-1 flex-col", view !== "layers" && "hidden"), children: [
4087
+ /* @__PURE__ */ jsxs7("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: [
4088
+ /* @__PURE__ */ jsx8("span", { children: labels.expandAll }),
4089
+ /* @__PURE__ */ jsx8(
4090
+ Switch,
4091
+ {
4092
+ checked: layersExpanded,
4093
+ onCheckedChange: toggleLayers,
4094
+ className: "data-[state=checked]:bg-brand data-[state=unchecked]:bg-panel-border"
4095
+ }
4096
+ )
4097
+ ] }),
4098
+ /* @__PURE__ */ jsx8(
4099
+ "div",
4100
+ {
4101
+ id: "gjs-layers",
4102
+ className: "min-h-0 flex-1 overflow-y-auto",
4103
+ onDoubleClickCapture: (e) => {
4104
+ if (e.target.closest("[data-name]")) e.stopPropagation();
4105
+ }
4106
+ }
4107
+ )
4108
+ ] })
4107
4109
  ] });
4108
4110
  }
4109
4111
  function Breadcrumb({