@ohhwells/bridge 0.1.139-next.395 → 0.1.139-next.398

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
@@ -1719,7 +1719,8 @@ function labelElement2(el) {
1719
1719
  return el.querySelector('[data-ohw-editable="text"], [data-ohw-editable="plain"]') ?? el.querySelector("[data-ohw-key]");
1720
1720
  }
1721
1721
  function buttonLabel(el) {
1722
- return (labelElement2(el)?.textContent ?? el.textContent ?? "").trim();
1722
+ const label = labelElement2(el);
1723
+ return (label ? label.innerHTML : el.textContent ?? "").trim();
1723
1724
  }
1724
1725
  function buttonHref(el) {
1725
1726
  return el.getAttribute("href") ?? "";
@@ -1858,7 +1859,7 @@ function duplicateButton(source, content) {
1858
1859
  stampVariantClass(copy, copyAssignment.variant);
1859
1860
  applyButtonStyle(copy, copyAssignment, paintedTokensOf(source) ?? tokens);
1860
1861
  const copyLabelEl = labelElement2(copy);
1861
- if (copyLabelEl) copyLabelEl.textContent = label;
1862
+ if (copyLabelEl) copyLabelEl.innerHTML = label;
1862
1863
  let collection = buttonCollectionOf(source);
1863
1864
  const collections = readCollections(content);
1864
1865
  let collectionId = collection?.getAttribute(COLLECTION_ATTR) ?? "";
@@ -2184,7 +2185,7 @@ function applySnapshotContent(el, snapshot, content) {
2184
2185
  const label = labelElement2(el);
2185
2186
  if (label) {
2186
2187
  if (label.getAttribute("data-ohw-key") !== labelKey) label.setAttribute("data-ohw-key", labelKey);
2187
- if (label.textContent !== text) label.textContent = text;
2188
+ if (label.innerHTML !== text) label.innerHTML = text;
2188
2189
  }
2189
2190
  }
2190
2191
  function reconcileButtonCollections(doc, content) {
@@ -4269,7 +4270,7 @@ function buildNavLink(index, href, label, template) {
4269
4270
  const span = document.createElement("span");
4270
4271
  span.setAttribute("data-ohw-editable", "text");
4271
4272
  span.setAttribute("data-ohw-key", `nav-${index}-label`);
4272
- span.textContent = label;
4273
+ span.innerHTML = label;
4273
4274
  anchor.appendChild(span);
4274
4275
  return anchor;
4275
4276
  }
@@ -10417,7 +10418,12 @@ function AiTreeRenderer({
10417
10418
  // the full row height instead of clumping at the top.
10418
10419
  ...distributed === "space-between" ? { display: "flex", flexDirection: "column", justifyContent: "space-between" } : {}
10419
10420
  },
10420
- children: renderNode(block, ctx, `r${r2}.b${b}`)
10421
+ children: renderNode(
10422
+ block,
10423
+ ctx,
10424
+ `r${r2}.b${b}`,
10425
+ settings.alignment === "center" ? "center" : "left"
10426
+ )
10421
10427
  },
10422
10428
  b
10423
10429
  ))
@@ -30394,6 +30400,44 @@ function OhhwellsBridge() {
30394
30400
  });
30395
30401
  };
30396
30402
  window.addEventListener("message", handleAiSetStyles);
30403
+ const handleAiSetButtonStyle = (e) => {
30404
+ if (e.data?.type !== "ow:ai-set-button-style") return;
30405
+ const nodeKey = typeof e.data.hrefKey === "string" ? e.data.hrefKey : "";
30406
+ const keyed = nodeKey ? document.querySelector(
30407
+ `[data-ohw-href-key="${CSS.escape(nodeKey)}"], [data-ohw-key="${CSS.escape(nodeKey)}"]`
30408
+ ) : null;
30409
+ const hrefKey = buttonId(keyed);
30410
+ const el = hrefKey ? document.querySelector(`[data-ohw-href-key="${CSS.escape(hrefKey)}"]`) : null;
30411
+ const previous = editContentRef.current[BUTTON_ASSIGNMENTS_KEY] ?? "";
30412
+ if (!el || !hrefKey || !isCtaButton(el)) {
30413
+ postToParentRef.current({ type: "ow:ai-button-style-applied", ok: false, previous, value: previous });
30414
+ return;
30415
+ }
30416
+ const tokens = tokensFromButton(el);
30417
+ const current = assignmentFor(el, editContentRef.current, tokens);
30418
+ const patch = e.data.assignment;
30419
+ const next = {
30420
+ variant: patch?.variant ?? current.variant,
30421
+ size: patch?.size ?? current.size
30422
+ };
30423
+ const value = typeof e.data.assignments === "string" ? e.data.assignments : JSON.stringify(withAssignment(editContentRef.current, hrefKey, next));
30424
+ editContentRef.current = { ...editContentRef.current, [BUTTON_ASSIGNMENTS_KEY]: value };
30425
+ applyButtonStyle(el, next, tokens);
30426
+ postToParentRef.current({
30427
+ type: "ow:change",
30428
+ nodes: [{ key: BUTTON_ASSIGNMENTS_KEY, text: value }]
30429
+ });
30430
+ postToParentRef.current({
30431
+ type: "ow:ai-button-style-applied",
30432
+ ok: true,
30433
+ // The resolved id, which may differ from the key the editor sent — undo must target this one.
30434
+ hrefKey,
30435
+ previous,
30436
+ previousAssignment: current,
30437
+ value
30438
+ });
30439
+ };
30440
+ window.addEventListener("message", handleAiSetButtonStyle);
30397
30441
  const handleGetBrand = (e) => {
30398
30442
  if (e.data?.type !== "ow:get-brand") return;
30399
30443
  const template = deriveTemplateBrand();
@@ -31433,6 +31477,7 @@ function OhhwellsBridge() {
31433
31477
  window.removeEventListener("message", handleAiSetSections);
31434
31478
  window.removeEventListener("message", handleAiSetBrand);
31435
31479
  window.removeEventListener("message", handleAiSetStyles);
31480
+ window.removeEventListener("message", handleAiSetButtonStyle);
31436
31481
  window.removeEventListener("message", handleCollectItems);
31437
31482
  window.removeEventListener("message", handleAiApplyItems);
31438
31483
  window.removeEventListener("message", handleGetBrand);