@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.cjs +51 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +51 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1726,7 +1726,8 @@ function labelElement2(el) {
|
|
|
1726
1726
|
return el.querySelector('[data-ohw-editable="text"], [data-ohw-editable="plain"]') ?? el.querySelector("[data-ohw-key]");
|
|
1727
1727
|
}
|
|
1728
1728
|
function buttonLabel(el) {
|
|
1729
|
-
|
|
1729
|
+
const label = labelElement2(el);
|
|
1730
|
+
return (label ? label.innerHTML : el.textContent ?? "").trim();
|
|
1730
1731
|
}
|
|
1731
1732
|
function buttonHref(el) {
|
|
1732
1733
|
return el.getAttribute("href") ?? "";
|
|
@@ -1865,7 +1866,7 @@ function duplicateButton(source, content) {
|
|
|
1865
1866
|
stampVariantClass(copy, copyAssignment.variant);
|
|
1866
1867
|
applyButtonStyle(copy, copyAssignment, paintedTokensOf(source) ?? tokens);
|
|
1867
1868
|
const copyLabelEl = labelElement2(copy);
|
|
1868
|
-
if (copyLabelEl) copyLabelEl.
|
|
1869
|
+
if (copyLabelEl) copyLabelEl.innerHTML = label;
|
|
1869
1870
|
let collection = buttonCollectionOf(source);
|
|
1870
1871
|
const collections = readCollections(content);
|
|
1871
1872
|
let collectionId = collection?.getAttribute(COLLECTION_ATTR) ?? "";
|
|
@@ -2191,7 +2192,7 @@ function applySnapshotContent(el, snapshot, content) {
|
|
|
2191
2192
|
const label = labelElement2(el);
|
|
2192
2193
|
if (label) {
|
|
2193
2194
|
if (label.getAttribute("data-ohw-key") !== labelKey) label.setAttribute("data-ohw-key", labelKey);
|
|
2194
|
-
if (label.
|
|
2195
|
+
if (label.innerHTML !== text) label.innerHTML = text;
|
|
2195
2196
|
}
|
|
2196
2197
|
}
|
|
2197
2198
|
function reconcileButtonCollections(doc, content) {
|
|
@@ -4276,7 +4277,7 @@ function buildNavLink(index, href, label, template) {
|
|
|
4276
4277
|
const span = document.createElement("span");
|
|
4277
4278
|
span.setAttribute("data-ohw-editable", "text");
|
|
4278
4279
|
span.setAttribute("data-ohw-key", `nav-${index}-label`);
|
|
4279
|
-
span.
|
|
4280
|
+
span.innerHTML = label;
|
|
4280
4281
|
anchor.appendChild(span);
|
|
4281
4282
|
return anchor;
|
|
4282
4283
|
}
|
|
@@ -10380,7 +10381,12 @@ function AiTreeRenderer({
|
|
|
10380
10381
|
// the full row height instead of clumping at the top.
|
|
10381
10382
|
...distributed === "space-between" ? { display: "flex", flexDirection: "column", justifyContent: "space-between" } : {}
|
|
10382
10383
|
},
|
|
10383
|
-
children: renderNode(
|
|
10384
|
+
children: renderNode(
|
|
10385
|
+
block,
|
|
10386
|
+
ctx,
|
|
10387
|
+
`r${r2}.b${b}`,
|
|
10388
|
+
settings.alignment === "center" ? "center" : "left"
|
|
10389
|
+
)
|
|
10384
10390
|
},
|
|
10385
10391
|
b
|
|
10386
10392
|
))
|
|
@@ -30316,6 +30322,44 @@ function OhhwellsBridge() {
|
|
|
30316
30322
|
});
|
|
30317
30323
|
};
|
|
30318
30324
|
window.addEventListener("message", handleAiSetStyles);
|
|
30325
|
+
const handleAiSetButtonStyle = (e) => {
|
|
30326
|
+
if (e.data?.type !== "ow:ai-set-button-style") return;
|
|
30327
|
+
const nodeKey = typeof e.data.hrefKey === "string" ? e.data.hrefKey : "";
|
|
30328
|
+
const keyed = nodeKey ? document.querySelector(
|
|
30329
|
+
`[data-ohw-href-key="${CSS.escape(nodeKey)}"], [data-ohw-key="${CSS.escape(nodeKey)}"]`
|
|
30330
|
+
) : null;
|
|
30331
|
+
const hrefKey = buttonId(keyed);
|
|
30332
|
+
const el = hrefKey ? document.querySelector(`[data-ohw-href-key="${CSS.escape(hrefKey)}"]`) : null;
|
|
30333
|
+
const previous = editContentRef.current[BUTTON_ASSIGNMENTS_KEY] ?? "";
|
|
30334
|
+
if (!el || !hrefKey || !isCtaButton(el)) {
|
|
30335
|
+
postToParentRef.current({ type: "ow:ai-button-style-applied", ok: false, previous, value: previous });
|
|
30336
|
+
return;
|
|
30337
|
+
}
|
|
30338
|
+
const tokens = tokensFromButton(el);
|
|
30339
|
+
const current = assignmentFor(el, editContentRef.current, tokens);
|
|
30340
|
+
const patch = e.data.assignment;
|
|
30341
|
+
const next = {
|
|
30342
|
+
variant: patch?.variant ?? current.variant,
|
|
30343
|
+
size: patch?.size ?? current.size
|
|
30344
|
+
};
|
|
30345
|
+
const value = typeof e.data.assignments === "string" ? e.data.assignments : JSON.stringify(withAssignment(editContentRef.current, hrefKey, next));
|
|
30346
|
+
editContentRef.current = { ...editContentRef.current, [BUTTON_ASSIGNMENTS_KEY]: value };
|
|
30347
|
+
applyButtonStyle(el, next, tokens);
|
|
30348
|
+
postToParentRef.current({
|
|
30349
|
+
type: "ow:change",
|
|
30350
|
+
nodes: [{ key: BUTTON_ASSIGNMENTS_KEY, text: value }]
|
|
30351
|
+
});
|
|
30352
|
+
postToParentRef.current({
|
|
30353
|
+
type: "ow:ai-button-style-applied",
|
|
30354
|
+
ok: true,
|
|
30355
|
+
// The resolved id, which may differ from the key the editor sent — undo must target this one.
|
|
30356
|
+
hrefKey,
|
|
30357
|
+
previous,
|
|
30358
|
+
previousAssignment: current,
|
|
30359
|
+
value
|
|
30360
|
+
});
|
|
30361
|
+
};
|
|
30362
|
+
window.addEventListener("message", handleAiSetButtonStyle);
|
|
30319
30363
|
const handleGetBrand = (e) => {
|
|
30320
30364
|
if (e.data?.type !== "ow:get-brand") return;
|
|
30321
30365
|
const template = deriveTemplateBrand();
|
|
@@ -31349,6 +31393,7 @@ function OhhwellsBridge() {
|
|
|
31349
31393
|
window.removeEventListener("message", handleAiSetSections);
|
|
31350
31394
|
window.removeEventListener("message", handleAiSetBrand);
|
|
31351
31395
|
window.removeEventListener("message", handleAiSetStyles);
|
|
31396
|
+
window.removeEventListener("message", handleAiSetButtonStyle);
|
|
31352
31397
|
window.removeEventListener("message", handleCollectItems);
|
|
31353
31398
|
window.removeEventListener("message", handleAiApplyItems);
|
|
31354
31399
|
window.removeEventListener("message", handleGetBrand);
|
|
@@ -31657,7 +31702,7 @@ function OhhwellsBridge() {
|
|
|
31657
31702
|
postToParent2({
|
|
31658
31703
|
type: "ow:ready",
|
|
31659
31704
|
version: "1",
|
|
31660
|
-
bridgeVersion: "0.1.
|
|
31705
|
+
bridgeVersion: "0.1.148",
|
|
31661
31706
|
path: pathname,
|
|
31662
31707
|
nodes: collectEditableNodes(editContentRef.current),
|
|
31663
31708
|
sections
|