@ohhwells/bridge 0.1.11 → 0.1.13-next.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/index.cjs CHANGED
@@ -3435,7 +3435,9 @@ function ToggleGroupItem({
3435
3435
  Toggle,
3436
3436
  {
3437
3437
  pressed: groupValue === value,
3438
- onPressedChange: () => onValueChange(value),
3438
+ onPressedChange: (pressed) => {
3439
+ if (pressed) onValueChange(value);
3440
+ },
3439
3441
  className: cn(
3440
3442
  "text-foreground cursor-pointer hover:bg-transparent hover:text-foreground",
3441
3443
  "data-[state=on]:bg-background data-[state=on]:shadow-sm",
@@ -4127,8 +4129,6 @@ function OhhwellsBridge() {
4127
4129
  [data-ohw-editable-state], [data-ohw-editable-state] * { pointer-events: none !important; }
4128
4130
  [data-ohw-editable-state][data-ohw-active-state] [data-ohw-editable] { pointer-events: auto !important; }
4129
4131
  [data-ohw-editable-state][data-ohw-active-state][data-ohw-editable] { pointer-events: auto !important; }
4130
- [data-ohw-editable-state] [data-ohw-editable="image"],
4131
- [data-ohw-editable-state][data-ohw-editable="image"] { pointer-events: auto !important; }
4132
4132
  `;
4133
4133
  const forceHover = document.createElement("style");
4134
4134
  forceHover.setAttribute("data-ohw-active-state-style", "");
@@ -4155,10 +4155,12 @@ function OhhwellsBridge() {
4155
4155
  if (editable) {
4156
4156
  if (editable.dataset.ohwEditable === "image" || editable.dataset.ohwEditable === "bg-image") {
4157
4157
  e.preventDefault();
4158
+ e.stopPropagation();
4158
4159
  postToParentRef.current({ type: "ow:image-pick", key: editable.dataset.ohwKey ?? "" });
4159
4160
  return;
4160
4161
  }
4161
4162
  e.preventDefault();
4163
+ e.stopPropagation();
4162
4164
  activateRef.current(editable);
4163
4165
  return;
4164
4166
  }
@@ -4223,7 +4225,7 @@ function OhhwellsBridge() {
4223
4225
  };
4224
4226
  const postImageHover = (imgEl, isDragOver = false, forceTextOverlap) => {
4225
4227
  const r2 = getVisibleRect(imgEl);
4226
- const hasTextOverlap = forceTextOverlap ?? (imgEl.dataset.ohwEditable === "bg-image" || imgEl.hasAttribute("data-ohw-editable-state"));
4228
+ const hasTextOverlap = forceTextOverlap ?? false;
4227
4229
  hoveredImageHasTextOverlapRef.current = hasTextOverlap;
4228
4230
  postToParentRef.current({
4229
4231
  type: "ow:image-hover",
@@ -4433,7 +4435,8 @@ function OhhwellsBridge() {
4433
4435
  e.dataTransfer.dropEffect = "copy";
4434
4436
  if (hoveredImageRef.current !== el) {
4435
4437
  hoveredImageRef.current = el;
4436
- postImageHover(el, true);
4438
+ const isStateCard = !!el.closest("[data-ohw-editable-state]");
4439
+ postImageHover(el, true, isStateCard ? true : void 0);
4437
4440
  }
4438
4441
  };
4439
4442
  const handleDragLeave = (e) => {
@@ -4621,12 +4624,11 @@ function OhhwellsBridge() {
4621
4624
  if (hoveredImageRef.current) {
4622
4625
  const el = hoveredImageRef.current;
4623
4626
  const r2 = el.getBoundingClientRect();
4624
- const hasTextOverlap = el.dataset.ohwEditable === "bg-image" || el.hasAttribute("data-ohw-editable-state");
4625
4627
  postToParentRef.current({
4626
4628
  type: "ow:image-hover",
4627
4629
  key: el.dataset.ohwKey ?? "",
4628
4630
  rect: { top: r2.top, left: r2.left, width: r2.width, height: r2.height },
4629
- hasTextOverlap
4631
+ hasTextOverlap: hoveredImageHasTextOverlapRef.current
4630
4632
  });
4631
4633
  }
4632
4634
  };
@@ -4700,12 +4702,49 @@ function OhhwellsBridge() {
4700
4702
  parentScrollRef.current = { iframeOffsetTop, headerH, canvasH };
4701
4703
  if (activeElRef.current) applyToolbarPos(activeElRef.current.getBoundingClientRect());
4702
4704
  };
4705
+ const handleClickAt = (e) => {
4706
+ if (e.data?.type !== "ow:click-at") return;
4707
+ const { clientX, clientY } = e.data;
4708
+ const allImages = Array.from(
4709
+ document.querySelectorAll('[data-ohw-editable="image"], [data-ohw-editable="bg-image"]')
4710
+ ).filter((el) => !!el.closest("[data-ohw-editable-state]"));
4711
+ const stateCardImage = allImages.find((el) => {
4712
+ const ownerCard = el.closest("[data-ohw-editable-state]");
4713
+ if (ownerCard) {
4714
+ const inHoverState = ownerCard.getAttribute("data-ohw-active-state") === "hover";
4715
+ const elState = el.dataset.ohwState;
4716
+ if (el === ownerCard && inHoverState) return false;
4717
+ if (elState === "default" && inHoverState) return false;
4718
+ if (elState === "hover" && !inHoverState) return false;
4719
+ }
4720
+ const r2 = el.getBoundingClientRect();
4721
+ return clientX >= r2.left && clientX <= r2.right && clientY >= r2.top && clientY <= r2.bottom;
4722
+ });
4723
+ if (stateCardImage) {
4724
+ postToParentRef.current({ type: "ow:image-pick", key: stateCardImage.dataset.ohwKey ?? "" });
4725
+ return;
4726
+ }
4727
+ const textEditable = Array.from(
4728
+ document.querySelectorAll(
4729
+ '[data-ohw-editable]:not([data-ohw-editable="image"]):not([data-ohw-editable="bg-image"])'
4730
+ )
4731
+ ).find((el) => {
4732
+ const r2 = el.getBoundingClientRect();
4733
+ return clientX >= r2.left && clientX <= r2.right && clientY >= r2.top && clientY <= r2.bottom;
4734
+ });
4735
+ if (textEditable) {
4736
+ activateRef.current(textEditable);
4737
+ return;
4738
+ }
4739
+ deactivateRef.current();
4740
+ };
4703
4741
  window.addEventListener("message", handleSave);
4704
4742
  window.addEventListener("message", handleImageUrl);
4705
4743
  window.addEventListener("message", handleAnimLock);
4706
4744
  window.addEventListener("message", handleCanvasHeight);
4707
4745
  window.addEventListener("message", handleParentScroll);
4708
4746
  window.addEventListener("message", handlePointerSync);
4747
+ window.addEventListener("message", handleClickAt);
4709
4748
  document.addEventListener("click", handleClick, true);
4710
4749
  document.addEventListener("paste", handlePaste, true);
4711
4750
  document.addEventListener("input", handleInput, true);
@@ -4739,6 +4778,7 @@ function OhhwellsBridge() {
4739
4778
  window.removeEventListener("message", handleCanvasHeight);
4740
4779
  window.removeEventListener("message", handleParentScroll);
4741
4780
  window.removeEventListener("message", handlePointerSync);
4781
+ window.removeEventListener("message", handleClickAt);
4742
4782
  window.removeEventListener("message", handleHydrate);
4743
4783
  window.removeEventListener("message", handleDeactivate);
4744
4784
  autoSaveTimers.current.forEach(clearTimeout);