@ohhwells/bridge 0.1.92 → 0.1.93

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
@@ -8258,17 +8258,40 @@ var REMOVED_ATTR2 = "data-ohw-section-removed";
8258
8258
  function isRemovedSection(el) {
8259
8259
  return el.hasAttribute(REMOVED_ATTR2);
8260
8260
  }
8261
+ function movableUnit(el) {
8262
+ return el.closest("[data-ohw-section-container]") ?? el;
8263
+ }
8264
+ function sectionTypeOf(el) {
8265
+ return el.getAttribute("data-ohw-section") ?? el.querySelector("[data-ohw-section]")?.getAttribute("data-ohw-section") ?? "";
8266
+ }
8267
+ function sectionElementOf(el) {
8268
+ return el.hasAttribute("data-ohw-section") ? el : el.querySelector("[data-ohw-section]") ?? el;
8269
+ }
8270
+ function collectTopLevelUnits(predicate) {
8271
+ const seen = /* @__PURE__ */ new Set();
8272
+ const result = [];
8273
+ document.querySelectorAll("[data-ohw-section]").forEach((el) => {
8274
+ if (!predicate(el)) return;
8275
+ const unit = movableUnit(el);
8276
+ if (unit.parentElement?.closest("[data-ohw-section],[data-ohw-section-container]")) return;
8277
+ if (seen.has(unit)) return;
8278
+ seen.add(unit);
8279
+ result.push(unit);
8280
+ });
8281
+ return result;
8282
+ }
8261
8283
  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
- );
8284
+ return collectTopLevelUnits((el) => !isChromeSection(el) && !isRemovedSection(movableUnit(el)));
8265
8285
  }
8266
8286
  function instanceIdOf(el) {
8267
8287
  return el.dataset.ohwInstance ?? el.dataset.ohwSection ?? "";
8268
8288
  }
8269
8289
  function findByInstanceId(instanceId) {
8270
8290
  const escapedId = CSS.escape(instanceId);
8271
- return document.querySelector(`[data-ohw-instance="${escapedId}"]`) ?? document.querySelector(`[data-ohw-section="${escapedId}"]:not([data-ohw-instance])`);
8291
+ const direct = document.querySelector(`[data-ohw-instance="${escapedId}"]`);
8292
+ if (direct) return movableUnit(direct);
8293
+ const bare = document.querySelector(`[data-ohw-section="${escapedId}"]:not([data-ohw-instance])`);
8294
+ return bare ? movableUnit(bare) : null;
8272
8295
  }
8273
8296
  function planSectionMove(instanceId, targetIndex, currentPath) {
8274
8297
  const sections = topLevelSections();
@@ -8280,7 +8303,7 @@ function planSectionMove(instanceId, targetIndex, currentPath) {
8280
8303
  const reordered = [...others.slice(0, clamped), dragged, ...others.slice(clamped)];
8281
8304
  return reordered.map((el, order) => ({
8282
8305
  instanceId: instanceIdOf(el),
8283
- type: el.getAttribute("data-ohw-section") ?? "",
8306
+ type: sectionTypeOf(el),
8284
8307
  order,
8285
8308
  pagePath: currentPath
8286
8309
  }));
@@ -8335,13 +8358,11 @@ function applyPersistedOrder(entries) {
8335
8358
  function setSectionRemoved(instanceId, currentPath, existingEntries, removed) {
8336
8359
  if (!findByInstanceId(instanceId)) return null;
8337
8360
  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
- );
8361
+ const allSections = collectTopLevelUnits((el) => !isChromeSection(el));
8341
8362
  allSections.forEach((el, order) => {
8342
8363
  const id = instanceIdOf(el);
8343
8364
  if (!byId.has(id)) {
8344
- byId.set(id, { instanceId: id, type: el.getAttribute("data-ohw-section") ?? "", order, pagePath: currentPath });
8365
+ byId.set(id, { instanceId: id, type: sectionTypeOf(el), order, pagePath: currentPath });
8345
8366
  }
8346
8367
  });
8347
8368
  const target = byId.get(instanceId);
@@ -8369,7 +8390,7 @@ function duplicateSectionInstance(instanceId, newId, currentPath, existingEntrie
8369
8390
  const id = instanceIdOf(el);
8370
8391
  return {
8371
8392
  instanceId: id,
8372
- type: el.getAttribute("data-ohw-section") ?? "",
8393
+ type: sectionTypeOf(el),
8373
8394
  order,
8374
8395
  pagePath: currentPath,
8375
8396
  ...byId.get(id)?.removed ? { removed: true } : {}
@@ -8411,6 +8432,10 @@ function initSectionInstancesFromContent(content, currentPath) {
8411
8432
  document.querySelectorAll("[data-ohw-section]:not([data-ohw-instance])").forEach((el) => {
8412
8433
  el.setAttribute("data-ohw-instance", el.getAttribute("data-ohw-section") ?? "");
8413
8434
  });
8435
+ document.querySelectorAll("[data-ohw-section-container]:not([data-ohw-instance])").forEach((el) => {
8436
+ const type = sectionTypeOf(el);
8437
+ if (type) el.setAttribute("data-ohw-instance", type);
8438
+ });
8414
8439
  const entries = getPageSectionOrderEntries(content[SECTION_ORDER_KEY], currentPath);
8415
8440
  for (const entry of entries) {
8416
8441
  if (entry.instanceId === entry.type) continue;
@@ -8429,10 +8454,7 @@ function initSectionInstancesFromContent(content, currentPath) {
8429
8454
 
8430
8455
  // src/ui/ai-section/AiSectionOverlay.tsx
8431
8456
  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
- }
8457
+ var findSectionElement = findByInstanceId;
8436
8458
  function readRect(instanceId) {
8437
8459
  const el = findSectionElement(instanceId);
8438
8460
  if (!el) return null;
@@ -8472,7 +8494,7 @@ function useLiveSectionRect(sectionId) {
8472
8494
  }
8473
8495
  function computeSectionBoundaryFlags(instanceId) {
8474
8496
  const topLevel = topLevelSections();
8475
- const index = topLevel.findIndex((el) => (el.dataset.ohwInstance ?? el.dataset.ohwSection) === instanceId);
8497
+ const index = topLevel.findIndex((el) => instanceIdOf(el) === instanceId);
8476
8498
  if (index === -1) return { isFirst: true, isLast: true };
8477
8499
  return { isFirst: index === 0, isLast: index === topLevel.length - 1 };
8478
8500
  }
@@ -8556,18 +8578,20 @@ function AiSectionOverlay({
8556
8578
  selectedIdRef.current = selectedId;
8557
8579
  const report = (0, import_react8.useCallback)(
8558
8580
  (el) => {
8581
+ const labelSrc = el ? sectionElementOf(el) : null;
8559
8582
  postToParent2({
8560
8583
  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
8584
+ sectionId: el ? instanceIdOf(el) || null : null,
8585
+ sectionLabel: labelSrc ? labelSrc.dataset.ohwSectionLabel ?? titleCaseSectionId(labelSrc.dataset.ohwSection ?? "") : null
8563
8586
  });
8564
8587
  },
8565
8588
  [postToParent2]
8566
8589
  );
8567
8590
  const selectFromElement = (0, import_react8.useCallback)(
8568
8591
  (el, options) => {
8569
- const sectionEl = el?.closest("[data-ohw-section]") ?? null;
8570
- const id = sectionEl ? sectionEl.dataset.ohwInstance ?? sectionEl.dataset.ohwSection ?? null : null;
8592
+ const inner = el?.closest("[data-ohw-section]") ?? null;
8593
+ const sectionEl = inner ? movableUnit(inner) : null;
8594
+ const id = sectionEl ? instanceIdOf(sectionEl) || null : null;
8571
8595
  if (id === selectedIdRef.current) return;
8572
8596
  setSelectedId(id);
8573
8597
  if (options?.report !== false) report(sectionEl);
@@ -8633,7 +8657,8 @@ function AiSectionOverlay({
8633
8657
  return;
8634
8658
  }
8635
8659
  const sec = t.closest("[data-ohw-section]");
8636
- setHoveredId(sec ? sec.dataset.ohwInstance ?? sec.dataset.ohwSection ?? null : null);
8660
+ const unit = sec ? movableUnit(sec) : null;
8661
+ setHoveredId(unit ? instanceIdOf(unit) || null : null);
8637
8662
  };
8638
8663
  const onLeave = () => setHoveredId(null);
8639
8664
  document.addEventListener("mousemove", onMove, { passive: true });
@@ -14251,8 +14276,9 @@ function useSectionDrag({
14251
14276
  const target = e.target;
14252
14277
  if (!(target instanceof HTMLElement)) return;
14253
14278
  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;
14279
+ const inner = target.closest("[data-ohw-section]");
14280
+ if (!inner || isChromeSection(inner) || inner.dataset.ohwSection === "footer") return;
14281
+ const sectionEl = movableUnit(inner);
14256
14282
  if (!topLevelSections().includes(sectionEl)) return;
14257
14283
  startSectionPressDrag(sectionEl, e.clientX, e.clientY, e.pointerId);
14258
14284
  };
@@ -15159,7 +15185,6 @@ function mountSchedulingWidget(insertAfter, notifyOnConnect = false, scheduleId,
15159
15185
  if (!mountPoint) return false;
15160
15186
  const container = document.createElement("div");
15161
15187
  container.dataset.ohwSectionContainer = "scheduling";
15162
- container.dataset.ohwSection = sectionId;
15163
15188
  container.dataset.ohwInstance = sectionId;
15164
15189
  if (insertBefore) {
15165
15190
  const beforeAnchor = document.querySelector(`[data-ohw-section="${insertBefore}"]`);
@@ -18316,10 +18341,10 @@ function OhhwellsBridge() {
18316
18341
  const applyFromCache = () => {
18317
18342
  const content = contentCache.get(subdomain);
18318
18343
  if (!content) return;
18319
- retryMissingSchedulingMounts(getPageSchedulingEntries(content["__ohw_sections"]), false);
18320
- initSectionInstancesFromContent(content, window.location.pathname);
18321
18344
  observer?.disconnect();
18322
18345
  try {
18346
+ retryMissingSchedulingMounts(getPageSchedulingEntries(content["__ohw_sections"]), false);
18347
+ initSectionInstancesFromContent(content, window.location.pathname);
18323
18348
  applyBrandChrome(content);
18324
18349
  if (typeof content[BRAND_KIT_KEY] === "string") {
18325
18350
  applyBrandToDom(parseBrandKit(content[BRAND_KIT_KEY]));
@@ -18410,6 +18435,10 @@ function OhhwellsBridge() {
18410
18435
  deselectRef.current();
18411
18436
  deactivateRef.current();
18412
18437
  }, [pathname, isEditMode]);
18438
+ (0, import_react17.useEffect)(() => {
18439
+ if (!isEditMode) return;
18440
+ initSectionInstancesFromContent(editContentRef.current, pathname);
18441
+ }, [pathname, isEditMode]);
18413
18442
  (0, import_react17.useEffect)(() => {
18414
18443
  const contentForNav = () => {
18415
18444
  if (isEditMode) return editContentRef.current;
@@ -21479,7 +21508,7 @@ function OhhwellsBridge() {
21479
21508
  postToParent2({
21480
21509
  type: "ow:ready",
21481
21510
  version: "1",
21482
- bridgeVersion: "0.1.91",
21511
+ bridgeVersion: "0.1.92",
21483
21512
  path: pathname,
21484
21513
  nodes: collectEditableNodes(editContentRef.current),
21485
21514
  sections