@ohhwells/bridge 0.1.54-next.150 → 0.1.54-next.151

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
@@ -10661,6 +10661,7 @@ function readLogoSizeState(content, placement) {
10661
10661
  function getLogoElement(el) {
10662
10662
  const marked = el.closest('[data-ohw-role="logo"], [data-ohw-logo]');
10663
10663
  if (marked) return marked;
10664
+ if (el.closest('[data-ohw-editable="icon"]')) return null;
10664
10665
  const root = el.closest("nav, [data-ohw-nav-root], footer");
10665
10666
  if (!root) return null;
10666
10667
  const anchor = el.closest("a");
@@ -12382,6 +12383,17 @@ function applyLinkHref(el, val) {
12382
12383
  const anchor = el instanceof HTMLAnchorElement ? el : el.querySelector("a");
12383
12384
  if (anchor) anchor.setAttribute("href", val);
12384
12385
  }
12386
+ function currentIconRef(el) {
12387
+ const uploaded = el instanceof HTMLImageElement ? el : el.querySelector("img");
12388
+ if (uploaded?.getAttribute("src")) {
12389
+ return uploaded.getAttribute("src") ?? "";
12390
+ }
12391
+ const svg = el instanceof SVGElement ? el : el.querySelector("svg");
12392
+ const named = Array.from(svg?.classList ?? []).find(
12393
+ (c) => c.startsWith("lucide-") && c !== "lucide-icon"
12394
+ );
12395
+ return named ? `lucide:${named.slice("lucide-".length)}` : "";
12396
+ }
12385
12397
  function getEditMeasureEl(editable) {
12386
12398
  return editable.closest("[data-ohw-href-key]") ?? editable;
12387
12399
  }
@@ -12426,8 +12438,11 @@ function isMediaEditable(el) {
12426
12438
  const t = el.dataset.ohwEditable;
12427
12439
  return t === "image" || t === "bg-image" || t === "video";
12428
12440
  }
12441
+ function isIconEditable(el) {
12442
+ return el.dataset.ohwEditable === "icon";
12443
+ }
12429
12444
  var MEDIA_SELECTOR = '[data-ohw-editable="image"], [data-ohw-editable="bg-image"], [data-ohw-editable="video"]';
12430
- var NON_MEDIA_SELECTOR = '[data-ohw-editable]:not([data-ohw-editable="image"]):not([data-ohw-editable="bg-image"]):not([data-ohw-editable="video"])';
12445
+ var NON_MEDIA_SELECTOR = '[data-ohw-editable]:not([data-ohw-editable="image"]):not([data-ohw-editable="bg-image"]):not([data-ohw-editable="video"]):not([data-ohw-editable="icon"])';
12431
12446
  function getVideoEl2(el) {
12432
12447
  return el instanceof HTMLVideoElement ? el : el.querySelector("video");
12433
12448
  }
@@ -14618,6 +14633,8 @@ function OhhwellsBridge() {
14618
14633
  }
14619
14634
  } else if (el.dataset.ohwEditable === "link") {
14620
14635
  applyLinkHref(el, val);
14636
+ } else if (el.dataset.ohwEditable === "icon") {
14637
+ if (el.innerHTML !== val) el.innerHTML = val;
14621
14638
  } else if (el.innerHTML !== val) {
14622
14639
  el.innerHTML = val;
14623
14640
  }
@@ -15069,6 +15086,17 @@ function OhhwellsBridge() {
15069
15086
  });
15070
15087
  return;
15071
15088
  }
15089
+ if (isIconEditable(editable)) {
15090
+ e.preventDefault();
15091
+ e.stopPropagation();
15092
+ aiSectionApiRef.current?.selectFromElement(editable);
15093
+ postToParentRef.current({
15094
+ type: "ow:icon-pick",
15095
+ key: editable.dataset.ohwKey ?? "",
15096
+ current: currentIconRef(editable)
15097
+ });
15098
+ return;
15099
+ }
15072
15100
  if (isMediaEditable(editable)) {
15073
15101
  e.preventDefault();
15074
15102
  e.stopPropagation();
@@ -15292,6 +15320,11 @@ function OhhwellsBridge() {
15292
15320
  const selected = selectedElRef.current;
15293
15321
  if (selected && (selected === editable || selected.contains(editable))) return;
15294
15322
  if (!isMediaEditable(editable) && !editable.hasAttribute("contenteditable")) {
15323
+ if (isIconEditable(editable)) {
15324
+ hoveredItemElRef.current = editable;
15325
+ setHoveredItemRect(editable.getBoundingClientRect());
15326
+ return;
15327
+ }
15295
15328
  const hoverTarget = editable.closest("[data-ohw-href-key]") ?? editable;
15296
15329
  if (hoverTarget.hasAttribute("data-ohw-href-key")) {
15297
15330
  clearHrefKeyHover(hoverTarget);
@@ -15357,6 +15390,13 @@ function OhhwellsBridge() {
15357
15390
  const related = e.relatedTarget instanceof Element ? e.relatedTarget : null;
15358
15391
  if (related?.closest("[data-ohw-drag-handle-container], [data-ohw-item-interaction]")) return;
15359
15392
  if (!isMediaEditable(editable)) {
15393
+ if (isIconEditable(editable) && hoveredItemElRef.current === editable) {
15394
+ if (!related?.closest("[data-ohw-item-interaction]")) {
15395
+ hoveredItemElRef.current = null;
15396
+ setHoveredItemRect(null);
15397
+ }
15398
+ return;
15399
+ }
15360
15400
  const hoverTarget = editable.closest("[data-ohw-href-key]") ?? editable;
15361
15401
  if (hoverTarget.hasAttribute("data-ohw-href-key")) {
15362
15402
  if (!related?.closest("[data-ohw-href-key]")) {
@@ -16002,6 +16042,19 @@ function OhhwellsBridge() {
16002
16042
  resumeAnimTracks();
16003
16043
  clearImageHover();
16004
16044
  };
16045
+ const handleIconMarkup = (e) => {
16046
+ if (e.data?.type !== "ow:icon-markup") return;
16047
+ const { key, markup } = e.data;
16048
+ if (!key || typeof markup !== "string") return;
16049
+ const targets = document.querySelectorAll(
16050
+ `[data-ohw-key="${key}"][data-ohw-editable="icon"]`
16051
+ );
16052
+ if (!targets.length) return;
16053
+ targets.forEach((el) => {
16054
+ el.innerHTML = markup;
16055
+ });
16056
+ postToParentRef.current({ type: "ow:change", nodes: [{ key, text: markup }] });
16057
+ };
16005
16058
  const handleImageUrl = (e) => {
16006
16059
  if (e.data?.type !== "ow:image-url") return;
16007
16060
  const { key, url } = e.data;
@@ -16857,6 +16910,7 @@ function OhhwellsBridge() {
16857
16910
  window.addEventListener("message", handleClearSchedulingWidget);
16858
16911
  window.addEventListener("message", handleRemoveSchedulingSection);
16859
16912
  window.addEventListener("message", handleCollectSection);
16913
+ window.addEventListener("message", handleIconMarkup);
16860
16914
  window.addEventListener("message", handleImageUrl);
16861
16915
  window.addEventListener("message", handleImageUploading);
16862
16916
  window.addEventListener("message", handleCarouselChange);
@@ -16916,6 +16970,7 @@ function OhhwellsBridge() {
16916
16970
  window.removeEventListener("message", handleClearSchedulingWidget);
16917
16971
  window.removeEventListener("message", handleRemoveSchedulingSection);
16918
16972
  window.removeEventListener("message", handleCollectSection);
16973
+ window.removeEventListener("message", handleIconMarkup);
16919
16974
  window.removeEventListener("message", handleImageUrl);
16920
16975
  window.removeEventListener("message", handleImageUploading);
16921
16976
  window.removeEventListener("message", handleCarouselChange);