@ohhwells/bridge 0.1.92 → 0.1.94

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
@@ -2261,6 +2261,22 @@ function applyAiSectionsToDom(state, options) {
2261
2261
  syncRemovedSections(state);
2262
2262
  syncTemplateHidden(state, pageSections.length > 0);
2263
2263
  }
2264
+ function unmountAllAiSections() {
2265
+ for (const [, section] of mounted) {
2266
+ section.root.unmount();
2267
+ section.container.remove();
2268
+ }
2269
+ mounted.clear();
2270
+ if (typeof document === "undefined") return;
2271
+ for (const el of document.querySelectorAll(`[${REPLACED_ATTR}]`)) {
2272
+ el.style.removeProperty("display");
2273
+ el.removeAttribute(REPLACED_ATTR);
2274
+ }
2275
+ for (const el of document.querySelectorAll(`[${REMOVED_ATTR}]`)) {
2276
+ el.style.removeProperty("display");
2277
+ el.removeAttribute(REMOVED_ATTR);
2278
+ }
2279
+ }
2264
2280
 
2265
2281
  // src/useLinkHrefGuardian.ts
2266
2282
  var import_react2 = require("react");
@@ -8258,17 +8274,40 @@ var REMOVED_ATTR2 = "data-ohw-section-removed";
8258
8274
  function isRemovedSection(el) {
8259
8275
  return el.hasAttribute(REMOVED_ATTR2);
8260
8276
  }
8277
+ function movableUnit(el) {
8278
+ return el.closest("[data-ohw-section-container]") ?? el;
8279
+ }
8280
+ function sectionTypeOf(el) {
8281
+ return el.getAttribute("data-ohw-section") ?? el.querySelector("[data-ohw-section]")?.getAttribute("data-ohw-section") ?? "";
8282
+ }
8283
+ function sectionElementOf(el) {
8284
+ return el.hasAttribute("data-ohw-section") ? el : el.querySelector("[data-ohw-section]") ?? el;
8285
+ }
8286
+ function collectTopLevelUnits(predicate) {
8287
+ const seen = /* @__PURE__ */ new Set();
8288
+ const result = [];
8289
+ document.querySelectorAll("[data-ohw-section]").forEach((el) => {
8290
+ if (!predicate(el)) return;
8291
+ const unit = movableUnit(el);
8292
+ if (unit.parentElement?.closest("[data-ohw-section],[data-ohw-section-container]")) return;
8293
+ if (seen.has(unit)) return;
8294
+ seen.add(unit);
8295
+ result.push(unit);
8296
+ });
8297
+ return result;
8298
+ }
8261
8299
  function topLevelSections() {
8262
- return Array.from(document.querySelectorAll("[data-ohw-section]")).filter(
8263
- (el) => !el.parentElement?.closest("[data-ohw-section]") && !isChromeSection(el) && !isRemovedSection(el)
8264
- );
8300
+ return collectTopLevelUnits((el) => !isChromeSection(el) && !isRemovedSection(movableUnit(el)));
8265
8301
  }
8266
8302
  function instanceIdOf(el) {
8267
8303
  return el.dataset.ohwInstance ?? el.dataset.ohwSection ?? "";
8268
8304
  }
8269
8305
  function findByInstanceId(instanceId) {
8270
8306
  const escapedId = CSS.escape(instanceId);
8271
- return document.querySelector(`[data-ohw-instance="${escapedId}"]`) ?? document.querySelector(`[data-ohw-section="${escapedId}"]:not([data-ohw-instance])`);
8307
+ const direct = document.querySelector(`[data-ohw-instance="${escapedId}"]`);
8308
+ if (direct) return movableUnit(direct);
8309
+ const bare = document.querySelector(`[data-ohw-section="${escapedId}"]:not([data-ohw-instance])`);
8310
+ return bare ? movableUnit(bare) : null;
8272
8311
  }
8273
8312
  function planSectionMove(instanceId, targetIndex, currentPath) {
8274
8313
  const sections = topLevelSections();
@@ -8280,7 +8319,7 @@ function planSectionMove(instanceId, targetIndex, currentPath) {
8280
8319
  const reordered = [...others.slice(0, clamped), dragged, ...others.slice(clamped)];
8281
8320
  return reordered.map((el, order) => ({
8282
8321
  instanceId: instanceIdOf(el),
8283
- type: el.getAttribute("data-ohw-section") ?? "",
8322
+ type: sectionTypeOf(el),
8284
8323
  order,
8285
8324
  pagePath: currentPath
8286
8325
  }));
@@ -8335,13 +8374,11 @@ function applyPersistedOrder(entries) {
8335
8374
  function setSectionRemoved(instanceId, currentPath, existingEntries, removed) {
8336
8375
  if (!findByInstanceId(instanceId)) return null;
8337
8376
  const byId = new Map(existingEntries.map((e) => [e.instanceId, e]));
8338
- const allSections = Array.from(document.querySelectorAll("[data-ohw-section]")).filter(
8339
- (el) => !el.parentElement?.closest("[data-ohw-section]") && !isChromeSection(el)
8340
- );
8377
+ const allSections = collectTopLevelUnits((el) => !isChromeSection(el));
8341
8378
  allSections.forEach((el, order) => {
8342
8379
  const id = instanceIdOf(el);
8343
8380
  if (!byId.has(id)) {
8344
- byId.set(id, { instanceId: id, type: el.getAttribute("data-ohw-section") ?? "", order, pagePath: currentPath });
8381
+ byId.set(id, { instanceId: id, type: sectionTypeOf(el), order, pagePath: currentPath });
8345
8382
  }
8346
8383
  });
8347
8384
  const target = byId.get(instanceId);
@@ -8369,7 +8406,7 @@ function duplicateSectionInstance(instanceId, newId, currentPath, existingEntrie
8369
8406
  const id = instanceIdOf(el);
8370
8407
  return {
8371
8408
  instanceId: id,
8372
- type: el.getAttribute("data-ohw-section") ?? "",
8409
+ type: sectionTypeOf(el),
8373
8410
  order,
8374
8411
  pagePath: currentPath,
8375
8412
  ...byId.get(id)?.removed ? { removed: true } : {}
@@ -8411,6 +8448,10 @@ function initSectionInstancesFromContent(content, currentPath) {
8411
8448
  document.querySelectorAll("[data-ohw-section]:not([data-ohw-instance])").forEach((el) => {
8412
8449
  el.setAttribute("data-ohw-instance", el.getAttribute("data-ohw-section") ?? "");
8413
8450
  });
8451
+ document.querySelectorAll("[data-ohw-section-container]:not([data-ohw-instance])").forEach((el) => {
8452
+ const type = sectionTypeOf(el);
8453
+ if (type) el.setAttribute("data-ohw-instance", type);
8454
+ });
8414
8455
  const entries = getPageSectionOrderEntries(content[SECTION_ORDER_KEY], currentPath);
8415
8456
  for (const entry of entries) {
8416
8457
  if (entry.instanceId === entry.type) continue;
@@ -8429,10 +8470,7 @@ function initSectionInstancesFromContent(content, currentPath) {
8429
8470
 
8430
8471
  // src/ui/ai-section/AiSectionOverlay.tsx
8431
8472
  var import_jsx_runtime17 = require("react/jsx-runtime");
8432
- function findSectionElement(instanceId) {
8433
- const escaped = CSS.escape(instanceId);
8434
- return document.querySelector(`[data-ohw-instance="${escaped}"]`) ?? document.querySelector(`[data-ohw-section="${escaped}"]:not([data-ohw-instance])`);
8435
- }
8473
+ var findSectionElement = findByInstanceId;
8436
8474
  function readRect(instanceId) {
8437
8475
  const el = findSectionElement(instanceId);
8438
8476
  if (!el) return null;
@@ -8472,7 +8510,7 @@ function useLiveSectionRect(sectionId) {
8472
8510
  }
8473
8511
  function computeSectionBoundaryFlags(instanceId) {
8474
8512
  const topLevel = topLevelSections();
8475
- const index = topLevel.findIndex((el) => (el.dataset.ohwInstance ?? el.dataset.ohwSection) === instanceId);
8513
+ const index = topLevel.findIndex((el) => instanceIdOf(el) === instanceId);
8476
8514
  if (index === -1) return { isFirst: true, isLast: true };
8477
8515
  return { isFirst: index === 0, isLast: index === topLevel.length - 1 };
8478
8516
  }
@@ -8556,18 +8594,20 @@ function AiSectionOverlay({
8556
8594
  selectedIdRef.current = selectedId;
8557
8595
  const report = (0, import_react8.useCallback)(
8558
8596
  (el) => {
8597
+ const labelSrc = el ? sectionElementOf(el) : null;
8559
8598
  postToParent2({
8560
8599
  type: "ow:section-selected",
8561
- sectionId: el ? el.dataset.ohwInstance ?? el.dataset.ohwSection ?? null : null,
8562
- sectionLabel: el ? el.dataset.ohwSectionLabel ?? titleCaseSectionId(el.dataset.ohwSection ?? "") : null
8600
+ sectionId: el ? instanceIdOf(el) || null : null,
8601
+ sectionLabel: labelSrc ? labelSrc.dataset.ohwSectionLabel ?? titleCaseSectionId(labelSrc.dataset.ohwSection ?? "") : null
8563
8602
  });
8564
8603
  },
8565
8604
  [postToParent2]
8566
8605
  );
8567
8606
  const selectFromElement = (0, import_react8.useCallback)(
8568
8607
  (el, options) => {
8569
- const sectionEl = el?.closest("[data-ohw-section]") ?? null;
8570
- const id = sectionEl ? sectionEl.dataset.ohwInstance ?? sectionEl.dataset.ohwSection ?? null : null;
8608
+ const inner = el?.closest("[data-ohw-section]") ?? null;
8609
+ const sectionEl = inner ? movableUnit(inner) : null;
8610
+ const id = sectionEl ? instanceIdOf(sectionEl) || null : null;
8571
8611
  if (id === selectedIdRef.current) return;
8572
8612
  setSelectedId(id);
8573
8613
  if (options?.report !== false) report(sectionEl);
@@ -8633,7 +8673,8 @@ function AiSectionOverlay({
8633
8673
  return;
8634
8674
  }
8635
8675
  const sec = t.closest("[data-ohw-section]");
8636
- setHoveredId(sec ? sec.dataset.ohwInstance ?? sec.dataset.ohwSection ?? null : null);
8676
+ const unit = sec ? movableUnit(sec) : null;
8677
+ setHoveredId(unit ? instanceIdOf(unit) || null : null);
8637
8678
  };
8638
8679
  const onLeave = () => setHoveredId(null);
8639
8680
  document.addEventListener("mousemove", onMove, { passive: true });
@@ -14251,8 +14292,9 @@ function useSectionDrag({
14251
14292
  const target = e.target;
14252
14293
  if (!(target instanceof HTMLElement)) return;
14253
14294
  if (target.closest(SECTION_DRAG_EXCLUDED_SELECTOR)) return;
14254
- const sectionEl = target.closest("[data-ohw-section]");
14255
- if (!sectionEl || isChromeSection(sectionEl) || sectionEl.dataset.ohwSection === "footer") return;
14295
+ const inner = target.closest("[data-ohw-section]");
14296
+ if (!inner || isChromeSection(inner) || inner.dataset.ohwSection === "footer") return;
14297
+ const sectionEl = movableUnit(inner);
14256
14298
  if (!topLevelSections().includes(sectionEl)) return;
14257
14299
  startSectionPressDrag(sectionEl, e.clientX, e.clientY, e.pointerId);
14258
14300
  };
@@ -15159,7 +15201,6 @@ function mountSchedulingWidget(insertAfter, notifyOnConnect = false, scheduleId,
15159
15201
  if (!mountPoint) return false;
15160
15202
  const container = document.createElement("div");
15161
15203
  container.dataset.ohwSectionContainer = "scheduling";
15162
- container.dataset.ohwSection = sectionId;
15163
15204
  container.dataset.ohwInstance = sectionId;
15164
15205
  if (insertBefore) {
15165
15206
  const beforeAnchor = document.querySelector(`[data-ohw-section="${insertBefore}"]`);
@@ -18316,10 +18357,10 @@ function OhhwellsBridge() {
18316
18357
  const applyFromCache = () => {
18317
18358
  const content = contentCache.get(subdomain);
18318
18359
  if (!content) return;
18319
- retryMissingSchedulingMounts(getPageSchedulingEntries(content["__ohw_sections"]), false);
18320
- initSectionInstancesFromContent(content, window.location.pathname);
18321
18360
  observer?.disconnect();
18322
18361
  try {
18362
+ retryMissingSchedulingMounts(getPageSchedulingEntries(content["__ohw_sections"]), false);
18363
+ initSectionInstancesFromContent(content, window.location.pathname);
18323
18364
  applyBrandChrome(content);
18324
18365
  if (typeof content[BRAND_KIT_KEY] === "string") {
18325
18366
  applyBrandToDom(parseBrandKit(content[BRAND_KIT_KEY]));
@@ -18402,6 +18443,22 @@ function OhhwellsBridge() {
18402
18443
  (0, import_react17.useEffect)(() => {
18403
18444
  postToParent2({ type: "ow:navigation", path: pathname });
18404
18445
  }, [pathname, postToParent2]);
18446
+ (0, import_react17.useEffect)(() => {
18447
+ if (!subdomain || isEditMode) return;
18448
+ const content = contentCache.get(subdomain);
18449
+ if (!content) return;
18450
+ unmountAllAiSections();
18451
+ initSectionsFromContent(
18452
+ content,
18453
+ /*removeExisting*/
18454
+ true,
18455
+ pathname
18456
+ );
18457
+ if (typeof content[AI_SECTIONS_KEY] === "string") {
18458
+ setAiSectionOrder(content[SECTION_ORDER_KEY], pathname);
18459
+ applyAiSectionsToDom(parseAiSectionsState(content[AI_SECTIONS_KEY]));
18460
+ }
18461
+ }, [pathname, subdomain, isEditMode]);
18405
18462
  (0, import_react17.useEffect)(() => {
18406
18463
  if (!isEditMode) return;
18407
18464
  if (linkPopoverSessionRef.current?.intent === "add-nav") return;
@@ -18410,6 +18467,10 @@ function OhhwellsBridge() {
18410
18467
  deselectRef.current();
18411
18468
  deactivateRef.current();
18412
18469
  }, [pathname, isEditMode]);
18470
+ (0, import_react17.useEffect)(() => {
18471
+ if (!isEditMode) return;
18472
+ initSectionInstancesFromContent(editContentRef.current, pathname);
18473
+ }, [pathname, isEditMode]);
18413
18474
  (0, import_react17.useEffect)(() => {
18414
18475
  const contentForNav = () => {
18415
18476
  if (isEditMode) return editContentRef.current;
@@ -21479,7 +21540,7 @@ function OhhwellsBridge() {
21479
21540
  postToParent2({
21480
21541
  type: "ow:ready",
21481
21542
  version: "1",
21482
- bridgeVersion: "0.1.91",
21543
+ bridgeVersion: "0.1.93",
21483
21544
  path: pathname,
21484
21545
  nodes: collectEditableNodes(editContentRef.current),
21485
21546
  sections