@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.js CHANGED
@@ -8185,17 +8185,40 @@ var REMOVED_ATTR2 = "data-ohw-section-removed";
8185
8185
  function isRemovedSection(el) {
8186
8186
  return el.hasAttribute(REMOVED_ATTR2);
8187
8187
  }
8188
+ function movableUnit(el) {
8189
+ return el.closest("[data-ohw-section-container]") ?? el;
8190
+ }
8191
+ function sectionTypeOf(el) {
8192
+ return el.getAttribute("data-ohw-section") ?? el.querySelector("[data-ohw-section]")?.getAttribute("data-ohw-section") ?? "";
8193
+ }
8194
+ function sectionElementOf(el) {
8195
+ return el.hasAttribute("data-ohw-section") ? el : el.querySelector("[data-ohw-section]") ?? el;
8196
+ }
8197
+ function collectTopLevelUnits(predicate) {
8198
+ const seen = /* @__PURE__ */ new Set();
8199
+ const result = [];
8200
+ document.querySelectorAll("[data-ohw-section]").forEach((el) => {
8201
+ if (!predicate(el)) return;
8202
+ const unit = movableUnit(el);
8203
+ if (unit.parentElement?.closest("[data-ohw-section],[data-ohw-section-container]")) return;
8204
+ if (seen.has(unit)) return;
8205
+ seen.add(unit);
8206
+ result.push(unit);
8207
+ });
8208
+ return result;
8209
+ }
8188
8210
  function topLevelSections() {
8189
- return Array.from(document.querySelectorAll("[data-ohw-section]")).filter(
8190
- (el) => !el.parentElement?.closest("[data-ohw-section]") && !isChromeSection(el) && !isRemovedSection(el)
8191
- );
8211
+ return collectTopLevelUnits((el) => !isChromeSection(el) && !isRemovedSection(movableUnit(el)));
8192
8212
  }
8193
8213
  function instanceIdOf(el) {
8194
8214
  return el.dataset.ohwInstance ?? el.dataset.ohwSection ?? "";
8195
8215
  }
8196
8216
  function findByInstanceId(instanceId) {
8197
8217
  const escapedId = CSS.escape(instanceId);
8198
- return document.querySelector(`[data-ohw-instance="${escapedId}"]`) ?? document.querySelector(`[data-ohw-section="${escapedId}"]:not([data-ohw-instance])`);
8218
+ const direct = document.querySelector(`[data-ohw-instance="${escapedId}"]`);
8219
+ if (direct) return movableUnit(direct);
8220
+ const bare = document.querySelector(`[data-ohw-section="${escapedId}"]:not([data-ohw-instance])`);
8221
+ return bare ? movableUnit(bare) : null;
8199
8222
  }
8200
8223
  function planSectionMove(instanceId, targetIndex, currentPath) {
8201
8224
  const sections = topLevelSections();
@@ -8207,7 +8230,7 @@ function planSectionMove(instanceId, targetIndex, currentPath) {
8207
8230
  const reordered = [...others.slice(0, clamped), dragged, ...others.slice(clamped)];
8208
8231
  return reordered.map((el, order) => ({
8209
8232
  instanceId: instanceIdOf(el),
8210
- type: el.getAttribute("data-ohw-section") ?? "",
8233
+ type: sectionTypeOf(el),
8211
8234
  order,
8212
8235
  pagePath: currentPath
8213
8236
  }));
@@ -8262,13 +8285,11 @@ function applyPersistedOrder(entries) {
8262
8285
  function setSectionRemoved(instanceId, currentPath, existingEntries, removed) {
8263
8286
  if (!findByInstanceId(instanceId)) return null;
8264
8287
  const byId = new Map(existingEntries.map((e) => [e.instanceId, e]));
8265
- const allSections = Array.from(document.querySelectorAll("[data-ohw-section]")).filter(
8266
- (el) => !el.parentElement?.closest("[data-ohw-section]") && !isChromeSection(el)
8267
- );
8288
+ const allSections = collectTopLevelUnits((el) => !isChromeSection(el));
8268
8289
  allSections.forEach((el, order) => {
8269
8290
  const id = instanceIdOf(el);
8270
8291
  if (!byId.has(id)) {
8271
- byId.set(id, { instanceId: id, type: el.getAttribute("data-ohw-section") ?? "", order, pagePath: currentPath });
8292
+ byId.set(id, { instanceId: id, type: sectionTypeOf(el), order, pagePath: currentPath });
8272
8293
  }
8273
8294
  });
8274
8295
  const target = byId.get(instanceId);
@@ -8296,7 +8317,7 @@ function duplicateSectionInstance(instanceId, newId, currentPath, existingEntrie
8296
8317
  const id = instanceIdOf(el);
8297
8318
  return {
8298
8319
  instanceId: id,
8299
- type: el.getAttribute("data-ohw-section") ?? "",
8320
+ type: sectionTypeOf(el),
8300
8321
  order,
8301
8322
  pagePath: currentPath,
8302
8323
  ...byId.get(id)?.removed ? { removed: true } : {}
@@ -8338,6 +8359,10 @@ function initSectionInstancesFromContent(content, currentPath) {
8338
8359
  document.querySelectorAll("[data-ohw-section]:not([data-ohw-instance])").forEach((el) => {
8339
8360
  el.setAttribute("data-ohw-instance", el.getAttribute("data-ohw-section") ?? "");
8340
8361
  });
8362
+ document.querySelectorAll("[data-ohw-section-container]:not([data-ohw-instance])").forEach((el) => {
8363
+ const type = sectionTypeOf(el);
8364
+ if (type) el.setAttribute("data-ohw-instance", type);
8365
+ });
8341
8366
  const entries = getPageSectionOrderEntries(content[SECTION_ORDER_KEY], currentPath);
8342
8367
  for (const entry of entries) {
8343
8368
  if (entry.instanceId === entry.type) continue;
@@ -8356,10 +8381,7 @@ function initSectionInstancesFromContent(content, currentPath) {
8356
8381
 
8357
8382
  // src/ui/ai-section/AiSectionOverlay.tsx
8358
8383
  import { Fragment as Fragment5, jsx as jsx17, jsxs as jsxs9 } from "react/jsx-runtime";
8359
- function findSectionElement(instanceId) {
8360
- const escaped = CSS.escape(instanceId);
8361
- return document.querySelector(`[data-ohw-instance="${escaped}"]`) ?? document.querySelector(`[data-ohw-section="${escaped}"]:not([data-ohw-instance])`);
8362
- }
8384
+ var findSectionElement = findByInstanceId;
8363
8385
  function readRect(instanceId) {
8364
8386
  const el = findSectionElement(instanceId);
8365
8387
  if (!el) return null;
@@ -8399,7 +8421,7 @@ function useLiveSectionRect(sectionId) {
8399
8421
  }
8400
8422
  function computeSectionBoundaryFlags(instanceId) {
8401
8423
  const topLevel = topLevelSections();
8402
- const index = topLevel.findIndex((el) => (el.dataset.ohwInstance ?? el.dataset.ohwSection) === instanceId);
8424
+ const index = topLevel.findIndex((el) => instanceIdOf(el) === instanceId);
8403
8425
  if (index === -1) return { isFirst: true, isLast: true };
8404
8426
  return { isFirst: index === 0, isLast: index === topLevel.length - 1 };
8405
8427
  }
@@ -8483,18 +8505,20 @@ function AiSectionOverlay({
8483
8505
  selectedIdRef.current = selectedId;
8484
8506
  const report = useCallback2(
8485
8507
  (el) => {
8508
+ const labelSrc = el ? sectionElementOf(el) : null;
8486
8509
  postToParent2({
8487
8510
  type: "ow:section-selected",
8488
- sectionId: el ? el.dataset.ohwInstance ?? el.dataset.ohwSection ?? null : null,
8489
- sectionLabel: el ? el.dataset.ohwSectionLabel ?? titleCaseSectionId(el.dataset.ohwSection ?? "") : null
8511
+ sectionId: el ? instanceIdOf(el) || null : null,
8512
+ sectionLabel: labelSrc ? labelSrc.dataset.ohwSectionLabel ?? titleCaseSectionId(labelSrc.dataset.ohwSection ?? "") : null
8490
8513
  });
8491
8514
  },
8492
8515
  [postToParent2]
8493
8516
  );
8494
8517
  const selectFromElement = useCallback2(
8495
8518
  (el, options) => {
8496
- const sectionEl = el?.closest("[data-ohw-section]") ?? null;
8497
- const id = sectionEl ? sectionEl.dataset.ohwInstance ?? sectionEl.dataset.ohwSection ?? null : null;
8519
+ const inner = el?.closest("[data-ohw-section]") ?? null;
8520
+ const sectionEl = inner ? movableUnit(inner) : null;
8521
+ const id = sectionEl ? instanceIdOf(sectionEl) || null : null;
8498
8522
  if (id === selectedIdRef.current) return;
8499
8523
  setSelectedId(id);
8500
8524
  if (options?.report !== false) report(sectionEl);
@@ -8560,7 +8584,8 @@ function AiSectionOverlay({
8560
8584
  return;
8561
8585
  }
8562
8586
  const sec = t.closest("[data-ohw-section]");
8563
- setHoveredId(sec ? sec.dataset.ohwInstance ?? sec.dataset.ohwSection ?? null : null);
8587
+ const unit = sec ? movableUnit(sec) : null;
8588
+ setHoveredId(unit ? instanceIdOf(unit) || null : null);
8564
8589
  };
8565
8590
  const onLeave = () => setHoveredId(null);
8566
8591
  document.addEventListener("mousemove", onMove, { passive: true });
@@ -14184,8 +14209,9 @@ function useSectionDrag({
14184
14209
  const target = e.target;
14185
14210
  if (!(target instanceof HTMLElement)) return;
14186
14211
  if (target.closest(SECTION_DRAG_EXCLUDED_SELECTOR)) return;
14187
- const sectionEl = target.closest("[data-ohw-section]");
14188
- if (!sectionEl || isChromeSection(sectionEl) || sectionEl.dataset.ohwSection === "footer") return;
14212
+ const inner = target.closest("[data-ohw-section]");
14213
+ if (!inner || isChromeSection(inner) || inner.dataset.ohwSection === "footer") return;
14214
+ const sectionEl = movableUnit(inner);
14189
14215
  if (!topLevelSections().includes(sectionEl)) return;
14190
14216
  startSectionPressDrag(sectionEl, e.clientX, e.clientY, e.pointerId);
14191
14217
  };
@@ -15092,7 +15118,6 @@ function mountSchedulingWidget(insertAfter, notifyOnConnect = false, scheduleId,
15092
15118
  if (!mountPoint) return false;
15093
15119
  const container = document.createElement("div");
15094
15120
  container.dataset.ohwSectionContainer = "scheduling";
15095
- container.dataset.ohwSection = sectionId;
15096
15121
  container.dataset.ohwInstance = sectionId;
15097
15122
  if (insertBefore) {
15098
15123
  const beforeAnchor = document.querySelector(`[data-ohw-section="${insertBefore}"]`);
@@ -18249,10 +18274,10 @@ function OhhwellsBridge() {
18249
18274
  const applyFromCache = () => {
18250
18275
  const content = contentCache.get(subdomain);
18251
18276
  if (!content) return;
18252
- retryMissingSchedulingMounts(getPageSchedulingEntries(content["__ohw_sections"]), false);
18253
- initSectionInstancesFromContent(content, window.location.pathname);
18254
18277
  observer?.disconnect();
18255
18278
  try {
18279
+ retryMissingSchedulingMounts(getPageSchedulingEntries(content["__ohw_sections"]), false);
18280
+ initSectionInstancesFromContent(content, window.location.pathname);
18256
18281
  applyBrandChrome(content);
18257
18282
  if (typeof content[BRAND_KIT_KEY] === "string") {
18258
18283
  applyBrandToDom(parseBrandKit(content[BRAND_KIT_KEY]));
@@ -18343,6 +18368,10 @@ function OhhwellsBridge() {
18343
18368
  deselectRef.current();
18344
18369
  deactivateRef.current();
18345
18370
  }, [pathname, isEditMode]);
18371
+ useEffect13(() => {
18372
+ if (!isEditMode) return;
18373
+ initSectionInstancesFromContent(editContentRef.current, pathname);
18374
+ }, [pathname, isEditMode]);
18346
18375
  useEffect13(() => {
18347
18376
  const contentForNav = () => {
18348
18377
  if (isEditMode) return editContentRef.current;
@@ -21412,7 +21441,7 @@ function OhhwellsBridge() {
21412
21441
  postToParent2({
21413
21442
  type: "ow:ready",
21414
21443
  version: "1",
21415
- bridgeVersion: "0.1.91",
21444
+ bridgeVersion: "0.1.92",
21416
21445
  path: pathname,
21417
21446
  nodes: collectEditableNodes(editContentRef.current),
21418
21447
  sections