@ohhwells/bridge 0.1.39-next.72 → 0.1.39-next.75

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.js CHANGED
@@ -8095,6 +8095,7 @@ function OhhwellsBridge() {
8095
8095
  const [mediaHover, setMediaHover] = useState7(null);
8096
8096
  const [carouselHover, setCarouselHover] = useState7(null);
8097
8097
  const [uploadingRects, setUploadingRects] = useState7({});
8098
+ const pendingUploadRectRef = useRef5(null);
8098
8099
  const hoveredGapRef = useRef5(null);
8099
8100
  const imageUnhoverTimerRef = useRef5(null);
8100
8101
  const imageShowTimerRef = useRef5(null);
@@ -9146,7 +9147,15 @@ function OhhwellsBridge() {
9146
9147
  if (isMediaEditable(editable)) {
9147
9148
  e.preventDefault();
9148
9149
  e.stopPropagation();
9149
- postToParentRef.current({ type: "ow:image-pick", key: editable.dataset.ohwKey ?? "", elementType: editable.dataset.ohwEditable ?? "image" });
9150
+ const key = editable.dataset.ohwKey ?? "";
9151
+ const r2 = editable.getBoundingClientRect();
9152
+ if (key && r2.width > 1 && r2.height > 1) {
9153
+ pendingUploadRectRef.current = {
9154
+ key,
9155
+ rect: { top: r2.top, left: r2.left, width: r2.width, height: r2.height }
9156
+ };
9157
+ }
9158
+ postToParentRef.current({ type: "ow:image-pick", key, elementType: editable.dataset.ohwEditable ?? "image" });
9150
9159
  return;
9151
9160
  }
9152
9161
  const hrefCtx = getHrefKeyFromElement(editable);
@@ -9816,6 +9825,7 @@ function OhhwellsBridge() {
9816
9825
  if (!entry || entry.fadingOut) return prev;
9817
9826
  return { ...prev, [key]: { ...entry, fadingOut: true } };
9818
9827
  });
9828
+ if (pendingUploadRectRef.current?.key === key) pendingUploadRectRef.current = null;
9819
9829
  };
9820
9830
  let found = false;
9821
9831
  document.querySelectorAll(`[data-ohw-key="${key}"]`).forEach((el) => {
@@ -10181,23 +10191,43 @@ function OhhwellsBridge() {
10181
10191
  activeStateElRef.current = null;
10182
10192
  setToggleState(null);
10183
10193
  };
10194
+ const resolveUploadRects = (key) => {
10195
+ const matches = Array.from(document.querySelectorAll(`[data-ohw-key="${key}"]`));
10196
+ const rects = matches.map((el) => {
10197
+ const r2 = el.getBoundingClientRect();
10198
+ return { top: r2.top, left: r2.left, width: r2.width, height: r2.height };
10199
+ }).filter((r2) => r2.width > 1 && r2.height > 1);
10200
+ if (rects.length > 0) return rects;
10201
+ const pending = pendingUploadRectRef.current;
10202
+ if (pending?.key === key && pending.rect.width > 1 && pending.rect.height > 1) {
10203
+ return [pending.rect];
10204
+ }
10205
+ const hovered = hoveredImageRef.current;
10206
+ if (hovered?.dataset.ohwKey === key) {
10207
+ const r2 = hovered.getBoundingClientRect();
10208
+ if (r2.width > 1 && r2.height > 1) {
10209
+ return [{ top: r2.top, left: r2.left, width: r2.width, height: r2.height }];
10210
+ }
10211
+ }
10212
+ return [];
10213
+ };
10184
10214
  const handleImageUploading = (e) => {
10185
- if (e.data?.type !== "ow:image-uploading") return;
10186
- const { key, uploading } = e.data;
10215
+ const type = e.data?.type;
10216
+ if (type !== "ow:image-uploading" && type !== "ow:anim-lock") return;
10217
+ const key = e.data.key;
10218
+ if (!key) return;
10219
+ const uploading = type === "ow:anim-lock" ? true : !!e.data.uploading;
10187
10220
  setUploadingRects((prev) => {
10188
10221
  if (!uploading) {
10222
+ if (pendingUploadRectRef.current?.key === key) pendingUploadRectRef.current = null;
10189
10223
  if (!(key in prev)) return prev;
10190
10224
  const next = { ...prev };
10191
10225
  delete next[key];
10192
10226
  return next;
10193
10227
  }
10194
- const el = document.querySelector(`[data-ohw-key="${key}"]`);
10195
- if (!el) return prev;
10196
- const r2 = getVisibleRect(el);
10197
- return {
10198
- ...prev,
10199
- [key]: { rect: { top: r2.top, left: r2.left, width: r2.width, height: r2.height } }
10200
- };
10228
+ const rects = resolveUploadRects(key);
10229
+ if (rects.length === 0) return prev;
10230
+ return { ...prev, [key]: { rects } };
10201
10231
  });
10202
10232
  document.querySelectorAll(`[data-ohw-key="${key}"]`).forEach((el) => {
10203
10233
  const track = el.closest("[data-ohw-hover-pause]");
@@ -10743,9 +10773,12 @@ function OhhwellsBridge() {
10743
10773
  );
10744
10774
  const handleMediaReplace = useCallback4(
10745
10775
  (key) => {
10776
+ if (mediaHover?.key === key) {
10777
+ pendingUploadRectRef.current = { key, rect: mediaHover.rect };
10778
+ }
10746
10779
  postToParent2({ type: "ow:image-pick", key, elementType: mediaHover?.elementType ?? "image" });
10747
10780
  },
10748
- [postToParent2, mediaHover?.elementType]
10781
+ [postToParent2, mediaHover]
10749
10782
  );
10750
10783
  const handleEditCarousel = useCallback4(
10751
10784
  (key) => {
@@ -10789,17 +10822,19 @@ function OhhwellsBridge() {
10789
10822
  return bridgeRoot ? createPortal2(
10790
10823
  /* @__PURE__ */ jsxs14(Fragment5, { children: [
10791
10824
  /* @__PURE__ */ jsx25("div", { ref: attachVisibleViewport, "data-ohw-visible-viewport": "", "aria-hidden": true }),
10792
- Object.entries(uploadingRects).map(([key, { rect, fadingOut }]) => /* @__PURE__ */ jsx25(
10793
- MediaOverlay,
10794
- {
10795
- hover: { key, rect, elementType: "image", isDragOver: false, hasTextOverlap: false },
10796
- isUploading: true,
10797
- fadingOut,
10798
- onFadeOutComplete: handleMediaFadeOutComplete,
10799
- onReplace: handleMediaReplace
10800
- },
10801
- `uploading-${key}`
10802
- )),
10825
+ Object.entries(uploadingRects).flatMap(
10826
+ ([key, { rects, fadingOut }]) => rects.map((rect, i) => /* @__PURE__ */ jsx25(
10827
+ MediaOverlay,
10828
+ {
10829
+ hover: { key, rect, elementType: "image", isDragOver: false, hasTextOverlap: false },
10830
+ isUploading: true,
10831
+ fadingOut,
10832
+ onFadeOutComplete: handleMediaFadeOutComplete,
10833
+ onReplace: handleMediaReplace
10834
+ },
10835
+ `uploading-${key}-${i}`
10836
+ ))
10837
+ ),
10803
10838
  mediaHover && !(mediaHover.key in uploadingRects) && /* @__PURE__ */ jsx25(
10804
10839
  MediaOverlay,
10805
10840
  {