@ohhwells/bridge 0.1.164 → 0.1.166

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
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  // src/OhhwellsBridge.tsx
4
- import React12, { useCallback as useCallback12, useEffect as useEffect19, useLayoutEffect as useLayoutEffect6, useRef as useRef14, useState as useState18 } from "react";
4
+ import React12, { useCallback as useCallback12, useEffect as useEffect20, useLayoutEffect as useLayoutEffect6, useRef as useRef14, useState as useState18 } from "react";
5
5
  import { createRoot as createRoot3 } from "react-dom/client";
6
6
  import { flushSync as flushSync3 } from "react-dom";
7
7
 
@@ -840,6 +840,10 @@ function useOhwCarousel(key, initial) {
840
840
  if (Array.isArray(detail?.images)) setImages(detail.images);
841
841
  };
842
842
  el.addEventListener(CAROUSEL_EVENT, onChange);
843
+ const pending = parseSlides(el.getAttribute(CAROUSEL_VALUE_ATTR));
844
+ if (pending.length > 0) {
845
+ setImages((prev) => JSON.stringify(prev) === JSON.stringify(pending) ? prev : pending);
846
+ }
843
847
  return () => el.removeEventListener(CAROUSEL_EVENT, onChange);
844
848
  }, [key]);
845
849
  const bind = {
@@ -2524,6 +2528,14 @@ function socialHrefKey(item) {
2524
2528
  function socialIconKey(item) {
2525
2529
  return item.querySelector(ICON_SELECTOR)?.dataset.ohwKey ?? null;
2526
2530
  }
2531
+ function pendingIconKey(item) {
2532
+ const existing = socialIconKey(item);
2533
+ if (existing) return existing;
2534
+ const base = socialHrefKey(item)?.replace(/-href$/, "");
2535
+ if (!base) return null;
2536
+ const taken = item.ownerDocument.querySelector(`[data-ohw-key="${base}"]`);
2537
+ return taken && taken !== item ? `${base}-icon` : base;
2538
+ }
2527
2539
  var SOCIAL_PLATFORM_LABELS = {
2528
2540
  instagram: "Instagram",
2529
2541
  facebook: "Facebook",
@@ -2721,9 +2733,9 @@ function reconcileSocialsFromContent(content, root = document) {
2721
2733
  listSocialsRows(root).forEach((row) => {
2722
2734
  const rowDisplay = socialsDisplayFor(row, content);
2723
2735
  listSocialItems(row).forEach((item) => {
2724
- const key = socialIconKey(item) ?? socialHrefKey(item)?.replace(/-href$/, "");
2736
+ const key = pendingIconKey(item);
2725
2737
  const stored2 = key ? content[key] : void 0;
2726
- if (!stored2?.trim()) return;
2738
+ if (!stored2?.trim().startsWith("<")) return;
2727
2739
  const existing = item.querySelector(ICON_SELECTOR);
2728
2740
  if (existing && existing.innerHTML.trim() && !existing.hasAttribute(SOCIALS_ICON_PLACEHOLDER_ATTR)) return;
2729
2741
  ensureIconSlot(item);
@@ -2983,8 +2995,7 @@ function ensureIconSlot(item) {
2983
2995
  const adopted = adoptAsIconSlot(drawn, base);
2984
2996
  if (adopted) return adopted;
2985
2997
  }
2986
- const taken = document.querySelector(`[data-ohw-key="${base}"]`);
2987
- const iconKey = taken && taken !== item ? `${base}-icon` : base;
2998
+ const iconKey = pendingIconKey(item) ?? base;
2988
2999
  const slot = document.createElement("span");
2989
3000
  slot.setAttribute("data-ohw-key", iconKey);
2990
3001
  slot.setAttribute("data-ohw-editable", "icon");
@@ -3496,11 +3507,11 @@ function insertFooterColumnDom(colIndex, heading, items) {
3496
3507
  container.appendChild(column);
3497
3508
  return { column, firstLink };
3498
3509
  }
3499
- function insertFooterColumn(heading = DEFAULT_FOOTER_COLUMN_HEADING, linkLabel = DEFAULT_FOOTER_COLUMN_LINK_LABEL, linkHref = DEFAULT_FOOTER_COLUMN_LINK_HREF) {
3510
+ function insertFooterColumn(heading = DEFAULT_FOOTER_COLUMN_HEADING, linkLabel = DEFAULT_FOOTER_COLUMN_LINK_LABEL, linkHref2 = DEFAULT_FOOTER_COLUMN_LINK_HREF) {
3500
3511
  if (!canAddFooterColumn()) {
3501
3512
  throw new Error(`Footer column limit reached (${MAX_FOOTER_COLUMNS})`);
3502
3513
  }
3503
- const resolvedHref = linkHref || (document.querySelector("[data-ai-footer], [data-ohw-ai-footer]") ? "/" : DEFAULT_FOOTER_COLUMN_LINK_HREF);
3514
+ const resolvedHref = linkHref2 || (document.querySelector("[data-ai-footer], [data-ohw-ai-footer]") ? "/" : DEFAULT_FOOTER_COLUMN_LINK_HREF);
3504
3515
  const colIndex = getNextFooterColumnIndex();
3505
3516
  const inserted = insertFooterColumnDom(colIndex, heading, [{ href: resolvedHref, label: linkLabel }]);
3506
3517
  if (!inserted?.firstLink) throw new Error("Failed to insert footer column");
@@ -3879,8 +3890,8 @@ function duplicateFooterItem(sourceAnchor) {
3879
3890
  const column = findFooterColumnForLink(sourceAnchor);
3880
3891
  if (!column) return null;
3881
3892
  const href = getLinkHref(sourceAnchor);
3882
- const labelEl = sourceAnchor.querySelector('[data-ohw-editable="text"]');
3883
- const label = (labelEl?.textContent ?? "").trim() || "Untitled";
3893
+ const labelEl2 = sourceAnchor.querySelector('[data-ohw-editable="text"]');
3894
+ const label = (labelEl2?.textContent ?? "").trim() || "Untitled";
3884
3895
  return insertFooterItem(column, href || "/", label, sourceAnchor);
3885
3896
  }
3886
3897
  function footerLabelKeyFromHrefKey(hrefKey) {
@@ -3890,8 +3901,8 @@ function deleteFooterItem(sourceAnchor) {
3890
3901
  if (!isFooterLinkAnchor(sourceAnchor)) return null;
3891
3902
  const hrefKey = sourceAnchor.getAttribute("data-ohw-href-key");
3892
3903
  if (!hrefKey || !isFooterHrefKey(hrefKey)) return null;
3893
- const labelEl = sourceAnchor.querySelector('[data-ohw-editable="text"]');
3894
- const label = (labelEl?.textContent ?? "").trim() || "Untitled";
3904
+ const labelEl2 = sourceAnchor.querySelector('[data-ohw-editable="text"]');
3905
+ const label = (labelEl2?.textContent ?? "").trim() || "Untitled";
3895
3906
  const labelKey = footerLabelKeyFromHrefKey(hrefKey);
3896
3907
  const previousOrder = getFooterOrderFromDom();
3897
3908
  const previousOrderJson = JSON.stringify(previousOrder);
@@ -4859,8 +4870,8 @@ function remapNavKeysInSubtree(root, keyMap) {
4859
4870
  const mapped = keyMap.get(oldHrefKey);
4860
4871
  if (!mapped) return;
4861
4872
  el.setAttribute("data-ohw-href-key", mapped.hrefKey);
4862
- const labelEl = el.querySelector(':scope > [data-ohw-editable="text"][data-ohw-key]') ?? el.querySelector('[data-ohw-editable="text"][data-ohw-key]');
4863
- if (labelEl) labelEl.setAttribute("data-ohw-key", mapped.labelKey);
4873
+ const labelEl2 = el.querySelector(':scope > [data-ohw-editable="text"][data-ohw-key]') ?? el.querySelector('[data-ohw-editable="text"][data-ohw-key]');
4874
+ if (labelEl2) labelEl2.setAttribute("data-ohw-key", mapped.labelKey);
4864
4875
  };
4865
4876
  if (root.matches("[data-ohw-href-key]")) remapAnchor(root);
4866
4877
  root.querySelectorAll("[data-ohw-href-key]").forEach(remapAnchor);
@@ -4868,10 +4879,10 @@ function remapNavKeysInSubtree(root, keyMap) {
4868
4879
  function readNavLinkSnapshot(hrefKey) {
4869
4880
  const el = findCounterpartByHrefKey(hrefKey, document) ?? document.querySelector(`[data-ohw-href-key="${CSS.escape(hrefKey)}"]`);
4870
4881
  if (!el) return { href: "/", label: "Untitled" };
4871
- const labelEl = el.querySelector('[data-ohw-editable="text"]');
4882
+ const labelEl2 = el.querySelector('[data-ohw-editable="text"]');
4872
4883
  return {
4873
4884
  href: getLinkHref2(el),
4874
- label: (labelEl?.textContent ?? "").trim() || "Untitled"
4885
+ label: (labelEl2?.textContent ?? "").trim() || "Untitled"
4875
4886
  };
4876
4887
  }
4877
4888
  function findClonedNavAnchor(unit, hrefKey) {
@@ -5045,8 +5056,8 @@ function deleteNavbarItem(sourceAnchor) {
5045
5056
  if (!isNavbarLinkItem(sourceAnchor)) return null;
5046
5057
  const sourceHrefKey = sourceAnchor.getAttribute("data-ohw-href-key");
5047
5058
  if (!sourceHrefKey || !isNavbarHrefKey(sourceHrefKey)) return null;
5048
- const labelEl = sourceAnchor.querySelector('[data-ohw-editable="text"]');
5049
- const label = (labelEl?.textContent ?? "").trim() || "Untitled";
5059
+ const labelEl2 = sourceAnchor.querySelector('[data-ohw-editable="text"]');
5060
+ const label = (labelEl2?.textContent ?? "").trim() || "Untitled";
5050
5061
  const previousForest = getNavForestFromDom();
5051
5062
  const previousOrderJson = serializeNavOrder(previousForest);
5052
5063
  const parentHrefKey = previousForest.find((n) => n.children.some((c) => c.id === sourceHrefKey))?.id ?? null;
@@ -6421,6 +6432,24 @@ function deleteSectionFromState(state, sectionId) {
6421
6432
  if (removed.includes(sectionId)) return state;
6422
6433
  return { ...state, v: 1, sections: state.sections, removed: [...removed, sectionId] };
6423
6434
  }
6435
+ function moveSectionInState(state, sectionId, targetPath) {
6436
+ const entry = state.sections.find((section) => section.id === sectionId);
6437
+ if (!entry) return null;
6438
+ const moved = {
6439
+ id: entry.id,
6440
+ label: entry.label,
6441
+ path: targetPath,
6442
+ afterSection: null,
6443
+ tree: entry.tree,
6444
+ media: entry.media,
6445
+ ...entry.brand ? { brand: entry.brand } : {}
6446
+ };
6447
+ return {
6448
+ ...state,
6449
+ v: 1,
6450
+ sections: state.sections.map((section) => section.id === sectionId ? moved : section)
6451
+ };
6452
+ }
6424
6453
  function reapRemovedAiSections(state, store, removedIds, excludeIds = /* @__PURE__ */ new Set()) {
6425
6454
  const generated = new Set(state.sections.map((entry) => entry.id));
6426
6455
  const reapedIds = [...new Set(removedIds)].filter((id) => generated.has(id) && !excludeIds.has(id));
@@ -11653,8 +11682,8 @@ function syncFooterTreeLinksFromDom(tree) {
11653
11682
  const heading = getFooterColumnHeadingEl(col);
11654
11683
  const title = heading ? textOf2(heading) : void 0;
11655
11684
  const items = listFooterLinksInColumn(col).map((anchor) => {
11656
- const labelEl = anchor.querySelector('[data-ohw-editable="text"]');
11657
- const label = textOf2(labelEl) || textOf2(anchor);
11685
+ const labelEl2 = anchor.querySelector('[data-ohw-editable="text"]');
11686
+ const label = textOf2(labelEl2) || textOf2(anchor);
11658
11687
  const href = hrefToFooterTreeRef(anchor.getAttribute("href"));
11659
11688
  return label ? { label, href: href || "home" } : null;
11660
11689
  }).filter((x) => Boolean(x));
@@ -17353,7 +17382,7 @@ function apiBase() {
17353
17382
  function bridgeVersion() {
17354
17383
  try {
17355
17384
  if (true) {
17356
- return "0.1.164";
17385
+ return "0.1.166";
17357
17386
  }
17358
17387
  } catch {
17359
17388
  }
@@ -17367,7 +17396,7 @@ function stampBridgeVersionOnDocument() {
17367
17396
  return;
17368
17397
  }
17369
17398
  try {
17370
- const v = true ? "0.1.164" : "";
17399
+ const v = true ? "0.1.166" : "";
17371
17400
  if (v) {
17372
17401
  document.documentElement.setAttribute("data-ohw-bridge-version", v);
17373
17402
  window.__OHW_BRIDGE_VERSION__ = v;
@@ -24093,6 +24122,138 @@ function deleteSelectedNavFooterItem(deps) {
24093
24122
  return false;
24094
24123
  }
24095
24124
 
24125
+ // src/lib/build-page-sync.ts
24126
+ import { useEffect as useEffect19 } from "react";
24127
+ var CHROME_KEY_RE = /^(nav|footer|header|navbar)[-_]/u;
24128
+ function normalisePath(path) {
24129
+ const trimmed = path.trim().replace(/[?#].*$/u, "");
24130
+ if (!trimmed || trimmed === "/") return "/";
24131
+ return `/${trimmed.replace(/^\/+|\/+$/gu, "")}`;
24132
+ }
24133
+ function isDeadPageHref(href, livePaths) {
24134
+ const value = href.trim();
24135
+ if (!value.startsWith("/") || value.startsWith("//")) return false;
24136
+ const path = normalisePath(value);
24137
+ if (path === "/") return false;
24138
+ return !livePaths.some((live) => {
24139
+ const p = normalisePath(live);
24140
+ return p === path || p !== "/" && path.startsWith(`${p}/`);
24141
+ });
24142
+ }
24143
+ var sameWords = (a, b) => a.trim().toLowerCase() === b.trim().toLowerCase();
24144
+ function planBuildPageSync(links, msg) {
24145
+ const live = Array.isArray(msg.livePaths) ? msg.livePaths : [];
24146
+ const removed = new Set((msg.removed ?? []).map(normalisePath));
24147
+ const remove = [];
24148
+ const relabel = [];
24149
+ const retarget = [];
24150
+ const fallback = live.some((p) => normalisePath(p) === "/contact") ? "/contact" : "/";
24151
+ for (const link of links) {
24152
+ const href = link.href.trim();
24153
+ const isPage = href.startsWith("/") && !href.startsWith("//");
24154
+ if (isPage && (removed.has(normalisePath(href)) || live.length > 0 && isDeadPageHref(href, live))) {
24155
+ if (link.area === "chrome") retarget.push({ hrefKey: link.hrefKey, href: fallback });
24156
+ else remove.push(link.hrefKey);
24157
+ continue;
24158
+ }
24159
+ if (isPage) {
24160
+ const path = normalisePath(href);
24161
+ const rename = (msg.relabel ?? []).find((r2) => normalisePath(r2.path) === path);
24162
+ if (rename && sameWords(link.label, rename.oldTitle) && !sameWords(link.label, rename.label)) {
24163
+ relabel.push({ hrefKey: link.hrefKey, label: rename.label });
24164
+ }
24165
+ continue;
24166
+ }
24167
+ if (href.startsWith("#") || href.startsWith("/#")) {
24168
+ const anchor = href.replace(/^\/?#/u, "").toLowerCase();
24169
+ const target = (msg.anchorLabels ?? []).find((a) => a.anchors.some((id) => id.toLowerCase() === anchor));
24170
+ if (target && sameWords(link.label.replace(/\s+/gu, "-"), anchor) && !sameWords(link.label, target.label)) {
24171
+ relabel.push({ hrefKey: link.hrefKey, label: target.label });
24172
+ }
24173
+ }
24174
+ }
24175
+ return { remove, relabel, retarget };
24176
+ }
24177
+ function linkHref(el) {
24178
+ const key = el.getAttribute("data-ohw-href-key");
24179
+ const stored = key ? getStoredLinkHref(key) : void 0;
24180
+ return stored ?? el.getAttribute("href") ?? "";
24181
+ }
24182
+ function labelEl(anchor) {
24183
+ return anchor.querySelector('[data-ohw-editable="text"]');
24184
+ }
24185
+ function collectLinks() {
24186
+ const seen = /* @__PURE__ */ new Set();
24187
+ const links = [];
24188
+ document.querySelectorAll("[data-ohw-href-key]").forEach((el) => {
24189
+ const hrefKey = el.getAttribute("data-ohw-href-key") ?? "";
24190
+ if (seen.has(hrefKey)) return;
24191
+ const area = isNavbarHrefKey(hrefKey) ? "nav" : isFooterHrefKey(hrefKey) ? "footer" : CHROME_KEY_RE.test(hrefKey) ? "chrome" : null;
24192
+ if (!area) return;
24193
+ const label = labelEl(el);
24194
+ if (!label && area !== "chrome") return;
24195
+ seen.add(hrefKey);
24196
+ links.push({ hrefKey, href: linkHref(el), label: label?.textContent ?? el.textContent ?? "", area });
24197
+ });
24198
+ return links;
24199
+ }
24200
+ function applyBuildPageSync(msg, deps) {
24201
+ const plan = planBuildPageSync(collectLinks(), msg);
24202
+ const nodes = /* @__PURE__ */ new Map();
24203
+ for (const hrefKey of plan.remove) {
24204
+ const anchor = document.querySelector(`[data-ohw-href-key="${CSS.escape(hrefKey)}"]`);
24205
+ if (!anchor) continue;
24206
+ const nav = isNavbarHrefKey(hrefKey);
24207
+ const result = nav ? deleteNavbarItem(anchor) : deleteFooterItem(anchor);
24208
+ if (!result) continue;
24209
+ for (const key of result.removedKeys) {
24210
+ nodes.set(key, "");
24211
+ clearStoredLinkHref(key);
24212
+ }
24213
+ nodes.set(nav ? NAV_ORDER_KEY : FOOTER_ORDER_KEY, result.orderJson);
24214
+ }
24215
+ for (const { hrefKey, label } of plan.relabel) {
24216
+ const labelKey = hrefKey.replace(/-href$/u, "-label");
24217
+ document.querySelectorAll(`[data-ohw-href-key="${CSS.escape(hrefKey)}"]`).forEach((anchor) => {
24218
+ const el = labelEl(anchor);
24219
+ if (el) el.textContent = label;
24220
+ });
24221
+ nodes.set(labelKey, label);
24222
+ }
24223
+ for (const { hrefKey, href } of plan.retarget) {
24224
+ setStoredLinkHref(hrefKey, href);
24225
+ document.querySelectorAll(`[data-ohw-href-key="${CSS.escape(hrefKey)}"]`).forEach((anchor) => {
24226
+ if (anchor instanceof HTMLAnchorElement) anchor.setAttribute("href", href);
24227
+ });
24228
+ nodes.set(hrefKey, href);
24229
+ }
24230
+ if (nodes.size === 0) return 0;
24231
+ deps.setEditContent({ ...deps.getEditContent(), ...Object.fromEntries(nodes) });
24232
+ deps.postToParent({
24233
+ type: "ow:change",
24234
+ nodes: [...nodes].map(([key, text]) => ({ key, text }))
24235
+ });
24236
+ return plan.remove.length + plan.relabel.length + plan.retarget.length;
24237
+ }
24238
+ function useBuildPageSync(isEditMode, editContentRef, postToParent2) {
24239
+ useEffect19(() => {
24240
+ if (!isEditMode) return;
24241
+ const onMessage = (e) => {
24242
+ if (e.source !== window.parent || e.data?.type !== "ow:pages-sync") return;
24243
+ const changed = applyBuildPageSync(e.data, {
24244
+ getEditContent: () => editContentRef.current,
24245
+ setEditContent: (next) => {
24246
+ editContentRef.current = next;
24247
+ },
24248
+ postToParent: postToParent2
24249
+ });
24250
+ postToParent2({ type: "ow:pages-synced", changed });
24251
+ };
24252
+ window.addEventListener("message", onMessage);
24253
+ return () => window.removeEventListener("message", onMessage);
24254
+ }, [isEditMode, editContentRef, postToParent2]);
24255
+ }
24256
+
24096
24257
  // src/lib/nav-page-sync.ts
24097
24258
  function labelKeyFor(hrefKey) {
24098
24259
  return hrefKey.replace(/-href$/, "-label");
@@ -25798,7 +25959,7 @@ function OhhwellsBridge() {
25798
25959
  const searchParams = useSearchParams();
25799
25960
  const isEditMode = isEditSessionActive();
25800
25961
  const [bridgeRoot, setBridgeRoot] = useState18(null);
25801
- useEffect19(() => {
25962
+ useEffect20(() => {
25802
25963
  const figtreeFontId = "ohw-figtree-font";
25803
25964
  if (!document.getElementById(figtreeFontId)) {
25804
25965
  const preconnect1 = Object.assign(document.createElement("link"), { rel: "preconnect", href: "https://fonts.googleapis.com" });
@@ -25837,7 +25998,7 @@ function OhhwellsBridge() {
25837
25998
  }, 0);
25838
25999
  return () => window.clearTimeout(t);
25839
26000
  }, [subdomainFromQuery, subdomain]);
25840
- useEffect19(() => {
26001
+ useEffect20(() => {
25841
26002
  if (!subdomainFromQuery || typeof window === "undefined") return;
25842
26003
  const url = new URL(window.location.href);
25843
26004
  if (!url.searchParams.has("subdomain")) return;
@@ -25857,14 +26018,14 @@ function OhhwellsBridge() {
25857
26018
  const [fetchState, setFetchState] = useState18("idle");
25858
26019
  const [showBranding, setShowBranding] = useState18(false);
25859
26020
  const autoSaveTimers = useRef14(/* @__PURE__ */ new Map());
25860
- useEffect19(() => {
26021
+ useEffect20(() => {
25861
26022
  stampBridgeVersionOnDocument();
25862
26023
  }, []);
25863
- useEffect19(() => {
26024
+ useEffect20(() => {
25864
26025
  if (isEditMode) return;
25865
26026
  return armLoaderHangBeacon(subdomain, fetchState);
25866
26027
  }, [isEditMode, subdomain, fetchState]);
25867
- useEffect19(() => {
26028
+ useEffect20(() => {
25868
26029
  if (isEditMode || !subdomain) return;
25869
26030
  const onError = (event) => {
25870
26031
  reportOutageBeacon({
@@ -26005,7 +26166,7 @@ function OhhwellsBridge() {
26005
26166
  }, []);
26006
26167
  const selectMediaElementRef = useRef14(selectMediaElement);
26007
26168
  selectMediaElementRef.current = selectMediaElement;
26008
- useEffect19(() => {
26169
+ useEffect20(() => {
26009
26170
  if (!selectedMedia) return;
26010
26171
  const update = () => {
26011
26172
  const el = selectedMediaElRef.current;
@@ -26220,7 +26381,7 @@ function OhhwellsBridge() {
26220
26381
  const [fieldDragging, setFieldDragging] = useState18(false);
26221
26382
  const clearFormPickRef = useRef14(clearFormPick);
26222
26383
  clearFormPickRef.current = clearFormPick;
26223
- useEffect19(() => {
26384
+ useEffect20(() => {
26224
26385
  const el = fieldPickElRef.current;
26225
26386
  if (!el || fieldPickRect === null) return;
26226
26387
  const observer = new ResizeObserver(() => {
@@ -26229,7 +26390,7 @@ function OhhwellsBridge() {
26229
26390
  observer.observe(el);
26230
26391
  return () => observer.disconnect();
26231
26392
  }, [fieldPickRect !== null, fieldPickState]);
26232
- useEffect19(() => {
26393
+ useEffect20(() => {
26233
26394
  const el = formPickElRef.current;
26234
26395
  if (!el || formPickRect === null) return;
26235
26396
  const observer = new ResizeObserver(() => {
@@ -26256,7 +26417,7 @@ function OhhwellsBridge() {
26256
26417
  const hoveredItemElRef = useRef14(null);
26257
26418
  const [hoveredItemRect, setHoveredItemRect] = useState18(null);
26258
26419
  const [hoveredTextRect, setHoveredTextRect] = useState18(null);
26259
- useEffect19(() => {
26420
+ useEffect20(() => {
26260
26421
  const sync = () => {
26261
26422
  const el = document.querySelector(
26262
26423
  '[data-ohw-hovered]:not([contenteditable]):not([data-ohw-href-key]):not([data-ohw-editable="form"] *)'
@@ -26334,6 +26495,7 @@ function OhhwellsBridge() {
26334
26495
  const linkPopoverSessionRef = useRef14(null);
26335
26496
  const addNavAfterAnchorRef = useRef14(null);
26336
26497
  const editContentRef = useRef14({});
26498
+ useBuildPageSync(isEditMode, editContentRef, postToParent2);
26337
26499
  const aiSectionsRef = useRef14("");
26338
26500
  const aiFooterRef = useRef14("");
26339
26501
  const applyTreeLocalRef = useRef14(
@@ -26356,7 +26518,7 @@ function OhhwellsBridge() {
26356
26518
  const linkPopoverGraceUntilRef = useRef14(0);
26357
26519
  setLinkPopoverRef.current = setLinkPopover;
26358
26520
  linkPopoverSessionRef.current = linkPopover;
26359
- useEffect19(() => {
26521
+ useEffect20(() => {
26360
26522
  setSectionOrderPersistHandler((entries) => {
26361
26523
  const currentPath = window.location.pathname;
26362
26524
  const merged = mergePageSectionOrder(editContentRef.current[SECTION_ORDER_KEY], currentPath, entries);
@@ -26366,7 +26528,7 @@ function OhhwellsBridge() {
26366
26528
  });
26367
26529
  return () => setSectionOrderPersistHandler(null);
26368
26530
  }, []);
26369
- useEffect19(() => {
26531
+ useEffect20(() => {
26370
26532
  setAiFooterMountOptions({
26371
26533
  resolvePageHref: (pageOrAnchorId) => {
26372
26534
  const [pageId, anchor] = pageOrAnchorId.split("#");
@@ -26450,7 +26612,7 @@ function OhhwellsBridge() {
26450
26612
  }, [isEditMode, pathname]);
26451
26613
  const runSectionsPrefetchRef = useRef14(runSectionsPrefetch);
26452
26614
  runSectionsPrefetchRef.current = runSectionsPrefetch;
26453
- useEffect19(() => {
26615
+ useEffect20(() => {
26454
26616
  if (!linkPopover) {
26455
26617
  document.documentElement.removeAttribute("data-ohw-link-popover-open");
26456
26618
  return;
@@ -26478,7 +26640,7 @@ function OhhwellsBridge() {
26478
26640
  document.documentElement.removeAttribute("data-ohw-link-popover-open");
26479
26641
  };
26480
26642
  }, [linkPopover, postToParent2]);
26481
- useEffect19(() => {
26643
+ useEffect20(() => {
26482
26644
  if (!isEditMode) return;
26483
26645
  const useFixtures = shouldUseDevFixtures();
26484
26646
  if (useFixtures) {
@@ -26504,7 +26666,7 @@ function OhhwellsBridge() {
26504
26666
  if (!useFixtures) postToParent2({ type: "ow:request-site-pages" });
26505
26667
  return () => window.removeEventListener("message", onSitePages);
26506
26668
  }, [isEditMode, postToParent2]);
26507
- useEffect19(() => {
26669
+ useEffect20(() => {
26508
26670
  if (!isEditMode) return;
26509
26671
  const deps = {
26510
26672
  getEditContent: () => editContentRef.current,
@@ -26541,14 +26703,14 @@ function OhhwellsBridge() {
26541
26703
  window.addEventListener("message", onPageMessage);
26542
26704
  return () => window.removeEventListener("message", onPageMessage);
26543
26705
  }, [isEditMode, postToParent2]);
26544
- useEffect19(() => {
26706
+ useEffect20(() => {
26545
26707
  if (!isEditMode || shouldUseDevFixtures()) return;
26546
26708
  void loadAllSectionsManifest().then((manifest) => {
26547
26709
  if (Object.keys(manifest).length === 0) return;
26548
26710
  setSectionsByPath((prev) => ({ ...manifest, ...prev }));
26549
26711
  });
26550
26712
  }, [isEditMode]);
26551
- useEffect19(() => {
26713
+ useEffect20(() => {
26552
26714
  const update = () => {
26553
26715
  const el = activeElRef.current ?? selectedElRef.current;
26554
26716
  if (el) setToolbarRect(getEditMeasureEl(el).getBoundingClientRect());
@@ -27807,7 +27969,7 @@ function OhhwellsBridge() {
27807
27969
  },
27808
27970
  [postToParent2]
27809
27971
  );
27810
- useEffect19(() => {
27972
+ useEffect20(() => {
27811
27973
  const onDragOver = (e) => {
27812
27974
  const dragged = buttonCollectionDragRef.current;
27813
27975
  if (!dragged) return;
@@ -27878,7 +28040,7 @@ function OhhwellsBridge() {
27878
28040
  setLogoSizeDraft(null);
27879
28041
  deselectRef.current();
27880
28042
  }, []);
27881
- useEffect19(() => {
28043
+ useEffect20(() => {
27882
28044
  const session = floatingPanel && floatingPanel.kind === "logo-size" ? floatingPanel : null;
27883
28045
  if (!session || !logoSizeDraft) {
27884
28046
  postToParentRef.current({ type: "ow:logo-size-panel", open: false });
@@ -28036,7 +28198,7 @@ function OhhwellsBridge() {
28036
28198
  deselectRef.current = deselect;
28037
28199
  closeFloatingPanelOnlyRef.current = closeFloatingPanelOnly;
28038
28200
  const lastSiteWideScopeRef = useRef14(null);
28039
- useEffect19(() => {
28201
+ useEffect20(() => {
28040
28202
  if (!isEditMode) {
28041
28203
  if (lastSiteWideScopeRef.current !== false) {
28042
28204
  lastSiteWideScopeRef.current = false;
@@ -28213,7 +28375,7 @@ function OhhwellsBridge() {
28213
28375
  cancelled = true;
28214
28376
  };
28215
28377
  }, [subdomain, isEditMode]);
28216
- useEffect19(() => {
28378
+ useEffect20(() => {
28217
28379
  if (!isEditMode) return;
28218
28380
  const resolveIndex = (form, clientY) => {
28219
28381
  const wrappers = listFieldWrappers(form).filter((el) => fieldKeyOf(el) !== fieldDragRef.current?.key);
@@ -28254,7 +28416,7 @@ function OhhwellsBridge() {
28254
28416
  window.removeEventListener("drop", onDrop, true);
28255
28417
  };
28256
28418
  }, [buildFieldDropSlots, isEditMode, persistFields, selectField]);
28257
- useEffect19(() => {
28419
+ useEffect20(() => {
28258
28420
  if (!isEditMode) return;
28259
28421
  const mark = () => document.querySelectorAll('[data-ohw-editable="form"]').forEach((form) => {
28260
28422
  markFormFields(form);
@@ -28266,7 +28428,7 @@ function OhhwellsBridge() {
28266
28428
  });
28267
28429
  return () => observer.disconnect();
28268
28430
  }, [isEditMode, fetchState, pathname]);
28269
- useEffect19(() => {
28431
+ useEffect20(() => {
28270
28432
  if (!isEditMode) return;
28271
28433
  let saveTimer = null;
28272
28434
  const onInput = (e) => {
@@ -28288,14 +28450,14 @@ function OhhwellsBridge() {
28288
28450
  document.addEventListener("input", onInput, true);
28289
28451
  return () => document.removeEventListener("input", onInput, true);
28290
28452
  }, [isEditMode, persistFields]);
28291
- useEffect19(() => {
28453
+ useEffect20(() => {
28292
28454
  if (isEditMode || fetchState !== "done") return;
28293
28455
  const content = contentCache.get(subdomain) ?? {};
28294
28456
  document.querySelectorAll('[data-ohw-editable="form"]').forEach((form) => {
28295
28457
  reconcileFieldsFromContent(form, content);
28296
28458
  });
28297
28459
  }, [isEditMode, fetchState, subdomain]);
28298
- useEffect19(() => {
28460
+ useEffect20(() => {
28299
28461
  if (!isEditMode) return;
28300
28462
  const swallow = (e) => {
28301
28463
  const target = e.target;
@@ -28304,14 +28466,14 @@ function OhhwellsBridge() {
28304
28466
  document.addEventListener("submit", swallow, true);
28305
28467
  return () => document.removeEventListener("submit", swallow, true);
28306
28468
  }, [isEditMode]);
28307
- useEffect19(() => {
28469
+ useEffect20(() => {
28308
28470
  if (isEditMode || fetchState !== "done") return;
28309
28471
  console.log("env", process.env.NEXT_PUBLIC_FLOWOPS_API_URL);
28310
28472
  const apiUrl = process.env.NEXT_PUBLIC_FLOWOPS_API_URL ?? "https://flowops-backend-staging-2yfdh7pwpq-as.a.run.app";
28311
28473
  console.log({ apiUrl, subdomain });
28312
28474
  bindPublishedForms(apiUrl, subdomain, contentCache.get(subdomain) ?? {});
28313
28475
  }, [isEditMode, fetchState, subdomain]);
28314
- useEffect19(() => {
28476
+ useEffect20(() => {
28315
28477
  if (!subdomain || isEditMode) return;
28316
28478
  let debounceTimer = null;
28317
28479
  let observer = null;
@@ -28434,10 +28596,10 @@ function OhhwellsBridge() {
28434
28596
  const visible = Boolean(subdomain) && fetchState !== "done";
28435
28597
  el.style.display = visible ? "flex" : "none";
28436
28598
  }, [subdomain, fetchState]);
28437
- useEffect19(() => {
28599
+ useEffect20(() => {
28438
28600
  postToParent2({ type: "ow:navigation", path: pathname });
28439
28601
  }, [pathname, postToParent2]);
28440
- useEffect19(() => {
28602
+ useEffect20(() => {
28441
28603
  if (!subdomain || isEditMode) return;
28442
28604
  const content = contentCache.get(subdomain);
28443
28605
  if (!content) return;
@@ -28455,7 +28617,7 @@ function OhhwellsBridge() {
28455
28617
  }
28456
28618
  applyAiFooterFromContent(content);
28457
28619
  }, [pathname, subdomain, isEditMode]);
28458
- useEffect19(() => {
28620
+ useEffect20(() => {
28459
28621
  if (!isEditMode) return;
28460
28622
  if (linkPopoverSessionRef.current?.intent === "add-nav") return;
28461
28623
  if (document.querySelector("[data-ohw-section-picker]")) return;
@@ -28463,12 +28625,12 @@ function OhhwellsBridge() {
28463
28625
  deselectRef.current();
28464
28626
  deactivateRef.current();
28465
28627
  }, [pathname, isEditMode]);
28466
- useEffect19(() => {
28628
+ useEffect20(() => {
28467
28629
  if (!isEditMode) return;
28468
28630
  initSectionInstancesFromContent(editContentRef.current, pathname);
28469
28631
  initItemInstancesFromContent(editContentRef.current);
28470
28632
  }, [pathname, isEditMode]);
28471
- useEffect19(() => {
28633
+ useEffect20(() => {
28472
28634
  if (!isEditMode) return;
28473
28635
  const observer = new MutationObserver(() => {
28474
28636
  const drawer = document.querySelector("[data-ohw-nav-drawer]");
@@ -28479,7 +28641,7 @@ function OhhwellsBridge() {
28479
28641
  observer.observe(document.body, { childList: true, subtree: true });
28480
28642
  return () => observer.disconnect();
28481
28643
  }, [isEditMode, pathname]);
28482
- useEffect19(() => {
28644
+ useEffect20(() => {
28483
28645
  const contentForNav = () => {
28484
28646
  if (isEditMode) return editContentRef.current;
28485
28647
  if (!subdomain) return {};
@@ -28552,7 +28714,7 @@ function OhhwellsBridge() {
28552
28714
  observer?.disconnect();
28553
28715
  };
28554
28716
  }, [isEditMode, pathname, subdomain, fetchState, resyncSelectedNavigationItem]);
28555
- useEffect19(() => {
28717
+ useEffect20(() => {
28556
28718
  if (!isEditMode) return;
28557
28719
  let applying = false;
28558
28720
  let rafId = null;
@@ -28590,7 +28752,7 @@ function OhhwellsBridge() {
28590
28752
  observer.disconnect();
28591
28753
  };
28592
28754
  }, [isEditMode, pathname]);
28593
- useEffect19(() => {
28755
+ useEffect20(() => {
28594
28756
  if (!isEditMode) return;
28595
28757
  let lastPosted = 0;
28596
28758
  const measure = () => {
@@ -28634,7 +28796,7 @@ function OhhwellsBridge() {
28634
28796
  window.removeEventListener("resize", handleResize);
28635
28797
  };
28636
28798
  }, [pathname, isEditMode, postToParent2]);
28637
- useEffect19(() => {
28799
+ useEffect20(() => {
28638
28800
  if (isEditMode) return;
28639
28801
  const handleClick = (e) => {
28640
28802
  if (!isPlainLeftClick(e)) return;
@@ -28648,7 +28810,7 @@ function OhhwellsBridge() {
28648
28810
  document.addEventListener("click", handleClick, true);
28649
28811
  return () => document.removeEventListener("click", handleClick, true);
28650
28812
  }, [isEditMode, router, pathname]);
28651
- useEffect19(() => {
28813
+ useEffect20(() => {
28652
28814
  if (!isEditMode) {
28653
28815
  editStylesRef.current?.base.remove();
28654
28816
  editStylesRef.current?.forceHover.remove();
@@ -30878,6 +31040,31 @@ function OhhwellsBridge() {
30878
31040
  postAiSectionsChanged();
30879
31041
  };
30880
31042
  window.addEventListener("message", handleAiDeleteSection);
31043
+ const handleAiMoveSection = (e) => {
31044
+ if (e.data?.type !== "ow:ai-move-section") return;
31045
+ const sectionId = typeof e.data.sectionId === "string" ? e.data.sectionId : "";
31046
+ const targetPage = typeof e.data.targetPage === "string" ? e.data.targetPage : "";
31047
+ if (!sectionId || !targetPage) return;
31048
+ const previous = aiSectionsRef.current;
31049
+ const nextState = moveSectionInState(parseAiSectionsState(previous), sectionId, targetPage);
31050
+ if (!nextState) return;
31051
+ clearInteractionChrome();
31052
+ const nextValue = serializeAiSectionsState(nextState);
31053
+ aiSectionsRef.current = nextValue;
31054
+ applyAiSectionsToDom(nextState);
31055
+ const newHeight = document.body.scrollHeight;
31056
+ if (newHeight > 50) postToParentRef.current({ type: "ow:height", height: newHeight });
31057
+ postToParentRef.current({ type: "ow:change", nodes: [{ key: AI_SECTIONS_KEY, text: nextValue }] });
31058
+ postToParentRef.current({
31059
+ type: "ow:ai-section-moved",
31060
+ sectionId,
31061
+ targetPage,
31062
+ previous,
31063
+ value: nextValue
31064
+ });
31065
+ postAiSectionsChanged();
31066
+ };
31067
+ window.addEventListener("message", handleAiMoveSection);
30881
31068
  const handleAiSetSections = (e) => {
30882
31069
  if (e.data?.type !== "ow:ai-set-sections") return;
30883
31070
  const value = typeof e.data.value === "string" ? e.data.value : "";
@@ -32077,6 +32264,7 @@ function OhhwellsBridge() {
32077
32264
  window.removeEventListener("message", handleAiApplyTree);
32078
32265
  window.removeEventListener("message", handleAiApplyFooter);
32079
32266
  window.removeEventListener("message", handleAiDeleteSection);
32267
+ window.removeEventListener("message", handleAiMoveSection);
32080
32268
  window.removeEventListener("message", handleAiSetSections);
32081
32269
  window.removeEventListener("message", handleAiSetBrand);
32082
32270
  window.removeEventListener("message", handleAiSetStyles);
@@ -32103,7 +32291,7 @@ function OhhwellsBridge() {
32103
32291
  if (imageShowTimerRef.current) clearTimeout(imageShowTimerRef.current);
32104
32292
  };
32105
32293
  }, [isEditMode, refreshStateRules]);
32106
- useEffect19(() => {
32294
+ useEffect20(() => {
32107
32295
  if (!isEditMode) return;
32108
32296
  const THRESHOLD = 10;
32109
32297
  const resolveWasSelected = (el) => {
@@ -32259,7 +32447,7 @@ function OhhwellsBridge() {
32259
32447
  unlockFooterDragInteraction();
32260
32448
  };
32261
32449
  }, [isEditMode]);
32262
- useEffect19(() => {
32450
+ useEffect20(() => {
32263
32451
  if (!isEditMode) return;
32264
32452
  const THRESHOLD = 10;
32265
32453
  const onPointerDown = (e) => {
@@ -32350,7 +32538,7 @@ function OhhwellsBridge() {
32350
32538
  document.removeEventListener("selectstart", blockSelectStart, true);
32351
32539
  };
32352
32540
  }, [isEditMode, persistButtonCollectionDrag, refreshButtonDragVisuals]);
32353
- useEffect19(() => {
32541
+ useEffect20(() => {
32354
32542
  const handler = (e) => {
32355
32543
  if (e.data?.type !== "ow:request-schedule-config") return;
32356
32544
  const insertAfterVal = e.data.insertAfter;
@@ -32366,7 +32554,7 @@ function OhhwellsBridge() {
32366
32554
  window.addEventListener("message", handler);
32367
32555
  return () => window.removeEventListener("message", handler);
32368
32556
  }, [processConfigRequest]);
32369
- useEffect19(() => {
32557
+ useEffect20(() => {
32370
32558
  if (!isEditMode) return;
32371
32559
  document.querySelectorAll("[data-ohw-active-state]").forEach((el) => {
32372
32560
  el.removeAttribute("data-ohw-active-state");
@@ -32390,7 +32578,7 @@ function OhhwellsBridge() {
32390
32578
  postToParent2({
32391
32579
  type: "ow:ready",
32392
32580
  version: "1",
32393
- bridgeVersion: "0.1.164",
32581
+ bridgeVersion: "0.1.166",
32394
32582
  path: pathname,
32395
32583
  nodes: collectEditableNodes(editContentRef.current),
32396
32584
  sections
@@ -32402,7 +32590,7 @@ function OhhwellsBridge() {
32402
32590
  clearTimeout(timer);
32403
32591
  };
32404
32592
  }, [pathname, isEditMode, refreshStateRules, postToParent2]);
32405
- useEffect19(() => {
32593
+ useEffect20(() => {
32406
32594
  scrollToHashSectionWhenReady();
32407
32595
  const onHashChange = () => scrollToHashSectionWhenReady();
32408
32596
  window.addEventListener("hashchange", onHashChange);
@@ -32444,7 +32632,7 @@ function OhhwellsBridge() {
32444
32632
  if (el) setToolbarRect(getEditMeasureEl(el).getBoundingClientRect());
32445
32633
  refreshActiveCommandsRef.current();
32446
32634
  }, []);
32447
- useEffect19(() => {
32635
+ useEffect20(() => {
32448
32636
  const session = floatingPanel && floatingPanel.kind === "logo-size" ? floatingPanel : null;
32449
32637
  if (!session || !logoSizeDraft) return;
32450
32638
  const onPanelAction = (e) => {
@@ -33618,6 +33806,7 @@ export {
33618
33806
  hasMountedContentNodes,
33619
33807
  indexCollectionItems,
33620
33808
  insertFooterHours,
33809
+ isDeadPageHref,
33621
33810
  isEditSessionActive,
33622
33811
  isPlainLeftClick,
33623
33812
  isRenderableFooterTree,
@@ -33629,6 +33818,7 @@ export {
33629
33818
  parseAiFooterState,
33630
33819
  parseAiSectionsState,
33631
33820
  parseTarget,
33821
+ planBuildPageSync,
33632
33822
  recordOverriddenPaths,
33633
33823
  releaseTemplateLogoIfReplaced,
33634
33824
  removeFooterBlock,