@ohhwells/bridge 0.1.89 → 0.1.91

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
@@ -14954,6 +14954,15 @@ function updateSectionScheduleId(insertAfter, scheduleId) {
14954
14954
  tracker.textContent = JSON.stringify(updated);
14955
14955
  return tracker.textContent ?? "[]";
14956
14956
  }
14957
+ var schedulingRoots = /* @__PURE__ */ new WeakMap();
14958
+ function unmountSchedulingWrapper(wrapper) {
14959
+ const root = schedulingRoots.get(wrapper);
14960
+ if (root) {
14961
+ schedulingRoots.delete(wrapper);
14962
+ setTimeout(() => root.unmount(), 0);
14963
+ }
14964
+ wrapper.remove();
14965
+ }
14957
14966
  function schedulingSectionId(insertAfter) {
14958
14967
  return `scheduling-${insertAfter}`;
14959
14968
  }
@@ -15007,12 +15016,12 @@ function retryMissingSchedulingMounts(entries, notifyOnConnect = false) {
15007
15016
  if (!hasMissingSchedulingWidgets(entries)) return;
15008
15017
  mountSchedulingEntries(entries, notifyOnConnect);
15009
15018
  }
15010
- function initSectionsFromContent(content, removeExisting = false) {
15019
+ function initSectionsFromContent(content, removeExisting = false, currentPath = typeof window !== "undefined" ? window.location.pathname : "/") {
15011
15020
  const raw = content["__ohw_sections"];
15012
15021
  if (!raw) return;
15013
15022
  try {
15014
15023
  if (removeExisting) {
15015
- document.querySelectorAll('[data-ohw-section-container="scheduling"]').forEach((el) => el.remove());
15024
+ document.querySelectorAll('[data-ohw-section-container="scheduling"]').forEach((el) => unmountSchedulingWrapper(el));
15016
15025
  }
15017
15026
  const inEditor = typeof window !== "undefined" && window.self !== window.top;
15018
15027
  if (inEditor) getSectionsTracker().textContent = raw;
@@ -15020,8 +15029,16 @@ function initSectionsFromContent(content, removeExisting = false) {
15020
15029
  const preExisting = pageEntries.filter((e) => !isSchedulingWidgetMissing(e));
15021
15030
  const notifyForEntry = inEditor ? (e) => !e.scheduleId : false;
15022
15031
  mountSchedulingEntries(pageEntries, notifyForEntry);
15023
- requestAnimationFrame(() => retryMissingSchedulingMounts(pageEntries, notifyForEntry));
15024
- setTimeout(() => retryMissingSchedulingMounts(pageEntries, notifyForEntry), 250);
15032
+ const reapplyOrder = () => applyPersistedOrder(getPageSectionOrderEntries(content[SECTION_ORDER_KEY], currentPath));
15033
+ reapplyOrder();
15034
+ requestAnimationFrame(() => {
15035
+ retryMissingSchedulingMounts(pageEntries, notifyForEntry);
15036
+ reapplyOrder();
15037
+ });
15038
+ setTimeout(() => {
15039
+ retryMissingSchedulingMounts(pageEntries, notifyForEntry);
15040
+ reapplyOrder();
15041
+ }, 250);
15025
15042
  for (const entry of preExisting) {
15026
15043
  window.postMessage({ type: "ow:schedule-config", insertAfter: entry.insertAfter, scheduleId: entry.scheduleId ?? null }, "*");
15027
15044
  }
@@ -15036,6 +15053,8 @@ function mountSchedulingWidget(insertAfter, notifyOnConnect = false, scheduleId,
15036
15053
  if (!mountPoint) return false;
15037
15054
  const container = document.createElement("div");
15038
15055
  container.dataset.ohwSectionContainer = "scheduling";
15056
+ container.dataset.ohwSection = sectionId;
15057
+ container.dataset.ohwInstance = sectionId;
15039
15058
  if (insertBefore) {
15040
15059
  const beforeAnchor = document.querySelector(`[data-ohw-section="${insertBefore}"]`);
15041
15060
  const beforePoint = beforeAnchor?.closest('[data-ohw-section-container="scheduling"]') ?? beforeAnchor;
@@ -15049,6 +15068,7 @@ function mountSchedulingWidget(insertAfter, notifyOnConnect = false, scheduleId,
15049
15068
  tail.insertAdjacentElement("afterend", container);
15050
15069
  }
15051
15070
  const root = (0, import_client2.createRoot)(container);
15071
+ schedulingRoots.set(container, root);
15052
15072
  (0, import_react_dom3.flushSync)(() => {
15053
15073
  root.render(
15054
15074
  /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
@@ -20343,6 +20363,33 @@ function OhhwellsBridge() {
20343
20363
  if (e.data?.type !== "ow:delete-section") return;
20344
20364
  const instanceId = typeof e.data.instanceId === "string" ? e.data.instanceId : "";
20345
20365
  if (!instanceId) return;
20366
+ if (instanceId.startsWith("scheduling-")) {
20367
+ const insertAfter = instanceId.slice("scheduling-".length);
20368
+ const el = document.querySelector(`[data-ohw-section="${CSS.escape(instanceId)}"]`);
20369
+ const wrapper = el?.closest('[data-ohw-section-container="scheduling"]') ?? null;
20370
+ if (wrapper) {
20371
+ unmountSchedulingWrapper(wrapper);
20372
+ } else {
20373
+ el?.setAttribute("style", "display:none");
20374
+ }
20375
+ const tracker = getSectionsTracker();
20376
+ let sections = [];
20377
+ try {
20378
+ sections = JSON.parse(tracker.textContent || "[]");
20379
+ } catch {
20380
+ }
20381
+ const currentPath = window.location.pathname;
20382
+ const updated = sections.filter(
20383
+ (s) => !(s.type === "scheduling" && s.insertAfter === insertAfter && (!s.pagePath || s.pagePath === currentPath))
20384
+ );
20385
+ tracker.textContent = JSON.stringify(updated);
20386
+ postToParentRef.current({ type: "ow:change", nodes: [{ key: "__ohw_sections", text: tracker.textContent }] });
20387
+ aiSectionApiRef.current?.clear();
20388
+ window.dispatchEvent(new Event("resize"));
20389
+ const height = document.body.scrollHeight;
20390
+ if (height > 50) postToParentRef.current({ type: "ow:height", height });
20391
+ return;
20392
+ }
20346
20393
  const currentEntries = getPageSectionOrderEntries(editContentRef.current[SECTION_ORDER_KEY], window.location.pathname);
20347
20394
  const entries = deleteSectionInstance(instanceId, window.location.pathname, currentEntries);
20348
20395
  if (!entries) return;
@@ -21303,7 +21350,7 @@ function OhhwellsBridge() {
21303
21350
  postToParent2({
21304
21351
  type: "ow:ready",
21305
21352
  version: "1",
21306
- bridgeVersion: "0.1.88",
21353
+ bridgeVersion: "0.1.90",
21307
21354
  path: pathname,
21308
21355
  nodes: collectEditableNodes(editContentRef.current),
21309
21356
  sections