@trafica/editor 1.0.48 → 1.0.49

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/index.mjs CHANGED
@@ -8646,11 +8646,15 @@ function EditorCore({
8646
8646
  const container = containerRef.current;
8647
8647
  if (!container) return;
8648
8648
  const cr = container.getBoundingClientRect();
8649
- const x = Math.max(0, e.clientX - cr.left - drag.offsetX + container.scrollLeft);
8650
- const y = Math.max(0, e.clientY - cr.top - drag.offsetY + container.scrollTop);
8651
8649
  const fig = container.querySelector(
8652
8650
  `[data-image-path="${JSON.stringify(drag.imagePath)}"]`
8653
8651
  );
8652
+ const figW = (fig == null ? void 0 : fig.offsetWidth) || drag.ghostW;
8653
+ const figH = (fig == null ? void 0 : fig.offsetHeight) || drag.ghostH;
8654
+ const rawX = e.clientX - cr.left - drag.offsetX + container.scrollLeft;
8655
+ const rawY = e.clientY - cr.top - drag.offsetY + container.scrollTop;
8656
+ const x = Math.max(0, Math.min(rawX, container.clientWidth - figW));
8657
+ const y = Math.max(0, Math.min(rawY, container.scrollHeight - figH));
8654
8658
  if (fig) {
8655
8659
  fig.style.position = "absolute";
8656
8660
  fig.style.left = `${x}px`;
@@ -8669,8 +8673,15 @@ function EditorCore({
8669
8673
  const container = containerRef.current;
8670
8674
  if (!container) return;
8671
8675
  const cr = container.getBoundingClientRect();
8672
- const x = Math.max(0, e.clientX - cr.left - drag.offsetX + container.scrollLeft);
8673
- const y = Math.max(0, e.clientY - cr.top - drag.offsetY + container.scrollTop);
8676
+ const fig = container.querySelector(
8677
+ `[data-image-path="${JSON.stringify(drag.imagePath)}"]`
8678
+ );
8679
+ const figW = (fig == null ? void 0 : fig.offsetWidth) || drag.ghostW;
8680
+ const figH = (fig == null ? void 0 : fig.offsetHeight) || drag.ghostH;
8681
+ const rawX = e.clientX - cr.left - drag.offsetX + container.scrollLeft;
8682
+ const rawY = e.clientY - cr.top - drag.offsetY + container.scrollTop;
8683
+ const x = Math.max(0, Math.min(rawX, container.clientWidth - figW));
8684
+ const y = Math.max(0, Math.min(rawY, container.scrollHeight - figH));
8674
8685
  setImageAttr(drag.imagePath, { x: Math.round(x), y: Math.round(y) })(engine);
8675
8686
  };
8676
8687
  document.addEventListener("mousemove", onMouseMove);