@ohhwells/bridge 0.1.8 → 0.1.10

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
@@ -3946,6 +3946,10 @@ function OhhwellsBridge() {
3946
3946
  const activate = (0, import_react.useCallback)((el) => {
3947
3947
  if (activeElRef.current === el) return;
3948
3948
  deactivate();
3949
+ if (hoveredImageRef.current) {
3950
+ hoveredImageRef.current = null;
3951
+ postToParentRef.current({ type: "ow:image-unhover" });
3952
+ }
3949
3953
  el.setAttribute("contenteditable", "true");
3950
3954
  el.removeAttribute("data-ohw-hovered");
3951
3955
  activeElRef.current = el;
@@ -4120,6 +4124,7 @@ function OhhwellsBridge() {
4120
4124
  [data-ohw-editable][contenteditable] *::selection { background: ${PRIMARY}59 !important; }
4121
4125
  [data-ohw-editable-state], [data-ohw-editable-state] * { pointer-events: none !important; }
4122
4126
  [data-ohw-editable-state][data-ohw-active-state] [data-ohw-editable] { pointer-events: auto !important; }
4127
+ [data-ohw-editable]:not([data-ohw-editable="image"]):not([data-ohw-editable="bg-image"]) { pointer-events: auto !important; }
4123
4128
  `;
4124
4129
  const forceHover = document.createElement("style");
4125
4130
  forceHover.setAttribute("data-ohw-active-state-style", "");
@@ -4214,10 +4219,13 @@ function OhhwellsBridge() {
4214
4219
  };
4215
4220
  const postImageHover = (imgEl, isDragOver = false) => {
4216
4221
  const r2 = getVisibleRect(imgEl);
4222
+ const hasTextOverlap = imgEl.dataset.ohwEditable === "bg-image" || imgEl.hasAttribute("data-ohw-editable-state");
4223
+ console.log("[OHW] postImageHover", { key: imgEl.dataset.ohwKey, editable: imgEl.dataset.ohwEditable, hasState: imgEl.hasAttribute("data-ohw-editable-state"), hasTextOverlap });
4217
4224
  postToParentRef.current({
4218
4225
  type: "ow:image-hover",
4219
4226
  key: imgEl.dataset.ohwKey ?? "",
4220
4227
  rect: { top: r2.top, left: r2.left, width: r2.width, height: r2.height },
4228
+ hasTextOverlap,
4221
4229
  ...isDragOver ? { isDragOver: true } : {}
4222
4230
  });
4223
4231
  const track = imgEl.closest("[data-ohw-hover-pause]");
@@ -4264,7 +4272,16 @@ function OhhwellsBridge() {
4264
4272
  }
4265
4273
  return smallest;
4266
4274
  };
4267
- const probeImageAt = (clientX, clientY, isDragOver = false, fromParentViewport = false, fromOverlay = false) => {
4275
+ const probeImageAt = (clientX, clientY, isDragOver = false, fromParentViewport = false) => {
4276
+ if (activeElRef.current) {
4277
+ console.log("[OHW] probeImageAt: text active, suppressing image hover");
4278
+ if (hoveredImageRef.current) {
4279
+ hoveredImageRef.current = null;
4280
+ resumeAnimTracks();
4281
+ postToParentRef.current({ type: "ow:image-unhover" });
4282
+ }
4283
+ return;
4284
+ }
4268
4285
  const toggleEl = document.querySelector("[data-ohw-state-toggle]");
4269
4286
  if (toggleEl) {
4270
4287
  const { x, y } = toProbeCoords(clientX, clientY, fromParentViewport);
@@ -4290,16 +4307,20 @@ function OhhwellsBridge() {
4290
4307
  }
4291
4308
  return;
4292
4309
  }
4293
- const topEditable = topEl?.closest("[data-ohw-editable]");
4294
- if (topEditable && topEditable.dataset.ohwEditable !== "image" && topEditable.dataset.ohwEditable !== "bg-image") {
4295
- if (topEditable.hasAttribute("contenteditable") && fromOverlay) return;
4310
+ const textEditable = Array.from(
4311
+ document.querySelectorAll('[data-ohw-editable]:not([data-ohw-editable="image"]):not([data-ohw-editable="bg-image"])')
4312
+ ).find((el) => {
4313
+ const er = el.getBoundingClientRect();
4314
+ return x >= er.left && x <= er.right && y >= er.top && y <= er.bottom;
4315
+ });
4316
+ if (textEditable) {
4296
4317
  if (hoveredImageRef.current) {
4297
4318
  hoveredImageRef.current = null;
4298
4319
  resumeAnimTracks();
4299
4320
  postToParentRef.current({ type: "ow:image-unhover" });
4300
4321
  }
4301
4322
  document.querySelectorAll("[data-ohw-hovered]").forEach((el) => el.removeAttribute("data-ohw-hovered"));
4302
- topEditable.setAttribute("data-ohw-hovered", "");
4323
+ if (!textEditable.hasAttribute("contenteditable")) textEditable.setAttribute("data-ohw-hovered", "");
4303
4324
  return;
4304
4325
  }
4305
4326
  const activeHovered = document.querySelector("[data-ohw-hovered]");
@@ -4325,9 +4346,20 @@ function OhhwellsBridge() {
4325
4346
  } else {
4326
4347
  const inIframeView = clientX >= 0 && clientY >= 0 && clientX <= window.innerWidth && clientY <= window.innerHeight;
4327
4348
  if (!inIframeView) return;
4328
- hoveredImageRef.current = null;
4329
- resumeAnimTracks();
4330
- postToParentRef.current({ type: "ow:image-unhover" });
4349
+ if (hoveredImageRef.current) {
4350
+ hoveredImageRef.current = null;
4351
+ resumeAnimTracks();
4352
+ postToParentRef.current({ type: "ow:image-unhover" });
4353
+ }
4354
+ const { x, y } = toProbeCoords(clientX, clientY, fromParentViewport);
4355
+ const textEl = Array.from(
4356
+ document.querySelectorAll('[data-ohw-editable]:not([data-ohw-editable="image"]):not([data-ohw-editable="bg-image"])')
4357
+ ).find((el) => {
4358
+ const er = el.getBoundingClientRect();
4359
+ return x >= er.left && x <= er.right && y >= er.top && y <= er.bottom;
4360
+ });
4361
+ document.querySelectorAll("[data-ohw-hovered]").forEach((el) => el.removeAttribute("data-ohw-hovered"));
4362
+ if (textEl && !textEl.hasAttribute("contenteditable")) textEl.setAttribute("data-ohw-hovered", "");
4331
4363
  }
4332
4364
  };
4333
4365
  const probeHoverCardsAt = (clientX, clientY, fromParentViewport = false) => {
@@ -4364,9 +4396,9 @@ function OhhwellsBridge() {
4364
4396
  };
4365
4397
  const handlePointerSync = (e) => {
4366
4398
  if (e.data?.type !== "ow:pointer-sync") return;
4367
- const { clientX, clientY, fromOverlay } = e.data;
4399
+ const { clientX, clientY } = e.data;
4368
4400
  if (typeof clientX !== "number" || typeof clientY !== "number") return;
4369
- probeImageAt(clientX, clientY, false, false, fromOverlay ?? false);
4401
+ probeImageAt(clientX, clientY);
4370
4402
  probeHoverCardsAt(clientX, clientY);
4371
4403
  };
4372
4404
  const handleDragOver = (e) => {
@@ -4565,11 +4597,14 @@ function OhhwellsBridge() {
4565
4597
  setToggleState((prev) => prev ? { ...prev, rect } : null);
4566
4598
  }
4567
4599
  if (hoveredImageRef.current) {
4568
- const r2 = hoveredImageRef.current.getBoundingClientRect();
4600
+ const el = hoveredImageRef.current;
4601
+ const r2 = el.getBoundingClientRect();
4602
+ const hasTextOverlap = el.dataset.ohwEditable === "bg-image" || el.hasAttribute("data-ohw-editable-state");
4569
4603
  postToParentRef.current({
4570
4604
  type: "ow:image-hover",
4571
- key: hoveredImageRef.current.dataset.ohwKey ?? "",
4572
- rect: { top: r2.top, left: r2.left, width: r2.width, height: r2.height }
4605
+ key: el.dataset.ohwKey ?? "",
4606
+ rect: { top: r2.top, left: r2.left, width: r2.width, height: r2.height },
4607
+ hasTextOverlap
4573
4608
  });
4574
4609
  }
4575
4610
  };