@ohhwells/bridge 0.1.148 → 0.1.149

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
@@ -1631,7 +1631,8 @@ function labelElement2(el) {
1631
1631
  return el.querySelector('[data-ohw-editable="text"], [data-ohw-editable="plain"]') ?? el.querySelector("[data-ohw-key]");
1632
1632
  }
1633
1633
  function buttonLabel(el) {
1634
- return (labelElement2(el)?.textContent ?? el.textContent ?? "").trim();
1634
+ const label = labelElement2(el);
1635
+ return (label ? label.innerHTML : el.textContent ?? "").trim();
1635
1636
  }
1636
1637
  function buttonHref(el) {
1637
1638
  return el.getAttribute("href") ?? "";
@@ -1770,7 +1771,7 @@ function duplicateButton(source, content) {
1770
1771
  stampVariantClass(copy, copyAssignment.variant);
1771
1772
  applyButtonStyle(copy, copyAssignment, paintedTokensOf(source) ?? tokens);
1772
1773
  const copyLabelEl = labelElement2(copy);
1773
- if (copyLabelEl) copyLabelEl.textContent = label;
1774
+ if (copyLabelEl) copyLabelEl.innerHTML = label;
1774
1775
  let collection = buttonCollectionOf(source);
1775
1776
  const collections = readCollections(content);
1776
1777
  let collectionId = collection?.getAttribute(COLLECTION_ATTR) ?? "";
@@ -2096,7 +2097,7 @@ function applySnapshotContent(el, snapshot, content) {
2096
2097
  const label = labelElement2(el);
2097
2098
  if (label) {
2098
2099
  if (label.getAttribute("data-ohw-key") !== labelKey) label.setAttribute("data-ohw-key", labelKey);
2099
- if (label.textContent !== text) label.textContent = text;
2100
+ if (label.innerHTML !== text) label.innerHTML = text;
2100
2101
  }
2101
2102
  }
2102
2103
  function reconcileButtonCollections(doc, content) {
@@ -4181,7 +4182,7 @@ function buildNavLink(index, href, label, template) {
4181
4182
  const span = document.createElement("span");
4182
4183
  span.setAttribute("data-ohw-editable", "text");
4183
4184
  span.setAttribute("data-ohw-key", `nav-${index}-label`);
4184
- span.textContent = label;
4185
+ span.innerHTML = label;
4185
4186
  anchor.appendChild(span);
4186
4187
  return anchor;
4187
4188
  }
@@ -10285,7 +10286,12 @@ function AiTreeRenderer({
10285
10286
  // the full row height instead of clumping at the top.
10286
10287
  ...distributed === "space-between" ? { display: "flex", flexDirection: "column", justifyContent: "space-between" } : {}
10287
10288
  },
10288
- children: renderNode(block, ctx, `r${r2}.b${b}`)
10289
+ children: renderNode(
10290
+ block,
10291
+ ctx,
10292
+ `r${r2}.b${b}`,
10293
+ settings.alignment === "center" ? "center" : "left"
10294
+ )
10289
10295
  },
10290
10296
  b
10291
10297
  ))
@@ -30227,6 +30233,44 @@ function OhhwellsBridge() {
30227
30233
  });
30228
30234
  };
30229
30235
  window.addEventListener("message", handleAiSetStyles);
30236
+ const handleAiSetButtonStyle = (e) => {
30237
+ if (e.data?.type !== "ow:ai-set-button-style") return;
30238
+ const nodeKey = typeof e.data.hrefKey === "string" ? e.data.hrefKey : "";
30239
+ const keyed = nodeKey ? document.querySelector(
30240
+ `[data-ohw-href-key="${CSS.escape(nodeKey)}"], [data-ohw-key="${CSS.escape(nodeKey)}"]`
30241
+ ) : null;
30242
+ const hrefKey = buttonId(keyed);
30243
+ const el = hrefKey ? document.querySelector(`[data-ohw-href-key="${CSS.escape(hrefKey)}"]`) : null;
30244
+ const previous = editContentRef.current[BUTTON_ASSIGNMENTS_KEY] ?? "";
30245
+ if (!el || !hrefKey || !isCtaButton(el)) {
30246
+ postToParentRef.current({ type: "ow:ai-button-style-applied", ok: false, previous, value: previous });
30247
+ return;
30248
+ }
30249
+ const tokens = tokensFromButton(el);
30250
+ const current = assignmentFor(el, editContentRef.current, tokens);
30251
+ const patch = e.data.assignment;
30252
+ const next = {
30253
+ variant: patch?.variant ?? current.variant,
30254
+ size: patch?.size ?? current.size
30255
+ };
30256
+ const value = typeof e.data.assignments === "string" ? e.data.assignments : JSON.stringify(withAssignment(editContentRef.current, hrefKey, next));
30257
+ editContentRef.current = { ...editContentRef.current, [BUTTON_ASSIGNMENTS_KEY]: value };
30258
+ applyButtonStyle(el, next, tokens);
30259
+ postToParentRef.current({
30260
+ type: "ow:change",
30261
+ nodes: [{ key: BUTTON_ASSIGNMENTS_KEY, text: value }]
30262
+ });
30263
+ postToParentRef.current({
30264
+ type: "ow:ai-button-style-applied",
30265
+ ok: true,
30266
+ // The resolved id, which may differ from the key the editor sent — undo must target this one.
30267
+ hrefKey,
30268
+ previous,
30269
+ previousAssignment: current,
30270
+ value
30271
+ });
30272
+ };
30273
+ window.addEventListener("message", handleAiSetButtonStyle);
30230
30274
  const handleGetBrand = (e) => {
30231
30275
  if (e.data?.type !== "ow:get-brand") return;
30232
30276
  const template = deriveTemplateBrand();
@@ -31260,6 +31304,7 @@ function OhhwellsBridge() {
31260
31304
  window.removeEventListener("message", handleAiSetSections);
31261
31305
  window.removeEventListener("message", handleAiSetBrand);
31262
31306
  window.removeEventListener("message", handleAiSetStyles);
31307
+ window.removeEventListener("message", handleAiSetButtonStyle);
31263
31308
  window.removeEventListener("message", handleCollectItems);
31264
31309
  window.removeEventListener("message", handleAiApplyItems);
31265
31310
  window.removeEventListener("message", handleGetBrand);
@@ -31568,7 +31613,7 @@ function OhhwellsBridge() {
31568
31613
  postToParent2({
31569
31614
  type: "ow:ready",
31570
31615
  version: "1",
31571
- bridgeVersion: "0.1.147",
31616
+ bridgeVersion: "0.1.148",
31572
31617
  path: pathname,
31573
31618
  nodes: collectEditableNodes(editContentRef.current),
31574
31619
  sections